3714 Commits

Author SHA1 Message Date
Ross Burton
7155971759 Handle musl on PPC32
On Linux, glibc and musl disagree over the layout of the ucontext_t
structure.  For more details, see the musl mailing list:

https://www.openwall.com/lists/musl/2018/02/22/1

Add conditionals to handle both the glibc and musl layout of the
structures.

Closes #709.

Signed-off-by: Ross Burton <ross.burton@arm.com>
2026-01-08 18:57:40 -05:00
Miha Zupan
a0b61b3e1c Avoid C4319 warnings from UNW_ALIGN 2026-01-08 11:32:11 -05:00
Rosen Penev
2978966905 mips/getcontext: set nomips16
This assembly is incompatible with mips16.

Fixes compilation when mips16 is enabled.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2026-01-08 11:15:04 -05:00
dependabot[bot]
659283ff17 Bump the github-actions group with 4 updates
Bumps the github-actions group with 4 updates: [actions/checkout](https://github.com/actions/checkout), [jirutka/setup-alpine](https://github.com/jirutka/setup-alpine), [github/codeql-action](https://github.com/github/codeql-action) and [actions/stale](https://github.com/actions/stale).


Updates `actions/checkout` from 6.0.0 to 6.0.1
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](1af3b93b68...8e8c483db8)

Updates `jirutka/setup-alpine` from 1.3.0 to 1.4.1
- [Release notes](https://github.com/jirutka/setup-alpine/releases)
- [Commits](cf5fddcea4...ae3b3ddba3)

Updates `github/codeql-action` from 4.31.5 to 4.31.9
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](fdbfb4d275...5d4e8d1aca)

