[lld] r319291 - [COFF] Don't export symbols that have corresponding __imp_ symbols
Martin Storsjo via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 28 21:50:49 PST 2017
Author: mstorsjo
Date: Tue Nov 28 21:50:49 2017
New Revision: 319291
URL: http://llvm.org/viewvc/llvm-project?rev=319291&view=rev
Log:
[COFF] Don't export symbols that have corresponding __imp_ symbols
GNU ld has got an exception for such symbols, and mingw-w64
occasionally uses that exception to avoid exporting symbols in cases
where they otherwise aren't caught by the other exclusion mechanisms.
Differential Revision: https://reviews.llvm.org/D40553
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=319291&r1=319290&r2=319291&view=diff
==============================================================================
--- lld/trunk/COFF/MinGW.cpp (original)
+++ lld/trunk/COFF/MinGW.cpp Tue Nov 28 21:50:49 2017
@@ -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
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())
Modified: lld/trunk/test/COFF/export-all.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/export-all.s?rev=319291&r1=319290&r2=319291&view=diff
==============================================================================
--- lld/trunk/test/COFF/export-all.s (original)
+++ lld/trunk/test/COFF/export-all.s Tue Nov 28 21:50:49 2017
@@ -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 at 12
.global _dataSym
+.global _unexported
+.global __imp__unexported
.text
_DllMainCRTStartup at 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.
More information about the llvm-commits
mailing list