]>
Commit | Line | Data |
---|---|---|
7dea968e UD |
1 | /* Copyright (C) 1998 Free Software Foundation, Inc. |
2 | This file is part of the GNU C Library. | |
3 | ||
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. | |
8 | ||
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. | |
13 | ||
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. */ | |
18 | ||
19 | #include <link.h> | |
3db52d94 UD |
20 | #include <stdlib.h> |
21 | #include <unistd.h> | |
22 | ||
1393c745 UD |
23 | extern void __libc_init_first (int argc, char **argv, char **envp); |
24 | ||
25 | extern int _dl_starting_up; | |
26 | weak_extern (_dl_starting_up) | |
27 | extern int __libc_multiple_libcs; | |
7dea968e UD |
28 | |
29 | int | |
30 | __libc_start_main (int (*main) (int, char **, char **), int argc, | |
3db52d94 UD |
31 | char **argv, void (*init) (void), void (*fini) (void), |
32 | void (*rtld_fini) (void)) | |
7dea968e | 33 | { |
1393c745 UD |
34 | #ifndef PIC |
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; | |
39 | ||
40 | __libc_multiple_libcs = dummy_addr && !_dl_starting_up; | |
41 | #endif | |
42 | ||
3db52d94 UD |
43 | /* Register the destructor of the dynamic linker if there is any. */ |
44 | if (rtld_fini != NULL) | |
45 | atexit (rtld_fini); | |
46 | ||
1393c745 UD |
47 | /* Set the global _environ variable correctly. */ |
48 | __environ = &argv[argc + 1]; | |
49 | ||
3db52d94 UD |
50 | /* Call the initializer of the libc. */ |
51 | #ifdef PIC | |
52 | if (_dl_debug_impcalls) | |
8193034b | 53 | _dl_debug_message (1, "\ninitialize libc\n\n", NULL); |
3db52d94 | 54 | #endif |
1393c745 | 55 | __libc_init_first (argc, argv, __environ); |
3db52d94 UD |
56 | |
57 | /* Call the initializer of the program. */ | |
58 | #ifdef PIC | |
59 | if (_dl_debug_impcalls) | |
8193034b | 60 | _dl_debug_message (1, "\ninitialize program: ", argv[0], "\n\n", NULL); |
3db52d94 UD |
61 | #endif |
62 | (*init) (); | |
63 | ||
64 | /* Register the destructor of the program. */ | |
65 | atexit (fini); | |
66 | ||
7dea968e UD |
67 | #ifdef PIC |
68 | if (_dl_debug_impcalls) | |
8193034b | 69 | _dl_debug_message (1, "\ntransferring control: ", argv[0], "\n\n", NULL); |
7dea968e UD |
70 | #endif |
71 | ||
3db52d94 | 72 | exit ((*main) (argc, argv, __environ)); |
7dea968e | 73 | } |