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 /bfd | |
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 'bfd')
-rw-r--r-- | bfd/ChangeLog | 13 | ||||
-rw-r--r-- | bfd/elf.c | 14 | ||||
-rw-r--r-- | bfd/elflink.c | 38 |
3 files changed, 54 insertions, 11 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 2aa89d0..b2553a6 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,16 @@ +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. + 2020-11-19 Nick Clifton <nickc@redhat.com> PR 26918 @@ -51,7 +51,8 @@ SECTION static int elf_sort_sections (const void *, const void *); static bfd_boolean assign_file_positions_except_relocs (bfd *, struct bfd_link_info *); -static bfd_boolean swap_out_syms (bfd *, struct elf_strtab_hash **, int) ; +static bfd_boolean swap_out_syms (bfd *, struct elf_strtab_hash **, int, + struct bfd_link_info *); static bfd_boolean elf_parse_notes (bfd *abfd, char *buf, size_t size, file_ptr offset, size_t align); @@ -4302,7 +4303,7 @@ _bfd_elf_compute_section_file_positions (bfd *abfd, /* Non-zero if doing a relocatable link. */ int relocatable_p = ! (abfd->flags & (EXEC_P | DYNAMIC)); - if (! swap_out_syms (abfd, &strtab, relocatable_p)) + if (! swap_out_syms (abfd, &strtab, relocatable_p, link_info)) return FALSE; } @@ -8050,7 +8051,8 @@ _bfd_elf_copy_private_symbol_data (bfd *ibfd, static bfd_boolean swap_out_syms (bfd *abfd, struct elf_strtab_hash **sttp, - int relocatable_p) + int relocatable_p, + struct bfd_link_info *info) { const struct elf_backend_data *bed; unsigned int symcount; @@ -8402,6 +8404,12 @@ Unable to handle section index %x in ELF symbol. Using ABS instead."), else elfsym->sym.st_name = _bfd_elf_strtab_offset (stt, elfsym->sym.st_name); + if (info && info->callbacks->ctf_new_symbol) + info->callbacks->ctf_new_symbol (elfsym->dest_index, + &elfsym->sym); + + /* Inform the linker of the addition of this symbol. */ + bed->s->swap_symbol_out (abfd, &elfsym->sym, (outbound_syms + (elfsym->dest_index diff --git a/bfd/elflink.c b/bfd/elflink.c index 6cc6361..7ba667a 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -3779,6 +3779,11 @@ elf_finalize_dynstr (bfd *output_bfd, struct bfd_link_info *info) _bfd_elf_strtab_finalize (dynstr); size = _bfd_elf_strtab_size (dynstr); + /* Allow the linker to examine the dynsymtab now it's fully populated. */ + + if (info->callbacks->examine_strtab) + info->callbacks->examine_strtab (dynstr); + bed = get_elf_backend_data (dynobj); sdyn = bfd_get_linker_section (dynobj, ".dynamic"); BFD_ASSERT (sdyn != NULL); @@ -9853,6 +9858,7 @@ elf_link_swap_symbols_out (struct elf_final_link_info *flinfo) } } + /* Now swap out the symbols. */ for (i = 0; i < hash_table->strtabcount; i++) { struct elf_sym_strtab *elfsym = &hash_table->strtab[i]; @@ -9862,6 +9868,13 @@ elf_link_swap_symbols_out (struct elf_final_link_info *flinfo) elfsym->sym.st_name = (unsigned long) _bfd_elf_strtab_offset (flinfo->symstrtab, elfsym->sym.st_name); + + /* Inform the linker of the addition of this symbol. */ + + if (flinfo->info->callbacks->ctf_new_symbol) + flinfo->info->callbacks->ctf_new_symbol (elfsym->dest_index, + &elfsym->sym); + bed->s->swap_symbol_out (flinfo->output_bfd, &elfsym->sym, ((bfd_byte *) symbuf + (elfsym->dest_index @@ -9870,14 +9883,6 @@ elf_link_swap_symbols_out (struct elf_final_link_info *flinfo) + elfsym->destshndx_index)); } - /* Allow the linker to examine the strtab and symtab now they are - populated. */ - - if (flinfo->info->callbacks->examine_strtab) - flinfo->info->callbacks->examine_strtab (hash_table->strtab, - hash_table->strtabcount, - flinfo->symstrtab); - hdr = &elf_tdata (flinfo->output_bfd)->symtab_hdr; pos = hdr->sh_offset + hdr->sh_size; amt = hash_table->strtabcount * bed->s->sizeof_sym; @@ -10485,6 +10490,12 @@ elf_link_output_extsym (struct bfd_hash_entry *bh, void *data) eoinfo->failed = TRUE; return FALSE; } + + /* Inform the linker of the addition of this symbol. */ + + if (flinfo->info->callbacks->ctf_new_dynsym) + flinfo->info->callbacks->ctf_new_dynsym (h->dynindx, &sym); + bed->s->swap_symbol_out (flinfo->output_bfd, &sym, esym, 0); if (flinfo->hash_sec != NULL) @@ -12761,6 +12772,12 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info) } sym.st_value = s->vma; dest = dynsym + dynindx * bed->s->sizeof_sym; + + /* Inform the linker of the addition of this symbol. */ + + if (info->callbacks->ctf_new_dynsym) + info->callbacks->ctf_new_dynsym (dynindx, &sym); + bed->s->swap_symbol_out (abfd, &sym, dest, 0); } } @@ -12799,6 +12816,11 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info) + e->isym.st_value); } + /* Inform the linker of the addition of this symbol. */ + + if (info->callbacks->ctf_new_dynsym) + info->callbacks->ctf_new_dynsym (e->dynindx, &sym); + dest = dynsym + e->dynindx * bed->s->sizeof_sym; bed->s->swap_symbol_out (abfd, &sym, dest, 0); } |