This is a follow-up patch for r220333. r220333 renames exported symbols.
That raised another issue; if we have both decorated and undecorated names
for the same symbol, we'll end up have two duplicate exported symbol
entries.
This is a fix for that issue by removing duplciate entries.
llvm-svn: 220350
#include "lld/Core/Simple.h"
#include "lld/ReaderWriter/PECOFFLinkingContext.h"
#include "llvm/Support/Allocator.h"
+#include <algorithm>
#include <mutex>
using llvm::COFF::WindowsSubsystem;
}
const File *find(StringRef sym, bool dataSymbolOnly) const override {
+ typedef PECOFFLinkingContext::ExportDesc ExportDesc;
auto it = _exportedSyms.find(sym);
if (it == _exportedSyms.end())
return nullptr;
std::string replace;
if (!findDecoratedSymbol(_ctx, _syms.get(), sym.str(), replace))
return nullptr;
- it->second->name = replace;
- if (_ctx->deadStrip())
- _ctx->addDeadStripRoot(_ctx->allocate(replace));
+ ExportDesc *desc = it->second;
+
+ // We found a decorated symbol. There may be another symbol that
+ // has the same decorated name. If that's the case, we remove the
+ // duplicate item.
+ std::vector<ExportDesc> &exp = _ctx->getDllExports();
+ auto isFound = std::find_if(
+ exp.begin(), exp.end(),
+ [&](ExportDesc &e) { return e.getExternalName().equals(replace); });
+ if (isFound != exp.end()) {
+ exp.erase(
+ std::remove_if(exp.begin(), exp.end(),
+ [&](ExportDesc &e) { return &e == desc; }),
+ exp.end());
+ } else {
+ it->second->name = replace;
+ if (_ctx->deadStrip())
+ _ctx->addDeadStripRoot(_ctx->allocate(replace));
+ }
+
return new (_alloc) impl::SymbolRenameFile(sym, replace);
}
- Name: .drectve
Characteristics: [ IMAGE_SCN_LNK_INFO, IMAGE_SCN_LNK_REMOVE ]
Alignment: 2147483648
- SectionData: 2f6578706f72743a6578706f7274666e334032353600 # /export:exportfn3@256
+ SectionData: 2f6578706f72743a5f6578706f7274666e334032353600 # /export:_exportfn3@256
symbols:
- Name: .text
Value: 0
SimpleType: IMAGE_SYM_TYPE_NULL
ComplexType: IMAGE_SYM_DTYPE_NULL
StorageClass: IMAGE_SYM_CLASS_EXTERNAL
- - Name: exportfn3@256
+ - Name: _exportfn3@256
Value: 16
SectionNumber: 1
SimpleType: IMAGE_SYM_TYPE_NULL
CHECK4: Ordinal RVA Name
CHECK4-NEXT: 5 0x2008 exportfn1
CHECK4-NEXT: 6 0x2010 exportfn2
-CHECK4-NEXT: 7 0x2010 exportfn5
-CHECK4-NEXT: 8 0x2010 exportfn3@256
+CHECK4-NEXT: 7 0x2010 exportfn3@256
+CHECK4-NEXT: 8 0x2010 exportfn5
# RUN: lld -flavor link /out:%t5.dll /dll /entry:init \
# RUN: /export:exportfn7 -- %t.obj
CHECK5: Export Table:
CHECK5: DLL name: export.test.tmp5.dll
CHECK5: Ordinal RVA Name
-CHECK5-NEXT: 1 0x2010 exportfn7
+CHECK5-NEXT: 1 0x2010 exportfn3@256
+CHECK5-NEXT: 2 0x2010 exportfn7
# RUN: lld -flavor link /out:%t6.dll /dll /entry:init \
# RUN: /export:exportfn8 -- %t.obj
CHECK6-NEXT: 1 0x2010 ?exportfn8@@YAXXZ
# RUN: lld -flavor link /out:%t6.dll /dll /entry:init \
-# RUN: /export:exportfn8 /export:exportfn8 -- %t.obj
+# RUN: /export:exportfn8 /export:exportfn8 /export:exportfn3 -- %t.obj
# RUN: llvm-objdump -p %t6.dll | FileCheck -check-prefix=DUP %s
DUP: Export Table:
DUP: DLL name: export.test.tmp6.dll
DUP: Ordinal RVA Name
-DUP: 1 0x2010 ?exportfn8@@YAXXZ
-DUP-NOT: 1 0x2010 ?exportfn8@@YAXXZ
+DUP-NEXT: 1 0x2010 ?exportfn8@@YAXXZ
+DUP-NEXT: 2 0x2010 exportfn3@256
+DUP-NOT: ?exportfn8@@YAXXZ
+DUP-NOT: exportfn3@256
# RUN: yaml2obj %p/Inputs/export.obj.yaml > %t.obj
#