[PATCH] D40014: [LLD] [COFF] Improve the autoexport check for symbols from import libraries with -opt:noref

Martin Storsjö via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 15 01:52:51 PST 2017


mstorsjo updated this revision to Diff 122991.
mstorsjo retitled this revision from "[LLD] [COFF] Don't crash when checking for autoexporting of symbols without a file" to "[LLD] [COFF] Improve the autoexport check for symbols from import libraries with -opt:noref".
mstorsjo edited the summary of this revision.
mstorsjo added a comment.

Identified the actual root cause, improved the related code further by checking for specific types of Defined symbols, added a test.


https://reviews.llvm.org/D40014

Files:
  COFF/MinGW.cpp
  test/COFF/export-all.s


Index: test/COFF/export-all.s
===================================================================
--- test/COFF/export-all.s
+++ test/COFF/export-all.s
@@ -65,3 +65,14 @@
 # CHECK-EXCLUDE: EXPORTS
 # CHECK-EXCLUDE-NEXT: foobar @1
 # CHECK-EXCLUDE-NEXT: EOF
+
+# Test that we handle import libraries together with -opt:noref.
+
+# RUN: yaml2obj < %p/Inputs/hello32.yaml > %t.obj
+# RUN: lld-link -lldmingw -dll -out:%t.dll -entry:main at 0 %t.obj -implib:%t.lib -opt:noref %p/Inputs/std32.lib -output-def:%t.def
+# RUN: echo "EOF" >> %t.def
+# RUN: cat %t.def | FileCheck -check-prefix=CHECK-IMPLIB %s
+
+# CHECK-IMPLIB: EXPORTS
+# CHECK-IMPLIB-NEXT: main at 0 @1
+# CHECK-IMPLIB-NEXT: EOF
Index: COFF/MinGW.cpp
===================================================================
--- COFF/MinGW.cpp
+++ COFF/MinGW.cpp
@@ -91,8 +91,12 @@
 bool AutoExporter::shouldExport(Defined *Sym) const {
   if (!Sym || !Sym->isLive() || !Sym->getChunk())
     return false;
+  if (!isa<DefinedRegular>(Sym) && !isa<DefinedCommon>(Sym))
+    return false;
   if (ExcludeSymbols.count(Sym->getName()))
     return false;
+  if (!Sym->getFile())
+    return false;
   StringRef LibName = sys::path::filename(Sym->getFile()->ParentName);
   // Drop the file extension.
   LibName = LibName.substr(0, LibName.rfind('.'));


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D40014.122991.patch
Type: text/x-patch
Size: 1298 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171115/c3cb00a9/attachment.bin>


More information about the llvm-commits mailing list