diff mbox series

[bpf] bpf: Fix BTF_ID symbol generation

Message ID 20230915103228.1196234-1-jolsa@kernel.org (mailing list archive)
State Changes Requested
Delegated to: BPF
Headers show
Series [bpf] bpf: Fix BTF_ID symbol generation | expand

Checks

Context Check Description
bpf/vmtest-bpf-PR success PR summary
bpf/vmtest-bpf-VM_Test-2 success Logs for build for s390x with gcc
bpf/vmtest-bpf-VM_Test-6 success Logs for test_maps on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-8 success Logs for test_maps on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-9 success Logs for test_maps on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-10 success Logs for test_progs on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-12 success Logs for test_progs on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-13 success Logs for test_progs on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-14 success Logs for test_progs_no_alu32 on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-17 success Logs for test_progs_no_alu32 on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-18 success Logs for test_progs_no_alu32_parallel on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-16 success Logs for test_progs_no_alu32 on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-19 success Logs for test_progs_no_alu32_parallel on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-20 success Logs for test_progs_no_alu32_parallel on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-21 success Logs for test_progs_parallel on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-23 success Logs for test_progs_parallel on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-26 success Logs for test_verifier on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-24 success Logs for test_verifier on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-25 success Logs for test_verifier on s390x with gcc
bpf/vmtest-bpf-VM_Test-27 success Logs for test_verifier on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-28 success Logs for veristat
bpf/vmtest-bpf-VM_Test-15 success Logs for test_progs_no_alu32 on s390x with gcc
bpf/vmtest-bpf-VM_Test-11 success Logs for test_progs on s390x with gcc
bpf/vmtest-bpf-VM_Test-22 success Logs for test_progs_parallel on x86_64 with gcc
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for bpf
netdev/fixes_present fail Series targets non-next tree, but doesn't contain any Fixes tags
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 2826 this patch: 2826
netdev/cc_maintainers warning 4 maintainers not CCed: martin.lau@linux.dev kpsingh@kernel.org yonghong.song@linux.dev song@kernel.org
netdev/build_clang success Errors and warnings before: 1517 this patch: 1517
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 2912 this patch: 2912
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 8 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-VM_Test-7 success Logs for test_maps on s390x with gcc
bpf/vmtest-bpf-VM_Test-0 success Logs for ShellCheck
bpf/vmtest-bpf-VM_Test-3 success Logs for build for x86_64 with gcc
bpf/vmtest-bpf-VM_Test-5 success Logs for set-matrix
bpf/vmtest-bpf-VM_Test-4 success Logs for build for x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-1 success Logs for build for aarch64 with gcc

Commit Message

Jiri Olsa Sept. 15, 2023, 10:32 a.m. UTC
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
Reported-by: Marcus Seyfarth <m.seyfarth@gmail.com>
Reported-by: Nick Desaulniers <ndesaulniers@google.com>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 include/linux/btf_ids.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Nick Desaulniers Sept. 15, 2023, 4:25 p.m. UTC | #1
On Fri, Sep 15, 2023 at 3:32 AM Jiri Olsa <jolsa@kernel.org> wrote:
>
> 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
> Reported-by: Marcus Seyfarth <m.seyfarth@gmail.com>
> Reported-by: Nick Desaulniers <ndesaulniers@google.com>
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> ---
>  include/linux/btf_ids.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/include/linux/btf_ids.h b/include/linux/btf_ids.h
> index a3462a9b8e18..a9cb10b0e2e9 100644
> --- a/include/linux/btf_ids.h
> +++ b/include/linux/btf_ids.h
> @@ -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.

>
>  /*
>   * The BTF_ID defines unique symbol for each ID pointing
> --
> 2.41.0
>
Nick Desaulniers Sept. 15, 2023, 5:27 p.m. UTC | #2
On Fri, Sep 15, 2023 at 9:25 AM Nick Desaulniers
<ndesaulniers@google.com> wrote:
>
> On Fri, Sep 15, 2023 at 3:32 AM Jiri Olsa <jolsa@kernel.org> wrote:
> >
> > 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
> > Reported-by: Marcus Seyfarth <m.seyfarth@gmail.com>
> > Reported-by: Nick Desaulniers <ndesaulniers@google.com>
> > Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> > ---
> >  include/linux/btf_ids.h | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/include/linux/btf_ids.h b/include/linux/btf_ids.h
> > index a3462a9b8e18..a9cb10b0e2e9 100644
> > --- a/include/linux/btf_ids.h
> > +++ b/include/linux/btf_ids.h
> > @@ -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

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.

> 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.
>
> >
> >  /*
> >   * The BTF_ID defines unique symbol for each ID pointing
> > --
> > 2.41.0
> >
>
>
> --
> Thanks,
> ~Nick Desaulniers
diff mbox series

Patch

diff --git a/include/linux/btf_ids.h b/include/linux/btf_ids.h
index a3462a9b8e18..a9cb10b0e2e9 100644
--- a/include/linux/btf_ids.h
+++ b/include/linux/btf_ids.h
@@ -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