From: imhameed Date: Mon, 26 Oct 2020 16:38:25 +0000 (-0700) Subject: CoreCLR runtime tests + Mono LLVM AOT on arm64 Linux (#41751) X-Git-Tag: submit/tizen/20210909.063632~4925 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5e6de70217496c0daf29fe85cfeb8feed2d49c27;p=platform%2Fupstream%2Fdotnet%2Fruntime.git CoreCLR runtime tests + Mono LLVM AOT on arm64 Linux (#41751) This change: - Adds new options to mono.proj: - MonoAOTEnableLLVM, which enables (or disables) building a Mono AOT cross compiler with LLVM; - MonoAOTLLVMDir, which specifies the path to a copy of LLVM suitable for building a Mono AOT cross compiler, and is optional; and - BuildMonoAOTCrossCompilerOnly, which allows building a Mono AOT cross compiler without building an associated full Mono runtime. - Changes offsets-tool.py's user interface slightly; '--include-prefix' is renamed to '--prefix' and may be specified multiple times. While this latter feature isn't necessary to build a Mono cross compiler today, because we don't use distribution-supplied cross-compilation headers on CI, it does make it easier to experiment with the offsets tool using arbitrary header layouts. For example, Debian's arm64 cross-compilation packages scatter useful header files across `/usr/lib/gcc-cross/aarch64-linux-gnu` and `/usr/aarch64-linux-gnu`. - Updates the docker image used for arm64 cross-compilation to a newer revision that includes libclang (see also https://github.com/dotnet/dotnet-buildtools-prereqs-docker/pull/375). - Adds some tests that currently fail to compile with Mono LLVM AOT to issues.targets. - Adds a Linux_arm64 LLVM AOT job to CI. Nothing particularly fancy is done to build the Mono LLVM AOT cross compiler; it is built as a step in the same job that also sends Linux_arm64 tests to Helix. --- diff --git a/docs/workflow/building/coreclr/linux-instructions.md b/docs/workflow/building/coreclr/linux-instructions.md index 8c6147f..674465b 100644 --- a/docs/workflow/building/coreclr/linux-instructions.md +++ b/docs/workflow/building/coreclr/linux-instructions.md @@ -53,7 +53,7 @@ This table of images might often become stale as we change our images as our req | Alpine | x64 | `mcr.microsoft.com/dotnet-buildtools/prereqs:alpine-3.9-WithNode-0fc54a3-20190918214015` | - | -clang9 | | CentOS 7 (build for RHEL 7) | x64 | `mcr.microsoft.com/dotnet-buildtools/prereqs:centos-7-359e48e-20200313130914` | - | -clang9 | | Ubuntu 16.04 | arm32 (armhf) | `mcr.microsoft.com/dotnet-buildtools/prereqs:ubuntu-16.04-cross-20200413125008-09ec757` | `/crossrootfs/arm` | -clang9 | -| Ubuntu 16.04 | arm64 (arm64v8) | `mcr.microsoft.com/dotnet-buildtools/prereqs:ubuntu-16.04-cross-arm64-20200413125008-cfdd435` | `/crossrootfs/arm64` | -clang9 | +| Ubuntu 16.04 | arm64 (arm64v8) | `mcr.microsoft.com/dotnet-buildtools/prereqs:ubuntu-16.04-cross-arm64-20201022204150-b2c2436` | `/crossrootfs/arm64` | -clang9 | | Alpine | arm64 (arm64v8) | `mcr.microsoft.com/dotnet-buildtools/prereqs:ubuntu-16.04-cross-arm64-alpine-20200413125008-406629a` | `/crossrootfs/arm64` | -clang5.0 | Environment diff --git a/eng/Subsets.props b/eng/Subsets.props index 7f2a252..b9b28de 100644 --- a/eng/Subsets.props +++ b/eng/Subsets.props @@ -57,6 +57,7 @@ clr.runtime+clr.jit+clr.alljits+linuxdac+clr.corelib+clr.nativecorelib+clr.tools+clr.packages mono.llvm+ + mono.llvm+ $(DefaultMonoSubsets)mono.wasmruntime+ $(DefaultMonoSubsets)mono.runtime+mono.corelib+mono.packages diff --git a/eng/pipelines/common/platform-matrix.yml b/eng/pipelines/common/platform-matrix.yml index a365a29..de52c86 100644 --- a/eng/pipelines/common/platform-matrix.yml +++ b/eng/pipelines/common/platform-matrix.yml @@ -64,7 +64,7 @@ jobs: targetRid: linux-arm64 platform: Linux_arm64 container: - image: ubuntu-16.04-cross-arm64-20200413125008-cfdd435 + image: ubuntu-16.04-cross-arm64-20201022204150-b2c2436 registry: mcr jobParameters: runtimeFlavor: ${{ parameters.runtimeFlavor }} diff --git a/eng/pipelines/common/templates/runtimes/run-test-job.yml b/eng/pipelines/common/templates/runtimes/run-test-job.yml index 4824c50..e469612 100644 --- a/eng/pipelines/common/templates/runtimes/run-test-job.yml +++ b/eng/pipelines/common/templates/runtimes/run-test-job.yml @@ -223,7 +223,6 @@ jobs: artifactName: '$(coreClrProductArtifactName)' displayName: 'CoreCLR product download for Mono' - # Download and unzip the Microsoft.NET.Sdk.IL package needed for traversing # ilproj test projects during copynativeonly. - template: /eng/pipelines/common/download-artifact-step.yml @@ -263,6 +262,20 @@ jobs: - script: $(Build.SourcesDirectory)/src/tests/build$(scriptExt) generatelayoutonly $(runtimeFlavorArgs) $(crossgenArg) $(buildConfig) $(archType) $(crossArg) $(priorityArg) $(librariesOverrideArg) displayName: Generate CORE_ROOT + # Build a Mono LLVM AOT cross-compiler for non-amd64 targets (in this case, just arm64) + - ${{ if and(eq(parameters.runtimeFlavor, 'mono'), eq(parameters.runtimeVariant, 'llvmaot')) }}: + - ${{ if eq(parameters.archType, 'arm64') }}: + - script: ./build.sh + -subset mono + -c $(buildConfigUpper) + -arch $(archType) + /p:BuildMonoAotCrossCompiler=true + /p:BuildMonoAotCrossCompilerOnly=true + /p:MonoLibClang="/usr/lib/llvm-9/lib/libclang-9.so.1" + /p:MonoAOTEnableLLVM=true + /p:MonoAOTLLVMUseCxx11Abi=true + displayName: "Build Mono LLVM AOT cross compiler" + # Overwrite coreclr runtime binaries with mono ones - ${{ if eq(parameters.runtimeFlavor, 'mono') }}: @@ -274,8 +287,14 @@ jobs: displayName: "Patch dotnet with mono" - ${{ if and(eq(parameters.runtimeFlavor, 'mono'), eq(parameters.runtimeVariant, 'llvmaot')) }}: - - script: $(Build.SourcesDirectory)/src/tests/build$(scriptExt) mono_aot $(buildConfig) - displayName: "LLVM AOT compile CoreCLR tests" + - ${{ if eq(parameters.archType, 'x64') }}: + - script: $(Build.SourcesDirectory)/src/tests/build$(scriptExt) mono_aot $(buildConfig) $(archType) + displayName: "LLVM AOT compile CoreCLR tests" + - ${{ if eq(parameters.archType, 'arm64') }}: + - script: $(Build.SourcesDirectory)/src/tests/build$(scriptExt) mono_aot $(buildConfig) $(archType) cross + displayName: "LLVM AOT cross-compile CoreCLR tests" + env: + __MonoToolPrefix: aarch64-linux-gnu- # Send tests to Helix - template: /eng/pipelines/common/templates/runtimes/send-to-helix-step.yml diff --git a/eng/pipelines/mono/templates/build-job.yml b/eng/pipelines/mono/templates/build-job.yml index 3d29cde..a6f149d 100644 --- a/eng/pipelines/mono/templates/build-job.yml +++ b/eng/pipelines/mono/templates/build-job.yml @@ -74,12 +74,15 @@ jobs: value: wasm - name: osOverride value: '-os Browser' + - ${{ if and(eq(parameters.osGroup, 'Linux'), not(eq(parameters.archType, 'x64'))) }}: + name: llvmCxxAbi + value: /p:MonoLLVMUseCxx11Abi=true - ${{ if eq(parameters.runtimeVariant, 'llvmjit') }}: - name: llvmParameter - value: /p:MonoEnableLLVM=true /p:MonoBundleLLVMOptimizer=false + value: /p:MonoEnableLLVM=true /p:MonoBundleLLVMOptimizer=false $(llvmCxxAbi) - ${{ if eq(parameters.runtimeVariant, 'llvmaot') }}: - name: llvmParameter - value: /p:MonoEnableLLVM=true /p:MonoBundleLLVMOptimizer=true + value: /p:MonoEnableLLVM=true /p:MonoBundleLLVMOptimizer=true $(llvmCxxAbi) - ${{ parameters.variables }} steps: @@ -96,7 +99,7 @@ jobs: - script: $(Build.SourcesDirectory)\eng\common\init-tools-native.cmd -InstallDirectory $(Build.SourcesDirectory)\native-tools -Force displayName: Install native dependencies - - ${{ if in(parameters.osGroup, 'OSX', 'iOS','tvOS') }}: + - ${{ if in(parameters.osGroup, 'OSX', 'iOS','tvOS') }}: - script: | du -sh $(Build.SourcesDirectory)/* df -h @@ -110,7 +113,7 @@ jobs: - script: build$(scriptExt) -subset mono -c $(buildConfig) -arch $(archType) $(osOverride) -ci $(officialBuildIdArg) $(llvmParameter) displayName: Build product - - ${{ if in(parameters.osGroup, 'OSX', 'iOS','tvOS') }}: + - ${{ if in(parameters.osGroup, 'OSX', 'iOS','tvOS') }}: - script: | du -sh $(Build.SourcesDirectory)/* df -h diff --git a/eng/pipelines/runtime.yml b/eng/pipelines/runtime.yml index fa6522c..dfec6fb 100644 --- a/eng/pipelines/runtime.yml +++ b/eng/pipelines/runtime.yml @@ -585,6 +585,7 @@ jobs: buildConfig: release platforms: - Linux_x64 + - Linux_arm64 jobParameters: runtimeVariant: llvmaot condition: >- @@ -853,6 +854,7 @@ jobs: runtimeFlavor: mono platforms: - Linux_x64 + - Linux_arm64 helixQueueGroup: pr helixQueuesTemplate: /eng/pipelines/coreclr/templates/helix-queues-setup.yml jobParameters: diff --git a/src/mono/CMakeLists.txt b/src/mono/CMakeLists.txt index 5922e9f..c42eb92 100644 --- a/src/mono/CMakeLists.txt +++ b/src/mono/CMakeLists.txt @@ -148,6 +148,9 @@ if(NOT AOT_TARGET_TRIPLE STREQUAL "") elseif(AOT_TARGET_TRIPLE STREQUAL "wasm32-unknown-none") set(TARGET_SYSTEM_NAME "Emscripten") set(TARGET_ARCH "wasm") + elseif(AOT_TARGET_TRIPLE STREQUAL "aarch64-linux-gnu") + set(TARGET_SYSTEM_NAME "Linux") + set(TARGET_ARCH "arm64") else() message(FATAL_ERROR "AOT target '${AOT_TARGET_TRIPLE}' not supported.") endif() diff --git a/src/mono/Directory.Build.props b/src/mono/Directory.Build.props index 395895a..d636f1a 100644 --- a/src/mono/Directory.Build.props +++ b/src/mono/Directory.Build.props @@ -3,7 +3,7 @@ true - + $([System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture.ToString().ToLowerInvariant) @@ -101,7 +101,8 @@ $(ArtifactsObjDir)mono/$(PlatformConfigPathPart)/ - $(MonoObjDir)llvm + $(MonoObjDir)llvm + $(MonoObjDir)cross/llvm diff --git a/src/mono/llvm/llvm-init.proj b/src/mono/llvm/llvm-init.proj index 3286a3b..99ee504 100644 --- a/src/mono/llvm/llvm-init.proj +++ b/src/mono/llvm/llvm-init.proj @@ -25,6 +25,9 @@ + + + @@ -32,10 +35,18 @@ + + + + + + + + diff --git a/src/mono/mono.proj b/src/mono/mono.proj index 9ec0a4e..ac9a93e 100644 --- a/src/mono/mono.proj +++ b/src/mono/mono.proj @@ -4,6 +4,9 @@ Build properties: - MonoEnableInterpreter - enable the interpreter - MonoEnableLLVM - enable LLVM + - MonoLLVMDir - [optional] the directory where LLVM is located + - MonoAOTEnableLLVM - enable LLVM for an AOT-only Mono + - MonoAOTLLVMDir - [optional] the directory where LLVM is located, for an AOT-only Mono - MonoVerboseBuild - enable verbose build --> @@ -29,8 +32,12 @@ true true true + true + true + true $(MonoObjDir)cross\config.h true + true $(Compiler) clang @@ -88,7 +95,7 @@ - @@ -143,11 +150,17 @@ <_MonoCXXFLAGS Include="-D_GLIBCXX_USE_CXX11_ABI=0" /> + + <_MonoAOTCXXFLAGS Include="-D_GLIBCXX_USE_CXX11_ABI=0" /> + <_MonoCXXFLAGS Include="-D_GLIBCXX_USE_CXX11_ABI=1" /> + + <_MonoAOTCXXFLAGS Include="-D_GLIBCXX_USE_CXX11_ABI=1" /> + @@ -290,8 +303,8 @@ - - + + @@ -319,6 +332,13 @@ x86_64-apple-darwin10 + + true + aarch64-linux-gnu + $(MonoObjDir)cross/offsets-aarch-linux-gnu.h + $(MonoCrossDir)/usr/lib/gcc/aarch64-linux-gnu/5 + + true @@ -330,6 +350,7 @@ $(XcodeDir)/Toolchains/XcodeDefault.xctoolchain/usr/lib/libclang.dylib + $(MonoCrossDir) @@ -338,6 +359,7 @@ + @@ -346,6 +368,10 @@ python3 $(MonoProjectRoot)mono/tools/offsets-tool/offsets-tool.py @(MonoAotCrossOffsetsToolParams, ' ') + + <_MonoAOTCXXFLAGSOption>-DCMAKE_CXX_FLAGS="@(_MonoAOTCXXFLAGS, ' ')" + + @@ -357,7 +383,8 @@ - + + @@ -373,7 +400,7 @@ - + <_MonoRuntimeFilePath Condition="'$(TargetsWindows)' == 'true' and '$(Platform)' == 'x64'">$(MonoObjDir)x64\Bin\$(Configuration)\mono-2.0-sgen.dll <_MonoRuntimeFilePath Condition="'$(TargetsWindows)' == 'true' and '$(Platform)' == 'x86'">$(MonoObjDir)Win32\Bin\$(Configuration)\mono-2.0-sgen.dll <_MonoRuntimeFilePath Condition="'$(TargetsOSX)' == 'true'">$(MonoObjDir)out\lib\libmonosgen-2.0.dylib @@ -383,7 +410,9 @@ <_MonoRuntimeFilePath Condition="'$(TargetsBrowser)' == 'true'">$(MonoObjDir)out\lib\libmonosgen-2.0.a <_MonoRuntimeFilePath Condition="'$(_MonoRuntimeFilePath)' == ''">$(MonoObjDir)mono\mini\.libs\libmonosgen-2.0.so <_MonoRuntimeStaticFilePath Condition="'$(TargetsiOS)' == 'true' or '$(TargetstvOS)' == 'true' or '$(TargetsAndroid)' == 'true'">$(MonoObjDir)out\lib\libmonosgen-2.0.a - <_MonoAotCrossFilePath Condition="'$(BuildMonoAOTCrossCompiler)' == 'true'">$(MonoObjDir)cross\out\bin\mono-sgen + + + <_MonoAotCrossFilePath >$(MonoObjDir)cross\out\bin\mono-sgen @@ -403,10 +432,10 @@ <_MonoRuntimeArtifacts Condition="'$(MonoBundleLLVMOptimizer)' == 'true'" Include="$(MonoLLVMDir)\bin\opt"> $(RuntimeBinDir)\opt - <_MonoRuntimeArtifacts Condition="'$(TargetOS)' == 'iOS' or '$(TargetOS)' == 'tvOS'" Include="$(MonoLLVMDir)\bin\llc"> + <_MonoRuntimeArtifacts Condition="'$(MonoAOTBundleLLVMOptimizer)' == 'true'" Include="$(MonoAOTLLVMDir)\bin\llc"> $(RuntimeBinDir)cross\llc - <_MonoRuntimeArtifacts Condition="'$(TargetOS)' == 'iOS' or '$(TargetOS)' == 'tvOS'" Include="$(MonoLLVMDir)\bin\opt"> + <_MonoRuntimeArtifacts Condition="'$(MonoAOTBundleLLVMOptimizer)' == 'true'" Include="$(MonoAOTLLVMDir)\bin\opt"> $(RuntimeBinDir)cross\opt <_MonoIncludeArtifacts Include="$(MonoObjDir)out\include\**" /> diff --git a/src/mono/mono/tools/offsets-tool/offsets-tool.py b/src/mono/mono/tools/offsets-tool/offsets-tool.py index e7c2021..cef736a 100644 --- a/src/mono/mono/tools/offsets-tool/offsets-tool.py +++ b/src/mono/mono/tools/offsets-tool/offsets-tool.py @@ -55,14 +55,14 @@ class OffsetsTool: sys.exit (1) parser = argparse.ArgumentParser () - parser.add_argument ('--libclang', dest='libclang', help='path to shared library of libclang.{so,dylib}') + parser.add_argument ('--libclang', dest='libclang', help='path to shared library of libclang.{so,dylib}', required=True) parser.add_argument ('--emscripten-sdk', dest='emscripten_path', help='path to emscripten sdk') parser.add_argument ('--outfile', dest='outfile', help='path to output file', required=True) parser.add_argument ('--monodir', dest='mono_path', help='path to mono source tree', required=True) parser.add_argument ('--targetdir', dest='target_path', help='path to mono tree configured for target', required=True) parser.add_argument ('--abi=', dest='abi', help='ABI triple to generate', required=True) parser.add_argument ('--sysroot=', dest='sysroot', help='path to sysroot headers of target') - parser.add_argument ('--include-prefix=', dest='include_prefix', help='prefix path to include directory of target') + parser.add_argument ('--prefix=', dest='prefixes', action='append', help='prefix path to include directory of target') parser.add_argument ('--netcore', dest='netcore', help='target runs with netcore', action='store_true') args = parser.parse_args () @@ -89,16 +89,18 @@ class OffsetsTool: # Linux elif "arm-linux-gnueabihf" == args.abi: + require_sysroot (args) self.target = Target ("TARGET_ARM", None, ["ARM_FPU_VFP", "HAVE_ARMV5", "HAVE_ARMV6", "HAVE_ARMV7"] + LINUX_DEFINES) self.target_args += ["--target=arm---gnueabihf"] self.target_args += ["-I", args.sysroot + "/include"] - if args.include_prefix: - if not os.path.isdir (args.include_prefix): - print ("provided path via --include-prefix (\"" + args.include_prefix + "\") doesn't exist.", file=sys.stderr) - sys.exit (1) - self.target_args += ["-I", args.include_prefix + "/include"] - self.target_args += ["-I", args.include_prefix + "/include-fixed"] + if args.prefixes: + for prefix in args.prefixes: + if not os.path.isdir (prefix): + print ("provided path via --prefix (\"" + prefix + "\") doesn't exist.", file=sys.stderr) + sys.exit (1) + self.target_args += ["-I", prefix + "/include"] + self.target_args += ["-I", prefix + "/include-fixed"] else: found = False for i in range (11, 5, -1): @@ -111,9 +113,23 @@ class OffsetsTool: break if not found: - print ("could not find a valid include path for target, provide one via --include-prefix=.", file=sys.stderr) + print ("could not find a valid include path for target, provide one via --prefix=.", file=sys.stderr) sys.exit (1) + elif "aarch64-linux-gnu" == args.abi: + require_sysroot (args) + self.target = Target ("TARGET_ARM64", None, LINUX_DEFINES) + self.target_args += ["--target=aarch64-linux-gnu"] + self.target_args += ["--sysroot", args.sysroot] + self.target_args += ["-I", args.sysroot + "/include"] + if args.prefixes: + for prefix in args.prefixes: + if not os.path.isdir (prefix): + print ("provided path via --prefix (\"" + prefix + "\") doesn't exist.", file=sys.stderr) + sys.exit (1) + self.target_args += ["-I", prefix + "/include"] + self.target_args += ["-I", prefix + "/include-fixed"] + # iOS elif "arm-apple-darwin10" == args.abi: require_sysroot (args) diff --git a/src/mono/msbuild/aot-compile.proj b/src/mono/msbuild/aot-compile.proj index 2bceabf..3a2e716 100644 --- a/src/mono/msbuild/aot-compile.proj +++ b/src/mono/msbuild/aot-compile.proj @@ -1,6 +1,10 @@ - + + + + + diff --git a/src/tests/build.sh b/src/tests/build.sh index 9fa47da..3894752 100755 --- a/src/tests/build.sh +++ b/src/tests/build.sh @@ -49,13 +49,12 @@ build_test_wrappers() build_mono_aot() { __RuntimeFlavor="mono" - __MonoBinDir="$__RootBinDir/bin/mono/$__TargetOS.$__BuildArch.$__BuildType" __Exclude="$__RepoRootDir/src/tests/issues.targets" __TestBinDir="$__TestWorkingDir" CORE_ROOT="$__TestBinDir"/Tests/Core_Root export __Exclude export CORE_ROOT - build_MSBuild_projects "Tests_MonoAot" "$__RepoRootDir/src/tests/run.proj" "Mono AOT compile tests" "/t:MonoAotCompileTests" "/p:RuntimeFlavor=$__RuntimeFlavor" "/p:MonoLlvmPath=$__MonoBinDir" + build_MSBuild_projects "Tests_MonoAot" "$__RepoRootDir/src/tests/run.proj" "Mono AOT compile tests" "/t:MonoAotCompileTests" "/p:RuntimeFlavor=$__RuntimeFlavor" "/p:MonoBinDir=$__MonoBinDir" } generate_layout() @@ -628,6 +627,7 @@ __IntermediatesDir="$__RootBinDir/obj/coreclr/$__OSPlatformConfig" __TestIntermediatesDir="$__RootBinDir/tests/coreclr/obj/$__OSPlatformConfig" __CrossComponentBinDir="$__BinDir" __CrossCompIntermediatesDir="$__IntermediatesDir/crossgen" +__MonoBinDir="$__RootBinDir/bin/mono/$__OSPlatformConfig" __CrossArch="$__HostArch" if [[ "$__CrossBuild" == 1 ]]; then diff --git a/src/tests/issues.targets b/src/tests/issues.targets index 91cc91a..65aaf3e 100644 --- a/src/tests/issues.targets +++ b/src/tests/issues.targets @@ -2647,6 +2647,19 @@ + + Doesn't compile with LLVM AOT. + + + Doesn't compile with LLVM AOT. + + + Doesn't compile with LLVM AOT. + + + Doesn't compile with LLVM AOT. + + needs triage diff --git a/src/tests/run.proj b/src/tests/run.proj index a321d25..65055f1 100644 --- a/src/tests/run.proj +++ b/src/tests/run.proj @@ -357,19 +357,30 @@ namespace $([System.String]::Copy($(Category)).Replace(".","_").Replace("\",""). - - $(CORE_ROOT)\corerun - $(CORE_ROOT)\corerun.exe + + + $(CORE_ROOT)/corerun + $(CORE_ROOT)\corerun.exe + $(MonoBinDir) + + $(MonoBinDir)/cross/mono-aot-cross + $(MonoBinDir)/cross + + - + + + - @(AotEnvVar) + @(MonoAotOption->'%(Identity)', ',') + $(CORE_ROOT) + - _CorerunExecutable=$(CorerunExecutable);_TestDll=%(TestDlls.Identity);AotEnvVars=@(AotEnvVar) + _AotCompiler=$(AotCompiler);_TestDll=%(TestDlls.Identity);_MonoPath=$(MonoPath);_MonoAotOptions=$(MonoAotOptions) - + @@ -407,11 +418,6 @@ namespace $([System.String]::Copy($(Category)).Replace(".","_").Replace("\",""). - -