From eb11fae6d08f479c0799db45860a98af528fa6e7 Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Sat, 28 Jul 2018 10:51:19 +0000 Subject: Vendor import of llvm trunk r338150: https://llvm.org/svn/llvm-project/llvm/trunk@338150 --- lib/Object/COFFImportFile.cpp | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) (limited to 'lib/Object/COFFImportFile.cpp') diff --git a/lib/Object/COFFImportFile.cpp b/lib/Object/COFFImportFile.cpp index 93631f1ad811..dc11cc4bcffe 100644 --- a/lib/Object/COFFImportFile.cpp +++ b/lib/Object/COFFImportFile.cpp @@ -91,7 +91,15 @@ static void writeStringTable(std::vector &B, } static ImportNameType getNameType(StringRef Sym, StringRef ExtName, - MachineTypes Machine) { + MachineTypes Machine, bool MinGW) { + // A decorated stdcall function in MSVC is exported with the + // type IMPORT_NAME, and the exported function name includes the + // the leading underscore. In MinGW on the other hand, a decorated + // stdcall function still omits the underscore (IMPORT_NAME_NOPREFIX). + // See the comment in isDecorated in COFFModuleDefinition.cpp for more + // details. + if (ExtName.startswith("_") && ExtName.contains('@') && !MinGW) + return IMPORT_NAME; if (Sym != ExtName) return IMPORT_NAME_UNDECORATE; if (Machine == IMAGE_FILE_MACHINE_I386 && Sym.startswith("_")) @@ -538,7 +546,12 @@ NewArchiveMember ObjectFactory::createWeakExternal(StringRef Sym, u16(0), IMAGE_SYM_CLASS_WEAK_EXTERNAL, 1}, - {{{2, 0, 0, 0, 3, 0, 0, 0}}, u32(0), u16(0), u16(0), uint8_t(0), 0}, + {{{2, 0, 0, 0, IMAGE_WEAK_EXTERN_SEARCH_ALIAS, 0, 0, 0}}, + u32(0), + u16(0), + u16(0), + IMAGE_SYM_CLASS_NULL, + 0}, }; SymbolTable[2].Name.Offset.Offset = sizeof(uint32_t); @@ -558,7 +571,7 @@ NewArchiveMember ObjectFactory::createWeakExternal(StringRef Sym, Error writeImportLibrary(StringRef ImportName, StringRef Path, ArrayRef Exports, - MachineTypes Machine, bool MakeWeakAliases) { + MachineTypes Machine, bool MinGW) { std::vector Members; ObjectFactory OF(llvm::sys::path::filename(ImportName), Machine); @@ -576,12 +589,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; @@ -589,7 +596,7 @@ Error writeImportLibrary(StringRef ImportName, StringRef Path, ImportType = IMPORT_CONST; StringRef SymbolName = E.SymbolName.empty() ? E.Name : E.SymbolName; - ImportNameType NameType = getNameType(SymbolName, E.Name, Machine); + ImportNameType NameType = getNameType(SymbolName, E.Name, Machine, MinGW); Expected Name = E.ExtName.empty() ? SymbolName : replace(SymbolName, E.Name, E.ExtName); @@ -597,6 +604,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)); } -- cgit v1.2.3