Commit Graph

2001 Commits

Author SHA1 Message Date
Arnaldo Carvalho de Melo 16d026ce5d btf_encoder: Move log_err() from btf_elf to btf
As it is all that it needs.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-04 17:28:56 -03:00
Arnaldo Carvalho de Melo c5f594eaa9 btf_encoder: Remove 'elf' from btf_elf__int_encoding_str() name
Its not at all ELF specific, its just a BTF encoding.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-04 17:28:56 -03:00
Arnaldo Carvalho de Melo c81d11b8bb btf_elf: Remove base_btf member, used only in the constructor
And that is where its passed, so just use the constructor argument, no
need to have it in the newly created object.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-04 17:28:56 -03:00
Arnaldo Carvalho de Melo 69f5fff50e btf_elf: No point in falling back to raw BTF in btf_new()
As now it is only called from the BTF _encoder_.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-04 17:28:56 -03:00
Arnaldo Carvalho de Melo 3fcf804a7e btf_elf: No point in looking at the filename for /sys/kernel/btf in btf_elf__new()
As btf_elf__new() is only called from the BTF encoder, and that will not
be encoding from a BTF file, it'll be from a DWARF one.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-04 17:28:56 -03:00
Arnaldo Carvalho de Melo c9eb447502 libbtf: Ditch unused btf_elf__string() method
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-04 17:28:56 -03:00
Arnaldo Carvalho de Melo a355a245fb libbtf: Remove unused btf_elf__load()
Now that bpf_loader uses libbpf directly, this can be ditched.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-04 17:28:56 -03:00
Arnaldo Carvalho de Melo 3de65d433a btf_encoder: Move printable_name() from btfe to btf
Its all it needs.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-04 17:28:56 -03:00
Arnaldo Carvalho de Melo 7fb31d787d btf_loader: Stop using libbtf.h and the btf_elf class
Now we just use libbpf's API to do everything.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-04 17:28:56 -03:00
Arnaldo Carvalho de Melo e431c18b80 btf_loader: cu__fixup_btf_bitfields doesn'n need btfe parameter, ditch it
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-04 17:28:56 -03:00
Arnaldo Carvalho de Melo 8c1919c10d btf_loader: class__fixup_btf_bitfields doesn'n need btfe parameter, ditch it
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-04 17:28:56 -03:00
Arnaldo Carvalho de Melo 4d2ae0d904 btf_elf: Remove unused btfe->priv member
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-04 17:28:56 -03:00
Arnaldo Carvalho de Melo b54b74edfc btf_loader: Add a local 'btf' var to prep next patches
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-04 17:28:56 -03:00
Arnaldo Carvalho de Melo 52bedef0fd btf_loader: Move load_sections() from btf_elf to btf
As it is all it needs.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-04 17:28:56 -03:00
Arnaldo Carvalho de Melo ac3f2952a8 btf_loader: Move load_types() from btf_elf to btf
As it is all it needs.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-04 17:28:56 -03:00
Arnaldo Carvalho de Melo 1a33deae14 btf_loader: Move create_new_tag() from btfe to cu
As all it needs is btfe->priv that is cu.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-04 17:28:56 -03:00
Arnaldo Carvalho de Melo 8323cb33bc btf_loader: Move create_new_datasec() from btfe to cu
As all it needs is btfe->priv that is cu.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-04 17:28:56 -03:00
Arnaldo Carvalho de Melo 6fb41bbf8e btf_loader: Move create_new_variable() from btfe to cu
As all it needs is btfe->priv that is cu.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-04 17:28:56 -03:00
Arnaldo Carvalho de Melo 9122424dda btf_loader: Move create_new_typedef() from btfe to cu
As all it needs is btfe->priv that is cu.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-04 17:28:56 -03:00
Arnaldo Carvalho de Melo dd3e9ab4a0 btf_loader: Move create_new_forward_decl() from btfe to cu
As all it needs is btfe->priv that is cu.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-04 17:28:56 -03:00
Arnaldo Carvalho de Melo cca6b51d29 btf_loader: Move create_new_subroutine_type() from btfe to cu
As all it needs is btfe->priv that is cu.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-04 17:28:56 -03:00
Arnaldo Carvalho de Melo ba1b77d01d btf_loader: Move create_new_enumeration() from btfe to cu
As all it needs is btfe->priv that is cu.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-04 17:28:56 -03:00
Arnaldo Carvalho de Melo a58bc8300f btf_loader: Move create_new_union() from btfe to cu
As all it needs is btfe->priv that is cu.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-04 17:28:56 -03:00
Arnaldo Carvalho de Melo 367f5fe74c btf_loader: Move create_new_class() from btfe to cu
As all it needs is btfe->priv that is cu.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-04 17:28:56 -03:00
Arnaldo Carvalho de Melo 2460bead8a btf_loader: The create_members() function doesn't need the btfe arg
Not used at all.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-04 17:28:56 -03:00
Arnaldo Carvalho de Melo 1136795fec btf_loader: Move create_new_array() from btfe to cu
As all it needs is btfe->priv that is cu.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-04 17:28:56 -03:00
Arnaldo Carvalho de Melo ab2f502891 btf_loader: Move create_new_float_type() from btfe to cu
As all it needs is btfe->priv that is cu.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-04 17:28:56 -03:00
Arnaldo Carvalho de Melo 6b452a1cc5 btf_loader: Move create_new_int_type() from btfe to cu
As all it needs is btfe->priv that is cu.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-04 17:28:56 -03:00
Arnaldo Carvalho de Melo 073a5f69ef btf_loader: Move create_new_function() from btfe to cu
As all it needs is btfe->priv that is cu.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-04 17:28:56 -03:00
Arnaldo Carvalho de Melo 29ad464f73 btf_loader: Move load_ftype() from btfe to cu
As all it needs is btfe->priv that is cu.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-04 17:28:56 -03:00
Arnaldo Carvalho de Melo 407693e2ca btf_loader: Pass cu to the load_sections/types routines
This will allow us to stop using btfe->priv and eventually btf_elf
altogether for the BTF loader.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-04 17:28:56 -03:00
Arnaldo Carvalho de Melo 89b9c4f885 libbtf: Remove the 'base_btf' global var, now unused
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-04 17:28:56 -03:00
Arnaldo Carvalho de Melo 6f70d0acca pahole: Use conf_load->base_btf to call cu__encode_btf()
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-04 17:28:56 -03:00
Arnaldo Carvalho de Melo 0e77be4099 btf_loader: Use conf_load->base_btf instead of the global btf_base var
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-04 17:28:56 -03:00
Arnaldo Carvalho de Melo 6ee61b161d pahole: Set conf_load.btf_base when applicable
Next step will be to make the btf_loader use it.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-04 17:28:56 -03:00
Arnaldo Carvalho de Melo b8255beb12 core: Allow passing the base_btf object via 'struct conf_load'
So that we can get rid of that global base_btf and use the right way
to pass load configuration to the format loaders.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-04 17:28:56 -03:00
Arnaldo Carvalho de Melo f93e05d8bd btf_encoder: Pass the base BTF object to the BTF encoder
We'll get rid of the 'base_btf' global variable in libbtf.c, so stop
using it in the BTF encoder.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-04 17:28:56 -03:00
Arnaldo Carvalho de Melo 81797a00fb btf_elf: Remove unused 'wordsize' member
As we are now using btf__pointer_size() from libbpf.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-04 17:28:56 -03:00
Arnaldo Carvalho de Melo ecc888b855 btf_loader: Use btf__pointer_size() to set cu->addr_size
To use libbpf APIs and go on removing the btf_elf class.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-04 17:28:56 -03:00
Arnaldo Carvalho de Melo e6b69ffc74 btf_elf: Remove unused is_big_endian member
Now that we use btf__endianness() to figure out that info, ditch this
unused member.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-04 17:28:56 -03:00
Arnaldo Carvalho de Melo 81fe7d688d btf_loader: Use btf__endianness() instead of to be removed btfe member
When loading a file, via btf__parse_split() libbtf will read the header
and have the endianness made available via the btf__endianness() API,
use it.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-04 17:28:56 -03:00
Arnaldo Carvalho de Melo 9f8ce7e113 libbtf: Remove unused btf_elf->raw_btf member
Now that we are using btf__parse_split() from libbpf, we don't need
that.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-04 17:28:56 -03:00
Arnaldo Carvalho de Melo 89be5646a0 pahole: Allow encoding BTF into a detached file
Previously the newly encoded BTF info was stored into a ELF section in
the file where the DWARF info was obtained, but it is useful to just
dump it into a separate file, do it.

  $ ls -la vmlinux.btf
  ls: cannot access 'vmlinux.btf': No such file or directory
  $ pahole -j vmlinux.btf vmlinux
  $ ls -la vmlinux.btf
  -rw-r-----. 1 acme acme 4630082 Jun  1 16:15 vmlinux.btf
  $ pahole -C list_head ./vmlinux.btf
  struct list_head {
  	struct list_head *         next;                 /*     0     8 */
  	struct list_head *         prev;                 /*     8     8 */

  	/* size: 16, cachelines: 1, members: 2 */
  	/* last cacheline: 16 bytes */
  };
  acme@toolbox pahole]$ pahole -C raw_spinlock_t ./vmlinux.btf
  typedef struct raw_spinlock raw_spinlock_t;
  acme@toolbox pahole]$ pahole -EC raw_spinlock ./vmlinux.btf
  struct raw_spinlock {
  	/* typedef arch_spinlock_t */ struct qspinlock {
  		union {
  			/* typedef atomic_t */ struct {
  				int counter;                                                  /*     0     4 */
  			} val;                                                                /*     0     4 */
  			struct {
  				/* typedef u8 -> __u8 */ unsigned char locked;                /*     0     1 */
  				/* typedef u8 -> __u8 */ unsigned char pending;               /*     1     1 */
  			};                                                                    /*     0     2 */
  			struct {
  				/* typedef u16 -> __u16 */ short unsigned int locked_pending; /*     0     2 */
  				/* typedef u16 -> __u16 */ short unsigned int tail;           /*     2     2 */
  			};                                                                    /*     0     4 */
  		};                                                                            /*     0     4 */
  	} raw_lock;                                                                           /*     0     4 */

  	/* size: 4, cachelines: 1, members: 1 */
  	/* last cacheline: 4 bytes */
  };
  ⬢[acme@toolbox pahole]$

