[llvm] b21f14e - MCAssembler: Fix ubsan "addition of unsigned offset to" for linker relaxation targets after #149465

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 20 15:01:18 PDT 2025


Author: Fangrui Song
Date: 2025-07-20T15:01:13-07:00
New Revision: b21f14e084125dd6df958544c8bbcd170619a20e

URL: https://github.com/llvm/llvm-project/commit/b21f14e084125dd6df958544c8bbcd170619a20e
DIFF: https://github.com/llvm/llvm-project/commit/b21f14e084125dd6df958544c8bbcd170619a20e.diff

LOG: MCAssembler: Fix ubsan "addition of unsigned offset to" for linker relaxation targets after #149465

Similar to 13549fd90af45d2200159cac14a12cf01db56aa1

Added: 
    

Modified: 
    llvm/lib/MC/MCAssembler.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/MC/MCAssembler.cpp b/llvm/lib/MC/MCAssembler.cpp
index 3f9bbc480533b..2b56e2a3dbf2a 100644
--- a/llvm/lib/MC/MCAssembler.cpp
+++ b/llvm/lib/MC/MCAssembler.cpp
@@ -986,10 +986,10 @@ void MCAssembler::layoutSection(MCSection &Sec) {
       }
       if (!AlignFixup && Size > F.getAlignMaxBytesToEmit())
         Size = 0;
-      // Update the variable tail size. The content is ignored.
-      assert(F.VarContentStart == 0 &&
-             "VarContentStart should not be modified");
-      F.VarContentEnd = Size;
+      // Update the variable tail size, offset by FixedSize to prevent ubsan
+      // pointer-overflow in evaluateFixup. The content is ignored.
+      F.VarContentStart = F.getFixedSize();
+      F.VarContentEnd = F.VarContentStart + Size;
       if (F.VarContentEnd > F.getParent()->ContentStorage.size())
         F.getParent()->ContentStorage.resize(F.VarContentEnd);
       Offset += Size;


        


More information about the llvm-commits mailing list