[lld] r207729 - [PECOFF] Fix exported symbol name.
Rui Ueyama
ruiu at google.com
Wed Apr 30 17:23:07 PDT 2014
Author: ruiu
Date: Wed Apr 30 19:23:07 2014
New Revision: 207729
URL: http://llvm.org/viewvc/llvm-project?rev=207729&view=rev
Log:
[PECOFF] Fix exported symbol name.
When creating a .lib file, we should strip the leading underscore,
but should not strip stdcall atsign suffix. Otherwise produced .lib
files cannot be linked.
Modified:
lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h
lld/trunk/lib/ReaderWriter/PECOFF/EdataPass.cpp
lld/trunk/lib/ReaderWriter/PECOFF/WriterImportLibrary.cpp
lld/trunk/test/pecoff/exportlib2.test
Modified: lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h?rev=207729&r1=207728&r2=207729&view=diff
==============================================================================
--- lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h (original)
+++ lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h Wed Apr 30 19:23:07 2014
@@ -67,6 +67,7 @@ public:
}
std::string name;
+ std::string internalName;
int ordinal;
bool noname;
bool isData;
Modified: lld/trunk/lib/ReaderWriter/PECOFF/EdataPass.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/EdataPass.cpp?rev=207729&r1=207728&r2=207729&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/EdataPass.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/EdataPass.cpp Wed Apr 30 19:23:07 2014
@@ -53,13 +53,21 @@ static StringRef removeAtSignSuffix(Stri
return sym;
}
-static bool getExportedAtoms(const PECOFFLinkingContext &ctx, MutableFile *file,
+static StringRef removeLeadingUnderscore(StringRef sym) {
+ if (sym.startswith("_"))
+ return sym.substr(1);
+ 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[removeAtSignSuffix(atom->name())] = atom;
- for (const PECOFFLinkingContext::ExportDesc &desc : ctx.getDllExports()) {
+ std::set<PECOFFLinkingContext::ExportDesc> exports = ctx.getDllExports();
+ ctx.getDllExports().clear();
+ for (PECOFFLinkingContext::ExportDesc desc : exports) {
auto it = definedAtoms.find(desc.name);
if (it == definedAtoms.end()) {
llvm::errs() << "Symbol <" << desc.name
@@ -68,6 +76,8 @@ static bool getExportedAtoms(const PECOF
}
const DefinedAtom *atom = it->second;
ret.push_back(TableEntry(desc.name, desc.ordinal, atom, desc.noname));
+ desc.internalName = removeLeadingUnderscore(atom->name());
+ ctx.addDllExport(desc);
}
std::sort(ret.begin(), ret.end(), compare);
return true;
Modified: lld/trunk/lib/ReaderWriter/PECOFF/WriterImportLibrary.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/WriterImportLibrary.cpp?rev=207729&r1=207728&r2=207729&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/WriterImportLibrary.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/WriterImportLibrary.cpp Wed Apr 30 19:23:07 2014
@@ -30,7 +30,7 @@ createModuleDefinitionFile(const PECOFFL
<< "EXPORTS\n";
for (const PECOFFLinkingContext::ExportDesc &desc : ctx.getDllExports()) {
- os << " " << ctx.undecorateSymbol(desc.name) << " @" << desc.ordinal;
+ os << " " << desc.internalName << " @" << desc.ordinal;
if (desc.noname)
os << " NONAME";
if (desc.isData)
Modified: lld/trunk/test/pecoff/exportlib2.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/exportlib2.test?rev=207729&r1=207728&r2=207729&view=diff
==============================================================================
--- lld/trunk/test/pecoff/exportlib2.test (original)
+++ lld/trunk/test/pecoff/exportlib2.test Wed Apr 30 19:23:07 2014
@@ -7,4 +7,4 @@
CHECK: LIBRARY "exportlib2.test.tmp.dll"
CHECK: EXPORTS
CHECK: exportfn1 @1
-CHECK: exportfn2 @2
+CHECK: exportfn2 at 8 @2
More information about the llvm-commits
mailing list