binutils-gdb/libctf/ctf-error.c
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

97 lines
4.4 KiB
C

/* Error table.
Copyright (C) 2019 Free Software Foundation, Inc.
This file is part of libctf.
libctf is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3, or (at your option) any later
version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not see
<http://www.gnu.org/licenses/>. */
#include <ctf-impl.h>
static const char *const _ctf_errlist[] = {
"File is not in CTF or ELF format", /* ECTF_FMT */
"BFD error", /* ECTF_BFDERR */
"File uses more recent CTF version than libctf", /* ECTF_CTFVERS */
"Ambiguous BFD target", /* ECTF_BFD_AMBIGUOUS */
"Symbol table uses invalid entry size", /* ECTF_SYMTAB */
"Symbol table data buffer is not valid", /* ECTF_SYMBAD */
"String table data buffer is not valid", /* ECTF_STRBAD */
"File data structure corruption detected", /* ECTF_CORRUPT */
"File does not contain CTF data", /* ECTF_NOCTFDATA */
"Buffer does not contain CTF data", /* ECTF_NOCTFBUF */
"Symbol table information is not available", /* ECTF_NOSYMTAB */
"Type information is in parent and unavailable", /* ECTF_NOPARENT */
"Cannot import types with different data model", /* ECTF_DMODEL */
"File added to link too late", /* ECTF_LINKADDEDLATE */
"Failed to allocate (de)compression buffer", /* ECTF_ZALLOC */
"Failed to decompress CTF data", /* ECTF_DECOMPRESS */
"External string table is not available", /* ECTF_STRTAB */
"String name offset is corrupt", /* ECTF_BADNAME */
"Invalid type identifier", /* ECTF_BADID */
"Type is not a struct or union", /* ECTF_NOTSOU */
"Type is not an enum", /* ECTF_NOTENUM */
"Type is not a struct, union, or enum", /* ECTF_NOTSUE */
"Type is not an integer, float, or enum", /* ECTF_NOTINTFP */
"Type is not an array", /* ECTF_NOTARRAY */
"Type does not reference another type", /* ECTF_NOTREF */
"Input buffer is too small for type name", /* ECTF_NAMELEN */
"No type information available for that name", /* ECTF_NOTYPE */
"Syntax error in type name", /* ECTF_SYNTAX */
"Symbol table entry or type is not a function", /* ECTF_NOTFUNC */
"No function information available for symbol", /* ECTF_NOFUNCDAT */
"Symbol table entry is not a data object", /* ECTF_NOTDATA */
"No type information available for symbol", /* ECTF_NOTYPEDAT */
"No label information available for that name", /* ECTF_NOLABEL */
"File does not contain any labels", /* ECTF_NOLABELDATA */
"Feature not supported", /* ECTF_NOTSUP */
"Invalid enum element name", /* ECTF_NOENUMNAM */
"Invalid member name", /* ECTF_NOMEMBNAM */
"CTF container is read-only", /* ECTF_RDONLY */
"Limit on number of dynamic type members reached", /* ECTF_DTFULL */
"Limit on number of dynamic types reached", /* ECTF_FULL */
"Duplicate member or variable name", /* ECTF_DUPLICATE */
"Conflicting type is already defined", /* ECTF_CONFLICT */
"Attempt to roll back past a ctf_update", /* ECTF_OVERROLLBACK */
"Failed to compress CTF data", /* ECTF_COMPRESS */
"Failed to create CTF archive", /* ECTF_ARCREATE */
"Name not found in CTF archive", /* ECTF_ARNNAME */
"Overflow of type bitness or offset in slice", /* ECTF_SLICEOVERFLOW */
"Unknown section number in dump", /* ECTF_DUMPSECTUNKNOWN */
"Section changed in middle of dump", /* ECTF_DUMPSECTCHANGED */
"Feature not yet implemented", /* ECTF_NOTYET */
"Internal error in link", /* ECTF_INTERNAL */
"Type not representable in CTF" /* ECTF_NONREPRESENTABLE */
};
static const int _ctf_nerr = sizeof (_ctf_errlist) / sizeof (_ctf_errlist[0]);
const char *
ctf_errmsg (int error)
{
const char *str;
if (error >= ECTF_BASE && (error - ECTF_BASE) < _ctf_nerr)
str = _ctf_errlist[error - ECTF_BASE];
else
str = ctf_strerror (error);
return (str ? str : "Unknown error");
}
int
ctf_errno (ctf_file_t * fp)
{
return fp->ctf_errno;
}