From e5b78d8041fb7fe178c3e3fd6d794ae74c5a7530 Mon Sep 17 00:00:00 2001 From: Frederic Riss Date: Sun, 31 Jan 2016 22:06:35 +0000 Subject: [MCDwarf] Fix encoding of line tables with weird custom parameters With poorly chosen custom parameters, the line table encoding logic would sometimes end up generating a special opcode bigger than 255, which is wrong. The set of default parameters that LLVM uses isn't subject to this bug. When carefully chosing the line table parameters, it's impossible to fall into the corner case that this patch fixes. The standard however doesn't require that these parameters be carefully chosen. And even if it did, we shouldn't generate broken encoding. Add a unittest for this specific encoding bug, and while at it, create some unit tests for the encoding logic using different sets of parameters. llvm-svn: 259334 --- llvm/lib/MC/MCDwarf.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'llvm/lib') diff --git a/llvm/lib/MC/MCDwarf.cpp b/llvm/lib/MC/MCDwarf.cpp index f2de2fc7255..e3e5f239ef6 100644 --- a/llvm/lib/MC/MCDwarf.cpp +++ b/llvm/lib/MC/MCDwarf.cpp @@ -452,7 +452,8 @@ void MCDwarfLineAddr::Encode(MCContext &Context, MCDwarfLineTableParams Params, // If the line increment is out of range of a special opcode, we must encode // it with DW_LNS_advance_line. - if (Temp >= Params.DWARF2LineRange) { + if (Temp >= Params.DWARF2LineRange || + Temp + Params.DWARF2LineOpcodeBase > 255) { OS << char(dwarf::DW_LNS_advance_line); encodeSLEB128(LineDelta, OS); @@ -494,8 +495,10 @@ void MCDwarfLineAddr::Encode(MCContext &Context, MCDwarfLineTableParams Params, if (NeedCopy) OS << char(dwarf::DW_LNS_copy); - else + else { + assert(Temp <= 255 && "Buggy special opcode encoding."); OS << char(Temp); + } } // Utility function to write a tuple for .debug_abbrev. -- cgit v1.2.3