aircrack-ng / rtl8812au

RTL8812AU/21AU and RTL8814AU driver with monitor mode and frame injection
GNU General Public License v2.0
3.57k stars 783 forks source link

[PATCH] Build for clang compiled kernels fails: `clang: error: unsupported option '-mhard-float' for target 'x86_64-linux-gnu'` and `error: error: unknown warning option '-Wno-stringop-overread'`. #1205

Open dreirund opened 1 week ago

dreirund commented 1 week ago

Patch below.


It seems that this does not build for Linux kernels compiled with clang.

It fails with
clang: error: unsupported option '-mhard-float' for target 'x86_64-linux-gnu'
— seems that the Makefile script hard-sets an option that clang does not understand.

dkms build -m rtl88xxau/r1298.b44d288 -k 6.11.3-vanilla-customconfig-clang:

Sign command: /usr/lib/modules/6.11.3-vanilla-customconfig-clang/build/scripts/sign-file
Signing key: /usr/lib/modules/6.11.3-vanilla-customconfig-clang/build/certs/signing_key.pem
Public certificate (MOK): /usr/lib/modules/6.11.3-vanilla-customconfig-clang/build/certs/signing_key.x509

Cleaning build area... done.
Building module(s)...(bad exit status: 2)
Failed command:
'make' -j16 KVER=6.11.3-vanilla-customconfig-clang KSRC=/lib/modules/6.11.3-vanilla-customconfig-clang/build CC=clang LD=ld.lld
Error! Bad return status for module build on kernel: 6.11.3-vanilla-customconfig-clang (x86_64)
Consult /var/lib/dkms/rtl88xxau/r1298.b44d288/build/make.log for more information.

/var/lib/dkms/rtl88xxau/r1298.b44d288/build/make.log contains:

DKMS make.log for rtl88xxau-r1298.b44d288 for kernel 6.11.3-vanilla-customconfig-clang (x86_64)
Thu Nov 14 01:25:23 PM CET 2024
make ARCH=x86_64 CROSS_COMPILE= -C /lib/modules/6.11.3-vanilla-customconfig-clang/build M=/var/lib/dkms/rtl88xxau/r1298.b44d288/build  modules
make[1]: Entering directory '/usr/lib/modules/6.11.3-vanilla-customconfig-clang/build'
  CC [M]  /var/lib/dkms/rtl88xxau/r1298.b44d288/build/core/rtw_cmd.o
  CC [M]  /var/lib/dkms/rtl88xxau/r1298.b44d288/build/core/rtw_security.o
  CC [M]  /var/lib/dkms/rtl88xxau/r1298.b44d288/build/core/rtw_debug.o
  CC [M]  /var/lib/dkms/rtl88xxau/r1298.b44d288/build/core/rtw_io.o
  CC [M]  /var/lib/dkms/rtl88xxau/r1298.b44d288/build/core/rtw_ioctl_query.o
  CC [M]  /var/lib/dkms/rtl88xxau/r1298.b44d288/build/core/rtw_ioctl_set.o
  CC [M]  /var/lib/dkms/rtl88xxau/r1298.b44d288/build/core/rtw_ieee80211.o
  CC [M]  /var/lib/dkms/rtl88xxau/r1298.b44d288/build/core/rtw_mlme.o
  CC [M]  /var/lib/dkms/rtl88xxau/r1298.b44d288/build/core/rtw_mlme_ext.o
clangclangclangclang: : : : error: error: error: error: unsupported option '-mhard-float' for target 'x86_64-linux-gnu'unsupported option '-mhard-float' for target 'x86_64-linux-gnu'unsupported option '-mhard-float' for target 'x86_64-linux-gnu'unsupported option '-mhard-float' for target 'x86_64-linux-gnu'

clang: error: unsupported option '-mhard-float' for target 'x86_64-linux-gnu'
clang: error: unsupported option '-mhard-float' for target 'x86_64-linux-gnu'
make[3]: *** [scripts/Makefile.build:244: /var/lib/dkms/rtl88xxau/r1298.b44d288/build/core/rtw_cmd.o] Error 1
make[3]: *** Waiting for unfinished jobs....
make[3]: *** [scripts/Makefile.build:244: /var/lib/dkms/rtl88xxau/r1298.b44d288/build/core/rtw_security.o] Error 1
make[3]: *** [scripts/Makefile.build:244: /var/lib/dkms/rtl88xxau/r1298.b44d288/build/core/rtw_debug.o] Error 1
make[3]: *** [scripts/Makefile.build:244: /var/lib/dkms/rtl88xxau/r1298.b44d288/build/core/rtw_io.o] Error 1
make[3]: *** [scripts/Makefile.build:244: /var/lib/dkms/rtl88xxau/r1298.b44d288/build/core/rtw_ioctl_query.o] Error 1
  CC [M]  /var/lib/dkms/rtl88xxau/r1298.b44d288/build/core/rtw_mi.o
