summaryrefslogtreecommitdiffstats
path: root/libexec
diff options
context:
space:
mode:
authoremaste <emaste@FreeBSD.org>2017-01-26 03:05:27 +0000
committeremaste <emaste@FreeBSD.org>2017-01-26 03:05:27 +0000
commit98865c5f18ecb1941d6b5594a95268fa4aab201c (patch)
tree6eeaccf9eda297f0d9444e2b10df54a0a70591a7 /libexec
parent569945959b62bb6cc84a7bfe9b9f1c8a4f625b08 (diff)
downloadFreeBSD-src-98865c5f18ecb1941d6b5594a95268fa4aab201c.zip
FreeBSD-src-98865c5f18ecb1941d6b5594a95268fa4aab201c.tar.gz
MFC r312288: rtld: do not rely on a populated GOT on amd64
On rela architectures GNU BFD ld and gold store the relocation addend in GOT entries (in addition to the relocation's r_addend field). rtld previously relied on this to access its own _DYNAMIC symbol in order to apply its own relocations. However, recording addends in the GOT is not specified by the ABI, and some versions of LLVM's LLD linker leave the GOT uninitialized on rela architectures. BFD ld does not populate the GOT on sparc64, and sparc64 rtld has a machine-dependent rtld_dynamic_addr() function that returns the _DYNAMIC address. Use the same approach on amd64, obtaining the %rip- relative _DYNAMIC address following a suggestion from Rafael EspĂ­ndola. Architectures other than amd64 should be addressed in future work.
Diffstat (limited to 'libexec')
-rw-r--r--libexec/rtld-elf/amd64/rtld_machdep.h4
-rw-r--r--libexec/rtld-elf/amd64/rtld_start.S12
2 files changed, 14 insertions, 2 deletions
diff --git a/libexec/rtld-elf/amd64/rtld_machdep.h b/libexec/rtld-elf/amd64/rtld_machdep.h
index df6fc33..0a6354f 100644
--- a/libexec/rtld-elf/amd64/rtld_machdep.h
+++ b/libexec/rtld-elf/amd64/rtld_machdep.h
@@ -35,8 +35,8 @@
struct Struct_Obj_Entry;
/* Return the address of the .dynamic section in the dynamic linker. */
-#define rtld_dynamic(obj) \
- ((const Elf_Dyn *)((obj)->relocbase + (Elf_Addr)&_DYNAMIC))
+Elf_Dyn *rtld_dynamic_addr(void);
+#define rtld_dynamic(obj) rtld_dynamic_addr()
/* Fixup the jump slot at "where" to transfer control to "target". */
static inline Elf_Addr
diff --git a/libexec/rtld-elf/amd64/rtld_start.S b/libexec/rtld-elf/amd64/rtld_start.S
index 387d26c..72240a9 100644
--- a/libexec/rtld-elf/amd64/rtld_start.S
+++ b/libexec/rtld-elf/amd64/rtld_start.S
@@ -156,4 +156,16 @@ _rtld_bind_start:
.cfi_endproc
.size _rtld_bind_start, . - _rtld_bind_start
+ .align 4
+ .globl rtld_dynamic_addr
+ .type rtld_dynamic_addr,@function
+rtld_dynamic_addr:
+ .cfi_startproc
+ .weak _DYNAMIC
+ .hidden _DYNAMIC
+ lea _DYNAMIC(%rip),%rax
+ ret
+ .cfi_endproc
+ .size rtld_dynamic_addr, . - rtld_dynamic_addr
+
.section .note.GNU-stack,"",%progbits
OpenPOWER on IntegriCloud