]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/start.c
Fri Mar 24 02:35:37 1995 Roland McGrath <roland@churchy.gnu.ai.mit.edu>
[thirdparty/glibc.git] / sysdeps / unix / start.c
1 /* Copyright (C) 1991, 1993, 1995 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 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.
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
12 GNU General Public License for more details.
13
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. */
17
18 #include <ansidecl.h>
19 #include <errno.h>
20 #include <stdlib.h>
21 #include <unistd.h>
22 #include <sysdep.h> /* In case it wants to define anything. */
23
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
29
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
37
38 #ifndef errno
39 volatile int errno;
40 #endif
41
42 extern void EXFUN(__libc_init, (int argc, char **argv, char **envp));
43 extern int EXFUN(main, (int argc, char **argv, char **envp));
44
45
46 /* Not a prototype because it gets called strangely. */
47 static void start1();
48
49 #ifndef HAVE__start
50
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 DEFUN_VOID(_start)
55 {
56 start1();
57 }
58
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 void _start (void) asm ("start");
64 #endif
65 asm (".set start, __start");
66 #endif
67
68 #endif
69
70 /* ARGSUSED */
71 static void
72 start1 (ARG_DUMMIES argc, argp)
73 DECL_DUMMIES
74 int argc;
75 char *argp;
76 {
77 char **argv = &argp;
78
79 /* The environment starts just after ARGV. */
80 __environ = &argv[argc + 1];
81
82 /* If the first thing after ARGV is the arguments
83 themselves, there is no environment. */
84 if ((char *) __environ == *argv)
85 /* The environment is empty. Make __environ
86 point at ARGV[ARGC], which is NULL. */
87 --__environ;
88
89 /* Do C library initializations. */
90 __libc_init (argc, argv, __environ);
91
92 /* Call the user program. */
93 exit (main (argc, argv, __environ));
94 }