Go to file
Yonghong Song eb6bd05766 dwarf_loader: Process DW_AT_count in DW_TAG_subrange_type
For array type, gcc and clang generates dwarf info with different tags.  For
example, with existing pahole,

  $ cat test.c
    int a[5][5];
  $ gcc -c -g test.c
  $ llvm-dwarfdump test.o
    ...
    0x0000001d:   DW_TAG_array_type
                  DW_AT_type    (0x0000003a "int")
                  DW_AT_sibling (0x00000033)

    0x00000026:     DW_TAG_subrange_type
                      DW_AT_type        (0x00000033 "long unsigned int")
                      DW_AT_upper_bound (0x04)

    0x0000002c:     DW_TAG_subrange_type
                      DW_AT_type        (0x00000033 "long unsigned int")
                      DW_AT_upper_bound (0x04)
  $ pahole -JV test.o
    [1] ARRAY (anon) type_id=3 index_type_id=3 nr_elems=25
    [2] INT long unsigned int size=8 bit_offset=0 nr_bits=64 encoding=(none)
    [3] INT int size=4 bit_offset=0 nr_bits=32 encoding=SIGNED
  $ clang -c -g test.c
  $ llvm-dwarfdump test.o
    ...
    0x00000033:   DW_TAG_array_type
                    DW_AT_type  (0x00000045 "int")

    0x00000038:     DW_TAG_subrange_type
                      DW_AT_type        (0x0000004c "__ARRAY_SIZE_TYPE__")
                      DW_AT_count       (0x05)

    0x0000003e:     DW_TAG_subrange_type
                      DW_AT_type        (0x0000004c "__ARRAY_SIZE_TYPE__")
                      DW_AT_count       (0x05)
  $ pahole -JV test.o
    [1] ARRAY (anon) type_id=2 index_type_id=2 nr_elems=0
    [2] INT int size=4 bit_offset=0 nr_bits=32 encoding=SIGNED
    [3] INT __ARRAY_SIZE_TYPE__ size=8 bit_offset=0 nr_bits=64 encoding=(none)

Current pahole processed DW_AT_upper_bound under DW_TAG_subrange_type to
get array range, but it did not process DW_AT_count so during pahole
dwarf2btf conversion, the flattened array size is 0.

This patch fixed the issue by processing DW_AT_count properly.
With the change, for clang generated test.o, pahole btf conversion output is:
  $ pahole -JV test.o
    [1] ARRAY (anon) type_id=2 index_type_id=2 nr_elems=25
    [2] INT int size=4 bit_offset=0 nr_bits=32 encoding=SIGNED
    [3] INT __ARRAY_SIZE_TYPE__ size=8 bit_offset=0 nr_bits=64 encoding=(none)

Committer testing:

Before:

  # pahole -C augmented_enter_connect_args augmented_syscalls.bpf.o
  struct augmented_enter_connect_args {
          struct syscall_enter_connect_args args;          /*     0    40 */
          char                       addr[0];              /*    40     0 */

          /* size: 56, cachelines: 1, members: 2 */
          /* padding: 16 */
          /* last cacheline: 56 bytes */
  };
  # file augmented_syscalls.bpf.o
  augmented_syscalls.bpf.o: ELF 64-bit LSB relocatable, *unknown arch 0xf7* version 1 (SYSV), with debug_info, not stripped
  #

After:

  # pahole -C augmented_enter_connect_args augmented_syscalls.bpf.o
  struct augmented_enter_connect_args {
	  struct syscall_enter_connect_args args;          /*     0    40 */
	  char                       addr[14];             /*    40    14 */

	  /* size: 56, cachelines: 1, members: 2 */
	  /* padding: 2 */
	  /* last cacheline: 56 bytes */
  };
  #

Signed-off-by: Yonghong Song <yhs@fb.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Martin KaFai Lau <kafai@fb.com>
Cc: Okash Khawaja <osk@fb.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2018-08-28 12:40:10 -03:00
cmake/modules cmake: Add comments explaining build_id and fedora/rh detection 2009-06-27 13:32:20 -03:00
lib [LICENSE]: Add COPYING file and add missing license info on some files 2007-12-17 14:15:42 -02:00
man-pages man-pages: Add entry for --hex 2017-09-05 10:13:06 -03:00
ostra [OSTRA]: Change ostra-cg license to GPLv2 2007-12-24 12:25:17 -02:00
rpm/SPECS v1.12 - New Release 2018-08-16 16:15:27 -03:00
CMakeLists.txt v1.12 - New Release 2018-08-16 16:15:27 -03:00
COPYING [LICENSE]: Add COPYING file and add missing license info on some files 2007-12-17 14:15:42 -02:00
MANIFEST v1.12 - New Release 2018-08-16 16:15:27 -03:00
NEWS v1.12 - New Release 2018-08-16 16:15:27 -03:00
README [CMAKE]: Make the default install prefix be /usr/local 2007-04-19 18:01:47 -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 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
btf.h btf: Add BTF support 2018-07-25 14:42:06 -03:00
btf_encoder.c btf: Add BTF support 2018-07-25 14:42:06 -03:00
btf_encoder.h btf: Add BTF support 2018-07-25 14:42:06 -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
ctf.h libctf: Use the same coding style as the dwarves 2008-09-25 16:01:26 -03:00
ctf_encoder.c dwarves_fprintf: Fix printf types on 64bit linux 2013-03-20 15:56:38 -03:00
ctf_encoder.h dwarves: Stop using 'self' 2014-01-06 16:46:50 -03:00
ctf_loader.c dwarves: Stop using 'self' 2012-08-17 18:47:15 -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: Add ____ilog2_NaN declaration to silence compiler warning 2016-03-15 11:42:16 -03:00
dwarf_loader.c dwarf_loader: Process DW_AT_count in DW_TAG_subrange_type 2018-08-28 12:40:10 -03:00
dwarves.c dwarves: Fix cus__load_files() success return value 2017-12-14 14:14:56 -03:00
dwarves.h dwarves_fprintf: Find holes on structs embedded in other structs 2016-06-30 16:18:11 -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: Print cacheline boundaries in multiple union members 2018-07-28 14:25:30 -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
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 [DWARVES]: Use a hash table for the tags in a CU 2008-02-11 11:47:17 -02:00
libbtf.c btf: Add BTF support 2018-07-25 14:42:06 -03:00
libbtf.h btf: Add BTF support 2018-07-25 14:42:06 -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
pahole.c btf: Add BTF support 2018-07-25 14:42:06 -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
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

README

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