binutils-gdb/libctf
Nick Alcock 53651de80f libctf, include: support foreign-endianness symtabs with CTF
The CTF symbol lookup machinery added recently has one deficit: it
assumes the symtab is in the machine's native endianness.  This is
always true when the linker is writing out symtabs (because cross
linkers byteswap symbols only after libctf has been called on them), but
may be untrue in the cross case when the linker or another tool
(objdump, etc) is reading them.

Unfortunately the easy way to model this to the caller, as an endianness
field in the ctf_sect_t, is precluded because doing so would change the
size of the ctf_sect_t, which would be an ABI break.  So, instead, allow
the endianness of the symtab to be set after open time, by calling one
of the two new API functions ctf_symsect_endianness (for ctf_dict_t's)
or ctf_arc_symsect_endianness (for entire ctf_archive_t's).  libctf
calls these functions automatically for objects opened via any of the
BFD-aware mechanisms (ctf_bfdopen, ctf_bfdopen_ctfsect, ctf_fdopen,
ctf_open, or ctf_arc_open), but the various mechanisms that just take
raw ctf_sect_t's will assume the symtab is in native endianness and need
a later call to ctf_*symsect_endianness to adjust it if needed.  (This
call is basically free if the endianness is actually native: it only
costs anything if the symtab endianness was previously guessed wrong,
and there is a symtab, and we are using it directly rather than using
symtab indexing.)

Obviously, calling ctf_lookup_by_symbol or ctf_symbol_next before the
symtab endianness is correctly set will probably give wrong answers --
but you can set it at any time as long as it is before then.

include/ChangeLog
2020-11-23  Nick Alcock  <nick.alcock@oracle.com>

	* ctf-api.h: Style nit: remove () on function names in comments.
	(ctf_sect_t): Mention endianness concerns.
	(ctf_symsect_endianness): New declaration.
	(ctf_arc_symsect_endianness): Likewise.

libctf/ChangeLog
2020-11-23  Nick Alcock  <nick.alcock@oracle.com>

	* ctf-impl.h (ctf_dict_t) <ctf_symtab_little_endian>: New.
	(struct ctf_archive_internal) <ctfi_symsect_little_endian>: Likewise.
	* ctf-create.c (ctf_serialize): Adjust for new field.
	* ctf-open.c (init_symtab): Note the semantics of repeated calls.
	(ctf_symsect_endianness): New.
	(ctf_bufopen_internal): Set ctf_symtab_little_endian suitably for
	the native endianness.
	(_Static_assert): Moved...
	(swap_thing): ... with this...
	* swap.h: ... to here.
	* ctf-util.c (ctf_elf32_to_link_sym): Use it, byteswapping the
	Elf32_Sym if the ctf_symtab_little_endian demands it.
	(ctf_elf64_to_link_sym): Likewise swap the Elf64_Sym if needed.
	* ctf-archive.c (ctf_arc_symsect_endianness): New, set the
	endianness of the symtab used by the dicts in an archive.
	(ctf_archive_iter_internal): Initialize to unknown (assumed native,
	do not call ctf_symsect_endianness).
	(ctf_dict_open_by_offset): Call ctf_symsect_endianness if need be.
	(ctf_dict_open_internal): Propagate the endianness down.
	(ctf_dict_open_sections): Likewise.
	* ctf-open-bfd.c (ctf_bfdopen_ctfsect): Get the endianness from the
	struct bfd and pass it down to the archive.
	* libctf.ver: Add ctf_symsect_endianness and
	ctf_arc_symsect_endianness.
2020-11-25 19:11:35 +00:00
..
.gitignore libctf: restructure error handling to reduce relocations 2020-07-22 17:57:20 +01:00
aclocal.m4 libctf, dedup: add new configure option --enable-libctf-hash-debugging 2020-07-22 18:02:19 +01:00
ChangeLog libctf, include: support foreign-endianness symtabs with CTF 2020-11-25 19:11:35 +00:00
config.h.in libctf, dedup: add deduplicator 2020-07-22 18:02:19 +01:00
configure libctf, binutils: initial work towards libctf gettextization 2020-08-27 13:14:10 +01:00
configure.ac libctf, binutils: initial work towards libctf gettextization 2020-08-27 13:14:10 +01:00
ctf-archive.c libctf, include: support foreign-endianness symtabs with CTF 2020-11-25 19:11:35 +00:00
ctf-create.c libctf, include: support foreign-endianness symtabs with CTF 2020-11-25 19:11:35 +00:00
ctf-decl.c libctf, include, binutils, gdb, ld: rename ctf_file_t to ctf_dict_t 2020-11-20 13:34:04 +00:00
ctf-decls.h libctf, dedup: add deduplicator 2020-07-22 18:02:19 +01:00
ctf-dedup.c libctf, ld: properly deduplicate function types 2020-11-20 13:34:10 +00:00
ctf-dump.c libctf: adjust dumper for symtypetab changes 2020-11-20 13:34:09 +00:00
ctf-endian.h Update year range in copyright notice of binutils files 2020-01-01 18:42:54 +10:30
ctf-error.c libctf, include, binutils, gdb, ld: rename ctf_file_t to ctf_dict_t 2020-11-20 13:34:04 +00:00
ctf-hash.c libctf: symbol type linking support 2020-11-20 13:34:08 +00:00
ctf-impl.h libctf, include: support foreign-endianness symtabs with CTF 2020-11-25 19:11:35 +00:00
ctf-inlines.h libctf, include, binutils, gdb, ld: rename ctf_file_t to ctf_dict_t 2020-11-20 13:34:04 +00:00
ctf-intl.h libctf, binutils: initial work towards libctf gettextization 2020-08-27 13:14:10 +01:00
ctf-labels.c libctf, include, binutils, gdb, ld: rename ctf_file_t to ctf_dict_t 2020-11-20 13:34:04 +00:00
ctf-link.c libctf: do not crash when CTF symbol or variable linking fails 2020-11-20 13:34:13 +00:00
ctf-lookup.c libctf: symbol type linking support 2020-11-20 13:34:08 +00:00
ctf-open-bfd.c libctf, include: support foreign-endianness symtabs with CTF 2020-11-25 19:11:35 +00:00
ctf-open.c libctf, include: support foreign-endianness symtabs with CTF 2020-11-25 19:11:35 +00:00
ctf-qsort_r.c Update year range in copyright notice of binutils files 2020-01-01 18:42:54 +10:30
ctf-sha1.c libctf: add SHA-1 support for libctf 2020-07-22 18:02:18 +01:00
ctf-sha1.h libctf: add SHA-1 support for libctf 2020-07-22 18:02:18 +01:00
ctf-string.c libctf: symbol type linking support 2020-11-20 13:34:08 +00:00
ctf-subr.c libctf: error-handling fixes 2020-11-20 13:34:12 +00:00
ctf-types.c libctf: symbol type linking support 2020-11-20 13:34:08 +00:00
ctf-util.c libctf, include: support foreign-endianness symtabs with CTF 2020-11-25 19:11:35 +00:00
elf.h Update year range in copyright notice of binutils files 2020-01-01 18:42:54 +10:30
libctf.ver libctf, include: support foreign-endianness symtabs with CTF 2020-11-25 19:11:35 +00:00
Makefile.am Remove libctf/mkerrors.sed 2020-10-21 11:52:17 -06:00
Makefile.in Remove libctf/mkerrors.sed 2020-10-21 11:52:17 -06:00
swap.h libctf, include: support foreign-endianness symtabs with CTF 2020-11-25 19:11:35 +00:00