[PATCH 22/46] btf, lto: Make all BTF IDs global on LTO

From: Jiri Slaby (SUSE)
Date: Mon Nov 14 2022 - 06:46:19 EST


From: Andi Kleen <andi@xxxxxxxxxxxxxx>

gcc LTO can put assembler top level statements into other assembler
files. The BTF IDs assumed that they are in the same file. So if we are
building with gcc LTO, make all BTF IDs global to work around this.

This is done by new __global_on_lto macro.

[js] do that for 8B BTF set too (commit ab21d6063c01)
[js] do global only in LTO case

Cc: Alexei Starovoitov <ast@xxxxxxxxxx>
Cc: Daniel Borkmann <daniel@xxxxxxxxxxxxx>
Cc: Andrii Nakryiko <andrii@xxxxxxxxxx>
Cc: Martin KaFai Lau <martin.lau@xxxxxxxxx>
Cc: Song Liu <song@xxxxxxxxxx>
Cc: Yonghong Song <yhs@xxxxxx>
Cc: John Fastabend <john.fastabend@xxxxxxxxx>
Cc: KP Singh <kpsingh@xxxxxxxxxx>
Cc: Stanislav Fomichev <sdf@xxxxxxxxxx>
Cc: Hao Luo <haoluo@xxxxxxxxxx>
Cc: Jiri Olsa <jolsa@xxxxxxxxxx>
Cc: bpf@xxxxxxxxxxxxxxx
Signed-off-by: Andi Kleen <andi@xxxxxxxxxxxxxx>
Signed-off-by: Martin Liska <mliska@xxxxxxx>
Signed-off-by: Jiri Slaby <jslaby@xxxxxxx>
---
include/linux/btf_ids.h | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/include/linux/btf_ids.h b/include/linux/btf_ids.h
index 3011757a48ef..a2bef302e42c 100644
--- a/include/linux/btf_ids.h
+++ b/include/linux/btf_ids.h
@@ -37,7 +37,7 @@ struct btf_id_set8 {
#define ____BTF_ID(symbol, word) \
asm( \
".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \
-".local " #symbol " ; \n" \
+"." __global_on_lto " " #symbol " ; \n" \
".type " #symbol ", STT_OBJECT; \n" \
".size " #symbol ", 4; \n" \
#symbol ": \n" \
@@ -88,7 +88,7 @@ asm( \
".popsection; \n");

#define BTF_ID_LIST(name) \
-__BTF_ID_LIST(name, "local") \
+__BTF_ID_LIST(name, __global_on_lto) \
extern u32 name[];

#define BTF_ID_LIST_GLOBAL(name, n) \
@@ -148,8 +148,8 @@ asm( \
".popsection; \n");

#define BTF_SET_START(name) \
-__BTF_ID_LIST(name, "local") \
-__BTF_SET_START(name, "local")
+__BTF_ID_LIST(name, __global_on_lto) \
+__BTF_SET_START(name, __global_on_lto)

#define BTF_SET_START_GLOBAL(name) \
__BTF_ID_LIST(name, "globl") \
@@ -192,8 +192,8 @@ asm( \
".popsection; \n");

#define BTF_SET8_START(name) \
-__BTF_ID_LIST(name, "local") \
-__BTF_SET8_START(name, "local")
+__BTF_ID_LIST(name, __global_on_lto) \
+__BTF_SET8_START(name, __global_on_lto)

#define BTF_SET8_END(name) \
asm( \
--
2.38.1