It turns out the startup code in csu/elf-init.c has a perfect pair of
ROP gadgets (see Marco-Gisbert and Ripoll-Ripoll, "return-to-csu: A
New Method to Bypass 64-bit Linux ASLR"). These functions are not
needed in dynamically-linked binaries because DT_INIT/DT_INIT_ARRAY
are already processed by the dynamic linker. However, the dynamic
linker skipped the main program for some reason. For maximum
backwards compatibility, this is not changed, and instead, the main
map is consulted from __libc_start_main if the init function argument
is a NULL pointer.
For statically linked binaries, the old approach based on linker
symbols is still used because there is nothing else available.
A new symbol version __libc_start_main@@GLIBC_2.34 is introduced because
new binaries running on an old libc would not run their ELF
constructors, leading to difficult-to-debug issues.
I used these shell commands:
../glibc/scripts/update-copyrights $PWD/../gnulib/build-aux/update-copyright
(cd ../glibc && git commit -am"[this commit message]")
and then ignored the output, which consisted lines saying "FOO: warning:
copyright statement not found" for each of 6694 files FOO.
I then removed trailing white space from benchtests/bench-pthread-locks.c
and iconvdata/tst-iconv-big5-hkscs-to-2ucs4.c, to work around this
diagnostic from Savannah:
remote: *** pre-commit check failed ...
remote: *** error: lines with trailing whitespace found
remote: error: hook declined to update refs/heads/master
Mark the ra register as undefined in _start, so that unwinding through
main works correctly. Also, don't use a tail call so that ra points after
the call to __libc_start_main, not after the previous call.
This patch contains code that needs to directly know about the RISC-V
ABI, which is specified in a work-in-progress psABI document:
https://github.com/riscv/riscv-elf-psabi-doc/blob/master/riscv-elf.md
This is meant to contain all the RISC-V code that needs to explicitly
name registers or manage in-memory structure layout. This does not
contain any of the Linux-specific code.
2018-01-29 Palmer Dabbelt <palmer@sifive.com>
* sysdeps/riscv/__longjmp.S: New file.
* sysdeps/riscv/backtrace.c: Likewise.
* sysdeps/riscv/bits/endian.h: Likewise.
* sysdeps/riscv/bits/setjmp.h: Likewise.
* sysdeps/riscv/bits/wordsize.h: Likewise.
* sysdeps/riscv/bsd-_setjmp.c: Likewise.
* sysdeps/riscv/bsd-setjmp.c: Likewise.
* sysdeps/riscv/dl-trampoline.S: Likewise.
* sysdeps/riscv/gccframe.h: Likewise.
* sysdeps/riscv/jmpbuf-offsets.h: Likewise.
* sysdeps/riscv/jmpbuf-unwind.h: Likewise.
* sysdeps/riscv/machine-gmon.h: Likewise.
* sysdeps/riscv/memusage.h: Likewise.
* sysdeps/riscv/setjmp.S: Likewise.
* sysdeps/riscv/sys/asm.h: Likewise.
* sysdeps/riscv/tls-macros.h: Likewise.