summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lld/COFF/MinGW.cpp10
-rw-r--r--lld/test/COFF/export-all.s8
2 files changed, 18 insertions, 0 deletions
diff --git a/lld/COFF/MinGW.cpp b/lld/COFF/MinGW.cpp
index 564ee9e4065..b7a47165640 100644
--- a/lld/COFF/MinGW.cpp
+++ b/lld/COFF/MinGW.cpp
@@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//
#include "MinGW.h"
+#include "SymbolTable.h"
#include "lld/Common/ErrorHandler.h"
#include "llvm/Object/COFF.h"
#include "llvm/Support/Path.h"
@@ -100,6 +101,15 @@ bool AutoExporter::shouldExport(Defined *Sym) const {
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).
+ if (Sym->getName().startswith("__imp_"))
+ return false;
+
+ // If a corresponding __imp_ symbol exists and is defined, don't export it.
+ if (Symtab->find(("__imp_" + Sym->getName()).str()))
+ 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())
diff --git a/lld/test/COFF/export-all.s b/lld/test/COFF/export-all.s
index 47f2cd7f1ae..96c7dca5df2 100644
--- a/lld/test/COFF/export-all.s
+++ b/lld/test/COFF/export-all.s
@@ -7,8 +7,10 @@
# RUN: llvm-readobj %t.lib | FileCheck -check-prefix=IMPLIB %s
# CHECK-NOT: Name: DllMainCRTStartup
+# CHECK-NOT: Name: _imp__unexported
# CHECK: Name: dataSym
# CHECK: Name: foobar
+# CHECK-NOT: Name: unexported
# IMPLIB: Symbol: __imp__dataSym
# IMPLIB-NOT: Symbol: _dataSym
@@ -18,14 +20,20 @@
.global _foobar
.global _DllMainCRTStartup@12
.global _dataSym
+.global _unexported
+.global __imp__unexported
.text
_DllMainCRTStartup@12:
ret
_foobar:
ret
+_unexported:
+ ret
.data
_dataSym:
.int 4
+__imp__unexported:
+ .int _unexported
# Test specifying -export-all-symbols, on an object file that contains
# dllexport directive for some of the symbols.
OpenPOWER on IntegriCloud