| Issue |
240690
|
| Summary |
[Driver][AArch64] ToolChain::getAArch64MultilibFlags Only Inspects OPT_mbranch_protection_EQ and Ignores OPT_msign_return_address_EQ Override Order
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
zjy-dev
|
In `CollectARMPACBTIOptions` (used for AArch64 codegen), the effective branch-protection configuration is determined by `Args.getLastArg(options::OPT_msign_return_address_EQ, options::OPT_mbranch_protection_EQ)` (right-most flag wins). However, in `ToolChain::getAArch64MultilibFlags` (clang/lib/Driver/ToolChain.cpp:308-312), the driver queries `const Arg *BranchProtectionArg = Args.getLastArgNoClaim(options::OPT_mbranch_protection_EQ);` and completely ignores `OPT_msign_return_address_EQ`. Consequently: (1) passing `-msign-return-address=all` or `-msign-return-address=non-leaf` emits PAC-signed code but omits `-mbranch-protection=...` from multilib selection; and (2) passing `-mbranch-protection=standard -msign-return-address=none` disables PAC/BTI in codegen while `getAArch64MultilibFlags` still reports `-mbranch-protection=standard`.
### Reproducer (`trigger.c`)
```c
int f(void) { return 0; }
```
Compile / reproduction command (`['--target=aarch64-none-elf', '-mbranch-protection=standard', '-msign-return-address=none', '-print-multi-flags-experimental', '-S']`):
```bash
podman exec -i -e TMPDIR=/dev/shm defuzz-toolchain-daemon /opt/llvm23/bin/clang --target=aarch64-none-elf -mbranch-protection=standard -msign-return-address=none -print-multi-flags-experimental -x c - -S -o -
```
Observed output on LLVM 23.1.2:
```text
--target=aarch64-unknown-none-elf
-fexceptions
-fno-pic
-frtti
-march=armv8-a+fp+simd
-mbranch-protection=standard
-munaligned-access
```
### Expected behavior
`ToolChain::getAArch64MultilibFlags` must use `Args.getLastArgNoClaim(options::OPT_msign_return_address_EQ, options::OPT_mbranch_protection_EQ)` and map `-msign-return-address={none,non-leaf,all}` to the corresponding `-mbranch-protection=` multilib flag.
### Root cause & impact
- **Source location**: `clang/lib/Driver/ToolChain.cpp:308-312; clang/lib/Driver/ToolChains/Arch/ARM.cpp:940-950`
- **Impact**: Causes multilib selection mismatch on AArch64 toolchains: `-msign-return-address=all` links against unhardened non-PAC runtime libraries, while `-mbranch-protection=standard -msign-return-address=none` reports `standard` branch protection in multilib flags despite generating unhardened code.
### Suggested fix
In `clang/lib/Driver/ToolChain.cpp:308-312`, query `Args.getLastArgNoClaim(options::OPT_msign_return_address_EQ, options::OPT_mbranch_protection_EQ)` and translate `OPT_msign_return_address_EQ` (`non-leaf` -> `-mbranch-protection=pac-ret`, `all` -> `-mbranch-protection=pac-ret+leaf`, `none` -> omit).
Environment: LLVM 23.1.2 (`llvmorg-23.1.2`), affected targets: `aarch64`.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs