]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - sysdeps/i386/start.S
Update copyright dates with scripts/update-copyrights
[thirdparty/glibc.git] / sysdeps / i386 / start.S
index afaf2cd020fd2bc946afe03d6cd88da89b07d438..24c806cfecdd17ed8c1dfc0532708291de1c4b0f 100644 (file)
@@ -1,5 +1,5 @@
 /* Startup code compliant to the ELF i386 ABI.
-   Copyright (C) 1995-2013 Free Software Foundation, Inc.
+   Copyright (C) 1995-2021 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -31,7 +31,7 @@
 
    You should have received a copy of the GNU Lesser General Public
    License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
+   <https://www.gnu.org/licenses/>.  */
 
 /* This is the canonical entry point, usually the first thing in the text
    segment.  The SVR4/i386 ABI (pages 3-31, 3-32) says that when the entry
                                        NULL
 */
 
-#include "bp-sym.h"
+#include <sysdep.h>
 
-       .text
-       .globl _start
-       .type _start,@function
-_start:
+ENTRY (_start)
+       /* Clearing frame pointer is insufficient, use CFI.  */
+       cfi_undefined (eip)
        /* Clear the frame pointer.  The ABI suggests this be done, to mark
           the outermost frame obviously.  */
        xorl %ebp, %ebp
@@ -83,7 +82,7 @@ _start:
        pushl %edx              /* Push address of the shared library
                                   termination function.  */
 
-#ifdef SHARED
+#ifdef PIC
        /* Load PIC register.  */
        call 1f
        addl $_GLOBAL_OFFSET_TABLE_, %ebx
@@ -97,11 +96,21 @@ _start:
        pushl %ecx              /* Push second argument: argv.  */
        pushl %esi              /* Push first argument: argc.  */
 
-       pushl BP_SYM (main)@GOT(%ebx)
+# ifdef SHARED
+       pushl main@GOT(%ebx)
+# else
+       /* Avoid relocation in static PIE since _start is called before
+          it is relocated.  Don't use "leal main@GOTOFF(%ebx), %eax"
+          since main may be in a shared object.  Linker will convert
+          "movl main@GOT(%ebx), %eax" to "leal main@GOTOFF(%ebx), %eax"
+          if main is defined locally.  */
+       movl main@GOT(%ebx), %eax
+       pushl %eax
+# endif
 
        /* Call the user's main function, and exit with its value.
           But let the libc call main.    */
-       call BP_SYM (__libc_start_main)@PLT
+       call __libc_start_main@PLT
 #else
        /* Push address of our own entry points to .fini and .init.  */
        pushl $__libc_csu_fini
@@ -110,19 +119,20 @@ _start:
        pushl %ecx              /* Push second argument: argv.  */
        pushl %esi              /* Push first argument: argc.  */
 
-       pushl $BP_SYM (main)
+       pushl $main
 
        /* Call the user's main function, and exit with its value.
           But let the libc call main.    */
-       call BP_SYM (__libc_start_main)
+       call __libc_start_main
 #endif
 
        hlt                     /* Crash if somehow `exit' does return.  */
 
-#ifdef SHARED
+#ifdef PIC
 1:     movl    (%esp), %ebx
        ret
 #endif
+END (_start)
 
 /* To fulfill the System V/i386 ABI we need this symbol.  Yuck, it's so
    meaningless since we don't support machines < 80386.  */