Skip to content

Commit 03751cd

Browse files
committed
[llvm-lib] Use ARM64EC machine type for import libraries when -machine:arm64x is used.
This is compatible with MSVC, -machine:arm64x is essentially an alias to -machine:arm64ec. To make a type library that exposes both native and EC symbols, an additional -defArm64Native argument is needed in both cases.
1 parent 3fbac79 commit 03751cd

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

llvm/lib/Object/COFFImportFile.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -626,8 +626,11 @@ Error writeImportLibrary(StringRef ImportName, StringRef Path,
626626
MachineTypes Machine, bool MinGW,
627627
ArrayRef<COFFShortExport> NativeExports) {
628628

629-
MachineTypes NativeMachine =
630-
isArm64EC(Machine) ? IMAGE_FILE_MACHINE_ARM64 : Machine;
629+
MachineTypes NativeMachine = Machine;
630+
if (isArm64EC(Machine)) {
631+
NativeMachine = IMAGE_FILE_MACHINE_ARM64;
632+
Machine = IMAGE_FILE_MACHINE_ARM64EC;
633+
}
631634

632635
std::vector<NewArchiveMember> Members;
633636
ObjectFactory OF(llvm::sys::path::filename(ImportName), NativeMachine);

llvm/test/tools/llvm-lib/arm64ec-implib.test

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,17 @@ ARMAP-NEXT: test_NULL_THUNK_DATA in test.dll
3434

3535
RUN: llvm-readobj test.lib | FileCheck -check-prefix=READOBJ %s
3636

37-
READOBJ: File: test.lib(test.dll)
37+
READOBJ: File: test{{.*}}.lib(test.dll)
3838
READOBJ-NEXT: Format: COFF-ARM64{{$}}
3939
READOBJ-NEXT: Arch: aarch64
4040
READOBJ-NEXT: AddressSize: 64bit
4141
READOBJ-EMPTY:
42-
READOBJ-NEXT: File: test.lib(test.dll)
42+
READOBJ-NEXT: File: test{{.*}}.lib(test.dll)
4343
READOBJ-NEXT: Format: COFF-ARM64{{$}}
4444
READOBJ-NEXT: Arch: aarch64
4545
READOBJ-NEXT: AddressSize: 64bit
4646
READOBJ-EMPTY:
47-
READOBJ-NEXT: File: test.lib(test.dll)
47+
READOBJ-NEXT: File: test{{.*}}.lib(test.dll)
4848
READOBJ-NEXT: Format: COFF-ARM64{{$}}
4949
READOBJ-NEXT: Arch: aarch64
5050
READOBJ-NEXT: AddressSize: 64bit
@@ -96,6 +96,11 @@ READOBJ-NEXT: Name type: name
9696
READOBJ-NEXT: Export name: dataexp
9797
READOBJ-NEXT: Symbol: __imp_dataexp
9898

99+
Using -machine:arm64x gives the same output.
100+
RUN: llvm-lib -machine:arm64x -def:test.def -out:testx.lib
101+
RUN: llvm-nm --print-armap testx.lib | FileCheck -check-prefix=ARMAP %s
102+
RUN: llvm-readobj testx.lib | FileCheck -check-prefix=READOBJ %s
103+
99104
Creating a new lib containing the existing lib:
100105
RUN: llvm-lib -machine:arm64ec test.lib -out:test2.lib
101106
RUN: llvm-nm --print-armap test2.lib | FileCheck -check-prefix=ARMAP %s
@@ -246,7 +251,9 @@ READOBJX-NEXT: Symbol: __imp_dataexp
246251

247252

248253
RUN: llvm-lib -machine:arm64ec -def:test.def -defArm64Native:test2.def -out:test2.lib
254+
RUN: llvm-lib -machine:arm64ec -def:test.def -defArm64Native:test2.def -out:test2x.lib
249255
RUN: llvm-nm --print-armap test2.lib | FileCheck -check-prefix=ARMAPX2 %s
256+
RUN: llvm-nm --print-armap test2x.lib | FileCheck -check-prefix=ARMAPX2 %s
250257

251258
ARMAPX2: Archive map
252259
ARMAPX2-NEXT: __IMPORT_DESCRIPTOR_test2 in test2.dll

0 commit comments

Comments
 (0)