2023-09-15 23:28:35

by Nick Desaulniers

[permalink] [raw]
Subject: [PATCH v2] bpf: Fix BTF_ID symbol generation collision

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

ld.lld: error: ld-temp.o <inline asm>:14577:1: symbol
'__BTF_ID__struct__cgroup__624' is already defined

This can be triggered under specific configs when __COUNTER__ happens to
be the same for the same symbol in two different translation units,
which is already quite unlikely to happen.

Add __LINE__ number suffix to make BTF_ID symbol more unique, which is
not a complete fix, but it would help for now and meanwhile we can work
on better solution as suggested by Andrii.

Cc: [email protected]
Reported-by: Satya Durga Srinivasu Prabhala <[email protected]>
Reported-by: Marcus Seyfarth <[email protected]>
Closes: https://github.com/ClangBuiltLinux/linux/issues/1913
Tested-by: Marcus Seyfarth <[email protected]>
Debugged-by: Nathan Chancellor <[email protected]>
Co-developed-by: Jiri Olsa <[email protected]>
Link: https://lore.kernel.org/bpf/CAEf4Bzb5KQ2_LmhN769ifMeSJaWfebccUasQOfQKaOd0nQ51tw@mail.gmail.com/
Signed-off-by: Nick Desaulniers <[email protected]>
---
tools/include/linux/btf_ids.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/include/linux/btf_ids.h b/tools/include/linux/btf_ids.h
index 71e54b1e3796..30e920b96a18 100644
--- a/tools/include/linux/btf_ids.h
+++ b/tools/include/linux/btf_ids.h
@@ -38,7 +38,7 @@ asm( \
____BTF_ID(symbol)

#define __ID(prefix) \
- __PASTE(prefix, __COUNTER__)
+ __PASTE(prefix, __COUNTER__ __LINE__)

/*
* The BTF_ID defines unique symbol for each ID pointing

---
base-commit: 9fdfb15a3dbf818e06be514f4abbfc071004cbe7
change-id: 20230915-bpf_collision-36889a391d44

Best regards,
--
Nick Desaulniers <[email protected]>


2023-09-16 06:07:02

by Nick Desaulniers

[permalink] [raw]
Subject: Re: [PATCH v2] bpf: Fix BTF_ID symbol generation collision

On Fri, Sep 15, 2023 at 10:33 AM Nick Desaulniers
<[email protected]> wrote:
>
> On Fri, Sep 15, 2023 at 10:28 AM Alexei Starovoitov
> <[email protected]> wrote:
> >
> > And please use [PATCH bpf v3] in subject, so that BPF CI can test it properly.
>
> Testing `b4 prep --set-prefixes "PATCH bpf "`

Ah, should just be "bpf" for --set-prefixes (fixed before sending v3).


--
Thanks,
~Nick Desaulniers