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.
5 This file is part of BFD, the Binary File Descriptor library.
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.
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.
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. */
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
33 The support is split into a basic support file @file{aoutx.h}
34 and other files which derive functions from the base. One
35 derivation file is @file{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
40 This information is further split out into more specific files
41 for each machine, including @file{sunos.c} for sun3 and sun4,
42 @file{newsos3.c} for the Sony NEWS, and @file{demo64.c} for a
43 demonstration of a 64 bit a.out format.
45 The base file @file{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 @file{aout32.c} and @file{aout64.c} to form the names
49 <<aout_32_swap_exec_header_in>>, <<aout_64_swap_exec_header_in>>, etc.
51 As an example, this is what goes on to make the back end for a
52 sun4, from @file{aout32.c}:
54 | #define ARCH_SIZE 32
60 | aout_32_canonicalize_reloc
61 | aout_32_find_nearest_line
63 | aout_32_get_reloc_upper_bound
69 | #define TARGET_NAME "a.out-sunos-big"
70 | #define VECNAME sunos_big_vec
73 requires all the names from @file{aout32.c}, and produces the jump vector
77 The file @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
87 When porting it to run on a new system, you must supply:
91 | HOST_MACHINE_ARCH (optional)
92 | HOST_MACHINE_MACHINE (optional)
93 | HOST_TEXT_START_ADDR
96 in the file @file{../include/sys/h-@var{XXX}.h} (for your host). These
97 values, plus the structures and macros defined in @file{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 @file{host-aout.c}, specify:
102 | TDEFAULTS = -DDEFAULT_VECTOR=host_aout_big_vec
103 | TDEPFILES= host-aout.o trad-core.o
105 in the @file{config/@var{XXX}.mt} file, and modify @file{configure.in}
107 @file{@var{XXX}.mt} file (by setting "<<bfd_target=XXX>>") when your
108 configuration is selected.
113 * Any BFD with D_PAGED set is ZMAGIC, and vice versa.
114 Doesn't matter what the setting of WP_TEXT is on output, but it'll
116 * Any BFD with D_PAGED clear and WP_TEXT set is NMAGIC.
117 * Any BFD with both flags clear is OMAGIC.
118 (Just want to make these explicit, so the conditions tested in this
119 file make sense if you're more familiar with a.out than with BFD.) */
122 #define KEEPITTYPE int
125 #include <string.h> /* For strchr and friends */
128 #include <ansidecl.h>
133 #include "aout/aout64.h"
134 #include "aout/stab_gnu.h"
137 static boolean translate_symbol_table
PARAMS ((bfd
*, aout_symbol_type
*,
138 struct external_nlist
*,
139 bfd_size_type
, char *,
148 The file @file{aoutx.h} provides for both the @emph{standard}
149 and @emph{extended} forms of a.out relocation records.
151 The standard records contain only an
152 address, a symbol index, and a type field. The extended records
153 (used on 29ks and sparcs) also have a full integer for an
157 #define CTOR_TABLE_RELOC_IDX 2
159 #define howto_table_ext NAME(aout,ext_howto_table)
160 #define howto_table_std NAME(aout,std_howto_table)
162 reloc_howto_type howto_table_ext
[] =
164 /* type rs size bsz pcrel bitpos ovrf sf name part_inpl readmask setmask pcdone */
165 HOWTO(RELOC_8
, 0, 0, 8, false, 0, complain_overflow_bitfield
,0,"8", false, 0,0x000000ff, false),
166 HOWTO(RELOC_16
, 0, 1, 16, false, 0, complain_overflow_bitfield
,0,"16", false, 0,0x0000ffff, false),
167 HOWTO(RELOC_32
, 0, 2, 32, false, 0, complain_overflow_bitfield
,0,"32", false, 0,0xffffffff, false),
168 HOWTO(RELOC_DISP8
, 0, 0, 8, true, 0, complain_overflow_signed
,0,"DISP8", false, 0,0x000000ff, false),
169 HOWTO(RELOC_DISP16
, 0, 1, 16, true, 0, complain_overflow_signed
,0,"DISP16", false, 0,0x0000ffff, false),
170 HOWTO(RELOC_DISP32
, 0, 2, 32, true, 0, complain_overflow_signed
,0,"DISP32", false, 0,0xffffffff, false),
171 HOWTO(RELOC_WDISP30
,2, 2, 30, true, 0, complain_overflow_signed
,0,"WDISP30", false, 0,0x3fffffff, false),
172 HOWTO(RELOC_WDISP22
,2, 2, 22, true, 0, complain_overflow_signed
,0,"WDISP22", false, 0,0x003fffff, false),
173 HOWTO(RELOC_HI22
, 10, 2, 22, false, 0, complain_overflow_bitfield
,0,"HI22", false, 0,0x003fffff, false),
174 HOWTO(RELOC_22
, 0, 2, 22, false, 0, complain_overflow_bitfield
,0,"22", false, 0,0x003fffff, false),
175 HOWTO(RELOC_13
, 0, 2, 13, false, 0, complain_overflow_bitfield
,0,"13", false, 0,0x00001fff, false),
176 HOWTO(RELOC_LO10
, 0, 2, 10, false, 0, complain_overflow_dont
,0,"LO10", false, 0,0x000003ff, false),
177 HOWTO(RELOC_SFA_BASE
,0, 2, 32, false, 0, complain_overflow_bitfield
,0,"SFA_BASE", false, 0,0xffffffff, false),
178 HOWTO(RELOC_SFA_OFF13
,0,2, 32, false, 0, complain_overflow_bitfield
,0,"SFA_OFF13",false, 0,0xffffffff, false),
179 HOWTO(RELOC_BASE10
, 0, 2, 16, false, 0, complain_overflow_bitfield
,0,"BASE10", false, 0,0x0000ffff, false),
180 HOWTO(RELOC_BASE13
, 0, 2, 13, false, 0, complain_overflow_bitfield
,0,"BASE13", false, 0,0x00001fff, false),
181 HOWTO(RELOC_BASE22
, 0, 2, 0, false, 0, complain_overflow_bitfield
,0,"BASE22", false, 0,0x00000000, false),
182 HOWTO(RELOC_PC10
, 0, 2, 10, false, 0, complain_overflow_bitfield
,0,"PC10", false, 0,0x000003ff, false),
183 HOWTO(RELOC_PC22
, 0, 2, 22, false, 0, complain_overflow_bitfield
,0,"PC22", false, 0,0x003fffff, false),
184 HOWTO(RELOC_JMP_TBL
,0, 2, 32, false, 0, complain_overflow_bitfield
,0,"JMP_TBL", false, 0,0xffffffff, false),
185 HOWTO(RELOC_SEGOFF16
,0, 2, 0, false, 0, complain_overflow_bitfield
,0,"SEGOFF16", false, 0,0x00000000, false),
186 HOWTO(RELOC_GLOB_DAT
,0, 2, 0, false, 0, complain_overflow_bitfield
,0,"GLOB_DAT", false, 0,0x00000000, false),
187 HOWTO(RELOC_JMP_SLOT
,0, 2, 0, false, 0, complain_overflow_bitfield
,0,"JMP_SLOT", false, 0,0x00000000, false),
188 HOWTO(RELOC_RELATIVE
,0, 2, 0, false, 0, complain_overflow_bitfield
,0,"RELATIVE", false, 0,0x00000000, false),
191 /* Convert standard reloc records to "arelent" format (incl byte swap). */
193 reloc_howto_type howto_table_std
[] = {
194 /* type rs size bsz pcrel bitpos ovrf sf name part_inpl readmask setmask pcdone */
195 HOWTO( 0, 0, 0, 8, false, 0, complain_overflow_bitfield
,0,"8", true, 0x000000ff,0x000000ff, false),
196 HOWTO( 1, 0, 1, 16, false, 0, complain_overflow_bitfield
,0,"16", true, 0x0000ffff,0x0000ffff, false),
197 HOWTO( 2, 0, 2, 32, false, 0, complain_overflow_bitfield
,0,"32", true, 0xffffffff,0xffffffff, false),
198 HOWTO( 3, 0, 4, 64, false, 0, complain_overflow_bitfield
,0,"64", true, 0xdeaddead,0xdeaddead, false),
199 HOWTO( 4, 0, 0, 8, true, 0, complain_overflow_signed
, 0,"DISP8", true, 0x000000ff,0x000000ff, false),
200 HOWTO( 5, 0, 1, 16, true, 0, complain_overflow_signed
, 0,"DISP16", true, 0x0000ffff,0x0000ffff, false),
201 HOWTO( 6, 0, 2, 32, true, 0, complain_overflow_signed
, 0,"DISP32", true, 0xffffffff,0xffffffff, false),
202 HOWTO( 7, 0, 4, 64, true, 0, complain_overflow_signed
, 0,"DISP64", true, 0xfeedface,0xfeedface, false),
204 HOWTO( 9, 0, 1, 16, false, 0, complain_overflow_bitfield
,0,"BASE16", false,0xffffffff,0xffffffff, false),
205 HOWTO(10, 0, 2, 32, false, 0, complain_overflow_bitfield
,0,"BASE32", false,0xffffffff,0xffffffff, false),
208 #define TABLE_SIZE(TABLE) (sizeof(TABLE)/sizeof(TABLE[0]))
210 CONST
struct reloc_howto_struct
*
211 DEFUN(NAME(aout
,reloc_type_lookup
),(abfd
,code
),
213 bfd_reloc_code_real_type code
)
215 #define EXT(i,j) case i: return &howto_table_ext[j]
216 #define STD(i,j) case i: return &howto_table_std[j]
217 int ext
= obj_reloc_entry_size (abfd
) == RELOC_EXT_SIZE
;
218 if (code
== BFD_RELOC_CTOR
)
219 switch (bfd_get_arch_info (abfd
)->bits_per_address
)
228 EXT (BFD_RELOC_32
, 2);
229 EXT (BFD_RELOC_HI22
, 8);
230 EXT (BFD_RELOC_LO10
, 11);
231 EXT (BFD_RELOC_32_PCREL_S2
, 6);
232 EXT (BFD_RELOC_SPARC_WDISP22
, 7);
233 default: return (CONST
struct reloc_howto_struct
*) 0;
239 STD (BFD_RELOC_16
, 1);
240 STD (BFD_RELOC_32
, 2);
241 STD (BFD_RELOC_8_PCREL
, 4);
242 STD (BFD_RELOC_16_PCREL
, 5);
243 STD (BFD_RELOC_32_PCREL
, 6);
244 STD (BFD_RELOC_16_BASEREL
, 9);
245 STD (BFD_RELOC_32_BASEREL
, 10);
246 default: return (CONST
struct reloc_howto_struct
*) 0;
252 Internal entry points
255 @file{aoutx.h} exports several routines for accessing the
256 contents of an a.out file, which are gathered and exported in
257 turn by various format specific files (eg sunos.c).
263 aout_@var{size}_swap_exec_header_in
266 void aout_@var{size}_swap_exec_header_in,
268 struct external_exec *raw_bytes,
269 struct internal_exec *execp);
272 Swap the information in an executable header @var{raw_bytes} taken
273 from a raw byte stream memory image into the internal exec header
274 structure @var{execp}.
277 #ifndef NAME_swap_exec_header_in
279 DEFUN(NAME(aout
,swap_exec_header_in
),(abfd
, raw_bytes
, execp
),
281 struct external_exec
*raw_bytes AND
282 struct internal_exec
*execp
)
284 struct external_exec
*bytes
= (struct external_exec
*)raw_bytes
;
286 /* The internal_exec structure has some fields that are unused in this
287 configuration (IE for i960), so ensure that all such uninitialized
288 fields are zero'd out. There are places where two of these structs
289 are memcmp'd, and thus the contents do matter. */
290 memset (execp
, 0, sizeof (struct internal_exec
));
291 /* Now fill in fields in the execp, from the bytes in the raw data. */
292 execp
->a_info
= bfd_h_get_32 (abfd
, bytes
->e_info
);
293 execp
->a_text
= GET_WORD (abfd
, bytes
->e_text
);
294 execp
->a_data
= GET_WORD (abfd
, bytes
->e_data
);
295 execp
->a_bss
= GET_WORD (abfd
, bytes
->e_bss
);
296 execp
->a_syms
= GET_WORD (abfd
, bytes
->e_syms
);
297 execp
->a_entry
= GET_WORD (abfd
, bytes
->e_entry
);
298 execp
->a_trsize
= GET_WORD (abfd
, bytes
->e_trsize
);
299 execp
->a_drsize
= GET_WORD (abfd
, bytes
->e_drsize
);
301 #define NAME_swap_exec_header_in NAME(aout,swap_exec_header_in)
306 aout_@var{size}_swap_exec_header_out
309 void aout_@var{size}_swap_exec_header_out
311 struct internal_exec *execp,
312 struct external_exec *raw_bytes);
315 Swap the information in an internal exec header structure
316 @var{execp} into the buffer @var{raw_bytes} ready for writing to disk.
319 DEFUN(NAME(aout
,swap_exec_header_out
),(abfd
, execp
, raw_bytes
),
321 struct internal_exec
*execp AND
322 struct external_exec
*raw_bytes
)
324 struct external_exec
*bytes
= (struct external_exec
*)raw_bytes
;
326 /* Now fill in fields in the raw data, from the fields in the exec struct. */
327 bfd_h_put_32 (abfd
, execp
->a_info
, bytes
->e_info
);
328 PUT_WORD (abfd
, execp
->a_text
, bytes
->e_text
);
329 PUT_WORD (abfd
, execp
->a_data
, bytes
->e_data
);
330 PUT_WORD (abfd
, execp
->a_bss
, bytes
->e_bss
);
331 PUT_WORD (abfd
, execp
->a_syms
, bytes
->e_syms
);
332 PUT_WORD (abfd
, execp
->a_entry
, bytes
->e_entry
);
333 PUT_WORD (abfd
, execp
->a_trsize
, bytes
->e_trsize
);
334 PUT_WORD (abfd
, execp
->a_drsize
, bytes
->e_drsize
);
341 aout_@var{size}_some_aout_object_p
344 bfd_target *aout_@var{size}_some_aout_object_p
346 bfd_target *(*callback_to_real_object_p)());
349 Some a.out variant thinks that the file open in @var{abfd}
350 checking is an a.out file. Do some more checking, and set up
351 for access if it really is. Call back to the calling
352 environment's "finish up" function just before returning, to
353 handle any last-minute setup.
357 DEFUN(NAME(aout
,some_aout_object_p
),(abfd
, execp
, callback_to_real_object_p
),
359 struct internal_exec
*execp AND
360 bfd_target
*(*callback_to_real_object_p
) PARAMS ((bfd
*)))
362 struct aout_data_struct
*rawptr
, *oldrawptr
;
365 rawptr
= (struct aout_data_struct
*) bfd_zalloc (abfd
, sizeof (struct aout_data_struct
));
366 if (rawptr
== NULL
) {
367 bfd_error
= no_memory
;
371 oldrawptr
= abfd
->tdata
.aout_data
;
372 abfd
->tdata
.aout_data
= rawptr
;
374 /* Copy the contents of the old tdata struct.
375 In particular, we want the subformat, since for hpux it was set in
376 hp300hpux.c:swap_exec_header_in and will be used in
377 hp300hpux.c:callback. */
378 if (oldrawptr
!= NULL
)
379 *abfd
->tdata
.aout_data
= *oldrawptr
;
381 abfd
->tdata
.aout_data
->a
.hdr
= &rawptr
->e
;
382 *(abfd
->tdata
.aout_data
->a
.hdr
) = *execp
; /* Copy in the internal_exec struct */
383 execp
= abfd
->tdata
.aout_data
->a
.hdr
;
385 /* Set the file flags */
386 abfd
->flags
= NO_FLAGS
;
387 if (execp
->a_drsize
|| execp
->a_trsize
)
388 abfd
->flags
|= HAS_RELOC
;
389 /* Setting of EXEC_P has been deferred to the bottom of this function */
391 abfd
->flags
|= HAS_LINENO
| HAS_DEBUG
| HAS_SYMS
| HAS_LOCALS
;
392 if (N_DYNAMIC(*execp
))
393 abfd
->flags
|= DYNAMIC
;
395 if (N_MAGIC (*execp
) == ZMAGIC
)
397 abfd
->flags
|= D_PAGED
|WP_TEXT
;
398 adata(abfd
).magic
= z_magic
;
400 else if (N_MAGIC (*execp
) == NMAGIC
)
402 abfd
->flags
|= WP_TEXT
;
403 adata(abfd
).magic
= n_magic
;
406 adata(abfd
).magic
= o_magic
;
408 bfd_get_start_address (abfd
) = execp
->a_entry
;
410 obj_aout_symbols (abfd
) = (aout_symbol_type
*)NULL
;
411 bfd_get_symcount (abfd
) = execp
->a_syms
/ sizeof (struct external_nlist
);
413 /* The default relocation entry size is that of traditional V7 Unix. */
414 obj_reloc_entry_size (abfd
) = RELOC_STD_SIZE
;
416 /* The default symbol entry size is that of traditional Unix. */
417 obj_symbol_entry_size (abfd
) = EXTERNAL_NLIST_SIZE
;
419 obj_aout_external_syms (abfd
) = NULL
;
420 obj_aout_external_strings (abfd
) = NULL
;
421 obj_aout_sym_hashes (abfd
) = NULL
;
423 /* Create the sections. This is raunchy, but bfd_close wants to reclaim
426 obj_textsec (abfd
) = bfd_make_section_old_way (abfd
, ".text");
427 obj_datasec (abfd
) = bfd_make_section_old_way (abfd
, ".data");
428 obj_bsssec (abfd
) = bfd_make_section_old_way (abfd
, ".bss");
431 (void)bfd_make_section (abfd
, ".text");
432 (void)bfd_make_section (abfd
, ".data");
433 (void)bfd_make_section (abfd
, ".bss");
436 obj_datasec (abfd
)->_raw_size
= execp
->a_data
;
437 obj_bsssec (abfd
)->_raw_size
= execp
->a_bss
;
439 /* If this object is dynamically linked, we assume that both
440 sections have relocs. This does no real harm, even though it may
442 obj_textsec (abfd
)->flags
=
443 (execp
->a_trsize
!= 0 || (abfd
->flags
& DYNAMIC
) != 0
444 ? (SEC_ALLOC
| SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
| SEC_RELOC
)
445 : (SEC_ALLOC
| SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
));
446 obj_datasec (abfd
)->flags
=
447 (execp
->a_drsize
!= 0 || (abfd
->flags
& DYNAMIC
) != 0
448 ? (SEC_ALLOC
| SEC_LOAD
| SEC_DATA
| SEC_HAS_CONTENTS
| SEC_RELOC
)
449 : (SEC_ALLOC
| SEC_LOAD
| SEC_DATA
| SEC_HAS_CONTENTS
));
450 obj_bsssec (abfd
)->flags
= SEC_ALLOC
;
452 #ifdef THIS_IS_ONLY_DOCUMENTATION
453 /* The common code can't fill in these things because they depend
454 on either the start address of the text segment, the rounding
455 up of virtual addersses between segments, or the starting file
456 position of the text segment -- all of which varies among different
457 versions of a.out. */
459 /* Call back to the format-dependent code to fill in the rest of the
460 fields and do any further cleanup. Things that should be filled
461 in by the callback: */
463 struct exec
*execp
= exec_hdr (abfd
);
465 obj_textsec (abfd
)->size
= N_TXTSIZE(*execp
);
466 obj_textsec (abfd
)->raw_size
= N_TXTSIZE(*execp
);
467 /* data and bss are already filled in since they're so standard */
469 /* The virtual memory addresses of the sections */
470 obj_textsec (abfd
)->vma
= N_TXTADDR(*execp
);
471 obj_datasec (abfd
)->vma
= N_DATADDR(*execp
);
472 obj_bsssec (abfd
)->vma
= N_BSSADDR(*execp
);
474 /* The file offsets of the sections */
475 obj_textsec (abfd
)->filepos
= N_TXTOFF(*execp
);
476 obj_datasec (abfd
)->filepos
= N_DATOFF(*execp
);
478 /* The file offsets of the relocation info */
479 obj_textsec (abfd
)->rel_filepos
= N_TRELOFF(*execp
);
480 obj_datasec (abfd
)->rel_filepos
= N_DRELOFF(*execp
);
482 /* The file offsets of the string table and symbol table. */
483 obj_str_filepos (abfd
) = N_STROFF (*execp
);
484 obj_sym_filepos (abfd
) = N_SYMOFF (*execp
);
486 /* Determine the architecture and machine type of the object file. */
487 switch (N_MACHTYPE (*exec_hdr (abfd
))) {
489 abfd
->obj_arch
= bfd_arch_obscure
;
493 adata(abfd
)->page_size
= PAGE_SIZE
;
494 adata(abfd
)->segment_size
= SEGMENT_SIZE
;
495 adata(abfd
)->exec_bytes_size
= EXEC_BYTES_SIZE
;
499 /* The architecture is encoded in various ways in various a.out variants,
500 or is not encoded at all in some of them. The relocation size depends
501 on the architecture and the a.out variant. Finally, the return value
502 is the bfd_target vector in use. If an error occurs, return zero and
503 set bfd_error to the appropriate error code.
505 Formats such as b.out, which have additional fields in the a.out
506 header, should cope with them in this callback as well. */
507 #endif /* DOCUMENTATION */
509 result
= (*callback_to_real_object_p
)(abfd
);
511 /* Now that the segment addresses have been worked out, take a better
512 guess at whether the file is executable. If the entry point
513 is within the text segment, assume it is. (This makes files
514 executable even if their entry point address is 0, as long as
515 their text starts at zero.)
517 At some point we should probably break down and stat the file and
518 declare it executable if (one of) its 'x' bits are on... */
519 if ((execp
->a_entry
>= obj_textsec(abfd
)->vma
) &&
520 (execp
->a_entry
< obj_textsec(abfd
)->vma
+ obj_textsec(abfd
)->_raw_size
))
521 abfd
->flags
|= EXEC_P
;
524 #if 0 /* These should be set correctly anyways. */
525 abfd
->sections
= obj_textsec (abfd
);
526 obj_textsec (abfd
)->next
= obj_datasec (abfd
);
527 obj_datasec (abfd
)->next
= obj_bsssec (abfd
);
533 abfd
->tdata
.aout_data
= oldrawptr
;
540 aout_@var{size}_mkobject
543 boolean aout_@var{size}_mkobject, (bfd *abfd);
546 Initialize BFD @var{abfd} for use with a.out files.
550 DEFUN(NAME(aout
,mkobject
),(abfd
),
553 struct aout_data_struct
*rawptr
;
555 bfd_error
= system_call_error
;
557 /* Use an intermediate variable for clarity */
558 rawptr
= (struct aout_data_struct
*)bfd_zalloc (abfd
, sizeof (struct aout_data_struct
));
560 if (rawptr
== NULL
) {
561 bfd_error
= no_memory
;
565 abfd
->tdata
.aout_data
= rawptr
;
566 exec_hdr (abfd
) = &(rawptr
->e
);
568 /* For simplicity's sake we just make all the sections right here. */
570 obj_textsec (abfd
) = (asection
*)NULL
;
571 obj_datasec (abfd
) = (asection
*)NULL
;
572 obj_bsssec (abfd
) = (asection
*)NULL
;
573 bfd_make_section (abfd
, ".text");
574 bfd_make_section (abfd
, ".data");
575 bfd_make_section (abfd
, ".bss");
576 bfd_make_section (abfd
, BFD_ABS_SECTION_NAME
);
577 bfd_make_section (abfd
, BFD_UND_SECTION_NAME
);
578 bfd_make_section (abfd
, BFD_COM_SECTION_NAME
);
586 aout_@var{size}_machine_type
589 enum machine_type aout_@var{size}_machine_type
590 (enum bfd_architecture arch,
591 unsigned long machine));
594 Keep track of machine architecture and machine type for
595 a.out's. Return the <<machine_type>> for a particular
596 architecture and machine, or <<M_UNKNOWN>> if that exact architecture
597 and machine can't be represented in a.out format.
599 If the architecture is understood, machine type 0 (default)
600 is always understood.
604 DEFUN(NAME(aout
,machine_type
),(arch
, machine
),
605 enum bfd_architecture arch AND
606 unsigned long machine
)
608 enum machine_type arch_flags
;
610 arch_flags
= M_UNKNOWN
;
614 if (machine
== 0) arch_flags
= M_SPARC
;
619 case 0: arch_flags
= M_68010
; break;
620 case 68000: arch_flags
= M_UNKNOWN
; break;
621 case 68010: arch_flags
= M_68010
; break;
622 case 68020: arch_flags
= M_68020
; break;
623 default: arch_flags
= M_UNKNOWN
; break;
628 if (machine
== 0) arch_flags
= M_386
;
632 if (machine
== 0) arch_flags
= M_29K
;
639 case 3000: arch_flags
= M_MIPS1
; break;
642 case 6000: arch_flags
= M_MIPS2
; break;
643 default: arch_flags
= M_UNKNOWN
; break;
648 arch_flags
= M_UNKNOWN
;
656 aout_@var{size}_set_arch_mach
659 boolean aout_@var{size}_set_arch_mach,
661 enum bfd_architecture arch,
662 unsigned long machine));
665 Set the architecture and the machine of the BFD @var{abfd} to the
666 values @var{arch} and @var{machine}. Verify that @var{abfd}'s format
667 can support the architecture required.
671 DEFUN(NAME(aout
,set_arch_mach
),(abfd
, arch
, machine
),
673 enum bfd_architecture arch AND
674 unsigned long machine
)
676 if (! bfd_default_set_arch_mach (abfd
, arch
, machine
))
679 if (arch
!= bfd_arch_unknown
&&
680 NAME(aout
,machine_type
) (arch
, machine
) == M_UNKNOWN
)
681 return false; /* We can't represent this type */
683 /* Determine the size of a relocation entry */
688 obj_reloc_entry_size (abfd
) = RELOC_EXT_SIZE
;
691 obj_reloc_entry_size (abfd
) = RELOC_STD_SIZE
;
695 return (*aout_backend_info(abfd
)->set_sizes
) (abfd
);
699 adjust_o_magic (abfd
, execp
)
701 struct internal_exec
*execp
;
703 file_ptr pos
= adata (abfd
).exec_bytes_size
;
708 obj_textsec(abfd
)->filepos
= pos
;
709 pos
+= obj_textsec(abfd
)->_raw_size
;
710 vma
+= obj_textsec(abfd
)->_raw_size
;
713 if (!obj_datasec(abfd
)->user_set_vma
)
715 #if 0 /* ?? Does alignment in the file image really matter? */
716 pad
= align_power (vma
, obj_datasec(abfd
)->alignment_power
) - vma
;
718 obj_textsec(abfd
)->_raw_size
+= pad
;
721 obj_datasec(abfd
)->vma
= vma
;
723 obj_datasec(abfd
)->filepos
= pos
;
724 pos
+= obj_datasec(abfd
)->_raw_size
;
725 vma
+= obj_datasec(abfd
)->_raw_size
;
728 if (!obj_bsssec(abfd
)->user_set_vma
)
731 pad
= align_power (vma
, obj_bsssec(abfd
)->alignment_power
) - vma
;
733 obj_datasec(abfd
)->_raw_size
+= pad
;
736 obj_bsssec(abfd
)->vma
= vma
;
738 obj_bsssec(abfd
)->filepos
= pos
;
740 /* Fix up the exec header. */
741 execp
->a_text
= obj_textsec(abfd
)->_raw_size
;
742 execp
->a_data
= obj_datasec(abfd
)->_raw_size
;
743 execp
->a_bss
= obj_bsssec(abfd
)->_raw_size
;
744 N_SET_MAGIC (*execp
, OMAGIC
);
748 adjust_z_magic (abfd
, execp
)
750 struct internal_exec
*execp
;
752 bfd_size_type data_pad
, text_pad
;
754 CONST
struct aout_backend_data
*abdp
;
755 int ztih
; /* Nonzero if text includes exec header. */
757 abdp
= aout_backend_info (abfd
);
760 ztih
= abdp
&& abdp
->text_includes_header
;
761 obj_textsec(abfd
)->filepos
= (ztih
762 ? adata(abfd
).exec_bytes_size
763 : adata(abfd
).page_size
);
764 if (! obj_textsec(abfd
)->user_set_vma
)
765 /* ?? Do we really need to check for relocs here? */
766 obj_textsec(abfd
)->vma
= ((abfd
->flags
& HAS_RELOC
)
769 ? (abdp
->default_text_vma
770 + adata(abfd
).exec_bytes_size
)
771 : abdp
->default_text_vma
));
772 /* Could take strange alignment of text section into account here? */
774 /* Find start of data. */
775 text_end
= obj_textsec(abfd
)->filepos
+ obj_textsec(abfd
)->_raw_size
;
776 text_pad
= BFD_ALIGN (text_end
, adata(abfd
).page_size
) - text_end
;
777 obj_textsec(abfd
)->_raw_size
+= text_pad
;
778 text_end
+= text_pad
;
781 if (!obj_datasec(abfd
)->user_set_vma
)
784 vma
= obj_textsec(abfd
)->vma
+ obj_textsec(abfd
)->_raw_size
;
785 obj_datasec(abfd
)->vma
= BFD_ALIGN (vma
, adata(abfd
).segment_size
);
787 if (abdp
&& abdp
->zmagic_mapped_contiguous
)
789 text_pad
= (obj_datasec(abfd
)->vma
790 - obj_textsec(abfd
)->vma
791 - obj_textsec(abfd
)->_raw_size
);
792 obj_textsec(abfd
)->_raw_size
+= text_pad
;
794 obj_datasec(abfd
)->filepos
= (obj_textsec(abfd
)->filepos
795 + obj_textsec(abfd
)->_raw_size
);
797 /* Fix up exec header while we're at it. */
798 execp
->a_text
= obj_textsec(abfd
)->_raw_size
;
799 if (ztih
&& (!abdp
|| (abdp
&& !abdp
->exec_header_not_counted
)))
800 execp
->a_text
+= adata(abfd
).exec_bytes_size
;
801 N_SET_MAGIC (*execp
, ZMAGIC
);
803 /* Spec says data section should be rounded up to page boundary. */
804 obj_datasec(abfd
)->_raw_size
805 = align_power (obj_datasec(abfd
)->_raw_size
,
806 obj_bsssec(abfd
)->alignment_power
);
807 execp
->a_data
= BFD_ALIGN (obj_datasec(abfd
)->_raw_size
,
808 adata(abfd
).page_size
);
809 data_pad
= execp
->a_data
- obj_datasec(abfd
)->_raw_size
;
812 if (!obj_bsssec(abfd
)->user_set_vma
)
813 obj_bsssec(abfd
)->vma
= (obj_datasec(abfd
)->vma
814 + obj_datasec(abfd
)->_raw_size
);
815 /* If the BSS immediately follows the data section and extra space
816 in the page is left after the data section, fudge data
817 in the header so that the bss section looks smaller by that
818 amount. We'll start the bss section there, and lie to the OS.
819 (Note that a linker script, as well as the above assignment,
820 could have explicitly set the BSS vma to immediately follow
821 the data section.) */
822 if (align_power (obj_bsssec(abfd
)->vma
, obj_bsssec(abfd
)->alignment_power
)
823 == obj_datasec(abfd
)->vma
+ obj_datasec(abfd
)->_raw_size
)
824 execp
->a_bss
= (data_pad
> obj_bsssec(abfd
)->_raw_size
) ? 0 :
825 obj_bsssec(abfd
)->_raw_size
- data_pad
;
827 execp
->a_bss
= obj_bsssec(abfd
)->_raw_size
;
831 adjust_n_magic (abfd
, execp
)
833 struct internal_exec
*execp
;
835 file_ptr pos
= adata(abfd
).exec_bytes_size
;
840 obj_textsec(abfd
)->filepos
= pos
;
841 if (!obj_textsec(abfd
)->user_set_vma
)
842 obj_textsec(abfd
)->vma
= vma
;
844 vma
= obj_textsec(abfd
)->vma
;
845 pos
+= obj_textsec(abfd
)->_raw_size
;
846 vma
+= obj_textsec(abfd
)->_raw_size
;
849 obj_datasec(abfd
)->filepos
= pos
;
850 if (!obj_datasec(abfd
)->user_set_vma
)
851 obj_datasec(abfd
)->vma
= BFD_ALIGN (vma
, adata(abfd
).segment_size
);
852 vma
= obj_datasec(abfd
)->vma
;
854 /* Since BSS follows data immediately, see if it needs alignment. */
855 vma
+= obj_datasec(abfd
)->_raw_size
;
856 pad
= align_power (vma
, obj_bsssec(abfd
)->alignment_power
) - vma
;
857 obj_datasec(abfd
)->_raw_size
+= pad
;
858 pos
+= obj_datasec(abfd
)->_raw_size
;
861 if (!obj_bsssec(abfd
)->user_set_vma
)
862 obj_bsssec(abfd
)->vma
= vma
;
864 vma
= obj_bsssec(abfd
)->vma
;
866 /* Fix up exec header. */
867 execp
->a_text
= obj_textsec(abfd
)->_raw_size
;
868 execp
->a_data
= obj_datasec(abfd
)->_raw_size
;
869 execp
->a_bss
= obj_bsssec(abfd
)->_raw_size
;
870 N_SET_MAGIC (*execp
, NMAGIC
);
874 DEFUN (NAME(aout
,adjust_sizes_and_vmas
), (abfd
, text_size
, text_end
),
875 bfd
*abfd AND bfd_size_type
*text_size AND file_ptr
*text_end
)
877 struct internal_exec
*execp
= exec_hdr (abfd
);
879 if ((obj_textsec (abfd
) == NULL
) || (obj_datasec (abfd
) == NULL
))
881 bfd_error
= invalid_operation
;
884 if (adata(abfd
).magic
!= undecided_magic
) return true;
886 obj_textsec(abfd
)->_raw_size
=
887 align_power(obj_textsec(abfd
)->_raw_size
,
888 obj_textsec(abfd
)->alignment_power
);
890 *text_size
= obj_textsec (abfd
)->_raw_size
;
891 /* Rule (heuristic) for when to pad to a new page. Note that there
892 are (at least) two ways demand-paged (ZMAGIC) files have been
893 handled. Most Berkeley-based systems start the text segment at
894 (PAGE_SIZE). However, newer versions of SUNOS start the text
895 segment right after the exec header; the latter is counted in the
896 text segment size, and is paged in by the kernel with the rest of
899 /* This perhaps isn't the right way to do this, but made it simpler for me
900 to understand enough to implement it. Better would probably be to go
901 right from BFD flags to alignment/positioning characteristics. But the
902 old code was sloppy enough about handling the flags, and had enough
903 other magic, that it was a little hard for me to understand. I think
904 I understand it better now, but I haven't time to do the cleanup this
907 if (abfd
->flags
& D_PAGED
)
908 /* Whether or not WP_TEXT is set -- let D_PAGED override. */
909 /* @@ What about QMAGIC? */
910 adata(abfd
).magic
= z_magic
;
911 else if (abfd
->flags
& WP_TEXT
)
912 adata(abfd
).magic
= n_magic
;
914 adata(abfd
).magic
= o_magic
;
916 #ifdef BFD_AOUT_DEBUG /* requires gcc2 */
918 fprintf (stderr
, "%s text=<%x,%x,%x> data=<%x,%x,%x> bss=<%x,%x,%x>\n",
920 switch (adata(abfd
).magic
) {
921 case n_magic
: str
= "NMAGIC"; break;
922 case o_magic
: str
= "OMAGIC"; break;
923 case z_magic
: str
= "ZMAGIC"; break;
928 obj_textsec(abfd
)->vma
, obj_textsec(abfd
)->_raw_size
,
929 obj_textsec(abfd
)->alignment_power
,
930 obj_datasec(abfd
)->vma
, obj_datasec(abfd
)->_raw_size
,
931 obj_datasec(abfd
)->alignment_power
,
932 obj_bsssec(abfd
)->vma
, obj_bsssec(abfd
)->_raw_size
,
933 obj_bsssec(abfd
)->alignment_power
);
937 switch (adata(abfd
).magic
)
940 adjust_o_magic (abfd
, execp
);
943 adjust_z_magic (abfd
, execp
);
946 adjust_n_magic (abfd
, execp
);
952 #ifdef BFD_AOUT_DEBUG
953 fprintf (stderr
, " text=<%x,%x,%x> data=<%x,%x,%x> bss=<%x,%x>\n",
954 obj_textsec(abfd
)->vma
, obj_textsec(abfd
)->_raw_size
,
955 obj_textsec(abfd
)->filepos
,
956 obj_datasec(abfd
)->vma
, obj_datasec(abfd
)->_raw_size
,
957 obj_datasec(abfd
)->filepos
,
958 obj_bsssec(abfd
)->vma
, obj_bsssec(abfd
)->_raw_size
);
966 aout_@var{size}_new_section_hook
969 boolean aout_@var{size}_new_section_hook,
974 Called by the BFD in response to a @code{bfd_make_section}
978 DEFUN(NAME(aout
,new_section_hook
),(abfd
, newsect
),
982 /* align to double at least */
983 newsect
->alignment_power
= bfd_get_arch_info(abfd
)->section_align_power
;
986 if (bfd_get_format (abfd
) == bfd_object
)
988 if (obj_textsec(abfd
) == NULL
&& !strcmp(newsect
->name
, ".text")) {
989 obj_textsec(abfd
)= newsect
;
990 newsect
->target_index
= N_TEXT
| N_EXT
;
994 if (obj_datasec(abfd
) == NULL
&& !strcmp(newsect
->name
, ".data")) {
995 obj_datasec(abfd
) = newsect
;
996 newsect
->target_index
= N_DATA
| N_EXT
;
1000 if (obj_bsssec(abfd
) == NULL
&& !strcmp(newsect
->name
, ".bss")) {
1001 obj_bsssec(abfd
) = newsect
;
1002 newsect
->target_index
= N_BSS
| N_EXT
;
1008 /* We allow more than three sections internally */
1013 DEFUN(NAME(aout
,set_section_contents
),(abfd
, section
, location
, offset
, count
),
1018 bfd_size_type count
)
1021 bfd_size_type text_size
;
1023 if (abfd
->output_has_begun
== false)
1025 if (NAME(aout
,adjust_sizes_and_vmas
) (abfd
,
1027 &text_end
) == false)
1031 /* regardless, once we know what we're doing, we might as well get going */
1032 if (section
!= obj_bsssec(abfd
))
1034 bfd_seek (abfd
, section
->filepos
+ offset
, SEEK_SET
);
1037 return (bfd_write ((PTR
)location
, 1, count
, abfd
) == count
) ?
1045 /* Classify stabs symbols */
1047 #define sym_in_text_section(sym) \
1048 (((sym)->type & (N_ABS | N_TEXT | N_DATA | N_BSS))== N_TEXT)
1050 #define sym_in_data_section(sym) \
1051 (((sym)->type & (N_ABS | N_TEXT | N_DATA | N_BSS))== N_DATA)
1053 #define sym_in_bss_section(sym) \
1054 (((sym)->type & (N_ABS | N_TEXT | N_DATA | N_BSS))== N_BSS)
1056 /* Symbol is undefined if type is N_UNDF|N_EXT and if it has
1057 zero in the "value" field. Nonzeroes there are fortrancommon
1059 #define sym_is_undefined(sym) \
1060 ((sym)->type == (N_UNDF | N_EXT) && (sym)->symbol.value == 0)
1062 /* Symbol is a global definition if N_EXT is on and if it has
1063 a nonzero type field. */
1064 #define sym_is_global_defn(sym) \
1065 (((sym)->type & N_EXT) && (sym)->type & N_TYPE)
1067 /* Symbol is debugger info if any bits outside N_TYPE or N_EXT
1069 #define sym_is_debugger_info(sym) \
1070 (((sym)->type & ~(N_EXT | N_TYPE)) || (sym)->type == N_FN)
1072 #define sym_is_fortrancommon(sym) \
1073 (((sym)->type == (N_EXT)) && (sym)->symbol.value != 0)
1075 /* Symbol is absolute if it has N_ABS set */
1076 #define sym_is_absolute(sym) \
1077 (((sym)->type & N_TYPE)== N_ABS)
1080 #define sym_is_indirect(sym) \
1081 (((sym)->type & N_ABS)== N_ABS)
1083 /* Only in their own functions for ease of debugging; when sym flags have
1084 stabilised these should be inlined into their (single) caller */
1087 DEFUN (translate_from_native_sym_flags
, (sym_pointer
, cache_ptr
, abfd
),
1088 struct external_nlist
*sym_pointer AND
1089 aout_symbol_type
* cache_ptr AND
1092 cache_ptr
->symbol
.section
= 0;
1093 switch (cache_ptr
->type
& N_TYPE
)
1095 case N_SETA
: case N_SETA
| N_EXT
:
1096 case N_SETT
: case N_SETT
| N_EXT
:
1097 case N_SETD
: case N_SETD
| N_EXT
:
1098 case N_SETB
: case N_SETB
| N_EXT
:
1100 char *copy
= bfd_alloc (abfd
, strlen (cache_ptr
->symbol
.name
) + 1);
1102 asection
*into_section
;
1104 arelent_chain
*reloc
= (arelent_chain
*) bfd_alloc (abfd
, sizeof (arelent_chain
));
1105 strcpy (copy
, cache_ptr
->symbol
.name
);
1107 /* Make sure that this bfd has a section with the right contructor
1109 section
= bfd_get_section_by_name (abfd
, copy
);
1111 section
= bfd_make_section (abfd
, copy
);
1113 /* Build a relocation entry for the constructor */
1114 switch ((cache_ptr
->type
& N_TYPE
))
1116 case N_SETA
: case N_SETA
| N_EXT
:
1117 into_section
= &bfd_abs_section
;
1118 cache_ptr
->type
= N_ABS
;
1120 case N_SETT
: case N_SETT
| N_EXT
:
1121 into_section
= (asection
*) obj_textsec (abfd
);
1122 cache_ptr
->type
= N_TEXT
;
1124 case N_SETD
: case N_SETD
| N_EXT
:
1125 into_section
= (asection
*) obj_datasec (abfd
);
1126 cache_ptr
->type
= N_DATA
;
1128 case N_SETB
: case N_SETB
| N_EXT
:
1129 into_section
= (asection
*) obj_bsssec (abfd
);
1130 cache_ptr
->type
= N_BSS
;
1136 /* Build a relocation pointing into the constuctor section
1137 pointing at the symbol in the set vector specified */
1139 reloc
->relent
.addend
= cache_ptr
->symbol
.value
;
1140 cache_ptr
->symbol
.section
= into_section
->symbol
->section
;
1141 reloc
->relent
.sym_ptr_ptr
= into_section
->symbol_ptr_ptr
;
1144 /* We modify the symbol to belong to a section depending upon the
1145 name of the symbol - probably __CTOR__ or __DTOR__ but we don't
1146 really care, and add to the size of the section to contain a
1147 pointer to the symbol. Build a reloc entry to relocate to this
1148 symbol attached to this section. */
1150 section
->flags
= SEC_CONSTRUCTOR
;
1153 section
->reloc_count
++;
1154 section
->alignment_power
= 2;
1156 reloc
->next
= section
->constructor_chain
;
1157 section
->constructor_chain
= reloc
;
1158 reloc
->relent
.address
= section
->_raw_size
;
1159 section
->_raw_size
+= sizeof (int *);
1162 = (obj_reloc_entry_size(abfd
) == RELOC_EXT_SIZE
1163 ? howto_table_ext
: howto_table_std
)
1164 + CTOR_TABLE_RELOC_IDX
;
1165 cache_ptr
->symbol
.flags
|= BSF_CONSTRUCTOR
;
1169 if (cache_ptr
->type
== N_WARNING
)
1171 /* This symbol is the text of a warning message, the next symbol
1172 is the symbol to associate the warning with */
1173 cache_ptr
->symbol
.flags
= BSF_DEBUGGING
| BSF_WARNING
;
1175 /* @@ Stuffing pointers into integers is a no-no.
1176 We can usually get away with it if the integer is
1177 large enough though. */
1178 if (sizeof (cache_ptr
+ 1) > sizeof (bfd_vma
))
1180 cache_ptr
->symbol
.value
= (bfd_vma
) ((cache_ptr
+ 1));
1182 /* We don't use a warning symbol's section, but we need
1183 it to be nonzero for the sanity check below, so
1184 pick one arbitrarily. */
1185 cache_ptr
->symbol
.section
= &bfd_abs_section
;
1187 /* We furgle with the next symbol in place.
1188 We don't want it to be undefined, we'll trample the type */
1189 (sym_pointer
+ 1)->e_type
[0] = 0xff;
1192 if ((cache_ptr
->type
| N_EXT
) == (N_INDR
| N_EXT
))
1194 /* Two symbols in a row for an INDR message. The first symbol
1195 contains the name we will match, the second symbol contains
1196 the name the first name is translated into. It is supplied to
1197 us undefined. This is good, since we want to pull in any files
1199 cache_ptr
->symbol
.flags
= BSF_DEBUGGING
| BSF_INDIRECT
;
1201 /* @@ Stuffing pointers into integers is a no-no.
1202 We can usually get away with it if the integer is
1203 large enough though. */
1204 if (sizeof (cache_ptr
+ 1) > sizeof (bfd_vma
))
1207 cache_ptr
->symbol
.value
= (bfd_vma
) ((cache_ptr
+ 1));
1208 cache_ptr
->symbol
.section
= &bfd_ind_section
;
1211 else if (sym_is_debugger_info (cache_ptr
))
1213 cache_ptr
->symbol
.flags
= BSF_DEBUGGING
;
1214 /* Work out the section correct for this symbol */
1215 switch (cache_ptr
->type
& N_TYPE
)
1219 cache_ptr
->symbol
.section
= obj_textsec (abfd
);
1220 cache_ptr
->symbol
.value
-= obj_textsec (abfd
)->vma
;
1223 cache_ptr
->symbol
.value
-= obj_datasec (abfd
)->vma
;
1224 cache_ptr
->symbol
.section
= obj_datasec (abfd
);
1227 cache_ptr
->symbol
.section
= obj_bsssec (abfd
);
1228 cache_ptr
->symbol
.value
-= obj_bsssec (abfd
)->vma
;
1232 cache_ptr
->symbol
.section
= &bfd_abs_section
;
1239 if (sym_is_fortrancommon (cache_ptr
))
1241 cache_ptr
->symbol
.flags
= 0;
1242 cache_ptr
->symbol
.section
= &bfd_com_section
;
1250 /* In a.out, the value of a symbol is always relative to the
1251 * start of the file, if this is a data symbol we'll subtract
1252 * the size of the text section to get the section relative
1253 * value. If this is a bss symbol (which would be strange)
1254 * we'll subtract the size of the previous two sections
1255 * to find the section relative address.
1258 if (sym_in_text_section (cache_ptr
))
1260 cache_ptr
->symbol
.value
-= obj_textsec (abfd
)->vma
;
1261 cache_ptr
->symbol
.section
= obj_textsec (abfd
);
1263 else if (sym_in_data_section (cache_ptr
))
1265 cache_ptr
->symbol
.value
-= obj_datasec (abfd
)->vma
;
1266 cache_ptr
->symbol
.section
= obj_datasec (abfd
);
1268 else if (sym_in_bss_section (cache_ptr
))
1270 cache_ptr
->symbol
.section
= obj_bsssec (abfd
);
1271 cache_ptr
->symbol
.value
-= obj_bsssec (abfd
)->vma
;
1273 else if (sym_is_undefined (cache_ptr
))
1275 cache_ptr
->symbol
.flags
= 0;
1276 cache_ptr
->symbol
.section
= &bfd_und_section
;
1278 else if (sym_is_absolute (cache_ptr
))
1280 cache_ptr
->symbol
.section
= &bfd_abs_section
;
1283 if (sym_is_global_defn (cache_ptr
))
1285 cache_ptr
->symbol
.flags
= BSF_GLOBAL
| BSF_EXPORT
;
1287 else if (! sym_is_undefined (cache_ptr
))
1289 cache_ptr
->symbol
.flags
= BSF_LOCAL
;
1293 if (cache_ptr
->symbol
.section
== 0)
1300 DEFUN(translate_to_native_sym_flags
,(sym_pointer
, cache_ptr
, abfd
),
1301 struct external_nlist
*sym_pointer AND
1302 asymbol
*cache_ptr AND
1305 bfd_vma value
= cache_ptr
->value
;
1307 /* mask out any existing type bits in case copying from one section
1309 sym_pointer
->e_type
[0] &= ~N_TYPE
;
1311 /* We attempt to order these tests by decreasing frequency of success,
1312 according to tcov when linking the linker. */
1313 if (bfd_get_output_section(cache_ptr
) == &bfd_abs_section
) {
1314 sym_pointer
->e_type
[0] |= N_ABS
;
1316 else if (bfd_get_output_section(cache_ptr
) == obj_textsec (abfd
)) {
1317 sym_pointer
->e_type
[0] |= N_TEXT
;
1319 else if (bfd_get_output_section(cache_ptr
) == obj_datasec (abfd
)) {
1320 sym_pointer
->e_type
[0] |= N_DATA
;
1322 else if (bfd_get_output_section(cache_ptr
) == obj_bsssec (abfd
)) {
1323 sym_pointer
->e_type
[0] |= N_BSS
;
1325 else if (bfd_get_output_section(cache_ptr
) == &bfd_und_section
) {
1326 sym_pointer
->e_type
[0] = (N_UNDF
| N_EXT
);
1328 else if (bfd_get_output_section(cache_ptr
) == &bfd_ind_section
) {
1329 sym_pointer
->e_type
[0] = N_INDR
;
1331 else if (bfd_get_output_section(cache_ptr
) == NULL
) {
1332 /* Protect the bfd_is_com_section call.
1333 This case occurs, e.g., for the *DEBUG* section of a COFF file. */
1334 bfd_error
= nonrepresentable_section
;
1337 else if (bfd_is_com_section (bfd_get_output_section (cache_ptr
))) {
1338 sym_pointer
->e_type
[0] = (N_UNDF
| N_EXT
);
1341 bfd_error
= nonrepresentable_section
;
1345 /* Turn the symbol from section relative to absolute again */
1347 value
+= cache_ptr
->section
->output_section
->vma
+ cache_ptr
->section
->output_offset
;
1350 if (cache_ptr
->flags
& (BSF_WARNING
)) {
1351 sym_pointer
->e_type
[0] = N_WARNING
;
1352 (sym_pointer
+1)->e_type
[0] = 1;
1355 if (cache_ptr
->flags
& BSF_DEBUGGING
) {
1356 sym_pointer
->e_type
[0] = ((aout_symbol_type
*)cache_ptr
)->type
;
1358 else if (cache_ptr
->flags
& (BSF_GLOBAL
| BSF_EXPORT
)) {
1359 sym_pointer
->e_type
[0] |= N_EXT
;
1361 if (cache_ptr
->flags
& BSF_CONSTRUCTOR
) {
1362 int type
= ((aout_symbol_type
*)cache_ptr
)->type
;
1365 case N_ABS
: type
= N_SETA
; break;
1366 case N_TEXT
: type
= N_SETT
; break;
1367 case N_DATA
: type
= N_SETD
; break;
1368 case N_BSS
: type
= N_SETB
; break;
1370 sym_pointer
->e_type
[0] = type
;
1373 PUT_WORD(abfd
, value
, sym_pointer
->e_value
);
1378 /* Native-level interface to symbols. */
1382 DEFUN(NAME(aout
,make_empty_symbol
),(abfd
),
1385 aout_symbol_type
*new =
1386 (aout_symbol_type
*)bfd_zalloc (abfd
, sizeof (aout_symbol_type
));
1387 new->symbol
.the_bfd
= abfd
;
1389 return &new->symbol
;
1392 /* Translate a set of internal symbols into external symbols. */
1395 translate_symbol_table (abfd
, in
, ext
, count
, str
, strsize
, dynamic
)
1397 aout_symbol_type
*in
;
1398 struct external_nlist
*ext
;
1399 bfd_size_type count
;
1401 bfd_size_type strsize
;
1404 struct external_nlist
*ext_end
;
1406 ext_end
= ext
+ count
;
1407 for (; ext
< ext_end
; ext
++, in
++)
1411 x
= GET_WORD (abfd
, ext
->e_strx
);
1412 in
->symbol
.the_bfd
= abfd
;
1414 /* For the normal symbols, the zero index points at the number
1415 of bytes in the string table but is to be interpreted as the
1416 null string. For the dynamic symbols, the number of bytes in
1417 the string table is stored in the __DYNAMIC structure and the
1418 zero index points at an actual string. */
1419 if (x
== 0 && ! dynamic
)
1420 in
->symbol
.name
= "";
1421 else if (x
< strsize
)
1422 in
->symbol
.name
= str
+ x
;
1426 in
->symbol
.value
= GET_SWORD (abfd
, ext
->e_value
);
1427 in
->desc
= bfd_h_get_16 (abfd
, ext
->e_desc
);
1428 in
->other
= bfd_h_get_8 (abfd
, ext
->e_other
);
1429 in
->type
= bfd_h_get_8 (abfd
, ext
->e_type
);
1430 in
->symbol
.udata
= 0;
1432 translate_from_native_sym_flags (ext
, in
, abfd
);
1435 in
->symbol
.flags
|= BSF_DYNAMIC
;
1441 /* We read the symbols into a buffer, which is discarded when this
1442 function exits. We read the strings into a buffer large enough to
1443 hold them all plus all the cached symbol entries. */
1446 DEFUN(NAME(aout
,slurp_symbol_table
),(abfd
),
1449 bfd_size_type symbol_size
;
1450 bfd_size_type string_size
;
1451 unsigned char string_chars
[BYTES_IN_WORD
];
1452 struct external_nlist
*syms
;
1454 aout_symbol_type
*cached
;
1455 bfd_size_type dynsym_count
= 0;
1456 struct external_nlist
*dynsyms
= NULL
;
1457 char *dynstrs
= NULL
;
1458 bfd_size_type dynstr_size
;
1460 /* If there's no work to be done, don't do any */
1461 if (obj_aout_symbols (abfd
) != (aout_symbol_type
*)NULL
) return true;
1462 symbol_size
= exec_hdr(abfd
)->a_syms
;
1463 if (symbol_size
== 0)
1465 bfd_error
= no_symbols
;
1469 bfd_seek (abfd
, obj_str_filepos (abfd
), SEEK_SET
);
1470 if (bfd_read ((PTR
)string_chars
, BYTES_IN_WORD
, 1, abfd
) != BYTES_IN_WORD
)
1472 string_size
= GET_WORD (abfd
, string_chars
);
1474 /* If this is a dynamic object, see if we can get the dynamic symbol
1476 if ((bfd_get_file_flags (abfd
) & DYNAMIC
) != 0
1477 && aout_backend_info (abfd
)->read_dynamic_symbols
)
1479 dynsym_count
= ((*aout_backend_info (abfd
)->read_dynamic_symbols
)
1480 (abfd
, &dynsyms
, &dynstrs
, &dynstr_size
));
1481 if (dynsym_count
== (bfd_size_type
) -1)
1485 strings
= (char *) bfd_alloc (abfd
, string_size
+ 1);
1486 cached
= ((aout_symbol_type
*)
1488 ((bfd_get_symcount (abfd
) + dynsym_count
)
1489 * sizeof (aout_symbol_type
))));
1491 /* Don't allocate on the obstack, so we can free it easily. */
1492 syms
= (struct external_nlist
*) bfd_xmalloc(symbol_size
);
1493 bfd_seek (abfd
, obj_sym_filepos (abfd
), SEEK_SET
);
1494 if (bfd_read ((PTR
)syms
, 1, symbol_size
, abfd
) != symbol_size
)
1500 bfd_release (abfd
, cached
);
1502 bfd_release (abfd
, strings
);
1506 bfd_seek (abfd
, obj_str_filepos (abfd
), SEEK_SET
);
1507 if (bfd_read ((PTR
)strings
, 1, string_size
, abfd
) != string_size
)
1511 strings
[string_size
] = 0; /* Just in case. */
1513 /* OK, now walk the new symtable, cacheing symbol properties */
1514 if (! translate_symbol_table (abfd
, cached
, syms
, bfd_get_symcount (abfd
),
1515 strings
, string_size
, false))
1517 if (dynsym_count
> 0)
1519 if (! translate_symbol_table (abfd
, cached
+ bfd_get_symcount (abfd
),
1520 dynsyms
, dynsym_count
, dynstrs
,
1524 bfd_get_symcount (abfd
) += dynsym_count
;
1527 obj_aout_symbols (abfd
) = cached
;
1534 /* Possible improvements:
1535 + look for strings matching trailing substrings of other strings
1536 + better data structures? balanced trees?
1537 + smaller per-string or per-symbol data? re-use some of the symbol's
1539 + also look at reducing memory use elsewhere -- maybe if we didn't have to
1540 construct the entire symbol table at once, we could get by with smaller
1541 amounts of VM? (What effect does that have on the string table
1543 + rip this out of here, put it into its own file in bfd or libiberty, so
1544 coff and elf can use it too. I'll work on this soon, but have more
1545 pressing tasks right now.
1547 A hash table might(?) be more efficient for handling exactly the cases that
1548 are handled now, but for trailing substring matches, I think we want to
1549 examine the `nearest' values (reverse-)lexically, not merely impose a strict
1550 order, nor look only for exact-match or not-match. I don't think a hash
1551 table would be very useful for that, and I don't feel like fleshing out two
1552 completely different implementations. [raeburn:930419.0331EDT] */
1554 struct stringtab_entry
{
1555 /* Hash value for this string. Only useful so long as we aren't doing
1556 substring matches. */
1559 /* Next node to look at, depending on whether the hash value of the string
1560 being searched for is less than or greater than the hash value of the
1561 current node. For now, `equal to' is lumped in with `greater than', for
1562 space efficiency. It's not a common enough case to warrant another field
1563 to be used for all nodes. */
1564 struct stringtab_entry
*less
;
1565 struct stringtab_entry
*greater
;
1567 /* The string itself. */
1570 /* The index allocated for this string. */
1571 bfd_size_type index
;
1573 #ifdef GATHER_STATISTICS
1574 /* How many references have there been to this string? (Not currently used;
1575 could be dumped out for anaylsis, if anyone's interested.) */
1576 unsigned long count
;
1579 /* Next node in linked list, in suggested output order. */
1580 struct stringtab_entry
*next_to_output
;
1583 struct stringtab_data
{
1584 /* Tree of string table entries. */
1585 struct stringtab_entry
*strings
;
1587 /* Fudge factor used to center top node of tree. */
1590 /* Next index value to issue. */
1591 bfd_size_type index
;
1593 /* Index used for empty strings. Cached here because checking for them
1594 is really easy, and we can avoid searching the tree. */
1595 bfd_size_type empty_string_index
;
1597 /* These fields indicate the two ends of a singly-linked list that indicates
1598 the order strings should be written out in. Use this order, and no
1599 seeking will need to be done, so output efficiency should be maximized. */
1600 struct stringtab_entry
**end
;
1601 struct stringtab_entry
*output_order
;
1603 #ifdef GATHER_STATISTICS
1604 /* Number of strings which duplicate strings already in the table. */
1605 unsigned long duplicates
;
1607 /* Number of bytes saved by not having to write all the duplicate strings. */
1608 unsigned long bytes_saved
;
1610 /* Number of zero-length strings. Currently, these all turn into
1611 references to the null byte at the end of the first string. In some
1612 cases (possibly not all? explore this...), it should be possible to
1613 simply write out a zero index value. */
1614 unsigned long empty_strings
;
1616 /* Number of times the hash values matched but the strings were different.
1617 Note that this includes the number of times the other string(s) occurs, so
1618 there may only be two strings hashing to the same value, even if this
1619 number is very large. */
1620 unsigned long bad_hash_matches
;
1622 /* Null strings aren't counted in this one.
1623 This will probably only be nonzero if we've got an input file
1624 which was produced by `ld -r' (i.e., it's already been processed
1625 through this code). Under some operating systems, native tools
1626 may make all empty strings have the same index; but the pointer
1627 check won't catch those, because to get to that stage we'd already
1628 have to compute the checksum, which requires reading the string,
1629 so we short-circuit that case with empty_string_index above. */
1630 unsigned long pointer_matches
;
1632 /* Number of comparisons done. I figure with the algorithms in use below,
1633 the average number of comparisons done (per symbol) should be roughly
1634 log-base-2 of the number of unique strings. */
1635 unsigned long n_compares
;
1639 /* Some utility functions for the string table code. */
1641 /* For speed, only hash on the first this many bytes of strings.
1642 This number was chosen by profiling ld linking itself, with -g. */
1643 #define HASHMAXLEN 25
1645 #define HASH_CHAR(c) (sum ^= sum >> 20, sum ^= sum << 7, sum += (c))
1647 static INLINE
unsigned int
1649 unsigned char *string
;
1650 register unsigned int len
;
1652 register unsigned int sum
= 0;
1654 if (len
> HASHMAXLEN
)
1662 HASH_CHAR (*string
++);
1668 stringtab_init (tab
)
1669 struct stringtab_data
*tab
;
1672 tab
->output_order
= 0;
1674 tab
->end
= &tab
->output_order
;
1676 /* Initial string table length includes size of length field. */
1677 tab
->index
= BYTES_IN_WORD
;
1678 tab
->empty_string_index
= -1;
1679 #ifdef GATHER_STATISTICS
1680 tab
->duplicates
= 0;
1681 tab
->empty_strings
= 0;
1682 tab
->bad_hash_matches
= 0;
1683 tab
->pointer_matches
= 0;
1684 tab
->bytes_saved
= 0;
1685 tab
->n_compares
= 0;
1690 compare (entry
, str
, hash
)
1691 struct stringtab_entry
*entry
;
1695 return hash
- entry
->hash
;
1698 #ifdef GATHER_STATISTICS
1699 /* Don't want to have to link in math library with all bfd applications... */
1700 static INLINE
double
1708 return ((d
> 1.41) ? 0.5 : 0) + n
;
1712 /* Main string table routines. */
1713 /* Returns index in string table. Whether or not this actually adds an
1714 entry into the string table should be irrelevant -- it just has to
1715 return a valid index. */
1716 static bfd_size_type
1717 add_to_stringtab (abfd
, str
, tab
)
1720 struct stringtab_data
*tab
;
1722 struct stringtab_entry
**ep
;
1723 register struct stringtab_entry
*entry
;
1724 unsigned int hashval
, len
;
1728 bfd_size_type index
;
1729 CONST bfd_size_type minus_one
= -1;
1731 #ifdef GATHER_STATISTICS
1732 tab
->empty_strings
++;
1734 index
= tab
->empty_string_index
;
1735 if (index
!= minus_one
)
1738 #ifdef GATHER_STATISTICS
1745 /* Need to find it. */
1746 entry
= tab
->strings
;
1749 index
= entry
->index
+ strlen (entry
->string
);
1750 tab
->empty_string_index
= index
;
1758 /* The hash_zero value is chosen such that the first symbol gets a value of
1759 zero. With a balanced tree, this wouldn't be very useful, but without it,
1760 we might get a more even split at the top level, instead of skewing it
1761 badly should hash("/usr/lib/crt0.o") (or whatever) be far from zero. */
1762 hashval
= hash (str
, len
) ^ tab
->hash_zero
;
1766 tab
->hash_zero
= hashval
;
1776 #ifdef GATHER_STATISTICS
1779 cmp
= compare (entry
, str
, hashval
);
1780 /* The not-equal cases are more frequent, so check them first. */
1782 ep
= &entry
->greater
;
1787 if (entry
->string
== str
)
1789 #ifdef GATHER_STATISTICS
1790 tab
->pointer_matches
++;
1794 /* Compare the first bytes to save a function call if they
1796 if (entry
->string
[0] == str
[0] && !strcmp (entry
->string
, str
))
1799 #ifdef GATHER_STATISTICS
1801 tab
->bytes_saved
+= len
+ 1;
1804 /* If we're in the linker, and the new string is from a new
1805 input file which might have already had these reductions
1806 run over it, we want to keep the new string pointer. I
1807 don't think we're likely to see any (or nearly as many,
1808 at least) cases where a later string is in the same location
1809 as an earlier one rather than this one. */
1810 entry
->string
= str
;
1811 return entry
->index
;
1813 #ifdef GATHER_STATISTICS
1814 tab
->bad_hash_matches
++;
1816 ep
= &entry
->greater
;
1820 /* If we get here, nothing that's in the table already matched.
1821 EP points to the `next' field at the end of the chain; stick a
1822 new entry on here. */
1824 entry
= (struct stringtab_entry
*)
1825 bfd_alloc_by_size_t (abfd
, sizeof (struct stringtab_entry
));
1827 entry
->less
= entry
->greater
= 0;
1828 entry
->hash
= hashval
;
1829 entry
->index
= tab
->index
;
1830 entry
->string
= str
;
1831 entry
->next_to_output
= 0;
1832 #ifdef GATHER_STATISTICS
1836 assert (*tab
->end
== 0);
1837 *(tab
->end
) = entry
;
1838 tab
->end
= &entry
->next_to_output
;
1839 assert (*tab
->end
== 0);
1842 tab
->index
+= len
+ 1;
1844 tab
->empty_string_index
= entry
->index
;
1848 return entry
->index
;
1852 emit_strtab (abfd
, tab
)
1854 struct stringtab_data
*tab
;
1856 struct stringtab_entry
*entry
;
1857 #ifdef GATHER_STATISTICS
1861 /* Be sure to put string length into correct byte ordering before writing
1863 char buffer
[BYTES_IN_WORD
];
1865 PUT_WORD (abfd
, tab
->index
, (unsigned char *) buffer
);
1866 bfd_write ((PTR
) buffer
, 1, BYTES_IN_WORD
, abfd
);
1868 for (entry
= tab
->output_order
; entry
; entry
= entry
->next_to_output
)
1870 bfd_write ((PTR
) entry
->string
, 1, strlen (entry
->string
) + 1, abfd
);
1871 #ifdef GATHER_STATISTICS
1876 #ifdef GATHER_STATISTICS
1877 /* Short form only, for now.
1878 To do: Specify output file. Conditionalize on environment? Detailed
1879 analysis if desired. */
1881 int n_syms
= bfd_get_symcount (abfd
);
1883 fprintf (stderr
, "String table data for output file:\n");
1884 fprintf (stderr
, " %8d symbols output\n", n_syms
);
1885 fprintf (stderr
, " %8d duplicate strings\n", tab
->duplicates
);
1886 fprintf (stderr
, " %8d empty strings\n", tab
->empty_strings
);
1887 fprintf (stderr
, " %8d unique strings output\n", count
);
1888 fprintf (stderr
, " %8d pointer matches\n", tab
->pointer_matches
);
1889 fprintf (stderr
, " %8d bytes saved\n", tab
->bytes_saved
);
1890 fprintf (stderr
, " %8d bad hash matches\n", tab
->bad_hash_matches
);
1891 fprintf (stderr
, " %8d hash-val comparisons\n", tab
->n_compares
);
1894 double n_compares
= tab
->n_compares
;
1895 double avg_compares
= n_compares
/ n_syms
;
1896 /* The second value here should usually be near one. */
1898 "\t average %f comparisons per symbol (%f * log2 nstrings)\n",
1899 avg_compares
, avg_compares
/ log2 (count
));
1906 generic = bfd_get_outsymbols(abfd);
1907 for (count = 0; count < bfd_get_symcount(abfd); count++)
1909 asymbol *g = *(generic++);
1913 size_t length = strlen(g->name)+1;
1914 bfd_write((PTR)g->name, 1, length, abfd);
1916 g->KEEPIT = (KEEPITTYPE) count;
1921 DEFUN(NAME(aout
,write_syms
),(abfd
),
1924 unsigned int count
;
1925 asymbol
**generic
= bfd_get_outsymbols (abfd
);
1926 struct stringtab_data strtab
;
1928 stringtab_init (&strtab
);
1930 for (count
= 0; count
< bfd_get_symcount (abfd
); count
++)
1932 asymbol
*g
= generic
[count
];
1933 struct external_nlist nsp
;
1936 PUT_WORD (abfd
, add_to_stringtab (abfd
, g
->name
, &strtab
),
1937 (unsigned char *) nsp
.e_strx
);
1939 PUT_WORD (abfd
, 0, (unsigned char *)nsp
.e_strx
);
1941 if (bfd_asymbol_flavour(g
) == abfd
->xvec
->flavour
)
1943 bfd_h_put_16(abfd
, aout_symbol(g
)->desc
, nsp
.e_desc
);
1944 bfd_h_put_8(abfd
, aout_symbol(g
)->other
, nsp
.e_other
);
1945 bfd_h_put_8(abfd
, aout_symbol(g
)->type
, nsp
.e_type
);
1949 bfd_h_put_16(abfd
,0, nsp
.e_desc
);
1950 bfd_h_put_8(abfd
, 0, nsp
.e_other
);
1951 bfd_h_put_8(abfd
, 0, nsp
.e_type
);
1954 if (! translate_to_native_sym_flags (&nsp
, g
, abfd
))
1957 if (bfd_write((PTR
)&nsp
,1,EXTERNAL_NLIST_SIZE
, abfd
)
1958 != EXTERNAL_NLIST_SIZE
)
1961 /* NB: `KEEPIT' currently overlays `flags', so set this only
1962 here, at the end. */
1966 emit_strtab (abfd
, &strtab
);
1973 DEFUN(NAME(aout
,get_symtab
),(abfd
, location
),
1977 unsigned int counter
= 0;
1978 aout_symbol_type
*symbase
;
1980 if (!NAME(aout
,slurp_symbol_table
)(abfd
)) return 0;
1982 for (symbase
= obj_aout_symbols(abfd
); counter
++ < bfd_get_symcount (abfd
);)
1983 *(location
++) = (asymbol
*)( symbase
++);
1985 return bfd_get_symcount (abfd
);
1989 /* Standard reloc stuff */
1990 /* Output standard relocation information to a file in target byte order. */
1993 DEFUN(NAME(aout
,swap_std_reloc_out
),(abfd
, g
, natptr
),
1996 struct reloc_std_external
*natptr
)
1999 asymbol
*sym
= *(g
->sym_ptr_ptr
);
2001 unsigned int r_length
;
2003 int r_baserel
, r_jmptable
, r_relative
;
2004 asection
*output_section
= sym
->section
->output_section
;
2006 PUT_WORD(abfd
, g
->address
, natptr
->r_address
);
2008 r_length
= g
->howto
->size
; /* Size as a power of two */
2009 r_pcrel
= (int) g
->howto
->pc_relative
; /* Relative to PC? */
2010 /* XXX This relies on relocs coming from a.out files. */
2011 r_baserel
= (g
->howto
->type
& 8) != 0;
2012 /* r_jmptable, r_relative??? FIXME-soon */
2017 /* For a standard reloc, the addend is in the object file. */
2018 r_addend
= g
->addend
+ (*(g
->sym_ptr_ptr
))->section
->output_section
->vma
;
2021 /* name was clobbered by aout_write_syms to be symbol index */
2023 /* If this relocation is relative to a symbol then set the
2024 r_index to the symbols index, and the r_extern bit.
2026 Absolute symbols can come in in two ways, either as an offset
2027 from the abs section, or as a symbol which has an abs value.
2032 if (bfd_is_com_section (output_section
)
2033 || output_section
== &bfd_abs_section
2034 || output_section
== &bfd_und_section
)
2036 if (bfd_abs_section
.symbol
== sym
)
2038 /* Whoops, looked like an abs symbol, but is really an offset
2039 from the abs section */
2045 /* Fill in symbol */
2047 r_index
= stoi((*(g
->sym_ptr_ptr
))->KEEPIT
);
2053 /* Just an ordinary section */
2055 r_index
= output_section
->target_index
;
2058 /* now the fun stuff */
2059 if (abfd
->xvec
->header_byteorder_big_p
!= false) {
2060 natptr
->r_index
[0] = r_index
>> 16;
2061 natptr
->r_index
[1] = r_index
>> 8;
2062 natptr
->r_index
[2] = r_index
;
2064 (r_extern
? RELOC_STD_BITS_EXTERN_BIG
: 0)
2065 | (r_pcrel
? RELOC_STD_BITS_PCREL_BIG
: 0)
2066 | (r_baserel
? RELOC_STD_BITS_BASEREL_BIG
: 0)
2067 | (r_jmptable
? RELOC_STD_BITS_JMPTABLE_BIG
: 0)
2068 | (r_relative
? RELOC_STD_BITS_RELATIVE_BIG
: 0)
2069 | (r_length
<< RELOC_STD_BITS_LENGTH_SH_BIG
);
2071 natptr
->r_index
[2] = r_index
>> 16;
2072 natptr
->r_index
[1] = r_index
>> 8;
2073 natptr
->r_index
[0] = r_index
;
2075 (r_extern
? RELOC_STD_BITS_EXTERN_LITTLE
: 0)
2076 | (r_pcrel
? RELOC_STD_BITS_PCREL_LITTLE
: 0)
2077 | (r_baserel
? RELOC_STD_BITS_BASEREL_LITTLE
: 0)
2078 | (r_jmptable
? RELOC_STD_BITS_JMPTABLE_LITTLE
: 0)
2079 | (r_relative
? RELOC_STD_BITS_RELATIVE_LITTLE
: 0)
2080 | (r_length
<< RELOC_STD_BITS_LENGTH_SH_LITTLE
);
2085 /* Extended stuff */
2086 /* Output extended relocation information to a file in target byte order. */
2089 DEFUN(NAME(aout
,swap_ext_reloc_out
),(abfd
, g
, natptr
),
2092 register struct reloc_ext_external
*natptr
)
2096 unsigned int r_type
;
2097 unsigned int r_addend
;
2098 asymbol
*sym
= *(g
->sym_ptr_ptr
);
2099 asection
*output_section
= sym
->section
->output_section
;
2101 PUT_WORD (abfd
, g
->address
, natptr
->r_address
);
2103 r_type
= (unsigned int) g
->howto
->type
;
2105 r_addend
= g
->addend
+ (*(g
->sym_ptr_ptr
))->section
->output_section
->vma
;
2107 /* If this relocation is relative to a symbol then set the
2108 r_index to the symbols index, and the r_extern bit.
2110 Absolute symbols can come in in two ways, either as an offset
2111 from the abs section, or as a symbol which has an abs value.
2112 check for that here. */
2114 if (bfd_is_com_section (output_section
)
2115 || output_section
== &bfd_abs_section
2116 || output_section
== &bfd_und_section
)
2118 if (bfd_abs_section
.symbol
== sym
)
2120 /* Whoops, looked like an abs symbol, but is really an offset
2121 from the abs section */
2128 r_index
= stoi((*(g
->sym_ptr_ptr
))->KEEPIT
);
2133 /* Just an ordinary section */
2135 r_index
= output_section
->target_index
;
2138 /* now the fun stuff */
2139 if (abfd
->xvec
->header_byteorder_big_p
!= false) {
2140 natptr
->r_index
[0] = r_index
>> 16;
2141 natptr
->r_index
[1] = r_index
>> 8;
2142 natptr
->r_index
[2] = r_index
;
2144 ((r_extern
? RELOC_EXT_BITS_EXTERN_BIG
: 0)
2145 | (r_type
<< RELOC_EXT_BITS_TYPE_SH_BIG
));
2147 natptr
->r_index
[2] = r_index
>> 16;
2148 natptr
->r_index
[1] = r_index
>> 8;
2149 natptr
->r_index
[0] = r_index
;
2151 (r_extern
? RELOC_EXT_BITS_EXTERN_LITTLE
: 0)
2152 | (r_type
<< RELOC_EXT_BITS_TYPE_SH_LITTLE
);
2155 PUT_WORD (abfd
, r_addend
, natptr
->r_addend
);
2158 /* BFD deals internally with all things based from the section they're
2159 in. so, something in 10 bytes into a text section with a base of
2160 50 would have a symbol (.text+10) and know .text vma was 50.
2162 Aout keeps all it's symbols based from zero, so the symbol would
2163 contain 60. This macro subs the base of each section from the value
2164 to give the true offset from the section */
2167 #define MOVE_ADDRESS(ad) \
2169 /* undefined symbol */ \
2170 cache_ptr->sym_ptr_ptr = symbols + r_index; \
2171 cache_ptr->addend = ad; \
2173 /* defined, section relative. replace symbol with pointer to \
2174 symbol which points to section */ \
2175 switch (r_index) { \
2177 case N_TEXT | N_EXT: \
2178 cache_ptr->sym_ptr_ptr = obj_textsec(abfd)->symbol_ptr_ptr; \
2179 cache_ptr->addend = ad - su->textsec->vma; \
2182 case N_DATA | N_EXT: \
2183 cache_ptr->sym_ptr_ptr = obj_datasec(abfd)->symbol_ptr_ptr; \
2184 cache_ptr->addend = ad - su->datasec->vma; \
2187 case N_BSS | N_EXT: \
2188 cache_ptr->sym_ptr_ptr = obj_bsssec(abfd)->symbol_ptr_ptr; \
2189 cache_ptr->addend = ad - su->bsssec->vma; \
2193 case N_ABS | N_EXT: \
2194 cache_ptr->sym_ptr_ptr = bfd_abs_section.symbol_ptr_ptr; \
2195 cache_ptr->addend = ad; \
2201 DEFUN(NAME(aout
,swap_ext_reloc_in
), (abfd
, bytes
, cache_ptr
, symbols
),
2203 struct reloc_ext_external
*bytes AND
2204 arelent
*cache_ptr AND
2209 unsigned int r_type
;
2210 struct aoutdata
*su
= &(abfd
->tdata
.aout_data
->a
);
2212 cache_ptr
->address
= (GET_SWORD (abfd
, bytes
->r_address
));
2214 /* now the fun stuff */
2215 if (abfd
->xvec
->header_byteorder_big_p
!= false) {
2216 r_index
= (bytes
->r_index
[0] << 16)
2217 | (bytes
->r_index
[1] << 8)
2218 | bytes
->r_index
[2];
2219 r_extern
= (0 != (bytes
->r_type
[0] & RELOC_EXT_BITS_EXTERN_BIG
));
2220 r_type
= (bytes
->r_type
[0] & RELOC_EXT_BITS_TYPE_BIG
)
2221 >> RELOC_EXT_BITS_TYPE_SH_BIG
;
2223 r_index
= (bytes
->r_index
[2] << 16)
2224 | (bytes
->r_index
[1] << 8)
2225 | bytes
->r_index
[0];
2226 r_extern
= (0 != (bytes
->r_type
[0] & RELOC_EXT_BITS_EXTERN_LITTLE
));
2227 r_type
= (bytes
->r_type
[0] & RELOC_EXT_BITS_TYPE_LITTLE
)
2228 >> RELOC_EXT_BITS_TYPE_SH_LITTLE
;
2231 cache_ptr
->howto
= howto_table_ext
+ r_type
;
2232 MOVE_ADDRESS(GET_SWORD(abfd
, bytes
->r_addend
));
2236 DEFUN(NAME(aout
,swap_std_reloc_in
), (abfd
, bytes
, cache_ptr
, symbols
),
2238 struct reloc_std_external
*bytes AND
2239 arelent
*cache_ptr AND
2244 unsigned int r_length
;
2246 int r_baserel
, r_jmptable
, r_relative
;
2247 struct aoutdata
*su
= &(abfd
->tdata
.aout_data
->a
);
2250 cache_ptr
->address
= bfd_h_get_32 (abfd
, bytes
->r_address
);
2252 /* now the fun stuff */
2253 if (abfd
->xvec
->header_byteorder_big_p
!= false) {
2254 r_index
= (bytes
->r_index
[0] << 16)
2255 | (bytes
->r_index
[1] << 8)
2256 | bytes
->r_index
[2];
2257 r_extern
= (0 != (bytes
->r_type
[0] & RELOC_STD_BITS_EXTERN_BIG
));
2258 r_pcrel
= (0 != (bytes
->r_type
[0] & RELOC_STD_BITS_PCREL_BIG
));
2259 r_baserel
= (0 != (bytes
->r_type
[0] & RELOC_STD_BITS_BASEREL_BIG
));
2260 r_jmptable
= (0 != (bytes
->r_type
[0] & RELOC_STD_BITS_JMPTABLE_BIG
));
2261 r_relative
= (0 != (bytes
->r_type
[0] & RELOC_STD_BITS_RELATIVE_BIG
));
2262 r_length
= (bytes
->r_type
[0] & RELOC_STD_BITS_LENGTH_BIG
)
2263 >> RELOC_STD_BITS_LENGTH_SH_BIG
;
2265 r_index
= (bytes
->r_index
[2] << 16)
2266 | (bytes
->r_index
[1] << 8)
2267 | bytes
->r_index
[0];
2268 r_extern
= (0 != (bytes
->r_type
[0] & RELOC_STD_BITS_EXTERN_LITTLE
));
2269 r_pcrel
= (0 != (bytes
->r_type
[0] & RELOC_STD_BITS_PCREL_LITTLE
));
2270 r_baserel
= (0 != (bytes
->r_type
[0] & RELOC_STD_BITS_BASEREL_LITTLE
));
2271 r_jmptable
= (0 != (bytes
->r_type
[0] & RELOC_STD_BITS_JMPTABLE_LITTLE
));
2272 r_relative
= (0 != (bytes
->r_type
[0] & RELOC_STD_BITS_RELATIVE_LITTLE
));
2273 r_length
= (bytes
->r_type
[0] & RELOC_STD_BITS_LENGTH_LITTLE
)
2274 >> RELOC_STD_BITS_LENGTH_SH_LITTLE
;
2277 howto_idx
= r_length
+ 4 * r_pcrel
+ 8 * r_baserel
;
2278 BFD_ASSERT (howto_idx
< TABLE_SIZE (howto_table_std
));
2279 cache_ptr
->howto
= howto_table_std
+ howto_idx
;
2280 BFD_ASSERT (cache_ptr
->howto
->type
!= -1);
2281 BFD_ASSERT (r_jmptable
== 0);
2282 BFD_ASSERT (r_relative
== 0);
2283 /* FIXME-soon: Roll jmptable, relative bits into howto setting */
2291 DEFUN(NAME(aout
,slurp_reloc_table
),(abfd
, asect
, symbols
),
2297 bfd_size_type reloc_size
;
2299 bfd_size_type dynrel_count
= 0;
2301 arelent
*reloc_cache
;
2303 unsigned int counter
= 0;
2306 if (asect
->relocation
) return true;
2308 if (asect
->flags
& SEC_CONSTRUCTOR
) return true;
2310 if (asect
== obj_datasec (abfd
))
2311 reloc_size
= exec_hdr(abfd
)->a_drsize
;
2312 else if (asect
== obj_textsec (abfd
))
2313 reloc_size
= exec_hdr(abfd
)->a_trsize
;
2316 bfd_error
= invalid_operation
;
2320 if ((bfd_get_file_flags (abfd
) & DYNAMIC
) != 0
2321 && aout_backend_info (abfd
)->read_dynamic_relocs
)
2323 dynrel_count
= ((*aout_backend_info (abfd
)->read_dynamic_relocs
)
2325 if (dynrel_count
== (bfd_size_type
) -1)
2329 bfd_seek (abfd
, asect
->rel_filepos
, SEEK_SET
);
2330 each_size
= obj_reloc_entry_size (abfd
);
2332 count
= reloc_size
/ each_size
;
2334 reloc_cache
= ((arelent
*)
2336 (size_t) ((count
+ dynrel_count
)
2337 * sizeof (arelent
))));
2341 bfd_error
= no_memory
;
2345 relocs
= (PTR
) bfd_alloc (abfd
, reloc_size
);
2348 bfd_release (abfd
, reloc_cache
);
2352 if (bfd_read (relocs
, 1, reloc_size
, abfd
) != reloc_size
)
2354 bfd_release (abfd
, relocs
);
2355 bfd_release (abfd
, reloc_cache
);
2356 bfd_error
= system_call_error
;
2360 cache_ptr
= reloc_cache
;
2361 if (each_size
== RELOC_EXT_SIZE
)
2363 register struct reloc_ext_external
*rptr
=
2364 (struct reloc_ext_external
*) relocs
;
2366 for (; counter
< count
; counter
++, rptr
++, cache_ptr
++)
2367 NAME(aout
,swap_ext_reloc_in
) (abfd
, rptr
, cache_ptr
, symbols
);
2371 register struct reloc_std_external
*rptr
2372 = (struct reloc_std_external
*) relocs
;
2374 for (; counter
< count
; counter
++, rptr
++, cache_ptr
++)
2375 NAME(aout
,swap_std_reloc_in
) (abfd
, rptr
, cache_ptr
, symbols
);
2378 if (dynrel_count
> 0)
2382 /* The dynamic symbols are at the end of the symbol table. */
2383 for (dynsyms
= symbols
;
2384 *dynsyms
!= NULL
&& ((*dynsyms
)->flags
& BSF_DYNAMIC
) == 0;
2388 /* Swap in the dynamic relocs. These relocs may be for either
2389 section, so we must discard ones we don't want. */
2391 if (each_size
== RELOC_EXT_SIZE
)
2393 register struct reloc_ext_external
*rptr
2394 = (struct reloc_ext_external
*) dynrels
;
2396 for (; counter
< dynrel_count
; counter
++, rptr
++, cache_ptr
++)
2398 NAME(aout
,swap_ext_reloc_in
) (abfd
, rptr
, cache_ptr
, dynsyms
);
2399 cache_ptr
->address
-= bfd_get_section_vma (abfd
, asect
);
2400 if (cache_ptr
->address
>= bfd_section_size (abfd
, asect
))
2406 register struct reloc_std_external
*rptr
2407 = (struct reloc_std_external
*) dynrels
;
2409 for (; counter
< dynrel_count
; counter
++, rptr
++, cache_ptr
++)
2411 NAME(aout
,swap_std_reloc_in
) (abfd
, rptr
, cache_ptr
, dynsyms
);
2412 cache_ptr
->address
-= bfd_get_section_vma (abfd
, asect
);
2413 if (cache_ptr
->address
>= bfd_section_size (abfd
, asect
))
2419 bfd_release (abfd
,relocs
);
2420 asect
->relocation
= reloc_cache
;
2421 asect
->reloc_count
= cache_ptr
- reloc_cache
;
2427 /* Write out a relocation section into an object file. */
2430 DEFUN(NAME(aout
,squirt_out_relocs
),(abfd
, section
),
2435 unsigned char *native
, *natptr
;
2438 unsigned int count
= section
->reloc_count
;
2441 if (count
== 0) return true;
2443 each_size
= obj_reloc_entry_size (abfd
);
2444 natsize
= each_size
* count
;
2445 native
= (unsigned char *) bfd_zalloc (abfd
, natsize
);
2447 bfd_error
= no_memory
;
2451 generic
= section
->orelocation
;
2453 if (each_size
== RELOC_EXT_SIZE
)
2455 for (natptr
= native
;
2457 --count
, natptr
+= each_size
, ++generic
)
2458 NAME(aout
,swap_ext_reloc_out
) (abfd
, *generic
, (struct reloc_ext_external
*)natptr
);
2462 for (natptr
= native
;
2464 --count
, natptr
+= each_size
, ++generic
)
2465 NAME(aout
,swap_std_reloc_out
)(abfd
, *generic
, (struct reloc_std_external
*)natptr
);
2468 if ( bfd_write ((PTR
) native
, 1, natsize
, abfd
) != natsize
) {
2469 bfd_release(abfd
, native
);
2472 bfd_release (abfd
, native
);
2477 /* This is stupid. This function should be a boolean predicate */
2479 DEFUN(NAME(aout
,canonicalize_reloc
),(abfd
, section
, relptr
, symbols
),
2482 arelent
**relptr AND
2485 arelent
*tblptr
= section
->relocation
;
2488 if (!(tblptr
|| NAME(aout
,slurp_reloc_table
)(abfd
, section
, symbols
)))
2491 if (section
->flags
& SEC_CONSTRUCTOR
) {
2492 arelent_chain
*chain
= section
->constructor_chain
;
2493 for (count
= 0; count
< section
->reloc_count
; count
++) {
2494 *relptr
++ = &chain
->relent
;
2495 chain
= chain
->next
;
2499 tblptr
= section
->relocation
;
2500 if (!tblptr
) return 0;
2502 for (count
= 0; count
++ < section
->reloc_count
;)
2504 *relptr
++ = tblptr
++;
2509 return section
->reloc_count
;
2513 DEFUN(NAME(aout
,get_reloc_upper_bound
),(abfd
, asect
),
2517 bfd_size_type dynrel_count
= 0;
2519 if (bfd_get_format (abfd
) != bfd_object
) {
2520 bfd_error
= invalid_operation
;
2523 if (asect
->flags
& SEC_CONSTRUCTOR
) {
2524 return (sizeof (arelent
*) * (asect
->reloc_count
+1));
2527 if ((bfd_get_file_flags (abfd
) & DYNAMIC
) != 0
2528 && aout_backend_info (abfd
)->read_dynamic_relocs
)
2532 dynrel_count
= ((*aout_backend_info (abfd
)->read_dynamic_relocs
)
2534 if (dynrel_count
== (bfd_size_type
) -1)
2538 if (asect
== obj_datasec (abfd
))
2539 return (sizeof (arelent
*) *
2540 ((exec_hdr(abfd
)->a_drsize
/ obj_reloc_entry_size (abfd
))
2541 + dynrel_count
+ 1));
2543 if (asect
== obj_textsec (abfd
))
2544 return (sizeof (arelent
*) *
2545 ((exec_hdr(abfd
)->a_trsize
/ obj_reloc_entry_size (abfd
))
2546 + dynrel_count
+ 1));
2548 bfd_error
= invalid_operation
;
2554 DEFUN(NAME(aout
,get_symtab_upper_bound
),(abfd
),
2557 if (!NAME(aout
,slurp_symbol_table
)(abfd
)) return 0;
2559 return (bfd_get_symcount (abfd
)+1) * (sizeof (aout_symbol_type
*));
2564 DEFUN(NAME(aout
,get_lineno
),(ignore_abfd
, ignore_symbol
),
2565 bfd
*ignore_abfd AND
2566 asymbol
*ignore_symbol
)
2568 return (alent
*)NULL
;
2573 DEFUN(NAME(aout
,get_symbol_info
),(ignore_abfd
, symbol
, ret
),
2574 bfd
*ignore_abfd AND
2578 bfd_symbol_info (symbol
, ret
);
2580 if (ret
->type
== '?')
2582 int type_code
= aout_symbol(symbol
)->type
& 0xff;
2583 CONST
char *stab_name
= aout_stab_name(type_code
);
2584 static char buf
[10];
2586 if (stab_name
== NULL
)
2588 sprintf(buf
, "(%d)", type_code
);
2592 ret
->stab_other
= (unsigned)(aout_symbol(symbol
)->other
& 0xff);
2593 ret
->stab_desc
= (unsigned)(aout_symbol(symbol
)->desc
& 0xffff);
2594 ret
->stab_name
= stab_name
;
2600 DEFUN(NAME(aout
,print_symbol
),(ignore_abfd
, afile
, symbol
, how
),
2601 bfd
*ignore_abfd AND
2604 bfd_print_symbol_type how
)
2606 FILE *file
= (FILE *)afile
;
2609 case bfd_print_symbol_name
:
2611 fprintf(file
,"%s", symbol
->name
);
2613 case bfd_print_symbol_more
:
2614 fprintf(file
,"%4x %2x %2x",(unsigned)(aout_symbol(symbol
)->desc
& 0xffff),
2615 (unsigned)(aout_symbol(symbol
)->other
& 0xff),
2616 (unsigned)(aout_symbol(symbol
)->type
));
2618 case bfd_print_symbol_all
:
2620 CONST
char *section_name
= symbol
->section
->name
;
2623 bfd_print_symbol_vandf((PTR
)file
,symbol
);
2625 fprintf(file
," %-5s %04x %02x %02x",
2627 (unsigned)(aout_symbol(symbol
)->desc
& 0xffff),
2628 (unsigned)(aout_symbol(symbol
)->other
& 0xff),
2629 (unsigned)(aout_symbol(symbol
)->type
& 0xff));
2631 fprintf(file
," %s", symbol
->name
);
2638 provided a BFD, a section and an offset into the section, calculate
2639 and return the name of the source file and the line nearest to the
2644 DEFUN(NAME(aout
,find_nearest_line
),(abfd
,
2652 asection
*section AND
2653 asymbol
**symbols AND
2655 CONST
char **filename_ptr AND
2656 CONST
char **functionname_ptr AND
2657 unsigned int *line_ptr
)
2659 /* Run down the file looking for the filename, function and linenumber */
2661 static char buffer
[100];
2662 static char filename_buffer
[200];
2663 CONST
char *directory_name
= NULL
;
2664 CONST
char *main_file_name
= NULL
;
2665 CONST
char *current_file_name
= NULL
;
2666 CONST
char *line_file_name
= NULL
; /* Value of current_file_name at line number. */
2667 bfd_vma high_line_vma
= ~0;
2668 bfd_vma low_func_vma
= 0;
2670 *filename_ptr
= abfd
->filename
;
2671 *functionname_ptr
= 0;
2673 if (symbols
!= (asymbol
**)NULL
) {
2674 for (p
= symbols
; *p
; p
++) {
2675 aout_symbol_type
*q
= (aout_symbol_type
*)(*p
);
2679 main_file_name
= current_file_name
= q
->symbol
.name
;
2680 /* Look ahead to next symbol to check if that too is an N_SO. */
2684 q
= (aout_symbol_type
*)(*p
);
2685 if (q
->type
!= (int)N_SO
)
2688 /* Found a second N_SO First is directory; second is filename. */
2689 directory_name
= current_file_name
;
2690 main_file_name
= current_file_name
= q
->symbol
.name
;
2691 if (obj_textsec(abfd
) != section
)
2695 current_file_name
= q
->symbol
.name
;
2702 /* We'll keep this if it resolves nearer than the one we have already */
2703 if (q
->symbol
.value
>= offset
&&
2704 q
->symbol
.value
< high_line_vma
) {
2705 *line_ptr
= q
->desc
;
2706 high_line_vma
= q
->symbol
.value
;
2707 line_file_name
= current_file_name
;
2712 /* We'll keep this if it is nearer than the one we have already */
2713 if (q
->symbol
.value
>= low_func_vma
&&
2714 q
->symbol
.value
<= offset
) {
2715 low_func_vma
= q
->symbol
.value
;
2716 func
= (asymbol
*)q
;
2718 if (*line_ptr
&& func
) {
2719 CONST
char *function
= func
->name
;
2721 strncpy(buffer
, function
, sizeof(buffer
)-1);
2722 buffer
[sizeof(buffer
)-1] = 0;
2723 /* Have to remove : stuff */
2724 p
= strchr(buffer
,':');
2725 if (p
!= NULL
) { *p
= '\0'; }
2726 *functionname_ptr
= buffer
;
2738 main_file_name
= line_file_name
;
2739 if (main_file_name
) {
2740 if (main_file_name
[0] == '/' || directory_name
== NULL
)
2741 *filename_ptr
= main_file_name
;
2743 sprintf(filename_buffer
, "%.140s%.50s",
2744 directory_name
, main_file_name
);
2745 *filename_ptr
= filename_buffer
;
2754 DEFUN(NAME(aout
,sizeof_headers
),(abfd
, execable
),
2758 return adata(abfd
).exec_bytes_size
;
2761 /* a.out link code. */
2763 /* a.out linker hash table entries. */
2765 struct aout_link_hash_entry
2767 struct bfd_link_hash_entry root
;
2768 /* Symbol index in output file. */
2772 /* a.out linker hash table. */
2774 struct aout_link_hash_table
2776 struct bfd_link_hash_table root
;
2779 static struct bfd_hash_entry
*aout_link_hash_newfunc
2780 PARAMS ((struct bfd_hash_entry
*entry
,
2781 struct bfd_hash_table
*table
,
2782 const char *string
));
2783 static boolean aout_link_add_object_symbols
2784 PARAMS ((bfd
*, struct bfd_link_info
*));
2785 static boolean aout_link_check_archive_element
2786 PARAMS ((bfd
*, struct bfd_link_info
*, boolean
*));
2787 static boolean aout_link_get_symbols
PARAMS ((bfd
*));
2788 static boolean aout_link_free_symbols
PARAMS ((bfd
*));
2789 static boolean aout_link_check_ar_symbols
2790 PARAMS ((bfd
*, struct bfd_link_info
*, boolean
*pneeded
));
2791 static boolean aout_link_add_symbols
2792 PARAMS ((bfd
*, struct bfd_link_info
*));
2794 /* Routine to create an entry in an a.out link hash table. */
2796 static struct bfd_hash_entry
*
2797 aout_link_hash_newfunc (entry
, table
, string
)
2798 struct bfd_hash_entry
*entry
;
2799 struct bfd_hash_table
*table
;
2802 struct aout_link_hash_entry
*ret
= (struct aout_link_hash_entry
*) entry
;
2804 /* Allocate the structure if it has not already been allocated by a
2806 if (ret
== (struct aout_link_hash_entry
*) NULL
)
2807 ret
= ((struct aout_link_hash_entry
*)
2808 bfd_hash_allocate (table
, sizeof (struct aout_link_hash_entry
)));
2810 /* Call the allocation method of the superclass. */
2811 ret
= ((struct aout_link_hash_entry
*)
2812 _bfd_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
2815 /* Set local fields. */
2818 return (struct bfd_hash_entry
*) ret
;
2821 /* Create an a.out link hash table. */
2823 struct bfd_link_hash_table
*
2824 NAME(aout
,link_hash_table_create
) (abfd
)
2827 struct aout_link_hash_table
*ret
;
2829 ret
= ((struct aout_link_hash_table
*)
2830 bfd_xmalloc (sizeof (struct aout_link_hash_table
)));
2831 if (! _bfd_link_hash_table_init (&ret
->root
, abfd
,
2832 aout_link_hash_newfunc
))
2835 return (struct bfd_link_hash_table
*) NULL
;
2840 /* Look up an entry in an a.out link hash table. */
2842 #define aout_link_hash_lookup(table, string, create, copy, follow) \
2843 ((struct aout_link_hash_entry *) \
2844 bfd_link_hash_lookup (&(table)->root, (string), (create), (copy), (follow)))
2846 /* Traverse an a.out link hash table. */
2848 #define aout_link_hash_traverse(table, func, info) \
2849 (bfd_link_hash_traverse \
2851 (boolean (*) PARAMS ((struct bfd_link_hash_entry *, PTR))) (func), \
2854 /* Get the a.out link hash table from the info structure. This is
2857 #define aout_hash_table(p) ((struct aout_link_hash_table *) ((p)->hash))
2859 /* Given an a.out BFD, add symbols to the global hash table as
2863 NAME(aout
,link_add_symbols
) (abfd
, info
)
2865 struct bfd_link_info
*info
;
2867 switch (bfd_get_format (abfd
))
2870 return aout_link_add_object_symbols (abfd
, info
);
2872 return _bfd_generic_link_add_archive_symbols
2873 (abfd
, info
, aout_link_check_archive_element
);
2875 bfd_error
= wrong_format
;
2880 /* Add symbols from an a.out object file. */
2883 aout_link_add_object_symbols (abfd
, info
)
2885 struct bfd_link_info
*info
;
2887 if (! aout_link_get_symbols (abfd
))
2889 if (! aout_link_add_symbols (abfd
, info
))
2891 if (! info
->keep_memory
)
2893 if (! aout_link_free_symbols (abfd
))
2899 /* Check a single archive element to see if we need to include it in
2900 the link. *PNEEDED is set according to whether this element is
2901 needed in the link or not. This is called from
2902 _bfd_generic_link_add_archive_symbols. */
2905 aout_link_check_archive_element (abfd
, info
, pneeded
)
2907 struct bfd_link_info
*info
;
2910 if (! aout_link_get_symbols (abfd
))
2913 if (! aout_link_check_ar_symbols (abfd
, info
, pneeded
))
2918 if (! aout_link_add_symbols (abfd
, info
))
2922 /* We keep around the symbols even if we aren't going to use this
2923 object file, because we may want to reread it. This doesn't
2924 waste too much memory, because it isn't all that common to read
2925 an archive element but not need it. */
2926 if (! info
->keep_memory
)
2928 if (! aout_link_free_symbols (abfd
))
2935 /* Read the internal symbols from an a.out file. */
2938 aout_link_get_symbols (abfd
)
2941 bfd_size_type count
;
2942 struct external_nlist
*syms
;
2943 unsigned char string_chars
[BYTES_IN_WORD
];
2944 bfd_size_type stringsize
;
2947 if (obj_aout_external_syms (abfd
) != (struct external_nlist
*) NULL
)
2949 /* We already have them. */
2953 count
= exec_hdr (abfd
)->a_syms
/ EXTERNAL_NLIST_SIZE
;
2955 /* We allocate using bfd_xmalloc to make the values easy to free
2956 later on. If we put them on the obstack it might not be possible
2958 syms
= ((struct external_nlist
*)
2959 bfd_xmalloc ((size_t) count
* EXTERNAL_NLIST_SIZE
));
2961 if (bfd_seek (abfd
, obj_sym_filepos (abfd
), SEEK_SET
) != 0
2962 || (bfd_read ((PTR
) syms
, 1, exec_hdr (abfd
)->a_syms
, abfd
)
2963 != exec_hdr (abfd
)->a_syms
))
2966 /* Get the size of the strings. */
2967 if (bfd_seek (abfd
, obj_str_filepos (abfd
), SEEK_SET
) != 0
2968 || (bfd_read ((PTR
) string_chars
, BYTES_IN_WORD
, 1, abfd
)
2971 stringsize
= GET_WORD (abfd
, string_chars
);
2972 strings
= (char *) bfd_xmalloc ((size_t) stringsize
);
2974 /* Skip space for the string count in the buffer for convenience
2975 when using indexes. */
2976 if (bfd_read (strings
+ BYTES_IN_WORD
, 1, stringsize
- BYTES_IN_WORD
, abfd
)
2977 != stringsize
- BYTES_IN_WORD
)
2980 /* Save the data. */
2981 obj_aout_external_syms (abfd
) = syms
;
2982 obj_aout_external_sym_count (abfd
) = count
;
2983 obj_aout_external_strings (abfd
) = strings
;
2988 /* Free up the internal symbols read from an a.out file. */
2991 aout_link_free_symbols (abfd
)
2994 if (obj_aout_external_syms (abfd
) != (struct external_nlist
*) NULL
)
2996 free ((PTR
) obj_aout_external_syms (abfd
));
2997 obj_aout_external_syms (abfd
) = (struct external_nlist
*) NULL
;
2999 if (obj_aout_external_strings (abfd
) != (char *) NULL
)
3001 free ((PTR
) obj_aout_external_strings (abfd
));
3002 obj_aout_external_strings (abfd
) = (char *) NULL
;
3007 /* Look through the internal symbols to see if this object file should
3008 be included in the link. We should include this object file if it
3009 defines any symbols which are currently undefined. If this object
3010 file defines a common symbol, then we may adjust the size of the
3011 known symbol but we do not include the object file in the link
3012 (unless there is some other reason to include it). */
3015 aout_link_check_ar_symbols (abfd
, info
, pneeded
)
3017 struct bfd_link_info
*info
;
3020 register struct external_nlist
*p
;
3021 struct external_nlist
*pend
;
3026 /* Look through all the symbols. */
3027 p
= obj_aout_external_syms (abfd
);
3028 pend
= p
+ obj_aout_external_sym_count (abfd
);
3029 strings
= obj_aout_external_strings (abfd
);
3030 for (; p
< pend
; p
++)
3032 int type
= bfd_h_get_8 (abfd
, p
->e_type
);
3034 struct bfd_link_hash_entry
*h
;
3036 /* Ignore symbols that are not externally visible. */
3037 if ((type
& N_EXT
) == 0)
3040 name
= strings
+ GET_WORD (abfd
, p
->e_strx
);
3041 h
= bfd_link_hash_lookup (info
->hash
, name
, false, false, true);
3043 /* We are only interested in symbols that are currently
3044 undefined or common. */
3045 if (h
== (struct bfd_link_hash_entry
*) NULL
3046 || (h
->type
!= bfd_link_hash_undefined
3047 && h
->type
!= bfd_link_hash_common
))
3050 if ((type
& (N_TEXT
| N_DATA
| N_BSS
)) != 0)
3052 /* This object file defines this symbol. We must link it
3053 in. This is true regardless of whether the current
3054 definition of the symbol is undefined or common. If the
3055 current definition is common, we have a case in which we
3056 have already seen an object file including
3058 and this object file from the archive includes
3060 In such a case we must include this object file. */
3061 if (! (*info
->callbacks
->add_archive_element
) (info
, abfd
, name
))
3067 if (type
== (N_EXT
| N_UNDF
))
3071 value
= GET_WORD (abfd
, p
->e_value
);
3074 /* This symbol is common in the object from the archive
3076 if (h
->type
== bfd_link_hash_undefined
)
3080 symbfd
= h
->u
.undef
.abfd
;
3081 if (symbfd
== (bfd
*) NULL
)
3083 /* This symbol was created as undefined from
3084 outside BFD. We assume that we should link
3085 in the object file. This is done for the -u
3086 option in the linker. */
3087 if (! (*info
->callbacks
->add_archive_element
) (info
,
3094 /* Turn the current link symbol into a common
3095 symbol. It is already on the undefs list. */
3096 h
->type
= bfd_link_hash_common
;
3097 h
->u
.c
.size
= value
;
3098 h
->u
.c
.section
= bfd_make_section_old_way (symbfd
,
3103 /* Adjust the size of the common symbol if
3105 if (value
> h
->u
.c
.size
)
3106 h
->u
.c
.size
= value
;
3112 /* We do not need this object file. */
3116 /* Add all symbols from an object file to the hash table. */
3119 aout_link_add_symbols (abfd
, info
)
3121 struct bfd_link_info
*info
;
3123 bfd_size_type sym_count
;
3126 struct aout_link_hash_entry
**sym_hash
;
3127 register struct external_nlist
*p
;
3128 struct external_nlist
*pend
;
3130 sym_count
= obj_aout_external_sym_count (abfd
);
3131 strings
= obj_aout_external_strings (abfd
);
3132 if (info
->keep_memory
)
3137 /* We keep a list of the linker hash table entries that correspond
3138 to particular symbols. We could just look them up in the hash
3139 table, but keeping the list is more efficient. Perhaps this
3140 should be conditional on info->keep_memory. */
3141 sym_hash
= ((struct aout_link_hash_entry
**)
3144 * sizeof (struct aout_link_hash_entry
*))));
3145 obj_aout_sym_hashes (abfd
) = sym_hash
;
3147 p
= obj_aout_external_syms (abfd
);
3148 pend
= p
+ sym_count
;
3149 for (; p
< pend
; p
++, sym_hash
++)
3160 type
= bfd_h_get_8 (abfd
, p
->e_type
);
3162 /* Ignore debugging symbols. */
3163 if ((type
& N_STAB
) != 0)
3166 /* Ignore symbols that are not external. */
3167 if ((type
& N_EXT
) == 0
3168 && type
!= N_WARNING
3174 /* If this is an N_INDR symbol we must skip the next entry,
3175 which is the symbol to indirect to (actually, an N_INDR
3176 symbol without N_EXT set is pretty useless). */
3185 /* Ignore N_FN symbols (these appear to have N_EXT set). */
3189 name
= strings
+ GET_WORD (abfd
, p
->e_strx
);
3190 value
= GET_WORD (abfd
, p
->e_value
);
3197 case N_UNDF
| N_EXT
:
3199 section
= &bfd_com_section
;
3201 section
= &bfd_und_section
;
3204 section
= &bfd_abs_section
;
3206 case N_TEXT
| N_EXT
:
3207 section
= obj_textsec (abfd
);
3208 value
-= bfd_get_section_vma (abfd
, section
);
3210 case N_DATA
| N_EXT
:
3211 section
= obj_datasec (abfd
);
3212 value
-= bfd_get_section_vma (abfd
, section
);
3215 section
= obj_bsssec (abfd
);
3216 value
-= bfd_get_section_vma (abfd
, section
);
3218 case N_INDR
| N_EXT
:
3219 /* An indirect symbol. The next symbol is the symbol
3220 which this one really is. */
3221 BFD_ASSERT (p
+ 1 < pend
);
3223 string
= strings
+ GET_WORD (abfd
, p
->e_strx
);
3224 section
= &bfd_ind_section
;
3225 flags
|= BSF_INDIRECT
;
3227 case N_COMM
| N_EXT
:
3228 section
= &bfd_com_section
;
3230 case N_SETA
: case N_SETA
| N_EXT
:
3231 section
= &bfd_abs_section
;
3232 flags
|= BSF_CONSTRUCTOR
;
3234 case N_SETT
: case N_SETT
| N_EXT
:
3235 section
= obj_textsec (abfd
);
3236 flags
|= BSF_CONSTRUCTOR
;
3237 value
-= bfd_get_section_vma (abfd
, section
);
3239 case N_SETD
: case N_SETD
| N_EXT
:
3240 section
= obj_datasec (abfd
);
3241 flags
|= BSF_CONSTRUCTOR
;
3242 value
-= bfd_get_section_vma (abfd
, section
);
3244 case N_SETB
: case N_SETB
| N_EXT
:
3245 section
= obj_bsssec (abfd
);
3246 flags
|= BSF_CONSTRUCTOR
;
3247 value
-= bfd_get_section_vma (abfd
, section
);
3250 /* A warning symbol. The next symbol is the one to warn
3252 BFD_ASSERT (p
+ 1 < pend
);
3255 name
= strings
+ GET_WORD (abfd
, p
->e_strx
);
3256 section
= &bfd_und_section
;
3257 flags
|= BSF_WARNING
;
3261 if (! (_bfd_generic_link_add_one_symbol
3262 (info
, abfd
, name
, flags
, section
, value
, string
, copy
, false,
3263 ARCH_SIZE
, (struct bfd_link_hash_entry
**) sym_hash
)))
3266 if (type
== (N_INDR
| N_EXT
) || type
== N_WARNING
)
3273 /* During the final link step we need to pass around a bunch of
3274 information, so we do it in an instance of this structure. */
3276 struct aout_final_link_info
3278 /* General link information. */
3279 struct bfd_link_info
*info
;
3282 /* Reloc file positions. */
3283 file_ptr treloff
, dreloff
;
3284 /* File position of symbols. */
3287 struct stringtab_data strtab
;
3290 static boolean aout_link_input_bfd
3291 PARAMS ((struct aout_final_link_info
*, bfd
*input_bfd
));
3292 static boolean aout_link_write_symbols
3293 PARAMS ((struct aout_final_link_info
*, bfd
*input_bfd
, int *symbol_map
));
3294 static boolean aout_link_write_other_symbol
3295 PARAMS ((struct aout_link_hash_entry
*, PTR
));
3296 static boolean aout_link_input_section
3297 PARAMS ((struct aout_final_link_info
*, bfd
*input_bfd
,
3298 asection
*input_section
, file_ptr
*reloff_ptr
,
3299 bfd_size_type rel_size
, int *symbol_map
));
3300 static boolean aout_link_input_section_std
3301 PARAMS ((struct aout_final_link_info
*, bfd
*input_bfd
,
3302 asection
*input_section
, struct reloc_std_external
*,
3303 bfd_size_type rel_size
, bfd_byte
*contents
, int *symbol_map
));
3304 static boolean aout_link_input_section_ext
3305 PARAMS ((struct aout_final_link_info
*, bfd
*input_bfd
,
3306 asection
*input_section
, struct reloc_ext_external
*,
3307 bfd_size_type rel_size
, bfd_byte
*contents
, int *symbol_map
));
3308 static INLINE asection
*aout_reloc_index_to_section
3309 PARAMS ((bfd
*, int));
3311 /* Do the final link step. This is called on the output BFD. The
3312 INFO structure should point to a list of BFDs linked through the
3313 link_next field which can be used to find each BFD which takes part
3314 in the output. Also, each section in ABFD should point to a list
3315 of bfd_link_order structures which list all the input sections for
3316 the output section. */
3319 NAME(aout
,final_link
) (abfd
, info
, callback
)
3321 struct bfd_link_info
*info
;
3322 void (*callback
) PARAMS ((bfd
*, file_ptr
*, file_ptr
*, file_ptr
*));
3324 struct aout_final_link_info aout_info
;
3326 bfd_size_type text_size
;
3328 register struct bfd_link_order
*p
;
3331 aout_info
.info
= info
;
3332 aout_info
.output_bfd
= abfd
;
3334 if (! info
->relocateable
)
3336 exec_hdr (abfd
)->a_trsize
= 0;
3337 exec_hdr (abfd
)->a_drsize
= 0;
3341 bfd_size_type trsize
, drsize
;
3343 /* Count up the relocation sizes. */
3346 for (sub
= info
->input_bfds
; sub
!= (bfd
*) NULL
; sub
= sub
->link_next
)
3348 if (bfd_get_flavour (abfd
) == bfd_target_aout_flavour
)
3350 trsize
+= exec_hdr (sub
)->a_trsize
;
3351 drsize
+= exec_hdr (sub
)->a_drsize
;
3355 /* FIXME: We need to identify the .text and .data sections
3356 and call get_reloc_upper_bound and canonicalize_reloc to
3357 work out the number of relocs needed, and then multiply
3358 by the reloc size. */
3362 exec_hdr (abfd
)->a_trsize
= trsize
;
3363 exec_hdr (abfd
)->a_drsize
= drsize
;
3366 exec_hdr (abfd
)->a_entry
= bfd_get_start_address (abfd
);
3368 /* Adjust the section sizes and vmas according to the magic number.
3369 This sets a_text, a_data and a_bss in the exec_hdr and sets the
3370 filepos for each section. */
3371 if (! NAME(aout
,adjust_sizes_and_vmas
) (abfd
, &text_size
, &text_end
))
3374 /* The relocation and symbol file positions differ among a.out
3375 targets. We are passed a callback routine from the backend
3376 specific code to handle this.
3377 FIXME: At this point we do not know how much space the symbol
3378 table will require. This will not work for any (nonstandard)
3379 a.out target that needs to know the symbol table size before it
3380 can compute the relocation file positions. This may or may not
3381 be the case for the hp300hpux target, for example. */
3382 (*callback
) (abfd
, &aout_info
.treloff
, &aout_info
.dreloff
,
3384 obj_textsec (abfd
)->rel_filepos
= aout_info
.treloff
;
3385 obj_datasec (abfd
)->rel_filepos
= aout_info
.dreloff
;
3386 obj_sym_filepos (abfd
) = aout_info
.symoff
;
3388 /* We keep a count of the symbols as we output them. */
3389 obj_aout_external_sym_count (abfd
) = 0;
3391 /* We accumulate the string table as we write out the symbols. */
3392 stringtab_init (&aout_info
.strtab
);
3394 /* The most time efficient way to do the link would be to read all
3395 the input object files into memory and then sort out the
3396 information into the output file. Unfortunately, that will
3397 probably use too much memory. Another method would be to step
3398 through everything that composes the text section and write it
3399 out, and then everything that composes the data section and write
3400 it out, and then write out the relocs, and then write out the
3401 symbols. Unfortunately, that requires reading stuff from each
3402 input file several times, and we will not be able to keep all the
3403 input files open simultaneously, and reopening them will be slow.
3405 What we do is basically process one input file at a time. We do
3406 everything we need to do with an input file once--copy over the
3407 section contents, handle the relocation information, and write
3408 out the symbols--and then we throw away the information we read
3409 from it. This approach requires a lot of lseeks of the output
3410 file, which is unfortunate but still faster than reopening a lot
3413 We use the output_has_begun field of the input BFDs to see
3414 whether we have already handled it. */
3415 for (sub
= info
->input_bfds
; sub
!= (bfd
*) NULL
; sub
= sub
->link_next
)
3416 sub
->output_has_begun
= false;
3418 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
3420 for (p
= o
->link_order_head
;
3421 p
!= (struct bfd_link_order
*) NULL
;
3424 /* If we might be using the C based alloca function, we need
3425 to dump the memory allocated by aout_link_input_bfd. */
3431 if (p
->type
== bfd_indirect_link_order
3432 && (bfd_get_flavour (p
->u
.indirect
.section
->owner
)
3433 == bfd_target_aout_flavour
))
3437 input_bfd
= p
->u
.indirect
.section
->owner
;
3438 if (! input_bfd
->output_has_begun
)
3440 if (! aout_link_input_bfd (&aout_info
, input_bfd
))
3442 input_bfd
->output_has_begun
= true;
3447 if (! _bfd_default_link_order (abfd
, info
, o
, p
))
3453 /* Write out any symbols that we have not already written out. */
3454 aout_link_hash_traverse (aout_hash_table (info
),
3455 aout_link_write_other_symbol
,
3458 /* Update the header information. */
3459 abfd
->symcount
= obj_aout_external_sym_count (abfd
);
3460 exec_hdr (abfd
)->a_syms
= abfd
->symcount
* EXTERNAL_NLIST_SIZE
;
3461 obj_str_filepos (abfd
) = obj_sym_filepos (abfd
) + exec_hdr (abfd
)->a_syms
;
3462 obj_textsec (abfd
)->reloc_count
=
3463 exec_hdr (abfd
)->a_trsize
/ obj_reloc_entry_size (abfd
);
3464 obj_datasec (abfd
)->reloc_count
=
3465 exec_hdr (abfd
)->a_drsize
/ obj_reloc_entry_size (abfd
);
3467 /* Write out the string table. */
3468 if (bfd_seek (abfd
, obj_str_filepos (abfd
), SEEK_SET
) != 0)
3470 emit_strtab (abfd
, &aout_info
.strtab
);
3475 /* Link an a.out input BFD into the output file. */
3478 aout_link_input_bfd (finfo
, input_bfd
)
3479 struct aout_final_link_info
*finfo
;
3482 bfd_size_type sym_count
;
3485 BFD_ASSERT (bfd_get_format (input_bfd
) == bfd_object
);
3487 /* Get the symbols. We probably have them already, unless
3488 finfo->info->keep_memory is false. */
3489 if (! aout_link_get_symbols (input_bfd
))
3492 sym_count
= obj_aout_external_sym_count (input_bfd
);
3493 symbol_map
= (int *) alloca ((size_t) sym_count
* sizeof (int));
3495 /* Write out the symbols and get a map of the new indices. */
3496 if (! aout_link_write_symbols (finfo
, input_bfd
, symbol_map
))
3499 /* Relocate and write out the sections. */
3500 if (! aout_link_input_section (finfo
, input_bfd
,
3501 obj_textsec (input_bfd
),
3503 exec_hdr (input_bfd
)->a_trsize
,
3505 || ! aout_link_input_section (finfo
, input_bfd
,
3506 obj_datasec (input_bfd
),
3508 exec_hdr (input_bfd
)->a_drsize
,
3512 /* If we are not keeping memory, we don't need the symbols any
3513 longer. We still need them if we are keeping memory, because the
3514 strings in the hash table point into them. */
3515 if (! finfo
->info
->keep_memory
)
3517 if (! aout_link_free_symbols (input_bfd
))
3524 /* Adjust and write out the symbols for an a.out file. Set the new
3525 symbol indices into a symbol_map. */
3528 aout_link_write_symbols (finfo
, input_bfd
, symbol_map
)
3529 struct aout_final_link_info
*finfo
;
3534 bfd_size_type sym_count
;
3536 enum bfd_link_strip strip
;
3537 enum bfd_link_discard discard
;
3538 struct external_nlist
*output_syms
;
3539 struct external_nlist
*outsym
;
3540 register struct external_nlist
*sym
;
3541 struct external_nlist
*sym_end
;
3542 struct aout_link_hash_entry
**sym_hash
;
3544 boolean skip_indirect
;
3546 output_bfd
= finfo
->output_bfd
;
3547 sym_count
= obj_aout_external_sym_count (input_bfd
);
3548 strings
= obj_aout_external_strings (input_bfd
);
3549 strip
= finfo
->info
->strip
;
3550 discard
= finfo
->info
->discard
;
3551 output_syms
= ((struct external_nlist
*)
3552 alloca ((size_t) (sym_count
+ 1) * EXTERNAL_NLIST_SIZE
));
3553 outsym
= output_syms
;
3555 /* First write out a symbol for this object file, unless we are
3556 discarding such symbols. */
3557 if (strip
!= strip_all
3558 && (strip
!= strip_some
3559 || bfd_hash_lookup (finfo
->info
->keep_hash
, input_bfd
->filename
,
3560 false, false) != NULL
)
3561 && discard
!= discard_all
)
3563 bfd_h_put_8 (output_bfd
, N_TEXT
, outsym
->e_type
);
3564 bfd_h_put_8 (output_bfd
, 0, outsym
->e_other
);
3565 bfd_h_put_16 (output_bfd
, (bfd_vma
) 0, outsym
->e_desc
);
3566 PUT_WORD (output_bfd
,
3567 add_to_stringtab (output_bfd
, input_bfd
->filename
,
3570 PUT_WORD (output_bfd
,
3571 (bfd_get_section_vma (output_bfd
,
3572 obj_textsec (input_bfd
)->output_section
)
3573 + obj_textsec (input_bfd
)->output_offset
),
3575 ++obj_aout_external_sym_count (output_bfd
);
3580 skip_indirect
= false;
3581 sym
= obj_aout_external_syms (input_bfd
);
3582 sym_end
= sym
+ sym_count
;
3583 sym_hash
= obj_aout_sym_hashes (input_bfd
);
3584 for (; sym
< sym_end
; sym
++, sym_hash
++, symbol_map
++)
3594 type
= bfd_h_get_8 (input_bfd
, sym
->e_type
);
3595 name
= strings
+ GET_WORD (input_bfd
, sym
->e_strx
);
3599 /* Pass this symbol through. It is the target of an
3600 indirect or warning symbol. */
3601 val
= GET_WORD (input_bfd
, sym
->e_value
);
3604 else if (skip_indirect
)
3606 /* Skip this symbol, which is the target of an indirect
3607 symbol that we have changed to no longer be an indirect
3609 skip_indirect
= false;
3614 struct aout_link_hash_entry
*h
;
3615 struct aout_link_hash_entry
*hresolve
;
3617 /* We have saved the hash table entry for this symbol, if
3618 there is one. Note that we could just look it up again
3619 in the hash table, provided we first check that it is an
3623 /* If this is an indirect or warning symbol, then change
3624 hresolve to the base symbol. We also change *sym_hash so
3625 that the relocation routines relocate against the real
3628 if (h
!= (struct aout_link_hash_entry
*) NULL
3629 && (h
->root
.type
== bfd_link_hash_indirect
3630 || h
->root
.type
== bfd_link_hash_warning
))
3632 hresolve
= (struct aout_link_hash_entry
*) h
->root
.u
.i
.link
;
3633 while (hresolve
->root
.type
== bfd_link_hash_indirect
)
3634 hresolve
= ((struct aout_link_hash_entry
*)
3635 hresolve
->root
.u
.i
.link
);
3636 *sym_hash
= hresolve
;
3639 /* If the symbol has already been written out, skip it. */
3640 if (h
!= (struct aout_link_hash_entry
*) NULL
3643 *symbol_map
= h
->indx
;
3647 /* See if we are stripping this symbol. */
3653 case strip_debugger
:
3654 if ((type
& N_STAB
) != 0)
3658 if (bfd_hash_lookup (finfo
->info
->keep_hash
, name
, false, false)
3668 if (h
!= (struct aout_link_hash_entry
*) NULL
)
3669 h
->root
.written
= true;
3673 /* Get the value of the symbol. */
3674 if ((type
& N_TYPE
) == N_TEXT
)
3675 symsec
= obj_textsec (input_bfd
);
3676 else if ((type
& N_TYPE
) == N_DATA
)
3677 symsec
= obj_datasec (input_bfd
);
3678 else if ((type
& N_TYPE
) == N_BSS
)
3679 symsec
= obj_bsssec (input_bfd
);
3680 else if ((type
& N_TYPE
) == N_ABS
)
3681 symsec
= &bfd_abs_section
;
3682 else if (((type
& N_TYPE
) == N_INDR
3683 && (hresolve
== (struct aout_link_hash_entry
*) NULL
3684 || (hresolve
->root
.type
!= bfd_link_hash_defined
3685 && hresolve
->root
.type
!= bfd_link_hash_common
)))
3686 || type
== N_WARNING
)
3688 /* Pass the next symbol through unchanged. The
3689 condition above for indirect symbols is so that if
3690 the indirect symbol was defined, we output it with
3691 the correct definition so the debugger will
3694 val
= GET_WORD (input_bfd
, sym
->e_value
);
3697 else if ((type
& N_STAB
) != 0)
3699 val
= GET_WORD (input_bfd
, sym
->e_value
);
3704 /* If we get here with an indirect symbol, it means that
3705 we are outputting it with a real definition. In such
3706 a case we do not want to output the next symbol,
3707 which is the target of the indirection. */
3708 if ((type
& N_TYPE
) == N_INDR
)
3709 skip_indirect
= true;
3711 /* We need to get the value from the hash table. We use
3712 hresolve so that if we have defined an indirect
3713 symbol we output the final definition. */
3714 if (h
== (struct aout_link_hash_entry
*) NULL
)
3716 else if (hresolve
->root
.type
== bfd_link_hash_defined
)
3718 asection
*input_section
;
3719 asection
*output_section
;
3721 /* This case means a common symbol which was turned
3722 into a defined symbol. */
3723 input_section
= hresolve
->root
.u
.def
.section
;
3724 output_section
= input_section
->output_section
;
3725 BFD_ASSERT (output_section
== &bfd_abs_section
3726 || output_section
->owner
== output_bfd
);
3727 val
= (hresolve
->root
.u
.def
.value
3728 + bfd_get_section_vma (output_bfd
, output_section
)
3729 + input_section
->output_offset
);
3731 /* Get the correct type based on the section. If
3732 this is a constructed set, force it to be
3733 globally visible. */
3742 if (output_section
== obj_textsec (output_bfd
))
3744 else if (output_section
== obj_datasec (output_bfd
))
3746 else if (output_section
== obj_bsssec (output_bfd
))
3751 else if (hresolve
->root
.type
== bfd_link_hash_common
)
3752 val
= hresolve
->root
.u
.c
.size
;
3758 if (symsec
!= (asection
*) NULL
)
3759 val
= (symsec
->output_section
->vma
3760 + symsec
->output_offset
3761 + (GET_WORD (input_bfd
, sym
->e_value
)
3764 /* If this is a global symbol set the written flag, and if
3765 it is a local symbol see if we should discard it. */
3766 if (h
!= (struct aout_link_hash_entry
*) NULL
)
3768 h
->root
.written
= true;
3769 h
->indx
= obj_aout_external_sym_count (output_bfd
);
3778 if (*name
== *finfo
->info
->lprefix
3779 && (finfo
->info
->lprefix_len
== 1
3780 || strncmp (name
, finfo
->info
->lprefix
,
3781 finfo
->info
->lprefix_len
) == 0))
3796 /* Copy this symbol into the list of symbols we are going to
3798 bfd_h_put_8 (output_bfd
, type
, outsym
->e_type
);
3799 bfd_h_put_8 (output_bfd
, bfd_h_get_8 (input_bfd
, sym
->e_other
),
3801 bfd_h_put_16 (output_bfd
, bfd_h_get_16 (input_bfd
, sym
->e_desc
),
3803 PUT_WORD (output_bfd
,
3804 add_to_stringtab (output_bfd
, name
, &finfo
->strtab
),
3806 PUT_WORD (output_bfd
, val
, outsym
->e_value
);
3807 *symbol_map
= obj_aout_external_sym_count (output_bfd
);
3808 ++obj_aout_external_sym_count (output_bfd
);
3812 /* Write out the output symbols we have just constructed. */
3813 if (outsym
> output_syms
)
3815 bfd_size_type outsym_count
;
3817 if (bfd_seek (output_bfd
, finfo
->symoff
, SEEK_SET
) != 0)
3819 outsym_count
= outsym
- output_syms
;
3820 if (bfd_write ((PTR
) output_syms
, (bfd_size_type
) EXTERNAL_NLIST_SIZE
,
3821 (bfd_size_type
) outsym_count
, output_bfd
)
3822 != outsym_count
* EXTERNAL_NLIST_SIZE
)
3824 finfo
->symoff
+= outsym_count
* EXTERNAL_NLIST_SIZE
;
3830 /* Write out a symbol that was not associated with an a.out input
3834 aout_link_write_other_symbol (h
, data
)
3835 struct aout_link_hash_entry
*h
;
3838 struct aout_final_link_info
*finfo
= (struct aout_final_link_info
*) data
;
3842 struct external_nlist outsym
;
3844 if (h
->root
.written
)
3847 output_bfd
= finfo
->output_bfd
;
3849 switch (h
->root
.type
)
3852 case bfd_link_hash_new
:
3854 /* Avoid variable not initialized warnings. */
3856 case bfd_link_hash_undefined
:
3857 type
= N_UNDF
| N_EXT
;
3860 case bfd_link_hash_defined
:
3864 sec
= h
->root
.u
.def
.section
;
3865 BFD_ASSERT (sec
== &bfd_abs_section
3866 || sec
->owner
== output_bfd
);
3867 if (sec
== obj_textsec (output_bfd
))
3868 type
= N_TEXT
| N_EXT
;
3869 else if (sec
== obj_datasec (output_bfd
))
3870 type
= N_DATA
| N_EXT
;
3871 else if (sec
== obj_bsssec (output_bfd
))
3872 type
= N_BSS
| N_EXT
;
3874 type
= N_ABS
| N_EXT
;
3875 val
= (h
->root
.u
.def
.value
3876 + sec
->output_section
->vma
3877 + sec
->output_offset
);
3880 case bfd_link_hash_common
:
3881 type
= N_UNDF
| N_EXT
;
3882 val
= h
->root
.u
.c
.size
;
3884 case bfd_link_hash_indirect
:
3885 case bfd_link_hash_warning
:
3886 /* FIXME: Ignore these for now. The circumstances under which
3887 they should be written out are not clear to me. */
3891 bfd_h_put_8 (output_bfd
, type
, outsym
.e_type
);
3892 bfd_h_put_8 (output_bfd
, 0, outsym
.e_other
);
3893 bfd_h_put_16 (output_bfd
, 0, outsym
.e_desc
);
3894 PUT_WORD (output_bfd
,
3895 add_to_stringtab (output_bfd
, h
->root
.root
.string
, &finfo
->strtab
),
3897 PUT_WORD (output_bfd
, val
, outsym
.e_value
);
3899 if (bfd_seek (output_bfd
, finfo
->symoff
, SEEK_SET
) != 0
3900 || bfd_write ((PTR
) &outsym
, (bfd_size_type
) EXTERNAL_NLIST_SIZE
,
3901 (bfd_size_type
) 1, output_bfd
) != EXTERNAL_NLIST_SIZE
)
3903 /* FIXME: No way to handle errors. */
3907 finfo
->symoff
+= EXTERNAL_NLIST_SIZE
;
3908 h
->indx
= obj_aout_external_sym_count (output_bfd
);
3909 ++obj_aout_external_sym_count (output_bfd
);
3914 /* Link an a.out section into the output file. */
3917 aout_link_input_section (finfo
, input_bfd
, input_section
, reloff_ptr
,
3918 rel_size
, symbol_map
)
3919 struct aout_final_link_info
*finfo
;
3921 asection
*input_section
;
3922 file_ptr
*reloff_ptr
;
3923 bfd_size_type rel_size
;
3926 bfd_size_type input_size
;
3930 /* Get the section contents. */
3931 input_size
= bfd_section_size (input_bfd
, input_section
);
3932 contents
= (bfd_byte
*) alloca (input_size
);
3933 if (! bfd_get_section_contents (input_bfd
, input_section
, (PTR
) contents
,
3934 (file_ptr
) 0, input_size
))
3937 /* Read in the relocs. */
3938 relocs
= (PTR
) alloca (rel_size
);
3939 if (bfd_seek (input_bfd
, input_section
->rel_filepos
, SEEK_SET
) != 0
3940 || bfd_read (relocs
, 1, rel_size
, input_bfd
) != rel_size
)
3943 /* Relocate the section contents. */
3944 if (obj_reloc_entry_size (input_bfd
) == RELOC_STD_SIZE
)
3946 if (! aout_link_input_section_std (finfo
, input_bfd
, input_section
,
3947 (struct reloc_std_external
*) relocs
,
3948 rel_size
, contents
, symbol_map
))
3953 if (! aout_link_input_section_ext (finfo
, input_bfd
, input_section
,
3954 (struct reloc_ext_external
*) relocs
,
3955 rel_size
, contents
, symbol_map
))
3959 /* Write out the section contents. */
3960 if (! bfd_set_section_contents (finfo
->output_bfd
,
3961 input_section
->output_section
,
3963 input_section
->output_offset
,
3967 /* If we are producing relocateable output, the relocs were
3968 modified, and we now write them out. */
3969 if (finfo
->info
->relocateable
)
3971 if (bfd_seek (finfo
->output_bfd
, *reloff_ptr
, SEEK_SET
) != 0)
3973 if (bfd_write (relocs
, (bfd_size_type
) 1, rel_size
, finfo
->output_bfd
)
3976 *reloff_ptr
+= rel_size
;
3978 /* Assert that the relocs have not run into the symbols, and
3979 that if these are the text relocs they have not run into the
3981 BFD_ASSERT (*reloff_ptr
<= obj_sym_filepos (finfo
->output_bfd
)
3982 && (reloff_ptr
!= &finfo
->treloff
3984 <= obj_datasec (finfo
->output_bfd
)->rel_filepos
)));
3990 /* Get the section corresponding to a reloc index. */
3992 static INLINE asection
*
3993 aout_reloc_index_to_section (abfd
, indx
)
3997 switch (indx
& N_TYPE
)
4000 return obj_textsec (abfd
);
4002 return obj_datasec (abfd
);
4004 return obj_bsssec (abfd
);
4007 return &bfd_abs_section
;
4013 /* Relocate an a.out section using standard a.out relocs. */
4016 aout_link_input_section_std (finfo
, input_bfd
, input_section
, relocs
,
4017 rel_size
, contents
, symbol_map
)
4018 struct aout_final_link_info
*finfo
;
4020 asection
*input_section
;
4021 struct reloc_std_external
*relocs
;
4022 bfd_size_type rel_size
;
4027 boolean relocateable
;
4028 struct external_nlist
*syms
;
4030 struct aout_link_hash_entry
**sym_hashes
;
4031 bfd_size_type reloc_count
;
4032 register struct reloc_std_external
*rel
;
4033 struct reloc_std_external
*rel_end
;
4035 output_bfd
= finfo
->output_bfd
;
4037 BFD_ASSERT (obj_reloc_entry_size (input_bfd
) == RELOC_STD_SIZE
);
4038 BFD_ASSERT (input_bfd
->xvec
->header_byteorder_big_p
4039 == output_bfd
->xvec
->header_byteorder_big_p
);
4041 relocateable
= finfo
->info
->relocateable
;
4042 syms
= obj_aout_external_syms (input_bfd
);
4043 strings
= obj_aout_external_strings (input_bfd
);
4044 sym_hashes
= obj_aout_sym_hashes (input_bfd
);
4046 reloc_count
= rel_size
/ RELOC_STD_SIZE
;
4048 rel_end
= rel
+ reloc_count
;
4049 for (; rel
< rel_end
; rel
++)
4061 bfd_reloc_status_type r
;
4063 r_addr
= GET_SWORD (input_bfd
, rel
->r_address
);
4065 if (input_bfd
->xvec
->header_byteorder_big_p
)
4067 r_index
= ((rel
->r_index
[0] << 16)
4068 | (rel
->r_index
[1] << 8)
4070 r_extern
= (0 != (rel
->r_type
[0] & RELOC_STD_BITS_EXTERN_BIG
));
4071 r_pcrel
= (0 != (rel
->r_type
[0] & RELOC_STD_BITS_PCREL_BIG
));
4072 r_baserel
= (0 != (rel
->r_type
[0] & RELOC_STD_BITS_BASEREL_BIG
));
4073 r_jmptable
= (0 != (rel
->r_type
[0] & RELOC_STD_BITS_JMPTABLE_BIG
));
4074 r_relative
= (0 != (rel
->r_type
[0] & RELOC_STD_BITS_RELATIVE_BIG
));
4075 r_length
= ((rel
->r_type
[0] & RELOC_STD_BITS_LENGTH_BIG
)
4076 >> RELOC_STD_BITS_LENGTH_SH_BIG
);
4080 r_index
= ((rel
->r_index
[2] << 16)
4081 | (rel
->r_index
[1] << 8)
4083 r_extern
= (0 != (rel
->r_type
[0] & RELOC_STD_BITS_EXTERN_LITTLE
));
4084 r_pcrel
= (0 != (rel
->r_type
[0] & RELOC_STD_BITS_PCREL_LITTLE
));
4085 r_baserel
= (0 != (rel
->r_type
[0] & RELOC_STD_BITS_BASEREL_LITTLE
));
4086 r_jmptable
= (0 != (rel
->r_type
[0] & RELOC_STD_BITS_JMPTABLE_LITTLE
));
4087 r_relative
= (0 != (rel
->r_type
[0] & RELOC_STD_BITS_RELATIVE_LITTLE
));
4088 r_length
= ((rel
->r_type
[0] & RELOC_STD_BITS_LENGTH_LITTLE
)
4089 >> RELOC_STD_BITS_LENGTH_SH_LITTLE
);
4092 howto_idx
= r_length
+ 4 * r_pcrel
+ 8 * r_baserel
;
4093 BFD_ASSERT (howto_idx
< TABLE_SIZE (howto_table_std
));
4094 BFD_ASSERT (r_jmptable
== 0);
4095 BFD_ASSERT (r_relative
== 0);
4099 /* We are generating a relocateable output file, and must
4100 modify the reloc accordingly. */
4103 struct aout_link_hash_entry
*h
;
4105 /* If we know the symbol this relocation is against,
4106 convert it into a relocation against a section. This
4107 is what the native linker does. */
4108 h
= sym_hashes
[r_index
];
4109 if (h
!= (struct aout_link_hash_entry
*) NULL
4110 && h
->root
.type
== bfd_link_hash_defined
)
4112 asection
*output_section
;
4114 /* Change the r_extern value. */
4115 if (output_bfd
->xvec
->header_byteorder_big_p
)
4116 rel
->r_type
[0] &=~ RELOC_STD_BITS_EXTERN_BIG
;
4118 rel
->r_type
[0] &=~ RELOC_STD_BITS_EXTERN_LITTLE
;
4120 /* Compute a new r_index. */
4121 output_section
= h
->root
.u
.def
.section
->output_section
;
4122 if (output_section
== obj_textsec (output_bfd
))
4124 else if (output_section
== obj_datasec (output_bfd
))
4126 else if (output_section
== obj_bsssec (output_bfd
))
4131 /* Add the symbol value and the section VMA to the
4132 addend stored in the contents. */
4133 relocation
= (h
->root
.u
.def
.value
4134 + output_section
->vma
4135 + h
->root
.u
.def
.section
->output_offset
);
4139 /* We must change r_index according to the symbol
4141 r_index
= symbol_map
[r_index
];
4147 name
= strings
+ GET_WORD (input_bfd
,
4148 syms
[r_index
].e_strx
);
4149 if (! ((*finfo
->info
->callbacks
->unattached_reloc
)
4150 (finfo
->info
, name
, input_bfd
, input_section
,
4159 /* Write out the new r_index value. */
4160 if (output_bfd
->xvec
->header_byteorder_big_p
)
4162 rel
->r_index
[0] = r_index
>> 16;
4163 rel
->r_index
[1] = r_index
>> 8;
4164 rel
->r_index
[2] = r_index
;
4168 rel
->r_index
[2] = r_index
>> 16;
4169 rel
->r_index
[1] = r_index
>> 8;
4170 rel
->r_index
[0] = r_index
;
4177 /* This is a relocation against a section. We must
4178 adjust by the amount that the section moved. */
4179 section
= aout_reloc_index_to_section (input_bfd
, r_index
);
4180 relocation
= (section
->output_section
->vma
4181 + section
->output_offset
4185 /* Change the address of the relocation. */
4186 PUT_WORD (output_bfd
,
4187 r_addr
+ input_section
->output_offset
,
4190 /* Adjust a PC relative relocation by removing the reference
4191 to the original address in the section and including the
4192 reference to the new address. */
4194 relocation
-= (input_section
->output_section
->vma
4195 + input_section
->output_offset
4196 - input_section
->vma
);
4198 if (relocation
== 0)
4201 r
= _bfd_relocate_contents (howto_table_std
+ howto_idx
,
4202 input_bfd
, relocation
,
4207 /* We are generating an executable, and must do a full
4211 struct aout_link_hash_entry
*h
;
4213 h
= sym_hashes
[r_index
];
4214 if (h
!= (struct aout_link_hash_entry
*) NULL
4215 && h
->root
.type
== bfd_link_hash_defined
)
4217 relocation
= (h
->root
.u
.def
.value
4218 + h
->root
.u
.def
.section
->output_section
->vma
4219 + h
->root
.u
.def
.section
->output_offset
);
4225 name
= strings
+ GET_WORD (input_bfd
, syms
[r_index
].e_strx
);
4226 if (! ((*finfo
->info
->callbacks
->undefined_symbol
)
4227 (finfo
->info
, name
, input_bfd
, input_section
,
4237 section
= aout_reloc_index_to_section (input_bfd
, r_index
);
4238 relocation
= (section
->output_section
->vma
4239 + section
->output_offset
4242 relocation
+= input_section
->vma
;
4245 r
= _bfd_final_link_relocate (howto_table_std
+ howto_idx
,
4246 input_bfd
, input_section
,
4247 contents
, r_addr
, relocation
,
4251 if (r
!= bfd_reloc_ok
)
4256 case bfd_reloc_outofrange
:
4258 case bfd_reloc_overflow
:
4263 name
= strings
+ GET_WORD (input_bfd
,
4264 syms
[r_index
].e_strx
);
4269 s
= aout_reloc_index_to_section (input_bfd
, r_index
);
4270 name
= bfd_section_name (input_bfd
, s
);
4272 if (! ((*finfo
->info
->callbacks
->reloc_overflow
)
4273 (finfo
->info
, name
, howto_table_std
[howto_idx
].name
,
4274 (bfd_vma
) 0, input_bfd
, input_section
, r_addr
)))
4285 /* Relocate an a.out section using extended a.out relocs. */
4288 aout_link_input_section_ext (finfo
, input_bfd
, input_section
, relocs
,
4289 rel_size
, contents
, symbol_map
)
4290 struct aout_final_link_info
*finfo
;
4292 asection
*input_section
;
4293 struct reloc_ext_external
*relocs
;
4294 bfd_size_type rel_size
;
4299 boolean relocateable
;
4300 struct external_nlist
*syms
;
4302 struct aout_link_hash_entry
**sym_hashes
;
4303 bfd_size_type reloc_count
;
4304 register struct reloc_ext_external
*rel
;
4305 struct reloc_ext_external
*rel_end
;
4307 output_bfd
= finfo
->output_bfd
;
4309 BFD_ASSERT (obj_reloc_entry_size (input_bfd
) == RELOC_EXT_SIZE
);
4310 BFD_ASSERT (input_bfd
->xvec
->header_byteorder_big_p
4311 == output_bfd
->xvec
->header_byteorder_big_p
);
4313 relocateable
= finfo
->info
->relocateable
;
4314 syms
= obj_aout_external_syms (input_bfd
);
4315 strings
= obj_aout_external_strings (input_bfd
);
4316 sym_hashes
= obj_aout_sym_hashes (input_bfd
);
4318 reloc_count
= rel_size
/ RELOC_EXT_SIZE
;
4320 rel_end
= rel
+ reloc_count
;
4321 for (; rel
< rel_end
; rel
++)
4330 r_addr
= GET_SWORD (input_bfd
, rel
->r_address
);
4332 if (input_bfd
->xvec
->header_byteorder_big_p
)
4334 r_index
= ((rel
->r_index
[0] << 16)
4335 | (rel
->r_index
[1] << 8)
4337 r_extern
= (0 != (rel
->r_type
[0] & RELOC_EXT_BITS_EXTERN_BIG
));
4338 r_type
= ((rel
->r_type
[0] & RELOC_EXT_BITS_TYPE_BIG
)
4339 >> RELOC_EXT_BITS_TYPE_SH_BIG
);
4343 r_index
= ((rel
->r_index
[2] << 16)
4344 | (rel
->r_index
[1] << 8)
4346 r_extern
= (0 != (rel
->r_type
[0] & RELOC_EXT_BITS_EXTERN_LITTLE
));
4347 r_type
= ((rel
->r_type
[0] & RELOC_EXT_BITS_TYPE_LITTLE
)
4348 >> RELOC_EXT_BITS_TYPE_SH_LITTLE
);
4351 r_addend
= GET_SWORD (input_bfd
, rel
->r_addend
);
4353 BFD_ASSERT (r_type
>= 0
4354 && r_type
< TABLE_SIZE (howto_table_ext
));
4358 /* We are generating a relocateable output file, and must
4359 modify the reloc accordingly. */
4362 struct aout_link_hash_entry
*h
;
4364 /* If we know the symbol this relocation is against,
4365 convert it into a relocation against a section. This
4366 is what the native linker does. */
4367 h
= sym_hashes
[r_index
];
4368 if (h
!= (struct aout_link_hash_entry
*) NULL
4369 && h
->root
.type
== bfd_link_hash_defined
)
4371 asection
*output_section
;
4373 /* Change the r_extern value. */
4374 if (output_bfd
->xvec
->header_byteorder_big_p
)
4375 rel
->r_type
[0] &=~ RELOC_EXT_BITS_EXTERN_BIG
;
4377 rel
->r_type
[0] &=~ RELOC_EXT_BITS_EXTERN_LITTLE
;
4379 /* Compute a new r_index. */
4380 output_section
= h
->root
.u
.def
.section
->output_section
;
4381 if (output_section
== obj_textsec (output_bfd
))
4383 else if (output_section
== obj_datasec (output_bfd
))
4385 else if (output_section
== obj_bsssec (output_bfd
))
4390 /* Add the symbol value and the section VMA to the
4392 relocation
= (h
->root
.u
.def
.value
4393 + output_section
->vma
4394 + h
->root
.u
.def
.section
->output_offset
);
4396 /* Now RELOCATION is the VMA of the final
4397 destination. If this is a PC relative reloc,
4398 then ADDEND is the negative of the source VMA.
4399 We want to set ADDEND to the difference between
4400 the destination VMA and the source VMA, which
4401 means we must adjust RELOCATION by the change in
4402 the source VMA. This is done below. */
4406 /* We must change r_index according to the symbol
4408 r_index
= symbol_map
[r_index
];
4415 + GET_WORD (input_bfd
, syms
[r_index
].e_strx
));
4416 if (! ((*finfo
->info
->callbacks
->unattached_reloc
)
4417 (finfo
->info
, name
, input_bfd
, input_section
,
4425 /* If this is a PC relative reloc, then the addend
4426 is the negative of the source VMA. We must
4427 adjust it by the change in the source VMA. This
4431 /* Write out the new r_index value. */
4432 if (output_bfd
->xvec
->header_byteorder_big_p
)
4434 rel
->r_index
[0] = r_index
>> 16;
4435 rel
->r_index
[1] = r_index
>> 8;
4436 rel
->r_index
[2] = r_index
;
4440 rel
->r_index
[2] = r_index
>> 16;
4441 rel
->r_index
[1] = r_index
>> 8;
4442 rel
->r_index
[0] = r_index
;
4449 /* This is a relocation against a section. We must
4450 adjust by the amount that the section moved. */
4451 section
= aout_reloc_index_to_section (input_bfd
, r_index
);
4452 relocation
= (section
->output_section
->vma
4453 + section
->output_offset
4456 /* If this is a PC relative reloc, then the addend is
4457 the difference in VMA between the destination and the
4458 source. We have just adjusted for the change in VMA
4459 of the destination, so we must also adjust by the
4460 change in VMA of the source. This is done below. */
4463 /* As described above, we must always adjust a PC relative
4464 reloc by the change in VMA of the source. */
4465 if (howto_table_ext
[r_type
].pc_relative
)
4466 relocation
-= (input_section
->output_section
->vma
4467 + input_section
->output_offset
4468 - input_section
->vma
);
4470 /* Change the addend if necessary. */
4471 if (relocation
!= 0)
4472 PUT_WORD (output_bfd
, r_addend
+ relocation
, rel
->r_addend
);
4474 /* Change the address of the relocation. */
4475 PUT_WORD (output_bfd
,
4476 r_addr
+ input_section
->output_offset
,
4481 bfd_reloc_status_type r
;
4483 /* We are generating an executable, and must do a full
4487 struct aout_link_hash_entry
*h
;
4489 h
= sym_hashes
[r_index
];
4490 if (h
!= (struct aout_link_hash_entry
*) NULL
4491 && h
->root
.type
== bfd_link_hash_defined
)
4493 relocation
= (h
->root
.u
.def
.value
4494 + h
->root
.u
.def
.section
->output_section
->vma
4495 + h
->root
.u
.def
.section
->output_offset
);
4501 name
= strings
+ GET_WORD (input_bfd
, syms
[r_index
].e_strx
);
4502 if (! ((*finfo
->info
->callbacks
->undefined_symbol
)
4503 (finfo
->info
, name
, input_bfd
, input_section
,
4513 section
= aout_reloc_index_to_section (input_bfd
, r_index
);
4515 /* If this is a PC relative reloc, then R_ADDEND is the
4516 difference between the two vmas, or
4517 old_dest_sec + old_dest_off - (old_src_sec + old_src_off)
4519 old_dest_sec == section->vma
4521 old_src_sec == input_section->vma
4523 old_src_off == r_addr
4525 _bfd_final_link_relocate expects RELOCATION +
4526 R_ADDEND to be the VMA of the destination minus
4527 r_addr (the minus r_addr is because this relocation
4528 is not pcrel_offset, which is a bit confusing and
4529 should, perhaps, be changed), or
4532 new_dest_sec == output_section->vma + output_offset
4533 We arrange for this to happen by setting RELOCATION to
4534 new_dest_sec + old_src_sec - old_dest_sec
4536 If this is not a PC relative reloc, then R_ADDEND is
4537 simply the VMA of the destination, so we set
4538 RELOCATION to the change in the destination VMA, or
4539 new_dest_sec - old_dest_sec
4541 relocation
= (section
->output_section
->vma
4542 + section
->output_offset
4544 if (howto_table_ext
[r_type
].pc_relative
)
4545 relocation
+= input_section
->vma
;
4548 r
= _bfd_final_link_relocate (howto_table_ext
+ r_type
,
4549 input_bfd
, input_section
,
4550 contents
, r_addr
, relocation
,
4552 if (r
!= bfd_reloc_ok
)
4557 case bfd_reloc_outofrange
:
4559 case bfd_reloc_overflow
:
4564 name
= strings
+ GET_WORD (input_bfd
,
4565 syms
[r_index
].e_strx
);
4570 s
= aout_reloc_index_to_section (input_bfd
, r_index
);
4571 name
= bfd_section_name (input_bfd
, s
);
4573 if (! ((*finfo
->info
->callbacks
->reloc_overflow
)
4574 (finfo
->info
, name
, howto_table_ext
[r_type
].name
,
4575 r_addend
, input_bfd
, input_section
, r_addr
)))