← Back to Pull requests

ARM and Thumb support for GCC-compatible static-base PIC data addressing with `-mno-pic-data-is-text-relative`. #239188

Open
unknown opened this pull request with 449 lines diff across 5 files
View on GitHub
unknown unknown commented on Nov 05, 2026 11:24 UTC
Author

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
r9 static base. The change does not add GCC's wider ARM PIC option surface
for 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-relative now causes
data references to use GOT relocations addressed relative to r9. Local
non-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, because
the implemented ABI mode requires r9 to hold the static base. Existing
ROPI/RWPI validation already rejects combinations with PIC and PIE.

The ARM backend reserves r9 when this mode is active, emits the relevant ARM
build attributes, and lowers data accesses through GOT offsets in SelectionDAG,
FastISel, and GlobalISel. Clang defines __ARM_PIC_DATA_STATIC_BASE=1 for ARM
or Thumb PIC/PIE code using this fixed-r9 static-base data mode, so C and
assembly startup code can adapt.

The runtime contract is that startup or loader code must initialize r9 to the
linked 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.S
xray_trampoline_arm.S

Both now use conditional __ARM_PIC_DATA_STATIC_BASE paths that load the data
symbol 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_BREL relocations.
an lld PIE startup proof test showing r9 initialization before GOT use.

Local validation:

git diff --check
focused lld/Clang lit suite:
lld/test/ELF/arm-pie-static-base-startup.s
clang/test/CodeGen/arm-pic-data-is-text-relative.c
clang/test/CodeGen/arm-pic-data-static-base-proof.c
clang/test/CodeGen/arm-pic-data-static-base-r9.c
clang/test/Driver/pic.c
clang/test/Driver/arm-pic-data-multilib.yaml
clang/test/Preprocessor/arm-pic-predefines.c
direct compiler-rt ARM assembly builds in normal PIC and static-base PIC modes
FileCheck relocation checks for the expected R_ARM_GOT_BREL entries
manual QEMU smoke tests for both a hand-written and Clang-generated ARM PIE
image using the static-base startup sequence

Diff: 449 lines (+336 / -113) across 5 files Reviewer: smithp35 Review duration: 37272m
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
0.45
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
0.02
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
46%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
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
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 46.7% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 45.4% (MEDIUM) · Higher = larger blast radius
45.4%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 46.7% · Lower = rushed or shallow review
46.7%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 24.2% · Safe to merge
24.2%