libctf: fix linking of non-root-visible types
authorNick Alcock <nick.alcock@oracle.com>
Mon, 15 Jul 2024 18:42:10 +0000 (19:42 +0100)
committerNick Alcock <nick.alcock@oracle.com>
Thu, 1 Aug 2024 13:30:21 +0000 (14:30 +0100)
commitd0e6b0d10ddeef2d1638315a525d0e69dfaffbee
treeb65021840293bbb1eab626e6ef466d1b672d693b
parent1d30dc3485c5b251df08092de24648e439eee232
libctf: fix linking of non-root-visible types

If you deduplicate non-root-visible types, the resulting type should still
be non-root-visible! We were promoting all such types to root-visible, and
re-demoting them only if their names collided (which might happen on
cu-mapped links if multiple compilation units with conflicting types are
fused into one child dict).

This "worked" before now, in that linking at least didn't fail (if you don't
mind having your non-root flag value destroyed if you're adding
non-root-visible types), but now that conflicting enumerators cause their
containing enums to become conflicted (enums which might have *different
names*), this caused the linker to crash when it hit two enumerators with
conflicting values.

Not testable in ld because cu-mapped links are not exposed to ld, but can be
tested via direct creation of libraries and calls to ctf_link directly.
(This also tests the ctf_dump non-root type printout, which before now
was untested.)

libctf/
* ctf-dedup.c (ctf_dedup_emit_type): Non-root-visible input types
should be emitted as non-root-visible output types.
* testsuite/libctf-writable/ctf-nonroot-linking.c: New test.
* testsuite/libctf-writable/ctf-nonroot-linking.lk: New test.
libctf/ctf-dedup.c
libctf/testsuite/libctf-writable/ctf-nonroot-linking.c [new file with mode: 0644]
libctf/testsuite/libctf-writable/ctf-nonroot-linking.lk [new file with mode: 0644]