Commit Graph

118 Commits

Author SHA1 Message Date
Arnaldo Carvalho de Melo d348b37ed1 btf_encoder: Reduce the size of encode_cu() by moving var encoding to separate method
Just to make code more manageable, no change intended.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-15 15:07:41 -03:00
Arnaldo Carvalho de Melo f62196d3be btf_encoder: No need to set the endianness twice when encoding into an ELF file
We do it already at the constructor.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-14 18:53:35 -03:00
Arnaldo Carvalho de Melo 819f83bd97 btf_encoder: Pass detached_filename to the constructor
The ->filename only points out to the ELF file when we're not writing to
a raw, detached BTF file, so reuse it to store the detached filename
when using that mode.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-14 18:53:35 -03:00
Arnaldo Carvalho de Melo 7ed4ddc468 btf_encoder: Adopt writing to raw file method
To stop using the btf__ namespace.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-14 18:53:35 -03:00
Arnaldo Carvalho de Melo 1498094d33 btf_encoder: Rename btf__encode_in_elf to btf_encoder__write_elf, shortening function signature
We were passing two 'btf_encoder' fields, so pass just the btf_encoder
instance. Ditch the unused 'flags' arg.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-14 18:53:35 -03:00
Arnaldo Carvalho de Melo cd2b8978c4 btf_encoder: Combine btf__write_elf() with btf__encode_in_elf()
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-14 18:53:35 -03:00
Arnaldo Carvalho de Melo 18a3e9711c btf_encoder: Move duplicate code to btf_encoder__encode()
Out of the raw and ELF output routines.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-14 18:53:35 -03:00
Arnaldo Carvalho de Melo 9eb3d7a29d btf_encoder: Pass the 'skip_encoding_vars' to the constructor
Instead of repeatedly passing it to btf_encoder__encode_cu().

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-14 18:53:35 -03:00
Arnaldo Carvalho de Melo 707101ec38 btf_encoder: No need to export the 'struct btf_definition', make it opaque
Only in btf_encoder.c we use its fields, so move everything there.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-14 18:53:35 -03:00
Luca Boccassi ae2581647e libbpf: Allow to use packaged version
Add a new CMake option, LIBBPF_EMBEDDED, to switch between the embedded
version and the system version (searched via pkg-config) of libbpf. Set
the embedded version as the default.

Committer testing:

