Coverage Report

Created: 2026-11-21 09:00

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