Blame csu/elf-init.c

Packit Service 82fcde
/* Startup support for ELF initializers/finalizers in the main executable.
Packit Service 82fcde
   Copyright (C) 2002-2018 Free Software Foundation, Inc.
Packit Service 82fcde
   This file is part of the GNU C Library.
Packit Service 82fcde
Packit Service 82fcde
   The GNU C Library is free software; you can redistribute it and/or
Packit Service 82fcde
   modify it under the terms of the GNU Lesser General Public
Packit Service 82fcde
   License as published by the Free Software Foundation; either
Packit Service 82fcde
   version 2.1 of the License, or (at your option) any later version.
Packit Service 82fcde
Packit Service 82fcde
   In addition to the permissions in the GNU Lesser General Public
Packit Service 82fcde
   License, the Free Software Foundation gives you unlimited
Packit Service 82fcde
   permission to link the compiled version of this file with other
Packit Service 82fcde
   programs, and to distribute those programs without any restriction
Packit Service 82fcde
   coming from the use of this file. (The GNU Lesser General Public
Packit Service 82fcde
   License restrictions do apply in other respects; for example, they
Packit Service 82fcde
   cover modification of the file, and distribution when not linked
Packit Service 82fcde
   into another program.)
Packit Service 82fcde
Packit Service 82fcde
   Note that people who make modified versions of this file are not
Packit Service 82fcde
   obligated to grant this special exception for their modified
Packit Service 82fcde
   versions; it is their choice whether to do so. The GNU Lesser
Packit Service 82fcde
   General Public License gives permission to release a modified
Packit Service 82fcde
   version without this exception; this exception also makes it
Packit Service 82fcde
   possible to release a modified version which carries forward this
Packit Service 82fcde
   exception.
Packit Service 82fcde
Packit Service 82fcde
   The GNU C Library is distributed in the hope that it will be useful,
Packit Service 82fcde
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 82fcde
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 82fcde
   Lesser General Public License for more details.
Packit Service 82fcde
Packit Service 82fcde
   You should have received a copy of the GNU Lesser General Public
Packit Service 82fcde
   License along with the GNU C Library; if not, see
Packit Service 82fcde
   <http://www.gnu.org/licenses/>.  */
Packit Service 82fcde
Packit Service 82fcde
#include <stddef.h>
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
/* These magic symbols are provided by the linker.  */
Packit Service 82fcde
extern void (*__preinit_array_start []) (int, char **, char **)
Packit Service 82fcde
  attribute_hidden;
Packit Service 82fcde
extern void (*__preinit_array_end []) (int, char **, char **)
Packit Service 82fcde
  attribute_hidden;
Packit Service 82fcde
extern void (*__init_array_start []) (int, char **, char **)
Packit Service 82fcde
  attribute_hidden;
Packit Service 82fcde
extern void (*__init_array_end []) (int, char **, char **)
Packit Service 82fcde
  attribute_hidden;
Packit Service 82fcde
extern void (*__fini_array_start []) (void) attribute_hidden;
Packit Service 82fcde
extern void (*__fini_array_end []) (void) attribute_hidden;
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
#ifndef NO_INITFINI
Packit Service 82fcde
/* These function symbols are provided for the .init/.fini section entry
Packit Service 82fcde
   points automagically by the linker.  */
Packit Service 82fcde
extern void _init (void);
Packit Service 82fcde
extern void _fini (void);
Packit Service 82fcde
#endif
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
/* These functions are passed to __libc_start_main by the startup code.
Packit Service 82fcde
   These get statically linked into each program.  For dynamically linked
Packit Service 82fcde
   programs, this module will come from libc_nonshared.a and differs from
Packit Service 82fcde
   the libc.a module in that it doesn't call the preinit array.  */
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
void
Packit Service 82fcde
__libc_csu_init (int argc, char **argv, char **envp)
Packit Service 82fcde
{
Packit Service 82fcde
  /* For dynamically linked executables the preinit array is executed by
Packit Service 82fcde
     the dynamic linker (before initializing any shared object).  */
Packit Service 82fcde
Packit Service 82fcde
#ifndef LIBC_NONSHARED
Packit Service 82fcde
  /* For static executables, preinit happens right before init.  */
Packit Service 82fcde
  {
Packit Service 82fcde
    const size_t size = __preinit_array_end - __preinit_array_start;
Packit Service 82fcde
    size_t i;
Packit Service 82fcde
    for (i = 0; i < size; i++)
Packit Service 82fcde
      (*__preinit_array_start [i]) (argc, argv, envp);
Packit Service 82fcde
  }
Packit Service 82fcde
#endif
Packit Service 82fcde
Packit Service 82fcde
#ifndef NO_INITFINI
Packit Service 82fcde
  _init ();
Packit Service 82fcde
#endif
Packit Service 82fcde
Packit Service 82fcde
  const size_t size = __init_array_end - __init_array_start;
Packit Service 82fcde
  for (size_t i = 0; i < size; i++)
Packit Service 82fcde
      (*__init_array_start [i]) (argc, argv, envp);
Packit Service 82fcde
}
Packit Service 82fcde
Packit Service 82fcde
/* This function should not be used anymore.  We run the executable's
Packit Service 82fcde
   destructor now just like any other.  We cannot remove the function,
Packit Service 82fcde
   though.  */
Packit Service 82fcde
void
Packit Service 82fcde
__libc_csu_fini (void)
Packit Service 82fcde
{
Packit Service 82fcde
#ifndef LIBC_NONSHARED
Packit Service 82fcde
  size_t i = __fini_array_end - __fini_array_start;
Packit Service 82fcde
  while (i-- > 0)
Packit Service 82fcde
    (*__fini_array_start [i]) ();
Packit Service 82fcde
Packit Service 82fcde
# ifndef NO_INITFINI
Packit Service 82fcde
  _fini ();
Packit Service 82fcde
# endif
Packit Service 82fcde
#endif
Packit Service 82fcde
}