binutils-gdb/libctf
Nick Alcock 791915db42 libctf: handle nonrepresentable types at link time
GCC can emit references to type 0 to indicate that this type is one that
is not representable in the version of CTF it emits (for instance,
version 3 cannot encode vector types).  Type 0 is already used in the
function section to indicate padding inserted to skip functions we do
not want to encode the type of, so using zero in this way is a good
extension of the format: but libctf reports such types as ECTF_BADID,
which is indistinguishable from file corruption via links to truly
nonexistent types with IDs like 0xDEADBEEF etc, which we really do want
to stop for.

In particular, this stops all traversals of types dead at this point,
preventing us from even dumping CTF files containing unrepresentable
types to see what's going on!

So add a new error, ECTF_NONREPRESENTABLE, which is returned by
recursive type resolution when a reference to a zero type is found.  (No
zero type is ever emitted into the CTF file by GCC, only references to
one).  We can't do much with types that are ultimately nonrepresentable,
but we can do enough to keep functioning.

Adjust ctf_add_type to ensure that top-level types of type zero and
structure and union members of ultimate type zero are simply skipped
without reporting an error, so we can copy structures and unions that
contain nonrepresentable members (skipping them and leaving a hole where
they would be, so no consumers downstream of the linker need to worry
about this): adjust the dumper so that we dump members of
nonrepresentable types in a simple form that indicates
nonrepresentability rather than terminating the dump, and do not falsely
assume all errors to be -ENOMEM: adjust the linker so that types that
fail to get added are simply skipped, so that both nonrepresentable
types and outright errors do not terminate the type addition, which
could skip many valid types and cause further errors when variables of
those types are added.

In future, when we gain the ability to call back to the linker to report
link-time type resolution errors, we should report failures to add all
but nonrepresentable types.  But we can't do that yet.

v5: Fix tabdamage.

include/
	* ctf-api.h (ECTF_NONREPRESENTABLE): New.
libctf/
	* ctf-types.c (ctf_type_resolve): Return ECTF_NONREPRESENTABLE on
	type zero.
	* ctf-create.c (ctf_add_type): Detect and skip nonrepresentable
	members and types.
	(ctf_add_variable): Likewise for variables pointing to them.
	* ctf-link.c (ctf_link_one_type): Do not warn for nonrepresentable
	type link failure, but do warn for others.
	* ctf-dump.c (ctf_dump_format_type): Likewise.  Do not assume all
	errors to be ENOMEM.
	(ctf_dump_member): Likewise.
	(ctf_dump_type): Likewise.
	(ctf_dump_header_strfield): Do not assume all errors to be ENOMEM.
	(ctf_dump_header_sectfield): Do not assume all errors to be ENOMEM.
	(ctf_dump_header): Likewise.
	(ctf_dump_label): likewise.
	(ctf_dump_objts): likewise.
	(ctf_dump_funcs): likewise.
	(ctf_dump_var): likewise.
	(ctf_dump_str): Likewise.
2019-10-03 17:04:56 +01:00
..
ChangeLog libctf: handle nonrepresentable types at link time 2019-10-03 17:04:56 +01:00
Makefile.am libctf: installable libctf as a shared library 2019-10-03 17:04:56 +01:00
Makefile.in libctf: installable libctf as a shared library 2019-10-03 17:04:56 +01:00
aclocal.m4 libctf: installable libctf as a shared library 2019-10-03 17:04:56 +01:00
config.h.in libctf: installable libctf as a shared library 2019-10-03 17:04:56 +01:00
configure libctf: installable libctf as a shared library 2019-10-03 17:04:56 +01:00
configure.ac libctf: installable libctf as a shared library 2019-10-03 17:04:56 +01:00
ctf-archive.c libctf: actually close bfds we have opened 2019-10-03 17:04:55 +01:00
ctf-create.c libctf: handle nonrepresentable types at link time 2019-10-03 17:04:56 +01:00
ctf-decl.c libctf: core type lookup 2019-05-28 17:08:14 +01:00
ctf-decls.h libctf: avoid strndup 2019-06-07 13:46:39 +01:00
ctf-dump.c libctf: handle nonrepresentable types at link time 2019-10-03 17:04:56 +01:00
ctf-endian.h libctf: make it compile for old glibc 2019-10-03 17:04:55 +01:00
ctf-error.c libctf: handle nonrepresentable types at link time 2019-10-03 17:04:56 +01:00
ctf-hash.c libctf: don't leak hash keys or values on value replacement 2019-10-03 17:04:55 +01:00
ctf-impl.h libctf: get rid of a disruptive public include of <sys/param.h> 2019-10-03 17:04:55 +01:00
ctf-labels.c libctf: fix a number of build problems found on Solaris and NetBSD 2019-05-31 11:10:51 +02:00
ctf-link.c libctf: handle nonrepresentable types at link time 2019-10-03 17:04:56 +01:00
ctf-lookup.c libctf: introduce ctf_func_type_{info,args}, ctf_type_aname_raw 2019-07-18 20:53:57 +01:00
ctf-open-bfd.c libctf: actually close bfds we have opened 2019-10-03 17:04:55 +01:00
ctf-open.c libctf: eschew C99 for loop initial declarations 2019-10-03 17:04:55 +01:00
ctf-qsort_r.c libctf: look for BSD versus GNU qsort_r signatures 2019-06-04 17:05:08 +01:00
ctf-string.c libctf: support getting strings from the ELF strtab 2019-10-03 17:04:55 +01:00
ctf-subr.c libctf: drop mmap()-based CTF data allocator 2019-06-21 13:04:02 +01:00
ctf-types.c libctf: handle nonrepresentable types at link time 2019-10-03 17:04:56 +01:00
ctf-util.c libctf: deduplicate and sort the string table 2019-07-01 11:05:59 +01:00
elf.h libctf: low-level list manipulation and helper utilities 2019-05-28 17:07:19 +01:00
libctf.ver libctf: installable libctf as a shared library 2019-10-03 17:04:56 +01:00
swap.h libctf: fix a number of build problems found on Solaris and NetBSD 2019-05-31 11:10:51 +02:00