From accc510ac3c00e86db2eeea29eee57b44731ea02 Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Wed, 28 Jan 2015 18:36:33 +0000 Subject: [PATCH] Since clang 3.6.0 now implements the archetype 'freebsd_kprintf' for __attribute__((format(...))), and the -fformat-extensions flag was removed, introduce a new macro in bsd.sys.mk to choose the right variant of compile flag for the used compiler, and use it. Also add something similar to kern.mk, since including bsd.sys.mk from that file will anger Warner. :-) Note that bsd.sys.mk does not support the MK_FORMAT_EXTENSIONS knob used in kern.mk, since that knob is only available in kern.opts.mk, not in src.opts.mk. We might want to add it later, to more easily support external compilers for building world (in particular, sys/boot). --- share/mk/bsd.sys.mk | 7 +++++++ sys/boot/efi/libefi/Makefile | 5 ++--- sys/boot/i386/libi386/Makefile | 4 ++-- sys/boot/pc98/libpc98/Makefile | 4 ++-- sys/conf/kern.mk | 2 ++ 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/share/mk/bsd.sys.mk b/share/mk/bsd.sys.mk index 5f2007906f5..04e7b9de07b 100644 --- a/share/mk/bsd.sys.mk +++ b/share/mk/bsd.sys.mk @@ -109,6 +109,13 @@ CWARNFLAGS+= -Werror CWARNFLAGS+= -Wno-format .endif # NO_WFORMAT || NO_WFORMAT.${COMPILER_TYPE} +# How to handle FreeBSD custom printf format specifiers. +.if ${COMPILER_TYPE} == "clang" && ${COMPILER_VERSION} >= 30600 +FORMAT_EXTENSIONS= -D__printf__=__freebsd_kprintf__ +.else +FORMAT_EXTENSIONS= -fformat-extensions +.endif + .if defined(IGNORE_PRAGMA) CWARNFLAGS+= -Wno-unknown-pragmas .endif # IGNORE_PRAGMA diff --git a/sys/boot/efi/libefi/Makefile b/sys/boot/efi/libefi/Makefile index 3edeb22ea5a..55abffc3079 100644 --- a/sys/boot/efi/libefi/Makefile +++ b/sys/boot/efi/libefi/Makefile @@ -20,8 +20,7 @@ CFLAGS+= -I${.CURDIR}/../../common CFLAGS+= -DNO_PCI - -# Suppress warning from clang for FreeBSD %b and %D formats -CFLAGS+= -fformat-extensions +# Handle FreeBSD specific %b and %D printf format specifiers +CFLAGS+= ${FORMAT_EXTENSIONS} .include diff --git a/sys/boot/i386/libi386/Makefile b/sys/boot/i386/libi386/Makefile index 0f360e99ab8..3e61a1b9686 100644 --- a/sys/boot/i386/libi386/Makefile +++ b/sys/boot/i386/libi386/Makefile @@ -55,8 +55,8 @@ CFLAGS+= -I${.CURDIR}/../../common -I${.CURDIR}/../common \ # the location of libstand CFLAGS+= -I${.CURDIR}/../../../../lib/libstand/ -# Suppress warning from clang for FreeBSD %b and %D formats -CFLAGS+= -fformat-extensions +# Handle FreeBSD specific %b and %D printf format specifiers +CFLAGS+= ${FORMAT_EXTENSIONS} .if ${MACHINE_CPUARCH} == "amd64" CLEANFILES+= machine diff --git a/sys/boot/pc98/libpc98/Makefile b/sys/boot/pc98/libpc98/Makefile index e612205de46..6b11de9f699 100644 --- a/sys/boot/pc98/libpc98/Makefile +++ b/sys/boot/pc98/libpc98/Makefile @@ -44,7 +44,7 @@ CFLAGS+= -I${.CURDIR}/../../common \ # the location of libstand CFLAGS+= -I${.CURDIR}/../../../../lib/libstand/ -# Suppress warning from clang for FreeBSD %b and %D formats -CFLAGS+= -fformat-extensions +# Handle FreeBSD specific %b and %D printf format specifiers +CFLAGS+= ${FORMAT_EXTENSIONS} .include diff --git a/sys/conf/kern.mk b/sys/conf/kern.mk index b964151437e..bfc447379a2 100644 --- a/sys/conf/kern.mk +++ b/sys/conf/kern.mk @@ -58,6 +58,8 @@ CWARNEXTRA?= -Wno-uninitialized # to be disabled. WARNING: format checking is disabled in this case. .if ${MK_FORMAT_EXTENSIONS} == "no" FORMAT_EXTENSIONS= -Wno-format +.elif ${COMPILER_TYPE} == "clang" && ${COMPILER_VERSION} >= 30600 +FORMAT_EXTENSIONS= -D__printf__=__freebsd_kprintf__ .else FORMAT_EXTENSIONS= -fformat-extensions .endif