linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
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" <behanw@converseincode.com>,
	"Jan-Simon Möller" <dl9pf@gmx.de>,
	"Mark Charlebois" <charlebm@gmail.com>
Subject: [PATCH 1/5 v2] kbuild: LLVMLinux: Add Kbuild support for building kernel with Clang
Date: Tue, 11 Mar 2014 14:26:57 -0700	[thread overview]
Message-ID: <1394573217-5816-1-git-send-email-behanw@converseincode.com> (raw)
In-Reply-To: <20140309215834.GA29655@ravnborg.org>

From: Behan Webster <behanw@converseincode.com>

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 <behanw@converseincode.com>
Signed-off-by: Jan-Simon Möller <dl9pf@gmx.de>
Signed-off-by: Mark Charlebois <charlebm@gmail.com>
Cc: PaX Team <pageexec@freemail.hu>
---
 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
-- 
1.8.3.2


  parent reply	other threads:[~2014-03-11 21:27 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-26  1:08 [PATCH 0/5] kbuild: LLVMLinux: Initial updates to kbuild to enable the kernel to be compiled with clang/LLVM behanw
2014-02-26  1:08 ` [PATCH 1/5] kbuild: LLVMLinux: Add Kbuild support for building kernel with Clang behanw
2014-03-09 21:58   ` Sam Ravnborg
2014-03-11  6:58     ` Behan Webster
2014-03-11 21:26     ` behanw [this message]
2014-02-26  1:08 ` [PATCH 2/5] kbuild: LLVMLinux: Adapt warnings for compilation with clang behanw
2014-02-26  1:17   ` Dave Jones
2014-02-26  1:31     ` Behan Webster
2014-02-26  1:34       ` H. Peter Anvin
2014-02-26  2:38     ` Behan Webster
2014-03-06 17:59   ` [PATCH 2/5 v2] " behanw
2014-02-26  1:08 ` [PATCH 3/5] kbuild: LLVMLinux: Fix LINUX_COMPILER definition script " behanw
2014-02-26  1:08 ` [PATCH 4/5] LLVMLinux: Add support for clang to compiler.h and new compiler-clang.h behanw
2014-02-26  1:08 ` [PATCH 5/5] x86 kbuild: LLVMLinux: More cc-options added for clang behanw
2014-02-26  1:32   ` H. Peter Anvin
2014-02-26  1:44     ` Behan Webster
2014-03-06 18:03     ` [PATCH 5/5 v2] " behanw

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1394573217-5816-1-git-send-email-behanw@converseincode.com \
    --to=behanw@converseincode.com \
    --cc=charlebm@gmail.com \
    --cc=dl9pf@gmx.de \
    --cc=dwmw2@infradead.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mmarek@suse.cz \
    --cc=pageexec@freemail.hu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).