]> git.baikalelectronics.ru Git - kernel.git/commit
libbpf: Preserve empty DATASEC BTFs during static linking
authorAndrii Nakryiko <andrii@kernel.org>
Fri, 26 Mar 2021 04:30:36 +0000 (21:30 -0700)
committerDaniel Borkmann <daniel@iogearbox.net>
Fri, 26 Mar 2021 16:45:17 +0000 (17:45 +0100)
commit818f1e59ff2c3980cd85a9e73446871bd0a1f29a
tree24c9ede976c5357a23ffab13bf742d2330fb8f6c
parent869556943f2183de5c41a547a1cfc91b01c0ad5a
libbpf: Preserve empty DATASEC BTFs during static linking

Ensure that BPF static linker preserves all DATASEC BTF types, even if some of
them might not have any variable information at all. This may happen if the
compiler promotes local initialized variable contents into .rodata section and
there are no global or static functions in the program.

For example,

  $ cat t.c
  struct t { char a; char b; char c; };
  void bar(struct t*);
  void find() {
     struct t tmp = {1, 2, 3};
     bar(&tmp);
  }

  $ clang -target bpf -O2 -g -S t.c
         .long   104                             # BTF_KIND_DATASEC(id = 8)
         .long   251658240                       # 0xf000000
         .long   0

         .ascii  ".rodata"                       # string offset=104

  $ clang -target bpf -O2 -g -c t.c
  $ readelf -S t.o | grep data
     [ 4] .rodata           PROGBITS         0000000000000000  00000090

Fixes: 6c29b3871bd8 ("libbpf: Add BPF static linker BTF and BTF.ext support")
Reported-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Yonghong Song <yhs@fb.com>
Link: https://lore.kernel.org/bpf/20210326043036.3081011-1-andrii@kernel.org
tools/lib/bpf/linker.c