From b1ed3ba86cec6308d9ad28797940abd8d38b3a57 Mon Sep 17 00:00:00 2001 From: "Sv. Lockal" Date: Thu, 30 Apr 2026 05:26:00 +0800 Subject: [PATCH] dev-libs/xdna-driver: fix compilation with Clang Multiple issues fixed: - module was compiled against `uname -r` kernel, not eselect-ed one - released version requires a patch to compile with Clang - previous attempt to forward CC to fix Clang compilation was incorrect from every standpoint; e. g. it there is KERNEL_CC for that, etc. Removed it, as upstream now has proper support (backported via patch). Closes: https://bugs.gentoo.org/973282 Signed-off-by: Sv. Lockal --- .../xdna-driver-2.21.75-llvm-support.patch | 32 +++++++++++++++++++ .../xdna-driver/xdna-driver-2.21.75-r1.ebuild | 24 ++++++++++---- .../xdna-driver/xdna-driver-999999.ebuild | 23 +++++++------ 3 files changed, 63 insertions(+), 16 deletions(-) create mode 100644 dev-libs/xdna-driver/files/xdna-driver-2.21.75-llvm-support.patch diff --git a/dev-libs/xdna-driver/files/xdna-driver-2.21.75-llvm-support.patch b/dev-libs/xdna-driver/files/xdna-driver-2.21.75-llvm-support.patch new file mode 100644 index 0000000000..4e7077227b --- /dev/null +++ b/dev-libs/xdna-driver/files/xdna-driver-2.21.75-llvm-support.patch @@ -0,0 +1,32 @@ +Fix for configuration generator to support Clang-built kernels. +Partially backports https://github.com/amd/xdna-driver/commit/539d1ba5dc3a46338af694ec07b06dfe4c052dc5 +--- a/src/driver/tools/configure_kernel.sh ++++ b/src/driver/tools/configure_kernel.sh +@@ -42,6 +42,16 @@ try_compile() { + tmpdir=$(mktemp -d /tmp/conftest-XXXXXX) + conftest_c="$tmpdir/conftest.c" + conftest_mk="$tmpdir/Makefile" ++ USE_LLVM="" ++ if [ -e /proc/config.gz ]; then ++ if zgrep -q "CONFIG_CC_IS_CLANG=y" /proc/config.gz 2>/dev/null; then ++ USE_LLVM="LLVM=1" ++ fi ++ elif [ -e "/boot/config-$KERNEL_VER" ]; then ++ if grep -q "CONFIG_CC_IS_CLANG=y" "/boot/config-$KERNEL_VER" 2>/dev/null; then ++ USE_LLVM="LLVM=1" ++ fi ++ fi + + # Minimal Kbuild for an external module + cat > "$conftest_mk" <> "$conftest_c" + +- # Now build it like your real driver +- if make -s -C "$KERNEL_SRC" M="$tmpdir" modules >/dev/null 2>&1; then ++ # Now build it like your real driver ($USE_LLVM intentionally unquoted to avoid empty arg) ++ if make -s -C "$KERNEL_SRC" M="$tmpdir" modules $USE_LLVM >/dev/null 2>&1; then + echo "#define $macro 1" >> "$OUT" + echo ">>> + $macro: yes" >&2 + else diff --git a/dev-libs/xdna-driver/xdna-driver-2.21.75-r1.ebuild b/dev-libs/xdna-driver/xdna-driver-2.21.75-r1.ebuild index 3f6342e7d5..3209dec18b 100644 --- a/dev-libs/xdna-driver/xdna-driver-2.21.75-r1.ebuild +++ b/dev-libs/xdna-driver/xdna-driver-2.21.75-r1.ebuild @@ -3,7 +3,7 @@ EAPI=8 -inherit linux-mod-r1 multiprocessing toolchain-funcs +inherit linux-mod-r1 multiprocessing optfeature toolchain-funcs DESCRIPTION="AMD XDNA Driver" HOMEPAGE="https://github.com/amd/xdna-driver" @@ -117,18 +117,19 @@ src_unpack() { src_prepare() { sed -e "s/-Werror//" -i Kbuild || die - # Forward clang compiler, otherwise fails when kernel is compiled with clang cflags - # shellcheck disable=SC2016 - sed -e 's/make -s /make -s CC="${CC}" /' \ - -i "${WORKDIR}/${P}"/src/driver/tools/configure_kernel.sh || die + pushd "${WORKDIR}/${P}" || die + eapply "${FILESDIR}/${PN}-2.21.75-llvm-support.patch" + popd || die default } src_configure() { cd "${WORKDIR}/${P}/src" || die - KERNEL_SRC="${KERNEL_DIR}" ARCH=$(tc-arch-kernel) \ - ./driver/tools/configure_kernel.sh || die + KERNEL_SRC="${KERNEL_DIR}" \ + KERNEL_VER="${KV_FULL}" \ + ARCH="$(tc-arch-kernel)" \ + CC="${KERNEL_CC}" ./driver/tools/configure_kernel.sh || die } src_compile() { @@ -171,3 +172,12 @@ src_install() { linux-mod-r1_src_install } + +pkg_postinst() { + linux-mod-r1_pkg_postinst + + einfo "To reload kernel module between out-of-tree builds run:" + einfo "modprobe -r amdxdna && modprobe amdxdna" + einfo "However, switching between in-tree and out-of-tree builds requires a reboot." + optfeature "for runtime and xrt-smi tool" dev-libs/xrt-xdna +} diff --git a/dev-libs/xdna-driver/xdna-driver-999999.ebuild b/dev-libs/xdna-driver/xdna-driver-999999.ebuild index 5a122fe7e3..1e9e49bdb1 100644 --- a/dev-libs/xdna-driver/xdna-driver-999999.ebuild +++ b/dev-libs/xdna-driver/xdna-driver-999999.ebuild @@ -3,7 +3,7 @@ EAPI=8 -inherit linux-mod-r1 multiprocessing toolchain-funcs +inherit linux-mod-r1 multiprocessing optfeature toolchain-funcs DESCRIPTION="AMD XDNA Driver" HOMEPAGE="https://github.com/amd/xdna-driver" @@ -119,19 +119,15 @@ src_unpack() { src_prepare() { sed -e "s/-Werror//" -i Kbuild || die - - # Forward clang compiler, otherwise fails when kernel is compiled with clang cflags - # shellcheck disable=SC2016 - sed -e 's/make -s /make -s CC="${CC}" /' \ - -i "${WORKDIR}/${P}"/src/driver/tools/configure_kernel.sh || die - default } src_configure() { cd "${WORKDIR}/${P}/src" || die - KERNEL_SRC="${KERNEL_DIR}" ARCH=$(tc-arch-kernel) \ - ./driver/tools/configure_kernel.sh || die + KERNEL_SRC="${KERNEL_DIR}" \ + KERNEL_VER="${KV_FULL}" \ + ARCH="$(tc-arch-kernel)" \ + CC="${KERNEL_CC}" ./driver/tools/configure_kernel.sh || die } src_compile() { @@ -174,3 +170,12 @@ src_install() { linux-mod-r1_src_install } + +pkg_postinst() { + linux-mod-r1_pkg_postinst + + einfo "To reload kernel module between out-of-tree builds run:" + einfo "modprobe -r amdxdna && modprobe amdxdna" + einfo "However, switching between in-tree and out-of-tree builds requires a reboot." + optfeature "for runtime and xrt-smi tool" dev-libs/xrt-xdna +}