| Issue |
238194
|
| Summary |
[AArch64][HWASan][BTI] __hwasan_personality_thunk gets no bti c in a BTI-marked object when the functions using it opt out of BTI
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
zjy-dev
|
`HWAddressSanitizer::instrumentPersonalityFunctions` creates
`__hwasan_personality_thunk.<personality>` (linkonce_odr, comdat). It adds
`"branch-target-enforcement"` only if one of the wrapped functions has that attribute. It does
not check the module flag `branch-target-enforcement`. If the functions in a TU that need the thunk all use
`__attribute__((target("branch-protection=none")))`, the thunk has no `bti c`. The object is still
marked BTI (`GNU_PROPERTY_AARCH64_FEATURE_1_BTI`, `Tag_Feature_BTI`). The unwinder calls the
thunk indirectly through `DW.ref.__hwasan_personality_thunk.*`, so on BTI-enforcing hardware
exception unwinding faults. Because the thunk is a comdat shared by all TUs, the linker can pick
this copy for the whole program.
```cpp
void may_throw();
struct Obj { ~Obj(); };
__attribute__((target("branch-protection=none"))) // remove this line -> control
void f() { Obj o; may_throw(); }
```
Compile flag: `clang++ --target=aarch64-linux-gnu -O2 -fsanitize=hwaddress -mbranch-protection=bti -S`
```asm
// with target("branch-protection=none") on f
__hwasan_personality_thunk.__gxx_personality_v0:
adrp x5, :got:__gxx_personality_v0 // no `bti c` / `hint #34`
.aeabi_attribute 0, 1 // Tag_Feature_BTI (object still marked BTI)
.word 3221225472 // GNU_PROPERTY_AARCH64_FEATURE_1_AND
.word 4
.word 1 // ... _BTI
// control (no attribute on f)
__hwasan_personality_thunk.__gxx_personality_v0:
hint #34 // bti c
adrp x5, :got:__gxx_personality_v0
```
Godbolt clang trunk (2026-11-01) gives the same output.
**Root cause.** `llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp:1893-1898` uses
`Function::Create` and derives BTI only from `any_of(P.second, hasFnAttribute("branch-target-enforcement"))`.
The opt-out removes the function attribute but keeps the module flag (`!"branch-target-enforcement", i32 2`)
and the BTI ELF marking, so the thunk's attributes do not match the object's BTI property.
**Suggested fix.** Create the thunk with `Function::createWithDefaultAttr` (it already adds
`branch-target-enforcement`, `sign-return-address`, etc. from module flags, Function.cpp:407-432),
or OR the module flag into the existing `any_of` check.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs