Coverage Report

Created: 2025-07-08 11:15

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