eliminate most prototypes so ansidecl.h isn't needed before this file (incomplete)
[deliverable/binutils-gdb.git] / bfd / aoutx.h
1 /* BFD semi-generic back-end for a.out binaries.
2 Copyright 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
3 Written by Cygnus Support.
4
5 This file is part of BFD, the Binary File Descriptor library.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
20
21 /*
22 SECTION
23 a.out backends
24
25
26 DESCRIPTION
27
28 BFD supports a number of different flavours of a.out format,
29 though the major differences are only the sizes of the
30 structures on disk, and the shape of the relocation
31 information.
32
33 The support is split into a basic support file @code{aoutx.h}
34 and other files which derive functions from the base. One
35 derivation file is @code{aoutf1.h} (for a.out flavour 1), and
36 adds to the basic a.out functions support for sun3, sun4, 386
37 and 29k a.out files, to create a target jump vector for a
38 specific target.
39
40 This information is further split out into more specific files
41 for each machine, including @code{sunos.c} for sun3 and sun4,
42 @code{newsos3.c} for the Sony NEWS, and @code{demo64.c} for a
43 demonstration of a 64 bit a.out format.
44
45 The base file @code{aoutx.h} defines general mechanisms for
46 reading and writing records to and from disk, and various
47 other methods which BFD requires. It is included by
48 @code{aout32.c} and @code{aout64.c} to form the names
49 aout_32_swap_exec_header_in, aout_64_swap_exec_header_in, etc.
50
51 As an example, this is what goes on to make the back end for a
52 sun4, from aout32.c
53
54 | #define ARCH_SIZE 32
55 | #include "aoutx.h"
56
57 Which exports names:
58
59 | ...
60 | aout_32_canonicalize_reloc
61 | aout_32_find_nearest_line
62 | aout_32_get_lineno
63 | aout_32_get_reloc_upper_bound
64 | ...
65
66 from sunos.c
67
68 | #define ARCH 32
69 | #define TARGET_NAME "a.out-sunos-big"
70 | #define VECNAME sunos_big_vec
71 | #include "aoutf1.h"
72
73 requires all the names from aout32.c, and produces the jump vector
74
75 | sunos_big_vec
76
77 The file host-aout.c is a special case. It is for a large set
78 of hosts that use ``more or less standard'' a.out files, and
79 for which cross-debugging is not interesting. It uses the
80 standard 32-bit a.out support routines, but determines the
81 file offsets and addresses of the text, data, and BSS
82 sections, the machine architecture and machine type, and the
83 entry point address, in a host-dependent manner. Once these
84 values have been determined, generic code is used to handle
85 the object file.
86
87 When porting it to run on a new system, you must supply:
88
89 | HOST_PAGE_SIZE
90 | HOST_SEGMENT_SIZE
91 | HOST_MACHINE_ARCH (optional)
92 | HOST_MACHINE_MACHINE (optional)
93 | HOST_TEXT_START_ADDR
94 | HOST_STACK_END_ADDR
95
96 in the file <<../include/sys/h-XXX.h>> (for your host). These
97 values, plus the structures and macros defined in <<a.out.h>> on
98 your host system, will produce a BFD target that will access
99 ordinary a.out files on your host. To configure a new machine
100 to use <<host-aout.c>., specify:
101
102 | TDEFAULTS = -DDEFAULT_VECTOR=host_aout_big_vec
103 | TDEPFILES= host-aout.o trad-core.o
104
105 in the <<config/mt-XXX>> file, and modify configure.in to use the
106 <<mt-XXX>> file (by setting "<<bfd_target=XXX>>") when your
107 configuration is selected.
108
109 */
110
111 /* Some assumptions:
112 * Any BFD with D_PAGED set is ZMAGIC, and vice versa.
113 Doesn't matter what the setting of WP_TEXT is on output, but it'll
114 get set on input.
115 * Any BFD with D_PAGED clear and WP_TEXT set is NMAGIC.
116 * Any BFD with both flags clear is OMAGIC.
117 (Just want to make these explicit, so the conditions tested in this
118 file make sense if you're more familiar with a.out than with BFD.) */
119
120 #define KEEPIT flags
121 #define KEEPITTYPE int
122
123 #include <assert.h>
124 #include <string.h> /* For strchr and friends */
125 #include "bfd.h"
126 #include <sysdep.h>
127 #include <ansidecl.h>
128
129 struct external_exec;
130 #include "libaout.h"
131 #include "libbfd.h"
132 #include "aout/aout64.h"
133 #include "aout/stab_gnu.h"
134 #include "aout/ar.h"
135
136 extern void (*bfd_error_trap)();
137
138 /*
139 SUBSECTION
140 relocations
141
142 DESCRIPTION
143 The file @code{aoutx.h} caters for both the @emph{standard}
144 and @emph{extended} forms of a.out relocation records.
145
146 The standard records are characterised by containing only an
147 address, a symbol index and a type field. The extended records
148 (used on 29ks and sparcs) also have a full integer for an
149 addend.
150
151 */
152 #define CTOR_TABLE_RELOC_IDX 2
153
154 #define howto_table_ext NAME(aout,ext_howto_table)
155 #define howto_table_std NAME(aout,std_howto_table)
156
157 reloc_howto_type howto_table_ext[] =
158 {
159 HOWTO(RELOC_8, 0, 0, 8, false, 0, true, true,0,"8", false, 0,0x000000ff, false),
160 HOWTO(RELOC_16, 0, 1, 16, false, 0, true, true,0,"16", false, 0,0x0000ffff, false),
161 HOWTO(RELOC_32, 0, 2, 32, false, 0, true, true,0,"32", false, 0,0xffffffff, false),
162 HOWTO(RELOC_DISP8, 0, 0, 8, true, 0, false, true,0,"DISP8", false, 0,0x000000ff, false),
163 HOWTO(RELOC_DISP16, 0, 1, 16, true, 0, false, true,0,"DISP16", false, 0,0x0000ffff, false),
164 HOWTO(RELOC_DISP32, 0, 2, 32, true, 0, false, true,0,"DISP32", false, 0,0xffffffff, false),
165 HOWTO(RELOC_WDISP30,2, 2, 30, true, 0, false, true,0,"WDISP30", false, 0,0x3fffffff, false),
166 HOWTO(RELOC_WDISP22,2, 2, 22, true, 0, false, true,0,"WDISP22", false, 0,0x003fffff, false),
167 HOWTO(RELOC_HI22, 10, 2, 22, false, 0, false, true,0,"HI22", false, 0,0x003fffff, false),
168 HOWTO(RELOC_22, 0, 2, 22, false, 0, false, true,0,"22", false, 0,0x003fffff, false),
169 HOWTO(RELOC_13, 0, 2, 13, false, 0, false, true,0,"13", false, 0,0x00001fff, false),
170 HOWTO(RELOC_LO10, 0, 2, 10, false, 0, false, true,0,"LO10", false, 0,0x000003ff, false),
171 HOWTO(RELOC_SFA_BASE,0, 2, 32, false, 0, false, true,0,"SFA_BASE", false, 0,0xffffffff, false),
172 HOWTO(RELOC_SFA_OFF13,0,2, 32, false, 0, false, true,0,"SFA_OFF13",false, 0,0xffffffff, false),
173 HOWTO(RELOC_BASE10, 0, 2, 16, false, 0, false, true,0,"BASE10", false, 0,0x0000ffff, false),
174 HOWTO(RELOC_BASE13, 0, 2, 13, false, 0, false, true,0,"BASE13", false, 0,0x00001fff, false),
175 HOWTO(RELOC_BASE22, 0, 2, 0, false, 0, false, true,0,"BASE22", false, 0,0x00000000, false),
176 HOWTO(RELOC_PC10, 0, 2, 10, false, 0, false, true,0,"PC10", false, 0,0x000003ff, false),
177 HOWTO(RELOC_PC22, 0, 2, 22, false, 0, false, true,0,"PC22", false, 0,0x003fffff, false),
178 HOWTO(RELOC_JMP_TBL,0, 2, 32, false, 0, false, true,0,"JMP_TBL", false, 0,0xffffffff, false),
179 HOWTO(RELOC_SEGOFF16,0, 2, 0, false, 0, false, true,0,"SEGOFF16", false, 0,0x00000000, false),
180 HOWTO(RELOC_GLOB_DAT,0, 2, 0, false, 0, false, true,0,"GLOB_DAT", false, 0,0x00000000, false),
181 HOWTO(RELOC_JMP_SLOT,0, 2, 0, false, 0, false, true,0,"JMP_SLOT", false, 0,0x00000000, false),
182 HOWTO(RELOC_RELATIVE,0, 2, 0, false, 0, false, true,0,"RELATIVE", false, 0,0x00000000, false),
183 };
184
185 /* Convert standard reloc records to "arelent" format (incl byte swap). */
186
187 reloc_howto_type howto_table_std[] = {
188 /* type rs size bsz pcrel bitpos abs ovrf sf name part_inpl readmask setmask pcdone */
189 HOWTO( 0, 0, 0, 8, false, 0, true, true,0,"8", true, 0x000000ff,0x000000ff, false),
190 HOWTO( 1, 0, 1, 16, false, 0, true, true,0,"16", true, 0x0000ffff,0x0000ffff, false),
191 HOWTO( 2, 0, 2, 32, false, 0, true, true,0,"32", true, 0xffffffff,0xffffffff, false),
192 HOWTO( 3, 0, 3, 64, false, 0, true, true,0,"64", true, 0xdeaddead,0xdeaddead, false),
193 HOWTO( 4, 0, 0, 8, true, 0, false, true,0,"DISP8", true, 0x000000ff,0x000000ff, false),
194 HOWTO( 5, 0, 1, 16, true, 0, false, true,0,"DISP16", true, 0x0000ffff,0x0000ffff, false),
195 HOWTO( 6, 0, 2, 32, true, 0, false, true,0,"DISP32", true, 0xffffffff,0xffffffff, false),
196 HOWTO( 7, 0, 3, 64, true, 0, false, true,0,"DISP64", true, 0xfeedface,0xfeedface, false),
197 };
198
199 CONST struct reloc_howto_struct *
200 DEFUN(NAME(aout,reloc_type_lookup),(abfd,code),
201 bfd *abfd AND
202 bfd_reloc_code_real_type code)
203 {
204 #define EXT(i,j) case i: return &howto_table_ext[j]
205 #define STD(i,j) case i: return &howto_table_std[j]
206 int ext = obj_reloc_entry_size (abfd) == RELOC_EXT_SIZE;
207 if (code == BFD_RELOC_CTOR)
208 switch (bfd_get_arch_info (abfd)->bits_per_address)
209 {
210 case 32:
211 code = BFD_RELOC_32;
212 break;
213 }
214 if (ext)
215 switch (code)
216 {
217 EXT (BFD_RELOC_32, 2);
218 EXT (BFD_RELOC_HI22, 8);
219 EXT (BFD_RELOC_LO10, 11);
220 EXT (BFD_RELOC_32_PCREL_S2, 6);
221 default: return (CONST struct reloc_howto_struct *) 0;
222 }
223 else
224 /* std relocs */
225 switch (code)
226 {
227 STD (BFD_RELOC_16, 1);
228 STD (BFD_RELOC_32, 2);
229 STD (BFD_RELOC_8_PCREL, 4);
230 STD (BFD_RELOC_16_PCREL, 5);
231 STD (BFD_RELOC_32_PCREL, 6);
232 default: return (CONST struct reloc_howto_struct *) 0;
233 }
234 }
235
236 extern bfd_error_vector_type bfd_error_vector;
237
238 /*
239 SUBSECTION
240 Internal Entry Points
241
242 DESCRIPTION
243 @code{aoutx.h} exports several routines for accessing the
244 contents of an a.out file, which are gathered and exported in
245 turn by various format specific files (eg sunos.c).
246
247 */
248
249 /*
250 FUNCTION
251 aout_<size>_swap_exec_header_in
252
253 DESCRIPTION
254 Swaps the information in an executable header taken from a raw
255 byte stream memory image, into the internal exec_header
256 structure.
257
258 SYNOPSIS
259 void aout_<size>_swap_exec_header_in,
260 (bfd *abfd,
261 struct external_exec *raw_bytes,
262 struct internal_exec *execp);
263 */
264
265 void
266 DEFUN(NAME(aout,swap_exec_header_in),(abfd, raw_bytes, execp),
267 bfd *abfd AND
268 struct external_exec *raw_bytes AND
269 struct internal_exec *execp)
270 {
271 struct external_exec *bytes = (struct external_exec *)raw_bytes;
272
273 /* The internal_exec structure has some fields that are unused in this
274 configuration (IE for i960), so ensure that all such uninitialized
275 fields are zero'd out. There are places where two of these structs
276 are memcmp'd, and thus the contents do matter. */
277 memset (execp, 0, sizeof (struct internal_exec));
278 /* Now fill in fields in the execp, from the bytes in the raw data. */
279 execp->a_info = bfd_h_get_32 (abfd, bytes->e_info);
280 execp->a_text = GET_WORD (abfd, bytes->e_text);
281 execp->a_data = GET_WORD (abfd, bytes->e_data);
282 execp->a_bss = GET_WORD (abfd, bytes->e_bss);
283 execp->a_syms = GET_WORD (abfd, bytes->e_syms);
284 execp->a_entry = GET_WORD (abfd, bytes->e_entry);
285 execp->a_trsize = GET_WORD (abfd, bytes->e_trsize);
286 execp->a_drsize = GET_WORD (abfd, bytes->e_drsize);
287 }
288
289 /*
290 FUNCTION
291 aout_<size>_swap_exec_header_out
292
293 DESCRIPTION
294 Swaps the information in an internal exec header structure
295 into the supplied buffer ready for writing to disk.
296
297 SYNOPSIS
298 void aout_<size>_swap_exec_header_out
299 (bfd *abfd,
300 struct internal_exec *execp,
301 struct external_exec *raw_bytes);
302 */
303 void
304 DEFUN(NAME(aout,swap_exec_header_out),(abfd, execp, raw_bytes),
305 bfd *abfd AND
306 struct internal_exec *execp AND
307 struct external_exec *raw_bytes)
308 {
309 struct external_exec *bytes = (struct external_exec *)raw_bytes;
310
311 /* Now fill in fields in the raw data, from the fields in the exec struct. */
312 bfd_h_put_32 (abfd, execp->a_info , bytes->e_info);
313 PUT_WORD (abfd, execp->a_text , bytes->e_text);
314 PUT_WORD (abfd, execp->a_data , bytes->e_data);
315 PUT_WORD (abfd, execp->a_bss , bytes->e_bss);
316 PUT_WORD (abfd, execp->a_syms , bytes->e_syms);
317 PUT_WORD (abfd, execp->a_entry , bytes->e_entry);
318 PUT_WORD (abfd, execp->a_trsize, bytes->e_trsize);
319 PUT_WORD (abfd, execp->a_drsize, bytes->e_drsize);
320 }
321
322
323
324 /*
325 FUNCTION
326 aout_<size>_some_aout_object_p
327
328 DESCRIPTION
329 Some A.OUT variant thinks that the file whose format we're
330 checking is an a.out file. Do some more checking, and set up
331 for access if it really is. Call back to the calling
332 environments "finish up" function just before returning, to
333 handle any last-minute setup.
334
335 SYNOPSIS
336 bfd_target *aout_<size>_some_aout_object_p
337 (bfd *abfd,
338 bfd_target *(*callback_to_real_object_p)());
339 */
340
341 bfd_target *
342 DEFUN(NAME(aout,some_aout_object_p),(abfd, execp, callback_to_real_object_p),
343 bfd *abfd AND
344 struct internal_exec *execp AND
345 bfd_target *(*callback_to_real_object_p) PARAMS ((bfd *)))
346 {
347 struct aout_data_struct *rawptr, *oldrawptr;
348 bfd_target *result;
349
350 rawptr = (struct aout_data_struct *) bfd_zalloc (abfd, sizeof (struct aout_data_struct ));
351 if (rawptr == NULL) {
352 bfd_error = no_memory;
353 return 0;
354 }
355
356 oldrawptr = abfd->tdata.aout_data;
357 abfd->tdata.aout_data = rawptr;
358 abfd->tdata.aout_data->a.hdr = &rawptr->e;
359 *(abfd->tdata.aout_data->a.hdr) = *execp; /* Copy in the internal_exec struct */
360 execp = abfd->tdata.aout_data->a.hdr;
361
362 /* Set the file flags */
363 abfd->flags = NO_FLAGS;
364 if (execp->a_drsize || execp->a_trsize)
365 abfd->flags |= HAS_RELOC;
366 /* Setting of EXEC_P has been deferred to the bottom of this function */
367 if (execp->a_syms)
368 abfd->flags |= HAS_LINENO | HAS_DEBUG | HAS_SYMS | HAS_LOCALS;
369
370 if (N_MAGIC (*execp) == ZMAGIC)
371 {
372 abfd->flags |= D_PAGED|WP_TEXT;
373 adata(abfd).magic = z_magic;
374 }
375 else if (N_MAGIC (*execp) == NMAGIC)
376 {
377 abfd->flags |= WP_TEXT;
378 adata(abfd).magic = n_magic;
379 }
380 else
381 adata(abfd).magic = o_magic;
382
383 bfd_get_start_address (abfd) = execp->a_entry;
384
385 obj_aout_symbols (abfd) = (aout_symbol_type *)NULL;
386 bfd_get_symcount (abfd) = execp->a_syms / sizeof (struct external_nlist);
387
388 /* The default relocation entry size is that of traditional V7 Unix. */
389 obj_reloc_entry_size (abfd) = RELOC_STD_SIZE;
390
391 /* The default symbol entry size is that of traditional Unix. */
392 obj_symbol_entry_size (abfd) = EXTERNAL_NLIST_SIZE;
393
394 /* create the sections. This is raunchy, but bfd_close wants to reclaim
395 them */
396
397 obj_textsec (abfd) = bfd_make_section_old_way (abfd, ".text");
398 obj_datasec (abfd) = bfd_make_section_old_way (abfd, ".data");
399 obj_bsssec (abfd) = bfd_make_section_old_way (abfd, ".bss");
400
401 #if 0
402 (void)bfd_make_section (abfd, ".text");
403 (void)bfd_make_section (abfd, ".data");
404 (void)bfd_make_section (abfd, ".bss");
405 #endif
406
407 obj_datasec (abfd)->_raw_size = execp->a_data;
408 obj_bsssec (abfd)->_raw_size = execp->a_bss;
409
410 obj_textsec (abfd)->flags = (execp->a_trsize != 0 ?
411 (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS | SEC_RELOC) :
412 (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS));
413 obj_datasec (abfd)->flags = (execp->a_drsize != 0 ?
414 (SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_HAS_CONTENTS | SEC_RELOC) :
415 (SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_HAS_CONTENTS));
416 obj_bsssec (abfd)->flags = SEC_ALLOC;
417
418 #ifdef THIS_IS_ONLY_DOCUMENTATION
419 /* The common code can't fill in these things because they depend
420 on either the start address of the text segment, the rounding
421 up of virtual addersses between segments, or the starting file
422 position of the text segment -- all of which varies among different
423 versions of a.out. */
424
425 /* Call back to the format-dependent code to fill in the rest of the
426 fields and do any further cleanup. Things that should be filled
427 in by the callback: */
428
429 struct exec *execp = exec_hdr (abfd);
430
431 obj_textsec (abfd)->size = N_TXTSIZE(*execp);
432 obj_textsec (abfd)->raw_size = N_TXTSIZE(*execp);
433 /* data and bss are already filled in since they're so standard */
434
435 /* The virtual memory addresses of the sections */
436 obj_textsec (abfd)->vma = N_TXTADDR(*execp);
437 obj_datasec (abfd)->vma = N_DATADDR(*execp);
438 obj_bsssec (abfd)->vma = N_BSSADDR(*execp);
439
440 /* The file offsets of the sections */
441 obj_textsec (abfd)->filepos = N_TXTOFF(*execp);
442 obj_datasec (abfd)->filepos = N_DATOFF(*execp);
443
444 /* The file offsets of the relocation info */
445 obj_textsec (abfd)->rel_filepos = N_TRELOFF(*execp);
446 obj_datasec (abfd)->rel_filepos = N_DRELOFF(*execp);
447
448 /* The file offsets of the string table and symbol table. */
449 obj_str_filepos (abfd) = N_STROFF (*execp);
450 obj_sym_filepos (abfd) = N_SYMOFF (*execp);
451
452 /* Determine the architecture and machine type of the object file. */
453 switch (N_MACHTYPE (*exec_hdr (abfd))) {
454 default:
455 abfd->obj_arch = bfd_arch_obscure;
456 break;
457 }
458
459 adata(abfd)->page_size = PAGE_SIZE;
460 adata(abfd)->segment_size = SEGMENT_SIZE;
461 adata(abfd)->exec_bytes_size = EXEC_BYTES_SIZE;
462
463 return abfd->xvec;
464
465 /* The architecture is encoded in various ways in various a.out variants,
466 or is not encoded at all in some of them. The relocation size depends
467 on the architecture and the a.out variant. Finally, the return value
468 is the bfd_target vector in use. If an error occurs, return zero and
469 set bfd_error to the appropriate error code.
470
471 Formats such as b.out, which have additional fields in the a.out
472 header, should cope with them in this callback as well. */
473 #endif /* DOCUMENTATION */
474
475 result = (*callback_to_real_object_p)(abfd);
476
477 /* Now that the segment addresses have been worked out, take a better
478 guess at whether the file is executable. If the entry point
479 is within the text segment, assume it is. (This makes files
480 executable even if their entry point address is 0, as long as
481 their text starts at zero.)
482
483 At some point we should probably break down and stat the file and
484 declare it executable if (one of) its 'x' bits are on... */
485 if ((execp->a_entry >= obj_textsec(abfd)->vma) &&
486 (execp->a_entry < obj_textsec(abfd)->vma + obj_textsec(abfd)->_raw_size))
487 abfd->flags |= EXEC_P;
488 if (result)
489 {
490 #if 0 /* These should be set correctly anyways. */
491 abfd->sections = obj_textsec (abfd);
492 obj_textsec (abfd)->next = obj_datasec (abfd);
493 obj_datasec (abfd)->next = obj_bsssec (abfd);
494 #endif
495 }
496 else
497 {
498 free (rawptr);
499 abfd->tdata.aout_data = oldrawptr;
500 }
501 return result;
502 }
503
504 /*
505 FUNCTION
506 aout_<size>_mkobject
507
508 DESCRIPTION
509 This routine initializes a BFD for use with a.out files.
510
511 SYNOPSIS
512 boolean aout_<size>_mkobject, (bfd *);
513 */
514
515 boolean
516 DEFUN(NAME(aout,mkobject),(abfd),
517 bfd *abfd)
518 {
519 struct aout_data_struct *rawptr;
520
521 bfd_error = system_call_error;
522
523 /* Use an intermediate variable for clarity */
524 rawptr = (struct aout_data_struct *)bfd_zalloc (abfd, sizeof (struct aout_data_struct ));
525
526 if (rawptr == NULL) {
527 bfd_error = no_memory;
528 return false;
529 }
530
531 abfd->tdata.aout_data = rawptr;
532 exec_hdr (abfd) = &(rawptr->e);
533
534 /* For simplicity's sake we just make all the sections right here. */
535
536 obj_textsec (abfd) = (asection *)NULL;
537 obj_datasec (abfd) = (asection *)NULL;
538 obj_bsssec (abfd) = (asection *)NULL;
539 bfd_make_section (abfd, ".text");
540 bfd_make_section (abfd, ".data");
541 bfd_make_section (abfd, ".bss");
542 bfd_make_section (abfd, BFD_ABS_SECTION_NAME);
543 bfd_make_section (abfd, BFD_UND_SECTION_NAME);
544 bfd_make_section (abfd, BFD_COM_SECTION_NAME);
545
546 return true;
547 }
548
549
550 /*
551 FUNCTION
552 aout_<size>_machine_type
553
554 DESCRIPTION
555 Keep track of machine architecture and machine type for
556 a.out's. Return the machine_type for a particular
557 arch&machine, or M_UNKNOWN if that exact arch&machine can't be
558 represented in a.out format.
559
560 If the architecture is understood, machine type 0 (default)
561 should always be understood.
562
563 SYNOPSIS
564 enum machine_type aout_<size>_machine_type
565 (enum bfd_architecture arch,
566 unsigned long machine));
567 */
568
569 enum machine_type
570 DEFUN(NAME(aout,machine_type),(arch, machine),
571 enum bfd_architecture arch AND
572 unsigned long machine)
573 {
574 enum machine_type arch_flags;
575
576 arch_flags = M_UNKNOWN;
577
578 switch (arch) {
579 case bfd_arch_sparc:
580 if (machine == 0) arch_flags = M_SPARC;
581 break;
582
583 case bfd_arch_m68k:
584 switch (machine) {
585 case 0: arch_flags = M_68010; break;
586 case 68000: arch_flags = M_UNKNOWN; break;
587 case 68010: arch_flags = M_68010; break;
588 case 68020: arch_flags = M_68020; break;
589 default: arch_flags = M_UNKNOWN; break;
590 }
591 break;
592
593 case bfd_arch_i386:
594 if (machine == 0) arch_flags = M_386;
595 break;
596
597 case bfd_arch_a29k:
598 if (machine == 0) arch_flags = M_29K;
599 break;
600
601 case bfd_arch_mips:
602 switch (machine) {
603 case 0:
604 case 2000:
605 case 3000: arch_flags = M_MIPS1; break;
606 case 4000:
607 case 4400:
608 case 6000: arch_flags = M_MIPS2; break;
609 default: arch_flags = M_UNKNOWN; break;
610 }
611 break;
612
613 default:
614 arch_flags = M_UNKNOWN;
615 }
616 return arch_flags;
617 }
618
619
620 /*
621 FUNCTION
622 aout_<size>_set_arch_mach
623
624 DESCRIPTION
625 Sets the architecture and the machine of the BFD to those
626 values supplied. Verifies that the format can support the
627 architecture required.
628
629 SYNOPSIS
630 boolean aout_<size>_set_arch_mach,
631 (bfd *,
632 enum bfd_architecture,
633 unsigned long machine));
634 */
635
636 boolean
637 DEFUN(NAME(aout,set_arch_mach),(abfd, arch, machine),
638 bfd *abfd AND
639 enum bfd_architecture arch AND
640 unsigned long machine)
641 {
642 bfd_default_set_arch_mach(abfd, arch, machine);
643 if (arch != bfd_arch_unknown &&
644 NAME(aout,machine_type) (arch, machine) == M_UNKNOWN)
645 return false; /* We can't represent this type */
646
647 /* Determine the size of a relocation entry */
648 switch (arch) {
649 case bfd_arch_sparc:
650 case bfd_arch_a29k:
651 case bfd_arch_mips:
652 obj_reloc_entry_size (abfd) = RELOC_EXT_SIZE;
653 break;
654 default:
655 obj_reloc_entry_size (abfd) = RELOC_STD_SIZE;
656 break;
657 }
658
659 return (*aout_backend_info(abfd)->set_sizes) (abfd);
660 }
661
662 boolean
663 DEFUN (NAME (aout,adjust_sizes_and_vmas), (abfd, text_size, text_end),
664 bfd *abfd AND bfd_size_type *text_size AND file_ptr *text_end)
665 {
666 struct internal_exec *execp = exec_hdr (abfd);
667 if ((obj_textsec (abfd) == NULL) || (obj_datasec (abfd) == NULL))
668 {
669 bfd_error = invalid_operation;
670 return false;
671 }
672 if (adata(abfd).magic != undecided_magic) return true;
673 obj_textsec(abfd)->_raw_size =
674 align_power(obj_textsec(abfd)->_raw_size,
675 obj_textsec(abfd)->alignment_power);
676
677 *text_size = obj_textsec (abfd)->_raw_size;
678 /* Rule (heuristic) for when to pad to a new page. Note that there
679 * are (at least) two ways demand-paged (ZMAGIC) files have been
680 * handled. Most Berkeley-based systems start the text segment at
681 * (PAGE_SIZE). However, newer versions of SUNOS start the text
682 * segment right after the exec header; the latter is counted in the
683 * text segment size, and is paged in by the kernel with the rest of
684 * the text. */
685
686 /* This perhaps isn't the right way to do this, but made it simpler for me
687 to understand enough to implement it. Better would probably be to go
688 right from BFD flags to alignment/positioning characteristics. But the
689 old code was sloppy enough about handling the flags, and had enough
690 other magic, that it was a little hard for me to understand. I think
691 I understand it better now, but I haven't time to do the cleanup this
692 minute. */
693 if (adata(abfd).magic == undecided_magic)
694 {
695 if (abfd->flags & D_PAGED)
696 /* whether or not WP_TEXT is set */
697 adata(abfd).magic = z_magic;
698 else if (abfd->flags & WP_TEXT)
699 adata(abfd).magic = n_magic;
700 else
701 adata(abfd).magic = o_magic;
702 }
703
704 #ifdef BFD_AOUT_DEBUG /* requires gcc2 */
705 #if __GNUC__ >= 2
706 fprintf (stderr, "%s text=<%x,%x,%x> data=<%x,%x,%x> bss=<%x,%x,%x>\n",
707 ({ char *str;
708 switch (adata(abfd).magic) {
709 case n_magic: str = "NMAGIC"; break;
710 case o_magic: str = "OMAGIC"; break;
711 case z_magic: str = "ZMAGIC"; break;
712 default: abort ();
713 }
714 str;
715 }),
716 obj_textsec(abfd)->vma, obj_textsec(abfd)->_raw_size, obj_textsec(abfd)->alignment_power,
717 obj_datasec(abfd)->vma, obj_datasec(abfd)->_raw_size, obj_datasec(abfd)->alignment_power,
718 obj_bsssec(abfd)->vma, obj_bsssec(abfd)->_raw_size, obj_bsssec(abfd)->alignment_power);
719 #endif
720 #endif
721
722 switch (adata(abfd).magic)
723 {
724 case o_magic:
725 {
726 file_ptr pos = adata (abfd).exec_bytes_size;
727 bfd_vma vma = 0;
728 int pad = 0;
729
730 obj_textsec(abfd)->filepos = pos;
731 pos += obj_textsec(abfd)->_raw_size;
732 vma += obj_textsec(abfd)->_raw_size;
733 if (!obj_datasec(abfd)->user_set_vma)
734 {
735 #if 0 /* ?? Does alignment in the file image really matter? */
736 pad = align_power (vma, obj_datasec(abfd)->alignment_power) - vma;
737 #endif
738 obj_textsec(abfd)->_raw_size += pad;
739 pos += pad;
740 vma += pad;
741 obj_datasec(abfd)->vma = vma;
742 }
743 obj_datasec(abfd)->filepos = pos;
744 pos += obj_datasec(abfd)->_raw_size;
745 vma += obj_datasec(abfd)->_raw_size;
746 if (!obj_bsssec(abfd)->user_set_vma)
747 {
748 #if 0
749 pad = align_power (vma, obj_bsssec(abfd)->alignment_power) - vma;
750 #endif
751 obj_datasec(abfd)->_raw_size += pad;
752 pos += pad;
753 vma += pad;
754 obj_bsssec(abfd)->vma = vma;
755 }
756 obj_bsssec(abfd)->filepos = pos;
757 execp->a_text = obj_textsec(abfd)->_raw_size;
758 execp->a_data = obj_datasec(abfd)->_raw_size;
759 execp->a_bss = obj_bsssec(abfd)->_raw_size;
760 N_SET_MAGIC (*execp, OMAGIC);
761 }
762 break;
763 case z_magic:
764 {
765 bfd_size_type data_pad, text_pad;
766 file_ptr text_end;
767 CONST struct aout_backend_data *abdp;
768 int ztih;
769 bfd_vma data_vma;
770
771 abdp = aout_backend_info (abfd);
772 ztih = abdp && abdp->text_includes_header;
773 obj_textsec(abfd)->filepos = (ztih
774 ? adata(abfd).exec_bytes_size
775 : adata(abfd).page_size);
776 if (! obj_textsec(abfd)->user_set_vma)
777 /* ?? Do we really need to check for relocs here? */
778 obj_textsec(abfd)->vma = ((abfd->flags & HAS_RELOC)
779 ? 0
780 : (ztih
781 ? (abdp->default_text_vma
782 + adata(abfd).exec_bytes_size)
783 : abdp->default_text_vma));
784 /* Could take strange alignment of text section into account here? */
785
786 /* Find start of data. */
787 text_end = obj_textsec(abfd)->filepos + obj_textsec(abfd)->_raw_size;
788 text_pad = BFD_ALIGN (text_end, adata(abfd).page_size) - text_end;
789 obj_textsec(abfd)->_raw_size += text_pad;
790 text_end += text_pad;
791
792 if (!obj_datasec(abfd)->user_set_vma)
793 {
794 bfd_vma vma;
795 vma = obj_textsec(abfd)->vma + obj_textsec(abfd)->_raw_size;
796 obj_datasec(abfd)->vma = BFD_ALIGN (vma, adata(abfd).segment_size);
797 }
798 data_vma = obj_datasec(abfd)->vma;
799 if (abdp && abdp->zmagic_mapped_contiguous)
800 {
801 text_pad = (obj_datasec(abfd)->vma
802 - obj_textsec(abfd)->vma
803 - obj_textsec(abfd)->_raw_size);
804 obj_textsec(abfd)->_raw_size += text_pad;
805 }
806 obj_datasec(abfd)->filepos = (obj_textsec(abfd)->filepos
807 + obj_textsec(abfd)->_raw_size);
808
809 /* Fix up exec header while we're at it. */
810 execp->a_text = obj_textsec(abfd)->_raw_size;
811 if (ztih && (!abdp || (abdp && !abdp->exec_header_not_counted)))
812 execp->a_text += adata(abfd).exec_bytes_size;
813 N_SET_MAGIC (*execp, ZMAGIC);
814 /* Spec says data section should be rounded up to page boundary. */
815 /* If extra space in page is left after data section, fudge data
816 in the header so that the bss section looks smaller by that
817 amount. We'll start the bss section there, and lie to the OS. */
818 obj_datasec(abfd)->_raw_size
819 = align_power (obj_datasec(abfd)->_raw_size,
820 obj_bsssec(abfd)->alignment_power);
821 execp->a_data = BFD_ALIGN (obj_datasec(abfd)->_raw_size,
822 adata(abfd).page_size);
823 data_pad = execp->a_data - obj_datasec(abfd)->_raw_size;
824
825 if (!obj_bsssec(abfd)->user_set_vma)
826 obj_bsssec(abfd)->vma = (obj_datasec(abfd)->vma
827 + obj_datasec(abfd)->_raw_size);
828 if (data_pad > obj_bsssec(abfd)->_raw_size)
829 execp->a_bss = 0;
830 else
831 execp->a_bss = obj_bsssec(abfd)->_raw_size - data_pad;
832 }
833 break;
834 case n_magic:
835 {
836 file_ptr pos = adata(abfd).exec_bytes_size;
837 bfd_vma vma = 0;
838 int pad;
839
840 obj_textsec(abfd)->filepos = pos;
841 if (!obj_textsec(abfd)->user_set_vma)
842 obj_textsec(abfd)->vma = vma;
843 else
844 vma = obj_textsec(abfd)->vma;
845 pos += obj_textsec(abfd)->_raw_size;
846 vma += obj_textsec(abfd)->_raw_size;
847 obj_datasec(abfd)->filepos = pos;
848 if (!obj_datasec(abfd)->user_set_vma)
849 obj_datasec(abfd)->vma = BFD_ALIGN (vma, adata(abfd).segment_size);
850 vma = obj_datasec(abfd)->vma;
851
852 /* Since BSS follows data immediately, see if it needs alignment. */
853 vma += obj_datasec(abfd)->_raw_size;
854 pad = align_power (vma, obj_bsssec(abfd)->alignment_power) - vma;
855 obj_datasec(abfd)->_raw_size += pad;
856 pos += obj_datasec(abfd)->_raw_size;
857
858 if (!obj_bsssec(abfd)->user_set_vma)
859 obj_bsssec(abfd)->vma = vma;
860 else
861 vma = obj_bsssec(abfd)->vma;
862 }
863 execp->a_text = obj_textsec(abfd)->_raw_size;
864 execp->a_data = obj_datasec(abfd)->_raw_size;
865 execp->a_bss = obj_bsssec(abfd)->_raw_size;
866 N_SET_MAGIC (*execp, NMAGIC);
867 break;
868 default:
869 abort ();
870 }
871 #ifdef BFD_AOUT_DEBUG
872 fprintf (stderr, " text=<%x,%x,%x> data=<%x,%x,%x> bss=<%x,%x>\n",
873 obj_textsec(abfd)->vma, obj_textsec(abfd)->_raw_size, obj_textsec(abfd)->filepos,
874 obj_datasec(abfd)->vma, obj_datasec(abfd)->_raw_size, obj_datasec(abfd)->filepos,
875 obj_bsssec(abfd)->vma, obj_bsssec(abfd)->_raw_size);
876 #endif
877 return true;
878 }
879
880 /*
881 FUNCTION
882 aout_<size>_new_section_hook
883
884 DESCRIPTION
885 Called by the BFD in response to a @code{bfd_make_section}
886 request.
887
888 SYNOPSIS
889 boolean aout_<size>_new_section_hook,
890 (bfd *abfd,
891 asection *newsect));
892 */
893 boolean
894 DEFUN(NAME(aout,new_section_hook),(abfd, newsect),
895 bfd *abfd AND
896 asection *newsect)
897 {
898 /* align to double at least */
899 newsect->alignment_power = bfd_get_arch_info(abfd)->section_align_power;
900
901
902 if (bfd_get_format (abfd) == bfd_object)
903 {
904 if (obj_textsec(abfd) == NULL && !strcmp(newsect->name, ".text")) {
905 obj_textsec(abfd)= newsect;
906 newsect->target_index = N_TEXT | N_EXT;
907 return true;
908 }
909
910 if (obj_datasec(abfd) == NULL && !strcmp(newsect->name, ".data")) {
911 obj_datasec(abfd) = newsect;
912 newsect->target_index = N_DATA | N_EXT;
913 return true;
914 }
915
916 if (obj_bsssec(abfd) == NULL && !strcmp(newsect->name, ".bss")) {
917 obj_bsssec(abfd) = newsect;
918 newsect->target_index = N_BSS | N_EXT;
919 return true;
920 }
921
922 }
923
924 /* We allow more than three sections internally */
925 return true;
926 }
927
928 boolean
929 DEFUN(NAME(aout,set_section_contents),(abfd, section, location, offset, count),
930 bfd *abfd AND
931 sec_ptr section AND
932 PTR location AND
933 file_ptr offset AND
934 bfd_size_type count)
935 {
936 file_ptr text_end;
937 bfd_size_type text_size;
938
939 if (abfd->output_has_begun == false)
940 { /* set by bfd.c handler */
941 switch (abfd->direction)
942 {
943 case read_direction:
944 case no_direction:
945 bfd_error = invalid_operation;
946 return false;
947
948 case write_direction:
949 if (NAME(aout,adjust_sizes_and_vmas) (abfd,
950 &text_size,
951 &text_end) == false)
952 return false;
953 case both_direction:
954 break;
955 }
956 }
957
958 /* regardless, once we know what we're doing, we might as well get going */
959 if (section != obj_bsssec(abfd))
960 {
961 bfd_seek (abfd, section->filepos + offset, SEEK_SET);
962
963 if (count) {
964 return (bfd_write ((PTR)location, 1, count, abfd) == count) ?
965 true : false;
966 }
967 return true;
968 }
969 return true;
970 }
971 \f
972 /* Classify stabs symbols */
973
974 #define sym_in_text_section(sym) \
975 (((sym)->type & (N_ABS | N_TEXT | N_DATA | N_BSS))== N_TEXT)
976
977 #define sym_in_data_section(sym) \
978 (((sym)->type & (N_ABS | N_TEXT | N_DATA | N_BSS))== N_DATA)
979
980 #define sym_in_bss_section(sym) \
981 (((sym)->type & (N_ABS | N_TEXT | N_DATA | N_BSS))== N_BSS)
982
983 /* Symbol is undefined if type is N_UNDF|N_EXT and if it has
984 zero in the "value" field. Nonzeroes there are fortrancommon
985 symbols. */
986 #define sym_is_undefined(sym) \
987 ((sym)->type == (N_UNDF | N_EXT) && (sym)->symbol.value == 0)
988
989 /* Symbol is a global definition if N_EXT is on and if it has
990 a nonzero type field. */
991 #define sym_is_global_defn(sym) \
992 (((sym)->type & N_EXT) && (sym)->type & N_TYPE)
993
994 /* Symbol is debugger info if any bits outside N_TYPE or N_EXT
995 are on. */
996 #define sym_is_debugger_info(sym) \
997 ((sym)->type & ~(N_EXT | N_TYPE))
998
999 #define sym_is_fortrancommon(sym) \
1000 (((sym)->type == (N_EXT)) && (sym)->symbol.value != 0)
1001
1002 /* Symbol is absolute if it has N_ABS set */
1003 #define sym_is_absolute(sym) \
1004 (((sym)->type & N_TYPE)== N_ABS)
1005
1006
1007 #define sym_is_indirect(sym) \
1008 (((sym)->type & N_ABS)== N_ABS)
1009
1010 /* Only in their own functions for ease of debugging; when sym flags have
1011 stabilised these should be inlined into their (single) caller */
1012
1013 static void
1014 DEFUN (translate_from_native_sym_flags, (sym_pointer, cache_ptr, abfd, statep),
1015 struct external_nlist *sym_pointer AND
1016 aout_symbol_type * cache_ptr AND
1017 bfd * abfd AND
1018 int *statep)
1019 {
1020 cache_ptr->symbol.section = 0;
1021 if (*statep)
1022 {
1023 /* This is an indirect symbol */
1024 cache_ptr->symbol.flags = BSF_DEBUGGING;
1025 cache_ptr->symbol.section = &bfd_und_section;
1026 *statep = 0;
1027 }
1028 else
1029 {
1030 switch (cache_ptr->type & N_TYPE)
1031 {
1032 case N_SETA:
1033 case N_SETT:
1034 case N_SETD:
1035 case N_SETB:
1036 {
1037 char *copy = bfd_alloc (abfd, strlen (cache_ptr->symbol.name) + 1);
1038 asection *section;
1039 asection *into_section;
1040
1041 arelent_chain *reloc = (arelent_chain *) bfd_alloc (abfd, sizeof (arelent_chain));
1042 strcpy (copy, cache_ptr->symbol.name);
1043
1044 /* Make sure that this bfd has a section with the right contructor
1045 name */
1046 section = bfd_get_section_by_name (abfd, copy);
1047 if (!section)
1048 section = bfd_make_section (abfd, copy);
1049
1050 /* Build a relocation entry for the constructor */
1051 switch ((cache_ptr->type & N_TYPE))
1052 {
1053 case N_SETA:
1054 into_section = &bfd_abs_section;
1055 break;
1056 case N_SETT:
1057 into_section = (asection *) obj_textsec (abfd);
1058 break;
1059 case N_SETD:
1060 into_section = (asection *) obj_datasec (abfd);
1061 break;
1062 case N_SETB:
1063 into_section = (asection *) obj_bsssec (abfd);
1064 break;
1065 default:
1066 abort ();
1067 }
1068
1069 /* Build a relocation pointing into the constuctor section
1070 pointing at the symbol in the set vector specified */
1071
1072 reloc->relent.addend = cache_ptr->symbol.value;
1073 cache_ptr->symbol.section = into_section->symbol->section;
1074 reloc->relent.sym_ptr_ptr = into_section->symbol_ptr_ptr;
1075
1076
1077 /* We modify the symbol to belong to a section depending upon the
1078 name of the symbol - probably __CTOR__ or __DTOR__ but we don't
1079 really care, and add to the size of the section to contain a
1080 pointer to the symbol. Build a reloc entry to relocate to this
1081 symbol attached to this section. */
1082
1083 section->flags = SEC_CONSTRUCTOR;
1084
1085
1086 section->reloc_count++;
1087 section->alignment_power = 2;
1088
1089 reloc->next = section->constructor_chain;
1090 section->constructor_chain = reloc;
1091 reloc->relent.address = section->_raw_size;
1092 section->_raw_size += sizeof (int *);
1093
1094 reloc->relent.howto = howto_table_ext + CTOR_TABLE_RELOC_IDX;
1095 cache_ptr->symbol.flags |= BSF_DEBUGGING | BSF_CONSTRUCTOR;
1096 }
1097 break;
1098 default:
1099 if (cache_ptr->type == N_WARNING)
1100 {
1101 /* This symbol is the text of a warning message, the next symbol
1102 is the symbol to associate the warning with */
1103 cache_ptr->symbol.flags = BSF_DEBUGGING | BSF_WARNING;
1104 cache_ptr->symbol.value = (bfd_vma) ((cache_ptr + 1));
1105 /* We furgle with the next symbol in place.
1106 We don't want it to be undefined, we'll trample the type */
1107 (sym_pointer + 1)->e_type[0] = 0xff;
1108 break;
1109 }
1110 if ((cache_ptr->type | N_EXT) == (N_INDR | N_EXT))
1111 {
1112 /* Two symbols in a row for an INDR message. The first symbol
1113 contains the name we will match, the second symbol contains
1114 the name the first name is translated into. It is supplied to
1115 us undefined. This is good, since we want to pull in any files
1116 which define it */
1117 cache_ptr->symbol.flags = BSF_DEBUGGING | BSF_INDIRECT;
1118 cache_ptr->symbol.value = (bfd_vma) ((cache_ptr + 1));
1119 cache_ptr->symbol.section = &bfd_ind_section;
1120 *statep = 1;
1121 }
1122
1123 else if (sym_is_debugger_info (cache_ptr))
1124 {
1125 cache_ptr->symbol.flags = BSF_DEBUGGING;
1126 /* Work out the section correct for this symbol */
1127 switch (cache_ptr->type & N_TYPE)
1128 {
1129 case N_TEXT:
1130 case N_FN:
1131 cache_ptr->symbol.section = obj_textsec (abfd);
1132 cache_ptr->symbol.value -= obj_textsec (abfd)->vma;
1133 break;
1134 case N_DATA:
1135 cache_ptr->symbol.value -= obj_datasec (abfd)->vma;
1136 cache_ptr->symbol.section = obj_datasec (abfd);
1137 break;
1138 case N_BSS:
1139 cache_ptr->symbol.section = obj_bsssec (abfd);
1140 cache_ptr->symbol.value -= obj_bsssec (abfd)->vma;
1141 break;
1142 default:
1143 case N_ABS:
1144
1145 cache_ptr->symbol.section = &bfd_abs_section;
1146 break;
1147 }
1148 }
1149 else
1150 {
1151
1152 if (sym_is_fortrancommon (cache_ptr))
1153 {
1154 cache_ptr->symbol.flags = 0;
1155 cache_ptr->symbol.section = &bfd_com_section;
1156 }
1157 else
1158 {
1159
1160
1161 }
1162
1163 /* In a.out, the value of a symbol is always relative to the
1164 * start of the file, if this is a data symbol we'll subtract
1165 * the size of the text section to get the section relative
1166 * value. If this is a bss symbol (which would be strange)
1167 * we'll subtract the size of the previous two sections
1168 * to find the section relative address.
1169 */
1170
1171 if (sym_in_text_section (cache_ptr))
1172 {
1173 cache_ptr->symbol.value -= obj_textsec (abfd)->vma;
1174 cache_ptr->symbol.section = obj_textsec (abfd);
1175 }
1176 else if (sym_in_data_section (cache_ptr))
1177 {
1178 cache_ptr->symbol.value -= obj_datasec (abfd)->vma;
1179 cache_ptr->symbol.section = obj_datasec (abfd);
1180 }
1181 else if (sym_in_bss_section (cache_ptr))
1182 {
1183 cache_ptr->symbol.section = obj_bsssec (abfd);
1184 cache_ptr->symbol.value -= obj_bsssec (abfd)->vma;
1185 }
1186 else if (sym_is_undefined (cache_ptr))
1187 {
1188 cache_ptr->symbol.flags = 0;
1189 cache_ptr->symbol.section = &bfd_und_section;
1190 }
1191 else if (sym_is_absolute (cache_ptr))
1192 {
1193 cache_ptr->symbol.section = &bfd_abs_section;
1194 }
1195
1196 if (sym_is_global_defn (cache_ptr))
1197 {
1198 cache_ptr->symbol.flags = BSF_GLOBAL | BSF_EXPORT;
1199 }
1200 else
1201 {
1202 cache_ptr->symbol.flags = BSF_LOCAL;
1203 }
1204 }
1205 }
1206 }
1207 if (cache_ptr->symbol.section == 0)
1208 abort ();
1209 }
1210
1211
1212
1213 static void
1214 DEFUN(translate_to_native_sym_flags,(sym_pointer, cache_ptr, abfd),
1215 struct external_nlist *sym_pointer AND
1216 asymbol *cache_ptr AND
1217 bfd *abfd)
1218 {
1219 bfd_vma value = cache_ptr->value;
1220
1221 /* mask out any existing type bits in case copying from one section
1222 to another */
1223 sym_pointer->e_type[0] &= ~N_TYPE;
1224
1225
1226 if (bfd_get_output_section(cache_ptr) == obj_bsssec (abfd)) {
1227 sym_pointer->e_type[0] |= N_BSS;
1228 }
1229 else if (bfd_get_output_section(cache_ptr) == obj_datasec (abfd)) {
1230 sym_pointer->e_type[0] |= N_DATA;
1231 }
1232 else if (bfd_get_output_section(cache_ptr) == obj_textsec (abfd)) {
1233 sym_pointer->e_type[0] |= N_TEXT;
1234 }
1235 else if (bfd_get_output_section(cache_ptr) == &bfd_abs_section)
1236 {
1237 sym_pointer->e_type[0] |= N_ABS;
1238 }
1239 else if (bfd_get_output_section(cache_ptr) == &bfd_und_section)
1240 {
1241 sym_pointer->e_type[0] = (N_UNDF | N_EXT);
1242 }
1243 else if (bfd_get_output_section(cache_ptr) == &bfd_ind_section)
1244 {
1245 sym_pointer->e_type[0] = N_INDR;
1246 }
1247 else if (bfd_is_com_section (bfd_get_output_section (cache_ptr))) {
1248 sym_pointer->e_type[0] = (N_UNDF | N_EXT);
1249 }
1250 else {
1251 if (cache_ptr->section->output_section)
1252 {
1253
1254 bfd_error_vector.nonrepresentable_section(abfd,
1255 bfd_get_output_section(cache_ptr)->name);
1256 }
1257 else
1258 {
1259 bfd_error_vector.nonrepresentable_section(abfd,
1260 cache_ptr->section->name);
1261
1262 }
1263
1264 }
1265 /* Turn the symbol from section relative to absolute again */
1266
1267 value += cache_ptr->section->output_section->vma + cache_ptr->section->output_offset ;
1268
1269
1270 if (cache_ptr->flags & (BSF_WARNING)) {
1271 (sym_pointer+1)->e_type[0] = 1;
1272 }
1273
1274 if (cache_ptr->flags & (BSF_GLOBAL | BSF_EXPORT)) {
1275 sym_pointer->e_type[0] |= N_EXT;
1276 }
1277 if (cache_ptr->flags & BSF_DEBUGGING) {
1278 sym_pointer->e_type [0]= ((aout_symbol_type *)cache_ptr)->type;
1279 }
1280
1281 PUT_WORD(abfd, value, sym_pointer->e_value);
1282 }
1283 \f
1284 /* Native-level interface to symbols. */
1285
1286 /* We read the symbols into a buffer, which is discarded when this
1287 function exits. We read the strings into a buffer large enough to
1288 hold them all plus all the cached symbol entries. */
1289
1290 asymbol *
1291 DEFUN(NAME(aout,make_empty_symbol),(abfd),
1292 bfd *abfd)
1293 {
1294 aout_symbol_type *new =
1295 (aout_symbol_type *)bfd_zalloc (abfd, sizeof (aout_symbol_type));
1296 new->symbol.the_bfd = abfd;
1297
1298 return &new->symbol;
1299 }
1300
1301 boolean
1302 DEFUN(NAME(aout,slurp_symbol_table),(abfd),
1303 bfd *abfd)
1304 {
1305 bfd_size_type symbol_size;
1306 bfd_size_type string_size;
1307 unsigned char string_chars[BYTES_IN_WORD];
1308 struct external_nlist *syms;
1309 char *strings;
1310 aout_symbol_type *cached;
1311
1312 /* If there's no work to be done, don't do any */
1313 if (obj_aout_symbols (abfd) != (aout_symbol_type *)NULL) return true;
1314 symbol_size = exec_hdr(abfd)->a_syms;
1315 if (symbol_size == 0)
1316 {
1317 bfd_error = no_symbols;
1318 return false;
1319 }
1320
1321 bfd_seek (abfd, obj_str_filepos (abfd), SEEK_SET);
1322 if (bfd_read ((PTR)string_chars, BYTES_IN_WORD, 1, abfd) != BYTES_IN_WORD)
1323 return false;
1324 string_size = GET_WORD (abfd, string_chars);
1325
1326 strings =(char *) bfd_alloc(abfd, string_size + 1);
1327 cached = (aout_symbol_type *)
1328 bfd_zalloc(abfd, (bfd_size_type)(bfd_get_symcount (abfd) * sizeof(aout_symbol_type)));
1329
1330 /* malloc this, so we can free it if simply. The symbol caching
1331 might want to allocate onto the bfd's obstack */
1332 syms = (struct external_nlist *) bfd_xmalloc(symbol_size);
1333 bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET);
1334 if (bfd_read ((PTR)syms, 1, symbol_size, abfd) != symbol_size)
1335 {
1336 bailout:
1337 if (syms)
1338 free (syms);
1339 if (cached)
1340 bfd_release (abfd, cached);
1341 if (strings)
1342 bfd_release (abfd, strings);
1343 return false;
1344 }
1345
1346 bfd_seek (abfd, obj_str_filepos (abfd), SEEK_SET);
1347 if (bfd_read ((PTR)strings, 1, string_size, abfd) != string_size)
1348 {
1349 goto bailout;
1350 }
1351 strings[string_size] = 0; /* Just in case. */
1352
1353 /* OK, now walk the new symtable, cacheing symbol properties */
1354 {
1355 register struct external_nlist *sym_pointer;
1356 int state = 0;
1357 register struct external_nlist *sym_end = syms + bfd_get_symcount (abfd);
1358 register aout_symbol_type *cache_ptr = cached;
1359
1360 /* Run through table and copy values */
1361 for (sym_pointer = syms, cache_ptr = cached;
1362 sym_pointer < sym_end; sym_pointer ++, cache_ptr++)
1363 {
1364 long x = GET_WORD(abfd, sym_pointer->e_strx);
1365 cache_ptr->symbol.the_bfd = abfd;
1366 if (x == 0)
1367 cache_ptr->symbol.name = "";
1368 else if (x >= 0 && x < string_size)
1369 cache_ptr->symbol.name = x + strings;
1370 else
1371 goto bailout;
1372
1373 cache_ptr->symbol.value = GET_SWORD(abfd, sym_pointer->e_value);
1374 cache_ptr->desc = bfd_h_get_16(abfd, sym_pointer->e_desc);
1375 cache_ptr->other = bfd_h_get_8(abfd, sym_pointer->e_other);
1376 cache_ptr->type = bfd_h_get_8(abfd, sym_pointer->e_type);
1377 cache_ptr->symbol.udata = 0;
1378 translate_from_native_sym_flags (sym_pointer, cache_ptr,
1379 abfd, &state);
1380 }
1381 }
1382
1383 obj_aout_symbols (abfd) = cached;
1384 free((PTR)syms);
1385
1386 return true;
1387 }
1388
1389 \f
1390 /* Possible improvements:
1391 + look for strings matching trailing substrings of other strings
1392 + better data structures? balanced trees?
1393 + smaller per-string or per-symbol data? re-use some of the symbol's
1394 data fields?
1395 + also look at reducing memory use elsewhere -- maybe if we didn't have to
1396 construct the entire symbol table at once, we could get by with smaller
1397 amounts of VM? (What effect does that have on the string table
1398 reductions?)
1399 + rip this out of here, put it into its own file in bfd or libiberty, so
1400 coff and elf can use it too. I'll work on this soon, but have more
1401 pressing tasks right now.
1402
1403 A hash table might(?) be more efficient for handling exactly the cases that
1404 are handled now, but for trailing substring matches, I think we want to
1405 examine the `nearest' values (reverse-)lexically, not merely impose a strict
1406 order, nor look only for exact-match or not-match. I don't think a hash
1407 table would be very useful for that, and I don't feel like fleshing out two
1408 completely different implementations. [raeburn:930419.0331EDT] */
1409
1410 #if __GNUC__ >= 2
1411 #define INLINE __inline__
1412 #else
1413 #define INLINE
1414 #endif
1415
1416 struct stringtab_entry {
1417 /* Hash value for this string. Only useful so long as we aren't doing
1418 substring matches. */
1419 int hash;
1420
1421 /* Next node to look at, depending on whether the hash value of the string
1422 being searched for is less than or greater than the hash value of the
1423 current node. For now, `equal to' is lumped in with `greater than', for
1424 space efficiency. It's not a common enough case to warrant another field
1425 to be used for all nodes. */
1426 struct stringtab_entry *less;
1427 struct stringtab_entry *greater;
1428
1429 /* The string itself. */
1430 CONST char *string;
1431
1432 /* The index allocated for this string. */
1433 bfd_size_type index;
1434
1435 #ifdef GATHER_STATISTICS
1436 /* How many references have there been to this string? (Not currently used;
1437 could be dumped out for anaylsis, if anyone's interested.) */
1438 unsigned long count;
1439 #endif
1440
1441 /* Next node in linked list, in suggested output order. */
1442 struct stringtab_entry *next_to_output;
1443 };
1444
1445 struct stringtab_data {
1446 /* Tree of string table entries. */
1447 struct stringtab_entry *strings;
1448
1449 /* Fudge factor used to center top node of tree. */
1450 int hash_zero;
1451
1452 /* Next index value to issue. */
1453 bfd_size_type index;
1454
1455 /* Index used for empty strings. Cached here because checking for them
1456 is really easy, and we can avoid searching the tree. */
1457 bfd_size_type empty_string_index;
1458
1459 /* These fields indicate the two ends of a singly-linked list that indicates
1460 the order strings should be written out in. Use this order, and no
1461 seeking will need to be done, so output efficiency should be maximized. */
1462 struct stringtab_entry **end;
1463 struct stringtab_entry *output_order;
1464
1465 #ifdef GATHER_STATISTICS
1466 /* Number of strings which duplicate strings already in the table. */
1467 unsigned long duplicates;
1468
1469 /* Number of bytes saved by not having to write all the duplicate strings. */
1470 unsigned long bytes_saved;
1471
1472 /* Number of zero-length strings. Currently, these all turn into
1473 references to the null byte at the end of the first string. In some
1474 cases (possibly not all? explore this...), it should be possible to
1475 simply write out a zero index value. */
1476 unsigned long empty_strings;
1477
1478 /* Number of times the hash values matched but the strings were different.
1479 Note that this includes the number of times the other string(s) occurs, so
1480 there may only be two strings hashing to the same value, even if this
1481 number is very large. */
1482 unsigned long bad_hash_matches;
1483
1484 /* Null strings aren't counted in this one.
1485 This will probably only be nonzero if we've got an input file
1486 which was produced by `ld -r' (i.e., it's already been processed
1487 through this code). Under some operating systems, native tools
1488 may make all empty strings have the same index; but the pointer
1489 check won't catch those, because to get to that stage we'd already
1490 have to compute the checksum, which requires reading the string,
1491 so we short-circuit that case with empty_string_index above. */
1492 unsigned long pointer_matches;
1493
1494 /* Number of comparisons done. I figure with the algorithms in use below,
1495 the average number of comparisons done (per symbol) should be roughly
1496 log-base-2 of the number of unique strings. */
1497 unsigned long n_compares;
1498 #endif
1499 };
1500
1501 /* Some utility functions for the string table code. */
1502
1503 static INLINE int
1504 hash (string)
1505 char *string;
1506 {
1507 unsigned int sum = 0;
1508 while (*string)
1509 {
1510 #if 0
1511 /* This expression borrowed from some code in gnu make. */
1512 sum += *string++, sum = (sum << 7) + (sum >> 20);
1513 #endif
1514 /* This appears to get a better distribution, at least for my one
1515 test case. Do some analysis on this later, get a real hash
1516 algorithm. */
1517 sum ^= sum >> 20;
1518 sum ^= sum << 7;
1519 sum += *string++;
1520 }
1521 return sum;
1522 }
1523
1524 static INLINE void
1525 stringtab_init (tab)
1526 struct stringtab_data *tab;
1527 {
1528 tab->strings = 0;
1529 tab->output_order = 0;
1530 tab->end = &tab->output_order;
1531
1532 /* Initial string table length includes size of length field. */
1533 tab->index = BYTES_IN_WORD;
1534 tab->empty_string_index = -1;
1535 #ifdef GATHER_STATISTICS
1536 tab->duplicates = 0;
1537 tab->empty_strings = 0;
1538 tab->bad_hash_matches = 0;
1539 tab->pointer_matches = 0;
1540 tab->bytes_saved = 0;
1541 tab->n_compares = 0;
1542 #endif
1543 }
1544
1545 static INLINE int
1546 compare (entry, str, hash)
1547 struct stringtab_entry *entry;
1548 CONST char *str;
1549 int hash;
1550 {
1551 if (hash == entry->hash)
1552 return 0;
1553 if (hash > entry->hash)
1554 return 1;
1555 if (hash < entry->hash)
1556 return -1;
1557 abort ();
1558 }
1559
1560 #ifdef GATHER_STATISTICS
1561 /* Don't want to have to link in math library with all bfd applications... */
1562 static INLINE double
1563 log2 (num)
1564 int num;
1565 {
1566 double d = num;
1567 #if defined (__i386__) && __GNUC__ >= 2
1568 asm ("fyl2x" : "=t" (d) : "0" (d), "u" (1.0));
1569 return d;
1570 #else
1571 int n = 0;
1572 while (d >= 2.0)
1573 n++, d /= 2.0;
1574 return ((d > 1.41) ? 0.5 : 0) + n;
1575 #endif
1576 }
1577 #endif
1578
1579 /* Main string table routines. */
1580 /* Returns index in string table. Whether or not this actually adds an
1581 entry into the string table should be irrelevant -- it just has to
1582 return a valid index. */
1583 static bfd_size_type
1584 add_to_stringtab (abfd, str, tab, check)
1585 bfd *abfd;
1586 CONST char *str;
1587 struct stringtab_data *tab;
1588 int check;
1589 {
1590 struct stringtab_entry **ep;
1591 struct stringtab_entry *entry;
1592 int hashval, len;
1593
1594 if (str[0] == 0)
1595 {
1596 bfd_size_type index;
1597 CONST bfd_size_type minus_one = -1;
1598
1599 #ifdef GATHER_STATISTICS
1600 tab->empty_strings++;
1601 #endif
1602 index = tab->empty_string_index;
1603 if (index != minus_one)
1604 {
1605 got_empty:
1606 #ifdef GATHER_STATISTICS
1607 tab->bytes_saved++;
1608 tab->duplicates++;
1609 #endif
1610 return index;
1611 }
1612
1613 /* Need to find it. */
1614 entry = tab->strings;
1615 if (entry)
1616 {
1617 index = entry->index + strlen (entry->string);
1618 tab->empty_string_index = index;
1619 goto got_empty;
1620 }
1621 len = 0;
1622 }
1623 else
1624 len = strlen (str);
1625
1626 /* The hash_zero value is chosen such that the first symbol gets a value of
1627 zero. With a balanced tree, this wouldn't be very useful, but without it,
1628 we might get a more even split at the top level, instead of skewing it
1629 badly should hash("/usr/lib/crt0.o") (or whatever) be far from zero. */
1630 hashval = hash (str) ^ tab->hash_zero;
1631 ep = &tab->strings;
1632 if (!*ep)
1633 {
1634 tab->hash_zero = hashval;
1635 hashval = 0;
1636 goto add_it;
1637 }
1638
1639 while (*ep)
1640 {
1641 int cmp;
1642 entry = *ep;
1643 #ifdef GATHER_STATISTICS
1644 tab->n_compares++;
1645 #endif
1646 cmp = compare (entry, str, hashval);
1647 if (cmp == 0)
1648 {
1649 if (entry->string == str)
1650 {
1651 #ifdef GATHER_STATISTICS
1652 tab->pointer_matches++;
1653 #endif
1654 goto match;
1655 }
1656 if (!strcmp (entry->string, str))
1657 {
1658 match:
1659 #ifdef GATHER_STATISTICS
1660 entry->count++;
1661 tab->bytes_saved += len + 1;
1662 tab->duplicates++;
1663 #endif
1664 /* If we're in the linker, and the new string is from a new
1665 input file which might have already had these reductions
1666 run over it, we want to keep the new string pointer. I
1667 don't think we're likely to see any (or nearly as many,
1668 at least) cases where a later string is in the same location
1669 as an earlier one rather than this one. */
1670 entry->string = str;
1671 return entry->index;
1672 }
1673 #ifdef GATHER_STATISTICS
1674 tab->bad_hash_matches++;
1675 #endif
1676 ep = &entry->greater;
1677 }
1678 else if (cmp > 0)
1679 ep = &entry->greater;
1680 else
1681 /* cmp < 0 */
1682 ep = &entry->less;
1683 }
1684
1685 /* If we get here, nothing that's in the table already matched.
1686 EP points to the `next' field at the end of the chain; stick a
1687 new entry on here. */
1688 add_it:
1689 entry = (struct stringtab_entry *) bfd_alloc_by_size_t (abfd,
1690 sizeof (struct stringtab_entry));
1691
1692 entry->less = entry->greater = 0;
1693 entry->hash = hashval;
1694 entry->index = tab->index;
1695 entry->string = str;
1696 entry->next_to_output = 0;
1697 #ifdef GATHER_STATISTICS
1698 entry->count = 1;
1699 #endif
1700
1701 assert (*tab->end == 0);
1702 *(tab->end) = entry;
1703 tab->end = &entry->next_to_output;
1704 assert (*tab->end == 0);
1705
1706 {
1707 tab->index += len + 1;
1708 if (len == 0)
1709 tab->empty_string_index = entry->index;
1710 }
1711 assert (*ep == 0);
1712 *ep = entry;
1713 return entry->index;
1714 }
1715
1716 static void
1717 emit_strtab (abfd, tab)
1718 bfd *abfd;
1719 struct stringtab_data *tab;
1720 {
1721 struct stringtab_entry *entry;
1722 #ifdef GATHER_STATISTICS
1723 int count = 0;
1724 #endif
1725
1726 /* Be sure to put string length into correct byte ordering before writing
1727 it out. */
1728 char buffer[BYTES_IN_WORD];
1729
1730 PUT_WORD (abfd, tab->index, (unsigned char *) buffer);
1731 bfd_write ((PTR) buffer, 1, BYTES_IN_WORD, abfd);
1732
1733 for (entry = tab->output_order; entry; entry = entry->next_to_output)
1734 {
1735 bfd_write ((PTR) entry->string, 1, strlen (entry->string) + 1, abfd);
1736 #ifdef GATHER_STATISTICS
1737 count++;
1738 #endif
1739 }
1740
1741 #ifdef GATHER_STATISTICS
1742 /* Short form only, for now.
1743 To do: Specify output file. Conditionalize on environment? Detailed
1744 analysis if desired. */
1745 {
1746 int n_syms = bfd_get_symcount (abfd);
1747
1748 fprintf (stderr, "String table data for output file:\n");
1749 fprintf (stderr, " %8d symbols output\n", n_syms);
1750 fprintf (stderr, " %8d duplicate strings\n", tab->duplicates);
1751 fprintf (stderr, " %8d empty strings\n", tab->empty_strings);
1752 fprintf (stderr, " %8d unique strings output\n", count);
1753 fprintf (stderr, " %8d pointer matches\n", tab->pointer_matches);
1754 fprintf (stderr, " %8d bytes saved\n", tab->bytes_saved);
1755 fprintf (stderr, " %8d bad hash matches\n", tab->bad_hash_matches);
1756 fprintf (stderr, " %8d hash-val comparisons\n", tab->n_compares);
1757 if (n_syms)
1758 {
1759 double n_compares = tab->n_compares;
1760 double avg_compares = n_compares / n_syms;
1761 /* The second value here should usually be near one. */
1762 fprintf (stderr, "\t average %f per symbol (%f * log2 nstrings)\n",
1763 avg_compares, avg_compares / log2 (count));
1764 }
1765 }
1766 #endif
1767
1768 /* Old code:
1769 unsigned int count;
1770 generic = bfd_get_outsymbols(abfd);
1771 for (count = 0; count < bfd_get_symcount(abfd); count++)
1772 {
1773 asymbol *g = *(generic++);
1774
1775 if (g->name)
1776 {
1777 size_t length = strlen(g->name)+1;
1778 bfd_write((PTR)g->name, 1, length, abfd);
1779 }
1780 g->KEEPIT = (KEEPITTYPE) count;
1781 } */
1782 }
1783
1784 void
1785 DEFUN(NAME(aout,write_syms),(abfd),
1786 bfd *abfd)
1787 {
1788 unsigned int count ;
1789 asymbol **generic = bfd_get_outsymbols (abfd);
1790 struct stringtab_data strtab;
1791
1792 stringtab_init (&strtab);
1793
1794 for (count = 0; count < bfd_get_symcount (abfd); count++)
1795 {
1796 asymbol *g = generic[count];
1797 struct external_nlist nsp;
1798
1799 if (g->name)
1800 PUT_WORD (abfd, add_to_stringtab (abfd, g->name, &strtab),
1801 (unsigned char *) nsp.e_strx);
1802 else
1803 PUT_WORD (abfd, 0, (unsigned char *)nsp.e_strx);
1804
1805 if (bfd_asymbol_flavour(g) == abfd->xvec->flavour)
1806 {
1807 bfd_h_put_16(abfd, aout_symbol(g)->desc, nsp.e_desc);
1808 bfd_h_put_8(abfd, aout_symbol(g)->other, nsp.e_other);
1809 bfd_h_put_8(abfd, aout_symbol(g)->type, nsp.e_type);
1810 }
1811 else
1812 {
1813 bfd_h_put_16(abfd,0, nsp.e_desc);
1814 bfd_h_put_8(abfd, 0, nsp.e_other);
1815 bfd_h_put_8(abfd, 0, nsp.e_type);
1816 }
1817
1818 translate_to_native_sym_flags (&nsp, g, abfd);
1819
1820 bfd_write((PTR)&nsp,1,EXTERNAL_NLIST_SIZE, abfd);
1821
1822 /* NB: `KEEPIT' currently overlays `flags', so set this only
1823 here, at the end. */
1824 g->KEEPIT = count;
1825 }
1826
1827 emit_strtab (abfd, &strtab);
1828 }
1829
1830 \f
1831 unsigned int
1832 DEFUN(NAME(aout,get_symtab),(abfd, location),
1833 bfd *abfd AND
1834 asymbol **location)
1835 {
1836 unsigned int counter = 0;
1837 aout_symbol_type *symbase;
1838
1839 if (!NAME(aout,slurp_symbol_table)(abfd)) return 0;
1840
1841 for (symbase = obj_aout_symbols(abfd); counter++ < bfd_get_symcount (abfd);)
1842 *(location++) = (asymbol *)( symbase++);
1843 *location++ =0;
1844 return bfd_get_symcount (abfd);
1845 }
1846
1847 \f
1848 /* Standard reloc stuff */
1849 /* Output standard relocation information to a file in target byte order. */
1850
1851 void
1852 DEFUN(NAME(aout,swap_std_reloc_out),(abfd, g, natptr),
1853 bfd *abfd AND
1854 arelent *g AND
1855 struct reloc_std_external *natptr)
1856 {
1857 int r_index;
1858 asymbol *sym = *(g->sym_ptr_ptr);
1859 int r_extern;
1860 unsigned int r_length;
1861 int r_pcrel;
1862 int r_baserel, r_jmptable, r_relative;
1863 unsigned int r_addend;
1864 asection *output_section = sym->section->output_section;
1865
1866 PUT_WORD(abfd, g->address, natptr->r_address);
1867
1868 r_length = g->howto->size ; /* Size as a power of two */
1869 r_pcrel = (int) g->howto->pc_relative; /* Relative to PC? */
1870 /* r_baserel, r_jmptable, r_relative??? FIXME-soon */
1871 r_baserel = 0;
1872 r_jmptable = 0;
1873 r_relative = 0;
1874
1875 r_addend = g->addend + (*(g->sym_ptr_ptr))->section->output_section->vma;
1876
1877 /* name was clobbered by aout_write_syms to be symbol index */
1878
1879 /* If this relocation is relative to a symbol then set the
1880 r_index to the symbols index, and the r_extern bit.
1881
1882 Absolute symbols can come in in two ways, either as an offset
1883 from the abs section, or as a symbol which has an abs value.
1884 check for that here
1885 */
1886
1887
1888 if (bfd_is_com_section (output_section)
1889 || output_section == &bfd_abs_section
1890 || output_section == &bfd_und_section)
1891 {
1892 if (bfd_abs_section.symbol == sym)
1893 {
1894 /* Whoops, looked like an abs symbol, but is really an offset
1895 from the abs section */
1896 r_index = 0;
1897 r_extern = 0;
1898 }
1899 else
1900 {
1901 /* Fill in symbol */
1902 r_extern = 1;
1903 r_index = stoi((*(g->sym_ptr_ptr))->KEEPIT);
1904
1905 }
1906 }
1907 else
1908 {
1909 /* Just an ordinary section */
1910 r_extern = 0;
1911 r_index = output_section->target_index;
1912 }
1913
1914 /* now the fun stuff */
1915 if (abfd->xvec->header_byteorder_big_p != false) {
1916 natptr->r_index[0] = r_index >> 16;
1917 natptr->r_index[1] = r_index >> 8;
1918 natptr->r_index[2] = r_index;
1919 natptr->r_type[0] =
1920 (r_extern? RELOC_STD_BITS_EXTERN_BIG: 0)
1921 | (r_pcrel? RELOC_STD_BITS_PCREL_BIG: 0)
1922 | (r_baserel? RELOC_STD_BITS_BASEREL_BIG: 0)
1923 | (r_jmptable? RELOC_STD_BITS_JMPTABLE_BIG: 0)
1924 | (r_relative? RELOC_STD_BITS_RELATIVE_BIG: 0)
1925 | (r_length << RELOC_STD_BITS_LENGTH_SH_BIG);
1926 } else {
1927 natptr->r_index[2] = r_index >> 16;
1928 natptr->r_index[1] = r_index >> 8;
1929 natptr->r_index[0] = r_index;
1930 natptr->r_type[0] =
1931 (r_extern? RELOC_STD_BITS_EXTERN_LITTLE: 0)
1932 | (r_pcrel? RELOC_STD_BITS_PCREL_LITTLE: 0)
1933 | (r_baserel? RELOC_STD_BITS_BASEREL_LITTLE: 0)
1934 | (r_jmptable? RELOC_STD_BITS_JMPTABLE_LITTLE: 0)
1935 | (r_relative? RELOC_STD_BITS_RELATIVE_LITTLE: 0)
1936 | (r_length << RELOC_STD_BITS_LENGTH_SH_LITTLE);
1937 }
1938 }
1939
1940
1941 /* Extended stuff */
1942 /* Output extended relocation information to a file in target byte order. */
1943
1944 void
1945 DEFUN(NAME(aout,swap_ext_reloc_out),(abfd, g, natptr),
1946 bfd *abfd AND
1947 arelent *g AND
1948 register struct reloc_ext_external *natptr)
1949 {
1950 int r_index;
1951 int r_extern;
1952 unsigned int r_type;
1953 unsigned int r_addend;
1954 asymbol *sym = *(g->sym_ptr_ptr);
1955 asection *output_section = sym->section->output_section;
1956
1957 PUT_WORD (abfd, g->address, natptr->r_address);
1958
1959 r_type = (unsigned int) g->howto->type;
1960
1961 r_addend = g->addend + (*(g->sym_ptr_ptr))->section->output_section->vma;
1962
1963
1964 /* If this relocation is relative to a symbol then set the
1965 r_index to the symbols index, and the r_extern bit.
1966
1967 Absolute symbols can come in in two ways, either as an offset
1968 from the abs section, or as a symbol which has an abs value.
1969 check for that here
1970 */
1971
1972 if (bfd_is_com_section (output_section)
1973 || output_section == &bfd_abs_section
1974 || output_section == &bfd_und_section)
1975 {
1976 if (bfd_abs_section.symbol == sym)
1977 {
1978 /* Whoops, looked like an abs symbol, but is really an offset
1979 from the abs section */
1980 r_index = 0;
1981 r_extern = 0;
1982 }
1983 else
1984 {
1985 r_extern = 1;
1986 r_index = stoi((*(g->sym_ptr_ptr))->KEEPIT);
1987 }
1988 }
1989 else
1990 {
1991 /* Just an ordinary section */
1992 r_extern = 0;
1993 r_index = output_section->target_index;
1994 }
1995
1996
1997 /* now the fun stuff */
1998 if (abfd->xvec->header_byteorder_big_p != false) {
1999 natptr->r_index[0] = r_index >> 16;
2000 natptr->r_index[1] = r_index >> 8;
2001 natptr->r_index[2] = r_index;
2002 natptr->r_type[0] =
2003 (r_extern? RELOC_EXT_BITS_EXTERN_BIG: 0)
2004 | (r_type << RELOC_EXT_BITS_TYPE_SH_BIG);
2005 } else {
2006 natptr->r_index[2] = r_index >> 16;
2007 natptr->r_index[1] = r_index >> 8;
2008 natptr->r_index[0] = r_index;
2009 natptr->r_type[0] =
2010 (r_extern? RELOC_EXT_BITS_EXTERN_LITTLE: 0)
2011 | (r_type << RELOC_EXT_BITS_TYPE_SH_LITTLE);
2012 }
2013
2014 PUT_WORD (abfd, r_addend, natptr->r_addend);
2015 }
2016
2017 /* BFD deals internally with all things based from the section they're
2018 in. so, something in 10 bytes into a text section with a base of
2019 50 would have a symbol (.text+10) and know .text vma was 50.
2020
2021 Aout keeps all it's symbols based from zero, so the symbol would
2022 contain 60. This macro subs the base of each section from the value
2023 to give the true offset from the section */
2024
2025
2026 #define MOVE_ADDRESS(ad) \
2027 if (r_extern) { \
2028 /* undefined symbol */ \
2029 cache_ptr->sym_ptr_ptr = symbols + r_index; \
2030 cache_ptr->addend = ad; \
2031 } else { \
2032 /* defined, section relative. replace symbol with pointer to \
2033 symbol which points to section */ \
2034 switch (r_index) { \
2035 case N_TEXT: \
2036 case N_TEXT | N_EXT: \
2037 cache_ptr->sym_ptr_ptr = obj_textsec(abfd)->symbol_ptr_ptr; \
2038 cache_ptr->addend = ad - su->textsec->vma; \
2039 break; \
2040 case N_DATA: \
2041 case N_DATA | N_EXT: \
2042 cache_ptr->sym_ptr_ptr = obj_datasec(abfd)->symbol_ptr_ptr; \
2043 cache_ptr->addend = ad - su->datasec->vma; \
2044 break; \
2045 case N_BSS: \
2046 case N_BSS | N_EXT: \
2047 cache_ptr->sym_ptr_ptr = obj_bsssec(abfd)->symbol_ptr_ptr; \
2048 cache_ptr->addend = ad - su->bsssec->vma; \
2049 break; \
2050 default: \
2051 case N_ABS: \
2052 case N_ABS | N_EXT: \
2053 cache_ptr->sym_ptr_ptr = bfd_abs_section.symbol_ptr_ptr; \
2054 cache_ptr->addend = ad; \
2055 break; \
2056 } \
2057 } \
2058
2059 void
2060 DEFUN(NAME(aout,swap_ext_reloc_in), (abfd, bytes, cache_ptr, symbols),
2061 bfd *abfd AND
2062 struct reloc_ext_external *bytes AND
2063 arelent *cache_ptr AND
2064 asymbol **symbols)
2065 {
2066 int r_index;
2067 int r_extern;
2068 unsigned int r_type;
2069 struct aoutdata *su = &(abfd->tdata.aout_data->a);
2070
2071 cache_ptr->address = (GET_SWORD (abfd, bytes->r_address));
2072
2073 /* now the fun stuff */
2074 if (abfd->xvec->header_byteorder_big_p != false) {
2075 r_index = (bytes->r_index[0] << 16)
2076 | (bytes->r_index[1] << 8)
2077 | bytes->r_index[2];
2078 r_extern = (0 != (bytes->r_type[0] & RELOC_EXT_BITS_EXTERN_BIG));
2079 r_type = (bytes->r_type[0] & RELOC_EXT_BITS_TYPE_BIG)
2080 >> RELOC_EXT_BITS_TYPE_SH_BIG;
2081 } else {
2082 r_index = (bytes->r_index[2] << 16)
2083 | (bytes->r_index[1] << 8)
2084 | bytes->r_index[0];
2085 r_extern = (0 != (bytes->r_type[0] & RELOC_EXT_BITS_EXTERN_LITTLE));
2086 r_type = (bytes->r_type[0] & RELOC_EXT_BITS_TYPE_LITTLE)
2087 >> RELOC_EXT_BITS_TYPE_SH_LITTLE;
2088 }
2089
2090 cache_ptr->howto = howto_table_ext + r_type;
2091 MOVE_ADDRESS(GET_SWORD(abfd, bytes->r_addend));
2092 }
2093
2094 void
2095 DEFUN(NAME(aout,swap_std_reloc_in), (abfd, bytes, cache_ptr, symbols),
2096 bfd *abfd AND
2097 struct reloc_std_external *bytes AND
2098 arelent *cache_ptr AND
2099 asymbol **symbols)
2100 {
2101 int r_index;
2102 int r_extern;
2103 unsigned int r_length;
2104 int r_pcrel;
2105 int r_baserel, r_jmptable, r_relative;
2106 struct aoutdata *su = &(abfd->tdata.aout_data->a);
2107
2108 cache_ptr->address = (int32_type)(bfd_h_get_32 (abfd, bytes->r_address));
2109
2110 /* now the fun stuff */
2111 if (abfd->xvec->header_byteorder_big_p != false) {
2112 r_index = (bytes->r_index[0] << 16)
2113 | (bytes->r_index[1] << 8)
2114 | bytes->r_index[2];
2115 r_extern = (0 != (bytes->r_type[0] & RELOC_STD_BITS_EXTERN_BIG));
2116 r_pcrel = (0 != (bytes->r_type[0] & RELOC_STD_BITS_PCREL_BIG));
2117 r_baserel = (0 != (bytes->r_type[0] & RELOC_STD_BITS_BASEREL_BIG));
2118 r_jmptable= (0 != (bytes->r_type[0] & RELOC_STD_BITS_JMPTABLE_BIG));
2119 r_relative= (0 != (bytes->r_type[0] & RELOC_STD_BITS_RELATIVE_BIG));
2120 r_length = (bytes->r_type[0] & RELOC_STD_BITS_LENGTH_BIG)
2121 >> RELOC_STD_BITS_LENGTH_SH_BIG;
2122 } else {
2123 r_index = (bytes->r_index[2] << 16)
2124 | (bytes->r_index[1] << 8)
2125 | bytes->r_index[0];
2126 r_extern = (0 != (bytes->r_type[0] & RELOC_STD_BITS_EXTERN_LITTLE));
2127 r_pcrel = (0 != (bytes->r_type[0] & RELOC_STD_BITS_PCREL_LITTLE));
2128 r_baserel = (0 != (bytes->r_type[0] & RELOC_STD_BITS_BASEREL_LITTLE));
2129 r_jmptable= (0 != (bytes->r_type[0] & RELOC_STD_BITS_JMPTABLE_LITTLE));
2130 r_relative= (0 != (bytes->r_type[0] & RELOC_STD_BITS_RELATIVE_LITTLE));
2131 r_length = (bytes->r_type[0] & RELOC_STD_BITS_LENGTH_LITTLE)
2132 >> RELOC_STD_BITS_LENGTH_SH_LITTLE;
2133 }
2134
2135 cache_ptr->howto = howto_table_std + r_length + 4 * r_pcrel;
2136 /* FIXME-soon: Roll baserel, jmptable, relative bits into howto setting */
2137
2138 MOVE_ADDRESS(0);
2139 }
2140
2141 /* Reloc hackery */
2142
2143 boolean
2144 DEFUN(NAME(aout,slurp_reloc_table),(abfd, asect, symbols),
2145 bfd *abfd AND
2146 sec_ptr asect AND
2147 asymbol **symbols)
2148 {
2149 unsigned int count;
2150 bfd_size_type reloc_size;
2151 PTR relocs;
2152 arelent *reloc_cache;
2153 size_t each_size;
2154
2155 if (asect->relocation) return true;
2156
2157 if (asect->flags & SEC_CONSTRUCTOR) return true;
2158
2159 if (asect == obj_datasec (abfd)) {
2160 reloc_size = exec_hdr(abfd)->a_drsize;
2161 goto doit;
2162 }
2163
2164 if (asect == obj_textsec (abfd)) {
2165 reloc_size = exec_hdr(abfd)->a_trsize;
2166 goto doit;
2167 }
2168
2169 bfd_error = invalid_operation;
2170 return false;
2171
2172 doit:
2173 bfd_seek (abfd, asect->rel_filepos, SEEK_SET);
2174 each_size = obj_reloc_entry_size (abfd);
2175
2176 count = reloc_size / each_size;
2177
2178
2179 reloc_cache = (arelent *) bfd_zalloc (abfd, (size_t)(count * sizeof
2180 (arelent)));
2181 if (!reloc_cache) {
2182 nomem:
2183 bfd_error = no_memory;
2184 return false;
2185 }
2186
2187 relocs = (PTR) bfd_alloc (abfd, reloc_size);
2188 if (!relocs) {
2189 bfd_release (abfd, reloc_cache);
2190 goto nomem;
2191 }
2192
2193 if (bfd_read (relocs, 1, reloc_size, abfd) != reloc_size) {
2194 bfd_release (abfd, relocs);
2195 bfd_release (abfd, reloc_cache);
2196 bfd_error = system_call_error;
2197 return false;
2198 }
2199
2200 if (each_size == RELOC_EXT_SIZE) {
2201 register struct reloc_ext_external *rptr = (struct reloc_ext_external *) relocs;
2202 unsigned int counter = 0;
2203 arelent *cache_ptr = reloc_cache;
2204
2205 for (; counter < count; counter++, rptr++, cache_ptr++) {
2206 NAME(aout,swap_ext_reloc_in)(abfd, rptr, cache_ptr, symbols);
2207 }
2208 } else {
2209 register struct reloc_std_external *rptr = (struct reloc_std_external*) relocs;
2210 unsigned int counter = 0;
2211 arelent *cache_ptr = reloc_cache;
2212
2213 for (; counter < count; counter++, rptr++, cache_ptr++) {
2214 NAME(aout,swap_std_reloc_in)(abfd, rptr, cache_ptr, symbols);
2215 }
2216
2217 }
2218
2219 bfd_release (abfd,relocs);
2220 asect->relocation = reloc_cache;
2221 asect->reloc_count = count;
2222 return true;
2223 }
2224
2225
2226
2227 /* Write out a relocation section into an object file. */
2228
2229 boolean
2230 DEFUN(NAME(aout,squirt_out_relocs),(abfd, section),
2231 bfd *abfd AND
2232 asection *section)
2233 {
2234 arelent **generic;
2235 unsigned char *native, *natptr;
2236 size_t each_size;
2237
2238 unsigned int count = section->reloc_count;
2239 size_t natsize;
2240
2241 if (count == 0) return true;
2242
2243 each_size = obj_reloc_entry_size (abfd);
2244 natsize = each_size * count;
2245 native = (unsigned char *) bfd_zalloc (abfd, natsize);
2246 if (!native) {
2247 bfd_error = no_memory;
2248 return false;
2249 }
2250
2251 generic = section->orelocation;
2252
2253 if (each_size == RELOC_EXT_SIZE)
2254 {
2255 for (natptr = native;
2256 count != 0;
2257 --count, natptr += each_size, ++generic)
2258 NAME(aout,swap_ext_reloc_out) (abfd, *generic, (struct reloc_ext_external *)natptr);
2259 }
2260 else
2261 {
2262 for (natptr = native;
2263 count != 0;
2264 --count, natptr += each_size, ++generic)
2265 NAME(aout,swap_std_reloc_out)(abfd, *generic, (struct reloc_std_external *)natptr);
2266 }
2267
2268 if ( bfd_write ((PTR) native, 1, natsize, abfd) != natsize) {
2269 bfd_release(abfd, native);
2270 return false;
2271 }
2272 bfd_release (abfd, native);
2273
2274 return true;
2275 }
2276
2277 /* This is stupid. This function should be a boolean predicate */
2278 unsigned int
2279 DEFUN(NAME(aout,canonicalize_reloc),(abfd, section, relptr, symbols),
2280 bfd *abfd AND
2281 sec_ptr section AND
2282 arelent **relptr AND
2283 asymbol **symbols)
2284 {
2285 arelent *tblptr = section->relocation;
2286 unsigned int count;
2287
2288 if (!(tblptr || NAME(aout,slurp_reloc_table)(abfd, section, symbols)))
2289 return 0;
2290
2291 if (section->flags & SEC_CONSTRUCTOR) {
2292 arelent_chain *chain = section->constructor_chain;
2293 for (count = 0; count < section->reloc_count; count ++) {
2294 *relptr ++ = &chain->relent;
2295 chain = chain->next;
2296 }
2297 }
2298 else {
2299 tblptr = section->relocation;
2300 if (!tblptr) return 0;
2301
2302 for (count = 0; count++ < section->reloc_count;)
2303 {
2304 *relptr++ = tblptr++;
2305 }
2306 }
2307 *relptr = 0;
2308
2309 return section->reloc_count;
2310 }
2311
2312 unsigned int
2313 DEFUN(NAME(aout,get_reloc_upper_bound),(abfd, asect),
2314 bfd *abfd AND
2315 sec_ptr asect)
2316 {
2317 if (bfd_get_format (abfd) != bfd_object) {
2318 bfd_error = invalid_operation;
2319 return 0;
2320 }
2321 if (asect->flags & SEC_CONSTRUCTOR) {
2322 return (sizeof (arelent *) * (asect->reloc_count+1));
2323 }
2324
2325
2326 if (asect == obj_datasec (abfd))
2327 return (sizeof (arelent *) *
2328 ((exec_hdr(abfd)->a_drsize / obj_reloc_entry_size (abfd))
2329 +1));
2330
2331 if (asect == obj_textsec (abfd))
2332 return (sizeof (arelent *) *
2333 ((exec_hdr(abfd)->a_trsize / obj_reloc_entry_size (abfd))
2334 +1));
2335
2336 bfd_error = invalid_operation;
2337 return 0;
2338 }
2339
2340 \f
2341 unsigned int
2342 DEFUN(NAME(aout,get_symtab_upper_bound),(abfd),
2343 bfd *abfd)
2344 {
2345 if (!NAME(aout,slurp_symbol_table)(abfd)) return 0;
2346
2347 return (bfd_get_symcount (abfd)+1) * (sizeof (aout_symbol_type *));
2348 }
2349 alent *
2350 DEFUN(NAME(aout,get_lineno),(ignore_abfd, ignore_symbol),
2351 bfd *ignore_abfd AND
2352 asymbol *ignore_symbol)
2353 {
2354 return (alent *)NULL;
2355 }
2356
2357
2358 void
2359 DEFUN(NAME(aout,print_symbol),(ignore_abfd, afile, symbol, how),
2360 bfd *ignore_abfd AND
2361 PTR afile AND
2362 asymbol *symbol AND
2363 bfd_print_symbol_type how)
2364 {
2365 FILE *file = (FILE *)afile;
2366
2367 switch (how) {
2368 case bfd_print_symbol_name:
2369 if (symbol->name)
2370 fprintf(file,"%s", symbol->name);
2371 break;
2372 case bfd_print_symbol_more:
2373 fprintf(file,"%4x %2x %2x",(unsigned)(aout_symbol(symbol)->desc & 0xffff),
2374 (unsigned)(aout_symbol(symbol)->other & 0xff),
2375 (unsigned)(aout_symbol(symbol)->type));
2376 break;
2377 case bfd_print_symbol_all:
2378 {
2379 CONST char *section_name = symbol->section->name;
2380
2381
2382 bfd_print_symbol_vandf((PTR)file,symbol);
2383
2384 fprintf(file," %-5s %04x %02x %02x",
2385 section_name,
2386 (unsigned)(aout_symbol(symbol)->desc & 0xffff),
2387 (unsigned)(aout_symbol(symbol)->other & 0xff),
2388 (unsigned)(aout_symbol(symbol)->type & 0xff));
2389 if (symbol->name)
2390 fprintf(file," %s", symbol->name);
2391 }
2392 break;
2393 case bfd_print_symbol_nm:
2394 {
2395 int section_code = bfd_decode_symclass (symbol);
2396
2397 if (section_code == 'U')
2398 fprintf(file, " ");
2399 else
2400 fprintf_vma(file, symbol->value+symbol->section->vma);
2401 if (section_code == '?')
2402 {
2403 int type_code = aout_symbol(symbol)->type & 0xff;
2404 CONST char *stab_name = aout_stab_name(type_code);
2405 char buf[10];
2406 if (stab_name == NULL)
2407 {
2408 sprintf(buf, "(%d)", type_code);
2409 stab_name = buf;
2410 }
2411 fprintf(file," - %02x %04x %5s",
2412 (unsigned)(aout_symbol(symbol)->other & 0xff),
2413 (unsigned)(aout_symbol(symbol)->desc & 0xffff),
2414 stab_name);
2415 }
2416 else
2417 fprintf(file," %c", section_code);
2418 if (symbol->name)
2419 fprintf(file," %s", symbol->name);
2420 }
2421 break;
2422 }
2423 }
2424
2425 /*
2426 provided a BFD, a section and an offset into the section, calculate
2427 and return the name of the source file and the line nearest to the
2428 wanted location.
2429 */
2430
2431 boolean
2432 DEFUN(NAME(aout,find_nearest_line),(abfd,
2433 section,
2434 symbols,
2435 offset,
2436 filename_ptr,
2437 functionname_ptr,
2438 line_ptr),
2439 bfd *abfd AND
2440 asection *section AND
2441 asymbol **symbols AND
2442 bfd_vma offset AND
2443 CONST char **filename_ptr AND
2444 CONST char **functionname_ptr AND
2445 unsigned int *line_ptr)
2446 {
2447 /* Run down the file looking for the filename, function and linenumber */
2448 asymbol **p;
2449 static char buffer[100];
2450 static char filename_buffer[200];
2451 CONST char *directory_name = NULL;
2452 CONST char *main_file_name = NULL;
2453 CONST char *current_file_name = NULL;
2454 CONST char *line_file_name = NULL; /* Value of current_file_name at line number. */
2455 bfd_vma high_line_vma = ~0;
2456 bfd_vma low_func_vma = 0;
2457 asymbol *func = 0;
2458 *filename_ptr = abfd->filename;
2459 *functionname_ptr = 0;
2460 *line_ptr = 0;
2461 if (symbols != (asymbol **)NULL) {
2462 for (p = symbols; *p; p++) {
2463 aout_symbol_type *q = (aout_symbol_type *)(*p);
2464 next:
2465 switch (q->type){
2466 case N_SO:
2467 main_file_name = current_file_name = q->symbol.name;
2468 /* Look ahead to next symbol to check if that too is an N_SO. */
2469 p++;
2470 if (*p == NULL)
2471 break;
2472 q = (aout_symbol_type *)(*p);
2473 if (q->type != (int)N_SO)
2474 goto next;
2475
2476 /* Found a second N_SO First is directory; second is filename. */
2477 directory_name = current_file_name;
2478 main_file_name = current_file_name = q->symbol.name;
2479 if (obj_textsec(abfd) != section)
2480 goto done;
2481 break;
2482 case N_SOL:
2483 current_file_name = q->symbol.name;
2484 break;
2485
2486 case N_SLINE:
2487
2488 case N_DSLINE:
2489 case N_BSLINE:
2490 /* We'll keep this if it resolves nearer than the one we have already */
2491 if (q->symbol.value >= offset &&
2492 q->symbol.value < high_line_vma) {
2493 *line_ptr = q->desc;
2494 high_line_vma = q->symbol.value;
2495 line_file_name = current_file_name;
2496 }
2497 break;
2498 case N_FUN:
2499 {
2500 /* We'll keep this if it is nearer than the one we have already */
2501 if (q->symbol.value >= low_func_vma &&
2502 q->symbol.value <= offset) {
2503 low_func_vma = q->symbol.value;
2504 func = (asymbol *)q;
2505 }
2506 if (*line_ptr && func) {
2507 CONST char *function = func->name;
2508 char *p;
2509 strncpy(buffer, function, sizeof(buffer)-1);
2510 buffer[sizeof(buffer)-1] = 0;
2511 /* Have to remove : stuff */
2512 p = strchr(buffer,':');
2513 if (p != NULL) { *p = '\0'; }
2514 *functionname_ptr = buffer;
2515 goto done;
2516
2517 }
2518 }
2519 break;
2520 }
2521 }
2522 }
2523
2524 done:
2525 if (*line_ptr)
2526 main_file_name = line_file_name;
2527 if (main_file_name) {
2528 if (main_file_name[0] == '/' || directory_name == NULL)
2529 *filename_ptr = main_file_name;
2530 else {
2531 sprintf(filename_buffer, "%.140s%.50s",
2532 directory_name, main_file_name);
2533 *filename_ptr = filename_buffer;
2534 }
2535 }
2536 return true;
2537
2538 }
2539
2540 int
2541 DEFUN(NAME(aout,sizeof_headers),(abfd, execable),
2542 bfd *abfd AND
2543 boolean execable)
2544 {
2545 return adata(abfd).exec_bytes_size;
2546 }
This page took 0.105 seconds and 4 git commands to generate.