The default build works as before:

  ⬢[acme@toolbox pahole]$ rm -rf build ; mkdir build ; cd build ; cmake -DCMAKE_BUILD_TYPE=Release .. ; cd ..
  -- The C compiler identification is GNU 11.1.1
  -- Detecting C compiler ABI info
  -- Detecting C compiler ABI info - done
  -- Check for working C compiler: /usr/bin/cc - skipped
  -- Detecting C compile features
  -- Detecting C compile features - done
  -- Checking availability of DWARF and ELF development libraries
  -- Looking for dwfl_module_build_id in elf
  -- Looking for dwfl_module_build_id in elf - found
  -- Found dwarf.h header: /usr/include
  -- Found elfutils/libdw.h header: /usr/include
  -- Found libdw library: /usr/lib64/libdw.so
  -- Found libelf library: /usr/lib64/libelf.so
  -- Checking availability of DWARF and ELF development libraries - done
  -- Found ZLIB: /usr/lib64/libz.so (found version "1.2.11")
  -- Submodule update
  -- Submodule update - done
  -- Performing Test HAVE_REALLOCARRAY_SUPPORT
  -- Performing Test HAVE_REALLOCARRAY_SUPPORT - Success
  -- Configuring done
  -- Generating done
  -- Build files have been written to: /var/home/acme/git/pahole/build
  ⬢[acme@toolbox pahole]$ make -j28 -C build
  make: Entering directory '/var/home/acme/git/pahole/build'
  make[1]: Entering directory '/var/home/acme/git/pahole/build'
  make[2]: Entering directory '/var/home/acme/git/pahole/build'
  Scanning dependencies of target bpf
  make[2]: Leaving directory '/var/home/acme/git/pahole/build'
  make[2]: Entering directory '/var/home/acme/git/pahole/build'
  [  5%] Building C object CMakeFiles/bpf.dir/lib/bpf/src/btf.c.o
  [  5%] Building C object CMakeFiles/bpf.dir/lib/bpf/src/bpf_prog_linfo.c.o
  [  5%] Building C object CMakeFiles/bpf.dir/lib/bpf/src/bpf.c.o
  [  7%] Building C object CMakeFiles/bpf.dir/lib/bpf/src/libbpf_errno.c.o
  <SNIP>
  make[2]: Leaving directory '/var/home/acme/git/pahole/build'
  [ 98%] Built target ctracer
  [100%] Linking C executable pahole
  make[2]: Leaving directory '/var/home/acme/git/pahole/build'
  [100%] Built target pahole
  make[1]: Leaving directory '/var/home/acme/git/pahole/build'
  make: Leaving directory '/var/home/acme/git/pahole/build'
  ⬢[acme@toolbox pahole]$ ldd build/pahole
  	linux-vdso.so.1 (0x00007ffcf4d92000)
  	libdwarves_reorganize.so.1 => /var/home/acme/git/pahole/build/libdwarves_reorganize.so.1 (0x00007f059c289000)
  	libdwarves.so.1 => /var/home/acme/git/pahole/build/libdwarves.so.1 (0x00007f059c226000)
  	libdw.so.1 => /lib64/libdw.so.1 (0x00007f059c186000)
  	libelf.so.1 => /lib64/libelf.so.1 (0x00007f059c16b000)
  	libz.so.1 => /lib64/libz.so.1 (0x00007f059c151000)
  	libc.so.6 => /lib64/libc.so.6 (0x00007f059bf82000)
  	libdl.so.2 => /lib64/libdl.so.2 (0x00007f059bf79000)
  	libzstd.so.1 => /lib64/libzstd.so.1 (0x00007f059be83000)
  	liblzma.so.5 => /lib64/liblzma.so.5 (0x00007f059be57000)
  	libbz2.so.1 => /lib64/libbz2.so.1 (0x00007f059be44000)
  	libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f059be23000)
  	/lib64/ld-linux-x86-64.so.2 (0x00007f059c290000)
  ⬢[acme@toolbox pahole]$

