dwarves/btf_encoder.h

46 lines
976 B
C
Raw Normal View History

#ifndef _BTF_ENCODER_H_
#define _BTF_ENCODER_H_ 1
/*
SPDX-License-Identifier: GPL-2.0-only
Copyright (C) 2019 Facebook
Derived from ctf_encoder.h, which is:
Copyright (C) Arnaldo Carvalho de Melo <acme@redhat.com>
*/
#include <stdbool.h>
#include <stdint.h>
struct btf;
struct btf_elf;
struct cu;
#define MAX_PERCPU_VAR_CNT 4096
struct var_info {
uint64_t addr;
const char *name;
uint32_t sz;
};
struct btf_encoder {
struct btf_elf *btfe;
bool has_index_type,
need_index_type;
struct {
struct var_info vars[MAX_PERCPU_VAR_CNT];
int var_cnt;
} percpu;
};
struct btf_encoder *btf_encoder__new(struct cu *cu, struct btf *base_btf, bool skip_encoding_vars);
void btf_encoder__delete(struct btf_encoder *encoder);
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-05-28 21:41:30 +02:00
int btf_encoder__encode(const char *filename);
btf: Allow multiple cu's in dwarf->btf conversion Currently, the pahole dwarf->btf conversion only supports one compilation unit. This is not ideal since we would like using pahole to generate BTF for vmlinux which has a lot of compilation units. This patch added support to process multiple compilation units per ELF file. Multiple ELF files are also supported properly. The following is a demonstration example: -bash-4.4$ cat t1.c struct t1 { int a1; } g1; int main(void) { return 0; } -bash-4.4$ cat t2.c struct t2 { char a2; } g2; int main() { return 0; } -bash-4.4$ cat t3.c struct t3 { unsigned char a1:4; } g1; int main(void) { return 0; } -bash-4.4$ cat t4.c struct t4 { volatile char a4; } g2; int main() { return 0; } -bash-4.4$ gcc -O2 -o t1 -g t1.c t2.c -bash-4.4$ gcc -O2 -o t3 -g t3.c t4.c Note that both the binary "t1" and "t3" have two compilation units in their respective dwarf debug_info sections. The following is the pahole verbose output for BTF conversion for these two binaries. -bash-4.4$ pahole -JV t1 t3 File t1: [1] STRUCT t1 size=4 vlen=1 a1 type_id=2 bits_offset=0 [2] INT int size=4 bit_offset=0 nr_bits=32 encoding=SIGNED [3] STRUCT t2 size=1 vlen=1 a2 type_id=4 bits_offset=0 [4] INT char size=1 bit_offset=0 nr_bits=8 encoding=(none) [5] INT int size=4 bit_offset=0 nr_bits=32 encoding=SIGNED File t3: [1] STRUCT t3 size=1 vlen=1 a1 type_id=3 bits_offset=0 [2] INT unsigned char size=1 bit_offset=0 nr_bits=8 encoding=(none) [3] INT unsigned char size=1 bit_offset=0 nr_bits=4 encoding=(none) [4] INT (anon) size=4 bit_offset=0 nr_bits=32 encoding=(none) [5] STRUCT t4 size=1 vlen=1 a4 type_id=6 bits_offset=0 [6] VOLATILE (anon) type_id=7 [7] INT char size=1 bit_offset=0 nr_bits=8 encoding=(none) [8] INT int size=4 bit_offset=0 nr_bits=32 encoding=SIGNED Signed-off-by: Andrii Nakryiko <andriin@fb.com> Acked-by: Martin KaFai Lau <kafai@fb.com> Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Alexei Starovoitov <ast@fb.com> Cc: Yonghong Song <yhs@fb.com> Signed-off-by: Yonghong Song <yhs@fb.com> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2018-12-18 23:09:39 +01:00
int cu__encode_btf(struct cu *cu, struct btf *base_btf, int verbose, bool force,
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-05-28 21:41:30 +02:00
bool skip_encoding_vars, const char *detached_btf_filename);
#endif /* _BTF_ENCODER_H_ */