603 Commits

Author SHA1 Message Date
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
Stephen Webb
7bc6cecda1 Fix some QNX test failures due to syscall name
Two tests were failing on QNX because they hard-code the syscall
function name for raising a signal and the hard-coded function name is
wrong for QNX OS.

Ran the relevant test code through clang-format and fixed additional
issues with Aarch64 scalable vector extension (SVE) on QNX.
2025-08-11 11:38:10 -04:00
H.J. Lu
84607272d8 x86-64: Include <cet.h> for Intel CET
Include <cet.h> when Intel Control-flow Enforcement Technology (CET)
is enabled.  Both GCC and Clang provide <cet.h> which should be included
in assembly codes with .S suffix when -fcf-protection is used.  It will
define _CET_ENDBR (endbr64) and the .note.gnu.property note section.

Fixes #644.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-08-11 08:58:22 -04:00
Mathieu Othacehe
7718ecc1dd arm: Disable test-async-sig.
This test randomly fails on arm because depending on the place where the
signal is received, the backtrace can involve glibc functions such as
"__read", which do not have .EXIDX instructions.
2025-06-03 10:19:47 -04:00
Stephen Webb
f75061c3b6 Removed unused src/arm/getcontext.S
The function in this source file was never used anywhere
(`unw_tdep_getcontext()` is a macro generating inline asm for arm). It
also fails to build from source for any OS other than Linux and FreeBSD.

Removed the file and checks for the symbol.
2025-05-30 14:42:35 -04:00
Mathieu Othacehe
e5f0500eb9 tests: Use sigaction in Gtest-concurrent.
Switch to sigaction instead of signal to setup the signal handler. The former
is deprecated and does not work fine on ARM.
2025-05-28 15:13:23 -04:00
Mathieu Othacehe
f221f09519 arm: Disable tests with UNW_INIT_SIGNAL_FRAME.
unw_init_local2 (&cursor, (unw_context_t*)context, UNW_INIT_SIGNAL_FRAME) with
a context that comes from the signal handler is not implemented on ARM.
2025-05-28 15:13:23 -04:00
Mathieu Othacehe
ee27425bbc arm: Deal with -UNW_ESTOPUNWIND in the tests.
When using .EXIDX based unwinding, some functions are flagged with the
.cantunwind directive. That causes unw_step to stop unwinding and to return
-UNW_ESTOPUNWIND.

Do not consider that as an error in the tests.
2025-05-28 15:13:23 -04:00
Wouter Deconinck
998b2cf3da Disable Ltest-mem-validate test when CONSERVATIVE_CHECKS and x86_64 or s390x 2025-04-15 09:33:09 -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
Gregory LEOCADIE
03a698b85c Fix more warnings 2025-02-25 15:55:23 -05:00
Mathieu Othacehe
d11545d79a tests: Add a DWARF specific backtrace test on ARM 2025-02-25 15:04:01 -05:00
Mathieu Othacehe
26694a75e7 tests: Fix the backtrace test on ARM.
On ARM, we are unwinding using EXIDX by default. This means that the last
unw_step call will return cantunwind. Take that into account by ignoring it.
2025-02-25 15:04:01 -05:00
Mathieu Othacehe
f70a60bc77 arm: Unhide the unwi_unwind_method variable.
Unhide it so that it can be used in the unit tests.
2025-02-25 15:04:01 -05:00
Mathieu Othacehe
d64ff72c36 tests: Improve the backtrace test
Make sure that the backtrace contains at least 3 frames.
2025-02-25 15:04:01 -05:00
Stephen Webb
b67d508a93 Fix bad prototype for malloc() in test
The unit test Gtest-nomalloc.c had an incorrect prototype for malloc()
which caused newer compilers to fail compiling for newer C editions.

Corrected the prototype and corrected a few other errors. The unit now
compiles using GCC with `CFLAGS=-Wall -Wextra -pedantic -C11` with no
warnings, which is the minimum requirement.

Added the tests/unw_test.h header as a first step to cleaning up some
unit tests further.
2025-02-12 16:12:09 -05:00
Stephen Webb
7aadfa552f Fix tdep_trace() returning bad count on aarch64.
`tdep_trace()` did not return the right count value when it did not
complete successfully.

Also rewrote tests/Gtest-trace to (a) add more tests of
`unw_backtrace2()`, (2) give more meaningful verbose output for the poor
humans trying to figure out why it's failing, and (iii) iterate the
signal callback several times to detect cache-related edge cases.
2024-07-22 12:28:24 -04:00
Stephen Webb
585d9c75ad Fix signal handling for aarch64-nto-qnx*
QNX does not put the signal context at a fixed offset in the signal
stack. Need to get the pointer to the context passed by the kernel to
the trampoline instead.