Then, trying to use the libbpf-devel present in Fedora 34:

  ⬢[acme@toolbox pahole]$ rm -rf build ; mkdir build ; cd build ; cmake -DCMAKE_BUILD_TYPE=Release -DLIBBPF_EMBEDDED=Off .. ; cd ..
  -- The C compiler identification is GNU 11.1.1
  -- Detecting C compiler ABI info
  -- Detecting C compiler ABI info - done
  -- Check for working C compiler: /usr/bin/cc - skipped
  -- Detecting C compile features
  -- Detecting C compile features - done
  -- Found PkgConfig: /usr/bin/pkg-config (found version "1.7.3")
  -- Checking for module 'libbpf>=0.3.0'
  --   Found libbpf, version 0.3.0
  -- Checking availability of DWARF and ELF development libraries
  -- Looking for dwfl_module_build_id in elf
  -- Looking for dwfl_module_build_id in elf - found
  -- Found dwarf.h header: /usr/include
  -- Found elfutils/libdw.h header: /usr/include
  -- Found libdw library: /usr/lib64/libdw.so
  -- Found libelf library: /usr/lib64/libelf.so
  -- Checking availability of DWARF and ELF development libraries - done
  -- Found ZLIB: /usr/lib64/libz.so (found version "1.2.11")
  -- Submodule update
  -- Submodule update - done
  -- Performing Test HAVE_REALLOCARRAY_SUPPORT
  -- Performing Test HAVE_REALLOCARRAY_SUPPORT - Success
  -- Configuring done
  -- Generating done
  -- Build files have been written to: /var/home/acme/git/pahole/build
  ⬢[acme@toolbox pahole]$ m
  make: Entering directory '/var/home/acme/git/pahole/build'
  make[1]: Entering directory '/var/home/acme/git/pahole/build'
  make[2]: Entering directory '/var/home/acme/git/pahole/build'
  Scanning dependencies of target dwarves
  make[2]: Leaving directory '/var/home/acme/git/pahole/build'
  make[2]: Entering directory '/var/home/acme/git/pahole/build'
  [  2%] Building C object CMakeFiles/dwarves.dir/dwarves.c.o
  [  5%] Building C object CMakeFiles/dwarves.dir/dwarves_fprintf.c.o
  [  7%] Building C object CMakeFiles/dwarves.dir/gobuffer.c.o
  <SNIP>
  [ 33%] Building C object CMakeFiles/dwarves.dir/rbtree.c.o
  /var/home/acme/git/pahole/btf_encoder.c:84:10: error: ‘BTF_KIND_FLOAT’ undeclared here (not in a function); did you mean ‘BTF_KIND_INT’?
     84 |         [BTF_KIND_FLOAT]        = "FLOAT",
        |          ^~~~~~~~~~~~~~
        |          BTF_KIND_INT
  /var/home/acme/git/pahole/btf_encoder.c:84:10: error: array index in initializer not of integer type
  /var/home/acme/git/pahole/btf_encoder.c:84:10: note: (near initialization for ‘btf_kind_str’)
  /var/home/acme/git/pahole/btf_encoder.c:84:35: warning: excess elements in array initializer
     84 |         [BTF_KIND_FLOAT]        = "FLOAT",
        |                                   ^~~~~~~
  /var/home/acme/git/pahole/btf_encoder.c:84:35: note: (near initialization for ‘btf_kind_str’)
  /var/home/acme/git/pahole/btf_encoder.c: In function ‘btf_encoder__add_float’:
  /var/home/acme/git/pahole/btf_encoder.c:224:22: warning: implicit declaration of function ‘btf__add_float’; did you mean ‘btf__add_var’? [-Wimplicit-function-declaration]
    224 |         int32_t id = btf__add_float(encoder->btf, name, BITS_ROUNDUP_BYTES(bt->bit_size));
        |                      ^~~~~~~~~~~~~~
        |                      btf__add_var
  /var/home/acme/git/pahole/btf_loader.c: In function ‘btf__load_types’:
  /var/home/acme/git/pahole/btf_loader.c:455:22: error: ‘BTF_KIND_FLOAT’ undeclared (first use in this function); did you mean ‘BTF_KIND_INT’?
    455 |                 case BTF_KIND_FLOAT:
        |                      ^~~~~~~~~~~~~~
        |                      BTF_KIND_INT
  /var/home/acme/git/pahole/btf_loader.c:455:22: note: each undeclared identifier is reported only once for each function it appears in
  make[2]: *** [CMakeFiles/dwarves.dir/build.make:173: CMakeFiles/dwarves.dir/btf_encoder.c.o] Error 1
  make[2]: *** Waiting for unfinished jobs....
  make[2]: *** [CMakeFiles/dwarves.dir/build.make:186: CMakeFiles/dwarves.dir/btf_loader.c.o] Error 1
  make[2]: Leaving directory '/var/home/acme/git/pahole/build'
  make[1]: *** [CMakeFiles/Makefile2:173: CMakeFiles/dwarves.dir/all] Error 2
  make[1]: Leaving directory '/var/home/acme/git/pahole/build'
  make: *** [Makefile:149: all] Error 2
  make: Leaving directory '/var/home/acme/git/pahole/build'
  ⬢[acme@toolbox pahole]$

It doesn't build as libbpf is old and doesn't have support for
BTF_KIND_FLOAT.

Signed-off-by: Luca Boccassi <bluca@debian.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: dwarves@vger.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-09 13:34:18 -03:00
Arnaldo Carvalho de Melo 743f2536d8 btf_encoder: Move libbtf.c to btf_encoder.c, the only user of its functions
All those functions now operate on a 'struct btf_encoder' object, there
is no need to make them visible outside the btf_encoder.c source file,
so move them all there and make them static.

This leads to some savings as the compiler is free to optimize further,
inlining stuff used in just one place, etc:

