[PATCH] D43470: [DWARF] Prevent crash when .debug_line line_range is zero
James Henderson via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 19 08:29:51 PST 2018
jhenderson created this revision.
jhenderson added reviewers: probinson, JDevlieghere, dblaikie, aprantl.
The line_range field of the .debug_line program prolog is used to calculate the meaning of special opcodes. Specifically, it is used to divide another value, which means that it cannot be 0. With this change, the prolog parser warns when a line_range of 0 is found. This will prevent llvm-dwarfdump and other tools from crashing with a divide-by-zero failure when consuming such an output.
Repository:
rL LLVM
https://reviews.llvm.org/D43470
Files:
lib/DebugInfo/DWARF/DWARFDebugLine.cpp
test/tools/llvm-dwarfdump/X86/bad_line_ranges.s
Index: test/tools/llvm-dwarfdump/X86/bad_line_ranges.s
===================================================================
--- test/tools/llvm-dwarfdump/X86/bad_line_ranges.s
+++ test/tools/llvm-dwarfdump/X86/bad_line_ranges.s
@@ -0,0 +1,58 @@
+# RUN: llvm-mc %s -filetype obj -triple x86_64-pc-linux -o %t.o
+# RUN: llvm-dwarfdump -debug-line %t.o | FileCheck %s -check-prefixes=CHECK
+# RUN: FileCheck %s -check-prefix=WARN -input-file=%t.err
+# RUN: not llvm-dwarfdump -debug-line -verify %t.o 2> %t2.err | FileCheck %s -check-prefix=ERR
+# RUN: FileCheck %s -check-prefix=WARN -input-file=%t2.err
+
+# CHECK-NOT: error:
+# CHECK-NOT: warning:
+# CHECK: line_range: 0
+# CHECK-NOT: error:
+# CHECK-NOT: warning:
+
+# WARN: warning: parsing line table prologue at 0x00000000 found a line_range of value 0
+# ERR: error: .debug_line[0x00000000] was not able to be parsed for CU:
+
+.section .debug_line,"", at progbits
+
+.Lline_table_start0:
+.long .Ldebug_line_end0 - .Ldebug_line_start0 # unit_length
+.Ldebug_line_start0:
+.short 4 # version
+.long .Lheader_end - .Lheader_start # header_length
+.Lheader_start:
+.byte 1 # minimum_instruction_length
+.byte 1 # maximum_operations_per_instruction
+.byte 1 # default_is_stmt
+.byte -5 # line_base
+.byte 0 # line_range
+.byte 13 # opcode_base
+.byte 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1 # standard_opcode_lengths
+.byte 0 # include directories
+.byte 0 # file_names
+.Lheader_end:
+.byte 25 # special opcode. In order to calculate its meaning, a division by line_range is required.
+.Ldebug_line_end0:
+
+.section .debug_info,"", at progbits
+.Lsection_info:
+.long .Lunit_end - .Lunit_start # Length of Unit
+.Lunit_start:
+.short 4 # DWARF version number
+.long .Lsection_abbrev # Offset Into Abbrev. Section
+.byte 8 # Address Size (in bytes)
+.byte 1 # Abbrev [1] 0xb:0x59 DW_TAG_compile_unit
+.long .Lline_table_start0 # DW_AT_stmt_list
+.byte 0 # End Of Children Mark
+.Lunit_end:
+
+.section .debug_abbrev,"", at progbits
+.Lsection_abbrev:
+.byte 1 # Abbreviation Code
+.byte 17 # DW_TAG_compile_unit
+.byte 0 # DW_CHILDREN_no
+.byte 16 # DW_AT_stmt_list
+.byte 23 # DW_FORM_sec_offset
+.byte 0 # EOM(1)
+.byte 0 # EOM(2)
+.byte 0 # EOM(3)
Index: lib/DebugInfo/DWARF/DWARFDebugLine.cpp
===================================================================
--- lib/DebugInfo/DWARF/DWARFDebugLine.cpp
+++ lib/DebugInfo/DWARF/DWARFDebugLine.cpp
@@ -305,6 +305,14 @@
PrologueOffset, EndPrologueOffset, (uint64_t)*OffsetPtr);
return false;
}
+
+ if (LineRange == 0) {
+ fprintf(stderr, "warning: parsing line table prologue at 0x%8.8" PRIx64
+ " found a line_range of value 0\n",
+ PrologueOffset);
+ return false;
+ }
+
return true;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43470.134927.patch
Type: text/x-patch
Size: 3405 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180219/3e0b961a/attachment.bin>
More information about the llvm-commits
mailing list