diff --git a/0004-Offload-Add-support-for-riscv64-to-host-plugin.patch b/0004-Offload-Add-support-for-riscv64-to-host-plugin.patch new file mode 100644 index 0000000000000000000000000000000000000000..e008d57b932a6f08d6347931cebb2888777e1479 --- /dev/null +++ b/0004-Offload-Add-support-for-riscv64-to-host-plugin.patch @@ -0,0 +1,94 @@ +From 8f24fd1576190808efd1f7ea639ae895207644f3 Mon Sep 17 00:00:00 2001 +From: Aurelien Jarno +Date: Mon, 11 Nov 2024 11:12:54 +0100 +Subject: [PATCH] [Offload] Add support for riscv64 to host plugin + +This adds support for the riscv64 architecture to the offload host +plugin. The check to define FFI_DEFAULT_ABI is intentionally not guarded +by __riscv_xlen as the value is the same for riscv32 and riscv64 +(support for OpenMP on riscv32 is still under review). + +Tested-by: jchzhou +--- + offload/CMakeLists.txt | 2 ++ + offload/plugins-nextgen/common/src/Utils/ELF.cpp | 2 ++ + offload/plugins-nextgen/host/CMakeLists.txt | 6 +++++- + offload/plugins-nextgen/host/dynamic_ffi/ffi.h | 3 ++- + offload/plugins-nextgen/host/src/rtl.cpp | 2 ++ + 5 files changed, 13 insertions(+), 2 deletions(-) + +diff --git a/offload/CMakeLists.txt b/offload/CMakeLists.txt +index 959d6260b..ccb61a698 100644 +--- a/offload/CMakeLists.txt ++++ b/offload/CMakeLists.txt +@@ -200,6 +200,8 @@ set (LIBOMPTARGET_ALL_TARGETS "${LIBOMPTARGET_ALL_TARGETS} nvptx64-nvidia-cuda-L + set (LIBOMPTARGET_ALL_TARGETS "${LIBOMPTARGET_ALL_TARGETS} nvptx64-nvidia-cuda-JIT-LTO") + set (LIBOMPTARGET_ALL_TARGETS "${LIBOMPTARGET_ALL_TARGETS} s390x-ibm-linux-gnu") + set (LIBOMPTARGET_ALL_TARGETS "${LIBOMPTARGET_ALL_TARGETS} s390x-ibm-linux-gnu-LTO") ++set (LIBOMPTARGET_ALL_TARGETS "${LIBOMPTARGET_ALL_TARGETS} riscv64-unknown-linux-gnu") ++set (LIBOMPTARGET_ALL_TARGETS "${LIBOMPTARGET_ALL_TARGETS} riscv64-unknown-linux-gnu-LTO") + + # Once the plugins for the different targets are validated, they will be added to + # the list of supported targets in the current system. +diff --git a/offload/plugins-nextgen/common/src/Utils/ELF.cpp b/offload/plugins-nextgen/common/src/Utils/ELF.cpp +index 90d6950b8..88642fd5b 100644 +--- a/offload/plugins-nextgen/common/src/Utils/ELF.cpp ++++ b/offload/plugins-nextgen/common/src/Utils/ELF.cpp +@@ -45,6 +45,8 @@ uint16_t utils::elf::getTargetMachine() { + return EM_AARCH64; + #elif defined(__powerpc64__) + return EM_PPC64; ++#elif defined(__riscv) ++ return EM_RISCV; + #else + #warning "Unknown ELF compilation target architecture" + return EM_NONE; +diff --git a/offload/plugins-nextgen/host/CMakeLists.txt b/offload/plugins-nextgen/host/CMakeLists.txt +index 817d128f9..286bc51cc 100644 +--- a/offload/plugins-nextgen/host/CMakeLists.txt ++++ b/offload/plugins-nextgen/host/CMakeLists.txt +@@ -1,4 +1,4 @@ +-set(supported_targets x86_64 aarch64 ppc64 ppc64le s390x) ++set(supported_targets x86_64 aarch64 ppc64 ppc64le riscv64 s390x) + if(NOT ${CMAKE_SYSTEM_PROCESSOR} IN_LIST supported_targets) + message(STATUS "Not building ${machine} NextGen offloading plugin") + return() +@@ -59,4 +59,8 @@ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "s390x$") + list(APPEND LIBOMPTARGET_SYSTEM_TARGETS + "s390x-ibm-linux-gnu" "s390x-ibm-linux-gnu-LTO") + set(LIBOMPTARGET_SYSTEM_TARGETS "${LIBOMPTARGET_SYSTEM_TARGETS}" PARENT_SCOPE) ++elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "riscv64$") ++ list(APPEND LIBOMPTARGET_SYSTEM_TARGETS ++ "riscv64-unknown-linux-gnu" "riscv64-unknown-linux-gnu-LTO") ++ set(LIBOMPTARGET_SYSTEM_TARGETS "${LIBOMPTARGET_SYSTEM_TARGETS}" PARENT_SCOPE) + endif() +diff --git a/offload/plugins-nextgen/host/dynamic_ffi/ffi.h b/offload/plugins-nextgen/host/dynamic_ffi/ffi.h +index 0ae025805..8b4e0286d 100644 +--- a/offload/plugins-nextgen/host/dynamic_ffi/ffi.h ++++ b/offload/plugins-nextgen/host/dynamic_ffi/ffi.h +@@ -43,7 +43,8 @@ typedef enum { + typedef enum ffi_abi { + #if (defined(_M_X64) || defined(__x86_64__)) + FFI_DEFAULT_ABI = 2, // FFI_UNIX64. +-#elif defined(__aarch64__) || defined(__arm64__) || defined(_M_ARM64) ++#elif defined(__aarch64__) || defined(__arm64__) || defined(_M_ARM64) || \ ++ defined(__riscv) + FFI_DEFAULT_ABI = 1, // FFI_SYSV. + #elif defined(__powerpc64__) + FFI_DEFAULT_ABI = 8, // FFI_LINUX. +diff --git a/offload/plugins-nextgen/host/src/rtl.cpp b/offload/plugins-nextgen/host/src/rtl.cpp +index fe296b77c..6f2e3d860 100644 +--- a/offload/plugins-nextgen/host/src/rtl.cpp ++++ b/offload/plugins-nextgen/host/src/rtl.cpp +@@ -440,6 +440,8 @@ struct GenELF64PluginTy final : public GenericPluginTy { + #else + return llvm::Triple::ppc64; + #endif ++#elif defined(__riscv) && (__riscv_xlen == 64) ++ return llvm::Triple::riscv64; + #else + return llvm::Triple::UnknownArch; + #endif +-- +2.48.1 + diff --git a/llvm-toolset-19.spec b/llvm-toolset-19.spec index 5282e0b759901a47c4cc6b3202281f51984d1726..e4219157f090267da35db166d549755349b89814 100644 --- a/llvm-toolset-19.spec +++ b/llvm-toolset-19.spec @@ -149,7 +149,7 @@ #region main package Name: llvm-toolset-%{maj_ver} Version: %{maj_ver}.%{min_ver}.%{patch_ver} -Release: 2 +Release: 3 Summary: The Low Level Virtual Machine License: NCSA @@ -166,6 +166,9 @@ Source2: CMakeLists.txt Patch0001: 0001-PATCH-clang-Don-t-install-static-libraries.patch Patch0002: 0002-Add-triples-for-X86_64-AArch64-Riscv64-openEuler-gcc.patch Patch0003: 0003-Always-build-shared-libs-for-LLD.patch +# backport riscv64 support for offload host plugin from llvm 20.1 +# https://github.com/llvm/llvm-project/pull/115773 +Patch0004: 0004-Offload-Add-support-for-riscv64-to-host-plugin.patch BuildRequires: gcc BuildRequires: gcc-c++ @@ -2496,7 +2499,8 @@ fi %{install_libdir}/clang/%{maj_ver}/lib/%{compiler_rt_triple}/clang_rt.crtend.o %endif -%ifnarch %{ix86} s390x +%ifnarch %{ix86} s390x riscv64 +# currently unsupported on above arches %{install_libdir}/clang/%{maj_ver}/lib/%{compiler_rt_triple}/liborc_rt.a %endif @@ -2514,7 +2518,7 @@ fi %{install_libdir}/libomp.so %{install_libdir}/libompd.so %{install_libdir}/libarcher.so -%ifnarch %{ix86} %{arm} riscv64 loongarch64 +%ifnarch %{ix86} %{arm} loongarch64 # libomptarget is not supported on 32-bit systems. # s390x does not support the offloading plugins. %if %{maj_ver} >= 20 @@ -2784,8 +2788,12 @@ fi #endregion files %changelog +* Fri Feb 28 2025 jchzhou - 19.1.7-3 +- Backport riscv64 support for offload host plugin +- Exclude packaging non-supported liborc_rt.a for riscv64 + * Tue Feb 25 2025 liyunfei - 19.1.7-2 - Bugfix for package name * Mon Feb 10 2025 liyunfei - 19.1.7-1 -- Package init \ No newline at end of file +- Package init