]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - bfd/aout-target.h
* mips-opc.c (mips_opcodes): Correct operands of "nor" with an
[thirdparty/binutils-gdb.git] / bfd / aout-target.h
CommitLineData
582bc90a 1/* Define a target vector and some small routines for a variant of a.out.
4c3721d5 2 Copyright (C) 1990, 1991, 1992, 1993 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
158/* Write an object file.
159 Section contents have already been written. We write the
160 file header, symbols, and relocation. */
161
162#ifndef MY_write_object_contents
163static boolean
57a1867e
DM
164MY(write_object_contents) (abfd)
165 bfd *abfd;
e98e6ec1 166{
e98e6ec1
SC
167 struct external_exec exec_bytes;
168 struct internal_exec *execp = exec_hdr (abfd);
169
582bc90a
PB
170#if CHOOSE_RELOC_SIZE
171 CHOOSE_RELOC_SIZE(abfd);
172#else
173 obj_reloc_entry_size (abfd) = RELOC_STD_SIZE;
174#endif
175
e98e6ec1 176 WRITE_HEADERS(abfd, execp);
582bc90a 177
e98e6ec1
SC
178 return true;
179}
180#define MY_write_object_contents MY(write_object_contents)
181#endif
182
294eaca4
SC
183#ifndef MY_set_sizes
184static boolean
57a1867e
DM
185MY(set_sizes) (abfd)
186 bfd *abfd;
294eaca4
SC
187{
188 adata(abfd).page_size = PAGE_SIZE;
189#ifdef SEGMENT_SIZE
190 adata(abfd).segment_size = SEGMENT_SIZE;
191#else
192 adata(abfd).segment_size = PAGE_SIZE;
193#endif
194 adata(abfd).exec_bytes_size = EXEC_BYTES_SIZE;
195 return true;
196}
197#define MY_set_sizes MY(set_sizes)
198#endif
199
200#ifndef MY_backend_data
57a1867e
DM
201
202#ifndef MY_read_dynamic_symbols
203#define MY_read_dynamic_symbols 0
204#endif
205#ifndef MY_read_dynamic_relocs
206#define MY_read_dynamic_relocs 0
207#endif
208
294eaca4
SC
209static CONST struct aout_backend_data MY(backend_data) = {
210 0, /* zmagic contiguous */
211 0, /* text incl header */
212 0, /* text vma? */
213 MY_set_sizes,
1f29e30b 214 0, /* exec header is counted */
57a1867e
DM
215 MY_read_dynamic_symbols,
216 MY_read_dynamic_relocs
294eaca4
SC
217};
218#define MY_backend_data &MY(backend_data)
219#endif
220
4c3721d5
ILT
221#ifndef MY_bfd_final_link
222
223/* Final link routine. We need to use a call back to get the correct
224 offsets in the output file. */
225
226static void final_link_callback
227 PARAMS ((bfd *, file_ptr *, file_ptr *, file_ptr *));
228
229static void
230final_link_callback (abfd, ptreloff, pdreloff, psymoff)
231 bfd *abfd;
232 file_ptr *ptreloff;
233 file_ptr *pdreloff;
234 file_ptr *psymoff;
235{
236 struct internal_exec *execp = exec_hdr (abfd);
237
238 *ptreloff = N_TRELOFF (*execp);
239 *pdreloff = N_DRELOFF (*execp);
240 *psymoff = N_SYMOFF (*execp);
241}
242
243static boolean
244MY_bfd_final_link (abfd, info)
245 bfd *abfd;
246 struct bfd_link_info *info;
247{
248 return NAME(aout,final_link) (abfd, info, final_link_callback);
249}
250
251#endif
252
e98e6ec1
SC
253/* We assume BFD generic archive files. */
254#ifndef MY_openr_next_archived_file
255#define MY_openr_next_archived_file bfd_generic_openr_next_archived_file
256#endif
257#ifndef MY_generic_stat_arch_elt
258#define MY_generic_stat_arch_elt bfd_generic_stat_arch_elt
259#endif
260#ifndef MY_slurp_armap
261#define MY_slurp_armap bfd_slurp_bsd_armap
262#endif
263#ifndef MY_slurp_extended_name_table
582bc90a 264#define MY_slurp_extended_name_table _bfd_slurp_extended_name_table
e98e6ec1
SC
265#endif
266#ifndef MY_write_armap
267#define MY_write_armap bsd_write_armap
268#endif
269#ifndef MY_truncate_arname
270#define MY_truncate_arname bfd_bsd_truncate_arname
271#endif
272
273/* No core file defined here -- configure in trad-core.c separately. */
274#ifndef MY_core_file_failing_command
275#define MY_core_file_failing_command _bfd_dummy_core_file_failing_command
276#endif
277#ifndef MY_core_file_failing_signal
278#define MY_core_file_failing_signal _bfd_dummy_core_file_failing_signal
279#endif
280#ifndef MY_core_file_matches_executable_p
281#define MY_core_file_matches_executable_p \
282 _bfd_dummy_core_file_matches_executable_p
283#endif
284#ifndef MY_core_file_p
285#define MY_core_file_p _bfd_dummy_target
286#endif
287
288#ifndef MY_bfd_debug_info_start
289#define MY_bfd_debug_info_start bfd_void
290#endif
291#ifndef MY_bfd_debug_info_end
292#define MY_bfd_debug_info_end bfd_void
293#endif
294#ifndef MY_bfd_debug_info_accumulate
1f29e30b
JG
295#define MY_bfd_debug_info_accumulate \
296 (void (*) PARAMS ((bfd*, struct sec *))) bfd_void
e98e6ec1
SC
297#endif
298
299#ifndef MY_core_file_failing_command
300#define MY_core_file_failing_command NAME(aout,core_file_failing_command)
301#endif
302#ifndef MY_core_file_failing_signal
303#define MY_core_file_failing_signal NAME(aout,core_file_failing_signal)
304#endif
305#ifndef MY_core_file_matches_executable_p
306#define MY_core_file_matches_executable_p NAME(aout,core_file_matches_executable_p)
307#endif
308#ifndef MY_slurp_armap
309#define MY_slurp_armap NAME(aout,slurp_armap)
310#endif
311#ifndef MY_slurp_extended_name_table
312#define MY_slurp_extended_name_table NAME(aout,slurp_extended_name_table)
313#endif
314#ifndef MY_truncate_arname
315#define MY_truncate_arname NAME(aout,truncate_arname)
316#endif
317#ifndef MY_write_armap
318#define MY_write_armap NAME(aout,write_armap)
319#endif
e98e6ec1
SC
320#ifndef MY_set_section_contents
321#define MY_set_section_contents NAME(aout,set_section_contents)
322#endif
323#ifndef MY_get_section_contents
324#define MY_get_section_contents NAME(aout,get_section_contents)
325#endif
326#ifndef MY_new_section_hook
327#define MY_new_section_hook NAME(aout,new_section_hook)
328#endif
329#ifndef MY_get_symtab_upper_bound
330#define MY_get_symtab_upper_bound NAME(aout,get_symtab_upper_bound)
331#endif
332#ifndef MY_get_symtab
333#define MY_get_symtab NAME(aout,get_symtab)
334#endif
335#ifndef MY_get_reloc_upper_bound
336#define MY_get_reloc_upper_bound NAME(aout,get_reloc_upper_bound)
337#endif
338#ifndef MY_canonicalize_reloc
339#define MY_canonicalize_reloc NAME(aout,canonicalize_reloc)
340#endif
341#ifndef MY_make_empty_symbol
342#define MY_make_empty_symbol NAME(aout,make_empty_symbol)
343#endif
344#ifndef MY_print_symbol
345#define MY_print_symbol NAME(aout,print_symbol)
346#endif
4c3721d5
ILT
347#ifndef MY_get_symbol_info
348#define MY_get_symbol_info NAME(aout,get_symbol_info)
349#endif
e98e6ec1
SC
350#ifndef MY_get_lineno
351#define MY_get_lineno NAME(aout,get_lineno)
352#endif
353#ifndef MY_set_arch_mach
354#define MY_set_arch_mach NAME(aout,set_arch_mach)
355#endif
356#ifndef MY_openr_next_archived_file
357#define MY_openr_next_archived_file NAME(aout,openr_next_archived_file)
358#endif
359#ifndef MY_find_nearest_line
360#define MY_find_nearest_line NAME(aout,find_nearest_line)
361#endif
362#ifndef MY_generic_stat_arch_elt
363#define MY_generic_stat_arch_elt NAME(aout,generic_stat_arch_elt)
364#endif
365#ifndef MY_sizeof_headers
366#define MY_sizeof_headers NAME(aout,sizeof_headers)
367#endif
4c3721d5
ILT
368#ifndef MY_bfd_get_relocated_section_contents
369#define MY_bfd_get_relocated_section_contents \
370 bfd_generic_get_relocated_section_contents
e98e6ec1 371#endif
4c3721d5
ILT
372#ifndef MY_bfd_relax_section
373#define MY_bfd_relax_section bfd_generic_relax_section
374#endif
375#ifndef MY_bfd_reloc_type_lookup
376#define MY_bfd_reloc_type_lookup NAME(aout,reloc_type_lookup)
e98e6ec1 377#endif
4c3721d5
ILT
378#ifndef MY_bfd_make_debug_symbol
379#define MY_bfd_make_debug_symbol 0
e98e6ec1 380#endif
4c3721d5
ILT
381#ifndef MY_bfd_link_hash_table_create
382#define MY_bfd_link_hash_table_create NAME(aout,link_hash_table_create)
582bc90a 383#endif
4c3721d5
ILT
384#ifndef MY_bfd_link_add_symbols
385#define MY_bfd_link_add_symbols NAME(aout,link_add_symbols)
582bc90a 386#endif
294eaca4 387
9deaaaf1
ILT
388#ifndef MY_bfd_copy_private_section_data
389#define MY_bfd_copy_private_section_data \
390 ((boolean (*) PARAMS ((bfd *, asection *, bfd *, asection *))) bfd_true)
391#endif
392#ifndef MY_bfd_copy_private_bfd_data
393#define MY_bfd_copy_private_bfd_data \
394 ((boolean (*) PARAMS ((bfd *, bfd *))) bfd_true)
395#endif
396
397#ifndef MY_bfd_is_local_label
398#define MY_bfd_is_local_label bfd_generic_is_local_label
399#endif
400
401#ifndef MY_bfd_free_cached_info
5c8444f8
ILT
402#define MY_bfd_free_cached_info NAME(aout,bfd_free_cached_info)
403#endif
404
405#ifndef MY_close_and_cleanup
406#define MY_close_and_cleanup MY_bfd_free_cached_info
9deaaaf1
ILT
407#endif
408
294eaca4
SC
409/* Aout symbols normally have leading underscores */
410#ifndef MY_symbol_leading_char
411#define MY_symbol_leading_char '_'
582bc90a 412#endif
e98e6ec1 413
4c3721d5
ILT
414/* Aout archives normally use spaces for padding */
415#ifndef AR_PAD_CHAR
416#define AR_PAD_CHAR ' '
417#endif
418
419#ifndef MY_BFD_TARGET
e98e6ec1
SC
420bfd_target MY(vec) =
421{
422 TARGETNAME, /* name */
423 bfd_target_aout_flavour,
582bc90a
PB
424#ifdef TARGET_IS_BIG_ENDIAN_P
425 true, /* target byte order (big) */
426 true, /* target headers byte order (big) */
427#else
428 false, /* target byte order (little) */
429 false, /* target headers byte order (little) */
430#endif
e98e6ec1
SC
431 (HAS_RELOC | EXEC_P | /* object flags */
432 HAS_LINENO | HAS_DEBUG |
57a1867e 433 HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED),
e98e6ec1 434 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
294eaca4 435 MY_symbol_leading_char,
4c3721d5 436 AR_PAD_CHAR, /* ar_pad_char */
582bc90a 437 15, /* ar_max_namelen */
4c3721d5 438 3, /* minimum alignment */
e98e6ec1 439#ifdef TARGET_IS_BIG_ENDIAN_P
4c3721d5
ILT
440 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
441 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
442 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* data */
443 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
444 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
445 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* hdrs */
e98e6ec1 446#else
4c3721d5
ILT
447 bfd_getl64, bfd_getl_signed_64, bfd_putl64,
448 bfd_getl32, bfd_getl_signed_32, bfd_putl32,
449 bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */
450 bfd_getl64, bfd_getl_signed_64, bfd_putl64,
451 bfd_getl32, bfd_getl_signed_32, bfd_putl32,
452 bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* hdrs */
e98e6ec1
SC
453#endif
454 {_bfd_dummy_target, MY_object_p, /* bfd_check_format */
455 bfd_generic_archive_p, MY_core_file_p},
456 {bfd_false, MY_mkobject, /* bfd_set_format */
457 _bfd_generic_mkarchive, bfd_false},
458 {bfd_false, MY_write_object_contents, /* bfd_write_contents */
459 _bfd_write_archive_contents, bfd_false},
460
4c3721d5 461 JUMP_TABLE (MY),
582bc90a 462 (PTR) MY_backend_data,
e98e6ec1 463};
4c3721d5 464#endif /* MY_BFD_TARGET */