libbpf / bpftool

Automated upstream mirror for bpftool stand-alone build.
Other
377 stars 69 forks source link

fix CLANG_BPF_CO_RE_PROBE_CMD #125

Closed lavenderfly closed 9 months ago

lavenderfly commented 9 months ago

When global variables are not initialized, the original command will get incorrect results in some versions of clang environment.

Take clang 10 as an example:

clang -v
clang version 10.0.1 (kylin 10.0.1-4.p01.ky10 119f3e344eeeca8114341787f19862d28a85f6ad)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/7.3.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.3.0
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/7.3.0
Candidate multilib: .;@m64
Selected multilib: .;@m64

Not initialized (current code):

[root@localhost src]# printf '%s\n' 'struct s { int i; } __attribute__((preserve_access_index)); struct s foo;' |     clang -g -target bpf -S -o - -x c - | grep BTF_KIND_
    .long   1                       # BTF_KIND_STRUCT(id = 1)
    .long   5                       # BTF_KIND_INT(id = 2)

Initialized (new code):

[root@localhost src]# printf '%s\n' 'struct s { int i; } __attribute__((preserve_access_index)); struct s foo={};' |     clang -g -target bpf -S -o - -x c - | grep BTF_KIND_
    .long   1                       # BTF_KIND_STRUCT(id = 1)
    .long   5                       # BTF_KIND_INT(id = 2)
    .long   9                       # BTF_KIND_VAR(id = 3)
    .long   13                      # BTF_KIND_DATASEC(id = 4)

This difference will affect the checking of clang-bpf-core features.

[root@localhost src]# make
...                        libbfd: [ on  ]
...               clang-bpf-co-re: [ OFF ]
...                          llvm: [ on  ]
...                        libcap: [ on  ]

This part of the code looks like this in the kernel:

struct test {
    int a;
    int b;
} __attribute__((preserve_access_index));
volatile struct test global_value_for_test = {};

This problem may only occur here.

lavenderfly commented 9 months ago

14 may be related to this PR

lavenderfly commented 9 months ago

Can you please just update your commit title to prefix it with mirror:? This helps filter commits that are added directly to the mirror repo from those that come from sync-ups with the kernel tree. Ideally, could you also wrap your commit description on 72 characters, please?

This commit still fails the check, can you give me more suggestions? For example, does "mirror:" have to be followed by a space?

lavenderfly commented 9 months ago

Sorry, I wasn't clear enough, can you please add a space after the prefix?

And the initial description was good, it explained better why the change is needed. Here's what I meant:

mirror: Fix CLANG_BPF_CO_RE_PROBE_CMD 

When global variables are not initialized, the original command will get
incorrect results in some versions of clang environment.

Signed-off-by: ...

thanks for your patient explanation