Skip to content

Commit b21f14e

Browse files
committed
MCAssembler: Fix ubsan "addition of unsigned offset to" for linker relaxation targets after llvm#149465
Similar to 13549fd
1 parent e3af202 commit b21f14e

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

llvm/lib/MC/MCAssembler.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -986,10 +986,10 @@ void MCAssembler::layoutSection(MCSection &Sec) {
986986
}
987987
if (!AlignFixup && Size > F.getAlignMaxBytesToEmit())
988988
Size = 0;
989-
// Update the variable tail size. The content is ignored.
990-
assert(F.VarContentStart == 0 &&
991-
"VarContentStart should not be modified");
992-
F.VarContentEnd = Size;
989+
// Update the variable tail size, offset by FixedSize to prevent ubsan
990+
// pointer-overflow in evaluateFixup. The content is ignored.
991+
F.VarContentStart = F.getFixedSize();
992+
F.VarContentEnd = F.VarContentStart + Size;
993993
if (F.VarContentEnd > F.getParent()->ContentStorage.size())
994994
F.getParent()->ContentStorage.resize(F.VarContentEnd);
995995
Offset += Size;

0 commit comments

Comments
 (0)