[PATCH] D40553: [LLD] [COFF] Don't export symbols that have corresponding __imp_ symbols
Martin Storsjö via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 28 06:04:25 PST 2017
mstorsjo created this revision.
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.
https://reviews.llvm.org/D40553
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
@@ -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.
Index: COFF/MinGW.cpp
===================================================================
--- COFF/MinGW.cpp
+++ 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"
@@ -99,6 +100,13 @@
return false;
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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D40553.124560.patch
Type: text/x-patch
Size: 1834 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171128/d9c20b12/attachment.bin>
More information about the llvm-commits
mailing list