Update.
[glibc.git] / sysdeps / unix / start.c
blob8112d2142aa975224b2f453d85d6f318c37a3c4d
1 /* Copyright (C) 1991, 1993, 1995, 1996 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 modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 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
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with the GNU C Library; see the file COPYING. If not, write to
16 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
18 #include <errno.h>
19 #include <stdlib.h>
20 #include <unistd.h>
21 #include <sysdep.h> /* In case it wants to define anything. */
23 /* The first piece of initialized data. */
24 int __data_start = 0;
25 #ifdef HAVE_WEAK_SYMBOLS
26 weak_alias (__data_start, data_start)
27 #endif
29 #ifdef DUMMIES
30 #define ARG_DUMMIES DUMMIES,
31 #define DECL_DUMMIES int DUMMIES;
32 #else
33 #define ARG_DUMMIES
34 #define DECL_DUMMIES
35 #endif
37 #ifndef errno
38 volatile int __errno;
39 string_alias (__errno, errno)
40 #endif
42 extern void __libc_init __P ((int argc, char **argv, char **envp));
43 extern int main __P ((int argc, char **argv, char **envp));
46 /* Not a prototype because it gets called strangely. */
47 static void start1();
49 #ifndef HAVE__start
51 /* N.B.: It is important that this be the first function.
52 This file is the first thing in the text section. */
53 void
54 _start ()
56 start1 ();
59 #ifndef NO_UNDERSCORES
60 /* Make an alias called `start' (no leading underscore, so it can't
61 conflict with C symbols) for `_start'. This is the name vendor crt0.o's
62 tend to use, and thus the name most linkers expect. */
63 asm (".set start, __start");
64 #endif
66 #endif
68 /* ARGSUSED */
69 static void
70 start1 (ARG_DUMMIES argc, argp)
71 DECL_DUMMIES
72 int argc;
73 char *argp;
75 char **argv = &argp;
77 /* The environment starts just after ARGV. */
78 __environ = &argv[argc + 1];
80 /* If the first thing after ARGV is the arguments
81 themselves, there is no environment. */
82 if ((char *) __environ == *argv)
83 /* The environment is empty. Make __environ
84 point at ARGV[ARGC], which is NULL. */
85 --__environ;
87 /* Do C library initializations. */
88 __libc_init (argc, argv, __environ);
90 /* Call the user program. */
91 exit (main (argc, argv, __environ));