binutils-gdb/libctf
Nick Alcock faf5e6ace8 libctf: add LIBCTF_WRITE_FOREIGN_ENDIAN debugging option
libctf has always handled endianness differences by detecting
foreign-endian CTF dicts on the input and endian-flipping them: dicts
are always written in native endianness.  This makes endian-awareness
very low overhead, but it means that the foreign-endian code paths
almost never get routinely tested, since "make check" usually reads in
dicts ld has just written out: only a few corrupted-CTF tests are
actually in fixed endianness, and even they only test the foreign-
endian code paths when you run make check on a big-endian machine.
(And the fix is surely not to add more .s-based tests like that, because
they are a nightmare to maintain compared to the C-code-based ones.)

To improve on this, add a new environment variable,
LIBCTF_WRITE_FOREIGN_ENDIAN, which causes libctf to unconditionally
endian-flip at ctf_write time, so the output is always in the wrong
endianness.  This then tests the foreign-endian read paths properly
at open time.

Make this easier by restructuring the writeout code in ctf-serialize.c,
which duplicates the maybe-gzip-and-write-out code three times (once
for ctf_write_mem, with thresholding, and once each for
ctf_compress_write and ctf_write just so those can avoid thresholding
and/or compression).  Instead, have the latter two call the former
with thresholds of 0 or (size_t) -1, respectively.

The endian-flipping code itself gains a bit of complexity, because
one single endian-flipper (flip_types) was assuming the input to be
in foreign-endian form and assuming it could pull things out of the
input once they had been flipped and make sense of them. At the
cost of a few lines of duplicated initializations, teach it to
read before flipping if we're flipping to foreign-endianness instead
of away from it.

libctf/
	* ctf-impl.h (ctf_flip_header): No longer static.
	(ctf_flip): Likewise.
	* ctf-open.c (flip_header): Rename to...
	(ctf_flip_header): ... this, now it is not private to one file.
	(flip_ctf): Rename...
	(ctf_flip): ... this too.  Add FOREIGN_ENDIAN arg.
	(flip_types): Likewise.  Use it.
	(ctf_bufopen_internal): Adjust calls.
	* ctf-serialize.c (ctf_write_mem): Add flip_endian path via
	a newly-allocated bounce buffer.
	(ctf_compress_write): Move below ctf_write_mem and reimplement
	in terms of it.
	(ctf_write): Likewise.
	(ctf_gzwrite): Note that this obscure writeout function does not
	support endian-flipping.
2022-03-23 13:48:32 +00: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
aclocal.m4
ChangeLog Add markers for 2.38 branch 2022-01-22 12:08:55 +00:00
ChangeLog-2020
config.h.in
configure libctf: re-generate configure 2021-12-02 07:51:57 -05: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 Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
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