Go to file
Yonghong Song 2a82d593be btf: Add kind_flag support for btf_loader
For struct/union members, the struct/union type info kind_flag is needed
to calculate correct bitfield_size and bit_offset.

  if (kind_flag) {
    bitfield_size = BTF_MEMBER_BITFIELD_SIZE(member->offset);
    bit_offset = BTF_MEMBER_BIT_OFFSET(member->offset);
  } else {
    bitfield_size = 0;
    bit_offset = member->offset;
  }

Note that bitfield_size and bit_offset will not depend on the member
type. The member type will help calculate correct bitfield_offset,
byte_size, byte_offset, bit_size.

For example, with the fix, we will be able to display
bit offset and bitfield size properly.

  -bash-4.4$ cat t.c
  struct t {
    int a:2;
    int b:3;
    int c:2;
  } g;
  -bash-4.4$ gcc -c -O2 -g t.c
  -bash-4.4$ pahole -JV t.o
  File t.o:
  [1] STRUCT t kind_flag=1 size=4 vlen=3
          a type_id=2 bitfield_size=2 bits_offset=0
          b type_id=2 bitfield_size=3 bits_offset=2
          c type_id=2 bitfield_size=2 bits_offset=5
  [2] INT int size=4 bit_offset=0 nr_bits=32 encoding=SIGNED
  -bash-4.4$ pahole -F btf t.o
  struct t {
          int                        a:2;                  /*     0: 0  4 */
          int                        b:3;                  /*     0: 2  4 */
          int                        c:2;                  /*     0: 5  4 */

          /* size: 4, cachelines: 1, members: 3 */
          /* bit_padding: 25 bits */
          /* last cacheline: 4 bytes */
  };

Note that the above offset showing is different from the below dwarf as
BTF bitfield_offset is always the offset from the start of structure,
kindly like big endian encoding. This may need adjustment to be
conforming to the dwarf dump format.

  -bash-4.4$ pahole -F dwarf t.o
  struct t {
          int                        a:2;                  /*     0:30  4 */
          int                        b:3;                  /*     0:27  4 */
          int                        c:2;                  /*     0:25  4 */

          /* size: 4, cachelines: 1, members: 3 */
          /* bit_padding: 25 bits */
          /* last cacheline: 4 bytes */
  };