Added unit tests to detect this situation (`[GL]test-sig-context`).
2024-06-18 08:52:51 -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
Stephen Webb
8b9a387171 Add use of libabigail for ABI checks
Added `make -C src check-abi` target to leverage libabigail 2.0 tools to
check for ABI changes.

Add ABI baseline files for aarch64, i686, riscv, s390x, and x86_64 Linux
targets and aarch64 and x86_64 QNX SDP 7.1 targets.

Used the check-abi target in the CI-unix github workflow.
2024-05-14 12:02:11 -04:00
Stephen Webb
8428e1f0ca Replace clobber of CFLAGS in configure.ac
Replaced the clobbering of the user variable CFLAGS in configure.ac with
UNW_EXTRA_CFLAGS.
2024-04-19 09:25:08 -04:00
Stephen Webb
be0b15d68f Replace defining CPPFLAGS in configure.ac
Replaced defining the user variable CPPFLAGS in configure.ac with
UNW_REMOTE_CPPFLAGS and UNW_TARGET_CPPFLAGS.
2024-04-19 09:25:08 -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
Dan Horák
49cb302b53 tests/ppc64-test-plt: add parameter names
ISO C does not support omitting parameter names in function definitions
before C2X, so better add them.

fixes:
ppc64-test-plt.c: In function ‘unw_get_accessors_int’:
ppc64-test-plt.c:10:41: error: parameter name omitted
   10 | unw_accessors_t *unw_get_accessors_int (unw_addr_space_t) { return NULL; }
      |                                         ^~~~~~~~~~~~~~~~
ppc64-test-plt.c: In function ‘_Uppc64_dwarf_step’:
ppc64-test-plt.c:11:17: error: parameter name omitted
   11 | int dwarf_step (struct dwarf_cursor*) { return 0; }
      |                 ^~~~~~~~~~~~~~~~~~~~
make[1]: *** [Makefile:1662: ppc64-test-plt.o] Error 1

seen on ppc64 with gcc 10.3.1
2024-02-15 07:46:44 -05:00
Stephen Webb
7e16c2d244 Make tests installable
Tests will now always be built (unless configured with --disable-tests)
and installed by default in ${prefix}/libexec/libunwind. A new script,
test-runner, is supplied to run all of the tests and produce TAP output.

configure.ac: make tests/check-namespace.sh executable,
    add license boilerplate
tests/Makefile.am: remove run-coredump-unwind, add test-runner,
    add license boilerplate, remove XFAIL for riscv64
tests/README.md: new file
tests/check-namespace.sh.in: make LIBUNWIND and LIBUNWIND_GENERIC
    externally settable, add license boilerplate
tests/run-check-namespace: remove file
test/run-ptrace-mapper: look for test-ptrace relative to script,
    add license boilerplate
test/run-ptrace-misc: look for test-ptrace relative to script,
    add license boilerplate
test/test-runner.in: new file
.github/workflows/CI-unix.yml: change run-check-namespace to
    check-namespace.sh, use libtool to run in-tree binaries instead of
    forcing static linking
2024-02-14 08:55:01 -05:00
Ross Burton
c8499e99dc tests/Garm64-test-sve-signal: check that SVE is present before running tests
If the compiler supports -march=armv8-a+sve then those options are used
to build this test, but all that needs is a sufficiently new compiler.

This then results in the __ARM_FEATURE_SVE check always passing, because
SVE is explicitly enabled.

However it's perfectly possible for the compiler to support +sve but the
machine running the code to not, which results with the test crashing
with "Illegal instruction".

Handle this case by checking HWCAP for SVE support, and skipping the
test unless we know it is available.  This check is Linux-specific at
present, but the logic is easily extended.

Signed-off-by: Ross Burton <ross.burton@arm.com>
2024-01-19 08:28:59 -05:00
Stephen M. Webb
c7e653f431 Simplify test-coredump-unwind
This test source had all kinds of bells and whistles added, requiring all kinds
of (non-portable) dependencies that were never really used. Removed the extra
stuff (logging through syslog, catching segfaults).

Also remove the build dependency on libbacktrace since it actually causes
conflicts with libunwind.
2023-12-31 09:45:45 -05:00
Stephen M. Webb
41ff26e8e4 Remove coredump/_UCD_lib.h
This header file was included in all the other coredump sources and pulled in a
slew of system headers, none of which were used anywhere. Some of those headers
did not even exist on all supported targets.

