1 /* Target definitions for NN-bit ELF
2    Copyright 1993, 1994, 1995, 1996 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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_read_minisymbols	_bfd_elf_read_minisymbols
40 #define bfd_elfNN_minisymbol_to_symbol	_bfd_elf_minisymbol_to_symbol
41 #define bfd_elfNN_get_dynamic_symtab_upper_bound _bfd_elf_get_dynamic_symtab_upper_bound
42 #define bfd_elfNN_get_lineno		_bfd_elf_get_lineno
43 #ifndef bfd_elfNN_get_reloc_upper_bound
44 #define bfd_elfNN_get_reloc_upper_bound _bfd_elf_get_reloc_upper_bound
45 #endif
46 #define bfd_elfNN_get_symbol_info	_bfd_elf_get_symbol_info
47 #define bfd_elfNN_get_symtab		_bfd_elf_get_symtab
48 #define bfd_elfNN_get_symtab_upper_bound _bfd_elf_get_symtab_upper_bound
49 #if 0 /* done in elf-bfd.h */
50 #define bfd_elfNN_link_record_dynamic_symbol _bfd_elf_link_record_dynamic_symbol
51 #endif
52 #define bfd_elfNN_make_empty_symbol	_bfd_elf_make_empty_symbol
53 #define bfd_elfNN_new_section_hook	_bfd_elf_new_section_hook
54 #define bfd_elfNN_set_arch_mach		_bfd_elf_set_arch_mach
55 #ifndef bfd_elfNN_set_section_contents
56 #define bfd_elfNN_set_section_contents	_bfd_elf_set_section_contents
57 #endif
58 #define bfd_elfNN_sizeof_headers	_bfd_elf_sizeof_headers
59 #define bfd_elfNN_write_object_contents _bfd_elf_write_object_contents
60 
61 #define bfd_elfNN_get_section_contents_in_window \
62   _bfd_generic_get_section_contents_in_window
63 
64 #ifndef elf_backend_want_got_plt
65 #define elf_backend_want_got_plt 0
66 #endif
67 #ifndef elf_backend_plt_readonly
68 #define elf_backend_plt_readonly 0
69 #endif
70 #ifndef elf_backend_want_plt_sym
71 #define elf_backend_want_plt_sym 0
72 #endif
73 
74 #define bfd_elfNN_bfd_debug_info_start	bfd_void
75 #define bfd_elfNN_bfd_debug_info_end	bfd_void
76 #define bfd_elfNN_bfd_debug_info_accumulate	(PROTO(void,(*),(bfd*, struct sec *))) bfd_void
77 
78 #ifndef bfd_elfNN_bfd_get_relocated_section_contents
79 #define bfd_elfNN_bfd_get_relocated_section_contents \
80  bfd_generic_get_relocated_section_contents
81 #endif
82 
83 #ifndef bfd_elfNN_bfd_relax_section
84 #define bfd_elfNN_bfd_relax_section bfd_generic_relax_section
85 #endif
86 
87 #define bfd_elfNN_bfd_make_debug_symbol \
88   ((asymbol *(*) PARAMS ((bfd *, void *, unsigned long))) bfd_nullvoidptr)
89 
90 #ifndef bfd_elfNN_bfd_copy_private_symbol_data
91 #define bfd_elfNN_bfd_copy_private_symbol_data \
92   _bfd_elf_copy_private_symbol_data
93 #endif
94 
95 #ifndef bfd_elfNN_bfd_copy_private_section_data
96 #define bfd_elfNN_bfd_copy_private_section_data \
97   _bfd_elf_copy_private_section_data
98 #endif
99 #ifndef bfd_elfNN_bfd_copy_private_bfd_data
100 #define bfd_elfNN_bfd_copy_private_bfd_data \
101   ((boolean (*) PARAMS ((bfd *, bfd *))) bfd_true)
102 #endif
103 #ifndef bfd_elfNN_bfd_print_private_bfd_data
104 #define bfd_elfNN_bfd_print_private_bfd_data \
105   _bfd_elf_print_private_bfd_data
106 #endif
107 #ifndef bfd_elfNN_bfd_merge_private_bfd_data
108 #define bfd_elfNN_bfd_merge_private_bfd_data \
109   ((boolean (*) PARAMS ((bfd *, bfd *))) bfd_true)
110 #endif
111 #ifndef bfd_elfNN_bfd_set_private_flags
112 #define bfd_elfNN_bfd_set_private_flags \
113   ((boolean (*) PARAMS ((bfd *, flagword))) bfd_true)
114 #endif
115 #ifndef bfd_elfNN_bfd_is_local_label
116 #define bfd_elfNN_bfd_is_local_label bfd_generic_is_local_label
117 #endif
118 
119 #ifndef bfd_elfNN_get_dynamic_reloc_upper_bound
120 #define bfd_elfNN_get_dynamic_reloc_upper_bound \
121   _bfd_nodynamic_get_dynamic_reloc_upper_bound
122 #endif
123 #ifndef bfd_elfNN_canonicalize_dynamic_reloc
124 #define bfd_elfNN_canonicalize_dynamic_reloc \
125   _bfd_nodynamic_canonicalize_dynamic_reloc
126 #endif
127 
128 #ifdef elf_backend_relocate_section
129 #ifndef bfd_elfNN_bfd_link_hash_table_create
130 #define bfd_elfNN_bfd_link_hash_table_create _bfd_elf_link_hash_table_create
131 #endif
132 #else /* ! defined (elf_backend_relocate_section) */
133 /* If no backend relocate_section routine, use the generic linker.  */
134 #ifndef bfd_elfNN_bfd_link_hash_table_create
135 #define bfd_elfNN_bfd_link_hash_table_create \
136   _bfd_generic_link_hash_table_create
137 #endif
138 #ifndef bfd_elfNN_bfd_link_add_symbols
139 #define bfd_elfNN_bfd_link_add_symbols	_bfd_generic_link_add_symbols
140 #endif
141 #ifndef bfd_elfNN_bfd_final_link
142 #define bfd_elfNN_bfd_final_link	_bfd_generic_final_link
143 #endif
144 #endif /* ! defined (elf_backend_relocate_section) */
145 #ifndef bfd_elfNN_bfd_link_split_section
146 #define bfd_elfNN_bfd_link_split_section _bfd_generic_link_split_section
147 #endif
148 
149 #ifndef bfd_elfNN_archive_p
150 #define bfd_elfNN_archive_p bfd_generic_archive_p
151 #endif
152 
153 #ifndef bfd_elfNN_write_archive_contents
154 #define bfd_elfNN_write_archive_contents _bfd_write_archive_contents
155 #endif
156 
157 #ifndef bfd_elfNN_mkarchive
158 #define bfd_elfNN_mkarchive _bfd_generic_mkarchive
159 #endif
160 
161 #ifndef elf_symbol_leading_char
162 #define elf_symbol_leading_char 0
163 #endif
164 
165 #ifndef elf_info_to_howto
166 #define elf_info_to_howto 0
167 #endif
168 
169 #ifndef elf_info_to_howto_rel
170 #define elf_info_to_howto_rel 0
171 #endif
172 
173 #ifndef ELF_MAXPAGESIZE
174 #define ELF_MAXPAGESIZE 1
175 #endif
176 
177 #ifndef elf_backend_collect
178 #define elf_backend_collect false
179 #endif
180 #ifndef elf_backend_type_change_ok
181 #define elf_backend_type_change_ok false
182 #endif
183 
184 #ifndef elf_backend_sym_is_global
185 #define elf_backend_sym_is_global	0
186 #endif
187 #ifndef elf_backend_object_p
188 #define elf_backend_object_p		0
189 #endif
190 #ifndef elf_backend_symbol_processing
191 #define elf_backend_symbol_processing	0
192 #endif
193 #ifndef elf_backend_symbol_table_processing
194 #define elf_backend_symbol_table_processing	0
195 #endif
196 #ifndef elf_backend_section_processing
197 #define elf_backend_section_processing	0
198 #endif
199 #ifndef elf_backend_section_from_shdr
200 #define elf_backend_section_from_shdr	0
201 #endif
202 #ifndef elf_backend_fake_sections
203 #define elf_backend_fake_sections	0
204 #endif
205 #ifndef elf_backend_section_from_bfd_section
206 #define elf_backend_section_from_bfd_section	0
207 #endif
208 #ifndef elf_backend_add_symbol_hook
209 #define elf_backend_add_symbol_hook	0
210 #endif
211 #ifndef elf_backend_link_output_symbol_hook
212 #define elf_backend_link_output_symbol_hook 0
213 #endif
214 #ifndef elf_backend_create_dynamic_sections
215 #define elf_backend_create_dynamic_sections 0
216 #endif
217 #ifndef elf_backend_check_relocs
218 #define elf_backend_check_relocs	0
219 #endif
220 #ifndef elf_backend_adjust_dynamic_symbol
221 #define elf_backend_adjust_dynamic_symbol 0
222 #endif
223 #ifndef elf_backend_size_dynamic_sections
224 #define elf_backend_size_dynamic_sections 0
225 #endif
226 #ifndef elf_backend_relocate_section
227 #define elf_backend_relocate_section	0
228 #endif
229 #ifndef elf_backend_finish_dynamic_symbol
230 #define elf_backend_finish_dynamic_symbol	0
231 #endif
232 #ifndef elf_backend_finish_dynamic_sections
233 #define elf_backend_finish_dynamic_sections	0
234 #endif
235 #ifndef elf_backend_begin_write_processing
236 #define elf_backend_begin_write_processing	0
237 #endif
238 #ifndef elf_backend_final_write_processing
239 #define elf_backend_final_write_processing	0
240 #endif
241 #ifndef elf_backend_additional_program_headers
242 #define elf_backend_additional_program_headers	0
243 #endif
244 #ifndef elf_backend_modify_segment_map
245 #define elf_backend_modify_segment_map	0
246 #endif
247 #ifndef elf_backend_ecoff_debug_swap
248 #define elf_backend_ecoff_debug_swap	0
249 #endif
250 
251 #ifndef ELF_MACHINE_ALT1
252 #define ELF_MACHINE_ALT1 0
253 #endif
254 
255 #ifndef ELF_MACHINE_ALT2
256 #define ELF_MACHINE_ALT2 0
257 #endif
258 
259 #ifndef elf_backend_size_info
260 #define elf_backend_size_info _bfd_elfNN_size_info
261 #endif
262 
263 extern const struct elf_size_info _bfd_elfNN_size_info;
264 
265 static CONST struct elf_backend_data elfNN_bed =
266 {
267 #ifdef USE_REL
268   0,				/* use_rela_p */
269 #else
270   1,				/* use_rela_p */
271 #endif
272   ELF_ARCH,			/* arch */
273   ELF_MACHINE_CODE,		/* elf_machine_code */
274   ELF_MAXPAGESIZE,		/* maxpagesize */
275   elf_backend_collect,
276   elf_backend_type_change_ok,
277   elf_info_to_howto,
278   elf_info_to_howto_rel,
279   elf_backend_sym_is_global,
280   elf_backend_object_p,
281   elf_backend_symbol_processing,
282   elf_backend_symbol_table_processing,
283   elf_backend_section_processing,
284   elf_backend_section_from_shdr,
285   elf_backend_fake_sections,
286   elf_backend_section_from_bfd_section,
287   elf_backend_add_symbol_hook,
288   elf_backend_link_output_symbol_hook,
289   elf_backend_create_dynamic_sections,
290   elf_backend_check_relocs,
291   elf_backend_adjust_dynamic_symbol,
292   elf_backend_size_dynamic_sections,
293   elf_backend_relocate_section,
294   elf_backend_finish_dynamic_symbol,
295   elf_backend_finish_dynamic_sections,
296   elf_backend_begin_write_processing,
297   elf_backend_final_write_processing,
298   elf_backend_additional_program_headers,
299   elf_backend_modify_segment_map,
300   elf_backend_ecoff_debug_swap,
301   ELF_MACHINE_ALT1,
302   ELF_MACHINE_ALT2,
303   &elf_backend_size_info,
304   elf_backend_want_got_plt,
305   elf_backend_plt_readonly,
306   elf_backend_want_plt_sym
307 };
308 
309 #ifdef TARGET_BIG_SYM
310 const bfd_target TARGET_BIG_SYM =
311 {
312   /* name: identify kind of target */
313   TARGET_BIG_NAME,
314 
315   /* flavour: general indication about file */
316   bfd_target_elf_flavour,
317 
318   /* byteorder: data is big endian */
319   BFD_ENDIAN_BIG,
320 
321   /* header_byteorder: header is also big endian */
322   BFD_ENDIAN_BIG,
323 
324   /* object_flags: mask of all file flags */
325   (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG | HAS_SYMS | HAS_LOCALS |
326    DYNAMIC | WP_TEXT | D_PAGED),
327 
328   /* section_flags: mask of all section flags */
329   (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_READONLY |
330    SEC_CODE | SEC_DATA | SEC_DEBUGGING | SEC_EXCLUDE | SEC_SORT_ENTRIES),
331 
332    /* leading_symbol_char: is the first char of a user symbol
333       predictable, and if so what is it */
334   elf_symbol_leading_char,
335 
336   /* ar_pad_char: pad character for filenames within an archive header
337      FIXME:  this really has nothing to do with ELF, this is a characteristic
338      of the archiver and/or os and should be independently tunable */
339   '/',
340 
341   /* ar_max_namelen: maximum number of characters in an archive header
342      FIXME:  this really has nothing to do with ELF, this is a characteristic
343      of the archiver and should be independently tunable.  This value is
344      a WAG (wild a** guess) */
345   14,
346 
347   /* Routines to byte-swap various sized integers from the data sections */
348   bfd_getb64, bfd_getb_signed_64, bfd_putb64,
349     bfd_getb32, bfd_getb_signed_32, bfd_putb32,
350     bfd_getb16, bfd_getb_signed_16, bfd_putb16,
351 
352   /* Routines to byte-swap various sized integers from the file headers */
353   bfd_getb64, bfd_getb_signed_64, bfd_putb64,
354     bfd_getb32, bfd_getb_signed_32, bfd_putb32,
355     bfd_getb16, bfd_getb_signed_16, bfd_putb16,
356 
357   /* bfd_check_format: check the format of a file being read */
358   { _bfd_dummy_target,		/* unknown format */
359     bfd_elfNN_object_p,		/* assembler/linker output (object file) */
360     bfd_elfNN_archive_p,	/* an archive */
361     bfd_elfNN_core_file_p	/* a core file */
362   },
363 
364   /* bfd_set_format: set the format of a file being written */
365   { bfd_false,
366     bfd_elf_mkobject,
367     bfd_elfNN_mkarchive,
368     bfd_false
369   },
370 
371   /* bfd_write_contents: write cached information into a file being written */
372   { bfd_false,
373     bfd_elfNN_write_object_contents,
374     bfd_elfNN_write_archive_contents,
375     bfd_false
376   },
377 
378       BFD_JUMP_TABLE_GENERIC (bfd_elfNN),
379       BFD_JUMP_TABLE_COPY (bfd_elfNN),
380       BFD_JUMP_TABLE_CORE (bfd_elfNN),
381 #ifdef bfd_elfNN_archive_functions
382       BFD_JUMP_TABLE_ARCHIVE (bfd_elfNN_archive),
383 #else
384       BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),
385 #endif
386       BFD_JUMP_TABLE_SYMBOLS (bfd_elfNN),
387       BFD_JUMP_TABLE_RELOCS (bfd_elfNN),
388       BFD_JUMP_TABLE_WRITE (bfd_elfNN),
389       BFD_JUMP_TABLE_LINK (bfd_elfNN),
390       BFD_JUMP_TABLE_DYNAMIC (bfd_elfNN),
391 
392   /* backend_data: */
393   (PTR) &elfNN_bed,
394 };
395 #endif
396 
397 #ifdef TARGET_LITTLE_SYM
398 const bfd_target TARGET_LITTLE_SYM =
399 {
400   /* name: identify kind of target */
401   TARGET_LITTLE_NAME,
402 
403   /* flavour: general indication about file */
404   bfd_target_elf_flavour,
405 
406   /* byteorder: data is little endian */
407   BFD_ENDIAN_LITTLE,
408 
409   /* header_byteorder: header is also little endian */
410   BFD_ENDIAN_LITTLE,
411 
412   /* object_flags: mask of all file flags */
413   (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG | HAS_SYMS | HAS_LOCALS |
414    DYNAMIC | WP_TEXT | D_PAGED),
415 
416   /* section_flags: mask of all section flags */
417   (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_READONLY |
418    SEC_CODE | SEC_DATA | SEC_DEBUGGING | SEC_EXCLUDE | SEC_SORT_ENTRIES),
419 
420    /* leading_symbol_char: is the first char of a user symbol
421       predictable, and if so what is it */
422   elf_symbol_leading_char,
423 
424   /* ar_pad_char: pad character for filenames within an archive header
425      FIXME:  this really has nothing to do with ELF, this is a characteristic
426      of the archiver and/or os and should be independently tunable */
427   '/',
428 
429   /* ar_max_namelen: maximum number of characters in an archive header
430      FIXME:  this really has nothing to do with ELF, this is a characteristic
431      of the archiver and should be independently tunable.  This value is
432      a WAG (wild a** guess) */
433   14,
434 
435   /* Routines to byte-swap various sized integers from the data sections */
436   bfd_getl64, bfd_getl_signed_64, bfd_putl64,
437     bfd_getl32, bfd_getl_signed_32, bfd_putl32,
438     bfd_getl16, bfd_getl_signed_16, bfd_putl16,
439 
440   /* Routines to byte-swap various sized integers from the file headers */
441   bfd_getl64, bfd_getl_signed_64, bfd_putl64,
442     bfd_getl32, bfd_getl_signed_32, bfd_putl32,
443     bfd_getl16, bfd_getl_signed_16, bfd_putl16,
444 
445   /* bfd_check_format: check the format of a file being read */
446   { _bfd_dummy_target,		/* unknown format */
447     bfd_elfNN_object_p,		/* assembler/linker output (object file) */
448     bfd_elfNN_archive_p,	/* an archive */
449     bfd_elfNN_core_file_p	/* a core file */
450   },
451 
452   /* bfd_set_format: set the format of a file being written */
453   { bfd_false,
454     bfd_elf_mkobject,
455     bfd_elfNN_mkarchive,
456     bfd_false
457   },
458 
459   /* bfd_write_contents: write cached information into a file being written */
460   { bfd_false,
461     bfd_elfNN_write_object_contents,
462     bfd_elfNN_write_archive_contents,
463     bfd_false
464   },
465 
466       BFD_JUMP_TABLE_GENERIC (bfd_elfNN),
467       BFD_JUMP_TABLE_COPY (bfd_elfNN),
468       BFD_JUMP_TABLE_CORE (bfd_elfNN),
469 #ifdef bfd_elfNN_archive_functions
470       BFD_JUMP_TABLE_ARCHIVE (bfd_elfNN_archive),
471 #else
472       BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),
473 #endif
474       BFD_JUMP_TABLE_SYMBOLS (bfd_elfNN),
475       BFD_JUMP_TABLE_RELOCS (bfd_elfNN),
476       BFD_JUMP_TABLE_WRITE (bfd_elfNN),
477       BFD_JUMP_TABLE_LINK (bfd_elfNN),
478       BFD_JUMP_TABLE_DYNAMIC (bfd_elfNN),
479 
480   /* backend_data: */
481   (PTR) &elfNN_bed,
482 };
483 #endif
484