[PECOFF] Support =internalName syntax in .def file.

Export definitions in a module definition file is as follows:

  exportedname[=internalname] [@ordinal [NONAME]] [PRIVATE] [DATA]

Previously we did not support =internalname, so users couldn't export
symbols from a DLL with a different name.

llvm-svn: 207827
This commit is contained in:
Rui Ueyama 2014-05-02 03:43:51 +00:00
parent 9663780e35
commit 0e363b75a4
7 changed files with 24 additions and 4 deletions

View File

@ -67,7 +67,7 @@ public:
}
std::string name;
std::string internalName;
std::string externalName;
int ordinal;
bool noname;
bool isData;

View File

@ -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] == '@') {

View File

@ -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);

View File

@ -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)

View File

@ -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
...

View File

@ -3,3 +3,4 @@
EXPORTS
exportfn1 @5 ; foo
exportfn2
exportfn5=exportfn6

View File

@ -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