1 /* BFD semi-generic back-end for a.out binaries.
2 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3 2000, 2001, 2002, 2003, 2004, 2005
4 Free Software Foundation, Inc.
5 Written by Cygnus Support.
7 This file is part of BFD, the Binary File Descriptor library.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
29 BFD supports a number of different flavours of a.out format,
30 though the major differences are only the sizes of the
31 structures on disk, and the shape of the relocation
34 The support is split into a basic support file @file{aoutx.h}
35 and other files which derive functions from the base. One
36 derivation file is @file{aoutf1.h} (for a.out flavour 1), and
37 adds to the basic a.out functions support for sun3, sun4, 386
38 and 29k a.out files, to create a target jump vector for a
41 This information is further split out into more specific files
42 for each machine, including @file{sunos.c} for sun3 and sun4,
43 @file{newsos3.c} for the Sony NEWS, and @file{demo64.c} for a
44 demonstration of a 64 bit a.out format.
46 The base file @file{aoutx.h} defines general mechanisms for
47 reading and writing records to and from disk and various
48 other methods which BFD requires. It is included by
49 @file{aout32.c} and @file{aout64.c} to form the names
50 <<aout_32_swap_exec_header_in>>, <<aout_64_swap_exec_header_in>>, etc.
52 As an example, this is what goes on to make the back end for a
53 sun4, from @file{aout32.c}:
55 | #define ARCH_SIZE 32
61 | aout_32_canonicalize_reloc
62 | aout_32_find_nearest_line
64 | 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. */
111 * Any BFD with D_PAGED set is ZMAGIC, and vice versa.
112 Doesn't matter what the setting of WP_TEXT is on output, but it'll
114 * Any BFD with D_PAGED clear and WP_TEXT set is NMAGIC.
115 * Any BFD with both flags clear is OMAGIC.
116 (Just want to make these explicit, so the conditions tested in this
117 file make sense if you're more familiar with a.out than with BFD.) */
119 #define KEEPIT udata.i
123 #include "safe-ctype.h"
128 #include "aout/aout64.h"
129 #include "aout/stab_gnu.h"
132 reloc_howto_type
* NAME (aout
, reloc_type_lookup
) (bfd
*, bfd_reloc_code_real_type
);
139 The file @file{aoutx.h} provides for both the @emph{standard}
140 and @emph{extended} forms of a.out relocation records.
142 The standard records contain only an
143 address, a symbol index, and a type field. The extended records
144 (used on 29ks and sparcs) also have a full integer for an
147 #ifndef CTOR_TABLE_RELOC_HOWTO
148 #define CTOR_TABLE_RELOC_IDX 2
149 #define CTOR_TABLE_RELOC_HOWTO(BFD) \
150 ((obj_reloc_entry_size (BFD) == RELOC_EXT_SIZE \
151 ? howto_table_ext : howto_table_std) \
152 + CTOR_TABLE_RELOC_IDX)
155 #ifndef MY_swap_std_reloc_in
156 #define MY_swap_std_reloc_in NAME (aout, swap_std_reloc_in)
159 #ifndef MY_swap_ext_reloc_in
160 #define MY_swap_ext_reloc_in NAME (aout, swap_ext_reloc_in)
163 #ifndef MY_swap_std_reloc_out
164 #define MY_swap_std_reloc_out NAME (aout, swap_std_reloc_out)
167 #ifndef MY_swap_ext_reloc_out
168 #define MY_swap_ext_reloc_out NAME (aout, swap_ext_reloc_out)
171 #ifndef MY_final_link_relocate
172 #define MY_final_link_relocate _bfd_final_link_relocate
175 #ifndef MY_relocate_contents
176 #define MY_relocate_contents _bfd_relocate_contents
179 #define howto_table_ext NAME (aout, ext_howto_table)
180 #define howto_table_std NAME (aout, std_howto_table)
182 reloc_howto_type howto_table_ext
[] =
184 /* Type rs size bsz pcrel bitpos ovrf sf name part_inpl readmask setmask pcdone. */
185 HOWTO (RELOC_8
, 0, 0, 8, FALSE
, 0, complain_overflow_bitfield
, 0, "8", FALSE
, 0, 0x000000ff, FALSE
),
186 HOWTO (RELOC_16
, 0, 1, 16, FALSE
, 0, complain_overflow_bitfield
, 0, "16", FALSE
, 0, 0x0000ffff, FALSE
),
187 HOWTO (RELOC_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
, 0, "32", FALSE
, 0, 0xffffffff, FALSE
),
188 HOWTO (RELOC_DISP8
, 0, 0, 8, TRUE
, 0, complain_overflow_signed
, 0, "DISP8", FALSE
, 0, 0x000000ff, FALSE
),
189 HOWTO (RELOC_DISP16
, 0, 1, 16, TRUE
, 0, complain_overflow_signed
, 0, "DISP16", FALSE
, 0, 0x0000ffff, FALSE
),
190 HOWTO (RELOC_DISP32
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
, 0, "DISP32", FALSE
, 0, 0xffffffff, FALSE
),
191 HOWTO (RELOC_WDISP30
, 2, 2, 30, TRUE
, 0, complain_overflow_signed
, 0, "WDISP30", FALSE
, 0, 0x3fffffff, FALSE
),
192 HOWTO (RELOC_WDISP22
, 2, 2, 22, TRUE
, 0, complain_overflow_signed
, 0, "WDISP22", FALSE
, 0, 0x003fffff, FALSE
),
193 HOWTO (RELOC_HI22
, 10, 2, 22, FALSE
, 0, complain_overflow_bitfield
, 0, "HI22", FALSE
, 0, 0x003fffff, FALSE
),
194 HOWTO (RELOC_22
, 0, 2, 22, FALSE
, 0, complain_overflow_bitfield
, 0, "22", FALSE
, 0, 0x003fffff, FALSE
),
195 HOWTO (RELOC_13
, 0, 2, 13, FALSE
, 0, complain_overflow_bitfield
, 0, "13", FALSE
, 0, 0x00001fff, FALSE
),
196 HOWTO (RELOC_LO10
, 0, 2, 10, FALSE
, 0, complain_overflow_dont
, 0, "LO10", FALSE
, 0, 0x000003ff, FALSE
),
197 HOWTO (RELOC_SFA_BASE
,0, 2, 32, FALSE
, 0, complain_overflow_bitfield
, 0, "SFA_BASE", FALSE
, 0, 0xffffffff, FALSE
),
198 HOWTO (RELOC_SFA_OFF13
,0, 2, 32, FALSE
, 0, complain_overflow_bitfield
, 0, "SFA_OFF13", FALSE
, 0, 0xffffffff, FALSE
),
199 HOWTO (RELOC_BASE10
, 0, 2, 10, FALSE
, 0, complain_overflow_dont
, 0, "BASE10", FALSE
, 0, 0x000003ff, FALSE
),
200 HOWTO (RELOC_BASE13
, 0, 2, 13, FALSE
, 0, complain_overflow_signed
, 0, "BASE13", FALSE
, 0, 0x00001fff, FALSE
),
201 HOWTO (RELOC_BASE22
, 10, 2, 22, FALSE
, 0, complain_overflow_bitfield
, 0, "BASE22", FALSE
, 0, 0x003fffff, FALSE
),
202 HOWTO (RELOC_PC10
, 0, 2, 10, TRUE
, 0, complain_overflow_dont
, 0, "PC10", FALSE
, 0, 0x000003ff, TRUE
),
203 HOWTO (RELOC_PC22
, 10, 2, 22, TRUE
, 0, complain_overflow_signed
, 0, "PC22", FALSE
, 0, 0x003fffff, TRUE
),
204 HOWTO (RELOC_JMP_TBL
, 2, 2, 30, TRUE
, 0, complain_overflow_signed
, 0, "JMP_TBL", FALSE
, 0, 0x3fffffff, FALSE
),
205 HOWTO (RELOC_SEGOFF16
,0, 2, 0, FALSE
, 0, complain_overflow_bitfield
, 0, "SEGOFF16", FALSE
, 0, 0x00000000, FALSE
),
206 HOWTO (RELOC_GLOB_DAT
,0, 2, 0, FALSE
, 0, complain_overflow_bitfield
, 0, "GLOB_DAT", FALSE
, 0, 0x00000000, FALSE
),
207 HOWTO (RELOC_JMP_SLOT
,0, 2, 0, FALSE
, 0, complain_overflow_bitfield
, 0, "JMP_SLOT", FALSE
, 0, 0x00000000, FALSE
),
208 HOWTO (RELOC_RELATIVE
,0, 2, 0, FALSE
, 0, complain_overflow_bitfield
, 0, "RELATIVE", FALSE
, 0, 0x00000000, FALSE
),
209 HOWTO (0, 0, 0, 0, FALSE
, 0, complain_overflow_dont
, 0, "R_SPARC_NONE",FALSE
, 0, 0x00000000, TRUE
),
210 HOWTO (0, 0, 0, 0, FALSE
, 0, complain_overflow_dont
, 0, "R_SPARC_NONE",FALSE
, 0, 0x00000000, TRUE
),
211 #define RELOC_SPARC_REV32 RELOC_WDISP19
212 HOWTO (RELOC_SPARC_REV32
, 0, 2, 32, FALSE
, 0, complain_overflow_dont
, 0,"R_SPARC_REV32",FALSE
, 0, 0xffffffff, FALSE
),
215 /* Convert standard reloc records to "arelent" format (incl byte swap). */
217 reloc_howto_type howto_table_std
[] =
219 /* type rs size bsz pcrel bitpos ovrf sf name part_inpl readmask setmask pcdone. */
220 HOWTO ( 0, 0, 0, 8, FALSE
, 0, complain_overflow_bitfield
,0,"8", TRUE
, 0x000000ff,0x000000ff, FALSE
),
221 HOWTO ( 1, 0, 1, 16, FALSE
, 0, complain_overflow_bitfield
,0,"16", TRUE
, 0x0000ffff,0x0000ffff, FALSE
),
222 HOWTO ( 2, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,0,"32", TRUE
, 0xffffffff,0xffffffff, FALSE
),
223 HOWTO ( 3, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,0,"64", TRUE
, 0xdeaddead,0xdeaddead, FALSE
),
224 HOWTO ( 4, 0, 0, 8, TRUE
, 0, complain_overflow_signed
, 0,"DISP8", TRUE
, 0x000000ff,0x000000ff, FALSE
),
225 HOWTO ( 5, 0, 1, 16, TRUE
, 0, complain_overflow_signed
, 0,"DISP16", TRUE
, 0x0000ffff,0x0000ffff, FALSE
),
226 HOWTO ( 6, 0, 2, 32, TRUE
, 0, complain_overflow_signed
, 0,"DISP32", TRUE
, 0xffffffff,0xffffffff, FALSE
),
227 HOWTO ( 7, 0, 4, 64, TRUE
, 0, complain_overflow_signed
, 0,"DISP64", TRUE
, 0xfeedface,0xfeedface, FALSE
),
228 HOWTO ( 8, 0, 2, 0, FALSE
, 0, complain_overflow_bitfield
,0,"GOT_REL", FALSE
, 0,0x00000000, FALSE
),
229 HOWTO ( 9, 0, 1, 16, FALSE
, 0, complain_overflow_bitfield
,0,"BASE16", FALSE
,0xffffffff,0xffffffff, FALSE
),
230 HOWTO (10, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,0,"BASE32", FALSE
,0xffffffff,0xffffffff, FALSE
),
236 HOWTO (16, 0, 2, 0, FALSE
, 0, complain_overflow_bitfield
,0,"JMP_TABLE", FALSE
, 0,0x00000000, FALSE
),
252 HOWTO (32, 0, 2, 0, FALSE
, 0, complain_overflow_bitfield
,0,"RELATIVE", FALSE
, 0,0x00000000, FALSE
),
260 HOWTO (40, 0, 2, 0, FALSE
, 0, complain_overflow_bitfield
,0,"BASEREL", FALSE
, 0,0x00000000, FALSE
),
263 #define TABLE_SIZE(TABLE) (sizeof (TABLE) / sizeof (TABLE[0]))
266 NAME (aout
, reloc_type_lookup
) (bfd
*abfd
, bfd_reloc_code_real_type code
)
268 #define EXT(i, j) case i: return & howto_table_ext [j]
269 #define STD(i, j) case i: return & howto_table_std [j]
270 int ext
= obj_reloc_entry_size (abfd
) == RELOC_EXT_SIZE
;
272 if (code
== BFD_RELOC_CTOR
)
273 switch (bfd_get_arch_info (abfd
)->bits_per_address
)
286 EXT (BFD_RELOC_8
, 0);
287 EXT (BFD_RELOC_16
, 1);
288 EXT (BFD_RELOC_32
, 2);
289 EXT (BFD_RELOC_HI22
, 8);
290 EXT (BFD_RELOC_LO10
, 11);
291 EXT (BFD_RELOC_32_PCREL_S2
, 6);
292 EXT (BFD_RELOC_SPARC_WDISP22
, 7);
293 EXT (BFD_RELOC_SPARC13
, 10);
294 EXT (BFD_RELOC_SPARC_GOT10
, 14);
295 EXT (BFD_RELOC_SPARC_BASE13
, 15);
296 EXT (BFD_RELOC_SPARC_GOT13
, 15);
297 EXT (BFD_RELOC_SPARC_GOT22
, 16);
298 EXT (BFD_RELOC_SPARC_PC10
, 17);
299 EXT (BFD_RELOC_SPARC_PC22
, 18);
300 EXT (BFD_RELOC_SPARC_WPLT30
, 19);
301 EXT (BFD_RELOC_SPARC_REV32
, 26);
309 STD (BFD_RELOC_8
, 0);
310 STD (BFD_RELOC_16
, 1);
311 STD (BFD_RELOC_32
, 2);
312 STD (BFD_RELOC_8_PCREL
, 4);
313 STD (BFD_RELOC_16_PCREL
, 5);
314 STD (BFD_RELOC_32_PCREL
, 6);
315 STD (BFD_RELOC_16_BASEREL
, 9);
316 STD (BFD_RELOC_32_BASEREL
, 10);
324 Internal entry points
327 @file{aoutx.h} exports several routines for accessing the
328 contents of an a.out file, which are gathered and exported in
329 turn by various format specific files (eg sunos.c).
334 aout_@var{size}_swap_exec_header_in
337 void aout_@var{size}_swap_exec_header_in,
339 struct external_exec *bytes,
340 struct internal_exec *execp);
343 Swap the information in an executable header @var{raw_bytes} taken
344 from a raw byte stream memory image into the internal exec header
345 structure @var{execp}.
348 #ifndef NAME_swap_exec_header_in
350 NAME (aout
, swap_exec_header_in
) (bfd
*abfd
,
351 struct external_exec
*bytes
,
352 struct internal_exec
*execp
)
354 /* The internal_exec structure has some fields that are unused in this
355 configuration (IE for i960), so ensure that all such uninitialized
356 fields are zero'd out. There are places where two of these structs
357 are memcmp'd, and thus the contents do matter. */
358 memset ((void *) execp
, 0, sizeof (struct internal_exec
));
359 /* Now fill in fields in the execp, from the bytes in the raw data. */
360 execp
->a_info
= H_GET_32 (abfd
, bytes
->e_info
);
361 execp
->a_text
= GET_WORD (abfd
, bytes
->e_text
);
362 execp
->a_data
= GET_WORD (abfd
, bytes
->e_data
);
363 execp
->a_bss
= GET_WORD (abfd
, bytes
->e_bss
);
364 execp
->a_syms
= GET_WORD (abfd
, bytes
->e_syms
);
365 execp
->a_entry
= GET_WORD (abfd
, bytes
->e_entry
);
366 execp
->a_trsize
= GET_WORD (abfd
, bytes
->e_trsize
);
367 execp
->a_drsize
= GET_WORD (abfd
, bytes
->e_drsize
);
369 #define NAME_swap_exec_header_in NAME (aout, swap_exec_header_in)
374 aout_@var{size}_swap_exec_header_out
377 void aout_@var{size}_swap_exec_header_out
379 struct internal_exec *execp,
380 struct external_exec *raw_bytes);
383 Swap the information in an internal exec header structure
384 @var{execp} into the buffer @var{raw_bytes} ready for writing to disk.
387 NAME (aout
, swap_exec_header_out
) (bfd
*abfd
,
388 struct internal_exec
*execp
,
389 struct external_exec
*bytes
)
391 /* Now fill in fields in the raw data, from the fields in the exec struct. */
392 H_PUT_32 (abfd
, execp
->a_info
, bytes
->e_info
);
393 PUT_WORD (abfd
, execp
->a_text
, bytes
->e_text
);
394 PUT_WORD (abfd
, execp
->a_data
, bytes
->e_data
);
395 PUT_WORD (abfd
, execp
->a_bss
, bytes
->e_bss
);
396 PUT_WORD (abfd
, execp
->a_syms
, bytes
->e_syms
);
397 PUT_WORD (abfd
, execp
->a_entry
, bytes
->e_entry
);
398 PUT_WORD (abfd
, execp
->a_trsize
, bytes
->e_trsize
);
399 PUT_WORD (abfd
, execp
->a_drsize
, bytes
->e_drsize
);
402 /* Make all the section for an a.out file. */
405 NAME (aout
, make_sections
) (bfd
*abfd
)
407 if (obj_textsec (abfd
) == NULL
&& bfd_make_section (abfd
, ".text") == NULL
)
409 if (obj_datasec (abfd
) == NULL
&& bfd_make_section (abfd
, ".data") == NULL
)
411 if (obj_bsssec (abfd
) == NULL
&& bfd_make_section (abfd
, ".bss") == NULL
)
418 aout_@var{size}_some_aout_object_p
421 const bfd_target *aout_@var{size}_some_aout_object_p
423 struct internal_exec *execp,
424 const bfd_target *(*callback_to_real_object_p) (bfd *));
427 Some a.out variant thinks that the file open in @var{abfd}
428 checking is an a.out file. Do some more checking, and set up
429 for access if it really is. Call back to the calling
430 environment's "finish up" function just before returning, to
431 handle any last-minute setup.
435 NAME (aout
, some_aout_object_p
) (bfd
*abfd
,
436 struct internal_exec
*execp
,
437 const bfd_target
*(*callback_to_real_object_p
) (bfd
*))
439 struct aout_data_struct
*rawptr
, *oldrawptr
;
440 const bfd_target
*result
;
441 bfd_size_type amt
= sizeof (* rawptr
);
443 rawptr
= bfd_zalloc (abfd
, amt
);
447 oldrawptr
= abfd
->tdata
.aout_data
;
448 abfd
->tdata
.aout_data
= rawptr
;
450 /* Copy the contents of the old tdata struct.
451 In particular, we want the subformat, since for hpux it was set in
452 hp300hpux.c:swap_exec_header_in and will be used in
453 hp300hpux.c:callback. */
454 if (oldrawptr
!= NULL
)
455 *abfd
->tdata
.aout_data
= *oldrawptr
;
457 abfd
->tdata
.aout_data
->a
.hdr
= &rawptr
->e
;
458 /* Copy in the internal_exec struct. */
459 *(abfd
->tdata
.aout_data
->a
.hdr
) = *execp
;
460 execp
= abfd
->tdata
.aout_data
->a
.hdr
;
462 /* Set the file flags. */
463 abfd
->flags
= BFD_NO_FLAGS
;
464 if (execp
->a_drsize
|| execp
->a_trsize
)
465 abfd
->flags
|= HAS_RELOC
;
466 /* Setting of EXEC_P has been deferred to the bottom of this function. */
468 abfd
->flags
|= HAS_LINENO
| HAS_DEBUG
| HAS_SYMS
| HAS_LOCALS
;
469 if (N_DYNAMIC (*execp
))
470 abfd
->flags
|= DYNAMIC
;
472 if (N_MAGIC (*execp
) == ZMAGIC
)
474 abfd
->flags
|= D_PAGED
| WP_TEXT
;
475 adata (abfd
).magic
= z_magic
;
477 else if (N_MAGIC (*execp
) == QMAGIC
)
479 abfd
->flags
|= D_PAGED
| WP_TEXT
;
480 adata (abfd
).magic
= z_magic
;
481 adata (abfd
).subformat
= q_magic_format
;
483 else if (N_MAGIC (*execp
) == NMAGIC
)
485 abfd
->flags
|= WP_TEXT
;
486 adata (abfd
).magic
= n_magic
;
488 else if (N_MAGIC (*execp
) == OMAGIC
489 || N_MAGIC (*execp
) == BMAGIC
)
490 adata (abfd
).magic
= o_magic
;
492 /* Should have been checked with N_BADMAG before this routine
496 bfd_get_start_address (abfd
) = execp
->a_entry
;
498 obj_aout_symbols (abfd
) = NULL
;
499 bfd_get_symcount (abfd
) = execp
->a_syms
/ sizeof (struct external_nlist
);
501 /* The default relocation entry size is that of traditional V7 Unix. */
502 obj_reloc_entry_size (abfd
) = RELOC_STD_SIZE
;
504 /* The default symbol entry size is that of traditional Unix. */
505 obj_symbol_entry_size (abfd
) = EXTERNAL_NLIST_SIZE
;
508 bfd_init_window (&obj_aout_sym_window (abfd
));
509 bfd_init_window (&obj_aout_string_window (abfd
));
511 obj_aout_external_syms (abfd
) = NULL
;
512 obj_aout_external_strings (abfd
) = NULL
;
513 obj_aout_sym_hashes (abfd
) = NULL
;
515 if (! NAME (aout
, make_sections
) (abfd
))
518 obj_datasec (abfd
)->size
= execp
->a_data
;
519 obj_bsssec (abfd
)->size
= execp
->a_bss
;
521 obj_textsec (abfd
)->flags
=
522 (execp
->a_trsize
!= 0
523 ? (SEC_ALLOC
| SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
| SEC_RELOC
)
524 : (SEC_ALLOC
| SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
));
525 obj_datasec (abfd
)->flags
=
526 (execp
->a_drsize
!= 0
527 ? (SEC_ALLOC
| SEC_LOAD
| SEC_DATA
| SEC_HAS_CONTENTS
| SEC_RELOC
)
528 : (SEC_ALLOC
| SEC_LOAD
| SEC_DATA
| SEC_HAS_CONTENTS
));
529 obj_bsssec (abfd
)->flags
= SEC_ALLOC
;
531 #ifdef THIS_IS_ONLY_DOCUMENTATION
532 /* The common code can't fill in these things because they depend
533 on either the start address of the text segment, the rounding
534 up of virtual addresses between segments, or the starting file
535 position of the text segment -- all of which varies among different
536 versions of a.out. */
538 /* Call back to the format-dependent code to fill in the rest of the
539 fields and do any further cleanup. Things that should be filled
540 in by the callback: */
542 struct exec
*execp
= exec_hdr (abfd
);
544 obj_textsec (abfd
)->size
= N_TXTSIZE (*execp
);
545 /* Data and bss are already filled in since they're so standard. */
547 /* The virtual memory addresses of the sections. */
548 obj_textsec (abfd
)->vma
= N_TXTADDR (*execp
);
549 obj_datasec (abfd
)->vma
= N_DATADDR (*execp
);
550 obj_bsssec (abfd
)->vma
= N_BSSADDR (*execp
);
552 /* The file offsets of the sections. */
553 obj_textsec (abfd
)->filepos
= N_TXTOFF (*execp
);
554 obj_datasec (abfd
)->filepos
= N_DATOFF (*execp
);
556 /* The file offsets of the relocation info. */
557 obj_textsec (abfd
)->rel_filepos
= N_TRELOFF (*execp
);
558 obj_datasec (abfd
)->rel_filepos
= N_DRELOFF (*execp
);
560 /* The file offsets of the string table and symbol table. */
561 obj_str_filepos (abfd
) = N_STROFF (*execp
);
562 obj_sym_filepos (abfd
) = N_SYMOFF (*execp
);
564 /* Determine the architecture and machine type of the object file. */
565 switch (N_MACHTYPE (*exec_hdr (abfd
)))
568 abfd
->obj_arch
= bfd_arch_obscure
;
572 adata (abfd
)->page_size
= TARGET_PAGE_SIZE
;
573 adata (abfd
)->segment_size
= SEGMENT_SIZE
;
574 adata (abfd
)->exec_bytes_size
= EXEC_BYTES_SIZE
;
578 /* The architecture is encoded in various ways in various a.out variants,
579 or is not encoded at all in some of them. The relocation size depends
580 on the architecture and the a.out variant. Finally, the return value
581 is the bfd_target vector in use. If an error occurs, return zero and
582 set bfd_error to the appropriate error code.
584 Formats such as b.out, which have additional fields in the a.out
585 header, should cope with them in this callback as well. */
586 #endif /* DOCUMENTATION */
588 result
= (*callback_to_real_object_p
) (abfd
);
590 /* Now that the segment addresses have been worked out, take a better
591 guess at whether the file is executable. If the entry point
592 is within the text segment, assume it is. (This makes files
593 executable even if their entry point address is 0, as long as
594 their text starts at zero.).
596 This test had to be changed to deal with systems where the text segment
597 runs at a different location than the default. The problem is that the
598 entry address can appear to be outside the text segment, thus causing an
599 erroneous conclusion that the file isn't executable.
601 To fix this, we now accept any non-zero entry point as an indication of
602 executability. This will work most of the time, since only the linker
603 sets the entry point, and that is likely to be non-zero for most systems. */
605 if (execp
->a_entry
!= 0
606 || (execp
->a_entry
>= obj_textsec (abfd
)->vma
607 && execp
->a_entry
< (obj_textsec (abfd
)->vma
608 + obj_textsec (abfd
)->size
)))
609 abfd
->flags
|= EXEC_P
;
613 struct stat stat_buf
;
615 /* The original heuristic doesn't work in some important cases.
616 The a.out file has no information about the text start
617 address. For files (like kernels) linked to non-standard
618 addresses (ld -Ttext nnn) the entry point may not be between
619 the default text start (obj_textsec(abfd)->vma) and
620 (obj_textsec(abfd)->vma) + text size. This is not just a mach
621 issue. Many kernels are loaded at non standard addresses. */
622 if (abfd
->iostream
!= NULL
623 && (abfd
->flags
& BFD_IN_MEMORY
) == 0
624 && (fstat (fileno ((FILE *) (abfd
->iostream
)), &stat_buf
) == 0)
625 && ((stat_buf
.st_mode
& 0111) != 0))
626 abfd
->flags
|= EXEC_P
;
628 #endif /* STAT_FOR_EXEC */
634 bfd_release (abfd
, rawptr
);
635 abfd
->tdata
.aout_data
= oldrawptr
;
641 aout_@var{size}_mkobject
644 bfd_boolean aout_@var{size}_mkobject, (bfd *abfd);
647 Initialize BFD @var{abfd} for use with a.out files.
651 NAME (aout
, mkobject
) (bfd
*abfd
)
653 struct aout_data_struct
*rawptr
;
654 bfd_size_type amt
= sizeof (* rawptr
);
656 bfd_set_error (bfd_error_system_call
);
658 rawptr
= bfd_zalloc (abfd
, amt
);
662 abfd
->tdata
.aout_data
= rawptr
;
663 exec_hdr (abfd
) = &(rawptr
->e
);
665 obj_textsec (abfd
) = NULL
;
666 obj_datasec (abfd
) = NULL
;
667 obj_bsssec (abfd
) = NULL
;
674 aout_@var{size}_machine_type
677 enum machine_type aout_@var{size}_machine_type
678 (enum bfd_architecture arch,
679 unsigned long machine,
680 bfd_boolean *unknown);
683 Keep track of machine architecture and machine type for
684 a.out's. Return the <<machine_type>> for a particular
685 architecture and machine, or <<M_UNKNOWN>> if that exact architecture
686 and machine can't be represented in a.out format.
688 If the architecture is understood, machine type 0 (default)
689 is always understood.
693 NAME (aout
, machine_type
) (enum bfd_architecture arch
,
694 unsigned long machine
,
695 bfd_boolean
*unknown
)
697 enum machine_type arch_flags
;
699 arch_flags
= M_UNKNOWN
;
706 || machine
== bfd_mach_sparc
707 || machine
== bfd_mach_sparc_sparclite
708 || machine
== bfd_mach_sparc_sparclite_le
709 || machine
== bfd_mach_sparc_v9
)
710 arch_flags
= M_SPARC
;
711 else if (machine
== bfd_mach_sparc_sparclet
)
712 arch_flags
= M_SPARCLET
;
718 case 0: arch_flags
= M_68010
; break;
719 case bfd_mach_m68000
: arch_flags
= M_UNKNOWN
; *unknown
= FALSE
; break;
720 case bfd_mach_m68010
: arch_flags
= M_68010
; break;
721 case bfd_mach_m68020
: arch_flags
= M_68020
; break;
722 default: arch_flags
= M_UNKNOWN
; break;
728 || machine
== bfd_mach_i386_i386
729 || machine
== bfd_mach_i386_i386_intel_syntax
)
747 case bfd_mach_mips3000
:
748 case bfd_mach_mips3900
:
749 arch_flags
= M_MIPS1
;
751 case bfd_mach_mips6000
:
752 arch_flags
= M_MIPS2
;
754 case bfd_mach_mips4000
:
755 case bfd_mach_mips4010
:
756 case bfd_mach_mips4100
:
757 case bfd_mach_mips4300
:
758 case bfd_mach_mips4400
:
759 case bfd_mach_mips4600
:
760 case bfd_mach_mips4650
:
761 case bfd_mach_mips8000
:
762 case bfd_mach_mips9000
:
763 case bfd_mach_mips10000
:
764 case bfd_mach_mips12000
:
765 case bfd_mach_mips16
:
766 case bfd_mach_mipsisa32
:
767 case bfd_mach_mipsisa32r2
:
769 case bfd_mach_mipsisa64
:
770 case bfd_mach_mipsisa64r2
:
771 case bfd_mach_mips_sb1
:
772 /* FIXME: These should be MIPS3, MIPS4, MIPS16, MIPS32, etc. */
773 arch_flags
= M_MIPS2
;
776 arch_flags
= M_UNKNOWN
;
784 case 0: arch_flags
= M_NS32532
; break;
785 case 32032: arch_flags
= M_NS32032
; break;
786 case 32532: arch_flags
= M_NS32532
; break;
787 default: arch_flags
= M_UNKNOWN
; break;
796 if (machine
== 0 || machine
== 255)
805 arch_flags
= M_UNKNOWN
;
808 if (arch_flags
!= M_UNKNOWN
)
816 aout_@var{size}_set_arch_mach
819 bfd_boolean aout_@var{size}_set_arch_mach,
821 enum bfd_architecture arch,
822 unsigned long machine);
825 Set the architecture and the machine of the BFD @var{abfd} to the
826 values @var{arch} and @var{machine}. Verify that @var{abfd}'s format
827 can support the architecture required.
831 NAME (aout
, set_arch_mach
) (bfd
*abfd
,
832 enum bfd_architecture arch
,
833 unsigned long machine
)
835 if (! bfd_default_set_arch_mach (abfd
, arch
, machine
))
838 if (arch
!= bfd_arch_unknown
)
842 NAME (aout
, machine_type
) (arch
, machine
, &unknown
);
847 /* Determine the size of a relocation entry. */
853 obj_reloc_entry_size (abfd
) = RELOC_EXT_SIZE
;
856 obj_reloc_entry_size (abfd
) = RELOC_STD_SIZE
;
860 return (*aout_backend_info (abfd
)->set_sizes
) (abfd
);
864 adjust_o_magic (bfd
*abfd
, struct internal_exec
*execp
)
866 file_ptr pos
= adata (abfd
).exec_bytes_size
;
871 obj_textsec (abfd
)->filepos
= pos
;
872 if (!obj_textsec (abfd
)->user_set_vma
)
873 obj_textsec (abfd
)->vma
= vma
;
875 vma
= obj_textsec (abfd
)->vma
;
877 pos
+= obj_textsec (abfd
)->size
;
878 vma
+= obj_textsec (abfd
)->size
;
881 if (!obj_datasec (abfd
)->user_set_vma
)
883 obj_textsec (abfd
)->size
+= pad
;
886 obj_datasec (abfd
)->vma
= vma
;
889 vma
= obj_datasec (abfd
)->vma
;
890 obj_datasec (abfd
)->filepos
= pos
;
891 pos
+= obj_datasec (abfd
)->size
;
892 vma
+= obj_datasec (abfd
)->size
;
895 if (!obj_bsssec (abfd
)->user_set_vma
)
897 obj_datasec (abfd
)->size
+= pad
;
900 obj_bsssec (abfd
)->vma
= vma
;
904 /* The VMA of the .bss section is set by the VMA of the
905 .data section plus the size of the .data section. We may
906 need to add padding bytes to make this true. */
907 pad
= obj_bsssec (abfd
)->vma
- vma
;
910 obj_datasec (abfd
)->size
+= pad
;
914 obj_bsssec (abfd
)->filepos
= pos
;
916 /* Fix up the exec header. */
917 execp
->a_text
= obj_textsec (abfd
)->size
;
918 execp
->a_data
= obj_datasec (abfd
)->size
;
919 execp
->a_bss
= obj_bsssec (abfd
)->size
;
920 N_SET_MAGIC (*execp
, OMAGIC
);
924 adjust_z_magic (bfd
*abfd
, struct internal_exec
*execp
)
926 bfd_size_type data_pad
, text_pad
;
928 const struct aout_backend_data
*abdp
;
929 /* TRUE if text includes exec header. */
932 abdp
= aout_backend_info (abfd
);
936 && (abdp
->text_includes_header
937 || obj_aout_subformat (abfd
) == q_magic_format
));
938 obj_textsec (abfd
)->filepos
= (ztih
939 ? adata (abfd
).exec_bytes_size
940 : adata (abfd
).zmagic_disk_block_size
);
941 if (! obj_textsec (abfd
)->user_set_vma
)
943 /* ?? Do we really need to check for relocs here? */
944 obj_textsec (abfd
)->vma
= ((abfd
->flags
& HAS_RELOC
)
947 ? (abdp
->default_text_vma
948 + adata (abfd
).exec_bytes_size
)
949 : abdp
->default_text_vma
));
954 /* The .text section is being loaded at an unusual address. We
955 may need to pad it such that the .data section starts at a page
958 text_pad
= ((obj_textsec (abfd
)->filepos
- obj_textsec (abfd
)->vma
)
959 & (adata (abfd
).page_size
- 1));
961 text_pad
= ((- obj_textsec (abfd
)->vma
)
962 & (adata (abfd
).page_size
- 1));
965 /* Find start of data. */
968 text_end
= obj_textsec (abfd
)->filepos
+ obj_textsec (abfd
)->size
;
969 text_pad
+= BFD_ALIGN (text_end
, adata (abfd
).page_size
) - text_end
;
973 /* Note that if page_size == zmagic_disk_block_size, then
974 filepos == page_size, and this case is the same as the ztih
976 text_end
= obj_textsec (abfd
)->size
;
977 text_pad
+= BFD_ALIGN (text_end
, adata (abfd
).page_size
) - text_end
;
978 text_end
+= obj_textsec (abfd
)->filepos
;
980 obj_textsec (abfd
)->size
+= text_pad
;
981 text_end
+= text_pad
;
984 if (!obj_datasec (abfd
)->user_set_vma
)
987 vma
= obj_textsec (abfd
)->vma
+ obj_textsec (abfd
)->size
;
988 obj_datasec (abfd
)->vma
= BFD_ALIGN (vma
, adata (abfd
).segment_size
);
990 if (abdp
&& abdp
->zmagic_mapped_contiguous
)
992 asection
* text
= obj_textsec (abfd
);
993 asection
* data
= obj_datasec (abfd
);
995 text_pad
= data
->vma
- (text
->vma
+ text
->size
);
996 /* Only pad the text section if the data
997 section is going to be placed after it. */
999 text
->size
+= text_pad
;
1001 obj_datasec (abfd
)->filepos
= (obj_textsec (abfd
)->filepos
1002 + obj_textsec (abfd
)->size
);
1004 /* Fix up exec header while we're at it. */
1005 execp
->a_text
= obj_textsec (abfd
)->size
;
1006 if (ztih
&& (!abdp
|| (abdp
&& !abdp
->exec_header_not_counted
)))
1007 execp
->a_text
+= adata (abfd
).exec_bytes_size
;
1008 if (obj_aout_subformat (abfd
) == q_magic_format
)
1009 N_SET_MAGIC (*execp
, QMAGIC
);
1011 N_SET_MAGIC (*execp
, ZMAGIC
);
1013 /* Spec says data section should be rounded up to page boundary. */
1014 obj_datasec (abfd
)->size
1015 = align_power (obj_datasec (abfd
)->size
,
1016 obj_bsssec (abfd
)->alignment_power
);
1017 execp
->a_data
= BFD_ALIGN (obj_datasec (abfd
)->size
,
1018 adata (abfd
).page_size
);
1019 data_pad
= execp
->a_data
- obj_datasec (abfd
)->size
;
1022 if (!obj_bsssec (abfd
)->user_set_vma
)
1023 obj_bsssec (abfd
)->vma
= (obj_datasec (abfd
)->vma
1024 + obj_datasec (abfd
)->size
);
1025 /* If the BSS immediately follows the data section and extra space
1026 in the page is left after the data section, fudge data
1027 in the header so that the bss section looks smaller by that
1028 amount. We'll start the bss section there, and lie to the OS.
1029 (Note that a linker script, as well as the above assignment,
1030 could have explicitly set the BSS vma to immediately follow
1031 the data section.) */
1032 if (align_power (obj_bsssec (abfd
)->vma
, obj_bsssec (abfd
)->alignment_power
)
1033 == obj_datasec (abfd
)->vma
+ obj_datasec (abfd
)->size
)
1034 execp
->a_bss
= (data_pad
> obj_bsssec (abfd
)->size
1035 ? 0 : obj_bsssec (abfd
)->size
- data_pad
);
1037 execp
->a_bss
= obj_bsssec (abfd
)->size
;
1041 adjust_n_magic (bfd
*abfd
, struct internal_exec
*execp
)
1043 file_ptr pos
= adata (abfd
).exec_bytes_size
;
1048 obj_textsec (abfd
)->filepos
= pos
;
1049 if (!obj_textsec (abfd
)->user_set_vma
)
1050 obj_textsec (abfd
)->vma
= vma
;
1052 vma
= obj_textsec (abfd
)->vma
;
1053 pos
+= obj_textsec (abfd
)->size
;
1054 vma
+= obj_textsec (abfd
)->size
;
1057 obj_datasec (abfd
)->filepos
= pos
;
1058 if (!obj_datasec (abfd
)->user_set_vma
)
1059 obj_datasec (abfd
)->vma
= BFD_ALIGN (vma
, adata (abfd
).segment_size
);
1060 vma
= obj_datasec (abfd
)->vma
;
1062 /* Since BSS follows data immediately, see if it needs alignment. */
1063 vma
+= obj_datasec (abfd
)->size
;
1064 pad
= align_power (vma
, obj_bsssec (abfd
)->alignment_power
) - vma
;
1065 obj_datasec (abfd
)->size
+= pad
;
1066 pos
+= obj_datasec (abfd
)->size
;
1069 if (!obj_bsssec (abfd
)->user_set_vma
)
1070 obj_bsssec (abfd
)->vma
= vma
;
1072 vma
= obj_bsssec (abfd
)->vma
;
1074 /* Fix up exec header. */
1075 execp
->a_text
= obj_textsec (abfd
)->size
;
1076 execp
->a_data
= obj_datasec (abfd
)->size
;
1077 execp
->a_bss
= obj_bsssec (abfd
)->size
;
1078 N_SET_MAGIC (*execp
, NMAGIC
);
1082 NAME (aout
, adjust_sizes_and_vmas
) (bfd
*abfd
,
1083 bfd_size_type
*text_size
,
1084 file_ptr
*text_end ATTRIBUTE_UNUSED
)
1086 struct internal_exec
*execp
= exec_hdr (abfd
);
1088 if (! NAME (aout
, make_sections
) (abfd
))
1091 if (adata (abfd
).magic
!= undecided_magic
)
1094 obj_textsec (abfd
)->size
=
1095 align_power (obj_textsec (abfd
)->size
,
1096 obj_textsec (abfd
)->alignment_power
);
1098 *text_size
= obj_textsec (abfd
)->size
;
1099 /* Rule (heuristic) for when to pad to a new page. Note that there
1100 are (at least) two ways demand-paged (ZMAGIC) files have been
1101 handled. Most Berkeley-based systems start the text segment at
1102 (TARGET_PAGE_SIZE). However, newer versions of SUNOS start the text
1103 segment right after the exec header; the latter is counted in the
1104 text segment size, and is paged in by the kernel with the rest of
1107 /* This perhaps isn't the right way to do this, but made it simpler for me
1108 to understand enough to implement it. Better would probably be to go
1109 right from BFD flags to alignment/positioning characteristics. But the
1110 old code was sloppy enough about handling the flags, and had enough
1111 other magic, that it was a little hard for me to understand. I think
1112 I understand it better now, but I haven't time to do the cleanup this
1115 if (abfd
->flags
& D_PAGED
)
1116 /* Whether or not WP_TEXT is set -- let D_PAGED override. */
1117 adata (abfd
).magic
= z_magic
;
1118 else if (abfd
->flags
& WP_TEXT
)
1119 adata (abfd
).magic
= n_magic
;
1121 adata (abfd
).magic
= o_magic
;
1123 #ifdef BFD_AOUT_DEBUG /* requires gcc2 */
1125 fprintf (stderr
, "%s text=<%x,%x,%x> data=<%x,%x,%x> bss=<%x,%x,%x>\n",
1127 switch (adata (abfd
).magic
)
1129 case n_magic
: str
= "NMAGIC"; break;
1130 case o_magic
: str
= "OMAGIC"; break;
1131 case z_magic
: str
= "ZMAGIC"; break;
1136 obj_textsec (abfd
)->vma
, obj_textsec (abfd
)->size
,
1137 obj_textsec (abfd
)->alignment_power
,
1138 obj_datasec (abfd
)->vma
, obj_datasec (abfd
)->size
,
1139 obj_datasec (abfd
)->alignment_power
,
1140 obj_bsssec (abfd
)->vma
, obj_bsssec (abfd
)->size
,
1141 obj_bsssec (abfd
)->alignment_power
);
1145 switch (adata (abfd
).magic
)
1148 adjust_o_magic (abfd
, execp
);
1151 adjust_z_magic (abfd
, execp
);
1154 adjust_n_magic (abfd
, execp
);
1160 #ifdef BFD_AOUT_DEBUG
1161 fprintf (stderr
, " text=<%x,%x,%x> data=<%x,%x,%x> bss=<%x,%x>\n",
1162 obj_textsec (abfd
)->vma
, obj_textsec (abfd
)->size
,
1163 obj_textsec (abfd
)->filepos
,
1164 obj_datasec (abfd
)->vma
, obj_datasec (abfd
)->size
,
1165 obj_datasec (abfd
)->filepos
,
1166 obj_bsssec (abfd
)->vma
, obj_bsssec (abfd
)->size
);
1174 aout_@var{size}_new_section_hook
1177 bfd_boolean aout_@var{size}_new_section_hook,
1182 Called by the BFD in response to a @code{bfd_make_section}
1186 NAME (aout
, new_section_hook
) (bfd
*abfd
, asection
*newsect
)
1188 /* Align to double at least. */
1189 newsect
->alignment_power
= bfd_get_arch_info (abfd
)->section_align_power
;
1191 if (bfd_get_format (abfd
) == bfd_object
)
1193 if (obj_textsec (abfd
) == NULL
&& !strcmp (newsect
->name
, ".text"))
1195 obj_textsec (abfd
)= newsect
;
1196 newsect
->target_index
= N_TEXT
;
1200 if (obj_datasec (abfd
) == NULL
&& !strcmp (newsect
->name
, ".data"))
1202 obj_datasec (abfd
) = newsect
;
1203 newsect
->target_index
= N_DATA
;
1207 if (obj_bsssec (abfd
) == NULL
&& !strcmp (newsect
->name
, ".bss"))
1209 obj_bsssec (abfd
) = newsect
;
1210 newsect
->target_index
= N_BSS
;
1215 /* We allow more than three sections internally. */
1220 NAME (aout
, set_section_contents
) (bfd
*abfd
,
1222 const void * location
,
1224 bfd_size_type count
)
1227 bfd_size_type text_size
;
1229 if (! abfd
->output_has_begun
)
1231 if (! NAME (aout
, adjust_sizes_and_vmas
) (abfd
, &text_size
, &text_end
))
1235 if (section
== obj_bsssec (abfd
))
1237 bfd_set_error (bfd_error_no_contents
);
1241 if (section
!= obj_textsec (abfd
)
1242 && section
!= obj_datasec (abfd
))
1244 if (aout_section_merge_with_text_p (abfd
, section
))
1245 section
->filepos
= obj_textsec (abfd
)->filepos
+
1246 (section
->vma
- obj_textsec (abfd
)->vma
);
1249 (*_bfd_error_handler
)
1250 (_("%s: can not represent section `%s' in a.out object file format"),
1251 bfd_get_filename (abfd
), bfd_get_section_name (abfd
, section
));
1252 bfd_set_error (bfd_error_nonrepresentable_section
);
1259 if (bfd_seek (abfd
, section
->filepos
+ offset
, SEEK_SET
) != 0
1260 || bfd_bwrite (location
, count
, abfd
) != count
)
1267 /* Read the external symbols from an a.out file. */
1270 aout_get_external_symbols (bfd
*abfd
)
1272 if (obj_aout_external_syms (abfd
) == NULL
)
1274 bfd_size_type count
;
1275 struct external_nlist
*syms
;
1278 count
= exec_hdr (abfd
)->a_syms
/ EXTERNAL_NLIST_SIZE
;
1281 if (! bfd_get_file_window (abfd
, obj_sym_filepos (abfd
),
1282 exec_hdr (abfd
)->a_syms
,
1283 &obj_aout_sym_window (abfd
), TRUE
))
1285 syms
= (struct external_nlist
*) obj_aout_sym_window (abfd
).data
;
1287 /* We allocate using malloc to make the values easy to free
1288 later on. If we put them on the objalloc it might not be
1289 possible to free them. */
1290 syms
= bfd_malloc (count
* EXTERNAL_NLIST_SIZE
);
1291 if (syms
== NULL
&& count
!= 0)
1294 amt
= exec_hdr (abfd
)->a_syms
;
1295 if (bfd_seek (abfd
, obj_sym_filepos (abfd
), SEEK_SET
) != 0
1296 || bfd_bread (syms
, amt
, abfd
) != amt
)
1303 obj_aout_external_syms (abfd
) = syms
;
1304 obj_aout_external_sym_count (abfd
) = count
;
1307 if (obj_aout_external_strings (abfd
) == NULL
1308 && exec_hdr (abfd
)->a_syms
!= 0)
1310 unsigned char string_chars
[BYTES_IN_WORD
];
1311 bfd_size_type stringsize
;
1313 bfd_size_type amt
= BYTES_IN_WORD
;
1315 /* Get the size of the strings. */
1316 if (bfd_seek (abfd
, obj_str_filepos (abfd
), SEEK_SET
) != 0
1317 || bfd_bread ((void *) string_chars
, amt
, abfd
) != amt
)
1319 stringsize
= GET_WORD (abfd
, string_chars
);
1322 if (! bfd_get_file_window (abfd
, obj_str_filepos (abfd
), stringsize
,
1323 &obj_aout_string_window (abfd
), TRUE
))
1325 strings
= (char *) obj_aout_string_window (abfd
).data
;
1327 strings
= bfd_malloc (stringsize
+ 1);
1328 if (strings
== NULL
)
1331 /* Skip space for the string count in the buffer for convenience
1332 when using indexes. */
1333 amt
= stringsize
- BYTES_IN_WORD
;
1334 if (bfd_bread (strings
+ BYTES_IN_WORD
, amt
, abfd
) != amt
)
1341 /* Ensure that a zero index yields an empty string. */
1344 strings
[stringsize
- 1] = 0;
1346 obj_aout_external_strings (abfd
) = strings
;
1347 obj_aout_external_string_size (abfd
) = stringsize
;
1353 /* Translate an a.out symbol into a BFD symbol. The desc, other, type
1354 and symbol->value fields of CACHE_PTR will be set from the a.out
1355 nlist structure. This function is responsible for setting
1356 symbol->flags and symbol->section, and adjusting symbol->value. */
1359 translate_from_native_sym_flags (bfd
*abfd
, aout_symbol_type
*cache_ptr
)
1363 if ((cache_ptr
->type
& N_STAB
) != 0
1364 || cache_ptr
->type
== N_FN
)
1368 /* This is a debugging symbol. */
1369 cache_ptr
->symbol
.flags
= BSF_DEBUGGING
;
1371 /* Work out the symbol section. */
1372 switch (cache_ptr
->type
& N_TYPE
)
1376 sec
= obj_textsec (abfd
);
1379 sec
= obj_datasec (abfd
);
1382 sec
= obj_bsssec (abfd
);
1386 sec
= bfd_abs_section_ptr
;
1390 cache_ptr
->symbol
.section
= sec
;
1391 cache_ptr
->symbol
.value
-= sec
->vma
;
1396 /* Get the default visibility. This does not apply to all types, so
1397 we just hold it in a local variable to use if wanted. */
1398 if ((cache_ptr
->type
& N_EXT
) == 0)
1399 visible
= BSF_LOCAL
;
1401 visible
= BSF_GLOBAL
;
1403 switch (cache_ptr
->type
)
1406 case N_ABS
: case N_ABS
| N_EXT
:
1407 cache_ptr
->symbol
.section
= bfd_abs_section_ptr
;
1408 cache_ptr
->symbol
.flags
= visible
;
1411 case N_UNDF
| N_EXT
:
1412 if (cache_ptr
->symbol
.value
!= 0)
1414 /* This is a common symbol. */
1415 cache_ptr
->symbol
.flags
= BSF_GLOBAL
;
1416 cache_ptr
->symbol
.section
= bfd_com_section_ptr
;
1420 cache_ptr
->symbol
.flags
= 0;
1421 cache_ptr
->symbol
.section
= bfd_und_section_ptr
;
1425 case N_TEXT
: case N_TEXT
| N_EXT
:
1426 cache_ptr
->symbol
.section
= obj_textsec (abfd
);
1427 cache_ptr
->symbol
.value
-= cache_ptr
->symbol
.section
->vma
;
1428 cache_ptr
->symbol
.flags
= visible
;
1431 /* N_SETV symbols used to represent set vectors placed in the
1432 data section. They are no longer generated. Theoretically,
1433 it was possible to extract the entries and combine them with
1434 new ones, although I don't know if that was ever actually
1435 done. Unless that feature is restored, treat them as data
1437 case N_SETV
: case N_SETV
| N_EXT
:
1438 case N_DATA
: case N_DATA
| N_EXT
:
1439 cache_ptr
->symbol
.section
= obj_datasec (abfd
);
1440 cache_ptr
->symbol
.value
-= cache_ptr
->symbol
.section
->vma
;
1441 cache_ptr
->symbol
.flags
= visible
;
1444 case N_BSS
: case N_BSS
| N_EXT
:
1445 cache_ptr
->symbol
.section
= obj_bsssec (abfd
);
1446 cache_ptr
->symbol
.value
-= cache_ptr
->symbol
.section
->vma
;
1447 cache_ptr
->symbol
.flags
= visible
;
1450 case N_SETA
: case N_SETA
| N_EXT
:
1451 case N_SETT
: case N_SETT
| N_EXT
:
1452 case N_SETD
: case N_SETD
| N_EXT
:
1453 case N_SETB
: case N_SETB
| N_EXT
:
1455 /* This code is no longer needed. It used to be used to make
1456 the linker handle set symbols, but they are now handled in
1457 the add_symbols routine instead. */
1458 switch (cache_ptr
->type
& N_TYPE
)
1461 cache_ptr
->symbol
.section
= bfd_abs_section_ptr
;
1464 cache_ptr
->symbol
.section
= obj_textsec (abfd
);
1467 cache_ptr
->symbol
.section
= obj_datasec (abfd
);
1470 cache_ptr
->symbol
.section
= obj_bsssec (abfd
);
1474 cache_ptr
->symbol
.flags
|= BSF_CONSTRUCTOR
;
1479 /* This symbol is the text of a warning message. The next
1480 symbol is the symbol to associate the warning with. If a
1481 reference is made to that symbol, a warning is issued. */
1482 cache_ptr
->symbol
.flags
= BSF_DEBUGGING
| BSF_WARNING
;
1483 cache_ptr
->symbol
.section
= bfd_abs_section_ptr
;
1486 case N_INDR
: case N_INDR
| N_EXT
:
1487 /* An indirect symbol. This consists of two symbols in a row.
1488 The first symbol is the name of the indirection. The second
1489 symbol is the name of the target. A reference to the first
1490 symbol becomes a reference to the second. */
1491 cache_ptr
->symbol
.flags
= BSF_DEBUGGING
| BSF_INDIRECT
| visible
;
1492 cache_ptr
->symbol
.section
= bfd_ind_section_ptr
;
1496 cache_ptr
->symbol
.section
= bfd_und_section_ptr
;
1497 cache_ptr
->symbol
.flags
= BSF_WEAK
;
1501 cache_ptr
->symbol
.section
= bfd_abs_section_ptr
;
1502 cache_ptr
->symbol
.flags
= BSF_WEAK
;
1506 cache_ptr
->symbol
.section
= obj_textsec (abfd
);
1507 cache_ptr
->symbol
.value
-= cache_ptr
->symbol
.section
->vma
;
1508 cache_ptr
->symbol
.flags
= BSF_WEAK
;
1512 cache_ptr
->symbol
.section
= obj_datasec (abfd
);
1513 cache_ptr
->symbol
.value
-= cache_ptr
->symbol
.section
->vma
;
1514 cache_ptr
->symbol
.flags
= BSF_WEAK
;
1518 cache_ptr
->symbol
.section
= obj_bsssec (abfd
);
1519 cache_ptr
->symbol
.value
-= cache_ptr
->symbol
.section
->vma
;
1520 cache_ptr
->symbol
.flags
= BSF_WEAK
;
1527 /* Set the fields of SYM_POINTER according to CACHE_PTR. */
1530 translate_to_native_sym_flags (bfd
*abfd
,
1532 struct external_nlist
*sym_pointer
)
1534 bfd_vma value
= cache_ptr
->value
;
1538 /* Mask out any existing type bits in case copying from one section
1540 sym_pointer
->e_type
[0] &= ~N_TYPE
;
1542 sec
= bfd_get_section (cache_ptr
);
1547 /* This case occurs, e.g., for the *DEBUG* section of a COFF
1549 (*_bfd_error_handler
)
1550 (_("%s: can not represent section for symbol `%s' in a.out object file format"),
1551 bfd_get_filename (abfd
),
1552 cache_ptr
->name
!= NULL
? cache_ptr
->name
: _("*unknown*"));
1553 bfd_set_error (bfd_error_nonrepresentable_section
);
1557 if (sec
->output_section
!= NULL
)
1559 off
= sec
->output_offset
;
1560 sec
= sec
->output_section
;
1563 if (bfd_is_abs_section (sec
))
1564 sym_pointer
->e_type
[0] |= N_ABS
;
1565 else if (sec
== obj_textsec (abfd
))
1566 sym_pointer
->e_type
[0] |= N_TEXT
;
1567 else if (sec
== obj_datasec (abfd
))
1568 sym_pointer
->e_type
[0] |= N_DATA
;
1569 else if (sec
== obj_bsssec (abfd
))
1570 sym_pointer
->e_type
[0] |= N_BSS
;
1571 else if (bfd_is_und_section (sec
))
1572 sym_pointer
->e_type
[0] = N_UNDF
| N_EXT
;
1573 else if (bfd_is_ind_section (sec
))
1574 sym_pointer
->e_type
[0] = N_INDR
;
1575 else if (bfd_is_com_section (sec
))
1576 sym_pointer
->e_type
[0] = N_UNDF
| N_EXT
;
1579 if (aout_section_merge_with_text_p (abfd
, sec
))
1580 sym_pointer
->e_type
[0] |= N_TEXT
;
1583 (*_bfd_error_handler
)
1584 (_("%s: can not represent section `%s' in a.out object file format"),
1585 bfd_get_filename (abfd
), bfd_get_section_name (abfd
, sec
));
1586 bfd_set_error (bfd_error_nonrepresentable_section
);
1591 /* Turn the symbol from section relative to absolute again. */
1592 value
+= sec
->vma
+ off
;
1594 if ((cache_ptr
->flags
& BSF_WARNING
) != 0)
1595 sym_pointer
->e_type
[0] = N_WARNING
;
1597 if ((cache_ptr
->flags
& BSF_DEBUGGING
) != 0)
1598 sym_pointer
->e_type
[0] = ((aout_symbol_type
*) cache_ptr
)->type
;
1599 else if ((cache_ptr
->flags
& BSF_GLOBAL
) != 0)
1600 sym_pointer
->e_type
[0] |= N_EXT
;
1601 else if ((cache_ptr
->flags
& BSF_LOCAL
) != 0)
1602 sym_pointer
->e_type
[0] &= ~N_EXT
;
1604 if ((cache_ptr
->flags
& BSF_CONSTRUCTOR
) != 0)
1606 int type
= ((aout_symbol_type
*) cache_ptr
)->type
;
1610 case N_ABS
: type
= N_SETA
; break;
1611 case N_TEXT
: type
= N_SETT
; break;
1612 case N_DATA
: type
= N_SETD
; break;
1613 case N_BSS
: type
= N_SETB
; break;
1615 sym_pointer
->e_type
[0] = type
;
1618 if ((cache_ptr
->flags
& BSF_WEAK
) != 0)
1622 switch (sym_pointer
->e_type
[0] & N_TYPE
)
1625 case N_ABS
: type
= N_WEAKA
; break;
1626 case N_TEXT
: type
= N_WEAKT
; break;
1627 case N_DATA
: type
= N_WEAKD
; break;
1628 case N_BSS
: type
= N_WEAKB
; break;
1629 case N_UNDF
: type
= N_WEAKU
; break;
1631 sym_pointer
->e_type
[0] = type
;
1634 PUT_WORD (abfd
, value
, sym_pointer
->e_value
);
1639 /* Native-level interface to symbols. */
1642 NAME (aout
, make_empty_symbol
) (bfd
*abfd
)
1644 bfd_size_type amt
= sizeof (aout_symbol_type
);
1646 aout_symbol_type
*new = bfd_zalloc (abfd
, amt
);
1649 new->symbol
.the_bfd
= abfd
;
1651 return &new->symbol
;
1654 /* Translate a set of internal symbols into external symbols. */
1657 NAME (aout
, translate_symbol_table
) (bfd
*abfd
,
1658 aout_symbol_type
*in
,
1659 struct external_nlist
*ext
,
1660 bfd_size_type count
,
1662 bfd_size_type strsize
,
1663 bfd_boolean dynamic
)
1665 struct external_nlist
*ext_end
;
1667 ext_end
= ext
+ count
;
1668 for (; ext
< ext_end
; ext
++, in
++)
1672 x
= GET_WORD (abfd
, ext
->e_strx
);
1673 in
->symbol
.the_bfd
= abfd
;
1675 /* For the normal symbols, the zero index points at the number
1676 of bytes in the string table but is to be interpreted as the
1677 null string. For the dynamic symbols, the number of bytes in
1678 the string table is stored in the __DYNAMIC structure and the
1679 zero index points at an actual string. */
1680 if (x
== 0 && ! dynamic
)
1681 in
->symbol
.name
= "";
1682 else if (x
< strsize
)
1683 in
->symbol
.name
= str
+ x
;
1687 in
->symbol
.value
= GET_SWORD (abfd
, ext
->e_value
);
1688 in
->desc
= H_GET_16 (abfd
, ext
->e_desc
);
1689 in
->other
= H_GET_8 (abfd
, ext
->e_other
);
1690 in
->type
= H_GET_8 (abfd
, ext
->e_type
);
1691 in
->symbol
.udata
.p
= NULL
;
1693 if (! translate_from_native_sym_flags (abfd
, in
))
1697 in
->symbol
.flags
|= BSF_DYNAMIC
;
1703 /* We read the symbols into a buffer, which is discarded when this
1704 function exits. We read the strings into a buffer large enough to
1705 hold them all plus all the cached symbol entries. */
1708 NAME (aout
, slurp_symbol_table
) (bfd
*abfd
)
1710 struct external_nlist
*old_external_syms
;
1711 aout_symbol_type
*cached
;
1712 bfd_size_type cached_size
;
1714 /* If there's no work to be done, don't do any. */
1715 if (obj_aout_symbols (abfd
) != NULL
)
1718 old_external_syms
= obj_aout_external_syms (abfd
);
1720 if (! aout_get_external_symbols (abfd
))
1723 cached_size
= obj_aout_external_sym_count (abfd
);
1724 cached_size
*= sizeof (aout_symbol_type
);
1725 cached
= bfd_zmalloc (cached_size
);
1726 if (cached
== NULL
&& cached_size
!= 0)
1729 /* Convert from external symbol information to internal. */
1730 if (! (NAME (aout
, translate_symbol_table
)
1732 obj_aout_external_syms (abfd
),
1733 obj_aout_external_sym_count (abfd
),
1734 obj_aout_external_strings (abfd
),
1735 obj_aout_external_string_size (abfd
),
1742 bfd_get_symcount (abfd
) = obj_aout_external_sym_count (abfd
);
1744 obj_aout_symbols (abfd
) = cached
;
1746 /* It is very likely that anybody who calls this function will not
1747 want the external symbol information, so if it was allocated
1748 because of our call to aout_get_external_symbols, we free it up
1749 right away to save space. */
1750 if (old_external_syms
== NULL
1751 && obj_aout_external_syms (abfd
) != NULL
)
1754 bfd_free_window (&obj_aout_sym_window (abfd
));
1756 free (obj_aout_external_syms (abfd
));
1758 obj_aout_external_syms (abfd
) = NULL
;
1764 /* We use a hash table when writing out symbols so that we only write
1765 out a particular string once. This helps particularly when the
1766 linker writes out stabs debugging entries, because each different
1767 contributing object file tends to have many duplicate stabs
1770 This hash table code breaks dbx on SunOS 4.1.3, so we don't do it
1771 if BFD_TRADITIONAL_FORMAT is set. */
1773 /* Get the index of a string in a strtab, adding it if it is not
1776 static inline bfd_size_type
1777 add_to_stringtab (bfd
*abfd
,
1778 struct bfd_strtab_hash
*tab
,
1783 bfd_size_type index
;
1785 /* An index of 0 always means the empty string. */
1786 if (str
== 0 || *str
== '\0')
1789 /* Don't hash if BFD_TRADITIONAL_FORMAT is set, because SunOS dbx
1790 doesn't understand a hashed string table. */
1792 if ((abfd
->flags
& BFD_TRADITIONAL_FORMAT
) != 0)
1795 index
= _bfd_stringtab_add (tab
, str
, hash
, copy
);
1797 if (index
!= (bfd_size_type
) -1)
1798 /* Add BYTES_IN_WORD to the return value to account for the
1799 space taken up by the string table size. */
1800 index
+= BYTES_IN_WORD
;
1805 /* Write out a strtab. ABFD is already at the right location in the
1809 emit_stringtab (bfd
*abfd
, struct bfd_strtab_hash
*tab
)
1811 bfd_byte buffer
[BYTES_IN_WORD
];
1812 bfd_size_type amt
= BYTES_IN_WORD
;
1814 /* The string table starts with the size. */
1815 PUT_WORD (abfd
, _bfd_stringtab_size (tab
) + BYTES_IN_WORD
, buffer
);
1816 if (bfd_bwrite ((void *) buffer
, amt
, abfd
) != amt
)
1819 return _bfd_stringtab_emit (abfd
, tab
);
1823 NAME (aout
, write_syms
) (bfd
*abfd
)
1825 unsigned int count
;
1826 asymbol
**generic
= bfd_get_outsymbols (abfd
);
1827 struct bfd_strtab_hash
*strtab
;
1829 strtab
= _bfd_stringtab_init ();
1833 for (count
= 0; count
< bfd_get_symcount (abfd
); count
++)
1835 asymbol
*g
= generic
[count
];
1837 struct external_nlist nsp
;
1840 indx
= add_to_stringtab (abfd
, strtab
, g
->name
, FALSE
);
1841 if (indx
== (bfd_size_type
) -1)
1843 PUT_WORD (abfd
, indx
, (bfd_byte
*) nsp
.e_strx
);
1845 if (bfd_asymbol_flavour (g
) == abfd
->xvec
->flavour
)
1847 H_PUT_16 (abfd
, aout_symbol (g
)->desc
, nsp
.e_desc
);
1848 H_PUT_8 (abfd
, aout_symbol (g
)->other
, nsp
.e_other
);
1849 H_PUT_8 (abfd
, aout_symbol (g
)->type
, nsp
.e_type
);
1853 H_PUT_16 (abfd
, 0, nsp
.e_desc
);
1854 H_PUT_8 (abfd
, 0, nsp
.e_other
);
1855 H_PUT_8 (abfd
, 0, nsp
.e_type
);
1858 if (! translate_to_native_sym_flags (abfd
, g
, &nsp
))
1861 amt
= EXTERNAL_NLIST_SIZE
;
1862 if (bfd_bwrite ((void *) &nsp
, amt
, abfd
) != amt
)
1865 /* NB: `KEEPIT' currently overlays `udata.p', so set this only
1866 here, at the end. */
1870 if (! emit_stringtab (abfd
, strtab
))
1873 _bfd_stringtab_free (strtab
);
1878 _bfd_stringtab_free (strtab
);
1883 NAME (aout
, canonicalize_symtab
) (bfd
*abfd
, asymbol
**location
)
1885 unsigned int counter
= 0;
1886 aout_symbol_type
*symbase
;
1888 if (!NAME (aout
, slurp_symbol_table
) (abfd
))
1891 for (symbase
= obj_aout_symbols (abfd
);
1892 counter
++ < bfd_get_symcount (abfd
);
1894 *(location
++) = (asymbol
*) (symbase
++);
1896 return bfd_get_symcount (abfd
);
1899 /* Standard reloc stuff. */
1900 /* Output standard relocation information to a file in target byte order. */
1902 extern void NAME (aout
, swap_std_reloc_out
)
1903 (bfd
*, arelent
*, struct reloc_std_external
*);
1906 NAME (aout
, swap_std_reloc_out
) (bfd
*abfd
,
1908 struct reloc_std_external
*natptr
)
1911 asymbol
*sym
= *(g
->sym_ptr_ptr
);
1913 unsigned int r_length
;
1915 int r_baserel
, r_jmptable
, r_relative
;
1916 asection
*output_section
= sym
->section
->output_section
;
1918 PUT_WORD (abfd
, g
->address
, natptr
->r_address
);
1920 r_length
= g
->howto
->size
; /* Size as a power of two. */
1921 r_pcrel
= (int) g
->howto
->pc_relative
; /* Relative to PC? */
1922 /* XXX This relies on relocs coming from a.out files. */
1923 r_baserel
= (g
->howto
->type
& 8) != 0;
1924 r_jmptable
= (g
->howto
->type
& 16) != 0;
1925 r_relative
= (g
->howto
->type
& 32) != 0;
1927 /* Name was clobbered by aout_write_syms to be symbol index. */
1929 /* If this relocation is relative to a symbol then set the
1930 r_index to the symbols index, and the r_extern bit.
1932 Absolute symbols can come in in two ways, either as an offset
1933 from the abs section, or as a symbol which has an abs value.
1934 check for that here. */
1936 if (bfd_is_com_section (output_section
)
1937 || bfd_is_abs_section (output_section
)
1938 || bfd_is_und_section (output_section
))
1940 if (bfd_abs_section_ptr
->symbol
== sym
)
1942 /* Whoops, looked like an abs symbol, but is
1943 really an offset from the abs section. */
1949 /* Fill in symbol. */
1951 r_index
= (*(g
->sym_ptr_ptr
))->KEEPIT
;
1956 /* Just an ordinary section. */
1958 r_index
= output_section
->target_index
;
1961 /* Now the fun stuff. */
1962 if (bfd_header_big_endian (abfd
))
1964 natptr
->r_index
[0] = r_index
>> 16;
1965 natptr
->r_index
[1] = r_index
>> 8;
1966 natptr
->r_index
[2] = r_index
;
1967 natptr
->r_type
[0] = ((r_extern
? RELOC_STD_BITS_EXTERN_BIG
: 0)
1968 | (r_pcrel
? RELOC_STD_BITS_PCREL_BIG
: 0)
1969 | (r_baserel
? RELOC_STD_BITS_BASEREL_BIG
: 0)
1970 | (r_jmptable
? RELOC_STD_BITS_JMPTABLE_BIG
: 0)
1971 | (r_relative
? RELOC_STD_BITS_RELATIVE_BIG
: 0)
1972 | (r_length
<< RELOC_STD_BITS_LENGTH_SH_BIG
));
1976 natptr
->r_index
[2] = r_index
>> 16;
1977 natptr
->r_index
[1] = r_index
>> 8;
1978 natptr
->r_index
[0] = r_index
;
1979 natptr
->r_type
[0] = ((r_extern
? RELOC_STD_BITS_EXTERN_LITTLE
: 0)
1980 | (r_pcrel
? RELOC_STD_BITS_PCREL_LITTLE
: 0)
1981 | (r_baserel
? RELOC_STD_BITS_BASEREL_LITTLE
: 0)
1982 | (r_jmptable
? RELOC_STD_BITS_JMPTABLE_LITTLE
: 0)
1983 | (r_relative
? RELOC_STD_BITS_RELATIVE_LITTLE
: 0)
1984 | (r_length
<< RELOC_STD_BITS_LENGTH_SH_LITTLE
));
1988 /* Extended stuff. */
1989 /* Output extended relocation information to a file in target byte order. */
1991 extern void NAME (aout
, swap_ext_reloc_out
)
1992 (bfd
*, arelent
*, struct reloc_ext_external
*);
1995 NAME (aout
, swap_ext_reloc_out
) (bfd
*abfd
,
1997 struct reloc_ext_external
*natptr
)
2001 unsigned int r_type
;
2003 asymbol
*sym
= *(g
->sym_ptr_ptr
);
2004 asection
*output_section
= sym
->section
->output_section
;
2006 PUT_WORD (abfd
, g
->address
, natptr
->r_address
);
2008 r_type
= (unsigned int) g
->howto
->type
;
2010 r_addend
= g
->addend
;
2011 if ((sym
->flags
& BSF_SECTION_SYM
) != 0)
2012 r_addend
+= (*(g
->sym_ptr_ptr
))->section
->output_section
->vma
;
2014 /* If this relocation is relative to a symbol then set the
2015 r_index to the symbols index, and the r_extern bit.
2017 Absolute symbols can come in in two ways, either as an offset
2018 from the abs section, or as a symbol which has an abs value.
2019 check for that here. */
2020 if (bfd_is_abs_section (bfd_get_section (sym
)))
2025 else if ((sym
->flags
& BSF_SECTION_SYM
) == 0)
2027 if (bfd_is_und_section (bfd_get_section (sym
))
2028 || (sym
->flags
& BSF_GLOBAL
) != 0)
2032 r_index
= (*(g
->sym_ptr_ptr
))->KEEPIT
;
2036 /* Just an ordinary section. */
2038 r_index
= output_section
->target_index
;
2041 /* Now the fun stuff. */
2042 if (bfd_header_big_endian (abfd
))
2044 natptr
->r_index
[0] = r_index
>> 16;
2045 natptr
->r_index
[1] = r_index
>> 8;
2046 natptr
->r_index
[2] = r_index
;
2047 natptr
->r_type
[0] = ((r_extern
? RELOC_EXT_BITS_EXTERN_BIG
: 0)
2048 | (r_type
<< RELOC_EXT_BITS_TYPE_SH_BIG
));
2052 natptr
->r_index
[2] = r_index
>> 16;
2053 natptr
->r_index
[1] = r_index
>> 8;
2054 natptr
->r_index
[0] = r_index
;
2055 natptr
->r_type
[0] = ((r_extern
? RELOC_EXT_BITS_EXTERN_LITTLE
: 0)
2056 | (r_type
<< RELOC_EXT_BITS_TYPE_SH_LITTLE
));
2059 PUT_WORD (abfd
, r_addend
, natptr
->r_addend
);
2062 /* BFD deals internally with all things based from the section they're
2063 in. so, something in 10 bytes into a text section with a base of
2064 50 would have a symbol (.text+10) and know .text vma was 50.
2066 Aout keeps all it's symbols based from zero, so the symbol would
2067 contain 60. This macro subs the base of each section from the value
2068 to give the true offset from the section. */
2070 #define MOVE_ADDRESS(ad) \
2073 /* Undefined symbol. */ \
2074 cache_ptr->sym_ptr_ptr = symbols + r_index; \
2075 cache_ptr->addend = ad; \
2079 /* Defined, section relative. Replace symbol with pointer to \
2080 symbol which points to section. */ \
2084 case N_TEXT | N_EXT: \
2085 cache_ptr->sym_ptr_ptr = obj_textsec (abfd)->symbol_ptr_ptr; \
2086 cache_ptr->addend = ad - su->textsec->vma; \
2089 case N_DATA | N_EXT: \
2090 cache_ptr->sym_ptr_ptr = obj_datasec (abfd)->symbol_ptr_ptr; \
2091 cache_ptr->addend = ad - su->datasec->vma; \
2094 case N_BSS | N_EXT: \
2095 cache_ptr->sym_ptr_ptr = obj_bsssec (abfd)->symbol_ptr_ptr; \
2096 cache_ptr->addend = ad - su->bsssec->vma; \
2100 case N_ABS | N_EXT: \
2101 cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr; \
2102 cache_ptr->addend = ad; \
2108 NAME (aout
, swap_ext_reloc_in
) (bfd
*abfd
,
2109 struct reloc_ext_external
*bytes
,
2112 bfd_size_type symcount
)
2114 unsigned int r_index
;
2116 unsigned int r_type
;
2117 struct aoutdata
*su
= &(abfd
->tdata
.aout_data
->a
);
2119 cache_ptr
->address
= (GET_SWORD (abfd
, bytes
->r_address
));
2121 /* Now the fun stuff. */
2122 if (bfd_header_big_endian (abfd
))
2124 r_index
= (((unsigned int) bytes
->r_index
[0] << 16)
2125 | ((unsigned int) bytes
->r_index
[1] << 8)
2126 | bytes
->r_index
[2]);
2127 r_extern
= (0 != (bytes
->r_type
[0] & RELOC_EXT_BITS_EXTERN_BIG
));
2128 r_type
= ((bytes
->r_type
[0] & RELOC_EXT_BITS_TYPE_BIG
)
2129 >> RELOC_EXT_BITS_TYPE_SH_BIG
);
2133 r_index
= (((unsigned int) bytes
->r_index
[2] << 16)
2134 | ((unsigned int) bytes
->r_index
[1] << 8)
2135 | bytes
->r_index
[0]);
2136 r_extern
= (0 != (bytes
->r_type
[0] & RELOC_EXT_BITS_EXTERN_LITTLE
));
2137 r_type
= ((bytes
->r_type
[0] & RELOC_EXT_BITS_TYPE_LITTLE
)
2138 >> RELOC_EXT_BITS_TYPE_SH_LITTLE
);
2141 cache_ptr
->howto
= howto_table_ext
+ r_type
;
2143 /* Base relative relocs are always against the symbol table,
2144 regardless of the setting of r_extern. r_extern just reflects
2145 whether the symbol the reloc is against is local or global. */
2146 if (r_type
== (unsigned int) RELOC_BASE10
2147 || r_type
== (unsigned int) RELOC_BASE13
2148 || r_type
== (unsigned int) RELOC_BASE22
)
2151 if (r_extern
&& r_index
> symcount
)
2153 /* We could arrange to return an error, but it might be useful
2154 to see the file even if it is bad. */
2159 MOVE_ADDRESS (GET_SWORD (abfd
, bytes
->r_addend
));
2163 NAME (aout
, swap_std_reloc_in
) (bfd
*abfd
,
2164 struct reloc_std_external
*bytes
,
2167 bfd_size_type symcount
)
2169 unsigned int r_index
;
2171 unsigned int r_length
;
2173 int r_baserel
, r_jmptable
, r_relative
;
2174 struct aoutdata
*su
= &(abfd
->tdata
.aout_data
->a
);
2175 unsigned int howto_idx
;
2177 cache_ptr
->address
= H_GET_32 (abfd
, bytes
->r_address
);
2179 /* Now the fun stuff. */
2180 if (bfd_header_big_endian (abfd
))
2182 r_index
= (((unsigned int) bytes
->r_index
[0] << 16)
2183 | ((unsigned int) bytes
->r_index
[1] << 8)
2184 | bytes
->r_index
[2]);
2185 r_extern
= (0 != (bytes
->r_type
[0] & RELOC_STD_BITS_EXTERN_BIG
));
2186 r_pcrel
= (0 != (bytes
->r_type
[0] & RELOC_STD_BITS_PCREL_BIG
));
2187 r_baserel
= (0 != (bytes
->r_type
[0] & RELOC_STD_BITS_BASEREL_BIG
));
2188 r_jmptable
= (0 != (bytes
->r_type
[0] & RELOC_STD_BITS_JMPTABLE_BIG
));
2189 r_relative
= (0 != (bytes
->r_type
[0] & RELOC_STD_BITS_RELATIVE_BIG
));
2190 r_length
= ((bytes
->r_type
[0] & RELOC_STD_BITS_LENGTH_BIG
)
2191 >> RELOC_STD_BITS_LENGTH_SH_BIG
);
2195 r_index
= (((unsigned int) bytes
->r_index
[2] << 16)
2196 | ((unsigned int) bytes
->r_index
[1] << 8)
2197 | bytes
->r_index
[0]);
2198 r_extern
= (0 != (bytes
->r_type
[0] & RELOC_STD_BITS_EXTERN_LITTLE
));
2199 r_pcrel
= (0 != (bytes
->r_type
[0] & RELOC_STD_BITS_PCREL_LITTLE
));
2200 r_baserel
= (0 != (bytes
->r_type
[0] & RELOC_STD_BITS_BASEREL_LITTLE
));
2201 r_jmptable
= (0 != (bytes
->r_type
[0] & RELOC_STD_BITS_JMPTABLE_LITTLE
));
2202 r_relative
= (0 != (bytes
->r_type
[0] & RELOC_STD_BITS_RELATIVE_LITTLE
));
2203 r_length
= ((bytes
->r_type
[0] & RELOC_STD_BITS_LENGTH_LITTLE
)
2204 >> RELOC_STD_BITS_LENGTH_SH_LITTLE
);
2207 howto_idx
= (r_length
+ 4 * r_pcrel
+ 8 * r_baserel
2208 + 16 * r_jmptable
+ 32 * r_relative
);
2209 BFD_ASSERT (howto_idx
< TABLE_SIZE (howto_table_std
));
2210 cache_ptr
->howto
= howto_table_std
+ howto_idx
;
2211 BFD_ASSERT (cache_ptr
->howto
->type
!= (unsigned int) -1);
2213 /* Base relative relocs are always against the symbol table,
2214 regardless of the setting of r_extern. r_extern just reflects
2215 whether the symbol the reloc is against is local or global. */
2219 if (r_extern
&& r_index
> symcount
)
2221 /* We could arrange to return an error, but it might be useful
2222 to see the file even if it is bad. */
2230 /* Read and swap the relocs for a section. */
2233 NAME (aout
, slurp_reloc_table
) (bfd
*abfd
, sec_ptr asect
, asymbol
**symbols
)
2235 bfd_size_type count
;
2236 bfd_size_type reloc_size
;
2238 arelent
*reloc_cache
;
2240 unsigned int counter
= 0;
2244 if (asect
->relocation
)
2247 if (asect
->flags
& SEC_CONSTRUCTOR
)
2250 if (asect
== obj_datasec (abfd
))
2251 reloc_size
= exec_hdr (abfd
)->a_drsize
;
2252 else if (asect
== obj_textsec (abfd
))
2253 reloc_size
= exec_hdr (abfd
)->a_trsize
;
2254 else if (asect
== obj_bsssec (abfd
))
2258 bfd_set_error (bfd_error_invalid_operation
);
2262 if (bfd_seek (abfd
, asect
->rel_filepos
, SEEK_SET
) != 0)
2265 each_size
= obj_reloc_entry_size (abfd
);
2267 count
= reloc_size
/ each_size
;
2269 amt
= count
* sizeof (arelent
);
2270 reloc_cache
= bfd_zmalloc (amt
);
2271 if (reloc_cache
== NULL
&& count
!= 0)
2274 relocs
= bfd_malloc (reloc_size
);
2275 if (relocs
== NULL
&& reloc_size
!= 0)
2281 if (bfd_bread (relocs
, reloc_size
, abfd
) != reloc_size
)
2288 cache_ptr
= reloc_cache
;
2289 if (each_size
== RELOC_EXT_SIZE
)
2291 struct reloc_ext_external
*rptr
= (struct reloc_ext_external
*) relocs
;
2293 for (; counter
< count
; counter
++, rptr
++, cache_ptr
++)
2294 MY_swap_ext_reloc_in (abfd
, rptr
, cache_ptr
, symbols
,
2295 (bfd_size_type
) bfd_get_symcount (abfd
));
2299 struct reloc_std_external
*rptr
= (struct reloc_std_external
*) relocs
;
2301 for (; counter
< count
; counter
++, rptr
++, cache_ptr
++)
2302 MY_swap_std_reloc_in (abfd
, rptr
, cache_ptr
, symbols
,
2303 (bfd_size_type
) bfd_get_symcount (abfd
));
2308 asect
->relocation
= reloc_cache
;
2309 asect
->reloc_count
= cache_ptr
- reloc_cache
;
2314 /* Write out a relocation section into an object file. */
2317 NAME (aout
, squirt_out_relocs
) (bfd
*abfd
, asection
*section
)
2320 unsigned char *native
, *natptr
;
2323 unsigned int count
= section
->reloc_count
;
2324 bfd_size_type natsize
;
2326 if (count
== 0 || section
->orelocation
== NULL
)
2329 each_size
= obj_reloc_entry_size (abfd
);
2330 natsize
= (bfd_size_type
) each_size
* count
;
2331 native
= bfd_zalloc (abfd
, natsize
);
2335 generic
= section
->orelocation
;
2337 if (each_size
== RELOC_EXT_SIZE
)
2339 for (natptr
= native
;
2341 --count
, natptr
+= each_size
, ++generic
)
2342 MY_swap_ext_reloc_out (abfd
, *generic
,
2343 (struct reloc_ext_external
*) natptr
);
2347 for (natptr
= native
;
2349 --count
, natptr
+= each_size
, ++generic
)
2350 MY_swap_std_reloc_out (abfd
, *generic
,
2351 (struct reloc_std_external
*) natptr
);
2354 if (bfd_bwrite ((void *) native
, natsize
, abfd
) != natsize
)
2356 bfd_release (abfd
, native
);
2359 bfd_release (abfd
, native
);
2364 /* This is stupid. This function should be a boolean predicate. */
2367 NAME (aout
, canonicalize_reloc
) (bfd
*abfd
,
2372 arelent
*tblptr
= section
->relocation
;
2375 if (section
== obj_bsssec (abfd
))
2381 if (!(tblptr
|| NAME (aout
, slurp_reloc_table
) (abfd
, section
, symbols
)))
2384 if (section
->flags
& SEC_CONSTRUCTOR
)
2386 arelent_chain
*chain
= section
->constructor_chain
;
2387 for (count
= 0; count
< section
->reloc_count
; count
++)
2389 *relptr
++ = &chain
->relent
;
2390 chain
= chain
->next
;
2395 tblptr
= section
->relocation
;
2397 for (count
= 0; count
++ < section
->reloc_count
; )
2399 *relptr
++ = tblptr
++;
2404 return section
->reloc_count
;
2408 NAME (aout
, get_reloc_upper_bound
) (bfd
*abfd
, sec_ptr asect
)
2410 if (bfd_get_format (abfd
) != bfd_object
)
2412 bfd_set_error (bfd_error_invalid_operation
);
2416 if (asect
->flags
& SEC_CONSTRUCTOR
)
2417 return sizeof (arelent
*) * (asect
->reloc_count
+ 1);
2419 if (asect
== obj_datasec (abfd
))
2420 return sizeof (arelent
*)
2421 * ((exec_hdr (abfd
)->a_drsize
/ obj_reloc_entry_size (abfd
))
2424 if (asect
== obj_textsec (abfd
))
2425 return sizeof (arelent
*)
2426 * ((exec_hdr (abfd
)->a_trsize
/ obj_reloc_entry_size (abfd
))
2429 if (asect
== obj_bsssec (abfd
))
2430 return sizeof (arelent
*);
2432 if (asect
== obj_bsssec (abfd
))
2435 bfd_set_error (bfd_error_invalid_operation
);
2440 NAME (aout
, get_symtab_upper_bound
) (bfd
*abfd
)
2442 if (!NAME (aout
, slurp_symbol_table
) (abfd
))
2445 return (bfd_get_symcount (abfd
)+1) * (sizeof (aout_symbol_type
*));
2449 NAME (aout
, get_lineno
) (bfd
*ignore_abfd ATTRIBUTE_UNUSED
,
2450 asymbol
*ignore_symbol ATTRIBUTE_UNUSED
)
2456 NAME (aout
, get_symbol_info
) (bfd
*ignore_abfd ATTRIBUTE_UNUSED
,
2460 bfd_symbol_info (symbol
, ret
);
2462 if (ret
->type
== '?')
2464 int type_code
= aout_symbol (symbol
)->type
& 0xff;
2465 const char *stab_name
= bfd_get_stab_name (type_code
);
2466 static char buf
[10];
2468 if (stab_name
== NULL
)
2470 sprintf (buf
, "(%d)", type_code
);
2474 ret
->stab_type
= type_code
;
2475 ret
->stab_other
= (unsigned) (aout_symbol (symbol
)->other
& 0xff);
2476 ret
->stab_desc
= (unsigned) (aout_symbol (symbol
)->desc
& 0xffff);
2477 ret
->stab_name
= stab_name
;
2482 NAME (aout
, print_symbol
) (bfd
*abfd
,
2485 bfd_print_symbol_type how
)
2487 FILE *file
= (FILE *)afile
;
2491 case bfd_print_symbol_name
:
2493 fprintf (file
,"%s", symbol
->name
);
2495 case bfd_print_symbol_more
:
2496 fprintf (file
,"%4x %2x %2x",
2497 (unsigned) (aout_symbol (symbol
)->desc
& 0xffff),
2498 (unsigned) (aout_symbol (symbol
)->other
& 0xff),
2499 (unsigned) (aout_symbol (symbol
)->type
));
2501 case bfd_print_symbol_all
:
2503 const char *section_name
= symbol
->section
->name
;
2505 bfd_print_symbol_vandf (abfd
, (void *)file
, symbol
);
2507 fprintf (file
," %-5s %04x %02x %02x",
2509 (unsigned) (aout_symbol (symbol
)->desc
& 0xffff),
2510 (unsigned) (aout_symbol (symbol
)->other
& 0xff),
2511 (unsigned) (aout_symbol (symbol
)->type
& 0xff));
2513 fprintf (file
," %s", symbol
->name
);
2519 /* If we don't have to allocate more than 1MB to hold the generic
2520 symbols, we use the generic minisymbol methord: it's faster, since
2521 it only translates the symbols once, not multiple times. */
2522 #define MINISYM_THRESHOLD (1000000 / sizeof (asymbol))
2524 /* Read minisymbols. For minisymbols, we use the unmodified a.out
2525 symbols. The minisymbol_to_symbol function translates these into
2526 BFD asymbol structures. */
2529 NAME (aout
, read_minisymbols
) (bfd
*abfd
,
2530 bfd_boolean dynamic
,
2532 unsigned int *sizep
)
2535 /* We could handle the dynamic symbols here as well, but it's
2536 easier to hand them off. */
2537 return _bfd_generic_read_minisymbols (abfd
, dynamic
, minisymsp
, sizep
);
2539 if (! aout_get_external_symbols (abfd
))
2542 if (obj_aout_external_sym_count (abfd
) < MINISYM_THRESHOLD
)
2543 return _bfd_generic_read_minisymbols (abfd
, dynamic
, minisymsp
, sizep
);
2545 *minisymsp
= (void *) obj_aout_external_syms (abfd
);
2547 /* By passing the external symbols back from this routine, we are
2548 giving up control over the memory block. Clear
2549 obj_aout_external_syms, so that we do not try to free it
2551 obj_aout_external_syms (abfd
) = NULL
;
2553 *sizep
= EXTERNAL_NLIST_SIZE
;
2554 return obj_aout_external_sym_count (abfd
);
2557 /* Convert a minisymbol to a BFD asymbol. A minisymbol is just an
2558 unmodified a.out symbol. The SYM argument is a structure returned
2559 by bfd_make_empty_symbol, which we fill in here. */
2562 NAME (aout
, minisymbol_to_symbol
) (bfd
*abfd
,
2563 bfd_boolean dynamic
,
2564 const void * minisym
,
2568 || obj_aout_external_sym_count (abfd
) < MINISYM_THRESHOLD
)
2569 return _bfd_generic_minisymbol_to_symbol (abfd
, dynamic
, minisym
, sym
);
2571 memset (sym
, 0, sizeof (aout_symbol_type
));
2573 /* We call translate_symbol_table to translate a single symbol. */
2574 if (! (NAME (aout
, translate_symbol_table
)
2576 (aout_symbol_type
*) sym
,
2577 (struct external_nlist
*) minisym
,
2579 obj_aout_external_strings (abfd
),
2580 obj_aout_external_string_size (abfd
),
2587 /* Provided a BFD, a section and an offset into the section, calculate
2588 and return the name of the source file and the line nearest to the
2592 NAME (aout
, find_nearest_line
) (bfd
*abfd
,
2596 const char **filename_ptr
,
2597 const char **functionname_ptr
,
2598 unsigned int *line_ptr
)
2600 /* Run down the file looking for the filename, function and linenumber. */
2602 const char *directory_name
= NULL
;
2603 const char *main_file_name
= NULL
;
2604 const char *current_file_name
= NULL
;
2605 const char *line_file_name
= NULL
; /* Value of current_file_name at line number. */
2606 const char *line_directory_name
= NULL
; /* Value of directory_name at line number. */
2607 bfd_vma low_line_vma
= 0;
2608 bfd_vma low_func_vma
= 0;
2610 bfd_size_type filelen
, funclen
;
2613 *filename_ptr
= abfd
->filename
;
2614 *functionname_ptr
= 0;
2617 if (symbols
!= NULL
)
2619 for (p
= symbols
; *p
; p
++)
2621 aout_symbol_type
*q
= (aout_symbol_type
*) (*p
);
2626 /* If this looks like a file name symbol, and it comes after
2627 the line number we have found so far, but before the
2628 offset, then we have probably not found the right line
2630 if (q
->symbol
.value
<= offset
2631 && ((q
->symbol
.value
> low_line_vma
2632 && (line_file_name
!= NULL
2634 || (q
->symbol
.value
> low_func_vma
2637 const char *symname
;
2639 symname
= q
->symbol
.name
;
2640 if (strcmp (symname
+ strlen (symname
) - 2, ".o") == 0)
2642 if (q
->symbol
.value
> low_line_vma
)
2645 line_file_name
= NULL
;
2647 if (q
->symbol
.value
> low_func_vma
)
2654 /* If this symbol is less than the offset, but greater than
2655 the line number we have found so far, then we have not
2656 found the right line number. */
2657 if (q
->symbol
.value
<= offset
)
2659 if (q
->symbol
.value
> low_line_vma
)
2662 line_file_name
= NULL
;
2664 if (q
->symbol
.value
> low_func_vma
)
2668 main_file_name
= current_file_name
= q
->symbol
.name
;
2669 /* Look ahead to next symbol to check if that too is an N_SO. */
2673 q
= (aout_symbol_type
*) (*p
);
2674 if (q
->type
!= (int)N_SO
)
2677 /* Found a second N_SO First is directory; second is filename. */
2678 directory_name
= current_file_name
;
2679 main_file_name
= current_file_name
= q
->symbol
.name
;
2680 if (obj_textsec (abfd
) != section
)
2684 current_file_name
= q
->symbol
.name
;
2691 /* We'll keep this if it resolves nearer than the one we have
2693 if (q
->symbol
.value
>= low_line_vma
2694 && q
->symbol
.value
<= offset
)
2696 *line_ptr
= q
->desc
;
2697 low_line_vma
= q
->symbol
.value
;
2698 line_file_name
= current_file_name
;
2699 line_directory_name
= directory_name
;
2704 /* We'll keep this if it is nearer than the one we have already. */
2705 if (q
->symbol
.value
>= low_func_vma
&&
2706 q
->symbol
.value
<= offset
)
2708 low_func_vma
= q
->symbol
.value
;
2709 func
= (asymbol
*)q
;
2711 else if (q
->symbol
.value
> offset
)
2722 main_file_name
= line_file_name
;
2723 directory_name
= line_directory_name
;
2726 if (main_file_name
== NULL
2727 || IS_ABSOLUTE_PATH (main_file_name
)
2728 || directory_name
== NULL
)
2731 filelen
= strlen (directory_name
) + strlen (main_file_name
);
2736 funclen
= strlen (bfd_asymbol_name (func
));
2738 if (adata (abfd
).line_buf
!= NULL
)
2739 free (adata (abfd
).line_buf
);
2741 if (filelen
+ funclen
== 0)
2742 adata (abfd
).line_buf
= buf
= NULL
;
2745 buf
= bfd_malloc (filelen
+ funclen
+ 3);
2746 adata (abfd
).line_buf
= buf
;
2751 if (main_file_name
!= NULL
)
2753 if (IS_ABSOLUTE_PATH (main_file_name
) || directory_name
== NULL
)
2754 *filename_ptr
= main_file_name
;
2757 sprintf (buf
, "%s%s", directory_name
, main_file_name
);
2758 *filename_ptr
= buf
;
2765 const char *function
= func
->name
;
2768 /* The caller expects a symbol name. We actually have a
2769 function name, without the leading underscore. Put the
2770 underscore back in, so that the caller gets a symbol name. */
2771 if (bfd_get_symbol_leading_char (abfd
) == '\0')
2772 strcpy (buf
, function
);
2775 buf
[0] = bfd_get_symbol_leading_char (abfd
);
2776 strcpy (buf
+ 1, function
);
2778 /* Have to remove : stuff. */
2779 colon
= strchr (buf
, ':');
2782 *functionname_ptr
= buf
;
2789 NAME (aout
, sizeof_headers
) (bfd
*abfd
, bfd_boolean execable ATTRIBUTE_UNUSED
)
2791 return adata (abfd
).exec_bytes_size
;
2794 /* Free all information we have cached for this BFD. We can always
2795 read it again later if we need it. */
2798 NAME (aout
, bfd_free_cached_info
) (bfd
*abfd
)
2802 if (bfd_get_format (abfd
) != bfd_object
2803 || abfd
->tdata
.aout_data
== NULL
)
2806 #define BFCI_FREE(x) if (x != NULL) { free (x); x = NULL; }
2807 BFCI_FREE (obj_aout_symbols (abfd
));
2809 obj_aout_external_syms (abfd
) = 0;
2810 bfd_free_window (&obj_aout_sym_window (abfd
));
2811 bfd_free_window (&obj_aout_string_window (abfd
));
2812 obj_aout_external_strings (abfd
) = 0;
2814 BFCI_FREE (obj_aout_external_syms (abfd
));
2815 BFCI_FREE (obj_aout_external_strings (abfd
));
2817 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
2818 BFCI_FREE (o
->relocation
);
2824 /* a.out link code. */
2826 /* Routine to create an entry in an a.out link hash table. */
2828 struct bfd_hash_entry
*
2829 NAME (aout
, link_hash_newfunc
) (struct bfd_hash_entry
*entry
,
2830 struct bfd_hash_table
*table
,
2833 struct aout_link_hash_entry
*ret
= (struct aout_link_hash_entry
*) entry
;
2835 /* Allocate the structure if it has not already been allocated by a
2838 ret
= bfd_hash_allocate (table
, sizeof (* ret
));
2842 /* Call the allocation method of the superclass. */
2843 ret
= ((struct aout_link_hash_entry
*)
2844 _bfd_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
2848 /* Set local fields. */
2849 ret
->written
= FALSE
;
2853 return (struct bfd_hash_entry
*) ret
;
2856 /* Initialize an a.out link hash table. */
2859 NAME (aout
, link_hash_table_init
) (struct aout_link_hash_table
*table
,
2861 struct bfd_hash_entry
*(*newfunc
)
2862 (struct bfd_hash_entry
*, struct bfd_hash_table
*,
2865 return _bfd_link_hash_table_init (&table
->root
, abfd
, newfunc
);
2868 /* Create an a.out link hash table. */
2870 struct bfd_link_hash_table
*
2871 NAME (aout
, link_hash_table_create
) (bfd
*abfd
)
2873 struct aout_link_hash_table
*ret
;
2874 bfd_size_type amt
= sizeof (* ret
);
2876 ret
= bfd_malloc (amt
);
2880 if (! NAME (aout
, link_hash_table_init
) (ret
, abfd
,
2881 NAME (aout
, link_hash_newfunc
)))
2889 /* Add all symbols from an object file to the hash table. */
2892 aout_link_add_symbols (bfd
*abfd
, struct bfd_link_info
*info
)
2894 bfd_boolean (*add_one_symbol
)
2895 (struct bfd_link_info
*, bfd
*, const char *, flagword
, asection
*,
2896 bfd_vma
, const char *, bfd_boolean
, bfd_boolean
,
2897 struct bfd_link_hash_entry
**);
2898 struct external_nlist
*syms
;
2899 bfd_size_type sym_count
;
2902 struct aout_link_hash_entry
**sym_hash
;
2903 struct external_nlist
*p
;
2904 struct external_nlist
*pend
;
2907 syms
= obj_aout_external_syms (abfd
);
2908 sym_count
= obj_aout_external_sym_count (abfd
);
2909 strings
= obj_aout_external_strings (abfd
);
2910 if (info
->keep_memory
)
2915 if (aout_backend_info (abfd
)->add_dynamic_symbols
!= NULL
)
2917 if (! ((*aout_backend_info (abfd
)->add_dynamic_symbols
)
2918 (abfd
, info
, &syms
, &sym_count
, &strings
)))
2922 /* We keep a list of the linker hash table entries that correspond
2923 to particular symbols. We could just look them up in the hash
2924 table, but keeping the list is more efficient. Perhaps this
2925 should be conditional on info->keep_memory. */
2926 amt
= sym_count
* sizeof (struct aout_link_hash_entry
*);
2927 sym_hash
= bfd_alloc (abfd
, amt
);
2928 if (sym_hash
== NULL
&& sym_count
!= 0)
2930 obj_aout_sym_hashes (abfd
) = sym_hash
;
2932 add_one_symbol
= aout_backend_info (abfd
)->add_one_symbol
;
2933 if (add_one_symbol
== NULL
)
2934 add_one_symbol
= _bfd_generic_link_add_one_symbol
;
2937 pend
= p
+ sym_count
;
2938 for (; p
< pend
; p
++, sym_hash
++)
2949 type
= H_GET_8 (abfd
, p
->e_type
);
2951 /* Ignore debugging symbols. */
2952 if ((type
& N_STAB
) != 0)
2955 name
= strings
+ GET_WORD (abfd
, p
->e_strx
);
2956 value
= GET_WORD (abfd
, p
->e_value
);
2973 /* Ignore symbols that are not externally visible. */
2976 /* Ignore local indirect symbol. */
2981 case N_UNDF
| N_EXT
:
2984 section
= bfd_und_section_ptr
;
2988 section
= bfd_com_section_ptr
;
2991 section
= bfd_abs_section_ptr
;
2993 case N_TEXT
| N_EXT
:
2994 section
= obj_textsec (abfd
);
2995 value
-= bfd_get_section_vma (abfd
, section
);
2997 case N_DATA
| N_EXT
:
2998 case N_SETV
| N_EXT
:
2999 /* Treat N_SETV symbols as N_DATA symbol; see comment in
3000 translate_from_native_sym_flags. */
3001 section
= obj_datasec (abfd
);
3002 value
-= bfd_get_section_vma (abfd
, section
);
3005 section
= obj_bsssec (abfd
);
3006 value
-= bfd_get_section_vma (abfd
, section
);
3008 case N_INDR
| N_EXT
:
3009 /* An indirect symbol. The next symbol is the symbol
3010 which this one really is. */
3011 BFD_ASSERT (p
+ 1 < pend
);
3013 string
= strings
+ GET_WORD (abfd
, p
->e_strx
);
3014 section
= bfd_ind_section_ptr
;
3015 flags
|= BSF_INDIRECT
;
3017 case N_COMM
| N_EXT
:
3018 section
= bfd_com_section_ptr
;
3020 case N_SETA
: case N_SETA
| N_EXT
:
3021 section
= bfd_abs_section_ptr
;
3022 flags
|= BSF_CONSTRUCTOR
;
3024 case N_SETT
: case N_SETT
| N_EXT
:
3025 section
= obj_textsec (abfd
);
3026 flags
|= BSF_CONSTRUCTOR
;
3027 value
-= bfd_get_section_vma (abfd
, section
);
3029 case N_SETD
: case N_SETD
| N_EXT
:
3030 section
= obj_datasec (abfd
);
3031 flags
|= BSF_CONSTRUCTOR
;
3032 value
-= bfd_get_section_vma (abfd
, section
);
3034 case N_SETB
: case N_SETB
| N_EXT
:
3035 section
= obj_bsssec (abfd
);
3036 flags
|= BSF_CONSTRUCTOR
;
3037 value
-= bfd_get_section_vma (abfd
, section
);
3040 /* A warning symbol. The next symbol is the one to warn
3041 about. If there is no next symbol, just look away. */
3046 name
= strings
+ GET_WORD (abfd
, p
->e_strx
);
3047 section
= bfd_und_section_ptr
;
3048 flags
|= BSF_WARNING
;
3051 section
= bfd_und_section_ptr
;
3055 section
= bfd_abs_section_ptr
;
3059 section
= obj_textsec (abfd
);
3060 value
-= bfd_get_section_vma (abfd
, section
);
3064 section
= obj_datasec (abfd
);
3065 value
-= bfd_get_section_vma (abfd
, section
);
3069 section
= obj_bsssec (abfd
);
3070 value
-= bfd_get_section_vma (abfd
, section
);
3075 if (! ((*add_one_symbol
)
3076 (info
, abfd
, name
, flags
, section
, value
, string
, copy
, FALSE
,
3077 (struct bfd_link_hash_entry
**) sym_hash
)))
3080 /* Restrict the maximum alignment of a common symbol based on
3081 the architecture, since a.out has no way to represent
3082 alignment requirements of a section in a .o file. FIXME:
3083 This isn't quite right: it should use the architecture of the
3084 output file, not the input files. */
3085 if ((*sym_hash
)->root
.type
== bfd_link_hash_common
3086 && ((*sym_hash
)->root
.u
.c
.p
->alignment_power
>
3087 bfd_get_arch_info (abfd
)->section_align_power
))
3088 (*sym_hash
)->root
.u
.c
.p
->alignment_power
=
3089 bfd_get_arch_info (abfd
)->section_align_power
;
3091 /* If this is a set symbol, and we are not building sets, then
3092 it is possible for the hash entry to not have been set. In
3093 such a case, treat the symbol as not globally defined. */
3094 if ((*sym_hash
)->root
.type
== bfd_link_hash_new
)
3096 BFD_ASSERT ((flags
& BSF_CONSTRUCTOR
) != 0);
3100 if (type
== (N_INDR
| N_EXT
) || type
== N_WARNING
)
3107 /* Free up the internal symbols read from an a.out file. */
3110 aout_link_free_symbols (bfd
*abfd
)
3112 if (obj_aout_external_syms (abfd
) != NULL
)
3115 bfd_free_window (&obj_aout_sym_window (abfd
));
3117 free ((void *) obj_aout_external_syms (abfd
));
3119 obj_aout_external_syms (abfd
) = NULL
;
3121 if (obj_aout_external_strings (abfd
) != NULL
)
3124 bfd_free_window (&obj_aout_string_window (abfd
));
3126 free ((void *) obj_aout_external_strings (abfd
));
3128 obj_aout_external_strings (abfd
) = NULL
;
3133 /* Add symbols from an a.out object file. */
3136 aout_link_add_object_symbols (bfd
*abfd
, struct bfd_link_info
*info
)
3138 if (! aout_get_external_symbols (abfd
))
3140 if (! aout_link_add_symbols (abfd
, info
))
3142 if (! info
->keep_memory
)
3144 if (! aout_link_free_symbols (abfd
))
3150 /* Look through the internal symbols to see if this object file should
3151 be included in the link. We should include this object file if it
3152 defines any symbols which are currently undefined. If this object
3153 file defines a common symbol, then we may adjust the size of the
3154 known symbol but we do not include the object file in the link
3155 (unless there is some other reason to include it). */
3158 aout_link_check_ar_symbols (bfd
*abfd
,
3159 struct bfd_link_info
*info
,
3160 bfd_boolean
*pneeded
)
3162 struct external_nlist
*p
;
3163 struct external_nlist
*pend
;
3168 /* Look through all the symbols. */
3169 p
= obj_aout_external_syms (abfd
);
3170 pend
= p
+ obj_aout_external_sym_count (abfd
);
3171 strings
= obj_aout_external_strings (abfd
);
3172 for (; p
< pend
; p
++)
3174 int type
= H_GET_8 (abfd
, p
->e_type
);
3176 struct bfd_link_hash_entry
*h
;
3178 /* Ignore symbols that are not externally visible. This is an
3179 optimization only, as we check the type more thoroughly
3181 if (((type
& N_EXT
) == 0
3182 || (type
& N_STAB
) != 0
3189 if (type
== N_WARNING
3195 name
= strings
+ GET_WORD (abfd
, p
->e_strx
);
3196 h
= bfd_link_hash_lookup (info
->hash
, name
, FALSE
, FALSE
, TRUE
);
3198 /* We are only interested in symbols that are currently
3199 undefined or common. */
3201 || (h
->type
!= bfd_link_hash_undefined
3202 && h
->type
!= bfd_link_hash_common
))
3204 if (type
== (N_INDR
| N_EXT
))
3209 if (type
== (N_TEXT
| N_EXT
)
3210 || type
== (N_DATA
| N_EXT
)
3211 || type
== (N_BSS
| N_EXT
)
3212 || type
== (N_ABS
| N_EXT
)
3213 || type
== (N_INDR
| N_EXT
))
3215 /* This object file defines this symbol. We must link it
3216 in. This is true regardless of whether the current
3217 definition of the symbol is undefined or common.
3219 If the current definition is common, we have a case in
3220 which we have already seen an object file including:
3222 and this object file from the archive includes:
3224 In such a case, whether to include this object is target
3225 dependant for backward compatibility.
3227 FIXME: The SunOS 4.1.3 linker will pull in the archive
3228 element if the symbol is defined in the .data section,
3229 but not if it is defined in the .text section. That
3230 seems a bit crazy to me, and it has not been implemented
3231 yet. However, it might be correct. */
3232 if (h
->type
== bfd_link_hash_common
)
3236 switch (info
->common_skip_ar_aymbols
)
3238 case bfd_link_common_skip_text
:
3239 skip
= (type
== (N_TEXT
| N_EXT
));
3241 case bfd_link_common_skip_data
:
3242 skip
= (type
== (N_DATA
| N_EXT
));
3245 case bfd_link_common_skip_all
:
3254 if (! (*info
->callbacks
->add_archive_element
) (info
, abfd
, name
))
3260 if (type
== (N_UNDF
| N_EXT
))
3264 value
= GET_WORD (abfd
, p
->e_value
);
3267 /* This symbol is common in the object from the archive
3269 if (h
->type
== bfd_link_hash_undefined
)
3274 symbfd
= h
->u
.undef
.abfd
;
3277 /* This symbol was created as undefined from
3278 outside BFD. We assume that we should link
3279 in the object file. This is done for the -u
3280 option in the linker. */
3281 if (! (*info
->callbacks
->add_archive_element
) (info
,
3288 /* Turn the current link symbol into a common
3289 symbol. It is already on the undefs list. */
3290 h
->type
= bfd_link_hash_common
;
3291 h
->u
.c
.p
= bfd_hash_allocate (&info
->hash
->table
,
3292 sizeof (struct bfd_link_hash_common_entry
));
3293 if (h
->u
.c
.p
== NULL
)
3296 h
->u
.c
.size
= value
;
3298 /* FIXME: This isn't quite right. The maximum
3299 alignment of a common symbol should be set by the
3300 architecture of the output file, not of the input
3302 power
= bfd_log2 (value
);
3303 if (power
> bfd_get_arch_info (abfd
)->section_align_power
)
3304 power
= bfd_get_arch_info (abfd
)->section_align_power
;
3305 h
->u
.c
.p
->alignment_power
= power
;
3307 h
->u
.c
.p
->section
= bfd_make_section_old_way (symbfd
,
3312 /* Adjust the size of the common symbol if
3314 if (value
> h
->u
.c
.size
)
3315 h
->u
.c
.size
= value
;
3325 /* This symbol is weak but defined. We must pull it in if
3326 the current link symbol is undefined, but we don't want
3327 it if the current link symbol is common. */
3328 if (h
->type
== bfd_link_hash_undefined
)
3330 if (! (*info
->callbacks
->add_archive_element
) (info
, abfd
, name
))
3338 /* We do not need this object file. */
3341 /* Check a single archive element to see if we need to include it in
3342 the link. *PNEEDED is set according to whether this element is
3343 needed in the link or not. This is called from
3344 _bfd_generic_link_add_archive_symbols. */
3347 aout_link_check_archive_element (bfd
*abfd
,
3348 struct bfd_link_info
*info
,
3349 bfd_boolean
*pneeded
)
3351 if (! aout_get_external_symbols (abfd
))
3354 if (! aout_link_check_ar_symbols (abfd
, info
, pneeded
))
3359 if (! aout_link_add_symbols (abfd
, info
))
3363 if (! info
->keep_memory
|| ! *pneeded
)
3365 if (! aout_link_free_symbols (abfd
))
3372 /* Given an a.out BFD, add symbols to the global hash table as
3376 NAME (aout
, link_add_symbols
) (bfd
*abfd
, struct bfd_link_info
*info
)
3378 switch (bfd_get_format (abfd
))
3381 return aout_link_add_object_symbols (abfd
, info
);
3383 return _bfd_generic_link_add_archive_symbols
3384 (abfd
, info
, aout_link_check_archive_element
);
3386 bfd_set_error (bfd_error_wrong_format
);
3391 /* A hash table used for header files with N_BINCL entries. */
3393 struct aout_link_includes_table
3395 struct bfd_hash_table root
;
3398 /* A linked list of totals that we have found for a particular header
3401 struct aout_link_includes_totals
3403 struct aout_link_includes_totals
*next
;
3407 /* An entry in the header file hash table. */
3409 struct aout_link_includes_entry
3411 struct bfd_hash_entry root
;
3412 /* List of totals we have found for this file. */
3413 struct aout_link_includes_totals
*totals
;
3416 /* Look up an entry in an the header file hash table. */
3418 #define aout_link_includes_lookup(table, string, create, copy) \
3419 ((struct aout_link_includes_entry *) \
3420 bfd_hash_lookup (&(table)->root, (string), (create), (copy)))
3422 /* During the final link step we need to pass around a bunch of
3423 information, so we do it in an instance of this structure. */
3425 struct aout_final_link_info
3427 /* General link information. */
3428 struct bfd_link_info
*info
;
3431 /* Reloc file positions. */
3432 file_ptr treloff
, dreloff
;
3433 /* File position of symbols. */
3436 struct bfd_strtab_hash
*strtab
;
3437 /* Header file hash table. */
3438 struct aout_link_includes_table includes
;
3439 /* A buffer large enough to hold the contents of any section. */
3441 /* A buffer large enough to hold the relocs of any section. */
3443 /* A buffer large enough to hold the symbol map of any input BFD. */
3445 /* A buffer large enough to hold output symbols of any input BFD. */
3446 struct external_nlist
*output_syms
;
3449 /* The function to create a new entry in the header file hash table. */
3451 static struct bfd_hash_entry
*
3452 aout_link_includes_newfunc (struct bfd_hash_entry
*entry
,
3453 struct bfd_hash_table
*table
,
3456 struct aout_link_includes_entry
*ret
=
3457 (struct aout_link_includes_entry
*) entry
;
3459 /* Allocate the structure if it has not already been allocated by a
3462 ret
= bfd_hash_allocate (table
, sizeof (* ret
));
3466 /* Call the allocation method of the superclass. */
3467 ret
= ((struct aout_link_includes_entry
*)
3468 bfd_hash_newfunc ((struct bfd_hash_entry
*) ret
, table
, string
));
3471 /* Set local fields. */
3475 return (struct bfd_hash_entry
*) ret
;
3478 /* Write out a symbol that was not associated with an a.out input
3482 aout_link_write_other_symbol (struct aout_link_hash_entry
*h
, void * data
)
3484 struct aout_final_link_info
*finfo
= (struct aout_final_link_info
*) data
;
3488 struct external_nlist outsym
;
3492 if (h
->root
.type
== bfd_link_hash_warning
)
3494 h
= (struct aout_link_hash_entry
*) h
->root
.u
.i
.link
;
3495 if (h
->root
.type
== bfd_link_hash_new
)
3499 output_bfd
= finfo
->output_bfd
;
3501 if (aout_backend_info (output_bfd
)->write_dynamic_symbol
!= NULL
)
3503 if (! ((*aout_backend_info (output_bfd
)->write_dynamic_symbol
)
3504 (output_bfd
, finfo
->info
, h
)))
3506 /* FIXME: No way to handle errors. */
3516 /* An indx of -2 means the symbol must be written. */
3518 && (finfo
->info
->strip
== strip_all
3519 || (finfo
->info
->strip
== strip_some
3520 && bfd_hash_lookup (finfo
->info
->keep_hash
, h
->root
.root
.string
,
3521 FALSE
, FALSE
) == NULL
)))
3524 switch (h
->root
.type
)
3527 case bfd_link_hash_warning
:
3529 /* Avoid variable not initialized warnings. */
3531 case bfd_link_hash_new
:
3532 /* This can happen for set symbols when sets are not being
3535 case bfd_link_hash_undefined
:
3536 type
= N_UNDF
| N_EXT
;
3539 case bfd_link_hash_defined
:
3540 case bfd_link_hash_defweak
:
3544 sec
= h
->root
.u
.def
.section
->output_section
;
3545 BFD_ASSERT (bfd_is_abs_section (sec
)
3546 || sec
->owner
== output_bfd
);
3547 if (sec
== obj_textsec (output_bfd
))
3548 type
= h
->root
.type
== bfd_link_hash_defined
? N_TEXT
: N_WEAKT
;
3549 else if (sec
== obj_datasec (output_bfd
))
3550 type
= h
->root
.type
== bfd_link_hash_defined
? N_DATA
: N_WEAKD
;
3551 else if (sec
== obj_bsssec (output_bfd
))
3552 type
= h
->root
.type
== bfd_link_hash_defined
? N_BSS
: N_WEAKB
;
3554 type
= h
->root
.type
== bfd_link_hash_defined
? N_ABS
: N_WEAKA
;
3556 val
= (h
->root
.u
.def
.value
3558 + h
->root
.u
.def
.section
->output_offset
);
3561 case bfd_link_hash_common
:
3562 type
= N_UNDF
| N_EXT
;
3563 val
= h
->root
.u
.c
.size
;
3565 case bfd_link_hash_undefweak
:
3568 case bfd_link_hash_indirect
:
3569 /* We ignore these symbols, since the indirected symbol is
3570 already in the hash table. */
3574 H_PUT_8 (output_bfd
, type
, outsym
.e_type
);
3575 H_PUT_8 (output_bfd
, 0, outsym
.e_other
);
3576 H_PUT_16 (output_bfd
, 0, outsym
.e_desc
);
3577 indx
= add_to_stringtab (output_bfd
, finfo
->strtab
, h
->root
.root
.string
,
3579 if (indx
== - (bfd_size_type
) 1)
3580 /* FIXME: No way to handle errors. */
3583 PUT_WORD (output_bfd
, indx
, outsym
.e_strx
);
3584 PUT_WORD (output_bfd
, val
, outsym
.e_value
);
3586 amt
= EXTERNAL_NLIST_SIZE
;
3587 if (bfd_seek (output_bfd
, finfo
->symoff
, SEEK_SET
) != 0
3588 || bfd_bwrite ((void *) &outsym
, amt
, output_bfd
) != amt
)
3589 /* FIXME: No way to handle errors. */
3592 finfo
->symoff
+= EXTERNAL_NLIST_SIZE
;
3593 h
->indx
= obj_aout_external_sym_count (output_bfd
);
3594 ++obj_aout_external_sym_count (output_bfd
);
3599 /* Handle a link order which is supposed to generate a reloc. */
3602 aout_link_reloc_link_order (struct aout_final_link_info
*finfo
,
3604 struct bfd_link_order
*p
)
3606 struct bfd_link_order_reloc
*pr
;
3609 reloc_howto_type
*howto
;
3610 file_ptr
*reloff_ptr
= NULL
;
3611 struct reloc_std_external srel
;
3612 struct reloc_ext_external erel
;
3618 if (p
->type
== bfd_section_reloc_link_order
)
3621 if (bfd_is_abs_section (pr
->u
.section
))
3622 r_index
= N_ABS
| N_EXT
;
3625 BFD_ASSERT (pr
->u
.section
->owner
== finfo
->output_bfd
);
3626 r_index
= pr
->u
.section
->target_index
;
3631 struct aout_link_hash_entry
*h
;
3633 BFD_ASSERT (p
->type
== bfd_symbol_reloc_link_order
);
3635 h
= ((struct aout_link_hash_entry
*)
3636 bfd_wrapped_link_hash_lookup (finfo
->output_bfd
, finfo
->info
,
3637 pr
->u
.name
, FALSE
, FALSE
, TRUE
));
3643 /* We decided to strip this symbol, but it turns out that we
3644 can't. Note that we lose the other and desc information
3645 here. I don't think that will ever matter for a global
3649 if (! aout_link_write_other_symbol (h
, (void *) finfo
))
3655 if (! ((*finfo
->info
->callbacks
->unattached_reloc
)
3656 (finfo
->info
, pr
->u
.name
, NULL
, NULL
, (bfd_vma
) 0)))
3662 howto
= bfd_reloc_type_lookup (finfo
->output_bfd
, pr
->reloc
);
3665 bfd_set_error (bfd_error_bad_value
);
3669 if (o
== obj_textsec (finfo
->output_bfd
))
3670 reloff_ptr
= &finfo
->treloff
;
3671 else if (o
== obj_datasec (finfo
->output_bfd
))
3672 reloff_ptr
= &finfo
->dreloff
;
3676 if (obj_reloc_entry_size (finfo
->output_bfd
) == RELOC_STD_SIZE
)
3679 MY_put_reloc (finfo
->output_bfd
, r_extern
, r_index
, p
->offset
, howto
,
3689 r_pcrel
= (int) howto
->pc_relative
;
3690 r_baserel
= (howto
->type
& 8) != 0;
3691 r_jmptable
= (howto
->type
& 16) != 0;
3692 r_relative
= (howto
->type
& 32) != 0;
3693 r_length
= howto
->size
;
3695 PUT_WORD (finfo
->output_bfd
, p
->offset
, srel
.r_address
);
3696 if (bfd_header_big_endian (finfo
->output_bfd
))
3698 srel
.r_index
[0] = r_index
>> 16;
3699 srel
.r_index
[1] = r_index
>> 8;
3700 srel
.r_index
[2] = r_index
;
3702 ((r_extern
? RELOC_STD_BITS_EXTERN_BIG
: 0)
3703 | (r_pcrel
? RELOC_STD_BITS_PCREL_BIG
: 0)
3704 | (r_baserel
? RELOC_STD_BITS_BASEREL_BIG
: 0)
3705 | (r_jmptable
? RELOC_STD_BITS_JMPTABLE_BIG
: 0)
3706 | (r_relative
? RELOC_STD_BITS_RELATIVE_BIG
: 0)
3707 | (r_length
<< RELOC_STD_BITS_LENGTH_SH_BIG
));
3711 srel
.r_index
[2] = r_index
>> 16;
3712 srel
.r_index
[1] = r_index
>> 8;
3713 srel
.r_index
[0] = r_index
;
3715 ((r_extern
? RELOC_STD_BITS_EXTERN_LITTLE
: 0)
3716 | (r_pcrel
? RELOC_STD_BITS_PCREL_LITTLE
: 0)
3717 | (r_baserel
? RELOC_STD_BITS_BASEREL_LITTLE
: 0)
3718 | (r_jmptable
? RELOC_STD_BITS_JMPTABLE_LITTLE
: 0)
3719 | (r_relative
? RELOC_STD_BITS_RELATIVE_LITTLE
: 0)
3720 | (r_length
<< RELOC_STD_BITS_LENGTH_SH_LITTLE
));
3724 rel_ptr
= (void *) &srel
;
3726 /* We have to write the addend into the object file, since
3727 standard a.out relocs are in place. It would be more
3728 reliable if we had the current contents of the file here,
3729 rather than assuming zeroes, but we can't read the file since
3730 it was opened using bfd_openw. */
3731 if (pr
->addend
!= 0)
3734 bfd_reloc_status_type r
;
3738 size
= bfd_get_reloc_size (howto
);
3739 buf
= bfd_zmalloc (size
);
3742 r
= MY_relocate_contents (howto
, finfo
->output_bfd
,
3743 (bfd_vma
) pr
->addend
, buf
);
3749 case bfd_reloc_outofrange
:
3751 case bfd_reloc_overflow
:
3752 if (! ((*finfo
->info
->callbacks
->reloc_overflow
)
3754 (p
->type
== bfd_section_reloc_link_order
3755 ? bfd_section_name (finfo
->output_bfd
,
3758 howto
->name
, pr
->addend
, NULL
, NULL
, (bfd_vma
) 0)))
3765 ok
= bfd_set_section_contents (finfo
->output_bfd
, o
, (void *) buf
,
3766 (file_ptr
) p
->offset
, size
);
3774 #ifdef MY_put_ext_reloc
3775 MY_put_ext_reloc (finfo
->output_bfd
, r_extern
, r_index
, p
->offset
,
3776 howto
, &erel
, pr
->addend
);
3778 PUT_WORD (finfo
->output_bfd
, p
->offset
, erel
.r_address
);
3780 if (bfd_header_big_endian (finfo
->output_bfd
))
3782 erel
.r_index
[0] = r_index
>> 16;
3783 erel
.r_index
[1] = r_index
>> 8;
3784 erel
.r_index
[2] = r_index
;
3786 ((r_extern
? RELOC_EXT_BITS_EXTERN_BIG
: 0)
3787 | (howto
->type
<< RELOC_EXT_BITS_TYPE_SH_BIG
));
3791 erel
.r_index
[2] = r_index
>> 16;
3792 erel
.r_index
[1] = r_index
>> 8;
3793 erel
.r_index
[0] = r_index
;
3795 (r_extern
? RELOC_EXT_BITS_EXTERN_LITTLE
: 0)
3796 | (howto
->type
<< RELOC_EXT_BITS_TYPE_SH_LITTLE
);
3799 PUT_WORD (finfo
->output_bfd
, (bfd_vma
) pr
->addend
, erel
.r_addend
);
3800 #endif /* MY_put_ext_reloc */
3802 rel_ptr
= (void *) &erel
;
3805 amt
= obj_reloc_entry_size (finfo
->output_bfd
);
3806 if (bfd_seek (finfo
->output_bfd
, *reloff_ptr
, SEEK_SET
) != 0
3807 || bfd_bwrite (rel_ptr
, amt
, finfo
->output_bfd
) != amt
)
3810 *reloff_ptr
+= obj_reloc_entry_size (finfo
->output_bfd
);
3812 /* Assert that the relocs have not run into the symbols, and that n
3813 the text relocs have not run into the data relocs. */
3814 BFD_ASSERT (*reloff_ptr
<= obj_sym_filepos (finfo
->output_bfd
)
3815 && (reloff_ptr
!= &finfo
->treloff
3817 <= obj_datasec (finfo
->output_bfd
)->rel_filepos
)));
3822 /* Get the section corresponding to a reloc index. */
3824 static INLINE asection
*
3825 aout_reloc_index_to_section (bfd
*abfd
, int indx
)
3827 switch (indx
& N_TYPE
)
3829 case N_TEXT
: return obj_textsec (abfd
);
3830 case N_DATA
: return obj_datasec (abfd
);
3831 case N_BSS
: return obj_bsssec (abfd
);
3833 case N_UNDF
: return bfd_abs_section_ptr
;
3839 /* Relocate an a.out section using standard a.out relocs. */
3842 aout_link_input_section_std (struct aout_final_link_info
*finfo
,
3844 asection
*input_section
,
3845 struct reloc_std_external
*relocs
,
3846 bfd_size_type rel_size
,
3849 bfd_boolean (*check_dynamic_reloc
)
3850 (struct bfd_link_info
*, bfd
*, asection
*,
3851 struct aout_link_hash_entry
*, void *, bfd_byte
*, bfd_boolean
*,
3854 bfd_boolean relocatable
;
3855 struct external_nlist
*syms
;
3857 struct aout_link_hash_entry
**sym_hashes
;
3859 bfd_size_type reloc_count
;
3860 struct reloc_std_external
*rel
;
3861 struct reloc_std_external
*rel_end
;
3863 output_bfd
= finfo
->output_bfd
;
3864 check_dynamic_reloc
= aout_backend_info (output_bfd
)->check_dynamic_reloc
;
3866 BFD_ASSERT (obj_reloc_entry_size (input_bfd
) == RELOC_STD_SIZE
);
3867 BFD_ASSERT (input_bfd
->xvec
->header_byteorder
3868 == output_bfd
->xvec
->header_byteorder
);
3870 relocatable
= finfo
->info
->relocatable
;
3871 syms
= obj_aout_external_syms (input_bfd
);
3872 strings
= obj_aout_external_strings (input_bfd
);
3873 sym_hashes
= obj_aout_sym_hashes (input_bfd
);
3874 symbol_map
= finfo
->symbol_map
;
3876 reloc_count
= rel_size
/ RELOC_STD_SIZE
;
3878 rel_end
= rel
+ reloc_count
;
3879 for (; rel
< rel_end
; rel
++)
3886 reloc_howto_type
*howto
;
3887 struct aout_link_hash_entry
*h
= NULL
;
3889 bfd_reloc_status_type r
;
3891 r_addr
= GET_SWORD (input_bfd
, rel
->r_address
);
3893 #ifdef MY_reloc_howto
3894 howto
= MY_reloc_howto (input_bfd
, rel
, r_index
, r_extern
, r_pcrel
);
3900 unsigned int howto_idx
;
3902 if (bfd_header_big_endian (input_bfd
))
3904 r_index
= (((unsigned int) rel
->r_index
[0] << 16)
3905 | ((unsigned int) rel
->r_index
[1] << 8)
3907 r_extern
= (0 != (rel
->r_type
[0] & RELOC_STD_BITS_EXTERN_BIG
));
3908 r_pcrel
= (0 != (rel
->r_type
[0] & RELOC_STD_BITS_PCREL_BIG
));
3909 r_baserel
= (0 != (rel
->r_type
[0] & RELOC_STD_BITS_BASEREL_BIG
));
3910 r_jmptable
= (0 != (rel
->r_type
[0] & RELOC_STD_BITS_JMPTABLE_BIG
));
3911 r_relative
= (0 != (rel
->r_type
[0] & RELOC_STD_BITS_RELATIVE_BIG
));
3912 r_length
= ((rel
->r_type
[0] & RELOC_STD_BITS_LENGTH_BIG
)
3913 >> RELOC_STD_BITS_LENGTH_SH_BIG
);
3917 r_index
= (((unsigned int) rel
->r_index
[2] << 16)
3918 | ((unsigned int) rel
->r_index
[1] << 8)
3920 r_extern
= (0 != (rel
->r_type
[0] & RELOC_STD_BITS_EXTERN_LITTLE
));
3921 r_pcrel
= (0 != (rel
->r_type
[0] & RELOC_STD_BITS_PCREL_LITTLE
));
3922 r_baserel
= (0 != (rel
->r_type
[0]
3923 & RELOC_STD_BITS_BASEREL_LITTLE
));
3924 r_jmptable
= (0 != (rel
->r_type
[0]
3925 & RELOC_STD_BITS_JMPTABLE_LITTLE
));
3926 r_relative
= (0 != (rel
->r_type
[0]
3927 & RELOC_STD_BITS_RELATIVE_LITTLE
));
3928 r_length
= ((rel
->r_type
[0] & RELOC_STD_BITS_LENGTH_LITTLE
)
3929 >> RELOC_STD_BITS_LENGTH_SH_LITTLE
);
3932 howto_idx
= (r_length
+ 4 * r_pcrel
+ 8 * r_baserel
3933 + 16 * r_jmptable
+ 32 * r_relative
);
3934 BFD_ASSERT (howto_idx
< TABLE_SIZE (howto_table_std
));
3935 howto
= howto_table_std
+ howto_idx
;
3941 /* We are generating a relocatable output file, and must
3942 modify the reloc accordingly. */
3945 /* If we know the symbol this relocation is against,
3946 convert it into a relocation against a section. This
3947 is what the native linker does. */
3948 h
= sym_hashes
[r_index
];
3950 && (h
->root
.type
== bfd_link_hash_defined
3951 || h
->root
.type
== bfd_link_hash_defweak
))
3953 asection
*output_section
;
3955 /* Change the r_extern value. */
3956 if (bfd_header_big_endian (output_bfd
))
3957 rel
->r_type
[0] &=~ RELOC_STD_BITS_EXTERN_BIG
;
3959 rel
->r_type
[0] &=~ RELOC_STD_BITS_EXTERN_LITTLE
;
3961 /* Compute a new r_index. */
3962 output_section
= h
->root
.u
.def
.section
->output_section
;
3963 if (output_section
== obj_textsec (output_bfd
))
3965 else if (output_section
== obj_datasec (output_bfd
))
3967 else if (output_section
== obj_bsssec (output_bfd
))
3972 /* Add the symbol value and the section VMA to the
3973 addend stored in the contents. */
3974 relocation
= (h
->root
.u
.def
.value
3975 + output_section
->vma
3976 + h
->root
.u
.def
.section
->output_offset
);
3980 /* We must change r_index according to the symbol
3982 r_index
= symbol_map
[r_index
];
3988 /* We decided to strip this symbol, but it
3989 turns out that we can't. Note that we
3990 lose the other and desc information here.
3991 I don't think that will ever matter for a
3997 if (! aout_link_write_other_symbol (h
,
4007 name
= strings
+ GET_WORD (input_bfd
,
4008 syms
[r_index
].e_strx
);
4009 if (! ((*finfo
->info
->callbacks
->unattached_reloc
)
4010 (finfo
->info
, name
, input_bfd
, input_section
,
4020 /* Write out the new r_index value. */
4021 if (bfd_header_big_endian (output_bfd
))
4023 rel
->r_index
[0] = r_index
>> 16;
4024 rel
->r_index
[1] = r_index
>> 8;
4025 rel
->r_index
[2] = r_index
;
4029 rel
->r_index
[2] = r_index
>> 16;
4030 rel
->r_index
[1] = r_index
>> 8;
4031 rel
->r_index
[0] = r_index
;
4038 /* This is a relocation against a section. We must
4039 adjust by the amount that the section moved. */
4040 section
= aout_reloc_index_to_section (input_bfd
, r_index
);
4041 relocation
= (section
->output_section
->vma
4042 + section
->output_offset
4046 /* Change the address of the relocation. */
4047 PUT_WORD (output_bfd
,
4048 r_addr
+ input_section
->output_offset
,
4051 /* Adjust a PC relative relocation by removing the reference
4052 to the original address in the section and including the
4053 reference to the new address. */
4055 relocation
-= (input_section
->output_section
->vma
4056 + input_section
->output_offset
4057 - input_section
->vma
);
4059 #ifdef MY_relocatable_reloc
4060 MY_relocatable_reloc (howto
, output_bfd
, rel
, relocation
, r_addr
);
4063 if (relocation
== 0)
4066 r
= MY_relocate_contents (howto
,
4067 input_bfd
, relocation
,
4074 /* We are generating an executable, and must do a full
4080 h
= sym_hashes
[r_index
];
4083 && (h
->root
.type
== bfd_link_hash_defined
4084 || h
->root
.type
== bfd_link_hash_defweak
))
4086 relocation
= (h
->root
.u
.def
.value
4087 + h
->root
.u
.def
.section
->output_section
->vma
4088 + h
->root
.u
.def
.section
->output_offset
);
4091 && h
->root
.type
== bfd_link_hash_undefweak
)
4103 section
= aout_reloc_index_to_section (input_bfd
, r_index
);
4104 relocation
= (section
->output_section
->vma
4105 + section
->output_offset
4108 relocation
+= input_section
->vma
;
4111 if (check_dynamic_reloc
!= NULL
)
4115 if (! ((*check_dynamic_reloc
)
4116 (finfo
->info
, input_bfd
, input_section
, h
,
4117 (void *) rel
, contents
, &skip
, &relocation
)))
4123 /* Now warn if a global symbol is undefined. We could not
4124 do this earlier, because check_dynamic_reloc might want
4125 to skip this reloc. */
4126 if (hundef
&& ! finfo
->info
->shared
&& ! r_baserel
)
4131 name
= h
->root
.root
.string
;
4133 name
= strings
+ GET_WORD (input_bfd
, syms
[r_index
].e_strx
);
4134 if (! ((*finfo
->info
->callbacks
->undefined_symbol
)
4135 (finfo
->info
, name
, input_bfd
, input_section
,
4140 r
= MY_final_link_relocate (howto
,
4141 input_bfd
, input_section
,
4142 contents
, r_addr
, relocation
,
4146 if (r
!= bfd_reloc_ok
)
4151 case bfd_reloc_outofrange
:
4153 case bfd_reloc_overflow
:
4160 name
= strings
+ GET_WORD (input_bfd
,
4161 syms
[r_index
].e_strx
);
4166 s
= aout_reloc_index_to_section (input_bfd
, r_index
);
4167 name
= bfd_section_name (input_bfd
, s
);
4169 if (! ((*finfo
->info
->callbacks
->reloc_overflow
)
4170 (finfo
->info
, (h
? &h
->root
: NULL
), name
,
4171 howto
->name
, (bfd_vma
) 0, input_bfd
,
4172 input_section
, r_addr
)))
4183 /* Relocate an a.out section using extended a.out relocs. */
4186 aout_link_input_section_ext (struct aout_final_link_info
*finfo
,
4188 asection
*input_section
,
4189 struct reloc_ext_external
*relocs
,
4190 bfd_size_type rel_size
,
4193 bfd_boolean (*check_dynamic_reloc
)
4194 (struct bfd_link_info
*, bfd
*, asection
*,
4195 struct aout_link_hash_entry
*, void *, bfd_byte
*, bfd_boolean
*,
4198 bfd_boolean relocatable
;
4199 struct external_nlist
*syms
;
4201 struct aout_link_hash_entry
**sym_hashes
;
4203 bfd_size_type reloc_count
;
4204 struct reloc_ext_external
*rel
;
4205 struct reloc_ext_external
*rel_end
;
4207 output_bfd
= finfo
->output_bfd
;
4208 check_dynamic_reloc
= aout_backend_info (output_bfd
)->check_dynamic_reloc
;
4210 BFD_ASSERT (obj_reloc_entry_size (input_bfd
) == RELOC_EXT_SIZE
);
4211 BFD_ASSERT (input_bfd
->xvec
->header_byteorder
4212 == output_bfd
->xvec
->header_byteorder
);
4214 relocatable
= finfo
->info
->relocatable
;
4215 syms
= obj_aout_external_syms (input_bfd
);
4216 strings
= obj_aout_external_strings (input_bfd
);
4217 sym_hashes
= obj_aout_sym_hashes (input_bfd
);
4218 symbol_map
= finfo
->symbol_map
;
4220 reloc_count
= rel_size
/ RELOC_EXT_SIZE
;
4222 rel_end
= rel
+ reloc_count
;
4223 for (; rel
< rel_end
; rel
++)
4228 unsigned int r_type
;
4230 struct aout_link_hash_entry
*h
= NULL
;
4231 asection
*r_section
= NULL
;
4234 r_addr
= GET_SWORD (input_bfd
, rel
->r_address
);
4236 if (bfd_header_big_endian (input_bfd
))
4238 r_index
= (((unsigned int) rel
->r_index
[0] << 16)
4239 | ((unsigned int) rel
->r_index
[1] << 8)
4241 r_extern
= (0 != (rel
->r_type
[0] & RELOC_EXT_BITS_EXTERN_BIG
));
4242 r_type
= ((rel
->r_type
[0] & RELOC_EXT_BITS_TYPE_BIG
)
4243 >> RELOC_EXT_BITS_TYPE_SH_BIG
);
4247 r_index
= (((unsigned int) rel
->r_index
[2] << 16)
4248 | ((unsigned int) rel
->r_index
[1] << 8)
4250 r_extern
= (0 != (rel
->r_type
[0] & RELOC_EXT_BITS_EXTERN_LITTLE
));
4251 r_type
= ((rel
->r_type
[0] & RELOC_EXT_BITS_TYPE_LITTLE
)
4252 >> RELOC_EXT_BITS_TYPE_SH_LITTLE
);
4255 r_addend
= GET_SWORD (input_bfd
, rel
->r_addend
);
4257 BFD_ASSERT (r_type
< TABLE_SIZE (howto_table_ext
));
4261 /* We are generating a relocatable output file, and must
4262 modify the reloc accordingly. */
4264 || r_type
== (unsigned int) RELOC_BASE10
4265 || r_type
== (unsigned int) RELOC_BASE13
4266 || r_type
== (unsigned int) RELOC_BASE22
)
4268 /* If we know the symbol this relocation is against,
4269 convert it into a relocation against a section. This
4270 is what the native linker does. */
4271 if (r_type
== (unsigned int) RELOC_BASE10
4272 || r_type
== (unsigned int) RELOC_BASE13
4273 || r_type
== (unsigned int) RELOC_BASE22
)
4276 h
= sym_hashes
[r_index
];
4278 && (h
->root
.type
== bfd_link_hash_defined
4279 || h
->root
.type
== bfd_link_hash_defweak
))
4281 asection
*output_section
;
4283 /* Change the r_extern value. */
4284 if (bfd_header_big_endian (output_bfd
))
4285 rel
->r_type
[0] &=~ RELOC_EXT_BITS_EXTERN_BIG
;
4287 rel
->r_type
[0] &=~ RELOC_EXT_BITS_EXTERN_LITTLE
;
4289 /* Compute a new r_index. */
4290 output_section
= h
->root
.u
.def
.section
->output_section
;
4291 if (output_section
== obj_textsec (output_bfd
))
4293 else if (output_section
== obj_datasec (output_bfd
))
4295 else if (output_section
== obj_bsssec (output_bfd
))
4300 /* Add the symbol value and the section VMA to the
4302 relocation
= (h
->root
.u
.def
.value
4303 + output_section
->vma
4304 + h
->root
.u
.def
.section
->output_offset
);
4306 /* Now RELOCATION is the VMA of the final
4307 destination. If this is a PC relative reloc,
4308 then ADDEND is the negative of the source VMA.
4309 We want to set ADDEND to the difference between
4310 the destination VMA and the source VMA, which
4311 means we must adjust RELOCATION by the change in
4312 the source VMA. This is done below. */
4316 /* We must change r_index according to the symbol
4318 r_index
= symbol_map
[r_index
];
4324 /* We decided to strip this symbol, but it
4325 turns out that we can't. Note that we
4326 lose the other and desc information here.
4327 I don't think that will ever matter for a
4333 if (! aout_link_write_other_symbol (h
,
4343 name
= strings
+ GET_WORD (input_bfd
,
4344 syms
[r_index
].e_strx
);
4345 if (! ((*finfo
->info
->callbacks
->unattached_reloc
)
4346 (finfo
->info
, name
, input_bfd
, input_section
,
4355 /* If this is a PC relative reloc, then the addend
4356 is the negative of the source VMA. We must
4357 adjust it by the change in the source VMA. This
4361 /* Write out the new r_index value. */
4362 if (bfd_header_big_endian (output_bfd
))
4364 rel
->r_index
[0] = r_index
>> 16;
4365 rel
->r_index
[1] = r_index
>> 8;
4366 rel
->r_index
[2] = r_index
;
4370 rel
->r_index
[2] = r_index
>> 16;
4371 rel
->r_index
[1] = r_index
>> 8;
4372 rel
->r_index
[0] = r_index
;
4377 /* This is a relocation against a section. We must
4378 adjust by the amount that the section moved. */
4379 r_section
= aout_reloc_index_to_section (input_bfd
, r_index
);
4380 relocation
= (r_section
->output_section
->vma
4381 + r_section
->output_offset
4384 /* If this is a PC relative reloc, then the addend is
4385 the difference in VMA between the destination and the
4386 source. We have just adjusted for the change in VMA
4387 of the destination, so we must also adjust by the
4388 change in VMA of the source. This is done below. */
4391 /* As described above, we must always adjust a PC relative
4392 reloc by the change in VMA of the source. However, if
4393 pcrel_offset is set, then the addend does not include the
4394 location within the section, in which case we don't need
4395 to adjust anything. */
4396 if (howto_table_ext
[r_type
].pc_relative
4397 && ! howto_table_ext
[r_type
].pcrel_offset
)
4398 relocation
-= (input_section
->output_section
->vma
4399 + input_section
->output_offset
4400 - input_section
->vma
);
4402 /* Change the addend if necessary. */
4403 if (relocation
!= 0)
4404 PUT_WORD (output_bfd
, r_addend
+ relocation
, rel
->r_addend
);
4406 /* Change the address of the relocation. */
4407 PUT_WORD (output_bfd
,
4408 r_addr
+ input_section
->output_offset
,
4414 bfd_reloc_status_type r
;
4416 /* We are generating an executable, and must do a full
4422 h
= sym_hashes
[r_index
];
4425 && (h
->root
.type
== bfd_link_hash_defined
4426 || h
->root
.type
== bfd_link_hash_defweak
))
4428 relocation
= (h
->root
.u
.def
.value
4429 + h
->root
.u
.def
.section
->output_section
->vma
4430 + h
->root
.u
.def
.section
->output_offset
);
4433 && h
->root
.type
== bfd_link_hash_undefweak
)
4441 else if (r_type
== (unsigned int) RELOC_BASE10
4442 || r_type
== (unsigned int) RELOC_BASE13
4443 || r_type
== (unsigned int) RELOC_BASE22
)
4445 struct external_nlist
*sym
;
4448 /* For base relative relocs, r_index is always an index
4449 into the symbol table, even if r_extern is 0. */
4450 sym
= syms
+ r_index
;
4451 type
= H_GET_8 (input_bfd
, sym
->e_type
);
4452 if ((type
& N_TYPE
) == N_TEXT
4454 r_section
= obj_textsec (input_bfd
);
4455 else if ((type
& N_TYPE
) == N_DATA
4457 r_section
= obj_datasec (input_bfd
);
4458 else if ((type
& N_TYPE
) == N_BSS
4460 r_section
= obj_bsssec (input_bfd
);
4461 else if ((type
& N_TYPE
) == N_ABS
4463 r_section
= bfd_abs_section_ptr
;
4466 relocation
= (r_section
->output_section
->vma
4467 + r_section
->output_offset
4468 + (GET_WORD (input_bfd
, sym
->e_value
)
4473 r_section
= aout_reloc_index_to_section (input_bfd
, r_index
);
4475 /* If this is a PC relative reloc, then R_ADDEND is the
4476 difference between the two vmas, or
4477 old_dest_sec + old_dest_off - (old_src_sec + old_src_off)
4479 old_dest_sec == section->vma
4481 old_src_sec == input_section->vma
4483 old_src_off == r_addr
4485 _bfd_final_link_relocate expects RELOCATION +
4486 R_ADDEND to be the VMA of the destination minus
4487 r_addr (the minus r_addr is because this relocation
4488 is not pcrel_offset, which is a bit confusing and
4489 should, perhaps, be changed), or
4492 new_dest_sec == output_section->vma + output_offset
4493 We arrange for this to happen by setting RELOCATION to
4494 new_dest_sec + old_src_sec - old_dest_sec
4496 If this is not a PC relative reloc, then R_ADDEND is
4497 simply the VMA of the destination, so we set
4498 RELOCATION to the change in the destination VMA, or
4499 new_dest_sec - old_dest_sec
4501 relocation
= (r_section
->output_section
->vma
4502 + r_section
->output_offset
4504 if (howto_table_ext
[r_type
].pc_relative
)
4505 relocation
+= input_section
->vma
;
4508 if (check_dynamic_reloc
!= NULL
)
4512 if (! ((*check_dynamic_reloc
)
4513 (finfo
->info
, input_bfd
, input_section
, h
,
4514 (void *) rel
, contents
, &skip
, &relocation
)))
4520 /* Now warn if a global symbol is undefined. We could not
4521 do this earlier, because check_dynamic_reloc might want
4522 to skip this reloc. */
4524 && ! finfo
->info
->shared
4525 && r_type
!= (unsigned int) RELOC_BASE10
4526 && r_type
!= (unsigned int) RELOC_BASE13
4527 && r_type
!= (unsigned int) RELOC_BASE22
)
4532 name
= h
->root
.root
.string
;
4534 name
= strings
+ GET_WORD (input_bfd
, syms
[r_index
].e_strx
);
4535 if (! ((*finfo
->info
->callbacks
->undefined_symbol
)
4536 (finfo
->info
, name
, input_bfd
, input_section
,
4541 if (r_type
!= (unsigned int) RELOC_SPARC_REV32
)
4542 r
= MY_final_link_relocate (howto_table_ext
+ r_type
,
4543 input_bfd
, input_section
,
4544 contents
, r_addr
, relocation
,
4550 x
= bfd_get_32 (input_bfd
, contents
+ r_addr
);
4551 x
= x
+ relocation
+ r_addend
;
4552 bfd_putl32 (/*input_bfd,*/ x
, contents
+ r_addr
);
4556 if (r
!= bfd_reloc_ok
)
4561 case bfd_reloc_outofrange
:
4563 case bfd_reloc_overflow
:
4570 || r_type
== (unsigned int) RELOC_BASE10
4571 || r_type
== (unsigned int) RELOC_BASE13
4572 || r_type
== (unsigned int) RELOC_BASE22
)
4573 name
= strings
+ GET_WORD (input_bfd
,
4574 syms
[r_index
].e_strx
);
4579 s
= aout_reloc_index_to_section (input_bfd
, r_index
);
4580 name
= bfd_section_name (input_bfd
, s
);
4582 if (! ((*finfo
->info
->callbacks
->reloc_overflow
)
4583 (finfo
->info
, (h
? &h
->root
: NULL
), name
,
4584 howto_table_ext
[r_type
].name
,
4585 r_addend
, input_bfd
, input_section
, r_addr
)))
4597 /* Link an a.out section into the output file. */
4600 aout_link_input_section (struct aout_final_link_info
*finfo
,
4602 asection
*input_section
,
4603 file_ptr
*reloff_ptr
,
4604 bfd_size_type rel_size
)
4606 bfd_size_type input_size
;
4609 /* Get the section contents. */
4610 input_size
= input_section
->size
;
4611 if (! bfd_get_section_contents (input_bfd
, input_section
,
4612 (void *) finfo
->contents
,
4613 (file_ptr
) 0, input_size
))
4616 /* Read in the relocs if we haven't already done it. */
4617 if (aout_section_data (input_section
) != NULL
4618 && aout_section_data (input_section
)->relocs
!= NULL
)
4619 relocs
= aout_section_data (input_section
)->relocs
;
4622 relocs
= finfo
->relocs
;
4625 if (bfd_seek (input_bfd
, input_section
->rel_filepos
, SEEK_SET
) != 0
4626 || bfd_bread (relocs
, rel_size
, input_bfd
) != rel_size
)
4631 /* Relocate the section contents. */
4632 if (obj_reloc_entry_size (input_bfd
) == RELOC_STD_SIZE
)
4634 if (! aout_link_input_section_std (finfo
, input_bfd
, input_section
,
4635 (struct reloc_std_external
*) relocs
,
4636 rel_size
, finfo
->contents
))
4641 if (! aout_link_input_section_ext (finfo
, input_bfd
, input_section
,
4642 (struct reloc_ext_external
*) relocs
,
4643 rel_size
, finfo
->contents
))
4647 /* Write out the section contents. */
4648 if (! bfd_set_section_contents (finfo
->output_bfd
,
4649 input_section
->output_section
,
4650 (void *) finfo
->contents
,
4651 (file_ptr
) input_section
->output_offset
,
4655 /* If we are producing relocatable output, the relocs were
4656 modified, and we now write them out. */
4657 if (finfo
->info
->relocatable
&& rel_size
> 0)
4659 if (bfd_seek (finfo
->output_bfd
, *reloff_ptr
, SEEK_SET
) != 0)
4661 if (bfd_bwrite (relocs
, rel_size
, finfo
->output_bfd
) != rel_size
)
4663 *reloff_ptr
+= rel_size
;
4665 /* Assert that the relocs have not run into the symbols, and
4666 that if these are the text relocs they have not run into the
4668 BFD_ASSERT (*reloff_ptr
<= obj_sym_filepos (finfo
->output_bfd
)
4669 && (reloff_ptr
!= &finfo
->treloff
4671 <= obj_datasec (finfo
->output_bfd
)->rel_filepos
)));
4677 /* Adjust and write out the symbols for an a.out file. Set the new
4678 symbol indices into a symbol_map. */
4681 aout_link_write_symbols (struct aout_final_link_info
*finfo
, bfd
*input_bfd
)
4684 bfd_size_type sym_count
;
4686 enum bfd_link_strip strip
;
4687 enum bfd_link_discard discard
;
4688 struct external_nlist
*outsym
;
4689 bfd_size_type strtab_index
;
4690 struct external_nlist
*sym
;
4691 struct external_nlist
*sym_end
;
4692 struct aout_link_hash_entry
**sym_hash
;
4695 bfd_boolean skip_next
;
4697 output_bfd
= finfo
->output_bfd
;
4698 sym_count
= obj_aout_external_sym_count (input_bfd
);
4699 strings
= obj_aout_external_strings (input_bfd
);
4700 strip
= finfo
->info
->strip
;
4701 discard
= finfo
->info
->discard
;
4702 outsym
= finfo
->output_syms
;
4704 /* First write out a symbol for this object file, unless we are
4705 discarding such symbols. */
4706 if (strip
!= strip_all
4707 && (strip
!= strip_some
4708 || bfd_hash_lookup (finfo
->info
->keep_hash
, input_bfd
->filename
,
4709 FALSE
, FALSE
) != NULL
)
4710 && discard
!= discard_all
)
4712 H_PUT_8 (output_bfd
, N_TEXT
, outsym
->e_type
);
4713 H_PUT_8 (output_bfd
, 0, outsym
->e_other
);
4714 H_PUT_16 (output_bfd
, 0, outsym
->e_desc
);
4715 strtab_index
= add_to_stringtab (output_bfd
, finfo
->strtab
,
4716 input_bfd
->filename
, FALSE
);
4717 if (strtab_index
== (bfd_size_type
) -1)
4719 PUT_WORD (output_bfd
, strtab_index
, outsym
->e_strx
);
4720 PUT_WORD (output_bfd
,
4721 (bfd_get_section_vma (output_bfd
,
4722 obj_textsec (input_bfd
)->output_section
)
4723 + obj_textsec (input_bfd
)->output_offset
),
4725 ++obj_aout_external_sym_count (output_bfd
);
4731 sym
= obj_aout_external_syms (input_bfd
);
4732 sym_end
= sym
+ sym_count
;
4733 sym_hash
= obj_aout_sym_hashes (input_bfd
);
4734 symbol_map
= finfo
->symbol_map
;
4735 memset (symbol_map
, 0, (size_t) sym_count
* sizeof *symbol_map
);
4736 for (; sym
< sym_end
; sym
++, sym_hash
++, symbol_map
++)
4740 struct aout_link_hash_entry
*h
;
4746 /* We set *symbol_map to 0 above for all symbols. If it has
4747 already been set to -1 for this symbol, it means that we are
4748 discarding it because it appears in a duplicate header file.
4749 See the N_BINCL code below. */
4750 if (*symbol_map
== -1)
4753 /* Initialize *symbol_map to -1, which means that the symbol was
4754 not copied into the output file. We will change it later if
4755 we do copy the symbol over. */
4758 type
= H_GET_8 (input_bfd
, sym
->e_type
);
4759 name
= strings
+ GET_WORD (input_bfd
, sym
->e_strx
);
4765 /* Pass this symbol through. It is the target of an
4766 indirect or warning symbol. */
4767 val
= GET_WORD (input_bfd
, sym
->e_value
);
4772 /* Skip this symbol, which is the target of an indirect
4773 symbol that we have changed to no longer be an indirect
4780 struct aout_link_hash_entry
*hresolve
;
4782 /* We have saved the hash table entry for this symbol, if
4783 there is one. Note that we could just look it up again
4784 in the hash table, provided we first check that it is an
4788 /* Use the name from the hash table, in case the symbol was
4791 && h
->root
.type
!= bfd_link_hash_warning
)
4792 name
= h
->root
.root
.string
;
4794 /* If this is an indirect or warning symbol, then change
4795 hresolve to the base symbol. We also change *sym_hash so
4796 that the relocation routines relocate against the real
4799 if (h
!= (struct aout_link_hash_entry
*) NULL
4800 && (h
->root
.type
== bfd_link_hash_indirect
4801 || h
->root
.type
== bfd_link_hash_warning
))
4803 hresolve
= (struct aout_link_hash_entry
*) h
->root
.u
.i
.link
;
4804 while (hresolve
->root
.type
== bfd_link_hash_indirect
4805 || hresolve
->root
.type
== bfd_link_hash_warning
)
4806 hresolve
= ((struct aout_link_hash_entry
*)
4807 hresolve
->root
.u
.i
.link
);
4808 *sym_hash
= hresolve
;
4811 /* If the symbol has already been written out, skip it. */
4815 if ((type
& N_TYPE
) == N_INDR
4816 || type
== N_WARNING
)
4818 *symbol_map
= h
->indx
;
4822 /* See if we are stripping this symbol. */
4828 case strip_debugger
:
4829 if ((type
& N_STAB
) != 0)
4833 if (bfd_hash_lookup (finfo
->info
->keep_hash
, name
, FALSE
, FALSE
)
4848 /* Get the value of the symbol. */
4849 if ((type
& N_TYPE
) == N_TEXT
4851 symsec
= obj_textsec (input_bfd
);
4852 else if ((type
& N_TYPE
) == N_DATA
4854 symsec
= obj_datasec (input_bfd
);
4855 else if ((type
& N_TYPE
) == N_BSS
4857 symsec
= obj_bsssec (input_bfd
);
4858 else if ((type
& N_TYPE
) == N_ABS
4860 symsec
= bfd_abs_section_ptr
;
4861 else if (((type
& N_TYPE
) == N_INDR
4862 && (hresolve
== NULL
4863 || (hresolve
->root
.type
!= bfd_link_hash_defined
4864 && hresolve
->root
.type
!= bfd_link_hash_defweak
4865 && hresolve
->root
.type
!= bfd_link_hash_common
)))
4866 || type
== N_WARNING
)
4868 /* Pass the next symbol through unchanged. The
4869 condition above for indirect symbols is so that if
4870 the indirect symbol was defined, we output it with
4871 the correct definition so the debugger will
4874 val
= GET_WORD (input_bfd
, sym
->e_value
);
4877 else if ((type
& N_STAB
) != 0)
4879 val
= GET_WORD (input_bfd
, sym
->e_value
);
4884 /* If we get here with an indirect symbol, it means that
4885 we are outputting it with a real definition. In such
4886 a case we do not want to output the next symbol,
4887 which is the target of the indirection. */
4888 if ((type
& N_TYPE
) == N_INDR
)
4893 /* We need to get the value from the hash table. We use
4894 hresolve so that if we have defined an indirect
4895 symbol we output the final definition. */
4898 switch (type
& N_TYPE
)
4901 symsec
= obj_textsec (input_bfd
);
4904 symsec
= obj_datasec (input_bfd
);
4907 symsec
= obj_bsssec (input_bfd
);
4910 symsec
= bfd_abs_section_ptr
;
4917 else if (hresolve
->root
.type
== bfd_link_hash_defined
4918 || hresolve
->root
.type
== bfd_link_hash_defweak
)
4920 asection
*input_section
;
4921 asection
*output_section
;
4923 /* This case usually means a common symbol which was
4924 turned into a defined symbol. */
4925 input_section
= hresolve
->root
.u
.def
.section
;
4926 output_section
= input_section
->output_section
;
4927 BFD_ASSERT (bfd_is_abs_section (output_section
)
4928 || output_section
->owner
== output_bfd
);
4929 val
= (hresolve
->root
.u
.def
.value
4930 + bfd_get_section_vma (output_bfd
, output_section
)
4931 + input_section
->output_offset
);
4933 /* Get the correct type based on the section. If
4934 this is a constructed set, force it to be
4935 globally visible. */
4944 if (output_section
== obj_textsec (output_bfd
))
4945 type
|= (hresolve
->root
.type
== bfd_link_hash_defined
4948 else if (output_section
== obj_datasec (output_bfd
))
4949 type
|= (hresolve
->root
.type
== bfd_link_hash_defined
4952 else if (output_section
== obj_bsssec (output_bfd
))
4953 type
|= (hresolve
->root
.type
== bfd_link_hash_defined
4957 type
|= (hresolve
->root
.type
== bfd_link_hash_defined
4961 else if (hresolve
->root
.type
== bfd_link_hash_common
)
4962 val
= hresolve
->root
.u
.c
.size
;
4963 else if (hresolve
->root
.type
== bfd_link_hash_undefweak
)
4972 val
= (symsec
->output_section
->vma
4973 + symsec
->output_offset
4974 + (GET_WORD (input_bfd
, sym
->e_value
)
4977 /* If this is a global symbol set the written flag, and if
4978 it is a local symbol see if we should discard it. */
4982 h
->indx
= obj_aout_external_sym_count (output_bfd
);
4984 else if ((type
& N_TYPE
) != N_SETT
4985 && (type
& N_TYPE
) != N_SETD
4986 && (type
& N_TYPE
) != N_SETB
4987 && (type
& N_TYPE
) != N_SETA
)
4992 case discard_sec_merge
:
4995 if ((type
& N_STAB
) == 0
4996 && bfd_is_local_label_name (input_bfd
, name
))
5010 /* An N_BINCL symbol indicates the start of the stabs
5011 entries for a header file. We need to scan ahead to the
5012 next N_EINCL symbol, ignoring nesting, adding up all the
5013 characters in the symbol names, not including the file
5014 numbers in types (the first number after an open
5016 if (type
== (int) N_BINCL
)
5018 struct external_nlist
*incl_sym
;
5020 struct aout_link_includes_entry
*incl_entry
;
5021 struct aout_link_includes_totals
*t
;
5025 for (incl_sym
= sym
+ 1; incl_sym
< sym_end
; incl_sym
++)
5029 incl_type
= H_GET_8 (input_bfd
, incl_sym
->e_type
);
5030 if (incl_type
== (int) N_EINCL
)
5036 else if (incl_type
== (int) N_BINCL
)
5042 s
= strings
+ GET_WORD (input_bfd
, incl_sym
->e_strx
);
5043 for (; *s
!= '\0'; s
++)
5048 /* Skip the file number. */
5050 while (ISDIGIT (*s
))
5058 /* If we have already included a header file with the
5059 same value, then replace this one with an N_EXCL
5061 copy
= (bfd_boolean
) (! finfo
->info
->keep_memory
);
5062 incl_entry
= aout_link_includes_lookup (&finfo
->includes
,
5064 if (incl_entry
== NULL
)
5066 for (t
= incl_entry
->totals
; t
!= NULL
; t
= t
->next
)
5067 if (t
->total
== val
)
5071 /* This is the first time we have seen this header
5072 file with this set of stabs strings. */
5073 t
= bfd_hash_allocate (&finfo
->includes
.root
,
5078 t
->next
= incl_entry
->totals
;
5079 incl_entry
->totals
= t
;
5085 /* This is a duplicate header file. We must change
5086 it to be an N_EXCL entry, and mark all the
5087 included symbols to prevent outputting them. */
5088 type
= (int) N_EXCL
;
5091 for (incl_sym
= sym
+ 1, incl_map
= symbol_map
+ 1;
5093 incl_sym
++, incl_map
++)
5097 incl_type
= H_GET_8 (input_bfd
, incl_sym
->e_type
);
5098 if (incl_type
== (int) N_EINCL
)
5107 else if (incl_type
== (int) N_BINCL
)
5116 /* Copy this symbol into the list of symbols we are going to
5118 H_PUT_8 (output_bfd
, type
, outsym
->e_type
);
5119 H_PUT_8 (output_bfd
, H_GET_8 (input_bfd
, sym
->e_other
), outsym
->e_other
);
5120 H_PUT_16 (output_bfd
, H_GET_16 (input_bfd
, sym
->e_desc
), outsym
->e_desc
);
5122 if (! finfo
->info
->keep_memory
)
5124 /* name points into a string table which we are going to
5125 free. If there is a hash table entry, use that string.
5126 Otherwise, copy name into memory. */
5128 name
= h
->root
.root
.string
;
5132 strtab_index
= add_to_stringtab (output_bfd
, finfo
->strtab
,
5134 if (strtab_index
== (bfd_size_type
) -1)
5136 PUT_WORD (output_bfd
, strtab_index
, outsym
->e_strx
);
5137 PUT_WORD (output_bfd
, val
, outsym
->e_value
);
5138 *symbol_map
= obj_aout_external_sym_count (output_bfd
);
5139 ++obj_aout_external_sym_count (output_bfd
);
5143 /* Write out the output symbols we have just constructed. */
5144 if (outsym
> finfo
->output_syms
)
5146 bfd_size_type outsym_size
;
5148 if (bfd_seek (output_bfd
, finfo
->symoff
, SEEK_SET
) != 0)
5150 outsym_size
= outsym
- finfo
->output_syms
;
5151 outsym_size
*= EXTERNAL_NLIST_SIZE
;
5152 if (bfd_bwrite ((void *) finfo
->output_syms
, outsym_size
, output_bfd
)
5155 finfo
->symoff
+= outsym_size
;
5161 /* Link an a.out input BFD into the output file. */
5164 aout_link_input_bfd (struct aout_final_link_info
*finfo
, bfd
*input_bfd
)
5166 bfd_size_type sym_count
;
5168 BFD_ASSERT (bfd_get_format (input_bfd
) == bfd_object
);
5170 /* If this is a dynamic object, it may need special handling. */
5171 if ((input_bfd
->flags
& DYNAMIC
) != 0
5172 && aout_backend_info (input_bfd
)->link_dynamic_object
!= NULL
)
5173 return ((*aout_backend_info (input_bfd
)->link_dynamic_object
)
5174 (finfo
->info
, input_bfd
));
5176 /* Get the symbols. We probably have them already, unless
5177 finfo->info->keep_memory is FALSE. */
5178 if (! aout_get_external_symbols (input_bfd
))
5181 sym_count
= obj_aout_external_sym_count (input_bfd
);
5183 /* Write out the symbols and get a map of the new indices. The map
5184 is placed into finfo->symbol_map. */
5185 if (! aout_link_write_symbols (finfo
, input_bfd
))
5188 /* Relocate and write out the sections. These functions use the
5189 symbol map created by aout_link_write_symbols. The linker_mark
5190 field will be set if these sections are to be included in the
5191 link, which will normally be the case. */
5192 if (obj_textsec (input_bfd
)->linker_mark
)
5194 if (! aout_link_input_section (finfo
, input_bfd
,
5195 obj_textsec (input_bfd
),
5197 exec_hdr (input_bfd
)->a_trsize
))
5200 if (obj_datasec (input_bfd
)->linker_mark
)
5202 if (! aout_link_input_section (finfo
, input_bfd
,
5203 obj_datasec (input_bfd
),
5205 exec_hdr (input_bfd
)->a_drsize
))
5209 /* If we are not keeping memory, we don't need the symbols any
5210 longer. We still need them if we are keeping memory, because the
5211 strings in the hash table point into them. */
5212 if (! finfo
->info
->keep_memory
)
5214 if (! aout_link_free_symbols (input_bfd
))
5221 /* Do the final link step. This is called on the output BFD. The
5222 INFO structure should point to a list of BFDs linked through the
5223 link_next field which can be used to find each BFD which takes part
5224 in the output. Also, each section in ABFD should point to a list
5225 of bfd_link_order structures which list all the input sections for
5226 the output section. */
5229 NAME (aout
, final_link
) (bfd
*abfd
,
5230 struct bfd_link_info
*info
,
5231 void (*callback
) (bfd
*, file_ptr
*, file_ptr
*, file_ptr
*))
5233 struct aout_final_link_info aout_info
;
5234 bfd_boolean includes_hash_initialized
= FALSE
;
5236 bfd_size_type trsize
, drsize
;
5237 bfd_size_type max_contents_size
;
5238 bfd_size_type max_relocs_size
;
5239 bfd_size_type max_sym_count
;
5240 bfd_size_type text_size
;
5242 struct bfd_link_order
*p
;
5244 bfd_boolean have_link_order_relocs
;
5247 abfd
->flags
|= DYNAMIC
;
5249 aout_info
.info
= info
;
5250 aout_info
.output_bfd
= abfd
;
5251 aout_info
.contents
= NULL
;
5252 aout_info
.relocs
= NULL
;
5253 aout_info
.symbol_map
= NULL
;
5254 aout_info
.output_syms
= NULL
;
5256 if (! bfd_hash_table_init_n (&aout_info
.includes
.root
,
5257 aout_link_includes_newfunc
,
5260 includes_hash_initialized
= TRUE
;
5262 /* Figure out the largest section size. Also, if generating
5263 relocatable output, count the relocs. */
5266 max_contents_size
= 0;
5267 max_relocs_size
= 0;
5269 for (sub
= info
->input_bfds
; sub
!= NULL
; sub
= sub
->link_next
)
5273 if (info
->relocatable
)
5275 if (bfd_get_flavour (sub
) == bfd_target_aout_flavour
)
5277 trsize
+= exec_hdr (sub
)->a_trsize
;
5278 drsize
+= exec_hdr (sub
)->a_drsize
;
5282 /* FIXME: We need to identify the .text and .data sections
5283 and call get_reloc_upper_bound and canonicalize_reloc to
5284 work out the number of relocs needed, and then multiply
5285 by the reloc size. */
5286 (*_bfd_error_handler
)
5287 (_("%s: relocatable link from %s to %s not supported"),
5288 bfd_get_filename (abfd
),
5289 sub
->xvec
->name
, abfd
->xvec
->name
);
5290 bfd_set_error (bfd_error_invalid_operation
);
5295 if (bfd_get_flavour (sub
) == bfd_target_aout_flavour
)
5297 sz
= obj_textsec (sub
)->size
;
5298 if (sz
> max_contents_size
)
5299 max_contents_size
= sz
;
5300 sz
= obj_datasec (sub
)->size
;
5301 if (sz
> max_contents_size
)
5302 max_contents_size
= sz
;
5304 sz
= exec_hdr (sub
)->a_trsize
;
5305 if (sz
> max_relocs_size
)
5306 max_relocs_size
= sz
;
5307 sz
= exec_hdr (sub
)->a_drsize
;
5308 if (sz
> max_relocs_size
)
5309 max_relocs_size
= sz
;
5311 sz
= obj_aout_external_sym_count (sub
);
5312 if (sz
> max_sym_count
)
5317 if (info
->relocatable
)
5319 if (obj_textsec (abfd
) != NULL
)
5320 trsize
+= (_bfd_count_link_order_relocs (obj_textsec (abfd
)
5322 * obj_reloc_entry_size (abfd
));
5323 if (obj_datasec (abfd
) != NULL
)
5324 drsize
+= (_bfd_count_link_order_relocs (obj_datasec (abfd
)
5326 * obj_reloc_entry_size (abfd
));
5329 exec_hdr (abfd
)->a_trsize
= trsize
;
5330 exec_hdr (abfd
)->a_drsize
= drsize
;
5332 exec_hdr (abfd
)->a_entry
= bfd_get_start_address (abfd
);
5334 /* Adjust the section sizes and vmas according to the magic number.
5335 This sets a_text, a_data and a_bss in the exec_hdr and sets the
5336 filepos for each section. */
5337 if (! NAME (aout
, adjust_sizes_and_vmas
) (abfd
, &text_size
, &text_end
))
5340 /* The relocation and symbol file positions differ among a.out
5341 targets. We are passed a callback routine from the backend
5342 specific code to handle this.
5343 FIXME: At this point we do not know how much space the symbol
5344 table will require. This will not work for any (nonstandard)
5345 a.out target that needs to know the symbol table size before it
5346 can compute the relocation file positions. This may or may not
5347 be the case for the hp300hpux target, for example. */
5348 (*callback
) (abfd
, &aout_info
.treloff
, &aout_info
.dreloff
,
5350 obj_textsec (abfd
)->rel_filepos
= aout_info
.treloff
;
5351 obj_datasec (abfd
)->rel_filepos
= aout_info
.dreloff
;
5352 obj_sym_filepos (abfd
) = aout_info
.symoff
;
5354 /* We keep a count of the symbols as we output them. */
5355 obj_aout_external_sym_count (abfd
) = 0;
5357 /* We accumulate the string table as we write out the symbols. */
5358 aout_info
.strtab
= _bfd_stringtab_init ();
5359 if (aout_info
.strtab
== NULL
)
5362 /* Allocate buffers to hold section contents and relocs. */
5363 aout_info
.contents
= bfd_malloc (max_contents_size
);
5364 aout_info
.relocs
= bfd_malloc (max_relocs_size
);
5365 aout_info
.symbol_map
= bfd_malloc (max_sym_count
* sizeof (int *));
5366 aout_info
.output_syms
= bfd_malloc ((max_sym_count
+ 1)
5367 * sizeof (struct external_nlist
));
5368 if ((aout_info
.contents
== NULL
&& max_contents_size
!= 0)
5369 || (aout_info
.relocs
== NULL
&& max_relocs_size
!= 0)
5370 || (aout_info
.symbol_map
== NULL
&& max_sym_count
!= 0)
5371 || aout_info
.output_syms
== NULL
)
5374 /* If we have a symbol named __DYNAMIC, force it out now. This is
5375 required by SunOS. Doing this here rather than in sunos.c is a
5376 hack, but it's easier than exporting everything which would be
5379 struct aout_link_hash_entry
*h
;
5381 h
= aout_link_hash_lookup (aout_hash_table (info
), "__DYNAMIC",
5382 FALSE
, FALSE
, FALSE
);
5384 aout_link_write_other_symbol (h
, &aout_info
);
5387 /* The most time efficient way to do the link would be to read all
5388 the input object files into memory and then sort out the
5389 information into the output file. Unfortunately, that will
5390 probably use too much memory. Another method would be to step
5391 through everything that composes the text section and write it
5392 out, and then everything that composes the data section and write
5393 it out, and then write out the relocs, and then write out the
5394 symbols. Unfortunately, that requires reading stuff from each
5395 input file several times, and we will not be able to keep all the
5396 input files open simultaneously, and reopening them will be slow.
5398 What we do is basically process one input file at a time. We do
5399 everything we need to do with an input file once--copy over the
5400 section contents, handle the relocation information, and write
5401 out the symbols--and then we throw away the information we read
5402 from it. This approach requires a lot of lseeks of the output
5403 file, which is unfortunate but still faster than reopening a lot
5406 We use the output_has_begun field of the input BFDs to see
5407 whether we have already handled it. */
5408 for (sub
= info
->input_bfds
; sub
!= NULL
; sub
= sub
->link_next
)
5409 sub
->output_has_begun
= FALSE
;
5411 /* Mark all sections which are to be included in the link. This
5412 will normally be every section. We need to do this so that we
5413 can identify any sections which the linker has decided to not
5415 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
5417 for (p
= o
->link_order_head
; p
!= NULL
; p
= p
->next
)
5418 if (p
->type
== bfd_indirect_link_order
)
5419 p
->u
.indirect
.section
->linker_mark
= TRUE
;
5422 have_link_order_relocs
= FALSE
;
5423 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
5425 for (p
= o
->link_order_head
;
5429 if (p
->type
== bfd_indirect_link_order
5430 && (bfd_get_flavour (p
->u
.indirect
.section
->owner
)
5431 == bfd_target_aout_flavour
))
5435 input_bfd
= p
->u
.indirect
.section
->owner
;
5436 if (! input_bfd
->output_has_begun
)
5438 if (! aout_link_input_bfd (&aout_info
, input_bfd
))
5440 input_bfd
->output_has_begun
= TRUE
;
5443 else if (p
->type
== bfd_section_reloc_link_order
5444 || p
->type
== bfd_symbol_reloc_link_order
)
5446 /* These are handled below. */
5447 have_link_order_relocs
= TRUE
;
5451 if (! _bfd_default_link_order (abfd
, info
, o
, p
))
5457 /* Write out any symbols that we have not already written out. */
5458 aout_link_hash_traverse (aout_hash_table (info
),
5459 aout_link_write_other_symbol
,
5460 (void *) &aout_info
);
5462 /* Now handle any relocs we were asked to create by the linker.
5463 These did not come from any input file. We must do these after
5464 we have written out all the symbols, so that we know the symbol
5466 if (have_link_order_relocs
)
5468 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
5470 for (p
= o
->link_order_head
;
5474 if (p
->type
== bfd_section_reloc_link_order
5475 || p
->type
== bfd_symbol_reloc_link_order
)
5477 if (! aout_link_reloc_link_order (&aout_info
, o
, p
))
5484 if (aout_info
.contents
!= NULL
)
5486 free (aout_info
.contents
);
5487 aout_info
.contents
= NULL
;
5489 if (aout_info
.relocs
!= NULL
)
5491 free (aout_info
.relocs
);
5492 aout_info
.relocs
= NULL
;
5494 if (aout_info
.symbol_map
!= NULL
)
5496 free (aout_info
.symbol_map
);
5497 aout_info
.symbol_map
= NULL
;
5499 if (aout_info
.output_syms
!= NULL
)
5501 free (aout_info
.output_syms
);
5502 aout_info
.output_syms
= NULL
;
5504 if (includes_hash_initialized
)
5506 bfd_hash_table_free (&aout_info
.includes
.root
);
5507 includes_hash_initialized
= FALSE
;
5510 /* Finish up any dynamic linking we may be doing. */
5511 if (aout_backend_info (abfd
)->finish_dynamic_link
!= NULL
)
5513 if (! (*aout_backend_info (abfd
)->finish_dynamic_link
) (abfd
, info
))
5517 /* Update the header information. */
5518 abfd
->symcount
= obj_aout_external_sym_count (abfd
);
5519 exec_hdr (abfd
)->a_syms
= abfd
->symcount
* EXTERNAL_NLIST_SIZE
;
5520 obj_str_filepos (abfd
) = obj_sym_filepos (abfd
) + exec_hdr (abfd
)->a_syms
;
5521 obj_textsec (abfd
)->reloc_count
=
5522 exec_hdr (abfd
)->a_trsize
/ obj_reloc_entry_size (abfd
);
5523 obj_datasec (abfd
)->reloc_count
=
5524 exec_hdr (abfd
)->a_drsize
/ obj_reloc_entry_size (abfd
);
5526 /* Write out the string table, unless there are no symbols. */
5527 if (abfd
->symcount
> 0)
5529 if (bfd_seek (abfd
, obj_str_filepos (abfd
), SEEK_SET
) != 0
5530 || ! emit_stringtab (abfd
, aout_info
.strtab
))
5533 else if (obj_textsec (abfd
)->reloc_count
== 0
5534 && obj_datasec (abfd
)->reloc_count
== 0)
5540 pos
= obj_datasec (abfd
)->filepos
+ exec_hdr (abfd
)->a_data
- 1;
5541 if (bfd_seek (abfd
, pos
, SEEK_SET
) != 0
5542 || bfd_bwrite (&b
, (bfd_size_type
) 1, abfd
) != 1)
5549 if (aout_info
.contents
!= NULL
)
5550 free (aout_info
.contents
);
5551 if (aout_info
.relocs
!= NULL
)
5552 free (aout_info
.relocs
);
5553 if (aout_info
.symbol_map
!= NULL
)
5554 free (aout_info
.symbol_map
);
5555 if (aout_info
.output_syms
!= NULL
)
5556 free (aout_info
.output_syms
);
5557 if (includes_hash_initialized
)
5558 bfd_hash_table_free (&aout_info
.includes
.root
);