From patchwork Wed Feb 26 01:08:39 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Behan Webster X-Patchwork-Id: 25333 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pd0-f198.google.com (mail-pd0-f198.google.com [209.85.192.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 2907720143 for ; Wed, 26 Feb 2014 01:09:42 +0000 (UTC) Received: by mail-pd0-f198.google.com with SMTP id v10sf514907pde.1 for ; Tue, 25 Feb 2014 17:09:42 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe:content-type :content-transfer-encoding; bh=KyMcthVlpXXbEtbxr3gSh0GPlTIqbzoodOB6RzoqtuA=; b=k6mccdyHCN89la2oHo70xqpev9yrTz/Ay9W3rDvXHc6GIcGMDPB+NKRHkvlEriJLkx EZNJ7Ge//OIx475ENrdA/uRg3D2uklFaWojZDukv4xjNj1sJYwPWMO7BpovVkuUWNpGY PPGgdMO6agCUkjXzlGB8ymfRvIHjtY/vV4OD0xZCBOLmHUcq2vFauQJAXljA6SdGACSr Sgp1y7YumWFd/RkKv4QM2VcbOhTqN+6L8avDulLeOfiYTkl2zcvc113NunBVzhH6q+1d 5yo2gD8mQsBYnlOoIayBeJKUl77SNlWKSl57mSDdn3xn8OEkyJ0nriZ/lnrgID+YOMP+ fu6Q== X-Gm-Message-State: ALoCoQm8jg0odKFWA4PwaBw3M9rpQDW0Hja2b0nd/2CJzU/BBJd42eTHMsvo+FJnIXzEz2VqdEx3 X-Received: by 10.67.4.202 with SMTP id cg10mr1991188pad.42.1393376982215; Tue, 25 Feb 2014 17:09:42 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.102.49 with SMTP id v46ls29124qge.6.gmail; Tue, 25 Feb 2014 17:09:42 -0800 (PST) X-Received: by 10.221.26.10 with SMTP id rk10mr3617857vcb.0.1393376982066; Tue, 25 Feb 2014 17:09:42 -0800 (PST) Received: from mail-vc0-x230.google.com (mail-vc0-x230.google.com [2607:f8b0:400c:c03::230]) by mx.google.com with ESMTPS id qw5si7279254vcb.123.2014.02.25.17.09.42 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 25 Feb 2014 17:09:42 -0800 (PST) Received-SPF: neutral (google.com: 2607:f8b0:400c:c03::230 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=2607:f8b0:400c:c03::230; Received: by mail-vc0-f176.google.com with SMTP id la4so215783vcb.35 for ; Tue, 25 Feb 2014 17:09:42 -0800 (PST) X-Received: by 10.58.207.13 with SMTP id ls13mr3571953vec.13.1393376981933; Tue, 25 Feb 2014 17:09:41 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.174.196 with SMTP id u4csp179539vcz; Tue, 25 Feb 2014 17:09:41 -0800 (PST) X-Received: by 10.68.224.195 with SMTP id re3mr3020095pbc.93.1393376981107; Tue, 25 Feb 2014 17:09:41 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id xn1si5352675pbc.128.2014.02.25.17.09.40; Tue, 25 Feb 2014 17:09:40 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751956AbaBZBJb (ORCPT + 26 others); Tue, 25 Feb 2014 20:09:31 -0500 Received: from mail-pb0-f43.google.com ([209.85.160.43]:61848 "EHLO mail-pb0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751491AbaBZBJ0 (ORCPT ); Tue, 25 Feb 2014 20:09:26 -0500 Received: by mail-pb0-f43.google.com with SMTP id ma3so220833pbc.16 for ; Tue, 25 Feb 2014 17:09:26 -0800 (PST) X-Received: by 10.66.231.104 with SMTP id tf8mr5176966pac.48.1393376966017; Tue, 25 Feb 2014 17:09:26 -0800 (PST) Received: from galdor.websterwood.com ([207.6.123.58]) by mx.google.com with ESMTPSA id un5sm154425478pab.3.2014.02.25.17.09.23 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 25 Feb 2014 17:09:24 -0800 (PST) From: behanw@converseincode.com To: mmarek@suse.cz, tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, x86@kernel.org, sparse@chrisli.org Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sparse@vger.kernel.org, torvalds@linux-foundation.org, dwmw2@infradead.org, pageexec@freemail.hu, Behan Webster , =?UTF-8?q?Jan-Simon=20M=C3=B6ller?= , Mark Charlebois Subject: [PATCH 1/5] kbuild: LLVMLinux: Add Kbuild support for building kernel with Clang Date: Tue, 25 Feb 2014 17:08:39 -0800 Message-Id: <1393376923-21892-2-git-send-email-behanw@converseincode.com> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1393376923-21892-1-git-send-email-behanw@converseincode.com> References: <1393376923-21892-1-git-send-email-behanw@converseincode.com> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Original-Sender: behanw@converseincode.com X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 2607:f8b0:400c:c03::230 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=neutral (bad format) header.i=@converseincode.com Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Behan Webster Add support to toplevel Makefile for compiling with clang, both for HOSTCC and CC. Use cc-option to prevent gcc option from breaking clang, and from clang options from breaking gcc. Clang 3.4 semantics are the same as gcc semantics for unsupported flags. For unsupported warnings clang 3.4 returns true but shows a warning and gcc shows a warning and returns false. Signed-off-by: Behan Webster Signed-off-by: Jan-Simon Möller Signed-off-by: Mark Charlebois Cc: PaX Team --- Makefile | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 831b36a..c4ab30d 100644 --- a/Makefile +++ b/Makefile @@ -247,6 +247,15 @@ HOSTCXX = g++ HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer HOSTCXXFLAGS = -O2 +ifeq ($(shell $(HOSTCC) -v 2>&1 | grep -c "clang version"), 1) +HOSTCOMPILER := clang +HOSTCFLAGS += -Wno-unused-value -Wno-unused-parameter \ + -Wno-missing-field-initializers -fno-delete-null-pointer-checks +else +HOSTCOMPILER := gcc +endif +export HOSTCOMPILER + # Decide whether to build built-in, modular, or both. # Normally, just do built-in. @@ -323,6 +332,12 @@ endif export quiet Q KBUILD_VERBOSE +ifeq ($(shell $(CC) -v 2>&1 | grep -c "clang version"), 1) +COMPILER := clang +else +COMPILER := gcc +endif +export COMPILER # Look for make include files relative to root of kernel src MAKEFLAGS += --include-dir=$(srctree) @@ -382,7 +397,7 @@ KBUILD_CFLAGS := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \ -fno-strict-aliasing -fno-common \ -Werror-implicit-function-declaration \ -Wno-format-security \ - -fno-delete-null-pointer-checks + $(call cc-option,-fno-delete-null-pointer-checks,) KBUILD_AFLAGS_KERNEL := KBUILD_CFLAGS_KERNEL := KBUILD_AFLAGS := -D__ASSEMBLY__ @@ -620,9 +635,24 @@ else endif KBUILD_CFLAGS += $(stackp-flag) +ifeq ($(COMPILER),clang) +KBUILD_CPPFLAGS += $(call cc-option,-Qunused-arguments,) +KBUILD_CPPFLAGS += $(call cc-option,-Wno-unknown-warning-option,) +KBUILD_CFLAGS += $(call cc-disable-warning, unused-variable) +KBUILD_CFLAGS += $(call cc-disable-warning, format-invalid-specifier) +KBUILD_CFLAGS += $(call cc-disable-warning, gnu) +# Quiet clang warning: comparison of unsigned expression < 0 is always false +KBUILD_CFLAGS += $(call cc-disable-warning, tautological-compare) +# CLANG uses a _MergedGlobals as optimization, but this breaks modpost, as the +# source of a reference will be _MergedGlobals and not on of the whitelisted names. +# See modpost pattern 2 +KBUILD_CFLAGS += $(call cc-option, -mno-global-merge,) +else + # This warning generated too much noise in a regular build. # Use make W=1 to enable this warning (see scripts/Makefile.build) KBUILD_CFLAGS += $(call cc-disable-warning, unused-but-set-variable) +endif ifdef CONFIG_FRAME_POINTER KBUILD_CFLAGS += -fno-omit-frame-pointer -fno-optimize-sibling-calls