binutils-gdb/ld/testsuite/ld-ctf
Nick Alcock f8da1a05db
libctf: dedup: enums with overlapping enumerators are conflicting
The CTF deduplicator was not considering enumerators inside enum types to be
things that caused type conflicts, so if the following two TUs were linked
together, you would end up with the following in the resulting dict:

1.c:
enum foo { A, B };

2.c:
enum bar { A, B };

linked:

enum foo { A, B };
enum bar { A, B };

This does work -- but it's not something that's valid C, and the general
point of the shared dict is that it is something that you could potentially
get from any valid C TU.

So consider such types to be conflicting, but obviously don't consider
actually identical enums to be conflicting, even though they too have (all)
their identifiers in common.  This involves surprisingly little code. The
deduplicator detects conflicting types by counting types in a hash table of
hash tables:

decorated identifier -> (type hash -> count)

where the COUNT is the number of times a given hash has been observed: any
name with more than one hash associated with it is considered conflicting
(the count is used to identify the most common such name for promotion to
the shared dict).

Before now, those identifiers were all the identifiers of types (possibly
decorated with their namespace on the front for enumerator identifiers), but
we can equally well put *enumeration constant names* in there, undecorated
like the identifiers of types in the global namespace, with the type hash
being the hash of each enum containing that enumerator.  The existing
conflicting-type-detection code will then accurately identify distinct enums
with enumeration constants in common.  The enum that contains the most
commonly-appearing enumerators will be promoted to the shared dict.

libctf/
	* ctf-impl.h (ctf_dedup_t) <cd_name_counts>: Extend comment.
	* ctf-dedup.c (ctf_dedup_count_name): New, split out of...
	(ctf_dedup_populate_mappings): ... here.  Call it for all
	* enumeration constants in an enum as well as types.

ld/
	* testsuite/ld-ctf/enum-3.c: New test CTF.
	* testsuite/ld-ctf/enum-4.c: Likewise.
	* testsuite/ld-ctf/overlapping-enums.d: New test.
	* testsuite/ld-ctf/overlapping-enums-2.d: Likewise.
2024-06-18 13:20:31 +01:00
..
A-2.c
A.c
array-char-conflicting-1.c
array-char-conflicting-2.c
array-char.c
array-conflicted-ordering.d
array-extern.c
array-extern.d
array-int.c
array.d
B-2.c
B.c
C-2.c
C.c
child-float.c
child-int.c
conflicting-cycle-1.B-1.d
conflicting-cycle-1.B-2.d
conflicting-cycle-1.parent.d
conflicting-cycle-2.A-1.d
conflicting-cycle-2.A-2.d
conflicting-cycle-2.parent.d
conflicting-cycle-3.C-1.d
conflicting-cycle-3.C-2.d
conflicting-cycle-3.parent.d
conflicting-enums.d
conflicting-typedefs.d
cross-tu-1.c
cross-tu-2.c
cross-tu-conflicting-2.c
cross-tu-cyclic-1.c
cross-tu-cyclic-2.c
cross-tu-cyclic-3.c
cross-tu-cyclic-4.c
cross-tu-cyclic-conflicting.d
cross-tu-cyclic-nonconflicting.d
cross-tu-into-cycle.d
cross-tu-noncyclic.d
ctf.exp
cycle-1.c
cycle-1.d
cycle-2.A.d
cycle-2.B.d
cycle-2.C.d
data-func-1.c
data-func-2.c
data-func-conflicted-vars.d
data-func-conflicted.d
diag-ctf-version-0.d
diag-ctf-version-0.s
diag-ctf-version-2-unsupported-feature.d
diag-ctf-version-2-unsupported-feature.s
diag-ctf-version-f.d
diag-ctf-version-f.s
diag-cttname-invalid.d
diag-cttname-invalid.s
diag-cttname-null.d
diag-cttname-null.s
diag-cuname.d
diag-cuname.s
diag-decompression-failure.d
diag-decompression-failure.s
diag-parlabel.d
diag-parlabel.s
diag-parname.d
diag-parname.s
diag-strlen-invalid.d
diag-strlen-invalid.s
diag-unsupported-flag.d
diag-unsupported-flag.s
diag-wrong-magic-number-mixed.d
diag-wrong-magic-number.d
diag-wrong-magic-number.s
enum-2.c
enum-3.c libctf: dedup: enums with overlapping enumerators are conflicting 2024-06-18 13:20:31 +01:00
enum-4.c libctf: dedup: enums with overlapping enumerators are conflicting 2024-06-18 13:20:31 +01:00
enum-forward.c
enum-forward.d
enum.c
enums.c
enums.d
forward.c
forward.d
function.c
function.d
nonrepresentable-1.c
nonrepresentable-2.c
nonrepresentable-member.c
nonrepresentable-member.d
nonrepresentable.d
overlapping-enums-2.d libctf: dedup: enums with overlapping enumerators are conflicting 2024-06-18 13:20:31 +01:00
overlapping-enums.d libctf: dedup: enums with overlapping enumerators are conflicting 2024-06-18 13:20:31 +01:00
slice.c
slice.d
super-sub-cycles.c
super-sub-cycles.d
typedef-int.c
typedef-long.c
union-1.c