binutils-gdb/libctf
Nick Alcock 49da556c65 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  <nick.alcock@oracle.com>

	* 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  <nick.alcock@oracle.com>

	* 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.
2021-05-06 09:30:59 +01:00
..
testsuite libctf: fix memory leak in a test 2021-03-25 16:32:50 +00:00
.gitignore
aclocal.m4 Implement a workaround for GNU mak jobserver 2021-01-12 05:45:44 -08:00
ChangeLog libctf, include: support an alternative encoding for nonrepresentable types 2021-05-06 09:30:59 +01:00
ChangeLog-2020
config.h.in
configure libctf: fix ELF-in-BFD checks in the presence of ASAN 2021-03-25 16:32:51 +00:00
configure.ac libctf: fix ELF-in-BFD checks in the presence of ASAN 2021-03-25 16:32:51 +00:00
ctf-archive.c libctf: fix GNU style for do {} while 2021-03-18 12:37:55 +00:00
ctf-create.c libctf, include: support an alternative encoding for nonrepresentable types 2021-05-06 09:30:59 +01:00
ctf-decl.c
ctf-decls.h
ctf-dedup.c libctf, include: support an alternative encoding for nonrepresentable types 2021-05-06 09:30:59 +01:00
ctf-dump.c libctf, dump: do not emit size or alignment if it would error 2021-03-25 16:32:46 +00:00
ctf-endian.h
ctf-error.c
ctf-hash.c libctf: do not corrupt strings across ctf_serialize 2021-03-18 12:40:40 +00:00
ctf-impl.h Provide an inline startswith function in bfd.h 2021-03-21 23:00:32 +10:30
ctf-inlines.h
ctf-intl.h
ctf-labels.c
ctf-link.c libctf: fix some tabdamage and move some code around 2021-03-18 12:37:52 +00:00
ctf-lookup.c libctf: don't dereference out-of-bounds locations in the qualifier hashtab 2021-03-25 16:32:49 +00:00
ctf-open-bfd.c libctf: make ctf_bfdopen_ctfsect a debugger entry point 2021-03-25 16:32:49 +00:00
ctf-open.c libctf, include: support an alternative encoding for nonrepresentable types 2021-05-06 09:30:59 +01:00
ctf-qsort_r.c
ctf-serialize.c libctf, serialize: functions with no args have a NULL dtd_vlen 2021-03-25 16:32:48 +00:00
ctf-sha1.c
ctf-sha1.h
ctf-string.c libctf: eliminate dtd_u, part 4: enums 2021-03-18 12:40:40 +00:00
ctf-subr.c
ctf-types.c libctf, include: support an alternative encoding for nonrepresentable types 2021-05-06 09:30:59 +01:00
ctf-util.c
elf.h
libctf.ver libctf, include: support an alternative encoding for nonrepresentable types 2021-05-06 09:30:59 +01:00
Makefile.am libctf: split serialization and file writeout into its own file 2021-03-18 12:37:53 +00:00
Makefile.in libctf: split serialization and file writeout into its own file 2021-03-18 12:37:53 +00:00
NEWS libctf, include: support an alternative encoding for nonrepresentable types 2021-05-06 09:30:59 +01:00
swap.h libctf: fix GNU style for do {} while 2021-03-18 12:37:55 +00:00