From 8eb1a0ce5654fe5109e2edb0a90ecb09f29c5a28 Mon Sep 17 00:00:00 2001 From: Kyle Evans Date: Tue, 7 Apr 2020 17:04:24 +0000 Subject: [PATCH] Add -fno-common to all userland/kernel src builds -fno-common will become the default in GCC10/LLVM11. Plenty of work has been put in to make sure our world builds are no -fno-common clean, so let's slap the build with this until it becomes the compiler default to ensure we don't regress. At this time, we will not be enforcing -fno-common on ports builds. I suspect most ports will be or quickly become -fno-common clean as they're naturally built against compilers that default to it, so this will hopefully become a non-issue in due time. The exception to this, which is actually the status quo, is that kmods built from ports will continue to build with -fno-common. As of the time of writing, I intend to also make stable/12 -fno-common clean. What's been done will be MFC'd to stable/11 if it's easily applicable and/or not much work to massage it into being functional, but I anticipate adding -fcommon to stable/11 builds to maintain its ability to be built with newer compilers for the rest of its lifetime instead of putting in a third branch's worth of effort. --- share/mk/src.sys.mk | 5 +++++ sys/conf/kern.pre.mk | 6 +++++- sys/conf/kmod.mk | 7 +++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/share/mk/src.sys.mk b/share/mk/src.sys.mk index fff26b477c6..addc115b8ab 100644 --- a/share/mk/src.sys.mk +++ b/share/mk/src.sys.mk @@ -34,6 +34,11 @@ __postrcconf_${var}:= ${MK_${var}:U-}${WITHOUT_${var}:Uno:Dyes}${WITH_${var}:Uno .endif # SRCCONF .endif +# The following should be removed no earlier than LLVM11 being imported into the +# tree, to ensure we don't regress the build. LLVM11 and GCC10 will switch the +# default over to -fno-common, making this redundant. +CFLAGS+= -fno-common + # tempting, but bsd.compiler.mk causes problems this early # probably need to remove dependence on bsd.own.mk #.include "src.opts.mk" diff --git a/sys/conf/kern.pre.mk b/sys/conf/kern.pre.mk index 193d8f6c2fa..918a58b510b 100644 --- a/sys/conf/kern.pre.mk +++ b/sys/conf/kern.pre.mk @@ -86,7 +86,7 @@ CFLAGS_PARAM_LARGE_FUNCTION_GROWTH?=1000 .if ${MACHINE_CPUARCH} == "mips" CFLAGS_ARCH_PARAMS?=--param max-inline-insns-single=1000 -DMACHINE_ARCH='"${MACHINE_ARCH}"' .endif -CFLAGS.gcc+= -fno-common -fms-extensions -finline-limit=${INLINE_LIMIT} +CFLAGS.gcc+= -fms-extensions -finline-limit=${INLINE_LIMIT} CFLAGS.gcc+= --param inline-unit-growth=${CFLAGS_PARAM_INLINE_UNIT_GROWTH} CFLAGS.gcc+= --param large-function-growth=${CFLAGS_PARAM_LARGE_FUNCTION_GROWTH} CFLAGS.gcc+= -fms-extensions @@ -98,6 +98,10 @@ WERROR?= -Wno-error .else WERROR?= -Werror .endif +# The following should be removed no earlier than LLVM11 being imported into the +# tree, to ensure we don't regress the build. LLVM11 and GCC10 will switch the +# default over to -fno-common, making this redundant. +CFLAGS+= -fno-common # XXX LOCORE means "don't declare C stuff" not "for locore.s". ASM_CFLAGS= -x assembler-with-cpp -DLOCORE ${CFLAGS} ${ASM_CFLAGS.${.IMPSRC:T}} diff --git a/sys/conf/kmod.mk b/sys/conf/kmod.mk index 55c8344e7da..e5c72030838 100644 --- a/sys/conf/kmod.mk +++ b/sys/conf/kmod.mk @@ -133,6 +133,13 @@ CFLAGS.gcc+= --param large-function-growth=1000 # Disallow common variables, and if we end up with commons from # somewhere unexpected, allocate storage for them in the module itself. +# +# -fno-common is the default for src builds, but this should be left in place +# until at least we catch up to GCC10/LLVM11 or otherwise enable -fno-common +# in instead. For now, we will have duplicate -fno-common in +# CFLAGS for in-tree module builds as they will also pick it up from +# share/mk/src.sys.mk, but the following is important for out-of-tree modules +# (e.g. ports). CFLAGS+= -fno-common LDFLAGS+= -d -warn-common