Skip to content

Commit ec118c7

Browse files
authored
Enable AltJits build for LoongArch64 and RiscV64 (#110282)
* Build LoongArch64 and RiscV64 AltJit * Add a new target for alljitscommunity
1 parent 6649e7f commit ec118c7

19 files changed

+81
-47
lines changed

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@
328328
<!-- Runtime doesn't support Arcade-driven target framework filtering. -->
329329
<NoTargetFrameworkFiltering>true</NoTargetFrameworkFiltering>
330330

331-
<NativeBuildPartitionPropertiesToRemove>ClrFullNativeBuild;ClrRuntimeSubset;ClrJitSubset;ClrPalTestsSubset;ClrAllJitsSubset;ClrILToolsSubset;ClrNativeAotSubset;ClrSpmiSubset;ClrCrossComponentsSubset;ClrDebugSubset;HostArchitecture;PgoInstrument;NativeOptimizationDataSupported;CMakeArgs;CxxStandardLibrary;CxxStandardLibraryStatic;CxxAbiLibrary</NativeBuildPartitionPropertiesToRemove>
331+
<NativeBuildPartitionPropertiesToRemove>ClrFullNativeBuild;ClrRuntimeSubset;ClrJitSubset;ClrPalTestsSubset;ClrAllJitsSubset;ClrAllJitsCommunitySubset;ClrILToolsSubset;ClrNativeAotSubset;ClrSpmiSubset;ClrCrossComponentsSubset;ClrDebugSubset;HostArchitecture;PgoInstrument;NativeOptimizationDataSupported;CMakeArgs;CxxStandardLibrary;CxxStandardLibraryStatic;CxxAbiLibrary</NativeBuildPartitionPropertiesToRemove>
332332
<UseSystemZlib Condition="'$(TargetsAppleMobile)' == 'true' or '$(TargetOS)' == 'android' or '$(TargetArchitecture)' == 'armv6'">true</UseSystemZlib>
333333
</PropertyGroup>
334334

eng/Subsets.props

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@
191191
<SubsetName Include="Clr.Hosts" Description="The CoreCLR corerun test host." />
192192
<SubsetName Include="Clr.Jit" Description="The JIT for the CoreCLR .NET runtime." />
193193
<SubsetName Include="Clr.AllJits" Description="All of the cross-targeting JIT compilers for the CoreCLR .NET runtime." />
194+
<SubsetName Include="Clr.AllJitsCommunity" Description="All of the cross-targeting JIT compilers for the CoreCLR .NET runtime, including community targets." />
194195
<SubsetName Include="Clr.Spmi" Description="SuperPMI, a tool for CoreCLR JIT testing." />
195196
<SubsetName Include="Clr.CoreLib" Description="The managed System.Private.CoreLib library for CoreCLR." />
196197
<SubsetName Include="Clr.NativeCoreLib" Description="Run crossgen on System.Private.CoreLib library for CoreCLR." />
@@ -291,6 +292,10 @@
291292
<ClrRuntimeBuildSubsets>$(ClrRuntimeBuildSubsets);ClrAllJitsSubset=true</ClrRuntimeBuildSubsets>
292293
</PropertyGroup>
293294

295+
<PropertyGroup Condition="$(_subset.Contains('+clr.alljitscommunity+'))">
296+
<ClrRuntimeBuildSubsets>$(ClrRuntimeBuildSubsets);ClrAllJitsCommunitySubset=true</ClrRuntimeBuildSubsets>
297+
</PropertyGroup>
298+
294299
<PropertyGroup Condition="$(_subset.Contains('+clr.iltools+'))">
295300
<ClrRuntimeBuildSubsets>$(ClrRuntimeBuildSubsets);ClrILToolsSubset=true</ClrRuntimeBuildSubsets>
296301
</PropertyGroup>

eng/native/functions.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
function(clr_unknown_arch)
22
if (WIN32)
3-
message(FATAL_ERROR "Only AMD64, ARM64, ARM and I386 hosts are supported. Found: ${CMAKE_SYSTEM_PROCESSOR}")
3+
message(FATAL_ERROR "Only AMD64, ARM64, ARM, I386, LOONGARCH64 and RISCV64 hosts are supported. Found: ${CMAKE_SYSTEM_PROCESSOR}")
44
elseif(CLR_CROSS_COMPONENTS_BUILD)
5-
message(FATAL_ERROR "Only AMD64, ARM64 and I386 hosts are supported for linux cross-architecture component. Found: ${CMAKE_SYSTEM_PROCESSOR}")
5+
message(FATAL_ERROR "Only AMD64, ARM64, I386, LOONGARCH64 and RISCV64 hosts are supported for linux cross-architecture component. Found: ${CMAKE_SYSTEM_PROCESSOR}")
66
else()
77
message(FATAL_ERROR "'${CMAKE_SYSTEM_PROCESSOR}' is an unsupported architecture.")
88
endif()
@@ -319,7 +319,7 @@ function(add_component componentName)
319319
else()
320320
set(componentTargetName "${componentName}")
321321
endif()
322-
if (${ARGC} EQUAL 3 AND "${ARG2}" STREQUAL "EXCLUDE_FROM_ALL")
322+
if (${ARGC} EQUAL 3 AND "${ARGV2}" STREQUAL "EXCLUDE_FROM_ALL")
323323
set(exclude_from_all_flag "EXCLUDE_FROM_ALL")
324324
endif()
325325
get_property(definedComponents GLOBAL PROPERTY CLR_CMAKE_COMPONENTS)

src/coreclr/build-runtime.cmd

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ set __TargetArchX64=0
4444
set __TargetArchX86=0
4545
set __TargetArchArm=0
4646
set __TargetArchArm64=0
47+
set __TargetArchLoongArch64=0
48+
set __TargetArchRiscV64=0
4749

4850
set __BuildTypeDebug=0
4951
set __BuildTypeChecked=0
@@ -89,6 +91,8 @@ if /i "%1" == "-x64" (set __TargetArchX64=1&shift&goto Arg_Loop)
8991
if /i "%1" == "-x86" (set __TargetArchX86=1&shift&goto Arg_Loop)
9092
if /i "%1" == "-arm" (set __TargetArchArm=1&shift&goto Arg_Loop)
9193
if /i "%1" == "-arm64" (set __TargetArchArm64=1&shift&goto Arg_Loop)
94+
if /i "%1" == "-loongarch64" (set __TargetArchLoongArch64=1&shift&goto Arg_Loop)
95+
if /i "%1" == "-riscv64" (set __TargetArchRiscV64=1&shift&goto Arg_Loop)
9296

9397
if /i "%1" == "-debug" (set __BuildTypeDebug=1&shift&goto Arg_Loop)
9498
if /i "%1" == "-checked" (set __BuildTypeChecked=1&shift&goto Arg_Loop)
@@ -103,6 +107,8 @@ if /i "%1" == "x64" (set __TargetArchX64=1&shift&goto Arg_Loop)
103107
if /i "%1" == "x86" (set __TargetArchX86=1&shift&goto Arg_Loop)
104108
if /i "%1" == "arm" (set __TargetArchArm=1&shift&goto Arg_Loop)
105109
if /i "%1" == "arm64" (set __TargetArchArm64=1&shift&goto Arg_Loop)
110+
if /i "%1" == "loongarch64" (set __TargetArchLoongArch64=1&shift&goto Arg_Loop)
111+
if /i "%1" == "riscv64" (set __TargetArchRiscV64=1&shift&goto Arg_Loop)
106112

107113
if /i "%1" == "debug" (set __BuildTypeDebug=1&shift&goto Arg_Loop)
108114
if /i "%1" == "checked" (set __BuildTypeChecked=1&shift&goto Arg_Loop)
@@ -167,16 +173,18 @@ if defined VCINSTALLDIR (
167173

168174
if defined __BuildAll goto BuildAll
169175

170-
set /A __TotalSpecifiedTargetArch=__TargetArchX64 + __TargetArchX86 + __TargetArchArm + __TargetArchArm64
176+
set /A __TotalSpecifiedTargetArch=__TargetArchX64 + __TargetArchX86 + __TargetArchArm + __TargetArchArm64 + __TargetArchLoongArch64 + __TargetArchRiscV64
171177
if %__TotalSpecifiedTargetArch% GTR 1 (
172178
echo Error: more than one build architecture specified, but "all" not specified.
173179
goto Usage
174180
)
175181

176-
if %__TargetArchX64%==1 set __TargetArch=x64
177-
if %__TargetArchX86%==1 set __TargetArch=x86
178-
if %__TargetArchArm%==1 set __TargetArch=arm
179-
if %__TargetArchArm64%==1 set __TargetArch=arm64
182+
if %__TargetArchX64%==1 set __TargetArch=x64
183+
if %__TargetArchX86%==1 set __TargetArch=x86
184+
if %__TargetArchArm%==1 set __TargetArch=arm
185+
if %__TargetArchArm64%==1 set __TargetArch=arm64
186+
if %__TargetArchLoongArch64%==1 set __TargetArch=loongarch64
187+
if %__TargetArchRiscV64%==1 set __TargetArch=riscv64
180188
if "%__HostArch%" == "" set __HostArch=%__TargetArch%
181189

182190
set /A __TotalSpecifiedBuildType=__BuildTypeDebug + __BuildTypeChecked + __BuildTypeRelease
@@ -294,6 +302,7 @@ if NOT DEFINED PYTHON (
294302
)
295303

296304
set __CMakeTarget=
305+
set __BuildAllJitsCommunity=0
297306
for /f "delims=" %%a in ("-%__RequestedBuildComponents%-") do (
298307
set "string=%%a"
299308
if not "!string:-hosts-=!"=="!string!" (
@@ -305,6 +314,10 @@ for /f "delims=" %%a in ("-%__RequestedBuildComponents%-") do (
305314
if not "!string:-alljits-=!"=="!string!" (
306315
set __CMakeTarget=!__CMakeTarget! alljits
307316
)
317+
if not "!string:-alljitscommunity-=!"=="!string!" (
318+
set __CMakeTarget=!__CMakeTarget! alljitscommunity
319+
set __BuildAllJitsCommunity=1
320+
)
308321
if not "!string:-runtime-=!"=="!string!" (
309322
set __CMakeTarget=!__CMakeTarget! runtime
310323
)
@@ -459,18 +472,24 @@ REM ============================================================================
459472

460473
set __TargetArchList=
461474

462-
set /A __TotalSpecifiedTargetArch=__TargetArchX64 + __TargetArchX86 + __TargetArchArm + __TargetArchArm64
475+
set /A __TotalSpecifiedTargetArch=__TargetArchX64 + __TargetArchX86 + __TargetArchArm + __TargetArchArm64 + __TargetArchLoongArch64 + __TargetArchRiscV64
463476
if %__TotalSpecifiedTargetArch% EQU 0 (
464477
REM Nothing specified means we want to build all architectures.
465478
set __TargetArchList=x64 x86 arm arm64
479+
480+
if %__BuildAllJitsCommunity%==1 (
481+
set __TargetArchList=%__TargetArchList% loongarch64 riscv64
482+
)
466483
)
467484

468485
REM Otherwise, add all the specified architectures to the list.
469486

470-
if %__TargetArchX64%==1 set __TargetArchList=%__TargetArchList% x64
471-
if %__TargetArchX86%==1 set __TargetArchList=%__TargetArchList% x86
472-
if %__TargetArchArm%==1 set __TargetArchList=%__TargetArchList% arm
473-
if %__TargetArchArm64%==1 set __TargetArchList=%__TargetArchList% arm64
487+
if %__TargetArchX64%==1 set __TargetArchList=%__TargetArchList% x64
488+
if %__TargetArchX86%==1 set __TargetArchList=%__TargetArchList% x86
489+
if %__TargetArchArm%==1 set __TargetArchList=%__TargetArchList% arm
490+
if %__TargetArchArm64%==1 set __TargetArchList=%__TargetArchList% arm64
491+
if %__TargetArchLoongArch64%==1 set __TargetArchList=%__TargetArchList% loongarch64
492+
if %__TargetArchRiscV64%==1 set __TargetArchList=%__TargetArchList% riscv64
474493

475494
set __BuildTypeList=
476495

@@ -553,7 +572,7 @@ echo All arguments are optional. The options are:
553572
echo.
554573
echo.-? -h -help --help: view this message.
555574
echo -all: Builds all configurations and platforms.
556-
echo Build architecture: one of -x64, -x86, -arm, -arm64 ^(default: -x64^).
575+
echo Build architecture: one of -x64, -x86, -arm, -arm64, -loongarch64, -riscv64 ^(default: -x64^).
557576
echo Build type: one of -Debug, -Checked, -Release ^(default: -Debug^).
558577
echo -component ^<name^> : specify this option one or more times to limit components built to those specified.
559578
echo Allowed ^<name^>: hosts jit alljits runtime paltests iltools nativeaot spmi

src/coreclr/build-runtime.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export PYTHON
2121
usage_list+=("-pgodatapath: path to profile guided optimization data.")
2222
usage_list+=("-pgoinstrument: generate instrumented code for profile guided optimization enabled binaries.")
2323
usage_list+=("-staticanalyzer: use scan_build static analyzer.")
24-
usage_list+=("-component: Build individual components instead of the full project. Available options are 'hosts', 'jit', 'runtime', 'paltests', 'alljits', 'iltools', 'nativeaot', and 'spmi'. Can be specified multiple times.")
24+
usage_list+=("-component: Build individual components instead of the full project. Available options are 'hosts', 'jit', 'runtime', 'paltests', 'alljits', 'alljitscommunity', 'iltools', 'nativeaot', and 'spmi'. Can be specified multiple times.")
2525
usage_list+=("-subdir: Append a directory with the provided name to the obj and bin paths.")
2626

2727
setup_dirs_local()

src/coreclr/gcinfo/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ endif()
6666
if (CLR_CMAKE_TARGET_ARCH_ARM64 OR CLR_CMAKE_TARGET_ARCH_AMD64)
6767
create_gcinfo_lib(TARGET gcinfo_universal_arm64 OS universal ARCH arm64)
6868
create_gcinfo_lib(TARGET gcinfo_unix_x64 OS unix ARCH x64)
69+
if (CLR_CMAKE_BUILD_COMMUNITY_ALTJITS EQUAL 1)
70+
create_gcinfo_lib(TARGET gcinfo_unix_loongarch64 OS unix ARCH loongarch64)
71+
create_gcinfo_lib(TARGET gcinfo_unix_riscv64 OS unix ARCH riscv64)
72+
endif(CLR_CMAKE_BUILD_COMMUNITY_ALTJITS EQUAL 1)
6973
create_gcinfo_lib(TARGET gcinfo_win_x64 OS win ARCH x64)
7074
endif (CLR_CMAKE_TARGET_ARCH_ARM64 OR CLR_CMAKE_TARGET_ARCH_AMD64)
7175

src/coreclr/inc/corinfo.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3351,6 +3351,17 @@ class ICorDynamicInfo : public ICorStaticInfo
33513351
//
33523352
#define IMAGE_REL_BASED_REL_THUMB_MOV32_PCREL 0x14
33533353

3354+
//
3355+
// LOONGARCH64 relocation types
3356+
//
3357+
#define IMAGE_REL_LOONGARCH64_PC 0x0003
3358+
#define IMAGE_REL_LOONGARCH64_JIR 0x0004
3359+
3360+
//
3361+
// RISCV64 relocation types
3362+
//
3363+
#define IMAGE_REL_RISCV64_PC 0x0003
3364+
33543365
/**********************************************************************************/
33553366
#ifdef TARGET_64BIT
33563367
#define USE_PER_FRAME_PINVOKE_INIT

src/coreclr/inc/gcinfotypes.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -781,8 +781,8 @@ void FASTCALL decodeCallPattern(int pattern,
781781
#define DENORMALIZE_STACK_SLOT(x) ((x)<<3)
782782
#define NORMALIZE_CODE_LENGTH(x) ((x)>>2) // All Instructions are 4 bytes long
783783
#define DENORMALIZE_CODE_LENGTH(x) ((x)<<2)
784-
#define NORMALIZE_STACK_BASE_REGISTER(x) ((x) == 22 ? 0 : 1) // Encode Frame pointer fp=$22 as zero
785-
#define DENORMALIZE_STACK_BASE_REGISTER(x) ((x) == 0 ? 22 : 3)
784+
#define NORMALIZE_STACK_BASE_REGISTER(x) ((x) == 22 ? 0u : 1u) // Encode Frame pointer fp=$22 as zero
785+
#define DENORMALIZE_STACK_BASE_REGISTER(x) ((x) == 0 ? 22u : 3u)
786786
#define NORMALIZE_SIZE_OF_STACK_AREA(x) ((x)>>3)
787787
#define DENORMALIZE_SIZE_OF_STACK_AREA(x) ((x)<<3)
788788
#define CODE_OFFSETS_NEED_NORMALIZATION 1
@@ -834,8 +834,8 @@ void FASTCALL decodeCallPattern(int pattern,
834834
#define DENORMALIZE_STACK_SLOT(x) ((x)<<3)
835835
#define NORMALIZE_CODE_LENGTH(x) ((x)>>2) // All Instructions are 4 bytes long
836836
#define DENORMALIZE_CODE_LENGTH(x) ((x)<<2)
837-
#define NORMALIZE_STACK_BASE_REGISTER(x) ((x) == 8 ? 0 : 1) // Encode Frame pointer X8 as zero, sp/x2 as 1
838-
#define DENORMALIZE_STACK_BASE_REGISTER(x) ((x) == 0 ? 8 : 2)
837+
#define NORMALIZE_STACK_BASE_REGISTER(x) ((x) == 8 ? 0u : 1u) // Encode Frame pointer X8 as zero, sp/x2 as 1
838+
#define DENORMALIZE_STACK_BASE_REGISTER(x) ((x) == 0 ? 8u : 2u)
839839
#define NORMALIZE_SIZE_OF_STACK_AREA(x) ((x)>>3)
840840
#define DENORMALIZE_SIZE_OF_STACK_AREA(x) ((x)<<3)
841841
#define CODE_OFFSETS_NEED_NORMALIZATION 1

src/coreclr/inc/palclr.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,4 +612,8 @@
612612
#define IMAGE_FILE_MACHINE_LOONGARCH64 0x6264 // LOONGARCH64.
613613
#endif
614614

615+
#ifndef IMAGE_FILE_MACHINE_RISCV64
616+
#define IMAGE_FILE_MACHINE_RISCV64 0x5064 // RISCV64.
617+
#endif
618+
615619
#endif // defined(HOST_WINDOWS)

src/coreclr/jit/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,10 @@ if (CLR_CMAKE_TARGET_ARCH_ARM64 OR CLR_CMAKE_TARGET_ARCH_AMD64)
642642
create_standalone_jit(TARGET clrjit_universal_arm64_${ARCH_HOST_NAME} OS universal ARCH arm64)
643643
create_standalone_jit(TARGET clrjit_unix_x64_${ARCH_HOST_NAME} OS unix_anyos ARCH x64)
644644
create_standalone_jit(TARGET clrjit_win_x64_${ARCH_HOST_NAME} OS win ARCH x64)
645+
if (CLR_CMAKE_BUILD_COMMUNITY_ALTJITS EQUAL 1)
646+
create_standalone_jit(TARGET clrjit_unix_loongarch64_${ARCH_HOST_NAME} OS unix ARCH loongarch64)
647+
create_standalone_jit(TARGET clrjit_unix_riscv64_${ARCH_HOST_NAME} OS unix ARCH riscv64)
648+
endif(CLR_CMAKE_BUILD_COMMUNITY_ALTJITS EQUAL 1)
645649
endif (CLR_CMAKE_TARGET_ARCH_ARM64 OR CLR_CMAKE_TARGET_ARCH_AMD64)
646650

647651
if (CLR_CMAKE_TARGET_ARCH_LOONGARCH64)

0 commit comments

Comments
 (0)