Coverage Report

Created: 2024-05-21 06:29

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