Skip to contentSkip to conversation

linux: disable attribute alias with gcc >= 8.1

RFC PATCH New Romain Naour 2 participants 3 messages May 31, 2018 – Jun 2, 2018

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 linux: disable attribute alias with gcc >= 8.1

gcc-8 started warning about function aliases that have a non-matching prototype. This seems rather useful in general, but it causes tons of warnings in the Linux kernel, where we rely on abusing those aliases for system call entry points, in order to sanitze the arguments passed from user space in registers.

See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82435

Add a new conditional patch that disable the attribute-alias warning introduced by gcc-8 by adding -Wno-attribute-alias to KBUILD_CFLAGS.

Cc Thomas Petazzoni <[email protected]>

---

Fixes most of build errors reported by toolchains-builder on Gitlab.
https://gitlab.com/free-electrons/toolchains-builder/pipelines/22921464

---
 ...e-attribute-alias-for-gcc-8.1.patch.conditional | 33 ++++++++++++++++++++++
 linux/linux.mk                                     | 14 +++++++++
 2 files changed, 47 insertions(+)
 create mode 100644 linux/0002-Makefile-disable-attribute-alias-for-gcc-8.1.patch.conditional
linux/0002-Makefile-disable-attribute-alias-for-gcc-8.1.patch.conditional new file +33 -0
new file mode 100644
index 0000000000..23ce8a12b5
@@ -0,0 +1,33 @@
+From f238848ce07b9b033847278ccafabc817634e650 Mon Sep 17 00:00:00 2001
+From: Romain Naour <[email protected]>
+Date: Thu, 31 May 2018 20:56:37 +0200
+Subject: [PATCH] Makefile: disable attribute-alias for gcc >= 8.1
+
+gcc-8 started warning about function aliases that have a non-matching
+prototype. This seems rather useful in general, but it causes tons of
+warnings in the Linux kernel, where we rely on abusing those aliases
+for system call entry points, in order to sanitze the arguments passed
+from user space in registers.
+
+See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82435
+
+Signed-off-by: Romain Naour <[email protected]>
+---
+ Makefile | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/Makefile b/Makefile
+index 56ba070..b54e19a6 100644
+--- a/Makefile
++++ b/Makefile
+@@ -641,6 +641,7 @@ KBUILD_CFLAGS	+= $(call cc-disable-warning,frame-address,)
+ KBUILD_CFLAGS	+= $(call cc-disable-warning, format-truncation)
+ KBUILD_CFLAGS	+= $(call cc-disable-warning, format-overflow)
+ KBUILD_CFLAGS	+= $(call cc-disable-warning, int-in-bool-context)
++KBUILD_CFLAGS	+= $(call cc-disable-warning, attribute-alias)
+ 
+ ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE
+ KBUILD_CFLAGS	+= $(call cc-option,-Oz,-Os)
+-- 
+2.7.4
+
linux/linux.mk +14 -0
index b6b91391b6..3af72f819e 100644
@@ -226,6 +226,20 @@ define LINUX_TRY_PATCH_TIMECONST
 endef
 LINUX_POST_PATCH_HOOKS += LINUX_TRY_PATCH_TIMECONST
 
+# gcc-8 started warning about function aliases that have a non-matching prototype.
+# This seems rather useful in general, but it causes tons of warnings in the Linux kernel,
+# where we rely on abusing those aliases for system call entry points, in order to sanitze
+# the arguments passed from user space in registers.
+# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82435
+ifeq ($(BR2_TOOLCHAIN_GCC_AT_LEAST_8),y)
+define LINUX_TRY_PATCH_NO_ATTRIBUTE_ALIAS
+	@if patch -p1 --dry-run -f -s -d $(@D) <$(LINUX_PKGDIR)/0002-Makefile-disable-attribute-alias-for-gcc-8.1.patch.conditional >/dev/null ; then \
+		$(APPLY_PATCHES) $(@D) $(LINUX_PKGDIR) 0002-Makefile-disable-attribute-alias-for-gcc-8.1.patch.conditional ; \
+	fi
+endef
+LINUX_POST_PATCH_HOOKS += LINUX_TRY_PATCH_NO_ATTRIBUTE_ALIAS
+endif
+
 ifeq ($(BR2_LINUX_KERNEL_USE_DEFCONFIG),y)
 LINUX_KCONFIG_DEFCONFIG = $(call qstrip,$(BR2_LINUX_KERNEL_DEFCONFIG))_defconfig
 else ifeq ($(BR2_LINUX_KERNEL_USE_ARCH_DEFAULT_CONFIG),y)
