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., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, 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_v8plus
710 || machine
== bfd_mach_sparc_v8plusa
711 || machine
== bfd_mach_sparc_v8plusb
712 || machine
== bfd_mach_sparc_v9
713 || machine
== bfd_mach_sparc_v9a
714 || machine
== bfd_mach_sparc_v9b
)
715 arch_flags
= M_SPARC
;
716 else if (machine
== bfd_mach_sparc_sparclet
)
717 arch_flags
= M_SPARCLET
;
723 case 0: arch_flags
= M_68010
; break;
724 case bfd_mach_m68000
: arch_flags
= M_UNKNOWN
; *unknown
= FALSE
; break;
725 case bfd_mach_m68010
: arch_flags
= M_68010
; break;
726 case bfd_mach_m68020
: arch_flags
= M_68020
; break;
727 default: arch_flags
= M_UNKNOWN
; break;
733 || machine
== bfd_mach_i386_i386
734 || 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. */
852 obj_reloc_entry_size (abfd
) = RELOC_EXT_SIZE
;
855 obj_reloc_entry_size (abfd
) = RELOC_STD_SIZE
;
859 return (*aout_backend_info (abfd
)->set_sizes
) (abfd
);
863 adjust_o_magic (bfd
*abfd
, struct internal_exec
*execp
)
865 file_ptr pos
= adata (abfd
).exec_bytes_size
;
870 obj_textsec (abfd
)->filepos
= pos
;
871 if (!obj_textsec (abfd
)->user_set_vma
)
872 obj_textsec (abfd
)->vma
= vma
;
874 vma
= obj_textsec (abfd
)->vma
;
876 pos
+= obj_textsec (abfd
)->size
;
877 vma
+= obj_textsec (abfd
)->size
;
880 if (!obj_datasec (abfd
)->user_set_vma
)
882 obj_textsec (abfd
)->size
+= pad
;
885 obj_datasec (abfd
)->vma
= vma
;
888 vma
= obj_datasec (abfd
)->vma
;
889 obj_datasec (abfd
)->filepos
= pos
;
890 pos
+= obj_datasec (abfd
)->size
;
891 vma
+= obj_datasec (abfd
)->size
;
894 if (!obj_bsssec (abfd
)->user_set_vma
)
896 obj_datasec (abfd
)->size
+= pad
;
899 obj_bsssec (abfd
)->vma
= vma
;
903 /* The VMA of the .bss section is set by the VMA of the
904 .data section plus the size of the .data section. We may
905 need to add padding bytes to make this true. */
906 pad
= obj_bsssec (abfd
)->vma
- vma
;
909 obj_datasec (abfd
)->size
+= pad
;
913 obj_bsssec (abfd
)->filepos
= pos
;
915 /* Fix up the exec header. */
916 execp
->a_text
= obj_textsec (abfd
)->size
;
917 execp
->a_data
= obj_datasec (abfd
)->size
;
918 execp
->a_bss
= obj_bsssec (abfd
)->size
;
919 N_SET_MAGIC (*execp
, OMAGIC
);
923 adjust_z_magic (bfd
*abfd
, struct internal_exec
*execp
)
925 bfd_size_type data_pad
, text_pad
;
927 const struct aout_backend_data
*abdp
;
928 /* TRUE if text includes exec header. */
931 abdp
= aout_backend_info (abfd
);
935 && (abdp
->text_includes_header
936 || obj_aout_subformat (abfd
) == q_magic_format
));
937 obj_textsec (abfd
)->filepos
= (ztih
938 ? adata (abfd
).exec_bytes_size
939 : adata (abfd
).zmagic_disk_block_size
);
940 if (! obj_textsec (abfd
)->user_set_vma
)
942 /* ?? Do we really need to check for relocs here? */
943 obj_textsec (abfd
)->vma
= ((abfd
->flags
& HAS_RELOC
)
946 ? (abdp
->default_text_vma
947 + adata (abfd
).exec_bytes_size
)
948 : abdp
->default_text_vma
));
953 /* The .text section is being loaded at an unusual address. We
954 may need to pad it such that the .data section starts at a page
957 text_pad
= ((obj_textsec (abfd
)->filepos
- obj_textsec (abfd
)->vma
)
958 & (adata (abfd
).page_size
- 1));
960 text_pad
= ((- obj_textsec (abfd
)->vma
)
961 & (adata (abfd
).page_size
- 1));
964 /* Find start of data. */
967 text_end
= obj_textsec (abfd
)->filepos
+ obj_textsec (abfd
)->size
;
968 text_pad
+= BFD_ALIGN (text_end
, adata (abfd
).page_size
) - text_end
;
972 /* Note that if page_size == zmagic_disk_block_size, then
973 filepos == page_size, and this case is the same as the ztih
975 text_end
= obj_textsec (abfd
)->size
;
976 text_pad
+= BFD_ALIGN (text_end
, adata (abfd
).page_size
) - text_end
;
977 text_end
+= obj_textsec (abfd
)->filepos
;
979 obj_textsec (abfd
)->size
+= text_pad
;
980 text_end
+= text_pad
;
983 if (!obj_datasec (abfd
)->user_set_vma
)
986 vma
= obj_textsec (abfd
)->vma
+ obj_textsec (abfd
)->size
;
987 obj_datasec (abfd
)->vma
= BFD_ALIGN (vma
, adata (abfd
).segment_size
);
989 if (abdp
&& abdp
->zmagic_mapped_contiguous
)
991 asection
* text
= obj_textsec (abfd
);
992 asection
* data
= obj_datasec (abfd
);
994 text_pad
= data
->vma
- (text
->vma
+ text
->size
);
995 /* Only pad the text section if the data
996 section is going to be placed after it. */
998 text
->size
+= text_pad
;
1000 obj_datasec (abfd
)->filepos
= (obj_textsec (abfd
)->filepos
1001 + obj_textsec (abfd
)->size
);
1003 /* Fix up exec header while we're at it. */
1004 execp
->a_text
= obj_textsec (abfd
)->size
;
1005 if (ztih
&& (!abdp
|| (abdp
&& !abdp
->exec_header_not_counted
)))
1006 execp
->a_text
+= adata (abfd
).exec_bytes_size
;
1007 if (obj_aout_subformat (abfd
) == q_magic_format
)
1008 N_SET_MAGIC (*execp
, QMAGIC
);
1010 N_SET_MAGIC (*execp
, ZMAGIC
);
1012 /* Spec says data section should be rounded up to page boundary. */
1013 obj_datasec (abfd
)->size
1014 = align_power (obj_datasec (abfd
)->size
,
1015 obj_bsssec (abfd
)->alignment_power
);
1016 execp
->a_data
= BFD_ALIGN (obj_datasec (abfd
)->size
,
1017 adata (abfd
).page_size
);
1018 data_pad
= execp
->a_data
- obj_datasec (abfd
)->size
;
1021 if (!obj_bsssec (abfd
)->user_set_vma
)
1022 obj_bsssec (abfd
)->vma
= (obj_datasec (abfd
)->vma
1023 + obj_datasec (abfd
)->size
);
1024 /* If the BSS immediately follows the data section and extra space
1025 in the page is left after the data section, fudge data
1026 in the header so that the bss section looks smaller by that
1027 amount. We'll start the bss section there, and lie to the OS.
1028 (Note that a linker script, as well as the above assignment,
1029 could have explicitly set the BSS vma to immediately follow
1030 the data section.) */
1031 if (align_power (obj_bsssec (abfd
)->vma
, obj_bsssec (abfd
)->alignment_power
)
1032 == obj_datasec (abfd
)->vma
+ obj_datasec (abfd
)->size
)
1033 execp
->a_bss
= (data_pad
> obj_bsssec (abfd
)->size
1034 ? 0 : obj_bsssec (abfd
)->size
- data_pad
);
1036 execp
->a_bss
= obj_bsssec (abfd
)->size
;
1040 adjust_n_magic (bfd
*abfd
, struct internal_exec
*execp
)
1042 file_ptr pos
= adata (abfd
).exec_bytes_size
;
1047 obj_textsec (abfd
)->filepos
= pos
;
1048 if (!obj_textsec (abfd
)->user_set_vma
)
1049 obj_textsec (abfd
)->vma
= vma
;
1051 vma
= obj_textsec (abfd
)->vma
;
1052 pos
+= obj_textsec (abfd
)->size
;
1053 vma
+= obj_textsec (abfd
)->size
;
1056 obj_datasec (abfd
)->filepos
= pos
;
1057 if (!obj_datasec (abfd
)->user_set_vma
)
1058 obj_datasec (abfd
)->vma
= BFD_ALIGN (vma
, adata (abfd
).segment_size
);
1059 vma
= obj_datasec (abfd
)->vma
;
1061 /* Since BSS follows data immediately, see if it needs alignment. */
1062 vma
+= obj_datasec (abfd
)->size
;
1063 pad
= align_power (vma
, obj_bsssec (abfd
)->alignment_power
) - vma
;
1064 obj_datasec (abfd
)->size
+= pad
;
1065 pos
+= obj_datasec (abfd
)->size
;
1068 if (!obj_bsssec (abfd
)->user_set_vma
)
1069 obj_bsssec (abfd
)->vma
= vma
;
1071 vma
= obj_bsssec (abfd
)->vma
;
1073 /* Fix up exec header. */
1074 execp
->a_text
= obj_textsec (abfd
)->size
;
1075 execp
->a_data
= obj_datasec (abfd
)->size
;
1076 execp
->a_bss
= obj_bsssec (abfd
)->size
;
1077 N_SET_MAGIC (*execp
, NMAGIC
);
1081 NAME (aout
, adjust_sizes_and_vmas
) (bfd
*abfd
,
1082 bfd_size_type
*text_size
,
1083 file_ptr
*text_end ATTRIBUTE_UNUSED
)
1085 struct internal_exec
*execp
= exec_hdr (abfd
);
1087 if (! NAME (aout
, make_sections
) (abfd
))
1090 if (adata (abfd
).magic
!= undecided_magic
)
1093 obj_textsec (abfd
)->size
=
1094 align_power (obj_textsec (abfd
)->size
,
1095 obj_textsec (abfd
)->alignment_power
);
1097 *text_size
= obj_textsec (abfd
)->size
;
1098 /* Rule (heuristic) for when to pad to a new page. Note that there
1099 are (at least) two ways demand-paged (ZMAGIC) files have been
1100 handled. Most Berkeley-based systems start the text segment at
1101 (TARGET_PAGE_SIZE). However, newer versions of SUNOS start the text
1102 segment right after the exec header; the latter is counted in the
1103 text segment size, and is paged in by the kernel with the rest of
1106 /* This perhaps isn't the right way to do this, but made it simpler for me
1107 to understand enough to implement it. Better would probably be to go
1108 right from BFD flags to alignment/positioning characteristics. But the
1109 old code was sloppy enough about handling the flags, and had enough
1110 other magic, that it was a little hard for me to understand. I think
1111 I understand it better now, but I haven't time to do the cleanup this
1114 if (abfd
->flags
& D_PAGED
)
1115 /* Whether or not WP_TEXT is set -- let D_PAGED override. */
1116 adata (abfd
).magic
= z_magic
;
1117 else if (abfd
->flags
& WP_TEXT
)
1118 adata (abfd
).magic
= n_magic
;
1120 adata (abfd
).magic
= o_magic
;
1122 #ifdef BFD_AOUT_DEBUG /* requires gcc2 */
1124 fprintf (stderr
, "%s text=<%x,%x,%x> data=<%x,%x,%x> bss=<%x,%x,%x>\n",
1126 switch (adata (abfd
).magic
)
1128 case n_magic
: str
= "NMAGIC"; break;
1129 case o_magic
: str
= "OMAGIC"; break;
1130 case z_magic
: str
= "ZMAGIC"; break;
1135 obj_textsec (abfd
)->vma
, obj_textsec (abfd
)->size
,
1136 obj_textsec (abfd
)->alignment_power
,
1137 obj_datasec (abfd
)->vma
, obj_datasec (abfd
)->size
,
1138 obj_datasec (abfd
)->alignment_power
,
1139 obj_bsssec (abfd
)->vma
, obj_bsssec (abfd
)->size
,
1140 obj_bsssec (abfd
)->alignment_power
);
1144 switch (adata (abfd
).magic
)
1147 adjust_o_magic (abfd
, execp
);
1150 adjust_z_magic (abfd
, execp
);
1153 adjust_n_magic (abfd
, execp
);
1159 #ifdef BFD_AOUT_DEBUG
1160 fprintf (stderr
, " text=<%x,%x,%x> data=<%x,%x,%x> bss=<%x,%x>\n",
1161 obj_textsec (abfd
)->vma
, obj_textsec (abfd
)->size
,
1162 obj_textsec (abfd
)->filepos
,
1163 obj_datasec (abfd
)->vma
, obj_datasec (abfd
)->size
,
1164 obj_datasec (abfd
)->filepos
,
1165 obj_bsssec (abfd
)->vma
, obj_bsssec (abfd
)->size
);
1173 aout_@var{size}_new_section_hook
1176 bfd_boolean aout_@var{size}_new_section_hook,
1181 Called by the BFD in response to a @code{bfd_make_section}
1185 NAME (aout
, new_section_hook
) (bfd
*abfd
, asection
*newsect
)
1187 /* Align to double at least. */
1188 newsect
->alignment_power
= bfd_get_arch_info (abfd
)->section_align_power
;
1190 if (bfd_get_format (abfd
) == bfd_object
)
1192 if (obj_textsec (abfd
) == NULL
&& !strcmp (newsect
->name
, ".text"))
1194 obj_textsec (abfd
)= newsect
;
1195 newsect
->target_index
= N_TEXT
;
1199 if (obj_datasec (abfd
) == NULL
&& !strcmp (newsect
->name
, ".data"))
1201 obj_datasec (abfd
) = newsect
;
1202 newsect
->target_index
= N_DATA
;
1206 if (obj_bsssec (abfd
) == NULL
&& !strcmp (newsect
->name
, ".bss"))
1208 obj_bsssec (abfd
) = newsect
;
1209 newsect
->target_index
= N_BSS
;
1214 /* We allow more than three sections internally. */
1219 NAME (aout
, set_section_contents
) (bfd
*abfd
,
1221 const void * location
,
1223 bfd_size_type count
)
1226 bfd_size_type text_size
;
1228 if (! abfd
->output_has_begun
)
1230 if (! NAME (aout
, adjust_sizes_and_vmas
) (abfd
, &text_size
, &text_end
))
1234 if (section
== obj_bsssec (abfd
))
1236 bfd_set_error (bfd_error_no_contents
);
1240 if (section
!= obj_textsec (abfd
)
1241 && section
!= obj_datasec (abfd
))
1243 if (aout_section_merge_with_text_p (abfd
, section
))
1244 section
->filepos
= obj_textsec (abfd
)->filepos
+
1245 (section
->vma
- obj_textsec (abfd
)->vma
);
1248 (*_bfd_error_handler
)
1249 (_("%s: can not represent section `%s' in a.out object file format"),
1250 bfd_get_filename (abfd
), bfd_get_section_name (abfd
, section
));
1251 bfd_set_error (bfd_error_nonrepresentable_section
);
1258 if (bfd_seek (abfd
, section
->filepos
+ offset
, SEEK_SET
) != 0
1259 || bfd_bwrite (location
, count
, abfd
) != count
)
1266 /* Read the external symbols from an a.out file. */
1269 aout_get_external_symbols (bfd
*abfd
)
1271 if (obj_aout_external_syms (abfd
) == NULL
)
1273 bfd_size_type count
;
1274 struct external_nlist
*syms
;
1277 count
= exec_hdr (abfd
)->a_syms
/ EXTERNAL_NLIST_SIZE
;
1280 if (! bfd_get_file_window (abfd
, obj_sym_filepos (abfd
),
1281 exec_hdr (abfd
)->a_syms
,
1282 &obj_aout_sym_window (abfd
), TRUE
))
1284 syms
= (struct external_nlist
*) obj_aout_sym_window (abfd
).data
;
1286 /* We allocate using malloc to make the values easy to free
1287 later on. If we put them on the objalloc it might not be
1288 possible to free them. */
1289 syms
= bfd_malloc (count
* EXTERNAL_NLIST_SIZE
);
1290 if (syms
== NULL
&& count
!= 0)
1293 amt
= exec_hdr (abfd
)->a_syms
;
1294 if (bfd_seek (abfd
, obj_sym_filepos (abfd
), SEEK_SET
) != 0
1295 || bfd_bread (syms
, amt
, abfd
) != amt
)
1302 obj_aout_external_syms (abfd
) = syms
;
1303 obj_aout_external_sym_count (abfd
) = count
;
1306 if (obj_aout_external_strings (abfd
) == NULL
1307 && exec_hdr (abfd
)->a_syms
!= 0)
1309 unsigned char string_chars
[BYTES_IN_WORD
];
1310 bfd_size_type stringsize
;
1312 bfd_size_type amt
= BYTES_IN_WORD
;
1314 /* Get the size of the strings. */
1315 if (bfd_seek (abfd
, obj_str_filepos (abfd
), SEEK_SET
) != 0
1316 || bfd_bread ((void *) string_chars
, amt
, abfd
) != amt
)
1318 stringsize
= GET_WORD (abfd
, string_chars
);
1321 if (! bfd_get_file_window (abfd
, obj_str_filepos (abfd
), stringsize
,
1322 &obj_aout_string_window (abfd
), TRUE
))
1324 strings
= (char *) obj_aout_string_window (abfd
).data
;
1326 strings
= bfd_malloc (stringsize
+ 1);
1327 if (strings
== NULL
)
1330 /* Skip space for the string count in the buffer for convenience
1331 when using indexes. */
1332 amt
= stringsize
- BYTES_IN_WORD
;
1333 if (bfd_bread (strings
+ BYTES_IN_WORD
, amt
, abfd
) != amt
)
1340 /* Ensure that a zero index yields an empty string. */
1343 strings
[stringsize
- 1] = 0;
1345 obj_aout_external_strings (abfd
) = strings
;
1346 obj_aout_external_string_size (abfd
) = stringsize
;
1352 /* Translate an a.out symbol into a BFD symbol. The desc, other, type
1353 and symbol->value fields of CACHE_PTR will be set from the a.out
1354 nlist structure. This function is responsible for setting
1355 symbol->flags and symbol->section, and adjusting symbol->value. */
1358 translate_from_native_sym_flags (bfd
*abfd
, aout_symbol_type
*cache_ptr
)
1362 if ((cache_ptr
->type
& N_STAB
) != 0
1363 || cache_ptr
->type
== N_FN
)
1367 /* This is a debugging symbol. */
1368 cache_ptr
->symbol
.flags
= BSF_DEBUGGING
;
1370 /* Work out the symbol section. */
1371 switch (cache_ptr
->type
& N_TYPE
)
1375 sec
= obj_textsec (abfd
);
1378 sec
= obj_datasec (abfd
);
1381 sec
= obj_bsssec (abfd
);
1385 sec
= bfd_abs_section_ptr
;
1389 cache_ptr
->symbol
.section
= sec
;
1390 cache_ptr
->symbol
.value
-= sec
->vma
;
1395 /* Get the default visibility. This does not apply to all types, so
1396 we just hold it in a local variable to use if wanted. */
1397 if ((cache_ptr
->type
& N_EXT
) == 0)
1398 visible
= BSF_LOCAL
;
1400 visible
= BSF_GLOBAL
;
1402 switch (cache_ptr
->type
)
1405 case N_ABS
: case N_ABS
| N_EXT
:
1406 cache_ptr
->symbol
.section
= bfd_abs_section_ptr
;
1407 cache_ptr
->symbol
.flags
= visible
;
1410 case N_UNDF
| N_EXT
:
1411 if (cache_ptr
->symbol
.value
!= 0)
1413 /* This is a common symbol. */
1414 cache_ptr
->symbol
.flags
= BSF_GLOBAL
;
1415 cache_ptr
->symbol
.section
= bfd_com_section_ptr
;
1419 cache_ptr
->symbol
.flags
= 0;
1420 cache_ptr
->symbol
.section
= bfd_und_section_ptr
;
1424 case N_TEXT
: case N_TEXT
| N_EXT
:
1425 cache_ptr
->symbol
.section
= obj_textsec (abfd
);
1426 cache_ptr
->symbol
.value
-= cache_ptr
->symbol
.section
->vma
;
1427 cache_ptr
->symbol
.flags
= visible
;
1430 /* N_SETV symbols used to represent set vectors placed in the
1431 data section. They are no longer generated. Theoretically,
1432 it was possible to extract the entries and combine them with
1433 new ones, although I don't know if that was ever actually
1434 done. Unless that feature is restored, treat them as data
1436 case N_SETV
: case N_SETV
| N_EXT
:
1437 case N_DATA
: case N_DATA
| N_EXT
:
1438 cache_ptr
->symbol
.section
= obj_datasec (abfd
);
1439 cache_ptr
->symbol
.value
-= cache_ptr
->symbol
.section
->vma
;
1440 cache_ptr
->symbol
.flags
= visible
;
1443 case N_BSS
: case N_BSS
| N_EXT
:
1444 cache_ptr
->symbol
.section
= obj_bsssec (abfd
);
1445 cache_ptr
->symbol
.value
-= cache_ptr
->symbol
.section
->vma
;
1446 cache_ptr
->symbol
.flags
= visible
;
1449 case N_SETA
: case N_SETA
| N_EXT
:
1450 case N_SETT
: case N_SETT
| N_EXT
:
1451 case N_SETD
: case N_SETD
| N_EXT
:
1452 case N_SETB
: case N_SETB
| N_EXT
:
1454 /* This code is no longer needed. It used to be used to make
1455 the linker handle set symbols, but they are now handled in
1456 the add_symbols routine instead. */
1457 switch (cache_ptr
->type
& N_TYPE
)
1460 cache_ptr
->symbol
.section
= bfd_abs_section_ptr
;
1463 cache_ptr
->symbol
.section
= obj_textsec (abfd
);
1466 cache_ptr
->symbol
.section
= obj_datasec (abfd
);
1469 cache_ptr
->symbol
.section
= obj_bsssec (abfd
);
1473 cache_ptr
->symbol
.flags
|= BSF_CONSTRUCTOR
;
1478 /* This symbol is the text of a warning message. The next
1479 symbol is the symbol to associate the warning with. If a
1480 reference is made to that symbol, a warning is issued. */
1481 cache_ptr
->symbol
.flags
= BSF_DEBUGGING
| BSF_WARNING
;
1482 cache_ptr
->symbol
.section
= bfd_abs_section_ptr
;
1485 case N_INDR
: case N_INDR
| N_EXT
:
1486 /* An indirect symbol. This consists of two symbols in a row.
1487 The first symbol is the name of the indirection. The second
1488 symbol is the name of the target. A reference to the first
1489 symbol becomes a reference to the second. */
1490 cache_ptr
->symbol
.flags
= BSF_DEBUGGING
| BSF_INDIRECT
| visible
;
1491 cache_ptr
->symbol
.section
= bfd_ind_section_ptr
;
1495 cache_ptr
->symbol
.section
= bfd_und_section_ptr
;
1496 cache_ptr
->symbol
.flags
= BSF_WEAK
;
1500 cache_ptr
->symbol
.section
= bfd_abs_section_ptr
;
1501 cache_ptr
->symbol
.flags
= BSF_WEAK
;
1505 cache_ptr
->symbol
.section
= obj_textsec (abfd
);
1506 cache_ptr
->symbol
.value
-= cache_ptr
->symbol
.section
->vma
;
1507 cache_ptr
->symbol
.flags
= BSF_WEAK
;
1511 cache_ptr
->symbol
.section
= obj_datasec (abfd
);
1512 cache_ptr
->symbol
.value
-= cache_ptr
->symbol
.section
->vma
;
1513 cache_ptr
->symbol
.flags
= BSF_WEAK
;
1517 cache_ptr
->symbol
.section
= obj_bsssec (abfd
);
1518 cache_ptr
->symbol
.value
-= cache_ptr
->symbol
.section
->vma
;
1519 cache_ptr
->symbol
.flags
= BSF_WEAK
;
1526 /* Set the fields of SYM_POINTER according to CACHE_PTR. */
1529 translate_to_native_sym_flags (bfd
*abfd
,
1531 struct external_nlist
*sym_pointer
)
1533 bfd_vma value
= cache_ptr
->value
;
1537 /* Mask out any existing type bits in case copying from one section
1539 sym_pointer
->e_type
[0] &= ~N_TYPE
;
1541 sec
= bfd_get_section (cache_ptr
);
1546 /* This case occurs, e.g., for the *DEBUG* section of a COFF
1548 (*_bfd_error_handler
)
1549 (_("%s: can not represent section for symbol `%s' in a.out object file format"),
1550 bfd_get_filename (abfd
),
1551 cache_ptr
->name
!= NULL
? cache_ptr
->name
: _("*unknown*"));
1552 bfd_set_error (bfd_error_nonrepresentable_section
);
1556 if (sec
->output_section
!= NULL
)
1558 off
= sec
->output_offset
;
1559 sec
= sec
->output_section
;
1562 if (bfd_is_abs_section (sec
))
1563 sym_pointer
->e_type
[0] |= N_ABS
;
1564 else if (sec
== obj_textsec (abfd
))
1565 sym_pointer
->e_type
[0] |= N_TEXT
;
1566 else if (sec
== obj_datasec (abfd
))
1567 sym_pointer
->e_type
[0] |= N_DATA
;
1568 else if (sec
== obj_bsssec (abfd
))
1569 sym_pointer
->e_type
[0] |= N_BSS
;
1570 else if (bfd_is_und_section (sec
))
1571 sym_pointer
->e_type
[0] = N_UNDF
| N_EXT
;
1572 else if (bfd_is_ind_section (sec
))
1573 sym_pointer
->e_type
[0] = N_INDR
;
1574 else if (bfd_is_com_section (sec
))
1575 sym_pointer
->e_type
[0] = N_UNDF
| N_EXT
;
1578 if (aout_section_merge_with_text_p (abfd
, sec
))
1579 sym_pointer
->e_type
[0] |= N_TEXT
;
1582 (*_bfd_error_handler
)
1583 (_("%s: can not represent section `%s' in a.out object file format"),
1584 bfd_get_filename (abfd
), bfd_get_section_name (abfd
, sec
));
1585 bfd_set_error (bfd_error_nonrepresentable_section
);
1590 /* Turn the symbol from section relative to absolute again. */
1591 value
+= sec
->vma
+ off
;
1593 if ((cache_ptr
->flags
& BSF_WARNING
) != 0)
1594 sym_pointer
->e_type
[0] = N_WARNING
;
1596 if ((cache_ptr
->flags
& BSF_DEBUGGING
) != 0)
1597 sym_pointer
->e_type
[0] = ((aout_symbol_type
*) cache_ptr
)->type
;
1598 else if ((cache_ptr
->flags
& BSF_GLOBAL
) != 0)
1599 sym_pointer
->e_type
[0] |= N_EXT
;
1600 else if ((cache_ptr
->flags
& BSF_LOCAL
) != 0)
1601 sym_pointer
->e_type
[0] &= ~N_EXT
;
1603 if ((cache_ptr
->flags
& BSF_CONSTRUCTOR
) != 0)
1605 int type
= ((aout_symbol_type
*) cache_ptr
)->type
;
1609 case N_ABS
: type
= N_SETA
; break;
1610 case N_TEXT
: type
= N_SETT
; break;
1611 case N_DATA
: type
= N_SETD
; break;
1612 case N_BSS
: type
= N_SETB
; break;
1614 sym_pointer
->e_type
[0] = type
;
1617 if ((cache_ptr
->flags
& BSF_WEAK
) != 0)
1621 switch (sym_pointer
->e_type
[0] & N_TYPE
)
1624 case N_ABS
: type
= N_WEAKA
; break;
1625 case N_TEXT
: type
= N_WEAKT
; break;
1626 case N_DATA
: type
= N_WEAKD
; break;
1627 case N_BSS
: type
= N_WEAKB
; break;
1628 case N_UNDF
: type
= N_WEAKU
; break;
1630 sym_pointer
->e_type
[0] = type
;
1633 PUT_WORD (abfd
, value
, sym_pointer
->e_value
);
1638 /* Native-level interface to symbols. */
1641 NAME (aout
, make_empty_symbol
) (bfd
*abfd
)
1643 bfd_size_type amt
= sizeof (aout_symbol_type
);
1645 aout_symbol_type
*new = bfd_zalloc (abfd
, amt
);
1648 new->symbol
.the_bfd
= abfd
;
1650 return &new->symbol
;
1653 /* Translate a set of internal symbols into external symbols. */
1656 NAME (aout
, translate_symbol_table
) (bfd
*abfd
,
1657 aout_symbol_type
*in
,
1658 struct external_nlist
*ext
,
1659 bfd_size_type count
,
1661 bfd_size_type strsize
,
1662 bfd_boolean dynamic
)
1664 struct external_nlist
*ext_end
;
1666 ext_end
= ext
+ count
;
1667 for (; ext
< ext_end
; ext
++, in
++)
1671 x
= GET_WORD (abfd
, ext
->e_strx
);
1672 in
->symbol
.the_bfd
= abfd
;
1674 /* For the normal symbols, the zero index points at the number
1675 of bytes in the string table but is to be interpreted as the
1676 null string. For the dynamic symbols, the number of bytes in
1677 the string table is stored in the __DYNAMIC structure and the
1678 zero index points at an actual string. */
1679 if (x
== 0 && ! dynamic
)
1680 in
->symbol
.name
= "";
1681 else if (x
< strsize
)
1682 in
->symbol
.name
= str
+ x
;
1686 in
->symbol
.value
= GET_SWORD (abfd
, ext
->e_value
);
1687 in
->desc
= H_GET_16 (abfd
, ext
->e_desc
);
1688 in
->other
= H_GET_8 (abfd
, ext
->e_other
);
1689 in
->type
= H_GET_8 (abfd
, ext
->e_type
);
1690 in
->symbol
.udata
.p
= NULL
;
1692 if (! translate_from_native_sym_flags (abfd
, in
))
1696 in
->symbol
.flags
|= BSF_DYNAMIC
;
1702 /* We read the symbols into a buffer, which is discarded when this
1703 function exits. We read the strings into a buffer large enough to
1704 hold them all plus all the cached symbol entries. */
1707 NAME (aout
, slurp_symbol_table
) (bfd
*abfd
)
1709 struct external_nlist
*old_external_syms
;
1710 aout_symbol_type
*cached
;
1711 bfd_size_type cached_size
;
1713 /* If there's no work to be done, don't do any. */
1714 if (obj_aout_symbols (abfd
) != NULL
)
1717 old_external_syms
= obj_aout_external_syms (abfd
);
1719 if (! aout_get_external_symbols (abfd
))
1722 cached_size
= obj_aout_external_sym_count (abfd
);
1723 cached_size
*= sizeof (aout_symbol_type
);
1724 cached
= bfd_zmalloc (cached_size
);
1725 if (cached
== NULL
&& cached_size
!= 0)
1728 /* Convert from external symbol information to internal. */
1729 if (! (NAME (aout
, translate_symbol_table
)
1731 obj_aout_external_syms (abfd
),
1732 obj_aout_external_sym_count (abfd
),
1733 obj_aout_external_strings (abfd
),
1734 obj_aout_external_string_size (abfd
),
1741 bfd_get_symcount (abfd
) = obj_aout_external_sym_count (abfd
);
1743 obj_aout_symbols (abfd
) = cached
;
1745 /* It is very likely that anybody who calls this function will not
1746 want the external symbol information, so if it was allocated
1747 because of our call to aout_get_external_symbols, we free it up
1748 right away to save space. */
1749 if (old_external_syms
== NULL
1750 && obj_aout_external_syms (abfd
) != NULL
)
1753 bfd_free_window (&obj_aout_sym_window (abfd
));
1755 free (obj_aout_external_syms (abfd
));
1757 obj_aout_external_syms (abfd
) = NULL
;
1763 /* We use a hash table when writing out symbols so that we only write
1764 out a particular string once. This helps particularly when the
1765 linker writes out stabs debugging entries, because each different
1766 contributing object file tends to have many duplicate stabs
1769 This hash table code breaks dbx on SunOS 4.1.3, so we don't do it
1770 if BFD_TRADITIONAL_FORMAT is set. */
1772 /* Get the index of a string in a strtab, adding it if it is not
1775 static inline bfd_size_type
1776 add_to_stringtab (bfd
*abfd
,
1777 struct bfd_strtab_hash
*tab
,
1782 bfd_size_type index
;
1784 /* An index of 0 always means the empty string. */
1785 if (str
== 0 || *str
== '\0')
1788 /* Don't hash if BFD_TRADITIONAL_FORMAT is set, because SunOS dbx
1789 doesn't understand a hashed string table. */
1791 if ((abfd
->flags
& BFD_TRADITIONAL_FORMAT
) != 0)
1794 index
= _bfd_stringtab_add (tab
, str
, hash
, copy
);
1796 if (index
!= (bfd_size_type
) -1)
1797 /* Add BYTES_IN_WORD to the return value to account for the
1798 space taken up by the string table size. */
1799 index
+= BYTES_IN_WORD
;
1804 /* Write out a strtab. ABFD is already at the right location in the
1808 emit_stringtab (bfd
*abfd
, struct bfd_strtab_hash
*tab
)
1810 bfd_byte buffer
[BYTES_IN_WORD
];
1811 bfd_size_type amt
= BYTES_IN_WORD
;
1813 /* The string table starts with the size. */
1814 PUT_WORD (abfd
, _bfd_stringtab_size (tab
) + BYTES_IN_WORD
, buffer
);
1815 if (bfd_bwrite ((void *) buffer
, amt
, abfd
) != amt
)
1818 return _bfd_stringtab_emit (abfd
, tab
);
1822 NAME (aout
, write_syms
) (bfd
*abfd
)
1824 unsigned int count
;
1825 asymbol
**generic
= bfd_get_outsymbols (abfd
);
1826 struct bfd_strtab_hash
*strtab
;
1828 strtab
= _bfd_stringtab_init ();
1832 for (count
= 0; count
< bfd_get_symcount (abfd
); count
++)
1834 asymbol
*g
= generic
[count
];
1836 struct external_nlist nsp
;
1839 indx
= add_to_stringtab (abfd
, strtab
, g
->name
, FALSE
);
1840 if (indx
== (bfd_size_type
) -1)
1842 PUT_WORD (abfd
, indx
, (bfd_byte
*) nsp
.e_strx
);
1844 if (bfd_asymbol_flavour (g
) == abfd
->xvec
->flavour
)
1846 H_PUT_16 (abfd
, aout_symbol (g
)->desc
, nsp
.e_desc
);
1847 H_PUT_8 (abfd
, aout_symbol (g
)->other
, nsp
.e_other
);
1848 H_PUT_8 (abfd
, aout_symbol (g
)->type
, nsp
.e_type
);
1852 H_PUT_16 (abfd
, 0, nsp
.e_desc
);
1853 H_PUT_8 (abfd
, 0, nsp
.e_other
);
1854 H_PUT_8 (abfd
, 0, nsp
.e_type
);
1857 if (! translate_to_native_sym_flags (abfd
, g
, &nsp
))
1860 amt
= EXTERNAL_NLIST_SIZE
;
1861 if (bfd_bwrite ((void *) &nsp
, amt
, abfd
) != amt
)
1864 /* NB: `KEEPIT' currently overlays `udata.p', so set this only
1865 here, at the end. */
1869 if (! emit_stringtab (abfd
, strtab
))
1872 _bfd_stringtab_free (strtab
);
1877 _bfd_stringtab_free (strtab
);
1882 NAME (aout
, canonicalize_symtab
) (bfd
*abfd
, asymbol
**location
)
1884 unsigned int counter
= 0;
1885 aout_symbol_type
*symbase
;
1887 if (!NAME (aout
, slurp_symbol_table
) (abfd
))
1890 for (symbase
= obj_aout_symbols (abfd
);
1891 counter
++ < bfd_get_symcount (abfd
);
1893 *(location
++) = (asymbol
*) (symbase
++);
1895 return bfd_get_symcount (abfd
);
1898 /* Standard reloc stuff. */
1899 /* Output standard relocation information to a file in target byte order. */
1901 extern void NAME (aout
, swap_std_reloc_out
)
1902 (bfd
*, arelent
*, struct reloc_std_external
*);
1905 NAME (aout
, swap_std_reloc_out
) (bfd
*abfd
,
1907 struct reloc_std_external
*natptr
)
1910 asymbol
*sym
= *(g
->sym_ptr_ptr
);
1912 unsigned int r_length
;
1914 int r_baserel
, r_jmptable
, r_relative
;
1915 asection
*output_section
= sym
->section
->output_section
;
1917 PUT_WORD (abfd
, g
->address
, natptr
->r_address
);
1919 r_length
= g
->howto
->size
; /* Size as a power of two. */
1920 r_pcrel
= (int) g
->howto
->pc_relative
; /* Relative to PC? */
1921 /* XXX This relies on relocs coming from a.out files. */
1922 r_baserel
= (g
->howto
->type
& 8) != 0;
1923 r_jmptable
= (g
->howto
->type
& 16) != 0;
1924 r_relative
= (g
->howto
->type
& 32) != 0;
1926 /* Name was clobbered by aout_write_syms to be symbol index. */
1928 /* If this relocation is relative to a symbol then set the
1929 r_index to the symbols index, and the r_extern bit.
1931 Absolute symbols can come in in two ways, either as an offset
1932 from the abs section, or as a symbol which has an abs value.
1933 check for that here. */
1935 if (bfd_is_com_section (output_section
)
1936 || bfd_is_abs_section (output_section
)
1937 || bfd_is_und_section (output_section
))
1939 if (bfd_abs_section_ptr
->symbol
== sym
)
1941 /* Whoops, looked like an abs symbol, but is
1942 really an offset from the abs section. */
1948 /* Fill in symbol. */
1950 r_index
= (*(g
->sym_ptr_ptr
))->KEEPIT
;
1955 /* Just an ordinary section. */
1957 r_index
= output_section
->target_index
;
1960 /* Now the fun stuff. */
1961 if (bfd_header_big_endian (abfd
))
1963 natptr
->r_index
[0] = r_index
>> 16;
1964 natptr
->r_index
[1] = r_index
>> 8;
1965 natptr
->r_index
[2] = r_index
;
1966 natptr
->r_type
[0] = ((r_extern
? RELOC_STD_BITS_EXTERN_BIG
: 0)
1967 | (r_pcrel
? RELOC_STD_BITS_PCREL_BIG
: 0)
1968 | (r_baserel
? RELOC_STD_BITS_BASEREL_BIG
: 0)
1969 | (r_jmptable
? RELOC_STD_BITS_JMPTABLE_BIG
: 0)
1970 | (r_relative
? RELOC_STD_BITS_RELATIVE_BIG
: 0)
1971 | (r_length
<< RELOC_STD_BITS_LENGTH_SH_BIG
));
1975 natptr
->r_index
[2] = r_index
>> 16;
1976 natptr
->r_index
[1] = r_index
>> 8;
1977 natptr
->r_index
[0] = r_index
;
1978 natptr
->r_type
[0] = ((r_extern
? RELOC_STD_BITS_EXTERN_LITTLE
: 0)
1979 | (r_pcrel
? RELOC_STD_BITS_PCREL_LITTLE
: 0)
1980 | (r_baserel
? RELOC_STD_BITS_BASEREL_LITTLE
: 0)
1981 | (r_jmptable
? RELOC_STD_BITS_JMPTABLE_LITTLE
: 0)
1982 | (r_relative
? RELOC_STD_BITS_RELATIVE_LITTLE
: 0)
1983 | (r_length
<< RELOC_STD_BITS_LENGTH_SH_LITTLE
));
1987 /* Extended stuff. */
1988 /* Output extended relocation information to a file in target byte order. */
1990 extern void NAME (aout
, swap_ext_reloc_out
)
1991 (bfd
*, arelent
*, struct reloc_ext_external
*);
1994 NAME (aout
, swap_ext_reloc_out
) (bfd
*abfd
,
1996 struct reloc_ext_external
*natptr
)
2000 unsigned int r_type
;
2002 asymbol
*sym
= *(g
->sym_ptr_ptr
);
2003 asection
*output_section
= sym
->section
->output_section
;
2005 PUT_WORD (abfd
, g
->address
, natptr
->r_address
);
2007 r_type
= (unsigned int) g
->howto
->type
;
2009 r_addend
= g
->addend
;
2010 if ((sym
->flags
& BSF_SECTION_SYM
) != 0)
2011 r_addend
+= (*(g
->sym_ptr_ptr
))->section
->output_section
->vma
;
2013 /* If this relocation is relative to a symbol then set the
2014 r_index to the symbols index, and the r_extern bit.
2016 Absolute symbols can come in in two ways, either as an offset
2017 from the abs section, or as a symbol which has an abs value.
2018 check for that here. */
2019 if (bfd_is_abs_section (bfd_get_section (sym
)))
2024 else if ((sym
->flags
& BSF_SECTION_SYM
) == 0)
2026 if (bfd_is_und_section (bfd_get_section (sym
))
2027 || (sym
->flags
& BSF_GLOBAL
) != 0)
2031 r_index
= (*(g
->sym_ptr_ptr
))->KEEPIT
;
2035 /* Just an ordinary section. */
2037 r_index
= output_section
->target_index
;
2040 /* Now the fun stuff. */
2041 if (bfd_header_big_endian (abfd
))
2043 natptr
->r_index
[0] = r_index
>> 16;
2044 natptr
->r_index
[1] = r_index
>> 8;
2045 natptr
->r_index
[2] = r_index
;
2046 natptr
->r_type
[0] = ((r_extern
? RELOC_EXT_BITS_EXTERN_BIG
: 0)
2047 | (r_type
<< RELOC_EXT_BITS_TYPE_SH_BIG
));
2051 natptr
->r_index
[2] = r_index
>> 16;
2052 natptr
->r_index
[1] = r_index
>> 8;
2053 natptr
->r_index
[0] = r_index
;
2054 natptr
->r_type
[0] = ((r_extern
? RELOC_EXT_BITS_EXTERN_LITTLE
: 0)
2055 | (r_type
<< RELOC_EXT_BITS_TYPE_SH_LITTLE
));
2058 PUT_WORD (abfd
, r_addend
, natptr
->r_addend
);
2061 /* BFD deals internally with all things based from the section they're
2062 in. so, something in 10 bytes into a text section with a base of
2063 50 would have a symbol (.text+10) and know .text vma was 50.
2065 Aout keeps all it's symbols based from zero, so the symbol would
2066 contain 60. This macro subs the base of each section from the value
2067 to give the true offset from the section. */
2069 #define MOVE_ADDRESS(ad) \
2072 /* Undefined symbol. */ \
2073 cache_ptr->sym_ptr_ptr = symbols + r_index; \
2074 cache_ptr->addend = ad; \
2078 /* Defined, section relative. Replace symbol with pointer to \
2079 symbol which points to section. */ \
2083 case N_TEXT | N_EXT: \
2084 cache_ptr->sym_ptr_ptr = obj_textsec (abfd)->symbol_ptr_ptr; \
2085 cache_ptr->addend = ad - su->textsec->vma; \
2088 case N_DATA | N_EXT: \
2089 cache_ptr->sym_ptr_ptr = obj_datasec (abfd)->symbol_ptr_ptr; \
2090 cache_ptr->addend = ad - su->datasec->vma; \
2093 case N_BSS | N_EXT: \
2094 cache_ptr->sym_ptr_ptr = obj_bsssec (abfd)->symbol_ptr_ptr; \
2095 cache_ptr->addend = ad - su->bsssec->vma; \
2099 case N_ABS | N_EXT: \
2100 cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr; \
2101 cache_ptr->addend = ad; \
2107 NAME (aout
, swap_ext_reloc_in
) (bfd
*abfd
,
2108 struct reloc_ext_external
*bytes
,
2111 bfd_size_type symcount
)
2113 unsigned int r_index
;
2115 unsigned int r_type
;
2116 struct aoutdata
*su
= &(abfd
->tdata
.aout_data
->a
);
2118 cache_ptr
->address
= (GET_SWORD (abfd
, bytes
->r_address
));
2120 /* Now the fun stuff. */
2121 if (bfd_header_big_endian (abfd
))
2123 r_index
= (((unsigned int) bytes
->r_index
[0] << 16)
2124 | ((unsigned int) bytes
->r_index
[1] << 8)
2125 | bytes
->r_index
[2]);
2126 r_extern
= (0 != (bytes
->r_type
[0] & RELOC_EXT_BITS_EXTERN_BIG
));
2127 r_type
= ((bytes
->r_type
[0] & RELOC_EXT_BITS_TYPE_BIG
)
2128 >> RELOC_EXT_BITS_TYPE_SH_BIG
);
2132 r_index
= (((unsigned int) bytes
->r_index
[2] << 16)
2133 | ((unsigned int) bytes
->r_index
[1] << 8)
2134 | bytes
->r_index
[0]);
2135 r_extern
= (0 != (bytes
->r_type
[0] & RELOC_EXT_BITS_EXTERN_LITTLE
));
2136 r_type
= ((bytes
->r_type
[0] & RELOC_EXT_BITS_TYPE_LITTLE
)
2137 >> RELOC_EXT_BITS_TYPE_SH_LITTLE
);
2140 cache_ptr
->howto
= howto_table_ext
+ r_type
;
2142 /* Base relative relocs are always against the symbol table,
2143 regardless of the setting of r_extern. r_extern just reflects
2144 whether the symbol the reloc is against is local or global. */
2145 if (r_type
== (unsigned int) RELOC_BASE10
2146 || r_type
== (unsigned int) RELOC_BASE13
2147 || r_type
== (unsigned int) RELOC_BASE22
)
2150 if (r_extern
&& r_index
> symcount
)
2152 /* We could arrange to return an error, but it might be useful
2153 to see the file even if it is bad. */
2158 MOVE_ADDRESS (GET_SWORD (abfd
, bytes
->r_addend
));
2162 NAME (aout
, swap_std_reloc_in
) (bfd
*abfd
,
2163 struct reloc_std_external
*bytes
,
2166 bfd_size_type symcount
)
2168 unsigned int r_index
;
2170 unsigned int r_length
;
2172 int r_baserel
, r_jmptable
, r_relative
;
2173 struct aoutdata
*su
= &(abfd
->tdata
.aout_data
->a
);
2174 unsigned int howto_idx
;
2176 cache_ptr
->address
= H_GET_32 (abfd
, bytes
->r_address
);
2178 /* Now the fun stuff. */
2179 if (bfd_header_big_endian (abfd
))
2181 r_index
= (((unsigned int) bytes
->r_index
[0] << 16)
2182 | ((unsigned int) bytes
->r_index
[1] << 8)
2183 | bytes
->r_index
[2]);
2184 r_extern
= (0 != (bytes
->r_type
[0] & RELOC_STD_BITS_EXTERN_BIG
));
2185 r_pcrel
= (0 != (bytes
->r_type
[0] & RELOC_STD_BITS_PCREL_BIG
));
2186 r_baserel
= (0 != (bytes
->r_type
[0] & RELOC_STD_BITS_BASEREL_BIG
));
2187 r_jmptable
= (0 != (bytes
->r_type
[0] & RELOC_STD_BITS_JMPTABLE_BIG
));
2188 r_relative
= (0 != (bytes
->r_type
[0] & RELOC_STD_BITS_RELATIVE_BIG
));
2189 r_length
= ((bytes
->r_type
[0] & RELOC_STD_BITS_LENGTH_BIG
)
2190 >> RELOC_STD_BITS_LENGTH_SH_BIG
);
2194 r_index
= (((unsigned int) bytes
->r_index
[2] << 16)
2195 | ((unsigned int) bytes
->r_index
[1] << 8)
2196 | bytes
->r_index
[0]);
2197 r_extern
= (0 != (bytes
->r_type
[0] & RELOC_STD_BITS_EXTERN_LITTLE
));
2198 r_pcrel
= (0 != (bytes
->r_type
[0] & RELOC_STD_BITS_PCREL_LITTLE
));
2199 r_baserel
= (0 != (bytes
->r_type
[0] & RELOC_STD_BITS_BASEREL_LITTLE
));
2200 r_jmptable
= (0 != (bytes
->r_type
[0] & RELOC_STD_BITS_JMPTABLE_LITTLE
));
2201 r_relative
= (0 != (bytes
->r_type
[0] & RELOC_STD_BITS_RELATIVE_LITTLE
));
2202 r_length
= ((bytes
->r_type
[0] & RELOC_STD_BITS_LENGTH_LITTLE
)
2203 >> RELOC_STD_BITS_LENGTH_SH_LITTLE
);
2206 howto_idx
= (r_length
+ 4 * r_pcrel
+ 8 * r_baserel
2207 + 16 * r_jmptable
+ 32 * r_relative
);
2208 BFD_ASSERT (howto_idx
< TABLE_SIZE (howto_table_std
));
2209 cache_ptr
->howto
= howto_table_std
+ howto_idx
;
2210 BFD_ASSERT (cache_ptr
->howto
->type
!= (unsigned int) -1);
2212 /* Base relative relocs are always against the symbol table,
2213 regardless of the setting of r_extern. r_extern just reflects
2214 whether the symbol the reloc is against is local or global. */
2218 if (r_extern
&& r_index
> symcount
)
2220 /* We could arrange to return an error, but it might be useful
2221 to see the file even if it is bad. */
2229 /* Read and swap the relocs for a section. */
2232 NAME (aout
, slurp_reloc_table
) (bfd
*abfd
, sec_ptr asect
, asymbol
**symbols
)
2234 bfd_size_type count
;
2235 bfd_size_type reloc_size
;
2237 arelent
*reloc_cache
;
2239 unsigned int counter
= 0;
2243 if (asect
->relocation
)
2246 if (asect
->flags
& SEC_CONSTRUCTOR
)
2249 if (asect
== obj_datasec (abfd
))
2250 reloc_size
= exec_hdr (abfd
)->a_drsize
;
2251 else if (asect
== obj_textsec (abfd
))
2252 reloc_size
= exec_hdr (abfd
)->a_trsize
;
2253 else if (asect
== obj_bsssec (abfd
))
2257 bfd_set_error (bfd_error_invalid_operation
);
2261 if (bfd_seek (abfd
, asect
->rel_filepos
, SEEK_SET
) != 0)
2264 each_size
= obj_reloc_entry_size (abfd
);
2266 count
= reloc_size
/ each_size
;
2268 amt
= count
* sizeof (arelent
);
2269 reloc_cache
= bfd_zmalloc (amt
);
2270 if (reloc_cache
== NULL
&& count
!= 0)
2273 relocs
= bfd_malloc (reloc_size
);
2274 if (relocs
== NULL
&& reloc_size
!= 0)
2280 if (bfd_bread (relocs
, reloc_size
, abfd
) != reloc_size
)
2287 cache_ptr
= reloc_cache
;
2288 if (each_size
== RELOC_EXT_SIZE
)
2290 struct reloc_ext_external
*rptr
= (struct reloc_ext_external
*) relocs
;
2292 for (; counter
< count
; counter
++, rptr
++, cache_ptr
++)
2293 MY_swap_ext_reloc_in (abfd
, rptr
, cache_ptr
, symbols
,
2294 (bfd_size_type
) bfd_get_symcount (abfd
));
2298 struct reloc_std_external
*rptr
= (struct reloc_std_external
*) relocs
;
2300 for (; counter
< count
; counter
++, rptr
++, cache_ptr
++)
2301 MY_swap_std_reloc_in (abfd
, rptr
, cache_ptr
, symbols
,
2302 (bfd_size_type
) bfd_get_symcount (abfd
));
2307 asect
->relocation
= reloc_cache
;
2308 asect
->reloc_count
= cache_ptr
- reloc_cache
;
2313 /* Write out a relocation section into an object file. */
2316 NAME (aout
, squirt_out_relocs
) (bfd
*abfd
, asection
*section
)
2319 unsigned char *native
, *natptr
;
2322 unsigned int count
= section
->reloc_count
;
2323 bfd_size_type natsize
;
2325 if (count
== 0 || section
->orelocation
== NULL
)
2328 each_size
= obj_reloc_entry_size (abfd
);
2329 natsize
= (bfd_size_type
) each_size
* count
;
2330 native
= bfd_zalloc (abfd
, natsize
);
2334 generic
= section
->orelocation
;
2336 if (each_size
== RELOC_EXT_SIZE
)
2338 for (natptr
= native
;
2340 --count
, natptr
+= each_size
, ++generic
)
2341 MY_swap_ext_reloc_out (abfd
, *generic
,
2342 (struct reloc_ext_external
*) natptr
);
2346 for (natptr
= native
;
2348 --count
, natptr
+= each_size
, ++generic
)
2349 MY_swap_std_reloc_out (abfd
, *generic
,
2350 (struct reloc_std_external
*) natptr
);
2353 if (bfd_bwrite ((void *) native
, natsize
, abfd
) != natsize
)
2355 bfd_release (abfd
, native
);
2358 bfd_release (abfd
, native
);
2363 /* This is stupid. This function should be a boolean predicate. */
2366 NAME (aout
, canonicalize_reloc
) (bfd
*abfd
,
2371 arelent
*tblptr
= section
->relocation
;
2374 if (section
== obj_bsssec (abfd
))
2380 if (!(tblptr
|| NAME (aout
, slurp_reloc_table
) (abfd
, section
, symbols
)))
2383 if (section
->flags
& SEC_CONSTRUCTOR
)
2385 arelent_chain
*chain
= section
->constructor_chain
;
2386 for (count
= 0; count
< section
->reloc_count
; count
++)
2388 *relptr
++ = &chain
->relent
;
2389 chain
= chain
->next
;
2394 tblptr
= section
->relocation
;
2396 for (count
= 0; count
++ < section
->reloc_count
; )
2398 *relptr
++ = tblptr
++;
2403 return section
->reloc_count
;
2407 NAME (aout
, get_reloc_upper_bound
) (bfd
*abfd
, sec_ptr asect
)
2409 if (bfd_get_format (abfd
) != bfd_object
)
2411 bfd_set_error (bfd_error_invalid_operation
);
2415 if (asect
->flags
& SEC_CONSTRUCTOR
)
2416 return sizeof (arelent
*) * (asect
->reloc_count
+ 1);
2418 if (asect
== obj_datasec (abfd
))
2419 return sizeof (arelent
*)
2420 * ((exec_hdr (abfd
)->a_drsize
/ obj_reloc_entry_size (abfd
))
2423 if (asect
== obj_textsec (abfd
))
2424 return sizeof (arelent
*)
2425 * ((exec_hdr (abfd
)->a_trsize
/ obj_reloc_entry_size (abfd
))
2428 if (asect
== obj_bsssec (abfd
))
2429 return sizeof (arelent
*);
2431 if (asect
== obj_bsssec (abfd
))
2434 bfd_set_error (bfd_error_invalid_operation
);
2439 NAME (aout
, get_symtab_upper_bound
) (bfd
*abfd
)
2441 if (!NAME (aout
, slurp_symbol_table
) (abfd
))
2444 return (bfd_get_symcount (abfd
)+1) * (sizeof (aout_symbol_type
*));
2448 NAME (aout
, get_lineno
) (bfd
*ignore_abfd ATTRIBUTE_UNUSED
,
2449 asymbol
*ignore_symbol ATTRIBUTE_UNUSED
)
2455 NAME (aout
, get_symbol_info
) (bfd
*ignore_abfd ATTRIBUTE_UNUSED
,
2459 bfd_symbol_info (symbol
, ret
);
2461 if (ret
->type
== '?')
2463 int type_code
= aout_symbol (symbol
)->type
& 0xff;
2464 const char *stab_name
= bfd_get_stab_name (type_code
);
2465 static char buf
[10];
2467 if (stab_name
== NULL
)
2469 sprintf (buf
, "(%d)", type_code
);
2473 ret
->stab_type
= type_code
;
2474 ret
->stab_other
= (unsigned) (aout_symbol (symbol
)->other
& 0xff);
2475 ret
->stab_desc
= (unsigned) (aout_symbol (symbol
)->desc
& 0xffff);
2476 ret
->stab_name
= stab_name
;
2481 NAME (aout
, print_symbol
) (bfd
*abfd
,
2484 bfd_print_symbol_type how
)
2486 FILE *file
= (FILE *)afile
;
2490 case bfd_print_symbol_name
:
2492 fprintf (file
,"%s", symbol
->name
);
2494 case bfd_print_symbol_more
:
2495 fprintf (file
,"%4x %2x %2x",
2496 (unsigned) (aout_symbol (symbol
)->desc
& 0xffff),
2497 (unsigned) (aout_symbol (symbol
)->other
& 0xff),
2498 (unsigned) (aout_symbol (symbol
)->type
));
2500 case bfd_print_symbol_all
:
2502 const char *section_name
= symbol
->section
->name
;
2504 bfd_print_symbol_vandf (abfd
, (void *)file
, symbol
);
2506 fprintf (file
," %-5s %04x %02x %02x",
2508 (unsigned) (aout_symbol (symbol
)->desc
& 0xffff),
2509 (unsigned) (aout_symbol (symbol
)->other
& 0xff),
2510 (unsigned) (aout_symbol (symbol
)->type
& 0xff));
2512 fprintf (file
," %s", symbol
->name
);
2518 /* If we don't have to allocate more than 1MB to hold the generic
2519 symbols, we use the generic minisymbol methord: it's faster, since
2520 it only translates the symbols once, not multiple times. */
2521 #define MINISYM_THRESHOLD (1000000 / sizeof (asymbol))
2523 /* Read minisymbols. For minisymbols, we use the unmodified a.out
2524 symbols. The minisymbol_to_symbol function translates these into
2525 BFD asymbol structures. */
2528 NAME (aout
, read_minisymbols
) (bfd
*abfd
,
2529 bfd_boolean dynamic
,
2531 unsigned int *sizep
)
2534 /* We could handle the dynamic symbols here as well, but it's
2535 easier to hand them off. */
2536 return _bfd_generic_read_minisymbols (abfd
, dynamic
, minisymsp
, sizep
);
2538 if (! aout_get_external_symbols (abfd
))
2541 if (obj_aout_external_sym_count (abfd
) < MINISYM_THRESHOLD
)
2542 return _bfd_generic_read_minisymbols (abfd
, dynamic
, minisymsp
, sizep
);
2544 *minisymsp
= (void *) obj_aout_external_syms (abfd
);
2546 /* By passing the external symbols back from this routine, we are
2547 giving up control over the memory block. Clear
2548 obj_aout_external_syms, so that we do not try to free it
2550 obj_aout_external_syms (abfd
) = NULL
;
2552 *sizep
= EXTERNAL_NLIST_SIZE
;
2553 return obj_aout_external_sym_count (abfd
);
2556 /* Convert a minisymbol to a BFD asymbol. A minisymbol is just an
2557 unmodified a.out symbol. The SYM argument is a structure returned
2558 by bfd_make_empty_symbol, which we fill in here. */
2561 NAME (aout
, minisymbol_to_symbol
) (bfd
*abfd
,
2562 bfd_boolean dynamic
,
2563 const void * minisym
,
2567 || obj_aout_external_sym_count (abfd
) < MINISYM_THRESHOLD
)
2568 return _bfd_generic_minisymbol_to_symbol (abfd
, dynamic
, minisym
, sym
);
2570 memset (sym
, 0, sizeof (aout_symbol_type
));
2572 /* We call translate_symbol_table to translate a single symbol. */
2573 if (! (NAME (aout
, translate_symbol_table
)
2575 (aout_symbol_type
*) sym
,
2576 (struct external_nlist
*) minisym
,
2578 obj_aout_external_strings (abfd
),
2579 obj_aout_external_string_size (abfd
),
2586 /* Provided a BFD, a section and an offset into the section, calculate
2587 and return the name of the source file and the line nearest to the
2591 NAME (aout
, find_nearest_line
) (bfd
*abfd
,
2595 const char **filename_ptr
,
2596 const char **functionname_ptr
,
2597 unsigned int *line_ptr
)
2599 /* Run down the file looking for the filename, function and linenumber. */
2601 const char *directory_name
= NULL
;
2602 const char *main_file_name
= NULL
;
2603 const char *current_file_name
= NULL
;
2604 const char *line_file_name
= NULL
; /* Value of current_file_name at line number. */
2605 const char *line_directory_name
= NULL
; /* Value of directory_name at line number. */
2606 bfd_vma low_line_vma
= 0;
2607 bfd_vma low_func_vma
= 0;
2609 bfd_size_type filelen
, funclen
;
2612 *filename_ptr
= abfd
->filename
;
2613 *functionname_ptr
= 0;
2616 if (symbols
!= NULL
)
2618 for (p
= symbols
; *p
; p
++)
2620 aout_symbol_type
*q
= (aout_symbol_type
*) (*p
);
2625 /* If this looks like a file name symbol, and it comes after
2626 the line number we have found so far, but before the
2627 offset, then we have probably not found the right line
2629 if (q
->symbol
.value
<= offset
2630 && ((q
->symbol
.value
> low_line_vma
2631 && (line_file_name
!= NULL
2633 || (q
->symbol
.value
> low_func_vma
2636 const char *symname
;
2638 symname
= q
->symbol
.name
;
2639 if (strcmp (symname
+ strlen (symname
) - 2, ".o") == 0)
2641 if (q
->symbol
.value
> low_line_vma
)
2644 line_file_name
= NULL
;
2646 if (q
->symbol
.value
> low_func_vma
)
2653 /* If this symbol is less than the offset, but greater than
2654 the line number we have found so far, then we have not
2655 found the right line number. */
2656 if (q
->symbol
.value
<= offset
)
2658 if (q
->symbol
.value
> low_line_vma
)
2661 line_file_name
= NULL
;
2663 if (q
->symbol
.value
> low_func_vma
)
2667 main_file_name
= current_file_name
= q
->symbol
.name
;
2668 /* Look ahead to next symbol to check if that too is an N_SO. */
2672 q
= (aout_symbol_type
*) (*p
);
2673 if (q
->type
!= (int)N_SO
)
2676 /* Found a second N_SO First is directory; second is filename. */
2677 directory_name
= current_file_name
;
2678 main_file_name
= current_file_name
= q
->symbol
.name
;
2679 if (obj_textsec (abfd
) != section
)
2683 current_file_name
= q
->symbol
.name
;
2690 /* We'll keep this if it resolves nearer than the one we have
2692 if (q
->symbol
.value
>= low_line_vma
2693 && q
->symbol
.value
<= offset
)
2695 *line_ptr
= q
->desc
;
2696 low_line_vma
= q
->symbol
.value
;
2697 line_file_name
= current_file_name
;
2698 line_directory_name
= directory_name
;
2703 /* We'll keep this if it is nearer than the one we have already. */
2704 if (q
->symbol
.value
>= low_func_vma
&&
2705 q
->symbol
.value
<= offset
)
2707 low_func_vma
= q
->symbol
.value
;
2708 func
= (asymbol
*)q
;
2710 else if (q
->symbol
.value
> offset
)
2721 main_file_name
= line_file_name
;
2722 directory_name
= line_directory_name
;
2725 if (main_file_name
== NULL
2726 || IS_ABSOLUTE_PATH (main_file_name
)
2727 || directory_name
== NULL
)
2730 filelen
= strlen (directory_name
) + strlen (main_file_name
);
2735 funclen
= strlen (bfd_asymbol_name (func
));
2737 if (adata (abfd
).line_buf
!= NULL
)
2738 free (adata (abfd
).line_buf
);
2740 if (filelen
+ funclen
== 0)
2741 adata (abfd
).line_buf
= buf
= NULL
;
2744 buf
= bfd_malloc (filelen
+ funclen
+ 3);
2745 adata (abfd
).line_buf
= buf
;
2750 if (main_file_name
!= NULL
)
2752 if (IS_ABSOLUTE_PATH (main_file_name
) || directory_name
== NULL
)
2753 *filename_ptr
= main_file_name
;
2756 sprintf (buf
, "%s%s", directory_name
, main_file_name
);
2757 *filename_ptr
= buf
;
2764 const char *function
= func
->name
;
2767 /* The caller expects a symbol name. We actually have a
2768 function name, without the leading underscore. Put the
2769 underscore back in, so that the caller gets a symbol name. */
2770 if (bfd_get_symbol_leading_char (abfd
) == '\0')
2771 strcpy (buf
, function
);
2774 buf
[0] = bfd_get_symbol_leading_char (abfd
);
2775 strcpy (buf
+ 1, function
);
2777 /* Have to remove : stuff. */
2778 colon
= strchr (buf
, ':');
2781 *functionname_ptr
= buf
;
2788 NAME (aout
, sizeof_headers
) (bfd
*abfd
, bfd_boolean execable ATTRIBUTE_UNUSED
)
2790 return adata (abfd
).exec_bytes_size
;
2793 /* Free all information we have cached for this BFD. We can always
2794 read it again later if we need it. */
2797 NAME (aout
, bfd_free_cached_info
) (bfd
*abfd
)
2801 if (bfd_get_format (abfd
) != bfd_object
2802 || abfd
->tdata
.aout_data
== NULL
)
2805 #define BFCI_FREE(x) if (x != NULL) { free (x); x = NULL; }
2806 BFCI_FREE (obj_aout_symbols (abfd
));
2808 obj_aout_external_syms (abfd
) = 0;
2809 bfd_free_window (&obj_aout_sym_window (abfd
));
2810 bfd_free_window (&obj_aout_string_window (abfd
));
2811 obj_aout_external_strings (abfd
) = 0;
2813 BFCI_FREE (obj_aout_external_syms (abfd
));
2814 BFCI_FREE (obj_aout_external_strings (abfd
));
2816 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
2817 BFCI_FREE (o
->relocation
);
2823 /* a.out link code. */
2825 /* Routine to create an entry in an a.out link hash table. */
2827 struct bfd_hash_entry
*
2828 NAME (aout
, link_hash_newfunc
) (struct bfd_hash_entry
*entry
,
2829 struct bfd_hash_table
*table
,
2832 struct aout_link_hash_entry
*ret
= (struct aout_link_hash_entry
*) entry
;
2834 /* Allocate the structure if it has not already been allocated by a
2837 ret
= bfd_hash_allocate (table
, sizeof (* ret
));
2841 /* Call the allocation method of the superclass. */
2842 ret
= ((struct aout_link_hash_entry
*)
2843 _bfd_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
2847 /* Set local fields. */
2848 ret
->written
= FALSE
;
2852 return (struct bfd_hash_entry
*) ret
;
2855 /* Initialize an a.out link hash table. */
2858 NAME (aout
, link_hash_table_init
) (struct aout_link_hash_table
*table
,
2860 struct bfd_hash_entry
*(*newfunc
)
2861 (struct bfd_hash_entry
*, struct bfd_hash_table
*,
2864 return _bfd_link_hash_table_init (&table
->root
, abfd
, newfunc
);
2867 /* Create an a.out link hash table. */
2869 struct bfd_link_hash_table
*
2870 NAME (aout
, link_hash_table_create
) (bfd
*abfd
)
2872 struct aout_link_hash_table
*ret
;
2873 bfd_size_type amt
= sizeof (* ret
);
2875 ret
= bfd_malloc (amt
);
2879 if (! NAME (aout
, link_hash_table_init
) (ret
, abfd
,
2880 NAME (aout
, link_hash_newfunc
)))
2888 /* Add all symbols from an object file to the hash table. */
2891 aout_link_add_symbols (bfd
*abfd
, struct bfd_link_info
*info
)
2893 bfd_boolean (*add_one_symbol
)
2894 (struct bfd_link_info
*, bfd
*, const char *, flagword
, asection
*,
2895 bfd_vma
, const char *, bfd_boolean
, bfd_boolean
,
2896 struct bfd_link_hash_entry
**);
2897 struct external_nlist
*syms
;
2898 bfd_size_type sym_count
;
2901 struct aout_link_hash_entry
**sym_hash
;
2902 struct external_nlist
*p
;
2903 struct external_nlist
*pend
;
2906 syms
= obj_aout_external_syms (abfd
);
2907 sym_count
= obj_aout_external_sym_count (abfd
);
2908 strings
= obj_aout_external_strings (abfd
);
2909 if (info
->keep_memory
)
2914 if (aout_backend_info (abfd
)->add_dynamic_symbols
!= NULL
)
2916 if (! ((*aout_backend_info (abfd
)->add_dynamic_symbols
)
2917 (abfd
, info
, &syms
, &sym_count
, &strings
)))
2921 /* We keep a list of the linker hash table entries that correspond
2922 to particular symbols. We could just look them up in the hash
2923 table, but keeping the list is more efficient. Perhaps this
2924 should be conditional on info->keep_memory. */
2925 amt
= sym_count
* sizeof (struct aout_link_hash_entry
*);
2926 sym_hash
= bfd_alloc (abfd
, amt
);
2927 if (sym_hash
== NULL
&& sym_count
!= 0)
2929 obj_aout_sym_hashes (abfd
) = sym_hash
;
2931 add_one_symbol
= aout_backend_info (abfd
)->add_one_symbol
;
2932 if (add_one_symbol
== NULL
)
2933 add_one_symbol
= _bfd_generic_link_add_one_symbol
;
2936 pend
= p
+ sym_count
;
2937 for (; p
< pend
; p
++, sym_hash
++)
2948 type
= H_GET_8 (abfd
, p
->e_type
);
2950 /* Ignore debugging symbols. */
2951 if ((type
& N_STAB
) != 0)
2954 name
= strings
+ GET_WORD (abfd
, p
->e_strx
);
2955 value
= GET_WORD (abfd
, p
->e_value
);
2972 /* Ignore symbols that are not externally visible. */
2975 /* Ignore local indirect symbol. */
2980 case N_UNDF
| N_EXT
:
2983 section
= bfd_und_section_ptr
;
2987 section
= bfd_com_section_ptr
;
2990 section
= bfd_abs_section_ptr
;
2992 case N_TEXT
| N_EXT
:
2993 section
= obj_textsec (abfd
);
2994 value
-= bfd_get_section_vma (abfd
, section
);
2996 case N_DATA
| N_EXT
:
2997 case N_SETV
| N_EXT
:
2998 /* Treat N_SETV symbols as N_DATA symbol; see comment in
2999 translate_from_native_sym_flags. */
3000 section
= obj_datasec (abfd
);
3001 value
-= bfd_get_section_vma (abfd
, section
);
3004 section
= obj_bsssec (abfd
);
3005 value
-= bfd_get_section_vma (abfd
, section
);
3007 case N_INDR
| N_EXT
:
3008 /* An indirect symbol. The next symbol is the symbol
3009 which this one really is. */
3010 BFD_ASSERT (p
+ 1 < pend
);
3012 string
= strings
+ GET_WORD (abfd
, p
->e_strx
);
3013 section
= bfd_ind_section_ptr
;
3014 flags
|= BSF_INDIRECT
;
3016 case N_COMM
| N_EXT
:
3017 section
= bfd_com_section_ptr
;
3019 case N_SETA
: case N_SETA
| N_EXT
:
3020 section
= bfd_abs_section_ptr
;
3021 flags
|= BSF_CONSTRUCTOR
;
3023 case N_SETT
: case N_SETT
| N_EXT
:
3024 section
= obj_textsec (abfd
);
3025 flags
|= BSF_CONSTRUCTOR
;
3026 value
-= bfd_get_section_vma (abfd
, section
);
3028 case N_SETD
: case N_SETD
| N_EXT
:
3029 section
= obj_datasec (abfd
);
3030 flags
|= BSF_CONSTRUCTOR
;
3031 value
-= bfd_get_section_vma (abfd
, section
);
3033 case N_SETB
: case N_SETB
| N_EXT
:
3034 section
= obj_bsssec (abfd
);
3035 flags
|= BSF_CONSTRUCTOR
;
3036 value
-= bfd_get_section_vma (abfd
, section
);
3039 /* A warning symbol. The next symbol is the one to warn
3040 about. If there is no next symbol, just look away. */
3045 name
= strings
+ GET_WORD (abfd
, p
->e_strx
);
3046 section
= bfd_und_section_ptr
;
3047 flags
|= BSF_WARNING
;
3050 section
= bfd_und_section_ptr
;
3054 section
= bfd_abs_section_ptr
;
3058 section
= obj_textsec (abfd
);
3059 value
-= bfd_get_section_vma (abfd
, section
);
3063 section
= obj_datasec (abfd
);
3064 value
-= bfd_get_section_vma (abfd
, section
);
3068 section
= obj_bsssec (abfd
);
3069 value
-= bfd_get_section_vma (abfd
, section
);
3074 if (! ((*add_one_symbol
)
3075 (info
, abfd
, name
, flags
, section
, value
, string
, copy
, FALSE
,
3076 (struct bfd_link_hash_entry
**) sym_hash
)))
3079 /* Restrict the maximum alignment of a common symbol based on
3080 the architecture, since a.out has no way to represent
3081 alignment requirements of a section in a .o file. FIXME:
3082 This isn't quite right: it should use the architecture of the
3083 output file, not the input files. */
3084 if ((*sym_hash
)->root
.type
== bfd_link_hash_common
3085 && ((*sym_hash
)->root
.u
.c
.p
->alignment_power
>
3086 bfd_get_arch_info (abfd
)->section_align_power
))
3087 (*sym_hash
)->root
.u
.c
.p
->alignment_power
=
3088 bfd_get_arch_info (abfd
)->section_align_power
;
3090 /* If this is a set symbol, and we are not building sets, then
3091 it is possible for the hash entry to not have been set. In
3092 such a case, treat the symbol as not globally defined. */
3093 if ((*sym_hash
)->root
.type
== bfd_link_hash_new
)
3095 BFD_ASSERT ((flags
& BSF_CONSTRUCTOR
) != 0);
3099 if (type
== (N_INDR
| N_EXT
) || type
== N_WARNING
)
3106 /* Free up the internal symbols read from an a.out file. */
3109 aout_link_free_symbols (bfd
*abfd
)
3111 if (obj_aout_external_syms (abfd
) != NULL
)
3114 bfd_free_window (&obj_aout_sym_window (abfd
));
3116 free ((void *) obj_aout_external_syms (abfd
));
3118 obj_aout_external_syms (abfd
) = NULL
;
3120 if (obj_aout_external_strings (abfd
) != NULL
)
3123 bfd_free_window (&obj_aout_string_window (abfd
));
3125 free ((void *) obj_aout_external_strings (abfd
));
3127 obj_aout_external_strings (abfd
) = NULL
;
3132 /* Add symbols from an a.out object file. */
3135 aout_link_add_object_symbols (bfd
*abfd
, struct bfd_link_info
*info
)
3137 if (! aout_get_external_symbols (abfd
))
3139 if (! aout_link_add_symbols (abfd
, info
))
3141 if (! info
->keep_memory
)
3143 if (! aout_link_free_symbols (abfd
))
3149 /* Look through the internal symbols to see if this object file should
3150 be included in the link. We should include this object file if it
3151 defines any symbols which are currently undefined. If this object
3152 file defines a common symbol, then we may adjust the size of the
3153 known symbol but we do not include the object file in the link
3154 (unless there is some other reason to include it). */
3157 aout_link_check_ar_symbols (bfd
*abfd
,
3158 struct bfd_link_info
*info
,
3159 bfd_boolean
*pneeded
)
3161 struct external_nlist
*p
;
3162 struct external_nlist
*pend
;
3167 /* Look through all the symbols. */
3168 p
= obj_aout_external_syms (abfd
);
3169 pend
= p
+ obj_aout_external_sym_count (abfd
);
3170 strings
= obj_aout_external_strings (abfd
);
3171 for (; p
< pend
; p
++)
3173 int type
= H_GET_8 (abfd
, p
->e_type
);
3175 struct bfd_link_hash_entry
*h
;
3177 /* Ignore symbols that are not externally visible. This is an
3178 optimization only, as we check the type more thoroughly
3180 if (((type
& N_EXT
) == 0
3181 || (type
& N_STAB
) != 0
3188 if (type
== N_WARNING
3194 name
= strings
+ GET_WORD (abfd
, p
->e_strx
);
3195 h
= bfd_link_hash_lookup (info
->hash
, name
, FALSE
, FALSE
, TRUE
);
3197 /* We are only interested in symbols that are currently
3198 undefined or common. */
3200 || (h
->type
!= bfd_link_hash_undefined
3201 && h
->type
!= bfd_link_hash_common
))
3203 if (type
== (N_INDR
| N_EXT
))
3208 if (type
== (N_TEXT
| N_EXT
)
3209 || type
== (N_DATA
| N_EXT
)
3210 || type
== (N_BSS
| N_EXT
)
3211 || type
== (N_ABS
| N_EXT
)
3212 || type
== (N_INDR
| N_EXT
))
3214 /* This object file defines this symbol. We must link it
3215 in. This is true regardless of whether the current
3216 definition of the symbol is undefined or common.
3218 If the current definition is common, we have a case in
3219 which we have already seen an object file including:
3221 and this object file from the archive includes:
3223 In such a case, whether to include this object is target
3224 dependant for backward compatibility.
3226 FIXME: The SunOS 4.1.3 linker will pull in the archive
3227 element if the symbol is defined in the .data section,
3228 but not if it is defined in the .text section. That
3229 seems a bit crazy to me, and it has not been implemented
3230 yet. However, it might be correct. */
3231 if (h
->type
== bfd_link_hash_common
)
3235 switch (info
->common_skip_ar_aymbols
)
3237 case bfd_link_common_skip_text
:
3238 skip
= (type
== (N_TEXT
| N_EXT
));
3240 case bfd_link_common_skip_data
:
3241 skip
= (type
== (N_DATA
| N_EXT
));
3244 case bfd_link_common_skip_all
:
3253 if (! (*info
->callbacks
->add_archive_element
) (info
, abfd
, name
))
3259 if (type
== (N_UNDF
| N_EXT
))
3263 value
= GET_WORD (abfd
, p
->e_value
);
3266 /* This symbol is common in the object from the archive
3268 if (h
->type
== bfd_link_hash_undefined
)
3273 symbfd
= h
->u
.undef
.abfd
;
3276 /* This symbol was created as undefined from
3277 outside BFD. We assume that we should link
3278 in the object file. This is done for the -u
3279 option in the linker. */
3280 if (! (*info
->callbacks
->add_archive_element
) (info
,
3287 /* Turn the current link symbol into a common
3288 symbol. It is already on the undefs list. */
3289 h
->type
= bfd_link_hash_common
;
3290 h
->u
.c
.p
= bfd_hash_allocate (&info
->hash
->table
,
3291 sizeof (struct bfd_link_hash_common_entry
));
3292 if (h
->u
.c
.p
== NULL
)
3295 h
->u
.c
.size
= value
;
3297 /* FIXME: This isn't quite right. The maximum
3298 alignment of a common symbol should be set by the
3299 architecture of the output file, not of the input
3301 power
= bfd_log2 (value
);
3302 if (power
> bfd_get_arch_info (abfd
)->section_align_power
)
3303 power
= bfd_get_arch_info (abfd
)->section_align_power
;
3304 h
->u
.c
.p
->alignment_power
= power
;
3306 h
->u
.c
.p
->section
= bfd_make_section_old_way (symbfd
,
3311 /* Adjust the size of the common symbol if
3313 if (value
> h
->u
.c
.size
)
3314 h
->u
.c
.size
= value
;
3324 /* This symbol is weak but defined. We must pull it in if
3325 the current link symbol is undefined, but we don't want
3326 it if the current link symbol is common. */
3327 if (h
->type
== bfd_link_hash_undefined
)
3329 if (! (*info
->callbacks
->add_archive_element
) (info
, abfd
, name
))
3337 /* We do not need this object file. */
3340 /* Check a single archive element to see if we need to include it in
3341 the link. *PNEEDED is set according to whether this element is
3342 needed in the link or not. This is called from
3343 _bfd_generic_link_add_archive_symbols. */
3346 aout_link_check_archive_element (bfd
*abfd
,
3347 struct bfd_link_info
*info
,
3348 bfd_boolean
*pneeded
)
3350 if (! aout_get_external_symbols (abfd
))
3353 if (! aout_link_check_ar_symbols (abfd
, info
, pneeded
))
3358 if (! aout_link_add_symbols (abfd
, info
))
3362 if (! info
->keep_memory
|| ! *pneeded
)
3364 if (! aout_link_free_symbols (abfd
))
3371 /* Given an a.out BFD, add symbols to the global hash table as
3375 NAME (aout
, link_add_symbols
) (bfd
*abfd
, struct bfd_link_info
*info
)
3377 switch (bfd_get_format (abfd
))
3380 return aout_link_add_object_symbols (abfd
, info
);
3382 return _bfd_generic_link_add_archive_symbols
3383 (abfd
, info
, aout_link_check_archive_element
);
3385 bfd_set_error (bfd_error_wrong_format
);
3390 /* A hash table used for header files with N_BINCL entries. */
3392 struct aout_link_includes_table
3394 struct bfd_hash_table root
;
3397 /* A linked list of totals that we have found for a particular header
3400 struct aout_link_includes_totals
3402 struct aout_link_includes_totals
*next
;
3406 /* An entry in the header file hash table. */
3408 struct aout_link_includes_entry
3410 struct bfd_hash_entry root
;
3411 /* List of totals we have found for this file. */
3412 struct aout_link_includes_totals
*totals
;
3415 /* Look up an entry in an the header file hash table. */
3417 #define aout_link_includes_lookup(table, string, create, copy) \
3418 ((struct aout_link_includes_entry *) \
3419 bfd_hash_lookup (&(table)->root, (string), (create), (copy)))
3421 /* During the final link step we need to pass around a bunch of
3422 information, so we do it in an instance of this structure. */
3424 struct aout_final_link_info
3426 /* General link information. */
3427 struct bfd_link_info
*info
;
3430 /* Reloc file positions. */
3431 file_ptr treloff
, dreloff
;
3432 /* File position of symbols. */
3435 struct bfd_strtab_hash
*strtab
;
3436 /* Header file hash table. */
3437 struct aout_link_includes_table includes
;
3438 /* A buffer large enough to hold the contents of any section. */
3440 /* A buffer large enough to hold the relocs of any section. */
3442 /* A buffer large enough to hold the symbol map of any input BFD. */
3444 /* A buffer large enough to hold output symbols of any input BFD. */
3445 struct external_nlist
*output_syms
;
3448 /* The function to create a new entry in the header file hash table. */
3450 static struct bfd_hash_entry
*
3451 aout_link_includes_newfunc (struct bfd_hash_entry
*entry
,
3452 struct bfd_hash_table
*table
,
3455 struct aout_link_includes_entry
*ret
=
3456 (struct aout_link_includes_entry
*) entry
;
3458 /* Allocate the structure if it has not already been allocated by a
3461 ret
= bfd_hash_allocate (table
, sizeof (* ret
));
3465 /* Call the allocation method of the superclass. */
3466 ret
= ((struct aout_link_includes_entry
*)
3467 bfd_hash_newfunc ((struct bfd_hash_entry
*) ret
, table
, string
));
3470 /* Set local fields. */
3474 return (struct bfd_hash_entry
*) ret
;
3477 /* Write out a symbol that was not associated with an a.out input
3481 aout_link_write_other_symbol (struct aout_link_hash_entry
*h
, void * data
)
3483 struct aout_final_link_info
*finfo
= (struct aout_final_link_info
*) data
;
3487 struct external_nlist outsym
;
3491 if (h
->root
.type
== bfd_link_hash_warning
)
3493 h
= (struct aout_link_hash_entry
*) h
->root
.u
.i
.link
;
3494 if (h
->root
.type
== bfd_link_hash_new
)
3498 output_bfd
= finfo
->output_bfd
;
3500 if (aout_backend_info (output_bfd
)->write_dynamic_symbol
!= NULL
)
3502 if (! ((*aout_backend_info (output_bfd
)->write_dynamic_symbol
)
3503 (output_bfd
, finfo
->info
, h
)))
3505 /* FIXME: No way to handle errors. */
3515 /* An indx of -2 means the symbol must be written. */
3517 && (finfo
->info
->strip
== strip_all
3518 || (finfo
->info
->strip
== strip_some
3519 && bfd_hash_lookup (finfo
->info
->keep_hash
, h
->root
.root
.string
,
3520 FALSE
, FALSE
) == NULL
)))
3523 switch (h
->root
.type
)
3526 case bfd_link_hash_warning
:
3528 /* Avoid variable not initialized warnings. */
3530 case bfd_link_hash_new
:
3531 /* This can happen for set symbols when sets are not being
3534 case bfd_link_hash_undefined
:
3535 type
= N_UNDF
| N_EXT
;
3538 case bfd_link_hash_defined
:
3539 case bfd_link_hash_defweak
:
3543 sec
= h
->root
.u
.def
.section
->output_section
;
3544 BFD_ASSERT (bfd_is_abs_section (sec
)
3545 || sec
->owner
== output_bfd
);
3546 if (sec
== obj_textsec (output_bfd
))
3547 type
= h
->root
.type
== bfd_link_hash_defined
? N_TEXT
: N_WEAKT
;
3548 else if (sec
== obj_datasec (output_bfd
))
3549 type
= h
->root
.type
== bfd_link_hash_defined
? N_DATA
: N_WEAKD
;
3550 else if (sec
== obj_bsssec (output_bfd
))
3551 type
= h
->root
.type
== bfd_link_hash_defined
? N_BSS
: N_WEAKB
;
3553 type
= h
->root
.type
== bfd_link_hash_defined
? N_ABS
: N_WEAKA
;
3555 val
= (h
->root
.u
.def
.value
3557 + h
->root
.u
.def
.section
->output_offset
);
3560 case bfd_link_hash_common
:
3561 type
= N_UNDF
| N_EXT
;
3562 val
= h
->root
.u
.c
.size
;
3564 case bfd_link_hash_undefweak
:
3567 case bfd_link_hash_indirect
:
3568 /* We ignore these symbols, since the indirected symbol is
3569 already in the hash table. */
3573 H_PUT_8 (output_bfd
, type
, outsym
.e_type
);
3574 H_PUT_8 (output_bfd
, 0, outsym
.e_other
);
3575 H_PUT_16 (output_bfd
, 0, outsym
.e_desc
);
3576 indx
= add_to_stringtab (output_bfd
, finfo
->strtab
, h
->root
.root
.string
,
3578 if (indx
== - (bfd_size_type
) 1)
3579 /* FIXME: No way to handle errors. */
3582 PUT_WORD (output_bfd
, indx
, outsym
.e_strx
);
3583 PUT_WORD (output_bfd
, val
, outsym
.e_value
);
3585 amt
= EXTERNAL_NLIST_SIZE
;
3586 if (bfd_seek (output_bfd
, finfo
->symoff
, SEEK_SET
) != 0
3587 || bfd_bwrite ((void *) &outsym
, amt
, output_bfd
) != amt
)
3588 /* FIXME: No way to handle errors. */
3591 finfo
->symoff
+= EXTERNAL_NLIST_SIZE
;
3592 h
->indx
= obj_aout_external_sym_count (output_bfd
);
3593 ++obj_aout_external_sym_count (output_bfd
);
3598 /* Handle a link order which is supposed to generate a reloc. */
3601 aout_link_reloc_link_order (struct aout_final_link_info
*finfo
,
3603 struct bfd_link_order
*p
)
3605 struct bfd_link_order_reloc
*pr
;
3608 reloc_howto_type
*howto
;
3609 file_ptr
*reloff_ptr
= NULL
;
3610 struct reloc_std_external srel
;
3611 struct reloc_ext_external erel
;
3617 if (p
->type
== bfd_section_reloc_link_order
)
3620 if (bfd_is_abs_section (pr
->u
.section
))
3621 r_index
= N_ABS
| N_EXT
;
3624 BFD_ASSERT (pr
->u
.section
->owner
== finfo
->output_bfd
);
3625 r_index
= pr
->u
.section
->target_index
;
3630 struct aout_link_hash_entry
*h
;
3632 BFD_ASSERT (p
->type
== bfd_symbol_reloc_link_order
);
3634 h
= ((struct aout_link_hash_entry
*)
3635 bfd_wrapped_link_hash_lookup (finfo
->output_bfd
, finfo
->info
,
3636 pr
->u
.name
, FALSE
, FALSE
, TRUE
));
3642 /* We decided to strip this symbol, but it turns out that we
3643 can't. Note that we lose the other and desc information
3644 here. I don't think that will ever matter for a global
3648 if (! aout_link_write_other_symbol (h
, (void *) finfo
))
3654 if (! ((*finfo
->info
->callbacks
->unattached_reloc
)
3655 (finfo
->info
, pr
->u
.name
, NULL
, NULL
, (bfd_vma
) 0)))
3661 howto
= bfd_reloc_type_lookup (finfo
->output_bfd
, pr
->reloc
);
3664 bfd_set_error (bfd_error_bad_value
);
3668 if (o
== obj_textsec (finfo
->output_bfd
))
3669 reloff_ptr
= &finfo
->treloff
;
3670 else if (o
== obj_datasec (finfo
->output_bfd
))
3671 reloff_ptr
= &finfo
->dreloff
;
3675 if (obj_reloc_entry_size (finfo
->output_bfd
) == RELOC_STD_SIZE
)
3678 MY_put_reloc (finfo
->output_bfd
, r_extern
, r_index
, p
->offset
, howto
,
3688 r_pcrel
= (int) howto
->pc_relative
;
3689 r_baserel
= (howto
->type
& 8) != 0;
3690 r_jmptable
= (howto
->type
& 16) != 0;
3691 r_relative
= (howto
->type
& 32) != 0;
3692 r_length
= howto
->size
;
3694 PUT_WORD (finfo
->output_bfd
, p
->offset
, srel
.r_address
);
3695 if (bfd_header_big_endian (finfo
->output_bfd
))
3697 srel
.r_index
[0] = r_index
>> 16;
3698 srel
.r_index
[1] = r_index
>> 8;
3699 srel
.r_index
[2] = r_index
;
3701 ((r_extern
? RELOC_STD_BITS_EXTERN_BIG
: 0)
3702 | (r_pcrel
? RELOC_STD_BITS_PCREL_BIG
: 0)
3703 | (r_baserel
? RELOC_STD_BITS_BASEREL_BIG
: 0)
3704 | (r_jmptable
? RELOC_STD_BITS_JMPTABLE_BIG
: 0)
3705 | (r_relative
? RELOC_STD_BITS_RELATIVE_BIG
: 0)
3706 | (r_length
<< RELOC_STD_BITS_LENGTH_SH_BIG
));
3710 srel
.r_index
[2] = r_index
>> 16;
3711 srel
.r_index
[1] = r_index
>> 8;
3712 srel
.r_index
[0] = r_index
;
3714 ((r_extern
? RELOC_STD_BITS_EXTERN_LITTLE
: 0)
3715 | (r_pcrel
? RELOC_STD_BITS_PCREL_LITTLE
: 0)
3716 | (r_baserel
? RELOC_STD_BITS_BASEREL_LITTLE
: 0)
3717 | (r_jmptable
? RELOC_STD_BITS_JMPTABLE_LITTLE
: 0)
3718 | (r_relative
? RELOC_STD_BITS_RELATIVE_LITTLE
: 0)
3719 | (r_length
<< RELOC_STD_BITS_LENGTH_SH_LITTLE
));
3723 rel_ptr
= (void *) &srel
;
3725 /* We have to write the addend into the object file, since
3726 standard a.out relocs are in place. It would be more
3727 reliable if we had the current contents of the file here,
3728 rather than assuming zeroes, but we can't read the file since
3729 it was opened using bfd_openw. */
3730 if (pr
->addend
!= 0)
3733 bfd_reloc_status_type r
;
3737 size
= bfd_get_reloc_size (howto
);
3738 buf
= bfd_zmalloc (size
);
3741 r
= MY_relocate_contents (howto
, finfo
->output_bfd
,
3742 (bfd_vma
) pr
->addend
, buf
);
3748 case bfd_reloc_outofrange
:
3750 case bfd_reloc_overflow
:
3751 if (! ((*finfo
->info
->callbacks
->reloc_overflow
)
3753 (p
->type
== bfd_section_reloc_link_order
3754 ? bfd_section_name (finfo
->output_bfd
,
3757 howto
->name
, pr
->addend
, NULL
, NULL
, (bfd_vma
) 0)))
3764 ok
= bfd_set_section_contents (finfo
->output_bfd
, o
, (void *) buf
,
3765 (file_ptr
) p
->offset
, size
);
3773 #ifdef MY_put_ext_reloc
3774 MY_put_ext_reloc (finfo
->output_bfd
, r_extern
, r_index
, p
->offset
,
3775 howto
, &erel
, pr
->addend
);
3777 PUT_WORD (finfo
->output_bfd
, p
->offset
, erel
.r_address
);
3779 if (bfd_header_big_endian (finfo
->output_bfd
))
3781 erel
.r_index
[0] = r_index
>> 16;
3782 erel
.r_index
[1] = r_index
>> 8;
3783 erel
.r_index
[2] = r_index
;
3785 ((r_extern
? RELOC_EXT_BITS_EXTERN_BIG
: 0)
3786 | (howto
->type
<< RELOC_EXT_BITS_TYPE_SH_BIG
));
3790 erel
.r_index
[2] = r_index
>> 16;
3791 erel
.r_index
[1] = r_index
>> 8;
3792 erel
.r_index
[0] = r_index
;
3794 (r_extern
? RELOC_EXT_BITS_EXTERN_LITTLE
: 0)
3795 | (howto
->type
<< RELOC_EXT_BITS_TYPE_SH_LITTLE
);
3798 PUT_WORD (finfo
->output_bfd
, (bfd_vma
) pr
->addend
, erel
.r_addend
);
3799 #endif /* MY_put_ext_reloc */
3801 rel_ptr
= (void *) &erel
;
3804 amt
= obj_reloc_entry_size (finfo
->output_bfd
);
3805 if (bfd_seek (finfo
->output_bfd
, *reloff_ptr
, SEEK_SET
) != 0
3806 || bfd_bwrite (rel_ptr
, amt
, finfo
->output_bfd
) != amt
)
3809 *reloff_ptr
+= obj_reloc_entry_size (finfo
->output_bfd
);
3811 /* Assert that the relocs have not run into the symbols, and that n
3812 the text relocs have not run into the data relocs. */
3813 BFD_ASSERT (*reloff_ptr
<= obj_sym_filepos (finfo
->output_bfd
)
3814 && (reloff_ptr
!= &finfo
->treloff
3816 <= obj_datasec (finfo
->output_bfd
)->rel_filepos
)));
3821 /* Get the section corresponding to a reloc index. */
3823 static INLINE asection
*
3824 aout_reloc_index_to_section (bfd
*abfd
, int indx
)
3826 switch (indx
& N_TYPE
)
3828 case N_TEXT
: return obj_textsec (abfd
);
3829 case N_DATA
: return obj_datasec (abfd
);
3830 case N_BSS
: return obj_bsssec (abfd
);
3832 case N_UNDF
: return bfd_abs_section_ptr
;
3838 /* Relocate an a.out section using standard a.out relocs. */
3841 aout_link_input_section_std (struct aout_final_link_info
*finfo
,
3843 asection
*input_section
,
3844 struct reloc_std_external
*relocs
,
3845 bfd_size_type rel_size
,
3848 bfd_boolean (*check_dynamic_reloc
)
3849 (struct bfd_link_info
*, bfd
*, asection
*,
3850 struct aout_link_hash_entry
*, void *, bfd_byte
*, bfd_boolean
*,
3853 bfd_boolean relocatable
;
3854 struct external_nlist
*syms
;
3856 struct aout_link_hash_entry
**sym_hashes
;
3858 bfd_size_type reloc_count
;
3859 struct reloc_std_external
*rel
;
3860 struct reloc_std_external
*rel_end
;
3862 output_bfd
= finfo
->output_bfd
;
3863 check_dynamic_reloc
= aout_backend_info (output_bfd
)->check_dynamic_reloc
;
3865 BFD_ASSERT (obj_reloc_entry_size (input_bfd
) == RELOC_STD_SIZE
);
3866 BFD_ASSERT (input_bfd
->xvec
->header_byteorder
3867 == output_bfd
->xvec
->header_byteorder
);
3869 relocatable
= finfo
->info
->relocatable
;
3870 syms
= obj_aout_external_syms (input_bfd
);
3871 strings
= obj_aout_external_strings (input_bfd
);
3872 sym_hashes
= obj_aout_sym_hashes (input_bfd
);
3873 symbol_map
= finfo
->symbol_map
;
3875 reloc_count
= rel_size
/ RELOC_STD_SIZE
;
3877 rel_end
= rel
+ reloc_count
;
3878 for (; rel
< rel_end
; rel
++)
3885 reloc_howto_type
*howto
;
3886 struct aout_link_hash_entry
*h
= NULL
;
3888 bfd_reloc_status_type r
;
3890 r_addr
= GET_SWORD (input_bfd
, rel
->r_address
);
3892 #ifdef MY_reloc_howto
3893 howto
= MY_reloc_howto (input_bfd
, rel
, r_index
, r_extern
, r_pcrel
);
3899 unsigned int howto_idx
;
3901 if (bfd_header_big_endian (input_bfd
))
3903 r_index
= (((unsigned int) rel
->r_index
[0] << 16)
3904 | ((unsigned int) rel
->r_index
[1] << 8)
3906 r_extern
= (0 != (rel
->r_type
[0] & RELOC_STD_BITS_EXTERN_BIG
));
3907 r_pcrel
= (0 != (rel
->r_type
[0] & RELOC_STD_BITS_PCREL_BIG
));
3908 r_baserel
= (0 != (rel
->r_type
[0] & RELOC_STD_BITS_BASEREL_BIG
));
3909 r_jmptable
= (0 != (rel
->r_type
[0] & RELOC_STD_BITS_JMPTABLE_BIG
));
3910 r_relative
= (0 != (rel
->r_type
[0] & RELOC_STD_BITS_RELATIVE_BIG
));
3911 r_length
= ((rel
->r_type
[0] & RELOC_STD_BITS_LENGTH_BIG
)
3912 >> RELOC_STD_BITS_LENGTH_SH_BIG
);
3916 r_index
= (((unsigned int) rel
->r_index
[2] << 16)
3917 | ((unsigned int) rel
->r_index
[1] << 8)
3919 r_extern
= (0 != (rel
->r_type
[0] & RELOC_STD_BITS_EXTERN_LITTLE
));
3920 r_pcrel
= (0 != (rel
->r_type
[0] & RELOC_STD_BITS_PCREL_LITTLE
));
3921 r_baserel
= (0 != (rel
->r_type
[0]
3922 & RELOC_STD_BITS_BASEREL_LITTLE
));
3923 r_jmptable
= (0 != (rel
->r_type
[0]
3924 & RELOC_STD_BITS_JMPTABLE_LITTLE
));
3925 r_relative
= (0 != (rel
->r_type
[0]
3926 & RELOC_STD_BITS_RELATIVE_LITTLE
));
3927 r_length
= ((rel
->r_type
[0] & RELOC_STD_BITS_LENGTH_LITTLE
)
3928 >> RELOC_STD_BITS_LENGTH_SH_LITTLE
);
3931 howto_idx
= (r_length
+ 4 * r_pcrel
+ 8 * r_baserel
3932 + 16 * r_jmptable
+ 32 * r_relative
);
3933 BFD_ASSERT (howto_idx
< TABLE_SIZE (howto_table_std
));
3934 howto
= howto_table_std
+ howto_idx
;
3940 /* We are generating a relocatable output file, and must
3941 modify the reloc accordingly. */
3944 /* If we know the symbol this relocation is against,
3945 convert it into a relocation against a section. This
3946 is what the native linker does. */
3947 h
= sym_hashes
[r_index
];
3949 && (h
->root
.type
== bfd_link_hash_defined
3950 || h
->root
.type
== bfd_link_hash_defweak
))
3952 asection
*output_section
;
3954 /* Change the r_extern value. */
3955 if (bfd_header_big_endian (output_bfd
))
3956 rel
->r_type
[0] &=~ RELOC_STD_BITS_EXTERN_BIG
;
3958 rel
->r_type
[0] &=~ RELOC_STD_BITS_EXTERN_LITTLE
;
3960 /* Compute a new r_index. */
3961 output_section
= h
->root
.u
.def
.section
->output_section
;
3962 if (output_section
== obj_textsec (output_bfd
))
3964 else if (output_section
== obj_datasec (output_bfd
))
3966 else if (output_section
== obj_bsssec (output_bfd
))
3971 /* Add the symbol value and the section VMA to the
3972 addend stored in the contents. */
3973 relocation
= (h
->root
.u
.def
.value
3974 + output_section
->vma
3975 + h
->root
.u
.def
.section
->output_offset
);
3979 /* We must change r_index according to the symbol
3981 r_index
= symbol_map
[r_index
];
3987 /* We decided to strip this symbol, but it
3988 turns out that we can't. Note that we
3989 lose the other and desc information here.
3990 I don't think that will ever matter for a
3996 if (! aout_link_write_other_symbol (h
,
4006 name
= strings
+ GET_WORD (input_bfd
,
4007 syms
[r_index
].e_strx
);
4008 if (! ((*finfo
->info
->callbacks
->unattached_reloc
)
4009 (finfo
->info
, name
, input_bfd
, input_section
,
4019 /* Write out the new r_index value. */
4020 if (bfd_header_big_endian (output_bfd
))
4022 rel
->r_index
[0] = r_index
>> 16;
4023 rel
->r_index
[1] = r_index
>> 8;
4024 rel
->r_index
[2] = r_index
;
4028 rel
->r_index
[2] = r_index
>> 16;
4029 rel
->r_index
[1] = r_index
>> 8;
4030 rel
->r_index
[0] = r_index
;
4037 /* This is a relocation against a section. We must
4038 adjust by the amount that the section moved. */
4039 section
= aout_reloc_index_to_section (input_bfd
, r_index
);
4040 relocation
= (section
->output_section
->vma
4041 + section
->output_offset
4045 /* Change the address of the relocation. */
4046 PUT_WORD (output_bfd
,
4047 r_addr
+ input_section
->output_offset
,
4050 /* Adjust a PC relative relocation by removing the reference
4051 to the original address in the section and including the
4052 reference to the new address. */
4054 relocation
-= (input_section
->output_section
->vma
4055 + input_section
->output_offset
4056 - input_section
->vma
);
4058 #ifdef MY_relocatable_reloc
4059 MY_relocatable_reloc (howto
, output_bfd
, rel
, relocation
, r_addr
);
4062 if (relocation
== 0)
4065 r
= MY_relocate_contents (howto
,
4066 input_bfd
, relocation
,
4073 /* We are generating an executable, and must do a full
4079 h
= sym_hashes
[r_index
];
4082 && (h
->root
.type
== bfd_link_hash_defined
4083 || h
->root
.type
== bfd_link_hash_defweak
))
4085 relocation
= (h
->root
.u
.def
.value
4086 + h
->root
.u
.def
.section
->output_section
->vma
4087 + h
->root
.u
.def
.section
->output_offset
);
4090 && h
->root
.type
== bfd_link_hash_undefweak
)
4102 section
= aout_reloc_index_to_section (input_bfd
, r_index
);
4103 relocation
= (section
->output_section
->vma
4104 + section
->output_offset
4107 relocation
+= input_section
->vma
;
4110 if (check_dynamic_reloc
!= NULL
)
4114 if (! ((*check_dynamic_reloc
)
4115 (finfo
->info
, input_bfd
, input_section
, h
,
4116 (void *) rel
, contents
, &skip
, &relocation
)))
4122 /* Now warn if a global symbol is undefined. We could not
4123 do this earlier, because check_dynamic_reloc might want
4124 to skip this reloc. */
4125 if (hundef
&& ! finfo
->info
->shared
&& ! r_baserel
)
4130 name
= h
->root
.root
.string
;
4132 name
= strings
+ GET_WORD (input_bfd
, syms
[r_index
].e_strx
);
4133 if (! ((*finfo
->info
->callbacks
->undefined_symbol
)
4134 (finfo
->info
, name
, input_bfd
, input_section
,
4139 r
= MY_final_link_relocate (howto
,
4140 input_bfd
, input_section
,
4141 contents
, r_addr
, relocation
,
4145 if (r
!= bfd_reloc_ok
)
4150 case bfd_reloc_outofrange
:
4152 case bfd_reloc_overflow
:
4159 name
= strings
+ GET_WORD (input_bfd
,
4160 syms
[r_index
].e_strx
);
4165 s
= aout_reloc_index_to_section (input_bfd
, r_index
);
4166 name
= bfd_section_name (input_bfd
, s
);
4168 if (! ((*finfo
->info
->callbacks
->reloc_overflow
)
4169 (finfo
->info
, (h
? &h
->root
: NULL
), name
,
4170 howto
->name
, (bfd_vma
) 0, input_bfd
,
4171 input_section
, r_addr
)))
4182 /* Relocate an a.out section using extended a.out relocs. */
4185 aout_link_input_section_ext (struct aout_final_link_info
*finfo
,
4187 asection
*input_section
,
4188 struct reloc_ext_external
*relocs
,
4189 bfd_size_type rel_size
,
4192 bfd_boolean (*check_dynamic_reloc
)
4193 (struct bfd_link_info
*, bfd
*, asection
*,
4194 struct aout_link_hash_entry
*, void *, bfd_byte
*, bfd_boolean
*,
4197 bfd_boolean relocatable
;
4198 struct external_nlist
*syms
;
4200 struct aout_link_hash_entry
**sym_hashes
;
4202 bfd_size_type reloc_count
;
4203 struct reloc_ext_external
*rel
;
4204 struct reloc_ext_external
*rel_end
;
4206 output_bfd
= finfo
->output_bfd
;
4207 check_dynamic_reloc
= aout_backend_info (output_bfd
)->check_dynamic_reloc
;
4209 BFD_ASSERT (obj_reloc_entry_size (input_bfd
) == RELOC_EXT_SIZE
);
4210 BFD_ASSERT (input_bfd
->xvec
->header_byteorder
4211 == output_bfd
->xvec
->header_byteorder
);
4213 relocatable
= finfo
->info
->relocatable
;
4214 syms
= obj_aout_external_syms (input_bfd
);
4215 strings
= obj_aout_external_strings (input_bfd
);
4216 sym_hashes
= obj_aout_sym_hashes (input_bfd
);
4217 symbol_map
= finfo
->symbol_map
;
4219 reloc_count
= rel_size
/ RELOC_EXT_SIZE
;
4221 rel_end
= rel
+ reloc_count
;
4222 for (; rel
< rel_end
; rel
++)
4227 unsigned int r_type
;
4229 struct aout_link_hash_entry
*h
= NULL
;
4230 asection
*r_section
= NULL
;
4233 r_addr
= GET_SWORD (input_bfd
, rel
->r_address
);
4235 if (bfd_header_big_endian (input_bfd
))
4237 r_index
= (((unsigned int) rel
->r_index
[0] << 16)
4238 | ((unsigned int) rel
->r_index
[1] << 8)
4240 r_extern
= (0 != (rel
->r_type
[0] & RELOC_EXT_BITS_EXTERN_BIG
));
4241 r_type
= ((rel
->r_type
[0] & RELOC_EXT_BITS_TYPE_BIG
)
4242 >> RELOC_EXT_BITS_TYPE_SH_BIG
);
4246 r_index
= (((unsigned int) rel
->r_index
[2] << 16)
4247 | ((unsigned int) rel
->r_index
[1] << 8)
4249 r_extern
= (0 != (rel
->r_type
[0] & RELOC_EXT_BITS_EXTERN_LITTLE
));
4250 r_type
= ((rel
->r_type
[0] & RELOC_EXT_BITS_TYPE_LITTLE
)
4251 >> RELOC_EXT_BITS_TYPE_SH_LITTLE
);
4254 r_addend
= GET_SWORD (input_bfd
, rel
->r_addend
);
4256 BFD_ASSERT (r_type
< TABLE_SIZE (howto_table_ext
));
4260 /* We are generating a relocatable output file, and must
4261 modify the reloc accordingly. */
4263 || r_type
== (unsigned int) RELOC_BASE10
4264 || r_type
== (unsigned int) RELOC_BASE13
4265 || r_type
== (unsigned int) RELOC_BASE22
)
4267 /* If we know the symbol this relocation is against,
4268 convert it into a relocation against a section. This
4269 is what the native linker does. */
4270 if (r_type
== (unsigned int) RELOC_BASE10
4271 || r_type
== (unsigned int) RELOC_BASE13
4272 || r_type
== (unsigned int) RELOC_BASE22
)
4275 h
= sym_hashes
[r_index
];
4277 && (h
->root
.type
== bfd_link_hash_defined
4278 || h
->root
.type
== bfd_link_hash_defweak
))
4280 asection
*output_section
;
4282 /* Change the r_extern value. */
4283 if (bfd_header_big_endian (output_bfd
))
4284 rel
->r_type
[0] &=~ RELOC_EXT_BITS_EXTERN_BIG
;
4286 rel
->r_type
[0] &=~ RELOC_EXT_BITS_EXTERN_LITTLE
;
4288 /* Compute a new r_index. */
4289 output_section
= h
->root
.u
.def
.section
->output_section
;
4290 if (output_section
== obj_textsec (output_bfd
))
4292 else if (output_section
== obj_datasec (output_bfd
))
4294 else if (output_section
== obj_bsssec (output_bfd
))
4299 /* Add the symbol value and the section VMA to the
4301 relocation
= (h
->root
.u
.def
.value
4302 + output_section
->vma
4303 + h
->root
.u
.def
.section
->output_offset
);
4305 /* Now RELOCATION is the VMA of the final
4306 destination. If this is a PC relative reloc,
4307 then ADDEND is the negative of the source VMA.
4308 We want to set ADDEND to the difference between
4309 the destination VMA and the source VMA, which
4310 means we must adjust RELOCATION by the change in
4311 the source VMA. This is done below. */
4315 /* We must change r_index according to the symbol
4317 r_index
= symbol_map
[r_index
];
4323 /* We decided to strip this symbol, but it
4324 turns out that we can't. Note that we
4325 lose the other and desc information here.
4326 I don't think that will ever matter for a
4332 if (! aout_link_write_other_symbol (h
,
4342 name
= strings
+ GET_WORD (input_bfd
,
4343 syms
[r_index
].e_strx
);
4344 if (! ((*finfo
->info
->callbacks
->unattached_reloc
)
4345 (finfo
->info
, name
, input_bfd
, input_section
,
4354 /* If this is a PC relative reloc, then the addend
4355 is the negative of the source VMA. We must
4356 adjust it by the change in the source VMA. This
4360 /* Write out the new r_index value. */
4361 if (bfd_header_big_endian (output_bfd
))
4363 rel
->r_index
[0] = r_index
>> 16;
4364 rel
->r_index
[1] = r_index
>> 8;
4365 rel
->r_index
[2] = r_index
;
4369 rel
->r_index
[2] = r_index
>> 16;
4370 rel
->r_index
[1] = r_index
>> 8;
4371 rel
->r_index
[0] = r_index
;
4376 /* This is a relocation against a section. We must
4377 adjust by the amount that the section moved. */
4378 r_section
= aout_reloc_index_to_section (input_bfd
, r_index
);
4379 relocation
= (r_section
->output_section
->vma
4380 + r_section
->output_offset
4383 /* If this is a PC relative reloc, then the addend is
4384 the difference in VMA between the destination and the
4385 source. We have just adjusted for the change in VMA
4386 of the destination, so we must also adjust by the
4387 change in VMA of the source. This is done below. */
4390 /* As described above, we must always adjust a PC relative
4391 reloc by the change in VMA of the source. However, if
4392 pcrel_offset is set, then the addend does not include the
4393 location within the section, in which case we don't need
4394 to adjust anything. */
4395 if (howto_table_ext
[r_type
].pc_relative
4396 && ! howto_table_ext
[r_type
].pcrel_offset
)
4397 relocation
-= (input_section
->output_section
->vma
4398 + input_section
->output_offset
4399 - input_section
->vma
);
4401 /* Change the addend if necessary. */
4402 if (relocation
!= 0)
4403 PUT_WORD (output_bfd
, r_addend
+ relocation
, rel
->r_addend
);
4405 /* Change the address of the relocation. */
4406 PUT_WORD (output_bfd
,
4407 r_addr
+ input_section
->output_offset
,
4413 bfd_reloc_status_type r
;
4415 /* We are generating an executable, and must do a full
4421 h
= sym_hashes
[r_index
];
4424 && (h
->root
.type
== bfd_link_hash_defined
4425 || h
->root
.type
== bfd_link_hash_defweak
))
4427 relocation
= (h
->root
.u
.def
.value
4428 + h
->root
.u
.def
.section
->output_section
->vma
4429 + h
->root
.u
.def
.section
->output_offset
);
4432 && h
->root
.type
== bfd_link_hash_undefweak
)
4440 else if (r_type
== (unsigned int) RELOC_BASE10
4441 || r_type
== (unsigned int) RELOC_BASE13
4442 || r_type
== (unsigned int) RELOC_BASE22
)
4444 struct external_nlist
*sym
;
4447 /* For base relative relocs, r_index is always an index
4448 into the symbol table, even if r_extern is 0. */
4449 sym
= syms
+ r_index
;
4450 type
= H_GET_8 (input_bfd
, sym
->e_type
);
4451 if ((type
& N_TYPE
) == N_TEXT
4453 r_section
= obj_textsec (input_bfd
);
4454 else if ((type
& N_TYPE
) == N_DATA
4456 r_section
= obj_datasec (input_bfd
);
4457 else if ((type
& N_TYPE
) == N_BSS
4459 r_section
= obj_bsssec (input_bfd
);
4460 else if ((type
& N_TYPE
) == N_ABS
4462 r_section
= bfd_abs_section_ptr
;
4465 relocation
= (r_section
->output_section
->vma
4466 + r_section
->output_offset
4467 + (GET_WORD (input_bfd
, sym
->e_value
)
4472 r_section
= aout_reloc_index_to_section (input_bfd
, r_index
);
4474 /* If this is a PC relative reloc, then R_ADDEND is the
4475 difference between the two vmas, or
4476 old_dest_sec + old_dest_off - (old_src_sec + old_src_off)
4478 old_dest_sec == section->vma
4480 old_src_sec == input_section->vma
4482 old_src_off == r_addr
4484 _bfd_final_link_relocate expects RELOCATION +
4485 R_ADDEND to be the VMA of the destination minus
4486 r_addr (the minus r_addr is because this relocation
4487 is not pcrel_offset, which is a bit confusing and
4488 should, perhaps, be changed), or
4491 new_dest_sec == output_section->vma + output_offset
4492 We arrange for this to happen by setting RELOCATION to
4493 new_dest_sec + old_src_sec - old_dest_sec
4495 If this is not a PC relative reloc, then R_ADDEND is
4496 simply the VMA of the destination, so we set
4497 RELOCATION to the change in the destination VMA, or
4498 new_dest_sec - old_dest_sec
4500 relocation
= (r_section
->output_section
->vma
4501 + r_section
->output_offset
4503 if (howto_table_ext
[r_type
].pc_relative
)
4504 relocation
+= input_section
->vma
;
4507 if (check_dynamic_reloc
!= NULL
)
4511 if (! ((*check_dynamic_reloc
)
4512 (finfo
->info
, input_bfd
, input_section
, h
,
4513 (void *) rel
, contents
, &skip
, &relocation
)))
4519 /* Now warn if a global symbol is undefined. We could not
4520 do this earlier, because check_dynamic_reloc might want
4521 to skip this reloc. */
4523 && ! finfo
->info
->shared
4524 && r_type
!= (unsigned int) RELOC_BASE10
4525 && r_type
!= (unsigned int) RELOC_BASE13
4526 && r_type
!= (unsigned int) RELOC_BASE22
)
4531 name
= h
->root
.root
.string
;
4533 name
= strings
+ GET_WORD (input_bfd
, syms
[r_index
].e_strx
);
4534 if (! ((*finfo
->info
->callbacks
->undefined_symbol
)
4535 (finfo
->info
, name
, input_bfd
, input_section
,
4540 if (r_type
!= (unsigned int) RELOC_SPARC_REV32
)
4541 r
= MY_final_link_relocate (howto_table_ext
+ r_type
,
4542 input_bfd
, input_section
,
4543 contents
, r_addr
, relocation
,
4549 x
= bfd_get_32 (input_bfd
, contents
+ r_addr
);
4550 x
= x
+ relocation
+ r_addend
;
4551 bfd_putl32 (/*input_bfd,*/ x
, contents
+ r_addr
);
4555 if (r
!= bfd_reloc_ok
)
4560 case bfd_reloc_outofrange
:
4562 case bfd_reloc_overflow
:
4569 || r_type
== (unsigned int) RELOC_BASE10
4570 || r_type
== (unsigned int) RELOC_BASE13
4571 || r_type
== (unsigned int) RELOC_BASE22
)
4572 name
= strings
+ GET_WORD (input_bfd
,
4573 syms
[r_index
].e_strx
);
4578 s
= aout_reloc_index_to_section (input_bfd
, r_index
);
4579 name
= bfd_section_name (input_bfd
, s
);
4581 if (! ((*finfo
->info
->callbacks
->reloc_overflow
)
4582 (finfo
->info
, (h
? &h
->root
: NULL
), name
,
4583 howto_table_ext
[r_type
].name
,
4584 r_addend
, input_bfd
, input_section
, r_addr
)))
4596 /* Link an a.out section into the output file. */
4599 aout_link_input_section (struct aout_final_link_info
*finfo
,
4601 asection
*input_section
,
4602 file_ptr
*reloff_ptr
,
4603 bfd_size_type rel_size
)
4605 bfd_size_type input_size
;
4608 /* Get the section contents. */
4609 input_size
= input_section
->size
;
4610 if (! bfd_get_section_contents (input_bfd
, input_section
,
4611 (void *) finfo
->contents
,
4612 (file_ptr
) 0, input_size
))
4615 /* Read in the relocs if we haven't already done it. */
4616 if (aout_section_data (input_section
) != NULL
4617 && aout_section_data (input_section
)->relocs
!= NULL
)
4618 relocs
= aout_section_data (input_section
)->relocs
;
4621 relocs
= finfo
->relocs
;
4624 if (bfd_seek (input_bfd
, input_section
->rel_filepos
, SEEK_SET
) != 0
4625 || bfd_bread (relocs
, rel_size
, input_bfd
) != rel_size
)
4630 /* Relocate the section contents. */
4631 if (obj_reloc_entry_size (input_bfd
) == RELOC_STD_SIZE
)
4633 if (! aout_link_input_section_std (finfo
, input_bfd
, input_section
,
4634 (struct reloc_std_external
*) relocs
,
4635 rel_size
, finfo
->contents
))
4640 if (! aout_link_input_section_ext (finfo
, input_bfd
, input_section
,
4641 (struct reloc_ext_external
*) relocs
,
4642 rel_size
, finfo
->contents
))
4646 /* Write out the section contents. */
4647 if (! bfd_set_section_contents (finfo
->output_bfd
,
4648 input_section
->output_section
,
4649 (void *) finfo
->contents
,
4650 (file_ptr
) input_section
->output_offset
,
4654 /* If we are producing relocatable output, the relocs were
4655 modified, and we now write them out. */
4656 if (finfo
->info
->relocatable
&& rel_size
> 0)
4658 if (bfd_seek (finfo
->output_bfd
, *reloff_ptr
, SEEK_SET
) != 0)
4660 if (bfd_bwrite (relocs
, rel_size
, finfo
->output_bfd
) != rel_size
)
4662 *reloff_ptr
+= rel_size
;
4664 /* Assert that the relocs have not run into the symbols, and
4665 that if these are the text relocs they have not run into the
4667 BFD_ASSERT (*reloff_ptr
<= obj_sym_filepos (finfo
->output_bfd
)
4668 && (reloff_ptr
!= &finfo
->treloff
4670 <= obj_datasec (finfo
->output_bfd
)->rel_filepos
)));
4676 /* Adjust and write out the symbols for an a.out file. Set the new
4677 symbol indices into a symbol_map. */
4680 aout_link_write_symbols (struct aout_final_link_info
*finfo
, bfd
*input_bfd
)
4683 bfd_size_type sym_count
;
4685 enum bfd_link_strip strip
;
4686 enum bfd_link_discard discard
;
4687 struct external_nlist
*outsym
;
4688 bfd_size_type strtab_index
;
4689 struct external_nlist
*sym
;
4690 struct external_nlist
*sym_end
;
4691 struct aout_link_hash_entry
**sym_hash
;
4694 bfd_boolean skip_next
;
4696 output_bfd
= finfo
->output_bfd
;
4697 sym_count
= obj_aout_external_sym_count (input_bfd
);
4698 strings
= obj_aout_external_strings (input_bfd
);
4699 strip
= finfo
->info
->strip
;
4700 discard
= finfo
->info
->discard
;
4701 outsym
= finfo
->output_syms
;
4703 /* First write out a symbol for this object file, unless we are
4704 discarding such symbols. */
4705 if (strip
!= strip_all
4706 && (strip
!= strip_some
4707 || bfd_hash_lookup (finfo
->info
->keep_hash
, input_bfd
->filename
,
4708 FALSE
, FALSE
) != NULL
)
4709 && discard
!= discard_all
)
4711 H_PUT_8 (output_bfd
, N_TEXT
, outsym
->e_type
);
4712 H_PUT_8 (output_bfd
, 0, outsym
->e_other
);
4713 H_PUT_16 (output_bfd
, 0, outsym
->e_desc
);
4714 strtab_index
= add_to_stringtab (output_bfd
, finfo
->strtab
,
4715 input_bfd
->filename
, FALSE
);
4716 if (strtab_index
== (bfd_size_type
) -1)
4718 PUT_WORD (output_bfd
, strtab_index
, outsym
->e_strx
);
4719 PUT_WORD (output_bfd
,
4720 (bfd_get_section_vma (output_bfd
,
4721 obj_textsec (input_bfd
)->output_section
)
4722 + obj_textsec (input_bfd
)->output_offset
),
4724 ++obj_aout_external_sym_count (output_bfd
);
4730 sym
= obj_aout_external_syms (input_bfd
);
4731 sym_end
= sym
+ sym_count
;
4732 sym_hash
= obj_aout_sym_hashes (input_bfd
);
4733 symbol_map
= finfo
->symbol_map
;
4734 memset (symbol_map
, 0, (size_t) sym_count
* sizeof *symbol_map
);
4735 for (; sym
< sym_end
; sym
++, sym_hash
++, symbol_map
++)
4739 struct aout_link_hash_entry
*h
;
4745 /* We set *symbol_map to 0 above for all symbols. If it has
4746 already been set to -1 for this symbol, it means that we are
4747 discarding it because it appears in a duplicate header file.
4748 See the N_BINCL code below. */
4749 if (*symbol_map
== -1)
4752 /* Initialize *symbol_map to -1, which means that the symbol was
4753 not copied into the output file. We will change it later if
4754 we do copy the symbol over. */
4757 type
= H_GET_8 (input_bfd
, sym
->e_type
);
4758 name
= strings
+ GET_WORD (input_bfd
, sym
->e_strx
);
4764 /* Pass this symbol through. It is the target of an
4765 indirect or warning symbol. */
4766 val
= GET_WORD (input_bfd
, sym
->e_value
);
4771 /* Skip this symbol, which is the target of an indirect
4772 symbol that we have changed to no longer be an indirect
4779 struct aout_link_hash_entry
*hresolve
;
4781 /* We have saved the hash table entry for this symbol, if
4782 there is one. Note that we could just look it up again
4783 in the hash table, provided we first check that it is an
4787 /* Use the name from the hash table, in case the symbol was
4790 && h
->root
.type
!= bfd_link_hash_warning
)
4791 name
= h
->root
.root
.string
;
4793 /* If this is an indirect or warning symbol, then change
4794 hresolve to the base symbol. We also change *sym_hash so
4795 that the relocation routines relocate against the real
4798 if (h
!= (struct aout_link_hash_entry
*) NULL
4799 && (h
->root
.type
== bfd_link_hash_indirect
4800 || h
->root
.type
== bfd_link_hash_warning
))
4802 hresolve
= (struct aout_link_hash_entry
*) h
->root
.u
.i
.link
;
4803 while (hresolve
->root
.type
== bfd_link_hash_indirect
4804 || hresolve
->root
.type
== bfd_link_hash_warning
)
4805 hresolve
= ((struct aout_link_hash_entry
*)
4806 hresolve
->root
.u
.i
.link
);
4807 *sym_hash
= hresolve
;
4810 /* If the symbol has already been written out, skip it. */
4814 if ((type
& N_TYPE
) == N_INDR
4815 || type
== N_WARNING
)
4817 *symbol_map
= h
->indx
;
4821 /* See if we are stripping this symbol. */
4827 case strip_debugger
:
4828 if ((type
& N_STAB
) != 0)
4832 if (bfd_hash_lookup (finfo
->info
->keep_hash
, name
, FALSE
, FALSE
)
4847 /* Get the value of the symbol. */
4848 if ((type
& N_TYPE
) == N_TEXT
4850 symsec
= obj_textsec (input_bfd
);
4851 else if ((type
& N_TYPE
) == N_DATA
4853 symsec
= obj_datasec (input_bfd
);
4854 else if ((type
& N_TYPE
) == N_BSS
4856 symsec
= obj_bsssec (input_bfd
);
4857 else if ((type
& N_TYPE
) == N_ABS
4859 symsec
= bfd_abs_section_ptr
;
4860 else if (((type
& N_TYPE
) == N_INDR
4861 && (hresolve
== NULL
4862 || (hresolve
->root
.type
!= bfd_link_hash_defined
4863 && hresolve
->root
.type
!= bfd_link_hash_defweak
4864 && hresolve
->root
.type
!= bfd_link_hash_common
)))
4865 || type
== N_WARNING
)
4867 /* Pass the next symbol through unchanged. The
4868 condition above for indirect symbols is so that if
4869 the indirect symbol was defined, we output it with
4870 the correct definition so the debugger will
4873 val
= GET_WORD (input_bfd
, sym
->e_value
);
4876 else if ((type
& N_STAB
) != 0)
4878 val
= GET_WORD (input_bfd
, sym
->e_value
);
4883 /* If we get here with an indirect symbol, it means that
4884 we are outputting it with a real definition. In such
4885 a case we do not want to output the next symbol,
4886 which is the target of the indirection. */
4887 if ((type
& N_TYPE
) == N_INDR
)
4892 /* We need to get the value from the hash table. We use
4893 hresolve so that if we have defined an indirect
4894 symbol we output the final definition. */
4897 switch (type
& N_TYPE
)
4900 symsec
= obj_textsec (input_bfd
);
4903 symsec
= obj_datasec (input_bfd
);
4906 symsec
= obj_bsssec (input_bfd
);
4909 symsec
= bfd_abs_section_ptr
;
4916 else if (hresolve
->root
.type
== bfd_link_hash_defined
4917 || hresolve
->root
.type
== bfd_link_hash_defweak
)
4919 asection
*input_section
;
4920 asection
*output_section
;
4922 /* This case usually means a common symbol which was
4923 turned into a defined symbol. */
4924 input_section
= hresolve
->root
.u
.def
.section
;
4925 output_section
= input_section
->output_section
;
4926 BFD_ASSERT (bfd_is_abs_section (output_section
)
4927 || output_section
->owner
== output_bfd
);
4928 val
= (hresolve
->root
.u
.def
.value
4929 + bfd_get_section_vma (output_bfd
, output_section
)
4930 + input_section
->output_offset
);
4932 /* Get the correct type based on the section. If
4933 this is a constructed set, force it to be
4934 globally visible. */
4943 if (output_section
== obj_textsec (output_bfd
))
4944 type
|= (hresolve
->root
.type
== bfd_link_hash_defined
4947 else if (output_section
== obj_datasec (output_bfd
))
4948 type
|= (hresolve
->root
.type
== bfd_link_hash_defined
4951 else if (output_section
== obj_bsssec (output_bfd
))
4952 type
|= (hresolve
->root
.type
== bfd_link_hash_defined
4956 type
|= (hresolve
->root
.type
== bfd_link_hash_defined
4960 else if (hresolve
->root
.type
== bfd_link_hash_common
)
4961 val
= hresolve
->root
.u
.c
.size
;
4962 else if (hresolve
->root
.type
== bfd_link_hash_undefweak
)
4971 val
= (symsec
->output_section
->vma
4972 + symsec
->output_offset
4973 + (GET_WORD (input_bfd
, sym
->e_value
)
4976 /* If this is a global symbol set the written flag, and if
4977 it is a local symbol see if we should discard it. */
4981 h
->indx
= obj_aout_external_sym_count (output_bfd
);
4983 else if ((type
& N_TYPE
) != N_SETT
4984 && (type
& N_TYPE
) != N_SETD
4985 && (type
& N_TYPE
) != N_SETB
4986 && (type
& N_TYPE
) != N_SETA
)
4991 case discard_sec_merge
:
4994 if ((type
& N_STAB
) == 0
4995 && bfd_is_local_label_name (input_bfd
, name
))
5009 /* An N_BINCL symbol indicates the start of the stabs
5010 entries for a header file. We need to scan ahead to the
5011 next N_EINCL symbol, ignoring nesting, adding up all the
5012 characters in the symbol names, not including the file
5013 numbers in types (the first number after an open
5015 if (type
== (int) N_BINCL
)
5017 struct external_nlist
*incl_sym
;
5019 struct aout_link_includes_entry
*incl_entry
;
5020 struct aout_link_includes_totals
*t
;
5024 for (incl_sym
= sym
+ 1; incl_sym
< sym_end
; incl_sym
++)
5028 incl_type
= H_GET_8 (input_bfd
, incl_sym
->e_type
);
5029 if (incl_type
== (int) N_EINCL
)
5035 else if (incl_type
== (int) N_BINCL
)
5041 s
= strings
+ GET_WORD (input_bfd
, incl_sym
->e_strx
);
5042 for (; *s
!= '\0'; s
++)
5047 /* Skip the file number. */
5049 while (ISDIGIT (*s
))
5057 /* If we have already included a header file with the
5058 same value, then replace this one with an N_EXCL
5060 copy
= (bfd_boolean
) (! finfo
->info
->keep_memory
);
5061 incl_entry
= aout_link_includes_lookup (&finfo
->includes
,
5063 if (incl_entry
== NULL
)
5065 for (t
= incl_entry
->totals
; t
!= NULL
; t
= t
->next
)
5066 if (t
->total
== val
)
5070 /* This is the first time we have seen this header
5071 file with this set of stabs strings. */
5072 t
= bfd_hash_allocate (&finfo
->includes
.root
,
5077 t
->next
= incl_entry
->totals
;
5078 incl_entry
->totals
= t
;
5084 /* This is a duplicate header file. We must change
5085 it to be an N_EXCL entry, and mark all the
5086 included symbols to prevent outputting them. */
5087 type
= (int) N_EXCL
;
5090 for (incl_sym
= sym
+ 1, incl_map
= symbol_map
+ 1;
5092 incl_sym
++, incl_map
++)
5096 incl_type
= H_GET_8 (input_bfd
, incl_sym
->e_type
);
5097 if (incl_type
== (int) N_EINCL
)
5106 else if (incl_type
== (int) N_BINCL
)
5115 /* Copy this symbol into the list of symbols we are going to
5117 H_PUT_8 (output_bfd
, type
, outsym
->e_type
);
5118 H_PUT_8 (output_bfd
, H_GET_8 (input_bfd
, sym
->e_other
), outsym
->e_other
);
5119 H_PUT_16 (output_bfd
, H_GET_16 (input_bfd
, sym
->e_desc
), outsym
->e_desc
);
5121 if (! finfo
->info
->keep_memory
)
5123 /* name points into a string table which we are going to
5124 free. If there is a hash table entry, use that string.
5125 Otherwise, copy name into memory. */
5127 name
= h
->root
.root
.string
;
5131 strtab_index
= add_to_stringtab (output_bfd
, finfo
->strtab
,
5133 if (strtab_index
== (bfd_size_type
) -1)
5135 PUT_WORD (output_bfd
, strtab_index
, outsym
->e_strx
);
5136 PUT_WORD (output_bfd
, val
, outsym
->e_value
);
5137 *symbol_map
= obj_aout_external_sym_count (output_bfd
);
5138 ++obj_aout_external_sym_count (output_bfd
);
5142 /* Write out the output symbols we have just constructed. */
5143 if (outsym
> finfo
->output_syms
)
5145 bfd_size_type outsym_size
;
5147 if (bfd_seek (output_bfd
, finfo
->symoff
, SEEK_SET
) != 0)
5149 outsym_size
= outsym
- finfo
->output_syms
;
5150 outsym_size
*= EXTERNAL_NLIST_SIZE
;
5151 if (bfd_bwrite ((void *) finfo
->output_syms
, outsym_size
, output_bfd
)
5154 finfo
->symoff
+= outsym_size
;
5160 /* Link an a.out input BFD into the output file. */
5163 aout_link_input_bfd (struct aout_final_link_info
*finfo
, bfd
*input_bfd
)
5165 bfd_size_type sym_count
;
5167 BFD_ASSERT (bfd_get_format (input_bfd
) == bfd_object
);
5169 /* If this is a dynamic object, it may need special handling. */
5170 if ((input_bfd
->flags
& DYNAMIC
) != 0
5171 && aout_backend_info (input_bfd
)->link_dynamic_object
!= NULL
)
5172 return ((*aout_backend_info (input_bfd
)->link_dynamic_object
)
5173 (finfo
->info
, input_bfd
));
5175 /* Get the symbols. We probably have them already, unless
5176 finfo->info->keep_memory is FALSE. */
5177 if (! aout_get_external_symbols (input_bfd
))
5180 sym_count
= obj_aout_external_sym_count (input_bfd
);
5182 /* Write out the symbols and get a map of the new indices. The map
5183 is placed into finfo->symbol_map. */
5184 if (! aout_link_write_symbols (finfo
, input_bfd
))
5187 /* Relocate and write out the sections. These functions use the
5188 symbol map created by aout_link_write_symbols. The linker_mark
5189 field will be set if these sections are to be included in the
5190 link, which will normally be the case. */
5191 if (obj_textsec (input_bfd
)->linker_mark
)
5193 if (! aout_link_input_section (finfo
, input_bfd
,
5194 obj_textsec (input_bfd
),
5196 exec_hdr (input_bfd
)->a_trsize
))
5199 if (obj_datasec (input_bfd
)->linker_mark
)
5201 if (! aout_link_input_section (finfo
, input_bfd
,
5202 obj_datasec (input_bfd
),
5204 exec_hdr (input_bfd
)->a_drsize
))
5208 /* If we are not keeping memory, we don't need the symbols any
5209 longer. We still need them if we are keeping memory, because the
5210 strings in the hash table point into them. */
5211 if (! finfo
->info
->keep_memory
)
5213 if (! aout_link_free_symbols (input_bfd
))
5220 /* Do the final link step. This is called on the output BFD. The
5221 INFO structure should point to a list of BFDs linked through the
5222 link_next field which can be used to find each BFD which takes part
5223 in the output. Also, each section in ABFD should point to a list
5224 of bfd_link_order structures which list all the input sections for
5225 the output section. */
5228 NAME (aout
, final_link
) (bfd
*abfd
,
5229 struct bfd_link_info
*info
,
5230 void (*callback
) (bfd
*, file_ptr
*, file_ptr
*, file_ptr
*))
5232 struct aout_final_link_info aout_info
;
5233 bfd_boolean includes_hash_initialized
= FALSE
;
5235 bfd_size_type trsize
, drsize
;
5236 bfd_size_type max_contents_size
;
5237 bfd_size_type max_relocs_size
;
5238 bfd_size_type max_sym_count
;
5239 bfd_size_type text_size
;
5241 struct bfd_link_order
*p
;
5243 bfd_boolean have_link_order_relocs
;
5246 abfd
->flags
|= DYNAMIC
;
5248 aout_info
.info
= info
;
5249 aout_info
.output_bfd
= abfd
;
5250 aout_info
.contents
= NULL
;
5251 aout_info
.relocs
= NULL
;
5252 aout_info
.symbol_map
= NULL
;
5253 aout_info
.output_syms
= NULL
;
5255 if (! bfd_hash_table_init_n (&aout_info
.includes
.root
,
5256 aout_link_includes_newfunc
,
5259 includes_hash_initialized
= TRUE
;
5261 /* Figure out the largest section size. Also, if generating
5262 relocatable output, count the relocs. */
5265 max_contents_size
= 0;
5266 max_relocs_size
= 0;
5268 for (sub
= info
->input_bfds
; sub
!= NULL
; sub
= sub
->link_next
)
5272 if (info
->relocatable
)
5274 if (bfd_get_flavour (sub
) == bfd_target_aout_flavour
)
5276 trsize
+= exec_hdr (sub
)->a_trsize
;
5277 drsize
+= exec_hdr (sub
)->a_drsize
;
5281 /* FIXME: We need to identify the .text and .data sections
5282 and call get_reloc_upper_bound and canonicalize_reloc to
5283 work out the number of relocs needed, and then multiply
5284 by the reloc size. */
5285 (*_bfd_error_handler
)
5286 (_("%s: relocatable link from %s to %s not supported"),
5287 bfd_get_filename (abfd
),
5288 sub
->xvec
->name
, abfd
->xvec
->name
);
5289 bfd_set_error (bfd_error_invalid_operation
);
5294 if (bfd_get_flavour (sub
) == bfd_target_aout_flavour
)
5296 sz
= obj_textsec (sub
)->size
;
5297 if (sz
> max_contents_size
)
5298 max_contents_size
= sz
;
5299 sz
= obj_datasec (sub
)->size
;
5300 if (sz
> max_contents_size
)
5301 max_contents_size
= sz
;
5303 sz
= exec_hdr (sub
)->a_trsize
;
5304 if (sz
> max_relocs_size
)
5305 max_relocs_size
= sz
;
5306 sz
= exec_hdr (sub
)->a_drsize
;
5307 if (sz
> max_relocs_size
)
5308 max_relocs_size
= sz
;
5310 sz
= obj_aout_external_sym_count (sub
);
5311 if (sz
> max_sym_count
)
5316 if (info
->relocatable
)
5318 if (obj_textsec (abfd
) != NULL
)
5319 trsize
+= (_bfd_count_link_order_relocs (obj_textsec (abfd
)
5320 ->map_head
.link_order
)
5321 * obj_reloc_entry_size (abfd
));
5322 if (obj_datasec (abfd
) != NULL
)
5323 drsize
+= (_bfd_count_link_order_relocs (obj_datasec (abfd
)
5324 ->map_head
.link_order
)
5325 * obj_reloc_entry_size (abfd
));
5328 exec_hdr (abfd
)->a_trsize
= trsize
;
5329 exec_hdr (abfd
)->a_drsize
= drsize
;
5331 exec_hdr (abfd
)->a_entry
= bfd_get_start_address (abfd
);
5333 /* Adjust the section sizes and vmas according to the magic number.
5334 This sets a_text, a_data and a_bss in the exec_hdr and sets the
5335 filepos for each section. */
5336 if (! NAME (aout
, adjust_sizes_and_vmas
) (abfd
, &text_size
, &text_end
))
5339 /* The relocation and symbol file positions differ among a.out
5340 targets. We are passed a callback routine from the backend
5341 specific code to handle this.
5342 FIXME: At this point we do not know how much space the symbol
5343 table will require. This will not work for any (nonstandard)
5344 a.out target that needs to know the symbol table size before it
5345 can compute the relocation file positions. This may or may not
5346 be the case for the hp300hpux target, for example. */
5347 (*callback
) (abfd
, &aout_info
.treloff
, &aout_info
.dreloff
,
5349 obj_textsec (abfd
)->rel_filepos
= aout_info
.treloff
;
5350 obj_datasec (abfd
)->rel_filepos
= aout_info
.dreloff
;
5351 obj_sym_filepos (abfd
) = aout_info
.symoff
;
5353 /* We keep a count of the symbols as we output them. */
5354 obj_aout_external_sym_count (abfd
) = 0;
5356 /* We accumulate the string table as we write out the symbols. */
5357 aout_info
.strtab
= _bfd_stringtab_init ();
5358 if (aout_info
.strtab
== NULL
)
5361 /* Allocate buffers to hold section contents and relocs. */
5362 aout_info
.contents
= bfd_malloc (max_contents_size
);
5363 aout_info
.relocs
= bfd_malloc (max_relocs_size
);
5364 aout_info
.symbol_map
= bfd_malloc (max_sym_count
* sizeof (int *));
5365 aout_info
.output_syms
= bfd_malloc ((max_sym_count
+ 1)
5366 * sizeof (struct external_nlist
));
5367 if ((aout_info
.contents
== NULL
&& max_contents_size
!= 0)
5368 || (aout_info
.relocs
== NULL
&& max_relocs_size
!= 0)
5369 || (aout_info
.symbol_map
== NULL
&& max_sym_count
!= 0)
5370 || aout_info
.output_syms
== NULL
)
5373 /* If we have a symbol named __DYNAMIC, force it out now. This is
5374 required by SunOS. Doing this here rather than in sunos.c is a
5375 hack, but it's easier than exporting everything which would be
5378 struct aout_link_hash_entry
*h
;
5380 h
= aout_link_hash_lookup (aout_hash_table (info
), "__DYNAMIC",
5381 FALSE
, FALSE
, FALSE
);
5383 aout_link_write_other_symbol (h
, &aout_info
);
5386 /* The most time efficient way to do the link would be to read all
5387 the input object files into memory and then sort out the
5388 information into the output file. Unfortunately, that will
5389 probably use too much memory. Another method would be to step
5390 through everything that composes the text section and write it
5391 out, and then everything that composes the data section and write
5392 it out, and then write out the relocs, and then write out the
5393 symbols. Unfortunately, that requires reading stuff from each
5394 input file several times, and we will not be able to keep all the
5395 input files open simultaneously, and reopening them will be slow.
5397 What we do is basically process one input file at a time. We do
5398 everything we need to do with an input file once--copy over the
5399 section contents, handle the relocation information, and write
5400 out the symbols--and then we throw away the information we read
5401 from it. This approach requires a lot of lseeks of the output
5402 file, which is unfortunate but still faster than reopening a lot
5405 We use the output_has_begun field of the input BFDs to see
5406 whether we have already handled it. */
5407 for (sub
= info
->input_bfds
; sub
!= NULL
; sub
= sub
->link_next
)
5408 sub
->output_has_begun
= FALSE
;
5410 /* Mark all sections which are to be included in the link. This
5411 will normally be every section. We need to do this so that we
5412 can identify any sections which the linker has decided to not
5414 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
5416 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
5417 if (p
->type
== bfd_indirect_link_order
)
5418 p
->u
.indirect
.section
->linker_mark
= TRUE
;
5421 have_link_order_relocs
= FALSE
;
5422 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
5424 for (p
= o
->map_head
.link_order
;
5428 if (p
->type
== bfd_indirect_link_order
5429 && (bfd_get_flavour (p
->u
.indirect
.section
->owner
)
5430 == bfd_target_aout_flavour
))
5434 input_bfd
= p
->u
.indirect
.section
->owner
;
5435 if (! input_bfd
->output_has_begun
)
5437 if (! aout_link_input_bfd (&aout_info
, input_bfd
))
5439 input_bfd
->output_has_begun
= TRUE
;
5442 else if (p
->type
== bfd_section_reloc_link_order
5443 || p
->type
== bfd_symbol_reloc_link_order
)
5445 /* These are handled below. */
5446 have_link_order_relocs
= TRUE
;
5450 if (! _bfd_default_link_order (abfd
, info
, o
, p
))
5456 /* Write out any symbols that we have not already written out. */
5457 aout_link_hash_traverse (aout_hash_table (info
),
5458 aout_link_write_other_symbol
,
5459 (void *) &aout_info
);
5461 /* Now handle any relocs we were asked to create by the linker.
5462 These did not come from any input file. We must do these after
5463 we have written out all the symbols, so that we know the symbol
5465 if (have_link_order_relocs
)
5467 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
5469 for (p
= o
->map_head
.link_order
;
5473 if (p
->type
== bfd_section_reloc_link_order
5474 || p
->type
== bfd_symbol_reloc_link_order
)
5476 if (! aout_link_reloc_link_order (&aout_info
, o
, p
))
5483 if (aout_info
.contents
!= NULL
)
5485 free (aout_info
.contents
);
5486 aout_info
.contents
= NULL
;
5488 if (aout_info
.relocs
!= NULL
)
5490 free (aout_info
.relocs
);
5491 aout_info
.relocs
= NULL
;
5493 if (aout_info
.symbol_map
!= NULL
)
5495 free (aout_info
.symbol_map
);
5496 aout_info
.symbol_map
= NULL
;
5498 if (aout_info
.output_syms
!= NULL
)
5500 free (aout_info
.output_syms
);
5501 aout_info
.output_syms
= NULL
;
5503 if (includes_hash_initialized
)
5505 bfd_hash_table_free (&aout_info
.includes
.root
);
5506 includes_hash_initialized
= FALSE
;
5509 /* Finish up any dynamic linking we may be doing. */
5510 if (aout_backend_info (abfd
)->finish_dynamic_link
!= NULL
)
5512 if (! (*aout_backend_info (abfd
)->finish_dynamic_link
) (abfd
, info
))
5516 /* Update the header information. */
5517 abfd
->symcount
= obj_aout_external_sym_count (abfd
);
5518 exec_hdr (abfd
)->a_syms
= abfd
->symcount
* EXTERNAL_NLIST_SIZE
;
5519 obj_str_filepos (abfd
) = obj_sym_filepos (abfd
) + exec_hdr (abfd
)->a_syms
;
5520 obj_textsec (abfd
)->reloc_count
=
5521 exec_hdr (abfd
)->a_trsize
/ obj_reloc_entry_size (abfd
);
5522 obj_datasec (abfd
)->reloc_count
=
5523 exec_hdr (abfd
)->a_drsize
/ obj_reloc_entry_size (abfd
);
5525 /* Write out the string table, unless there are no symbols. */
5526 if (abfd
->symcount
> 0)
5528 if (bfd_seek (abfd
, obj_str_filepos (abfd
), SEEK_SET
) != 0
5529 || ! emit_stringtab (abfd
, aout_info
.strtab
))
5532 else if (obj_textsec (abfd
)->reloc_count
== 0
5533 && obj_datasec (abfd
)->reloc_count
== 0)
5539 pos
= obj_datasec (abfd
)->filepos
+ exec_hdr (abfd
)->a_data
- 1;
5540 if (bfd_seek (abfd
, pos
, SEEK_SET
) != 0
5541 || bfd_bwrite (&b
, (bfd_size_type
) 1, abfd
) != 1)
5548 if (aout_info
.contents
!= NULL
)
5549 free (aout_info
.contents
);
5550 if (aout_info
.relocs
!= NULL
)
5551 free (aout_info
.relocs
);
5552 if (aout_info
.symbol_map
!= NULL
)
5553 free (aout_info
.symbol_map
);
5554 if (aout_info
.output_syms
!= NULL
)
5555 free (aout_info
.output_syms
);
5556 if (includes_hash_initialized
)
5557 bfd_hash_table_free (&aout_info
.includes
.root
);