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