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 */
197 0, /* exec header is counted */
199 #define MY_backend_data &MY(backend_data)
202 /* We assume BFD generic archive files. */
203 #ifndef MY_openr_next_archived_file
204 #define MY_openr_next_archived_file bfd_generic_openr_next_archived_file
206 #ifndef MY_generic_stat_arch_elt
207 #define MY_generic_stat_arch_elt bfd_generic_stat_arch_elt
209 #ifndef MY_slurp_armap
210 #define MY_slurp_armap bfd_slurp_bsd_armap
212 #ifndef MY_slurp_extended_name_table
213 #define MY_slurp_extended_name_table _bfd_slurp_extended_name_table
215 #ifndef MY_write_armap
216 #define MY_write_armap bsd_write_armap
218 #ifndef MY_truncate_arname
219 #define MY_truncate_arname bfd_bsd_truncate_arname
222 /* No core file defined here -- configure in trad-core.c separately. */
223 #ifndef MY_core_file_failing_command
224 #define MY_core_file_failing_command _bfd_dummy_core_file_failing_command
226 #ifndef MY_core_file_failing_signal
227 #define MY_core_file_failing_signal _bfd_dummy_core_file_failing_signal
229 #ifndef MY_core_file_matches_executable_p
230 #define MY_core_file_matches_executable_p \
231 _bfd_dummy_core_file_matches_executable_p
233 #ifndef MY_core_file_p
234 #define MY_core_file_p _bfd_dummy_target
237 #ifndef MY_bfd_debug_info_start
238 #define MY_bfd_debug_info_start bfd_void
240 #ifndef MY_bfd_debug_info_end
241 #define MY_bfd_debug_info_end bfd_void
243 #ifndef MY_bfd_debug_info_accumulate
244 #define MY_bfd_debug_info_accumulate \
245 (void (*) PARAMS ((bfd*, struct sec *))) bfd_void
248 #ifndef MY_core_file_failing_command
249 #define MY_core_file_failing_command NAME(aout,core_file_failing_command)
251 #ifndef MY_core_file_failing_signal
252 #define MY_core_file_failing_signal NAME(aout,core_file_failing_signal)
254 #ifndef MY_core_file_matches_executable_p
255 #define MY_core_file_matches_executable_p NAME(aout,core_file_matches_executable_p)
257 #ifndef MY_slurp_armap
258 #define MY_slurp_armap NAME(aout,slurp_armap)
260 #ifndef MY_slurp_extended_name_table
261 #define MY_slurp_extended_name_table NAME(aout,slurp_extended_name_table)
263 #ifndef MY_truncate_arname
264 #define MY_truncate_arname NAME(aout,truncate_arname)
266 #ifndef MY_write_armap
267 #define MY_write_armap NAME(aout,write_armap)
269 #ifndef MY_close_and_cleanup
270 #define MY_close_and_cleanup NAME(aout,close_and_cleanup)
272 #ifndef MY_set_section_contents
273 #define MY_set_section_contents NAME(aout,set_section_contents)
275 #ifndef MY_get_section_contents
276 #define MY_get_section_contents NAME(aout,get_section_contents)
278 #ifndef MY_new_section_hook
279 #define MY_new_section_hook NAME(aout,new_section_hook)
281 #ifndef MY_get_symtab_upper_bound
282 #define MY_get_symtab_upper_bound NAME(aout,get_symtab_upper_bound)
284 #ifndef MY_get_symtab
285 #define MY_get_symtab NAME(aout,get_symtab)
287 #ifndef MY_get_reloc_upper_bound
288 #define MY_get_reloc_upper_bound NAME(aout,get_reloc_upper_bound)
290 #ifndef MY_canonicalize_reloc
291 #define MY_canonicalize_reloc NAME(aout,canonicalize_reloc)
293 #ifndef MY_make_empty_symbol
294 #define MY_make_empty_symbol NAME(aout,make_empty_symbol)
296 #ifndef MY_print_symbol
297 #define MY_print_symbol NAME(aout,print_symbol)
299 #ifndef MY_get_lineno
300 #define MY_get_lineno NAME(aout,get_lineno)
302 #ifndef MY_set_arch_mach
303 #define MY_set_arch_mach NAME(aout,set_arch_mach)
305 #ifndef MY_openr_next_archived_file
306 #define MY_openr_next_archived_file NAME(aout,openr_next_archived_file)
308 #ifndef MY_find_nearest_line
309 #define MY_find_nearest_line NAME(aout,find_nearest_line)
311 #ifndef MY_generic_stat_arch_elt
312 #define MY_generic_stat_arch_elt NAME(aout,generic_stat_arch_elt)
314 #ifndef MY_sizeof_headers
315 #define MY_sizeof_headers NAME(aout,sizeof_headers)
317 #ifndef MY_bfd_debug_info_start
318 #define MY_bfd_debug_info_start NAME(aout,bfd_debug_info_start)
320 #ifndef MY_bfd_debug_info_end
321 #define MY_bfd_debug_info_end NAME(aout,bfd_debug_info_end)
323 #ifndef MY_bfd_debug_info_accumulat
324 #define MY_bfd_debug_info_accumulat NAME(aout,bfd_debug_info_accumulat)
326 #ifndef MY_reloc_howto_type_lookup
327 #define MY_reloc_howto_type_lookup NAME(aout,reloc_type_lookup)
329 #ifndef MY_make_debug_symbol
330 #define MY_make_debug_symbol 0
333 /* Aout symbols normally have leading underscores */
334 #ifndef MY_symbol_leading_char
335 #define MY_symbol_leading_char '_'
340 TARGETNAME, /* name */
341 bfd_target_aout_flavour,
342 #ifdef TARGET_IS_BIG_ENDIAN_P
343 true, /* target byte order (big) */
344 true, /* target headers byte order (big) */
346 false, /* target byte order (little) */
347 false, /* target headers byte order (little) */
349 (HAS_RELOC | EXEC_P | /* object flags */
350 HAS_LINENO | HAS_DEBUG |
351 HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED),
352 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
353 MY_symbol_leading_char,
354 ' ', /* ar_pad_char */
355 15, /* ar_max_namelen */
356 1, /* minimum alignment */
357 #ifdef TARGET_IS_BIG_ENDIAN_P
358 _do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16, /* data */
359 _do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16, /* hdrs */
361 _do_getl64, _do_putl64, _do_getl32, _do_putl32, _do_getl16, _do_putl16, /* data */
362 _do_getl64, _do_putl64, _do_getl32, _do_putl32, _do_getl16, _do_putl16, /* hdrs */
364 {_bfd_dummy_target, MY_object_p, /* bfd_check_format */
365 bfd_generic_archive_p, MY_core_file_p},
366 {bfd_false, MY_mkobject, /* bfd_set_format */
367 _bfd_generic_mkarchive, bfd_false},
368 {bfd_false, MY_write_object_contents, /* bfd_write_contents */
369 _bfd_write_archive_contents, bfd_false},
371 MY_core_file_failing_command,
372 MY_core_file_failing_signal,
373 MY_core_file_matches_executable_p,
375 MY_slurp_extended_name_table,
378 MY_close_and_cleanup,
379 MY_set_section_contents,
380 MY_get_section_contents,
382 MY_get_symtab_upper_bound,
384 MY_get_reloc_upper_bound,
385 MY_canonicalize_reloc,
386 MY_make_empty_symbol,
390 MY_openr_next_archived_file,
391 MY_find_nearest_line,
392 MY_generic_stat_arch_elt,
394 MY_bfd_debug_info_start,
395 MY_bfd_debug_info_end,
396 MY_bfd_debug_info_accumulate,
397 bfd_generic_get_relocated_section_contents,
398 bfd_generic_relax_section,
399 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* COFF stuff?! */
400 MY_reloc_howto_type_lookup,
401 MY_make_debug_symbol,
402 (PTR) MY_backend_data,