summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2014-05-01 00:23:07 +0000
committerRui Ueyama <ruiu@google.com>2014-05-01 00:23:07 +0000
commite1452c22e5e372fad64384f18085680845723d55 (patch)
tree04a09c1bc0a314f4dab485079e03301542a94613
parentff68cb7f4cc40add935e31c5150d3002e6944e14 (diff)
downloadbcm5719-llvm-e1452c22e5e372fad64384f18085680845723d55.tar.gz
bcm5719-llvm-e1452c22e5e372fad64384f18085680845723d55.zip
[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. llvm-svn: 207729
-rw-r--r--lld/include/lld/ReaderWriter/PECOFFLinkingContext.h1
-rw-r--r--lld/lib/ReaderWriter/PECOFF/EdataPass.cpp14
-rw-r--r--lld/lib/ReaderWriter/PECOFF/WriterImportLibrary.cpp2
-rw-r--r--lld/test/pecoff/exportlib2.test2
4 files changed, 15 insertions, 4 deletions
diff --git a/lld/include/lld/ReaderWriter/PECOFFLinkingContext.h b/lld/include/lld/ReaderWriter/PECOFFLinkingContext.h
index de5f6f4281d..7283161a35a 100644
--- a/lld/include/lld/ReaderWriter/PECOFFLinkingContext.h
+++ b/lld/include/lld/ReaderWriter/PECOFFLinkingContext.h
@@ -67,6 +67,7 @@ public:
}
std::string name;
+ std::string internalName;
int ordinal;
bool noname;
bool isData;
diff --git a/lld/lib/ReaderWriter/PECOFF/EdataPass.cpp b/lld/lib/ReaderWriter/PECOFF/EdataPass.cpp
index 37b2255846e..f7b023cadf8 100644
--- a/lld/lib/ReaderWriter/PECOFF/EdataPass.cpp
+++ b/lld/lib/ReaderWriter/PECOFF/EdataPass.cpp
@@ -53,13 +53,21 @@ static StringRef removeAtSignSuffix(StringRef sym) {
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 PECOFFLinkingContext &ctx, MutableFile *file,
}
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;
diff --git a/lld/lib/ReaderWriter/PECOFF/WriterImportLibrary.cpp b/lld/lib/ReaderWriter/PECOFF/WriterImportLibrary.cpp
index e5630737908..dec60dc1403 100644
--- a/lld/lib/ReaderWriter/PECOFF/WriterImportLibrary.cpp
+++ b/lld/lib/ReaderWriter/PECOFF/WriterImportLibrary.cpp
@@ -30,7 +30,7 @@ createModuleDefinitionFile(const PECOFFLinkingContext &ctx) {
<< "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)
diff --git a/lld/test/pecoff/exportlib2.test b/lld/test/pecoff/exportlib2.test
index 8698d0a71fc..ee396dd8da7 100644
--- a/lld/test/pecoff/exportlib2.test
+++ b/lld/test/pecoff/exportlib2.test
@@ -7,4 +7,4 @@
CHECK: LIBRARY "exportlib2.test.tmp.dll"
CHECK: EXPORTS
CHECK: exportfn1 @1
-CHECK: exportfn2 @2
+CHECK: exportfn2@8 @2
OpenPOWER on IntegriCloud