1 /* BFD semi-generic back-end for a.out binaries.
2 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2000,
4 Free Software Foundation, Inc.
5 Written by Cygnus Support.
7 This file is part of BFD, the Binary File Descriptor library.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
29 BFD supports a number of different flavours of a.out format,
30 though the major differences are only the sizes of the
31 structures on disk, and the shape of the relocation
34 The support is split into a basic support file @file{aoutx.h}
35 and other files which derive functions from the base. One
36 derivation file is @file{aoutf1.h} (for a.out flavour 1), and
37 adds to the basic a.out functions support for sun3, sun4, 386
38 and 29k a.out files, to create a target jump vector for a
41 This information is further split out into more specific files
42 for each machine, including @file{sunos.c} for sun3 and sun4,
43 @file{newsos3.c} for the Sony NEWS, and @file{demo64.c} for a
44 demonstration of a 64 bit a.out format.
46 The base file @file{aoutx.h} defines general mechanisms for
47 reading and writing records to and from disk and various
48 other methods which BFD requires. It is included by
49 @file{aout32.c} and @file{aout64.c} to form the names
50 <<aout_32_swap_exec_header_in>>, <<aout_64_swap_exec_header_in>>, etc.
52 As an example, this is what goes on to make the back end for a
53 sun4, from @file{aout32.c}:
55 | #define ARCH_SIZE 32
61 | aout_32_canonicalize_reloc
62 | aout_32_find_nearest_line
64 | aout_32_get_reloc_upper_bound
69 | #define TARGET_NAME "a.out-sunos-big"
70 | #define VECNAME sunos_big_vec
73 requires all the names from @file{aout32.c}, and produces the jump vector
77 The file @file{host-aout.c} is a special case. It is for a large set
78 of hosts that use ``more or less standard'' a.out files, and
79 for which cross-debugging is not interesting. It uses the
80 standard 32-bit a.out support routines, but determines the
81 file offsets and addresses of the text, data, and BSS
82 sections, the machine architecture and machine type, and the
83 entry point address, in a host-dependent manner. Once these
84 values have been determined, generic code is used to handle
87 When porting it to run on a new system, you must supply:
91 | HOST_MACHINE_ARCH (optional)
92 | HOST_MACHINE_MACHINE (optional)
93 | HOST_TEXT_START_ADDR
96 in the file @file{../include/sys/h-@var{XXX}.h} (for your host). These
97 values, plus the structures and macros defined in @file{a.out.h} on
98 your host system, will produce a BFD target that will access
99 ordinary a.out files on your host. To configure a new machine
100 to use @file{host-aout.c}, specify:
102 | TDEFAULTS = -DDEFAULT_VECTOR=host_aout_big_vec
103 | TDEPFILES= host-aout.o trad-core.o
105 in the @file{config/@var{XXX}.mt} file, and modify @file{configure.in}
107 @file{@var{XXX}.mt} file (by setting "<<bfd_target=XXX>>") when your
108 configuration is selected.
113 * Any BFD with D_PAGED set is ZMAGIC, and vice versa.
114 Doesn't matter what the setting of WP_TEXT is on output, but it'll
116 * Any BFD with D_PAGED clear and WP_TEXT set is NMAGIC.
117 * Any BFD with both flags clear is OMAGIC.
118 (Just want to make these explicit, so the conditions tested in this
119 file make sense if you're more familiar with a.out than with BFD.) */
121 #define KEEPIT udata.i
125 #include "safe-ctype.h"
130 #include "aout/aout64.h"
131 #include "aout/stab_gnu.h"
134 static boolean aout_get_external_symbols PARAMS ((bfd *));
135 static boolean translate_from_native_sym_flags
136 PARAMS ((bfd *, aout_symbol_type *));
137 static boolean translate_to_native_sym_flags
138 PARAMS ((bfd *, asymbol *, struct external_nlist *));
139 static void adjust_o_magic PARAMS ((bfd *, struct internal_exec *));
140 static void adjust_z_magic PARAMS ((bfd *, struct internal_exec *));
141 static void adjust_n_magic PARAMS ((bfd *, struct internal_exec *));
142 reloc_howto_type * NAME(aout,reloc_type_lookup)
143 PARAMS ((bfd *, bfd_reloc_code_real_type));
150 The file @file{aoutx.h} provides for both the @emph{standard}
151 and @emph{extended} forms of a.out relocation records.
153 The standard records contain only an
154 address, a symbol index, and a type field. The extended records
155 (used on 29ks and sparcs) also have a full integer for an
159 #ifndef CTOR_TABLE_RELOC_HOWTO
160 #define CTOR_TABLE_RELOC_IDX 2
161 #define CTOR_TABLE_RELOC_HOWTO(BFD) \
162 ((obj_reloc_entry_size (BFD) == RELOC_EXT_SIZE \
163 ? howto_table_ext : howto_table_std) \
164 + CTOR_TABLE_RELOC_IDX)
167 #ifndef MY_swap_std_reloc_in
168 #define MY_swap_std_reloc_in NAME(aout,swap_std_reloc_in)
171 #ifndef MY_swap_ext_reloc_in
172 #define MY_swap_ext_reloc_in NAME(aout,swap_ext_reloc_in)
175 #ifndef MY_swap_std_reloc_out
176 #define MY_swap_std_reloc_out NAME(aout,swap_std_reloc_out)
179 #ifndef MY_swap_ext_reloc_out
180 #define MY_swap_ext_reloc_out NAME(aout,swap_ext_reloc_out)
183 #ifndef MY_final_link_relocate
184 #define MY_final_link_relocate _bfd_final_link_relocate
187 #ifndef MY_relocate_contents
188 #define MY_relocate_contents _bfd_relocate_contents
191 #define howto_table_ext NAME(aout,ext_howto_table)
192 #define howto_table_std NAME(aout,std_howto_table)
194 reloc_howto_type howto_table_ext[] =
196 /* type rs size bsz pcrel bitpos ovrf sf name part_inpl readmask setmask pcdone. */
197 HOWTO(RELOC_8, 0, 0, 8, false, 0, complain_overflow_bitfield,0,"8", false, 0,0x000000ff, false),
198 HOWTO(RELOC_16, 0, 1, 16, false, 0, complain_overflow_bitfield,0,"16", false, 0,0x0000ffff, false),
199 HOWTO(RELOC_32, 0, 2, 32, false, 0, complain_overflow_bitfield,0,"32", false, 0,0xffffffff, false),
200 HOWTO(RELOC_DISP8, 0, 0, 8, true, 0, complain_overflow_signed,0,"DISP8", false, 0,0x000000ff, false),
201 HOWTO(RELOC_DISP16, 0, 1, 16, true, 0, complain_overflow_signed,0,"DISP16", false, 0,0x0000ffff, false),
202 HOWTO(RELOC_DISP32, 0, 2, 32, true, 0, complain_overflow_signed,0,"DISP32", false, 0,0xffffffff, false),
203 HOWTO(RELOC_WDISP30,2, 2, 30, true, 0, complain_overflow_signed,0,"WDISP30", false, 0,0x3fffffff, false),
204 HOWTO(RELOC_WDISP22,2, 2, 22, true, 0, complain_overflow_signed,0,"WDISP22", false, 0,0x003fffff, false),
205 HOWTO(RELOC_HI22, 10, 2, 22, false, 0, complain_overflow_bitfield,0,"HI22", false, 0,0x003fffff, false),
206 HOWTO(RELOC_22, 0, 2, 22, false, 0, complain_overflow_bitfield,0,"22", false, 0,0x003fffff, false),
207 HOWTO(RELOC_13, 0, 2, 13, false, 0, complain_overflow_bitfield,0,"13", false, 0,0x00001fff, false),
208 HOWTO(RELOC_LO10, 0, 2, 10, false, 0, complain_overflow_dont,0,"LO10", false, 0,0x000003ff, false),
209 HOWTO(RELOC_SFA_BASE,0, 2, 32, false, 0, complain_overflow_bitfield,0,"SFA_BASE", false, 0,0xffffffff, false),
210 HOWTO(RELOC_SFA_OFF13,0,2, 32, false, 0, complain_overflow_bitfield,0,"SFA_OFF13",false, 0,0xffffffff, false),
211 HOWTO(RELOC_BASE10, 0, 2, 10, false, 0, complain_overflow_dont,0,"BASE10", false, 0,0x000003ff, false),
212 HOWTO(RELOC_BASE13, 0, 2, 13, false, 0, complain_overflow_signed,0,"BASE13", false, 0,0x00001fff, false),
213 HOWTO(RELOC_BASE22, 10, 2, 22, false, 0, complain_overflow_bitfield,0,"BASE22", false, 0,0x003fffff, false),
214 HOWTO(RELOC_PC10, 0, 2, 10, true, 0, complain_overflow_dont,0,"PC10", false, 0,0x000003ff, true),
215 HOWTO(RELOC_PC22, 10, 2, 22, true, 0, complain_overflow_signed,0,"PC22", false, 0,0x003fffff, true),
216 HOWTO(RELOC_JMP_TBL,2, 2, 30, true, 0, complain_overflow_signed,0,"JMP_TBL", false, 0,0x3fffffff, false),
217 HOWTO(RELOC_SEGOFF16,0, 2, 0, false, 0, complain_overflow_bitfield,0,"SEGOFF16", false, 0,0x00000000, false),
218 HOWTO(RELOC_GLOB_DAT,0, 2, 0, false, 0, complain_overflow_bitfield,0,"GLOB_DAT", false, 0,0x00000000, false),
219 HOWTO(RELOC_JMP_SLOT,0, 2, 0, false, 0, complain_overflow_bitfield,0,"JMP_SLOT", false, 0,0x00000000, false),
220 HOWTO(RELOC_RELATIVE,0, 2, 0, false, 0, complain_overflow_bitfield,0,"RELATIVE", false, 0,0x00000000, false),
221 HOWTO(0, 0, 0, 0, false, 0, complain_overflow_dont, 0, "R_SPARC_NONE", false,0,0x00000000,true),
222 HOWTO(0, 0, 0, 0, false, 0, complain_overflow_dont, 0, "R_SPARC_NONE", false,0,0x00000000,true),
223 #define RELOC_SPARC_REV32 RELOC_WDISP19
224 HOWTO(RELOC_SPARC_REV32, 0, 2, 32, false, 0, complain_overflow_dont,0,"R_SPARC_REV32", false, 0,0xffffffff, false),
227 /* Convert standard reloc records to "arelent" format (incl byte swap). */
229 reloc_howto_type howto_table_std[] = {
230 /* type rs size bsz pcrel bitpos ovrf sf name part_inpl readmask setmask pcdone. */
231 HOWTO ( 0, 0, 0, 8, false, 0, complain_overflow_bitfield,0,"8", true, 0x000000ff,0x000000ff, false),
232 HOWTO ( 1, 0, 1, 16, false, 0, complain_overflow_bitfield,0,"16", true, 0x0000ffff,0x0000ffff, false),
233 HOWTO ( 2, 0, 2, 32, false, 0, complain_overflow_bitfield,0,"32", true, 0xffffffff,0xffffffff, false),
234 HOWTO ( 3, 0, 4, 64, false, 0, complain_overflow_bitfield,0,"64", true, 0xdeaddead,0xdeaddead, false),
235 HOWTO ( 4, 0, 0, 8, true, 0, complain_overflow_signed, 0,"DISP8", true, 0x000000ff,0x000000ff, false),
236 HOWTO ( 5, 0, 1, 16, true, 0, complain_overflow_signed, 0,"DISP16", true, 0x0000ffff,0x0000ffff, false),
237 HOWTO ( 6, 0, 2, 32, true, 0, complain_overflow_signed, 0,"DISP32", true, 0xffffffff,0xffffffff, false),
238 HOWTO ( 7, 0, 4, 64, true, 0, complain_overflow_signed, 0,"DISP64", true, 0xfeedface,0xfeedface, false),
239 HOWTO ( 8, 0, 2, 0, false, 0, complain_overflow_bitfield,0,"GOT_REL", false, 0,0x00000000, false),
240 HOWTO ( 9, 0, 1, 16, false, 0, complain_overflow_bitfield,0,"BASE16", false,0xffffffff,0xffffffff, false),
241 HOWTO (10, 0, 2, 32, false, 0, complain_overflow_bitfield,0,"BASE32", false,0xffffffff,0xffffffff, false),
247 HOWTO (16, 0, 2, 0, false, 0, complain_overflow_bitfield,0,"JMP_TABLE", false, 0,0x00000000, false),
263 HOWTO (32, 0, 2, 0, false, 0, complain_overflow_bitfield,0,"RELATIVE", false, 0,0x00000000, false),
271 HOWTO (40, 0, 2, 0, false, 0, complain_overflow_bitfield,0,"BASEREL", false, 0,0x00000000, false),
274 #define TABLE_SIZE(TABLE) (sizeof (TABLE) / sizeof (TABLE[0]))
277 NAME(aout,reloc_type_lookup) (abfd,code)
279 bfd_reloc_code_real_type code;
281 #define EXT(i, j) case i: return &howto_table_ext[j]
282 #define STD(i, j) case i: return &howto_table_std[j]
283 int ext = obj_reloc_entry_size (abfd) == RELOC_EXT_SIZE;
285 if (code == BFD_RELOC_CTOR)
286 switch (bfd_get_arch_info (abfd)->bits_per_address)
299 EXT (BFD_RELOC_8, 0);
300 EXT (BFD_RELOC_16, 1);
301 EXT (BFD_RELOC_32, 2);
302 EXT (BFD_RELOC_HI22, 8);
303 EXT (BFD_RELOC_LO10, 11);
304 EXT (BFD_RELOC_32_PCREL_S2, 6);
305 EXT (BFD_RELOC_SPARC_WDISP22, 7);
306 EXT (BFD_RELOC_SPARC13, 10);
307 EXT (BFD_RELOC_SPARC_GOT10, 14);
308 EXT (BFD_RELOC_SPARC_BASE13, 15);
309 EXT (BFD_RELOC_SPARC_GOT13, 15);
310 EXT (BFD_RELOC_SPARC_GOT22, 16);
311 EXT (BFD_RELOC_SPARC_PC10, 17);
312 EXT (BFD_RELOC_SPARC_PC22, 18);
313 EXT (BFD_RELOC_SPARC_WPLT30, 19);
314 EXT (BFD_RELOC_SPARC_REV32, 26);
315 default: return (reloc_howto_type *) NULL;
321 STD (BFD_RELOC_8, 0);
322 STD (BFD_RELOC_16, 1);
323 STD (BFD_RELOC_32, 2);
324 STD (BFD_RELOC_8_PCREL, 4);
325 STD (BFD_RELOC_16_PCREL, 5);
326 STD (BFD_RELOC_32_PCREL, 6);
327 STD (BFD_RELOC_16_BASEREL, 9);
328 STD (BFD_RELOC_32_BASEREL, 10);
329 default: return (reloc_howto_type *) NULL;
335 Internal entry points
338 @file{aoutx.h} exports several routines for accessing the
339 contents of an a.out file, which are gathered and exported in
340 turn by various format specific files (eg sunos.c).
346 aout_@var{size}_swap_exec_header_in
349 void aout_@var{size}_swap_exec_header_in,
351 struct external_exec *raw_bytes,
352 struct internal_exec *execp);
355 Swap the information in an executable header @var{raw_bytes} taken
356 from a raw byte stream memory image into the internal exec header
357 structure @var{execp}.
360 #ifndef NAME_swap_exec_header_in
362 NAME(aout,swap_exec_header_in) (abfd, raw_bytes, execp)
364 struct external_exec *raw_bytes;
365 struct internal_exec *execp;
367 struct external_exec *bytes = (struct external_exec *)raw_bytes;
369 /* The internal_exec structure has some fields that are unused in this
370 configuration (IE for i960), so ensure that all such uninitialized
371 fields are zero'd out. There are places where two of these structs
372 are memcmp'd, and thus the contents do matter. */
373 memset ((PTR) execp, 0, sizeof (struct internal_exec));
374 /* Now fill in fields in the execp, from the bytes in the raw data. */
375 execp->a_info = H_GET_32 (abfd, bytes->e_info);
376 execp->a_text = GET_WORD (abfd, bytes->e_text);
377 execp->a_data = GET_WORD (abfd, bytes->e_data);
378 execp->a_bss = GET_WORD (abfd, bytes->e_bss);
379 execp->a_syms = GET_WORD (abfd, bytes->e_syms);
380 execp->a_entry = GET_WORD (abfd, bytes->e_entry);
381 execp->a_trsize = GET_WORD (abfd, bytes->e_trsize);
382 execp->a_drsize = GET_WORD (abfd, bytes->e_drsize);
384 #define NAME_swap_exec_header_in NAME(aout,swap_exec_header_in)
389 aout_@var{size}_swap_exec_header_out
392 void aout_@var{size}_swap_exec_header_out
394 struct internal_exec *execp,
395 struct external_exec *raw_bytes);
398 Swap the information in an internal exec header structure
399 @var{execp} into the buffer @var{raw_bytes} ready for writing to disk.
402 NAME(aout,swap_exec_header_out) (abfd, execp, raw_bytes)
404 struct internal_exec *execp;
405 struct external_exec *raw_bytes;
407 struct external_exec *bytes = (struct external_exec *)raw_bytes;
409 /* Now fill in fields in the raw data, from the fields in the exec struct. */
410 H_PUT_32 (abfd, execp->a_info , bytes->e_info);
411 PUT_WORD (abfd, execp->a_text , bytes->e_text);
412 PUT_WORD (abfd, execp->a_data , bytes->e_data);
413 PUT_WORD (abfd, execp->a_bss , bytes->e_bss);
414 PUT_WORD (abfd, execp->a_syms , bytes->e_syms);
415 PUT_WORD (abfd, execp->a_entry , bytes->e_entry);
416 PUT_WORD (abfd, execp->a_trsize, bytes->e_trsize);
417 PUT_WORD (abfd, execp->a_drsize, bytes->e_drsize);
420 /* Make all the section for an a.out file. */
423 NAME(aout,make_sections) (abfd)
426 if (obj_textsec (abfd) == (asection *) NULL
427 && bfd_make_section (abfd, ".text") == (asection *) NULL)
429 if (obj_datasec (abfd) == (asection *) NULL
430 && bfd_make_section (abfd, ".data") == (asection *) NULL)
432 if (obj_bsssec (abfd) == (asection *) NULL
433 && bfd_make_section (abfd, ".bss") == (asection *) NULL)
440 aout_@var{size}_some_aout_object_p
443 const bfd_target *aout_@var{size}_some_aout_object_p
445 const bfd_target *(*callback_to_real_object_p) ());
448 Some a.out variant thinks that the file open in @var{abfd}
449 checking is an a.out file. Do some more checking, and set up
450 for access if it really is. Call back to the calling
451 environment's "finish up" function just before returning, to
452 handle any last-minute setup.
456 NAME(aout,some_aout_object_p) (abfd, execp, callback_to_real_object_p)
458 struct internal_exec *execp;
459 const bfd_target *(*callback_to_real_object_p) PARAMS ((bfd *));
461 struct aout_data_struct *rawptr, *oldrawptr;
462 const bfd_target *result;
463 bfd_size_type amt = sizeof (struct aout_data_struct);
465 rawptr = (struct aout_data_struct *) bfd_zalloc (abfd, amt);
469 oldrawptr = abfd->tdata.aout_data;
470 abfd->tdata.aout_data = rawptr;
472 /* Copy the contents of the old tdata struct.
473 In particular, we want the subformat, since for hpux it was set in
474 hp300hpux.c:swap_exec_header_in and will be used in
475 hp300hpux.c:callback. */
476 if (oldrawptr != NULL)
477 *abfd->tdata.aout_data = *oldrawptr;
479 abfd->tdata.aout_data->a.hdr = &rawptr->e;
480 /* Copy in the internal_exec struct. */
481 *(abfd->tdata.aout_data->a.hdr) = *execp;
482 execp = abfd->tdata.aout_data->a.hdr;
484 /* Set the file flags. */
485 abfd->flags = BFD_NO_FLAGS;
486 if (execp->a_drsize || execp->a_trsize)
487 abfd->flags |= HAS_RELOC;
488 /* Setting of EXEC_P has been deferred to the bottom of this function. */
490 abfd->flags |= HAS_LINENO | HAS_DEBUG | HAS_SYMS | HAS_LOCALS;
491 if (N_DYNAMIC (*execp))
492 abfd->flags |= DYNAMIC;
494 if (N_MAGIC (*execp) == ZMAGIC)
496 abfd->flags |= D_PAGED | WP_TEXT;
497 adata (abfd).magic = z_magic;
499 else if (N_MAGIC (*execp) == QMAGIC)
501 abfd->flags |= D_PAGED | WP_TEXT;
502 adata (abfd).magic = z_magic;
503 adata (abfd).subformat = q_magic_format;
505 else if (N_MAGIC (*execp) == NMAGIC)
507 abfd->flags |= WP_TEXT;
508 adata (abfd).magic = n_magic;
510 else if (N_MAGIC (*execp) == OMAGIC
511 || N_MAGIC (*execp) == BMAGIC)
512 adata (abfd).magic = o_magic;
515 /* Should have been checked with N_BADMAG before this routine
520 bfd_get_start_address (abfd) = execp->a_entry;
522 obj_aout_symbols (abfd) = (aout_symbol_type *)NULL;
523 bfd_get_symcount (abfd) = execp->a_syms / sizeof (struct external_nlist);
525 /* The default relocation entry size is that of traditional V7 Unix. */
526 obj_reloc_entry_size (abfd) = RELOC_STD_SIZE;
528 /* The default symbol entry size is that of traditional Unix. */
529 obj_symbol_entry_size (abfd) = EXTERNAL_NLIST_SIZE;
532 bfd_init_window (&obj_aout_sym_window (abfd));
533 bfd_init_window (&obj_aout_string_window (abfd));
535 obj_aout_external_syms (abfd) = NULL;
536 obj_aout_external_strings (abfd) = NULL;
537 obj_aout_sym_hashes (abfd) = NULL;
539 if (! NAME(aout,make_sections) (abfd))
542 obj_datasec (abfd)->_raw_size = execp->a_data;
543 obj_bsssec (abfd)->_raw_size = execp->a_bss;
545 obj_textsec (abfd)->flags =
546 (execp->a_trsize != 0
547 ? (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS | SEC_RELOC)
548 : (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS));
549 obj_datasec (abfd)->flags =
550 (execp->a_drsize != 0
551 ? (SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_HAS_CONTENTS | SEC_RELOC)
552 : (SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_HAS_CONTENTS));
553 obj_bsssec (abfd)->flags = SEC_ALLOC;
555 #ifdef THIS_IS_ONLY_DOCUMENTATION
556 /* The common code can't fill in these things because they depend
557 on either the start address of the text segment, the rounding
558 up of virtual addresses between segments, or the starting file
559 position of the text segment -- all of which varies among different
560 versions of a.out. */
562 /* Call back to the format-dependent code to fill in the rest of the
563 fields and do any further cleanup. Things that should be filled
564 in by the callback: */
566 struct exec *execp = exec_hdr (abfd);
568 obj_textsec (abfd)->size = N_TXTSIZE (*execp);
569 obj_textsec (abfd)->raw_size = N_TXTSIZE (*execp);
570 /* Data and bss are already filled in since they're so standard. */
572 /* The virtual memory addresses of the sections. */
573 obj_textsec (abfd)->vma = N_TXTADDR (*execp);
574 obj_datasec (abfd)->vma = N_DATADDR (*execp);
575 obj_bsssec (abfd)->vma = N_BSSADDR (*execp);
577 /* The file offsets of the sections. */
578 obj_textsec (abfd)->filepos = N_TXTOFF (*execp);
579 obj_datasec (abfd)->filepos = N_DATOFF (*execp);
581 /* The file offsets of the relocation info. */
582 obj_textsec (abfd)->rel_filepos = N_TRELOFF (*execp);
583 obj_datasec (abfd)->rel_filepos = N_DRELOFF (*execp);
585 /* The file offsets of the string table and symbol table. */
586 obj_str_filepos (abfd) = N_STROFF (*execp);
587 obj_sym_filepos (abfd) = N_SYMOFF (*execp);
589 /* Determine the architecture and machine type of the object file. */
590 switch (N_MACHTYPE (*exec_hdr (abfd)))
593 abfd->obj_arch = bfd_arch_obscure;
597 adata (abfd)->page_size = TARGET_PAGE_SIZE;
598 adata (abfd)->segment_size = SEGMENT_SIZE;
599 adata (abfd)->exec_bytes_size = EXEC_BYTES_SIZE;
603 /* The architecture is encoded in various ways in various a.out variants,
604 or is not encoded at all in some of them. The relocation size depends
605 on the architecture and the a.out variant. Finally, the return value
606 is the bfd_target vector in use. If an error occurs, return zero and
607 set bfd_error to the appropriate error code.
609 Formats such as b.out, which have additional fields in the a.out
610 header, should cope with them in this callback as well. */
611 #endif /* DOCUMENTATION */
613 result = (*callback_to_real_object_p) (abfd);
615 /* Now that the segment addresses have been worked out, take a better
616 guess at whether the file is executable. If the entry point
617 is within the text segment, assume it is. (This makes files
618 executable even if their entry point address is 0, as long as
619 their text starts at zero.).
621 This test had to be changed to deal with systems where the text segment
622 runs at a different location than the default. The problem is that the
623 entry address can appear to be outside the text segment, thus causing an
624 erroneous conclusion that the file isn't executable.
626 To fix this, we now accept any non-zero entry point as an indication of
627 executability. This will work most of the time, since only the linker
628 sets the entry point, and that is likely to be non-zero for most systems. */
630 if (execp->a_entry != 0
631 || (execp->a_entry >= obj_textsec (abfd)->vma
632 && execp->a_entry < (obj_textsec (abfd)->vma
633 + obj_textsec (abfd)->_raw_size)))
634 abfd->flags |= EXEC_P;
638 struct stat stat_buf;
640 /* The original heuristic doesn't work in some important cases.
641 The a.out file has no information about the text start
642 address. For files (like kernels) linked to non-standard
643 addresses (ld -Ttext nnn) the entry point may not be between
644 the default text start (obj_textsec(abfd)->vma) and
645 (obj_textsec(abfd)->vma) + text size. This is not just a mach
646 issue. Many kernels are loaded at non standard addresses. */
647 if (abfd->iostream != NULL
648 && (abfd->flags & BFD_IN_MEMORY) == 0
649 && (fstat (fileno ((FILE *) (abfd->iostream)), &stat_buf) == 0)
650 && ((stat_buf.st_mode & 0111) != 0))
651 abfd->flags |= EXEC_P;
653 #endif /* STAT_FOR_EXEC */
657 #if 0 /* These should be set correctly anyways. */
658 abfd->sections = obj_textsec (abfd);
659 obj_textsec (abfd)->next = obj_datasec (abfd);
660 obj_datasec (abfd)->next = obj_bsssec (abfd);
666 bfd_release (abfd, rawptr);
667 abfd->tdata.aout_data = oldrawptr;
673 aout_@var{size}_mkobject
676 boolean aout_@var{size}_mkobject, (bfd *abfd);
679 Initialize BFD @var{abfd} for use with a.out files.
683 NAME(aout,mkobject) (abfd)
686 struct aout_data_struct *rawptr;
687 bfd_size_type amt = sizeof (struct aout_data_struct);
689 bfd_set_error (bfd_error_system_call);
691 rawptr = (struct aout_data_struct *) bfd_zalloc (abfd, amt);
695 abfd->tdata.aout_data = rawptr;
696 exec_hdr (abfd) = &(rawptr->e);
698 obj_textsec (abfd) = (asection *) NULL;
699 obj_datasec (abfd) = (asection *) NULL;
700 obj_bsssec (abfd) = (asection *) NULL;
707 aout_@var{size}_machine_type
710 enum machine_type aout_@var{size}_machine_type
711 (enum bfd_architecture arch,
712 unsigned long machine));
715 Keep track of machine architecture and machine type for
716 a.out's. Return the <<machine_type>> for a particular
717 architecture and machine, or <<M_UNKNOWN>> if that exact architecture
718 and machine can't be represented in a.out format.
720 If the architecture is understood, machine type 0 (default)
721 is always understood.
725 NAME(aout,machine_type) (arch, machine, unknown)
726 enum bfd_architecture arch;
727 unsigned long machine;
730 enum machine_type arch_flags;
732 arch_flags = M_UNKNOWN;
739 || machine == bfd_mach_sparc
740 || machine == bfd_mach_sparc_sparclite
741 || machine == bfd_mach_sparc_sparclite_le
742 || machine == bfd_mach_sparc_v9)
743 arch_flags = M_SPARC;
744 else if (machine == bfd_mach_sparc_sparclet)
745 arch_flags = M_SPARCLET;
751 case 0: arch_flags = M_68010; break;
752 case bfd_mach_m68000: arch_flags = M_UNKNOWN; *unknown = false; break;
753 case bfd_mach_m68010: arch_flags = M_68010; break;
754 case bfd_mach_m68020: arch_flags = M_68020; break;
755 default: arch_flags = M_UNKNOWN; break;
778 case bfd_mach_mips3000:
779 case bfd_mach_mips3900:
780 arch_flags = M_MIPS1;
782 case bfd_mach_mips6000:
783 arch_flags = M_MIPS2;
785 case bfd_mach_mips4000:
786 case bfd_mach_mips4010:
787 case bfd_mach_mips4100:
788 case bfd_mach_mips4300:
789 case bfd_mach_mips4400:
790 case bfd_mach_mips4600:
791 case bfd_mach_mips4650:
792 case bfd_mach_mips8000:
793 case bfd_mach_mips10000:
794 case bfd_mach_mips12000:
795 case bfd_mach_mips16:
796 case bfd_mach_mipsisa32:
798 case bfd_mach_mipsisa64:
799 case bfd_mach_mips_sb1:
800 /* FIXME: These should be MIPS3, MIPS4, MIPS16, MIPS32, etc. */
801 arch_flags = M_MIPS2;
804 arch_flags = M_UNKNOWN;
812 case 0: arch_flags = M_NS32532; break;
813 case 32032: arch_flags = M_NS32032; break;
814 case 32532: arch_flags = M_NS32532; break;
815 default: arch_flags = M_UNKNOWN; break;
824 if (machine == 0 || machine == 255)
829 arch_flags = M_UNKNOWN;
832 if (arch_flags != M_UNKNOWN)
840 aout_@var{size}_set_arch_mach
843 boolean aout_@var{size}_set_arch_mach,
845 enum bfd_architecture arch,
846 unsigned long machine));
849 Set the architecture and the machine of the BFD @var{abfd} to the
850 values @var{arch} and @var{machine}. Verify that @var{abfd}'s format
851 can support the architecture required.
855 NAME(aout,set_arch_mach) (abfd, arch, machine)
857 enum bfd_architecture arch;
858 unsigned long machine;
860 if (! bfd_default_set_arch_mach (abfd, arch, machine))
863 if (arch != bfd_arch_unknown)
867 NAME(aout,machine_type) (arch, machine, &unknown);
872 /* Determine the size of a relocation entry. */
878 obj_reloc_entry_size (abfd) = RELOC_EXT_SIZE;
881 obj_reloc_entry_size (abfd) = RELOC_STD_SIZE;
885 return (*aout_backend_info (abfd)->set_sizes) (abfd);
889 adjust_o_magic (abfd, execp)
891 struct internal_exec *execp;
893 file_ptr pos = adata (abfd).exec_bytes_size;
898 obj_textsec (abfd)->filepos = pos;
899 if (!obj_textsec (abfd)->user_set_vma)
900 obj_textsec (abfd)->vma = vma;
902 vma = obj_textsec (abfd)->vma;
904 pos += obj_textsec (abfd)->_raw_size;
905 vma += obj_textsec (abfd)->_raw_size;
908 if (!obj_datasec (abfd)->user_set_vma)
910 #if 0 /* ?? Does alignment in the file image really matter? */
911 pad = align_power (vma, obj_datasec (abfd)->alignment_power) - vma;
913 obj_textsec (abfd)->_raw_size += pad;
916 obj_datasec (abfd)->vma = vma;
919 vma = obj_datasec (abfd)->vma;
920 obj_datasec (abfd)->filepos = pos;
921 pos += obj_datasec (abfd)->_raw_size;
922 vma += obj_datasec (abfd)->_raw_size;
925 if (!obj_bsssec (abfd)->user_set_vma)
928 pad = align_power (vma, obj_bsssec (abfd)->alignment_power) - vma;
930 obj_datasec (abfd)->_raw_size += pad;
933 obj_bsssec (abfd)->vma = vma;
937 /* The VMA of the .bss section is set by the VMA of the
938 .data section plus the size of the .data section. We may
939 need to add padding bytes to make this true. */
940 pad = obj_bsssec (abfd)->vma - vma;
943 obj_datasec (abfd)->_raw_size += pad;
947 obj_bsssec (abfd)->filepos = pos;
949 /* Fix up the exec header. */
950 execp->a_text = obj_textsec (abfd)->_raw_size;
951 execp->a_data = obj_datasec (abfd)->_raw_size;
952 execp->a_bss = obj_bsssec (abfd)->_raw_size;
953 N_SET_MAGIC (*execp, OMAGIC);
957 adjust_z_magic (abfd, execp)
959 struct internal_exec *execp;
961 bfd_size_type data_pad, text_pad;
963 const struct aout_backend_data *abdp;
964 int ztih; /* Nonzero if text includes exec header. */
966 abdp = aout_backend_info (abfd);
970 && (abdp->text_includes_header
971 || obj_aout_subformat (abfd) == q_magic_format));
972 obj_textsec (abfd)->filepos = (ztih
973 ? adata (abfd).exec_bytes_size
974 : adata (abfd).zmagic_disk_block_size);
975 if (! obj_textsec (abfd)->user_set_vma)
977 /* ?? Do we really need to check for relocs here? */
978 obj_textsec (abfd)->vma = ((abfd->flags & HAS_RELOC)
981 ? (abdp->default_text_vma
982 + adata (abfd).exec_bytes_size)
983 : abdp->default_text_vma));
988 /* The .text section is being loaded at an unusual address. We
989 may need to pad it such that the .data section starts at a page
992 text_pad = ((obj_textsec (abfd)->filepos - obj_textsec (abfd)->vma)
993 & (adata (abfd).page_size - 1));
995 text_pad = ((- obj_textsec (abfd)->vma)
996 & (adata (abfd).page_size - 1));
999 /* Find start of data. */
1002 text_end = obj_textsec (abfd)->filepos + obj_textsec (abfd)->_raw_size;
1003 text_pad += BFD_ALIGN (text_end, adata (abfd).page_size) - text_end;
1007 /* Note that if page_size == zmagic_disk_block_size, then
1008 filepos == page_size, and this case is the same as the ztih
1010 text_end = obj_textsec (abfd)->_raw_size;
1011 text_pad += BFD_ALIGN (text_end, adata (abfd).page_size) - text_end;
1012 text_end += obj_textsec (abfd)->filepos;
1014 obj_textsec (abfd)->_raw_size += text_pad;
1015 text_end += text_pad;
1018 if (!obj_datasec (abfd)->user_set_vma)
1021 vma = obj_textsec (abfd)->vma + obj_textsec (abfd)->_raw_size;
1022 obj_datasec (abfd)->vma = BFD_ALIGN (vma, adata (abfd).segment_size);
1024 if (abdp && abdp->zmagic_mapped_contiguous)
1026 asection * text = obj_textsec (abfd);
1027 asection * data = obj_datasec (abfd);
1029 text_pad = data->vma - (text->vma + text->_raw_size);
1030 /* Only pad the text section if the data
1031 section is going to be placed after it. */
1033 text->_raw_size += text_pad;
1035 obj_datasec (abfd)->filepos = (obj_textsec (abfd)->filepos
1036 + obj_textsec (abfd)->_raw_size);
1038 /* Fix up exec header while we're at it. */
1039 execp->a_text = obj_textsec (abfd)->_raw_size;
1040 if (ztih && (!abdp || (abdp && !abdp->exec_header_not_counted)))
1041 execp->a_text += adata (abfd).exec_bytes_size;
1042 if (obj_aout_subformat (abfd) == q_magic_format)
1043 N_SET_MAGIC (*execp, QMAGIC);
1045 N_SET_MAGIC (*execp, ZMAGIC);
1047 /* Spec says data section should be rounded up to page boundary. */
1048 obj_datasec (abfd)->_raw_size
1049 = align_power (obj_datasec (abfd)->_raw_size,
1050 obj_bsssec (abfd)->alignment_power);
1051 execp->a_data = BFD_ALIGN (obj_datasec (abfd)->_raw_size,
1052 adata (abfd).page_size);
1053 data_pad = execp->a_data - obj_datasec (abfd)->_raw_size;
1056 if (!obj_bsssec (abfd)->user_set_vma)
1057 obj_bsssec (abfd)->vma = (obj_datasec (abfd)->vma
1058 + obj_datasec (abfd)->_raw_size);
1059 /* If the BSS immediately follows the data section and extra space
1060 in the page is left after the data section, fudge data
1061 in the header so that the bss section looks smaller by that
1062 amount. We'll start the bss section there, and lie to the OS.
1063 (Note that a linker script, as well as the above assignment,
1064 could have explicitly set the BSS vma to immediately follow
1065 the data section.) */
1066 if (align_power (obj_bsssec (abfd)->vma, obj_bsssec (abfd)->alignment_power)
1067 == obj_datasec (abfd)->vma + obj_datasec (abfd)->_raw_size)
1068 execp->a_bss = (data_pad > obj_bsssec (abfd)->_raw_size
1069 ? 0 : obj_bsssec (abfd)->_raw_size - data_pad);
1071 execp->a_bss = obj_bsssec (abfd)->_raw_size;
1075 adjust_n_magic (abfd, execp)
1077 struct internal_exec *execp;
1079 file_ptr pos = adata (abfd).exec_bytes_size;
1084 obj_textsec (abfd)->filepos = pos;
1085 if (!obj_textsec (abfd)->user_set_vma)
1086 obj_textsec (abfd)->vma = vma;
1088 vma = obj_textsec (abfd)->vma;
1089 pos += obj_textsec (abfd)->_raw_size;
1090 vma += obj_textsec (abfd)->_raw_size;
1093 obj_datasec (abfd)->filepos = pos;
1094 if (!obj_datasec (abfd)->user_set_vma)
1095 obj_datasec (abfd)->vma = BFD_ALIGN (vma, adata (abfd).segment_size);
1096 vma = obj_datasec (abfd)->vma;
1098 /* Since BSS follows data immediately, see if it needs alignment. */
1099 vma += obj_datasec (abfd)->_raw_size;
1100 pad = align_power (vma, obj_bsssec (abfd)->alignment_power) - vma;
1101 obj_datasec (abfd)->_raw_size += pad;
1102 pos += obj_datasec (abfd)->_raw_size;
1105 if (!obj_bsssec (abfd)->user_set_vma)
1106 obj_bsssec (abfd)->vma = vma;
1108 vma = obj_bsssec (abfd)->vma;
1110 /* Fix up exec header. */
1111 execp->a_text = obj_textsec (abfd)->_raw_size;
1112 execp->a_data = obj_datasec (abfd)->_raw_size;
1113 execp->a_bss = obj_bsssec (abfd)->_raw_size;
1114 N_SET_MAGIC (*execp, NMAGIC);
1118 NAME(aout,adjust_sizes_and_vmas) (abfd, text_size, text_end)
1120 bfd_size_type *text_size;
1121 file_ptr *text_end ATTRIBUTE_UNUSED;
1123 struct internal_exec *execp = exec_hdr (abfd);
1125 if (! NAME(aout,make_sections) (abfd))
1128 if (adata (abfd).magic != undecided_magic)
1131 obj_textsec (abfd)->_raw_size =
1132 align_power (obj_textsec (abfd)->_raw_size,
1133 obj_textsec (abfd)->alignment_power);
1135 *text_size = obj_textsec (abfd)->_raw_size;
1136 /* Rule (heuristic) for when to pad to a new page. Note that there
1137 are (at least) two ways demand-paged (ZMAGIC) files have been
1138 handled. Most Berkeley-based systems start the text segment at
1139 (TARGET_PAGE_SIZE). However, newer versions of SUNOS start the text
1140 segment right after the exec header; the latter is counted in the
1141 text segment size, and is paged in by the kernel with the rest of
1144 /* This perhaps isn't the right way to do this, but made it simpler for me
1145 to understand enough to implement it. Better would probably be to go
1146 right from BFD flags to alignment/positioning characteristics. But the
1147 old code was sloppy enough about handling the flags, and had enough
1148 other magic, that it was a little hard for me to understand. I think
1149 I understand it better now, but I haven't time to do the cleanup this
1152 if (abfd->flags & D_PAGED)
1153 /* Whether or not WP_TEXT is set -- let D_PAGED override. */
1154 adata (abfd).magic = z_magic;
1155 else if (abfd->flags & WP_TEXT)
1156 adata (abfd).magic = n_magic;
1158 adata (abfd).magic = o_magic;
1160 #ifdef BFD_AOUT_DEBUG /* requires gcc2 */
1162 fprintf (stderr, "%s text=<%x,%x,%x> data=<%x,%x,%x> bss=<%x,%x,%x>\n",
1164 switch (adata (abfd).magic)
1166 case n_magic: str = "NMAGIC"; break;
1167 case o_magic: str = "OMAGIC"; break;
1168 case z_magic: str = "ZMAGIC"; break;
1173 obj_textsec (abfd)->vma, obj_textsec (abfd)->_raw_size,
1174 obj_textsec (abfd)->alignment_power,
1175 obj_datasec (abfd)->vma, obj_datasec (abfd)->_raw_size,
1176 obj_datasec (abfd)->alignment_power,
1177 obj_bsssec (abfd)->vma, obj_bsssec (abfd)->_raw_size,
1178 obj_bsssec (abfd)->alignment_power);
1182 switch (adata (abfd).magic)
1185 adjust_o_magic (abfd, execp);
1188 adjust_z_magic (abfd, execp);
1191 adjust_n_magic (abfd, execp);
1197 #ifdef BFD_AOUT_DEBUG
1198 fprintf (stderr, " text=<%x,%x,%x> data=<%x,%x,%x> bss=<%x,%x>\n",
1199 obj_textsec (abfd)->vma, obj_textsec (abfd)->_raw_size,
1200 obj_textsec (abfd)->filepos,
1201 obj_datasec (abfd)->vma, obj_datasec (abfd)->_raw_size,
1202 obj_datasec (abfd)->filepos,
1203 obj_bsssec (abfd)->vma, obj_bsssec (abfd)->_raw_size);
1211 aout_@var{size}_new_section_hook
1214 boolean aout_@var{size}_new_section_hook,
1216 asection *newsect));
1219 Called by the BFD in response to a @code{bfd_make_section}
1223 NAME(aout,new_section_hook) (abfd, newsect)
1227 /* Align to double at least. */
1228 newsect->alignment_power = bfd_get_arch_info (abfd)->section_align_power;
1230 if (bfd_get_format (abfd) == bfd_object)
1232 if (obj_textsec (abfd) == NULL && !strcmp (newsect->name, ".text"))
1234 obj_textsec (abfd)= newsect;
1235 newsect->target_index = N_TEXT;
1239 if (obj_datasec (abfd) == NULL && !strcmp (newsect->name, ".data"))
1241 obj_datasec (abfd) = newsect;
1242 newsect->target_index = N_DATA;
1246 if (obj_bsssec (abfd) == NULL && !strcmp (newsect->name, ".bss"))
1248 obj_bsssec (abfd) = newsect;
1249 newsect->target_index = N_BSS;
1254 /* We allow more than three sections internally. */
1259 NAME(aout,set_section_contents) (abfd, section, location, offset, count)
1264 bfd_size_type count;
1267 bfd_size_type text_size;
1269 if (! abfd->output_has_begun)
1271 if (! NAME(aout,adjust_sizes_and_vmas) (abfd, &text_size, &text_end))
1275 if (section == obj_bsssec (abfd))
1277 bfd_set_error (bfd_error_no_contents);
1281 if (section != obj_textsec (abfd)
1282 && section != obj_datasec (abfd))
1284 (*_bfd_error_handler)
1285 (_("%s: can not represent section `%s' in a.out object file format"),
1286 bfd_get_filename (abfd), bfd_get_section_name (abfd, section));
1287 bfd_set_error (bfd_error_nonrepresentable_section);
1293 if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0
1294 || bfd_bwrite (location, count, abfd) != count)
1301 /* Read the external symbols from an a.out file. */
1304 aout_get_external_symbols (abfd)
1307 if (obj_aout_external_syms (abfd) == (struct external_nlist *) NULL)
1309 bfd_size_type count;
1310 struct external_nlist *syms;
1313 count = exec_hdr (abfd)->a_syms / EXTERNAL_NLIST_SIZE;
1316 if (! bfd_get_file_window (abfd, obj_sym_filepos (abfd),
1317 exec_hdr (abfd)->a_syms,
1318 &obj_aout_sym_window (abfd), true))
1320 syms = (struct external_nlist *) obj_aout_sym_window (abfd).data;
1322 /* We allocate using malloc to make the values easy to free
1323 later on. If we put them on the objalloc it might not be
1324 possible to free them. */
1325 syms = ((struct external_nlist *)
1326 bfd_malloc (count * EXTERNAL_NLIST_SIZE));
1327 if (syms == (struct external_nlist *) NULL && count != 0)
1330 amt = exec_hdr (abfd)->a_syms;
1331 if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0
1332 || bfd_bread (syms, amt, abfd) != amt)
1339 obj_aout_external_syms (abfd) = syms;
1340 obj_aout_external_sym_count (abfd) = count;
1343 if (obj_aout_external_strings (abfd) == NULL
1344 && exec_hdr (abfd)->a_syms != 0)
1346 unsigned char string_chars[BYTES_IN_WORD];
1347 bfd_size_type stringsize;
1349 bfd_size_type amt = BYTES_IN_WORD;
1351 /* Get the size of the strings. */
1352 if (bfd_seek (abfd, obj_str_filepos (abfd), SEEK_SET) != 0
1353 || bfd_bread ((PTR) string_chars, amt, abfd) != amt)
1355 stringsize = GET_WORD (abfd, string_chars);
1358 if (! bfd_get_file_window (abfd, obj_str_filepos (abfd), stringsize,
1359 &obj_aout_string_window (abfd), true))
1361 strings = (char *) obj_aout_string_window (abfd).data;
1363 strings = (char *) bfd_malloc (stringsize + 1);
1364 if (strings == NULL)
1367 /* Skip space for the string count in the buffer for convenience
1368 when using indexes. */
1369 amt = stringsize - BYTES_IN_WORD;
1370 if (bfd_bread (strings + BYTES_IN_WORD, amt, abfd) != amt)
1377 /* Ensure that a zero index yields an empty string. */
1380 strings[stringsize - 1] = 0;
1382 obj_aout_external_strings (abfd) = strings;
1383 obj_aout_external_string_size (abfd) = stringsize;
1389 /* Translate an a.out symbol into a BFD symbol. The desc, other, type
1390 and symbol->value fields of CACHE_PTR will be set from the a.out
1391 nlist structure. This function is responsible for setting
1392 symbol->flags and symbol->section, and adjusting symbol->value. */
1395 translate_from_native_sym_flags (abfd, cache_ptr)
1397 aout_symbol_type *cache_ptr;
1401 if ((cache_ptr->type & N_STAB) != 0
1402 || cache_ptr->type == N_FN)
1406 /* This is a debugging symbol. */
1407 cache_ptr->symbol.flags = BSF_DEBUGGING;
1409 /* Work out the symbol section. */
1410 switch (cache_ptr->type & N_TYPE)
1414 sec = obj_textsec (abfd);
1417 sec = obj_datasec (abfd);
1420 sec = obj_bsssec (abfd);
1424 sec = bfd_abs_section_ptr;
1428 cache_ptr->symbol.section = sec;
1429 cache_ptr->symbol.value -= sec->vma;
1434 /* Get the default visibility. This does not apply to all types, so
1435 we just hold it in a local variable to use if wanted. */
1436 if ((cache_ptr->type & N_EXT) == 0)
1437 visible = BSF_LOCAL;
1439 visible = BSF_GLOBAL;
1441 switch (cache_ptr->type)
1444 case N_ABS: case N_ABS | N_EXT:
1445 cache_ptr->symbol.section = bfd_abs_section_ptr;
1446 cache_ptr->symbol.flags = visible;
1449 case N_UNDF | N_EXT:
1450 if (cache_ptr->symbol.value != 0)
1452 /* This is a common symbol. */
1453 cache_ptr->symbol.flags = BSF_GLOBAL;
1454 cache_ptr->symbol.section = bfd_com_section_ptr;
1458 cache_ptr->symbol.flags = 0;
1459 cache_ptr->symbol.section = bfd_und_section_ptr;
1463 case N_TEXT: case N_TEXT | N_EXT:
1464 cache_ptr->symbol.section = obj_textsec (abfd);
1465 cache_ptr->symbol.value -= cache_ptr->symbol.section->vma;
1466 cache_ptr->symbol.flags = visible;
1469 /* N_SETV symbols used to represent set vectors placed in the
1470 data section. They are no longer generated. Theoretically,
1471 it was possible to extract the entries and combine them with
1472 new ones, although I don't know if that was ever actually
1473 done. Unless that feature is restored, treat them as data
1475 case N_SETV: case N_SETV | N_EXT:
1476 case N_DATA: case N_DATA | N_EXT:
1477 cache_ptr->symbol.section = obj_datasec (abfd);
1478 cache_ptr->symbol.value -= cache_ptr->symbol.section->vma;
1479 cache_ptr->symbol.flags = visible;
1482 case N_BSS: case N_BSS | N_EXT:
1483 cache_ptr->symbol.section = obj_bsssec (abfd);
1484 cache_ptr->symbol.value -= cache_ptr->symbol.section->vma;
1485 cache_ptr->symbol.flags = visible;
1488 case N_SETA: case N_SETA | N_EXT:
1489 case N_SETT: case N_SETT | N_EXT:
1490 case N_SETD: case N_SETD | N_EXT:
1491 case N_SETB: case N_SETB | N_EXT:
1493 /* This code is no longer needed. It used to be used to make
1494 the linker handle set symbols, but they are now handled in
1495 the add_symbols routine instead. */
1498 arelent_chain *reloc;
1499 asection *into_section;
1502 /* This is a set symbol. The name of the symbol is the name
1503 of the set (e.g., __CTOR_LIST__). The value of the symbol
1504 is the value to add to the set. We create a section with
1505 the same name as the symbol, and add a reloc to insert the
1506 appropriate value into the section.
1508 This action is actually obsolete; it used to make the
1509 linker do the right thing, but the linker no longer uses
1512 section = bfd_get_section_by_name (abfd, cache_ptr->symbol.name);
1513 if (section == NULL)
1517 amt = strlen (cache_ptr->symbol.name) + 1;
1518 copy = bfd_alloc (abfd, amt);
1522 strcpy (copy, cache_ptr->symbol.name);
1523 section = bfd_make_section (abfd, copy);
1524 if (section == NULL)
1528 amt = sizeof (arelent_chain);
1529 reloc = (arelent_chain *) bfd_alloc (abfd, amt);
1533 /* Build a relocation entry for the constructor. */
1534 switch (cache_ptr->type & N_TYPE)
1537 into_section = bfd_abs_section_ptr;
1538 cache_ptr->type = N_ABS;
1541 into_section = obj_textsec (abfd);
1542 cache_ptr->type = N_TEXT;
1545 into_section = obj_datasec (abfd);
1546 cache_ptr->type = N_DATA;
1549 into_section = obj_bsssec (abfd);
1550 cache_ptr->type = N_BSS;
1554 /* Build a relocation pointing into the constructor section
1555 pointing at the symbol in the set vector specified. */
1556 reloc->relent.addend = cache_ptr->symbol.value;
1557 cache_ptr->symbol.section = into_section;
1558 reloc->relent.sym_ptr_ptr = into_section->symbol_ptr_ptr;
1560 /* We modify the symbol to belong to a section depending upon
1561 the name of the symbol, and add to the size of the section
1562 to contain a pointer to the symbol. Build a reloc entry to
1563 relocate to this symbol attached to this section. */
1564 section->flags = SEC_CONSTRUCTOR | SEC_RELOC;
1566 section->reloc_count++;
1567 section->alignment_power = 2;
1569 reloc->next = section->constructor_chain;
1570 section->constructor_chain = reloc;
1571 reloc->relent.address = section->_raw_size;
1572 section->_raw_size += BYTES_IN_WORD;
1574 reloc->relent.howto = CTOR_TABLE_RELOC_HOWTO (abfd);
1578 switch (cache_ptr->type & N_TYPE)
1581 cache_ptr->symbol.section = bfd_abs_section_ptr;
1584 cache_ptr->symbol.section = obj_textsec (abfd);
1587 cache_ptr->symbol.section = obj_datasec (abfd);
1590 cache_ptr->symbol.section = obj_bsssec (abfd);
1594 cache_ptr->symbol.flags |= BSF_CONSTRUCTOR;
1599 /* This symbol is the text of a warning message. The next
1600 symbol is the symbol to associate the warning with. If a
1601 reference is made to that symbol, a warning is issued. */
1602 cache_ptr->symbol.flags = BSF_DEBUGGING | BSF_WARNING;
1603 cache_ptr->symbol.section = bfd_abs_section_ptr;
1606 case N_INDR: case N_INDR | N_EXT:
1607 /* An indirect symbol. This consists of two symbols in a row.
1608 The first symbol is the name of the indirection. The second
1609 symbol is the name of the target. A reference to the first
1610 symbol becomes a reference to the second. */
1611 cache_ptr->symbol.flags = BSF_DEBUGGING | BSF_INDIRECT | visible;
1612 cache_ptr->symbol.section = bfd_ind_section_ptr;
1616 cache_ptr->symbol.section = bfd_und_section_ptr;
1617 cache_ptr->symbol.flags = BSF_WEAK;
1621 cache_ptr->symbol.section = bfd_abs_section_ptr;
1622 cache_ptr->symbol.flags = BSF_WEAK;
1626 cache_ptr->symbol.section = obj_textsec (abfd);
1627 cache_ptr->symbol.value -= cache_ptr->symbol.section->vma;
1628 cache_ptr->symbol.flags = BSF_WEAK;
1632 cache_ptr->symbol.section = obj_datasec (abfd);
1633 cache_ptr->symbol.value -= cache_ptr->symbol.section->vma;
1634 cache_ptr->symbol.flags = BSF_WEAK;
1638 cache_ptr->symbol.section = obj_bsssec (abfd);
1639 cache_ptr->symbol.value -= cache_ptr->symbol.section->vma;
1640 cache_ptr->symbol.flags = BSF_WEAK;
1647 /* Set the fields of SYM_POINTER according to CACHE_PTR. */
1650 translate_to_native_sym_flags (abfd, cache_ptr, sym_pointer)
1653 struct external_nlist *sym_pointer;
1655 bfd_vma value = cache_ptr->value;
1659 /* Mask out any existing type bits in case copying from one section
1661 sym_pointer->e_type[0] &= ~N_TYPE;
1663 sec = bfd_get_section (cache_ptr);
1668 /* This case occurs, e.g., for the *DEBUG* section of a COFF
1670 (*_bfd_error_handler)
1671 (_("%s: can not represent section for symbol `%s' in a.out object file format"),
1672 bfd_get_filename (abfd),
1673 cache_ptr->name != NULL ? cache_ptr->name : _("*unknown*"));
1674 bfd_set_error (bfd_error_nonrepresentable_section);
1678 if (sec->output_section != NULL)
1680 off = sec->output_offset;
1681 sec = sec->output_section;
1684 if (bfd_is_abs_section (sec))
1685 sym_pointer->e_type[0] |= N_ABS;
1686 else if (sec == obj_textsec (abfd))
1687 sym_pointer->e_type[0] |= N_TEXT;
1688 else if (sec == obj_datasec (abfd))
1689 sym_pointer->e_type[0] |= N_DATA;
1690 else if (sec == obj_bsssec (abfd))
1691 sym_pointer->e_type[0] |= N_BSS;
1692 else if (bfd_is_und_section (sec))
1693 sym_pointer->e_type[0] = N_UNDF | N_EXT;
1694 else if (bfd_is_ind_section (sec))
1695 sym_pointer->e_type[0] = N_INDR;
1696 else if (bfd_is_com_section (sec))
1697 sym_pointer->e_type[0] = N_UNDF | N_EXT;
1700 (*_bfd_error_handler)
1701 (_("%s: can not represent section `%s' in a.out object file format"),
1702 bfd_get_filename (abfd), bfd_get_section_name (abfd, sec));
1703 bfd_set_error (bfd_error_nonrepresentable_section);
1707 /* Turn the symbol from section relative to absolute again. */
1708 value += sec->vma + off;
1710 if ((cache_ptr->flags & BSF_WARNING) != 0)
1711 sym_pointer->e_type[0] = N_WARNING;
1713 if ((cache_ptr->flags & BSF_DEBUGGING) != 0)
1714 sym_pointer->e_type[0] = ((aout_symbol_type *) cache_ptr)->type;
1715 else if ((cache_ptr->flags & BSF_GLOBAL) != 0)
1716 sym_pointer->e_type[0] |= N_EXT;
1717 else if ((cache_ptr->flags & BSF_LOCAL) != 0)
1718 sym_pointer->e_type[0] &= ~N_EXT;
1720 if ((cache_ptr->flags & BSF_CONSTRUCTOR) != 0)
1722 int type = ((aout_symbol_type *) cache_ptr)->type;
1726 case N_ABS: type = N_SETA; break;
1727 case N_TEXT: type = N_SETT; break;
1728 case N_DATA: type = N_SETD; break;
1729 case N_BSS: type = N_SETB; break;
1731 sym_pointer->e_type[0] = type;
1734 if ((cache_ptr->flags & BSF_WEAK) != 0)
1738 switch (sym_pointer->e_type[0] & N_TYPE)
1741 case N_ABS: type = N_WEAKA; break;
1742 case N_TEXT: type = N_WEAKT; break;
1743 case N_DATA: type = N_WEAKD; break;
1744 case N_BSS: type = N_WEAKB; break;
1745 case N_UNDF: type = N_WEAKU; break;
1747 sym_pointer->e_type[0] = type;
1750 PUT_WORD (abfd, value, sym_pointer->e_value);
1755 /* Native-level interface to symbols. */
1758 NAME(aout,make_empty_symbol) (abfd)
1761 bfd_size_type amt = sizeof (aout_symbol_type);
1762 aout_symbol_type *new = (aout_symbol_type *) bfd_zalloc (abfd, amt);
1765 new->symbol.the_bfd = abfd;
1767 return &new->symbol;
1770 /* Translate a set of internal symbols into external symbols. */
1773 NAME(aout,translate_symbol_table) (abfd, in, ext, count, str, strsize, dynamic)
1775 aout_symbol_type *in;
1776 struct external_nlist *ext;
1777 bfd_size_type count;
1779 bfd_size_type strsize;
1782 struct external_nlist *ext_end;
1784 ext_end = ext + count;
1785 for (; ext < ext_end; ext++, in++)
1789 x = GET_WORD (abfd, ext->e_strx);
1790 in->symbol.the_bfd = abfd;
1792 /* For the normal symbols, the zero index points at the number
1793 of bytes in the string table but is to be interpreted as the
1794 null string. For the dynamic symbols, the number of bytes in
1795 the string table is stored in the __DYNAMIC structure and the
1796 zero index points at an actual string. */
1797 if (x == 0 && ! dynamic)
1798 in->symbol.name = "";
1799 else if (x < strsize)
1800 in->symbol.name = str + x;
1804 in->symbol.value = GET_SWORD (abfd, ext->e_value);
1805 in->desc = H_GET_16 (abfd, ext->e_desc);
1806 in->other = H_GET_8 (abfd, ext->e_other);
1807 in->type = H_GET_8 (abfd, ext->e_type);
1808 in->symbol.udata.p = NULL;
1810 if (! translate_from_native_sym_flags (abfd, in))
1814 in->symbol.flags |= BSF_DYNAMIC;
1820 /* We read the symbols into a buffer, which is discarded when this
1821 function exits. We read the strings into a buffer large enough to
1822 hold them all plus all the cached symbol entries. */
1825 NAME(aout,slurp_symbol_table) (abfd)
1828 struct external_nlist *old_external_syms;
1829 aout_symbol_type *cached;
1830 bfd_size_type cached_size;
1832 /* If there's no work to be done, don't do any. */
1833 if (obj_aout_symbols (abfd) != (aout_symbol_type *) NULL)
1836 old_external_syms = obj_aout_external_syms (abfd);
1838 if (! aout_get_external_symbols (abfd))
1841 cached_size = obj_aout_external_sym_count (abfd);
1842 cached_size *= sizeof (aout_symbol_type);
1843 cached = (aout_symbol_type *) bfd_zmalloc (cached_size);
1844 if (cached == NULL && cached_size != 0)
1847 /* Convert from external symbol information to internal. */
1848 if (! (NAME(aout,translate_symbol_table)
1850 obj_aout_external_syms (abfd),
1851 obj_aout_external_sym_count (abfd),
1852 obj_aout_external_strings (abfd),
1853 obj_aout_external_string_size (abfd),
1860 bfd_get_symcount (abfd) = obj_aout_external_sym_count (abfd);
1862 obj_aout_symbols (abfd) = cached;
1864 /* It is very likely that anybody who calls this function will not
1865 want the external symbol information, so if it was allocated
1866 because of our call to aout_get_external_symbols, we free it up
1867 right away to save space. */
1868 if (old_external_syms == (struct external_nlist *) NULL
1869 && obj_aout_external_syms (abfd) != (struct external_nlist *) NULL)
1872 bfd_free_window (&obj_aout_sym_window (abfd));
1874 free (obj_aout_external_syms (abfd));
1876 obj_aout_external_syms (abfd) = NULL;
1882 /* We use a hash table when writing out symbols so that we only write
1883 out a particular string once. This helps particularly when the
1884 linker writes out stabs debugging entries, because each different
1885 contributing object file tends to have many duplicate stabs
1888 This hash table code breaks dbx on SunOS 4.1.3, so we don't do it
1889 if BFD_TRADITIONAL_FORMAT is set. */
1891 static bfd_size_type add_to_stringtab
1892 PARAMS ((bfd *, struct bfd_strtab_hash *, const char *, boolean));
1893 static boolean emit_stringtab PARAMS ((bfd *, struct bfd_strtab_hash *));
1895 /* Get the index of a string in a strtab, adding it if it is not
1898 static INLINE bfd_size_type
1899 add_to_stringtab (abfd, tab, str, copy)
1901 struct bfd_strtab_hash *tab;
1906 bfd_size_type index;
1908 /* An index of 0 always means the empty string. */
1909 if (str == 0 || *str == '\0')
1912 /* Don't hash if BFD_TRADITIONAL_FORMAT is set, because SunOS dbx
1913 doesn't understand a hashed string table. */
1915 if ((abfd->flags & BFD_TRADITIONAL_FORMAT) != 0)
1918 index = _bfd_stringtab_add (tab, str, hash, copy);
1920 if (index != (bfd_size_type) -1)
1922 /* Add BYTES_IN_WORD to the return value to account for the
1923 space taken up by the string table size. */
1924 index += BYTES_IN_WORD;
1930 /* Write out a strtab. ABFD is already at the right location in the
1934 emit_stringtab (abfd, tab)
1936 struct bfd_strtab_hash *tab;
1938 bfd_byte buffer[BYTES_IN_WORD];
1939 bfd_size_type amt = BYTES_IN_WORD;
1941 /* The string table starts with the size. */
1942 PUT_WORD (abfd, _bfd_stringtab_size (tab) + BYTES_IN_WORD, buffer);
1943 if (bfd_bwrite ((PTR) buffer, amt, abfd) != amt)
1946 return _bfd_stringtab_emit (abfd, tab);
1950 NAME(aout,write_syms) (abfd)
1953 unsigned int count ;
1954 asymbol **generic = bfd_get_outsymbols (abfd);
1955 struct bfd_strtab_hash *strtab;
1957 strtab = _bfd_stringtab_init ();
1961 for (count = 0; count < bfd_get_symcount (abfd); count++)
1963 asymbol *g = generic[count];
1965 struct external_nlist nsp;
1968 indx = add_to_stringtab (abfd, strtab, g->name, false);
1969 if (indx == (bfd_size_type) -1)
1971 PUT_WORD (abfd, indx, (bfd_byte *) nsp.e_strx);
1973 if (bfd_asymbol_flavour (g) == abfd->xvec->flavour)
1975 H_PUT_16 (abfd, aout_symbol (g)->desc, nsp.e_desc);
1976 H_PUT_8 (abfd, aout_symbol (g)->other, nsp.e_other);
1977 H_PUT_8 (abfd, aout_symbol (g)->type, nsp.e_type);
1981 H_PUT_16 (abfd, 0, nsp.e_desc);
1982 H_PUT_8 (abfd, 0, nsp.e_other);
1983 H_PUT_8 (abfd, 0, nsp.e_type);
1986 if (! translate_to_native_sym_flags (abfd, g, &nsp))
1989 amt = EXTERNAL_NLIST_SIZE;
1990 if (bfd_bwrite ((PTR) &nsp, amt, abfd) != amt)
1993 /* NB: `KEEPIT' currently overlays `udata.p', so set this only
1994 here, at the end. */
1998 if (! emit_stringtab (abfd, strtab))
2001 _bfd_stringtab_free (strtab);
2006 _bfd_stringtab_free (strtab);
2011 NAME(aout,get_symtab) (abfd, location)
2015 unsigned int counter = 0;
2016 aout_symbol_type *symbase;
2018 if (!NAME(aout,slurp_symbol_table) (abfd))
2021 for (symbase = obj_aout_symbols (abfd);
2022 counter++ < bfd_get_symcount (abfd);
2024 *(location++) = (asymbol *) (symbase++);
2026 return bfd_get_symcount (abfd);
2029 /* Standard reloc stuff. */
2030 /* Output standard relocation information to a file in target byte order. */
2032 extern void NAME(aout,swap_std_reloc_out)
2033 PARAMS ((bfd *, arelent *, struct reloc_std_external *));
2036 NAME(aout,swap_std_reloc_out) (abfd, g, natptr)
2039 struct reloc_std_external *natptr;
2042 asymbol *sym = *(g->sym_ptr_ptr);
2044 unsigned int r_length;
2046 int r_baserel, r_jmptable, r_relative;
2047 asection *output_section = sym->section->output_section;
2049 PUT_WORD (abfd, g->address, natptr->r_address);
2051 r_length = g->howto->size ; /* Size as a power of two. */
2052 r_pcrel = (int) g->howto->pc_relative; /* Relative to PC? */
2053 /* XXX This relies on relocs coming from a.out files. */
2054 r_baserel = (g->howto->type & 8) != 0;
2055 r_jmptable = (g->howto->type & 16) != 0;
2056 r_relative = (g->howto->type & 32) != 0;
2059 /* For a standard reloc, the addend is in the object file. */
2060 r_addend = g->addend + (*(g->sym_ptr_ptr))->section->output_section->vma;
2063 /* Name was clobbered by aout_write_syms to be symbol index. */
2065 /* If this relocation is relative to a symbol then set the
2066 r_index to the symbols index, and the r_extern bit.
2068 Absolute symbols can come in in two ways, either as an offset
2069 from the abs section, or as a symbol which has an abs value.
2070 check for that here. */
2072 if (bfd_is_com_section (output_section)
2073 || bfd_is_abs_section (output_section)
2074 || bfd_is_und_section (output_section))
2076 if (bfd_abs_section_ptr->symbol == sym)
2078 /* Whoops, looked like an abs symbol, but is
2079 really an offset from the abs section. */
2085 /* Fill in symbol. */
2087 r_index = (*(g->sym_ptr_ptr))->KEEPIT;
2092 /* Just an ordinary section. */
2094 r_index = output_section->target_index;
2097 /* Now the fun stuff. */
2098 if (bfd_header_big_endian (abfd))
2100 natptr->r_index[0] = r_index >> 16;
2101 natptr->r_index[1] = r_index >> 8;
2102 natptr->r_index[2] = r_index;
2103 natptr->r_type[0] = ((r_extern ? RELOC_STD_BITS_EXTERN_BIG : 0)
2104 | (r_pcrel ? RELOC_STD_BITS_PCREL_BIG : 0)
2105 | (r_baserel ? RELOC_STD_BITS_BASEREL_BIG : 0)
2106 | (r_jmptable ? RELOC_STD_BITS_JMPTABLE_BIG : 0)
2107 | (r_relative ? RELOC_STD_BITS_RELATIVE_BIG : 0)
2108 | (r_length << RELOC_STD_BITS_LENGTH_SH_BIG));
2112 natptr->r_index[2] = r_index >> 16;
2113 natptr->r_index[1] = r_index >> 8;
2114 natptr->r_index[0] = r_index;
2115 natptr->r_type[0] = ((r_extern ? RELOC_STD_BITS_EXTERN_LITTLE : 0)
2116 | (r_pcrel ? RELOC_STD_BITS_PCREL_LITTLE : 0)
2117 | (r_baserel ? RELOC_STD_BITS_BASEREL_LITTLE : 0)
2118 | (r_jmptable ? RELOC_STD_BITS_JMPTABLE_LITTLE : 0)
2119 | (r_relative ? RELOC_STD_BITS_RELATIVE_LITTLE : 0)
2120 | (r_length << RELOC_STD_BITS_LENGTH_SH_LITTLE));
2124 /* Extended stuff. */
2125 /* Output extended relocation information to a file in target byte order. */
2127 extern void NAME(aout,swap_ext_reloc_out)
2128 PARAMS ((bfd *, arelent *, struct reloc_ext_external *));
2131 NAME(aout,swap_ext_reloc_out) (abfd, g, natptr)
2134 register struct reloc_ext_external *natptr;
2138 unsigned int r_type;
2140 asymbol *sym = *(g->sym_ptr_ptr);
2141 asection *output_section = sym->section->output_section;
2143 PUT_WORD (abfd, g->address, natptr->r_address);
2145 r_type = (unsigned int) g->howto->type;
2147 r_addend = g->addend;
2148 if ((sym->flags & BSF_SECTION_SYM) != 0)
2149 r_addend += (*(g->sym_ptr_ptr))->section->output_section->vma;
2151 /* If this relocation is relative to a symbol then set the
2152 r_index to the symbols index, and the r_extern bit.
2154 Absolute symbols can come in in two ways, either as an offset
2155 from the abs section, or as a symbol which has an abs value.
2156 check for that here. */
2157 if (bfd_is_abs_section (bfd_get_section (sym)))
2162 else if ((sym->flags & BSF_SECTION_SYM) == 0)
2164 if (bfd_is_und_section (bfd_get_section (sym))
2165 || (sym->flags & BSF_GLOBAL) != 0)
2169 r_index = (*(g->sym_ptr_ptr))->KEEPIT;
2173 /* Just an ordinary section. */
2175 r_index = output_section->target_index;
2178 /* Now the fun stuff. */
2179 if (bfd_header_big_endian (abfd))
2181 natptr->r_index[0] = r_index >> 16;
2182 natptr->r_index[1] = r_index >> 8;
2183 natptr->r_index[2] = r_index;
2184 natptr->r_type[0] = ((r_extern ? RELOC_EXT_BITS_EXTERN_BIG : 0)
2185 | (r_type << RELOC_EXT_BITS_TYPE_SH_BIG));
2189 natptr->r_index[2] = r_index >> 16;
2190 natptr->r_index[1] = r_index >> 8;
2191 natptr->r_index[0] = r_index;
2192 natptr->r_type[0] = ((r_extern ? RELOC_EXT_BITS_EXTERN_LITTLE : 0)
2193 | (r_type << RELOC_EXT_BITS_TYPE_SH_LITTLE));
2196 PUT_WORD (abfd, r_addend, natptr->r_addend);
2199 /* BFD deals internally with all things based from the section they're
2200 in. so, something in 10 bytes into a text section with a base of
2201 50 would have a symbol (.text+10) and know .text vma was 50.
2203 Aout keeps all it's symbols based from zero, so the symbol would
2204 contain 60. This macro subs the base of each section from the value
2205 to give the true offset from the section. */
2207 #define MOVE_ADDRESS(ad) \
2210 /* Undefined symbol. */ \
2211 cache_ptr->sym_ptr_ptr = symbols + r_index; \
2212 cache_ptr->addend = ad; \
2216 /* Defined, section relative. Replace symbol with pointer to \
2217 symbol which points to section. */ \
2221 case N_TEXT | N_EXT: \
2222 cache_ptr->sym_ptr_ptr = obj_textsec (abfd)->symbol_ptr_ptr; \
2223 cache_ptr->addend = ad - su->textsec->vma; \
2226 case N_DATA | N_EXT: \
2227 cache_ptr->sym_ptr_ptr = obj_datasec (abfd)->symbol_ptr_ptr; \
2228 cache_ptr->addend = ad - su->datasec->vma; \
2231 case N_BSS | N_EXT: \
2232 cache_ptr->sym_ptr_ptr = obj_bsssec (abfd)->symbol_ptr_ptr; \
2233 cache_ptr->addend = ad - su->bsssec->vma; \
2237 case N_ABS | N_EXT: \
2238 cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr; \
2239 cache_ptr->addend = ad; \
2245 NAME(aout,swap_ext_reloc_in) (abfd, bytes, cache_ptr, symbols, symcount)
2247 struct reloc_ext_external *bytes;
2250 bfd_size_type symcount;
2252 unsigned int r_index;
2254 unsigned int r_type;
2255 struct aoutdata *su = &(abfd->tdata.aout_data->a);
2257 cache_ptr->address = (GET_SWORD (abfd, bytes->r_address));
2259 /* Now the fun stuff. */
2260 if (bfd_header_big_endian (abfd))
2262 r_index = ((bytes->r_index[0] << 16)
2263 | (bytes->r_index[1] << 8)
2264 | bytes->r_index[2]);
2265 r_extern = (0 != (bytes->r_type[0] & RELOC_EXT_BITS_EXTERN_BIG));
2266 r_type = ((bytes->r_type[0] & RELOC_EXT_BITS_TYPE_BIG)
2267 >> RELOC_EXT_BITS_TYPE_SH_BIG);
2271 r_index = ((bytes->r_index[2] << 16)
2272 | (bytes->r_index[1] << 8)
2273 | bytes->r_index[0]);
2274 r_extern = (0 != (bytes->r_type[0] & RELOC_EXT_BITS_EXTERN_LITTLE));
2275 r_type = ((bytes->r_type[0] & RELOC_EXT_BITS_TYPE_LITTLE)
2276 >> RELOC_EXT_BITS_TYPE_SH_LITTLE);
2279 cache_ptr->howto = howto_table_ext + r_type;
2281 /* Base relative relocs are always against the symbol table,
2282 regardless of the setting of r_extern. r_extern just reflects
2283 whether the symbol the reloc is against is local or global. */
2284 if (r_type == RELOC_BASE10
2285 || r_type == RELOC_BASE13
2286 || r_type == RELOC_BASE22)
2289 if (r_extern && r_index > symcount)
2291 /* We could arrange to return an error, but it might be useful
2292 to see the file even if it is bad. */
2297 MOVE_ADDRESS (GET_SWORD (abfd, bytes->r_addend));
2301 NAME(aout,swap_std_reloc_in) (abfd, bytes, cache_ptr, symbols, symcount)
2303 struct reloc_std_external *bytes;
2306 bfd_size_type symcount;
2308 unsigned int r_index;
2310 unsigned int r_length;
2312 int r_baserel, r_jmptable, r_relative;
2313 struct aoutdata *su = &(abfd->tdata.aout_data->a);
2314 unsigned int howto_idx;
2316 cache_ptr->address = H_GET_32 (abfd, bytes->r_address);
2318 /* Now the fun stuff. */
2319 if (bfd_header_big_endian (abfd))
2321 r_index = ((bytes->r_index[0] << 16)
2322 | (bytes->r_index[1] << 8)
2323 | bytes->r_index[2]);
2324 r_extern = (0 != (bytes->r_type[0] & RELOC_STD_BITS_EXTERN_BIG));
2325 r_pcrel = (0 != (bytes->r_type[0] & RELOC_STD_BITS_PCREL_BIG));
2326 r_baserel = (0 != (bytes->r_type[0] & RELOC_STD_BITS_BASEREL_BIG));
2327 r_jmptable= (0 != (bytes->r_type[0] & RELOC_STD_BITS_JMPTABLE_BIG));
2328 r_relative= (0 != (bytes->r_type[0] & RELOC_STD_BITS_RELATIVE_BIG));
2329 r_length = ((bytes->r_type[0] & RELOC_STD_BITS_LENGTH_BIG)
2330 >> RELOC_STD_BITS_LENGTH_SH_BIG);
2334 r_index = ((bytes->r_index[2] << 16)
2335 | (bytes->r_index[1] << 8)
2336 | bytes->r_index[0]);
2337 r_extern = (0 != (bytes->r_type[0] & RELOC_STD_BITS_EXTERN_LITTLE));
2338 r_pcrel = (0 != (bytes->r_type[0] & RELOC_STD_BITS_PCREL_LITTLE));
2339 r_baserel = (0 != (bytes->r_type[0] & RELOC_STD_BITS_BASEREL_LITTLE));
2340 r_jmptable= (0 != (bytes->r_type[0] & RELOC_STD_BITS_JMPTABLE_LITTLE));
2341 r_relative= (0 != (bytes->r_type[0] & RELOC_STD_BITS_RELATIVE_LITTLE));
2342 r_length = ((bytes->r_type[0] & RELOC_STD_BITS_LENGTH_LITTLE)
2343 >> RELOC_STD_BITS_LENGTH_SH_LITTLE);
2346 howto_idx = (r_length + 4 * r_pcrel + 8 * r_baserel
2347 + 16 * r_jmptable + 32 * r_relative);
2348 BFD_ASSERT (howto_idx < TABLE_SIZE (howto_table_std));
2349 cache_ptr->howto = howto_table_std + howto_idx;
2350 BFD_ASSERT (cache_ptr->howto->type != (unsigned int) -1);
2352 /* Base relative relocs are always against the symbol table,
2353 regardless of the setting of r_extern. r_extern just reflects
2354 whether the symbol the reloc is against is local or global. */
2358 if (r_extern && r_index > symcount)
2360 /* We could arrange to return an error, but it might be useful
2361 to see the file even if it is bad. */
2369 /* Read and swap the relocs for a section. */
2372 NAME(aout,slurp_reloc_table) (abfd, asect, symbols)
2377 bfd_size_type count;
2378 bfd_size_type reloc_size;
2380 arelent *reloc_cache;
2382 unsigned int counter = 0;
2386 if (asect->relocation)
2389 if (asect->flags & SEC_CONSTRUCTOR)
2392 if (asect == obj_datasec (abfd))
2393 reloc_size = exec_hdr (abfd)->a_drsize;
2394 else if (asect == obj_textsec (abfd))
2395 reloc_size = exec_hdr (abfd)->a_trsize;
2396 else if (asect == obj_bsssec (abfd))
2400 bfd_set_error (bfd_error_invalid_operation);
2404 if (bfd_seek (abfd, asect->rel_filepos, SEEK_SET) != 0)
2407 each_size = obj_reloc_entry_size (abfd);
2409 count = reloc_size / each_size;
2411 amt = count * sizeof (arelent);
2412 reloc_cache = (arelent *) bfd_zmalloc (amt);
2413 if (reloc_cache == NULL && count != 0)
2416 relocs = bfd_malloc (reloc_size);
2417 if (relocs == NULL && reloc_size != 0)
2423 if (bfd_bread (relocs, reloc_size, abfd) != reloc_size)
2430 cache_ptr = reloc_cache;
2431 if (each_size == RELOC_EXT_SIZE)
2433 struct reloc_ext_external *rptr = (struct reloc_ext_external *) relocs;
2435 for (; counter < count; counter++, rptr++, cache_ptr++)
2436 MY_swap_ext_reloc_in (abfd, rptr, cache_ptr, symbols,
2437 (bfd_size_type) bfd_get_symcount (abfd));
2441 struct reloc_std_external *rptr = (struct reloc_std_external *) relocs;
2443 for (; counter < count; counter++, rptr++, cache_ptr++)
2444 MY_swap_std_reloc_in (abfd, rptr, cache_ptr, symbols,
2445 (bfd_size_type) bfd_get_symcount (abfd));
2450 asect->relocation = reloc_cache;
2451 asect->reloc_count = cache_ptr - reloc_cache;
2456 /* Write out a relocation section into an object file. */
2459 NAME(aout,squirt_out_relocs) (abfd, section)
2464 unsigned char *native, *natptr;
2467 unsigned int count = section->reloc_count;
2468 bfd_size_type natsize;
2470 if (count == 0 || section->orelocation == NULL)
2473 each_size = obj_reloc_entry_size (abfd);
2474 natsize = (bfd_size_type) each_size * count;
2475 native = (unsigned char *) bfd_zalloc (abfd, natsize);
2479 generic = section->orelocation;
2481 if (each_size == RELOC_EXT_SIZE)
2483 for (natptr = native;
2485 --count, natptr += each_size, ++generic)
2486 MY_swap_ext_reloc_out (abfd, *generic,
2487 (struct reloc_ext_external *) natptr);
2491 for (natptr = native;
2493 --count, natptr += each_size, ++generic)
2494 MY_swap_std_reloc_out (abfd, *generic,
2495 (struct reloc_std_external *) natptr);
2498 if (bfd_bwrite ((PTR) native, natsize, abfd) != natsize)
2500 bfd_release (abfd, native);
2503 bfd_release (abfd, native);
2508 /* This is stupid. This function should be a boolean predicate. */
2511 NAME(aout,canonicalize_reloc) (abfd, section, relptr, symbols)
2517 arelent *tblptr = section->relocation;
2520 if (section == obj_bsssec (abfd))
2526 if (!(tblptr || NAME(aout,slurp_reloc_table) (abfd, section, symbols)))
2529 if (section->flags & SEC_CONSTRUCTOR)
2531 arelent_chain *chain = section->constructor_chain;
2532 for (count = 0; count < section->reloc_count; count ++)
2534 *relptr ++ = &chain->relent;
2535 chain = chain->next;
2540 tblptr = section->relocation;
2542 for (count = 0; count++ < section->reloc_count; )
2544 *relptr++ = tblptr++;
2549 return section->reloc_count;
2553 NAME(aout,get_reloc_upper_bound) (abfd, asect)
2557 if (bfd_get_format (abfd) != bfd_object)
2559 bfd_set_error (bfd_error_invalid_operation);
2563 if (asect->flags & SEC_CONSTRUCTOR)
2564 return (sizeof (arelent *) * (asect->reloc_count+1));
2566 if (asect == obj_datasec (abfd))
2567 return (sizeof (arelent *)
2568 * ((exec_hdr (abfd)->a_drsize / obj_reloc_entry_size (abfd))
2571 if (asect == obj_textsec (abfd))
2572 return (sizeof (arelent *)
2573 * ((exec_hdr (abfd)->a_trsize / obj_reloc_entry_size (abfd))
2576 if (asect == obj_bsssec (abfd))
2577 return sizeof (arelent *);
2579 if (asect == obj_bsssec (abfd))
2582 bfd_set_error (bfd_error_invalid_operation);
2587 NAME(aout,get_symtab_upper_bound) (abfd)
2590 if (!NAME(aout,slurp_symbol_table) (abfd))
2593 return (bfd_get_symcount (abfd)+1) * (sizeof (aout_symbol_type *));
2597 NAME(aout,get_lineno) (ignore_abfd, ignore_symbol)
2598 bfd *ignore_abfd ATTRIBUTE_UNUSED;
2599 asymbol *ignore_symbol ATTRIBUTE_UNUSED;
2601 return (alent *)NULL;
2605 NAME(aout,get_symbol_info) (ignore_abfd, symbol, ret)
2606 bfd *ignore_abfd ATTRIBUTE_UNUSED;
2610 bfd_symbol_info (symbol, ret);
2612 if (ret->type == '?')
2614 int type_code = aout_symbol (symbol)->type & 0xff;
2615 const char *stab_name = bfd_get_stab_name (type_code);
2616 static char buf[10];
2618 if (stab_name == NULL)
2620 sprintf (buf, "(%d)", type_code);
2624 ret->stab_type = type_code;
2625 ret->stab_other = (unsigned) (aout_symbol (symbol)->other & 0xff);
2626 ret->stab_desc = (unsigned) (aout_symbol (symbol)->desc & 0xffff);
2627 ret->stab_name = stab_name;
2632 NAME(aout,print_symbol) (abfd, afile, symbol, how)
2636 bfd_print_symbol_type how;
2638 FILE *file = (FILE *)afile;
2642 case bfd_print_symbol_name:
2644 fprintf (file,"%s", symbol->name);
2646 case bfd_print_symbol_more:
2647 fprintf (file,"%4x %2x %2x",
2648 (unsigned) (aout_symbol (symbol)->desc & 0xffff),
2649 (unsigned) (aout_symbol (symbol)->other & 0xff),
2650 (unsigned) (aout_symbol (symbol)->type));
2652 case bfd_print_symbol_all:
2654 const char *section_name = symbol->section->name;
2656 bfd_print_symbol_vandf (abfd, (PTR)file, symbol);
2658 fprintf (file," %-5s %04x %02x %02x",
2660 (unsigned) (aout_symbol (symbol)->desc & 0xffff),
2661 (unsigned) (aout_symbol (symbol)->other & 0xff),
2662 (unsigned) (aout_symbol (symbol)->type & 0xff));
2664 fprintf (file," %s", symbol->name);
2670 /* If we don't have to allocate more than 1MB to hold the generic
2671 symbols, we use the generic minisymbol methord: it's faster, since
2672 it only translates the symbols once, not multiple times. */
2673 #define MINISYM_THRESHOLD (1000000 / sizeof (asymbol))
2675 /* Read minisymbols. For minisymbols, we use the unmodified a.out
2676 symbols. The minisymbol_to_symbol function translates these into
2677 BFD asymbol structures. */
2680 NAME(aout,read_minisymbols) (abfd, dynamic, minisymsp, sizep)
2684 unsigned int *sizep;
2688 /* We could handle the dynamic symbols here as well, but it's
2689 easier to hand them off. */
2690 return _bfd_generic_read_minisymbols (abfd, dynamic, minisymsp, sizep);
2693 if (! aout_get_external_symbols (abfd))
2696 if (obj_aout_external_sym_count (abfd) < MINISYM_THRESHOLD)
2697 return _bfd_generic_read_minisymbols (abfd, dynamic, minisymsp, sizep);
2699 *minisymsp = (PTR) obj_aout_external_syms (abfd);
2701 /* By passing the external symbols back from this routine, we are
2702 giving up control over the memory block. Clear
2703 obj_aout_external_syms, so that we do not try to free it
2705 obj_aout_external_syms (abfd) = NULL;
2707 *sizep = EXTERNAL_NLIST_SIZE;
2708 return obj_aout_external_sym_count (abfd);
2711 /* Convert a minisymbol to a BFD asymbol. A minisymbol is just an
2712 unmodified a.out symbol. The SYM argument is a structure returned
2713 by bfd_make_empty_symbol, which we fill in here. */
2716 NAME(aout,minisymbol_to_symbol) (abfd, dynamic, minisym, sym)
2723 || obj_aout_external_sym_count (abfd) < MINISYM_THRESHOLD)
2724 return _bfd_generic_minisymbol_to_symbol (abfd, dynamic, minisym, sym);
2726 memset (sym, 0, sizeof (aout_symbol_type));
2728 /* We call translate_symbol_table to translate a single symbol. */
2729 if (! (NAME(aout,translate_symbol_table)
2731 (aout_symbol_type *) sym,
2732 (struct external_nlist *) minisym,
2734 obj_aout_external_strings (abfd),
2735 obj_aout_external_string_size (abfd),
2742 /* Provided a BFD, a section and an offset into the section, calculate
2743 and return the name of the source file and the line nearest to the
2747 NAME(aout,find_nearest_line)
2748 (abfd, section, symbols, offset, filename_ptr, functionname_ptr, line_ptr)
2753 const char **filename_ptr;
2754 const char **functionname_ptr;
2755 unsigned int *line_ptr;
2757 /* Run down the file looking for the filename, function and linenumber. */
2759 const char *directory_name = NULL;
2760 const char *main_file_name = NULL;
2761 const char *current_file_name = NULL;
2762 const char *line_file_name = NULL; /* Value of current_file_name at line number. */
2763 const char *line_directory_name = NULL; /* Value of directory_name at line number. */
2764 bfd_vma low_line_vma = 0;
2765 bfd_vma low_func_vma = 0;
2767 bfd_size_type filelen, funclen;
2770 *filename_ptr = abfd->filename;
2771 *functionname_ptr = 0;
2774 if (symbols != (asymbol **)NULL)
2776 for (p = symbols; *p; p++)
2778 aout_symbol_type *q = (aout_symbol_type *) (*p);
2783 /* If this looks like a file name symbol, and it comes after
2784 the line number we have found so far, but before the
2785 offset, then we have probably not found the right line
2787 if (q->symbol.value <= offset
2788 && ((q->symbol.value > low_line_vma
2789 && (line_file_name != NULL
2791 || (q->symbol.value > low_func_vma
2794 const char *symname;
2796 symname = q->symbol.name;
2797 if (strcmp (symname + strlen (symname) - 2, ".o") == 0)
2799 if (q->symbol.value > low_line_vma)
2802 line_file_name = NULL;
2804 if (q->symbol.value > low_func_vma)
2811 /* If this symbol is less than the offset, but greater than
2812 the line number we have found so far, then we have not
2813 found the right line number. */
2814 if (q->symbol.value <= offset)
2816 if (q->symbol.value > low_line_vma)
2819 line_file_name = NULL;
2821 if (q->symbol.value > low_func_vma)
2825 main_file_name = current_file_name = q->symbol.name;
2826 /* Look ahead to next symbol to check if that too is an N_SO. */
2830 q = (aout_symbol_type *) (*p);
2831 if (q->type != (int)N_SO)
2834 /* Found a second N_SO First is directory; second is filename. */
2835 directory_name = current_file_name;
2836 main_file_name = current_file_name = q->symbol.name;
2837 if (obj_textsec (abfd) != section)
2841 current_file_name = q->symbol.name;
2848 /* We'll keep this if it resolves nearer than the one we have
2850 if (q->symbol.value >= low_line_vma
2851 && q->symbol.value <= offset)
2853 *line_ptr = q->desc;
2854 low_line_vma = q->symbol.value;
2855 line_file_name = current_file_name;
2856 line_directory_name = directory_name;
2861 /* We'll keep this if it is nearer than the one we have already. */
2862 if (q->symbol.value >= low_func_vma &&
2863 q->symbol.value <= offset)
2865 low_func_vma = q->symbol.value;
2866 func = (asymbol *)q;
2868 else if (q->symbol.value > offset)
2879 main_file_name = line_file_name;
2880 directory_name = line_directory_name;
2883 if (main_file_name == NULL
2884 || IS_ABSOLUTE_PATH (main_file_name)
2885 || directory_name == NULL)
2888 filelen = strlen (directory_name) + strlen (main_file_name);
2893 funclen = strlen (bfd_asymbol_name (func));
2895 if (adata (abfd).line_buf != NULL)
2896 free (adata (abfd).line_buf);
2898 if (filelen + funclen == 0)
2899 adata (abfd).line_buf = buf = NULL;
2902 buf = (char *) bfd_malloc (filelen + funclen + 3);
2903 adata (abfd).line_buf = buf;
2908 if (main_file_name != NULL)
2910 if (IS_ABSOLUTE_PATH (main_file_name) || directory_name == NULL)
2911 *filename_ptr = main_file_name;
2914 sprintf (buf, "%s%s", directory_name, main_file_name);
2915 *filename_ptr = buf;
2922 const char *function = func->name;
2925 /* The caller expects a symbol name. We actually have a
2926 function name, without the leading underscore. Put the
2927 underscore back in, so that the caller gets a symbol name. */
2928 if (bfd_get_symbol_leading_char (abfd) == '\0')
2929 strcpy (buf, function);
2932 buf[0] = bfd_get_symbol_leading_char (abfd);
2933 strcpy (buf + 1, function);
2935 /* Have to remove : stuff. */
2936 colon = strchr (buf, ':');
2939 *functionname_ptr = buf;
2946 NAME(aout,sizeof_headers) (abfd, execable)
2948 boolean execable ATTRIBUTE_UNUSED;
2950 return adata (abfd).exec_bytes_size;
2953 /* Free all information we have cached for this BFD. We can always
2954 read it again later if we need it. */
2957 NAME(aout,bfd_free_cached_info) (abfd)
2962 if (bfd_get_format (abfd) != bfd_object
2963 || abfd->tdata.aout_data == NULL)
2966 #define BFCI_FREE(x) if (x != NULL) { free (x); x = NULL; }
2967 BFCI_FREE (obj_aout_symbols (abfd));
2969 obj_aout_external_syms (abfd) = 0;
2970 bfd_free_window (&obj_aout_sym_window (abfd));
2971 bfd_free_window (&obj_aout_string_window (abfd));
2972 obj_aout_external_strings (abfd) = 0;
2974 BFCI_FREE (obj_aout_external_syms (abfd));
2975 BFCI_FREE (obj_aout_external_strings (abfd));
2977 for (o = abfd->sections; o != (asection *) NULL; o = o->next)
2978 BFCI_FREE (o->relocation);
2984 /* a.out link code. */
2986 static boolean aout_link_add_object_symbols
2987 PARAMS ((bfd *, struct bfd_link_info *));
2988 static boolean aout_link_check_archive_element
2989 PARAMS ((bfd *, struct bfd_link_info *, boolean *));
2990 static boolean aout_link_free_symbols PARAMS ((bfd *));
2991 static boolean aout_link_check_ar_symbols
2992 PARAMS ((bfd *, struct bfd_link_info *, boolean *pneeded));
2993 static boolean aout_link_add_symbols
2994 PARAMS ((bfd *, struct bfd_link_info *));
2996 /* Routine to create an entry in an a.out link hash table. */
2998 struct bfd_hash_entry *
2999 NAME(aout,link_hash_newfunc) (entry, table, string)
3000 struct bfd_hash_entry *entry;
3001 struct bfd_hash_table *table;
3004 struct aout_link_hash_entry *ret = (struct aout_link_hash_entry *) entry;
3006 /* Allocate the structure if it has not already been allocated by a
3008 if (ret == (struct aout_link_hash_entry *) NULL)
3009 ret = ((struct aout_link_hash_entry *)
3010 bfd_hash_allocate (table, sizeof (struct aout_link_hash_entry)));
3011 if (ret == (struct aout_link_hash_entry *) NULL)
3012 return (struct bfd_hash_entry *) ret;
3014 /* Call the allocation method of the superclass. */
3015 ret = ((struct aout_link_hash_entry *)
3016 _bfd_link_hash_newfunc ((struct bfd_hash_entry *) ret,
3020 /* Set local fields. */
3021 ret->written = false;
3025 return (struct bfd_hash_entry *) ret;
3028 /* Initialize an a.out link hash table. */
3031 NAME(aout,link_hash_table_init) (table, abfd, newfunc)
3032 struct aout_link_hash_table *table;
3034 struct bfd_hash_entry *(*newfunc) PARAMS ((struct bfd_hash_entry *,
3035 struct bfd_hash_table *,
3038 return _bfd_link_hash_table_init (&table->root, abfd, newfunc);
3041 /* Create an a.out link hash table. */
3043 struct bfd_link_hash_table *
3044 NAME(aout,link_hash_table_create) (abfd)
3047 struct aout_link_hash_table *ret;
3048 bfd_size_type amt = sizeof (struct aout_link_hash_table);
3050 ret = (struct aout_link_hash_table *) bfd_alloc (abfd, amt);
3052 return (struct bfd_link_hash_table *) NULL;
3053 if (! NAME(aout,link_hash_table_init) (ret, abfd,
3054 NAME(aout,link_hash_newfunc)))
3057 return (struct bfd_link_hash_table *) NULL;
3062 /* Given an a.out BFD, add symbols to the global hash table as
3066 NAME(aout,link_add_symbols) (abfd, info)
3068 struct bfd_link_info *info;
3070 switch (bfd_get_format (abfd))
3073 return aout_link_add_object_symbols (abfd, info);
3075 return _bfd_generic_link_add_archive_symbols
3076 (abfd, info, aout_link_check_archive_element);
3078 bfd_set_error (bfd_error_wrong_format);
3083 /* Add symbols from an a.out object file. */
3086 aout_link_add_object_symbols (abfd, info)
3088 struct bfd_link_info *info;
3090 if (! aout_get_external_symbols (abfd))
3092 if (! aout_link_add_symbols (abfd, info))
3094 if (! info->keep_memory)
3096 if (! aout_link_free_symbols (abfd))
3102 /* Check a single archive element to see if we need to include it in
3103 the link. *PNEEDED is set according to whether this element is
3104 needed in the link or not. This is called from
3105 _bfd_generic_link_add_archive_symbols. */
3108 aout_link_check_archive_element (abfd, info, pneeded)
3110 struct bfd_link_info *info;
3113 if (! aout_get_external_symbols (abfd))
3116 if (! aout_link_check_ar_symbols (abfd, info, pneeded))
3121 if (! aout_link_add_symbols (abfd, info))
3125 if (! info->keep_memory || ! *pneeded)
3127 if (! aout_link_free_symbols (abfd))
3134 /* Free up the internal symbols read from an a.out file. */
3137 aout_link_free_symbols (abfd)
3140 if (obj_aout_external_syms (abfd) != (struct external_nlist *) NULL)
3143 bfd_free_window (&obj_aout_sym_window (abfd));
3145 free ((PTR) obj_aout_external_syms (abfd));
3147 obj_aout_external_syms (abfd) = (struct external_nlist *) NULL;
3149 if (obj_aout_external_strings (abfd) != (char *) NULL)
3152 bfd_free_window (&obj_aout_string_window (abfd));
3154 free ((PTR) obj_aout_external_strings (abfd));
3156 obj_aout_external_strings (abfd) = (char *) NULL;
3161 /* Look through the internal symbols to see if this object file should
3162 be included in the link. We should include this object file if it
3163 defines any symbols which are currently undefined. If this object
3164 file defines a common symbol, then we may adjust the size of the
3165 known symbol but we do not include the object file in the link
3166 (unless there is some other reason to include it). */
3169 aout_link_check_ar_symbols (abfd, info, pneeded)
3171 struct bfd_link_info *info;
3174 register struct external_nlist *p;
3175 struct external_nlist *pend;
3180 /* Look through all the symbols. */
3181 p = obj_aout_external_syms (abfd);
3182 pend = p + obj_aout_external_sym_count (abfd);
3183 strings = obj_aout_external_strings (abfd);
3184 for (; p < pend; p++)
3186 int type = H_GET_8 (abfd, p->e_type);
3188 struct bfd_link_hash_entry *h;
3190 /* Ignore symbols that are not externally visible. This is an
3191 optimization only, as we check the type more thoroughly
3193 if (((type & N_EXT) == 0
3194 || (type & N_STAB) != 0
3201 if (type == N_WARNING
3207 name = strings + GET_WORD (abfd, p->e_strx);
3208 h = bfd_link_hash_lookup (info->hash, name, false, false, true);
3210 /* We are only interested in symbols that are currently
3211 undefined or common. */
3212 if (h == (struct bfd_link_hash_entry *) NULL
3213 || (h->type != bfd_link_hash_undefined
3214 && h->type != bfd_link_hash_common))
3216 if (type == (N_INDR | N_EXT))
3221 if (type == (N_TEXT | N_EXT)
3222 || type == (N_DATA | N_EXT)
3223 || type == (N_BSS | N_EXT)
3224 || type == (N_ABS | N_EXT)
3225 || type == (N_INDR | N_EXT))
3227 /* This object file defines this symbol. We must link it
3228 in. This is true regardless of whether the current
3229 definition of the symbol is undefined or common.
3231 If the current definition is common, we have a case in
3232 which we have already seen an object file including:
3234 and this object file from the archive includes:
3236 In such a case, whether to include this object is target
3237 dependant for backward compatability.
3239 FIXME: The SunOS 4.1.3 linker will pull in the archive
3240 element if the symbol is defined in the .data section,
3241 but not if it is defined in the .text section. That
3242 seems a bit crazy to me, and it has not been implemented
3243 yet. However, it might be correct. */
3244 if (h->type == bfd_link_hash_common)
3248 switch (info->common_skip_ar_aymbols)
3250 case bfd_link_common_skip_text:
3251 skip = (type == (N_TEXT | N_EXT));
3253 case bfd_link_common_skip_data:
3254 skip = (type == (N_DATA | N_EXT));
3257 case bfd_link_common_skip_all:
3266 if (! (*info->callbacks->add_archive_element) (info, abfd, name))
3272 if (type == (N_UNDF | N_EXT))
3276 value = GET_WORD (abfd, p->e_value);
3279 /* This symbol is common in the object from the archive
3281 if (h->type == bfd_link_hash_undefined)
3286 symbfd = h->u.undef.abfd;
3287 if (symbfd == (bfd *) NULL)
3289 /* This symbol was created as undefined from
3290 outside BFD. We assume that we should link
3291 in the object file. This is done for the -u
3292 option in the linker. */
3293 if (! (*info->callbacks->add_archive_element) (info,
3300 /* Turn the current link symbol into a common
3301 symbol. It is already on the undefs list. */
3302 h->type = bfd_link_hash_common;
3303 h->u.c.p = ((struct bfd_link_hash_common_entry *)
3304 bfd_hash_allocate (&info->hash->table,
3305 sizeof (struct bfd_link_hash_common_entry)));
3306 if (h->u.c.p == NULL)
3309 h->u.c.size = value;
3311 /* FIXME: This isn't quite right. The maximum
3312 alignment of a common symbol should be set by the
3313 architecture of the output file, not of the input
3315 power = bfd_log2 (value);
3316 if (power > bfd_get_arch_info (abfd)->section_align_power)
3317 power = bfd_get_arch_info (abfd)->section_align_power;
3318 h->u.c.p->alignment_power = power;
3320 h->u.c.p->section = bfd_make_section_old_way (symbfd,
3325 /* Adjust the size of the common symbol if
3327 if (value > h->u.c.size)
3328 h->u.c.size = value;
3338 /* This symbol is weak but defined. We must pull it in if
3339 the current link symbol is undefined, but we don't want
3340 it if the current link symbol is common. */
3341 if (h->type == bfd_link_hash_undefined)
3343 if (! (*info->callbacks->add_archive_element) (info, abfd, name))
3351 /* We do not need this object file. */
3355 /* Add all symbols from an object file to the hash table. */
3358 aout_link_add_symbols (abfd, info)
3360 struct bfd_link_info *info;
3362 boolean (*add_one_symbol) PARAMS ((struct bfd_link_info *, bfd *,
3363 const char *, flagword, asection *,
3364 bfd_vma, const char *, boolean,
3366 struct bfd_link_hash_entry **));
3367 struct external_nlist *syms;
3368 bfd_size_type sym_count;
3371 struct aout_link_hash_entry **sym_hash;
3372 register struct external_nlist *p;
3373 struct external_nlist *pend;
3376 syms = obj_aout_external_syms (abfd);
3377 sym_count = obj_aout_external_sym_count (abfd);
3378 strings = obj_aout_external_strings (abfd);
3379 if (info->keep_memory)
3384 if (aout_backend_info (abfd)->add_dynamic_symbols != NULL)
3386 if (! ((*aout_backend_info (abfd)->add_dynamic_symbols)
3387 (abfd, info, &syms, &sym_count, &strings)))
3391 /* We keep a list of the linker hash table entries that correspond
3392 to particular symbols. We could just look them up in the hash
3393 table, but keeping the list is more efficient. Perhaps this
3394 should be conditional on info->keep_memory. */
3395 amt = sym_count * sizeof (struct aout_link_hash_entry *);
3396 sym_hash = (struct aout_link_hash_entry **) bfd_alloc (abfd, amt);
3397 if (sym_hash == NULL && sym_count != 0)
3399 obj_aout_sym_hashes (abfd) = sym_hash;
3401 add_one_symbol = aout_backend_info (abfd)->add_one_symbol;
3402 if (add_one_symbol == NULL)
3403 add_one_symbol = _bfd_generic_link_add_one_symbol;
3406 pend = p + sym_count;
3407 for (; p < pend; p++, sym_hash++)
3418 type = H_GET_8 (abfd, p->e_type);
3420 /* Ignore debugging symbols. */
3421 if ((type & N_STAB) != 0)
3424 name = strings + GET_WORD (abfd, p->e_strx);
3425 value = GET_WORD (abfd, p->e_value);
3442 /* Ignore symbols that are not externally visible. */
3445 /* Ignore local indirect symbol. */
3450 case N_UNDF | N_EXT:
3453 section = bfd_und_section_ptr;
3457 section = bfd_com_section_ptr;
3460 section = bfd_abs_section_ptr;
3462 case N_TEXT | N_EXT:
3463 section = obj_textsec (abfd);
3464 value -= bfd_get_section_vma (abfd, section);
3466 case N_DATA | N_EXT:
3467 case N_SETV | N_EXT:
3468 /* Treat N_SETV symbols as N_DATA symbol; see comment in
3469 translate_from_native_sym_flags. */
3470 section = obj_datasec (abfd);
3471 value -= bfd_get_section_vma (abfd, section);
3474 section = obj_bsssec (abfd);
3475 value -= bfd_get_section_vma (abfd, section);
3477 case N_INDR | N_EXT:
3478 /* An indirect symbol. The next symbol is the symbol
3479 which this one really is. */
3480 BFD_ASSERT (p + 1 < pend);
3482 string = strings + GET_WORD (abfd, p->e_strx);
3483 section = bfd_ind_section_ptr;
3484 flags |= BSF_INDIRECT;
3486 case N_COMM | N_EXT:
3487 section = bfd_com_section_ptr;
3489 case N_SETA: case N_SETA | N_EXT:
3490 section = bfd_abs_section_ptr;
3491 flags |= BSF_CONSTRUCTOR;
3493 case N_SETT: case N_SETT | N_EXT:
3494 section = obj_textsec (abfd);
3495 flags |= BSF_CONSTRUCTOR;
3496 value -= bfd_get_section_vma (abfd, section);
3498 case N_SETD: case N_SETD | N_EXT:
3499 section = obj_datasec (abfd);
3500 flags |= BSF_CONSTRUCTOR;
3501 value -= bfd_get_section_vma (abfd, section);
3503 case N_SETB: case N_SETB | N_EXT:
3504 section = obj_bsssec (abfd);
3505 flags |= BSF_CONSTRUCTOR;
3506 value -= bfd_get_section_vma (abfd, section);
3509 /* A warning symbol. The next symbol is the one to warn
3511 BFD_ASSERT (p + 1 < pend);
3514 name = strings + GET_WORD (abfd, p->e_strx);
3515 section = bfd_und_section_ptr;
3516 flags |= BSF_WARNING;
3519 section = bfd_und_section_ptr;
3523 section = bfd_abs_section_ptr;
3527 section = obj_textsec (abfd);
3528 value -= bfd_get_section_vma (abfd, section);
3532 section = obj_datasec (abfd);
3533 value -= bfd_get_section_vma (abfd, section);
3537 section = obj_bsssec (abfd);
3538 value -= bfd_get_section_vma (abfd, section);
3543 if (! ((*add_one_symbol)
3544 (info, abfd, name, flags, section, value, string, copy, false,
3545 (struct bfd_link_hash_entry **) sym_hash)))
3548 /* Restrict the maximum alignment of a common symbol based on
3549 the architecture, since a.out has no way to represent
3550 alignment requirements of a section in a .o file. FIXME:
3551 This isn't quite right: it should use the architecture of the
3552 output file, not the input files. */
3553 if ((*sym_hash)->root.type == bfd_link_hash_common
3554 && ((*sym_hash)->root.u.c.p->alignment_power >
3555 bfd_get_arch_info (abfd)->section_align_power))
3556 (*sym_hash)->root.u.c.p->alignment_power =
3557 bfd_get_arch_info (abfd)->section_align_power;
3559 /* If this is a set symbol, and we are not building sets, then
3560 it is possible for the hash entry to not have been set. In
3561 such a case, treat the symbol as not globally defined. */
3562 if ((*sym_hash)->root.type == bfd_link_hash_new)
3564 BFD_ASSERT ((flags & BSF_CONSTRUCTOR) != 0);
3568 if (type == (N_INDR | N_EXT) || type == N_WARNING)
3575 /* A hash table used for header files with N_BINCL entries. */
3577 struct aout_link_includes_table
3579 struct bfd_hash_table root;
3582 /* A linked list of totals that we have found for a particular header
3585 struct aout_link_includes_totals
3587 struct aout_link_includes_totals *next;
3591 /* An entry in the header file hash table. */
3593 struct aout_link_includes_entry
3595 struct bfd_hash_entry root;
3596 /* List of totals we have found for this file. */
3597 struct aout_link_includes_totals *totals;
3600 /* Look up an entry in an the header file hash table. */
3602 #define aout_link_includes_lookup(table, string, create, copy) \
3603 ((struct aout_link_includes_entry *) \
3604 bfd_hash_lookup (&(table)->root, (string), (create), (copy)))
3606 /* During the final link step we need to pass around a bunch of
3607 information, so we do it in an instance of this structure. */
3609 struct aout_final_link_info
3611 /* General link information. */
3612 struct bfd_link_info *info;
3615 /* Reloc file positions. */
3616 file_ptr treloff, dreloff;
3617 /* File position of symbols. */
3620 struct bfd_strtab_hash *strtab;
3621 /* Header file hash table. */
3622 struct aout_link_includes_table includes;
3623 /* A buffer large enough to hold the contents of any section. */
3625 /* A buffer large enough to hold the relocs of any section. */
3627 /* A buffer large enough to hold the symbol map of any input BFD. */
3629 /* A buffer large enough to hold output symbols of any input BFD. */
3630 struct external_nlist *output_syms;
3633 static struct bfd_hash_entry *aout_link_includes_newfunc
3634 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
3635 static boolean aout_link_input_bfd
3636 PARAMS ((struct aout_final_link_info *, bfd *input_bfd));
3637 static boolean aout_link_write_symbols
3638 PARAMS ((struct aout_final_link_info *, bfd *input_bfd));
3639 static boolean aout_link_write_other_symbol
3640 PARAMS ((struct aout_link_hash_entry *, PTR));
3641 static boolean aout_link_input_section
3642 PARAMS ((struct aout_final_link_info *, bfd *input_bfd,
3643 asection *input_section, file_ptr *reloff_ptr,
3644 bfd_size_type rel_size));
3645 static boolean aout_link_input_section_std
3646 PARAMS ((struct aout_final_link_info *, bfd *input_bfd,
3647 asection *input_section, struct reloc_std_external *,
3648 bfd_size_type rel_size, bfd_byte *contents));
3649 static boolean aout_link_input_section_ext
3650 PARAMS ((struct aout_final_link_info *, bfd *input_bfd,
3651 asection *input_section, struct reloc_ext_external *,
3652 bfd_size_type rel_size, bfd_byte *contents));
3653 static INLINE asection *aout_reloc_index_to_section
3654 PARAMS ((bfd *, int));
3655 static boolean aout_link_reloc_link_order
3656 PARAMS ((struct aout_final_link_info *, asection *,
3657 struct bfd_link_order *));
3659 /* The function to create a new entry in the header file hash table. */
3661 static struct bfd_hash_entry *
3662 aout_link_includes_newfunc (entry, table, string)
3663 struct bfd_hash_entry *entry;
3664 struct bfd_hash_table *table;
3667 struct aout_link_includes_entry *ret =
3668 (struct aout_link_includes_entry *) entry;
3670 /* Allocate the structure if it has not already been allocated by a
3672 if (ret == (struct aout_link_includes_entry *) NULL)
3673 ret = ((struct aout_link_includes_entry *)
3674 bfd_hash_allocate (table,
3675 sizeof (struct aout_link_includes_entry)));
3676 if (ret == (struct aout_link_includes_entry *) NULL)
3677 return (struct bfd_hash_entry *) ret;
3679 /* Call the allocation method of the superclass. */
3680 ret = ((struct aout_link_includes_entry *)
3681 bfd_hash_newfunc ((struct bfd_hash_entry *) ret, table, string));
3684 /* Set local fields. */
3688 return (struct bfd_hash_entry *) ret;
3691 /* Do the final link step. This is called on the output BFD. The
3692 INFO structure should point to a list of BFDs linked through the
3693 link_next field which can be used to find each BFD which takes part
3694 in the output. Also, each section in ABFD should point to a list
3695 of bfd_link_order structures which list all the input sections for
3696 the output section. */
3699 NAME(aout,final_link) (abfd, info, callback)
3701 struct bfd_link_info *info;
3702 void (*callback) PARAMS ((bfd *, file_ptr *, file_ptr *, file_ptr *));
3704 struct aout_final_link_info aout_info;
3705 boolean includes_hash_initialized = false;
3707 bfd_size_type trsize, drsize;
3708 bfd_size_type max_contents_size;
3709 bfd_size_type max_relocs_size;
3710 bfd_size_type max_sym_count;
3711 bfd_size_type text_size;
3713 register struct bfd_link_order *p;
3715 boolean have_link_order_relocs;
3718 abfd->flags |= DYNAMIC;
3720 aout_info.info = info;
3721 aout_info.output_bfd = abfd;
3722 aout_info.contents = NULL;
3723 aout_info.relocs = NULL;
3724 aout_info.symbol_map = NULL;
3725 aout_info.output_syms = NULL;
3727 if (! bfd_hash_table_init_n (&aout_info.includes.root,
3728 aout_link_includes_newfunc,
3731 includes_hash_initialized = true;
3733 /* Figure out the largest section size. Also, if generating
3734 relocateable output, count the relocs. */
3737 max_contents_size = 0;
3738 max_relocs_size = 0;
3740 for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
3744 if (info->relocateable)
3746 if (bfd_get_flavour (sub) == bfd_target_aout_flavour)
3748 trsize += exec_hdr (sub)->a_trsize;
3749 drsize += exec_hdr (sub)->a_drsize;
3753 /* FIXME: We need to identify the .text and .data sections
3754 and call get_reloc_upper_bound and canonicalize_reloc to
3755 work out the number of relocs needed, and then multiply
3756 by the reloc size. */
3757 (*_bfd_error_handler)
3758 (_("%s: relocateable link from %s to %s not supported"),
3759 bfd_get_filename (abfd),
3760 sub->xvec->name, abfd->xvec->name);
3761 bfd_set_error (bfd_error_invalid_operation);
3766 if (bfd_get_flavour (sub) == bfd_target_aout_flavour)
3768 sz = bfd_section_size (sub, obj_textsec (sub));
3769 if (sz > max_contents_size)
3770 max_contents_size = sz;
3771 sz = bfd_section_size (sub, obj_datasec (sub));
3772 if (sz > max_contents_size)
3773 max_contents_size = sz;
3775 sz = exec_hdr (sub)->a_trsize;
3776 if (sz > max_relocs_size)
3777 max_relocs_size = sz;
3778 sz = exec_hdr (sub)->a_drsize;
3779 if (sz > max_relocs_size)
3780 max_relocs_size = sz;
3782 sz = obj_aout_external_sym_count (sub);
3783 if (sz > max_sym_count)
3788 if (info->relocateable)
3790 if (obj_textsec (abfd) != (asection *) NULL)
3791 trsize += (_bfd_count_link_order_relocs (obj_textsec (abfd)
3793 * obj_reloc_entry_size (abfd));
3794 if (obj_datasec (abfd) != (asection *) NULL)
3795 drsize += (_bfd_count_link_order_relocs (obj_datasec (abfd)
3797 * obj_reloc_entry_size (abfd));
3800 exec_hdr (abfd)->a_trsize = trsize;
3801 exec_hdr (abfd)->a_drsize = drsize;
3803 exec_hdr (abfd)->a_entry = bfd_get_start_address (abfd);
3805 /* Adjust the section sizes and vmas according to the magic number.
3806 This sets a_text, a_data and a_bss in the exec_hdr and sets the
3807 filepos for each section. */
3808 if (! NAME(aout,adjust_sizes_and_vmas) (abfd, &text_size, &text_end))
3811 /* The relocation and symbol file positions differ among a.out
3812 targets. We are passed a callback routine from the backend
3813 specific code to handle this.
3814 FIXME: At this point we do not know how much space the symbol
3815 table will require. This will not work for any (nonstandard)
3816 a.out target that needs to know the symbol table size before it
3817 can compute the relocation file positions. This may or may not
3818 be the case for the hp300hpux target, for example. */
3819 (*callback) (abfd, &aout_info.treloff, &aout_info.dreloff,
3821 obj_textsec (abfd)->rel_filepos = aout_info.treloff;
3822 obj_datasec (abfd)->rel_filepos = aout_info.dreloff;
3823 obj_sym_filepos (abfd) = aout_info.symoff;
3825 /* We keep a count of the symbols as we output them. */
3826 obj_aout_external_sym_count (abfd) = 0;
3828 /* We accumulate the string table as we write out the symbols. */
3829 aout_info.strtab = _bfd_stringtab_init ();
3830 if (aout_info.strtab == NULL)
3833 /* Allocate buffers to hold section contents and relocs. */
3834 aout_info.contents = (bfd_byte *) bfd_malloc (max_contents_size);
3835 aout_info.relocs = (PTR) bfd_malloc (max_relocs_size);
3836 aout_info.symbol_map = (int *) bfd_malloc (max_sym_count * sizeof (int *));
3837 aout_info.output_syms = ((struct external_nlist *)
3838 bfd_malloc ((max_sym_count + 1)
3839 * sizeof (struct external_nlist)));
3840 if ((aout_info.contents == NULL && max_contents_size != 0)
3841 || (aout_info.relocs == NULL && max_relocs_size != 0)
3842 || (aout_info.symbol_map == NULL && max_sym_count != 0)
3843 || aout_info.output_syms == NULL)
3846 /* If we have a symbol named __DYNAMIC, force it out now. This is
3847 required by SunOS. Doing this here rather than in sunos.c is a
3848 hack, but it's easier than exporting everything which would be
3851 struct aout_link_hash_entry *h;
3853 h = aout_link_hash_lookup (aout_hash_table (info), "__DYNAMIC",
3854 false, false, false);
3856 aout_link_write_other_symbol (h, &aout_info);
3859 /* The most time efficient way to do the link would be to read all
3860 the input object files into memory and then sort out the
3861 information into the output file. Unfortunately, that will
3862 probably use too much memory. Another method would be to step
3863 through everything that composes the text section and write it
3864 out, and then everything that composes the data section and write
3865 it out, and then write out the relocs, and then write out the
3866 symbols. Unfortunately, that requires reading stuff from each
3867 input file several times, and we will not be able to keep all the
3868 input files open simultaneously, and reopening them will be slow.
3870 What we do is basically process one input file at a time. We do
3871 everything we need to do with an input file once--copy over the
3872 section contents, handle the relocation information, and write
3873 out the symbols--and then we throw away the information we read
3874 from it. This approach requires a lot of lseeks of the output
3875 file, which is unfortunate but still faster than reopening a lot
3878 We use the output_has_begun field of the input BFDs to see
3879 whether we have already handled it. */
3880 for (sub = info->input_bfds; sub != (bfd *) NULL; sub = sub->link_next)
3881 sub->output_has_begun = false;
3883 /* Mark all sections which are to be included in the link. This
3884 will normally be every section. We need to do this so that we
3885 can identify any sections which the linker has decided to not
3887 for (o = abfd->sections; o != NULL; o = o->next)
3889 for (p = o->link_order_head; p != NULL; p = p->next)
3891 if (p->type == bfd_indirect_link_order)
3892 p->u.indirect.section->linker_mark = true;
3896 have_link_order_relocs = false;
3897 for (o = abfd->sections; o != (asection *) NULL; o = o->next)
3899 for (p = o->link_order_head;
3900 p != (struct bfd_link_order *) NULL;
3903 if (p->type == bfd_indirect_link_order
3904 && (bfd_get_flavour (p->u.indirect.section->owner)
3905 == bfd_target_aout_flavour))
3909 input_bfd = p->u.indirect.section->owner;
3910 if (! input_bfd->output_has_begun)
3912 if (! aout_link_input_bfd (&aout_info, input_bfd))
3914 input_bfd->output_has_begun = true;
3917 else if (p->type == bfd_section_reloc_link_order
3918 || p->type == bfd_symbol_reloc_link_order)
3920 /* These are handled below. */
3921 have_link_order_relocs = true;
3925 if (! _bfd_default_link_order (abfd, info, o, p))
3931 /* Write out any symbols that we have not already written out. */
3932 aout_link_hash_traverse (aout_hash_table (info),
3933 aout_link_write_other_symbol,
3936 /* Now handle any relocs we were asked to create by the linker.
3937 These did not come from any input file. We must do these after
3938 we have written out all the symbols, so that we know the symbol
3940 if (have_link_order_relocs)
3942 for (o = abfd->sections; o != (asection *) NULL; o = o->next)
3944 for (p = o->link_order_head;
3945 p != (struct bfd_link_order *) NULL;
3948 if (p->type == bfd_section_reloc_link_order
3949 || p->type == bfd_symbol_reloc_link_order)
3951 if (! aout_link_reloc_link_order (&aout_info, o, p))
3958 if (aout_info.contents != NULL)
3960 free (aout_info.contents);
3961 aout_info.contents = NULL;
3963 if (aout_info.relocs != NULL)
3965 free (aout_info.relocs);
3966 aout_info.relocs = NULL;
3968 if (aout_info.symbol_map != NULL)
3970 free (aout_info.symbol_map);
3971 aout_info.symbol_map = NULL;
3973 if (aout_info.output_syms != NULL)
3975 free (aout_info.output_syms);
3976 aout_info.output_syms = NULL;
3978 if (includes_hash_initialized)
3980 bfd_hash_table_free (&aout_info.includes.root);
3981 includes_hash_initialized = false;
3984 /* Finish up any dynamic linking we may be doing. */
3985 if (aout_backend_info (abfd)->finish_dynamic_link != NULL)
3987 if (! (*aout_backend_info (abfd)->finish_dynamic_link) (abfd, info))
3991 /* Update the header information. */
3992 abfd->symcount = obj_aout_external_sym_count (abfd);
3993 exec_hdr (abfd)->a_syms = abfd->symcount * EXTERNAL_NLIST_SIZE;
3994 obj_str_filepos (abfd) = obj_sym_filepos (abfd) + exec_hdr (abfd)->a_syms;
3995 obj_textsec (abfd)->reloc_count =
3996 exec_hdr (abfd)->a_trsize / obj_reloc_entry_size (abfd);
3997 obj_datasec (abfd)->reloc_count =
3998 exec_hdr (abfd)->a_drsize / obj_reloc_entry_size (abfd);
4000 /* Write out the string table, unless there are no symbols. */
4001 if (abfd->symcount > 0)
4003 if (bfd_seek (abfd, obj_str_filepos (abfd), SEEK_SET) != 0
4004 || ! emit_stringtab (abfd, aout_info.strtab))
4007 else if (obj_textsec (abfd)->reloc_count == 0
4008 && obj_datasec (abfd)->reloc_count == 0)
4014 pos = obj_datasec (abfd)->filepos + exec_hdr (abfd)->a_data - 1;
4015 if (bfd_seek (abfd, pos, SEEK_SET) != 0
4016 || bfd_bwrite (&b, (bfd_size_type) 1, abfd) != 1)
4023 if (aout_info.contents != NULL)
4024 free (aout_info.contents);
4025 if (aout_info.relocs != NULL)
4026 free (aout_info.relocs);
4027 if (aout_info.symbol_map != NULL)
4028 free (aout_info.symbol_map);
4029 if (aout_info.output_syms != NULL)
4030 free (aout_info.output_syms);
4031 if (includes_hash_initialized)
4032 bfd_hash_table_free (&aout_info.includes.root);
4036 /* Link an a.out input BFD into the output file. */
4039 aout_link_input_bfd (finfo, input_bfd)
4040 struct aout_final_link_info *finfo;
4043 bfd_size_type sym_count;
4045 BFD_ASSERT (bfd_get_format (input_bfd) == bfd_object);
4047 /* If this is a dynamic object, it may need special handling. */
4048 if ((input_bfd->flags & DYNAMIC) != 0
4049 && aout_backend_info (input_bfd)->link_dynamic_object != NULL)
4051 return ((*aout_backend_info (input_bfd)->link_dynamic_object)
4052 (finfo->info, input_bfd));
4055 /* Get the symbols. We probably have them already, unless
4056 finfo->info->keep_memory is false. */
4057 if (! aout_get_external_symbols (input_bfd))
4060 sym_count = obj_aout_external_sym_count (input_bfd);
4062 /* Write out the symbols and get a map of the new indices. The map
4063 is placed into finfo->symbol_map. */
4064 if (! aout_link_write_symbols (finfo, input_bfd))
4067 /* Relocate and write out the sections. These functions use the
4068 symbol map created by aout_link_write_symbols. The linker_mark
4069 field will be set if these sections are to be included in the
4070 link, which will normally be the case. */
4071 if (obj_textsec (input_bfd)->linker_mark)
4073 if (! aout_link_input_section (finfo, input_bfd,
4074 obj_textsec (input_bfd),
4076 exec_hdr (input_bfd)->a_trsize))
4079 if (obj_datasec (input_bfd)->linker_mark)
4081 if (! aout_link_input_section (finfo, input_bfd,
4082 obj_datasec (input_bfd),
4084 exec_hdr (input_bfd)->a_drsize))
4088 /* If we are not keeping memory, we don't need the symbols any
4089 longer. We still need them if we are keeping memory, because the
4090 strings in the hash table point into them. */
4091 if (! finfo->info->keep_memory)
4093 if (! aout_link_free_symbols (input_bfd))
4100 /* Adjust and write out the symbols for an a.out file. Set the new
4101 symbol indices into a symbol_map. */
4104 aout_link_write_symbols (finfo, input_bfd)
4105 struct aout_final_link_info *finfo;
4109 bfd_size_type sym_count;
4111 enum bfd_link_strip strip;
4112 enum bfd_link_discard discard;
4113 struct external_nlist *outsym;
4114 bfd_size_type strtab_index;
4115 register struct external_nlist *sym;
4116 struct external_nlist *sym_end;
4117 struct aout_link_hash_entry **sym_hash;
4122 output_bfd = finfo->output_bfd;
4123 sym_count = obj_aout_external_sym_count (input_bfd);
4124 strings = obj_aout_external_strings (input_bfd);
4125 strip = finfo->info->strip;
4126 discard = finfo->info->discard;
4127 outsym = finfo->output_syms;
4129 /* First write out a symbol for this object file, unless we are
4130 discarding such symbols. */
4131 if (strip != strip_all
4132 && (strip != strip_some
4133 || bfd_hash_lookup (finfo->info->keep_hash, input_bfd->filename,
4134 false, false) != NULL)
4135 && discard != discard_all)
4137 H_PUT_8 (output_bfd, N_TEXT, outsym->e_type);
4138 H_PUT_8 (output_bfd, 0, outsym->e_other);
4139 H_PUT_16 (output_bfd, 0, outsym->e_desc);
4140 strtab_index = add_to_stringtab (output_bfd, finfo->strtab,
4141 input_bfd->filename, false);
4142 if (strtab_index == (bfd_size_type) -1)
4144 PUT_WORD (output_bfd, strtab_index, outsym->e_strx);
4145 PUT_WORD (output_bfd,
4146 (bfd_get_section_vma (output_bfd,
4147 obj_textsec (input_bfd)->output_section)
4148 + obj_textsec (input_bfd)->output_offset),
4150 ++obj_aout_external_sym_count (output_bfd);
4156 sym = obj_aout_external_syms (input_bfd);
4157 sym_end = sym + sym_count;
4158 sym_hash = obj_aout_sym_hashes (input_bfd);
4159 symbol_map = finfo->symbol_map;
4160 memset (symbol_map, 0, (size_t) sym_count * sizeof *symbol_map);
4161 for (; sym < sym_end; sym++, sym_hash++, symbol_map++)
4165 struct aout_link_hash_entry *h;
4171 /* We set *symbol_map to 0 above for all symbols. If it has
4172 already been set to -1 for this symbol, it means that we are
4173 discarding it because it appears in a duplicate header file.
4174 See the N_BINCL code below. */
4175 if (*symbol_map == -1)
4178 /* Initialize *symbol_map to -1, which means that the symbol was
4179 not copied into the output file. We will change it later if
4180 we do copy the symbol over. */
4183 type = H_GET_8 (input_bfd, sym->e_type);
4184 name = strings + GET_WORD (input_bfd, sym->e_strx);
4190 /* Pass this symbol through. It is the target of an
4191 indirect or warning symbol. */
4192 val = GET_WORD (input_bfd, sym->e_value);
4197 /* Skip this symbol, which is the target of an indirect
4198 symbol that we have changed to no longer be an indirect
4205 struct aout_link_hash_entry *hresolve;
4207 /* We have saved the hash table entry for this symbol, if
4208 there is one. Note that we could just look it up again
4209 in the hash table, provided we first check that it is an
4213 /* Use the name from the hash table, in case the symbol was
4216 && h->root.type != bfd_link_hash_warning)
4217 name = h->root.root.string;
4219 /* If this is an indirect or warning symbol, then change
4220 hresolve to the base symbol. We also change *sym_hash so
4221 that the relocation routines relocate against the real
4224 if (h != (struct aout_link_hash_entry *) NULL
4225 && (h->root.type == bfd_link_hash_indirect
4226 || h->root.type == bfd_link_hash_warning))
4228 hresolve = (struct aout_link_hash_entry *) h->root.u.i.link;
4229 while (hresolve->root.type == bfd_link_hash_indirect
4230 || hresolve->root.type == bfd_link_hash_warning)
4231 hresolve = ((struct aout_link_hash_entry *)
4232 hresolve->root.u.i.link);
4233 *sym_hash = hresolve;
4236 /* If the symbol has already been written out, skip it. */
4237 if (h != (struct aout_link_hash_entry *) NULL
4240 if ((type & N_TYPE) == N_INDR
4241 || type == N_WARNING)
4243 *symbol_map = h->indx;
4247 /* See if we are stripping this symbol. */
4253 case strip_debugger:
4254 if ((type & N_STAB) != 0)
4258 if (bfd_hash_lookup (finfo->info->keep_hash, name, false, false)
4268 if (h != (struct aout_link_hash_entry *) NULL)
4273 /* Get the value of the symbol. */
4274 if ((type & N_TYPE) == N_TEXT
4276 symsec = obj_textsec (input_bfd);
4277 else if ((type & N_TYPE) == N_DATA
4279 symsec = obj_datasec (input_bfd);
4280 else if ((type & N_TYPE) == N_BSS
4282 symsec = obj_bsssec (input_bfd);
4283 else if ((type & N_TYPE) == N_ABS
4285 symsec = bfd_abs_section_ptr;
4286 else if (((type & N_TYPE) == N_INDR
4287 && (hresolve == (struct aout_link_hash_entry *) NULL
4288 || (hresolve->root.type != bfd_link_hash_defined
4289 && hresolve->root.type != bfd_link_hash_defweak
4290 && hresolve->root.type != bfd_link_hash_common)))
4291 || type == N_WARNING)
4293 /* Pass the next symbol through unchanged. The
4294 condition above for indirect symbols is so that if
4295 the indirect symbol was defined, we output it with
4296 the correct definition so the debugger will
4299 val = GET_WORD (input_bfd, sym->e_value);
4302 else if ((type & N_STAB) != 0)
4304 val = GET_WORD (input_bfd, sym->e_value);
4309 /* If we get here with an indirect symbol, it means that
4310 we are outputting it with a real definition. In such
4311 a case we do not want to output the next symbol,
4312 which is the target of the indirection. */
4313 if ((type & N_TYPE) == N_INDR)
4318 /* We need to get the value from the hash table. We use
4319 hresolve so that if we have defined an indirect
4320 symbol we output the final definition. */
4321 if (h == (struct aout_link_hash_entry *) NULL)
4323 switch (type & N_TYPE)
4326 symsec = obj_textsec (input_bfd);
4329 symsec = obj_datasec (input_bfd);
4332 symsec = obj_bsssec (input_bfd);
4335 symsec = bfd_abs_section_ptr;
4342 else if (hresolve->root.type == bfd_link_hash_defined
4343 || hresolve->root.type == bfd_link_hash_defweak)
4345 asection *input_section;
4346 asection *output_section;
4348 /* This case usually means a common symbol which was
4349 turned into a defined symbol. */
4350 input_section = hresolve->root.u.def.section;
4351 output_section = input_section->output_section;
4352 BFD_ASSERT (bfd_is_abs_section (output_section)
4353 || output_section->owner == output_bfd);
4354 val = (hresolve->root.u.def.value
4355 + bfd_get_section_vma (output_bfd, output_section)
4356 + input_section->output_offset);
4358 /* Get the correct type based on the section. If
4359 this is a constructed set, force it to be
4360 globally visible. */
4369 if (output_section == obj_textsec (output_bfd))
4370 type |= (hresolve->root.type == bfd_link_hash_defined
4373 else if (output_section == obj_datasec (output_bfd))
4374 type |= (hresolve->root.type == bfd_link_hash_defined
4377 else if (output_section == obj_bsssec (output_bfd))
4378 type |= (hresolve->root.type == bfd_link_hash_defined
4382 type |= (hresolve->root.type == bfd_link_hash_defined
4386 else if (hresolve->root.type == bfd_link_hash_common)
4387 val = hresolve->root.u.c.size;
4388 else if (hresolve->root.type == bfd_link_hash_undefweak)
4396 if (symsec != (asection *) NULL)
4397 val = (symsec->output_section->vma
4398 + symsec->output_offset
4399 + (GET_WORD (input_bfd, sym->e_value)
4402 /* If this is a global symbol set the written flag, and if
4403 it is a local symbol see if we should discard it. */
4404 if (h != (struct aout_link_hash_entry *) NULL)
4407 h->indx = obj_aout_external_sym_count (output_bfd);
4409 else if ((type & N_TYPE) != N_SETT
4410 && (type & N_TYPE) != N_SETD
4411 && (type & N_TYPE) != N_SETB
4412 && (type & N_TYPE) != N_SETA)
4417 case discard_sec_merge:
4420 if ((type & N_STAB) == 0
4421 && bfd_is_local_label_name (input_bfd, name))
4435 /* An N_BINCL symbol indicates the start of the stabs
4436 entries for a header file. We need to scan ahead to the
4437 next N_EINCL symbol, ignoring nesting, adding up all the
4438 characters in the symbol names, not including the file
4439 numbers in types (the first number after an open
4441 if (type == N_BINCL)
4443 struct external_nlist *incl_sym;
4445 struct aout_link_includes_entry *incl_entry;
4446 struct aout_link_includes_totals *t;
4450 for (incl_sym = sym + 1; incl_sym < sym_end; incl_sym++)
4454 incl_type = H_GET_8 (input_bfd, incl_sym->e_type);
4455 if (incl_type == N_EINCL)
4461 else if (incl_type == N_BINCL)
4467 s = strings + GET_WORD (input_bfd, incl_sym->e_strx);
4468 for (; *s != '\0'; s++)
4473 /* Skip the file number. */
4475 while (ISDIGIT (*s))
4483 /* If we have already included a header file with the
4484 same value, then replace this one with an N_EXCL
4486 copy = ! finfo->info->keep_memory;
4487 incl_entry = aout_link_includes_lookup (&finfo->includes,
4489 if (incl_entry == NULL)
4491 for (t = incl_entry->totals; t != NULL; t = t->next)
4492 if (t->total == val)
4496 /* This is the first time we have seen this header
4497 file with this set of stabs strings. */
4498 t = ((struct aout_link_includes_totals *)
4499 bfd_hash_allocate (&finfo->includes.root,
4504 t->next = incl_entry->totals;
4505 incl_entry->totals = t;
4511 /* This is a duplicate header file. We must change
4512 it to be an N_EXCL entry, and mark all the
4513 included symbols to prevent outputting them. */
4517 for (incl_sym = sym + 1, incl_map = symbol_map + 1;
4519 incl_sym++, incl_map++)
4523 incl_type = H_GET_8 (input_bfd, incl_sym->e_type);
4524 if (incl_type == N_EINCL)
4533 else if (incl_type == N_BINCL)
4542 /* Copy this symbol into the list of symbols we are going to
4544 H_PUT_8 (output_bfd, type, outsym->e_type);
4545 H_PUT_8 (output_bfd, H_GET_8 (input_bfd, sym->e_other), outsym->e_other);
4546 H_PUT_16 (output_bfd, H_GET_16 (input_bfd, sym->e_desc), outsym->e_desc);
4548 if (! finfo->info->keep_memory)
4550 /* name points into a string table which we are going to
4551 free. If there is a hash table entry, use that string.
4552 Otherwise, copy name into memory. */
4553 if (h != (struct aout_link_hash_entry *) NULL)
4554 name = h->root.root.string;
4558 strtab_index = add_to_stringtab (output_bfd, finfo->strtab,
4560 if (strtab_index == (bfd_size_type) -1)
4562 PUT_WORD (output_bfd, strtab_index, outsym->e_strx);
4563 PUT_WORD (output_bfd, val, outsym->e_value);
4564 *symbol_map = obj_aout_external_sym_count (output_bfd);
4565 ++obj_aout_external_sym_count (output_bfd);
4569 /* Write out the output symbols we have just constructed. */
4570 if (outsym > finfo->output_syms)
4572 bfd_size_type outsym_size;
4574 if (bfd_seek (output_bfd, finfo->symoff, SEEK_SET) != 0)
4576 outsym_size = outsym - finfo->output_syms;
4577 outsym_size *= EXTERNAL_NLIST_SIZE;
4578 if (bfd_bwrite ((PTR) finfo->output_syms, outsym_size, output_bfd)
4581 finfo->symoff += outsym_size;
4587 /* Write out a symbol that was not associated with an a.out input
4591 aout_link_write_other_symbol (h, data)
4592 struct aout_link_hash_entry *h;
4595 struct aout_final_link_info *finfo = (struct aout_final_link_info *) data;
4599 struct external_nlist outsym;
4603 if (h->root.type == bfd_link_hash_warning)
4605 h = (struct aout_link_hash_entry *) h->root.u.i.link;
4606 if (h->root.type == bfd_link_hash_new)
4610 output_bfd = finfo->output_bfd;
4612 if (aout_backend_info (output_bfd)->write_dynamic_symbol != NULL)
4614 if (! ((*aout_backend_info (output_bfd)->write_dynamic_symbol)
4615 (output_bfd, finfo->info, h)))
4617 /* FIXME: No way to handle errors. */
4627 /* An indx of -2 means the symbol must be written. */
4629 && (finfo->info->strip == strip_all
4630 || (finfo->info->strip == strip_some
4631 && bfd_hash_lookup (finfo->info->keep_hash, h->root.root.string,
4632 false, false) == NULL)))
4635 switch (h->root.type)
4638 case bfd_link_hash_warning:
4640 /* Avoid variable not initialized warnings. */
4642 case bfd_link_hash_new:
4643 /* This can happen for set symbols when sets are not being
4646 case bfd_link_hash_undefined:
4647 type = N_UNDF | N_EXT;
4650 case bfd_link_hash_defined:
4651 case bfd_link_hash_defweak:
4655 sec = h->root.u.def.section->output_section;
4656 BFD_ASSERT (bfd_is_abs_section (sec)
4657 || sec->owner == output_bfd);
4658 if (sec == obj_textsec (output_bfd))
4659 type = h->root.type == bfd_link_hash_defined ? N_TEXT : N_WEAKT;
4660 else if (sec == obj_datasec (output_bfd))
4661 type = h->root.type == bfd_link_hash_defined ? N_DATA : N_WEAKD;
4662 else if (sec == obj_bsssec (output_bfd))
4663 type = h->root.type == bfd_link_hash_defined ? N_BSS : N_WEAKB;
4665 type = h->root.type == bfd_link_hash_defined ? N_ABS : N_WEAKA;
4667 val = (h->root.u.def.value
4669 + h->root.u.def.section->output_offset);
4672 case bfd_link_hash_common:
4673 type = N_UNDF | N_EXT;
4674 val = h->root.u.c.size;
4676 case bfd_link_hash_undefweak:
4679 case bfd_link_hash_indirect:
4680 /* We ignore these symbols, since the indirected symbol is
4681 already in the hash table. */
4685 H_PUT_8 (output_bfd, type, outsym.e_type);
4686 H_PUT_8 (output_bfd, 0, outsym.e_other);
4687 H_PUT_16 (output_bfd, 0, outsym.e_desc);
4688 indx = add_to_stringtab (output_bfd, finfo->strtab, h->root.root.string,
4690 if (indx == - (bfd_size_type) 1)
4692 /* FIXME: No way to handle errors. */
4695 PUT_WORD (output_bfd, indx, outsym.e_strx);
4696 PUT_WORD (output_bfd, val, outsym.e_value);
4698 amt = EXTERNAL_NLIST_SIZE;
4699 if (bfd_seek (output_bfd, finfo->symoff, SEEK_SET) != 0
4700 || bfd_bwrite ((PTR) &outsym, amt, output_bfd) != amt)
4702 /* FIXME: No way to handle errors. */
4706 finfo->symoff += EXTERNAL_NLIST_SIZE;
4707 h->indx = obj_aout_external_sym_count (output_bfd);
4708 ++obj_aout_external_sym_count (output_bfd);
4713 /* Link an a.out section into the output file. */
4716 aout_link_input_section (finfo, input_bfd, input_section, reloff_ptr,
4718 struct aout_final_link_info *finfo;
4720 asection *input_section;
4721 file_ptr *reloff_ptr;
4722 bfd_size_type rel_size;
4724 bfd_size_type input_size;
4727 /* Get the section contents. */
4728 input_size = bfd_section_size (input_bfd, input_section);
4729 if (! bfd_get_section_contents (input_bfd, input_section,
4730 (PTR) finfo->contents,
4731 (file_ptr) 0, input_size))
4734 /* Read in the relocs if we haven't already done it. */
4735 if (aout_section_data (input_section) != NULL
4736 && aout_section_data (input_section)->relocs != NULL)
4737 relocs = aout_section_data (input_section)->relocs;
4740 relocs = finfo->relocs;
4743 if (bfd_seek (input_bfd, input_section->rel_filepos, SEEK_SET) != 0
4744 || bfd_bread (relocs, rel_size, input_bfd) != rel_size)
4749 /* Relocate the section contents. */
4750 if (obj_reloc_entry_size (input_bfd) == RELOC_STD_SIZE)
4752 if (! aout_link_input_section_std (finfo, input_bfd, input_section,
4753 (struct reloc_std_external *) relocs,
4754 rel_size, finfo->contents))
4759 if (! aout_link_input_section_ext (finfo, input_bfd, input_section,
4760 (struct reloc_ext_external *) relocs,
4761 rel_size, finfo->contents))
4765 /* Write out the section contents. */
4766 if (! bfd_set_section_contents (finfo->output_bfd,
4767 input_section->output_section,
4768 (PTR) finfo->contents,
4769 (file_ptr) input_section->output_offset,
4773 /* If we are producing relocateable output, the relocs were
4774 modified, and we now write them out. */
4775 if (finfo->info->relocateable && rel_size > 0)
4777 if (bfd_seek (finfo->output_bfd, *reloff_ptr, SEEK_SET) != 0)
4779 if (bfd_bwrite (relocs, rel_size, finfo->output_bfd) != rel_size)
4781 *reloff_ptr += rel_size;
4783 /* Assert that the relocs have not run into the symbols, and
4784 that if these are the text relocs they have not run into the
4786 BFD_ASSERT (*reloff_ptr <= obj_sym_filepos (finfo->output_bfd)
4787 && (reloff_ptr != &finfo->treloff
4789 <= obj_datasec (finfo->output_bfd)->rel_filepos)));
4795 /* Get the section corresponding to a reloc index. */
4797 static INLINE asection *
4798 aout_reloc_index_to_section (abfd, indx)
4802 switch (indx & N_TYPE)
4805 return obj_textsec (abfd);
4807 return obj_datasec (abfd);
4809 return obj_bsssec (abfd);
4812 return bfd_abs_section_ptr;
4820 /* Relocate an a.out section using standard a.out relocs. */
4823 aout_link_input_section_std (finfo, input_bfd, input_section, relocs,
4825 struct aout_final_link_info *finfo;
4827 asection *input_section;
4828 struct reloc_std_external *relocs;
4829 bfd_size_type rel_size;
4832 boolean (*check_dynamic_reloc) PARAMS ((struct bfd_link_info *,
4834 struct aout_link_hash_entry *,
4835 PTR, bfd_byte *, boolean *,
4838 boolean relocateable;
4839 struct external_nlist *syms;
4841 struct aout_link_hash_entry **sym_hashes;
4843 bfd_size_type reloc_count;
4844 register struct reloc_std_external *rel;
4845 struct reloc_std_external *rel_end;
4847 output_bfd = finfo->output_bfd;
4848 check_dynamic_reloc = aout_backend_info (output_bfd)->check_dynamic_reloc;
4850 BFD_ASSERT (obj_reloc_entry_size (input_bfd) == RELOC_STD_SIZE);
4851 BFD_ASSERT (input_bfd->xvec->header_byteorder
4852 == output_bfd->xvec->header_byteorder);
4854 relocateable = finfo->info->relocateable;
4855 syms = obj_aout_external_syms (input_bfd);
4856 strings = obj_aout_external_strings (input_bfd);
4857 sym_hashes = obj_aout_sym_hashes (input_bfd);
4858 symbol_map = finfo->symbol_map;
4860 reloc_count = rel_size / RELOC_STD_SIZE;
4862 rel_end = rel + reloc_count;
4863 for (; rel < rel_end; rel++)
4870 reloc_howto_type *howto;
4871 struct aout_link_hash_entry *h = NULL;
4873 bfd_reloc_status_type r;
4875 r_addr = GET_SWORD (input_bfd, rel->r_address);
4877 #ifdef MY_reloc_howto
4878 howto = MY_reloc_howto (input_bfd, rel, r_index, r_extern, r_pcrel);
4884 unsigned int howto_idx;
4886 if (bfd_header_big_endian (input_bfd))
4888 r_index = ((rel->r_index[0] << 16)
4889 | (rel->r_index[1] << 8)
4891 r_extern = (0 != (rel->r_type[0] & RELOC_STD_BITS_EXTERN_BIG));
4892 r_pcrel = (0 != (rel->r_type[0] & RELOC_STD_BITS_PCREL_BIG));
4893 r_baserel = (0 != (rel->r_type[0] & RELOC_STD_BITS_BASEREL_BIG));
4894 r_jmptable= (0 != (rel->r_type[0] & RELOC_STD_BITS_JMPTABLE_BIG));
4895 r_relative= (0 != (rel->r_type[0] & RELOC_STD_BITS_RELATIVE_BIG));
4896 r_length = ((rel->r_type[0] & RELOC_STD_BITS_LENGTH_BIG)
4897 >> RELOC_STD_BITS_LENGTH_SH_BIG);
4901 r_index = ((rel->r_index[2] << 16)
4902 | (rel->r_index[1] << 8)
4904 r_extern = (0 != (rel->r_type[0] & RELOC_STD_BITS_EXTERN_LITTLE));
4905 r_pcrel = (0 != (rel->r_type[0] & RELOC_STD_BITS_PCREL_LITTLE));
4906 r_baserel = (0 != (rel->r_type[0]
4907 & RELOC_STD_BITS_BASEREL_LITTLE));
4908 r_jmptable= (0 != (rel->r_type[0]
4909 & RELOC_STD_BITS_JMPTABLE_LITTLE));
4910 r_relative= (0 != (rel->r_type[0]
4911 & RELOC_STD_BITS_RELATIVE_LITTLE));
4912 r_length = ((rel->r_type[0] & RELOC_STD_BITS_LENGTH_LITTLE)
4913 >> RELOC_STD_BITS_LENGTH_SH_LITTLE);
4916 howto_idx = (r_length + 4 * r_pcrel + 8 * r_baserel
4917 + 16 * r_jmptable + 32 * r_relative);
4918 BFD_ASSERT (howto_idx < TABLE_SIZE (howto_table_std));
4919 howto = howto_table_std + howto_idx;
4925 /* We are generating a relocateable output file, and must
4926 modify the reloc accordingly. */
4929 /* If we know the symbol this relocation is against,
4930 convert it into a relocation against a section. This
4931 is what the native linker does. */
4932 h = sym_hashes[r_index];
4933 if (h != (struct aout_link_hash_entry *) NULL
4934 && (h->root.type == bfd_link_hash_defined
4935 || h->root.type == bfd_link_hash_defweak))
4937 asection *output_section;
4939 /* Change the r_extern value. */
4940 if (bfd_header_big_endian (output_bfd))
4941 rel->r_type[0] &=~ RELOC_STD_BITS_EXTERN_BIG;
4943 rel->r_type[0] &=~ RELOC_STD_BITS_EXTERN_LITTLE;
4945 /* Compute a new r_index. */
4946 output_section = h->root.u.def.section->output_section;
4947 if (output_section == obj_textsec (output_bfd))
4949 else if (output_section == obj_datasec (output_bfd))
4951 else if (output_section == obj_bsssec (output_bfd))
4956 /* Add the symbol value and the section VMA to the
4957 addend stored in the contents. */
4958 relocation = (h->root.u.def.value
4959 + output_section->vma
4960 + h->root.u.def.section->output_offset);
4964 /* We must change r_index according to the symbol
4966 r_index = symbol_map[r_index];
4972 /* We decided to strip this symbol, but it
4973 turns out that we can't. Note that we
4974 lose the other and desc information here.
4975 I don't think that will ever matter for a
4981 if (! aout_link_write_other_symbol (h,
4991 name = strings + GET_WORD (input_bfd,
4992 syms[r_index].e_strx);
4993 if (! ((*finfo->info->callbacks->unattached_reloc)
4994 (finfo->info, name, input_bfd, input_section,
5004 /* Write out the new r_index value. */
5005 if (bfd_header_big_endian (output_bfd))
5007 rel->r_index[0] = r_index >> 16;
5008 rel->r_index[1] = r_index >> 8;
5009 rel->r_index[2] = r_index;
5013 rel->r_index[2] = r_index >> 16;
5014 rel->r_index[1] = r_index >> 8;
5015 rel->r_index[0] = r_index;
5022 /* This is a relocation against a section. We must
5023 adjust by the amount that the section moved. */
5024 section = aout_reloc_index_to_section (input_bfd, r_index);
5025 relocation = (section->output_section->vma
5026 + section->output_offset
5030 /* Change the address of the relocation. */
5031 PUT_WORD (output_bfd,
5032 r_addr + input_section->output_offset,
5035 /* Adjust a PC relative relocation by removing the reference
5036 to the original address in the section and including the
5037 reference to the new address. */
5039 relocation -= (input_section->output_section->vma
5040 + input_section->output_offset
5041 - input_section->vma);
5043 #ifdef MY_relocatable_reloc
5044 MY_relocatable_reloc (howto, output_bfd, rel, relocation, r_addr);
5047 if (relocation == 0)
5050 r = MY_relocate_contents (howto,
5051 input_bfd, relocation,
5058 /* We are generating an executable, and must do a full
5064 h = sym_hashes[r_index];
5066 if (h != (struct aout_link_hash_entry *) NULL
5067 && (h->root.type == bfd_link_hash_defined
5068 || h->root.type == bfd_link_hash_defweak))
5070 relocation = (h->root.u.def.value
5071 + h->root.u.def.section->output_section->vma
5072 + h->root.u.def.section->output_offset);
5074 else if (h != (struct aout_link_hash_entry *) NULL
5075 && h->root.type == bfd_link_hash_undefweak)
5087 section = aout_reloc_index_to_section (input_bfd, r_index);
5088 relocation = (section->output_section->vma
5089 + section->output_offset
5092 relocation += input_section->vma;
5095 if (check_dynamic_reloc != NULL)
5099 if (! ((*check_dynamic_reloc)
5100 (finfo->info, input_bfd, input_section, h,
5101 (PTR) rel, contents, &skip, &relocation)))
5107 /* Now warn if a global symbol is undefined. We could not
5108 do this earlier, because check_dynamic_reloc might want
5109 to skip this reloc. */
5110 if (hundef && ! finfo->info->shared && ! r_baserel)
5115 name = h->root.root.string;
5117 name = strings + GET_WORD (input_bfd, syms[r_index].e_strx);
5118 if (! ((*finfo->info->callbacks->undefined_symbol)
5119 (finfo->info, name, input_bfd, input_section,
5124 r = MY_final_link_relocate (howto,
5125 input_bfd, input_section,
5126 contents, r_addr, relocation,
5130 if (r != bfd_reloc_ok)
5135 case bfd_reloc_outofrange:
5137 case bfd_reloc_overflow:
5142 name = h->root.root.string;
5144 name = strings + GET_WORD (input_bfd,
5145 syms[r_index].e_strx);
5150 s = aout_reloc_index_to_section (input_bfd, r_index);
5151 name = bfd_section_name (input_bfd, s);
5153 if (! ((*finfo->info->callbacks->reloc_overflow)
5154 (finfo->info, name, howto->name,
5155 (bfd_vma) 0, input_bfd, input_section, r_addr)))
5166 /* Relocate an a.out section using extended a.out relocs. */
5169 aout_link_input_section_ext (finfo, input_bfd, input_section, relocs,
5171 struct aout_final_link_info *finfo;
5173 asection *input_section;
5174 struct reloc_ext_external *relocs;
5175 bfd_size_type rel_size;
5178 boolean (*check_dynamic_reloc) PARAMS ((struct bfd_link_info *,
5180 struct aout_link_hash_entry *,
5181 PTR, bfd_byte *, boolean *,
5184 boolean relocateable;
5185 struct external_nlist *syms;
5187 struct aout_link_hash_entry **sym_hashes;
5189 bfd_size_type reloc_count;
5190 register struct reloc_ext_external *rel;
5191 struct reloc_ext_external *rel_end;
5193 output_bfd = finfo->output_bfd;
5194 check_dynamic_reloc = aout_backend_info (output_bfd)->check_dynamic_reloc;
5196 BFD_ASSERT (obj_reloc_entry_size (input_bfd) == RELOC_EXT_SIZE);
5197 BFD_ASSERT (input_bfd->xvec->header_byteorder
5198 == output_bfd->xvec->header_byteorder);
5200 relocateable = finfo->info->relocateable;
5201 syms = obj_aout_external_syms (input_bfd);
5202 strings = obj_aout_external_strings (input_bfd);
5203 sym_hashes = obj_aout_sym_hashes (input_bfd);
5204 symbol_map = finfo->symbol_map;
5206 reloc_count = rel_size / RELOC_EXT_SIZE;
5208 rel_end = rel + reloc_count;
5209 for (; rel < rel_end; rel++)
5214 unsigned int r_type;
5216 struct aout_link_hash_entry *h = NULL;
5217 asection *r_section = NULL;
5220 r_addr = GET_SWORD (input_bfd, rel->r_address);
5222 if (bfd_header_big_endian (input_bfd))
5224 r_index = ((rel->r_index[0] << 16)
5225 | (rel->r_index[1] << 8)
5227 r_extern = (0 != (rel->r_type[0] & RELOC_EXT_BITS_EXTERN_BIG));
5228 r_type = ((rel->r_type[0] & RELOC_EXT_BITS_TYPE_BIG)
5229 >> RELOC_EXT_BITS_TYPE_SH_BIG);
5233 r_index = ((rel->r_index[2] << 16)
5234 | (rel->r_index[1] << 8)
5236 r_extern = (0 != (rel->r_type[0] & RELOC_EXT_BITS_EXTERN_LITTLE));
5237 r_type = ((rel->r_type[0] & RELOC_EXT_BITS_TYPE_LITTLE)
5238 >> RELOC_EXT_BITS_TYPE_SH_LITTLE);
5241 r_addend = GET_SWORD (input_bfd, rel->r_addend);
5243 BFD_ASSERT (r_type < TABLE_SIZE (howto_table_ext));
5247 /* We are generating a relocateable output file, and must
5248 modify the reloc accordingly. */
5250 || r_type == RELOC_BASE10
5251 || r_type == RELOC_BASE13
5252 || r_type == RELOC_BASE22)
5254 /* If we know the symbol this relocation is against,
5255 convert it into a relocation against a section. This
5256 is what the native linker does. */
5257 if (r_type == RELOC_BASE10
5258 || r_type == RELOC_BASE13
5259 || r_type == RELOC_BASE22)
5262 h = sym_hashes[r_index];
5263 if (h != (struct aout_link_hash_entry *) NULL
5264 && (h->root.type == bfd_link_hash_defined
5265 || h->root.type == bfd_link_hash_defweak))
5267 asection *output_section;
5269 /* Change the r_extern value. */
5270 if (bfd_header_big_endian (output_bfd))
5271 rel->r_type[0] &=~ RELOC_EXT_BITS_EXTERN_BIG;
5273 rel->r_type[0] &=~ RELOC_EXT_BITS_EXTERN_LITTLE;
5275 /* Compute a new r_index. */
5276 output_section = h->root.u.def.section->output_section;
5277 if (output_section == obj_textsec (output_bfd))
5279 else if (output_section == obj_datasec (output_bfd))
5281 else if (output_section == obj_bsssec (output_bfd))
5286 /* Add the symbol value and the section VMA to the
5288 relocation = (h->root.u.def.value
5289 + output_section->vma
5290 + h->root.u.def.section->output_offset);
5292 /* Now RELOCATION is the VMA of the final
5293 destination. If this is a PC relative reloc,
5294 then ADDEND is the negative of the source VMA.
5295 We want to set ADDEND to the difference between
5296 the destination VMA and the source VMA, which
5297 means we must adjust RELOCATION by the change in
5298 the source VMA. This is done below. */
5302 /* We must change r_index according to the symbol
5304 r_index = symbol_map[r_index];
5310 /* We decided to strip this symbol, but it
5311 turns out that we can't. Note that we
5312 lose the other and desc information here.
5313 I don't think that will ever matter for a
5319 if (! aout_link_write_other_symbol (h,
5329 name = strings + GET_WORD (input_bfd,
5330 syms[r_index].e_strx);
5331 if (! ((*finfo->info->callbacks->unattached_reloc)
5332 (finfo->info, name, input_bfd, input_section,
5341 /* If this is a PC relative reloc, then the addend
5342 is the negative of the source VMA. We must
5343 adjust it by the change in the source VMA. This
5347 /* Write out the new r_index value. */
5348 if (bfd_header_big_endian (output_bfd))
5350 rel->r_index[0] = r_index >> 16;
5351 rel->r_index[1] = r_index >> 8;
5352 rel->r_index[2] = r_index;
5356 rel->r_index[2] = r_index >> 16;
5357 rel->r_index[1] = r_index >> 8;
5358 rel->r_index[0] = r_index;
5363 /* This is a relocation against a section. We must
5364 adjust by the amount that the section moved. */
5365 r_section = aout_reloc_index_to_section (input_bfd, r_index);
5366 relocation = (r_section->output_section->vma
5367 + r_section->output_offset
5370 /* If this is a PC relative reloc, then the addend is
5371 the difference in VMA between the destination and the
5372 source. We have just adjusted for the change in VMA
5373 of the destination, so we must also adjust by the
5374 change in VMA of the source. This is done below. */
5377 /* As described above, we must always adjust a PC relative
5378 reloc by the change in VMA of the source. However, if
5379 pcrel_offset is set, then the addend does not include the
5380 location within the section, in which case we don't need
5381 to adjust anything. */
5382 if (howto_table_ext[r_type].pc_relative
5383 && ! howto_table_ext[r_type].pcrel_offset)
5384 relocation -= (input_section->output_section->vma
5385 + input_section->output_offset
5386 - input_section->vma);
5388 /* Change the addend if necessary. */
5389 if (relocation != 0)
5390 PUT_WORD (output_bfd, r_addend + relocation, rel->r_addend);
5392 /* Change the address of the relocation. */
5393 PUT_WORD (output_bfd,
5394 r_addr + input_section->output_offset,
5400 bfd_reloc_status_type r;
5402 /* We are generating an executable, and must do a full
5408 h = sym_hashes[r_index];
5410 if (h != (struct aout_link_hash_entry *) NULL
5411 && (h->root.type == bfd_link_hash_defined
5412 || h->root.type == bfd_link_hash_defweak))
5414 relocation = (h->root.u.def.value
5415 + h->root.u.def.section->output_section->vma
5416 + h->root.u.def.section->output_offset);
5418 else if (h != (struct aout_link_hash_entry *) NULL
5419 && h->root.type == bfd_link_hash_undefweak)
5427 else if (r_type == RELOC_BASE10
5428 || r_type == RELOC_BASE13
5429 || r_type == RELOC_BASE22)
5431 struct external_nlist *sym;
5434 /* For base relative relocs, r_index is always an index
5435 into the symbol table, even if r_extern is 0. */
5436 sym = syms + r_index;
5437 type = H_GET_8 (input_bfd, sym->e_type);
5438 if ((type & N_TYPE) == N_TEXT
5440 r_section = obj_textsec (input_bfd);
5441 else if ((type & N_TYPE) == N_DATA
5443 r_section = obj_datasec (input_bfd);
5444 else if ((type & N_TYPE) == N_BSS
5446 r_section = obj_bsssec (input_bfd);
5447 else if ((type & N_TYPE) == N_ABS
5449 r_section = bfd_abs_section_ptr;
5452 relocation = (r_section->output_section->vma
5453 + r_section->output_offset
5454 + (GET_WORD (input_bfd, sym->e_value)
5459 r_section = aout_reloc_index_to_section (input_bfd, r_index);
5461 /* If this is a PC relative reloc, then R_ADDEND is the
5462 difference between the two vmas, or
5463 old_dest_sec + old_dest_off - (old_src_sec + old_src_off)
5465 old_dest_sec == section->vma
5467 old_src_sec == input_section->vma
5469 old_src_off == r_addr
5471 _bfd_final_link_relocate expects RELOCATION +
5472 R_ADDEND to be the VMA of the destination minus
5473 r_addr (the minus r_addr is because this relocation
5474 is not pcrel_offset, which is a bit confusing and
5475 should, perhaps, be changed), or
5478 new_dest_sec == output_section->vma + output_offset
5479 We arrange for this to happen by setting RELOCATION to
5480 new_dest_sec + old_src_sec - old_dest_sec
5482 If this is not a PC relative reloc, then R_ADDEND is
5483 simply the VMA of the destination, so we set
5484 RELOCATION to the change in the destination VMA, or
5485 new_dest_sec - old_dest_sec
5487 relocation = (r_section->output_section->vma
5488 + r_section->output_offset
5490 if (howto_table_ext[r_type].pc_relative)
5491 relocation += input_section->vma;
5494 if (check_dynamic_reloc != NULL)
5498 if (! ((*check_dynamic_reloc)
5499 (finfo->info, input_bfd, input_section, h,
5500 (PTR) rel, contents, &skip, &relocation)))
5506 /* Now warn if a global symbol is undefined. We could not
5507 do this earlier, because check_dynamic_reloc might want
5508 to skip this reloc. */
5510 && ! finfo->info->shared
5511 && r_type != RELOC_BASE10
5512 && r_type != RELOC_BASE13
5513 && r_type != RELOC_BASE22)
5518 name = h->root.root.string;
5520 name = strings + GET_WORD (input_bfd, syms[r_index].e_strx);
5521 if (! ((*finfo->info->callbacks->undefined_symbol)
5522 (finfo->info, name, input_bfd, input_section,
5527 if (r_type != RELOC_SPARC_REV32)
5528 r = MY_final_link_relocate (howto_table_ext + r_type,
5529 input_bfd, input_section,
5530 contents, r_addr, relocation,
5536 x = bfd_get_32 (input_bfd, contents + r_addr);
5537 x = x + relocation + r_addend;
5538 bfd_putl32 (/*input_bfd,*/ x, contents + r_addr);
5542 if (r != bfd_reloc_ok)
5547 case bfd_reloc_outofrange:
5549 case bfd_reloc_overflow:
5554 name = h->root.root.string;
5556 || r_type == RELOC_BASE10
5557 || r_type == RELOC_BASE13
5558 || r_type == RELOC_BASE22)
5559 name = strings + GET_WORD (input_bfd,
5560 syms[r_index].e_strx);
5565 s = aout_reloc_index_to_section (input_bfd, r_index);
5566 name = bfd_section_name (input_bfd, s);
5568 if (! ((*finfo->info->callbacks->reloc_overflow)
5569 (finfo->info, name, howto_table_ext[r_type].name,
5570 r_addend, input_bfd, input_section, r_addr)))
5582 /* Handle a link order which is supposed to generate a reloc. */
5585 aout_link_reloc_link_order (finfo, o, p)
5586 struct aout_final_link_info *finfo;
5588 struct bfd_link_order *p;
5590 struct bfd_link_order_reloc *pr;
5593 reloc_howto_type *howto;
5594 file_ptr *reloff_ptr = NULL;
5595 struct reloc_std_external srel;
5596 struct reloc_ext_external erel;
5602 if (p->type == bfd_section_reloc_link_order)
5605 if (bfd_is_abs_section (pr->u.section))
5606 r_index = N_ABS | N_EXT;
5609 BFD_ASSERT (pr->u.section->owner == finfo->output_bfd);
5610 r_index = pr->u.section->target_index;
5615 struct aout_link_hash_entry *h;
5617 BFD_ASSERT (p->type == bfd_symbol_reloc_link_order);
5619 h = ((struct aout_link_hash_entry *)
5620 bfd_wrapped_link_hash_lookup (finfo->output_bfd, finfo->info,
5621 pr->u.name, false, false, true));
5622 if (h != (struct aout_link_hash_entry *) NULL
5627 /* We decided to strip this symbol, but it turns out that we
5628 can't. Note that we lose the other and desc information
5629 here. I don't think that will ever matter for a global
5633 if (! aout_link_write_other_symbol (h, (PTR) finfo))
5639 if (! ((*finfo->info->callbacks->unattached_reloc)
5640 (finfo->info, pr->u.name, (bfd *) NULL,
5641 (asection *) NULL, (bfd_vma) 0)))
5647 howto = bfd_reloc_type_lookup (finfo->output_bfd, pr->reloc);
5650 bfd_set_error (bfd_error_bad_value);
5654 if (o == obj_textsec (finfo->output_bfd))
5655 reloff_ptr = &finfo->treloff;
5656 else if (o == obj_datasec (finfo->output_bfd))
5657 reloff_ptr = &finfo->dreloff;
5661 if (obj_reloc_entry_size (finfo->output_bfd) == RELOC_STD_SIZE)
5664 MY_put_reloc (finfo->output_bfd, r_extern, r_index, p->offset, howto,
5674 r_pcrel = howto->pc_relative;
5675 r_baserel = (howto->type & 8) != 0;
5676 r_jmptable = (howto->type & 16) != 0;
5677 r_relative = (howto->type & 32) != 0;
5678 r_length = howto->size;
5680 PUT_WORD (finfo->output_bfd, p->offset, srel.r_address);
5681 if (bfd_header_big_endian (finfo->output_bfd))
5683 srel.r_index[0] = r_index >> 16;
5684 srel.r_index[1] = r_index >> 8;
5685 srel.r_index[2] = r_index;
5687 ((r_extern ? RELOC_STD_BITS_EXTERN_BIG : 0)
5688 | (r_pcrel ? RELOC_STD_BITS_PCREL_BIG : 0)
5689 | (r_baserel ? RELOC_STD_BITS_BASEREL_BIG : 0)
5690 | (r_jmptable ? RELOC_STD_BITS_JMPTABLE_BIG : 0)
5691 | (r_relative ? RELOC_STD_BITS_RELATIVE_BIG : 0)
5692 | (r_length << RELOC_STD_BITS_LENGTH_SH_BIG));
5696 srel.r_index[2] = r_index >> 16;
5697 srel.r_index[1] = r_index >> 8;
5698 srel.r_index[0] = r_index;
5700 ((r_extern ? RELOC_STD_BITS_EXTERN_LITTLE : 0)
5701 | (r_pcrel ? RELOC_STD_BITS_PCREL_LITTLE : 0)
5702 | (r_baserel ? RELOC_STD_BITS_BASEREL_LITTLE : 0)
5703 | (r_jmptable ? RELOC_STD_BITS_JMPTABLE_LITTLE : 0)
5704 | (r_relative ? RELOC_STD_BITS_RELATIVE_LITTLE : 0)
5705 | (r_length << RELOC_STD_BITS_LENGTH_SH_LITTLE));
5709 rel_ptr = (PTR) &srel;
5711 /* We have to write the addend into the object file, since
5712 standard a.out relocs are in place. It would be more
5713 reliable if we had the current contents of the file here,
5714 rather than assuming zeroes, but we can't read the file since
5715 it was opened using bfd_openw. */
5716 if (pr->addend != 0)
5719 bfd_reloc_status_type r;
5723 size = bfd_get_reloc_size (howto);
5724 buf = (bfd_byte *) bfd_zmalloc (size);
5725 if (buf == (bfd_byte *) NULL)
5727 r = MY_relocate_contents (howto, finfo->output_bfd,
5728 (bfd_vma) pr->addend, buf);
5734 case bfd_reloc_outofrange:
5736 case bfd_reloc_overflow:
5737 if (! ((*finfo->info->callbacks->reloc_overflow)
5739 (p->type == bfd_section_reloc_link_order
5740 ? bfd_section_name (finfo->output_bfd,
5743 howto->name, pr->addend, (bfd *) NULL,
5744 (asection *) NULL, (bfd_vma) 0)))
5751 ok = bfd_set_section_contents (finfo->output_bfd, o, (PTR) buf,
5752 (file_ptr) p->offset, size);
5760 #ifdef MY_put_ext_reloc
5761 MY_put_ext_reloc (finfo->output_bfd, r_extern, r_index, p->offset,
5762 howto, &erel, pr->addend);
5764 PUT_WORD (finfo->output_bfd, p->offset, erel.r_address);
5766 if (bfd_header_big_endian (finfo->output_bfd))
5768 erel.r_index[0] = r_index >> 16;
5769 erel.r_index[1] = r_index >> 8;
5770 erel.r_index[2] = r_index;
5772 ((r_extern ? RELOC_EXT_BITS_EXTERN_BIG : 0)
5773 | (howto->type << RELOC_EXT_BITS_TYPE_SH_BIG));
5777 erel.r_index[2] = r_index >> 16;
5778 erel.r_index[1] = r_index >> 8;
5779 erel.r_index[0] = r_index;
5781 (r_extern ? RELOC_EXT_BITS_EXTERN_LITTLE : 0)
5782 | (howto->type << RELOC_EXT_BITS_TYPE_SH_LITTLE);
5785 PUT_WORD (finfo->output_bfd, (bfd_vma) pr->addend, erel.r_addend);
5786 #endif /* MY_put_ext_reloc */
5788 rel_ptr = (PTR) &erel;
5791 amt = obj_reloc_entry_size (finfo->output_bfd);
5792 if (bfd_seek (finfo->output_bfd, *reloff_ptr, SEEK_SET) != 0
5793 || bfd_bwrite (rel_ptr, amt, finfo->output_bfd) != amt)
5796 *reloff_ptr += obj_reloc_entry_size (finfo->output_bfd);
5798 /* Assert that the relocs have not run into the symbols, and that n
5799 the text relocs have not run into the data relocs. */
5800 BFD_ASSERT (*reloff_ptr <= obj_sym_filepos (finfo->output_bfd)
5801 && (reloff_ptr != &finfo->treloff
5803 <= obj_datasec (finfo->output_bfd)->rel_filepos)));