aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorNick Alcock <nick.alcock@oracle.com>2020-11-23 21:17:44 +0000
committerNick Alcock <nick.alcock@oracle.com>2020-11-25 19:11:35 +0000
commit53651de80f811495262a5b17b774a486dd37b326 (patch)
tree597993b81493a294506b5b721204adebf995b0d9 /include
parentcbfa382abb360307c0c6b750e4c550a0d2b702d6 (diff)
downloadgdb-53651de80f811495262a5b17b774a486dd37b326.zip
gdb-53651de80f811495262a5b17b774a486dd37b326.tar.gz
gdb-53651de80f811495262a5b17b774a486dd37b326.tar.bz2
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.
Diffstat (limited to 'include')
-rw-r--r--include/ChangeLog7
-rw-r--r--include/ctf-api.h30
2 files changed, 24 insertions, 13 deletions
diff --git a/include/ChangeLog b/include/ChangeLog
index 704c9af..2816129 100644
--- a/include/ChangeLog
+++ b/include/ChangeLog
@@ -1,3 +1,10 @@
+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.
+
2020-11-20 Nick Alcock <nick.alcock@oracle.com>
* ctf-api.h (ctf_getsymsect): New.
diff --git a/include/ctf-api.h b/include/ctf-api.h
index 8687475..9dd0592 100644
--- a/include/ctf-api.h
+++ b/include/ctf-api.h
@@ -51,10 +51,12 @@ struct bfd;
/* If the debugger needs to provide the CTF library with a set of raw buffers
for use as the CTF data, symbol table, and string table, it can do so by
- filling in ctf_sect_t structures and passing them to ctf_bufopen().
+ filling in ctf_sect_t structures and passing them to ctf_bufopen.
- The contents of this structure must always be in native endianness (no
- byteswapping is performed). */
+ The contents of this structure must always be in native endianness. At read
+ time, the symbol table endianness is derived from the BFD target (if BFD is
+ in use): if a BFD target is not in use, please call ctf_symsect_endianness or
+ ctf_arc_symsect_endianness. */
typedef struct ctf_sect
{
@@ -67,12 +69,12 @@ typedef struct ctf_sect
/* A minimal symbol extracted from a linker's internal symbol table
representation. The symbol name can be given either via st_name or via a
strtab offset in st_nameidx, which corresponds to one of the string offsets
- communicated via the ctf_link_add_strtab callback. */
+ communicated via the ctf_link_add_strtab callback. */
typedef struct ctf_link_sym
{
/* The st_name and st_nameidx will not be accessed outside the call to
- ctf_link_shuffle_syms(). If you set st_nameidx to offset zero, make sure
+ ctf_link_shuffle_syms. If you set st_nameidx to offset zero, make sure
to set st_nameidx_set as well. */
const char *st_name;
@@ -118,7 +120,7 @@ typedef enum ctf_sect_names
} ctf_sect_names_t;
/* Encoding information for integers, floating-point values, and certain other
- intrinsics can be obtained by calling ctf_type_encoding(), below. The flags
+ intrinsics can be obtained by calling ctf_type_encoding, below. The flags
field will contain values appropriate for the type defined in <ctf.h>. */
typedef struct ctf_encoding
@@ -162,8 +164,8 @@ typedef struct ctf_snapshot_id
#define CTF_FUNC_VARARG 0x1 /* Function arguments end with varargs. */
/* Functions that return a ctf_id_t use the following value to indicate failure.
- ctf_errno() can be used to obtain an error code. Functions that return
- a straight integral -1 also use ctf_errno(). */
+ ctf_errno can be used to obtain an error code. Functions that return
+ a straight integral -1 also use ctf_errno. */
#define CTF_ERR ((ctf_id_t) -1L)
/* This macro holds information about all the available ctf errors.
@@ -244,7 +246,7 @@ _CTF_ERRORS
#define ECTF_NERR (ECTF_NEEDSBFD - ECTF_BASE + 1) /* Count of CTF errors. */
/* The CTF data model is inferred to be the caller's data model or the data
- model of the given object, unless ctf_setmodel() is explicitly called. */
+ model of the given object, unless ctf_setmodel is explicitly called. */
#define CTF_MODEL_ILP32 1 /* Object data model is ILP32. */
#define CTF_MODEL_LP64 2 /* Object data model is LP64. */
#ifdef _LP64
@@ -253,7 +255,7 @@ _CTF_ERRORS
# define CTF_MODEL_NATIVE CTF_MODEL_ILP32
#endif
-/* Dynamic CTF containers can be created using ctf_create(). The ctf_add_*
+/* Dynamic CTF containers can be created using ctf_create. The ctf_add_*
routines can be used to add new definitions to the dynamic container.
New types are labeled as root or non-root to determine whether they are
visible at the top-level program scope when subsequently doing a lookup. */
@@ -283,9 +285,9 @@ typedef char *ctf_dump_decorate_f (ctf_sect_names_t sect,
typedef struct ctf_dump_state ctf_dump_state_t;
-/* Iteration state for the _next() functions, and allocators/copiers/freers for
+/* Iteration state for the _next functions, and allocators/copiers/freers for
it. (None of these are needed for the simple case of iterating to the end:
- the _next() function allocate and free the iterators for you.) */
+ the _next function allocate and free the iterators for you.) */
typedef struct ctf_next ctf_next_t;
extern ctf_next_t *ctf_next_create (void);
@@ -295,7 +297,7 @@ extern ctf_next_t *ctf_next_copy (ctf_next_t *);
/* Opening. These mostly return an abstraction over both CTF files and CTF
archives: so they can be used to open both. CTF files will appear to be an
archive with one member named '.ctf'. The low-level functions
- ctf_simple_open() and ctf_bufopen() return ctf_dict_t's directly, and cannot
+ ctf_simple_open and ctf_bufopen return ctf_dict_t's directly, and cannot
be used on CTF archives. */
extern ctf_archive_t *ctf_bfdopen (struct bfd *, int *);
@@ -309,12 +311,14 @@ extern void ctf_close (ctf_archive_t *);
extern ctf_sect_t ctf_getdatasect (const ctf_dict_t *);
extern ctf_sect_t ctf_getsymsect (const ctf_dict_t *);
extern ctf_sect_t ctf_getstrsect (const ctf_dict_t *);
+extern void ctf_symsect_endianness (ctf_dict_t *, int little_endian);
extern ctf_archive_t *ctf_get_arc (const ctf_dict_t *);
extern ctf_archive_t *ctf_arc_open (const char *, int *);
extern ctf_archive_t *ctf_arc_bufopen (const ctf_sect_t *,
const ctf_sect_t *,
const ctf_sect_t *,
int *);
+extern void ctf_arc_symsect_endianness (ctf_archive_t *, int little_endian);
extern void ctf_arc_close (ctf_archive_t *);
extern ctf_dict_t *ctf_arc_lookup_symbol (ctf_archive_t *,
unsigned long symidx,