* elf-bfd.h (struct elf_link_local_dynamic_entry): Add init_refcount.
[external/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    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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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) CAT4(x,64,_,y)
39 #endif
40 #if ARCH_SIZE==32
41 #define NAME(x,y) CAT4(x,32,_,y)
42 #endif
43 #endif
44
45 #ifndef NAME
46 #define NAME(x,y) CAT4(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       PTR mips_extr;
68       PTR 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 /* ELF linker hash table entries.  */
80
81 struct elf_link_hash_entry
82 {
83   struct bfd_link_hash_entry root;
84
85   /* Symbol index in output file.  This is initialized to -1.  It is
86      set to -2 if the symbol is used by a reloc.  */
87   long indx;
88
89   /* Symbol size.  */
90   bfd_size_type size;
91
92   /* Symbol index as a dynamic symbol.  Initialized to -1, and remains
93      -1 if this is not a dynamic symbol.  */
94   /* ??? Note that this is consistently used as a synonym for tests
95      against whether we can perform various simplifying transformations
96      to the code.  (E.g. changing a pc-relative jump to a PLT entry
97      into a pc-relative jump to the target function.)  That test, which
98      is often relatively complex, and someplaces wrong or incomplete,
99      should really be replaced by a predicate in elflink.c.
100
101      End result: this field -1 does not indicate that the symbol is
102      not in the dynamic symbol table, but rather that the symbol is
103      not visible outside this DSO.  */
104   long dynindx;
105
106   /* String table index in .dynstr if this is a dynamic symbol.  */
107   unsigned long dynstr_index;
108
109   /* If this is a weak defined symbol from a dynamic object, this
110      field points to a defined symbol with the same value, if there is
111      one.  Otherwise it is NULL.  */
112   struct elf_link_hash_entry *weakdef;
113
114   /* If this symbol requires an entry in the global offset table, the
115      processor specific backend uses this field to track usage and
116      final offset.  We use a union and two names primarily to document
117      the intent of any particular piece of code.  The field should be
118      used as a count until size_dynamic_sections, at which point the
119      contents of the .got is fixed.  Afterward, if this field is -1,
120      then the symbol does not require a global offset table entry.  */
121   union
122     {
123       bfd_signed_vma refcount;
124       bfd_vma offset;
125     } got;
126
127   /* Same, but tracks a procedure linkage table entry.  */
128   union
129     {
130       bfd_signed_vma refcount;
131       bfd_vma offset;
132     } plt;
133
134   /* If this symbol is used in the linker created sections, the processor
135      specific backend uses this field to map the field into the offset
136      from the beginning of the section.  */
137   struct elf_linker_section_pointers *linker_section_pointer;
138
139   /* Version information.  */
140   union
141   {
142     /* This field is used for a symbol which is not defined in a
143        regular object.  It points to the version information read in
144        from the dynamic object.  */
145     Elf_Internal_Verdef *verdef;
146     /* This field is used for a symbol which is defined in a regular
147        object.  It is set up in size_dynamic_sections.  It points to
148        the version information we should write out for this symbol.  */
149     struct bfd_elf_version_tree *vertree;
150   } verinfo;
151
152   /* Virtual table entry use information.  This array is nominally of size
153      size/sizeof(target_void_pointer), though we have to be able to assume
154      and track a size while the symbol is still undefined.  It is indexed
155      via offset/sizeof(target_void_pointer).  */
156   size_t vtable_entries_size;
157   boolean *vtable_entries_used;
158
159   /* Virtual table derivation info.  */
160   struct elf_link_hash_entry *vtable_parent;
161
162   /* Symbol type (STT_NOTYPE, STT_OBJECT, etc.).  */
163   char type;
164
165   /* Symbol st_other value, symbol visibility.  */
166   unsigned char other;
167
168   /* Hash value of the name computed using the ELF hash function.  */
169   unsigned long elf_hash_value;
170
171   /* Some flags; legal values follow.  */
172   unsigned short elf_link_hash_flags;
173   /* Symbol is referenced by a non-shared object.  */
174 #define ELF_LINK_HASH_REF_REGULAR 01
175   /* Symbol is defined by a non-shared object.  */
176 #define ELF_LINK_HASH_DEF_REGULAR 02
177   /* Symbol is referenced by a shared object.  */
178 #define ELF_LINK_HASH_REF_DYNAMIC 04
179   /* Symbol is defined by a shared object.  */
180 #define ELF_LINK_HASH_DEF_DYNAMIC 010
181   /* Symbol has a non-weak reference from a non-shared object.  */
182 #define ELF_LINK_HASH_REF_REGULAR_NONWEAK 020
183   /* Dynamic symbol has been adjustd.  */
184 #define ELF_LINK_HASH_DYNAMIC_ADJUSTED 040
185   /* Symbol needs a copy reloc.  */
186 #define ELF_LINK_HASH_NEEDS_COPY 0100
187   /* Symbol needs a procedure linkage table entry.  */
188 #define ELF_LINK_HASH_NEEDS_PLT 0200
189   /* Symbol appears in a non-ELF input file.  */
190 #define ELF_LINK_NON_ELF 0400
191   /* Symbol should be marked as hidden in the version information.  */
192 #define ELF_LINK_HIDDEN 01000
193   /* Symbol was forced to local scope due to a version script file.  */
194 #define ELF_LINK_FORCED_LOCAL 02000
195   /* Symbol was marked during garbage collection.  */
196 #define ELF_LINK_HASH_MARK 04000
197   /* Symbol is referenced by a non-GOT/non-PLT relocation.  This is
198      not currently set by all the backends.  */
199 #define ELF_LINK_NON_GOT_REF 010000
200 };
201
202 /* Records local symbols to be emitted in the dynamic symbol table.  */
203
204 struct elf_link_local_dynamic_entry
205 {
206   struct elf_link_local_dynamic_entry *next;
207
208   /* The input bfd this symbol came from.  */
209   bfd *input_bfd;
210
211   /* The index of the local symbol being copied.  */
212   long input_indx;
213
214   /* The index in the outgoing dynamic symbol table.  */
215   long dynindx;
216
217   /* A copy of the input symbol.  */
218   Elf_Internal_Sym isym;
219 };
220
221 /* ELF linker hash table.  */
222
223 struct elf_link_hash_table
224 {
225   struct bfd_link_hash_table root;
226
227   /* Whether we have created the special dynamic sections required
228      when linking against or generating a shared object.  */
229   boolean dynamic_sections_created;
230
231   /* The BFD used to hold special sections created by the linker.
232      This will be the first BFD found which requires these sections to
233      be created.  */
234   bfd *dynobj;
235
236   /* The value to use when initialising got.refcount/offset and
237      plt.refcount/offset in an elf_link_hash_entry.  Set to zero when
238      the values are refcounts.  Set to -1 in size_dynamic_sections
239      when the values may be offsets.  */
240   bfd_signed_vma init_refcount;
241
242   /* The number of symbols found in the link which must be put into
243      the .dynsym section.  */
244   bfd_size_type dynsymcount;
245
246   /* The string table of dynamic symbols, which becomes the .dynstr
247      section.  */
248   struct bfd_strtab_hash *dynstr;
249
250   /* The number of buckets in the hash table in the .hash section.
251      This is based on the number of dynamic symbols.  */
252   bfd_size_type bucketcount;
253
254   /* A linked list of DT_NEEDED names found in dynamic objects
255      included in the link.  */
256   struct bfd_link_needed_list *needed;
257
258   /* The _GLOBAL_OFFSET_TABLE_ symbol.  */
259   struct elf_link_hash_entry *hgot;
260
261   /* A pointer to information used to link stabs in sections.  */
262   PTR stab_info;
263
264   /* A pointer to information used to merge SEC_MERGE sections.  */
265   PTR merge_info;
266
267   /* A linked list of local symbols to be added to .dynsym.  */
268   struct elf_link_local_dynamic_entry *dynlocal;
269
270   /* A linked list of DT_RPATH/DT_RUNPATH names found in dynamic
271      objects included in the link.  */
272   struct bfd_link_needed_list *runpath;
273 };
274
275 /* Look up an entry in an ELF linker hash table.  */
276
277 #define elf_link_hash_lookup(table, string, create, copy, follow)       \
278   ((struct elf_link_hash_entry *)                                       \
279    bfd_link_hash_lookup (&(table)->root, (string), (create),            \
280                          (copy), (follow)))
281
282 /* Traverse an ELF linker hash table.  */
283
284 #define elf_link_hash_traverse(table, func, info)                       \
285   (bfd_link_hash_traverse                                               \
286    (&(table)->root,                                                     \
287     (boolean (*) PARAMS ((struct bfd_link_hash_entry *, PTR))) (func),  \
288     (info)))
289
290 /* Get the ELF linker hash table from a link_info structure.  */
291
292 #define elf_hash_table(p) ((struct elf_link_hash_table *) ((p)->hash))
293
294 /* Returns true if the hash table is a struct elf_link_hash_table.  */
295 #define is_elf_hash_table(p)                                            \
296   ((p)->hash->type == bfd_link_elf_hash_table)
297 \f
298 /* Constant information held for an ELF backend.  */
299
300 struct elf_size_info {
301   unsigned char sizeof_ehdr, sizeof_phdr, sizeof_shdr;
302   unsigned char sizeof_rel, sizeof_rela, sizeof_sym, sizeof_dyn, sizeof_note;
303
304   /* The size of entries in the .hash section.  */
305   unsigned char sizeof_hash_entry;
306
307   /* The number of internal relocations to allocate per external
308      relocation entry.  */
309   unsigned char int_rels_per_ext_rel;
310
311   unsigned char arch_size, file_align;
312   unsigned char elfclass, ev_current;
313   int (*write_out_phdrs)
314     PARAMS ((bfd *, const Elf_Internal_Phdr *, unsigned int));
315   boolean (*write_shdrs_and_ehdr)
316     PARAMS ((bfd *));
317   void (*write_relocs)
318     PARAMS ((bfd *, asection *, PTR));
319   void (*swap_symbol_out)
320     PARAMS ((bfd *, const Elf_Internal_Sym *, PTR));
321   boolean (*slurp_reloc_table)
322     PARAMS ((bfd *, asection *, asymbol **, boolean));
323   long (*slurp_symbol_table)
324     PARAMS ((bfd *, asymbol **, boolean));
325   void (*swap_dyn_in)
326     PARAMS ((bfd *, const PTR, Elf_Internal_Dyn *));
327   void (*swap_dyn_out)
328     PARAMS ((bfd *, const Elf_Internal_Dyn *, PTR));
329
330   /* This function, if defined, is called to swap in a REL
331      relocation.  If an external relocation corresponds to more than
332      one internal relocation, then all relocations are swapped in at
333      once.  */
334   void (*swap_reloc_in)
335     PARAMS ((bfd *, const bfd_byte *, Elf_Internal_Rel *));
336
337   /* This function, if defined, is called to swap out a REL
338      relocation.  */
339   void (*swap_reloc_out)
340     PARAMS ((bfd *, const Elf_Internal_Rel *, bfd_byte *));
341
342   /* This function, if defined, is called to swap in a RELA
343      relocation.  If an external relocation corresponds to more than
344      one internal relocation, then all relocations are swapped in at
345      once.  */
346   void (*swap_reloca_in)
347     PARAMS ((bfd *, const bfd_byte *, Elf_Internal_Rela *));
348
349   /* This function, if defined, is called to swap out a RELA
350      relocation.  */
351   void (*swap_reloca_out)
352     PARAMS ((bfd *, const Elf_Internal_Rela *, bfd_byte *));
353
354 };
355
356 #define elf_symbol_from(ABFD,S) \
357         (((S)->the_bfd->xvec->flavour == bfd_target_elf_flavour \
358           && (S)->the_bfd->tdata.elf_obj_data != 0) \
359          ? (elf_symbol_type *) (S) \
360          : 0)
361
362 enum elf_reloc_type_class {
363   reloc_class_normal,
364   reloc_class_relative,
365   reloc_class_plt,
366   reloc_class_copy
367 };
368
369 struct elf_backend_data
370 {
371   /* The architecture for this backend.  */
372   enum bfd_architecture arch;
373
374   /* The ELF machine code (EM_xxxx) for this backend.  */
375   int elf_machine_code;
376
377   /* The maximum page size for this backend.  */
378   bfd_vma maxpagesize;
379
380   /* A function to translate an ELF RELA relocation to a BFD arelent
381      structure.  */
382   void (*elf_info_to_howto)
383     PARAMS ((bfd *, arelent *, Elf_Internal_Rela *));
384
385   /* A function to translate an ELF REL relocation to a BFD arelent
386      structure.  */
387   void (*elf_info_to_howto_rel)
388     PARAMS ((bfd *, arelent *, Elf_Internal_Rel *));
389
390   /* A function to determine whether a symbol is global when
391      partitioning the symbol table into local and global symbols.
392      This should be NULL for most targets, in which case the correct
393      thing will be done.  MIPS ELF, at least on the Irix 5, has
394      special requirements.  */
395   boolean (*elf_backend_sym_is_global)
396     PARAMS ((bfd *, asymbol *));
397
398   /* The remaining functions are hooks which are called only if they
399      are not NULL.  */
400
401   /* A function to permit a backend specific check on whether a
402      particular BFD format is relevant for an object file, and to
403      permit the backend to set any global information it wishes.  When
404      this is called elf_elfheader is set, but anything else should be
405      used with caution.  If this returns false, the check_format
406      routine will return a bfd_error_wrong_format error.  */
407   boolean (*elf_backend_object_p)
408     PARAMS ((bfd *));
409
410   /* A function to do additional symbol processing when reading the
411      ELF symbol table.  This is where any processor-specific special
412      section indices are handled.  */
413   void (*elf_backend_symbol_processing)
414     PARAMS ((bfd *, asymbol *));
415
416   /* A function to do additional symbol processing after reading the
417      entire ELF symbol table.  */
418   boolean (*elf_backend_symbol_table_processing)
419     PARAMS ((bfd *, elf_symbol_type *, unsigned int));
420
421    /* A function to set the type of the info field.  Processor-specific
422      types should be handled here.  */
423   int (*elf_backend_get_symbol_type)
424     PARAMS (( Elf_Internal_Sym *, int));
425
426   /* A function to do additional processing on the ELF section header
427      just before writing it out.  This is used to set the flags and
428      type fields for some sections, or to actually write out data for
429      unusual sections.  */
430   boolean (*elf_backend_section_processing)
431     PARAMS ((bfd *, Elf32_Internal_Shdr *));
432
433   /* A function to handle unusual section types when creating BFD
434      sections from ELF sections.  */
435   boolean (*elf_backend_section_from_shdr)
436     PARAMS ((bfd *, Elf32_Internal_Shdr *, char *));
437
438   /* A function to convert machine dependent section header flags to
439      BFD internal section header flags.  */
440   boolean (*elf_backend_section_flags)
441     PARAMS ((flagword *, Elf32_Internal_Shdr *));
442
443   /* A function to handle unusual program segment types when creating BFD
444      sections from ELF program segments.  */
445   boolean (*elf_backend_section_from_phdr)
446     PARAMS ((bfd *, Elf32_Internal_Phdr *, int));
447
448   /* A function to set up the ELF section header for a BFD section in
449      preparation for writing it out.  This is where the flags and type
450      fields are set for unusual sections.  */
451   boolean (*elf_backend_fake_sections)
452     PARAMS ((bfd *, Elf32_Internal_Shdr *, asection *));
453
454   /* A function to get the ELF section index for a BFD section.  If
455      this returns true, the section was found.  If it is a normal ELF
456      section, *RETVAL should be left unchanged.  If it is not a normal
457      ELF section *RETVAL should be set to the SHN_xxxx index.  */
458   boolean (*elf_backend_section_from_bfd_section)
459     PARAMS ((bfd *, Elf32_Internal_Shdr *, asection *, int *retval));
460
461   /* If this field is not NULL, it is called by the add_symbols phase
462      of a link just before adding a symbol to the global linker hash
463      table.  It may modify any of the fields as it wishes.  If *NAME
464      is set to NULL, the symbol will be skipped rather than being
465      added to the hash table.  This function is responsible for
466      handling all processor dependent symbol bindings and section
467      indices, and must set at least *FLAGS and *SEC for each processor
468      dependent case; failure to do so will cause a link error.  */
469   boolean (*elf_add_symbol_hook)
470     PARAMS ((bfd *abfd, struct bfd_link_info *info,
471              const Elf_Internal_Sym *, const char **name,
472              flagword *flags, asection **sec, bfd_vma *value));
473
474   /* If this field is not NULL, it is called by the elf_link_output_sym
475      phase of a link for each symbol which will appear in the object file.  */
476   boolean (*elf_backend_link_output_symbol_hook)
477     PARAMS ((bfd *, struct bfd_link_info *info, const char *,
478              Elf_Internal_Sym *, asection *));
479
480   /* The CREATE_DYNAMIC_SECTIONS function is called by the ELF backend
481      linker the first time it encounters a dynamic object in the link.
482      This function must create any sections required for dynamic
483      linking.  The ABFD argument is a dynamic object.  The .interp,
484      .dynamic, .dynsym, .dynstr, and .hash functions have already been
485      created, and this function may modify the section flags if
486      desired.  This function will normally create the .got and .plt
487      sections, but different backends have different requirements.  */
488   boolean (*elf_backend_create_dynamic_sections)
489     PARAMS ((bfd *abfd, struct bfd_link_info *info));
490
491   /* The CHECK_RELOCS function is called by the add_symbols phase of
492      the ELF backend linker.  It is called once for each section with
493      relocs of an object file, just after the symbols for the object
494      file have been added to the global linker hash table.  The
495      function must look through the relocs and do any special handling
496      required.  This generally means allocating space in the global
497      offset table, and perhaps allocating space for a reloc.  The
498      relocs are always passed as Rela structures; if the section
499      actually uses Rel structures, the r_addend field will always be
500      zero.  */
501   boolean (*check_relocs)
502     PARAMS ((bfd *abfd, struct bfd_link_info *info, asection *o,
503              const Elf_Internal_Rela *relocs));
504
505   /* The ADJUST_DYNAMIC_SYMBOL function is called by the ELF backend
506      linker for every symbol which is defined by a dynamic object and
507      referenced by a regular object.  This is called after all the
508      input files have been seen, but before the SIZE_DYNAMIC_SECTIONS
509      function has been called.  The hash table entry should be
510      bfd_link_hash_defined ore bfd_link_hash_defweak, and it should be
511      defined in a section from a dynamic object.  Dynamic object
512      sections are not included in the final link, and this function is
513      responsible for changing the value to something which the rest of
514      the link can deal with.  This will normally involve adding an
515      entry to the .plt or .got or some such section, and setting the
516      symbol to point to that.  */
517   boolean (*elf_backend_adjust_dynamic_symbol)
518     PARAMS ((struct bfd_link_info *info, struct elf_link_hash_entry *h));
519
520   /* The ALWAYS_SIZE_SECTIONS function is called by the backend linker
521      after all the linker input files have been seen but before the
522      section sizes have been set.  This is called after
523      ADJUST_DYNAMIC_SYMBOL, but before SIZE_DYNAMIC_SECTIONS.  */
524   boolean (*elf_backend_always_size_sections)
525     PARAMS ((bfd *output_bfd, struct bfd_link_info *info));
526
527   /* The SIZE_DYNAMIC_SECTIONS function is called by the ELF backend
528      linker after all the linker input files have been seen but before
529      the sections sizes have been set.  This is called after
530      ADJUST_DYNAMIC_SYMBOL has been called on all appropriate symbols.
531      It is only called when linking against a dynamic object.  It must
532      set the sizes of the dynamic sections, and may fill in their
533      contents as well.  The generic ELF linker can handle the .dynsym,
534      .dynstr and .hash sections.  This function must handle the
535      .interp section and any sections created by the
536      CREATE_DYNAMIC_SECTIONS entry point.  */
537   boolean (*elf_backend_size_dynamic_sections)
538     PARAMS ((bfd *output_bfd, struct bfd_link_info *info));
539
540   /* The RELOCATE_SECTION function is called by the ELF backend linker
541      to handle the relocations for a section.
542
543      The relocs are always passed as Rela structures; if the section
544      actually uses Rel structures, the r_addend field will always be
545      zero.
546
547      This function is responsible for adjust the section contents as
548      necessary, and (if using Rela relocs and generating a
549      relocateable output file) adjusting the reloc addend as
550      necessary.
551
552      This function does not have to worry about setting the reloc
553      address or the reloc symbol index.
554
555      LOCAL_SYMS is a pointer to the swapped in local symbols.
556
557      LOCAL_SECTIONS is an array giving the section in the input file
558      corresponding to the st_shndx field of each local symbol.
559
560      The global hash table entry for the global symbols can be found
561      via elf_sym_hashes (input_bfd).
562
563      When generating relocateable output, this function must handle
564      STB_LOCAL/STT_SECTION symbols specially.  The output symbol is
565      going to be the section symbol corresponding to the output
566      section, which means that the addend must be adjusted
567      accordingly.  */
568   boolean (*elf_backend_relocate_section)
569     PARAMS ((bfd *output_bfd, struct bfd_link_info *info,
570              bfd *input_bfd, asection *input_section, bfd_byte *contents,
571              Elf_Internal_Rela *relocs, Elf_Internal_Sym *local_syms,
572              asection **local_sections));
573
574   /* The FINISH_DYNAMIC_SYMBOL function is called by the ELF backend
575      linker just before it writes a symbol out to the .dynsym section.
576      The processor backend may make any required adjustment to the
577      symbol.  It may also take the opportunity to set contents of the
578      dynamic sections.  Note that FINISH_DYNAMIC_SYMBOL is called on
579      all .dynsym symbols, while ADJUST_DYNAMIC_SYMBOL is only called
580      on those symbols which are defined by a dynamic object.  */
581   boolean (*elf_backend_finish_dynamic_symbol)
582     PARAMS ((bfd *output_bfd, struct bfd_link_info *info,
583              struct elf_link_hash_entry *h, Elf_Internal_Sym *sym));
584
585   /* The FINISH_DYNAMIC_SECTIONS function is called by the ELF backend
586      linker just before it writes all the dynamic sections out to the
587      output file.  The FINISH_DYNAMIC_SYMBOL will have been called on
588      all dynamic symbols.  */
589   boolean (*elf_backend_finish_dynamic_sections)
590     PARAMS ((bfd *output_bfd, struct bfd_link_info *info));
591
592   /* A function to do any beginning processing needed for the ELF file
593      before building the ELF headers and computing file positions.  */
594   void (*elf_backend_begin_write_processing)
595     PARAMS ((bfd *, struct bfd_link_info *));
596
597   /* A function to do any final processing needed for the ELF file
598      before writing it out.  The LINKER argument is true if this BFD
599      was created by the ELF backend linker.  */
600   void (*elf_backend_final_write_processing)
601     PARAMS ((bfd *, boolean linker));
602
603   /* This function is called by get_program_header_size.  It should
604      return the number of additional program segments which this BFD
605      will need.  It should return -1 on error.  */
606   int (*elf_backend_additional_program_headers)
607     PARAMS ((bfd *));
608
609   /* This function is called to modify an existing segment map in a
610      backend specific fashion.  */
611   boolean (*elf_backend_modify_segment_map)
612     PARAMS ((bfd *));
613
614   /* This function is called during section gc to discover the section a
615      particular relocation refers to.  It need not be defined for hosts
616      that have no queer relocation types.  */
617   asection * (*gc_mark_hook)
618     PARAMS ((bfd *abfd, struct bfd_link_info *, Elf_Internal_Rela *,
619              struct elf_link_hash_entry *h, Elf_Internal_Sym *));
620
621   /* This function, if defined, is called during the sweep phase of gc
622      in order that a backend might update any data structures it might
623      be maintaining.  */
624   boolean (*gc_sweep_hook)
625     PARAMS ((bfd *abfd, struct bfd_link_info *info, asection *o,
626              const Elf_Internal_Rela *relocs));
627
628   /* This function, if defined, is called after the ELF headers have
629      been created.  This allows for things like the OS and ABI versions
630      to be changed.  */
631   void (*elf_backend_post_process_headers)
632     PARAMS ((bfd *, struct bfd_link_info *));
633
634   /* This function, if defined, prints a symbol to file and returns the
635      name of the symbol to be printed.  It should return NULL to fall
636      back to default symbol printing.  */
637   const char *(*elf_backend_print_symbol_all)
638     PARAMS ((bfd *, PTR, asymbol *));
639
640   /* This function, if defined, is called after all local symbols and
641      global symbols converted to locals are emited into the symtab
642      section.  It allows the backend to emit special global symbols
643      not handled in the hash table.  */
644   boolean (*elf_backend_output_arch_syms)
645     PARAMS ((bfd *, struct bfd_link_info *, PTR,
646             boolean (*) (PTR, const char *, Elf_Internal_Sym *, asection *)));
647
648   /* Copy any information related to dynamic linking from a pre-existing
649      symbol IND to a newly created symbol DIR.  */
650   void (*elf_backend_copy_indirect_symbol)
651     PARAMS ((struct elf_link_hash_entry *, struct elf_link_hash_entry *));
652
653   /* Modify any information related to dynamic linking such that the
654      symbol is not exported.  */
655   void (*elf_backend_hide_symbol)
656     PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
657
658   /* Emit relocations.  Overrides default routine for emitting relocs,
659      except during a relocatable link, or if all relocs are being emitted.  */
660   void (*elf_backend_emit_relocs)
661     PARAMS ((bfd *, asection *, Elf_Internal_Shdr *, Elf_Internal_Rela *));
662
663   /* Count relocations.  Not called for relocatable links
664      or if all relocs are being preserved in the output.  */
665   unsigned int (*elf_backend_count_relocs)
666     PARAMS ((asection *, Elf_Internal_Rela *));
667
668   /* This function, if defined, is called when an NT_PRSTATUS note is found
669      in a core file. */
670   boolean (*elf_backend_grok_prstatus)
671     PARAMS ((bfd *, Elf_Internal_Note *));
672
673   /* This function, if defined, is called when an NT_PSINFO or NT_PRPSINFO
674      note is found in a core file. */
675   boolean (*elf_backend_grok_psinfo)
676     PARAMS ((bfd *, Elf_Internal_Note *));
677
678   /* Functions to print VMAs.  Special code to handle 64 bit ELF files.  */
679   void (* elf_backend_sprintf_vma)
680     PARAMS ((bfd *, char *, bfd_vma));
681   void (* elf_backend_fprintf_vma)
682     PARAMS ((bfd *, PTR, bfd_vma));
683
684   /* This function returns class of a reloc type.  */
685   enum elf_reloc_type_class (*elf_backend_reloc_type_class)
686     PARAMS ((const Elf_Internal_Rela *));
687
688   /* The swapping table to use when dealing with ECOFF information.
689      Used for the MIPS ELF .mdebug section.  */
690   const struct ecoff_debug_swap *elf_backend_ecoff_debug_swap;
691
692   /* Alternate EM_xxxx machine codes for this backend.  */
693   int elf_machine_alt1;
694   int elf_machine_alt2;
695
696   const struct elf_size_info *s;
697
698   /* offset of the _GLOBAL_OFFSET_TABLE_ symbol from the start of the
699      .got section */
700   bfd_vma got_symbol_offset;
701
702   /* The size in bytes of the headers for the GOT and PLT.  This includes
703      the so-called reserved entries on some systems.  */
704   bfd_vma got_header_size;
705   bfd_vma plt_header_size;
706
707   /* This is true if the linker should act like collect and gather
708      global constructors and destructors by name.  This is true for
709      MIPS ELF because the Irix 5 tools can not handle the .init
710      section.  */
711   unsigned collect : 1;
712
713   /* This is true if the linker should ignore changes to the type of a
714      symbol.  This is true for MIPS ELF because some Irix 5 objects
715      record undefined functions as STT_OBJECT although the definitions
716      are STT_FUNC.  */
717   unsigned type_change_ok : 1;
718
719   /* Whether the backend may use REL relocations.  (Some backends use
720      both REL and RELA relocations, and this flag is set for those
721      backends.)  */
722   unsigned may_use_rel_p : 1;
723
724   /* Whether the backend may use RELA relocations.  (Some backends use
725      both REL and RELA relocations, and this flag is set for those
726      backends.)  */
727   unsigned may_use_rela_p : 1;
728
729   /* Whether the default relocation type is RELA.  If a backend with
730      this flag set wants REL relocations for a particular section,
731      it must note that explicitly.  Similarly, if this flag is clear,
732      and the backend wants RELA relocations for a particular
733      section.  */
734   unsigned default_use_rela_p : 1;
735
736   /* True if addresses "naturally" sign extend.  This is used when
737      swapping in from Elf32 when BFD64.  */
738   unsigned sign_extend_vma : 1;
739
740   unsigned want_got_plt : 1;
741   unsigned plt_readonly : 1;
742   unsigned want_plt_sym : 1;
743   unsigned plt_not_loaded : 1;
744   unsigned plt_alignment : 4;
745   unsigned can_gc_sections : 1;
746   unsigned can_refcount : 1;
747   unsigned want_got_sym : 1;
748   unsigned want_dynbss : 1;
749 };
750
751 /* Information stored for each BFD section in an ELF file.  This
752    structure is allocated by elf_new_section_hook.  */
753
754 struct bfd_elf_section_data
755 {
756   /* The ELF header for this section.  */
757   Elf_Internal_Shdr this_hdr;
758
759   /* The ELF header for the reloc section associated with this
760      section, if any.  */
761   Elf_Internal_Shdr rel_hdr;
762
763   /* If there is a second reloc section associated with this section,
764      as can happen on Irix 6, this field points to the header.  */
765   Elf_Internal_Shdr *rel_hdr2;
766
767   /* The number of relocations currently assigned to REL_HDR.  */
768   unsigned int rel_count;
769
770   /* The number of relocations currently assigned to REL_HDR2.  */
771   unsigned int rel_count2;
772
773   /* The number of dynamic relocs copied for local symbols.  */
774   unsigned int local_dynrel;
775
776   /* A pointer to the bfd section used for dynamic relocs.  */
777   asection *sreloc;
778
779   /* The ELF section number of this section.  Only used for an output
780      file.  */
781   int this_idx;
782
783   /* The ELF section number of the reloc section indicated by
784      REL_HDR if any.  Only used for an output file.  */
785   int rel_idx;
786
787   /* The ELF section number of the reloc section indicated by
788      REL_HDR2 if any.  Only used for an output file.  */
789   int rel_idx2;
790
791   /* Used by the backend linker to store the symbol hash table entries
792      associated with relocs against global symbols.  */
793   struct elf_link_hash_entry **rel_hashes;
794
795   /* A pointer to the swapped relocs.  If the section uses REL relocs,
796      rather than RELA, all the r_addend fields will be zero.  This
797      pointer may be NULL.  It is used by the backend linker.  */
798   Elf_Internal_Rela *relocs;
799
800   /* Used by the backend linker when generating a shared library to
801      record the dynamic symbol index for a section symbol
802      corresponding to this section.  A value of 0 means that there is
803      no dynamic symbol for this section.  */
804   long dynindx;
805
806   /* A pointer used for .stab linking optimizations.  */
807   PTR stab_info;
808
809   /* A pointer used for SEC_MERGE optimizations.  */
810   PTR merge_info;
811
812   /* A pointer available for the processor specific ELF backend.  */
813   PTR tdata;
814
815   /* Nonzero if this section uses RELA relocations, rather than REL.  */
816   unsigned int use_rela_p:1;
817 };
818
819 #define elf_section_data(sec)  ((struct bfd_elf_section_data*)sec->used_by_bfd)
820
821 #define get_elf_backend_data(abfd) \
822   ((struct elf_backend_data *) (abfd)->xvec->backend_data)
823
824 /* Enumeration to specify the special section.  */
825 typedef enum elf_linker_section_enum
826 {
827   LINKER_SECTION_UNKNOWN,               /* not used */
828   LINKER_SECTION_GOT,                   /* .got section for global offset pointers */
829   LINKER_SECTION_PLT,                   /* .plt section for generated procedure stubs */
830   LINKER_SECTION_SDATA,                 /* .sdata/.sbss section for PowerPC */
831   LINKER_SECTION_SDATA2,                /* .sdata2/.sbss2 section for PowerPC */
832   LINKER_SECTION_MAX                    /* # of linker sections */
833 } elf_linker_section_enum_t;
834
835 /* Sections created by the linker.  */
836
837 typedef struct elf_linker_section
838 {
839   char *name;                           /* name of the section */
840   char *rel_name;                       /* name of the associated .rel{,a}. section */
841   char *bss_name;                       /* name of a related .bss section */
842   char *sym_name;                       /* name of symbol to reference this section */
843   asection *section;                    /* pointer to the section */
844   asection *bss_section;                /* pointer to the bss section associated with this */
845   asection *rel_section;                /* pointer to the relocations needed for this section */
846   struct elf_link_hash_entry *sym_hash; /* pointer to the created symbol hash value */
847   bfd_vma initial_size;                 /* initial size before any linker generated allocations */
848   bfd_vma sym_offset;                   /* offset of symbol from beginning of section */
849   bfd_vma hole_size;                    /* size of reserved address hole in allocation */
850   bfd_vma hole_offset;                  /* current offset for the hole */
851   bfd_vma max_hole_offset;              /* maximum offset for the hole */
852   elf_linker_section_enum_t which;      /* which section this is */
853   boolean hole_written_p;               /* whether the hole has been initialized */
854   unsigned int alignment;               /* alignment for the section */
855   flagword flags;                       /* flags to use to create the section */
856 } elf_linker_section_t;
857
858 /* Linked list of allocated pointer entries.  This hangs off of the symbol lists, and
859    provides allows us to return different pointers, based on different addend's.  */
860
861 typedef struct elf_linker_section_pointers
862 {
863   struct elf_linker_section_pointers *next;     /* next allocated pointer for this symbol */
864   bfd_vma offset;                               /* offset of pointer from beginning of section */
865   bfd_vma addend;                               /* addend used */
866   elf_linker_section_enum_t which;              /* which linker section this is */
867   boolean written_address_p;                    /* whether address was written yet */
868 } elf_linker_section_pointers_t;
869
870 /* Some private data is stashed away for future use using the tdata pointer
871    in the bfd structure.  */
872
873 struct elf_obj_tdata
874 {
875   Elf_Internal_Ehdr elf_header[1];      /* Actual data, but ref like ptr */
876   Elf_Internal_Shdr **elf_sect_ptr;
877   Elf_Internal_Phdr *phdr;
878   struct elf_segment_map *segment_map;
879   struct bfd_strtab_hash *strtab_ptr;
880   int num_locals;
881   int num_globals;
882   int num_section_syms;
883   asymbol **section_syms;               /* STT_SECTION symbols for each section */
884   Elf_Internal_Shdr symtab_hdr;
885   Elf_Internal_Shdr shstrtab_hdr;
886   Elf_Internal_Shdr strtab_hdr;
887   Elf_Internal_Shdr dynsymtab_hdr;
888   Elf_Internal_Shdr dynstrtab_hdr;
889   Elf_Internal_Shdr dynversym_hdr;
890   Elf_Internal_Shdr dynverref_hdr;
891   Elf_Internal_Shdr dynverdef_hdr;
892   unsigned int symtab_section, shstrtab_section;
893   unsigned int strtab_section, dynsymtab_section;
894   unsigned int dynversym_section, dynverdef_section, dynverref_section;
895   file_ptr next_file_pos;
896 #if 0
897   /* we don't need these inside bfd anymore, and I think
898      these weren't used outside bfd.  */
899   void *prstatus;                       /* The raw /proc prstatus structure */
900   void *prpsinfo;                       /* The raw /proc prpsinfo structure */
901 #endif
902   bfd_vma gp;                           /* The gp value (MIPS only, for now) */
903   unsigned int gp_size;                 /* The gp size (MIPS only, for now) */
904
905   /* Information grabbed from an elf core file.  */
906   int core_signal;
907   int core_pid;
908   int core_lwpid;
909   char* core_program;
910   char* core_command;
911
912   /* This is set to true if the object was created by the backend
913      linker.  */
914   boolean linker;
915
916   /* A mapping from external symbols to entries in the linker hash
917      table, used when linking.  This is indexed by the symbol index
918      minus the sh_info field of the symbol table header.  */
919   struct elf_link_hash_entry **sym_hashes;
920
921   /* A mapping from local symbols to offsets into the global offset
922      table, used when linking.  This is indexed by the symbol index.
923      Like for the globals, we use a union and two names primarily to
924      document the intent of any particular piece of code.  The field
925      should be used as a count until size_dynamic_sections, at which
926      point the contents of the .got is fixed.  Afterward, if an entry
927      is -1, then the symbol does not require a global offset table entry.  */
928   union
929     {
930       bfd_signed_vma *refcounts;
931       bfd_vma *offsets;
932     } local_got;
933
934   /* A mapping from local symbols to offsets into the various linker
935      sections added.  This is index by the symbol index.  */
936   elf_linker_section_pointers_t **linker_section_pointers;
937
938   /* The linker ELF emulation code needs to let the backend ELF linker
939      know what filename should be used for a dynamic object if the
940      dynamic object is found using a search.  The emulation code then
941      sometimes needs to know what name was actually used.  Until the
942      file has been added to the linker symbol table, this field holds
943      the name the linker wants.  After it has been added, it holds the
944      name actually used, which will be the DT_SONAME entry if there is
945      one.  */
946   const char *dt_name;
947
948   /* When a reference in a regular object is resolved by a shared
949      object is loaded into via the DT_NEEDED entries by the linker
950      ELF emulation code, we need to add the shared object to the
951      DT_NEEDED list of the resulting binary to indicate the dependency
952      as if the -l option is passed to the linker. This field holds the
953      name of the loaded shared object.  */
954   const char *dt_soname;
955
956   /* Irix 5 often screws up the symbol table, sorting local symbols
957      after global symbols.  This flag is set if the symbol table in
958      this BFD appears to be screwed up.  If it is, we ignore the
959      sh_info field in the symbol table header, and always read all the
960      symbols.  */
961   boolean bad_symtab;
962
963   /* Records the result of `get_program_header_size'.  */
964   bfd_size_type program_header_size;
965
966   /* Used by find_nearest_line entry point.  */
967   PTR line_info;
968
969   /* Used by MIPS ELF find_nearest_line entry point.  The structure
970      could be included directly in this one, but there's no point to
971      wasting the memory just for the infrequently called
972      find_nearest_line.  */
973   struct mips_elf_find_line *find_line_info;
974
975   /* A place to stash dwarf1 info for this bfd.  */
976   struct dwarf1_debug *dwarf1_find_line_info;
977
978   /* A place to stash dwarf2 info for this bfd.  */
979   PTR dwarf2_find_line_info;
980
981   /* An array of stub sections indexed by symbol number, used by the
982      MIPS ELF linker.  FIXME: We should figure out some way to only
983      include this field for a MIPS ELF target.  */
984   asection **local_stubs;
985
986   /* Used to determine if the e_flags field has been initialized */
987   boolean flags_init;
988
989   /* Number of symbol version definitions we are about to emit.  */
990   unsigned int cverdefs;
991
992   /* Number of symbol version references we are about to emit.  */
993   unsigned int cverrefs;
994
995   /* Symbol version definitions in external objects.  */
996   Elf_Internal_Verdef *verdef;
997
998   /* Symbol version references to external objects.  */
999   Elf_Internal_Verneed *verref;
1000
1001   /* Linker sections that we are interested in.  */
1002   struct elf_linker_section *linker_section[ (int)LINKER_SECTION_MAX ];
1003
1004   /* The Irix 5 support uses two virtual sections, which represent
1005      text/data symbols defined in dynamic objects.  */
1006   asymbol *elf_data_symbol;
1007   asymbol *elf_text_symbol;
1008   asection *elf_data_section;
1009   asection *elf_text_section;
1010 };
1011
1012 #define elf_tdata(bfd)          ((bfd) -> tdata.elf_obj_data)
1013 #define elf_elfheader(bfd)      (elf_tdata(bfd) -> elf_header)
1014 #define elf_elfsections(bfd)    (elf_tdata(bfd) -> elf_sect_ptr)
1015 #define elf_shstrtab(bfd)       (elf_tdata(bfd) -> strtab_ptr)
1016 #define elf_onesymtab(bfd)      (elf_tdata(bfd) -> symtab_section)
1017 #define elf_dynsymtab(bfd)      (elf_tdata(bfd) -> dynsymtab_section)
1018 #define elf_dynversym(bfd)      (elf_tdata(bfd) -> dynversym_section)
1019 #define elf_dynverdef(bfd)      (elf_tdata(bfd) -> dynverdef_section)
1020 #define elf_dynverref(bfd)      (elf_tdata(bfd) -> dynverref_section)
1021 #define elf_num_locals(bfd)     (elf_tdata(bfd) -> num_locals)
1022 #define elf_num_globals(bfd)    (elf_tdata(bfd) -> num_globals)
1023 #define elf_section_syms(bfd)   (elf_tdata(bfd) -> section_syms)
1024 #define elf_num_section_syms(bfd) (elf_tdata(bfd) -> num_section_syms)
1025 #define core_prpsinfo(bfd)      (elf_tdata(bfd) -> prpsinfo)
1026 #define core_prstatus(bfd)      (elf_tdata(bfd) -> prstatus)
1027 #define elf_gp(bfd)             (elf_tdata(bfd) -> gp)
1028 #define elf_gp_size(bfd)        (elf_tdata(bfd) -> gp_size)
1029 #define elf_sym_hashes(bfd)     (elf_tdata(bfd) -> sym_hashes)
1030 #define elf_local_got_refcounts(bfd) (elf_tdata(bfd) -> local_got.refcounts)
1031 #define elf_local_got_offsets(bfd) (elf_tdata(bfd) -> local_got.offsets)
1032 #define elf_local_ptr_offsets(bfd) (elf_tdata(bfd) -> linker_section_pointers)
1033 #define elf_dt_name(bfd)        (elf_tdata(bfd) -> dt_name)
1034 #define elf_dt_soname(bfd)      (elf_tdata(bfd) -> dt_soname)
1035 #define elf_bad_symtab(bfd)     (elf_tdata(bfd) -> bad_symtab)
1036 #define elf_flags_init(bfd)     (elf_tdata(bfd) -> flags_init)
1037 #define elf_linker_section(bfd,n) (elf_tdata(bfd) -> linker_section[(int)n])
1038 \f
1039 extern void _bfd_elf_swap_verdef_in
1040   PARAMS ((bfd *, const Elf_External_Verdef *, Elf_Internal_Verdef *));
1041 extern void _bfd_elf_swap_verdef_out
1042   PARAMS ((bfd *, const Elf_Internal_Verdef *, Elf_External_Verdef *));
1043 extern void _bfd_elf_swap_verdaux_in
1044   PARAMS ((bfd *, const Elf_External_Verdaux *, Elf_Internal_Verdaux *));
1045 extern void _bfd_elf_swap_verdaux_out
1046   PARAMS ((bfd *, const Elf_Internal_Verdaux *, Elf_External_Verdaux *));
1047 extern void _bfd_elf_swap_verneed_in
1048   PARAMS ((bfd *, const Elf_External_Verneed *, Elf_Internal_Verneed *));
1049 extern void _bfd_elf_swap_verneed_out
1050   PARAMS ((bfd *, const Elf_Internal_Verneed *, Elf_External_Verneed *));
1051 extern void _bfd_elf_swap_vernaux_in
1052   PARAMS ((bfd *, const Elf_External_Vernaux *, Elf_Internal_Vernaux *));
1053 extern void _bfd_elf_swap_vernaux_out
1054   PARAMS ((bfd *, const Elf_Internal_Vernaux *, Elf_External_Vernaux *));
1055 extern void _bfd_elf_swap_versym_in
1056   PARAMS ((bfd *, const Elf_External_Versym *, Elf_Internal_Versym *));
1057 extern void _bfd_elf_swap_versym_out
1058   PARAMS ((bfd *, const Elf_Internal_Versym *, Elf_External_Versym *));
1059
1060 extern int _bfd_elf_section_from_bfd_section
1061   PARAMS ((bfd *, asection *));
1062 extern char *bfd_elf_string_from_elf_section
1063   PARAMS ((bfd *, unsigned, unsigned));
1064 extern char *bfd_elf_get_str_section
1065   PARAMS ((bfd *, unsigned));
1066
1067 extern boolean _bfd_elf_print_private_bfd_data
1068   PARAMS ((bfd *, PTR));
1069 extern void bfd_elf_print_symbol
1070   PARAMS ((bfd *, PTR, asymbol *, bfd_print_symbol_type));
1071
1072 #define elf_string_from_elf_strtab(abfd, strindex) \
1073   bfd_elf_string_from_elf_section(abfd, elf_elfheader(abfd)->e_shstrndx, \
1074                                   strindex)
1075
1076 #define bfd_elf32_print_symbol  bfd_elf_print_symbol
1077 #define bfd_elf64_print_symbol  bfd_elf_print_symbol
1078
1079 extern void _bfd_elf_sprintf_vma
1080   PARAMS ((bfd *, char *, bfd_vma));
1081 extern void _bfd_elf_fprintf_vma
1082   PARAMS ((bfd *, PTR, bfd_vma));
1083
1084 extern enum elf_reloc_type_class _bfd_elf_reloc_type_class
1085   PARAMS ((const Elf_Internal_Rela *));
1086
1087 extern unsigned long bfd_elf_hash
1088   PARAMS ((const char *));
1089
1090 extern bfd_reloc_status_type bfd_elf_generic_reloc
1091   PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
1092 extern boolean bfd_elf_mkobject
1093   PARAMS ((bfd *));
1094 extern boolean bfd_elf_mkcorefile
1095   PARAMS ((bfd *));
1096 extern Elf_Internal_Shdr *bfd_elf_find_section
1097   PARAMS ((bfd *, char *));
1098 extern boolean _bfd_elf_make_section_from_shdr
1099   PARAMS ((bfd *, Elf_Internal_Shdr *, const char *));
1100 extern boolean _bfd_elf_make_section_from_phdr
1101   PARAMS ((bfd *, Elf_Internal_Phdr *, int, const char *));
1102 extern struct bfd_hash_entry *_bfd_elf_link_hash_newfunc
1103   PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
1104 extern struct bfd_link_hash_table *_bfd_elf_link_hash_table_create
1105   PARAMS ((bfd *));
1106 extern void _bfd_elf_link_hash_copy_indirect
1107   PARAMS ((struct elf_link_hash_entry *, struct elf_link_hash_entry *));
1108 extern void _bfd_elf_link_hash_hide_symbol
1109   PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
1110 extern boolean _bfd_elf_link_hash_table_init
1111   PARAMS ((struct elf_link_hash_table *, bfd *,
1112            struct bfd_hash_entry *(*) (struct bfd_hash_entry *,
1113                                        struct bfd_hash_table *,
1114                                        const char *)));
1115 extern boolean _bfd_elf_slurp_version_tables
1116   PARAMS ((bfd *));
1117
1118 extern boolean _bfd_elf_merge_sections
1119   PARAMS ((bfd *, struct bfd_link_info *));
1120
1121 extern boolean _bfd_elf_copy_private_symbol_data
1122   PARAMS ((bfd *, asymbol *, bfd *, asymbol *));
1123 extern boolean _bfd_elf_copy_private_section_data
1124   PARAMS ((bfd *, asection *, bfd *, asection *));
1125 extern boolean _bfd_elf_write_object_contents
1126   PARAMS ((bfd *));
1127 extern boolean _bfd_elf_write_corefile_contents
1128   PARAMS ((bfd *));
1129 extern boolean _bfd_elf_set_section_contents
1130   PARAMS ((bfd *, sec_ptr, PTR, file_ptr, bfd_size_type));
1131 extern long _bfd_elf_get_symtab_upper_bound
1132   PARAMS ((bfd *));
1133 extern long _bfd_elf_get_symtab
1134   PARAMS ((bfd *, asymbol **));
1135 extern long _bfd_elf_get_dynamic_symtab_upper_bound
1136   PARAMS ((bfd *));
1137 extern long _bfd_elf_canonicalize_dynamic_symtab
1138   PARAMS ((bfd *, asymbol **));
1139 extern long _bfd_elf_get_reloc_upper_bound
1140   PARAMS ((bfd *, sec_ptr));
1141 extern long _bfd_elf_canonicalize_reloc
1142   PARAMS ((bfd *, sec_ptr, arelent **, asymbol **));
1143 extern long _bfd_elf_get_dynamic_reloc_upper_bound
1144   PARAMS ((bfd *));
1145 extern long _bfd_elf_canonicalize_dynamic_reloc
1146   PARAMS ((bfd *, arelent **, asymbol **));
1147 extern asymbol *_bfd_elf_make_empty_symbol
1148   PARAMS ((bfd *));
1149 extern void _bfd_elf_get_symbol_info
1150   PARAMS ((bfd *, asymbol *, symbol_info *));
1151 extern boolean _bfd_elf_is_local_label_name
1152   PARAMS ((bfd *, const char *));
1153 extern alent *_bfd_elf_get_lineno
1154   PARAMS ((bfd *, asymbol *));
1155 extern boolean _bfd_elf_set_arch_mach
1156   PARAMS ((bfd *, enum bfd_architecture, unsigned long));
1157 extern boolean _bfd_elf_find_nearest_line
1158   PARAMS ((bfd *, asection *, asymbol **, bfd_vma, const char **,
1159            const char **, unsigned int *));
1160 #define _bfd_elf_read_minisymbols _bfd_generic_read_minisymbols
1161 #define _bfd_elf_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol
1162 extern int _bfd_elf_sizeof_headers
1163   PARAMS ((bfd *, boolean));
1164 extern boolean _bfd_elf_new_section_hook
1165   PARAMS ((bfd *, asection *));
1166 extern boolean _bfd_elf_init_reloc_shdr
1167   PARAMS ((bfd *, Elf_Internal_Shdr *, asection *, boolean));
1168
1169 /* If the target doesn't have reloc handling written yet:  */
1170 extern void _bfd_elf_no_info_to_howto
1171   PARAMS ((bfd *, arelent *, Elf_Internal_Rela *));
1172
1173 extern boolean bfd_section_from_shdr
1174   PARAMS ((bfd *, unsigned int shindex));
1175 extern boolean bfd_section_from_phdr
1176   PARAMS ((bfd *, Elf_Internal_Phdr *, int));
1177
1178 extern int _bfd_elf_symbol_from_bfd_symbol
1179   PARAMS ((bfd *, asymbol **));
1180
1181 extern asection *bfd_section_from_elf_index
1182   PARAMS ((bfd *, unsigned int));
1183 extern boolean _bfd_elf_create_dynamic_sections
1184   PARAMS ((bfd *, struct bfd_link_info *));
1185 extern struct bfd_strtab_hash *_bfd_elf_stringtab_init
1186   PARAMS ((void));
1187 extern boolean _bfd_elf_link_record_dynamic_symbol
1188   PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
1189 extern long _bfd_elf_link_lookup_local_dynindx
1190   PARAMS ((struct bfd_link_info *, bfd *, long));
1191 extern boolean _bfd_elf_compute_section_file_positions
1192   PARAMS ((bfd *, struct bfd_link_info *));
1193 extern void _bfd_elf_assign_file_positions_for_relocs
1194   PARAMS ((bfd *));
1195 extern file_ptr _bfd_elf_assign_file_position_for_section
1196   PARAMS ((Elf_Internal_Shdr *, file_ptr, boolean));
1197
1198 extern boolean _bfd_elf_validate_reloc
1199   PARAMS ((bfd *, arelent *));
1200
1201 extern boolean _bfd_elf_create_dynamic_sections
1202   PARAMS ((bfd *, struct bfd_link_info *));
1203 extern boolean _bfd_elf_create_got_section
1204   PARAMS ((bfd *, struct bfd_link_info *));
1205 extern unsigned long _bfd_elf_link_renumber_dynsyms
1206   PARAMS ((bfd *, struct bfd_link_info *));
1207
1208 extern boolean _bfd_elfcore_make_pseudosection
1209   PARAMS ((bfd *, char *, size_t, ufile_ptr));
1210 extern char *_bfd_elfcore_strndup
1211   PARAMS ((bfd *, char *, size_t));
1212
1213 extern elf_linker_section_t *_bfd_elf_create_linker_section
1214   PARAMS ((bfd *, struct bfd_link_info *, enum elf_linker_section_enum,
1215            elf_linker_section_t *));
1216
1217 extern elf_linker_section_pointers_t *_bfd_elf_find_pointer_linker_section
1218   PARAMS ((elf_linker_section_pointers_t *, bfd_vma,
1219            elf_linker_section_enum_t));
1220
1221 extern boolean bfd_elf32_create_pointer_linker_section
1222   PARAMS ((bfd *, struct bfd_link_info *, elf_linker_section_t *,
1223            struct elf_link_hash_entry *, const Elf32_Internal_Rela *));
1224
1225 extern bfd_vma bfd_elf32_finish_pointer_linker_section
1226   PARAMS ((bfd *, bfd *, struct bfd_link_info *, elf_linker_section_t *,
1227            struct elf_link_hash_entry *, bfd_vma,
1228            const Elf32_Internal_Rela *, int));
1229
1230 extern boolean bfd_elf64_create_pointer_linker_section
1231   PARAMS ((bfd *, struct bfd_link_info *, elf_linker_section_t *,
1232            struct elf_link_hash_entry *, const Elf64_Internal_Rela *));
1233
1234 extern bfd_vma bfd_elf64_finish_pointer_linker_section
1235   PARAMS ((bfd *, bfd *, struct bfd_link_info *, elf_linker_section_t *,
1236            struct elf_link_hash_entry *, bfd_vma,
1237            const Elf64_Internal_Rela *, int));
1238
1239 extern boolean _bfd_elf_make_linker_section_rela
1240   PARAMS ((bfd *, elf_linker_section_t *, int));
1241
1242 extern const bfd_target *bfd_elf32_object_p
1243   PARAMS ((bfd *));
1244 extern const bfd_target *bfd_elf32_core_file_p
1245   PARAMS ((bfd *));
1246 extern char *bfd_elf32_core_file_failing_command
1247   PARAMS ((bfd *));
1248 extern int bfd_elf32_core_file_failing_signal
1249   PARAMS ((bfd *));
1250 extern boolean bfd_elf32_core_file_matches_executable_p
1251   PARAMS ((bfd *, bfd *));
1252
1253 extern boolean bfd_elf32_bfd_link_add_symbols
1254   PARAMS ((bfd *, struct bfd_link_info *));
1255 extern boolean bfd_elf32_bfd_final_link
1256   PARAMS ((bfd *, struct bfd_link_info *));
1257
1258 extern void bfd_elf32_swap_symbol_in
1259   PARAMS ((bfd *, const Elf32_External_Sym *, Elf_Internal_Sym *));
1260 extern void bfd_elf32_swap_symbol_out
1261   PARAMS ((bfd *, const Elf_Internal_Sym *, PTR));
1262 extern void bfd_elf32_swap_reloc_in
1263   PARAMS ((bfd *, const Elf32_External_Rel *, Elf_Internal_Rel *));
1264 extern void bfd_elf32_swap_reloc_out
1265   PARAMS ((bfd *, const Elf_Internal_Rel *, Elf32_External_Rel *));
1266 extern void bfd_elf32_swap_reloca_in
1267   PARAMS ((bfd *, const Elf32_External_Rela *, Elf_Internal_Rela *));
1268 extern void bfd_elf32_swap_reloca_out
1269   PARAMS ((bfd *, const Elf_Internal_Rela *, Elf32_External_Rela *));
1270 extern void bfd_elf32_swap_phdr_in
1271   PARAMS ((bfd *, const Elf32_External_Phdr *, Elf_Internal_Phdr *));
1272 extern void bfd_elf32_swap_phdr_out
1273   PARAMS ((bfd *, const Elf_Internal_Phdr *, Elf32_External_Phdr *));
1274 extern void bfd_elf32_swap_dyn_in
1275   PARAMS ((bfd *, const PTR, Elf_Internal_Dyn *));
1276 extern void bfd_elf32_swap_dyn_out
1277   PARAMS ((bfd *, const Elf_Internal_Dyn *, PTR));
1278 extern long bfd_elf32_slurp_symbol_table
1279   PARAMS ((bfd *, asymbol **, boolean));
1280 extern boolean bfd_elf32_write_shdrs_and_ehdr
1281   PARAMS ((bfd *));
1282 extern int bfd_elf32_write_out_phdrs
1283   PARAMS ((bfd *, const Elf_Internal_Phdr *, unsigned int));
1284 extern void bfd_elf32_write_relocs
1285   PARAMS ((bfd *, asection *, PTR));
1286 extern boolean bfd_elf32_slurp_reloc_table
1287   PARAMS ((bfd *, asection *, asymbol **, boolean));
1288 extern boolean bfd_elf32_add_dynamic_entry
1289   PARAMS ((struct bfd_link_info *, bfd_vma, bfd_vma));
1290 extern boolean bfd_elf32_link_create_dynamic_sections
1291   PARAMS ((bfd *, struct bfd_link_info *));
1292 extern Elf_Internal_Rela *_bfd_elf32_link_read_relocs
1293   PARAMS ((bfd *, asection *, PTR, Elf_Internal_Rela *, boolean));
1294
1295 extern const bfd_target *bfd_elf64_object_p
1296   PARAMS ((bfd *));
1297 extern const bfd_target *bfd_elf64_core_file_p
1298   PARAMS ((bfd *));
1299 extern char *bfd_elf64_core_file_failing_command
1300   PARAMS ((bfd *));
1301 extern int bfd_elf64_core_file_failing_signal
1302   PARAMS ((bfd *));
1303 extern boolean bfd_elf64_core_file_matches_executable_p
1304   PARAMS ((bfd *, bfd *));
1305 extern boolean bfd_elf64_bfd_link_add_symbols
1306   PARAMS ((bfd *, struct bfd_link_info *));
1307 extern boolean bfd_elf64_bfd_final_link
1308   PARAMS ((bfd *, struct bfd_link_info *));
1309
1310 extern void bfd_elf64_swap_symbol_in
1311   PARAMS ((bfd *, const Elf64_External_Sym *, Elf_Internal_Sym *));
1312 extern void bfd_elf64_swap_symbol_out
1313   PARAMS ((bfd *, const Elf_Internal_Sym *, PTR));
1314 extern void bfd_elf64_swap_reloc_in
1315   PARAMS ((bfd *, const Elf64_External_Rel *, Elf_Internal_Rel *));
1316 extern void bfd_elf64_swap_reloc_out
1317   PARAMS ((bfd *, const Elf_Internal_Rel *, Elf64_External_Rel *));
1318 extern void bfd_elf64_swap_reloca_in
1319   PARAMS ((bfd *, const Elf64_External_Rela *, Elf_Internal_Rela *));
1320 extern void bfd_elf64_swap_reloca_out
1321   PARAMS ((bfd *, const Elf_Internal_Rela *, Elf64_External_Rela *));
1322 extern void bfd_elf64_swap_phdr_in
1323   PARAMS ((bfd *, const Elf64_External_Phdr *, Elf_Internal_Phdr *));
1324 extern void bfd_elf64_swap_phdr_out
1325   PARAMS ((bfd *, const Elf_Internal_Phdr *, Elf64_External_Phdr *));
1326 extern void bfd_elf64_swap_dyn_in
1327   PARAMS ((bfd *, const PTR, Elf_Internal_Dyn *));
1328 extern void bfd_elf64_swap_dyn_out
1329   PARAMS ((bfd *, const Elf_Internal_Dyn *, PTR));
1330 extern long bfd_elf64_slurp_symbol_table
1331   PARAMS ((bfd *, asymbol **, boolean));
1332 extern boolean bfd_elf64_write_shdrs_and_ehdr
1333   PARAMS ((bfd *));
1334 extern int bfd_elf64_write_out_phdrs
1335   PARAMS ((bfd *, const Elf_Internal_Phdr *, unsigned int));
1336 extern void bfd_elf64_write_relocs
1337   PARAMS ((bfd *, asection *, PTR));
1338 extern boolean bfd_elf64_slurp_reloc_table
1339   PARAMS ((bfd *, asection *, asymbol **, boolean));
1340 extern boolean bfd_elf64_add_dynamic_entry
1341   PARAMS ((struct bfd_link_info *, bfd_vma, bfd_vma));
1342 extern boolean bfd_elf64_link_create_dynamic_sections
1343   PARAMS ((bfd *, struct bfd_link_info *));
1344 extern Elf_Internal_Rela *_bfd_elf64_link_read_relocs
1345   PARAMS ((bfd *, asection *, PTR, Elf_Internal_Rela *, boolean));
1346
1347 #define bfd_elf32_link_record_dynamic_symbol \
1348   _bfd_elf_link_record_dynamic_symbol
1349 #define bfd_elf64_link_record_dynamic_symbol \
1350   _bfd_elf_link_record_dynamic_symbol
1351
1352 extern boolean _bfd_elf32_link_record_local_dynamic_symbol
1353   PARAMS ((struct bfd_link_info *, bfd *, long));
1354 extern boolean _bfd_elf64_link_record_local_dynamic_symbol
1355   PARAMS ((struct bfd_link_info *, bfd *, long));
1356
1357 extern boolean _bfd_elf_close_and_cleanup
1358   PARAMS ((bfd *));
1359 extern bfd_reloc_status_type _bfd_elf_rel_vtable_reloc_fn
1360   PARAMS ((bfd *, arelent *, struct symbol_cache_entry *, PTR,
1361            asection *, bfd *, char **));
1362
1363 extern boolean _bfd_elf32_gc_sections
1364   PARAMS ((bfd *, struct bfd_link_info *));
1365 extern boolean _bfd_elf32_gc_common_finalize_got_offsets
1366   PARAMS ((bfd *, struct bfd_link_info *));
1367 extern boolean _bfd_elf32_gc_common_final_link
1368   PARAMS ((bfd *, struct bfd_link_info *));
1369 extern boolean _bfd_elf32_gc_record_vtinherit
1370   PARAMS ((bfd *, asection *, struct elf_link_hash_entry *, bfd_vma));
1371 extern boolean _bfd_elf32_gc_record_vtentry
1372   PARAMS ((bfd *, asection *, struct elf_link_hash_entry *, bfd_vma));
1373
1374 extern boolean _bfd_elf64_gc_sections
1375   PARAMS ((bfd *, struct bfd_link_info *));
1376 extern boolean _bfd_elf64_gc_common_finalize_got_offsets
1377   PARAMS ((bfd *, struct bfd_link_info *));
1378 extern boolean _bfd_elf64_gc_common_final_link
1379   PARAMS ((bfd *, struct bfd_link_info *));
1380 extern boolean _bfd_elf64_gc_record_vtinherit
1381   PARAMS ((bfd *, asection *, struct elf_link_hash_entry *, bfd_vma));
1382 extern boolean _bfd_elf64_gc_record_vtentry
1383   PARAMS ((bfd *, asection *, struct elf_link_hash_entry *, bfd_vma));
1384
1385 /* MIPS ELF specific routines.  */
1386
1387 extern boolean _bfd_mips_elf_object_p
1388   PARAMS ((bfd *));
1389 extern boolean _bfd_mips_elf_section_from_shdr
1390   PARAMS ((bfd *, Elf_Internal_Shdr *, char *));
1391 extern boolean _bfd_mips_elf_fake_sections
1392   PARAMS ((bfd *, Elf_Internal_Shdr *, asection *));
1393 extern boolean _bfd_mips_elf_section_from_bfd_section
1394   PARAMS ((bfd *, Elf_Internal_Shdr *, asection *, int *));
1395 extern boolean _bfd_mips_elf_section_processing
1396   PARAMS ((bfd *, Elf_Internal_Shdr *));
1397 extern void _bfd_mips_elf_symbol_processing
1398   PARAMS ((bfd *, asymbol *));
1399 extern boolean _bfd_mips_elf_read_ecoff_info
1400   PARAMS ((bfd *, asection *, struct ecoff_debug_info *));
1401 extern void _bfd_mips_elf_final_write_processing
1402   PARAMS ((bfd *, boolean));
1403 extern bfd_reloc_status_type _bfd_mips_elf_hi16_reloc
1404   PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
1405 extern bfd_reloc_status_type _bfd_mips_elf_lo16_reloc
1406   PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
1407 extern bfd_reloc_status_type _bfd_mips_elf_gprel16_reloc
1408   PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
1409 extern bfd_reloc_status_type _bfd_mips_elf_got16_reloc
1410   PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
1411 extern bfd_reloc_status_type _bfd_mips_elf_gprel32_reloc
1412   PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
1413 extern boolean _bfd_mips_elf_set_private_flags
1414   PARAMS ((bfd *, flagword));
1415 extern boolean _bfd_mips_elf_copy_private_bfd_data
1416   PARAMS ((bfd *, bfd *));
1417 extern boolean _bfd_mips_elf_merge_private_bfd_data
1418   PARAMS ((bfd *, bfd *));
1419 extern boolean _bfd_mips_elf_find_nearest_line
1420   PARAMS ((bfd *, asection *, asymbol **, bfd_vma, const char **,
1421            const char **, unsigned int *));
1422 extern boolean _bfd_mips_elf_set_section_contents
1423   PARAMS ((bfd *, asection *, PTR, file_ptr, bfd_size_type));
1424 extern boolean _bfd_mips_elf_create_dynamic_sections
1425   PARAMS ((bfd *, struct bfd_link_info *));
1426 extern boolean _bfd_mips_elf_add_symbol_hook
1427   PARAMS ((bfd *, struct bfd_link_info *, const Elf_Internal_Sym *,
1428            const char **, flagword *, asection **, bfd_vma *));
1429 extern boolean _bfd_mips_elf_adjust_dynamic_symbol
1430   PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
1431 extern boolean _bfd_mips_elf_finish_dynamic_symbol
1432   PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
1433            Elf_Internal_Sym *));
1434 extern boolean _bfd_mips_elf_finish_dynamic_sections
1435   PARAMS ((bfd *, struct bfd_link_info *));
1436 extern asection * _bfd_mips_elf_gc_mark_hook
1437   PARAMS ((bfd *, struct bfd_link_info *, Elf_Internal_Rela *,
1438            struct elf_link_hash_entry *, Elf_Internal_Sym *));
1439 extern boolean _bfd_mips_elf_gc_sweep_hook
1440   PARAMS ((bfd *, struct bfd_link_info *, asection *,
1441            const Elf_Internal_Rela *));
1442 extern boolean _bfd_mips_elf_always_size_sections
1443   PARAMS ((bfd *, struct bfd_link_info *));
1444 extern boolean _bfd_mips_elf_size_dynamic_sections
1445   PARAMS ((bfd *, struct bfd_link_info *));
1446 extern boolean _bfd_mips_elf_check_relocs
1447   PARAMS ((bfd *, struct bfd_link_info *, asection *,
1448            const Elf_Internal_Rela *));
1449 extern struct bfd_link_hash_table *_bfd_mips_elf_link_hash_table_create
1450   PARAMS ((bfd *));
1451 extern boolean _bfd_mips_elf_print_private_bfd_data
1452   PARAMS ((bfd *, PTR));
1453 extern boolean _bfd_mips_elf_link_output_symbol_hook
1454   PARAMS ((bfd *, struct bfd_link_info *, const char *, Elf_Internal_Sym *,
1455            asection *));
1456 extern boolean _bfd_mips_elf_final_link
1457   PARAMS ((bfd *, struct bfd_link_info *));
1458 extern int _bfd_mips_elf_additional_program_headers
1459   PARAMS ((bfd *));
1460 extern boolean _bfd_mips_elf_modify_segment_map
1461   PARAMS ((bfd *));
1462 extern boolean _bfd_mips_elf_relocate_section
1463   PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
1464            Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
1465
1466 /* SH ELF specific routine.  */
1467
1468 extern boolean _sh_elf_set_mach_from_flags
1469   PARAMS ((bfd *));
1470
1471 #endif /* _LIBELF_H_ */