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