Skip to content

Commit 37c175a

Browse files
authored
[clang][Driver] Pass -machine argument to the linker explicitly for ARM64EC targets. (#86835)
This is required by the linker. Also add a new -marm64x command line argument to allow specifying -machine:arm64x.
1 parent 29e8bfc commit 37c175a

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4510,6 +4510,9 @@ def mwindows : Joined<["-"], "mwindows">, Group<m_Group>;
45104510
def mdll : Joined<["-"], "mdll">, Group<m_Group>;
45114511
def municode : Joined<["-"], "municode">, Group<m_Group>;
45124512
def mthreads : Joined<["-"], "mthreads">, Group<m_Group>;
4513+
def marm64x : Joined<["-"], "marm64x">, Group<m_Group>,
4514+
Visibility<[ClangOption, CLOption]>,
4515+
HelpText<"Link as a hybrid ARM64X image">;
45134516
def mguard_EQ : Joined<["-"], "mguard=">, Group<m_Group>,
45144517
HelpText<"Enable or disable Control Flow Guard checks and guard tables emission">,
45154518
Values<"none,cf,cf-nochecks">;

clang/lib/Driver/ToolChains/MSVC.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ void visualstudio::Linker::ConstructJob(Compilation &C, const JobAction &JA,
7979
CmdArgs.push_back(
8080
Args.MakeArgString(std::string("-out:") + Output.getFilename()));
8181

82+
if (Args.hasArg(options::OPT_marm64x))
83+
CmdArgs.push_back("-machine:arm64x");
84+
else if (TC.getTriple().isWindowsArm64EC())
85+
CmdArgs.push_back("-machine:arm64ec");
86+
8287
if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles) &&
8388
!C.getDriver().IsCLMode() && !C.getDriver().IsFlangMode()) {
8489
CmdArgs.push_back("-defaultlib:libcmt");
@@ -1017,4 +1022,7 @@ void MSVCToolChain::addClangTargetOptions(
10171022
if (DriverArgs.hasFlag(options::OPT_fno_rtti, options::OPT_frtti,
10181023
/*Default=*/false))
10191024
CC1Args.push_back("-D_HAS_STATIC_RTTI=0");
1025+
1026+
if (Arg *A = DriverArgs.getLastArgNoClaim(options::OPT_marm64x))
1027+
A->ignoreTargetSpecific();
10201028
}

clang/test/Driver/msvc-link.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,23 @@
3636
// VFSOVERLAY: "--vfsoverlay"
3737
// VFSOVERLAY: lld-link
3838
// VFSOVERLAY: "/vfsoverlay:{{.*}}" "{{.*}}.obj"
39+
40+
// RUN: %clang -target arm64ec-pc-windows-msvc -fuse-ld=link -### %s 2>&1 | FileCheck --check-prefix=ARM64EC %s
41+
// RUN: %clang_cl -target arm64ec-pc-windows-msvc -fuse-ld=link -### %s 2>&1 | FileCheck --check-prefix=ARM64EC %s
42+
// RUN: %clang_cl -arm64EC -fuse-ld=link -### %s 2>&1 | FileCheck --check-prefix=ARM64EC %s
43+
// ARM64EC: "-machine:arm64ec"
44+
45+
// RUN: %clang -target arm64ec-pc-windows-msvc -fuse-ld=link -marm64x -### %s 2>&1 | \
46+
// RUN: FileCheck --check-prefix=ARM64X %s
47+
// RUN: %clang -target aarch64-pc-windows-msvc -fuse-ld=link -marm64x -### %s 2>&1 | \
48+
// RUN: FileCheck --check-prefix=ARM64X %s
49+
// RUN: %clang_cl -marm64x -fuse-ld=link -### %s 2>&1 | FileCheck --check-prefix=ARM64X %s
50+
// RUN: %clang_cl -arm64EC -marm64x -fuse-ld=link -### %s 2>&1 | FileCheck --check-prefix=ARM64X %s
51+
// ARM64X: "-machine:arm64x"
52+
53+
// RUN: not %clang -target x86_64-linux-gnu -marm64x -### %s 2>&1 | FileCheck --check-prefix=HYBRID-ERR %s
54+
// HYBRID-ERR: error: unsupported option '-marm64x' for target 'x86_64-linux-gnu'
55+
56+
// RUN: %clang -c -marm64x -target arm64ec-pc-windows-msvc -fuse-ld=link -### %s 2>&1 | \
57+
// RUN: FileCheck --check-prefix=HYBRID-WARN %s
58+
// HYBRID-WARN: warning: argument unused during compilation: '-marm64x' [-Wunused-command-line-argument]

0 commit comments

Comments
 (0)