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