[PATCH] D69594: Warn when an output section name is longer than 8 characters

Reid Kleckner via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 29 16:09:03 PDT 2019


rnk created this revision.
rnk added reviewers: ruiu, mstorsjo.
Herald added a subscriber: aprantl.
Herald added a project: LLVM.

Microsoft's dumpbin tool cannot handle such PE files. LLVM tools and GNU
tools can, and use this to encode long section names like ".debug_info",
which is commonly used for DWARF. Don't do this in mingw mode, since
these are commonly used.

PR43754


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D69594

Files:
  lld/COFF/Config.h
  lld/COFF/Driver.cpp
  lld/COFF/Writer.cpp
  lld/test/COFF/long-section-name.test


Index: lld/test/COFF/long-section-name.test
===================================================================
--- lld/test/COFF/long-section-name.test
+++ lld/test/COFF/long-section-name.test
@@ -1,8 +1,17 @@
 # RUN: yaml2obj < %s > %t.obj
-# RUN: lld-link /out:%t.exe /entry:main %t.obj
+# RUN: lld-link /out:%t.exe /entry:main %t.obj 2>&1 | FileCheck %s --check-prefix=WARN
 # RUN: llvm-readobj --sections %t.exe | FileCheck %s
-# RUN: lld-link /debug /out:%t2.exe /entry:main %t.obj
+# RUN: lld-link /debug /out:%t2.exe /entry:main %t.obj 2>&1 | FileCheck %s --check-prefix=WARN
 # RUN: llvm-readobj --sections %t2.exe | FileCheck %s
+#
+# No warnings in mingw mode or with ignore flag.
+# RUN: lld-link /out:%t.exe /entry:main %t.obj /ignore:longsections 2>&1 | FileCheck %s --check-prefix=IGNORE --allow-empty
+# RUN: lld-link /out:%t.exe /entry:main %t.obj -lldmingw 2>&1 | FileCheck %s --check-prefix=IGNORE --allow-empty
+
+# WARN: warning: section name .data_long_section_name is longer than 8 characters and will use a non-standard string table
+# WARN: warning: section name .text_long_section_name is longer than 8 characters and will use a non-standard string table
+
+# IGNORE-NOT: warning:
 
 # CHECK: Name: .eh_fram (
 # CHECK: Name: .data_long_section_name
Index: lld/COFF/Writer.cpp
===================================================================
--- lld/COFF/Writer.cpp
+++ lld/COFF/Writer.cpp
@@ -1148,6 +1148,11 @@
       continue;
     if ((sec->header.Characteristics & IMAGE_SCN_MEM_DISCARDABLE) == 0)
       continue;
+    if (config->warnLongSectionNames) {
+      warn("section name " + sec->name +
+           " is longer than 8 characters and will use a non-standard string "
+           "table");
+    }
     sec->setStringTableOff(addEntryToStringTable(sec->name));
   }
 
Index: lld/COFF/Driver.cpp
===================================================================
--- lld/COFF/Driver.cpp
+++ lld/COFF/Driver.cpp
@@ -1188,10 +1188,17 @@
         config->warnDebugInfoUnusable = false;
       else if (s == "4217")
         config->warnLocallyDefinedImported = false;
+      else if (s == "longsections")
+        config->warnLongSectionNames = false;
       // Other warning numbers are ignored.
     }
   }
 
+  // Don't warn about long section names, such as .debug_info, for mingw.
+  if (config->mingw) {
+    config->warnLongSectionNames = false;
+  }
+
   // Handle /out
   if (auto *arg = args.getLastArg(OPT_out))
     config->outputFile = arg->getValue();
Index: lld/COFF/Config.h
===================================================================
--- lld/COFF/Config.h
+++ lld/COFF/Config.h
@@ -218,6 +218,7 @@
   bool warnMissingOrderSymbol = true;
   bool warnLocallyDefinedImported = true;
   bool warnDebugInfoUnusable = true;
+  bool warnLongSectionNames = true;
   bool incremental = true;
   bool integrityCheck = false;
   bool killAt = false;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69594.226988.patch
Type: text/x-patch
Size: 2903 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191029/c65b60fa/attachment.bin>


More information about the llvm-commits mailing list