Requested-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-04 17:28:54 -03:00
Arnaldo Carvalho de Melo 22a76fbc8b btf_loader: Use btf__parse_split()
This way we use libbtf to transparently load both ELF files with a BTF
section as well as raw BTF files, such as those in /sys/kernel/btf/ or
the ones generated using 'pahole --btf_encode_detached'

Suggested-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-01 16:12:13 -03:00
Arnaldo Carvalho de Melo c9d4c106ab dwarf_loader: Add define for DW_OP_addrx
To fix the build in systems where this isn't defined.

Reported-by: Marcos Paulo de Souza <mpdesouza@suse.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-05-28 13:23:29 -03:00
Arnaldo Carvalho de Melo 76f7844c81 libbtf: Fix typo
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-05-27 21:25:20 -03:00
Shuyi Cheng 3d510406ff pahole: Add --kabi_prefix flag
To solve problems similar to _RH_KABI_REPLACE. The _RH_KABI_REPLACE(_orig, _new) macros perserve size alignment and kabi agreement between _orig and _new.Below is the definition of this macro:

    union {                        \
        _new;                    \
        struct {                \
            _orig;                \
        } __UNIQUE_ID(rh_kabi_hide);        \
        __RH_KABI_CHECK_SIZE_ALIGN(_orig, _new);    \
    }

