Skip to content

Commit e28b3ea

Browse files
committed
[DWARF] Adjust warning condition for .dwo sections with relocations
D106624 added a .dwo warning (when there are relocations) that may fire for non-debug sections, e.g. `.rodata.dwo` when there is a data symbol foo in -fdata-sections mode. Adjust it to only warn for .debug sections. While here, change the diagnostic to be more conventional https://llvm.org/docs/CodingStandards.html#error-and-warning-messages and use the relocated section name instead of the relocation section name. This change does not handle `.zdebug` (support was mostly removed from LLVM) or `__debug` (Mach-O, no DWO support). Reviewed By: ayermolo, HaohaiWen Differential Revision: https://reviews.llvm.org/D153602
1 parent f042890 commit e28b3ea

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

llvm/lib/DebugInfo/DWARF/DWARFContext.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1887,10 +1887,6 @@ class DWARFObjInMemory final : public DWARFObject {
18871887
S.Data = Data;
18881888
}
18891889

1890-
if (RelocatedSection != Obj.section_end() && Name.contains(".dwo"))
1891-
HandleWarning(
1892-
createError("Unexpected relocations for dwo section " + Name));
1893-
18941890
if (RelocatedSection == Obj.section_end() ||
18951891
(RelocAction == DWARFContext::ProcessDebugRelocations::Ignore))
18961892
continue;
@@ -1916,6 +1912,12 @@ class DWARFObjInMemory final : public DWARFObject {
19161912
if (!L && isa<MachOObjectFile>(&Obj))
19171913
continue;
19181914

1915+
if (!Section.relocations().empty() && Name.ends_with(".dwo") &&
1916+
RelSecName.startswith(".debug")) {
1917+
HandleWarning(createError("unexpected relocations for dwo section '" +
1918+
RelSecName + "'"));
1919+
}
1920+
19191921
RelSecName = RelSecName.substr(
19201922
RelSecName.find_first_not_of("._z")); // Skip . and _ prefixes.
19211923

llvm/test/DebugInfo/X86/dwarfdump-rela-dwo.s

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# RUN: llvm-mc -triple x86_64-unknown-linux %s -filetype=obj -o %t.o
44
# RUN: llvm-dwarfdump --debug-info %t.o | FileCheck %s
55
# RUN: llvm-dwarfdump --debug-info %t.o 2> %t.txt
6-
# RUN: cat %t.txt | FileCheck %s --check-prefix=PART2
6+
# RUN: FileCheck --input-file=%t.txt %s --check-prefix=PART2 --implicit-check-not=warning:
77

88
.section .debug_str.dwo,"MSe",@progbits,1
99
.dwo_producer:
@@ -33,6 +33,9 @@
3333
.byte 0x00 # EOM(2)
3434
.byte 0x00 # EOM(3)
3535

36+
# PART2: warning: unexpected relocations for dwo section '.debug_abbrev.dwo'
37+
.reloc ., R_X86_64_NONE, 0
38+
3639
.section .debug_info.dwo,"e",@progbits
3740
# CHECK-LABEL: .debug_info.dwo
3841

@@ -55,4 +58,10 @@ CU_split_5_end:
5558
# CHECK: 0x00000014: DW_TAG_compile_unit
5659
# CHECK-NEXT: DW_AT_producer ("Handmade DWO producer")
5760
# CHECK-NEXT: DW_AT_name ("V5_dwo_compile_unit")
58-
# PART2: warning: Unexpected relocations for dwo section rela.debug_info.dwo
61+
# PART2: warning: unexpected relocations for dwo section '.debug_info.dwo'
62+
63+
## No warning, even if their names end with ".dwo".
64+
.section .rodata.dwo,"a"
65+
.long ext
66+
.section .foo.dwo,""
67+
.long .dwo_producer

0 commit comments

Comments
 (0)