Go to file
Yonghong Song d99d551930 btf_encoder: Support btf_type_tag attribute
[$ ~] cat t.c
  #define __tag1 __attribute__((btf_type_tag("tag1")))
  #define __tag2 __attribute__((btf_type_tag("tag2")))
  int __tag1 * __tag1 __tag2 *g __attribute__((section(".data..percpu")));
  [$ ~] clang -O2 -g -c t.c
  [$ ~] pahole -JV t.o
  Found per-CPU symbol 'g' at address 0x0
  Found 1 per-CPU variables!
  File t.o:
  [1] TYPE_TAG tag1 type_id=5
  [2] TYPE_TAG tag2 type_id=1
  [3] PTR (anon) type_id=2
  [4] TYPE_TAG tag1 type_id=6
  [5] PTR (anon) type_id=4
  [6] INT int size=4 nr_bits=32 encoding=SIGNED
  search cu 't.c' for percpu global variables.
  Variable 'g' from CU 't.c' at address 0x0 encoded
  [7] VAR g type=3 linkage=1
  [8] DATASEC .data..percpu size=8 vlen=1
          type=7 offset=0 size=8
  [$ ~]

You can see for the source:

  int __tag1 * __tag1 __tag2 *g __attribute__((section(".data..percpu")));

the following type chain is generated:

  var -> ptr -> tag2 -> tag1 -> ptr -> tag1 -> int

The following shows pahole option "--skip_encoding_btf_type_tag" can be
used to prevent BTF_KIND_TYPE_TAG generation.

  [$ ~] pahole -JV t.o --skip_encoding_btf_type_tag
  Found per-CPU symbol 'g' at address 0x0
  Found 1 per-CPU variables!
  File t.o:
  [1] PTR (anon) type_id=2
  [2] PTR (anon) type_id=3
  [3] INT int size=4 nr_bits=32 encoding=SIGNED
  search cu 't.c' for percpu global variables.
  Variable 'g' from CU 't.c' at address 0x0 encoded
  [4] VAR g type=1 linkage=1
  [5] DATASEC .data..percpu size=8 vlen=1
          type=4 offset=0 size=8
  [$ ~]

Committer testing:

  $ rm -f t.o; clang -O2 -g -c t.c
  $ llvm-dwarfdump t.o
  t.o:	file format elf64-x86-64

  .debug_info contents:
  0x00000000: Compile Unit: length = 0x0000005e, format = DWARF32, version = 0x0004, abbr_offset = 0x0000, addr_size = 0x08 (next unit at 0x00000062)

  0x0000000b: DW_TAG_compile_unit
                DW_AT_producer	("clang version 14.0.0 (https://github.com/llvm/llvm-project 0d3add216f04b99ed1db1a05c39975d4a9c83e6b)")
                DW_AT_language	(DW_LANG_C99)
                DW_AT_name	("t.c")
                DW_AT_stmt_list	(0x00000000)
                DW_AT_comp_dir	("/var/home/acme/git/pahole")

  0x0000001e:   DW_TAG_variable
                  DW_AT_name	("g")
                  DW_AT_type	(0x00000033 "int **")
                  DW_AT_external	(true)
                  DW_AT_decl_file	("/var/home/acme/git/pahole/t.c")
                  DW_AT_decl_line	(3)
                  DW_AT_location	(DW_OP_addr 0x0)

  0x00000033:   DW_TAG_pointer_type
                  DW_AT_type	(0x0000004b "int *")

  0x00000038:     DW_TAG_LLVM_annotation
                    DW_AT_name	("btf_type_tag")
                    DW_AT_const_value	("tag1")

  0x00000041:     DW_TAG_LLVM_annotation
                    DW_AT_name	("btf_type_tag")
                    DW_AT_const_value	("tag2")

  0x0000004a:     NULL

  0x0000004b:   DW_TAG_pointer_type
                  DW_AT_type	(0x0000005a "int")

  0x00000050:     DW_TAG_LLVM_annotation
                    DW_AT_name	("btf_type_tag")
                    DW_AT_const_value	("tag1")

  0x00000059:     NULL

  0x0000005a:   DW_TAG_base_type
                  DW_AT_name	("int")
                  DW_AT_encoding	(DW_ATE_signed)
                  DW_AT_byte_size	(0x04)

  0x00000061:   NULL
  $ pahole -JV t.o
  Found per-CPU symbol 'g' at address 0x0
  Found 1 per-CPU variables!
  File t.o:
  [1] TYPE_TAG tag1 type_id=5
  [2] TYPE_TAG tag2 type_id=1
  [3] PTR (anon) type_id=2
  [4] TYPE_TAG tag1 type_id=6
  [5] PTR (anon) type_id=4
  [6] INT int size=4 nr_bits=32 encoding=SIGNED
  search cu 't.c' for percpu global variables.
  Variable 'g' from CU 't.c' at address 0x0 encoded
  [7] VAR g type=3 linkage=1
  [8] DATASEC .data..percpu size=8 vlen=1
  	type=7 offset=0 size=8
  ⬢[acme@toolbox pahole]$ pahole -JV t.o --skip_encoding_btf_type_tag
  Found per-CPU symbol 'g' at address 0x0
  Found 1 per-CPU variables!
  File t.o:
  [1] PTR (anon) type_id=2
  [2] PTR (anon) type_id=3
  [3] INT int size=4 nr_bits=32 encoding=SIGNED
  search cu 't.c' for percpu global variables.
  Variable 'g' from CU 't.c' at address 0x0 encoded
  [4] VAR g type=1 linkage=1
  [5] DATASEC .data..percpu size=8 vlen=1
  	type=4 offset=0 size=8
  $