make[3]: *** [scripts/Makefile.build:244: /var/lib/dkms/rtl88xxau/r1298.b44d288/build/core/rtw_ioctl_set.o] Error 1
clang: error: unsupported option '-mhard-float' for target 'x86_64-linux-gnu'
make[3]: *** [scripts/Makefile.build:244: /var/lib/dkms/rtl88xxau/r1298.b44d288/build/core/rtw_ieee80211.o] Error 1
clang: error: unsupported option '-mhard-float' for target 'x86_64-linux-gnu'
clang: error: unsupported option '-mhard-float' for target 'x86_64-linux-gnu'
make[3]: *** [scripts/Makefile.build:244: /var/lib/dkms/rtl88xxau/r1298.b44d288/build/core/rtw_mlme.o] Error 1
clang: error: unsupported option '-mhard-float' for target 'x86_64-linux-gnu'
make[3]: *** [scripts/Makefile.build:244: /var/lib/dkms/rtl88xxau/r1298.b44d288/build/core/rtw_mlme_ext.o] Error 1
make[3]: *** [scripts/Makefile.build:244: /var/lib/dkms/rtl88xxau/r1298.b44d288/build/core/rtw_mi.o] Error 1
make[2]: *** [/usr/lib/modules/6.11.3-vanilla-customconfig-clang/build/Makefile:1926: /var/lib/dkms/rtl88xxau/r1298.b44d288/build] Error 2
make[1]: *** [Makefile:224: __sub-make] Error 2
make[1]: Leaving directory '/usr/lib/modules/6.11.3-vanilla-customconfig-clang/build'
make: *** [Makefile:1730: modules] Error 2

In Makefile I find

ifeq ($(ARCH), i386)
EXTRA_CFLAGS += -mhard-float
EXTRA_CFLAGS += -DMARK_KERNEL_PFU
else ifeq ($(ARCH), x86_64)
EXTRA_CFLAGS += -mhard-float
EXTRA_CFLAGS += -DMARK_KERNEL_PFU
endif

If this is "fixed", clang complains about -Wno-stringop-overread:

[...]
  CC [M]  /var/lib/dkms/rtl88xxau/r1298.b44d288/build/core/rtw_mlme.o
error: error: unknown warning option '-Wno-stringop-overread' [-Werror,-Wunknown-warning-option]unknown warning option '-Wno-stringop-overread' [-Werror,-Wunknown-warning-option]

error: unknown warning option '-Wno-stringop-overread' [-Werror,-Wunknown-warning-option]
  CC [M]  /var/lib/dkms/rtl88xxau/r1298.b44d288/build/core/rtw_mlme_ext.o
error: error: unknown warning option '-Wno-stringop-overread' [-Werror,-Wunknown-warning-option]unknown warning option '-Wno-stringop-overread' [-Werror,-Wunknown-warning-option]
[...]

In Makefile, I find regarding this:

EXTRA_CFLAGS += -Wno-stringop-overread

Possible patch:

↗ Here is a patch that fixes those two issues (and I recommend setting the $CFLAGS completely from what was used during kernel build or the build environment, also not overriding optimisation settings):

diff -rU1 rtl88xxau.orig/Makefile rtl88xxau/Makefile
--- rtl88xxau.orig/Makefile 2024-11-14 13:30:02.136693553 +0100
+++ rtl88xxau/Makefile  2024-11-14 13:56:07.723375267 +0100
@@ -14,3 +14,6 @@
 #EXTRA_CFLAGS += -Wno-error=incompatible-pointer-types
+# 'clang' does not understand '-Wno-stringop-overread', see https://github.com/aircrack-ng/rtl8812au/issues/1205. So only add this if 'gcc' is the compiler.
+ifeq ($(CC), gcc)
 EXTRA_CFLAGS += -Wno-stringop-overread
+endif
 #EXTRA_CFLAGS += -Wno-pointer-bool-conversion
@@ -1623,6 +1626,12 @@
 ifeq ($(ARCH), i386)
+# 'clang' does not understand '-mhard-float', see https://github.com/aircrack-ng/rtl8812au/issues/1205. So only add this if 'gcc' is the compiler.
+ifeq ($(CC), gcc)
 EXTRA_CFLAGS += -mhard-float
+endif
 EXTRA_CFLAGS += -DMARK_KERNEL_PFU
 else ifeq ($(ARCH), x86_64)
+# 'clang' does not understand '-mhard-float', see https://github.com/aircrack-ng/rtl8812au/issues/1205. So only add this if 'gcc' is the compiler.
+ifeq ($(CC), gcc)
 EXTRA_CFLAGS += -mhard-float
+endif
 EXTRA_CFLAGS += -DMARK_KERNEL_PFU

I don't know if this patch is "legit", in the sense that CC=gcc is set when compiling for a GCC compiled kernel.


For the otherwise same kernel, but compiled with GCC, it works:

dkms build -m rtl88xxau/r1298.b44d288 -k 6.11.3-vanilla-customconfig-gcc:


Sign command: /usr/lib/modules/6.11.3-vanilla-customconfig-gcc/build/scripts/sign-file
Signing key: /usr/lib/modules/6.11.3-vanilla-customconfig-gcc/build/certs/signing_key.pem
Public certificate (MOK): /usr/lib/modules/6.11.3-vanilla-customconfig-gcc/build/certs/signing_key.x509

Cleaning build area... done.
Building module(s)........ done.
Signing module /var/lib/dkms/rtl88xxau/r1298.b44d288/build/88XXau.ko
Cleaning build area... done.

Regards!