From: Nick Alcock Date: Fri, 25 Apr 2025 18:14:02 +0000 (+0100) Subject: libctf: dedup: structs with bitfields, BTF floats X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6b8885cfc9de8b20fa3495a152e457103cfc6c95;p=thirdparty%2Fbinutils-gdb.git libctf: dedup: structs with bitfields, BTF floats The last two trivial cases. Hash in the bitfieldness of structs and the bit-width of members (their bit-offset is already being hashed in), and emit them accordingly. BTF floats hardly have any state: emitting them is even easier. --- diff --git a/libctf/ctf-dedup.c b/libctf/ctf-dedup.c index cf1e71bd22a..614d10d7e12 100644 --- a/libctf/ctf-dedup.c +++ b/libctf/ctf-dedup.c @@ -726,6 +726,14 @@ ctf_dedup_rhash_type (ctf_dict_t *fp, ctf_dict_t *input, ctf_dict_t **inputs, depth); break; } + case CTF_K_BTF_FLOAT: + { + ssize_t size; + + ctf_get_ctt_size (input, tp, &size, NULL); + ctf_dedup_sha1_add (&hash, &size, sizeof (size_t), "size", depth); + break; + } /* Types that reference other types. */ case CTF_K_TYPEDEF: case CTF_K_VOLATILE: @@ -970,11 +978,20 @@ ctf_dedup_rhash_type (ctf_dict_t *fp, ctf_dict_t *input, ctf_dict_t **inputs, ctf_id_t membtype; ssize_t size; int bit_width; + int is_bitfield; ctf_get_ctt_size (input, tp, &size, NULL); ctf_dedup_sha1_add (&hash, &size, sizeof (ssize_t), "struct size", depth); + if ((is_bitfield = ctf_struct_bitfield (input, type)) < 0) + { + whaterr = N_("error doing struct/union member bitfield checking"); + goto input_err; + } + ctf_dedup_sha1_add (&hash, &is_bitfield, sizeof (is_bitfield), + "struct/union bitfieldness", depth); + while ((offset = ctf_member_next (input, type, &i, &mname, &membtype, &bit_width, 0)) >= 0) { @@ -998,6 +1015,8 @@ ctf_dedup_rhash_type (ctf_dict_t *fp, ctf_dict_t *input, ctf_dict_t **inputs, depth); ctf_dedup_sha1_add (&hash, &offset, sizeof (offset), "member offset", depth); + ctf_dedup_sha1_add (&hash, &bit_width, sizeof (bit_width), + "member bit width", depth); ADD_CITER (citers, hval); } if (ctf_errno (input) != ECTF_NEXT_END) @@ -2246,6 +2265,7 @@ ctf_dedup_rwalk_one_output_mapping (ctf_dict_t *output, case CTF_K_FORWARD: case CTF_K_INTEGER: case CTF_K_FLOAT: + case CTF_K_BTF_FLOAT: case CTF_K_ENUM: case CTF_K_ENUM64: /* No types referenced. */ @@ -2913,6 +2933,7 @@ ctf_dedup_emit_type (const char *hval, ctf_dict_t *output, ctf_dict_t **inputs, break; case CTF_K_FLOAT: + case CTF_K_BTF_FLOAT: case CTF_K_INTEGER: errtype = _("float/int"); if (ctf_type_encoding (input, type, &ep) < 0) @@ -3112,11 +3133,22 @@ ctf_dedup_emit_type (const char *hval, ctf_dict_t *output, ctf_dict_t **inputs, case CTF_K_STRUCT: case CTF_K_UNION: { - size_t size = ctf_type_size (input, type); + ssize_t size = ctf_type_size (input, type); void *out_id; + int is_bitfield; + /* Insert the structure itself, so other types can refer to it. */ errtype = _("structure/union"); + + is_bitfield = ctf_struct_bitfield (input, type); + + if (is_bitfield < 0 || size < 0) + goto err_input; + + if (is_bitfield) + isroot |= CTF_ADD_STRUCT_BITFIELDS; + if (kind == CTF_K_STRUCT) new_type = ctf_add_struct_sized (target, isroot, name, size); else @@ -3247,8 +3279,8 @@ ctf_dedup_emit_struct_members (ctf_dict_t *output, ctf_dict_t **inputs, #ifdef ENABLE_LIBCTF_HASH_DEBUGGING ctf_dprintf ("Emitting %s, target-mapped type %lx, offset %zi\n", name, membtype, offset); #endif - if (ctf_add_member_offset (target, target_type, name, - membtype, offset) < 0) + if (ctf_add_member_bitfield (target, target_type, name, membtype, + offset, width) < 0) { ctf_next_destroy (j); goto err_target;