binutils-gdb/libctf
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
..
doc libctf: delete unused libctf_TEXINFOS 2022-02-11 04:20:49 -05:00
testsuite Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
.gitignore libctf: restructure error handling to reduce relocations 2020-07-22 17:57:20 +01:00
aclocal.m4 Implement a workaround for GNU mak jobserver 2021-01-12 05:45:44 -08:00
ChangeLog Add markers for 2.38 branch 2022-01-22 12:08:55 +00:00
ChangeLog-2020 libctf: fix old ChangeLog typo 2021-01-05 14:53:40 +00:00
config.h.in libctf, dedup: add deduplicator 2020-07-22 18:02:19 +01:00
configure libtool.m4: fix the NM="/nm/over/here -B/option/with/path" case 2022-03-25 12:02:35 +00:00
configure.ac Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
ctf-archive.c Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
ctf-create.c Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
ctf-decl.c Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
ctf-decls.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
ctf-dedup.c libctf: impose an ordering on conflicting types 2022-04-28 11:47:12 +01:00
ctf-dump.c Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
ctf-endian.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
ctf-error.c Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
ctf-hash.c Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
ctf-impl.h libctf: add LIBCTF_WRITE_FOREIGN_ENDIAN debugging option 2022-03-23 13:48:32 +00:00
ctf-inlines.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
ctf-intl.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
ctf-labels.c Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
ctf-link.c include, libctf, ld: extend variable section to contain functions too 2022-03-23 13:48:32 +00:00
ctf-lookup.c Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
ctf-open-bfd.c Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
ctf-open.c libctf: add LIBCTF_WRITE_FOREIGN_ENDIAN debugging option 2022-03-23 13:48:32 +00:00
ctf-qsort_r.c Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
ctf-serialize.c libctf: add LIBCTF_WRITE_FOREIGN_ENDIAN debugging option 2022-03-23 13:48:32 +00:00
ctf-sha1.c Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
ctf-sha1.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
ctf-string.c Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
ctf-subr.c Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
ctf-types.c Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
ctf-util.c Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
elf.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
libctf.ver Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
Makefile.am Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
Makefile.in libctf: delete unused libctf_TEXINFOS 2022-02-11 04:20:49 -05:00
NEWS include, libctf, ld: extend variable section to contain functions too 2022-03-23 13:48:32 +00:00
swap.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30