[lld] r218354 - [PECOFF] Keep renamed undefined symbol name in export descriptor
Rui Ueyama
ruiu at google.com
Tue Sep 23 18:44:59 PDT 2014
Author: ruiu
Date: Tue Sep 23 20:44:59 2014
New Revision: 218354
URL: http://llvm.org/viewvc/llvm-project?rev=218354&view=rev
Log:
[PECOFF] Keep renamed undefined symbol name in export descriptor
Exported symbol name resolution is two-pass. In the first pass,
we try to resolve that as a regular undefined symbol. If it fails,
we look for mangled name for the symbol and rename the undefined
symbol and try again.
After all name resolution is done, we look for an atom for each
exported symbol again, to construct the export table. In this
process we try the regular names first, and then try mangled names.
But at this moment we should have knew which name is correct.
This patch is to keep the information we get in the first process
to use it later.
Modified:
lld/trunk/lib/ReaderWriter/PECOFF/EdataPass.cpp
lld/trunk/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h
Modified: lld/trunk/lib/ReaderWriter/PECOFF/EdataPass.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/EdataPass.cpp?rev=218354&r1=218353&r2=218354&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/EdataPass.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/EdataPass.cpp Tue Sep 23 20:44:59 2014
@@ -46,20 +46,11 @@ static void assignOrdinals(PECOFFLinking
desc.ordinal = nextOrdinal++;
}
-static StringRef removeStdcallSuffix(StringRef sym) {
- if (!sym.startswith("_"))
- return sym;
- StringRef trimmed = sym.rtrim("0123456789");
- if (sym.size() != trimmed.size() && trimmed.endswith("@"))
- return trimmed.drop_back();
- return sym;
-}
-
static bool getExportedAtoms(PECOFFLinkingContext &ctx, MutableFile *file,
std::vector<TableEntry> &ret) {
std::map<StringRef, const DefinedAtom *> definedAtoms;
for (const DefinedAtom *atom : file->defined())
- definedAtoms[removeStdcallSuffix(atom->name())] = atom;
+ definedAtoms[atom->name()] = atom;
for (PECOFFLinkingContext::ExportDesc &desc : ctx.getDllExports()) {
auto it = definedAtoms.find(desc.name);
Modified: lld/trunk/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h?rev=218354&r1=218353&r2=218354&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h Tue Sep 23 20:44:59 2014
@@ -246,16 +246,18 @@ public:
std::shared_ptr<ResolvableSymbols> syms)
: VirtualArchiveLibraryFile("<export>"), _syms(syms),
_ctx(const_cast<PECOFFLinkingContext *>(&ctx)) {
- for (const PECOFFLinkingContext::ExportDesc &desc : ctx.getDllExports())
- _exportedSyms.insert(desc.name);
+ for (PECOFFLinkingContext::ExportDesc &desc : _ctx->getDllExports())
+ _exportedSyms[desc.name] = &desc;
}
const File *find(StringRef sym, bool dataSymbolOnly) const override {
- if (_exportedSyms.count(sym) == 0)
+ auto it = _exportedSyms.find(sym);
+ if (it == _exportedSyms.end())
return nullptr;
std::string replace;
if (!findSymbolWithAtsignSuffix(sym.str(), replace))
return nullptr;
+ it->second->name = replace;
if (_ctx->deadStrip())
_ctx->addDeadStripRoot(_ctx->allocate(replace));
return new (_alloc) impl::SymbolRenameFile(sym, replace);
@@ -283,7 +285,7 @@ private:
return false;
}
- std::set<std::string> _exportedSyms;
+ std::map<std::string, PECOFFLinkingContext::ExportDesc *> _exportedSyms;
std::shared_ptr<ResolvableSymbols> _syms;
mutable llvm::BumpPtrAllocator _alloc;
mutable PECOFFLinkingContext *_ctx;
More information about the llvm-commits
mailing list