]>
Commit | Line | Data |
---|---|---|
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 | |
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 | ||
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 |
25 | extern 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 SC |
30 | static bfd_target * |
31 | DEFUN(MY(callback),(abfd), | |
32 | bfd *abfd) | |
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 | ||
82 | static bfd_target * | |
83 | DEFUN(MY(object_p),(abfd), | |
84 | bfd *abfd) | |
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) { | |
92 | bfd_error = wrong_format; | |
93 | return 0; | |
94 | } | |
95 | ||
3f99570e JK |
96 | #ifdef SWAP_MAGIC |
97 | exec.a_info = SWAP_MAGIC (exec_bytes.e_info); | |
4c3721d5 | 98 | #else |
e98e6ec1 | 99 | exec.a_info = bfd_h_get_32 (abfd, exec_bytes.e_info); |
3f99570e | 100 | #endif /* SWAP_MAGIC */ |
e98e6ec1 SC |
101 | |
102 | if (N_BADMAG (exec)) return 0; | |
4c3721d5 ILT |
103 | #ifdef MACHTYPE_OK |
104 | if (!(MACHTYPE_OK (N_MACHTYPE (exec)))) return 0; | |
105 | #endif | |
e98e6ec1 SC |
106 | |
107 | NAME(aout,swap_exec_header_in)(abfd, &exec_bytes, &exec); | |
108 | target = NAME(aout,some_aout_object_p) (abfd, &exec, MY(callback)); | |
109 | ||
110 | #ifdef ENTRY_CAN_BE_ZERO | |
111 | /* The NEWSOS3 entry-point is/was 0, which (amongst other lossage) | |
112 | * means that it isn't obvious if EXEC_P should be set. | |
113 | * All of the following must be true for an executable: | |
114 | * There must be no relocations, the bfd can be neither an | |
115 | * archive nor an archive element, and the file must be executable. */ | |
116 | ||
117 | if (exec.a_trsize + exec.a_drsize == 0 | |
118 | && bfd_get_format(abfd) == bfd_object && abfd->my_archive == NULL) | |
119 | { | |
120 | struct stat buf; | |
121 | #ifndef S_IXUSR | |
122 | #define S_IXUSR 0100 /* Execute by owner. */ | |
123 | #endif | |
124 | if (stat(abfd->filename, &buf) == 0 && (buf.st_mode & S_IXUSR)) | |
125 | abfd->flags |= EXEC_P; | |
126 | } | |
127 | #endif /* ENTRY_CAN_BE_ZERO */ | |
128 | ||
129 | return target; | |
130 | } | |
131 | #define MY_object_p MY(object_p) | |
132 | #endif | |
133 | ||
134 | ||
135 | #ifndef MY_mkobject | |
136 | static boolean | |
137 | DEFUN(MY(mkobject),(abfd), | |
138 | bfd *abfd) | |
139 | { | |
140 | if (NAME(aout,mkobject)(abfd) == false) | |
141 | return false; | |
294eaca4 SC |
142 | #if 0 /* Sizes get set in set_sizes callback, later, after we know |
143 | the architecture and machine. */ | |
e98e6ec1 SC |
144 | adata(abfd).page_size = PAGE_SIZE; |
145 | #ifdef SEGMENT_SIZE | |
146 | adata(abfd).segment_size = SEGMENT_SIZE; | |
147 | #else | |
148 | adata(abfd).segment_size = PAGE_SIZE; | |
149 | #endif | |
150 | adata(abfd).exec_bytes_size = EXEC_BYTES_SIZE; | |
294eaca4 | 151 | #endif |
e98e6ec1 SC |
152 | return true; |
153 | } | |
154 | #define MY_mkobject MY(mkobject) | |
155 | #endif | |
156 | ||
157 | /* Write an object file. | |
158 | Section contents have already been written. We write the | |
159 | file header, symbols, and relocation. */ | |
160 | ||
161 | #ifndef MY_write_object_contents | |
162 | static boolean | |
163 | DEFUN(MY(write_object_contents),(abfd), | |
164 | bfd *abfd) | |
165 | { | |
e98e6ec1 SC |
166 | struct external_exec exec_bytes; |
167 | struct internal_exec *execp = exec_hdr (abfd); | |
168 | ||
582bc90a PB |
169 | #if CHOOSE_RELOC_SIZE |
170 | CHOOSE_RELOC_SIZE(abfd); | |
171 | #else | |
172 | obj_reloc_entry_size (abfd) = RELOC_STD_SIZE; | |
173 | #endif | |
174 | ||
e98e6ec1 | 175 | WRITE_HEADERS(abfd, execp); |
582bc90a | 176 | |
e98e6ec1 SC |
177 | return true; |
178 | } | |
179 | #define MY_write_object_contents MY(write_object_contents) | |
180 | #endif | |
181 | ||
294eaca4 SC |
182 | #ifndef MY_set_sizes |
183 | static boolean | |
184 | DEFUN(MY(set_sizes),(abfd), bfd *abfd) | |
185 | { | |
186 | adata(abfd).page_size = PAGE_SIZE; | |
187 | #ifdef SEGMENT_SIZE | |
188 | adata(abfd).segment_size = SEGMENT_SIZE; | |
189 | #else | |
190 | adata(abfd).segment_size = PAGE_SIZE; | |
191 | #endif | |
192 | adata(abfd).exec_bytes_size = EXEC_BYTES_SIZE; | |
193 | return true; | |
194 | } | |
195 | #define MY_set_sizes MY(set_sizes) | |
196 | #endif | |
197 | ||
198 | #ifndef MY_backend_data | |
199 | static CONST struct aout_backend_data MY(backend_data) = { | |
200 | 0, /* zmagic contiguous */ | |
201 | 0, /* text incl header */ | |
202 | 0, /* text vma? */ | |
203 | MY_set_sizes, | |
1f29e30b | 204 | 0, /* exec header is counted */ |
294eaca4 SC |
205 | }; |
206 | #define MY_backend_data &MY(backend_data) | |
207 | #endif | |
208 | ||
4c3721d5 ILT |
209 | #ifndef MY_bfd_final_link |
210 | ||
211 | /* Final link routine. We need to use a call back to get the correct | |
212 | offsets in the output file. */ | |
213 | ||
214 | static void final_link_callback | |
215 | PARAMS ((bfd *, file_ptr *, file_ptr *, file_ptr *)); | |
216 | ||
217 | static void | |
218 | final_link_callback (abfd, ptreloff, pdreloff, psymoff) | |
219 | bfd *abfd; | |
220 | file_ptr *ptreloff; | |
221 | file_ptr *pdreloff; | |
222 | file_ptr *psymoff; | |
223 | { | |
224 | struct internal_exec *execp = exec_hdr (abfd); | |
225 | ||
226 | *ptreloff = N_TRELOFF (*execp); | |
227 | *pdreloff = N_DRELOFF (*execp); | |
228 | *psymoff = N_SYMOFF (*execp); | |
229 | } | |
230 | ||
231 | static boolean | |
232 | MY_bfd_final_link (abfd, info) | |
233 | bfd *abfd; | |
234 | struct bfd_link_info *info; | |
235 | { | |
236 | return NAME(aout,final_link) (abfd, info, final_link_callback); | |
237 | } | |
238 | ||
239 | #endif | |
240 | ||
e98e6ec1 SC |
241 | /* We assume BFD generic archive files. */ |
242 | #ifndef MY_openr_next_archived_file | |
243 | #define MY_openr_next_archived_file bfd_generic_openr_next_archived_file | |
244 | #endif | |
245 | #ifndef MY_generic_stat_arch_elt | |
246 | #define MY_generic_stat_arch_elt bfd_generic_stat_arch_elt | |
247 | #endif | |
248 | #ifndef MY_slurp_armap | |
249 | #define MY_slurp_armap bfd_slurp_bsd_armap | |
250 | #endif | |
251 | #ifndef MY_slurp_extended_name_table | |
582bc90a | 252 | #define MY_slurp_extended_name_table _bfd_slurp_extended_name_table |
e98e6ec1 SC |
253 | #endif |
254 | #ifndef MY_write_armap | |
255 | #define MY_write_armap bsd_write_armap | |
256 | #endif | |
257 | #ifndef MY_truncate_arname | |
258 | #define MY_truncate_arname bfd_bsd_truncate_arname | |
259 | #endif | |
260 | ||
261 | /* No core file defined here -- configure in trad-core.c separately. */ | |
262 | #ifndef MY_core_file_failing_command | |
263 | #define MY_core_file_failing_command _bfd_dummy_core_file_failing_command | |
264 | #endif | |
265 | #ifndef MY_core_file_failing_signal | |
266 | #define MY_core_file_failing_signal _bfd_dummy_core_file_failing_signal | |
267 | #endif | |
268 | #ifndef MY_core_file_matches_executable_p | |
269 | #define MY_core_file_matches_executable_p \ | |
270 | _bfd_dummy_core_file_matches_executable_p | |
271 | #endif | |
272 | #ifndef MY_core_file_p | |
273 | #define MY_core_file_p _bfd_dummy_target | |
274 | #endif | |
275 | ||
276 | #ifndef MY_bfd_debug_info_start | |
277 | #define MY_bfd_debug_info_start bfd_void | |
278 | #endif | |
279 | #ifndef MY_bfd_debug_info_end | |
280 | #define MY_bfd_debug_info_end bfd_void | |
281 | #endif | |
282 | #ifndef MY_bfd_debug_info_accumulate | |
1f29e30b JG |
283 | #define MY_bfd_debug_info_accumulate \ |
284 | (void (*) PARAMS ((bfd*, struct sec *))) bfd_void | |
e98e6ec1 SC |
285 | #endif |
286 | ||
287 | #ifndef MY_core_file_failing_command | |
288 | #define MY_core_file_failing_command NAME(aout,core_file_failing_command) | |
289 | #endif | |
290 | #ifndef MY_core_file_failing_signal | |
291 | #define MY_core_file_failing_signal NAME(aout,core_file_failing_signal) | |
292 | #endif | |
293 | #ifndef MY_core_file_matches_executable_p | |
294 | #define MY_core_file_matches_executable_p NAME(aout,core_file_matches_executable_p) | |
295 | #endif | |
296 | #ifndef MY_slurp_armap | |
297 | #define MY_slurp_armap NAME(aout,slurp_armap) | |
298 | #endif | |
299 | #ifndef MY_slurp_extended_name_table | |
300 | #define MY_slurp_extended_name_table NAME(aout,slurp_extended_name_table) | |
301 | #endif | |
302 | #ifndef MY_truncate_arname | |
303 | #define MY_truncate_arname NAME(aout,truncate_arname) | |
304 | #endif | |
305 | #ifndef MY_write_armap | |
306 | #define MY_write_armap NAME(aout,write_armap) | |
307 | #endif | |
308 | #ifndef MY_close_and_cleanup | |
309 | #define MY_close_and_cleanup NAME(aout,close_and_cleanup) | |
310 | #endif | |
311 | #ifndef MY_set_section_contents | |
312 | #define MY_set_section_contents NAME(aout,set_section_contents) | |
313 | #endif | |
314 | #ifndef MY_get_section_contents | |
315 | #define MY_get_section_contents NAME(aout,get_section_contents) | |
316 | #endif | |
317 | #ifndef MY_new_section_hook | |
318 | #define MY_new_section_hook NAME(aout,new_section_hook) | |
319 | #endif | |
320 | #ifndef MY_get_symtab_upper_bound | |
321 | #define MY_get_symtab_upper_bound NAME(aout,get_symtab_upper_bound) | |
322 | #endif | |
323 | #ifndef MY_get_symtab | |
324 | #define MY_get_symtab NAME(aout,get_symtab) | |
325 | #endif | |
326 | #ifndef MY_get_reloc_upper_bound | |
327 | #define MY_get_reloc_upper_bound NAME(aout,get_reloc_upper_bound) | |
328 | #endif | |
329 | #ifndef MY_canonicalize_reloc | |
330 | #define MY_canonicalize_reloc NAME(aout,canonicalize_reloc) | |
331 | #endif | |
332 | #ifndef MY_make_empty_symbol | |
333 | #define MY_make_empty_symbol NAME(aout,make_empty_symbol) | |
334 | #endif | |
335 | #ifndef MY_print_symbol | |
336 | #define MY_print_symbol NAME(aout,print_symbol) | |
337 | #endif | |
4c3721d5 ILT |
338 | #ifndef MY_get_symbol_info |
339 | #define MY_get_symbol_info NAME(aout,get_symbol_info) | |
340 | #endif | |
e98e6ec1 SC |
341 | #ifndef MY_get_lineno |
342 | #define MY_get_lineno NAME(aout,get_lineno) | |
343 | #endif | |
344 | #ifndef MY_set_arch_mach | |
345 | #define MY_set_arch_mach NAME(aout,set_arch_mach) | |
346 | #endif | |
347 | #ifndef MY_openr_next_archived_file | |
348 | #define MY_openr_next_archived_file NAME(aout,openr_next_archived_file) | |
349 | #endif | |
350 | #ifndef MY_find_nearest_line | |
351 | #define MY_find_nearest_line NAME(aout,find_nearest_line) | |
352 | #endif | |
353 | #ifndef MY_generic_stat_arch_elt | |
354 | #define MY_generic_stat_arch_elt NAME(aout,generic_stat_arch_elt) | |
355 | #endif | |
356 | #ifndef MY_sizeof_headers | |
357 | #define MY_sizeof_headers NAME(aout,sizeof_headers) | |
358 | #endif | |
4c3721d5 ILT |
359 | #ifndef MY_bfd_get_relocated_section_contents |
360 | #define MY_bfd_get_relocated_section_contents \ | |
361 | bfd_generic_get_relocated_section_contents | |
e98e6ec1 | 362 | #endif |
4c3721d5 ILT |
363 | #ifndef MY_bfd_relax_section |
364 | #define MY_bfd_relax_section bfd_generic_relax_section | |
365 | #endif | |
366 | #ifndef MY_bfd_reloc_type_lookup | |
367 | #define MY_bfd_reloc_type_lookup NAME(aout,reloc_type_lookup) | |
e98e6ec1 | 368 | #endif |
4c3721d5 ILT |
369 | #ifndef MY_bfd_make_debug_symbol |
370 | #define MY_bfd_make_debug_symbol 0 | |
e98e6ec1 | 371 | #endif |
4c3721d5 ILT |
372 | #ifndef MY_bfd_link_hash_table_create |
373 | #define MY_bfd_link_hash_table_create NAME(aout,link_hash_table_create) | |
582bc90a | 374 | #endif |
4c3721d5 ILT |
375 | #ifndef MY_bfd_link_add_symbols |
376 | #define MY_bfd_link_add_symbols NAME(aout,link_add_symbols) | |
582bc90a | 377 | #endif |
294eaca4 SC |
378 | |
379 | /* Aout symbols normally have leading underscores */ | |
380 | #ifndef MY_symbol_leading_char | |
381 | #define MY_symbol_leading_char '_' | |
582bc90a | 382 | #endif |
e98e6ec1 | 383 | |
4c3721d5 ILT |
384 | /* Aout archives normally use spaces for padding */ |
385 | #ifndef AR_PAD_CHAR | |
386 | #define AR_PAD_CHAR ' ' | |
387 | #endif | |
388 | ||
389 | #ifndef MY_BFD_TARGET | |
e98e6ec1 SC |
390 | bfd_target MY(vec) = |
391 | { | |
392 | TARGETNAME, /* name */ | |
393 | bfd_target_aout_flavour, | |
582bc90a PB |
394 | #ifdef TARGET_IS_BIG_ENDIAN_P |
395 | true, /* target byte order (big) */ | |
396 | true, /* target headers byte order (big) */ | |
397 | #else | |
398 | false, /* target byte order (little) */ | |
399 | false, /* target headers byte order (little) */ | |
400 | #endif | |
e98e6ec1 SC |
401 | (HAS_RELOC | EXEC_P | /* object flags */ |
402 | HAS_LINENO | HAS_DEBUG | | |
4c3721d5 | 403 | HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED), |
e98e6ec1 | 404 | (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */ |
294eaca4 | 405 | MY_symbol_leading_char, |
4c3721d5 | 406 | AR_PAD_CHAR, /* ar_pad_char */ |
582bc90a | 407 | 15, /* ar_max_namelen */ |
4c3721d5 | 408 | 3, /* minimum alignment */ |
e98e6ec1 | 409 | #ifdef TARGET_IS_BIG_ENDIAN_P |
4c3721d5 ILT |
410 | bfd_getb64, bfd_getb_signed_64, bfd_putb64, |
411 | bfd_getb32, bfd_getb_signed_32, bfd_putb32, | |
412 | bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* data */ | |
413 | bfd_getb64, bfd_getb_signed_64, bfd_putb64, | |
414 | bfd_getb32, bfd_getb_signed_32, bfd_putb32, | |
415 | bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* hdrs */ | |
e98e6ec1 | 416 | #else |
4c3721d5 ILT |
417 | bfd_getl64, bfd_getl_signed_64, bfd_putl64, |
418 | bfd_getl32, bfd_getl_signed_32, bfd_putl32, | |
419 | bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */ | |
420 | bfd_getl64, bfd_getl_signed_64, bfd_putl64, | |
421 | bfd_getl32, bfd_getl_signed_32, bfd_putl32, | |
422 | bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* hdrs */ | |
e98e6ec1 SC |
423 | #endif |
424 | {_bfd_dummy_target, MY_object_p, /* bfd_check_format */ | |
425 | bfd_generic_archive_p, MY_core_file_p}, | |
426 | {bfd_false, MY_mkobject, /* bfd_set_format */ | |
427 | _bfd_generic_mkarchive, bfd_false}, | |
428 | {bfd_false, MY_write_object_contents, /* bfd_write_contents */ | |
429 | _bfd_write_archive_contents, bfd_false}, | |
430 | ||
4c3721d5 | 431 | JUMP_TABLE (MY), |
582bc90a | 432 | (PTR) MY_backend_data, |
e98e6ec1 | 433 | }; |
4c3721d5 | 434 | #endif /* MY_BFD_TARGET */ |