1 /* Define a target vector and some small routines for a variant of a.out.
2 Copyright (C) 1990, 1991, 1992, 1993 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. */
34 struct internal_exec
*execp
= exec_hdr (abfd
);
36 /* Calculate the file positions of the parts of a newly read aout header */
37 obj_textsec (abfd
)->_raw_size
= N_TXTSIZE(*execp
);
39 /* The virtual memory addresses of the sections */
40 obj_textsec (abfd
)->vma
= N_TXTADDR(*execp
);
41 obj_datasec (abfd
)->vma
= N_DATADDR(*execp
);
42 obj_bsssec (abfd
)->vma
= N_BSSADDR(*execp
);
44 /* The file offsets of the sections */
45 obj_textsec (abfd
)->filepos
= N_TXTOFF (*execp
);
46 obj_datasec (abfd
)->filepos
= N_DATOFF (*execp
);
48 /* The file offsets of the relocation info */
49 obj_textsec (abfd
)->rel_filepos
= N_TRELOFF(*execp
);
50 obj_datasec (abfd
)->rel_filepos
= N_DRELOFF(*execp
);
52 /* The file offsets of the string table and symbol table. */
53 obj_sym_filepos (abfd
) = N_SYMOFF (*execp
);
54 obj_str_filepos (abfd
) = N_STROFF (*execp
);
56 /* Determine the architecture and machine type of the object file. */
58 SET_ARCH_MACH(abfd
, *execp
);
60 bfd_default_set_arch_mach(abfd
, DEFAULT_ARCH
, 0);
63 /* Don't set sizes now -- can't be sure until we know arch & mach.
64 Sizes get set in set_sizes callback, later. */
66 adata(abfd
).page_size
= PAGE_SIZE
;
68 adata(abfd
).segment_size
= SEGMENT_SIZE
;
70 adata(abfd
).segment_size
= PAGE_SIZE
;
72 adata(abfd
).exec_bytes_size
= EXEC_BYTES_SIZE
;
80 /* Finish up the reading of an a.out file header */
86 struct external_exec exec_bytes
; /* Raw exec header from file */
87 struct internal_exec exec
; /* Cleaned-up exec header */
90 if (bfd_read ((PTR
) &exec_bytes
, 1, EXEC_BYTES_SIZE
, abfd
)
92 bfd_set_error (bfd_error_wrong_format
);
97 exec
.a_info
= SWAP_MAGIC (exec_bytes
.e_info
);
99 exec
.a_info
= bfd_h_get_32 (abfd
, exec_bytes
.e_info
);
100 #endif /* SWAP_MAGIC */
102 if (N_BADMAG (exec
)) return 0;
104 if (!(MACHTYPE_OK (N_MACHTYPE (exec
)))) return 0;
107 NAME(aout
,swap_exec_header_in
)(abfd
, &exec_bytes
, &exec
);
108 target
= NAME(aout
,some_aout_object_p
) (abfd
, &exec
, MY(callback
));
110 #ifdef ENTRY_CAN_BE_ZERO
111 /* The NEWSOS3 entry-point is/was 0, which (amongst other lossage)
112 * means that it isn't obvious if EXEC_P should be set.
113 * All of the following must be true for an executable:
114 * There must be no relocations, the bfd can be neither an
115 * archive nor an archive element, and the file must be executable. */
117 if (exec
.a_trsize
+ exec
.a_drsize
== 0
118 && bfd_get_format(abfd
) == bfd_object
&& abfd
->my_archive
== NULL
)
122 #define S_IXUSR 0100 /* Execute by owner. */
124 if (stat(abfd
->filename
, &buf
) == 0 && (buf
.st_mode
& S_IXUSR
))
125 abfd
->flags
|= EXEC_P
;
127 #endif /* ENTRY_CAN_BE_ZERO */
131 #define MY_object_p MY(object_p)
140 if (NAME(aout
,mkobject
)(abfd
) == false)
142 #if 0 /* Sizes get set in set_sizes callback, later, after we know
143 the architecture and machine. */
144 adata(abfd
).page_size
= PAGE_SIZE
;
146 adata(abfd
).segment_size
= SEGMENT_SIZE
;
148 adata(abfd
).segment_size
= PAGE_SIZE
;
150 adata(abfd
).exec_bytes_size
= EXEC_BYTES_SIZE
;
154 #define MY_mkobject MY(mkobject)
157 /* Write an object file.
158 Section contents have already been written. We write the
159 file header, symbols, and relocation. */
161 #ifndef MY_write_object_contents
163 MY(write_object_contents
) (abfd
)
166 struct external_exec exec_bytes
;
167 struct internal_exec
*execp
= exec_hdr (abfd
);
169 #if CHOOSE_RELOC_SIZE
170 CHOOSE_RELOC_SIZE(abfd
);
172 obj_reloc_entry_size (abfd
) = RELOC_STD_SIZE
;
175 WRITE_HEADERS(abfd
, execp
);
179 #define MY_write_object_contents MY(write_object_contents)
187 adata(abfd
).page_size
= PAGE_SIZE
;
189 adata(abfd
).segment_size
= SEGMENT_SIZE
;
191 adata(abfd
).segment_size
= PAGE_SIZE
;
193 adata(abfd
).exec_bytes_size
= EXEC_BYTES_SIZE
;
196 #define MY_set_sizes MY(set_sizes)
199 #ifndef MY_backend_data
201 #ifndef MY_read_dynamic_symbols
202 #define MY_read_dynamic_symbols 0
204 #ifndef MY_read_dynamic_relocs
205 #define MY_read_dynamic_relocs 0
208 static CONST
struct aout_backend_data
MY(backend_data
) = {
209 0, /* zmagic contiguous */
210 0, /* text incl header */
213 0, /* exec header is counted */
214 MY_read_dynamic_symbols
,
215 MY_read_dynamic_relocs
217 #define MY_backend_data &MY(backend_data)
220 #ifndef MY_bfd_final_link
222 /* Final link routine. We need to use a call back to get the correct
223 offsets in the output file. */
225 static void final_link_callback
226 PARAMS ((bfd
*, file_ptr
*, file_ptr
*, file_ptr
*));
229 final_link_callback (abfd
, ptreloff
, pdreloff
, psymoff
)
235 struct internal_exec
*execp
= exec_hdr (abfd
);
237 *ptreloff
= N_TRELOFF (*execp
);
238 *pdreloff
= N_DRELOFF (*execp
);
239 *psymoff
= N_SYMOFF (*execp
);
243 MY_bfd_final_link (abfd
, info
)
245 struct bfd_link_info
*info
;
247 return NAME(aout
,final_link
) (abfd
, info
, final_link_callback
);
252 /* We assume BFD generic archive files. */
253 #ifndef MY_openr_next_archived_file
254 #define MY_openr_next_archived_file bfd_generic_openr_next_archived_file
256 #ifndef MY_generic_stat_arch_elt
257 #define MY_generic_stat_arch_elt bfd_generic_stat_arch_elt
259 #ifndef MY_slurp_armap
260 #define MY_slurp_armap bfd_slurp_bsd_armap
262 #ifndef MY_slurp_extended_name_table
263 #define MY_slurp_extended_name_table _bfd_slurp_extended_name_table
265 #ifndef MY_write_armap
266 #define MY_write_armap bsd_write_armap
268 #ifndef MY_truncate_arname
269 #define MY_truncate_arname bfd_bsd_truncate_arname
272 /* No core file defined here -- configure in trad-core.c separately. */
273 #ifndef MY_core_file_failing_command
274 #define MY_core_file_failing_command _bfd_dummy_core_file_failing_command
276 #ifndef MY_core_file_failing_signal
277 #define MY_core_file_failing_signal _bfd_dummy_core_file_failing_signal
279 #ifndef MY_core_file_matches_executable_p
280 #define MY_core_file_matches_executable_p \
281 _bfd_dummy_core_file_matches_executable_p
283 #ifndef MY_core_file_p
284 #define MY_core_file_p _bfd_dummy_target
287 #ifndef MY_bfd_debug_info_start
288 #define MY_bfd_debug_info_start bfd_void
290 #ifndef MY_bfd_debug_info_end
291 #define MY_bfd_debug_info_end bfd_void
293 #ifndef MY_bfd_debug_info_accumulate
294 #define MY_bfd_debug_info_accumulate \
295 (void (*) PARAMS ((bfd*, struct sec *))) bfd_void
298 #ifndef MY_core_file_failing_command
299 #define MY_core_file_failing_command NAME(aout,core_file_failing_command)
301 #ifndef MY_core_file_failing_signal
302 #define MY_core_file_failing_signal NAME(aout,core_file_failing_signal)
304 #ifndef MY_core_file_matches_executable_p
305 #define MY_core_file_matches_executable_p NAME(aout,core_file_matches_executable_p)
307 #ifndef MY_slurp_armap
308 #define MY_slurp_armap NAME(aout,slurp_armap)
310 #ifndef MY_slurp_extended_name_table
311 #define MY_slurp_extended_name_table NAME(aout,slurp_extended_name_table)
313 #ifndef MY_truncate_arname
314 #define MY_truncate_arname NAME(aout,truncate_arname)
316 #ifndef MY_write_armap
317 #define MY_write_armap NAME(aout,write_armap)
319 #ifndef MY_set_section_contents
320 #define MY_set_section_contents NAME(aout,set_section_contents)
322 #ifndef MY_get_section_contents
323 #define MY_get_section_contents NAME(aout,get_section_contents)
325 #ifndef MY_new_section_hook
326 #define MY_new_section_hook NAME(aout,new_section_hook)
328 #ifndef MY_get_symtab_upper_bound
329 #define MY_get_symtab_upper_bound NAME(aout,get_symtab_upper_bound)
331 #ifndef MY_get_symtab
332 #define MY_get_symtab NAME(aout,get_symtab)
334 #ifndef MY_get_reloc_upper_bound
335 #define MY_get_reloc_upper_bound NAME(aout,get_reloc_upper_bound)
337 #ifndef MY_canonicalize_reloc
338 #define MY_canonicalize_reloc NAME(aout,canonicalize_reloc)
340 #ifndef MY_make_empty_symbol
341 #define MY_make_empty_symbol NAME(aout,make_empty_symbol)
343 #ifndef MY_print_symbol
344 #define MY_print_symbol NAME(aout,print_symbol)
346 #ifndef MY_get_symbol_info
347 #define MY_get_symbol_info NAME(aout,get_symbol_info)
349 #ifndef MY_get_lineno
350 #define MY_get_lineno NAME(aout,get_lineno)
352 #ifndef MY_set_arch_mach
353 #define MY_set_arch_mach NAME(aout,set_arch_mach)
355 #ifndef MY_openr_next_archived_file
356 #define MY_openr_next_archived_file NAME(aout,openr_next_archived_file)
358 #ifndef MY_find_nearest_line
359 #define MY_find_nearest_line NAME(aout,find_nearest_line)
361 #ifndef MY_generic_stat_arch_elt
362 #define MY_generic_stat_arch_elt NAME(aout,generic_stat_arch_elt)
364 #ifndef MY_sizeof_headers
365 #define MY_sizeof_headers NAME(aout,sizeof_headers)
367 #ifndef MY_bfd_get_relocated_section_contents
368 #define MY_bfd_get_relocated_section_contents \
369 bfd_generic_get_relocated_section_contents
371 #ifndef MY_bfd_relax_section
372 #define MY_bfd_relax_section bfd_generic_relax_section
374 #ifndef MY_bfd_reloc_type_lookup
375 #define MY_bfd_reloc_type_lookup NAME(aout,reloc_type_lookup)
377 #ifndef MY_bfd_make_debug_symbol
378 #define MY_bfd_make_debug_symbol 0
380 #ifndef MY_bfd_link_hash_table_create
381 #define MY_bfd_link_hash_table_create NAME(aout,link_hash_table_create)
383 #ifndef MY_bfd_link_add_symbols
384 #define MY_bfd_link_add_symbols NAME(aout,link_add_symbols)
387 #ifndef MY_bfd_copy_private_section_data
388 #define MY_bfd_copy_private_section_data \
389 ((boolean (*) PARAMS ((bfd *, asection *, bfd *, asection *))) bfd_true)
391 #ifndef MY_bfd_copy_private_bfd_data
392 #define MY_bfd_copy_private_bfd_data \
393 ((boolean (*) PARAMS ((bfd *, bfd *))) bfd_true)
396 #ifndef MY_bfd_is_local_label
397 #define MY_bfd_is_local_label bfd_generic_is_local_label
400 #ifndef MY_bfd_free_cached_info
401 #define MY_bfd_free_cached_info NAME(aout,bfd_free_cached_info)
404 #ifndef MY_close_and_cleanup
405 #define MY_close_and_cleanup MY_bfd_free_cached_info
408 /* Aout symbols normally have leading underscores */
409 #ifndef MY_symbol_leading_char
410 #define MY_symbol_leading_char '_'
413 /* Aout archives normally use spaces for padding */
415 #define AR_PAD_CHAR ' '
418 #ifndef MY_BFD_TARGET
421 TARGETNAME
, /* name */
422 bfd_target_aout_flavour
,
423 #ifdef TARGET_IS_BIG_ENDIAN_P
424 true, /* target byte order (big) */
425 true, /* target headers byte order (big) */
427 false, /* target byte order (little) */
428 false, /* target headers byte order (little) */
430 (HAS_RELOC
| EXEC_P
| /* object flags */
431 HAS_LINENO
| HAS_DEBUG
|
432 HAS_SYMS
| HAS_LOCALS
| DYNAMIC
| WP_TEXT
| D_PAGED
),
433 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
), /* section flags */
434 MY_symbol_leading_char
,
435 AR_PAD_CHAR
, /* ar_pad_char */
436 15, /* ar_max_namelen */
437 3, /* minimum alignment */
438 #ifdef TARGET_IS_BIG_ENDIAN_P
439 bfd_getb64
, bfd_getb_signed_64
, bfd_putb64
,
440 bfd_getb32
, bfd_getb_signed_32
, bfd_putb32
,
441 bfd_getb16
, bfd_getb_signed_16
, bfd_putb16
, /* data */
442 bfd_getb64
, bfd_getb_signed_64
, bfd_putb64
,
443 bfd_getb32
, bfd_getb_signed_32
, bfd_putb32
,
444 bfd_getb16
, bfd_getb_signed_16
, bfd_putb16
, /* hdrs */
446 bfd_getl64
, bfd_getl_signed_64
, bfd_putl64
,
447 bfd_getl32
, bfd_getl_signed_32
, bfd_putl32
,
448 bfd_getl16
, bfd_getl_signed_16
, bfd_putl16
, /* data */
449 bfd_getl64
, bfd_getl_signed_64
, bfd_putl64
,
450 bfd_getl32
, bfd_getl_signed_32
, bfd_putl32
,
451 bfd_getl16
, bfd_getl_signed_16
, bfd_putl16
, /* hdrs */
453 {_bfd_dummy_target
, MY_object_p
, /* bfd_check_format */
454 bfd_generic_archive_p
, MY_core_file_p
},
455 {bfd_false
, MY_mkobject
, /* bfd_set_format */
456 _bfd_generic_mkarchive
, bfd_false
},
457 {bfd_false
, MY_write_object_contents
, /* bfd_write_contents */
458 _bfd_write_archive_contents
, bfd_false
},
461 (PTR
) MY_backend_data
,
463 #endif /* MY_BFD_TARGET */