libctf, ld: prohibit getting the size or alignment of forwards
C allows you to do only a very few things with entities of incomplete
type (as opposed to pointers to them): make pointers to them and give
them cv-quals, roughly. In particular you can't sizeof them and you
can't get their alignment.
We cannot impose all the requirements the standard imposes on CTF users,
because the deduplicator can transform any structure type into a forward
for the purposes of breaking cycles: so CTF type graphs can easily
contain things like arrays of forward type (if you want to figure out
their size or alignment, you need to chase down the types this forward
might be a forward to in child TU dicts: we will soon add API functions
to make doing this much easier).
Nonetheless, it is still meaningless to ask for the size or alignment of
forwards: but libctf didn't prohibit this and returned nonsense from
internal implementation details when you asked (it returned the kind of
the pointed-to type as both the size and alignment, because forwards
reuse ctt_type as a type kind, and ctt_type and ctt_size overlap). So
introduce a new error, ECTF_INCOMPLETE, which is returned when you try
to get the size or alignment of forwards: we also return it when you try
to do things that require libctf itself to get the size or alignment of
a forward, notably using a forward as an array index type (which C
should never do in any case) or adding forwards to structures without
specifying their offset explicitly.
The dumper will not emit size or alignment info for forwards any more.
(This should not be an API break since ctf_type_size and ctf_type_align
could both return errors before now: any code that isn't expecting error
returns is already potentially broken.)
include/ChangeLog
2021-01-05 Nick Alcock <nick.alcock@oracle.com>
* ctf-api.h (ECTF_INCOMPLETE): New.
(ECTF_NERR): Adjust.
ld/ChangeLog
2021-01-05 Nick Alcock <nick.alcock@oracle.com>
* testsuite/ld-ctf/conflicting-cycle-1.parent.d: Adjust for dumper
changes.
* testsuite/ld-ctf/cross-tu-cyclic-conflicting.d: Likewise.
* testsuite/ld-ctf/forward.c: New test...
* testsuite/ld-ctf/forward.d: ... and results.
libctf/ChangeLog
2021-01-05 Nick Alcock <nick.alcock@oracle.com>
* ctf-types.c (ctf_type_resolve): Improve comment.
(ctf_type_size): Yield ECTF_INCOMPLETE when applied to forwards.
Emit errors into the right dict.
(ctf_type_align): Likewise.
* ctf-create.c (ctf_add_member_offset): Yield ECTF_INCOMPLETE
when adding a member without explicit offset when this member, or
the previous member, is incomplete.
* ctf-dump.c (ctf_dump_format_type): Do not try to print the size of
forwards.
(ctf_dump_member): Do not try to print their alignment.
2021-01-05 21:25:56 +08:00
|
|
|
|
2021-01-05 Nick Alcock <nick.alcock@oracle.com>
|
|
|
|
|
|
|
|
|
|
* ctf-types.c (ctf_type_resolve): Improve comment.
|
|
|
|
|
(ctf_type_size): Yield ECTF_INCOMPLETE when applied to forwards.
|
|
|
|
|
Emit errors into the right dict.
|
|
|
|
|
(ctf_type_align): Likewise.
|
|
|
|
|
* ctf-create.c (ctf_add_member_offset): Yield ECTF_INCOMPLETE
|
|
|
|
|
when adding a member without explicit offset when this member, or
|
|
|
|
|
the previous member, is incomplete.
|
|
|
|
|
* ctf-dump.c (ctf_dump_format_type): Do not try to print the size of
|
|
|
|
|
forwards.
|
|
|
|
|
(ctf_dump_member): Do not try to print their alignment.
|
|
|
|
|
|
2021-01-05 21:25:56 +08:00
|
|
|
|
2021-01-05 Nick Alcock <nick.alcock@oracle.com>
|
|
|
|
|
|
|
|
|
|
* ctf-dump.c (ctf_dump_objts): Dump by calling ctf_dump_format_type.
|
|
|
|
|
(ctf_dump_format_type): Don't emit the size for function objects.
|
|
|
|
|
Dump the element type of arrays like we dump the pointed-to type of
|
|
|
|
|
pointers, etc.
|
|
|
|
|
|
2021-01-05 21:25:56 +08:00
|
|
|
|
2021-01-05 Nick Alcock <nick.alcock@oracle.com>
|
|
|
|
|
|
|
|
|
|
* ctf-dump.c (ctf_dump_format_type): Add 0x to hex type IDs.
|
|
|
|
|
(ctf_dump_header): Add 0x to the hex magic number.
|
|
|
|
|
(ctf_dump_str): Add 0x to the hex string offsets.
|
|
|
|
|
(ctf_dump_membstate_t) <cdm_toplevel_indent>: New.
|
|
|
|
|
(ctf_dump_type): Adjust. Free it when we're done.
|
|
|
|
|
(type_hex_digits): New.
|
|
|
|
|
(ctf_dump_member): Align output depending on the width of the type
|
|
|
|
|
ID being generated. Use printf padding, not a loop, to generate
|
|
|
|
|
indentation.
|
|
|
|
|
|
2021-01-05 21:25:56 +08:00
|
|
|
|
2021-01-05 Nick Alcock <nick.alcock@oracle.com>
|
|
|
|
|
|
|
|
|
|
* ctf-decl.c (ctf_decl_push): Don't print array decls backwards.
|
|
|
|
|
|
2020-12-27 18:32:52 +08:00
|
|
|
|
2021-01-04 Nicolas Boulenguez <nicolas@debian.org>
|
|
|
|
|
|
|
|
|
|
PR 27117
|
|
|
|
|
* configure.ac: Make AC_CONFIG_MACRO_DIR consistent with
|
|
|
|
|
ACLOCAL_AMFLAGS -I dirs.
|
|
|
|
|
* configure: Regenerate.
|
|
|
|
|
|
2021-01-01 06:58:58 +08:00
|
|
|
|
2021-01-01 Alan Modra <amodra@gmail.com>
|
|
|
|
|
|
|
|
|
|
Update year range in copyright notice of all files.
|
|
|
|
|
|
2021-01-01 06:47:13 +08:00
|
|
|
|
For older changes see ChangeLog-2020
|
|
|
|
|
|
|
|
|
|
Copyright (C) 2021 Free Software Foundation, Inc.
|
2019-04-24 01:55:27 +08:00
|
|
|
|
|
2021-01-01 06:47:13 +08:00
|
|
|
|
Copying and distribution of this file, with or without modification,
|
|
|
|
|
are permitted in any medium without royalty provided the copyright
|
|
|
|
|
notice and this notice are preserved.
|
2019-04-24 01:55:27 +08:00
|
|
|
|
|
|
|
|
|
Local Variables:
|
|
|
|
|
mode: change-log
|
|
|
|
|
left-margin: 8
|
2021-01-01 06:47:13 +08:00
|
|
|
|
fill-column: 74
|
2019-04-24 01:55:27 +08:00
|
|
|
|
version-control: never
|
|
|
|
|
End:
|