Updates `actions/stale` from 10.1.0 to 10.1.1
- [Release notes](https://github.com/actions/stale/releases)
- [Changelog](https://github.com/actions/stale/blob/main/CHANGELOG.md)
- [Commits](5f858e3efb...997185467f)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: 6.0.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: github-actions
- dependency-name: jirutka/setup-alpine
  dependency-version: 1.4.1
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: github-actions
- dependency-name: github/codeql-action
  dependency-version: 4.31.9
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: github-actions
- dependency-name: actions/stale
  dependency-version: 10.1.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: github-actions
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-01-08 11:10:29 -05:00
dependabot[bot]
aee94cd5e8 Bump the github-actions group with 3 updates
Bumps the github-actions group with 3 updates: [actions/checkout](https://github.com/actions/checkout), [github/codeql-action](https://github.com/github/codeql-action) and [actions/stale](https://github.com/actions/stale).


Updates `actions/checkout` from 5.0.0 to 6.0.0
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](08c6903cd8...1af3b93b68)

Updates `github/codeql-action` from 3.30.5 to 4.31.5
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](3599b3baa1...fdbfb4d275)

Updates `actions/stale` from 10.0.0 to 10.1.0
- [Release notes](https://github.com/actions/stale/releases)
- [Changelog](https://github.com/actions/stale/blob/main/CHANGELOG.md)
- [Commits](3a9db7e6a4...5f858e3efb)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: 6.0.0
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: github-actions
- dependency-name: github/codeql-action
  dependency-version: 4.31.5
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: github-actions
- dependency-name: actions/stale
  dependency-version: 10.1.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: github-actions
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-12-10 09:17:14 -05:00
dependabot[bot]
812a5305ff Bump the github-actions group with 2 updates
Bumps the github-actions group with 2 updates: [github/codeql-action](https://github.com/github/codeql-action) and [actions/stale](https://github.com/actions/stale).


Updates `github/codeql-action` from 3.29.11 to 3.30.5
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](3c3833e0f8...3599b3baa1)

Updates `actions/stale` from 9.1.0 to 10.0.0
- [Release notes](https://github.com/actions/stale/releases)
- [Changelog](https://github.com/actions/stale/blob/main/CHANGELOG.md)
- [Commits](5bef64f19d...3a9db7e6a4)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-version: 3.30.5
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: github-actions
- dependency-name: actions/stale
  dependency-version: 10.0.0
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: github-actions
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-11-21 14:29:01 -05:00
Nathan Grasso Bronson
a9b9293b28 _Ux86_64_setcontext should not read from stack after adjusting %rsp 2025-11-21 14:26:58 -05:00
I-Al-Istannen
8f294c4551 dwarf: Select matching text segment when finding unwind table
As an ELF file can have multiple executable segments, `mapoff` refers to
the file offset of the segment containing the current `ip`. However,
`dwarf_find_unwind_table` was not using this information and instead
selected the *last* encountered executable `PT_LOAD` segment.

This causes `loadoff`, `load_base`, and finally `rti.segbase` to be
calculated incorrectly, resulting in the `.eh_frame_hdr` binary search
reading from invalid memory addresses and returning incorrect unwind
information.

Fix this by selecting the `PT_LOAD` segment whose file offset (`p_offset`)
matches `mapoff`, or the first executable segment if no match is found.
2025-11-21 11:56:31 -05:00
Stephen Webb
bfc0d618f7 Fix stray -lc in configure
When configure is run with --enable-cxx-exceptions a stray `-lc` has
wandered into the execution path. While it doesn't hurt anything if
gives a disturbing error message.
2025-09-10 09:52:17 -04:00
Stephen Webb
e8a8b35f5f Disable C++ exception report for HPPA by default
`Ltest-cxx-exceptions` doesn't work, better off not buildinging it by
default.
2025-09-03 08:40:15 -04:00
dependabot[bot]
4ab1dbe714 Bump the github-actions group with 2 updates
Bumps the github-actions group with 2 updates: [actions/checkout](https://github.com/actions/checkout) and [github/codeql-action](https://github.com/github/codeql-action).


Updates `actions/checkout` from 4.2.2 to 5.0.0
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](11bd71901b...08c6903cd8)

Updates `github/codeql-action` from 3.29.7 to 3.29.11
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](51f77329af...3c3833e0f8)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: 5.0.0
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: github-actions
- dependency-name: github/codeql-action
  dependency-version: 3.29.11
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: github-actions
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-09-02 12:20:28 -04: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
Stephen Webb
3c4658cb97 Fix off-by-one in aarch64 unw_backtrace()
The code was subtracting the `use_prev_instr` value twice, resulting in
odd-numbered addresses for the IP in the returned array.
2025-08-28 08:57:15 -04:00
Stephen Webb
5f46ba494c Made -nostdlib depend on exception support
When libunwind is configured to provide the Itanium Level 1 Exception
Support it needs to avoid linking in any compiler runtime libraries that
already provide that support (for example, libgcc_s.so) in order to
avoid duplicate symbols or ODR violations.  This caused a problem on
more recent GCC editions because of some dark magic in which
libgcc_s.so is actually a linker script instead of a shared object so
the library will be underlinked on some platforms.

The use of `-nostdlib` should be limited to only the case in which the
optional exception support is selected at configure time. When that is
the case, we can assume the developer knows what they're doing (they're
writing their own exception handling stack) and can pass the right LDADD
explcitly as required.

This changes makes the use of `-nostdlib` and `-lc -lgcc_s` dependent on
the configure-time `--enable-cxx-exceptions=yes`, which is not the
default.
2025-08-25 11:12:45 -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
kasperk81
2ad7f439d6 Update jmpbuf.h 2025-08-07 13:18:13 -04:00
kasperk81
66f9d10fc8 Implement Gresume for freebsd riscv64 2025-08-07 13:18:13 -04:00
dependabot[bot]
278033e91a Bump github/codeql-action in the github-actions group
Bumps the github-actions group with 1 update: [github/codeql-action](https://github.com/github/codeql-action).


Updates `github/codeql-action` from 3.29.2 to 3.29.5
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](181d5eefc2...51f77329af)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-version: 3.29.5
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: github-actions
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-08-07 08:25:44 -04:00
Ross Burton
b2d2e81e5f mips/getcontext.S: use assembler-friendly byte order symbols
endian.h on musl/mips can't be included in __ASSEMBLER__ mode,
so use the __BYTE_ORDER__ symbol instead.

Signed-off-by: Ross Burton <ross.burton@arm.com>
2025-07-29 08:06:57 -04:00
Stephen Webb
0fca68b9fb Use file offset when reading GNU hash table
All segemnets in an ELF file are not guaranteed to have the same base
virtual address.

Adjusted the GNU hash table address based on the actual file offset of
the segment containing ir rather than the offset of the program table
header itself.
2025-07-25 11:51:10 -04:00
Stephen Webb
637b9ebcde Add support for x86_64 Control-Flow Enforcement
The x86_64 assembly files need to add `enbr64` instructions and a
special ELF note for the GNU gnu.property extension.
2025-07-24 13:42:57 -04:00
dependabot[bot]
4c0446622d Bump github/codeql-action in the github-actions group
---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-version: 3.29.2
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: github-actions
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-07-04 09:01:02 -04:00
dependabot[bot]
2a15c30f7e Bump github/codeql-action in the github-actions group
Bumps the github-actions group with 1 update: [github/codeql-action](https://github.com/github/codeql-action).


Updates `github/codeql-action` from 3.28.16 to 3.28.18
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](28deaeda66...ff0a06e83c)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-version: 3.28.18
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: github-actions
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-06-30 07:55:05 -04:00
Herman Semenov
eeeaa8a77a fix: fixes bit shifting 32bit (1u - unsigned int) with subsequent expansion to 64bit (1ULL - unsigned wide long64)
Type vulnerability:

 - CWE-190 Integer Overflow or Wraparound

References:

 - https://cwe.mitre.org/data/definitions/190.html
2025-06-20 15:01:19 -04:00
Herman Semenov
2c609f5855 mi: removed excess check before free() in label 'out'
C89: 4.10.3.2 The free function.

The free function causes the space pointed to by ptr to be deallocated, that is, made available for further allocation. If ptr is a null pointer, no action occurs.
2025-06-20 11:40:24 -04:00
Stephen Webb
caaa5d7248 Add HPPA as a cross-build CI target 2025-06-16 08:45:57 -04:00
Phong X. Nguyen
7886dbbcdd Remove __linux__ check per PR review 2025-06-13 07:38:29 -04:00
Phong X. Nguyen
230f20100e Avoid NT_ARM_PAC_MASK on older Linux kernels 2025-06-13 07:38:29 -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
Stephen Webb
06dd379a7c Fix typo in README
CI clause under PA-RISC was referring to x86_64.

Also added explicit info on PPC CI failures.
2025-06-06 12:24:57 -04:00
Mathieu Othacehe
09885eb855 Revert "Do not fallback to slow_backtrace when tdep_trace stops unwinding"
This reverts commit 5b195ffd50 because it breaks
both arm and armhf test suites.
2025-06-06 09:12:43 -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
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
Milian Wolff
5b195ffd50 Do not fallback to slow_backtrace when tdep_trace stops unwinding
On an aarch64 system tdep_trace was returning `-UNW_ESTOPUNWIND`
a lot while profiling a Qt 6 / QML application with heaptrack.
I have not understood why exactly, but note that QML injects
JIT frames and more, which potentially lead to such failures?

Without the patch here, unwinding became excessively slow because
the `slow_backtrace` fallback continuously called `tdep_get_elf_image`
which is extremely slow for applications with many entries in their
`/proc/<pid>/maps` file.

With the patch here applied, I could use heaptrack again with
the expected bearable overhead. The backtraces still look fine,
so for me this patch here looks like a good workaround.
2025-06-03 09:19:22 -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
Stephen Webb
197a8f6902 Fix register range check for armv7 QNX coredump 2025-05-28 15:45:04 -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
Mathieu Othacehe
34aa934fd1 arm: Fix resume.
We want to use the LR register, not the PC register to resume to the cursor.
2025-05-28 15:13:23 -04:00
Stephen Webb
55b3c7b81d Fix doc-building config
Change the autoconf rules so that
  - docs are always built and installed unless
    `--enable-documentation=no` is passed
  - the documentation-build tools latex2man and pdflatex are
    autodetected and, if not found, just issue a warning at configure
    time and doc builds do nothing. Since built man pages are under
    source control this should not have a dire effect.

Fixes #822
2025-05-26 15:17:36 -04:00
kasperk81
00b847fea2 add initial freebsd riscv support 2025-05-23 15:19:47 -04:00
Stephen M. Webb
b62977ab32 Read link register from context when unwinding on arm and aarch64
Prevent unw_bactrace family functions from unwinding using the slow path if the fast path had to stop (return -UNW_ESTOPUNWIND).
2025-05-22 10:47:50 -04:00
Gregory LEOCADIE
ecc7060923 Address PR comment 2025-05-22 13:32:26 +02:00
Gregory LEOCADIE
f9855cfd9a Fix crash on QNX 2025-05-22 13:32:26 +02:00
Gregory LEOCADIE
4c341da1d2 Rewrite how we read link register 2025-05-22 13:32:26 +02:00
Gregory LEOCADIE
6eb27584fd Read the R14 register (link register) on arm 2025-05-22 13:32:26 +02:00
Gregory LEOCADIE
3d882574dc Read link register from context on aarch64 2025-05-22 13:30:07 +02:00