Before, for encoding then reading we have:

  ⬢[acme@toolbox pahole]$ rm -f vmlinux.btf ; perf stat -r5 pahole -j vmlinux.btf vmlinux && perf stat -r5 btfdiff vmlinux vmlinux.btf

   Performance counter stats for 'pahole -j vmlinux.btf vmlinux' (5 runs):

            8,546.56 msec task-clock:u              #    0.989 CPUs utilized            ( +-  0.71% )
                   0      context-switches:u        #    0.000 /sec
                   0      cpu-migrations:u          #    0.000 /sec
             775,699      page-faults:u             #   89.802 K/sec                    ( +-  0.00% )
      34,082,471,148      cycles:u                  #    3.946 GHz                      ( +-  0.22% )  (83.33%)
         636,039,662      stalled-cycles-frontend:u #    1.87% frontend cycles idle     ( +-  1.69% )  (83.33%)
       4,895,524,778      stalled-cycles-backend:u  #   14.38% backend cycles idle      ( +-  2.10% )  (83.33%)
      77,379,632,646      instructions:u            #    2.27  insn per cycle
                                                    #    0.07  stalled cycles per insn  ( +-  0.04% )  (83.33%)
      18,185,560,802      branches:u                #    2.105 G/sec                    ( +-  0.03% )  (83.34%)
         149,715,849      branch-misses:u           #    0.82% of all branches          ( +-  0.15% )  (83.34%)

              8.6412 +- 0.0612 seconds time elapsed  ( +-  0.71% )

   Performance counter stats for 'btfdiff vmlinux vmlinux.btf' (5 runs):

            7,168.97 msec task-clock:u              #    1.016 CPUs utilized            ( +-  0.50% )
                   0      context-switches:u        #    0.000 /sec
                   0      cpu-migrations:u          #    0.000 /sec
             727,965      page-faults:u             #  103.257 K/sec                    ( +-  0.00% )
      27,339,019,686      cycles:u                  #    3.878 GHz                      ( +-  0.17% )  (83.28%)
         511,689,773      stalled-cycles-frontend:u #    1.88% frontend cycles idle     ( +-  1.84% )  (83.34%)
       3,677,090,126      stalled-cycles-backend:u  #   13.53% backend cycles idle      ( +-  1.47% )  (83.35%)
      66,182,032,226      instructions:u            #    2.44  insn per cycle
                                                    #    0.06  stalled cycles per insn  ( +-  0.02% )  (83.35%)
      15,747,149,247      branches:u                #    2.234 G/sec                    ( +-  0.02% )  (83.36%)
          98,013,024      branch-misses:u           #    0.62% of all branches          ( +-  0.21% )  (83.33%)

              7.0554 +- 0.0357 seconds time elapsed  ( +-  0.51% )

  ⬢[acme@toolbox pahole]$

