diff options
author | Nick Alcock <nick.alcock@oracle.com> | 2021-01-05 13:25:56 +0000 |
---|---|---|
committer | Nick Alcock <nick.alcock@oracle.com> | 2021-01-05 14:53:39 +0000 |
commit | ffeece6ac2d4e4d2bf28c910b51c74ffc881c963 (patch) | |
tree | dbb61a523d3289f68a024ed1c84a4290d75b364b /ld | |
parent | 91e7ce2fd7b82f3982b453d1c6f4576621bc1c2d (diff) | |
download | fsf-binutils-gdb-ffeece6ac2d4e4d2bf28c910b51c74ffc881c963.zip fsf-binutils-gdb-ffeece6ac2d4e4d2bf28c910b51c74ffc881c963.tar.gz fsf-binutils-gdb-ffeece6ac2d4e4d2bf28c910b51c74ffc881c963.tar.bz2 |
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.
Diffstat (limited to 'ld')
-rw-r--r-- | ld/ChangeLog | 8 | ||||
-rw-r--r-- | ld/testsuite/ld-ctf/conflicting-cycle-1.parent.d | 4 | ||||
-rw-r--r-- | ld/testsuite/ld-ctf/cross-tu-cyclic-conflicting.d | 4 | ||||
-rw-r--r-- | ld/testsuite/ld-ctf/forward.c | 2 | ||||
-rw-r--r-- | ld/testsuite/ld-ctf/forward.d | 23 |
5 files changed, 37 insertions, 4 deletions
diff --git a/ld/ChangeLog b/ld/ChangeLog index a130c6c..1497fc4 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,5 +1,13 @@ 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. + +2021-01-05 Nick Alcock <nick.alcock@oracle.com> + * testsuite/ld-ctf/array.d: Adjust for dumper changes. * testsuite/ld-ctf/data-func-conflicted.d: Likewise. * testsuite/ld-ctf/diag-cttname-null.d: Likewise. diff --git a/ld/testsuite/ld-ctf/conflicting-cycle-1.parent.d b/ld/testsuite/ld-ctf/conflicting-cycle-1.parent.d index 4cbe9b6..5da66fda 100644 --- a/ld/testsuite/ld-ctf/conflicting-cycle-1.parent.d +++ b/ld/testsuite/ld-ctf/conflicting-cycle-1.parent.d @@ -29,8 +29,8 @@ Contents of CTF section .ctf: #... Types: #... - 0x[0-9a-f]*: struct B \(.* - *\[0x0\] \(ID 0x[0-9a-f]*\) \(kind 9\) struct B \(.* + 0x[0-9a-f]*: struct B + *\[0x0\] \(ID 0x[0-9a-f]*\) \(kind 9\) struct B #... CTF archive member: .*: #... diff --git a/ld/testsuite/ld-ctf/cross-tu-cyclic-conflicting.d b/ld/testsuite/ld-ctf/cross-tu-cyclic-conflicting.d index 3c975eb..eff295e 100644 --- a/ld/testsuite/ld-ctf/cross-tu-cyclic-conflicting.d +++ b/ld/testsuite/ld-ctf/cross-tu-cyclic-conflicting.d @@ -23,8 +23,8 @@ Contents of CTF section \.ctf: 0x[0-9a-f]*: int \[0x0:0x[0-9a-f]*\] \(size 0x[0-9a-f]*\) *\[0x0\] \(ID 0x[0-9a-f]*\) \(kind 1\) int:[0-9]* \(aligned at 0x[0-9a-f]*, format 0x1, offset:bits 0x0:0x[0-9a-f]*\) #... - 0x[0-9a-f]*: struct A .* - *\[0x0\] \(ID 0x[0-9a-f]*\) \(kind 9\) struct A .* + 0x[0-9a-f]*: struct A + *\[0x0\] \(ID 0x[0-9a-f]*\) \(kind 9\) struct A #... 0x[0-9a-f]*: struct C .* *\[0x0\] \(ID 0x[0-9a-f]*\) \(kind 6\) struct C .* diff --git a/ld/testsuite/ld-ctf/forward.c b/ld/testsuite/ld-ctf/forward.c new file mode 100644 index 0000000..e41a7ae --- /dev/null +++ b/ld/testsuite/ld-ctf/forward.c @@ -0,0 +1,2 @@ +struct foo; +struct foo *bar __attribute__((used)); diff --git a/ld/testsuite/ld-ctf/forward.d b/ld/testsuite/ld-ctf/forward.d new file mode 100644 index 0000000..9ff0dd2 --- /dev/null +++ b/ld/testsuite/ld-ctf/forward.d @@ -0,0 +1,23 @@ +#as: +#source: forward.c +#objdump: --ctf=.ctf +#ld: -shared +#name: Forwards + +.*: +file format .* + +Contents of CTF section .ctf: + + Header: + Magic number: 0xdff2 + Version: 4 \(CTF_VERSION_3\) +#... + Type section: .* \(0x18 bytes\) +#... + Types: + + 0x[0-9a-f]: struct foo + *\[0x0\] \(ID 0x[0-9a-f]*\) \(kind 9\) struct foo + 0x[0-9a-f]: struct foo \* \(size 0x[0-9a-f]*\) -> 0x[0-9a-f]: struct foo + *\[0x0\] \(ID 0x[0-9a-f]\) \(kind 3\) struct foo \* \(aligned at 0x[0-9a-f]*\) +#... |