From 22ba0b2f67ac68d6094772a98e961e2aa572383e Mon Sep 17 00:00:00 2001 From: Warner Losh Date: Sat, 10 May 2014 16:38:09 +0000 Subject: [PATCH] Simplify clang ifdefs in the kernel a bit. Introduce CFLAGS.${COMPILER_TYPE} to mirror userland. Be explicit about which compiler needs something (not clang isn't necessarily gcc in the future). --- sys/conf/Makefile.arm | 13 +++++-------- sys/conf/kern.mk | 20 +++++++------------- sys/conf/kern.pre.mk | 22 +++++++++------------- sys/conf/kmod.mk | 8 +++----- 4 files changed, 24 insertions(+), 39 deletions(-) diff --git a/sys/conf/Makefile.arm b/sys/conf/Makefile.arm index 562d15227eca..9ea428e91fa8 100644 --- a/sys/conf/Makefile.arm +++ b/sys/conf/Makefile.arm @@ -39,20 +39,17 @@ SYSTEM_DEP:= ${SYSTEM_DEP:$S/conf/ldscript.$M=ldscript.$M} STRIP_FLAGS = -S .endif -.if ${COMPILER_TYPE} != "clang" -CFLAGS += -mno-thumb-interwork -.endif +# We don't support gcc's thump interwork stuff, so disable it +CFLAGS.gcc += -mno-thumb-interwork .if empty(DDB_ENABLED) -.if ${MK_ARM_EABI} == "no" && ${COMPILER_TYPE} == "gcc" -CFLAGS += -mno-apcs-frame +.if ${MK_ARM_EABI} == "no" +CFLAGS.gcc += -mno-apcs-frame .endif .elif ${MK_ARM_EABI} != "no" CFLAGS += -funwind-tables -.if ${COMPILER_TYPE} == "clang" # clang requires us to tell it to emit assembly with unwind information -CFLAGS += -mllvm -arm-enable-ehabi -.endif +CFLAGS.clang += -mllvm -arm-enable-ehabi .endif # hack because genassym.c includes sys/bus.h which includes these. diff --git a/sys/conf/kern.mk b/sys/conf/kern.mk index 1571f8360512..19afc4d49381 100644 --- a/sys/conf/kern.mk +++ b/sys/conf/kern.mk @@ -64,11 +64,8 @@ FORMAT_EXTENSIONS= -fformat-extensions # Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3, -mno-sse41 and -mno-sse42 # .if ${MACHINE_CPUARCH} == "i386" -.if ${COMPILER_TYPE} != "clang" -CFLAGS+= -mno-align-long-strings -mpreferred-stack-boundary=2 -.else -CFLAGS+= -mno-aes -mno-avx -.endif +CFLAGS.gcc+= -mno-align-long-strings -mpreferred-stack-boundary=2 +CFLAGS.clang+= -mno-aes -mno-avx CFLAGS+= -mno-mmx -mno-sse -msoft-float INLINE_LIMIT?= 8000 .endif @@ -93,11 +90,8 @@ INLINE_LIMIT?= 15000 # operations which it has a tendency to do. # .if ${MACHINE_CPUARCH} == "sparc64" -.if ${COMPILER_TYPE} == "clang" -CFLAGS+= -mcmodel=large -fno-dwarf2-cfi-asm -.else -CFLAGS+= -mcmodel=medany -msoft-float -.endif +CFLAGS.clang+= -mcmodel=large -fno-dwarf2-cfi-asm +CFLAGS.gcc+= -mcmodel=medany -msoft-float INLINE_LIMIT?= 15000 .endif @@ -116,9 +110,7 @@ INLINE_LIMIT?= 15000 # (-mfpmath= is not supported) # .if ${MACHINE_CPUARCH} == "amd64" -.if ${COMPILER_TYPE} == "clang" -CFLAGS+= -mno-aes -mno-avx -.endif +CFLAGS.clang+= -mno-aes -mno-avx CFLAGS+= -mcmodel=kernel -mno-red-zone -mno-mmx -mno-sse -msoft-float \ -fno-asynchronous-unwind-tables INLINE_LIMIT?= 8000 @@ -173,3 +165,5 @@ CFLAGS+= -fstack-protector .if ${CFLAGS:M-g} != "" && ${CFLAGS:M-gdwarf*} == "" CFLAGS+= -gdwarf-2 .endif + +CFLAGS+= ${CFLAGS.${COMPILER_TYPE}} diff --git a/sys/conf/kern.pre.mk b/sys/conf/kern.pre.mk index 343be5742699..05706fa85be7 100644 --- a/sys/conf/kern.pre.mk +++ b/sys/conf/kern.pre.mk @@ -37,10 +37,10 @@ _MINUS_O= -O2 .endif .endif .if ${MACHINE_CPUARCH} == "amd64" -.if ${COMPILER_TYPE} != "clang" -COPTFLAGS?=-O2 -frename-registers -pipe -.else +.if ${COMPILER_TYPE} == "clang" COPTFLAGS?=-O2 -pipe +.else +COPTFLAGS?=-O2 -frename-registers -pipe .endif .else COPTFLAGS?=${_MINUS_O} -pipe @@ -86,13 +86,11 @@ CFLAGS_PARAM_LARGE_FUNCTION_GROWTH?=1000 .if ${MACHINE_CPUARCH} == "mips" CFLAGS_ARCH_PARAMS?=--param max-inline-insns-single=1000 .endif -.if ${COMPILER_TYPE} != "clang" -CFLAGS+= -fno-common -finline-limit=${INLINE_LIMIT} -CFLAGS+= --param inline-unit-growth=${CFLAGS_PARAM_INLINE_UNIT_GROWTH} -CFLAGS+= --param large-function-growth=${CFLAGS_PARAM_LARGE_FUNCTION_GROWTH} +CFLAGS.gcc+= -fno-common -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} .if defined(CFLAGS_ARCH_PARAMS) -CFLAGS+=${CFLAGS_ARCH_PARAMS} -.endif +CFLAGS.gcc+=${CFLAGS_ARCH_PARAMS} .endif WERROR?= -Werror @@ -107,13 +105,11 @@ GCC_MS_EXTENSIONS= -fms-extensions .if defined(PROFLEVEL) && ${PROFLEVEL} >= 1 CFLAGS+= -DGPROF -.if ${COMPILER_TYPE} != "clang" -CFLAGS+= -falign-functions=16 -.endif +CFLAGS.gcc+= -falign-functions=16 .if ${PROFLEVEL} >= 2 CFLAGS+= -DGPROF4 -DGUPROF PROF= -pg -.if ${COMPILER_TYPE} != "clang" +.if ${COMPILER_TYPE} == "gcc" PROF+= -mprofiler-epilogue .endif .else diff --git a/sys/conf/kmod.mk b/sys/conf/kmod.mk index ebd6179d8453..4f85ab4185a3 100644 --- a/sys/conf/kmod.mk +++ b/sys/conf/kmod.mk @@ -116,11 +116,9 @@ CFLAGS+= -I. -I@ # for example. CFLAGS+= -I@/contrib/altq -.if ${COMPILER_TYPE} != "clang" -CFLAGS+= -finline-limit=${INLINE_LIMIT} -CFLAGS+= --param inline-unit-growth=100 -CFLAGS+= --param large-function-growth=1000 -.endif +CFLAGS.gcc+= -finline-limit=${INLINE_LIMIT} +CFLAGS.gcc+= --param inline-unit-growth=100 +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.