Skip to content

Commit 64f9e35

Browse files
[DWARFVerifier] Fix verification of empty line tables
A line table whose sole entry is an entry sequence should not have the entry's file index verified, as that value corresponds to the initial value of the state machine, not to a real file index. In DWARF 5, this is particularly problematic as it uses 0-based indexing, and the state machine specifies a starting index of 1; in other words, you'd need to have _two_ files before such index became legal "by default". A previous attempt to fix this problem was done [1], but it was too specific in its condition, and did not capture all possible cases where this issue can happen. [1]: #77004
1 parent d6c2cbb commit 64f9e35

File tree

2 files changed

+61
-7
lines changed

2 files changed

+61
-7
lines changed

llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,11 @@ void DWARFVerifier::verifyDebugLineRows() {
10251025
FileIndex++;
10261026
}
10271027

1028+
// Nothing to verify in a line table with a single row containing the end
1029+
// sequence.
1030+
if (LineTable->Rows.size() == 1 && LineTable->Rows.front().EndSequence)
1031+
continue;
1032+
10281033
// Verify rows.
10291034
uint64_t PrevAddress = 0;
10301035
uint32_t RowIndex = 0;
@@ -1048,13 +1053,7 @@ void DWARFVerifier::verifyDebugLineRows() {
10481053
});
10491054
}
10501055

1051-
// If the prologue contains no file names and the line table has only one
1052-
// row, do not verify the file index, this is a line table of an empty
1053-
// file with an end_sequence, but the DWARF standard sets the file number
1054-
// to 1 by default, otherwise verify file index.
1055-
if ((LineTable->Prologue.FileNames.size() ||
1056-
LineTable->Rows.size() != 1) &&
1057-
!LineTable->hasFileAtIndex(Row.File)) {
1056+
if (!LineTable->hasFileAtIndex(Row.File)) {
10581057
++NumDebugLineErrors;
10591058
ErrorCategory.Report("Invalid file index in debug_line", [&]() {
10601059
error() << ".debug_line["
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# RUN: yaml2obj %s -o %t.o
2+
# RUN: llvm-dwarfdump -debug-line -verify %t.o | FileCheck %s
3+
4+
# CHECK: Verifying .debug_line...
5+
# CHECK: No errors
6+
7+
# In a line table like the one below, with no rows (other than the
8+
# end_sequence), we should never verify the file index because the state
9+
# machine starts initializes the file index to 1, which is invalid in DWARF 5
10+
# due to its 0-based indexing.
11+
12+
# file_names[ 0]:
13+
# name: "/home/umb/tests_2018/106_rnglists2"
14+
# dir_index: 0
15+
# Address Line Column File ISA Discriminator OpIndex Flags
16+
# ------------------ ------ ------ ------ --- ------------- ------- -------------
17+
# 0x0000000000000000 1 0 1 0 0 0 is_stmt end_sequence
18+
19+
20+
--- !ELF
21+
FileHeader:
22+
Class: ELFCLASS64
23+
Data: ELFDATA2LSB
24+
Type: ET_EXEC
25+
DWARF:
26+
debug_abbrev:
27+
- ID: 0
28+
Table:
29+
- Code: 0x1
30+
Tag: DW_TAG_compile_unit
31+
Children: DW_CHILDREN_no
32+
Attributes:
33+
- Attribute: DW_AT_stmt_list
34+
Form: DW_FORM_sec_offset
35+
debug_info:
36+
- Length: 0xd
37+
Version: 5
38+
UnitType: DW_UT_compile
39+
AbbrevTableID: 0
40+
AbbrOffset: 0x0
41+
AddrSize: 8
42+
Entries:
43+
- AbbrCode: 0x1
44+
Values:
45+
- Value: 0x0
46+
Sections:
47+
- Name: .debug_line
48+
Type: SHT_PROGBITS
49+
AddressAlign: 0x1
50+
Content: 300000000500080025000000010101fb0e0d00010101010000000100000101011f010000000002011f020b010000000000000101
51+
- Name: .debug_line_str
52+
Type: SHT_PROGBITS
53+
Flags: [ SHF_MERGE, SHF_STRINGS ]
54+
AddressAlign: 0x1
55+
Content: 2F686F6D652F756D622F74657374735F323031382F3130365F726E676C697374733200746573742E63707000

0 commit comments

Comments
 (0)