btf_loader: Refactor class__fixup_btf_bitfields

Refactor class__fixup_btf_bitfields to remove a "continue" statement, to
prepare the ground for alignment fixup that is relevant for some types
matching:

    type->tag != DW_TAG_base_type && type->tag != DW_TAG_enumeration_type

Committer testing:

btfdiff passes for a x86_64 kernel built with gcc and for a clang
thin-LTO vmlinux build.

Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Douglas Raillard <douglas.raillard@arm.com>
Cc: dwarves@vger.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Douglas Raillard 2021-10-18 14:16:20 +01:00 committed by Arnaldo Carvalho de Melo
parent 5282feee6d
commit e975d0fba8
1 changed files with 14 additions and 15 deletions

View File

@ -486,28 +486,27 @@ static int class__fixup_btf_bitfields(struct tag *tag, struct cu *cu)
pos->byte_size = tag__size(type, cu);
pos->bit_size = pos->byte_size * 8;
/* bitfield fixup is needed for enums and base types only */
if (type->tag != DW_TAG_base_type && type->tag != DW_TAG_enumeration_type)
continue;
/* if BTF data is incorrect and has size == 0, skip field,
* instead of crashing */
if (pos->byte_size == 0) {
continue;
}
if (pos->bitfield_size) {
/* bitfields seem to be always aligned, no matter the packing */
pos->byte_offset = pos->bit_offset / pos->bit_size * pos->bit_size / 8;
pos->bitfield_offset = pos->bit_offset - pos->byte_offset * 8;
/* re-adjust bitfield offset if it is negative */
if (pos->bitfield_offset < 0) {
pos->bitfield_offset += pos->bit_size;
pos->byte_offset -= pos->byte_size;
pos->bit_offset = pos->byte_offset * 8 + pos->bitfield_offset;
/* bitfield fixup is needed for enums and base types only */
if (type->tag == DW_TAG_base_type || type->tag == DW_TAG_enumeration_type) {
if (pos->bitfield_size) {
/* bitfields seem to be always aligned, no matter the packing */
pos->byte_offset = pos->bit_offset / pos->bit_size * pos->bit_size / 8;
pos->bitfield_offset = pos->bit_offset - pos->byte_offset * 8;
/* re-adjust bitfield offset if it is negative */
if (pos->bitfield_offset < 0) {
pos->bitfield_offset += pos->bit_size;
pos->byte_offset -= pos->byte_size;
pos->bit_offset = pos->byte_offset * 8 + pos->bitfield_offset;
}
} else {
pos->byte_offset = pos->bit_offset / 8;
}
} else {
pos->byte_offset = pos->bit_offset / 8;
}
}