Then, with this patch:

  ⬢[acme@toolbox pahole]$ rm -f vmlinux.btf ; perf stat -r5 pahole -j vmlinux.btf vmlinux && perf stat -r5 btfdiff vmlinux vmlinux.btf

   Performance counter stats for 'pahole -j vmlinux.btf vmlinux' (5 runs):

            8,280.48 msec task-clock:u              #    0.975 CPUs utilized            ( +-  0.72% )
                   0      context-switches:u        #    0.000 /sec
                   0      cpu-migrations:u          #    0.000 /sec
             775,699      page-faults:u             #   91.481 K/sec                    ( +-  0.00% )
      33,265,078,702      cycles:u                  #    3.923 GHz                      ( +-  0.32% )  (83.32%)
         725,690,346      stalled-cycles-frontend:u #    2.16% frontend cycles idle     ( +-  1.76% )  (83.34%)
       4,803,211,469      stalled-cycles-backend:u  #   14.33% backend cycles idle      ( +-  2.43% )  (83.34%)
      77,162,277,929      instructions:u            #    2.30  insn per cycle
                                                    #    0.07  stalled cycles per insn  ( +-  0.06% )  (83.34%)
      18,139,715,894      branches:u                #    2.139 G/sec                    ( +-  0.03% )  (83.34%)
         149,609,552      branch-misses:u           #    0.82% of all branches          ( +-  0.16% )  (83.33%)

              8.4921 +- 0.0630 seconds time elapsed  ( +-  0.74% )

   Performance counter stats for 'btfdiff vmlinux vmlinux.btf' (5 runs):

            7,018.11 msec task-clock:u              #    1.013 CPUs utilized            ( +-  0.68% )
                   0      context-switches:u        #    0.000 /sec
                   0      cpu-migrations:u          #    0.000 /sec
             727,949      page-faults:u             #  105.207 K/sec                    ( +-  0.00% )
      26,632,191,985      cycles:u                  #    3.849 GHz                      ( +-  0.31% )  (83.35%)
         496,648,058      stalled-cycles-frontend:u #    1.87% frontend cycles idle     ( +-  2.02% )  (83.29%)
       3,437,243,040      stalled-cycles-backend:u  #   12.92% backend cycles idle      ( +-  0.90% )  (83.33%)
      66,192,034,237      instructions:u            #    2.49  insn per cycle
                                                    #    0.05  stalled cycles per insn  ( +-  0.03% )  (83.34%)
      15,750,883,004      branches:u                #    2.276 G/sec                    ( +-  0.03% )  (83.35%)
          97,544,298      branch-misses:u           #    0.62% of all branches          ( +-  0.12% )  (83.36%)

              6.9247 +- 0.0478 seconds time elapsed  ( +-  0.69% )

  ⬢[acme@toolbox pahole]$

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-09 13:34:15 -03:00
Arnaldo Carvalho de Melo 6f72dddbed btf_encoder: Move PERCPU_SECTION define to the only source file using it
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-09 10:56:36 -03:00
Arnaldo Carvalho de Melo f0f5b4f2bc btf_encoder: Move library global variable btf_gen_floats to btf_encoder class
So this should be the last global variable in the BTF encoder, good
riddance!

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-09 10:54:10 -03:00
Arnaldo Carvalho de Melo 09970b03bd btf_encoder: Ditch unused 'btf_encoder__verbose' global variable
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-09 10:46:52 -03:00
Arnaldo Carvalho de Melo 9f19e96001 btf_encoder: No need to pass encoder->percpu_secinfo to btf_encoder__add_datasec()
As it receives the encoder and can get that field from it.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-09 10:46:30 -03:00
Arnaldo Carvalho de Melo 869c177f8e btf_encoder: Make btf_encoder__add_var_secinfo() receive a btf_encoder pointer
For consistency.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-09 10:21:07 -03:00
Arnaldo Carvalho de Melo f0e8cd68f5 btf_encoder: Adopt btf__encode_var_secinfo() as btf_encoder__add_var_secinfo()
So that we can eventually ditch the btf_encoder__verbose and
btf_gen_float globals, making them members of 'struct btf_encoder'.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-09 10:18:53 -03:00
Arnaldo Carvalho de Melo cc646d93d1 btf_encoder: Adopt btf__encode_datasec_type() as btf_encoder__add_datasec()
As it is just prep work to call libbpf's btf__add_datasec() for
variables using pahole's data structures populated from another format,
normally DWARF.

So that we can eventually ditch the btf_encoder__verbose and
btf_gen_float globals, making them members of 'struct btf_encoder'.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-09 10:14:47 -03:00
Arnaldo Carvalho de Melo b0f71fabde btf_encoder: Adopt btf__encode_var_type() as btf_encoder__add_var()
As it is just prep work to call libbpf's btf__add_var for a variable
using pahole's data structures populated from another format, normally
DWARF.

So that we can eventually ditch the btf_encoder__verbose and
btf_gen_float globals, making them members of 'struct btf_encoder'.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-09 10:12:26 -03:00
Arnaldo Carvalho de Melo 1aece1e7e6 btf_encoder: Adopt btf__encode_enum_val() as btf_encoder__add_enum_val()
As it is just prep work to call libbpf's btf__add_enum_val for an
enumeration entry using pahole's data structures populated from another
format, normally DWARF.

So that we can eventually ditch the btf_encoder__verbose and
btf_gen_float globals, making them members of 'struct btf_encoder'.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-09 10:10:35 -03:00
Arnaldo Carvalho de Melo 4371b3cd5b btf_encoder: Adopt btf__encode_enum() as btf_encoder__add_enum()
As it is just prep work to call libbpf's btf__add_enum for an
enumeration using pahole's data structures populated from another
format, normally DWARF.

