2.9
[glibc/nacl-glibc.git] / sysdeps / unix / start.c
blob2474fc2e7f6f10cfdc3f051c067bfe088460e236
1 /* Copyright (C) 1991, 93, 1995-1998, 2000 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 In addition to the permissions in the GNU Lesser General Public
10 License, the Free Software Foundation gives you unlimited
11 permission to link the compiled version of this file with other
12 programs, and to distribute those programs without any restriction
13 coming from the use of this file. (The GNU Lesser General Public
14 License restrictions do apply in other respects; for example, they
15 cover modification of the file, and distribution when not linked
16 into another program.)
18 Note that people who make modified versions of this file are not
19 obligated to grant this special exception for their modified
20 versions; it is their choice whether to do so. The GNU Lesser
21 General Public License gives permission to release a modified
22 version without this exception; this exception also makes it
23 possible to release a modified version which carries forward this
24 exception.
26 The GNU C Library is distributed in the hope that it will be useful,
27 but WITHOUT ANY WARRANTY; without even the implied warranty of
28 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
29 Lesser General Public License for more details.
31 You should have received a copy of the GNU Lesser General Public
32 License along with the GNU C Library; if not, write to the Free
33 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
34 02111-1307 USA. */
36 #include <errno.h>
37 #include <stdlib.h>
38 #include <unistd.h>
39 #include <sysdep.h> /* In case it wants to define anything. */
41 /* The first piece of initialized data. */
42 int __data_start = 0;
43 #ifdef HAVE_WEAK_SYMBOLS
44 weak_alias (__data_start, data_start)
45 #endif
47 #ifdef DUMMIES
48 #define ARG_DUMMIES DUMMIES,
49 #define DECL_DUMMIES int DUMMIES;
50 #else
51 #define ARG_DUMMIES
52 #define DECL_DUMMIES
53 #endif
55 extern void __libc_init (int argc, char **argv, char **envp);
56 extern int main (int argc, char **argv, char **envp);
59 /* Not a prototype because it gets called strangely. */
60 static void start1();
62 #ifndef HAVE__start
64 /* N.B.: It is important that this be the first function.
65 This file is the first thing in the text section. */
66 void
67 _start ()
69 start1 ();
72 #ifndef NO_UNDERSCORES
73 /* Make an alias called `start' (no leading underscore, so it can't
74 conflict with C symbols) for `_start'. This is the name vendor crt0.o's
75 tend to use, and thus the name most linkers expect. */
76 asm (".set start, __start");
77 #endif
79 #endif
81 /* ARGSUSED */
82 static void
83 start1 (ARG_DUMMIES argc, argp)
84 DECL_DUMMIES
85 int argc;
86 char *argp;
88 char **argv = &argp;
90 /* The environment starts just after ARGV. */
91 __environ = &argv[argc + 1];
93 /* If the first thing after ARGV is the arguments
94 themselves, there is no environment. */
95 if ((char *) __environ == *argv)
96 /* The environment is empty. Make __environ
97 point at ARGV[ARGC], which is NULL. */
98 --__environ;
100 /* Do C library initializations. */
101 __libc_init (argc, argv, __environ);
103 /* Call the user program. */
104 exit (main (argc, argv, __environ));