Update.
[glibc.git] / sysdeps / unix / start.c
blob49d17810add0062459015f7548dc93fcde05d38b
1 /* Copyright (C) 1991, 93, 95, 96, 97, 98 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. */
19 #include <errno.h>
20 #include <stdlib.h>
21 #include <unistd.h>
22 #include <sysdep.h> /* In case it wants to define anything. */
24 /* The first piece of initialized data. */
25 int __data_start = 0;
26 #ifdef HAVE_WEAK_SYMBOLS
27 weak_alias (__data_start, data_start)
28 #endif
30 #ifdef DUMMIES
31 #define ARG_DUMMIES DUMMIES,
32 #define DECL_DUMMIES int DUMMIES;
33 #else
34 #define ARG_DUMMIES
35 #define DECL_DUMMIES
36 #endif
38 #ifndef errno
39 volatile int __errno;
40 strong_alias (__errno, errno)
41 #endif
43 extern void __libc_init __P ((int argc, char **argv, char **envp));
44 extern int main __P ((int argc, char **argv, char **envp));
47 /* Not a prototype because it gets called strangely. */
48 static void start1();
50 #ifndef HAVE__start
52 /* N.B.: It is important that this be the first function.
53 This file is the first thing in the text section. */
54 void
55 _start ()
57 start1 ();
60 #ifndef NO_UNDERSCORES
61 /* Make an alias called `start' (no leading underscore, so it can't
62 conflict with C symbols) for `_start'. This is the name vendor crt0.o's
63 tend to use, and thus the name most linkers expect. */
64 asm (".set start, __start");
65 #endif
67 #endif
69 /* ARGSUSED */
70 static void
71 start1 (ARG_DUMMIES argc, argp)
72 DECL_DUMMIES
73 int argc;
74 char *argp;
76 char **argv = &argp;
78 /* The environment starts just after ARGV. */
79 __environ = &argv[argc + 1];
81 /* If the first thing after ARGV is the arguments
82 themselves, there is no environment. */
83 if ((char *) __environ == *argv)
84 /* The environment is empty. Make __environ
85 point at ARGV[ARGC], which is NULL. */
86 --__environ;
88 /* Do C library initializations. */
89 __libc_init (argc, argv, __environ);
91 /* Call the user program. */
92 exit (main (argc, argv, __environ));