1 /* BFD semi-generic back-end for a.out binaries.
2 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2000,
4 Free Software Foundation, Inc.
5 Written by Cygnus Support.
7 This file is part of BFD, the Binary File Descriptor library.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
29 BFD supports a number of different flavours of a.out format,
30 though the major differences are only the sizes of the
31 structures on disk, and the shape of the relocation
34 The support is split into a basic support file @file{aoutx.h}
35 and other files which derive functions from the base. One
36 derivation file is @file{aoutf1.h} (for a.out flavour 1), and
37 adds to the basic a.out functions support for sun3, sun4, 386
38 and 29k a.out files, to create a target jump vector for a
41 This information is further split out into more specific files
42 for each machine, including @file{sunos.c} for sun3 and sun4,
43 @file{newsos3.c} for the Sony NEWS, and @file{demo64.c} for a
44 demonstration of a 64 bit a.out format.
46 The base file @file{aoutx.h} defines general mechanisms for
47 reading and writing records to and from disk and various
48 other methods which BFD requires. It is included by
49 @file{aout32.c} and @file{aout64.c} to form the names
50 <<aout_32_swap_exec_header_in>>, <<aout_64_swap_exec_header_in>>, etc.
52 As an example, this is what goes on to make the back end for a
53 sun4, from @file{aout32.c}:
55 | #define ARCH_SIZE 32
61 | aout_32_canonicalize_reloc
62 | aout_32_find_nearest_line
64 | aout_32_get_reloc_upper_bound
69 | #define TARGET_NAME "a.out-sunos-big"
70 | #define VECNAME sunos_big_vec
73 requires all the names from @file{aout32.c}, and produces the jump vector
77 The file @file{host-aout.c} is a special case. It is for a large set
78 of hosts that use ``more or less standard'' a.out files, and
79 for which cross-debugging is not interesting. It uses the
80 standard 32-bit a.out support routines, but determines the
81 file offsets and addresses of the text, data, and BSS
82 sections, the machine architecture and machine type, and the
83 entry point address, in a host-dependent manner. Once these
84 values have been determined, generic code is used to handle
87 When porting it to run on a new system, you must supply:
91 | HOST_MACHINE_ARCH (optional)
92 | HOST_MACHINE_MACHINE (optional)
93 | HOST_TEXT_START_ADDR
96 in the file @file{../include/sys/h-@var{XXX}.h} (for your host). These
97 values, plus the structures and macros defined in @file{a.out.h} on
98 your host system, will produce a BFD target that will access
99 ordinary a.out files on your host. To configure a new machine
100 to use @file{host-aout.c}, specify:
102 | TDEFAULTS = -DDEFAULT_VECTOR=host_aout_big_vec
103 | TDEPFILES= host-aout.o trad-core.o
105 in the @file{config/@var{XXX}.mt} file, and modify @file{configure.in}
107 @file{@var{XXX}.mt} file (by setting "<<bfd_target=XXX>>") when your
108 configuration is selected.
113 * Any BFD with D_PAGED set is ZMAGIC, and vice versa.
114 Doesn't matter what the setting of WP_TEXT is on output, but it'll
116 * Any BFD with D_PAGED clear and WP_TEXT set is NMAGIC.
117 * Any BFD with both flags clear is OMAGIC.
118 (Just want to make these explicit, so the conditions tested in this
119 file make sense if you're more familiar with a.out than with BFD.) */
121 #define KEEPIT udata.i
125 #include "safe-ctype.h"
130 #include "aout/aout64.h"
131 #include "aout/stab_gnu.h"
134 static boolean aout_get_external_symbols
PARAMS ((bfd
*));
135 static boolean translate_from_native_sym_flags
136 PARAMS ((bfd
*, aout_symbol_type
*));
137 static boolean translate_to_native_sym_flags
138 PARAMS ((bfd
*, asymbol
*, struct external_nlist
*));
139 static void adjust_o_magic
PARAMS ((bfd
*, struct internal_exec
*));
140 static void adjust_z_magic
PARAMS ((bfd
*, struct internal_exec
*));
141 static void adjust_n_magic
PARAMS ((bfd
*, struct internal_exec
*));
142 reloc_howto_type
* NAME(aout
,reloc_type_lookup
)
143 PARAMS ((bfd
*, bfd_reloc_code_real_type
));
150 The file @file{aoutx.h} provides for both the @emph{standard}
151 and @emph{extended} forms of a.out relocation records.
153 The standard records contain only an
154 address, a symbol index, and a type field. The extended records
155 (used on 29ks and sparcs) also have a full integer for an
159 #ifndef CTOR_TABLE_RELOC_HOWTO
160 #define CTOR_TABLE_RELOC_IDX 2
161 #define CTOR_TABLE_RELOC_HOWTO(BFD) \
162 ((obj_reloc_entry_size (BFD) == RELOC_EXT_SIZE \
163 ? howto_table_ext : howto_table_std) \
164 + CTOR_TABLE_RELOC_IDX)
167 #ifndef MY_swap_std_reloc_in
168 #define MY_swap_std_reloc_in NAME(aout,swap_std_reloc_in)
171 #ifndef MY_swap_ext_reloc_in
172 #define MY_swap_ext_reloc_in NAME(aout,swap_ext_reloc_in)
175 #ifndef MY_swap_std_reloc_out
176 #define MY_swap_std_reloc_out NAME(aout,swap_std_reloc_out)
179 #ifndef MY_swap_ext_reloc_out
180 #define MY_swap_ext_reloc_out NAME(aout,swap_ext_reloc_out)
183 #ifndef MY_final_link_relocate
184 #define MY_final_link_relocate _bfd_final_link_relocate
187 #ifndef MY_relocate_contents
188 #define MY_relocate_contents _bfd_relocate_contents
191 #define howto_table_ext NAME(aout,ext_howto_table)
192 #define howto_table_std NAME(aout,std_howto_table)
194 reloc_howto_type howto_table_ext
[] =
196 /* type rs size bsz pcrel bitpos ovrf sf name part_inpl readmask setmask pcdone */
197 HOWTO(RELOC_8
, 0, 0, 8, false, 0, complain_overflow_bitfield
,0,"8", false, 0,0x000000ff, false),
198 HOWTO(RELOC_16
, 0, 1, 16, false, 0, complain_overflow_bitfield
,0,"16", false, 0,0x0000ffff, false),
199 HOWTO(RELOC_32
, 0, 2, 32, false, 0, complain_overflow_bitfield
,0,"32", false, 0,0xffffffff, false),
200 HOWTO(RELOC_DISP8
, 0, 0, 8, true, 0, complain_overflow_signed
,0,"DISP8", false, 0,0x000000ff, false),
201 HOWTO(RELOC_DISP16
, 0, 1, 16, true, 0, complain_overflow_signed
,0,"DISP16", false, 0,0x0000ffff, false),
202 HOWTO(RELOC_DISP32
, 0, 2, 32, true, 0, complain_overflow_signed
,0,"DISP32", false, 0,0xffffffff, false),
203 HOWTO(RELOC_WDISP30
,2, 2, 30, true, 0, complain_overflow_signed
,0,"WDISP30", false, 0,0x3fffffff, false),
204 HOWTO(RELOC_WDISP22
,2, 2, 22, true, 0, complain_overflow_signed
,0,"WDISP22", false, 0,0x003fffff, false),
205 HOWTO(RELOC_HI22
, 10, 2, 22, false, 0, complain_overflow_bitfield
,0,"HI22", false, 0,0x003fffff, false),
206 HOWTO(RELOC_22
, 0, 2, 22, false, 0, complain_overflow_bitfield
,0,"22", false, 0,0x003fffff, false),
207 HOWTO(RELOC_13
, 0, 2, 13, false, 0, complain_overflow_bitfield
,0,"13", false, 0,0x00001fff, false),
208 HOWTO(RELOC_LO10
, 0, 2, 10, false, 0, complain_overflow_dont
,0,"LO10", false, 0,0x000003ff, false),
209 HOWTO(RELOC_SFA_BASE
,0, 2, 32, false, 0, complain_overflow_bitfield
,0,"SFA_BASE", false, 0,0xffffffff, false),
210 HOWTO(RELOC_SFA_OFF13
,0,2, 32, false, 0, complain_overflow_bitfield
,0,"SFA_OFF13",false, 0,0xffffffff, false),
211 HOWTO(RELOC_BASE10
, 0, 2, 10, false, 0, complain_overflow_dont
,0,"BASE10", false, 0,0x000003ff, false),
212 HOWTO(RELOC_BASE13
, 0, 2, 13, false, 0, complain_overflow_signed
,0,"BASE13", false, 0,0x00001fff, false),
213 HOWTO(RELOC_BASE22
, 10, 2, 22, false, 0, complain_overflow_bitfield
,0,"BASE22", false, 0,0x003fffff, false),
214 HOWTO(RELOC_PC10
, 0, 2, 10, true, 0, complain_overflow_dont
,0,"PC10", false, 0,0x000003ff, true),
215 HOWTO(RELOC_PC22
, 10, 2, 22, true, 0, complain_overflow_signed
,0,"PC22", false, 0,0x003fffff, true),
216 HOWTO(RELOC_JMP_TBL
,2, 2, 30, true, 0, complain_overflow_signed
,0,"JMP_TBL", false, 0,0x3fffffff, false),
217 HOWTO(RELOC_SEGOFF16
,0, 2, 0, false, 0, complain_overflow_bitfield
,0,"SEGOFF16", false, 0,0x00000000, false),
218 HOWTO(RELOC_GLOB_DAT
,0, 2, 0, false, 0, complain_overflow_bitfield
,0,"GLOB_DAT", false, 0,0x00000000, false),
219 HOWTO(RELOC_JMP_SLOT
,0, 2, 0, false, 0, complain_overflow_bitfield
,0,"JMP_SLOT", false, 0,0x00000000, false),
220 HOWTO(RELOC_RELATIVE
,0, 2, 0, false, 0, complain_overflow_bitfield
,0,"RELATIVE", false, 0,0x00000000, false),
221 HOWTO(0, 0, 0, 0, false, 0, complain_overflow_dont
, 0, "R_SPARC_NONE", false,0,0x00000000,true),
222 HOWTO(0, 0, 0, 0, false, 0, complain_overflow_dont
, 0, "R_SPARC_NONE", false,0,0x00000000,true),
223 #define RELOC_SPARC_REV32 RELOC_WDISP19
224 HOWTO(RELOC_SPARC_REV32
, 0, 2, 32, false, 0, complain_overflow_dont
,0,"R_SPARC_REV32", false, 0,0xffffffff, false),
227 /* Convert standard reloc records to "arelent" format (incl byte swap). */
229 reloc_howto_type howto_table_std
[] = {
230 /* type rs size bsz pcrel bitpos ovrf sf name part_inpl readmask setmask pcdone */
231 HOWTO ( 0, 0, 0, 8, false, 0, complain_overflow_bitfield
,0,"8", true, 0x000000ff,0x000000ff, false),
232 HOWTO ( 1, 0, 1, 16, false, 0, complain_overflow_bitfield
,0,"16", true, 0x0000ffff,0x0000ffff, false),
233 HOWTO ( 2, 0, 2, 32, false, 0, complain_overflow_bitfield
,0,"32", true, 0xffffffff,0xffffffff, false),
234 HOWTO ( 3, 0, 4, 64, false, 0, complain_overflow_bitfield
,0,"64", true, 0xdeaddead,0xdeaddead, false),
235 HOWTO ( 4, 0, 0, 8, true, 0, complain_overflow_signed
, 0,"DISP8", true, 0x000000ff,0x000000ff, false),
236 HOWTO ( 5, 0, 1, 16, true, 0, complain_overflow_signed
, 0,"DISP16", true, 0x0000ffff,0x0000ffff, false),
237 HOWTO ( 6, 0, 2, 32, true, 0, complain_overflow_signed
, 0,"DISP32", true, 0xffffffff,0xffffffff, false),
238 HOWTO ( 7, 0, 4, 64, true, 0, complain_overflow_signed
, 0,"DISP64", true, 0xfeedface,0xfeedface, false),
239 HOWTO ( 8, 0, 2, 0, false, 0, complain_overflow_bitfield
,0,"GOT_REL", false, 0,0x00000000, false),
240 HOWTO ( 9, 0, 1, 16, false, 0, complain_overflow_bitfield
,0,"BASE16", false,0xffffffff,0xffffffff, false),
241 HOWTO (10, 0, 2, 32, false, 0, complain_overflow_bitfield
,0,"BASE32", false,0xffffffff,0xffffffff, false),
247 HOWTO (16, 0, 2, 0, false, 0, complain_overflow_bitfield
,0,"JMP_TABLE", false, 0,0x00000000, false),
263 HOWTO (32, 0, 2, 0, false, 0, complain_overflow_bitfield
,0,"RELATIVE", false, 0,0x00000000, false),
271 HOWTO (40, 0, 2, 0, false, 0, complain_overflow_bitfield
,0,"BASEREL", false, 0,0x00000000, false),
274 #define TABLE_SIZE(TABLE) (sizeof (TABLE) / sizeof (TABLE[0]))
277 NAME(aout
,reloc_type_lookup
) (abfd
,code
)
279 bfd_reloc_code_real_type code
;
281 #define EXT(i, j) case i: return &howto_table_ext[j]
282 #define STD(i, j) case i: return &howto_table_std[j]
283 int ext
= obj_reloc_entry_size (abfd
) == RELOC_EXT_SIZE
;
284 if (code
== BFD_RELOC_CTOR
)
285 switch (bfd_get_arch_info (abfd
)->bits_per_address
)
297 EXT (BFD_RELOC_8
, 0);
298 EXT (BFD_RELOC_16
, 1);
299 EXT (BFD_RELOC_32
, 2);
300 EXT (BFD_RELOC_HI22
, 8);
301 EXT (BFD_RELOC_LO10
, 11);
302 EXT (BFD_RELOC_32_PCREL_S2
, 6);
303 EXT (BFD_RELOC_SPARC_WDISP22
, 7);
304 EXT (BFD_RELOC_SPARC13
, 10);
305 EXT (BFD_RELOC_SPARC_GOT10
, 14);
306 EXT (BFD_RELOC_SPARC_BASE13
, 15);
307 EXT (BFD_RELOC_SPARC_GOT13
, 15);
308 EXT (BFD_RELOC_SPARC_GOT22
, 16);
309 EXT (BFD_RELOC_SPARC_PC10
, 17);
310 EXT (BFD_RELOC_SPARC_PC22
, 18);
311 EXT (BFD_RELOC_SPARC_WPLT30
, 19);
312 EXT (BFD_RELOC_SPARC_REV32
, 26);
313 default: return (reloc_howto_type
*) NULL
;
319 STD (BFD_RELOC_16
, 1);
320 STD (BFD_RELOC_32
, 2);
321 STD (BFD_RELOC_8_PCREL
, 4);
322 STD (BFD_RELOC_16_PCREL
, 5);
323 STD (BFD_RELOC_32_PCREL
, 6);
324 STD (BFD_RELOC_16_BASEREL
, 9);
325 STD (BFD_RELOC_32_BASEREL
, 10);
326 default: return (reloc_howto_type
*) NULL
;
332 Internal entry points
335 @file{aoutx.h} exports several routines for accessing the
336 contents of an a.out file, which are gathered and exported in
337 turn by various format specific files (eg sunos.c).
343 aout_@var{size}_swap_exec_header_in
346 void aout_@var{size}_swap_exec_header_in,
348 struct external_exec *raw_bytes,
349 struct internal_exec *execp);
352 Swap the information in an executable header @var{raw_bytes} taken
353 from a raw byte stream memory image into the internal exec header
354 structure @var{execp}.
357 #ifndef NAME_swap_exec_header_in
359 NAME(aout
,swap_exec_header_in
) (abfd
, raw_bytes
, execp
)
361 struct external_exec
*raw_bytes
;
362 struct internal_exec
*execp
;
364 struct external_exec
*bytes
= (struct external_exec
*)raw_bytes
;
366 /* The internal_exec structure has some fields that are unused in this
367 configuration (IE for i960), so ensure that all such uninitialized
368 fields are zero'd out. There are places where two of these structs
369 are memcmp'd, and thus the contents do matter. */
370 memset ((PTR
) execp
, 0, sizeof (struct internal_exec
));
371 /* Now fill in fields in the execp, from the bytes in the raw data. */
372 execp
->a_info
= H_GET_32 (abfd
, bytes
->e_info
);
373 execp
->a_text
= GET_WORD (abfd
, bytes
->e_text
);
374 execp
->a_data
= GET_WORD (abfd
, bytes
->e_data
);
375 execp
->a_bss
= GET_WORD (abfd
, bytes
->e_bss
);
376 execp
->a_syms
= GET_WORD (abfd
, bytes
->e_syms
);
377 execp
->a_entry
= GET_WORD (abfd
, bytes
->e_entry
);
378 execp
->a_trsize
= GET_WORD (abfd
, bytes
->e_trsize
);
379 execp
->a_drsize
= GET_WORD (abfd
, bytes
->e_drsize
);
381 #define NAME_swap_exec_header_in NAME(aout,swap_exec_header_in)
386 aout_@var{size}_swap_exec_header_out
389 void aout_@var{size}_swap_exec_header_out
391 struct internal_exec *execp,
392 struct external_exec *raw_bytes);
395 Swap the information in an internal exec header structure
396 @var{execp} into the buffer @var{raw_bytes} ready for writing to disk.
399 NAME(aout
,swap_exec_header_out
) (abfd
, execp
, raw_bytes
)
401 struct internal_exec
*execp
;
402 struct external_exec
*raw_bytes
;
404 struct external_exec
*bytes
= (struct external_exec
*)raw_bytes
;
406 /* Now fill in fields in the raw data, from the fields in the exec struct. */
407 H_PUT_32 (abfd
, execp
->a_info
, bytes
->e_info
);
408 PUT_WORD (abfd
, execp
->a_text
, bytes
->e_text
);
409 PUT_WORD (abfd
, execp
->a_data
, bytes
->e_data
);
410 PUT_WORD (abfd
, execp
->a_bss
, bytes
->e_bss
);
411 PUT_WORD (abfd
, execp
->a_syms
, bytes
->e_syms
);
412 PUT_WORD (abfd
, execp
->a_entry
, bytes
->e_entry
);
413 PUT_WORD (abfd
, execp
->a_trsize
, bytes
->e_trsize
);
414 PUT_WORD (abfd
, execp
->a_drsize
, bytes
->e_drsize
);
417 /* Make all the section for an a.out file. */
420 NAME(aout
,make_sections
) (abfd
)
423 if (obj_textsec (abfd
) == (asection
*) NULL
424 && bfd_make_section (abfd
, ".text") == (asection
*) NULL
)
426 if (obj_datasec (abfd
) == (asection
*) NULL
427 && bfd_make_section (abfd
, ".data") == (asection
*) NULL
)
429 if (obj_bsssec (abfd
) == (asection
*) NULL
430 && bfd_make_section (abfd
, ".bss") == (asection
*) NULL
)
437 aout_@var{size}_some_aout_object_p
440 const bfd_target *aout_@var{size}_some_aout_object_p
442 const bfd_target *(*callback_to_real_object_p) ());
445 Some a.out variant thinks that the file open in @var{abfd}
446 checking is an a.out file. Do some more checking, and set up
447 for access if it really is. Call back to the calling
448 environment's "finish up" function just before returning, to
449 handle any last-minute setup.
453 NAME(aout
,some_aout_object_p
) (abfd
, execp
, callback_to_real_object_p
)
455 struct internal_exec
*execp
;
456 const bfd_target
*(*callback_to_real_object_p
) PARAMS ((bfd
*));
458 struct aout_data_struct
*rawptr
, *oldrawptr
;
459 const bfd_target
*result
;
460 bfd_size_type amt
= sizeof (struct aout_data_struct
);
462 rawptr
= (struct aout_data_struct
*) bfd_zalloc (abfd
, amt
);
466 oldrawptr
= abfd
->tdata
.aout_data
;
467 abfd
->tdata
.aout_data
= rawptr
;
469 /* Copy the contents of the old tdata struct.
470 In particular, we want the subformat, since for hpux it was set in
471 hp300hpux.c:swap_exec_header_in and will be used in
472 hp300hpux.c:callback. */
473 if (oldrawptr
!= NULL
)
474 *abfd
->tdata
.aout_data
= *oldrawptr
;
476 abfd
->tdata
.aout_data
->a
.hdr
= &rawptr
->e
;
477 *(abfd
->tdata
.aout_data
->a
.hdr
) = *execp
; /* Copy in the internal_exec struct */
478 execp
= abfd
->tdata
.aout_data
->a
.hdr
;
480 /* Set the file flags */
481 abfd
->flags
= BFD_NO_FLAGS
;
482 if (execp
->a_drsize
|| execp
->a_trsize
)
483 abfd
->flags
|= HAS_RELOC
;
484 /* Setting of EXEC_P has been deferred to the bottom of this function */
486 abfd
->flags
|= HAS_LINENO
| HAS_DEBUG
| HAS_SYMS
| HAS_LOCALS
;
487 if (N_DYNAMIC (*execp
))
488 abfd
->flags
|= DYNAMIC
;
490 if (N_MAGIC (*execp
) == ZMAGIC
)
492 abfd
->flags
|= D_PAGED
| WP_TEXT
;
493 adata (abfd
).magic
= z_magic
;
495 else if (N_MAGIC (*execp
) == QMAGIC
)
497 abfd
->flags
|= D_PAGED
| WP_TEXT
;
498 adata (abfd
).magic
= z_magic
;
499 adata (abfd
).subformat
= q_magic_format
;
501 else if (N_MAGIC (*execp
) == NMAGIC
)
503 abfd
->flags
|= WP_TEXT
;
504 adata (abfd
).magic
= n_magic
;
506 else if (N_MAGIC (*execp
) == OMAGIC
507 || N_MAGIC (*execp
) == BMAGIC
)
508 adata (abfd
).magic
= o_magic
;
511 /* Should have been checked with N_BADMAG before this routine
516 bfd_get_start_address (abfd
) = execp
->a_entry
;
518 obj_aout_symbols (abfd
) = (aout_symbol_type
*)NULL
;
519 bfd_get_symcount (abfd
) = execp
->a_syms
/ sizeof (struct external_nlist
);
521 /* The default relocation entry size is that of traditional V7 Unix. */
522 obj_reloc_entry_size (abfd
) = RELOC_STD_SIZE
;
524 /* The default symbol entry size is that of traditional Unix. */
525 obj_symbol_entry_size (abfd
) = EXTERNAL_NLIST_SIZE
;
528 bfd_init_window (&obj_aout_sym_window (abfd
));
529 bfd_init_window (&obj_aout_string_window (abfd
));
531 obj_aout_external_syms (abfd
) = NULL
;
532 obj_aout_external_strings (abfd
) = NULL
;
533 obj_aout_sym_hashes (abfd
) = NULL
;
535 if (! NAME(aout
,make_sections
) (abfd
))
538 obj_datasec (abfd
)->_raw_size
= execp
->a_data
;
539 obj_bsssec (abfd
)->_raw_size
= execp
->a_bss
;
541 obj_textsec (abfd
)->flags
=
542 (execp
->a_trsize
!= 0
543 ? (SEC_ALLOC
| SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
| SEC_RELOC
)
544 : (SEC_ALLOC
| SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
));
545 obj_datasec (abfd
)->flags
=
546 (execp
->a_drsize
!= 0
547 ? (SEC_ALLOC
| SEC_LOAD
| SEC_DATA
| SEC_HAS_CONTENTS
| SEC_RELOC
)
548 : (SEC_ALLOC
| SEC_LOAD
| SEC_DATA
| SEC_HAS_CONTENTS
));
549 obj_bsssec (abfd
)->flags
= SEC_ALLOC
;
551 #ifdef THIS_IS_ONLY_DOCUMENTATION
552 /* The common code can't fill in these things because they depend
553 on either the start address of the text segment, the rounding
554 up of virtual addresses between segments, or the starting file
555 position of the text segment -- all of which varies among different
556 versions of a.out. */
558 /* Call back to the format-dependent code to fill in the rest of the
559 fields and do any further cleanup. Things that should be filled
560 in by the callback: */
562 struct exec
*execp
= exec_hdr (abfd
);
564 obj_textsec (abfd
)->size
= N_TXTSIZE (*execp
);
565 obj_textsec (abfd
)->raw_size
= N_TXTSIZE (*execp
);
566 /* data and bss are already filled in since they're so standard */
568 /* The virtual memory addresses of the sections */
569 obj_textsec (abfd
)->vma
= N_TXTADDR (*execp
);
570 obj_datasec (abfd
)->vma
= N_DATADDR (*execp
);
571 obj_bsssec (abfd
)->vma
= N_BSSADDR (*execp
);
573 /* The file offsets of the sections */
574 obj_textsec (abfd
)->filepos
= N_TXTOFF (*execp
);
575 obj_datasec (abfd
)->filepos
= N_DATOFF (*execp
);
577 /* The file offsets of the relocation info */
578 obj_textsec (abfd
)->rel_filepos
= N_TRELOFF (*execp
);
579 obj_datasec (abfd
)->rel_filepos
= N_DRELOFF (*execp
);
581 /* The file offsets of the string table and symbol table. */
582 obj_str_filepos (abfd
) = N_STROFF (*execp
);
583 obj_sym_filepos (abfd
) = N_SYMOFF (*execp
);
585 /* Determine the architecture and machine type of the object file. */
586 switch (N_MACHTYPE (*exec_hdr (abfd
)))
589 abfd
->obj_arch
= bfd_arch_obscure
;
593 adata (abfd
)->page_size
= TARGET_PAGE_SIZE
;
594 adata (abfd
)->segment_size
= SEGMENT_SIZE
;
595 adata (abfd
)->exec_bytes_size
= EXEC_BYTES_SIZE
;
599 /* The architecture is encoded in various ways in various a.out variants,
600 or is not encoded at all in some of them. The relocation size depends
601 on the architecture and the a.out variant. Finally, the return value
602 is the bfd_target vector in use. If an error occurs, return zero and
603 set bfd_error to the appropriate error code.
605 Formats such as b.out, which have additional fields in the a.out
606 header, should cope with them in this callback as well. */
607 #endif /* DOCUMENTATION */
609 result
= (*callback_to_real_object_p
) (abfd
);
611 /* Now that the segment addresses have been worked out, take a better
612 guess at whether the file is executable. If the entry point
613 is within the text segment, assume it is. (This makes files
614 executable even if their entry point address is 0, as long as
615 their text starts at zero.).
617 This test had to be changed to deal with systems where the text segment
618 runs at a different location than the default. The problem is that the
619 entry address can appear to be outside the text segment, thus causing an
620 erroneous conclusion that the file isn't executable.
622 To fix this, we now accept any non-zero entry point as an indication of
623 executability. This will work most of the time, since only the linker
624 sets the entry point, and that is likely to be non-zero for most systems. */
626 if (execp
->a_entry
!= 0
627 || (execp
->a_entry
>= obj_textsec (abfd
)->vma
628 && execp
->a_entry
< (obj_textsec (abfd
)->vma
629 + obj_textsec (abfd
)->_raw_size
)))
630 abfd
->flags
|= EXEC_P
;
634 struct stat stat_buf
;
636 /* The original heuristic doesn't work in some important cases.
637 The a.out file has no information about the text start
638 address. For files (like kernels) linked to non-standard
639 addresses (ld -Ttext nnn) the entry point may not be between
640 the default text start (obj_textsec(abfd)->vma) and
641 (obj_textsec(abfd)->vma) + text size. This is not just a mach
642 issue. Many kernels are loaded at non standard addresses. */
643 if (abfd
->iostream
!= NULL
644 && (abfd
->flags
& BFD_IN_MEMORY
) == 0
645 && (fstat (fileno ((FILE *) (abfd
->iostream
)), &stat_buf
) == 0)
646 && ((stat_buf
.st_mode
& 0111) != 0))
647 abfd
->flags
|= EXEC_P
;
649 #endif /* STAT_FOR_EXEC */
653 #if 0 /* These should be set correctly anyways. */
654 abfd
->sections
= obj_textsec (abfd
);
655 obj_textsec (abfd
)->next
= obj_datasec (abfd
);
656 obj_datasec (abfd
)->next
= obj_bsssec (abfd
);
662 abfd
->tdata
.aout_data
= oldrawptr
;
669 aout_@var{size}_mkobject
672 boolean aout_@var{size}_mkobject, (bfd *abfd);
675 Initialize BFD @var{abfd} for use with a.out files.
679 NAME(aout
,mkobject
) (abfd
)
682 struct aout_data_struct
*rawptr
;
683 bfd_size_type amt
= sizeof (struct aout_data_struct
);
685 bfd_set_error (bfd_error_system_call
);
687 rawptr
= (struct aout_data_struct
*) bfd_zalloc (abfd
, amt
);
691 abfd
->tdata
.aout_data
= rawptr
;
692 exec_hdr (abfd
) = &(rawptr
->e
);
694 obj_textsec (abfd
) = (asection
*) NULL
;
695 obj_datasec (abfd
) = (asection
*) NULL
;
696 obj_bsssec (abfd
) = (asection
*) NULL
;
703 aout_@var{size}_machine_type
706 enum machine_type aout_@var{size}_machine_type
707 (enum bfd_architecture arch,
708 unsigned long machine));
711 Keep track of machine architecture and machine type for
712 a.out's. Return the <<machine_type>> for a particular
713 architecture and machine, or <<M_UNKNOWN>> if that exact architecture
714 and machine can't be represented in a.out format.
716 If the architecture is understood, machine type 0 (default)
717 is always understood.
721 NAME(aout
,machine_type
) (arch
, machine
, unknown
)
722 enum bfd_architecture arch
;
723 unsigned long machine
;
726 enum machine_type arch_flags
;
728 arch_flags
= M_UNKNOWN
;
735 || machine
== bfd_mach_sparc
736 || machine
== bfd_mach_sparc_sparclite
737 || machine
== bfd_mach_sparc_sparclite_le
738 || machine
== bfd_mach_sparc_v9
)
739 arch_flags
= M_SPARC
;
740 else if (machine
== bfd_mach_sparc_sparclet
)
741 arch_flags
= M_SPARCLET
;
747 case 0: arch_flags
= M_68010
; break;
748 case bfd_mach_m68000
: arch_flags
= M_UNKNOWN
; *unknown
= false; break;
749 case bfd_mach_m68010
: arch_flags
= M_68010
; break;
750 case bfd_mach_m68020
: arch_flags
= M_68020
; break;
751 default: arch_flags
= M_UNKNOWN
; break;
774 case bfd_mach_mips3000
:
775 case bfd_mach_mips3900
:
776 arch_flags
= M_MIPS1
;
778 case bfd_mach_mips6000
:
779 arch_flags
= M_MIPS2
;
781 case bfd_mach_mips4000
:
782 case bfd_mach_mips4010
:
783 case bfd_mach_mips4100
:
784 case bfd_mach_mips4300
:
785 case bfd_mach_mips4400
:
786 case bfd_mach_mips4600
:
787 case bfd_mach_mips4650
:
788 case bfd_mach_mips8000
:
789 case bfd_mach_mips10000
:
790 case bfd_mach_mips12000
:
791 case bfd_mach_mips16
:
792 case bfd_mach_mipsisa32
:
794 case bfd_mach_mipsisa64
:
795 case bfd_mach_mips_sb1
:
796 /* FIXME: These should be MIPS3, MIPS4, MIPS16, MIPS32, etc. */
797 arch_flags
= M_MIPS2
;
800 arch_flags
= M_UNKNOWN
;
808 case 0: arch_flags
= M_NS32532
; break;
809 case 32032: arch_flags
= M_NS32032
; break;
810 case 32532: arch_flags
= M_NS32532
; break;
811 default: arch_flags
= M_UNKNOWN
; break;
820 if (machine
== 0 || machine
== 255)
825 arch_flags
= M_UNKNOWN
;
828 if (arch_flags
!= M_UNKNOWN
)
836 aout_@var{size}_set_arch_mach
839 boolean aout_@var{size}_set_arch_mach,
841 enum bfd_architecture arch,
842 unsigned long machine));
845 Set the architecture and the machine of the BFD @var{abfd} to the
846 values @var{arch} and @var{machine}. Verify that @var{abfd}'s format
847 can support the architecture required.
851 NAME(aout
,set_arch_mach
) (abfd
, arch
, machine
)
853 enum bfd_architecture arch
;
854 unsigned long machine
;
856 if (! bfd_default_set_arch_mach (abfd
, arch
, machine
))
859 if (arch
!= bfd_arch_unknown
)
863 NAME(aout
,machine_type
) (arch
, machine
, &unknown
);
868 /* Determine the size of a relocation entry */
874 obj_reloc_entry_size (abfd
) = RELOC_EXT_SIZE
;
877 obj_reloc_entry_size (abfd
) = RELOC_STD_SIZE
;
881 return (*aout_backend_info (abfd
)->set_sizes
) (abfd
);
885 adjust_o_magic (abfd
, execp
)
887 struct internal_exec
*execp
;
889 file_ptr pos
= adata (abfd
).exec_bytes_size
;
894 obj_textsec (abfd
)->filepos
= pos
;
895 if (!obj_textsec (abfd
)->user_set_vma
)
896 obj_textsec (abfd
)->vma
= vma
;
898 vma
= obj_textsec (abfd
)->vma
;
900 pos
+= obj_textsec (abfd
)->_raw_size
;
901 vma
+= obj_textsec (abfd
)->_raw_size
;
904 if (!obj_datasec (abfd
)->user_set_vma
)
906 #if 0 /* ?? Does alignment in the file image really matter? */
907 pad
= align_power (vma
, obj_datasec (abfd
)->alignment_power
) - vma
;
909 obj_textsec (abfd
)->_raw_size
+= pad
;
912 obj_datasec (abfd
)->vma
= vma
;
915 vma
= obj_datasec (abfd
)->vma
;
916 obj_datasec (abfd
)->filepos
= pos
;
917 pos
+= obj_datasec (abfd
)->_raw_size
;
918 vma
+= obj_datasec (abfd
)->_raw_size
;
921 if (!obj_bsssec (abfd
)->user_set_vma
)
924 pad
= align_power (vma
, obj_bsssec (abfd
)->alignment_power
) - vma
;
926 obj_datasec (abfd
)->_raw_size
+= pad
;
929 obj_bsssec (abfd
)->vma
= vma
;
933 /* The VMA of the .bss section is set by the VMA of the
934 .data section plus the size of the .data section. We may
935 need to add padding bytes to make this true. */
936 pad
= obj_bsssec (abfd
)->vma
- vma
;
939 obj_datasec (abfd
)->_raw_size
+= pad
;
943 obj_bsssec (abfd
)->filepos
= pos
;
945 /* Fix up the exec header. */
946 execp
->a_text
= obj_textsec (abfd
)->_raw_size
;
947 execp
->a_data
= obj_datasec (abfd
)->_raw_size
;
948 execp
->a_bss
= obj_bsssec (abfd
)->_raw_size
;
949 N_SET_MAGIC (*execp
, OMAGIC
);
953 adjust_z_magic (abfd
, execp
)
955 struct internal_exec
*execp
;
957 bfd_size_type data_pad
, text_pad
;
959 const struct aout_backend_data
*abdp
;
960 int ztih
; /* Nonzero if text includes exec header. */
962 abdp
= aout_backend_info (abfd
);
966 && (abdp
->text_includes_header
967 || obj_aout_subformat (abfd
) == q_magic_format
));
968 obj_textsec (abfd
)->filepos
= (ztih
969 ? adata (abfd
).exec_bytes_size
970 : adata (abfd
).zmagic_disk_block_size
);
971 if (! obj_textsec (abfd
)->user_set_vma
)
973 /* ?? Do we really need to check for relocs here? */
974 obj_textsec (abfd
)->vma
= ((abfd
->flags
& HAS_RELOC
)
977 ? (abdp
->default_text_vma
978 + adata (abfd
).exec_bytes_size
)
979 : abdp
->default_text_vma
));
984 /* The .text section is being loaded at an unusual address. We
985 may need to pad it such that the .data section starts at a page
988 text_pad
= ((obj_textsec (abfd
)->filepos
- obj_textsec (abfd
)->vma
)
989 & (adata (abfd
).page_size
- 1));
991 text_pad
= ((- obj_textsec (abfd
)->vma
)
992 & (adata (abfd
).page_size
- 1));
995 /* Find start of data. */
998 text_end
= obj_textsec (abfd
)->filepos
+ obj_textsec (abfd
)->_raw_size
;
999 text_pad
+= BFD_ALIGN (text_end
, adata (abfd
).page_size
) - text_end
;
1003 /* Note that if page_size == zmagic_disk_block_size, then
1004 filepos == page_size, and this case is the same as the ztih
1006 text_end
= obj_textsec (abfd
)->_raw_size
;
1007 text_pad
+= BFD_ALIGN (text_end
, adata (abfd
).page_size
) - text_end
;
1008 text_end
+= obj_textsec (abfd
)->filepos
;
1010 obj_textsec (abfd
)->_raw_size
+= text_pad
;
1011 text_end
+= text_pad
;
1014 if (!obj_datasec (abfd
)->user_set_vma
)
1017 vma
= obj_textsec (abfd
)->vma
+ obj_textsec (abfd
)->_raw_size
;
1018 obj_datasec (abfd
)->vma
= BFD_ALIGN (vma
, adata (abfd
).segment_size
);
1020 if (abdp
&& abdp
->zmagic_mapped_contiguous
)
1022 asection
* text
= obj_textsec (abfd
);
1023 asection
* data
= obj_datasec (abfd
);
1025 text_pad
= data
->vma
- (text
->vma
+ text
->_raw_size
);
1026 /* Only pad the text section if the data
1027 section is going to be placed after it. */
1029 text
->_raw_size
+= text_pad
;
1031 obj_datasec (abfd
)->filepos
= (obj_textsec (abfd
)->filepos
1032 + obj_textsec (abfd
)->_raw_size
);
1034 /* Fix up exec header while we're at it. */
1035 execp
->a_text
= obj_textsec (abfd
)->_raw_size
;
1036 if (ztih
&& (!abdp
|| (abdp
&& !abdp
->exec_header_not_counted
)))
1037 execp
->a_text
+= adata (abfd
).exec_bytes_size
;
1038 if (obj_aout_subformat (abfd
) == q_magic_format
)
1039 N_SET_MAGIC (*execp
, QMAGIC
);
1041 N_SET_MAGIC (*execp
, ZMAGIC
);
1043 /* Spec says data section should be rounded up to page boundary. */
1044 obj_datasec (abfd
)->_raw_size
1045 = align_power (obj_datasec (abfd
)->_raw_size
,
1046 obj_bsssec (abfd
)->alignment_power
);
1047 execp
->a_data
= BFD_ALIGN (obj_datasec (abfd
)->_raw_size
,
1048 adata (abfd
).page_size
);
1049 data_pad
= execp
->a_data
- obj_datasec (abfd
)->_raw_size
;
1052 if (!obj_bsssec (abfd
)->user_set_vma
)
1053 obj_bsssec (abfd
)->vma
= (obj_datasec (abfd
)->vma
1054 + obj_datasec (abfd
)->_raw_size
);
1055 /* If the BSS immediately follows the data section and extra space
1056 in the page is left after the data section, fudge data
1057 in the header so that the bss section looks smaller by that
1058 amount. We'll start the bss section there, and lie to the OS.
1059 (Note that a linker script, as well as the above assignment,
1060 could have explicitly set the BSS vma to immediately follow
1061 the data section.) */
1062 if (align_power (obj_bsssec (abfd
)->vma
, obj_bsssec (abfd
)->alignment_power
)
1063 == obj_datasec (abfd
)->vma
+ obj_datasec (abfd
)->_raw_size
)
1064 execp
->a_bss
= (data_pad
> obj_bsssec (abfd
)->_raw_size
1065 ? 0 : obj_bsssec (abfd
)->_raw_size
- data_pad
);
1067 execp
->a_bss
= obj_bsssec (abfd
)->_raw_size
;
1071 adjust_n_magic (abfd
, execp
)
1073 struct internal_exec
*execp
;
1075 file_ptr pos
= adata (abfd
).exec_bytes_size
;
1080 obj_textsec (abfd
)->filepos
= pos
;
1081 if (!obj_textsec (abfd
)->user_set_vma
)
1082 obj_textsec (abfd
)->vma
= vma
;
1084 vma
= obj_textsec (abfd
)->vma
;
1085 pos
+= obj_textsec (abfd
)->_raw_size
;
1086 vma
+= obj_textsec (abfd
)->_raw_size
;
1089 obj_datasec (abfd
)->filepos
= pos
;
1090 if (!obj_datasec (abfd
)->user_set_vma
)
1091 obj_datasec (abfd
)->vma
= BFD_ALIGN (vma
, adata (abfd
).segment_size
);
1092 vma
= obj_datasec (abfd
)->vma
;
1094 /* Since BSS follows data immediately, see if it needs alignment. */
1095 vma
+= obj_datasec (abfd
)->_raw_size
;
1096 pad
= align_power (vma
, obj_bsssec (abfd
)->alignment_power
) - vma
;
1097 obj_datasec (abfd
)->_raw_size
+= pad
;
1098 pos
+= obj_datasec (abfd
)->_raw_size
;
1101 if (!obj_bsssec (abfd
)->user_set_vma
)
1102 obj_bsssec (abfd
)->vma
= vma
;
1104 vma
= obj_bsssec (abfd
)->vma
;
1106 /* Fix up exec header. */
1107 execp
->a_text
= obj_textsec (abfd
)->_raw_size
;
1108 execp
->a_data
= obj_datasec (abfd
)->_raw_size
;
1109 execp
->a_bss
= obj_bsssec (abfd
)->_raw_size
;
1110 N_SET_MAGIC (*execp
, NMAGIC
);
1114 NAME(aout
,adjust_sizes_and_vmas
) (abfd
, text_size
, text_end
)
1116 bfd_size_type
*text_size
;
1117 file_ptr
*text_end ATTRIBUTE_UNUSED
;
1119 struct internal_exec
*execp
= exec_hdr (abfd
);
1121 if (! NAME(aout
,make_sections
) (abfd
))
1124 if (adata (abfd
).magic
!= undecided_magic
)
1127 obj_textsec (abfd
)->_raw_size
=
1128 align_power (obj_textsec (abfd
)->_raw_size
,
1129 obj_textsec (abfd
)->alignment_power
);
1131 *text_size
= obj_textsec (abfd
)->_raw_size
;
1132 /* Rule (heuristic) for when to pad to a new page. Note that there
1133 are (at least) two ways demand-paged (ZMAGIC) files have been
1134 handled. Most Berkeley-based systems start the text segment at
1135 (TARGET_PAGE_SIZE). However, newer versions of SUNOS start the text
1136 segment right after the exec header; the latter is counted in the
1137 text segment size, and is paged in by the kernel with the rest of
1140 /* This perhaps isn't the right way to do this, but made it simpler for me
1141 to understand enough to implement it. Better would probably be to go
1142 right from BFD flags to alignment/positioning characteristics. But the
1143 old code was sloppy enough about handling the flags, and had enough
1144 other magic, that it was a little hard for me to understand. I think
1145 I understand it better now, but I haven't time to do the cleanup this
1148 if (abfd
->flags
& D_PAGED
)
1149 /* Whether or not WP_TEXT is set -- let D_PAGED override. */
1150 adata (abfd
).magic
= z_magic
;
1151 else if (abfd
->flags
& WP_TEXT
)
1152 adata (abfd
).magic
= n_magic
;
1154 adata (abfd
).magic
= o_magic
;
1156 #ifdef BFD_AOUT_DEBUG /* requires gcc2 */
1158 fprintf (stderr
, "%s text=<%x,%x,%x> data=<%x,%x,%x> bss=<%x,%x,%x>\n",
1160 switch (adata (abfd
).magic
)
1162 case n_magic
: str
= "NMAGIC"; break;
1163 case o_magic
: str
= "OMAGIC"; break;
1164 case z_magic
: str
= "ZMAGIC"; break;
1169 obj_textsec (abfd
)->vma
, obj_textsec (abfd
)->_raw_size
,
1170 obj_textsec (abfd
)->alignment_power
,
1171 obj_datasec (abfd
)->vma
, obj_datasec (abfd
)->_raw_size
,
1172 obj_datasec (abfd
)->alignment_power
,
1173 obj_bsssec (abfd
)->vma
, obj_bsssec (abfd
)->_raw_size
,
1174 obj_bsssec (abfd
)->alignment_power
);
1178 switch (adata (abfd
).magic
)
1181 adjust_o_magic (abfd
, execp
);
1184 adjust_z_magic (abfd
, execp
);
1187 adjust_n_magic (abfd
, execp
);
1193 #ifdef BFD_AOUT_DEBUG
1194 fprintf (stderr
, " text=<%x,%x,%x> data=<%x,%x,%x> bss=<%x,%x>\n",
1195 obj_textsec (abfd
)->vma
, obj_textsec (abfd
)->_raw_size
,
1196 obj_textsec (abfd
)->filepos
,
1197 obj_datasec (abfd
)->vma
, obj_datasec (abfd
)->_raw_size
,
1198 obj_datasec (abfd
)->filepos
,
1199 obj_bsssec (abfd
)->vma
, obj_bsssec (abfd
)->_raw_size
);
1207 aout_@var{size}_new_section_hook
1210 boolean aout_@var{size}_new_section_hook,
1212 asection *newsect));
1215 Called by the BFD in response to a @code{bfd_make_section}
1219 NAME(aout
,new_section_hook
) (abfd
, newsect
)
1223 /* align to double at least */
1224 newsect
->alignment_power
= bfd_get_arch_info (abfd
)->section_align_power
;
1226 if (bfd_get_format (abfd
) == bfd_object
)
1228 if (obj_textsec (abfd
) == NULL
&& !strcmp (newsect
->name
, ".text"))
1230 obj_textsec (abfd
)= newsect
;
1231 newsect
->target_index
= N_TEXT
;
1235 if (obj_datasec (abfd
) == NULL
&& !strcmp (newsect
->name
, ".data"))
1237 obj_datasec (abfd
) = newsect
;
1238 newsect
->target_index
= N_DATA
;
1242 if (obj_bsssec (abfd
) == NULL
&& !strcmp (newsect
->name
, ".bss"))
1244 obj_bsssec (abfd
) = newsect
;
1245 newsect
->target_index
= N_BSS
;
1251 /* We allow more than three sections internally */
1256 NAME(aout
,set_section_contents
) (abfd
, section
, location
, offset
, count
)
1261 bfd_size_type count
;
1264 bfd_size_type text_size
;
1266 if (! abfd
->output_has_begun
)
1268 if (! NAME(aout
,adjust_sizes_and_vmas
) (abfd
, &text_size
, &text_end
))
1272 if (section
== obj_bsssec (abfd
))
1274 bfd_set_error (bfd_error_no_contents
);
1278 if (section
!= obj_textsec (abfd
)
1279 && section
!= obj_datasec (abfd
))
1281 (*_bfd_error_handler
)
1282 (_("%s: can not represent section `%s' in a.out object file format"),
1283 bfd_get_filename (abfd
), bfd_get_section_name (abfd
, section
));
1284 bfd_set_error (bfd_error_nonrepresentable_section
);
1290 if (bfd_seek (abfd
, section
->filepos
+ offset
, SEEK_SET
) != 0
1291 || bfd_bwrite (location
, count
, abfd
) != count
)
1298 /* Read the external symbols from an a.out file. */
1301 aout_get_external_symbols (abfd
)
1304 if (obj_aout_external_syms (abfd
) == (struct external_nlist
*) NULL
)
1306 bfd_size_type count
;
1307 struct external_nlist
*syms
;
1310 count
= exec_hdr (abfd
)->a_syms
/ EXTERNAL_NLIST_SIZE
;
1313 if (bfd_get_file_window (abfd
,
1314 obj_sym_filepos (abfd
), exec_hdr (abfd
)->a_syms
,
1315 &obj_aout_sym_window (abfd
), true) == false)
1317 syms
= (struct external_nlist
*) obj_aout_sym_window (abfd
).data
;
1319 /* We allocate using malloc to make the values easy to free
1320 later on. If we put them on the objalloc it might not be
1321 possible to free them. */
1322 syms
= ((struct external_nlist
*)
1323 bfd_malloc (count
* EXTERNAL_NLIST_SIZE
));
1324 if (syms
== (struct external_nlist
*) NULL
&& count
!= 0)
1327 amt
= exec_hdr (abfd
)->a_syms
;
1328 if (bfd_seek (abfd
, obj_sym_filepos (abfd
), SEEK_SET
) != 0
1329 || bfd_bread (syms
, amt
, abfd
) != amt
)
1336 obj_aout_external_syms (abfd
) = syms
;
1337 obj_aout_external_sym_count (abfd
) = count
;
1340 if (obj_aout_external_strings (abfd
) == NULL
1341 && exec_hdr (abfd
)->a_syms
!= 0)
1343 unsigned char string_chars
[BYTES_IN_WORD
];
1344 bfd_size_type stringsize
;
1346 bfd_size_type amt
= BYTES_IN_WORD
;
1348 /* Get the size of the strings. */
1349 if (bfd_seek (abfd
, obj_str_filepos (abfd
), SEEK_SET
) != 0
1350 || bfd_bread ((PTR
) string_chars
, amt
, abfd
) != amt
)
1352 stringsize
= GET_WORD (abfd
, string_chars
);
1355 if (bfd_get_file_window (abfd
, obj_str_filepos (abfd
), stringsize
,
1356 &obj_aout_string_window (abfd
), true) == false)
1358 strings
= (char *) obj_aout_string_window (abfd
).data
;
1360 strings
= (char *) bfd_malloc (stringsize
+ 1);
1361 if (strings
== NULL
)
1364 /* Skip space for the string count in the buffer for convenience
1365 when using indexes. */
1366 amt
= stringsize
- BYTES_IN_WORD
;
1367 if (bfd_bread (strings
+ BYTES_IN_WORD
, amt
, abfd
) != amt
)
1374 /* Ensure that a zero index yields an empty string. */
1377 strings
[stringsize
- 1] = 0;
1379 obj_aout_external_strings (abfd
) = strings
;
1380 obj_aout_external_string_size (abfd
) = stringsize
;
1386 /* Translate an a.out symbol into a BFD symbol. The desc, other, type
1387 and symbol->value fields of CACHE_PTR will be set from the a.out
1388 nlist structure. This function is responsible for setting
1389 symbol->flags and symbol->section, and adjusting symbol->value. */
1392 translate_from_native_sym_flags (abfd
, cache_ptr
)
1394 aout_symbol_type
*cache_ptr
;
1398 if ((cache_ptr
->type
& N_STAB
) != 0
1399 || cache_ptr
->type
== N_FN
)
1403 /* This is a debugging symbol. */
1405 cache_ptr
->symbol
.flags
= BSF_DEBUGGING
;
1407 /* Work out the symbol section. */
1408 switch (cache_ptr
->type
& N_TYPE
)
1412 sec
= obj_textsec (abfd
);
1415 sec
= obj_datasec (abfd
);
1418 sec
= obj_bsssec (abfd
);
1422 sec
= bfd_abs_section_ptr
;
1426 cache_ptr
->symbol
.section
= sec
;
1427 cache_ptr
->symbol
.value
-= sec
->vma
;
1432 /* Get the default visibility. This does not apply to all types, so
1433 we just hold it in a local variable to use if wanted. */
1434 if ((cache_ptr
->type
& N_EXT
) == 0)
1435 visible
= BSF_LOCAL
;
1437 visible
= BSF_GLOBAL
;
1439 switch (cache_ptr
->type
)
1442 case N_ABS
: case N_ABS
| N_EXT
:
1443 cache_ptr
->symbol
.section
= bfd_abs_section_ptr
;
1444 cache_ptr
->symbol
.flags
= visible
;
1447 case N_UNDF
| N_EXT
:
1448 if (cache_ptr
->symbol
.value
!= 0)
1450 /* This is a common symbol. */
1451 cache_ptr
->symbol
.flags
= BSF_GLOBAL
;
1452 cache_ptr
->symbol
.section
= bfd_com_section_ptr
;
1456 cache_ptr
->symbol
.flags
= 0;
1457 cache_ptr
->symbol
.section
= bfd_und_section_ptr
;
1461 case N_TEXT
: case N_TEXT
| N_EXT
:
1462 cache_ptr
->symbol
.section
= obj_textsec (abfd
);
1463 cache_ptr
->symbol
.value
-= cache_ptr
->symbol
.section
->vma
;
1464 cache_ptr
->symbol
.flags
= visible
;
1467 /* N_SETV symbols used to represent set vectors placed in the
1468 data section. They are no longer generated. Theoretically,
1469 it was possible to extract the entries and combine them with
1470 new ones, although I don't know if that was ever actually
1471 done. Unless that feature is restored, treat them as data
1473 case N_SETV
: case N_SETV
| N_EXT
:
1474 case N_DATA
: case N_DATA
| N_EXT
:
1475 cache_ptr
->symbol
.section
= obj_datasec (abfd
);
1476 cache_ptr
->symbol
.value
-= cache_ptr
->symbol
.section
->vma
;
1477 cache_ptr
->symbol
.flags
= visible
;
1480 case N_BSS
: case N_BSS
| N_EXT
:
1481 cache_ptr
->symbol
.section
= obj_bsssec (abfd
);
1482 cache_ptr
->symbol
.value
-= cache_ptr
->symbol
.section
->vma
;
1483 cache_ptr
->symbol
.flags
= visible
;
1486 case N_SETA
: case N_SETA
| N_EXT
:
1487 case N_SETT
: case N_SETT
| N_EXT
:
1488 case N_SETD
: case N_SETD
| N_EXT
:
1489 case N_SETB
: case N_SETB
| N_EXT
:
1491 /* This code is no longer needed. It used to be used to make
1492 the linker handle set symbols, but they are now handled in
1493 the add_symbols routine instead. */
1496 arelent_chain
*reloc
;
1497 asection
*into_section
;
1500 /* This is a set symbol. The name of the symbol is the name
1501 of the set (e.g., __CTOR_LIST__). The value of the symbol
1502 is the value to add to the set. We create a section with
1503 the same name as the symbol, and add a reloc to insert the
1504 appropriate value into the section.
1506 This action is actually obsolete; it used to make the
1507 linker do the right thing, but the linker no longer uses
1510 section
= bfd_get_section_by_name (abfd
, cache_ptr
->symbol
.name
);
1511 if (section
== NULL
)
1515 amt
= strlen (cache_ptr
->symbol
.name
) + 1;
1516 copy
= bfd_alloc (abfd
, amt
);
1520 strcpy (copy
, cache_ptr
->symbol
.name
);
1521 section
= bfd_make_section (abfd
, copy
);
1522 if (section
== NULL
)
1526 amt
= sizeof (arelent_chain
);
1527 reloc
= (arelent_chain
*) bfd_alloc (abfd
, amt
);
1531 /* Build a relocation entry for the constructor. */
1532 switch (cache_ptr
->type
& N_TYPE
)
1535 into_section
= bfd_abs_section_ptr
;
1536 cache_ptr
->type
= N_ABS
;
1539 into_section
= obj_textsec (abfd
);
1540 cache_ptr
->type
= N_TEXT
;
1543 into_section
= obj_datasec (abfd
);
1544 cache_ptr
->type
= N_DATA
;
1547 into_section
= obj_bsssec (abfd
);
1548 cache_ptr
->type
= N_BSS
;
1552 /* Build a relocation pointing into the constructor section
1553 pointing at the symbol in the set vector specified. */
1554 reloc
->relent
.addend
= cache_ptr
->symbol
.value
;
1555 cache_ptr
->symbol
.section
= into_section
;
1556 reloc
->relent
.sym_ptr_ptr
= into_section
->symbol_ptr_ptr
;
1558 /* We modify the symbol to belong to a section depending upon
1559 the name of the symbol, and add to the size of the section
1560 to contain a pointer to the symbol. Build a reloc entry to
1561 relocate to this symbol attached to this section. */
1562 section
->flags
= SEC_CONSTRUCTOR
| SEC_RELOC
;
1564 section
->reloc_count
++;
1565 section
->alignment_power
= 2;
1567 reloc
->next
= section
->constructor_chain
;
1568 section
->constructor_chain
= reloc
;
1569 reloc
->relent
.address
= section
->_raw_size
;
1570 section
->_raw_size
+= BYTES_IN_WORD
;
1572 reloc
->relent
.howto
= CTOR_TABLE_RELOC_HOWTO (abfd
);
1576 switch (cache_ptr
->type
& N_TYPE
)
1579 cache_ptr
->symbol
.section
= bfd_abs_section_ptr
;
1582 cache_ptr
->symbol
.section
= obj_textsec (abfd
);
1585 cache_ptr
->symbol
.section
= obj_datasec (abfd
);
1588 cache_ptr
->symbol
.section
= obj_bsssec (abfd
);
1592 cache_ptr
->symbol
.flags
|= BSF_CONSTRUCTOR
;
1597 /* This symbol is the text of a warning message. The next
1598 symbol is the symbol to associate the warning with. If a
1599 reference is made to that symbol, a warning is issued. */
1600 cache_ptr
->symbol
.flags
= BSF_DEBUGGING
| BSF_WARNING
;
1601 cache_ptr
->symbol
.section
= bfd_abs_section_ptr
;
1604 case N_INDR
: case N_INDR
| N_EXT
:
1605 /* An indirect symbol. This consists of two symbols in a row.
1606 The first symbol is the name of the indirection. The second
1607 symbol is the name of the target. A reference to the first
1608 symbol becomes a reference to the second. */
1609 cache_ptr
->symbol
.flags
= BSF_DEBUGGING
| BSF_INDIRECT
| visible
;
1610 cache_ptr
->symbol
.section
= bfd_ind_section_ptr
;
1614 cache_ptr
->symbol
.section
= bfd_und_section_ptr
;
1615 cache_ptr
->symbol
.flags
= BSF_WEAK
;
1619 cache_ptr
->symbol
.section
= bfd_abs_section_ptr
;
1620 cache_ptr
->symbol
.flags
= BSF_WEAK
;
1624 cache_ptr
->symbol
.section
= obj_textsec (abfd
);
1625 cache_ptr
->symbol
.value
-= cache_ptr
->symbol
.section
->vma
;
1626 cache_ptr
->symbol
.flags
= BSF_WEAK
;
1630 cache_ptr
->symbol
.section
= obj_datasec (abfd
);
1631 cache_ptr
->symbol
.value
-= cache_ptr
->symbol
.section
->vma
;
1632 cache_ptr
->symbol
.flags
= BSF_WEAK
;
1636 cache_ptr
->symbol
.section
= obj_bsssec (abfd
);
1637 cache_ptr
->symbol
.value
-= cache_ptr
->symbol
.section
->vma
;
1638 cache_ptr
->symbol
.flags
= BSF_WEAK
;
1645 /* Set the fields of SYM_POINTER according to CACHE_PTR. */
1648 translate_to_native_sym_flags (abfd
, cache_ptr
, sym_pointer
)
1651 struct external_nlist
*sym_pointer
;
1653 bfd_vma value
= cache_ptr
->value
;
1657 /* Mask out any existing type bits in case copying from one section
1659 sym_pointer
->e_type
[0] &= ~N_TYPE
;
1661 sec
= bfd_get_section (cache_ptr
);
1666 /* This case occurs, e.g., for the *DEBUG* section of a COFF
1668 (*_bfd_error_handler
)
1669 (_("%s: can not represent section for symbol `%s' in a.out object file format"),
1670 bfd_get_filename (abfd
),
1671 cache_ptr
->name
!= NULL
? cache_ptr
->name
: _("*unknown*"));
1672 bfd_set_error (bfd_error_nonrepresentable_section
);
1676 if (sec
->output_section
!= NULL
)
1678 off
= sec
->output_offset
;
1679 sec
= sec
->output_section
;
1682 if (bfd_is_abs_section (sec
))
1683 sym_pointer
->e_type
[0] |= N_ABS
;
1684 else if (sec
== obj_textsec (abfd
))
1685 sym_pointer
->e_type
[0] |= N_TEXT
;
1686 else if (sec
== obj_datasec (abfd
))
1687 sym_pointer
->e_type
[0] |= N_DATA
;
1688 else if (sec
== obj_bsssec (abfd
))
1689 sym_pointer
->e_type
[0] |= N_BSS
;
1690 else if (bfd_is_und_section (sec
))
1691 sym_pointer
->e_type
[0] = N_UNDF
| N_EXT
;
1692 else if (bfd_is_ind_section (sec
))
1693 sym_pointer
->e_type
[0] = N_INDR
;
1694 else if (bfd_is_com_section (sec
))
1695 sym_pointer
->e_type
[0] = N_UNDF
| N_EXT
;
1698 (*_bfd_error_handler
)
1699 (_("%s: can not represent section `%s' in a.out object file format"),
1700 bfd_get_filename (abfd
), bfd_get_section_name (abfd
, sec
));
1701 bfd_set_error (bfd_error_nonrepresentable_section
);
1705 /* Turn the symbol from section relative to absolute again */
1706 value
+= sec
->vma
+ off
;
1708 if ((cache_ptr
->flags
& BSF_WARNING
) != 0)
1709 sym_pointer
->e_type
[0] = N_WARNING
;
1711 if ((cache_ptr
->flags
& BSF_DEBUGGING
) != 0)
1712 sym_pointer
->e_type
[0] = ((aout_symbol_type
*) cache_ptr
)->type
;
1713 else if ((cache_ptr
->flags
& BSF_GLOBAL
) != 0)
1714 sym_pointer
->e_type
[0] |= N_EXT
;
1715 else if ((cache_ptr
->flags
& BSF_LOCAL
) != 0)
1716 sym_pointer
->e_type
[0] &= ~N_EXT
;
1718 if ((cache_ptr
->flags
& BSF_CONSTRUCTOR
) != 0)
1720 int type
= ((aout_symbol_type
*) cache_ptr
)->type
;
1723 case N_ABS
: type
= N_SETA
; break;
1724 case N_TEXT
: type
= N_SETT
; break;
1725 case N_DATA
: type
= N_SETD
; break;
1726 case N_BSS
: type
= N_SETB
; break;
1728 sym_pointer
->e_type
[0] = type
;
1731 if ((cache_ptr
->flags
& BSF_WEAK
) != 0)
1735 switch (sym_pointer
->e_type
[0] & N_TYPE
)
1738 case N_ABS
: type
= N_WEAKA
; break;
1739 case N_TEXT
: type
= N_WEAKT
; break;
1740 case N_DATA
: type
= N_WEAKD
; break;
1741 case N_BSS
: type
= N_WEAKB
; break;
1742 case N_UNDF
: type
= N_WEAKU
; break;
1744 sym_pointer
->e_type
[0] = type
;
1747 PUT_WORD (abfd
, value
, sym_pointer
->e_value
);
1752 /* Native-level interface to symbols. */
1755 NAME(aout
,make_empty_symbol
) (abfd
)
1758 bfd_size_type amt
= sizeof (aout_symbol_type
);
1759 aout_symbol_type
*new = (aout_symbol_type
*) bfd_zalloc (abfd
, amt
);
1762 new->symbol
.the_bfd
= abfd
;
1764 return &new->symbol
;
1767 /* Translate a set of internal symbols into external symbols. */
1770 NAME(aout
,translate_symbol_table
) (abfd
, in
, ext
, count
, str
, strsize
, dynamic
)
1772 aout_symbol_type
*in
;
1773 struct external_nlist
*ext
;
1774 bfd_size_type count
;
1776 bfd_size_type strsize
;
1779 struct external_nlist
*ext_end
;
1781 ext_end
= ext
+ count
;
1782 for (; ext
< ext_end
; ext
++, in
++)
1786 x
= GET_WORD (abfd
, ext
->e_strx
);
1787 in
->symbol
.the_bfd
= abfd
;
1789 /* For the normal symbols, the zero index points at the number
1790 of bytes in the string table but is to be interpreted as the
1791 null string. For the dynamic symbols, the number of bytes in
1792 the string table is stored in the __DYNAMIC structure and the
1793 zero index points at an actual string. */
1794 if (x
== 0 && ! dynamic
)
1795 in
->symbol
.name
= "";
1796 else if (x
< strsize
)
1797 in
->symbol
.name
= str
+ x
;
1801 in
->symbol
.value
= GET_SWORD (abfd
, ext
->e_value
);
1802 in
->desc
= H_GET_16 (abfd
, ext
->e_desc
);
1803 in
->other
= H_GET_8 (abfd
, ext
->e_other
);
1804 in
->type
= H_GET_8 (abfd
, ext
->e_type
);
1805 in
->symbol
.udata
.p
= NULL
;
1807 if (! translate_from_native_sym_flags (abfd
, in
))
1811 in
->symbol
.flags
|= BSF_DYNAMIC
;
1817 /* We read the symbols into a buffer, which is discarded when this
1818 function exits. We read the strings into a buffer large enough to
1819 hold them all plus all the cached symbol entries. */
1822 NAME(aout
,slurp_symbol_table
) (abfd
)
1825 struct external_nlist
*old_external_syms
;
1826 aout_symbol_type
*cached
;
1827 bfd_size_type cached_size
;
1829 /* If there's no work to be done, don't do any */
1830 if (obj_aout_symbols (abfd
) != (aout_symbol_type
*) NULL
)
1833 old_external_syms
= obj_aout_external_syms (abfd
);
1835 if (! aout_get_external_symbols (abfd
))
1838 cached_size
= obj_aout_external_sym_count (abfd
);
1839 cached_size
*= sizeof (aout_symbol_type
);
1840 cached
= (aout_symbol_type
*) bfd_malloc (cached_size
);
1841 if (cached
== NULL
&& cached_size
!= 0)
1843 if (cached_size
!= 0)
1844 memset (cached
, 0, (size_t) cached_size
);
1846 /* Convert from external symbol information to internal. */
1847 if (! (NAME(aout
,translate_symbol_table
)
1849 obj_aout_external_syms (abfd
),
1850 obj_aout_external_sym_count (abfd
),
1851 obj_aout_external_strings (abfd
),
1852 obj_aout_external_string_size (abfd
),
1859 bfd_get_symcount (abfd
) = obj_aout_external_sym_count (abfd
);
1861 obj_aout_symbols (abfd
) = cached
;
1863 /* It is very likely that anybody who calls this function will not
1864 want the external symbol information, so if it was allocated
1865 because of our call to aout_get_external_symbols, we free it up
1866 right away to save space. */
1867 if (old_external_syms
== (struct external_nlist
*) NULL
1868 && obj_aout_external_syms (abfd
) != (struct external_nlist
*) NULL
)
1871 bfd_free_window (&obj_aout_sym_window (abfd
));
1873 free (obj_aout_external_syms (abfd
));
1875 obj_aout_external_syms (abfd
) = NULL
;
1881 /* We use a hash table when writing out symbols so that we only write
1882 out a particular string once. This helps particularly when the
1883 linker writes out stabs debugging entries, because each different
1884 contributing object file tends to have many duplicate stabs
1887 This hash table code breaks dbx on SunOS 4.1.3, so we don't do it
1888 if BFD_TRADITIONAL_FORMAT is set. */
1890 static bfd_size_type add_to_stringtab
1891 PARAMS ((bfd
*, struct bfd_strtab_hash
*, const char *, boolean
));
1892 static boolean emit_stringtab
PARAMS ((bfd
*, struct bfd_strtab_hash
*));
1894 /* Get the index of a string in a strtab, adding it if it is not
1897 static INLINE bfd_size_type
1898 add_to_stringtab (abfd
, tab
, str
, copy
)
1900 struct bfd_strtab_hash
*tab
;
1905 bfd_size_type index
;
1907 /* An index of 0 always means the empty string. */
1908 if (str
== 0 || *str
== '\0')
1911 /* Don't hash if BFD_TRADITIONAL_FORMAT is set, because SunOS dbx
1912 doesn't understand a hashed string table. */
1914 if ((abfd
->flags
& BFD_TRADITIONAL_FORMAT
) != 0)
1917 index
= _bfd_stringtab_add (tab
, str
, hash
, copy
);
1919 if (index
!= (bfd_size_type
) -1)
1921 /* Add BYTES_IN_WORD to the return value to account for the
1922 space taken up by the string table size. */
1923 index
+= BYTES_IN_WORD
;
1929 /* Write out a strtab. ABFD is already at the right location in the
1933 emit_stringtab (abfd
, tab
)
1935 struct bfd_strtab_hash
*tab
;
1937 bfd_byte buffer
[BYTES_IN_WORD
];
1938 bfd_size_type amt
= BYTES_IN_WORD
;
1940 /* The string table starts with the size. */
1941 PUT_WORD (abfd
, _bfd_stringtab_size (tab
) + BYTES_IN_WORD
, buffer
);
1942 if (bfd_bwrite ((PTR
) buffer
, amt
, abfd
) != amt
)
1945 return _bfd_stringtab_emit (abfd
, tab
);
1949 NAME(aout
,write_syms
) (abfd
)
1952 unsigned int count
;
1953 asymbol
**generic
= bfd_get_outsymbols (abfd
);
1954 struct bfd_strtab_hash
*strtab
;
1956 strtab
= _bfd_stringtab_init ();
1960 for (count
= 0; count
< bfd_get_symcount (abfd
); count
++)
1962 asymbol
*g
= generic
[count
];
1964 struct external_nlist nsp
;
1967 indx
= add_to_stringtab (abfd
, strtab
, g
->name
, false);
1968 if (indx
== (bfd_size_type
) -1)
1970 PUT_WORD (abfd
, indx
, (bfd_byte
*) nsp
.e_strx
);
1972 if (bfd_asymbol_flavour (g
) == abfd
->xvec
->flavour
)
1974 H_PUT_16 (abfd
, aout_symbol (g
)->desc
, nsp
.e_desc
);
1975 H_PUT_8 (abfd
, aout_symbol (g
)->other
, nsp
.e_other
);
1976 H_PUT_8 (abfd
, aout_symbol (g
)->type
, nsp
.e_type
);
1980 H_PUT_16 (abfd
, 0, nsp
.e_desc
);
1981 H_PUT_8 (abfd
, 0, nsp
.e_other
);
1982 H_PUT_8 (abfd
, 0, nsp
.e_type
);
1985 if (! translate_to_native_sym_flags (abfd
, g
, &nsp
))
1988 amt
= EXTERNAL_NLIST_SIZE
;
1989 if (bfd_bwrite ((PTR
) &nsp
, amt
, abfd
) != amt
)
1992 /* NB: `KEEPIT' currently overlays `udata.p', so set this only
1993 here, at the end. */
1997 if (! emit_stringtab (abfd
, strtab
))
2000 _bfd_stringtab_free (strtab
);
2005 _bfd_stringtab_free (strtab
);
2010 NAME(aout
,get_symtab
) (abfd
, location
)
2014 unsigned int counter
= 0;
2015 aout_symbol_type
*symbase
;
2017 if (!NAME(aout
,slurp_symbol_table
) (abfd
))
2020 for (symbase
= obj_aout_symbols (abfd
);
2021 counter
++ < bfd_get_symcount (abfd
);
2023 *(location
++) = (asymbol
*) (symbase
++);
2025 return bfd_get_symcount (abfd
);
2028 /* Standard reloc stuff */
2029 /* Output standard relocation information to a file in target byte order. */
2031 extern void NAME(aout
,swap_std_reloc_out
)
2032 PARAMS ((bfd
*, arelent
*, struct reloc_std_external
*));
2035 NAME(aout
,swap_std_reloc_out
) (abfd
, g
, natptr
)
2038 struct reloc_std_external
*natptr
;
2041 asymbol
*sym
= *(g
->sym_ptr_ptr
);
2043 unsigned int r_length
;
2045 int r_baserel
, r_jmptable
, r_relative
;
2046 asection
*output_section
= sym
->section
->output_section
;
2048 PUT_WORD (abfd
, g
->address
, natptr
->r_address
);
2050 r_length
= g
->howto
->size
; /* Size as a power of two */
2051 r_pcrel
= (int) g
->howto
->pc_relative
; /* Relative to PC? */
2052 /* XXX This relies on relocs coming from a.out files. */
2053 r_baserel
= (g
->howto
->type
& 8) != 0;
2054 r_jmptable
= (g
->howto
->type
& 16) != 0;
2055 r_relative
= (g
->howto
->type
& 32) != 0;
2058 /* For a standard reloc, the addend is in the object file. */
2059 r_addend
= g
->addend
+ (*(g
->sym_ptr_ptr
))->section
->output_section
->vma
;
2062 /* name was clobbered by aout_write_syms to be symbol index */
2064 /* If this relocation is relative to a symbol then set the
2065 r_index to the symbols index, and the r_extern bit.
2067 Absolute symbols can come in in two ways, either as an offset
2068 from the abs section, or as a symbol which has an abs value.
2072 if (bfd_is_com_section (output_section
)
2073 || bfd_is_abs_section (output_section
)
2074 || bfd_is_und_section (output_section
))
2076 if (bfd_abs_section_ptr
->symbol
== sym
)
2078 /* Whoops, looked like an abs symbol, but is really an offset
2079 from the abs section */
2085 /* Fill in symbol */
2087 r_index
= (*(g
->sym_ptr_ptr
))->KEEPIT
;
2093 /* Just an ordinary section */
2095 r_index
= output_section
->target_index
;
2098 /* now the fun stuff */
2099 if (bfd_header_big_endian (abfd
))
2101 natptr
->r_index
[0] = r_index
>> 16;
2102 natptr
->r_index
[1] = r_index
>> 8;
2103 natptr
->r_index
[2] = r_index
;
2104 natptr
->r_type
[0] = ((r_extern
? RELOC_STD_BITS_EXTERN_BIG
: 0)
2105 | (r_pcrel
? RELOC_STD_BITS_PCREL_BIG
: 0)
2106 | (r_baserel
? RELOC_STD_BITS_BASEREL_BIG
: 0)
2107 | (r_jmptable
? RELOC_STD_BITS_JMPTABLE_BIG
: 0)
2108 | (r_relative
? RELOC_STD_BITS_RELATIVE_BIG
: 0)
2109 | (r_length
<< RELOC_STD_BITS_LENGTH_SH_BIG
));
2113 natptr
->r_index
[2] = r_index
>> 16;
2114 natptr
->r_index
[1] = r_index
>> 8;
2115 natptr
->r_index
[0] = r_index
;
2116 natptr
->r_type
[0] = ((r_extern
? RELOC_STD_BITS_EXTERN_LITTLE
: 0)
2117 | (r_pcrel
? RELOC_STD_BITS_PCREL_LITTLE
: 0)
2118 | (r_baserel
? RELOC_STD_BITS_BASEREL_LITTLE
: 0)
2119 | (r_jmptable
? RELOC_STD_BITS_JMPTABLE_LITTLE
: 0)
2120 | (r_relative
? RELOC_STD_BITS_RELATIVE_LITTLE
: 0)
2121 | (r_length
<< RELOC_STD_BITS_LENGTH_SH_LITTLE
));
2125 /* Extended stuff */
2126 /* Output extended relocation information to a file in target byte order. */
2128 extern void NAME(aout
,swap_ext_reloc_out
)
2129 PARAMS ((bfd
*, arelent
*, struct reloc_ext_external
*));
2132 NAME(aout
,swap_ext_reloc_out
) (abfd
, g
, natptr
)
2135 register struct reloc_ext_external
*natptr
;
2139 unsigned int r_type
;
2141 asymbol
*sym
= *(g
->sym_ptr_ptr
);
2142 asection
*output_section
= sym
->section
->output_section
;
2144 PUT_WORD (abfd
, g
->address
, natptr
->r_address
);
2146 r_type
= (unsigned int) g
->howto
->type
;
2148 r_addend
= g
->addend
;
2149 if ((sym
->flags
& BSF_SECTION_SYM
) != 0)
2150 r_addend
+= (*(g
->sym_ptr_ptr
))->section
->output_section
->vma
;
2152 /* If this relocation is relative to a symbol then set the
2153 r_index to the symbols index, and the r_extern bit.
2155 Absolute symbols can come in in two ways, either as an offset
2156 from the abs section, or as a symbol which has an abs value.
2157 check for that here. */
2159 if (bfd_is_abs_section (bfd_get_section (sym
)))
2164 else if ((sym
->flags
& BSF_SECTION_SYM
) == 0)
2166 if (bfd_is_und_section (bfd_get_section (sym
))
2167 || (sym
->flags
& BSF_GLOBAL
) != 0)
2171 r_index
= (*(g
->sym_ptr_ptr
))->KEEPIT
;
2175 /* Just an ordinary section */
2177 r_index
= output_section
->target_index
;
2180 /* now the fun stuff */
2181 if (bfd_header_big_endian (abfd
))
2183 natptr
->r_index
[0] = r_index
>> 16;
2184 natptr
->r_index
[1] = r_index
>> 8;
2185 natptr
->r_index
[2] = r_index
;
2186 natptr
->r_type
[0] = ((r_extern
? RELOC_EXT_BITS_EXTERN_BIG
: 0)
2187 | (r_type
<< RELOC_EXT_BITS_TYPE_SH_BIG
));
2191 natptr
->r_index
[2] = r_index
>> 16;
2192 natptr
->r_index
[1] = r_index
>> 8;
2193 natptr
->r_index
[0] = r_index
;
2194 natptr
->r_type
[0] = ((r_extern
? RELOC_EXT_BITS_EXTERN_LITTLE
: 0)
2195 | (r_type
<< RELOC_EXT_BITS_TYPE_SH_LITTLE
));
2198 PUT_WORD (abfd
, r_addend
, natptr
->r_addend
);
2201 /* BFD deals internally with all things based from the section they're
2202 in. so, something in 10 bytes into a text section with a base of
2203 50 would have a symbol (.text+10) and know .text vma was 50.
2205 Aout keeps all it's symbols based from zero, so the symbol would
2206 contain 60. This macro subs the base of each section from the value
2207 to give the true offset from the section. */
2209 #define MOVE_ADDRESS(ad) \
2212 /* Undefined symbol. */ \
2213 cache_ptr->sym_ptr_ptr = symbols + r_index; \
2214 cache_ptr->addend = ad; \
2218 /* Defined, section relative. Replace symbol with pointer to \
2219 symbol which points to section. */ \
2223 case N_TEXT | N_EXT: \
2224 cache_ptr->sym_ptr_ptr = obj_textsec (abfd)->symbol_ptr_ptr; \
2225 cache_ptr->addend = ad - su->textsec->vma; \
2228 case N_DATA | N_EXT: \
2229 cache_ptr->sym_ptr_ptr = obj_datasec (abfd)->symbol_ptr_ptr; \
2230 cache_ptr->addend = ad - su->datasec->vma; \
2233 case N_BSS | N_EXT: \
2234 cache_ptr->sym_ptr_ptr = obj_bsssec (abfd)->symbol_ptr_ptr; \
2235 cache_ptr->addend = ad - su->bsssec->vma; \
2239 case N_ABS | N_EXT: \
2240 cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr; \
2241 cache_ptr->addend = ad; \
2247 NAME(aout
,swap_ext_reloc_in
) (abfd
, bytes
, cache_ptr
, symbols
, symcount
)
2249 struct reloc_ext_external
*bytes
;
2252 bfd_size_type symcount
;
2254 unsigned int r_index
;
2256 unsigned int r_type
;
2257 struct aoutdata
*su
= &(abfd
->tdata
.aout_data
->a
);
2259 cache_ptr
->address
= (GET_SWORD (abfd
, bytes
->r_address
));
2261 /* now the fun stuff */
2262 if (bfd_header_big_endian (abfd
))
2264 r_index
= ((bytes
->r_index
[0] << 16)
2265 | (bytes
->r_index
[1] << 8)
2266 | bytes
->r_index
[2]);
2267 r_extern
= (0 != (bytes
->r_type
[0] & RELOC_EXT_BITS_EXTERN_BIG
));
2268 r_type
= ((bytes
->r_type
[0] & RELOC_EXT_BITS_TYPE_BIG
)
2269 >> RELOC_EXT_BITS_TYPE_SH_BIG
);
2273 r_index
= ((bytes
->r_index
[2] << 16)
2274 | (bytes
->r_index
[1] << 8)
2275 | bytes
->r_index
[0]);
2276 r_extern
= (0 != (bytes
->r_type
[0] & RELOC_EXT_BITS_EXTERN_LITTLE
));
2277 r_type
= ((bytes
->r_type
[0] & RELOC_EXT_BITS_TYPE_LITTLE
)
2278 >> RELOC_EXT_BITS_TYPE_SH_LITTLE
);
2281 cache_ptr
->howto
= howto_table_ext
+ r_type
;
2283 /* Base relative relocs are always against the symbol table,
2284 regardless of the setting of r_extern. r_extern just reflects
2285 whether the symbol the reloc is against is local or global. */
2286 if (r_type
== RELOC_BASE10
2287 || r_type
== RELOC_BASE13
2288 || r_type
== RELOC_BASE22
)
2291 if (r_extern
&& r_index
> symcount
)
2293 /* We could arrange to return an error, but it might be useful
2294 to see the file even if it is bad. */
2299 MOVE_ADDRESS (GET_SWORD (abfd
, bytes
->r_addend
));
2303 NAME(aout
,swap_std_reloc_in
) (abfd
, bytes
, cache_ptr
, symbols
, symcount
)
2305 struct reloc_std_external
*bytes
;
2308 bfd_size_type symcount
;
2310 unsigned int r_index
;
2312 unsigned int r_length
;
2314 int r_baserel
, r_jmptable
, r_relative
;
2315 struct aoutdata
*su
= &(abfd
->tdata
.aout_data
->a
);
2316 unsigned int howto_idx
;
2318 cache_ptr
->address
= H_GET_32 (abfd
, bytes
->r_address
);
2320 /* now the fun stuff */
2321 if (bfd_header_big_endian (abfd
))
2323 r_index
= ((bytes
->r_index
[0] << 16)
2324 | (bytes
->r_index
[1] << 8)
2325 | bytes
->r_index
[2]);
2326 r_extern
= (0 != (bytes
->r_type
[0] & RELOC_STD_BITS_EXTERN_BIG
));
2327 r_pcrel
= (0 != (bytes
->r_type
[0] & RELOC_STD_BITS_PCREL_BIG
));
2328 r_baserel
= (0 != (bytes
->r_type
[0] & RELOC_STD_BITS_BASEREL_BIG
));
2329 r_jmptable
= (0 != (bytes
->r_type
[0] & RELOC_STD_BITS_JMPTABLE_BIG
));
2330 r_relative
= (0 != (bytes
->r_type
[0] & RELOC_STD_BITS_RELATIVE_BIG
));
2331 r_length
= ((bytes
->r_type
[0] & RELOC_STD_BITS_LENGTH_BIG
)
2332 >> RELOC_STD_BITS_LENGTH_SH_BIG
);
2336 r_index
= ((bytes
->r_index
[2] << 16)
2337 | (bytes
->r_index
[1] << 8)
2338 | bytes
->r_index
[0]);
2339 r_extern
= (0 != (bytes
->r_type
[0] & RELOC_STD_BITS_EXTERN_LITTLE
));
2340 r_pcrel
= (0 != (bytes
->r_type
[0] & RELOC_STD_BITS_PCREL_LITTLE
));
2341 r_baserel
= (0 != (bytes
->r_type
[0] & RELOC_STD_BITS_BASEREL_LITTLE
));
2342 r_jmptable
= (0 != (bytes
->r_type
[0] & RELOC_STD_BITS_JMPTABLE_LITTLE
));
2343 r_relative
= (0 != (bytes
->r_type
[0] & RELOC_STD_BITS_RELATIVE_LITTLE
));
2344 r_length
= ((bytes
->r_type
[0] & RELOC_STD_BITS_LENGTH_LITTLE
)
2345 >> RELOC_STD_BITS_LENGTH_SH_LITTLE
);
2348 howto_idx
= (r_length
+ 4 * r_pcrel
+ 8 * r_baserel
2349 + 16 * r_jmptable
+ 32 * r_relative
);
2350 BFD_ASSERT (howto_idx
< TABLE_SIZE (howto_table_std
));
2351 cache_ptr
->howto
= howto_table_std
+ howto_idx
;
2352 BFD_ASSERT (cache_ptr
->howto
->type
!= (unsigned int) -1);
2354 /* Base relative relocs are always against the symbol table,
2355 regardless of the setting of r_extern. r_extern just reflects
2356 whether the symbol the reloc is against is local or global. */
2360 if (r_extern
&& r_index
> symcount
)
2362 /* We could arrange to return an error, but it might be useful
2363 to see the file even if it is bad. */
2371 /* Read and swap the relocs for a section. */
2374 NAME(aout
,slurp_reloc_table
) (abfd
, asect
, symbols
)
2379 bfd_size_type count
;
2380 bfd_size_type reloc_size
;
2382 arelent
*reloc_cache
;
2384 unsigned int counter
= 0;
2388 if (asect
->relocation
)
2391 if (asect
->flags
& SEC_CONSTRUCTOR
)
2394 if (asect
== obj_datasec (abfd
))
2395 reloc_size
= exec_hdr (abfd
)->a_drsize
;
2396 else if (asect
== obj_textsec (abfd
))
2397 reloc_size
= exec_hdr (abfd
)->a_trsize
;
2398 else if (asect
== obj_bsssec (abfd
))
2402 bfd_set_error (bfd_error_invalid_operation
);
2406 if (bfd_seek (abfd
, asect
->rel_filepos
, SEEK_SET
) != 0)
2409 each_size
= obj_reloc_entry_size (abfd
);
2411 count
= reloc_size
/ each_size
;
2413 amt
= count
* sizeof (arelent
);
2414 reloc_cache
= (arelent
*) bfd_malloc (amt
);
2415 if (reloc_cache
== NULL
&& count
!= 0)
2417 memset (reloc_cache
, 0, (size_t) amt
);
2419 relocs
= bfd_malloc (reloc_size
);
2420 if (relocs
== NULL
&& reloc_size
!= 0)
2426 if (bfd_bread (relocs
, reloc_size
, abfd
) != reloc_size
)
2433 cache_ptr
= reloc_cache
;
2434 if (each_size
== RELOC_EXT_SIZE
)
2436 struct reloc_ext_external
*rptr
= (struct reloc_ext_external
*) relocs
;
2438 for (; counter
< count
; counter
++, rptr
++, cache_ptr
++)
2439 MY_swap_ext_reloc_in (abfd
, rptr
, cache_ptr
, symbols
,
2440 (bfd_size_type
) bfd_get_symcount (abfd
));
2444 struct reloc_std_external
*rptr
= (struct reloc_std_external
*) relocs
;
2446 for (; counter
< count
; counter
++, rptr
++, cache_ptr
++)
2447 MY_swap_std_reloc_in (abfd
, rptr
, cache_ptr
, symbols
,
2448 (bfd_size_type
) bfd_get_symcount (abfd
));
2453 asect
->relocation
= reloc_cache
;
2454 asect
->reloc_count
= cache_ptr
- reloc_cache
;
2459 /* Write out a relocation section into an object file. */
2462 NAME(aout
,squirt_out_relocs
) (abfd
, section
)
2467 unsigned char *native
, *natptr
;
2470 unsigned int count
= section
->reloc_count
;
2471 bfd_size_type natsize
;
2473 if (count
== 0 || section
->orelocation
== NULL
)
2476 each_size
= obj_reloc_entry_size (abfd
);
2477 natsize
= (bfd_size_type
) each_size
* count
;
2478 native
= (unsigned char *) bfd_zalloc (abfd
, natsize
);
2482 generic
= section
->orelocation
;
2484 if (each_size
== RELOC_EXT_SIZE
)
2486 for (natptr
= native
;
2488 --count
, natptr
+= each_size
, ++generic
)
2489 MY_swap_ext_reloc_out (abfd
, *generic
,
2490 (struct reloc_ext_external
*) natptr
);
2494 for (natptr
= native
;
2496 --count
, natptr
+= each_size
, ++generic
)
2497 MY_swap_std_reloc_out (abfd
, *generic
,
2498 (struct reloc_std_external
*) natptr
);
2501 if (bfd_bwrite ((PTR
) native
, natsize
, abfd
) != natsize
)
2503 bfd_release (abfd
, native
);
2506 bfd_release (abfd
, native
);
2511 /* This is stupid. This function should be a boolean predicate */
2513 NAME(aout
,canonicalize_reloc
) (abfd
, section
, relptr
, symbols
)
2519 arelent
*tblptr
= section
->relocation
;
2522 if (section
== obj_bsssec (abfd
))
2528 if (!(tblptr
|| NAME(aout
,slurp_reloc_table
) (abfd
, section
, symbols
)))
2531 if (section
->flags
& SEC_CONSTRUCTOR
)
2533 arelent_chain
*chain
= section
->constructor_chain
;
2534 for (count
= 0; count
< section
->reloc_count
; count
++)
2536 *relptr
++ = &chain
->relent
;
2537 chain
= chain
->next
;
2542 tblptr
= section
->relocation
;
2544 for (count
= 0; count
++ < section
->reloc_count
; )
2546 *relptr
++ = tblptr
++;
2551 return section
->reloc_count
;
2555 NAME(aout
,get_reloc_upper_bound
) (abfd
, asect
)
2559 if (bfd_get_format (abfd
) != bfd_object
)
2561 bfd_set_error (bfd_error_invalid_operation
);
2564 if (asect
->flags
& SEC_CONSTRUCTOR
)
2566 return (sizeof (arelent
*) * (asect
->reloc_count
+1));
2569 if (asect
== obj_datasec (abfd
))
2570 return (sizeof (arelent
*)
2571 * ((exec_hdr (abfd
)->a_drsize
/ obj_reloc_entry_size (abfd
))
2574 if (asect
== obj_textsec (abfd
))
2575 return (sizeof (arelent
*)
2576 * ((exec_hdr (abfd
)->a_trsize
/ obj_reloc_entry_size (abfd
))
2579 if (asect
== obj_bsssec (abfd
))
2580 return sizeof (arelent
*);
2582 if (asect
== obj_bsssec (abfd
))
2585 bfd_set_error (bfd_error_invalid_operation
);
2590 NAME(aout
,get_symtab_upper_bound
) (abfd
)
2593 if (!NAME(aout
,slurp_symbol_table
) (abfd
))
2596 return (bfd_get_symcount (abfd
)+1) * (sizeof (aout_symbol_type
*));
2600 NAME(aout
,get_lineno
) (ignore_abfd
, ignore_symbol
)
2601 bfd
*ignore_abfd ATTRIBUTE_UNUSED
;
2602 asymbol
*ignore_symbol ATTRIBUTE_UNUSED
;
2604 return (alent
*)NULL
;
2608 NAME(aout
,get_symbol_info
) (ignore_abfd
, symbol
, ret
)
2609 bfd
*ignore_abfd ATTRIBUTE_UNUSED
;
2613 bfd_symbol_info (symbol
, ret
);
2615 if (ret
->type
== '?')
2617 int type_code
= aout_symbol (symbol
)->type
& 0xff;
2618 const char *stab_name
= bfd_get_stab_name (type_code
);
2619 static char buf
[10];
2621 if (stab_name
== NULL
)
2623 sprintf (buf
, "(%d)", type_code
);
2627 ret
->stab_type
= type_code
;
2628 ret
->stab_other
= (unsigned) (aout_symbol (symbol
)->other
& 0xff);
2629 ret
->stab_desc
= (unsigned) (aout_symbol (symbol
)->desc
& 0xffff);
2630 ret
->stab_name
= stab_name
;
2635 NAME(aout
,print_symbol
) (abfd
, afile
, symbol
, how
)
2639 bfd_print_symbol_type how
;
2641 FILE *file
= (FILE *)afile
;
2645 case bfd_print_symbol_name
:
2647 fprintf (file
,"%s", symbol
->name
);
2649 case bfd_print_symbol_more
:
2650 fprintf (file
,"%4x %2x %2x",
2651 (unsigned) (aout_symbol (symbol
)->desc
& 0xffff),
2652 (unsigned) (aout_symbol (symbol
)->other
& 0xff),
2653 (unsigned) (aout_symbol (symbol
)->type
));
2655 case bfd_print_symbol_all
:
2657 const char *section_name
= symbol
->section
->name
;
2659 bfd_print_symbol_vandf (abfd
, (PTR
)file
, symbol
);
2661 fprintf (file
," %-5s %04x %02x %02x",
2663 (unsigned) (aout_symbol (symbol
)->desc
& 0xffff),
2664 (unsigned) (aout_symbol (symbol
)->other
& 0xff),
2665 (unsigned) (aout_symbol (symbol
)->type
& 0xff));
2667 fprintf (file
," %s", symbol
->name
);
2673 /* If we don't have to allocate more than 1MB to hold the generic
2674 symbols, we use the generic minisymbol methord: it's faster, since
2675 it only translates the symbols once, not multiple times. */
2676 #define MINISYM_THRESHOLD (1000000 / sizeof (asymbol))
2678 /* Read minisymbols. For minisymbols, we use the unmodified a.out
2679 symbols. The minisymbol_to_symbol function translates these into
2680 BFD asymbol structures. */
2683 NAME(aout
,read_minisymbols
) (abfd
, dynamic
, minisymsp
, sizep
)
2687 unsigned int *sizep
;
2691 /* We could handle the dynamic symbols here as well, but it's
2692 easier to hand them off. */
2693 return _bfd_generic_read_minisymbols (abfd
, dynamic
, minisymsp
, sizep
);
2696 if (! aout_get_external_symbols (abfd
))
2699 if (obj_aout_external_sym_count (abfd
) < MINISYM_THRESHOLD
)
2700 return _bfd_generic_read_minisymbols (abfd
, dynamic
, minisymsp
, sizep
);
2702 *minisymsp
= (PTR
) obj_aout_external_syms (abfd
);
2704 /* By passing the external symbols back from this routine, we are
2705 giving up control over the memory block. Clear
2706 obj_aout_external_syms, so that we do not try to free it
2708 obj_aout_external_syms (abfd
) = NULL
;
2710 *sizep
= EXTERNAL_NLIST_SIZE
;
2711 return obj_aout_external_sym_count (abfd
);
2714 /* Convert a minisymbol to a BFD asymbol. A minisymbol is just an
2715 unmodified a.out symbol. The SYM argument is a structure returned
2716 by bfd_make_empty_symbol, which we fill in here. */
2719 NAME(aout
,minisymbol_to_symbol
) (abfd
, dynamic
, minisym
, sym
)
2726 || obj_aout_external_sym_count (abfd
) < MINISYM_THRESHOLD
)
2727 return _bfd_generic_minisymbol_to_symbol (abfd
, dynamic
, minisym
, sym
);
2729 memset (sym
, 0, sizeof (aout_symbol_type
));
2731 /* We call translate_symbol_table to translate a single symbol. */
2732 if (! (NAME(aout
,translate_symbol_table
)
2734 (aout_symbol_type
*) sym
,
2735 (struct external_nlist
*) minisym
,
2737 obj_aout_external_strings (abfd
),
2738 obj_aout_external_string_size (abfd
),
2746 provided a BFD, a section and an offset into the section, calculate
2747 and return the name of the source file and the line nearest to the
2752 NAME(aout
,find_nearest_line
)
2753 (abfd
, section
, symbols
, offset
, filename_ptr
, functionname_ptr
, line_ptr
)
2758 const char **filename_ptr
;
2759 const char **functionname_ptr
;
2760 unsigned int *line_ptr
;
2762 /* Run down the file looking for the filename, function and linenumber */
2764 const char *directory_name
= NULL
;
2765 const char *main_file_name
= NULL
;
2766 const char *current_file_name
= NULL
;
2767 const char *line_file_name
= NULL
; /* Value of current_file_name at line number. */
2768 const char *line_directory_name
= NULL
; /* Value of directory_name at line number. */
2769 bfd_vma low_line_vma
= 0;
2770 bfd_vma low_func_vma
= 0;
2772 bfd_size_type filelen
, funclen
;
2775 *filename_ptr
= abfd
->filename
;
2776 *functionname_ptr
= 0;
2778 if (symbols
!= (asymbol
**)NULL
)
2780 for (p
= symbols
; *p
; p
++)
2782 aout_symbol_type
*q
= (aout_symbol_type
*) (*p
);
2787 /* If this looks like a file name symbol, and it comes after
2788 the line number we have found so far, but before the
2789 offset, then we have probably not found the right line
2791 if (q
->symbol
.value
<= offset
2792 && ((q
->symbol
.value
> low_line_vma
2793 && (line_file_name
!= NULL
2795 || (q
->symbol
.value
> low_func_vma
2798 const char *symname
;
2800 symname
= q
->symbol
.name
;
2801 if (strcmp (symname
+ strlen (symname
) - 2, ".o") == 0)
2803 if (q
->symbol
.value
> low_line_vma
)
2806 line_file_name
= NULL
;
2808 if (q
->symbol
.value
> low_func_vma
)
2815 /* If this symbol is less than the offset, but greater than
2816 the line number we have found so far, then we have not
2817 found the right line number. */
2818 if (q
->symbol
.value
<= offset
)
2820 if (q
->symbol
.value
> low_line_vma
)
2823 line_file_name
= NULL
;
2825 if (q
->symbol
.value
> low_func_vma
)
2829 main_file_name
= current_file_name
= q
->symbol
.name
;
2830 /* Look ahead to next symbol to check if that too is an N_SO. */
2834 q
= (aout_symbol_type
*) (*p
);
2835 if (q
->type
!= (int)N_SO
)
2838 /* Found a second N_SO First is directory; second is filename. */
2839 directory_name
= current_file_name
;
2840 main_file_name
= current_file_name
= q
->symbol
.name
;
2841 if (obj_textsec (abfd
) != section
)
2845 current_file_name
= q
->symbol
.name
;
2852 /* We'll keep this if it resolves nearer than the one we have
2854 if (q
->symbol
.value
>= low_line_vma
2855 && q
->symbol
.value
<= offset
)
2857 *line_ptr
= q
->desc
;
2858 low_line_vma
= q
->symbol
.value
;
2859 line_file_name
= current_file_name
;
2860 line_directory_name
= directory_name
;
2865 /* We'll keep this if it is nearer than the one we have already */
2866 if (q
->symbol
.value
>= low_func_vma
&&
2867 q
->symbol
.value
<= offset
) {
2868 low_func_vma
= q
->symbol
.value
;
2869 func
= (asymbol
*)q
;
2871 else if (q
->symbol
.value
> offset
)
2882 main_file_name
= line_file_name
;
2883 directory_name
= line_directory_name
;
2886 if (main_file_name
== NULL
2887 || IS_ABSOLUTE_PATH (main_file_name
)
2888 || directory_name
== NULL
)
2891 filelen
= strlen (directory_name
) + strlen (main_file_name
);
2895 funclen
= strlen (bfd_asymbol_name (func
));
2897 if (adata (abfd
).line_buf
!= NULL
)
2898 free (adata (abfd
).line_buf
);
2899 if (filelen
+ funclen
== 0)
2900 adata (abfd
).line_buf
= buf
= NULL
;
2903 buf
= (char *) bfd_malloc (filelen
+ funclen
+ 3);
2904 adata (abfd
).line_buf
= buf
;
2909 if (main_file_name
!= NULL
)
2911 if (IS_ABSOLUTE_PATH (main_file_name
) || directory_name
== NULL
)
2912 *filename_ptr
= main_file_name
;
2915 sprintf (buf
, "%s%s", directory_name
, main_file_name
);
2916 *filename_ptr
= buf
;
2923 const char *function
= func
->name
;
2926 /* The caller expects a symbol name. We actually have a
2927 function name, without the leading underscore. Put the
2928 underscore back in, so that the caller gets a symbol name. */
2929 if (bfd_get_symbol_leading_char (abfd
) == '\0')
2930 strcpy (buf
, function
);
2933 buf
[0] = bfd_get_symbol_leading_char (abfd
);
2934 strcpy (buf
+ 1, function
);
2936 /* Have to remove : stuff */
2937 colon
= strchr (buf
, ':');
2940 *functionname_ptr
= buf
;
2947 NAME(aout
,sizeof_headers
) (abfd
, execable
)
2949 boolean execable ATTRIBUTE_UNUSED
;
2951 return adata (abfd
).exec_bytes_size
;
2954 /* Free all information we have cached for this BFD. We can always
2955 read it again later if we need it. */
2958 NAME(aout
,bfd_free_cached_info
) (abfd
)
2963 if (bfd_get_format (abfd
) != bfd_object
2964 || abfd
->tdata
.aout_data
== NULL
)
2967 #define BFCI_FREE(x) if (x != NULL) { free (x); x = NULL; }
2968 BFCI_FREE (obj_aout_symbols (abfd
));
2970 obj_aout_external_syms (abfd
) = 0;
2971 bfd_free_window (&obj_aout_sym_window (abfd
));
2972 bfd_free_window (&obj_aout_string_window (abfd
));
2973 obj_aout_external_strings (abfd
) = 0;
2975 BFCI_FREE (obj_aout_external_syms (abfd
));
2976 BFCI_FREE (obj_aout_external_strings (abfd
));
2978 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
2979 BFCI_FREE (o
->relocation
);
2985 /* a.out link code. */
2987 static boolean aout_link_add_object_symbols
2988 PARAMS ((bfd
*, struct bfd_link_info
*));
2989 static boolean aout_link_check_archive_element
2990 PARAMS ((bfd
*, struct bfd_link_info
*, boolean
*));
2991 static boolean aout_link_free_symbols
PARAMS ((bfd
*));
2992 static boolean aout_link_check_ar_symbols
2993 PARAMS ((bfd
*, struct bfd_link_info
*, boolean
*pneeded
));
2994 static boolean aout_link_add_symbols
2995 PARAMS ((bfd
*, struct bfd_link_info
*));
2997 /* Routine to create an entry in an a.out link hash table. */
2999 struct bfd_hash_entry
*
3000 NAME(aout
,link_hash_newfunc
) (entry
, table
, string
)
3001 struct bfd_hash_entry
*entry
;
3002 struct bfd_hash_table
*table
;
3005 struct aout_link_hash_entry
*ret
= (struct aout_link_hash_entry
*) entry
;
3007 /* Allocate the structure if it has not already been allocated by a
3009 if (ret
== (struct aout_link_hash_entry
*) NULL
)
3010 ret
= ((struct aout_link_hash_entry
*)
3011 bfd_hash_allocate (table
, sizeof (struct aout_link_hash_entry
)));
3012 if (ret
== (struct aout_link_hash_entry
*) NULL
)
3013 return (struct bfd_hash_entry
*) ret
;
3015 /* Call the allocation method of the superclass. */
3016 ret
= ((struct aout_link_hash_entry
*)
3017 _bfd_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
3021 /* Set local fields. */
3022 ret
->written
= false;
3026 return (struct bfd_hash_entry
*) ret
;
3029 /* Initialize an a.out link hash table. */
3032 NAME(aout
,link_hash_table_init
) (table
, abfd
, newfunc
)
3033 struct aout_link_hash_table
*table
;
3035 struct bfd_hash_entry
*(*newfunc
) PARAMS ((struct bfd_hash_entry
*,
3036 struct bfd_hash_table
*,
3039 return _bfd_link_hash_table_init (&table
->root
, abfd
, newfunc
);
3042 /* Create an a.out link hash table. */
3044 struct bfd_link_hash_table
*
3045 NAME(aout
,link_hash_table_create
) (abfd
)
3048 struct aout_link_hash_table
*ret
;
3049 bfd_size_type amt
= sizeof (struct aout_link_hash_table
);
3051 ret
= (struct aout_link_hash_table
*) bfd_alloc (abfd
, amt
);
3053 return (struct bfd_link_hash_table
*) NULL
;
3054 if (! NAME(aout
,link_hash_table_init
) (ret
, abfd
,
3055 NAME(aout
,link_hash_newfunc
)))
3058 return (struct bfd_link_hash_table
*) NULL
;
3063 /* Given an a.out BFD, add symbols to the global hash table as
3067 NAME(aout
,link_add_symbols
) (abfd
, info
)
3069 struct bfd_link_info
*info
;
3071 switch (bfd_get_format (abfd
))
3074 return aout_link_add_object_symbols (abfd
, info
);
3076 return _bfd_generic_link_add_archive_symbols
3077 (abfd
, info
, aout_link_check_archive_element
);
3079 bfd_set_error (bfd_error_wrong_format
);
3084 /* Add symbols from an a.out object file. */
3087 aout_link_add_object_symbols (abfd
, info
)
3089 struct bfd_link_info
*info
;
3091 if (! aout_get_external_symbols (abfd
))
3093 if (! aout_link_add_symbols (abfd
, info
))
3095 if (! info
->keep_memory
)
3097 if (! aout_link_free_symbols (abfd
))
3103 /* Check a single archive element to see if we need to include it in
3104 the link. *PNEEDED is set according to whether this element is
3105 needed in the link or not. This is called from
3106 _bfd_generic_link_add_archive_symbols. */
3109 aout_link_check_archive_element (abfd
, info
, pneeded
)
3111 struct bfd_link_info
*info
;
3114 if (! aout_get_external_symbols (abfd
))
3117 if (! aout_link_check_ar_symbols (abfd
, info
, pneeded
))
3122 if (! aout_link_add_symbols (abfd
, info
))
3126 if (! info
->keep_memory
|| ! *pneeded
)
3128 if (! aout_link_free_symbols (abfd
))
3135 /* Free up the internal symbols read from an a.out file. */
3138 aout_link_free_symbols (abfd
)
3141 if (obj_aout_external_syms (abfd
) != (struct external_nlist
*) NULL
)
3144 bfd_free_window (&obj_aout_sym_window (abfd
));
3146 free ((PTR
) obj_aout_external_syms (abfd
));
3148 obj_aout_external_syms (abfd
) = (struct external_nlist
*) NULL
;
3150 if (obj_aout_external_strings (abfd
) != (char *) NULL
)
3153 bfd_free_window (&obj_aout_string_window (abfd
));
3155 free ((PTR
) obj_aout_external_strings (abfd
));
3157 obj_aout_external_strings (abfd
) = (char *) NULL
;
3162 /* Look through the internal symbols to see if this object file should
3163 be included in the link. We should include this object file if it
3164 defines any symbols which are currently undefined. If this object
3165 file defines a common symbol, then we may adjust the size of the
3166 known symbol but we do not include the object file in the link
3167 (unless there is some other reason to include it). */
3170 aout_link_check_ar_symbols (abfd
, info
, pneeded
)
3172 struct bfd_link_info
*info
;
3175 register struct external_nlist
*p
;
3176 struct external_nlist
*pend
;
3181 /* Look through all the symbols. */
3182 p
= obj_aout_external_syms (abfd
);
3183 pend
= p
+ obj_aout_external_sym_count (abfd
);
3184 strings
= obj_aout_external_strings (abfd
);
3185 for (; p
< pend
; p
++)
3187 int type
= H_GET_8 (abfd
, p
->e_type
);
3189 struct bfd_link_hash_entry
*h
;
3191 /* Ignore symbols that are not externally visible. This is an
3192 optimization only, as we check the type more thoroughly
3194 if (((type
& N_EXT
) == 0
3195 || (type
& N_STAB
) != 0
3202 if (type
== N_WARNING
3208 name
= strings
+ GET_WORD (abfd
, p
->e_strx
);
3209 h
= bfd_link_hash_lookup (info
->hash
, name
, false, false, true);
3211 /* We are only interested in symbols that are currently
3212 undefined or common. */
3213 if (h
== (struct bfd_link_hash_entry
*) NULL
3214 || (h
->type
!= bfd_link_hash_undefined
3215 && h
->type
!= bfd_link_hash_common
))
3217 if (type
== (N_INDR
| N_EXT
))
3222 if (type
== (N_TEXT
| N_EXT
)
3223 || type
== (N_DATA
| N_EXT
)
3224 || type
== (N_BSS
| N_EXT
)
3225 || type
== (N_ABS
| N_EXT
)
3226 || type
== (N_INDR
| N_EXT
))
3228 /* This object file defines this symbol. We must link it
3229 in. This is true regardless of whether the current
3230 definition of the symbol is undefined or common. If the
3231 current definition is common, we have a case in which we
3232 have already seen an object file including
3234 and this object file from the archive includes
3236 In such a case we must include this object file.
3238 FIXME: The SunOS 4.1.3 linker will pull in the archive
3239 element if the symbol is defined in the .data section,
3240 but not if it is defined in the .text section. That
3241 seems a bit crazy to me, and I haven't implemented it.
3242 However, it might be correct. */
3243 if (! (*info
->callbacks
->add_archive_element
) (info
, abfd
, name
))
3249 if (type
== (N_UNDF
| N_EXT
))
3253 value
= GET_WORD (abfd
, p
->e_value
);
3256 /* This symbol is common in the object from the archive
3258 if (h
->type
== bfd_link_hash_undefined
)
3263 symbfd
= h
->u
.undef
.abfd
;
3264 if (symbfd
== (bfd
*) NULL
)
3266 /* This symbol was created as undefined from
3267 outside BFD. We assume that we should link
3268 in the object file. This is done for the -u
3269 option in the linker. */
3270 if (! (*info
->callbacks
->add_archive_element
) (info
,
3277 /* Turn the current link symbol into a common
3278 symbol. It is already on the undefs list. */
3279 h
->type
= bfd_link_hash_common
;
3280 h
->u
.c
.p
= ((struct bfd_link_hash_common_entry
*)
3281 bfd_hash_allocate (&info
->hash
->table
,
3282 sizeof (struct bfd_link_hash_common_entry
)));
3283 if (h
->u
.c
.p
== NULL
)
3286 h
->u
.c
.size
= value
;
3288 /* FIXME: This isn't quite right. The maximum
3289 alignment of a common symbol should be set by the
3290 architecture of the output file, not of the input
3292 power
= bfd_log2 (value
);
3293 if (power
> bfd_get_arch_info (abfd
)->section_align_power
)
3294 power
= bfd_get_arch_info (abfd
)->section_align_power
;
3295 h
->u
.c
.p
->alignment_power
= power
;
3297 h
->u
.c
.p
->section
= bfd_make_section_old_way (symbfd
,
3302 /* Adjust the size of the common symbol if
3304 if (value
> h
->u
.c
.size
)
3305 h
->u
.c
.size
= value
;
3315 /* This symbol is weak but defined. We must pull it in if
3316 the current link symbol is undefined, but we don't want
3317 it if the current link symbol is common. */
3318 if (h
->type
== bfd_link_hash_undefined
)
3320 if (! (*info
->callbacks
->add_archive_element
) (info
, abfd
, name
))
3328 /* We do not need this object file. */
3332 /* Add all symbols from an object file to the hash table. */
3335 aout_link_add_symbols (abfd
, info
)
3337 struct bfd_link_info
*info
;
3339 boolean (*add_one_symbol
) PARAMS ((struct bfd_link_info
*, bfd
*,
3340 const char *, flagword
, asection
*,
3341 bfd_vma
, const char *, boolean
,
3343 struct bfd_link_hash_entry
**));
3344 struct external_nlist
*syms
;
3345 bfd_size_type sym_count
;
3348 struct aout_link_hash_entry
**sym_hash
;
3349 register struct external_nlist
*p
;
3350 struct external_nlist
*pend
;
3353 syms
= obj_aout_external_syms (abfd
);
3354 sym_count
= obj_aout_external_sym_count (abfd
);
3355 strings
= obj_aout_external_strings (abfd
);
3356 if (info
->keep_memory
)
3361 if (aout_backend_info (abfd
)->add_dynamic_symbols
!= NULL
)
3363 if (! ((*aout_backend_info (abfd
)->add_dynamic_symbols
)
3364 (abfd
, info
, &syms
, &sym_count
, &strings
)))
3368 /* We keep a list of the linker hash table entries that correspond
3369 to particular symbols. We could just look them up in the hash
3370 table, but keeping the list is more efficient. Perhaps this
3371 should be conditional on info->keep_memory. */
3372 amt
= sym_count
* sizeof (struct aout_link_hash_entry
*);
3373 sym_hash
= (struct aout_link_hash_entry
**) bfd_alloc (abfd
, amt
);
3374 if (sym_hash
== NULL
&& sym_count
!= 0)
3376 obj_aout_sym_hashes (abfd
) = sym_hash
;
3378 add_one_symbol
= aout_backend_info (abfd
)->add_one_symbol
;
3379 if (add_one_symbol
== NULL
)
3380 add_one_symbol
= _bfd_generic_link_add_one_symbol
;
3383 pend
= p
+ sym_count
;
3384 for (; p
< pend
; p
++, sym_hash
++)
3395 type
= H_GET_8 (abfd
, p
->e_type
);
3397 /* Ignore debugging symbols. */
3398 if ((type
& N_STAB
) != 0)
3401 name
= strings
+ GET_WORD (abfd
, p
->e_strx
);
3402 value
= GET_WORD (abfd
, p
->e_value
);
3419 /* Ignore symbols that are not externally visible. */
3422 /* Ignore local indirect symbol. */
3427 case N_UNDF
| N_EXT
:
3430 section
= bfd_und_section_ptr
;
3434 section
= bfd_com_section_ptr
;
3437 section
= bfd_abs_section_ptr
;
3439 case N_TEXT
| N_EXT
:
3440 section
= obj_textsec (abfd
);
3441 value
-= bfd_get_section_vma (abfd
, section
);
3443 case N_DATA
| N_EXT
:
3444 case N_SETV
| N_EXT
:
3445 /* Treat N_SETV symbols as N_DATA symbol; see comment in
3446 translate_from_native_sym_flags. */
3447 section
= obj_datasec (abfd
);
3448 value
-= bfd_get_section_vma (abfd
, section
);
3451 section
= obj_bsssec (abfd
);
3452 value
-= bfd_get_section_vma (abfd
, section
);
3454 case N_INDR
| N_EXT
:
3455 /* An indirect symbol. The next symbol is the symbol
3456 which this one really is. */
3457 BFD_ASSERT (p
+ 1 < pend
);
3459 string
= strings
+ GET_WORD (abfd
, p
->e_strx
);
3460 section
= bfd_ind_section_ptr
;
3461 flags
|= BSF_INDIRECT
;
3463 case N_COMM
| N_EXT
:
3464 section
= bfd_com_section_ptr
;
3466 case N_SETA
: case N_SETA
| N_EXT
:
3467 section
= bfd_abs_section_ptr
;
3468 flags
|= BSF_CONSTRUCTOR
;
3470 case N_SETT
: case N_SETT
| N_EXT
:
3471 section
= obj_textsec (abfd
);
3472 flags
|= BSF_CONSTRUCTOR
;
3473 value
-= bfd_get_section_vma (abfd
, section
);
3475 case N_SETD
: case N_SETD
| N_EXT
:
3476 section
= obj_datasec (abfd
);
3477 flags
|= BSF_CONSTRUCTOR
;
3478 value
-= bfd_get_section_vma (abfd
, section
);
3480 case N_SETB
: case N_SETB
| N_EXT
:
3481 section
= obj_bsssec (abfd
);
3482 flags
|= BSF_CONSTRUCTOR
;
3483 value
-= bfd_get_section_vma (abfd
, section
);
3486 /* A warning symbol. The next symbol is the one to warn
3488 BFD_ASSERT (p
+ 1 < pend
);
3491 name
= strings
+ GET_WORD (abfd
, p
->e_strx
);
3492 section
= bfd_und_section_ptr
;
3493 flags
|= BSF_WARNING
;
3496 section
= bfd_und_section_ptr
;
3500 section
= bfd_abs_section_ptr
;
3504 section
= obj_textsec (abfd
);
3505 value
-= bfd_get_section_vma (abfd
, section
);
3509 section
= obj_datasec (abfd
);
3510 value
-= bfd_get_section_vma (abfd
, section
);
3514 section
= obj_bsssec (abfd
);
3515 value
-= bfd_get_section_vma (abfd
, section
);
3520 if (! ((*add_one_symbol
)
3521 (info
, abfd
, name
, flags
, section
, value
, string
, copy
, false,
3522 (struct bfd_link_hash_entry
**) sym_hash
)))
3525 /* Restrict the maximum alignment of a common symbol based on
3526 the architecture, since a.out has no way to represent
3527 alignment requirements of a section in a .o file. FIXME:
3528 This isn't quite right: it should use the architecture of the
3529 output file, not the input files. */
3530 if ((*sym_hash
)->root
.type
== bfd_link_hash_common
3531 && ((*sym_hash
)->root
.u
.c
.p
->alignment_power
>
3532 bfd_get_arch_info (abfd
)->section_align_power
))
3533 (*sym_hash
)->root
.u
.c
.p
->alignment_power
=
3534 bfd_get_arch_info (abfd
)->section_align_power
;
3536 /* If this is a set symbol, and we are not building sets, then
3537 it is possible for the hash entry to not have been set. In
3538 such a case, treat the symbol as not globally defined. */
3539 if ((*sym_hash
)->root
.type
== bfd_link_hash_new
)
3541 BFD_ASSERT ((flags
& BSF_CONSTRUCTOR
) != 0);
3545 if (type
== (N_INDR
| N_EXT
) || type
== N_WARNING
)
3552 /* A hash table used for header files with N_BINCL entries. */
3554 struct aout_link_includes_table
3556 struct bfd_hash_table root
;
3559 /* A linked list of totals that we have found for a particular header
3562 struct aout_link_includes_totals
3564 struct aout_link_includes_totals
*next
;
3568 /* An entry in the header file hash table. */
3570 struct aout_link_includes_entry
3572 struct bfd_hash_entry root
;
3573 /* List of totals we have found for this file. */
3574 struct aout_link_includes_totals
*totals
;
3577 /* Look up an entry in an the header file hash table. */
3579 #define aout_link_includes_lookup(table, string, create, copy) \
3580 ((struct aout_link_includes_entry *) \
3581 bfd_hash_lookup (&(table)->root, (string), (create), (copy)))
3583 /* During the final link step we need to pass around a bunch of
3584 information, so we do it in an instance of this structure. */
3586 struct aout_final_link_info
3588 /* General link information. */
3589 struct bfd_link_info
*info
;
3592 /* Reloc file positions. */
3593 file_ptr treloff
, dreloff
;
3594 /* File position of symbols. */
3597 struct bfd_strtab_hash
*strtab
;
3598 /* Header file hash table. */
3599 struct aout_link_includes_table includes
;
3600 /* A buffer large enough to hold the contents of any section. */
3602 /* A buffer large enough to hold the relocs of any section. */
3604 /* A buffer large enough to hold the symbol map of any input BFD. */
3606 /* A buffer large enough to hold output symbols of any input BFD. */
3607 struct external_nlist
*output_syms
;
3610 static struct bfd_hash_entry
*aout_link_includes_newfunc
3611 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
3612 static boolean aout_link_input_bfd
3613 PARAMS ((struct aout_final_link_info
*, bfd
*input_bfd
));
3614 static boolean aout_link_write_symbols
3615 PARAMS ((struct aout_final_link_info
*, bfd
*input_bfd
));
3616 static boolean aout_link_write_other_symbol
3617 PARAMS ((struct aout_link_hash_entry
*, PTR
));
3618 static boolean aout_link_input_section
3619 PARAMS ((struct aout_final_link_info
*, bfd
*input_bfd
,
3620 asection
*input_section
, file_ptr
*reloff_ptr
,
3621 bfd_size_type rel_size
));
3622 static boolean aout_link_input_section_std
3623 PARAMS ((struct aout_final_link_info
*, bfd
*input_bfd
,
3624 asection
*input_section
, struct reloc_std_external
*,
3625 bfd_size_type rel_size
, bfd_byte
*contents
));
3626 static boolean aout_link_input_section_ext
3627 PARAMS ((struct aout_final_link_info
*, bfd
*input_bfd
,
3628 asection
*input_section
, struct reloc_ext_external
*,
3629 bfd_size_type rel_size
, bfd_byte
*contents
));
3630 static INLINE asection
*aout_reloc_index_to_section
3631 PARAMS ((bfd
*, int));
3632 static boolean aout_link_reloc_link_order
3633 PARAMS ((struct aout_final_link_info
*, asection
*,
3634 struct bfd_link_order
*));
3636 /* The function to create a new entry in the header file hash table. */
3638 static struct bfd_hash_entry
*
3639 aout_link_includes_newfunc (entry
, table
, string
)
3640 struct bfd_hash_entry
*entry
;
3641 struct bfd_hash_table
*table
;
3644 struct aout_link_includes_entry
*ret
=
3645 (struct aout_link_includes_entry
*) entry
;
3647 /* Allocate the structure if it has not already been allocated by a
3649 if (ret
== (struct aout_link_includes_entry
*) NULL
)
3650 ret
= ((struct aout_link_includes_entry
*)
3651 bfd_hash_allocate (table
,
3652 sizeof (struct aout_link_includes_entry
)));
3653 if (ret
== (struct aout_link_includes_entry
*) NULL
)
3654 return (struct bfd_hash_entry
*) ret
;
3656 /* Call the allocation method of the superclass. */
3657 ret
= ((struct aout_link_includes_entry
*)
3658 bfd_hash_newfunc ((struct bfd_hash_entry
*) ret
, table
, string
));
3661 /* Set local fields. */
3665 return (struct bfd_hash_entry
*) ret
;
3668 /* Do the final link step. This is called on the output BFD. The
3669 INFO structure should point to a list of BFDs linked through the
3670 link_next field which can be used to find each BFD which takes part
3671 in the output. Also, each section in ABFD should point to a list
3672 of bfd_link_order structures which list all the input sections for
3673 the output section. */
3676 NAME(aout
,final_link
) (abfd
, info
, callback
)
3678 struct bfd_link_info
*info
;
3679 void (*callback
) PARAMS ((bfd
*, file_ptr
*, file_ptr
*, file_ptr
*));
3681 struct aout_final_link_info aout_info
;
3682 boolean includes_hash_initialized
= false;
3684 bfd_size_type trsize
, drsize
;
3685 bfd_size_type max_contents_size
;
3686 bfd_size_type max_relocs_size
;
3687 bfd_size_type max_sym_count
;
3688 bfd_size_type text_size
;
3690 register struct bfd_link_order
*p
;
3692 boolean have_link_order_relocs
;
3695 abfd
->flags
|= DYNAMIC
;
3697 aout_info
.info
= info
;
3698 aout_info
.output_bfd
= abfd
;
3699 aout_info
.contents
= NULL
;
3700 aout_info
.relocs
= NULL
;
3701 aout_info
.symbol_map
= NULL
;
3702 aout_info
.output_syms
= NULL
;
3704 if (! bfd_hash_table_init_n (&aout_info
.includes
.root
,
3705 aout_link_includes_newfunc
,
3708 includes_hash_initialized
= true;
3710 /* Figure out the largest section size. Also, if generating
3711 relocateable output, count the relocs. */
3714 max_contents_size
= 0;
3715 max_relocs_size
= 0;
3717 for (sub
= info
->input_bfds
; sub
!= NULL
; sub
= sub
->link_next
)
3721 if (info
->relocateable
)
3723 if (bfd_get_flavour (sub
) == bfd_target_aout_flavour
)
3725 trsize
+= exec_hdr (sub
)->a_trsize
;
3726 drsize
+= exec_hdr (sub
)->a_drsize
;
3730 /* FIXME: We need to identify the .text and .data sections
3731 and call get_reloc_upper_bound and canonicalize_reloc to
3732 work out the number of relocs needed, and then multiply
3733 by the reloc size. */
3734 (*_bfd_error_handler
)
3735 (_("%s: relocateable link from %s to %s not supported"),
3736 bfd_get_filename (abfd
),
3737 sub
->xvec
->name
, abfd
->xvec
->name
);
3738 bfd_set_error (bfd_error_invalid_operation
);
3743 if (bfd_get_flavour (sub
) == bfd_target_aout_flavour
)
3745 sz
= bfd_section_size (sub
, obj_textsec (sub
));
3746 if (sz
> max_contents_size
)
3747 max_contents_size
= sz
;
3748 sz
= bfd_section_size (sub
, obj_datasec (sub
));
3749 if (sz
> max_contents_size
)
3750 max_contents_size
= sz
;
3752 sz
= exec_hdr (sub
)->a_trsize
;
3753 if (sz
> max_relocs_size
)
3754 max_relocs_size
= sz
;
3755 sz
= exec_hdr (sub
)->a_drsize
;
3756 if (sz
> max_relocs_size
)
3757 max_relocs_size
= sz
;
3759 sz
= obj_aout_external_sym_count (sub
);
3760 if (sz
> max_sym_count
)
3765 if (info
->relocateable
)
3767 if (obj_textsec (abfd
) != (asection
*) NULL
)
3768 trsize
+= (_bfd_count_link_order_relocs (obj_textsec (abfd
)
3770 * obj_reloc_entry_size (abfd
));
3771 if (obj_datasec (abfd
) != (asection
*) NULL
)
3772 drsize
+= (_bfd_count_link_order_relocs (obj_datasec (abfd
)
3774 * obj_reloc_entry_size (abfd
));
3777 exec_hdr (abfd
)->a_trsize
= trsize
;
3778 exec_hdr (abfd
)->a_drsize
= drsize
;
3780 exec_hdr (abfd
)->a_entry
= bfd_get_start_address (abfd
);
3782 /* Adjust the section sizes and vmas according to the magic number.
3783 This sets a_text, a_data and a_bss in the exec_hdr and sets the
3784 filepos for each section. */
3785 if (! NAME(aout
,adjust_sizes_and_vmas
) (abfd
, &text_size
, &text_end
))
3788 /* The relocation and symbol file positions differ among a.out
3789 targets. We are passed a callback routine from the backend
3790 specific code to handle this.
3791 FIXME: At this point we do not know how much space the symbol
3792 table will require. This will not work for any (nonstandard)
3793 a.out target that needs to know the symbol table size before it
3794 can compute the relocation file positions. This may or may not
3795 be the case for the hp300hpux target, for example. */
3796 (*callback
) (abfd
, &aout_info
.treloff
, &aout_info
.dreloff
,
3798 obj_textsec (abfd
)->rel_filepos
= aout_info
.treloff
;
3799 obj_datasec (abfd
)->rel_filepos
= aout_info
.dreloff
;
3800 obj_sym_filepos (abfd
) = aout_info
.symoff
;
3802 /* We keep a count of the symbols as we output them. */
3803 obj_aout_external_sym_count (abfd
) = 0;
3805 /* We accumulate the string table as we write out the symbols. */
3806 aout_info
.strtab
= _bfd_stringtab_init ();
3807 if (aout_info
.strtab
== NULL
)
3810 /* Allocate buffers to hold section contents and relocs. */
3811 aout_info
.contents
= (bfd_byte
*) bfd_malloc (max_contents_size
);
3812 aout_info
.relocs
= (PTR
) bfd_malloc (max_relocs_size
);
3813 aout_info
.symbol_map
= (int *) bfd_malloc (max_sym_count
* sizeof (int *));
3814 aout_info
.output_syms
= ((struct external_nlist
*)
3815 bfd_malloc ((max_sym_count
+ 1)
3816 * sizeof (struct external_nlist
)));
3817 if ((aout_info
.contents
== NULL
&& max_contents_size
!= 0)
3818 || (aout_info
.relocs
== NULL
&& max_relocs_size
!= 0)
3819 || (aout_info
.symbol_map
== NULL
&& max_sym_count
!= 0)
3820 || aout_info
.output_syms
== NULL
)
3823 /* If we have a symbol named __DYNAMIC, force it out now. This is
3824 required by SunOS. Doing this here rather than in sunos.c is a
3825 hack, but it's easier than exporting everything which would be
3828 struct aout_link_hash_entry
*h
;
3830 h
= aout_link_hash_lookup (aout_hash_table (info
), "__DYNAMIC",
3831 false, false, false);
3833 aout_link_write_other_symbol (h
, &aout_info
);
3836 /* The most time efficient way to do the link would be to read all
3837 the input object files into memory and then sort out the
3838 information into the output file. Unfortunately, that will
3839 probably use too much memory. Another method would be to step
3840 through everything that composes the text section and write it
3841 out, and then everything that composes the data section and write
3842 it out, and then write out the relocs, and then write out the
3843 symbols. Unfortunately, that requires reading stuff from each
3844 input file several times, and we will not be able to keep all the
3845 input files open simultaneously, and reopening them will be slow.
3847 What we do is basically process one input file at a time. We do
3848 everything we need to do with an input file once--copy over the
3849 section contents, handle the relocation information, and write
3850 out the symbols--and then we throw away the information we read
3851 from it. This approach requires a lot of lseeks of the output
3852 file, which is unfortunate but still faster than reopening a lot
3855 We use the output_has_begun field of the input BFDs to see
3856 whether we have already handled it. */
3857 for (sub
= info
->input_bfds
; sub
!= (bfd
*) NULL
; sub
= sub
->link_next
)
3858 sub
->output_has_begun
= false;
3860 /* Mark all sections which are to be included in the link. This
3861 will normally be every section. We need to do this so that we
3862 can identify any sections which the linker has decided to not
3864 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
3866 for (p
= o
->link_order_head
; p
!= NULL
; p
= p
->next
)
3868 if (p
->type
== bfd_indirect_link_order
)
3869 p
->u
.indirect
.section
->linker_mark
= true;
3873 have_link_order_relocs
= false;
3874 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
3876 for (p
= o
->link_order_head
;
3877 p
!= (struct bfd_link_order
*) NULL
;
3880 if (p
->type
== bfd_indirect_link_order
3881 && (bfd_get_flavour (p
->u
.indirect
.section
->owner
)
3882 == bfd_target_aout_flavour
))
3886 input_bfd
= p
->u
.indirect
.section
->owner
;
3887 if (! input_bfd
->output_has_begun
)
3889 if (! aout_link_input_bfd (&aout_info
, input_bfd
))
3891 input_bfd
->output_has_begun
= true;
3894 else if (p
->type
== bfd_section_reloc_link_order
3895 || p
->type
== bfd_symbol_reloc_link_order
)
3897 /* These are handled below. */
3898 have_link_order_relocs
= true;
3902 if (! _bfd_default_link_order (abfd
, info
, o
, p
))
3908 /* Write out any symbols that we have not already written out. */
3909 aout_link_hash_traverse (aout_hash_table (info
),
3910 aout_link_write_other_symbol
,
3913 /* Now handle any relocs we were asked to create by the linker.
3914 These did not come from any input file. We must do these after
3915 we have written out all the symbols, so that we know the symbol
3917 if (have_link_order_relocs
)
3919 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
3921 for (p
= o
->link_order_head
;
3922 p
!= (struct bfd_link_order
*) NULL
;
3925 if (p
->type
== bfd_section_reloc_link_order
3926 || p
->type
== bfd_symbol_reloc_link_order
)
3928 if (! aout_link_reloc_link_order (&aout_info
, o
, p
))
3935 if (aout_info
.contents
!= NULL
)
3937 free (aout_info
.contents
);
3938 aout_info
.contents
= NULL
;
3940 if (aout_info
.relocs
!= NULL
)
3942 free (aout_info
.relocs
);
3943 aout_info
.relocs
= NULL
;
3945 if (aout_info
.symbol_map
!= NULL
)
3947 free (aout_info
.symbol_map
);
3948 aout_info
.symbol_map
= NULL
;
3950 if (aout_info
.output_syms
!= NULL
)
3952 free (aout_info
.output_syms
);
3953 aout_info
.output_syms
= NULL
;
3955 if (includes_hash_initialized
)
3957 bfd_hash_table_free (&aout_info
.includes
.root
);
3958 includes_hash_initialized
= false;
3961 /* Finish up any dynamic linking we may be doing. */
3962 if (aout_backend_info (abfd
)->finish_dynamic_link
!= NULL
)
3964 if (! (*aout_backend_info (abfd
)->finish_dynamic_link
) (abfd
, info
))
3968 /* Update the header information. */
3969 abfd
->symcount
= obj_aout_external_sym_count (abfd
);
3970 exec_hdr (abfd
)->a_syms
= abfd
->symcount
* EXTERNAL_NLIST_SIZE
;
3971 obj_str_filepos (abfd
) = obj_sym_filepos (abfd
) + exec_hdr (abfd
)->a_syms
;
3972 obj_textsec (abfd
)->reloc_count
=
3973 exec_hdr (abfd
)->a_trsize
/ obj_reloc_entry_size (abfd
);
3974 obj_datasec (abfd
)->reloc_count
=
3975 exec_hdr (abfd
)->a_drsize
/ obj_reloc_entry_size (abfd
);
3977 /* Write out the string table, unless there are no symbols. */
3978 if (abfd
->symcount
> 0)
3980 if (bfd_seek (abfd
, obj_str_filepos (abfd
), SEEK_SET
) != 0
3981 || ! emit_stringtab (abfd
, aout_info
.strtab
))
3984 else if (obj_textsec (abfd
)->reloc_count
== 0
3985 && obj_datasec (abfd
)->reloc_count
== 0)
3991 pos
= obj_datasec (abfd
)->filepos
+ exec_hdr (abfd
)->a_data
- 1;
3992 if (bfd_seek (abfd
, pos
, SEEK_SET
) != 0
3993 || bfd_bwrite (&b
, (bfd_size_type
) 1, abfd
) != 1)
4000 if (aout_info
.contents
!= NULL
)
4001 free (aout_info
.contents
);
4002 if (aout_info
.relocs
!= NULL
)
4003 free (aout_info
.relocs
);
4004 if (aout_info
.symbol_map
!= NULL
)
4005 free (aout_info
.symbol_map
);
4006 if (aout_info
.output_syms
!= NULL
)
4007 free (aout_info
.output_syms
);
4008 if (includes_hash_initialized
)
4009 bfd_hash_table_free (&aout_info
.includes
.root
);
4013 /* Link an a.out input BFD into the output file. */
4016 aout_link_input_bfd (finfo
, input_bfd
)
4017 struct aout_final_link_info
*finfo
;
4020 bfd_size_type sym_count
;
4022 BFD_ASSERT (bfd_get_format (input_bfd
) == bfd_object
);
4024 /* If this is a dynamic object, it may need special handling. */
4025 if ((input_bfd
->flags
& DYNAMIC
) != 0
4026 && aout_backend_info (input_bfd
)->link_dynamic_object
!= NULL
)
4028 return ((*aout_backend_info (input_bfd
)->link_dynamic_object
)
4029 (finfo
->info
, input_bfd
));
4032 /* Get the symbols. We probably have them already, unless
4033 finfo->info->keep_memory is false. */
4034 if (! aout_get_external_symbols (input_bfd
))
4037 sym_count
= obj_aout_external_sym_count (input_bfd
);
4039 /* Write out the symbols and get a map of the new indices. The map
4040 is placed into finfo->symbol_map. */
4041 if (! aout_link_write_symbols (finfo
, input_bfd
))
4044 /* Relocate and write out the sections. These functions use the
4045 symbol map created by aout_link_write_symbols. The linker_mark
4046 field will be set if these sections are to be included in the
4047 link, which will normally be the case. */
4048 if (obj_textsec (input_bfd
)->linker_mark
)
4050 if (! aout_link_input_section (finfo
, input_bfd
,
4051 obj_textsec (input_bfd
),
4053 exec_hdr (input_bfd
)->a_trsize
))
4056 if (obj_datasec (input_bfd
)->linker_mark
)
4058 if (! aout_link_input_section (finfo
, input_bfd
,
4059 obj_datasec (input_bfd
),
4061 exec_hdr (input_bfd
)->a_drsize
))
4065 /* If we are not keeping memory, we don't need the symbols any
4066 longer. We still need them if we are keeping memory, because the
4067 strings in the hash table point into them. */
4068 if (! finfo
->info
->keep_memory
)
4070 if (! aout_link_free_symbols (input_bfd
))
4077 /* Adjust and write out the symbols for an a.out file. Set the new
4078 symbol indices into a symbol_map. */
4081 aout_link_write_symbols (finfo
, input_bfd
)
4082 struct aout_final_link_info
*finfo
;
4086 bfd_size_type sym_count
;
4088 enum bfd_link_strip strip
;
4089 enum bfd_link_discard discard
;
4090 struct external_nlist
*outsym
;
4091 bfd_size_type strtab_index
;
4092 register struct external_nlist
*sym
;
4093 struct external_nlist
*sym_end
;
4094 struct aout_link_hash_entry
**sym_hash
;
4099 output_bfd
= finfo
->output_bfd
;
4100 sym_count
= obj_aout_external_sym_count (input_bfd
);
4101 strings
= obj_aout_external_strings (input_bfd
);
4102 strip
= finfo
->info
->strip
;
4103 discard
= finfo
->info
->discard
;
4104 outsym
= finfo
->output_syms
;
4106 /* First write out a symbol for this object file, unless we are
4107 discarding such symbols. */
4108 if (strip
!= strip_all
4109 && (strip
!= strip_some
4110 || bfd_hash_lookup (finfo
->info
->keep_hash
, input_bfd
->filename
,
4111 false, false) != NULL
)
4112 && discard
!= discard_all
)
4114 H_PUT_8 (output_bfd
, N_TEXT
, outsym
->e_type
);
4115 H_PUT_8 (output_bfd
, 0, outsym
->e_other
);
4116 H_PUT_16 (output_bfd
, 0, outsym
->e_desc
);
4117 strtab_index
= add_to_stringtab (output_bfd
, finfo
->strtab
,
4118 input_bfd
->filename
, false);
4119 if (strtab_index
== (bfd_size_type
) -1)
4121 PUT_WORD (output_bfd
, strtab_index
, outsym
->e_strx
);
4122 PUT_WORD (output_bfd
,
4123 (bfd_get_section_vma (output_bfd
,
4124 obj_textsec (input_bfd
)->output_section
)
4125 + obj_textsec (input_bfd
)->output_offset
),
4127 ++obj_aout_external_sym_count (output_bfd
);
4133 sym
= obj_aout_external_syms (input_bfd
);
4134 sym_end
= sym
+ sym_count
;
4135 sym_hash
= obj_aout_sym_hashes (input_bfd
);
4136 symbol_map
= finfo
->symbol_map
;
4137 memset (symbol_map
, 0, (size_t) sym_count
* sizeof *symbol_map
);
4138 for (; sym
< sym_end
; sym
++, sym_hash
++, symbol_map
++)
4142 struct aout_link_hash_entry
*h
;
4148 /* We set *symbol_map to 0 above for all symbols. If it has
4149 already been set to -1 for this symbol, it means that we are
4150 discarding it because it appears in a duplicate header file.
4151 See the N_BINCL code below. */
4152 if (*symbol_map
== -1)
4155 /* Initialize *symbol_map to -1, which means that the symbol was
4156 not copied into the output file. We will change it later if
4157 we do copy the symbol over. */
4160 type
= H_GET_8 (input_bfd
, sym
->e_type
);
4161 name
= strings
+ GET_WORD (input_bfd
, sym
->e_strx
);
4167 /* Pass this symbol through. It is the target of an
4168 indirect or warning symbol. */
4169 val
= GET_WORD (input_bfd
, sym
->e_value
);
4174 /* Skip this symbol, which is the target of an indirect
4175 symbol that we have changed to no longer be an indirect
4182 struct aout_link_hash_entry
*hresolve
;
4184 /* We have saved the hash table entry for this symbol, if
4185 there is one. Note that we could just look it up again
4186 in the hash table, provided we first check that it is an
4190 /* Use the name from the hash table, in case the symbol was
4193 name
= h
->root
.root
.string
;
4195 /* If this is an indirect or warning symbol, then change
4196 hresolve to the base symbol. We also change *sym_hash so
4197 that the relocation routines relocate against the real
4200 if (h
!= (struct aout_link_hash_entry
*) NULL
4201 && (h
->root
.type
== bfd_link_hash_indirect
4202 || h
->root
.type
== bfd_link_hash_warning
))
4204 hresolve
= (struct aout_link_hash_entry
*) h
->root
.u
.i
.link
;
4205 while (hresolve
->root
.type
== bfd_link_hash_indirect
4206 || hresolve
->root
.type
== bfd_link_hash_warning
)
4207 hresolve
= ((struct aout_link_hash_entry
*)
4208 hresolve
->root
.u
.i
.link
);
4209 *sym_hash
= hresolve
;
4212 /* If the symbol has already been written out, skip it. */
4213 if (h
!= (struct aout_link_hash_entry
*) NULL
4214 && h
->root
.type
!= bfd_link_hash_warning
4217 if ((type
& N_TYPE
) == N_INDR
4218 || type
== N_WARNING
)
4220 *symbol_map
= h
->indx
;
4224 /* See if we are stripping this symbol. */
4230 case strip_debugger
:
4231 if ((type
& N_STAB
) != 0)
4235 if (bfd_hash_lookup (finfo
->info
->keep_hash
, name
, false, false)
4245 if (h
!= (struct aout_link_hash_entry
*) NULL
)
4250 /* Get the value of the symbol. */
4251 if ((type
& N_TYPE
) == N_TEXT
4253 symsec
= obj_textsec (input_bfd
);
4254 else if ((type
& N_TYPE
) == N_DATA
4256 symsec
= obj_datasec (input_bfd
);
4257 else if ((type
& N_TYPE
) == N_BSS
4259 symsec
= obj_bsssec (input_bfd
);
4260 else if ((type
& N_TYPE
) == N_ABS
4262 symsec
= bfd_abs_section_ptr
;
4263 else if (((type
& N_TYPE
) == N_INDR
4264 && (hresolve
== (struct aout_link_hash_entry
*) NULL
4265 || (hresolve
->root
.type
!= bfd_link_hash_defined
4266 && hresolve
->root
.type
!= bfd_link_hash_defweak
4267 && hresolve
->root
.type
!= bfd_link_hash_common
)))
4268 || type
== N_WARNING
)
4270 /* Pass the next symbol through unchanged. The
4271 condition above for indirect symbols is so that if
4272 the indirect symbol was defined, we output it with
4273 the correct definition so the debugger will
4276 val
= GET_WORD (input_bfd
, sym
->e_value
);
4279 else if ((type
& N_STAB
) != 0)
4281 val
= GET_WORD (input_bfd
, sym
->e_value
);
4286 /* If we get here with an indirect symbol, it means that
4287 we are outputting it with a real definition. In such
4288 a case we do not want to output the next symbol,
4289 which is the target of the indirection. */
4290 if ((type
& N_TYPE
) == N_INDR
)
4295 /* We need to get the value from the hash table. We use
4296 hresolve so that if we have defined an indirect
4297 symbol we output the final definition. */
4298 if (h
== (struct aout_link_hash_entry
*) NULL
)
4300 switch (type
& N_TYPE
)
4303 symsec
= obj_textsec (input_bfd
);
4306 symsec
= obj_datasec (input_bfd
);
4309 symsec
= obj_bsssec (input_bfd
);
4312 symsec
= bfd_abs_section_ptr
;
4319 else if (hresolve
->root
.type
== bfd_link_hash_defined
4320 || hresolve
->root
.type
== bfd_link_hash_defweak
)
4322 asection
*input_section
;
4323 asection
*output_section
;
4325 /* This case usually means a common symbol which was
4326 turned into a defined symbol. */
4327 input_section
= hresolve
->root
.u
.def
.section
;
4328 output_section
= input_section
->output_section
;
4329 BFD_ASSERT (bfd_is_abs_section (output_section
)
4330 || output_section
->owner
== output_bfd
);
4331 val
= (hresolve
->root
.u
.def
.value
4332 + bfd_get_section_vma (output_bfd
, output_section
)
4333 + input_section
->output_offset
);
4335 /* Get the correct type based on the section. If
4336 this is a constructed set, force it to be
4337 globally visible. */
4346 if (output_section
== obj_textsec (output_bfd
))
4347 type
|= (hresolve
->root
.type
== bfd_link_hash_defined
4350 else if (output_section
== obj_datasec (output_bfd
))
4351 type
|= (hresolve
->root
.type
== bfd_link_hash_defined
4354 else if (output_section
== obj_bsssec (output_bfd
))
4355 type
|= (hresolve
->root
.type
== bfd_link_hash_defined
4359 type
|= (hresolve
->root
.type
== bfd_link_hash_defined
4363 else if (hresolve
->root
.type
== bfd_link_hash_common
)
4364 val
= hresolve
->root
.u
.c
.size
;
4365 else if (hresolve
->root
.type
== bfd_link_hash_undefweak
)
4373 if (symsec
!= (asection
*) NULL
)
4374 val
= (symsec
->output_section
->vma
4375 + symsec
->output_offset
4376 + (GET_WORD (input_bfd
, sym
->e_value
)
4379 /* If this is a global symbol set the written flag, and if
4380 it is a local symbol see if we should discard it. */
4381 if (h
!= (struct aout_link_hash_entry
*) NULL
)
4384 h
->indx
= obj_aout_external_sym_count (output_bfd
);
4386 else if ((type
& N_TYPE
) != N_SETT
4387 && (type
& N_TYPE
) != N_SETD
4388 && (type
& N_TYPE
) != N_SETB
4389 && (type
& N_TYPE
) != N_SETA
)
4394 case discard_sec_merge
:
4397 if ((type
& N_STAB
) == 0
4398 && bfd_is_local_label_name (input_bfd
, name
))
4412 /* An N_BINCL symbol indicates the start of the stabs
4413 entries for a header file. We need to scan ahead to the
4414 next N_EINCL symbol, ignoring nesting, adding up all the
4415 characters in the symbol names, not including the file
4416 numbers in types (the first number after an open
4418 if (type
== N_BINCL
)
4420 struct external_nlist
*incl_sym
;
4422 struct aout_link_includes_entry
*incl_entry
;
4423 struct aout_link_includes_totals
*t
;
4427 for (incl_sym
= sym
+ 1; incl_sym
< sym_end
; incl_sym
++)
4431 incl_type
= H_GET_8 (input_bfd
, incl_sym
->e_type
);
4432 if (incl_type
== N_EINCL
)
4438 else if (incl_type
== N_BINCL
)
4444 s
= strings
+ GET_WORD (input_bfd
, incl_sym
->e_strx
);
4445 for (; *s
!= '\0'; s
++)
4450 /* Skip the file number. */
4452 while (ISDIGIT (*s
))
4460 /* If we have already included a header file with the
4461 same value, then replace this one with an N_EXCL
4463 copy
= ! finfo
->info
->keep_memory
;
4464 incl_entry
= aout_link_includes_lookup (&finfo
->includes
,
4466 if (incl_entry
== NULL
)
4468 for (t
= incl_entry
->totals
; t
!= NULL
; t
= t
->next
)
4469 if (t
->total
== val
)
4473 /* This is the first time we have seen this header
4474 file with this set of stabs strings. */
4475 t
= ((struct aout_link_includes_totals
*)
4476 bfd_hash_allocate (&finfo
->includes
.root
,
4481 t
->next
= incl_entry
->totals
;
4482 incl_entry
->totals
= t
;
4488 /* This is a duplicate header file. We must change
4489 it to be an N_EXCL entry, and mark all the
4490 included symbols to prevent outputting them. */
4494 for (incl_sym
= sym
+ 1, incl_map
= symbol_map
+ 1;
4496 incl_sym
++, incl_map
++)
4500 incl_type
= H_GET_8 (input_bfd
, incl_sym
->e_type
);
4501 if (incl_type
== N_EINCL
)
4510 else if (incl_type
== N_BINCL
)
4519 /* Copy this symbol into the list of symbols we are going to
4521 H_PUT_8 (output_bfd
, type
, outsym
->e_type
);
4522 H_PUT_8 (output_bfd
, H_GET_8 (input_bfd
, sym
->e_other
), outsym
->e_other
);
4523 H_PUT_16 (output_bfd
, H_GET_16 (input_bfd
, sym
->e_desc
), outsym
->e_desc
);
4525 if (! finfo
->info
->keep_memory
)
4527 /* name points into a string table which we are going to
4528 free. If there is a hash table entry, use that string.
4529 Otherwise, copy name into memory. */
4530 if (h
!= (struct aout_link_hash_entry
*) NULL
)
4531 name
= h
->root
.root
.string
;
4535 strtab_index
= add_to_stringtab (output_bfd
, finfo
->strtab
,
4537 if (strtab_index
== (bfd_size_type
) -1)
4539 PUT_WORD (output_bfd
, strtab_index
, outsym
->e_strx
);
4540 PUT_WORD (output_bfd
, val
, outsym
->e_value
);
4541 *symbol_map
= obj_aout_external_sym_count (output_bfd
);
4542 ++obj_aout_external_sym_count (output_bfd
);
4546 /* Write out the output symbols we have just constructed. */
4547 if (outsym
> finfo
->output_syms
)
4549 bfd_size_type outsym_size
;
4551 if (bfd_seek (output_bfd
, finfo
->symoff
, SEEK_SET
) != 0)
4553 outsym_size
= outsym
- finfo
->output_syms
;
4554 outsym_size
*= EXTERNAL_NLIST_SIZE
;
4555 if (bfd_bwrite ((PTR
) finfo
->output_syms
, outsym_size
, output_bfd
)
4558 finfo
->symoff
+= outsym_size
;
4564 /* Write out a symbol that was not associated with an a.out input
4568 aout_link_write_other_symbol (h
, data
)
4569 struct aout_link_hash_entry
*h
;
4572 struct aout_final_link_info
*finfo
= (struct aout_final_link_info
*) data
;
4576 struct external_nlist outsym
;
4580 output_bfd
= finfo
->output_bfd
;
4582 if (aout_backend_info (output_bfd
)->write_dynamic_symbol
!= NULL
)
4584 if (! ((*aout_backend_info (output_bfd
)->write_dynamic_symbol
)
4585 (output_bfd
, finfo
->info
, h
)))
4587 /* FIXME: No way to handle errors. */
4597 /* An indx of -2 means the symbol must be written. */
4599 && (finfo
->info
->strip
== strip_all
4600 || (finfo
->info
->strip
== strip_some
4601 && bfd_hash_lookup (finfo
->info
->keep_hash
, h
->root
.root
.string
,
4602 false, false) == NULL
)))
4605 switch (h
->root
.type
)
4609 /* Avoid variable not initialized warnings. */
4611 case bfd_link_hash_new
:
4612 /* This can happen for set symbols when sets are not being
4615 case bfd_link_hash_undefined
:
4616 type
= N_UNDF
| N_EXT
;
4619 case bfd_link_hash_defined
:
4620 case bfd_link_hash_defweak
:
4624 sec
= h
->root
.u
.def
.section
->output_section
;
4625 BFD_ASSERT (bfd_is_abs_section (sec
)
4626 || sec
->owner
== output_bfd
);
4627 if (sec
== obj_textsec (output_bfd
))
4628 type
= h
->root
.type
== bfd_link_hash_defined
? N_TEXT
: N_WEAKT
;
4629 else if (sec
== obj_datasec (output_bfd
))
4630 type
= h
->root
.type
== bfd_link_hash_defined
? N_DATA
: N_WEAKD
;
4631 else if (sec
== obj_bsssec (output_bfd
))
4632 type
= h
->root
.type
== bfd_link_hash_defined
? N_BSS
: N_WEAKB
;
4634 type
= h
->root
.type
== bfd_link_hash_defined
? N_ABS
: N_WEAKA
;
4636 val
= (h
->root
.u
.def
.value
4638 + h
->root
.u
.def
.section
->output_offset
);
4641 case bfd_link_hash_common
:
4642 type
= N_UNDF
| N_EXT
;
4643 val
= h
->root
.u
.c
.size
;
4645 case bfd_link_hash_undefweak
:
4648 case bfd_link_hash_indirect
:
4649 case bfd_link_hash_warning
:
4650 /* FIXME: Ignore these for now. The circumstances under which
4651 they should be written out are not clear to me. */
4655 H_PUT_8 (output_bfd
, type
, outsym
.e_type
);
4656 H_PUT_8 (output_bfd
, 0, outsym
.e_other
);
4657 H_PUT_16 (output_bfd
, 0, outsym
.e_desc
);
4658 indx
= add_to_stringtab (output_bfd
, finfo
->strtab
, h
->root
.root
.string
,
4660 if (indx
== - (bfd_size_type
) 1)
4662 /* FIXME: No way to handle errors. */
4665 PUT_WORD (output_bfd
, indx
, outsym
.e_strx
);
4666 PUT_WORD (output_bfd
, val
, outsym
.e_value
);
4668 amt
= EXTERNAL_NLIST_SIZE
;
4669 if (bfd_seek (output_bfd
, finfo
->symoff
, SEEK_SET
) != 0
4670 || bfd_bwrite ((PTR
) &outsym
, amt
, output_bfd
) != amt
)
4672 /* FIXME: No way to handle errors. */
4676 finfo
->symoff
+= EXTERNAL_NLIST_SIZE
;
4677 h
->indx
= obj_aout_external_sym_count (output_bfd
);
4678 ++obj_aout_external_sym_count (output_bfd
);
4683 /* Link an a.out section into the output file. */
4686 aout_link_input_section (finfo
, input_bfd
, input_section
, reloff_ptr
,
4688 struct aout_final_link_info
*finfo
;
4690 asection
*input_section
;
4691 file_ptr
*reloff_ptr
;
4692 bfd_size_type rel_size
;
4694 bfd_size_type input_size
;
4697 /* Get the section contents. */
4698 input_size
= bfd_section_size (input_bfd
, input_section
);
4699 if (! bfd_get_section_contents (input_bfd
, input_section
,
4700 (PTR
) finfo
->contents
,
4701 (file_ptr
) 0, input_size
))
4704 /* Read in the relocs if we haven't already done it. */
4705 if (aout_section_data (input_section
) != NULL
4706 && aout_section_data (input_section
)->relocs
!= NULL
)
4707 relocs
= aout_section_data (input_section
)->relocs
;
4710 relocs
= finfo
->relocs
;
4713 if (bfd_seek (input_bfd
, input_section
->rel_filepos
, SEEK_SET
) != 0
4714 || bfd_bread (relocs
, rel_size
, input_bfd
) != rel_size
)
4719 /* Relocate the section contents. */
4720 if (obj_reloc_entry_size (input_bfd
) == RELOC_STD_SIZE
)
4722 if (! aout_link_input_section_std (finfo
, input_bfd
, input_section
,
4723 (struct reloc_std_external
*) relocs
,
4724 rel_size
, finfo
->contents
))
4729 if (! aout_link_input_section_ext (finfo
, input_bfd
, input_section
,
4730 (struct reloc_ext_external
*) relocs
,
4731 rel_size
, finfo
->contents
))
4735 /* Write out the section contents. */
4736 if (! bfd_set_section_contents (finfo
->output_bfd
,
4737 input_section
->output_section
,
4738 (PTR
) finfo
->contents
,
4739 (file_ptr
) input_section
->output_offset
,
4743 /* If we are producing relocateable output, the relocs were
4744 modified, and we now write them out. */
4745 if (finfo
->info
->relocateable
&& rel_size
> 0)
4747 if (bfd_seek (finfo
->output_bfd
, *reloff_ptr
, SEEK_SET
) != 0)
4749 if (bfd_bwrite (relocs
, rel_size
, finfo
->output_bfd
) != rel_size
)
4751 *reloff_ptr
+= rel_size
;
4753 /* Assert that the relocs have not run into the symbols, and
4754 that if these are the text relocs they have not run into the
4756 BFD_ASSERT (*reloff_ptr
<= obj_sym_filepos (finfo
->output_bfd
)
4757 && (reloff_ptr
!= &finfo
->treloff
4759 <= obj_datasec (finfo
->output_bfd
)->rel_filepos
)));
4765 /* Get the section corresponding to a reloc index. */
4767 static INLINE asection
*
4768 aout_reloc_index_to_section (abfd
, indx
)
4772 switch (indx
& N_TYPE
)
4775 return obj_textsec (abfd
);
4777 return obj_datasec (abfd
);
4779 return obj_bsssec (abfd
);
4782 return bfd_abs_section_ptr
;
4790 /* Relocate an a.out section using standard a.out relocs. */
4793 aout_link_input_section_std (finfo
, input_bfd
, input_section
, relocs
,
4795 struct aout_final_link_info
*finfo
;
4797 asection
*input_section
;
4798 struct reloc_std_external
*relocs
;
4799 bfd_size_type rel_size
;
4802 boolean (*check_dynamic_reloc
) PARAMS ((struct bfd_link_info
*,
4804 struct aout_link_hash_entry
*,
4805 PTR
, bfd_byte
*, boolean
*,
4808 boolean relocateable
;
4809 struct external_nlist
*syms
;
4811 struct aout_link_hash_entry
**sym_hashes
;
4813 bfd_size_type reloc_count
;
4814 register struct reloc_std_external
*rel
;
4815 struct reloc_std_external
*rel_end
;
4817 output_bfd
= finfo
->output_bfd
;
4818 check_dynamic_reloc
= aout_backend_info (output_bfd
)->check_dynamic_reloc
;
4820 BFD_ASSERT (obj_reloc_entry_size (input_bfd
) == RELOC_STD_SIZE
);
4821 BFD_ASSERT (input_bfd
->xvec
->header_byteorder
4822 == output_bfd
->xvec
->header_byteorder
);
4824 relocateable
= finfo
->info
->relocateable
;
4825 syms
= obj_aout_external_syms (input_bfd
);
4826 strings
= obj_aout_external_strings (input_bfd
);
4827 sym_hashes
= obj_aout_sym_hashes (input_bfd
);
4828 symbol_map
= finfo
->symbol_map
;
4830 reloc_count
= rel_size
/ RELOC_STD_SIZE
;
4832 rel_end
= rel
+ reloc_count
;
4833 for (; rel
< rel_end
; rel
++)
4840 reloc_howto_type
*howto
;
4841 struct aout_link_hash_entry
*h
= NULL
;
4843 bfd_reloc_status_type r
;
4845 r_addr
= GET_SWORD (input_bfd
, rel
->r_address
);
4847 #ifdef MY_reloc_howto
4848 howto
= MY_reloc_howto (input_bfd
, rel
, r_index
, r_extern
, r_pcrel
);
4854 unsigned int howto_idx
;
4856 if (bfd_header_big_endian (input_bfd
))
4858 r_index
= ((rel
->r_index
[0] << 16)
4859 | (rel
->r_index
[1] << 8)
4861 r_extern
= (0 != (rel
->r_type
[0] & RELOC_STD_BITS_EXTERN_BIG
));
4862 r_pcrel
= (0 != (rel
->r_type
[0] & RELOC_STD_BITS_PCREL_BIG
));
4863 r_baserel
= (0 != (rel
->r_type
[0] & RELOC_STD_BITS_BASEREL_BIG
));
4864 r_jmptable
= (0 != (rel
->r_type
[0] & RELOC_STD_BITS_JMPTABLE_BIG
));
4865 r_relative
= (0 != (rel
->r_type
[0] & RELOC_STD_BITS_RELATIVE_BIG
));
4866 r_length
= ((rel
->r_type
[0] & RELOC_STD_BITS_LENGTH_BIG
)
4867 >> RELOC_STD_BITS_LENGTH_SH_BIG
);
4871 r_index
= ((rel
->r_index
[2] << 16)
4872 | (rel
->r_index
[1] << 8)
4874 r_extern
= (0 != (rel
->r_type
[0] & RELOC_STD_BITS_EXTERN_LITTLE
));
4875 r_pcrel
= (0 != (rel
->r_type
[0] & RELOC_STD_BITS_PCREL_LITTLE
));
4876 r_baserel
= (0 != (rel
->r_type
[0]
4877 & RELOC_STD_BITS_BASEREL_LITTLE
));
4878 r_jmptable
= (0 != (rel
->r_type
[0]
4879 & RELOC_STD_BITS_JMPTABLE_LITTLE
));
4880 r_relative
= (0 != (rel
->r_type
[0]
4881 & RELOC_STD_BITS_RELATIVE_LITTLE
));
4882 r_length
= ((rel
->r_type
[0] & RELOC_STD_BITS_LENGTH_LITTLE
)
4883 >> RELOC_STD_BITS_LENGTH_SH_LITTLE
);
4886 howto_idx
= (r_length
+ 4 * r_pcrel
+ 8 * r_baserel
4887 + 16 * r_jmptable
+ 32 * r_relative
);
4888 BFD_ASSERT (howto_idx
< TABLE_SIZE (howto_table_std
));
4889 howto
= howto_table_std
+ howto_idx
;
4895 /* We are generating a relocateable output file, and must
4896 modify the reloc accordingly. */
4899 /* If we know the symbol this relocation is against,
4900 convert it into a relocation against a section. This
4901 is what the native linker does. */
4902 h
= sym_hashes
[r_index
];
4903 if (h
!= (struct aout_link_hash_entry
*) NULL
4904 && (h
->root
.type
== bfd_link_hash_defined
4905 || h
->root
.type
== bfd_link_hash_defweak
))
4907 asection
*output_section
;
4909 /* Change the r_extern value. */
4910 if (bfd_header_big_endian (output_bfd
))
4911 rel
->r_type
[0] &=~ RELOC_STD_BITS_EXTERN_BIG
;
4913 rel
->r_type
[0] &=~ RELOC_STD_BITS_EXTERN_LITTLE
;
4915 /* Compute a new r_index. */
4916 output_section
= h
->root
.u
.def
.section
->output_section
;
4917 if (output_section
== obj_textsec (output_bfd
))
4919 else if (output_section
== obj_datasec (output_bfd
))
4921 else if (output_section
== obj_bsssec (output_bfd
))
4926 /* Add the symbol value and the section VMA to the
4927 addend stored in the contents. */
4928 relocation
= (h
->root
.u
.def
.value
4929 + output_section
->vma
4930 + h
->root
.u
.def
.section
->output_offset
);
4934 /* We must change r_index according to the symbol
4936 r_index
= symbol_map
[r_index
];
4942 /* We decided to strip this symbol, but it
4943 turns out that we can't. Note that we
4944 lose the other and desc information here.
4945 I don't think that will ever matter for a
4951 if (! aout_link_write_other_symbol (h
,
4961 name
= strings
+ GET_WORD (input_bfd
,
4962 syms
[r_index
].e_strx
);
4963 if (! ((*finfo
->info
->callbacks
->unattached_reloc
)
4964 (finfo
->info
, name
, input_bfd
, input_section
,
4974 /* Write out the new r_index value. */
4975 if (bfd_header_big_endian (output_bfd
))
4977 rel
->r_index
[0] = r_index
>> 16;
4978 rel
->r_index
[1] = r_index
>> 8;
4979 rel
->r_index
[2] = r_index
;
4983 rel
->r_index
[2] = r_index
>> 16;
4984 rel
->r_index
[1] = r_index
>> 8;
4985 rel
->r_index
[0] = r_index
;
4992 /* This is a relocation against a section. We must
4993 adjust by the amount that the section moved. */
4994 section
= aout_reloc_index_to_section (input_bfd
, r_index
);
4995 relocation
= (section
->output_section
->vma
4996 + section
->output_offset
5000 /* Change the address of the relocation. */
5001 PUT_WORD (output_bfd
,
5002 r_addr
+ input_section
->output_offset
,
5005 /* Adjust a PC relative relocation by removing the reference
5006 to the original address in the section and including the
5007 reference to the new address. */
5009 relocation
-= (input_section
->output_section
->vma
5010 + input_section
->output_offset
5011 - input_section
->vma
);
5013 #ifdef MY_relocatable_reloc
5014 MY_relocatable_reloc (howto
, output_bfd
, rel
, relocation
, r_addr
);
5017 if (relocation
== 0)
5020 r
= MY_relocate_contents (howto
,
5021 input_bfd
, relocation
,
5028 /* We are generating an executable, and must do a full
5034 h
= sym_hashes
[r_index
];
5036 if (h
!= (struct aout_link_hash_entry
*) NULL
5037 && (h
->root
.type
== bfd_link_hash_defined
5038 || h
->root
.type
== bfd_link_hash_defweak
))
5040 relocation
= (h
->root
.u
.def
.value
5041 + h
->root
.u
.def
.section
->output_section
->vma
5042 + h
->root
.u
.def
.section
->output_offset
);
5044 else if (h
!= (struct aout_link_hash_entry
*) NULL
5045 && h
->root
.type
== bfd_link_hash_undefweak
)
5057 section
= aout_reloc_index_to_section (input_bfd
, r_index
);
5058 relocation
= (section
->output_section
->vma
5059 + section
->output_offset
5062 relocation
+= input_section
->vma
;
5065 if (check_dynamic_reloc
!= NULL
)
5069 if (! ((*check_dynamic_reloc
)
5070 (finfo
->info
, input_bfd
, input_section
, h
,
5071 (PTR
) rel
, contents
, &skip
, &relocation
)))
5077 /* Now warn if a global symbol is undefined. We could not
5078 do this earlier, because check_dynamic_reloc might want
5079 to skip this reloc. */
5080 if (hundef
&& ! finfo
->info
->shared
&& ! r_baserel
)
5085 name
= h
->root
.root
.string
;
5087 name
= strings
+ GET_WORD (input_bfd
, syms
[r_index
].e_strx
);
5088 if (! ((*finfo
->info
->callbacks
->undefined_symbol
)
5089 (finfo
->info
, name
, input_bfd
, input_section
,
5094 r
= MY_final_link_relocate (howto
,
5095 input_bfd
, input_section
,
5096 contents
, r_addr
, relocation
,
5100 if (r
!= bfd_reloc_ok
)
5105 case bfd_reloc_outofrange
:
5107 case bfd_reloc_overflow
:
5112 name
= h
->root
.root
.string
;
5114 name
= strings
+ GET_WORD (input_bfd
,
5115 syms
[r_index
].e_strx
);
5120 s
= aout_reloc_index_to_section (input_bfd
, r_index
);
5121 name
= bfd_section_name (input_bfd
, s
);
5123 if (! ((*finfo
->info
->callbacks
->reloc_overflow
)
5124 (finfo
->info
, name
, howto
->name
,
5125 (bfd_vma
) 0, input_bfd
, input_section
, r_addr
)))
5136 /* Relocate an a.out section using extended a.out relocs. */
5139 aout_link_input_section_ext (finfo
, input_bfd
, input_section
, relocs
,
5141 struct aout_final_link_info
*finfo
;
5143 asection
*input_section
;
5144 struct reloc_ext_external
*relocs
;
5145 bfd_size_type rel_size
;
5148 boolean (*check_dynamic_reloc
) PARAMS ((struct bfd_link_info
*,
5150 struct aout_link_hash_entry
*,
5151 PTR
, bfd_byte
*, boolean
*,
5154 boolean relocateable
;
5155 struct external_nlist
*syms
;
5157 struct aout_link_hash_entry
**sym_hashes
;
5159 bfd_size_type reloc_count
;
5160 register struct reloc_ext_external
*rel
;
5161 struct reloc_ext_external
*rel_end
;
5163 output_bfd
= finfo
->output_bfd
;
5164 check_dynamic_reloc
= aout_backend_info (output_bfd
)->check_dynamic_reloc
;
5166 BFD_ASSERT (obj_reloc_entry_size (input_bfd
) == RELOC_EXT_SIZE
);
5167 BFD_ASSERT (input_bfd
->xvec
->header_byteorder
5168 == output_bfd
->xvec
->header_byteorder
);
5170 relocateable
= finfo
->info
->relocateable
;
5171 syms
= obj_aout_external_syms (input_bfd
);
5172 strings
= obj_aout_external_strings (input_bfd
);
5173 sym_hashes
= obj_aout_sym_hashes (input_bfd
);
5174 symbol_map
= finfo
->symbol_map
;
5176 reloc_count
= rel_size
/ RELOC_EXT_SIZE
;
5178 rel_end
= rel
+ reloc_count
;
5179 for (; rel
< rel_end
; rel
++)
5184 unsigned int r_type
;
5186 struct aout_link_hash_entry
*h
= NULL
;
5187 asection
*r_section
= NULL
;
5190 r_addr
= GET_SWORD (input_bfd
, rel
->r_address
);
5192 if (bfd_header_big_endian (input_bfd
))
5194 r_index
= ((rel
->r_index
[0] << 16)
5195 | (rel
->r_index
[1] << 8)
5197 r_extern
= (0 != (rel
->r_type
[0] & RELOC_EXT_BITS_EXTERN_BIG
));
5198 r_type
= ((rel
->r_type
[0] & RELOC_EXT_BITS_TYPE_BIG
)
5199 >> RELOC_EXT_BITS_TYPE_SH_BIG
);
5203 r_index
= ((rel
->r_index
[2] << 16)
5204 | (rel
->r_index
[1] << 8)
5206 r_extern
= (0 != (rel
->r_type
[0] & RELOC_EXT_BITS_EXTERN_LITTLE
));
5207 r_type
= ((rel
->r_type
[0] & RELOC_EXT_BITS_TYPE_LITTLE
)
5208 >> RELOC_EXT_BITS_TYPE_SH_LITTLE
);
5211 r_addend
= GET_SWORD (input_bfd
, rel
->r_addend
);
5213 BFD_ASSERT (r_type
< TABLE_SIZE (howto_table_ext
));
5217 /* We are generating a relocateable output file, and must
5218 modify the reloc accordingly. */
5220 || r_type
== RELOC_BASE10
5221 || r_type
== RELOC_BASE13
5222 || r_type
== RELOC_BASE22
)
5224 /* If we know the symbol this relocation is against,
5225 convert it into a relocation against a section. This
5226 is what the native linker does. */
5227 if (r_type
== RELOC_BASE10
5228 || r_type
== RELOC_BASE13
5229 || r_type
== RELOC_BASE22
)
5232 h
= sym_hashes
[r_index
];
5233 if (h
!= (struct aout_link_hash_entry
*) NULL
5234 && (h
->root
.type
== bfd_link_hash_defined
5235 || h
->root
.type
== bfd_link_hash_defweak
))
5237 asection
*output_section
;
5239 /* Change the r_extern value. */
5240 if (bfd_header_big_endian (output_bfd
))
5241 rel
->r_type
[0] &=~ RELOC_EXT_BITS_EXTERN_BIG
;
5243 rel
->r_type
[0] &=~ RELOC_EXT_BITS_EXTERN_LITTLE
;
5245 /* Compute a new r_index. */
5246 output_section
= h
->root
.u
.def
.section
->output_section
;
5247 if (output_section
== obj_textsec (output_bfd
))
5249 else if (output_section
== obj_datasec (output_bfd
))
5251 else if (output_section
== obj_bsssec (output_bfd
))
5256 /* Add the symbol value and the section VMA to the
5258 relocation
= (h
->root
.u
.def
.value
5259 + output_section
->vma
5260 + h
->root
.u
.def
.section
->output_offset
);
5262 /* Now RELOCATION is the VMA of the final
5263 destination. If this is a PC relative reloc,
5264 then ADDEND is the negative of the source VMA.
5265 We want to set ADDEND to the difference between
5266 the destination VMA and the source VMA, which
5267 means we must adjust RELOCATION by the change in
5268 the source VMA. This is done below. */
5272 /* We must change r_index according to the symbol
5274 r_index
= symbol_map
[r_index
];
5280 /* We decided to strip this symbol, but it
5281 turns out that we can't. Note that we
5282 lose the other and desc information here.
5283 I don't think that will ever matter for a
5289 if (! aout_link_write_other_symbol (h
,
5299 name
= strings
+ GET_WORD (input_bfd
,
5300 syms
[r_index
].e_strx
);
5301 if (! ((*finfo
->info
->callbacks
->unattached_reloc
)
5302 (finfo
->info
, name
, input_bfd
, input_section
,
5311 /* If this is a PC relative reloc, then the addend
5312 is the negative of the source VMA. We must
5313 adjust it by the change in the source VMA. This
5317 /* Write out the new r_index value. */
5318 if (bfd_header_big_endian (output_bfd
))
5320 rel
->r_index
[0] = r_index
>> 16;
5321 rel
->r_index
[1] = r_index
>> 8;
5322 rel
->r_index
[2] = r_index
;
5326 rel
->r_index
[2] = r_index
>> 16;
5327 rel
->r_index
[1] = r_index
>> 8;
5328 rel
->r_index
[0] = r_index
;
5333 /* This is a relocation against a section. We must
5334 adjust by the amount that the section moved. */
5335 r_section
= aout_reloc_index_to_section (input_bfd
, r_index
);
5336 relocation
= (r_section
->output_section
->vma
5337 + r_section
->output_offset
5340 /* If this is a PC relative reloc, then the addend is
5341 the difference in VMA between the destination and the
5342 source. We have just adjusted for the change in VMA
5343 of the destination, so we must also adjust by the
5344 change in VMA of the source. This is done below. */
5347 /* As described above, we must always adjust a PC relative
5348 reloc by the change in VMA of the source. However, if
5349 pcrel_offset is set, then the addend does not include the
5350 location within the section, in which case we don't need
5351 to adjust anything. */
5352 if (howto_table_ext
[r_type
].pc_relative
5353 && ! howto_table_ext
[r_type
].pcrel_offset
)
5354 relocation
-= (input_section
->output_section
->vma
5355 + input_section
->output_offset
5356 - input_section
->vma
);
5358 /* Change the addend if necessary. */
5359 if (relocation
!= 0)
5360 PUT_WORD (output_bfd
, r_addend
+ relocation
, rel
->r_addend
);
5362 /* Change the address of the relocation. */
5363 PUT_WORD (output_bfd
,
5364 r_addr
+ input_section
->output_offset
,
5370 bfd_reloc_status_type r
;
5372 /* We are generating an executable, and must do a full
5378 h
= sym_hashes
[r_index
];
5380 if (h
!= (struct aout_link_hash_entry
*) NULL
5381 && (h
->root
.type
== bfd_link_hash_defined
5382 || h
->root
.type
== bfd_link_hash_defweak
))
5384 relocation
= (h
->root
.u
.def
.value
5385 + h
->root
.u
.def
.section
->output_section
->vma
5386 + h
->root
.u
.def
.section
->output_offset
);
5388 else if (h
!= (struct aout_link_hash_entry
*) NULL
5389 && h
->root
.type
== bfd_link_hash_undefweak
)
5397 else if (r_type
== RELOC_BASE10
5398 || r_type
== RELOC_BASE13
5399 || r_type
== RELOC_BASE22
)
5401 struct external_nlist
*sym
;
5404 /* For base relative relocs, r_index is always an index
5405 into the symbol table, even if r_extern is 0. */
5406 sym
= syms
+ r_index
;
5407 type
= H_GET_8 (input_bfd
, sym
->e_type
);
5408 if ((type
& N_TYPE
) == N_TEXT
5410 r_section
= obj_textsec (input_bfd
);
5411 else if ((type
& N_TYPE
) == N_DATA
5413 r_section
= obj_datasec (input_bfd
);
5414 else if ((type
& N_TYPE
) == N_BSS
5416 r_section
= obj_bsssec (input_bfd
);
5417 else if ((type
& N_TYPE
) == N_ABS
5419 r_section
= bfd_abs_section_ptr
;
5422 relocation
= (r_section
->output_section
->vma
5423 + r_section
->output_offset
5424 + (GET_WORD (input_bfd
, sym
->e_value
)
5429 r_section
= aout_reloc_index_to_section (input_bfd
, r_index
);
5431 /* If this is a PC relative reloc, then R_ADDEND is the
5432 difference between the two vmas, or
5433 old_dest_sec + old_dest_off - (old_src_sec + old_src_off)
5435 old_dest_sec == section->vma
5437 old_src_sec == input_section->vma
5439 old_src_off == r_addr
5441 _bfd_final_link_relocate expects RELOCATION +
5442 R_ADDEND to be the VMA of the destination minus
5443 r_addr (the minus r_addr is because this relocation
5444 is not pcrel_offset, which is a bit confusing and
5445 should, perhaps, be changed), or
5448 new_dest_sec == output_section->vma + output_offset
5449 We arrange for this to happen by setting RELOCATION to
5450 new_dest_sec + old_src_sec - old_dest_sec
5452 If this is not a PC relative reloc, then R_ADDEND is
5453 simply the VMA of the destination, so we set
5454 RELOCATION to the change in the destination VMA, or
5455 new_dest_sec - old_dest_sec
5457 relocation
= (r_section
->output_section
->vma
5458 + r_section
->output_offset
5460 if (howto_table_ext
[r_type
].pc_relative
)
5461 relocation
+= input_section
->vma
;
5464 if (check_dynamic_reloc
!= NULL
)
5468 if (! ((*check_dynamic_reloc
)
5469 (finfo
->info
, input_bfd
, input_section
, h
,
5470 (PTR
) rel
, contents
, &skip
, &relocation
)))
5476 /* Now warn if a global symbol is undefined. We could not
5477 do this earlier, because check_dynamic_reloc might want
5478 to skip this reloc. */
5480 && ! finfo
->info
->shared
5481 && r_type
!= RELOC_BASE10
5482 && r_type
!= RELOC_BASE13
5483 && r_type
!= RELOC_BASE22
)
5488 name
= h
->root
.root
.string
;
5490 name
= strings
+ GET_WORD (input_bfd
, syms
[r_index
].e_strx
);
5491 if (! ((*finfo
->info
->callbacks
->undefined_symbol
)
5492 (finfo
->info
, name
, input_bfd
, input_section
,
5497 if (r_type
!= RELOC_SPARC_REV32
)
5498 r
= MY_final_link_relocate (howto_table_ext
+ r_type
,
5499 input_bfd
, input_section
,
5500 contents
, r_addr
, relocation
,
5506 x
= bfd_get_32 (input_bfd
, contents
+ r_addr
);
5507 x
= x
+ relocation
+ r_addend
;
5508 bfd_putl32 (/*input_bfd,*/ x
, contents
+ r_addr
);
5512 if (r
!= bfd_reloc_ok
)
5517 case bfd_reloc_outofrange
:
5519 case bfd_reloc_overflow
:
5524 name
= h
->root
.root
.string
;
5526 || r_type
== RELOC_BASE10
5527 || r_type
== RELOC_BASE13
5528 || r_type
== RELOC_BASE22
)
5529 name
= strings
+ GET_WORD (input_bfd
,
5530 syms
[r_index
].e_strx
);
5535 s
= aout_reloc_index_to_section (input_bfd
, r_index
);
5536 name
= bfd_section_name (input_bfd
, s
);
5538 if (! ((*finfo
->info
->callbacks
->reloc_overflow
)
5539 (finfo
->info
, name
, howto_table_ext
[r_type
].name
,
5540 r_addend
, input_bfd
, input_section
, r_addr
)))
5552 /* Handle a link order which is supposed to generate a reloc. */
5555 aout_link_reloc_link_order (finfo
, o
, p
)
5556 struct aout_final_link_info
*finfo
;
5558 struct bfd_link_order
*p
;
5560 struct bfd_link_order_reloc
*pr
;
5563 reloc_howto_type
*howto
;
5564 file_ptr
*reloff_ptr
= NULL
;
5565 struct reloc_std_external srel
;
5566 struct reloc_ext_external erel
;
5572 if (p
->type
== bfd_section_reloc_link_order
)
5575 if (bfd_is_abs_section (pr
->u
.section
))
5576 r_index
= N_ABS
| N_EXT
;
5579 BFD_ASSERT (pr
->u
.section
->owner
== finfo
->output_bfd
);
5580 r_index
= pr
->u
.section
->target_index
;
5585 struct aout_link_hash_entry
*h
;
5587 BFD_ASSERT (p
->type
== bfd_symbol_reloc_link_order
);
5589 h
= ((struct aout_link_hash_entry
*)
5590 bfd_wrapped_link_hash_lookup (finfo
->output_bfd
, finfo
->info
,
5591 pr
->u
.name
, false, false, true));
5592 if (h
!= (struct aout_link_hash_entry
*) NULL
5597 /* We decided to strip this symbol, but it turns out that we
5598 can't. Note that we lose the other and desc information
5599 here. I don't think that will ever matter for a global
5603 if (! aout_link_write_other_symbol (h
, (PTR
) finfo
))
5609 if (! ((*finfo
->info
->callbacks
->unattached_reloc
)
5610 (finfo
->info
, pr
->u
.name
, (bfd
*) NULL
,
5611 (asection
*) NULL
, (bfd_vma
) 0)))
5617 howto
= bfd_reloc_type_lookup (finfo
->output_bfd
, pr
->reloc
);
5620 bfd_set_error (bfd_error_bad_value
);
5624 if (o
== obj_textsec (finfo
->output_bfd
))
5625 reloff_ptr
= &finfo
->treloff
;
5626 else if (o
== obj_datasec (finfo
->output_bfd
))
5627 reloff_ptr
= &finfo
->dreloff
;
5631 if (obj_reloc_entry_size (finfo
->output_bfd
) == RELOC_STD_SIZE
)
5634 MY_put_reloc (finfo
->output_bfd
, r_extern
, r_index
, p
->offset
, howto
,
5644 r_pcrel
= howto
->pc_relative
;
5645 r_baserel
= (howto
->type
& 8) != 0;
5646 r_jmptable
= (howto
->type
& 16) != 0;
5647 r_relative
= (howto
->type
& 32) != 0;
5648 r_length
= howto
->size
;
5650 PUT_WORD (finfo
->output_bfd
, p
->offset
, srel
.r_address
);
5651 if (bfd_header_big_endian (finfo
->output_bfd
))
5653 srel
.r_index
[0] = r_index
>> 16;
5654 srel
.r_index
[1] = r_index
>> 8;
5655 srel
.r_index
[2] = r_index
;
5657 ((r_extern
? RELOC_STD_BITS_EXTERN_BIG
: 0)
5658 | (r_pcrel
? RELOC_STD_BITS_PCREL_BIG
: 0)
5659 | (r_baserel
? RELOC_STD_BITS_BASEREL_BIG
: 0)
5660 | (r_jmptable
? RELOC_STD_BITS_JMPTABLE_BIG
: 0)
5661 | (r_relative
? RELOC_STD_BITS_RELATIVE_BIG
: 0)
5662 | (r_length
<< RELOC_STD_BITS_LENGTH_SH_BIG
));
5666 srel
.r_index
[2] = r_index
>> 16;
5667 srel
.r_index
[1] = r_index
>> 8;
5668 srel
.r_index
[0] = r_index
;
5670 ((r_extern
? RELOC_STD_BITS_EXTERN_LITTLE
: 0)
5671 | (r_pcrel
? RELOC_STD_BITS_PCREL_LITTLE
: 0)
5672 | (r_baserel
? RELOC_STD_BITS_BASEREL_LITTLE
: 0)
5673 | (r_jmptable
? RELOC_STD_BITS_JMPTABLE_LITTLE
: 0)
5674 | (r_relative
? RELOC_STD_BITS_RELATIVE_LITTLE
: 0)
5675 | (r_length
<< RELOC_STD_BITS_LENGTH_SH_LITTLE
));
5679 rel_ptr
= (PTR
) &srel
;
5681 /* We have to write the addend into the object file, since
5682 standard a.out relocs are in place. It would be more
5683 reliable if we had the current contents of the file here,
5684 rather than assuming zeroes, but we can't read the file since
5685 it was opened using bfd_openw. */
5686 if (pr
->addend
!= 0)
5689 bfd_reloc_status_type r
;
5693 size
= bfd_get_reloc_size (howto
);
5694 buf
= (bfd_byte
*) bfd_zmalloc (size
);
5695 if (buf
== (bfd_byte
*) NULL
)
5697 r
= MY_relocate_contents (howto
, finfo
->output_bfd
,
5698 (bfd_vma
) pr
->addend
, buf
);
5704 case bfd_reloc_outofrange
:
5706 case bfd_reloc_overflow
:
5707 if (! ((*finfo
->info
->callbacks
->reloc_overflow
)
5709 (p
->type
== bfd_section_reloc_link_order
5710 ? bfd_section_name (finfo
->output_bfd
,
5713 howto
->name
, pr
->addend
, (bfd
*) NULL
,
5714 (asection
*) NULL
, (bfd_vma
) 0)))
5721 ok
= bfd_set_section_contents (finfo
->output_bfd
, o
, (PTR
) buf
,
5722 (file_ptr
) p
->offset
, size
);
5730 #ifdef MY_put_ext_reloc
5731 MY_put_ext_reloc (finfo
->output_bfd
, r_extern
, r_index
, p
->offset
,
5732 howto
, &erel
, pr
->addend
);
5734 PUT_WORD (finfo
->output_bfd
, p
->offset
, erel
.r_address
);
5736 if (bfd_header_big_endian (finfo
->output_bfd
))
5738 erel
.r_index
[0] = r_index
>> 16;
5739 erel
.r_index
[1] = r_index
>> 8;
5740 erel
.r_index
[2] = r_index
;
5742 ((r_extern
? RELOC_EXT_BITS_EXTERN_BIG
: 0)
5743 | (howto
->type
<< RELOC_EXT_BITS_TYPE_SH_BIG
));
5747 erel
.r_index
[2] = r_index
>> 16;
5748 erel
.r_index
[1] = r_index
>> 8;
5749 erel
.r_index
[0] = r_index
;
5751 (r_extern
? RELOC_EXT_BITS_EXTERN_LITTLE
: 0)
5752 | (howto
->type
<< RELOC_EXT_BITS_TYPE_SH_LITTLE
);
5755 PUT_WORD (finfo
->output_bfd
, (bfd_vma
) pr
->addend
, erel
.r_addend
);
5756 #endif /* MY_put_ext_reloc */
5758 rel_ptr
= (PTR
) &erel
;
5761 amt
= obj_reloc_entry_size (finfo
->output_bfd
);
5762 if (bfd_seek (finfo
->output_bfd
, *reloff_ptr
, SEEK_SET
) != 0
5763 || bfd_bwrite (rel_ptr
, amt
, finfo
->output_bfd
) != amt
)
5766 *reloff_ptr
+= obj_reloc_entry_size (finfo
->output_bfd
);
5768 /* Assert that the relocs have not run into the symbols, and that n
5769 the text relocs have not run into the data relocs. */
5770 BFD_ASSERT (*reloff_ptr
<= obj_sym_filepos (finfo
->output_bfd
)
5771 && (reloff_ptr
!= &finfo
->treloff
5773 <= obj_datasec (finfo
->output_bfd
)->rel_filepos
)));