dwarves/btf_encoder.h

64 lines
1.3 KiB
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>
#include <gelf.h>
struct btf;
struct btf_elf;
struct cu;
struct elf_symtab;
struct elf_function;
#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;
const char *filename;
struct elf_symtab *symtab;
GElf_Ehdr ehdr;
bool has_index_type,
need_index_type,
verbose,
force;
uint32_t array_index_id;
struct {
struct var_info vars[MAX_PERCPU_VAR_CNT];
int var_cnt;
uint32_t shndx;
uint64_t base_addr;
uint64_t sec_sz;
} percpu;
struct {
struct elf_function *entries;
int allocated;
int cnt;
} functions;
};
extern bool btf_encoder__verbose;
struct btf_encoder *btf_encoder__new(struct cu *cu, struct btf *base_btf, bool skip_encoding_vars, bool force, bool verbose);
void btf_encoder__delete(struct btf_encoder *encoder);
int btf_encoder__encode(struct btf_encoder *encoder, const char *detached_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 btf_encoder__encode_cu(struct btf_encoder *encoder, struct cu *cu, bool skip_encoding_vars);
#endif /* _BTF_ENCODER_H_ */