llvm / llvm/llvm-project

[PAC][libunwind] Unify signed return address handling logic

Open
#160,110 1 comment 0 reactions 0 assignees Claimed by @kovdan01 View on GitHub
hardening libunwind
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

#143230 introduces libunwind hardening which could be used with pauth-enabled ABIs (such as arm64e for Apple and pauthtest for Linux). This includes handling of signed return addresses. Both mentioned ABIs implicitly enable `-fptrauth-returns` flag, which sets `__has_feature(ptrauth_returns)` to true and triggers RA signing in codegen via setting `"ptrauth-returns"` attribute for functions in IR.

The existing logic in libunwind already handles signed RA - such handling was introduced previously to support signed RA appearing when `-mbranch-protection=pac-ret` is used: https://github.com/llvm/llvm-project/blob/3cb21742193663143800bd86284e0cf395e0cff2/libunwind/src/DwarfInstructions.hpp#L303-L344

Note that existing implementation in libunwind supports different RA sign state in different stack frames. For example, we can build libunwind itself w/o pac-ret enabled, and build user code with pac-ret enabled, and unwinding would work fine since we look at RA sign state in each individual frame.

After #143230, signed RA handling looks as follows:

1. If libunwind is built with pauth-enabled ABIs such as arm64e and pauthtest (which imply `__has_feature(ptrauth_calls) && __has_feature(ptrauth_returns)`, we skip old signed RA handling logic and use signed RA handling logic from #143230.
2. Otherwise, we use old signed RA handling logic.

Actual codegen is the same for `-fptrauth-returns` and `-mbranch-protection=pac-ret`, we just have different ways enabling that (see also https://github.com/llvm/llvm-project/pull/143230#issuecomment-3313311124).

We should unify logic in libunwind for these two cases as well.

Contributor guide

Open the contributing guide

Research direction

Start with libunwind/src/DwarfInstructions.hpp, especially the existing signed return-address handling around the referenced lines, then compare it with the pauth-enabled logic introduced by #143230 and the linked pull request #171717. Confirm how both -fptrauth-returns and -mbranch-protection=pac-ret paths are handled across stack frames; done means the duplicated cases use unified logic without losing per-frame signing behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.