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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20 #include "aout/aout64.h"
21 #include "aout/stab_gnu.h"
23 /*#include "libaout.h"*/
25 extern reloc_howto_type * 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 obj_textsec (abfd)->lma = obj_textsec (abfd)->vma;
47 obj_datasec (abfd)->lma = obj_datasec (abfd)->vma;
48 obj_bsssec (abfd)->lma = obj_bsssec (abfd)->vma;
50 /* The file offsets of the sections */
51 obj_textsec (abfd)->filepos = N_TXTOFF (*execp);
52 obj_datasec (abfd)->filepos = N_DATOFF (*execp);
54 /* The file offsets of the relocation info */
55 obj_textsec (abfd)->rel_filepos = N_TRELOFF(*execp);
56 obj_datasec (abfd)->rel_filepos = N_DRELOFF(*execp);
58 /* The file offsets of the string table and symbol table. */
59 obj_sym_filepos (abfd) = N_SYMOFF (*execp);
60 obj_str_filepos (abfd) = N_STROFF (*execp);
62 /* Determine the architecture and machine type of the object file. */
64 SET_ARCH_MACH(abfd, *execp);
66 bfd_default_set_arch_mach(abfd, DEFAULT_ARCH, 0);
69 /* Now that we know the architecture, set the alignments of the
70 sections. This is normally done by NAME(aout,new_section_hook),
71 but when the initial sections were created the architecture had
72 not yet been set. However, for backward compatibility, we don't
73 set the alignment power any higher than as required by the size
75 arch_align_power = bfd_get_arch_info (abfd)->section_align_power;
76 arch_align = 1 << arch_align_power;
77 if ((BFD_ALIGN (obj_textsec (abfd)->_raw_size, arch_align)
78 == obj_textsec (abfd)->_raw_size)
79 && (BFD_ALIGN (obj_datasec (abfd)->_raw_size, arch_align)
80 == obj_datasec (abfd)->_raw_size)
81 && (BFD_ALIGN (obj_bsssec (abfd)->_raw_size, arch_align)
82 == obj_bsssec (abfd)->_raw_size))
84 obj_textsec (abfd)->alignment_power = arch_align_power;
85 obj_datasec (abfd)->alignment_power = arch_align_power;
86 obj_bsssec (abfd)->alignment_power = arch_align_power;
89 /* Don't set sizes now -- can't be sure until we know arch & mach.
90 Sizes get set in set_sizes callback, later. */
92 adata(abfd).page_size = TARGET_PAGE_SIZE;
94 adata(abfd).segment_size = SEGMENT_SIZE;
96 adata(abfd).segment_size = TARGET_PAGE_SIZE;
98 adata(abfd).exec_bytes_size = EXEC_BYTES_SIZE;
106 /* Finish up the reading of an a.out file header */
108 static const bfd_target *
112 struct external_exec exec_bytes; /* Raw exec header from file */
113 struct internal_exec exec; /* Cleaned-up exec header */
114 const bfd_target *target;
116 if (bfd_read ((PTR) &exec_bytes, 1, EXEC_BYTES_SIZE, abfd)
117 != EXEC_BYTES_SIZE) {
118 if (bfd_get_error () != bfd_error_system_call)
119 bfd_set_error (bfd_error_wrong_format);
124 exec.a_info = SWAP_MAGIC (exec_bytes.e_info);
126 exec.a_info = bfd_h_get_32 (abfd, exec_bytes.e_info);
127 #endif /* SWAP_MAGIC */
129 if (N_BADMAG (exec)) return 0;
131 if (!(MACHTYPE_OK (N_MACHTYPE (exec)))) return 0;
134 NAME(aout,swap_exec_header_in)(abfd, &exec_bytes, &exec);
137 /* swap_exec_header_in read in a_info with the wrong byte order */
138 exec.a_info = SWAP_MAGIC (exec_bytes.e_info);
139 #endif /* SWAP_MAGIC */
141 target = NAME(aout,some_aout_object_p) (abfd, &exec, MY(callback));
143 #ifdef ENTRY_CAN_BE_ZERO
144 /* The NEWSOS3 entry-point is/was 0, which (amongst other lossage)
145 * means that it isn't obvious if EXEC_P should be set.
146 * All of the following must be true for an executable:
147 * There must be no relocations, the bfd can be neither an
148 * archive nor an archive element, and the file must be executable. */
150 if (exec.a_trsize + exec.a_drsize == 0
151 && bfd_get_format(abfd) == bfd_object && abfd->my_archive == NULL)
155 #define S_IXUSR 0100 /* Execute by owner. */
157 if (stat(abfd->filename, &buf) == 0 && (buf.st_mode & S_IXUSR))
158 abfd->flags |= EXEC_P;
160 #endif /* ENTRY_CAN_BE_ZERO */
164 #define MY_object_p MY(object_p)
173 if (NAME(aout,mkobject)(abfd) == false)
175 #if 0 /* Sizes get set in set_sizes callback, later, after we know
176 the architecture and machine. */
177 adata(abfd).page_size = TARGET_PAGE_SIZE;
179 adata(abfd).segment_size = SEGMENT_SIZE;
181 adata(abfd).segment_size = TARGET_PAGE_SIZE;
183 adata(abfd).exec_bytes_size = EXEC_BYTES_SIZE;
187 #define MY_mkobject MY(mkobject)
190 #ifndef MY_bfd_copy_private_section_data
192 /* Copy private section data. This actually does nothing with the
193 sections. It copies the subformat field. We copy it here, because
194 we need to know whether this is a QMAGIC file before we set the
195 section contents, and copy_private_bfd_data is not called until
196 after the section contents have been set. */
200 MY_bfd_copy_private_section_data (ibfd, isec, obfd, osec)
206 if (bfd_get_flavour (obfd) == bfd_target_aout_flavour)
207 obj_aout_subformat (obfd) = obj_aout_subformat (ibfd);
213 /* Write an object file.
214 Section contents have already been written. We write the
215 file header, symbols, and relocation. */
217 #ifndef MY_write_object_contents
219 MY(write_object_contents) (abfd)
222 struct external_exec exec_bytes;
223 struct internal_exec *execp = exec_hdr (abfd);
225 #if CHOOSE_RELOC_SIZE
226 CHOOSE_RELOC_SIZE(abfd);
228 obj_reloc_entry_size (abfd) = RELOC_STD_SIZE;
231 WRITE_HEADERS(abfd, execp);
235 #define MY_write_object_contents MY(write_object_contents)
243 adata(abfd).page_size = TARGET_PAGE_SIZE;
246 adata(abfd).segment_size = SEGMENT_SIZE;
248 adata(abfd).segment_size = TARGET_PAGE_SIZE;
251 #ifdef ZMAGIC_DISK_BLOCK_SIZE
252 adata(abfd).zmagic_disk_block_size = ZMAGIC_DISK_BLOCK_SIZE;
254 adata(abfd).zmagic_disk_block_size = TARGET_PAGE_SIZE;
257 adata(abfd).exec_bytes_size = EXEC_BYTES_SIZE;
260 #define MY_set_sizes MY(set_sizes)
263 #ifndef MY_exec_hdr_flags
264 #define MY_exec_hdr_flags 0
267 #ifndef MY_backend_data
269 #ifndef MY_zmagic_contiguous
270 #define MY_zmagic_contiguous 0
272 #ifndef MY_text_includes_header
273 #define MY_text_includes_header 0
275 #ifndef MY_exec_header_not_counted
276 #define MY_exec_header_not_counted 0
278 #ifndef MY_add_dynamic_symbols
279 #define MY_add_dynamic_symbols 0
281 #ifndef MY_add_one_symbol
282 #define MY_add_one_symbol 0
284 #ifndef MY_link_dynamic_object
285 #define MY_link_dynamic_object 0
287 #ifndef MY_write_dynamic_symbol
288 #define MY_write_dynamic_symbol 0
290 #ifndef MY_check_dynamic_reloc
291 #define MY_check_dynamic_reloc 0
293 #ifndef MY_finish_dynamic_link
294 #define MY_finish_dynamic_link 0
297 static CONST struct aout_backend_data MY(backend_data) = {
298 MY_zmagic_contiguous,
299 MY_text_includes_header,
303 MY_exec_header_not_counted,
304 MY_add_dynamic_symbols,
306 MY_link_dynamic_object,
307 MY_write_dynamic_symbol,
308 MY_check_dynamic_reloc,
309 MY_finish_dynamic_link
311 #define MY_backend_data &MY(backend_data)
314 #ifndef MY_final_link_callback
316 /* Callback for the final_link routine to set the section offsets. */
318 static void MY_final_link_callback
319 PARAMS ((bfd *, file_ptr *, file_ptr *, file_ptr *));
322 MY_final_link_callback (abfd, ptreloff, pdreloff, psymoff)
328 struct internal_exec *execp = exec_hdr (abfd);
330 *ptreloff = N_TRELOFF (*execp);
331 *pdreloff = N_DRELOFF (*execp);
332 *psymoff = N_SYMOFF (*execp);
337 #ifndef MY_bfd_final_link
339 /* Final link routine. We need to use a call back to get the correct
340 offsets in the output file. */
343 MY_bfd_final_link (abfd, info)
345 struct bfd_link_info *info;
347 return NAME(aout,final_link) (abfd, info, MY_final_link_callback);
352 /* We assume BFD generic archive files. */
353 #ifndef MY_openr_next_archived_file
354 #define MY_openr_next_archived_file bfd_generic_openr_next_archived_file
356 #ifndef MY_get_elt_at_index
357 #define MY_get_elt_at_index _bfd_generic_get_elt_at_index
359 #ifndef MY_generic_stat_arch_elt
360 #define MY_generic_stat_arch_elt bfd_generic_stat_arch_elt
362 #ifndef MY_slurp_armap
363 #define MY_slurp_armap bfd_slurp_bsd_armap
365 #ifndef MY_slurp_extended_name_table
366 #define MY_slurp_extended_name_table _bfd_slurp_extended_name_table
368 #ifndef MY_construct_extended_name_table
369 #define MY_construct_extended_name_table \
370 _bfd_archive_bsd_construct_extended_name_table
372 #ifndef MY_write_armap
373 #define MY_write_armap bsd_write_armap
375 #ifndef MY_read_ar_hdr
376 #define MY_read_ar_hdr _bfd_generic_read_ar_hdr
378 #ifndef MY_truncate_arname
379 #define MY_truncate_arname bfd_bsd_truncate_arname
381 #ifndef MY_update_armap_timestamp
382 #define MY_update_armap_timestamp _bfd_archive_bsd_update_armap_timestamp
385 /* No core file defined here -- configure in trad-core.c separately. */
386 #ifndef MY_core_file_failing_command
387 #define MY_core_file_failing_command _bfd_nocore_core_file_failing_command
389 #ifndef MY_core_file_failing_signal
390 #define MY_core_file_failing_signal _bfd_nocore_core_file_failing_signal
392 #ifndef MY_core_file_matches_executable_p
393 #define MY_core_file_matches_executable_p \
394 _bfd_nocore_core_file_matches_executable_p
396 #ifndef MY_core_file_p
397 #define MY_core_file_p _bfd_dummy_target
400 #ifndef MY_bfd_debug_info_start
401 #define MY_bfd_debug_info_start bfd_void
403 #ifndef MY_bfd_debug_info_end
404 #define MY_bfd_debug_info_end bfd_void
406 #ifndef MY_bfd_debug_info_accumulate
407 #define MY_bfd_debug_info_accumulate \
408 (void (*) PARAMS ((bfd*, struct sec *))) bfd_void
411 #ifndef MY_core_file_failing_command
412 #define MY_core_file_failing_command NAME(aout,core_file_failing_command)
414 #ifndef MY_core_file_failing_signal
415 #define MY_core_file_failing_signal NAME(aout,core_file_failing_signal)
417 #ifndef MY_core_file_matches_executable_p
418 #define MY_core_file_matches_executable_p NAME(aout,core_file_matches_executable_p)
420 #ifndef MY_set_section_contents
421 #define MY_set_section_contents NAME(aout,set_section_contents)
423 #ifndef MY_get_section_contents
424 #define MY_get_section_contents NAME(aout,get_section_contents)
426 #ifndef MY_get_section_contents_in_window
427 #define MY_get_section_contents_in_window _bfd_generic_get_section_contents_in_window
429 #ifndef MY_new_section_hook
430 #define MY_new_section_hook NAME(aout,new_section_hook)
432 #ifndef MY_get_symtab_upper_bound
433 #define MY_get_symtab_upper_bound NAME(aout,get_symtab_upper_bound)
435 #ifndef MY_get_symtab
436 #define MY_get_symtab NAME(aout,get_symtab)
438 #ifndef MY_get_reloc_upper_bound
439 #define MY_get_reloc_upper_bound NAME(aout,get_reloc_upper_bound)
441 #ifndef MY_canonicalize_reloc
442 #define MY_canonicalize_reloc NAME(aout,canonicalize_reloc)
444 #ifndef MY_make_empty_symbol
445 #define MY_make_empty_symbol NAME(aout,make_empty_symbol)
447 #ifndef MY_print_symbol
448 #define MY_print_symbol NAME(aout,print_symbol)
450 #ifndef MY_get_symbol_info
451 #define MY_get_symbol_info NAME(aout,get_symbol_info)
453 #ifndef MY_get_lineno
454 #define MY_get_lineno NAME(aout,get_lineno)
456 #ifndef MY_set_arch_mach
457 #define MY_set_arch_mach NAME(aout,set_arch_mach)
459 #ifndef MY_find_nearest_line
460 #define MY_find_nearest_line NAME(aout,find_nearest_line)
462 #ifndef MY_sizeof_headers
463 #define MY_sizeof_headers NAME(aout,sizeof_headers)
465 #ifndef MY_bfd_get_relocated_section_contents
466 #define MY_bfd_get_relocated_section_contents \
467 bfd_generic_get_relocated_section_contents
469 #ifndef MY_bfd_relax_section
470 #define MY_bfd_relax_section bfd_generic_relax_section
472 #ifndef MY_bfd_reloc_type_lookup
473 #define MY_bfd_reloc_type_lookup NAME(aout,reloc_type_lookup)
475 #ifndef MY_bfd_make_debug_symbol
476 #define MY_bfd_make_debug_symbol 0
478 #ifndef MY_read_minisymbols
479 #define MY_read_minisymbols NAME(aout,read_minisymbols)
481 #ifndef MY_minisymbol_to_symbol
482 #define MY_minisymbol_to_symbol NAME(aout,minisymbol_to_symbol)
484 #ifndef MY_bfd_link_hash_table_create
485 #define MY_bfd_link_hash_table_create NAME(aout,link_hash_table_create)
487 #ifndef MY_bfd_link_add_symbols
488 #define MY_bfd_link_add_symbols NAME(aout,link_add_symbols)
490 #ifndef MY_bfd_link_split_section
491 #define MY_bfd_link_split_section _bfd_generic_link_split_section
495 #ifndef MY_bfd_copy_private_bfd_data
496 #define MY_bfd_copy_private_bfd_data _bfd_generic_bfd_copy_private_bfd_data
499 #ifndef MY_bfd_merge_private_bfd_data
500 #define MY_bfd_merge_private_bfd_data _bfd_generic_bfd_merge_private_bfd_data
503 #ifndef MY_bfd_copy_private_symbol_data
504 #define MY_bfd_copy_private_symbol_data _bfd_generic_bfd_copy_private_symbol_data
507 #ifndef MY_bfd_print_private_bfd_data
508 #define MY_bfd_print_private_bfd_data _bfd_generic_bfd_print_private_bfd_data
511 #ifndef MY_bfd_set_private_flags
512 #define MY_bfd_set_private_flags _bfd_generic_bfd_set_private_flags
515 #ifndef MY_bfd_is_local_label
516 #define MY_bfd_is_local_label bfd_generic_is_local_label
519 #ifndef MY_bfd_free_cached_info
520 #define MY_bfd_free_cached_info NAME(aout,bfd_free_cached_info)
523 #ifndef MY_close_and_cleanup
524 #define MY_close_and_cleanup MY_bfd_free_cached_info
527 #ifndef MY_get_dynamic_symtab_upper_bound
528 #define MY_get_dynamic_symtab_upper_bound \
529 _bfd_nodynamic_get_dynamic_symtab_upper_bound
531 #ifndef MY_canonicalize_dynamic_symtab
532 #define MY_canonicalize_dynamic_symtab \
533 _bfd_nodynamic_canonicalize_dynamic_symtab
535 #ifndef MY_get_dynamic_reloc_upper_bound
536 #define MY_get_dynamic_reloc_upper_bound \
537 _bfd_nodynamic_get_dynamic_reloc_upper_bound
539 #ifndef MY_canonicalize_dynamic_reloc
540 #define MY_canonicalize_dynamic_reloc \
541 _bfd_nodynamic_canonicalize_dynamic_reloc
544 /* Aout symbols normally have leading underscores */
545 #ifndef MY_symbol_leading_char
546 #define MY_symbol_leading_char '_'
549 /* Aout archives normally use spaces for padding */
551 #define AR_PAD_CHAR ' '
554 #ifndef MY_BFD_TARGET
555 const bfd_target MY(vec) =
557 TARGETNAME, /* name */
558 bfd_target_aout_flavour,
559 #ifdef TARGET_IS_BIG_ENDIAN_P
560 BFD_ENDIAN_BIG, /* target byte order (big) */
561 BFD_ENDIAN_BIG, /* target headers byte order (big) */
563 BFD_ENDIAN_LITTLE, /* target byte order (little) */
564 BFD_ENDIAN_LITTLE, /* target headers byte order (little) */
566 (HAS_RELOC | EXEC_P | /* object flags */
567 HAS_LINENO | HAS_DEBUG |
568 HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED),
569 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
570 MY_symbol_leading_char,
571 AR_PAD_CHAR, /* ar_pad_char */
572 15, /* ar_max_namelen */
573 #ifdef TARGET_IS_BIG_ENDIAN_P
574 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
575 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
576 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* data */
577 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
578 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
579 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* hdrs */
581 bfd_getl64, bfd_getl_signed_64, bfd_putl64,
582 bfd_getl32, bfd_getl_signed_32, bfd_putl32,
583 bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */
584 bfd_getl64, bfd_getl_signed_64, bfd_putl64,
585 bfd_getl32, bfd_getl_signed_32, bfd_putl32,
586 bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* hdrs */
588 {_bfd_dummy_target, MY_object_p, /* bfd_check_format */
589 bfd_generic_archive_p, MY_core_file_p},
590 {bfd_false, MY_mkobject, /* bfd_set_format */
591 _bfd_generic_mkarchive, bfd_false},
592 {bfd_false, MY_write_object_contents, /* bfd_write_contents */
593 _bfd_write_archive_contents, bfd_false},
595 BFD_JUMP_TABLE_GENERIC (MY),
596 BFD_JUMP_TABLE_COPY (MY),
597 BFD_JUMP_TABLE_CORE (MY),
598 BFD_JUMP_TABLE_ARCHIVE (MY),
599 BFD_JUMP_TABLE_SYMBOLS (MY),
600 BFD_JUMP_TABLE_RELOCS (MY),
601 BFD_JUMP_TABLE_WRITE (MY),
602 BFD_JUMP_TABLE_LINK (MY),
603 BFD_JUMP_TABLE_DYNAMIC (MY),
605 (PTR) MY_backend_data,
607 #endif /* MY_BFD_TARGET */