]> git.proxmox.com Git - mirror_iproute2.git/commit
bpf: check map symbol type properly with newer llvm compiler
authorYonghong Song <yhs@fb.com>
Mon, 29 Oct 2018 22:32:03 +0000 (15:32 -0700)
committerStephen Hemminger <stephen@networkplumber.org>
Wed, 31 Oct 2018 15:27:07 +0000 (08:27 -0700)
commit7a04dd84a7f938f72fcef9efe8383314b0a66274
tree93424059795872e41e369ef6be02135a7479490e
parent00240899ec0b0bb296ee54860802adec3be0d26e
bpf: check map symbol type properly with newer llvm compiler

With llvm 7.0 or earlier, the map symbol type is STT_NOTYPE.
  -bash-4.4$ cat t.c
  __attribute__((section("maps"))) int g;
  -bash-4.4$ clang -target bpf -O2 -c t.c
  -bash-4.4$ readelf -s t.o

  Symbol table '.symtab' contains 2 entries:
     Num:    Value          Size Type    Bind   Vis      Ndx Name
       0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND
       1: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT    3 g

The following llvm commit enables BPF target to generate
proper symbol type and size.
  commit bf6ec206615b9718869d48b4e5400d0c6e3638dd
  Author: Yonghong Song <yhs@fb.com>
  Date:   Wed Sep 19 16:04:13 2018 +0000

      [bpf] Symbol sizes and types in object file

      Clang-compiled object files currently don't include the symbol sizes and
      types.  Some tools however need that information.  For example, ctfconvert
      uses that information to generate FreeBSD's CTF representation from ELF
      files.
      With this patch, symbol sizes and types are included in object files.

Signed-off-by: Paul Chaignon <paul.chaignon@orange.com>
Reported-by: Yutaro Hayakawa <yhayakawa3720@gmail.com>
Hence, for llvm 8.0.0 (currently trunk), symbol type will be not NOTYPE, but OBJECT.
  -bash-4.4$ clang -target bpf -O2 -c t.c
  -bash-4.4$ readelf -s t.o

  Symbol table '.symtab' contains 3 entries:
     Num:    Value          Size Type    Bind   Vis      Ndx Name
       0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND
       1: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS t.c
       2: 0000000000000000     4 OBJECT  GLOBAL DEFAULT    3 g

This patch makes sure bpf library accepts both NOTYPE and OBJECT types
of global map symbols.

Signed-off-by: Yonghong Song <yhs@fb.com>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
lib/bpf.c