1 /* Define a target vector and some small routines for a variant of a.out.
2 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4 Free Software Foundation, Inc.
6 This file is part of BFD, the Binary File Descriptor library.
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.
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.
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. */
22 #include "aout/aout64.h"
23 #include "aout/stab_gnu.h"
25 /*#include "libaout.h"*/
28 #define SEGMENT_SIZE TARGET_PAGE_SIZE
31 extern reloc_howto_type
* NAME(aout
,reloc_type_lookup
)
32 PARAMS ((bfd
*, bfd_reloc_code_real_type
));
34 /* Set parameters about this a.out file that are machine-dependent.
35 This routine is called from some_aout_object_p just before it returns. */
38 static const bfd_target
*MY(callback
) PARAMS ((bfd
*));
40 static const bfd_target
*
44 struct internal_exec
*execp
= exec_hdr (abfd
);
45 unsigned int arch_align_power
;
46 unsigned long arch_align
;
48 /* Calculate the file positions of the parts of a newly read aout header */
49 obj_textsec (abfd
)->_raw_size
= N_TXTSIZE(*execp
);
51 /* The virtual memory addresses of the sections */
52 obj_textsec (abfd
)->vma
= N_TXTADDR(*execp
);
53 obj_datasec (abfd
)->vma
= N_DATADDR(*execp
);
54 obj_bsssec (abfd
)->vma
= N_BSSADDR(*execp
);
56 /* For some targets, if the entry point is not in the same page
57 as the start of the text, then adjust the VMA so that it is.
58 FIXME: Do this with a macro like SET_ARCH_MACH instead? */
59 if (aout_backend_info (abfd
)->entry_is_text_address
60 && execp
->a_entry
> obj_textsec (abfd
)->vma
)
64 adjust
= execp
->a_entry
- obj_textsec (abfd
)->vma
;
65 /* Adjust only by whole pages. */
66 adjust
&= ~(TARGET_PAGE_SIZE
- 1);
67 obj_textsec (abfd
)->vma
+= adjust
;
68 obj_datasec (abfd
)->vma
+= adjust
;
69 obj_bsssec (abfd
)->vma
+= adjust
;
72 /* Set the load addresses to be the same as the virtual addresses. */
73 obj_textsec (abfd
)->lma
= obj_textsec (abfd
)->vma
;
74 obj_datasec (abfd
)->lma
= obj_datasec (abfd
)->vma
;
75 obj_bsssec (abfd
)->lma
= obj_bsssec (abfd
)->vma
;
77 /* The file offsets of the sections */
78 obj_textsec (abfd
)->filepos
= N_TXTOFF (*execp
);
79 obj_datasec (abfd
)->filepos
= N_DATOFF (*execp
);
81 /* The file offsets of the relocation info */
82 obj_textsec (abfd
)->rel_filepos
= N_TRELOFF(*execp
);
83 obj_datasec (abfd
)->rel_filepos
= N_DRELOFF(*execp
);
85 /* The file offsets of the string table and symbol table. */
86 obj_sym_filepos (abfd
) = N_SYMOFF (*execp
);
87 obj_str_filepos (abfd
) = N_STROFF (*execp
);
89 /* Determine the architecture and machine type of the object file. */
91 SET_ARCH_MACH(abfd
, *execp
);
93 bfd_default_set_arch_mach(abfd
, DEFAULT_ARCH
, 0);
96 /* The number of relocation records. This must be called after
97 SET_ARCH_MACH. It assumes that SET_ARCH_MACH will set
98 obj_reloc_entry_size correctly, if the reloc size is not
100 obj_textsec (abfd
)->reloc_count
=
101 execp
->a_trsize
/ obj_reloc_entry_size (abfd
);
102 obj_datasec (abfd
)->reloc_count
=
103 execp
->a_drsize
/ obj_reloc_entry_size (abfd
);
105 /* Now that we know the architecture, set the alignments of the
106 sections. This is normally done by NAME(aout,new_section_hook),
107 but when the initial sections were created the architecture had
108 not yet been set. However, for backward compatibility, we don't
109 set the alignment power any higher than as required by the size
111 arch_align_power
= bfd_get_arch_info (abfd
)->section_align_power
;
112 arch_align
= 1 << arch_align_power
;
113 if ((BFD_ALIGN (obj_textsec (abfd
)->_raw_size
, arch_align
)
114 == obj_textsec (abfd
)->_raw_size
)
115 && (BFD_ALIGN (obj_datasec (abfd
)->_raw_size
, arch_align
)
116 == obj_datasec (abfd
)->_raw_size
)
117 && (BFD_ALIGN (obj_bsssec (abfd
)->_raw_size
, arch_align
)
118 == obj_bsssec (abfd
)->_raw_size
))
120 obj_textsec (abfd
)->alignment_power
= arch_align_power
;
121 obj_datasec (abfd
)->alignment_power
= arch_align_power
;
122 obj_bsssec (abfd
)->alignment_power
= arch_align_power
;
125 /* Don't set sizes now -- can't be sure until we know arch & mach.
126 Sizes get set in set_sizes callback, later. */
128 adata(abfd
).page_size
= TARGET_PAGE_SIZE
;
129 adata(abfd
).segment_size
= SEGMENT_SIZE
;
130 adata(abfd
).exec_bytes_size
= EXEC_BYTES_SIZE
;
138 /* Finish up the reading of an a.out file header */
140 static const bfd_target
*MY(object_p
) PARAMS ((bfd
*));
142 static const bfd_target
*
146 struct external_exec exec_bytes
; /* Raw exec header from file */
147 struct internal_exec exec
; /* Cleaned-up exec header */
148 const bfd_target
*target
;
150 if (bfd_read ((PTR
) &exec_bytes
, 1, EXEC_BYTES_SIZE
, abfd
)
151 != EXEC_BYTES_SIZE
) {
152 if (bfd_get_error () != bfd_error_system_call
)
153 bfd_set_error (bfd_error_wrong_format
);
158 exec
.a_info
= SWAP_MAGIC (exec_bytes
.e_info
);
160 exec
.a_info
= GET_MAGIC (abfd
, exec_bytes
.e_info
);
161 #endif /* SWAP_MAGIC */
163 if (N_BADMAG (exec
)) return 0;
165 if (!(MACHTYPE_OK (N_MACHTYPE (exec
)))) return 0;
168 NAME(aout
,swap_exec_header_in
) (abfd
, &exec_bytes
, &exec
);
171 /* swap_exec_header_in read in a_info with the wrong byte order */
172 exec
.a_info
= SWAP_MAGIC (exec_bytes
.e_info
);
173 #endif /* SWAP_MAGIC */
175 target
= NAME(aout
,some_aout_object_p
) (abfd
, &exec
, MY(callback
));
177 #ifdef ENTRY_CAN_BE_ZERO
178 /* The NEWSOS3 entry-point is/was 0, which (amongst other lossage)
179 * means that it isn't obvious if EXEC_P should be set.
180 * All of the following must be true for an executable:
181 * There must be no relocations, the bfd can be neither an
182 * archive nor an archive element, and the file must be executable. */
184 if (exec
.a_trsize
+ exec
.a_drsize
== 0
185 && bfd_get_format(abfd
) == bfd_object
&& abfd
->my_archive
== NULL
)
189 #define S_IXUSR 0100 /* Execute by owner. */
191 if (stat(abfd
->filename
, &buf
) == 0 && (buf
.st_mode
& S_IXUSR
))
192 abfd
->flags
|= EXEC_P
;
194 #endif /* ENTRY_CAN_BE_ZERO */
198 #define MY_object_p MY(object_p)
203 static boolean
MY(mkobject
) PARAMS ((bfd
*));
209 if (NAME(aout
,mkobject
) (abfd
) == false)
211 #if 0 /* Sizes get set in set_sizes callback, later, after we know
212 the architecture and machine. */
213 adata(abfd
).page_size
= TARGET_PAGE_SIZE
;
214 adata(abfd
).segment_size
= SEGMENT_SIZE
;
215 adata(abfd
).exec_bytes_size
= EXEC_BYTES_SIZE
;
219 #define MY_mkobject MY(mkobject)
222 #ifndef MY_bfd_copy_private_section_data
224 /* Copy private section data. This actually does nothing with the
225 sections. It copies the subformat field. We copy it here, because
226 we need to know whether this is a QMAGIC file before we set the
227 section contents, and copy_private_bfd_data is not called until
228 after the section contents have been set. */
230 static boolean MY_bfd_copy_private_section_data
231 PARAMS ((bfd
*, asection
*, bfd
*, asection
*));
234 MY_bfd_copy_private_section_data (ibfd
, isec
, obfd
, osec
)
236 asection
*isec ATTRIBUTE_UNUSED
;
238 asection
*osec ATTRIBUTE_UNUSED
;
240 if (bfd_get_flavour (ibfd
) == bfd_target_aout_flavour
241 && bfd_get_flavour (obfd
) == bfd_target_aout_flavour
)
242 obj_aout_subformat (obfd
) = obj_aout_subformat (ibfd
);
248 /* Write an object file.
249 Section contents have already been written. We write the
250 file header, symbols, and relocation. */
252 #ifndef MY_write_object_contents
254 MY(write_object_contents
) (abfd
)
257 struct external_exec exec_bytes
;
258 struct internal_exec
*execp
= exec_hdr (abfd
);
260 obj_reloc_entry_size (abfd
) = RELOC_STD_SIZE
;
262 WRITE_HEADERS(abfd
, execp
);
266 #define MY_write_object_contents MY(write_object_contents)
271 static boolean
MY(set_sizes
) PARAMS ((bfd
*));
277 adata(abfd
).page_size
= TARGET_PAGE_SIZE
;
278 adata(abfd
).segment_size
= SEGMENT_SIZE
;
280 #ifdef ZMAGIC_DISK_BLOCK_SIZE
281 adata(abfd
).zmagic_disk_block_size
= ZMAGIC_DISK_BLOCK_SIZE
;
283 adata(abfd
).zmagic_disk_block_size
= TARGET_PAGE_SIZE
;
286 adata(abfd
).exec_bytes_size
= EXEC_BYTES_SIZE
;
289 #define MY_set_sizes MY(set_sizes)
292 #ifndef MY_exec_hdr_flags
293 #define MY_exec_hdr_flags 0
296 #ifndef MY_backend_data
298 #ifndef MY_zmagic_contiguous
299 #define MY_zmagic_contiguous 0
301 #ifndef MY_text_includes_header
302 #define MY_text_includes_header 0
304 #ifndef MY_entry_is_text_address
305 #define MY_entry_is_text_address 0
307 #ifndef MY_exec_header_not_counted
308 #define MY_exec_header_not_counted 0
310 #ifndef MY_add_dynamic_symbols
311 #define MY_add_dynamic_symbols 0
313 #ifndef MY_add_one_symbol
314 #define MY_add_one_symbol 0
316 #ifndef MY_link_dynamic_object
317 #define MY_link_dynamic_object 0
319 #ifndef MY_write_dynamic_symbol
320 #define MY_write_dynamic_symbol 0
322 #ifndef MY_check_dynamic_reloc
323 #define MY_check_dynamic_reloc 0
325 #ifndef MY_finish_dynamic_link
326 #define MY_finish_dynamic_link 0
329 static CONST
struct aout_backend_data
MY(backend_data
) = {
330 MY_zmagic_contiguous
,
331 MY_text_includes_header
,
332 MY_entry_is_text_address
,
336 MY_exec_header_not_counted
,
337 MY_add_dynamic_symbols
,
339 MY_link_dynamic_object
,
340 MY_write_dynamic_symbol
,
341 MY_check_dynamic_reloc
,
342 MY_finish_dynamic_link
344 #define MY_backend_data &MY(backend_data)
347 #ifndef MY_final_link_callback
349 /* Callback for the final_link routine to set the section offsets. */
351 static void MY_final_link_callback
352 PARAMS ((bfd
*, file_ptr
*, file_ptr
*, file_ptr
*));
355 MY_final_link_callback (abfd
, ptreloff
, pdreloff
, psymoff
)
361 struct internal_exec
*execp
= exec_hdr (abfd
);
363 *ptreloff
= N_TRELOFF (*execp
);
364 *pdreloff
= N_DRELOFF (*execp
);
365 *psymoff
= N_SYMOFF (*execp
);
370 #ifndef MY_bfd_final_link
372 /* Final link routine. We need to use a call back to get the correct
373 offsets in the output file. */
375 static boolean MY_bfd_final_link
PARAMS ((bfd
*, struct bfd_link_info
*));
378 MY_bfd_final_link (abfd
, info
)
380 struct bfd_link_info
*info
;
382 return NAME(aout
,final_link
) (abfd
, info
, MY_final_link_callback
);
387 /* We assume BFD generic archive files. */
388 #ifndef MY_openr_next_archived_file
389 #define MY_openr_next_archived_file bfd_generic_openr_next_archived_file
391 #ifndef MY_get_elt_at_index
392 #define MY_get_elt_at_index _bfd_generic_get_elt_at_index
394 #ifndef MY_generic_stat_arch_elt
395 #define MY_generic_stat_arch_elt bfd_generic_stat_arch_elt
397 #ifndef MY_slurp_armap
398 #define MY_slurp_armap bfd_slurp_bsd_armap
400 #ifndef MY_slurp_extended_name_table
401 #define MY_slurp_extended_name_table _bfd_slurp_extended_name_table
403 #ifndef MY_construct_extended_name_table
404 #define MY_construct_extended_name_table \
405 _bfd_archive_bsd_construct_extended_name_table
407 #ifndef MY_write_armap
408 #define MY_write_armap bsd_write_armap
410 #ifndef MY_read_ar_hdr
411 #define MY_read_ar_hdr _bfd_generic_read_ar_hdr
413 #ifndef MY_truncate_arname
414 #define MY_truncate_arname bfd_bsd_truncate_arname
416 #ifndef MY_update_armap_timestamp
417 #define MY_update_armap_timestamp _bfd_archive_bsd_update_armap_timestamp
420 /* No core file defined here -- configure in trad-core.c separately. */
421 #ifndef MY_core_file_failing_command
422 #define MY_core_file_failing_command _bfd_nocore_core_file_failing_command
424 #ifndef MY_core_file_failing_signal
425 #define MY_core_file_failing_signal _bfd_nocore_core_file_failing_signal
427 #ifndef MY_core_file_matches_executable_p
428 #define MY_core_file_matches_executable_p \
429 _bfd_nocore_core_file_matches_executable_p
431 #ifndef MY_core_file_p
432 #define MY_core_file_p _bfd_dummy_target
435 #ifndef MY_bfd_debug_info_start
436 #define MY_bfd_debug_info_start bfd_void
438 #ifndef MY_bfd_debug_info_end
439 #define MY_bfd_debug_info_end bfd_void
441 #ifndef MY_bfd_debug_info_accumulate
442 #define MY_bfd_debug_info_accumulate \
443 (void (*) PARAMS ((bfd*, struct sec *))) bfd_void
446 #ifndef MY_core_file_failing_command
447 #define MY_core_file_failing_command NAME(aout,core_file_failing_command)
449 #ifndef MY_core_file_failing_signal
450 #define MY_core_file_failing_signal NAME(aout,core_file_failing_signal)
452 #ifndef MY_core_file_matches_executable_p
453 #define MY_core_file_matches_executable_p NAME(aout,core_file_matches_executable_p)
455 #ifndef MY_set_section_contents
456 #define MY_set_section_contents NAME(aout,set_section_contents)
458 #ifndef MY_get_section_contents
459 #define MY_get_section_contents NAME(aout,get_section_contents)
461 #ifndef MY_get_section_contents_in_window
462 #define MY_get_section_contents_in_window _bfd_generic_get_section_contents_in_window
464 #ifndef MY_new_section_hook
465 #define MY_new_section_hook NAME(aout,new_section_hook)
467 #ifndef MY_get_symtab_upper_bound
468 #define MY_get_symtab_upper_bound NAME(aout,get_symtab_upper_bound)
470 #ifndef MY_get_symtab
471 #define MY_get_symtab NAME(aout,get_symtab)
473 #ifndef MY_get_reloc_upper_bound
474 #define MY_get_reloc_upper_bound NAME(aout,get_reloc_upper_bound)
476 #ifndef MY_canonicalize_reloc
477 #define MY_canonicalize_reloc NAME(aout,canonicalize_reloc)
479 #ifndef MY_make_empty_symbol
480 #define MY_make_empty_symbol NAME(aout,make_empty_symbol)
482 #ifndef MY_print_symbol
483 #define MY_print_symbol NAME(aout,print_symbol)
485 #ifndef MY_get_symbol_info
486 #define MY_get_symbol_info NAME(aout,get_symbol_info)
488 #ifndef MY_get_lineno
489 #define MY_get_lineno NAME(aout,get_lineno)
491 #ifndef MY_set_arch_mach
492 #define MY_set_arch_mach NAME(aout,set_arch_mach)
494 #ifndef MY_find_nearest_line
495 #define MY_find_nearest_line NAME(aout,find_nearest_line)
497 #ifndef MY_sizeof_headers
498 #define MY_sizeof_headers NAME(aout,sizeof_headers)
500 #ifndef MY_bfd_get_relocated_section_contents
501 #define MY_bfd_get_relocated_section_contents \
502 bfd_generic_get_relocated_section_contents
504 #ifndef MY_bfd_relax_section
505 #define MY_bfd_relax_section bfd_generic_relax_section
507 #ifndef MY_bfd_gc_sections
508 #define MY_bfd_gc_sections bfd_generic_gc_sections
510 #ifndef MY_bfd_merge_sections
511 #define MY_bfd_merge_sections bfd_generic_merge_sections
513 #ifndef MY_bfd_reloc_type_lookup
514 #define MY_bfd_reloc_type_lookup NAME(aout,reloc_type_lookup)
516 #ifndef MY_bfd_make_debug_symbol
517 #define MY_bfd_make_debug_symbol 0
519 #ifndef MY_read_minisymbols
520 #define MY_read_minisymbols NAME(aout,read_minisymbols)
522 #ifndef MY_minisymbol_to_symbol
523 #define MY_minisymbol_to_symbol NAME(aout,minisymbol_to_symbol)
525 #ifndef MY_bfd_link_hash_table_create
526 #define MY_bfd_link_hash_table_create NAME(aout,link_hash_table_create)
528 #ifndef MY_bfd_link_add_symbols
529 #define MY_bfd_link_add_symbols NAME(aout,link_add_symbols)
531 #ifndef MY_bfd_link_split_section
532 #define MY_bfd_link_split_section _bfd_generic_link_split_section
535 #ifndef MY_bfd_copy_private_bfd_data
536 #define MY_bfd_copy_private_bfd_data _bfd_generic_bfd_copy_private_bfd_data
539 #ifndef MY_bfd_merge_private_bfd_data
540 #define MY_bfd_merge_private_bfd_data _bfd_generic_bfd_merge_private_bfd_data
543 #ifndef MY_bfd_copy_private_symbol_data
544 #define MY_bfd_copy_private_symbol_data _bfd_generic_bfd_copy_private_symbol_data
547 #ifndef MY_bfd_print_private_bfd_data
548 #define MY_bfd_print_private_bfd_data _bfd_generic_bfd_print_private_bfd_data
551 #ifndef MY_bfd_set_private_flags
552 #define MY_bfd_set_private_flags _bfd_generic_bfd_set_private_flags
555 #ifndef MY_bfd_is_local_label_name
556 #define MY_bfd_is_local_label_name bfd_generic_is_local_label_name
559 #ifndef MY_bfd_free_cached_info
560 #define MY_bfd_free_cached_info NAME(aout,bfd_free_cached_info)
563 #ifndef MY_close_and_cleanup
564 #define MY_close_and_cleanup MY_bfd_free_cached_info
567 #ifndef MY_get_dynamic_symtab_upper_bound
568 #define MY_get_dynamic_symtab_upper_bound \
569 _bfd_nodynamic_get_dynamic_symtab_upper_bound
571 #ifndef MY_canonicalize_dynamic_symtab
572 #define MY_canonicalize_dynamic_symtab \
573 _bfd_nodynamic_canonicalize_dynamic_symtab
575 #ifndef MY_get_dynamic_reloc_upper_bound
576 #define MY_get_dynamic_reloc_upper_bound \
577 _bfd_nodynamic_get_dynamic_reloc_upper_bound
579 #ifndef MY_canonicalize_dynamic_reloc
580 #define MY_canonicalize_dynamic_reloc \
581 _bfd_nodynamic_canonicalize_dynamic_reloc
584 /* Aout symbols normally have leading underscores */
585 #ifndef MY_symbol_leading_char
586 #define MY_symbol_leading_char '_'
589 /* Aout archives normally use spaces for padding */
591 #define AR_PAD_CHAR ' '
594 #ifndef MY_BFD_TARGET
595 const bfd_target
MY(vec
) =
597 TARGETNAME
, /* name */
598 bfd_target_aout_flavour
,
599 #ifdef TARGET_IS_BIG_ENDIAN_P
600 BFD_ENDIAN_BIG
, /* target byte order (big) */
601 BFD_ENDIAN_BIG
, /* target headers byte order (big) */
603 BFD_ENDIAN_LITTLE
, /* target byte order (little) */
604 BFD_ENDIAN_LITTLE
, /* target headers byte order (little) */
606 (HAS_RELOC
| EXEC_P
| /* object flags */
607 HAS_LINENO
| HAS_DEBUG
|
608 HAS_SYMS
| HAS_LOCALS
| DYNAMIC
| WP_TEXT
| D_PAGED
),
609 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_CODE
| SEC_DATA
),
610 MY_symbol_leading_char
,
611 AR_PAD_CHAR
, /* ar_pad_char */
612 15, /* ar_max_namelen */
613 #ifdef TARGET_IS_BIG_ENDIAN_P
614 bfd_getb64
, bfd_getb_signed_64
, bfd_putb64
,
615 bfd_getb32
, bfd_getb_signed_32
, bfd_putb32
,
616 bfd_getb16
, bfd_getb_signed_16
, bfd_putb16
, /* data */
617 bfd_getb64
, bfd_getb_signed_64
, bfd_putb64
,
618 bfd_getb32
, bfd_getb_signed_32
, bfd_putb32
,
619 bfd_getb16
, bfd_getb_signed_16
, bfd_putb16
, /* hdrs */
621 bfd_getl64
, bfd_getl_signed_64
, bfd_putl64
,
622 bfd_getl32
, bfd_getl_signed_32
, bfd_putl32
,
623 bfd_getl16
, bfd_getl_signed_16
, bfd_putl16
, /* data */
624 bfd_getl64
, bfd_getl_signed_64
, bfd_putl64
,
625 bfd_getl32
, bfd_getl_signed_32
, bfd_putl32
,
626 bfd_getl16
, bfd_getl_signed_16
, bfd_putl16
, /* hdrs */
628 {_bfd_dummy_target
, MY_object_p
, /* bfd_check_format */
629 bfd_generic_archive_p
, MY_core_file_p
},
630 {bfd_false
, MY_mkobject
, /* bfd_set_format */
631 _bfd_generic_mkarchive
, bfd_false
},
632 {bfd_false
, MY_write_object_contents
, /* bfd_write_contents */
633 _bfd_write_archive_contents
, bfd_false
},
635 BFD_JUMP_TABLE_GENERIC (MY
),
636 BFD_JUMP_TABLE_COPY (MY
),
637 BFD_JUMP_TABLE_CORE (MY
),
638 BFD_JUMP_TABLE_ARCHIVE (MY
),
639 BFD_JUMP_TABLE_SYMBOLS (MY
),
640 BFD_JUMP_TABLE_RELOCS (MY
),
641 BFD_JUMP_TABLE_WRITE (MY
),
642 BFD_JUMP_TABLE_LINK (MY
),
643 BFD_JUMP_TABLE_DYNAMIC (MY
),
645 /* Alternative_target */
648 (PTR
) MY_backend_data
650 #endif /* MY_BFD_TARGET */