diff --git a/build-coredistools.sh b/build-coredistools.sh index 9dca3af..a60600a 100755 --- a/build-coredistools.sh +++ b/build-coredistools.sh @@ -17,14 +17,13 @@ CMakeOSXArchitectures= LLVMTargetsToBuild="AArch64;ARM;X86" # Figure out which `strip` to use. Prefer `llvm-strip` if it is available. -# `llvm-strip` is available in CBL-Mariner container; `strip` is available on macOS. -StripTool=$(command -v llvm-strip) +# `llvm-strip` is available in CBL-Mariner container, +# `llvm-strip-` is available on standard cross build Ubuntu container, +# `strip` is available on macOS. +StripTool=$(command -v llvm-strip{,-{20..15}} strip | head -n 1) if [ -z "$StripTool" ]; then - StripTool=$(command -v strip) - if [ -z "$StripTool" ]; then - echo "Strip tool not found" - exit 1 - fi + echo "Strip tool not found" + exit 1 fi TblGenTool=$(command -v llvm-tblgen) @@ -33,13 +32,14 @@ if [ -z "$TblGenTool" ]; then exit 1 fi -C_COMPILER=$(command -v clang) +# Take first match from: clang clang-20 clang-19 .. clang-15 +C_COMPILER=$(command -v clang{,-{20..15}} | head -n 1) if [ -z "$C_COMPILER" ]; then echo "C compiler not found" # Keep going in case cmake can find one? fi -CXX_COMPILER=$(command -v clang++) +CXX_COMPILER=$(command -v clang++{,-{20..15}} | head -n 1) if [ -z "$CXX_COMPILER" ]; then echo "C++ compiler not found" # Keep going in case cmake can find one? @@ -79,6 +79,13 @@ case "$TargetOSArchitecture" in LLVMTargetsToBuild="LoongArch" ;; + linux-riscv64) + CMakeCrossCompiling=ON + LLVMHostTriple=riscv64-linux-gnu + LLVMTargetsToBuild="RISCV" + EnsureCrossRootfsDirectoryExists + ;; + osx-arm64) CMakeCrossCompiling=ON CMakeOSXArchitectures=arm64 diff --git a/build-tblgen.sh b/build-tblgen.sh index c616649..7a2c313 100755 --- a/build-tblgen.sh +++ b/build-tblgen.sh @@ -70,14 +70,18 @@ fi pushd "$BinariesDirectory" +# Take first match from: clang clang-20 clang-19 .. clang-15 +C_COMPILER=$(command -v clang{,-{20..15}} | head -n 1) +CXX_COMPILER=$(command -v clang++{,-{20..15}} | head -n 1) + if [ -z "$CrossRootfsDirectory" ]; then BUILD_FLAGS="" cmake \ -G "Unix Makefiles" \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_CROSSCOMPILING=$CMakeCrossCompiling \ - -DCMAKE_C_COMPILER=$(command -v clang) \ - -DCMAKE_CXX_COMPILER=$(command -v clang++) \ + -DCMAKE_C_COMPILER=$C_COMPILER \ + -DCMAKE_CXX_COMPILER=$CXX_COMPILER \ -DCMAKE_C_FLAGS="${BUILD_FLAGS}" \ -DCMAKE_CXX_FLAGS="${BUILD_FLAGS}" \ -DCMAKE_INSTALL_PREFIX=$RootDirectory \ @@ -92,8 +96,8 @@ elif [ $CrossBuildUsingMariner -eq 1 ]; then -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_INSTALL_PREFIX=$RootDirectory \ -DCMAKE_CROSSCOMPILING=$CMakeCrossCompiling \ - -DCMAKE_C_COMPILER=$(command -v clang) \ - -DCMAKE_CXX_COMPILER=$(command -v clang++) \ + -DCMAKE_C_COMPILER=$C_COMPILER \ + -DCMAKE_CXX_COMPILER=$CXX_COMPILER \ -DCMAKE_C_FLAGS="${BUILD_FLAGS}" \ -DCMAKE_CXX_FLAGS="${BUILD_FLAGS}" \ -DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=lld" \ @@ -109,8 +113,8 @@ else -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_INSTALL_PREFIX=$RootDirectory \ -DCMAKE_CROSSCOMPILING=$CMakeCrossCompiling \ - -DCMAKE_C_COMPILER=$(command -v clang) \ - -DCMAKE_CXX_COMPILER=$(command -v clang++) \ + -DCMAKE_C_COMPILER=$C_COMPILER \ + -DCMAKE_CXX_COMPILER=$CXX_COMPILER \ -DCMAKE_C_FLAGS="${BUILD_FLAGS}" \ -DCMAKE_CXX_FLAGS="${BUILD_FLAGS}" \ -DCMAKE_INCLUDE_PATH=$CrossRootfsDirectory/usr/include \ diff --git a/doc/building-coredistools.md b/doc/building-coredistools.md index 9651e5f..b1a0c08 100644 --- a/doc/building-coredistools.md +++ b/doc/building-coredistools.md @@ -105,3 +105,17 @@ sudo tdnf install -y ncurses-compat export PATH=$(pwd)/bin:$PATH ./build-coredistools.sh linux-arm /crossrootfs/arm ``` + +8. Build `libcoredistools.so` for Linux riscv64 under Docker: +There is no CBL Mariner container for RISC-V so use the standard Ubuntu cross build container used for e.g. dotnet/runtime. +``` +docker run -it --rm --entrypoint /bin/bash -v ~/git/jitutils:/opt/code -w /opt/code mcr.microsoft.com/dotnet-buildtools/prereqs:ubuntu-22.04-cross-riscv64 +apt install libtinfo5 + +# If you haven't built llvm-tblgen in step 5, you can do so in the same docker (pass "/" as crossrootfs). +./build-tblgen.sh linux-x64 / + +# Now, the main course +export PATH=$(pwd)/bin:$PATH +./build-coredistools.sh linux-riscv64 /crossrootfs/riscv64 +``` \ No newline at end of file diff --git a/src/coredistools/coredistools.cpp b/src/coredistools/coredistools.cpp index 0ff8232..f4b0b96 100644 --- a/src/coredistools/coredistools.cpp +++ b/src/coredistools/coredistools.cpp @@ -286,6 +286,9 @@ bool CorDisasm::setTarget() { case Triple::loongarch64: TheTargetArch = Target_LoongArch64; break; + case Triple::riscv64: + TheTargetArch = Target_RiscV64; + break; default: Print->Error("Unsupported Architecture: %s\n", Triple::getArchTypeName(TheTriple->getArch())); @@ -309,6 +312,9 @@ bool CorDisasm::setTarget() { case Target_LoongArch64: TheTriple->setArch(Triple::loongarch64); break; + case Target_RiscV64: + TheTriple->setArch(Triple::riscv64); + break; default: Print->Error("Unsupported Architecture: %s\n", Triple::getArchTypeName(TheTriple->getArch())); diff --git a/src/coredistools/coredistools.h b/src/coredistools/coredistools.h index f26693f..5bee8f2 100644 --- a/src/coredistools/coredistools.h +++ b/src/coredistools/coredistools.h @@ -42,7 +42,8 @@ enum TargetArch { Target_X64, Target_Thumb, Target_Arm64, - Target_LoongArch64 + Target_LoongArch64, + Target_RiscV64, }; struct CorDisasm;