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
Arnaldo Carvalho de Melo
1512ab8ab6
pahole: 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
1105b7dad2
elf_symtab: Use zfree() where applicable
...
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-05-27 11:00:18 -03:00
Arnaldo Carvalho de Melo
131275fa20
codiff: Use zfree() where applicable
...
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-05-27 11:00:18 -03:00
Arnaldo Carvalho de Melo
6784b03fd4
dutil: Adopt the zalloc()/zfree() from perf
...
So that we handle const pointers, also zalloc() is much simpler just
calling calloc(1, size).
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-05-27 11:00:18 -03:00
Arnaldo Carvalho de Melo
d7f5824a9e
libctf: Use zfree() where applicable
...
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-05-27 11:00:18 -03:00
Arnaldo Carvalho de Melo
45d9eb8602
pahole: Use zfree() where applicable
...
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-05-27 11:00:18 -03:00
Arnaldo Carvalho de Melo
f48cc78e8e
dwarf_loader: Use zfree() instead of ad-hoc implementation
...
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-05-27 11:00:18 -03:00
Arnaldo Carvalho de Melo
d0f6a4a1da
gobuffer: Use zfree() and make delete accept NULL, like free()
...
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-05-27 11:00:18 -03:00
Arnaldo Carvalho de Melo
db37185d16
dwarves: Use zfree()
...
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-05-27 11:00:18 -03:00
Arnaldo Carvalho de Melo
e7e86c75e1
libbtf: Use zfree()
...
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-05-27 11:00:18 -03:00
Arnaldo Carvalho de Melo
972001e58e
dutil: Adopt zfree(), to use it more pervasively
...
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-05-27 11:00:18 -03:00
Arnaldo Carvalho de Melo
5847901abf
dwarves: Plug leaks in cu__new() found by covscan
...
Error: GCC_ANALYZER_WARNING (CWE-401):
dwarves-1.21/dwarves.c: scope_hint: In function 'cu__new'
dwarves-1.21/dwarves.c:604:16: warning[-Wanalyzer-malloc-leak]: leak of '<unknown>'
# 602| }
# 603| out:
# 604|-> return cu;
# 605| out_free_name:
# 606| free(cu->name);
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-05-27 11:00:18 -03:00
Arnaldo Carvalho de Melo
32114e611a
dwarf_loader: Call dwarf_cu__delete() when aborting the load
...
Addressing these covscan report entry:
Error: GCC_ANALYZER_WARNING (CWE-401):
dwarves-1.21/dwarf_loader.c:2645:40: warning[-Wanalyzer-malloc-leak]: leak of 'dcu'
# 2643| filename);
# 2644| if (cu == NULL || cu__set_common(cu, conf, mod, elf) != 0)
# 2645|-> return DWARF_CB_ABORT;
# 2646|
# 2647| dcu = malloc(sizeof(struct dwarf_cu));
Error: RESOURCE_LEAK (CWE-772):
dwarves-1.21/dwarf_loader.c:2647: alloc_fn: Storage is returned from allocation function "malloc".
dwarves-1.21/dwarf_loader.c:2647: var_assign: Assigning: "dcu" = storage returned from "malloc(120UL)".
dwarves-1.21/dwarf_loader.c:2663: leaked_storage: Variable "dcu" going out of scope leaks the storage it points to.
# 2661| }
# 2662| if (hashtags__bits < default_hbits)
# 2663|-> return DWARF_CB_ABORT;
# 2664|
# 2665| dcu->cu = cu;
Error: CLANG_WARNING:
dwarves-1.21/dwarf_loader.c:2663:12: warning[unix.Malloc]: Potential leak of memory pointed to by 'dcu'
# 2661| }
# 2662| if (hashtags__bits < default_hbits)
# 2663|-> return DWARF_CB_ABORT;
# 2664|
# 2665| dcu->cu = cu;
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-05-27 11:00:18 -03:00
Arnaldo Carvalho de Melo
26bd4c4164
dwarf_loader: Delete the allocated CU when aborting
...
As in this case we're not adding it to the cus->cus in
finalize_cu_immediately().
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-05-27 11:00:18 -03:00
Arnaldo Carvalho de Melo
d8940df90b
dwarf_loader: Make all ABORT returns go thru a single exit label
...
No change in logic, just prepping the way for proper deletion of
objects.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-05-27 11:00:18 -03:00