Home | History | Annotate | Line # | Download | only in include
bfdlink.h revision 1.1
      1  1.1  christos /* bfdlink.h -- header file for BFD link routines
      2  1.1  christos    Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
      3  1.1  christos    2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
      4  1.1  christos    Written by Steve Chamberlain and Ian Lance Taylor, Cygnus Support.
      5  1.1  christos 
      6  1.1  christos    This file is part of BFD, the Binary File Descriptor library.
      7  1.1  christos 
      8  1.1  christos    This program is free software; you can redistribute it and/or modify
      9  1.1  christos    it under the terms of the GNU General Public License as published by
     10  1.1  christos    the Free Software Foundation; either version 3 of the License, or
     11  1.1  christos    (at your option) any later version.
     12  1.1  christos 
     13  1.1  christos    This program is distributed in the hope that it will be useful,
     14  1.1  christos    but WITHOUT ANY WARRANTY; without even the implied warranty of
     15  1.1  christos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16  1.1  christos    GNU General Public License for more details.
     17  1.1  christos 
     18  1.1  christos    You should have received a copy of the GNU General Public License
     19  1.1  christos    along with this program; if not, write to the Free Software
     20  1.1  christos    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
     21  1.1  christos    MA 02110-1301, USA.  */
     22  1.1  christos 
     23  1.1  christos #ifndef BFDLINK_H
     24  1.1  christos #define BFDLINK_H
     25  1.1  christos 
     26  1.1  christos /* Which symbols to strip during a link.  */
     27  1.1  christos enum bfd_link_strip
     28  1.1  christos {
     29  1.1  christos   strip_none,		/* Don't strip any symbols.  */
     30  1.1  christos   strip_debugger,	/* Strip debugging symbols.  */
     31  1.1  christos   strip_some,		/* keep_hash is the list of symbols to keep.  */
     32  1.1  christos   strip_all		/* Strip all symbols.  */
     33  1.1  christos };
     34  1.1  christos 
     35  1.1  christos /* Which local symbols to discard during a link.  This is irrelevant
     36  1.1  christos    if strip_all is used.  */
     37  1.1  christos enum bfd_link_discard
     38  1.1  christos {
     39  1.1  christos   discard_sec_merge,	/* Discard local temporary symbols in SEC_MERGE
     40  1.1  christos 			   sections.  */
     41  1.1  christos   discard_none,		/* Don't discard any locals.  */
     42  1.1  christos   discard_l,		/* Discard local temporary symbols.  */
     43  1.1  christos   discard_all		/* Discard all locals.  */
     44  1.1  christos };
     45  1.1  christos 
     46  1.1  christos /* Describes the type of hash table entry structure being used.
     47  1.1  christos    Different hash table structure have different fields and so
     48  1.1  christos    support different linking features.  */
     49  1.1  christos enum bfd_link_hash_table_type
     50  1.1  christos   {
     51  1.1  christos     bfd_link_generic_hash_table,
     52  1.1  christos     bfd_link_elf_hash_table
     53  1.1  christos   };
     54  1.1  christos 
     55  1.1  christos /* These are the possible types of an entry in the BFD link hash
     57  1.1  christos    table.  */
     58  1.1  christos 
     59  1.1  christos enum bfd_link_hash_type
     60  1.1  christos {
     61  1.1  christos   bfd_link_hash_new,		/* Symbol is new.  */
     62  1.1  christos   bfd_link_hash_undefined,	/* Symbol seen before, but undefined.  */
     63  1.1  christos   bfd_link_hash_undefweak,	/* Symbol is weak and undefined.  */
     64  1.1  christos   bfd_link_hash_defined,	/* Symbol is defined.  */
     65  1.1  christos   bfd_link_hash_defweak,	/* Symbol is weak and defined.  */
     66  1.1  christos   bfd_link_hash_common,		/* Symbol is common.  */
     67  1.1  christos   bfd_link_hash_indirect,	/* Symbol is an indirect link.  */
     68  1.1  christos   bfd_link_hash_warning		/* Like indirect, but warn if referenced.  */
     69  1.1  christos };
     70  1.1  christos 
     71  1.1  christos enum bfd_link_common_skip_ar_symbols
     72  1.1  christos {
     73  1.1  christos   bfd_link_common_skip_none,
     74  1.1  christos   bfd_link_common_skip_text,
     75  1.1  christos   bfd_link_common_skip_data,
     76  1.1  christos   bfd_link_common_skip_all
     77  1.1  christos };
     78  1.1  christos 
     79  1.1  christos struct bfd_link_hash_common_entry
     80  1.1  christos   {
     81  1.1  christos     unsigned int alignment_power;	/* Alignment.  */
     82  1.1  christos     asection *section;		/* Symbol section.  */
     83  1.1  christos   };
     84  1.1  christos 
     85  1.1  christos /* The linking routines use a hash table which uses this structure for
     86  1.1  christos    its elements.  */
     87  1.1  christos 
     88  1.1  christos struct bfd_link_hash_entry
     89  1.1  christos {
     90  1.1  christos   /* Base hash table entry structure.  */
     91  1.1  christos   struct bfd_hash_entry root;
     92  1.1  christos 
     93  1.1  christos   /* Type of this entry.  */
     94  1.1  christos   enum bfd_link_hash_type type;
     95  1.1  christos 
     96  1.1  christos   /* A union of information depending upon the type.  */
     97  1.1  christos   union
     98  1.1  christos     {
     99  1.1  christos       /* Nothing is kept for bfd_hash_new.  */
    100  1.1  christos       /* bfd_link_hash_undefined, bfd_link_hash_undefweak.  */
    101  1.1  christos       struct
    102  1.1  christos 	{
    103  1.1  christos 	  /* Undefined and common symbols are kept in a linked list through
    104  1.1  christos 	     this field.  This field is present in all of the union element
    105  1.1  christos 	     so that we don't need to remove entries from the list when we
    106  1.1  christos 	     change their type.  Removing entries would either require the
    107  1.1  christos 	     list to be doubly linked, which would waste more memory, or
    108  1.1  christos 	     require a traversal.  When an undefined or common symbol is
    109  1.1  christos 	     created, it should be added to this list, the head of which is in
    110  1.1  christos 	     the link hash table itself.  As symbols are defined, they need
    111  1.1  christos 	     not be removed from the list; anything which reads the list must
    112  1.1  christos 	     doublecheck the symbol type.
    113  1.1  christos 
    114  1.1  christos 	     Weak symbols are not kept on this list.
    115  1.1  christos 
    116  1.1  christos 	     Defined and defweak symbols use this field as a reference marker.
    117  1.1  christos 	     If the field is not NULL, or this structure is the tail of the
    118  1.1  christos 	     undefined symbol list, the symbol has been referenced.  If the
    119  1.1  christos 	     symbol is undefined and becomes defined, this field will
    120  1.1  christos 	     automatically be non-NULL since the symbol will have been on the
    121  1.1  christos 	     undefined symbol list.  */
    122  1.1  christos 	  struct bfd_link_hash_entry *next;
    123  1.1  christos 	  bfd *abfd;		/* BFD symbol was found in.  */
    124  1.1  christos 	  bfd *weak;		/* BFD weak symbol was found in.  */
    125  1.1  christos 	} undef;
    126  1.1  christos       /* bfd_link_hash_defined, bfd_link_hash_defweak.  */
    127  1.1  christos       struct
    128  1.1  christos 	{
    129  1.1  christos 	  struct bfd_link_hash_entry *next;
    130  1.1  christos 	  asection *section;	/* Symbol section.  */
    131  1.1  christos 	  bfd_vma value;	/* Symbol value.  */
    132  1.1  christos 	} def;
    133  1.1  christos       /* bfd_link_hash_indirect, bfd_link_hash_warning.  */
    134  1.1  christos       struct
    135  1.1  christos 	{
    136  1.1  christos 	  struct bfd_link_hash_entry *next;
    137  1.1  christos 	  struct bfd_link_hash_entry *link;	/* Real symbol.  */
    138  1.1  christos 	  const char *warning;	/* Warning (bfd_link_hash_warning only).  */
    139  1.1  christos 	} i;
    140  1.1  christos       /* bfd_link_hash_common.  */
    141  1.1  christos       struct
    142  1.1  christos 	{
    143  1.1  christos 	  struct bfd_link_hash_entry *next;
    144  1.1  christos 	  /* The linker needs to know three things about common
    145  1.1  christos 	     symbols: the size, the alignment, and the section in
    146  1.1  christos 	     which the symbol should be placed.  We store the size
    147  1.1  christos 	     here, and we allocate a small structure to hold the
    148  1.1  christos 	     section and the alignment.  The alignment is stored as a
    149  1.1  christos 	     power of two.  We don't store all the information
    150  1.1  christos 	     directly because we don't want to increase the size of
    151  1.1  christos 	     the union; this structure is a major space user in the
    152  1.1  christos 	     linker.  */
    153  1.1  christos 	  struct bfd_link_hash_common_entry *p;
    154  1.1  christos 	  bfd_size_type size;	/* Common symbol size.  */
    155  1.1  christos 	} c;
    156  1.1  christos     } u;
    157  1.1  christos };
    158  1.1  christos 
    159  1.1  christos /* This is the link hash table.  It is a derived class of
    160  1.1  christos    bfd_hash_table.  */
    161  1.1  christos 
    162  1.1  christos struct bfd_link_hash_table
    163  1.1  christos {
    164  1.1  christos   /* The hash table itself.  */
    165  1.1  christos   struct bfd_hash_table table;
    166  1.1  christos   /* A linked list of undefined and common symbols, linked through the
    167  1.1  christos      next field in the bfd_link_hash_entry structure.  */
    168  1.1  christos   struct bfd_link_hash_entry *undefs;
    169  1.1  christos   /* Entries are added to the tail of the undefs list.  */
    170  1.1  christos   struct bfd_link_hash_entry *undefs_tail;
    171  1.1  christos   /* The type of the link hash table.  */
    172  1.1  christos   enum bfd_link_hash_table_type type;
    173  1.1  christos };
    174  1.1  christos 
    175  1.1  christos /* Look up an entry in a link hash table.  If FOLLOW is TRUE, this
    176  1.1  christos    follows bfd_link_hash_indirect and bfd_link_hash_warning links to
    177  1.1  christos    the real symbol.  */
    178  1.1  christos extern struct bfd_link_hash_entry *bfd_link_hash_lookup
    179  1.1  christos   (struct bfd_link_hash_table *, const char *, bfd_boolean create,
    180  1.1  christos    bfd_boolean copy, bfd_boolean follow);
    181  1.1  christos 
    182  1.1  christos /* Look up an entry in the main linker hash table if the symbol might
    183  1.1  christos    be wrapped.  This should only be used for references to an
    184  1.1  christos    undefined symbol, not for definitions of a symbol.  */
    185  1.1  christos 
    186  1.1  christos extern struct bfd_link_hash_entry *bfd_wrapped_link_hash_lookup
    187  1.1  christos   (bfd *, struct bfd_link_info *, const char *, bfd_boolean,
    188  1.1  christos    bfd_boolean, bfd_boolean);
    189  1.1  christos 
    190  1.1  christos /* Traverse a link hash table.  */
    191  1.1  christos extern void bfd_link_hash_traverse
    192  1.1  christos   (struct bfd_link_hash_table *,
    193  1.1  christos     bfd_boolean (*) (struct bfd_link_hash_entry *, void *),
    194  1.1  christos     void *);
    195  1.1  christos 
    196  1.1  christos /* Add an entry to the undefs list.  */
    197  1.1  christos extern void bfd_link_add_undef
    198  1.1  christos   (struct bfd_link_hash_table *, struct bfd_link_hash_entry *);
    199  1.1  christos 
    200  1.1  christos /* Remove symbols from the undefs list that don't belong there.  */
    201  1.1  christos extern void bfd_link_repair_undef_list
    202  1.1  christos   (struct bfd_link_hash_table *table);
    203  1.1  christos 
    204  1.1  christos /* Read symbols and cache symbol pointer array in outsymbols.  */
    205  1.1  christos extern bfd_boolean bfd_generic_link_read_symbols (bfd *);
    206  1.1  christos 
    207  1.1  christos struct bfd_sym_chain
    208  1.1  christos {
    209  1.1  christos   struct bfd_sym_chain *next;
    210  1.1  christos   const char *name;
    211  1.1  christos };
    212  1.1  christos 
    213  1.1  christos /* How to handle unresolved symbols.
    215  1.1  christos    There are four possibilities which are enumerated below:  */
    216  1.1  christos enum report_method
    217  1.1  christos {
    218  1.1  christos   /* This is the initial value when then link_info structure is created.
    219  1.1  christos      It allows the various stages of the linker to determine whether they
    220  1.1  christos      allowed to set the value.  */
    221  1.1  christos   RM_NOT_YET_SET = 0,
    222  1.1  christos   RM_IGNORE,
    223  1.1  christos   RM_GENERATE_WARNING,
    224  1.1  christos   RM_GENERATE_ERROR
    225  1.1  christos };
    226  1.1  christos 
    227  1.1  christos struct bfd_elf_dynamic_list;
    228  1.1  christos 
    229  1.1  christos /* This structure holds all the information needed to communicate
    230  1.1  christos    between BFD and the linker when doing a link.  */
    231  1.1  christos 
    232  1.1  christos struct bfd_link_info
    233  1.1  christos {
    234  1.1  christos   /* TRUE if BFD should generate a relocatable object file.  */
    235  1.1  christos   unsigned int relocatable: 1;
    236  1.1  christos 
    237  1.1  christos   /* TRUE if BFD should generate relocation information in the final
    238  1.1  christos      executable.  */
    239  1.1  christos   unsigned int emitrelocations: 1;
    240  1.1  christos 
    241  1.1  christos   /* TRUE if BFD should generate a "task linked" object file,
    242  1.1  christos      similar to relocatable but also with globals converted to
    243  1.1  christos      statics.  */
    244  1.1  christos   unsigned int task_link: 1;
    245  1.1  christos 
    246  1.1  christos   /* TRUE if BFD should generate a shared object.  */
    247  1.1  christos   unsigned int shared: 1;
    248  1.1  christos 
    249  1.1  christos   /* TRUE if BFD should pre-bind symbols in a shared object.  */
    250  1.1  christos   unsigned int symbolic: 1;
    251  1.1  christos 
    252  1.1  christos   /* TRUE if BFD should export all symbols in the dynamic symbol table
    253  1.1  christos      of an executable, rather than only those used.  */
    254  1.1  christos   unsigned int export_dynamic: 1;
    255  1.1  christos 
    256  1.1  christos   /* TRUE if shared objects should be linked directly, not shared.  */
    257  1.1  christos   unsigned int static_link: 1;
    258  1.1  christos 
    259  1.1  christos   /* TRUE if the output file should be in a traditional format.  This
    260  1.1  christos      is equivalent to the setting of the BFD_TRADITIONAL_FORMAT flag
    261  1.1  christos      on the output file, but may be checked when reading the input
    262  1.1  christos      files.  */
    263  1.1  christos   unsigned int traditional_format: 1;
    264  1.1  christos 
    265  1.1  christos   /* TRUE if we want to produced optimized output files.  This might
    266  1.1  christos      need much more time and therefore must be explicitly selected.  */
    267  1.1  christos   unsigned int optimize: 1;
    268  1.1  christos 
    269  1.1  christos   /* TRUE if ok to have multiple definition.  */
    270  1.1  christos   unsigned int allow_multiple_definition: 1;
    271  1.1  christos 
    272  1.1  christos   /* TRUE if ok to have version with no definition.  */
    273  1.1  christos   unsigned int allow_undefined_version: 1;
    274  1.1  christos 
    275  1.1  christos   /* TRUE if a default symbol version should be created and used for
    276  1.1  christos      exported symbols.  */
    277  1.1  christos   unsigned int create_default_symver: 1;
    278  1.1  christos 
    279  1.1  christos   /* TRUE if a default symbol version should be created and used for
    280  1.1  christos      imported symbols.  */
    281  1.1  christos   unsigned int default_imported_symver: 1;
    282  1.1  christos 
    283  1.1  christos   /* TRUE if symbols should be retained in memory, FALSE if they
    284  1.1  christos      should be freed and reread.  */
    285  1.1  christos   unsigned int keep_memory: 1;
    286  1.1  christos 
    287  1.1  christos   /* TRUE if every symbol should be reported back via the notice
    288  1.1  christos      callback.  */
    289  1.1  christos   unsigned int notice_all: 1;
    290  1.1  christos 
    291  1.1  christos   /* TRUE if executable should not contain copy relocs.
    292  1.1  christos      Setting this true may result in a non-sharable text segment.  */
    293  1.1  christos   unsigned int nocopyreloc: 1;
    294  1.1  christos 
    295  1.1  christos   /* TRUE if the new ELF dynamic tags are enabled. */
    296  1.1  christos   unsigned int new_dtags: 1;
    297  1.1  christos 
    298  1.1  christos   /* TRUE if non-PLT relocs should be merged into one reloc section
    299  1.1  christos      and sorted so that relocs against the same symbol come together.  */
    300  1.1  christos   unsigned int combreloc: 1;
    301  1.1  christos 
    302  1.1  christos   /* TRUE if .eh_frame_hdr section and PT_GNU_EH_FRAME ELF segment
    303  1.1  christos      should be created.  */
    304  1.1  christos   unsigned int eh_frame_hdr: 1;
    305  1.1  christos 
    306  1.1  christos   /* TRUE if global symbols in discarded sections should be stripped.  */
    307  1.1  christos   unsigned int strip_discarded: 1;
    308  1.1  christos 
    309  1.1  christos   /* TRUE if generating a position independent executable.  */
    310  1.1  christos   unsigned int pie: 1;
    311  1.1  christos 
    312  1.1  christos   /* TRUE if generating an executable, position independent or not.  */
    313  1.1  christos   unsigned int executable : 1;
    314  1.1  christos 
    315  1.1  christos   /* TRUE if PT_GNU_STACK segment should be created with PF_R|PF_W|PF_X
    316  1.1  christos      flags.  */
    317  1.1  christos   unsigned int execstack: 1;
    318  1.1  christos 
    319  1.1  christos   /* TRUE if PT_GNU_STACK segment should be created with PF_R|PF_W
    320  1.1  christos      flags.  */
    321  1.1  christos   unsigned int noexecstack: 1;
    322  1.1  christos 
    323  1.1  christos   /* TRUE if PT_GNU_RELRO segment should be created.  */
    324  1.1  christos   unsigned int relro: 1;
    325  1.1  christos 
    326  1.1  christos   /* TRUE if we should warn when adding a DT_TEXTREL to a shared object.  */
    327  1.1  christos   unsigned int warn_shared_textrel: 1;
    328  1.1  christos 
    329  1.1  christos   /* TRUE if we should warn alternate ELF machine code.  */
    330  1.1  christos   unsigned int warn_alternate_em: 1;
    331  1.1  christos 
    332  1.1  christos   /* TRUE if unreferenced sections should be removed.  */
    333  1.1  christos   unsigned int gc_sections: 1;
    334  1.1  christos 
    335  1.1  christos   /* TRUE if user shoudl be informed of removed unreferenced sections.  */
    336  1.1  christos   unsigned int print_gc_sections: 1;
    337  1.1  christos 
    338  1.1  christos   /* TRUE if .hash section should be created.  */
    339  1.1  christos   unsigned int emit_hash: 1;
    340  1.1  christos 
    341  1.1  christos   /* TRUE if .gnu.hash section should be created.  */
    342  1.1  christos   unsigned int emit_gnu_hash: 1;
    343  1.1  christos 
    344  1.1  christos   /* If TRUE reduce memory overheads, at the expense of speed. This will
    345  1.1  christos      cause map file generation to use an O(N^2) algorithm and disable
    346  1.1  christos      caching ELF symbol buffer.  */
    347  1.1  christos   unsigned int reduce_memory_overheads: 1;
    348  1.1  christos 
    349  1.1  christos   /* TRUE if all data symbols should be dynamic.  */
    350  1.1  christos    unsigned int dynamic_data: 1;
    351  1.1  christos 
    352  1.1  christos   /* TRUE if some symbols have to be dynamic, controlled by
    353  1.1  christos      --dynamic-list command line options.  */
    354  1.1  christos   unsigned int dynamic: 1;
    355  1.1  christos 
    356  1.1  christos   /* Non-NULL if .note.gnu.build-id section should be created.  */
    357  1.1  christos   char *emit_note_gnu_build_id;
    358  1.1  christos 
    359  1.1  christos   /* What to do with unresolved symbols in an object file.
    360  1.1  christos      When producing executables the default is GENERATE_ERROR.
    361  1.1  christos      When producing shared libraries the default is IGNORE.  The
    362  1.1  christos      assumption with shared libraries is that the reference will be
    363  1.1  christos      resolved at load/execution time.  */
    364  1.1  christos   enum report_method unresolved_syms_in_objects;
    365  1.1  christos 
    366  1.1  christos   /* What to do with unresolved symbols in a shared library.
    367  1.1  christos      The same defaults apply.  */
    368  1.1  christos   enum report_method unresolved_syms_in_shared_libs;
    369  1.1  christos 
    370  1.1  christos   /* Which symbols to strip.  */
    371  1.1  christos   enum bfd_link_strip strip;
    372  1.1  christos 
    373  1.1  christos   /* Which local symbols to discard.  */
    374  1.1  christos   enum bfd_link_discard discard;
    375  1.1  christos 
    376  1.1  christos   /* Criteria for skipping symbols when determining
    377  1.1  christos      whether to include an object from an archive. */
    378  1.1  christos   enum bfd_link_common_skip_ar_symbols common_skip_ar_symbols;
    379  1.1  christos 
    380  1.1  christos   /* Char that may appear as the first char of a symbol, but should be
    381  1.1  christos      skipped (like symbol_leading_char) when looking up symbols in
    382  1.1  christos      wrap_hash.  Used by PowerPC Linux for 'dot' symbols.  */
    383  1.1  christos   char wrap_char;
    384  1.1  christos 
    385  1.1  christos   /* Separator between archive and filename in linker script filespecs.  */
    386  1.1  christos   char path_separator;
    387  1.1  christos 
    388  1.1  christos   /* Function callbacks.  */
    389  1.1  christos   const struct bfd_link_callbacks *callbacks;
    390  1.1  christos 
    391  1.1  christos   /* Hash table handled by BFD.  */
    392  1.1  christos   struct bfd_link_hash_table *hash;
    393  1.1  christos 
    394  1.1  christos   /* Hash table of symbols to keep.  This is NULL unless strip is
    395  1.1  christos      strip_some.  */
    396  1.1  christos   struct bfd_hash_table *keep_hash;
    397  1.1  christos 
    398  1.1  christos   /* Hash table of symbols to report back via the notice callback.  If
    399  1.1  christos      this is NULL, and notice_all is FALSE, then no symbols are
    400  1.1  christos      reported back.  */
    401  1.1  christos   struct bfd_hash_table *notice_hash;
    402  1.1  christos 
    403  1.1  christos   /* Hash table of symbols which are being wrapped (the --wrap linker
    404  1.1  christos      option).  If this is NULL, no symbols are being wrapped.  */
    405  1.1  christos   struct bfd_hash_table *wrap_hash;
    406  1.1  christos 
    407  1.1  christos   /* The output BFD.  */
    408  1.1  christos   bfd *output_bfd;
    409  1.1  christos 
    410  1.1  christos   /* The list of input BFD's involved in the link.  These are chained
    411  1.1  christos      together via the link_next field.  */
    412  1.1  christos   bfd *input_bfds;
    413  1.1  christos   bfd **input_bfds_tail;
    414  1.1  christos 
    415  1.1  christos   /* If a symbol should be created for each input BFD, this is section
    416  1.1  christos      where those symbols should be placed.  It must be a section in
    417  1.1  christos      the output BFD.  It may be NULL, in which case no such symbols
    418  1.1  christos      will be created.  This is to support CREATE_OBJECT_SYMBOLS in the
    419  1.1  christos      linker command language.  */
    420  1.1  christos   asection *create_object_symbols_section;
    421  1.1  christos 
    422  1.1  christos   /* List of global symbol names that are starting points for marking
    423  1.1  christos      sections against garbage collection.  */
    424  1.1  christos   struct bfd_sym_chain *gc_sym_list;
    425  1.1  christos 
    426  1.1  christos   /* If a base output file is wanted, then this points to it */
    427  1.1  christos   void *base_file;
    428  1.1  christos 
    429  1.1  christos   /* The function to call when the executable or shared object is
    430  1.1  christos      loaded.  */
    431  1.1  christos   const char *init_function;
    432  1.1  christos 
    433  1.1  christos   /* The function to call when the executable or shared object is
    434  1.1  christos      unloaded.  */
    435  1.1  christos   const char *fini_function;
    436  1.1  christos 
    437  1.1  christos   /* Number of relaxation passes.  Usually only one relaxation pass
    438  1.1  christos      is needed.  But a backend can have as many relaxation passes as
    439  1.1  christos      necessary.  During bfd_relax_section call, it is set to the
    440  1.1  christos      current pass, starting from 0.  */
    441  1.1  christos   int relax_pass;
    442  1.1  christos 
    443  1.1  christos   /* Number of relaxation trips.  This number is incremented every
    444  1.1  christos      time the relaxation pass is restarted due to a previous
    445  1.1  christos      relaxation returning true in *AGAIN.  */
    446  1.1  christos   int relax_trip;
    447  1.1  christos 
    448  1.1  christos   /* Non-zero if auto-import thunks for DATA items in pei386 DLLs
    449  1.1  christos      should be generated/linked against.  Set to 1 if this feature
    450  1.1  christos      is explicitly requested by the user, -1 if enabled by default.  */
    451  1.1  christos   int pei386_auto_import;
    452  1.1  christos 
    453  1.1  christos   /* Non-zero if runtime relocs for DATA items with non-zero addends
    454  1.1  christos      in pei386 DLLs should be generated.  Set to 1 if this feature
    455  1.1  christos      is explicitly requested by the user, -1 if enabled by default.  */
    456  1.1  christos   int pei386_runtime_pseudo_reloc;
    457  1.1  christos 
    458  1.1  christos   /* How many spare .dynamic DT_NULL entries should be added?  */
    459  1.1  christos   unsigned int spare_dynamic_tags;
    460  1.1  christos 
    461  1.1  christos   /* May be used to set DT_FLAGS for ELF. */
    462  1.1  christos   bfd_vma flags;
    463  1.1  christos 
    464  1.1  christos   /* May be used to set DT_FLAGS_1 for ELF. */
    465  1.1  christos   bfd_vma flags_1;
    466  1.1  christos 
    467  1.1  christos   /* Start and end of RELRO region.  */
    468  1.1  christos   bfd_vma relro_start, relro_end;
    469  1.1  christos 
    470  1.1  christos   /* List of symbols should be dynamic.  */
    471  1.1  christos   struct bfd_elf_dynamic_list *dynamic_list;
    472  1.1  christos };
    473  1.1  christos 
    474  1.1  christos /* This structures holds a set of callback functions.  These are called
    475  1.1  christos    by the BFD linker routines.  Except for the info functions, the first
    476  1.1  christos    argument to each callback function is the bfd_link_info structure
    477  1.1  christos    being used and each function returns a boolean value.  If the
    478  1.1  christos    function returns FALSE, then the BFD function which called it should
    479  1.1  christos    return with a failure indication.  */
    480  1.1  christos 
    481  1.1  christos struct bfd_link_callbacks
    482  1.1  christos {
    483  1.1  christos   /* A function which is called when an object is added from an
    484  1.1  christos      archive.  ABFD is the archive element being added.  NAME is the
    485  1.1  christos      name of the symbol which caused the archive element to be pulled
    486  1.1  christos      in.  This function may set *SUBSBFD to point to an alternative
    487  1.1  christos      BFD from which symbols should in fact be added in place of the
    488  1.1  christos      original BFD's symbols.  */
    489  1.1  christos   bfd_boolean (*add_archive_element)
    490  1.1  christos     (struct bfd_link_info *, bfd *abfd, const char *name, bfd **subsbfd);
    491  1.1  christos   /* A function which is called when a symbol is found with multiple
    492  1.1  christos      definitions.  NAME is the symbol which is defined multiple times.
    493  1.1  christos      OBFD is the old BFD, OSEC is the old section, OVAL is the old
    494  1.1  christos      value, NBFD is the new BFD, NSEC is the new section, and NVAL is
    495  1.1  christos      the new value.  OBFD may be NULL.  OSEC and NSEC may be
    496  1.1  christos      bfd_com_section or bfd_ind_section.  */
    497  1.1  christos   bfd_boolean (*multiple_definition)
    498  1.1  christos     (struct bfd_link_info *, const char *name,
    499  1.1  christos      bfd *obfd, asection *osec, bfd_vma oval,
    500  1.1  christos      bfd *nbfd, asection *nsec, bfd_vma nval);
    501  1.1  christos   /* A function which is called when a common symbol is defined
    502  1.1  christos      multiple times.  NAME is the symbol appearing multiple times.
    503  1.1  christos      OBFD is the BFD of the existing symbol; it may be NULL if this is
    504  1.1  christos      not known.  OTYPE is the type of the existing symbol, which may
    505  1.1  christos      be bfd_link_hash_defined, bfd_link_hash_defweak,
    506  1.1  christos      bfd_link_hash_common, or bfd_link_hash_indirect.  If OTYPE is
    507  1.1  christos      bfd_link_hash_common, OSIZE is the size of the existing symbol.
    508  1.1  christos      NBFD is the BFD of the new symbol.  NTYPE is the type of the new
    509  1.1  christos      symbol, one of bfd_link_hash_defined, bfd_link_hash_common, or
    510  1.1  christos      bfd_link_hash_indirect.  If NTYPE is bfd_link_hash_common, NSIZE
    511  1.1  christos      is the size of the new symbol.  */
    512  1.1  christos   bfd_boolean (*multiple_common)
    513  1.1  christos     (struct bfd_link_info *, const char *name,
    514  1.1  christos      bfd *obfd, enum bfd_link_hash_type otype, bfd_vma osize,
    515  1.1  christos      bfd *nbfd, enum bfd_link_hash_type ntype, bfd_vma nsize);
    516  1.1  christos   /* A function which is called to add a symbol to a set.  ENTRY is
    517  1.1  christos      the link hash table entry for the set itself (e.g.,
    518  1.1  christos      __CTOR_LIST__).  RELOC is the relocation to use for an entry in
    519  1.1  christos      the set when generating a relocatable file, and is also used to
    520  1.1  christos      get the size of the entry when generating an executable file.
    521  1.1  christos      ABFD, SEC and VALUE identify the value to add to the set.  */
    522  1.1  christos   bfd_boolean (*add_to_set)
    523  1.1  christos     (struct bfd_link_info *, struct bfd_link_hash_entry *entry,
    524  1.1  christos      bfd_reloc_code_real_type reloc, bfd *abfd, asection *sec, bfd_vma value);
    525  1.1  christos   /* A function which is called when the name of a g++ constructor or
    526  1.1  christos      destructor is found.  This is only called by some object file
    527  1.1  christos      formats.  CONSTRUCTOR is TRUE for a constructor, FALSE for a
    528  1.1  christos      destructor.  This will use BFD_RELOC_CTOR when generating a
    529  1.1  christos      relocatable file.  NAME is the name of the symbol found.  ABFD,
    530  1.1  christos      SECTION and VALUE are the value of the symbol.  */
    531  1.1  christos   bfd_boolean (*constructor)
    532  1.1  christos     (struct bfd_link_info *, bfd_boolean constructor, const char *name,
    533  1.1  christos      bfd *abfd, asection *sec, bfd_vma value);
    534  1.1  christos   /* A function which is called to issue a linker warning.  For
    535  1.1  christos      example, this is called when there is a reference to a warning
    536  1.1  christos      symbol.  WARNING is the warning to be issued.  SYMBOL is the name
    537  1.1  christos      of the symbol which triggered the warning; it may be NULL if
    538  1.1  christos      there is none.  ABFD, SECTION and ADDRESS identify the location
    539  1.1  christos      which trigerred the warning; either ABFD or SECTION or both may
    540  1.1  christos      be NULL if the location is not known.  */
    541  1.1  christos   bfd_boolean (*warning)
    542  1.1  christos     (struct bfd_link_info *, const char *warning, const char *symbol,
    543  1.1  christos      bfd *abfd, asection *section, bfd_vma address);
    544  1.1  christos   /* A function which is called when a relocation is attempted against
    545  1.1  christos      an undefined symbol.  NAME is the symbol which is undefined.
    546  1.1  christos      ABFD, SECTION and ADDRESS identify the location from which the
    547  1.1  christos      reference is made. IS_FATAL indicates whether an undefined symbol is
    548  1.1  christos      a fatal error or not. In some cases SECTION may be NULL.  */
    549  1.1  christos   bfd_boolean (*undefined_symbol)
    550  1.1  christos     (struct bfd_link_info *, const char *name, bfd *abfd,
    551  1.1  christos      asection *section, bfd_vma address, bfd_boolean is_fatal);
    552  1.1  christos   /* A function which is called when a reloc overflow occurs. ENTRY is
    553  1.1  christos      the link hash table entry for the symbol the reloc is against.
    554  1.1  christos      NAME is the name of the local symbol or section the reloc is
    555  1.1  christos      against, RELOC_NAME is the name of the relocation, and ADDEND is
    556  1.1  christos      any addend that is used.  ABFD, SECTION and ADDRESS identify the
    557  1.1  christos      location at which the overflow occurs; if this is the result of a
    558  1.1  christos      bfd_section_reloc_link_order or bfd_symbol_reloc_link_order, then
    559  1.1  christos      ABFD will be NULL.  */
    560  1.1  christos   bfd_boolean (*reloc_overflow)
    561  1.1  christos     (struct bfd_link_info *, struct bfd_link_hash_entry *entry,
    562  1.1  christos      const char *name, const char *reloc_name, bfd_vma addend,
    563  1.1  christos      bfd *abfd, asection *section, bfd_vma address);
    564  1.1  christos   /* A function which is called when a dangerous reloc is performed.
    565  1.1  christos      MESSAGE is an appropriate message.
    566  1.1  christos      ABFD, SECTION and ADDRESS identify the location at which the
    567  1.1  christos      problem occurred; if this is the result of a
    568  1.1  christos      bfd_section_reloc_link_order or bfd_symbol_reloc_link_order, then
    569  1.1  christos      ABFD will be NULL.  */
    570  1.1  christos   bfd_boolean (*reloc_dangerous)
    571  1.1  christos     (struct bfd_link_info *, const char *message,
    572  1.1  christos      bfd *abfd, asection *section, bfd_vma address);
    573  1.1  christos   /* A function which is called when a reloc is found to be attached
    574  1.1  christos      to a symbol which is not being written out.  NAME is the name of
    575  1.1  christos      the symbol.  ABFD, SECTION and ADDRESS identify the location of
    576  1.1  christos      the reloc; if this is the result of a
    577  1.1  christos      bfd_section_reloc_link_order or bfd_symbol_reloc_link_order, then
    578  1.1  christos      ABFD will be NULL.  */
    579  1.1  christos   bfd_boolean (*unattached_reloc)
    580  1.1  christos     (struct bfd_link_info *, const char *name,
    581  1.1  christos      bfd *abfd, asection *section, bfd_vma address);
    582  1.1  christos   /* A function which is called when a symbol in notice_hash is
    583  1.1  christos      defined or referenced.  NAME is the symbol.  ABFD, SECTION and
    584  1.1  christos      ADDRESS are the value of the symbol.  If SECTION is
    585  1.1  christos      bfd_und_section, this is a reference.  */
    586  1.1  christos   bfd_boolean (*notice)
    587  1.1  christos     (struct bfd_link_info *, const char *name,
    588  1.1  christos      bfd *abfd, asection *section, bfd_vma address);
    589  1.1  christos   /* Error or warning link info message.  */
    590  1.1  christos   void (*einfo)
    591  1.1  christos     (const char *fmt, ...);
    592  1.1  christos   /* General link info message.  */
    593  1.1  christos   void (*info)
    594  1.1  christos     (const char *fmt, ...);
    595  1.1  christos   /* Message to be printed in linker map file.  */
    596  1.1  christos   void (*minfo)
    597  1.1  christos     (const char *fmt, ...);
    598  1.1  christos   /* This callback provides a chance for users of the BFD library to
    599  1.1  christos      override its decision about whether to place two adjacent sections
    600  1.1  christos      into the same segment.  */
    601  1.1  christos   bfd_boolean (*override_segment_assignment)
    602  1.1  christos     (struct bfd_link_info *, bfd * abfd,
    603  1.1  christos      asection * current_section, asection * previous_section,
    604  1.1  christos      bfd_boolean new_segment);
    605  1.1  christos };
    606  1.1  christos 
    607  1.1  christos /* The linker builds link_order structures which tell the code how to
    609  1.1  christos    include input data in the output file.  */
    610  1.1  christos 
    611  1.1  christos /* These are the types of link_order structures.  */
    612  1.1  christos 
    613  1.1  christos enum bfd_link_order_type
    614  1.1  christos {
    615  1.1  christos   bfd_undefined_link_order,	/* Undefined.  */
    616  1.1  christos   bfd_indirect_link_order,	/* Built from a section.  */
    617  1.1  christos   bfd_data_link_order,		/* Set to explicit data.  */
    618  1.1  christos   bfd_section_reloc_link_order,	/* Relocate against a section.  */
    619  1.1  christos   bfd_symbol_reloc_link_order	/* Relocate against a symbol.  */
    620  1.1  christos };
    621  1.1  christos 
    622  1.1  christos /* This is the link_order structure itself.  These form a chain
    623  1.1  christos    attached to the output section whose contents they are describing.  */
    624  1.1  christos 
    625  1.1  christos struct bfd_link_order
    626  1.1  christos {
    627  1.1  christos   /* Next link_order in chain.  */
    628  1.1  christos   struct bfd_link_order *next;
    629  1.1  christos   /* Type of link_order.  */
    630  1.1  christos   enum bfd_link_order_type type;
    631  1.1  christos   /* Offset within output section.  */
    632  1.1  christos   bfd_vma offset;
    633  1.1  christos   /* Size within output section.  */
    634  1.1  christos   bfd_size_type size;
    635  1.1  christos   /* Type specific information.  */
    636  1.1  christos   union
    637  1.1  christos     {
    638  1.1  christos       struct
    639  1.1  christos 	{
    640  1.1  christos 	  /* Section to include.  If this is used, then
    641  1.1  christos 	     section->output_section must be the section the
    642  1.1  christos 	     link_order is attached to, section->output_offset must
    643  1.1  christos 	     equal the link_order offset field, and section->size
    644  1.1  christos 	     must equal the link_order size field.  Maybe these
    645  1.1  christos 	     restrictions should be relaxed someday.  */
    646  1.1  christos 	  asection *section;
    647  1.1  christos 	} indirect;
    648  1.1  christos       struct
    649  1.1  christos 	{
    650  1.1  christos 	  /* Size of contents, or zero when contents size == size
    651  1.1  christos 	     within output section.
    652  1.1  christos 	     A non-zero value allows filling of the output section
    653  1.1  christos 	     with an arbitrary repeated pattern.  */
    654  1.1  christos 	  unsigned int size;
    655  1.1  christos 	  /* Data to put into file.  */
    656  1.1  christos 	  bfd_byte *contents;
    657  1.1  christos 	} data;
    658  1.1  christos       struct
    659  1.1  christos 	{
    660  1.1  christos 	  /* Description of reloc to generate.  Used for
    661  1.1  christos 	     bfd_section_reloc_link_order and
    662  1.1  christos 	     bfd_symbol_reloc_link_order.  */
    663  1.1  christos 	  struct bfd_link_order_reloc *p;
    664  1.1  christos 	} reloc;
    665  1.1  christos     } u;
    666  1.1  christos };
    667  1.1  christos 
    668  1.1  christos /* A linker order of type bfd_section_reloc_link_order or
    669  1.1  christos    bfd_symbol_reloc_link_order means to create a reloc against a
    670  1.1  christos    section or symbol, respectively.  This is used to implement -Ur to
    671  1.1  christos    generate relocs for the constructor tables.  The
    672  1.1  christos    bfd_link_order_reloc structure describes the reloc that BFD should
    673  1.1  christos    create.  It is similar to a arelent, but I didn't use arelent
    674  1.1  christos    because the linker does not know anything about most symbols, and
    675  1.1  christos    any asymbol structure it creates will be partially meaningless.
    676  1.1  christos    This information could logically be in the bfd_link_order struct,
    677  1.1  christos    but I didn't want to waste the space since these types of relocs
    678  1.1  christos    are relatively rare.  */
    679  1.1  christos 
    680  1.1  christos struct bfd_link_order_reloc
    681  1.1  christos {
    682  1.1  christos   /* Reloc type.  */
    683  1.1  christos   bfd_reloc_code_real_type reloc;
    684  1.1  christos 
    685  1.1  christos   union
    686  1.1  christos     {
    687  1.1  christos       /* For type bfd_section_reloc_link_order, this is the section
    688  1.1  christos 	 the reloc should be against.  This must be a section in the
    689  1.1  christos 	 output BFD, not any of the input BFDs.  */
    690  1.1  christos       asection *section;
    691  1.1  christos       /* For type bfd_symbol_reloc_link_order, this is the name of the
    692  1.1  christos 	 symbol the reloc should be against.  */
    693  1.1  christos       const char *name;
    694  1.1  christos     } u;
    695  1.1  christos 
    696  1.1  christos   /* Addend to use.  The object file should contain zero.  The BFD
    697  1.1  christos      backend is responsible for filling in the contents of the object
    698  1.1  christos      file correctly.  For some object file formats (e.g., COFF) the
    699  1.1  christos      addend must be stored into in the object file, and for some
    700  1.1  christos      (e.g., SPARC a.out) it is kept in the reloc.  */
    701  1.1  christos   bfd_vma addend;
    702  1.1  christos };
    703  1.1  christos 
    704  1.1  christos /* Allocate a new link_order for a section.  */
    705  1.1  christos extern struct bfd_link_order *bfd_new_link_order (bfd *, asection *);
    706  1.1  christos 
    707  1.1  christos /* These structures are used to describe version information for the
    708  1.1  christos    ELF linker.  These structures could be manipulated entirely inside
    709  1.1  christos    BFD, but it would be a pain.  Instead, the regular linker sets up
    710  1.1  christos    these structures, and then passes them into BFD.  */
    711  1.1  christos 
    712  1.1  christos /* Glob pattern for a version.  */
    713  1.1  christos 
    714  1.1  christos struct bfd_elf_version_expr
    715  1.1  christos {
    716  1.1  christos   /* Next glob pattern for this version.  */
    717  1.1  christos   struct bfd_elf_version_expr *next;
    718  1.1  christos   /* Glob pattern.  */
    719  1.1  christos   const char *pattern;
    720  1.1  christos   /* Set if pattern is not a glob.  */
    721  1.1  christos   unsigned int literal : 1;
    722  1.1  christos   /* Defined by ".symver".  */
    723  1.1  christos   unsigned int symver : 1;
    724  1.1  christos   /* Defined by version script.  */
    725  1.1  christos   unsigned int script : 1;
    726  1.1  christos   /* Pattern type.  */
    727  1.1  christos #define BFD_ELF_VERSION_C_TYPE		1
    728  1.1  christos #define BFD_ELF_VERSION_CXX_TYPE	2
    729  1.1  christos #define BFD_ELF_VERSION_JAVA_TYPE	4
    730  1.1  christos   unsigned int mask : 3;
    731  1.1  christos };
    732  1.1  christos 
    733  1.1  christos struct bfd_elf_version_expr_head
    734  1.1  christos {
    735  1.1  christos   /* List of all patterns, both wildcards and non-wildcards.  */
    736  1.1  christos   struct bfd_elf_version_expr *list;
    737  1.1  christos   /* Hash table for non-wildcards.  */
    738  1.1  christos   void *htab;
    739  1.1  christos   /* Remaining patterns.  */
    740  1.1  christos   struct bfd_elf_version_expr *remaining;
    741  1.1  christos   /* What kind of pattern types are present in list (bitmask).  */
    742  1.1  christos   unsigned int mask;
    743  1.1  christos };
    744  1.1  christos 
    745  1.1  christos /* Version dependencies.  */
    746  1.1  christos 
    747  1.1  christos struct bfd_elf_version_deps
    748  1.1  christos {
    749  1.1  christos   /* Next dependency for this version.  */
    750  1.1  christos   struct bfd_elf_version_deps *next;
    751  1.1  christos   /* The version which this version depends upon.  */
    752  1.1  christos   struct bfd_elf_version_tree *version_needed;
    753  1.1  christos };
    754  1.1  christos 
    755  1.1  christos /* A node in the version tree.  */
    756  1.1  christos 
    757  1.1  christos struct bfd_elf_version_tree
    758  1.1  christos {
    759  1.1  christos   /* Next version.  */
    760  1.1  christos   struct bfd_elf_version_tree *next;
    761  1.1  christos   /* Name of this version.  */
    762  1.1  christos   const char *name;
    763  1.1  christos   /* Version number.  */
    764  1.1  christos   unsigned int vernum;
    765  1.1  christos   /* Regular expressions for global symbols in this version.  */
    766  1.1  christos   struct bfd_elf_version_expr_head globals;
    767  1.1  christos   /* Regular expressions for local symbols in this version.  */
    768  1.1  christos   struct bfd_elf_version_expr_head locals;
    769  1.1  christos   /* List of versions which this version depends upon.  */
    770  1.1  christos   struct bfd_elf_version_deps *deps;
    771  1.1  christos   /* Index of the version name.  This is used within BFD.  */
    772  1.1  christos   unsigned int name_indx;
    773  1.1  christos   /* Whether this version tree was used.  This is used within BFD.  */
    774  1.1  christos   int used;
    775  1.1  christos   /* Matching hook.  */
    776  1.1  christos   struct bfd_elf_version_expr *(*match)
    777  1.1  christos     (struct bfd_elf_version_expr_head *head,
    778  1.1  christos      struct bfd_elf_version_expr *prev, const char *sym);
    779  1.1  christos };
    780  1.1  christos 
    781  1.1  christos struct bfd_elf_dynamic_list
    782  1.1  christos {
    783  1.1  christos   struct bfd_elf_version_expr_head head;
    784  1.1  christos   struct bfd_elf_version_expr *(*match)
    785  1.1  christos     (struct bfd_elf_version_expr_head *head,
    786  1.1  christos      struct bfd_elf_version_expr *prev, const char *sym);
    787                };
    788                
    789                #endif
    790