From: Ard Biesheuvel <ardb@kernel.org>
To: linux-arm-kernel@lists.infradead.org
Cc: Ard Biesheuvel <ardb@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Quentin Perret <qperret@google.com>,
Catalin Marinas <catalin.marinas@arm.com>,
James Morse <james.morse@arm.com>, Will Deacon <will@kernel.org>,
Frederic Weisbecker <frederic@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
Kees Cook <keescook@chromium.org>
Subject: [PATCH v5 1/2] static_call: force symbol references with external linkage for CFI/LTO
Date: Thu, 28 Oct 2021 01:34:08 +0200 [thread overview]
Message-ID: <20211027233409.902331-2-ardb@kernel.org> (raw)
In-Reply-To: <20211027233409.902331-1-ardb@kernel.org>
When building with Clang with CFI or LTO enabled, the linker may decide
not to emit function symbols with static linkage at all, or emit them
under a different symbol name. This breaks static calls, given that we
refer to such functions both from C code and from assembler, and we
expect the names to be the same.
So let's force the use of an alias with external linkage in a way that
is visible to the compiler. This ensures that the C name and the asm
name are identical.
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
include/linux/static_call.h | 21 ++++++++++++++++++--
1 file changed, 19 insertions(+), 2 deletions(-)
diff --git a/include/linux/static_call.h b/include/linux/static_call.h
index 3e56a9751c06..19dc210214c0 100644
--- a/include/linux/static_call.h
+++ b/include/linux/static_call.h
@@ -327,10 +327,27 @@ static inline int static_call_text_reserved(void *start, void *end)
#endif /* CONFIG_HAVE_STATIC_CALL */
+#ifdef CONFIG_LTO
+/*
+ * DEFINE_STATIC_CALL() accepts any function symbol reference for its _func
+ * argument, but this may cause problems under Clang LTO/CFI if the function
+ * symbol has static linkage, because the symbol names exposed at the
+ * asm/object level may deviate from the C names. So let's force the reference
+ * to go via an alias with external linkage instead.
+ */
+#define _DEFINE_STATIC_CALL(name, _func, _init, _alias) \
+ extern typeof(_func) _alias __alias(_init); \
+ __DEFINE_STATIC_CALL(name, _func, _alias)
+#else
+#define _DEFINE_STATIC_CALL(name, _func, _init, _alias) \
+ __DEFINE_STATIC_CALL(name, _func, _init)
+#endif
+
#define DEFINE_STATIC_CALL(name, _func) \
- __DEFINE_STATIC_CALL(name, _func, _func)
+ _DEFINE_STATIC_CALL(name, _func, _func, __UNIQUE_ID(_func))
#define DEFINE_STATIC_CALL_RET0(name, _func) \
- __DEFINE_STATIC_CALL(name, _func, __static_call_return0)
+ _DEFINE_STATIC_CALL(name, _func, __static_call_return0, \
+ __UNIQUE_ID(_func))
#endif /* _LINUX_STATIC_CALL_H */
--
2.30.2
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2021-10-27 23:35 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-27 23:34 [PATCH v5 0/2] static call support for arm64 Ard Biesheuvel
2021-10-27 23:34 ` Ard Biesheuvel [this message]
2021-10-27 23:34 ` [PATCH v5 2/2] arm64: implement support for static call trampolines Ard Biesheuvel
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=20211027233409.902331-2-ardb@kernel.org \
--to=ardb@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=frederic@kernel.org \
--cc=james.morse@arm.com \
--cc=keescook@chromium.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=mark.rutland@arm.com \
--cc=peterz@infradead.org \
--cc=qperret@google.com \
--cc=will@kernel.org \
/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).