Index: llvm/trunk/include/llvm/Object/COFFImportFile.h =================================================================== --- llvm/trunk/include/llvm/Object/COFFImportFile.h +++ llvm/trunk/include/llvm/Object/COFFImportFile.h @@ -74,6 +74,7 @@ std::string Name; std::string ExtName; std::string SymbolName; + std::string AliasTarget; uint16_t Ordinal = 0; bool Noname = false; @@ -81,10 +82,6 @@ bool Private = false; bool Constant = false; - bool isWeak() { - return ExtName.size() && ExtName != Name; - } - friend bool operator==(const COFFShortExport &L, const COFFShortExport &R) { return L.Name == R.Name && L.ExtName == R.ExtName && L.Ordinal == R.Ordinal && L.Noname == R.Noname && @@ -98,8 +95,7 @@ Error writeImportLibrary(StringRef ImportName, StringRef Path, ArrayRef Exports, - COFF::MachineTypes Machine, bool MakeWeakAliases, - bool MinGW); + COFF::MachineTypes Machine, bool MinGW); } // namespace object } // namespace llvm Index: llvm/trunk/lib/Object/COFFImportFile.cpp =================================================================== --- llvm/trunk/lib/Object/COFFImportFile.cpp +++ llvm/trunk/lib/Object/COFFImportFile.cpp @@ -566,8 +566,7 @@ Error writeImportLibrary(StringRef ImportName, StringRef Path, ArrayRef Exports, - MachineTypes Machine, bool MakeWeakAliases, - bool MinGW) { + MachineTypes Machine, bool MinGW) { std::vector Members; ObjectFactory OF(llvm::sys::path::filename(ImportName), Machine); @@ -585,12 +584,6 @@ 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 @@ 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)); } Index: llvm/trunk/lib/Object/COFFModuleDefinition.cpp =================================================================== --- llvm/trunk/lib/Object/COFFModuleDefinition.cpp +++ llvm/trunk/lib/Object/COFFModuleDefinition.cpp @@ -37,6 +37,7 @@ Identifier, Comma, Equal, + EqualEqual, KwBase, KwConstant, KwData, @@ -104,9 +105,10 @@ } 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 @@ 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(); Index: llvm/trunk/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp =================================================================== --- llvm/trunk/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp +++ llvm/trunk/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp @@ -158,7 +158,7 @@ if (Machine == IMAGE_FILE_MACHINE_I386 && Args.getLastArg(OPT_k)) { for (COFFShortExport& E : Def->Exports) { - if (E.isWeak() || (!E.Name.empty() && E.Name[0] == '?')) + if (!E.AliasTarget.empty() || (!E.Name.empty() && E.Name[0] == '?')) continue; E.SymbolName = E.Name; // Trim off the trailing decoration. Symbols will always have a @@ -173,7 +173,7 @@ } } - if (writeImportLibrary(Def->OutputFile, Path, Def->Exports, Machine, true, true)) + if (writeImportLibrary(Def->OutputFile, Path, Def->Exports, Machine, true)) return 1; return 0; } Index: llvm/trunk/test/tools/llvm-dlltool/coff-decorated.def =================================================================== --- llvm/trunk/test/tools/llvm-dlltool/coff-decorated.def +++ llvm/trunk/test/tools/llvm-dlltool/coff-decorated.def @@ -7,7 +7,7 @@ CdeclFunction StdcallFunction@4 @FastcallFunction@4 -StdcallAlias@4=StdcallFunction@4 +StdcallAlias@4==StdcallFunction@4 ??_7exception@@6B@ ; CHECK: Name type: noprefix Index: llvm/trunk/test/tools/llvm-dlltool/coff-weak-exports.def =================================================================== --- llvm/trunk/test/tools/llvm-dlltool/coff-weak-exports.def +++ llvm/trunk/test/tools/llvm-dlltool/coff-weak-exports.def @@ -4,8 +4,25 @@ LIBRARY test.dll EXPORTS TestFunction==AltTestFunction +; When creating an import library, the DLL internal function name of +; the implementation of a function isn't visible at all. +ImpLibName = Implementation +; A different import library name and implementation name can be mixed +; with exposing it via a different name in the DLL than in code. +ImpLibName2 = Implementation2 == AltTestFunction2 +; The fact that a DLL export entry is a forward to a different DLL doesn't +; matter for the import library +ImpLibName3 = kernel32.Sleep ; CHECK: U AltTestFunction ; CHECK-NEXT: w TestFunction ; CHECK: U __imp_AltTestFunction ; CHECK-NEXT: w __imp_TestFunction +; CHECK: T ImpLibName +; CHECK-NEXT: T __imp_ImpLibName +; CHECK: U AltTestFunction2 +; CHECK-NEXT: w ImpLibName2 +; CHECK: U __imp_AltTestFunction2 +; CHECK-NEXT: w __imp_ImpLibName2 +; CHECK: T ImpLibName3 +; CHECK-NEXT: T __imp_ImpLibName3