binutils-gdb/ld/testsuite/ld-ctf/array-extern.d
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

33 lines
571 B
Makefile

#as:
#source: array-char.c
#source: array-extern.c
#objdump: --ctf
#ld: -shared --ctf-variables --hash-style=sysv
#name: Arrays (extern)
.*: +file format .*
Contents of CTF section .ctf:
Header:
Magic number: 0xdff2
Version: 4 \(CTF_VERSION_3\)
#...
Data object section: .* \(0x[1-9a-f][0-9a-f]* bytes\)
Type section: .* \(0x44 bytes\)
String section: .*
Labels:
Data objects:
digits_names -> 0x[0-9a-f]*: \(kind 4\) char \*\[10\] .*
Function objects:
Variables:
Types:
#...
0x[0-9a-f]*: \(kind 4\) .*\[10\] \(size .*
#...