From: ashimida <ashimida@linux.alibaba.com>
To: masahiroy@kernel.org, michal.lkml@markovi.net, nathan@kernel.org,
ndesaulniers@google.com
Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org,
clang-built-linux@googlegroups.com,
ashimida <ashimida@linux.alibaba.com>
Subject: [PATCH] [RFC] kbuild: add CLANG_TRIPLE to prevent clang from compiling with wrong --target
Date: Thu, 9 Sep 2021 15:42:43 +0800 [thread overview]
Message-ID: <1631173363-40160-1-git-send-email-ashimida@linux.alibaba.com> (raw)
Kernel compiled with tool chain CROSS_COMPILE=aarch64-linux-android-
will panic during the startup phase.
Clang's --target option comes from $(CROSS_COMPILE). At the time
-fstack-protector-strong is enabled, and compiled with command:
make CC=clang HOSTCC=clang ARCH=arm64 CROSS_COMPILE=aarch64-linux-android-
clang will insert code like:
mrs x8, TPIDR_EL0 //default value is zero
str x8, [sp]
ldr x8, [x8, #40] //access addr 0x40
instead of the code that accesses __stack_chk_guard to get the
canary, which will cause the kernel to crash due to 0x40
address access.
This patch (from android) is used to remind the user that current
tool chain cannot be used as the "--target" of clang, the user
should specify an additional "--target" through CLANG_TRIPLE.
Signed-off-by: ashimida <ashimida@linux.alibaba.com>
---
Makefile | 6 +++++-
scripts/clang-android.sh | 4 ++++
2 files changed, 9 insertions(+), 1 deletion(-)
create mode 100755 scripts/clang-android.sh
diff --git a/Makefile b/Makefile
index 61741e9..09bb314 100644
--- a/Makefile
+++ b/Makefile
@@ -586,7 +586,11 @@ CC_VERSION_TEXT = $(subst $(pound),,$(shell $(CC) --version 2>/dev/null | head -
ifneq ($(findstring clang,$(CC_VERSION_TEXT)),)
ifneq ($(CROSS_COMPILE),)
-CLANG_FLAGS += --target=$(notdir $(CROSS_COMPILE:%-=%))
+CLANG_TRIPLE ?= $(CROSS_COMPILE)
+CLANG_FLAGS += --target=$(notdir $(CLANG_TRIPLE:%-=%))
+ifeq ($(shell $(srctree)/scripts/clang-android.sh $(CC) $(CLANG_FLAGS)), y)
+$(error "Clang with Android --target detected. Did you specify CLANG_TRIPLE?")
+endif
endif
ifeq ($(LLVM_IAS),1)
CLANG_FLAGS += -integrated-as
diff --git a/scripts/clang-android.sh b/scripts/clang-android.sh
new file mode 100755
index 0000000..9186c4f
--- /dev/null
+++ b/scripts/clang-android.sh
@@ -0,0 +1,4 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+
+$* -dM -E - </dev/null 2>&1 | grep -q __ANDROID__ && echo "y"
--
2.7.4
next reply other threads:[~2021-09-09 7:42 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-09 7:42 ashimida [this message]
2021-09-09 17:19 ` Nick Desaulniers
2021-09-11 11:55 ` ashimida
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=1631173363-40160-1-git-send-email-ashimida@linux.alibaba.com \
--to=ashimida@linux.alibaba.com \
--cc=clang-built-linux@googlegroups.com \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=masahiroy@kernel.org \
--cc=michal.lkml@markovi.net \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
/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
all inboxes | Powered by JetHome®