1 /* Copyright (C) 1998 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. */
23 extern void __libc_init_first (int argc, char **argv, char **envp);
25 extern int _dl_starting_up;
26 weak_extern (_dl_starting_up)
27 extern int __libc_multiple_libcs;
30 __libc_start_main (int (*main) (int, char **, char **), int argc,
31 char **argv, void (*init) (void), void (*fini) (void),
32 void (*rtld_fini) (void))
35 /* The next variable is only here to work around a bug in gcc <= 2.7.2.2.
36 If the address would be taken inside the expression the optimizer
37 would try to be too smart and throws it away. Grrr. */
38 int *dummy_addr = &_dl_starting_up;
40 __libc_multiple_libcs = dummy_addr && !_dl_starting_up;
43 /* Register the destructor of the dynamic linker if there is any. */
44 if (rtld_fini != NULL)
47 /* Set the global _environ variable correctly. */
48 __environ = &argv[argc + 1];
50 /* Call the initializer of the libc. */
52 if (_dl_debug_impcalls)
53 _dl_debug_message (1, "\ninitialize libc\n\n", NULL);
55 __libc_init_first (argc, argv, __environ);
57 /* Call the initializer of the program. */
59 if (_dl_debug_impcalls)
60 _dl_debug_message (1, "\ninitialize program: ", argv[0], "\n\n", NULL);
64 /* Register the destructor of the program. */
68 if (_dl_debug_impcalls)
69 _dl_debug_message (1, "\ntransferring control: ", argv[0], "\n\n", NULL);
72 exit ((*main) (argc, argv, __environ));