Fewer build dependencies, fewer build failures, no change in functionality.
2023-12-31 09:45:45 -05:00
Stephen Webb
5dc97eb19c Annotate XFAILs in tests/Makefile.am
Added links back to github issues for most XFAILS in tests/Makefile.am.
Also added additional XFAILS for PPC32 (with links).
2023-12-02 10:00:26 -05:00
Stephen Webb
75281907d3 Use header for test function prototype
Some of the unit test code was bringing an extern function prototype
into scoe in a function body. The idiomatic and expected way to do this
is by using a header file and not adhering to the idiom not only
increases the cognitive load of the reader but tgriggers warning from
static analysis tools.

This change just does it the right way instead. No functional change.
2023-11-29 15:47:17 -05:00
Kent Cheung
02006007bd Further improvements to unw_step fallback method on AArch64.
Frame pointer (FP) cannot always be relied upon if DWARF unwinding
fails. Depending on position in the function prologue/epilogue, the
frame record may be pointed to by the FP, SP, or at an offset to SP.
Detect which case it is by inspecting the function disassembly and
matching to known frame record store/load instructions.

Unittest added to verify different frame record store/load methods are
detected when given real function examples from a python2.7 binary.
2023-11-24 15:29:15 -05:00
Stephen Webb
a9a110f768 Fixed local variable hiding a global variable
This issue was found by static analysis. It makes comprehending what the
tests do a little more difficult. There is no functional change.

Verified on Ubuntu 20.04 x86_64.
2023-11-13 10:16:26 -05:00
Xiang.Lin
8563227423 Add tests for unw_get_elf_filename 2023-09-15 13:43:35 -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
Kent Cheung
90e3e53f01 Improved AArch64 is_plt_entry implementation
Previous implementation could only handle cases where IP was at the
first instruction in the PLT. This change implements detecting PLT
entries regardless of where the current IP is within the entry.

Added AArch64-only unittest for is_plt_entry. Mock instructions are set
up for testing, using different offsets and non-PLT replacements.
2023-08-22 10:58:22 -04:00
kasperk81 k
5c0f5237f7 typos 2023-08-06 07:05:56 -04:00
hubin
4a542a787f tests/mapper: avoid calling printf between SIGUSR1 and SIGUSR2
glibc printf() needs using atomic instruction to acquire the stdout lock.
Under ARMv8.0 ISA, atomic instruction is realized using LL-SC routine, which
will keep retrying if other cpu accesses the target memory during the atomic
instruction.
In mapper testcase, parent process uses ptrace to single step mapper program,
thus if calling printf between SIGUSR1 and SIGUSR2, printf will be single-
step executed, and the atomic instruction will be stuck in deadloop.
2023-07-07 11:55:46 -04:00
Ziyang Chen
634206d8fe Fix run-ptrace-mapper test case failed by allowing unw_get_proc_info() return unsuccessful result. 2023-07-06 14:23:13 -04:00
Kent Cheung
ae6f1d4b9f Corrected restriction for plt check and test to little endian. 2023-07-06 13:57:03 -04:00
Kent Cheung
0d6d11326f Limited plt check to big endian only. 2023-07-06 13:57:03 -04:00
Kent Cheung
78066de654 Addressed static linking failure in unittest. 2023-07-06 13:57:03 -04:00
Kent Cheung
00376d19ab Added support for unwinding through PPC64 PLT entries.
Added function to detect when specified IP is within a PLT entry. This
is determined by reading surrounding instructions and matching them to
known PPC64 PLT procedure instructions.

Added PPC64-only unittest for is_plt_entry. Mock instructions are set up
for testing, using different offsets and non-PLT replacements.
2023-07-06 13:57:03 -04: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
72c03e44f1 Improve test-mem-validate.
For testing mprotect consume_and_run() stack region, calculate steps
ans handle stack grows direction.
2023-07-05 09:14:08 -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
5e35c32866 Add basic local unwinding on QNX x86_64
Adds OS-specific functionality to the x86_64 target for QNX OS.

Fixes some miscellaneous portability issues.

Disables the setjmp module build by default for QNX OS since it's not
supported at all.
2023-06-27 10:07:32 -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
Stephen Webb
478046442c Make use of -lpthreads autodetected by configury
Not all targets have a separate pthread library. Make it autodetected in
configure.

Refactored a number of the optionally enabled things in configure.ac for
the following reasons.

  1. Their dependencies are only checked when the feature is enabled
  2. reduce redundant checks
  3. Add defaults to the --help message
  4. Group related check and messages together
  5. Improve user feedback
  6. Make grammatic voice and style more consistent

There should be no functional changes to what gets built and when.
2023-06-14 16:09:31 -04:00