]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
libctf: actually deduplicate the strtab
authorNick Alcock <nick.alcock@oracle.com>
Mon, 15 Jul 2024 22:29:02 +0000 (23:29 +0100)
committerNick Alcock <nick.alcock@oracle.com>
Fri, 28 Feb 2025 14:47:24 +0000 (14:47 +0000)
commit4d2d5afa6078355074fa284c49a2cad2657fd367
treed38db3ac404980d4163baff5f5464b82954c356f
parent9daceda7960df4b142d5c925eb16e813469978c3
libctf: actually deduplicate the strtab

This commit finally implements strtab deduplication, putting together all
the pieces assembled in the earlier commits.

The magic is entirely localized to ctf_link_write, which preserializes all
the dicts (parent first), and calls ctf_dedup_strings on the parent.

(The error paths get tweaked a bit too.)

Calling ctf_dedup_strings has implications elsewhere: the lifetime rules for
the inputs versus outputs change a bit now that the child output dicts
contain references to the parent dict's atoms table.  We also pre-purge
movable refs from all the deduplicated strings before freeing any of this
because movable refs contain backreferences into the dict they came from,
which means the parent contains references to all the children!  Purging
the refs first makes those references go away so we can free the children
without creating any wild pointers, even temporarily.

There's a new testcase that identifies a regression whereby offset 0 (the
null string) and index 0 (in children now often the parent dict name,
".ctf") got mixed up, leading to anonymous structs and unions getting the
not entirely C-valid name ".ctf" instead.

May other testcases get adjusted to no longer depend on the precise layout
of the strtab.

TODO: add new tests to verify that strings are actually being deduplicated.

libctf/
* ctf-link.c (ctf_link_write): Deduplicate strings.
* ctf-open.c (ctf_dict_close): Free refs, then the link outputs,
        then the out cu_mapping, then the inputs, in that order.
        * ctf-string.c (ctf_str_purge_refs): Not static any more.
* ctf-impl.h: Declare it.

ld/
* testsuite/ld-ctf/conflicting-cycle-2.A-1.d: Don't depend on
        strtab contents.
* testsuite/ld-ctf/conflicting-cycle-2.A-2.d: Likewise.
* testsuite/ld-ctf/conflicting-cycle-2.parent.d: Likewise.
* testsuite/ld-ctf/conflicting-cycle-3.C-1.d: Likewise.
* testsuite/ld-ctf/conflicting-cycle-3.C-2.d: Likewise.
* testsuite/ld-ctf/anonymous-conflicts*: New test.
12 files changed:
ld/testsuite/ld-ctf/anonymous-conflicts-B.c [new file with mode: 0644]
ld/testsuite/ld-ctf/anonymous-conflicts.c [new file with mode: 0644]
ld/testsuite/ld-ctf/anonymous-conflicts.d [new file with mode: 0644]
ld/testsuite/ld-ctf/conflicting-cycle-2.A-1.d
ld/testsuite/ld-ctf/conflicting-cycle-2.A-2.d
ld/testsuite/ld-ctf/conflicting-cycle-2.parent.d
ld/testsuite/ld-ctf/conflicting-cycle-3.C-1.d
ld/testsuite/ld-ctf/conflicting-cycle-3.C-2.d
libctf/ctf-impl.h
libctf/ctf-link.c
libctf/ctf-open.c
libctf/ctf-string.c