From 49da556c658684db1b8bdba956e541bc99628f02 Mon Sep 17 00:00:00 2001 From: Nick Alcock Date: Thu, 6 May 2021 09:30:58 +0100 Subject: libctf, include: support an alternative encoding for nonrepresentable types Before now, types that could not be encoded in CTF were represented as references to type ID 0, which does not itself appear in the dictionary. This choice is annoying in several ways, principally that it forces generators and consumers of CTF to grow special cases for types that are referenced in valid dicts but don't appear. Allow an alternative representation (which will become the only representation in format v4) whereby nonrepresentable types are encoded as actual types with kind CTF_K_UNKNOWN (an already-existing kind theoretically but not in practice used for padding, with value 0). This is backward-compatible, because CTF_K_UNKNOWN was not used anywhere before now: it was used in old-format function symtypetabs, but these were never emitted by any compiler and the code to handle them in libctf likely never worked and was removed last year, in favour of new-format symtypetabs that contain only type IDs, not type kinds. In order to link this type, we need an API addition to let us add types of unknown kind to the dict: we let them optionally have names so that GCC can emit many different unknown types and those types with identical names will be deduplicated together. There are also small tweaks to the deduplicator to actually dedup such types, to let opening of dicts with unknown types with names work, to return the ECTF_NONREPRESENTABLE error on resolution of such types (like ID 0), and to print their names as something useful but not a valid C identifier, mostly for the sake of the dumper. Tests added in the next commit. include/ChangeLog 2021-05-06 Nick Alcock * ctf.h (CTF_K_UNKNOWN): Document that it can be used for nonrepresentable types, not just padding. * ctf-api.h (ctf_add_unknown): New. libctf/ChangeLog 2021-05-06 Nick Alcock * ctf-open.c (init_types): Unknown types may have names. * ctf-types.c (ctf_type_resolve): CTF_K_UNKNOWN is as non-representable as type ID 0. (ctf_type_aname): Print unknown types. * ctf-dedup.c (ctf_dedup_hash_type): Do not early-exit for CTF_K_UNKNOWN types: they have real hash values now. (ctf_dedup_rwalk_one_output_mapping): Treat CTF_K_UNKNOWN types like other types with no referents: call the callback and do not skip them. (ctf_dedup_emit_type): Emit via... * ctf-create.c (ctf_add_unknown): ... this new function. * libctf.ver (LIBCTF_1.2): Add it. --- include/ChangeLog | 6 ++++++ include/ctf-api.h | 1 + include/ctf.h | 3 ++- 3 files changed, 9 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/ChangeLog b/include/ChangeLog index 0f277f9..aed37fd 100644 --- a/include/ChangeLog +++ b/include/ChangeLog @@ -1,3 +1,9 @@ +2021-05-06 Nick Alcock + + * ctf.h (CTF_K_UNKNOWN): Document that it can be used for + nonrepresentable types, not just padding. + * ctf-api.h (ctf_add_unknown): New. + 2021-04-22 Clément Chigot * coff/internal.h (union internal_auxent): diff --git a/include/ctf-api.h b/include/ctf-api.h index 25dbe9e..fa8f2cd 100644 --- a/include/ctf-api.h +++ b/include/ctf-api.h @@ -491,6 +491,7 @@ extern ctf_id_t ctf_add_struct_sized (ctf_dict_t *, uint32_t, const char *, size_t); extern ctf_id_t ctf_add_union_sized (ctf_dict_t *, uint32_t, const char *, size_t); +extern ctf_id_t ctf_add_unknown (ctf_dict_t *, uint32_t, const char *); extern ctf_id_t ctf_add_volatile (ctf_dict_t *, uint32_t, ctf_id_t); extern int ctf_add_enumerator (ctf_dict_t *, ctf_id_t, const char *, int); diff --git a/include/ctf.h b/include/ctf.h index 90631fc..fa31c46 100644 --- a/include/ctf.h +++ b/include/ctf.h @@ -405,7 +405,8 @@ union CTF_INFO_VLEN() will extract the number of elements in the list, and the type of each element is shown in the comments below. */ -#define CTF_K_UNKNOWN 0 /* Unknown type (used for padding). */ +#define CTF_K_UNKNOWN 0 /* Unknown type (used for padding and + unrepresentable types). */ #define CTF_K_INTEGER 1 /* Variant data is CTF_INT_DATA (see below). */ #define CTF_K_FLOAT 2 /* Variant data is CTF_FP_DATA (see below). */ #define CTF_K_POINTER 3 /* ctt_type is referenced type. */ -- cgit v1.1