Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions llvm/include/llvm/BinaryFormat/Dwarf.h
Original file line number Diff line number Diff line change
Expand Up @@ -1128,6 +1128,9 @@ struct FormParams {
uint8_t getDwarfOffsetByteSize() const {
return dwarf::getDwarfOffsetByteSize(Format);
}
inline uint64_t getDwarfMaxOffset() const {
return (getDwarfOffsetByteSize() == 4) ? UINT32_MAX : UINT64_MAX;
}

explicit operator bool() const { return Version && AddrSize; }
};
Expand Down
6 changes: 4 additions & 2 deletions llvm/lib/DWARFLinker/Classic/DWARFLinker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2427,11 +2427,13 @@ void DWARFLinker::DIECloner::generateLineTableForUnit(CompileUnit &Unit) {
uint64_t OrigStmtSeq = StmtSeq.get();
// 1. Get the original row index from the stmt list offset.
auto OrigRowIter = SeqOffToOrigRow.find(OrigStmtSeq);
const uint64_t InvalidOffset =
Unit.getOrigUnit().getFormParams().getDwarfMaxOffset();
// Check whether we have an output sequence for the StmtSeq offset.
// Some sequences are discarded by the DWARFLinker if they are invalid
// (empty).
if (OrigRowIter == SeqOffToOrigRow.end()) {
StmtSeq.set(UINT64_MAX);
StmtSeq.set(InvalidOffset);
continue;
}
size_t OrigRowIndex = OrigRowIter->second;
Expand All @@ -2441,7 +2443,7 @@ void DWARFLinker::DIECloner::generateLineTableForUnit(CompileUnit &Unit) {
if (NewRowIter == OrigRowToNewRow.end()) {
// If the original row index is not found in the map, update the
// stmt_sequence attribute to the 'invalid offset' magic value.
StmtSeq.set(UINT64_MAX);
StmtSeq.set(InvalidOffset);
continue;
}

Expand Down
16 changes: 10 additions & 6 deletions llvm/lib/DebugInfo/GSYM/DwarfTransformer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,12 +320,16 @@ static void convertFunctionLineTable(OutputAggregator &Out, CUInfo &CUI,
// Attempt to retrieve DW_AT_LLVM_stmt_sequence if present.
std::optional<uint64_t> StmtSeqOffset;
if (auto StmtSeqAttr = Die.find(llvm::dwarf::DW_AT_LLVM_stmt_sequence)) {
// The `DW_AT_LLVM_stmt_sequence` attribute might be set to `UINT64_MAX`
// when it refers to an empty line sequence. In such cases, the DWARF linker
// will exclude the empty sequence from the final output and assign
// `UINT64_MAX` to the `DW_AT_LLVM_stmt_sequence` attribute.
uint64_t StmtSeqVal = dwarf::toSectionOffset(StmtSeqAttr, UINT64_MAX);
if (StmtSeqVal != UINT64_MAX)
// The `DW_AT_LLVM_stmt_sequence` attribute might be set to an invalid
// sentinel value when it refers to an empty line sequence. In such cases,
// the DWARF linker will exclude the empty sequence from the final output
// and assign the sentinel value to the `DW_AT_LLVM_stmt_sequence`
// attribute. The sentinel value is UINT32_MAX for DWARF32 and UINT64_MAX
// for DWARF64.
const uint64_t InvalidOffset =
Die.getDwarfUnit()->getFormParams().getDwarfMaxOffset();
uint64_t StmtSeqVal = dwarf::toSectionOffset(StmtSeqAttr, InvalidOffset);
if (StmtSeqVal != InvalidOffset)
StmtSeqOffset = StmtSeqVal;
}

Expand Down
Loading