Skip to content

Omit .debug_aranges if it is empty #99897

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 4 additions & 2 deletions llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2990,6 +2990,9 @@ struct ArangeSpan {
// Emit a debug aranges section, containing a CU lookup for any
// address we can tie back to a CU.
void DwarfDebug::emitDebugARanges() {
if (ArangeLabels.empty())
return;

// Provides a unique id per text section.
MapVector<MCSection *, SmallVector<SymbolCU, 8>> SectionMap;

Expand All @@ -3012,8 +3015,7 @@ void DwarfDebug::emitDebugARanges() {
for (auto &I : SectionMap) {
MCSection *Section = I.first;
SmallVector<SymbolCU, 8> &List = I.second;
if (List.size() < 1)
continue;
assert(!List.empty());
Comment on lines -3015 to +3018
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After convincing myself that any List must be non-empty, I was confident that the early return could be placed above this loop. I replaced the dead check with an assert to avoid similar head scratching in future.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the assert is appropriate even without the early return. If ArangeLabels is empty, SectionMap will also be empty, and the loop body will not execute.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, agreed. Just wanted to explain why I touched this seemingly unrelated part, for posterity.


// If we have no section (e.g. common), just write out
// individual spans for each symbol.
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/DebugInfo/omit-empty.ll
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
; RUN: %llc_dwarf %s -filetype=obj -o - | llvm-objdump -h - | FileCheck %s
; RUN: %llc_dwarf %s -filetype=obj -generate-arange-section -o - | llvm-objdump -h - | FileCheck %s
; REQUIRES: object-emission

; CHECK-NOT: .debug_
Expand Down
Loading