diff options
author | Jan Klötzke <jan.kloetzke@kernkonzept.com> | 2025-03-19 08:03:12 +0100 |
---|---|---|
committer | Waldemar Brodkorb <wbx@openadk.org> | 2025-03-22 09:11:14 +0100 |
commit | b99b7756228faecb8d506dba64bdb4970a965d5a (patch) | |
tree | 631a85bcdadcd18efc42d0321a6f45334c36e16d /libc/sysdeps/linux/x86_64/crt1.S | |
parent | 278ac6b3098315cddec8f71f27bd8de22e53ca6c (diff) |
Do not rely on unrelocated GOT entries
The LLVM linker seems to be quite clever. When resolving relocations,
accesses to the GOT are potentially replaced by PC relative addressing
to the requested symbol. This breaks the old method of calculating the
load address by using an unrelocated GOT entry value. Instead, rely on
__ehdr_start having a link address of zero.
Signed-off-by: Marcus Haehnel <marcus.haehnel@kernkonzept.com>
Diffstat (limited to 'libc/sysdeps/linux/x86_64/crt1.S')
-rw-r--r-- | libc/sysdeps/linux/x86_64/crt1.S | 6 |
1 files changed, 1 insertions, 5 deletions
diff --git a/libc/sysdeps/linux/x86_64/crt1.S b/libc/sysdeps/linux/x86_64/crt1.S index 701cbf2f6..151aeffeb 100644 --- a/libc/sysdeps/linux/x86_64/crt1.S +++ b/libc/sysdeps/linux/x86_64/crt1.S @@ -83,11 +83,7 @@ _start: #ifdef L_rcrt1 pushq %rdi /* save rdi (but should be 0...) */ pushq %rdx /* store rdx (rtld_fini) */ - xorq %rcx, %rcx /* ensure rcx is 0 */ - addq _start@GOTPCREL(%rip), %rcx /* get offset of _start from beginning of file */ - movq _start@GOTPCREL(%rip), %rax /* get run time address of _start */ - subq %rcx, %rax /* calculate run time load offset */ - movq %rax, %rdi /* load offset -> param 1 */ + lea __ehdr_start(%rip), %rdi /* "Calculate" load address... */ call reloc_static_pie /* relocate dynamic addrs */ xorq %rax, %rax /* cleanup */ popq %rdx |