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. */
21 #include <elf/ldsodefs.h>
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
;
28 extern void *__libc_stack_end
;
31 __libc_start_main (int (*main
) (int, char **, char **), int argc
,
32 char **argv
, void (*init
) (void), void (*fini
) (void),
33 void (*rtld_fini
) (void), void *stack_end
)
36 /* The next variable is only here to work around a bug in gcc <= 2.7.2.2.
37 If the address would be taken inside the expression the optimizer
38 would try to be too smart and throws it away. Grrr. */
39 int *dummy_addr
= &_dl_starting_up
;
41 __libc_multiple_libcs
= dummy_addr
&& !_dl_starting_up
;
44 /* Store the lowest stack address. */
45 __libc_stack_end
= stack_end
;
47 /* Set the global _environ variable correctly. */
48 __environ
= &argv
[argc
+ 1];
50 /* Register the destructor of the dynamic linker if there is any. */
51 if (rtld_fini
!= NULL
)
54 /* Call the initializer of the libc. */
56 if (_dl_debug_impcalls
)
57 _dl_debug_message (1, "\ninitialize libc\n\n", NULL
);
59 __libc_init_first (argc
, argv
, __environ
);
61 /* Register the destructor of the program, if any. */
65 /* Call the initializer of the program, if any. */
67 if (_dl_debug_impcalls
)
68 _dl_debug_message (1, "\ninitialize program: ", argv
[0], "\n\n", NULL
);
74 if (_dl_debug_impcalls
)
75 _dl_debug_message (1, "\ntransferring control: ", argv
[0], "\n\n", NULL
);
78 exit ((*main
) (argc
, argv
, __environ
));