PR 1150
[platform/upstream/binutils.git] / bfd / elf-bfd.h
1 /* BFD back-end data structures for ELF files.
2    Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
3    2002, 2003, 2004, 2005 Free Software Foundation, Inc.
4    Written by Cygnus Support.
5
6    This file is part of BFD, the Binary File Descriptor library.
7
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
21
22 #ifndef _LIBELF_H_
23 #define _LIBELF_H_ 1
24
25 #include "elf/common.h"
26 #include "elf/internal.h"
27 #include "elf/external.h"
28 #include "bfdlink.h"
29
30 /* The number of entries in a section is its size divided by the size
31    of a single entry.  This is normally only applicable to reloc and
32    symbol table sections.  */
33 #define NUM_SHDR_ENTRIES(shdr) ((shdr)->sh_size / (shdr)->sh_entsize)
34
35 /* If size isn't specified as 64 or 32, NAME macro should fail.  */
36 #ifndef NAME
37 #if ARCH_SIZE == 64
38 #define NAME(x, y) x ## 64 ## _ ## y
39 #endif
40 #if ARCH_SIZE == 32
41 #define NAME(x, y) x ## 32 ## _ ## y
42 #endif
43 #endif
44
45 #ifndef NAME
46 #define NAME(x, y) x ## NOSIZE ## _ ## y
47 #endif
48
49 #define ElfNAME(X)      NAME(Elf,X)
50 #define elfNAME(X)      NAME(elf,X)
51
52 /* Information held for an ELF symbol.  The first field is the
53    corresponding asymbol.  Every symbol is an ELF file is actually a
54    pointer to this structure, although it is often handled as a
55    pointer to an asymbol.  */
56
57 typedef struct
58 {
59   /* The BFD symbol.  */
60   asymbol symbol;
61   /* ELF symbol information.  */
62   Elf_Internal_Sym internal_elf_sym;
63   /* Backend specific information.  */
64   union
65     {
66       unsigned int hppa_arg_reloc;
67       void *mips_extr;
68       void *any;
69     }
70   tc_data;
71
72   /* Version information.  This is from an Elf_Internal_Versym
73      structure in a SHT_GNU_versym section.  It is zero if there is no
74      version information.  */
75   unsigned short version;
76
77 } elf_symbol_type;
78 \f
79 struct elf_strtab_hash;
80 struct got_entry;
81 struct plt_entry;
82
83 /* ELF linker hash table entries.  */
84
85 struct elf_link_hash_entry
86 {
87   struct bfd_link_hash_entry root;
88
89   /* Symbol index in output file.  This is initialized to -1.  It is
90      set to -2 if the symbol is used by a reloc.  */
91   long indx;
92
93   /* Symbol index as a dynamic symbol.  Initialized to -1, and remains
94      -1 if this is not a dynamic symbol.  */
95   /* ??? Note that this is consistently used as a synonym for tests
96      against whether we can perform various simplifying transformations
97      to the code.  (E.g. changing a pc-relative jump to a PLT entry
98      into a pc-relative jump to the target function.)  That test, which
99      is often relatively complex, and someplaces wrong or incomplete,
100      should really be replaced by a predicate in elflink.c.
101
102      End result: this field -1 does not indicate that the symbol is
103      not in the dynamic symbol table, but rather that the symbol is
104      not visible outside this DSO.  */
105   long dynindx;
106
107   /* If this symbol requires an entry in the global offset table, the
108      processor specific backend uses this field to track usage and
109      final offset.  Two schemes are supported:  The first assumes that
110      a symbol may only have one GOT entry, and uses REFCOUNT until
111      size_dynamic_sections, at which point the contents of the .got is
112      fixed.  Afterward, if OFFSET is -1, then the symbol does not
113      require a global offset table entry.  The second scheme allows
114      multiple GOT entries per symbol, managed via a linked list
115      pointed to by GLIST.  */
116   union gotplt_union
117     {
118       bfd_signed_vma refcount;
119       bfd_vma offset;
120       struct got_entry *glist;
121       struct plt_entry *plist;
122     } got;
123
124   /* Same, but tracks a procedure linkage table entry.  */
125   union gotplt_union plt;
126
127   /* Symbol size.  */
128   bfd_size_type size;
129
130   /* Symbol type (STT_NOTYPE, STT_OBJECT, etc.).  */
131   unsigned int type : 8;
132
133   /* Symbol st_other value, symbol visibility.  */
134   unsigned int other : 8;
135
136   /* Symbol is referenced by a non-shared object.  */
137   unsigned int ref_regular : 1;
138   /* Symbol is defined by a non-shared object.  */
139   unsigned int def_regular : 1;
140   /* Symbol is referenced by a shared object.  */
141   unsigned int ref_dynamic : 1;
142   /* Symbol is defined by a shared object.  */
143   unsigned int def_dynamic : 1;
144   /* Symbol has a non-weak reference from a non-shared object.  */
145   unsigned int ref_regular_nonweak : 1;
146   /* Dynamic symbol has been adjustd.  */
147   unsigned int dynamic_adjusted : 1;
148   /* Symbol needs a copy reloc.  */
149   unsigned int needs_copy : 1;
150   /* Symbol needs a procedure linkage table entry.  */
151   unsigned int needs_plt : 1;
152   /* Symbol appears in a non-ELF input file.  */
153   unsigned int non_elf : 1;
154   /* Symbol should be marked as hidden in the version information.  */
155   unsigned int hidden : 1;
156   /* Symbol was forced to local scope due to a version script file.  */
157   unsigned int forced_local : 1;
158   /* Symbol was marked during garbage collection.  */
159   unsigned int mark : 1;
160   /* Symbol is referenced by a non-GOT/non-PLT relocation.  This is
161      not currently set by all the backends.  */
162   unsigned int non_got_ref : 1;
163   /* Symbol has a definition in a shared object.
164      FIXME: There is no real need for this field if def_dynamic is never
165      cleared and all places that test def_dynamic also test def_regular.  */
166   unsigned int dynamic_def : 1;
167   /* Symbol is weak in all shared objects.  */
168   unsigned int dynamic_weak : 1;
169   /* Symbol is referenced with a relocation where C/C++ pointer equality
170      matters.  */
171   unsigned int pointer_equality_needed : 1;
172
173   /* String table index in .dynstr if this is a dynamic symbol.  */
174   unsigned long dynstr_index;
175
176   union
177   {
178     /* If this is a weak defined symbol from a dynamic object, this
179        field points to a defined symbol with the same value, if there is
180        one.  Otherwise it is NULL.  */
181     struct elf_link_hash_entry *weakdef;
182
183     /* Hash value of the name computed using the ELF hash function.
184        Used part way through size_dynamic_sections, after we've finished
185        with weakdefs.  */
186     unsigned long elf_hash_value;
187   } u;
188
189   /* Version information.  */
190   union
191   {
192     /* This field is used for a symbol which is not defined in a
193        regular object.  It points to the version information read in
194        from the dynamic object.  */
195     Elf_Internal_Verdef *verdef;
196     /* This field is used for a symbol which is defined in a regular
197        object.  It is set up in size_dynamic_sections.  It points to
198        the version information we should write out for this symbol.  */
199     struct bfd_elf_version_tree *vertree;
200   } verinfo;
201
202   struct
203   {
204     /* Virtual table entry use information.  This array is nominally of size
205        size/sizeof(target_void_pointer), though we have to be able to assume
206        and track a size while the symbol is still undefined.  It is indexed
207        via offset/sizeof(target_void_pointer).  */
208     size_t size;
209     bfd_boolean *used;
210
211     /* Virtual table derivation info.  */
212     struct elf_link_hash_entry *parent;
213   } *vtable;
214 };
215
216 /* Will references to this symbol always reference the symbol
217    in this object?  STV_PROTECTED is excluded from the visibility test
218    here so that function pointer comparisons work properly.  Since
219    function symbols not defined in an app are set to their .plt entry,
220    it's necessary for shared libs to also reference the .plt even
221    though the symbol is really local to the shared lib.  */
222 #define SYMBOL_REFERENCES_LOCAL(INFO, H) \
223   _bfd_elf_symbol_refs_local_p (H, INFO, 0)
224
225 /* Will _calls_ to this symbol always call the version in this object?  */
226 #define SYMBOL_CALLS_LOCAL(INFO, H) \
227   _bfd_elf_symbol_refs_local_p (H, INFO, 1)
228
229 /* Common symbols that are turned into definitions don't have the
230    DEF_REGULAR flag set, so they might appear to be undefined.  */
231 #define ELF_COMMON_DEF_P(H) \
232   (!(H)->def_regular                                                    \
233    && !(H)->def_dynamic                                                 \
234    && (H)->root.type == bfd_link_hash_defined)
235
236 /* Records local symbols to be emitted in the dynamic symbol table.  */
237
238 struct elf_link_local_dynamic_entry
239 {
240   struct elf_link_local_dynamic_entry *next;
241
242   /* The input bfd this symbol came from.  */
243   bfd *input_bfd;
244
245   /* The index of the local symbol being copied.  */
246   long input_indx;
247
248   /* The index in the outgoing dynamic symbol table.  */
249   long dynindx;
250
251   /* A copy of the input symbol.  */
252   Elf_Internal_Sym isym;
253 };
254
255 struct elf_link_loaded_list
256 {
257   struct elf_link_loaded_list *next;
258   bfd *abfd;
259 };
260
261 /* Structures used by the eh_frame optimization code.  */
262 struct cie_header
263 {
264   unsigned int length;
265   unsigned int id;
266 };
267
268 struct cie
269 {
270   struct cie_header hdr;
271   unsigned char version;
272   char augmentation[20];
273   bfd_vma code_align;
274   bfd_signed_vma data_align;
275   bfd_vma ra_column;
276   bfd_vma augmentation_size;
277   struct elf_link_hash_entry *personality;
278   unsigned char per_encoding;
279   unsigned char lsda_encoding;
280   unsigned char fde_encoding;
281   unsigned char initial_insn_length;
282   unsigned char make_relative;
283   unsigned char make_lsda_relative;
284   unsigned char initial_instructions[50];
285 };
286
287 struct eh_cie_fde
288 {
289   /* For FDEs, this points to the CIE used.  */
290   struct eh_cie_fde *cie_inf;
291   unsigned int size;
292   unsigned int offset;
293   unsigned int new_offset;
294   unsigned char fde_encoding;
295   unsigned char lsda_encoding;
296   unsigned char lsda_offset;
297   unsigned int cie : 1;
298   unsigned int removed : 1;
299   unsigned int add_augmentation_size : 1;
300   unsigned int add_fde_encoding : 1;
301   unsigned int make_relative : 1;
302   unsigned int make_lsda_relative : 1;
303   unsigned int need_lsda_relative : 1;
304   unsigned int per_encoding_relative : 1;
305 };
306
307 struct eh_frame_sec_info
308 {
309   unsigned int count;
310   unsigned int alloced;
311   struct eh_cie_fde entry[1];
312 };
313
314 struct eh_frame_array_ent
315 {
316   bfd_vma initial_loc;
317   bfd_vma fde;
318 };
319
320 struct eh_frame_hdr_info
321 {
322   struct cie last_cie;
323   asection *last_cie_sec;
324   struct eh_cie_fde *last_cie_inf;
325   asection *hdr_sec;
326   unsigned int fde_count, array_count;
327   struct eh_frame_array_ent *array;
328   /* TRUE if .eh_frame_hdr should contain the sorted search table.
329      We build it if we successfully read all .eh_frame input sections
330      and recognize them.  */
331   bfd_boolean table;
332   bfd_boolean offsets_adjusted;
333 };
334
335 /* ELF linker hash table.  */
336
337 struct elf_link_hash_table
338 {
339   struct bfd_link_hash_table root;
340
341   /* Whether we have created the special dynamic sections required
342      when linking against or generating a shared object.  */
343   bfd_boolean dynamic_sections_created;
344
345   /* The BFD used to hold special sections created by the linker.
346      This will be the first BFD found which requires these sections to
347      be created.  */
348   bfd *dynobj;
349
350   /* The value to use when initialising got.refcount/offset and
351      plt.refcount/offset in an elf_link_hash_entry.  Set to zero when
352      the values are refcounts.  Set to init_got_offset/init_plt_offset
353      in size_dynamic_sections when the values may be offsets.  */
354   union gotplt_union init_got_refcount;
355   union gotplt_union init_plt_refcount;
356
357   /* The value to use for got.refcount/offset and plt.refcount/offset
358      when the values may be offsets.  Normally (bfd_vma) -1.  */
359   union gotplt_union init_got_offset;
360   union gotplt_union init_plt_offset;
361
362   /* The number of symbols found in the link which must be put into
363      the .dynsym section.  */
364   bfd_size_type dynsymcount;
365
366   /* The string table of dynamic symbols, which becomes the .dynstr
367      section.  */
368   struct elf_strtab_hash *dynstr;
369
370   /* The number of buckets in the hash table in the .hash section.
371      This is based on the number of dynamic symbols.  */
372   bfd_size_type bucketcount;
373
374   /* A linked list of DT_NEEDED names found in dynamic objects
375      included in the link.  */
376   struct bfd_link_needed_list *needed;
377
378   /* The _GLOBAL_OFFSET_TABLE_ symbol.  */
379   struct elf_link_hash_entry *hgot;
380
381   /* A pointer to information used to merge SEC_MERGE sections.  */
382   void *merge_info;
383
384   /* Used to link stabs in sections.  */
385   struct stab_info stab_info;
386
387   /* Used by eh_frame code when editing .eh_frame.  */
388   struct eh_frame_hdr_info eh_info;
389
390   /* A linked list of local symbols to be added to .dynsym.  */
391   struct elf_link_local_dynamic_entry *dynlocal;
392
393   /* A linked list of DT_RPATH/DT_RUNPATH names found in dynamic
394      objects included in the link.  */
395   struct bfd_link_needed_list *runpath;
396
397   /* Cached first output tls section and size of PT_TLS segment.  */
398   asection *tls_sec;
399   bfd_size_type tls_size;
400
401   /* A linked list of BFD's loaded in the link.  */
402   struct elf_link_loaded_list *loaded;
403
404   /* True if this target has relocatable executables, so needs dynamic
405      section symbols.  */
406   bfd_boolean is_relocatable_executable;
407 };
408
409 /* Look up an entry in an ELF linker hash table.  */
410
411 #define elf_link_hash_lookup(table, string, create, copy, follow)       \
412   ((struct elf_link_hash_entry *)                                       \
413    bfd_link_hash_lookup (&(table)->root, (string), (create),            \
414                          (copy), (follow)))
415
416 /* Traverse an ELF linker hash table.  */
417
418 #define elf_link_hash_traverse(table, func, info)                       \
419   (bfd_link_hash_traverse                                               \
420    (&(table)->root,                                                     \
421     (bfd_boolean (*) (struct bfd_link_hash_entry *, void *)) (func),    \
422     (info)))
423
424 /* Get the ELF linker hash table from a link_info structure.  */
425
426 #define elf_hash_table(p) ((struct elf_link_hash_table *) ((p)->hash))
427
428 /* Returns TRUE if the hash table is a struct elf_link_hash_table.  */
429 #define is_elf_hash_table(htab)                                         \
430   (((struct bfd_link_hash_table *) (htab))->type == bfd_link_elf_hash_table)
431
432 /* Used by bfd_section_from_r_symndx to cache a small number of local
433    symbol to section mappings.  */
434 #define LOCAL_SYM_CACHE_SIZE 32
435 struct sym_sec_cache
436 {
437   bfd *abfd;
438   unsigned long indx[LOCAL_SYM_CACHE_SIZE];
439   asection *sec[LOCAL_SYM_CACHE_SIZE];
440 };
441 \f
442 /* Constant information held for an ELF backend.  */
443
444 struct elf_size_info {
445   unsigned char sizeof_ehdr, sizeof_phdr, sizeof_shdr;
446   unsigned char sizeof_rel, sizeof_rela, sizeof_sym, sizeof_dyn, sizeof_note;
447
448   /* The size of entries in the .hash section.  */
449   unsigned char sizeof_hash_entry;
450
451   /* The number of internal relocations to allocate per external
452      relocation entry.  */
453   unsigned char int_rels_per_ext_rel;
454   /* We use some fixed size arrays.  This should be large enough to
455      handle all back-ends.  */
456 #define MAX_INT_RELS_PER_EXT_REL 3
457
458   unsigned char arch_size, log_file_align;
459   unsigned char elfclass, ev_current;
460   int (*write_out_phdrs)
461     (bfd *, const Elf_Internal_Phdr *, unsigned int);
462   bfd_boolean
463     (*write_shdrs_and_ehdr) (bfd *);
464   void (*write_relocs)
465     (bfd *, asection *, void *);
466   void (*swap_symbol_in)
467     (bfd *, const void *, const void *, Elf_Internal_Sym *);
468   void (*swap_symbol_out)
469     (bfd *, const Elf_Internal_Sym *, void *, void *);
470   bfd_boolean (*slurp_reloc_table)
471     (bfd *, asection *, asymbol **, bfd_boolean);
472   long (*slurp_symbol_table)
473     (bfd *, asymbol **, bfd_boolean);
474   void (*swap_dyn_in)
475     (bfd *, const void *, Elf_Internal_Dyn *);
476   void (*swap_dyn_out)
477     (bfd *, const Elf_Internal_Dyn *, void *);
478
479   /* This function is called to swap in a REL relocation.  If an
480      external relocation corresponds to more than one internal
481      relocation, then all relocations are swapped in at once.  */
482   void (*swap_reloc_in)
483     (bfd *, const bfd_byte *, Elf_Internal_Rela *);
484
485   /* This function is called to swap out a REL relocation.  */
486   void (*swap_reloc_out)
487     (bfd *, const Elf_Internal_Rela *, bfd_byte *);
488
489   /* This function is called to swap in a RELA relocation.  If an
490      external relocation corresponds to more than one internal
491      relocation, then all relocations are swapped in at once.  */
492   void (*swap_reloca_in)
493     (bfd *, const bfd_byte *, Elf_Internal_Rela *);
494
495   /* This function is called to swap out a RELA relocation.  */
496   void (*swap_reloca_out)
497     (bfd *, const Elf_Internal_Rela *, bfd_byte *);
498 };
499
500 #define elf_symbol_from(ABFD,S) \
501         (((S)->the_bfd->xvec->flavour == bfd_target_elf_flavour \
502           && (S)->the_bfd->tdata.elf_obj_data != 0) \
503          ? (elf_symbol_type *) (S) \
504          : 0)
505
506 enum elf_reloc_type_class {
507   reloc_class_normal,
508   reloc_class_relative,
509   reloc_class_plt,
510   reloc_class_copy
511 };
512
513 struct elf_reloc_cookie
514 {
515   Elf_Internal_Rela *rels, *rel, *relend;
516   Elf_Internal_Sym *locsyms;
517   bfd *abfd;
518   size_t locsymcount;
519   size_t extsymoff;
520   struct elf_link_hash_entry **sym_hashes;
521   int r_sym_shift;
522   bfd_boolean bad_symtab;
523 };
524
525 /* The level of IRIX compatibility we're striving for.  */
526
527 typedef enum {
528   ict_none,
529   ict_irix5,
530   ict_irix6
531 } irix_compat_t;
532
533 /* Mapping of ELF section names and types.  */
534 struct bfd_elf_special_section
535 {
536   const char *prefix;
537   int prefix_length;
538   /* 0 means name must match PREFIX exactly.
539      -1 means name must start with PREFIX followed by an arbitrary string.
540      -2 means name must match PREFIX exactly or consist of PREFIX followed
541      by a dot then anything.
542      > 0 means name must start with the first PREFIX_LENGTH chars of
543      PREFIX and finish with the last SUFFIX_LENGTH chars of PREFIX.  */
544   int suffix_length;
545   int type;
546   int attr;
547 };
548
549 enum action_discarded
550   {
551     COMPLAIN = 1,
552     PRETEND = 2
553   };
554
555 struct elf_backend_data
556 {
557   /* The architecture for this backend.  */
558   enum bfd_architecture arch;
559
560   /* The ELF machine code (EM_xxxx) for this backend.  */
561   int elf_machine_code;
562
563   /* The maximum page size for this backend.  */
564   bfd_vma maxpagesize;
565
566   /* The minimum page size for this backend.  An input object will not be
567      considered page aligned unless its sections are correctly aligned for
568      pages at least this large.  May be smaller than maxpagesize.  */
569   bfd_vma minpagesize;
570
571   /* The BFD flags applied to sections created for dynamic linking.  */
572   flagword dynamic_sec_flags;
573
574   /* A function to translate an ELF RELA relocation to a BFD arelent
575      structure.  */
576   void (*elf_info_to_howto)
577     (bfd *, arelent *, Elf_Internal_Rela *);
578
579   /* A function to translate an ELF REL relocation to a BFD arelent
580      structure.  */
581   void (*elf_info_to_howto_rel)
582     (bfd *, arelent *, Elf_Internal_Rela *);
583
584   /* A function to determine whether a symbol is global when
585      partitioning the symbol table into local and global symbols.
586      This should be NULL for most targets, in which case the correct
587      thing will be done.  MIPS ELF, at least on the Irix 5, has
588      special requirements.  */
589   bfd_boolean (*elf_backend_sym_is_global)
590     (bfd *, asymbol *);
591
592   /* The remaining functions are hooks which are called only if they
593      are not NULL.  */
594
595   /* A function to permit a backend specific check on whether a
596      particular BFD format is relevant for an object file, and to
597      permit the backend to set any global information it wishes.  When
598      this is called elf_elfheader is set, but anything else should be
599      used with caution.  If this returns FALSE, the check_format
600      routine will return a bfd_error_wrong_format error.  */
601   bfd_boolean (*elf_backend_object_p)
602     (bfd *);
603
604   /* A function to do additional symbol processing when reading the
605      ELF symbol table.  This is where any processor-specific special
606      section indices are handled.  */
607   void (*elf_backend_symbol_processing)
608     (bfd *, asymbol *);
609
610   /* A function to do additional symbol processing after reading the
611      entire ELF symbol table.  */
612   bfd_boolean (*elf_backend_symbol_table_processing)
613     (bfd *, elf_symbol_type *, unsigned int);
614
615   /* A function to set the type of the info field.  Processor-specific
616      types should be handled here.  */
617   int (*elf_backend_get_symbol_type)
618     (Elf_Internal_Sym *, int);
619
620   /* A function to return the linker hash table entry of a symbol that
621      might be satisfied by an archive symbol.  */
622   struct elf_link_hash_entry * (*elf_backend_archive_symbol_lookup)
623     (bfd *, struct bfd_link_info *, const char *);
624
625   /* Return true if local section symbols should have a non-null st_name.
626      NULL implies false.  */
627   bfd_boolean (*elf_backend_name_local_section_symbols)
628     (bfd *);
629
630   /* A function to do additional processing on the ELF section header
631      just before writing it out.  This is used to set the flags and
632      type fields for some sections, or to actually write out data for
633      unusual sections.  */
634   bfd_boolean (*elf_backend_section_processing)
635     (bfd *, Elf_Internal_Shdr *);
636
637   /* A function to handle unusual section types when creating BFD
638      sections from ELF sections.  */
639   bfd_boolean (*elf_backend_section_from_shdr)
640     (bfd *, Elf_Internal_Shdr *, const char *, int);
641
642   /* A function to convert machine dependent ELF section header flags to
643      BFD internal section header flags.  */
644   bfd_boolean (*elf_backend_section_flags)
645     (flagword *, const Elf_Internal_Shdr *);
646
647   /* A function that returns a struct containing ELF section flags and
648      type for the given BFD section.   */
649   const struct bfd_elf_special_section * (*get_sec_type_attr)
650     (bfd *, asection *);
651
652   /* A function to handle unusual program segment types when creating BFD
653      sections from ELF program segments.  */
654   bfd_boolean (*elf_backend_section_from_phdr)
655     (bfd *, Elf_Internal_Phdr *, int, const char *);
656
657   /* A function to set up the ELF section header for a BFD section in
658      preparation for writing it out.  This is where the flags and type
659      fields are set for unusual sections.  */
660   bfd_boolean (*elf_backend_fake_sections)
661     (bfd *, Elf_Internal_Shdr *, asection *);
662
663   /* A function to get the ELF section index for a BFD section.  If
664      this returns TRUE, the section was found.  If it is a normal ELF
665      section, *RETVAL should be left unchanged.  If it is not a normal
666      ELF section *RETVAL should be set to the SHN_xxxx index.  */
667   bfd_boolean (*elf_backend_section_from_bfd_section)
668     (bfd *, asection *, int *retval);
669
670   /* If this field is not NULL, it is called by the add_symbols phase
671      of a link just before adding a symbol to the global linker hash
672      table.  It may modify any of the fields as it wishes.  If *NAME
673      is set to NULL, the symbol will be skipped rather than being
674      added to the hash table.  This function is responsible for
675      handling all processor dependent symbol bindings and section
676      indices, and must set at least *FLAGS and *SEC for each processor
677      dependent case; failure to do so will cause a link error.  */
678   bfd_boolean (*elf_add_symbol_hook)
679     (bfd *abfd, struct bfd_link_info *info, Elf_Internal_Sym *,
680      const char **name, flagword *flags, asection **sec, bfd_vma *value);
681
682   /* If this field is not NULL, it is called by the elf_link_output_sym
683      phase of a link for each symbol which will appear in the object file.  */
684   bfd_boolean (*elf_backend_link_output_symbol_hook)
685     (struct bfd_link_info *info, const char *, Elf_Internal_Sym *,
686      asection *, struct elf_link_hash_entry *);
687
688   /* The CREATE_DYNAMIC_SECTIONS function is called by the ELF backend
689      linker the first time it encounters a dynamic object in the link.
690      This function must create any sections required for dynamic
691      linking.  The ABFD argument is a dynamic object.  The .interp,
692      .dynamic, .dynsym, .dynstr, and .hash functions have already been
693      created, and this function may modify the section flags if
694      desired.  This function will normally create the .got and .plt
695      sections, but different backends have different requirements.  */
696   bfd_boolean (*elf_backend_create_dynamic_sections)
697     (bfd *abfd, struct bfd_link_info *info);
698
699   /* When creating a shared library, determine whether to omit the
700      dynamic symbol for the section.  */
701   bfd_boolean (*elf_backend_omit_section_dynsym)
702     (bfd *output_bfd, struct bfd_link_info *info, asection *osec);
703
704   /* The CHECK_RELOCS function is called by the add_symbols phase of
705      the ELF backend linker.  It is called once for each section with
706      relocs of an object file, just after the symbols for the object
707      file have been added to the global linker hash table.  The
708      function must look through the relocs and do any special handling
709      required.  This generally means allocating space in the global
710      offset table, and perhaps allocating space for a reloc.  The
711      relocs are always passed as Rela structures; if the section
712      actually uses Rel structures, the r_addend field will always be
713      zero.  */
714   bfd_boolean (*check_relocs)
715     (bfd *abfd, struct bfd_link_info *info, asection *o,
716      const Elf_Internal_Rela *relocs);
717
718   /* The CHECK_DIRECTIVES function is called once per input file by
719      the add_symbols phase of the ELF backend linker.  The function
720      must inspect the bfd and create any additional symbols according
721      to any custom directives in the bfd.  */
722   bfd_boolean (*check_directives)
723     (bfd *abfd, struct bfd_link_info *info);
724
725   /* The ADJUST_DYNAMIC_SYMBOL function is called by the ELF backend
726      linker for every symbol which is defined by a dynamic object and
727      referenced by a regular object.  This is called after all the
728      input files have been seen, but before the SIZE_DYNAMIC_SECTIONS
729      function has been called.  The hash table entry should be
730      bfd_link_hash_defined ore bfd_link_hash_defweak, and it should be
731      defined in a section from a dynamic object.  Dynamic object
732      sections are not included in the final link, and this function is
733      responsible for changing the value to something which the rest of
734      the link can deal with.  This will normally involve adding an
735      entry to the .plt or .got or some such section, and setting the
736      symbol to point to that.  */
737   bfd_boolean (*elf_backend_adjust_dynamic_symbol)
738     (struct bfd_link_info *info, struct elf_link_hash_entry *h);
739
740   /* The ALWAYS_SIZE_SECTIONS function is called by the backend linker
741      after all the linker input files have been seen but before the
742      section sizes have been set.  This is called after
743      ADJUST_DYNAMIC_SYMBOL, but before SIZE_DYNAMIC_SECTIONS.  */
744   bfd_boolean (*elf_backend_always_size_sections)
745     (bfd *output_bfd, struct bfd_link_info *info);
746
747   /* The SIZE_DYNAMIC_SECTIONS function is called by the ELF backend
748      linker after all the linker input files have been seen but before
749      the sections sizes have been set.  This is called after
750      ADJUST_DYNAMIC_SYMBOL has been called on all appropriate symbols.
751      It is only called when linking against a dynamic object.  It must
752      set the sizes of the dynamic sections, and may fill in their
753      contents as well.  The generic ELF linker can handle the .dynsym,
754      .dynstr and .hash sections.  This function must handle the
755      .interp section and any sections created by the
756      CREATE_DYNAMIC_SECTIONS entry point.  */
757   bfd_boolean (*elf_backend_size_dynamic_sections)
758     (bfd *output_bfd, struct bfd_link_info *info);
759
760   /* The RELOCATE_SECTION function is called by the ELF backend linker
761      to handle the relocations for a section.
762
763      The relocs are always passed as Rela structures; if the section
764      actually uses Rel structures, the r_addend field will always be
765      zero.
766
767      This function is responsible for adjust the section contents as
768      necessary, and (if using Rela relocs and generating a
769      relocatable output file) adjusting the reloc addend as
770      necessary.
771
772      This function does not have to worry about setting the reloc
773      address or the reloc symbol index.
774
775      LOCAL_SYMS is a pointer to the swapped in local symbols.
776
777      LOCAL_SECTIONS is an array giving the section in the input file
778      corresponding to the st_shndx field of each local symbol.
779
780      The global hash table entry for the global symbols can be found
781      via elf_sym_hashes (input_bfd).
782
783      When generating relocatable output, this function must handle
784      STB_LOCAL/STT_SECTION symbols specially.  The output symbol is
785      going to be the section symbol corresponding to the output
786      section, which means that the addend must be adjusted
787      accordingly.  */
788   bfd_boolean (*elf_backend_relocate_section)
789     (bfd *output_bfd, struct bfd_link_info *info, bfd *input_bfd,
790      asection *input_section, bfd_byte *contents, Elf_Internal_Rela *relocs,
791      Elf_Internal_Sym *local_syms, asection **local_sections);
792
793   /* The FINISH_DYNAMIC_SYMBOL function is called by the ELF backend
794      linker just before it writes a symbol out to the .dynsym section.
795      The processor backend may make any required adjustment to the
796      symbol.  It may also take the opportunity to set contents of the
797      dynamic sections.  Note that FINISH_DYNAMIC_SYMBOL is called on
798      all .dynsym symbols, while ADJUST_DYNAMIC_SYMBOL is only called
799      on those symbols which are defined by a dynamic object.  */
800   bfd_boolean (*elf_backend_finish_dynamic_symbol)
801     (bfd *output_bfd, struct bfd_link_info *info,
802      struct elf_link_hash_entry *h, Elf_Internal_Sym *sym);
803
804   /* The FINISH_DYNAMIC_SECTIONS function is called by the ELF backend
805      linker just before it writes all the dynamic sections out to the
806      output file.  The FINISH_DYNAMIC_SYMBOL will have been called on
807      all dynamic symbols.  */
808   bfd_boolean (*elf_backend_finish_dynamic_sections)
809     (bfd *output_bfd, struct bfd_link_info *info);
810
811   /* A function to do any beginning processing needed for the ELF file
812      before building the ELF headers and computing file positions.  */
813   void (*elf_backend_begin_write_processing)
814     (bfd *, struct bfd_link_info *);
815
816   /* A function to do any final processing needed for the ELF file
817      before writing it out.  The LINKER argument is TRUE if this BFD
818      was created by the ELF backend linker.  */
819   void (*elf_backend_final_write_processing)
820     (bfd *, bfd_boolean linker);
821
822   /* This function is called by get_program_header_size.  It should
823      return the number of additional program segments which this BFD
824      will need.  It should return -1 on error.  */
825   int (*elf_backend_additional_program_headers)
826     (bfd *);
827
828   /* This function is called to modify an existing segment map in a
829      backend specific fashion.  */
830   bfd_boolean (*elf_backend_modify_segment_map)
831     (bfd *, struct bfd_link_info *);
832
833   /* This function is called during section gc to discover the section a
834      particular relocation refers to.  */
835   asection * (*gc_mark_hook)
836     (asection *sec, struct bfd_link_info *, Elf_Internal_Rela *,
837      struct elf_link_hash_entry *h, Elf_Internal_Sym *);
838
839   /* This function, if defined, is called during the sweep phase of gc
840      in order that a backend might update any data structures it might
841      be maintaining.  */
842   bfd_boolean (*gc_sweep_hook)
843     (bfd *abfd, struct bfd_link_info *info, asection *o,
844      const Elf_Internal_Rela *relocs);
845
846   /* This function, if defined, is called after the ELF headers have
847      been created.  This allows for things like the OS and ABI versions
848      to be changed.  */
849   void (*elf_backend_post_process_headers)
850     (bfd *, struct bfd_link_info *);
851
852   /* This function, if defined, prints a symbol to file and returns the
853      name of the symbol to be printed.  It should return NULL to fall
854      back to default symbol printing.  */
855   const char *(*elf_backend_print_symbol_all)
856     (bfd *, void *, asymbol *);
857
858   /* This function, if defined, is called after all local symbols and
859      global symbols converted to locals are emitted into the symtab
860      section.  It allows the backend to emit special global symbols
861      not handled in the hash table.  */
862   bfd_boolean (*elf_backend_output_arch_syms)
863     (bfd *, struct bfd_link_info *, void *,
864      bfd_boolean (*) (void *, const char *, Elf_Internal_Sym *, asection *,
865                       struct elf_link_hash_entry *));
866
867   /* Copy any information related to dynamic linking from a pre-existing
868      symbol to a newly created symbol.  Also called to copy flags and
869      other back-end info to a weakdef, in which case the symbol is not
870      newly created and plt/got refcounts and dynamic indices should not
871      be copied.  */
872   void (*elf_backend_copy_indirect_symbol)
873     (struct bfd_link_info *, struct elf_link_hash_entry *,
874      struct elf_link_hash_entry *);
875
876   /* Modify any information related to dynamic linking such that the
877      symbol is not exported.  */
878   void (*elf_backend_hide_symbol)
879     (struct bfd_link_info *, struct elf_link_hash_entry *, bfd_boolean);
880
881   /* Merge the backend specific symbol attribute.  */
882   void (*elf_backend_merge_symbol_attribute)
883     (struct elf_link_hash_entry *, const Elf_Internal_Sym *, bfd_boolean,
884      bfd_boolean);
885
886   /* Decide whether an undefined symbol is special and can be ignored.
887      This is the case for OPTIONAL symbols on IRIX.  */
888   bfd_boolean (*elf_backend_ignore_undef_symbol)
889     (struct elf_link_hash_entry *);
890
891   /* Emit relocations.  Overrides default routine for emitting relocs,
892      except during a relocatable link, or if all relocs are being emitted.  */
893   bfd_boolean (*elf_backend_emit_relocs)
894     (bfd *, asection *, Elf_Internal_Shdr *, Elf_Internal_Rela *,
895      struct elf_link_hash_entry **);
896
897   /* Count relocations.  Not called for relocatable links
898      or if all relocs are being preserved in the output.  */
899   unsigned int (*elf_backend_count_relocs)
900     (asection *, Elf_Internal_Rela *);
901
902   /* This function, if defined, is called when an NT_PRSTATUS note is found
903      in a core file. */
904   bfd_boolean (*elf_backend_grok_prstatus)
905     (bfd *, Elf_Internal_Note *);
906
907   /* This function, if defined, is called when an NT_PSINFO or NT_PRPSINFO
908      note is found in a core file. */
909   bfd_boolean (*elf_backend_grok_psinfo)
910     (bfd *, Elf_Internal_Note *);
911
912   /* Functions to print VMAs.  Special code to handle 64 bit ELF files.  */
913   void (* elf_backend_sprintf_vma)
914     (bfd *, char *, bfd_vma);
915   void (* elf_backend_fprintf_vma)
916     (bfd *, void *, bfd_vma);
917
918   /* This function returns class of a reloc type.  */
919   enum elf_reloc_type_class (*elf_backend_reloc_type_class)
920     (const Elf_Internal_Rela *);
921
922   /* This function, if defined, removes information about discarded functions
923      from other sections which mention them.  */
924   bfd_boolean (*elf_backend_discard_info)
925     (bfd *, struct elf_reloc_cookie *, struct bfd_link_info *);
926
927   /* This function, if defined, signals that the function above has removed
928      the discarded relocations for this section.  */
929   bfd_boolean (*elf_backend_ignore_discarded_relocs)
930     (asection *);
931
932   /* What to do when ld finds relocations against symbols defined in
933      discarded sections.  */
934   unsigned int (*action_discarded)
935     (asection *);
936
937   /* This function returns the width of FDE pointers in bytes, or 0 if
938      that can't be determined for some reason.  The default definition
939      goes by the bfd's EI_CLASS.  */
940   unsigned int (*elf_backend_eh_frame_address_size)
941     (bfd *, asection *);
942
943   /* These functions tell elf-eh-frame whether to attempt to turn
944      absolute or lsda encodings into pc-relative ones.  The default
945      definition enables these transformations.  */
946   bfd_boolean (*elf_backend_can_make_relative_eh_frame)
947      (bfd *, struct bfd_link_info *, asection *);
948   bfd_boolean (*elf_backend_can_make_lsda_relative_eh_frame)
949      (bfd *, struct bfd_link_info *, asection *);
950
951   /* This function returns an encoding after computing the encoded
952      value (and storing it in ENCODED) for the given OFFSET into OSEC,
953      to be stored in at LOC_OFFSET into the LOC_SEC input section.
954      The default definition chooses a 32-bit PC-relative encoding.  */
955   bfd_byte (*elf_backend_encode_eh_address)
956      (bfd *abfd, struct bfd_link_info *info,
957       asection *osec, bfd_vma offset,
958       asection *loc_sec, bfd_vma loc_offset,
959       bfd_vma *encoded);
960
961   /* This function, if defined, may write out the given section.
962      Returns TRUE if it did so and FALSE if the caller should.  */
963   bfd_boolean (*elf_backend_write_section)
964     (bfd *, asection *, bfd_byte *);
965
966   /* The level of IRIX compatibility we're striving for.
967      MIPS ELF specific function.  */
968   irix_compat_t (*elf_backend_mips_irix_compat)
969     (bfd *);
970
971   reloc_howto_type *(*elf_backend_mips_rtype_to_howto)
972     (unsigned int, bfd_boolean);
973
974   /* The swapping table to use when dealing with ECOFF information.
975      Used for the MIPS ELF .mdebug section.  */
976   const struct ecoff_debug_swap *elf_backend_ecoff_debug_swap;
977
978   /* This function implements `bfd_elf_bfd_from_remote_memory';
979      see elf.c, elfcode.h.  */
980   bfd *(*elf_backend_bfd_from_remote_memory)
981      (bfd *templ, bfd_vma ehdr_vma, bfd_vma *loadbasep,
982       int (*target_read_memory) (bfd_vma vma, bfd_byte *myaddr, int len));
983
984   /* This function is used by `_bfd_elf_get_synthetic_symtab';
985      see elf.c.  */
986   bfd_vma (*plt_sym_val) (bfd_vma, const asection *, const arelent *);
987
988   /* Is symbol defined in common section?  */
989   bfd_boolean (*common_definition) (Elf_Internal_Sym *);
990
991   /* Return a common section index for section.  */
992   unsigned int (*common_section_index) (asection *);
993
994   /* Return a common section for section.  */
995   asection *(*common_section) (asection *);
996
997   /* Return TRUE if we can merge 2 definitions.  */
998   bfd_boolean (*merge_symbol) (struct bfd_link_info *,
999                                struct elf_link_hash_entry **,
1000                                struct elf_link_hash_entry *,
1001                                Elf_Internal_Sym *, asection **,
1002                                bfd_vma *, unsigned int *,
1003                                bfd_boolean *, bfd_boolean *,
1004                                bfd_boolean *, bfd_boolean *,
1005                                bfd_boolean *, bfd_boolean *,
1006                                bfd_boolean *, bfd_boolean *,
1007                                bfd *, asection **,
1008                                bfd_boolean *, bfd_boolean *,
1009                                bfd_boolean *, bfd_boolean *,
1010                                bfd *, asection **);
1011
1012   /* Used to handle bad SHF_LINK_ORDER input.  */
1013   bfd_error_handler_type link_order_error_handler;
1014
1015   /* Name of the PLT relocation section.  */
1016   const char *relplt_name;
1017
1018   /* Alternate EM_xxxx machine codes for this backend.  */
1019   int elf_machine_alt1;
1020   int elf_machine_alt2;
1021
1022   const struct elf_size_info *s;
1023
1024   /* An array of target specific special sections.  */
1025   const struct bfd_elf_special_section *special_sections;
1026
1027   /* The size in bytes of the header for the GOT.  This includes the
1028      so-called reserved entries on some systems.  */
1029   bfd_vma got_header_size;
1030
1031   /* This is TRUE if the linker should act like collect and gather
1032      global constructors and destructors by name.  This is TRUE for
1033      MIPS ELF because the Irix 5 tools can not handle the .init
1034      section.  */
1035   unsigned collect : 1;
1036
1037   /* This is TRUE if the linker should ignore changes to the type of a
1038      symbol.  This is TRUE for MIPS ELF because some Irix 5 objects
1039      record undefined functions as STT_OBJECT although the definitions
1040      are STT_FUNC.  */
1041   unsigned type_change_ok : 1;
1042
1043   /* Whether the backend may use REL relocations.  (Some backends use
1044      both REL and RELA relocations, and this flag is set for those
1045      backends.)  */
1046   unsigned may_use_rel_p : 1;
1047
1048   /* Whether the backend may use RELA relocations.  (Some backends use
1049      both REL and RELA relocations, and this flag is set for those
1050      backends.)  */
1051   unsigned may_use_rela_p : 1;
1052
1053   /* Whether the default relocation type is RELA.  If a backend with
1054      this flag set wants REL relocations for a particular section,
1055      it must note that explicitly.  Similarly, if this flag is clear,
1056      and the backend wants RELA relocations for a particular
1057      section.  */
1058   unsigned default_use_rela_p : 1;
1059
1060   /* Set if RELA relocations for a relocatable link can be handled by
1061      generic code.  Backends that set this flag need do nothing in the
1062      backend relocate_section routine for relocatable linking.  */
1063   unsigned rela_normal : 1;
1064
1065   /* TRUE if addresses "naturally" sign extend.  This is used when
1066      swapping in from Elf32 when BFD64.  */
1067   unsigned sign_extend_vma : 1;
1068
1069   unsigned want_got_plt : 1;
1070   unsigned plt_readonly : 1;
1071   unsigned want_plt_sym : 1;
1072   unsigned plt_not_loaded : 1;
1073   unsigned plt_alignment : 4;
1074   unsigned can_gc_sections : 1;
1075   unsigned can_refcount : 1;
1076   unsigned want_got_sym : 1;
1077   unsigned want_dynbss : 1;
1078     /* Targets which do not support physical addressing often require
1079        that the p_paddr field in the section header to be set to zero.
1080        This field indicates whether this behavior is required.  */
1081   unsigned want_p_paddr_set_to_zero : 1;
1082 };
1083
1084 /* Information stored for each BFD section in an ELF file.  This
1085    structure is allocated by elf_new_section_hook.  */
1086
1087 struct bfd_elf_section_data
1088 {
1089   /* The ELF header for this section.  */
1090   Elf_Internal_Shdr this_hdr;
1091
1092   /* The ELF header for the reloc section associated with this
1093      section, if any.  */
1094   Elf_Internal_Shdr rel_hdr;
1095
1096   /* If there is a second reloc section associated with this section,
1097      as can happen on Irix 6, this field points to the header.  */
1098   Elf_Internal_Shdr *rel_hdr2;
1099
1100   /* The number of relocations currently assigned to REL_HDR.  */
1101   unsigned int rel_count;
1102
1103   /* The number of relocations currently assigned to REL_HDR2.  */
1104   unsigned int rel_count2;
1105
1106   /* The ELF section number of this section.  */
1107   int this_idx;
1108
1109   /* The ELF section number of the reloc section indicated by
1110      REL_HDR if any.  Only used for an output file.  */
1111   int rel_idx;
1112
1113   /* The ELF section number of the reloc section indicated by
1114      REL_HDR2 if any.  Only used for an output file.  */
1115   int rel_idx2;
1116
1117   /* Used by the backend linker when generating a shared library to
1118      record the dynamic symbol index for a section symbol
1119      corresponding to this section.  A value of 0 means that there is
1120      no dynamic symbol for this section.  */
1121   int dynindx;
1122
1123   /* A pointer to the linked-to section for SHF_LINK_ORDER.  */
1124   asection *linked_to;
1125
1126   /* Used by the backend linker to store the symbol hash table entries
1127      associated with relocs against global symbols.  */
1128   struct elf_link_hash_entry **rel_hashes;
1129
1130   /* A pointer to the swapped relocs.  If the section uses REL relocs,
1131      rather than RELA, all the r_addend fields will be zero.  This
1132      pointer may be NULL.  It is used by the backend linker.  */
1133   Elf_Internal_Rela *relocs;
1134
1135   /* A pointer to a linked list tracking dynamic relocs copied for
1136      local symbols.  */
1137   void *local_dynrel;
1138
1139   /* A pointer to the bfd section used for dynamic relocs.  */
1140   asection *sreloc;
1141
1142   union {
1143     /* Group name, if this section is a member of a group.  */
1144     const char *name;
1145
1146     /* Group signature sym, if this is the SHT_GROUP section.  */
1147     struct bfd_symbol *id;
1148   } group;
1149
1150   /* Optional information about section group; NULL if it doesn't
1151      belongs to any section group. */
1152   asection *sec_group;
1153
1154   /* A linked list of sections in the group.  Circular when used by
1155      the linker.  */
1156   asection *next_in_group;
1157
1158   /* A pointer used for various section optimizations.  */
1159   void *sec_info;
1160 };
1161
1162 #define elf_section_data(sec)  ((struct bfd_elf_section_data*)(sec)->used_by_bfd)
1163 #define elf_linked_to_section(sec) (elf_section_data(sec)->linked_to)
1164 #define elf_section_type(sec)  (elf_section_data(sec)->this_hdr.sh_type)
1165 #define elf_section_flags(sec) (elf_section_data(sec)->this_hdr.sh_flags)
1166 #define elf_group_name(sec)    (elf_section_data(sec)->group.name)
1167 #define elf_group_id(sec)      (elf_section_data(sec)->group.id)
1168 #define elf_next_in_group(sec) (elf_section_data(sec)->next_in_group)
1169 #define elf_sec_group(sec)      (elf_section_data(sec)->sec_group)
1170
1171 /* Return TRUE if section has been discarded.  */
1172 #define elf_discarded_section(sec)                              \
1173   (!bfd_is_abs_section (sec)                                    \
1174    && bfd_is_abs_section ((sec)->output_section)                \
1175    && (sec)->sec_info_type != ELF_INFO_TYPE_MERGE               \
1176    && (sec)->sec_info_type != ELF_INFO_TYPE_JUST_SYMS)
1177
1178 #define get_elf_backend_data(abfd) \
1179   ((const struct elf_backend_data *) (abfd)->xvec->backend_data)
1180
1181 /* This struct is used to pass information to routines called via
1182    elf_link_hash_traverse which must return failure.  */
1183
1184 struct elf_info_failed
1185 {
1186   bfd_boolean failed;
1187   struct bfd_link_info *info;
1188   struct bfd_elf_version_tree *verdefs;
1189 };
1190
1191 /* This structure is used to pass information to
1192    _bfd_elf_link_assign_sym_version.  */
1193
1194 struct elf_assign_sym_version_info
1195 {
1196   /* Output BFD.  */
1197   bfd *output_bfd;
1198   /* General link information.  */
1199   struct bfd_link_info *info;
1200   /* Version tree.  */
1201   struct bfd_elf_version_tree *verdefs;
1202   /* Whether we had a failure.  */
1203   bfd_boolean failed;
1204 };
1205
1206 /* This structure is used to pass information to
1207    _bfd_elf_link_find_version_dependencies.  */
1208
1209 struct elf_find_verdep_info
1210 {
1211   /* Output BFD.  */
1212   bfd *output_bfd;
1213   /* General link information.  */
1214   struct bfd_link_info *info;
1215   /* The number of dependencies.  */
1216   unsigned int vers;
1217   /* Whether we had a failure.  */
1218   bfd_boolean failed;
1219 };
1220
1221 /* Some private data is stashed away for future use using the tdata pointer
1222    in the bfd structure.  */
1223
1224 struct elf_obj_tdata
1225 {
1226   Elf_Internal_Ehdr elf_header[1];      /* Actual data, but ref like ptr */
1227   Elf_Internal_Shdr **elf_sect_ptr;
1228   Elf_Internal_Phdr *phdr;
1229   struct elf_segment_map *segment_map;
1230   struct elf_strtab_hash *strtab_ptr;
1231   int num_locals;
1232   int num_globals;
1233   unsigned int num_elf_sections;        /* elf_sect_ptr size */
1234   int num_section_syms;
1235   asymbol **section_syms;               /* STT_SECTION symbols for each section */
1236   Elf_Internal_Shdr symtab_hdr;
1237   Elf_Internal_Shdr shstrtab_hdr;
1238   Elf_Internal_Shdr strtab_hdr;
1239   Elf_Internal_Shdr dynsymtab_hdr;
1240   Elf_Internal_Shdr dynstrtab_hdr;
1241   Elf_Internal_Shdr dynversym_hdr;
1242   Elf_Internal_Shdr dynverref_hdr;
1243   Elf_Internal_Shdr dynverdef_hdr;
1244   Elf_Internal_Shdr symtab_shndx_hdr;
1245   unsigned int symtab_section, shstrtab_section;
1246   unsigned int strtab_section, dynsymtab_section;
1247   unsigned int symtab_shndx_section;
1248   unsigned int dynversym_section, dynverdef_section, dynverref_section;
1249   file_ptr next_file_pos;
1250   bfd_vma gp;                           /* The gp value */
1251   unsigned int gp_size;                 /* The gp size */
1252
1253   /* Information grabbed from an elf core file.  */
1254   int core_signal;
1255   int core_pid;
1256   int core_lwpid;
1257   char* core_program;
1258   char* core_command;
1259
1260   /* A mapping from external symbols to entries in the linker hash
1261      table, used when linking.  This is indexed by the symbol index
1262      minus the sh_info field of the symbol table header.  */
1263   struct elf_link_hash_entry **sym_hashes;
1264
1265   /* Track usage and final offsets of GOT entries for local symbols.
1266      This array is indexed by symbol index.  Elements are used
1267      identically to "got" in struct elf_link_hash_entry.  */
1268   union
1269     {
1270       bfd_signed_vma *refcounts;
1271       bfd_vma *offsets;
1272       struct got_entry **ents;
1273     } local_got;
1274
1275   /* The linker ELF emulation code needs to let the backend ELF linker
1276      know what filename should be used for a dynamic object if the
1277      dynamic object is found using a search.  The emulation code then
1278      sometimes needs to know what name was actually used.  Until the
1279      file has been added to the linker symbol table, this field holds
1280      the name the linker wants.  After it has been added, it holds the
1281      name actually used, which will be the DT_SONAME entry if there is
1282      one.  */
1283   const char *dt_name;
1284
1285   /* Records the result of `get_program_header_size'.  */
1286   bfd_size_type program_header_size;
1287
1288   /* Used by find_nearest_line entry point.  */
1289   void *line_info;
1290
1291   /* Used by MIPS ELF find_nearest_line entry point.  The structure
1292      could be included directly in this one, but there's no point to
1293      wasting the memory just for the infrequently called
1294      find_nearest_line.  */
1295   struct mips_elf_find_line *find_line_info;
1296
1297   /* A place to stash dwarf1 info for this bfd.  */
1298   struct dwarf1_debug *dwarf1_find_line_info;
1299
1300   /* A place to stash dwarf2 info for this bfd.  */
1301   void *dwarf2_find_line_info;
1302
1303   /* An array of stub sections indexed by symbol number, used by the
1304      MIPS ELF linker.  FIXME: We should figure out some way to only
1305      include this field for a MIPS ELF target.  */
1306   asection **local_stubs;
1307
1308   /* Used to determine if PT_GNU_EH_FRAME segment header should be
1309      created.  */
1310   asection *eh_frame_hdr;
1311
1312   Elf_Internal_Shdr **group_sect_ptr;
1313   int num_group;
1314
1315   /* Number of symbol version definitions we are about to emit.  */
1316   unsigned int cverdefs;
1317
1318   /* Number of symbol version references we are about to emit.  */
1319   unsigned int cverrefs;
1320
1321   /* Segment flags for the PT_GNU_STACK segment.  */
1322   unsigned int stack_flags;
1323
1324   /* Should the PT_GNU_RELRO segment be emitted?  */
1325   bfd_boolean relro;
1326
1327   /* Symbol version definitions in external objects.  */
1328   Elf_Internal_Verdef *verdef;
1329
1330   /* Symbol version references to external objects.  */
1331   Elf_Internal_Verneed *verref;
1332
1333   /* The Irix 5 support uses two virtual sections, which represent
1334      text/data symbols defined in dynamic objects.  */
1335   asymbol *elf_data_symbol;
1336   asymbol *elf_text_symbol;
1337   asection *elf_data_section;
1338   asection *elf_text_section;
1339
1340   /* Whether a dyanmic object was specified normally on the linker
1341      command line, or was specified when --as-needed was in effect,
1342      or was found via a DT_NEEDED entry.  */
1343   enum dynamic_lib_link_class dyn_lib_class;
1344
1345   /* This is set to TRUE if the object was created by the backend
1346      linker.  */
1347   bfd_boolean linker;
1348
1349   /* Irix 5 often screws up the symbol table, sorting local symbols
1350      after global symbols.  This flag is set if the symbol table in
1351      this BFD appears to be screwed up.  If it is, we ignore the
1352      sh_info field in the symbol table header, and always read all the
1353      symbols.  */
1354   bfd_boolean bad_symtab;
1355
1356   /* Used to determine if the e_flags field has been initialized */
1357   bfd_boolean flags_init;
1358 };
1359
1360 #define elf_tdata(bfd)          ((bfd) -> tdata.elf_obj_data)
1361 #define elf_elfheader(bfd)      (elf_tdata(bfd) -> elf_header)
1362 #define elf_elfsections(bfd)    (elf_tdata(bfd) -> elf_sect_ptr)
1363 #define elf_numsections(bfd)    (elf_tdata(bfd) -> num_elf_sections)
1364 #define elf_shstrtab(bfd)       (elf_tdata(bfd) -> strtab_ptr)
1365 #define elf_onesymtab(bfd)      (elf_tdata(bfd) -> symtab_section)
1366 #define elf_symtab_shndx(bfd)   (elf_tdata(bfd) -> symtab_shndx_section)
1367 #define elf_dynsymtab(bfd)      (elf_tdata(bfd) -> dynsymtab_section)
1368 #define elf_dynversym(bfd)      (elf_tdata(bfd) -> dynversym_section)
1369 #define elf_dynverdef(bfd)      (elf_tdata(bfd) -> dynverdef_section)
1370 #define elf_dynverref(bfd)      (elf_tdata(bfd) -> dynverref_section)
1371 #define elf_num_locals(bfd)     (elf_tdata(bfd) -> num_locals)
1372 #define elf_num_globals(bfd)    (elf_tdata(bfd) -> num_globals)
1373 #define elf_section_syms(bfd)   (elf_tdata(bfd) -> section_syms)
1374 #define elf_num_section_syms(bfd) (elf_tdata(bfd) -> num_section_syms)
1375 #define core_prpsinfo(bfd)      (elf_tdata(bfd) -> prpsinfo)
1376 #define core_prstatus(bfd)      (elf_tdata(bfd) -> prstatus)
1377 #define elf_gp(bfd)             (elf_tdata(bfd) -> gp)
1378 #define elf_gp_size(bfd)        (elf_tdata(bfd) -> gp_size)
1379 #define elf_sym_hashes(bfd)     (elf_tdata(bfd) -> sym_hashes)
1380 #define elf_local_got_refcounts(bfd) (elf_tdata(bfd) -> local_got.refcounts)
1381 #define elf_local_got_offsets(bfd) (elf_tdata(bfd) -> local_got.offsets)
1382 #define elf_local_got_ents(bfd) (elf_tdata(bfd) -> local_got.ents)
1383 #define elf_dt_name(bfd)        (elf_tdata(bfd) -> dt_name)
1384 #define elf_dyn_lib_class(bfd)  (elf_tdata(bfd) -> dyn_lib_class)
1385 #define elf_bad_symtab(bfd)     (elf_tdata(bfd) -> bad_symtab)
1386 #define elf_flags_init(bfd)     (elf_tdata(bfd) -> flags_init)
1387 \f
1388 extern void _bfd_elf_swap_verdef_in
1389   (bfd *, const Elf_External_Verdef *, Elf_Internal_Verdef *);
1390 extern void _bfd_elf_swap_verdef_out
1391   (bfd *, const Elf_Internal_Verdef *, Elf_External_Verdef *);
1392 extern void _bfd_elf_swap_verdaux_in
1393   (bfd *, const Elf_External_Verdaux *, Elf_Internal_Verdaux *);
1394 extern void _bfd_elf_swap_verdaux_out
1395   (bfd *, const Elf_Internal_Verdaux *, Elf_External_Verdaux *);
1396 extern void _bfd_elf_swap_verneed_in
1397   (bfd *, const Elf_External_Verneed *, Elf_Internal_Verneed *);
1398 extern void _bfd_elf_swap_verneed_out
1399   (bfd *, const Elf_Internal_Verneed *, Elf_External_Verneed *);
1400 extern void _bfd_elf_swap_vernaux_in
1401   (bfd *, const Elf_External_Vernaux *, Elf_Internal_Vernaux *);
1402 extern void _bfd_elf_swap_vernaux_out
1403   (bfd *, const Elf_Internal_Vernaux *, Elf_External_Vernaux *);
1404 extern void _bfd_elf_swap_versym_in
1405   (bfd *, const Elf_External_Versym *, Elf_Internal_Versym *);
1406 extern void _bfd_elf_swap_versym_out
1407   (bfd *, const Elf_Internal_Versym *, Elf_External_Versym *);
1408
1409 extern int _bfd_elf_section_from_bfd_section
1410   (bfd *, asection *);
1411 extern char *bfd_elf_string_from_elf_section
1412   (bfd *, unsigned, unsigned);
1413 extern char *bfd_elf_get_str_section
1414   (bfd *, unsigned);
1415 extern Elf_Internal_Sym *bfd_elf_get_elf_syms
1416   (bfd *, Elf_Internal_Shdr *, size_t, size_t, Elf_Internal_Sym *, void *,
1417    Elf_External_Sym_Shndx *);
1418 extern const char *bfd_elf_sym_name
1419   (bfd *, Elf_Internal_Shdr *, Elf_Internal_Sym *, asection *);
1420
1421 extern bfd_boolean _bfd_elf_copy_private_bfd_data
1422   (bfd *, bfd *);
1423 extern bfd_boolean _bfd_elf_print_private_bfd_data
1424   (bfd *, void *);
1425 extern void bfd_elf_print_symbol
1426   (bfd *, void *, asymbol *, bfd_print_symbol_type);
1427
1428 extern void _bfd_elf_sprintf_vma
1429   (bfd *, char *, bfd_vma);
1430 extern void _bfd_elf_fprintf_vma
1431   (bfd *, void *, bfd_vma);
1432
1433 extern unsigned int _bfd_elf_eh_frame_address_size
1434   (bfd *, asection *);
1435 extern bfd_byte _bfd_elf_encode_eh_address
1436   (bfd *abfd, struct bfd_link_info *info, asection *osec, bfd_vma offset,
1437    asection *loc_sec, bfd_vma loc_offset, bfd_vma *encoded);
1438 extern bfd_boolean _bfd_elf_can_make_relative
1439   (bfd *input_bfd, struct bfd_link_info *info, asection *eh_frame_section);
1440
1441 extern enum elf_reloc_type_class _bfd_elf_reloc_type_class
1442   (const Elf_Internal_Rela *);
1443 extern bfd_vma _bfd_elf_rela_local_sym
1444   (bfd *, Elf_Internal_Sym *, asection **, Elf_Internal_Rela *);
1445 extern bfd_vma _bfd_elf_rel_local_sym
1446   (bfd *, Elf_Internal_Sym *, asection **, bfd_vma);
1447 extern bfd_vma _bfd_elf_section_offset
1448   (bfd *, struct bfd_link_info *, asection *, bfd_vma);
1449
1450 extern unsigned long bfd_elf_hash
1451   (const char *);
1452
1453 extern bfd_reloc_status_type bfd_elf_generic_reloc
1454   (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
1455 extern bfd_boolean bfd_elf_mkobject
1456   (bfd *);
1457 extern bfd_boolean bfd_elf_mkcorefile
1458   (bfd *);
1459 extern Elf_Internal_Shdr *bfd_elf_find_section
1460   (bfd *, char *);
1461 extern bfd_boolean _bfd_elf_make_section_from_shdr
1462   (bfd *, Elf_Internal_Shdr *, const char *, int);
1463 extern bfd_boolean _bfd_elf_make_section_from_phdr
1464   (bfd *, Elf_Internal_Phdr *, int, const char *);
1465 extern struct bfd_hash_entry *_bfd_elf_link_hash_newfunc
1466   (struct bfd_hash_entry *, struct bfd_hash_table *, const char *);
1467 extern struct bfd_link_hash_table *_bfd_elf_link_hash_table_create
1468   (bfd *);
1469 extern void _bfd_elf_link_hash_copy_indirect
1470   (struct bfd_link_info *, struct elf_link_hash_entry *,
1471    struct elf_link_hash_entry *);
1472 extern void _bfd_elf_link_hash_hide_symbol
1473   (struct bfd_link_info *, struct elf_link_hash_entry *, bfd_boolean);
1474 extern bfd_boolean _bfd_elf_link_hash_table_init
1475   (struct elf_link_hash_table *, bfd *,
1476    struct bfd_hash_entry *(*)
1477      (struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
1478 extern bfd_boolean _bfd_elf_slurp_version_tables
1479   (bfd *, bfd_boolean);
1480 extern bfd_boolean _bfd_elf_merge_sections
1481   (bfd *, struct bfd_link_info *);
1482 extern bfd_boolean _bfd_elf_match_sections_by_type
1483   (bfd *, const asection *, bfd *, const asection *);
1484 extern bfd_boolean bfd_elf_is_group_section
1485   (bfd *, const struct bfd_section *);
1486 extern void _bfd_elf_section_already_linked
1487   (bfd *, struct bfd_section *);
1488 extern void bfd_elf_set_group_contents
1489   (bfd *, asection *, void *);
1490 extern asection *_bfd_elf_check_kept_section
1491   (asection *);
1492 extern void _bfd_elf_link_just_syms
1493   (asection *, struct bfd_link_info *);
1494 extern bfd_boolean _bfd_elf_copy_private_header_data
1495   (bfd *, bfd *);
1496 extern bfd_boolean _bfd_elf_copy_private_symbol_data
1497   (bfd *, asymbol *, bfd *, asymbol *);
1498 #define _bfd_generic_init_private_section_data \
1499   _bfd_elf_init_private_section_data
1500 extern bfd_boolean _bfd_elf_init_private_section_data
1501   (bfd *, asection *, bfd *, asection *, struct bfd_link_info *);
1502 extern bfd_boolean _bfd_elf_copy_private_section_data
1503   (bfd *, asection *, bfd *, asection *);
1504 extern bfd_boolean _bfd_elf_write_object_contents
1505   (bfd *);
1506 extern bfd_boolean _bfd_elf_write_corefile_contents
1507   (bfd *);
1508 extern bfd_boolean _bfd_elf_set_section_contents
1509   (bfd *, sec_ptr, const void *, file_ptr, bfd_size_type);
1510 extern long _bfd_elf_get_symtab_upper_bound
1511   (bfd *);
1512 extern long _bfd_elf_canonicalize_symtab
1513   (bfd *, asymbol **);
1514 extern long _bfd_elf_get_dynamic_symtab_upper_bound
1515   (bfd *);
1516 extern long _bfd_elf_canonicalize_dynamic_symtab
1517   (bfd *, asymbol **);
1518 extern long _bfd_elf_get_synthetic_symtab
1519   (bfd *, long, asymbol **, long, asymbol **, asymbol **);
1520 extern long _bfd_elf_get_reloc_upper_bound
1521   (bfd *, sec_ptr);
1522 extern long _bfd_elf_canonicalize_reloc
1523   (bfd *, sec_ptr, arelent **, asymbol **);
1524 extern long _bfd_elf_get_dynamic_reloc_upper_bound
1525   (bfd *);
1526 extern long _bfd_elf_canonicalize_dynamic_reloc
1527   (bfd *, arelent **, asymbol **);
1528 extern asymbol *_bfd_elf_make_empty_symbol
1529   (bfd *);
1530 extern void _bfd_elf_get_symbol_info
1531   (bfd *, asymbol *, symbol_info *);
1532 extern bfd_boolean _bfd_elf_is_local_label_name
1533   (bfd *, const char *);
1534 extern alent *_bfd_elf_get_lineno
1535   (bfd *, asymbol *);
1536 extern bfd_boolean _bfd_elf_set_arch_mach
1537   (bfd *, enum bfd_architecture, unsigned long);
1538 extern bfd_boolean _bfd_elf_find_nearest_line
1539   (bfd *, asection *, asymbol **, bfd_vma, const char **, const char **,
1540    unsigned int *);
1541 extern bfd_boolean _bfd_elf_find_line
1542   (bfd *, asymbol **, asymbol *, const char **, unsigned int *);
1543 #define _bfd_generic_find_line _bfd_elf_find_line
1544 extern bfd_boolean _bfd_elf_find_inliner_info
1545   (bfd *, const char **, const char **, unsigned int *);
1546 #define _bfd_elf_read_minisymbols _bfd_generic_read_minisymbols
1547 #define _bfd_elf_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol
1548 extern int _bfd_elf_sizeof_headers
1549   (bfd *, bfd_boolean);
1550 extern bfd_boolean _bfd_elf_new_section_hook
1551   (bfd *, asection *);
1552 extern bfd_boolean _bfd_elf_init_reloc_shdr
1553   (bfd *, Elf_Internal_Shdr *, asection *, bfd_boolean);
1554 extern const struct bfd_elf_special_section *_bfd_elf_get_special_section
1555   (const char *, const struct bfd_elf_special_section *, unsigned int);
1556 extern const struct bfd_elf_special_section *_bfd_elf_get_sec_type_attr
1557   (bfd *, asection *);
1558
1559 /* If the target doesn't have reloc handling written yet:  */
1560 extern void _bfd_elf_no_info_to_howto
1561   (bfd *, arelent *, Elf_Internal_Rela *);
1562
1563 extern bfd_boolean bfd_section_from_shdr
1564   (bfd *, unsigned int shindex);
1565 extern bfd_boolean bfd_section_from_phdr
1566   (bfd *, Elf_Internal_Phdr *, int);
1567
1568 extern int _bfd_elf_symbol_from_bfd_symbol
1569   (bfd *, asymbol **);
1570
1571 extern asection *bfd_section_from_r_symndx
1572   (bfd *, struct sym_sec_cache *, asection *, unsigned long);
1573 extern asection *bfd_section_from_elf_index
1574   (bfd *, unsigned int);
1575 extern struct bfd_strtab_hash *_bfd_elf_stringtab_init
1576   (void);
1577
1578 extern struct elf_strtab_hash * _bfd_elf_strtab_init
1579   (void);
1580 extern void _bfd_elf_strtab_free
1581   (struct elf_strtab_hash *);
1582 extern bfd_size_type _bfd_elf_strtab_add
1583   (struct elf_strtab_hash *, const char *, bfd_boolean);
1584 extern void _bfd_elf_strtab_addref
1585   (struct elf_strtab_hash *, bfd_size_type);
1586 extern void _bfd_elf_strtab_delref
1587   (struct elf_strtab_hash *, bfd_size_type);
1588 extern void _bfd_elf_strtab_clear_all_refs
1589   (struct elf_strtab_hash *);
1590 extern bfd_size_type _bfd_elf_strtab_size
1591   (struct elf_strtab_hash *);
1592 extern bfd_size_type _bfd_elf_strtab_offset
1593   (struct elf_strtab_hash *, bfd_size_type);
1594 extern bfd_boolean _bfd_elf_strtab_emit
1595   (bfd *, struct elf_strtab_hash *);
1596 extern void _bfd_elf_strtab_finalize
1597   (struct elf_strtab_hash *);
1598
1599 extern bfd_boolean _bfd_elf_discard_section_eh_frame
1600   (bfd *, struct bfd_link_info *, asection *,
1601    bfd_boolean (*) (bfd_vma, void *), struct elf_reloc_cookie *);
1602 extern bfd_boolean _bfd_elf_discard_section_eh_frame_hdr
1603   (bfd *, struct bfd_link_info *);
1604 extern bfd_vma _bfd_elf_eh_frame_section_offset
1605   (bfd *, struct bfd_link_info *, asection *, bfd_vma);
1606 extern bfd_boolean _bfd_elf_write_section_eh_frame
1607   (bfd *, struct bfd_link_info *, asection *, bfd_byte *);
1608 extern bfd_boolean _bfd_elf_write_section_eh_frame_hdr
1609   (bfd *, struct bfd_link_info *);
1610 extern bfd_boolean _bfd_elf_maybe_strip_eh_frame_hdr
1611   (struct bfd_link_info *);
1612
1613 extern bfd_boolean _bfd_elf_merge_symbol
1614   (bfd *, struct bfd_link_info *, const char *, Elf_Internal_Sym *,
1615    asection **, bfd_vma *, unsigned int *,
1616    struct elf_link_hash_entry **, bfd_boolean *,
1617    bfd_boolean *, bfd_boolean *, bfd_boolean *);
1618
1619 extern bfd_boolean _bfd_elf_add_default_symbol
1620   (bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
1621    const char *, Elf_Internal_Sym *, asection **, bfd_vma *,
1622    bfd_boolean *, bfd_boolean);
1623
1624 extern bfd_boolean _bfd_elf_export_symbol
1625   (struct elf_link_hash_entry *, void *);
1626
1627 extern bfd_boolean _bfd_elf_link_find_version_dependencies
1628   (struct elf_link_hash_entry *, void *);
1629
1630 extern bfd_boolean _bfd_elf_link_assign_sym_version
1631   (struct elf_link_hash_entry *, void *);
1632
1633 extern long _bfd_elf_link_lookup_local_dynindx
1634   (struct bfd_link_info *, bfd *, long);
1635 extern bfd_boolean _bfd_elf_compute_section_file_positions
1636   (bfd *, struct bfd_link_info *);
1637 extern void _bfd_elf_assign_file_positions_for_relocs
1638   (bfd *);
1639 extern file_ptr _bfd_elf_assign_file_position_for_section
1640   (Elf_Internal_Shdr *, file_ptr, bfd_boolean);
1641
1642 extern bfd_boolean _bfd_elf_validate_reloc
1643   (bfd *, arelent *);
1644
1645 extern bfd_boolean _bfd_elf_link_create_dynamic_sections
1646   (bfd *, struct bfd_link_info *);
1647 extern bfd_boolean _bfd_elf_link_omit_section_dynsym
1648   (bfd *, struct bfd_link_info *, asection *);
1649 extern bfd_boolean _bfd_elf_create_dynamic_sections
1650   (bfd *, struct bfd_link_info *);
1651 extern bfd_boolean _bfd_elf_create_got_section
1652   (bfd *, struct bfd_link_info *);
1653 extern struct elf_link_hash_entry *_bfd_elf_define_linkage_sym
1654   (bfd *, struct bfd_link_info *, asection *, const char *);
1655
1656 extern bfd_boolean _bfd_elfcore_make_pseudosection
1657   (bfd *, char *, size_t, ufile_ptr);
1658 extern char *_bfd_elfcore_strndup
1659   (bfd *, char *, size_t);
1660
1661 extern Elf_Internal_Rela *_bfd_elf_link_read_relocs
1662   (bfd *, asection *, void *, Elf_Internal_Rela *, bfd_boolean);
1663
1664 extern bfd_boolean _bfd_elf_link_size_reloc_section
1665   (bfd *, Elf_Internal_Shdr *, asection *);
1666
1667 extern bfd_boolean _bfd_elf_link_output_relocs
1668   (bfd *, asection *, Elf_Internal_Shdr *, Elf_Internal_Rela *,
1669    struct elf_link_hash_entry **);
1670
1671 extern bfd_boolean _bfd_elf_fix_symbol_flags
1672   (struct elf_link_hash_entry *, struct elf_info_failed *);
1673
1674 extern bfd_boolean _bfd_elf_adjust_dynamic_symbol
1675   (struct elf_link_hash_entry *, void *);
1676
1677 extern bfd_boolean _bfd_elf_link_sec_merge_syms
1678   (struct elf_link_hash_entry *, void *);
1679
1680 extern bfd_boolean _bfd_elf_dynamic_symbol_p
1681   (struct elf_link_hash_entry *, struct bfd_link_info *, bfd_boolean);
1682
1683 extern bfd_boolean _bfd_elf_symbol_refs_local_p
1684   (struct elf_link_hash_entry *, struct bfd_link_info *, bfd_boolean);
1685
1686 extern bfd_boolean bfd_elf_match_symbols_in_sections
1687   (asection *sec1, asection *sec2);
1688
1689 extern bfd_boolean _bfd_elf_setup_sections
1690   (bfd *);
1691
1692 extern const bfd_target *bfd_elf32_object_p
1693   (bfd *);
1694 extern const bfd_target *bfd_elf32_core_file_p
1695   (bfd *);
1696 extern char *bfd_elf32_core_file_failing_command
1697   (bfd *);
1698 extern int bfd_elf32_core_file_failing_signal
1699   (bfd *);
1700 extern bfd_boolean bfd_elf32_core_file_matches_executable_p
1701   (bfd *, bfd *);
1702
1703 extern void bfd_elf32_swap_symbol_in
1704   (bfd *, const void *, const void *, Elf_Internal_Sym *);
1705 extern void bfd_elf32_swap_symbol_out
1706   (bfd *, const Elf_Internal_Sym *, void *, void *);
1707 extern void bfd_elf32_swap_reloc_in
1708   (bfd *, const bfd_byte *, Elf_Internal_Rela *);
1709 extern void bfd_elf32_swap_reloc_out
1710   (bfd *, const Elf_Internal_Rela *, bfd_byte *);
1711 extern void bfd_elf32_swap_reloca_in
1712   (bfd *, const bfd_byte *, Elf_Internal_Rela *);
1713 extern void bfd_elf32_swap_reloca_out
1714   (bfd *, const Elf_Internal_Rela *, bfd_byte *);
1715 extern void bfd_elf32_swap_phdr_in
1716   (bfd *, const Elf32_External_Phdr *, Elf_Internal_Phdr *);
1717 extern void bfd_elf32_swap_phdr_out
1718   (bfd *, const Elf_Internal_Phdr *, Elf32_External_Phdr *);
1719 extern void bfd_elf32_swap_dyn_in
1720   (bfd *, const void *, Elf_Internal_Dyn *);
1721 extern void bfd_elf32_swap_dyn_out
1722   (bfd *, const Elf_Internal_Dyn *, void *);
1723 extern long bfd_elf32_slurp_symbol_table
1724   (bfd *, asymbol **, bfd_boolean);
1725 extern bfd_boolean bfd_elf32_write_shdrs_and_ehdr
1726   (bfd *);
1727 extern int bfd_elf32_write_out_phdrs
1728   (bfd *, const Elf_Internal_Phdr *, unsigned int);
1729 extern void bfd_elf32_write_relocs
1730   (bfd *, asection *, void *);
1731 extern bfd_boolean bfd_elf32_slurp_reloc_table
1732   (bfd *, asection *, asymbol **, bfd_boolean);
1733
1734 extern const bfd_target *bfd_elf64_object_p
1735   (bfd *);
1736 extern const bfd_target *bfd_elf64_core_file_p
1737   (bfd *);
1738 extern char *bfd_elf64_core_file_failing_command
1739   (bfd *);
1740 extern int bfd_elf64_core_file_failing_signal
1741   (bfd *);
1742 extern bfd_boolean bfd_elf64_core_file_matches_executable_p
1743   (bfd *, bfd *);
1744
1745 extern void bfd_elf64_swap_symbol_in
1746   (bfd *, const void *, const void *, Elf_Internal_Sym *);
1747 extern void bfd_elf64_swap_symbol_out
1748   (bfd *, const Elf_Internal_Sym *, void *, void *);
1749 extern void bfd_elf64_swap_reloc_in
1750   (bfd *, const bfd_byte *, Elf_Internal_Rela *);
1751 extern void bfd_elf64_swap_reloc_out
1752   (bfd *, const Elf_Internal_Rela *, bfd_byte *);
1753 extern void bfd_elf64_swap_reloca_in
1754   (bfd *, const bfd_byte *, Elf_Internal_Rela *);
1755 extern void bfd_elf64_swap_reloca_out
1756   (bfd *, const Elf_Internal_Rela *, bfd_byte *);
1757 extern void bfd_elf64_swap_phdr_in
1758   (bfd *, const Elf64_External_Phdr *, Elf_Internal_Phdr *);
1759 extern void bfd_elf64_swap_phdr_out
1760   (bfd *, const Elf_Internal_Phdr *, Elf64_External_Phdr *);
1761 extern void bfd_elf64_swap_dyn_in
1762   (bfd *, const void *, Elf_Internal_Dyn *);
1763 extern void bfd_elf64_swap_dyn_out
1764   (bfd *, const Elf_Internal_Dyn *, void *);
1765 extern long bfd_elf64_slurp_symbol_table
1766   (bfd *, asymbol **, bfd_boolean);
1767 extern bfd_boolean bfd_elf64_write_shdrs_and_ehdr
1768   (bfd *);
1769 extern int bfd_elf64_write_out_phdrs
1770   (bfd *, const Elf_Internal_Phdr *, unsigned int);
1771 extern void bfd_elf64_write_relocs
1772   (bfd *, asection *, void *);
1773 extern bfd_boolean bfd_elf64_slurp_reloc_table
1774   (bfd *, asection *, asymbol **, bfd_boolean);
1775
1776 extern struct elf_link_hash_entry *_bfd_elf_archive_symbol_lookup
1777   (bfd *, struct bfd_link_info *, const char *);
1778 extern bfd_boolean bfd_elf_link_add_symbols
1779   (bfd *, struct bfd_link_info *);
1780 extern bfd_boolean _bfd_elf_add_dynamic_entry
1781   (struct bfd_link_info *, bfd_vma, bfd_vma);
1782
1783 extern bfd_boolean bfd_elf_link_record_dynamic_symbol
1784   (struct bfd_link_info *, struct elf_link_hash_entry *);
1785
1786 extern int bfd_elf_link_record_local_dynamic_symbol
1787   (struct bfd_link_info *, bfd *, long);
1788
1789 extern bfd_boolean _bfd_elf_close_and_cleanup
1790   (bfd *);
1791
1792 extern bfd_boolean _bfd_elf_common_definition
1793   (Elf_Internal_Sym *);
1794
1795 extern unsigned int _bfd_elf_common_section_index
1796   (asection *);
1797
1798 extern asection *_bfd_elf_common_section
1799   (asection *);
1800
1801 extern void _bfd_dwarf2_cleanup_debug_info
1802   (bfd *);
1803
1804 extern bfd_reloc_status_type _bfd_elf_rel_vtable_reloc_fn
1805   (bfd *, arelent *, struct bfd_symbol *, void *,
1806    asection *, bfd *, char **);
1807
1808 extern bfd_boolean bfd_elf_final_link
1809   (bfd *, struct bfd_link_info *);
1810
1811 extern bfd_boolean bfd_elf_gc_sections
1812   (bfd *, struct bfd_link_info *);
1813
1814 extern bfd_boolean bfd_elf_gc_record_vtinherit
1815   (bfd *, asection *, struct elf_link_hash_entry *, bfd_vma);
1816
1817 extern bfd_boolean bfd_elf_gc_record_vtentry
1818   (bfd *, asection *, struct elf_link_hash_entry *, bfd_vma);
1819
1820 extern bfd_boolean _bfd_elf_gc_mark
1821   (struct bfd_link_info *, asection *,
1822    asection * (*) (asection *, struct bfd_link_info *, Elf_Internal_Rela *,
1823                    struct elf_link_hash_entry *, Elf_Internal_Sym *));
1824
1825 extern bfd_boolean bfd_elf_gc_common_finalize_got_offsets
1826   (bfd *, struct bfd_link_info *);
1827
1828 extern bfd_boolean bfd_elf_gc_common_final_link
1829   (bfd *, struct bfd_link_info *);
1830
1831 extern bfd_boolean bfd_elf_reloc_symbol_deleted_p
1832   (bfd_vma, void *);
1833
1834 extern struct elf_segment_map *
1835 _bfd_elf_make_dynamic_segment
1836   (bfd *, asection *);
1837
1838 /* Exported interface for writing elf corefile notes. */
1839 extern char *elfcore_write_note
1840   (bfd *, char *, int *, const char *, int, const void *, int);
1841 extern char *elfcore_write_prpsinfo
1842   (bfd *, char *, int *, const char *, const char *);
1843 extern char *elfcore_write_prstatus
1844   (bfd *, char *, int *, long, int, const void *);
1845 extern char * elfcore_write_pstatus
1846   (bfd *, char *, int *, long, int, const void *);
1847 extern char *elfcore_write_prfpreg
1848   (bfd *, char *, int *, const void *, int);
1849 extern char *elfcore_write_prxfpreg
1850   (bfd *, char *, int *, const void *, int);
1851 extern char *elfcore_write_lwpstatus
1852   (bfd *, char *, int *, long, int, const void *);
1853
1854 extern bfd *_bfd_elf32_bfd_from_remote_memory
1855   (bfd *templ, bfd_vma ehdr_vma, bfd_vma *loadbasep,
1856    int (*target_read_memory) (bfd_vma, bfd_byte *, int));
1857 extern bfd *_bfd_elf64_bfd_from_remote_memory
1858   (bfd *templ, bfd_vma ehdr_vma, bfd_vma *loadbasep,
1859    int (*target_read_memory) (bfd_vma, bfd_byte *, int));
1860
1861 /* Large common section.  */
1862 extern asection _bfd_elf_large_com_section;
1863
1864 /* SH ELF specific routine.  */
1865
1866 extern bfd_boolean _sh_elf_set_mach_from_flags
1867   (bfd *);
1868
1869 /* This is the condition under which finish_dynamic_symbol will be called.
1870    If our finish_dynamic_symbol isn't called, we'll need to do something
1871    about initializing any .plt and .got entries in relocate_section.  */
1872 #define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, SHARED, H) \
1873   ((DYN)                                                                \
1874    && ((SHARED) || !(H)->forced_local)                                  \
1875    && ((H)->dynindx != -1 || (H)->forced_local))
1876
1877 /* This macro is to avoid lots of duplicated code in the body
1878    of xxx_relocate_section() in the various elfxx-xxxx.c files.  */
1879 #define RELOC_FOR_GLOBAL_SYMBOL(info, input_bfd, input_section, rel,    \
1880                                 r_symndx, symtab_hdr, sym_hashes,       \
1881                                 h, sec, relocation,                     \
1882                                 unresolved_reloc, warned)               \
1883   do                                                                    \
1884     {                                                                   \
1885       /* It seems this can happen with erroneous or unsupported         \
1886          input (mixing a.out and elf in an archive, for example.)  */   \
1887       if (sym_hashes == NULL)                                           \
1888         return FALSE;                                                   \
1889                                                                         \
1890       h = sym_hashes[r_symndx - symtab_hdr->sh_info];                   \
1891                                                                         \
1892       while (h->root.type == bfd_link_hash_indirect                     \
1893              || h->root.type == bfd_link_hash_warning)                  \
1894         h = (struct elf_link_hash_entry *) h->root.u.i.link;            \
1895                                                                         \
1896       warned = FALSE;                                                   \
1897       unresolved_reloc = FALSE;                                         \
1898       relocation = 0;                                                   \
1899       if (h->root.type == bfd_link_hash_defined                         \
1900           || h->root.type == bfd_link_hash_defweak)                     \
1901         {                                                               \
1902           sec = h->root.u.def.section;                                  \
1903           if (sec == NULL                                               \
1904               || sec->output_section == NULL)                           \
1905             /* Set a flag that will be cleared later if we find a       \
1906                relocation value for this symbol.  output_section        \
1907                is typically NULL for symbols satisfied by a shared      \
1908                library.  */                                             \
1909             unresolved_reloc = TRUE;                                    \
1910           else                                                          \
1911             relocation = (h->root.u.def.value                           \
1912                           + sec->output_section->vma                    \
1913                           + sec->output_offset);                        \
1914         }                                                               \
1915       else if (h->root.type == bfd_link_hash_undefweak)                 \
1916         ;                                                               \
1917       else if (info->unresolved_syms_in_objects == RM_IGNORE            \
1918                && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)          \
1919         ;                                                               \
1920       else                                                              \
1921         {                                                               \
1922           bfd_boolean err;                                              \
1923           err = (info->unresolved_syms_in_objects == RM_GENERATE_ERROR  \
1924                  || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT);       \
1925           if (!info->callbacks->undefined_symbol (info,                 \
1926                                                   h->root.root.string,  \
1927                                                   input_bfd,            \
1928                                                   input_section,        \
1929                                                   rel->r_offset, err))  \
1930             return FALSE;                                               \
1931           warned = TRUE;                                                \
1932         }                                                               \
1933     }                                                                   \
1934   while (0)
1935
1936 #endif /* _LIBELF_H_ */