diff options
author | Martin Storsjo <martin@martin.st> | 2018-05-09 09:21:53 +0000 |
---|---|---|
committer | Martin Storsjo <martin@martin.st> | 2018-05-09 09:21:53 +0000 |
commit | 284ab80f8d055bb350246c6e28d9a5579d784144 (patch) | |
tree | e239cdf69d0fedfc4842f6cfdf983bb213054252 /llvm/lib/Object | |
parent | f1f8f4a1fd116323a6c4f3a4bde87243bab5668d (diff) | |
download | bcm5719-llvm-284ab80f8d055bb350246c6e28d9a5579d784144.tar.gz bcm5719-llvm-284ab80f8d055bb350246c6e28d9a5579d784144.zip |
[COFF] Improve correctness of def parsing for GNU features
The operator == used for exporting a function with a different
name in the DLL compared to the name in the import library
(which is useful for adding linker level aliases for function
in the import library) is a feature distinct and different from
the operator = used for exporting a function with a different
name (both in import library and DLL) than in the implementation
producing the DLL.
When creating an import library using dlltool, from a def file that
contains forwards (Func = OtherDll.Func), this shouldn't affect the
produced import library, which should still behave just as if it
was a normal exported function.
This clears a lot of confusion and subtle misunderstandings, and
avoids a parameter that was used to avoid creating weak aliases
when invoked from lld. (This parameter was added previously due to
the existing conflation of the two features.)
Differential Revision: https://reviews.llvm.org/D46245
llvm-svn: 331859
Diffstat (limited to 'llvm/lib/Object')
-rw-r--r-- | llvm/lib/Object/COFFImportFile.cpp | 15 | ||||
-rw-r--r-- | llvm/lib/Object/COFFModuleDefinition.cpp | 13 |
2 files changed, 18 insertions, 10 deletions
diff --git a/llvm/lib/Object/COFFImportFile.cpp b/llvm/lib/Object/COFFImportFile.cpp index c249a6d97b4..4bde1db3078 100644 --- a/llvm/lib/Object/COFFImportFile.cpp +++ b/llvm/lib/Object/COFFImportFile.cpp @@ -566,8 +566,7 @@ NewArchiveMember ObjectFactory::createWeakExternal(StringRef Sym, Error writeImportLibrary(StringRef ImportName, StringRef Path, ArrayRef<COFFShortExport> Exports, - MachineTypes Machine, bool MakeWeakAliases, - bool MinGW) { + MachineTypes Machine, bool MinGW) { std::vector<NewArchiveMember> Members; ObjectFactory OF(llvm::sys::path::filename(ImportName), Machine); @@ -585,12 +584,6 @@ Error writeImportLibrary(StringRef ImportName, StringRef Path, if (E.Private) continue; - if (E.isWeak() && MakeWeakAliases) { - Members.push_back(OF.createWeakExternal(E.Name, E.ExtName, false)); - Members.push_back(OF.createWeakExternal(E.Name, E.ExtName, true)); - continue; - } - ImportType ImportType = IMPORT_CODE; if (E.Data) ImportType = IMPORT_DATA; @@ -606,6 +599,12 @@ Error writeImportLibrary(StringRef ImportName, StringRef Path, if (!Name) return Name.takeError(); + if (!E.AliasTarget.empty() && *Name != E.AliasTarget) { + Members.push_back(OF.createWeakExternal(E.AliasTarget, *Name, false)); + Members.push_back(OF.createWeakExternal(E.AliasTarget, *Name, true)); + continue; + } + Members.push_back( OF.createShortImport(*Name, E.Ordinal, ImportType, NameType)); } diff --git a/llvm/lib/Object/COFFModuleDefinition.cpp b/llvm/lib/Object/COFFModuleDefinition.cpp index a571354648d..c703071b86e 100644 --- a/llvm/lib/Object/COFFModuleDefinition.cpp +++ b/llvm/lib/Object/COFFModuleDefinition.cpp @@ -37,6 +37,7 @@ enum Kind { Identifier, Comma, Equal, + EqualEqual, KwBase, KwConstant, KwData, @@ -104,9 +105,10 @@ public: } case '=': Buf = Buf.drop_front(); - // GNU dlltool accepts both = and ==. - if (Buf.startswith("=")) + if (Buf.startswith("=")) { Buf = Buf.drop_front(); + return Token(EqualEqual, "=="); + } return Token(Equal, "="); case ',': Buf = Buf.drop_front(); @@ -282,6 +284,13 @@ private: E.Private = true; continue; } + if (Tok.K == EqualEqual) { + read(); + E.AliasTarget = Tok.Value; + if (Machine == IMAGE_FILE_MACHINE_I386 && !isDecorated(E.AliasTarget, MingwDef)) + E.AliasTarget = std::string("_").append(E.AliasTarget); + continue; + } unget(); Info.Exports.push_back(E); return Error::success(); |