diff --git a/lld/include/lld/ReaderWriter/PECOFFLinkingContext.h b/lld/include/lld/ReaderWriter/PECOFFLinkingContext.h index 7283161a35ac..30bd0414e4be 100644 --- a/lld/include/lld/ReaderWriter/PECOFFLinkingContext.h +++ b/lld/include/lld/ReaderWriter/PECOFFLinkingContext.h @@ -67,7 +67,7 @@ public: } std::string name; - std::string internalName; + std::string externalName; int ordinal; bool noname; bool isData; diff --git a/lld/lib/Driver/WinLinkModuleDef.cpp b/lld/lib/Driver/WinLinkModuleDef.cpp index 61d3e967ba13..9992f92068f6 100644 --- a/lld/lib/Driver/WinLinkModuleDef.cpp +++ b/lld/lib/Driver/WinLinkModuleDef.cpp @@ -195,6 +195,17 @@ bool Parser::parseExport(PECOFFLinkingContext::ExportDesc &result) { } result.name = _tok._range; + consumeToken(); + if (_tok._kind == Kind::equal) { + consumeToken(); + if (_tok._kind != Kind::identifier) + return false; + result.externalName = result.name; + result.name = _tok._range; + } else { + ungetToken(); + } + for (;;) { consumeToken(); if (_tok._kind == Kind::identifier && _tok._range[0] == '@') { diff --git a/lld/lib/ReaderWriter/PECOFF/EdataPass.cpp b/lld/lib/ReaderWriter/PECOFF/EdataPass.cpp index 8d6424138e72..cc5a003a4844 100644 --- a/lld/lib/ReaderWriter/PECOFF/EdataPass.cpp +++ b/lld/lib/ReaderWriter/PECOFF/EdataPass.cpp @@ -77,7 +77,8 @@ static bool getExportedAtoms(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()); + if (desc.externalName.empty()) + desc.externalName = removeLeadingUnderscore(atom->name()); exports.insert(desc); } ctx.getDllExports().swap(exports); diff --git a/lld/lib/ReaderWriter/PECOFF/WriterImportLibrary.cpp b/lld/lib/ReaderWriter/PECOFF/WriterImportLibrary.cpp index dec60dc1403e..77e2af43e031 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 << " " << desc.internalName << " @" << desc.ordinal; + os << " " << desc.externalName << " @" << desc.ordinal; if (desc.noname) os << " NONAME"; if (desc.isData) diff --git a/lld/test/pecoff/Inputs/export.obj.yaml b/lld/test/pecoff/Inputs/export.obj.yaml index cd961862e411..f1c043f81966 100644 --- a/lld/test/pecoff/Inputs/export.obj.yaml +++ b/lld/test/pecoff/Inputs/export.obj.yaml @@ -48,4 +48,10 @@ symbols: SimpleType: IMAGE_SYM_TYPE_NULL ComplexType: IMAGE_SYM_DTYPE_NULL StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: _exportfn6 + Value: 16 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL ... diff --git a/lld/test/pecoff/Inputs/exports.def b/lld/test/pecoff/Inputs/exports.def index 54031a6f258a..360a58e64cb1 100644 --- a/lld/test/pecoff/Inputs/exports.def +++ b/lld/test/pecoff/Inputs/exports.def @@ -3,3 +3,4 @@ EXPORTS exportfn1 @5 ; foo exportfn2 + exportfn5=exportfn6 diff --git a/lld/test/pecoff/export.test b/lld/test/pecoff/export.test index ed3a88a855ae..ebe5b1447aac 100644 --- a/lld/test/pecoff/export.test +++ b/lld/test/pecoff/export.test @@ -39,4 +39,5 @@ CHECK4: DLL name: export.test.tmp4.dll CHECK4: Ordinal RVA Name CHECK4-NEXT: 5 0x2008 exportfn1 CHECK4-NEXT: 6 0x2010 exportfn2 -CHECK4-NEXT: 7 0x2010 exportfn3@256 +CHECK4-NEXT: 7 0x2010 exportfn6 +CHECK4-NEXT: 8 0x2010 exportfn3@256