aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAurelien Jarno <aurelien@aurel32.net>2021-12-16 00:06:28 +0100
committerAurelien Jarno <aurelien@aurel32.net>2021-12-17 20:29:34 +0100
commit225da459cebef1037dcd78b56471edc0721e1c41 (patch)
tree717a875f9560c97c016761183c9bdfaac73b482c
parentd2e594d71509faf36cf851a69370db34a4f5fa65 (diff)
downloadglibc-225da459cebef1037dcd78b56471edc0721e1c41.tar
glibc-225da459cebef1037dcd78b56471edc0721e1c41.tar.gz
glibc-225da459cebef1037dcd78b56471edc0721e1c41.tar.bz2
glibc-225da459cebef1037dcd78b56471edc0721e1c41.zip
riscv: align stack before calling _dl_init [BZ #28703]
Align the stack pointer to 128 bits during the call to _dl_init() as specified by the RISC-V ABI [1]. This fixes the elf/tst-align2 test. Fixes bug 28703. [1] https://github.com/riscv-non-isa/riscv-elf-psabi-doc
-rw-r--r--sysdeps/riscv/dl-machine.h6
1 files changed, 6 insertions, 0 deletions
diff --git a/sysdeps/riscv/dl-machine.h b/sysdeps/riscv/dl-machine.h
index ce2b3c3875..f457a41c70 100644
--- a/sysdeps/riscv/dl-machine.h
+++ b/sysdeps/riscv/dl-machine.h
@@ -125,8 +125,14 @@ elf_machine_dynamic (void)
sll a3, a1, " STRINGXP (PTRLOG) "\n\
add a3, a3, a2\n\
add a3, a3, " STRINGXP (SZREG) "\n\
+ # Stash the stack pointer in s1.\n\
+ mv s1, sp\n\
+ # Align stack to 128 bits for the _dl_init call.\n\
+ andi sp, sp,-16\n\
# Call the function to run the initializers.\n\
jal _dl_init\n\
+ # Restore the stack pointer for _start.\n\
+ mv sp, s1\n\
# Pass our finalizer function to _start.\n\
lla a0, _dl_fini\n\
# Jump to the user entry point.\n\