binutils-gdb/ld/testsuite/ld-ctf
Nick Alcock 95ade9a5f4 libctf: impose an ordering on conflicting types
When two types conflict and they are not types which can have forwards
(say, two arrays of different sizes with the same name in two different
TUs) the CTF deduplicator uses a popularity contest to decide what to
do: the type cited by the most other types ends up put into the shared
dict, while the others are relegated to per-CU child dicts.

This works well as long as one type *is* most popular -- but what if
there is a tie?  If several types have the same popularity count,
we end up picking the first we run across and promoting it, and
unfortunately since we are working over a dynhash in essentially
arbitrary order, this means we promote a random one.  So multiple
runs of ld with the same inputs can produce different outputs!
All the outputs are valid, but this is still undesirable.

Adjust things to use the same strategy used to sort types on the output:
when there is a tie, always put the type that appears in a CU that
appeared earlier on the link line (and if there is somehow still a tie,
which should be impossible, pick the type with the lowest type ID).

Add a testcase -- and since this emerged when trying out extern arrays,
check that those work as well (this requires a newer GCC, but since all
GCCs that can emit CTF at all are unreleased this is probably OK as
well).

Fix up one testcase that has slight type ordering changes as a result
of this change.

libctf/ChangeLog:

	* ctf-dedup.c (ctf_dedup_detect_name_ambiguity): Use
	cd_output_first_gid to break ties.

ld/ChangeLog:

	* testsuite/ld-ctf/array-conflicted-ordering.d: New test, using...
	* testsuite/ld-ctf/array-char-conflicting-1.c: ... this...
	* testsuite/ld-ctf/array-char-conflicting-2.c: ... and this.
	* testsuite/ld-ctf/array-extern.d: New test, using...
	* testsuite/ld-ctf/array-extern.c: ... this.
	* testsuite/ld-ctf/conflicting-typedefs.d: Adjust for ordering
	changes.
2022-04-28 11:47:12 +01:00
..
A-2.c
A.c
array-char-conflicting-1.c libctf: impose an ordering on conflicting types 2022-04-28 11:47:12 +01:00
array-char-conflicting-2.c libctf: impose an ordering on conflicting types 2022-04-28 11:47:12 +01:00
array-char.c
array-conflicted-ordering.d libctf: impose an ordering on conflicting types 2022-04-28 11:47:12 +01:00
array-extern.c libctf: impose an ordering on conflicting types 2022-04-28 11:47:12 +01:00
array-extern.d libctf: impose an ordering on conflicting types 2022-04-28 11:47:12 +01:00
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 libctf: impose an ordering on conflicting types 2022-04-28 11:47:12 +01:00
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 Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
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 include, libctf, ld: extend variable section to contain functions too 2022-03-23 13:48:32 +00:00
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 libctf, ld: diagnose corrupted CTF header cth_strlen 2022-03-23 13:48:32 +00:00
diag-cttname-null.d
diag-cttname-null.s libctf, ld: diagnose corrupted CTF header cth_strlen 2022-03-23 13:48:32 +00:00
diag-cuname.d
diag-cuname.s libctf, ld: diagnose corrupted CTF header cth_strlen 2022-03-23 13:48:32 +00:00
diag-decompression-failure.d
diag-decompression-failure.s
diag-parlabel.d
diag-parlabel.s libctf, ld: diagnose corrupted CTF header cth_strlen 2022-03-23 13:48:32 +00:00
diag-parname.d
diag-parname.s libctf, ld: diagnose corrupted CTF header cth_strlen 2022-03-23 13:48:32 +00:00
diag-strlen-invalid.d libctf, ld: diagnose corrupted CTF header cth_strlen 2022-03-23 13:48:32 +00:00
diag-strlen-invalid.s libctf, ld: diagnose corrupted CTF header cth_strlen 2022-03-23 13:48:32 +00:00
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-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 Adjust ld ctf test for 32-bit targets 2022-03-04 00:28:07 +10:30
slice.c
slice.d
super-sub-cycles.c
super-sub-cycles.d
typedef-int.c
typedef-long.c
union-1.c