1 /* Define a target vector and some small routines for a variant of a.out.
2 Copyright (C) 1990-1991 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. */
31 DEFUN(MY(callback),(abfd),
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 */
83 DEFUN(MY(object_p),(abfd),
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_error = wrong_format;
96 exec.a_info = bfd_h_get_32 (abfd, exec_bytes.e_info);
98 if (N_BADMAG (exec)) return 0;
100 NAME(aout,swap_exec_header_in)(abfd, &exec_bytes, &exec);
101 target = NAME(aout,some_aout_object_p) (abfd, &exec, MY(callback));
103 #ifdef ENTRY_CAN_BE_ZERO
104 /* The NEWSOS3 entry-point is/was 0, which (amongst other lossage)
105 * means that it isn't obvious if EXEC_P should be set.
106 * All of the following must be true for an executable:
107 * There must be no relocations, the bfd can be neither an
108 * archive nor an archive element, and the file must be executable. */
110 if (exec.a_trsize + exec.a_drsize == 0
111 && bfd_get_format(abfd) == bfd_object && abfd->my_archive == NULL)
115 #define S_IXUSR 0100 /* Execute by owner. */
117 if (stat(abfd->filename, &buf) == 0 && (buf.st_mode & S_IXUSR))
118 abfd->flags |= EXEC_P;
120 #endif /* ENTRY_CAN_BE_ZERO */
124 #define MY_object_p MY(object_p)
130 DEFUN(MY(mkobject),(abfd),
133 if (NAME(aout,mkobject)(abfd) == false)
135 #if 0 /* Sizes get set in set_sizes callback, later, after we know
136 the architecture and machine. */
137 adata(abfd).page_size = PAGE_SIZE;
139 adata(abfd).segment_size = SEGMENT_SIZE;
141 adata(abfd).segment_size = PAGE_SIZE;
143 adata(abfd).exec_bytes_size = EXEC_BYTES_SIZE;
147 #define MY_mkobject MY(mkobject)
150 /* Write an object file.
151 Section contents have already been written. We write the
152 file header, symbols, and relocation. */
154 #ifndef MY_write_object_contents
156 DEFUN(MY(write_object_contents),(abfd),
159 struct external_exec exec_bytes;
160 struct internal_exec *execp = exec_hdr (abfd);
162 #if CHOOSE_RELOC_SIZE
163 CHOOSE_RELOC_SIZE(abfd);
165 obj_reloc_entry_size (abfd) = RELOC_STD_SIZE;
168 WRITE_HEADERS(abfd, execp);
172 #define MY_write_object_contents MY(write_object_contents)
177 DEFUN(MY(set_sizes),(abfd), bfd *abfd)
179 adata(abfd).page_size = PAGE_SIZE;
181 adata(abfd).segment_size = SEGMENT_SIZE;
183 adata(abfd).segment_size = PAGE_SIZE;
185 adata(abfd).exec_bytes_size = EXEC_BYTES_SIZE;
188 #define MY_set_sizes MY(set_sizes)
191 #ifndef MY_backend_data
192 static CONST struct aout_backend_data MY(backend_data) = {
193 0, /* zmagic contiguous */
194 0, /* text incl header */
198 #define MY_backend_data &MY(backend_data)
201 /* We assume BFD generic archive files. */
202 #ifndef MY_openr_next_archived_file
203 #define MY_openr_next_archived_file bfd_generic_openr_next_archived_file
205 #ifndef MY_generic_stat_arch_elt
206 #define MY_generic_stat_arch_elt bfd_generic_stat_arch_elt
208 #ifndef MY_slurp_armap
209 #define MY_slurp_armap bfd_slurp_bsd_armap
211 #ifndef MY_slurp_extended_name_table
212 #define MY_slurp_extended_name_table _bfd_slurp_extended_name_table
214 #ifndef MY_write_armap
215 #define MY_write_armap bsd_write_armap
217 #ifndef MY_truncate_arname
218 #define MY_truncate_arname bfd_bsd_truncate_arname
221 /* No core file defined here -- configure in trad-core.c separately. */
222 #ifndef MY_core_file_failing_command
223 #define MY_core_file_failing_command _bfd_dummy_core_file_failing_command
225 #ifndef MY_core_file_failing_signal
226 #define MY_core_file_failing_signal _bfd_dummy_core_file_failing_signal
228 #ifndef MY_core_file_matches_executable_p
229 #define MY_core_file_matches_executable_p \
230 _bfd_dummy_core_file_matches_executable_p
232 #ifndef MY_core_file_p
233 #define MY_core_file_p _bfd_dummy_target
236 #ifndef MY_bfd_debug_info_start
237 #define MY_bfd_debug_info_start bfd_void
239 #ifndef MY_bfd_debug_info_end
240 #define MY_bfd_debug_info_end bfd_void
242 #ifndef MY_bfd_debug_info_accumulate
243 #define MY_bfd_debug_info_accumulate (PROTO(void,(*),(bfd*, struct sec *))) bfd_void
246 #ifndef MY_core_file_failing_command
247 #define MY_core_file_failing_command NAME(aout,core_file_failing_command)
249 #ifndef MY_core_file_failing_signal
250 #define MY_core_file_failing_signal NAME(aout,core_file_failing_signal)
252 #ifndef MY_core_file_matches_executable_p
253 #define MY_core_file_matches_executable_p NAME(aout,core_file_matches_executable_p)
255 #ifndef MY_slurp_armap
256 #define MY_slurp_armap NAME(aout,slurp_armap)
258 #ifndef MY_slurp_extended_name_table
259 #define MY_slurp_extended_name_table NAME(aout,slurp_extended_name_table)
261 #ifndef MY_truncate_arname
262 #define MY_truncate_arname NAME(aout,truncate_arname)
264 #ifndef MY_write_armap
265 #define MY_write_armap NAME(aout,write_armap)
267 #ifndef MY_close_and_cleanup
268 #define MY_close_and_cleanup NAME(aout,close_and_cleanup)
270 #ifndef MY_set_section_contents
271 #define MY_set_section_contents NAME(aout,set_section_contents)
273 #ifndef MY_get_section_contents
274 #define MY_get_section_contents NAME(aout,get_section_contents)
276 #ifndef MY_new_section_hook
277 #define MY_new_section_hook NAME(aout,new_section_hook)
279 #ifndef MY_get_symtab_upper_bound
280 #define MY_get_symtab_upper_bound NAME(aout,get_symtab_upper_bound)
282 #ifndef MY_get_symtab
283 #define MY_get_symtab NAME(aout,get_symtab)
285 #ifndef MY_get_reloc_upper_bound
286 #define MY_get_reloc_upper_bound NAME(aout,get_reloc_upper_bound)
288 #ifndef MY_canonicalize_reloc
289 #define MY_canonicalize_reloc NAME(aout,canonicalize_reloc)
291 #ifndef MY_make_empty_symbol
292 #define MY_make_empty_symbol NAME(aout,make_empty_symbol)
294 #ifndef MY_print_symbol
295 #define MY_print_symbol NAME(aout,print_symbol)
297 #ifndef MY_get_lineno
298 #define MY_get_lineno NAME(aout,get_lineno)
300 #ifndef MY_set_arch_mach
301 #define MY_set_arch_mach NAME(aout,set_arch_mach)
303 #ifndef MY_openr_next_archived_file
304 #define MY_openr_next_archived_file NAME(aout,openr_next_archived_file)
306 #ifndef MY_find_nearest_line
307 #define MY_find_nearest_line NAME(aout,find_nearest_line)
309 #ifndef MY_generic_stat_arch_elt
310 #define MY_generic_stat_arch_elt NAME(aout,generic_stat_arch_elt)
312 #ifndef MY_sizeof_headers
313 #define MY_sizeof_headers NAME(aout,sizeof_headers)
315 #ifndef MY_bfd_debug_info_start
316 #define MY_bfd_debug_info_start NAME(aout,bfd_debug_info_start)
318 #ifndef MY_bfd_debug_info_end
319 #define MY_bfd_debug_info_end NAME(aout,bfd_debug_info_end)
321 #ifndef MY_bfd_debug_info_accumulat
322 #define MY_bfd_debug_info_accumulat NAME(aout,bfd_debug_info_accumulat)
324 #ifndef MY_reloc_howto_type_lookup
325 #define MY_reloc_howto_type_lookup NAME(aout,reloc_type_lookup)
327 #ifndef MY_make_debug_symbol
328 #define MY_make_debug_symbol 0
331 /* Aout symbols normally have leading underscores */
332 #ifndef MY_symbol_leading_char
333 #define MY_symbol_leading_char '_'
338 TARGETNAME, /* name */
339 bfd_target_aout_flavour,
340 #ifdef TARGET_IS_BIG_ENDIAN_P
341 true, /* target byte order (big) */
342 true, /* target headers byte order (big) */
344 false, /* target byte order (little) */
345 false, /* target headers byte order (little) */
347 (HAS_RELOC | EXEC_P | /* object flags */
348 HAS_LINENO | HAS_DEBUG |
349 HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED),
350 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
351 MY_symbol_leading_char,
352 ' ', /* ar_pad_char */
353 15, /* ar_max_namelen */
354 1, /* minimum alignment */
355 #ifdef TARGET_IS_BIG_ENDIAN_P
356 _do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16, /* data */
357 _do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16, /* hdrs */
359 _do_getl64, _do_putl64, _do_getl32, _do_putl32, _do_getl16, _do_putl16, /* data */
360 _do_getl64, _do_putl64, _do_getl32, _do_putl32, _do_getl16, _do_putl16, /* hdrs */
362 {_bfd_dummy_target, MY_object_p, /* bfd_check_format */
363 bfd_generic_archive_p, MY_core_file_p},
364 {bfd_false, MY_mkobject, /* bfd_set_format */
365 _bfd_generic_mkarchive, bfd_false},
366 {bfd_false, MY_write_object_contents, /* bfd_write_contents */
367 _bfd_write_archive_contents, bfd_false},
369 MY_core_file_failing_command,
370 MY_core_file_failing_signal,
371 MY_core_file_matches_executable_p,
373 MY_slurp_extended_name_table,
376 MY_close_and_cleanup,
377 MY_set_section_contents,
378 MY_get_section_contents,
380 MY_get_symtab_upper_bound,
382 MY_get_reloc_upper_bound,
383 MY_canonicalize_reloc,
384 MY_make_empty_symbol,
388 MY_openr_next_archived_file,
389 MY_find_nearest_line,
390 MY_generic_stat_arch_elt,
392 MY_bfd_debug_info_start,
393 MY_bfd_debug_info_end,
394 MY_bfd_debug_info_accumulate,
395 bfd_generic_get_relocated_section_contents,
396 bfd_generic_relax_section,
397 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* COFF stuff?! */
398 MY_reloc_howto_type_lookup,
399 MY_make_debug_symbol,
400 (PTR) MY_backend_data,