[PATCH] D149235: Always emit symbol tables when dwarf section exists in COFF

Haohai, Wen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 25 23:20:09 PDT 2023


HaohaiWen created this revision.
Herald added a project: All.
HaohaiWen requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This also fixes NO check prefix which never worked in symtab.test


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149235

Files:
  lld/COFF/Writer.cpp
  lld/test/COFF/symtab.test


Index: lld/test/COFF/symtab.test
===================================================================
--- lld/test/COFF/symtab.test
+++ lld/test/COFF/symtab.test
@@ -6,7 +6,9 @@
 # RUN: lld-link /debug:symtab /opt:noref /out:%t.exe /entry:main %t.obj %p/Inputs/std64.lib
 # RUN: llvm-readobj --symbols %t.exe | FileCheck %s
 
-# RUN: lld-link /debug /out:%t.exe /entry:main %t.obj %p/Inputs/std64.lib
+# RUN: lld-link /debug /merge:.blank=.debug_info /out:%t.exe /entry:main %t.obj %p/Inputs/std64.lib
+# RUN: llvm-readobj --symbols %t.exe | FileCheck %s
+# RUN: lld-link /debug /merge:.debug_info=.blank /out:%t.exe /entry:main %t.obj %p/Inputs/std64.lib
 # RUN: llvm-readobj --symbols %t.exe | FileCheck -check-prefix=NO %s
 
 # CHECK:      Symbols [
@@ -84,7 +86,8 @@
 # CHECK-NEXT:   }
 # CHECK-NEXT: ]
 
-# NO: Symbols [
+# NO:       Symbols [
+# NO-NEXT:  ]
 
 --- !COFF
 header:
@@ -141,6 +144,14 @@
     Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]
     Alignment:       4
     SectionData:     48656C6C6F0048656C6C6F20576F726C6400
+  - Name:            .blank
+    Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ]
+    Alignment:       1
+    SectionData:     0000
+  - Name:            .debug_info
+    Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ]
+    Alignment:       1
+    SectionData:     0000
 symbols:
   - Name:            "@comp.id"
     Value:           10394907
Index: lld/COFF/Writer.cpp
===================================================================
--- lld/COFF/Writer.cpp
+++ lld/COFF/Writer.cpp
@@ -1266,7 +1266,9 @@
   // solution where discardable sections have long names preserved and
   // non-discardable sections have their names truncated, to ensure that any
   // section which is mapped at runtime also has its name mapped at runtime.
+  bool HasDwarfSection = false;
   for (OutputSection *sec : ctx.outputSections) {
+    HasDwarfSection |= sec->name.startswith(".debug_");
     if (sec->name.size() <= COFF::NameSize)
       continue;
     if ((sec->header.Characteristics & IMAGE_SCN_MEM_DISCARDABLE) == 0)
@@ -1279,7 +1281,7 @@
     sec->setStringTableOff(addEntryToStringTable(sec->name));
   }
 
-  if (ctx.config.debugDwarf || ctx.config.debugSymtab) {
+  if (ctx.config.debugDwarf || ctx.config.debugSymtab || HasDwarfSection) {
     for (ObjFile *file : ctx.objFileInstances) {
       for (Symbol *b : file->getSymbols()) {
         auto *d = dyn_cast_or_null<Defined>(b);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D149235.517066.patch
Type: text/x-patch
Size: 2575 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230426/76ff97fa/attachment.bin>


More information about the llvm-commits mailing list