Signed-off-by: Yonghong Song <yhs@fb.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Acked-by: Andrii Nakryiko <andrii@kernel.org>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: bpf@vger.kernel.org
Cc: dwarves@vger.kernel.org
Cc: kernel-team@fb.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-11-23 20:37:58 -03:00
cmake/modules cmake: Add a module to find if obstack is in a separate library 2021-08-20 16:40:27 -03:00
lib libbpf: Sync with latest libbpf repo to pick support for BTF_KIND_TYPE_TAG 2021-11-23 20:37:35 -03:00
man-pages man pages: Add missing --skip_encoding_btf_decl_tag entry 2021-11-23 20:37:58 -03:00
ostra ostra: Initial python3 conversion 2019-04-23 12:02:22 -03:00
rpm/SPECS pahole: Prep 1.22 2021-08-23 09:48:58 -03:00
.gitignore pahole: Add build dir, config.h to .gitignore 2019-02-11 12:55:46 -03:00
.gitmodules pahole: add libbpf as submodule under lib/bpf 2019-02-11 12:56:40 -03:00
CMakeLists.txt CMakeList.txt: Don't download libbpf source when system library is used 2021-09-27 17:04:53 -03:00
COPYING [LICENSE]: Add COPYING file and add missing license info on some files 2007-12-17 14:15:42 -02:00
MANIFEST pahole: Prep 1.22 2021-08-23 09:48:58 -03:00
NEWS pahole: Prep 1.22 2021-08-23 09:48:58 -03:00
README README: Add documentation for -DBUILD_SHARED_LIBS 2021-06-10 14:31:44 -03:00
README.DEBUG README.DEBUG: Add an extra step to make the instructions cut'n'exec 2017-12-14 14:15:54 -03:00
README.btf v1.13: New release 2019-04-16 16:13:19 -03:00
README.cross README: Add instructions to do a cross build 2020-08-17 09:52:02 -03:00
README.ctracer ctracer: update README.ctracer, f9 has the dwarves 2008-10-29 08:54:53 -02:00
README.tarball README.tarball: Overcome --transform problem with symlinks 2021-08-20 16:40:27 -03:00
btf_encoder.c btf_encoder: Support btf_type_tag attribute 2021-11-23 20:37:58 -03:00
btf_encoder.h btf_encoder: Add methods to maintain a list of btf encoders 2021-08-20 16:40:27 -03:00
btf_loader.c btf_loader: Use cacheline size to infer alignment 2021-10-28 10:22:17 -03:00
btfdiff btfdiff: Suppress alignment tags with BTF as well as with DWARF 2021-10-28 09:37:26 -03:00
buildcmd.sh buildcmd.sh: Add single build script for use in CI 2021-08-20 16:40:27 -03:00
changes-v1.13 v1.13: New release 2019-04-16 16:13:19 -03:00
changes-v1.16 dwarves: Prep v1.16 2019-12-16 11:43:53 -03:00
changes-v1.17 dwarves: Prep v1.17 2020-03-13 16:36:02 -03:00
changes-v1.18 dwarves: Prep v1.18 2020-10-02 17:29:59 -03:00
changes-v1.19 dwarves: Prep v1.19 2020-11-23 09:52:44 -03:00
changes-v1.20 pahole: Prep 1.20 2021-02-03 21:45:01 -03:00
changes-v1.21 pahole: Prep 1.21 2021-04-09 19:39:15 -03:00
changes-v1.22 pahole: Prep 1.22 2021-08-23 09:48:58 -03:00
codiff.c dwarves_fprintf: Move cacheline_size into struct conf_fprintf 2021-10-28 10:17:59 -03:00
config.h.cmake [DWARVES] Fixes a FIXME relating to a missing elf (libdw) symbol check. 2008-02-12 21:08:49 -02:00
ctf.h Adopt SPDX-License-Identifier 2019-01-18 15:41:48 -03:00
ctf_encoder.c strings: use BTF's string APIs for strings management 2020-10-20 17:17:51 -03:00
ctf_encoder.h Adopt SPDX-License-Identifier 2019-01-18 15:41:48 -03:00
ctf_loader.c core: Use obstacks: take 2 2021-08-20 16:40:27 -03:00
ctfdwdiff ctfdwdiff: Don't ask for variables and inline expansions in pfunct 2009-03-31 19:21:46 -03:00
ctracer.c dwarves_fprintf: Move cacheline_size into struct conf_fprintf 2021-10-28 10:17:59 -03:00
dtagnames.c dwarves_fprintf: Move cacheline_size into struct conf_fprintf 2021-10-28 10:17:59 -03:00
dutil.c dutil: elf_symtab__new() doesn't need the GElf_Ehdr *ep argument 2021-08-20 16:40:27 -03:00
dutil.h dutil: Move DW_TAG_LLVM_annotation definition to dutil.h 2021-11-23 20:37:43 -03:00
dwarf_loader.c dwarf_loader: Support btf_type_tag attribute 2021-11-23 20:37:51 -03:00
dwarves.c dwarves_fprintf: Move cacheline_size into struct conf_fprintf 2021-10-28 10:17:59 -03:00
dwarves.h btf_encoder: Support btf_type_tag attribute 2021-11-23 20:37:58 -03:00
dwarves_emit.c core: enumeration__emit_definitions() doesn't need a 'cu' argument 2021-08-12 09:39:46 -03:00
dwarves_emit.h emit: type__emit_fwd_decl() isn't used outside emit.c, make it static 2021-08-12 09:39:46 -03:00
dwarves_fprintf.c fprintf: Add DWARF5 tags added in elfutils 0.170 2021-11-12 15:16:51 -03:00
dwarves_reorganize.c core: base_type__name() doesn't need a 'cu' arg 2021-08-12 09:41:13 -03:00
dwarves_reorganize.h Adopt SPDX-License-Identifier 2019-01-18 15:41:48 -03:00
elf_symtab.c elf_symtab: Remove needless GElf_Ehdr pointer argument from the constructor 2021-08-20 16:40:27 -03:00
elf_symtab.h elf_symtab: Remove needless GElf_Ehdr pointer argument from the constructor 2021-08-20 16:40:27 -03:00
elfcreator.c elfcreator: elfcreator_copy_scn() doesn't need the 'elf' arg 2021-08-20 16:40:27 -03:00
elfcreator.h elfcreator: elfcreator_copy_scn() doesn't need the 'elf' arg 2021-08-20 16:40:27 -03:00
fullcircle v1.13: New release 2019-04-16 16:13:19 -03:00
gobuffer.c gobuffer: Use zfree() and make delete accept NULL, like free() 2021-05-27 11:00:18 -03:00
gobuffer.h Adopt SPDX-License-Identifier 2019-01-18 15:41:48 -03:00
hash.h hash: Remove unused hash_32(), hash_ptr() 2021-08-20 16:40:27 -03:00
libctf.c elf_symtab: Remove needless GElf_Ehdr pointer argument from the constructor 2021-08-20 16:40:27 -03:00
libctf.h strings: use BTF's string APIs for strings management 2020-10-20 17:17:51 -03:00
list.h list: Adopt list_next_entry() from the Linux kernel 2021-08-20 16:40:27 -03:00
pahole.c dwarf_loader: Support btf_type_tag attribute 2021-11-23 20:37:51 -03:00
pdwtags.c dwarves_fprintf: Move cacheline_size into struct conf_fprintf 2021-10-28 10:17:59 -03:00
pfunct.c dwarves_fprintf: Move cacheline_size into struct conf_fprintf 2021-10-28 10:17:59 -03:00
pglobal.c dwarves_fprintf: Move cacheline_size into struct conf_fprintf 2021-10-28 10:17:59 -03:00
prefcnt.c dwarves_fprintf: Move cacheline_size into struct conf_fprintf 2021-10-28 10:17:59 -03:00
rbtree.c Adopt SPDX-License-Identifier 2019-01-18 15:41:48 -03:00
rbtree.h Adopt SPDX-License-Identifier 2019-01-18 15:41:48 -03:00
regtest regtest: Accept --diff instad of plain 'diff' as long option 2012-05-14 19:36:58 -03:00
scncopy.c elfcreator: elfcreator_copy_scn() doesn't need the 'elf' arg 2021-08-20 16:40:27 -03:00
syscse.c syscse: zero_extend() doesn't need a 'cu' arg 2021-08-20 16:40:27 -03:00

README

Build instructions:

1. install cmake
2. mkdir build
3. cd build
4. cmake -D__LIB=lib ..
5. make install

cmake Options:
  -DBUILD_SHARED_LIBS
    By default SHARED libraries are created and applications are linked to it.
    Use -DBUILD_SHARED_LIBS=OFF while invoking cmake to create STATIC libraries
    and link applications to it.

    Ex. cmake -D__LIB=lib -DBUILD_SHARED_LIBS=OFF ..

  -DCMAKE_INSTALL_PREFIX
    Default is to install to /usr/local, use -DCMAKE_INSTALL_PREFIX=
    when invoking cmake to specify another install location.

Known to work scenarios:

Mandriva Cooker:

cmake 2.4.5-1mdv2007.1
libelfutils1-devel 0.123-1mdv2007.1

Debian Unstable:

cmake 2.4.5-1
libdw-dev 0.123-2

Fedora Core 6:

cmake 2.4.5-2.fc6
elfutils-devel 0.126-1.fc6