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 */
658 #if 0 /* These should be set correctly anyways. */
659 abfd
->sections
= obj_textsec (abfd
);
660 obj_textsec (abfd
)->next
= obj_datasec (abfd
);
661 obj_datasec (abfd
)->next
= obj_bsssec (abfd
);
667 bfd_release (abfd
, rawptr
);
668 abfd
->tdata
.aout_data
= oldrawptr
;
674 aout_@var{size}_mkobject
677 bfd_boolean aout_@var{size}_mkobject, (bfd *abfd);
680 Initialize BFD @var{abfd} for use with a.out files.
684 NAME(aout
,mkobject
) (abfd
)
687 struct aout_data_struct
*rawptr
;
688 bfd_size_type amt
= sizeof (struct aout_data_struct
);
690 bfd_set_error (bfd_error_system_call
);
692 rawptr
= (struct aout_data_struct
*) bfd_zalloc (abfd
, amt
);
696 abfd
->tdata
.aout_data
= rawptr
;
697 exec_hdr (abfd
) = &(rawptr
->e
);
699 obj_textsec (abfd
) = (asection
*) NULL
;
700 obj_datasec (abfd
) = (asection
*) NULL
;
701 obj_bsssec (abfd
) = (asection
*) NULL
;
708 aout_@var{size}_machine_type
711 enum machine_type aout_@var{size}_machine_type
712 (enum bfd_architecture arch,
713 unsigned long machine));
716 Keep track of machine architecture and machine type for
717 a.out's. Return the <<machine_type>> for a particular
718 architecture and machine, or <<M_UNKNOWN>> if that exact architecture
719 and machine can't be represented in a.out format.
721 If the architecture is understood, machine type 0 (default)
722 is always understood.
726 NAME(aout
,machine_type
) (arch
, machine
, unknown
)
727 enum bfd_architecture arch
;
728 unsigned long machine
;
729 bfd_boolean
*unknown
;
731 enum machine_type arch_flags
;
733 arch_flags
= M_UNKNOWN
;
740 || machine
== bfd_mach_sparc
741 || machine
== bfd_mach_sparc_sparclite
742 || machine
== bfd_mach_sparc_sparclite_le
743 || machine
== bfd_mach_sparc_v9
)
744 arch_flags
= M_SPARC
;
745 else if (machine
== bfd_mach_sparc_sparclet
)
746 arch_flags
= M_SPARCLET
;
752 case 0: arch_flags
= M_68010
; break;
753 case bfd_mach_m68000
: arch_flags
= M_UNKNOWN
; *unknown
= FALSE
; break;
754 case bfd_mach_m68010
: arch_flags
= M_68010
; break;
755 case bfd_mach_m68020
: arch_flags
= M_68020
; break;
756 default: arch_flags
= M_UNKNOWN
; break;
762 || machine
== bfd_mach_i386_i386
763 || machine
== bfd_mach_i386_i386_intel_syntax
)
781 case bfd_mach_mips3000
:
782 case bfd_mach_mips3900
:
783 arch_flags
= M_MIPS1
;
785 case bfd_mach_mips6000
:
786 arch_flags
= M_MIPS2
;
788 case bfd_mach_mips4000
:
789 case bfd_mach_mips4010
:
790 case bfd_mach_mips4100
:
791 case bfd_mach_mips4300
:
792 case bfd_mach_mips4400
:
793 case bfd_mach_mips4600
:
794 case bfd_mach_mips4650
:
795 case bfd_mach_mips8000
:
796 case bfd_mach_mips10000
:
797 case bfd_mach_mips12000
:
798 case bfd_mach_mips16
:
799 case bfd_mach_mipsisa32
:
800 case bfd_mach_mipsisa32r2
:
802 case bfd_mach_mipsisa64
:
803 case bfd_mach_mipsisa64r2
:
804 case bfd_mach_mips_sb1
:
805 /* FIXME: These should be MIPS3, MIPS4, MIPS16, MIPS32, etc. */
806 arch_flags
= M_MIPS2
;
809 arch_flags
= M_UNKNOWN
;
817 case 0: arch_flags
= M_NS32532
; break;
818 case 32032: arch_flags
= M_NS32032
; break;
819 case 32532: arch_flags
= M_NS32532
; break;
820 default: arch_flags
= M_UNKNOWN
; break;
829 if (machine
== 0 || machine
== 255)
838 arch_flags
= M_UNKNOWN
;
841 if (arch_flags
!= M_UNKNOWN
)
849 aout_@var{size}_set_arch_mach
852 bfd_boolean aout_@var{size}_set_arch_mach,
854 enum bfd_architecture arch,
855 unsigned long machine));
858 Set the architecture and the machine of the BFD @var{abfd} to the
859 values @var{arch} and @var{machine}. Verify that @var{abfd}'s format
860 can support the architecture required.
864 NAME(aout
,set_arch_mach
) (abfd
, arch
, machine
)
866 enum bfd_architecture arch
;
867 unsigned long machine
;
869 if (! bfd_default_set_arch_mach (abfd
, arch
, machine
))
872 if (arch
!= bfd_arch_unknown
)
876 NAME(aout
,machine_type
) (arch
, machine
, &unknown
);
881 /* Determine the size of a relocation entry. */
887 obj_reloc_entry_size (abfd
) = RELOC_EXT_SIZE
;
890 obj_reloc_entry_size (abfd
) = RELOC_STD_SIZE
;
894 return (*aout_backend_info (abfd
)->set_sizes
) (abfd
);
898 adjust_o_magic (abfd
, execp
)
900 struct internal_exec
*execp
;
902 file_ptr pos
= adata (abfd
).exec_bytes_size
;
907 obj_textsec (abfd
)->filepos
= pos
;
908 if (!obj_textsec (abfd
)->user_set_vma
)
909 obj_textsec (abfd
)->vma
= vma
;
911 vma
= obj_textsec (abfd
)->vma
;
913 pos
+= obj_textsec (abfd
)->size
;
914 vma
+= obj_textsec (abfd
)->size
;
917 if (!obj_datasec (abfd
)->user_set_vma
)
919 #if 0 /* ?? Does alignment in the file image really matter? */
920 pad
= align_power (vma
, obj_datasec (abfd
)->alignment_power
) - vma
;
922 obj_textsec (abfd
)->size
+= pad
;
925 obj_datasec (abfd
)->vma
= vma
;
928 vma
= obj_datasec (abfd
)->vma
;
929 obj_datasec (abfd
)->filepos
= pos
;
930 pos
+= obj_datasec (abfd
)->size
;
931 vma
+= obj_datasec (abfd
)->size
;
934 if (!obj_bsssec (abfd
)->user_set_vma
)
937 pad
= align_power (vma
, obj_bsssec (abfd
)->alignment_power
) - vma
;
939 obj_datasec (abfd
)->size
+= pad
;
942 obj_bsssec (abfd
)->vma
= vma
;
946 /* The VMA of the .bss section is set by the VMA of the
947 .data section plus the size of the .data section. We may
948 need to add padding bytes to make this true. */
949 pad
= obj_bsssec (abfd
)->vma
- vma
;
952 obj_datasec (abfd
)->size
+= pad
;
956 obj_bsssec (abfd
)->filepos
= pos
;
958 /* Fix up the exec header. */
959 execp
->a_text
= obj_textsec (abfd
)->size
;
960 execp
->a_data
= obj_datasec (abfd
)->size
;
961 execp
->a_bss
= obj_bsssec (abfd
)->size
;
962 N_SET_MAGIC (*execp
, OMAGIC
);
966 adjust_z_magic (abfd
, execp
)
968 struct internal_exec
*execp
;
970 bfd_size_type data_pad
, text_pad
;
972 const struct aout_backend_data
*abdp
;
973 int ztih
; /* Nonzero if text includes exec header. */
975 abdp
= aout_backend_info (abfd
);
979 && (abdp
->text_includes_header
980 || obj_aout_subformat (abfd
) == q_magic_format
));
981 obj_textsec (abfd
)->filepos
= (ztih
982 ? adata (abfd
).exec_bytes_size
983 : adata (abfd
).zmagic_disk_block_size
);
984 if (! obj_textsec (abfd
)->user_set_vma
)
986 /* ?? Do we really need to check for relocs here? */
987 obj_textsec (abfd
)->vma
= ((abfd
->flags
& HAS_RELOC
)
990 ? (abdp
->default_text_vma
991 + adata (abfd
).exec_bytes_size
)
992 : abdp
->default_text_vma
));
997 /* The .text section is being loaded at an unusual address. We
998 may need to pad it such that the .data section starts at a page
1001 text_pad
= ((obj_textsec (abfd
)->filepos
- obj_textsec (abfd
)->vma
)
1002 & (adata (abfd
).page_size
- 1));
1004 text_pad
= ((- obj_textsec (abfd
)->vma
)
1005 & (adata (abfd
).page_size
- 1));
1008 /* Find start of data. */
1011 text_end
= obj_textsec (abfd
)->filepos
+ obj_textsec (abfd
)->size
;
1012 text_pad
+= BFD_ALIGN (text_end
, adata (abfd
).page_size
) - text_end
;
1016 /* Note that if page_size == zmagic_disk_block_size, then
1017 filepos == page_size, and this case is the same as the ztih
1019 text_end
= obj_textsec (abfd
)->size
;
1020 text_pad
+= BFD_ALIGN (text_end
, adata (abfd
).page_size
) - text_end
;
1021 text_end
+= obj_textsec (abfd
)->filepos
;
1023 obj_textsec (abfd
)->size
+= text_pad
;
1024 text_end
+= text_pad
;
1027 if (!obj_datasec (abfd
)->user_set_vma
)
1030 vma
= obj_textsec (abfd
)->vma
+ obj_textsec (abfd
)->size
;
1031 obj_datasec (abfd
)->vma
= BFD_ALIGN (vma
, adata (abfd
).segment_size
);
1033 if (abdp
&& abdp
->zmagic_mapped_contiguous
)
1035 asection
* text
= obj_textsec (abfd
);
1036 asection
* data
= obj_datasec (abfd
);
1038 text_pad
= data
->vma
- (text
->vma
+ text
->size
);
1039 /* Only pad the text section if the data
1040 section is going to be placed after it. */
1042 text
->size
+= text_pad
;
1044 obj_datasec (abfd
)->filepos
= (obj_textsec (abfd
)->filepos
1045 + obj_textsec (abfd
)->size
);
1047 /* Fix up exec header while we're at it. */
1048 execp
->a_text
= obj_textsec (abfd
)->size
;
1049 if (ztih
&& (!abdp
|| (abdp
&& !abdp
->exec_header_not_counted
)))
1050 execp
->a_text
+= adata (abfd
).exec_bytes_size
;
1051 if (obj_aout_subformat (abfd
) == q_magic_format
)
1052 N_SET_MAGIC (*execp
, QMAGIC
);
1054 N_SET_MAGIC (*execp
, ZMAGIC
);
1056 /* Spec says data section should be rounded up to page boundary. */
1057 obj_datasec (abfd
)->size
1058 = align_power (obj_datasec (abfd
)->size
,
1059 obj_bsssec (abfd
)->alignment_power
);
1060 execp
->a_data
= BFD_ALIGN (obj_datasec (abfd
)->size
,
1061 adata (abfd
).page_size
);
1062 data_pad
= execp
->a_data
- obj_datasec (abfd
)->size
;
1065 if (!obj_bsssec (abfd
)->user_set_vma
)
1066 obj_bsssec (abfd
)->vma
= (obj_datasec (abfd
)->vma
1067 + obj_datasec (abfd
)->size
);
1068 /* If the BSS immediately follows the data section and extra space
1069 in the page is left after the data section, fudge data
1070 in the header so that the bss section looks smaller by that
1071 amount. We'll start the bss section there, and lie to the OS.
1072 (Note that a linker script, as well as the above assignment,
1073 could have explicitly set the BSS vma to immediately follow
1074 the data section.) */
1075 if (align_power (obj_bsssec (abfd
)->vma
, obj_bsssec (abfd
)->alignment_power
)
1076 == obj_datasec (abfd
)->vma
+ obj_datasec (abfd
)->size
)
1077 execp
->a_bss
= (data_pad
> obj_bsssec (abfd
)->size
1078 ? 0 : obj_bsssec (abfd
)->size
- data_pad
);
1080 execp
->a_bss
= obj_bsssec (abfd
)->size
;
1084 adjust_n_magic (abfd
, execp
)
1086 struct internal_exec
*execp
;
1088 file_ptr pos
= adata (abfd
).exec_bytes_size
;
1093 obj_textsec (abfd
)->filepos
= pos
;
1094 if (!obj_textsec (abfd
)->user_set_vma
)
1095 obj_textsec (abfd
)->vma
= vma
;
1097 vma
= obj_textsec (abfd
)->vma
;
1098 pos
+= obj_textsec (abfd
)->size
;
1099 vma
+= obj_textsec (abfd
)->size
;
1102 obj_datasec (abfd
)->filepos
= pos
;
1103 if (!obj_datasec (abfd
)->user_set_vma
)
1104 obj_datasec (abfd
)->vma
= BFD_ALIGN (vma
, adata (abfd
).segment_size
);
1105 vma
= obj_datasec (abfd
)->vma
;
1107 /* Since BSS follows data immediately, see if it needs alignment. */
1108 vma
+= obj_datasec (abfd
)->size
;
1109 pad
= align_power (vma
, obj_bsssec (abfd
)->alignment_power
) - vma
;
1110 obj_datasec (abfd
)->size
+= pad
;
1111 pos
+= obj_datasec (abfd
)->size
;
1114 if (!obj_bsssec (abfd
)->user_set_vma
)
1115 obj_bsssec (abfd
)->vma
= vma
;
1117 vma
= obj_bsssec (abfd
)->vma
;
1119 /* Fix up exec header. */
1120 execp
->a_text
= obj_textsec (abfd
)->size
;
1121 execp
->a_data
= obj_datasec (abfd
)->size
;
1122 execp
->a_bss
= obj_bsssec (abfd
)->size
;
1123 N_SET_MAGIC (*execp
, NMAGIC
);
1127 NAME(aout
,adjust_sizes_and_vmas
) (abfd
, text_size
, text_end
)
1129 bfd_size_type
*text_size
;
1130 file_ptr
*text_end ATTRIBUTE_UNUSED
;
1132 struct internal_exec
*execp
= exec_hdr (abfd
);
1134 if (! NAME(aout
,make_sections
) (abfd
))
1137 if (adata (abfd
).magic
!= undecided_magic
)
1140 obj_textsec (abfd
)->size
=
1141 align_power (obj_textsec (abfd
)->size
,
1142 obj_textsec (abfd
)->alignment_power
);
1144 *text_size
= obj_textsec (abfd
)->size
;
1145 /* Rule (heuristic) for when to pad to a new page. Note that there
1146 are (at least) two ways demand-paged (ZMAGIC) files have been
1147 handled. Most Berkeley-based systems start the text segment at
1148 (TARGET_PAGE_SIZE). However, newer versions of SUNOS start the text
1149 segment right after the exec header; the latter is counted in the
1150 text segment size, and is paged in by the kernel with the rest of
1153 /* This perhaps isn't the right way to do this, but made it simpler for me
1154 to understand enough to implement it. Better would probably be to go
1155 right from BFD flags to alignment/positioning characteristics. But the
1156 old code was sloppy enough about handling the flags, and had enough
1157 other magic, that it was a little hard for me to understand. I think
1158 I understand it better now, but I haven't time to do the cleanup this
1161 if (abfd
->flags
& D_PAGED
)
1162 /* Whether or not WP_TEXT is set -- let D_PAGED override. */
1163 adata (abfd
).magic
= z_magic
;
1164 else if (abfd
->flags
& WP_TEXT
)
1165 adata (abfd
).magic
= n_magic
;
1167 adata (abfd
).magic
= o_magic
;
1169 #ifdef BFD_AOUT_DEBUG /* requires gcc2 */
1171 fprintf (stderr
, "%s text=<%x,%x,%x> data=<%x,%x,%x> bss=<%x,%x,%x>\n",
1173 switch (adata (abfd
).magic
)
1175 case n_magic
: str
= "NMAGIC"; break;
1176 case o_magic
: str
= "OMAGIC"; break;
1177 case z_magic
: str
= "ZMAGIC"; break;
1182 obj_textsec (abfd
)->vma
, obj_textsec (abfd
)->size
,
1183 obj_textsec (abfd
)->alignment_power
,
1184 obj_datasec (abfd
)->vma
, obj_datasec (abfd
)->size
,
1185 obj_datasec (abfd
)->alignment_power
,
1186 obj_bsssec (abfd
)->vma
, obj_bsssec (abfd
)->size
,
1187 obj_bsssec (abfd
)->alignment_power
);
1191 switch (adata (abfd
).magic
)
1194 adjust_o_magic (abfd
, execp
);
1197 adjust_z_magic (abfd
, execp
);
1200 adjust_n_magic (abfd
, execp
);
1206 #ifdef BFD_AOUT_DEBUG
1207 fprintf (stderr
, " text=<%x,%x,%x> data=<%x,%x,%x> bss=<%x,%x>\n",
1208 obj_textsec (abfd
)->vma
, obj_textsec (abfd
)->size
,
1209 obj_textsec (abfd
)->filepos
,
1210 obj_datasec (abfd
)->vma
, obj_datasec (abfd
)->size
,
1211 obj_datasec (abfd
)->filepos
,
1212 obj_bsssec (abfd
)->vma
, obj_bsssec (abfd
)->size
);
1220 aout_@var{size}_new_section_hook
1223 bfd_boolean aout_@var{size}_new_section_hook,
1225 asection *newsect));
1228 Called by the BFD in response to a @code{bfd_make_section}
1232 NAME(aout
,new_section_hook
) (abfd
, newsect
)
1236 /* Align to double at least. */
1237 newsect
->alignment_power
= bfd_get_arch_info (abfd
)->section_align_power
;
1239 if (bfd_get_format (abfd
) == bfd_object
)
1241 if (obj_textsec (abfd
) == NULL
&& !strcmp (newsect
->name
, ".text"))
1243 obj_textsec (abfd
)= newsect
;
1244 newsect
->target_index
= N_TEXT
;
1248 if (obj_datasec (abfd
) == NULL
&& !strcmp (newsect
->name
, ".data"))
1250 obj_datasec (abfd
) = newsect
;
1251 newsect
->target_index
= N_DATA
;
1255 if (obj_bsssec (abfd
) == NULL
&& !strcmp (newsect
->name
, ".bss"))
1257 obj_bsssec (abfd
) = newsect
;
1258 newsect
->target_index
= N_BSS
;
1263 /* We allow more than three sections internally. */
1268 NAME(aout
,set_section_contents
) (abfd
, section
, location
, offset
, count
)
1273 bfd_size_type count
;
1276 bfd_size_type text_size
;
1278 if (! abfd
->output_has_begun
)
1280 if (! NAME(aout
,adjust_sizes_and_vmas
) (abfd
, &text_size
, &text_end
))
1284 if (section
== obj_bsssec (abfd
))
1286 bfd_set_error (bfd_error_no_contents
);
1290 if (section
!= obj_textsec (abfd
)
1291 && section
!= obj_datasec (abfd
))
1293 if (aout_section_merge_with_text_p (abfd
, section
))
1294 section
->filepos
= obj_textsec (abfd
)->filepos
+
1295 (section
->vma
- obj_textsec (abfd
)->vma
);
1298 (*_bfd_error_handler
)
1299 (_("%s: can not represent section `%s' in a.out object file format"),
1300 bfd_get_filename (abfd
), bfd_get_section_name (abfd
, section
));
1301 bfd_set_error (bfd_error_nonrepresentable_section
);
1308 if (bfd_seek (abfd
, section
->filepos
+ offset
, SEEK_SET
) != 0
1309 || bfd_bwrite (location
, count
, abfd
) != count
)
1316 /* Read the external symbols from an a.out file. */
1319 aout_get_external_symbols (abfd
)
1322 if (obj_aout_external_syms (abfd
) == (struct external_nlist
*) NULL
)
1324 bfd_size_type count
;
1325 struct external_nlist
*syms
;
1328 count
= exec_hdr (abfd
)->a_syms
/ EXTERNAL_NLIST_SIZE
;
1331 if (! bfd_get_file_window (abfd
, obj_sym_filepos (abfd
),
1332 exec_hdr (abfd
)->a_syms
,
1333 &obj_aout_sym_window (abfd
), TRUE
))
1335 syms
= (struct external_nlist
*) obj_aout_sym_window (abfd
).data
;
1337 /* We allocate using malloc to make the values easy to free
1338 later on. If we put them on the objalloc it might not be
1339 possible to free them. */
1340 syms
= ((struct external_nlist
*)
1341 bfd_malloc (count
* EXTERNAL_NLIST_SIZE
));
1342 if (syms
== (struct external_nlist
*) NULL
&& count
!= 0)
1345 amt
= exec_hdr (abfd
)->a_syms
;
1346 if (bfd_seek (abfd
, obj_sym_filepos (abfd
), SEEK_SET
) != 0
1347 || bfd_bread (syms
, amt
, abfd
) != amt
)
1354 obj_aout_external_syms (abfd
) = syms
;
1355 obj_aout_external_sym_count (abfd
) = count
;
1358 if (obj_aout_external_strings (abfd
) == NULL
1359 && exec_hdr (abfd
)->a_syms
!= 0)
1361 unsigned char string_chars
[BYTES_IN_WORD
];
1362 bfd_size_type stringsize
;
1364 bfd_size_type amt
= BYTES_IN_WORD
;
1366 /* Get the size of the strings. */
1367 if (bfd_seek (abfd
, obj_str_filepos (abfd
), SEEK_SET
) != 0
1368 || bfd_bread ((PTR
) string_chars
, amt
, abfd
) != amt
)
1370 stringsize
= GET_WORD (abfd
, string_chars
);
1373 if (! bfd_get_file_window (abfd
, obj_str_filepos (abfd
), stringsize
,
1374 &obj_aout_string_window (abfd
), TRUE
))
1376 strings
= (char *) obj_aout_string_window (abfd
).data
;
1378 strings
= (char *) bfd_malloc (stringsize
+ 1);
1379 if (strings
== NULL
)
1382 /* Skip space for the string count in the buffer for convenience
1383 when using indexes. */
1384 amt
= stringsize
- BYTES_IN_WORD
;
1385 if (bfd_bread (strings
+ BYTES_IN_WORD
, amt
, abfd
) != amt
)
1392 /* Ensure that a zero index yields an empty string. */
1395 strings
[stringsize
- 1] = 0;
1397 obj_aout_external_strings (abfd
) = strings
;
1398 obj_aout_external_string_size (abfd
) = stringsize
;
1404 /* Translate an a.out symbol into a BFD symbol. The desc, other, type
1405 and symbol->value fields of CACHE_PTR will be set from the a.out
1406 nlist structure. This function is responsible for setting
1407 symbol->flags and symbol->section, and adjusting symbol->value. */
1410 translate_from_native_sym_flags (abfd
, cache_ptr
)
1412 aout_symbol_type
*cache_ptr
;
1416 if ((cache_ptr
->type
& N_STAB
) != 0
1417 || cache_ptr
->type
== N_FN
)
1421 /* This is a debugging symbol. */
1422 cache_ptr
->symbol
.flags
= BSF_DEBUGGING
;
1424 /* Work out the symbol section. */
1425 switch (cache_ptr
->type
& N_TYPE
)
1429 sec
= obj_textsec (abfd
);
1432 sec
= obj_datasec (abfd
);
1435 sec
= obj_bsssec (abfd
);
1439 sec
= bfd_abs_section_ptr
;
1443 cache_ptr
->symbol
.section
= sec
;
1444 cache_ptr
->symbol
.value
-= sec
->vma
;
1449 /* Get the default visibility. This does not apply to all types, so
1450 we just hold it in a local variable to use if wanted. */
1451 if ((cache_ptr
->type
& N_EXT
) == 0)
1452 visible
= BSF_LOCAL
;
1454 visible
= BSF_GLOBAL
;
1456 switch (cache_ptr
->type
)
1459 case N_ABS
: case N_ABS
| N_EXT
:
1460 cache_ptr
->symbol
.section
= bfd_abs_section_ptr
;
1461 cache_ptr
->symbol
.flags
= visible
;
1464 case N_UNDF
| N_EXT
:
1465 if (cache_ptr
->symbol
.value
!= 0)
1467 /* This is a common symbol. */
1468 cache_ptr
->symbol
.flags
= BSF_GLOBAL
;
1469 cache_ptr
->symbol
.section
= bfd_com_section_ptr
;
1473 cache_ptr
->symbol
.flags
= 0;
1474 cache_ptr
->symbol
.section
= bfd_und_section_ptr
;
1478 case N_TEXT
: case N_TEXT
| N_EXT
:
1479 cache_ptr
->symbol
.section
= obj_textsec (abfd
);
1480 cache_ptr
->symbol
.value
-= cache_ptr
->symbol
.section
->vma
;
1481 cache_ptr
->symbol
.flags
= visible
;
1484 /* N_SETV symbols used to represent set vectors placed in the
1485 data section. They are no longer generated. Theoretically,
1486 it was possible to extract the entries and combine them with
1487 new ones, although I don't know if that was ever actually
1488 done. Unless that feature is restored, treat them as data
1490 case N_SETV
: case N_SETV
| N_EXT
:
1491 case N_DATA
: case N_DATA
| N_EXT
:
1492 cache_ptr
->symbol
.section
= obj_datasec (abfd
);
1493 cache_ptr
->symbol
.value
-= cache_ptr
->symbol
.section
->vma
;
1494 cache_ptr
->symbol
.flags
= visible
;
1497 case N_BSS
: case N_BSS
| N_EXT
:
1498 cache_ptr
->symbol
.section
= obj_bsssec (abfd
);
1499 cache_ptr
->symbol
.value
-= cache_ptr
->symbol
.section
->vma
;
1500 cache_ptr
->symbol
.flags
= visible
;
1503 case N_SETA
: case N_SETA
| N_EXT
:
1504 case N_SETT
: case N_SETT
| N_EXT
:
1505 case N_SETD
: case N_SETD
| N_EXT
:
1506 case N_SETB
: case N_SETB
| N_EXT
:
1508 /* This code is no longer needed. It used to be used to make
1509 the linker handle set symbols, but they are now handled in
1510 the add_symbols routine instead. */
1513 arelent_chain
*reloc
;
1514 asection
*into_section
;
1517 /* This is a set symbol. The name of the symbol is the name
1518 of the set (e.g., __CTOR_LIST__). The value of the symbol
1519 is the value to add to the set. We create a section with
1520 the same name as the symbol, and add a reloc to insert the
1521 appropriate value into the section.
1523 This action is actually obsolete; it used to make the
1524 linker do the right thing, but the linker no longer uses
1527 section
= bfd_get_section_by_name (abfd
, cache_ptr
->symbol
.name
);
1528 if (section
== NULL
)
1532 amt
= strlen (cache_ptr
->symbol
.name
) + 1;
1533 copy
= bfd_alloc (abfd
, amt
);
1537 strcpy (copy
, cache_ptr
->symbol
.name
);
1538 section
= bfd_make_section (abfd
, copy
);
1539 if (section
== NULL
)
1543 amt
= sizeof (arelent_chain
);
1544 reloc
= (arelent_chain
*) bfd_alloc (abfd
, amt
);
1548 /* Build a relocation entry for the constructor. */
1549 switch (cache_ptr
->type
& N_TYPE
)
1552 into_section
= bfd_abs_section_ptr
;
1553 cache_ptr
->type
= N_ABS
;
1556 into_section
= obj_textsec (abfd
);
1557 cache_ptr
->type
= N_TEXT
;
1560 into_section
= obj_datasec (abfd
);
1561 cache_ptr
->type
= N_DATA
;
1564 into_section
= obj_bsssec (abfd
);
1565 cache_ptr
->type
= N_BSS
;
1569 /* Build a relocation pointing into the constructor section
1570 pointing at the symbol in the set vector specified. */
1571 reloc
->relent
.addend
= cache_ptr
->symbol
.value
;
1572 cache_ptr
->symbol
.section
= into_section
;
1573 reloc
->relent
.sym_ptr_ptr
= into_section
->symbol_ptr_ptr
;
1575 /* We modify the symbol to belong to a section depending upon
1576 the name of the symbol, and add to the size of the section
1577 to contain a pointer to the symbol. Build a reloc entry to
1578 relocate to this symbol attached to this section. */
1579 section
->flags
= SEC_CONSTRUCTOR
| SEC_RELOC
;
1581 section
->reloc_count
++;
1582 section
->alignment_power
= 2;
1584 reloc
->next
= section
->constructor_chain
;
1585 section
->constructor_chain
= reloc
;
1586 reloc
->relent
.address
= section
->size
;
1587 section
->size
+= BYTES_IN_WORD
;
1589 reloc
->relent
.howto
= CTOR_TABLE_RELOC_HOWTO (abfd
);
1593 switch (cache_ptr
->type
& N_TYPE
)
1596 cache_ptr
->symbol
.section
= bfd_abs_section_ptr
;
1599 cache_ptr
->symbol
.section
= obj_textsec (abfd
);
1602 cache_ptr
->symbol
.section
= obj_datasec (abfd
);
1605 cache_ptr
->symbol
.section
= obj_bsssec (abfd
);
1609 cache_ptr
->symbol
.flags
|= BSF_CONSTRUCTOR
;
1614 /* This symbol is the text of a warning message. The next
1615 symbol is the symbol to associate the warning with. If a
1616 reference is made to that symbol, a warning is issued. */
1617 cache_ptr
->symbol
.flags
= BSF_DEBUGGING
| BSF_WARNING
;
1618 cache_ptr
->symbol
.section
= bfd_abs_section_ptr
;
1621 case N_INDR
: case N_INDR
| N_EXT
:
1622 /* An indirect symbol. This consists of two symbols in a row.
1623 The first symbol is the name of the indirection. The second
1624 symbol is the name of the target. A reference to the first
1625 symbol becomes a reference to the second. */
1626 cache_ptr
->symbol
.flags
= BSF_DEBUGGING
| BSF_INDIRECT
| visible
;
1627 cache_ptr
->symbol
.section
= bfd_ind_section_ptr
;
1631 cache_ptr
->symbol
.section
= bfd_und_section_ptr
;
1632 cache_ptr
->symbol
.flags
= BSF_WEAK
;
1636 cache_ptr
->symbol
.section
= bfd_abs_section_ptr
;
1637 cache_ptr
->symbol
.flags
= BSF_WEAK
;
1641 cache_ptr
->symbol
.section
= obj_textsec (abfd
);
1642 cache_ptr
->symbol
.value
-= cache_ptr
->symbol
.section
->vma
;
1643 cache_ptr
->symbol
.flags
= BSF_WEAK
;
1647 cache_ptr
->symbol
.section
= obj_datasec (abfd
);
1648 cache_ptr
->symbol
.value
-= cache_ptr
->symbol
.section
->vma
;
1649 cache_ptr
->symbol
.flags
= BSF_WEAK
;
1653 cache_ptr
->symbol
.section
= obj_bsssec (abfd
);
1654 cache_ptr
->symbol
.value
-= cache_ptr
->symbol
.section
->vma
;
1655 cache_ptr
->symbol
.flags
= BSF_WEAK
;
1662 /* Set the fields of SYM_POINTER according to CACHE_PTR. */
1665 translate_to_native_sym_flags (abfd
, cache_ptr
, sym_pointer
)
1668 struct external_nlist
*sym_pointer
;
1670 bfd_vma value
= cache_ptr
->value
;
1674 /* Mask out any existing type bits in case copying from one section
1676 sym_pointer
->e_type
[0] &= ~N_TYPE
;
1678 sec
= bfd_get_section (cache_ptr
);
1683 /* This case occurs, e.g., for the *DEBUG* section of a COFF
1685 (*_bfd_error_handler
)
1686 (_("%s: can not represent section for symbol `%s' in a.out object file format"),
1687 bfd_get_filename (abfd
),
1688 cache_ptr
->name
!= NULL
? cache_ptr
->name
: _("*unknown*"));
1689 bfd_set_error (bfd_error_nonrepresentable_section
);
1693 if (sec
->output_section
!= NULL
)
1695 off
= sec
->output_offset
;
1696 sec
= sec
->output_section
;
1699 if (bfd_is_abs_section (sec
))
1700 sym_pointer
->e_type
[0] |= N_ABS
;
1701 else if (sec
== obj_textsec (abfd
))
1702 sym_pointer
->e_type
[0] |= N_TEXT
;
1703 else if (sec
== obj_datasec (abfd
))
1704 sym_pointer
->e_type
[0] |= N_DATA
;
1705 else if (sec
== obj_bsssec (abfd
))
1706 sym_pointer
->e_type
[0] |= N_BSS
;
1707 else if (bfd_is_und_section (sec
))
1708 sym_pointer
->e_type
[0] = N_UNDF
| N_EXT
;
1709 else if (bfd_is_ind_section (sec
))
1710 sym_pointer
->e_type
[0] = N_INDR
;
1711 else if (bfd_is_com_section (sec
))
1712 sym_pointer
->e_type
[0] = N_UNDF
| N_EXT
;
1715 if (aout_section_merge_with_text_p (abfd
, sec
))
1716 sym_pointer
->e_type
[0] |= N_TEXT
;
1719 (*_bfd_error_handler
)
1720 (_("%s: can not represent section `%s' in a.out object file format"),
1721 bfd_get_filename (abfd
), bfd_get_section_name (abfd
, sec
));
1722 bfd_set_error (bfd_error_nonrepresentable_section
);
1727 /* Turn the symbol from section relative to absolute again. */
1728 value
+= sec
->vma
+ off
;
1730 if ((cache_ptr
->flags
& BSF_WARNING
) != 0)
1731 sym_pointer
->e_type
[0] = N_WARNING
;
1733 if ((cache_ptr
->flags
& BSF_DEBUGGING
) != 0)
1734 sym_pointer
->e_type
[0] = ((aout_symbol_type
*) cache_ptr
)->type
;
1735 else if ((cache_ptr
->flags
& BSF_GLOBAL
) != 0)
1736 sym_pointer
->e_type
[0] |= N_EXT
;
1737 else if ((cache_ptr
->flags
& BSF_LOCAL
) != 0)
1738 sym_pointer
->e_type
[0] &= ~N_EXT
;
1740 if ((cache_ptr
->flags
& BSF_CONSTRUCTOR
) != 0)
1742 int type
= ((aout_symbol_type
*) cache_ptr
)->type
;
1746 case N_ABS
: type
= N_SETA
; break;
1747 case N_TEXT
: type
= N_SETT
; break;
1748 case N_DATA
: type
= N_SETD
; break;
1749 case N_BSS
: type
= N_SETB
; break;
1751 sym_pointer
->e_type
[0] = type
;
1754 if ((cache_ptr
->flags
& BSF_WEAK
) != 0)
1758 switch (sym_pointer
->e_type
[0] & N_TYPE
)
1761 case N_ABS
: type
= N_WEAKA
; break;
1762 case N_TEXT
: type
= N_WEAKT
; break;
1763 case N_DATA
: type
= N_WEAKD
; break;
1764 case N_BSS
: type
= N_WEAKB
; break;
1765 case N_UNDF
: type
= N_WEAKU
; break;
1767 sym_pointer
->e_type
[0] = type
;
1770 PUT_WORD (abfd
, value
, sym_pointer
->e_value
);
1775 /* Native-level interface to symbols. */
1778 NAME(aout
,make_empty_symbol
) (abfd
)
1781 bfd_size_type amt
= sizeof (aout_symbol_type
);
1782 aout_symbol_type
*new = (aout_symbol_type
*) bfd_zalloc (abfd
, amt
);
1785 new->symbol
.the_bfd
= abfd
;
1787 return &new->symbol
;
1790 /* Translate a set of internal symbols into external symbols. */
1793 NAME(aout
,translate_symbol_table
) (abfd
, in
, ext
, count
, str
, strsize
, dynamic
)
1795 aout_symbol_type
*in
;
1796 struct external_nlist
*ext
;
1797 bfd_size_type count
;
1799 bfd_size_type strsize
;
1800 bfd_boolean dynamic
;
1802 struct external_nlist
*ext_end
;
1804 ext_end
= ext
+ count
;
1805 for (; ext
< ext_end
; ext
++, in
++)
1809 x
= GET_WORD (abfd
, ext
->e_strx
);
1810 in
->symbol
.the_bfd
= abfd
;
1812 /* For the normal symbols, the zero index points at the number
1813 of bytes in the string table but is to be interpreted as the
1814 null string. For the dynamic symbols, the number of bytes in
1815 the string table is stored in the __DYNAMIC structure and the
1816 zero index points at an actual string. */
1817 if (x
== 0 && ! dynamic
)
1818 in
->symbol
.name
= "";
1819 else if (x
< strsize
)
1820 in
->symbol
.name
= str
+ x
;
1824 in
->symbol
.value
= GET_SWORD (abfd
, ext
->e_value
);
1825 in
->desc
= H_GET_16 (abfd
, ext
->e_desc
);
1826 in
->other
= H_GET_8 (abfd
, ext
->e_other
);
1827 in
->type
= H_GET_8 (abfd
, ext
->e_type
);
1828 in
->symbol
.udata
.p
= NULL
;
1830 if (! translate_from_native_sym_flags (abfd
, in
))
1834 in
->symbol
.flags
|= BSF_DYNAMIC
;
1840 /* We read the symbols into a buffer, which is discarded when this
1841 function exits. We read the strings into a buffer large enough to
1842 hold them all plus all the cached symbol entries. */
1845 NAME(aout
,slurp_symbol_table
) (abfd
)
1848 struct external_nlist
*old_external_syms
;
1849 aout_symbol_type
*cached
;
1850 bfd_size_type cached_size
;
1852 /* If there's no work to be done, don't do any. */
1853 if (obj_aout_symbols (abfd
) != (aout_symbol_type
*) NULL
)
1856 old_external_syms
= obj_aout_external_syms (abfd
);
1858 if (! aout_get_external_symbols (abfd
))
1861 cached_size
= obj_aout_external_sym_count (abfd
);
1862 cached_size
*= sizeof (aout_symbol_type
);
1863 cached
= (aout_symbol_type
*) bfd_zmalloc (cached_size
);
1864 if (cached
== NULL
&& cached_size
!= 0)
1867 /* Convert from external symbol information to internal. */
1868 if (! (NAME(aout
,translate_symbol_table
)
1870 obj_aout_external_syms (abfd
),
1871 obj_aout_external_sym_count (abfd
),
1872 obj_aout_external_strings (abfd
),
1873 obj_aout_external_string_size (abfd
),
1880 bfd_get_symcount (abfd
) = obj_aout_external_sym_count (abfd
);
1882 obj_aout_symbols (abfd
) = cached
;
1884 /* It is very likely that anybody who calls this function will not
1885 want the external symbol information, so if it was allocated
1886 because of our call to aout_get_external_symbols, we free it up
1887 right away to save space. */
1888 if (old_external_syms
== (struct external_nlist
*) NULL
1889 && obj_aout_external_syms (abfd
) != (struct external_nlist
*) NULL
)
1892 bfd_free_window (&obj_aout_sym_window (abfd
));
1894 free (obj_aout_external_syms (abfd
));
1896 obj_aout_external_syms (abfd
) = NULL
;
1902 /* We use a hash table when writing out symbols so that we only write
1903 out a particular string once. This helps particularly when the
1904 linker writes out stabs debugging entries, because each different
1905 contributing object file tends to have many duplicate stabs
1908 This hash table code breaks dbx on SunOS 4.1.3, so we don't do it
1909 if BFD_TRADITIONAL_FORMAT is set. */
1911 static bfd_size_type add_to_stringtab
1912 PARAMS ((bfd
*, struct bfd_strtab_hash
*, const char *, bfd_boolean
));
1913 static bfd_boolean emit_stringtab
1914 PARAMS ((bfd
*, struct bfd_strtab_hash
*));
1916 /* Get the index of a string in a strtab, adding it if it is not
1919 static INLINE bfd_size_type
1920 add_to_stringtab (abfd
, tab
, str
, copy
)
1922 struct bfd_strtab_hash
*tab
;
1927 bfd_size_type index
;
1929 /* An index of 0 always means the empty string. */
1930 if (str
== 0 || *str
== '\0')
1933 /* Don't hash if BFD_TRADITIONAL_FORMAT is set, because SunOS dbx
1934 doesn't understand a hashed string table. */
1936 if ((abfd
->flags
& BFD_TRADITIONAL_FORMAT
) != 0)
1939 index
= _bfd_stringtab_add (tab
, str
, hash
, copy
);
1941 if (index
!= (bfd_size_type
) -1)
1943 /* Add BYTES_IN_WORD to the return value to account for the
1944 space taken up by the string table size. */
1945 index
+= BYTES_IN_WORD
;
1951 /* Write out a strtab. ABFD is already at the right location in the
1955 emit_stringtab (abfd
, tab
)
1957 struct bfd_strtab_hash
*tab
;
1959 bfd_byte buffer
[BYTES_IN_WORD
];
1960 bfd_size_type amt
= BYTES_IN_WORD
;
1962 /* The string table starts with the size. */
1963 PUT_WORD (abfd
, _bfd_stringtab_size (tab
) + BYTES_IN_WORD
, buffer
);
1964 if (bfd_bwrite ((PTR
) buffer
, amt
, abfd
) != amt
)
1967 return _bfd_stringtab_emit (abfd
, tab
);
1971 NAME(aout
,write_syms
) (abfd
)
1974 unsigned int count
;
1975 asymbol
**generic
= bfd_get_outsymbols (abfd
);
1976 struct bfd_strtab_hash
*strtab
;
1978 strtab
= _bfd_stringtab_init ();
1982 for (count
= 0; count
< bfd_get_symcount (abfd
); count
++)
1984 asymbol
*g
= generic
[count
];
1986 struct external_nlist nsp
;
1989 indx
= add_to_stringtab (abfd
, strtab
, g
->name
, FALSE
);
1990 if (indx
== (bfd_size_type
) -1)
1992 PUT_WORD (abfd
, indx
, (bfd_byte
*) nsp
.e_strx
);
1994 if (bfd_asymbol_flavour (g
) == abfd
->xvec
->flavour
)
1996 H_PUT_16 (abfd
, aout_symbol (g
)->desc
, nsp
.e_desc
);
1997 H_PUT_8 (abfd
, aout_symbol (g
)->other
, nsp
.e_other
);
1998 H_PUT_8 (abfd
, aout_symbol (g
)->type
, nsp
.e_type
);
2002 H_PUT_16 (abfd
, 0, nsp
.e_desc
);
2003 H_PUT_8 (abfd
, 0, nsp
.e_other
);
2004 H_PUT_8 (abfd
, 0, nsp
.e_type
);
2007 if (! translate_to_native_sym_flags (abfd
, g
, &nsp
))
2010 amt
= EXTERNAL_NLIST_SIZE
;
2011 if (bfd_bwrite ((PTR
) &nsp
, amt
, abfd
) != amt
)
2014 /* NB: `KEEPIT' currently overlays `udata.p', so set this only
2015 here, at the end. */
2019 if (! emit_stringtab (abfd
, strtab
))
2022 _bfd_stringtab_free (strtab
);
2027 _bfd_stringtab_free (strtab
);
2032 NAME(aout
,canonicalize_symtab
) (abfd
, location
)
2036 unsigned int counter
= 0;
2037 aout_symbol_type
*symbase
;
2039 if (!NAME(aout
,slurp_symbol_table
) (abfd
))
2042 for (symbase
= obj_aout_symbols (abfd
);
2043 counter
++ < bfd_get_symcount (abfd
);
2045 *(location
++) = (asymbol
*) (symbase
++);
2047 return bfd_get_symcount (abfd
);
2050 /* Standard reloc stuff. */
2051 /* Output standard relocation information to a file in target byte order. */
2053 extern void NAME(aout
,swap_std_reloc_out
)
2054 PARAMS ((bfd
*, arelent
*, struct reloc_std_external
*));
2057 NAME(aout
,swap_std_reloc_out
) (abfd
, g
, natptr
)
2060 struct reloc_std_external
*natptr
;
2063 asymbol
*sym
= *(g
->sym_ptr_ptr
);
2065 unsigned int r_length
;
2067 int r_baserel
, r_jmptable
, r_relative
;
2068 asection
*output_section
= sym
->section
->output_section
;
2070 PUT_WORD (abfd
, g
->address
, natptr
->r_address
);
2072 r_length
= g
->howto
->size
; /* Size as a power of two. */
2073 r_pcrel
= (int) g
->howto
->pc_relative
; /* Relative to PC? */
2074 /* XXX This relies on relocs coming from a.out files. */
2075 r_baserel
= (g
->howto
->type
& 8) != 0;
2076 r_jmptable
= (g
->howto
->type
& 16) != 0;
2077 r_relative
= (g
->howto
->type
& 32) != 0;
2080 /* For a standard reloc, the addend is in the object file. */
2081 r_addend
= g
->addend
+ (*(g
->sym_ptr_ptr
))->section
->output_section
->vma
;
2084 /* Name was clobbered by aout_write_syms to be symbol index. */
2086 /* If this relocation is relative to a symbol then set the
2087 r_index to the symbols index, and the r_extern bit.
2089 Absolute symbols can come in in two ways, either as an offset
2090 from the abs section, or as a symbol which has an abs value.
2091 check for that here. */
2093 if (bfd_is_com_section (output_section
)
2094 || bfd_is_abs_section (output_section
)
2095 || bfd_is_und_section (output_section
))
2097 if (bfd_abs_section_ptr
->symbol
== sym
)
2099 /* Whoops, looked like an abs symbol, but is
2100 really an offset from the abs section. */
2106 /* Fill in symbol. */
2108 r_index
= (*(g
->sym_ptr_ptr
))->KEEPIT
;
2113 /* Just an ordinary section. */
2115 r_index
= output_section
->target_index
;
2118 /* Now the fun stuff. */
2119 if (bfd_header_big_endian (abfd
))
2121 natptr
->r_index
[0] = r_index
>> 16;
2122 natptr
->r_index
[1] = r_index
>> 8;
2123 natptr
->r_index
[2] = r_index
;
2124 natptr
->r_type
[0] = ((r_extern
? RELOC_STD_BITS_EXTERN_BIG
: 0)
2125 | (r_pcrel
? RELOC_STD_BITS_PCREL_BIG
: 0)
2126 | (r_baserel
? RELOC_STD_BITS_BASEREL_BIG
: 0)
2127 | (r_jmptable
? RELOC_STD_BITS_JMPTABLE_BIG
: 0)
2128 | (r_relative
? RELOC_STD_BITS_RELATIVE_BIG
: 0)
2129 | (r_length
<< RELOC_STD_BITS_LENGTH_SH_BIG
));
2133 natptr
->r_index
[2] = r_index
>> 16;
2134 natptr
->r_index
[1] = r_index
>> 8;
2135 natptr
->r_index
[0] = r_index
;
2136 natptr
->r_type
[0] = ((r_extern
? RELOC_STD_BITS_EXTERN_LITTLE
: 0)
2137 | (r_pcrel
? RELOC_STD_BITS_PCREL_LITTLE
: 0)
2138 | (r_baserel
? RELOC_STD_BITS_BASEREL_LITTLE
: 0)
2139 | (r_jmptable
? RELOC_STD_BITS_JMPTABLE_LITTLE
: 0)
2140 | (r_relative
? RELOC_STD_BITS_RELATIVE_LITTLE
: 0)
2141 | (r_length
<< RELOC_STD_BITS_LENGTH_SH_LITTLE
));
2145 /* Extended stuff. */
2146 /* Output extended relocation information to a file in target byte order. */
2148 extern void NAME(aout
,swap_ext_reloc_out
)
2149 PARAMS ((bfd
*, arelent
*, struct reloc_ext_external
*));
2152 NAME(aout
,swap_ext_reloc_out
) (abfd
, g
, natptr
)
2155 register struct reloc_ext_external
*natptr
;
2159 unsigned int r_type
;
2161 asymbol
*sym
= *(g
->sym_ptr_ptr
);
2162 asection
*output_section
= sym
->section
->output_section
;
2164 PUT_WORD (abfd
, g
->address
, natptr
->r_address
);
2166 r_type
= (unsigned int) g
->howto
->type
;
2168 r_addend
= g
->addend
;
2169 if ((sym
->flags
& BSF_SECTION_SYM
) != 0)
2170 r_addend
+= (*(g
->sym_ptr_ptr
))->section
->output_section
->vma
;
2172 /* If this relocation is relative to a symbol then set the
2173 r_index to the symbols index, and the r_extern bit.
2175 Absolute symbols can come in in two ways, either as an offset
2176 from the abs section, or as a symbol which has an abs value.
2177 check for that here. */
2178 if (bfd_is_abs_section (bfd_get_section (sym
)))
2183 else if ((sym
->flags
& BSF_SECTION_SYM
) == 0)
2185 if (bfd_is_und_section (bfd_get_section (sym
))
2186 || (sym
->flags
& BSF_GLOBAL
) != 0)
2190 r_index
= (*(g
->sym_ptr_ptr
))->KEEPIT
;
2194 /* Just an ordinary section. */
2196 r_index
= output_section
->target_index
;
2199 /* Now the fun stuff. */
2200 if (bfd_header_big_endian (abfd
))
2202 natptr
->r_index
[0] = r_index
>> 16;
2203 natptr
->r_index
[1] = r_index
>> 8;
2204 natptr
->r_index
[2] = r_index
;
2205 natptr
->r_type
[0] = ((r_extern
? RELOC_EXT_BITS_EXTERN_BIG
: 0)
2206 | (r_type
<< RELOC_EXT_BITS_TYPE_SH_BIG
));
2210 natptr
->r_index
[2] = r_index
>> 16;
2211 natptr
->r_index
[1] = r_index
>> 8;
2212 natptr
->r_index
[0] = r_index
;
2213 natptr
->r_type
[0] = ((r_extern
? RELOC_EXT_BITS_EXTERN_LITTLE
: 0)
2214 | (r_type
<< RELOC_EXT_BITS_TYPE_SH_LITTLE
));
2217 PUT_WORD (abfd
, r_addend
, natptr
->r_addend
);
2220 /* BFD deals internally with all things based from the section they're
2221 in. so, something in 10 bytes into a text section with a base of
2222 50 would have a symbol (.text+10) and know .text vma was 50.
2224 Aout keeps all it's symbols based from zero, so the symbol would
2225 contain 60. This macro subs the base of each section from the value
2226 to give the true offset from the section. */
2228 #define MOVE_ADDRESS(ad) \
2231 /* Undefined symbol. */ \
2232 cache_ptr->sym_ptr_ptr = symbols + r_index; \
2233 cache_ptr->addend = ad; \
2237 /* Defined, section relative. Replace symbol with pointer to \
2238 symbol which points to section. */ \
2242 case N_TEXT | N_EXT: \
2243 cache_ptr->sym_ptr_ptr = obj_textsec (abfd)->symbol_ptr_ptr; \
2244 cache_ptr->addend = ad - su->textsec->vma; \
2247 case N_DATA | N_EXT: \
2248 cache_ptr->sym_ptr_ptr = obj_datasec (abfd)->symbol_ptr_ptr; \
2249 cache_ptr->addend = ad - su->datasec->vma; \
2252 case N_BSS | N_EXT: \
2253 cache_ptr->sym_ptr_ptr = obj_bsssec (abfd)->symbol_ptr_ptr; \
2254 cache_ptr->addend = ad - su->bsssec->vma; \
2258 case N_ABS | N_EXT: \
2259 cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr; \
2260 cache_ptr->addend = ad; \
2266 NAME(aout
,swap_ext_reloc_in
) (abfd
, bytes
, cache_ptr
, symbols
, symcount
)
2268 struct reloc_ext_external
*bytes
;
2271 bfd_size_type symcount
;
2273 unsigned int r_index
;
2275 unsigned int r_type
;
2276 struct aoutdata
*su
= &(abfd
->tdata
.aout_data
->a
);
2278 cache_ptr
->address
= (GET_SWORD (abfd
, bytes
->r_address
));
2280 /* Now the fun stuff. */
2281 if (bfd_header_big_endian (abfd
))
2283 r_index
= (((unsigned int) bytes
->r_index
[0] << 16)
2284 | ((unsigned int) bytes
->r_index
[1] << 8)
2285 | bytes
->r_index
[2]);
2286 r_extern
= (0 != (bytes
->r_type
[0] & RELOC_EXT_BITS_EXTERN_BIG
));
2287 r_type
= ((bytes
->r_type
[0] & RELOC_EXT_BITS_TYPE_BIG
)
2288 >> RELOC_EXT_BITS_TYPE_SH_BIG
);
2292 r_index
= (((unsigned int) bytes
->r_index
[2] << 16)
2293 | ((unsigned int) bytes
->r_index
[1] << 8)
2294 | bytes
->r_index
[0]);
2295 r_extern
= (0 != (bytes
->r_type
[0] & RELOC_EXT_BITS_EXTERN_LITTLE
));
2296 r_type
= ((bytes
->r_type
[0] & RELOC_EXT_BITS_TYPE_LITTLE
)
2297 >> RELOC_EXT_BITS_TYPE_SH_LITTLE
);
2300 cache_ptr
->howto
= howto_table_ext
+ r_type
;
2302 /* Base relative relocs are always against the symbol table,
2303 regardless of the setting of r_extern. r_extern just reflects
2304 whether the symbol the reloc is against is local or global. */
2305 if (r_type
== (unsigned int) RELOC_BASE10
2306 || r_type
== (unsigned int) RELOC_BASE13
2307 || r_type
== (unsigned int) RELOC_BASE22
)
2310 if (r_extern
&& r_index
> symcount
)
2312 /* We could arrange to return an error, but it might be useful
2313 to see the file even if it is bad. */
2318 MOVE_ADDRESS (GET_SWORD (abfd
, bytes
->r_addend
));
2322 NAME(aout
,swap_std_reloc_in
) (abfd
, bytes
, cache_ptr
, symbols
, symcount
)
2324 struct reloc_std_external
*bytes
;
2327 bfd_size_type symcount
;
2329 unsigned int r_index
;
2331 unsigned int r_length
;
2333 int r_baserel
, r_jmptable
, r_relative
;
2334 struct aoutdata
*su
= &(abfd
->tdata
.aout_data
->a
);
2335 unsigned int howto_idx
;
2337 cache_ptr
->address
= H_GET_32 (abfd
, bytes
->r_address
);
2339 /* Now the fun stuff. */
2340 if (bfd_header_big_endian (abfd
))
2342 r_index
= (((unsigned int) bytes
->r_index
[0] << 16)
2343 | ((unsigned int) bytes
->r_index
[1] << 8)
2344 | bytes
->r_index
[2]);
2345 r_extern
= (0 != (bytes
->r_type
[0] & RELOC_STD_BITS_EXTERN_BIG
));
2346 r_pcrel
= (0 != (bytes
->r_type
[0] & RELOC_STD_BITS_PCREL_BIG
));
2347 r_baserel
= (0 != (bytes
->r_type
[0] & RELOC_STD_BITS_BASEREL_BIG
));
2348 r_jmptable
= (0 != (bytes
->r_type
[0] & RELOC_STD_BITS_JMPTABLE_BIG
));
2349 r_relative
= (0 != (bytes
->r_type
[0] & RELOC_STD_BITS_RELATIVE_BIG
));
2350 r_length
= ((bytes
->r_type
[0] & RELOC_STD_BITS_LENGTH_BIG
)
2351 >> RELOC_STD_BITS_LENGTH_SH_BIG
);
2355 r_index
= (((unsigned int) bytes
->r_index
[2] << 16)
2356 | ((unsigned int) bytes
->r_index
[1] << 8)
2357 | bytes
->r_index
[0]);
2358 r_extern
= (0 != (bytes
->r_type
[0] & RELOC_STD_BITS_EXTERN_LITTLE
));
2359 r_pcrel
= (0 != (bytes
->r_type
[0] & RELOC_STD_BITS_PCREL_LITTLE
));
2360 r_baserel
= (0 != (bytes
->r_type
[0] & RELOC_STD_BITS_BASEREL_LITTLE
));
2361 r_jmptable
= (0 != (bytes
->r_type
[0] & RELOC_STD_BITS_JMPTABLE_LITTLE
));
2362 r_relative
= (0 != (bytes
->r_type
[0] & RELOC_STD_BITS_RELATIVE_LITTLE
));
2363 r_length
= ((bytes
->r_type
[0] & RELOC_STD_BITS_LENGTH_LITTLE
)
2364 >> RELOC_STD_BITS_LENGTH_SH_LITTLE
);
2367 howto_idx
= (r_length
+ 4 * r_pcrel
+ 8 * r_baserel
2368 + 16 * r_jmptable
+ 32 * r_relative
);
2369 BFD_ASSERT (howto_idx
< TABLE_SIZE (howto_table_std
));
2370 cache_ptr
->howto
= howto_table_std
+ howto_idx
;
2371 BFD_ASSERT (cache_ptr
->howto
->type
!= (unsigned int) -1);
2373 /* Base relative relocs are always against the symbol table,
2374 regardless of the setting of r_extern. r_extern just reflects
2375 whether the symbol the reloc is against is local or global. */
2379 if (r_extern
&& r_index
> symcount
)
2381 /* We could arrange to return an error, but it might be useful
2382 to see the file even if it is bad. */
2390 /* Read and swap the relocs for a section. */
2393 NAME(aout
,slurp_reloc_table
) (abfd
, asect
, symbols
)
2398 bfd_size_type count
;
2399 bfd_size_type reloc_size
;
2401 arelent
*reloc_cache
;
2403 unsigned int counter
= 0;
2407 if (asect
->relocation
)
2410 if (asect
->flags
& SEC_CONSTRUCTOR
)
2413 if (asect
== obj_datasec (abfd
))
2414 reloc_size
= exec_hdr (abfd
)->a_drsize
;
2415 else if (asect
== obj_textsec (abfd
))
2416 reloc_size
= exec_hdr (abfd
)->a_trsize
;
2417 else if (asect
== obj_bsssec (abfd
))
2421 bfd_set_error (bfd_error_invalid_operation
);
2425 if (bfd_seek (abfd
, asect
->rel_filepos
, SEEK_SET
) != 0)
2428 each_size
= obj_reloc_entry_size (abfd
);
2430 count
= reloc_size
/ each_size
;
2432 amt
= count
* sizeof (arelent
);
2433 reloc_cache
= (arelent
*) bfd_zmalloc (amt
);
2434 if (reloc_cache
== NULL
&& count
!= 0)
2437 relocs
= bfd_malloc (reloc_size
);
2438 if (relocs
== NULL
&& reloc_size
!= 0)
2444 if (bfd_bread (relocs
, reloc_size
, abfd
) != reloc_size
)
2451 cache_ptr
= reloc_cache
;
2452 if (each_size
== RELOC_EXT_SIZE
)
2454 struct reloc_ext_external
*rptr
= (struct reloc_ext_external
*) relocs
;
2456 for (; counter
< count
; counter
++, rptr
++, cache_ptr
++)
2457 MY_swap_ext_reloc_in (abfd
, rptr
, cache_ptr
, symbols
,
2458 (bfd_size_type
) bfd_get_symcount (abfd
));
2462 struct reloc_std_external
*rptr
= (struct reloc_std_external
*) relocs
;
2464 for (; counter
< count
; counter
++, rptr
++, cache_ptr
++)
2465 MY_swap_std_reloc_in (abfd
, rptr
, cache_ptr
, symbols
,
2466 (bfd_size_type
) bfd_get_symcount (abfd
));
2471 asect
->relocation
= reloc_cache
;
2472 asect
->reloc_count
= cache_ptr
- reloc_cache
;
2477 /* Write out a relocation section into an object file. */
2480 NAME(aout
,squirt_out_relocs
) (abfd
, section
)
2485 unsigned char *native
, *natptr
;
2488 unsigned int count
= section
->reloc_count
;
2489 bfd_size_type natsize
;
2491 if (count
== 0 || section
->orelocation
== NULL
)
2494 each_size
= obj_reloc_entry_size (abfd
);
2495 natsize
= (bfd_size_type
) each_size
* count
;
2496 native
= (unsigned char *) bfd_zalloc (abfd
, natsize
);
2500 generic
= section
->orelocation
;
2502 if (each_size
== RELOC_EXT_SIZE
)
2504 for (natptr
= native
;
2506 --count
, natptr
+= each_size
, ++generic
)
2507 MY_swap_ext_reloc_out (abfd
, *generic
,
2508 (struct reloc_ext_external
*) natptr
);
2512 for (natptr
= native
;
2514 --count
, natptr
+= each_size
, ++generic
)
2515 MY_swap_std_reloc_out (abfd
, *generic
,
2516 (struct reloc_std_external
*) natptr
);
2519 if (bfd_bwrite ((PTR
) native
, natsize
, abfd
) != natsize
)
2521 bfd_release (abfd
, native
);
2524 bfd_release (abfd
, native
);
2529 /* This is stupid. This function should be a boolean predicate. */
2532 NAME(aout
,canonicalize_reloc
) (abfd
, section
, relptr
, symbols
)
2538 arelent
*tblptr
= section
->relocation
;
2541 if (section
== obj_bsssec (abfd
))
2547 if (!(tblptr
|| NAME(aout
,slurp_reloc_table
) (abfd
, section
, symbols
)))
2550 if (section
->flags
& SEC_CONSTRUCTOR
)
2552 arelent_chain
*chain
= section
->constructor_chain
;
2553 for (count
= 0; count
< section
->reloc_count
; count
++)
2555 *relptr
++ = &chain
->relent
;
2556 chain
= chain
->next
;
2561 tblptr
= section
->relocation
;
2563 for (count
= 0; count
++ < section
->reloc_count
; )
2565 *relptr
++ = tblptr
++;
2570 return section
->reloc_count
;
2574 NAME(aout
,get_reloc_upper_bound
) (abfd
, asect
)
2578 if (bfd_get_format (abfd
) != bfd_object
)
2580 bfd_set_error (bfd_error_invalid_operation
);
2584 if (asect
->flags
& SEC_CONSTRUCTOR
)
2585 return (sizeof (arelent
*) * (asect
->reloc_count
+1));
2587 if (asect
== obj_datasec (abfd
))
2588 return (sizeof (arelent
*)
2589 * ((exec_hdr (abfd
)->a_drsize
/ obj_reloc_entry_size (abfd
))
2592 if (asect
== obj_textsec (abfd
))
2593 return (sizeof (arelent
*)
2594 * ((exec_hdr (abfd
)->a_trsize
/ obj_reloc_entry_size (abfd
))
2597 if (asect
== obj_bsssec (abfd
))
2598 return sizeof (arelent
*);
2600 if (asect
== obj_bsssec (abfd
))
2603 bfd_set_error (bfd_error_invalid_operation
);
2608 NAME(aout
,get_symtab_upper_bound
) (abfd
)
2611 if (!NAME(aout
,slurp_symbol_table
) (abfd
))
2614 return (bfd_get_symcount (abfd
)+1) * (sizeof (aout_symbol_type
*));
2618 NAME(aout
,get_lineno
) (ignore_abfd
, ignore_symbol
)
2619 bfd
*ignore_abfd ATTRIBUTE_UNUSED
;
2620 asymbol
*ignore_symbol ATTRIBUTE_UNUSED
;
2622 return (alent
*)NULL
;
2626 NAME(aout
,get_symbol_info
) (ignore_abfd
, symbol
, ret
)
2627 bfd
*ignore_abfd ATTRIBUTE_UNUSED
;
2631 bfd_symbol_info (symbol
, ret
);
2633 if (ret
->type
== '?')
2635 int type_code
= aout_symbol (symbol
)->type
& 0xff;
2636 const char *stab_name
= bfd_get_stab_name (type_code
);
2637 static char buf
[10];
2639 if (stab_name
== NULL
)
2641 sprintf (buf
, "(%d)", type_code
);
2645 ret
->stab_type
= type_code
;
2646 ret
->stab_other
= (unsigned) (aout_symbol (symbol
)->other
& 0xff);
2647 ret
->stab_desc
= (unsigned) (aout_symbol (symbol
)->desc
& 0xffff);
2648 ret
->stab_name
= stab_name
;
2653 NAME(aout
,print_symbol
) (abfd
, afile
, symbol
, how
)
2657 bfd_print_symbol_type how
;
2659 FILE *file
= (FILE *)afile
;
2663 case bfd_print_symbol_name
:
2665 fprintf (file
,"%s", symbol
->name
);
2667 case bfd_print_symbol_more
:
2668 fprintf (file
,"%4x %2x %2x",
2669 (unsigned) (aout_symbol (symbol
)->desc
& 0xffff),
2670 (unsigned) (aout_symbol (symbol
)->other
& 0xff),
2671 (unsigned) (aout_symbol (symbol
)->type
));
2673 case bfd_print_symbol_all
:
2675 const char *section_name
= symbol
->section
->name
;
2677 bfd_print_symbol_vandf (abfd
, (PTR
)file
, symbol
);
2679 fprintf (file
," %-5s %04x %02x %02x",
2681 (unsigned) (aout_symbol (symbol
)->desc
& 0xffff),
2682 (unsigned) (aout_symbol (symbol
)->other
& 0xff),
2683 (unsigned) (aout_symbol (symbol
)->type
& 0xff));
2685 fprintf (file
," %s", symbol
->name
);
2691 /* If we don't have to allocate more than 1MB to hold the generic
2692 symbols, we use the generic minisymbol methord: it's faster, since
2693 it only translates the symbols once, not multiple times. */
2694 #define MINISYM_THRESHOLD (1000000 / sizeof (asymbol))
2696 /* Read minisymbols. For minisymbols, we use the unmodified a.out
2697 symbols. The minisymbol_to_symbol function translates these into
2698 BFD asymbol structures. */
2701 NAME(aout
,read_minisymbols
) (abfd
, dynamic
, minisymsp
, sizep
)
2703 bfd_boolean dynamic
;
2705 unsigned int *sizep
;
2709 /* We could handle the dynamic symbols here as well, but it's
2710 easier to hand them off. */
2711 return _bfd_generic_read_minisymbols (abfd
, dynamic
, minisymsp
, sizep
);
2714 if (! aout_get_external_symbols (abfd
))
2717 if (obj_aout_external_sym_count (abfd
) < MINISYM_THRESHOLD
)
2718 return _bfd_generic_read_minisymbols (abfd
, dynamic
, minisymsp
, sizep
);
2720 *minisymsp
= (PTR
) obj_aout_external_syms (abfd
);
2722 /* By passing the external symbols back from this routine, we are
2723 giving up control over the memory block. Clear
2724 obj_aout_external_syms, so that we do not try to free it
2726 obj_aout_external_syms (abfd
) = NULL
;
2728 *sizep
= EXTERNAL_NLIST_SIZE
;
2729 return obj_aout_external_sym_count (abfd
);
2732 /* Convert a minisymbol to a BFD asymbol. A minisymbol is just an
2733 unmodified a.out symbol. The SYM argument is a structure returned
2734 by bfd_make_empty_symbol, which we fill in here. */
2737 NAME(aout
,minisymbol_to_symbol
) (abfd
, dynamic
, minisym
, sym
)
2739 bfd_boolean dynamic
;
2744 || obj_aout_external_sym_count (abfd
) < MINISYM_THRESHOLD
)
2745 return _bfd_generic_minisymbol_to_symbol (abfd
, dynamic
, minisym
, sym
);
2747 memset (sym
, 0, sizeof (aout_symbol_type
));
2749 /* We call translate_symbol_table to translate a single symbol. */
2750 if (! (NAME(aout
,translate_symbol_table
)
2752 (aout_symbol_type
*) sym
,
2753 (struct external_nlist
*) minisym
,
2755 obj_aout_external_strings (abfd
),
2756 obj_aout_external_string_size (abfd
),
2763 /* Provided a BFD, a section and an offset into the section, calculate
2764 and return the name of the source file and the line nearest to the
2768 NAME(aout
,find_nearest_line
)
2769 (abfd
, section
, symbols
, offset
, filename_ptr
, functionname_ptr
, line_ptr
)
2774 const char **filename_ptr
;
2775 const char **functionname_ptr
;
2776 unsigned int *line_ptr
;
2778 /* Run down the file looking for the filename, function and linenumber. */
2780 const char *directory_name
= NULL
;
2781 const char *main_file_name
= NULL
;
2782 const char *current_file_name
= NULL
;
2783 const char *line_file_name
= NULL
; /* Value of current_file_name at line number. */
2784 const char *line_directory_name
= NULL
; /* Value of directory_name at line number. */
2785 bfd_vma low_line_vma
= 0;
2786 bfd_vma low_func_vma
= 0;
2788 bfd_size_type filelen
, funclen
;
2791 *filename_ptr
= abfd
->filename
;
2792 *functionname_ptr
= 0;
2795 if (symbols
!= (asymbol
**)NULL
)
2797 for (p
= symbols
; *p
; p
++)
2799 aout_symbol_type
*q
= (aout_symbol_type
*) (*p
);
2804 /* If this looks like a file name symbol, and it comes after
2805 the line number we have found so far, but before the
2806 offset, then we have probably not found the right line
2808 if (q
->symbol
.value
<= offset
2809 && ((q
->symbol
.value
> low_line_vma
2810 && (line_file_name
!= NULL
2812 || (q
->symbol
.value
> low_func_vma
2815 const char *symname
;
2817 symname
= q
->symbol
.name
;
2818 if (strcmp (symname
+ strlen (symname
) - 2, ".o") == 0)
2820 if (q
->symbol
.value
> low_line_vma
)
2823 line_file_name
= NULL
;
2825 if (q
->symbol
.value
> low_func_vma
)
2832 /* If this symbol is less than the offset, but greater than
2833 the line number we have found so far, then we have not
2834 found the right line number. */
2835 if (q
->symbol
.value
<= offset
)
2837 if (q
->symbol
.value
> low_line_vma
)
2840 line_file_name
= NULL
;
2842 if (q
->symbol
.value
> low_func_vma
)
2846 main_file_name
= current_file_name
= q
->symbol
.name
;
2847 /* Look ahead to next symbol to check if that too is an N_SO. */
2851 q
= (aout_symbol_type
*) (*p
);
2852 if (q
->type
!= (int)N_SO
)
2855 /* Found a second N_SO First is directory; second is filename. */
2856 directory_name
= current_file_name
;
2857 main_file_name
= current_file_name
= q
->symbol
.name
;
2858 if (obj_textsec (abfd
) != section
)
2862 current_file_name
= q
->symbol
.name
;
2869 /* We'll keep this if it resolves nearer than the one we have
2871 if (q
->symbol
.value
>= low_line_vma
2872 && q
->symbol
.value
<= offset
)
2874 *line_ptr
= q
->desc
;
2875 low_line_vma
= q
->symbol
.value
;
2876 line_file_name
= current_file_name
;
2877 line_directory_name
= directory_name
;
2882 /* We'll keep this if it is nearer than the one we have already. */
2883 if (q
->symbol
.value
>= low_func_vma
&&
2884 q
->symbol
.value
<= offset
)
2886 low_func_vma
= q
->symbol
.value
;
2887 func
= (asymbol
*)q
;
2889 else if (q
->symbol
.value
> offset
)
2900 main_file_name
= line_file_name
;
2901 directory_name
= line_directory_name
;
2904 if (main_file_name
== NULL
2905 || IS_ABSOLUTE_PATH (main_file_name
)
2906 || directory_name
== NULL
)
2909 filelen
= strlen (directory_name
) + strlen (main_file_name
);
2914 funclen
= strlen (bfd_asymbol_name (func
));
2916 if (adata (abfd
).line_buf
!= NULL
)
2917 free (adata (abfd
).line_buf
);
2919 if (filelen
+ funclen
== 0)
2920 adata (abfd
).line_buf
= buf
= NULL
;
2923 buf
= (char *) bfd_malloc (filelen
+ funclen
+ 3);
2924 adata (abfd
).line_buf
= buf
;
2929 if (main_file_name
!= NULL
)
2931 if (IS_ABSOLUTE_PATH (main_file_name
) || directory_name
== NULL
)
2932 *filename_ptr
= main_file_name
;
2935 sprintf (buf
, "%s%s", directory_name
, main_file_name
);
2936 *filename_ptr
= buf
;
2943 const char *function
= func
->name
;
2946 /* The caller expects a symbol name. We actually have a
2947 function name, without the leading underscore. Put the
2948 underscore back in, so that the caller gets a symbol name. */
2949 if (bfd_get_symbol_leading_char (abfd
) == '\0')
2950 strcpy (buf
, function
);
2953 buf
[0] = bfd_get_symbol_leading_char (abfd
);
2954 strcpy (buf
+ 1, function
);
2956 /* Have to remove : stuff. */
2957 colon
= strchr (buf
, ':');
2960 *functionname_ptr
= buf
;
2967 NAME(aout
,sizeof_headers
) (abfd
, execable
)
2969 bfd_boolean execable ATTRIBUTE_UNUSED
;
2971 return adata (abfd
).exec_bytes_size
;
2974 /* Free all information we have cached for this BFD. We can always
2975 read it again later if we need it. */
2978 NAME(aout
,bfd_free_cached_info
) (abfd
)
2983 if (bfd_get_format (abfd
) != bfd_object
2984 || abfd
->tdata
.aout_data
== NULL
)
2987 #define BFCI_FREE(x) if (x != NULL) { free (x); x = NULL; }
2988 BFCI_FREE (obj_aout_symbols (abfd
));
2990 obj_aout_external_syms (abfd
) = 0;
2991 bfd_free_window (&obj_aout_sym_window (abfd
));
2992 bfd_free_window (&obj_aout_string_window (abfd
));
2993 obj_aout_external_strings (abfd
) = 0;
2995 BFCI_FREE (obj_aout_external_syms (abfd
));
2996 BFCI_FREE (obj_aout_external_strings (abfd
));
2998 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
2999 BFCI_FREE (o
->relocation
);
3005 /* a.out link code. */
3007 static bfd_boolean aout_link_add_object_symbols
3008 PARAMS ((bfd
*, struct bfd_link_info
*));
3009 static bfd_boolean aout_link_check_archive_element
3010 PARAMS ((bfd
*, struct bfd_link_info
*, bfd_boolean
*));
3011 static bfd_boolean aout_link_free_symbols
3013 static bfd_boolean aout_link_check_ar_symbols
3014 PARAMS ((bfd
*, struct bfd_link_info
*, bfd_boolean
*pneeded
));
3015 static bfd_boolean aout_link_add_symbols
3016 PARAMS ((bfd
*, struct bfd_link_info
*));
3018 /* Routine to create an entry in an a.out link hash table. */
3020 struct bfd_hash_entry
*
3021 NAME(aout
,link_hash_newfunc
) (entry
, table
, string
)
3022 struct bfd_hash_entry
*entry
;
3023 struct bfd_hash_table
*table
;
3026 struct aout_link_hash_entry
*ret
= (struct aout_link_hash_entry
*) entry
;
3028 /* Allocate the structure if it has not already been allocated by a
3030 if (ret
== (struct aout_link_hash_entry
*) NULL
)
3031 ret
= ((struct aout_link_hash_entry
*)
3032 bfd_hash_allocate (table
, sizeof (struct aout_link_hash_entry
)));
3033 if (ret
== (struct aout_link_hash_entry
*) NULL
)
3034 return (struct bfd_hash_entry
*) ret
;
3036 /* Call the allocation method of the superclass. */
3037 ret
= ((struct aout_link_hash_entry
*)
3038 _bfd_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
3042 /* Set local fields. */
3043 ret
->written
= FALSE
;
3047 return (struct bfd_hash_entry
*) ret
;
3050 /* Initialize an a.out link hash table. */
3053 NAME(aout
,link_hash_table_init
) (table
, abfd
, newfunc
)
3054 struct aout_link_hash_table
*table
;
3056 struct bfd_hash_entry
*(*newfunc
)
3057 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*,
3060 return _bfd_link_hash_table_init (&table
->root
, abfd
, newfunc
);
3063 /* Create an a.out link hash table. */
3065 struct bfd_link_hash_table
*
3066 NAME(aout
,link_hash_table_create
) (abfd
)
3069 struct aout_link_hash_table
*ret
;
3070 bfd_size_type amt
= sizeof (struct aout_link_hash_table
);
3072 ret
= (struct aout_link_hash_table
*) bfd_malloc (amt
);
3074 return (struct bfd_link_hash_table
*) NULL
;
3076 if (! NAME(aout
,link_hash_table_init
) (ret
, abfd
,
3077 NAME(aout
,link_hash_newfunc
)))
3080 return (struct bfd_link_hash_table
*) NULL
;
3085 /* Given an a.out BFD, add symbols to the global hash table as
3089 NAME(aout
,link_add_symbols
) (abfd
, info
)
3091 struct bfd_link_info
*info
;
3093 switch (bfd_get_format (abfd
))
3096 return aout_link_add_object_symbols (abfd
, info
);
3098 return _bfd_generic_link_add_archive_symbols
3099 (abfd
, info
, aout_link_check_archive_element
);
3101 bfd_set_error (bfd_error_wrong_format
);
3106 /* Add symbols from an a.out object file. */
3109 aout_link_add_object_symbols (abfd
, info
)
3111 struct bfd_link_info
*info
;
3113 if (! aout_get_external_symbols (abfd
))
3115 if (! aout_link_add_symbols (abfd
, info
))
3117 if (! info
->keep_memory
)
3119 if (! aout_link_free_symbols (abfd
))
3125 /* Check a single archive element to see if we need to include it in
3126 the link. *PNEEDED is set according to whether this element is
3127 needed in the link or not. This is called from
3128 _bfd_generic_link_add_archive_symbols. */
3131 aout_link_check_archive_element (abfd
, info
, pneeded
)
3133 struct bfd_link_info
*info
;
3134 bfd_boolean
*pneeded
;
3136 if (! aout_get_external_symbols (abfd
))
3139 if (! aout_link_check_ar_symbols (abfd
, info
, pneeded
))
3144 if (! aout_link_add_symbols (abfd
, info
))
3148 if (! info
->keep_memory
|| ! *pneeded
)
3150 if (! aout_link_free_symbols (abfd
))
3157 /* Free up the internal symbols read from an a.out file. */
3160 aout_link_free_symbols (abfd
)
3163 if (obj_aout_external_syms (abfd
) != (struct external_nlist
*) NULL
)
3166 bfd_free_window (&obj_aout_sym_window (abfd
));
3168 free ((PTR
) obj_aout_external_syms (abfd
));
3170 obj_aout_external_syms (abfd
) = (struct external_nlist
*) NULL
;
3172 if (obj_aout_external_strings (abfd
) != (char *) NULL
)
3175 bfd_free_window (&obj_aout_string_window (abfd
));
3177 free ((PTR
) obj_aout_external_strings (abfd
));
3179 obj_aout_external_strings (abfd
) = (char *) NULL
;
3184 /* Look through the internal symbols to see if this object file should
3185 be included in the link. We should include this object file if it
3186 defines any symbols which are currently undefined. If this object
3187 file defines a common symbol, then we may adjust the size of the
3188 known symbol but we do not include the object file in the link
3189 (unless there is some other reason to include it). */
3192 aout_link_check_ar_symbols (abfd
, info
, pneeded
)
3194 struct bfd_link_info
*info
;
3195 bfd_boolean
*pneeded
;
3197 register struct external_nlist
*p
;
3198 struct external_nlist
*pend
;
3203 /* Look through all the symbols. */
3204 p
= obj_aout_external_syms (abfd
);
3205 pend
= p
+ obj_aout_external_sym_count (abfd
);
3206 strings
= obj_aout_external_strings (abfd
);
3207 for (; p
< pend
; p
++)
3209 int type
= H_GET_8 (abfd
, p
->e_type
);
3211 struct bfd_link_hash_entry
*h
;
3213 /* Ignore symbols that are not externally visible. This is an
3214 optimization only, as we check the type more thoroughly
3216 if (((type
& N_EXT
) == 0
3217 || (type
& N_STAB
) != 0
3224 if (type
== N_WARNING
3230 name
= strings
+ GET_WORD (abfd
, p
->e_strx
);
3231 h
= bfd_link_hash_lookup (info
->hash
, name
, FALSE
, FALSE
, TRUE
);
3233 /* We are only interested in symbols that are currently
3234 undefined or common. */
3235 if (h
== (struct bfd_link_hash_entry
*) NULL
3236 || (h
->type
!= bfd_link_hash_undefined
3237 && h
->type
!= bfd_link_hash_common
))
3239 if (type
== (N_INDR
| N_EXT
))
3244 if (type
== (N_TEXT
| N_EXT
)
3245 || type
== (N_DATA
| N_EXT
)
3246 || type
== (N_BSS
| N_EXT
)
3247 || type
== (N_ABS
| N_EXT
)
3248 || type
== (N_INDR
| N_EXT
))
3250 /* This object file defines this symbol. We must link it
3251 in. This is true regardless of whether the current
3252 definition of the symbol is undefined or common.
3254 If the current definition is common, we have a case in
3255 which we have already seen an object file including:
3257 and this object file from the archive includes:
3259 In such a case, whether to include this object is target
3260 dependant for backward compatibility.
3262 FIXME: The SunOS 4.1.3 linker will pull in the archive
3263 element if the symbol is defined in the .data section,
3264 but not if it is defined in the .text section. That
3265 seems a bit crazy to me, and it has not been implemented
3266 yet. However, it might be correct. */
3267 if (h
->type
== bfd_link_hash_common
)
3271 switch (info
->common_skip_ar_aymbols
)
3273 case bfd_link_common_skip_text
:
3274 skip
= (type
== (N_TEXT
| N_EXT
));
3276 case bfd_link_common_skip_data
:
3277 skip
= (type
== (N_DATA
| N_EXT
));
3280 case bfd_link_common_skip_all
:
3289 if (! (*info
->callbacks
->add_archive_element
) (info
, abfd
, name
))
3295 if (type
== (N_UNDF
| N_EXT
))
3299 value
= GET_WORD (abfd
, p
->e_value
);
3302 /* This symbol is common in the object from the archive
3304 if (h
->type
== bfd_link_hash_undefined
)
3309 symbfd
= h
->u
.undef
.abfd
;
3310 if (symbfd
== (bfd
*) NULL
)
3312 /* This symbol was created as undefined from
3313 outside BFD. We assume that we should link
3314 in the object file. This is done for the -u
3315 option in the linker. */
3316 if (! (*info
->callbacks
->add_archive_element
) (info
,
3323 /* Turn the current link symbol into a common
3324 symbol. It is already on the undefs list. */
3325 h
->type
= bfd_link_hash_common
;
3326 h
->u
.c
.p
= ((struct bfd_link_hash_common_entry
*)
3327 bfd_hash_allocate (&info
->hash
->table
,
3328 sizeof (struct bfd_link_hash_common_entry
)));
3329 if (h
->u
.c
.p
== NULL
)
3332 h
->u
.c
.size
= value
;
3334 /* FIXME: This isn't quite right. The maximum
3335 alignment of a common symbol should be set by the
3336 architecture of the output file, not of the input
3338 power
= bfd_log2 (value
);
3339 if (power
> bfd_get_arch_info (abfd
)->section_align_power
)
3340 power
= bfd_get_arch_info (abfd
)->section_align_power
;
3341 h
->u
.c
.p
->alignment_power
= power
;
3343 h
->u
.c
.p
->section
= bfd_make_section_old_way (symbfd
,
3348 /* Adjust the size of the common symbol if
3350 if (value
> h
->u
.c
.size
)
3351 h
->u
.c
.size
= value
;
3361 /* This symbol is weak but defined. We must pull it in if
3362 the current link symbol is undefined, but we don't want
3363 it if the current link symbol is common. */
3364 if (h
->type
== bfd_link_hash_undefined
)
3366 if (! (*info
->callbacks
->add_archive_element
) (info
, abfd
, name
))
3374 /* We do not need this object file. */
3378 /* Add all symbols from an object file to the hash table. */
3381 aout_link_add_symbols (abfd
, info
)
3383 struct bfd_link_info
*info
;
3385 bfd_boolean (*add_one_symbol
)
3386 PARAMS ((struct bfd_link_info
*, bfd
*, const char *, flagword
, asection
*,
3387 bfd_vma
, const char *, bfd_boolean
, bfd_boolean
,
3388 struct bfd_link_hash_entry
**));
3389 struct external_nlist
*syms
;
3390 bfd_size_type sym_count
;
3393 struct aout_link_hash_entry
**sym_hash
;
3394 register struct external_nlist
*p
;
3395 struct external_nlist
*pend
;
3398 syms
= obj_aout_external_syms (abfd
);
3399 sym_count
= obj_aout_external_sym_count (abfd
);
3400 strings
= obj_aout_external_strings (abfd
);
3401 if (info
->keep_memory
)
3406 if (aout_backend_info (abfd
)->add_dynamic_symbols
!= NULL
)
3408 if (! ((*aout_backend_info (abfd
)->add_dynamic_symbols
)
3409 (abfd
, info
, &syms
, &sym_count
, &strings
)))
3413 /* We keep a list of the linker hash table entries that correspond
3414 to particular symbols. We could just look them up in the hash
3415 table, but keeping the list is more efficient. Perhaps this
3416 should be conditional on info->keep_memory. */
3417 amt
= sym_count
* sizeof (struct aout_link_hash_entry
*);
3418 sym_hash
= (struct aout_link_hash_entry
**) bfd_alloc (abfd
, amt
);
3419 if (sym_hash
== NULL
&& sym_count
!= 0)
3421 obj_aout_sym_hashes (abfd
) = sym_hash
;
3423 add_one_symbol
= aout_backend_info (abfd
)->add_one_symbol
;
3424 if (add_one_symbol
== NULL
)
3425 add_one_symbol
= _bfd_generic_link_add_one_symbol
;
3428 pend
= p
+ sym_count
;
3429 for (; p
< pend
; p
++, sym_hash
++)
3440 type
= H_GET_8 (abfd
, p
->e_type
);
3442 /* Ignore debugging symbols. */
3443 if ((type
& N_STAB
) != 0)
3446 name
= strings
+ GET_WORD (abfd
, p
->e_strx
);
3447 value
= GET_WORD (abfd
, p
->e_value
);
3464 /* Ignore symbols that are not externally visible. */
3467 /* Ignore local indirect symbol. */
3472 case N_UNDF
| N_EXT
:
3475 section
= bfd_und_section_ptr
;
3479 section
= bfd_com_section_ptr
;
3482 section
= bfd_abs_section_ptr
;
3484 case N_TEXT
| N_EXT
:
3485 section
= obj_textsec (abfd
);
3486 value
-= bfd_get_section_vma (abfd
, section
);
3488 case N_DATA
| N_EXT
:
3489 case N_SETV
| N_EXT
:
3490 /* Treat N_SETV symbols as N_DATA symbol; see comment in
3491 translate_from_native_sym_flags. */
3492 section
= obj_datasec (abfd
);
3493 value
-= bfd_get_section_vma (abfd
, section
);
3496 section
= obj_bsssec (abfd
);
3497 value
-= bfd_get_section_vma (abfd
, section
);
3499 case N_INDR
| N_EXT
:
3500 /* An indirect symbol. The next symbol is the symbol
3501 which this one really is. */
3502 BFD_ASSERT (p
+ 1 < pend
);
3504 string
= strings
+ GET_WORD (abfd
, p
->e_strx
);
3505 section
= bfd_ind_section_ptr
;
3506 flags
|= BSF_INDIRECT
;
3508 case N_COMM
| N_EXT
:
3509 section
= bfd_com_section_ptr
;
3511 case N_SETA
: case N_SETA
| N_EXT
:
3512 section
= bfd_abs_section_ptr
;
3513 flags
|= BSF_CONSTRUCTOR
;
3515 case N_SETT
: case N_SETT
| N_EXT
:
3516 section
= obj_textsec (abfd
);
3517 flags
|= BSF_CONSTRUCTOR
;
3518 value
-= bfd_get_section_vma (abfd
, section
);
3520 case N_SETD
: case N_SETD
| N_EXT
:
3521 section
= obj_datasec (abfd
);
3522 flags
|= BSF_CONSTRUCTOR
;
3523 value
-= bfd_get_section_vma (abfd
, section
);
3525 case N_SETB
: case N_SETB
| N_EXT
:
3526 section
= obj_bsssec (abfd
);
3527 flags
|= BSF_CONSTRUCTOR
;
3528 value
-= bfd_get_section_vma (abfd
, section
);
3531 /* A warning symbol. The next symbol is the one to warn
3533 BFD_ASSERT (p
+ 1 < pend
);
3536 name
= strings
+ GET_WORD (abfd
, p
->e_strx
);
3537 section
= bfd_und_section_ptr
;
3538 flags
|= BSF_WARNING
;
3541 section
= bfd_und_section_ptr
;
3545 section
= bfd_abs_section_ptr
;
3549 section
= obj_textsec (abfd
);
3550 value
-= bfd_get_section_vma (abfd
, section
);
3554 section
= obj_datasec (abfd
);
3555 value
-= bfd_get_section_vma (abfd
, section
);
3559 section
= obj_bsssec (abfd
);
3560 value
-= bfd_get_section_vma (abfd
, section
);
3565 if (! ((*add_one_symbol
)
3566 (info
, abfd
, name
, flags
, section
, value
, string
, copy
, FALSE
,
3567 (struct bfd_link_hash_entry
**) sym_hash
)))
3570 /* Restrict the maximum alignment of a common symbol based on
3571 the architecture, since a.out has no way to represent
3572 alignment requirements of a section in a .o file. FIXME:
3573 This isn't quite right: it should use the architecture of the
3574 output file, not the input files. */
3575 if ((*sym_hash
)->root
.type
== bfd_link_hash_common
3576 && ((*sym_hash
)->root
.u
.c
.p
->alignment_power
>
3577 bfd_get_arch_info (abfd
)->section_align_power
))
3578 (*sym_hash
)->root
.u
.c
.p
->alignment_power
=
3579 bfd_get_arch_info (abfd
)->section_align_power
;
3581 /* If this is a set symbol, and we are not building sets, then
3582 it is possible for the hash entry to not have been set. In
3583 such a case, treat the symbol as not globally defined. */
3584 if ((*sym_hash
)->root
.type
== bfd_link_hash_new
)
3586 BFD_ASSERT ((flags
& BSF_CONSTRUCTOR
) != 0);
3590 if (type
== (N_INDR
| N_EXT
) || type
== N_WARNING
)
3597 /* A hash table used for header files with N_BINCL entries. */
3599 struct aout_link_includes_table
3601 struct bfd_hash_table root
;
3604 /* A linked list of totals that we have found for a particular header
3607 struct aout_link_includes_totals
3609 struct aout_link_includes_totals
*next
;
3613 /* An entry in the header file hash table. */
3615 struct aout_link_includes_entry
3617 struct bfd_hash_entry root
;
3618 /* List of totals we have found for this file. */
3619 struct aout_link_includes_totals
*totals
;
3622 /* Look up an entry in an the header file hash table. */
3624 #define aout_link_includes_lookup(table, string, create, copy) \
3625 ((struct aout_link_includes_entry *) \
3626 bfd_hash_lookup (&(table)->root, (string), (create), (copy)))
3628 /* During the final link step we need to pass around a bunch of
3629 information, so we do it in an instance of this structure. */
3631 struct aout_final_link_info
3633 /* General link information. */
3634 struct bfd_link_info
*info
;
3637 /* Reloc file positions. */
3638 file_ptr treloff
, dreloff
;
3639 /* File position of symbols. */
3642 struct bfd_strtab_hash
*strtab
;
3643 /* Header file hash table. */
3644 struct aout_link_includes_table includes
;
3645 /* A buffer large enough to hold the contents of any section. */
3647 /* A buffer large enough to hold the relocs of any section. */
3649 /* A buffer large enough to hold the symbol map of any input BFD. */
3651 /* A buffer large enough to hold output symbols of any input BFD. */
3652 struct external_nlist
*output_syms
;
3655 static struct bfd_hash_entry
*aout_link_includes_newfunc
3656 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
3657 static bfd_boolean aout_link_input_bfd
3658 PARAMS ((struct aout_final_link_info
*, bfd
*input_bfd
));
3659 static bfd_boolean aout_link_write_symbols
3660 PARAMS ((struct aout_final_link_info
*, bfd
*input_bfd
));
3661 static bfd_boolean aout_link_write_other_symbol
3662 PARAMS ((struct aout_link_hash_entry
*, PTR
));
3663 static bfd_boolean aout_link_input_section
3664 PARAMS ((struct aout_final_link_info
*, bfd
*input_bfd
,
3665 asection
*input_section
, file_ptr
*reloff_ptr
,
3666 bfd_size_type rel_size
));
3667 static bfd_boolean aout_link_input_section_std
3668 PARAMS ((struct aout_final_link_info
*, bfd
*input_bfd
,
3669 asection
*input_section
, struct reloc_std_external
*,
3670 bfd_size_type rel_size
, bfd_byte
*contents
));
3671 static bfd_boolean aout_link_input_section_ext
3672 PARAMS ((struct aout_final_link_info
*, bfd
*input_bfd
,
3673 asection
*input_section
, struct reloc_ext_external
*,
3674 bfd_size_type rel_size
, bfd_byte
*contents
));
3675 static INLINE asection
*aout_reloc_index_to_section
3676 PARAMS ((bfd
*, int));
3677 static bfd_boolean aout_link_reloc_link_order
3678 PARAMS ((struct aout_final_link_info
*, asection
*,
3679 struct bfd_link_order
*));
3681 /* The function to create a new entry in the header file hash table. */
3683 static struct bfd_hash_entry
*
3684 aout_link_includes_newfunc (entry
, table
, string
)
3685 struct bfd_hash_entry
*entry
;
3686 struct bfd_hash_table
*table
;
3689 struct aout_link_includes_entry
*ret
=
3690 (struct aout_link_includes_entry
*) entry
;
3692 /* Allocate the structure if it has not already been allocated by a
3694 if (ret
== (struct aout_link_includes_entry
*) NULL
)
3695 ret
= ((struct aout_link_includes_entry
*)
3696 bfd_hash_allocate (table
,
3697 sizeof (struct aout_link_includes_entry
)));
3698 if (ret
== (struct aout_link_includes_entry
*) NULL
)
3699 return (struct bfd_hash_entry
*) ret
;
3701 /* Call the allocation method of the superclass. */
3702 ret
= ((struct aout_link_includes_entry
*)
3703 bfd_hash_newfunc ((struct bfd_hash_entry
*) ret
, table
, string
));
3706 /* Set local fields. */
3710 return (struct bfd_hash_entry
*) ret
;
3713 /* Do the final link step. This is called on the output BFD. The
3714 INFO structure should point to a list of BFDs linked through the
3715 link_next field which can be used to find each BFD which takes part
3716 in the output. Also, each section in ABFD should point to a list
3717 of bfd_link_order structures which list all the input sections for
3718 the output section. */
3721 NAME(aout
,final_link
) (abfd
, info
, callback
)
3723 struct bfd_link_info
*info
;
3724 void (*callback
) PARAMS ((bfd
*, file_ptr
*, file_ptr
*, file_ptr
*));
3726 struct aout_final_link_info aout_info
;
3727 bfd_boolean includes_hash_initialized
= FALSE
;
3729 bfd_size_type trsize
, drsize
;
3730 bfd_size_type max_contents_size
;
3731 bfd_size_type max_relocs_size
;
3732 bfd_size_type max_sym_count
;
3733 bfd_size_type text_size
;
3735 register struct bfd_link_order
*p
;
3737 bfd_boolean have_link_order_relocs
;
3740 abfd
->flags
|= DYNAMIC
;
3742 aout_info
.info
= info
;
3743 aout_info
.output_bfd
= abfd
;
3744 aout_info
.contents
= NULL
;
3745 aout_info
.relocs
= NULL
;
3746 aout_info
.symbol_map
= NULL
;
3747 aout_info
.output_syms
= NULL
;
3749 if (! bfd_hash_table_init_n (&aout_info
.includes
.root
,
3750 aout_link_includes_newfunc
,
3753 includes_hash_initialized
= TRUE
;
3755 /* Figure out the largest section size. Also, if generating
3756 relocatable output, count the relocs. */
3759 max_contents_size
= 0;
3760 max_relocs_size
= 0;
3762 for (sub
= info
->input_bfds
; sub
!= NULL
; sub
= sub
->link_next
)
3766 if (info
->relocatable
)
3768 if (bfd_get_flavour (sub
) == bfd_target_aout_flavour
)
3770 trsize
+= exec_hdr (sub
)->a_trsize
;
3771 drsize
+= exec_hdr (sub
)->a_drsize
;
3775 /* FIXME: We need to identify the .text and .data sections
3776 and call get_reloc_upper_bound and canonicalize_reloc to
3777 work out the number of relocs needed, and then multiply
3778 by the reloc size. */
3779 (*_bfd_error_handler
)
3780 (_("%s: relocatable link from %s to %s not supported"),
3781 bfd_get_filename (abfd
),
3782 sub
->xvec
->name
, abfd
->xvec
->name
);
3783 bfd_set_error (bfd_error_invalid_operation
);
3788 if (bfd_get_flavour (sub
) == bfd_target_aout_flavour
)
3790 sz
= obj_textsec (sub
)->size
;
3791 if (sz
> max_contents_size
)
3792 max_contents_size
= sz
;
3793 sz
= obj_datasec (sub
)->size
;
3794 if (sz
> max_contents_size
)
3795 max_contents_size
= sz
;
3797 sz
= exec_hdr (sub
)->a_trsize
;
3798 if (sz
> max_relocs_size
)
3799 max_relocs_size
= sz
;
3800 sz
= exec_hdr (sub
)->a_drsize
;
3801 if (sz
> max_relocs_size
)
3802 max_relocs_size
= sz
;
3804 sz
= obj_aout_external_sym_count (sub
);
3805 if (sz
> max_sym_count
)
3810 if (info
->relocatable
)
3812 if (obj_textsec (abfd
) != (asection
*) NULL
)
3813 trsize
+= (_bfd_count_link_order_relocs (obj_textsec (abfd
)
3815 * obj_reloc_entry_size (abfd
));
3816 if (obj_datasec (abfd
) != (asection
*) NULL
)
3817 drsize
+= (_bfd_count_link_order_relocs (obj_datasec (abfd
)
3819 * obj_reloc_entry_size (abfd
));
3822 exec_hdr (abfd
)->a_trsize
= trsize
;
3823 exec_hdr (abfd
)->a_drsize
= drsize
;
3825 exec_hdr (abfd
)->a_entry
= bfd_get_start_address (abfd
);
3827 /* Adjust the section sizes and vmas according to the magic number.
3828 This sets a_text, a_data and a_bss in the exec_hdr and sets the
3829 filepos for each section. */
3830 if (! NAME(aout
,adjust_sizes_and_vmas
) (abfd
, &text_size
, &text_end
))
3833 /* The relocation and symbol file positions differ among a.out
3834 targets. We are passed a callback routine from the backend
3835 specific code to handle this.
3836 FIXME: At this point we do not know how much space the symbol
3837 table will require. This will not work for any (nonstandard)
3838 a.out target that needs to know the symbol table size before it
3839 can compute the relocation file positions. This may or may not
3840 be the case for the hp300hpux target, for example. */
3841 (*callback
) (abfd
, &aout_info
.treloff
, &aout_info
.dreloff
,
3843 obj_textsec (abfd
)->rel_filepos
= aout_info
.treloff
;
3844 obj_datasec (abfd
)->rel_filepos
= aout_info
.dreloff
;
3845 obj_sym_filepos (abfd
) = aout_info
.symoff
;
3847 /* We keep a count of the symbols as we output them. */
3848 obj_aout_external_sym_count (abfd
) = 0;
3850 /* We accumulate the string table as we write out the symbols. */
3851 aout_info
.strtab
= _bfd_stringtab_init ();
3852 if (aout_info
.strtab
== NULL
)
3855 /* Allocate buffers to hold section contents and relocs. */
3856 aout_info
.contents
= (bfd_byte
*) bfd_malloc (max_contents_size
);
3857 aout_info
.relocs
= (PTR
) bfd_malloc (max_relocs_size
);
3858 aout_info
.symbol_map
= (int *) bfd_malloc (max_sym_count
* sizeof (int *));
3859 aout_info
.output_syms
= ((struct external_nlist
*)
3860 bfd_malloc ((max_sym_count
+ 1)
3861 * sizeof (struct external_nlist
)));
3862 if ((aout_info
.contents
== NULL
&& max_contents_size
!= 0)
3863 || (aout_info
.relocs
== NULL
&& max_relocs_size
!= 0)
3864 || (aout_info
.symbol_map
== NULL
&& max_sym_count
!= 0)
3865 || aout_info
.output_syms
== NULL
)
3868 /* If we have a symbol named __DYNAMIC, force it out now. This is
3869 required by SunOS. Doing this here rather than in sunos.c is a
3870 hack, but it's easier than exporting everything which would be
3873 struct aout_link_hash_entry
*h
;
3875 h
= aout_link_hash_lookup (aout_hash_table (info
), "__DYNAMIC",
3876 FALSE
, FALSE
, FALSE
);
3878 aout_link_write_other_symbol (h
, &aout_info
);
3881 /* The most time efficient way to do the link would be to read all
3882 the input object files into memory and then sort out the
3883 information into the output file. Unfortunately, that will
3884 probably use too much memory. Another method would be to step
3885 through everything that composes the text section and write it
3886 out, and then everything that composes the data section and write
3887 it out, and then write out the relocs, and then write out the
3888 symbols. Unfortunately, that requires reading stuff from each
3889 input file several times, and we will not be able to keep all the
3890 input files open simultaneously, and reopening them will be slow.
3892 What we do is basically process one input file at a time. We do
3893 everything we need to do with an input file once--copy over the
3894 section contents, handle the relocation information, and write
3895 out the symbols--and then we throw away the information we read
3896 from it. This approach requires a lot of lseeks of the output
3897 file, which is unfortunate but still faster than reopening a lot
3900 We use the output_has_begun field of the input BFDs to see
3901 whether we have already handled it. */
3902 for (sub
= info
->input_bfds
; sub
!= (bfd
*) NULL
; sub
= sub
->link_next
)
3903 sub
->output_has_begun
= FALSE
;
3905 /* Mark all sections which are to be included in the link. This
3906 will normally be every section. We need to do this so that we
3907 can identify any sections which the linker has decided to not
3909 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
3911 for (p
= o
->link_order_head
; p
!= NULL
; p
= p
->next
)
3912 if (p
->type
== bfd_indirect_link_order
)
3913 p
->u
.indirect
.section
->linker_mark
= TRUE
;
3916 have_link_order_relocs
= FALSE
;
3917 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
3919 for (p
= o
->link_order_head
;
3920 p
!= (struct bfd_link_order
*) NULL
;
3923 if (p
->type
== bfd_indirect_link_order
3924 && (bfd_get_flavour (p
->u
.indirect
.section
->owner
)
3925 == bfd_target_aout_flavour
))
3929 input_bfd
= p
->u
.indirect
.section
->owner
;
3930 if (! input_bfd
->output_has_begun
)
3932 if (! aout_link_input_bfd (&aout_info
, input_bfd
))
3934 input_bfd
->output_has_begun
= TRUE
;
3937 else if (p
->type
== bfd_section_reloc_link_order
3938 || p
->type
== bfd_symbol_reloc_link_order
)
3940 /* These are handled below. */
3941 have_link_order_relocs
= TRUE
;
3945 if (! _bfd_default_link_order (abfd
, info
, o
, p
))
3951 /* Write out any symbols that we have not already written out. */
3952 aout_link_hash_traverse (aout_hash_table (info
),
3953 aout_link_write_other_symbol
,
3956 /* Now handle any relocs we were asked to create by the linker.
3957 These did not come from any input file. We must do these after
3958 we have written out all the symbols, so that we know the symbol
3960 if (have_link_order_relocs
)
3962 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
3964 for (p
= o
->link_order_head
;
3965 p
!= (struct bfd_link_order
*) NULL
;
3968 if (p
->type
== bfd_section_reloc_link_order
3969 || p
->type
== bfd_symbol_reloc_link_order
)
3971 if (! aout_link_reloc_link_order (&aout_info
, o
, p
))
3978 if (aout_info
.contents
!= NULL
)
3980 free (aout_info
.contents
);
3981 aout_info
.contents
= NULL
;
3983 if (aout_info
.relocs
!= NULL
)
3985 free (aout_info
.relocs
);
3986 aout_info
.relocs
= NULL
;
3988 if (aout_info
.symbol_map
!= NULL
)
3990 free (aout_info
.symbol_map
);
3991 aout_info
.symbol_map
= NULL
;
3993 if (aout_info
.output_syms
!= NULL
)
3995 free (aout_info
.output_syms
);
3996 aout_info
.output_syms
= NULL
;
3998 if (includes_hash_initialized
)
4000 bfd_hash_table_free (&aout_info
.includes
.root
);
4001 includes_hash_initialized
= FALSE
;
4004 /* Finish up any dynamic linking we may be doing. */
4005 if (aout_backend_info (abfd
)->finish_dynamic_link
!= NULL
)
4007 if (! (*aout_backend_info (abfd
)->finish_dynamic_link
) (abfd
, info
))
4011 /* Update the header information. */
4012 abfd
->symcount
= obj_aout_external_sym_count (abfd
);
4013 exec_hdr (abfd
)->a_syms
= abfd
->symcount
* EXTERNAL_NLIST_SIZE
;
4014 obj_str_filepos (abfd
) = obj_sym_filepos (abfd
) + exec_hdr (abfd
)->a_syms
;
4015 obj_textsec (abfd
)->reloc_count
=
4016 exec_hdr (abfd
)->a_trsize
/ obj_reloc_entry_size (abfd
);
4017 obj_datasec (abfd
)->reloc_count
=
4018 exec_hdr (abfd
)->a_drsize
/ obj_reloc_entry_size (abfd
);
4020 /* Write out the string table, unless there are no symbols. */
4021 if (abfd
->symcount
> 0)
4023 if (bfd_seek (abfd
, obj_str_filepos (abfd
), SEEK_SET
) != 0
4024 || ! emit_stringtab (abfd
, aout_info
.strtab
))
4027 else if (obj_textsec (abfd
)->reloc_count
== 0
4028 && obj_datasec (abfd
)->reloc_count
== 0)
4034 pos
= obj_datasec (abfd
)->filepos
+ exec_hdr (abfd
)->a_data
- 1;
4035 if (bfd_seek (abfd
, pos
, SEEK_SET
) != 0
4036 || bfd_bwrite (&b
, (bfd_size_type
) 1, abfd
) != 1)
4043 if (aout_info
.contents
!= NULL
)
4044 free (aout_info
.contents
);
4045 if (aout_info
.relocs
!= NULL
)
4046 free (aout_info
.relocs
);
4047 if (aout_info
.symbol_map
!= NULL
)
4048 free (aout_info
.symbol_map
);
4049 if (aout_info
.output_syms
!= NULL
)
4050 free (aout_info
.output_syms
);
4051 if (includes_hash_initialized
)
4052 bfd_hash_table_free (&aout_info
.includes
.root
);
4056 /* Link an a.out input BFD into the output file. */
4059 aout_link_input_bfd (finfo
, input_bfd
)
4060 struct aout_final_link_info
*finfo
;
4063 bfd_size_type sym_count
;
4065 BFD_ASSERT (bfd_get_format (input_bfd
) == bfd_object
);
4067 /* If this is a dynamic object, it may need special handling. */
4068 if ((input_bfd
->flags
& DYNAMIC
) != 0
4069 && aout_backend_info (input_bfd
)->link_dynamic_object
!= NULL
)
4071 return ((*aout_backend_info (input_bfd
)->link_dynamic_object
)
4072 (finfo
->info
, input_bfd
));
4075 /* Get the symbols. We probably have them already, unless
4076 finfo->info->keep_memory is FALSE. */
4077 if (! aout_get_external_symbols (input_bfd
))
4080 sym_count
= obj_aout_external_sym_count (input_bfd
);
4082 /* Write out the symbols and get a map of the new indices. The map
4083 is placed into finfo->symbol_map. */
4084 if (! aout_link_write_symbols (finfo
, input_bfd
))
4087 /* Relocate and write out the sections. These functions use the
4088 symbol map created by aout_link_write_symbols. The linker_mark
4089 field will be set if these sections are to be included in the
4090 link, which will normally be the case. */
4091 if (obj_textsec (input_bfd
)->linker_mark
)
4093 if (! aout_link_input_section (finfo
, input_bfd
,
4094 obj_textsec (input_bfd
),
4096 exec_hdr (input_bfd
)->a_trsize
))
4099 if (obj_datasec (input_bfd
)->linker_mark
)
4101 if (! aout_link_input_section (finfo
, input_bfd
,
4102 obj_datasec (input_bfd
),
4104 exec_hdr (input_bfd
)->a_drsize
))
4108 /* If we are not keeping memory, we don't need the symbols any
4109 longer. We still need them if we are keeping memory, because the
4110 strings in the hash table point into them. */
4111 if (! finfo
->info
->keep_memory
)
4113 if (! aout_link_free_symbols (input_bfd
))
4120 /* Adjust and write out the symbols for an a.out file. Set the new
4121 symbol indices into a symbol_map. */
4124 aout_link_write_symbols (finfo
, input_bfd
)
4125 struct aout_final_link_info
*finfo
;
4129 bfd_size_type sym_count
;
4131 enum bfd_link_strip strip
;
4132 enum bfd_link_discard discard
;
4133 struct external_nlist
*outsym
;
4134 bfd_size_type strtab_index
;
4135 register struct external_nlist
*sym
;
4136 struct external_nlist
*sym_end
;
4137 struct aout_link_hash_entry
**sym_hash
;
4140 bfd_boolean skip_next
;
4142 output_bfd
= finfo
->output_bfd
;
4143 sym_count
= obj_aout_external_sym_count (input_bfd
);
4144 strings
= obj_aout_external_strings (input_bfd
);
4145 strip
= finfo
->info
->strip
;
4146 discard
= finfo
->info
->discard
;
4147 outsym
= finfo
->output_syms
;
4149 /* First write out a symbol for this object file, unless we are
4150 discarding such symbols. */
4151 if (strip
!= strip_all
4152 && (strip
!= strip_some
4153 || bfd_hash_lookup (finfo
->info
->keep_hash
, input_bfd
->filename
,
4154 FALSE
, FALSE
) != NULL
)
4155 && discard
!= discard_all
)
4157 H_PUT_8 (output_bfd
, N_TEXT
, outsym
->e_type
);
4158 H_PUT_8 (output_bfd
, 0, outsym
->e_other
);
4159 H_PUT_16 (output_bfd
, 0, outsym
->e_desc
);
4160 strtab_index
= add_to_stringtab (output_bfd
, finfo
->strtab
,
4161 input_bfd
->filename
, FALSE
);
4162 if (strtab_index
== (bfd_size_type
) -1)
4164 PUT_WORD (output_bfd
, strtab_index
, outsym
->e_strx
);
4165 PUT_WORD (output_bfd
,
4166 (bfd_get_section_vma (output_bfd
,
4167 obj_textsec (input_bfd
)->output_section
)
4168 + obj_textsec (input_bfd
)->output_offset
),
4170 ++obj_aout_external_sym_count (output_bfd
);
4176 sym
= obj_aout_external_syms (input_bfd
);
4177 sym_end
= sym
+ sym_count
;
4178 sym_hash
= obj_aout_sym_hashes (input_bfd
);
4179 symbol_map
= finfo
->symbol_map
;
4180 memset (symbol_map
, 0, (size_t) sym_count
* sizeof *symbol_map
);
4181 for (; sym
< sym_end
; sym
++, sym_hash
++, symbol_map
++)
4185 struct aout_link_hash_entry
*h
;
4191 /* We set *symbol_map to 0 above for all symbols. If it has
4192 already been set to -1 for this symbol, it means that we are
4193 discarding it because it appears in a duplicate header file.
4194 See the N_BINCL code below. */
4195 if (*symbol_map
== -1)
4198 /* Initialize *symbol_map to -1, which means that the symbol was
4199 not copied into the output file. We will change it later if
4200 we do copy the symbol over. */
4203 type
= H_GET_8 (input_bfd
, sym
->e_type
);
4204 name
= strings
+ GET_WORD (input_bfd
, sym
->e_strx
);
4210 /* Pass this symbol through. It is the target of an
4211 indirect or warning symbol. */
4212 val
= GET_WORD (input_bfd
, sym
->e_value
);
4217 /* Skip this symbol, which is the target of an indirect
4218 symbol that we have changed to no longer be an indirect
4225 struct aout_link_hash_entry
*hresolve
;
4227 /* We have saved the hash table entry for this symbol, if
4228 there is one. Note that we could just look it up again
4229 in the hash table, provided we first check that it is an
4233 /* Use the name from the hash table, in case the symbol was
4236 && h
->root
.type
!= bfd_link_hash_warning
)
4237 name
= h
->root
.root
.string
;
4239 /* If this is an indirect or warning symbol, then change
4240 hresolve to the base symbol. We also change *sym_hash so
4241 that the relocation routines relocate against the real
4244 if (h
!= (struct aout_link_hash_entry
*) NULL
4245 && (h
->root
.type
== bfd_link_hash_indirect
4246 || h
->root
.type
== bfd_link_hash_warning
))
4248 hresolve
= (struct aout_link_hash_entry
*) h
->root
.u
.i
.link
;
4249 while (hresolve
->root
.type
== bfd_link_hash_indirect
4250 || hresolve
->root
.type
== bfd_link_hash_warning
)
4251 hresolve
= ((struct aout_link_hash_entry
*)
4252 hresolve
->root
.u
.i
.link
);
4253 *sym_hash
= hresolve
;
4256 /* If the symbol has already been written out, skip it. */
4257 if (h
!= (struct aout_link_hash_entry
*) NULL
4260 if ((type
& N_TYPE
) == N_INDR
4261 || type
== N_WARNING
)
4263 *symbol_map
= h
->indx
;
4267 /* See if we are stripping this symbol. */
4273 case strip_debugger
:
4274 if ((type
& N_STAB
) != 0)
4278 if (bfd_hash_lookup (finfo
->info
->keep_hash
, name
, FALSE
, FALSE
)
4288 if (h
!= (struct aout_link_hash_entry
*) NULL
)
4293 /* Get the value of the symbol. */
4294 if ((type
& N_TYPE
) == N_TEXT
4296 symsec
= obj_textsec (input_bfd
);
4297 else if ((type
& N_TYPE
) == N_DATA
4299 symsec
= obj_datasec (input_bfd
);
4300 else if ((type
& N_TYPE
) == N_BSS
4302 symsec
= obj_bsssec (input_bfd
);
4303 else if ((type
& N_TYPE
) == N_ABS
4305 symsec
= bfd_abs_section_ptr
;
4306 else if (((type
& N_TYPE
) == N_INDR
4307 && (hresolve
== (struct aout_link_hash_entry
*) NULL
4308 || (hresolve
->root
.type
!= bfd_link_hash_defined
4309 && hresolve
->root
.type
!= bfd_link_hash_defweak
4310 && hresolve
->root
.type
!= bfd_link_hash_common
)))
4311 || type
== N_WARNING
)
4313 /* Pass the next symbol through unchanged. The
4314 condition above for indirect symbols is so that if
4315 the indirect symbol was defined, we output it with
4316 the correct definition so the debugger will
4319 val
= GET_WORD (input_bfd
, sym
->e_value
);
4322 else if ((type
& N_STAB
) != 0)
4324 val
= GET_WORD (input_bfd
, sym
->e_value
);
4329 /* If we get here with an indirect symbol, it means that
4330 we are outputting it with a real definition. In such
4331 a case we do not want to output the next symbol,
4332 which is the target of the indirection. */
4333 if ((type
& N_TYPE
) == N_INDR
)
4338 /* We need to get the value from the hash table. We use
4339 hresolve so that if we have defined an indirect
4340 symbol we output the final definition. */
4341 if (h
== (struct aout_link_hash_entry
*) NULL
)
4343 switch (type
& N_TYPE
)
4346 symsec
= obj_textsec (input_bfd
);
4349 symsec
= obj_datasec (input_bfd
);
4352 symsec
= obj_bsssec (input_bfd
);
4355 symsec
= bfd_abs_section_ptr
;
4362 else if (hresolve
->root
.type
== bfd_link_hash_defined
4363 || hresolve
->root
.type
== bfd_link_hash_defweak
)
4365 asection
*input_section
;
4366 asection
*output_section
;
4368 /* This case usually means a common symbol which was
4369 turned into a defined symbol. */
4370 input_section
= hresolve
->root
.u
.def
.section
;
4371 output_section
= input_section
->output_section
;
4372 BFD_ASSERT (bfd_is_abs_section (output_section
)
4373 || output_section
->owner
== output_bfd
);
4374 val
= (hresolve
->root
.u
.def
.value
4375 + bfd_get_section_vma (output_bfd
, output_section
)
4376 + input_section
->output_offset
);
4378 /* Get the correct type based on the section. If
4379 this is a constructed set, force it to be
4380 globally visible. */
4389 if (output_section
== obj_textsec (output_bfd
))
4390 type
|= (hresolve
->root
.type
== bfd_link_hash_defined
4393 else if (output_section
== obj_datasec (output_bfd
))
4394 type
|= (hresolve
->root
.type
== bfd_link_hash_defined
4397 else if (output_section
== obj_bsssec (output_bfd
))
4398 type
|= (hresolve
->root
.type
== bfd_link_hash_defined
4402 type
|= (hresolve
->root
.type
== bfd_link_hash_defined
4406 else if (hresolve
->root
.type
== bfd_link_hash_common
)
4407 val
= hresolve
->root
.u
.c
.size
;
4408 else if (hresolve
->root
.type
== bfd_link_hash_undefweak
)
4416 if (symsec
!= (asection
*) NULL
)
4417 val
= (symsec
->output_section
->vma
4418 + symsec
->output_offset
4419 + (GET_WORD (input_bfd
, sym
->e_value
)
4422 /* If this is a global symbol set the written flag, and if
4423 it is a local symbol see if we should discard it. */
4424 if (h
!= (struct aout_link_hash_entry
*) NULL
)
4427 h
->indx
= obj_aout_external_sym_count (output_bfd
);
4429 else if ((type
& N_TYPE
) != N_SETT
4430 && (type
& N_TYPE
) != N_SETD
4431 && (type
& N_TYPE
) != N_SETB
4432 && (type
& N_TYPE
) != N_SETA
)
4437 case discard_sec_merge
:
4440 if ((type
& N_STAB
) == 0
4441 && bfd_is_local_label_name (input_bfd
, name
))
4455 /* An N_BINCL symbol indicates the start of the stabs
4456 entries for a header file. We need to scan ahead to the
4457 next N_EINCL symbol, ignoring nesting, adding up all the
4458 characters in the symbol names, not including the file
4459 numbers in types (the first number after an open
4461 if (type
== (int) N_BINCL
)
4463 struct external_nlist
*incl_sym
;
4465 struct aout_link_includes_entry
*incl_entry
;
4466 struct aout_link_includes_totals
*t
;
4470 for (incl_sym
= sym
+ 1; incl_sym
< sym_end
; incl_sym
++)
4474 incl_type
= H_GET_8 (input_bfd
, incl_sym
->e_type
);
4475 if (incl_type
== (int) N_EINCL
)
4481 else if (incl_type
== (int) N_BINCL
)
4487 s
= strings
+ GET_WORD (input_bfd
, incl_sym
->e_strx
);
4488 for (; *s
!= '\0'; s
++)
4493 /* Skip the file number. */
4495 while (ISDIGIT (*s
))
4503 /* If we have already included a header file with the
4504 same value, then replace this one with an N_EXCL
4506 copy
= (bfd_boolean
) (! finfo
->info
->keep_memory
);
4507 incl_entry
= aout_link_includes_lookup (&finfo
->includes
,
4509 if (incl_entry
== NULL
)
4511 for (t
= incl_entry
->totals
; t
!= NULL
; t
= t
->next
)
4512 if (t
->total
== val
)
4516 /* This is the first time we have seen this header
4517 file with this set of stabs strings. */
4518 t
= ((struct aout_link_includes_totals
*)
4519 bfd_hash_allocate (&finfo
->includes
.root
,
4524 t
->next
= incl_entry
->totals
;
4525 incl_entry
->totals
= t
;
4531 /* This is a duplicate header file. We must change
4532 it to be an N_EXCL entry, and mark all the
4533 included symbols to prevent outputting them. */
4534 type
= (int) N_EXCL
;
4537 for (incl_sym
= sym
+ 1, incl_map
= symbol_map
+ 1;
4539 incl_sym
++, incl_map
++)
4543 incl_type
= H_GET_8 (input_bfd
, incl_sym
->e_type
);
4544 if (incl_type
== (int) N_EINCL
)
4553 else if (incl_type
== (int) N_BINCL
)
4562 /* Copy this symbol into the list of symbols we are going to
4564 H_PUT_8 (output_bfd
, type
, outsym
->e_type
);
4565 H_PUT_8 (output_bfd
, H_GET_8 (input_bfd
, sym
->e_other
), outsym
->e_other
);
4566 H_PUT_16 (output_bfd
, H_GET_16 (input_bfd
, sym
->e_desc
), outsym
->e_desc
);
4568 if (! finfo
->info
->keep_memory
)
4570 /* name points into a string table which we are going to
4571 free. If there is a hash table entry, use that string.
4572 Otherwise, copy name into memory. */
4573 if (h
!= (struct aout_link_hash_entry
*) NULL
)
4574 name
= h
->root
.root
.string
;
4578 strtab_index
= add_to_stringtab (output_bfd
, finfo
->strtab
,
4580 if (strtab_index
== (bfd_size_type
) -1)
4582 PUT_WORD (output_bfd
, strtab_index
, outsym
->e_strx
);
4583 PUT_WORD (output_bfd
, val
, outsym
->e_value
);
4584 *symbol_map
= obj_aout_external_sym_count (output_bfd
);
4585 ++obj_aout_external_sym_count (output_bfd
);
4589 /* Write out the output symbols we have just constructed. */
4590 if (outsym
> finfo
->output_syms
)
4592 bfd_size_type outsym_size
;
4594 if (bfd_seek (output_bfd
, finfo
->symoff
, SEEK_SET
) != 0)
4596 outsym_size
= outsym
- finfo
->output_syms
;
4597 outsym_size
*= EXTERNAL_NLIST_SIZE
;
4598 if (bfd_bwrite ((PTR
) finfo
->output_syms
, outsym_size
, output_bfd
)
4601 finfo
->symoff
+= outsym_size
;
4607 /* Write out a symbol that was not associated with an a.out input
4611 aout_link_write_other_symbol (h
, data
)
4612 struct aout_link_hash_entry
*h
;
4615 struct aout_final_link_info
*finfo
= (struct aout_final_link_info
*) data
;
4619 struct external_nlist outsym
;
4623 if (h
->root
.type
== bfd_link_hash_warning
)
4625 h
= (struct aout_link_hash_entry
*) h
->root
.u
.i
.link
;
4626 if (h
->root
.type
== bfd_link_hash_new
)
4630 output_bfd
= finfo
->output_bfd
;
4632 if (aout_backend_info (output_bfd
)->write_dynamic_symbol
!= NULL
)
4634 if (! ((*aout_backend_info (output_bfd
)->write_dynamic_symbol
)
4635 (output_bfd
, finfo
->info
, h
)))
4637 /* FIXME: No way to handle errors. */
4647 /* An indx of -2 means the symbol must be written. */
4649 && (finfo
->info
->strip
== strip_all
4650 || (finfo
->info
->strip
== strip_some
4651 && bfd_hash_lookup (finfo
->info
->keep_hash
, h
->root
.root
.string
,
4652 FALSE
, FALSE
) == NULL
)))
4655 switch (h
->root
.type
)
4658 case bfd_link_hash_warning
:
4660 /* Avoid variable not initialized warnings. */
4662 case bfd_link_hash_new
:
4663 /* This can happen for set symbols when sets are not being
4666 case bfd_link_hash_undefined
:
4667 type
= N_UNDF
| N_EXT
;
4670 case bfd_link_hash_defined
:
4671 case bfd_link_hash_defweak
:
4675 sec
= h
->root
.u
.def
.section
->output_section
;
4676 BFD_ASSERT (bfd_is_abs_section (sec
)
4677 || sec
->owner
== output_bfd
);
4678 if (sec
== obj_textsec (output_bfd
))
4679 type
= h
->root
.type
== bfd_link_hash_defined
? N_TEXT
: N_WEAKT
;
4680 else if (sec
== obj_datasec (output_bfd
))
4681 type
= h
->root
.type
== bfd_link_hash_defined
? N_DATA
: N_WEAKD
;
4682 else if (sec
== obj_bsssec (output_bfd
))
4683 type
= h
->root
.type
== bfd_link_hash_defined
? N_BSS
: N_WEAKB
;
4685 type
= h
->root
.type
== bfd_link_hash_defined
? N_ABS
: N_WEAKA
;
4687 val
= (h
->root
.u
.def
.value
4689 + h
->root
.u
.def
.section
->output_offset
);
4692 case bfd_link_hash_common
:
4693 type
= N_UNDF
| N_EXT
;
4694 val
= h
->root
.u
.c
.size
;
4696 case bfd_link_hash_undefweak
:
4699 case bfd_link_hash_indirect
:
4700 /* We ignore these symbols, since the indirected symbol is
4701 already in the hash table. */
4705 H_PUT_8 (output_bfd
, type
, outsym
.e_type
);
4706 H_PUT_8 (output_bfd
, 0, outsym
.e_other
);
4707 H_PUT_16 (output_bfd
, 0, outsym
.e_desc
);
4708 indx
= add_to_stringtab (output_bfd
, finfo
->strtab
, h
->root
.root
.string
,
4710 if (indx
== - (bfd_size_type
) 1)
4712 /* FIXME: No way to handle errors. */
4715 PUT_WORD (output_bfd
, indx
, outsym
.e_strx
);
4716 PUT_WORD (output_bfd
, val
, outsym
.e_value
);
4718 amt
= EXTERNAL_NLIST_SIZE
;
4719 if (bfd_seek (output_bfd
, finfo
->symoff
, SEEK_SET
) != 0
4720 || bfd_bwrite ((PTR
) &outsym
, amt
, output_bfd
) != amt
)
4722 /* FIXME: No way to handle errors. */
4726 finfo
->symoff
+= EXTERNAL_NLIST_SIZE
;
4727 h
->indx
= obj_aout_external_sym_count (output_bfd
);
4728 ++obj_aout_external_sym_count (output_bfd
);
4733 /* Link an a.out section into the output file. */
4736 aout_link_input_section (finfo
, input_bfd
, input_section
, reloff_ptr
,
4738 struct aout_final_link_info
*finfo
;
4740 asection
*input_section
;
4741 file_ptr
*reloff_ptr
;
4742 bfd_size_type rel_size
;
4744 bfd_size_type input_size
;
4747 /* Get the section contents. */
4748 input_size
= input_section
->size
;
4749 if (! bfd_get_section_contents (input_bfd
, input_section
,
4750 (PTR
) finfo
->contents
,
4751 (file_ptr
) 0, input_size
))
4754 /* Read in the relocs if we haven't already done it. */
4755 if (aout_section_data (input_section
) != NULL
4756 && aout_section_data (input_section
)->relocs
!= NULL
)
4757 relocs
= aout_section_data (input_section
)->relocs
;
4760 relocs
= finfo
->relocs
;
4763 if (bfd_seek (input_bfd
, input_section
->rel_filepos
, SEEK_SET
) != 0
4764 || bfd_bread (relocs
, rel_size
, input_bfd
) != rel_size
)
4769 /* Relocate the section contents. */
4770 if (obj_reloc_entry_size (input_bfd
) == RELOC_STD_SIZE
)
4772 if (! aout_link_input_section_std (finfo
, input_bfd
, input_section
,
4773 (struct reloc_std_external
*) relocs
,
4774 rel_size
, finfo
->contents
))
4779 if (! aout_link_input_section_ext (finfo
, input_bfd
, input_section
,
4780 (struct reloc_ext_external
*) relocs
,
4781 rel_size
, finfo
->contents
))
4785 /* Write out the section contents. */
4786 if (! bfd_set_section_contents (finfo
->output_bfd
,
4787 input_section
->output_section
,
4788 (PTR
) finfo
->contents
,
4789 (file_ptr
) input_section
->output_offset
,
4793 /* If we are producing relocatable output, the relocs were
4794 modified, and we now write them out. */
4795 if (finfo
->info
->relocatable
&& rel_size
> 0)
4797 if (bfd_seek (finfo
->output_bfd
, *reloff_ptr
, SEEK_SET
) != 0)
4799 if (bfd_bwrite (relocs
, rel_size
, finfo
->output_bfd
) != rel_size
)
4801 *reloff_ptr
+= rel_size
;
4803 /* Assert that the relocs have not run into the symbols, and
4804 that if these are the text relocs they have not run into the
4806 BFD_ASSERT (*reloff_ptr
<= obj_sym_filepos (finfo
->output_bfd
)
4807 && (reloff_ptr
!= &finfo
->treloff
4809 <= obj_datasec (finfo
->output_bfd
)->rel_filepos
)));
4815 /* Get the section corresponding to a reloc index. */
4817 static INLINE asection
*
4818 aout_reloc_index_to_section (abfd
, indx
)
4822 switch (indx
& N_TYPE
)
4825 return obj_textsec (abfd
);
4827 return obj_datasec (abfd
);
4829 return obj_bsssec (abfd
);
4832 return bfd_abs_section_ptr
;
4840 /* Relocate an a.out section using standard a.out relocs. */
4843 aout_link_input_section_std (finfo
, input_bfd
, input_section
, relocs
,
4845 struct aout_final_link_info
*finfo
;
4847 asection
*input_section
;
4848 struct reloc_std_external
*relocs
;
4849 bfd_size_type rel_size
;
4852 bfd_boolean (*check_dynamic_reloc
)
4853 PARAMS ((struct bfd_link_info
*, bfd
*, asection
*,
4854 struct aout_link_hash_entry
*, PTR
, bfd_byte
*, bfd_boolean
*,
4857 bfd_boolean relocatable
;
4858 struct external_nlist
*syms
;
4860 struct aout_link_hash_entry
**sym_hashes
;
4862 bfd_size_type reloc_count
;
4863 register struct reloc_std_external
*rel
;
4864 struct reloc_std_external
*rel_end
;
4866 output_bfd
= finfo
->output_bfd
;
4867 check_dynamic_reloc
= aout_backend_info (output_bfd
)->check_dynamic_reloc
;
4869 BFD_ASSERT (obj_reloc_entry_size (input_bfd
) == RELOC_STD_SIZE
);
4870 BFD_ASSERT (input_bfd
->xvec
->header_byteorder
4871 == output_bfd
->xvec
->header_byteorder
);
4873 relocatable
= finfo
->info
->relocatable
;
4874 syms
= obj_aout_external_syms (input_bfd
);
4875 strings
= obj_aout_external_strings (input_bfd
);
4876 sym_hashes
= obj_aout_sym_hashes (input_bfd
);
4877 symbol_map
= finfo
->symbol_map
;
4879 reloc_count
= rel_size
/ RELOC_STD_SIZE
;
4881 rel_end
= rel
+ reloc_count
;
4882 for (; rel
< rel_end
; rel
++)
4889 reloc_howto_type
*howto
;
4890 struct aout_link_hash_entry
*h
= NULL
;
4892 bfd_reloc_status_type r
;
4894 r_addr
= GET_SWORD (input_bfd
, rel
->r_address
);
4896 #ifdef MY_reloc_howto
4897 howto
= MY_reloc_howto (input_bfd
, rel
, r_index
, r_extern
, r_pcrel
);
4903 unsigned int howto_idx
;
4905 if (bfd_header_big_endian (input_bfd
))
4907 r_index
= (((unsigned int) rel
->r_index
[0] << 16)
4908 | ((unsigned int) rel
->r_index
[1] << 8)
4910 r_extern
= (0 != (rel
->r_type
[0] & RELOC_STD_BITS_EXTERN_BIG
));
4911 r_pcrel
= (0 != (rel
->r_type
[0] & RELOC_STD_BITS_PCREL_BIG
));
4912 r_baserel
= (0 != (rel
->r_type
[0] & RELOC_STD_BITS_BASEREL_BIG
));
4913 r_jmptable
= (0 != (rel
->r_type
[0] & RELOC_STD_BITS_JMPTABLE_BIG
));
4914 r_relative
= (0 != (rel
->r_type
[0] & RELOC_STD_BITS_RELATIVE_BIG
));
4915 r_length
= ((rel
->r_type
[0] & RELOC_STD_BITS_LENGTH_BIG
)
4916 >> RELOC_STD_BITS_LENGTH_SH_BIG
);
4920 r_index
= (((unsigned int) rel
->r_index
[2] << 16)
4921 | ((unsigned int) rel
->r_index
[1] << 8)
4923 r_extern
= (0 != (rel
->r_type
[0] & RELOC_STD_BITS_EXTERN_LITTLE
));
4924 r_pcrel
= (0 != (rel
->r_type
[0] & RELOC_STD_BITS_PCREL_LITTLE
));
4925 r_baserel
= (0 != (rel
->r_type
[0]
4926 & RELOC_STD_BITS_BASEREL_LITTLE
));
4927 r_jmptable
= (0 != (rel
->r_type
[0]
4928 & RELOC_STD_BITS_JMPTABLE_LITTLE
));
4929 r_relative
= (0 != (rel
->r_type
[0]
4930 & RELOC_STD_BITS_RELATIVE_LITTLE
));
4931 r_length
= ((rel
->r_type
[0] & RELOC_STD_BITS_LENGTH_LITTLE
)
4932 >> RELOC_STD_BITS_LENGTH_SH_LITTLE
);
4935 howto_idx
= (r_length
+ 4 * r_pcrel
+ 8 * r_baserel
4936 + 16 * r_jmptable
+ 32 * r_relative
);
4937 BFD_ASSERT (howto_idx
< TABLE_SIZE (howto_table_std
));
4938 howto
= howto_table_std
+ howto_idx
;
4944 /* We are generating a relocatable output file, and must
4945 modify the reloc accordingly. */
4948 /* If we know the symbol this relocation is against,
4949 convert it into a relocation against a section. This
4950 is what the native linker does. */
4951 h
= sym_hashes
[r_index
];
4952 if (h
!= (struct aout_link_hash_entry
*) NULL
4953 && (h
->root
.type
== bfd_link_hash_defined
4954 || h
->root
.type
== bfd_link_hash_defweak
))
4956 asection
*output_section
;
4958 /* Change the r_extern value. */
4959 if (bfd_header_big_endian (output_bfd
))
4960 rel
->r_type
[0] &=~ RELOC_STD_BITS_EXTERN_BIG
;
4962 rel
->r_type
[0] &=~ RELOC_STD_BITS_EXTERN_LITTLE
;
4964 /* Compute a new r_index. */
4965 output_section
= h
->root
.u
.def
.section
->output_section
;
4966 if (output_section
== obj_textsec (output_bfd
))
4968 else if (output_section
== obj_datasec (output_bfd
))
4970 else if (output_section
== obj_bsssec (output_bfd
))
4975 /* Add the symbol value and the section VMA to the
4976 addend stored in the contents. */
4977 relocation
= (h
->root
.u
.def
.value
4978 + output_section
->vma
4979 + h
->root
.u
.def
.section
->output_offset
);
4983 /* We must change r_index according to the symbol
4985 r_index
= symbol_map
[r_index
];
4991 /* We decided to strip this symbol, but it
4992 turns out that we can't. Note that we
4993 lose the other and desc information here.
4994 I don't think that will ever matter for a
5000 if (! aout_link_write_other_symbol (h
,
5010 name
= strings
+ GET_WORD (input_bfd
,
5011 syms
[r_index
].e_strx
);
5012 if (! ((*finfo
->info
->callbacks
->unattached_reloc
)
5013 (finfo
->info
, name
, input_bfd
, input_section
,
5023 /* Write out the new r_index value. */
5024 if (bfd_header_big_endian (output_bfd
))
5026 rel
->r_index
[0] = r_index
>> 16;
5027 rel
->r_index
[1] = r_index
>> 8;
5028 rel
->r_index
[2] = r_index
;
5032 rel
->r_index
[2] = r_index
>> 16;
5033 rel
->r_index
[1] = r_index
>> 8;
5034 rel
->r_index
[0] = r_index
;
5041 /* This is a relocation against a section. We must
5042 adjust by the amount that the section moved. */
5043 section
= aout_reloc_index_to_section (input_bfd
, r_index
);
5044 relocation
= (section
->output_section
->vma
5045 + section
->output_offset
5049 /* Change the address of the relocation. */
5050 PUT_WORD (output_bfd
,
5051 r_addr
+ input_section
->output_offset
,
5054 /* Adjust a PC relative relocation by removing the reference
5055 to the original address in the section and including the
5056 reference to the new address. */
5058 relocation
-= (input_section
->output_section
->vma
5059 + input_section
->output_offset
5060 - input_section
->vma
);
5062 #ifdef MY_relocatable_reloc
5063 MY_relocatable_reloc (howto
, output_bfd
, rel
, relocation
, r_addr
);
5066 if (relocation
== 0)
5069 r
= MY_relocate_contents (howto
,
5070 input_bfd
, relocation
,
5077 /* We are generating an executable, and must do a full
5083 h
= sym_hashes
[r_index
];
5085 if (h
!= (struct aout_link_hash_entry
*) NULL
5086 && (h
->root
.type
== bfd_link_hash_defined
5087 || h
->root
.type
== bfd_link_hash_defweak
))
5089 relocation
= (h
->root
.u
.def
.value
5090 + h
->root
.u
.def
.section
->output_section
->vma
5091 + h
->root
.u
.def
.section
->output_offset
);
5093 else if (h
!= (struct aout_link_hash_entry
*) NULL
5094 && h
->root
.type
== bfd_link_hash_undefweak
)
5106 section
= aout_reloc_index_to_section (input_bfd
, r_index
);
5107 relocation
= (section
->output_section
->vma
5108 + section
->output_offset
5111 relocation
+= input_section
->vma
;
5114 if (check_dynamic_reloc
!= NULL
)
5118 if (! ((*check_dynamic_reloc
)
5119 (finfo
->info
, input_bfd
, input_section
, h
,
5120 (PTR
) rel
, contents
, &skip
, &relocation
)))
5126 /* Now warn if a global symbol is undefined. We could not
5127 do this earlier, because check_dynamic_reloc might want
5128 to skip this reloc. */
5129 if (hundef
&& ! finfo
->info
->shared
&& ! r_baserel
)
5134 name
= h
->root
.root
.string
;
5136 name
= strings
+ GET_WORD (input_bfd
, syms
[r_index
].e_strx
);
5137 if (! ((*finfo
->info
->callbacks
->undefined_symbol
)
5138 (finfo
->info
, name
, input_bfd
, input_section
,
5143 r
= MY_final_link_relocate (howto
,
5144 input_bfd
, input_section
,
5145 contents
, r_addr
, relocation
,
5149 if (r
!= bfd_reloc_ok
)
5154 case bfd_reloc_outofrange
:
5156 case bfd_reloc_overflow
:
5161 name
= h
->root
.root
.string
;
5163 name
= strings
+ GET_WORD (input_bfd
,
5164 syms
[r_index
].e_strx
);
5169 s
= aout_reloc_index_to_section (input_bfd
, r_index
);
5170 name
= bfd_section_name (input_bfd
, s
);
5172 if (! ((*finfo
->info
->callbacks
->reloc_overflow
)
5173 (finfo
->info
, name
, howto
->name
,
5174 (bfd_vma
) 0, input_bfd
, input_section
, r_addr
)))
5185 /* Relocate an a.out section using extended a.out relocs. */
5188 aout_link_input_section_ext (finfo
, input_bfd
, input_section
, relocs
,
5190 struct aout_final_link_info
*finfo
;
5192 asection
*input_section
;
5193 struct reloc_ext_external
*relocs
;
5194 bfd_size_type rel_size
;
5197 bfd_boolean (*check_dynamic_reloc
)
5198 PARAMS ((struct bfd_link_info
*, bfd
*, asection
*,
5199 struct aout_link_hash_entry
*, PTR
, bfd_byte
*, bfd_boolean
*,
5202 bfd_boolean relocatable
;
5203 struct external_nlist
*syms
;
5205 struct aout_link_hash_entry
**sym_hashes
;
5207 bfd_size_type reloc_count
;
5208 register struct reloc_ext_external
*rel
;
5209 struct reloc_ext_external
*rel_end
;
5211 output_bfd
= finfo
->output_bfd
;
5212 check_dynamic_reloc
= aout_backend_info (output_bfd
)->check_dynamic_reloc
;
5214 BFD_ASSERT (obj_reloc_entry_size (input_bfd
) == RELOC_EXT_SIZE
);
5215 BFD_ASSERT (input_bfd
->xvec
->header_byteorder
5216 == output_bfd
->xvec
->header_byteorder
);
5218 relocatable
= finfo
->info
->relocatable
;
5219 syms
= obj_aout_external_syms (input_bfd
);
5220 strings
= obj_aout_external_strings (input_bfd
);
5221 sym_hashes
= obj_aout_sym_hashes (input_bfd
);
5222 symbol_map
= finfo
->symbol_map
;
5224 reloc_count
= rel_size
/ RELOC_EXT_SIZE
;
5226 rel_end
= rel
+ reloc_count
;
5227 for (; rel
< rel_end
; rel
++)
5232 unsigned int r_type
;
5234 struct aout_link_hash_entry
*h
= NULL
;
5235 asection
*r_section
= NULL
;
5238 r_addr
= GET_SWORD (input_bfd
, rel
->r_address
);
5240 if (bfd_header_big_endian (input_bfd
))
5242 r_index
= (((unsigned int) rel
->r_index
[0] << 16)
5243 | ((unsigned int) rel
->r_index
[1] << 8)
5245 r_extern
= (0 != (rel
->r_type
[0] & RELOC_EXT_BITS_EXTERN_BIG
));
5246 r_type
= ((rel
->r_type
[0] & RELOC_EXT_BITS_TYPE_BIG
)
5247 >> RELOC_EXT_BITS_TYPE_SH_BIG
);
5251 r_index
= (((unsigned int) rel
->r_index
[2] << 16)
5252 | ((unsigned int) rel
->r_index
[1] << 8)
5254 r_extern
= (0 != (rel
->r_type
[0] & RELOC_EXT_BITS_EXTERN_LITTLE
));
5255 r_type
= ((rel
->r_type
[0] & RELOC_EXT_BITS_TYPE_LITTLE
)
5256 >> RELOC_EXT_BITS_TYPE_SH_LITTLE
);
5259 r_addend
= GET_SWORD (input_bfd
, rel
->r_addend
);
5261 BFD_ASSERT (r_type
< TABLE_SIZE (howto_table_ext
));
5265 /* We are generating a relocatable output file, and must
5266 modify the reloc accordingly. */
5268 || r_type
== (unsigned int) RELOC_BASE10
5269 || r_type
== (unsigned int) RELOC_BASE13
5270 || r_type
== (unsigned int) RELOC_BASE22
)
5272 /* If we know the symbol this relocation is against,
5273 convert it into a relocation against a section. This
5274 is what the native linker does. */
5275 if (r_type
== (unsigned int) RELOC_BASE10
5276 || r_type
== (unsigned int) RELOC_BASE13
5277 || r_type
== (unsigned int) RELOC_BASE22
)
5280 h
= sym_hashes
[r_index
];
5281 if (h
!= (struct aout_link_hash_entry
*) NULL
5282 && (h
->root
.type
== bfd_link_hash_defined
5283 || h
->root
.type
== bfd_link_hash_defweak
))
5285 asection
*output_section
;
5287 /* Change the r_extern value. */
5288 if (bfd_header_big_endian (output_bfd
))
5289 rel
->r_type
[0] &=~ RELOC_EXT_BITS_EXTERN_BIG
;
5291 rel
->r_type
[0] &=~ RELOC_EXT_BITS_EXTERN_LITTLE
;
5293 /* Compute a new r_index. */
5294 output_section
= h
->root
.u
.def
.section
->output_section
;
5295 if (output_section
== obj_textsec (output_bfd
))
5297 else if (output_section
== obj_datasec (output_bfd
))
5299 else if (output_section
== obj_bsssec (output_bfd
))
5304 /* Add the symbol value and the section VMA to the
5306 relocation
= (h
->root
.u
.def
.value
5307 + output_section
->vma
5308 + h
->root
.u
.def
.section
->output_offset
);
5310 /* Now RELOCATION is the VMA of the final
5311 destination. If this is a PC relative reloc,
5312 then ADDEND is the negative of the source VMA.
5313 We want to set ADDEND to the difference between
5314 the destination VMA and the source VMA, which
5315 means we must adjust RELOCATION by the change in
5316 the source VMA. This is done below. */
5320 /* We must change r_index according to the symbol
5322 r_index
= symbol_map
[r_index
];
5328 /* We decided to strip this symbol, but it
5329 turns out that we can't. Note that we
5330 lose the other and desc information here.
5331 I don't think that will ever matter for a
5337 if (! aout_link_write_other_symbol (h
,
5347 name
= strings
+ GET_WORD (input_bfd
,
5348 syms
[r_index
].e_strx
);
5349 if (! ((*finfo
->info
->callbacks
->unattached_reloc
)
5350 (finfo
->info
, name
, input_bfd
, input_section
,
5359 /* If this is a PC relative reloc, then the addend
5360 is the negative of the source VMA. We must
5361 adjust it by the change in the source VMA. This
5365 /* Write out the new r_index value. */
5366 if (bfd_header_big_endian (output_bfd
))
5368 rel
->r_index
[0] = r_index
>> 16;
5369 rel
->r_index
[1] = r_index
>> 8;
5370 rel
->r_index
[2] = r_index
;
5374 rel
->r_index
[2] = r_index
>> 16;
5375 rel
->r_index
[1] = r_index
>> 8;
5376 rel
->r_index
[0] = r_index
;
5381 /* This is a relocation against a section. We must
5382 adjust by the amount that the section moved. */
5383 r_section
= aout_reloc_index_to_section (input_bfd
, r_index
);
5384 relocation
= (r_section
->output_section
->vma
5385 + r_section
->output_offset
5388 /* If this is a PC relative reloc, then the addend is
5389 the difference in VMA between the destination and the
5390 source. We have just adjusted for the change in VMA
5391 of the destination, so we must also adjust by the
5392 change in VMA of the source. This is done below. */
5395 /* As described above, we must always adjust a PC relative
5396 reloc by the change in VMA of the source. However, if
5397 pcrel_offset is set, then the addend does not include the
5398 location within the section, in which case we don't need
5399 to adjust anything. */
5400 if (howto_table_ext
[r_type
].pc_relative
5401 && ! howto_table_ext
[r_type
].pcrel_offset
)
5402 relocation
-= (input_section
->output_section
->vma
5403 + input_section
->output_offset
5404 - input_section
->vma
);
5406 /* Change the addend if necessary. */
5407 if (relocation
!= 0)
5408 PUT_WORD (output_bfd
, r_addend
+ relocation
, rel
->r_addend
);
5410 /* Change the address of the relocation. */
5411 PUT_WORD (output_bfd
,
5412 r_addr
+ input_section
->output_offset
,
5418 bfd_reloc_status_type r
;
5420 /* We are generating an executable, and must do a full
5426 h
= sym_hashes
[r_index
];
5428 if (h
!= (struct aout_link_hash_entry
*) NULL
5429 && (h
->root
.type
== bfd_link_hash_defined
5430 || h
->root
.type
== bfd_link_hash_defweak
))
5432 relocation
= (h
->root
.u
.def
.value
5433 + h
->root
.u
.def
.section
->output_section
->vma
5434 + h
->root
.u
.def
.section
->output_offset
);
5436 else if (h
!= (struct aout_link_hash_entry
*) NULL
5437 && h
->root
.type
== bfd_link_hash_undefweak
)
5445 else if (r_type
== (unsigned int) RELOC_BASE10
5446 || r_type
== (unsigned int) RELOC_BASE13
5447 || r_type
== (unsigned int) RELOC_BASE22
)
5449 struct external_nlist
*sym
;
5452 /* For base relative relocs, r_index is always an index
5453 into the symbol table, even if r_extern is 0. */
5454 sym
= syms
+ r_index
;
5455 type
= H_GET_8 (input_bfd
, sym
->e_type
);
5456 if ((type
& N_TYPE
) == N_TEXT
5458 r_section
= obj_textsec (input_bfd
);
5459 else if ((type
& N_TYPE
) == N_DATA
5461 r_section
= obj_datasec (input_bfd
);
5462 else if ((type
& N_TYPE
) == N_BSS
5464 r_section
= obj_bsssec (input_bfd
);
5465 else if ((type
& N_TYPE
) == N_ABS
5467 r_section
= bfd_abs_section_ptr
;
5470 relocation
= (r_section
->output_section
->vma
5471 + r_section
->output_offset
5472 + (GET_WORD (input_bfd
, sym
->e_value
)
5477 r_section
= aout_reloc_index_to_section (input_bfd
, r_index
);
5479 /* If this is a PC relative reloc, then R_ADDEND is the
5480 difference between the two vmas, or
5481 old_dest_sec + old_dest_off - (old_src_sec + old_src_off)
5483 old_dest_sec == section->vma
5485 old_src_sec == input_section->vma
5487 old_src_off == r_addr
5489 _bfd_final_link_relocate expects RELOCATION +
5490 R_ADDEND to be the VMA of the destination minus
5491 r_addr (the minus r_addr is because this relocation
5492 is not pcrel_offset, which is a bit confusing and
5493 should, perhaps, be changed), or
5496 new_dest_sec == output_section->vma + output_offset
5497 We arrange for this to happen by setting RELOCATION to
5498 new_dest_sec + old_src_sec - old_dest_sec
5500 If this is not a PC relative reloc, then R_ADDEND is
5501 simply the VMA of the destination, so we set
5502 RELOCATION to the change in the destination VMA, or
5503 new_dest_sec - old_dest_sec
5505 relocation
= (r_section
->output_section
->vma
5506 + r_section
->output_offset
5508 if (howto_table_ext
[r_type
].pc_relative
)
5509 relocation
+= input_section
->vma
;
5512 if (check_dynamic_reloc
!= NULL
)
5516 if (! ((*check_dynamic_reloc
)
5517 (finfo
->info
, input_bfd
, input_section
, h
,
5518 (PTR
) rel
, contents
, &skip
, &relocation
)))
5524 /* Now warn if a global symbol is undefined. We could not
5525 do this earlier, because check_dynamic_reloc might want
5526 to skip this reloc. */
5528 && ! finfo
->info
->shared
5529 && r_type
!= (unsigned int) RELOC_BASE10
5530 && r_type
!= (unsigned int) RELOC_BASE13
5531 && r_type
!= (unsigned int) RELOC_BASE22
)
5536 name
= h
->root
.root
.string
;
5538 name
= strings
+ GET_WORD (input_bfd
, syms
[r_index
].e_strx
);
5539 if (! ((*finfo
->info
->callbacks
->undefined_symbol
)
5540 (finfo
->info
, name
, input_bfd
, input_section
,
5545 if (r_type
!= (unsigned int) RELOC_SPARC_REV32
)
5546 r
= MY_final_link_relocate (howto_table_ext
+ r_type
,
5547 input_bfd
, input_section
,
5548 contents
, r_addr
, relocation
,
5554 x
= bfd_get_32 (input_bfd
, contents
+ r_addr
);
5555 x
= x
+ relocation
+ r_addend
;
5556 bfd_putl32 (/*input_bfd,*/ x
, contents
+ r_addr
);
5560 if (r
!= bfd_reloc_ok
)
5565 case bfd_reloc_outofrange
:
5567 case bfd_reloc_overflow
:
5572 name
= h
->root
.root
.string
;
5574 || r_type
== (unsigned int) RELOC_BASE10
5575 || r_type
== (unsigned int) RELOC_BASE13
5576 || r_type
== (unsigned int) RELOC_BASE22
)
5577 name
= strings
+ GET_WORD (input_bfd
,
5578 syms
[r_index
].e_strx
);
5583 s
= aout_reloc_index_to_section (input_bfd
, r_index
);
5584 name
= bfd_section_name (input_bfd
, s
);
5586 if (! ((*finfo
->info
->callbacks
->reloc_overflow
)
5587 (finfo
->info
, name
, howto_table_ext
[r_type
].name
,
5588 r_addend
, input_bfd
, input_section
, r_addr
)))
5600 /* Handle a link order which is supposed to generate a reloc. */
5603 aout_link_reloc_link_order (finfo
, o
, p
)
5604 struct aout_final_link_info
*finfo
;
5606 struct bfd_link_order
*p
;
5608 struct bfd_link_order_reloc
*pr
;
5611 reloc_howto_type
*howto
;
5612 file_ptr
*reloff_ptr
= NULL
;
5613 struct reloc_std_external srel
;
5614 struct reloc_ext_external erel
;
5620 if (p
->type
== bfd_section_reloc_link_order
)
5623 if (bfd_is_abs_section (pr
->u
.section
))
5624 r_index
= N_ABS
| N_EXT
;
5627 BFD_ASSERT (pr
->u
.section
->owner
== finfo
->output_bfd
);
5628 r_index
= pr
->u
.section
->target_index
;
5633 struct aout_link_hash_entry
*h
;
5635 BFD_ASSERT (p
->type
== bfd_symbol_reloc_link_order
);
5637 h
= ((struct aout_link_hash_entry
*)
5638 bfd_wrapped_link_hash_lookup (finfo
->output_bfd
, finfo
->info
,
5639 pr
->u
.name
, FALSE
, FALSE
, TRUE
));
5640 if (h
!= (struct aout_link_hash_entry
*) NULL
5645 /* We decided to strip this symbol, but it turns out that we
5646 can't. Note that we lose the other and desc information
5647 here. I don't think that will ever matter for a global
5651 if (! aout_link_write_other_symbol (h
, (PTR
) finfo
))
5657 if (! ((*finfo
->info
->callbacks
->unattached_reloc
)
5658 (finfo
->info
, pr
->u
.name
, (bfd
*) NULL
,
5659 (asection
*) NULL
, (bfd_vma
) 0)))
5665 howto
= bfd_reloc_type_lookup (finfo
->output_bfd
, pr
->reloc
);
5668 bfd_set_error (bfd_error_bad_value
);
5672 if (o
== obj_textsec (finfo
->output_bfd
))
5673 reloff_ptr
= &finfo
->treloff
;
5674 else if (o
== obj_datasec (finfo
->output_bfd
))
5675 reloff_ptr
= &finfo
->dreloff
;
5679 if (obj_reloc_entry_size (finfo
->output_bfd
) == RELOC_STD_SIZE
)
5682 MY_put_reloc (finfo
->output_bfd
, r_extern
, r_index
, p
->offset
, howto
,
5692 r_pcrel
= (int) howto
->pc_relative
;
5693 r_baserel
= (howto
->type
& 8) != 0;
5694 r_jmptable
= (howto
->type
& 16) != 0;
5695 r_relative
= (howto
->type
& 32) != 0;
5696 r_length
= howto
->size
;
5698 PUT_WORD (finfo
->output_bfd
, p
->offset
, srel
.r_address
);
5699 if (bfd_header_big_endian (finfo
->output_bfd
))
5701 srel
.r_index
[0] = r_index
>> 16;
5702 srel
.r_index
[1] = r_index
>> 8;
5703 srel
.r_index
[2] = r_index
;
5705 ((r_extern
? RELOC_STD_BITS_EXTERN_BIG
: 0)
5706 | (r_pcrel
? RELOC_STD_BITS_PCREL_BIG
: 0)
5707 | (r_baserel
? RELOC_STD_BITS_BASEREL_BIG
: 0)
5708 | (r_jmptable
? RELOC_STD_BITS_JMPTABLE_BIG
: 0)
5709 | (r_relative
? RELOC_STD_BITS_RELATIVE_BIG
: 0)
5710 | (r_length
<< RELOC_STD_BITS_LENGTH_SH_BIG
));
5714 srel
.r_index
[2] = r_index
>> 16;
5715 srel
.r_index
[1] = r_index
>> 8;
5716 srel
.r_index
[0] = r_index
;
5718 ((r_extern
? RELOC_STD_BITS_EXTERN_LITTLE
: 0)
5719 | (r_pcrel
? RELOC_STD_BITS_PCREL_LITTLE
: 0)
5720 | (r_baserel
? RELOC_STD_BITS_BASEREL_LITTLE
: 0)
5721 | (r_jmptable
? RELOC_STD_BITS_JMPTABLE_LITTLE
: 0)
5722 | (r_relative
? RELOC_STD_BITS_RELATIVE_LITTLE
: 0)
5723 | (r_length
<< RELOC_STD_BITS_LENGTH_SH_LITTLE
));
5727 rel_ptr
= (PTR
) &srel
;
5729 /* We have to write the addend into the object file, since
5730 standard a.out relocs are in place. It would be more
5731 reliable if we had the current contents of the file here,
5732 rather than assuming zeroes, but we can't read the file since
5733 it was opened using bfd_openw. */
5734 if (pr
->addend
!= 0)
5737 bfd_reloc_status_type r
;
5741 size
= bfd_get_reloc_size (howto
);
5742 buf
= (bfd_byte
*) bfd_zmalloc (size
);
5743 if (buf
== (bfd_byte
*) NULL
)
5745 r
= MY_relocate_contents (howto
, finfo
->output_bfd
,
5746 (bfd_vma
) pr
->addend
, buf
);
5752 case bfd_reloc_outofrange
:
5754 case bfd_reloc_overflow
:
5755 if (! ((*finfo
->info
->callbacks
->reloc_overflow
)
5757 (p
->type
== bfd_section_reloc_link_order
5758 ? bfd_section_name (finfo
->output_bfd
,
5761 howto
->name
, pr
->addend
, (bfd
*) NULL
,
5762 (asection
*) NULL
, (bfd_vma
) 0)))
5769 ok
= bfd_set_section_contents (finfo
->output_bfd
, o
, (PTR
) buf
,
5770 (file_ptr
) p
->offset
, size
);
5778 #ifdef MY_put_ext_reloc
5779 MY_put_ext_reloc (finfo
->output_bfd
, r_extern
, r_index
, p
->offset
,
5780 howto
, &erel
, pr
->addend
);
5782 PUT_WORD (finfo
->output_bfd
, p
->offset
, erel
.r_address
);
5784 if (bfd_header_big_endian (finfo
->output_bfd
))
5786 erel
.r_index
[0] = r_index
>> 16;
5787 erel
.r_index
[1] = r_index
>> 8;
5788 erel
.r_index
[2] = r_index
;
5790 ((r_extern
? RELOC_EXT_BITS_EXTERN_BIG
: 0)
5791 | (howto
->type
<< RELOC_EXT_BITS_TYPE_SH_BIG
));
5795 erel
.r_index
[2] = r_index
>> 16;
5796 erel
.r_index
[1] = r_index
>> 8;
5797 erel
.r_index
[0] = r_index
;
5799 (r_extern
? RELOC_EXT_BITS_EXTERN_LITTLE
: 0)
5800 | (howto
->type
<< RELOC_EXT_BITS_TYPE_SH_LITTLE
);
5803 PUT_WORD (finfo
->output_bfd
, (bfd_vma
) pr
->addend
, erel
.r_addend
);
5804 #endif /* MY_put_ext_reloc */
5806 rel_ptr
= (PTR
) &erel
;
5809 amt
= obj_reloc_entry_size (finfo
->output_bfd
);
5810 if (bfd_seek (finfo
->output_bfd
, *reloff_ptr
, SEEK_SET
) != 0
5811 || bfd_bwrite (rel_ptr
, amt
, finfo
->output_bfd
) != amt
)
5814 *reloff_ptr
+= obj_reloc_entry_size (finfo
->output_bfd
);
5816 /* Assert that the relocs have not run into the symbols, and that n
5817 the text relocs have not run into the data relocs. */
5818 BFD_ASSERT (*reloff_ptr
<= obj_sym_filepos (finfo
->output_bfd
)
5819 && (reloff_ptr
!= &finfo
->treloff
5821 <= obj_datasec (finfo
->output_bfd
)->rel_filepos
)));