Skip to content

Commit fd19137

Browse files
authored
[llvm-dlltool] Add ARM64EC target support. (#81624)
Add new target and a new -n option allowing to specify native module definition file, similar to how -defArm64Native works in llvm-lib. This also changes archive format to use K_COFF like non-mingw targets. It's required on ARM64EC, but it should be fine for other targets too.
1 parent 7c422dd commit fd19137

File tree

4 files changed

+68
-5
lines changed

4 files changed

+68
-5
lines changed

llvm/lib/Object/COFFImportFile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@ Error writeImportLibrary(StringRef ImportName, StringRef Path,
712712
return e;
713713

714714
return writeArchive(Path, Members, SymtabWritingMode::NormalSymtab,
715-
MinGW ? object::Archive::K_GNU : object::Archive::K_COFF,
715+
object::Archive::K_COFF,
716716
/*Deterministic*/ true, /*Thin*/ false,
717717
/*OldArchiveBuf*/ nullptr, isArm64EC(Machine));
718718
}

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ MachineTypes getEmulation(StringRef S) {
7575
.Case("i386:x86-64", IMAGE_FILE_MACHINE_AMD64)
7676
.Case("arm", IMAGE_FILE_MACHINE_ARMNT)
7777
.Case("arm64", IMAGE_FILE_MACHINE_ARM64)
78+
.Case("arm64ec", IMAGE_FILE_MACHINE_ARM64EC)
7879
.Default(IMAGE_FILE_MACHINE_UNKNOWN);
7980
}
8081

@@ -87,7 +88,8 @@ MachineTypes getMachine(Triple T) {
8788
case Triple::arm:
8889
return COFF::IMAGE_FILE_MACHINE_ARMNT;
8990
case Triple::aarch64:
90-
return COFF::IMAGE_FILE_MACHINE_ARM64;
91+
return T.isWindowsArm64EC() ? COFF::IMAGE_FILE_MACHINE_ARM64EC
92+
: COFF::IMAGE_FILE_MACHINE_ARM64;
9193
default:
9294
return COFF::IMAGE_FILE_MACHINE_UNKNOWN;
9395
}
@@ -168,7 +170,7 @@ int llvm::dlltoolDriverMain(llvm::ArrayRef<const char *> ArgsArr) {
168170
(!Args.hasArgNoClaim(OPT_d) && !Args.hasArgNoClaim(OPT_l))) {
169171
Table.printHelp(outs(), "llvm-dlltool [options] file...", "llvm-dlltool",
170172
false);
171-
llvm::outs() << "\nTARGETS: i386, i386:x86-64, arm, arm64\n";
173+
llvm::outs() << "\nTARGETS: i386, i386:x86-64, arm, arm64, arm64ec\n";
172174
return 1;
173175
}
174176

@@ -201,7 +203,19 @@ int llvm::dlltoolDriverMain(llvm::ArrayRef<const char *> ArgsArr) {
201203
if (auto *Arg = Args.getLastArg(OPT_D))
202204
OutputFile = Arg->getValue();
203205

204-
std::vector<COFFShortExport> Exports;
206+
std::vector<COFFShortExport> Exports, NativeExports;
207+
208+
if (Args.hasArg(OPT_n)) {
209+
if (!isArm64EC(Machine)) {
210+
llvm::errs() << "native .def file is supported only on arm64ec target\n";
211+
return 1;
212+
}
213+
if (!parseModuleDefinition(Args.getLastArg(OPT_n)->getValue(),
214+
IMAGE_FILE_MACHINE_ARM64, AddUnderscores,
215+
NativeExports, OutputFile))
216+
return 1;
217+
}
218+
205219
if (!parseModuleDefinition(Args.getLastArg(OPT_d)->getValue(), Machine,
206220
AddUnderscores, Exports, OutputFile))
207221
return 1;
@@ -230,7 +244,7 @@ int llvm::dlltoolDriverMain(llvm::ArrayRef<const char *> ArgsArr) {
230244

231245
std::string Path = std::string(Args.getLastArgValue(OPT_l));
232246
if (!Path.empty() && writeImportLibrary(OutputFile, Path, Exports, Machine,
233-
/*MinGW=*/true))
247+
/*MinGW=*/true, NativeExports))
234248
return 1;
235249
return 0;
236250
}

llvm/lib/ToolDrivers/llvm-dlltool/Options.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ def D_long : JoinedOrSeparate<["--"], "dllname">, Alias<D>;
1212
def d: JoinedOrSeparate<["-"], "d">, HelpText<"Input .def File">;
1313
def d_long : JoinedOrSeparate<["--"], "input-def">, Alias<d>;
1414

15+
def n: JoinedOrSeparate<["-"], "n">, HelpText<"Input native .def File on ARM64EC">;
16+
def n_long : JoinedOrSeparate<["--"], "input-native-def">, Alias<d>;
17+
1518
def k: Flag<["-"], "k">, HelpText<"Kill @n Symbol from export">;
1619
def k_alias: Flag<["--"], "kill-at">, Alias<k>;
1720

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
Test creating ARM64EC importlib.
2+
3+
RUN: split-file %s %t.dir && cd %t.dir
4+
5+
RUN: llvm-dlltool -m arm64ec -d test.def -l test.lib
6+
RUN: llvm-nm --print-armap test.lib | FileCheck --check-prefix=ARMAP %s
7+
8+
ARMAP: Archive map
9+
ARMAP-NEXT: __IMPORT_DESCRIPTOR_test in test.dll
10+
ARMAP-NEXT: __NULL_IMPORT_DESCRIPTOR in test.dll
11+
ARMAP-NEXT: test_NULL_THUNK_DATA in test.dll
12+
ARMAP-EMPTY:
13+
ARMAP-NEXT: Archive EC map
14+
ARMAP-NEXT: #func in test.dll
15+
ARMAP-NEXT: __imp_aux_func in test.dll
16+
ARMAP-NEXT: __imp_func in test.dll
17+
ARMAP-NEXT: func in test.dll
18+
19+
RUN: llvm-dlltool -m arm64ec -d test.def -n test2.def -l test2.lib
20+
RUN: llvm-nm --print-armap test2.lib | FileCheck --check-prefix=ARMAP2 %s
21+
22+
ARMAP2: Archive map
23+
ARMAP2-NEXT: __IMPORT_DESCRIPTOR_test in test.dll
24+
ARMAP2-NEXT: __NULL_IMPORT_DESCRIPTOR in test.dll
25+
ARMAP2-NEXT: __imp_otherfunc in test.dll
26+
ARMAP2-NEXT: otherfunc in test.dll
27+
ARMAP2-NEXT: test_NULL_THUNK_DATA in test.dll
28+
ARMAP2-EMPTY:
29+
ARMAP2-NEXT: Archive EC map
30+
ARMAP2-NEXT: #func in test.dll
31+
ARMAP2-NEXT: __imp_aux_func in test.dll
32+
ARMAP2-NEXT: __imp_func in test.dll
33+
ARMAP2-NEXT: func in test.dll
34+
35+
RUN: not llvm-dlltool -m arm64 -d test.def -n test2.def -l test2.lib 2>&1 | FileCheck --check-prefix=ERR %s
36+
ERR: native .def file is supported only on arm64ec target
37+
38+
#--- test.def
39+
LIBRARY test.dll
40+
EXPORTS
41+
func
42+
43+
#--- test2.def
44+
LIBRARY test.dll
45+
EXPORTS
46+
otherfunc

0 commit comments

Comments
 (0)