The MUSL libc setjmp/longjmp handling differs from the GNU libc
setjmp/longjmp handling. It may not be possible to properly support
sigsetjmp/siglongjmp on MUSL libc.
1. Add a configure option, --enable-cet, to compile libunwind with
"-mshstk -fcf-protection" and link with -Wl,-z,cet-report=error.
CET is always enabled if -fcf-protection is on by default.
2. Add a frames field to struct cursor and update unw_step to cont stack
frames to pop.
3. Update x86_64_sigreturn to pop 4 shadow stack frames.
4. Update x86_64_local_resume to pop the same number of shadow stack
frames as the regular stack frames.
5. Update _Ux86_64_setcontext to pop 2 shadow stack frames.
There are no failures with
$ ./configure --enable-cet
$ make -j12
$ GLIBC_TUNABLES=glibc.cpu.hwcaps=SHSTK make check
on Linux when shadow stack is enabled.
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
This reverts commit a4014f3377. The
implementation of the pre-linking support is wrong. It assumes that only
pre-linked libraries will have the virtual address of the LOAD ELF section set
to non-zero.
On arm-linux-gnueabi, without pre-linking, we have:
LOAD 0x000000 0x00010000 0x00010000 0x267fc 0x267fc R E 0x10000
Which means that load_offset is set to 0x10000 and incorrectly substracted
from ip - ip_base. It also seems that pre-linking support is vastly
deprecated.
Reverting that one fixes .debug_frame based unwinding of arm-linux-gnueabi.
Fix the following warning by making sure that r1 is the first register in the
register list. It means that r0 has to be saved beforehand outside of the
stmia instruction.
{standard input}:333: Warning: if writeback register is in list, it must be
the lowest reg in the list
A (new) unit test was failing at -O0 because it referenced functions
private to the implementation and not exposed through the shared library
ABI. To fix this, the shared library(ies) are now built using a
convenience library, which can also be directly linked to unit tests so
the private functions can be exposed.
This is the first step to greatly expanded unit testing (ie. testing at
unit seams instead of integration testing only at the public API level).
Only one single unit test for the AARCH64 architecture is fully enabled
at this point.
Fixes#841
- Support for pac-ret on aarch64 existed partially before inside the
DWARF parser but this needed applying elsewhere in the code
- Move PAC mask stripping functions to be accessible from more places
and rename to `tdep_ptrauth_insn_mask` for consistency with the
corresponding accessor function
- Apply PAC stripping in appropriate places
- Add ptrace accessor function implementation for `ptrauth_insn_mask`
- make check is now passing on aarch64 when compiled with
`CFLAGS="-mbranch-protection=standard"`
- There is an extra function in the ptrace library ABI now
(`_UPT_ptrauth_insn_mask`) but there are also some other ABI changes
reported by libabigail / `make abi-check` that are unrelated to this
change, so I am not sure whether to proceed with updating the .abi
files or not
Closes#647
Signed-off-by: Lexi Kane <lexi.kane@arm.com>
The mi_mmap() function bypassed the standard libc mmap() call and directly invoked syscall(). This caused a "bad address" error on s390x due to differences in how parameters are passed and handled to syscalls on s390x. To avoid this issue, it's recommended to fall back to using the libc mmap() implementation for s390x.
Signed-off-by: sankalpjha555 <sankalp@ibm.com>
Enabling debug mode was convoluted and added cognitive load.
This change simplifies how the configuration option --enable-debug works
by simply adding -DUNW_DEBUG=1 to the preprocesor flags via a specific
confiuration variable, accomplishing the folowing goals.
- don't clobber the CPPFLAGS user variable
- don't mess with -DNDEBUG which has other meanings orthogonal
to libunwind debug mode
- don't hide the definition of the ABI-changing build-time option
behind an ifdef in an internal header file
In addition I added a warning to confogure --help to point out that
enabling the option changes the ABI. Caveat lector.
QNX aarch64 kernel call without frame pointer and cfi directives,
this will fallback to use frame pointer unwinder, but the frame pointer
is caller's frame pointer, causing caller frame be skipped.
Try to sniff kernel call pattern, get procedure's ip range by symtab
and do the matchup from the beginning of procedure. If matched, then
fallback to use link register unwinder.
This target is no longer supported by common toolchains or operating
systems. If support is required, it can still be found in libunwind
version 1.7 and earlier.
Eliminated all build warnings coming from `make check` with
CFLAGS="-Wall -Wextra" (and some "-pedantic") for an x86_64 target (GCC
9 Ubuntu 16.04, GCC 10 Ubuntu 20.04). Except for the "Implement
get_list_addr(), please." beg.
This was mostly tagging various parameters as "maybe unused", but there
were a few other changes like assigning to the correct member of
sa_handler and casting things to the right type.
This will hopefully reduce the noise in builds.
The unit test test-ptrace was failing on x86 targets. This was for 3
unrelated reasons.
1. mi_mmap() was bypassing the libc mmap() call and invoking syscall()
instead. Unfortunately on x86 Linux the direct syscall is not supported
because of the way parameters are passed to syscalls. Fall back to the
libc mmap() for x86-linux.
2. The ptrace(PTRACE_GETREGSET) call just returns an error no x86-linux.
Fall back to using ptrace(PTRACE_GETREGS) instead. That only works if
the parameters are passed in the correct order (they were reveresed).
This might break on Solaris.
3. The CI test run as multilibbed tests (running 32-bit binaries on a
64-bit OS). The test itself runs a 64-bit binary (`ls`) and the elfxx.c
code built into libunwind can not handle multilibbed use although it's
supposed to be the fundamental architecture of the library. That's a
differenmt issue though, so in the mean time XFAIL the test in CI.
This required using unw_context_t consistently and removing the volatile
qualifier for sigset_t values in test-setjmp (it doesn't do what I think
the author though it did).
Previous changes to save floating-point registers missed adding
postincrement to the STM command so the floating-point regs were
overwriting the integer regs.
Logic was reversed when initializing the debug level, resulting in
incorrectly formatted output.
Added comments of #if/#else/#endif to make following the code a little
easier.
The pre-processor directives are interpreted before the code in compiled
so there is no connection between compiler identifiers and pre-processor
identifiers.
On the FreeBSD syscall() function returns int, on 64-bit the conversion
long perfoms the sign extension here.