From patchwork Thu Nov 6 00:58:54 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Hutchings X-Patchwork-Id: 5238591 Return-Path: X-Original-To: patchwork-linux-kbuild@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 2125D9F295 for ; Thu, 6 Nov 2014 00:59:12 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 266AF20172 for ; Thu, 6 Nov 2014 00:59:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DF9562015E for ; Thu, 6 Nov 2014 00:59:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750915AbaKFA7J (ORCPT ); Wed, 5 Nov 2014 19:59:09 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:56235 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750877AbaKFA7I (ORCPT ); Wed, 5 Nov 2014 19:59:08 -0500 Received: from deadeye.wl.decadent.org.uk ([192.168.4.249] helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from ) id 1XmBPm-0000j6-0x for linux-kbuild@vger.kernel.org; Thu, 06 Nov 2014 00:59:06 +0000 Received: from ben by deadeye with local (Exim 4.84) (envelope-from ) id 1XmBPg-0003Vp-IL for linux-kbuild@vger.kernel.org; Thu, 06 Nov 2014 00:59:00 +0000 Message-ID: <1415235534.3398.35.camel@decadent.org.uk> Subject: [PATCH] kbuild: Use -nostdinc in compile tests From: Ben Hutchings To: linux-kbuild Date: Thu, 06 Nov 2014 00:58:54 +0000 X-Mailer: Evolution 3.12.7-1 Mime-Version: 1.0 X-SA-Exim-Connect-IP: 192.168.4.249 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_TVD_MIME_EPI, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP gcc 4.8 and later include by default. In some versions of eglibc that includes , but that may be missing when building with a biarch compiler. Also itself could be missing as we are only trying to build a kernel, not userland. The -nostdinc option disables this, though it isn't explicitly documented. This option is already used when actually building the kernel, but not by cc-option and other tests. This can result in silently miscompiling the kernel. References: https://bugs.debian.org/717557 References: https://bugs.debian.org/726861 Signed-off-by: Ben Hutchings --- This specific issue appeared and then was fixed in Debian about a year ago, but it seems like it can also affect cross-builds. It may also be worth adding some sort of sanity test, so we stop immediately if $(cc-option $(empty),broken) yields 'broken'. Ben. Makefile | 4 +++- scripts/Kbuild.include | 15 ++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index ffc1ce2..c0fbf67 100644 --- a/Makefile +++ b/Makefile @@ -619,6 +619,8 @@ endif # Tell gcc to never replace conditional load with a non-conditional one KBUILD_CFLAGS += $(call cc-option,--param=allow-store-data-races=0) +NOSTDINC_FLAGS += -nostdinc + ifdef CONFIG_READABLE_ASM # Disable optimizations that make assembler listings hard to read. # reorder blocks reorders the control in the function @@ -742,7 +744,7 @@ KBUILD_CFLAGS += $(call cc-option, -fno-inline-functions-called-once) endif # arch Makefile may override CC so keep this after arch Makefile is included -NOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include) +NOSTDINC_FLAGS += -isystem $(shell $(CC) -print-file-name=include) CHECKFLAGS += $(NOSTDINC_FLAGS) # warn about C99 declaration after statement diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include index 65e7b08..e87fc08 100644 --- a/scripts/Kbuild.include +++ b/scripts/Kbuild.include @@ -111,12 +111,12 @@ as-instr = $(call try-run,\ # Usage: cflags-y += $(call cc-option,-march=winchip-c6,-march=i586) cc-option = $(call try-run,\ - $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(1) -c -x c /dev/null -o "$$TMP",$(1),$(2)) + $(CC) $(NOSTDINC_FLAGS) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(1) -c -x c /dev/null -o "$$TMP",$(1),$(2)) # cc-option-yn # Usage: flag := $(call cc-option-yn,-march=winchip-c6) cc-option-yn = $(call try-run,\ - $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(1) -c -x c /dev/null -o "$$TMP",y,n) + $(CC) $(NOSTDINC_FLAGS) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(1) -c -x c /dev/null -o "$$TMP",y,n) # cc-option-align # Prefix align with either -falign or -malign @@ -126,16 +126,17 @@ cc-option-align = $(subst -functions=0,,\ # cc-disable-warning # Usage: cflags-y += $(call cc-disable-warning,unused-but-set-variable) cc-disable-warning = $(call try-run,\ - $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1))) + $(CC) $(NOSTDINC_FLAGS) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1))) # cc-version # Usage gcc-ver := $(call cc-version) -cc-version = $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-version.sh $(CC)) +cc-version = $(shell $(CONFIG_SHELL) \ + $(srctree)/scripts/gcc-version.sh $(CC) $(NOSTDINC_FLAGS)) # cc-fullversion # Usage gcc-ver := $(call cc-fullversion) cc-fullversion = $(shell $(CONFIG_SHELL) \ - $(srctree)/scripts/gcc-version.sh -p $(CC)) + $(srctree)/scripts/gcc-version.sh -p $(CC) $(NOSTDINC_FLAGS)) # cc-ifversion # Usage: EXTRA_CFLAGS += $(call cc-ifversion, -lt, 0402, -O1) @@ -144,12 +145,12 @@ cc-ifversion = $(shell [ $(call cc-version, $(CC)) $(1) $(2) ] && echo $(3)) # cc-ldoption # Usage: ldflags += $(call cc-ldoption, -Wl$(comma)--hash-style=both) cc-ldoption = $(call try-run,\ - $(CC) $(1) -nostdlib -x c /dev/null -o "$$TMP",$(1),$(2)) + $(CC) $(NOSTDINC_FLAGS) $(1) -nostdlib -x c /dev/null -o "$$TMP",$(1),$(2)) # ld-option # Usage: LDFLAGS += $(call ld-option, -X) ld-option = $(call try-run,\ - $(CC) -x c /dev/null -c -o "$$TMPO" ; $(LD) $(1) "$$TMPO" -o "$$TMP",$(1),$(2)) + $(CC) $(NOSTDINC_FLAGS) -x c /dev/null -c -o "$$TMPO" ; $(LD) $(1) "$$TMPO" -o "$$TMP",$(1),$(2)) # ar-option # Usage: KBUILD_ARFLAGS := $(call ar-option,D)