diff --git a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp --- a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp @@ -1887,10 +1887,6 @@ S.Data = Data; } - if (RelocatedSection != Obj.section_end() && Name.contains(".dwo")) - HandleWarning( - createError("Unexpected relocations for dwo section " + Name)); - if (RelocatedSection == Obj.section_end() || (RelocAction == DWARFContext::ProcessDebugRelocations::Ignore)) continue; @@ -1916,6 +1912,12 @@ if (!L && isa(&Obj)) continue; + if (!Section.relocations().empty() && Name.ends_with(".dwo") && + RelSecName.startswith(".debug")) { + HandleWarning(createError("unexpected relocations for dwo section '" + + RelSecName + "'")); + } + RelSecName = RelSecName.substr( RelSecName.find_first_not_of("._z")); // Skip . and _ prefixes. diff --git a/llvm/test/DebugInfo/X86/dwarfdump-rela-dwo.s b/llvm/test/DebugInfo/X86/dwarfdump-rela-dwo.s --- a/llvm/test/DebugInfo/X86/dwarfdump-rela-dwo.s +++ b/llvm/test/DebugInfo/X86/dwarfdump-rela-dwo.s @@ -3,7 +3,7 @@ # RUN: llvm-mc -triple x86_64-unknown-linux %s -filetype=obj -o %t.o # RUN: llvm-dwarfdump --debug-info %t.o | FileCheck %s # RUN: llvm-dwarfdump --debug-info %t.o 2> %t.txt -# RUN: cat %t.txt | FileCheck %s --check-prefix=PART2 +# RUN: FileCheck --input-file=%t.txt %s --check-prefix=PART2 --implicit-check-not=warning: .section .debug_str.dwo,"MSe",@progbits,1 .dwo_producer: @@ -33,6 +33,9 @@ .byte 0x00 # EOM(2) .byte 0x00 # EOM(3) +# PART2: warning: unexpected relocations for dwo section '.debug_abbrev.dwo' + .reloc ., R_X86_64_NONE, 0 + .section .debug_info.dwo,"e",@progbits # CHECK-LABEL: .debug_info.dwo @@ -55,4 +58,10 @@ # CHECK: 0x00000014: DW_TAG_compile_unit # CHECK-NEXT: DW_AT_producer ("Handmade DWO producer") # CHECK-NEXT: DW_AT_name ("V5_dwo_compile_unit") -# PART2: warning: Unexpected relocations for dwo section rela.debug_info.dwo +# PART2: warning: unexpected relocations for dwo section '.debug_info.dwo' + +## No warning, even if their names end with ".dwo". + .section .rodata.dwo,"a" + .long ext + .section .foo.dwo,"" + .long .dwo_producer