mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2025-01-12 12:16:04 +08:00
3d16b64e28
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.
268 lines
9.2 KiB
C
268 lines
9.2 KiB
C
/* ld-emul.h - Linker emulation header file
|
|
Copyright (C) 1991-2020 Free Software Foundation, Inc.
|
|
|
|
This file is part of the GNU Binutils.
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program; if not, write to the Free Software
|
|
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
|
|
MA 02110-1301, USA. */
|
|
|
|
#ifndef LDEMUL_H
|
|
#define LDEMUL_H
|
|
|
|
/* Forward declaration for ldemul_add_options() and others. */
|
|
struct option;
|
|
|
|
extern void ldemul_hll
|
|
(char *);
|
|
extern void ldemul_syslib
|
|
(char *);
|
|
extern void ldemul_after_parse
|
|
(void);
|
|
extern void ldemul_before_parse
|
|
(void);
|
|
extern void ldemul_after_open
|
|
(void);
|
|
extern void ldemul_after_check_relocs
|
|
(void);
|
|
extern void ldemul_before_place_orphans
|
|
(void);
|
|
extern void ldemul_after_allocation
|
|
(void);
|
|
extern void ldemul_before_allocation
|
|
(void);
|
|
extern void ldemul_set_output_arch
|
|
(void);
|
|
extern char *ldemul_choose_target
|
|
(int, char**);
|
|
extern void ldemul_choose_mode
|
|
(char *);
|
|
extern void ldemul_list_emulations
|
|
(FILE *);
|
|
extern void ldemul_list_emulation_options
|
|
(FILE *);
|
|
extern char *ldemul_get_script
|
|
(int *isfile);
|
|
extern void ldemul_finish
|
|
(void);
|
|
extern void ldemul_set_symbols
|
|
(void);
|
|
extern void ldemul_create_output_section_statements
|
|
(void);
|
|
extern lang_output_section_statement_type *ldemul_place_orphan
|
|
(asection *, const char *, int);
|
|
extern bfd_boolean ldemul_parse_args
|
|
(int, char **);
|
|
extern void ldemul_add_options
|
|
(int, char **, int, struct option **, int, struct option **);
|
|
extern bfd_boolean ldemul_handle_option
|
|
(int);
|
|
extern bfd_boolean ldemul_unrecognized_file
|
|
(struct lang_input_statement_struct *);
|
|
extern bfd_boolean ldemul_recognized_file
|
|
(struct lang_input_statement_struct *);
|
|
extern bfd_boolean ldemul_open_dynamic_archive
|
|
(const char *, struct search_dirs *, struct lang_input_statement_struct *);
|
|
extern char *ldemul_default_target
|
|
(int, char**);
|
|
extern void after_parse_default
|
|
(void);
|
|
extern void after_open_default
|
|
(void);
|
|
extern void after_check_relocs_default
|
|
(void);
|
|
extern void before_place_orphans_default
|
|
(void);
|
|
extern void after_allocation_default
|
|
(void);
|
|
extern void before_allocation_default
|
|
(void);
|
|
extern void finish_default
|
|
(void);
|
|
extern void finish_default
|
|
(void);
|
|
extern void set_output_arch_default
|
|
(void);
|
|
extern void syslib_default
|
|
(char*);
|
|
extern void hll_default
|
|
(char*);
|
|
extern int ldemul_find_potential_libraries
|
|
(char *, struct lang_input_statement_struct *);
|
|
extern struct bfd_elf_version_expr *ldemul_new_vers_pattern
|
|
(struct bfd_elf_version_expr *);
|
|
extern void ldemul_extra_map_file_text
|
|
(bfd *, struct bfd_link_info *, FILE *);
|
|
/* Return 1 if we are emitting CTF early, and 0 if ldemul_examine_strtab_for_ctf
|
|
will be called by the target. */
|
|
extern int ldemul_emit_ctf_early
|
|
(void);
|
|
/* Called from per-target code to examine the strtab and symtab. */
|
|
extern void ldemul_acquire_strings_for_ctf
|
|
(struct ctf_dict *, struct elf_strtab_hash *);
|
|
extern void ldemul_new_dynsym_for_ctf
|
|
(struct ctf_dict *, int symidx, struct elf_internal_sym *);
|
|
|
|
extern bfd_boolean ldemul_print_symbol
|
|
(struct bfd_link_hash_entry *hash_entry, void *ptr);
|
|
|
|
typedef struct ld_emulation_xfer_struct {
|
|
/* Run before parsing the command line and script file.
|
|
Set the architecture, maybe other things. */
|
|
void (*before_parse) (void);
|
|
|
|
/* Handle the SYSLIB (low level library) script command. */
|
|
void (*syslib) (char *);
|
|
|
|
/* Handle the HLL (high level library) script command. */
|
|
void (*hll) (char *);
|
|
|
|
/* Run after parsing the command line and script file. */
|
|
void (*after_parse) (void);
|
|
|
|
/* Run after opening all input files, and loading the symbols. */
|
|
void (*after_open) (void);
|
|
|
|
/* Run after checking relocations. */
|
|
void (*after_check_relocs) (void);
|
|
|
|
/* Run before placing orphans. */
|
|
void (*before_place_orphans) (void);
|
|
|
|
/* Run after allocating output sections. */
|
|
void (*after_allocation) (void);
|
|
|
|
/* Set the output architecture and machine if possible. */
|
|
void (*set_output_arch) (void);
|
|
|
|
/* Decide which target name to use. */
|
|
char * (*choose_target) (int, char**);
|
|
|
|
/* Run before allocating output sections. */
|
|
void (*before_allocation) (void);
|
|
|
|
/* Return the appropriate linker script. */
|
|
char * (*get_script) (int *isfile);
|
|
|
|
/* The name of this emulation. */
|
|
char *emulation_name;
|
|
|
|
/* The output format. */
|
|
char *target_name;
|
|
|
|
/* Run after assigning values from the script. */
|
|
void (*finish) (void);
|
|
|
|
/* Create any output sections needed by the target. */
|
|
void (*create_output_section_statements) (void);
|
|
|
|
/* Try to open a dynamic library. ARCH is an architecture name, and
|
|
is normally the empty string. ENTRY is the lang_input_statement
|
|
that should be opened. */
|
|
bfd_boolean (*open_dynamic_archive)
|
|
(const char *arch, struct search_dirs *,
|
|
struct lang_input_statement_struct *entry);
|
|
|
|
/* Place an orphan section. Return TRUE if it was placed, FALSE if
|
|
the default action should be taken. This field may be NULL, in
|
|
which case the default action will always be taken. */
|
|
lang_output_section_statement_type *(*place_orphan)
|
|
(asection *, const char *, int);
|
|
|
|
/* Run after assigning parsing with the args, but before
|
|
reading the script. Used to initialize symbols used in the script. */
|
|
void (*set_symbols) (void);
|
|
|
|
/* Parse args which the base linker doesn't understand.
|
|
Return TRUE if the arg needs no further processing. */
|
|
bfd_boolean (*parse_args) (int, char **);
|
|
|
|
/* Hook to add options to parameters passed by the base linker to
|
|
getopt_long and getopt_long_only calls. */
|
|
void (*add_options)
|
|
(int, char **, int, struct option **, int, struct option **);
|
|
|
|
/* Companion to the above to handle an option. Returns TRUE if it is
|
|
one of our options. */
|
|
bfd_boolean (*handle_option) (int);
|
|
|
|
/* Run to handle files which are not recognized as object files or
|
|
archives. Return TRUE if the file was handled. */
|
|
bfd_boolean (*unrecognized_file)
|
|
(struct lang_input_statement_struct *);
|
|
|
|
/* Run to list the command line options which parse_args handles. */
|
|
void (* list_options) (FILE *);
|
|
|
|
/* Run to specially handle files which *are* recognized as object
|
|
files or archives. Return TRUE if the file was handled. */
|
|
bfd_boolean (*recognized_file)
|
|
(struct lang_input_statement_struct *);
|
|
|
|
/* Called when looking for libraries in a directory specified
|
|
via a linker command line option or linker script option.
|
|
Files that match the pattern "lib*.a" have already been scanned.
|
|
(For VMS files matching ":lib*.a" have also been scanned). */
|
|
int (* find_potential_libraries)
|
|
(char *, struct lang_input_statement_struct *);
|
|
|
|
/* Called when adding a new version pattern. PowerPC64-ELF uses
|
|
this hook to add a pattern matching ".foo" for every "foo". */
|
|
struct bfd_elf_version_expr * (*new_vers_pattern)
|
|
(struct bfd_elf_version_expr *);
|
|
|
|
/* Called when printing the map file, in case there are
|
|
emulation-specific sections for it. */
|
|
void (*extra_map_file_text)
|
|
(bfd *, struct bfd_link_info *, FILE *);
|
|
|
|
/* If this returns true, we emit CTF as early as possible: if false, we emit
|
|
CTF once the strtab and symtab are laid out. */
|
|
int (*emit_ctf_early)
|
|
(void);
|
|
|
|
/* Called to examine the string table late enough in linking that it is
|
|
finally laid out. If emit_ctf_early returns true, this is not called, and
|
|
ldemul_maybe_emit_ctf emits CTF in 'early' mode: otherwise, it waits
|
|
until 'late'. (Late mode needs explicit support at per-target link time to
|
|
get called at all). If set, called by ld when the examine_strtab
|
|
bfd_link_callback is invoked by per-target code. */
|
|
void (*acquire_strings_for_ctf) (struct ctf_dict *, struct elf_strtab_hash *);
|
|
|
|
/* Called when a new symbol is added to the dynamic symbol table. If
|
|
emit_ctf_early returns true, this is not called, and ldemul_maybe_emit_ctf
|
|
emits CTF in 'early' mode: otherwise, it waits until 'late'. (Late mode
|
|
needs explicit support at per-target link time to get called at all). If
|
|
set, called by ld when the ctf_new_symbol bfd_link_callback is invoked by
|
|
per-target code. Called with a NULL symbol when no further symbols will be
|
|
provided. */
|
|
void (*new_dynsym_for_ctf) (struct ctf_dict *, int, struct elf_internal_sym *);
|
|
|
|
/* Called when printing a symbol to the map file. AIX uses this
|
|
hook to flag gc'd symbols. */
|
|
bfd_boolean (*print_symbol)
|
|
(struct bfd_link_hash_entry *hash_entry, void *ptr);
|
|
|
|
} ld_emulation_xfer_type;
|
|
|
|
typedef enum {
|
|
intel_ic960_ld_mode_enum,
|
|
default_mode_enum,
|
|
intel_gld960_ld_mode_enum
|
|
} lang_emulation_mode_enum_type;
|
|
|
|
extern ld_emulation_xfer_type *ld_emulations[];
|
|
|
|
#endif
|