[PATCH 04/46] compiler.h: introduce __visible_on_lto

From: Jiri Slaby (SUSE)
Date: Mon Nov 14 2022 - 06:44:24 EST


From: Jiri Slaby <jslaby@xxxxxxx>

__visible_on_lto is defined as "__visible" when gcc LTO is turned on
(see later patches), and "static" otherwise. It is needed for top-level
symbols which are referenced in assembly. It is because the assembly and
the symbol can each end up in a different file with gcc LTO. And that
leads to linker errors.

So the symbols have to be visible when gcc LTO is in charge. On the
contrary, they have to be static on non-gcc-LTO builds. Otherwise a
warning about missing declaration occurs.

Reported-by: kernel test robot <lkp@xxxxxxxxx>
Cc: Martin Liska <mliska@xxxxxxx>
Signed-off-by: Jiri Slaby <jslaby@xxxxxxx>
---
include/linux/compiler.h | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/include/linux/compiler.h b/include/linux/compiler.h
index 973a1bfd7ef5..2305a3cbe99c 100644
--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -133,6 +133,12 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val,
#define __annotate_jump_table
#endif /* CONFIG_OBJTOOL */

+#ifdef CONFIG_LTO_GCC
+# define __visible_on_lto __visible
+#else
+# define __visible_on_lto static
+#endif
+
#ifndef unreachable
# define unreachable() do { \
annotate_unreachable(); \
--
2.38.1