aboutsummaryrefslogtreecommitdiff
path: root/libctf
diff options
context:
space:
mode:
authorNick Alcock <nick.alcock@oracle.com>2025-04-25 19:14:02 +0100
committerNick Alcock <nick.alcock@oracle.com>2025-04-25 21:23:07 +0100
commit6b8885cfc9de8b20fa3495a152e457103cfc6c95 (patch)
treeea5e5a10f996bcb632bf1e0ecf100b281d8c7add /libctf
parent95eb77bddb0da40e2e88dcbab8fae3538c100550 (diff)
downloadbinutils-6b8885cfc9de8b20fa3495a152e457103cfc6c95.zip
binutils-6b8885cfc9de8b20fa3495a152e457103cfc6c95.tar.gz
binutils-6b8885cfc9de8b20fa3495a152e457103cfc6c95.tar.bz2
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.
Diffstat (limited to 'libctf')
-rw-r--r--libctf/ctf-dedup.c38
1 files changed, 35 insertions, 3 deletions
diff --git a/libctf/ctf-dedup.c b/libctf/ctf-dedup.c
index cf1e71b..614d10d 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;