From patchwork Tue Mar 11 21:26:57 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Behan Webster X-Patchwork-Id: 26050 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f199.google.com (mail-ob0-f199.google.com [209.85.214.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id CE42A202E1 for ; Tue, 11 Mar 2014 21:27:16 +0000 (UTC) Received: by mail-ob0-f199.google.com with SMTP id wo20sf35495246obc.10 for ; Tue, 11 Mar 2014 14:27:16 -0700 (PDT) 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=yW9xon0DRMYVgZcVg7NuFfAJ6zNjif0z0e0iXltYeVg=; b=B09JLLT8ds6FWl//M5hk8/1PmUrGPQFeA/DWJjQm2x1sWcz6nAvQHQ+sCN13NfB+bX OQkBkXJT3to+a7KSJ/sTtYPk1xz0X5W3cNxiUZo0qQtQzscPQk+edn89Ewi2iH2is6cT pq/A3mcVPfCz6CeOZOoLR4O79IHND0D0GpTxkJKQlPiS+PNm8XSTk0EIYWb4vFjXQLye C0kHFVMHsF/t1T8CN5Y+PW3bg8nUrwgAeE/oIbl2TLfjN024XeYlV0mnUAdcWVr1UwBF OpcwsMR3bT6edDiIfEc3i97K/YOxcXZVGzfdKjBYC1le+4T7PcIeXeaMApIheIr76RUB wc4g== X-Gm-Message-State: ALoCoQl5Ytuc+WkpEzrFV2tX5yi4c9r7TaqkvcIGqGlfpsiDAm+ow789HkSIStOMF8HgojnIYwOh X-Received: by 10.50.225.6 with SMTP id rg6mr10942185igc.6.1394573236202; Tue, 11 Mar 2014 14:27:16 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.33.203 with SMTP id j69ls2644037qgj.27.gmail; Tue, 11 Mar 2014 14:27:16 -0700 (PDT) X-Received: by 10.220.12.140 with SMTP id x12mr28883966vcx.19.1394573236062; Tue, 11 Mar 2014 14:27:16 -0700 (PDT) Received: from mail-ve0-x22c.google.com (mail-ve0-x22c.google.com [2607:f8b0:400c:c01::22c]) by mx.google.com with ESMTPS id cp10si6184047ved.96.2014.03.11.14.27.16 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 11 Mar 2014 14:27:16 -0700 (PDT) Received-SPF: neutral (google.com: 2607:f8b0:400c:c01::22c 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:c01::22c; Received: by mail-ve0-f172.google.com with SMTP id jx11so9324610veb.31 for ; Tue, 11 Mar 2014 14:27:16 -0700 (PDT) X-Received: by 10.59.7.170 with SMTP id dd10mr29207741ved.12.1394573235959; Tue, 11 Mar 2014 14:27:15 -0700 (PDT) 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.78.9 with SMTP id i9csp235312vck; Tue, 11 Mar 2014 14:27:15 -0700 (PDT) X-Received: by 10.66.252.135 with SMTP id zs7mr434769pac.13.1394573235003; Tue, 11 Mar 2014 14:27:15 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a3si210936pay.252.2014.03.11.14.27.14; Tue, 11 Mar 2014 14:27:14 -0700 (PDT) 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 S1755803AbaCKV1G (ORCPT + 26 others); Tue, 11 Mar 2014 17:27:06 -0400 Received: from mail-pd0-f177.google.com ([209.85.192.177]:42366 "EHLO mail-pd0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753061AbaCKV1D (ORCPT ); Tue, 11 Mar 2014 17:27:03 -0400 Received: by mail-pd0-f177.google.com with SMTP id g10so113704pdj.36 for ; Tue, 11 Mar 2014 14:27:02 -0700 (PDT) X-Received: by 10.68.52.132 with SMTP id t4mr441144pbo.102.1394573222268; Tue, 11 Mar 2014 14:27:02 -0700 (PDT) Received: from localhost.localdomain ([207.6.123.58]) by mx.google.com with ESMTPSA id pp5sm485656pbb.33.2014.03.11.14.27.00 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 11 Mar 2014 14:27:01 -0700 (PDT) From: behanw@converseincode.com To: mmarek@suse.cz Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, dwmw2@infradead.org, pageexec@freemail.hu, Behan Webster , =?UTF-8?q?Jan-Simon=20M=C3=B6ller?= , Mark Charlebois Subject: [PATCH 1/5 v2] kbuild: LLVMLinux: Add Kbuild support for building kernel with Clang Date: Tue, 11 Mar 2014 14:26:57 -0700 Message-Id: <1394573217-5816-1-git-send-email-behanw@converseincode.com> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <20140309215834.GA29655@ravnborg.org> References: <20140309215834.GA29655@ravnborg.org> 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:c01::22c 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 | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 1a2628e..db2cd6e 100644 --- a/Makefile +++ b/Makefile @@ -247,6 +247,11 @@ 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) +HOSTCFLAGS += -Wno-unused-value -Wno-unused-parameter \ + -Wno-missing-field-initializers -fno-delete-null-pointer-checks +endif + # Decide whether to build built-in, modular, or both. # Normally, just do built-in. @@ -323,6 +328,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 +393,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__ @@ -622,9 +633,24 @@ endif 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