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 /* Set parameters about this a.out file that are machine-dependent.
26 This routine is called from some_aout_object_p just before it returns. */
28 DEFUN(MY(callback),(abfd),
31 struct internal_exec *execp = exec_hdr (abfd);
32 struct aout_backend_data *abdp;
34 /* Calculate the file positions of the parts of a newly read aout header */
35 obj_textsec (abfd)->_raw_size = N_TXTSIZE(*execp);
37 /* The virtual memory addresses of the sections */
38 obj_textsec (abfd)->vma = N_TXTADDR(*execp);
39 obj_datasec (abfd)->vma = N_DATADDR(*execp);
40 obj_bsssec (abfd)->vma = N_BSSADDR(*execp);
42 /* The file offsets of the sections */
43 obj_textsec (abfd)->filepos = N_TXTOFF (*execp);
44 obj_datasec (abfd)->filepos = N_DATOFF (*execp);
46 /* The file offsets of the relocation info */
47 obj_textsec (abfd)->rel_filepos = N_TRELOFF(*execp);
48 obj_datasec (abfd)->rel_filepos = N_DRELOFF(*execp);
50 /* The file offsets of the string table and symbol table. */
51 obj_sym_filepos (abfd) = N_SYMOFF (*execp);
52 obj_str_filepos (abfd) = N_STROFF (*execp);
54 /* Determine the architecture and machine type of the object file. */
56 SET_ARCH_MACH(abfd, *execp);
58 bfd_default_set_arch_mach(abfd, DEFAULT_ARCH, 0);
61 /* Don't set sizes now -- can't be sure until we know arch & mach.
62 Sizes get set in set_sizes callback, later. */
64 adata(abfd).page_size = PAGE_SIZE;
66 adata(abfd).segment_size = SEGMENT_SIZE;
68 adata(abfd).segment_size = PAGE_SIZE;
70 adata(abfd).exec_bytes_size = EXEC_BYTES_SIZE;
77 /* Finish up the reading of an a.out file header */
80 DEFUN(MY(object_p),(abfd),
83 struct external_exec exec_bytes; /* Raw exec header from file */
84 struct internal_exec exec; /* Cleaned-up exec header */
87 if (bfd_read ((PTR) &exec_bytes, 1, EXEC_BYTES_SIZE, abfd)
89 bfd_error = wrong_format;
93 exec.a_info = bfd_h_get_32 (abfd, exec_bytes.e_info);
95 if (N_BADMAG (exec)) return 0;
97 NAME(aout,swap_exec_header_in)(abfd, &exec_bytes, &exec);
98 target = NAME(aout,some_aout_object_p) (abfd, &exec, MY(callback));
100 #ifdef ENTRY_CAN_BE_ZERO
101 /* The NEWSOS3 entry-point is/was 0, which (amongst other lossage)
102 * means that it isn't obvious if EXEC_P should be set.
103 * All of the following must be true for an executable:
104 * There must be no relocations, the bfd can be neither an
105 * archive nor an archive element, and the file must be executable. */
107 if (exec.a_trsize + exec.a_drsize == 0
108 && bfd_get_format(abfd) == bfd_object && abfd->my_archive == NULL)
112 #define S_IXUSR 0100 /* Execute by owner. */
114 if (stat(abfd->filename, &buf) == 0 && (buf.st_mode & S_IXUSR))
115 abfd->flags |= EXEC_P;
117 #endif /* ENTRY_CAN_BE_ZERO */
121 #define MY_object_p MY(object_p)
127 DEFUN(MY(mkobject),(abfd),
130 if (NAME(aout,mkobject)(abfd) == false)
132 #if 0 /* Sizes get set in set_sizes callback, later, after we know
133 the architecture and machine. */
134 adata(abfd).page_size = PAGE_SIZE;
136 adata(abfd).segment_size = SEGMENT_SIZE;
138 adata(abfd).segment_size = PAGE_SIZE;
140 adata(abfd).exec_bytes_size = EXEC_BYTES_SIZE;
144 #define MY_mkobject MY(mkobject)
147 /* Write an object file.
148 Section contents have already been written. We write the
149 file header, symbols, and relocation. */
151 #ifndef MY_write_object_contents
153 DEFUN(MY(write_object_contents),(abfd),
156 bfd_size_type data_pad = 0;
157 struct external_exec exec_bytes;
158 struct internal_exec *execp = exec_hdr (abfd);
160 #if CHOOSE_RELOC_SIZE
161 CHOOSE_RELOC_SIZE(abfd);
163 obj_reloc_entry_size (abfd) = RELOC_STD_SIZE;
166 WRITE_HEADERS(abfd, execp);
170 #define MY_write_object_contents MY(write_object_contents)
175 DEFUN(MY(set_sizes),(abfd), bfd *abfd)
177 adata(abfd).page_size = PAGE_SIZE;
179 adata(abfd).segment_size = SEGMENT_SIZE;
181 adata(abfd).segment_size = PAGE_SIZE;
183 adata(abfd).exec_bytes_size = EXEC_BYTES_SIZE;
186 #define MY_set_sizes MY(set_sizes)
189 #ifndef MY_backend_data
190 static CONST struct aout_backend_data MY(backend_data) = {
191 0, /* zmagic contiguous */
192 0, /* text incl header */
196 #define MY_backend_data &MY(backend_data)
199 /* We assume BFD generic archive files. */
200 #ifndef MY_openr_next_archived_file
201 #define MY_openr_next_archived_file bfd_generic_openr_next_archived_file
203 #ifndef MY_generic_stat_arch_elt
204 #define MY_generic_stat_arch_elt bfd_generic_stat_arch_elt
206 #ifndef MY_slurp_armap
207 #define MY_slurp_armap bfd_slurp_bsd_armap
209 #ifndef MY_slurp_extended_name_table
210 #define MY_slurp_extended_name_table _bfd_slurp_extended_name_table
212 #ifndef MY_write_armap
213 #define MY_write_armap bsd_write_armap
215 #ifndef MY_truncate_arname
216 #define MY_truncate_arname bfd_bsd_truncate_arname
219 /* No core file defined here -- configure in trad-core.c separately. */
220 #ifndef MY_core_file_failing_command
221 #define MY_core_file_failing_command _bfd_dummy_core_file_failing_command
223 #ifndef MY_core_file_failing_signal
224 #define MY_core_file_failing_signal _bfd_dummy_core_file_failing_signal
226 #ifndef MY_core_file_matches_executable_p
227 #define MY_core_file_matches_executable_p \
228 _bfd_dummy_core_file_matches_executable_p
230 #ifndef MY_core_file_p
231 #define MY_core_file_p _bfd_dummy_target
234 #ifndef MY_bfd_debug_info_start
235 #define MY_bfd_debug_info_start bfd_void
237 #ifndef MY_bfd_debug_info_end
238 #define MY_bfd_debug_info_end bfd_void
240 #ifndef MY_bfd_debug_info_accumulate
241 #define MY_bfd_debug_info_accumulate (PROTO(void,(*),(bfd*, struct sec *))) bfd_void
244 #ifndef MY_core_file_failing_command
245 #define MY_core_file_failing_command NAME(aout,core_file_failing_command)
247 #ifndef MY_core_file_failing_signal
248 #define MY_core_file_failing_signal NAME(aout,core_file_failing_signal)
250 #ifndef MY_core_file_matches_executable_p
251 #define MY_core_file_matches_executable_p NAME(aout,core_file_matches_executable_p)
253 #ifndef MY_slurp_armap
254 #define MY_slurp_armap NAME(aout,slurp_armap)
256 #ifndef MY_slurp_extended_name_table
257 #define MY_slurp_extended_name_table NAME(aout,slurp_extended_name_table)
259 #ifndef MY_truncate_arname
260 #define MY_truncate_arname NAME(aout,truncate_arname)
262 #ifndef MY_write_armap
263 #define MY_write_armap NAME(aout,write_armap)
265 #ifndef MY_close_and_cleanup
266 #define MY_close_and_cleanup NAME(aout,close_and_cleanup)
268 #ifndef MY_set_section_contents
269 #define MY_set_section_contents NAME(aout,set_section_contents)
271 #ifndef MY_get_section_contents
272 #define MY_get_section_contents NAME(aout,get_section_contents)
274 #ifndef MY_new_section_hook
275 #define MY_new_section_hook NAME(aout,new_section_hook)
277 #ifndef MY_get_symtab_upper_bound
278 #define MY_get_symtab_upper_bound NAME(aout,get_symtab_upper_bound)
280 #ifndef MY_get_symtab
281 #define MY_get_symtab NAME(aout,get_symtab)
283 #ifndef MY_get_reloc_upper_bound
284 #define MY_get_reloc_upper_bound NAME(aout,get_reloc_upper_bound)
286 #ifndef MY_canonicalize_reloc
287 #define MY_canonicalize_reloc NAME(aout,canonicalize_reloc)
289 #ifndef MY_make_empty_symbol
290 #define MY_make_empty_symbol NAME(aout,make_empty_symbol)
292 #ifndef MY_print_symbol
293 #define MY_print_symbol NAME(aout,print_symbol)
295 #ifndef MY_get_lineno
296 #define MY_get_lineno NAME(aout,get_lineno)
298 #ifndef MY_set_arch_mach
299 #define MY_set_arch_mach NAME(aout,set_arch_mach)
301 #ifndef MY_openr_next_archived_file
302 #define MY_openr_next_archived_file NAME(aout,openr_next_archived_file)
304 #ifndef MY_find_nearest_line
305 #define MY_find_nearest_line NAME(aout,find_nearest_line)
307 #ifndef MY_generic_stat_arch_elt
308 #define MY_generic_stat_arch_elt NAME(aout,generic_stat_arch_elt)
310 #ifndef MY_sizeof_headers
311 #define MY_sizeof_headers NAME(aout,sizeof_headers)
313 #ifndef MY_bfd_debug_info_start
314 #define MY_bfd_debug_info_start NAME(aout,bfd_debug_info_start)
316 #ifndef MY_bfd_debug_info_end
317 #define MY_bfd_debug_info_end NAME(aout,bfd_debug_info_end)
319 #ifndef MY_bfd_debug_info_accumulat
320 #define MY_bfd_debug_info_accumulat NAME(aout,bfd_debug_info_accumulat)
322 #ifndef MY_reloc_howto_type_lookup
323 #define MY_reloc_howto_type_lookup 0
325 #ifndef MY_make_debug_symbol
326 #define MY_make_debug_symbol 0
329 /* Aout symbols normally have leading underscores */
330 #ifndef MY_symbol_leading_char
331 #define MY_symbol_leading_char '_'
336 TARGETNAME, /* name */
337 bfd_target_aout_flavour,
338 #ifdef TARGET_IS_BIG_ENDIAN_P
339 true, /* target byte order (big) */
340 true, /* target headers byte order (big) */
342 false, /* target byte order (little) */
343 false, /* target headers byte order (little) */
345 (HAS_RELOC | EXEC_P | /* object flags */
346 HAS_LINENO | HAS_DEBUG |
347 HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED),
348 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
349 MY_symbol_leading_char,
350 ' ', /* ar_pad_char */
351 15, /* ar_max_namelen */
352 1, /* minimum alignment */
353 #ifdef TARGET_IS_BIG_ENDIAN_P
354 _do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16, /* data */
355 _do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16, /* hdrs */
357 _do_getl64, _do_putl64, _do_getl32, _do_putl32, _do_getl16, _do_putl16, /* data */
358 _do_getl64, _do_putl64, _do_getl32, _do_putl32, _do_getl16, _do_putl16, /* hdrs */
360 {_bfd_dummy_target, MY_object_p, /* bfd_check_format */
361 bfd_generic_archive_p, MY_core_file_p},
362 {bfd_false, MY_mkobject, /* bfd_set_format */
363 _bfd_generic_mkarchive, bfd_false},
364 {bfd_false, MY_write_object_contents, /* bfd_write_contents */
365 _bfd_write_archive_contents, bfd_false},
367 MY_core_file_failing_command,
368 MY_core_file_failing_signal,
369 MY_core_file_matches_executable_p,
371 MY_slurp_extended_name_table,
374 MY_close_and_cleanup,
375 MY_set_section_contents,
376 MY_get_section_contents,
378 MY_get_symtab_upper_bound,
380 MY_get_reloc_upper_bound,
381 MY_canonicalize_reloc,
382 MY_make_empty_symbol,
386 MY_openr_next_archived_file,
387 MY_find_nearest_line,
388 MY_generic_stat_arch_elt,
390 MY_bfd_debug_info_start,
391 MY_bfd_debug_info_end,
392 MY_bfd_debug_info_accumulate,
393 bfd_generic_get_relocated_section_contents,
394 bfd_generic_relax_section,
395 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* COFF stuff?! */
396 MY_reloc_howto_type_lookup,
397 MY_make_debug_symbol,
398 (PTR) MY_backend_data,