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 @@ -148,6 +148,18 @@ std::string Path = Args.getLastArgValue(OPT_l); + // If ExtName is set (if the "ExtName = Name" syntax was used), overwrite + // Name with ExtName and clear ExtName. When only creating an import + // library and not linking, the internal name is irrelevant. This avoids + // cases where writeImportLibrary tries to transplant decoration from + // symbol decoration onto ExtName. + for (COFFShortExport& E : Def->Exports) { + if (!E.ExtName.empty()) { + E.Name = E.ExtName; + E.ExtName.clear(); + } + } + if (Machine == IMAGE_FILE_MACHINE_I386 && Args.getLastArg(OPT_k)) { for (COFFShortExport& E : Def->Exports) { if (!E.AliasTarget.empty() || (!E.Name.empty() && E.Name[0] == '?')) @@ -162,7 +174,6 @@ // By making sure E.SymbolName != E.Name for decorated symbols, // writeImportLibrary writes these symbols with the type // IMPORT_NAME_UNDECORATE. - E.ExtName = E.ExtName.substr(0, E.ExtName.find('@', 1)); } } 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 @@ -10,6 +10,8 @@ StdcallAlias@4==StdcallFunction@4 ??_7exception@@6B@ StdcallExportName@4=StdcallInternalFunction@4 +OtherStdcallExportName@4=CdeclInternalFunction +CdeclExportName=StdcallInternalFunction@4 ; CHECK: Name type: noprefix ; CHECK: Symbol: __imp__CdeclFunction @@ -25,5 +27,12 @@ ; CHECK: Symbol: ??_7exception@@6B@ ; CHECK-NM: W _StdcallAlias@4 ; CHECK-NM: U _StdcallFunction@4 +; CHECK: Name type: undecorate ; CHECK: Symbol: __imp__StdcallExportName@4{{$}} ; CHECK: Symbol: _StdcallExportName@4{{$}} +; CHECK: Name type: undecorate +; CHECK: Symbol: __imp__OtherStdcallExportName@4{{$}} +; CHECK: Symbol: _OtherStdcallExportName@4{{$}} +; CHECK: Name type: noprefix +; CHECK: Symbol: __imp__CdeclExportName +; CHECK: Symbol: _CdeclExportName