dwarf_loader: Allow asking not to read the DW_AT_alignment attribute

As this isn't present in most types or struct members, which ends up
making dwarf_attr() call libdw_find_attr() that will do a linear search
on all the attributes.

We don't use this in the BTF encoder, so no point in reading that.

This will be used in pahole in the following cset.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Arnaldo Carvalho de Melo 2021-07-16 17:36:32 -03:00
parent 1ef1639039
commit 21a41e5386
2 changed files with 8 additions and 2 deletions

View File

@ -322,6 +322,11 @@ static uint64_t attr_numeric(Dwarf_Die *die, uint32_t name)
return 0;
}
static uint64_t attr_alignment(Dwarf_Die *die, struct conf_load *conf)
{
return conf->ignore_alignment_attr ? 0 : attr_numeric(die, DW_AT_alignment);
}
static uint64_t dwarf_expr(const uint8_t *expr, uint32_t len __maybe_unused)
{
/* Common case: offset from start of the class */
@ -601,7 +606,7 @@ static void type__init(struct type *type, Dwarf_Die *die, struct cu *cu, struct
namespace__init(&type->namespace, die, cu, conf);
__type__init(type);
type->size = attr_numeric(die, DW_AT_byte_size);
type->alignment = attr_numeric(die, DW_AT_alignment);
type->alignment = attr_alignment(die, conf);
type->declaration = attr_numeric(die, DW_AT_declaration);
dwarf_tag__set_spec(type->namespace.tag.priv,
attr_type(die, DW_AT_specification));
@ -860,7 +865,7 @@ static struct class_member *class_member__new(Dwarf_Die *die, struct cu *cu,
if (member != NULL) {
tag__init(&member->tag, cu, die);
member->name = attr_string(die, DW_AT_name, conf);
member->alignment = attr_numeric(die, DW_AT_alignment);
member->alignment = attr_alignment(die, conf);
Dwarf_Attribute attr;

View File

@ -51,6 +51,7 @@ struct conf_load {
bool extra_dbg_info;
bool fixup_silly_bitfields;
bool get_addr_info;
bool ignore_alignment_attr;
uint16_t kabi_prefix_len;
const char *kabi_prefix;
struct btf *base_btf;