diff options
author | Peter Wemm <peter@FreeBSD.org> | 2004-03-21 01:43:39 +0000 |
---|---|---|
committer | Peter Wemm <peter@FreeBSD.org> | 2004-03-21 01:43:39 +0000 |
commit | c707fea10b76b3723a1ed53ac5fbc164bd64cf0a (patch) | |
tree | 53a3c1e90f84179d25360d9b62c3830ebadcde7d /libexec | |
parent | 6beee8df28faf8054a1b09c0a2ed7252a1d58074 (diff) | |
download | src-c707fea10b76b3723a1ed53ac5fbc164bd64cf0a.tar.gz src-c707fea10b76b3723a1ed53ac5fbc164bd64cf0a.zip |
More stack alignment fixes. Arrange so we call _rtld() in ld-elf.so.1
with the correct alignment. This is important because this calls to
library static constructors are made from here. The bug in the old crt*.s
files hid this because in this case, two wrongs do indeed make a right.
Also, call _rtld_bind() with the correct alignment, because it calls back
into the pthread library locking functions. If things happen just
the wrong way, we get a SIG10 due to the broken stack alignment.
Notes
Notes:
svn path=/head/; revision=127254
Diffstat (limited to 'libexec')
-rw-r--r-- | libexec/rtld-elf/amd64/rtld_start.S | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/libexec/rtld-elf/amd64/rtld_start.S b/libexec/rtld-elf/amd64/rtld_start.S index c2c6b9c6dced..4cdad22b0557 100644 --- a/libexec/rtld-elf/amd64/rtld_start.S +++ b/libexec/rtld-elf/amd64/rtld_start.S @@ -31,14 +31,13 @@ .type .rtld_start,@function .rtld_start: xorq %rbp,%rbp # Clear frame pointer for good form - subq $16,%rsp # A place to store exit procedure addr + subq $24,%rsp # A place to store exit procedure addr movq %rdi,%r12 movq %rsp,%rsi # save address of exit proc movq %rsp,%rdx # construct address of obj_main addq $8,%rdx call _rtld@PLT # Call rtld(sp); returns entry point popq %rsi # Get exit procedure address - addq $8,%rsp # Ignore obj_main movq %r12,%rdi # *ap /* * At this point, %rax contains the entry point of the main program, and @@ -62,8 +61,9 @@ * assembly-language code that is not ABI-compliant. * * Stack map: - * reloff 0x58 - * obj 0x50 + * reloff 0x60 + * obj 0x58 + * spare 0x50 * rflags 0x48 * rax 0x40 * rdx 0x38 @@ -79,6 +79,7 @@ .globl _rtld_bind_start .type _rtld_bind_start,@function _rtld_bind_start: + subq $8,%rsp pushfq # Save rflags pushq %rax # Save %rax pushq %rdx # Save %rdx @@ -90,15 +91,15 @@ _rtld_bind_start: pushq %r10 # Save %r10 pushq %r11 # Save %r11 - movq 0x50(%rsp),%rdi # Fetch obj argument - movq 0x58(%rsp),%rsi # Fetch reloff argument + movq 0x58(%rsp),%rdi # Fetch obj argument + movq 0x60(%rsp),%rsi # Fetch reloff argument leaq (%rsi,%rsi,2),%rsi # multiply by 3 leaq (,%rsi,8),%rsi # now 8, for 24 (sizeof Elf_Rela) call _rtld_bind@PLT # Transfer control to the binder /* Now %rax contains the entry point of the function being called. */ - movq %rax,0x58(%rsp) # Store target over reloff argument + movq %rax,0x60(%rsp) # Store target over reloff argument popq %r11 # Restore %r11 popq %r10 # Restore %r10 popq %r9 # Restore %r9 @@ -109,5 +110,5 @@ _rtld_bind_start: popq %rdx # Restore %rdx popq %rax # Restore %rax popfq # Restore rflags - leaq 8(%rsp),%rsp # Discard obj, do not change rflags + leaq 16(%rsp),%rsp # Discard spare, obj, do not change rflags ret # "Return" to target address |