Skip to content

Commit 1cec6b2

Browse files
committed
[llvm-dlltool] Handle external and internal names with differing decoration
Also add a missed part of the test from SVN r369747. Differential Revision: https://reviews.llvm.org/D66996 llvm-svn: 370656
1 parent 4078226 commit 1cec6b2

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

llvm/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,18 @@ int llvm::dlltoolDriverMain(llvm::ArrayRef<const char *> ArgsArr) {
148148

149149
std::string Path = Args.getLastArgValue(OPT_l);
150150

151+
// If ExtName is set (if the "ExtName = Name" syntax was used), overwrite
152+
// Name with ExtName and clear ExtName. When only creating an import
153+
// library and not linking, the internal name is irrelevant. This avoids
154+
// cases where writeImportLibrary tries to transplant decoration from
155+
// symbol decoration onto ExtName.
156+
for (COFFShortExport& E : Def->Exports) {
157+
if (!E.ExtName.empty()) {
158+
E.Name = E.ExtName;
159+
E.ExtName.clear();
160+
}
161+
}
162+
151163
if (Machine == IMAGE_FILE_MACHINE_I386 && Args.getLastArg(OPT_k)) {
152164
for (COFFShortExport& E : Def->Exports) {
153165
if (!E.AliasTarget.empty() || (!E.Name.empty() && E.Name[0] == '?'))
@@ -162,7 +174,6 @@ int llvm::dlltoolDriverMain(llvm::ArrayRef<const char *> ArgsArr) {
162174
// By making sure E.SymbolName != E.Name for decorated symbols,
163175
// writeImportLibrary writes these symbols with the type
164176
// IMPORT_NAME_UNDECORATE.
165-
E.ExtName = E.ExtName.substr(0, E.ExtName.find('@', 1));
166177
}
167178
}
168179

llvm/test/tools/llvm-dlltool/coff-decorated.def

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ StdcallFunction@4
1010
StdcallAlias@4==StdcallFunction@4
1111
??_7exception@@6B@
1212
StdcallExportName@4=StdcallInternalFunction@4
13+
OtherStdcallExportName@4=CdeclInternalFunction
14+
CdeclExportName=StdcallInternalFunction@4
1315

1416
; CHECK: Name type: noprefix
1517
; CHECK: Symbol: __imp__CdeclFunction
@@ -25,5 +27,12 @@ StdcallExportName@4=StdcallInternalFunction@4
2527
; CHECK: Symbol: ??_7exception@@6B@
2628
; CHECK-NM: W _StdcallAlias@4
2729
; CHECK-NM: U _StdcallFunction@4
30+
; CHECK: Name type: undecorate
2831
; CHECK: Symbol: __imp__StdcallExportName@4{{$}}
2932
; CHECK: Symbol: _StdcallExportName@4{{$}}
33+
; CHECK: Name type: undecorate
34+
; CHECK: Symbol: __imp__OtherStdcallExportName@4{{$}}
35+
; CHECK: Symbol: _OtherStdcallExportName@4{{$}}
36+
; CHECK: Name type: noprefix
37+
; CHECK: Symbol: __imp__CdeclExportName
38+
; CHECK: Symbol: _CdeclExportName

0 commit comments

Comments
 (0)