llvm-project
4a70cd6c - [BOLT][AArch64] Support BTI-hardened binaries in Clustered Relaxation (#234122)

Commit
5 hours ago
[BOLT][AArch64] Support BTI-hardened binaries in Clustered Relaxation (#234122) Clustered relaxation can extend an out-of-range call with an indirect ADRP/ADD/BR thunk. In a BTI binary, its target needs a compatible landing pad. Adding a pad to a rewritten fragment after local branch relaxation changes the fragment size and can put an already relaxed local branch out of range. For in-layout calls in BTI binaries, use chains of direct B thunks, without applying the configured chain-length limit. Direct branches do not require additional landing pads. The same machinery already relaxes unconditional control-flow branches, which cannot use long thunks because they must not clobber x16/x17. Non-BTI calls retain the configured limit and can fall back to long thunks. If a landing pad is already present then long thunks can still be used for BTI calls. A chain with multiple thunks can add branch latency compared with an indirect long thunk. With the default 124 MiB clusters, a normally sized two-cluster layout needs at most one thunk, which the default non-BTI policy also permits. Hot code is expected to be grouped together, so multi-cluster calls are likely to be cold, but this is not guaranteed for very large binaries. We have not measured the performance impact of multi-hop chains. An alternative is an indirect long thunk targeting a BTI-padded short veneer near the destination. That would bound the number of extra direct branches but requires additional placement, reuse, and range accounting. Another alternative is to insert landing pads before local relaxation; without the final layout, this can add unnecessary pads and code size. Direct chains reuse the existing relaxation machinery and avoid those complications, at the cost of potentially longer call paths. Calls to out-of-layout targets still use long thunks and need BTI fixups. Defer those fixups until the new output function list is installed, because they can add patch functions for old-text or PLT entries to that list. ClusteredRelaxation now owns and installs the list before applying fixups, making the relaxWithClusters wrapper unnecessary. Replace the unsigned maximum-value sentinels in clustered relaxation with std::numeric_limits. Tests cover old-to-new and new-to-old BTI fixups, in-layout multi-hop chains, skipped functions, and PLT entries.
Author
Parents
Loading