[lld] r343070 - [COFF] Don't do autoexport of symbols from GNU import libraries

Martin Storsjo via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 25 23:13:47 PDT 2018


Author: mstorsjo
Date: Tue Sep 25 23:13:47 2018
New Revision: 343070

URL: http://llvm.org/viewvc/llvm-project?rev=343070&view=rev
Log:
[COFF] Don't do autoexport of symbols from GNU import libraries

This involves adding more generic list of symbol suffixes/prefixes
to ignore for autoexport; adding a few other entries to these lists
as well from the corresponding lists in binutils.

Differential Revision: https://reviews.llvm.org/D52382

Added:
    lld/trunk/test/COFF/imports-gnu-autoexport.s
Modified:
    lld/trunk/COFF/MinGW.cpp
    lld/trunk/COFF/MinGW.h

Modified: lld/trunk/COFF/MinGW.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/MinGW.cpp?rev=343070&r1=343069&r2=343070&view=diff
==============================================================================
--- lld/trunk/COFF/MinGW.cpp (original)
+++ lld/trunk/COFF/MinGW.cpp Tue Sep 25 23:13:47 2018
@@ -20,6 +20,22 @@ using namespace llvm;
 using namespace llvm::COFF;
 
 void AutoExporter::initSymbolExcludes() {
+  ExcludeSymbolPrefixes = {
+      // Import symbols
+      "__imp_",
+      "__IMPORT_DESCRIPTOR_",
+      // Extra import symbols from GNU import libraries
+      "__nm_",
+      // C++ symbols
+      "__rtti_",
+      "__builtin_",
+      // Artifical symbols such as .refptr
+      ".",
+  };
+  ExcludeSymbolSuffixes = {
+      "_iname",
+      "_NULL_THUNK_DATA",
+  };
   if (Config->Machine == I386) {
     ExcludeSymbols = {
         "__NULL_IMPORT_DESCRIPTOR",
@@ -36,6 +52,7 @@ void AutoExporter::initSymbolExcludes()
         "_DllEntryPoint at 12",
         "_DllMainCRTStartup at 12",
     };
+    ExcludeSymbolPrefixes.insert("__head_");
   } else {
     ExcludeSymbols = {
         "__NULL_IMPORT_DESCRIPTOR",
@@ -52,6 +69,7 @@ void AutoExporter::initSymbolExcludes()
         "DllEntryPoint",
         "DllMainCRTStartup",
     };
+    ExcludeSymbolPrefixes.insert("_head_");
   }
 }
 
@@ -110,11 +128,12 @@ bool AutoExporter::shouldExport(Defined
   if (ExcludeSymbols.count(Sym->getName()))
     return false;
 
-  // Don't export anything that looks like an import symbol (which also can be
-  // a manually defined data symbol with such a name); don't export artificial
-  // symbols like .refptr pointer stubs.
-  if (Sym->getName().startswith("__imp_") || Sym->getName().startswith("."))
-    return false;
+  for (StringRef Prefix : ExcludeSymbolPrefixes.keys())
+    if (Sym->getName().startswith(Prefix))
+      return false;
+  for (StringRef Suffix : ExcludeSymbolSuffixes.keys())
+    if (Sym->getName().endswith(Suffix))
+      return false;
 
   // If a corresponding __imp_ symbol exists and is defined, don't export it.
   if (Symtab->find(("__imp_" + Sym->getName()).str()))

Modified: lld/trunk/COFF/MinGW.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/MinGW.h?rev=343070&r1=343069&r2=343070&view=diff
==============================================================================
--- lld/trunk/COFF/MinGW.h (original)
+++ lld/trunk/COFF/MinGW.h Tue Sep 25 23:13:47 2018
@@ -28,6 +28,8 @@ public:
   void addWholeArchive(StringRef Path);
 
   llvm::StringSet<> ExcludeSymbols;
+  llvm::StringSet<> ExcludeSymbolPrefixes;
+  llvm::StringSet<> ExcludeSymbolSuffixes;
   llvm::StringSet<> ExcludeLibs;
   llvm::StringSet<> ExcludeObjects;
 

Added: lld/trunk/test/COFF/imports-gnu-autoexport.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/imports-gnu-autoexport.s?rev=343070&view=auto
==============================================================================
--- lld/trunk/test/COFF/imports-gnu-autoexport.s (added)
+++ lld/trunk/test/COFF/imports-gnu-autoexport.s Tue Sep 25 23:13:47 2018
@@ -0,0 +1,25 @@
+# REQUIRES: x86
+#
+# RUN: llvm-mc -triple=x86_64-windows-gnu %p/Inputs/gnu-implib-head.s -filetype=obj -o %t-dabcdh.o
+# RUN: llvm-mc -triple=x86_64-windows-gnu %p/Inputs/gnu-implib-func.s -filetype=obj -o %t-dabcds00000.o
+# RUN: llvm-mc -triple=x86_64-windows-gnu %p/Inputs/gnu-implib-tail.s -filetype=obj -o %t-dabcdt.o
+# RUN: rm -f %t-implib.a
+# RUN: llvm-ar rcs %t-implib.a %t-dabcdh.o %t-dabcds00000.o %t-dabcdt.o
+# RUN: lld-link -lldmingw -dll -out:%t.dll -entry:main -subsystem:console \
+# RUN:   %p/Inputs/hello64.obj %p/Inputs/std64.lib %t-implib.a -include:func
+# RUN: llvm-readobj -coff-exports %t.dll | FileCheck -check-prefix=EXPORT %s
+
+# Check that only the single normal symbol was exported, none of the symbols
+# from the import library.
+
+EXPORT:      Export {
+EXPORT-NEXT:   Ordinal: 0
+EXPORT-NEXT:   Name:
+EXPORT-NEXT:   RVA: 0x0
+EXPORT-NEXT: }
+EXPORT-NEXT: Export {
+EXPORT-NEXT:   Ordinal: 1
+EXPORT-NEXT:   Name: main
+EXPORT-NEXT:   RVA: 0x1010
+EXPORT-NEXT: }
+EXPORT-NEXT-EMPTY:




More information about the llvm-commits mailing list