From: Nick Alcock Date: Thu, 24 Apr 2025 16:28:34 +0000 (+0100) Subject: libctf, create, types: encoding, BTF floats X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2c1a0a70d14a5e26acd9a3bafcd40845d1cabf4f;p=thirdparty%2Fbinutils-gdb.git libctf, create, types: encoding, BTF floats This adds support for the nearly useless BTF_KIND_FLOAT, under the name CTF_K_BTF_FLOAT. At the same time we fix up the ctf_add_encoding and ctf_type_encoding machinery for the new API changes. I expect this to change a bit: Ali Bahrami reckons I've oversimplified the CTFv4 encoding representation and need to reintroduce at least a width. New API: ctf_id_t ctf_add_btf_float (ctf_dict_t *, uint32_t, const char *, const ctf_encoding_t *); --- diff --git a/include/ctf-api.h b/include/ctf-api.h index cc56de5d927..f0769a67fed 100644 --- a/include/ctf-api.h +++ b/include/ctf-api.h @@ -135,7 +135,9 @@ typedef enum ctf_sect_names /* Encoding information for integers, floating-point values, and certain other intrinsics can be obtained by calling ctf_type_encoding, below. The flags - field will contain values appropriate for the type defined in . */ + field will contain values appropriate for the type defined in . + + For floats, only the first of these fields is meaningful. */ typedef struct ctf_encoding { @@ -846,6 +848,8 @@ extern ctf_id_t ctf_add_enum64 (ctf_dict_t *, uint32_t, const char *); extern ctf_id_t ctf_add_enum_encoded (ctf_dict_t *, uint32_t, const char *, const ctf_encoding_t *); extern ctf_id_t ctf_add_enum (ctf_dict_t *, uint32_t, const char *); +extern ctf_id_t ctf_add_btf_float (ctf_dict_t *, uint32_t, + const char *, const ctf_encoding_t *); extern ctf_id_t ctf_add_float (ctf_dict_t *, uint32_t, const char *, const ctf_encoding_t *); extern ctf_id_t ctf_add_forward (ctf_dict_t *, uint32_t, const char *, diff --git a/libctf/ctf-create.c b/libctf/ctf-create.c index e75ef770245..2ab8472be2c 100644 --- a/libctf/ctf-create.c +++ b/libctf/ctf-create.c @@ -668,32 +668,29 @@ ctf_add_encoded (ctf_dict_t *fp, uint32_t flag, if (name == NULL || name[0] == '\0') return (ctf_set_typed_errno (fp, ECTF_NONAME)); - if (!ctf_assert (fp, kind == CTF_K_INTEGER || kind == CTF_K_FLOAT)) - return CTF_ERR; /* errno is set for us. */ + if (!ctf_assert (fp, kind == CTF_K_INTEGER || kind == CTF_K_FLOAT + || kind == CTF_K_BTF_FLOAT)) + return CTF_ERR; /* errno is set for us. */ - if ((type = ctf_add_generic (fp, flag, name, kind, sizeof (uint32_t), - &dtd)) == CTF_ERR) + if (kind == CTF_K_BTF_FLOAT) + vlen = 0; + + if ((dtd = ctf_add_generic (fp, flag, name, kind, 0, vlen, 0, NULL)) == NULL) return CTF_ERR; /* errno is set for us. */ - dtd->dtd_data.ctt_info = CTF_TYPE_INFO (kind, flag, 0); - dtd->dtd_data.ctt_size = clp2 (P2ROUNDUP (ep->cte_bits, CHAR_BIT) - / CHAR_BIT); - switch (kind) + dtd->dtd_data->ctt_info = CTF_TYPE_INFO (kind, 0, 0); + dtd->dtd_data->ctt_size = clp2 (P2ROUNDUP (ep->cte_bits, CHAR_BIT) / CHAR_BIT); + + if (kind != CTF_K_BTF_FLOAT) { - case CTF_K_INTEGER: - encoding = CTF_INT_DATA (ep->cte_format, ep->cte_offset, ep->cte_bits); - break; - case CTF_K_FLOAT: - encoding = CTF_FP_DATA (ep->cte_format, ep->cte_offset, ep->cte_bits); - break; - default: - /* ctf_assert is opaque with -fno-inline. This dead code avoids - a warning about "encoding" being used uninitialized. */ - return CTF_ERR; + encoding = ep->cte_format; + if (kind == CTF_K_INTEGER) + encoding = CTF_INT_DATA (ep->cte_format, ep->cte_offset, ep->cte_bits); + + memcpy (dtd->dtd_vlen, &encoding, sizeof (encoding)); } - memcpy (dtd->dtd_vlen, &encoding, sizeof (encoding)); - return type; + return dtd->dtd_type; } ctf_id_t @@ -770,7 +767,7 @@ ctf_add_slice (ctf_dict_t *fp, uint32_t flag, ctf_id_t ref, kind = ctf_type_kind_unsliced (fp, resolved_ref); if ((kind != CTF_K_INTEGER) && (kind != CTF_K_FLOAT) && - (kind != CTF_K_ENUM) + (kind != CTF_K_ENUM) && (kind != CTF_K_BTF_FLOAT) && (ref != 0)) return (ctf_set_typed_errno (fp, ECTF_NOTINTFP)); @@ -805,6 +802,13 @@ ctf_add_float (ctf_dict_t *fp, uint32_t flag, return (ctf_add_encoded (fp, flag, name, ep, CTF_K_FLOAT)); } +ctf_id_t +ctf_add_btf_float (ctf_dict_t *fp, uint32_t flag, + const char *name, const ctf_encoding_t *ep) +{ + return (ctf_add_encoded (fp, flag, name, ep, CTF_K_BTF_FLOAT)); +} + ctf_id_t ctf_add_pointer (ctf_dict_t *fp, uint32_t flag, ctf_id_t ref) { diff --git a/libctf/ctf-types.c b/libctf/ctf-types.c index f30a3c2804e..09c0baefdba 100644 --- a/libctf/ctf-types.c +++ b/libctf/ctf-types.c @@ -871,6 +871,7 @@ ctf_type_aname (ctf_dict_t *fp, ctf_id_t type) case CTF_K_FLOAT: case CTF_K_TYPEDEF: /* Integers, floats, and typedefs must always be named types. */ + case CTF_K_BTF_FLOAT: if (name[0] == '\0') { @@ -1387,24 +1388,19 @@ int ctf_type_encoding (ctf_dict_t *fp, ctf_id_t type, ctf_encoding_t *ep) { ctf_dict_t *ofp = fp; - ctf_dtdef_t *dtd; - const ctf_type_t *tp; - ssize_t increment; + const ctf_type_t *tp, *suffix; const unsigned char *vlen; uint32_t data; - if ((tp = ctf_lookup_by_id (&fp, type)) == NULL) + if ((tp = ctf_lookup_by_id (&fp, type, &suffix)) == NULL) return -1; /* errno is set for us. */ - if ((dtd = ctf_dynamic_type (ofp, type)) != NULL) - vlen = dtd->dtd_vlen; - else - { - ctf_get_ctt_size (fp, tp, NULL, &increment); - vlen = (const unsigned char *) ((uintptr_t) tp + increment); - } + if ((type = ctf_type_resolve (fp, type)) == CTF_ERR) + return (ctf_set_typed_errno (ofp, ECTF_NOTYPE)); - switch (LCTF_INFO_KIND (fp, tp->ctt_info)) + vlen = ctf_vlen (fp, type, tp, NULL); + + switch (LCTF_KIND (fp, tp)) { case CTF_K_INTEGER: data = *(const uint32_t *) vlen; @@ -1424,6 +1420,11 @@ ctf_type_encoding (ctf_dict_t *fp, ctf_id_t type, ctf_encoding_t *ep) ep->cte_offset = 0; ep->cte_bits = 0; break; + case CTF_K_BTF_FLOAT: + ep->cte_format = 0; + ep->cte_offset = 0; + ep->cte_bits = suffix->ctt_size * CHAR_BIT; + break; case CTF_K_SLICE: { const ctf_slice_t *slice; diff --git a/libctf/libctf.ver b/libctf/libctf.ver index 107a52783d4..a4dfa5d5aae 100644 --- a/libctf/libctf.ver +++ b/libctf/libctf.ver @@ -116,6 +116,7 @@ LIBCTF_2.0 { ctf_add_enum64; ctf_add_enum64_encoded; ctf_add_float; + ctf_add_btf_float; ctf_add_forward; ctf_add_function; ctf_add_integer;