So that we can eventually ditch the btf_encoder__verbose and
btf_gen_float globals, making them members of 'struct btf_encoder'.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-09 10:08:45 -03:00
Arnaldo Carvalho de Melo b536947512 btf_encoder: Adopt btf__encode_enumeration_type() as btf_encoder__add_enum_type()
As it is just prep work to call libbpf's btf__add_enum*() APIs for an
enumeration and its entries using pahole's data structures populated
from another format, normally DWARF.

So that we can eventually ditch the btf_encoder__verbose and
btf_gen_float globals, making them members of 'struct btf_encoder'.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-09 10:06:43 -03:00
Arnaldo Carvalho de Melo 393febe592 btf_encoder: Adopt btf__encode_func_proto() as btf_encoder__add_func_proto()
As it is just prep work to call libbpf's btf__add_func_proto() for a
function prototype using pahole's data structures populated from another
format, normally DWARF.

So that we can eventually ditch the btf_encoder__verbose and
btf_gen_float globals, making them members of 'struct btf_encoder'.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-09 10:01:22 -03:00
Arnaldo Carvalho de Melo 4eb4c03578 btf_encoder: Adopt btf__encode_array() as btf_encoder__add_array()
As it is just prep work to call libbpf's btf__add_array() for an array
using pahole's data structures populated from another format, normally
DWARF.

So that we can eventually ditch the btf_encoder__verbose and
btf_gen_float globals, making them members of 'struct btf_encoder'.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-09 09:59:20 -03:00
Arnaldo Carvalho de Melo 06cd9f00c6 btf_encoder: Adopt btf__encode_struct() as btf_encoder__add_struct()
As it is just prep work to call libbpf's btf__add_struct() for a
struct/union/class using pahole's data structures populated from another
format, normally DWARF.

So that we can eventually ditch the btf_encoder__verbose and
btf_gen_float globals, making them members of 'struct btf_encoder'.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-09 09:57:15 -03:00
Arnaldo Carvalho de Melo 0b29d5a65c btf_encoder: Adopt btf__encode_member() as btf_encoder__add_field()
As it is just prep work to call libbpf's btf__add_field() for a
struct/union/class member using pahole's data structures populated from
another format, normally DWARF.

So that we can eventually ditch the btf_encoder__verbose and
btf_gen_float globals, making them members of 'struct btf_encoder'.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-09 09:53:45 -03:00
Arnaldo Carvalho de Melo 3e2a1f7ddc btf_encoder: Adopt btf__encode_struct_type() as btf_encoder__add_struct_type()
As it is just prep work to call the various libbpf's btf__add*() for
structs/unions and its members using pahole's data structures populated
from another format, normally DWARF.

So that we can eventually ditch the btf_encoder__verbose and
btf_gen_float globals, making them members of 'struct btf_encoder'.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-09 09:46:22 -03:00
Arnaldo Carvalho de Melo 2c7a2f270e btf_encoder: Adopt btf__encode_ref_type() as btf_encoder__add_ref_type()
As it is just prep work to call the various libbpf's btf__add*() for
types that reference other types (volatile, const, pointers, etc) using
pahole's data structures populated from another format, normally DWARF.

So that we can eventually ditch the btf_encoder__verbose and
btf_gen_float globals, making them members of 'struct btf_encoder'.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-09 09:42:20 -03:00
Arnaldo Carvalho de Melo 68ed8af859 btf_encoder: Adopt btf__encode_base_type() as btf_encoder__add_base_type()
As it is just prep work to call libbpf's btf__add_base_type() using
pahole's data structures populated from another format, normally DWARF.

