Back to index

glibc  2.9
start.c
Go to the documentation of this file.
00001 /* Copyright (C) 1991, 93, 1995-1998, 2000 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003 
00004    The GNU C Library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Lesser General Public
00006    License as published by the Free Software Foundation; either
00007    version 2.1 of the License, or (at your option) any later version.
00008 
00009    In addition to the permissions in the GNU Lesser General Public
00010    License, the Free Software Foundation gives you unlimited
00011    permission to link the compiled version of this file with other
00012    programs, and to distribute those programs without any restriction
00013    coming from the use of this file. (The GNU Lesser General Public
00014    License restrictions do apply in other respects; for example, they
00015    cover modification of the file, and distribution when not linked
00016    into another program.)
00017 
00018    Note that people who make modified versions of this file are not
00019    obligated to grant this special exception for their modified
00020    versions; it is their choice whether to do so. The GNU Lesser
00021    General Public License gives permission to release a modified
00022    version without this exception; this exception also makes it
00023    possible to release a modified version which carries forward this
00024    exception.
00025 
00026    The GNU C Library is distributed in the hope that it will be useful,
00027    but WITHOUT ANY WARRANTY; without even the implied warranty of
00028    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00029    Lesser General Public License for more details.
00030 
00031    You should have received a copy of the GNU Lesser General Public
00032    License along with the GNU C Library; if not, write to the Free
00033    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00034    02111-1307 USA.  */
00035 
00036 #include <errno.h>
00037 #include <stdlib.h>
00038 #include <unistd.h>
00039 #include <sysdep.h>         /* In case it wants to define anything.  */
00040 
00041 /* The first piece of initialized data.  */
00042 int __data_start = 0;
00043 #ifdef HAVE_WEAK_SYMBOLS
00044 weak_alias (__data_start, data_start)
00045 #endif
00046 
00047 #ifdef DUMMIES
00048 #define       ARG_DUMMIES   DUMMIES,
00049 #define       DECL_DUMMIES  int DUMMIES;
00050 #else
00051 #define       ARG_DUMMIES
00052 #define       DECL_DUMMIES
00053 #endif
00054 
00055 extern void __libc_init (int argc, char **argv, char **envp);
00056 extern int main (int argc, char **argv, char **envp);
00057 
00058 
00059 /* Not a prototype because it gets called strangely.  */
00060 static void start1();
00061 
00062 #ifndef       HAVE__start
00063 
00064 /* N.B.: It is important that this be the first function.
00065    This file is the first thing in the text section.  */
00066 void
00067 _start ()
00068 {
00069   start1 ();
00070 }
00071 
00072 #ifndef NO_UNDERSCORES
00073 /* Make an alias called `start' (no leading underscore, so it can't
00074    conflict with C symbols) for `_start'.  This is the name vendor crt0.o's
00075    tend to use, and thus the name most linkers expect.  */
00076 asm (".set start, __start");
00077 #endif
00078 
00079 #endif
00080 
00081 /* ARGSUSED */
00082 static void
00083 start1 (ARG_DUMMIES argc, argp)
00084      DECL_DUMMIES
00085      int argc;
00086      char *argp;
00087 {
00088   char **argv = &argp;
00089 
00090   /* The environment starts just after ARGV.  */
00091   __environ = &argv[argc + 1];
00092 
00093   /* If the first thing after ARGV is the arguments
00094      themselves, there is no environment.  */
00095   if ((char *) __environ == *argv)
00096     /* The environment is empty.  Make __environ
00097        point at ARGV[ARGC], which is NULL.  */
00098     --__environ;
00099 
00100   /* Do C library initializations.  */
00101   __libc_init (argc, argv, __environ);
00102 
00103   /* Call the user program.  */
00104   exit (main (argc, argv, __environ));
00105 }