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);
33 /* Calculate the file positions of the parts of a newly read aout header */
34 obj_textsec (abfd)->_raw_size = N_TXTSIZE(*execp);
36 /* The virtual memory addresses of the sections */
37 obj_textsec (abfd)->vma = N_TXTADDR(*execp);
38 obj_datasec (abfd)->vma = N_DATADDR(*execp);
39 obj_bsssec (abfd)->vma = N_BSSADDR(*execp);
41 /* The file offsets of the sections */
42 obj_textsec (abfd)->filepos = N_TXTOFF (*execp);
43 obj_datasec (abfd)->filepos = N_DATOFF (*execp);
45 /* The file offsets of the relocation info */
46 obj_textsec (abfd)->rel_filepos = N_TRELOFF(*execp);
47 obj_datasec (abfd)->rel_filepos = N_DRELOFF(*execp);
49 /* The file offsets of the string table and symbol table. */
50 obj_sym_filepos (abfd) = N_SYMOFF (*execp);
51 obj_str_filepos (abfd) = N_STROFF (*execp);
53 /* Determine the architecture and machine type of the object file. */
55 SET_ARCH_MACH(abfd, *execp);
57 bfd_default_set_arch_mach(abfd, DEFAULT_ARCH, 0);
60 adata(abfd).page_size = PAGE_SIZE;
62 adata(abfd).segment_size = SEGMENT_SIZE;
64 adata(abfd).segment_size = PAGE_SIZE;
66 adata(abfd).exec_bytes_size = EXEC_BYTES_SIZE;
72 /* Finish up the reading of an a.out file header */
75 DEFUN(MY(object_p),(abfd),
78 struct external_exec exec_bytes; /* Raw exec header from file */
79 struct internal_exec exec; /* Cleaned-up exec header */
82 if (bfd_read ((PTR) &exec_bytes, 1, EXEC_BYTES_SIZE, abfd)
84 bfd_error = wrong_format;
88 exec.a_info = bfd_h_get_32 (abfd, exec_bytes.e_info);
90 if (N_BADMAG (exec)) return 0;
92 NAME(aout,swap_exec_header_in)(abfd, &exec_bytes, &exec);
93 target = NAME(aout,some_aout_object_p) (abfd, &exec, MY(callback));
95 #ifdef ENTRY_CAN_BE_ZERO
96 /* The NEWSOS3 entry-point is/was 0, which (amongst other lossage)
97 * means that it isn't obvious if EXEC_P should be set.
98 * All of the following must be true for an executable:
99 * There must be no relocations, the bfd can be neither an
100 * archive nor an archive element, and the file must be executable. */
102 if (exec.a_trsize + exec.a_drsize == 0
103 && bfd_get_format(abfd) == bfd_object && abfd->my_archive == NULL)
107 #define S_IXUSR 0100 /* Execute by owner. */
109 if (stat(abfd->filename, &buf) == 0 && (buf.st_mode & S_IXUSR))
110 abfd->flags |= EXEC_P;
112 #endif /* ENTRY_CAN_BE_ZERO */
116 #define MY_object_p MY(object_p)
122 DEFUN(MY(mkobject),(abfd),
125 if (NAME(aout,mkobject)(abfd) == false)
127 adata(abfd).page_size = PAGE_SIZE;
129 adata(abfd).segment_size = SEGMENT_SIZE;
131 adata(abfd).segment_size = PAGE_SIZE;
133 adata(abfd).exec_bytes_size = EXEC_BYTES_SIZE;
136 #define MY_mkobject MY(mkobject)
139 /* Write an object file.
140 Section contents have already been written. We write the
141 file header, symbols, and relocation. */
143 #ifndef MY_write_object_contents
145 DEFUN(MY(write_object_contents),(abfd),
148 bfd_size_type data_pad = 0;
149 struct external_exec exec_bytes;
150 struct internal_exec *execp = exec_hdr (abfd);
152 #if CHOOSE_RELOC_SIZE
153 CHOOSE_RELOC_SIZE(abfd);
155 obj_reloc_entry_size (abfd) = RELOC_STD_SIZE;
158 WRITE_HEADERS(abfd, execp);
162 #define MY_write_object_contents MY(write_object_contents)
165 /* We assume BFD generic archive files. */
166 #ifndef MY_openr_next_archived_file
167 #define MY_openr_next_archived_file bfd_generic_openr_next_archived_file
169 #ifndef MY_generic_stat_arch_elt
170 #define MY_generic_stat_arch_elt bfd_generic_stat_arch_elt
172 #ifndef MY_slurp_armap
173 #define MY_slurp_armap bfd_slurp_bsd_armap
175 #ifndef MY_slurp_extended_name_table
176 #define MY_slurp_extended_name_table _bfd_slurp_extended_name_table
178 #ifndef MY_write_armap
179 #define MY_write_armap bsd_write_armap
181 #ifndef MY_truncate_arname
182 #define MY_truncate_arname bfd_bsd_truncate_arname
185 /* No core file defined here -- configure in trad-core.c separately. */
186 #ifndef MY_core_file_failing_command
187 #define MY_core_file_failing_command _bfd_dummy_core_file_failing_command
189 #ifndef MY_core_file_failing_signal
190 #define MY_core_file_failing_signal _bfd_dummy_core_file_failing_signal
192 #ifndef MY_core_file_matches_executable_p
193 #define MY_core_file_matches_executable_p \
194 _bfd_dummy_core_file_matches_executable_p
196 #ifndef MY_core_file_p
197 #define MY_core_file_p _bfd_dummy_target
200 #ifndef MY_bfd_debug_info_start
201 #define MY_bfd_debug_info_start bfd_void
203 #ifndef MY_bfd_debug_info_end
204 #define MY_bfd_debug_info_end bfd_void
206 #ifndef MY_bfd_debug_info_accumulate
207 #define MY_bfd_debug_info_accumulate (PROTO(void,(*),(bfd*, struct sec *))) bfd_void
210 #ifndef MY_core_file_failing_command
211 #define MY_core_file_failing_command NAME(aout,core_file_failing_command)
213 #ifndef MY_core_file_failing_signal
214 #define MY_core_file_failing_signal NAME(aout,core_file_failing_signal)
216 #ifndef MY_core_file_matches_executable_p
217 #define MY_core_file_matches_executable_p NAME(aout,core_file_matches_executable_p)
219 #ifndef MY_slurp_armap
220 #define MY_slurp_armap NAME(aout,slurp_armap)
222 #ifndef MY_slurp_extended_name_table
223 #define MY_slurp_extended_name_table NAME(aout,slurp_extended_name_table)
225 #ifndef MY_truncate_arname
226 #define MY_truncate_arname NAME(aout,truncate_arname)
228 #ifndef MY_write_armap
229 #define MY_write_armap NAME(aout,write_armap)
231 #ifndef MY_close_and_cleanup
232 #define MY_close_and_cleanup NAME(aout,close_and_cleanup)
234 #ifndef MY_set_section_contents
235 #define MY_set_section_contents NAME(aout,set_section_contents)
237 #ifndef MY_get_section_contents
238 #define MY_get_section_contents NAME(aout,get_section_contents)
240 #ifndef MY_new_section_hook
241 #define MY_new_section_hook NAME(aout,new_section_hook)
243 #ifndef MY_get_symtab_upper_bound
244 #define MY_get_symtab_upper_bound NAME(aout,get_symtab_upper_bound)
246 #ifndef MY_get_symtab
247 #define MY_get_symtab NAME(aout,get_symtab)
249 #ifndef MY_get_reloc_upper_bound
250 #define MY_get_reloc_upper_bound NAME(aout,get_reloc_upper_bound)
252 #ifndef MY_canonicalize_reloc
253 #define MY_canonicalize_reloc NAME(aout,canonicalize_reloc)
255 #ifndef MY_make_empty_symbol
256 #define MY_make_empty_symbol NAME(aout,make_empty_symbol)
258 #ifndef MY_print_symbol
259 #define MY_print_symbol NAME(aout,print_symbol)
261 #ifndef MY_get_lineno
262 #define MY_get_lineno NAME(aout,get_lineno)
264 #ifndef MY_set_arch_mach
265 #define MY_set_arch_mach NAME(aout,set_arch_mach)
267 #ifndef MY_openr_next_archived_file
268 #define MY_openr_next_archived_file NAME(aout,openr_next_archived_file)
270 #ifndef MY_find_nearest_line
271 #define MY_find_nearest_line NAME(aout,find_nearest_line)
273 #ifndef MY_generic_stat_arch_elt
274 #define MY_generic_stat_arch_elt NAME(aout,generic_stat_arch_elt)
276 #ifndef MY_sizeof_headers
277 #define MY_sizeof_headers NAME(aout,sizeof_headers)
279 #ifndef MY_bfd_debug_info_start
280 #define MY_bfd_debug_info_start NAME(aout,bfd_debug_info_start)
282 #ifndef MY_bfd_debug_info_end
283 #define MY_bfd_debug_info_end NAME(aout,bfd_debug_info_end)
285 #ifndef MY_bfd_debug_info_accumulat
286 #define MY_bfd_debug_info_accumulat NAME(aout,bfd_debug_info_accumulat)
288 #ifndef MY_reloc_howto_type_lookup
289 #define MY_reloc_howto_type_lookup 0
291 #ifndef MY_make_debug_symbol
292 #define MY_make_debug_symbol 0
294 #ifndef MY_backend_data
295 #define MY_backend_data (PTR) 0
300 TARGETNAME, /* name */
301 bfd_target_aout_flavour,
302 #ifdef TARGET_IS_BIG_ENDIAN_P
303 true, /* target byte order (big) */
304 true, /* target headers byte order (big) */
306 false, /* target byte order (little) */
307 false, /* target headers byte order (little) */
309 (HAS_RELOC | EXEC_P | /* object flags */
310 HAS_LINENO | HAS_DEBUG |
311 HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED),
312 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
313 ' ', /* ar_pad_char */
314 15, /* ar_max_namelen */
315 1, /* minimum alignment */
316 #ifdef TARGET_IS_BIG_ENDIAN_P
317 _do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16, /* data */
318 _do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16, /* hdrs */
320 _do_getl64, _do_putl64, _do_getl32, _do_putl32, _do_getl16, _do_putl16, /* data */
321 _do_getl64, _do_putl64, _do_getl32, _do_putl32, _do_getl16, _do_putl16, /* hdrs */
323 {_bfd_dummy_target, MY_object_p, /* bfd_check_format */
324 bfd_generic_archive_p, MY_core_file_p},
325 {bfd_false, MY_mkobject, /* bfd_set_format */
326 _bfd_generic_mkarchive, bfd_false},
327 {bfd_false, MY_write_object_contents, /* bfd_write_contents */
328 _bfd_write_archive_contents, bfd_false},
330 MY_core_file_failing_command,
331 MY_core_file_failing_signal,
332 MY_core_file_matches_executable_p,
334 MY_slurp_extended_name_table,
337 MY_close_and_cleanup,
338 MY_set_section_contents,
339 MY_get_section_contents,
341 MY_get_symtab_upper_bound,
343 MY_get_reloc_upper_bound,
344 MY_canonicalize_reloc,
345 MY_make_empty_symbol,
349 MY_openr_next_archived_file,
350 MY_find_nearest_line,
351 MY_generic_stat_arch_elt,
353 MY_bfd_debug_info_start,
354 MY_bfd_debug_info_end,
355 MY_bfd_debug_info_accumulate,
356 bfd_generic_get_relocated_section_contents,
357 bfd_generic_relax_section,
358 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* COFF stuff?! */
359 MY_reloc_howto_type_lookup,
360 MY_make_debug_symbol,
361 (PTR) MY_backend_data,