1 /* BFD semi-generic back-end for a.out binaries.
2 Copyright 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
3 Written by Cygnus Support.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
28 BFD supports a number of different flavours of a.out format,
29 though the major differences are only the sizes of the
30 structures on disk, and the shape of the relocation
33 The support is split into a basic support file @file{aoutx.h}
34 and other files which derive functions from the base. One
35 derivation file is @file{aoutf1.h} (for a.out flavour 1), and
36 adds to the basic a.out functions support for sun3, sun4, 386
37 and 29k a.out files, to create a target jump vector for a
40 This information is further split out into more specific files
41 for each machine, including @file{sunos.c} for sun3 and sun4,
42 @file{newsos3.c} for the Sony NEWS, and @file{demo64.c} for a
43 demonstration of a 64 bit a.out format.
45 The base file @file{aoutx.h} defines general mechanisms for
46 reading and writing records to and from disk and various
47 other methods which BFD requires. It is included by
48 @file{aout32.c} and @file{aout64.c} to form the names
49 <<aout_32_swap_exec_header_in>>, <<aout_64_swap_exec_header_in>>, etc.
51 As an example, this is what goes on to make the back end for a
52 sun4, from @file{aout32.c}:
54 | #define ARCH_SIZE 32
60 | aout_32_canonicalize_reloc
61 | aout_32_find_nearest_line
63 | 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.) */
122 #define KEEPITTYPE int
125 #include <string.h> /* For strchr and friends */
132 #include "aout/aout64.h"
133 #include "aout/stab_gnu.h"
136 static boolean aout_get_external_symbols PARAMS ((bfd *));
143 The file @file{aoutx.h} provides for both the @emph{standard}
144 and @emph{extended} forms of a.out relocation records.
146 The standard records contain only an
147 address, a symbol index, and a type field. The extended records
148 (used on 29ks and sparcs) also have a full integer for an
152 #define CTOR_TABLE_RELOC_IDX 2
154 #define howto_table_ext NAME(aout,ext_howto_table)
155 #define howto_table_std NAME(aout,std_howto_table)
157 reloc_howto_type howto_table_ext[] =
159 /* type rs size bsz pcrel bitpos ovrf sf name part_inpl readmask setmask pcdone */
160 HOWTO(RELOC_8, 0, 0, 8, false, 0, complain_overflow_bitfield,0,"8", false, 0,0x000000ff, false),
161 HOWTO(RELOC_16, 0, 1, 16, false, 0, complain_overflow_bitfield,0,"16", false, 0,0x0000ffff, false),
162 HOWTO(RELOC_32, 0, 2, 32, false, 0, complain_overflow_bitfield,0,"32", false, 0,0xffffffff, false),
163 HOWTO(RELOC_DISP8, 0, 0, 8, true, 0, complain_overflow_signed,0,"DISP8", false, 0,0x000000ff, false),
164 HOWTO(RELOC_DISP16, 0, 1, 16, true, 0, complain_overflow_signed,0,"DISP16", false, 0,0x0000ffff, false),
165 HOWTO(RELOC_DISP32, 0, 2, 32, true, 0, complain_overflow_signed,0,"DISP32", false, 0,0xffffffff, false),
166 HOWTO(RELOC_WDISP30,2, 2, 30, true, 0, complain_overflow_signed,0,"WDISP30", false, 0,0x3fffffff, false),
167 HOWTO(RELOC_WDISP22,2, 2, 22, true, 0, complain_overflow_signed,0,"WDISP22", false, 0,0x003fffff, false),
168 HOWTO(RELOC_HI22, 10, 2, 22, false, 0, complain_overflow_bitfield,0,"HI22", false, 0,0x003fffff, false),
169 HOWTO(RELOC_22, 0, 2, 22, false, 0, complain_overflow_bitfield,0,"22", false, 0,0x003fffff, false),
170 HOWTO(RELOC_13, 0, 2, 13, false, 0, complain_overflow_bitfield,0,"13", false, 0,0x00001fff, false),
171 HOWTO(RELOC_LO10, 0, 2, 10, false, 0, complain_overflow_dont,0,"LO10", false, 0,0x000003ff, false),
172 HOWTO(RELOC_SFA_BASE,0, 2, 32, false, 0, complain_overflow_bitfield,0,"SFA_BASE", false, 0,0xffffffff, false),
173 HOWTO(RELOC_SFA_OFF13,0,2, 32, false, 0, complain_overflow_bitfield,0,"SFA_OFF13",false, 0,0xffffffff, false),
174 HOWTO(RELOC_BASE10, 0, 2, 16, false, 0, complain_overflow_bitfield,0,"BASE10", false, 0,0x0000ffff, false),
175 HOWTO(RELOC_BASE13, 0, 2, 13, false, 0, complain_overflow_bitfield,0,"BASE13", false, 0,0x00001fff, false),
176 HOWTO(RELOC_BASE22, 0, 2, 0, false, 0, complain_overflow_bitfield,0,"BASE22", false, 0,0x00000000, false),
177 HOWTO(RELOC_PC10, 0, 2, 10, false, 0, complain_overflow_bitfield,0,"PC10", false, 0,0x000003ff, false),
178 HOWTO(RELOC_PC22, 0, 2, 22, false, 0, complain_overflow_bitfield,0,"PC22", false, 0,0x003fffff, false),
179 HOWTO(RELOC_JMP_TBL,0, 2, 32, false, 0, complain_overflow_bitfield,0,"JMP_TBL", false, 0,0xffffffff, false),
180 HOWTO(RELOC_SEGOFF16,0, 2, 0, false, 0, complain_overflow_bitfield,0,"SEGOFF16", false, 0,0x00000000, false),
181 HOWTO(RELOC_GLOB_DAT,0, 2, 0, false, 0, complain_overflow_bitfield,0,"GLOB_DAT", false, 0,0x00000000, false),
182 HOWTO(RELOC_JMP_SLOT,0, 2, 0, false, 0, complain_overflow_bitfield,0,"JMP_SLOT", false, 0,0x00000000, false),
183 HOWTO(RELOC_RELATIVE,0, 2, 0, false, 0, complain_overflow_bitfield,0,"RELATIVE", false, 0,0x00000000, false),
186 /* Convert standard reloc records to "arelent" format (incl byte swap). */
188 reloc_howto_type howto_table_std[] = {
189 /* type rs size bsz pcrel bitpos ovrf sf name part_inpl readmask setmask pcdone */
190 HOWTO( 0, 0, 0, 8, false, 0, complain_overflow_bitfield,0,"8", true, 0x000000ff,0x000000ff, false),
191 HOWTO( 1, 0, 1, 16, false, 0, complain_overflow_bitfield,0,"16", true, 0x0000ffff,0x0000ffff, false),
192 HOWTO( 2, 0, 2, 32, false, 0, complain_overflow_bitfield,0,"32", true, 0xffffffff,0xffffffff, false),
193 HOWTO( 3, 0, 4, 64, false, 0, complain_overflow_bitfield,0,"64", true, 0xdeaddead,0xdeaddead, false),
194 HOWTO( 4, 0, 0, 8, true, 0, complain_overflow_signed, 0,"DISP8", true, 0x000000ff,0x000000ff, false),
195 HOWTO( 5, 0, 1, 16, true, 0, complain_overflow_signed, 0,"DISP16", true, 0x0000ffff,0x0000ffff, false),
196 HOWTO( 6, 0, 2, 32, true, 0, complain_overflow_signed, 0,"DISP32", true, 0xffffffff,0xffffffff, false),
197 HOWTO( 7, 0, 4, 64, true, 0, complain_overflow_signed, 0,"DISP64", true, 0xfeedface,0xfeedface, false),
199 HOWTO( 9, 0, 1, 16, false, 0, complain_overflow_bitfield,0,"BASE16", false,0xffffffff,0xffffffff, false),
200 HOWTO(10, 0, 2, 32, false, 0, complain_overflow_bitfield,0,"BASE32", false,0xffffffff,0xffffffff, false),
203 #define TABLE_SIZE(TABLE) (sizeof(TABLE)/sizeof(TABLE[0]))
205 CONST struct reloc_howto_struct *
206 NAME(aout,reloc_type_lookup) (abfd,code)
208 bfd_reloc_code_real_type code;
210 #define EXT(i,j) case i: return &howto_table_ext[j]
211 #define STD(i,j) case i: return &howto_table_std[j]
212 int ext = obj_reloc_entry_size (abfd) == RELOC_EXT_SIZE;
213 if (code == BFD_RELOC_CTOR)
214 switch (bfd_get_arch_info (abfd)->bits_per_address)
226 EXT (BFD_RELOC_32, 2);
227 EXT (BFD_RELOC_HI22, 8);
228 EXT (BFD_RELOC_LO10, 11);
229 EXT (BFD_RELOC_32_PCREL_S2, 6);
230 EXT (BFD_RELOC_SPARC_WDISP22, 7);
231 EXT (BFD_RELOC_SPARC13, 10);
232 EXT (BFD_RELOC_SPARC_BASE13, 15);
233 default: return (CONST struct reloc_howto_struct *) 0;
239 STD (BFD_RELOC_16, 1);
240 STD (BFD_RELOC_32, 2);
241 STD (BFD_RELOC_8_PCREL, 4);
242 STD (BFD_RELOC_16_PCREL, 5);
243 STD (BFD_RELOC_32_PCREL, 6);
244 STD (BFD_RELOC_16_BASEREL, 9);
245 STD (BFD_RELOC_32_BASEREL, 10);
246 default: return (CONST struct reloc_howto_struct *) 0;
252 Internal entry points
255 @file{aoutx.h} exports several routines for accessing the
256 contents of an a.out file, which are gathered and exported in
257 turn by various format specific files (eg sunos.c).
263 aout_@var{size}_swap_exec_header_in
266 void aout_@var{size}_swap_exec_header_in,
268 struct external_exec *raw_bytes,
269 struct internal_exec *execp);
272 Swap the information in an executable header @var{raw_bytes} taken
273 from a raw byte stream memory image into the internal exec header
274 structure @var{execp}.
277 #ifndef NAME_swap_exec_header_in
279 NAME(aout,swap_exec_header_in) (abfd, raw_bytes, execp)
281 struct external_exec *raw_bytes;
282 struct internal_exec *execp;
284 struct external_exec *bytes = (struct external_exec *)raw_bytes;
286 /* The internal_exec structure has some fields that are unused in this
287 configuration (IE for i960), so ensure that all such uninitialized
288 fields are zero'd out. There are places where two of these structs
289 are memcmp'd, and thus the contents do matter. */
290 memset ((PTR) execp, 0, sizeof (struct internal_exec));
291 /* Now fill in fields in the execp, from the bytes in the raw data. */
292 execp->a_info = bfd_h_get_32 (abfd, bytes->e_info);
293 execp->a_text = GET_WORD (abfd, bytes->e_text);
294 execp->a_data = GET_WORD (abfd, bytes->e_data);
295 execp->a_bss = GET_WORD (abfd, bytes->e_bss);
296 execp->a_syms = GET_WORD (abfd, bytes->e_syms);
297 execp->a_entry = GET_WORD (abfd, bytes->e_entry);
298 execp->a_trsize = GET_WORD (abfd, bytes->e_trsize);
299 execp->a_drsize = GET_WORD (abfd, bytes->e_drsize);
301 #define NAME_swap_exec_header_in NAME(aout,swap_exec_header_in)
306 aout_@var{size}_swap_exec_header_out
309 void aout_@var{size}_swap_exec_header_out
311 struct internal_exec *execp,
312 struct external_exec *raw_bytes);
315 Swap the information in an internal exec header structure
316 @var{execp} into the buffer @var{raw_bytes} ready for writing to disk.
319 NAME(aout,swap_exec_header_out) (abfd, execp, raw_bytes)
321 struct internal_exec *execp;
322 struct external_exec *raw_bytes;
324 struct external_exec *bytes = (struct external_exec *)raw_bytes;
326 /* Now fill in fields in the raw data, from the fields in the exec struct. */
327 bfd_h_put_32 (abfd, execp->a_info , bytes->e_info);
328 PUT_WORD (abfd, execp->a_text , bytes->e_text);
329 PUT_WORD (abfd, execp->a_data , bytes->e_data);
330 PUT_WORD (abfd, execp->a_bss , bytes->e_bss);
331 PUT_WORD (abfd, execp->a_syms , bytes->e_syms);
332 PUT_WORD (abfd, execp->a_entry , bytes->e_entry);
333 PUT_WORD (abfd, execp->a_trsize, bytes->e_trsize);
334 PUT_WORD (abfd, execp->a_drsize, bytes->e_drsize);
341 aout_@var{size}_some_aout_object_p
344 bfd_target *aout_@var{size}_some_aout_object_p
346 bfd_target *(*callback_to_real_object_p)());
349 Some a.out variant thinks that the file open in @var{abfd}
350 checking is an a.out file. Do some more checking, and set up
351 for access if it really is. Call back to the calling
352 environment's "finish up" function just before returning, to
353 handle any last-minute setup.
357 NAME(aout,some_aout_object_p) (abfd, execp, callback_to_real_object_p)
359 struct internal_exec *execp;
360 bfd_target *(*callback_to_real_object_p) PARAMS ((bfd *));
362 struct aout_data_struct *rawptr, *oldrawptr;
365 rawptr = (struct aout_data_struct *) bfd_zalloc (abfd, sizeof (struct aout_data_struct ));
366 if (rawptr == NULL) {
367 bfd_set_error (bfd_error_no_memory);
371 oldrawptr = abfd->tdata.aout_data;
372 abfd->tdata.aout_data = rawptr;
374 /* Copy the contents of the old tdata struct.
375 In particular, we want the subformat, since for hpux it was set in
376 hp300hpux.c:swap_exec_header_in and will be used in
377 hp300hpux.c:callback. */
378 if (oldrawptr != NULL)
379 *abfd->tdata.aout_data = *oldrawptr;
381 abfd->tdata.aout_data->a.hdr = &rawptr->e;
382 *(abfd->tdata.aout_data->a.hdr) = *execp; /* Copy in the internal_exec struct */
383 execp = abfd->tdata.aout_data->a.hdr;
385 /* Set the file flags */
386 abfd->flags = NO_FLAGS;
387 if (execp->a_drsize || execp->a_trsize)
388 abfd->flags |= HAS_RELOC;
389 /* Setting of EXEC_P has been deferred to the bottom of this function */
391 abfd->flags |= HAS_LINENO | HAS_DEBUG | HAS_SYMS | HAS_LOCALS;
392 if (N_DYNAMIC(*execp))
393 abfd->flags |= DYNAMIC;
395 if (N_MAGIC (*execp) == ZMAGIC)
397 abfd->flags |= D_PAGED|WP_TEXT;
398 adata(abfd).magic = z_magic;
400 else if (N_MAGIC (*execp) == NMAGIC)
402 abfd->flags |= WP_TEXT;
403 adata(abfd).magic = n_magic;
406 adata(abfd).magic = o_magic;
408 bfd_get_start_address (abfd) = execp->a_entry;
410 obj_aout_symbols (abfd) = (aout_symbol_type *)NULL;
411 bfd_get_symcount (abfd) = execp->a_syms / sizeof (struct external_nlist);
413 /* The default relocation entry size is that of traditional V7 Unix. */
414 obj_reloc_entry_size (abfd) = RELOC_STD_SIZE;
416 /* The default symbol entry size is that of traditional Unix. */
417 obj_symbol_entry_size (abfd) = EXTERNAL_NLIST_SIZE;
419 obj_aout_external_syms (abfd) = NULL;
420 obj_aout_external_strings (abfd) = NULL;
421 obj_aout_sym_hashes (abfd) = NULL;
423 /* Create the sections. This is raunchy, but bfd_close wants to reclaim
426 obj_textsec (abfd) = bfd_make_section_old_way (abfd, ".text");
427 obj_datasec (abfd) = bfd_make_section_old_way (abfd, ".data");
428 obj_bsssec (abfd) = bfd_make_section_old_way (abfd, ".bss");
431 (void)bfd_make_section (abfd, ".text");
432 (void)bfd_make_section (abfd, ".data");
433 (void)bfd_make_section (abfd, ".bss");
436 obj_datasec (abfd)->_raw_size = execp->a_data;
437 obj_bsssec (abfd)->_raw_size = execp->a_bss;
439 /* If this object is dynamically linked, we assume that both
440 sections have relocs. This does no real harm, even though it may
442 obj_textsec (abfd)->flags =
443 (execp->a_trsize != 0 || (abfd->flags & DYNAMIC) != 0
444 ? (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS | SEC_RELOC)
445 : (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS));
446 obj_datasec (abfd)->flags =
447 (execp->a_drsize != 0 || (abfd->flags & DYNAMIC) != 0
448 ? (SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_HAS_CONTENTS | SEC_RELOC)
449 : (SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_HAS_CONTENTS));
450 obj_bsssec (abfd)->flags = SEC_ALLOC;
452 #ifdef THIS_IS_ONLY_DOCUMENTATION
453 /* The common code can't fill in these things because they depend
454 on either the start address of the text segment, the rounding
455 up of virtual addresses between segments, or the starting file
456 position of the text segment -- all of which varies among different
457 versions of a.out. */
459 /* Call back to the format-dependent code to fill in the rest of the
460 fields and do any further cleanup. Things that should be filled
461 in by the callback: */
463 struct exec *execp = exec_hdr (abfd);
465 obj_textsec (abfd)->size = N_TXTSIZE(*execp);
466 obj_textsec (abfd)->raw_size = N_TXTSIZE(*execp);
467 /* data and bss are already filled in since they're so standard */
469 /* The virtual memory addresses of the sections */
470 obj_textsec (abfd)->vma = N_TXTADDR(*execp);
471 obj_datasec (abfd)->vma = N_DATADDR(*execp);
472 obj_bsssec (abfd)->vma = N_BSSADDR(*execp);
474 /* The file offsets of the sections */
475 obj_textsec (abfd)->filepos = N_TXTOFF(*execp);
476 obj_datasec (abfd)->filepos = N_DATOFF(*execp);
478 /* The file offsets of the relocation info */
479 obj_textsec (abfd)->rel_filepos = N_TRELOFF(*execp);
480 obj_datasec (abfd)->rel_filepos = N_DRELOFF(*execp);
482 /* The file offsets of the string table and symbol table. */
483 obj_str_filepos (abfd) = N_STROFF (*execp);
484 obj_sym_filepos (abfd) = N_SYMOFF (*execp);
486 /* Determine the architecture and machine type of the object file. */
487 switch (N_MACHTYPE (*exec_hdr (abfd))) {
489 abfd->obj_arch = bfd_arch_obscure;
493 adata(abfd)->page_size = PAGE_SIZE;
494 adata(abfd)->segment_size = SEGMENT_SIZE;
495 adata(abfd)->exec_bytes_size = EXEC_BYTES_SIZE;
499 /* The architecture is encoded in various ways in various a.out variants,
500 or is not encoded at all in some of them. The relocation size depends
501 on the architecture and the a.out variant. Finally, the return value
502 is the bfd_target vector in use. If an error occurs, return zero and
503 set bfd_error to the appropriate error code.
505 Formats such as b.out, which have additional fields in the a.out
506 header, should cope with them in this callback as well. */
507 #endif /* DOCUMENTATION */
509 result = (*callback_to_real_object_p)(abfd);
511 /* Now that the segment addresses have been worked out, take a better
512 guess at whether the file is executable. If the entry point
513 is within the text segment, assume it is. (This makes files
514 executable even if their entry point address is 0, as long as
515 their text starts at zero.)
517 At some point we should probably break down and stat the file and
518 declare it executable if (one of) its 'x' bits are on... */
519 if ((execp->a_entry >= obj_textsec(abfd)->vma) &&
520 (execp->a_entry < obj_textsec(abfd)->vma + obj_textsec(abfd)->_raw_size))
521 abfd->flags |= EXEC_P;
524 #if 0 /* These should be set correctly anyways. */
525 abfd->sections = obj_textsec (abfd);
526 obj_textsec (abfd)->next = obj_datasec (abfd);
527 obj_datasec (abfd)->next = obj_bsssec (abfd);
533 abfd->tdata.aout_data = oldrawptr;
540 aout_@var{size}_mkobject
543 boolean aout_@var{size}_mkobject, (bfd *abfd);
546 Initialize BFD @var{abfd} for use with a.out files.
550 NAME(aout,mkobject) (abfd)
553 struct aout_data_struct *rawptr;
555 bfd_set_error (bfd_error_system_call);
557 /* Use an intermediate variable for clarity */
558 rawptr = (struct aout_data_struct *)bfd_zalloc (abfd, sizeof (struct aout_data_struct ));
560 if (rawptr == NULL) {
561 bfd_set_error (bfd_error_no_memory);
565 abfd->tdata.aout_data = rawptr;
566 exec_hdr (abfd) = &(rawptr->e);
568 /* For simplicity's sake we just make all the sections right here. */
570 obj_textsec (abfd) = (asection *)NULL;
571 obj_datasec (abfd) = (asection *)NULL;
572 obj_bsssec (abfd) = (asection *)NULL;
573 bfd_make_section (abfd, ".text");
574 bfd_make_section (abfd, ".data");
575 bfd_make_section (abfd, ".bss");
576 bfd_make_section (abfd, BFD_ABS_SECTION_NAME);
577 bfd_make_section (abfd, BFD_UND_SECTION_NAME);
578 bfd_make_section (abfd, BFD_COM_SECTION_NAME);
586 aout_@var{size}_machine_type
589 enum machine_type aout_@var{size}_machine_type
590 (enum bfd_architecture arch,
591 unsigned long machine));
594 Keep track of machine architecture and machine type for
595 a.out's. Return the <<machine_type>> for a particular
596 architecture and machine, or <<M_UNKNOWN>> if that exact architecture
597 and machine can't be represented in a.out format.
599 If the architecture is understood, machine type 0 (default)
600 is always understood.
604 NAME(aout,machine_type) (arch, machine)
605 enum bfd_architecture arch;
606 unsigned long machine;
608 enum machine_type arch_flags;
610 arch_flags = M_UNKNOWN;
614 if (machine == 0) arch_flags = M_SPARC;
619 case 0: arch_flags = M_68010; break;
620 case 68000: arch_flags = M_UNKNOWN; break;
621 case 68010: arch_flags = M_68010; break;
622 case 68020: arch_flags = M_68020; break;
623 default: arch_flags = M_UNKNOWN; break;
628 if (machine == 0) arch_flags = M_386;
632 if (machine == 0) arch_flags = M_29K;
639 case 3000: arch_flags = M_MIPS1; break;
642 case 6000: arch_flags = M_MIPS2; break;
643 default: arch_flags = M_UNKNOWN; break;
648 arch_flags = M_UNKNOWN;
656 aout_@var{size}_set_arch_mach
659 boolean aout_@var{size}_set_arch_mach,
661 enum bfd_architecture arch,
662 unsigned long machine));
665 Set the architecture and the machine of the BFD @var{abfd} to the
666 values @var{arch} and @var{machine}. Verify that @var{abfd}'s format
667 can support the architecture required.
671 NAME(aout,set_arch_mach) (abfd, arch, machine)
673 enum bfd_architecture arch;
674 unsigned long machine;
676 if (! bfd_default_set_arch_mach (abfd, arch, machine))
679 if (arch != bfd_arch_unknown &&
680 NAME(aout,machine_type) (arch, machine) == M_UNKNOWN)
681 return false; /* We can't represent this type */
683 /* Determine the size of a relocation entry */
688 obj_reloc_entry_size (abfd) = RELOC_EXT_SIZE;
691 obj_reloc_entry_size (abfd) = RELOC_STD_SIZE;
695 return (*aout_backend_info(abfd)->set_sizes) (abfd);
699 adjust_o_magic (abfd, execp)
701 struct internal_exec *execp;
703 file_ptr pos = adata (abfd).exec_bytes_size;
708 obj_textsec(abfd)->filepos = pos;
709 pos += obj_textsec(abfd)->_raw_size;
710 vma += obj_textsec(abfd)->_raw_size;
713 if (!obj_datasec(abfd)->user_set_vma)
715 #if 0 /* ?? Does alignment in the file image really matter? */
716 pad = align_power (vma, obj_datasec(abfd)->alignment_power) - vma;
718 obj_textsec(abfd)->_raw_size += pad;
721 obj_datasec(abfd)->vma = vma;
723 obj_datasec(abfd)->filepos = pos;
724 pos += obj_datasec(abfd)->_raw_size;
725 vma += obj_datasec(abfd)->_raw_size;
728 if (!obj_bsssec(abfd)->user_set_vma)
731 pad = align_power (vma, obj_bsssec(abfd)->alignment_power) - vma;
733 obj_datasec(abfd)->_raw_size += pad;
736 obj_bsssec(abfd)->vma = vma;
738 obj_bsssec(abfd)->filepos = pos;
740 /* Fix up the exec header. */
741 execp->a_text = obj_textsec(abfd)->_raw_size;
742 execp->a_data = obj_datasec(abfd)->_raw_size;
743 execp->a_bss = obj_bsssec(abfd)->_raw_size;
744 N_SET_MAGIC (*execp, OMAGIC);
748 adjust_z_magic (abfd, execp)
750 struct internal_exec *execp;
752 bfd_size_type data_pad, text_pad;
754 CONST struct aout_backend_data *abdp;
755 int ztih; /* Nonzero if text includes exec header. */
757 abdp = aout_backend_info (abfd);
760 ztih = abdp && abdp->text_includes_header;
761 obj_textsec(abfd)->filepos = (ztih
762 ? adata(abfd).exec_bytes_size
763 : adata(abfd).page_size);
764 if (! obj_textsec(abfd)->user_set_vma)
765 /* ?? Do we really need to check for relocs here? */
766 obj_textsec(abfd)->vma = ((abfd->flags & HAS_RELOC)
769 ? (abdp->default_text_vma
770 + adata(abfd).exec_bytes_size)
771 : abdp->default_text_vma));
772 /* Could take strange alignment of text section into account here? */
774 /* Find start of data. */
775 text_end = obj_textsec(abfd)->filepos + obj_textsec(abfd)->_raw_size;
776 text_pad = BFD_ALIGN (text_end, adata(abfd).page_size) - text_end;
777 obj_textsec(abfd)->_raw_size += text_pad;
778 text_end += text_pad;
781 if (!obj_datasec(abfd)->user_set_vma)
784 vma = obj_textsec(abfd)->vma + obj_textsec(abfd)->_raw_size;
785 obj_datasec(abfd)->vma = BFD_ALIGN (vma, adata(abfd).segment_size);
787 if (abdp && abdp->zmagic_mapped_contiguous)
789 text_pad = (obj_datasec(abfd)->vma
790 - obj_textsec(abfd)->vma
791 - obj_textsec(abfd)->_raw_size);
792 obj_textsec(abfd)->_raw_size += text_pad;
794 obj_datasec(abfd)->filepos = (obj_textsec(abfd)->filepos
795 + obj_textsec(abfd)->_raw_size);
797 /* Fix up exec header while we're at it. */
798 execp->a_text = obj_textsec(abfd)->_raw_size;
799 if (ztih && (!abdp || (abdp && !abdp->exec_header_not_counted)))
800 execp->a_text += adata(abfd).exec_bytes_size;
801 N_SET_MAGIC (*execp, ZMAGIC);
803 /* Spec says data section should be rounded up to page boundary. */
804 obj_datasec(abfd)->_raw_size
805 = align_power (obj_datasec(abfd)->_raw_size,
806 obj_bsssec(abfd)->alignment_power);
807 execp->a_data = BFD_ALIGN (obj_datasec(abfd)->_raw_size,
808 adata(abfd).page_size);
809 data_pad = execp->a_data - obj_datasec(abfd)->_raw_size;
812 if (!obj_bsssec(abfd)->user_set_vma)
813 obj_bsssec(abfd)->vma = (obj_datasec(abfd)->vma
814 + obj_datasec(abfd)->_raw_size);
815 /* If the BSS immediately follows the data section and extra space
816 in the page is left after the data section, fudge data
817 in the header so that the bss section looks smaller by that
818 amount. We'll start the bss section there, and lie to the OS.
819 (Note that a linker script, as well as the above assignment,
820 could have explicitly set the BSS vma to immediately follow
821 the data section.) */
822 if (align_power (obj_bsssec(abfd)->vma, obj_bsssec(abfd)->alignment_power)
823 == obj_datasec(abfd)->vma + obj_datasec(abfd)->_raw_size)
824 execp->a_bss = (data_pad > obj_bsssec(abfd)->_raw_size) ? 0 :
825 obj_bsssec(abfd)->_raw_size - data_pad;
827 execp->a_bss = obj_bsssec(abfd)->_raw_size;
831 adjust_n_magic (abfd, execp)
833 struct internal_exec *execp;
835 file_ptr pos = adata(abfd).exec_bytes_size;
840 obj_textsec(abfd)->filepos = pos;
841 if (!obj_textsec(abfd)->user_set_vma)
842 obj_textsec(abfd)->vma = vma;
844 vma = obj_textsec(abfd)->vma;
845 pos += obj_textsec(abfd)->_raw_size;
846 vma += obj_textsec(abfd)->_raw_size;
849 obj_datasec(abfd)->filepos = pos;
850 if (!obj_datasec(abfd)->user_set_vma)
851 obj_datasec(abfd)->vma = BFD_ALIGN (vma, adata(abfd).segment_size);
852 vma = obj_datasec(abfd)->vma;
854 /* Since BSS follows data immediately, see if it needs alignment. */
855 vma += obj_datasec(abfd)->_raw_size;
856 pad = align_power (vma, obj_bsssec(abfd)->alignment_power) - vma;
857 obj_datasec(abfd)->_raw_size += pad;
858 pos += obj_datasec(abfd)->_raw_size;
861 if (!obj_bsssec(abfd)->user_set_vma)
862 obj_bsssec(abfd)->vma = vma;
864 vma = obj_bsssec(abfd)->vma;
866 /* Fix up exec header. */
867 execp->a_text = obj_textsec(abfd)->_raw_size;
868 execp->a_data = obj_datasec(abfd)->_raw_size;
869 execp->a_bss = obj_bsssec(abfd)->_raw_size;
870 N_SET_MAGIC (*execp, NMAGIC);
874 NAME(aout,adjust_sizes_and_vmas) (abfd, text_size, text_end)
876 bfd_size_type *text_size;
879 struct internal_exec *execp = exec_hdr (abfd);
881 if ((obj_textsec (abfd) == NULL) || (obj_datasec (abfd) == NULL))
883 bfd_set_error (bfd_error_invalid_operation);
886 if (adata(abfd).magic != undecided_magic) return true;
888 obj_textsec(abfd)->_raw_size =
889 align_power(obj_textsec(abfd)->_raw_size,
890 obj_textsec(abfd)->alignment_power);
892 *text_size = obj_textsec (abfd)->_raw_size;
893 /* Rule (heuristic) for when to pad to a new page. Note that there
894 are (at least) two ways demand-paged (ZMAGIC) files have been
895 handled. Most Berkeley-based systems start the text segment at
896 (PAGE_SIZE). However, newer versions of SUNOS start the text
897 segment right after the exec header; the latter is counted in the
898 text segment size, and is paged in by the kernel with the rest of
901 /* This perhaps isn't the right way to do this, but made it simpler for me
902 to understand enough to implement it. Better would probably be to go
903 right from BFD flags to alignment/positioning characteristics. But the
904 old code was sloppy enough about handling the flags, and had enough
905 other magic, that it was a little hard for me to understand. I think
906 I understand it better now, but I haven't time to do the cleanup this
909 if (abfd->flags & D_PAGED)
910 /* Whether or not WP_TEXT is set -- let D_PAGED override. */
911 /* @@ What about QMAGIC? */
912 adata(abfd).magic = z_magic;
913 else if (abfd->flags & WP_TEXT)
914 adata(abfd).magic = n_magic;
916 adata(abfd).magic = o_magic;
918 #ifdef BFD_AOUT_DEBUG /* requires gcc2 */
920 fprintf (stderr, "%s text=<%x,%x,%x> data=<%x,%x,%x> bss=<%x,%x,%x>\n",
922 switch (adata(abfd).magic) {
923 case n_magic: str = "NMAGIC"; break;
924 case o_magic: str = "OMAGIC"; break;
925 case z_magic: str = "ZMAGIC"; break;
930 obj_textsec(abfd)->vma, obj_textsec(abfd)->_raw_size,
931 obj_textsec(abfd)->alignment_power,
932 obj_datasec(abfd)->vma, obj_datasec(abfd)->_raw_size,
933 obj_datasec(abfd)->alignment_power,
934 obj_bsssec(abfd)->vma, obj_bsssec(abfd)->_raw_size,
935 obj_bsssec(abfd)->alignment_power);
939 switch (adata(abfd).magic)
942 adjust_o_magic (abfd, execp);
945 adjust_z_magic (abfd, execp);
948 adjust_n_magic (abfd, execp);
954 #ifdef BFD_AOUT_DEBUG
955 fprintf (stderr, " text=<%x,%x,%x> data=<%x,%x,%x> bss=<%x,%x>\n",
956 obj_textsec(abfd)->vma, obj_textsec(abfd)->_raw_size,
957 obj_textsec(abfd)->filepos,
958 obj_datasec(abfd)->vma, obj_datasec(abfd)->_raw_size,
959 obj_datasec(abfd)->filepos,
960 obj_bsssec(abfd)->vma, obj_bsssec(abfd)->_raw_size);
968 aout_@var{size}_new_section_hook
971 boolean aout_@var{size}_new_section_hook,
976 Called by the BFD in response to a @code{bfd_make_section}
980 NAME(aout,new_section_hook) (abfd, newsect)
984 /* align to double at least */
985 newsect->alignment_power = bfd_get_arch_info(abfd)->section_align_power;
988 if (bfd_get_format (abfd) == bfd_object)
990 if (obj_textsec(abfd) == NULL && !strcmp(newsect->name, ".text")) {
991 obj_textsec(abfd)= newsect;
992 newsect->target_index = N_TEXT;
996 if (obj_datasec(abfd) == NULL && !strcmp(newsect->name, ".data")) {
997 obj_datasec(abfd) = newsect;
998 newsect->target_index = N_DATA;
1002 if (obj_bsssec(abfd) == NULL && !strcmp(newsect->name, ".bss")) {
1003 obj_bsssec(abfd) = newsect;
1004 newsect->target_index = N_BSS;
1010 /* We allow more than three sections internally */
1015 NAME(aout,set_section_contents) (abfd, section, location, offset, count)
1020 bfd_size_type count;
1023 bfd_size_type text_size;
1025 if (abfd->output_has_begun == false)
1027 if (NAME(aout,adjust_sizes_and_vmas) (abfd,
1029 &text_end) == false)
1033 /* regardless, once we know what we're doing, we might as well get going */
1034 if (section != obj_bsssec(abfd))
1036 if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0)
1040 return (bfd_write ((PTR)location, 1, count, abfd) == count) ?
1048 /* Classify stabs symbols */
1050 #define sym_in_text_section(sym) \
1051 (((sym)->type & (N_ABS | N_TEXT | N_DATA | N_BSS))== N_TEXT)
1053 #define sym_in_data_section(sym) \
1054 (((sym)->type & (N_ABS | N_TEXT | N_DATA | N_BSS))== N_DATA)
1056 #define sym_in_bss_section(sym) \
1057 (((sym)->type & (N_ABS | N_TEXT | N_DATA | N_BSS))== N_BSS)
1059 /* Symbol is undefined if type is N_UNDF|N_EXT and if it has
1060 zero in the "value" field. Nonzeroes there are fortrancommon
1062 #define sym_is_undefined(sym) \
1063 ((sym)->type == (N_UNDF | N_EXT) && (sym)->symbol.value == 0)
1065 /* Symbol is a global definition if N_EXT is on and if it has
1066 a nonzero type field. */
1067 #define sym_is_global_defn(sym) \
1068 (((sym)->type & N_EXT) && (sym)->type & N_TYPE)
1070 /* Symbol is debugger info if any bits outside N_TYPE or N_EXT
1072 #define sym_is_debugger_info(sym) \
1073 (((sym)->type & ~(N_EXT | N_TYPE)) || (sym)->type == N_FN)
1075 #define sym_is_fortrancommon(sym) \
1076 (((sym)->type == (N_EXT)) && (sym)->symbol.value != 0)
1078 /* Symbol is absolute if it has N_ABS set */
1079 #define sym_is_absolute(sym) \
1080 (((sym)->type & N_TYPE)== N_ABS)
1083 #define sym_is_indirect(sym) \
1084 (((sym)->type & N_ABS)== N_ABS)
1086 /* Read the external symbols from an a.out file. */
1089 aout_get_external_symbols (abfd)
1092 if (obj_aout_external_syms (abfd) == (struct external_nlist *) NULL)
1094 bfd_size_type count;
1095 struct external_nlist *syms;
1097 count = exec_hdr (abfd)->a_syms / EXTERNAL_NLIST_SIZE;
1099 /* We allocate using malloc to make the values easy to free
1100 later on. If we put them on the obstack it might not be
1101 possible to free them. */
1102 syms = ((struct external_nlist *)
1103 malloc ((size_t) count * EXTERNAL_NLIST_SIZE));
1104 if (syms == (struct external_nlist *) NULL && count != 0)
1106 bfd_set_error (bfd_error_no_memory);
1110 if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0
1111 || (bfd_read (syms, 1, exec_hdr (abfd)->a_syms, abfd)
1112 != exec_hdr (abfd)->a_syms))
1118 obj_aout_external_syms (abfd) = syms;
1119 obj_aout_external_sym_count (abfd) = count;
1122 if (obj_aout_external_strings (abfd) == NULL)
1124 unsigned char string_chars[BYTES_IN_WORD];
1125 bfd_size_type stringsize;
1128 /* Get the size of the strings. */
1129 if (bfd_seek (abfd, obj_str_filepos (abfd), SEEK_SET) != 0
1130 || (bfd_read ((PTR) string_chars, BYTES_IN_WORD, 1, abfd)
1133 stringsize = GET_WORD (abfd, string_chars);
1135 strings = (char *) malloc ((size_t) stringsize + 1);
1136 if (strings == NULL)
1138 bfd_set_error (bfd_error_no_memory);
1142 /* Skip space for the string count in the buffer for convenience
1143 when using indexes. */
1144 if (bfd_read (strings + BYTES_IN_WORD, 1, stringsize - BYTES_IN_WORD,
1146 != stringsize - BYTES_IN_WORD)
1152 /* Sanity preservation. */
1153 strings[stringsize] = '\0';
1155 obj_aout_external_strings (abfd) = strings;
1156 obj_aout_external_string_size (abfd) = stringsize;
1162 /* Only in their own functions for ease of debugging; when sym flags have
1163 stabilised these should be inlined into their (single) caller */
1166 translate_from_native_sym_flags (sym_pointer, cache_ptr, abfd)
1167 struct external_nlist *sym_pointer;
1168 aout_symbol_type * cache_ptr;
1171 cache_ptr->symbol.section = 0;
1172 switch (cache_ptr->type & N_TYPE)
1174 case N_SETA: case N_SETA | N_EXT:
1175 case N_SETT: case N_SETT | N_EXT:
1176 case N_SETD: case N_SETD | N_EXT:
1177 case N_SETB: case N_SETB | N_EXT:
1179 char *copy = bfd_alloc (abfd, strlen (cache_ptr->symbol.name) + 1);
1181 asection *into_section;
1182 arelent_chain *reloc = (arelent_chain *) bfd_alloc (abfd, sizeof (arelent_chain));
1184 if (!copy || !reloc)
1186 bfd_set_error (bfd_error_no_memory);
1190 strcpy (copy, cache_ptr->symbol.name);
1192 /* Make sure that this bfd has a section with the right contructor
1194 section = bfd_get_section_by_name (abfd, copy);
1196 section = bfd_make_section (abfd, copy);
1198 /* Build a relocation entry for the constructor */
1199 switch ((cache_ptr->type & N_TYPE))
1201 case N_SETA: case N_SETA | N_EXT:
1202 into_section = &bfd_abs_section;
1203 cache_ptr->type = N_ABS;
1205 case N_SETT: case N_SETT | N_EXT:
1206 into_section = (asection *) obj_textsec (abfd);
1207 cache_ptr->type = N_TEXT;
1209 case N_SETD: case N_SETD | N_EXT:
1210 into_section = (asection *) obj_datasec (abfd);
1211 cache_ptr->type = N_DATA;
1213 case N_SETB: case N_SETB | N_EXT:
1214 into_section = (asection *) obj_bsssec (abfd);
1215 cache_ptr->type = N_BSS;
1218 bfd_set_error (bfd_error_bad_value);
1222 /* Build a relocation pointing into the constuctor section
1223 pointing at the symbol in the set vector specified */
1225 reloc->relent.addend = cache_ptr->symbol.value;
1226 cache_ptr->symbol.section = into_section->symbol->section;
1227 reloc->relent.sym_ptr_ptr = into_section->symbol_ptr_ptr;
1230 /* We modify the symbol to belong to a section depending upon the
1231 name of the symbol - probably __CTOR__ or __DTOR__ but we don't
1232 really care, and add to the size of the section to contain a
1233 pointer to the symbol. Build a reloc entry to relocate to this
1234 symbol attached to this section. */
1236 section->flags = SEC_CONSTRUCTOR | SEC_RELOC;
1239 section->reloc_count++;
1240 section->alignment_power = 2;
1242 reloc->next = section->constructor_chain;
1243 section->constructor_chain = reloc;
1244 reloc->relent.address = section->_raw_size;
1245 section->_raw_size += sizeof (int *);
1248 = (obj_reloc_entry_size(abfd) == RELOC_EXT_SIZE
1249 ? howto_table_ext : howto_table_std)
1250 + CTOR_TABLE_RELOC_IDX;
1251 cache_ptr->symbol.flags |= BSF_CONSTRUCTOR;
1255 if (cache_ptr->type == N_WARNING)
1257 /* This symbol is the text of a warning message, the next symbol
1258 is the symbol to associate the warning with */
1259 cache_ptr->symbol.flags = BSF_DEBUGGING | BSF_WARNING;
1261 /* @@ Stuffing pointers into integers is a no-no.
1262 We can usually get away with it if the integer is
1263 large enough though. */
1264 if (sizeof (cache_ptr + 1) > sizeof (bfd_vma))
1266 cache_ptr->symbol.value = (bfd_vma) ((cache_ptr + 1));
1268 /* We don't use a warning symbol's section, but we need
1269 it to be nonzero for the sanity check below, so
1270 pick one arbitrarily. */
1271 cache_ptr->symbol.section = &bfd_abs_section;
1273 /* We furgle with the next symbol in place.
1274 We don't want it to be undefined, we'll trample the type */
1275 (sym_pointer + 1)->e_type[0] = 0xff;
1278 if ((cache_ptr->type | N_EXT) == (N_INDR | N_EXT))
1280 /* Two symbols in a row for an INDR message. The first symbol
1281 contains the name we will match, the second symbol contains
1282 the name the first name is translated into. It is supplied to
1283 us undefined. This is good, since we want to pull in any files
1285 cache_ptr->symbol.flags = BSF_DEBUGGING | BSF_INDIRECT;
1287 /* @@ Stuffing pointers into integers is a no-no.
1288 We can usually get away with it if the integer is
1289 large enough though. */
1290 if (sizeof (cache_ptr + 1) > sizeof (bfd_vma))
1293 cache_ptr->symbol.value = (bfd_vma) ((cache_ptr + 1));
1294 cache_ptr->symbol.section = &bfd_ind_section;
1297 else if (sym_is_debugger_info (cache_ptr))
1299 cache_ptr->symbol.flags = BSF_DEBUGGING;
1300 /* Work out the section correct for this symbol */
1301 switch (cache_ptr->type & N_TYPE)
1305 cache_ptr->symbol.section = obj_textsec (abfd);
1306 cache_ptr->symbol.value -= obj_textsec (abfd)->vma;
1309 cache_ptr->symbol.value -= obj_datasec (abfd)->vma;
1310 cache_ptr->symbol.section = obj_datasec (abfd);
1313 cache_ptr->symbol.section = obj_bsssec (abfd);
1314 cache_ptr->symbol.value -= obj_bsssec (abfd)->vma;
1318 cache_ptr->symbol.section = &bfd_abs_section;
1325 if (sym_is_fortrancommon (cache_ptr))
1327 cache_ptr->symbol.flags = 0;
1328 cache_ptr->symbol.section = &bfd_com_section;
1336 /* In a.out, the value of a symbol is always relative to the
1337 * start of the file, if this is a data symbol we'll subtract
1338 * the size of the text section to get the section relative
1339 * value. If this is a bss symbol (which would be strange)
1340 * we'll subtract the size of the previous two sections
1341 * to find the section relative address.
1344 if (sym_in_text_section (cache_ptr))
1346 cache_ptr->symbol.value -= obj_textsec (abfd)->vma;
1347 cache_ptr->symbol.section = obj_textsec (abfd);
1349 else if (sym_in_data_section (cache_ptr))
1351 cache_ptr->symbol.value -= obj_datasec (abfd)->vma;
1352 cache_ptr->symbol.section = obj_datasec (abfd);
1354 else if (sym_in_bss_section (cache_ptr))
1356 cache_ptr->symbol.section = obj_bsssec (abfd);
1357 cache_ptr->symbol.value -= obj_bsssec (abfd)->vma;
1359 else if (sym_is_undefined (cache_ptr))
1361 cache_ptr->symbol.flags = 0;
1362 cache_ptr->symbol.section = &bfd_und_section;
1364 else if (sym_is_absolute (cache_ptr))
1366 cache_ptr->symbol.section = &bfd_abs_section;
1369 if (sym_is_global_defn (cache_ptr))
1371 cache_ptr->symbol.flags = BSF_GLOBAL | BSF_EXPORT;
1373 else if (! sym_is_undefined (cache_ptr))
1375 cache_ptr->symbol.flags = BSF_LOCAL;
1379 if (cache_ptr->symbol.section == 0)
1386 translate_to_native_sym_flags (sym_pointer, cache_ptr, abfd)
1387 struct external_nlist *sym_pointer;
1391 bfd_vma value = cache_ptr->value;
1393 /* mask out any existing type bits in case copying from one section
1395 sym_pointer->e_type[0] &= ~N_TYPE;
1397 /* We attempt to order these tests by decreasing frequency of success,
1398 according to tcov when linking the linker. */
1399 if (bfd_get_output_section(cache_ptr) == &bfd_abs_section) {
1400 sym_pointer->e_type[0] |= N_ABS;
1402 else if (bfd_get_output_section(cache_ptr) == obj_textsec (abfd)) {
1403 sym_pointer->e_type[0] |= N_TEXT;
1405 else if (bfd_get_output_section(cache_ptr) == obj_datasec (abfd)) {
1406 sym_pointer->e_type[0] |= N_DATA;
1408 else if (bfd_get_output_section(cache_ptr) == obj_bsssec (abfd)) {
1409 sym_pointer->e_type[0] |= N_BSS;
1411 else if (bfd_get_output_section(cache_ptr) == &bfd_und_section) {
1412 sym_pointer->e_type[0] = (N_UNDF | N_EXT);
1414 else if (bfd_get_output_section(cache_ptr) == &bfd_ind_section) {
1415 sym_pointer->e_type[0] = N_INDR;
1417 else if (bfd_get_output_section(cache_ptr) == NULL) {
1418 /* Protect the bfd_is_com_section call.
1419 This case occurs, e.g., for the *DEBUG* section of a COFF file. */
1420 bfd_set_error (bfd_error_nonrepresentable_section);
1423 else if (bfd_is_com_section (bfd_get_output_section (cache_ptr))) {
1424 sym_pointer->e_type[0] = (N_UNDF | N_EXT);
1427 bfd_set_error (bfd_error_nonrepresentable_section);
1431 /* Turn the symbol from section relative to absolute again */
1433 value += cache_ptr->section->output_section->vma + cache_ptr->section->output_offset ;
1436 if (cache_ptr->flags & (BSF_WARNING)) {
1437 sym_pointer->e_type[0] = N_WARNING;
1438 (sym_pointer+1)->e_type[0] = 1;
1441 if (cache_ptr->flags & BSF_DEBUGGING) {
1442 sym_pointer->e_type[0] = ((aout_symbol_type *)cache_ptr)->type;
1444 else if (cache_ptr->flags & (BSF_GLOBAL | BSF_EXPORT)) {
1445 sym_pointer->e_type[0] |= N_EXT;
1447 if (cache_ptr->flags & BSF_CONSTRUCTOR) {
1448 int type = ((aout_symbol_type *)cache_ptr)->type;
1451 case N_ABS: type = N_SETA; break;
1452 case N_TEXT: type = N_SETT; break;
1453 case N_DATA: type = N_SETD; break;
1454 case N_BSS: type = N_SETB; break;
1456 sym_pointer->e_type[0] = type;
1459 PUT_WORD(abfd, value, sym_pointer->e_value);
1464 /* Native-level interface to symbols. */
1468 NAME(aout,make_empty_symbol) (abfd)
1471 aout_symbol_type *new =
1472 (aout_symbol_type *)bfd_zalloc (abfd, sizeof (aout_symbol_type));
1475 bfd_set_error (bfd_error_no_memory);
1478 new->symbol.the_bfd = abfd;
1480 return &new->symbol;
1483 /* Translate a set of internal symbols into external symbols. */
1486 NAME(aout,translate_symbol_table) (abfd, in, ext, count, str, strsize, dynamic)
1488 aout_symbol_type *in;
1489 struct external_nlist *ext;
1490 bfd_size_type count;
1492 bfd_size_type strsize;
1495 struct external_nlist *ext_end;
1497 ext_end = ext + count;
1498 for (; ext < ext_end; ext++, in++)
1502 x = GET_WORD (abfd, ext->e_strx);
1503 in->symbol.the_bfd = abfd;
1505 /* For the normal symbols, the zero index points at the number
1506 of bytes in the string table but is to be interpreted as the
1507 null string. For the dynamic symbols, the number of bytes in
1508 the string table is stored in the __DYNAMIC structure and the
1509 zero index points at an actual string. */
1510 if (x == 0 && ! dynamic)
1511 in->symbol.name = "";
1512 else if (x < strsize)
1513 in->symbol.name = str + x;
1517 in->symbol.value = GET_SWORD (abfd, ext->e_value);
1518 in->desc = bfd_h_get_16 (abfd, ext->e_desc);
1519 in->other = bfd_h_get_8 (abfd, ext->e_other);
1520 in->type = bfd_h_get_8 (abfd, ext->e_type);
1521 in->symbol.udata = 0;
1523 if (!translate_from_native_sym_flags (ext, in, abfd))
1527 in->symbol.flags |= BSF_DYNAMIC;
1533 /* We read the symbols into a buffer, which is discarded when this
1534 function exits. We read the strings into a buffer large enough to
1535 hold them all plus all the cached symbol entries. */
1538 NAME(aout,slurp_symbol_table) (abfd)
1541 struct external_nlist *old_external_syms;
1542 aout_symbol_type *cached;
1545 /* If there's no work to be done, don't do any */
1546 if (obj_aout_symbols (abfd) != (aout_symbol_type *) NULL)
1549 old_external_syms = obj_aout_external_syms (abfd);
1551 if (! aout_get_external_symbols (abfd))
1554 if (obj_aout_external_sym_count (abfd) == 0)
1556 bfd_set_error (bfd_error_no_symbols);
1560 cached_size = (obj_aout_external_sym_count (abfd)
1561 * sizeof (aout_symbol_type));
1562 cached = (aout_symbol_type *) malloc (cached_size);
1563 memset (cached, 0, cached_size);
1567 bfd_set_error (bfd_error_no_memory);
1571 /* Convert from external symbol information to internal. */
1572 if (! (NAME(aout,translate_symbol_table)
1574 obj_aout_external_syms (abfd),
1575 obj_aout_external_sym_count (abfd),
1576 obj_aout_external_strings (abfd),
1577 obj_aout_external_string_size (abfd),
1584 bfd_get_symcount (abfd) = obj_aout_external_sym_count (abfd);
1586 obj_aout_symbols (abfd) = cached;
1588 /* It is very likely that anybody who calls this function will not
1589 want the external symbol information, so if it was allocated
1590 because of our call to aout_get_external_symbols, we free it up
1591 right away to save space. */
1592 if (old_external_syms == (struct external_nlist *) NULL
1593 && obj_aout_external_syms (abfd) != (struct external_nlist *) NULL)
1595 free (obj_aout_external_syms (abfd));
1596 obj_aout_external_syms (abfd) = NULL;
1602 /* Possible improvements:
1603 + look for strings matching trailing substrings of other strings
1604 + better data structures? balanced trees?
1605 + smaller per-string or per-symbol data? re-use some of the symbol's
1607 + also look at reducing memory use elsewhere -- maybe if we didn't have to
1608 construct the entire symbol table at once, we could get by with smaller
1609 amounts of VM? (What effect does that have on the string table
1611 + rip this out of here, put it into its own file in bfd or libiberty, so
1612 coff and elf can use it too. I'll work on this soon, but have more
1613 pressing tasks right now.
1615 A hash table might(?) be more efficient for handling exactly the cases that
1616 are handled now, but for trailing substring matches, I think we want to
1617 examine the `nearest' values (reverse-)lexically, not merely impose a strict
1618 order, nor look only for exact-match or not-match. I don't think a hash
1619 table would be very useful for that, and I don't feel like fleshing out two
1620 completely different implementations. [raeburn:930419.0331EDT] */
1622 struct stringtab_entry {
1623 /* Hash value for this string. Only useful so long as we aren't doing
1624 substring matches. */
1627 /* Next node to look at, depending on whether the hash value of the string
1628 being searched for is less than or greater than the hash value of the
1629 current node. For now, `equal to' is lumped in with `greater than', for
1630 space efficiency. It's not a common enough case to warrant another field
1631 to be used for all nodes. */
1632 struct stringtab_entry *less;
1633 struct stringtab_entry *greater;
1635 /* The string itself. */
1638 /* The index allocated for this string. */
1639 bfd_size_type index;
1641 #ifdef GATHER_STATISTICS
1642 /* How many references have there been to this string? (Not currently used;
1643 could be dumped out for anaylsis, if anyone's interested.) */
1644 unsigned long count;
1647 /* Next node in linked list, in suggested output order. */
1648 struct stringtab_entry *next_to_output;
1651 struct stringtab_data {
1652 /* Tree of string table entries. */
1653 struct stringtab_entry *strings;
1655 /* Fudge factor used to center top node of tree. */
1658 /* Next index value to issue. */
1659 bfd_size_type index;
1661 /* Index used for empty strings. Cached here because checking for them
1662 is really easy, and we can avoid searching the tree. */
1663 bfd_size_type empty_string_index;
1665 /* These fields indicate the two ends of a singly-linked list that indicates
1666 the order strings should be written out in. Use this order, and no
1667 seeking will need to be done, so output efficiency should be maximized. */
1668 struct stringtab_entry **end;
1669 struct stringtab_entry *output_order;
1671 #ifdef GATHER_STATISTICS
1672 /* Number of strings which duplicate strings already in the table. */
1673 unsigned long duplicates;
1675 /* Number of bytes saved by not having to write all the duplicate strings. */
1676 unsigned long bytes_saved;
1678 /* Number of zero-length strings. Currently, these all turn into
1679 references to the null byte at the end of the first string. In some
1680 cases (possibly not all? explore this...), it should be possible to
1681 simply write out a zero index value. */
1682 unsigned long empty_strings;
1684 /* Number of times the hash values matched but the strings were different.
1685 Note that this includes the number of times the other string(s) occurs, so
1686 there may only be two strings hashing to the same value, even if this
1687 number is very large. */
1688 unsigned long bad_hash_matches;
1690 /* Null strings aren't counted in this one.
1691 This will probably only be nonzero if we've got an input file
1692 which was produced by `ld -r' (i.e., it's already been processed
1693 through this code). Under some operating systems, native tools
1694 may make all empty strings have the same index; but the pointer
1695 check won't catch those, because to get to that stage we'd already
1696 have to compute the checksum, which requires reading the string,
1697 so we short-circuit that case with empty_string_index above. */
1698 unsigned long pointer_matches;
1700 /* Number of comparisons done. I figure with the algorithms in use below,
1701 the average number of comparisons done (per symbol) should be roughly
1702 log-base-2 of the number of unique strings. */
1703 unsigned long n_compares;
1707 /* Some utility functions for the string table code. */
1709 /* For speed, only hash on the first this many bytes of strings.
1710 This number was chosen by profiling ld linking itself, with -g. */
1711 #define HASHMAXLEN 25
1713 #define HASH_CHAR(c) (sum ^= sum >> 20, sum ^= sum << 7, sum += (c))
1715 static INLINE unsigned int
1717 unsigned char *string;
1718 register unsigned int len;
1720 register unsigned int sum = 0;
1722 if (len > HASHMAXLEN)
1730 HASH_CHAR (*string++);
1736 stringtab_init (tab)
1737 struct stringtab_data *tab;
1740 tab->output_order = 0;
1742 tab->end = &tab->output_order;
1744 /* Initial string table length includes size of length field. */
1745 tab->index = BYTES_IN_WORD;
1746 tab->empty_string_index = -1;
1747 #ifdef GATHER_STATISTICS
1748 tab->duplicates = 0;
1749 tab->empty_strings = 0;
1750 tab->bad_hash_matches = 0;
1751 tab->pointer_matches = 0;
1752 tab->bytes_saved = 0;
1753 tab->n_compares = 0;
1758 compare (entry, str, hash)
1759 struct stringtab_entry *entry;
1763 return hash - entry->hash;
1766 #ifdef GATHER_STATISTICS
1767 /* Don't want to have to link in math library with all bfd applications... */
1768 static INLINE double
1776 return ((d > 1.41) ? 0.5 : 0) + n;
1780 /* Main string table routines. */
1781 /* Returns index in string table. Whether or not this actually adds an
1782 entry into the string table should be irrelevant -- it just has to
1783 return a valid index. */
1784 static bfd_size_type
1785 add_to_stringtab (abfd, str, tab)
1788 struct stringtab_data *tab;
1790 struct stringtab_entry **ep;
1791 register struct stringtab_entry *entry;
1792 unsigned int hashval, len;
1796 bfd_size_type index;
1797 CONST bfd_size_type minus_one = -1;
1799 #ifdef GATHER_STATISTICS
1800 tab->empty_strings++;
1802 index = tab->empty_string_index;
1803 if (index != minus_one)
1806 #ifdef GATHER_STATISTICS
1813 /* Need to find it. */
1814 entry = tab->strings;
1817 index = entry->index + strlen (entry->string);
1818 tab->empty_string_index = index;
1826 /* The hash_zero value is chosen such that the first symbol gets a value of
1827 zero. With a balanced tree, this wouldn't be very useful, but without it,
1828 we might get a more even split at the top level, instead of skewing it
1829 badly should hash("/usr/lib/crt0.o") (or whatever) be far from zero. */
1830 hashval = hash (str, len) ^ tab->hash_zero;
1834 tab->hash_zero = hashval;
1844 #ifdef GATHER_STATISTICS
1847 cmp = compare (entry, str, hashval);
1848 /* The not-equal cases are more frequent, so check them first. */
1850 ep = &entry->greater;
1855 if (entry->string == str)
1857 #ifdef GATHER_STATISTICS
1858 tab->pointer_matches++;
1862 /* Compare the first bytes to save a function call if they
1864 if (entry->string[0] == str[0] && !strcmp (entry->string, str))
1867 #ifdef GATHER_STATISTICS
1869 tab->bytes_saved += len + 1;
1872 /* If we're in the linker, and the new string is from a new
1873 input file which might have already had these reductions
1874 run over it, we want to keep the new string pointer. I
1875 don't think we're likely to see any (or nearly as many,
1876 at least) cases where a later string is in the same location
1877 as an earlier one rather than this one. */
1878 entry->string = str;
1879 return entry->index;
1881 #ifdef GATHER_STATISTICS
1882 tab->bad_hash_matches++;
1884 ep = &entry->greater;
1888 /* If we get here, nothing that's in the table already matched.
1889 EP points to the `next' field at the end of the chain; stick a
1890 new entry on here. */
1892 entry = (struct stringtab_entry *)
1893 bfd_alloc_by_size_t (abfd, sizeof (struct stringtab_entry));
1896 bfd_set_error (bfd_error_no_memory);
1897 abort(); /* FIXME */
1900 entry->less = entry->greater = 0;
1901 entry->hash = hashval;
1902 entry->index = tab->index;
1903 entry->string = str;
1904 entry->next_to_output = 0;
1905 #ifdef GATHER_STATISTICS
1909 assert (*tab->end == 0);
1910 *(tab->end) = entry;
1911 tab->end = &entry->next_to_output;
1912 assert (*tab->end == 0);
1915 tab->index += len + 1;
1917 tab->empty_string_index = entry->index;
1921 return entry->index;
1925 emit_strtab (abfd, tab)
1927 struct stringtab_data *tab;
1929 struct stringtab_entry *entry;
1930 #ifdef GATHER_STATISTICS
1934 /* Be sure to put string length into correct byte ordering before writing
1936 char buffer[BYTES_IN_WORD];
1938 PUT_WORD (abfd, tab->index, (unsigned char *) buffer);
1939 if (bfd_write ((PTR) buffer, 1, BYTES_IN_WORD, abfd) != BYTES_IN_WORD)
1942 for (entry = tab->output_order; entry; entry = entry->next_to_output)
1944 size_t len = strlen (entry->string) + 1;
1946 if (bfd_write ((PTR) entry->string, 1, len, abfd) != len)
1949 #ifdef GATHER_STATISTICS
1954 #ifdef GATHER_STATISTICS
1955 /* Short form only, for now.
1956 To do: Specify output file. Conditionalize on environment? Detailed
1957 analysis if desired. */
1959 int n_syms = bfd_get_symcount (abfd);
1961 fprintf (stderr, "String table data for output file:\n");
1962 fprintf (stderr, " %8d symbols output\n", n_syms);
1963 fprintf (stderr, " %8d duplicate strings\n", tab->duplicates);
1964 fprintf (stderr, " %8d empty strings\n", tab->empty_strings);
1965 fprintf (stderr, " %8d unique strings output\n", count);
1966 fprintf (stderr, " %8d pointer matches\n", tab->pointer_matches);
1967 fprintf (stderr, " %8d bytes saved\n", tab->bytes_saved);
1968 fprintf (stderr, " %8d bad hash matches\n", tab->bad_hash_matches);
1969 fprintf (stderr, " %8d hash-val comparisons\n", tab->n_compares);
1972 double n_compares = tab->n_compares;
1973 double avg_compares = n_compares / n_syms;
1974 /* The second value here should usually be near one. */
1976 "\t average %f comparisons per symbol (%f * log2 nstrings)\n",
1977 avg_compares, avg_compares / log2 (count));
1984 generic = bfd_get_outsymbols(abfd);
1985 for (count = 0; count < bfd_get_symcount(abfd); count++)
1987 asymbol *g = *(generic++);
1991 size_t length = strlen(g->name)+1;
1992 bfd_write((PTR)g->name, 1, length, abfd);
1994 g->KEEPIT = (KEEPITTYPE) count;
2001 NAME(aout,write_syms) (abfd)
2004 unsigned int count ;
2005 asymbol **generic = bfd_get_outsymbols (abfd);
2006 struct stringtab_data strtab;
2008 stringtab_init (&strtab);
2010 for (count = 0; count < bfd_get_symcount (abfd); count++)
2012 asymbol *g = generic[count];
2013 struct external_nlist nsp;
2016 PUT_WORD (abfd, add_to_stringtab (abfd, g->name, &strtab),
2017 (unsigned char *) nsp.e_strx);
2019 PUT_WORD (abfd, 0, (unsigned char *)nsp.e_strx);
2021 if (bfd_asymbol_flavour(g) == abfd->xvec->flavour)
2023 bfd_h_put_16(abfd, aout_symbol(g)->desc, nsp.e_desc);
2024 bfd_h_put_8(abfd, aout_symbol(g)->other, nsp.e_other);
2025 bfd_h_put_8(abfd, aout_symbol(g)->type, nsp.e_type);
2029 bfd_h_put_16(abfd,0, nsp.e_desc);
2030 bfd_h_put_8(abfd, 0, nsp.e_other);
2031 bfd_h_put_8(abfd, 0, nsp.e_type);
2034 if (! translate_to_native_sym_flags (&nsp, g, abfd))
2037 if (bfd_write((PTR)&nsp,1,EXTERNAL_NLIST_SIZE, abfd)
2038 != EXTERNAL_NLIST_SIZE)
2041 /* NB: `KEEPIT' currently overlays `flags', so set this only
2042 here, at the end. */
2046 return emit_strtab (abfd, &strtab);
2051 NAME(aout,get_symtab) (abfd, location)
2055 unsigned int counter = 0;
2056 aout_symbol_type *symbase;
2058 if (!NAME(aout,slurp_symbol_table)(abfd))
2061 for (symbase = obj_aout_symbols(abfd); counter++ < bfd_get_symcount (abfd);)
2062 *(location++) = (asymbol *)( symbase++);
2064 return bfd_get_symcount (abfd);
2068 /* Standard reloc stuff */
2069 /* Output standard relocation information to a file in target byte order. */
2072 NAME(aout,swap_std_reloc_out) (abfd, g, natptr)
2075 struct reloc_std_external *natptr;
2078 asymbol *sym = *(g->sym_ptr_ptr);
2080 unsigned int r_length;
2082 int r_baserel, r_jmptable, r_relative;
2083 asection *output_section = sym->section->output_section;
2085 PUT_WORD(abfd, g->address, natptr->r_address);
2087 r_length = g->howto->size ; /* Size as a power of two */
2088 r_pcrel = (int) g->howto->pc_relative; /* Relative to PC? */
2089 /* XXX This relies on relocs coming from a.out files. */
2090 r_baserel = (g->howto->type & 8) != 0;
2091 /* r_jmptable, r_relative??? FIXME-soon */
2096 /* For a standard reloc, the addend is in the object file. */
2097 r_addend = g->addend + (*(g->sym_ptr_ptr))->section->output_section->vma;
2100 /* name was clobbered by aout_write_syms to be symbol index */
2102 /* If this relocation is relative to a symbol then set the
2103 r_index to the symbols index, and the r_extern bit.
2105 Absolute symbols can come in in two ways, either as an offset
2106 from the abs section, or as a symbol which has an abs value.
2111 if (bfd_is_com_section (output_section)
2112 || output_section == &bfd_abs_section
2113 || output_section == &bfd_und_section)
2115 if (bfd_abs_section.symbol == sym)
2117 /* Whoops, looked like an abs symbol, but is really an offset
2118 from the abs section */
2124 /* Fill in symbol */
2126 r_index = stoi((*(g->sym_ptr_ptr))->KEEPIT);
2132 /* Just an ordinary section */
2134 r_index = output_section->target_index;
2137 /* now the fun stuff */
2138 if (abfd->xvec->header_byteorder_big_p != false) {
2139 natptr->r_index[0] = r_index >> 16;
2140 natptr->r_index[1] = r_index >> 8;
2141 natptr->r_index[2] = r_index;
2143 (r_extern? RELOC_STD_BITS_EXTERN_BIG: 0)
2144 | (r_pcrel? RELOC_STD_BITS_PCREL_BIG: 0)
2145 | (r_baserel? RELOC_STD_BITS_BASEREL_BIG: 0)
2146 | (r_jmptable? RELOC_STD_BITS_JMPTABLE_BIG: 0)
2147 | (r_relative? RELOC_STD_BITS_RELATIVE_BIG: 0)
2148 | (r_length << RELOC_STD_BITS_LENGTH_SH_BIG);
2150 natptr->r_index[2] = r_index >> 16;
2151 natptr->r_index[1] = r_index >> 8;
2152 natptr->r_index[0] = r_index;
2154 (r_extern? RELOC_STD_BITS_EXTERN_LITTLE: 0)
2155 | (r_pcrel? RELOC_STD_BITS_PCREL_LITTLE: 0)
2156 | (r_baserel? RELOC_STD_BITS_BASEREL_LITTLE: 0)
2157 | (r_jmptable? RELOC_STD_BITS_JMPTABLE_LITTLE: 0)
2158 | (r_relative? RELOC_STD_BITS_RELATIVE_LITTLE: 0)
2159 | (r_length << RELOC_STD_BITS_LENGTH_SH_LITTLE);
2164 /* Extended stuff */
2165 /* Output extended relocation information to a file in target byte order. */
2168 NAME(aout,swap_ext_reloc_out) (abfd, g, natptr)
2171 register struct reloc_ext_external *natptr;
2175 unsigned int r_type;
2176 unsigned int r_addend;
2177 asymbol *sym = *(g->sym_ptr_ptr);
2178 asection *output_section = sym->section->output_section;
2180 PUT_WORD (abfd, g->address, natptr->r_address);
2182 r_type = (unsigned int) g->howto->type;
2184 r_addend = g->addend + (*(g->sym_ptr_ptr))->section->output_section->vma;
2186 /* If this relocation is relative to a symbol then set the
2187 r_index to the symbols index, and the r_extern bit.
2189 Absolute symbols can come in in two ways, either as an offset
2190 from the abs section, or as a symbol which has an abs value.
2191 check for that here. */
2193 if (bfd_is_com_section (output_section)
2194 || output_section == &bfd_abs_section
2195 || output_section == &bfd_und_section)
2197 if (bfd_abs_section.symbol == sym)
2199 /* Whoops, looked like an abs symbol, but is really an offset
2200 from the abs section */
2207 r_index = stoi((*(g->sym_ptr_ptr))->KEEPIT);
2212 /* Just an ordinary section */
2214 r_index = output_section->target_index;
2217 /* now the fun stuff */
2218 if (abfd->xvec->header_byteorder_big_p != false) {
2219 natptr->r_index[0] = r_index >> 16;
2220 natptr->r_index[1] = r_index >> 8;
2221 natptr->r_index[2] = r_index;
2223 ((r_extern? RELOC_EXT_BITS_EXTERN_BIG: 0)
2224 | (r_type << RELOC_EXT_BITS_TYPE_SH_BIG));
2226 natptr->r_index[2] = r_index >> 16;
2227 natptr->r_index[1] = r_index >> 8;
2228 natptr->r_index[0] = r_index;
2230 (r_extern? RELOC_EXT_BITS_EXTERN_LITTLE: 0)
2231 | (r_type << RELOC_EXT_BITS_TYPE_SH_LITTLE);
2234 PUT_WORD (abfd, r_addend, natptr->r_addend);
2237 /* BFD deals internally with all things based from the section they're
2238 in. so, something in 10 bytes into a text section with a base of
2239 50 would have a symbol (.text+10) and know .text vma was 50.
2241 Aout keeps all it's symbols based from zero, so the symbol would
2242 contain 60. This macro subs the base of each section from the value
2243 to give the true offset from the section */
2246 #define MOVE_ADDRESS(ad) \
2248 /* undefined symbol */ \
2249 cache_ptr->sym_ptr_ptr = symbols + r_index; \
2250 cache_ptr->addend = ad; \
2252 /* defined, section relative. replace symbol with pointer to \
2253 symbol which points to section */ \
2254 switch (r_index) { \
2256 case N_TEXT | N_EXT: \
2257 cache_ptr->sym_ptr_ptr = obj_textsec(abfd)->symbol_ptr_ptr; \
2258 cache_ptr->addend = ad - su->textsec->vma; \
2261 case N_DATA | N_EXT: \
2262 cache_ptr->sym_ptr_ptr = obj_datasec(abfd)->symbol_ptr_ptr; \
2263 cache_ptr->addend = ad - su->datasec->vma; \
2266 case N_BSS | N_EXT: \
2267 cache_ptr->sym_ptr_ptr = obj_bsssec(abfd)->symbol_ptr_ptr; \
2268 cache_ptr->addend = ad - su->bsssec->vma; \
2272 case N_ABS | N_EXT: \
2273 cache_ptr->sym_ptr_ptr = bfd_abs_section.symbol_ptr_ptr; \
2274 cache_ptr->addend = ad; \
2280 NAME(aout,swap_ext_reloc_in) (abfd, bytes, cache_ptr, symbols)
2282 struct reloc_ext_external *bytes;
2288 unsigned int r_type;
2289 struct aoutdata *su = &(abfd->tdata.aout_data->a);
2291 cache_ptr->address = (GET_SWORD (abfd, bytes->r_address));
2293 /* now the fun stuff */
2294 if (abfd->xvec->header_byteorder_big_p != false) {
2295 r_index = (bytes->r_index[0] << 16)
2296 | (bytes->r_index[1] << 8)
2297 | bytes->r_index[2];
2298 r_extern = (0 != (bytes->r_type[0] & RELOC_EXT_BITS_EXTERN_BIG));
2299 r_type = (bytes->r_type[0] & RELOC_EXT_BITS_TYPE_BIG)
2300 >> RELOC_EXT_BITS_TYPE_SH_BIG;
2302 r_index = (bytes->r_index[2] << 16)
2303 | (bytes->r_index[1] << 8)
2304 | bytes->r_index[0];
2305 r_extern = (0 != (bytes->r_type[0] & RELOC_EXT_BITS_EXTERN_LITTLE));
2306 r_type = (bytes->r_type[0] & RELOC_EXT_BITS_TYPE_LITTLE)
2307 >> RELOC_EXT_BITS_TYPE_SH_LITTLE;
2310 cache_ptr->howto = howto_table_ext + r_type;
2311 MOVE_ADDRESS(GET_SWORD(abfd, bytes->r_addend));
2315 NAME(aout,swap_std_reloc_in) (abfd, bytes, cache_ptr, symbols)
2317 struct reloc_std_external *bytes;
2323 unsigned int r_length;
2325 int r_baserel, r_jmptable, r_relative;
2326 struct aoutdata *su = &(abfd->tdata.aout_data->a);
2329 cache_ptr->address = bfd_h_get_32 (abfd, bytes->r_address);
2331 /* now the fun stuff */
2332 if (abfd->xvec->header_byteorder_big_p != false) {
2333 r_index = (bytes->r_index[0] << 16)
2334 | (bytes->r_index[1] << 8)
2335 | bytes->r_index[2];
2336 r_extern = (0 != (bytes->r_type[0] & RELOC_STD_BITS_EXTERN_BIG));
2337 r_pcrel = (0 != (bytes->r_type[0] & RELOC_STD_BITS_PCREL_BIG));
2338 r_baserel = (0 != (bytes->r_type[0] & RELOC_STD_BITS_BASEREL_BIG));
2339 r_jmptable= (0 != (bytes->r_type[0] & RELOC_STD_BITS_JMPTABLE_BIG));
2340 r_relative= (0 != (bytes->r_type[0] & RELOC_STD_BITS_RELATIVE_BIG));
2341 r_length = (bytes->r_type[0] & RELOC_STD_BITS_LENGTH_BIG)
2342 >> RELOC_STD_BITS_LENGTH_SH_BIG;
2344 r_index = (bytes->r_index[2] << 16)
2345 | (bytes->r_index[1] << 8)
2346 | bytes->r_index[0];
2347 r_extern = (0 != (bytes->r_type[0] & RELOC_STD_BITS_EXTERN_LITTLE));
2348 r_pcrel = (0 != (bytes->r_type[0] & RELOC_STD_BITS_PCREL_LITTLE));
2349 r_baserel = (0 != (bytes->r_type[0] & RELOC_STD_BITS_BASEREL_LITTLE));
2350 r_jmptable= (0 != (bytes->r_type[0] & RELOC_STD_BITS_JMPTABLE_LITTLE));
2351 r_relative= (0 != (bytes->r_type[0] & RELOC_STD_BITS_RELATIVE_LITTLE));
2352 r_length = (bytes->r_type[0] & RELOC_STD_BITS_LENGTH_LITTLE)
2353 >> RELOC_STD_BITS_LENGTH_SH_LITTLE;
2356 howto_idx = r_length + 4 * r_pcrel + 8 * r_baserel;
2357 BFD_ASSERT (howto_idx < TABLE_SIZE (howto_table_std));
2358 cache_ptr->howto = howto_table_std + howto_idx;
2359 BFD_ASSERT (cache_ptr->howto->type != -1);
2360 BFD_ASSERT (r_jmptable == 0);
2361 BFD_ASSERT (r_relative == 0);
2362 /* FIXME-soon: Roll jmptable, relative bits into howto setting */
2367 /* Read and swap the relocs for a section. */
2370 NAME(aout,slurp_reloc_table) (abfd, asect, symbols)
2376 bfd_size_type reloc_size;
2378 arelent *reloc_cache;
2380 unsigned int counter = 0;
2383 if (asect->relocation)
2386 if (asect->flags & SEC_CONSTRUCTOR)
2389 if (asect == obj_datasec (abfd))
2390 reloc_size = exec_hdr(abfd)->a_drsize;
2391 else if (asect == obj_textsec (abfd))
2392 reloc_size = exec_hdr(abfd)->a_trsize;
2395 bfd_set_error (bfd_error_invalid_operation);
2399 if (bfd_seek (abfd, asect->rel_filepos, SEEK_SET) != 0)
2402 each_size = obj_reloc_entry_size (abfd);
2404 count = reloc_size / each_size;
2406 reloc_cache = (arelent *) malloc ((size_t) (count * sizeof (arelent)));
2407 if (reloc_cache == NULL && count != 0)
2409 bfd_set_error (bfd_error_no_memory);
2412 memset (reloc_cache, 0, count * sizeof (arelent));
2414 relocs = malloc (reloc_size);
2415 if (relocs == NULL && reloc_size != 0)
2418 bfd_set_error (bfd_error_no_memory);
2422 if (bfd_read (relocs, 1, reloc_size, abfd) != reloc_size)
2429 cache_ptr = reloc_cache;
2430 if (each_size == RELOC_EXT_SIZE)
2432 register struct reloc_ext_external *rptr =
2433 (struct reloc_ext_external *) relocs;
2435 for (; counter < count; counter++, rptr++, cache_ptr++)
2436 NAME(aout,swap_ext_reloc_in) (abfd, rptr, cache_ptr, symbols);
2440 register struct reloc_std_external *rptr =
2441 (struct reloc_std_external *) relocs;
2443 for (; counter < count; counter++, rptr++, cache_ptr++)
2444 NAME(aout,swap_std_reloc_in) (abfd, rptr, cache_ptr, symbols);
2449 asect->relocation = reloc_cache;
2450 asect->reloc_count = cache_ptr - reloc_cache;
2455 /* Write out a relocation section into an object file. */
2458 NAME(aout,squirt_out_relocs) (abfd, section)
2463 unsigned char *native, *natptr;
2466 unsigned int count = section->reloc_count;
2469 if (count == 0) return true;
2471 each_size = obj_reloc_entry_size (abfd);
2472 natsize = each_size * count;
2473 native = (unsigned char *) bfd_zalloc (abfd, natsize);
2475 bfd_set_error (bfd_error_no_memory);
2479 generic = section->orelocation;
2481 if (each_size == RELOC_EXT_SIZE)
2483 for (natptr = native;
2485 --count, natptr += each_size, ++generic)
2486 NAME(aout,swap_ext_reloc_out) (abfd, *generic, (struct reloc_ext_external *)natptr);
2490 for (natptr = native;
2492 --count, natptr += each_size, ++generic)
2493 NAME(aout,swap_std_reloc_out)(abfd, *generic, (struct reloc_std_external *)natptr);
2496 if ( bfd_write ((PTR) native, 1, natsize, abfd) != natsize) {
2497 bfd_release(abfd, native);
2500 bfd_release (abfd, native);
2505 /* This is stupid. This function should be a boolean predicate */
2507 NAME(aout,canonicalize_reloc) (abfd, section, relptr, symbols)
2513 arelent *tblptr = section->relocation;
2516 if (!(tblptr || NAME(aout,slurp_reloc_table)(abfd, section, symbols)))
2519 if (section->flags & SEC_CONSTRUCTOR) {
2520 arelent_chain *chain = section->constructor_chain;
2521 for (count = 0; count < section->reloc_count; count ++) {
2522 *relptr ++ = &chain->relent;
2523 chain = chain->next;
2527 tblptr = section->relocation;
2529 for (count = 0; count++ < section->reloc_count;)
2531 *relptr++ = tblptr++;
2536 return section->reloc_count;
2540 NAME(aout,get_reloc_upper_bound) (abfd, asect)
2544 if (bfd_get_format (abfd) != bfd_object) {
2545 bfd_set_error (bfd_error_invalid_operation);
2548 if (asect->flags & SEC_CONSTRUCTOR) {
2549 return (sizeof (arelent *) * (asect->reloc_count+1));
2552 if (asect == obj_datasec (abfd))
2553 return (sizeof (arelent *)
2554 * ((exec_hdr(abfd)->a_drsize / obj_reloc_entry_size (abfd))
2557 if (asect == obj_textsec (abfd))
2558 return (sizeof (arelent *)
2559 * ((exec_hdr(abfd)->a_trsize / obj_reloc_entry_size (abfd))
2562 bfd_set_error (bfd_error_invalid_operation);
2568 NAME(aout,get_symtab_upper_bound) (abfd)
2571 if (!NAME(aout,slurp_symbol_table)(abfd))
2574 return (bfd_get_symcount (abfd)+1) * (sizeof (aout_symbol_type *));
2579 NAME(aout,get_lineno) (ignore_abfd, ignore_symbol)
2581 asymbol *ignore_symbol;
2583 return (alent *)NULL;
2588 NAME(aout,get_symbol_info) (ignore_abfd, symbol, ret)
2593 bfd_symbol_info (symbol, ret);
2595 if (ret->type == '?')
2597 int type_code = aout_symbol(symbol)->type & 0xff;
2598 CONST char *stab_name = aout_stab_name(type_code);
2599 static char buf[10];
2601 if (stab_name == NULL)
2603 sprintf(buf, "(%d)", type_code);
2607 ret->stab_other = (unsigned)(aout_symbol(symbol)->other & 0xff);
2608 ret->stab_desc = (unsigned)(aout_symbol(symbol)->desc & 0xffff);
2609 ret->stab_name = stab_name;
2615 NAME(aout,print_symbol) (ignore_abfd, afile, symbol, how)
2619 bfd_print_symbol_type how;
2621 FILE *file = (FILE *)afile;
2624 case bfd_print_symbol_name:
2626 fprintf(file,"%s", symbol->name);
2628 case bfd_print_symbol_more:
2629 fprintf(file,"%4x %2x %2x",(unsigned)(aout_symbol(symbol)->desc & 0xffff),
2630 (unsigned)(aout_symbol(symbol)->other & 0xff),
2631 (unsigned)(aout_symbol(symbol)->type));
2633 case bfd_print_symbol_all:
2635 CONST char *section_name = symbol->section->name;
2638 bfd_print_symbol_vandf((PTR)file,symbol);
2640 fprintf(file," %-5s %04x %02x %02x",
2642 (unsigned)(aout_symbol(symbol)->desc & 0xffff),
2643 (unsigned)(aout_symbol(symbol)->other & 0xff),
2644 (unsigned)(aout_symbol(symbol)->type & 0xff));
2646 fprintf(file," %s", symbol->name);
2653 provided a BFD, a section and an offset into the section, calculate
2654 and return the name of the source file and the line nearest to the
2659 NAME(aout,find_nearest_line)
2660 (abfd, section, symbols, offset, filename_ptr, functionname_ptr, line_ptr)
2665 CONST char **filename_ptr;
2666 CONST char **functionname_ptr;
2667 unsigned int *line_ptr;
2669 /* Run down the file looking for the filename, function and linenumber */
2671 static char buffer[100];
2672 static char filename_buffer[200];
2673 CONST char *directory_name = NULL;
2674 CONST char *main_file_name = NULL;
2675 CONST char *current_file_name = NULL;
2676 CONST char *line_file_name = NULL; /* Value of current_file_name at line number. */
2677 bfd_vma high_line_vma = ~0;
2678 bfd_vma low_func_vma = 0;
2680 *filename_ptr = abfd->filename;
2681 *functionname_ptr = 0;
2683 if (symbols != (asymbol **)NULL) {
2684 for (p = symbols; *p; p++) {
2685 aout_symbol_type *q = (aout_symbol_type *)(*p);
2689 main_file_name = current_file_name = q->symbol.name;
2690 /* Look ahead to next symbol to check if that too is an N_SO. */
2694 q = (aout_symbol_type *)(*p);
2695 if (q->type != (int)N_SO)
2698 /* Found a second N_SO First is directory; second is filename. */
2699 directory_name = current_file_name;
2700 main_file_name = current_file_name = q->symbol.name;
2701 if (obj_textsec(abfd) != section)
2705 current_file_name = q->symbol.name;
2712 /* We'll keep this if it resolves nearer than the one we have already */
2713 if (q->symbol.value >= offset &&
2714 q->symbol.value < high_line_vma) {
2715 *line_ptr = q->desc;
2716 high_line_vma = q->symbol.value;
2717 line_file_name = current_file_name;
2722 /* We'll keep this if it is nearer than the one we have already */
2723 if (q->symbol.value >= low_func_vma &&
2724 q->symbol.value <= offset) {
2725 low_func_vma = q->symbol.value;
2726 func = (asymbol *)q;
2728 if (*line_ptr && func) {
2729 CONST char *function = func->name;
2732 /* The caller expects a symbol name. We actually have a
2733 function name, without the leading underscore. Put the
2734 underscore back in, so that the caller gets a symbol
2736 if (bfd_get_symbol_leading_char (abfd) == '\0')
2737 strncpy (buffer, function, sizeof (buffer) - 1);
2740 buffer[0] = bfd_get_symbol_leading_char (abfd);
2741 strncpy (buffer + 1, function, sizeof (buffer) - 2);
2743 buffer[sizeof(buffer)-1] = 0;
2744 /* Have to remove : stuff */
2745 p = strchr(buffer,':');
2746 if (p != NULL) { *p = '\0'; }
2747 *functionname_ptr = buffer;
2759 main_file_name = line_file_name;
2760 if (main_file_name) {
2761 if (main_file_name[0] == '/' || directory_name == NULL)
2762 *filename_ptr = main_file_name;
2764 sprintf(filename_buffer, "%.140s%.50s",
2765 directory_name, main_file_name);
2766 *filename_ptr = filename_buffer;
2775 NAME(aout,sizeof_headers) (abfd, execable)
2779 return adata(abfd).exec_bytes_size;
2782 /* Free all information we have cached for this BFD. We can always
2783 read it again later if we need it. */
2786 NAME(aout,bfd_free_cached_info) (abfd)
2791 if (bfd_get_format (abfd) != bfd_object)
2794 #define FREE(x) if (x != NULL) { free (x); x = NULL; }
2795 FREE (obj_aout_symbols (abfd));
2796 FREE (obj_aout_external_syms (abfd));
2797 FREE (obj_aout_external_strings (abfd));
2798 for (o = abfd->sections; o != (asection *) NULL; o = o->next)
2799 FREE (o->relocation);
2805 /* a.out link code. */
2807 /* a.out linker hash table entries. */
2809 struct aout_link_hash_entry
2811 struct bfd_link_hash_entry root;
2812 /* Symbol index in output file. */
2816 /* a.out linker hash table. */
2818 struct aout_link_hash_table
2820 struct bfd_link_hash_table root;
2823 static struct bfd_hash_entry *aout_link_hash_newfunc
2824 PARAMS ((struct bfd_hash_entry *entry,
2825 struct bfd_hash_table *table,
2826 const char *string));
2827 static boolean aout_link_add_object_symbols
2828 PARAMS ((bfd *, struct bfd_link_info *));
2829 static boolean aout_link_check_archive_element
2830 PARAMS ((bfd *, struct bfd_link_info *, boolean *));
2831 static boolean aout_link_free_symbols PARAMS ((bfd *));
2832 static boolean aout_link_check_ar_symbols
2833 PARAMS ((bfd *, struct bfd_link_info *, boolean *pneeded));
2834 static boolean aout_link_add_symbols
2835 PARAMS ((bfd *, struct bfd_link_info *));
2837 /* Routine to create an entry in an a.out link hash table. */
2839 static struct bfd_hash_entry *
2840 aout_link_hash_newfunc (entry, table, string)
2841 struct bfd_hash_entry *entry;
2842 struct bfd_hash_table *table;
2845 struct aout_link_hash_entry *ret = (struct aout_link_hash_entry *) entry;
2847 /* Allocate the structure if it has not already been allocated by a
2849 if (ret == (struct aout_link_hash_entry *) NULL)
2850 ret = ((struct aout_link_hash_entry *)
2851 bfd_hash_allocate (table, sizeof (struct aout_link_hash_entry)));
2852 if (ret == (struct aout_link_hash_entry *) NULL)
2854 bfd_set_error (bfd_error_no_memory);
2855 return (struct bfd_hash_entry *) ret;
2858 /* Call the allocation method of the superclass. */
2859 ret = ((struct aout_link_hash_entry *)
2860 _bfd_link_hash_newfunc ((struct bfd_hash_entry *) ret,
2863 /* Set local fields. */
2866 return (struct bfd_hash_entry *) ret;
2869 /* Create an a.out link hash table. */
2871 struct bfd_link_hash_table *
2872 NAME(aout,link_hash_table_create) (abfd)
2875 struct aout_link_hash_table *ret;
2877 ret = ((struct aout_link_hash_table *)
2878 malloc (sizeof (struct aout_link_hash_table)));
2879 if (ret == (struct aout_link_hash_table *) NULL)
2881 bfd_set_error (bfd_error_no_memory);
2882 return (struct bfd_link_hash_table *) NULL;
2884 if (! _bfd_link_hash_table_init (&ret->root, abfd,
2885 aout_link_hash_newfunc))
2888 return (struct bfd_link_hash_table *) NULL;
2893 /* Look up an entry in an a.out link hash table. */
2895 #define aout_link_hash_lookup(table, string, create, copy, follow) \
2896 ((struct aout_link_hash_entry *) \
2897 bfd_link_hash_lookup (&(table)->root, (string), (create), (copy), (follow)))
2899 /* Traverse an a.out link hash table. */
2901 #define aout_link_hash_traverse(table, func, info) \
2902 (bfd_link_hash_traverse \
2904 (boolean (*) PARAMS ((struct bfd_link_hash_entry *, PTR))) (func), \
2907 /* Get the a.out link hash table from the info structure. This is
2910 #define aout_hash_table(p) ((struct aout_link_hash_table *) ((p)->hash))
2912 /* Given an a.out BFD, add symbols to the global hash table as
2916 NAME(aout,link_add_symbols) (abfd, info)
2918 struct bfd_link_info *info;
2920 switch (bfd_get_format (abfd))
2923 return aout_link_add_object_symbols (abfd, info);
2925 return _bfd_generic_link_add_archive_symbols
2926 (abfd, info, aout_link_check_archive_element);
2928 bfd_set_error (bfd_error_wrong_format);
2933 /* Add symbols from an a.out object file. */
2936 aout_link_add_object_symbols (abfd, info)
2938 struct bfd_link_info *info;
2940 if (! aout_get_external_symbols (abfd))
2942 if (! aout_link_add_symbols (abfd, info))
2944 if (! info->keep_memory)
2946 if (! aout_link_free_symbols (abfd))
2952 /* Check a single archive element to see if we need to include it in
2953 the link. *PNEEDED is set according to whether this element is
2954 needed in the link or not. This is called from
2955 _bfd_generic_link_add_archive_symbols. */
2958 aout_link_check_archive_element (abfd, info, pneeded)
2960 struct bfd_link_info *info;
2963 if (! aout_get_external_symbols (abfd))
2966 if (! aout_link_check_ar_symbols (abfd, info, pneeded))
2971 if (! aout_link_add_symbols (abfd, info))
2975 /* We keep around the symbols even if we aren't going to use this
2976 object file, because we may want to reread it. This doesn't
2977 waste too much memory, because it isn't all that common to read
2978 an archive element but not need it. */
2979 if (! info->keep_memory)
2981 if (! aout_link_free_symbols (abfd))
2988 /* Free up the internal symbols read from an a.out file. */
2991 aout_link_free_symbols (abfd)
2994 if (obj_aout_external_syms (abfd) != (struct external_nlist *) NULL)
2996 free ((PTR) obj_aout_external_syms (abfd));
2997 obj_aout_external_syms (abfd) = (struct external_nlist *) NULL;
2999 if (obj_aout_external_strings (abfd) != (char *) NULL)
3001 free ((PTR) obj_aout_external_strings (abfd));
3002 obj_aout_external_strings (abfd) = (char *) NULL;
3007 /* Look through the internal symbols to see if this object file should
3008 be included in the link. We should include this object file if it
3009 defines any symbols which are currently undefined. If this object
3010 file defines a common symbol, then we may adjust the size of the
3011 known symbol but we do not include the object file in the link
3012 (unless there is some other reason to include it). */
3015 aout_link_check_ar_symbols (abfd, info, pneeded)
3017 struct bfd_link_info *info;
3020 register struct external_nlist *p;
3021 struct external_nlist *pend;
3026 /* Look through all the symbols. */
3027 p = obj_aout_external_syms (abfd);
3028 pend = p + obj_aout_external_sym_count (abfd);
3029 strings = obj_aout_external_strings (abfd);
3030 for (; p < pend; p++)
3032 int type = bfd_h_get_8 (abfd, p->e_type);
3034 struct bfd_link_hash_entry *h;
3036 /* Ignore symbols that are not externally visible. */
3037 if ((type & N_EXT) == 0)
3039 if (type == N_WARNING
3045 name = strings + GET_WORD (abfd, p->e_strx);
3046 h = bfd_link_hash_lookup (info->hash, name, false, false, true);
3048 /* We are only interested in symbols that are currently
3049 undefined or common. */
3050 if (h == (struct bfd_link_hash_entry *) NULL
3051 || (h->type != bfd_link_hash_undefined
3052 && h->type != bfd_link_hash_common))
3054 if (type == (N_INDR | N_EXT))
3059 if (type == (N_TEXT | N_EXT)
3060 || type == (N_DATA | N_EXT)
3061 || type == (N_BSS | N_EXT)
3062 || type == (N_ABS | N_EXT)
3063 || type == (N_INDR | N_EXT))
3065 /* This object file defines this symbol. We must link it
3066 in. This is true regardless of whether the current
3067 definition of the symbol is undefined or common. If the
3068 current definition is common, we have a case in which we
3069 have already seen an object file including
3071 and this object file from the archive includes
3073 In such a case we must include this object file. */
3074 if (! (*info->callbacks->add_archive_element) (info, abfd, name))
3080 if (type == (N_UNDF | N_EXT))
3084 value = GET_WORD (abfd, p->e_value);
3087 /* This symbol is common in the object from the archive
3089 if (h->type == bfd_link_hash_undefined)
3093 symbfd = h->u.undef.abfd;
3094 if (symbfd == (bfd *) NULL)
3096 /* This symbol was created as undefined from
3097 outside BFD. We assume that we should link
3098 in the object file. This is done for the -u
3099 option in the linker. */
3100 if (! (*info->callbacks->add_archive_element) (info,
3107 /* Turn the current link symbol into a common
3108 symbol. It is already on the undefs list. */
3109 h->type = bfd_link_hash_common;
3110 h->u.c.size = value;
3111 h->u.c.section = bfd_make_section_old_way (symbfd,
3116 /* Adjust the size of the common symbol if
3118 if (value > h->u.c.size)
3119 h->u.c.size = value;
3125 /* We do not need this object file. */
3129 /* Add all symbols from an object file to the hash table. */
3132 aout_link_add_symbols (abfd, info)
3134 struct bfd_link_info *info;
3136 bfd_size_type sym_count;
3139 struct aout_link_hash_entry **sym_hash;
3140 register struct external_nlist *p;
3141 struct external_nlist *pend;
3143 sym_count = obj_aout_external_sym_count (abfd);
3144 strings = obj_aout_external_strings (abfd);
3145 if (info->keep_memory)
3150 /* We keep a list of the linker hash table entries that correspond
3151 to particular symbols. We could just look them up in the hash
3152 table, but keeping the list is more efficient. Perhaps this
3153 should be conditional on info->keep_memory. */
3154 sym_hash = ((struct aout_link_hash_entry **)
3157 * sizeof (struct aout_link_hash_entry *))));
3160 bfd_set_error (bfd_error_no_memory);
3163 obj_aout_sym_hashes (abfd) = sym_hash;
3165 p = obj_aout_external_syms (abfd);
3166 pend = p + sym_count;
3167 for (; p < pend; p++, sym_hash++)
3178 type = bfd_h_get_8 (abfd, p->e_type);
3180 /* Ignore debugging symbols. */
3181 if ((type & N_STAB) != 0)
3184 /* Ignore symbols that are not external. */
3185 if ((type & N_EXT) == 0
3186 && type != N_WARNING
3192 /* If this is an N_INDR symbol we must skip the next entry,
3193 which is the symbol to indirect to (actually, an N_INDR
3194 symbol without N_EXT set is pretty useless). */
3203 /* Ignore N_FN symbols (these appear to have N_EXT set). */
3207 name = strings + GET_WORD (abfd, p->e_strx);
3208 value = GET_WORD (abfd, p->e_value);
3215 case N_UNDF | N_EXT:
3217 section = &bfd_com_section;
3219 section = &bfd_und_section;
3222 section = &bfd_abs_section;
3224 case N_TEXT | N_EXT:
3225 section = obj_textsec (abfd);
3226 value -= bfd_get_section_vma (abfd, section);
3228 case N_DATA | N_EXT:
3229 section = obj_datasec (abfd);
3230 value -= bfd_get_section_vma (abfd, section);
3233 section = obj_bsssec (abfd);
3234 value -= bfd_get_section_vma (abfd, section);
3236 case N_INDR | N_EXT:
3237 /* An indirect symbol. The next symbol is the symbol
3238 which this one really is. */
3239 BFD_ASSERT (p + 1 < pend);
3241 string = strings + GET_WORD (abfd, p->e_strx);
3242 section = &bfd_ind_section;
3243 flags |= BSF_INDIRECT;
3245 case N_COMM | N_EXT:
3246 section = &bfd_com_section;
3248 case N_SETA: case N_SETA | N_EXT:
3249 section = &bfd_abs_section;
3250 flags |= BSF_CONSTRUCTOR;
3252 case N_SETT: case N_SETT | N_EXT:
3253 section = obj_textsec (abfd);
3254 flags |= BSF_CONSTRUCTOR;
3255 value -= bfd_get_section_vma (abfd, section);
3257 case N_SETD: case N_SETD | N_EXT:
3258 section = obj_datasec (abfd);
3259 flags |= BSF_CONSTRUCTOR;
3260 value -= bfd_get_section_vma (abfd, section);
3262 case N_SETB: case N_SETB | N_EXT:
3263 section = obj_bsssec (abfd);
3264 flags |= BSF_CONSTRUCTOR;
3265 value -= bfd_get_section_vma (abfd, section);
3268 /* A warning symbol. The next symbol is the one to warn
3270 BFD_ASSERT (p + 1 < pend);
3273 name = strings + GET_WORD (abfd, p->e_strx);
3274 section = &bfd_und_section;
3275 flags |= BSF_WARNING;
3279 if (! (_bfd_generic_link_add_one_symbol
3280 (info, abfd, name, flags, section, value, string, copy, false,
3281 (struct bfd_link_hash_entry **) sym_hash)))
3284 if (type == (N_INDR | N_EXT) || type == N_WARNING)
3291 /* During the final link step we need to pass around a bunch of
3292 information, so we do it in an instance of this structure. */
3294 struct aout_final_link_info
3296 /* General link information. */
3297 struct bfd_link_info *info;
3300 /* Reloc file positions. */
3301 file_ptr treloff, dreloff;
3302 /* File position of symbols. */
3305 struct stringtab_data strtab;
3308 static boolean aout_link_input_bfd
3309 PARAMS ((struct aout_final_link_info *, bfd *input_bfd));
3310 static boolean aout_link_write_symbols
3311 PARAMS ((struct aout_final_link_info *, bfd *input_bfd, int *symbol_map));
3312 static boolean aout_link_write_other_symbol
3313 PARAMS ((struct aout_link_hash_entry *, PTR));
3314 static boolean aout_link_input_section
3315 PARAMS ((struct aout_final_link_info *, bfd *input_bfd,
3316 asection *input_section, file_ptr *reloff_ptr,
3317 bfd_size_type rel_size, int *symbol_map));
3318 static boolean aout_link_input_section_std
3319 PARAMS ((struct aout_final_link_info *, bfd *input_bfd,
3320 asection *input_section, struct reloc_std_external *,
3321 bfd_size_type rel_size, bfd_byte *contents, int *symbol_map));
3322 static boolean aout_link_input_section_ext
3323 PARAMS ((struct aout_final_link_info *, bfd *input_bfd,
3324 asection *input_section, struct reloc_ext_external *,
3325 bfd_size_type rel_size, bfd_byte *contents, int *symbol_map));
3326 static INLINE asection *aout_reloc_index_to_section
3327 PARAMS ((bfd *, int));
3328 static boolean aout_link_reloc_link_order
3329 PARAMS ((struct aout_final_link_info *, asection *,
3330 struct bfd_link_order *));
3332 /* Do the final link step. This is called on the output BFD. The
3333 INFO structure should point to a list of BFDs linked through the
3334 link_next field which can be used to find each BFD which takes part
3335 in the output. Also, each section in ABFD should point to a list
3336 of bfd_link_order structures which list all the input sections for
3337 the output section. */
3340 NAME(aout,final_link) (abfd, info, callback)
3342 struct bfd_link_info *info;
3343 void (*callback) PARAMS ((bfd *, file_ptr *, file_ptr *, file_ptr *));
3345 struct aout_final_link_info aout_info;
3347 bfd_size_type text_size;
3349 register struct bfd_link_order *p;
3351 boolean have_link_order_relocs;
3353 aout_info.info = info;
3354 aout_info.output_bfd = abfd;
3356 if (! info->relocateable)
3358 exec_hdr (abfd)->a_trsize = 0;
3359 exec_hdr (abfd)->a_drsize = 0;
3363 bfd_size_type trsize, drsize;
3365 /* Count up the relocation sizes. */
3368 for (sub = info->input_bfds; sub != (bfd *) NULL; sub = sub->link_next)
3370 if (bfd_get_flavour (abfd) == bfd_target_aout_flavour)
3372 trsize += exec_hdr (sub)->a_trsize;
3373 drsize += exec_hdr (sub)->a_drsize;
3377 /* FIXME: We need to identify the .text and .data sections
3378 and call get_reloc_upper_bound and canonicalize_reloc to
3379 work out the number of relocs needed, and then multiply
3380 by the reloc size. */
3384 trsize += (_bfd_count_link_order_relocs (obj_textsec (abfd)
3386 * obj_reloc_entry_size (abfd));
3387 exec_hdr (abfd)->a_trsize = trsize;
3388 drsize += (_bfd_count_link_order_relocs (obj_datasec (abfd)
3390 * obj_reloc_entry_size (abfd));
3391 exec_hdr (abfd)->a_drsize = drsize;
3394 exec_hdr (abfd)->a_entry = bfd_get_start_address (abfd);
3396 /* Adjust the section sizes and vmas according to the magic number.
3397 This sets a_text, a_data and a_bss in the exec_hdr and sets the
3398 filepos for each section. */
3399 if (! NAME(aout,adjust_sizes_and_vmas) (abfd, &text_size, &text_end))
3402 /* The relocation and symbol file positions differ among a.out
3403 targets. We are passed a callback routine from the backend
3404 specific code to handle this.
3405 FIXME: At this point we do not know how much space the symbol
3406 table will require. This will not work for any (nonstandard)
3407 a.out target that needs to know the symbol table size before it
3408 can compute the relocation file positions. This may or may not
3409 be the case for the hp300hpux target, for example. */
3410 (*callback) (abfd, &aout_info.treloff, &aout_info.dreloff,
3412 obj_textsec (abfd)->rel_filepos = aout_info.treloff;
3413 obj_datasec (abfd)->rel_filepos = aout_info.dreloff;
3414 obj_sym_filepos (abfd) = aout_info.symoff;
3416 /* We keep a count of the symbols as we output them. */
3417 obj_aout_external_sym_count (abfd) = 0;
3419 /* We accumulate the string table as we write out the symbols. */
3420 stringtab_init (&aout_info.strtab);
3422 /* The most time efficient way to do the link would be to read all
3423 the input object files into memory and then sort out the
3424 information into the output file. Unfortunately, that will
3425 probably use too much memory. Another method would be to step
3426 through everything that composes the text section and write it
3427 out, and then everything that composes the data section and write
3428 it out, and then write out the relocs, and then write out the
3429 symbols. Unfortunately, that requires reading stuff from each
3430 input file several times, and we will not be able to keep all the
3431 input files open simultaneously, and reopening them will be slow.
3433 What we do is basically process one input file at a time. We do
3434 everything we need to do with an input file once--copy over the
3435 section contents, handle the relocation information, and write
3436 out the symbols--and then we throw away the information we read
3437 from it. This approach requires a lot of lseeks of the output
3438 file, which is unfortunate but still faster than reopening a lot
3441 We use the output_has_begun field of the input BFDs to see
3442 whether we have already handled it. */
3443 for (sub = info->input_bfds; sub != (bfd *) NULL; sub = sub->link_next)
3444 sub->output_has_begun = false;
3446 have_link_order_relocs = false;
3447 for (o = abfd->sections; o != (asection *) NULL; o = o->next)
3449 for (p = o->link_order_head;
3450 p != (struct bfd_link_order *) NULL;
3453 if (p->type == bfd_indirect_link_order
3454 && (bfd_get_flavour (p->u.indirect.section->owner)
3455 == bfd_target_aout_flavour))
3459 input_bfd = p->u.indirect.section->owner;
3460 if (! input_bfd->output_has_begun)
3462 if (! aout_link_input_bfd (&aout_info, input_bfd))
3464 input_bfd->output_has_begun = true;
3467 else if (p->type == bfd_section_reloc_link_order
3468 || p->type == bfd_symbol_reloc_link_order)
3470 /* These are handled below. */
3471 have_link_order_relocs = true;
3475 if (! _bfd_default_link_order (abfd, info, o, p))
3481 /* Write out any symbols that we have not already written out. */
3482 aout_link_hash_traverse (aout_hash_table (info),
3483 aout_link_write_other_symbol,
3486 /* Now handle any relocs we were asked to create by the linker.
3487 These did not come from any input file. We must do these after
3488 we have written out all the symbols, so that we know the symbol
3490 if (have_link_order_relocs)
3492 for (o = abfd->sections; o != (asection *) NULL; o = o->next)
3494 for (p = o->link_order_head;
3495 p != (struct bfd_link_order *) NULL;
3498 if (p->type == bfd_section_reloc_link_order
3499 || p->type == bfd_symbol_reloc_link_order)
3501 if (! aout_link_reloc_link_order (&aout_info, o, p))
3508 /* Update the header information. */
3509 abfd->symcount = obj_aout_external_sym_count (abfd);
3510 exec_hdr (abfd)->a_syms = abfd->symcount * EXTERNAL_NLIST_SIZE;
3511 obj_str_filepos (abfd) = obj_sym_filepos (abfd) + exec_hdr (abfd)->a_syms;
3512 obj_textsec (abfd)->reloc_count =
3513 exec_hdr (abfd)->a_trsize / obj_reloc_entry_size (abfd);
3514 obj_datasec (abfd)->reloc_count =
3515 exec_hdr (abfd)->a_drsize / obj_reloc_entry_size (abfd);
3517 /* Write out the string table. */
3518 if (bfd_seek (abfd, obj_str_filepos (abfd), SEEK_SET) != 0)
3520 return emit_strtab (abfd, &aout_info.strtab);
3523 /* Link an a.out input BFD into the output file. */
3526 aout_link_input_bfd (finfo, input_bfd)
3527 struct aout_final_link_info *finfo;
3530 bfd_size_type sym_count;
3531 int *symbol_map = NULL;
3533 BFD_ASSERT (bfd_get_format (input_bfd) == bfd_object);
3535 /* Get the symbols. We probably have them already, unless
3536 finfo->info->keep_memory is false. */
3537 if (! aout_get_external_symbols (input_bfd))
3540 sym_count = obj_aout_external_sym_count (input_bfd);
3541 symbol_map = (int *) malloc ((size_t) sym_count * sizeof (int));
3542 if (symbol_map == NULL && sym_count != 0)
3544 bfd_set_error (bfd_error_no_memory);
3548 /* Write out the symbols and get a map of the new indices. */
3549 if (! aout_link_write_symbols (finfo, input_bfd, symbol_map))
3552 /* Relocate and write out the sections. */
3553 if (! aout_link_input_section (finfo, input_bfd,
3554 obj_textsec (input_bfd),
3556 exec_hdr (input_bfd)->a_trsize,
3558 || ! aout_link_input_section (finfo, input_bfd,
3559 obj_datasec (input_bfd),
3561 exec_hdr (input_bfd)->a_drsize,
3565 /* If we are not keeping memory, we don't need the symbols any
3566 longer. We still need them if we are keeping memory, because the
3567 strings in the hash table point into them. */
3568 if (! finfo->info->keep_memory)
3570 if (! aout_link_free_symbols (input_bfd))
3574 if (symbol_map != NULL)
3578 if (symbol_map != NULL)
3583 /* Adjust and write out the symbols for an a.out file. Set the new
3584 symbol indices into a symbol_map. */
3587 aout_link_write_symbols (finfo, input_bfd, symbol_map)
3588 struct aout_final_link_info *finfo;
3593 bfd_size_type sym_count;
3595 enum bfd_link_strip strip;
3596 enum bfd_link_discard discard;
3597 struct external_nlist *output_syms = NULL;
3598 struct external_nlist *outsym;
3599 register struct external_nlist *sym;
3600 struct external_nlist *sym_end;
3601 struct aout_link_hash_entry **sym_hash;
3603 boolean skip_indirect;
3605 output_bfd = finfo->output_bfd;
3606 sym_count = obj_aout_external_sym_count (input_bfd);
3607 strings = obj_aout_external_strings (input_bfd);
3608 strip = finfo->info->strip;
3609 discard = finfo->info->discard;
3610 output_syms = ((struct external_nlist *)
3611 malloc ((size_t) (sym_count + 1) * EXTERNAL_NLIST_SIZE));
3612 if (output_syms == NULL)
3614 bfd_set_error (bfd_error_no_memory);
3617 outsym = output_syms;
3619 /* First write out a symbol for this object file, unless we are
3620 discarding such symbols. */
3621 if (strip != strip_all
3622 && (strip != strip_some
3623 || bfd_hash_lookup (finfo->info->keep_hash, input_bfd->filename,
3624 false, false) != NULL)
3625 && discard != discard_all)
3627 bfd_h_put_8 (output_bfd, N_TEXT, outsym->e_type);
3628 bfd_h_put_8 (output_bfd, 0, outsym->e_other);
3629 bfd_h_put_16 (output_bfd, (bfd_vma) 0, outsym->e_desc);
3630 PUT_WORD (output_bfd,
3631 add_to_stringtab (output_bfd, input_bfd->filename,
3634 PUT_WORD (output_bfd,
3635 (bfd_get_section_vma (output_bfd,
3636 obj_textsec (input_bfd)->output_section)
3637 + obj_textsec (input_bfd)->output_offset),
3639 ++obj_aout_external_sym_count (output_bfd);
3644 skip_indirect = false;
3645 sym = obj_aout_external_syms (input_bfd);
3646 sym_end = sym + sym_count;
3647 sym_hash = obj_aout_sym_hashes (input_bfd);
3648 for (; sym < sym_end; sym++, sym_hash++, symbol_map++)
3652 struct aout_link_hash_entry *h;
3659 type = bfd_h_get_8 (input_bfd, sym->e_type);
3660 name = strings + GET_WORD (input_bfd, sym->e_strx);
3666 /* Pass this symbol through. It is the target of an
3667 indirect or warning symbol. */
3668 val = GET_WORD (input_bfd, sym->e_value);
3671 else if (skip_indirect)
3673 /* Skip this symbol, which is the target of an indirect
3674 symbol that we have changed to no longer be an indirect
3676 skip_indirect = false;
3681 struct aout_link_hash_entry *hresolve;
3683 /* We have saved the hash table entry for this symbol, if
3684 there is one. Note that we could just look it up again
3685 in the hash table, provided we first check that it is an
3689 /* If this is an indirect or warning symbol, then change
3690 hresolve to the base symbol. We also change *sym_hash so
3691 that the relocation routines relocate against the real
3694 if (h != (struct aout_link_hash_entry *) NULL
3695 && (h->root.type == bfd_link_hash_indirect
3696 || h->root.type == bfd_link_hash_warning))
3698 hresolve = (struct aout_link_hash_entry *) h->root.u.i.link;
3699 while (hresolve->root.type == bfd_link_hash_indirect)
3700 hresolve = ((struct aout_link_hash_entry *)
3701 hresolve->root.u.i.link);
3702 *sym_hash = hresolve;
3705 /* If the symbol has already been written out, skip it. */
3706 if (h != (struct aout_link_hash_entry *) NULL
3709 *symbol_map = h->indx;
3713 /* See if we are stripping this symbol. */
3719 case strip_debugger:
3720 if ((type & N_STAB) != 0)
3724 if (bfd_hash_lookup (finfo->info->keep_hash, name, false, false)
3734 if (h != (struct aout_link_hash_entry *) NULL)
3735 h->root.written = true;
3739 /* Get the value of the symbol. */
3740 if ((type & N_TYPE) == N_TEXT)
3741 symsec = obj_textsec (input_bfd);
3742 else if ((type & N_TYPE) == N_DATA)
3743 symsec = obj_datasec (input_bfd);
3744 else if ((type & N_TYPE) == N_BSS)
3745 symsec = obj_bsssec (input_bfd);
3746 else if ((type & N_TYPE) == N_ABS)
3747 symsec = &bfd_abs_section;
3748 else if (((type & N_TYPE) == N_INDR
3749 && (hresolve == (struct aout_link_hash_entry *) NULL
3750 || (hresolve->root.type != bfd_link_hash_defined
3751 && hresolve->root.type != bfd_link_hash_common)))
3752 || type == N_WARNING)
3754 /* Pass the next symbol through unchanged. The
3755 condition above for indirect symbols is so that if
3756 the indirect symbol was defined, we output it with
3757 the correct definition so the debugger will
3760 val = GET_WORD (input_bfd, sym->e_value);
3763 else if ((type & N_STAB) != 0)
3765 val = GET_WORD (input_bfd, sym->e_value);
3770 /* If we get here with an indirect symbol, it means that
3771 we are outputting it with a real definition. In such
3772 a case we do not want to output the next symbol,
3773 which is the target of the indirection. */
3774 if ((type & N_TYPE) == N_INDR)
3775 skip_indirect = true;
3777 /* We need to get the value from the hash table. We use
3778 hresolve so that if we have defined an indirect
3779 symbol we output the final definition. */
3780 if (h == (struct aout_link_hash_entry *) NULL)
3782 else if (hresolve->root.type == bfd_link_hash_defined)
3784 asection *input_section;
3785 asection *output_section;
3787 /* This case means a common symbol which was turned
3788 into a defined symbol. */
3789 input_section = hresolve->root.u.def.section;
3790 output_section = input_section->output_section;
3791 BFD_ASSERT (output_section == &bfd_abs_section
3792 || output_section->owner == output_bfd);
3793 val = (hresolve->root.u.def.value
3794 + bfd_get_section_vma (output_bfd, output_section)
3795 + input_section->output_offset);
3797 /* Get the correct type based on the section. If
3798 this is a constructed set, force it to be
3799 globally visible. */
3808 if (output_section == obj_textsec (output_bfd))
3810 else if (output_section == obj_datasec (output_bfd))
3812 else if (output_section == obj_bsssec (output_bfd))
3817 else if (hresolve->root.type == bfd_link_hash_common)
3818 val = hresolve->root.u.c.size;
3824 if (symsec != (asection *) NULL)
3825 val = (symsec->output_section->vma
3826 + symsec->output_offset
3827 + (GET_WORD (input_bfd, sym->e_value)
3830 /* If this is a global symbol set the written flag, and if
3831 it is a local symbol see if we should discard it. */
3832 if (h != (struct aout_link_hash_entry *) NULL)
3834 h->root.written = true;
3835 h->indx = obj_aout_external_sym_count (output_bfd);
3844 if (*name == *finfo->info->lprefix
3845 && (finfo->info->lprefix_len == 1
3846 || strncmp (name, finfo->info->lprefix,
3847 finfo->info->lprefix_len) == 0))
3862 /* Copy this symbol into the list of symbols we are going to
3864 bfd_h_put_8 (output_bfd, type, outsym->e_type);
3865 bfd_h_put_8 (output_bfd, bfd_h_get_8 (input_bfd, sym->e_other),
3867 bfd_h_put_16 (output_bfd, bfd_h_get_16 (input_bfd, sym->e_desc),
3869 if (! finfo->info->keep_memory)
3871 /* name points into a string table which we are going to
3872 free. If there is a hash table entry, use that string.
3873 Otherwise, copy name into memory. */
3874 if (h != (struct aout_link_hash_entry *) NULL)
3875 name = (*sym_hash)->root.root.string;
3880 n = bfd_alloc (output_bfd, strlen (name) + 1);
3885 PUT_WORD (output_bfd,
3886 add_to_stringtab (output_bfd, name, &finfo->strtab),
3888 PUT_WORD (output_bfd, val, outsym->e_value);
3889 *symbol_map = obj_aout_external_sym_count (output_bfd);
3890 ++obj_aout_external_sym_count (output_bfd);
3894 /* Write out the output symbols we have just constructed. */
3895 if (outsym > output_syms)
3897 bfd_size_type outsym_count;
3899 if (bfd_seek (output_bfd, finfo->symoff, SEEK_SET) != 0)
3901 outsym_count = outsym - output_syms;
3902 if (bfd_write ((PTR) output_syms, (bfd_size_type) EXTERNAL_NLIST_SIZE,
3903 (bfd_size_type) outsym_count, output_bfd)
3904 != outsym_count * EXTERNAL_NLIST_SIZE)
3906 finfo->symoff += outsym_count * EXTERNAL_NLIST_SIZE;
3909 if (output_syms != NULL)
3913 if (output_syms != NULL)
3918 /* Write out a symbol that was not associated with an a.out input
3922 aout_link_write_other_symbol (h, data)
3923 struct aout_link_hash_entry *h;
3926 struct aout_final_link_info *finfo = (struct aout_final_link_info *) data;
3930 struct external_nlist outsym;
3932 if (h->root.written)
3935 h->root.written = true;
3937 if (finfo->info->strip == strip_all
3938 || (finfo->info->strip == strip_some
3939 && bfd_hash_lookup (finfo->info->keep_hash, h->root.root.string,
3940 false, false) == NULL))
3943 output_bfd = finfo->output_bfd;
3945 switch (h->root.type)
3948 case bfd_link_hash_new:
3950 /* Avoid variable not initialized warnings. */
3952 case bfd_link_hash_undefined:
3953 type = N_UNDF | N_EXT;
3956 case bfd_link_hash_defined:
3960 sec = h->root.u.def.section;
3961 BFD_ASSERT (sec == &bfd_abs_section
3962 || sec->owner == output_bfd);
3963 if (sec == obj_textsec (output_bfd))
3964 type = N_TEXT | N_EXT;
3965 else if (sec == obj_datasec (output_bfd))
3966 type = N_DATA | N_EXT;
3967 else if (sec == obj_bsssec (output_bfd))
3968 type = N_BSS | N_EXT;
3970 type = N_ABS | N_EXT;
3971 val = (h->root.u.def.value
3972 + sec->output_section->vma
3973 + sec->output_offset);
3976 case bfd_link_hash_common:
3977 type = N_UNDF | N_EXT;
3978 val = h->root.u.c.size;
3980 case bfd_link_hash_indirect:
3981 case bfd_link_hash_warning:
3982 /* FIXME: Ignore these for now. The circumstances under which
3983 they should be written out are not clear to me. */
3987 bfd_h_put_8 (output_bfd, type, outsym.e_type);
3988 bfd_h_put_8 (output_bfd, 0, outsym.e_other);
3989 bfd_h_put_16 (output_bfd, 0, outsym.e_desc);
3990 PUT_WORD (output_bfd,
3991 add_to_stringtab (output_bfd, h->root.root.string, &finfo->strtab),
3993 PUT_WORD (output_bfd, val, outsym.e_value);
3995 if (bfd_seek (output_bfd, finfo->symoff, SEEK_SET) != 0
3996 || bfd_write ((PTR) &outsym, (bfd_size_type) EXTERNAL_NLIST_SIZE,
3997 (bfd_size_type) 1, output_bfd) != EXTERNAL_NLIST_SIZE)
3999 /* FIXME: No way to handle errors. */
4003 finfo->symoff += EXTERNAL_NLIST_SIZE;
4004 h->indx = obj_aout_external_sym_count (output_bfd);
4005 ++obj_aout_external_sym_count (output_bfd);
4010 /* Link an a.out section into the output file. */
4013 aout_link_input_section (finfo, input_bfd, input_section, reloff_ptr,
4014 rel_size, symbol_map)
4015 struct aout_final_link_info *finfo;
4017 asection *input_section;
4018 file_ptr *reloff_ptr;
4019 bfd_size_type rel_size;
4022 bfd_size_type input_size;
4023 bfd_byte *contents = NULL;
4026 /* Get the section contents. */
4027 input_size = bfd_section_size (input_bfd, input_section);
4028 contents = (bfd_byte *) malloc (input_size);
4029 if (contents == NULL && input_size != 0)
4031 bfd_set_error (bfd_error_no_memory);
4034 if (! bfd_get_section_contents (input_bfd, input_section, (PTR) contents,
4035 (file_ptr) 0, input_size))
4038 /* Read in the relocs. */
4039 relocs = (PTR) malloc (rel_size);
4040 if (relocs == NULL && rel_size != 0)
4042 bfd_set_error (bfd_error_no_memory);
4045 if (bfd_seek (input_bfd, input_section->rel_filepos, SEEK_SET) != 0
4046 || bfd_read (relocs, 1, rel_size, input_bfd) != rel_size)
4049 /* Relocate the section contents. */
4050 if (obj_reloc_entry_size (input_bfd) == RELOC_STD_SIZE)
4052 if (! aout_link_input_section_std (finfo, input_bfd, input_section,
4053 (struct reloc_std_external *) relocs,
4054 rel_size, contents, symbol_map))
4059 if (! aout_link_input_section_ext (finfo, input_bfd, input_section,
4060 (struct reloc_ext_external *) relocs,
4061 rel_size, contents, symbol_map))
4065 /* Write out the section contents. */
4066 if (! bfd_set_section_contents (finfo->output_bfd,
4067 input_section->output_section,
4069 input_section->output_offset,
4073 /* If we are producing relocateable output, the relocs were
4074 modified, and we now write them out. */
4075 if (finfo->info->relocateable)
4077 if (bfd_seek (finfo->output_bfd, *reloff_ptr, SEEK_SET) != 0)
4079 if (bfd_write (relocs, (bfd_size_type) 1, rel_size, finfo->output_bfd)
4082 *reloff_ptr += rel_size;
4084 /* Assert that the relocs have not run into the symbols, and
4085 that if these are the text relocs they have not run into the
4087 BFD_ASSERT (*reloff_ptr <= obj_sym_filepos (finfo->output_bfd)
4088 && (reloff_ptr != &finfo->treloff
4090 <= obj_datasec (finfo->output_bfd)->rel_filepos)));
4095 if (contents != NULL)
4101 if (contents != NULL)
4106 /* Get the section corresponding to a reloc index. */
4108 static INLINE asection *
4109 aout_reloc_index_to_section (abfd, indx)
4113 switch (indx & N_TYPE)
4116 return obj_textsec (abfd);
4118 return obj_datasec (abfd);
4120 return obj_bsssec (abfd);
4123 return &bfd_abs_section;
4129 /* Relocate an a.out section using standard a.out relocs. */
4132 aout_link_input_section_std (finfo, input_bfd, input_section, relocs,
4133 rel_size, contents, symbol_map)
4134 struct aout_final_link_info *finfo;
4136 asection *input_section;
4137 struct reloc_std_external *relocs;
4138 bfd_size_type rel_size;
4143 boolean relocateable;
4144 struct external_nlist *syms;
4146 struct aout_link_hash_entry **sym_hashes;
4147 bfd_size_type reloc_count;
4148 register struct reloc_std_external *rel;
4149 struct reloc_std_external *rel_end;
4151 output_bfd = finfo->output_bfd;
4153 BFD_ASSERT (obj_reloc_entry_size (input_bfd) == RELOC_STD_SIZE);
4154 BFD_ASSERT (input_bfd->xvec->header_byteorder_big_p
4155 == output_bfd->xvec->header_byteorder_big_p);
4157 relocateable = finfo->info->relocateable;
4158 syms = obj_aout_external_syms (input_bfd);
4159 strings = obj_aout_external_strings (input_bfd);
4160 sym_hashes = obj_aout_sym_hashes (input_bfd);
4162 reloc_count = rel_size / RELOC_STD_SIZE;
4164 rel_end = rel + reloc_count;
4165 for (; rel < rel_end; rel++)
4177 bfd_reloc_status_type r;
4179 r_addr = GET_SWORD (input_bfd, rel->r_address);
4181 if (input_bfd->xvec->header_byteorder_big_p)
4183 r_index = ((rel->r_index[0] << 16)
4184 | (rel->r_index[1] << 8)
4186 r_extern = (0 != (rel->r_type[0] & RELOC_STD_BITS_EXTERN_BIG));
4187 r_pcrel = (0 != (rel->r_type[0] & RELOC_STD_BITS_PCREL_BIG));
4188 r_baserel = (0 != (rel->r_type[0] & RELOC_STD_BITS_BASEREL_BIG));
4189 r_jmptable= (0 != (rel->r_type[0] & RELOC_STD_BITS_JMPTABLE_BIG));
4190 r_relative= (0 != (rel->r_type[0] & RELOC_STD_BITS_RELATIVE_BIG));
4191 r_length = ((rel->r_type[0] & RELOC_STD_BITS_LENGTH_BIG)
4192 >> RELOC_STD_BITS_LENGTH_SH_BIG);
4196 r_index = ((rel->r_index[2] << 16)
4197 | (rel->r_index[1] << 8)
4199 r_extern = (0 != (rel->r_type[0] & RELOC_STD_BITS_EXTERN_LITTLE));
4200 r_pcrel = (0 != (rel->r_type[0] & RELOC_STD_BITS_PCREL_LITTLE));
4201 r_baserel = (0 != (rel->r_type[0] & RELOC_STD_BITS_BASEREL_LITTLE));
4202 r_jmptable= (0 != (rel->r_type[0] & RELOC_STD_BITS_JMPTABLE_LITTLE));
4203 r_relative= (0 != (rel->r_type[0] & RELOC_STD_BITS_RELATIVE_LITTLE));
4204 r_length = ((rel->r_type[0] & RELOC_STD_BITS_LENGTH_LITTLE)
4205 >> RELOC_STD_BITS_LENGTH_SH_LITTLE);
4208 howto_idx = r_length + 4 * r_pcrel + 8 * r_baserel;
4209 BFD_ASSERT (howto_idx < TABLE_SIZE (howto_table_std));
4210 BFD_ASSERT (r_jmptable == 0);
4211 BFD_ASSERT (r_relative == 0);
4215 /* We are generating a relocateable output file, and must
4216 modify the reloc accordingly. */
4219 struct aout_link_hash_entry *h;
4221 /* If we know the symbol this relocation is against,
4222 convert it into a relocation against a section. This
4223 is what the native linker does. */
4224 h = sym_hashes[r_index];
4225 if (h != (struct aout_link_hash_entry *) NULL
4226 && h->root.type == bfd_link_hash_defined)
4228 asection *output_section;
4230 /* Change the r_extern value. */
4231 if (output_bfd->xvec->header_byteorder_big_p)
4232 rel->r_type[0] &=~ RELOC_STD_BITS_EXTERN_BIG;
4234 rel->r_type[0] &=~ RELOC_STD_BITS_EXTERN_LITTLE;
4236 /* Compute a new r_index. */
4237 output_section = h->root.u.def.section->output_section;
4238 if (output_section == obj_textsec (output_bfd))
4240 else if (output_section == obj_datasec (output_bfd))
4242 else if (output_section == obj_bsssec (output_bfd))
4247 /* Add the symbol value and the section VMA to the
4248 addend stored in the contents. */
4249 relocation = (h->root.u.def.value
4250 + output_section->vma
4251 + h->root.u.def.section->output_offset);
4255 /* We must change r_index according to the symbol
4257 r_index = symbol_map[r_index];
4263 name = strings + GET_WORD (input_bfd,
4264 syms[r_index].e_strx);
4265 if (! ((*finfo->info->callbacks->unattached_reloc)
4266 (finfo->info, name, input_bfd, input_section,
4275 /* Write out the new r_index value. */
4276 if (output_bfd->xvec->header_byteorder_big_p)
4278 rel->r_index[0] = r_index >> 16;
4279 rel->r_index[1] = r_index >> 8;
4280 rel->r_index[2] = r_index;
4284 rel->r_index[2] = r_index >> 16;
4285 rel->r_index[1] = r_index >> 8;
4286 rel->r_index[0] = r_index;
4293 /* This is a relocation against a section. We must
4294 adjust by the amount that the section moved. */
4295 section = aout_reloc_index_to_section (input_bfd, r_index);
4296 relocation = (section->output_section->vma
4297 + section->output_offset
4301 /* Change the address of the relocation. */
4302 PUT_WORD (output_bfd,
4303 r_addr + input_section->output_offset,
4306 /* Adjust a PC relative relocation by removing the reference
4307 to the original address in the section and including the
4308 reference to the new address. */
4310 relocation -= (input_section->output_section->vma
4311 + input_section->output_offset
4312 - input_section->vma);
4314 if (relocation == 0)
4317 r = _bfd_relocate_contents (howto_table_std + howto_idx,
4318 input_bfd, relocation,
4323 /* We are generating an executable, and must do a full
4327 struct aout_link_hash_entry *h;
4329 h = sym_hashes[r_index];
4330 if (h != (struct aout_link_hash_entry *) NULL
4331 && h->root.type == bfd_link_hash_defined)
4333 relocation = (h->root.u.def.value
4334 + h->root.u.def.section->output_section->vma
4335 + h->root.u.def.section->output_offset);
4341 name = strings + GET_WORD (input_bfd, syms[r_index].e_strx);
4342 if (! ((*finfo->info->callbacks->undefined_symbol)
4343 (finfo->info, name, input_bfd, input_section,
4353 section = aout_reloc_index_to_section (input_bfd, r_index);
4354 relocation = (section->output_section->vma
4355 + section->output_offset
4358 relocation += input_section->vma;
4361 r = _bfd_final_link_relocate (howto_table_std + howto_idx,
4362 input_bfd, input_section,
4363 contents, r_addr, relocation,
4367 if (r != bfd_reloc_ok)
4372 case bfd_reloc_outofrange:
4374 case bfd_reloc_overflow:
4379 name = strings + GET_WORD (input_bfd,
4380 syms[r_index].e_strx);
4385 s = aout_reloc_index_to_section (input_bfd, r_index);
4386 name = bfd_section_name (input_bfd, s);
4388 if (! ((*finfo->info->callbacks->reloc_overflow)
4389 (finfo->info, name, howto_table_std[howto_idx].name,
4390 (bfd_vma) 0, input_bfd, input_section, r_addr)))
4401 /* Relocate an a.out section using extended a.out relocs. */
4404 aout_link_input_section_ext (finfo, input_bfd, input_section, relocs,
4405 rel_size, contents, symbol_map)
4406 struct aout_final_link_info *finfo;
4408 asection *input_section;
4409 struct reloc_ext_external *relocs;
4410 bfd_size_type rel_size;
4415 boolean relocateable;
4416 struct external_nlist *syms;
4418 struct aout_link_hash_entry **sym_hashes;
4419 bfd_size_type reloc_count;
4420 register struct reloc_ext_external *rel;
4421 struct reloc_ext_external *rel_end;
4423 output_bfd = finfo->output_bfd;
4425 BFD_ASSERT (obj_reloc_entry_size (input_bfd) == RELOC_EXT_SIZE);
4426 BFD_ASSERT (input_bfd->xvec->header_byteorder_big_p
4427 == output_bfd->xvec->header_byteorder_big_p);
4429 relocateable = finfo->info->relocateable;
4430 syms = obj_aout_external_syms (input_bfd);
4431 strings = obj_aout_external_strings (input_bfd);
4432 sym_hashes = obj_aout_sym_hashes (input_bfd);
4434 reloc_count = rel_size / RELOC_EXT_SIZE;
4436 rel_end = rel + reloc_count;
4437 for (; rel < rel_end; rel++)
4446 r_addr = GET_SWORD (input_bfd, rel->r_address);
4448 if (input_bfd->xvec->header_byteorder_big_p)
4450 r_index = ((rel->r_index[0] << 16)
4451 | (rel->r_index[1] << 8)
4453 r_extern = (0 != (rel->r_type[0] & RELOC_EXT_BITS_EXTERN_BIG));
4454 r_type = ((rel->r_type[0] & RELOC_EXT_BITS_TYPE_BIG)
4455 >> RELOC_EXT_BITS_TYPE_SH_BIG);
4459 r_index = ((rel->r_index[2] << 16)
4460 | (rel->r_index[1] << 8)
4462 r_extern = (0 != (rel->r_type[0] & RELOC_EXT_BITS_EXTERN_LITTLE));
4463 r_type = ((rel->r_type[0] & RELOC_EXT_BITS_TYPE_LITTLE)
4464 >> RELOC_EXT_BITS_TYPE_SH_LITTLE);
4467 r_addend = GET_SWORD (input_bfd, rel->r_addend);
4469 BFD_ASSERT (r_type >= 0
4470 && r_type < TABLE_SIZE (howto_table_ext));
4474 /* We are generating a relocateable output file, and must
4475 modify the reloc accordingly. */
4478 struct aout_link_hash_entry *h;
4480 /* If we know the symbol this relocation is against,
4481 convert it into a relocation against a section. This
4482 is what the native linker does. */
4483 h = sym_hashes[r_index];
4484 if (h != (struct aout_link_hash_entry *) NULL
4485 && h->root.type == bfd_link_hash_defined)
4487 asection *output_section;
4489 /* Change the r_extern value. */
4490 if (output_bfd->xvec->header_byteorder_big_p)
4491 rel->r_type[0] &=~ RELOC_EXT_BITS_EXTERN_BIG;
4493 rel->r_type[0] &=~ RELOC_EXT_BITS_EXTERN_LITTLE;
4495 /* Compute a new r_index. */
4496 output_section = h->root.u.def.section->output_section;
4497 if (output_section == obj_textsec (output_bfd))
4499 else if (output_section == obj_datasec (output_bfd))
4501 else if (output_section == obj_bsssec (output_bfd))
4506 /* Add the symbol value and the section VMA to the
4508 relocation = (h->root.u.def.value
4509 + output_section->vma
4510 + h->root.u.def.section->output_offset);
4512 /* Now RELOCATION is the VMA of the final
4513 destination. If this is a PC relative reloc,
4514 then ADDEND is the negative of the source VMA.
4515 We want to set ADDEND to the difference between
4516 the destination VMA and the source VMA, which
4517 means we must adjust RELOCATION by the change in
4518 the source VMA. This is done below. */
4522 /* We must change r_index according to the symbol
4524 r_index = symbol_map[r_index];
4531 + GET_WORD (input_bfd, syms[r_index].e_strx));
4532 if (! ((*finfo->info->callbacks->unattached_reloc)
4533 (finfo->info, name, input_bfd, input_section,
4541 /* If this is a PC relative reloc, then the addend
4542 is the negative of the source VMA. We must
4543 adjust it by the change in the source VMA. This
4547 /* Write out the new r_index value. */
4548 if (output_bfd->xvec->header_byteorder_big_p)
4550 rel->r_index[0] = r_index >> 16;
4551 rel->r_index[1] = r_index >> 8;
4552 rel->r_index[2] = r_index;
4556 rel->r_index[2] = r_index >> 16;
4557 rel->r_index[1] = r_index >> 8;
4558 rel->r_index[0] = r_index;
4565 /* This is a relocation against a section. We must
4566 adjust by the amount that the section moved. */
4567 section = aout_reloc_index_to_section (input_bfd, r_index);
4568 relocation = (section->output_section->vma
4569 + section->output_offset
4572 /* If this is a PC relative reloc, then the addend is
4573 the difference in VMA between the destination and the
4574 source. We have just adjusted for the change in VMA
4575 of the destination, so we must also adjust by the
4576 change in VMA of the source. This is done below. */
4579 /* As described above, we must always adjust a PC relative
4580 reloc by the change in VMA of the source. */
4581 if (howto_table_ext[r_type].pc_relative)
4582 relocation -= (input_section->output_section->vma
4583 + input_section->output_offset
4584 - input_section->vma);
4586 /* Change the addend if necessary. */
4587 if (relocation != 0)
4588 PUT_WORD (output_bfd, r_addend + relocation, rel->r_addend);
4590 /* Change the address of the relocation. */
4591 PUT_WORD (output_bfd,
4592 r_addr + input_section->output_offset,
4597 bfd_reloc_status_type r;
4599 /* We are generating an executable, and must do a full
4603 struct aout_link_hash_entry *h;
4605 h = sym_hashes[r_index];
4606 if (h != (struct aout_link_hash_entry *) NULL
4607 && h->root.type == bfd_link_hash_defined)
4609 relocation = (h->root.u.def.value
4610 + h->root.u.def.section->output_section->vma
4611 + h->root.u.def.section->output_offset);
4617 name = strings + GET_WORD (input_bfd, syms[r_index].e_strx);
4618 if (! ((*finfo->info->callbacks->undefined_symbol)
4619 (finfo->info, name, input_bfd, input_section,
4629 section = aout_reloc_index_to_section (input_bfd, r_index);
4631 /* If this is a PC relative reloc, then R_ADDEND is the
4632 difference between the two vmas, or
4633 old_dest_sec + old_dest_off - (old_src_sec + old_src_off)
4635 old_dest_sec == section->vma
4637 old_src_sec == input_section->vma
4639 old_src_off == r_addr
4641 _bfd_final_link_relocate expects RELOCATION +
4642 R_ADDEND to be the VMA of the destination minus
4643 r_addr (the minus r_addr is because this relocation
4644 is not pcrel_offset, which is a bit confusing and
4645 should, perhaps, be changed), or
4648 new_dest_sec == output_section->vma + output_offset
4649 We arrange for this to happen by setting RELOCATION to
4650 new_dest_sec + old_src_sec - old_dest_sec
4652 If this is not a PC relative reloc, then R_ADDEND is
4653 simply the VMA of the destination, so we set
4654 RELOCATION to the change in the destination VMA, or
4655 new_dest_sec - old_dest_sec
4657 relocation = (section->output_section->vma
4658 + section->output_offset
4660 if (howto_table_ext[r_type].pc_relative)
4661 relocation += input_section->vma;
4664 r = _bfd_final_link_relocate (howto_table_ext + r_type,
4665 input_bfd, input_section,
4666 contents, r_addr, relocation,
4668 if (r != bfd_reloc_ok)
4673 case bfd_reloc_outofrange:
4675 case bfd_reloc_overflow:
4680 name = strings + GET_WORD (input_bfd,
4681 syms[r_index].e_strx);
4686 s = aout_reloc_index_to_section (input_bfd, r_index);
4687 name = bfd_section_name (input_bfd, s);
4689 if (! ((*finfo->info->callbacks->reloc_overflow)
4690 (finfo->info, name, howto_table_ext[r_type].name,
4691 r_addend, input_bfd, input_section, r_addr)))
4703 /* Handle a link order which is supposed to generate a reloc. */
4706 aout_link_reloc_link_order (finfo, o, p)
4707 struct aout_final_link_info *finfo;
4709 struct bfd_link_order *p;
4711 struct bfd_link_order_reloc *pr;
4714 const reloc_howto_type *howto;
4715 file_ptr *reloff_ptr;
4716 struct reloc_std_external srel;
4717 struct reloc_ext_external erel;
4722 if (p->type == bfd_section_reloc_link_order)
4725 if (pr->u.section == &bfd_abs_section)
4726 r_index = N_ABS | N_EXT;
4729 BFD_ASSERT (pr->u.section->owner == finfo->output_bfd);
4730 r_index = pr->u.section->target_index;
4735 struct aout_link_hash_entry *h;
4737 BFD_ASSERT (p->type == bfd_symbol_reloc_link_order);
4739 h = aout_link_hash_lookup (aout_hash_table (finfo->info),
4740 pr->u.name, false, false, true);
4741 if (h != (struct aout_link_hash_entry *) NULL
4746 if (! ((*finfo->info->callbacks->unattached_reloc)
4747 (finfo->info, pr->u.name, (bfd *) NULL,
4748 (asection *) NULL, (bfd_vma) 0)))
4754 howto = bfd_reloc_type_lookup (finfo->output_bfd, pr->reloc);
4755 if (howto == (const reloc_howto_type *) NULL)
4757 bfd_set_error (bfd_error_bad_value);
4761 if (o == obj_textsec (finfo->output_bfd))
4762 reloff_ptr = &finfo->treloff;
4763 else if (o == obj_datasec (finfo->output_bfd))
4764 reloff_ptr = &finfo->dreloff;
4768 if (obj_reloc_entry_size (finfo->output_bfd) == RELOC_STD_SIZE)
4776 r_pcrel = howto->pc_relative;
4777 r_baserel = (howto->type & 8) != 0;
4780 r_length = howto->size;
4782 PUT_WORD (finfo->output_bfd, p->offset, srel.r_address);
4783 if (finfo->output_bfd->xvec->header_byteorder_big_p)
4785 srel.r_index[0] = r_index >> 16;
4786 srel.r_index[1] = r_index >> 8;
4787 srel.r_index[2] = r_index;
4789 ((r_extern ? RELOC_STD_BITS_EXTERN_BIG : 0)
4790 | (r_pcrel ? RELOC_STD_BITS_PCREL_BIG : 0)
4791 | (r_baserel ? RELOC_STD_BITS_BASEREL_BIG : 0)
4792 | (r_jmptable ? RELOC_STD_BITS_JMPTABLE_BIG : 0)
4793 | (r_relative ? RELOC_STD_BITS_RELATIVE_BIG : 0)
4794 | (r_length << RELOC_STD_BITS_LENGTH_SH_BIG));
4798 srel.r_index[2] = r_index >> 16;
4799 srel.r_index[1] = r_index >> 8;
4800 srel.r_index[0] = r_index;
4802 ((r_extern ? RELOC_STD_BITS_EXTERN_LITTLE : 0)
4803 | (r_pcrel ? RELOC_STD_BITS_PCREL_LITTLE : 0)
4804 | (r_baserel ? RELOC_STD_BITS_BASEREL_LITTLE : 0)
4805 | (r_jmptable ? RELOC_STD_BITS_JMPTABLE_LITTLE : 0)
4806 | (r_relative ? RELOC_STD_BITS_RELATIVE_LITTLE : 0)
4807 | (r_length << RELOC_STD_BITS_LENGTH_SH_LITTLE));
4810 rel_ptr = (PTR) &srel;
4812 /* We have to write the addend into the object file, since
4813 standard a.out relocs are in place. It would be more
4814 reliable if we had the current contents of the file here,
4815 rather than assuming zeroes, but we can't read the file since
4816 it was opened using bfd_openw. */
4817 if (pr->addend != 0)
4820 bfd_reloc_status_type r;
4824 size = bfd_get_reloc_size (howto);
4825 buf = (bfd_byte*) bfd_zmalloc (size);
4826 if (buf == (bfd_byte *) NULL)
4828 bfd_set_error (bfd_error_no_memory);
4831 r = _bfd_relocate_contents (howto, finfo->output_bfd,
4838 case bfd_reloc_outofrange:
4840 case bfd_reloc_overflow:
4841 if (! ((*finfo->info->callbacks->reloc_overflow)
4843 (p->type == bfd_section_reloc_link_order
4844 ? bfd_section_name (finfo->output_bfd,
4847 howto->name, pr->addend, (bfd *) NULL,
4848 (asection *) NULL, (bfd_vma) 0)))
4855 ok = bfd_set_section_contents (finfo->output_bfd, o,
4857 (file_ptr) p->offset,
4866 PUT_WORD (finfo->output_bfd, p->offset, erel.r_address);
4868 if (finfo->output_bfd->xvec->header_byteorder_big_p)
4870 erel.r_index[0] = r_index >> 16;
4871 erel.r_index[1] = r_index >> 8;
4872 erel.r_index[2] = r_index;
4874 ((r_extern ? RELOC_EXT_BITS_EXTERN_BIG : 0)
4875 | (howto->type << RELOC_EXT_BITS_TYPE_SH_BIG));
4879 erel.r_index[2] = r_index >> 16;
4880 erel.r_index[1] = r_index >> 8;
4881 erel.r_index[0] = r_index;
4883 (r_extern ? RELOC_EXT_BITS_EXTERN_LITTLE : 0)
4884 | (howto->type << RELOC_EXT_BITS_TYPE_SH_LITTLE);
4887 PUT_WORD (finfo->output_bfd, pr->addend, erel.r_addend);
4889 rel_ptr = (PTR) &erel;
4892 if (bfd_seek (finfo->output_bfd, *reloff_ptr, SEEK_SET) != 0
4893 || (bfd_write (rel_ptr, (bfd_size_type) 1,
4894 obj_reloc_entry_size (finfo->output_bfd),
4896 != obj_reloc_entry_size (finfo->output_bfd)))
4899 *reloff_ptr += obj_reloc_entry_size (finfo->output_bfd);
4901 /* Assert that the relocs have not run into the symbols, and that n
4902 the text relocs have not run into the data relocs. */
4903 BFD_ASSERT (*reloff_ptr <= obj_sym_filepos (finfo->output_bfd)
4904 && (reloff_ptr != &finfo->treloff
4906 <= obj_datasec (finfo->output_bfd)->rel_filepos)));