Added new files elflink.c, elflink.h, elfcore.h.
[external/binutils.git] / bfd / elfxx-target.h
1 /* Target definitions for NN-bit ELF
2    Copyright 1993, 1994, 1995 Free Software Foundation, Inc.
3
4 This file is part of BFD, the Binary File Descriptor library.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
19
20 /* This structure contains everything that BFD knows about a target.
21    It includes things like its byte order, name, what routines to call
22    to do various operations, etc.  Every BFD points to a target structure
23    with its "xvec" member.
24
25    There are two such structures here:  one for big-endian machines and
26    one for little-endian machines.   */
27
28 #define bfd_elfNN_close_and_cleanup _bfd_generic_close_and_cleanup
29 #define bfd_elfNN_bfd_free_cached_info _bfd_generic_bfd_free_cached_info
30 #ifndef bfd_elfNN_get_section_contents
31 #define bfd_elfNN_get_section_contents _bfd_generic_get_section_contents
32 #endif
33
34 #define bfd_elfNN_canonicalize_dynamic_symtab _bfd_elf_canonicalize_dynamic_symtab
35 #define bfd_elfNN_canonicalize_reloc    _bfd_elf_canonicalize_reloc
36 #ifndef bfd_elfNN_find_nearest_line
37 #define bfd_elfNN_find_nearest_line     _bfd_elf_find_nearest_line
38 #endif
39 #define bfd_elfNN_get_dynamic_symtab_upper_bound _bfd_elf_get_dynamic_symtab_upper_bound
40 #define bfd_elfNN_get_lineno            _bfd_elf_get_lineno
41 #define bfd_elfNN_get_reloc_upper_bound _bfd_elf_get_reloc_upper_bound
42 #define bfd_elfNN_get_symbol_info       _bfd_elf_get_symbol_info
43 #define bfd_elfNN_get_symtab            _bfd_elf_get_symtab
44 #define bfd_elfNN_get_symtab_upper_bound _bfd_elf_get_symtab_upper_bound
45 #if 0 /* done in libelf.h */
46 #define bfd_elfNN_link_record_dynamic_symbol _bfd_elf_link_record_dynamic_symbol
47 #endif
48 #define bfd_elfNN_make_empty_symbol     _bfd_elf_make_empty_symbol
49 #define bfd_elfNN_new_section_hook      _bfd_elf_new_section_hook
50 #define bfd_elfNN_set_arch_mach         _bfd_elf_set_arch_mach
51 #ifndef bfd_elfNN_set_section_contents
52 #define bfd_elfNN_set_section_contents  _bfd_elf_set_section_contents
53 #endif
54 #define bfd_elfNN_sizeof_headers        _bfd_elf_sizeof_headers
55 #define bfd_elfNN_write_object_contents _bfd_elf_write_object_contents
56
57 #ifndef elf_backend_want_got_plt
58 #define elf_backend_want_got_plt 0
59 #endif
60 #ifndef elf_backend_plt_readonly
61 #define elf_backend_plt_readonly 0
62 #endif
63 #ifndef elf_backend_want_plt_sym
64 #define elf_backend_want_plt_sym 0
65 #endif
66
67 #define bfd_elfNN_bfd_debug_info_start  bfd_void
68 #define bfd_elfNN_bfd_debug_info_end    bfd_void
69 #define bfd_elfNN_bfd_debug_info_accumulate     (PROTO(void,(*),(bfd*, struct sec *))) bfd_void
70
71 #ifndef bfd_elfNN_bfd_get_relocated_section_contents
72 #define bfd_elfNN_bfd_get_relocated_section_contents \
73  bfd_generic_get_relocated_section_contents
74 #endif
75
76 #define bfd_elfNN_bfd_relax_section bfd_generic_relax_section
77 #define bfd_elfNN_bfd_make_debug_symbol \
78   ((asymbol *(*) PARAMS ((bfd *, void *, unsigned long))) bfd_nullvoidptr)
79
80 #ifndef bfd_elfNN_bfd_copy_private_symbol_data
81 #define bfd_elfNN_bfd_copy_private_symbol_data \
82   ((boolean (*) PARAMS ((bfd *, asymbol *, bfd *, asymbol *))) bfd_true)
83 #endif
84 #ifndef bfd_elfNN_bfd_copy_private_section_data
85 #define bfd_elfNN_bfd_copy_private_section_data \
86   ((boolean (*) PARAMS ((bfd *, asection *, bfd *, asection *))) bfd_true)
87 #endif
88 #ifndef bfd_elfNN_bfd_copy_private_bfd_data
89 #define bfd_elfNN_bfd_copy_private_bfd_data \
90   ((boolean (*) PARAMS ((bfd *, bfd *))) bfd_true)
91 #endif
92 #ifndef bfd_elfNN_bfd_merge_private_bfd_data
93 #define bfd_elfNN_bfd_merge_private_bfd_data \
94   ((boolean (*) PARAMS ((bfd *, bfd *))) bfd_true)
95 #endif
96 #ifndef bfd_elfNN_bfd_set_private_flags
97 #define bfd_elfNN_bfd_set_private_flags \
98   ((boolean (*) PARAMS ((bfd *, flagword))) bfd_true)
99 #endif
100 #ifndef bfd_elfNN_bfd_is_local_label
101 #define bfd_elfNN_bfd_is_local_label bfd_generic_is_local_label
102 #endif
103
104 #ifndef bfd_elfNN_get_dynamic_reloc_upper_bound
105 #define bfd_elfNN_get_dynamic_reloc_upper_bound \
106   _bfd_nodynamic_get_dynamic_reloc_upper_bound
107 #endif
108 #ifndef bfd_elfNN_canonicalize_dynamic_reloc
109 #define bfd_elfNN_canonicalize_dynamic_reloc \
110   _bfd_nodynamic_canonicalize_dynamic_reloc
111 #endif
112
113 #ifdef elf_backend_relocate_section
114 #ifndef bfd_elfNN_bfd_link_hash_table_create
115 #define bfd_elfNN_bfd_link_hash_table_create _bfd_elf_link_hash_table_create
116 #endif
117 #else /* ! defined (elf_backend_relocate_section) */
118 /* If no backend relocate_section routine, use the generic linker.  */
119 #ifndef bfd_elfNN_bfd_link_hash_table_create
120 #define bfd_elfNN_bfd_link_hash_table_create \
121   _bfd_generic_link_hash_table_create
122 #endif
123 #ifndef bfd_elfNN_bfd_link_add_symbols
124 #define bfd_elfNN_bfd_link_add_symbols  _bfd_generic_link_add_symbols
125 #endif
126 #ifndef bfd_elfNN_bfd_final_link
127 #define bfd_elfNN_bfd_final_link        _bfd_generic_final_link
128 #endif
129 #endif /* ! defined (elf_backend_relocate_section) */
130 #ifndef bfd_elfNN_bfd_link_split_section
131 #define bfd_elfNN_bfd_link_split_section _bfd_generic_link_split_section
132 #endif
133
134 #ifndef elf_info_to_howto_rel
135 #define elf_info_to_howto_rel 0
136 #endif
137
138 #ifndef ELF_MAXPAGESIZE
139 #define ELF_MAXPAGESIZE 1
140 #endif
141
142 #ifndef elf_backend_collect
143 #define elf_backend_collect false
144 #endif
145
146 #ifndef elf_backend_sym_is_global
147 #define elf_backend_sym_is_global       0
148 #endif
149 #ifndef elf_backend_object_p
150 #define elf_backend_object_p            0
151 #endif
152 #ifndef elf_backend_symbol_processing
153 #define elf_backend_symbol_processing   0
154 #endif
155 #ifndef elf_backend_symbol_table_processing
156 #define elf_backend_symbol_table_processing     0
157 #endif
158 #ifndef elf_backend_section_processing
159 #define elf_backend_section_processing  0
160 #endif
161 #ifndef elf_backend_section_from_shdr
162 #define elf_backend_section_from_shdr   0
163 #endif
164 #ifndef elf_backend_fake_sections
165 #define elf_backend_fake_sections       0
166 #endif
167 #ifndef elf_backend_section_from_bfd_section
168 #define elf_backend_section_from_bfd_section    0
169 #endif
170 #ifndef elf_backend_add_symbol_hook
171 #define elf_backend_add_symbol_hook     0
172 #endif
173 #ifndef elf_backend_link_output_symbol_hook
174 #define elf_backend_link_output_symbol_hook 0
175 #endif
176 #ifndef elf_backend_create_dynamic_sections
177 #define elf_backend_create_dynamic_sections 0
178 #endif
179 #ifndef elf_backend_check_relocs
180 #define elf_backend_check_relocs        0
181 #endif
182 #ifndef elf_backend_adjust_dynamic_symbol
183 #define elf_backend_adjust_dynamic_symbol 0
184 #endif
185 #ifndef elf_backend_size_dynamic_sections
186 #define elf_backend_size_dynamic_sections 0
187 #endif
188 #ifndef elf_backend_relocate_section
189 #define elf_backend_relocate_section    0
190 #endif
191 #ifndef elf_backend_finish_dynamic_symbol
192 #define elf_backend_finish_dynamic_symbol       0
193 #endif
194 #ifndef elf_backend_finish_dynamic_sections
195 #define elf_backend_finish_dynamic_sections     0
196 #endif
197 #ifndef elf_backend_begin_write_processing
198 #define elf_backend_begin_write_processing      0
199 #endif
200 #ifndef elf_backend_final_write_processing
201 #define elf_backend_final_write_processing      0
202 #endif
203 #ifndef elf_backend_ecoff_debug_swap
204 #define elf_backend_ecoff_debug_swap    0
205 #endif
206
207 #ifndef ELF_MACHINE_ALT1
208 #define ELF_MACHINE_ALT1 0
209 #endif
210
211 #ifndef ELF_MACHINE_ALT2
212 #define ELF_MACHINE_ALT2 0
213 #endif
214
215 extern const struct elf_size_info _bfd_elfNN_size_info;
216
217 static CONST struct elf_backend_data elfNN_bed =
218 {
219 #ifdef USE_REL
220   0,                            /* use_rela_p */
221 #else
222   1,                            /* use_rela_p */
223 #endif
224   ELF_ARCH,                     /* arch */
225   ELF_MACHINE_CODE,             /* elf_machine_code */
226   ELF_MAXPAGESIZE,              /* maxpagesize */
227   elf_backend_collect,
228   elf_info_to_howto,
229   elf_info_to_howto_rel,
230   elf_backend_sym_is_global,
231   elf_backend_object_p,
232   elf_backend_symbol_processing,
233   elf_backend_symbol_table_processing,
234   elf_backend_section_processing,
235   elf_backend_section_from_shdr,
236   elf_backend_fake_sections,
237   elf_backend_section_from_bfd_section,
238   elf_backend_add_symbol_hook,
239   elf_backend_link_output_symbol_hook,
240   elf_backend_create_dynamic_sections,
241   elf_backend_check_relocs,
242   elf_backend_adjust_dynamic_symbol,
243   elf_backend_size_dynamic_sections,
244   elf_backend_relocate_section,
245   elf_backend_finish_dynamic_symbol,
246   elf_backend_finish_dynamic_sections,
247   elf_backend_begin_write_processing,
248   elf_backend_final_write_processing,
249   elf_backend_ecoff_debug_swap,
250   ELF_MACHINE_ALT1,
251   ELF_MACHINE_ALT2,
252   &_bfd_elfNN_size_info,
253   elf_backend_want_got_plt,
254   elf_backend_plt_readonly,
255   elf_backend_want_plt_sym,
256 };
257
258 #ifdef TARGET_BIG_SYM
259 const bfd_target TARGET_BIG_SYM =
260 {
261   /* name: identify kind of target */
262   TARGET_BIG_NAME,
263
264   /* flavour: general indication about file */
265   bfd_target_elf_flavour,
266
267   /* byteorder_big_p: data is big endian */
268   true,
269
270   /* header_byteorder_big_p: header is also big endian */
271   true,
272
273   /* object_flags: mask of all file flags */
274   (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG | HAS_SYMS | HAS_LOCALS |
275    DYNAMIC | WP_TEXT | D_PAGED),
276   
277   /* section_flags: mask of all section flags */
278   (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_READONLY |
279    SEC_CODE | SEC_DATA | SEC_DEBUGGING),
280
281    /* leading_symbol_char: is the first char of a user symbol
282       predictable, and if so what is it */
283    0,
284
285   /* ar_pad_char: pad character for filenames within an archive header
286      FIXME:  this really has nothing to do with ELF, this is a characteristic
287      of the archiver and/or os and should be independently tunable */
288   '/',
289
290   /* ar_max_namelen: maximum number of characters in an archive header
291      FIXME:  this really has nothing to do with ELF, this is a characteristic
292      of the archiver and should be independently tunable.  This value is
293      a WAG (wild a** guess) */
294   14,
295
296   /* align_power_min: minimum alignment restriction for any section
297      FIXME:  this value may be target machine dependent */
298   3,
299
300   /* Routines to byte-swap various sized integers from the data sections */
301   bfd_getb64, bfd_getb_signed_64, bfd_putb64,
302     bfd_getb32, bfd_getb_signed_32, bfd_putb32,
303     bfd_getb16, bfd_getb_signed_16, bfd_putb16,
304
305   /* Routines to byte-swap various sized integers from the file headers */
306   bfd_getb64, bfd_getb_signed_64, bfd_putb64,
307     bfd_getb32, bfd_getb_signed_32, bfd_putb32,
308     bfd_getb16, bfd_getb_signed_16, bfd_putb16,
309
310   /* bfd_check_format: check the format of a file being read */
311   { _bfd_dummy_target,          /* unknown format */
312     bfd_elfNN_object_p,         /* assembler/linker output (object file) */
313     bfd_generic_archive_p,      /* an archive */
314     bfd_elfNN_core_file_p       /* a core file */
315   },
316
317   /* bfd_set_format: set the format of a file being written */
318   { bfd_false,
319     bfd_elf_mkobject,
320     _bfd_generic_mkarchive,
321     bfd_false
322   },
323
324   /* bfd_write_contents: write cached information into a file being written */
325   { bfd_false,
326     bfd_elfNN_write_object_contents,
327     _bfd_write_archive_contents,
328     bfd_false
329   },
330
331       BFD_JUMP_TABLE_GENERIC (bfd_elfNN),
332       BFD_JUMP_TABLE_COPY (bfd_elfNN),
333       BFD_JUMP_TABLE_CORE (bfd_elfNN),
334       BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),
335       BFD_JUMP_TABLE_SYMBOLS (bfd_elfNN),
336       BFD_JUMP_TABLE_RELOCS (bfd_elfNN),
337       BFD_JUMP_TABLE_WRITE (bfd_elfNN),
338       BFD_JUMP_TABLE_LINK (bfd_elfNN),
339       BFD_JUMP_TABLE_DYNAMIC (bfd_elfNN),
340
341   /* backend_data: */
342   (PTR) &elfNN_bed,
343 };
344 #endif
345
346 #ifdef TARGET_LITTLE_SYM
347 const bfd_target TARGET_LITTLE_SYM =
348 {
349   /* name: identify kind of target */
350   TARGET_LITTLE_NAME,
351
352   /* flavour: general indication about file */
353   bfd_target_elf_flavour,
354
355   /* byteorder_big_p: data is big endian */
356   false,                /* Nope -- this one's little endian */
357
358   /* header_byteorder_big_p: header is also big endian */
359   false,                /* Nope -- this one's little endian */
360
361   /* object_flags: mask of all file flags */
362   (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG | HAS_SYMS | HAS_LOCALS |
363    DYNAMIC | WP_TEXT | D_PAGED),
364   
365   /* section_flags: mask of all section flags */
366   (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_READONLY |
367    SEC_CODE | SEC_DATA | SEC_DEBUGGING),
368
369    /* leading_symbol_char: is the first char of a user symbol
370       predictable, and if so what is it */
371    0,
372
373   /* ar_pad_char: pad character for filenames within an archive header
374      FIXME:  this really has nothing to do with ELF, this is a characteristic
375      of the archiver and/or os and should be independently tunable */
376   '/',
377
378   /* ar_max_namelen: maximum number of characters in an archive header
379      FIXME:  this really has nothing to do with ELF, this is a characteristic
380      of the archiver and should be independently tunable.  This value is
381      a WAG (wild a** guess) */
382   14,
383
384   /* align_power_min: minimum alignment restriction for any section
385      FIXME:  this value may be target machine dependent */
386   3,
387
388   /* Routines to byte-swap various sized integers from the data sections */
389   bfd_getl64, bfd_getl_signed_64, bfd_putl64,
390     bfd_getl32, bfd_getl_signed_32, bfd_putl32,
391     bfd_getl16, bfd_getl_signed_16, bfd_putl16,
392
393   /* Routines to byte-swap various sized integers from the file headers */
394   bfd_getl64, bfd_getl_signed_64, bfd_putl64,
395     bfd_getl32, bfd_getl_signed_32, bfd_putl32,
396     bfd_getl16, bfd_getl_signed_16, bfd_putl16,
397
398   /* bfd_check_format: check the format of a file being read */
399   { _bfd_dummy_target,          /* unknown format */
400     bfd_elfNN_object_p,         /* assembler/linker output (object file) */
401     bfd_generic_archive_p,      /* an archive */
402     bfd_elfNN_core_file_p       /* a core file */
403   },
404
405   /* bfd_set_format: set the format of a file being written */
406   { bfd_false,
407     bfd_elf_mkobject,
408     _bfd_generic_mkarchive,
409     bfd_false
410   },
411
412   /* bfd_write_contents: write cached information into a file being written */
413   { bfd_false,
414     bfd_elfNN_write_object_contents,
415     _bfd_write_archive_contents,
416     bfd_false
417   },
418
419       BFD_JUMP_TABLE_GENERIC (bfd_elfNN),
420       BFD_JUMP_TABLE_COPY (bfd_elfNN),
421       BFD_JUMP_TABLE_CORE (bfd_elfNN),
422       BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),
423       BFD_JUMP_TABLE_SYMBOLS (bfd_elfNN),
424       BFD_JUMP_TABLE_RELOCS (bfd_elfNN),
425       BFD_JUMP_TABLE_WRITE (bfd_elfNN),
426       BFD_JUMP_TABLE_LINK (bfd_elfNN),
427       BFD_JUMP_TABLE_DYNAMIC (bfd_elfNN),
428
429   /* backend_data: */
430   (PTR) &elfNN_bed,
431 };
432 #endif