Add CFI to i386 _start functions

Message ID CABV8kRwe+htGrz7_ij9fj=4umiRos9QcCJ+egaTEuzAV6Jt05g@mail.gmail.com
State New, archived
Headers

Commit Message

Keno Fischer Aug. 15, 2016, 7:23 p.m. UTC
  As a follow up to my patch patch for RTLD_START on x86_64, this adds
cfi instructions to the _start functions in both the dynamic loader
and the application startup files.
---
 sysdeps/i386/dl-machine.h | 14 ++++++++++----
 sysdeps/i386/start.S      | 10 ++++++----
 2 files changed, 16 insertions(+), 8 deletions(-)
  

Patch

diff --git a/sysdeps/i386/dl-machine.h b/sysdeps/i386/dl-machine.h
index 4e3968a..b8fd5f3 100644
--- a/sysdeps/i386/dl-machine.h
+++ b/sysdeps/i386/dl-machine.h
@@ -149,11 +149,16 @@  extern ElfW(Addr) _dl_profile_fixup (struct link_map *l,
  .align 16\n\
 .globl _start\n\
 .globl _dl_start_user\n\
-_start:\n\
+_start:\n"\
+CFI_STARTPROC "\n"\
+CFI_UNDEFINED(%eip) "\n\
  # Note that _dl_start gets the parameter in %eax.\n\
  movl %esp, %eax\n\
- call _dl_start\n\
-_dl_start_user:\n\
+ call _dl_start\n"\
+CFI_ENDPROC "\n\
+_dl_start_user:\n"\
+CFI_STARTPROC "\n"\
+CFI_UNDEFINED(%eip) "\n\
  # Save the user entry point address in %edi.\n\
  movl %eax, %edi\n\
  # Point %ebx at the GOT.\n\
@@ -195,7 +200,8 @@  _dl_start_user:\n\
  # Restore %esp _start expects.\n\
  movl (%esp), %esp\n\
  # Jump to the user's entry point.\n\
- jmp *%edi\n\
+ jmp *%edi\n"\
+CFI_ENDPROC "\n\
  .previous\n\
 ");

diff --git a/sysdeps/i386/start.S b/sysdeps/i386/start.S
index 964e6d9..3ad1749 100644
--- a/sysdeps/i386/start.S
+++ b/sysdeps/i386/start.S
@@ -52,10 +52,11 @@ 
  NULL
 */

- .text
- .globl _start
- .type _start,@function
-_start:
+#include <sysdep.h>
+
+ENTRY (_start)
+ /* Also use CFI to indicate outermost frame.  */
+ cfi_undefined (eip)
  /* Clear the frame pointer.  The ABI suggests this be done, to mark
    the outermost frame obviously.  */
  xorl %ebp, %ebp
@@ -121,6 +122,7 @@  _start:
 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.  */