ARM and Thumb support for GCC-compatible static-base PIC data addressing with `-mno-pic-data-is-text-relative`. #239188
All Vouch review confidence checks passed
Residual risk 0.24 = Change Risk (0.45) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.45 · 449 lines diff across 5 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.366
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #239188"
general
weight: 0.35
smithp35
Summary
This adds ARM and Thumb support for GCC-compatible static-base PIC data
addressing with
-mno-pic-data-is-text-relative.The implemented mode is deliberately scoped to the default ARM EABI behavior
used by GCC when text-relative PIC data is disabled: data references are
materialized through GOT offsets relative to an incoming, runtime-initialized
r9static base. The change does not add GCC's wider ARM PIC option surfacefor selecting a different PIC register or explicitly disabling single-PIC-base
code generation.
The PR includes three related pieces:
Clang/LLVM support for the option and ARM lowering.
compiler-rt assembly fixes for runtime files that hand-load global data.
an lld proof test for a minimal static-base PIE startup sequence.
Design
For ARM and Thumb PIC or PIE code,
-mno-pic-data-is-text-relativenow causesdata references to use GOT relocations addressed relative to
r9. Localnon-FDPIC function references remain text-relative; they are not treated as data
references.
Clang forwards the option only for PIC or PIE code generation and diagnoses
non-PIC/non-PIE use. It also rejects the combination with
-ffixed-r9, becausethe implemented ABI mode requires
r9to hold the static base. ExistingROPI/RWPI validation already rejects combinations with PIC and PIE.
The ARM backend reserves
r9when this mode is active, emits the relevant ARMbuild attributes, and lowers data accesses through GOT offsets in SelectionDAG,
FastISel, and GlobalISel. Clang defines
__ARM_PIC_DATA_STATIC_BASE=1for ARMor Thumb PIC/PIE code using this fixed-
r9static-base data mode, so C andassembly startup code can adapt.
The runtime contract is that startup or loader code must initialize
r9to thelinked image's GOT/static-base value before entering compiled code.
Runtime Assembly
Two compiler-rt ARM assembly files had hand-written PC-relative data-symbol load
sequences:
sanitizer_common_interceptors_vfork_arm.inc.Sxray_trampoline_arm.SBoth now use conditional
__ARM_PIC_DATA_STATIC_BASEpaths that load the datasymbol through an
r9-relative GOT entry when the static-base mode is active,while preserving the existing PC-relative sequences otherwise.
Tests
Added coverage includes:
Clang driver forwarding and diagnostics for
-fpic,-fPIC,-fpie,-fPIE, and invalid combinations.multilib flag normalization for text-relative and static-base PIC data modes.
preprocessor coverage for
__ARM_PIC_DATA_STATIC_BASE.ARM, Thumb, Thumb-1, and big-endian code-generation checks.
SelectionDAG, FastISel, and GlobalISel coverage.
object-level relocation and build-attribute checks.
an r9 register-allocation reservation test under register pressure.
compiler-rt assembly tests for
R_ARM_GOT_BRELrelocations.an lld PIE startup proof test showing
r9initialization before GOT use.Local validation:
git diff --checkfocused lld/Clang lit suite:
lld/test/ELF/arm-pie-static-base-startup.sclang/test/CodeGen/arm-pic-data-is-text-relative.cclang/test/CodeGen/arm-pic-data-static-base-proof.cclang/test/CodeGen/arm-pic-data-static-base-r9.cclang/test/Driver/pic.cclang/test/Driver/arm-pic-data-multilib.yamlclang/test/Preprocessor/arm-pic-predefines.cdirect compiler-rt ARM assembly builds in normal PIC and static-base PIC modes
FileCheck relocation checks for the expected
R_ARM_GOT_BRELentriesmanual QEMU smoke tests for both a hand-written and Clang-generated ARM PIE
image using the static-base startup sequence