Skip to content

Commit f1dad0b

Browse files
authored
[DWARFLinker] Handle empty sequences when processing DW_AT_LLVM_stmt_sequence attributes (#132875)
We previously assumed that every `DW_AT_LLVM_stmt_sequence` attribute has a corresponding sequence in the processed line table. However, this isn't always true. Some sequences can be removed by the linker if they are empty, as shown [here](https://github.com/alx32/llvm-project/blob/release/14.x/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp#L565-L566). When an attribute refers to one of these removed sequences, there is no actual sequence for it to match. In such cases, we update the attribute to indicate that it is invalid and does not point to any sequence. This informs readers that the attribute should be ignored. The newly modified test would have triggered the assert that is being removed in this patch.
1 parent 7da71a6 commit f1dad0b

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

llvm/lib/DWARFLinker/Classic/DWARFLinker.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2311,8 +2311,13 @@ void DWARFLinker::DIECloner::generateLineTableForUnit(CompileUnit &Unit) {
23112311
uint64_t OrigStmtSeq = StmtSeq.get();
23122312
// 1. Get the original row index from the stmt list offset.
23132313
auto OrigRowIter = SeqOffToOrigRow.find(OrigStmtSeq);
2314-
assert(OrigRowIter != SeqOffToOrigRow.end() &&
2315-
"Stmt list offset not found in sequence offsets map");
2314+
// Check whether we have an output sequence for the StmtSeq offset.
2315+
// Some sequences are discarded by the DWARFLinker if they are invalid
2316+
// (empty).
2317+
if (OrigRowIter == SeqOffToOrigRow.end()) {
2318+
StmtSeq.set(UINT64_MAX);
2319+
continue;
2320+
}
23162321
size_t OrigRowIndex = OrigRowIter->second;
23172322

23182323
// 2. Get the new row index from the original row index.

llvm/test/tools/dsymutil/ARM/stmt-seq-macho.test

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,21 @@ ATTRIB int function2_copy2(int a) {
4141
int result = a - 22;
4242
return result;
4343
}
44+
45+
struct logic_error {
46+
logic_error(const char* s) {}
47+
};
48+
49+
struct length_error : public logic_error {
50+
__attribute__((noinline)) explicit length_error(const char* s) : logic_error(s) {}
51+
};
4452

4553
int main() {
4654
int sum = 0;
4755
sum += function2_copy2(3);
4856
sum += function3_copy2(41);
4957
sum += function2_copy1(11);
58+
length_error e("test");
5059
return sum;
5160
}
5261
EOF
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)