So that we can eventually ditch the btf_encoder__verbose and
btf_gen_float globals, making them members of 'struct btf_encoder'.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-09 09:31:26 -03:00
Arnaldo Carvalho de Melo 282a8a2187 btf_encoder: Use 'struct btf' directly, stop using btf_elf
Now that btf_elf is only crating the 'struct btf' instance, do it
directly.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-09 09:20:23 -03:00
Arnaldo Carvalho de Melo dd0b01f568 libbtf: Remove unused ELF fields and calls from btf_elf
The continuous eroding of libbtf and the move to use libbpf APIs made
possible to ditch these aspects from libbtf.c and btf_elf, that is near
terminal death :-)

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-09 09:10:36 -03:00
Arnaldo Carvalho de Melo a0c5f49b0c btf_encoder: Phagocytize percpu_secinfo from btf_elf
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-08 17:54:35 -03:00
Arnaldo Carvalho de Melo 46a3e3a87a btf_encoder: Move the global btf_encoder to its users, like pahole
Tools should instantiate it using btf_encoder__new(), etc, ditch the
library global.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-08 15:38:48 -03:00
Arnaldo Carvalho de Melo fa849010b4 btf_encoder: Adopt the cu__encode_btf() method, as btf_encoder__encode_cu()
This should be the last user of the global btf_encoder variable, time to
ditch it.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-08 15:35:30 -03:00
Arnaldo Carvalho de Melo 3be437c5e7 btf_encoder: Set btf_encoder__verbose in just one place, its users
E.g.: pahole.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-08 15:32:55 -03:00
Arnaldo Carvalho de Melo e1e787af44 btf_encoder: Move btf_elf__verbose var to btf_encoder class
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-08 15:29:55 -03:00
Arnaldo Carvalho de Melo 66f4054252 btf_encoder: Adopt btf_elf__force, its only used in btf_encoder methods
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-08 15:20:11 -03:00
Arnaldo Carvalho de Melo 5e1207754e pahole: Adopt btf_encoder object instantiation from btf_encoder
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-08 15:03:05 -03:00
Arnaldo Carvalho de Melo 0208952e8f btf_encoder: Move the function encode() to be a btf_encoder method
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-08 14:44:19 -03:00
Arnaldo Carvalho de Melo bcc5f95364 btf_encoder: Temporarily expose the 'encoder' variable
To move creation to pahole.c, i.e. outside the library, to the user,
then move the other methods still using the global variable.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-08 14:40:17 -03:00
Arnaldo Carvalho de Melo e27be59f10 btf_encoder: Move 'filename' member from btf_elf to btf_encoder
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-08 10:10:41 -03:00
Arnaldo Carvalho de Melo 6bc135c8f4 btf_encoder: No need for calling btf_encoder__encode() from cu__encode_btf()
For a vmlinux, the usual case, btf_encoder__encode() ends up being
called just from pahole, after processing all CUs, this looks like a
leftover from when Andrii made it support multiple CUs.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-04 17:46:18 -03:00
Arnaldo Carvalho de Melo 48a0fa2ef7 btf_encoder: Move btf_elf based encode_in_elf and write_elf methods to btf_encoder
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-04 17:38:54 -03:00
Arnaldo Carvalho de Melo cc8eae604d btf_encoder: Move collect_symbols() call to btf_encoder constructor
As we'll call the constructor from users, not from inside the a
btf_constructor method updating a global variable.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-04 17:30:20 -03:00
Arnaldo Carvalho de Melo 96e59c5568 btf_encoder: Remove needless hash.h include, not used anymore
In 2e719cca66 ("btf_encoder: revamp how per-CPU variables are encoded")
hash.h stopped being used, remove the hash.h include.

Cc: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-04 17:30:20 -03:00
Arnaldo Carvalho de Melo 92f8852d8d btf_encoder: Move global elf_functions table to the btf_encoder class
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-04 17:30:20 -03:00
Arnaldo Carvalho de Melo aa48ed55a7 btf_encoder: Move ELF's ehdr from btf_elf to btf_encoder
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-04 17:30:20 -03:00
Arnaldo Carvalho de Melo b3701a8346 btf_encoder: Move 'symtab' from btf_elf to btf_encoder
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-04 17:30:20 -03:00
Arnaldo Carvalho de Melo be8dac4869 btf_encoder: Move percpu members from btf_elf to btf_encoder
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-04 17:30:20 -03:00
Arnaldo Carvalho de Melo 7f70877b19 btf_encoder: Add a 'verbose' member for encoder specific logging requests
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-04 17:30:20 -03:00