]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - bfd/aout-target.h
Some of these are guesses, if you know different, just yell.
[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 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 /* Set parameters about this a.out file that are machine-dependent.
26 This routine is called from some_aout_object_p just before it returns. */
27 static bfd_target *
28 DEFUN(MY(callback),(abfd),
29 bfd *abfd)
30 {
31 struct internal_exec *execp = exec_hdr (abfd);
32 struct aout_backend_data *abdp;
33
34 /* Calculate the file positions of the parts of a newly read aout header */
35 obj_textsec (abfd)->_raw_size = N_TXTSIZE(*execp);
36
37 /* The virtual memory addresses of the sections */
38 obj_textsec (abfd)->vma = N_TXTADDR(*execp);
39 obj_datasec (abfd)->vma = N_DATADDR(*execp);
40 obj_bsssec (abfd)->vma = N_BSSADDR(*execp);
41
42 /* The file offsets of the sections */
43 obj_textsec (abfd)->filepos = N_TXTOFF (*execp);
44 obj_datasec (abfd)->filepos = N_DATOFF (*execp);
45
46 /* The file offsets of the relocation info */
47 obj_textsec (abfd)->rel_filepos = N_TRELOFF(*execp);
48 obj_datasec (abfd)->rel_filepos = N_DRELOFF(*execp);
49
50 /* The file offsets of the string table and symbol table. */
51 obj_sym_filepos (abfd) = N_SYMOFF (*execp);
52 obj_str_filepos (abfd) = N_STROFF (*execp);
53
54 /* Determine the architecture and machine type of the object file. */
55 #ifdef SET_ARCH_MACH
56 SET_ARCH_MACH(abfd, *execp);
57 #else
58 bfd_default_set_arch_mach(abfd, DEFAULT_ARCH, 0);
59 #endif
60
61 /* Don't set sizes now -- can't be sure until we know arch & mach.
62 Sizes get set in set_sizes callback, later. */
63 #if 0
64 adata(abfd).page_size = PAGE_SIZE;
65 #ifdef SEGMENT_SIZE
66 adata(abfd).segment_size = SEGMENT_SIZE;
67 #else
68 adata(abfd).segment_size = PAGE_SIZE;
69 #endif
70 adata(abfd).exec_bytes_size = EXEC_BYTES_SIZE;
71 #endif
72
73 return abfd->xvec;
74 }
75
76 #ifndef MY_object_p
77 /* Finish up the reading of an a.out file header */
78
79 static bfd_target *
80 DEFUN(MY(object_p),(abfd),
81 bfd *abfd)
82 {
83 struct external_exec exec_bytes; /* Raw exec header from file */
84 struct internal_exec exec; /* Cleaned-up exec header */
85 bfd_target *target;
86
87 if (bfd_read ((PTR) &exec_bytes, 1, EXEC_BYTES_SIZE, abfd)
88 != EXEC_BYTES_SIZE) {
89 bfd_error = wrong_format;
90 return 0;
91 }
92
93 exec.a_info = bfd_h_get_32 (abfd, exec_bytes.e_info);
94
95 if (N_BADMAG (exec)) return 0;
96
97 NAME(aout,swap_exec_header_in)(abfd, &exec_bytes, &exec);
98 target = NAME(aout,some_aout_object_p) (abfd, &exec, MY(callback));
99
100 #ifdef ENTRY_CAN_BE_ZERO
101 /* The NEWSOS3 entry-point is/was 0, which (amongst other lossage)
102 * means that it isn't obvious if EXEC_P should be set.
103 * All of the following must be true for an executable:
104 * There must be no relocations, the bfd can be neither an
105 * archive nor an archive element, and the file must be executable. */
106
107 if (exec.a_trsize + exec.a_drsize == 0
108 && bfd_get_format(abfd) == bfd_object && abfd->my_archive == NULL)
109 {
110 struct stat buf;
111 #ifndef S_IXUSR
112 #define S_IXUSR 0100 /* Execute by owner. */
113 #endif
114 if (stat(abfd->filename, &buf) == 0 && (buf.st_mode & S_IXUSR))
115 abfd->flags |= EXEC_P;
116 }
117 #endif /* ENTRY_CAN_BE_ZERO */
118
119 return target;
120 }
121 #define MY_object_p MY(object_p)
122 #endif
123
124
125 #ifndef MY_mkobject
126 static boolean
127 DEFUN(MY(mkobject),(abfd),
128 bfd *abfd)
129 {
130 if (NAME(aout,mkobject)(abfd) == false)
131 return false;
132 #if 0 /* Sizes get set in set_sizes callback, later, after we know
133 the architecture and machine. */
134 adata(abfd).page_size = PAGE_SIZE;
135 #ifdef SEGMENT_SIZE
136 adata(abfd).segment_size = SEGMENT_SIZE;
137 #else
138 adata(abfd).segment_size = PAGE_SIZE;
139 #endif
140 adata(abfd).exec_bytes_size = EXEC_BYTES_SIZE;
141 #endif
142 return true;
143 }
144 #define MY_mkobject MY(mkobject)
145 #endif
146
147 /* Write an object file.
148 Section contents have already been written. We write the
149 file header, symbols, and relocation. */
150
151 #ifndef MY_write_object_contents
152 static boolean
153 DEFUN(MY(write_object_contents),(abfd),
154 bfd *abfd)
155 {
156 bfd_size_type data_pad = 0;
157 struct external_exec exec_bytes;
158 struct internal_exec *execp = exec_hdr (abfd);
159
160 #if CHOOSE_RELOC_SIZE
161 CHOOSE_RELOC_SIZE(abfd);
162 #else
163 obj_reloc_entry_size (abfd) = RELOC_STD_SIZE;
164 #endif
165
166 WRITE_HEADERS(abfd, execp);
167
168 return true;
169 }
170 #define MY_write_object_contents MY(write_object_contents)
171 #endif
172
173 #ifndef MY_set_sizes
174 static boolean
175 DEFUN(MY(set_sizes),(abfd), bfd *abfd)
176 {
177 adata(abfd).page_size = PAGE_SIZE;
178 #ifdef SEGMENT_SIZE
179 adata(abfd).segment_size = SEGMENT_SIZE;
180 #else
181 adata(abfd).segment_size = PAGE_SIZE;
182 #endif
183 adata(abfd).exec_bytes_size = EXEC_BYTES_SIZE;
184 return true;
185 }
186 #define MY_set_sizes MY(set_sizes)
187 #endif
188
189 #ifndef MY_backend_data
190 static CONST struct aout_backend_data MY(backend_data) = {
191 0, /* zmagic contiguous */
192 0, /* text incl header */
193 0, /* text vma? */
194 MY_set_sizes,
195 };
196 #define MY_backend_data &MY(backend_data)
197 #endif
198
199 /* We assume BFD generic archive files. */
200 #ifndef MY_openr_next_archived_file
201 #define MY_openr_next_archived_file bfd_generic_openr_next_archived_file
202 #endif
203 #ifndef MY_generic_stat_arch_elt
204 #define MY_generic_stat_arch_elt bfd_generic_stat_arch_elt
205 #endif
206 #ifndef MY_slurp_armap
207 #define MY_slurp_armap bfd_slurp_bsd_armap
208 #endif
209 #ifndef MY_slurp_extended_name_table
210 #define MY_slurp_extended_name_table _bfd_slurp_extended_name_table
211 #endif
212 #ifndef MY_write_armap
213 #define MY_write_armap bsd_write_armap
214 #endif
215 #ifndef MY_truncate_arname
216 #define MY_truncate_arname bfd_bsd_truncate_arname
217 #endif
218
219 /* No core file defined here -- configure in trad-core.c separately. */
220 #ifndef MY_core_file_failing_command
221 #define MY_core_file_failing_command _bfd_dummy_core_file_failing_command
222 #endif
223 #ifndef MY_core_file_failing_signal
224 #define MY_core_file_failing_signal _bfd_dummy_core_file_failing_signal
225 #endif
226 #ifndef MY_core_file_matches_executable_p
227 #define MY_core_file_matches_executable_p \
228 _bfd_dummy_core_file_matches_executable_p
229 #endif
230 #ifndef MY_core_file_p
231 #define MY_core_file_p _bfd_dummy_target
232 #endif
233
234 #ifndef MY_bfd_debug_info_start
235 #define MY_bfd_debug_info_start bfd_void
236 #endif
237 #ifndef MY_bfd_debug_info_end
238 #define MY_bfd_debug_info_end bfd_void
239 #endif
240 #ifndef MY_bfd_debug_info_accumulate
241 #define MY_bfd_debug_info_accumulate (PROTO(void,(*),(bfd*, struct sec *))) bfd_void
242 #endif
243
244 #ifndef MY_core_file_failing_command
245 #define MY_core_file_failing_command NAME(aout,core_file_failing_command)
246 #endif
247 #ifndef MY_core_file_failing_signal
248 #define MY_core_file_failing_signal NAME(aout,core_file_failing_signal)
249 #endif
250 #ifndef MY_core_file_matches_executable_p
251 #define MY_core_file_matches_executable_p NAME(aout,core_file_matches_executable_p)
252 #endif
253 #ifndef MY_slurp_armap
254 #define MY_slurp_armap NAME(aout,slurp_armap)
255 #endif
256 #ifndef MY_slurp_extended_name_table
257 #define MY_slurp_extended_name_table NAME(aout,slurp_extended_name_table)
258 #endif
259 #ifndef MY_truncate_arname
260 #define MY_truncate_arname NAME(aout,truncate_arname)
261 #endif
262 #ifndef MY_write_armap
263 #define MY_write_armap NAME(aout,write_armap)
264 #endif
265 #ifndef MY_close_and_cleanup
266 #define MY_close_and_cleanup NAME(aout,close_and_cleanup)
267 #endif
268 #ifndef MY_set_section_contents
269 #define MY_set_section_contents NAME(aout,set_section_contents)
270 #endif
271 #ifndef MY_get_section_contents
272 #define MY_get_section_contents NAME(aout,get_section_contents)
273 #endif
274 #ifndef MY_new_section_hook
275 #define MY_new_section_hook NAME(aout,new_section_hook)
276 #endif
277 #ifndef MY_get_symtab_upper_bound
278 #define MY_get_symtab_upper_bound NAME(aout,get_symtab_upper_bound)
279 #endif
280 #ifndef MY_get_symtab
281 #define MY_get_symtab NAME(aout,get_symtab)
282 #endif
283 #ifndef MY_get_reloc_upper_bound
284 #define MY_get_reloc_upper_bound NAME(aout,get_reloc_upper_bound)
285 #endif
286 #ifndef MY_canonicalize_reloc
287 #define MY_canonicalize_reloc NAME(aout,canonicalize_reloc)
288 #endif
289 #ifndef MY_make_empty_symbol
290 #define MY_make_empty_symbol NAME(aout,make_empty_symbol)
291 #endif
292 #ifndef MY_print_symbol
293 #define MY_print_symbol NAME(aout,print_symbol)
294 #endif
295 #ifndef MY_get_lineno
296 #define MY_get_lineno NAME(aout,get_lineno)
297 #endif
298 #ifndef MY_set_arch_mach
299 #define MY_set_arch_mach NAME(aout,set_arch_mach)
300 #endif
301 #ifndef MY_openr_next_archived_file
302 #define MY_openr_next_archived_file NAME(aout,openr_next_archived_file)
303 #endif
304 #ifndef MY_find_nearest_line
305 #define MY_find_nearest_line NAME(aout,find_nearest_line)
306 #endif
307 #ifndef MY_generic_stat_arch_elt
308 #define MY_generic_stat_arch_elt NAME(aout,generic_stat_arch_elt)
309 #endif
310 #ifndef MY_sizeof_headers
311 #define MY_sizeof_headers NAME(aout,sizeof_headers)
312 #endif
313 #ifndef MY_bfd_debug_info_start
314 #define MY_bfd_debug_info_start NAME(aout,bfd_debug_info_start)
315 #endif
316 #ifndef MY_bfd_debug_info_end
317 #define MY_bfd_debug_info_end NAME(aout,bfd_debug_info_end)
318 #endif
319 #ifndef MY_bfd_debug_info_accumulat
320 #define MY_bfd_debug_info_accumulat NAME(aout,bfd_debug_info_accumulat)
321 #endif
322 #ifndef MY_reloc_howto_type_lookup
323 #define MY_reloc_howto_type_lookup 0
324 #endif
325 #ifndef MY_make_debug_symbol
326 #define MY_make_debug_symbol 0
327 #endif
328
329 /* Aout symbols normally have leading underscores */
330 #ifndef MY_symbol_leading_char
331 #define MY_symbol_leading_char '_'
332 #endif
333
334 bfd_target MY(vec) =
335 {
336 TARGETNAME, /* name */
337 bfd_target_aout_flavour,
338 #ifdef TARGET_IS_BIG_ENDIAN_P
339 true, /* target byte order (big) */
340 true, /* target headers byte order (big) */
341 #else
342 false, /* target byte order (little) */
343 false, /* target headers byte order (little) */
344 #endif
345 (HAS_RELOC | EXEC_P | /* object flags */
346 HAS_LINENO | HAS_DEBUG |
347 HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED),
348 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
349 MY_symbol_leading_char,
350 ' ', /* ar_pad_char */
351 15, /* ar_max_namelen */
352 1, /* minimum alignment */
353 #ifdef TARGET_IS_BIG_ENDIAN_P
354 _do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16, /* data */
355 _do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16, /* hdrs */
356 #else
357 _do_getl64, _do_putl64, _do_getl32, _do_putl32, _do_getl16, _do_putl16, /* data */
358 _do_getl64, _do_putl64, _do_getl32, _do_putl32, _do_getl16, _do_putl16, /* hdrs */
359 #endif
360 {_bfd_dummy_target, MY_object_p, /* bfd_check_format */
361 bfd_generic_archive_p, MY_core_file_p},
362 {bfd_false, MY_mkobject, /* bfd_set_format */
363 _bfd_generic_mkarchive, bfd_false},
364 {bfd_false, MY_write_object_contents, /* bfd_write_contents */
365 _bfd_write_archive_contents, bfd_false},
366
367 MY_core_file_failing_command,
368 MY_core_file_failing_signal,
369 MY_core_file_matches_executable_p,
370 MY_slurp_armap,
371 MY_slurp_extended_name_table,
372 MY_truncate_arname,
373 MY_write_armap,
374 MY_close_and_cleanup,
375 MY_set_section_contents,
376 MY_get_section_contents,
377 MY_new_section_hook,
378 MY_get_symtab_upper_bound,
379 MY_get_symtab,
380 MY_get_reloc_upper_bound,
381 MY_canonicalize_reloc,
382 MY_make_empty_symbol,
383 MY_print_symbol,
384 MY_get_lineno,
385 MY_set_arch_mach,
386 MY_openr_next_archived_file,
387 MY_find_nearest_line,
388 MY_generic_stat_arch_elt,
389 MY_sizeof_headers,
390 MY_bfd_debug_info_start,
391 MY_bfd_debug_info_end,
392 MY_bfd_debug_info_accumulate,
393 bfd_generic_get_relocated_section_contents,
394 bfd_generic_relax_section,
395 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* COFF stuff?! */
396 MY_reloc_howto_type_lookup,
397 MY_make_debug_symbol,
398 (PTR) MY_backend_data,
399 };