diff options
author | Nick Alcock <nick.alcock@oracle.com> | 2020-11-20 13:34:04 +0000 |
---|---|---|
committer | Nick Alcock <nick.alcock@oracle.com> | 2020-11-20 13:34:07 +0000 |
commit | 3d16b64e28ab2cd7e69c0b31bc3ab1601891c969 (patch) | |
tree | 437086ea5f07f3be6400e95422735a446ce28801 /include | |
parent | 83d59285d549dab64d1be496408c0e62f30030b4 (diff) | |
download | gdb-3d16b64e28ab2cd7e69c0b31bc3ab1601891c969.zip gdb-3d16b64e28ab2cd7e69c0b31bc3ab1601891c969.tar.gz gdb-3d16b64e28ab2cd7e69c0b31bc3ab1601891c969.tar.bz2 |
bfd, include, ld, binutils, libctf: CTF should use the dynstr/sym
This is embarrassing.
The whole point of CTF is that it remains intact even after a binary is
stripped, providing a compact mapping from symbols to types for
everything in the externally-visible interface of an ELF object: it has
connections to the symbol table for that purpose, and to the string
table to avoid duplicating symbol names. So it's a shame that the hooks
I implemented last year served to hook it up to the .symtab and .strtab,
which obviously disappear on strip, leaving any accompanying the CTF
dict containing references to strings (and, soon, symbols) which don't
exist any more because their containing strtab has been vaporized. The
original Solaris design used .dynsym and .dynstr (well, actually,
.ldynsym, which has more symbols) which do not disappear. So should we.
Thankfully the work we did before serves as guide rails, and adjusting
things to use the .dynstr and .dynsym was fast and easy. The only
annoyance is that the dynsym is assembled inside elflink.c in a fairly
piecemeal fashion, so that the easiest way to get the symbols out was to
hook in before every call to swap_symbol_out (we also leave in a hook in
front of symbol additions to the .symtab because it seems plausible that
we might want to hook them in future too: for now that hook is unused).
We adjust things so that rather than being offered a whole hash table of
symbols at once, libctf is now given symbols one at a time, with st_name
indexes already resolved and pointing at their final .dynstr offsets:
it's now up to libctf to resolve these to names as needed using the
strtab info we pass it separately.
Some bits might be contentious. The ctf_new_dynstr callback takes an
elf_internal_sym, and this remains an elf_internal_sym right down
through the generic emulation layers into ldelfgen. This is no worse
than the elf_sym_strtab we used to pass down, but in the future when we
gain non-ELF CTF symtab support we might want to lower the
elf_internal_sym to some other representation (perhaps a
ctf_link_symbol) in bfd or in ldlang_ctf_new_dynsym. We rename the
'apply_strsym' hooks to 'acquire_strings' instead, becuse they no longer
have anything to do with symbols.
There are some API changes to pieces of API which are technically public
but actually totally unused by anything and/or unused by anything but ld
so they can change freely: the ctf_link_symbol gains new fields to allow
symbol names to be given as strtab offsets as well as strings, and a
symidx so that the symbol index can be passed in. ctf_link_shuffle_syms
loses its callback parameter: the idea now is that linkers call the new
ctf_link_add_linker_symbol for every symbol in .dynsym, feed in all the
strtab entries with ctf_link_add_strtab, and then a call to
ctf_link_shuffle_syms will apply both and arrange to use them to reorder
the CTF symtab at CTF serialization time (which is coming in the next
commit).
Inside libctf we have a new preamble flag CTF_F_DYNSTR which is always
set in v3-format CTF dicts from this commit forwards: CTF dicts without
this flag are associated with .strtab like they used to be, so that old
dicts' external strings don't turn to garbage when loaded by new libctf.
Dicts with this flag are associated with .dynstr and .dynsym instead.
(The flag is not the next in sequence because this commit was written
quite late: the missing flags will be filled in by the next commit.)
Tests forthcoming in a later commit in this series.
bfd/ChangeLog
2020-11-20 Nick Alcock <nick.alcock@oracle.com>
* elflink.c (elf_finalize_dynstr): Call examine_strtab after
dynstr finalization.
(elf_link_swap_symbols_out): Don't call it here. Call
ctf_new_symbol before swap_symbol_out.
(elf_link_output_extsym): Call ctf_new_dynsym before
swap_symbol_out.
(bfd_elf_final_link): Likewise.
* elf.c (swap_out_syms): Pass in bfd_link_info. Call
ctf_new_symbol before swap_symbol_out.
(_bfd_elf_compute_section_file_positions): Adjust.
binutils/ChangeLog
2020-11-20 Nick Alcock <nick.alcock@oracle.com>
* readelf.c (dump_section_as_ctf): Use .dynsym and .dynstr, not
.symtab and .strtab.
include/ChangeLog
2020-11-20 Nick Alcock <nick.alcock@oracle.com>
* bfdlink.h (struct elf_sym_strtab): Replace with...
(struct elf_internal_sym): ... this.
(struct bfd_link_callbacks) <examine_strtab>: Take only a
symstrtab argument.
<ctf_new_symbol>: New.
<ctf_new_dynsym>: Likewise.
* ctf-api.h (struct ctf_link_sym) <st_symidx>: New.
<st_nameidx>: Likewise.
<st_nameidx_set>: Likewise.
(ctf_link_iter_symbol_f): Removed.
(ctf_link_shuffle_syms): Remove most parameters, just takes a
ctf_dict_t now.
(ctf_link_add_linker_symbol): New, split from
ctf_link_shuffle_syms.
* ctf.h (CTF_F_DYNSTR): New.
(CTF_F_MAX): Adjust.
ld/ChangeLog
2020-11-20 Nick Alcock <nick.alcock@oracle.com>
* ldelfgen.c (struct ctf_strsym_iter_cb_arg): Rename to...
(struct ctf_strtab_iter_cb_arg): ... this, changing fields:
<syms>: Remove.
<symcount>: Remove.
<symstrtab>: Rename to...
<strtab>: ... this.
(ldelf_ctf_strtab_iter_cb): Adjust.
(ldelf_ctf_symbols_iter_cb): Remove.
(ldelf_new_dynsym_for_ctf): New, tell libctf about a single
symbol.
(ldelf_examine_strtab_for_ctf): Rename to...
(ldelf_acquire_strings_for_ctf): ... this, only doing the strtab
portion and not symbols.
* ldelfgen.h: Adjust declarations accordingly.
* ldemul.c (ldemul_examine_strtab_for_ctf): Rename to...
(ldemul_acquire_strings_for_ctf): ... this.
(ldemul_new_dynsym_for_ctf): New.
* ldemul.h: Adjust declarations accordingly.
* ldlang.c (ldlang_ctf_apply_strsym): Rename to...
(ldlang_ctf_acquire_strings): ... this.
(ldlang_ctf_new_dynsym): New.
(lang_write_ctf): Call ldemul_new_dynsym_for_ctf with NULL to do
the actual symbol shuffle.
* ldlang.h (struct elf_strtab_hash): Adjust accordingly.
* ldmain.c (bfd_link_callbacks): Wire up new/renamed callbacks.
libctf/ChangeLog
2020-11-20 Nick Alcock <nick.alcock@oracle.com>
* ctf-link.c (ctf_link_shuffle_syms): Adjust.
(ctf_link_add_linker_symbol): New, unimplemented stub.
* libctf.ver: Add it.
* ctf-create.c (ctf_serialize): Set CTF_F_DYNSTR on newly-serialized
dicts.
* ctf-open-bfd.c (ctf_bfdopen_ctfsect): Check for the flag: open the
symtab/strtab if not present, dynsym/dynstr otherwise.
* ctf-archive.c (ctf_arc_bufpreamble): New, get the preamble from
some arbitrary member of a CTF archive.
* ctf-impl.h (ctf_arc_bufpreamble): Declare it.
Diffstat (limited to 'include')
-rw-r--r-- | include/ChangeLog | 19 | ||||
-rw-r--r-- | include/bfdlink.h | 16 | ||||
-rw-r--r-- | include/ctf-api.h | 18 | ||||
-rw-r--r-- | include/ctf.h | 3 |
4 files changed, 43 insertions, 13 deletions
diff --git a/include/ChangeLog b/include/ChangeLog index 11ec1f4..5c0f6b9 100644 --- a/include/ChangeLog +++ b/include/ChangeLog @@ -1,5 +1,24 @@ 2020-11-20 Nick Alcock <nick.alcock@oracle.com> + * bfdlink.h (struct elf_sym_strtab): Replace with... + (struct elf_internal_sym): ... this. + (struct bfd_link_callbacks) <examine_strtab>: Take only a + symstrtab argument. + <ctf_new_symbol>: New. + <ctf_new_dynsym>: Likewise. + * ctf-api.h (struct ctf_link_sym) <st_symidx>: New. + <st_nameidx>: Likewise. + <st_nameidx_set>: Likewise. + (ctf_link_iter_symbol_f): Removed. + (ctf_link_shuffle_syms): Remove most parameters, just takes a + ctf_dict_t now. + (ctf_link_add_linker_symbol): New, split from + ctf_link_shuffle_syms. + * ctf.h (CTF_F_DYNSTR): New. + (CTF_F_MAX): Adjust. + +2020-11-20 Nick Alcock <nick.alcock@oracle.com> + * ctf-api.h (ctf_arc_open_by_name): Rename to... (ctf_dict_open): ... this, keeping compatibility function. (ctf_arc_open_by_name_sections): Rename to... diff --git a/include/bfdlink.h b/include/bfdlink.h index 55020e3..b92ef54 100644 --- a/include/bfdlink.h +++ b/include/bfdlink.h @@ -671,7 +671,7 @@ struct bfd_link_info /* Some forward-definitions used by some callbacks. */ struct elf_strtab_hash; -struct elf_sym_strtab; +struct elf_internal_sym; /* This structures holds a set of callback functions. These are called by the BFD linker routines. */ @@ -795,11 +795,17 @@ struct bfd_link_callbacks asection * current_section, asection * previous_section, bfd_boolean new_segment); /* This callback provides a chance for callers of the BFD to examine the - ELF string table and symbol table once they are complete and indexes and - offsets assigned. */ + ELF (dynamic) string table once it is complete. */ void (*examine_strtab) - (struct elf_sym_strtab *syms, bfd_size_type symcount, - struct elf_strtab_hash *symstrtab); + (struct elf_strtab_hash *symstrtab); + /* This callback is called just before a symbol is swapped out, so that the + CTF machinery can look up symbols during construction. The name is + already an external strtab offset at this point. */ + void (*ctf_new_symbol) + (int symidx, struct elf_internal_sym *sym); + /* Likewise, for dynamic symbols. */ + void (*ctf_new_dynsym) + (int symidx, struct elf_internal_sym *sym); /* This callback should emit the CTF section into a non-loadable section in the output BFD named .ctf or a name beginning with ".ctf.". */ void (*emit_ctf) diff --git a/include/ctf-api.h b/include/ctf-api.h index 38d7758..93bd5f3 100644 --- a/include/ctf-api.h +++ b/include/ctf-api.h @@ -65,14 +65,20 @@ typedef struct ctf_sect } ctf_sect_t; /* A minimal symbol extracted from a linker's internal symbol table - representation. */ + 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. */ typedef struct ctf_link_sym { - /* The st_name will not be accessed outside the call to - ctf_link_shuffle_syms(). */ + /* 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 + to set st_nameidx_set as well. */ const char *st_name; + size_t st_nameidx; + int st_nameidx_set; + uint32_t st_symidx; uint32_t st_shndx; uint32_t st_type; uint32_t st_value; @@ -485,10 +491,8 @@ extern int ctf_link (ctf_dict_t *, int flags); typedef const char *ctf_link_strtab_string_f (uint32_t *offset, void *arg); extern int ctf_link_add_strtab (ctf_dict_t *, ctf_link_strtab_string_f *, void *); -typedef ctf_link_sym_t *ctf_link_iter_symbol_f (ctf_link_sym_t *dest, - void *arg); -extern int ctf_link_shuffle_syms (ctf_dict_t *, ctf_link_iter_symbol_f *, - void *); +extern int ctf_link_add_linker_symbol (ctf_dict_t *, ctf_link_sym_t *); +extern int ctf_link_shuffle_syms (ctf_dict_t *); extern unsigned char *ctf_link_write (ctf_dict_t *, size_t *size, size_t threshold); diff --git a/include/ctf.h b/include/ctf.h index 6b8aa53..d0a21f1 100644 --- a/include/ctf.h +++ b/include/ctf.h @@ -200,7 +200,8 @@ typedef struct ctf_header #define CTF_VERSION CTF_VERSION_3 /* Current version. */ #define CTF_F_COMPRESS 0x1 /* Data buffer is compressed by libctf. */ -#define CTF_F_MAX CTF_F_COMPRESS /* The greatest flag value in use. */ +#define CTF_F_DYNSTR 0x8 /* Strings come from .dynstr. */ +#define CTF_F_MAX (CTF_F_COMPRESS | CTF_F_DYNSTR) typedef struct ctf_lblent { |