ctf: capture all DIEs with structs/enums as their ultimate supertype
dwarf2ctf has to scan all the DWARF in the kernel repeatedly while generating
its compressed type representation: it even has to scan inside functions, even
though it is only interested in file-scope types and variables, because opaque
structure, union, or enumeration references at the top level can contain
references to a definition inside a function. Repeated scanning of gigabytes of
DWARF is slow: dwarf2ctf spends most of its time doing this, not emitting types.
To make this less abominably slow, dwarf2ctf contains a filtration mechanism to
avoid scanning or emitting DIEs which will never be useful.
An iron rule of dwarf2ctf is that *all* DIEs that are emitted as types must
first be spotted by this 'duplicate detector' scanning phase, since it not only
determines which types are duplicated but also where they should go: whether
they are shared between kernel modules (and should go into the shared type
repository in ctf.ko) or are shared between translation units in a single module
or not duplicated at all, in which case they go into the module's local CTF. So
if the filtration mechanism skips types which are later emitted, dwarf2ctf can
do little but abort (in general dwarf2ctf aborts if it finds internal
consistency problems which may affect the generation of many types, but skips
types and warns if it finds problems with single types which are not likely to
affect the generation of other types).
One of these filtration functions is filter_ctf_file_scope(). This is called to
filter out DIEs representing most qualifiers and base types when they appear
inside functions, by simply checking if the parent of the DIE is
DW_TAG_compile_unit. In GCC 4.4.x, applying this to a variety of DIEs was
sufficient to filter out all DIEs inside functions that we weren't going to emit
CTF representations of.
Unfortunately GCC has since changed its debugging information representation
somewhat in a fashion which breaks this. Inside drivers/firmware/dmi-id.c we
see the example dwarf2ctf calls out when it fails:
static const struct mafield {
const char *prefix;
int field;
} fields[] = {
[...]
{ NULL, DMI_NONE }
};
const struct mafield *f;
This is a structure inside a function, but even so GCC generates some of its
type DIEs at global scope and they are emitted into the CTF. Over time, GCC is
moving more of the DIEs into subprogram scope, but not yet all of them: this is
what has broken us.
The variable 'f' is represented by the following DIEs, where A, B, C and D are
DIE offsets:
[ A] structure_type
name (strp) "mafield"
[...]
[ B] const_type
type (ref4) [ A]
[ C] pointer_type
byte_size (data1) 8
type (ref4) [ B]
In GCC 4.4.x, all of these other than the structure_type itself are at the
global scope, not the subprogram scope, so the filter never kicks in for these
DIEs and all of them are emitted successfully. Between 4.4.x and 4.8.0, the
'const_type' moved into subprogram scope, but the pointer_type did not, so we
have a pointer_type at global scope referring to a const_type at subprogram
scope -- which has been filtered out by the filtration function, so emission of
the pointer_type fails and dwarf2ctf aborts because its type graph is
incomplete, with a type pointing at a type it has no record of.
Fix this by having filter_ctf_file_scope() look at the DW_AT_type attribute of
its target DIE, chaining to its type-attributeless terminus and note whether
that terminus is a structure, union, or enumeration: all DIEs having such types
at the terminus of their type chains must not be filtered out.
Orabug:
18117464
Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
Reviewed-by: Chuck Anderson <chuck.anderson@oracle.com>