comment on v9 stuff
[deliverable/binutils-gdb.git] / bfd / aout-target.h
CommitLineData
582bc90a 1/* Define a target vector and some small routines for a variant of a.out.
f5419a59 2 Copyright (C) 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
e98e6ec1
SC
3
4This file is part of BFD, the Binary File Descriptor library.
5
6This program is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2 of the License, or
9(at your option) any later version.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with this program; if not, write to the Free Software
18Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
19
582bc90a
PB
20#include "aout/aout64.h"
21#include "aout/stab_gnu.h"
22#include "aout/ar.h"
23/*#include "libaout.h"*/
24
214f8f23
KR
25extern CONST struct reloc_howto_struct * NAME(aout,reloc_type_lookup) ();
26
e98e6ec1
SC
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. */
214f8f23 29#ifndef MY_callback
e98e6ec1 30static bfd_target *
57a1867e
DM
31MY(callback) (abfd)
32 bfd *abfd;
e98e6ec1
SC
33{
34 struct internal_exec *execp = exec_hdr (abfd);
294eaca4
SC
35
36 /* Calculate the file positions of the parts of a newly read aout header */
e98e6ec1
SC
37 obj_textsec (abfd)->_raw_size = N_TXTSIZE(*execp);
38
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);
43
44 /* The file offsets of the sections */
45 obj_textsec (abfd)->filepos = N_TXTOFF (*execp);
46 obj_datasec (abfd)->filepos = N_DATOFF (*execp);
47
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);
51
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);
55
582bc90a 56 /* Determine the architecture and machine type of the object file. */
e98e6ec1
SC
57#ifdef SET_ARCH_MACH
58 SET_ARCH_MACH(abfd, *execp);
59#else
60 bfd_default_set_arch_mach(abfd, DEFAULT_ARCH, 0);
61#endif
62
294eaca4
SC
63 /* Don't set sizes now -- can't be sure until we know arch & mach.
64 Sizes get set in set_sizes callback, later. */
65#if 0
e98e6ec1
SC
66 adata(abfd).page_size = PAGE_SIZE;
67#ifdef SEGMENT_SIZE
68 adata(abfd).segment_size = SEGMENT_SIZE;
69#else
70 adata(abfd).segment_size = PAGE_SIZE;
71#endif
72 adata(abfd).exec_bytes_size = EXEC_BYTES_SIZE;
294eaca4 73#endif
e98e6ec1
SC
74
75 return abfd->xvec;
76}
214f8f23 77#endif
e98e6ec1
SC
78
79#ifndef MY_object_p
80/* Finish up the reading of an a.out file header */
81
82static bfd_target *
57a1867e
DM
83MY(object_p) (abfd)
84 bfd *abfd;
e98e6ec1
SC
85{
86 struct external_exec exec_bytes; /* Raw exec header from file */
87 struct internal_exec exec; /* Cleaned-up exec header */
88 bfd_target *target;
89
90 if (bfd_read ((PTR) &exec_bytes, 1, EXEC_BYTES_SIZE, abfd)
91 != EXEC_BYTES_SIZE) {
4002f18a
ILT
92 if (bfd_get_error () != bfd_error_system_call)
93 bfd_set_error (bfd_error_wrong_format);
e98e6ec1
SC
94 return 0;
95 }
96
3f99570e
JK
97#ifdef SWAP_MAGIC
98 exec.a_info = SWAP_MAGIC (exec_bytes.e_info);
4c3721d5 99#else
e98e6ec1 100 exec.a_info = bfd_h_get_32 (abfd, exec_bytes.e_info);
3f99570e 101#endif /* SWAP_MAGIC */
e98e6ec1
SC
102
103 if (N_BADMAG (exec)) return 0;
4c3721d5
ILT
104#ifdef MACHTYPE_OK
105 if (!(MACHTYPE_OK (N_MACHTYPE (exec)))) return 0;
106#endif
e98e6ec1
SC
107
108 NAME(aout,swap_exec_header_in)(abfd, &exec_bytes, &exec);
109 target = NAME(aout,some_aout_object_p) (abfd, &exec, MY(callback));
110
111#ifdef ENTRY_CAN_BE_ZERO
112 /* The NEWSOS3 entry-point is/was 0, which (amongst other lossage)
113 * means that it isn't obvious if EXEC_P should be set.
114 * All of the following must be true for an executable:
115 * There must be no relocations, the bfd can be neither an
116 * archive nor an archive element, and the file must be executable. */
117
118 if (exec.a_trsize + exec.a_drsize == 0
119 && bfd_get_format(abfd) == bfd_object && abfd->my_archive == NULL)
120 {
121 struct stat buf;
122#ifndef S_IXUSR
123#define S_IXUSR 0100 /* Execute by owner. */
124#endif
125 if (stat(abfd->filename, &buf) == 0 && (buf.st_mode & S_IXUSR))
126 abfd->flags |= EXEC_P;
127 }
128#endif /* ENTRY_CAN_BE_ZERO */
129
130 return target;
131}
132#define MY_object_p MY(object_p)
133#endif
134
135
136#ifndef MY_mkobject
137static boolean
57a1867e
DM
138MY(mkobject) (abfd)
139 bfd *abfd;
e98e6ec1
SC
140{
141 if (NAME(aout,mkobject)(abfd) == false)
142 return false;
294eaca4
SC
143#if 0 /* Sizes get set in set_sizes callback, later, after we know
144 the architecture and machine. */
e98e6ec1
SC
145 adata(abfd).page_size = PAGE_SIZE;
146#ifdef SEGMENT_SIZE
147 adata(abfd).segment_size = SEGMENT_SIZE;
148#else
149 adata(abfd).segment_size = PAGE_SIZE;
150#endif
151 adata(abfd).exec_bytes_size = EXEC_BYTES_SIZE;
294eaca4 152#endif
e98e6ec1
SC
153 return true;
154}
155#define MY_mkobject MY(mkobject)
156#endif
157
f5419a59
ILT
158#ifndef MY_bfd_copy_private_section_data
159
160/* Copy private section data. This actually does nothing with the
161 sections. It copies the subformat field. We copy it here, because
162 we know whether this is a QMAGIC file before we set the section
163 contents, and copy_private_bfd_data is not called until after the
164 section contents have been set. */
165
166/*ARGSUSED*/
167static boolean
168MY_bfd_copy_private_section_data (ibfd, isec, obfd, osec)
169 bfd *ibfd;
170 asection *isec;
171 bfd *obfd;
172 asection *osec;
173{
174 obj_aout_subformat (obfd) = obj_aout_subformat (ibfd);
175 return true;
176}
177
178#endif
179
e98e6ec1
SC
180/* Write an object file.
181 Section contents have already been written. We write the
182 file header, symbols, and relocation. */
183
184#ifndef MY_write_object_contents
185static boolean
57a1867e
DM
186MY(write_object_contents) (abfd)
187 bfd *abfd;
e98e6ec1 188{
e98e6ec1
SC
189 struct external_exec exec_bytes;
190 struct internal_exec *execp = exec_hdr (abfd);
191
582bc90a
PB
192#if CHOOSE_RELOC_SIZE
193 CHOOSE_RELOC_SIZE(abfd);
194#else
195 obj_reloc_entry_size (abfd) = RELOC_STD_SIZE;
196#endif
197
e98e6ec1 198 WRITE_HEADERS(abfd, execp);
582bc90a 199
e98e6ec1
SC
200 return true;
201}
202#define MY_write_object_contents MY(write_object_contents)
203#endif
204
294eaca4
SC
205#ifndef MY_set_sizes
206static boolean
57a1867e
DM
207MY(set_sizes) (abfd)
208 bfd *abfd;
294eaca4
SC
209{
210 adata(abfd).page_size = PAGE_SIZE;
211#ifdef SEGMENT_SIZE
212 adata(abfd).segment_size = SEGMENT_SIZE;
213#else
214 adata(abfd).segment_size = PAGE_SIZE;
215#endif
216 adata(abfd).exec_bytes_size = EXEC_BYTES_SIZE;
217 return true;
218}
219#define MY_set_sizes MY(set_sizes)
220#endif
221
f5419a59
ILT
222#ifndef MY_exec_hdr_flags
223#define MY_exec_hdr_flags 0
224#endif
225
294eaca4 226#ifndef MY_backend_data
57a1867e 227
f5419a59
ILT
228#ifndef MY_text_includes_header
229#define MY_text_includes_header 0
230#endif
231#ifndef MY_add_dynamic_symbols
232#define MY_add_dynamic_symbols 0
233#endif
234#ifndef MY_add_one_symbol
235#define MY_add_one_symbol 0
236#endif
237#ifndef MY_link_dynamic_object
238#define MY_link_dynamic_object 0
239#endif
240#ifndef MY_write_dynamic_symbol
241#define MY_write_dynamic_symbol 0
242#endif
243#ifndef MY_check_dynamic_reloc
244#define MY_check_dynamic_reloc 0
57a1867e 245#endif
f5419a59
ILT
246#ifndef MY_finish_dynamic_link
247#define MY_finish_dynamic_link 0
57a1867e
DM
248#endif
249
294eaca4
SC
250static CONST struct aout_backend_data MY(backend_data) = {
251 0, /* zmagic contiguous */
f5419a59
ILT
252 MY_text_includes_header,
253 MY_exec_hdr_flags,
294eaca4
SC
254 0, /* text vma? */
255 MY_set_sizes,
1f29e30b 256 0, /* exec header is counted */
f5419a59
ILT
257 MY_add_dynamic_symbols,
258 MY_add_one_symbol,
259 MY_link_dynamic_object,
260 MY_write_dynamic_symbol,
261 MY_check_dynamic_reloc,
262 MY_finish_dynamic_link
294eaca4
SC
263};
264#define MY_backend_data &MY(backend_data)
265#endif
266
f5419a59 267#ifndef MY_final_link_callback
4c3721d5 268
f5419a59 269/* Callback for the final_link routine to set the section offsets. */
4c3721d5 270
f5419a59 271static void MY_final_link_callback
4c3721d5
ILT
272 PARAMS ((bfd *, file_ptr *, file_ptr *, file_ptr *));
273
274static void
f5419a59 275MY_final_link_callback (abfd, ptreloff, pdreloff, psymoff)
4c3721d5
ILT
276 bfd *abfd;
277 file_ptr *ptreloff;
278 file_ptr *pdreloff;
279 file_ptr *psymoff;
280{
281 struct internal_exec *execp = exec_hdr (abfd);
282
283 *ptreloff = N_TRELOFF (*execp);
284 *pdreloff = N_DRELOFF (*execp);
285 *psymoff = N_SYMOFF (*execp);
286}
287
f5419a59
ILT
288#endif
289
290#ifndef MY_bfd_final_link
291
292/* Final link routine. We need to use a call back to get the correct
293 offsets in the output file. */
294
4c3721d5
ILT
295static boolean
296MY_bfd_final_link (abfd, info)
297 bfd *abfd;
298 struct bfd_link_info *info;
299{
f5419a59 300 return NAME(aout,final_link) (abfd, info, MY_final_link_callback);
4c3721d5
ILT
301}
302
303#endif
304
e98e6ec1
SC
305/* We assume BFD generic archive files. */
306#ifndef MY_openr_next_archived_file
307#define MY_openr_next_archived_file bfd_generic_openr_next_archived_file
308#endif
309#ifndef MY_generic_stat_arch_elt
310#define MY_generic_stat_arch_elt bfd_generic_stat_arch_elt
311#endif
312#ifndef MY_slurp_armap
313#define MY_slurp_armap bfd_slurp_bsd_armap
314#endif
315#ifndef MY_slurp_extended_name_table
582bc90a 316#define MY_slurp_extended_name_table _bfd_slurp_extended_name_table
e98e6ec1
SC
317#endif
318#ifndef MY_write_armap
319#define MY_write_armap bsd_write_armap
320#endif
321#ifndef MY_truncate_arname
322#define MY_truncate_arname bfd_bsd_truncate_arname
323#endif
324
325/* No core file defined here -- configure in trad-core.c separately. */
326#ifndef MY_core_file_failing_command
6812b607 327#define MY_core_file_failing_command _bfd_nocore_core_file_failing_command
e98e6ec1
SC
328#endif
329#ifndef MY_core_file_failing_signal
6812b607 330#define MY_core_file_failing_signal _bfd_nocore_core_file_failing_signal
e98e6ec1
SC
331#endif
332#ifndef MY_core_file_matches_executable_p
333#define MY_core_file_matches_executable_p \
6812b607 334 _bfd_nocore_core_file_matches_executable_p
e98e6ec1
SC
335#endif
336#ifndef MY_core_file_p
337#define MY_core_file_p _bfd_dummy_target
338#endif
339
340#ifndef MY_bfd_debug_info_start
341#define MY_bfd_debug_info_start bfd_void
342#endif
343#ifndef MY_bfd_debug_info_end
344#define MY_bfd_debug_info_end bfd_void
345#endif
346#ifndef MY_bfd_debug_info_accumulate
1f29e30b
JG
347#define MY_bfd_debug_info_accumulate \
348 (void (*) PARAMS ((bfd*, struct sec *))) bfd_void
e98e6ec1
SC
349#endif
350
351#ifndef MY_core_file_failing_command
352#define MY_core_file_failing_command NAME(aout,core_file_failing_command)
353#endif
354#ifndef MY_core_file_failing_signal
355#define MY_core_file_failing_signal NAME(aout,core_file_failing_signal)
356#endif
357#ifndef MY_core_file_matches_executable_p
358#define MY_core_file_matches_executable_p NAME(aout,core_file_matches_executable_p)
359#endif
e98e6ec1
SC
360#ifndef MY_set_section_contents
361#define MY_set_section_contents NAME(aout,set_section_contents)
362#endif
363#ifndef MY_get_section_contents
364#define MY_get_section_contents NAME(aout,get_section_contents)
365#endif
366#ifndef MY_new_section_hook
367#define MY_new_section_hook NAME(aout,new_section_hook)
368#endif
369#ifndef MY_get_symtab_upper_bound
370#define MY_get_symtab_upper_bound NAME(aout,get_symtab_upper_bound)
371#endif
372#ifndef MY_get_symtab
373#define MY_get_symtab NAME(aout,get_symtab)
374#endif
375#ifndef MY_get_reloc_upper_bound
376#define MY_get_reloc_upper_bound NAME(aout,get_reloc_upper_bound)
377#endif
378#ifndef MY_canonicalize_reloc
379#define MY_canonicalize_reloc NAME(aout,canonicalize_reloc)
380#endif
381#ifndef MY_make_empty_symbol
382#define MY_make_empty_symbol NAME(aout,make_empty_symbol)
383#endif
384#ifndef MY_print_symbol
385#define MY_print_symbol NAME(aout,print_symbol)
386#endif
4c3721d5
ILT
387#ifndef MY_get_symbol_info
388#define MY_get_symbol_info NAME(aout,get_symbol_info)
389#endif
e98e6ec1
SC
390#ifndef MY_get_lineno
391#define MY_get_lineno NAME(aout,get_lineno)
392#endif
393#ifndef MY_set_arch_mach
394#define MY_set_arch_mach NAME(aout,set_arch_mach)
395#endif
e98e6ec1
SC
396#ifndef MY_find_nearest_line
397#define MY_find_nearest_line NAME(aout,find_nearest_line)
398#endif
e98e6ec1
SC
399#ifndef MY_sizeof_headers
400#define MY_sizeof_headers NAME(aout,sizeof_headers)
401#endif
4c3721d5
ILT
402#ifndef MY_bfd_get_relocated_section_contents
403#define MY_bfd_get_relocated_section_contents \
404 bfd_generic_get_relocated_section_contents
e98e6ec1 405#endif
4c3721d5
ILT
406#ifndef MY_bfd_relax_section
407#define MY_bfd_relax_section bfd_generic_relax_section
408#endif
409#ifndef MY_bfd_reloc_type_lookup
410#define MY_bfd_reloc_type_lookup NAME(aout,reloc_type_lookup)
e98e6ec1 411#endif
4c3721d5
ILT
412#ifndef MY_bfd_make_debug_symbol
413#define MY_bfd_make_debug_symbol 0
e98e6ec1 414#endif
4c3721d5
ILT
415#ifndef MY_bfd_link_hash_table_create
416#define MY_bfd_link_hash_table_create NAME(aout,link_hash_table_create)
582bc90a 417#endif
4c3721d5
ILT
418#ifndef MY_bfd_link_add_symbols
419#define MY_bfd_link_add_symbols NAME(aout,link_add_symbols)
582bc90a 420#endif
294eaca4 421
9deaaaf1 422#ifndef MY_bfd_copy_private_bfd_data
6812b607 423#define MY_bfd_copy_private_bfd_data _bfd_generic_bfd_copy_private_bfd_data
9deaaaf1
ILT
424#endif
425
426#ifndef MY_bfd_is_local_label
427#define MY_bfd_is_local_label bfd_generic_is_local_label
428#endif
429
430#ifndef MY_bfd_free_cached_info
5c8444f8
ILT
431#define MY_bfd_free_cached_info NAME(aout,bfd_free_cached_info)
432#endif
433
434#ifndef MY_close_and_cleanup
435#define MY_close_and_cleanup MY_bfd_free_cached_info
9deaaaf1
ILT
436#endif
437
f5419a59
ILT
438#ifndef MY_get_dynamic_symtab_upper_bound
439#define MY_get_dynamic_symtab_upper_bound \
440 _bfd_nodynamic_get_dynamic_symtab_upper_bound
441#endif
442#ifndef MY_canonicalize_dynamic_symtab
443#define MY_canonicalize_dynamic_symtab \
444 _bfd_nodynamic_canonicalize_dynamic_symtab
445#endif
446#ifndef MY_get_dynamic_reloc_upper_bound
447#define MY_get_dynamic_reloc_upper_bound \
448 _bfd_nodynamic_get_dynamic_reloc_upper_bound
449#endif
450#ifndef MY_canonicalize_dynamic_reloc
451#define MY_canonicalize_dynamic_reloc \
452 _bfd_nodynamic_canonicalize_dynamic_reloc
453#endif
454
294eaca4
SC
455/* Aout symbols normally have leading underscores */
456#ifndef MY_symbol_leading_char
457#define MY_symbol_leading_char '_'
582bc90a 458#endif
e98e6ec1 459
4c3721d5
ILT
460/* Aout archives normally use spaces for padding */
461#ifndef AR_PAD_CHAR
462#define AR_PAD_CHAR ' '
463#endif
464
465#ifndef MY_BFD_TARGET
e98e6ec1
SC
466bfd_target MY(vec) =
467{
468 TARGETNAME, /* name */
469 bfd_target_aout_flavour,
582bc90a
PB
470#ifdef TARGET_IS_BIG_ENDIAN_P
471 true, /* target byte order (big) */
472 true, /* target headers byte order (big) */
473#else
474 false, /* target byte order (little) */
475 false, /* target headers byte order (little) */
476#endif
e98e6ec1
SC
477 (HAS_RELOC | EXEC_P | /* object flags */
478 HAS_LINENO | HAS_DEBUG |
57a1867e 479 HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED),
e98e6ec1 480 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
294eaca4 481 MY_symbol_leading_char,
4c3721d5 482 AR_PAD_CHAR, /* ar_pad_char */
582bc90a 483 15, /* ar_max_namelen */
4c3721d5 484 3, /* minimum alignment */
e98e6ec1 485#ifdef TARGET_IS_BIG_ENDIAN_P
4c3721d5
ILT
486 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
487 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
488 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* data */
489 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
490 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
491 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* hdrs */
e98e6ec1 492#else
4c3721d5
ILT
493 bfd_getl64, bfd_getl_signed_64, bfd_putl64,
494 bfd_getl32, bfd_getl_signed_32, bfd_putl32,
495 bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */
496 bfd_getl64, bfd_getl_signed_64, bfd_putl64,
497 bfd_getl32, bfd_getl_signed_32, bfd_putl32,
498 bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* hdrs */
e98e6ec1
SC
499#endif
500 {_bfd_dummy_target, MY_object_p, /* bfd_check_format */
501 bfd_generic_archive_p, MY_core_file_p},
502 {bfd_false, MY_mkobject, /* bfd_set_format */
503 _bfd_generic_mkarchive, bfd_false},
504 {bfd_false, MY_write_object_contents, /* bfd_write_contents */
505 _bfd_write_archive_contents, bfd_false},
506
6812b607
ILT
507 BFD_JUMP_TABLE_GENERIC (MY),
508 BFD_JUMP_TABLE_COPY (MY),
509 BFD_JUMP_TABLE_CORE (MY),
510 BFD_JUMP_TABLE_ARCHIVE (MY),
511 BFD_JUMP_TABLE_SYMBOLS (MY),
512 BFD_JUMP_TABLE_RELOCS (MY),
513 BFD_JUMP_TABLE_WRITE (MY),
514 BFD_JUMP_TABLE_LINK (MY),
f5419a59 515 BFD_JUMP_TABLE_DYNAMIC (MY),
6812b607 516
582bc90a 517 (PTR) MY_backend_data,
e98e6ec1 518};
4c3721d5 519#endif /* MY_BFD_TARGET */
This page took 0.13778 seconds and 4 git commands to generate.