__UNIQUE_ID uses the __COUNTER__ macro, and the __COUNTER__ macro is automatically incremented by 1 every time it is precompiled. Therefore, in different compilation units, the same structure has different names.Here is a concrete example:

struct acpi_dev_node {
    union {
        struct acpi_device *companion;
        struct {
            void *handle;
        } __UNIQUE_ID_rh_kabi_hide29;
        union {        };
    };
};
struct acpi_dev_node {
    union {
        struct acpi_device *companion;
        struct {
            void *handle;
        } __UNIQUE_ID_rh_kabi_hide31;
        union {        };
    };
};

Finally, it will cause the btf algorithm to de-duplication efficiency is not high, and time-consuming. For example, running ./pahole -J vmlinux-3.10.0-1160.el7.x86_64 without --kabi_prefix flag, the running time is:
                real 8m28.912s
                user 8m27.271s
                sys 0m1.471s
And the size of the generated btf segment is 30678240 bytes.

After adding the patch, running ./pahole --kabi_prefix=__UNIQUE_ID_rh_kabi_hide -J vmlinux-3.10.0-1160.el7.x86_64. The running time of the command is:
                real 0m19.634s
                user 0m18.457s
                sys 0m1.169s
And the size of the generated btf segment is 3117719 bytes.

Signed-off-by: Shuyi Cheng <chengshuyi@linux.alibaba.com>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Cc: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Wenan Mao <wenan.mao@linux.alibaba.com>
Cc: dwarves@vger.kernel.org
Link: https://lore.kernel.org/dwarves/482e5543-d7da-7bed-098d-cc879d8db253@linux.alibaba.com/
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-05-27 13:44:35 -03:00
Andrii Nakryiko 0d17503db0 btf_encoder: fix and complete filtering out zero-sized per-CPU variables
btf_encoder is ignoring zero-sized per-CPU ELF symbols, but the same has to be
done for DWARF variables when matching them with ELF symbols. This is due to
zero-sized DWARF variables matching unrelated (non-zero-sized) variable that
happens to be allocated at the exact same address, leading to a lot of
confusion in BTF.

See [0] for when this causes big problems.

  [0] https://lore.kernel.org/bpf/CAEf4BzZ0-sihSL-UAm21JcaCCY92CqfNxycHRZYXcoj8OYb=wA@mail.gmail.com/

Committer notes:

Kept the {} around the if block with more than one line, which
simplifies the original patch by just removing that assignment
to the 'dwarf_name' variable.

Reported-by: Michal Suchánek <msuchanek@suse.de>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
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-05-27 11:56:45 -03:00
Arnaldo Carvalho de Melo fb418f9d83 dwarves: Make handling of NULL by destructos consistent
All should accept a NULL and bail out, just like free().

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-05-27 11:00:18 -03:00
Arnaldo Carvalho de Melo f049fe9ebf dutil: Make handling of NULL by destructos consistent
All should accept a NULL and bail out, just like free().

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-05-27 11:00:18 -03:00