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 <lockalsash@gmail.com>
This commit is contained in:
Sv. Lockal
2026-04-30 05:26:00 +08:00
parent 683944aa59
commit b1ed3ba86c
3 changed files with 63 additions and 16 deletions

View File

@@ -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" <<EOF
@@ -58,8 +68,8 @@ EOF
# Append the actual test code from stdin
cat >> "$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

View File

@@ -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
}

View File

@@ -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
}