Signed-off-by: Yonghong Song <yhs@fb.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexei Starovoitov <ast@fb.com>
Cc: Martin KaFai Lau <kafai@fb.com>
Cc: dwarves@vger.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2018-12-21 09:51:12 -03:00
cmake/modules cmake: Add comments explaining build_id and fedora/rh detection 2009-06-27 13:32:20 -03:00
lib
man-pages man-pages: Add entry for --hex 2017-09-05 10:13:06 -03:00
ostra
rpm/SPECS v1.12 - New Release 2018-08-16 16:15:27 -03:00
btf_encoder.c btf: add func_proto support 2018-12-20 11:33:35 -03:00
btf_encoder.h btf: Allow multiple cu's in dwarf->btf conversion 2018-12-20 10:44:48 -03:00
btf_loader.c btf: Add kind_flag support for btf_loader 2018-12-21 09:51:12 -03:00
btf.h btf: add func_proto support 2018-12-20 11:33:35 -03:00
CMakeLists.txt btf_loader: Introduce a loader for the BTF format 2018-12-20 15:23:35 -03:00
codiff.c dwarves: Support static class data members 2012-08-20 14:42:17 -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
COPYING
ctf_encoder.c dwarves: Rename variable->location to ->scope 2018-09-26 16:45:25 -03:00
ctf_encoder.h dwarves: Stop using 'self' 2014-01-06 16:46:50 -03:00
ctf_loader.c dwarves: Rename variable->location to ->scope 2018-09-26 16:45:25 -03:00
ctf.h libctf: Use the same coding style as the dwarves 2008-09-25 16:01:26 -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: Shorten class__fprintf() sig 2016-06-29 16:19:20 -03:00
dtagnames.c dwarves: Use cus__fprintf_load_files_err() in the remaining tools 2016-03-15 14:29:57 -03:00
dutil.c dwarves: Stop using 'self' 2012-08-17 18:47:15 -03:00
dutil.h dutil: Adopt strstart() from the linux perf tools sources 2018-12-20 14:52:25 -03:00
dwarf_loader.c btf: fix struct/union/fwd types with kind_flag 2018-12-20 11:27:20 -03:00
dwarves_emit.c dwarves: Stop using 'self' 2012-08-17 18:47:15 -03:00
dwarves_emit.h dwarves: Stop using 'self' 2014-01-06 16:46:50 -03:00
dwarves_fprintf.c dwarves_fprintf: Set conf.cachelinep in union__fprintf() too 2018-10-03 10:38:44 -03:00
dwarves_reorganize.c dwarves_fprintf: Shorten class__fprintf() sig 2016-06-29 16:19:20 -03:00
dwarves_reorganize.h dwarves: Stop using 'self' 2014-01-06 16:46:50 -03:00
dwarves.c btf_loader: Introduce a loader for the BTF format 2018-12-20 15:23:35 -03:00
dwarves.h btf: Add kind_flag support for btf_loader 2018-12-21 09:51:12 -03:00
elf_symtab.c dwarves: Stop using 'self' 2012-08-17 18:47:15 -03:00
elf_symtab.h dwarves: Stop using 'self' 2014-01-06 16:46:50 -03:00
elfcreator.c Add scncopy - like object copy but tries not to change section content 2010-01-12 14:23:32 -02:00
elfcreator.h Add scncopy - like object copy but tries not to change section content 2010-01-12 14:23:32 -02:00
gobuffer.c dwarves: Stop using 'self' 2012-08-17 18:47:15 -03:00
gobuffer.h dwarves: Stop using 'self' 2014-01-06 16:46:50 -03:00
hash.h
libbtf.c btf_loader: Introduce a loader for the BTF format 2018-12-20 15:23:35 -03:00
libbtf.h btf_loader: Introduce a loader for the BTF format 2018-12-20 15:23:35 -03:00
libctf.c dwarves: Stop using 'self' 2012-08-17 18:47:15 -03:00
libctf.h dwarves: Stop using 'self' 2014-01-06 16:46:50 -03:00
list.h coding style: remove trailing whitespaces, etc 2009-03-14 13:50:36 -03:00
MANIFEST MANIFEST: Add missing COPYING file 2018-09-11 11:22:41 -03:00
NEWS v1.12 - New Release 2018-08-16 16:15:27 -03:00
pahole.c btf: fix struct/union/fwd types with kind_flag 2018-12-20 11:27:20 -03:00
pdwtags.c dwarves: Update e-mail address 2016-06-28 14:24:41 -03:00
pfunct.c pahole: Search and use running kernel vmlinux when no file is passed 2017-11-24 11:24:16 -03:00
pglobal.c dwarves: Use cus__fprintf_load_files_err() in the remaining tools 2016-03-15 14:29:57 -03:00
prefcnt.c dwarves: Use cus__fprintf_load_files_err() in the remaining tools 2016-03-15 14:29:57 -03:00
rbtree.c dwarves: Add an rbtree for the functions in a cu 2009-06-04 14:56:44 -03:00
rbtree.h dwarves: Add an rbtree for the functions in a cu 2009-06-04 14:56:44 -03:00
README
README.btf README.btf: Add section on validating the .BTF section via the kernel 2018-08-16 12:05:29 -03:00
README.ctracer ctracer: update README.ctracer, f9 has the dwarves 2008-10-29 08:54:53 -02:00
README.DEBUG README.DEBUG: Add an extra step to make the instructions cut'n'exec 2017-12-14 14:15:54 -03:00
regtest regtest: Accept --diff instad of plain 'diff' as long option 2012-05-14 19:36:58 -03:00
scncopy.c scncopy: Fix minor problems with --usage. 2010-01-12 16:37:27 -02:00
strings.c dwarves: Stop using 'self' 2012-08-17 18:47:15 -03:00
strings.h dwarves: Stop using 'self' 2014-01-06 16:46:50 -03:00
syscse.c dwarves: Update e-mail address 2016-06-28 14:24:41 -03:00

Build instructions:

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

Default is to be installed on /usr/local, see rpm spec file for
installing on other places.

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