source: vendor/binutils/current/bfd/aoutx.h

Last change on this file was 609, checked in by bird, 22 years ago

binutils v2.14 - offical sources.

  • Property cvs2svn:cvs-rev set to 1.1.1.2
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 167.8 KB
Line 
1/* BFD semi-generic back-end for a.out binaries.
2 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2000,
3 2001, 2002, 2003
4 Free Software Foundation, Inc.
5 Written by Cygnus Support.
6
7 This file is part of BFD, the Binary File Descriptor library.
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22
23/*
24SECTION
25 a.out backends
26
27DESCRIPTION
28
29 BFD supports a number of different flavours of a.out format,
30 though the major differences are only the sizes of the
31 structures on disk, and the shape of the relocation
32 information.
33
34 The support is split into a basic support file @file{aoutx.h}
35 and other files which derive functions from the base. One
36 derivation file is @file{aoutf1.h} (for a.out flavour 1), and
37 adds to the basic a.out functions support for sun3, sun4, 386
38 and 29k a.out files, to create a target jump vector for a
39 specific target.
40
41 This information is further split out into more specific files
42 for each machine, including @file{sunos.c} for sun3 and sun4,
43 @file{newsos3.c} for the Sony NEWS, and @file{demo64.c} for a
44 demonstration of a 64 bit a.out format.
45
46 The base file @file{aoutx.h} defines general mechanisms for
47 reading and writing records to and from disk and various
48 other methods which BFD requires. It is included by
49 @file{aout32.c} and @file{aout64.c} to form the names
50 <<aout_32_swap_exec_header_in>>, <<aout_64_swap_exec_header_in>>, etc.
51
52 As an example, this is what goes on to make the back end for a
53 sun4, from @file{aout32.c}:
54
55| #define ARCH_SIZE 32
56| #include "aoutx.h"
57
58 Which exports names:
59
60| ...
61| aout_32_canonicalize_reloc
62| aout_32_find_nearest_line
63| aout_32_get_lineno
64| aout_32_get_reloc_upper_bound
65| ...
66
67 from @file{sunos.c}:
68
69| #define TARGET_NAME "a.out-sunos-big"
70| #define VECNAME sunos_big_vec
71| #include "aoutf1.h"
72
73 requires all the names from @file{aout32.c}, and produces the jump vector
74
75| sunos_big_vec
76
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
85 the object file.
86
87 When porting it to run on a new system, you must supply:
88
89| HOST_PAGE_SIZE
90| HOST_SEGMENT_SIZE
91| HOST_MACHINE_ARCH (optional)
92| HOST_MACHINE_MACHINE (optional)
93| HOST_TEXT_START_ADDR
94| HOST_STACK_END_ADDR
95
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:
101
102| TDEFAULTS = -DDEFAULT_VECTOR=host_aout_big_vec
103| TDEPFILES= host-aout.o trad-core.o
104
105 in the @file{config/@var{XXX}.mt} file, and modify @file{configure.in}
106 to use the
107 @file{@var{XXX}.mt} file (by setting "<<bfd_target=XXX>>") when your
108 configuration is selected. */
109
110/* Some assumptions:
111 * Any BFD with D_PAGED set is ZMAGIC, and vice versa.
112 Doesn't matter what the setting of WP_TEXT is on output, but it'll
113 get set on input.
114 * Any BFD with D_PAGED clear and WP_TEXT set is NMAGIC.
115 * Any BFD with both flags clear is OMAGIC.
116 (Just want to make these explicit, so the conditions tested in this
117 file make sense if you're more familiar with a.out than with BFD.) */
118
119#define KEEPIT udata.i
120
121#include "bfd.h"
122#include "sysdep.h"
123#include "safe-ctype.h"
124#include "bfdlink.h"
125
126#include "libaout.h"
127#include "libbfd.h"
128#include "aout/aout64.h"
129#include "aout/stab_gnu.h"
130#include "aout/ar.h"
131
132static bfd_boolean aout_get_external_symbols
133 PARAMS ((bfd *));
134static bfd_boolean translate_from_native_sym_flags
135 PARAMS ((bfd *, aout_symbol_type *));
136static bfd_boolean translate_to_native_sym_flags
137 PARAMS ((bfd *, asymbol *, struct external_nlist *));
138static void adjust_o_magic
139 PARAMS ((bfd *, struct internal_exec *));
140static void adjust_z_magic
141 PARAMS ((bfd *, struct internal_exec *));
142static void adjust_n_magic
143 PARAMS ((bfd *, struct internal_exec *));
144reloc_howto_type * NAME(aout,reloc_type_lookup)
145 PARAMS ((bfd *, bfd_reloc_code_real_type));
146
147/*
148SUBSECTION
149 Relocations
150
151DESCRIPTION
152 The file @file{aoutx.h} provides for both the @emph{standard}
153 and @emph{extended} forms of a.out relocation records.
154
155 The standard records contain only an
156 address, a symbol index, and a type field. The extended records
157 (used on 29ks and sparcs) also have a full integer for an
158 addend. */
159
160#ifndef CTOR_TABLE_RELOC_HOWTO
161#define CTOR_TABLE_RELOC_IDX 2
162#define CTOR_TABLE_RELOC_HOWTO(BFD) \
163 ((obj_reloc_entry_size (BFD) == RELOC_EXT_SIZE \
164 ? howto_table_ext : howto_table_std) \
165 + CTOR_TABLE_RELOC_IDX)
166#endif
167
168#ifndef MY_swap_std_reloc_in
169#define MY_swap_std_reloc_in NAME(aout,swap_std_reloc_in)
170#endif
171
172#ifndef MY_swap_ext_reloc_in
173#define MY_swap_ext_reloc_in NAME(aout,swap_ext_reloc_in)
174#endif
175
176#ifndef MY_swap_std_reloc_out
177#define MY_swap_std_reloc_out NAME(aout,swap_std_reloc_out)
178#endif
179
180#ifndef MY_swap_ext_reloc_out
181#define MY_swap_ext_reloc_out NAME(aout,swap_ext_reloc_out)
182#endif
183
184#ifndef MY_final_link_relocate
185#define MY_final_link_relocate _bfd_final_link_relocate
186#endif
187
188#ifndef MY_relocate_contents
189#define MY_relocate_contents _bfd_relocate_contents
190#endif
191
192#define howto_table_ext NAME(aout,ext_howto_table)
193#define howto_table_std NAME(aout,std_howto_table)
194
195reloc_howto_type howto_table_ext[] =
196{
197 /* type rs size bsz pcrel bitpos ovrf sf name part_inpl readmask setmask pcdone. */
198 HOWTO(RELOC_8, 0, 0, 8, FALSE, 0, complain_overflow_bitfield,0,"8", FALSE, 0,0x000000ff, FALSE),
199 HOWTO(RELOC_16, 0, 1, 16, FALSE, 0, complain_overflow_bitfield,0,"16", FALSE, 0,0x0000ffff, FALSE),
200 HOWTO(RELOC_32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,0,"32", FALSE, 0,0xffffffff, FALSE),
201 HOWTO(RELOC_DISP8, 0, 0, 8, TRUE, 0, complain_overflow_signed,0,"DISP8", FALSE, 0,0x000000ff, FALSE),
202 HOWTO(RELOC_DISP16, 0, 1, 16, TRUE, 0, complain_overflow_signed,0,"DISP16", FALSE, 0,0x0000ffff, FALSE),
203 HOWTO(RELOC_DISP32, 0, 2, 32, TRUE, 0, complain_overflow_signed,0,"DISP32", FALSE, 0,0xffffffff, FALSE),
204 HOWTO(RELOC_WDISP30,2, 2, 30, TRUE, 0, complain_overflow_signed,0,"WDISP30", FALSE, 0,0x3fffffff, FALSE),
205 HOWTO(RELOC_WDISP22,2, 2, 22, TRUE, 0, complain_overflow_signed,0,"WDISP22", FALSE, 0,0x003fffff, FALSE),
206 HOWTO(RELOC_HI22, 10, 2, 22, FALSE, 0, complain_overflow_bitfield,0,"HI22", FALSE, 0,0x003fffff, FALSE),
207 HOWTO(RELOC_22, 0, 2, 22, FALSE, 0, complain_overflow_bitfield,0,"22", FALSE, 0,0x003fffff, FALSE),
208 HOWTO(RELOC_13, 0, 2, 13, FALSE, 0, complain_overflow_bitfield,0,"13", FALSE, 0,0x00001fff, FALSE),
209 HOWTO(RELOC_LO10, 0, 2, 10, FALSE, 0, complain_overflow_dont,0,"LO10", FALSE, 0,0x000003ff, FALSE),
210 HOWTO(RELOC_SFA_BASE,0, 2, 32, FALSE, 0, complain_overflow_bitfield,0,"SFA_BASE", FALSE, 0,0xffffffff, FALSE),
211 HOWTO(RELOC_SFA_OFF13,0,2, 32, FALSE, 0, complain_overflow_bitfield,0,"SFA_OFF13",FALSE, 0,0xffffffff, FALSE),
212 HOWTO(RELOC_BASE10, 0, 2, 10, FALSE, 0, complain_overflow_dont,0,"BASE10", FALSE, 0,0x000003ff, FALSE),
213 HOWTO(RELOC_BASE13, 0, 2, 13, FALSE, 0, complain_overflow_signed,0,"BASE13", FALSE, 0,0x00001fff, FALSE),
214 HOWTO(RELOC_BASE22, 10, 2, 22, FALSE, 0, complain_overflow_bitfield,0,"BASE22", FALSE, 0,0x003fffff, FALSE),
215 HOWTO(RELOC_PC10, 0, 2, 10, TRUE, 0, complain_overflow_dont,0,"PC10", FALSE, 0,0x000003ff, TRUE),
216 HOWTO(RELOC_PC22, 10, 2, 22, TRUE, 0, complain_overflow_signed,0,"PC22", FALSE, 0,0x003fffff, TRUE),
217 HOWTO(RELOC_JMP_TBL,2, 2, 30, TRUE, 0, complain_overflow_signed,0,"JMP_TBL", FALSE, 0,0x3fffffff, FALSE),
218 HOWTO(RELOC_SEGOFF16,0, 2, 0, FALSE, 0, complain_overflow_bitfield,0,"SEGOFF16", FALSE, 0,0x00000000, FALSE),
219 HOWTO(RELOC_GLOB_DAT,0, 2, 0, FALSE, 0, complain_overflow_bitfield,0,"GLOB_DAT", FALSE, 0,0x00000000, FALSE),
220 HOWTO(RELOC_JMP_SLOT,0, 2, 0, FALSE, 0, complain_overflow_bitfield,0,"JMP_SLOT", FALSE, 0,0x00000000, FALSE),
221 HOWTO(RELOC_RELATIVE,0, 2, 0, FALSE, 0, complain_overflow_bitfield,0,"RELATIVE", FALSE, 0,0x00000000, FALSE),
222 HOWTO(0, 0, 0, 0, FALSE, 0, complain_overflow_dont, 0, "R_SPARC_NONE", FALSE,0,0x00000000,TRUE),
223 HOWTO(0, 0, 0, 0, FALSE, 0, complain_overflow_dont, 0, "R_SPARC_NONE", FALSE,0,0x00000000,TRUE),
224#define RELOC_SPARC_REV32 RELOC_WDISP19
225 HOWTO(RELOC_SPARC_REV32, 0, 2, 32, FALSE, 0, complain_overflow_dont,0,"R_SPARC_REV32", FALSE, 0,0xffffffff, FALSE),
226};
227
228/* Convert standard reloc records to "arelent" format (incl byte swap). */
229
230reloc_howto_type howto_table_std[] =
231{
232 /* type rs size bsz pcrel bitpos ovrf sf name part_inpl readmask setmask pcdone. */
233HOWTO ( 0, 0, 0, 8, FALSE, 0, complain_overflow_bitfield,0,"8", TRUE, 0x000000ff,0x000000ff, FALSE),
234HOWTO ( 1, 0, 1, 16, FALSE, 0, complain_overflow_bitfield,0,"16", TRUE, 0x0000ffff,0x0000ffff, FALSE),
235HOWTO ( 2, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,0,"32", TRUE, 0xffffffff,0xffffffff, FALSE),
236HOWTO ( 3, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,0,"64", TRUE, 0xdeaddead,0xdeaddead, FALSE),
237HOWTO ( 4, 0, 0, 8, TRUE, 0, complain_overflow_signed, 0,"DISP8", TRUE, 0x000000ff,0x000000ff, FALSE),
238HOWTO ( 5, 0, 1, 16, TRUE, 0, complain_overflow_signed, 0,"DISP16", TRUE, 0x0000ffff,0x0000ffff, FALSE),
239HOWTO ( 6, 0, 2, 32, TRUE, 0, complain_overflow_signed, 0,"DISP32", TRUE, 0xffffffff,0xffffffff, FALSE),
240HOWTO ( 7, 0, 4, 64, TRUE, 0, complain_overflow_signed, 0,"DISP64", TRUE, 0xfeedface,0xfeedface, FALSE),
241HOWTO ( 8, 0, 2, 0, FALSE, 0, complain_overflow_bitfield,0,"GOT_REL", FALSE, 0,0x00000000, FALSE),
242HOWTO ( 9, 0, 1, 16, FALSE, 0, complain_overflow_bitfield,0,"BASE16", FALSE,0xffffffff,0xffffffff, FALSE),
243HOWTO (10, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,0,"BASE32", FALSE,0xffffffff,0xffffffff, FALSE),
244EMPTY_HOWTO (-1),
245EMPTY_HOWTO (-1),
246EMPTY_HOWTO (-1),
247EMPTY_HOWTO (-1),
248EMPTY_HOWTO (-1),
249 HOWTO (16, 0, 2, 0, FALSE, 0, complain_overflow_bitfield,0,"JMP_TABLE", FALSE, 0,0x00000000, FALSE),
250EMPTY_HOWTO (-1),
251EMPTY_HOWTO (-1),
252EMPTY_HOWTO (-1),
253EMPTY_HOWTO (-1),
254EMPTY_HOWTO (-1),
255EMPTY_HOWTO (-1),
256EMPTY_HOWTO (-1),
257EMPTY_HOWTO (-1),
258EMPTY_HOWTO (-1),
259EMPTY_HOWTO (-1),
260EMPTY_HOWTO (-1),
261EMPTY_HOWTO (-1),
262EMPTY_HOWTO (-1),
263EMPTY_HOWTO (-1),
264EMPTY_HOWTO (-1),
265 HOWTO (32, 0, 2, 0, FALSE, 0, complain_overflow_bitfield,0,"RELATIVE", FALSE, 0,0x00000000, FALSE),
266EMPTY_HOWTO (-1),
267EMPTY_HOWTO (-1),
268EMPTY_HOWTO (-1),
269EMPTY_HOWTO (-1),
270EMPTY_HOWTO (-1),
271EMPTY_HOWTO (-1),
272EMPTY_HOWTO (-1),
273 HOWTO (40, 0, 2, 0, FALSE, 0, complain_overflow_bitfield,0,"BASEREL", FALSE, 0,0x00000000, FALSE),
274};
275
276#define TABLE_SIZE(TABLE) (sizeof (TABLE) / sizeof (TABLE[0]))
277
278reloc_howto_type *
279NAME(aout,reloc_type_lookup) (abfd,code)
280 bfd *abfd;
281 bfd_reloc_code_real_type code;
282{
283#define EXT(i, j) case i: return &howto_table_ext[j]
284#define STD(i, j) case i: return &howto_table_std[j]
285 int ext = obj_reloc_entry_size (abfd) == RELOC_EXT_SIZE;
286
287 if (code == BFD_RELOC_CTOR)
288 switch (bfd_get_arch_info (abfd)->bits_per_address)
289 {
290 case 32:
291 code = BFD_RELOC_32;
292 break;
293 case 64:
294 code = BFD_RELOC_64;
295 break;
296 }
297
298 if (ext)
299 switch (code)
300 {
301 EXT (BFD_RELOC_8, 0);
302 EXT (BFD_RELOC_16, 1);
303 EXT (BFD_RELOC_32, 2);
304 EXT (BFD_RELOC_HI22, 8);
305 EXT (BFD_RELOC_LO10, 11);
306 EXT (BFD_RELOC_32_PCREL_S2, 6);
307 EXT (BFD_RELOC_SPARC_WDISP22, 7);
308 EXT (BFD_RELOC_SPARC13, 10);
309 EXT (BFD_RELOC_SPARC_GOT10, 14);
310 EXT (BFD_RELOC_SPARC_BASE13, 15);
311 EXT (BFD_RELOC_SPARC_GOT13, 15);
312 EXT (BFD_RELOC_SPARC_GOT22, 16);
313 EXT (BFD_RELOC_SPARC_PC10, 17);
314 EXT (BFD_RELOC_SPARC_PC22, 18);
315 EXT (BFD_RELOC_SPARC_WPLT30, 19);
316 EXT (BFD_RELOC_SPARC_REV32, 26);
317 default: return (reloc_howto_type *) NULL;
318 }
319 else
320 /* std relocs. */
321 switch (code)
322 {
323 STD (BFD_RELOC_8, 0);
324 STD (BFD_RELOC_16, 1);
325 STD (BFD_RELOC_32, 2);
326 STD (BFD_RELOC_8_PCREL, 4);
327 STD (BFD_RELOC_16_PCREL, 5);
328 STD (BFD_RELOC_32_PCREL, 6);
329 STD (BFD_RELOC_16_BASEREL, 9);
330 STD (BFD_RELOC_32_BASEREL, 10);
331 default: return (reloc_howto_type *) NULL;
332 }
333}
334
335/*
336SUBSECTION
337 Internal entry points
338
339DESCRIPTION
340 @file{aoutx.h} exports several routines for accessing the
341 contents of an a.out file, which are gathered and exported in
342 turn by various format specific files (eg sunos.c).
343
344*/
345
346/*
347FUNCTION
348 aout_@var{size}_swap_exec_header_in
349
350SYNOPSIS
351 void aout_@var{size}_swap_exec_header_in,
352 (bfd *abfd,
353 struct external_exec *raw_bytes,
354 struct internal_exec *execp);
355
356DESCRIPTION
357 Swap the information in an executable header @var{raw_bytes} taken
358 from a raw byte stream memory image into the internal exec header
359 structure @var{execp}.
360*/
361
362#ifndef NAME_swap_exec_header_in
363void
364NAME(aout,swap_exec_header_in) (abfd, raw_bytes, execp)
365 bfd *abfd;
366 struct external_exec *raw_bytes;
367 struct internal_exec *execp;
368{
369 struct external_exec *bytes = (struct external_exec *)raw_bytes;
370
371 /* The internal_exec structure has some fields that are unused in this
372 configuration (IE for i960), so ensure that all such uninitialized
373 fields are zero'd out. There are places where two of these structs
374 are memcmp'd, and thus the contents do matter. */
375 memset ((PTR) execp, 0, sizeof (struct internal_exec));
376 /* Now fill in fields in the execp, from the bytes in the raw data. */
377 execp->a_info = H_GET_32 (abfd, bytes->e_info);
378 execp->a_text = GET_WORD (abfd, bytes->e_text);
379 execp->a_data = GET_WORD (abfd, bytes->e_data);
380 execp->a_bss = GET_WORD (abfd, bytes->e_bss);
381 execp->a_syms = GET_WORD (abfd, bytes->e_syms);
382 execp->a_entry = GET_WORD (abfd, bytes->e_entry);
383 execp->a_trsize = GET_WORD (abfd, bytes->e_trsize);
384 execp->a_drsize = GET_WORD (abfd, bytes->e_drsize);
385}
386#define NAME_swap_exec_header_in NAME(aout,swap_exec_header_in)
387#endif
388
389/*
390FUNCTION
391 aout_@var{size}_swap_exec_header_out
392
393SYNOPSIS
394 void aout_@var{size}_swap_exec_header_out
395 (bfd *abfd,
396 struct internal_exec *execp,
397 struct external_exec *raw_bytes);
398
399DESCRIPTION
400 Swap the information in an internal exec header structure
401 @var{execp} into the buffer @var{raw_bytes} ready for writing to disk.
402*/
403void
404NAME(aout,swap_exec_header_out) (abfd, execp, raw_bytes)
405 bfd *abfd;
406 struct internal_exec *execp;
407 struct external_exec *raw_bytes;
408{
409 struct external_exec *bytes = (struct external_exec *)raw_bytes;
410
411 /* Now fill in fields in the raw data, from the fields in the exec struct. */
412 H_PUT_32 (abfd, execp->a_info , bytes->e_info);
413 PUT_WORD (abfd, execp->a_text , bytes->e_text);
414 PUT_WORD (abfd, execp->a_data , bytes->e_data);
415 PUT_WORD (abfd, execp->a_bss , bytes->e_bss);
416 PUT_WORD (abfd, execp->a_syms , bytes->e_syms);
417 PUT_WORD (abfd, execp->a_entry , bytes->e_entry);
418 PUT_WORD (abfd, execp->a_trsize, bytes->e_trsize);
419 PUT_WORD (abfd, execp->a_drsize, bytes->e_drsize);
420}
421
422/* Make all the section for an a.out file. */
423
424bfd_boolean
425NAME(aout,make_sections) (abfd)
426 bfd *abfd;
427{
428 if (obj_textsec (abfd) == (asection *) NULL
429 && bfd_make_section (abfd, ".text") == (asection *) NULL)
430 return FALSE;
431 if (obj_datasec (abfd) == (asection *) NULL
432 && bfd_make_section (abfd, ".data") == (asection *) NULL)
433 return FALSE;
434 if (obj_bsssec (abfd) == (asection *) NULL
435 && bfd_make_section (abfd, ".bss") == (asection *) NULL)
436 return FALSE;
437 return TRUE;
438}
439
440/*
441FUNCTION
442 aout_@var{size}_some_aout_object_p
443
444SYNOPSIS
445 const bfd_target *aout_@var{size}_some_aout_object_p
446 (bfd *abfd,
447 const bfd_target *(*callback_to_real_object_p) ());
448
449DESCRIPTION
450 Some a.out variant thinks that the file open in @var{abfd}
451 checking is an a.out file. Do some more checking, and set up
452 for access if it really is. Call back to the calling
453 environment's "finish up" function just before returning, to
454 handle any last-minute setup.
455*/
456
457const bfd_target *
458NAME(aout,some_aout_object_p) (abfd, execp, callback_to_real_object_p)
459 bfd *abfd;
460 struct internal_exec *execp;
461 const bfd_target *(*callback_to_real_object_p) PARAMS ((bfd *));
462{
463 struct aout_data_struct *rawptr, *oldrawptr;
464 const bfd_target *result;
465 bfd_size_type amt = sizeof (struct aout_data_struct);
466
467 rawptr = (struct aout_data_struct *) bfd_zalloc (abfd, amt);
468 if (rawptr == NULL)
469 return 0;
470
471 oldrawptr = abfd->tdata.aout_data;
472 abfd->tdata.aout_data = rawptr;
473
474 /* Copy the contents of the old tdata struct.
475 In particular, we want the subformat, since for hpux it was set in
476 hp300hpux.c:swap_exec_header_in and will be used in
477 hp300hpux.c:callback. */
478 if (oldrawptr != NULL)
479 *abfd->tdata.aout_data = *oldrawptr;
480
481 abfd->tdata.aout_data->a.hdr = &rawptr->e;
482 /* Copy in the internal_exec struct. */
483 *(abfd->tdata.aout_data->a.hdr) = *execp;
484 execp = abfd->tdata.aout_data->a.hdr;
485
486 /* Set the file flags. */
487 abfd->flags = BFD_NO_FLAGS;
488 if (execp->a_drsize || execp->a_trsize)
489 abfd->flags |= HAS_RELOC;
490 /* Setting of EXEC_P has been deferred to the bottom of this function. */
491 if (execp->a_syms)
492 abfd->flags |= HAS_LINENO | HAS_DEBUG | HAS_SYMS | HAS_LOCALS;
493 if (N_DYNAMIC (*execp))
494 abfd->flags |= DYNAMIC;
495
496 if (N_MAGIC (*execp) == ZMAGIC)
497 {
498 abfd->flags |= D_PAGED | WP_TEXT;
499 adata (abfd).magic = z_magic;
500 }
501 else if (N_MAGIC (*execp) == QMAGIC)
502 {
503 abfd->flags |= D_PAGED | WP_TEXT;
504 adata (abfd).magic = z_magic;
505 adata (abfd).subformat = q_magic_format;
506 }
507 else if (N_MAGIC (*execp) == NMAGIC)
508 {
509 abfd->flags |= WP_TEXT;
510 adata (abfd).magic = n_magic;
511 }
512 else if (N_MAGIC (*execp) == OMAGIC
513 || N_MAGIC (*execp) == BMAGIC)
514 adata (abfd).magic = o_magic;
515 else
516 {
517 /* Should have been checked with N_BADMAG before this routine
518 was called. */
519 abort ();
520 }
521
522 bfd_get_start_address (abfd) = execp->a_entry;
523
524 obj_aout_symbols (abfd) = (aout_symbol_type *)NULL;
525 bfd_get_symcount (abfd) = execp->a_syms / sizeof (struct external_nlist);
526
527 /* The default relocation entry size is that of traditional V7 Unix. */
528 obj_reloc_entry_size (abfd) = RELOC_STD_SIZE;
529
530 /* The default symbol entry size is that of traditional Unix. */
531 obj_symbol_entry_size (abfd) = EXTERNAL_NLIST_SIZE;
532
533#ifdef USE_MMAP
534 bfd_init_window (&obj_aout_sym_window (abfd));
535 bfd_init_window (&obj_aout_string_window (abfd));
536#endif
537 obj_aout_external_syms (abfd) = NULL;
538 obj_aout_external_strings (abfd) = NULL;
539 obj_aout_sym_hashes (abfd) = NULL;
540
541 if (! NAME(aout,make_sections) (abfd))
542 goto error_ret;
543
544 obj_datasec (abfd)->_raw_size = execp->a_data;
545 obj_bsssec (abfd)->_raw_size = execp->a_bss;
546
547 obj_textsec (abfd)->flags =
548 (execp->a_trsize != 0
549 ? (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS | SEC_RELOC)
550 : (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS));
551 obj_datasec (abfd)->flags =
552 (execp->a_drsize != 0
553 ? (SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_HAS_CONTENTS | SEC_RELOC)
554 : (SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_HAS_CONTENTS));
555 obj_bsssec (abfd)->flags = SEC_ALLOC;
556
557#ifdef THIS_IS_ONLY_DOCUMENTATION
558 /* The common code can't fill in these things because they depend
559 on either the start address of the text segment, the rounding
560 up of virtual addresses between segments, or the starting file
561 position of the text segment -- all of which varies among different
562 versions of a.out. */
563
564 /* Call back to the format-dependent code to fill in the rest of the
565 fields and do any further cleanup. Things that should be filled
566 in by the callback: */
567
568 struct exec *execp = exec_hdr (abfd);
569
570 obj_textsec (abfd)->size = N_TXTSIZE (*execp);
571 obj_textsec (abfd)->raw_size = N_TXTSIZE (*execp);
572 /* Data and bss are already filled in since they're so standard. */
573
574 /* The virtual memory addresses of the sections. */
575 obj_textsec (abfd)->vma = N_TXTADDR (*execp);
576 obj_datasec (abfd)->vma = N_DATADDR (*execp);
577 obj_bsssec (abfd)->vma = N_BSSADDR (*execp);
578
579 /* The file offsets of the sections. */
580 obj_textsec (abfd)->filepos = N_TXTOFF (*execp);
581 obj_datasec (abfd)->filepos = N_DATOFF (*execp);
582
583 /* The file offsets of the relocation info. */
584 obj_textsec (abfd)->rel_filepos = N_TRELOFF (*execp);
585 obj_datasec (abfd)->rel_filepos = N_DRELOFF (*execp);
586
587 /* The file offsets of the string table and symbol table. */
588 obj_str_filepos (abfd) = N_STROFF (*execp);
589 obj_sym_filepos (abfd) = N_SYMOFF (*execp);
590
591 /* Determine the architecture and machine type of the object file. */
592 switch (N_MACHTYPE (*exec_hdr (abfd)))
593 {
594 default:
595 abfd->obj_arch = bfd_arch_obscure;
596 break;
597 }
598
599 adata (abfd)->page_size = TARGET_PAGE_SIZE;
600 adata (abfd)->segment_size = SEGMENT_SIZE;
601 adata (abfd)->exec_bytes_size = EXEC_BYTES_SIZE;
602
603 return abfd->xvec;
604
605 /* The architecture is encoded in various ways in various a.out variants,
606 or is not encoded at all in some of them. The relocation size depends
607 on the architecture and the a.out variant. Finally, the return value
608 is the bfd_target vector in use. If an error occurs, return zero and
609 set bfd_error to the appropriate error code.
610
611 Formats such as b.out, which have additional fields in the a.out
612 header, should cope with them in this callback as well. */
613#endif /* DOCUMENTATION */
614
615 result = (*callback_to_real_object_p) (abfd);
616
617 /* Now that the segment addresses have been worked out, take a better
618 guess at whether the file is executable. If the entry point
619 is within the text segment, assume it is. (This makes files
620 executable even if their entry point address is 0, as long as
621 their text starts at zero.).
622
623 This test had to be changed to deal with systems where the text segment
624 runs at a different location than the default. The problem is that the
625 entry address can appear to be outside the text segment, thus causing an
626 erroneous conclusion that the file isn't executable.
627
628 To fix this, we now accept any non-zero entry point as an indication of
629 executability. This will work most of the time, since only the linker
630 sets the entry point, and that is likely to be non-zero for most systems. */
631
632 if (execp->a_entry != 0
633 || (execp->a_entry >= obj_textsec (abfd)->vma
634 && execp->a_entry < (obj_textsec (abfd)->vma
635 + obj_textsec (abfd)->_raw_size)))
636 abfd->flags |= EXEC_P;
637#ifdef STAT_FOR_EXEC
638 else
639 {
640 struct stat stat_buf;
641
642 /* The original heuristic doesn't work in some important cases.
643 The a.out file has no information about the text start
644 address. For files (like kernels) linked to non-standard
645 addresses (ld -Ttext nnn) the entry point may not be between
646 the default text start (obj_textsec(abfd)->vma) and
647 (obj_textsec(abfd)->vma) + text size. This is not just a mach
648 issue. Many kernels are loaded at non standard addresses. */
649 if (abfd->iostream != NULL
650 && (abfd->flags & BFD_IN_MEMORY) == 0
651 && (fstat (fileno ((FILE *) (abfd->iostream)), &stat_buf) == 0)
652 && ((stat_buf.st_mode & 0111) != 0))
653 abfd->flags |= EXEC_P;
654 }
655#endif /* STAT_FOR_EXEC */
656
657 if (result)
658 {
659#if 0 /* These should be set correctly anyways. */
660 abfd->sections = obj_textsec (abfd);
661 obj_textsec (abfd)->next = obj_datasec (abfd);
662 obj_datasec (abfd)->next = obj_bsssec (abfd);
663#endif
664 return result;
665 }
666
667 error_ret:
668 bfd_release (abfd, rawptr);
669 abfd->tdata.aout_data = oldrawptr;
670 return NULL;
671}
672
673/*
674FUNCTION
675 aout_@var{size}_mkobject
676
677SYNOPSIS
678 bfd_boolean aout_@var{size}_mkobject, (bfd *abfd);
679
680DESCRIPTION
681 Initialize BFD @var{abfd} for use with a.out files.
682*/
683
684bfd_boolean
685NAME(aout,mkobject) (abfd)
686 bfd *abfd;
687{
688 struct aout_data_struct *rawptr;
689 bfd_size_type amt = sizeof (struct aout_data_struct);
690
691 bfd_set_error (bfd_error_system_call);
692
693 rawptr = (struct aout_data_struct *) bfd_zalloc (abfd, amt);
694 if (rawptr == NULL)
695 return FALSE;
696
697 abfd->tdata.aout_data = rawptr;
698 exec_hdr (abfd) = &(rawptr->e);
699
700 obj_textsec (abfd) = (asection *) NULL;
701 obj_datasec (abfd) = (asection *) NULL;
702 obj_bsssec (abfd) = (asection *) NULL;
703
704 return TRUE;
705}
706
707/*
708FUNCTION
709 aout_@var{size}_machine_type
710
711SYNOPSIS
712 enum machine_type aout_@var{size}_machine_type
713 (enum bfd_architecture arch,
714 unsigned long machine));
715
716DESCRIPTION
717 Keep track of machine architecture and machine type for
718 a.out's. Return the <<machine_type>> for a particular
719 architecture and machine, or <<M_UNKNOWN>> if that exact architecture
720 and machine can't be represented in a.out format.
721
722 If the architecture is understood, machine type 0 (default)
723 is always understood.
724*/
725
726enum machine_type
727NAME(aout,machine_type) (arch, machine, unknown)
728 enum bfd_architecture arch;
729 unsigned long machine;
730 bfd_boolean *unknown;
731{
732 enum machine_type arch_flags;
733
734 arch_flags = M_UNKNOWN;
735 *unknown = TRUE;
736
737 switch (arch)
738 {
739 case bfd_arch_sparc:
740 if (machine == 0
741 || machine == bfd_mach_sparc
742 || machine == bfd_mach_sparc_sparclite
743 || machine == bfd_mach_sparc_sparclite_le
744 || machine == bfd_mach_sparc_v9)
745 arch_flags = M_SPARC;
746 else if (machine == bfd_mach_sparc_sparclet)
747 arch_flags = M_SPARCLET;
748 break;
749
750 case bfd_arch_m68k:
751 switch (machine)
752 {
753 case 0: arch_flags = M_68010; break;
754 case bfd_mach_m68000: arch_flags = M_UNKNOWN; *unknown = FALSE; break;
755 case bfd_mach_m68010: arch_flags = M_68010; break;
756 case bfd_mach_m68020: arch_flags = M_68020; break;
757 default: arch_flags = M_UNKNOWN; break;
758 }
759 break;
760
761 case bfd_arch_i386:
762 if (machine == 0
763 || machine == bfd_mach_i386_i386
764 || machine == bfd_mach_i386_i386_intel_syntax)
765 arch_flags = M_386;
766 break;
767
768 case bfd_arch_a29k:
769 if (machine == 0)
770 arch_flags = M_29K;
771 break;
772
773 case bfd_arch_arm:
774 if (machine == 0)
775 arch_flags = M_ARM;
776 break;
777
778 case bfd_arch_mips:
779 switch (machine)
780 {
781 case 0:
782 case bfd_mach_mips3000:
783 case bfd_mach_mips3900:
784 arch_flags = M_MIPS1;
785 break;
786 case bfd_mach_mips6000:
787 arch_flags = M_MIPS2;
788 break;
789 case bfd_mach_mips4000:
790 case bfd_mach_mips4010:
791 case bfd_mach_mips4100:
792 case bfd_mach_mips4300:
793 case bfd_mach_mips4400:
794 case bfd_mach_mips4600:
795 case bfd_mach_mips4650:
796 case bfd_mach_mips8000:
797 case bfd_mach_mips10000:
798 case bfd_mach_mips12000:
799 case bfd_mach_mips16:
800 case bfd_mach_mipsisa32:
801 case bfd_mach_mipsisa32r2:
802 case bfd_mach_mips5:
803 case bfd_mach_mipsisa64:
804 case bfd_mach_mips_sb1:
805 /* FIXME: These should be MIPS3, MIPS4, MIPS16, MIPS32, etc. */
806 arch_flags = M_MIPS2;
807 break;
808 default:
809 arch_flags = M_UNKNOWN;
810 break;
811 }
812 break;
813
814 case bfd_arch_ns32k:
815 switch (machine)
816 {
817 case 0: arch_flags = M_NS32532; break;
818 case 32032: arch_flags = M_NS32032; break;
819 case 32532: arch_flags = M_NS32532; break;
820 default: arch_flags = M_UNKNOWN; break;
821 }
822 break;
823
824 case bfd_arch_vax:
825 *unknown = FALSE;
826 break;
827
828 case bfd_arch_cris:
829 if (machine == 0 || machine == 255)
830 arch_flags = M_CRIS;
831 break;
832
833 default:
834 arch_flags = M_UNKNOWN;
835 }
836
837 if (arch_flags != M_UNKNOWN)
838 *unknown = FALSE;
839
840 return arch_flags;
841}
842
843/*
844FUNCTION
845 aout_@var{size}_set_arch_mach
846
847SYNOPSIS
848 bfd_boolean aout_@var{size}_set_arch_mach,
849 (bfd *,
850 enum bfd_architecture arch,
851 unsigned long machine));
852
853DESCRIPTION
854 Set the architecture and the machine of the BFD @var{abfd} to the
855 values @var{arch} and @var{machine}. Verify that @var{abfd}'s format
856 can support the architecture required.
857*/
858
859bfd_boolean
860NAME(aout,set_arch_mach) (abfd, arch, machine)
861 bfd *abfd;
862 enum bfd_architecture arch;
863 unsigned long machine;
864{
865 if (! bfd_default_set_arch_mach (abfd, arch, machine))
866 return FALSE;
867
868 if (arch != bfd_arch_unknown)
869 {
870 bfd_boolean unknown;
871
872 NAME(aout,machine_type) (arch, machine, &unknown);
873 if (unknown)
874 return FALSE;
875 }
876
877 /* Determine the size of a relocation entry. */
878 switch (arch)
879 {
880 case bfd_arch_sparc:
881 case bfd_arch_a29k:
882 case bfd_arch_mips:
883 obj_reloc_entry_size (abfd) = RELOC_EXT_SIZE;
884 break;
885 default:
886 obj_reloc_entry_size (abfd) = RELOC_STD_SIZE;
887 break;
888 }
889
890 return (*aout_backend_info (abfd)->set_sizes) (abfd);
891}
892
893static void
894adjust_o_magic (abfd, execp)
895 bfd *abfd;
896 struct internal_exec *execp;
897{
898 file_ptr pos = adata (abfd).exec_bytes_size;
899 bfd_vma vma = 0;
900 int pad = 0;
901
902 /* Text. */
903 obj_textsec (abfd)->filepos = pos;
904 if (!obj_textsec (abfd)->user_set_vma)
905 obj_textsec (abfd)->vma = vma;
906 else
907 vma = obj_textsec (abfd)->vma;
908
909 pos += obj_textsec (abfd)->_raw_size;
910 vma += obj_textsec (abfd)->_raw_size;
911
912 /* Data. */
913 if (!obj_datasec (abfd)->user_set_vma)
914 {
915#if 0 /* ?? Does alignment in the file image really matter? */
916 pad = align_power (vma, obj_datasec (abfd)->alignment_power) - vma;
917#endif
918 obj_textsec (abfd)->_raw_size += pad;
919 pos += pad;
920 vma += pad;
921 obj_datasec (abfd)->vma = vma;
922 }
923 else
924 vma = obj_datasec (abfd)->vma;
925 obj_datasec (abfd)->filepos = pos;
926 pos += obj_datasec (abfd)->_raw_size;
927 vma += obj_datasec (abfd)->_raw_size;
928
929 /* BSS. */
930 if (!obj_bsssec (abfd)->user_set_vma)
931 {
932#if 0
933 pad = align_power (vma, obj_bsssec (abfd)->alignment_power) - vma;
934#endif
935 obj_datasec (abfd)->_raw_size += pad;
936 pos += pad;
937 vma += pad;
938 obj_bsssec (abfd)->vma = vma;
939 }
940 else
941 {
942 /* The VMA of the .bss section is set by the VMA of the
943 .data section plus the size of the .data section. We may
944 need to add padding bytes to make this true. */
945 pad = obj_bsssec (abfd)->vma - vma;
946 if (pad > 0)
947 {
948 obj_datasec (abfd)->_raw_size += pad;
949 pos += pad;
950 }
951 }
952 obj_bsssec (abfd)->filepos = pos;
953
954 /* Fix up the exec header. */
955 execp->a_text = obj_textsec (abfd)->_raw_size;
956 execp->a_data = obj_datasec (abfd)->_raw_size;
957 execp->a_bss = obj_bsssec (abfd)->_raw_size;
958 N_SET_MAGIC (*execp, OMAGIC);
959}
960
961static void
962adjust_z_magic (abfd, execp)
963 bfd *abfd;
964 struct internal_exec *execp;
965{
966 bfd_size_type data_pad, text_pad;
967 file_ptr text_end;
968 const struct aout_backend_data *abdp;
969 int ztih; /* Nonzero if text includes exec header. */
970
971 abdp = aout_backend_info (abfd);
972
973 /* Text. */
974 ztih = (abdp != NULL
975 && (abdp->text_includes_header
976 || obj_aout_subformat (abfd) == q_magic_format));
977 obj_textsec (abfd)->filepos = (ztih
978 ? adata (abfd).exec_bytes_size
979 : adata (abfd).zmagic_disk_block_size);
980 if (! obj_textsec (abfd)->user_set_vma)
981 {
982 /* ?? Do we really need to check for relocs here? */
983 obj_textsec (abfd)->vma = ((abfd->flags & HAS_RELOC)
984 ? 0
985 : (ztih
986 ? (abdp->default_text_vma
987 + adata (abfd).exec_bytes_size)
988 : abdp->default_text_vma));
989 text_pad = 0;
990 }
991 else
992 {
993 /* The .text section is being loaded at an unusual address. We
994 may need to pad it such that the .data section starts at a page
995 boundary. */
996 if (ztih)
997 text_pad = ((obj_textsec (abfd)->filepos - obj_textsec (abfd)->vma)
998 & (adata (abfd).page_size - 1));
999 else
1000 text_pad = ((- obj_textsec (abfd)->vma)
1001 & (adata (abfd).page_size - 1));
1002 }
1003
1004 /* Find start of data. */
1005 if (ztih)
1006 {
1007 text_end = obj_textsec (abfd)->filepos + obj_textsec (abfd)->_raw_size;
1008 text_pad += BFD_ALIGN (text_end, adata (abfd).page_size) - text_end;
1009 }
1010 else
1011 {
1012 /* Note that if page_size == zmagic_disk_block_size, then
1013 filepos == page_size, and this case is the same as the ztih
1014 case. */
1015 text_end = obj_textsec (abfd)->_raw_size;
1016 text_pad += BFD_ALIGN (text_end, adata (abfd).page_size) - text_end;
1017 text_end += obj_textsec (abfd)->filepos;
1018 }
1019 obj_textsec (abfd)->_raw_size += text_pad;
1020 text_end += text_pad;
1021
1022 /* Data. */
1023 if (!obj_datasec (abfd)->user_set_vma)
1024 {
1025 bfd_vma vma;
1026 vma = obj_textsec (abfd)->vma + obj_textsec (abfd)->_raw_size;
1027 obj_datasec (abfd)->vma = BFD_ALIGN (vma, adata (abfd).segment_size);
1028 }
1029 if (abdp && abdp->zmagic_mapped_contiguous)
1030 {
1031 asection * text = obj_textsec (abfd);
1032 asection * data = obj_datasec (abfd);
1033
1034 text_pad = data->vma - (text->vma + text->_raw_size);
1035 /* Only pad the text section if the data
1036 section is going to be placed after it. */
1037 if (text_pad > 0)
1038 text->_raw_size += text_pad;
1039 }
1040 obj_datasec (abfd)->filepos = (obj_textsec (abfd)->filepos
1041 + obj_textsec (abfd)->_raw_size);
1042
1043 /* Fix up exec header while we're at it. */
1044 execp->a_text = obj_textsec (abfd)->_raw_size;
1045 if (ztih && (!abdp || (abdp && !abdp->exec_header_not_counted)))
1046 execp->a_text += adata (abfd).exec_bytes_size;
1047 if (obj_aout_subformat (abfd) == q_magic_format)
1048 N_SET_MAGIC (*execp, QMAGIC);
1049 else
1050 N_SET_MAGIC (*execp, ZMAGIC);
1051
1052 /* Spec says data section should be rounded up to page boundary. */
1053 obj_datasec (abfd)->_raw_size
1054 = align_power (obj_datasec (abfd)->_raw_size,
1055 obj_bsssec (abfd)->alignment_power);
1056 execp->a_data = BFD_ALIGN (obj_datasec (abfd)->_raw_size,
1057 adata (abfd).page_size);
1058 data_pad = execp->a_data - obj_datasec (abfd)->_raw_size;
1059
1060 /* BSS. */
1061 if (!obj_bsssec (abfd)->user_set_vma)
1062 obj_bsssec (abfd)->vma = (obj_datasec (abfd)->vma
1063 + obj_datasec (abfd)->_raw_size);
1064 /* If the BSS immediately follows the data section and extra space
1065 in the page is left after the data section, fudge data
1066 in the header so that the bss section looks smaller by that
1067 amount. We'll start the bss section there, and lie to the OS.
1068 (Note that a linker script, as well as the above assignment,
1069 could have explicitly set the BSS vma to immediately follow
1070 the data section.) */
1071 if (align_power (obj_bsssec (abfd)->vma, obj_bsssec (abfd)->alignment_power)
1072 == obj_datasec (abfd)->vma + obj_datasec (abfd)->_raw_size)
1073 execp->a_bss = (data_pad > obj_bsssec (abfd)->_raw_size
1074 ? 0 : obj_bsssec (abfd)->_raw_size - data_pad);
1075 else
1076 execp->a_bss = obj_bsssec (abfd)->_raw_size;
1077}
1078
1079static void
1080adjust_n_magic (abfd, execp)
1081 bfd *abfd;
1082 struct internal_exec *execp;
1083{
1084 file_ptr pos = adata (abfd).exec_bytes_size;
1085 bfd_vma vma = 0;
1086 int pad;
1087
1088 /* Text. */
1089 obj_textsec (abfd)->filepos = pos;
1090 if (!obj_textsec (abfd)->user_set_vma)
1091 obj_textsec (abfd)->vma = vma;
1092 else
1093 vma = obj_textsec (abfd)->vma;
1094 pos += obj_textsec (abfd)->_raw_size;
1095 vma += obj_textsec (abfd)->_raw_size;
1096
1097 /* Data. */
1098 obj_datasec (abfd)->filepos = pos;
1099 if (!obj_datasec (abfd)->user_set_vma)
1100 obj_datasec (abfd)->vma = BFD_ALIGN (vma, adata (abfd).segment_size);
1101 vma = obj_datasec (abfd)->vma;
1102
1103 /* Since BSS follows data immediately, see if it needs alignment. */
1104 vma += obj_datasec (abfd)->_raw_size;
1105 pad = align_power (vma, obj_bsssec (abfd)->alignment_power) - vma;
1106 obj_datasec (abfd)->_raw_size += pad;
1107 pos += obj_datasec (abfd)->_raw_size;
1108
1109 /* BSS. */
1110 if (!obj_bsssec (abfd)->user_set_vma)
1111 obj_bsssec (abfd)->vma = vma;
1112 else
1113 vma = obj_bsssec (abfd)->vma;
1114
1115 /* Fix up exec header. */
1116 execp->a_text = obj_textsec (abfd)->_raw_size;
1117 execp->a_data = obj_datasec (abfd)->_raw_size;
1118 execp->a_bss = obj_bsssec (abfd)->_raw_size;
1119 N_SET_MAGIC (*execp, NMAGIC);
1120}
1121
1122bfd_boolean
1123NAME(aout,adjust_sizes_and_vmas) (abfd, text_size, text_end)
1124 bfd *abfd;
1125 bfd_size_type *text_size;
1126 file_ptr *text_end ATTRIBUTE_UNUSED;
1127{
1128 struct internal_exec *execp = exec_hdr (abfd);
1129
1130 if (! NAME(aout,make_sections) (abfd))
1131 return FALSE;
1132
1133 if (adata (abfd).magic != undecided_magic)
1134 return TRUE;
1135
1136 obj_textsec (abfd)->_raw_size =
1137 align_power (obj_textsec (abfd)->_raw_size,
1138 obj_textsec (abfd)->alignment_power);
1139
1140 *text_size = obj_textsec (abfd)->_raw_size;
1141 /* Rule (heuristic) for when to pad to a new page. Note that there
1142 are (at least) two ways demand-paged (ZMAGIC) files have been
1143 handled. Most Berkeley-based systems start the text segment at
1144 (TARGET_PAGE_SIZE). However, newer versions of SUNOS start the text
1145 segment right after the exec header; the latter is counted in the
1146 text segment size, and is paged in by the kernel with the rest of
1147 the text. */
1148
1149 /* This perhaps isn't the right way to do this, but made it simpler for me
1150 to understand enough to implement it. Better would probably be to go
1151 right from BFD flags to alignment/positioning characteristics. But the
1152 old code was sloppy enough about handling the flags, and had enough
1153 other magic, that it was a little hard for me to understand. I think
1154 I understand it better now, but I haven't time to do the cleanup this
1155 minute. */
1156
1157 if (abfd->flags & D_PAGED)
1158 /* Whether or not WP_TEXT is set -- let D_PAGED override. */
1159 adata (abfd).magic = z_magic;
1160 else if (abfd->flags & WP_TEXT)
1161 adata (abfd).magic = n_magic;
1162 else
1163 adata (abfd).magic = o_magic;
1164
1165#ifdef BFD_AOUT_DEBUG /* requires gcc2 */
1166#if __GNUC__ >= 2
1167 fprintf (stderr, "%s text=<%x,%x,%x> data=<%x,%x,%x> bss=<%x,%x,%x>\n",
1168 ({ char *str;
1169 switch (adata (abfd).magic)
1170 {
1171 case n_magic: str = "NMAGIC"; break;
1172 case o_magic: str = "OMAGIC"; break;
1173 case z_magic: str = "ZMAGIC"; break;
1174 default: abort ();
1175 }
1176 str;
1177 }),
1178 obj_textsec (abfd)->vma, obj_textsec (abfd)->_raw_size,
1179 obj_textsec (abfd)->alignment_power,
1180 obj_datasec (abfd)->vma, obj_datasec (abfd)->_raw_size,
1181 obj_datasec (abfd)->alignment_power,
1182 obj_bsssec (abfd)->vma, obj_bsssec (abfd)->_raw_size,
1183 obj_bsssec (abfd)->alignment_power);
1184#endif
1185#endif
1186
1187 switch (adata (abfd).magic)
1188 {
1189 case o_magic:
1190 adjust_o_magic (abfd, execp);
1191 break;
1192 case z_magic:
1193 adjust_z_magic (abfd, execp);
1194 break;
1195 case n_magic:
1196 adjust_n_magic (abfd, execp);
1197 break;
1198 default:
1199 abort ();
1200 }
1201
1202#ifdef BFD_AOUT_DEBUG
1203 fprintf (stderr, " text=<%x,%x,%x> data=<%x,%x,%x> bss=<%x,%x>\n",
1204 obj_textsec (abfd)->vma, obj_textsec (abfd)->_raw_size,
1205 obj_textsec (abfd)->filepos,
1206 obj_datasec (abfd)->vma, obj_datasec (abfd)->_raw_size,
1207 obj_datasec (abfd)->filepos,
1208 obj_bsssec (abfd)->vma, obj_bsssec (abfd)->_raw_size);
1209#endif
1210
1211 return TRUE;
1212}
1213
1214/*
1215FUNCTION
1216 aout_@var{size}_new_section_hook
1217
1218SYNOPSIS
1219 bfd_boolean aout_@var{size}_new_section_hook,
1220 (bfd *abfd,
1221 asection *newsect));
1222
1223DESCRIPTION
1224 Called by the BFD in response to a @code{bfd_make_section}
1225 request.
1226*/
1227bfd_boolean
1228NAME(aout,new_section_hook) (abfd, newsect)
1229 bfd *abfd;
1230 asection *newsect;
1231{
1232 /* Align to double at least. */
1233 newsect->alignment_power = bfd_get_arch_info (abfd)->section_align_power;
1234
1235 if (bfd_get_format (abfd) == bfd_object)
1236 {
1237 if (obj_textsec (abfd) == NULL && !strcmp (newsect->name, ".text"))
1238 {
1239 obj_textsec (abfd)= newsect;
1240 newsect->target_index = N_TEXT;
1241 return TRUE;
1242 }
1243
1244 if (obj_datasec (abfd) == NULL && !strcmp (newsect->name, ".data"))
1245 {
1246 obj_datasec (abfd) = newsect;
1247 newsect->target_index = N_DATA;
1248 return TRUE;
1249 }
1250
1251 if (obj_bsssec (abfd) == NULL && !strcmp (newsect->name, ".bss"))
1252 {
1253 obj_bsssec (abfd) = newsect;
1254 newsect->target_index = N_BSS;
1255 return TRUE;
1256 }
1257 }
1258
1259 /* We allow more than three sections internally. */
1260 return TRUE;
1261}
1262
1263bfd_boolean
1264NAME(aout,set_section_contents) (abfd, section, location, offset, count)
1265 bfd *abfd;
1266 sec_ptr section;
1267 PTR location;
1268 file_ptr offset;
1269 bfd_size_type count;
1270{
1271 file_ptr text_end;
1272 bfd_size_type text_size;
1273
1274 if (! abfd->output_has_begun)
1275 {
1276 if (! NAME(aout,adjust_sizes_and_vmas) (abfd, &text_size, &text_end))
1277 return FALSE;
1278 }
1279
1280 if (section == obj_bsssec (abfd))
1281 {
1282 bfd_set_error (bfd_error_no_contents);
1283 return FALSE;
1284 }
1285
1286 if (section != obj_textsec (abfd)
1287 && section != obj_datasec (abfd))
1288 {
1289 if (aout_section_merge_with_text_p (abfd, section))
1290 section->filepos = obj_textsec (abfd)->filepos +
1291 (section->vma - obj_textsec (abfd)->vma);
1292 else
1293 {
1294 (*_bfd_error_handler)
1295 (_("%s: can not represent section `%s' in a.out object file format"),
1296 bfd_get_filename (abfd), bfd_get_section_name (abfd, section));
1297 bfd_set_error (bfd_error_nonrepresentable_section);
1298 return FALSE;
1299 }
1300 }
1301
1302 if (count != 0)
1303 {
1304 if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0
1305 || bfd_bwrite (location, count, abfd) != count)
1306 return FALSE;
1307 }
1308
1309 return TRUE;
1310}
1311
1312
1313/* Read the external symbols from an a.out file. */
1314
1315static bfd_boolean
1316aout_get_external_symbols (abfd)
1317 bfd *abfd;
1318{
1319 if (obj_aout_external_syms (abfd) == (struct external_nlist *) NULL)
1320 {
1321 bfd_size_type count;
1322 struct external_nlist *syms;
1323 bfd_size_type amt;
1324
1325 count = exec_hdr (abfd)->a_syms / EXTERNAL_NLIST_SIZE;
1326
1327#ifdef USE_MMAP
1328 if (! bfd_get_file_window (abfd, obj_sym_filepos (abfd),
1329 exec_hdr (abfd)->a_syms,
1330 &obj_aout_sym_window (abfd), TRUE))
1331 return FALSE;
1332 syms = (struct external_nlist *) obj_aout_sym_window (abfd).data;
1333#else
1334 /* We allocate using malloc to make the values easy to free
1335 later on. If we put them on the objalloc it might not be
1336 possible to free them. */
1337 syms = ((struct external_nlist *)
1338 bfd_malloc (count * EXTERNAL_NLIST_SIZE));
1339 if (syms == (struct external_nlist *) NULL && count != 0)
1340 return FALSE;
1341
1342 amt = exec_hdr (abfd)->a_syms;
1343 if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0
1344 || bfd_bread (syms, amt, abfd) != amt)
1345 {
1346 free (syms);
1347 return FALSE;
1348 }
1349#endif
1350
1351 obj_aout_external_syms (abfd) = syms;
1352 obj_aout_external_sym_count (abfd) = count;
1353 }
1354
1355 if (obj_aout_external_strings (abfd) == NULL
1356 && exec_hdr (abfd)->a_syms != 0)
1357 {
1358 unsigned char string_chars[BYTES_IN_WORD];
1359 bfd_size_type stringsize;
1360 char *strings;
1361 bfd_size_type amt = BYTES_IN_WORD;
1362
1363 /* Get the size of the strings. */
1364 if (bfd_seek (abfd, obj_str_filepos (abfd), SEEK_SET) != 0
1365 || bfd_bread ((PTR) string_chars, amt, abfd) != amt)
1366 return FALSE;
1367 stringsize = GET_WORD (abfd, string_chars);
1368
1369#ifdef USE_MMAP
1370 if (! bfd_get_file_window (abfd, obj_str_filepos (abfd), stringsize,
1371 &obj_aout_string_window (abfd), TRUE))
1372 return FALSE;
1373 strings = (char *) obj_aout_string_window (abfd).data;
1374#else
1375 strings = (char *) bfd_malloc (stringsize + 1);
1376 if (strings == NULL)
1377 return FALSE;
1378
1379 /* Skip space for the string count in the buffer for convenience
1380 when using indexes. */
1381 amt = stringsize - BYTES_IN_WORD;
1382 if (bfd_bread (strings + BYTES_IN_WORD, amt, abfd) != amt)
1383 {
1384 free (strings);
1385 return FALSE;
1386 }
1387#endif
1388
1389 /* Ensure that a zero index yields an empty string. */
1390 strings[0] = '\0';
1391
1392 strings[stringsize - 1] = 0;
1393
1394 obj_aout_external_strings (abfd) = strings;
1395 obj_aout_external_string_size (abfd) = stringsize;
1396 }
1397
1398 return TRUE;
1399}
1400
1401/* Translate an a.out symbol into a BFD symbol. The desc, other, type
1402 and symbol->value fields of CACHE_PTR will be set from the a.out
1403 nlist structure. This function is responsible for setting
1404 symbol->flags and symbol->section, and adjusting symbol->value. */
1405
1406static bfd_boolean
1407translate_from_native_sym_flags (abfd, cache_ptr)
1408 bfd *abfd;
1409 aout_symbol_type *cache_ptr;
1410{
1411 flagword visible;
1412
1413 if ((cache_ptr->type & N_STAB) != 0
1414 || cache_ptr->type == N_FN)
1415 {
1416 asection *sec;
1417
1418 /* This is a debugging symbol. */
1419 cache_ptr->symbol.flags = BSF_DEBUGGING;
1420
1421 /* Work out the symbol section. */
1422 switch (cache_ptr->type & N_TYPE)
1423 {
1424 case N_TEXT:
1425 case N_FN:
1426 sec = obj_textsec (abfd);
1427 break;
1428 case N_DATA:
1429 sec = obj_datasec (abfd);
1430 break;
1431 case N_BSS:
1432 sec = obj_bsssec (abfd);
1433 break;
1434 default:
1435 case N_ABS:
1436 sec = bfd_abs_section_ptr;
1437 break;
1438 }
1439
1440 cache_ptr->symbol.section = sec;
1441 cache_ptr->symbol.value -= sec->vma;
1442
1443 return TRUE;
1444 }
1445
1446 /* Get the default visibility. This does not apply to all types, so
1447 we just hold it in a local variable to use if wanted. */
1448 if ((cache_ptr->type & N_EXT) == 0)
1449 visible = BSF_LOCAL;
1450 else
1451 visible = BSF_GLOBAL;
1452
1453 switch (cache_ptr->type)
1454 {
1455 default:
1456 case N_ABS: case N_ABS | N_EXT:
1457 cache_ptr->symbol.section = bfd_abs_section_ptr;
1458 cache_ptr->symbol.flags = visible;
1459 break;
1460
1461 case N_UNDF | N_EXT:
1462 if (cache_ptr->symbol.value != 0)
1463 {
1464 /* This is a common symbol. */
1465 cache_ptr->symbol.flags = BSF_GLOBAL;
1466 cache_ptr->symbol.section = bfd_com_section_ptr;
1467 }
1468 else
1469 {
1470 cache_ptr->symbol.flags = 0;
1471 cache_ptr->symbol.section = bfd_und_section_ptr;
1472 }
1473 break;
1474
1475 case N_TEXT: case N_TEXT | N_EXT:
1476 cache_ptr->symbol.section = obj_textsec (abfd);
1477 cache_ptr->symbol.value -= cache_ptr->symbol.section->vma;
1478 cache_ptr->symbol.flags = visible;
1479 break;
1480
1481 /* N_SETV symbols used to represent set vectors placed in the
1482 data section. They are no longer generated. Theoretically,
1483 it was possible to extract the entries and combine them with
1484 new ones, although I don't know if that was ever actually
1485 done. Unless that feature is restored, treat them as data
1486 symbols. */
1487 case N_SETV: case N_SETV | N_EXT:
1488 case N_DATA: case N_DATA | N_EXT:
1489 cache_ptr->symbol.section = obj_datasec (abfd);
1490 cache_ptr->symbol.value -= cache_ptr->symbol.section->vma;
1491 cache_ptr->symbol.flags = visible;
1492 break;
1493
1494 case N_BSS: case N_BSS | N_EXT:
1495 cache_ptr->symbol.section = obj_bsssec (abfd);
1496 cache_ptr->symbol.value -= cache_ptr->symbol.section->vma;
1497 cache_ptr->symbol.flags = visible;
1498 break;
1499
1500 case N_SETA: case N_SETA | N_EXT:
1501 case N_SETT: case N_SETT | N_EXT:
1502 case N_SETD: case N_SETD | N_EXT:
1503 case N_SETB: case N_SETB | N_EXT:
1504 {
1505 /* This code is no longer needed. It used to be used to make
1506 the linker handle set symbols, but they are now handled in
1507 the add_symbols routine instead. */
1508#if 0
1509 asection *section;
1510 arelent_chain *reloc;
1511 asection *into_section;
1512 bfd_size_type amt;
1513
1514 /* This is a set symbol. The name of the symbol is the name
1515 of the set (e.g., __CTOR_LIST__). The value of the symbol
1516 is the value to add to the set. We create a section with
1517 the same name as the symbol, and add a reloc to insert the
1518 appropriate value into the section.
1519
1520 This action is actually obsolete; it used to make the
1521 linker do the right thing, but the linker no longer uses
1522 this function. */
1523
1524 section = bfd_get_section_by_name (abfd, cache_ptr->symbol.name);
1525 if (section == NULL)
1526 {
1527 char *copy;
1528
1529 amt = strlen (cache_ptr->symbol.name) + 1;
1530 copy = bfd_alloc (abfd, amt);
1531 if (copy == NULL)
1532 return FALSE;
1533
1534 strcpy (copy, cache_ptr->symbol.name);
1535 section = bfd_make_section (abfd, copy);
1536 if (section == NULL)
1537 return FALSE;
1538 }
1539
1540 amt = sizeof (arelent_chain);
1541 reloc = (arelent_chain *) bfd_alloc (abfd, amt);
1542 if (reloc == NULL)
1543 return FALSE;
1544
1545 /* Build a relocation entry for the constructor. */
1546 switch (cache_ptr->type & N_TYPE)
1547 {
1548 case N_SETA:
1549 into_section = bfd_abs_section_ptr;
1550 cache_ptr->type = N_ABS;
1551 break;
1552 case N_SETT:
1553 into_section = obj_textsec (abfd);
1554 cache_ptr->type = N_TEXT;
1555 break;
1556 case N_SETD:
1557 into_section = obj_datasec (abfd);
1558 cache_ptr->type = N_DATA;
1559 break;
1560 case N_SETB:
1561 into_section = obj_bsssec (abfd);
1562 cache_ptr->type = N_BSS;
1563 break;
1564 }
1565
1566 /* Build a relocation pointing into the constructor section
1567 pointing at the symbol in the set vector specified. */
1568 reloc->relent.addend = cache_ptr->symbol.value;
1569 cache_ptr->symbol.section = into_section;
1570 reloc->relent.sym_ptr_ptr = into_section->symbol_ptr_ptr;
1571
1572 /* We modify the symbol to belong to a section depending upon
1573 the name of the symbol, and add to the size of the section
1574 to contain a pointer to the symbol. Build a reloc entry to
1575 relocate to this symbol attached to this section. */
1576 section->flags = SEC_CONSTRUCTOR | SEC_RELOC;
1577
1578 section->reloc_count++;
1579 section->alignment_power = 2;
1580
1581 reloc->next = section->constructor_chain;
1582 section->constructor_chain = reloc;
1583 reloc->relent.address = section->_raw_size;
1584 section->_raw_size += BYTES_IN_WORD;
1585
1586 reloc->relent.howto = CTOR_TABLE_RELOC_HOWTO (abfd);
1587
1588#endif /* 0 */
1589
1590 switch (cache_ptr->type & N_TYPE)
1591 {
1592 case N_SETA:
1593 cache_ptr->symbol.section = bfd_abs_section_ptr;
1594 break;
1595 case N_SETT:
1596 cache_ptr->symbol.section = obj_textsec (abfd);
1597 break;
1598 case N_SETD:
1599 cache_ptr->symbol.section = obj_datasec (abfd);
1600 break;
1601 case N_SETB:
1602 cache_ptr->symbol.section = obj_bsssec (abfd);
1603 break;
1604 }
1605
1606 cache_ptr->symbol.flags |= BSF_CONSTRUCTOR;
1607 }
1608 break;
1609
1610 case N_WARNING:
1611 /* This symbol is the text of a warning message. The next
1612 symbol is the symbol to associate the warning with. If a
1613 reference is made to that symbol, a warning is issued. */
1614 cache_ptr->symbol.flags = BSF_DEBUGGING | BSF_WARNING;
1615 cache_ptr->symbol.section = bfd_abs_section_ptr;
1616 break;
1617
1618 case N_INDR: case N_INDR | N_EXT:
1619 /* An indirect symbol. This consists of two symbols in a row.
1620 The first symbol is the name of the indirection. The second
1621 symbol is the name of the target. A reference to the first
1622 symbol becomes a reference to the second. */
1623 cache_ptr->symbol.flags = BSF_DEBUGGING | BSF_INDIRECT | visible;
1624 cache_ptr->symbol.section = bfd_ind_section_ptr;
1625 break;
1626
1627 case N_WEAKU:
1628 cache_ptr->symbol.section = bfd_und_section_ptr;
1629 cache_ptr->symbol.flags = BSF_WEAK;
1630 break;
1631
1632 case N_WEAKA:
1633 cache_ptr->symbol.section = bfd_abs_section_ptr;
1634 cache_ptr->symbol.flags = BSF_WEAK;
1635 break;
1636
1637 case N_WEAKT:
1638 cache_ptr->symbol.section = obj_textsec (abfd);
1639 cache_ptr->symbol.value -= cache_ptr->symbol.section->vma;
1640 cache_ptr->symbol.flags = BSF_WEAK;
1641 break;
1642
1643 case N_WEAKD:
1644 cache_ptr->symbol.section = obj_datasec (abfd);
1645 cache_ptr->symbol.value -= cache_ptr->symbol.section->vma;
1646 cache_ptr->symbol.flags = BSF_WEAK;
1647 break;
1648
1649 case N_WEAKB:
1650 cache_ptr->symbol.section = obj_bsssec (abfd);
1651 cache_ptr->symbol.value -= cache_ptr->symbol.section->vma;
1652 cache_ptr->symbol.flags = BSF_WEAK;
1653 break;
1654 }
1655
1656 return TRUE;
1657}
1658
1659/* Set the fields of SYM_POINTER according to CACHE_PTR. */
1660
1661static bfd_boolean
1662translate_to_native_sym_flags (abfd, cache_ptr, sym_pointer)
1663 bfd *abfd;
1664 asymbol *cache_ptr;
1665 struct external_nlist *sym_pointer;
1666{
1667 bfd_vma value = cache_ptr->value;
1668 asection *sec;
1669 bfd_vma off;
1670
1671 /* Mask out any existing type bits in case copying from one section
1672 to another. */
1673 sym_pointer->e_type[0] &= ~N_TYPE;
1674
1675 sec = bfd_get_section (cache_ptr);
1676 off = 0;
1677
1678 if (sec == NULL)
1679 {
1680 /* This case occurs, e.g., for the *DEBUG* section of a COFF
1681 file. */
1682 (*_bfd_error_handler)
1683 (_("%s: can not represent section for symbol `%s' in a.out object file format"),
1684 bfd_get_filename (abfd),
1685 cache_ptr->name != NULL ? cache_ptr->name : _("*unknown*"));
1686 bfd_set_error (bfd_error_nonrepresentable_section);
1687 return FALSE;
1688 }
1689
1690 if (sec->output_section != NULL)
1691 {
1692 off = sec->output_offset;
1693 sec = sec->output_section;
1694 }
1695
1696 if (bfd_is_abs_section (sec))
1697 sym_pointer->e_type[0] |= N_ABS;
1698 else if (sec == obj_textsec (abfd))
1699 sym_pointer->e_type[0] |= N_TEXT;
1700 else if (sec == obj_datasec (abfd))
1701 sym_pointer->e_type[0] |= N_DATA;
1702 else if (sec == obj_bsssec (abfd))
1703 sym_pointer->e_type[0] |= N_BSS;
1704 else if (bfd_is_und_section (sec))
1705 sym_pointer->e_type[0] = N_UNDF | N_EXT;
1706 else if (bfd_is_ind_section (sec))
1707 sym_pointer->e_type[0] = N_INDR;
1708 else if (bfd_is_com_section (sec))
1709 sym_pointer->e_type[0] = N_UNDF | N_EXT;
1710 else
1711 {
1712 if (aout_section_merge_with_text_p (abfd, sec))
1713 sym_pointer->e_type[0] |= N_TEXT;
1714 else
1715 {
1716 (*_bfd_error_handler)
1717 (_("%s: can not represent section `%s' in a.out object file format"),
1718 bfd_get_filename (abfd), bfd_get_section_name (abfd, sec));
1719 bfd_set_error (bfd_error_nonrepresentable_section);
1720 return FALSE;
1721 }
1722 }
1723
1724 /* Turn the symbol from section relative to absolute again. */
1725 value += sec->vma + off;
1726
1727 if ((cache_ptr->flags & BSF_WARNING) != 0)
1728 sym_pointer->e_type[0] = N_WARNING;
1729
1730 if ((cache_ptr->flags & BSF_DEBUGGING) != 0)
1731 sym_pointer->e_type[0] = ((aout_symbol_type *) cache_ptr)->type;
1732 else if ((cache_ptr->flags & BSF_GLOBAL) != 0)
1733 sym_pointer->e_type[0] |= N_EXT;
1734 else if ((cache_ptr->flags & BSF_LOCAL) != 0)
1735 sym_pointer->e_type[0] &= ~N_EXT;
1736
1737 if ((cache_ptr->flags & BSF_CONSTRUCTOR) != 0)
1738 {
1739 int type = ((aout_symbol_type *) cache_ptr)->type;
1740
1741 switch (type)
1742 {
1743 case N_ABS: type = N_SETA; break;
1744 case N_TEXT: type = N_SETT; break;
1745 case N_DATA: type = N_SETD; break;
1746 case N_BSS: type = N_SETB; break;
1747 }
1748 sym_pointer->e_type[0] = type;
1749 }
1750
1751 if ((cache_ptr->flags & BSF_WEAK) != 0)
1752 {
1753 int type;
1754
1755 switch (sym_pointer->e_type[0] & N_TYPE)
1756 {
1757 default:
1758 case N_ABS: type = N_WEAKA; break;
1759 case N_TEXT: type = N_WEAKT; break;
1760 case N_DATA: type = N_WEAKD; break;
1761 case N_BSS: type = N_WEAKB; break;
1762 case N_UNDF: type = N_WEAKU; break;
1763 }
1764 sym_pointer->e_type[0] = type;
1765 }
1766
1767 PUT_WORD (abfd, value, sym_pointer->e_value);
1768
1769 return TRUE;
1770}
1771
1772
1773/* Native-level interface to symbols. */
1774
1775asymbol *
1776NAME(aout,make_empty_symbol) (abfd)
1777 bfd *abfd;
1778{
1779 bfd_size_type amt = sizeof (aout_symbol_type);
1780 aout_symbol_type *new = (aout_symbol_type *) bfd_zalloc (abfd, amt);
1781 if (!new)
1782 return NULL;
1783 new->symbol.the_bfd = abfd;
1784
1785 return &new->symbol;
1786}
1787
1788/* Translate a set of internal symbols into external symbols. */
1789
1790bfd_boolean
1791NAME(aout,translate_symbol_table) (abfd, in, ext, count, str, strsize, dynamic)
1792 bfd *abfd;
1793 aout_symbol_type *in;
1794 struct external_nlist *ext;
1795 bfd_size_type count;
1796 char *str;
1797 bfd_size_type strsize;
1798 bfd_boolean dynamic;
1799{
1800 struct external_nlist *ext_end;
1801
1802 ext_end = ext + count;
1803 for (; ext < ext_end; ext++, in++)
1804 {
1805 bfd_vma x;
1806
1807 x = GET_WORD (abfd, ext->e_strx);
1808 in->symbol.the_bfd = abfd;
1809
1810 /* For the normal symbols, the zero index points at the number
1811 of bytes in the string table but is to be interpreted as the
1812 null string. For the dynamic symbols, the number of bytes in
1813 the string table is stored in the __DYNAMIC structure and the
1814 zero index points at an actual string. */
1815 if (x == 0 && ! dynamic)
1816 in->symbol.name = "";
1817 else if (x < strsize)
1818 in->symbol.name = str + x;
1819 else
1820 return FALSE;
1821
1822 in->symbol.value = GET_SWORD (abfd, ext->e_value);
1823 in->desc = H_GET_16 (abfd, ext->e_desc);
1824 in->other = H_GET_8 (abfd, ext->e_other);
1825 in->type = H_GET_8 (abfd, ext->e_type);
1826 in->symbol.udata.p = NULL;
1827
1828 if (! translate_from_native_sym_flags (abfd, in))
1829 return FALSE;
1830
1831 if (dynamic)
1832 in->symbol.flags |= BSF_DYNAMIC;
1833 }
1834
1835 return TRUE;
1836}
1837
1838/* We read the symbols into a buffer, which is discarded when this
1839 function exits. We read the strings into a buffer large enough to
1840 hold them all plus all the cached symbol entries. */
1841
1842bfd_boolean
1843NAME(aout,slurp_symbol_table) (abfd)
1844 bfd *abfd;
1845{
1846 struct external_nlist *old_external_syms;
1847 aout_symbol_type *cached;
1848 bfd_size_type cached_size;
1849
1850 /* If there's no work to be done, don't do any. */
1851 if (obj_aout_symbols (abfd) != (aout_symbol_type *) NULL)
1852 return TRUE;
1853
1854 old_external_syms = obj_aout_external_syms (abfd);
1855
1856 if (! aout_get_external_symbols (abfd))
1857 return FALSE;
1858
1859 cached_size = obj_aout_external_sym_count (abfd);
1860 cached_size *= sizeof (aout_symbol_type);
1861 cached = (aout_symbol_type *) bfd_zmalloc (cached_size);
1862 if (cached == NULL && cached_size != 0)
1863 return FALSE;
1864
1865 /* Convert from external symbol information to internal. */
1866 if (! (NAME(aout,translate_symbol_table)
1867 (abfd, cached,
1868 obj_aout_external_syms (abfd),
1869 obj_aout_external_sym_count (abfd),
1870 obj_aout_external_strings (abfd),
1871 obj_aout_external_string_size (abfd),
1872 FALSE)))
1873 {
1874 free (cached);
1875 return FALSE;
1876 }
1877
1878 bfd_get_symcount (abfd) = obj_aout_external_sym_count (abfd);
1879
1880 obj_aout_symbols (abfd) = cached;
1881
1882 /* It is very likely that anybody who calls this function will not
1883 want the external symbol information, so if it was allocated
1884 because of our call to aout_get_external_symbols, we free it up
1885 right away to save space. */
1886 if (old_external_syms == (struct external_nlist *) NULL
1887 && obj_aout_external_syms (abfd) != (struct external_nlist *) NULL)
1888 {
1889#ifdef USE_MMAP
1890 bfd_free_window (&obj_aout_sym_window (abfd));
1891#else
1892 free (obj_aout_external_syms (abfd));
1893#endif
1894 obj_aout_external_syms (abfd) = NULL;
1895 }
1896
1897 return TRUE;
1898}
1899
1900
1901/* We use a hash table when writing out symbols so that we only write
1902 out a particular string once. This helps particularly when the
1903 linker writes out stabs debugging entries, because each different
1904 contributing object file tends to have many duplicate stabs
1905 strings.
1906
1907 This hash table code breaks dbx on SunOS 4.1.3, so we don't do it
1908 if BFD_TRADITIONAL_FORMAT is set. */
1909
1910static bfd_size_type add_to_stringtab
1911 PARAMS ((bfd *, struct bfd_strtab_hash *, const char *, bfd_boolean));
1912static bfd_boolean emit_stringtab
1913 PARAMS ((bfd *, struct bfd_strtab_hash *));
1914
1915/* Get the index of a string in a strtab, adding it if it is not
1916 already present. */
1917
1918static INLINE bfd_size_type
1919add_to_stringtab (abfd, tab, str, copy)
1920 bfd *abfd;
1921 struct bfd_strtab_hash *tab;
1922 const char *str;
1923 bfd_boolean copy;
1924{
1925 bfd_boolean hash;
1926 bfd_size_type index;
1927
1928 /* An index of 0 always means the empty string. */
1929 if (str == 0 || *str == '\0')
1930 return 0;
1931
1932 /* Don't hash if BFD_TRADITIONAL_FORMAT is set, because SunOS dbx
1933 doesn't understand a hashed string table. */
1934 hash = TRUE;
1935 if ((abfd->flags & BFD_TRADITIONAL_FORMAT) != 0)
1936 hash = FALSE;
1937
1938 index = _bfd_stringtab_add (tab, str, hash, copy);
1939
1940 if (index != (bfd_size_type) -1)
1941 {
1942 /* Add BYTES_IN_WORD to the return value to account for the
1943 space taken up by the string table size. */
1944 index += BYTES_IN_WORD;
1945 }
1946
1947 return index;
1948}
1949
1950/* Write out a strtab. ABFD is already at the right location in the
1951 file. */
1952
1953static bfd_boolean
1954emit_stringtab (abfd, tab)
1955 register bfd *abfd;
1956 struct bfd_strtab_hash *tab;
1957{
1958 bfd_byte buffer[BYTES_IN_WORD];
1959 bfd_size_type amt = BYTES_IN_WORD;
1960
1961 /* The string table starts with the size. */
1962 PUT_WORD (abfd, _bfd_stringtab_size (tab) + BYTES_IN_WORD, buffer);
1963 if (bfd_bwrite ((PTR) buffer, amt, abfd) != amt)
1964 return FALSE;
1965
1966 return _bfd_stringtab_emit (abfd, tab);
1967}
1968
1969
1970bfd_boolean
1971NAME(aout,write_syms) (abfd)
1972 bfd *abfd;
1973{
1974 unsigned int count ;
1975 asymbol **generic = bfd_get_outsymbols (abfd);
1976 struct bfd_strtab_hash *strtab;
1977
1978 strtab = _bfd_stringtab_init ();
1979 if (strtab == NULL)
1980 return FALSE;
1981
1982 for (count = 0; count < bfd_get_symcount (abfd); count++)
1983 {
1984 asymbol *g = generic[count];
1985 bfd_size_type indx;
1986 struct external_nlist nsp;
1987 bfd_size_type amt;
1988
1989 indx = add_to_stringtab (abfd, strtab, g->name, FALSE);
1990 if (indx == (bfd_size_type) -1)
1991 goto error_return;
1992 PUT_WORD (abfd, indx, (bfd_byte *) nsp.e_strx);
1993
1994 if (bfd_asymbol_flavour (g) == abfd->xvec->flavour)
1995 {
1996 H_PUT_16 (abfd, aout_symbol (g)->desc, nsp.e_desc);
1997 H_PUT_8 (abfd, aout_symbol (g)->other, nsp.e_other);
1998 H_PUT_8 (abfd, aout_symbol (g)->type, nsp.e_type);
1999 }
2000 else
2001 {
2002 H_PUT_16 (abfd, 0, nsp.e_desc);
2003 H_PUT_8 (abfd, 0, nsp.e_other);
2004 H_PUT_8 (abfd, 0, nsp.e_type);
2005 }
2006
2007 if (! translate_to_native_sym_flags (abfd, g, &nsp))
2008 goto error_return;
2009
2010 amt = EXTERNAL_NLIST_SIZE;
2011 if (bfd_bwrite ((PTR) &nsp, amt, abfd) != amt)
2012 goto error_return;
2013
2014 /* NB: `KEEPIT' currently overlays `udata.p', so set this only
2015 here, at the end. */
2016 g->KEEPIT = count;
2017 }
2018
2019 if (! emit_stringtab (abfd, strtab))
2020 goto error_return;
2021
2022 _bfd_stringtab_free (strtab);
2023
2024 return TRUE;
2025
2026error_return:
2027 _bfd_stringtab_free (strtab);
2028 return FALSE;
2029}
2030
2031
2032long
2033NAME(aout,get_symtab) (abfd, location)
2034 bfd *abfd;
2035 asymbol **location;
2036{
2037 unsigned int counter = 0;
2038 aout_symbol_type *symbase;
2039
2040 if (!NAME(aout,slurp_symbol_table) (abfd))
2041 return -1;
2042
2043 for (symbase = obj_aout_symbols (abfd);
2044 counter++ < bfd_get_symcount (abfd);
2045 )
2046 *(location++) = (asymbol *) (symbase++);
2047 *location++ =0;
2048 return bfd_get_symcount (abfd);
2049}
2050
2051
2052/* Standard reloc stuff. */
2053/* Output standard relocation information to a file in target byte order. */
2054
2055extern void NAME(aout,swap_std_reloc_out)
2056 PARAMS ((bfd *, arelent *, struct reloc_std_external *));
2057
2058void
2059NAME(aout,swap_std_reloc_out) (abfd, g, natptr)
2060 bfd *abfd;
2061 arelent *g;
2062 struct reloc_std_external *natptr;
2063{
2064 int r_index;
2065 asymbol *sym = *(g->sym_ptr_ptr);
2066 int r_extern;
2067 unsigned int r_length;
2068 int r_pcrel;
2069 int r_baserel, r_jmptable, r_relative;
2070 asection *output_section = sym->section->output_section;
2071
2072 PUT_WORD (abfd, g->address, natptr->r_address);
2073
2074 r_length = g->howto->size ; /* Size as a power of two. */
2075 r_pcrel = (int) g->howto->pc_relative; /* Relative to PC? */
2076 /* XXX This relies on relocs coming from a.out files. */
2077 r_baserel = (g->howto->type & 8) != 0;
2078 r_jmptable = (g->howto->type & 16) != 0;
2079 r_relative = (g->howto->type & 32) != 0;
2080
2081#if 0
2082 /* For a standard reloc, the addend is in the object file. */
2083 r_addend = g->addend + (*(g->sym_ptr_ptr))->section->output_section->vma;
2084#endif
2085
2086 /* Name was clobbered by aout_write_syms to be symbol index. */
2087
2088 /* If this relocation is relative to a symbol then set the
2089 r_index to the symbols index, and the r_extern bit.
2090
2091 Absolute symbols can come in in two ways, either as an offset
2092 from the abs section, or as a symbol which has an abs value.
2093 check for that here. */
2094
2095 if (bfd_is_com_section (output_section)
2096 || bfd_is_abs_section (output_section)
2097 || bfd_is_und_section (output_section))
2098 {
2099 if (bfd_abs_section_ptr->symbol == sym)
2100 {
2101 /* Whoops, looked like an abs symbol, but is
2102 really an offset from the abs section. */
2103 r_index = N_ABS;
2104 r_extern = 0;
2105 }
2106 else
2107 {
2108 /* Fill in symbol. */
2109 r_extern = 1;
2110 r_index = (*(g->sym_ptr_ptr))->KEEPIT;
2111 }
2112 }
2113 else
2114 {
2115 /* Just an ordinary section. */
2116 r_extern = 0;
2117 r_index = output_section->target_index;
2118 }
2119
2120 /* Now the fun stuff. */
2121 if (bfd_header_big_endian (abfd))
2122 {
2123 natptr->r_index[0] = r_index >> 16;
2124 natptr->r_index[1] = r_index >> 8;
2125 natptr->r_index[2] = r_index;
2126 natptr->r_type[0] = ((r_extern ? RELOC_STD_BITS_EXTERN_BIG : 0)
2127 | (r_pcrel ? RELOC_STD_BITS_PCREL_BIG : 0)
2128 | (r_baserel ? RELOC_STD_BITS_BASEREL_BIG : 0)
2129 | (r_jmptable ? RELOC_STD_BITS_JMPTABLE_BIG : 0)
2130 | (r_relative ? RELOC_STD_BITS_RELATIVE_BIG : 0)
2131 | (r_length << RELOC_STD_BITS_LENGTH_SH_BIG));
2132 }
2133 else
2134 {
2135 natptr->r_index[2] = r_index >> 16;
2136 natptr->r_index[1] = r_index >> 8;
2137 natptr->r_index[0] = r_index;
2138 natptr->r_type[0] = ((r_extern ? RELOC_STD_BITS_EXTERN_LITTLE : 0)
2139 | (r_pcrel ? RELOC_STD_BITS_PCREL_LITTLE : 0)
2140 | (r_baserel ? RELOC_STD_BITS_BASEREL_LITTLE : 0)
2141 | (r_jmptable ? RELOC_STD_BITS_JMPTABLE_LITTLE : 0)
2142 | (r_relative ? RELOC_STD_BITS_RELATIVE_LITTLE : 0)
2143 | (r_length << RELOC_STD_BITS_LENGTH_SH_LITTLE));
2144 }
2145}
2146
2147/* Extended stuff. */
2148/* Output extended relocation information to a file in target byte order. */
2149
2150extern void NAME(aout,swap_ext_reloc_out)
2151 PARAMS ((bfd *, arelent *, struct reloc_ext_external *));
2152
2153void
2154NAME(aout,swap_ext_reloc_out) (abfd, g, natptr)
2155 bfd *abfd;
2156 arelent *g;
2157 register struct reloc_ext_external *natptr;
2158{
2159 int r_index;
2160 int r_extern;
2161 unsigned int r_type;
2162 bfd_vma r_addend;
2163 asymbol *sym = *(g->sym_ptr_ptr);
2164 asection *output_section = sym->section->output_section;
2165
2166 PUT_WORD (abfd, g->address, natptr->r_address);
2167
2168 r_type = (unsigned int) g->howto->type;
2169
2170 r_addend = g->addend;
2171 if ((sym->flags & BSF_SECTION_SYM) != 0)
2172 r_addend += (*(g->sym_ptr_ptr))->section->output_section->vma;
2173
2174 /* If this relocation is relative to a symbol then set the
2175 r_index to the symbols index, and the r_extern bit.
2176
2177 Absolute symbols can come in in two ways, either as an offset
2178 from the abs section, or as a symbol which has an abs value.
2179 check for that here. */
2180 if (bfd_is_abs_section (bfd_get_section (sym)))
2181 {
2182 r_extern = 0;
2183 r_index = N_ABS;
2184 }
2185 else if ((sym->flags & BSF_SECTION_SYM) == 0)
2186 {
2187 if (bfd_is_und_section (bfd_get_section (sym))
2188 || (sym->flags & BSF_GLOBAL) != 0)
2189 r_extern = 1;
2190 else
2191 r_extern = 0;
2192 r_index = (*(g->sym_ptr_ptr))->KEEPIT;
2193 }
2194 else
2195 {
2196 /* Just an ordinary section. */
2197 r_extern = 0;
2198 r_index = output_section->target_index;
2199 }
2200
2201 /* Now the fun stuff. */
2202 if (bfd_header_big_endian (abfd))
2203 {
2204 natptr->r_index[0] = r_index >> 16;
2205 natptr->r_index[1] = r_index >> 8;
2206 natptr->r_index[2] = r_index;
2207 natptr->r_type[0] = ((r_extern ? RELOC_EXT_BITS_EXTERN_BIG : 0)
2208 | (r_type << RELOC_EXT_BITS_TYPE_SH_BIG));
2209 }
2210 else
2211 {
2212 natptr->r_index[2] = r_index >> 16;
2213 natptr->r_index[1] = r_index >> 8;
2214 natptr->r_index[0] = r_index;
2215 natptr->r_type[0] = ((r_extern ? RELOC_EXT_BITS_EXTERN_LITTLE : 0)
2216 | (r_type << RELOC_EXT_BITS_TYPE_SH_LITTLE));
2217 }
2218
2219 PUT_WORD (abfd, r_addend, natptr->r_addend);
2220}
2221
2222/* BFD deals internally with all things based from the section they're
2223 in. so, something in 10 bytes into a text section with a base of
2224 50 would have a symbol (.text+10) and know .text vma was 50.
2225
2226 Aout keeps all it's symbols based from zero, so the symbol would
2227 contain 60. This macro subs the base of each section from the value
2228 to give the true offset from the section. */
2229
2230#define MOVE_ADDRESS(ad) \
2231 if (r_extern) \
2232 { \
2233 /* Undefined symbol. */ \
2234 cache_ptr->sym_ptr_ptr = symbols + r_index; \
2235 cache_ptr->addend = ad; \
2236 } \
2237 else \
2238 { \
2239 /* Defined, section relative. Replace symbol with pointer to \
2240 symbol which points to section. */ \
2241 switch (r_index) \
2242 { \
2243 case N_TEXT: \
2244 case N_TEXT | N_EXT: \
2245 cache_ptr->sym_ptr_ptr = obj_textsec (abfd)->symbol_ptr_ptr; \
2246 cache_ptr->addend = ad - su->textsec->vma; \
2247 break; \
2248 case N_DATA: \
2249 case N_DATA | N_EXT: \
2250 cache_ptr->sym_ptr_ptr = obj_datasec (abfd)->symbol_ptr_ptr; \
2251 cache_ptr->addend = ad - su->datasec->vma; \
2252 break; \
2253 case N_BSS: \
2254 case N_BSS | N_EXT: \
2255 cache_ptr->sym_ptr_ptr = obj_bsssec (abfd)->symbol_ptr_ptr; \
2256 cache_ptr->addend = ad - su->bsssec->vma; \
2257 break; \
2258 default: \
2259 case N_ABS: \
2260 case N_ABS | N_EXT: \
2261 cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr; \
2262 cache_ptr->addend = ad; \
2263 break; \
2264 } \
2265 }
2266
2267void
2268NAME(aout,swap_ext_reloc_in) (abfd, bytes, cache_ptr, symbols, symcount)
2269 bfd *abfd;
2270 struct reloc_ext_external *bytes;
2271 arelent *cache_ptr;
2272 asymbol **symbols;
2273 bfd_size_type symcount;
2274{
2275 unsigned int r_index;
2276 int r_extern;
2277 unsigned int r_type;
2278 struct aoutdata *su = &(abfd->tdata.aout_data->a);
2279
2280 cache_ptr->address = (GET_SWORD (abfd, bytes->r_address));
2281
2282 /* Now the fun stuff. */
2283 if (bfd_header_big_endian (abfd))
2284 {
2285 r_index = (((unsigned int) bytes->r_index[0] << 16)
2286 | ((unsigned int) bytes->r_index[1] << 8)
2287 | bytes->r_index[2]);
2288 r_extern = (0 != (bytes->r_type[0] & RELOC_EXT_BITS_EXTERN_BIG));
2289 r_type = ((bytes->r_type[0] & RELOC_EXT_BITS_TYPE_BIG)
2290 >> RELOC_EXT_BITS_TYPE_SH_BIG);
2291 }
2292 else
2293 {
2294 r_index = (((unsigned int) bytes->r_index[2] << 16)
2295 | ((unsigned int) bytes->r_index[1] << 8)
2296 | bytes->r_index[0]);
2297 r_extern = (0 != (bytes->r_type[0] & RELOC_EXT_BITS_EXTERN_LITTLE));
2298 r_type = ((bytes->r_type[0] & RELOC_EXT_BITS_TYPE_LITTLE)
2299 >> RELOC_EXT_BITS_TYPE_SH_LITTLE);
2300 }
2301
2302 cache_ptr->howto = howto_table_ext + r_type;
2303
2304 /* Base relative relocs are always against the symbol table,
2305 regardless of the setting of r_extern. r_extern just reflects
2306 whether the symbol the reloc is against is local or global. */
2307 if (r_type == (unsigned int) RELOC_BASE10
2308 || r_type == (unsigned int) RELOC_BASE13
2309 || r_type == (unsigned int) RELOC_BASE22)
2310 r_extern = 1;
2311
2312 if (r_extern && r_index > symcount)
2313 {
2314 /* We could arrange to return an error, but it might be useful
2315 to see the file even if it is bad. */
2316 r_extern = 0;
2317 r_index = N_ABS;
2318 }
2319
2320 MOVE_ADDRESS (GET_SWORD (abfd, bytes->r_addend));
2321}
2322
2323void
2324NAME(aout,swap_std_reloc_in) (abfd, bytes, cache_ptr, symbols, symcount)
2325 bfd *abfd;
2326 struct reloc_std_external *bytes;
2327 arelent *cache_ptr;
2328 asymbol **symbols;
2329 bfd_size_type symcount;
2330{
2331 unsigned int r_index;
2332 int r_extern;
2333 unsigned int r_length;
2334 int r_pcrel;
2335 int r_baserel, r_jmptable, r_relative;
2336 struct aoutdata *su = &(abfd->tdata.aout_data->a);
2337 unsigned int howto_idx;
2338
2339 cache_ptr->address = H_GET_32 (abfd, bytes->r_address);
2340
2341 /* Now the fun stuff. */
2342 if (bfd_header_big_endian (abfd))
2343 {
2344 r_index = (((unsigned int) bytes->r_index[0] << 16)
2345 | ((unsigned int) bytes->r_index[1] << 8)
2346 | bytes->r_index[2]);
2347 r_extern = (0 != (bytes->r_type[0] & RELOC_STD_BITS_EXTERN_BIG));
2348 r_pcrel = (0 != (bytes->r_type[0] & RELOC_STD_BITS_PCREL_BIG));
2349 r_baserel = (0 != (bytes->r_type[0] & RELOC_STD_BITS_BASEREL_BIG));
2350 r_jmptable= (0 != (bytes->r_type[0] & RELOC_STD_BITS_JMPTABLE_BIG));
2351 r_relative= (0 != (bytes->r_type[0] & RELOC_STD_BITS_RELATIVE_BIG));
2352 r_length = ((bytes->r_type[0] & RELOC_STD_BITS_LENGTH_BIG)
2353 >> RELOC_STD_BITS_LENGTH_SH_BIG);
2354 }
2355 else
2356 {
2357 r_index = (((unsigned int) bytes->r_index[2] << 16)
2358 | ((unsigned int) bytes->r_index[1] << 8)
2359 | bytes->r_index[0]);
2360 r_extern = (0 != (bytes->r_type[0] & RELOC_STD_BITS_EXTERN_LITTLE));
2361 r_pcrel = (0 != (bytes->r_type[0] & RELOC_STD_BITS_PCREL_LITTLE));
2362 r_baserel = (0 != (bytes->r_type[0] & RELOC_STD_BITS_BASEREL_LITTLE));
2363 r_jmptable= (0 != (bytes->r_type[0] & RELOC_STD_BITS_JMPTABLE_LITTLE));
2364 r_relative= (0 != (bytes->r_type[0] & RELOC_STD_BITS_RELATIVE_LITTLE));
2365 r_length = ((bytes->r_type[0] & RELOC_STD_BITS_LENGTH_LITTLE)
2366 >> RELOC_STD_BITS_LENGTH_SH_LITTLE);
2367 }
2368
2369 howto_idx = (r_length + 4 * r_pcrel + 8 * r_baserel
2370 + 16 * r_jmptable + 32 * r_relative);
2371 BFD_ASSERT (howto_idx < TABLE_SIZE (howto_table_std));
2372 cache_ptr->howto = howto_table_std + howto_idx;
2373 BFD_ASSERT (cache_ptr->howto->type != (unsigned int) -1);
2374
2375 /* Base relative relocs are always against the symbol table,
2376 regardless of the setting of r_extern. r_extern just reflects
2377 whether the symbol the reloc is against is local or global. */
2378 if (r_baserel)
2379 r_extern = 1;
2380
2381 if (r_extern && r_index > symcount)
2382 {
2383 /* We could arrange to return an error, but it might be useful
2384 to see the file even if it is bad. */
2385 r_extern = 0;
2386 r_index = N_ABS;
2387 }
2388
2389 MOVE_ADDRESS (0);
2390}
2391
2392/* Read and swap the relocs for a section. */
2393
2394bfd_boolean
2395NAME(aout,slurp_reloc_table) (abfd, asect, symbols)
2396 bfd *abfd;
2397 sec_ptr asect;
2398 asymbol **symbols;
2399{
2400 bfd_size_type count;
2401 bfd_size_type reloc_size;
2402 PTR relocs;
2403 arelent *reloc_cache;
2404 size_t each_size;
2405 unsigned int counter = 0;
2406 arelent *cache_ptr;
2407 bfd_size_type amt;
2408
2409 if (asect->relocation)
2410 return TRUE;
2411
2412 if (asect->flags & SEC_CONSTRUCTOR)
2413 return TRUE;
2414
2415 if (asect == obj_datasec (abfd))
2416 reloc_size = exec_hdr (abfd)->a_drsize;
2417 else if (asect == obj_textsec (abfd))
2418 reloc_size = exec_hdr (abfd)->a_trsize;
2419 else if (asect == obj_bsssec (abfd))
2420 reloc_size = 0;
2421 else
2422 {
2423 bfd_set_error (bfd_error_invalid_operation);
2424 return FALSE;
2425 }
2426
2427 if (bfd_seek (abfd, asect->rel_filepos, SEEK_SET) != 0)
2428 return FALSE;
2429
2430 each_size = obj_reloc_entry_size (abfd);
2431
2432 count = reloc_size / each_size;
2433
2434 amt = count * sizeof (arelent);
2435 reloc_cache = (arelent *) bfd_zmalloc (amt);
2436 if (reloc_cache == NULL && count != 0)
2437 return FALSE;
2438
2439 relocs = bfd_malloc (reloc_size);
2440 if (relocs == NULL && reloc_size != 0)
2441 {
2442 free (reloc_cache);
2443 return FALSE;
2444 }
2445
2446 if (bfd_bread (relocs, reloc_size, abfd) != reloc_size)
2447 {
2448 free (relocs);
2449 free (reloc_cache);
2450 return FALSE;
2451 }
2452
2453 cache_ptr = reloc_cache;
2454 if (each_size == RELOC_EXT_SIZE)
2455 {
2456 struct reloc_ext_external *rptr = (struct reloc_ext_external *) relocs;
2457
2458 for (; counter < count; counter++, rptr++, cache_ptr++)
2459 MY_swap_ext_reloc_in (abfd, rptr, cache_ptr, symbols,
2460 (bfd_size_type) bfd_get_symcount (abfd));
2461 }
2462 else
2463 {
2464 struct reloc_std_external *rptr = (struct reloc_std_external *) relocs;
2465
2466 for (; counter < count; counter++, rptr++, cache_ptr++)
2467 MY_swap_std_reloc_in (abfd, rptr, cache_ptr, symbols,
2468 (bfd_size_type) bfd_get_symcount (abfd));
2469 }
2470
2471 free (relocs);
2472
2473 asect->relocation = reloc_cache;
2474 asect->reloc_count = cache_ptr - reloc_cache;
2475
2476 return TRUE;
2477}
2478
2479/* Write out a relocation section into an object file. */
2480
2481bfd_boolean
2482NAME(aout,squirt_out_relocs) (abfd, section)
2483 bfd *abfd;
2484 asection *section;
2485{
2486 arelent **generic;
2487 unsigned char *native, *natptr;
2488 size_t each_size;
2489
2490 unsigned int count = section->reloc_count;
2491 bfd_size_type natsize;
2492
2493 if (count == 0 || section->orelocation == NULL)
2494 return TRUE;
2495
2496 each_size = obj_reloc_entry_size (abfd);
2497 natsize = (bfd_size_type) each_size * count;
2498 native = (unsigned char *) bfd_zalloc (abfd, natsize);
2499 if (!native)
2500 return FALSE;
2501
2502 generic = section->orelocation;
2503
2504 if (each_size == RELOC_EXT_SIZE)
2505 {
2506 for (natptr = native;
2507 count != 0;
2508 --count, natptr += each_size, ++generic)
2509 MY_swap_ext_reloc_out (abfd, *generic,
2510 (struct reloc_ext_external *) natptr);
2511 }
2512 else
2513 {
2514 for (natptr = native;
2515 count != 0;
2516 --count, natptr += each_size, ++generic)
2517 MY_swap_std_reloc_out (abfd, *generic,
2518 (struct reloc_std_external *) natptr);
2519 }
2520
2521 if (bfd_bwrite ((PTR) native, natsize, abfd) != natsize)
2522 {
2523 bfd_release (abfd, native);
2524 return FALSE;
2525 }
2526 bfd_release (abfd, native);
2527
2528 return TRUE;
2529}
2530
2531/* This is stupid. This function should be a boolean predicate. */
2532
2533long
2534NAME(aout,canonicalize_reloc) (abfd, section, relptr, symbols)
2535 bfd *abfd;
2536 sec_ptr section;
2537 arelent **relptr;
2538 asymbol **symbols;
2539{
2540 arelent *tblptr = section->relocation;
2541 unsigned int count;
2542
2543 if (section == obj_bsssec (abfd))
2544 {
2545 *relptr = NULL;
2546 return 0;
2547 }
2548
2549 if (!(tblptr || NAME(aout,slurp_reloc_table) (abfd, section, symbols)))
2550 return -1;
2551
2552 if (section->flags & SEC_CONSTRUCTOR)
2553 {
2554 arelent_chain *chain = section->constructor_chain;
2555 for (count = 0; count < section->reloc_count; count ++)
2556 {
2557 *relptr ++ = &chain->relent;
2558 chain = chain->next;
2559 }
2560 }
2561 else
2562 {
2563 tblptr = section->relocation;
2564
2565 for (count = 0; count++ < section->reloc_count; )
2566 {
2567 *relptr++ = tblptr++;
2568 }
2569 }
2570 *relptr = 0;
2571
2572 return section->reloc_count;
2573}
2574
2575long
2576NAME(aout,get_reloc_upper_bound) (abfd, asect)
2577 bfd *abfd;
2578 sec_ptr asect;
2579{
2580 if (bfd_get_format (abfd) != bfd_object)
2581 {
2582 bfd_set_error (bfd_error_invalid_operation);
2583 return -1;
2584 }
2585
2586 if (asect->flags & SEC_CONSTRUCTOR)
2587 return (sizeof (arelent *) * (asect->reloc_count+1));
2588
2589 if (asect == obj_datasec (abfd))
2590 return (sizeof (arelent *)
2591 * ((exec_hdr (abfd)->a_drsize / obj_reloc_entry_size (abfd))
2592 + 1));
2593
2594 if (asect == obj_textsec (abfd))
2595 return (sizeof (arelent *)
2596 * ((exec_hdr (abfd)->a_trsize / obj_reloc_entry_size (abfd))
2597 + 1));
2598
2599 if (asect == obj_bsssec (abfd))
2600 return sizeof (arelent *);
2601
2602 if (asect == obj_bsssec (abfd))
2603 return 0;
2604
2605 bfd_set_error (bfd_error_invalid_operation);
2606 return -1;
2607}
2608
2609
2610long
2611NAME(aout,get_symtab_upper_bound) (abfd)
2612 bfd *abfd;
2613{
2614 if (!NAME(aout,slurp_symbol_table) (abfd))
2615 return -1;
2616
2617 return (bfd_get_symcount (abfd)+1) * (sizeof (aout_symbol_type *));
2618}
2619
2620alent *
2621NAME(aout,get_lineno) (ignore_abfd, ignore_symbol)
2622 bfd *ignore_abfd ATTRIBUTE_UNUSED;
2623 asymbol *ignore_symbol ATTRIBUTE_UNUSED;
2624{
2625 return (alent *)NULL;
2626}
2627
2628void
2629NAME(aout,get_symbol_info) (ignore_abfd, symbol, ret)
2630 bfd *ignore_abfd ATTRIBUTE_UNUSED;
2631 asymbol *symbol;
2632 symbol_info *ret;
2633{
2634 bfd_symbol_info (symbol, ret);
2635
2636 if (ret->type == '?')
2637 {
2638 int type_code = aout_symbol (symbol)->type & 0xff;
2639 const char *stab_name = bfd_get_stab_name (type_code);
2640 static char buf[10];
2641
2642 if (stab_name == NULL)
2643 {
2644 sprintf (buf, "(%d)", type_code);
2645 stab_name = buf;
2646 }
2647 ret->type = '-';
2648 ret->stab_type = type_code;
2649 ret->stab_other = (unsigned) (aout_symbol (symbol)->other & 0xff);
2650 ret->stab_desc = (unsigned) (aout_symbol (symbol)->desc & 0xffff);
2651 ret->stab_name = stab_name;
2652 }
2653}
2654
2655void
2656NAME(aout,print_symbol) (abfd, afile, symbol, how)
2657 bfd *abfd;
2658 PTR afile;
2659 asymbol *symbol;
2660 bfd_print_symbol_type how;
2661{
2662 FILE *file = (FILE *)afile;
2663
2664 switch (how)
2665 {
2666 case bfd_print_symbol_name:
2667 if (symbol->name)
2668 fprintf (file,"%s", symbol->name);
2669 break;
2670 case bfd_print_symbol_more:
2671 fprintf (file,"%4x %2x %2x",
2672 (unsigned) (aout_symbol (symbol)->desc & 0xffff),
2673 (unsigned) (aout_symbol (symbol)->other & 0xff),
2674 (unsigned) (aout_symbol (symbol)->type));
2675 break;
2676 case bfd_print_symbol_all:
2677 {
2678 const char *section_name = symbol->section->name;
2679
2680 bfd_print_symbol_vandf (abfd, (PTR)file, symbol);
2681
2682 fprintf (file," %-5s %04x %02x %02x",
2683 section_name,
2684 (unsigned) (aout_symbol (symbol)->desc & 0xffff),
2685 (unsigned) (aout_symbol (symbol)->other & 0xff),
2686 (unsigned) (aout_symbol (symbol)->type & 0xff));
2687 if (symbol->name)
2688 fprintf (file," %s", symbol->name);
2689 }
2690 break;
2691 }
2692}
2693
2694/* If we don't have to allocate more than 1MB to hold the generic
2695 symbols, we use the generic minisymbol methord: it's faster, since
2696 it only translates the symbols once, not multiple times. */
2697#define MINISYM_THRESHOLD (1000000 / sizeof (asymbol))
2698
2699/* Read minisymbols. For minisymbols, we use the unmodified a.out
2700 symbols. The minisymbol_to_symbol function translates these into
2701 BFD asymbol structures. */
2702
2703long
2704NAME(aout,read_minisymbols) (abfd, dynamic, minisymsp, sizep)
2705 bfd *abfd;
2706 bfd_boolean dynamic;
2707 PTR *minisymsp;
2708 unsigned int *sizep;
2709{
2710 if (dynamic)
2711 {
2712 /* We could handle the dynamic symbols here as well, but it's
2713 easier to hand them off. */
2714 return _bfd_generic_read_minisymbols (abfd, dynamic, minisymsp, sizep);
2715 }
2716
2717 if (! aout_get_external_symbols (abfd))
2718 return -1;
2719
2720 if (obj_aout_external_sym_count (abfd) < MINISYM_THRESHOLD)
2721 return _bfd_generic_read_minisymbols (abfd, dynamic, minisymsp, sizep);
2722
2723 *minisymsp = (PTR) obj_aout_external_syms (abfd);
2724
2725 /* By passing the external symbols back from this routine, we are
2726 giving up control over the memory block. Clear
2727 obj_aout_external_syms, so that we do not try to free it
2728 ourselves. */
2729 obj_aout_external_syms (abfd) = NULL;
2730
2731 *sizep = EXTERNAL_NLIST_SIZE;
2732 return obj_aout_external_sym_count (abfd);
2733}
2734
2735/* Convert a minisymbol to a BFD asymbol. A minisymbol is just an
2736 unmodified a.out symbol. The SYM argument is a structure returned
2737 by bfd_make_empty_symbol, which we fill in here. */
2738
2739asymbol *
2740NAME(aout,minisymbol_to_symbol) (abfd, dynamic, minisym, sym)
2741 bfd *abfd;
2742 bfd_boolean dynamic;
2743 const PTR minisym;
2744 asymbol *sym;
2745{
2746 if (dynamic
2747 || obj_aout_external_sym_count (abfd) < MINISYM_THRESHOLD)
2748 return _bfd_generic_minisymbol_to_symbol (abfd, dynamic, minisym, sym);
2749
2750 memset (sym, 0, sizeof (aout_symbol_type));
2751
2752 /* We call translate_symbol_table to translate a single symbol. */
2753 if (! (NAME(aout,translate_symbol_table)
2754 (abfd,
2755 (aout_symbol_type *) sym,
2756 (struct external_nlist *) minisym,
2757 (bfd_size_type) 1,
2758 obj_aout_external_strings (abfd),
2759 obj_aout_external_string_size (abfd),
2760 FALSE)))
2761 return NULL;
2762
2763 return sym;
2764}
2765
2766/* Provided a BFD, a section and an offset into the section, calculate
2767 and return the name of the source file and the line nearest to the
2768 wanted location. */
2769
2770bfd_boolean
2771NAME(aout,find_nearest_line)
2772 (abfd, section, symbols, offset, filename_ptr, functionname_ptr, line_ptr)
2773 bfd *abfd;
2774 asection *section;
2775 asymbol **symbols;
2776 bfd_vma offset;
2777 const char **filename_ptr;
2778 const char **functionname_ptr;
2779 unsigned int *line_ptr;
2780{
2781 /* Run down the file looking for the filename, function and linenumber. */
2782 asymbol **p;
2783 const char *directory_name = NULL;
2784 const char *main_file_name = NULL;
2785 const char *current_file_name = NULL;
2786 const char *line_file_name = NULL; /* Value of current_file_name at line number. */
2787 const char *line_directory_name = NULL; /* Value of directory_name at line number. */
2788 bfd_vma low_line_vma = 0;
2789 bfd_vma low_func_vma = 0;
2790 asymbol *func = 0;
2791 bfd_size_type filelen, funclen;
2792 char *buf;
2793
2794 *filename_ptr = abfd->filename;
2795 *functionname_ptr = 0;
2796 *line_ptr = 0;
2797
2798 if (symbols != (asymbol **)NULL)
2799 {
2800 for (p = symbols; *p; p++)
2801 {
2802 aout_symbol_type *q = (aout_symbol_type *) (*p);
2803 next:
2804 switch (q->type)
2805 {
2806 case N_TEXT:
2807 /* If this looks like a file name symbol, and it comes after
2808 the line number we have found so far, but before the
2809 offset, then we have probably not found the right line
2810 number. */
2811 if (q->symbol.value <= offset
2812 && ((q->symbol.value > low_line_vma
2813 && (line_file_name != NULL
2814 || *line_ptr != 0))
2815 || (q->symbol.value > low_func_vma
2816 && func != NULL)))
2817 {
2818 const char *symname;
2819
2820 symname = q->symbol.name;
2821 if (strcmp (symname + strlen (symname) - 2, ".o") == 0)
2822 {
2823 if (q->symbol.value > low_line_vma)
2824 {
2825 *line_ptr = 0;
2826 line_file_name = NULL;
2827 }
2828 if (q->symbol.value > low_func_vma)
2829 func = NULL;
2830 }
2831 }
2832 break;
2833
2834 case N_SO:
2835 /* If this symbol is less than the offset, but greater than
2836 the line number we have found so far, then we have not
2837 found the right line number. */
2838 if (q->symbol.value <= offset)
2839 {
2840 if (q->symbol.value > low_line_vma)
2841 {
2842 *line_ptr = 0;
2843 line_file_name = NULL;
2844 }
2845 if (q->symbol.value > low_func_vma)
2846 func = NULL;
2847 }
2848
2849 main_file_name = current_file_name = q->symbol.name;
2850 /* Look ahead to next symbol to check if that too is an N_SO. */
2851 p++;
2852 if (*p == NULL)
2853 break;
2854 q = (aout_symbol_type *) (*p);
2855 if (q->type != (int)N_SO)
2856 goto next;
2857
2858 /* Found a second N_SO First is directory; second is filename. */
2859 directory_name = current_file_name;
2860 main_file_name = current_file_name = q->symbol.name;
2861 if (obj_textsec (abfd) != section)
2862 goto done;
2863 break;
2864 case N_SOL:
2865 current_file_name = q->symbol.name;
2866 break;
2867
2868 case N_SLINE:
2869
2870 case N_DSLINE:
2871 case N_BSLINE:
2872 /* We'll keep this if it resolves nearer than the one we have
2873 already. */
2874 if (q->symbol.value >= low_line_vma
2875 && q->symbol.value <= offset)
2876 {
2877 *line_ptr = q->desc;
2878 low_line_vma = q->symbol.value;
2879 line_file_name = current_file_name;
2880 line_directory_name = directory_name;
2881 }
2882 break;
2883 case N_FUN:
2884 {
2885 /* We'll keep this if it is nearer than the one we have already. */
2886 if (q->symbol.value >= low_func_vma &&
2887 q->symbol.value <= offset)
2888 {
2889 low_func_vma = q->symbol.value;
2890 func = (asymbol *)q;
2891 }
2892 else if (q->symbol.value > offset)
2893 goto done;
2894 }
2895 break;
2896 }
2897 }
2898 }
2899
2900 done:
2901 if (*line_ptr != 0)
2902 {
2903 main_file_name = line_file_name;
2904 directory_name = line_directory_name;
2905 }
2906
2907 if (main_file_name == NULL
2908 || IS_ABSOLUTE_PATH (main_file_name)
2909 || directory_name == NULL)
2910 filelen = 0;
2911 else
2912 filelen = strlen (directory_name) + strlen (main_file_name);
2913
2914 if (func == NULL)
2915 funclen = 0;
2916 else
2917 funclen = strlen (bfd_asymbol_name (func));
2918
2919 if (adata (abfd).line_buf != NULL)
2920 free (adata (abfd).line_buf);
2921
2922 if (filelen + funclen == 0)
2923 adata (abfd).line_buf = buf = NULL;
2924 else
2925 {
2926 buf = (char *) bfd_malloc (filelen + funclen + 3);
2927 adata (abfd).line_buf = buf;
2928 if (buf == NULL)
2929 return FALSE;
2930 }
2931
2932 if (main_file_name != NULL)
2933 {
2934 if (IS_ABSOLUTE_PATH (main_file_name) || directory_name == NULL)
2935 *filename_ptr = main_file_name;
2936 else
2937 {
2938 sprintf (buf, "%s%s", directory_name, main_file_name);
2939 *filename_ptr = buf;
2940 buf += filelen + 1;
2941 }
2942 }
2943
2944 if (func)
2945 {
2946 const char *function = func->name;
2947 char *colon;
2948
2949 /* The caller expects a symbol name. We actually have a
2950 function name, without the leading underscore. Put the
2951 underscore back in, so that the caller gets a symbol name. */
2952 if (bfd_get_symbol_leading_char (abfd) == '\0')
2953 strcpy (buf, function);
2954 else
2955 {
2956 buf[0] = bfd_get_symbol_leading_char (abfd);
2957 strcpy (buf + 1, function);
2958 }
2959 /* Have to remove : stuff. */
2960 colon = strchr (buf, ':');
2961 if (colon != NULL)
2962 *colon = '\0';
2963 *functionname_ptr = buf;
2964 }
2965
2966 return TRUE;
2967}
2968
2969int
2970NAME(aout,sizeof_headers) (abfd, execable)
2971 bfd *abfd;
2972 bfd_boolean execable ATTRIBUTE_UNUSED;
2973{
2974 return adata (abfd).exec_bytes_size;
2975}
2976
2977/* Free all information we have cached for this BFD. We can always
2978 read it again later if we need it. */
2979
2980bfd_boolean
2981NAME(aout,bfd_free_cached_info) (abfd)
2982 bfd *abfd;
2983{
2984 asection *o;
2985
2986 if (bfd_get_format (abfd) != bfd_object
2987 || abfd->tdata.aout_data == NULL)
2988 return TRUE;
2989
2990#define BFCI_FREE(x) if (x != NULL) { free (x); x = NULL; }
2991 BFCI_FREE (obj_aout_symbols (abfd));
2992#ifdef USE_MMAP
2993 obj_aout_external_syms (abfd) = 0;
2994 bfd_free_window (&obj_aout_sym_window (abfd));
2995 bfd_free_window (&obj_aout_string_window (abfd));
2996 obj_aout_external_strings (abfd) = 0;
2997#else
2998 BFCI_FREE (obj_aout_external_syms (abfd));
2999 BFCI_FREE (obj_aout_external_strings (abfd));
3000#endif
3001 for (o = abfd->sections; o != (asection *) NULL; o = o->next)
3002 BFCI_FREE (o->relocation);
3003#undef BFCI_FREE
3004
3005 return TRUE;
3006}
3007
3008
3009/* a.out link code. */
3010
3011static bfd_boolean aout_link_add_object_symbols
3012 PARAMS ((bfd *, struct bfd_link_info *));
3013static bfd_boolean aout_link_check_archive_element
3014 PARAMS ((bfd *, struct bfd_link_info *, bfd_boolean *));
3015static bfd_boolean aout_link_free_symbols
3016 PARAMS ((bfd *));
3017static bfd_boolean aout_link_check_ar_symbols
3018 PARAMS ((bfd *, struct bfd_link_info *, bfd_boolean *pneeded));
3019static bfd_boolean aout_link_add_symbols
3020 PARAMS ((bfd *, struct bfd_link_info *));
3021
3022/* Routine to create an entry in an a.out link hash table. */
3023
3024struct bfd_hash_entry *
3025NAME(aout,link_hash_newfunc) (entry, table, string)
3026 struct bfd_hash_entry *entry;
3027 struct bfd_hash_table *table;
3028 const char *string;
3029{
3030 struct aout_link_hash_entry *ret = (struct aout_link_hash_entry *) entry;
3031
3032 /* Allocate the structure if it has not already been allocated by a
3033 subclass. */
3034 if (ret == (struct aout_link_hash_entry *) NULL)
3035 ret = ((struct aout_link_hash_entry *)
3036 bfd_hash_allocate (table, sizeof (struct aout_link_hash_entry)));
3037 if (ret == (struct aout_link_hash_entry *) NULL)
3038 return (struct bfd_hash_entry *) ret;
3039
3040 /* Call the allocation method of the superclass. */
3041 ret = ((struct aout_link_hash_entry *)
3042 _bfd_link_hash_newfunc ((struct bfd_hash_entry *) ret,
3043 table, string));
3044 if (ret)
3045 {
3046 /* Set local fields. */
3047 ret->written = FALSE;
3048 ret->indx = -1;
3049 }
3050
3051 return (struct bfd_hash_entry *) ret;
3052}
3053
3054/* Initialize an a.out link hash table. */
3055
3056bfd_boolean
3057NAME(aout,link_hash_table_init) (table, abfd, newfunc)
3058 struct aout_link_hash_table *table;
3059 bfd *abfd;
3060 struct bfd_hash_entry *(*newfunc)
3061 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *,
3062 const char *));
3063{
3064 return _bfd_link_hash_table_init (&table->root, abfd, newfunc);
3065}
3066
3067/* Create an a.out link hash table. */
3068
3069struct bfd_link_hash_table *
3070NAME(aout,link_hash_table_create) (abfd)
3071 bfd *abfd;
3072{
3073 struct aout_link_hash_table *ret;
3074 bfd_size_type amt = sizeof (struct aout_link_hash_table);
3075
3076 ret = (struct aout_link_hash_table *) bfd_malloc (amt);
3077 if (ret == NULL)
3078 return (struct bfd_link_hash_table *) NULL;
3079
3080 if (! NAME(aout,link_hash_table_init) (ret, abfd,
3081 NAME(aout,link_hash_newfunc)))
3082 {
3083 free (ret);
3084 return (struct bfd_link_hash_table *) NULL;
3085 }
3086 return &ret->root;
3087}
3088
3089/* Given an a.out BFD, add symbols to the global hash table as
3090 appropriate. */
3091
3092bfd_boolean
3093NAME(aout,link_add_symbols) (abfd, info)
3094 bfd *abfd;
3095 struct bfd_link_info *info;
3096{
3097 switch (bfd_get_format (abfd))
3098 {
3099 case bfd_object:
3100 return aout_link_add_object_symbols (abfd, info);
3101 case bfd_archive:
3102 return _bfd_generic_link_add_archive_symbols
3103 (abfd, info, aout_link_check_archive_element);
3104 default:
3105 bfd_set_error (bfd_error_wrong_format);
3106 return FALSE;
3107 }
3108}
3109
3110/* Add symbols from an a.out object file. */
3111
3112static bfd_boolean
3113aout_link_add_object_symbols (abfd, info)
3114 bfd *abfd;
3115 struct bfd_link_info *info;
3116{
3117 if (! aout_get_external_symbols (abfd))
3118 return FALSE;
3119 if (! aout_link_add_symbols (abfd, info))
3120 return FALSE;
3121 if (! info->keep_memory)
3122 {
3123 if (! aout_link_free_symbols (abfd))
3124 return FALSE;
3125 }
3126 return TRUE;
3127}
3128
3129/* Check a single archive element to see if we need to include it in
3130 the link. *PNEEDED is set according to whether this element is
3131 needed in the link or not. This is called from
3132 _bfd_generic_link_add_archive_symbols. */
3133
3134static bfd_boolean
3135aout_link_check_archive_element (abfd, info, pneeded)
3136 bfd *abfd;
3137 struct bfd_link_info *info;
3138 bfd_boolean *pneeded;
3139{
3140 if (! aout_get_external_symbols (abfd))
3141 return FALSE;
3142
3143 if (! aout_link_check_ar_symbols (abfd, info, pneeded))
3144 return FALSE;
3145
3146 if (*pneeded)
3147 {
3148 if (! aout_link_add_symbols (abfd, info))
3149 return FALSE;
3150 }
3151
3152 if (! info->keep_memory || ! *pneeded)
3153 {
3154 if (! aout_link_free_symbols (abfd))
3155 return FALSE;
3156 }
3157
3158 return TRUE;
3159}
3160
3161/* Free up the internal symbols read from an a.out file. */
3162
3163static bfd_boolean
3164aout_link_free_symbols (abfd)
3165 bfd *abfd;
3166{
3167 if (obj_aout_external_syms (abfd) != (struct external_nlist *) NULL)
3168 {
3169#ifdef USE_MMAP
3170 bfd_free_window (&obj_aout_sym_window (abfd));
3171#else
3172 free ((PTR) obj_aout_external_syms (abfd));
3173#endif
3174 obj_aout_external_syms (abfd) = (struct external_nlist *) NULL;
3175 }
3176 if (obj_aout_external_strings (abfd) != (char *) NULL)
3177 {
3178#ifdef USE_MMAP
3179 bfd_free_window (&obj_aout_string_window (abfd));
3180#else
3181 free ((PTR) obj_aout_external_strings (abfd));
3182#endif
3183 obj_aout_external_strings (abfd) = (char *) NULL;
3184 }
3185 return TRUE;
3186}
3187
3188/* Look through the internal symbols to see if this object file should
3189 be included in the link. We should include this object file if it
3190 defines any symbols which are currently undefined. If this object
3191 file defines a common symbol, then we may adjust the size of the
3192 known symbol but we do not include the object file in the link
3193 (unless there is some other reason to include it). */
3194
3195static bfd_boolean
3196aout_link_check_ar_symbols (abfd, info, pneeded)
3197 bfd *abfd;
3198 struct bfd_link_info *info;
3199 bfd_boolean *pneeded;
3200{
3201 register struct external_nlist *p;
3202 struct external_nlist *pend;
3203 char *strings;
3204
3205 *pneeded = FALSE;
3206
3207 /* Look through all the symbols. */
3208 p = obj_aout_external_syms (abfd);
3209 pend = p + obj_aout_external_sym_count (abfd);
3210 strings = obj_aout_external_strings (abfd);
3211 for (; p < pend; p++)
3212 {
3213 int type = H_GET_8 (abfd, p->e_type);
3214 const char *name;
3215 struct bfd_link_hash_entry *h;
3216
3217 /* Ignore symbols that are not externally visible. This is an
3218 optimization only, as we check the type more thoroughly
3219 below. */
3220 if (((type & N_EXT) == 0
3221 || (type & N_STAB) != 0
3222 || type == N_FN)
3223 && type != N_WEAKA
3224 && type != N_WEAKT
3225 && type != N_WEAKD
3226 && type != N_WEAKB)
3227 {
3228 if (type == N_WARNING
3229 || type == N_INDR)
3230 ++p;
3231 continue;
3232 }
3233
3234 name = strings + GET_WORD (abfd, p->e_strx);
3235 h = bfd_link_hash_lookup (info->hash, name, FALSE, FALSE, TRUE);
3236
3237 /* We are only interested in symbols that are currently
3238 undefined or common. */
3239 if (h == (struct bfd_link_hash_entry *) NULL
3240 || (h->type != bfd_link_hash_undefined
3241 && h->type != bfd_link_hash_common))
3242 {
3243 if (type == (N_INDR | N_EXT))
3244 ++p;
3245 continue;
3246 }
3247
3248 if (type == (N_TEXT | N_EXT)
3249 || type == (N_DATA | N_EXT)
3250 || type == (N_BSS | N_EXT)
3251 || type == (N_ABS | N_EXT)
3252 || type == (N_INDR | N_EXT))
3253 {
3254 /* This object file defines this symbol. We must link it
3255 in. This is true regardless of whether the current
3256 definition of the symbol is undefined or common.
3257
3258 If the current definition is common, we have a case in
3259 which we have already seen an object file including:
3260 int a;
3261 and this object file from the archive includes:
3262 int a = 5;
3263 In such a case, whether to include this object is target
3264 dependant for backward compatability.
3265
3266 FIXME: The SunOS 4.1.3 linker will pull in the archive
3267 element if the symbol is defined in the .data section,
3268 but not if it is defined in the .text section. That
3269 seems a bit crazy to me, and it has not been implemented
3270 yet. However, it might be correct. */
3271 if (h->type == bfd_link_hash_common)
3272 {
3273 int skip = 0;
3274
3275 switch (info->common_skip_ar_aymbols)
3276 {
3277 case bfd_link_common_skip_text:
3278 skip = (type == (N_TEXT | N_EXT));
3279 break;
3280 case bfd_link_common_skip_data:
3281 skip = (type == (N_DATA | N_EXT));
3282 break;
3283 default:
3284 case bfd_link_common_skip_all:
3285 skip = 1;
3286 break;
3287 }
3288
3289 if (skip)
3290 continue;
3291 }
3292
3293 if (! (*info->callbacks->add_archive_element) (info, abfd, name))
3294 return FALSE;
3295 *pneeded = TRUE;
3296 return TRUE;
3297 }
3298
3299 if (type == (N_UNDF | N_EXT))
3300 {
3301 bfd_vma value;
3302
3303 value = GET_WORD (abfd, p->e_value);
3304 if (value != 0)
3305 {
3306 /* This symbol is common in the object from the archive
3307 file. */
3308 if (h->type == bfd_link_hash_undefined)
3309 {
3310 bfd *symbfd;
3311 unsigned int power;
3312
3313 symbfd = h->u.undef.abfd;
3314 if (symbfd == (bfd *) NULL)
3315 {
3316 /* This symbol was created as undefined from
3317 outside BFD. We assume that we should link
3318 in the object file. This is done for the -u
3319 option in the linker. */
3320 if (! (*info->callbacks->add_archive_element) (info,
3321 abfd,
3322 name))
3323 return FALSE;
3324 *pneeded = TRUE;
3325 return TRUE;
3326 }
3327 /* Turn the current link symbol into a common
3328 symbol. It is already on the undefs list. */
3329 h->type = bfd_link_hash_common;
3330 h->u.c.p = ((struct bfd_link_hash_common_entry *)
3331 bfd_hash_allocate (&info->hash->table,
3332 sizeof (struct bfd_link_hash_common_entry)));
3333 if (h->u.c.p == NULL)
3334 return FALSE;
3335
3336 h->u.c.size = value;
3337
3338 /* FIXME: This isn't quite right. The maximum
3339 alignment of a common symbol should be set by the
3340 architecture of the output file, not of the input
3341 file. */
3342 power = bfd_log2 (value);
3343 if (power > bfd_get_arch_info (abfd)->section_align_power)
3344 power = bfd_get_arch_info (abfd)->section_align_power;
3345 h->u.c.p->alignment_power = power;
3346
3347 h->u.c.p->section = bfd_make_section_old_way (symbfd,
3348 "COMMON");
3349 }
3350 else
3351 {
3352 /* Adjust the size of the common symbol if
3353 necessary. */
3354 if (value > h->u.c.size)
3355 h->u.c.size = value;
3356 }
3357 }
3358 }
3359
3360 if (type == N_WEAKA
3361 || type == N_WEAKT
3362 || type == N_WEAKD
3363 || type == N_WEAKB)
3364 {
3365 /* This symbol is weak but defined. We must pull it in if
3366 the current link symbol is undefined, but we don't want
3367 it if the current link symbol is common. */
3368 if (h->type == bfd_link_hash_undefined)
3369 {
3370 if (! (*info->callbacks->add_archive_element) (info, abfd, name))
3371 return FALSE;
3372 *pneeded = TRUE;
3373 return TRUE;
3374 }
3375 }
3376 }
3377
3378 /* We do not need this object file. */
3379 return TRUE;
3380}
3381
3382/* Add all symbols from an object file to the hash table. */
3383
3384static bfd_boolean
3385aout_link_add_symbols (abfd, info)
3386 bfd *abfd;
3387 struct bfd_link_info *info;
3388{
3389 bfd_boolean (*add_one_symbol)
3390 PARAMS ((struct bfd_link_info *, bfd *, const char *, flagword, asection *,
3391 bfd_vma, const char *, bfd_boolean, bfd_boolean,
3392 struct bfd_link_hash_entry **));
3393 struct external_nlist *syms;
3394 bfd_size_type sym_count;
3395 char *strings;
3396 bfd_boolean copy;
3397 struct aout_link_hash_entry **sym_hash;
3398 register struct external_nlist *p;
3399 struct external_nlist *pend;
3400 bfd_size_type amt;
3401
3402 syms = obj_aout_external_syms (abfd);
3403 sym_count = obj_aout_external_sym_count (abfd);
3404 strings = obj_aout_external_strings (abfd);
3405 if (info->keep_memory)
3406 copy = FALSE;
3407 else
3408 copy = TRUE;
3409
3410 if (aout_backend_info (abfd)->add_dynamic_symbols != NULL)
3411 {
3412 if (! ((*aout_backend_info (abfd)->add_dynamic_symbols)
3413 (abfd, info, &syms, &sym_count, &strings)))
3414 return FALSE;
3415 }
3416
3417 /* We keep a list of the linker hash table entries that correspond
3418 to particular symbols. We could just look them up in the hash
3419 table, but keeping the list is more efficient. Perhaps this
3420 should be conditional on info->keep_memory. */
3421 amt = sym_count * sizeof (struct aout_link_hash_entry *);
3422 sym_hash = (struct aout_link_hash_entry **) bfd_alloc (abfd, amt);
3423 if (sym_hash == NULL && sym_count != 0)
3424 return FALSE;
3425 obj_aout_sym_hashes (abfd) = sym_hash;
3426
3427 add_one_symbol = aout_backend_info (abfd)->add_one_symbol;
3428 if (add_one_symbol == NULL)
3429 add_one_symbol = _bfd_generic_link_add_one_symbol;
3430
3431 p = syms;
3432 pend = p + sym_count;
3433 for (; p < pend; p++, sym_hash++)
3434 {
3435 int type;
3436 const char *name;
3437 bfd_vma value;
3438 asection *section;
3439 flagword flags;
3440 const char *string;
3441
3442 *sym_hash = NULL;
3443
3444 type = H_GET_8 (abfd, p->e_type);
3445
3446 /* Ignore debugging symbols. */
3447 if ((type & N_STAB) != 0)
3448 continue;
3449
3450 name = strings + GET_WORD (abfd, p->e_strx);
3451 value = GET_WORD (abfd, p->e_value);
3452 flags = BSF_GLOBAL;
3453 string = NULL;
3454 switch (type)
3455 {
3456 default:
3457 abort ();
3458
3459 case N_UNDF:
3460 case N_ABS:
3461 case N_TEXT:
3462 case N_DATA:
3463 case N_BSS:
3464 case N_FN_SEQ:
3465 case N_COMM:
3466 case N_SETV:
3467 case N_FN:
3468 /* Ignore symbols that are not externally visible. */
3469 continue;
3470 case N_INDR:
3471 /* Ignore local indirect symbol. */
3472 ++p;
3473 ++sym_hash;
3474 continue;
3475
3476 case N_UNDF | N_EXT:
3477 if (value == 0)
3478 {
3479 section = bfd_und_section_ptr;
3480 flags = 0;
3481 }
3482 else
3483 section = bfd_com_section_ptr;
3484 break;
3485 case N_ABS | N_EXT:
3486 section = bfd_abs_section_ptr;
3487 break;
3488 case N_TEXT | N_EXT:
3489 section = obj_textsec (abfd);
3490 value -= bfd_get_section_vma (abfd, section);
3491 break;
3492 case N_DATA | N_EXT:
3493 case N_SETV | N_EXT:
3494 /* Treat N_SETV symbols as N_DATA symbol; see comment in
3495 translate_from_native_sym_flags. */
3496 section = obj_datasec (abfd);
3497 value -= bfd_get_section_vma (abfd, section);
3498 break;
3499 case N_BSS | N_EXT:
3500 section = obj_bsssec (abfd);
3501 value -= bfd_get_section_vma (abfd, section);
3502 break;
3503 case N_INDR | N_EXT:
3504 /* An indirect symbol. The next symbol is the symbol
3505 which this one really is. */
3506 BFD_ASSERT (p + 1 < pend);
3507 ++p;
3508 string = strings + GET_WORD (abfd, p->e_strx);
3509 section = bfd_ind_section_ptr;
3510 flags |= BSF_INDIRECT;
3511 break;
3512 case N_COMM | N_EXT:
3513 section = bfd_com_section_ptr;
3514 break;
3515 case N_SETA: case N_SETA | N_EXT:
3516 section = bfd_abs_section_ptr;
3517 flags |= BSF_CONSTRUCTOR;
3518 break;
3519 case N_SETT: case N_SETT | N_EXT:
3520 section = obj_textsec (abfd);
3521 flags |= BSF_CONSTRUCTOR;
3522 value -= bfd_get_section_vma (abfd, section);
3523 break;
3524 case N_SETD: case N_SETD | N_EXT:
3525 section = obj_datasec (abfd);
3526 flags |= BSF_CONSTRUCTOR;
3527 value -= bfd_get_section_vma (abfd, section);
3528 break;
3529 case N_SETB: case N_SETB | N_EXT:
3530 section = obj_bsssec (abfd);
3531 flags |= BSF_CONSTRUCTOR;
3532 value -= bfd_get_section_vma (abfd, section);
3533 break;
3534 case N_WARNING:
3535 /* A warning symbol. The next symbol is the one to warn
3536 about. */
3537 BFD_ASSERT (p + 1 < pend);
3538 ++p;
3539 string = name;
3540 name = strings + GET_WORD (abfd, p->e_strx);
3541 section = bfd_und_section_ptr;
3542 flags |= BSF_WARNING;
3543 break;
3544 case N_WEAKU:
3545 section = bfd_und_section_ptr;
3546 flags = BSF_WEAK;
3547 break;
3548 case N_WEAKA:
3549 section = bfd_abs_section_ptr;
3550 flags = BSF_WEAK;
3551 break;
3552 case N_WEAKT:
3553 section = obj_textsec (abfd);
3554 value -= bfd_get_section_vma (abfd, section);
3555 flags = BSF_WEAK;
3556 break;
3557 case N_WEAKD:
3558 section = obj_datasec (abfd);
3559 value -= bfd_get_section_vma (abfd, section);
3560 flags = BSF_WEAK;
3561 break;
3562 case N_WEAKB:
3563 section = obj_bsssec (abfd);
3564 value -= bfd_get_section_vma (abfd, section);
3565 flags = BSF_WEAK;
3566 break;
3567 }
3568
3569 if (! ((*add_one_symbol)
3570 (info, abfd, name, flags, section, value, string, copy, FALSE,
3571 (struct bfd_link_hash_entry **) sym_hash)))
3572 return FALSE;
3573
3574 /* Restrict the maximum alignment of a common symbol based on
3575 the architecture, since a.out has no way to represent
3576 alignment requirements of a section in a .o file. FIXME:
3577 This isn't quite right: it should use the architecture of the
3578 output file, not the input files. */
3579 if ((*sym_hash)->root.type == bfd_link_hash_common
3580 && ((*sym_hash)->root.u.c.p->alignment_power >
3581 bfd_get_arch_info (abfd)->section_align_power))
3582 (*sym_hash)->root.u.c.p->alignment_power =
3583 bfd_get_arch_info (abfd)->section_align_power;
3584
3585 /* If this is a set symbol, and we are not building sets, then
3586 it is possible for the hash entry to not have been set. In
3587 such a case, treat the symbol as not globally defined. */
3588 if ((*sym_hash)->root.type == bfd_link_hash_new)
3589 {
3590 BFD_ASSERT ((flags & BSF_CONSTRUCTOR) != 0);
3591 *sym_hash = NULL;
3592 }
3593
3594 if (type == (N_INDR | N_EXT) || type == N_WARNING)
3595 ++sym_hash;
3596 }
3597
3598 return TRUE;
3599}
3600
3601
3602/* A hash table used for header files with N_BINCL entries. */
3603
3604struct aout_link_includes_table
3605{
3606 struct bfd_hash_table root;
3607};
3608
3609/* A linked list of totals that we have found for a particular header
3610 file. */
3611
3612struct aout_link_includes_totals
3613{
3614 struct aout_link_includes_totals *next;
3615 bfd_vma total;
3616};
3617
3618/* An entry in the header file hash table. */
3619
3620struct aout_link_includes_entry
3621{
3622 struct bfd_hash_entry root;
3623 /* List of totals we have found for this file. */
3624 struct aout_link_includes_totals *totals;
3625};
3626
3627/* Look up an entry in an the header file hash table. */
3628
3629#define aout_link_includes_lookup(table, string, create, copy) \
3630 ((struct aout_link_includes_entry *) \
3631 bfd_hash_lookup (&(table)->root, (string), (create), (copy)))
3632
3633/* During the final link step we need to pass around a bunch of
3634 information, so we do it in an instance of this structure. */
3635
3636struct aout_final_link_info
3637{
3638 /* General link information. */
3639 struct bfd_link_info *info;
3640 /* Output bfd. */
3641 bfd *output_bfd;
3642 /* Reloc file positions. */
3643 file_ptr treloff, dreloff;
3644 /* File position of symbols. */
3645 file_ptr symoff;
3646 /* String table. */
3647 struct bfd_strtab_hash *strtab;
3648 /* Header file hash table. */
3649 struct aout_link_includes_table includes;
3650 /* A buffer large enough to hold the contents of any section. */
3651 bfd_byte *contents;
3652 /* A buffer large enough to hold the relocs of any section. */
3653 PTR relocs;
3654 /* A buffer large enough to hold the symbol map of any input BFD. */
3655 int *symbol_map;
3656 /* A buffer large enough to hold output symbols of any input BFD. */
3657 struct external_nlist *output_syms;
3658};
3659
3660static struct bfd_hash_entry *aout_link_includes_newfunc
3661 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
3662static bfd_boolean aout_link_input_bfd
3663 PARAMS ((struct aout_final_link_info *, bfd *input_bfd));
3664static bfd_boolean aout_link_write_symbols
3665 PARAMS ((struct aout_final_link_info *, bfd *input_bfd));
3666static bfd_boolean aout_link_write_other_symbol
3667 PARAMS ((struct aout_link_hash_entry *, PTR));
3668static bfd_boolean aout_link_input_section
3669 PARAMS ((struct aout_final_link_info *, bfd *input_bfd,
3670 asection *input_section, file_ptr *reloff_ptr,
3671 bfd_size_type rel_size));
3672static bfd_boolean aout_link_input_section_std
3673 PARAMS ((struct aout_final_link_info *, bfd *input_bfd,
3674 asection *input_section, struct reloc_std_external *,
3675 bfd_size_type rel_size, bfd_byte *contents));
3676static bfd_boolean aout_link_input_section_ext
3677 PARAMS ((struct aout_final_link_info *, bfd *input_bfd,
3678 asection *input_section, struct reloc_ext_external *,
3679 bfd_size_type rel_size, bfd_byte *contents));
3680static INLINE asection *aout_reloc_index_to_section
3681 PARAMS ((bfd *, int));
3682static bfd_boolean aout_link_reloc_link_order
3683 PARAMS ((struct aout_final_link_info *, asection *,
3684 struct bfd_link_order *));
3685
3686/* The function to create a new entry in the header file hash table. */
3687
3688static struct bfd_hash_entry *
3689aout_link_includes_newfunc (entry, table, string)
3690 struct bfd_hash_entry *entry;
3691 struct bfd_hash_table *table;
3692 const char *string;
3693{
3694 struct aout_link_includes_entry *ret =
3695 (struct aout_link_includes_entry *) entry;
3696
3697 /* Allocate the structure if it has not already been allocated by a
3698 subclass. */
3699 if (ret == (struct aout_link_includes_entry *) NULL)
3700 ret = ((struct aout_link_includes_entry *)
3701 bfd_hash_allocate (table,
3702 sizeof (struct aout_link_includes_entry)));
3703 if (ret == (struct aout_link_includes_entry *) NULL)
3704 return (struct bfd_hash_entry *) ret;
3705
3706 /* Call the allocation method of the superclass. */
3707 ret = ((struct aout_link_includes_entry *)
3708 bfd_hash_newfunc ((struct bfd_hash_entry *) ret, table, string));
3709 if (ret)
3710 {
3711 /* Set local fields. */
3712 ret->totals = NULL;
3713 }
3714
3715 return (struct bfd_hash_entry *) ret;
3716}
3717
3718/* Do the final link step. This is called on the output BFD. The
3719 INFO structure should point to a list of BFDs linked through the
3720 link_next field which can be used to find each BFD which takes part
3721 in the output. Also, each section in ABFD should point to a list
3722 of bfd_link_order structures which list all the input sections for
3723 the output section. */
3724
3725bfd_boolean
3726NAME(aout,final_link) (abfd, info, callback)
3727 bfd *abfd;
3728 struct bfd_link_info *info;
3729 void (*callback) PARAMS ((bfd *, file_ptr *, file_ptr *, file_ptr *));
3730{
3731 struct aout_final_link_info aout_info;
3732 bfd_boolean includes_hash_initialized = FALSE;
3733 register bfd *sub;
3734 bfd_size_type trsize, drsize;
3735 bfd_size_type max_contents_size;
3736 bfd_size_type max_relocs_size;
3737 bfd_size_type max_sym_count;
3738 bfd_size_type text_size;
3739 file_ptr text_end;
3740 register struct bfd_link_order *p;
3741 asection *o;
3742 bfd_boolean have_link_order_relocs;
3743
3744 if (info->shared)
3745 abfd->flags |= DYNAMIC;
3746
3747 aout_info.info = info;
3748 aout_info.output_bfd = abfd;
3749 aout_info.contents = NULL;
3750 aout_info.relocs = NULL;
3751 aout_info.symbol_map = NULL;
3752 aout_info.output_syms = NULL;
3753
3754 if (! bfd_hash_table_init_n (&aout_info.includes.root,
3755 aout_link_includes_newfunc,
3756 251))
3757 goto error_return;
3758 includes_hash_initialized = TRUE;
3759
3760 /* Figure out the largest section size. Also, if generating
3761 relocateable output, count the relocs. */
3762 trsize = 0;
3763 drsize = 0;
3764 max_contents_size = 0;
3765 max_relocs_size = 0;
3766 max_sym_count = 0;
3767 for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
3768 {
3769 bfd_size_type sz;
3770
3771 if (info->relocateable)
3772 {
3773 if (bfd_get_flavour (sub) == bfd_target_aout_flavour)
3774 {
3775 trsize += exec_hdr (sub)->a_trsize;
3776 drsize += exec_hdr (sub)->a_drsize;
3777 }
3778 else
3779 {
3780 /* FIXME: We need to identify the .text and .data sections
3781 and call get_reloc_upper_bound and canonicalize_reloc to
3782 work out the number of relocs needed, and then multiply
3783 by the reloc size. */
3784 (*_bfd_error_handler)
3785 (_("%s: relocateable link from %s to %s not supported"),
3786 bfd_get_filename (abfd),
3787 sub->xvec->name, abfd->xvec->name);
3788 bfd_set_error (bfd_error_invalid_operation);
3789 goto error_return;
3790 }
3791 }
3792
3793 if (bfd_get_flavour (sub) == bfd_target_aout_flavour)
3794 {
3795 sz = bfd_section_size (sub, obj_textsec (sub));
3796 if (sz > max_contents_size)
3797 max_contents_size = sz;
3798 sz = bfd_section_size (sub, obj_datasec (sub));
3799 if (sz > max_contents_size)
3800 max_contents_size = sz;
3801
3802 sz = exec_hdr (sub)->a_trsize;
3803 if (sz > max_relocs_size)
3804 max_relocs_size = sz;
3805 sz = exec_hdr (sub)->a_drsize;
3806 if (sz > max_relocs_size)
3807 max_relocs_size = sz;
3808
3809 sz = obj_aout_external_sym_count (sub);
3810 if (sz > max_sym_count)
3811 max_sym_count = sz;
3812 }
3813 }
3814
3815 if (info->relocateable)
3816 {
3817 if (obj_textsec (abfd) != (asection *) NULL)
3818 trsize += (_bfd_count_link_order_relocs (obj_textsec (abfd)
3819 ->link_order_head)
3820 * obj_reloc_entry_size (abfd));
3821 if (obj_datasec (abfd) != (asection *) NULL)
3822 drsize += (_bfd_count_link_order_relocs (obj_datasec (abfd)
3823 ->link_order_head)
3824 * obj_reloc_entry_size (abfd));
3825 }
3826
3827 exec_hdr (abfd)->a_trsize = trsize;
3828 exec_hdr (abfd)->a_drsize = drsize;
3829
3830 exec_hdr (abfd)->a_entry = bfd_get_start_address (abfd);
3831
3832 /* Adjust the section sizes and vmas according to the magic number.
3833 This sets a_text, a_data and a_bss in the exec_hdr and sets the
3834 filepos for each section. */
3835 if (! NAME(aout,adjust_sizes_and_vmas) (abfd, &text_size, &text_end))
3836 goto error_return;
3837
3838 /* The relocation and symbol file positions differ among a.out
3839 targets. We are passed a callback routine from the backend
3840 specific code to handle this.
3841 FIXME: At this point we do not know how much space the symbol
3842 table will require. This will not work for any (nonstandard)
3843 a.out target that needs to know the symbol table size before it
3844 can compute the relocation file positions. This may or may not
3845 be the case for the hp300hpux target, for example. */
3846 (*callback) (abfd, &aout_info.treloff, &aout_info.dreloff,
3847 &aout_info.symoff);
3848 obj_textsec (abfd)->rel_filepos = aout_info.treloff;
3849 obj_datasec (abfd)->rel_filepos = aout_info.dreloff;
3850 obj_sym_filepos (abfd) = aout_info.symoff;
3851
3852 /* We keep a count of the symbols as we output them. */
3853 obj_aout_external_sym_count (abfd) = 0;
3854
3855 /* We accumulate the string table as we write out the symbols. */
3856 aout_info.strtab = _bfd_stringtab_init ();
3857 if (aout_info.strtab == NULL)
3858 goto error_return;
3859
3860 /* Allocate buffers to hold section contents and relocs. */
3861 aout_info.contents = (bfd_byte *) bfd_malloc (max_contents_size);
3862 aout_info.relocs = (PTR) bfd_malloc (max_relocs_size);
3863 aout_info.symbol_map = (int *) bfd_malloc (max_sym_count * sizeof (int *));
3864 aout_info.output_syms = ((struct external_nlist *)
3865 bfd_malloc ((max_sym_count + 1)
3866 * sizeof (struct external_nlist)));
3867 if ((aout_info.contents == NULL && max_contents_size != 0)
3868 || (aout_info.relocs == NULL && max_relocs_size != 0)
3869 || (aout_info.symbol_map == NULL && max_sym_count != 0)
3870 || aout_info.output_syms == NULL)
3871 goto error_return;
3872
3873 /* If we have a symbol named __DYNAMIC, force it out now. This is
3874 required by SunOS. Doing this here rather than in sunos.c is a
3875 hack, but it's easier than exporting everything which would be
3876 needed. */
3877 {
3878 struct aout_link_hash_entry *h;
3879
3880 h = aout_link_hash_lookup (aout_hash_table (info), "__DYNAMIC",
3881 FALSE, FALSE, FALSE);
3882 if (h != NULL)
3883 aout_link_write_other_symbol (h, &aout_info);
3884 }
3885
3886 /* The most time efficient way to do the link would be to read all
3887 the input object files into memory and then sort out the
3888 information into the output file. Unfortunately, that will
3889 probably use too much memory. Another method would be to step
3890 through everything that composes the text section and write it
3891 out, and then everything that composes the data section and write
3892 it out, and then write out the relocs, and then write out the
3893 symbols. Unfortunately, that requires reading stuff from each
3894 input file several times, and we will not be able to keep all the
3895 input files open simultaneously, and reopening them will be slow.
3896
3897 What we do is basically process one input file at a time. We do
3898 everything we need to do with an input file once--copy over the
3899 section contents, handle the relocation information, and write
3900 out the symbols--and then we throw away the information we read
3901 from it. This approach requires a lot of lseeks of the output
3902 file, which is unfortunate but still faster than reopening a lot
3903 of files.
3904
3905 We use the output_has_begun field of the input BFDs to see
3906 whether we have already handled it. */
3907 for (sub = info->input_bfds; sub != (bfd *) NULL; sub = sub->link_next)
3908 sub->output_has_begun = FALSE;
3909
3910 /* Mark all sections which are to be included in the link. This
3911 will normally be every section. We need to do this so that we
3912 can identify any sections which the linker has decided to not
3913 include. */
3914 for (o = abfd->sections; o != NULL; o = o->next)
3915 {
3916 for (p = o->link_order_head; p != NULL; p = p->next)
3917 if (p->type == bfd_indirect_link_order)
3918 p->u.indirect.section->linker_mark = TRUE;
3919 }
3920
3921 have_link_order_relocs = FALSE;
3922 for (o = abfd->sections; o != (asection *) NULL; o = o->next)
3923 {
3924 for (p = o->link_order_head;
3925 p != (struct bfd_link_order *) NULL;
3926 p = p->next)
3927 {
3928 if (p->type == bfd_indirect_link_order
3929 && (bfd_get_flavour (p->u.indirect.section->owner)
3930 == bfd_target_aout_flavour))
3931 {
3932 bfd *input_bfd;
3933
3934 input_bfd = p->u.indirect.section->owner;
3935 if (! input_bfd->output_has_begun)
3936 {
3937 if (! aout_link_input_bfd (&aout_info, input_bfd))
3938 goto error_return;
3939 input_bfd->output_has_begun = TRUE;
3940 }
3941 }
3942 else if (p->type == bfd_section_reloc_link_order
3943 || p->type == bfd_symbol_reloc_link_order)
3944 {
3945 /* These are handled below. */
3946 have_link_order_relocs = TRUE;
3947 }
3948 else
3949 {
3950 if (! _bfd_default_link_order (abfd, info, o, p))
3951 goto error_return;
3952 }
3953 }
3954 }
3955
3956 /* Write out any symbols that we have not already written out. */
3957 aout_link_hash_traverse (aout_hash_table (info),
3958 aout_link_write_other_symbol,
3959 (PTR) &aout_info);
3960
3961 /* Now handle any relocs we were asked to create by the linker.
3962 These did not come from any input file. We must do these after
3963 we have written out all the symbols, so that we know the symbol
3964 indices to use. */
3965 if (have_link_order_relocs)
3966 {
3967 for (o = abfd->sections; o != (asection *) NULL; o = o->next)
3968 {
3969 for (p = o->link_order_head;
3970 p != (struct bfd_link_order *) NULL;
3971 p = p->next)
3972 {
3973 if (p->type == bfd_section_reloc_link_order
3974 || p->type == bfd_symbol_reloc_link_order)
3975 {
3976 if (! aout_link_reloc_link_order (&aout_info, o, p))
3977 goto error_return;
3978 }
3979 }
3980 }
3981 }
3982
3983 if (aout_info.contents != NULL)
3984 {
3985 free (aout_info.contents);
3986 aout_info.contents = NULL;
3987 }
3988 if (aout_info.relocs != NULL)
3989 {
3990 free (aout_info.relocs);
3991 aout_info.relocs = NULL;
3992 }
3993 if (aout_info.symbol_map != NULL)
3994 {
3995 free (aout_info.symbol_map);
3996 aout_info.symbol_map = NULL;
3997 }
3998 if (aout_info.output_syms != NULL)
3999 {
4000 free (aout_info.output_syms);
4001 aout_info.output_syms = NULL;
4002 }
4003 if (includes_hash_initialized)
4004 {
4005 bfd_hash_table_free (&aout_info.includes.root);
4006 includes_hash_initialized = FALSE;
4007 }
4008
4009 /* Finish up any dynamic linking we may be doing. */
4010 if (aout_backend_info (abfd)->finish_dynamic_link != NULL)
4011 {
4012 if (! (*aout_backend_info (abfd)->finish_dynamic_link) (abfd, info))
4013 goto error_return;
4014 }
4015
4016 /* Update the header information. */
4017 abfd->symcount = obj_aout_external_sym_count (abfd);
4018 exec_hdr (abfd)->a_syms = abfd->symcount * EXTERNAL_NLIST_SIZE;
4019 obj_str_filepos (abfd) = obj_sym_filepos (abfd) + exec_hdr (abfd)->a_syms;
4020 obj_textsec (abfd)->reloc_count =
4021 exec_hdr (abfd)->a_trsize / obj_reloc_entry_size (abfd);
4022 obj_datasec (abfd)->reloc_count =
4023 exec_hdr (abfd)->a_drsize / obj_reloc_entry_size (abfd);
4024
4025 /* Write out the string table, unless there are no symbols. */
4026 if (abfd->symcount > 0)
4027 {
4028 if (bfd_seek (abfd, obj_str_filepos (abfd), SEEK_SET) != 0
4029 || ! emit_stringtab (abfd, aout_info.strtab))
4030 goto error_return;
4031 }
4032 else if (obj_textsec (abfd)->reloc_count == 0
4033 && obj_datasec (abfd)->reloc_count == 0)
4034 {
4035 bfd_byte b;
4036 file_ptr pos;
4037
4038 b = 0;
4039 pos = obj_datasec (abfd)->filepos + exec_hdr (abfd)->a_data - 1;
4040 if (bfd_seek (abfd, pos, SEEK_SET) != 0
4041 || bfd_bwrite (&b, (bfd_size_type) 1, abfd) != 1)
4042 goto error_return;
4043 }
4044
4045 return TRUE;
4046
4047 error_return:
4048 if (aout_info.contents != NULL)
4049 free (aout_info.contents);
4050 if (aout_info.relocs != NULL)
4051 free (aout_info.relocs);
4052 if (aout_info.symbol_map != NULL)
4053 free (aout_info.symbol_map);
4054 if (aout_info.output_syms != NULL)
4055 free (aout_info.output_syms);
4056 if (includes_hash_initialized)
4057 bfd_hash_table_free (&aout_info.includes.root);
4058 return FALSE;
4059}
4060
4061/* Link an a.out input BFD into the output file. */
4062
4063static bfd_boolean
4064aout_link_input_bfd (finfo, input_bfd)
4065 struct aout_final_link_info *finfo;
4066 bfd *input_bfd;
4067{
4068 bfd_size_type sym_count;
4069
4070 BFD_ASSERT (bfd_get_format (input_bfd) == bfd_object);
4071
4072 /* If this is a dynamic object, it may need special handling. */
4073 if ((input_bfd->flags & DYNAMIC) != 0
4074 && aout_backend_info (input_bfd)->link_dynamic_object != NULL)
4075 {
4076 return ((*aout_backend_info (input_bfd)->link_dynamic_object)
4077 (finfo->info, input_bfd));
4078 }
4079
4080 /* Get the symbols. We probably have them already, unless
4081 finfo->info->keep_memory is FALSE. */
4082 if (! aout_get_external_symbols (input_bfd))
4083 return FALSE;
4084
4085 sym_count = obj_aout_external_sym_count (input_bfd);
4086
4087 /* Write out the symbols and get a map of the new indices. The map
4088 is placed into finfo->symbol_map. */
4089 if (! aout_link_write_symbols (finfo, input_bfd))
4090 return FALSE;
4091
4092 /* Relocate and write out the sections. These functions use the
4093 symbol map created by aout_link_write_symbols. The linker_mark
4094 field will be set if these sections are to be included in the
4095 link, which will normally be the case. */
4096 if (obj_textsec (input_bfd)->linker_mark)
4097 {
4098 if (! aout_link_input_section (finfo, input_bfd,
4099 obj_textsec (input_bfd),
4100 &finfo->treloff,
4101 exec_hdr (input_bfd)->a_trsize))
4102 return FALSE;
4103 }
4104 if (obj_datasec (input_bfd)->linker_mark)
4105 {
4106 if (! aout_link_input_section (finfo, input_bfd,
4107 obj_datasec (input_bfd),
4108 &finfo->dreloff,
4109 exec_hdr (input_bfd)->a_drsize))
4110 return FALSE;
4111 }
4112
4113 /* If we are not keeping memory, we don't need the symbols any
4114 longer. We still need them if we are keeping memory, because the
4115 strings in the hash table point into them. */
4116 if (! finfo->info->keep_memory)
4117 {
4118 if (! aout_link_free_symbols (input_bfd))
4119 return FALSE;
4120 }
4121
4122 return TRUE;
4123}
4124
4125/* Adjust and write out the symbols for an a.out file. Set the new
4126 symbol indices into a symbol_map. */
4127
4128static bfd_boolean
4129aout_link_write_symbols (finfo, input_bfd)
4130 struct aout_final_link_info *finfo;
4131 bfd *input_bfd;
4132{
4133 bfd *output_bfd;
4134 bfd_size_type sym_count;
4135 char *strings;
4136 enum bfd_link_strip strip;
4137 enum bfd_link_discard discard;
4138 struct external_nlist *outsym;
4139 bfd_size_type strtab_index;
4140 register struct external_nlist *sym;
4141 struct external_nlist *sym_end;
4142 struct aout_link_hash_entry **sym_hash;
4143 int *symbol_map;
4144 bfd_boolean pass;
4145 bfd_boolean skip_next;
4146
4147 output_bfd = finfo->output_bfd;
4148 sym_count = obj_aout_external_sym_count (input_bfd);
4149 strings = obj_aout_external_strings (input_bfd);
4150 strip = finfo->info->strip;
4151 discard = finfo->info->discard;
4152 outsym = finfo->output_syms;
4153
4154 /* First write out a symbol for this object file, unless we are
4155 discarding such symbols. */
4156 if (strip != strip_all
4157 && (strip != strip_some
4158 || bfd_hash_lookup (finfo->info->keep_hash, input_bfd->filename,
4159 FALSE, FALSE) != NULL)
4160 && discard != discard_all)
4161 {
4162 H_PUT_8 (output_bfd, N_TEXT, outsym->e_type);
4163 H_PUT_8 (output_bfd, 0, outsym->e_other);
4164 H_PUT_16 (output_bfd, 0, outsym->e_desc);
4165 strtab_index = add_to_stringtab (output_bfd, finfo->strtab,
4166 input_bfd->filename, FALSE);
4167 if (strtab_index == (bfd_size_type) -1)
4168 return FALSE;
4169 PUT_WORD (output_bfd, strtab_index, outsym->e_strx);
4170 PUT_WORD (output_bfd,
4171 (bfd_get_section_vma (output_bfd,
4172 obj_textsec (input_bfd)->output_section)
4173 + obj_textsec (input_bfd)->output_offset),
4174 outsym->e_value);
4175 ++obj_aout_external_sym_count (output_bfd);
4176 ++outsym;
4177 }
4178
4179 pass = FALSE;
4180 skip_next = FALSE;
4181 sym = obj_aout_external_syms (input_bfd);
4182 sym_end = sym + sym_count;
4183 sym_hash = obj_aout_sym_hashes (input_bfd);
4184 symbol_map = finfo->symbol_map;
4185 memset (symbol_map, 0, (size_t) sym_count * sizeof *symbol_map);
4186 for (; sym < sym_end; sym++, sym_hash++, symbol_map++)
4187 {
4188 const char *name;
4189 int type;
4190 struct aout_link_hash_entry *h;
4191 bfd_boolean skip;
4192 asection *symsec;
4193 bfd_vma val = 0;
4194 bfd_boolean copy;
4195
4196 /* We set *symbol_map to 0 above for all symbols. If it has
4197 already been set to -1 for this symbol, it means that we are
4198 discarding it because it appears in a duplicate header file.
4199 See the N_BINCL code below. */
4200 if (*symbol_map == -1)
4201 continue;
4202
4203 /* Initialize *symbol_map to -1, which means that the symbol was
4204 not copied into the output file. We will change it later if
4205 we do copy the symbol over. */
4206 *symbol_map = -1;
4207
4208 type = H_GET_8 (input_bfd, sym->e_type);
4209 name = strings + GET_WORD (input_bfd, sym->e_strx);
4210
4211 h = NULL;
4212
4213 if (pass)
4214 {
4215 /* Pass this symbol through. It is the target of an
4216 indirect or warning symbol. */
4217 val = GET_WORD (input_bfd, sym->e_value);
4218 pass = FALSE;
4219 }
4220 else if (skip_next)
4221 {
4222 /* Skip this symbol, which is the target of an indirect
4223 symbol that we have changed to no longer be an indirect
4224 symbol. */
4225 skip_next = FALSE;
4226 continue;
4227 }
4228 else
4229 {
4230 struct aout_link_hash_entry *hresolve;
4231
4232 /* We have saved the hash table entry for this symbol, if
4233 there is one. Note that we could just look it up again
4234 in the hash table, provided we first check that it is an
4235 external symbol. */
4236 h = *sym_hash;
4237
4238 /* Use the name from the hash table, in case the symbol was
4239 wrapped. */
4240 if (h != NULL
4241 && h->root.type != bfd_link_hash_warning)
4242 name = h->root.root.string;
4243
4244 /* If this is an indirect or warning symbol, then change
4245 hresolve to the base symbol. We also change *sym_hash so
4246 that the relocation routines relocate against the real
4247 symbol. */
4248 hresolve = h;
4249 if (h != (struct aout_link_hash_entry *) NULL
4250 && (h->root.type == bfd_link_hash_indirect
4251 || h->root.type == bfd_link_hash_warning))
4252 {
4253 hresolve = (struct aout_link_hash_entry *) h->root.u.i.link;
4254 while (hresolve->root.type == bfd_link_hash_indirect
4255 || hresolve->root.type == bfd_link_hash_warning)
4256 hresolve = ((struct aout_link_hash_entry *)
4257 hresolve->root.u.i.link);
4258 *sym_hash = hresolve;
4259 }
4260
4261 /* If the symbol has already been written out, skip it. */
4262 if (h != (struct aout_link_hash_entry *) NULL
4263 && h->written)
4264 {
4265 if ((type & N_TYPE) == N_INDR
4266 || type == N_WARNING)
4267 skip_next = TRUE;
4268 *symbol_map = h->indx;
4269 continue;
4270 }
4271
4272 /* See if we are stripping this symbol. */
4273 skip = FALSE;
4274 switch (strip)
4275 {
4276 case strip_none:
4277 break;
4278 case strip_debugger:
4279 if ((type & N_STAB) != 0)
4280 skip = TRUE;
4281 break;
4282 case strip_some:
4283 if (bfd_hash_lookup (finfo->info->keep_hash, name, FALSE, FALSE)
4284 == NULL)
4285 skip = TRUE;
4286 break;
4287 case strip_all:
4288 skip = TRUE;
4289 break;
4290 }
4291 if (skip)
4292 {
4293 if (h != (struct aout_link_hash_entry *) NULL)
4294 h->written = TRUE;
4295 continue;
4296 }
4297
4298 /* Get the value of the symbol. */
4299 if ((type & N_TYPE) == N_TEXT
4300 || type == N_WEAKT)
4301 symsec = obj_textsec (input_bfd);
4302 else if ((type & N_TYPE) == N_DATA
4303 || type == N_WEAKD)
4304 symsec = obj_datasec (input_bfd);
4305 else if ((type & N_TYPE) == N_BSS
4306 || type == N_WEAKB)
4307 symsec = obj_bsssec (input_bfd);
4308 else if ((type & N_TYPE) == N_ABS
4309 || type == N_WEAKA)
4310 symsec = bfd_abs_section_ptr;
4311 else if (((type & N_TYPE) == N_INDR
4312 && (hresolve == (struct aout_link_hash_entry *) NULL
4313 || (hresolve->root.type != bfd_link_hash_defined
4314 && hresolve->root.type != bfd_link_hash_defweak
4315 && hresolve->root.type != bfd_link_hash_common)))
4316 || type == N_WARNING)
4317 {
4318 /* Pass the next symbol through unchanged. The
4319 condition above for indirect symbols is so that if
4320 the indirect symbol was defined, we output it with
4321 the correct definition so the debugger will
4322 understand it. */
4323 pass = TRUE;
4324 val = GET_WORD (input_bfd, sym->e_value);
4325 symsec = NULL;
4326 }
4327 else if ((type & N_STAB) != 0)
4328 {
4329 val = GET_WORD (input_bfd, sym->e_value);
4330 symsec = NULL;
4331 }
4332 else
4333 {
4334 /* If we get here with an indirect symbol, it means that
4335 we are outputting it with a real definition. In such
4336 a case we do not want to output the next symbol,
4337 which is the target of the indirection. */
4338 if ((type & N_TYPE) == N_INDR)
4339 skip_next = TRUE;
4340
4341 symsec = NULL;
4342
4343 /* We need to get the value from the hash table. We use
4344 hresolve so that if we have defined an indirect
4345 symbol we output the final definition. */
4346 if (h == (struct aout_link_hash_entry *) NULL)
4347 {
4348 switch (type & N_TYPE)
4349 {
4350 case N_SETT:
4351 symsec = obj_textsec (input_bfd);
4352 break;
4353 case N_SETD:
4354 symsec = obj_datasec (input_bfd);
4355 break;
4356 case N_SETB:
4357 symsec = obj_bsssec (input_bfd);
4358 break;
4359 case N_SETA:
4360 symsec = bfd_abs_section_ptr;
4361 break;
4362 default:
4363 val = 0;
4364 break;
4365 }
4366 }
4367 else if (hresolve->root.type == bfd_link_hash_defined
4368 || hresolve->root.type == bfd_link_hash_defweak)
4369 {
4370 asection *input_section;
4371 asection *output_section;
4372
4373 /* This case usually means a common symbol which was
4374 turned into a defined symbol. */
4375 input_section = hresolve->root.u.def.section;
4376 output_section = input_section->output_section;
4377 BFD_ASSERT (bfd_is_abs_section (output_section)
4378 || output_section->owner == output_bfd);
4379 val = (hresolve->root.u.def.value
4380 + bfd_get_section_vma (output_bfd, output_section)
4381 + input_section->output_offset);
4382
4383 /* Get the correct type based on the section. If
4384 this is a constructed set, force it to be
4385 globally visible. */
4386 if (type == N_SETT
4387 || type == N_SETD
4388 || type == N_SETB
4389 || type == N_SETA)
4390 type |= N_EXT;
4391
4392 type &=~ N_TYPE;
4393
4394 if (output_section == obj_textsec (output_bfd))
4395 type |= (hresolve->root.type == bfd_link_hash_defined
4396 ? N_TEXT
4397 : N_WEAKT);
4398 else if (output_section == obj_datasec (output_bfd))
4399 type |= (hresolve->root.type == bfd_link_hash_defined
4400 ? N_DATA
4401 : N_WEAKD);
4402 else if (output_section == obj_bsssec (output_bfd))
4403 type |= (hresolve->root.type == bfd_link_hash_defined
4404 ? N_BSS
4405 : N_WEAKB);
4406 else
4407 type |= (hresolve->root.type == bfd_link_hash_defined
4408 ? N_ABS
4409 : N_WEAKA);
4410 }
4411 else if (hresolve->root.type == bfd_link_hash_common)
4412 val = hresolve->root.u.c.size;
4413 else if (hresolve->root.type == bfd_link_hash_undefweak)
4414 {
4415 val = 0;
4416 type = N_WEAKU;
4417 }
4418 else
4419 val = 0;
4420 }
4421 if (symsec != (asection *) NULL)
4422 val = (symsec->output_section->vma
4423 + symsec->output_offset
4424 + (GET_WORD (input_bfd, sym->e_value)
4425 - symsec->vma));
4426
4427 /* If this is a global symbol set the written flag, and if
4428 it is a local symbol see if we should discard it. */
4429 if (h != (struct aout_link_hash_entry *) NULL)
4430 {
4431 h->written = TRUE;
4432 h->indx = obj_aout_external_sym_count (output_bfd);
4433 }
4434 else if ((type & N_TYPE) != N_SETT
4435 && (type & N_TYPE) != N_SETD
4436 && (type & N_TYPE) != N_SETB
4437 && (type & N_TYPE) != N_SETA)
4438 {
4439 switch (discard)
4440 {
4441 case discard_none:
4442 case discard_sec_merge:
4443 break;
4444 case discard_l:
4445 if ((type & N_STAB) == 0
4446 && bfd_is_local_label_name (input_bfd, name))
4447 skip = TRUE;
4448 break;
4449 case discard_all:
4450 skip = TRUE;
4451 break;
4452 }
4453 if (skip)
4454 {
4455 pass = FALSE;
4456 continue;
4457 }
4458 }
4459
4460 /* An N_BINCL symbol indicates the start of the stabs
4461 entries for a header file. We need to scan ahead to the
4462 next N_EINCL symbol, ignoring nesting, adding up all the
4463 characters in the symbol names, not including the file
4464 numbers in types (the first number after an open
4465 parenthesis). */
4466 if (type == (int) N_BINCL)
4467 {
4468 struct external_nlist *incl_sym;
4469 int nest;
4470 struct aout_link_includes_entry *incl_entry;
4471 struct aout_link_includes_totals *t;
4472
4473 val = 0;
4474 nest = 0;
4475 for (incl_sym = sym + 1; incl_sym < sym_end; incl_sym++)
4476 {
4477 int incl_type;
4478
4479 incl_type = H_GET_8 (input_bfd, incl_sym->e_type);
4480 if (incl_type == (int) N_EINCL)
4481 {
4482 if (nest == 0)
4483 break;
4484 --nest;
4485 }
4486 else if (incl_type == (int) N_BINCL)
4487 ++nest;
4488 else if (nest == 0)
4489 {
4490 const char *s;
4491
4492 s = strings + GET_WORD (input_bfd, incl_sym->e_strx);
4493 for (; *s != '\0'; s++)
4494 {
4495 val += *s;
4496 if (*s == '(')
4497 {
4498 /* Skip the file number. */
4499 ++s;
4500 while (ISDIGIT (*s))
4501 ++s;
4502 --s;
4503 }
4504 }
4505 }
4506 }
4507
4508 /* If we have already included a header file with the
4509 same value, then replace this one with an N_EXCL
4510 symbol. */
4511 copy = (bfd_boolean) (! finfo->info->keep_memory);
4512 incl_entry = aout_link_includes_lookup (&finfo->includes,
4513 name, TRUE, copy);
4514 if (incl_entry == NULL)
4515 return FALSE;
4516 for (t = incl_entry->totals; t != NULL; t = t->next)
4517 if (t->total == val)
4518 break;
4519 if (t == NULL)
4520 {
4521 /* This is the first time we have seen this header
4522 file with this set of stabs strings. */
4523 t = ((struct aout_link_includes_totals *)
4524 bfd_hash_allocate (&finfo->includes.root,
4525 sizeof *t));
4526 if (t == NULL)
4527 return FALSE;
4528 t->total = val;
4529 t->next = incl_entry->totals;
4530 incl_entry->totals = t;
4531 }
4532 else
4533 {
4534 int *incl_map;
4535
4536 /* This is a duplicate header file. We must change
4537 it to be an N_EXCL entry, and mark all the
4538 included symbols to prevent outputting them. */
4539 type = (int) N_EXCL;
4540
4541 nest = 0;
4542 for (incl_sym = sym + 1, incl_map = symbol_map + 1;
4543 incl_sym < sym_end;
4544 incl_sym++, incl_map++)
4545 {
4546 int incl_type;
4547
4548 incl_type = H_GET_8 (input_bfd, incl_sym->e_type);
4549 if (incl_type == (int) N_EINCL)
4550 {
4551 if (nest == 0)
4552 {
4553 *incl_map = -1;
4554 break;
4555 }
4556 --nest;
4557 }
4558 else if (incl_type == (int) N_BINCL)
4559 ++nest;
4560 else if (nest == 0)
4561 *incl_map = -1;
4562 }
4563 }
4564 }
4565 }
4566
4567 /* Copy this symbol into the list of symbols we are going to
4568 write out. */
4569 H_PUT_8 (output_bfd, type, outsym->e_type);
4570 H_PUT_8 (output_bfd, H_GET_8 (input_bfd, sym->e_other), outsym->e_other);
4571 H_PUT_16 (output_bfd, H_GET_16 (input_bfd, sym->e_desc), outsym->e_desc);
4572 copy = FALSE;
4573 if (! finfo->info->keep_memory)
4574 {
4575 /* name points into a string table which we are going to
4576 free. If there is a hash table entry, use that string.
4577 Otherwise, copy name into memory. */
4578 if (h != (struct aout_link_hash_entry *) NULL)
4579 name = h->root.root.string;
4580 else
4581 copy = TRUE;
4582 }
4583 strtab_index = add_to_stringtab (output_bfd, finfo->strtab,
4584 name, copy);
4585 if (strtab_index == (bfd_size_type) -1)
4586 return FALSE;
4587 PUT_WORD (output_bfd, strtab_index, outsym->e_strx);
4588 PUT_WORD (output_bfd, val, outsym->e_value);
4589 *symbol_map = obj_aout_external_sym_count (output_bfd);
4590 ++obj_aout_external_sym_count (output_bfd);
4591 ++outsym;
4592 }
4593
4594 /* Write out the output symbols we have just constructed. */
4595 if (outsym > finfo->output_syms)
4596 {
4597 bfd_size_type outsym_size;
4598
4599 if (bfd_seek (output_bfd, finfo->symoff, SEEK_SET) != 0)
4600 return FALSE;
4601 outsym_size = outsym - finfo->output_syms;
4602 outsym_size *= EXTERNAL_NLIST_SIZE;
4603 if (bfd_bwrite ((PTR) finfo->output_syms, outsym_size, output_bfd)
4604 != outsym_size)
4605 return FALSE;
4606 finfo->symoff += outsym_size;
4607 }
4608
4609 return TRUE;
4610}
4611
4612/* Write out a symbol that was not associated with an a.out input
4613 object. */
4614
4615static bfd_boolean
4616aout_link_write_other_symbol (h, data)
4617 struct aout_link_hash_entry *h;
4618 PTR data;
4619{
4620 struct aout_final_link_info *finfo = (struct aout_final_link_info *) data;
4621 bfd *output_bfd;
4622 int type;
4623 bfd_vma val;
4624 struct external_nlist outsym;
4625 bfd_size_type indx;
4626 bfd_size_type amt;
4627
4628 if (h->root.type == bfd_link_hash_warning)
4629 {
4630 h = (struct aout_link_hash_entry *) h->root.u.i.link;
4631 if (h->root.type == bfd_link_hash_new)
4632 return TRUE;
4633 }
4634
4635 output_bfd = finfo->output_bfd;
4636
4637 if (aout_backend_info (output_bfd)->write_dynamic_symbol != NULL)
4638 {
4639 if (! ((*aout_backend_info (output_bfd)->write_dynamic_symbol)
4640 (output_bfd, finfo->info, h)))
4641 {
4642 /* FIXME: No way to handle errors. */
4643 abort ();
4644 }
4645 }
4646
4647 if (h->written)
4648 return TRUE;
4649
4650 h->written = TRUE;
4651
4652 /* An indx of -2 means the symbol must be written. */
4653 if (h->indx != -2
4654 && (finfo->info->strip == strip_all
4655 || (finfo->info->strip == strip_some
4656 && bfd_hash_lookup (finfo->info->keep_hash, h->root.root.string,
4657 FALSE, FALSE) == NULL)))
4658 return TRUE;
4659
4660 switch (h->root.type)
4661 {
4662 default:
4663 case bfd_link_hash_warning:
4664 abort ();
4665 /* Avoid variable not initialized warnings. */
4666 return TRUE;
4667 case bfd_link_hash_new:
4668 /* This can happen for set symbols when sets are not being
4669 built. */
4670 return TRUE;
4671 case bfd_link_hash_undefined:
4672 type = N_UNDF | N_EXT;
4673 val = 0;
4674 break;
4675 case bfd_link_hash_defined:
4676 case bfd_link_hash_defweak:
4677 {
4678 asection *sec;
4679
4680 sec = h->root.u.def.section->output_section;
4681 BFD_ASSERT (bfd_is_abs_section (sec)
4682 || sec->owner == output_bfd);
4683 if (sec == obj_textsec (output_bfd))
4684 type = h->root.type == bfd_link_hash_defined ? N_TEXT : N_WEAKT;
4685 else if (sec == obj_datasec (output_bfd))
4686 type = h->root.type == bfd_link_hash_defined ? N_DATA : N_WEAKD;
4687 else if (sec == obj_bsssec (output_bfd))
4688 type = h->root.type == bfd_link_hash_defined ? N_BSS : N_WEAKB;
4689 else
4690 type = h->root.type == bfd_link_hash_defined ? N_ABS : N_WEAKA;
4691 type |= N_EXT;
4692 val = (h->root.u.def.value
4693 + sec->vma
4694 + h->root.u.def.section->output_offset);
4695 }
4696 break;
4697 case bfd_link_hash_common:
4698 type = N_UNDF | N_EXT;
4699 val = h->root.u.c.size;
4700 break;
4701 case bfd_link_hash_undefweak:
4702 type = N_WEAKU;
4703 val = 0;
4704 case bfd_link_hash_indirect:
4705 /* We ignore these symbols, since the indirected symbol is
4706 already in the hash table. */
4707 return TRUE;
4708 }
4709
4710 H_PUT_8 (output_bfd, type, outsym.e_type);
4711 H_PUT_8 (output_bfd, 0, outsym.e_other);
4712 H_PUT_16 (output_bfd, 0, outsym.e_desc);
4713 indx = add_to_stringtab (output_bfd, finfo->strtab, h->root.root.string,
4714 FALSE);
4715 if (indx == - (bfd_size_type) 1)
4716 {
4717 /* FIXME: No way to handle errors. */
4718 abort ();
4719 }
4720 PUT_WORD (output_bfd, indx, outsym.e_strx);
4721 PUT_WORD (output_bfd, val, outsym.e_value);
4722
4723 amt = EXTERNAL_NLIST_SIZE;
4724 if (bfd_seek (output_bfd, finfo->symoff, SEEK_SET) != 0
4725 || bfd_bwrite ((PTR) &outsym, amt, output_bfd) != amt)
4726 {
4727 /* FIXME: No way to handle errors. */
4728 abort ();
4729 }
4730
4731 finfo->symoff += EXTERNAL_NLIST_SIZE;
4732 h->indx = obj_aout_external_sym_count (output_bfd);
4733 ++obj_aout_external_sym_count (output_bfd);
4734
4735 return TRUE;
4736}
4737
4738/* Link an a.out section into the output file. */
4739
4740static bfd_boolean
4741aout_link_input_section (finfo, input_bfd, input_section, reloff_ptr,
4742 rel_size)
4743 struct aout_final_link_info *finfo;
4744 bfd *input_bfd;
4745 asection *input_section;
4746 file_ptr *reloff_ptr;
4747 bfd_size_type rel_size;
4748{
4749 bfd_size_type input_size;
4750 PTR relocs;
4751
4752 /* Get the section contents. */
4753 input_size = bfd_section_size (input_bfd, input_section);
4754 if (! bfd_get_section_contents (input_bfd, input_section,
4755 (PTR) finfo->contents,
4756 (file_ptr) 0, input_size))
4757 return FALSE;
4758
4759 /* Read in the relocs if we haven't already done it. */
4760 if (aout_section_data (input_section) != NULL
4761 && aout_section_data (input_section)->relocs != NULL)
4762 relocs = aout_section_data (input_section)->relocs;
4763 else
4764 {
4765 relocs = finfo->relocs;
4766 if (rel_size > 0)
4767 {
4768 if (bfd_seek (input_bfd, input_section->rel_filepos, SEEK_SET) != 0
4769 || bfd_bread (relocs, rel_size, input_bfd) != rel_size)
4770 return FALSE;
4771 }
4772 }
4773
4774 /* Relocate the section contents. */
4775 if (obj_reloc_entry_size (input_bfd) == RELOC_STD_SIZE)
4776 {
4777 if (! aout_link_input_section_std (finfo, input_bfd, input_section,
4778 (struct reloc_std_external *) relocs,
4779 rel_size, finfo->contents))
4780 return FALSE;
4781 }
4782 else
4783 {
4784 if (! aout_link_input_section_ext (finfo, input_bfd, input_section,
4785 (struct reloc_ext_external *) relocs,
4786 rel_size, finfo->contents))
4787 return FALSE;
4788 }
4789
4790 /* Write out the section contents. */
4791 if (! bfd_set_section_contents (finfo->output_bfd,
4792 input_section->output_section,
4793 (PTR) finfo->contents,
4794 (file_ptr) input_section->output_offset,
4795 input_size))
4796 return FALSE;
4797
4798 /* If we are producing relocateable output, the relocs were
4799 modified, and we now write them out. */
4800 if (finfo->info->relocateable && rel_size > 0)
4801 {
4802 if (bfd_seek (finfo->output_bfd, *reloff_ptr, SEEK_SET) != 0)
4803 return FALSE;
4804 if (bfd_bwrite (relocs, rel_size, finfo->output_bfd) != rel_size)
4805 return FALSE;
4806 *reloff_ptr += rel_size;
4807
4808 /* Assert that the relocs have not run into the symbols, and
4809 that if these are the text relocs they have not run into the
4810 data relocs. */
4811 BFD_ASSERT (*reloff_ptr <= obj_sym_filepos (finfo->output_bfd)
4812 && (reloff_ptr != &finfo->treloff
4813 || (*reloff_ptr
4814 <= obj_datasec (finfo->output_bfd)->rel_filepos)));
4815 }
4816
4817 return TRUE;
4818}
4819
4820/* Get the section corresponding to a reloc index. */
4821
4822static INLINE asection *
4823aout_reloc_index_to_section (abfd, indx)
4824 bfd *abfd;
4825 int indx;
4826{
4827 switch (indx & N_TYPE)
4828 {
4829 case N_TEXT:
4830 return obj_textsec (abfd);
4831 case N_DATA:
4832 return obj_datasec (abfd);
4833 case N_BSS:
4834 return obj_bsssec (abfd);
4835 case N_ABS:
4836 case N_UNDF:
4837 return bfd_abs_section_ptr;
4838 default:
4839 abort ();
4840 }
4841 /*NOTREACHED*/
4842 return NULL;
4843}
4844
4845/* Relocate an a.out section using standard a.out relocs. */
4846
4847static bfd_boolean
4848aout_link_input_section_std (finfo, input_bfd, input_section, relocs,
4849 rel_size, contents)
4850 struct aout_final_link_info *finfo;
4851 bfd *input_bfd;
4852 asection *input_section;
4853 struct reloc_std_external *relocs;
4854 bfd_size_type rel_size;
4855 bfd_byte *contents;
4856{
4857 bfd_boolean (*check_dynamic_reloc)
4858 PARAMS ((struct bfd_link_info *, bfd *, asection *,
4859 struct aout_link_hash_entry *, PTR, bfd_byte *, bfd_boolean *,
4860 bfd_vma *));
4861 bfd *output_bfd;
4862 bfd_boolean relocateable;
4863 struct external_nlist *syms;
4864 char *strings;
4865 struct aout_link_hash_entry **sym_hashes;
4866 int *symbol_map;
4867 bfd_size_type reloc_count;
4868 register struct reloc_std_external *rel;
4869 struct reloc_std_external *rel_end;
4870
4871 output_bfd = finfo->output_bfd;
4872 check_dynamic_reloc = aout_backend_info (output_bfd)->check_dynamic_reloc;
4873
4874 BFD_ASSERT (obj_reloc_entry_size (input_bfd) == RELOC_STD_SIZE);
4875 BFD_ASSERT (input_bfd->xvec->header_byteorder
4876 == output_bfd->xvec->header_byteorder);
4877
4878 relocateable = finfo->info->relocateable;
4879 syms = obj_aout_external_syms (input_bfd);
4880 strings = obj_aout_external_strings (input_bfd);
4881 sym_hashes = obj_aout_sym_hashes (input_bfd);
4882 symbol_map = finfo->symbol_map;
4883
4884 reloc_count = rel_size / RELOC_STD_SIZE;
4885 rel = relocs;
4886 rel_end = rel + reloc_count;
4887 for (; rel < rel_end; rel++)
4888 {
4889 bfd_vma r_addr;
4890 int r_index;
4891 int r_extern;
4892 int r_pcrel;
4893 int r_baserel = 0;
4894 reloc_howto_type *howto;
4895 struct aout_link_hash_entry *h = NULL;
4896 bfd_vma relocation;
4897 bfd_reloc_status_type r;
4898
4899 r_addr = GET_SWORD (input_bfd, rel->r_address);
4900
4901#ifdef MY_reloc_howto
4902 howto = MY_reloc_howto (input_bfd, rel, r_index, r_extern, r_pcrel);
4903#else
4904 {
4905 int r_jmptable;
4906 int r_relative;
4907 int r_length;
4908 unsigned int howto_idx;
4909
4910 if (bfd_header_big_endian (input_bfd))
4911 {
4912 r_index = (((unsigned int) rel->r_index[0] << 16)
4913 | ((unsigned int) rel->r_index[1] << 8)
4914 | rel->r_index[2]);
4915 r_extern = (0 != (rel->r_type[0] & RELOC_STD_BITS_EXTERN_BIG));
4916 r_pcrel = (0 != (rel->r_type[0] & RELOC_STD_BITS_PCREL_BIG));
4917 r_baserel = (0 != (rel->r_type[0] & RELOC_STD_BITS_BASEREL_BIG));
4918 r_jmptable= (0 != (rel->r_type[0] & RELOC_STD_BITS_JMPTABLE_BIG));
4919 r_relative= (0 != (rel->r_type[0] & RELOC_STD_BITS_RELATIVE_BIG));
4920 r_length = ((rel->r_type[0] & RELOC_STD_BITS_LENGTH_BIG)
4921 >> RELOC_STD_BITS_LENGTH_SH_BIG);
4922 }
4923 else
4924 {
4925 r_index = (((unsigned int) rel->r_index[2] << 16)
4926 | ((unsigned int) rel->r_index[1] << 8)
4927 | rel->r_index[0]);
4928 r_extern = (0 != (rel->r_type[0] & RELOC_STD_BITS_EXTERN_LITTLE));
4929 r_pcrel = (0 != (rel->r_type[0] & RELOC_STD_BITS_PCREL_LITTLE));
4930 r_baserel = (0 != (rel->r_type[0]
4931 & RELOC_STD_BITS_BASEREL_LITTLE));
4932 r_jmptable= (0 != (rel->r_type[0]
4933 & RELOC_STD_BITS_JMPTABLE_LITTLE));
4934 r_relative= (0 != (rel->r_type[0]
4935 & RELOC_STD_BITS_RELATIVE_LITTLE));
4936 r_length = ((rel->r_type[0] & RELOC_STD_BITS_LENGTH_LITTLE)
4937 >> RELOC_STD_BITS_LENGTH_SH_LITTLE);
4938 }
4939
4940 howto_idx = (r_length + 4 * r_pcrel + 8 * r_baserel
4941 + 16 * r_jmptable + 32 * r_relative);
4942 BFD_ASSERT (howto_idx < TABLE_SIZE (howto_table_std));
4943 howto = howto_table_std + howto_idx;
4944 }
4945#endif
4946
4947 if (relocateable)
4948 {
4949 /* We are generating a relocateable output file, and must
4950 modify the reloc accordingly. */
4951 if (r_extern)
4952 {
4953 /* If we know the symbol this relocation is against,
4954 convert it into a relocation against a section. This
4955 is what the native linker does. */
4956 h = sym_hashes[r_index];
4957 if (h != (struct aout_link_hash_entry *) NULL
4958 && (h->root.type == bfd_link_hash_defined
4959 || h->root.type == bfd_link_hash_defweak))
4960 {
4961 asection *output_section;
4962
4963 /* Change the r_extern value. */
4964 if (bfd_header_big_endian (output_bfd))
4965 rel->r_type[0] &=~ RELOC_STD_BITS_EXTERN_BIG;
4966 else
4967 rel->r_type[0] &=~ RELOC_STD_BITS_EXTERN_LITTLE;
4968
4969 /* Compute a new r_index. */
4970 output_section = h->root.u.def.section->output_section;
4971 if (output_section == obj_textsec (output_bfd))
4972 r_index = N_TEXT;
4973 else if (output_section == obj_datasec (output_bfd))
4974 r_index = N_DATA;
4975 else if (output_section == obj_bsssec (output_bfd))
4976 r_index = N_BSS;
4977 else
4978 r_index = N_ABS;
4979
4980 /* Add the symbol value and the section VMA to the
4981 addend stored in the contents. */
4982 relocation = (h->root.u.def.value
4983 + output_section->vma
4984 + h->root.u.def.section->output_offset);
4985 }
4986 else
4987 {
4988 /* We must change r_index according to the symbol
4989 map. */
4990 r_index = symbol_map[r_index];
4991
4992 if (r_index == -1)
4993 {
4994 if (h != NULL)
4995 {
4996 /* We decided to strip this symbol, but it
4997 turns out that we can't. Note that we
4998 lose the other and desc information here.
4999 I don't think that will ever matter for a
5000 global symbol. */
5001 if (h->indx < 0)
5002 {
5003 h->indx = -2;
5004 h->written = FALSE;
5005 if (! aout_link_write_other_symbol (h,
5006 (PTR) finfo))
5007 return FALSE;
5008 }
5009 r_index = h->indx;
5010 }
5011 else
5012 {
5013 const char *name;
5014
5015 name = strings + GET_WORD (input_bfd,
5016 syms[r_index].e_strx);
5017 if (! ((*finfo->info->callbacks->unattached_reloc)
5018 (finfo->info, name, input_bfd, input_section,
5019 r_addr)))
5020 return FALSE;
5021 r_index = 0;
5022 }
5023 }
5024
5025 relocation = 0;
5026 }
5027
5028 /* Write out the new r_index value. */
5029 if (bfd_header_big_endian (output_bfd))
5030 {
5031 rel->r_index[0] = r_index >> 16;
5032 rel->r_index[1] = r_index >> 8;
5033 rel->r_index[2] = r_index;
5034 }
5035 else
5036 {
5037 rel->r_index[2] = r_index >> 16;
5038 rel->r_index[1] = r_index >> 8;
5039 rel->r_index[0] = r_index;
5040 }
5041 }
5042 else
5043 {
5044 asection *section;
5045
5046 /* This is a relocation against a section. We must
5047 adjust by the amount that the section moved. */
5048 section = aout_reloc_index_to_section (input_bfd, r_index);
5049 relocation = (section->output_section->vma
5050 + section->output_offset
5051 - section->vma);
5052 }
5053
5054 /* Change the address of the relocation. */
5055 PUT_WORD (output_bfd,
5056 r_addr + input_section->output_offset,
5057 rel->r_address);
5058
5059 /* Adjust a PC relative relocation by removing the reference
5060 to the original address in the section and including the
5061 reference to the new address. */
5062 if (r_pcrel)
5063 relocation -= (input_section->output_section->vma
5064 + input_section->output_offset
5065 - input_section->vma);
5066
5067#ifdef MY_relocatable_reloc
5068 MY_relocatable_reloc (howto, output_bfd, rel, relocation, r_addr);
5069#endif
5070
5071 if (relocation == 0)
5072 r = bfd_reloc_ok;
5073 else
5074 r = MY_relocate_contents (howto,
5075 input_bfd, relocation,
5076 contents + r_addr);
5077 }
5078 else
5079 {
5080 bfd_boolean hundef;
5081
5082 /* We are generating an executable, and must do a full
5083 relocation. */
5084 hundef = FALSE;
5085
5086 if (r_extern)
5087 {
5088 h = sym_hashes[r_index];
5089
5090 if (h != (struct aout_link_hash_entry *) NULL
5091 && (h->root.type == bfd_link_hash_defined
5092 || h->root.type == bfd_link_hash_defweak))
5093 {
5094 relocation = (h->root.u.def.value
5095 + h->root.u.def.section->output_section->vma
5096 + h->root.u.def.section->output_offset);
5097 }
5098 else if (h != (struct aout_link_hash_entry *) NULL
5099 && h->root.type == bfd_link_hash_undefweak)
5100 relocation = 0;
5101 else
5102 {
5103 hundef = TRUE;
5104 relocation = 0;
5105 }
5106 }
5107 else
5108 {
5109 asection *section;
5110
5111 section = aout_reloc_index_to_section (input_bfd, r_index);
5112 relocation = (section->output_section->vma
5113 + section->output_offset
5114 - section->vma);
5115 if (r_pcrel)
5116 relocation += input_section->vma;
5117 }
5118
5119 if (check_dynamic_reloc != NULL)
5120 {
5121 bfd_boolean skip;
5122
5123 if (! ((*check_dynamic_reloc)
5124 (finfo->info, input_bfd, input_section, h,
5125 (PTR) rel, contents, &skip, &relocation)))
5126 return FALSE;
5127 if (skip)
5128 continue;
5129 }
5130
5131 /* Now warn if a global symbol is undefined. We could not
5132 do this earlier, because check_dynamic_reloc might want
5133 to skip this reloc. */
5134 if (hundef && ! finfo->info->shared && ! r_baserel)
5135 {
5136 const char *name;
5137
5138 if (h != NULL)
5139 name = h->root.root.string;
5140 else
5141 name = strings + GET_WORD (input_bfd, syms[r_index].e_strx);
5142 if (! ((*finfo->info->callbacks->undefined_symbol)
5143 (finfo->info, name, input_bfd, input_section,
5144 r_addr, TRUE)))
5145 return FALSE;
5146 }
5147
5148 r = MY_final_link_relocate (howto,
5149 input_bfd, input_section,
5150 contents, r_addr, relocation,
5151 (bfd_vma) 0);
5152 }
5153
5154 if (r != bfd_reloc_ok)
5155 {
5156 switch (r)
5157 {
5158 default:
5159 case bfd_reloc_outofrange:
5160 abort ();
5161 case bfd_reloc_overflow:
5162 {
5163 const char *name;
5164
5165 if (h != NULL)
5166 name = h->root.root.string;
5167 else if (r_extern)
5168 name = strings + GET_WORD (input_bfd,
5169 syms[r_index].e_strx);
5170 else
5171 {
5172 asection *s;
5173
5174 s = aout_reloc_index_to_section (input_bfd, r_index);
5175 name = bfd_section_name (input_bfd, s);
5176 }
5177 if (! ((*finfo->info->callbacks->reloc_overflow)
5178 (finfo->info, name, howto->name,
5179 (bfd_vma) 0, input_bfd, input_section, r_addr)))
5180 return FALSE;
5181 }
5182 break;
5183 }
5184 }
5185 }
5186
5187 return TRUE;
5188}
5189
5190/* Relocate an a.out section using extended a.out relocs. */
5191
5192static bfd_boolean
5193aout_link_input_section_ext (finfo, input_bfd, input_section, relocs,
5194 rel_size, contents)
5195 struct aout_final_link_info *finfo;
5196 bfd *input_bfd;
5197 asection *input_section;
5198 struct reloc_ext_external *relocs;
5199 bfd_size_type rel_size;
5200 bfd_byte *contents;
5201{
5202 bfd_boolean (*check_dynamic_reloc)
5203 PARAMS ((struct bfd_link_info *, bfd *, asection *,
5204 struct aout_link_hash_entry *, PTR, bfd_byte *, bfd_boolean *,
5205 bfd_vma *));
5206 bfd *output_bfd;
5207 bfd_boolean relocateable;
5208 struct external_nlist *syms;
5209 char *strings;
5210 struct aout_link_hash_entry **sym_hashes;
5211 int *symbol_map;
5212 bfd_size_type reloc_count;
5213 register struct reloc_ext_external *rel;
5214 struct reloc_ext_external *rel_end;
5215
5216 output_bfd = finfo->output_bfd;
5217 check_dynamic_reloc = aout_backend_info (output_bfd)->check_dynamic_reloc;
5218
5219 BFD_ASSERT (obj_reloc_entry_size (input_bfd) == RELOC_EXT_SIZE);
5220 BFD_ASSERT (input_bfd->xvec->header_byteorder
5221 == output_bfd->xvec->header_byteorder);
5222
5223 relocateable = finfo->info->relocateable;
5224 syms = obj_aout_external_syms (input_bfd);
5225 strings = obj_aout_external_strings (input_bfd);
5226 sym_hashes = obj_aout_sym_hashes (input_bfd);
5227 symbol_map = finfo->symbol_map;
5228
5229 reloc_count = rel_size / RELOC_EXT_SIZE;
5230 rel = relocs;
5231 rel_end = rel + reloc_count;
5232 for (; rel < rel_end; rel++)
5233 {
5234 bfd_vma r_addr;
5235 int r_index;
5236 int r_extern;
5237 unsigned int r_type;
5238 bfd_vma r_addend;
5239 struct aout_link_hash_entry *h = NULL;
5240 asection *r_section = NULL;
5241 bfd_vma relocation;
5242
5243 r_addr = GET_SWORD (input_bfd, rel->r_address);
5244
5245 if (bfd_header_big_endian (input_bfd))
5246 {
5247 r_index = (((unsigned int) rel->r_index[0] << 16)
5248 | ((unsigned int) rel->r_index[1] << 8)
5249 | rel->r_index[2]);
5250 r_extern = (0 != (rel->r_type[0] & RELOC_EXT_BITS_EXTERN_BIG));
5251 r_type = ((rel->r_type[0] & RELOC_EXT_BITS_TYPE_BIG)
5252 >> RELOC_EXT_BITS_TYPE_SH_BIG);
5253 }
5254 else
5255 {
5256 r_index = (((unsigned int) rel->r_index[2] << 16)
5257 | ((unsigned int) rel->r_index[1] << 8)
5258 | rel->r_index[0]);
5259 r_extern = (0 != (rel->r_type[0] & RELOC_EXT_BITS_EXTERN_LITTLE));
5260 r_type = ((rel->r_type[0] & RELOC_EXT_BITS_TYPE_LITTLE)
5261 >> RELOC_EXT_BITS_TYPE_SH_LITTLE);
5262 }
5263
5264 r_addend = GET_SWORD (input_bfd, rel->r_addend);
5265
5266 BFD_ASSERT (r_type < TABLE_SIZE (howto_table_ext));
5267
5268 if (relocateable)
5269 {
5270 /* We are generating a relocateable output file, and must
5271 modify the reloc accordingly. */
5272 if (r_extern
5273 || r_type == (unsigned int) RELOC_BASE10
5274 || r_type == (unsigned int) RELOC_BASE13
5275 || r_type == (unsigned int) RELOC_BASE22)
5276 {
5277 /* If we know the symbol this relocation is against,
5278 convert it into a relocation against a section. This
5279 is what the native linker does. */
5280 if (r_type == (unsigned int) RELOC_BASE10
5281 || r_type == (unsigned int) RELOC_BASE13
5282 || r_type == (unsigned int) RELOC_BASE22)
5283 h = NULL;
5284 else
5285 h = sym_hashes[r_index];
5286 if (h != (struct aout_link_hash_entry *) NULL
5287 && (h->root.type == bfd_link_hash_defined
5288 || h->root.type == bfd_link_hash_defweak))
5289 {
5290 asection *output_section;
5291
5292 /* Change the r_extern value. */
5293 if (bfd_header_big_endian (output_bfd))
5294 rel->r_type[0] &=~ RELOC_EXT_BITS_EXTERN_BIG;
5295 else
5296 rel->r_type[0] &=~ RELOC_EXT_BITS_EXTERN_LITTLE;
5297
5298 /* Compute a new r_index. */
5299 output_section = h->root.u.def.section->output_section;
5300 if (output_section == obj_textsec (output_bfd))
5301 r_index = N_TEXT;
5302 else if (output_section == obj_datasec (output_bfd))
5303 r_index = N_DATA;
5304 else if (output_section == obj_bsssec (output_bfd))
5305 r_index = N_BSS;
5306 else
5307 r_index = N_ABS;
5308
5309 /* Add the symbol value and the section VMA to the
5310 addend. */
5311 relocation = (h->root.u.def.value
5312 + output_section->vma
5313 + h->root.u.def.section->output_offset);
5314
5315 /* Now RELOCATION is the VMA of the final
5316 destination. If this is a PC relative reloc,
5317 then ADDEND is the negative of the source VMA.
5318 We want to set ADDEND to the difference between
5319 the destination VMA and the source VMA, which
5320 means we must adjust RELOCATION by the change in
5321 the source VMA. This is done below. */
5322 }
5323 else
5324 {
5325 /* We must change r_index according to the symbol
5326 map. */
5327 r_index = symbol_map[r_index];
5328
5329 if (r_index == -1)
5330 {
5331 if (h != NULL)
5332 {
5333 /* We decided to strip this symbol, but it
5334 turns out that we can't. Note that we
5335 lose the other and desc information here.
5336 I don't think that will ever matter for a
5337 global symbol. */
5338 if (h->indx < 0)
5339 {
5340 h->indx = -2;
5341 h->written = FALSE;
5342 if (! aout_link_write_other_symbol (h,
5343 (PTR) finfo))
5344 return FALSE;
5345 }
5346 r_index = h->indx;
5347 }
5348 else
5349 {
5350 const char *name;
5351
5352 name = strings + GET_WORD (input_bfd,
5353 syms[r_index].e_strx);
5354 if (! ((*finfo->info->callbacks->unattached_reloc)
5355 (finfo->info, name, input_bfd, input_section,
5356 r_addr)))
5357 return FALSE;
5358 r_index = 0;
5359 }
5360 }
5361
5362 relocation = 0;
5363
5364 /* If this is a PC relative reloc, then the addend
5365 is the negative of the source VMA. We must
5366 adjust it by the change in the source VMA. This
5367 is done below. */
5368 }
5369
5370 /* Write out the new r_index value. */
5371 if (bfd_header_big_endian (output_bfd))
5372 {
5373 rel->r_index[0] = r_index >> 16;
5374 rel->r_index[1] = r_index >> 8;
5375 rel->r_index[2] = r_index;
5376 }
5377 else
5378 {
5379 rel->r_index[2] = r_index >> 16;
5380 rel->r_index[1] = r_index >> 8;
5381 rel->r_index[0] = r_index;
5382 }
5383 }
5384 else
5385 {
5386 /* This is a relocation against a section. We must
5387 adjust by the amount that the section moved. */
5388 r_section = aout_reloc_index_to_section (input_bfd, r_index);
5389 relocation = (r_section->output_section->vma
5390 + r_section->output_offset
5391 - r_section->vma);
5392
5393 /* If this is a PC relative reloc, then the addend is
5394 the difference in VMA between the destination and the
5395 source. We have just adjusted for the change in VMA
5396 of the destination, so we must also adjust by the
5397 change in VMA of the source. This is done below. */
5398 }
5399
5400 /* As described above, we must always adjust a PC relative
5401 reloc by the change in VMA of the source. However, if
5402 pcrel_offset is set, then the addend does not include the
5403 location within the section, in which case we don't need
5404 to adjust anything. */
5405 if (howto_table_ext[r_type].pc_relative
5406 && ! howto_table_ext[r_type].pcrel_offset)
5407 relocation -= (input_section->output_section->vma
5408 + input_section->output_offset
5409 - input_section->vma);
5410
5411 /* Change the addend if necessary. */
5412 if (relocation != 0)
5413 PUT_WORD (output_bfd, r_addend + relocation, rel->r_addend);
5414
5415 /* Change the address of the relocation. */
5416 PUT_WORD (output_bfd,
5417 r_addr + input_section->output_offset,
5418 rel->r_address);
5419 }
5420 else
5421 {
5422 bfd_boolean hundef;
5423 bfd_reloc_status_type r;
5424
5425 /* We are generating an executable, and must do a full
5426 relocation. */
5427 hundef = FALSE;
5428
5429 if (r_extern)
5430 {
5431 h = sym_hashes[r_index];
5432
5433 if (h != (struct aout_link_hash_entry *) NULL
5434 && (h->root.type == bfd_link_hash_defined
5435 || h->root.type == bfd_link_hash_defweak))
5436 {
5437 relocation = (h->root.u.def.value
5438 + h->root.u.def.section->output_section->vma
5439 + h->root.u.def.section->output_offset);
5440 }
5441 else if (h != (struct aout_link_hash_entry *) NULL
5442 && h->root.type == bfd_link_hash_undefweak)
5443 relocation = 0;
5444 else
5445 {
5446 hundef = TRUE;
5447 relocation = 0;
5448 }
5449 }
5450 else if (r_type == (unsigned int) RELOC_BASE10
5451 || r_type == (unsigned int) RELOC_BASE13
5452 || r_type == (unsigned int) RELOC_BASE22)
5453 {
5454 struct external_nlist *sym;
5455 int type;
5456
5457 /* For base relative relocs, r_index is always an index
5458 into the symbol table, even if r_extern is 0. */
5459 sym = syms + r_index;
5460 type = H_GET_8 (input_bfd, sym->e_type);
5461 if ((type & N_TYPE) == N_TEXT
5462 || type == N_WEAKT)
5463 r_section = obj_textsec (input_bfd);
5464 else if ((type & N_TYPE) == N_DATA
5465 || type == N_WEAKD)
5466 r_section = obj_datasec (input_bfd);
5467 else if ((type & N_TYPE) == N_BSS
5468 || type == N_WEAKB)
5469 r_section = obj_bsssec (input_bfd);
5470 else if ((type & N_TYPE) == N_ABS
5471 || type == N_WEAKA)
5472 r_section = bfd_abs_section_ptr;
5473 else
5474 abort ();
5475 relocation = (r_section->output_section->vma
5476 + r_section->output_offset
5477 + (GET_WORD (input_bfd, sym->e_value)
5478 - r_section->vma));
5479 }
5480 else
5481 {
5482 r_section = aout_reloc_index_to_section (input_bfd, r_index);
5483
5484 /* If this is a PC relative reloc, then R_ADDEND is the
5485 difference between the two vmas, or
5486 old_dest_sec + old_dest_off - (old_src_sec + old_src_off)
5487 where
5488 old_dest_sec == section->vma
5489 and
5490 old_src_sec == input_section->vma
5491 and
5492 old_src_off == r_addr
5493
5494 _bfd_final_link_relocate expects RELOCATION +
5495 R_ADDEND to be the VMA of the destination minus
5496 r_addr (the minus r_addr is because this relocation
5497 is not pcrel_offset, which is a bit confusing and
5498 should, perhaps, be changed), or
5499 new_dest_sec
5500 where
5501 new_dest_sec == output_section->vma + output_offset
5502 We arrange for this to happen by setting RELOCATION to
5503 new_dest_sec + old_src_sec - old_dest_sec
5504
5505 If this is not a PC relative reloc, then R_ADDEND is
5506 simply the VMA of the destination, so we set
5507 RELOCATION to the change in the destination VMA, or
5508 new_dest_sec - old_dest_sec
5509 */
5510 relocation = (r_section->output_section->vma
5511 + r_section->output_offset
5512 - r_section->vma);
5513 if (howto_table_ext[r_type].pc_relative)
5514 relocation += input_section->vma;
5515 }
5516
5517 if (check_dynamic_reloc != NULL)
5518 {
5519 bfd_boolean skip;
5520
5521 if (! ((*check_dynamic_reloc)
5522 (finfo->info, input_bfd, input_section, h,
5523 (PTR) rel, contents, &skip, &relocation)))
5524 return FALSE;
5525 if (skip)
5526 continue;
5527 }
5528
5529 /* Now warn if a global symbol is undefined. We could not
5530 do this earlier, because check_dynamic_reloc might want
5531 to skip this reloc. */
5532 if (hundef
5533 && ! finfo->info->shared
5534 && r_type != (unsigned int) RELOC_BASE10
5535 && r_type != (unsigned int) RELOC_BASE13
5536 && r_type != (unsigned int) RELOC_BASE22)
5537 {
5538 const char *name;
5539
5540 if (h != NULL)
5541 name = h->root.root.string;
5542 else
5543 name = strings + GET_WORD (input_bfd, syms[r_index].e_strx);
5544 if (! ((*finfo->info->callbacks->undefined_symbol)
5545 (finfo->info, name, input_bfd, input_section,
5546 r_addr, TRUE)))
5547 return FALSE;
5548 }
5549
5550 if (r_type != (unsigned int) RELOC_SPARC_REV32)
5551 r = MY_final_link_relocate (howto_table_ext + r_type,
5552 input_bfd, input_section,
5553 contents, r_addr, relocation,
5554 r_addend);
5555 else
5556 {
5557 bfd_vma x;
5558
5559 x = bfd_get_32 (input_bfd, contents + r_addr);
5560 x = x + relocation + r_addend;
5561 bfd_putl32 (/*input_bfd,*/ x, contents + r_addr);
5562 r = bfd_reloc_ok;
5563 }
5564
5565 if (r != bfd_reloc_ok)
5566 {
5567 switch (r)
5568 {
5569 default:
5570 case bfd_reloc_outofrange:
5571 abort ();
5572 case bfd_reloc_overflow:
5573 {
5574 const char *name;
5575
5576 if (h != NULL)
5577 name = h->root.root.string;
5578 else if (r_extern
5579 || r_type == (unsigned int) RELOC_BASE10
5580 || r_type == (unsigned int) RELOC_BASE13
5581 || r_type == (unsigned int) RELOC_BASE22)
5582 name = strings + GET_WORD (input_bfd,
5583 syms[r_index].e_strx);
5584 else
5585 {
5586 asection *s;
5587
5588 s = aout_reloc_index_to_section (input_bfd, r_index);
5589 name = bfd_section_name (input_bfd, s);
5590 }
5591 if (! ((*finfo->info->callbacks->reloc_overflow)
5592 (finfo->info, name, howto_table_ext[r_type].name,
5593 r_addend, input_bfd, input_section, r_addr)))
5594 return FALSE;
5595 }
5596 break;
5597 }
5598 }
5599 }
5600 }
5601
5602 return TRUE;
5603}
5604
5605/* Handle a link order which is supposed to generate a reloc. */
5606
5607static bfd_boolean
5608aout_link_reloc_link_order (finfo, o, p)
5609 struct aout_final_link_info *finfo;
5610 asection *o;
5611 struct bfd_link_order *p;
5612{
5613 struct bfd_link_order_reloc *pr;
5614 int r_index;
5615 int r_extern;
5616 reloc_howto_type *howto;
5617 file_ptr *reloff_ptr = NULL;
5618 struct reloc_std_external srel;
5619 struct reloc_ext_external erel;
5620 PTR rel_ptr;
5621 bfd_size_type amt;
5622
5623 pr = p->u.reloc.p;
5624
5625 if (p->type == bfd_section_reloc_link_order)
5626 {
5627 r_extern = 0;
5628 if (bfd_is_abs_section (pr->u.section))
5629 r_index = N_ABS | N_EXT;
5630 else
5631 {
5632 BFD_ASSERT (pr->u.section->owner == finfo->output_bfd);
5633 r_index = pr->u.section->target_index;
5634 }
5635 }
5636 else
5637 {
5638 struct aout_link_hash_entry *h;
5639
5640 BFD_ASSERT (p->type == bfd_symbol_reloc_link_order);
5641 r_extern = 1;
5642 h = ((struct aout_link_hash_entry *)
5643 bfd_wrapped_link_hash_lookup (finfo->output_bfd, finfo->info,
5644 pr->u.name, FALSE, FALSE, TRUE));
5645 if (h != (struct aout_link_hash_entry *) NULL
5646 && h->indx >= 0)
5647 r_index = h->indx;
5648 else if (h != NULL)
5649 {
5650 /* We decided to strip this symbol, but it turns out that we
5651 can't. Note that we lose the other and desc information
5652 here. I don't think that will ever matter for a global
5653 symbol. */
5654 h->indx = -2;
5655 h->written = FALSE;
5656 if (! aout_link_write_other_symbol (h, (PTR) finfo))
5657 return FALSE;
5658 r_index = h->indx;
5659 }
5660 else
5661 {
5662 if (! ((*finfo->info->callbacks->unattached_reloc)
5663 (finfo->info, pr->u.name, (bfd *) NULL,
5664 (asection *) NULL, (bfd_vma) 0)))
5665 return FALSE;
5666 r_index = 0;
5667 }
5668 }
5669
5670 howto = bfd_reloc_type_lookup (finfo->output_bfd, pr->reloc);
5671 if (howto == 0)
5672 {
5673 bfd_set_error (bfd_error_bad_value);
5674 return FALSE;
5675 }
5676
5677 if (o == obj_textsec (finfo->output_bfd))
5678 reloff_ptr = &finfo->treloff;
5679 else if (o == obj_datasec (finfo->output_bfd))
5680 reloff_ptr = &finfo->dreloff;
5681 else
5682 abort ();
5683
5684 if (obj_reloc_entry_size (finfo->output_bfd) == RELOC_STD_SIZE)
5685 {
5686#ifdef MY_put_reloc
5687 MY_put_reloc (finfo->output_bfd, r_extern, r_index, p->offset, howto,
5688 &srel);
5689#else
5690 {
5691 int r_pcrel;
5692 int r_baserel;
5693 int r_jmptable;
5694 int r_relative;
5695 int r_length;
5696
5697 r_pcrel = (int) howto->pc_relative;
5698 r_baserel = (howto->type & 8) != 0;
5699 r_jmptable = (howto->type & 16) != 0;
5700 r_relative = (howto->type & 32) != 0;
5701 r_length = howto->size;
5702
5703 PUT_WORD (finfo->output_bfd, p->offset, srel.r_address);
5704 if (bfd_header_big_endian (finfo->output_bfd))
5705 {
5706 srel.r_index[0] = r_index >> 16;
5707 srel.r_index[1] = r_index >> 8;
5708 srel.r_index[2] = r_index;
5709 srel.r_type[0] =
5710 ((r_extern ? RELOC_STD_BITS_EXTERN_BIG : 0)
5711 | (r_pcrel ? RELOC_STD_BITS_PCREL_BIG : 0)
5712 | (r_baserel ? RELOC_STD_BITS_BASEREL_BIG : 0)
5713 | (r_jmptable ? RELOC_STD_BITS_JMPTABLE_BIG : 0)
5714 | (r_relative ? RELOC_STD_BITS_RELATIVE_BIG : 0)
5715 | (r_length << RELOC_STD_BITS_LENGTH_SH_BIG));
5716 }
5717 else
5718 {
5719 srel.r_index[2] = r_index >> 16;
5720 srel.r_index[1] = r_index >> 8;
5721 srel.r_index[0] = r_index;
5722 srel.r_type[0] =
5723 ((r_extern ? RELOC_STD_BITS_EXTERN_LITTLE : 0)
5724 | (r_pcrel ? RELOC_STD_BITS_PCREL_LITTLE : 0)
5725 | (r_baserel ? RELOC_STD_BITS_BASEREL_LITTLE : 0)
5726 | (r_jmptable ? RELOC_STD_BITS_JMPTABLE_LITTLE : 0)
5727 | (r_relative ? RELOC_STD_BITS_RELATIVE_LITTLE : 0)
5728 | (r_length << RELOC_STD_BITS_LENGTH_SH_LITTLE));
5729 }
5730 }
5731#endif
5732 rel_ptr = (PTR) &srel;
5733
5734 /* We have to write the addend into the object file, since
5735 standard a.out relocs are in place. It would be more
5736 reliable if we had the current contents of the file here,
5737 rather than assuming zeroes, but we can't read the file since
5738 it was opened using bfd_openw. */
5739 if (pr->addend != 0)
5740 {
5741 bfd_size_type size;
5742 bfd_reloc_status_type r;
5743 bfd_byte *buf;
5744 bfd_boolean ok;
5745
5746 size = bfd_get_reloc_size (howto);
5747 buf = (bfd_byte *) bfd_zmalloc (size);
5748 if (buf == (bfd_byte *) NULL)
5749 return FALSE;
5750 r = MY_relocate_contents (howto, finfo->output_bfd,
5751 (bfd_vma) pr->addend, buf);
5752 switch (r)
5753 {
5754 case bfd_reloc_ok:
5755 break;
5756 default:
5757 case bfd_reloc_outofrange:
5758 abort ();
5759 case bfd_reloc_overflow:
5760 if (! ((*finfo->info->callbacks->reloc_overflow)
5761 (finfo->info,
5762 (p->type == bfd_section_reloc_link_order
5763 ? bfd_section_name (finfo->output_bfd,
5764 pr->u.section)
5765 : pr->u.name),
5766 howto->name, pr->addend, (bfd *) NULL,
5767 (asection *) NULL, (bfd_vma) 0)))
5768 {
5769 free (buf);
5770 return FALSE;
5771 }
5772 break;
5773 }
5774 ok = bfd_set_section_contents (finfo->output_bfd, o, (PTR) buf,
5775 (file_ptr) p->offset, size);
5776 free (buf);
5777 if (! ok)
5778 return FALSE;
5779 }
5780 }
5781 else
5782 {
5783#ifdef MY_put_ext_reloc
5784 MY_put_ext_reloc (finfo->output_bfd, r_extern, r_index, p->offset,
5785 howto, &erel, pr->addend);
5786#else
5787 PUT_WORD (finfo->output_bfd, p->offset, erel.r_address);
5788
5789 if (bfd_header_big_endian (finfo->output_bfd))
5790 {
5791 erel.r_index[0] = r_index >> 16;
5792 erel.r_index[1] = r_index >> 8;
5793 erel.r_index[2] = r_index;
5794 erel.r_type[0] =
5795 ((r_extern ? RELOC_EXT_BITS_EXTERN_BIG : 0)
5796 | (howto->type << RELOC_EXT_BITS_TYPE_SH_BIG));
5797 }
5798 else
5799 {
5800 erel.r_index[2] = r_index >> 16;
5801 erel.r_index[1] = r_index >> 8;
5802 erel.r_index[0] = r_index;
5803 erel.r_type[0] =
5804 (r_extern ? RELOC_EXT_BITS_EXTERN_LITTLE : 0)
5805 | (howto->type << RELOC_EXT_BITS_TYPE_SH_LITTLE);
5806 }
5807
5808 PUT_WORD (finfo->output_bfd, (bfd_vma) pr->addend, erel.r_addend);
5809#endif /* MY_put_ext_reloc */
5810
5811 rel_ptr = (PTR) &erel;
5812 }
5813
5814 amt = obj_reloc_entry_size (finfo->output_bfd);
5815 if (bfd_seek (finfo->output_bfd, *reloff_ptr, SEEK_SET) != 0
5816 || bfd_bwrite (rel_ptr, amt, finfo->output_bfd) != amt)
5817 return FALSE;
5818
5819 *reloff_ptr += obj_reloc_entry_size (finfo->output_bfd);
5820
5821 /* Assert that the relocs have not run into the symbols, and that n
5822 the text relocs have not run into the data relocs. */
5823 BFD_ASSERT (*reloff_ptr <= obj_sym_filepos (finfo->output_bfd)
5824 && (reloff_ptr != &finfo->treloff
5825 || (*reloff_ptr
5826 <= obj_datasec (finfo->output_bfd)->rel_filepos)));
5827
5828 return TRUE;
5829}
Note: See TracBrowser for help on using the repository browser.