[llvm-dlltool] Handle external and internal names with differing decoration
authorMartin Storsjo <martin@martin.st>
Mon, 2 Sep 2019 13:28:16 +0000 (13:28 +0000)
committerMartin Storsjo <martin@martin.st>
Mon, 2 Sep 2019 13:28:16 +0000 (13:28 +0000)
Also add a missed part of the test from SVN r369747.

Differential Revision: https://reviews.llvm.org/D66996

llvm-svn: 370656

llvm/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp
llvm/test/tools/llvm-dlltool/coff-decorated.def

index bd026a0..19f253b 100644 (file)
@@ -148,6 +148,18 @@ int llvm::dlltoolDriverMain(llvm::ArrayRef<const char *> ArgsArr) {
 
   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 @@ int llvm::dlltoolDriverMain(llvm::ArrayRef<const char *> ArgsArr) {
       // 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 e1ca3cb..42adea9 100644 (file)
@@ -10,6 +10,8 @@ StdcallFunction@4
 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 @@ StdcallExportName@4=StdcallInternalFunction@4
 ; 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