Signature · 1 line
2.14.3
#1 lore raw

RFC PATCH 1/1 linux: disable attribute alias with gcc >= 8.1

Hello Romain,

Quoted 11 lines · Romain Naour

gcc-8 started warning about function aliases that have a non-matching prototype. This seems rather useful in general, but it causes tons of warnings in the Linux kernel, where we rely on abusing those aliases for system call entry points, in order to sanitze the arguments passed from user space in registers.

See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82435

Add a new conditional patch that disable the attribute-alias warning introduced by gcc-8 by adding -Wno-attribute-alias to KBUILD_CFLAGS.

Quoted 6 lines
Cc Thomas Petazzoni <[email protected]>

---

Fixes most of build errors reported by toolchains-builder on Gitlab.
https://gitlab.com/free-electrons/toolchains-builder/pipelines/22921464

Thanks, but unfortunately, it doesn't fix a lot of those build errors, because your patch doesn't apply as soon as the Linux kernel version is a bit different.

For example, if you take qemu_mips32r2el_malta_defconfig, which builds a 4.11.3 kernel, your patch doesn't apply, and so the bug appears.

So instead, I would like to suggest something like this:

ifeq ($(BR2_TOOLCHAIN_GCC_AT_LEAST_8),y)
LINUX_MAKE_ENV += KCFLAGS=-Wno-attribute-alias
endif

which works without any patch, and therefore works with potentially all kernel versions.

Best regards,

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin (formerly Free Electrons)
Embedded Linux and Kernel engineering
https://bootlin.com
#2 lore raw

RFC PATCH 1/1 linux: disable attribute alias with gcc >= 8.1

Hi Thomas,

Le 01/06/2018 ? 23:12, Thomas Petazzoni a ?crit?:

Quoted 28 lines

Hello Romain,

Quoted 11 lines · Romain Naour

gcc-8 started warning about function aliases that have a non-matching prototype. This seems rather useful in general, but it causes tons of warnings in the Linux kernel, where we rely on abusing those aliases for system call entry points, in order to sanitze the arguments passed from user space in registers.

See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82435

Add a new conditional patch that disable the attribute-alias warning introduced by gcc-8 by adding -Wno-attribute-alias to KBUILD_CFLAGS.

Quoted 6 lines
Cc Thomas Petazzoni <[email protected]>

---

Fixes most of build errors reported by toolchains-builder on Gitlab.
https://gitlab.com/free-electrons/toolchains-builder/pipelines/22921464

Thanks, but unfortunately, it doesn't fix a lot of those build errors, because your patch doesn't apply as soon as the Linux kernel version is a bit different.

For example, if you take qemu_mips32r2el_malta_defconfig, which builds a 4.11.3 kernel, your patch doesn't apply, and so the bug appears.

Quoted 8 lines

So instead, I would like to suggest something like this:

ifeq ($(BR2_TOOLCHAIN_GCC_AT_LEAST_8),y)
LINUX_MAKE_ENV += KCFLAGS=-Wno-attribute-alias
endif

which works without any patch, and therefore works with potentially all kernel versions.

Thanks for KCFLAGS, I missed it and tried to use KBUILD_CFLAGS directly... I wanted to not override KBUILD_CFLAGS from linux.mk to not lose CFLAGS defined in the Makefile, that is why I use an conditional patch (which is not great).

I'll resend a v2.

Best regards,
Romain

Quoted 5 lines

Best regards,

Thomas