569 Commits

Author SHA1 Message Date
Miha Zupan
a0b61b3e1c Avoid C4319 warnings from UNW_ALIGN 2026-01-08 11:32:11 -05:00
Stephen M. Webb
bf6ee1169a Add setjmp support for aarch64-linux-musl
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.
2025-09-02 09:48:53 -04:00
H.J. Lu
155b3d90f4 x86-64: Add a configure option to enable Intel CET
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>
2025-08-25 08:27:16 -04:00
kasperk81
2ad7f439d6 Update jmpbuf.h 2025-08-07 13:18:13 -04:00
danglin44
f7a07922b8 Improve hppa support
Various tweaks to the HPPA-specific code to improve the unit test pass
rate.
2025-06-09 13:34:11 -04:00
Mathieu Othacehe
62dfb32339 Revert "Fix unwinding of pre-linked libraries"
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.
2025-06-03 10:19:47 -04:00
kasperk81
00b847fea2 add initial freebsd riscv support 2025-05-23 15:19:47 -04:00
Mathieu Othacehe
c3042adcea arm: Fix assembly warning.
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
2025-05-14 05:52:15 -04:00
Adam Lackorzynski
b31806304b riscv: Add dwarf_{put,get}fp for double-size words
On riscv32, xlen is 32, while flen can be 64 depending on the model
used.
2025-05-02 12:02:05 -04:00
Stephen Webb
1c862c3aae Build libunwind using convenience libs
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
2025-04-15 09:00:19 -04:00
Stijn Lemm
fa421e4fc4 Remove undefined functions from public coredump header. Removed in #363 2025-04-10 13:16:47 -04:00
Lexi Kane
177deb5f89 Support -mbranch-protection=pac-ret on aarch64
- 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>
2025-02-28 12:40:13 -05:00
Gregory LEOCADIE
03a698b85c Fix more warnings 2025-02-25 15:55:23 -05:00
Sankalp
7cc4c20fbc Fixed Gtest-sig-context and Ltest-sig-context
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>
2024-08-30 15:46:28 -04:00
Stephen Webb
9fd5fe66ff Add unw_is_plt_entry() to public API
Moved this function into the public API. Adjusted unit tests
accordingly.
2024-06-14 07:57:45 -04:00
Ian Zborovsky
0be67323b2 Fixed miscompilation of unw_getcontext() on ARM 2024-05-07 08:39:33 -04:00
Stephen Webb
6aa693e7e0 Simplify --enable-debug
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.
2024-04-19 09:25:08 -04:00
Aaron Robinson
f079064b19 Address warnings from MSVC (#734)
* Address warnings from MSVC

These issues were found when enabling
C4242 and C4244 warnings.

* Add support on CI
2024-04-03 13:37:43 -04:00
Adeel Mujahid
76587c9e51 Fix win-x64 crossbuild (remote unwind) 2024-01-18 11:36:07 -05:00
Adeel Mujahid
4faebf4d8b Check existence of attribute 2024-01-16 09:23:10 -05:00
Stephen Webb
995590e02d Fix edge condition in unw_address_is_valid
Logic was skipping the last page in a multi-page check.
2023-11-28 08:38:28 -05:00
Stephen Webb
5f24bd6d9e Remove include/x86/jmpbuf.h
This file had been superceded by include/tdep-x86/jmpbuf.h, wasn't used
anywhere, and not even distributed.
2023-11-21 12:50:35 -05:00
Bert Wesarg
1b783a8e68 Ensure that structs are not empty
Closes #434

Signed-off-by: Bert Wesarg <bert.wesarg@tu-dresden.de>
2023-11-01 09:22:32 -04:00
Giovanni Mascellani
b65d0b3af7 Import config.h before dwarf-config.h.
Header tdep-x86_64/dwarf-config.h depends on config.h because it uses
CONFIG_MSABI_SUPPORT.
2023-09-20 10:56:54 -04:00
Xiang.Lin
d7e59261fe Get elf filename and fileoffset from ip
For the case that can't get symbol info on board, it's a benefit
if can get filename and offset, then use addr2line to decode on host.
2023-09-15 13:43:35 -04:00
Xiang.Lin
a35ff787bf Fix lose caller frame of kernel call on QNX aarch64
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.
2023-09-04 09:32:19 -04:00
Kent Cheung
70f4f920e7 Use pthread_sigmask instead of sigprocmask
pthread_sigmask use in multithreaded programs is explicitly specified by POSIX.1.
2023-08-14 10:37:45 -04:00
Dmitry Chagin
032abaaac2 Implement unw_resume for FreeBSD/Aarch64. 2023-07-07 00:10:16 +03:00
Dmitry Chagin
599e2db62a Unify the way we search for a frame by stack pointer
Due to the fact that it highly depends on the platform and OS adding
the opportunity to specify stack shift for all ports independently.
2023-07-07 00:08:34 +03:00
Stephen Webb
2c1613b7ad Remove tilegx as a target
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.
2023-07-05 14:03:58 -04:00
Dmitry Chagin
273c231510 Fix uc_addr() for FreeBSD/Aarch64.
On FreeBSD the Neon registers are preserved in the mc_fpregs of
the machine context structure.
2023-07-04 09:01:57 -04:00
Stephen Webb
a9e1cb6c18 Add nto remote
QNX OS uses a special nto remote instead of the ptrace used by Linux and
the BSDs.
2023-06-27 10:07:33 -04:00
Stephen Webb
5ba9f7e804 Add basic local unwinding on QNX aarch64
Basic local unwinding on QNX aarch64 target.
2023-06-27 10:07:33 -04:00
Stephen Webb
ea8e99b9f1 Rebase on mainline 2023-06-22 11:54:57 -04:00
Stephen M. Webb
26b0cfc407 Eliminate x86_64 build warnings
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.
2023-06-15 10:43:21 -04:00
Dmitry Chagin
6cb8916b5c Implement _UI_siglongjmp_cont for FreeBSD/x86_64. 2023-06-13 22:17:07 -04:00
Dmitry Chagin
bd2f6fc73f Reduce warnings on FreeBSD/x86_64, unhide tdep_stash_frame under __linux__
as it's should be OS independent.
2023-06-12 22:06:54 -04:00
Stephen Webb
a4da394095 Resync on upstream mainline 2023-06-06 12:49:15 -04:00
Stephen Webb
a58eab7494 Fix test-ptrace on x86-linux target
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.
2023-06-06 12:23:51 -04:00
Stephen Webb
76f57b1dff Use unw_address_is_valid() for more targets
Converted aarch64, riscv, s390x and loongarch64 targets to use thsi new
function instead of cut'n'paste code sharing.
2023-06-05 15:34:19 -04:00
Stephen Webb
b3549c98c4 Add new global unw_address_is_valid()
Replaced validate_mem() for x86_64 targets with a generic
unw_address_is_valid().
2023-06-05 12:36:10 -04:00
Dmitry Chagin
1b480c9936 Implement signal frame unwinding for FreeBSD/aarch64.
Closes #407
2023-06-02 15:13:40 -04:00
Stephen Webb
9ab9547fd6 Fix build warnings for aarch64-linux targets
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).
2023-05-31 14:44:16 -04:00
Stephen Webb
f2e180d209 Fix arm unw_getcontext() missing increment
Previous changes to save floating-point registers missed adding
postincrement to the STM command so the floating-point regs were
overwriting the integer regs.
2023-05-26 15:13:53 -04:00
Stephen Webb
0db82f9d6f Undefined UNW_DEBUG_LEVEL by default 2023-05-23 15:44:50 -04:00
Stephen Webb
ee08162962 Fix broken Windows cross-build 2023-05-23 15:44:50 -04:00
Stephen Webb
68a70e8030 Fix reversed logic in Debug()
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.
2023-05-23 15:44:50 -04:00
Dmitry Chagin
921eee5ee2 Fix unw_getcontext on FreeBSD Aarch64.
Initialize x0 by machine context offset, not by value of the first gpr on the stack.
2023-05-20 08:48:02 -04:00
Dmitry Chagin
995150a872 Fix a bug introduced in 5010beb0.
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.
2023-05-20 08:48:02 -04:00
Stephen Webb
c72a010b6c Make Debug() signal-safe
The Debug() function was using fprintf(), which is not signal safe.

Fixes GH issue #505
2023-05-18 15:49:12 -04:00