Author: hans Date: Mon Aug 21 16:26:07 2017 New Revision: 311408 URL: http://llvm.org/viewvc/llvm-project?rev=311408&view=rev Log: Merging r310990: ------------------------------------------------------------------------ r310990 | mstorsjo | 2017-08-15 22:18:36 -0700 (Tue, 15 Aug 2017) | 18 lines
[llvm-dlltool] Fix creating stdcall/fastcall import libraries for i386 Hook up the -k option (that in the original GNU dlltool removes the @n suffix from the symbol that the final executable ends up linked to). In llvm-dlltool, make sure that functions end up with the undecorate name type if this option is set and they are decorated. In mingw, when creating import libraries from def files instead of creating an import library as a side effect of linking a DLL, the symbol names in the def contain the stdcall/fastcall decoration (but no leading underscore). By setting the undecorate name type, a linker linking to the import library will omit the decoration from the DLL import entry. With this in place, mingw-w64 for i386 built with llvm-dlltool/clang produces import libraries that actually work. Differential Revision: https://reviews.llvm.org/D36548 ------------------------------------------------------------------------ Added: llvm/branches/release_50/test/DllTool/coff-decorated.def - copied unchanged from r310990, llvm/trunk/test/DllTool/coff-decorated.def Modified: llvm/branches/release_50/ (props changed) llvm/branches/release_50/lib/Object/COFFModuleDefinition.cpp llvm/branches/release_50/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp llvm/branches/release_50/lib/ToolDrivers/llvm-dlltool/Options.td Propchange: llvm/branches/release_50/ ------------------------------------------------------------------------------ --- svn:mergeinfo (original) +++ svn:mergeinfo Mon Aug 21 16:26:07 2017 @@ -1,3 +1,3 @@ /llvm/branches/Apple/Pertwee:110850,110961 /llvm/branches/type-system-rewrite:133420-134817 -/llvm/trunk:155241,308483-308484,308503,308808,308813,308847,308891,308906,308950,308963,308978,308986,309044,309071,309113,309120,309122,309140,309227,309302,309321,309323,309325,309330,309343,309353,309355,309422,309481,309483,309495,309555,309561,309594,309614,309651,309744,309758,309849,309928,309930,309945,310066,310071,310190,310240-310242,310250,310253,310262,310267,310481,310492,310498,310510,310534,310552,310604,310712,310779,310784,310796,310842,310906,310926,310939,310979,310988,310991,311068,311087,311229,311258 +/llvm/trunk:155241,308483-308484,308503,308808,308813,308847,308891,308906,308950,308963,308978,308986,309044,309071,309113,309120,309122,309140,309227,309302,309321,309323,309325,309330,309343,309353,309355,309422,309481,309483,309495,309555,309561,309594,309614,309651,309744,309758,309849,309928,309930,309945,310066,310071,310190,310240-310242,310250,310253,310262,310267,310481,310492,310498,310510,310534,310552,310604,310712,310779,310784,310796,310842,310906,310926,310939,310979,310988,310990-310991,311068,311087,311229,311258 Modified: llvm/branches/release_50/lib/Object/COFFModuleDefinition.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_50/lib/Object/COFFModuleDefinition.cpp?rev=311408&r1=311407&r2=311408&view=diff ============================================================================== --- llvm/branches/release_50/lib/Object/COFFModuleDefinition.cpp (original) +++ llvm/branches/release_50/lib/Object/COFFModuleDefinition.cpp Mon Aug 21 16:26:07 2017 @@ -232,7 +232,13 @@ private: for (;;) { read(); if (Tok.K == Identifier && Tok.Value[0] == '@') { - Tok.Value.drop_front().getAsInteger(10, E.Ordinal); + if (Tok.Value.drop_front().getAsInteger(10, E.Ordinal)) { + // Not an ordinal modifier at all, but the next export (fastcall + // decorated) - complete the current one. + unget(); + Info.Exports.push_back(E); + return Error::success(); + } read(); if (Tok.K == KwNoname) { E.Noname = true; Modified: llvm/branches/release_50/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_50/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp?rev=311408&r1=311407&r2=311408&view=diff ============================================================================== --- llvm/branches/release_50/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp (original) +++ llvm/branches/release_50/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp Mon Aug 21 16:26:07 2017 @@ -161,6 +161,22 @@ int llvm::dlltoolDriverMain(llvm::ArrayR if (Path.empty()) Path = getImplibPath(Def->OutputFile); + if (Machine == IMAGE_FILE_MACHINE_I386 && Args.getLastArg(OPT_k)) { + for (COFFShortExport& E : Def->Exports) { + if (E.isWeak() || (!E.Name.empty() && E.Name[0] == '?')) + continue; + E.SymbolName = E.Name; + // Trim off the trailing decoration. Symbols will always have a + // starting prefix here (either _ for cdecl/stdcall, @ for fastcall + // or ? for C++ functions). (Vectorcall functions also will end up having + // a prefix here, even if they shouldn't.) + E.Name = E.Name.substr(0, E.Name.find('@', 1)); + // By making sure E.SymbolName != E.Name for decorated symbols, + // writeImportLibrary writes these symbols with the type + // IMPORT_NAME_UNDECORATE. + } + } + if (writeImportLibrary(Def->OutputFile, Path, Def->Exports, Machine, true)) return 1; return 0; Modified: llvm/branches/release_50/lib/ToolDrivers/llvm-dlltool/Options.td URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_50/lib/ToolDrivers/llvm-dlltool/Options.td?rev=311408&r1=311407&r2=311408&view=diff ============================================================================== --- llvm/branches/release_50/lib/ToolDrivers/llvm-dlltool/Options.td (original) +++ llvm/branches/release_50/lib/ToolDrivers/llvm-dlltool/Options.td Mon Aug 21 16:26:07 2017 @@ -12,13 +12,13 @@ def D_long : JoinedOrSeparate<["--"], "d def d: JoinedOrSeparate<["-"], "d">, HelpText<"Input .def File">; def d_long : JoinedOrSeparate<["--"], "input-def">, Alias<d>; +def k: Flag<["-"], "k">, HelpText<"Kill @n Symbol from export">; +def k_alias: Flag<["--"], "kill-at">, Alias<k>; + //============================================================================== // The flags below do nothing. They are defined only for dlltool compatibility. //============================================================================== -def k: Flag<["-"], "k">, HelpText<"Kill @n Symbol from export">; -def k_alias: Flag<["--"], "kill-at">, Alias<k>; - def S: JoinedOrSeparate<["-"], "S">, HelpText<"Assembler">; def S_alias: JoinedOrSeparate<["--"], "as">, Alias<S>; _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits