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
testsuite
.gitignore
aclocal.m4
ChangeLog
ChangeLog-2020
config.h.in
configure libtool.m4: fix the NM="/nm/over/here -B/option/with/path" case 2022-03-25 12:02:35 +00:00
configure.ac
ctf-archive.c
ctf-create.c
ctf-decl.c
ctf-decls.h
ctf-dedup.c libctf: impose an ordering on conflicting types 2022-04-28 11:47:12 +01:00
ctf-dump.c
ctf-endian.h
ctf-error.c
ctf-hash.c
ctf-impl.h libctf: add LIBCTF_WRITE_FOREIGN_ENDIAN debugging option 2022-03-23 13:48:32 +00:00
ctf-inlines.h
ctf-intl.h
ctf-labels.c
ctf-link.c
ctf-lookup.c
ctf-open-bfd.c
ctf-open.c libctf: add LIBCTF_WRITE_FOREIGN_ENDIAN debugging option 2022-03-23 13:48:32 +00:00
ctf-qsort_r.c
ctf-serialize.c libctf: add LIBCTF_WRITE_FOREIGN_ENDIAN debugging option 2022-03-23 13:48:32 +00:00
ctf-sha1.c
ctf-sha1.h
ctf-string.c
ctf-subr.c
ctf-types.c
ctf-util.c
elf.h
libctf.ver
Makefile.am
Makefile.in
NEWS
swap.h