1 /* Copyright (C) 1998, 1999, 2000, 2001, 2002 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 Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the 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 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
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
;
34 extern void __pthread_initialize_minimal (void)
36 __attribute__ ((weak
))
42 extern int BP_SYM (__libc_start_main
) (int (*main
) (int, char **, char **),
44 char *__unbounded
*__unbounded ubp_av
,
47 void (*rtld_fini
) (void),
48 void *__unbounded stack_end
)
49 __attribute__ ((noreturn
));
52 /* GKM FIXME: GCC: this should get __BP_ prefix by virtue of the
53 BPs in the arglist of startup_info.main and startup_info.init. */
54 BP_SYM (__libc_start_main
) (int (*main
) (int, char **, char **),
55 int argc
, char *__unbounded
*__unbounded ubp_av
,
56 void (*init
) (void), void (*fini
) (void),
57 void (*rtld_fini
) (void), void *__unbounded stack_end
)
59 char *__unbounded
*__unbounded ubp_ev
= &ubp_av
[argc
+ 1];
60 #if __BOUNDED_POINTERS__
66 /* Result of the 'main' function. */
70 # ifdef HAVE_AUX_VECTOR
71 void *__unbounded
*__unbounded auxvec
;
74 __libc_multiple_libcs
= &_dl_starting_up
&& !_dl_starting_up
;
77 INIT_ARGV_and_ENVIRON
;
79 /* Store the lowest stack address. */
80 __libc_stack_end
= stack_end
;
83 # ifdef HAVE_AUX_VECTOR
84 /* First process the auxiliary vector since we need to find the
85 program header to locate an eventually present PT_TLS entry. */
86 for (auxvec
= (void *__unbounded
*__unbounded
) ubp_ev
;
87 *auxvec
!= NULL
; ++auxvec
);
89 _dl_aux_init ((ElfW(auxv_t
) *) auxvec
);
92 /* Initialize the thread library at least a bit since the libgcc
93 functions are using thread functions if these are available and
94 we need to setup errno. If there is no thread library and we
95 handle TLS the function is defined in the libc to initialized the
98 if (__pthread_initialize_minimal
)
100 __pthread_initialize_minimal ();
102 /* Some security at this point. Prevent starting a SUID binary where
103 the standard file descriptors are not opened. We have to do this
104 only for statically linked applications since otherwise the dynamic
105 loader did the work already. */
106 if (__builtin_expect (__libc_enable_secure
, 0))
107 __libc_check_standard_fds ();
110 /* Register the destructor of the dynamic linker if there is any. */
111 if (__builtin_expect (rtld_fini
!= NULL
, 1))
112 __cxa_atexit ((void (*) (void *)) rtld_fini
, NULL
, NULL
);
114 /* Call the initializer of the libc. This is only needed here if we
115 are compiling for the static library in which case we haven't
116 run the constructors in `_dl_start_user'. */
118 __libc_init_first (argc
, argv
, __environ
);
121 /* Register the destructor of the program, if any. */
123 __cxa_atexit ((void (*) (void *)) fini
, NULL
, NULL
);
125 /* Call the initializer of the program, if any. */
127 if (__builtin_expect (GL(dl_debug_mask
) & DL_DEBUG_IMPCALLS
, 0))
128 _dl_debug_printf ("\ninitialize program: %s\n\n", argv
[0]);
134 if (__builtin_expect (GL(dl_debug_mask
) & DL_DEBUG_IMPCALLS
, 0))
135 _dl_debug_printf ("\ntransferring control: %s\n\n", argv
[0]);
138 #ifdef HAVE_CANCELBUF
139 if (setjmp (THREAD_SELF
->cancelbuf
) == 0)
142 /* XXX This is where the try/finally handling must be used. */
144 result
= main (argc
, argv
, __environ
);
146 #ifdef HAVE_CANCELBUF
148 /* Not much left to do but to exit the thread, not the process. */