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. PR: 214972 Reviewed by: kib MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D9180
This commit is contained in:
parent
275c6b6b14
commit
358751cd80
@ -35,8 +35,8 @@
|
|||||||
struct Struct_Obj_Entry;
|
struct Struct_Obj_Entry;
|
||||||
|
|
||||||
/* Return the address of the .dynamic section in the dynamic linker. */
|
/* Return the address of the .dynamic section in the dynamic linker. */
|
||||||
#define rtld_dynamic(obj) \
|
Elf_Dyn *rtld_dynamic_addr(void);
|
||||||
((const Elf_Dyn *)((obj)->relocbase + (Elf_Addr)&_DYNAMIC))
|
#define rtld_dynamic(obj) rtld_dynamic_addr()
|
||||||
|
|
||||||
/* Fixup the jump slot at "where" to transfer control to "target". */
|
/* Fixup the jump slot at "where" to transfer control to "target". */
|
||||||
static inline Elf_Addr
|
static inline Elf_Addr
|
||||||
|
@ -156,4 +156,16 @@ _rtld_bind_start:
|
|||||||
.cfi_endproc
|
.cfi_endproc
|
||||||
.size _rtld_bind_start, . - _rtld_bind_start
|
.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
|
.section .note.GNU-stack,"",%progbits
|
||||||
|
Loading…
Reference in New Issue
Block a user