Skip to contentSkip to conversation

bpf: Fix BTF_ID symbol generation

PATCH In review Jiri Olsa 2 participants 3 messages Sep 15, 2023 BPF

lore
Share & tools
lore

Jiri Olsa

author reviewer
#0 lore raw

PATCH 1/1 bpf: Fix BTF_ID symbol generation

Marcus and Nick reported issue where BTF_ID macro generates same symbol in separate objects and that breaks final vmlinux link.

Adding __LINE__ number suffix to make BTF_ID symbol more unique, which is not real fix, but it would help for now and meanwhile we can work on better solution as suggested by Andrii in [2].

[1] https://github.com/ClangBuiltLinux/linux/issues/1913
[2] https://lore.kernel.org/bpf/ZQQVr35crUtN1quS@krava/T/#m64d7c29c407d6adf0e7b420359958b3aafa7bf69

---
 include/linux/btf_ids.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/btf_ids.h +1 -1
index a3462a9b8e18..a9cb10b0e2e9 100644
@@ -49,7 +49,7 @@ word							\
 	____BTF_ID(symbol, word)
 
 #define __ID(prefix) \
-	__PASTE(prefix, __COUNTER__)
+	__PASTE(__PASTE(prefix, __COUNTER__), __LINE__)
 
 /*
  * The BTF_ID defines unique symbol for each ID pointing
Signature · 1 line
2.41.0
#1 lore raw
Quoted 22 lines · Jiri Olsa

Marcus and Nick reported issue where BTF_ID macro generates same symbol in separate objects and that breaks final vmlinux link.

Adding __LINE__ number suffix to make BTF_ID symbol more unique, which is not real fix, but it would help for now and meanwhile we can work on better solution as suggested by Andrii in [2].

[1] https://github.com/ClangBuiltLinux/linux/issues/1913
[2] https://lore.kernel.org/bpf/ZQQVr35crUtN1quS@krava/T/#m64d7c29c407d6adf0e7b420359958b3aafa7bf69

---
 include/linux/btf_ids.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/btf_ids.h +0 -0
index a3462a9b8e18..a9cb10b0e2e9 100644

include/linux/btf_ids.h word \ · line 52

Quoted 5 lines
include/linux/btf_ids.h +1 -1
@@ -49,7 +49,7 @@ word                                                  \
        ____BTF_ID(symbol, word)
 
 #define __ID(prefix) \
-       __PASTE(prefix, __COUNTER__)
+       __PASTE(__PASTE(prefix, __COUNTER__), __LINE__)

I think __COUNTER__ and __LINE__ both expand to string literals; you can avoid another expansion via __PASTE by just putting them adjacent, like so:
https://github.com/ClangBuiltLinux/linux/issues/1913#issuecomment-1710794319
I'll send that as a v2 and link back to your v1.

Quoted 6 lines
include/linux/btf_ids.h +0 -1
 /*
  * The BTF_ID defines unique symbol for each ID pointing
--

2.41.0

Signature · 2 lines
Thanks,
~Nick Desaulniers
#2 lore raw
Quoted 26 lines · Nick Desaulniers
Quoted 24 lines · Jiri Olsa

Marcus and Nick reported issue where BTF_ID macro generates same symbol in separate objects and that breaks final vmlinux link.

Adding __LINE__ number suffix to make BTF_ID symbol more unique, which is not real fix, but it would help for now and meanwhile we can work on better solution as suggested by Andrii in [2].

[1] https://github.com/ClangBuiltLinux/linux/issues/1913
[2] https://lore.kernel.org/bpf/ZQQVr35crUtN1quS@krava/T/#m64d7c29c407d6adf0e7b420359958b3aafa7bf69

---
 include/linux/btf_ids.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/btf_ids.h +0 -0
index a3462a9b8e18..a9cb10b0e2e9 100644
@@ -49,7 +49,7 @@ word                                                  \
        ____BTF_ID(symbol, word)
 
Quoted 5 lines

include/linux/btf_ids.h word \ · line 52

Quoted 3 lines
include/linux/btf_ids.h +1 -1
 #define __ID(prefix) \
-       __PASTE(prefix, __COUNTER__)
+       __PASTE(__PASTE(prefix, __COUNTER__), __LINE__)

I think __COUNTER__ and __LINE__ both expand to string literals; you

ah, no I was wrong.

But this change needs to go into tools/include/linux/btf_ids.h, too.

I'll wrap that up in my v3.

Quoted 16 lines

can avoid another expansion via __PASTE by just putting them adjacent, like so:
https://github.com/ClangBuiltLinux/linux/issues/1913#issuecomment-1710794319
I'll send that as a v2 and link back to your v1.

Quoted 6 lines
include/linux/btf_ids.h +0 -1
 /*
  * The BTF_ID defines unique symbol for each ID pointing
--

2.41.0

--
Thanks,
~Nick Desaulniers

Signature · 2 lines
Thanks,
~Nick Desaulniers