1 /* Define a target vector and some small routines for a variant of a.out.
2 Copyright (C) 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
4 This file is part of BFD, the Binary File Descriptor library.
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.
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.
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. */
20 #include "aout/aout64.h"
21 #include "aout/stab_gnu.h"
23 /*#include "libaout.h"*/
25 extern CONST struct reloc_howto_struct * NAME(aout,reloc_type_lookup) ();
27 /* Set parameters about this a.out file that are machine-dependent.
28 This routine is called from some_aout_object_p just before it returns. */
30 static const bfd_target *
34 struct internal_exec *execp = exec_hdr (abfd);
35 unsigned int arch_align_power;
36 unsigned long arch_align;
38 /* Calculate the file positions of the parts of a newly read aout header */
39 obj_textsec (abfd)->_raw_size = N_TXTSIZE(*execp);
41 /* The virtual memory addresses of the sections */
42 obj_textsec (abfd)->vma = N_TXTADDR(*execp);
43 obj_datasec (abfd)->vma = N_DATADDR(*execp);
44 obj_bsssec (abfd)->vma = N_BSSADDR(*execp);
46 /* The file offsets of the sections */
47 obj_textsec (abfd)->filepos = N_TXTOFF (*execp);
48 obj_datasec (abfd)->filepos = N_DATOFF (*execp);
50 /* The file offsets of the relocation info */
51 obj_textsec (abfd)->rel_filepos = N_TRELOFF(*execp);
52 obj_datasec (abfd)->rel_filepos = N_DRELOFF(*execp);
54 /* The file offsets of the string table and symbol table. */
55 obj_sym_filepos (abfd) = N_SYMOFF (*execp);
56 obj_str_filepos (abfd) = N_STROFF (*execp);
58 /* Determine the architecture and machine type of the object file. */
60 SET_ARCH_MACH(abfd, *execp);
62 bfd_default_set_arch_mach(abfd, DEFAULT_ARCH, 0);
65 /* Now that we know the architecture, set the alignments of the
66 sections. This is normally done by NAME(aout,new_section_hook),
67 but when the initial sections were created the architecture had
68 not yet been set. However, for backward compatibility, we don't
69 set the alignment power any higher than as required by the size
71 arch_align_power = bfd_get_arch_info (abfd)->section_align_power;
72 arch_align = 1 << arch_align_power;
73 if ((BFD_ALIGN (obj_textsec (abfd)->_raw_size, arch_align)
74 == obj_textsec (abfd)->_raw_size)
75 && (BFD_ALIGN (obj_datasec (abfd)->_raw_size, arch_align)
76 == obj_datasec (abfd)->_raw_size)
77 && (BFD_ALIGN (obj_bsssec (abfd)->_raw_size, arch_align)
78 == obj_bsssec (abfd)->_raw_size))
80 obj_textsec (abfd)->alignment_power = arch_align_power;
81 obj_datasec (abfd)->alignment_power = arch_align_power;
82 obj_bsssec (abfd)->alignment_power = arch_align_power;
85 /* Don't set sizes now -- can't be sure until we know arch & mach.
86 Sizes get set in set_sizes callback, later. */
88 adata(abfd).page_size = PAGE_SIZE;
90 adata(abfd).segment_size = SEGMENT_SIZE;
92 adata(abfd).segment_size = PAGE_SIZE;
94 adata(abfd).exec_bytes_size = EXEC_BYTES_SIZE;
102 /* Finish up the reading of an a.out file header */
104 static const bfd_target *
108 struct external_exec exec_bytes; /* Raw exec header from file */
109 struct internal_exec exec; /* Cleaned-up exec header */
110 const bfd_target *target;
112 if (bfd_read ((PTR) &exec_bytes, 1, EXEC_BYTES_SIZE, abfd)
113 != EXEC_BYTES_SIZE) {
114 if (bfd_get_error () != bfd_error_system_call)
115 bfd_set_error (bfd_error_wrong_format);
120 exec.a_info = SWAP_MAGIC (exec_bytes.e_info);
122 exec.a_info = bfd_h_get_32 (abfd, exec_bytes.e_info);
123 #endif /* SWAP_MAGIC */
125 if (N_BADMAG (exec)) return 0;
127 if (!(MACHTYPE_OK (N_MACHTYPE (exec)))) return 0;
130 NAME(aout,swap_exec_header_in)(abfd, &exec_bytes, &exec);
133 /* swap_exec_header_in read in a_info with the wrong byte order */
134 exec.a_info = SWAP_MAGIC (exec_bytes.e_info);
135 #endif /* SWAP_MAGIC */
137 target = NAME(aout,some_aout_object_p) (abfd, &exec, MY(callback));
139 #ifdef ENTRY_CAN_BE_ZERO
140 /* The NEWSOS3 entry-point is/was 0, which (amongst other lossage)
141 * means that it isn't obvious if EXEC_P should be set.
142 * All of the following must be true for an executable:
143 * There must be no relocations, the bfd can be neither an
144 * archive nor an archive element, and the file must be executable. */
146 if (exec.a_trsize + exec.a_drsize == 0
147 && bfd_get_format(abfd) == bfd_object && abfd->my_archive == NULL)
151 #define S_IXUSR 0100 /* Execute by owner. */
153 if (stat(abfd->filename, &buf) == 0 && (buf.st_mode & S_IXUSR))
154 abfd->flags |= EXEC_P;
156 #endif /* ENTRY_CAN_BE_ZERO */
160 #define MY_object_p MY(object_p)
169 if (NAME(aout,mkobject)(abfd) == false)
171 #if 0 /* Sizes get set in set_sizes callback, later, after we know
172 the architecture and machine. */
173 adata(abfd).page_size = PAGE_SIZE;
175 adata(abfd).segment_size = SEGMENT_SIZE;
177 adata(abfd).segment_size = PAGE_SIZE;
179 adata(abfd).exec_bytes_size = EXEC_BYTES_SIZE;
183 #define MY_mkobject MY(mkobject)
186 #ifndef MY_bfd_copy_private_section_data
188 /* Copy private section data. This actually does nothing with the
189 sections. It copies the subformat field. We copy it here, because
190 we need to know whether this is a QMAGIC file before we set the
191 section contents, and copy_private_bfd_data is not called until
192 after the section contents have been set. */
196 MY_bfd_copy_private_section_data (ibfd, isec, obfd, osec)
202 obj_aout_subformat (obfd) = obj_aout_subformat (ibfd);
208 /* Write an object file.
209 Section contents have already been written. We write the
210 file header, symbols, and relocation. */
212 #ifndef MY_write_object_contents
214 MY(write_object_contents) (abfd)
217 struct external_exec exec_bytes;
218 struct internal_exec *execp = exec_hdr (abfd);
220 #if CHOOSE_RELOC_SIZE
221 CHOOSE_RELOC_SIZE(abfd);
223 obj_reloc_entry_size (abfd) = RELOC_STD_SIZE;
226 WRITE_HEADERS(abfd, execp);
230 #define MY_write_object_contents MY(write_object_contents)
238 adata(abfd).page_size = PAGE_SIZE;
241 adata(abfd).segment_size = SEGMENT_SIZE;
243 adata(abfd).segment_size = PAGE_SIZE;
246 #ifdef ZMAGIC_DISK_BLOCK_SIZE
247 adata(abfd).zmagic_disk_block_size = ZMAGIC_DISK_BLOCK_SIZE;
249 adata(abfd).zmagic_disk_block_size = PAGE_SIZE;
252 adata(abfd).exec_bytes_size = EXEC_BYTES_SIZE;
255 #define MY_set_sizes MY(set_sizes)
258 #ifndef MY_exec_hdr_flags
259 #define MY_exec_hdr_flags 0
262 #ifndef MY_backend_data
264 #ifndef MY_zmagic_contiguous
265 #define MY_zmagic_contiguous 0
267 #ifndef MY_text_includes_header
268 #define MY_text_includes_header 0
270 #ifndef MY_add_dynamic_symbols
271 #define MY_add_dynamic_symbols 0
273 #ifndef MY_add_one_symbol
274 #define MY_add_one_symbol 0
276 #ifndef MY_link_dynamic_object
277 #define MY_link_dynamic_object 0
279 #ifndef MY_write_dynamic_symbol
280 #define MY_write_dynamic_symbol 0
282 #ifndef MY_check_dynamic_reloc
283 #define MY_check_dynamic_reloc 0
285 #ifndef MY_finish_dynamic_link
286 #define MY_finish_dynamic_link 0
289 static CONST struct aout_backend_data MY(backend_data) = {
290 MY_zmagic_contiguous,
291 MY_text_includes_header,
295 0, /* exec header is counted */
296 MY_add_dynamic_symbols,
298 MY_link_dynamic_object,
299 MY_write_dynamic_symbol,
300 MY_check_dynamic_reloc,
301 MY_finish_dynamic_link
303 #define MY_backend_data &MY(backend_data)
306 #ifndef MY_final_link_callback
308 /* Callback for the final_link routine to set the section offsets. */
310 static void MY_final_link_callback
311 PARAMS ((bfd *, file_ptr *, file_ptr *, file_ptr *));
314 MY_final_link_callback (abfd, ptreloff, pdreloff, psymoff)
320 struct internal_exec *execp = exec_hdr (abfd);
322 *ptreloff = N_TRELOFF (*execp);
323 *pdreloff = N_DRELOFF (*execp);
324 *psymoff = N_SYMOFF (*execp);
329 #ifndef MY_bfd_final_link
331 /* Final link routine. We need to use a call back to get the correct
332 offsets in the output file. */
335 MY_bfd_final_link (abfd, info)
337 struct bfd_link_info *info;
339 return NAME(aout,final_link) (abfd, info, MY_final_link_callback);
344 /* We assume BFD generic archive files. */
345 #ifndef MY_openr_next_archived_file
346 #define MY_openr_next_archived_file bfd_generic_openr_next_archived_file
348 #ifndef MY_generic_stat_arch_elt
349 #define MY_generic_stat_arch_elt bfd_generic_stat_arch_elt
351 #ifndef MY_slurp_armap
352 #define MY_slurp_armap bfd_slurp_bsd_armap
354 #ifndef MY_slurp_extended_name_table
355 #define MY_slurp_extended_name_table _bfd_slurp_extended_name_table
357 #ifndef MY_write_armap
358 #define MY_write_armap bsd_write_armap
360 #ifndef MY_truncate_arname
361 #define MY_truncate_arname bfd_bsd_truncate_arname
364 /* No core file defined here -- configure in trad-core.c separately. */
365 #ifndef MY_core_file_failing_command
366 #define MY_core_file_failing_command _bfd_nocore_core_file_failing_command
368 #ifndef MY_core_file_failing_signal
369 #define MY_core_file_failing_signal _bfd_nocore_core_file_failing_signal
371 #ifndef MY_core_file_matches_executable_p
372 #define MY_core_file_matches_executable_p \
373 _bfd_nocore_core_file_matches_executable_p
375 #ifndef MY_core_file_p
376 #define MY_core_file_p _bfd_dummy_target
379 #ifndef MY_bfd_debug_info_start
380 #define MY_bfd_debug_info_start bfd_void
382 #ifndef MY_bfd_debug_info_end
383 #define MY_bfd_debug_info_end bfd_void
385 #ifndef MY_bfd_debug_info_accumulate
386 #define MY_bfd_debug_info_accumulate \
387 (void (*) PARAMS ((bfd*, struct sec *))) bfd_void
390 #ifndef MY_core_file_failing_command
391 #define MY_core_file_failing_command NAME(aout,core_file_failing_command)
393 #ifndef MY_core_file_failing_signal
394 #define MY_core_file_failing_signal NAME(aout,core_file_failing_signal)
396 #ifndef MY_core_file_matches_executable_p
397 #define MY_core_file_matches_executable_p NAME(aout,core_file_matches_executable_p)
399 #ifndef MY_set_section_contents
400 #define MY_set_section_contents NAME(aout,set_section_contents)
402 #ifndef MY_get_section_contents
403 #define MY_get_section_contents NAME(aout,get_section_contents)
405 #ifndef MY_new_section_hook
406 #define MY_new_section_hook NAME(aout,new_section_hook)
408 #ifndef MY_get_symtab_upper_bound
409 #define MY_get_symtab_upper_bound NAME(aout,get_symtab_upper_bound)
411 #ifndef MY_get_symtab
412 #define MY_get_symtab NAME(aout,get_symtab)
414 #ifndef MY_get_reloc_upper_bound
415 #define MY_get_reloc_upper_bound NAME(aout,get_reloc_upper_bound)
417 #ifndef MY_canonicalize_reloc
418 #define MY_canonicalize_reloc NAME(aout,canonicalize_reloc)
420 #ifndef MY_make_empty_symbol
421 #define MY_make_empty_symbol NAME(aout,make_empty_symbol)
423 #ifndef MY_print_symbol
424 #define MY_print_symbol NAME(aout,print_symbol)
426 #ifndef MY_get_symbol_info
427 #define MY_get_symbol_info NAME(aout,get_symbol_info)
429 #ifndef MY_get_lineno
430 #define MY_get_lineno NAME(aout,get_lineno)
432 #ifndef MY_set_arch_mach
433 #define MY_set_arch_mach NAME(aout,set_arch_mach)
435 #ifndef MY_find_nearest_line
436 #define MY_find_nearest_line NAME(aout,find_nearest_line)
438 #ifndef MY_sizeof_headers
439 #define MY_sizeof_headers NAME(aout,sizeof_headers)
441 #ifndef MY_bfd_get_relocated_section_contents
442 #define MY_bfd_get_relocated_section_contents \
443 bfd_generic_get_relocated_section_contents
445 #ifndef MY_bfd_relax_section
446 #define MY_bfd_relax_section bfd_generic_relax_section
448 #ifndef MY_bfd_reloc_type_lookup
449 #define MY_bfd_reloc_type_lookup NAME(aout,reloc_type_lookup)
451 #ifndef MY_bfd_make_debug_symbol
452 #define MY_bfd_make_debug_symbol 0
454 #ifndef MY_bfd_link_hash_table_create
455 #define MY_bfd_link_hash_table_create NAME(aout,link_hash_table_create)
457 #ifndef MY_bfd_link_add_symbols
458 #define MY_bfd_link_add_symbols NAME(aout,link_add_symbols)
461 #ifndef MY_bfd_copy_private_bfd_data
462 #define MY_bfd_copy_private_bfd_data _bfd_generic_bfd_copy_private_bfd_data
465 #ifndef MY_bfd_is_local_label
466 #define MY_bfd_is_local_label bfd_generic_is_local_label
469 #ifndef MY_bfd_free_cached_info
470 #define MY_bfd_free_cached_info NAME(aout,bfd_free_cached_info)
473 #ifndef MY_close_and_cleanup
474 #define MY_close_and_cleanup MY_bfd_free_cached_info
477 #ifndef MY_get_dynamic_symtab_upper_bound
478 #define MY_get_dynamic_symtab_upper_bound \
479 _bfd_nodynamic_get_dynamic_symtab_upper_bound
481 #ifndef MY_canonicalize_dynamic_symtab
482 #define MY_canonicalize_dynamic_symtab \
483 _bfd_nodynamic_canonicalize_dynamic_symtab
485 #ifndef MY_get_dynamic_reloc_upper_bound
486 #define MY_get_dynamic_reloc_upper_bound \
487 _bfd_nodynamic_get_dynamic_reloc_upper_bound
489 #ifndef MY_canonicalize_dynamic_reloc
490 #define MY_canonicalize_dynamic_reloc \
491 _bfd_nodynamic_canonicalize_dynamic_reloc
494 /* Aout symbols normally have leading underscores */
495 #ifndef MY_symbol_leading_char
496 #define MY_symbol_leading_char '_'
499 /* Aout archives normally use spaces for padding */
501 #define AR_PAD_CHAR ' '
504 #ifndef MY_BFD_TARGET
505 const bfd_target MY(vec) =
507 TARGETNAME, /* name */
508 bfd_target_aout_flavour,
509 #ifdef TARGET_IS_BIG_ENDIAN_P
510 true, /* target byte order (big) */
511 true, /* target headers byte order (big) */
513 false, /* target byte order (little) */
514 false, /* target headers byte order (little) */
516 (HAS_RELOC | EXEC_P | /* object flags */
517 HAS_LINENO | HAS_DEBUG |
518 HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED),
519 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
520 MY_symbol_leading_char,
521 AR_PAD_CHAR, /* ar_pad_char */
522 15, /* ar_max_namelen */
523 3, /* minimum alignment */
524 #ifdef TARGET_IS_BIG_ENDIAN_P
525 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
526 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
527 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* data */
528 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
529 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
530 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* hdrs */
532 bfd_getl64, bfd_getl_signed_64, bfd_putl64,
533 bfd_getl32, bfd_getl_signed_32, bfd_putl32,
534 bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */
535 bfd_getl64, bfd_getl_signed_64, bfd_putl64,
536 bfd_getl32, bfd_getl_signed_32, bfd_putl32,
537 bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* hdrs */
539 {_bfd_dummy_target, MY_object_p, /* bfd_check_format */
540 bfd_generic_archive_p, MY_core_file_p},
541 {bfd_false, MY_mkobject, /* bfd_set_format */
542 _bfd_generic_mkarchive, bfd_false},
543 {bfd_false, MY_write_object_contents, /* bfd_write_contents */
544 _bfd_write_archive_contents, bfd_false},
546 BFD_JUMP_TABLE_GENERIC (MY),
547 BFD_JUMP_TABLE_COPY (MY),
548 BFD_JUMP_TABLE_CORE (MY),
549 BFD_JUMP_TABLE_ARCHIVE (MY),
550 BFD_JUMP_TABLE_SYMBOLS (MY),
551 BFD_JUMP_TABLE_RELOCS (MY),
552 BFD_JUMP_TABLE_WRITE (MY),
553 BFD_JUMP_TABLE_LINK (MY),
554 BFD_JUMP_TABLE_DYNAMIC (MY),
556 (PTR) MY_backend_data,
558 #endif /* MY_BFD_TARGET */