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: 3814311 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 BCA869F1CD for ; Tue, 11 Mar 2014 21:27:07 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C9BE520211 for ; Tue, 11 Mar 2014 21:27:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4B1CD201FD for ; Tue, 11 Mar 2014 21:27:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753714AbaCKV1E (ORCPT ); Tue, 11 Mar 2014 17:27:04 -0400 Received: from mail-pb0-f54.google.com ([209.85.160.54]:57242 "EHLO mail-pb0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752203AbaCKV1D (ORCPT ); Tue, 11 Mar 2014 17:27:03 -0400 Received: by mail-pb0-f54.google.com with SMTP id ma3so116459pbc.13 for ; Tue, 11 Mar 2014 14:27:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=converseincode.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=Kvd9YVP73iy91B2XZL3ebLP++KL6duDj6QifpUoPQRs=; b=a60maAACK/l0LqIimVrxo28vY81waSgiFgIj0QmRf5ze4z9JhDj7Nuk2xfOZVIV8PA JSAc207u5ECK2ehygAp9GPQAsfuIyrdIO4LB4UdXFp5NY9l/6qkUyD0QA6k926IN7Epy KKJ8D/aFdZvG/iZTtJfi587c80D+cwwQ/LCn8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-type:content-transfer-encoding; bh=Kvd9YVP73iy91B2XZL3ebLP++KL6duDj6QifpUoPQRs=; b=MFka6j57CpAzVFwoOgX9KKqyJLT9uftqX3o91bHEAWQ9caRmCtSgZSUHKLJMf/FOG7 dFyEM8N92QyQqiVfDjQhszukaSJW03i38T91WyIM86oevEKYCBxGBl5sRSQ9sWyVrtjG 6/FPlYLgectfJfTOEe6x9/AxuEDVxydbdxI/ek9P73xw8AT7CL4kJ3JjPllTOgnaAxPc 5EYHMFCzoXlgC5a2e0iIZ+9liS84XlSCroBPDUfltvgRnz4k+8/s+vr2mL9qFqlGJzho o6REpfBfgk1NEOm51DNeJ1/pHL6yO0LjHkIXWg3fLn0S0CwsfpDTbkzx7CsjsiurXRxg Ia4w== X-Gm-Message-State: ALoCoQnHMR6FSezimc6eJvDkXP1vMJoa+Xl+0Mkf5+lTNjCKw912PMThjGFVW4uMk6Ruehpk4ap/ 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-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID,T_RP_MATCHES_RCVD,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 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