loaders: Record CU's endianness in dwarf/btf/ctf loaders

This patch records for each CU whether it's in little-endian or
big-endian data format. This flag will be used in subsequent commits to
adjust bit offsets where necessary, to make them uniform across
endianness. This patch doesn't have any effect on pahole's output.

Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Cc: Alexei Starovoitov <ast@fb.com>
Cc: Mark Wielaard <mark@klomp.org>
Cc: Martin KaFai Lau <kafai@fb.com>
Cc: Yonghong Song <yhs@fb.com>
Cc: dwarves@vger.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Andrii Nakryiko 2019-03-17 21:23:41 -07:00 committed by Arnaldo Carvalho de Melo
parent 975757bc88
commit 5104d1bef3
4 changed files with 15 additions and 0 deletions

View File

@ -538,6 +538,7 @@ int btf_elf__load_file(struct cus *cus, struct conf_load *conf, const char *file
cu->language = LANG_C;
cu->uses_global_strings = false;
cu->little_endian = !btfe->is_big_endian;
cu->dfops = &btf_elf__ops;
cu->priv = btfe;
btfe->priv = cu;

View File

@ -734,6 +734,7 @@ int ctf__load_file(struct cus *cus, struct conf_load *conf,
cu->language = LANG_C;
cu->uses_global_strings = false;
cu->little_endian = state->ehdr.e_ident[EI_DATA] == ELFDATA2LSB;
cu->dfops = &ctf__ops;
cu->priv = state;
state->priv = cu;

View File

@ -2243,6 +2243,12 @@ static int cus__load_debug_types(struct cus *cus, struct conf_load *conf,
cu->extra_dbg_info = conf ? conf->extra_dbg_info : 0;
cu->has_addr_info = conf ? conf->get_addr_info : 0;
GElf_Ehdr ehdr;
if (gelf_getehdr(elf, &ehdr) == NULL) {
return DWARF_CB_ABORT;
}
cu->little_endian = ehdr.e_ident[EI_DATA] == ELFDATA2LSB;
dwarf_cu__init(dcup);
dcup->cu = cu;
/* Funny hack. */
@ -2324,6 +2330,12 @@ static int cus__load_module(struct cus *cus, struct conf_load *conf,
cu->extra_dbg_info = conf ? conf->extra_dbg_info : 0;
cu->has_addr_info = conf ? conf->get_addr_info : 0;
GElf_Ehdr ehdr;
if (gelf_getehdr(elf, &ehdr) == NULL) {
return DWARF_CB_ABORT;
}
cu->little_endian = ehdr.e_ident[EI_DATA] == ELFDATA2LSB;
struct dwarf_cu dcu;
dwarf_cu__init(&dcu);

View File

@ -200,6 +200,7 @@ struct cu {
uint8_t extra_dbg_info:1;
uint8_t has_addr_info:1;
uint8_t uses_global_strings:1;
uint8_t little_endian:1;
uint16_t language;
unsigned long nr_inline_expansions;
size_t size_inline_expansions;