btf_loader: Fixup class_member->bit_offset for !big_endian files

Yonghong explains:

<quote>
The bitfield offset in BTF starts from lower number to bigger one. That
is, it is always following the big endian convention, bitfield_offset
will be smaller if close to the top of structure.

This is different from what dwarf is doing, which will show different
things on little endian vs. big endian.

You can make simple adjustment based on all available info. In
btf_encoder.s, we did similar adjustment for little endian from
dwarf to btf.
</>

So fix it up while loading, so that the rebuilt C output shows the same
thing from BTF and from DWARF.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Arnaldo Carvalho de Melo 2018-12-21 15:01:11 -03:00
parent b24718fe27
commit ab0cb33e54
1 changed files with 7 additions and 4 deletions

View File

@ -443,7 +443,7 @@ static int btf__load_sections(struct btf *btf)
return btf__load_types(btf);
}
static int class__fixup_btf_bitfields(struct tag *tag, struct cu *cu)
static int class__fixup_btf_bitfields(struct tag *tag, struct cu *cu, struct btf *btf)
{
struct class_member *pos;
struct type *tag_type = tag__type(tag);
@ -502,6 +502,9 @@ static int class__fixup_btf_bitfields(struct tag *tag, struct cu *cu)
}
pos->bitfield_offset = pos->bit_offset % integral_bit_size;
if (!btf->is_big_endian)
pos->bitfield_offset = integral_bit_size - pos->bitfield_offset - pos->bitfield_size;
pos->bit_size = type_bit_size;
pos->byte_offset = (((pos->bit_offset / integral_bit_size) *
integral_bit_size) / 8);
@ -510,14 +513,14 @@ static int class__fixup_btf_bitfields(struct tag *tag, struct cu *cu)
return 0;
}
static int cu__fixup_btf_bitfields(struct cu *cu)
static int cu__fixup_btf_bitfields(struct cu *cu, struct btf *btf)
{
int err = 0;
struct tag *pos;
list_for_each_entry(pos, &cu->tags, node)
if (tag__is_struct(pos) || tag__is_union(pos)) {
err = class__fixup_btf_bitfields(pos, cu);
err = class__fixup_btf_bitfields(pos, cu, btf);
if (err)
break;
}
@ -566,7 +569,7 @@ int btf__load_file(struct cus *cus, struct conf_load *conf,
return err;
}
err = cu__fixup_btf_bitfields(cu);
err = cu__fixup_btf_bitfields(cu, state);
/*
* The app stole this cu, possibly deleting it,
* so forget about it