[llvm] e28b3ea - [DWARF] Adjust warning condition for .dwo sections with relocations

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sat Jun 24 10:06:21 PDT 2023


Author: Fangrui Song
Date: 2023-06-24T10:06:17-07:00
New Revision: e28b3ea52aa68114ad9862ba2609042556d713ae

URL: https://github.com/llvm/llvm-project/commit/e28b3ea52aa68114ad9862ba2609042556d713ae
DIFF: https://github.com/llvm/llvm-project/commit/e28b3ea52aa68114ad9862ba2609042556d713ae.diff

LOG: [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

Added: 
    

Modified: 
    llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
    llvm/test/DebugInfo/X86/dwarfdump-rela-dwo.s

Removed: 
    


################################################################################
diff  --git a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
index 2eaad4bb43e49..122c61fb6941d 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
@@ -1887,10 +1887,6 @@ class DWARFObjInMemory final : public DWARFObject {
         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 @@ class DWARFObjInMemory final : public DWARFObject {
       if (!L && isa<MachOObjectFile>(&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
index d55f70f2c9488..9b4c0db4fb9e4 100644
--- 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", at 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", at progbits
 # CHECK-LABEL: .debug_info.dwo
 
@@ -55,4 +58,10 @@ CU_split_5_end:
 # 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


        


More information about the llvm-commits mailing list