Coverage Report

Created: 2026-07-25 10:20

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