This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Add CFI to x86_64 RTLD_START


The application's entry point already has the appropriate CFI to
indicate to tools that the end of the stack has been reached. This
CFI was lacking from the dynamic linker, causing garbled backtraces
after hitting _dl_start. Fix this by adding the appropriate CFI.

Example gdb output before:

```
(gdb) bt
 #0  0x00007f10a2cee2d0 in _start () from /lib64/ld-linux-x86-64.so.2
 #1  0x0000000000000003 in ?? ()
 #2  0x00007ffd2ba54ce9 in ?? ()
 #3  0x00007ffd2ba54d04 in ?? ()
 #4  0x00007ffd2ba54d07 in ?? ()
 #5  0x0000000000000000 in ?? ()
```

after:
```
(gdb) bt
 #0  0x00007f36273551b0 in _start () from
/home/kfischer/replacement-usr/lib/ld-2.23.90.so
```

This is likely applicable to other architectures as well, but I only
have access to x86_64, so this patch is limited to that architecture.
---
 sysdeps/x86_64/dl-machine.h | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/sysdeps/x86_64/dl-machine.h b/sysdeps/x86_64/dl-machine.h
index ed0c1a8..7a246d4 100644
--- a/sysdeps/x86_64/dl-machine.h
+++ b/sysdeps/x86_64/dl-machine.h
@@ -141,10 +141,15 @@ elf_machine_runtime_setup (struct link_map *l,
int lazy, int profile)
  .align 16\n\
 .globl _start\n\
 .globl _dl_start_user\n\
-_start:\n\
+_start:\n"\
+CFI_STARTPROC "\n"\
+CFI_UNDEFINED(%rip) "\n\
  movq %rsp, %rdi\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(%rip) "\n\
  # Save the user entry point address in %r12.\n\
  movq %rax, %r12\n\
  # See if we were run as a command with the executable file\n\
@@ -180,7 +185,8 @@ _dl_start_user:\n\
  # And make sure %rsp points to argc stored on the stack.\n\
  movq %r13, %rsp\n\
  # Jump to the user's entry point.\n\
- jmp *%r12\n\
+ jmp *%r12\n"\
+CFI_ENDPROC "\n\
 .previous\n\
 ");

-- 
2.6.4


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]