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. */
111 * Any BFD with D_PAGED set is ZMAGIC, and vice versa.
112 Doesn't matter what the setting of WP_TEXT is on output, but it'll
114 * Any BFD with D_PAGED clear and WP_TEXT set is NMAGIC.
115 * Any BFD with both flags clear is OMAGIC.
116 (Just want to make these explicit, so the conditions tested in this
117 file make sense if you're more familiar with a.out than with BFD.) */
119 #define KEEPIT udata.i
123 #include "safe-ctype.h"
128 #include "aout/aout64.h"
129 #include "aout/stab_gnu.h"
132 static bfd_boolean aout_get_external_symbols
134 static bfd_boolean translate_from_native_sym_flags
135 PARAMS ((bfd
*, aout_symbol_type
*));
136 static bfd_boolean translate_to_native_sym_flags
137 PARAMS ((bfd
*, asymbol
*, struct external_nlist
*));
138 static void adjust_o_magic
139 PARAMS ((bfd
*, struct internal_exec
*));
140 static void adjust_z_magic
141 PARAMS ((bfd
*, struct internal_exec
*));
142 static void adjust_n_magic
143 PARAMS ((bfd
*, struct internal_exec
*));
144 reloc_howto_type
* NAME(aout
,reloc_type_lookup
)
145 PARAMS ((bfd
*, bfd_reloc_code_real_type
));
152 The file @file{aoutx.h} provides for both the @emph{standard}
153 and @emph{extended} forms of a.out relocation records.
155 The standard records contain only an
156 address, a symbol index, and a type field. The extended records
157 (used on 29ks and sparcs) also have a full integer for an
160 #ifndef CTOR_TABLE_RELOC_HOWTO
161 #define CTOR_TABLE_RELOC_IDX 2
162 #define CTOR_TABLE_RELOC_HOWTO(BFD) \
163 ((obj_reloc_entry_size (BFD) == RELOC_EXT_SIZE \
164 ? howto_table_ext : howto_table_std) \
165 + CTOR_TABLE_RELOC_IDX)
168 #ifndef MY_swap_std_reloc_in
169 #define MY_swap_std_reloc_in NAME(aout,swap_std_reloc_in)
172 #ifndef MY_swap_ext_reloc_in
173 #define MY_swap_ext_reloc_in NAME(aout,swap_ext_reloc_in)
176 #ifndef MY_swap_std_reloc_out
177 #define MY_swap_std_reloc_out NAME(aout,swap_std_reloc_out)
180 #ifndef MY_swap_ext_reloc_out
181 #define MY_swap_ext_reloc_out NAME(aout,swap_ext_reloc_out)
184 #ifndef MY_final_link_relocate
185 #define MY_final_link_relocate _bfd_final_link_relocate
188 #ifndef MY_relocate_contents
189 #define MY_relocate_contents _bfd_relocate_contents
192 #define howto_table_ext NAME(aout,ext_howto_table)
193 #define howto_table_std NAME(aout,std_howto_table)
195 reloc_howto_type howto_table_ext
[] =
197 /* type rs size bsz pcrel bitpos ovrf sf name part_inpl readmask setmask pcdone. */
198 HOWTO(RELOC_8
, 0, 0, 8, FALSE
, 0, complain_overflow_bitfield
,0,"8", FALSE
, 0,0x000000ff, FALSE
),
199 HOWTO(RELOC_16
, 0, 1, 16, FALSE
, 0, complain_overflow_bitfield
,0,"16", FALSE
, 0,0x0000ffff, FALSE
),
200 HOWTO(RELOC_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,0,"32", FALSE
, 0,0xffffffff, FALSE
),
201 HOWTO(RELOC_DISP8
, 0, 0, 8, TRUE
, 0, complain_overflow_signed
,0,"DISP8", FALSE
, 0,0x000000ff, FALSE
),
202 HOWTO(RELOC_DISP16
, 0, 1, 16, TRUE
, 0, complain_overflow_signed
,0,"DISP16", FALSE
, 0,0x0000ffff, FALSE
),
203 HOWTO(RELOC_DISP32
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,0,"DISP32", FALSE
, 0,0xffffffff, FALSE
),
204 HOWTO(RELOC_WDISP30
,2, 2, 30, TRUE
, 0, complain_overflow_signed
,0,"WDISP30", FALSE
, 0,0x3fffffff, FALSE
),
205 HOWTO(RELOC_WDISP22
,2, 2, 22, TRUE
, 0, complain_overflow_signed
,0,"WDISP22", FALSE
, 0,0x003fffff, FALSE
),
206 HOWTO(RELOC_HI22
, 10, 2, 22, FALSE
, 0, complain_overflow_bitfield
,0,"HI22", FALSE
, 0,0x003fffff, FALSE
),
207 HOWTO(RELOC_22
, 0, 2, 22, FALSE
, 0, complain_overflow_bitfield
,0,"22", FALSE
, 0,0x003fffff, FALSE
),
208 HOWTO(RELOC_13
, 0, 2, 13, FALSE
, 0, complain_overflow_bitfield
,0,"13", FALSE
, 0,0x00001fff, FALSE
),
209 HOWTO(RELOC_LO10
, 0, 2, 10, FALSE
, 0, complain_overflow_dont
,0,"LO10", FALSE
, 0,0x000003ff, FALSE
),
210 HOWTO(RELOC_SFA_BASE
,0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,0,"SFA_BASE", FALSE
, 0,0xffffffff, FALSE
),
211 HOWTO(RELOC_SFA_OFF13
,0,2, 32, FALSE
, 0, complain_overflow_bitfield
,0,"SFA_OFF13",FALSE
, 0,0xffffffff, FALSE
),
212 HOWTO(RELOC_BASE10
, 0, 2, 10, FALSE
, 0, complain_overflow_dont
,0,"BASE10", FALSE
, 0,0x000003ff, FALSE
),
213 HOWTO(RELOC_BASE13
, 0, 2, 13, FALSE
, 0, complain_overflow_signed
,0,"BASE13", FALSE
, 0,0x00001fff, FALSE
),
214 HOWTO(RELOC_BASE22
, 10, 2, 22, FALSE
, 0, complain_overflow_bitfield
,0,"BASE22", FALSE
, 0,0x003fffff, FALSE
),
215 HOWTO(RELOC_PC10
, 0, 2, 10, TRUE
, 0, complain_overflow_dont
,0,"PC10", FALSE
, 0,0x000003ff, TRUE
),
216 HOWTO(RELOC_PC22
, 10, 2, 22, TRUE
, 0, complain_overflow_signed
,0,"PC22", FALSE
, 0,0x003fffff, TRUE
),
217 HOWTO(RELOC_JMP_TBL
,2, 2, 30, TRUE
, 0, complain_overflow_signed
,0,"JMP_TBL", FALSE
, 0,0x3fffffff, FALSE
),
218 HOWTO(RELOC_SEGOFF16
,0, 2, 0, FALSE
, 0, complain_overflow_bitfield
,0,"SEGOFF16", FALSE
, 0,0x00000000, FALSE
),
219 HOWTO(RELOC_GLOB_DAT
,0, 2, 0, FALSE
, 0, complain_overflow_bitfield
,0,"GLOB_DAT", FALSE
, 0,0x00000000, FALSE
),
220 HOWTO(RELOC_JMP_SLOT
,0, 2, 0, FALSE
, 0, complain_overflow_bitfield
,0,"JMP_SLOT", FALSE
, 0,0x00000000, FALSE
),
221 HOWTO(RELOC_RELATIVE
,0, 2, 0, FALSE
, 0, complain_overflow_bitfield
,0,"RELATIVE", FALSE
, 0,0x00000000, FALSE
),
222 HOWTO(0, 0, 0, 0, FALSE
, 0, complain_overflow_dont
, 0, "R_SPARC_NONE", FALSE
,0,0x00000000,TRUE
),
223 HOWTO(0, 0, 0, 0, FALSE
, 0, complain_overflow_dont
, 0, "R_SPARC_NONE", FALSE
,0,0x00000000,TRUE
),
224 #define RELOC_SPARC_REV32 RELOC_WDISP19
225 HOWTO(RELOC_SPARC_REV32
, 0, 2, 32, FALSE
, 0, complain_overflow_dont
,0,"R_SPARC_REV32", FALSE
, 0,0xffffffff, FALSE
),
228 /* Convert standard reloc records to "arelent" format (incl byte swap). */
230 reloc_howto_type howto_table_std
[] =
232 /* type rs size bsz pcrel bitpos ovrf sf name part_inpl readmask setmask pcdone. */
233 HOWTO ( 0, 0, 0, 8, FALSE
, 0, complain_overflow_bitfield
,0,"8", TRUE
, 0x000000ff,0x000000ff, FALSE
),
234 HOWTO ( 1, 0, 1, 16, FALSE
, 0, complain_overflow_bitfield
,0,"16", TRUE
, 0x0000ffff,0x0000ffff, FALSE
),
235 HOWTO ( 2, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,0,"32", TRUE
, 0xffffffff,0xffffffff, FALSE
),
236 HOWTO ( 3, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,0,"64", TRUE
, 0xdeaddead,0xdeaddead, FALSE
),
237 HOWTO ( 4, 0, 0, 8, TRUE
, 0, complain_overflow_signed
, 0,"DISP8", TRUE
, 0x000000ff,0x000000ff, FALSE
),
238 HOWTO ( 5, 0, 1, 16, TRUE
, 0, complain_overflow_signed
, 0,"DISP16", TRUE
, 0x0000ffff,0x0000ffff, FALSE
),
239 HOWTO ( 6, 0, 2, 32, TRUE
, 0, complain_overflow_signed
, 0,"DISP32", TRUE
, 0xffffffff,0xffffffff, FALSE
),
240 HOWTO ( 7, 0, 4, 64, TRUE
, 0, complain_overflow_signed
, 0,"DISP64", TRUE
, 0xfeedface,0xfeedface, FALSE
),
241 HOWTO ( 8, 0, 2, 0, FALSE
, 0, complain_overflow_bitfield
,0,"GOT_REL", FALSE
, 0,0x00000000, FALSE
),
242 HOWTO ( 9, 0, 1, 16, FALSE
, 0, complain_overflow_bitfield
,0,"BASE16", FALSE
,0xffffffff,0xffffffff, FALSE
),
243 HOWTO (10, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,0,"BASE32", FALSE
,0xffffffff,0xffffffff, FALSE
),
249 HOWTO (16, 0, 2, 0, FALSE
, 0, complain_overflow_bitfield
,0,"JMP_TABLE", FALSE
, 0,0x00000000, FALSE
),
265 HOWTO (32, 0, 2, 0, FALSE
, 0, complain_overflow_bitfield
,0,"RELATIVE", FALSE
, 0,0x00000000, FALSE
),
273 HOWTO (40, 0, 2, 0, FALSE
, 0, complain_overflow_bitfield
,0,"BASEREL", FALSE
, 0,0x00000000, FALSE
),
276 #define TABLE_SIZE(TABLE) (sizeof (TABLE) / sizeof (TABLE[0]))
279 NAME(aout
,reloc_type_lookup
) (abfd
,code
)
281 bfd_reloc_code_real_type code
;
283 #define EXT(i, j) case i: return &howto_table_ext[j]
284 #define STD(i, j) case i: return &howto_table_std[j]
285 int ext
= obj_reloc_entry_size (abfd
) == RELOC_EXT_SIZE
;
287 if (code
== BFD_RELOC_CTOR
)
288 switch (bfd_get_arch_info (abfd
)->bits_per_address
)
301 EXT (BFD_RELOC_8
, 0);
302 EXT (BFD_RELOC_16
, 1);
303 EXT (BFD_RELOC_32
, 2);
304 EXT (BFD_RELOC_HI22
, 8);
305 EXT (BFD_RELOC_LO10
, 11);
306 EXT (BFD_RELOC_32_PCREL_S2
, 6);
307 EXT (BFD_RELOC_SPARC_WDISP22
, 7);
308 EXT (BFD_RELOC_SPARC13
, 10);
309 EXT (BFD_RELOC_SPARC_GOT10
, 14);
310 EXT (BFD_RELOC_SPARC_BASE13
, 15);
311 EXT (BFD_RELOC_SPARC_GOT13
, 15);
312 EXT (BFD_RELOC_SPARC_GOT22
, 16);
313 EXT (BFD_RELOC_SPARC_PC10
, 17);
314 EXT (BFD_RELOC_SPARC_PC22
, 18);
315 EXT (BFD_RELOC_SPARC_WPLT30
, 19);
316 EXT (BFD_RELOC_SPARC_REV32
, 26);
317 default: return (reloc_howto_type
*) NULL
;
323 STD (BFD_RELOC_8
, 0);
324 STD (BFD_RELOC_16
, 1);
325 STD (BFD_RELOC_32
, 2);
326 STD (BFD_RELOC_8_PCREL
, 4);
327 STD (BFD_RELOC_16_PCREL
, 5);
328 STD (BFD_RELOC_32_PCREL
, 6);
329 STD (BFD_RELOC_16_BASEREL
, 9);
330 STD (BFD_RELOC_32_BASEREL
, 10);
331 default: return (reloc_howto_type
*) NULL
;
337 Internal entry points
340 @file{aoutx.h} exports several routines for accessing the
341 contents of an a.out file, which are gathered and exported in
342 turn by various format specific files (eg sunos.c).
348 aout_@var{size}_swap_exec_header_in
351 void aout_@var{size}_swap_exec_header_in,
353 struct external_exec *raw_bytes,
354 struct internal_exec *execp);
357 Swap the information in an executable header @var{raw_bytes} taken
358 from a raw byte stream memory image into the internal exec header
359 structure @var{execp}.
362 #ifndef NAME_swap_exec_header_in
364 NAME(aout
,swap_exec_header_in
) (abfd
, raw_bytes
, execp
)
366 struct external_exec
*raw_bytes
;
367 struct internal_exec
*execp
;
369 struct external_exec
*bytes
= (struct external_exec
*)raw_bytes
;
371 /* The internal_exec structure has some fields that are unused in this
372 configuration (IE for i960), so ensure that all such uninitialized
373 fields are zero'd out. There are places where two of these structs
374 are memcmp'd, and thus the contents do matter. */
375 memset ((PTR
) execp
, 0, sizeof (struct internal_exec
));
376 /* Now fill in fields in the execp, from the bytes in the raw data. */
377 execp
->a_info
= H_GET_32 (abfd
, bytes
->e_info
);
378 execp
->a_text
= GET_WORD (abfd
, bytes
->e_text
);
379 execp
->a_data
= GET_WORD (abfd
, bytes
->e_data
);
380 execp
->a_bss
= GET_WORD (abfd
, bytes
->e_bss
);
381 execp
->a_syms
= GET_WORD (abfd
, bytes
->e_syms
);
382 execp
->a_entry
= GET_WORD (abfd
, bytes
->e_entry
);
383 execp
->a_trsize
= GET_WORD (abfd
, bytes
->e_trsize
);
384 execp
->a_drsize
= GET_WORD (abfd
, bytes
->e_drsize
);
386 #define NAME_swap_exec_header_in NAME(aout,swap_exec_header_in)
391 aout_@var{size}_swap_exec_header_out
394 void aout_@var{size}_swap_exec_header_out
396 struct internal_exec *execp,
397 struct external_exec *raw_bytes);
400 Swap the information in an internal exec header structure
401 @var{execp} into the buffer @var{raw_bytes} ready for writing to disk.
404 NAME(aout
,swap_exec_header_out
) (abfd
, execp
, raw_bytes
)
406 struct internal_exec
*execp
;
407 struct external_exec
*raw_bytes
;
409 struct external_exec
*bytes
= (struct external_exec
*)raw_bytes
;
411 /* Now fill in fields in the raw data, from the fields in the exec struct. */
412 H_PUT_32 (abfd
, execp
->a_info
, bytes
->e_info
);
413 PUT_WORD (abfd
, execp
->a_text
, bytes
->e_text
);
414 PUT_WORD (abfd
, execp
->a_data
, bytes
->e_data
);
415 PUT_WORD (abfd
, execp
->a_bss
, bytes
->e_bss
);
416 PUT_WORD (abfd
, execp
->a_syms
, bytes
->e_syms
);
417 PUT_WORD (abfd
, execp
->a_entry
, bytes
->e_entry
);
418 PUT_WORD (abfd
, execp
->a_trsize
, bytes
->e_trsize
);
419 PUT_WORD (abfd
, execp
->a_drsize
, bytes
->e_drsize
);
422 /* Make all the section for an a.out file. */
425 NAME(aout
,make_sections
) (abfd
)
428 if (obj_textsec (abfd
) == (asection
*) NULL
429 && bfd_make_section (abfd
, ".text") == (asection
*) NULL
)
431 if (obj_datasec (abfd
) == (asection
*) NULL
432 && bfd_make_section (abfd
, ".data") == (asection
*) NULL
)
434 if (obj_bsssec (abfd
) == (asection
*) NULL
435 && bfd_make_section (abfd
, ".bss") == (asection
*) NULL
)
442 aout_@var{size}_some_aout_object_p
445 const bfd_target *aout_@var{size}_some_aout_object_p
447 const bfd_target *(*callback_to_real_object_p) ());
450 Some a.out variant thinks that the file open in @var{abfd}
451 checking is an a.out file. Do some more checking, and set up
452 for access if it really is. Call back to the calling
453 environment's "finish up" function just before returning, to
454 handle any last-minute setup.
458 NAME(aout
,some_aout_object_p
) (abfd
, execp
, callback_to_real_object_p
)
460 struct internal_exec
*execp
;
461 const bfd_target
*(*callback_to_real_object_p
) PARAMS ((bfd
*));
463 struct aout_data_struct
*rawptr
, *oldrawptr
;
464 const bfd_target
*result
;
465 bfd_size_type amt
= sizeof (struct aout_data_struct
);
467 rawptr
= (struct aout_data_struct
*) bfd_zalloc (abfd
, amt
);
471 oldrawptr
= abfd
->tdata
.aout_data
;
472 abfd
->tdata
.aout_data
= rawptr
;
474 /* Copy the contents of the old tdata struct.
475 In particular, we want the subformat, since for hpux it was set in
476 hp300hpux.c:swap_exec_header_in and will be used in
477 hp300hpux.c:callback. */
478 if (oldrawptr
!= NULL
)
479 *abfd
->tdata
.aout_data
= *oldrawptr
;
481 abfd
->tdata
.aout_data
->a
.hdr
= &rawptr
->e
;
482 /* Copy in the internal_exec struct. */
483 *(abfd
->tdata
.aout_data
->a
.hdr
) = *execp
;
484 execp
= abfd
->tdata
.aout_data
->a
.hdr
;
486 /* Set the file flags. */
487 abfd
->flags
= BFD_NO_FLAGS
;
488 if (execp
->a_drsize
|| execp
->a_trsize
)
489 abfd
->flags
|= HAS_RELOC
;
490 /* Setting of EXEC_P has been deferred to the bottom of this function. */
492 abfd
->flags
|= HAS_LINENO
| HAS_DEBUG
| HAS_SYMS
| HAS_LOCALS
;
493 if (N_DYNAMIC (*execp
))
494 abfd
->flags
|= DYNAMIC
;
496 if (N_MAGIC (*execp
) == ZMAGIC
)
498 abfd
->flags
|= D_PAGED
| WP_TEXT
;
499 adata (abfd
).magic
= z_magic
;
501 else if (N_MAGIC (*execp
) == QMAGIC
)
503 abfd
->flags
|= D_PAGED
| WP_TEXT
;
504 adata (abfd
).magic
= z_magic
;
505 adata (abfd
).subformat
= q_magic_format
;
507 else if (N_MAGIC (*execp
) == NMAGIC
)
509 abfd
->flags
|= WP_TEXT
;
510 adata (abfd
).magic
= n_magic
;
512 else if (N_MAGIC (*execp
) == OMAGIC
513 || N_MAGIC (*execp
) == BMAGIC
)
514 adata (abfd
).magic
= o_magic
;
517 /* Should have been checked with N_BADMAG before this routine
522 bfd_get_start_address (abfd
) = execp
->a_entry
;
524 obj_aout_symbols (abfd
) = (aout_symbol_type
*)NULL
;
525 bfd_get_symcount (abfd
) = execp
->a_syms
/ sizeof (struct external_nlist
);
527 /* The default relocation entry size is that of traditional V7 Unix. */
528 obj_reloc_entry_size (abfd
) = RELOC_STD_SIZE
;
530 /* The default symbol entry size is that of traditional Unix. */
531 obj_symbol_entry_size (abfd
) = EXTERNAL_NLIST_SIZE
;
534 bfd_init_window (&obj_aout_sym_window (abfd
));
535 bfd_init_window (&obj_aout_string_window (abfd
));
537 obj_aout_external_syms (abfd
) = NULL
;
538 obj_aout_external_strings (abfd
) = NULL
;
539 obj_aout_sym_hashes (abfd
) = NULL
;
541 if (! NAME(aout
,make_sections
) (abfd
))
544 obj_datasec (abfd
)->size
= execp
->a_data
;
545 obj_bsssec (abfd
)->size
= execp
->a_bss
;
547 obj_textsec (abfd
)->flags
=
548 (execp
->a_trsize
!= 0
549 ? (SEC_ALLOC
| SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
| SEC_RELOC
)
550 : (SEC_ALLOC
| SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
));
551 obj_datasec (abfd
)->flags
=
552 (execp
->a_drsize
!= 0
553 ? (SEC_ALLOC
| SEC_LOAD
| SEC_DATA
| SEC_HAS_CONTENTS
| SEC_RELOC
)
554 : (SEC_ALLOC
| SEC_LOAD
| SEC_DATA
| SEC_HAS_CONTENTS
));
555 obj_bsssec (abfd
)->flags
= SEC_ALLOC
;
557 #ifdef THIS_IS_ONLY_DOCUMENTATION
558 /* The common code can't fill in these things because they depend
559 on either the start address of the text segment, the rounding
560 up of virtual addresses between segments, or the starting file
561 position of the text segment -- all of which varies among different
562 versions of a.out. */
564 /* Call back to the format-dependent code to fill in the rest of the
565 fields and do any further cleanup. Things that should be filled
566 in by the callback: */
568 struct exec
*execp
= exec_hdr (abfd
);
570 obj_textsec (abfd
)->size
= N_TXTSIZE (*execp
);
571 /* Data and bss are already filled in since they're so standard. */
573 /* The virtual memory addresses of the sections. */
574 obj_textsec (abfd
)->vma
= N_TXTADDR (*execp
);
575 obj_datasec (abfd
)->vma
= N_DATADDR (*execp
);
576 obj_bsssec (abfd
)->vma
= N_BSSADDR (*execp
);
578 /* The file offsets of the sections. */
579 obj_textsec (abfd
)->filepos
= N_TXTOFF (*execp
);
580 obj_datasec (abfd
)->filepos
= N_DATOFF (*execp
);
582 /* The file offsets of the relocation info. */
583 obj_textsec (abfd
)->rel_filepos
= N_TRELOFF (*execp
);
584 obj_datasec (abfd
)->rel_filepos
= N_DRELOFF (*execp
);
586 /* The file offsets of the string table and symbol table. */
587 obj_str_filepos (abfd
) = N_STROFF (*execp
);
588 obj_sym_filepos (abfd
) = N_SYMOFF (*execp
);
590 /* Determine the architecture and machine type of the object file. */
591 switch (N_MACHTYPE (*exec_hdr (abfd
)))
594 abfd
->obj_arch
= bfd_arch_obscure
;
598 adata (abfd
)->page_size
= TARGET_PAGE_SIZE
;
599 adata (abfd
)->segment_size
= SEGMENT_SIZE
;
600 adata (abfd
)->exec_bytes_size
= EXEC_BYTES_SIZE
;
604 /* The architecture is encoded in various ways in various a.out variants,
605 or is not encoded at all in some of them. The relocation size depends
606 on the architecture and the a.out variant. Finally, the return value
607 is the bfd_target vector in use. If an error occurs, return zero and
608 set bfd_error to the appropriate error code.
610 Formats such as b.out, which have additional fields in the a.out
611 header, should cope with them in this callback as well. */
612 #endif /* DOCUMENTATION */
614 result
= (*callback_to_real_object_p
) (abfd
);
616 /* Now that the segment addresses have been worked out, take a better
617 guess at whether the file is executable. If the entry point
618 is within the text segment, assume it is. (This makes files
619 executable even if their entry point address is 0, as long as
620 their text starts at zero.).
622 This test had to be changed to deal with systems where the text segment
623 runs at a different location than the default. The problem is that the
624 entry address can appear to be outside the text segment, thus causing an
625 erroneous conclusion that the file isn't executable.
627 To fix this, we now accept any non-zero entry point as an indication of
628 executability. This will work most of the time, since only the linker
629 sets the entry point, and that is likely to be non-zero for most systems. */
631 if (execp
->a_entry
!= 0
632 || (execp
->a_entry
>= obj_textsec (abfd
)->vma
633 && execp
->a_entry
< (obj_textsec (abfd
)->vma
634 + obj_textsec (abfd
)->size
)))
635 abfd
->flags
|= EXEC_P
;
639 struct stat stat_buf
;
641 /* The original heuristic doesn't work in some important cases.
642 The a.out file has no information about the text start
643 address. For files (like kernels) linked to non-standard
644 addresses (ld -Ttext nnn) the entry point may not be between
645 the default text start (obj_textsec(abfd)->vma) and
646 (obj_textsec(abfd)->vma) + text size. This is not just a mach
647 issue. Many kernels are loaded at non standard addresses. */
648 if (abfd
->iostream
!= NULL
649 && (abfd
->flags
& BFD_IN_MEMORY
) == 0
650 && (fstat (fileno ((FILE *) (abfd
->iostream
)), &stat_buf
) == 0)
651 && ((stat_buf
.st_mode
& 0111) != 0))
652 abfd
->flags
|= EXEC_P
;
654 #endif /* STAT_FOR_EXEC */
660 bfd_release (abfd
, rawptr
);
661 abfd
->tdata
.aout_data
= oldrawptr
;
667 aout_@var{size}_mkobject
670 bfd_boolean aout_@var{size}_mkobject, (bfd *abfd);
673 Initialize BFD @var{abfd} for use with a.out files.
677 NAME(aout
,mkobject
) (abfd
)
680 struct aout_data_struct
*rawptr
;
681 bfd_size_type amt
= sizeof (struct aout_data_struct
);
683 bfd_set_error (bfd_error_system_call
);
685 rawptr
= (struct aout_data_struct
*) bfd_zalloc (abfd
, amt
);
689 abfd
->tdata
.aout_data
= rawptr
;
690 exec_hdr (abfd
) = &(rawptr
->e
);
692 obj_textsec (abfd
) = (asection
*) NULL
;
693 obj_datasec (abfd
) = (asection
*) NULL
;
694 obj_bsssec (abfd
) = (asection
*) NULL
;
701 aout_@var{size}_machine_type
704 enum machine_type aout_@var{size}_machine_type
705 (enum bfd_architecture arch,
706 unsigned long machine));
709 Keep track of machine architecture and machine type for
710 a.out's. Return the <<machine_type>> for a particular
711 architecture and machine, or <<M_UNKNOWN>> if that exact architecture
712 and machine can't be represented in a.out format.
714 If the architecture is understood, machine type 0 (default)
715 is always understood.
719 NAME(aout
,machine_type
) (arch
, machine
, unknown
)
720 enum bfd_architecture arch
;
721 unsigned long machine
;
722 bfd_boolean
*unknown
;
724 enum machine_type arch_flags
;
726 arch_flags
= M_UNKNOWN
;
733 || machine
== bfd_mach_sparc
734 || machine
== bfd_mach_sparc_sparclite
735 || machine
== bfd_mach_sparc_sparclite_le
736 || machine
== bfd_mach_sparc_v9
)
737 arch_flags
= M_SPARC
;
738 else if (machine
== bfd_mach_sparc_sparclet
)
739 arch_flags
= M_SPARCLET
;
745 case 0: arch_flags
= M_68010
; break;
746 case bfd_mach_m68000
: arch_flags
= M_UNKNOWN
; *unknown
= FALSE
; break;
747 case bfd_mach_m68010
: arch_flags
= M_68010
; break;
748 case bfd_mach_m68020
: arch_flags
= M_68020
; break;
749 default: arch_flags
= M_UNKNOWN
; break;
755 || machine
== bfd_mach_i386_i386
756 || machine
== bfd_mach_i386_i386_intel_syntax
)
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_mips9000
:
790 case bfd_mach_mips10000
:
791 case bfd_mach_mips12000
:
792 case bfd_mach_mips16
:
793 case bfd_mach_mipsisa32
:
794 case bfd_mach_mipsisa32r2
:
796 case bfd_mach_mipsisa64
:
797 case bfd_mach_mipsisa64r2
:
798 case bfd_mach_mips_sb1
:
799 /* FIXME: These should be MIPS3, MIPS4, MIPS16, MIPS32, etc. */
800 arch_flags
= M_MIPS2
;
803 arch_flags
= M_UNKNOWN
;
811 case 0: arch_flags
= M_NS32532
; break;
812 case 32032: arch_flags
= M_NS32032
; break;
813 case 32532: arch_flags
= M_NS32532
; break;
814 default: arch_flags
= M_UNKNOWN
; break;
823 if (machine
== 0 || machine
== 255)
832 arch_flags
= M_UNKNOWN
;
835 if (arch_flags
!= M_UNKNOWN
)
843 aout_@var{size}_set_arch_mach
846 bfd_boolean aout_@var{size}_set_arch_mach,
848 enum bfd_architecture arch,
849 unsigned long machine));
852 Set the architecture and the machine of the BFD @var{abfd} to the
853 values @var{arch} and @var{machine}. Verify that @var{abfd}'s format
854 can support the architecture required.
858 NAME(aout
,set_arch_mach
) (abfd
, arch
, machine
)
860 enum bfd_architecture arch
;
861 unsigned long machine
;
863 if (! bfd_default_set_arch_mach (abfd
, arch
, machine
))
866 if (arch
!= bfd_arch_unknown
)
870 NAME(aout
,machine_type
) (arch
, machine
, &unknown
);
875 /* Determine the size of a relocation entry. */
881 obj_reloc_entry_size (abfd
) = RELOC_EXT_SIZE
;
884 obj_reloc_entry_size (abfd
) = RELOC_STD_SIZE
;
888 return (*aout_backend_info (abfd
)->set_sizes
) (abfd
);
892 adjust_o_magic (abfd
, execp
)
894 struct internal_exec
*execp
;
896 file_ptr pos
= adata (abfd
).exec_bytes_size
;
901 obj_textsec (abfd
)->filepos
= pos
;
902 if (!obj_textsec (abfd
)->user_set_vma
)
903 obj_textsec (abfd
)->vma
= vma
;
905 vma
= obj_textsec (abfd
)->vma
;
907 pos
+= obj_textsec (abfd
)->size
;
908 vma
+= obj_textsec (abfd
)->size
;
911 if (!obj_datasec (abfd
)->user_set_vma
)
913 obj_textsec (abfd
)->size
+= pad
;
916 obj_datasec (abfd
)->vma
= vma
;
919 vma
= obj_datasec (abfd
)->vma
;
920 obj_datasec (abfd
)->filepos
= pos
;
921 pos
+= obj_datasec (abfd
)->size
;
922 vma
+= obj_datasec (abfd
)->size
;
925 if (!obj_bsssec (abfd
)->user_set_vma
)
927 obj_datasec (abfd
)->size
+= pad
;
930 obj_bsssec (abfd
)->vma
= vma
;
934 /* The VMA of the .bss section is set by the VMA of the
935 .data section plus the size of the .data section. We may
936 need to add padding bytes to make this true. */
937 pad
= obj_bsssec (abfd
)->vma
- vma
;
940 obj_datasec (abfd
)->size
+= pad
;
944 obj_bsssec (abfd
)->filepos
= pos
;
946 /* Fix up the exec header. */
947 execp
->a_text
= obj_textsec (abfd
)->size
;
948 execp
->a_data
= obj_datasec (abfd
)->size
;
949 execp
->a_bss
= obj_bsssec (abfd
)->size
;
950 N_SET_MAGIC (*execp
, OMAGIC
);
954 adjust_z_magic (abfd
, execp
)
956 struct internal_exec
*execp
;
958 bfd_size_type data_pad
, text_pad
;
960 const struct aout_backend_data
*abdp
;
961 int ztih
; /* Nonzero if text includes exec header. */
963 abdp
= aout_backend_info (abfd
);
967 && (abdp
->text_includes_header
968 || obj_aout_subformat (abfd
) == q_magic_format
));
969 obj_textsec (abfd
)->filepos
= (ztih
970 ? adata (abfd
).exec_bytes_size
971 : adata (abfd
).zmagic_disk_block_size
);
972 if (! obj_textsec (abfd
)->user_set_vma
)
974 /* ?? Do we really need to check for relocs here? */
975 obj_textsec (abfd
)->vma
= ((abfd
->flags
& HAS_RELOC
)
978 ? (abdp
->default_text_vma
979 + adata (abfd
).exec_bytes_size
)
980 : abdp
->default_text_vma
));
985 /* The .text section is being loaded at an unusual address. We
986 may need to pad it such that the .data section starts at a page
989 text_pad
= ((obj_textsec (abfd
)->filepos
- obj_textsec (abfd
)->vma
)
990 & (adata (abfd
).page_size
- 1));
992 text_pad
= ((- obj_textsec (abfd
)->vma
)
993 & (adata (abfd
).page_size
- 1));
996 /* Find start of data. */
999 text_end
= obj_textsec (abfd
)->filepos
+ obj_textsec (abfd
)->size
;
1000 text_pad
+= BFD_ALIGN (text_end
, adata (abfd
).page_size
) - text_end
;
1004 /* Note that if page_size == zmagic_disk_block_size, then
1005 filepos == page_size, and this case is the same as the ztih
1007 text_end
= obj_textsec (abfd
)->size
;
1008 text_pad
+= BFD_ALIGN (text_end
, adata (abfd
).page_size
) - text_end
;
1009 text_end
+= obj_textsec (abfd
)->filepos
;
1011 obj_textsec (abfd
)->size
+= text_pad
;
1012 text_end
+= text_pad
;
1015 if (!obj_datasec (abfd
)->user_set_vma
)
1018 vma
= obj_textsec (abfd
)->vma
+ obj_textsec (abfd
)->size
;
1019 obj_datasec (abfd
)->vma
= BFD_ALIGN (vma
, adata (abfd
).segment_size
);
1021 if (abdp
&& abdp
->zmagic_mapped_contiguous
)
1023 asection
* text
= obj_textsec (abfd
);
1024 asection
* data
= obj_datasec (abfd
);
1026 text_pad
= data
->vma
- (text
->vma
+ text
->size
);
1027 /* Only pad the text section if the data
1028 section is going to be placed after it. */
1030 text
->size
+= text_pad
;
1032 obj_datasec (abfd
)->filepos
= (obj_textsec (abfd
)->filepos
1033 + obj_textsec (abfd
)->size
);
1035 /* Fix up exec header while we're at it. */
1036 execp
->a_text
= obj_textsec (abfd
)->size
;
1037 if (ztih
&& (!abdp
|| (abdp
&& !abdp
->exec_header_not_counted
)))
1038 execp
->a_text
+= adata (abfd
).exec_bytes_size
;
1039 if (obj_aout_subformat (abfd
) == q_magic_format
)
1040 N_SET_MAGIC (*execp
, QMAGIC
);
1042 N_SET_MAGIC (*execp
, ZMAGIC
);
1044 /* Spec says data section should be rounded up to page boundary. */
1045 obj_datasec (abfd
)->size
1046 = align_power (obj_datasec (abfd
)->size
,
1047 obj_bsssec (abfd
)->alignment_power
);
1048 execp
->a_data
= BFD_ALIGN (obj_datasec (abfd
)->size
,
1049 adata (abfd
).page_size
);
1050 data_pad
= execp
->a_data
- obj_datasec (abfd
)->size
;
1053 if (!obj_bsssec (abfd
)->user_set_vma
)
1054 obj_bsssec (abfd
)->vma
= (obj_datasec (abfd
)->vma
1055 + obj_datasec (abfd
)->size
);
1056 /* If the BSS immediately follows the data section and extra space
1057 in the page is left after the data section, fudge data
1058 in the header so that the bss section looks smaller by that
1059 amount. We'll start the bss section there, and lie to the OS.
1060 (Note that a linker script, as well as the above assignment,
1061 could have explicitly set the BSS vma to immediately follow
1062 the data section.) */
1063 if (align_power (obj_bsssec (abfd
)->vma
, obj_bsssec (abfd
)->alignment_power
)
1064 == obj_datasec (abfd
)->vma
+ obj_datasec (abfd
)->size
)
1065 execp
->a_bss
= (data_pad
> obj_bsssec (abfd
)->size
1066 ? 0 : obj_bsssec (abfd
)->size
- data_pad
);
1068 execp
->a_bss
= obj_bsssec (abfd
)->size
;
1072 adjust_n_magic (abfd
, execp
)
1074 struct internal_exec
*execp
;
1076 file_ptr pos
= adata (abfd
).exec_bytes_size
;
1081 obj_textsec (abfd
)->filepos
= pos
;
1082 if (!obj_textsec (abfd
)->user_set_vma
)
1083 obj_textsec (abfd
)->vma
= vma
;
1085 vma
= obj_textsec (abfd
)->vma
;
1086 pos
+= obj_textsec (abfd
)->size
;
1087 vma
+= obj_textsec (abfd
)->size
;
1090 obj_datasec (abfd
)->filepos
= pos
;
1091 if (!obj_datasec (abfd
)->user_set_vma
)
1092 obj_datasec (abfd
)->vma
= BFD_ALIGN (vma
, adata (abfd
).segment_size
);
1093 vma
= obj_datasec (abfd
)->vma
;
1095 /* Since BSS follows data immediately, see if it needs alignment. */
1096 vma
+= obj_datasec (abfd
)->size
;
1097 pad
= align_power (vma
, obj_bsssec (abfd
)->alignment_power
) - vma
;
1098 obj_datasec (abfd
)->size
+= pad
;
1099 pos
+= obj_datasec (abfd
)->size
;
1102 if (!obj_bsssec (abfd
)->user_set_vma
)
1103 obj_bsssec (abfd
)->vma
= vma
;
1105 vma
= obj_bsssec (abfd
)->vma
;
1107 /* Fix up exec header. */
1108 execp
->a_text
= obj_textsec (abfd
)->size
;
1109 execp
->a_data
= obj_datasec (abfd
)->size
;
1110 execp
->a_bss
= obj_bsssec (abfd
)->size
;
1111 N_SET_MAGIC (*execp
, NMAGIC
);
1115 NAME(aout
,adjust_sizes_and_vmas
) (abfd
, text_size
, text_end
)
1117 bfd_size_type
*text_size
;
1118 file_ptr
*text_end ATTRIBUTE_UNUSED
;
1120 struct internal_exec
*execp
= exec_hdr (abfd
);
1122 if (! NAME(aout
,make_sections
) (abfd
))
1125 if (adata (abfd
).magic
!= undecided_magic
)
1128 obj_textsec (abfd
)->size
=
1129 align_power (obj_textsec (abfd
)->size
,
1130 obj_textsec (abfd
)->alignment_power
);
1132 *text_size
= obj_textsec (abfd
)->size
;
1133 /* Rule (heuristic) for when to pad to a new page. Note that there
1134 are (at least) two ways demand-paged (ZMAGIC) files have been
1135 handled. Most Berkeley-based systems start the text segment at
1136 (TARGET_PAGE_SIZE). However, newer versions of SUNOS start the text
1137 segment right after the exec header; the latter is counted in the
1138 text segment size, and is paged in by the kernel with the rest of
1141 /* This perhaps isn't the right way to do this, but made it simpler for me
1142 to understand enough to implement it. Better would probably be to go
1143 right from BFD flags to alignment/positioning characteristics. But the
1144 old code was sloppy enough about handling the flags, and had enough
1145 other magic, that it was a little hard for me to understand. I think
1146 I understand it better now, but I haven't time to do the cleanup this
1149 if (abfd
->flags
& D_PAGED
)
1150 /* Whether or not WP_TEXT is set -- let D_PAGED override. */
1151 adata (abfd
).magic
= z_magic
;
1152 else if (abfd
->flags
& WP_TEXT
)
1153 adata (abfd
).magic
= n_magic
;
1155 adata (abfd
).magic
= o_magic
;
1157 #ifdef BFD_AOUT_DEBUG /* requires gcc2 */
1159 fprintf (stderr
, "%s text=<%x,%x,%x> data=<%x,%x,%x> bss=<%x,%x,%x>\n",
1161 switch (adata (abfd
).magic
)
1163 case n_magic
: str
= "NMAGIC"; break;
1164 case o_magic
: str
= "OMAGIC"; break;
1165 case z_magic
: str
= "ZMAGIC"; break;
1170 obj_textsec (abfd
)->vma
, obj_textsec (abfd
)->size
,
1171 obj_textsec (abfd
)->alignment_power
,
1172 obj_datasec (abfd
)->vma
, obj_datasec (abfd
)->size
,
1173 obj_datasec (abfd
)->alignment_power
,
1174 obj_bsssec (abfd
)->vma
, obj_bsssec (abfd
)->size
,
1175 obj_bsssec (abfd
)->alignment_power
);
1179 switch (adata (abfd
).magic
)
1182 adjust_o_magic (abfd
, execp
);
1185 adjust_z_magic (abfd
, execp
);
1188 adjust_n_magic (abfd
, execp
);
1194 #ifdef BFD_AOUT_DEBUG
1195 fprintf (stderr
, " text=<%x,%x,%x> data=<%x,%x,%x> bss=<%x,%x>\n",
1196 obj_textsec (abfd
)->vma
, obj_textsec (abfd
)->size
,
1197 obj_textsec (abfd
)->filepos
,
1198 obj_datasec (abfd
)->vma
, obj_datasec (abfd
)->size
,
1199 obj_datasec (abfd
)->filepos
,
1200 obj_bsssec (abfd
)->vma
, obj_bsssec (abfd
)->size
);
1208 aout_@var{size}_new_section_hook
1211 bfd_boolean aout_@var{size}_new_section_hook,
1213 asection *newsect));
1216 Called by the BFD in response to a @code{bfd_make_section}
1220 NAME(aout
,new_section_hook
) (abfd
, newsect
)
1224 /* Align to double at least. */
1225 newsect
->alignment_power
= bfd_get_arch_info (abfd
)->section_align_power
;
1227 if (bfd_get_format (abfd
) == bfd_object
)
1229 if (obj_textsec (abfd
) == NULL
&& !strcmp (newsect
->name
, ".text"))
1231 obj_textsec (abfd
)= newsect
;
1232 newsect
->target_index
= N_TEXT
;
1236 if (obj_datasec (abfd
) == NULL
&& !strcmp (newsect
->name
, ".data"))
1238 obj_datasec (abfd
) = newsect
;
1239 newsect
->target_index
= N_DATA
;
1243 if (obj_bsssec (abfd
) == NULL
&& !strcmp (newsect
->name
, ".bss"))
1245 obj_bsssec (abfd
) = newsect
;
1246 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 if (aout_section_merge_with_text_p (abfd
, section
))
1282 section
->filepos
= obj_textsec (abfd
)->filepos
+
1283 (section
->vma
- obj_textsec (abfd
)->vma
);
1286 (*_bfd_error_handler
)
1287 (_("%s: can not represent section `%s' in a.out object file format"),
1288 bfd_get_filename (abfd
), bfd_get_section_name (abfd
, section
));
1289 bfd_set_error (bfd_error_nonrepresentable_section
);
1296 if (bfd_seek (abfd
, section
->filepos
+ offset
, SEEK_SET
) != 0
1297 || bfd_bwrite (location
, count
, abfd
) != count
)
1304 /* Read the external symbols from an a.out file. */
1307 aout_get_external_symbols (abfd
)
1310 if (obj_aout_external_syms (abfd
) == (struct external_nlist
*) NULL
)
1312 bfd_size_type count
;
1313 struct external_nlist
*syms
;
1316 count
= exec_hdr (abfd
)->a_syms
/ EXTERNAL_NLIST_SIZE
;
1319 if (! bfd_get_file_window (abfd
, obj_sym_filepos (abfd
),
1320 exec_hdr (abfd
)->a_syms
,
1321 &obj_aout_sym_window (abfd
), TRUE
))
1323 syms
= (struct external_nlist
*) obj_aout_sym_window (abfd
).data
;
1325 /* We allocate using malloc to make the values easy to free
1326 later on. If we put them on the objalloc it might not be
1327 possible to free them. */
1328 syms
= ((struct external_nlist
*)
1329 bfd_malloc (count
* EXTERNAL_NLIST_SIZE
));
1330 if (syms
== (struct external_nlist
*) NULL
&& count
!= 0)
1333 amt
= exec_hdr (abfd
)->a_syms
;
1334 if (bfd_seek (abfd
, obj_sym_filepos (abfd
), SEEK_SET
) != 0
1335 || bfd_bread (syms
, amt
, abfd
) != amt
)
1342 obj_aout_external_syms (abfd
) = syms
;
1343 obj_aout_external_sym_count (abfd
) = count
;
1346 if (obj_aout_external_strings (abfd
) == NULL
1347 && exec_hdr (abfd
)->a_syms
!= 0)
1349 unsigned char string_chars
[BYTES_IN_WORD
];
1350 bfd_size_type stringsize
;
1352 bfd_size_type amt
= BYTES_IN_WORD
;
1354 /* Get the size of the strings. */
1355 if (bfd_seek (abfd
, obj_str_filepos (abfd
), SEEK_SET
) != 0
1356 || bfd_bread ((PTR
) string_chars
, amt
, abfd
) != amt
)
1358 stringsize
= GET_WORD (abfd
, string_chars
);
1361 if (! bfd_get_file_window (abfd
, obj_str_filepos (abfd
), stringsize
,
1362 &obj_aout_string_window (abfd
), TRUE
))
1364 strings
= (char *) obj_aout_string_window (abfd
).data
;
1366 strings
= (char *) bfd_malloc (stringsize
+ 1);
1367 if (strings
== NULL
)
1370 /* Skip space for the string count in the buffer for convenience
1371 when using indexes. */
1372 amt
= stringsize
- BYTES_IN_WORD
;
1373 if (bfd_bread (strings
+ BYTES_IN_WORD
, amt
, abfd
) != amt
)
1380 /* Ensure that a zero index yields an empty string. */
1383 strings
[stringsize
- 1] = 0;
1385 obj_aout_external_strings (abfd
) = strings
;
1386 obj_aout_external_string_size (abfd
) = stringsize
;
1392 /* Translate an a.out symbol into a BFD symbol. The desc, other, type
1393 and symbol->value fields of CACHE_PTR will be set from the a.out
1394 nlist structure. This function is responsible for setting
1395 symbol->flags and symbol->section, and adjusting symbol->value. */
1398 translate_from_native_sym_flags (abfd
, cache_ptr
)
1400 aout_symbol_type
*cache_ptr
;
1404 if ((cache_ptr
->type
& N_STAB
) != 0
1405 || cache_ptr
->type
== N_FN
)
1409 /* This is a debugging symbol. */
1410 cache_ptr
->symbol
.flags
= BSF_DEBUGGING
;
1412 /* Work out the symbol section. */
1413 switch (cache_ptr
->type
& N_TYPE
)
1417 sec
= obj_textsec (abfd
);
1420 sec
= obj_datasec (abfd
);
1423 sec
= obj_bsssec (abfd
);
1427 sec
= bfd_abs_section_ptr
;
1431 cache_ptr
->symbol
.section
= sec
;
1432 cache_ptr
->symbol
.value
-= sec
->vma
;
1437 /* Get the default visibility. This does not apply to all types, so
1438 we just hold it in a local variable to use if wanted. */
1439 if ((cache_ptr
->type
& N_EXT
) == 0)
1440 visible
= BSF_LOCAL
;
1442 visible
= BSF_GLOBAL
;
1444 switch (cache_ptr
->type
)
1447 case N_ABS
: case N_ABS
| N_EXT
:
1448 cache_ptr
->symbol
.section
= bfd_abs_section_ptr
;
1449 cache_ptr
->symbol
.flags
= visible
;
1452 case N_UNDF
| N_EXT
:
1453 if (cache_ptr
->symbol
.value
!= 0)
1455 /* This is a common symbol. */
1456 cache_ptr
->symbol
.flags
= BSF_GLOBAL
;
1457 cache_ptr
->symbol
.section
= bfd_com_section_ptr
;
1461 cache_ptr
->symbol
.flags
= 0;
1462 cache_ptr
->symbol
.section
= bfd_und_section_ptr
;
1466 case N_TEXT
: case N_TEXT
| N_EXT
:
1467 cache_ptr
->symbol
.section
= obj_textsec (abfd
);
1468 cache_ptr
->symbol
.value
-= cache_ptr
->symbol
.section
->vma
;
1469 cache_ptr
->symbol
.flags
= visible
;
1472 /* N_SETV symbols used to represent set vectors placed in the
1473 data section. They are no longer generated. Theoretically,
1474 it was possible to extract the entries and combine them with
1475 new ones, although I don't know if that was ever actually
1476 done. Unless that feature is restored, treat them as data
1478 case N_SETV
: case N_SETV
| N_EXT
:
1479 case N_DATA
: case N_DATA
| N_EXT
:
1480 cache_ptr
->symbol
.section
= obj_datasec (abfd
);
1481 cache_ptr
->symbol
.value
-= cache_ptr
->symbol
.section
->vma
;
1482 cache_ptr
->symbol
.flags
= visible
;
1485 case N_BSS
: case N_BSS
| N_EXT
:
1486 cache_ptr
->symbol
.section
= obj_bsssec (abfd
);
1487 cache_ptr
->symbol
.value
-= cache_ptr
->symbol
.section
->vma
;
1488 cache_ptr
->symbol
.flags
= visible
;
1491 case N_SETA
: case N_SETA
| N_EXT
:
1492 case N_SETT
: case N_SETT
| N_EXT
:
1493 case N_SETD
: case N_SETD
| N_EXT
:
1494 case N_SETB
: case N_SETB
| N_EXT
:
1496 /* This code is no longer needed. It used to be used to make
1497 the linker handle set symbols, but they are now handled in
1498 the add_symbols routine instead. */
1499 switch (cache_ptr
->type
& N_TYPE
)
1502 cache_ptr
->symbol
.section
= bfd_abs_section_ptr
;
1505 cache_ptr
->symbol
.section
= obj_textsec (abfd
);
1508 cache_ptr
->symbol
.section
= obj_datasec (abfd
);
1511 cache_ptr
->symbol
.section
= obj_bsssec (abfd
);
1515 cache_ptr
->symbol
.flags
|= BSF_CONSTRUCTOR
;
1520 /* This symbol is the text of a warning message. The next
1521 symbol is the symbol to associate the warning with. If a
1522 reference is made to that symbol, a warning is issued. */
1523 cache_ptr
->symbol
.flags
= BSF_DEBUGGING
| BSF_WARNING
;
1524 cache_ptr
->symbol
.section
= bfd_abs_section_ptr
;
1527 case N_INDR
: case N_INDR
| N_EXT
:
1528 /* An indirect symbol. This consists of two symbols in a row.
1529 The first symbol is the name of the indirection. The second
1530 symbol is the name of the target. A reference to the first
1531 symbol becomes a reference to the second. */
1532 cache_ptr
->symbol
.flags
= BSF_DEBUGGING
| BSF_INDIRECT
| visible
;
1533 cache_ptr
->symbol
.section
= bfd_ind_section_ptr
;
1537 cache_ptr
->symbol
.section
= bfd_und_section_ptr
;
1538 cache_ptr
->symbol
.flags
= BSF_WEAK
;
1542 cache_ptr
->symbol
.section
= bfd_abs_section_ptr
;
1543 cache_ptr
->symbol
.flags
= BSF_WEAK
;
1547 cache_ptr
->symbol
.section
= obj_textsec (abfd
);
1548 cache_ptr
->symbol
.value
-= cache_ptr
->symbol
.section
->vma
;
1549 cache_ptr
->symbol
.flags
= BSF_WEAK
;
1553 cache_ptr
->symbol
.section
= obj_datasec (abfd
);
1554 cache_ptr
->symbol
.value
-= cache_ptr
->symbol
.section
->vma
;
1555 cache_ptr
->symbol
.flags
= BSF_WEAK
;
1559 cache_ptr
->symbol
.section
= obj_bsssec (abfd
);
1560 cache_ptr
->symbol
.value
-= cache_ptr
->symbol
.section
->vma
;
1561 cache_ptr
->symbol
.flags
= BSF_WEAK
;
1568 /* Set the fields of SYM_POINTER according to CACHE_PTR. */
1571 translate_to_native_sym_flags (abfd
, cache_ptr
, sym_pointer
)
1574 struct external_nlist
*sym_pointer
;
1576 bfd_vma value
= cache_ptr
->value
;
1580 /* Mask out any existing type bits in case copying from one section
1582 sym_pointer
->e_type
[0] &= ~N_TYPE
;
1584 sec
= bfd_get_section (cache_ptr
);
1589 /* This case occurs, e.g., for the *DEBUG* section of a COFF
1591 (*_bfd_error_handler
)
1592 (_("%s: can not represent section for symbol `%s' in a.out object file format"),
1593 bfd_get_filename (abfd
),
1594 cache_ptr
->name
!= NULL
? cache_ptr
->name
: _("*unknown*"));
1595 bfd_set_error (bfd_error_nonrepresentable_section
);
1599 if (sec
->output_section
!= NULL
)
1601 off
= sec
->output_offset
;
1602 sec
= sec
->output_section
;
1605 if (bfd_is_abs_section (sec
))
1606 sym_pointer
->e_type
[0] |= N_ABS
;
1607 else if (sec
== obj_textsec (abfd
))
1608 sym_pointer
->e_type
[0] |= N_TEXT
;
1609 else if (sec
== obj_datasec (abfd
))
1610 sym_pointer
->e_type
[0] |= N_DATA
;
1611 else if (sec
== obj_bsssec (abfd
))
1612 sym_pointer
->e_type
[0] |= N_BSS
;
1613 else if (bfd_is_und_section (sec
))
1614 sym_pointer
->e_type
[0] = N_UNDF
| N_EXT
;
1615 else if (bfd_is_ind_section (sec
))
1616 sym_pointer
->e_type
[0] = N_INDR
;
1617 else if (bfd_is_com_section (sec
))
1618 sym_pointer
->e_type
[0] = N_UNDF
| N_EXT
;
1621 if (aout_section_merge_with_text_p (abfd
, sec
))
1622 sym_pointer
->e_type
[0] |= N_TEXT
;
1625 (*_bfd_error_handler
)
1626 (_("%s: can not represent section `%s' in a.out object file format"),
1627 bfd_get_filename (abfd
), bfd_get_section_name (abfd
, sec
));
1628 bfd_set_error (bfd_error_nonrepresentable_section
);
1633 /* Turn the symbol from section relative to absolute again. */
1634 value
+= sec
->vma
+ off
;
1636 if ((cache_ptr
->flags
& BSF_WARNING
) != 0)
1637 sym_pointer
->e_type
[0] = N_WARNING
;
1639 if ((cache_ptr
->flags
& BSF_DEBUGGING
) != 0)
1640 sym_pointer
->e_type
[0] = ((aout_symbol_type
*) cache_ptr
)->type
;
1641 else if ((cache_ptr
->flags
& BSF_GLOBAL
) != 0)
1642 sym_pointer
->e_type
[0] |= N_EXT
;
1643 else if ((cache_ptr
->flags
& BSF_LOCAL
) != 0)
1644 sym_pointer
->e_type
[0] &= ~N_EXT
;
1646 if ((cache_ptr
->flags
& BSF_CONSTRUCTOR
) != 0)
1648 int type
= ((aout_symbol_type
*) cache_ptr
)->type
;
1652 case N_ABS
: type
= N_SETA
; break;
1653 case N_TEXT
: type
= N_SETT
; break;
1654 case N_DATA
: type
= N_SETD
; break;
1655 case N_BSS
: type
= N_SETB
; break;
1657 sym_pointer
->e_type
[0] = type
;
1660 if ((cache_ptr
->flags
& BSF_WEAK
) != 0)
1664 switch (sym_pointer
->e_type
[0] & N_TYPE
)
1667 case N_ABS
: type
= N_WEAKA
; break;
1668 case N_TEXT
: type
= N_WEAKT
; break;
1669 case N_DATA
: type
= N_WEAKD
; break;
1670 case N_BSS
: type
= N_WEAKB
; break;
1671 case N_UNDF
: type
= N_WEAKU
; break;
1673 sym_pointer
->e_type
[0] = type
;
1676 PUT_WORD (abfd
, value
, sym_pointer
->e_value
);
1681 /* Native-level interface to symbols. */
1684 NAME(aout
,make_empty_symbol
) (abfd
)
1687 bfd_size_type amt
= sizeof (aout_symbol_type
);
1688 aout_symbol_type
*new = (aout_symbol_type
*) bfd_zalloc (abfd
, amt
);
1691 new->symbol
.the_bfd
= abfd
;
1693 return &new->symbol
;
1696 /* Translate a set of internal symbols into external symbols. */
1699 NAME(aout
,translate_symbol_table
) (abfd
, in
, ext
, count
, str
, strsize
, dynamic
)
1701 aout_symbol_type
*in
;
1702 struct external_nlist
*ext
;
1703 bfd_size_type count
;
1705 bfd_size_type strsize
;
1706 bfd_boolean dynamic
;
1708 struct external_nlist
*ext_end
;
1710 ext_end
= ext
+ count
;
1711 for (; ext
< ext_end
; ext
++, in
++)
1715 x
= GET_WORD (abfd
, ext
->e_strx
);
1716 in
->symbol
.the_bfd
= abfd
;
1718 /* For the normal symbols, the zero index points at the number
1719 of bytes in the string table but is to be interpreted as the
1720 null string. For the dynamic symbols, the number of bytes in
1721 the string table is stored in the __DYNAMIC structure and the
1722 zero index points at an actual string. */
1723 if (x
== 0 && ! dynamic
)
1724 in
->symbol
.name
= "";
1725 else if (x
< strsize
)
1726 in
->symbol
.name
= str
+ x
;
1730 in
->symbol
.value
= GET_SWORD (abfd
, ext
->e_value
);
1731 in
->desc
= H_GET_16 (abfd
, ext
->e_desc
);
1732 in
->other
= H_GET_8 (abfd
, ext
->e_other
);
1733 in
->type
= H_GET_8 (abfd
, ext
->e_type
);
1734 in
->symbol
.udata
.p
= NULL
;
1736 if (! translate_from_native_sym_flags (abfd
, in
))
1740 in
->symbol
.flags
|= BSF_DYNAMIC
;
1746 /* We read the symbols into a buffer, which is discarded when this
1747 function exits. We read the strings into a buffer large enough to
1748 hold them all plus all the cached symbol entries. */
1751 NAME(aout
,slurp_symbol_table
) (abfd
)
1754 struct external_nlist
*old_external_syms
;
1755 aout_symbol_type
*cached
;
1756 bfd_size_type cached_size
;
1758 /* If there's no work to be done, don't do any. */
1759 if (obj_aout_symbols (abfd
) != (aout_symbol_type
*) NULL
)
1762 old_external_syms
= obj_aout_external_syms (abfd
);
1764 if (! aout_get_external_symbols (abfd
))
1767 cached_size
= obj_aout_external_sym_count (abfd
);
1768 cached_size
*= sizeof (aout_symbol_type
);
1769 cached
= (aout_symbol_type
*) bfd_zmalloc (cached_size
);
1770 if (cached
== NULL
&& cached_size
!= 0)
1773 /* Convert from external symbol information to internal. */
1774 if (! (NAME(aout
,translate_symbol_table
)
1776 obj_aout_external_syms (abfd
),
1777 obj_aout_external_sym_count (abfd
),
1778 obj_aout_external_strings (abfd
),
1779 obj_aout_external_string_size (abfd
),
1786 bfd_get_symcount (abfd
) = obj_aout_external_sym_count (abfd
);
1788 obj_aout_symbols (abfd
) = cached
;
1790 /* It is very likely that anybody who calls this function will not
1791 want the external symbol information, so if it was allocated
1792 because of our call to aout_get_external_symbols, we free it up
1793 right away to save space. */
1794 if (old_external_syms
== (struct external_nlist
*) NULL
1795 && obj_aout_external_syms (abfd
) != (struct external_nlist
*) NULL
)
1798 bfd_free_window (&obj_aout_sym_window (abfd
));
1800 free (obj_aout_external_syms (abfd
));
1802 obj_aout_external_syms (abfd
) = NULL
;
1808 /* We use a hash table when writing out symbols so that we only write
1809 out a particular string once. This helps particularly when the
1810 linker writes out stabs debugging entries, because each different
1811 contributing object file tends to have many duplicate stabs
1814 This hash table code breaks dbx on SunOS 4.1.3, so we don't do it
1815 if BFD_TRADITIONAL_FORMAT is set. */
1817 static bfd_size_type add_to_stringtab
1818 PARAMS ((bfd
*, struct bfd_strtab_hash
*, const char *, bfd_boolean
));
1819 static bfd_boolean emit_stringtab
1820 PARAMS ((bfd
*, struct bfd_strtab_hash
*));
1822 /* Get the index of a string in a strtab, adding it if it is not
1825 static INLINE bfd_size_type
1826 add_to_stringtab (abfd
, tab
, str
, copy
)
1828 struct bfd_strtab_hash
*tab
;
1833 bfd_size_type index
;
1835 /* An index of 0 always means the empty string. */
1836 if (str
== 0 || *str
== '\0')
1839 /* Don't hash if BFD_TRADITIONAL_FORMAT is set, because SunOS dbx
1840 doesn't understand a hashed string table. */
1842 if ((abfd
->flags
& BFD_TRADITIONAL_FORMAT
) != 0)
1845 index
= _bfd_stringtab_add (tab
, str
, hash
, copy
);
1847 if (index
!= (bfd_size_type
) -1)
1849 /* Add BYTES_IN_WORD to the return value to account for the
1850 space taken up by the string table size. */
1851 index
+= BYTES_IN_WORD
;
1857 /* Write out a strtab. ABFD is already at the right location in the
1861 emit_stringtab (abfd
, tab
)
1863 struct bfd_strtab_hash
*tab
;
1865 bfd_byte buffer
[BYTES_IN_WORD
];
1866 bfd_size_type amt
= BYTES_IN_WORD
;
1868 /* The string table starts with the size. */
1869 PUT_WORD (abfd
, _bfd_stringtab_size (tab
) + BYTES_IN_WORD
, buffer
);
1870 if (bfd_bwrite ((PTR
) buffer
, amt
, abfd
) != amt
)
1873 return _bfd_stringtab_emit (abfd
, tab
);
1877 NAME(aout
,write_syms
) (abfd
)
1880 unsigned int count
;
1881 asymbol
**generic
= bfd_get_outsymbols (abfd
);
1882 struct bfd_strtab_hash
*strtab
;
1884 strtab
= _bfd_stringtab_init ();
1888 for (count
= 0; count
< bfd_get_symcount (abfd
); count
++)
1890 asymbol
*g
= generic
[count
];
1892 struct external_nlist nsp
;
1895 indx
= add_to_stringtab (abfd
, strtab
, g
->name
, FALSE
);
1896 if (indx
== (bfd_size_type
) -1)
1898 PUT_WORD (abfd
, indx
, (bfd_byte
*) nsp
.e_strx
);
1900 if (bfd_asymbol_flavour (g
) == abfd
->xvec
->flavour
)
1902 H_PUT_16 (abfd
, aout_symbol (g
)->desc
, nsp
.e_desc
);
1903 H_PUT_8 (abfd
, aout_symbol (g
)->other
, nsp
.e_other
);
1904 H_PUT_8 (abfd
, aout_symbol (g
)->type
, nsp
.e_type
);
1908 H_PUT_16 (abfd
, 0, nsp
.e_desc
);
1909 H_PUT_8 (abfd
, 0, nsp
.e_other
);
1910 H_PUT_8 (abfd
, 0, nsp
.e_type
);
1913 if (! translate_to_native_sym_flags (abfd
, g
, &nsp
))
1916 amt
= EXTERNAL_NLIST_SIZE
;
1917 if (bfd_bwrite ((PTR
) &nsp
, amt
, abfd
) != amt
)
1920 /* NB: `KEEPIT' currently overlays `udata.p', so set this only
1921 here, at the end. */
1925 if (! emit_stringtab (abfd
, strtab
))
1928 _bfd_stringtab_free (strtab
);
1933 _bfd_stringtab_free (strtab
);
1938 NAME(aout
,canonicalize_symtab
) (abfd
, location
)
1942 unsigned int counter
= 0;
1943 aout_symbol_type
*symbase
;
1945 if (!NAME(aout
,slurp_symbol_table
) (abfd
))
1948 for (symbase
= obj_aout_symbols (abfd
);
1949 counter
++ < bfd_get_symcount (abfd
);
1951 *(location
++) = (asymbol
*) (symbase
++);
1953 return bfd_get_symcount (abfd
);
1956 /* Standard reloc stuff. */
1957 /* Output standard relocation information to a file in target byte order. */
1959 extern void NAME(aout
,swap_std_reloc_out
)
1960 PARAMS ((bfd
*, arelent
*, struct reloc_std_external
*));
1963 NAME(aout
,swap_std_reloc_out
) (abfd
, g
, natptr
)
1966 struct reloc_std_external
*natptr
;
1969 asymbol
*sym
= *(g
->sym_ptr_ptr
);
1971 unsigned int r_length
;
1973 int r_baserel
, r_jmptable
, r_relative
;
1974 asection
*output_section
= sym
->section
->output_section
;
1976 PUT_WORD (abfd
, g
->address
, natptr
->r_address
);
1978 r_length
= g
->howto
->size
; /* Size as a power of two. */
1979 r_pcrel
= (int) g
->howto
->pc_relative
; /* Relative to PC? */
1980 /* XXX This relies on relocs coming from a.out files. */
1981 r_baserel
= (g
->howto
->type
& 8) != 0;
1982 r_jmptable
= (g
->howto
->type
& 16) != 0;
1983 r_relative
= (g
->howto
->type
& 32) != 0;
1985 /* Name was clobbered by aout_write_syms to be symbol index. */
1987 /* If this relocation is relative to a symbol then set the
1988 r_index to the symbols index, and the r_extern bit.
1990 Absolute symbols can come in in two ways, either as an offset
1991 from the abs section, or as a symbol which has an abs value.
1992 check for that here. */
1994 if (bfd_is_com_section (output_section
)
1995 || bfd_is_abs_section (output_section
)
1996 || bfd_is_und_section (output_section
))
1998 if (bfd_abs_section_ptr
->symbol
== sym
)
2000 /* Whoops, looked like an abs symbol, but is
2001 really an offset from the abs section. */
2007 /* Fill in symbol. */
2009 r_index
= (*(g
->sym_ptr_ptr
))->KEEPIT
;
2014 /* Just an ordinary section. */
2016 r_index
= output_section
->target_index
;
2019 /* Now the fun stuff. */
2020 if (bfd_header_big_endian (abfd
))
2022 natptr
->r_index
[0] = r_index
>> 16;
2023 natptr
->r_index
[1] = r_index
>> 8;
2024 natptr
->r_index
[2] = r_index
;
2025 natptr
->r_type
[0] = ((r_extern
? RELOC_STD_BITS_EXTERN_BIG
: 0)
2026 | (r_pcrel
? RELOC_STD_BITS_PCREL_BIG
: 0)
2027 | (r_baserel
? RELOC_STD_BITS_BASEREL_BIG
: 0)
2028 | (r_jmptable
? RELOC_STD_BITS_JMPTABLE_BIG
: 0)
2029 | (r_relative
? RELOC_STD_BITS_RELATIVE_BIG
: 0)
2030 | (r_length
<< RELOC_STD_BITS_LENGTH_SH_BIG
));
2034 natptr
->r_index
[2] = r_index
>> 16;
2035 natptr
->r_index
[1] = r_index
>> 8;
2036 natptr
->r_index
[0] = r_index
;
2037 natptr
->r_type
[0] = ((r_extern
? RELOC_STD_BITS_EXTERN_LITTLE
: 0)
2038 | (r_pcrel
? RELOC_STD_BITS_PCREL_LITTLE
: 0)
2039 | (r_baserel
? RELOC_STD_BITS_BASEREL_LITTLE
: 0)
2040 | (r_jmptable
? RELOC_STD_BITS_JMPTABLE_LITTLE
: 0)
2041 | (r_relative
? RELOC_STD_BITS_RELATIVE_LITTLE
: 0)
2042 | (r_length
<< RELOC_STD_BITS_LENGTH_SH_LITTLE
));
2046 /* Extended stuff. */
2047 /* Output extended relocation information to a file in target byte order. */
2049 extern void NAME(aout
,swap_ext_reloc_out
)
2050 PARAMS ((bfd
*, arelent
*, struct reloc_ext_external
*));
2053 NAME(aout
,swap_ext_reloc_out
) (abfd
, g
, natptr
)
2056 register struct reloc_ext_external
*natptr
;
2060 unsigned int r_type
;
2062 asymbol
*sym
= *(g
->sym_ptr_ptr
);
2063 asection
*output_section
= sym
->section
->output_section
;
2065 PUT_WORD (abfd
, g
->address
, natptr
->r_address
);
2067 r_type
= (unsigned int) g
->howto
->type
;
2069 r_addend
= g
->addend
;
2070 if ((sym
->flags
& BSF_SECTION_SYM
) != 0)
2071 r_addend
+= (*(g
->sym_ptr_ptr
))->section
->output_section
->vma
;
2073 /* If this relocation is relative to a symbol then set the
2074 r_index to the symbols index, and the r_extern bit.
2076 Absolute symbols can come in in two ways, either as an offset
2077 from the abs section, or as a symbol which has an abs value.
2078 check for that here. */
2079 if (bfd_is_abs_section (bfd_get_section (sym
)))
2084 else if ((sym
->flags
& BSF_SECTION_SYM
) == 0)
2086 if (bfd_is_und_section (bfd_get_section (sym
))
2087 || (sym
->flags
& BSF_GLOBAL
) != 0)
2091 r_index
= (*(g
->sym_ptr_ptr
))->KEEPIT
;
2095 /* Just an ordinary section. */
2097 r_index
= output_section
->target_index
;
2100 /* Now the fun stuff. */
2101 if (bfd_header_big_endian (abfd
))
2103 natptr
->r_index
[0] = r_index
>> 16;
2104 natptr
->r_index
[1] = r_index
>> 8;
2105 natptr
->r_index
[2] = r_index
;
2106 natptr
->r_type
[0] = ((r_extern
? RELOC_EXT_BITS_EXTERN_BIG
: 0)
2107 | (r_type
<< RELOC_EXT_BITS_TYPE_SH_BIG
));
2111 natptr
->r_index
[2] = r_index
>> 16;
2112 natptr
->r_index
[1] = r_index
>> 8;
2113 natptr
->r_index
[0] = r_index
;
2114 natptr
->r_type
[0] = ((r_extern
? RELOC_EXT_BITS_EXTERN_LITTLE
: 0)
2115 | (r_type
<< RELOC_EXT_BITS_TYPE_SH_LITTLE
));
2118 PUT_WORD (abfd
, r_addend
, natptr
->r_addend
);
2121 /* BFD deals internally with all things based from the section they're
2122 in. so, something in 10 bytes into a text section with a base of
2123 50 would have a symbol (.text+10) and know .text vma was 50.
2125 Aout keeps all it's symbols based from zero, so the symbol would
2126 contain 60. This macro subs the base of each section from the value
2127 to give the true offset from the section. */
2129 #define MOVE_ADDRESS(ad) \
2132 /* Undefined symbol. */ \
2133 cache_ptr->sym_ptr_ptr = symbols + r_index; \
2134 cache_ptr->addend = ad; \
2138 /* Defined, section relative. Replace symbol with pointer to \
2139 symbol which points to section. */ \
2143 case N_TEXT | N_EXT: \
2144 cache_ptr->sym_ptr_ptr = obj_textsec (abfd)->symbol_ptr_ptr; \
2145 cache_ptr->addend = ad - su->textsec->vma; \
2148 case N_DATA | N_EXT: \
2149 cache_ptr->sym_ptr_ptr = obj_datasec (abfd)->symbol_ptr_ptr; \
2150 cache_ptr->addend = ad - su->datasec->vma; \
2153 case N_BSS | N_EXT: \
2154 cache_ptr->sym_ptr_ptr = obj_bsssec (abfd)->symbol_ptr_ptr; \
2155 cache_ptr->addend = ad - su->bsssec->vma; \
2159 case N_ABS | N_EXT: \
2160 cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr; \
2161 cache_ptr->addend = ad; \
2167 NAME(aout
,swap_ext_reloc_in
) (abfd
, bytes
, cache_ptr
, symbols
, symcount
)
2169 struct reloc_ext_external
*bytes
;
2172 bfd_size_type symcount
;
2174 unsigned int r_index
;
2176 unsigned int r_type
;
2177 struct aoutdata
*su
= &(abfd
->tdata
.aout_data
->a
);
2179 cache_ptr
->address
= (GET_SWORD (abfd
, bytes
->r_address
));
2181 /* Now the fun stuff. */
2182 if (bfd_header_big_endian (abfd
))
2184 r_index
= (((unsigned int) bytes
->r_index
[0] << 16)
2185 | ((unsigned int) bytes
->r_index
[1] << 8)
2186 | bytes
->r_index
[2]);
2187 r_extern
= (0 != (bytes
->r_type
[0] & RELOC_EXT_BITS_EXTERN_BIG
));
2188 r_type
= ((bytes
->r_type
[0] & RELOC_EXT_BITS_TYPE_BIG
)
2189 >> RELOC_EXT_BITS_TYPE_SH_BIG
);
2193 r_index
= (((unsigned int) bytes
->r_index
[2] << 16)
2194 | ((unsigned int) bytes
->r_index
[1] << 8)
2195 | bytes
->r_index
[0]);
2196 r_extern
= (0 != (bytes
->r_type
[0] & RELOC_EXT_BITS_EXTERN_LITTLE
));
2197 r_type
= ((bytes
->r_type
[0] & RELOC_EXT_BITS_TYPE_LITTLE
)
2198 >> RELOC_EXT_BITS_TYPE_SH_LITTLE
);
2201 cache_ptr
->howto
= howto_table_ext
+ r_type
;
2203 /* Base relative relocs are always against the symbol table,
2204 regardless of the setting of r_extern. r_extern just reflects
2205 whether the symbol the reloc is against is local or global. */
2206 if (r_type
== (unsigned int) RELOC_BASE10
2207 || r_type
== (unsigned int) RELOC_BASE13
2208 || r_type
== (unsigned int) RELOC_BASE22
)
2211 if (r_extern
&& r_index
> symcount
)
2213 /* We could arrange to return an error, but it might be useful
2214 to see the file even if it is bad. */
2219 MOVE_ADDRESS (GET_SWORD (abfd
, bytes
->r_addend
));
2223 NAME(aout
,swap_std_reloc_in
) (abfd
, bytes
, cache_ptr
, symbols
, symcount
)
2225 struct reloc_std_external
*bytes
;
2228 bfd_size_type symcount
;
2230 unsigned int r_index
;
2232 unsigned int r_length
;
2234 int r_baserel
, r_jmptable
, r_relative
;
2235 struct aoutdata
*su
= &(abfd
->tdata
.aout_data
->a
);
2236 unsigned int howto_idx
;
2238 cache_ptr
->address
= H_GET_32 (abfd
, bytes
->r_address
);
2240 /* Now the fun stuff. */
2241 if (bfd_header_big_endian (abfd
))
2243 r_index
= (((unsigned int) bytes
->r_index
[0] << 16)
2244 | ((unsigned int) bytes
->r_index
[1] << 8)
2245 | bytes
->r_index
[2]);
2246 r_extern
= (0 != (bytes
->r_type
[0] & RELOC_STD_BITS_EXTERN_BIG
));
2247 r_pcrel
= (0 != (bytes
->r_type
[0] & RELOC_STD_BITS_PCREL_BIG
));
2248 r_baserel
= (0 != (bytes
->r_type
[0] & RELOC_STD_BITS_BASEREL_BIG
));
2249 r_jmptable
= (0 != (bytes
->r_type
[0] & RELOC_STD_BITS_JMPTABLE_BIG
));
2250 r_relative
= (0 != (bytes
->r_type
[0] & RELOC_STD_BITS_RELATIVE_BIG
));
2251 r_length
= ((bytes
->r_type
[0] & RELOC_STD_BITS_LENGTH_BIG
)
2252 >> RELOC_STD_BITS_LENGTH_SH_BIG
);
2256 r_index
= (((unsigned int) bytes
->r_index
[2] << 16)
2257 | ((unsigned int) bytes
->r_index
[1] << 8)
2258 | bytes
->r_index
[0]);
2259 r_extern
= (0 != (bytes
->r_type
[0] & RELOC_STD_BITS_EXTERN_LITTLE
));
2260 r_pcrel
= (0 != (bytes
->r_type
[0] & RELOC_STD_BITS_PCREL_LITTLE
));
2261 r_baserel
= (0 != (bytes
->r_type
[0] & RELOC_STD_BITS_BASEREL_LITTLE
));
2262 r_jmptable
= (0 != (bytes
->r_type
[0] & RELOC_STD_BITS_JMPTABLE_LITTLE
));
2263 r_relative
= (0 != (bytes
->r_type
[0] & RELOC_STD_BITS_RELATIVE_LITTLE
));
2264 r_length
= ((bytes
->r_type
[0] & RELOC_STD_BITS_LENGTH_LITTLE
)
2265 >> RELOC_STD_BITS_LENGTH_SH_LITTLE
);
2268 howto_idx
= (r_length
+ 4 * r_pcrel
+ 8 * r_baserel
2269 + 16 * r_jmptable
+ 32 * r_relative
);
2270 BFD_ASSERT (howto_idx
< TABLE_SIZE (howto_table_std
));
2271 cache_ptr
->howto
= howto_table_std
+ howto_idx
;
2272 BFD_ASSERT (cache_ptr
->howto
->type
!= (unsigned int) -1);
2274 /* Base relative relocs are always against the symbol table,
2275 regardless of the setting of r_extern. r_extern just reflects
2276 whether the symbol the reloc is against is local or global. */
2280 if (r_extern
&& r_index
> symcount
)
2282 /* We could arrange to return an error, but it might be useful
2283 to see the file even if it is bad. */
2291 /* Read and swap the relocs for a section. */
2294 NAME(aout
,slurp_reloc_table
) (abfd
, asect
, symbols
)
2299 bfd_size_type count
;
2300 bfd_size_type reloc_size
;
2302 arelent
*reloc_cache
;
2304 unsigned int counter
= 0;
2308 if (asect
->relocation
)
2311 if (asect
->flags
& SEC_CONSTRUCTOR
)
2314 if (asect
== obj_datasec (abfd
))
2315 reloc_size
= exec_hdr (abfd
)->a_drsize
;
2316 else if (asect
== obj_textsec (abfd
))
2317 reloc_size
= exec_hdr (abfd
)->a_trsize
;
2318 else if (asect
== obj_bsssec (abfd
))
2322 bfd_set_error (bfd_error_invalid_operation
);
2326 if (bfd_seek (abfd
, asect
->rel_filepos
, SEEK_SET
) != 0)
2329 each_size
= obj_reloc_entry_size (abfd
);
2331 count
= reloc_size
/ each_size
;
2333 amt
= count
* sizeof (arelent
);
2334 reloc_cache
= (arelent
*) bfd_zmalloc (amt
);
2335 if (reloc_cache
== NULL
&& count
!= 0)
2338 relocs
= bfd_malloc (reloc_size
);
2339 if (relocs
== NULL
&& reloc_size
!= 0)
2345 if (bfd_bread (relocs
, reloc_size
, abfd
) != reloc_size
)
2352 cache_ptr
= reloc_cache
;
2353 if (each_size
== RELOC_EXT_SIZE
)
2355 struct reloc_ext_external
*rptr
= (struct reloc_ext_external
*) relocs
;
2357 for (; counter
< count
; counter
++, rptr
++, cache_ptr
++)
2358 MY_swap_ext_reloc_in (abfd
, rptr
, cache_ptr
, symbols
,
2359 (bfd_size_type
) bfd_get_symcount (abfd
));
2363 struct reloc_std_external
*rptr
= (struct reloc_std_external
*) relocs
;
2365 for (; counter
< count
; counter
++, rptr
++, cache_ptr
++)
2366 MY_swap_std_reloc_in (abfd
, rptr
, cache_ptr
, symbols
,
2367 (bfd_size_type
) bfd_get_symcount (abfd
));
2372 asect
->relocation
= reloc_cache
;
2373 asect
->reloc_count
= cache_ptr
- reloc_cache
;
2378 /* Write out a relocation section into an object file. */
2381 NAME(aout
,squirt_out_relocs
) (abfd
, section
)
2386 unsigned char *native
, *natptr
;
2389 unsigned int count
= section
->reloc_count
;
2390 bfd_size_type natsize
;
2392 if (count
== 0 || section
->orelocation
== NULL
)
2395 each_size
= obj_reloc_entry_size (abfd
);
2396 natsize
= (bfd_size_type
) each_size
* count
;
2397 native
= (unsigned char *) bfd_zalloc (abfd
, natsize
);
2401 generic
= section
->orelocation
;
2403 if (each_size
== RELOC_EXT_SIZE
)
2405 for (natptr
= native
;
2407 --count
, natptr
+= each_size
, ++generic
)
2408 MY_swap_ext_reloc_out (abfd
, *generic
,
2409 (struct reloc_ext_external
*) natptr
);
2413 for (natptr
= native
;
2415 --count
, natptr
+= each_size
, ++generic
)
2416 MY_swap_std_reloc_out (abfd
, *generic
,
2417 (struct reloc_std_external
*) natptr
);
2420 if (bfd_bwrite ((PTR
) native
, natsize
, abfd
) != natsize
)
2422 bfd_release (abfd
, native
);
2425 bfd_release (abfd
, native
);
2430 /* This is stupid. This function should be a boolean predicate. */
2433 NAME(aout
,canonicalize_reloc
) (abfd
, section
, relptr
, symbols
)
2439 arelent
*tblptr
= section
->relocation
;
2442 if (section
== obj_bsssec (abfd
))
2448 if (!(tblptr
|| NAME(aout
,slurp_reloc_table
) (abfd
, section
, symbols
)))
2451 if (section
->flags
& SEC_CONSTRUCTOR
)
2453 arelent_chain
*chain
= section
->constructor_chain
;
2454 for (count
= 0; count
< section
->reloc_count
; count
++)
2456 *relptr
++ = &chain
->relent
;
2457 chain
= chain
->next
;
2462 tblptr
= section
->relocation
;
2464 for (count
= 0; count
++ < section
->reloc_count
; )
2466 *relptr
++ = tblptr
++;
2471 return section
->reloc_count
;
2475 NAME(aout
,get_reloc_upper_bound
) (abfd
, asect
)
2479 if (bfd_get_format (abfd
) != bfd_object
)
2481 bfd_set_error (bfd_error_invalid_operation
);
2485 if (asect
->flags
& SEC_CONSTRUCTOR
)
2486 return (sizeof (arelent
*) * (asect
->reloc_count
+1));
2488 if (asect
== obj_datasec (abfd
))
2489 return (sizeof (arelent
*)
2490 * ((exec_hdr (abfd
)->a_drsize
/ obj_reloc_entry_size (abfd
))
2493 if (asect
== obj_textsec (abfd
))
2494 return (sizeof (arelent
*)
2495 * ((exec_hdr (abfd
)->a_trsize
/ obj_reloc_entry_size (abfd
))
2498 if (asect
== obj_bsssec (abfd
))
2499 return sizeof (arelent
*);
2501 if (asect
== obj_bsssec (abfd
))
2504 bfd_set_error (bfd_error_invalid_operation
);
2509 NAME(aout
,get_symtab_upper_bound
) (abfd
)
2512 if (!NAME(aout
,slurp_symbol_table
) (abfd
))
2515 return (bfd_get_symcount (abfd
)+1) * (sizeof (aout_symbol_type
*));
2519 NAME(aout
,get_lineno
) (ignore_abfd
, ignore_symbol
)
2520 bfd
*ignore_abfd ATTRIBUTE_UNUSED
;
2521 asymbol
*ignore_symbol ATTRIBUTE_UNUSED
;
2523 return (alent
*)NULL
;
2527 NAME(aout
,get_symbol_info
) (ignore_abfd
, symbol
, ret
)
2528 bfd
*ignore_abfd ATTRIBUTE_UNUSED
;
2532 bfd_symbol_info (symbol
, ret
);
2534 if (ret
->type
== '?')
2536 int type_code
= aout_symbol (symbol
)->type
& 0xff;
2537 const char *stab_name
= bfd_get_stab_name (type_code
);
2538 static char buf
[10];
2540 if (stab_name
== NULL
)
2542 sprintf (buf
, "(%d)", type_code
);
2546 ret
->stab_type
= type_code
;
2547 ret
->stab_other
= (unsigned) (aout_symbol (symbol
)->other
& 0xff);
2548 ret
->stab_desc
= (unsigned) (aout_symbol (symbol
)->desc
& 0xffff);
2549 ret
->stab_name
= stab_name
;
2554 NAME(aout
,print_symbol
) (abfd
, afile
, symbol
, how
)
2558 bfd_print_symbol_type how
;
2560 FILE *file
= (FILE *)afile
;
2564 case bfd_print_symbol_name
:
2566 fprintf (file
,"%s", symbol
->name
);
2568 case bfd_print_symbol_more
:
2569 fprintf (file
,"%4x %2x %2x",
2570 (unsigned) (aout_symbol (symbol
)->desc
& 0xffff),
2571 (unsigned) (aout_symbol (symbol
)->other
& 0xff),
2572 (unsigned) (aout_symbol (symbol
)->type
));
2574 case bfd_print_symbol_all
:
2576 const char *section_name
= symbol
->section
->name
;
2578 bfd_print_symbol_vandf (abfd
, (PTR
)file
, symbol
);
2580 fprintf (file
," %-5s %04x %02x %02x",
2582 (unsigned) (aout_symbol (symbol
)->desc
& 0xffff),
2583 (unsigned) (aout_symbol (symbol
)->other
& 0xff),
2584 (unsigned) (aout_symbol (symbol
)->type
& 0xff));
2586 fprintf (file
," %s", symbol
->name
);
2592 /* If we don't have to allocate more than 1MB to hold the generic
2593 symbols, we use the generic minisymbol methord: it's faster, since
2594 it only translates the symbols once, not multiple times. */
2595 #define MINISYM_THRESHOLD (1000000 / sizeof (asymbol))
2597 /* Read minisymbols. For minisymbols, we use the unmodified a.out
2598 symbols. The minisymbol_to_symbol function translates these into
2599 BFD asymbol structures. */
2602 NAME(aout
,read_minisymbols
) (abfd
, dynamic
, minisymsp
, sizep
)
2604 bfd_boolean dynamic
;
2606 unsigned int *sizep
;
2610 /* We could handle the dynamic symbols here as well, but it's
2611 easier to hand them off. */
2612 return _bfd_generic_read_minisymbols (abfd
, dynamic
, minisymsp
, sizep
);
2615 if (! aout_get_external_symbols (abfd
))
2618 if (obj_aout_external_sym_count (abfd
) < MINISYM_THRESHOLD
)
2619 return _bfd_generic_read_minisymbols (abfd
, dynamic
, minisymsp
, sizep
);
2621 *minisymsp
= (PTR
) obj_aout_external_syms (abfd
);
2623 /* By passing the external symbols back from this routine, we are
2624 giving up control over the memory block. Clear
2625 obj_aout_external_syms, so that we do not try to free it
2627 obj_aout_external_syms (abfd
) = NULL
;
2629 *sizep
= EXTERNAL_NLIST_SIZE
;
2630 return obj_aout_external_sym_count (abfd
);
2633 /* Convert a minisymbol to a BFD asymbol. A minisymbol is just an
2634 unmodified a.out symbol. The SYM argument is a structure returned
2635 by bfd_make_empty_symbol, which we fill in here. */
2638 NAME(aout
,minisymbol_to_symbol
) (abfd
, dynamic
, minisym
, sym
)
2640 bfd_boolean dynamic
;
2645 || obj_aout_external_sym_count (abfd
) < MINISYM_THRESHOLD
)
2646 return _bfd_generic_minisymbol_to_symbol (abfd
, dynamic
, minisym
, sym
);
2648 memset (sym
, 0, sizeof (aout_symbol_type
));
2650 /* We call translate_symbol_table to translate a single symbol. */
2651 if (! (NAME(aout
,translate_symbol_table
)
2653 (aout_symbol_type
*) sym
,
2654 (struct external_nlist
*) minisym
,
2656 obj_aout_external_strings (abfd
),
2657 obj_aout_external_string_size (abfd
),
2664 /* Provided a BFD, a section and an offset into the section, calculate
2665 and return the name of the source file and the line nearest to the
2669 NAME(aout
,find_nearest_line
)
2670 (abfd
, section
, symbols
, offset
, filename_ptr
, functionname_ptr
, line_ptr
)
2675 const char **filename_ptr
;
2676 const char **functionname_ptr
;
2677 unsigned int *line_ptr
;
2679 /* Run down the file looking for the filename, function and linenumber. */
2681 const char *directory_name
= NULL
;
2682 const char *main_file_name
= NULL
;
2683 const char *current_file_name
= NULL
;
2684 const char *line_file_name
= NULL
; /* Value of current_file_name at line number. */
2685 const char *line_directory_name
= NULL
; /* Value of directory_name at line number. */
2686 bfd_vma low_line_vma
= 0;
2687 bfd_vma low_func_vma
= 0;
2689 bfd_size_type filelen
, funclen
;
2692 *filename_ptr
= abfd
->filename
;
2693 *functionname_ptr
= 0;
2696 if (symbols
!= (asymbol
**)NULL
)
2698 for (p
= symbols
; *p
; p
++)
2700 aout_symbol_type
*q
= (aout_symbol_type
*) (*p
);
2705 /* If this looks like a file name symbol, and it comes after
2706 the line number we have found so far, but before the
2707 offset, then we have probably not found the right line
2709 if (q
->symbol
.value
<= offset
2710 && ((q
->symbol
.value
> low_line_vma
2711 && (line_file_name
!= NULL
2713 || (q
->symbol
.value
> low_func_vma
2716 const char *symname
;
2718 symname
= q
->symbol
.name
;
2719 if (strcmp (symname
+ strlen (symname
) - 2, ".o") == 0)
2721 if (q
->symbol
.value
> low_line_vma
)
2724 line_file_name
= NULL
;
2726 if (q
->symbol
.value
> low_func_vma
)
2733 /* If this symbol is less than the offset, but greater than
2734 the line number we have found so far, then we have not
2735 found the right line number. */
2736 if (q
->symbol
.value
<= offset
)
2738 if (q
->symbol
.value
> low_line_vma
)
2741 line_file_name
= NULL
;
2743 if (q
->symbol
.value
> low_func_vma
)
2747 main_file_name
= current_file_name
= q
->symbol
.name
;
2748 /* Look ahead to next symbol to check if that too is an N_SO. */
2752 q
= (aout_symbol_type
*) (*p
);
2753 if (q
->type
!= (int)N_SO
)
2756 /* Found a second N_SO First is directory; second is filename. */
2757 directory_name
= current_file_name
;
2758 main_file_name
= current_file_name
= q
->symbol
.name
;
2759 if (obj_textsec (abfd
) != section
)
2763 current_file_name
= q
->symbol
.name
;
2770 /* We'll keep this if it resolves nearer than the one we have
2772 if (q
->symbol
.value
>= low_line_vma
2773 && q
->symbol
.value
<= offset
)
2775 *line_ptr
= q
->desc
;
2776 low_line_vma
= q
->symbol
.value
;
2777 line_file_name
= current_file_name
;
2778 line_directory_name
= directory_name
;
2783 /* We'll keep this if it is nearer than the one we have already. */
2784 if (q
->symbol
.value
>= low_func_vma
&&
2785 q
->symbol
.value
<= offset
)
2787 low_func_vma
= q
->symbol
.value
;
2788 func
= (asymbol
*)q
;
2790 else if (q
->symbol
.value
> offset
)
2801 main_file_name
= line_file_name
;
2802 directory_name
= line_directory_name
;
2805 if (main_file_name
== NULL
2806 || IS_ABSOLUTE_PATH (main_file_name
)
2807 || directory_name
== NULL
)
2810 filelen
= strlen (directory_name
) + strlen (main_file_name
);
2815 funclen
= strlen (bfd_asymbol_name (func
));
2817 if (adata (abfd
).line_buf
!= NULL
)
2818 free (adata (abfd
).line_buf
);
2820 if (filelen
+ funclen
== 0)
2821 adata (abfd
).line_buf
= buf
= NULL
;
2824 buf
= (char *) bfd_malloc (filelen
+ funclen
+ 3);
2825 adata (abfd
).line_buf
= buf
;
2830 if (main_file_name
!= NULL
)
2832 if (IS_ABSOLUTE_PATH (main_file_name
) || directory_name
== NULL
)
2833 *filename_ptr
= main_file_name
;
2836 sprintf (buf
, "%s%s", directory_name
, main_file_name
);
2837 *filename_ptr
= buf
;
2844 const char *function
= func
->name
;
2847 /* The caller expects a symbol name. We actually have a
2848 function name, without the leading underscore. Put the
2849 underscore back in, so that the caller gets a symbol name. */
2850 if (bfd_get_symbol_leading_char (abfd
) == '\0')
2851 strcpy (buf
, function
);
2854 buf
[0] = bfd_get_symbol_leading_char (abfd
);
2855 strcpy (buf
+ 1, function
);
2857 /* Have to remove : stuff. */
2858 colon
= strchr (buf
, ':');
2861 *functionname_ptr
= buf
;
2868 NAME(aout
,sizeof_headers
) (abfd
, execable
)
2870 bfd_boolean execable ATTRIBUTE_UNUSED
;
2872 return adata (abfd
).exec_bytes_size
;
2875 /* Free all information we have cached for this BFD. We can always
2876 read it again later if we need it. */
2879 NAME(aout
,bfd_free_cached_info
) (abfd
)
2884 if (bfd_get_format (abfd
) != bfd_object
2885 || abfd
->tdata
.aout_data
== NULL
)
2888 #define BFCI_FREE(x) if (x != NULL) { free (x); x = NULL; }
2889 BFCI_FREE (obj_aout_symbols (abfd
));
2891 obj_aout_external_syms (abfd
) = 0;
2892 bfd_free_window (&obj_aout_sym_window (abfd
));
2893 bfd_free_window (&obj_aout_string_window (abfd
));
2894 obj_aout_external_strings (abfd
) = 0;
2896 BFCI_FREE (obj_aout_external_syms (abfd
));
2897 BFCI_FREE (obj_aout_external_strings (abfd
));
2899 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
2900 BFCI_FREE (o
->relocation
);
2906 /* a.out link code. */
2908 static bfd_boolean aout_link_add_object_symbols
2909 PARAMS ((bfd
*, struct bfd_link_info
*));
2910 static bfd_boolean aout_link_check_archive_element
2911 PARAMS ((bfd
*, struct bfd_link_info
*, bfd_boolean
*));
2912 static bfd_boolean aout_link_free_symbols
2914 static bfd_boolean aout_link_check_ar_symbols
2915 PARAMS ((bfd
*, struct bfd_link_info
*, bfd_boolean
*pneeded
));
2916 static bfd_boolean aout_link_add_symbols
2917 PARAMS ((bfd
*, struct bfd_link_info
*));
2919 /* Routine to create an entry in an a.out link hash table. */
2921 struct bfd_hash_entry
*
2922 NAME(aout
,link_hash_newfunc
) (entry
, table
, string
)
2923 struct bfd_hash_entry
*entry
;
2924 struct bfd_hash_table
*table
;
2927 struct aout_link_hash_entry
*ret
= (struct aout_link_hash_entry
*) entry
;
2929 /* Allocate the structure if it has not already been allocated by a
2931 if (ret
== (struct aout_link_hash_entry
*) NULL
)
2932 ret
= ((struct aout_link_hash_entry
*)
2933 bfd_hash_allocate (table
, sizeof (struct aout_link_hash_entry
)));
2934 if (ret
== (struct aout_link_hash_entry
*) NULL
)
2935 return (struct bfd_hash_entry
*) ret
;
2937 /* Call the allocation method of the superclass. */
2938 ret
= ((struct aout_link_hash_entry
*)
2939 _bfd_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
2943 /* Set local fields. */
2944 ret
->written
= FALSE
;
2948 return (struct bfd_hash_entry
*) ret
;
2951 /* Initialize an a.out link hash table. */
2954 NAME(aout
,link_hash_table_init
) (table
, abfd
, newfunc
)
2955 struct aout_link_hash_table
*table
;
2957 struct bfd_hash_entry
*(*newfunc
)
2958 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*,
2961 return _bfd_link_hash_table_init (&table
->root
, abfd
, newfunc
);
2964 /* Create an a.out link hash table. */
2966 struct bfd_link_hash_table
*
2967 NAME(aout
,link_hash_table_create
) (abfd
)
2970 struct aout_link_hash_table
*ret
;
2971 bfd_size_type amt
= sizeof (struct aout_link_hash_table
);
2973 ret
= (struct aout_link_hash_table
*) bfd_malloc (amt
);
2975 return (struct bfd_link_hash_table
*) NULL
;
2977 if (! NAME(aout
,link_hash_table_init
) (ret
, abfd
,
2978 NAME(aout
,link_hash_newfunc
)))
2981 return (struct bfd_link_hash_table
*) NULL
;
2986 /* Given an a.out BFD, add symbols to the global hash table as
2990 NAME(aout
,link_add_symbols
) (abfd
, info
)
2992 struct bfd_link_info
*info
;
2994 switch (bfd_get_format (abfd
))
2997 return aout_link_add_object_symbols (abfd
, info
);
2999 return _bfd_generic_link_add_archive_symbols
3000 (abfd
, info
, aout_link_check_archive_element
);
3002 bfd_set_error (bfd_error_wrong_format
);
3007 /* Add symbols from an a.out object file. */
3010 aout_link_add_object_symbols (abfd
, info
)
3012 struct bfd_link_info
*info
;
3014 if (! aout_get_external_symbols (abfd
))
3016 if (! aout_link_add_symbols (abfd
, info
))
3018 if (! info
->keep_memory
)
3020 if (! aout_link_free_symbols (abfd
))
3026 /* Check a single archive element to see if we need to include it in
3027 the link. *PNEEDED is set according to whether this element is
3028 needed in the link or not. This is called from
3029 _bfd_generic_link_add_archive_symbols. */
3032 aout_link_check_archive_element (abfd
, info
, pneeded
)
3034 struct bfd_link_info
*info
;
3035 bfd_boolean
*pneeded
;
3037 if (! aout_get_external_symbols (abfd
))
3040 if (! aout_link_check_ar_symbols (abfd
, info
, pneeded
))
3045 if (! aout_link_add_symbols (abfd
, info
))
3049 if (! info
->keep_memory
|| ! *pneeded
)
3051 if (! aout_link_free_symbols (abfd
))
3058 /* Free up the internal symbols read from an a.out file. */
3061 aout_link_free_symbols (abfd
)
3064 if (obj_aout_external_syms (abfd
) != (struct external_nlist
*) NULL
)
3067 bfd_free_window (&obj_aout_sym_window (abfd
));
3069 free ((PTR
) obj_aout_external_syms (abfd
));
3071 obj_aout_external_syms (abfd
) = (struct external_nlist
*) NULL
;
3073 if (obj_aout_external_strings (abfd
) != (char *) NULL
)
3076 bfd_free_window (&obj_aout_string_window (abfd
));
3078 free ((PTR
) obj_aout_external_strings (abfd
));
3080 obj_aout_external_strings (abfd
) = (char *) NULL
;
3085 /* Look through the internal symbols to see if this object file should
3086 be included in the link. We should include this object file if it
3087 defines any symbols which are currently undefined. If this object
3088 file defines a common symbol, then we may adjust the size of the
3089 known symbol but we do not include the object file in the link
3090 (unless there is some other reason to include it). */
3093 aout_link_check_ar_symbols (abfd
, info
, pneeded
)
3095 struct bfd_link_info
*info
;
3096 bfd_boolean
*pneeded
;
3098 register struct external_nlist
*p
;
3099 struct external_nlist
*pend
;
3104 /* Look through all the symbols. */
3105 p
= obj_aout_external_syms (abfd
);
3106 pend
= p
+ obj_aout_external_sym_count (abfd
);
3107 strings
= obj_aout_external_strings (abfd
);
3108 for (; p
< pend
; p
++)
3110 int type
= H_GET_8 (abfd
, p
->e_type
);
3112 struct bfd_link_hash_entry
*h
;
3114 /* Ignore symbols that are not externally visible. This is an
3115 optimization only, as we check the type more thoroughly
3117 if (((type
& N_EXT
) == 0
3118 || (type
& N_STAB
) != 0
3125 if (type
== N_WARNING
3131 name
= strings
+ GET_WORD (abfd
, p
->e_strx
);
3132 h
= bfd_link_hash_lookup (info
->hash
, name
, FALSE
, FALSE
, TRUE
);
3134 /* We are only interested in symbols that are currently
3135 undefined or common. */
3136 if (h
== (struct bfd_link_hash_entry
*) NULL
3137 || (h
->type
!= bfd_link_hash_undefined
3138 && h
->type
!= bfd_link_hash_common
))
3140 if (type
== (N_INDR
| N_EXT
))
3145 if (type
== (N_TEXT
| N_EXT
)
3146 || type
== (N_DATA
| N_EXT
)
3147 || type
== (N_BSS
| N_EXT
)
3148 || type
== (N_ABS
| N_EXT
)
3149 || type
== (N_INDR
| N_EXT
))
3151 /* This object file defines this symbol. We must link it
3152 in. This is true regardless of whether the current
3153 definition of the symbol is undefined or common.
3155 If the current definition is common, we have a case in
3156 which we have already seen an object file including:
3158 and this object file from the archive includes:
3160 In such a case, whether to include this object is target
3161 dependant for backward compatibility.
3163 FIXME: The SunOS 4.1.3 linker will pull in the archive
3164 element if the symbol is defined in the .data section,
3165 but not if it is defined in the .text section. That
3166 seems a bit crazy to me, and it has not been implemented
3167 yet. However, it might be correct. */
3168 if (h
->type
== bfd_link_hash_common
)
3172 switch (info
->common_skip_ar_aymbols
)
3174 case bfd_link_common_skip_text
:
3175 skip
= (type
== (N_TEXT
| N_EXT
));
3177 case bfd_link_common_skip_data
:
3178 skip
= (type
== (N_DATA
| N_EXT
));
3181 case bfd_link_common_skip_all
:
3190 if (! (*info
->callbacks
->add_archive_element
) (info
, abfd
, name
))
3196 if (type
== (N_UNDF
| N_EXT
))
3200 value
= GET_WORD (abfd
, p
->e_value
);
3203 /* This symbol is common in the object from the archive
3205 if (h
->type
== bfd_link_hash_undefined
)
3210 symbfd
= h
->u
.undef
.abfd
;
3211 if (symbfd
== (bfd
*) NULL
)
3213 /* This symbol was created as undefined from
3214 outside BFD. We assume that we should link
3215 in the object file. This is done for the -u
3216 option in the linker. */
3217 if (! (*info
->callbacks
->add_archive_element
) (info
,
3224 /* Turn the current link symbol into a common
3225 symbol. It is already on the undefs list. */
3226 h
->type
= bfd_link_hash_common
;
3227 h
->u
.c
.p
= ((struct bfd_link_hash_common_entry
*)
3228 bfd_hash_allocate (&info
->hash
->table
,
3229 sizeof (struct bfd_link_hash_common_entry
)));
3230 if (h
->u
.c
.p
== NULL
)
3233 h
->u
.c
.size
= value
;
3235 /* FIXME: This isn't quite right. The maximum
3236 alignment of a common symbol should be set by the
3237 architecture of the output file, not of the input
3239 power
= bfd_log2 (value
);
3240 if (power
> bfd_get_arch_info (abfd
)->section_align_power
)
3241 power
= bfd_get_arch_info (abfd
)->section_align_power
;
3242 h
->u
.c
.p
->alignment_power
= power
;
3244 h
->u
.c
.p
->section
= bfd_make_section_old_way (symbfd
,
3249 /* Adjust the size of the common symbol if
3251 if (value
> h
->u
.c
.size
)
3252 h
->u
.c
.size
= value
;
3262 /* This symbol is weak but defined. We must pull it in if
3263 the current link symbol is undefined, but we don't want
3264 it if the current link symbol is common. */
3265 if (h
->type
== bfd_link_hash_undefined
)
3267 if (! (*info
->callbacks
->add_archive_element
) (info
, abfd
, name
))
3275 /* We do not need this object file. */
3279 /* Add all symbols from an object file to the hash table. */
3282 aout_link_add_symbols (abfd
, info
)
3284 struct bfd_link_info
*info
;
3286 bfd_boolean (*add_one_symbol
)
3287 PARAMS ((struct bfd_link_info
*, bfd
*, const char *, flagword
, asection
*,
3288 bfd_vma
, const char *, bfd_boolean
, bfd_boolean
,
3289 struct bfd_link_hash_entry
**));
3290 struct external_nlist
*syms
;
3291 bfd_size_type sym_count
;
3294 struct aout_link_hash_entry
**sym_hash
;
3295 register struct external_nlist
*p
;
3296 struct external_nlist
*pend
;
3299 syms
= obj_aout_external_syms (abfd
);
3300 sym_count
= obj_aout_external_sym_count (abfd
);
3301 strings
= obj_aout_external_strings (abfd
);
3302 if (info
->keep_memory
)
3307 if (aout_backend_info (abfd
)->add_dynamic_symbols
!= NULL
)
3309 if (! ((*aout_backend_info (abfd
)->add_dynamic_symbols
)
3310 (abfd
, info
, &syms
, &sym_count
, &strings
)))
3314 /* We keep a list of the linker hash table entries that correspond
3315 to particular symbols. We could just look them up in the hash
3316 table, but keeping the list is more efficient. Perhaps this
3317 should be conditional on info->keep_memory. */
3318 amt
= sym_count
* sizeof (struct aout_link_hash_entry
*);
3319 sym_hash
= (struct aout_link_hash_entry
**) bfd_alloc (abfd
, amt
);
3320 if (sym_hash
== NULL
&& sym_count
!= 0)
3322 obj_aout_sym_hashes (abfd
) = sym_hash
;
3324 add_one_symbol
= aout_backend_info (abfd
)->add_one_symbol
;
3325 if (add_one_symbol
== NULL
)
3326 add_one_symbol
= _bfd_generic_link_add_one_symbol
;
3329 pend
= p
+ sym_count
;
3330 for (; p
< pend
; p
++, sym_hash
++)
3341 type
= H_GET_8 (abfd
, p
->e_type
);
3343 /* Ignore debugging symbols. */
3344 if ((type
& N_STAB
) != 0)
3347 name
= strings
+ GET_WORD (abfd
, p
->e_strx
);
3348 value
= GET_WORD (abfd
, p
->e_value
);
3365 /* Ignore symbols that are not externally visible. */
3368 /* Ignore local indirect symbol. */
3373 case N_UNDF
| N_EXT
:
3376 section
= bfd_und_section_ptr
;
3380 section
= bfd_com_section_ptr
;
3383 section
= bfd_abs_section_ptr
;
3385 case N_TEXT
| N_EXT
:
3386 section
= obj_textsec (abfd
);
3387 value
-= bfd_get_section_vma (abfd
, section
);
3389 case N_DATA
| N_EXT
:
3390 case N_SETV
| N_EXT
:
3391 /* Treat N_SETV symbols as N_DATA symbol; see comment in
3392 translate_from_native_sym_flags. */
3393 section
= obj_datasec (abfd
);
3394 value
-= bfd_get_section_vma (abfd
, section
);
3397 section
= obj_bsssec (abfd
);
3398 value
-= bfd_get_section_vma (abfd
, section
);
3400 case N_INDR
| N_EXT
:
3401 /* An indirect symbol. The next symbol is the symbol
3402 which this one really is. */
3403 BFD_ASSERT (p
+ 1 < pend
);
3405 string
= strings
+ GET_WORD (abfd
, p
->e_strx
);
3406 section
= bfd_ind_section_ptr
;
3407 flags
|= BSF_INDIRECT
;
3409 case N_COMM
| N_EXT
:
3410 section
= bfd_com_section_ptr
;
3412 case N_SETA
: case N_SETA
| N_EXT
:
3413 section
= bfd_abs_section_ptr
;
3414 flags
|= BSF_CONSTRUCTOR
;
3416 case N_SETT
: case N_SETT
| N_EXT
:
3417 section
= obj_textsec (abfd
);
3418 flags
|= BSF_CONSTRUCTOR
;
3419 value
-= bfd_get_section_vma (abfd
, section
);
3421 case N_SETD
: case N_SETD
| N_EXT
:
3422 section
= obj_datasec (abfd
);
3423 flags
|= BSF_CONSTRUCTOR
;
3424 value
-= bfd_get_section_vma (abfd
, section
);
3426 case N_SETB
: case N_SETB
| N_EXT
:
3427 section
= obj_bsssec (abfd
);
3428 flags
|= BSF_CONSTRUCTOR
;
3429 value
-= bfd_get_section_vma (abfd
, section
);
3432 /* A warning symbol. The next symbol is the one to warn
3434 BFD_ASSERT (p
+ 1 < pend
);
3437 name
= strings
+ GET_WORD (abfd
, p
->e_strx
);
3438 section
= bfd_und_section_ptr
;
3439 flags
|= BSF_WARNING
;
3442 section
= bfd_und_section_ptr
;
3446 section
= bfd_abs_section_ptr
;
3450 section
= obj_textsec (abfd
);
3451 value
-= bfd_get_section_vma (abfd
, section
);
3455 section
= obj_datasec (abfd
);
3456 value
-= bfd_get_section_vma (abfd
, section
);
3460 section
= obj_bsssec (abfd
);
3461 value
-= bfd_get_section_vma (abfd
, section
);
3466 if (! ((*add_one_symbol
)
3467 (info
, abfd
, name
, flags
, section
, value
, string
, copy
, FALSE
,
3468 (struct bfd_link_hash_entry
**) sym_hash
)))
3471 /* Restrict the maximum alignment of a common symbol based on
3472 the architecture, since a.out has no way to represent
3473 alignment requirements of a section in a .o file. FIXME:
3474 This isn't quite right: it should use the architecture of the
3475 output file, not the input files. */
3476 if ((*sym_hash
)->root
.type
== bfd_link_hash_common
3477 && ((*sym_hash
)->root
.u
.c
.p
->alignment_power
>
3478 bfd_get_arch_info (abfd
)->section_align_power
))
3479 (*sym_hash
)->root
.u
.c
.p
->alignment_power
=
3480 bfd_get_arch_info (abfd
)->section_align_power
;
3482 /* If this is a set symbol, and we are not building sets, then
3483 it is possible for the hash entry to not have been set. In
3484 such a case, treat the symbol as not globally defined. */
3485 if ((*sym_hash
)->root
.type
== bfd_link_hash_new
)
3487 BFD_ASSERT ((flags
& BSF_CONSTRUCTOR
) != 0);
3491 if (type
== (N_INDR
| N_EXT
) || type
== N_WARNING
)
3498 /* A hash table used for header files with N_BINCL entries. */
3500 struct aout_link_includes_table
3502 struct bfd_hash_table root
;
3505 /* A linked list of totals that we have found for a particular header
3508 struct aout_link_includes_totals
3510 struct aout_link_includes_totals
*next
;
3514 /* An entry in the header file hash table. */
3516 struct aout_link_includes_entry
3518 struct bfd_hash_entry root
;
3519 /* List of totals we have found for this file. */
3520 struct aout_link_includes_totals
*totals
;
3523 /* Look up an entry in an the header file hash table. */
3525 #define aout_link_includes_lookup(table, string, create, copy) \
3526 ((struct aout_link_includes_entry *) \
3527 bfd_hash_lookup (&(table)->root, (string), (create), (copy)))
3529 /* During the final link step we need to pass around a bunch of
3530 information, so we do it in an instance of this structure. */
3532 struct aout_final_link_info
3534 /* General link information. */
3535 struct bfd_link_info
*info
;
3538 /* Reloc file positions. */
3539 file_ptr treloff
, dreloff
;
3540 /* File position of symbols. */
3543 struct bfd_strtab_hash
*strtab
;
3544 /* Header file hash table. */
3545 struct aout_link_includes_table includes
;
3546 /* A buffer large enough to hold the contents of any section. */
3548 /* A buffer large enough to hold the relocs of any section. */
3550 /* A buffer large enough to hold the symbol map of any input BFD. */
3552 /* A buffer large enough to hold output symbols of any input BFD. */
3553 struct external_nlist
*output_syms
;
3556 static struct bfd_hash_entry
*aout_link_includes_newfunc
3557 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
3558 static bfd_boolean aout_link_input_bfd
3559 PARAMS ((struct aout_final_link_info
*, bfd
*input_bfd
));
3560 static bfd_boolean aout_link_write_symbols
3561 PARAMS ((struct aout_final_link_info
*, bfd
*input_bfd
));
3562 static bfd_boolean aout_link_write_other_symbol
3563 PARAMS ((struct aout_link_hash_entry
*, PTR
));
3564 static bfd_boolean aout_link_input_section
3565 PARAMS ((struct aout_final_link_info
*, bfd
*input_bfd
,
3566 asection
*input_section
, file_ptr
*reloff_ptr
,
3567 bfd_size_type rel_size
));
3568 static bfd_boolean aout_link_input_section_std
3569 PARAMS ((struct aout_final_link_info
*, bfd
*input_bfd
,
3570 asection
*input_section
, struct reloc_std_external
*,
3571 bfd_size_type rel_size
, bfd_byte
*contents
));
3572 static bfd_boolean aout_link_input_section_ext
3573 PARAMS ((struct aout_final_link_info
*, bfd
*input_bfd
,
3574 asection
*input_section
, struct reloc_ext_external
*,
3575 bfd_size_type rel_size
, bfd_byte
*contents
));
3576 static INLINE asection
*aout_reloc_index_to_section
3577 PARAMS ((bfd
*, int));
3578 static bfd_boolean aout_link_reloc_link_order
3579 PARAMS ((struct aout_final_link_info
*, asection
*,
3580 struct bfd_link_order
*));
3582 /* The function to create a new entry in the header file hash table. */
3584 static struct bfd_hash_entry
*
3585 aout_link_includes_newfunc (entry
, table
, string
)
3586 struct bfd_hash_entry
*entry
;
3587 struct bfd_hash_table
*table
;
3590 struct aout_link_includes_entry
*ret
=
3591 (struct aout_link_includes_entry
*) entry
;
3593 /* Allocate the structure if it has not already been allocated by a
3595 if (ret
== (struct aout_link_includes_entry
*) NULL
)
3596 ret
= ((struct aout_link_includes_entry
*)
3597 bfd_hash_allocate (table
,
3598 sizeof (struct aout_link_includes_entry
)));
3599 if (ret
== (struct aout_link_includes_entry
*) NULL
)
3600 return (struct bfd_hash_entry
*) ret
;
3602 /* Call the allocation method of the superclass. */
3603 ret
= ((struct aout_link_includes_entry
*)
3604 bfd_hash_newfunc ((struct bfd_hash_entry
*) ret
, table
, string
));
3607 /* Set local fields. */
3611 return (struct bfd_hash_entry
*) ret
;
3614 /* Do the final link step. This is called on the output BFD. The
3615 INFO structure should point to a list of BFDs linked through the
3616 link_next field which can be used to find each BFD which takes part
3617 in the output. Also, each section in ABFD should point to a list
3618 of bfd_link_order structures which list all the input sections for
3619 the output section. */
3622 NAME(aout
,final_link
) (abfd
, info
, callback
)
3624 struct bfd_link_info
*info
;
3625 void (*callback
) PARAMS ((bfd
*, file_ptr
*, file_ptr
*, file_ptr
*));
3627 struct aout_final_link_info aout_info
;
3628 bfd_boolean includes_hash_initialized
= FALSE
;
3630 bfd_size_type trsize
, drsize
;
3631 bfd_size_type max_contents_size
;
3632 bfd_size_type max_relocs_size
;
3633 bfd_size_type max_sym_count
;
3634 bfd_size_type text_size
;
3636 register struct bfd_link_order
*p
;
3638 bfd_boolean have_link_order_relocs
;
3641 abfd
->flags
|= DYNAMIC
;
3643 aout_info
.info
= info
;
3644 aout_info
.output_bfd
= abfd
;
3645 aout_info
.contents
= NULL
;
3646 aout_info
.relocs
= NULL
;
3647 aout_info
.symbol_map
= NULL
;
3648 aout_info
.output_syms
= NULL
;
3650 if (! bfd_hash_table_init_n (&aout_info
.includes
.root
,
3651 aout_link_includes_newfunc
,
3654 includes_hash_initialized
= TRUE
;
3656 /* Figure out the largest section size. Also, if generating
3657 relocatable output, count the relocs. */
3660 max_contents_size
= 0;
3661 max_relocs_size
= 0;
3663 for (sub
= info
->input_bfds
; sub
!= NULL
; sub
= sub
->link_next
)
3667 if (info
->relocatable
)
3669 if (bfd_get_flavour (sub
) == bfd_target_aout_flavour
)
3671 trsize
+= exec_hdr (sub
)->a_trsize
;
3672 drsize
+= exec_hdr (sub
)->a_drsize
;
3676 /* FIXME: We need to identify the .text and .data sections
3677 and call get_reloc_upper_bound and canonicalize_reloc to
3678 work out the number of relocs needed, and then multiply
3679 by the reloc size. */
3680 (*_bfd_error_handler
)
3681 (_("%s: relocatable link from %s to %s not supported"),
3682 bfd_get_filename (abfd
),
3683 sub
->xvec
->name
, abfd
->xvec
->name
);
3684 bfd_set_error (bfd_error_invalid_operation
);
3689 if (bfd_get_flavour (sub
) == bfd_target_aout_flavour
)
3691 sz
= obj_textsec (sub
)->size
;
3692 if (sz
> max_contents_size
)
3693 max_contents_size
= sz
;
3694 sz
= obj_datasec (sub
)->size
;
3695 if (sz
> max_contents_size
)
3696 max_contents_size
= sz
;
3698 sz
= exec_hdr (sub
)->a_trsize
;
3699 if (sz
> max_relocs_size
)
3700 max_relocs_size
= sz
;
3701 sz
= exec_hdr (sub
)->a_drsize
;
3702 if (sz
> max_relocs_size
)
3703 max_relocs_size
= sz
;
3705 sz
= obj_aout_external_sym_count (sub
);
3706 if (sz
> max_sym_count
)
3711 if (info
->relocatable
)
3713 if (obj_textsec (abfd
) != (asection
*) NULL
)
3714 trsize
+= (_bfd_count_link_order_relocs (obj_textsec (abfd
)
3716 * obj_reloc_entry_size (abfd
));
3717 if (obj_datasec (abfd
) != (asection
*) NULL
)
3718 drsize
+= (_bfd_count_link_order_relocs (obj_datasec (abfd
)
3720 * obj_reloc_entry_size (abfd
));
3723 exec_hdr (abfd
)->a_trsize
= trsize
;
3724 exec_hdr (abfd
)->a_drsize
= drsize
;
3726 exec_hdr (abfd
)->a_entry
= bfd_get_start_address (abfd
);
3728 /* Adjust the section sizes and vmas according to the magic number.
3729 This sets a_text, a_data and a_bss in the exec_hdr and sets the
3730 filepos for each section. */
3731 if (! NAME(aout
,adjust_sizes_and_vmas
) (abfd
, &text_size
, &text_end
))
3734 /* The relocation and symbol file positions differ among a.out
3735 targets. We are passed a callback routine from the backend
3736 specific code to handle this.
3737 FIXME: At this point we do not know how much space the symbol
3738 table will require. This will not work for any (nonstandard)
3739 a.out target that needs to know the symbol table size before it
3740 can compute the relocation file positions. This may or may not
3741 be the case for the hp300hpux target, for example. */
3742 (*callback
) (abfd
, &aout_info
.treloff
, &aout_info
.dreloff
,
3744 obj_textsec (abfd
)->rel_filepos
= aout_info
.treloff
;
3745 obj_datasec (abfd
)->rel_filepos
= aout_info
.dreloff
;
3746 obj_sym_filepos (abfd
) = aout_info
.symoff
;
3748 /* We keep a count of the symbols as we output them. */
3749 obj_aout_external_sym_count (abfd
) = 0;
3751 /* We accumulate the string table as we write out the symbols. */
3752 aout_info
.strtab
= _bfd_stringtab_init ();
3753 if (aout_info
.strtab
== NULL
)
3756 /* Allocate buffers to hold section contents and relocs. */
3757 aout_info
.contents
= (bfd_byte
*) bfd_malloc (max_contents_size
);
3758 aout_info
.relocs
= (PTR
) bfd_malloc (max_relocs_size
);
3759 aout_info
.symbol_map
= (int *) bfd_malloc (max_sym_count
* sizeof (int *));
3760 aout_info
.output_syms
= ((struct external_nlist
*)
3761 bfd_malloc ((max_sym_count
+ 1)
3762 * sizeof (struct external_nlist
)));
3763 if ((aout_info
.contents
== NULL
&& max_contents_size
!= 0)
3764 || (aout_info
.relocs
== NULL
&& max_relocs_size
!= 0)
3765 || (aout_info
.symbol_map
== NULL
&& max_sym_count
!= 0)
3766 || aout_info
.output_syms
== NULL
)
3769 /* If we have a symbol named __DYNAMIC, force it out now. This is
3770 required by SunOS. Doing this here rather than in sunos.c is a
3771 hack, but it's easier than exporting everything which would be
3774 struct aout_link_hash_entry
*h
;
3776 h
= aout_link_hash_lookup (aout_hash_table (info
), "__DYNAMIC",
3777 FALSE
, FALSE
, FALSE
);
3779 aout_link_write_other_symbol (h
, &aout_info
);
3782 /* The most time efficient way to do the link would be to read all
3783 the input object files into memory and then sort out the
3784 information into the output file. Unfortunately, that will
3785 probably use too much memory. Another method would be to step
3786 through everything that composes the text section and write it
3787 out, and then everything that composes the data section and write
3788 it out, and then write out the relocs, and then write out the
3789 symbols. Unfortunately, that requires reading stuff from each
3790 input file several times, and we will not be able to keep all the
3791 input files open simultaneously, and reopening them will be slow.
3793 What we do is basically process one input file at a time. We do
3794 everything we need to do with an input file once--copy over the
3795 section contents, handle the relocation information, and write
3796 out the symbols--and then we throw away the information we read
3797 from it. This approach requires a lot of lseeks of the output
3798 file, which is unfortunate but still faster than reopening a lot
3801 We use the output_has_begun field of the input BFDs to see
3802 whether we have already handled it. */
3803 for (sub
= info
->input_bfds
; sub
!= (bfd
*) NULL
; sub
= sub
->link_next
)
3804 sub
->output_has_begun
= FALSE
;
3806 /* Mark all sections which are to be included in the link. This
3807 will normally be every section. We need to do this so that we
3808 can identify any sections which the linker has decided to not
3810 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
3812 for (p
= o
->link_order_head
; p
!= NULL
; p
= p
->next
)
3813 if (p
->type
== bfd_indirect_link_order
)
3814 p
->u
.indirect
.section
->linker_mark
= TRUE
;
3817 have_link_order_relocs
= FALSE
;
3818 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
3820 for (p
= o
->link_order_head
;
3821 p
!= (struct bfd_link_order
*) NULL
;
3824 if (p
->type
== bfd_indirect_link_order
3825 && (bfd_get_flavour (p
->u
.indirect
.section
->owner
)
3826 == bfd_target_aout_flavour
))
3830 input_bfd
= p
->u
.indirect
.section
->owner
;
3831 if (! input_bfd
->output_has_begun
)
3833 if (! aout_link_input_bfd (&aout_info
, input_bfd
))
3835 input_bfd
->output_has_begun
= TRUE
;
3838 else if (p
->type
== bfd_section_reloc_link_order
3839 || p
->type
== bfd_symbol_reloc_link_order
)
3841 /* These are handled below. */
3842 have_link_order_relocs
= TRUE
;
3846 if (! _bfd_default_link_order (abfd
, info
, o
, p
))
3852 /* Write out any symbols that we have not already written out. */
3853 aout_link_hash_traverse (aout_hash_table (info
),
3854 aout_link_write_other_symbol
,
3857 /* Now handle any relocs we were asked to create by the linker.
3858 These did not come from any input file. We must do these after
3859 we have written out all the symbols, so that we know the symbol
3861 if (have_link_order_relocs
)
3863 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
3865 for (p
= o
->link_order_head
;
3866 p
!= (struct bfd_link_order
*) NULL
;
3869 if (p
->type
== bfd_section_reloc_link_order
3870 || p
->type
== bfd_symbol_reloc_link_order
)
3872 if (! aout_link_reloc_link_order (&aout_info
, o
, p
))
3879 if (aout_info
.contents
!= NULL
)
3881 free (aout_info
.contents
);
3882 aout_info
.contents
= NULL
;
3884 if (aout_info
.relocs
!= NULL
)
3886 free (aout_info
.relocs
);
3887 aout_info
.relocs
= NULL
;
3889 if (aout_info
.symbol_map
!= NULL
)
3891 free (aout_info
.symbol_map
);
3892 aout_info
.symbol_map
= NULL
;
3894 if (aout_info
.output_syms
!= NULL
)
3896 free (aout_info
.output_syms
);
3897 aout_info
.output_syms
= NULL
;
3899 if (includes_hash_initialized
)
3901 bfd_hash_table_free (&aout_info
.includes
.root
);
3902 includes_hash_initialized
= FALSE
;
3905 /* Finish up any dynamic linking we may be doing. */
3906 if (aout_backend_info (abfd
)->finish_dynamic_link
!= NULL
)
3908 if (! (*aout_backend_info (abfd
)->finish_dynamic_link
) (abfd
, info
))
3912 /* Update the header information. */
3913 abfd
->symcount
= obj_aout_external_sym_count (abfd
);
3914 exec_hdr (abfd
)->a_syms
= abfd
->symcount
* EXTERNAL_NLIST_SIZE
;
3915 obj_str_filepos (abfd
) = obj_sym_filepos (abfd
) + exec_hdr (abfd
)->a_syms
;
3916 obj_textsec (abfd
)->reloc_count
=
3917 exec_hdr (abfd
)->a_trsize
/ obj_reloc_entry_size (abfd
);
3918 obj_datasec (abfd
)->reloc_count
=
3919 exec_hdr (abfd
)->a_drsize
/ obj_reloc_entry_size (abfd
);
3921 /* Write out the string table, unless there are no symbols. */
3922 if (abfd
->symcount
> 0)
3924 if (bfd_seek (abfd
, obj_str_filepos (abfd
), SEEK_SET
) != 0
3925 || ! emit_stringtab (abfd
, aout_info
.strtab
))
3928 else if (obj_textsec (abfd
)->reloc_count
== 0
3929 && obj_datasec (abfd
)->reloc_count
== 0)
3935 pos
= obj_datasec (abfd
)->filepos
+ exec_hdr (abfd
)->a_data
- 1;
3936 if (bfd_seek (abfd
, pos
, SEEK_SET
) != 0
3937 || bfd_bwrite (&b
, (bfd_size_type
) 1, abfd
) != 1)
3944 if (aout_info
.contents
!= NULL
)
3945 free (aout_info
.contents
);
3946 if (aout_info
.relocs
!= NULL
)
3947 free (aout_info
.relocs
);
3948 if (aout_info
.symbol_map
!= NULL
)
3949 free (aout_info
.symbol_map
);
3950 if (aout_info
.output_syms
!= NULL
)
3951 free (aout_info
.output_syms
);
3952 if (includes_hash_initialized
)
3953 bfd_hash_table_free (&aout_info
.includes
.root
);
3957 /* Link an a.out input BFD into the output file. */
3960 aout_link_input_bfd (finfo
, input_bfd
)
3961 struct aout_final_link_info
*finfo
;
3964 bfd_size_type sym_count
;
3966 BFD_ASSERT (bfd_get_format (input_bfd
) == bfd_object
);
3968 /* If this is a dynamic object, it may need special handling. */
3969 if ((input_bfd
->flags
& DYNAMIC
) != 0
3970 && aout_backend_info (input_bfd
)->link_dynamic_object
!= NULL
)
3972 return ((*aout_backend_info (input_bfd
)->link_dynamic_object
)
3973 (finfo
->info
, input_bfd
));
3976 /* Get the symbols. We probably have them already, unless
3977 finfo->info->keep_memory is FALSE. */
3978 if (! aout_get_external_symbols (input_bfd
))
3981 sym_count
= obj_aout_external_sym_count (input_bfd
);
3983 /* Write out the symbols and get a map of the new indices. The map
3984 is placed into finfo->symbol_map. */
3985 if (! aout_link_write_symbols (finfo
, input_bfd
))
3988 /* Relocate and write out the sections. These functions use the
3989 symbol map created by aout_link_write_symbols. The linker_mark
3990 field will be set if these sections are to be included in the
3991 link, which will normally be the case. */
3992 if (obj_textsec (input_bfd
)->linker_mark
)
3994 if (! aout_link_input_section (finfo
, input_bfd
,
3995 obj_textsec (input_bfd
),
3997 exec_hdr (input_bfd
)->a_trsize
))
4000 if (obj_datasec (input_bfd
)->linker_mark
)
4002 if (! aout_link_input_section (finfo
, input_bfd
,
4003 obj_datasec (input_bfd
),
4005 exec_hdr (input_bfd
)->a_drsize
))
4009 /* If we are not keeping memory, we don't need the symbols any
4010 longer. We still need them if we are keeping memory, because the
4011 strings in the hash table point into them. */
4012 if (! finfo
->info
->keep_memory
)
4014 if (! aout_link_free_symbols (input_bfd
))
4021 /* Adjust and write out the symbols for an a.out file. Set the new
4022 symbol indices into a symbol_map. */
4025 aout_link_write_symbols (finfo
, input_bfd
)
4026 struct aout_final_link_info
*finfo
;
4030 bfd_size_type sym_count
;
4032 enum bfd_link_strip strip
;
4033 enum bfd_link_discard discard
;
4034 struct external_nlist
*outsym
;
4035 bfd_size_type strtab_index
;
4036 register struct external_nlist
*sym
;
4037 struct external_nlist
*sym_end
;
4038 struct aout_link_hash_entry
**sym_hash
;
4041 bfd_boolean skip_next
;
4043 output_bfd
= finfo
->output_bfd
;
4044 sym_count
= obj_aout_external_sym_count (input_bfd
);
4045 strings
= obj_aout_external_strings (input_bfd
);
4046 strip
= finfo
->info
->strip
;
4047 discard
= finfo
->info
->discard
;
4048 outsym
= finfo
->output_syms
;
4050 /* First write out a symbol for this object file, unless we are
4051 discarding such symbols. */
4052 if (strip
!= strip_all
4053 && (strip
!= strip_some
4054 || bfd_hash_lookup (finfo
->info
->keep_hash
, input_bfd
->filename
,
4055 FALSE
, FALSE
) != NULL
)
4056 && discard
!= discard_all
)
4058 H_PUT_8 (output_bfd
, N_TEXT
, outsym
->e_type
);
4059 H_PUT_8 (output_bfd
, 0, outsym
->e_other
);
4060 H_PUT_16 (output_bfd
, 0, outsym
->e_desc
);
4061 strtab_index
= add_to_stringtab (output_bfd
, finfo
->strtab
,
4062 input_bfd
->filename
, FALSE
);
4063 if (strtab_index
== (bfd_size_type
) -1)
4065 PUT_WORD (output_bfd
, strtab_index
, outsym
->e_strx
);
4066 PUT_WORD (output_bfd
,
4067 (bfd_get_section_vma (output_bfd
,
4068 obj_textsec (input_bfd
)->output_section
)
4069 + obj_textsec (input_bfd
)->output_offset
),
4071 ++obj_aout_external_sym_count (output_bfd
);
4077 sym
= obj_aout_external_syms (input_bfd
);
4078 sym_end
= sym
+ sym_count
;
4079 sym_hash
= obj_aout_sym_hashes (input_bfd
);
4080 symbol_map
= finfo
->symbol_map
;
4081 memset (symbol_map
, 0, (size_t) sym_count
* sizeof *symbol_map
);
4082 for (; sym
< sym_end
; sym
++, sym_hash
++, symbol_map
++)
4086 struct aout_link_hash_entry
*h
;
4092 /* We set *symbol_map to 0 above for all symbols. If it has
4093 already been set to -1 for this symbol, it means that we are
4094 discarding it because it appears in a duplicate header file.
4095 See the N_BINCL code below. */
4096 if (*symbol_map
== -1)
4099 /* Initialize *symbol_map to -1, which means that the symbol was
4100 not copied into the output file. We will change it later if
4101 we do copy the symbol over. */
4104 type
= H_GET_8 (input_bfd
, sym
->e_type
);
4105 name
= strings
+ GET_WORD (input_bfd
, sym
->e_strx
);
4111 /* Pass this symbol through. It is the target of an
4112 indirect or warning symbol. */
4113 val
= GET_WORD (input_bfd
, sym
->e_value
);
4118 /* Skip this symbol, which is the target of an indirect
4119 symbol that we have changed to no longer be an indirect
4126 struct aout_link_hash_entry
*hresolve
;
4128 /* We have saved the hash table entry for this symbol, if
4129 there is one. Note that we could just look it up again
4130 in the hash table, provided we first check that it is an
4134 /* Use the name from the hash table, in case the symbol was
4137 && h
->root
.type
!= bfd_link_hash_warning
)
4138 name
= h
->root
.root
.string
;
4140 /* If this is an indirect or warning symbol, then change
4141 hresolve to the base symbol. We also change *sym_hash so
4142 that the relocation routines relocate against the real
4145 if (h
!= (struct aout_link_hash_entry
*) NULL
4146 && (h
->root
.type
== bfd_link_hash_indirect
4147 || h
->root
.type
== bfd_link_hash_warning
))
4149 hresolve
= (struct aout_link_hash_entry
*) h
->root
.u
.i
.link
;
4150 while (hresolve
->root
.type
== bfd_link_hash_indirect
4151 || hresolve
->root
.type
== bfd_link_hash_warning
)
4152 hresolve
= ((struct aout_link_hash_entry
*)
4153 hresolve
->root
.u
.i
.link
);
4154 *sym_hash
= hresolve
;
4157 /* If the symbol has already been written out, skip it. */
4158 if (h
!= (struct aout_link_hash_entry
*) NULL
4161 if ((type
& N_TYPE
) == N_INDR
4162 || type
== N_WARNING
)
4164 *symbol_map
= h
->indx
;
4168 /* See if we are stripping this symbol. */
4174 case strip_debugger
:
4175 if ((type
& N_STAB
) != 0)
4179 if (bfd_hash_lookup (finfo
->info
->keep_hash
, name
, FALSE
, FALSE
)
4189 if (h
!= (struct aout_link_hash_entry
*) NULL
)
4194 /* Get the value of the symbol. */
4195 if ((type
& N_TYPE
) == N_TEXT
4197 symsec
= obj_textsec (input_bfd
);
4198 else if ((type
& N_TYPE
) == N_DATA
4200 symsec
= obj_datasec (input_bfd
);
4201 else if ((type
& N_TYPE
) == N_BSS
4203 symsec
= obj_bsssec (input_bfd
);
4204 else if ((type
& N_TYPE
) == N_ABS
4206 symsec
= bfd_abs_section_ptr
;
4207 else if (((type
& N_TYPE
) == N_INDR
4208 && (hresolve
== (struct aout_link_hash_entry
*) NULL
4209 || (hresolve
->root
.type
!= bfd_link_hash_defined
4210 && hresolve
->root
.type
!= bfd_link_hash_defweak
4211 && hresolve
->root
.type
!= bfd_link_hash_common
)))
4212 || type
== N_WARNING
)
4214 /* Pass the next symbol through unchanged. The
4215 condition above for indirect symbols is so that if
4216 the indirect symbol was defined, we output it with
4217 the correct definition so the debugger will
4220 val
= GET_WORD (input_bfd
, sym
->e_value
);
4223 else if ((type
& N_STAB
) != 0)
4225 val
= GET_WORD (input_bfd
, sym
->e_value
);
4230 /* If we get here with an indirect symbol, it means that
4231 we are outputting it with a real definition. In such
4232 a case we do not want to output the next symbol,
4233 which is the target of the indirection. */
4234 if ((type
& N_TYPE
) == N_INDR
)
4239 /* We need to get the value from the hash table. We use
4240 hresolve so that if we have defined an indirect
4241 symbol we output the final definition. */
4242 if (h
== (struct aout_link_hash_entry
*) NULL
)
4244 switch (type
& N_TYPE
)
4247 symsec
= obj_textsec (input_bfd
);
4250 symsec
= obj_datasec (input_bfd
);
4253 symsec
= obj_bsssec (input_bfd
);
4256 symsec
= bfd_abs_section_ptr
;
4263 else if (hresolve
->root
.type
== bfd_link_hash_defined
4264 || hresolve
->root
.type
== bfd_link_hash_defweak
)
4266 asection
*input_section
;
4267 asection
*output_section
;
4269 /* This case usually means a common symbol which was
4270 turned into a defined symbol. */
4271 input_section
= hresolve
->root
.u
.def
.section
;
4272 output_section
= input_section
->output_section
;
4273 BFD_ASSERT (bfd_is_abs_section (output_section
)
4274 || output_section
->owner
== output_bfd
);
4275 val
= (hresolve
->root
.u
.def
.value
4276 + bfd_get_section_vma (output_bfd
, output_section
)
4277 + input_section
->output_offset
);
4279 /* Get the correct type based on the section. If
4280 this is a constructed set, force it to be
4281 globally visible. */
4290 if (output_section
== obj_textsec (output_bfd
))
4291 type
|= (hresolve
->root
.type
== bfd_link_hash_defined
4294 else if (output_section
== obj_datasec (output_bfd
))
4295 type
|= (hresolve
->root
.type
== bfd_link_hash_defined
4298 else if (output_section
== obj_bsssec (output_bfd
))
4299 type
|= (hresolve
->root
.type
== bfd_link_hash_defined
4303 type
|= (hresolve
->root
.type
== bfd_link_hash_defined
4307 else if (hresolve
->root
.type
== bfd_link_hash_common
)
4308 val
= hresolve
->root
.u
.c
.size
;
4309 else if (hresolve
->root
.type
== bfd_link_hash_undefweak
)
4317 if (symsec
!= (asection
*) NULL
)
4318 val
= (symsec
->output_section
->vma
4319 + symsec
->output_offset
4320 + (GET_WORD (input_bfd
, sym
->e_value
)
4323 /* If this is a global symbol set the written flag, and if
4324 it is a local symbol see if we should discard it. */
4325 if (h
!= (struct aout_link_hash_entry
*) NULL
)
4328 h
->indx
= obj_aout_external_sym_count (output_bfd
);
4330 else if ((type
& N_TYPE
) != N_SETT
4331 && (type
& N_TYPE
) != N_SETD
4332 && (type
& N_TYPE
) != N_SETB
4333 && (type
& N_TYPE
) != N_SETA
)
4338 case discard_sec_merge
:
4341 if ((type
& N_STAB
) == 0
4342 && bfd_is_local_label_name (input_bfd
, name
))
4356 /* An N_BINCL symbol indicates the start of the stabs
4357 entries for a header file. We need to scan ahead to the
4358 next N_EINCL symbol, ignoring nesting, adding up all the
4359 characters in the symbol names, not including the file
4360 numbers in types (the first number after an open
4362 if (type
== (int) N_BINCL
)
4364 struct external_nlist
*incl_sym
;
4366 struct aout_link_includes_entry
*incl_entry
;
4367 struct aout_link_includes_totals
*t
;
4371 for (incl_sym
= sym
+ 1; incl_sym
< sym_end
; incl_sym
++)
4375 incl_type
= H_GET_8 (input_bfd
, incl_sym
->e_type
);
4376 if (incl_type
== (int) N_EINCL
)
4382 else if (incl_type
== (int) N_BINCL
)
4388 s
= strings
+ GET_WORD (input_bfd
, incl_sym
->e_strx
);
4389 for (; *s
!= '\0'; s
++)
4394 /* Skip the file number. */
4396 while (ISDIGIT (*s
))
4404 /* If we have already included a header file with the
4405 same value, then replace this one with an N_EXCL
4407 copy
= (bfd_boolean
) (! finfo
->info
->keep_memory
);
4408 incl_entry
= aout_link_includes_lookup (&finfo
->includes
,
4410 if (incl_entry
== NULL
)
4412 for (t
= incl_entry
->totals
; t
!= NULL
; t
= t
->next
)
4413 if (t
->total
== val
)
4417 /* This is the first time we have seen this header
4418 file with this set of stabs strings. */
4419 t
= ((struct aout_link_includes_totals
*)
4420 bfd_hash_allocate (&finfo
->includes
.root
,
4425 t
->next
= incl_entry
->totals
;
4426 incl_entry
->totals
= t
;
4432 /* This is a duplicate header file. We must change
4433 it to be an N_EXCL entry, and mark all the
4434 included symbols to prevent outputting them. */
4435 type
= (int) N_EXCL
;
4438 for (incl_sym
= sym
+ 1, incl_map
= symbol_map
+ 1;
4440 incl_sym
++, incl_map
++)
4444 incl_type
= H_GET_8 (input_bfd
, incl_sym
->e_type
);
4445 if (incl_type
== (int) N_EINCL
)
4454 else if (incl_type
== (int) N_BINCL
)
4463 /* Copy this symbol into the list of symbols we are going to
4465 H_PUT_8 (output_bfd
, type
, outsym
->e_type
);
4466 H_PUT_8 (output_bfd
, H_GET_8 (input_bfd
, sym
->e_other
), outsym
->e_other
);
4467 H_PUT_16 (output_bfd
, H_GET_16 (input_bfd
, sym
->e_desc
), outsym
->e_desc
);
4469 if (! finfo
->info
->keep_memory
)
4471 /* name points into a string table which we are going to
4472 free. If there is a hash table entry, use that string.
4473 Otherwise, copy name into memory. */
4474 if (h
!= (struct aout_link_hash_entry
*) NULL
)
4475 name
= h
->root
.root
.string
;
4479 strtab_index
= add_to_stringtab (output_bfd
, finfo
->strtab
,
4481 if (strtab_index
== (bfd_size_type
) -1)
4483 PUT_WORD (output_bfd
, strtab_index
, outsym
->e_strx
);
4484 PUT_WORD (output_bfd
, val
, outsym
->e_value
);
4485 *symbol_map
= obj_aout_external_sym_count (output_bfd
);
4486 ++obj_aout_external_sym_count (output_bfd
);
4490 /* Write out the output symbols we have just constructed. */
4491 if (outsym
> finfo
->output_syms
)
4493 bfd_size_type outsym_size
;
4495 if (bfd_seek (output_bfd
, finfo
->symoff
, SEEK_SET
) != 0)
4497 outsym_size
= outsym
- finfo
->output_syms
;
4498 outsym_size
*= EXTERNAL_NLIST_SIZE
;
4499 if (bfd_bwrite ((PTR
) finfo
->output_syms
, outsym_size
, output_bfd
)
4502 finfo
->symoff
+= outsym_size
;
4508 /* Write out a symbol that was not associated with an a.out input
4512 aout_link_write_other_symbol (h
, data
)
4513 struct aout_link_hash_entry
*h
;
4516 struct aout_final_link_info
*finfo
= (struct aout_final_link_info
*) data
;
4520 struct external_nlist outsym
;
4524 if (h
->root
.type
== bfd_link_hash_warning
)
4526 h
= (struct aout_link_hash_entry
*) h
->root
.u
.i
.link
;
4527 if (h
->root
.type
== bfd_link_hash_new
)
4531 output_bfd
= finfo
->output_bfd
;
4533 if (aout_backend_info (output_bfd
)->write_dynamic_symbol
!= NULL
)
4535 if (! ((*aout_backend_info (output_bfd
)->write_dynamic_symbol
)
4536 (output_bfd
, finfo
->info
, h
)))
4538 /* FIXME: No way to handle errors. */
4548 /* An indx of -2 means the symbol must be written. */
4550 && (finfo
->info
->strip
== strip_all
4551 || (finfo
->info
->strip
== strip_some
4552 && bfd_hash_lookup (finfo
->info
->keep_hash
, h
->root
.root
.string
,
4553 FALSE
, FALSE
) == NULL
)))
4556 switch (h
->root
.type
)
4559 case bfd_link_hash_warning
:
4561 /* Avoid variable not initialized warnings. */
4563 case bfd_link_hash_new
:
4564 /* This can happen for set symbols when sets are not being
4567 case bfd_link_hash_undefined
:
4568 type
= N_UNDF
| N_EXT
;
4571 case bfd_link_hash_defined
:
4572 case bfd_link_hash_defweak
:
4576 sec
= h
->root
.u
.def
.section
->output_section
;
4577 BFD_ASSERT (bfd_is_abs_section (sec
)
4578 || sec
->owner
== output_bfd
);
4579 if (sec
== obj_textsec (output_bfd
))
4580 type
= h
->root
.type
== bfd_link_hash_defined
? N_TEXT
: N_WEAKT
;
4581 else if (sec
== obj_datasec (output_bfd
))
4582 type
= h
->root
.type
== bfd_link_hash_defined
? N_DATA
: N_WEAKD
;
4583 else if (sec
== obj_bsssec (output_bfd
))
4584 type
= h
->root
.type
== bfd_link_hash_defined
? N_BSS
: N_WEAKB
;
4586 type
= h
->root
.type
== bfd_link_hash_defined
? N_ABS
: N_WEAKA
;
4588 val
= (h
->root
.u
.def
.value
4590 + h
->root
.u
.def
.section
->output_offset
);
4593 case bfd_link_hash_common
:
4594 type
= N_UNDF
| N_EXT
;
4595 val
= h
->root
.u
.c
.size
;
4597 case bfd_link_hash_undefweak
:
4600 case bfd_link_hash_indirect
:
4601 /* We ignore these symbols, since the indirected symbol is
4602 already in the hash table. */
4606 H_PUT_8 (output_bfd
, type
, outsym
.e_type
);
4607 H_PUT_8 (output_bfd
, 0, outsym
.e_other
);
4608 H_PUT_16 (output_bfd
, 0, outsym
.e_desc
);
4609 indx
= add_to_stringtab (output_bfd
, finfo
->strtab
, h
->root
.root
.string
,
4611 if (indx
== - (bfd_size_type
) 1)
4613 /* FIXME: No way to handle errors. */
4616 PUT_WORD (output_bfd
, indx
, outsym
.e_strx
);
4617 PUT_WORD (output_bfd
, val
, outsym
.e_value
);
4619 amt
= EXTERNAL_NLIST_SIZE
;
4620 if (bfd_seek (output_bfd
, finfo
->symoff
, SEEK_SET
) != 0
4621 || bfd_bwrite ((PTR
) &outsym
, amt
, output_bfd
) != amt
)
4623 /* FIXME: No way to handle errors. */
4627 finfo
->symoff
+= EXTERNAL_NLIST_SIZE
;
4628 h
->indx
= obj_aout_external_sym_count (output_bfd
);
4629 ++obj_aout_external_sym_count (output_bfd
);
4634 /* Link an a.out section into the output file. */
4637 aout_link_input_section (finfo
, input_bfd
, input_section
, reloff_ptr
,
4639 struct aout_final_link_info
*finfo
;
4641 asection
*input_section
;
4642 file_ptr
*reloff_ptr
;
4643 bfd_size_type rel_size
;
4645 bfd_size_type input_size
;
4648 /* Get the section contents. */
4649 input_size
= input_section
->size
;
4650 if (! bfd_get_section_contents (input_bfd
, input_section
,
4651 (PTR
) finfo
->contents
,
4652 (file_ptr
) 0, input_size
))
4655 /* Read in the relocs if we haven't already done it. */
4656 if (aout_section_data (input_section
) != NULL
4657 && aout_section_data (input_section
)->relocs
!= NULL
)
4658 relocs
= aout_section_data (input_section
)->relocs
;
4661 relocs
= finfo
->relocs
;
4664 if (bfd_seek (input_bfd
, input_section
->rel_filepos
, SEEK_SET
) != 0
4665 || bfd_bread (relocs
, rel_size
, input_bfd
) != rel_size
)
4670 /* Relocate the section contents. */
4671 if (obj_reloc_entry_size (input_bfd
) == RELOC_STD_SIZE
)
4673 if (! aout_link_input_section_std (finfo
, input_bfd
, input_section
,
4674 (struct reloc_std_external
*) relocs
,
4675 rel_size
, finfo
->contents
))
4680 if (! aout_link_input_section_ext (finfo
, input_bfd
, input_section
,
4681 (struct reloc_ext_external
*) relocs
,
4682 rel_size
, finfo
->contents
))
4686 /* Write out the section contents. */
4687 if (! bfd_set_section_contents (finfo
->output_bfd
,
4688 input_section
->output_section
,
4689 (PTR
) finfo
->contents
,
4690 (file_ptr
) input_section
->output_offset
,
4694 /* If we are producing relocatable output, the relocs were
4695 modified, and we now write them out. */
4696 if (finfo
->info
->relocatable
&& rel_size
> 0)
4698 if (bfd_seek (finfo
->output_bfd
, *reloff_ptr
, SEEK_SET
) != 0)
4700 if (bfd_bwrite (relocs
, rel_size
, finfo
->output_bfd
) != rel_size
)
4702 *reloff_ptr
+= rel_size
;
4704 /* Assert that the relocs have not run into the symbols, and
4705 that if these are the text relocs they have not run into the
4707 BFD_ASSERT (*reloff_ptr
<= obj_sym_filepos (finfo
->output_bfd
)
4708 && (reloff_ptr
!= &finfo
->treloff
4710 <= obj_datasec (finfo
->output_bfd
)->rel_filepos
)));
4716 /* Get the section corresponding to a reloc index. */
4718 static INLINE asection
*
4719 aout_reloc_index_to_section (abfd
, indx
)
4723 switch (indx
& N_TYPE
)
4726 return obj_textsec (abfd
);
4728 return obj_datasec (abfd
);
4730 return obj_bsssec (abfd
);
4733 return bfd_abs_section_ptr
;
4741 /* Relocate an a.out section using standard a.out relocs. */
4744 aout_link_input_section_std (finfo
, input_bfd
, input_section
, relocs
,
4746 struct aout_final_link_info
*finfo
;
4748 asection
*input_section
;
4749 struct reloc_std_external
*relocs
;
4750 bfd_size_type rel_size
;
4753 bfd_boolean (*check_dynamic_reloc
)
4754 PARAMS ((struct bfd_link_info
*, bfd
*, asection
*,
4755 struct aout_link_hash_entry
*, PTR
, bfd_byte
*, bfd_boolean
*,
4758 bfd_boolean relocatable
;
4759 struct external_nlist
*syms
;
4761 struct aout_link_hash_entry
**sym_hashes
;
4763 bfd_size_type reloc_count
;
4764 register struct reloc_std_external
*rel
;
4765 struct reloc_std_external
*rel_end
;
4767 output_bfd
= finfo
->output_bfd
;
4768 check_dynamic_reloc
= aout_backend_info (output_bfd
)->check_dynamic_reloc
;
4770 BFD_ASSERT (obj_reloc_entry_size (input_bfd
) == RELOC_STD_SIZE
);
4771 BFD_ASSERT (input_bfd
->xvec
->header_byteorder
4772 == output_bfd
->xvec
->header_byteorder
);
4774 relocatable
= finfo
->info
->relocatable
;
4775 syms
= obj_aout_external_syms (input_bfd
);
4776 strings
= obj_aout_external_strings (input_bfd
);
4777 sym_hashes
= obj_aout_sym_hashes (input_bfd
);
4778 symbol_map
= finfo
->symbol_map
;
4780 reloc_count
= rel_size
/ RELOC_STD_SIZE
;
4782 rel_end
= rel
+ reloc_count
;
4783 for (; rel
< rel_end
; rel
++)
4790 reloc_howto_type
*howto
;
4791 struct aout_link_hash_entry
*h
= NULL
;
4793 bfd_reloc_status_type r
;
4795 r_addr
= GET_SWORD (input_bfd
, rel
->r_address
);
4797 #ifdef MY_reloc_howto
4798 howto
= MY_reloc_howto (input_bfd
, rel
, r_index
, r_extern
, r_pcrel
);
4804 unsigned int howto_idx
;
4806 if (bfd_header_big_endian (input_bfd
))
4808 r_index
= (((unsigned int) rel
->r_index
[0] << 16)
4809 | ((unsigned int) rel
->r_index
[1] << 8)
4811 r_extern
= (0 != (rel
->r_type
[0] & RELOC_STD_BITS_EXTERN_BIG
));
4812 r_pcrel
= (0 != (rel
->r_type
[0] & RELOC_STD_BITS_PCREL_BIG
));
4813 r_baserel
= (0 != (rel
->r_type
[0] & RELOC_STD_BITS_BASEREL_BIG
));
4814 r_jmptable
= (0 != (rel
->r_type
[0] & RELOC_STD_BITS_JMPTABLE_BIG
));
4815 r_relative
= (0 != (rel
->r_type
[0] & RELOC_STD_BITS_RELATIVE_BIG
));
4816 r_length
= ((rel
->r_type
[0] & RELOC_STD_BITS_LENGTH_BIG
)
4817 >> RELOC_STD_BITS_LENGTH_SH_BIG
);
4821 r_index
= (((unsigned int) rel
->r_index
[2] << 16)
4822 | ((unsigned int) rel
->r_index
[1] << 8)
4824 r_extern
= (0 != (rel
->r_type
[0] & RELOC_STD_BITS_EXTERN_LITTLE
));
4825 r_pcrel
= (0 != (rel
->r_type
[0] & RELOC_STD_BITS_PCREL_LITTLE
));
4826 r_baserel
= (0 != (rel
->r_type
[0]
4827 & RELOC_STD_BITS_BASEREL_LITTLE
));
4828 r_jmptable
= (0 != (rel
->r_type
[0]
4829 & RELOC_STD_BITS_JMPTABLE_LITTLE
));
4830 r_relative
= (0 != (rel
->r_type
[0]
4831 & RELOC_STD_BITS_RELATIVE_LITTLE
));
4832 r_length
= ((rel
->r_type
[0] & RELOC_STD_BITS_LENGTH_LITTLE
)
4833 >> RELOC_STD_BITS_LENGTH_SH_LITTLE
);
4836 howto_idx
= (r_length
+ 4 * r_pcrel
+ 8 * r_baserel
4837 + 16 * r_jmptable
+ 32 * r_relative
);
4838 BFD_ASSERT (howto_idx
< TABLE_SIZE (howto_table_std
));
4839 howto
= howto_table_std
+ howto_idx
;
4845 /* We are generating a relocatable output file, and must
4846 modify the reloc accordingly. */
4849 /* If we know the symbol this relocation is against,
4850 convert it into a relocation against a section. This
4851 is what the native linker does. */
4852 h
= sym_hashes
[r_index
];
4853 if (h
!= (struct aout_link_hash_entry
*) NULL
4854 && (h
->root
.type
== bfd_link_hash_defined
4855 || h
->root
.type
== bfd_link_hash_defweak
))
4857 asection
*output_section
;
4859 /* Change the r_extern value. */
4860 if (bfd_header_big_endian (output_bfd
))
4861 rel
->r_type
[0] &=~ RELOC_STD_BITS_EXTERN_BIG
;
4863 rel
->r_type
[0] &=~ RELOC_STD_BITS_EXTERN_LITTLE
;
4865 /* Compute a new r_index. */
4866 output_section
= h
->root
.u
.def
.section
->output_section
;
4867 if (output_section
== obj_textsec (output_bfd
))
4869 else if (output_section
== obj_datasec (output_bfd
))
4871 else if (output_section
== obj_bsssec (output_bfd
))
4876 /* Add the symbol value and the section VMA to the
4877 addend stored in the contents. */
4878 relocation
= (h
->root
.u
.def
.value
4879 + output_section
->vma
4880 + h
->root
.u
.def
.section
->output_offset
);
4884 /* We must change r_index according to the symbol
4886 r_index
= symbol_map
[r_index
];
4892 /* We decided to strip this symbol, but it
4893 turns out that we can't. Note that we
4894 lose the other and desc information here.
4895 I don't think that will ever matter for a
4901 if (! aout_link_write_other_symbol (h
,
4911 name
= strings
+ GET_WORD (input_bfd
,
4912 syms
[r_index
].e_strx
);
4913 if (! ((*finfo
->info
->callbacks
->unattached_reloc
)
4914 (finfo
->info
, name
, input_bfd
, input_section
,
4924 /* Write out the new r_index value. */
4925 if (bfd_header_big_endian (output_bfd
))
4927 rel
->r_index
[0] = r_index
>> 16;
4928 rel
->r_index
[1] = r_index
>> 8;
4929 rel
->r_index
[2] = r_index
;
4933 rel
->r_index
[2] = r_index
>> 16;
4934 rel
->r_index
[1] = r_index
>> 8;
4935 rel
->r_index
[0] = r_index
;
4942 /* This is a relocation against a section. We must
4943 adjust by the amount that the section moved. */
4944 section
= aout_reloc_index_to_section (input_bfd
, r_index
);
4945 relocation
= (section
->output_section
->vma
4946 + section
->output_offset
4950 /* Change the address of the relocation. */
4951 PUT_WORD (output_bfd
,
4952 r_addr
+ input_section
->output_offset
,
4955 /* Adjust a PC relative relocation by removing the reference
4956 to the original address in the section and including the
4957 reference to the new address. */
4959 relocation
-= (input_section
->output_section
->vma
4960 + input_section
->output_offset
4961 - input_section
->vma
);
4963 #ifdef MY_relocatable_reloc
4964 MY_relocatable_reloc (howto
, output_bfd
, rel
, relocation
, r_addr
);
4967 if (relocation
== 0)
4970 r
= MY_relocate_contents (howto
,
4971 input_bfd
, relocation
,
4978 /* We are generating an executable, and must do a full
4984 h
= sym_hashes
[r_index
];
4986 if (h
!= (struct aout_link_hash_entry
*) NULL
4987 && (h
->root
.type
== bfd_link_hash_defined
4988 || h
->root
.type
== bfd_link_hash_defweak
))
4990 relocation
= (h
->root
.u
.def
.value
4991 + h
->root
.u
.def
.section
->output_section
->vma
4992 + h
->root
.u
.def
.section
->output_offset
);
4994 else if (h
!= (struct aout_link_hash_entry
*) NULL
4995 && h
->root
.type
== bfd_link_hash_undefweak
)
5007 section
= aout_reloc_index_to_section (input_bfd
, r_index
);
5008 relocation
= (section
->output_section
->vma
5009 + section
->output_offset
5012 relocation
+= input_section
->vma
;
5015 if (check_dynamic_reloc
!= NULL
)
5019 if (! ((*check_dynamic_reloc
)
5020 (finfo
->info
, input_bfd
, input_section
, h
,
5021 (PTR
) rel
, contents
, &skip
, &relocation
)))
5027 /* Now warn if a global symbol is undefined. We could not
5028 do this earlier, because check_dynamic_reloc might want
5029 to skip this reloc. */
5030 if (hundef
&& ! finfo
->info
->shared
&& ! r_baserel
)
5035 name
= h
->root
.root
.string
;
5037 name
= strings
+ GET_WORD (input_bfd
, syms
[r_index
].e_strx
);
5038 if (! ((*finfo
->info
->callbacks
->undefined_symbol
)
5039 (finfo
->info
, name
, input_bfd
, input_section
,
5044 r
= MY_final_link_relocate (howto
,
5045 input_bfd
, input_section
,
5046 contents
, r_addr
, relocation
,
5050 if (r
!= bfd_reloc_ok
)
5055 case bfd_reloc_outofrange
:
5057 case bfd_reloc_overflow
:
5064 name
= strings
+ GET_WORD (input_bfd
,
5065 syms
[r_index
].e_strx
);
5070 s
= aout_reloc_index_to_section (input_bfd
, r_index
);
5071 name
= bfd_section_name (input_bfd
, s
);
5073 if (! ((*finfo
->info
->callbacks
->reloc_overflow
)
5074 (finfo
->info
, (h
? &h
->root
: NULL
), name
,
5075 howto
->name
, (bfd_vma
) 0, input_bfd
,
5076 input_section
, r_addr
)))
5087 /* Relocate an a.out section using extended a.out relocs. */
5090 aout_link_input_section_ext (finfo
, input_bfd
, input_section
, relocs
,
5092 struct aout_final_link_info
*finfo
;
5094 asection
*input_section
;
5095 struct reloc_ext_external
*relocs
;
5096 bfd_size_type rel_size
;
5099 bfd_boolean (*check_dynamic_reloc
)
5100 PARAMS ((struct bfd_link_info
*, bfd
*, asection
*,
5101 struct aout_link_hash_entry
*, PTR
, bfd_byte
*, bfd_boolean
*,
5104 bfd_boolean relocatable
;
5105 struct external_nlist
*syms
;
5107 struct aout_link_hash_entry
**sym_hashes
;
5109 bfd_size_type reloc_count
;
5110 register struct reloc_ext_external
*rel
;
5111 struct reloc_ext_external
*rel_end
;
5113 output_bfd
= finfo
->output_bfd
;
5114 check_dynamic_reloc
= aout_backend_info (output_bfd
)->check_dynamic_reloc
;
5116 BFD_ASSERT (obj_reloc_entry_size (input_bfd
) == RELOC_EXT_SIZE
);
5117 BFD_ASSERT (input_bfd
->xvec
->header_byteorder
5118 == output_bfd
->xvec
->header_byteorder
);
5120 relocatable
= finfo
->info
->relocatable
;
5121 syms
= obj_aout_external_syms (input_bfd
);
5122 strings
= obj_aout_external_strings (input_bfd
);
5123 sym_hashes
= obj_aout_sym_hashes (input_bfd
);
5124 symbol_map
= finfo
->symbol_map
;
5126 reloc_count
= rel_size
/ RELOC_EXT_SIZE
;
5128 rel_end
= rel
+ reloc_count
;
5129 for (; rel
< rel_end
; rel
++)
5134 unsigned int r_type
;
5136 struct aout_link_hash_entry
*h
= NULL
;
5137 asection
*r_section
= NULL
;
5140 r_addr
= GET_SWORD (input_bfd
, rel
->r_address
);
5142 if (bfd_header_big_endian (input_bfd
))
5144 r_index
= (((unsigned int) rel
->r_index
[0] << 16)
5145 | ((unsigned int) rel
->r_index
[1] << 8)
5147 r_extern
= (0 != (rel
->r_type
[0] & RELOC_EXT_BITS_EXTERN_BIG
));
5148 r_type
= ((rel
->r_type
[0] & RELOC_EXT_BITS_TYPE_BIG
)
5149 >> RELOC_EXT_BITS_TYPE_SH_BIG
);
5153 r_index
= (((unsigned int) rel
->r_index
[2] << 16)
5154 | ((unsigned int) rel
->r_index
[1] << 8)
5156 r_extern
= (0 != (rel
->r_type
[0] & RELOC_EXT_BITS_EXTERN_LITTLE
));
5157 r_type
= ((rel
->r_type
[0] & RELOC_EXT_BITS_TYPE_LITTLE
)
5158 >> RELOC_EXT_BITS_TYPE_SH_LITTLE
);
5161 r_addend
= GET_SWORD (input_bfd
, rel
->r_addend
);
5163 BFD_ASSERT (r_type
< TABLE_SIZE (howto_table_ext
));
5167 /* We are generating a relocatable output file, and must
5168 modify the reloc accordingly. */
5170 || r_type
== (unsigned int) RELOC_BASE10
5171 || r_type
== (unsigned int) RELOC_BASE13
5172 || r_type
== (unsigned int) RELOC_BASE22
)
5174 /* If we know the symbol this relocation is against,
5175 convert it into a relocation against a section. This
5176 is what the native linker does. */
5177 if (r_type
== (unsigned int) RELOC_BASE10
5178 || r_type
== (unsigned int) RELOC_BASE13
5179 || r_type
== (unsigned int) RELOC_BASE22
)
5182 h
= sym_hashes
[r_index
];
5183 if (h
!= (struct aout_link_hash_entry
*) NULL
5184 && (h
->root
.type
== bfd_link_hash_defined
5185 || h
->root
.type
== bfd_link_hash_defweak
))
5187 asection
*output_section
;
5189 /* Change the r_extern value. */
5190 if (bfd_header_big_endian (output_bfd
))
5191 rel
->r_type
[0] &=~ RELOC_EXT_BITS_EXTERN_BIG
;
5193 rel
->r_type
[0] &=~ RELOC_EXT_BITS_EXTERN_LITTLE
;
5195 /* Compute a new r_index. */
5196 output_section
= h
->root
.u
.def
.section
->output_section
;
5197 if (output_section
== obj_textsec (output_bfd
))
5199 else if (output_section
== obj_datasec (output_bfd
))
5201 else if (output_section
== obj_bsssec (output_bfd
))
5206 /* Add the symbol value and the section VMA to the
5208 relocation
= (h
->root
.u
.def
.value
5209 + output_section
->vma
5210 + h
->root
.u
.def
.section
->output_offset
);
5212 /* Now RELOCATION is the VMA of the final
5213 destination. If this is a PC relative reloc,
5214 then ADDEND is the negative of the source VMA.
5215 We want to set ADDEND to the difference between
5216 the destination VMA and the source VMA, which
5217 means we must adjust RELOCATION by the change in
5218 the source VMA. This is done below. */
5222 /* We must change r_index according to the symbol
5224 r_index
= symbol_map
[r_index
];
5230 /* We decided to strip this symbol, but it
5231 turns out that we can't. Note that we
5232 lose the other and desc information here.
5233 I don't think that will ever matter for a
5239 if (! aout_link_write_other_symbol (h
,
5249 name
= strings
+ GET_WORD (input_bfd
,
5250 syms
[r_index
].e_strx
);
5251 if (! ((*finfo
->info
->callbacks
->unattached_reloc
)
5252 (finfo
->info
, name
, input_bfd
, input_section
,
5261 /* If this is a PC relative reloc, then the addend
5262 is the negative of the source VMA. We must
5263 adjust it by the change in the source VMA. This
5267 /* Write out the new r_index value. */
5268 if (bfd_header_big_endian (output_bfd
))
5270 rel
->r_index
[0] = r_index
>> 16;
5271 rel
->r_index
[1] = r_index
>> 8;
5272 rel
->r_index
[2] = r_index
;
5276 rel
->r_index
[2] = r_index
>> 16;
5277 rel
->r_index
[1] = r_index
>> 8;
5278 rel
->r_index
[0] = r_index
;
5283 /* This is a relocation against a section. We must
5284 adjust by the amount that the section moved. */
5285 r_section
= aout_reloc_index_to_section (input_bfd
, r_index
);
5286 relocation
= (r_section
->output_section
->vma
5287 + r_section
->output_offset
5290 /* If this is a PC relative reloc, then the addend is
5291 the difference in VMA between the destination and the
5292 source. We have just adjusted for the change in VMA
5293 of the destination, so we must also adjust by the
5294 change in VMA of the source. This is done below. */
5297 /* As described above, we must always adjust a PC relative
5298 reloc by the change in VMA of the source. However, if
5299 pcrel_offset is set, then the addend does not include the
5300 location within the section, in which case we don't need
5301 to adjust anything. */
5302 if (howto_table_ext
[r_type
].pc_relative
5303 && ! howto_table_ext
[r_type
].pcrel_offset
)
5304 relocation
-= (input_section
->output_section
->vma
5305 + input_section
->output_offset
5306 - input_section
->vma
);
5308 /* Change the addend if necessary. */
5309 if (relocation
!= 0)
5310 PUT_WORD (output_bfd
, r_addend
+ relocation
, rel
->r_addend
);
5312 /* Change the address of the relocation. */
5313 PUT_WORD (output_bfd
,
5314 r_addr
+ input_section
->output_offset
,
5320 bfd_reloc_status_type r
;
5322 /* We are generating an executable, and must do a full
5328 h
= sym_hashes
[r_index
];
5330 if (h
!= (struct aout_link_hash_entry
*) NULL
5331 && (h
->root
.type
== bfd_link_hash_defined
5332 || h
->root
.type
== bfd_link_hash_defweak
))
5334 relocation
= (h
->root
.u
.def
.value
5335 + h
->root
.u
.def
.section
->output_section
->vma
5336 + h
->root
.u
.def
.section
->output_offset
);
5338 else if (h
!= (struct aout_link_hash_entry
*) NULL
5339 && h
->root
.type
== bfd_link_hash_undefweak
)
5347 else if (r_type
== (unsigned int) RELOC_BASE10
5348 || r_type
== (unsigned int) RELOC_BASE13
5349 || r_type
== (unsigned int) RELOC_BASE22
)
5351 struct external_nlist
*sym
;
5354 /* For base relative relocs, r_index is always an index
5355 into the symbol table, even if r_extern is 0. */
5356 sym
= syms
+ r_index
;
5357 type
= H_GET_8 (input_bfd
, sym
->e_type
);
5358 if ((type
& N_TYPE
) == N_TEXT
5360 r_section
= obj_textsec (input_bfd
);
5361 else if ((type
& N_TYPE
) == N_DATA
5363 r_section
= obj_datasec (input_bfd
);
5364 else if ((type
& N_TYPE
) == N_BSS
5366 r_section
= obj_bsssec (input_bfd
);
5367 else if ((type
& N_TYPE
) == N_ABS
5369 r_section
= bfd_abs_section_ptr
;
5372 relocation
= (r_section
->output_section
->vma
5373 + r_section
->output_offset
5374 + (GET_WORD (input_bfd
, sym
->e_value
)
5379 r_section
= aout_reloc_index_to_section (input_bfd
, r_index
);
5381 /* If this is a PC relative reloc, then R_ADDEND is the
5382 difference between the two vmas, or
5383 old_dest_sec + old_dest_off - (old_src_sec + old_src_off)
5385 old_dest_sec == section->vma
5387 old_src_sec == input_section->vma
5389 old_src_off == r_addr
5391 _bfd_final_link_relocate expects RELOCATION +
5392 R_ADDEND to be the VMA of the destination minus
5393 r_addr (the minus r_addr is because this relocation
5394 is not pcrel_offset, which is a bit confusing and
5395 should, perhaps, be changed), or
5398 new_dest_sec == output_section->vma + output_offset
5399 We arrange for this to happen by setting RELOCATION to
5400 new_dest_sec + old_src_sec - old_dest_sec
5402 If this is not a PC relative reloc, then R_ADDEND is
5403 simply the VMA of the destination, so we set
5404 RELOCATION to the change in the destination VMA, or
5405 new_dest_sec - old_dest_sec
5407 relocation
= (r_section
->output_section
->vma
5408 + r_section
->output_offset
5410 if (howto_table_ext
[r_type
].pc_relative
)
5411 relocation
+= input_section
->vma
;
5414 if (check_dynamic_reloc
!= NULL
)
5418 if (! ((*check_dynamic_reloc
)
5419 (finfo
->info
, input_bfd
, input_section
, h
,
5420 (PTR
) rel
, contents
, &skip
, &relocation
)))
5426 /* Now warn if a global symbol is undefined. We could not
5427 do this earlier, because check_dynamic_reloc might want
5428 to skip this reloc. */
5430 && ! finfo
->info
->shared
5431 && r_type
!= (unsigned int) RELOC_BASE10
5432 && r_type
!= (unsigned int) RELOC_BASE13
5433 && r_type
!= (unsigned int) RELOC_BASE22
)
5438 name
= h
->root
.root
.string
;
5440 name
= strings
+ GET_WORD (input_bfd
, syms
[r_index
].e_strx
);
5441 if (! ((*finfo
->info
->callbacks
->undefined_symbol
)
5442 (finfo
->info
, name
, input_bfd
, input_section
,
5447 if (r_type
!= (unsigned int) RELOC_SPARC_REV32
)
5448 r
= MY_final_link_relocate (howto_table_ext
+ r_type
,
5449 input_bfd
, input_section
,
5450 contents
, r_addr
, relocation
,
5456 x
= bfd_get_32 (input_bfd
, contents
+ r_addr
);
5457 x
= x
+ relocation
+ r_addend
;
5458 bfd_putl32 (/*input_bfd,*/ x
, contents
+ r_addr
);
5462 if (r
!= bfd_reloc_ok
)
5467 case bfd_reloc_outofrange
:
5469 case bfd_reloc_overflow
:
5476 || r_type
== (unsigned int) RELOC_BASE10
5477 || r_type
== (unsigned int) RELOC_BASE13
5478 || r_type
== (unsigned int) RELOC_BASE22
)
5479 name
= strings
+ GET_WORD (input_bfd
,
5480 syms
[r_index
].e_strx
);
5485 s
= aout_reloc_index_to_section (input_bfd
, r_index
);
5486 name
= bfd_section_name (input_bfd
, s
);
5488 if (! ((*finfo
->info
->callbacks
->reloc_overflow
)
5489 (finfo
->info
, (h
? &h
->root
: NULL
), name
,
5490 howto_table_ext
[r_type
].name
,
5491 r_addend
, input_bfd
, input_section
, r_addr
)))
5503 /* Handle a link order which is supposed to generate a reloc. */
5506 aout_link_reloc_link_order (finfo
, o
, p
)
5507 struct aout_final_link_info
*finfo
;
5509 struct bfd_link_order
*p
;
5511 struct bfd_link_order_reloc
*pr
;
5514 reloc_howto_type
*howto
;
5515 file_ptr
*reloff_ptr
= NULL
;
5516 struct reloc_std_external srel
;
5517 struct reloc_ext_external erel
;
5523 if (p
->type
== bfd_section_reloc_link_order
)
5526 if (bfd_is_abs_section (pr
->u
.section
))
5527 r_index
= N_ABS
| N_EXT
;
5530 BFD_ASSERT (pr
->u
.section
->owner
== finfo
->output_bfd
);
5531 r_index
= pr
->u
.section
->target_index
;
5536 struct aout_link_hash_entry
*h
;
5538 BFD_ASSERT (p
->type
== bfd_symbol_reloc_link_order
);
5540 h
= ((struct aout_link_hash_entry
*)
5541 bfd_wrapped_link_hash_lookup (finfo
->output_bfd
, finfo
->info
,
5542 pr
->u
.name
, FALSE
, FALSE
, TRUE
));
5543 if (h
!= (struct aout_link_hash_entry
*) NULL
5548 /* We decided to strip this symbol, but it turns out that we
5549 can't. Note that we lose the other and desc information
5550 here. I don't think that will ever matter for a global
5554 if (! aout_link_write_other_symbol (h
, (PTR
) finfo
))
5560 if (! ((*finfo
->info
->callbacks
->unattached_reloc
)
5561 (finfo
->info
, pr
->u
.name
, (bfd
*) NULL
,
5562 (asection
*) NULL
, (bfd_vma
) 0)))
5568 howto
= bfd_reloc_type_lookup (finfo
->output_bfd
, pr
->reloc
);
5571 bfd_set_error (bfd_error_bad_value
);
5575 if (o
== obj_textsec (finfo
->output_bfd
))
5576 reloff_ptr
= &finfo
->treloff
;
5577 else if (o
== obj_datasec (finfo
->output_bfd
))
5578 reloff_ptr
= &finfo
->dreloff
;
5582 if (obj_reloc_entry_size (finfo
->output_bfd
) == RELOC_STD_SIZE
)
5585 MY_put_reloc (finfo
->output_bfd
, r_extern
, r_index
, p
->offset
, howto
,
5595 r_pcrel
= (int) howto
->pc_relative
;
5596 r_baserel
= (howto
->type
& 8) != 0;
5597 r_jmptable
= (howto
->type
& 16) != 0;
5598 r_relative
= (howto
->type
& 32) != 0;
5599 r_length
= howto
->size
;
5601 PUT_WORD (finfo
->output_bfd
, p
->offset
, srel
.r_address
);
5602 if (bfd_header_big_endian (finfo
->output_bfd
))
5604 srel
.r_index
[0] = r_index
>> 16;
5605 srel
.r_index
[1] = r_index
>> 8;
5606 srel
.r_index
[2] = r_index
;
5608 ((r_extern
? RELOC_STD_BITS_EXTERN_BIG
: 0)
5609 | (r_pcrel
? RELOC_STD_BITS_PCREL_BIG
: 0)
5610 | (r_baserel
? RELOC_STD_BITS_BASEREL_BIG
: 0)
5611 | (r_jmptable
? RELOC_STD_BITS_JMPTABLE_BIG
: 0)
5612 | (r_relative
? RELOC_STD_BITS_RELATIVE_BIG
: 0)
5613 | (r_length
<< RELOC_STD_BITS_LENGTH_SH_BIG
));
5617 srel
.r_index
[2] = r_index
>> 16;
5618 srel
.r_index
[1] = r_index
>> 8;
5619 srel
.r_index
[0] = r_index
;
5621 ((r_extern
? RELOC_STD_BITS_EXTERN_LITTLE
: 0)
5622 | (r_pcrel
? RELOC_STD_BITS_PCREL_LITTLE
: 0)
5623 | (r_baserel
? RELOC_STD_BITS_BASEREL_LITTLE
: 0)
5624 | (r_jmptable
? RELOC_STD_BITS_JMPTABLE_LITTLE
: 0)
5625 | (r_relative
? RELOC_STD_BITS_RELATIVE_LITTLE
: 0)
5626 | (r_length
<< RELOC_STD_BITS_LENGTH_SH_LITTLE
));
5630 rel_ptr
= (PTR
) &srel
;
5632 /* We have to write the addend into the object file, since
5633 standard a.out relocs are in place. It would be more
5634 reliable if we had the current contents of the file here,
5635 rather than assuming zeroes, but we can't read the file since
5636 it was opened using bfd_openw. */
5637 if (pr
->addend
!= 0)
5640 bfd_reloc_status_type r
;
5644 size
= bfd_get_reloc_size (howto
);
5645 buf
= (bfd_byte
*) bfd_zmalloc (size
);
5646 if (buf
== (bfd_byte
*) NULL
)
5648 r
= MY_relocate_contents (howto
, finfo
->output_bfd
,
5649 (bfd_vma
) pr
->addend
, buf
);
5655 case bfd_reloc_outofrange
:
5657 case bfd_reloc_overflow
:
5658 if (! ((*finfo
->info
->callbacks
->reloc_overflow
)
5660 (p
->type
== bfd_section_reloc_link_order
5661 ? bfd_section_name (finfo
->output_bfd
,
5664 howto
->name
, pr
->addend
, (bfd
*) NULL
,
5665 (asection
*) NULL
, (bfd_vma
) 0)))
5672 ok
= bfd_set_section_contents (finfo
->output_bfd
, o
, (PTR
) buf
,
5673 (file_ptr
) p
->offset
, size
);
5681 #ifdef MY_put_ext_reloc
5682 MY_put_ext_reloc (finfo
->output_bfd
, r_extern
, r_index
, p
->offset
,
5683 howto
, &erel
, pr
->addend
);
5685 PUT_WORD (finfo
->output_bfd
, p
->offset
, erel
.r_address
);
5687 if (bfd_header_big_endian (finfo
->output_bfd
))
5689 erel
.r_index
[0] = r_index
>> 16;
5690 erel
.r_index
[1] = r_index
>> 8;
5691 erel
.r_index
[2] = r_index
;
5693 ((r_extern
? RELOC_EXT_BITS_EXTERN_BIG
: 0)
5694 | (howto
->type
<< RELOC_EXT_BITS_TYPE_SH_BIG
));
5698 erel
.r_index
[2] = r_index
>> 16;
5699 erel
.r_index
[1] = r_index
>> 8;
5700 erel
.r_index
[0] = r_index
;
5702 (r_extern
? RELOC_EXT_BITS_EXTERN_LITTLE
: 0)
5703 | (howto
->type
<< RELOC_EXT_BITS_TYPE_SH_LITTLE
);
5706 PUT_WORD (finfo
->output_bfd
, (bfd_vma
) pr
->addend
, erel
.r_addend
);
5707 #endif /* MY_put_ext_reloc */
5709 rel_ptr
= (PTR
) &erel
;
5712 amt
= obj_reloc_entry_size (finfo
->output_bfd
);
5713 if (bfd_seek (finfo
->output_bfd
, *reloff_ptr
, SEEK_SET
) != 0
5714 || bfd_bwrite (rel_ptr
, amt
, finfo
->output_bfd
) != amt
)
5717 *reloff_ptr
+= obj_reloc_entry_size (finfo
->output_bfd
);
5719 /* Assert that the relocs have not run into the symbols, and that n
5720 the text relocs have not run into the data relocs. */
5721 BFD_ASSERT (*reloff_ptr
<= obj_sym_filepos (finfo
->output_bfd
)
5722 && (reloff_ptr
!= &finfo
->treloff
5724 <= obj_datasec (finfo
->output_bfd
)->rel_filepos
)));