[lld] r318384 - [COFF] Improve the autoexport check for symbols from import libraries with -opt:noref
Martin Storsjo via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 15 23:22:44 PST 2017
Author: mstorsjo
Date: Wed Nov 15 23:22:44 2017
New Revision: 318384
URL: http://llvm.org/viewvc/llvm-project?rev=318384&view=rev
Log:
[COFF] Improve the autoexport check for symbols from import libraries with -opt:noref
If -opt:noref is specified, they can end up with isLive() == 1
when the autoexport check is run.
To reduce the risk of potential issues, only consider exporting
DefinedRegular and DefinedCommon, nothing else.
Differential Revision: https://reviews.llvm.org/D40014
Modified:
lld/trunk/COFF/MinGW.cpp
lld/trunk/test/COFF/export-all.s
Modified: lld/trunk/COFF/MinGW.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/MinGW.cpp?rev=318384&r1=318383&r2=318384&view=diff
==============================================================================
--- lld/trunk/COFF/MinGW.cpp (original)
+++ lld/trunk/COFF/MinGW.cpp Wed Nov 15 23:22:44 2017
@@ -91,8 +91,16 @@ AutoExporter::AutoExporter() {
bool AutoExporter::shouldExport(Defined *Sym) const {
if (!Sym || !Sym->isLive() || !Sym->getChunk())
return false;
+ // Only allow the symbol kinds that make sense to export; in particular,
+ // disallow import symbols.
+ if (!isa<DefinedRegular>(Sym) && !isa<DefinedCommon>(Sym))
+ return false;
if (ExcludeSymbols.count(Sym->getName()))
return false;
+ // Check that file is non-null before dereferencing it, symbols not
+ // originating in regular object files probably shouldn't be exported.
+ if (!Sym->getFile())
+ return false;
StringRef LibName = sys::path::filename(Sym->getFile()->ParentName);
// Drop the file extension.
LibName = LibName.substr(0, LibName.rfind('.'));
Modified: lld/trunk/test/COFF/export-all.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/export-all.s?rev=318384&r1=318383&r2=318384&view=diff
==============================================================================
--- lld/trunk/test/COFF/export-all.s (original)
+++ lld/trunk/test/COFF/export-all.s Wed Nov 15 23:22:44 2017
@@ -65,3 +65,14 @@ _dataSym:
# 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
More information about the llvm-commits
mailing list