aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib
diff options
context:
space:
mode:
authorFangrui Song <i@maskray.me>2025-07-17 10:29:18 -0700
committerFangrui Song <i@maskray.me>2025-07-17 10:29:19 -0700
commit13549fd90af45d2200159cac14a12cf01db56aa1 (patch)
tree737d2969b98fbc94e3c4c9e9ec4e6281aee6dfe6 /llvm/lib
parentb8bc3ff9bedf0b8f1d38273f7920cb0bba1a5a9e (diff)
downloadllvm-13549fd90af45d2200159cac14a12cf01db56aa1.zip
llvm-13549fd90af45d2200159cac14a12cf01db56aa1.tar.gz
llvm-13549fd90af45d2200159cac14a12cf01db56aa1.tar.bz2
MCAssembler: Modify Contents when VarFixups is not empty
When there is no VarFixup, VarContentStart is zero. `slice(F.VarContentStart - Contents.size(), F.getSize())` might lead to "runtime error: addition of unsigned offset to" in ubsan builds after #148544
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/MC/MCAssembler.cpp18
1 files changed, 11 insertions, 7 deletions
diff --git a/llvm/lib/MC/MCAssembler.cpp b/llvm/lib/MC/MCAssembler.cpp
index f1a82f6..3e96bdf 100644
--- a/llvm/lib/MC/MCAssembler.cpp
+++ b/llvm/lib/MC/MCAssembler.cpp
@@ -735,13 +735,17 @@ void MCAssembler::layout() {
// In the variable part, fixup offsets are relative to the fixed part's
// start. Extend the variable contents to the left to account for the
// fixed part size.
- Contents = MutableArrayRef(F.getParent()->ContentStorage)
- .slice(F.VarContentStart - Contents.size(), F.getSize());
- for (MCFixup &Fixup : F.getVarFixups()) {
- uint64_t FixedValue;
- MCValue Target;
- evaluateFixup(F, Fixup, Target, FixedValue,
- /*RecordReloc=*/true, Contents);
+ auto VarFixups = F.getVarFixups();
+ if (VarFixups.size()) {
+ Contents =
+ MutableArrayRef(F.getParent()->ContentStorage)
+ .slice(F.VarContentStart - Contents.size(), F.getSize());
+ for (MCFixup &Fixup : VarFixups) {
+ uint64_t FixedValue;
+ MCValue Target;
+ evaluateFixup(F, Fixup, Target, FixedValue,
+ /*RecordReloc=*/true, Contents);
+ }
}
} else if (auto *AF = dyn_cast<MCAlignFragment>(&F)) {
// For RISC-V linker relaxation, an alignment relocation might be