1 /* Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If not,
16 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
25 extern void __libc_init_first (int argc
, char **argv
, char **envp
);
27 extern int _dl_starting_up
;
28 weak_extern (_dl_starting_up
)
29 extern int __libc_multiple_libcs
;
30 extern void *__libc_stack_end
;
33 extern void __pthread_initialize_minimal (void) __attribute__ ((weak
));
37 extern int BP_SYM (__libc_start_main
) (int (*main
) (int, char **, char **),
39 char *__unbounded
*__unbounded ubp_av
,
42 void (*rtld_fini
) (void),
43 void *__unbounded stack_end
)
44 __attribute__ ((noreturn
));
47 /* GKM FIXME: GCC: this should get __BP_ prefix by virtue of the
48 BPs in the arglist of startup_info.main and startup_info.init. */
49 BP_SYM (__libc_start_main
) (int (*main
) (int, char **, char **),
50 int argc
, char *__unbounded
*__unbounded ubp_av
,
51 void (*init
) (void), void (*fini
) (void),
52 void (*rtld_fini
) (void), void *__unbounded stack_end
)
54 char *__unbounded
*__unbounded ubp_ev
= &ubp_av
[argc
+ 1];
55 #if __BOUNDED_POINTERS__
62 # ifdef HAVE_AUX_VECTOR
63 void *__unbounded
*__unbounded auxvec
;
66 /* The next variable is only here to work around a bug in gcc <= 2.7.2.2.
67 If the address would be taken inside the expression the optimizer
68 would try to be too smart and throws it away. Grrr. */
69 int *dummy_addr
= &_dl_starting_up
;
71 __libc_multiple_libcs
= dummy_addr
&& !_dl_starting_up
;
74 INIT_ARGV_and_ENVIRON
;
76 /* Store the lowest stack address. */
77 __libc_stack_end
= stack_end
;
80 /* Initialize the thread library at least a bit since the libgcc
81 functions are using thread functions if these are available and
82 we need to setup errno. */
83 if (__pthread_initialize_minimal
)
84 __pthread_initialize_minimal ();
86 /* Some security at this point. Prevent starting a SUID binary where
87 the standard file descriptors are not opened. We have to do this
88 only for statically linked applications since otherwise the dynamic
89 loader did the work already. */
90 if (__builtin_expect (__libc_enable_secure
, 0))
91 __libc_check_standard_fds ();
93 # ifdef HAVE_AUX_VECTOR
94 for (auxvec
= (void *__unbounded
*__unbounded
) ubp_ev
;
95 *auxvec
!= NULL
; ++auxvec
);
97 _dl_aux_init ((ElfW(auxv_t
) *) auxvec
);
101 /* Register the destructor of the dynamic linker if there is any. */
102 if (__builtin_expect (rtld_fini
!= NULL
, 1))
103 __cxa_atexit ((void (*) (void *)) rtld_fini
, NULL
, NULL
);
105 /* Call the initializer of the libc. This is only needed here if we
106 are compiling for the static library in which case we haven't
107 run the constructors in `_dl_start_user'. */
109 __libc_init_first (argc
, argv
, __environ
);
112 /* Register the destructor of the program, if any. */
114 __cxa_atexit ((void (*) (void *)) fini
, NULL
, NULL
);
116 /* Call the initializer of the program, if any. */
118 if (__builtin_expect (_dl_debug_mask
& DL_DEBUG_IMPCALLS
, 0))
119 _dl_debug_printf ("\ninitialize program: %s\n\n", argv
[0]);
125 if (__builtin_expect (_dl_debug_mask
& DL_DEBUG_IMPCALLS
, 0))
126 _dl_debug_printf ("\ntransferring control: %s\n\n", argv
[0]);
129 exit ((*main
) (argc
, argv
, __environ
));