[MC] Fix assembler infinite loop on EH table using LEB padding.
Fix the infinite loop reported in PR35809. It can occur with GCC-style
EH table assembly, where the compiler relies on the assembler to
calculate the offsets in the EH table.
Also see https://sourceware.org/bugzilla/show_bug.cgi?id=4029 for the
equivalent issue in the GNU assembler.
Patch by Ryan Prichard!
llvm-svn: 323934
diff --git a/llvm/lib/MC/MCAssembler.cpp b/llvm/lib/MC/MCAssembler.cpp
index bd881b4..a0f9a85 100644
--- a/llvm/lib/MC/MCAssembler.cpp
+++ b/llvm/lib/MC/MCAssembler.cpp
@@ -868,10 +868,14 @@
SmallString<8> &Data = LF.getContents();
Data.clear();
raw_svector_ostream OSE(Data);
+ // The compiler can generate EH table assembly that is impossible to assemble
+ // without either adding padding to an LEB fragment or adding extra padding
+ // to a later alignment fragment. To accommodate such tables, relaxation can
+ // only increase an LEB fragment size here, not decrease it. See PR35809.
if (LF.isSigned())
- encodeSLEB128(Value, OSE);
+ encodeSLEB128(Value, OSE, OldSize);
else
- encodeULEB128(Value, OSE);
+ encodeULEB128(Value, OSE, OldSize);
return OldSize != LF.getContents().size();
}