Coverage Report

Created: 2023-08-28 06:26

/src/binutils-gdb/bfd/coffcode.h
Line
Count
Source (jump to first uncovered line)
1
/* Support for the generic parts of most COFF variants, for BFD.
2
   Copyright (C) 1990-2023 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
/* Most of this hacked by  Steve Chamberlain,
23
      sac@cygnus.com.  */
24
/*
25
SECTION
26
  coff backends
27
28
  BFD supports a number of different flavours of coff format.
29
  The major differences between formats are the sizes and
30
  alignments of fields in structures on disk, and the occasional
31
  extra field.
32
33
  Coff in all its varieties is implemented with a few common
34
  files and a number of implementation specific files. For
35
  example, the i386 coff format is implemented in the file
36
  @file{coff-i386.c}.  This file @code{#include}s
37
  @file{coff/i386.h} which defines the external structure of the
38
  coff format for the i386, and @file{coff/internal.h} which
39
  defines the internal structure. @file{coff-i386.c} also
40
  defines the relocations used by the i386 coff format
41
  @xref{Relocations}.
42
43
SUBSECTION
44
  Porting to a new version of coff
45
46
  The recommended method is to select from the existing
47
  implementations the version of coff which is most like the one
48
  you want to use.  For example, we'll say that i386 coff is
49
  the one you select, and that your coff flavour is called foo.
50
  Copy @file{i386coff.c} to @file{foocoff.c}, copy
51
  @file{../include/coff/i386.h} to @file{../include/coff/foo.h},
52
  and add the lines to @file{targets.c} and @file{Makefile.in}
53
  so that your new back end is used. Alter the shapes of the
54
  structures in @file{../include/coff/foo.h} so that they match
55
  what you need. You will probably also have to add
56
  @code{#ifdef}s to the code in @file{coff/internal.h} and
57
  @file{coffcode.h} if your version of coff is too wild.
58
59
  You can verify that your new BFD backend works quite simply by
60
  building @file{objdump} from the @file{binutils} directory,
61
  and making sure that its version of what's going on and your
62
  host system's idea (assuming it has the pretty standard coff
63
  dump utility, usually called @code{att-dump} or just
64
  @code{dump}) are the same.  Then clean up your code, and send
65
  what you've done to Cygnus. Then your stuff will be in the
66
  next release, and you won't have to keep integrating it.
67
68
SUBSECTION
69
  How the coff backend works
70
71
SUBSUBSECTION
72
  File layout
73
74
  The Coff backend is split into generic routines that are
75
  applicable to any Coff target and routines that are specific
76
  to a particular target.  The target-specific routines are
77
  further split into ones which are basically the same for all
78
  Coff targets except that they use the external symbol format
79
  or use different values for certain constants.
80
81
  The generic routines are in @file{coffgen.c}.  These routines
82
  work for any Coff target.  They use some hooks into the target
83
  specific code; the hooks are in a @code{bfd_coff_backend_data}
84
  structure, one of which exists for each target.
85
86
  The essentially similar target-specific routines are in
87
  @file{coffcode.h}.  This header file includes executable C code.
88
  The various Coff targets first include the appropriate Coff
89
  header file, make any special defines that are needed, and
90
  then include @file{coffcode.h}.
91
92
  Some of the Coff targets then also have additional routines in
93
  the target source file itself.
94
95
SUBSUBSECTION
96
  Coff long section names
97
98
  In the standard Coff object format, section names are limited to
99
  the eight bytes available in the @code{s_name} field of the
100
  @code{SCNHDR} section header structure.  The format requires the
101
  field to be NUL-padded, but not necessarily NUL-terminated, so
102
  the longest section names permitted are a full eight characters.
103
104
  The Microsoft PE variants of the Coff object file format add
105
  an extension to support the use of long section names.  This
106
  extension is defined in section 4 of the Microsoft PE/COFF
107
  specification (rev 8.1).  If a section name is too long to fit
108
  into the section header's @code{s_name} field, it is instead
109
  placed into the string table, and the @code{s_name} field is
110
  filled with a slash ("/") followed by the ASCII decimal
111
  representation of the offset of the full name relative to the
112
  string table base.
113
114
  Note that this implies that the extension can only be used in object
115
  files, as executables do not contain a string table.  The standard
116
  specifies that long section names from objects emitted into executable
117
  images are to be truncated.
118
119
  However, as a GNU extension, BFD can generate executable images
120
  that contain a string table and long section names.  This
121
  would appear to be technically valid, as the standard only says
122
  that Coff debugging information is deprecated, not forbidden,
123
  and in practice it works, although some tools that parse PE files
124
  expecting the MS standard format may become confused; @file{PEview} is
125
  one known example.
126
127
  The functionality is supported in BFD by code implemented under
128
  the control of the macro @code{COFF_LONG_SECTION_NAMES}.  If not
129
  defined, the format does not support long section names in any way.
130
  If defined, it is used to initialise a flag,
131
  @code{_bfd_coff_long_section_names}, and a hook function pointer,
132
  @code{_bfd_coff_set_long_section_names}, in the Coff backend data
133
  structure.  The flag controls the generation of long section names
134
  in output BFDs at runtime; if it is false, as it will be by default
135
  when generating an executable image, long section names are truncated;
136
  if true, the long section names extension is employed.  The hook
137
  points to a function that allows the value of a copy of the flag
138
  in coff object tdata to be altered at runtime, on formats that
139
  support long section names at all; on other formats it points
140
  to a stub that returns an error indication.
141
142
  With input BFDs, the flag is set according to whether any long section
143
  names are detected while reading the section headers.  For a completely
144
  new BFD, the flag is set to the default for the target format.  This
145
  information can be used by a client of the BFD library when deciding
146
  what output format to generate, and means that a BFD that is opened
147
  for read and subsequently converted to a writeable BFD and modified
148
  in-place will retain whatever format it had on input.
149
150
  If @code{COFF_LONG_SECTION_NAMES} is simply defined (blank), or is
151
  defined to the value "1", then long section names are enabled by
152
  default; if it is defined to the value zero, they are disabled by
153
  default (but still accepted in input BFDs).  The header @file{coffcode.h}
154
  defines a macro, @code{COFF_DEFAULT_LONG_SECTION_NAMES}, which is
155
  used in the backends to initialise the backend data structure fields
156
  appropriately; see the comments for further detail.
157
158
SUBSUBSECTION
159
  Bit twiddling
160
161
  Each flavour of coff supported in BFD has its own header file
162
  describing the external layout of the structures. There is also
163
  an internal description of the coff layout, in
164
  @file{coff/internal.h}. A major function of the
165
  coff backend is swapping the bytes and twiddling the bits to
166
  translate the external form of the structures into the normal
167
  internal form. This is all performed in the
168
  @code{bfd_swap}_@i{thing}_@i{direction} routines. Some
169
  elements are different sizes between different versions of
170
  coff; it is the duty of the coff version specific include file
171
  to override the definitions of various packing routines in
172
  @file{coffcode.h}. E.g., the size of line number entry in coff is
173
  sometimes 16 bits, and sometimes 32 bits. @code{#define}ing
174
  @code{PUT_LNSZ_LNNO} and @code{GET_LNSZ_LNNO} will select the
175
  correct one. No doubt, some day someone will find a version of
176
  coff which has a varying field size not catered to at the
177
  moment. To port BFD, that person will have to add more @code{#defines}.
178
  Three of the bit twiddling routines are exported to
179
  @code{gdb}; @code{coff_swap_aux_in}, @code{coff_swap_sym_in}
180
  and @code{coff_swap_lineno_in}. @code{GDB} reads the symbol
181
  table on its own, but uses BFD to fix things up.  More of the
182
  bit twiddlers are exported for @code{gas};
183
  @code{coff_swap_aux_out}, @code{coff_swap_sym_out},
184
  @code{coff_swap_lineno_out}, @code{coff_swap_reloc_out},
185
  @code{coff_swap_filehdr_out}, @code{coff_swap_aouthdr_out},
186
  @code{coff_swap_scnhdr_out}. @code{Gas} currently keeps track
187
  of all the symbol table and reloc drudgery itself, thereby
188
  saving the internal BFD overhead, but uses BFD to swap things
189
  on the way out, making cross ports much safer.  Doing so also
190
  allows BFD (and thus the linker) to use the same header files
191
  as @code{gas}, which makes one avenue to disaster disappear.
192
193
SUBSUBSECTION
194
  Symbol reading
195
196
  The simple canonical form for symbols used by BFD is not rich
197
  enough to keep all the information available in a coff symbol
198
  table. The back end gets around this problem by keeping the original
199
  symbol table around, "behind the scenes".
200
201
  When a symbol table is requested (through a call to
202
  @code{bfd_canonicalize_symtab}), a request gets through to
203
  @code{coff_get_normalized_symtab}. This reads the symbol table from
204
  the coff file and swaps all the structures inside into the
205
  internal form. It also fixes up all the pointers in the table
206
  (represented in the file by offsets from the first symbol in
207
  the table) into physical pointers to elements in the new
208
  internal table. This involves some work since the meanings of
209
  fields change depending upon context: a field that is a
210
  pointer to another structure in the symbol table at one moment
211
  may be the size in bytes of a structure at the next.  Another
212
  pass is made over the table. All symbols which mark file names
213
  (<<C_FILE>> symbols) are modified so that the internal
214
  string points to the value in the auxent (the real filename)
215
  rather than the normal text associated with the symbol
216
  (@code{".file"}).
217
218
  At this time the symbol names are moved around. Coff stores
219
  all symbols less than nine characters long physically
220
  within the symbol table; longer strings are kept at the end of
221
  the file in the string table. This pass moves all strings
222
  into memory and replaces them with pointers to the strings.
223
224
  The symbol table is massaged once again, this time to create
225
  the canonical table used by the BFD application. Each symbol
226
  is inspected in turn, and a decision made (using the
227
  @code{sclass} field) about the various flags to set in the
228
  @code{asymbol}.  @xref{Symbols}. The generated canonical table
229
  shares strings with the hidden internal symbol table.
230
231
  Any linenumbers are read from the coff file too, and attached
232
  to the symbols which own the functions the linenumbers belong to.
233
234
SUBSUBSECTION
235
  Symbol writing
236
237
  Writing a symbol to a coff file which didn't come from a coff
238
  file will lose any debugging information. The @code{asymbol}
239
  structure remembers the BFD from which the symbol was taken, and on
240
  output the back end makes sure that the same destination target as
241
  source target is present.
242
243
  When the symbols have come from a coff file then all the
244
  debugging information is preserved.
245
246
  Symbol tables are provided for writing to the back end in a
247
  vector of pointers to pointers. This allows applications like
248
  the linker to accumulate and output large symbol tables
249
  without having to do too much byte copying.
250
251
  This function runs through the provided symbol table and
252
  patches each symbol marked as a file place holder
253
  (@code{C_FILE}) to point to the next file place holder in the
254
  list. It also marks each @code{offset} field in the list with
255
  the offset from the first symbol of the current symbol.
256
257
  Another function of this procedure is to turn the canonical
258
  value form of BFD into the form used by coff. Internally, BFD
259
  expects symbol values to be offsets from a section base; so a
260
  symbol physically at 0x120, but in a section starting at
261
  0x100, would have the value 0x20. Coff expects symbols to
262
  contain their final value, so symbols have their values
263
  changed at this point to reflect their sum with their owning
264
  section.  This transformation uses the
265
  <<output_section>> field of the @code{asymbol}'s
266
  @code{asection} @xref{Sections}.
267
268
  o <<coff_mangle_symbols>>
269
270
  This routine runs though the provided symbol table and uses
271
  the offsets generated by the previous pass and the pointers
272
  generated when the symbol table was read in to create the
273
  structured hierarchy required by coff. It changes each pointer
274
  to a symbol into the index into the symbol table of the asymbol.
275
276
  o <<coff_write_symbols>>
277
278
  This routine runs through the symbol table and patches up the
279
  symbols from their internal form into the coff way, calls the
280
  bit twiddlers, and writes out the table to the file.
281
282
*/
283
284
/*
285
INTERNAL_DEFINITION
286
  coff_symbol_type
287
288
DESCRIPTION
289
  The hidden information for an <<asymbol>> is described in a
290
  <<combined_entry_type>>:
291
292
CODE_FRAGMENT
293
.typedef struct coff_ptr_struct
294
.{
295
.  {* Remembers the offset from the first symbol in the file for
296
.     this symbol.  Generated by coff_renumber_symbols.  *}
297
.  unsigned int offset;
298
.
299
.  {* Selects between the elements of the union below.  *}
300
.  unsigned int is_sym : 1;
301
.
302
.  {* Selects between the elements of the x_sym.x_tagndx union.  If set,
303
.     p is valid and the field will be renumbered.  *}
304
.  unsigned int fix_tag : 1;
305
.
306
.  {* Selects between the elements of the x_sym.x_fcnary.x_fcn.x_endndx
307
.     union.  If set, p is valid and the field will be renumbered.  *}
308
.  unsigned int fix_end : 1;
309
.
310
.  {* Selects between the elements of the x_csect.x_scnlen union.  If set,
311
.     p is valid and the field will be renumbered.  *}
312
.  unsigned int fix_scnlen : 1;
313
.
314
.  {* If set, u.syment.n_value contains a pointer to a symbol.  The final
315
.     value will be the offset field.  Used for XCOFF C_BSTAT symbols.  *}
316
.  unsigned int fix_value : 1;
317
.
318
.  {* If set, u.syment.n_value is an index into the line number entries.
319
.     Used for XCOFF C_BINCL/C_EINCL symbols.  *}
320
.  unsigned int fix_line : 1;
321
.
322
.  {* The container for the symbol structure as read and translated
323
.     from the file.  *}
324
.  union
325
.  {
326
.    union internal_auxent auxent;
327
.    struct internal_syment syment;
328
.  } u;
329
.
330
. {* An extra pointer which can used by format based on COFF (like XCOFF)
331
.    to provide extra information to their backend.  *}
332
. void *extrap;
333
.} combined_entry_type;
334
.
335
.{* Each canonical asymbol really looks like this: *}
336
.
337
.typedef struct coff_symbol_struct
338
.{
339
.  {* The actual symbol which the rest of BFD works with *}
340
.  asymbol symbol;
341
.
342
.  {* A pointer to the hidden information for this symbol *}
343
.  combined_entry_type *native;
344
.
345
.  {* A pointer to the linenumber information for this symbol *}
346
.  struct lineno_cache_entry *lineno;
347
.
348
.  {* Have the line numbers been relocated yet ? *}
349
.  bool done_lineno;
350
.} coff_symbol_type;
351
.
352
*/
353
354
#include "libiberty.h"
355
#include <string.h>
356
357
#ifdef COFF_WITH_PE
358
#include "peicode.h"
359
#else
360
#include "coffswap.h"
361
#endif
362
363
22
#define STRING_SIZE_SIZE 4
364
365
387k
#define DOT_DEBUG ".debug"
366
387k
#define DOT_ZDEBUG  ".zdebug"
367
53.2k
#define GNU_LINKONCE_WI ".gnu.linkonce.wi."
368
53.2k
#define GNU_LINKONCE_WT ".gnu.linkonce.wt."
369
94
#define DOT_RELOC ".reloc"
370
371
#if defined(COFF_WITH_PE) || defined(COFF_GO32_EXE) || defined(COFF_GO32)
372
# define COFF_WITH_EXTENDED_RELOC_COUNTER
373
#endif
374
375
#if defined (COFF_LONG_SECTION_NAMES)
376
/* Needed to expand the inputs to BLANKOR1TOODD.  */
377
#define COFFLONGSECTIONCATHELPER(x,y)    x ## y
378
/* If the input macro Y is blank or '1', return an odd number; if it is
379
   '0', return an even number.  Result undefined in all other cases.  */
380
#define BLANKOR1TOODD(y)     COFFLONGSECTIONCATHELPER(1,y)
381
/* Defined to numerical 0 or 1 according to whether generation of long
382
   section names is disabled or enabled by default.  */
383
#define COFF_ENABLE_LONG_SECTION_NAMES   (BLANKOR1TOODD(COFF_LONG_SECTION_NAMES) & 1)
384
/* Where long section names are supported, we allow them to be enabled
385
   and disabled at runtime, so select an appropriate hook function for
386
   _bfd_coff_set_long_section_names.  */
387
#define COFF_LONG_SECTION_NAMES_SETTER   bfd_coff_set_long_section_names_allowed
388
#else /* !defined (COFF_LONG_SECTION_NAMES) */
389
/* If long section names are not supported, this stub disallows any
390
   attempt to enable them at run-time.  */
391
#define COFF_LONG_SECTION_NAMES_SETTER   bfd_coff_set_long_section_names_disallowed
392
#endif /* defined (COFF_LONG_SECTION_NAMES) */
393
394
/* Define a macro that can be used to initialise both the fields relating
395
   to long section names in the backend data struct simultaneously.  */
396
#if COFF_ENABLE_LONG_SECTION_NAMES
397
#define COFF_DEFAULT_LONG_SECTION_NAMES  (true), COFF_LONG_SECTION_NAMES_SETTER
398
#else /* !COFF_ENABLE_LONG_SECTION_NAMES */
399
#define COFF_DEFAULT_LONG_SECTION_NAMES  (false), COFF_LONG_SECTION_NAMES_SETTER
400
#endif /* COFF_ENABLE_LONG_SECTION_NAMES */
401
402
static enum coff_symbol_classification coff_classify_symbol
403
  (bfd *, struct internal_syment *);
404

405
/* void warning(); */
406
407
#if defined (COFF_LONG_SECTION_NAMES)
408
static bool
409
bfd_coff_set_long_section_names_allowed (bfd *abfd, int enable)
410
121k
{
411
121k
  bfd_coff_long_section_names (abfd) = enable;
412
121k
  return true;
413
121k
}
pei-i386.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
239
{
411
239
  bfd_coff_long_section_names (abfd) = enable;
412
239
  return true;
413
239
}
pe-x86_64.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
571
{
411
571
  bfd_coff_long_section_names (abfd) = enable;
412
571
  return true;
413
571
}
pei-x86_64.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
1.04k
{
411
1.04k
  bfd_coff_long_section_names (abfd) = enable;
412
1.04k
  return true;
413
1.04k
}
pe-aarch64.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
218
{
411
218
  bfd_coff_long_section_names (abfd) = enable;
412
218
  return true;
413
218
}
pei-aarch64.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
5.47k
{
411
5.47k
  bfd_coff_long_section_names (abfd) = enable;
412
5.47k
  return true;
413
5.47k
}
pei-ia64.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
218
{
411
218
  bfd_coff_long_section_names (abfd) = enable;
412
218
  return true;
413
218
}
pei-loongarch64.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
494
{
411
494
  bfd_coff_long_section_names (abfd) = enable;
412
494
  return true;
413
494
}
coff-go32.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
7.69k
{
411
7.69k
  bfd_coff_long_section_names (abfd) = enable;
412
7.69k
  return true;
413
7.69k
}
coff-stgo32.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
93.1k
{
411
93.1k
  bfd_coff_long_section_names (abfd) = enable;
412
93.1k
  return true;
413
93.1k
}
pe-arm-wince.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
4
{
411
4
  bfd_coff_long_section_names (abfd) = enable;
412
4
  return true;
413
4
}
pe-arm.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
4
{
411
4
  bfd_coff_long_section_names (abfd) = enable;
412
4
  return true;
413
4
}
pe-i386.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
1.08k
{
411
1.08k
  bfd_coff_long_section_names (abfd) = enable;
412
1.08k
  return true;
413
1.08k
}
pe-mcore.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
237
{
411
237
  bfd_coff_long_section_names (abfd) = enable;
412
237
  return true;
413
237
}
pe-sh.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
4.84k
{
411
4.84k
  bfd_coff_long_section_names (abfd) = enable;
412
4.84k
  return true;
413
4.84k
}
pei-arm-wince.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
4.11k
{
411
4.11k
  bfd_coff_long_section_names (abfd) = enable;
412
4.11k
  return true;
413
4.11k
}
pei-arm.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
28
{
411
28
  bfd_coff_long_section_names (abfd) = enable;
412
28
  return true;
413
28
}
pei-mcore.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
15
{
411
15
  bfd_coff_long_section_names (abfd) = enable;
412
15
  return true;
413
15
}
pei-sh.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
1.54k
{
411
1.54k
  bfd_coff_long_section_names (abfd) = enable;
412
1.54k
  return true;
413
1.54k
}
414
#else /* !defined (COFF_LONG_SECTION_NAMES) */
415
static bool
416
bfd_coff_set_long_section_names_disallowed (bfd *abfd ATTRIBUTE_UNUSED,
417
              int enable ATTRIBUTE_UNUSED)
418
1.01M
{
419
1.01M
  return false;
420
1.01M
}
coff-x86_64.c:bfd_coff_set_long_section_names_disallowed
Line
Count
Source
418
20.4k
{
419
20.4k
  return false;
420
20.4k
}
coff64-rs6000.c:bfd_coff_set_long_section_names_disallowed
Line
Count
Source
418
180k
{
419
180k
  return false;
420
180k
}
cf-i386lynx.c:bfd_coff_set_long_section_names_disallowed
Line
Count
Source
418
82.1k
{
419
82.1k
  return false;
420
82.1k
}
coff-i386.c:bfd_coff_set_long_section_names_disallowed
Line
Count
Source
418
7.92k
{
419
7.92k
  return false;
420
7.92k
}
coff-rs6000.c:bfd_coff_set_long_section_names_disallowed
Line
Count
Source
418
220k
{
419
220k
  return false;
420
220k
}
coff-sh.c:bfd_coff_set_long_section_names_disallowed
Line
Count
Source
418
361k
{
419
361k
  return false;
420
361k
}
coff-tic30.c:bfd_coff_set_long_section_names_disallowed
Line
Count
Source
418
10.7k
{
419
10.7k
  return false;
420
10.7k
}
Unexecuted instantiation: coff-tic4x.c:bfd_coff_set_long_section_names_disallowed
coff-tic54x.c:bfd_coff_set_long_section_names_disallowed
Line
Count
Source
418
22.9k
{
419
22.9k
  return false;
420
22.9k
}
coff-z80.c:bfd_coff_set_long_section_names_disallowed
Line
Count
Source
418
9.22k
{
419
9.22k
  return false;
420
9.22k
}
coff-z8k.c:bfd_coff_set_long_section_names_disallowed
Line
Count
Source
418
98.5k
{
419
98.5k
  return false;
420
98.5k
}
421
#endif /* defined (COFF_LONG_SECTION_NAMES) */
422
423
/* Return a word with STYP_* (scnhdr.s_flags) flags set to represent
424
   the incoming SEC_* flags.  The inverse of this function is
425
   styp_to_sec_flags().  NOTE: If you add to/change this routine, you
426
   should probably mirror the changes in styp_to_sec_flags().  */
427
428
#ifndef COFF_WITH_PE
429
430
/* Macros for setting debugging flags.  */
431
432
#ifdef STYP_DEBUG
433
0
#define STYP_XCOFF_DEBUG STYP_DEBUG
434
#else
435
0
#define STYP_XCOFF_DEBUG STYP_INFO
436
#endif
437
438
#ifdef COFF_ALIGN_IN_S_FLAGS
439
0
#define STYP_DEBUG_INFO STYP_DSECT
440
#else
441
0
#define STYP_DEBUG_INFO STYP_INFO
442
#endif
443
444
static long
445
sec_to_styp_flags (const char *sec_name, flagword sec_flags)
446
254
{
447
254
  long styp_flags = 0;
448
449
254
  if (!strcmp (sec_name, _TEXT))
450
0
    {
451
0
      styp_flags = STYP_TEXT;
452
0
    }
453
254
  else if (!strcmp (sec_name, _DATA))
454
0
    {
455
0
      styp_flags = STYP_DATA;
456
0
    }
457
254
  else if (!strcmp (sec_name, _BSS))
458
0
    {
459
0
      styp_flags = STYP_BSS;
460
#ifdef _COMMENT
461
    }
462
254
  else if (!strcmp (sec_name, _COMMENT))
463
0
    {
464
0
      styp_flags = STYP_INFO;
465
#endif /* _COMMENT */
466
#ifdef _LIB
467
    }
468
254
  else if (!strcmp (sec_name, _LIB))
469
0
    {
470
0
      styp_flags = STYP_LIB;
471
#endif /* _LIB */
472
#ifdef _LIT
473
    }
474
  else if (!strcmp (sec_name, _LIT))
475
    {
476
      styp_flags = STYP_LIT;
477
#endif /* _LIT */
478
0
    }
479
254
  else if (startswith (sec_name, DOT_DEBUG)
480
254
     || startswith (sec_name, DOT_ZDEBUG))
481
0
    {
482
      /* Handle the XCOFF debug section and DWARF2 debug sections.  */
483
0
      if (!sec_name[6])
484
0
  styp_flags = STYP_XCOFF_DEBUG;
485
0
      else
486
0
  styp_flags = STYP_DEBUG_INFO;
487
0
    }
488
254
  else if (startswith (sec_name, ".stab"))
489
0
    {
490
0
      styp_flags = STYP_DEBUG_INFO;
491
0
    }
492
#ifdef COFF_LONG_SECTION_NAMES
493
0
  else if (startswith (sec_name, GNU_LINKONCE_WI)
494
0
     || startswith (sec_name, GNU_LINKONCE_WT))
495
0
    {
496
0
      styp_flags = STYP_DEBUG_INFO;
497
0
    }
498
0
#endif
499
#ifdef RS6000COFF_C
500
0
  else if (!strcmp (sec_name, _TDATA))
501
0
    {
502
0
      styp_flags = STYP_TDATA;
503
0
    }
504
0
  else if (!strcmp (sec_name, _TBSS))
505
0
    {
506
0
      styp_flags = STYP_TBSS;
507
0
    }
508
0
  else if (!strcmp (sec_name, _PAD))
509
0
    {
510
0
      styp_flags = STYP_PAD;
511
0
    }
512
0
  else if (!strcmp (sec_name, _LOADER))
513
0
    {
514
0
      styp_flags = STYP_LOADER;
515
0
    }
516
0
  else if (!strcmp (sec_name, _EXCEPT))
517
0
    {
518
0
      styp_flags = STYP_EXCEPT;
519
0
    }
520
0
  else if (!strcmp (sec_name, _TYPCHK))
521
0
    {
522
0
      styp_flags = STYP_TYPCHK;
523
0
    }
524
0
  else if (sec_flags & SEC_DEBUGGING)
525
0
    {
526
0
      int i;
527
528
0
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
529
0
  if (!strcmp (sec_name, xcoff_dwsect_names[i].xcoff_name))
530
0
    {
531
0
      styp_flags = STYP_DWARF | xcoff_dwsect_names[i].flag;
532
0
      break;
533
0
    }
534
0
    }
535
0
#endif
536
  /* Try and figure out what it should be */
537
254
  else if (sec_flags & SEC_CODE)
538
0
    {
539
0
      styp_flags = STYP_TEXT;
540
0
    }
541
254
  else if (sec_flags & SEC_DATA)
542
0
    {
543
0
      styp_flags = STYP_DATA;
544
0
    }
545
254
  else if (sec_flags & SEC_READONLY)
546
0
    {
547
0
#ifdef STYP_LIT     /* 29k readonly text/data section */
548
0
      styp_flags = STYP_LIT;
549
#else
550
      styp_flags = STYP_TEXT;
551
#endif /* STYP_LIT */
552
0
    }
553
254
  else if (sec_flags & SEC_LOAD)
554
254
    {
555
254
      styp_flags = STYP_TEXT;
556
254
    }
557
0
  else if (sec_flags & SEC_ALLOC)
558
0
    {
559
0
      styp_flags = STYP_BSS;
560
0
    }
561
562
#ifdef STYP_CLINK
563
0
  if (sec_flags & SEC_TIC54X_CLINK)
564
0
    styp_flags |= STYP_CLINK;
565
#endif
566
567
#ifdef STYP_BLOCK
568
0
  if (sec_flags & SEC_TIC54X_BLOCK)
569
0
    styp_flags |= STYP_BLOCK;
570
#endif
571
572
254
#ifdef STYP_NOLOAD
573
254
  if ((sec_flags & (SEC_NEVER_LOAD | SEC_COFF_SHARED_LIBRARY)) != 0)
574
0
    styp_flags |= STYP_NOLOAD;
575
254
#endif
576
577
254
  return styp_flags;
578
254
}
Unexecuted instantiation: coff-x86_64.c:sec_to_styp_flags
Unexecuted instantiation: coff64-rs6000.c:sec_to_styp_flags
Unexecuted instantiation: cf-i386lynx.c:sec_to_styp_flags
Unexecuted instantiation: coff-go32.c:sec_to_styp_flags
Unexecuted instantiation: coff-i386.c:sec_to_styp_flags
Unexecuted instantiation: coff-rs6000.c:sec_to_styp_flags
Unexecuted instantiation: coff-sh.c:sec_to_styp_flags
Unexecuted instantiation: coff-stgo32.c:sec_to_styp_flags
Unexecuted instantiation: coff-tic30.c:sec_to_styp_flags
Unexecuted instantiation: coff-tic4x.c:sec_to_styp_flags
Unexecuted instantiation: coff-tic54x.c:sec_to_styp_flags
Unexecuted instantiation: coff-z80.c:sec_to_styp_flags
coff-z8k.c:sec_to_styp_flags
Line
Count
Source
446
254
{
447
254
  long styp_flags = 0;
448
449
254
  if (!strcmp (sec_name, _TEXT))
450
0
    {
451
0
      styp_flags = STYP_TEXT;
452
0
    }
453
254
  else if (!strcmp (sec_name, _DATA))
454
0
    {
455
0
      styp_flags = STYP_DATA;
456
0
    }
457
254
  else if (!strcmp (sec_name, _BSS))
458
0
    {
459
0
      styp_flags = STYP_BSS;
460
0
#ifdef _COMMENT
461
0
    }
462
254
  else if (!strcmp (sec_name, _COMMENT))
463
0
    {
464
0
      styp_flags = STYP_INFO;
465
0
#endif /* _COMMENT */
466
0
#ifdef _LIB
467
0
    }
468
254
  else if (!strcmp (sec_name, _LIB))
469
0
    {
470
0
      styp_flags = STYP_LIB;
471
0
#endif /* _LIB */
472
#ifdef _LIT
473
    }
474
  else if (!strcmp (sec_name, _LIT))
475
    {
476
      styp_flags = STYP_LIT;
477
#endif /* _LIT */
478
0
    }
479
254
  else if (startswith (sec_name, DOT_DEBUG)
480
254
     || startswith (sec_name, DOT_ZDEBUG))
481
0
    {
482
      /* Handle the XCOFF debug section and DWARF2 debug sections.  */
483
0
      if (!sec_name[6])
484
0
  styp_flags = STYP_XCOFF_DEBUG;
485
0
      else
486
0
  styp_flags = STYP_DEBUG_INFO;
487
0
    }
488
254
  else if (startswith (sec_name, ".stab"))
489
0
    {
490
0
      styp_flags = STYP_DEBUG_INFO;
491
0
    }
492
#ifdef COFF_LONG_SECTION_NAMES
493
  else if (startswith (sec_name, GNU_LINKONCE_WI)
494
     || startswith (sec_name, GNU_LINKONCE_WT))
495
    {
496
      styp_flags = STYP_DEBUG_INFO;
497
    }
498
#endif
499
#ifdef RS6000COFF_C
500
  else if (!strcmp (sec_name, _TDATA))
501
    {
502
      styp_flags = STYP_TDATA;
503
    }
504
  else if (!strcmp (sec_name, _TBSS))
505
    {
506
      styp_flags = STYP_TBSS;
507
    }
508
  else if (!strcmp (sec_name, _PAD))
509
    {
510
      styp_flags = STYP_PAD;
511
    }
512
  else if (!strcmp (sec_name, _LOADER))
513
    {
514
      styp_flags = STYP_LOADER;
515
    }
516
  else if (!strcmp (sec_name, _EXCEPT))
517
    {
518
      styp_flags = STYP_EXCEPT;
519
    }
520
  else if (!strcmp (sec_name, _TYPCHK))
521
    {
522
      styp_flags = STYP_TYPCHK;
523
    }
524
  else if (sec_flags & SEC_DEBUGGING)
525
    {
526
      int i;
527
528
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
529
  if (!strcmp (sec_name, xcoff_dwsect_names[i].xcoff_name))
530
    {
531
      styp_flags = STYP_DWARF | xcoff_dwsect_names[i].flag;
532
      break;
533
    }
534
    }
535
#endif
536
  /* Try and figure out what it should be */
537
254
  else if (sec_flags & SEC_CODE)
538
0
    {
539
0
      styp_flags = STYP_TEXT;
540
0
    }
541
254
  else if (sec_flags & SEC_DATA)
542
0
    {
543
0
      styp_flags = STYP_DATA;
544
0
    }
545
254
  else if (sec_flags & SEC_READONLY)
546
0
    {
547
0
#ifdef STYP_LIT     /* 29k readonly text/data section */
548
0
      styp_flags = STYP_LIT;
549
#else
550
      styp_flags = STYP_TEXT;
551
#endif /* STYP_LIT */
552
0
    }
553
254
  else if (sec_flags & SEC_LOAD)
554
254
    {
555
254
      styp_flags = STYP_TEXT;
556
254
    }
557
0
  else if (sec_flags & SEC_ALLOC)
558
0
    {
559
0
      styp_flags = STYP_BSS;
560
0
    }
561
562
#ifdef STYP_CLINK
563
  if (sec_flags & SEC_TIC54X_CLINK)
564
    styp_flags |= STYP_CLINK;
565
#endif
566
567
#ifdef STYP_BLOCK
568
  if (sec_flags & SEC_TIC54X_BLOCK)
569
    styp_flags |= STYP_BLOCK;
570
#endif
571
572
254
#ifdef STYP_NOLOAD
573
254
  if ((sec_flags & (SEC_NEVER_LOAD | SEC_COFF_SHARED_LIBRARY)) != 0)
574
0
    styp_flags |= STYP_NOLOAD;
575
254
#endif
576
577
254
  return styp_flags;
578
254
}
579
580
#else /* COFF_WITH_PE */
581
582
/* The PE version; see above for the general comments.  The non-PE
583
   case seems to be more guessing, and breaks PE format; specifically,
584
   .rdata is readonly, but it sure ain't text.  Really, all this
585
   should be set up properly in gas (or whatever assembler is in use),
586
   and honor whatever objcopy/strip, etc. sent us as input.  */
587
588
static long
589
sec_to_styp_flags (const char *sec_name, flagword sec_flags)
590
601
{
591
601
  long styp_flags = 0;
592
601
  bool is_dbg = false;
593
594
601
  if (startswith (sec_name, DOT_DEBUG)
595
601
      || startswith (sec_name, DOT_ZDEBUG)
596
601
#ifdef COFF_LONG_SECTION_NAMES
597
601
      || startswith (sec_name, GNU_LINKONCE_WI)
598
601
      || startswith (sec_name, GNU_LINKONCE_WT)
599
601
#endif
600
601
      || startswith (sec_name, ".stab"))
601
40
    is_dbg = true;
602
603
  /* caution: there are at least three groups of symbols that have
604
     very similar bits and meanings: IMAGE_SCN*, SEC_*, and STYP_*.
605
     SEC_* are the BFD internal flags, used for generic BFD
606
     information.  STYP_* are the COFF section flags which appear in
607
     COFF files.  IMAGE_SCN_* are the PE section flags which appear in
608
     PE files.  The STYP_* flags and the IMAGE_SCN_* flags overlap,
609
     but there are more IMAGE_SCN_* flags.  */
610
611
  /* FIXME: There is no gas syntax to specify the debug section flag.  */
612
601
  if (is_dbg)
613
40
    {
614
40
      sec_flags &= (SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD
615
40
        | SEC_LINK_DUPLICATES_SAME_CONTENTS
616
40
        | SEC_LINK_DUPLICATES_SAME_SIZE);
617
40
      sec_flags |= SEC_DEBUGGING | SEC_READONLY;
618
40
    }
619
620
  /* skip LOAD */
621
  /* READONLY later */
622
  /* skip RELOC */
623
601
  if ((sec_flags & SEC_CODE) != 0)
624
5
    styp_flags |= IMAGE_SCN_CNT_CODE;
625
601
  if ((sec_flags & (SEC_DATA | SEC_DEBUGGING)) != 0)
626
92
    styp_flags |= IMAGE_SCN_CNT_INITIALIZED_DATA;
627
601
  if ((sec_flags & SEC_ALLOC) != 0 && (sec_flags & SEC_LOAD) == 0)
628
4
    styp_flags |= IMAGE_SCN_CNT_UNINITIALIZED_DATA;  /* ==STYP_BSS */
629
  /* skip ROM */
630
  /* skip constRUCTOR */
631
  /* skip CONTENTS */
632
#ifndef COFF_IMAGE_WITH_PE
633
  /* I don't think any of the IMAGE_SCN_LNK_* flags set below should be set
634
     when the output is PE. Only object files should have them, for the linker
635
     to consume.  */
636
507
  if ((sec_flags & SEC_IS_COMMON) != 0)
637
0
    styp_flags |= IMAGE_SCN_LNK_COMDAT;
638
#endif
639
601
  if ((sec_flags & SEC_DEBUGGING) != 0)
640
42
    styp_flags |= IMAGE_SCN_MEM_DISCARDABLE;
641
601
  if ((sec_flags & (SEC_EXCLUDE | SEC_NEVER_LOAD)) != 0 && !is_dbg)
642
#ifdef COFF_IMAGE_WITH_PE
643
0
    styp_flags |= IMAGE_SCN_MEM_DISCARDABLE;
644
#else
645
0
    styp_flags |= IMAGE_SCN_LNK_REMOVE;
646
#endif
647
  /* skip IN_MEMORY */
648
  /* skip SORT */
649
#ifndef COFF_IMAGE_WITH_PE
650
507
  if (sec_flags & SEC_LINK_ONCE)
651
1
    styp_flags |= IMAGE_SCN_LNK_COMDAT;
652
507
  if ((sec_flags
653
507
       & (SEC_LINK_DUPLICATES_DISCARD | SEC_LINK_DUPLICATES_SAME_CONTENTS
654
507
    | SEC_LINK_DUPLICATES_SAME_SIZE)) != 0)
655
0
    styp_flags |= IMAGE_SCN_LNK_COMDAT;
656
#endif
657
658
  /* skip LINKER_CREATED */
659
660
601
  if ((sec_flags & SEC_COFF_NOREAD) == 0)
661
96
    styp_flags |= IMAGE_SCN_MEM_READ;     /* Invert NOREAD for read.  */
662
601
  if ((sec_flags & SEC_READONLY) == 0)
663
17
    styp_flags |= IMAGE_SCN_MEM_WRITE;    /* Invert READONLY for write.  */
664
601
  if (sec_flags & SEC_CODE)
665
5
    styp_flags |= IMAGE_SCN_MEM_EXECUTE;  /* CODE->EXECUTE.  */
666
601
  if (sec_flags & SEC_COFF_SHARED)
667
0
    styp_flags |= IMAGE_SCN_MEM_SHARED;   /* Shared remains meaningful.  */
668
669
601
  return styp_flags;
670
601
}
pei-i386.c:sec_to_styp_flags
Line
Count
Source
590
13
{
591
13
  long styp_flags = 0;
592
13
  bool is_dbg = false;
593
594
13
  if (startswith (sec_name, DOT_DEBUG)
595
13
      || startswith (sec_name, DOT_ZDEBUG)
596
13
#ifdef COFF_LONG_SECTION_NAMES
597
13
      || startswith (sec_name, GNU_LINKONCE_WI)
598
13
      || startswith (sec_name, GNU_LINKONCE_WT)
599
13
#endif
600
13
      || startswith (sec_name, ".stab"))
601
0
    is_dbg = true;
602
603
  /* caution: there are at least three groups of symbols that have
604
     very similar bits and meanings: IMAGE_SCN*, SEC_*, and STYP_*.
605
     SEC_* are the BFD internal flags, used for generic BFD
606
     information.  STYP_* are the COFF section flags which appear in
607
     COFF files.  IMAGE_SCN_* are the PE section flags which appear in
608
     PE files.  The STYP_* flags and the IMAGE_SCN_* flags overlap,
609
     but there are more IMAGE_SCN_* flags.  */
610
611
  /* FIXME: There is no gas syntax to specify the debug section flag.  */
612
13
  if (is_dbg)
613
0
    {
614
0
      sec_flags &= (SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD
615
0
        | SEC_LINK_DUPLICATES_SAME_CONTENTS
616
0
        | SEC_LINK_DUPLICATES_SAME_SIZE);
617
0
      sec_flags |= SEC_DEBUGGING | SEC_READONLY;
618
0
    }
619
620
  /* skip LOAD */
621
  /* READONLY later */
622
  /* skip RELOC */
623
13
  if ((sec_flags & SEC_CODE) != 0)
624
2
    styp_flags |= IMAGE_SCN_CNT_CODE;
625
13
  if ((sec_flags & (SEC_DATA | SEC_DEBUGGING)) != 0)
626
11
    styp_flags |= IMAGE_SCN_CNT_INITIALIZED_DATA;
627
13
  if ((sec_flags & SEC_ALLOC) != 0 && (sec_flags & SEC_LOAD) == 0)
628
1
    styp_flags |= IMAGE_SCN_CNT_UNINITIALIZED_DATA;  /* ==STYP_BSS */
629
  /* skip ROM */
630
  /* skip constRUCTOR */
631
  /* skip CONTENTS */
632
#ifndef COFF_IMAGE_WITH_PE
633
  /* I don't think any of the IMAGE_SCN_LNK_* flags set below should be set
634
     when the output is PE. Only object files should have them, for the linker
635
     to consume.  */
636
  if ((sec_flags & SEC_IS_COMMON) != 0)
637
    styp_flags |= IMAGE_SCN_LNK_COMDAT;
638
#endif
639
13
  if ((sec_flags & SEC_DEBUGGING) != 0)
640
1
    styp_flags |= IMAGE_SCN_MEM_DISCARDABLE;
641
13
  if ((sec_flags & (SEC_EXCLUDE | SEC_NEVER_LOAD)) != 0 && !is_dbg)
642
0
#ifdef COFF_IMAGE_WITH_PE
643
0
    styp_flags |= IMAGE_SCN_MEM_DISCARDABLE;
644
#else
645
    styp_flags |= IMAGE_SCN_LNK_REMOVE;
646
#endif
647
  /* skip IN_MEMORY */
648
  /* skip SORT */
649
#ifndef COFF_IMAGE_WITH_PE
650
  if (sec_flags & SEC_LINK_ONCE)
651
    styp_flags |= IMAGE_SCN_LNK_COMDAT;
652
  if ((sec_flags
653
       & (SEC_LINK_DUPLICATES_DISCARD | SEC_LINK_DUPLICATES_SAME_CONTENTS
654
    | SEC_LINK_DUPLICATES_SAME_SIZE)) != 0)
655
    styp_flags |= IMAGE_SCN_LNK_COMDAT;
656
#endif
657
658
  /* skip LINKER_CREATED */
659
660
13
  if ((sec_flags & SEC_COFF_NOREAD) == 0)
661
13
    styp_flags |= IMAGE_SCN_MEM_READ;     /* Invert NOREAD for read.  */
662
13
  if ((sec_flags & SEC_READONLY) == 0)
663
5
    styp_flags |= IMAGE_SCN_MEM_WRITE;    /* Invert READONLY for write.  */
664
13
  if (sec_flags & SEC_CODE)
665
2
    styp_flags |= IMAGE_SCN_MEM_EXECUTE;  /* CODE->EXECUTE.  */
666
13
  if (sec_flags & SEC_COFF_SHARED)
667
0
    styp_flags |= IMAGE_SCN_MEM_SHARED;   /* Shared remains meaningful.  */
668
669
13
  return styp_flags;
670
13
}
Unexecuted instantiation: pe-x86_64.c:sec_to_styp_flags
pei-x86_64.c:sec_to_styp_flags
Line
Count
Source
590
75
{
591
75
  long styp_flags = 0;
592
75
  bool is_dbg = false;
593
594
75
  if (startswith (sec_name, DOT_DEBUG)
595
75
      || startswith (sec_name, DOT_ZDEBUG)
596
75
#ifdef COFF_LONG_SECTION_NAMES
597
75
      || startswith (sec_name, GNU_LINKONCE_WI)
598
75
      || startswith (sec_name, GNU_LINKONCE_WT)
599
75
#endif
600
75
      || startswith (sec_name, ".stab"))
601
32
    is_dbg = true;
602
603
  /* caution: there are at least three groups of symbols that have
604
     very similar bits and meanings: IMAGE_SCN*, SEC_*, and STYP_*.
605
     SEC_* are the BFD internal flags, used for generic BFD
606
     information.  STYP_* are the COFF section flags which appear in
607
     COFF files.  IMAGE_SCN_* are the PE section flags which appear in
608
     PE files.  The STYP_* flags and the IMAGE_SCN_* flags overlap,
609
     but there are more IMAGE_SCN_* flags.  */
610
611
  /* FIXME: There is no gas syntax to specify the debug section flag.  */
612
75
  if (is_dbg)
613
32
    {
614
32
      sec_flags &= (SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD
615
32
        | SEC_LINK_DUPLICATES_SAME_CONTENTS
616
32
        | SEC_LINK_DUPLICATES_SAME_SIZE);
617
32
      sec_flags |= SEC_DEBUGGING | SEC_READONLY;
618
32
    }
619
620
  /* skip LOAD */
621
  /* READONLY later */
622
  /* skip RELOC */
623
75
  if ((sec_flags & SEC_CODE) != 0)
624
3
    styp_flags |= IMAGE_SCN_CNT_CODE;
625
75
  if ((sec_flags & (SEC_DATA | SEC_DEBUGGING)) != 0)
626
72
    styp_flags |= IMAGE_SCN_CNT_INITIALIZED_DATA;
627
75
  if ((sec_flags & SEC_ALLOC) != 0 && (sec_flags & SEC_LOAD) == 0)
628
3
    styp_flags |= IMAGE_SCN_CNT_UNINITIALIZED_DATA;  /* ==STYP_BSS */
629
  /* skip ROM */
630
  /* skip constRUCTOR */
631
  /* skip CONTENTS */
632
#ifndef COFF_IMAGE_WITH_PE
633
  /* I don't think any of the IMAGE_SCN_LNK_* flags set below should be set
634
     when the output is PE. Only object files should have them, for the linker
635
     to consume.  */
636
  if ((sec_flags & SEC_IS_COMMON) != 0)
637
    styp_flags |= IMAGE_SCN_LNK_COMDAT;
638
#endif
639
75
  if ((sec_flags & SEC_DEBUGGING) != 0)
640
32
    styp_flags |= IMAGE_SCN_MEM_DISCARDABLE;
641
75
  if ((sec_flags & (SEC_EXCLUDE | SEC_NEVER_LOAD)) != 0 && !is_dbg)
642
0
#ifdef COFF_IMAGE_WITH_PE
643
0
    styp_flags |= IMAGE_SCN_MEM_DISCARDABLE;
644
#else
645
    styp_flags |= IMAGE_SCN_LNK_REMOVE;
646
#endif
647
  /* skip IN_MEMORY */
648
  /* skip SORT */
649
#ifndef COFF_IMAGE_WITH_PE
650
  if (sec_flags & SEC_LINK_ONCE)
651
    styp_flags |= IMAGE_SCN_LNK_COMDAT;
652
  if ((sec_flags
653
       & (SEC_LINK_DUPLICATES_DISCARD | SEC_LINK_DUPLICATES_SAME_CONTENTS
654
    | SEC_LINK_DUPLICATES_SAME_SIZE)) != 0)
655
    styp_flags |= IMAGE_SCN_LNK_COMDAT;
656
#endif
657
658
  /* skip LINKER_CREATED */
659
660
75
  if ((sec_flags & SEC_COFF_NOREAD) == 0)
661
75
    styp_flags |= IMAGE_SCN_MEM_READ;     /* Invert NOREAD for read.  */
662
75
  if ((sec_flags & SEC_READONLY) == 0)
663
12
    styp_flags |= IMAGE_SCN_MEM_WRITE;    /* Invert READONLY for write.  */
664
75
  if (sec_flags & SEC_CODE)
665
3
    styp_flags |= IMAGE_SCN_MEM_EXECUTE;  /* CODE->EXECUTE.  */
666
75
  if (sec_flags & SEC_COFF_SHARED)
667
0
    styp_flags |= IMAGE_SCN_MEM_SHARED;   /* Shared remains meaningful.  */
668
669
75
  return styp_flags;
670
75
}
pe-aarch64.c:sec_to_styp_flags
Line
Count
Source
590
1
{
591
1
  long styp_flags = 0;
592
1
  bool is_dbg = false;
593
594
1
  if (startswith (sec_name, DOT_DEBUG)
595
1
      || startswith (sec_name, DOT_ZDEBUG)
596
1
#ifdef COFF_LONG_SECTION_NAMES
597
1
      || startswith (sec_name, GNU_LINKONCE_WI)
598
1
      || startswith (sec_name, GNU_LINKONCE_WT)
599
1
#endif
600
1
      || startswith (sec_name, ".stab"))
601
0
    is_dbg = true;
602
603
  /* caution: there are at least three groups of symbols that have
604
     very similar bits and meanings: IMAGE_SCN*, SEC_*, and STYP_*.
605
     SEC_* are the BFD internal flags, used for generic BFD
606
     information.  STYP_* are the COFF section flags which appear in
607
     COFF files.  IMAGE_SCN_* are the PE section flags which appear in
608
     PE files.  The STYP_* flags and the IMAGE_SCN_* flags overlap,
609
     but there are more IMAGE_SCN_* flags.  */
610
611
  /* FIXME: There is no gas syntax to specify the debug section flag.  */
612
1
  if (is_dbg)
613
0
    {
614
0
      sec_flags &= (SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD
615
0
        | SEC_LINK_DUPLICATES_SAME_CONTENTS
616
0
        | SEC_LINK_DUPLICATES_SAME_SIZE);
617
0
      sec_flags |= SEC_DEBUGGING | SEC_READONLY;
618
0
    }
619
620
  /* skip LOAD */
621
  /* READONLY later */
622
  /* skip RELOC */
623
1
  if ((sec_flags & SEC_CODE) != 0)
624
0
    styp_flags |= IMAGE_SCN_CNT_CODE;
625
1
  if ((sec_flags & (SEC_DATA | SEC_DEBUGGING)) != 0)
626
0
    styp_flags |= IMAGE_SCN_CNT_INITIALIZED_DATA;
627
1
  if ((sec_flags & SEC_ALLOC) != 0 && (sec_flags & SEC_LOAD) == 0)
628
0
    styp_flags |= IMAGE_SCN_CNT_UNINITIALIZED_DATA;  /* ==STYP_BSS */
629
  /* skip ROM */
630
  /* skip constRUCTOR */
631
  /* skip CONTENTS */
632
1
#ifndef COFF_IMAGE_WITH_PE
633
  /* I don't think any of the IMAGE_SCN_LNK_* flags set below should be set
634
     when the output is PE. Only object files should have them, for the linker
635
     to consume.  */
636
1
  if ((sec_flags & SEC_IS_COMMON) != 0)
637
0
    styp_flags |= IMAGE_SCN_LNK_COMDAT;
638
1
#endif
639
1
  if ((sec_flags & SEC_DEBUGGING) != 0)
640
0
    styp_flags |= IMAGE_SCN_MEM_DISCARDABLE;
641
1
  if ((sec_flags & (SEC_EXCLUDE | SEC_NEVER_LOAD)) != 0 && !is_dbg)
642
#ifdef COFF_IMAGE_WITH_PE
643
    styp_flags |= IMAGE_SCN_MEM_DISCARDABLE;
644
#else
645
0
    styp_flags |= IMAGE_SCN_LNK_REMOVE;
646
1
#endif
647
  /* skip IN_MEMORY */
648
  /* skip SORT */
649
1
#ifndef COFF_IMAGE_WITH_PE
650
1
  if (sec_flags & SEC_LINK_ONCE)
651
0
    styp_flags |= IMAGE_SCN_LNK_COMDAT;
652
1
  if ((sec_flags
653
1
       & (SEC_LINK_DUPLICATES_DISCARD | SEC_LINK_DUPLICATES_SAME_CONTENTS
654
1
    | SEC_LINK_DUPLICATES_SAME_SIZE)) != 0)
655
0
    styp_flags |= IMAGE_SCN_LNK_COMDAT;
656
1
#endif
657
658
  /* skip LINKER_CREATED */
659
660
1
  if ((sec_flags & SEC_COFF_NOREAD) == 0)
661
0
    styp_flags |= IMAGE_SCN_MEM_READ;     /* Invert NOREAD for read.  */
662
1
  if ((sec_flags & SEC_READONLY) == 0)
663
0
    styp_flags |= IMAGE_SCN_MEM_WRITE;    /* Invert READONLY for write.  */
664
1
  if (sec_flags & SEC_CODE)
665
0
    styp_flags |= IMAGE_SCN_MEM_EXECUTE;  /* CODE->EXECUTE.  */
666
1
  if (sec_flags & SEC_COFF_SHARED)
667
0
    styp_flags |= IMAGE_SCN_MEM_SHARED;   /* Shared remains meaningful.  */
668
669
1
  return styp_flags;
670
1
}
pei-aarch64.c:sec_to_styp_flags
Line
Count
Source
590
4
{
591
4
  long styp_flags = 0;
592
4
  bool is_dbg = false;
593
594
4
  if (startswith (sec_name, DOT_DEBUG)
595
4
      || startswith (sec_name, DOT_ZDEBUG)
596
4
#ifdef COFF_LONG_SECTION_NAMES
597
4
      || startswith (sec_name, GNU_LINKONCE_WI)
598
4
      || startswith (sec_name, GNU_LINKONCE_WT)
599
4
#endif
600
4
      || startswith (sec_name, ".stab"))
601
4
    is_dbg = true;
602
603
  /* caution: there are at least three groups of symbols that have
604
     very similar bits and meanings: IMAGE_SCN*, SEC_*, and STYP_*.
605
     SEC_* are the BFD internal flags, used for generic BFD
606
     information.  STYP_* are the COFF section flags which appear in
607
     COFF files.  IMAGE_SCN_* are the PE section flags which appear in
608
     PE files.  The STYP_* flags and the IMAGE_SCN_* flags overlap,
609
     but there are more IMAGE_SCN_* flags.  */
610
611
  /* FIXME: There is no gas syntax to specify the debug section flag.  */
612
4
  if (is_dbg)
613
4
    {
614
4
      sec_flags &= (SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD
615
4
        | SEC_LINK_DUPLICATES_SAME_CONTENTS
616
4
        | SEC_LINK_DUPLICATES_SAME_SIZE);
617
4
      sec_flags |= SEC_DEBUGGING | SEC_READONLY;
618
4
    }
619
620
  /* skip LOAD */
621
  /* READONLY later */
622
  /* skip RELOC */
623
4
  if ((sec_flags & SEC_CODE) != 0)
624
0
    styp_flags |= IMAGE_SCN_CNT_CODE;
625
4
  if ((sec_flags & (SEC_DATA | SEC_DEBUGGING)) != 0)
626
4
    styp_flags |= IMAGE_SCN_CNT_INITIALIZED_DATA;
627
4
  if ((sec_flags & SEC_ALLOC) != 0 && (sec_flags & SEC_LOAD) == 0)
628
0
    styp_flags |= IMAGE_SCN_CNT_UNINITIALIZED_DATA;  /* ==STYP_BSS */
629
  /* skip ROM */
630
  /* skip constRUCTOR */
631
  /* skip CONTENTS */
632
#ifndef COFF_IMAGE_WITH_PE
633
  /* I don't think any of the IMAGE_SCN_LNK_* flags set below should be set
634
     when the output is PE. Only object files should have them, for the linker
635
     to consume.  */
636
  if ((sec_flags & SEC_IS_COMMON) != 0)
637
    styp_flags |= IMAGE_SCN_LNK_COMDAT;
638
#endif
639
4
  if ((sec_flags & SEC_DEBUGGING) != 0)
640
4
    styp_flags |= IMAGE_SCN_MEM_DISCARDABLE;
641
4
  if ((sec_flags & (SEC_EXCLUDE | SEC_NEVER_LOAD)) != 0 && !is_dbg)
642
0
#ifdef COFF_IMAGE_WITH_PE
643
0
    styp_flags |= IMAGE_SCN_MEM_DISCARDABLE;
644
#else
645
    styp_flags |= IMAGE_SCN_LNK_REMOVE;
646
#endif
647
  /* skip IN_MEMORY */
648
  /* skip SORT */
649
#ifndef COFF_IMAGE_WITH_PE
650
  if (sec_flags & SEC_LINK_ONCE)
651
    styp_flags |= IMAGE_SCN_LNK_COMDAT;
652
  if ((sec_flags
653
       & (SEC_LINK_DUPLICATES_DISCARD | SEC_LINK_DUPLICATES_SAME_CONTENTS
654
    | SEC_LINK_DUPLICATES_SAME_SIZE)) != 0)
655
    styp_flags |= IMAGE_SCN_LNK_COMDAT;
656
#endif
657
658
  /* skip LINKER_CREATED */
659
660
4
  if ((sec_flags & SEC_COFF_NOREAD) == 0)
661
4
    styp_flags |= IMAGE_SCN_MEM_READ;     /* Invert NOREAD for read.  */
662
4
  if ((sec_flags & SEC_READONLY) == 0)
663
0
    styp_flags |= IMAGE_SCN_MEM_WRITE;    /* Invert READONLY for write.  */
664
4
  if (sec_flags & SEC_CODE)
665
0
    styp_flags |= IMAGE_SCN_MEM_EXECUTE;  /* CODE->EXECUTE.  */
666
4
  if (sec_flags & SEC_COFF_SHARED)
667
0
    styp_flags |= IMAGE_SCN_MEM_SHARED;   /* Shared remains meaningful.  */
668
669
4
  return styp_flags;
670
4
}
Unexecuted instantiation: pei-ia64.c:sec_to_styp_flags
Unexecuted instantiation: pei-loongarch64.c:sec_to_styp_flags
Unexecuted instantiation: pe-arm-wince.c:sec_to_styp_flags
Unexecuted instantiation: pe-arm.c:sec_to_styp_flags
pe-i386.c:sec_to_styp_flags
Line
Count
Source
590
499
{
591
499
  long styp_flags = 0;
592
499
  bool is_dbg = false;
593
594
499
  if (startswith (sec_name, DOT_DEBUG)
595
499
      || startswith (sec_name, DOT_ZDEBUG)
596
499
#ifdef COFF_LONG_SECTION_NAMES
597
499
      || startswith (sec_name, GNU_LINKONCE_WI)
598
499
      || startswith (sec_name, GNU_LINKONCE_WT)
599
499
#endif
600
499
      || startswith (sec_name, ".stab"))
601
2
    is_dbg = true;
602
603
  /* caution: there are at least three groups of symbols that have
604
     very similar bits and meanings: IMAGE_SCN*, SEC_*, and STYP_*.
605
     SEC_* are the BFD internal flags, used for generic BFD
606
     information.  STYP_* are the COFF section flags which appear in
607
     COFF files.  IMAGE_SCN_* are the PE section flags which appear in
608
     PE files.  The STYP_* flags and the IMAGE_SCN_* flags overlap,
609
     but there are more IMAGE_SCN_* flags.  */
610
611
  /* FIXME: There is no gas syntax to specify the debug section flag.  */
612
499
  if (is_dbg)
613
2
    {
614
2
      sec_flags &= (SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD
615
2
        | SEC_LINK_DUPLICATES_SAME_CONTENTS
616
2
        | SEC_LINK_DUPLICATES_SAME_SIZE);
617
2
      sec_flags |= SEC_DEBUGGING | SEC_READONLY;
618
2
    }
619
620
  /* skip LOAD */
621
  /* READONLY later */
622
  /* skip RELOC */
623
499
  if ((sec_flags & SEC_CODE) != 0)
624
0
    styp_flags |= IMAGE_SCN_CNT_CODE;
625
499
  if ((sec_flags & (SEC_DATA | SEC_DEBUGGING)) != 0)
626
3
    styp_flags |= IMAGE_SCN_CNT_INITIALIZED_DATA;
627
499
  if ((sec_flags & SEC_ALLOC) != 0 && (sec_flags & SEC_LOAD) == 0)
628
0
    styp_flags |= IMAGE_SCN_CNT_UNINITIALIZED_DATA;  /* ==STYP_BSS */
629
  /* skip ROM */
630
  /* skip constRUCTOR */
631
  /* skip CONTENTS */
632
499
#ifndef COFF_IMAGE_WITH_PE
633
  /* I don't think any of the IMAGE_SCN_LNK_* flags set below should be set
634
     when the output is PE. Only object files should have them, for the linker
635
     to consume.  */
636
499
  if ((sec_flags & SEC_IS_COMMON) != 0)
637
0
    styp_flags |= IMAGE_SCN_LNK_COMDAT;
638
499
#endif
639
499
  if ((sec_flags & SEC_DEBUGGING) != 0)
640
3
    styp_flags |= IMAGE_SCN_MEM_DISCARDABLE;
641
499
  if ((sec_flags & (SEC_EXCLUDE | SEC_NEVER_LOAD)) != 0 && !is_dbg)
642
#ifdef COFF_IMAGE_WITH_PE
643
    styp_flags |= IMAGE_SCN_MEM_DISCARDABLE;
644
#else
645
0
    styp_flags |= IMAGE_SCN_LNK_REMOVE;
646
499
#endif
647
  /* skip IN_MEMORY */
648
  /* skip SORT */
649
499
#ifndef COFF_IMAGE_WITH_PE
650
499
  if (sec_flags & SEC_LINK_ONCE)
651
1
    styp_flags |= IMAGE_SCN_LNK_COMDAT;
652
499
  if ((sec_flags
653
499
       & (SEC_LINK_DUPLICATES_DISCARD | SEC_LINK_DUPLICATES_SAME_CONTENTS
654
499
    | SEC_LINK_DUPLICATES_SAME_SIZE)) != 0)
655
0
    styp_flags |= IMAGE_SCN_LNK_COMDAT;
656
499
#endif
657
658
  /* skip LINKER_CREATED */
659
660
499
  if ((sec_flags & SEC_COFF_NOREAD) == 0)
661
2
    styp_flags |= IMAGE_SCN_MEM_READ;     /* Invert NOREAD for read.  */
662
499
  if ((sec_flags & SEC_READONLY) == 0)
663
0
    styp_flags |= IMAGE_SCN_MEM_WRITE;    /* Invert READONLY for write.  */
664
499
  if (sec_flags & SEC_CODE)
665
0
    styp_flags |= IMAGE_SCN_MEM_EXECUTE;  /* CODE->EXECUTE.  */
666
499
  if (sec_flags & SEC_COFF_SHARED)
667
0
    styp_flags |= IMAGE_SCN_MEM_SHARED;   /* Shared remains meaningful.  */
668
669
499
  return styp_flags;
670
499
}
pe-mcore.c:sec_to_styp_flags
Line
Count
Source
590
7
{
591
7
  long styp_flags = 0;
592
7
  bool is_dbg = false;
593
594
7
  if (startswith (sec_name, DOT_DEBUG)
595
7
      || startswith (sec_name, DOT_ZDEBUG)
596
7
#ifdef COFF_LONG_SECTION_NAMES
597
7
      || startswith (sec_name, GNU_LINKONCE_WI)
598
7
      || startswith (sec_name, GNU_LINKONCE_WT)
599
7
#endif
600
7
      || startswith (sec_name, ".stab"))
601
0
    is_dbg = true;
602
603
  /* caution: there are at least three groups of symbols that have
604
     very similar bits and meanings: IMAGE_SCN*, SEC_*, and STYP_*.
605
     SEC_* are the BFD internal flags, used for generic BFD
606
     information.  STYP_* are the COFF section flags which appear in
607
     COFF files.  IMAGE_SCN_* are the PE section flags which appear in
608
     PE files.  The STYP_* flags and the IMAGE_SCN_* flags overlap,
609
     but there are more IMAGE_SCN_* flags.  */
610
611
  /* FIXME: There is no gas syntax to specify the debug section flag.  */
612
7
  if (is_dbg)
613
0
    {
614
0
      sec_flags &= (SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD
615
0
        | SEC_LINK_DUPLICATES_SAME_CONTENTS
616
0
        | SEC_LINK_DUPLICATES_SAME_SIZE);
617
0
      sec_flags |= SEC_DEBUGGING | SEC_READONLY;
618
0
    }
619
620
  /* skip LOAD */
621
  /* READONLY later */
622
  /* skip RELOC */
623
7
  if ((sec_flags & SEC_CODE) != 0)
624
0
    styp_flags |= IMAGE_SCN_CNT_CODE;
625
7
  if ((sec_flags & (SEC_DATA | SEC_DEBUGGING)) != 0)
626
0
    styp_flags |= IMAGE_SCN_CNT_INITIALIZED_DATA;
627
7
  if ((sec_flags & SEC_ALLOC) != 0 && (sec_flags & SEC_LOAD) == 0)
628
0
    styp_flags |= IMAGE_SCN_CNT_UNINITIALIZED_DATA;  /* ==STYP_BSS */
629
  /* skip ROM */
630
  /* skip constRUCTOR */
631
  /* skip CONTENTS */
632
7
#ifndef COFF_IMAGE_WITH_PE
633
  /* I don't think any of the IMAGE_SCN_LNK_* flags set below should be set
634
     when the output is PE. Only object files should have them, for the linker
635
     to consume.  */
636
7
  if ((sec_flags & SEC_IS_COMMON) != 0)
637
0
    styp_flags |= IMAGE_SCN_LNK_COMDAT;
638
7
#endif
639
7
  if ((sec_flags & SEC_DEBUGGING) != 0)
640
0
    styp_flags |= IMAGE_SCN_MEM_DISCARDABLE;
641
7
  if ((sec_flags & (SEC_EXCLUDE | SEC_NEVER_LOAD)) != 0 && !is_dbg)
642
#ifdef COFF_IMAGE_WITH_PE
643
    styp_flags |= IMAGE_SCN_MEM_DISCARDABLE;
644
#else
645
0
    styp_flags |= IMAGE_SCN_LNK_REMOVE;
646
7
#endif
647
  /* skip IN_MEMORY */
648
  /* skip SORT */
649
7
#ifndef COFF_IMAGE_WITH_PE
650
7
  if (sec_flags & SEC_LINK_ONCE)
651
0
    styp_flags |= IMAGE_SCN_LNK_COMDAT;
652
7
  if ((sec_flags
653
7
       & (SEC_LINK_DUPLICATES_DISCARD | SEC_LINK_DUPLICATES_SAME_CONTENTS
654
7
    | SEC_LINK_DUPLICATES_SAME_SIZE)) != 0)
655
0
    styp_flags |= IMAGE_SCN_LNK_COMDAT;
656
7
#endif
657
658
  /* skip LINKER_CREATED */
659
660
7
  if ((sec_flags & SEC_COFF_NOREAD) == 0)
661
0
    styp_flags |= IMAGE_SCN_MEM_READ;     /* Invert NOREAD for read.  */
662
7
  if ((sec_flags & SEC_READONLY) == 0)
663
0
    styp_flags |= IMAGE_SCN_MEM_WRITE;    /* Invert READONLY for write.  */
664
7
  if (sec_flags & SEC_CODE)
665
0
    styp_flags |= IMAGE_SCN_MEM_EXECUTE;  /* CODE->EXECUTE.  */
666
7
  if (sec_flags & SEC_COFF_SHARED)
667
0
    styp_flags |= IMAGE_SCN_MEM_SHARED;   /* Shared remains meaningful.  */
668
669
7
  return styp_flags;
670
7
}
Unexecuted instantiation: pe-sh.c:sec_to_styp_flags
pei-arm-wince.c:sec_to_styp_flags
Line
Count
Source
590
2
{
591
2
  long styp_flags = 0;
592
2
  bool is_dbg = false;
593
594
2
  if (startswith (sec_name, DOT_DEBUG)
595
2
      || startswith (sec_name, DOT_ZDEBUG)
596
2
#ifdef COFF_LONG_SECTION_NAMES
597
2
      || startswith (sec_name, GNU_LINKONCE_WI)
598
2
      || startswith (sec_name, GNU_LINKONCE_WT)
599
2
#endif
600
2
      || startswith (sec_name, ".stab"))
601
2
    is_dbg = true;
602
603
  /* caution: there are at least three groups of symbols that have
604
     very similar bits and meanings: IMAGE_SCN*, SEC_*, and STYP_*.
605
     SEC_* are the BFD internal flags, used for generic BFD
606
     information.  STYP_* are the COFF section flags which appear in
607
     COFF files.  IMAGE_SCN_* are the PE section flags which appear in
608
     PE files.  The STYP_* flags and the IMAGE_SCN_* flags overlap,
609
     but there are more IMAGE_SCN_* flags.  */
610
611
  /* FIXME: There is no gas syntax to specify the debug section flag.  */
612
2
  if (is_dbg)
613
2
    {
614
2
      sec_flags &= (SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD
615
2
        | SEC_LINK_DUPLICATES_SAME_CONTENTS
616
2
        | SEC_LINK_DUPLICATES_SAME_SIZE);
617
2
      sec_flags |= SEC_DEBUGGING | SEC_READONLY;
618
2
    }
619
620
  /* skip LOAD */
621
  /* READONLY later */
622
  /* skip RELOC */
623
2
  if ((sec_flags & SEC_CODE) != 0)
624
0
    styp_flags |= IMAGE_SCN_CNT_CODE;
625
2
  if ((sec_flags & (SEC_DATA | SEC_DEBUGGING)) != 0)
626
2
    styp_flags |= IMAGE_SCN_CNT_INITIALIZED_DATA;
627
2
  if ((sec_flags & SEC_ALLOC) != 0 && (sec_flags & SEC_LOAD) == 0)
628
0
    styp_flags |= IMAGE_SCN_CNT_UNINITIALIZED_DATA;  /* ==STYP_BSS */
629
  /* skip ROM */
630
  /* skip constRUCTOR */
631
  /* skip CONTENTS */
632
#ifndef COFF_IMAGE_WITH_PE
633
  /* I don't think any of the IMAGE_SCN_LNK_* flags set below should be set
634
     when the output is PE. Only object files should have them, for the linker
635
     to consume.  */
636
  if ((sec_flags & SEC_IS_COMMON) != 0)
637
    styp_flags |= IMAGE_SCN_LNK_COMDAT;
638
#endif
639
2
  if ((sec_flags & SEC_DEBUGGING) != 0)
640
2
    styp_flags |= IMAGE_SCN_MEM_DISCARDABLE;
641
2
  if ((sec_flags & (SEC_EXCLUDE | SEC_NEVER_LOAD)) != 0 && !is_dbg)
642
0
#ifdef COFF_IMAGE_WITH_PE
643
0
    styp_flags |= IMAGE_SCN_MEM_DISCARDABLE;
644
#else
645
    styp_flags |= IMAGE_SCN_LNK_REMOVE;
646
#endif
647
  /* skip IN_MEMORY */
648
  /* skip SORT */
649
#ifndef COFF_IMAGE_WITH_PE
650
  if (sec_flags & SEC_LINK_ONCE)
651
    styp_flags |= IMAGE_SCN_LNK_COMDAT;
652
  if ((sec_flags
653
       & (SEC_LINK_DUPLICATES_DISCARD | SEC_LINK_DUPLICATES_SAME_CONTENTS
654
    | SEC_LINK_DUPLICATES_SAME_SIZE)) != 0)
655
    styp_flags |= IMAGE_SCN_LNK_COMDAT;
656
#endif
657
658
  /* skip LINKER_CREATED */
659
660
2
  if ((sec_flags & SEC_COFF_NOREAD) == 0)
661
2
    styp_flags |= IMAGE_SCN_MEM_READ;     /* Invert NOREAD for read.  */
662
2
  if ((sec_flags & SEC_READONLY) == 0)
663
0
    styp_flags |= IMAGE_SCN_MEM_WRITE;    /* Invert READONLY for write.  */
664
2
  if (sec_flags & SEC_CODE)
665
0
    styp_flags |= IMAGE_SCN_MEM_EXECUTE;  /* CODE->EXECUTE.  */
666
2
  if (sec_flags & SEC_COFF_SHARED)
667
0
    styp_flags |= IMAGE_SCN_MEM_SHARED;   /* Shared remains meaningful.  */
668
669
2
  return styp_flags;
670
2
}
Unexecuted instantiation: pei-arm.c:sec_to_styp_flags
Unexecuted instantiation: pei-mcore.c:sec_to_styp_flags
Unexecuted instantiation: pei-sh.c:sec_to_styp_flags
671
672
#endif /* COFF_WITH_PE */
673
674
/* Return a word with SEC_* flags set to represent the incoming STYP_*
675
   flags (from scnhdr.s_flags).  The inverse of this function is
676
   sec_to_styp_flags().  NOTE: If you add to/change this routine, you
677
   should probably mirror the changes in sec_to_styp_flags().  */
678
679
#ifndef COFF_WITH_PE
680
681
static bool
682
styp_to_sec_flags (bfd *abfd,
683
       void * hdr,
684
       const char *name,
685
       asection *section ATTRIBUTE_UNUSED,
686
       flagword *flags_ptr)
687
1.11M
{
688
1.11M
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
689
1.11M
  unsigned long styp_flags = internal_s->s_flags;
690
1.11M
  flagword sec_flags = 0;
691
692
#ifdef STYP_BLOCK
693
22.8k
  if (styp_flags & STYP_BLOCK)
694
3.04k
    sec_flags |= SEC_TIC54X_BLOCK;
695
#endif
696
697
#ifdef STYP_CLINK
698
22.8k
  if (styp_flags & STYP_CLINK)
699
3.22k
    sec_flags |= SEC_TIC54X_CLINK;
700
#endif
701
702
1.11M
#ifdef STYP_NOLOAD
703
1.11M
  if (styp_flags & STYP_NOLOAD)
704
361k
    sec_flags |= SEC_NEVER_LOAD;
705
1.11M
#endif /* STYP_NOLOAD */
706
707
  /* For 386 COFF, at least, an unloadable text or data section is
708
     actually a shared library section.  */
709
1.11M
  if (styp_flags & STYP_TEXT)
710
309k
    {
711
309k
      if (sec_flags & SEC_NEVER_LOAD)
712
161k
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
713
148k
      else
714
148k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
715
309k
    }
716
804k
  else if (styp_flags & STYP_DATA)
717
154k
    {
718
154k
      if (sec_flags & SEC_NEVER_LOAD)
719
94.9k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
720
59.9k
      else
721
59.9k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
722
154k
    }
723
649k
  else if (styp_flags & STYP_BSS)
724
148k
    {
725
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
726
25.8k
      if (sec_flags & SEC_NEVER_LOAD)
727
4.90k
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
728
20.9k
      else
729
20.9k
#endif
730
143k
  sec_flags |= SEC_ALLOC;
731
148k
    }
732
501k
  else if (styp_flags & STYP_INFO)
733
74.8k
    {
734
      /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
735
   defined.  coff_compute_section_file_positions uses
736
   COFF_PAGE_SIZE to ensure that the low order bits of the
737
   section VMA and the file offset match.  If we don't know
738
   COFF_PAGE_SIZE, we can't ensure the correct correspondence,
739
   and demand page loading of the file will fail.  */
740
#if defined (COFF_PAGE_SIZE) && !defined (COFF_ALIGN_IN_S_FLAGS)
741
17.8k
      sec_flags |= SEC_DEBUGGING;
742
#endif
743
74.8k
    }
744
426k
  else if (styp_flags & STYP_PAD)
745
42.6k
    sec_flags = 0;
746
#ifdef RS6000COFF_C
747
143k
  else if (styp_flags & STYP_TDATA)
748
4.83k
    {
749
4.83k
      if (sec_flags & SEC_NEVER_LOAD)
750
1.47k
  sec_flags |= SEC_DATA | SEC_THREAD_LOCAL | SEC_COFF_SHARED_LIBRARY;
751
3.36k
      else
752
3.36k
  sec_flags |= SEC_DATA | SEC_THREAD_LOCAL | SEC_LOAD | SEC_ALLOC;
753
4.83k
    }
754
139k
  else if (styp_flags & STYP_TBSS)
755
2.66k
    {
756
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
757
      if (sec_flags & SEC_NEVER_LOAD)
758
  sec_flags |= SEC_ALLOC | SEC_THREAD_LOCAL | SEC_COFF_SHARED_LIBRARY;
759
      else
760
#endif
761
2.66k
  sec_flags |= SEC_ALLOC | SEC_THREAD_LOCAL;
762
2.66k
    }
763
136k
  else if (styp_flags & STYP_EXCEPT)
764
5.81k
    sec_flags |= SEC_LOAD;
765
130k
  else if (styp_flags & STYP_LOADER)
766
1.65k
    sec_flags |= SEC_LOAD;
767
129k
  else if (styp_flags & STYP_TYPCHK)
768
355
    sec_flags |= SEC_LOAD;
769
128k
  else if (styp_flags & STYP_DWARF)
770
696
    sec_flags |= SEC_DEBUGGING;
771
127k
#endif
772
367k
  else if (strcmp (name, _TEXT) == 0)
773
265
    {
774
265
      if (sec_flags & SEC_NEVER_LOAD)
775
11
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
776
254
      else
777
254
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
778
265
    }
779
367k
  else if (strcmp (name, _DATA) == 0)
780
1
    {
781
1
      if (sec_flags & SEC_NEVER_LOAD)
782
0
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
783
1
      else
784
1
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
785
1
    }
786
367k
  else if (strcmp (name, _BSS) == 0)
787
7
    {
788
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
789
3
      if (sec_flags & SEC_NEVER_LOAD)
790
0
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
791
3
      else
792
3
#endif
793
7
  sec_flags |= SEC_ALLOC;
794
7
    }
795
367k
  else if (startswith (name, DOT_DEBUG)
796
367k
     || startswith (name, DOT_ZDEBUG)
797
#ifdef _COMMENT
798
229k
     || strcmp (name, _COMMENT) == 0
799
#endif
800
#ifdef COFF_LONG_SECTION_NAMES
801
33.6k
     || startswith (name, GNU_LINKONCE_WI)
802
33.6k
     || startswith (name, GNU_LINKONCE_WT)
803
#endif
804
367k
     || startswith (name, ".stab"))
805
595
    {
806
#ifdef COFF_PAGE_SIZE
807
436
      sec_flags |= SEC_DEBUGGING;
808
#endif
809
595
    }
810
#ifdef _LIB
811
229k
  else if (strcmp (name, _LIB) == 0)
812
5
    ;
813
229k
#endif
814
#ifdef _LIT
815
  else if (strcmp (name, _LIT) == 0)
816
    sec_flags = SEC_LOAD | SEC_ALLOC | SEC_READONLY;
817
#endif
818
229k
  else
819
367k
    sec_flags |= SEC_ALLOC | SEC_LOAD;
820
821
1.11M
#ifdef STYP_LIT     /* A29k readonly text/data section type.  */
822
1.11M
  if ((styp_flags & STYP_LIT) == STYP_LIT)
823
131k
    sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
824
1.11M
#endif /* STYP_LIT */
825
826
#ifdef STYP_OTHER_LOAD    /* Other loaded sections.  */
827
  if (styp_flags & STYP_OTHER_LOAD)
828
    sec_flags = (SEC_LOAD | SEC_ALLOC);
829
#endif /* STYP_SDATA */
830
831
1.11M
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
832
1.11M
      && (startswith (name, ".sbss")
833
0
    || startswith (name, ".sdata")))
834
0
    sec_flags |= SEC_SMALL_DATA;
835
836
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
837
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
838
     only link a single copy of the section.  This is used to support
839
     g++.  g++ will emit each template expansion in its own section.
840
     The symbols will be defined as weak, so that multiple definitions
841
     are permitted.  The GNU linker extension is to actually discard
842
     all but one of the sections.  */
843
100k
  if (startswith (name, ".gnu.linkonce"))
844
0
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
845
#endif
846
847
1.11M
  if (flags_ptr == NULL)
848
0
    return false;
849
850
1.11M
  * flags_ptr = sec_flags;
851
1.11M
  return true;
852
1.11M
}
coff-x86_64.c:styp_to_sec_flags
Line
Count
Source
687
20.3k
{
688
20.3k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
689
20.3k
  unsigned long styp_flags = internal_s->s_flags;
690
20.3k
  flagword sec_flags = 0;
691
692
#ifdef STYP_BLOCK
693
  if (styp_flags & STYP_BLOCK)
694
    sec_flags |= SEC_TIC54X_BLOCK;
695
#endif
696
697
#ifdef STYP_CLINK
698
  if (styp_flags & STYP_CLINK)
699
    sec_flags |= SEC_TIC54X_CLINK;
700
#endif
701
702
20.3k
#ifdef STYP_NOLOAD
703
20.3k
  if (styp_flags & STYP_NOLOAD)
704
1.51k
    sec_flags |= SEC_NEVER_LOAD;
705
20.3k
#endif /* STYP_NOLOAD */
706
707
  /* For 386 COFF, at least, an unloadable text or data section is
708
     actually a shared library section.  */
709
20.3k
  if (styp_flags & STYP_TEXT)
710
1.49k
    {
711
1.49k
      if (sec_flags & SEC_NEVER_LOAD)
712
781
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
713
714
      else
714
714
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
715
1.49k
    }
716
18.8k
  else if (styp_flags & STYP_DATA)
717
509
    {
718
509
      if (sec_flags & SEC_NEVER_LOAD)
719
264
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
720
245
      else
721
245
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
722
509
    }
723
18.3k
  else if (styp_flags & STYP_BSS)
724
12.7k
    {
725
12.7k
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
726
12.7k
      if (sec_flags & SEC_NEVER_LOAD)
727
155
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
728
12.5k
      else
729
12.5k
#endif
730
12.5k
  sec_flags |= SEC_ALLOC;
731
12.7k
    }
732
5.64k
  else if (styp_flags & STYP_INFO)
733
400
    {
734
      /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
735
   defined.  coff_compute_section_file_positions uses
736
   COFF_PAGE_SIZE to ensure that the low order bits of the
737
   section VMA and the file offset match.  If we don't know
738
   COFF_PAGE_SIZE, we can't ensure the correct correspondence,
739
   and demand page loading of the file will fail.  */
740
400
#if defined (COFF_PAGE_SIZE) && !defined (COFF_ALIGN_IN_S_FLAGS)
741
400
      sec_flags |= SEC_DEBUGGING;
742
400
#endif
743
400
    }
744
5.24k
  else if (styp_flags & STYP_PAD)
745
149
    sec_flags = 0;
746
#ifdef RS6000COFF_C
747
  else if (styp_flags & STYP_TDATA)
748
    {
749
      if (sec_flags & SEC_NEVER_LOAD)
750
  sec_flags |= SEC_DATA | SEC_THREAD_LOCAL | SEC_COFF_SHARED_LIBRARY;
751
      else
752
  sec_flags |= SEC_DATA | SEC_THREAD_LOCAL | SEC_LOAD | SEC_ALLOC;
753
    }
754
  else if (styp_flags & STYP_TBSS)
755
    {
756
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
757
      if (sec_flags & SEC_NEVER_LOAD)
758
  sec_flags |= SEC_ALLOC | SEC_THREAD_LOCAL | SEC_COFF_SHARED_LIBRARY;
759
      else
760
#endif
761
  sec_flags |= SEC_ALLOC | SEC_THREAD_LOCAL;
762
    }
763
  else if (styp_flags & STYP_EXCEPT)
764
    sec_flags |= SEC_LOAD;
765
  else if (styp_flags & STYP_LOADER)
766
    sec_flags |= SEC_LOAD;
767
  else if (styp_flags & STYP_TYPCHK)
768
    sec_flags |= SEC_LOAD;
769
  else if (styp_flags & STYP_DWARF)
770
    sec_flags |= SEC_DEBUGGING;
771
#endif
772
5.09k
  else if (strcmp (name, _TEXT) == 0)
773
24
    {
774
24
      if (sec_flags & SEC_NEVER_LOAD)
775
3
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
776
21
      else
777
21
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
778
24
    }
779
5.06k
  else if (strcmp (name, _DATA) == 0)
780
0
    {
781
0
      if (sec_flags & SEC_NEVER_LOAD)
782
0
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
783
0
      else
784
0
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
785
0
    }
786
5.06k
  else if (strcmp (name, _BSS) == 0)
787
2
    {
788
2
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
789
2
      if (sec_flags & SEC_NEVER_LOAD)
790
0
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
791
2
      else
792
2
#endif
793
2
  sec_flags |= SEC_ALLOC;
794
2
    }
795
5.06k
  else if (startswith (name, DOT_DEBUG)
796
5.06k
     || startswith (name, DOT_ZDEBUG)
797
5.06k
#ifdef _COMMENT
798
5.06k
     || strcmp (name, _COMMENT) == 0
799
5.06k
#endif
800
#ifdef COFF_LONG_SECTION_NAMES
801
     || startswith (name, GNU_LINKONCE_WI)
802
     || startswith (name, GNU_LINKONCE_WT)
803
#endif
804
5.06k
     || startswith (name, ".stab"))
805
8
    {
806
8
#ifdef COFF_PAGE_SIZE
807
8
      sec_flags |= SEC_DEBUGGING;
808
8
#endif
809
8
    }
810
5.05k
#ifdef _LIB
811
5.05k
  else if (strcmp (name, _LIB) == 0)
812
0
    ;
813
5.05k
#endif
814
#ifdef _LIT
815
  else if (strcmp (name, _LIT) == 0)
816
    sec_flags = SEC_LOAD | SEC_ALLOC | SEC_READONLY;
817
#endif
818
5.05k
  else
819
5.05k
    sec_flags |= SEC_ALLOC | SEC_LOAD;
820
821
20.3k
#ifdef STYP_LIT     /* A29k readonly text/data section type.  */
822
20.3k
  if ((styp_flags & STYP_LIT) == STYP_LIT)
823
576
    sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
824
20.3k
#endif /* STYP_LIT */
825
826
#ifdef STYP_OTHER_LOAD    /* Other loaded sections.  */
827
  if (styp_flags & STYP_OTHER_LOAD)
828
    sec_flags = (SEC_LOAD | SEC_ALLOC);
829
#endif /* STYP_SDATA */
830
831
20.3k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
832
20.3k
      && (startswith (name, ".sbss")
833
0
    || startswith (name, ".sdata")))
834
0
    sec_flags |= SEC_SMALL_DATA;
835
836
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
837
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
838
     only link a single copy of the section.  This is used to support
839
     g++.  g++ will emit each template expansion in its own section.
840
     The symbols will be defined as weak, so that multiple definitions
841
     are permitted.  The GNU linker extension is to actually discard
842
     all but one of the sections.  */
843
  if (startswith (name, ".gnu.linkonce"))
844
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
845
#endif
846
847
20.3k
  if (flags_ptr == NULL)
848
0
    return false;
849
850
20.3k
  * flags_ptr = sec_flags;
851
20.3k
  return true;
852
20.3k
}
coff64-rs6000.c:styp_to_sec_flags
Line
Count
Source
687
180k
{
688
180k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
689
180k
  unsigned long styp_flags = internal_s->s_flags;
690
180k
  flagword sec_flags = 0;
691
692
#ifdef STYP_BLOCK
693
  if (styp_flags & STYP_BLOCK)
694
    sec_flags |= SEC_TIC54X_BLOCK;
695
#endif
696
697
#ifdef STYP_CLINK
698
  if (styp_flags & STYP_CLINK)
699
    sec_flags |= SEC_TIC54X_CLINK;
700
#endif
701
702
180k
#ifdef STYP_NOLOAD
703
180k
  if (styp_flags & STYP_NOLOAD)
704
39.9k
    sec_flags |= SEC_NEVER_LOAD;
705
180k
#endif /* STYP_NOLOAD */
706
707
  /* For 386 COFF, at least, an unloadable text or data section is
708
     actually a shared library section.  */
709
180k
  if (styp_flags & STYP_TEXT)
710
37.2k
    {
711
37.2k
      if (sec_flags & SEC_NEVER_LOAD)
712
20.4k
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
713
16.8k
      else
714
16.8k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
715
37.2k
    }
716
142k
  else if (styp_flags & STYP_DATA)
717
11.9k
    {
718
11.9k
      if (sec_flags & SEC_NEVER_LOAD)
719
7.49k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
720
4.49k
      else
721
4.49k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
722
11.9k
    }
723
130k
  else if (styp_flags & STYP_BSS)
724
4.07k
    {
725
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
726
      if (sec_flags & SEC_NEVER_LOAD)
727
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
728
      else
729
#endif
730
4.07k
  sec_flags |= SEC_ALLOC;
731
4.07k
    }
732
126k
  else if (styp_flags & STYP_INFO)
733
9.58k
    {
734
      /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
735
   defined.  coff_compute_section_file_positions uses
736
   COFF_PAGE_SIZE to ensure that the low order bits of the
737
   section VMA and the file offset match.  If we don't know
738
   COFF_PAGE_SIZE, we can't ensure the correct correspondence,
739
   and demand page loading of the file will fail.  */
740
#if defined (COFF_PAGE_SIZE) && !defined (COFF_ALIGN_IN_S_FLAGS)
741
      sec_flags |= SEC_DEBUGGING;
742
#endif
743
9.58k
    }
744
117k
  else if (styp_flags & STYP_PAD)
745
6.76k
    sec_flags = 0;
746
110k
#ifdef RS6000COFF_C
747
110k
  else if (styp_flags & STYP_TDATA)
748
1.94k
    {
749
1.94k
      if (sec_flags & SEC_NEVER_LOAD)
750
552
  sec_flags |= SEC_DATA | SEC_THREAD_LOCAL | SEC_COFF_SHARED_LIBRARY;
751
1.39k
      else
752
1.39k
  sec_flags |= SEC_DATA | SEC_THREAD_LOCAL | SEC_LOAD | SEC_ALLOC;
753
1.94k
    }
754
108k
  else if (styp_flags & STYP_TBSS)
755
1.23k
    {
756
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
757
      if (sec_flags & SEC_NEVER_LOAD)
758
  sec_flags |= SEC_ALLOC | SEC_THREAD_LOCAL | SEC_COFF_SHARED_LIBRARY;
759
      else
760
#endif
761
1.23k
  sec_flags |= SEC_ALLOC | SEC_THREAD_LOCAL;
762
1.23k
    }
763
107k
  else if (styp_flags & STYP_EXCEPT)
764
2.00k
    sec_flags |= SEC_LOAD;
765
105k
  else if (styp_flags & STYP_LOADER)
766
1.00k
    sec_flags |= SEC_LOAD;
767
104k
  else if (styp_flags & STYP_TYPCHK)
768
61
    sec_flags |= SEC_LOAD;
769
104k
  else if (styp_flags & STYP_DWARF)
770
303
    sec_flags |= SEC_DEBUGGING;
771
103k
#endif
772
103k
  else if (strcmp (name, _TEXT) == 0)
773
0
    {
774
0
      if (sec_flags & SEC_NEVER_LOAD)
775
0
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
776
0
      else
777
0
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
778
0
    }
779
103k
  else if (strcmp (name, _DATA) == 0)
780
0
    {
781
0
      if (sec_flags & SEC_NEVER_LOAD)
782
0
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
783
0
      else
784
0
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
785
0
    }
786
103k
  else if (strcmp (name, _BSS) == 0)
787
0
    {
788
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
789
      if (sec_flags & SEC_NEVER_LOAD)
790
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
791
      else
792
#endif
793
0
  sec_flags |= SEC_ALLOC;
794
0
    }
795
103k
  else if (startswith (name, DOT_DEBUG)
796
103k
     || startswith (name, DOT_ZDEBUG)
797
#ifdef _COMMENT
798
     || strcmp (name, _COMMENT) == 0
799
#endif
800
#ifdef COFF_LONG_SECTION_NAMES
801
     || startswith (name, GNU_LINKONCE_WI)
802
     || startswith (name, GNU_LINKONCE_WT)
803
#endif
804
103k
     || startswith (name, ".stab"))
805
1
    {
806
#ifdef COFF_PAGE_SIZE
807
      sec_flags |= SEC_DEBUGGING;
808
#endif
809
1
    }
810
#ifdef _LIB
811
  else if (strcmp (name, _LIB) == 0)
812
    ;
813
#endif
814
#ifdef _LIT
815
  else if (strcmp (name, _LIT) == 0)
816
    sec_flags = SEC_LOAD | SEC_ALLOC | SEC_READONLY;
817
#endif
818
103k
  else
819
103k
    sec_flags |= SEC_ALLOC | SEC_LOAD;
820
821
180k
#ifdef STYP_LIT     /* A29k readonly text/data section type.  */
822
180k
  if ((styp_flags & STYP_LIT) == STYP_LIT)
823
9.21k
    sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
824
180k
#endif /* STYP_LIT */
825
826
#ifdef STYP_OTHER_LOAD    /* Other loaded sections.  */
827
  if (styp_flags & STYP_OTHER_LOAD)
828
    sec_flags = (SEC_LOAD | SEC_ALLOC);
829
#endif /* STYP_SDATA */
830
831
180k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
832
180k
      && (startswith (name, ".sbss")
833
0
    || startswith (name, ".sdata")))
834
0
    sec_flags |= SEC_SMALL_DATA;
835
836
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
837
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
838
     only link a single copy of the section.  This is used to support
839
     g++.  g++ will emit each template expansion in its own section.
840
     The symbols will be defined as weak, so that multiple definitions
841
     are permitted.  The GNU linker extension is to actually discard
842
     all but one of the sections.  */
843
  if (startswith (name, ".gnu.linkonce"))
844
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
845
#endif
846
847
180k
  if (flags_ptr == NULL)
848
0
    return false;
849
850
180k
  * flags_ptr = sec_flags;
851
180k
  return true;
852
180k
}
cf-i386lynx.c:styp_to_sec_flags
Line
Count
Source
687
82.1k
{
688
82.1k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
689
82.1k
  unsigned long styp_flags = internal_s->s_flags;
690
82.1k
  flagword sec_flags = 0;
691
692
#ifdef STYP_BLOCK
693
  if (styp_flags & STYP_BLOCK)
694
    sec_flags |= SEC_TIC54X_BLOCK;
695
#endif
696
697
#ifdef STYP_CLINK
698
  if (styp_flags & STYP_CLINK)
699
    sec_flags |= SEC_TIC54X_CLINK;
700
#endif
701
702
82.1k
#ifdef STYP_NOLOAD
703
82.1k
  if (styp_flags & STYP_NOLOAD)
704
27.8k
    sec_flags |= SEC_NEVER_LOAD;
705
82.1k
#endif /* STYP_NOLOAD */
706
707
  /* For 386 COFF, at least, an unloadable text or data section is
708
     actually a shared library section.  */
709
82.1k
  if (styp_flags & STYP_TEXT)
710
28.7k
    {
711
28.7k
      if (sec_flags & SEC_NEVER_LOAD)
712
13.9k
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
713
14.8k
      else
714
14.8k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
715
28.7k
    }
716
53.3k
  else if (styp_flags & STYP_DATA)
717
10.8k
    {
718
10.8k
      if (sec_flags & SEC_NEVER_LOAD)
719
5.67k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
720
5.14k
      else
721
5.14k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
722
10.8k
    }
723
42.5k
  else if (styp_flags & STYP_BSS)
724
6.03k
    {
725
6.03k
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
726
6.03k
      if (sec_flags & SEC_NEVER_LOAD)
727
2.17k
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
728
3.85k
      else
729
3.85k
#endif
730
3.85k
  sec_flags |= SEC_ALLOC;
731
6.03k
    }
732
36.5k
  else if (styp_flags & STYP_INFO)
733
7.33k
    {
734
      /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
735
   defined.  coff_compute_section_file_positions uses
736
   COFF_PAGE_SIZE to ensure that the low order bits of the
737
   section VMA and the file offset match.  If we don't know
738
   COFF_PAGE_SIZE, we can't ensure the correct correspondence,
739
   and demand page loading of the file will fail.  */
740
7.33k
#if defined (COFF_PAGE_SIZE) && !defined (COFF_ALIGN_IN_S_FLAGS)
741
7.33k
      sec_flags |= SEC_DEBUGGING;
742
7.33k
#endif
743
7.33k
    }
744
29.1k
  else if (styp_flags & STYP_PAD)
745
2.21k
    sec_flags = 0;
746
#ifdef RS6000COFF_C
747
  else if (styp_flags & STYP_TDATA)
748
    {
749
      if (sec_flags & SEC_NEVER_LOAD)
750
  sec_flags |= SEC_DATA | SEC_THREAD_LOCAL | SEC_COFF_SHARED_LIBRARY;
751
      else
752
  sec_flags |= SEC_DATA | SEC_THREAD_LOCAL | SEC_LOAD | SEC_ALLOC;
753
    }
754
  else if (styp_flags & STYP_TBSS)
755
    {
756
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
757
      if (sec_flags & SEC_NEVER_LOAD)
758
  sec_flags |= SEC_ALLOC | SEC_THREAD_LOCAL | SEC_COFF_SHARED_LIBRARY;
759
      else
760
#endif
761
  sec_flags |= SEC_ALLOC | SEC_THREAD_LOCAL;
762
    }
763
  else if (styp_flags & STYP_EXCEPT)
764
    sec_flags |= SEC_LOAD;
765
  else if (styp_flags & STYP_LOADER)
766
    sec_flags |= SEC_LOAD;
767
  else if (styp_flags & STYP_TYPCHK)
768
    sec_flags |= SEC_LOAD;
769
  else if (styp_flags & STYP_DWARF)
770
    sec_flags |= SEC_DEBUGGING;
771
#endif
772
26.9k
  else if (strcmp (name, _TEXT) == 0)
773
58
    {
774
58
      if (sec_flags & SEC_NEVER_LOAD)
775
2
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
776
56
      else
777
56
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
778
58
    }
779
26.9k
  else if (strcmp (name, _DATA) == 0)
780
0
    {
781
0
      if (sec_flags & SEC_NEVER_LOAD)
782
0
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
783
0
      else
784
0
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
785
0
    }
786
26.9k
  else if (strcmp (name, _BSS) == 0)
787
0
    {
788
0
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
789
0
      if (sec_flags & SEC_NEVER_LOAD)
790
0
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
791
0
      else
792
0
#endif
793
0
  sec_flags |= SEC_ALLOC;
794
0
    }
795
26.9k
  else if (startswith (name, DOT_DEBUG)
796
26.9k
     || startswith (name, DOT_ZDEBUG)
797
26.9k
#ifdef _COMMENT
798
26.9k
     || strcmp (name, _COMMENT) == 0
799
26.9k
#endif
800
#ifdef COFF_LONG_SECTION_NAMES
801
     || startswith (name, GNU_LINKONCE_WI)
802
     || startswith (name, GNU_LINKONCE_WT)
803
#endif
804
26.9k
     || startswith (name, ".stab"))
805
177
    {
806
177
#ifdef COFF_PAGE_SIZE
807
177
      sec_flags |= SEC_DEBUGGING;
808
177
#endif
809
177
    }
810
26.7k
#ifdef _LIB
811
26.7k
  else if (strcmp (name, _LIB) == 0)
812
2
    ;
813
26.7k
#endif
814
#ifdef _LIT
815
  else if (strcmp (name, _LIT) == 0)
816
    sec_flags = SEC_LOAD | SEC_ALLOC | SEC_READONLY;
817
#endif
818
26.7k
  else
819
26.7k
    sec_flags |= SEC_ALLOC | SEC_LOAD;
820
821
82.1k
#ifdef STYP_LIT     /* A29k readonly text/data section type.  */
822
82.1k
  if ((styp_flags & STYP_LIT) == STYP_LIT)
823
12.9k
    sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
824
82.1k
#endif /* STYP_LIT */
825
826
#ifdef STYP_OTHER_LOAD    /* Other loaded sections.  */
827
  if (styp_flags & STYP_OTHER_LOAD)
828
    sec_flags = (SEC_LOAD | SEC_ALLOC);
829
#endif /* STYP_SDATA */
830
831
82.1k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
832
82.1k
      && (startswith (name, ".sbss")
833
0
    || startswith (name, ".sdata")))
834
0
    sec_flags |= SEC_SMALL_DATA;
835
836
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
837
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
838
     only link a single copy of the section.  This is used to support
839
     g++.  g++ will emit each template expansion in its own section.
840
     The symbols will be defined as weak, so that multiple definitions
841
     are permitted.  The GNU linker extension is to actually discard
842
     all but one of the sections.  */
843
  if (startswith (name, ".gnu.linkonce"))
844
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
845
#endif
846
847
82.1k
  if (flags_ptr == NULL)
848
0
    return false;
849
850
82.1k
  * flags_ptr = sec_flags;
851
82.1k
  return true;
852
82.1k
}
coff-go32.c:styp_to_sec_flags
Line
Count
Source
687
7.68k
{
688
7.68k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
689
7.68k
  unsigned long styp_flags = internal_s->s_flags;
690
7.68k
  flagword sec_flags = 0;
691
692
#ifdef STYP_BLOCK
693
  if (styp_flags & STYP_BLOCK)
694
    sec_flags |= SEC_TIC54X_BLOCK;
695
#endif
696
697
#ifdef STYP_CLINK
698
  if (styp_flags & STYP_CLINK)
699
    sec_flags |= SEC_TIC54X_CLINK;
700
#endif
701
702
7.68k
#ifdef STYP_NOLOAD
703
7.68k
  if (styp_flags & STYP_NOLOAD)
704
2.03k
    sec_flags |= SEC_NEVER_LOAD;
705
7.68k
#endif /* STYP_NOLOAD */
706
707
  /* For 386 COFF, at least, an unloadable text or data section is
708
     actually a shared library section.  */
709
7.68k
  if (styp_flags & STYP_TEXT)
710
1.63k
    {
711
1.63k
      if (sec_flags & SEC_NEVER_LOAD)
712
884
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
713
752
      else
714
752
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
715
1.63k
    }
716
6.04k
  else if (styp_flags & STYP_DATA)
717
574
    {
718
574
      if (sec_flags & SEC_NEVER_LOAD)
719
274
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
720
300
      else
721
300
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
722
574
    }
723
5.47k
  else if (styp_flags & STYP_BSS)
724
345
    {
725
345
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
726
345
      if (sec_flags & SEC_NEVER_LOAD)
727
137
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
728
208
      else
729
208
#endif
730
208
  sec_flags |= SEC_ALLOC;
731
345
    }
732
5.12k
  else if (styp_flags & STYP_INFO)
733
826
    {
734
      /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
735
   defined.  coff_compute_section_file_positions uses
736
   COFF_PAGE_SIZE to ensure that the low order bits of the
737
   section VMA and the file offset match.  If we don't know
738
   COFF_PAGE_SIZE, we can't ensure the correct correspondence,
739
   and demand page loading of the file will fail.  */
740
826
#if defined (COFF_PAGE_SIZE) && !defined (COFF_ALIGN_IN_S_FLAGS)
741
826
      sec_flags |= SEC_DEBUGGING;
742
826
#endif
743
826
    }
744
4.30k
  else if (styp_flags & STYP_PAD)
745
654
    sec_flags = 0;
746
#ifdef RS6000COFF_C
747
  else if (styp_flags & STYP_TDATA)
748
    {
749
      if (sec_flags & SEC_NEVER_LOAD)
750
  sec_flags |= SEC_DATA | SEC_THREAD_LOCAL | SEC_COFF_SHARED_LIBRARY;
751
      else
752
  sec_flags |= SEC_DATA | SEC_THREAD_LOCAL | SEC_LOAD | SEC_ALLOC;
753
    }
754
  else if (styp_flags & STYP_TBSS)
755
    {
756
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
757
      if (sec_flags & SEC_NEVER_LOAD)
758
  sec_flags |= SEC_ALLOC | SEC_THREAD_LOCAL | SEC_COFF_SHARED_LIBRARY;
759
      else
760
#endif
761
  sec_flags |= SEC_ALLOC | SEC_THREAD_LOCAL;
762
    }
763
  else if (styp_flags & STYP_EXCEPT)
764
    sec_flags |= SEC_LOAD;
765
  else if (styp_flags & STYP_LOADER)
766
    sec_flags |= SEC_LOAD;
767
  else if (styp_flags & STYP_TYPCHK)
768
    sec_flags |= SEC_LOAD;
769
  else if (styp_flags & STYP_DWARF)
770
    sec_flags |= SEC_DEBUGGING;
771
#endif
772
3.64k
  else if (strcmp (name, _TEXT) == 0)
773
12
    {
774
12
      if (sec_flags & SEC_NEVER_LOAD)
775
0
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
776
12
      else
777
12
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
778
12
    }
779
3.63k
  else if (strcmp (name, _DATA) == 0)
780
0
    {
781
0
      if (sec_flags & SEC_NEVER_LOAD)
782
0
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
783
0
      else
784
0
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
785
0
    }
786
3.63k
  else if (strcmp (name, _BSS) == 0)
787
0
    {
788
0
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
789
0
      if (sec_flags & SEC_NEVER_LOAD)
790
0
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
791
0
      else
792
0
#endif
793
0
  sec_flags |= SEC_ALLOC;
794
0
    }
795
3.63k
  else if (startswith (name, DOT_DEBUG)
796
3.63k
     || startswith (name, DOT_ZDEBUG)
797
3.63k
#ifdef _COMMENT
798
3.63k
     || strcmp (name, _COMMENT) == 0
799
3.63k
#endif
800
3.63k
#ifdef COFF_LONG_SECTION_NAMES
801
3.63k
     || startswith (name, GNU_LINKONCE_WI)
802
3.63k
     || startswith (name, GNU_LINKONCE_WT)
803
3.63k
#endif
804
3.63k
     || startswith (name, ".stab"))
805
10
    {
806
10
#ifdef COFF_PAGE_SIZE
807
10
      sec_flags |= SEC_DEBUGGING;
808
10
#endif
809
10
    }
810
3.62k
#ifdef _LIB
811
3.62k
  else if (strcmp (name, _LIB) == 0)
812
0
    ;
813
3.62k
#endif
814
#ifdef _LIT
815
  else if (strcmp (name, _LIT) == 0)
816
    sec_flags = SEC_LOAD | SEC_ALLOC | SEC_READONLY;
817
#endif
818
3.62k
  else
819
3.62k
    sec_flags |= SEC_ALLOC | SEC_LOAD;
820
821
7.68k
#ifdef STYP_LIT     /* A29k readonly text/data section type.  */
822
7.68k
  if ((styp_flags & STYP_LIT) == STYP_LIT)
823
636
    sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
824
7.68k
#endif /* STYP_LIT */
825
826
#ifdef STYP_OTHER_LOAD    /* Other loaded sections.  */
827
  if (styp_flags & STYP_OTHER_LOAD)
828
    sec_flags = (SEC_LOAD | SEC_ALLOC);
829
#endif /* STYP_SDATA */
830
831
7.68k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
832
7.68k
      && (startswith (name, ".sbss")
833
0
    || startswith (name, ".sdata")))
834
0
    sec_flags |= SEC_SMALL_DATA;
835
836
7.68k
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
837
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
838
     only link a single copy of the section.  This is used to support
839
     g++.  g++ will emit each template expansion in its own section.
840
     The symbols will be defined as weak, so that multiple definitions
841
     are permitted.  The GNU linker extension is to actually discard
842
     all but one of the sections.  */
843
7.68k
  if (startswith (name, ".gnu.linkonce"))
844
0
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
845
7.68k
#endif
846
847
7.68k
  if (flags_ptr == NULL)
848
0
    return false;
849
850
7.68k
  * flags_ptr = sec_flags;
851
7.68k
  return true;
852
7.68k
}
coff-i386.c:styp_to_sec_flags
Line
Count
Source
687
7.92k
{
688
7.92k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
689
7.92k
  unsigned long styp_flags = internal_s->s_flags;
690
7.92k
  flagword sec_flags = 0;
691
692
#ifdef STYP_BLOCK
693
  if (styp_flags & STYP_BLOCK)
694
    sec_flags |= SEC_TIC54X_BLOCK;
695
#endif
696
697
#ifdef STYP_CLINK
698
  if (styp_flags & STYP_CLINK)
699
    sec_flags |= SEC_TIC54X_CLINK;
700
#endif
701
702
7.92k
#ifdef STYP_NOLOAD
703
7.92k
  if (styp_flags & STYP_NOLOAD)
704
2.11k
    sec_flags |= SEC_NEVER_LOAD;
705
7.92k
#endif /* STYP_NOLOAD */
706
707
  /* For 386 COFF, at least, an unloadable text or data section is
708
     actually a shared library section.  */
709
7.92k
  if (styp_flags & STYP_TEXT)
710
1.72k
    {
711
1.72k
      if (sec_flags & SEC_NEVER_LOAD)
712
945
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
713
782
      else
714
782
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
715
1.72k
    }
716
6.19k
  else if (styp_flags & STYP_DATA)
717
587
    {
718
587
      if (sec_flags & SEC_NEVER_LOAD)
719
283
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
720
304
      else
721
304
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
722
587
    }
723
5.60k
  else if (styp_flags & STYP_BSS)
724
350
    {
725
350
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
726
350
      if (sec_flags & SEC_NEVER_LOAD)
727
139
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
728
211
      else
729
211
#endif
730
211
  sec_flags |= SEC_ALLOC;
731
350
    }
732
5.25k
  else if (styp_flags & STYP_INFO)
733
839
    {
734
      /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
735
   defined.  coff_compute_section_file_positions uses
736
   COFF_PAGE_SIZE to ensure that the low order bits of the
737
   section VMA and the file offset match.  If we don't know
738
   COFF_PAGE_SIZE, we can't ensure the correct correspondence,
739
   and demand page loading of the file will fail.  */
740
839
#if defined (COFF_PAGE_SIZE) && !defined (COFF_ALIGN_IN_S_FLAGS)
741
839
      sec_flags |= SEC_DEBUGGING;
742
839
#endif
743
839
    }
744
4.41k
  else if (styp_flags & STYP_PAD)
745
658
    sec_flags = 0;
746
#ifdef RS6000COFF_C
747
  else if (styp_flags & STYP_TDATA)
748
    {
749
      if (sec_flags & SEC_NEVER_LOAD)
750
  sec_flags |= SEC_DATA | SEC_THREAD_LOCAL | SEC_COFF_SHARED_LIBRARY;
751
      else
752
  sec_flags |= SEC_DATA | SEC_THREAD_LOCAL | SEC_LOAD | SEC_ALLOC;
753
    }
754
  else if (styp_flags & STYP_TBSS)
755
    {
756
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
757
      if (sec_flags & SEC_NEVER_LOAD)
758
  sec_flags |= SEC_ALLOC | SEC_THREAD_LOCAL | SEC_COFF_SHARED_LIBRARY;
759
      else
760
#endif
761
  sec_flags |= SEC_ALLOC | SEC_THREAD_LOCAL;
762
    }
763
  else if (styp_flags & STYP_EXCEPT)
764
    sec_flags |= SEC_LOAD;
765
  else if (styp_flags & STYP_LOADER)
766
    sec_flags |= SEC_LOAD;
767
  else if (styp_flags & STYP_TYPCHK)
768
    sec_flags |= SEC_LOAD;
769
  else if (styp_flags & STYP_DWARF)
770
    sec_flags |= SEC_DEBUGGING;
771
#endif
772
3.76k
  else if (strcmp (name, _TEXT) == 0)
773
12
    {
774
12
      if (sec_flags & SEC_NEVER_LOAD)
775
0
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
776
12
      else
777
12
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
778
12
    }
779
3.74k
  else if (strcmp (name, _DATA) == 0)
780
0
    {
781
0
      if (sec_flags & SEC_NEVER_LOAD)
782
0
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
783
0
      else
784
0
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
785
0
    }
786
3.74k
  else if (strcmp (name, _BSS) == 0)
787
0
    {
788
0
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
789
0
      if (sec_flags & SEC_NEVER_LOAD)
790
0
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
791
0
      else
792
0
#endif
793
0
  sec_flags |= SEC_ALLOC;
794
0
    }
795
3.74k
  else if (startswith (name, DOT_DEBUG)
796
3.74k
     || startswith (name, DOT_ZDEBUG)
797
3.74k
#ifdef _COMMENT
798
3.74k
     || strcmp (name, _COMMENT) == 0
799
3.74k
#endif
800
#ifdef COFF_LONG_SECTION_NAMES
801
     || startswith (name, GNU_LINKONCE_WI)
802
     || startswith (name, GNU_LINKONCE_WT)
803
#endif
804
3.74k
     || startswith (name, ".stab"))
805
11
    {
806
11
#ifdef COFF_PAGE_SIZE
807
11
      sec_flags |= SEC_DEBUGGING;
808
11
#endif
809
11
    }
810
3.73k
#ifdef _LIB
811
3.73k
  else if (strcmp (name, _LIB) == 0)
812
0
    ;
813
3.73k
#endif
814
#ifdef _LIT
815
  else if (strcmp (name, _LIT) == 0)
816
    sec_flags = SEC_LOAD | SEC_ALLOC | SEC_READONLY;
817
#endif
818
3.73k
  else
819
3.73k
    sec_flags |= SEC_ALLOC | SEC_LOAD;
820
821
7.92k
#ifdef STYP_LIT     /* A29k readonly text/data section type.  */
822
7.92k
  if ((styp_flags & STYP_LIT) == STYP_LIT)
823
687
    sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
824
7.92k
#endif /* STYP_LIT */
825
826
#ifdef STYP_OTHER_LOAD    /* Other loaded sections.  */
827
  if (styp_flags & STYP_OTHER_LOAD)
828
    sec_flags = (SEC_LOAD | SEC_ALLOC);
829
#endif /* STYP_SDATA */
830
831
7.92k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
832
7.92k
      && (startswith (name, ".sbss")
833
0
    || startswith (name, ".sdata")))
834
0
    sec_flags |= SEC_SMALL_DATA;
835
836
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
837
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
838
     only link a single copy of the section.  This is used to support
839
     g++.  g++ will emit each template expansion in its own section.
840
     The symbols will be defined as weak, so that multiple definitions
841
     are permitted.  The GNU linker extension is to actually discard
842
     all but one of the sections.  */
843
  if (startswith (name, ".gnu.linkonce"))
844
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
845
#endif
846
847
7.92k
  if (flags_ptr == NULL)
848
0
    return false;
849
850
7.92k
  * flags_ptr = sec_flags;
851
7.92k
  return true;
852
7.92k
}
coff-rs6000.c:styp_to_sec_flags
Line
Count
Source
687
220k
{
688
220k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
689
220k
  unsigned long styp_flags = internal_s->s_flags;
690
220k
  flagword sec_flags = 0;
691
692
#ifdef STYP_BLOCK
693
  if (styp_flags & STYP_BLOCK)
694
    sec_flags |= SEC_TIC54X_BLOCK;
695
#endif
696
697
#ifdef STYP_CLINK
698
  if (styp_flags & STYP_CLINK)
699
    sec_flags |= SEC_TIC54X_CLINK;
700
#endif
701
702
220k
#ifdef STYP_NOLOAD
703
220k
  if (styp_flags & STYP_NOLOAD)
704
70.7k
    sec_flags |= SEC_NEVER_LOAD;
705
220k
#endif /* STYP_NOLOAD */
706
707
  /* For 386 COFF, at least, an unloadable text or data section is
708
     actually a shared library section.  */
709
220k
  if (styp_flags & STYP_TEXT)
710
62.5k
    {
711
62.5k
      if (sec_flags & SEC_NEVER_LOAD)
712
32.5k
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
713
29.9k
      else
714
29.9k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
715
62.5k
    }
716
158k
  else if (styp_flags & STYP_DATA)
717
29.0k
    {
718
29.0k
      if (sec_flags & SEC_NEVER_LOAD)
719
14.9k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
720
14.1k
      else
721
14.1k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
722
29.0k
    }
723
129k
  else if (styp_flags & STYP_BSS)
724
70.1k
    {
725
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
726
      if (sec_flags & SEC_NEVER_LOAD)
727
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
728
      else
729
#endif
730
70.1k
  sec_flags |= SEC_ALLOC;
731
70.1k
    }
732
58.8k
  else if (styp_flags & STYP_INFO)
733
11.0k
    {
734
      /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
735
   defined.  coff_compute_section_file_positions uses
736
   COFF_PAGE_SIZE to ensure that the low order bits of the
737
   section VMA and the file offset match.  If we don't know
738
   COFF_PAGE_SIZE, we can't ensure the correct correspondence,
739
   and demand page loading of the file will fail.  */
740
#if defined (COFF_PAGE_SIZE) && !defined (COFF_ALIGN_IN_S_FLAGS)
741
      sec_flags |= SEC_DEBUGGING;
742
#endif
743
11.0k
    }
744
47.7k
  else if (styp_flags & STYP_PAD)
745
14.2k
    sec_flags = 0;
746
33.4k
#ifdef RS6000COFF_C
747
33.4k
  else if (styp_flags & STYP_TDATA)
748
2.89k
    {
749
2.89k
      if (sec_flags & SEC_NEVER_LOAD)
750
924
  sec_flags |= SEC_DATA | SEC_THREAD_LOCAL | SEC_COFF_SHARED_LIBRARY;
751
1.96k
      else
752
1.96k
  sec_flags |= SEC_DATA | SEC_THREAD_LOCAL | SEC_LOAD | SEC_ALLOC;
753
2.89k
    }
754
30.5k
  else if (styp_flags & STYP_TBSS)
755
1.42k
    {
756
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
757
      if (sec_flags & SEC_NEVER_LOAD)
758
  sec_flags |= SEC_ALLOC | SEC_THREAD_LOCAL | SEC_COFF_SHARED_LIBRARY;
759
      else
760
#endif
761
1.42k
  sec_flags |= SEC_ALLOC | SEC_THREAD_LOCAL;
762
1.42k
    }
763
29.1k
  else if (styp_flags & STYP_EXCEPT)
764
3.80k
    sec_flags |= SEC_LOAD;
765
25.3k
  else if (styp_flags & STYP_LOADER)
766
650
    sec_flags |= SEC_LOAD;
767
24.6k
  else if (styp_flags & STYP_TYPCHK)
768
294
    sec_flags |= SEC_LOAD;
769
24.4k
  else if (styp_flags & STYP_DWARF)
770
393
    sec_flags |= SEC_DEBUGGING;
771
24.0k
#endif
772
24.0k
  else if (strcmp (name, _TEXT) == 0)
773
3
    {
774
3
      if (sec_flags & SEC_NEVER_LOAD)
775
0
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
776
3
      else
777
3
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
778
3
    }
779
24.0k
  else if (strcmp (name, _DATA) == 0)
780
0
    {
781
0
      if (sec_flags & SEC_NEVER_LOAD)
782
0
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
783
0
      else
784
0
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
785
0
    }
786
24.0k
  else if (strcmp (name, _BSS) == 0)
787
0
    {
788
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
789
      if (sec_flags & SEC_NEVER_LOAD)
790
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
791
      else
792
#endif
793
0
  sec_flags |= SEC_ALLOC;
794
0
    }
795
24.0k
  else if (startswith (name, DOT_DEBUG)
796
24.0k
     || startswith (name, DOT_ZDEBUG)
797
#ifdef _COMMENT
798
     || strcmp (name, _COMMENT) == 0
799
#endif
800
#ifdef COFF_LONG_SECTION_NAMES
801
     || startswith (name, GNU_LINKONCE_WI)
802
     || startswith (name, GNU_LINKONCE_WT)
803
#endif
804
24.0k
     || startswith (name, ".stab"))
805
2
    {
806
#ifdef COFF_PAGE_SIZE
807
      sec_flags |= SEC_DEBUGGING;
808
#endif
809
2
    }
810
#ifdef _LIB
811
  else if (strcmp (name, _LIB) == 0)
812
    ;
813
#endif
814
#ifdef _LIT
815
  else if (strcmp (name, _LIT) == 0)
816
    sec_flags = SEC_LOAD | SEC_ALLOC | SEC_READONLY;
817
#endif
818
24.0k
  else
819
24.0k
    sec_flags |= SEC_ALLOC | SEC_LOAD;
820
821
220k
#ifdef STYP_LIT     /* A29k readonly text/data section type.  */
822
220k
  if ((styp_flags & STYP_LIT) == STYP_LIT)
823
28.9k
    sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
824
220k
#endif /* STYP_LIT */
825
826
#ifdef STYP_OTHER_LOAD    /* Other loaded sections.  */
827
  if (styp_flags & STYP_OTHER_LOAD)
828
    sec_flags = (SEC_LOAD | SEC_ALLOC);
829
#endif /* STYP_SDATA */
830
831
220k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
832
220k
      && (startswith (name, ".sbss")
833
0
    || startswith (name, ".sdata")))
834
0
    sec_flags |= SEC_SMALL_DATA;
835
836
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
837
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
838
     only link a single copy of the section.  This is used to support
839
     g++.  g++ will emit each template expansion in its own section.
840
     The symbols will be defined as weak, so that multiple definitions
841
     are permitted.  The GNU linker extension is to actually discard
842
     all but one of the sections.  */
843
  if (startswith (name, ".gnu.linkonce"))
844
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
845
#endif
846
847
220k
  if (flags_ptr == NULL)
848
0
    return false;
849
850
220k
  * flags_ptr = sec_flags;
851
220k
  return true;
852
220k
}
coff-sh.c:styp_to_sec_flags
Line
Count
Source
687
360k
{
688
360k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
689
360k
  unsigned long styp_flags = internal_s->s_flags;
690
360k
  flagword sec_flags = 0;
691
692
#ifdef STYP_BLOCK
693
  if (styp_flags & STYP_BLOCK)
694
    sec_flags |= SEC_TIC54X_BLOCK;
695
#endif
696
697
#ifdef STYP_CLINK
698
  if (styp_flags & STYP_CLINK)
699
    sec_flags |= SEC_TIC54X_CLINK;
700
#endif
701
702
360k
#ifdef STYP_NOLOAD
703
360k
  if (styp_flags & STYP_NOLOAD)
704
147k
    sec_flags |= SEC_NEVER_LOAD;
705
360k
#endif /* STYP_NOLOAD */
706
707
  /* For 386 COFF, at least, an unloadable text or data section is
708
     actually a shared library section.  */
709
360k
  if (styp_flags & STYP_TEXT)
710
108k
    {
711
108k
      if (sec_flags & SEC_NEVER_LOAD)
712
55.1k
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
713
52.9k
      else
714
52.9k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
715
108k
    }
716
252k
  else if (styp_flags & STYP_DATA)
717
78.0k
    {
718
78.0k
      if (sec_flags & SEC_NEVER_LOAD)
719
53.5k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
720
24.4k
      else
721
24.4k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
722
78.0k
    }
723
174k
  else if (styp_flags & STYP_BSS)
724
39.5k
    {
725
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
726
      if (sec_flags & SEC_NEVER_LOAD)
727
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
728
      else
729
#endif
730
39.5k
  sec_flags |= SEC_ALLOC;
731
39.5k
    }
732
135k
  else if (styp_flags & STYP_INFO)
733
24.2k
    {
734
      /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
735
   defined.  coff_compute_section_file_positions uses
736
   COFF_PAGE_SIZE to ensure that the low order bits of the
737
   section VMA and the file offset match.  If we don't know
738
   COFF_PAGE_SIZE, we can't ensure the correct correspondence,
739
   and demand page loading of the file will fail.  */
740
#if defined (COFF_PAGE_SIZE) && !defined (COFF_ALIGN_IN_S_FLAGS)
741
      sec_flags |= SEC_DEBUGGING;
742
#endif
743
24.2k
    }
744
111k
  else if (styp_flags & STYP_PAD)
745
8.89k
    sec_flags = 0;
746
#ifdef RS6000COFF_C
747
  else if (styp_flags & STYP_TDATA)
748
    {
749
      if (sec_flags & SEC_NEVER_LOAD)
750
  sec_flags |= SEC_DATA | SEC_THREAD_LOCAL | SEC_COFF_SHARED_LIBRARY;
751
      else
752
  sec_flags |= SEC_DATA | SEC_THREAD_LOCAL | SEC_LOAD | SEC_ALLOC;
753
    }
754
  else if (styp_flags & STYP_TBSS)
755
    {
756
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
757
      if (sec_flags & SEC_NEVER_LOAD)
758
  sec_flags |= SEC_ALLOC | SEC_THREAD_LOCAL | SEC_COFF_SHARED_LIBRARY;
759
      else
760
#endif
761
  sec_flags |= SEC_ALLOC | SEC_THREAD_LOCAL;
762
    }
763
  else if (styp_flags & STYP_EXCEPT)
764
    sec_flags |= SEC_LOAD;
765
  else if (styp_flags & STYP_LOADER)
766
    sec_flags |= SEC_LOAD;
767
  else if (styp_flags & STYP_TYPCHK)
768
    sec_flags |= SEC_LOAD;
769
  else if (styp_flags & STYP_DWARF)
770
    sec_flags |= SEC_DEBUGGING;
771
#endif
772
102k
  else if (strcmp (name, _TEXT) == 0)
773
41
    {
774
41
      if (sec_flags & SEC_NEVER_LOAD)
775
0
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
776
41
      else
777
41
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
778
41
    }
779
102k
  else if (strcmp (name, _DATA) == 0)
780
0
    {
781
0
      if (sec_flags & SEC_NEVER_LOAD)
782
0
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
783
0
      else
784
0
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
785
0
    }
786
102k
  else if (strcmp (name, _BSS) == 0)
787
0
    {
788
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
789
      if (sec_flags & SEC_NEVER_LOAD)
790
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
791
      else
792
#endif
793
0
  sec_flags |= SEC_ALLOC;
794
0
    }
795
102k
  else if (startswith (name, DOT_DEBUG)
796
102k
     || startswith (name, DOT_ZDEBUG)
797
102k
#ifdef _COMMENT
798
102k
     || strcmp (name, _COMMENT) == 0
799
102k
#endif
800
#ifdef COFF_LONG_SECTION_NAMES
801
     || startswith (name, GNU_LINKONCE_WI)
802
     || startswith (name, GNU_LINKONCE_WT)
803
#endif
804
102k
     || startswith (name, ".stab"))
805
86
    {
806
#ifdef COFF_PAGE_SIZE
807
      sec_flags |= SEC_DEBUGGING;
808
#endif
809
86
    }
810
102k
#ifdef _LIB
811
102k
  else if (strcmp (name, _LIB) == 0)
812
1
    ;
813
102k
#endif
814
#ifdef _LIT
815
  else if (strcmp (name, _LIT) == 0)
816
    sec_flags = SEC_LOAD | SEC_ALLOC | SEC_READONLY;
817
#endif
818
102k
  else
819
102k
    sec_flags |= SEC_ALLOC | SEC_LOAD;
820
821
360k
#ifdef STYP_LIT     /* A29k readonly text/data section type.  */
822
360k
  if ((styp_flags & STYP_LIT) == STYP_LIT)
823
49.3k
    sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
824
360k
#endif /* STYP_LIT */
825
826
#ifdef STYP_OTHER_LOAD    /* Other loaded sections.  */
827
  if (styp_flags & STYP_OTHER_LOAD)
828
    sec_flags = (SEC_LOAD | SEC_ALLOC);
829
#endif /* STYP_SDATA */
830
831
360k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
832
360k
      && (startswith (name, ".sbss")
833
0
    || startswith (name, ".sdata")))
834
0
    sec_flags |= SEC_SMALL_DATA;
835
836
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
837
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
838
     only link a single copy of the section.  This is used to support
839
     g++.  g++ will emit each template expansion in its own section.
840
     The symbols will be defined as weak, so that multiple definitions
841
     are permitted.  The GNU linker extension is to actually discard
842
     all but one of the sections.  */
843
  if (startswith (name, ".gnu.linkonce"))
844
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
845
#endif
846
847
360k
  if (flags_ptr == NULL)
848
0
    return false;
849
850
360k
  * flags_ptr = sec_flags;
851
360k
  return true;
852
360k
}
coff-stgo32.c:styp_to_sec_flags
Line
Count
Source
687
92.9k
{
688
92.9k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
689
92.9k
  unsigned long styp_flags = internal_s->s_flags;
690
92.9k
  flagword sec_flags = 0;
691
692
#ifdef STYP_BLOCK
693
  if (styp_flags & STYP_BLOCK)
694
    sec_flags |= SEC_TIC54X_BLOCK;
695
#endif
696
697
#ifdef STYP_CLINK
698
  if (styp_flags & STYP_CLINK)
699
    sec_flags |= SEC_TIC54X_CLINK;
700
#endif
701
702
92.9k
#ifdef STYP_NOLOAD
703
92.9k
  if (styp_flags & STYP_NOLOAD)
704
31.9k
    sec_flags |= SEC_NEVER_LOAD;
705
92.9k
#endif /* STYP_NOLOAD */
706
707
  /* For 386 COFF, at least, an unloadable text or data section is
708
     actually a shared library section.  */
709
92.9k
  if (styp_flags & STYP_TEXT)
710
34.0k
    {
711
34.0k
      if (sec_flags & SEC_NEVER_LOAD)
712
16.6k
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
713
17.4k
      else
714
17.4k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
715
34.0k
    }
716
58.8k
  else if (styp_flags & STYP_DATA)
717
11.9k
    {
718
11.9k
      if (sec_flags & SEC_NEVER_LOAD)
719
6.25k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
720
5.71k
      else
721
5.71k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
722
11.9k
    }
723
46.9k
  else if (styp_flags & STYP_BSS)
724
6.42k
    {
725
6.42k
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
726
6.42k
      if (sec_flags & SEC_NEVER_LOAD)
727
2.29k
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
728
4.12k
      else
729
4.12k
#endif
730
4.12k
  sec_flags |= SEC_ALLOC;
731
6.42k
    }
732
40.4k
  else if (styp_flags & STYP_INFO)
733
8.43k
    {
734
      /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
735
   defined.  coff_compute_section_file_positions uses
736
   COFF_PAGE_SIZE to ensure that the low order bits of the
737
   section VMA and the file offset match.  If we don't know
738
   COFF_PAGE_SIZE, we can't ensure the correct correspondence,
739
   and demand page loading of the file will fail.  */
740
8.43k
#if defined (COFF_PAGE_SIZE) && !defined (COFF_ALIGN_IN_S_FLAGS)
741
8.43k
      sec_flags |= SEC_DEBUGGING;
742
8.43k
#endif
743
8.43k
    }
744
32.0k
  else if (styp_flags & STYP_PAD)
745
1.84k
    sec_flags = 0;
746
#ifdef RS6000COFF_C
747
  else if (styp_flags & STYP_TDATA)
748
    {
749
      if (sec_flags & SEC_NEVER_LOAD)
750
  sec_flags |= SEC_DATA | SEC_THREAD_LOCAL | SEC_COFF_SHARED_LIBRARY;
751
      else
752
  sec_flags |= SEC_DATA | SEC_THREAD_LOCAL | SEC_LOAD | SEC_ALLOC;
753
    }
754
  else if (styp_flags & STYP_TBSS)
755
    {
756
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
757
      if (sec_flags & SEC_NEVER_LOAD)
758
  sec_flags |= SEC_ALLOC | SEC_THREAD_LOCAL | SEC_COFF_SHARED_LIBRARY;
759
      else
760
#endif
761
  sec_flags |= SEC_ALLOC | SEC_THREAD_LOCAL;
762
    }
763
  else if (styp_flags & STYP_EXCEPT)
764
    sec_flags |= SEC_LOAD;
765
  else if (styp_flags & STYP_LOADER)
766
    sec_flags |= SEC_LOAD;
767
  else if (styp_flags & STYP_TYPCHK)
768
    sec_flags |= SEC_LOAD;
769
  else if (styp_flags & STYP_DWARF)
770
    sec_flags |= SEC_DEBUGGING;
771
#endif
772
30.2k
  else if (strcmp (name, _TEXT) == 0)
773
64
    {
774
64
      if (sec_flags & SEC_NEVER_LOAD)
775
2
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
776
62
      else
777
62
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
778
64
    }
779
30.1k
  else if (strcmp (name, _DATA) == 0)
780
0
    {
781
0
      if (sec_flags & SEC_NEVER_LOAD)
782
0
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
783
0
      else
784
0
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
785
0
    }
786
30.1k
  else if (strcmp (name, _BSS) == 0)
787
1
    {
788
1
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
789
1
      if (sec_flags & SEC_NEVER_LOAD)
790
0
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
791
1
      else
792
1
#endif
793
1
  sec_flags |= SEC_ALLOC;
794
1
    }
795
30.1k
  else if (startswith (name, DOT_DEBUG)
796
30.1k
     || startswith (name, DOT_ZDEBUG)
797
30.1k
#ifdef _COMMENT
798
30.1k
     || strcmp (name, _COMMENT) == 0
799
30.1k
#endif
800
30.1k
#ifdef COFF_LONG_SECTION_NAMES
801
30.1k
     || startswith (name, GNU_LINKONCE_WI)
802
30.1k
     || startswith (name, GNU_LINKONCE_WT)
803
30.1k
#endif
804
30.1k
     || startswith (name, ".stab"))
805
230
    {
806
230
#ifdef COFF_PAGE_SIZE
807
230
      sec_flags |= SEC_DEBUGGING;
808
230
#endif
809
230
    }
810
29.9k
#ifdef _LIB
811
29.9k
  else if (strcmp (name, _LIB) == 0)
812
2
    ;
813
29.9k
#endif
814
#ifdef _LIT
815
  else if (strcmp (name, _LIT) == 0)
816
    sec_flags = SEC_LOAD | SEC_ALLOC | SEC_READONLY;
817
#endif
818
29.9k
  else
819
29.9k
    sec_flags |= SEC_ALLOC | SEC_LOAD;
820
821
92.9k
#ifdef STYP_LIT     /* A29k readonly text/data section type.  */
822
92.9k
  if ((styp_flags & STYP_LIT) == STYP_LIT)
823
15.6k
    sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
824
92.9k
#endif /* STYP_LIT */
825
826
#ifdef STYP_OTHER_LOAD    /* Other loaded sections.  */
827
  if (styp_flags & STYP_OTHER_LOAD)
828
    sec_flags = (SEC_LOAD | SEC_ALLOC);
829
#endif /* STYP_SDATA */
830
831
92.9k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
832
92.9k
      && (startswith (name, ".sbss")
833
0
    || startswith (name, ".sdata")))
834
0
    sec_flags |= SEC_SMALL_DATA;
835
836
92.9k
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
837
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
838
     only link a single copy of the section.  This is used to support
839
     g++.  g++ will emit each template expansion in its own section.
840
     The symbols will be defined as weak, so that multiple definitions
841
     are permitted.  The GNU linker extension is to actually discard
842
     all but one of the sections.  */
843
92.9k
  if (startswith (name, ".gnu.linkonce"))
844
0
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
845
92.9k
#endif
846
847
92.9k
  if (flags_ptr == NULL)
848
0
    return false;
849
850
92.9k
  * flags_ptr = sec_flags;
851
92.9k
  return true;
852
92.9k
}
coff-tic30.c:styp_to_sec_flags
Line
Count
Source
687
10.6k
{
688
10.6k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
689
10.6k
  unsigned long styp_flags = internal_s->s_flags;
690
10.6k
  flagword sec_flags = 0;
691
692
#ifdef STYP_BLOCK
693
  if (styp_flags & STYP_BLOCK)
694
    sec_flags |= SEC_TIC54X_BLOCK;
695
#endif
696
697
#ifdef STYP_CLINK
698
  if (styp_flags & STYP_CLINK)
699
    sec_flags |= SEC_TIC54X_CLINK;
700
#endif
701
702
10.6k
#ifdef STYP_NOLOAD
703
10.6k
  if (styp_flags & STYP_NOLOAD)
704
3.00k
    sec_flags |= SEC_NEVER_LOAD;
705
10.6k
#endif /* STYP_NOLOAD */
706
707
  /* For 386 COFF, at least, an unloadable text or data section is
708
     actually a shared library section.  */
709
10.6k
  if (styp_flags & STYP_TEXT)
710
2.66k
    {
711
2.66k
      if (sec_flags & SEC_NEVER_LOAD)
712
1.62k
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
713
1.03k
      else
714
1.03k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
715
2.66k
    }
716
8.01k
  else if (styp_flags & STYP_DATA)
717
645
    {
718
645
      if (sec_flags & SEC_NEVER_LOAD)
719
358
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
720
287
      else
721
287
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
722
645
    }
723
7.37k
  else if (styp_flags & STYP_BSS)
724
468
    {
725
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
726
      if (sec_flags & SEC_NEVER_LOAD)
727
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
728
      else
729
#endif
730
468
  sec_flags |= SEC_ALLOC;
731
468
    }
732
6.90k
  else if (styp_flags & STYP_INFO)
733
1.09k
    {
734
      /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
735
   defined.  coff_compute_section_file_positions uses
736
   COFF_PAGE_SIZE to ensure that the low order bits of the
737
   section VMA and the file offset match.  If we don't know
738
   COFF_PAGE_SIZE, we can't ensure the correct correspondence,
739
   and demand page loading of the file will fail.  */
740
#if defined (COFF_PAGE_SIZE) && !defined (COFF_ALIGN_IN_S_FLAGS)
741
      sec_flags |= SEC_DEBUGGING;
742
#endif
743
1.09k
    }
744
5.81k
  else if (styp_flags & STYP_PAD)
745
241
    sec_flags = 0;
746
#ifdef RS6000COFF_C
747
  else if (styp_flags & STYP_TDATA)
748
    {
749
      if (sec_flags & SEC_NEVER_LOAD)
750
  sec_flags |= SEC_DATA | SEC_THREAD_LOCAL | SEC_COFF_SHARED_LIBRARY;
751
      else
752
  sec_flags |= SEC_DATA | SEC_THREAD_LOCAL | SEC_LOAD | SEC_ALLOC;
753
    }
754
  else if (styp_flags & STYP_TBSS)
755
    {
756
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
757
      if (sec_flags & SEC_NEVER_LOAD)
758
  sec_flags |= SEC_ALLOC | SEC_THREAD_LOCAL | SEC_COFF_SHARED_LIBRARY;
759
      else
760
#endif
761
  sec_flags |= SEC_ALLOC | SEC_THREAD_LOCAL;
762
    }
763
  else if (styp_flags & STYP_EXCEPT)
764
    sec_flags |= SEC_LOAD;
765
  else if (styp_flags & STYP_LOADER)
766
    sec_flags |= SEC_LOAD;
767
  else if (styp_flags & STYP_TYPCHK)
768
    sec_flags |= SEC_LOAD;
769
  else if (styp_flags & STYP_DWARF)
770
    sec_flags |= SEC_DEBUGGING;
771
#endif
772
5.57k
  else if (strcmp (name, _TEXT) == 0)
773
18
    {
774
18
      if (sec_flags & SEC_NEVER_LOAD)
775
2
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
776
16
      else
777
16
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
778
18
    }
779
5.55k
  else if (strcmp (name, _DATA) == 0)
780
0
    {
781
0
      if (sec_flags & SEC_NEVER_LOAD)
782
0
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
783
0
      else
784
0
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
785
0
    }
786
5.55k
  else if (strcmp (name, _BSS) == 0)
787
0
    {
788
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
789
      if (sec_flags & SEC_NEVER_LOAD)
790
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
791
      else
792
#endif
793
0
  sec_flags |= SEC_ALLOC;
794
0
    }
795
5.55k
  else if (startswith (name, DOT_DEBUG)
796
5.55k
     || startswith (name, DOT_ZDEBUG)
797
5.55k
#ifdef _COMMENT
798
5.55k
     || strcmp (name, _COMMENT) == 0
799
5.55k
#endif
800
#ifdef COFF_LONG_SECTION_NAMES
801
     || startswith (name, GNU_LINKONCE_WI)
802
     || startswith (name, GNU_LINKONCE_WT)
803
#endif
804
5.55k
     || startswith (name, ".stab"))
805
12
    {
806
#ifdef COFF_PAGE_SIZE
807
      sec_flags |= SEC_DEBUGGING;
808
#endif
809
12
    }
810
5.54k
#ifdef _LIB
811
5.54k
  else if (strcmp (name, _LIB) == 0)
812
0
    ;
813
5.54k
#endif
814
#ifdef _LIT
815
  else if (strcmp (name, _LIT) == 0)
816
    sec_flags = SEC_LOAD | SEC_ALLOC | SEC_READONLY;
817
#endif
818
5.54k
  else
819
5.54k
    sec_flags |= SEC_ALLOC | SEC_LOAD;
820
821
10.6k
#ifdef STYP_LIT     /* A29k readonly text/data section type.  */
822
10.6k
  if ((styp_flags & STYP_LIT) == STYP_LIT)
823
793
    sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
824
10.6k
#endif /* STYP_LIT */
825
826
#ifdef STYP_OTHER_LOAD    /* Other loaded sections.  */
827
  if (styp_flags & STYP_OTHER_LOAD)
828
    sec_flags = (SEC_LOAD | SEC_ALLOC);
829
#endif /* STYP_SDATA */
830
831
10.6k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
832
10.6k
      && (startswith (name, ".sbss")
833
0
    || startswith (name, ".sdata")))
834
0
    sec_flags |= SEC_SMALL_DATA;
835
836
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
837
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
838
     only link a single copy of the section.  This is used to support
839
     g++.  g++ will emit each template expansion in its own section.
840
     The symbols will be defined as weak, so that multiple definitions
841
     are permitted.  The GNU linker extension is to actually discard
842
     all but one of the sections.  */
843
  if (startswith (name, ".gnu.linkonce"))
844
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
845
#endif
846
847
10.6k
  if (flags_ptr == NULL)
848
0
    return false;
849
850
10.6k
  * flags_ptr = sec_flags;
851
10.6k
  return true;
852
10.6k
}
Unexecuted instantiation: coff-tic4x.c:styp_to_sec_flags
coff-tic54x.c:styp_to_sec_flags
Line
Count
Source
687
22.8k
{
688
22.8k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
689
22.8k
  unsigned long styp_flags = internal_s->s_flags;
690
22.8k
  flagword sec_flags = 0;
691
692
22.8k
#ifdef STYP_BLOCK
693
22.8k
  if (styp_flags & STYP_BLOCK)
694
3.04k
    sec_flags |= SEC_TIC54X_BLOCK;
695
22.8k
#endif
696
697
22.8k
#ifdef STYP_CLINK
698
22.8k
  if (styp_flags & STYP_CLINK)
699
3.22k
    sec_flags |= SEC_TIC54X_CLINK;
700
22.8k
#endif
701
702
22.8k
#ifdef STYP_NOLOAD
703
22.8k
  if (styp_flags & STYP_NOLOAD)
704
6.05k
    sec_flags |= SEC_NEVER_LOAD;
705
22.8k
#endif /* STYP_NOLOAD */
706
707
  /* For 386 COFF, at least, an unloadable text or data section is
708
     actually a shared library section.  */
709
22.8k
  if (styp_flags & STYP_TEXT)
710
5.96k
    {
711
5.96k
      if (sec_flags & SEC_NEVER_LOAD)
712
4.30k
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
713
1.66k
      else
714
1.66k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
715
5.96k
    }
716
16.9k
  else if (styp_flags & STYP_DATA)
717
1.04k
    {
718
1.04k
      if (sec_flags & SEC_NEVER_LOAD)
719
485
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
720
559
      else
721
559
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
722
1.04k
    }
723
15.8k
  else if (styp_flags & STYP_BSS)
724
4.31k
    {
725
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
726
      if (sec_flags & SEC_NEVER_LOAD)
727
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
728
      else
729
#endif
730
4.31k
  sec_flags |= SEC_ALLOC;
731
4.31k
    }
732
11.5k
  else if (styp_flags & STYP_INFO)
733
1.18k
    {
734
      /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
735
   defined.  coff_compute_section_file_positions uses
736
   COFF_PAGE_SIZE to ensure that the low order bits of the
737
   section VMA and the file offset match.  If we don't know
738
   COFF_PAGE_SIZE, we can't ensure the correct correspondence,
739
   and demand page loading of the file will fail.  */
740
#if defined (COFF_PAGE_SIZE) && !defined (COFF_ALIGN_IN_S_FLAGS)
741
      sec_flags |= SEC_DEBUGGING;
742
#endif
743
1.18k
    }
744
10.3k
  else if (styp_flags & STYP_PAD)
745
765
    sec_flags = 0;
746
#ifdef RS6000COFF_C
747
  else if (styp_flags & STYP_TDATA)
748
    {
749
      if (sec_flags & SEC_NEVER_LOAD)
750
  sec_flags |= SEC_DATA | SEC_THREAD_LOCAL | SEC_COFF_SHARED_LIBRARY;
751
      else
752
  sec_flags |= SEC_DATA | SEC_THREAD_LOCAL | SEC_LOAD | SEC_ALLOC;
753
    }
754
  else if (styp_flags & STYP_TBSS)
755
    {
756
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
757
      if (sec_flags & SEC_NEVER_LOAD)
758
  sec_flags |= SEC_ALLOC | SEC_THREAD_LOCAL | SEC_COFF_SHARED_LIBRARY;
759
      else
760
#endif
761
  sec_flags |= SEC_ALLOC | SEC_THREAD_LOCAL;
762
    }
763
  else if (styp_flags & STYP_EXCEPT)
764
    sec_flags |= SEC_LOAD;
765
  else if (styp_flags & STYP_LOADER)
766
    sec_flags |= SEC_LOAD;
767
  else if (styp_flags & STYP_TYPCHK)
768
    sec_flags |= SEC_LOAD;
769
  else if (styp_flags & STYP_DWARF)
770
    sec_flags |= SEC_DEBUGGING;
771
#endif
772
9.59k
  else if (strcmp (name, _TEXT) == 0)
773
21
    {
774
21
      if (sec_flags & SEC_NEVER_LOAD)
775
0
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
776
21
      else
777
21
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
778
21
    }
779
9.57k
  else if (strcmp (name, _DATA) == 0)
780
0
    {
781
0
      if (sec_flags & SEC_NEVER_LOAD)
782
0
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
783
0
      else
784
0
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
785
0
    }
786
9.57k
  else if (strcmp (name, _BSS) == 0)
787
0
    {
788
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
789
      if (sec_flags & SEC_NEVER_LOAD)
790
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
791
      else
792
#endif
793
0
  sec_flags |= SEC_ALLOC;
794
0
    }
795
9.57k
  else if (startswith (name, DOT_DEBUG)
796
9.57k
     || startswith (name, DOT_ZDEBUG)
797
#ifdef _COMMENT
798
     || strcmp (name, _COMMENT) == 0
799
#endif
800
#ifdef COFF_LONG_SECTION_NAMES
801
     || startswith (name, GNU_LINKONCE_WI)
802
     || startswith (name, GNU_LINKONCE_WT)
803
#endif
804
9.57k
     || startswith (name, ".stab"))
805
1
    {
806
#ifdef COFF_PAGE_SIZE
807
      sec_flags |= SEC_DEBUGGING;
808
#endif
809
1
    }
810
#ifdef _LIB
811
  else if (strcmp (name, _LIB) == 0)
812
    ;
813
#endif
814
#ifdef _LIT
815
  else if (strcmp (name, _LIT) == 0)
816
    sec_flags = SEC_LOAD | SEC_ALLOC | SEC_READONLY;
817
#endif
818
9.57k
  else
819
9.57k
    sec_flags |= SEC_ALLOC | SEC_LOAD;
820
821
22.8k
#ifdef STYP_LIT     /* A29k readonly text/data section type.  */
822
22.8k
  if ((styp_flags & STYP_LIT) == STYP_LIT)
823
3.73k
    sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
824
22.8k
#endif /* STYP_LIT */
825
826
#ifdef STYP_OTHER_LOAD    /* Other loaded sections.  */
827
  if (styp_flags & STYP_OTHER_LOAD)
828
    sec_flags = (SEC_LOAD | SEC_ALLOC);
829
#endif /* STYP_SDATA */
830
831
22.8k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
832
22.8k
      && (startswith (name, ".sbss")
833
0
    || startswith (name, ".sdata")))
834
0
    sec_flags |= SEC_SMALL_DATA;
835
836
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
837
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
838
     only link a single copy of the section.  This is used to support
839
     g++.  g++ will emit each template expansion in its own section.
840
     The symbols will be defined as weak, so that multiple definitions
841
     are permitted.  The GNU linker extension is to actually discard
842
     all but one of the sections.  */
843
  if (startswith (name, ".gnu.linkonce"))
844
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
845
#endif
846
847
22.8k
  if (flags_ptr == NULL)
848
0
    return false;
849
850
22.8k
  * flags_ptr = sec_flags;
851
22.8k
  return true;
852
22.8k
}
coff-z80.c:styp_to_sec_flags
Line
Count
Source
687
9.17k
{
688
9.17k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
689
9.17k
  unsigned long styp_flags = internal_s->s_flags;
690
9.17k
  flagword sec_flags = 0;
691
692
#ifdef STYP_BLOCK
693
  if (styp_flags & STYP_BLOCK)
694
    sec_flags |= SEC_TIC54X_BLOCK;
695
#endif
696
697
#ifdef STYP_CLINK
698
  if (styp_flags & STYP_CLINK)
699
    sec_flags |= SEC_TIC54X_CLINK;
700
#endif
701
702
9.17k
#ifdef STYP_NOLOAD
703
9.17k
  if (styp_flags & STYP_NOLOAD)
704
2.96k
    sec_flags |= SEC_NEVER_LOAD;
705
9.17k
#endif /* STYP_NOLOAD */
706
707
  /* For 386 COFF, at least, an unloadable text or data section is
708
     actually a shared library section.  */
709
9.17k
  if (styp_flags & STYP_TEXT)
710
2.23k
    {
711
2.23k
      if (sec_flags & SEC_NEVER_LOAD)
712
1.48k
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
713
752
      else
714
752
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
715
2.23k
    }
716
6.94k
  else if (styp_flags & STYP_DATA)
717
338
    {
718
338
      if (sec_flags & SEC_NEVER_LOAD)
719
173
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
720
165
      else
721
165
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
722
338
    }
723
6.60k
  else if (styp_flags & STYP_BSS)
724
231
    {
725
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
726
      if (sec_flags & SEC_NEVER_LOAD)
727
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
728
      else
729
#endif
730
231
  sec_flags |= SEC_ALLOC;
731
231
    }
732
6.37k
  else if (styp_flags & STYP_INFO)
733
1.20k
    {
734
      /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
735
   defined.  coff_compute_section_file_positions uses
736
   COFF_PAGE_SIZE to ensure that the low order bits of the
737
   section VMA and the file offset match.  If we don't know
738
   COFF_PAGE_SIZE, we can't ensure the correct correspondence,
739
   and demand page loading of the file will fail.  */
740
#if defined (COFF_PAGE_SIZE) && !defined (COFF_ALIGN_IN_S_FLAGS)
741
      sec_flags |= SEC_DEBUGGING;
742
#endif
743
1.20k
    }
744
5.17k
  else if (styp_flags & STYP_PAD)
745
832
    sec_flags = 0;
746
#ifdef RS6000COFF_C
747
  else if (styp_flags & STYP_TDATA)
748
    {
749
      if (sec_flags & SEC_NEVER_LOAD)
750
  sec_flags |= SEC_DATA | SEC_THREAD_LOCAL | SEC_COFF_SHARED_LIBRARY;
751
      else
752
  sec_flags |= SEC_DATA | SEC_THREAD_LOCAL | SEC_LOAD | SEC_ALLOC;
753
    }
754
  else if (styp_flags & STYP_TBSS)
755
    {
756
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
757
      if (sec_flags & SEC_NEVER_LOAD)
758
  sec_flags |= SEC_ALLOC | SEC_THREAD_LOCAL | SEC_COFF_SHARED_LIBRARY;
759
      else
760
#endif
761
  sec_flags |= SEC_ALLOC | SEC_THREAD_LOCAL;
762
    }
763
  else if (styp_flags & STYP_EXCEPT)
764
    sec_flags |= SEC_LOAD;
765
  else if (styp_flags & STYP_LOADER)
766
    sec_flags |= SEC_LOAD;
767
  else if (styp_flags & STYP_TYPCHK)
768
    sec_flags |= SEC_LOAD;
769
  else if (styp_flags & STYP_DWARF)
770
    sec_flags |= SEC_DEBUGGING;
771
#endif
772
4.34k
  else if (strcmp (name, _TEXT) == 0)
773
4
    {
774
4
      if (sec_flags & SEC_NEVER_LOAD)
775
0
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
776
4
      else
777
4
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
778
4
    }
779
4.33k
  else if (strcmp (name, _DATA) == 0)
780
0
    {
781
0
      if (sec_flags & SEC_NEVER_LOAD)
782
0
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
783
0
      else
784
0
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
785
0
    }
786
4.33k
  else if (strcmp (name, _BSS) == 0)
787
0
    {
788
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
789
      if (sec_flags & SEC_NEVER_LOAD)
790
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
791
      else
792
#endif
793
0
  sec_flags |= SEC_ALLOC;
794
0
    }
795
4.33k
  else if (startswith (name, DOT_DEBUG)
796
4.33k
     || startswith (name, DOT_ZDEBUG)
797
4.33k
#ifdef _COMMENT
798
4.33k
     || strcmp (name, _COMMENT) == 0
799
4.33k
#endif
800
#ifdef COFF_LONG_SECTION_NAMES
801
     || startswith (name, GNU_LINKONCE_WI)
802
     || startswith (name, GNU_LINKONCE_WT)
803
#endif
804
4.33k
     || startswith (name, ".stab"))
805
7
    {
806
#ifdef COFF_PAGE_SIZE
807
      sec_flags |= SEC_DEBUGGING;
808
#endif
809
7
    }
810
4.33k
#ifdef _LIB
811
4.33k
  else if (strcmp (name, _LIB) == 0)
812
0
    ;
813
4.33k
#endif
814
#ifdef _LIT
815
  else if (strcmp (name, _LIT) == 0)
816
    sec_flags = SEC_LOAD | SEC_ALLOC | SEC_READONLY;
817
#endif
818
4.33k
  else
819
4.33k
    sec_flags |= SEC_ALLOC | SEC_LOAD;
820
821
9.17k
#ifdef STYP_LIT     /* A29k readonly text/data section type.  */
822
9.17k
  if ((styp_flags & STYP_LIT) == STYP_LIT)
823
1.33k
    sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
824
9.17k
#endif /* STYP_LIT */
825
826
#ifdef STYP_OTHER_LOAD    /* Other loaded sections.  */
827
  if (styp_flags & STYP_OTHER_LOAD)
828
    sec_flags = (SEC_LOAD | SEC_ALLOC);
829
#endif /* STYP_SDATA */
830
831
9.17k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
832
9.17k
      && (startswith (name, ".sbss")
833
0
    || startswith (name, ".sdata")))
834
0
    sec_flags |= SEC_SMALL_DATA;
835
836
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
837
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
838
     only link a single copy of the section.  This is used to support
839
     g++.  g++ will emit each template expansion in its own section.
840
     The symbols will be defined as weak, so that multiple definitions
841
     are permitted.  The GNU linker extension is to actually discard
842
     all but one of the sections.  */
843
  if (startswith (name, ".gnu.linkonce"))
844
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
845
#endif
846
847
9.17k
  if (flags_ptr == NULL)
848
0
    return false;
849
850
9.17k
  * flags_ptr = sec_flags;
851
9.17k
  return true;
852
9.17k
}
coff-z8k.c:styp_to_sec_flags
Line
Count
Source
687
98.5k
{
688
98.5k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
689
98.5k
  unsigned long styp_flags = internal_s->s_flags;
690
98.5k
  flagword sec_flags = 0;
691
692
#ifdef STYP_BLOCK
693
  if (styp_flags & STYP_BLOCK)
694
    sec_flags |= SEC_TIC54X_BLOCK;
695
#endif
696
697
#ifdef STYP_CLINK
698
  if (styp_flags & STYP_CLINK)
699
    sec_flags |= SEC_TIC54X_CLINK;
700
#endif
701
702
98.5k
#ifdef STYP_NOLOAD
703
98.5k
  if (styp_flags & STYP_NOLOAD)
704
25.9k
    sec_flags |= SEC_NEVER_LOAD;
705
98.5k
#endif /* STYP_NOLOAD */
706
707
  /* For 386 COFF, at least, an unloadable text or data section is
708
     actually a shared library section.  */
709
98.5k
  if (styp_flags & STYP_TEXT)
710
23.0k
    {
711
23.0k
      if (sec_flags & SEC_NEVER_LOAD)
712
12.6k
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
713
10.3k
      else
714
10.3k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
715
23.0k
    }
716
75.5k
  else if (styp_flags & STYP_DATA)
717
9.32k
    {
718
9.32k
      if (sec_flags & SEC_NEVER_LOAD)
719
5.19k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
720
4.12k
      else
721
4.12k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
722
9.32k
    }
723
66.1k
  else if (styp_flags & STYP_BSS)
724
3.59k
    {
725
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
726
      if (sec_flags & SEC_NEVER_LOAD)
727
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
728
      else
729
#endif
730
3.59k
  sec_flags |= SEC_ALLOC;
731
3.59k
    }
732
62.5k
  else if (styp_flags & STYP_INFO)
733
8.61k
    {
734
      /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
735
   defined.  coff_compute_section_file_positions uses
736
   COFF_PAGE_SIZE to ensure that the low order bits of the
737
   section VMA and the file offset match.  If we don't know
738
   COFF_PAGE_SIZE, we can't ensure the correct correspondence,
739
   and demand page loading of the file will fail.  */
740
#if defined (COFF_PAGE_SIZE) && !defined (COFF_ALIGN_IN_S_FLAGS)
741
      sec_flags |= SEC_DEBUGGING;
742
#endif
743
8.61k
    }
744
53.9k
  else if (styp_flags & STYP_PAD)
745
5.41k
    sec_flags = 0;
746
#ifdef RS6000COFF_C
747
  else if (styp_flags & STYP_TDATA)
748
    {
749
      if (sec_flags & SEC_NEVER_LOAD)
750
  sec_flags |= SEC_DATA | SEC_THREAD_LOCAL | SEC_COFF_SHARED_LIBRARY;
751
      else
752
  sec_flags |= SEC_DATA | SEC_THREAD_LOCAL | SEC_LOAD | SEC_ALLOC;
753
    }
754
  else if (styp_flags & STYP_TBSS)
755
    {
756
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
757
      if (sec_flags & SEC_NEVER_LOAD)
758
  sec_flags |= SEC_ALLOC | SEC_THREAD_LOCAL | SEC_COFF_SHARED_LIBRARY;
759
      else
760
#endif
761
  sec_flags |= SEC_ALLOC | SEC_THREAD_LOCAL;
762
    }
763
  else if (styp_flags & STYP_EXCEPT)
764
    sec_flags |= SEC_LOAD;
765
  else if (styp_flags & STYP_LOADER)
766
    sec_flags |= SEC_LOAD;
767
  else if (styp_flags & STYP_TYPCHK)
768
    sec_flags |= SEC_LOAD;
769
  else if (styp_flags & STYP_DWARF)
770
    sec_flags |= SEC_DEBUGGING;
771
#endif
772
48.5k
  else if (strcmp (name, _TEXT) == 0)
773
8
    {
774
8
      if (sec_flags & SEC_NEVER_LOAD)
775
2
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
776
6
      else
777
6
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
778
8
    }
779
48.5k
  else if (strcmp (name, _DATA) == 0)
780
1
    {
781
1
      if (sec_flags & SEC_NEVER_LOAD)
782
0
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
783
1
      else
784
1
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
785
1
    }
786
48.5k
  else if (strcmp (name, _BSS) == 0)
787
4
    {
788
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
789
      if (sec_flags & SEC_NEVER_LOAD)
790
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
791
      else
792
#endif
793
4
  sec_flags |= SEC_ALLOC;
794
4
    }
795
48.5k
  else if (startswith (name, DOT_DEBUG)
796
48.5k
     || startswith (name, DOT_ZDEBUG)
797
48.5k
#ifdef _COMMENT
798
48.5k
     || strcmp (name, _COMMENT) == 0
799
48.5k
#endif
800
#ifdef COFF_LONG_SECTION_NAMES
801
     || startswith (name, GNU_LINKONCE_WI)
802
     || startswith (name, GNU_LINKONCE_WT)
803
#endif
804
48.5k
     || startswith (name, ".stab"))
805
50
    {
806
#ifdef COFF_PAGE_SIZE
807
      sec_flags |= SEC_DEBUGGING;
808
#endif
809
50
    }
810
48.4k
#ifdef _LIB
811
48.4k
  else if (strcmp (name, _LIB) == 0)
812
0
    ;
813
48.4k
#endif
814
#ifdef _LIT
815
  else if (strcmp (name, _LIT) == 0)
816
    sec_flags = SEC_LOAD | SEC_ALLOC | SEC_READONLY;
817
#endif
818
48.4k
  else
819
48.4k
    sec_flags |= SEC_ALLOC | SEC_LOAD;
820
821
98.5k
#ifdef STYP_LIT     /* A29k readonly text/data section type.  */
822
98.5k
  if ((styp_flags & STYP_LIT) == STYP_LIT)
823
8.11k
    sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
824
98.5k
#endif /* STYP_LIT */
825
826
#ifdef STYP_OTHER_LOAD    /* Other loaded sections.  */
827
  if (styp_flags & STYP_OTHER_LOAD)
828
    sec_flags = (SEC_LOAD | SEC_ALLOC);
829
#endif /* STYP_SDATA */
830
831
98.5k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
832
98.5k
      && (startswith (name, ".sbss")
833
0
    || startswith (name, ".sdata")))
834
0
    sec_flags |= SEC_SMALL_DATA;
835
836
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
837
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
838
     only link a single copy of the section.  This is used to support
839
     g++.  g++ will emit each template expansion in its own section.
840
     The symbols will be defined as weak, so that multiple definitions
841
     are permitted.  The GNU linker extension is to actually discard
842
     all but one of the sections.  */
843
  if (startswith (name, ".gnu.linkonce"))
844
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
845
#endif
846
847
98.5k
  if (flags_ptr == NULL)
848
0
    return false;
849
850
98.5k
  * flags_ptr = sec_flags;
851
98.5k
  return true;
852
98.5k
}
853
854
#else /* COFF_WITH_PE */
855
856
static hashval_t
857
comdat_hashf (const void *entry)
858
352k
{
859
352k
  const struct comdat_hash_entry *fe = entry;
860
352k
  return fe->target_index;
861
352k
}
pei-i386.c:comdat_hashf
Line
Count
Source
858
3.47k
{
859
3.47k
  const struct comdat_hash_entry *fe = entry;
860
3.47k
  return fe->target_index;
861
3.47k
}
pe-x86_64.c:comdat_hashf
Line
Count
Source
858
9.79k
{
859
9.79k
  const struct comdat_hash_entry *fe = entry;
860
9.79k
  return fe->target_index;
861
9.79k
}
pei-x86_64.c:comdat_hashf
Line
Count
Source
858
3.59k
{
859
3.59k
  const struct comdat_hash_entry *fe = entry;
860
3.59k
  return fe->target_index;
861
3.59k
}
pe-aarch64.c:comdat_hashf
Line
Count
Source
858
7.89k
{
859
7.89k
  const struct comdat_hash_entry *fe = entry;
860
7.89k
  return fe->target_index;
861
7.89k
}
pei-aarch64.c:comdat_hashf
Line
Count
Source
858
18.0k
{
859
18.0k
  const struct comdat_hash_entry *fe = entry;
860
18.0k
  return fe->target_index;
861
18.0k
}
pei-ia64.c:comdat_hashf
Line
Count
Source
858
2.06k
{
859
2.06k
  const struct comdat_hash_entry *fe = entry;
860
2.06k
  return fe->target_index;
861
2.06k
}
pei-loongarch64.c:comdat_hashf
Line
Count
Source
858
6.71k
{
859
6.71k
  const struct comdat_hash_entry *fe = entry;
860
6.71k
  return fe->target_index;
861
6.71k
}
pe-arm-wince.c:comdat_hashf
Line
Count
Source
858
277
{
859
277
  const struct comdat_hash_entry *fe = entry;
860
277
  return fe->target_index;
861
277
}
pe-arm.c:comdat_hashf
Line
Count
Source
858
277
{
859
277
  const struct comdat_hash_entry *fe = entry;
860
277
  return fe->target_index;
861
277
}
pe-i386.c:comdat_hashf
Line
Count
Source
858
7.60k
{
859
7.60k
  const struct comdat_hash_entry *fe = entry;
860
7.60k
  return fe->target_index;
861
7.60k
}
pe-mcore.c:comdat_hashf
Line
Count
Source
858
837
{
859
837
  const struct comdat_hash_entry *fe = entry;
860
837
  return fe->target_index;
861
837
}
pe-sh.c:comdat_hashf
Line
Count
Source
858
287k
{
859
287k
  const struct comdat_hash_entry *fe = entry;
860
287k
  return fe->target_index;
861
287k
}
Unexecuted instantiation: pei-arm-wince.c:comdat_hashf
Unexecuted instantiation: pei-arm.c:comdat_hashf
Unexecuted instantiation: pei-mcore.c:comdat_hashf
pei-sh.c:comdat_hashf
Line
Count
Source
858
3.76k
{
859
3.76k
  const struct comdat_hash_entry *fe = entry;
860
3.76k
  return fe->target_index;
861
3.76k
}
862
863
static int
864
comdat_eqf (const void *e1, const void *e2)
865
318k
{
866
318k
  const struct comdat_hash_entry *fe1 = e1;
867
318k
  const struct comdat_hash_entry *fe2 = e2;
868
318k
  return fe1->target_index == fe2->target_index;
869
318k
}
pei-i386.c:comdat_eqf
Line
Count
Source
865
2.98k
{
866
2.98k
  const struct comdat_hash_entry *fe1 = e1;
867
2.98k
  const struct comdat_hash_entry *fe2 = e2;
868
2.98k
  return fe1->target_index == fe2->target_index;
869
2.98k
}
pe-x86_64.c:comdat_eqf
Line
Count
Source
865
8.59k
{
866
8.59k
  const struct comdat_hash_entry *fe1 = e1;
867
8.59k
  const struct comdat_hash_entry *fe2 = e2;
868
8.59k
  return fe1->target_index == fe2->target_index;
869
8.59k
}
pei-x86_64.c:comdat_eqf
Line
Count
Source
865
3.12k
{
866
3.12k
  const struct comdat_hash_entry *fe1 = e1;
867
3.12k
  const struct comdat_hash_entry *fe2 = e2;
868
3.12k
  return fe1->target_index == fe2->target_index;
869
3.12k
}
pe-aarch64.c:comdat_eqf
Line
Count
Source
865
6.81k
{
866
6.81k
  const struct comdat_hash_entry *fe1 = e1;
867
6.81k
  const struct comdat_hash_entry *fe2 = e2;
868
6.81k
  return fe1->target_index == fe2->target_index;
869
6.81k
}
pei-aarch64.c:comdat_eqf
Line
Count
Source
865
17.1k
{
866
17.1k
  const struct comdat_hash_entry *fe1 = e1;
867
17.1k
  const struct comdat_hash_entry *fe2 = e2;
868
17.1k
  return fe1->target_index == fe2->target_index;
869
17.1k
}
pei-ia64.c:comdat_eqf
Line
Count
Source
865
2.01k
{
866
2.01k
  const struct comdat_hash_entry *fe1 = e1;
867
2.01k
  const struct comdat_hash_entry *fe2 = e2;
868
2.01k
  return fe1->target_index == fe2->target_index;
869
2.01k
}
pei-loongarch64.c:comdat_eqf
Line
Count
Source
865
5.72k
{
866
5.72k
  const struct comdat_hash_entry *fe1 = e1;
867
5.72k
  const struct comdat_hash_entry *fe2 = e2;
868
5.72k
  return fe1->target_index == fe2->target_index;
869
5.72k
}
pe-arm-wince.c:comdat_eqf
Line
Count
Source
865
272
{
866
272
  const struct comdat_hash_entry *fe1 = e1;
867
272
  const struct comdat_hash_entry *fe2 = e2;
868
272
  return fe1->target_index == fe2->target_index;
869
272
}
pe-arm.c:comdat_eqf
Line
Count
Source
865
272
{
866
272
  const struct comdat_hash_entry *fe1 = e1;
867
272
  const struct comdat_hash_entry *fe2 = e2;
868
272
  return fe1->target_index == fe2->target_index;
869
272
}
pe-i386.c:comdat_eqf
Line
Count
Source
865
6.22k
{
866
6.22k
  const struct comdat_hash_entry *fe1 = e1;
867
6.22k
  const struct comdat_hash_entry *fe2 = e2;
868
6.22k
  return fe1->target_index == fe2->target_index;
869
6.22k
}
pe-mcore.c:comdat_eqf
Line
Count
Source
865
522
{
866
522
  const struct comdat_hash_entry *fe1 = e1;
867
522
  const struct comdat_hash_entry *fe2 = e2;
868
522
  return fe1->target_index == fe2->target_index;
869
522
}
pe-sh.c:comdat_eqf
Line
Count
Source
865
261k
{
866
261k
  const struct comdat_hash_entry *fe1 = e1;
867
261k
  const struct comdat_hash_entry *fe2 = e2;
868
261k
  return fe1->target_index == fe2->target_index;
869
261k
}
Unexecuted instantiation: pei-arm-wince.c:comdat_eqf
Unexecuted instantiation: pei-arm.c:comdat_eqf
Unexecuted instantiation: pei-mcore.c:comdat_eqf
pei-sh.c:comdat_eqf
Line
Count
Source
865
3.57k
{
866
3.57k
  const struct comdat_hash_entry *fe1 = e1;
867
3.57k
  const struct comdat_hash_entry *fe2 = e2;
868
3.57k
  return fe1->target_index == fe2->target_index;
869
3.57k
}
870
871
static void
872
comdat_delf (void *ent)
873
42.6k
{
874
42.6k
  struct comdat_hash_entry *e = ent;
875
42.6k
  free (e->symname);
876
42.6k
  free (e);
877
42.6k
}
pei-i386.c:comdat_delf
Line
Count
Source
873
609
{
874
609
  struct comdat_hash_entry *e = ent;
875
609
  free (e->symname);
876
609
  free (e);
877
609
}
pe-x86_64.c:comdat_delf
Line
Count
Source
873
1.54k
{
874
1.54k
  struct comdat_hash_entry *e = ent;
875
1.54k
  free (e->symname);
876
1.54k
  free (e);
877
1.54k
}
pei-x86_64.c:comdat_delf
Line
Count
Source
873
673
{
874
673
  struct comdat_hash_entry *e = ent;
875
673
  free (e->symname);
876
673
  free (e);
877
673
}
pe-aarch64.c:comdat_delf
Line
Count
Source
873
1.53k
{
874
1.53k
  struct comdat_hash_entry *e = ent;
875
1.53k
  free (e->symname);
876
1.53k
  free (e);
877
1.53k
}
pei-aarch64.c:comdat_delf
Line
Count
Source
873
1.31k
{
874
1.31k
  struct comdat_hash_entry *e = ent;
875
1.31k
  free (e->symname);
876
1.31k
  free (e);
877
1.31k
}
pei-ia64.c:comdat_delf
Line
Count
Source
873
296
{
874
296
  struct comdat_hash_entry *e = ent;
875
296
  free (e->symname);
876
296
  free (e);
877
296
}
pei-loongarch64.c:comdat_delf
Line
Count
Source
873
1.38k
{
874
1.38k
  struct comdat_hash_entry *e = ent;
875
1.38k
  free (e->symname);
876
1.38k
  free (e);
877
1.38k
}
pe-arm-wince.c:comdat_delf
Line
Count
Source
873
13
{
874
13
  struct comdat_hash_entry *e = ent;
875
13
  free (e->symname);
876
13
  free (e);
877
13
}
pe-arm.c:comdat_delf
Line
Count
Source
873
13
{
874
13
  struct comdat_hash_entry *e = ent;
875
13
  free (e->symname);
876
13
  free (e);
877
13
}
pe-i386.c:comdat_delf
Line
Count
Source
873
1.38k
{
874
1.38k
  struct comdat_hash_entry *e = ent;
875
1.38k
  free (e->symname);
876
1.38k
  free (e);
877
1.38k
}
pe-mcore.c:comdat_delf
Line
Count
Source
873
198
{
874
198
  struct comdat_hash_entry *e = ent;
875
198
  free (e->symname);
876
198
  free (e);
877
198
}
pe-sh.c:comdat_delf
Line
Count
Source
873
33.4k
{
874
33.4k
  struct comdat_hash_entry *e = ent;
875
33.4k
  free (e->symname);
876
33.4k
  free (e);
877
33.4k
}
Unexecuted instantiation: pei-arm-wince.c:comdat_delf
Unexecuted instantiation: pei-arm.c:comdat_delf
Unexecuted instantiation: pei-mcore.c:comdat_delf
pei-sh.c:comdat_delf
Line
Count
Source
873
253
{
874
253
  struct comdat_hash_entry *e = ent;
875
253
  free (e->symname);
876
253
  free (e);
877
253
}
878
879
static struct comdat_hash_entry *
880
find_flags (htab_t comdat_hash, int target_index)
881
1.96k
{
882
1.96k
  struct comdat_hash_entry needle;
883
1.96k
  needle.target_index = target_index;
884
885
1.96k
  return htab_find (comdat_hash, &needle);
886
1.96k
}
pei-i386.c:find_flags
Line
Count
Source
881
42
{
882
42
  struct comdat_hash_entry needle;
883
42
  needle.target_index = target_index;
884
885
42
  return htab_find (comdat_hash, &needle);
886
42
}
pe-x86_64.c:find_flags
Line
Count
Source
881
40
{
882
40
  struct comdat_hash_entry needle;
883
40
  needle.target_index = target_index;
884
885
40
  return htab_find (comdat_hash, &needle);
886
40
}
pei-x86_64.c:find_flags
Line
Count
Source
881
46
{
882
46
  struct comdat_hash_entry needle;
883
46
  needle.target_index = target_index;
884
885
46
  return htab_find (comdat_hash, &needle);
886
46
}
pe-aarch64.c:find_flags
Line
Count
Source
881
60
{
882
60
  struct comdat_hash_entry needle;
883
60
  needle.target_index = target_index;
884
885
60
  return htab_find (comdat_hash, &needle);
886
60
}
pei-aarch64.c:find_flags
Line
Count
Source
881
272
{
882
272
  struct comdat_hash_entry needle;
883
272
  needle.target_index = target_index;
884
885
272
  return htab_find (comdat_hash, &needle);
886
272
}
pei-ia64.c:find_flags
Line
Count
Source
881
10
{
882
10
  struct comdat_hash_entry needle;
883
10
  needle.target_index = target_index;
884
885
10
  return htab_find (comdat_hash, &needle);
886
10
}
pei-loongarch64.c:find_flags
Line
Count
Source
881
63
{
882
63
  struct comdat_hash_entry needle;
883
63
  needle.target_index = target_index;
884
885
63
  return htab_find (comdat_hash, &needle);
886
63
}
pe-arm-wince.c:find_flags
Line
Count
Source
881
4
{
882
4
  struct comdat_hash_entry needle;
883
4
  needle.target_index = target_index;
884
885
4
  return htab_find (comdat_hash, &needle);
886
4
}
pe-arm.c:find_flags
Line
Count
Source
881
4
{
882
4
  struct comdat_hash_entry needle;
883
4
  needle.target_index = target_index;
884
885
4
  return htab_find (comdat_hash, &needle);
886
4
}
pe-i386.c:find_flags
Line
Count
Source
881
141
{
882
141
  struct comdat_hash_entry needle;
883
141
  needle.target_index = target_index;
884
885
141
  return htab_find (comdat_hash, &needle);
886
141
}
pe-mcore.c:find_flags
Line
Count
Source
881
1
{
882
1
  struct comdat_hash_entry needle;
883
1
  needle.target_index = target_index;
884
885
1
  return htab_find (comdat_hash, &needle);
886
1
}
pe-sh.c:find_flags
Line
Count
Source
881
1.27k
{
882
1.27k
  struct comdat_hash_entry needle;
883
1.27k
  needle.target_index = target_index;
884
885
1.27k
  return htab_find (comdat_hash, &needle);
886
1.27k
}
Unexecuted instantiation: pei-arm-wince.c:find_flags
Unexecuted instantiation: pei-arm.c:find_flags
Unexecuted instantiation: pei-mcore.c:find_flags
pei-sh.c:find_flags
Line
Count
Source
881
7
{
882
7
  struct comdat_hash_entry needle;
883
7
  needle.target_index = target_index;
884
885
7
  return htab_find (comdat_hash, &needle);
886
7
}
887
888
static bool
889
fill_comdat_hash (bfd *abfd)
890
1.21k
{
891
1.21k
  bfd_byte *esymstart, *esym, *esymend;
892
893
  /* Unfortunately, the PE format stores essential information in the
894
     symbol table, of all places.  We need to extract that information
895
     now, so that objdump and the linker will know how to handle the
896
     section without worrying about the symbols.  We can't call
897
     slurp_symtab, because the linker doesn't want the swapped symbols.  */
898
899
  /* COMDAT sections are special.  The first symbol is the section
900
     symbol, which tells what kind of COMDAT section it is.  The
901
     second symbol is the "comdat symbol" - the one with the unique
902
     name.  GNU uses the section symbol for the unique name; MS uses
903
     ".text" for every comdat section.  Sigh.  - DJ.  */
904
905
  /* This is not mirrored in sec_to_styp_flags(), but there doesn't
906
     seem to be a need to, either, and it would at best be rather messy.  */
907
908
1.21k
  if (! _bfd_coff_get_external_symbols (abfd))
909
29
    return true;
910
911
1.18k
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
912
1.18k
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
913
914
1.18k
  for (struct internal_syment isym;
915
375k
       esym < esymend;
916
374k
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
917
374k
    {
918
374k
      char buf[SYMNMLEN + 1];
919
374k
      const char *symname;
920
374k
      flagword sec_flags = SEC_LINK_ONCE;
921
922
374k
      bfd_coff_swap_sym_in (abfd, esym, &isym);
923
924
      /* According to the MSVC documentation, the first TWO entries
925
   with the section # are both of interest to us.  The first one
926
   is the "section symbol" (section name).  The second is the
927
   comdat symbol name.  Here, we've found the first qualifying
928
   entry; we distinguish it from the second with a state flag.
929
930
   In the case of gas-generated (at least until that is fixed)
931
   .o files, it isn't necessarily the second one.  It may be
932
   some other later symbol.
933
934
   Since gas also doesn't follow MS conventions and emits the
935
   section similar to .text$<name>, where <something> is the
936
   name we're looking for, we distinguish the two as follows:
937
938
   If the section name is simply a section name (no $) we
939
   presume it's MS-generated, and look at precisely the second
940
   symbol for the comdat name.  If the section name has a $, we
941
   assume it's gas-generated, and look for <something> (whatever
942
   follows the $) as the comdat symbol.  */
943
944
      /* All 3 branches use this.  */
945
374k
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
946
947
      /* PR 17512 file: 078-11867-0.004  */
948
374k
      if (symname == NULL)
949
70.4k
  {
950
70.4k
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
951
70.4k
            abfd);
952
70.4k
    continue;
953
70.4k
  }
954
955
304k
      union internal_auxent aux;
956
957
304k
      struct comdat_hash_entry needle;
958
304k
      needle.target_index = isym.n_scnum;
959
960
304k
      void **slot
961
304k
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
962
304k
      if (slot == NULL)
963
0
  return false;
964
965
304k
      if (*slot == NULL)
966
43.0k
  {
967
43.0k
    if (isym.n_numaux == 0)
968
14.8k
      aux.x_scn.x_comdat = 0;
969
28.2k
    else
970
28.2k
      {
971
        /* PR 17512: file: e2cfe54f.  */
972
28.2k
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
973
348
    {
974
      /* xgettext:c-format */
975
348
      _bfd_error_handler (_("%pB: warning: no symbol for"
976
348
          " section '%s' found"),
977
348
              abfd, symname);
978
348
      continue;
979
348
    }
980
27.8k
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
981
27.8k
            isym.n_type, isym.n_sclass, 0,
982
27.8k
            isym.n_numaux, &aux);
983
27.8k
      }
984
985
    /* FIXME: Microsoft uses NODUPLICATES and ASSOCIATIVE, but
986
       gnu uses ANY and SAME_SIZE.  Unfortunately, gnu doesn't
987
       do the comdat symbols right.  So, until we can fix it to
988
       do the right thing, we are temporarily disabling comdats
989
       for the MS types (they're used in DLLs and C++, but we
990
       don't support *their* C++ libraries anyway - DJ.  */
991
992
    /* Cygwin does not follow the MS style, and uses ANY and
993
       SAME_SIZE where NODUPLICATES and ASSOCIATIVE should be
994
       used.  For Interix, we just do the right thing up
995
       front.  */
996
997
42.6k
    switch (aux.x_scn.x_comdat)
998
42.6k
      {
999
50
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1000
#ifdef STRICT_PE_FORMAT
1001
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1002
#else
1003
50
        sec_flags &= ~SEC_LINK_ONCE;
1004
50
#endif
1005
50
        break;
1006
1007
3
      case IMAGE_COMDAT_SELECT_ANY:
1008
3
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1009
3
        break;
1010
1011
0
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1012
0
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1013
0
        break;
1014
1015
0
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1016
        /* Not yet fully implemented ??? */
1017
0
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1018
0
        break;
1019
1020
        /* debug$S gets this case; other implications ???  */
1021
1022
        /* There may be no symbol.  We'll search the whole
1023
     table.  Is this the right place to play this game?
1024
     Or should we do it when reading it in?  */
1025
0
      case IMAGE_COMDAT_SELECT_ASSOCIATIVE:
1026
#ifdef STRICT_PE_FORMAT
1027
        /* FIXME: This is not currently implemented.  */
1028
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1029
#else
1030
0
        sec_flags &= ~SEC_LINK_ONCE;
1031
0
#endif
1032
0
        break;
1033
1034
42.6k
      default:  /* 0 means "no symbol" */
1035
        /* debug$F gets this case; other implications ???  */
1036
42.6k
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1037
42.6k
        break;
1038
42.6k
      }
1039
1040
42.6k
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1041
42.6k
    if (*slot == NULL)
1042
0
      return false;
1043
42.6k
    struct comdat_hash_entry *newentry = *slot;
1044
42.6k
    newentry->sec_flags = sec_flags;
1045
42.6k
    newentry->symname = bfd_strdup (symname);
1046
42.6k
    newentry->target_index = isym.n_scnum;
1047
42.6k
    newentry->isym = isym;
1048
42.6k
    newentry->comdat_symbol = -1;
1049
42.6k
  }
1050
261k
      else
1051
261k
  {
1052
261k
    struct comdat_hash_entry *entry = *slot;
1053
1054
261k
    if (entry->comdat_symbol != -1)
1055
253k
      continue;
1056
1057
7.46k
    char *target_name = strchr (entry->symname, '$');
1058
7.46k
    if (target_name != NULL)
1059
351
      {
1060
        /* Gas mode: the first matching on partial name.  */
1061
1062
351
        target_name += 1;
1063
#ifndef TARGET_UNDERSCORE
1064
323
#define TARGET_UNDERSCORE 0
1065
#endif
1066
        /* Is this the name we're looking for ?  */
1067
351
        if (strcmp (target_name,
1068
351
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1069
350
    {
1070
      /* Not the name we're looking for */
1071
350
      continue;
1072
350
    }
1073
351
      }
1074
    /* MSVC mode: the lexically second symbol (or drop through
1075
       from the above).  */
1076
    /* This must the second symbol with the section #.  It is
1077
       the actual symbol name.  Intel puts the two adjacent, but
1078
       Alpha (at least) spreads them out.  */
1079
1080
7.11k
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1081
7.11k
    entry->comdat_name = bfd_strdup (symname);
1082
7.11k
  }
1083
304k
    }
1084
1085
1.18k
  return true;
1086
1.18k
}
pei-i386.c:fill_comdat_hash
Line
Count
Source
890
42
{
891
42
  bfd_byte *esymstart, *esym, *esymend;
892
893
  /* Unfortunately, the PE format stores essential information in the
894
     symbol table, of all places.  We need to extract that information
895
     now, so that objdump and the linker will know how to handle the
896
     section without worrying about the symbols.  We can't call
897
     slurp_symtab, because the linker doesn't want the swapped symbols.  */
898
899
  /* COMDAT sections are special.  The first symbol is the section
900
     symbol, which tells what kind of COMDAT section it is.  The
901
     second symbol is the "comdat symbol" - the one with the unique
902
     name.  GNU uses the section symbol for the unique name; MS uses
903
     ".text" for every comdat section.  Sigh.  - DJ.  */
904
905
  /* This is not mirrored in sec_to_styp_flags(), but there doesn't
906
     seem to be a need to, either, and it would at best be rather messy.  */
907
908
42
  if (! _bfd_coff_get_external_symbols (abfd))
909
0
    return true;
910
911
42
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
912
42
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
913
914
42
  for (struct internal_syment isym;
915
3.67k
       esym < esymend;
916
3.63k
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
917
3.63k
    {
918
3.63k
      char buf[SYMNMLEN + 1];
919
3.63k
      const char *symname;
920
3.63k
      flagword sec_flags = SEC_LINK_ONCE;
921
922
3.63k
      bfd_coff_swap_sym_in (abfd, esym, &isym);
923
924
      /* According to the MSVC documentation, the first TWO entries
925
   with the section # are both of interest to us.  The first one
926
   is the "section symbol" (section name).  The second is the
927
   comdat symbol name.  Here, we've found the first qualifying
928
   entry; we distinguish it from the second with a state flag.
929
930
   In the case of gas-generated (at least until that is fixed)
931
   .o files, it isn't necessarily the second one.  It may be
932
   some other later symbol.
933
934
   Since gas also doesn't follow MS conventions and emits the
935
   section similar to .text$<name>, where <something> is the
936
   name we're looking for, we distinguish the two as follows:
937
938
   If the section name is simply a section name (no $) we
939
   presume it's MS-generated, and look at precisely the second
940
   symbol for the comdat name.  If the section name has a $, we
941
   assume it's gas-generated, and look for <something> (whatever
942
   follows the $) as the comdat symbol.  */
943
944
      /* All 3 branches use this.  */
945
3.63k
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
946
947
      /* PR 17512 file: 078-11867-0.004  */
948
3.63k
      if (symname == NULL)
949
661
  {
950
661
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
951
661
            abfd);
952
661
    continue;
953
661
  }
954
955
2.97k
      union internal_auxent aux;
956
957
2.97k
      struct comdat_hash_entry needle;
958
2.97k
      needle.target_index = isym.n_scnum;
959
960
2.97k
      void **slot
961
2.97k
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
962
2.97k
      if (slot == NULL)
963
0
  return false;
964
965
2.97k
      if (*slot == NULL)
966
627
  {
967
627
    if (isym.n_numaux == 0)
968
206
      aux.x_scn.x_comdat = 0;
969
421
    else
970
421
      {
971
        /* PR 17512: file: e2cfe54f.  */
972
421
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
973
18
    {
974
      /* xgettext:c-format */
975
18
      _bfd_error_handler (_("%pB: warning: no symbol for"
976
18
          " section '%s' found"),
977
18
              abfd, symname);
978
18
      continue;
979
18
    }
980
403
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
981
403
            isym.n_type, isym.n_sclass, 0,
982
403
            isym.n_numaux, &aux);
983
403
      }
984
985
    /* FIXME: Microsoft uses NODUPLICATES and ASSOCIATIVE, but
986
       gnu uses ANY and SAME_SIZE.  Unfortunately, gnu doesn't
987
       do the comdat symbols right.  So, until we can fix it to
988
       do the right thing, we are temporarily disabling comdats
989
       for the MS types (they're used in DLLs and C++, but we
990
       don't support *their* C++ libraries anyway - DJ.  */
991
992
    /* Cygwin does not follow the MS style, and uses ANY and
993
       SAME_SIZE where NODUPLICATES and ASSOCIATIVE should be
994
       used.  For Interix, we just do the right thing up
995
       front.  */
996
997
609
    switch (aux.x_scn.x_comdat)
998
609
      {
999
2
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1000
#ifdef STRICT_PE_FORMAT
1001
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1002
#else
1003
2
        sec_flags &= ~SEC_LINK_ONCE;
1004
2
#endif
1005
2
        break;
1006
1007
1
      case IMAGE_COMDAT_SELECT_ANY:
1008
1
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1009
1
        break;
1010
1011
0
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1012
0
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1013
0
        break;
1014
1015
0
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1016
        /* Not yet fully implemented ??? */
1017
0
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1018
0
        break;
1019
1020
        /* debug$S gets this case; other implications ???  */
1021
1022
        /* There may be no symbol.  We'll search the whole
1023
     table.  Is this the right place to play this game?
1024
     Or should we do it when reading it in?  */
1025
0
      case IMAGE_COMDAT_SELECT_ASSOCIATIVE:
1026
#ifdef STRICT_PE_FORMAT
1027
        /* FIXME: This is not currently implemented.  */
1028
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1029
#else
1030
0
        sec_flags &= ~SEC_LINK_ONCE;
1031
0
#endif
1032
0
        break;
1033
1034
606
      default:  /* 0 means "no symbol" */
1035
        /* debug$F gets this case; other implications ???  */
1036
606
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1037
606
        break;
1038
609
      }
1039
1040
609
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1041
609
    if (*slot == NULL)
1042
0
      return false;
1043
609
    struct comdat_hash_entry *newentry = *slot;
1044
609
    newentry->sec_flags = sec_flags;
1045
609
    newentry->symname = bfd_strdup (symname);
1046
609
    newentry->target_index = isym.n_scnum;
1047
609
    newentry->isym = isym;
1048
609
    newentry->comdat_symbol = -1;
1049
609
  }
1050
2.34k
      else
1051
2.34k
  {
1052
2.34k
    struct comdat_hash_entry *entry = *slot;
1053
1054
2.34k
    if (entry->comdat_symbol != -1)
1055
2.26k
      continue;
1056
1057
84
    char *target_name = strchr (entry->symname, '$');
1058
84
    if (target_name != NULL)
1059
0
      {
1060
        /* Gas mode: the first matching on partial name.  */
1061
1062
0
        target_name += 1;
1063
#ifndef TARGET_UNDERSCORE
1064
#define TARGET_UNDERSCORE 0
1065
#endif
1066
        /* Is this the name we're looking for ?  */
1067
0
        if (strcmp (target_name,
1068
0
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1069
0
    {
1070
      /* Not the name we're looking for */
1071
0
      continue;
1072
0
    }
1073
0
      }
1074
    /* MSVC mode: the lexically second symbol (or drop through
1075
       from the above).  */
1076
    /* This must the second symbol with the section #.  It is
1077
       the actual symbol name.  Intel puts the two adjacent, but
1078
       Alpha (at least) spreads them out.  */
1079
1080
84
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1081
84
    entry->comdat_name = bfd_strdup (symname);
1082
84
  }
1083
2.97k
    }
1084
1085
42
  return true;
1086
42
}
pe-x86_64.c:fill_comdat_hash
Line
Count
Source
890
40
{
891
40
  bfd_byte *esymstart, *esym, *esymend;
892
893
  /* Unfortunately, the PE format stores essential information in the
894
     symbol table, of all places.  We need to extract that information
895
     now, so that objdump and the linker will know how to handle the
896
     section without worrying about the symbols.  We can't call
897
     slurp_symtab, because the linker doesn't want the swapped symbols.  */
898
899
  /* COMDAT sections are special.  The first symbol is the section
900
     symbol, which tells what kind of COMDAT section it is.  The
901
     second symbol is the "comdat symbol" - the one with the unique
902
     name.  GNU uses the section symbol for the unique name; MS uses
903
     ".text" for every comdat section.  Sigh.  - DJ.  */
904
905
  /* This is not mirrored in sec_to_styp_flags(), but there doesn't
906
     seem to be a need to, either, and it would at best be rather messy.  */
907
908
40
  if (! _bfd_coff_get_external_symbols (abfd))
909
0
    return true;
910
911
40
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
912
40
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
913
914
40
  for (struct internal_syment isym;
915
9.69k
       esym < esymend;
916
9.65k
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
917
9.65k
    {
918
9.65k
      char buf[SYMNMLEN + 1];
919
9.65k
      const char *symname;
920
9.65k
      flagword sec_flags = SEC_LINK_ONCE;
921
922
9.65k
      bfd_coff_swap_sym_in (abfd, esym, &isym);
923
924
      /* According to the MSVC documentation, the first TWO entries
925
   with the section # are both of interest to us.  The first one
926
   is the "section symbol" (section name).  The second is the
927
   comdat symbol name.  Here, we've found the first qualifying
928
   entry; we distinguish it from the second with a state flag.
929
930
   In the case of gas-generated (at least until that is fixed)
931
   .o files, it isn't necessarily the second one.  It may be
932
   some other later symbol.
933
934
   Since gas also doesn't follow MS conventions and emits the
935
   section similar to .text$<name>, where <something> is the
936
   name we're looking for, we distinguish the two as follows:
937
938
   If the section name is simply a section name (no $) we
939
   presume it's MS-generated, and look at precisely the second
940
   symbol for the comdat name.  If the section name has a $, we
941
   assume it's gas-generated, and look for <something> (whatever
942
   follows the $) as the comdat symbol.  */
943
944
      /* All 3 branches use this.  */
945
9.65k
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
946
947
      /* PR 17512 file: 078-11867-0.004  */
948
9.65k
      if (symname == NULL)
949
1.91k
  {
950
1.91k
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
951
1.91k
            abfd);
952
1.91k
    continue;
953
1.91k
  }
954
955
7.73k
      union internal_auxent aux;
956
957
7.73k
      struct comdat_hash_entry needle;
958
7.73k
      needle.target_index = isym.n_scnum;
959
960
7.73k
      void **slot
961
7.73k
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
962
7.73k
      if (slot == NULL)
963
0
  return false;
964
965
7.73k
      if (*slot == NULL)
966
1.55k
  {
967
1.55k
    if (isym.n_numaux == 0)
968
892
      aux.x_scn.x_comdat = 0;
969
659
    else
970
659
      {
971
        /* PR 17512: file: e2cfe54f.  */
972
659
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
973
3
    {
974
      /* xgettext:c-format */
975
3
      _bfd_error_handler (_("%pB: warning: no symbol for"
976
3
          " section '%s' found"),
977
3
              abfd, symname);
978
3
      continue;
979
3
    }
980
656
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
981
656
            isym.n_type, isym.n_sclass, 0,
982
656
            isym.n_numaux, &aux);
983
656
      }
984
985
    /* FIXME: Microsoft uses NODUPLICATES and ASSOCIATIVE, but
986
       gnu uses ANY and SAME_SIZE.  Unfortunately, gnu doesn't
987
       do the comdat symbols right.  So, until we can fix it to
988
       do the right thing, we are temporarily disabling comdats
989
       for the MS types (they're used in DLLs and C++, but we
990
       don't support *their* C++ libraries anyway - DJ.  */
991
992
    /* Cygwin does not follow the MS style, and uses ANY and
993
       SAME_SIZE where NODUPLICATES and ASSOCIATIVE should be
994
       used.  For Interix, we just do the right thing up
995
       front.  */
996
997
1.54k
    switch (aux.x_scn.x_comdat)
998
1.54k
      {
999
1
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1000
#ifdef STRICT_PE_FORMAT
1001
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1002
#else
1003
1
        sec_flags &= ~SEC_LINK_ONCE;
1004
1
#endif
1005
1
        break;
1006
1007
1
      case IMAGE_COMDAT_SELECT_ANY:
1008
1
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1009
1
        break;
1010
1011
0
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1012
0
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1013
0
        break;
1014
1015
0
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1016
        /* Not yet fully implemented ??? */
1017
0
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1018
0
        break;
1019
1020
        /* debug$S gets this case; other implications ???  */
1021
1022
        /* There may be no symbol.  We'll search the whole
1023
     table.  Is this the right place to play this game?
1024
     Or should we do it when reading it in?  */
1025
0
      case IMAGE_COMDAT_SELECT_ASSOCIATIVE:
1026
#ifdef STRICT_PE_FORMAT
1027
        /* FIXME: This is not currently implemented.  */
1028
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1029
#else
1030
0
        sec_flags &= ~SEC_LINK_ONCE;
1031
0
#endif
1032
0
        break;
1033
1034
1.54k
      default:  /* 0 means "no symbol" */
1035
        /* debug$F gets this case; other implications ???  */
1036
1.54k
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1037
1.54k
        break;
1038
1.54k
      }
1039
1040
1.54k
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1041
1.54k
    if (*slot == NULL)
1042
0
      return false;
1043
1.54k
    struct comdat_hash_entry *newentry = *slot;
1044
1.54k
    newentry->sec_flags = sec_flags;
1045
1.54k
    newentry->symname = bfd_strdup (symname);
1046
1.54k
    newentry->target_index = isym.n_scnum;
1047
1.54k
    newentry->isym = isym;
1048
1.54k
    newentry->comdat_symbol = -1;
1049
1.54k
  }
1050
6.18k
      else
1051
6.18k
  {
1052
6.18k
    struct comdat_hash_entry *entry = *slot;
1053
1054
6.18k
    if (entry->comdat_symbol != -1)
1055
5.88k
      continue;
1056
1057
306
    char *target_name = strchr (entry->symname, '$');
1058
306
    if (target_name != NULL)
1059
0
      {
1060
        /* Gas mode: the first matching on partial name.  */
1061
1062
0
        target_name += 1;
1063
#ifndef TARGET_UNDERSCORE
1064
#define TARGET_UNDERSCORE 0
1065
#endif
1066
        /* Is this the name we're looking for ?  */
1067
0
        if (strcmp (target_name,
1068
0
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1069
0
    {
1070
      /* Not the name we're looking for */
1071
0
      continue;
1072
0
    }
1073
0
      }
1074
    /* MSVC mode: the lexically second symbol (or drop through
1075
       from the above).  */
1076
    /* This must the second symbol with the section #.  It is
1077
       the actual symbol name.  Intel puts the two adjacent, but
1078
       Alpha (at least) spreads them out.  */
1079
1080
306
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1081
306
    entry->comdat_name = bfd_strdup (symname);
1082
306
  }
1083
7.73k
    }
1084
1085
40
  return true;
1086
40
}
pei-x86_64.c:fill_comdat_hash
Line
Count
Source
890
35
{
891
35
  bfd_byte *esymstart, *esym, *esymend;
892
893
  /* Unfortunately, the PE format stores essential information in the
894
     symbol table, of all places.  We need to extract that information
895
     now, so that objdump and the linker will know how to handle the
896
     section without worrying about the symbols.  We can't call
897
     slurp_symtab, because the linker doesn't want the swapped symbols.  */
898
899
  /* COMDAT sections are special.  The first symbol is the section
900
     symbol, which tells what kind of COMDAT section it is.  The
901
     second symbol is the "comdat symbol" - the one with the unique
902
     name.  GNU uses the section symbol for the unique name; MS uses
903
     ".text" for every comdat section.  Sigh.  - DJ.  */
904
905
  /* This is not mirrored in sec_to_styp_flags(), but there doesn't
906
     seem to be a need to, either, and it would at best be rather messy.  */
907
908
35
  if (! _bfd_coff_get_external_symbols (abfd))
909
0
    return true;
910
911
35
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
912
35
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
913
914
35
  for (struct internal_syment isym;
915
4.22k
       esym < esymend;
916
4.18k
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
917
4.18k
    {
918
4.18k
      char buf[SYMNMLEN + 1];
919
4.18k
      const char *symname;
920
4.18k
      flagword sec_flags = SEC_LINK_ONCE;
921
922
4.18k
      bfd_coff_swap_sym_in (abfd, esym, &isym);
923
924
      /* According to the MSVC documentation, the first TWO entries
925
   with the section # are both of interest to us.  The first one
926
   is the "section symbol" (section name).  The second is the
927
   comdat symbol name.  Here, we've found the first qualifying
928
   entry; we distinguish it from the second with a state flag.
929
930
   In the case of gas-generated (at least until that is fixed)
931
   .o files, it isn't necessarily the second one.  It may be
932
   some other later symbol.
933
934
   Since gas also doesn't follow MS conventions and emits the
935
   section similar to .text$<name>, where <something> is the
936
   name we're looking for, we distinguish the two as follows:
937
938
   If the section name is simply a section name (no $) we
939
   presume it's MS-generated, and look at precisely the second
940
   symbol for the comdat name.  If the section name has a $, we
941
   assume it's gas-generated, and look for <something> (whatever
942
   follows the $) as the comdat symbol.  */
943
944
      /* All 3 branches use this.  */
945
4.18k
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
946
947
      /* PR 17512 file: 078-11867-0.004  */
948
4.18k
      if (symname == NULL)
949
1.21k
  {
950
1.21k
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
951
1.21k
            abfd);
952
1.21k
    continue;
953
1.21k
  }
954
955
2.97k
      union internal_auxent aux;
956
957
2.97k
      struct comdat_hash_entry needle;
958
2.97k
      needle.target_index = isym.n_scnum;
959
960
2.97k
      void **slot
961
2.97k
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
962
2.97k
      if (slot == NULL)
963
0
  return false;
964
965
2.97k
      if (*slot == NULL)
966
680
  {
967
680
    if (isym.n_numaux == 0)
968
430
      aux.x_scn.x_comdat = 0;
969
250
    else
970
250
      {
971
        /* PR 17512: file: e2cfe54f.  */
972
250
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
973
7
    {
974
      /* xgettext:c-format */
975
7
      _bfd_error_handler (_("%pB: warning: no symbol for"
976
7
          " section '%s' found"),
977
7
              abfd, symname);
978
7
      continue;
979
7
    }
980
243
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
981
243
            isym.n_type, isym.n_sclass, 0,
982
243
            isym.n_numaux, &aux);
983
243
      }
984
985
    /* FIXME: Microsoft uses NODUPLICATES and ASSOCIATIVE, but
986
       gnu uses ANY and SAME_SIZE.  Unfortunately, gnu doesn't
987
       do the comdat symbols right.  So, until we can fix it to
988
       do the right thing, we are temporarily disabling comdats
989
       for the MS types (they're used in DLLs and C++, but we
990
       don't support *their* C++ libraries anyway - DJ.  */
991
992
    /* Cygwin does not follow the MS style, and uses ANY and
993
       SAME_SIZE where NODUPLICATES and ASSOCIATIVE should be
994
       used.  For Interix, we just do the right thing up
995
       front.  */
996
997
673
    switch (aux.x_scn.x_comdat)
998
673
      {
999
4
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1000
#ifdef STRICT_PE_FORMAT
1001
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1002
#else
1003
4
        sec_flags &= ~SEC_LINK_ONCE;
1004
4
#endif
1005
4
        break;
1006
1007
0
      case IMAGE_COMDAT_SELECT_ANY:
1008
0
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1009
0
        break;
1010
1011
0
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1012
0
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1013
0
        break;
1014
1015
0
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1016
        /* Not yet fully implemented ??? */
1017
0
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1018
0
        break;
1019
1020
        /* debug$S gets this case; other implications ???  */
1021
1022
        /* There may be no symbol.  We'll search the whole
1023
     table.  Is this the right place to play this game?
1024
     Or should we do it when reading it in?  */
1025
0
      case IMAGE_COMDAT_SELECT_ASSOCIATIVE:
1026
#ifdef STRICT_PE_FORMAT
1027
        /* FIXME: This is not currently implemented.  */
1028
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1029
#else
1030
0
        sec_flags &= ~SEC_LINK_ONCE;
1031
0
#endif
1032
0
        break;
1033
1034
669
      default:  /* 0 means "no symbol" */
1035
        /* debug$F gets this case; other implications ???  */
1036
669
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1037
669
        break;
1038
673
      }
1039
1040
673
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1041
673
    if (*slot == NULL)
1042
0
      return false;
1043
673
    struct comdat_hash_entry *newentry = *slot;
1044
673
    newentry->sec_flags = sec_flags;
1045
673
    newentry->symname = bfd_strdup (symname);
1046
673
    newentry->target_index = isym.n_scnum;
1047
673
    newentry->isym = isym;
1048
673
    newentry->comdat_symbol = -1;
1049
673
  }
1050
2.29k
      else
1051
2.29k
  {
1052
2.29k
    struct comdat_hash_entry *entry = *slot;
1053
1054
2.29k
    if (entry->comdat_symbol != -1)
1055
2.09k
      continue;
1056
1057
201
    char *target_name = strchr (entry->symname, '$');
1058
201
    if (target_name != NULL)
1059
9
      {
1060
        /* Gas mode: the first matching on partial name.  */
1061
1062
9
        target_name += 1;
1063
#ifndef TARGET_UNDERSCORE
1064
#define TARGET_UNDERSCORE 0
1065
#endif
1066
        /* Is this the name we're looking for ?  */
1067
9
        if (strcmp (target_name,
1068
9
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1069
9
    {
1070
      /* Not the name we're looking for */
1071
9
      continue;
1072
9
    }
1073
9
      }
1074
    /* MSVC mode: the lexically second symbol (or drop through
1075
       from the above).  */
1076
    /* This must the second symbol with the section #.  It is
1077
       the actual symbol name.  Intel puts the two adjacent, but
1078
       Alpha (at least) spreads them out.  */
1079
1080
192
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1081
192
    entry->comdat_name = bfd_strdup (symname);
1082
192
  }
1083
2.97k
    }
1084
1085
35
  return true;
1086
35
}
pe-aarch64.c:fill_comdat_hash
Line
Count
Source
890
58
{
891
58
  bfd_byte *esymstart, *esym, *esymend;
892
893
  /* Unfortunately, the PE format stores essential information in the
894
     symbol table, of all places.  We need to extract that information
895
     now, so that objdump and the linker will know how to handle the
896
     section without worrying about the symbols.  We can't call
897
     slurp_symtab, because the linker doesn't want the swapped symbols.  */
898
899
  /* COMDAT sections are special.  The first symbol is the section
900
     symbol, which tells what kind of COMDAT section it is.  The
901
     second symbol is the "comdat symbol" - the one with the unique
902
     name.  GNU uses the section symbol for the unique name; MS uses
903
     ".text" for every comdat section.  Sigh.  - DJ.  */
904
905
  /* This is not mirrored in sec_to_styp_flags(), but there doesn't
906
     seem to be a need to, either, and it would at best be rather messy.  */
907
908
58
  if (! _bfd_coff_get_external_symbols (abfd))
909
1
    return true;
910
911
57
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
912
57
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
913
914
57
  for (struct internal_syment isym;
915
8.27k
       esym < esymend;
916
8.21k
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
917
8.21k
    {
918
8.21k
      char buf[SYMNMLEN + 1];
919
8.21k
      const char *symname;
920
8.21k
      flagword sec_flags = SEC_LINK_ONCE;
921
922
8.21k
      bfd_coff_swap_sym_in (abfd, esym, &isym);
923
924
      /* According to the MSVC documentation, the first TWO entries
925
   with the section # are both of interest to us.  The first one
926
   is the "section symbol" (section name).  The second is the
927
   comdat symbol name.  Here, we've found the first qualifying
928
   entry; we distinguish it from the second with a state flag.
929
930
   In the case of gas-generated (at least until that is fixed)
931
   .o files, it isn't necessarily the second one.  It may be
932
   some other later symbol.
933
934
   Since gas also doesn't follow MS conventions and emits the
935
   section similar to .text$<name>, where <something> is the
936
   name we're looking for, we distinguish the two as follows:
937
938
   If the section name is simply a section name (no $) we
939
   presume it's MS-generated, and look at precisely the second
940
   symbol for the comdat name.  If the section name has a $, we
941
   assume it's gas-generated, and look for <something> (whatever
942
   follows the $) as the comdat symbol.  */
943
944
      /* All 3 branches use this.  */
945
8.21k
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
946
947
      /* PR 17512 file: 078-11867-0.004  */
948
8.21k
      if (symname == NULL)
949
1.63k
  {
950
1.63k
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
951
1.63k
            abfd);
952
1.63k
    continue;
953
1.63k
  }
954
955
6.57k
      union internal_auxent aux;
956
957
6.57k
      struct comdat_hash_entry needle;
958
6.57k
      needle.target_index = isym.n_scnum;
959
960
6.57k
      void **slot
961
6.57k
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
962
6.57k
      if (slot == NULL)
963
0
  return false;
964
965
6.57k
      if (*slot == NULL)
966
1.55k
  {
967
1.55k
    if (isym.n_numaux == 0)
968
586
      aux.x_scn.x_comdat = 0;
969
971
    else
970
971
      {
971
        /* PR 17512: file: e2cfe54f.  */
972
971
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
973
27
    {
974
      /* xgettext:c-format */
975
27
      _bfd_error_handler (_("%pB: warning: no symbol for"
976
27
          " section '%s' found"),
977
27
              abfd, symname);
978
27
      continue;
979
27
    }
980
944
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
981
944
            isym.n_type, isym.n_sclass, 0,
982
944
            isym.n_numaux, &aux);
983
944
      }
984
985
    /* FIXME: Microsoft uses NODUPLICATES and ASSOCIATIVE, but
986
       gnu uses ANY and SAME_SIZE.  Unfortunately, gnu doesn't
987
       do the comdat symbols right.  So, until we can fix it to
988
       do the right thing, we are temporarily disabling comdats
989
       for the MS types (they're used in DLLs and C++, but we
990
       don't support *their* C++ libraries anyway - DJ.  */
991
992
    /* Cygwin does not follow the MS style, and uses ANY and
993
       SAME_SIZE where NODUPLICATES and ASSOCIATIVE should be
994
       used.  For Interix, we just do the right thing up
995
       front.  */
996
997
1.53k
    switch (aux.x_scn.x_comdat)
998
1.53k
      {
999
7
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1000
#ifdef STRICT_PE_FORMAT
1001
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1002
#else
1003
7
        sec_flags &= ~SEC_LINK_ONCE;
1004
7
#endif
1005
7
        break;
1006
1007
0
      case IMAGE_COMDAT_SELECT_ANY:
1008
0
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1009
0
        break;
1010
1011
0
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1012
0
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1013
0
        break;
1014
1015
0
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1016
        /* Not yet fully implemented ??? */
1017
0
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1018
0
        break;
1019
1020
        /* debug$S gets this case; other implications ???  */
1021
1022
        /* There may be no symbol.  We'll search the whole
1023
     table.  Is this the right place to play this game?
1024
     Or should we do it when reading it in?  */
1025
0
      case IMAGE_COMDAT_SELECT_ASSOCIATIVE:
1026
#ifdef STRICT_PE_FORMAT
1027
        /* FIXME: This is not currently implemented.  */
1028
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1029
#else
1030
0
        sec_flags &= ~SEC_LINK_ONCE;
1031
0
#endif
1032
0
        break;
1033
1034
1.52k
      default:  /* 0 means "no symbol" */
1035
        /* debug$F gets this case; other implications ???  */
1036
1.52k
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1037
1.52k
        break;
1038
1.53k
      }
1039
1040
1.53k
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1041
1.53k
    if (*slot == NULL)
1042
0
      return false;
1043
1.53k
    struct comdat_hash_entry *newentry = *slot;
1044
1.53k
    newentry->sec_flags = sec_flags;
1045
1.53k
    newentry->symname = bfd_strdup (symname);
1046
1.53k
    newentry->target_index = isym.n_scnum;
1047
1.53k
    newentry->isym = isym;
1048
1.53k
    newentry->comdat_symbol = -1;
1049
1.53k
  }
1050
5.01k
      else
1051
5.01k
  {
1052
5.01k
    struct comdat_hash_entry *entry = *slot;
1053
1054
5.01k
    if (entry->comdat_symbol != -1)
1055
4.47k
      continue;
1056
1057
540
    char *target_name = strchr (entry->symname, '$');
1058
540
    if (target_name != NULL)
1059
296
      {
1060
        /* Gas mode: the first matching on partial name.  */
1061
1062
296
        target_name += 1;
1063
296
#ifndef TARGET_UNDERSCORE
1064
296
#define TARGET_UNDERSCORE 0
1065
296
#endif
1066
        /* Is this the name we're looking for ?  */
1067
296
        if (strcmp (target_name,
1068
296
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1069
296
    {
1070
      /* Not the name we're looking for */
1071
296
      continue;
1072
296
    }
1073
296
      }
1074
    /* MSVC mode: the lexically second symbol (or drop through
1075
       from the above).  */
1076
    /* This must the second symbol with the section #.  It is
1077
       the actual symbol name.  Intel puts the two adjacent, but
1078
       Alpha (at least) spreads them out.  */
1079
1080
244
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1081
244
    entry->comdat_name = bfd_strdup (symname);
1082
244
  }
1083
6.57k
    }
1084
1085
57
  return true;
1086
57
}
pei-aarch64.c:fill_comdat_hash
Line
Count
Source
890
47
{
891
47
  bfd_byte *esymstart, *esym, *esymend;
892
893
  /* Unfortunately, the PE format stores essential information in the
894
     symbol table, of all places.  We need to extract that information
895
     now, so that objdump and the linker will know how to handle the
896
     section without worrying about the symbols.  We can't call
897
     slurp_symtab, because the linker doesn't want the swapped symbols.  */
898
899
  /* COMDAT sections are special.  The first symbol is the section
900
     symbol, which tells what kind of COMDAT section it is.  The
901
     second symbol is the "comdat symbol" - the one with the unique
902
     name.  GNU uses the section symbol for the unique name; MS uses
903
     ".text" for every comdat section.  Sigh.  - DJ.  */
904
905
  /* This is not mirrored in sec_to_styp_flags(), but there doesn't
906
     seem to be a need to, either, and it would at best be rather messy.  */
907
908
47
  if (! _bfd_coff_get_external_symbols (abfd))
909
2
    return true;
910
911
45
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
912
45
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
913
914
45
  for (struct internal_syment isym;
915
20.4k
       esym < esymend;
916
20.4k
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
917
20.4k
    {
918
20.4k
      char buf[SYMNMLEN + 1];
919
20.4k
      const char *symname;
920
20.4k
      flagword sec_flags = SEC_LINK_ONCE;
921
922
20.4k
      bfd_coff_swap_sym_in (abfd, esym, &isym);
923
924
      /* According to the MSVC documentation, the first TWO entries
925
   with the section # are both of interest to us.  The first one
926
   is the "section symbol" (section name).  The second is the
927
   comdat symbol name.  Here, we've found the first qualifying
928
   entry; we distinguish it from the second with a state flag.
929
930
   In the case of gas-generated (at least until that is fixed)
931
   .o files, it isn't necessarily the second one.  It may be
932
   some other later symbol.
933
934
   Since gas also doesn't follow MS conventions and emits the
935
   section similar to .text$<name>, where <something> is the
936
   name we're looking for, we distinguish the two as follows:
937
938
   If the section name is simply a section name (no $) we
939
   presume it's MS-generated, and look at precisely the second
940
   symbol for the comdat name.  If the section name has a $, we
941
   assume it's gas-generated, and look for <something> (whatever
942
   follows the $) as the comdat symbol.  */
943
944
      /* All 3 branches use this.  */
945
20.4k
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
946
947
      /* PR 17512 file: 078-11867-0.004  */
948
20.4k
      if (symname == NULL)
949
3.97k
  {
950
3.97k
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
951
3.97k
            abfd);
952
3.97k
    continue;
953
3.97k
  }
954
955
16.4k
      union internal_auxent aux;
956
957
16.4k
      struct comdat_hash_entry needle;
958
16.4k
      needle.target_index = isym.n_scnum;
959
960
16.4k
      void **slot
961
16.4k
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
962
16.4k
      if (slot == NULL)
963
0
  return false;
964
965
16.4k
      if (*slot == NULL)
966
1.32k
  {
967
1.32k
    if (isym.n_numaux == 0)
968
738
      aux.x_scn.x_comdat = 0;
969
587
    else
970
587
      {
971
        /* PR 17512: file: e2cfe54f.  */
972
587
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
973
15
    {
974
      /* xgettext:c-format */
975
15
      _bfd_error_handler (_("%pB: warning: no symbol for"
976
15
          " section '%s' found"),
977
15
              abfd, symname);
978
15
      continue;
979
15
    }
980
572
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
981
572
            isym.n_type, isym.n_sclass, 0,
982
572
            isym.n_numaux, &aux);
983
572
      }
984
985
    /* FIXME: Microsoft uses NODUPLICATES and ASSOCIATIVE, but
986
       gnu uses ANY and SAME_SIZE.  Unfortunately, gnu doesn't
987
       do the comdat symbols right.  So, until we can fix it to
988
       do the right thing, we are temporarily disabling comdats
989
       for the MS types (they're used in DLLs and C++, but we
990
       don't support *their* C++ libraries anyway - DJ.  */
991
992
    /* Cygwin does not follow the MS style, and uses ANY and
993
       SAME_SIZE where NODUPLICATES and ASSOCIATIVE should be
994
       used.  For Interix, we just do the right thing up
995
       front.  */
996
997
1.31k
    switch (aux.x_scn.x_comdat)
998
1.31k
      {
999
10
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1000
#ifdef STRICT_PE_FORMAT
1001
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1002
#else
1003
10
        sec_flags &= ~SEC_LINK_ONCE;
1004
10
#endif
1005
10
        break;
1006
1007
0
      case IMAGE_COMDAT_SELECT_ANY:
1008
0
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1009
0
        break;
1010
1011
0
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1012
0
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1013
0
        break;
1014
1015
0
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1016
        /* Not yet fully implemented ??? */
1017
0
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1018
0
        break;
1019
1020
        /* debug$S gets this case; other implications ???  */
1021
1022
        /* There may be no symbol.  We'll search the whole
1023
     table.  Is this the right place to play this game?
1024
     Or should we do it when reading it in?  */
1025
0
      case IMAGE_COMDAT_SELECT_ASSOCIATIVE:
1026
#ifdef STRICT_PE_FORMAT
1027
        /* FIXME: This is not currently implemented.  */
1028
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1029
#else
1030
0
        sec_flags &= ~SEC_LINK_ONCE;
1031
0
#endif
1032
0
        break;
1033
1034
1.30k
      default:  /* 0 means "no symbol" */
1035
        /* debug$F gets this case; other implications ???  */
1036
1.30k
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1037
1.30k
        break;
1038
1.31k
      }
1039
1040
1.31k
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1041
1.31k
    if (*slot == NULL)
1042
0
      return false;
1043
1.31k
    struct comdat_hash_entry *newentry = *slot;
1044
1.31k
    newentry->sec_flags = sec_flags;
1045
1.31k
    newentry->symname = bfd_strdup (symname);
1046
1.31k
    newentry->target_index = isym.n_scnum;
1047
1.31k
    newentry->isym = isym;
1048
1.31k
    newentry->comdat_symbol = -1;
1049
1.31k
  }
1050
15.1k
      else
1051
15.1k
  {
1052
15.1k
    struct comdat_hash_entry *entry = *slot;
1053
1054
15.1k
    if (entry->comdat_symbol != -1)
1055
14.8k
      continue;
1056
1057
347
    char *target_name = strchr (entry->symname, '$');
1058
347
    if (target_name != NULL)
1059
0
      {
1060
        /* Gas mode: the first matching on partial name.  */
1061
1062
0
        target_name += 1;
1063
0
#ifndef TARGET_UNDERSCORE
1064
0
#define TARGET_UNDERSCORE 0
1065
0
#endif
1066
        /* Is this the name we're looking for ?  */
1067
0
        if (strcmp (target_name,
1068
0
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1069
0
    {
1070
      /* Not the name we're looking for */
1071
0
      continue;
1072
0
    }
1073
0
      }
1074
    /* MSVC mode: the lexically second symbol (or drop through
1075
       from the above).  */
1076
    /* This must the second symbol with the section #.  It is
1077
       the actual symbol name.  Intel puts the two adjacent, but
1078
       Alpha (at least) spreads them out.  */
1079
1080
347
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1081
347
    entry->comdat_name = bfd_strdup (symname);
1082
347
  }
1083
16.4k
    }
1084
1085
45
  return true;
1086
45
}
pei-ia64.c:fill_comdat_hash
Line
Count
Source
890
10
{
891
10
  bfd_byte *esymstart, *esym, *esymend;
892
893
  /* Unfortunately, the PE format stores essential information in the
894
     symbol table, of all places.  We need to extract that information
895
     now, so that objdump and the linker will know how to handle the
896
     section without worrying about the symbols.  We can't call
897
     slurp_symtab, because the linker doesn't want the swapped symbols.  */
898
899
  /* COMDAT sections are special.  The first symbol is the section
900
     symbol, which tells what kind of COMDAT section it is.  The
901
     second symbol is the "comdat symbol" - the one with the unique
902
     name.  GNU uses the section symbol for the unique name; MS uses
903
     ".text" for every comdat section.  Sigh.  - DJ.  */
904
905
  /* This is not mirrored in sec_to_styp_flags(), but there doesn't
906
     seem to be a need to, either, and it would at best be rather messy.  */
907
908
10
  if (! _bfd_coff_get_external_symbols (abfd))
909
0
    return true;
910
911
10
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
912
10
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
913
914
10
  for (struct internal_syment isym;
915
2.12k
       esym < esymend;
916
2.11k
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
917
2.11k
    {
918
2.11k
      char buf[SYMNMLEN + 1];
919
2.11k
      const char *symname;
920
2.11k
      flagword sec_flags = SEC_LINK_ONCE;
921
922
2.11k
      bfd_coff_swap_sym_in (abfd, esym, &isym);
923
924
      /* According to the MSVC documentation, the first TWO entries
925
   with the section # are both of interest to us.  The first one
926
   is the "section symbol" (section name).  The second is the
927
   comdat symbol name.  Here, we've found the first qualifying
928
   entry; we distinguish it from the second with a state flag.
929
930
   In the case of gas-generated (at least until that is fixed)
931
   .o files, it isn't necessarily the second one.  It may be
932
   some other later symbol.
933
934
   Since gas also doesn't follow MS conventions and emits the
935
   section similar to .text$<name>, where <something> is the
936
   name we're looking for, we distinguish the two as follows:
937
938
   If the section name is simply a section name (no $) we
939
   presume it's MS-generated, and look at precisely the second
940
   symbol for the comdat name.  If the section name has a $, we
941
   assume it's gas-generated, and look for <something> (whatever
942
   follows the $) as the comdat symbol.  */
943
944
      /* All 3 branches use this.  */
945
2.11k
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
946
947
      /* PR 17512 file: 078-11867-0.004  */
948
2.11k
      if (symname == NULL)
949
442
  {
950
442
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
951
442
            abfd);
952
442
    continue;
953
442
  }
954
955
1.67k
      union internal_auxent aux;
956
957
1.67k
      struct comdat_hash_entry needle;
958
1.67k
      needle.target_index = isym.n_scnum;
959
960
1.67k
      void **slot
961
1.67k
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
962
1.67k
      if (slot == NULL)
963
0
  return false;
964
965
1.67k
      if (*slot == NULL)
966
302
  {
967
302
    if (isym.n_numaux == 0)
968
126
      aux.x_scn.x_comdat = 0;
969
176
    else
970
176
      {
971
        /* PR 17512: file: e2cfe54f.  */
972
176
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
973
6
    {
974
      /* xgettext:c-format */
975
6
      _bfd_error_handler (_("%pB: warning: no symbol for"
976
6
          " section '%s' found"),
977
6
              abfd, symname);
978
6
      continue;
979
6
    }
980
170
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
981
170
            isym.n_type, isym.n_sclass, 0,
982
170
            isym.n_numaux, &aux);
983
170
      }
984
985
    /* FIXME: Microsoft uses NODUPLICATES and ASSOCIATIVE, but
986
       gnu uses ANY and SAME_SIZE.  Unfortunately, gnu doesn't
987
       do the comdat symbols right.  So, until we can fix it to
988
       do the right thing, we are temporarily disabling comdats
989
       for the MS types (they're used in DLLs and C++, but we
990
       don't support *their* C++ libraries anyway - DJ.  */
991
992
    /* Cygwin does not follow the MS style, and uses ANY and
993
       SAME_SIZE where NODUPLICATES and ASSOCIATIVE should be
994
       used.  For Interix, we just do the right thing up
995
       front.  */
996
997
296
    switch (aux.x_scn.x_comdat)
998
296
      {
999
2
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1000
#ifdef STRICT_PE_FORMAT
1001
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1002
#else
1003
2
        sec_flags &= ~SEC_LINK_ONCE;
1004
2
#endif
1005
2
        break;
1006
1007
0
      case IMAGE_COMDAT_SELECT_ANY:
1008
0
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1009
0
        break;
1010
1011
0
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1012
0
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1013
0
        break;
1014
1015
0
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1016
        /* Not yet fully implemented ??? */
1017
0
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1018
0
        break;
1019
1020
        /* debug$S gets this case; other implications ???  */
1021
1022
        /* There may be no symbol.  We'll search the whole
1023
     table.  Is this the right place to play this game?
1024
     Or should we do it when reading it in?  */
1025
0
      case IMAGE_COMDAT_SELECT_ASSOCIATIVE:
1026
#ifdef STRICT_PE_FORMAT
1027
        /* FIXME: This is not currently implemented.  */
1028
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1029
#else
1030
0
        sec_flags &= ~SEC_LINK_ONCE;
1031
0
#endif
1032
0
        break;
1033
1034
294
      default:  /* 0 means "no symbol" */
1035
        /* debug$F gets this case; other implications ???  */
1036
294
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1037
294
        break;
1038
296
      }
1039
1040
296
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1041
296
    if (*slot == NULL)
1042
0
      return false;
1043
296
    struct comdat_hash_entry *newentry = *slot;
1044
296
    newentry->sec_flags = sec_flags;
1045
296
    newentry->symname = bfd_strdup (symname);
1046
296
    newentry->target_index = isym.n_scnum;
1047
296
    newentry->isym = isym;
1048
296
    newentry->comdat_symbol = -1;
1049
296
  }
1050
1.37k
      else
1051
1.37k
  {
1052
1.37k
    struct comdat_hash_entry *entry = *slot;
1053
1054
1.37k
    if (entry->comdat_symbol != -1)
1055
1.31k
      continue;
1056
1057
56
    char *target_name = strchr (entry->symname, '$');
1058
56
    if (target_name != NULL)
1059
0
      {
1060
        /* Gas mode: the first matching on partial name.  */
1061
1062
0
        target_name += 1;
1063
#ifndef TARGET_UNDERSCORE
1064
#define TARGET_UNDERSCORE 0
1065
#endif
1066
        /* Is this the name we're looking for ?  */
1067
0
        if (strcmp (target_name,
1068
0
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1069
0
    {
1070
      /* Not the name we're looking for */
1071
0
      continue;
1072
0
    }
1073
0
      }
1074
    /* MSVC mode: the lexically second symbol (or drop through
1075
       from the above).  */
1076
    /* This must the second symbol with the section #.  It is
1077
       the actual symbol name.  Intel puts the two adjacent, but
1078
       Alpha (at least) spreads them out.  */
1079
1080
56
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1081
56
    entry->comdat_name = bfd_strdup (symname);
1082
56
  }
1083
1.67k
    }
1084
1085
10
  return true;
1086
10
}
pei-loongarch64.c:fill_comdat_hash
Line
Count
Source
890
63
{
891
63
  bfd_byte *esymstart, *esym, *esymend;
892
893
  /* Unfortunately, the PE format stores essential information in the
894
     symbol table, of all places.  We need to extract that information
895
     now, so that objdump and the linker will know how to handle the
896
     section without worrying about the symbols.  We can't call
897
     slurp_symtab, because the linker doesn't want the swapped symbols.  */
898
899
  /* COMDAT sections are special.  The first symbol is the section
900
     symbol, which tells what kind of COMDAT section it is.  The
901
     second symbol is the "comdat symbol" - the one with the unique
902
     name.  GNU uses the section symbol for the unique name; MS uses
903
     ".text" for every comdat section.  Sigh.  - DJ.  */
904
905
  /* This is not mirrored in sec_to_styp_flags(), but there doesn't
906
     seem to be a need to, either, and it would at best be rather messy.  */
907
908
63
  if (! _bfd_coff_get_external_symbols (abfd))
909
0
    return true;
910
911
63
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
912
63
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
913
914
63
  for (struct internal_syment isym;
915
8.67k
       esym < esymend;
916
8.61k
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
917
8.61k
    {
918
8.61k
      char buf[SYMNMLEN + 1];
919
8.61k
      const char *symname;
920
8.61k
      flagword sec_flags = SEC_LINK_ONCE;
921
922
8.61k
      bfd_coff_swap_sym_in (abfd, esym, &isym);
923
924
      /* According to the MSVC documentation, the first TWO entries
925
   with the section # are both of interest to us.  The first one
926
   is the "section symbol" (section name).  The second is the
927
   comdat symbol name.  Here, we've found the first qualifying
928
   entry; we distinguish it from the second with a state flag.
929
930
   In the case of gas-generated (at least until that is fixed)
931
   .o files, it isn't necessarily the second one.  It may be
932
   some other later symbol.
933
934
   Since gas also doesn't follow MS conventions and emits the
935
   section similar to .text$<name>, where <something> is the
936
   name we're looking for, we distinguish the two as follows:
937
938
   If the section name is simply a section name (no $) we
939
   presume it's MS-generated, and look at precisely the second
940
   symbol for the comdat name.  If the section name has a $, we
941
   assume it's gas-generated, and look for <something> (whatever
942
   follows the $) as the comdat symbol.  */
943
944
      /* All 3 branches use this.  */
945
8.61k
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
946
947
      /* PR 17512 file: 078-11867-0.004  */
948
8.61k
      if (symname == NULL)
949
3.09k
  {
950
3.09k
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
951
3.09k
            abfd);
952
3.09k
    continue;
953
3.09k
  }
954
955
5.52k
      union internal_auxent aux;
956
957
5.52k
      struct comdat_hash_entry needle;
958
5.52k
      needle.target_index = isym.n_scnum;
959
960
5.52k
      void **slot
961
5.52k
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
962
5.52k
      if (slot == NULL)
963
0
  return false;
964
965
5.52k
      if (*slot == NULL)
966
1.40k
  {
967
1.40k
    if (isym.n_numaux == 0)
968
663
      aux.x_scn.x_comdat = 0;
969
743
    else
970
743
      {
971
        /* PR 17512: file: e2cfe54f.  */
972
743
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
973
26
    {
974
      /* xgettext:c-format */
975
26
      _bfd_error_handler (_("%pB: warning: no symbol for"
976
26
          " section '%s' found"),
977
26
              abfd, symname);
978
26
      continue;
979
26
    }
980
717
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
981
717
            isym.n_type, isym.n_sclass, 0,
982
717
            isym.n_numaux, &aux);
983
717
      }
984
985
    /* FIXME: Microsoft uses NODUPLICATES and ASSOCIATIVE, but
986
       gnu uses ANY and SAME_SIZE.  Unfortunately, gnu doesn't
987
       do the comdat symbols right.  So, until we can fix it to
988
       do the right thing, we are temporarily disabling comdats
989
       for the MS types (they're used in DLLs and C++, but we
990
       don't support *their* C++ libraries anyway - DJ.  */
991
992
    /* Cygwin does not follow the MS style, and uses ANY and
993
       SAME_SIZE where NODUPLICATES and ASSOCIATIVE should be
994
       used.  For Interix, we just do the right thing up
995
       front.  */
996
997
1.38k
    switch (aux.x_scn.x_comdat)
998
1.38k
      {
999
7
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1000
#ifdef STRICT_PE_FORMAT
1001
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1002
#else
1003
7
        sec_flags &= ~SEC_LINK_ONCE;
1004
7
#endif
1005
7
        break;
1006
1007
0
      case IMAGE_COMDAT_SELECT_ANY:
1008
0
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1009
0
        break;
1010
1011
0
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1012
0
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1013
0
        break;
1014
1015
0
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1016
        /* Not yet fully implemented ??? */
1017
0
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1018
0
        break;
1019
1020
        /* debug$S gets this case; other implications ???  */
1021
1022
        /* There may be no symbol.  We'll search the whole
1023
     table.  Is this the right place to play this game?
1024
     Or should we do it when reading it in?  */
1025
0
      case IMAGE_COMDAT_SELECT_ASSOCIATIVE:
1026
#ifdef STRICT_PE_FORMAT
1027
        /* FIXME: This is not currently implemented.  */
1028
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1029
#else
1030
0
        sec_flags &= ~SEC_LINK_ONCE;
1031
0
#endif
1032
0
        break;
1033
1034
1.37k
      default:  /* 0 means "no symbol" */
1035
        /* debug$F gets this case; other implications ???  */
1036
1.37k
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1037
1.37k
        break;
1038
1.38k
      }
1039
1040
1.38k
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1041
1.38k
    if (*slot == NULL)
1042
0
      return false;
1043
1.38k
    struct comdat_hash_entry *newentry = *slot;
1044
1.38k
    newentry->sec_flags = sec_flags;
1045
1.38k
    newentry->symname = bfd_strdup (symname);
1046
1.38k
    newentry->target_index = isym.n_scnum;
1047
1.38k
    newentry->isym = isym;
1048
1.38k
    newentry->comdat_symbol = -1;
1049
1.38k
  }
1050
4.11k
      else
1051
4.11k
  {
1052
4.11k
    struct comdat_hash_entry *entry = *slot;
1053
1054
4.11k
    if (entry->comdat_symbol != -1)
1055
3.82k
      continue;
1056
1057
287
    char *target_name = strchr (entry->symname, '$');
1058
287
    if (target_name != NULL)
1059
27
      {
1060
        /* Gas mode: the first matching on partial name.  */
1061
1062
27
        target_name += 1;
1063
27
#ifndef TARGET_UNDERSCORE
1064
27
#define TARGET_UNDERSCORE 0
1065
27
#endif
1066
        /* Is this the name we're looking for ?  */
1067
27
        if (strcmp (target_name,
1068
27
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1069
26
    {
1070
      /* Not the name we're looking for */
1071
26
      continue;
1072
26
    }
1073
27
      }
1074
    /* MSVC mode: the lexically second symbol (or drop through
1075
       from the above).  */
1076
    /* This must the second symbol with the section #.  It is
1077
       the actual symbol name.  Intel puts the two adjacent, but
1078
       Alpha (at least) spreads them out.  */
1079
1080
261
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1081
261
    entry->comdat_name = bfd_strdup (symname);
1082
261
  }
1083
5.52k
    }
1084
1085
63
  return true;
1086
63
}
pe-arm-wince.c:fill_comdat_hash
Line
Count
Source
890
4
{
891
4
  bfd_byte *esymstart, *esym, *esymend;
892
893
  /* Unfortunately, the PE format stores essential information in the
894
     symbol table, of all places.  We need to extract that information
895
     now, so that objdump and the linker will know how to handle the
896
     section without worrying about the symbols.  We can't call
897
     slurp_symtab, because the linker doesn't want the swapped symbols.  */
898
899
  /* COMDAT sections are special.  The first symbol is the section
900
     symbol, which tells what kind of COMDAT section it is.  The
901
     second symbol is the "comdat symbol" - the one with the unique
902
     name.  GNU uses the section symbol for the unique name; MS uses
903
     ".text" for every comdat section.  Sigh.  - DJ.  */
904
905
  /* This is not mirrored in sec_to_styp_flags(), but there doesn't
906
     seem to be a need to, either, and it would at best be rather messy.  */
907
908
4
  if (! _bfd_coff_get_external_symbols (abfd))
909
0
    return true;
910
911
4
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
912
4
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
913
914
4
  for (struct internal_syment isym;
915
280
       esym < esymend;
916
276
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
917
276
    {
918
276
      char buf[SYMNMLEN + 1];
919
276
      const char *symname;
920
276
      flagword sec_flags = SEC_LINK_ONCE;
921
922
276
      bfd_coff_swap_sym_in (abfd, esym, &isym);
923
924
      /* According to the MSVC documentation, the first TWO entries
925
   with the section # are both of interest to us.  The first one
926
   is the "section symbol" (section name).  The second is the
927
   comdat symbol name.  Here, we've found the first qualifying
928
   entry; we distinguish it from the second with a state flag.
929
930
   In the case of gas-generated (at least until that is fixed)
931
   .o files, it isn't necessarily the second one.  It may be
932
   some other later symbol.
933
934
   Since gas also doesn't follow MS conventions and emits the
935
   section similar to .text$<name>, where <something> is the
936
   name we're looking for, we distinguish the two as follows:
937
938
   If the section name is simply a section name (no $) we
939
   presume it's MS-generated, and look at precisely the second
940
   symbol for the comdat name.  If the section name has a $, we
941
   assume it's gas-generated, and look for <something> (whatever
942
   follows the $) as the comdat symbol.  */
943
944
      /* All 3 branches use this.  */
945
276
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
946
947
      /* PR 17512 file: 078-11867-0.004  */
948
276
      if (symname == NULL)
949
3
  {
950
3
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
951
3
            abfd);
952
3
    continue;
953
3
  }
954
955
273
      union internal_auxent aux;
956
957
273
      struct comdat_hash_entry needle;
958
273
      needle.target_index = isym.n_scnum;
959
960
273
      void **slot
961
273
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
962
273
      if (slot == NULL)
963
0
  return false;
964
965
273
      if (*slot == NULL)
966
13
  {
967
13
    if (isym.n_numaux == 0)
968
7
      aux.x_scn.x_comdat = 0;
969
6
    else
970
6
      {
971
        /* PR 17512: file: e2cfe54f.  */
972
6
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
973
0
    {
974
      /* xgettext:c-format */
975
0
      _bfd_error_handler (_("%pB: warning: no symbol for"
976
0
          " section '%s' found"),
977
0
              abfd, symname);
978
0
      continue;
979
0
    }
980
6
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
981
6
            isym.n_type, isym.n_sclass, 0,
982
6
            isym.n_numaux, &aux);
983
6
      }
984
985
    /* FIXME: Microsoft uses NODUPLICATES and ASSOCIATIVE, but
986
       gnu uses ANY and SAME_SIZE.  Unfortunately, gnu doesn't
987
       do the comdat symbols right.  So, until we can fix it to
988
       do the right thing, we are temporarily disabling comdats
989
       for the MS types (they're used in DLLs and C++, but we
990
       don't support *their* C++ libraries anyway - DJ.  */
991
992
    /* Cygwin does not follow the MS style, and uses ANY and
993
       SAME_SIZE where NODUPLICATES and ASSOCIATIVE should be
994
       used.  For Interix, we just do the right thing up
995
       front.  */
996
997
13
    switch (aux.x_scn.x_comdat)
998
13
      {
999
0
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1000
#ifdef STRICT_PE_FORMAT
1001
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1002
#else
1003
0
        sec_flags &= ~SEC_LINK_ONCE;
1004
0
#endif
1005
0
        break;
1006
1007
0
      case IMAGE_COMDAT_SELECT_ANY:
1008
0
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1009
0
        break;
1010
1011
0
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1012
0
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1013
0
        break;
1014
1015
0
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1016
        /* Not yet fully implemented ??? */
1017
0
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1018
0
        break;
1019
1020
        /* debug$S gets this case; other implications ???  */
1021
1022
        /* There may be no symbol.  We'll search the whole
1023
     table.  Is this the right place to play this game?
1024
     Or should we do it when reading it in?  */
1025
0
      case IMAGE_COMDAT_SELECT_ASSOCIATIVE:
1026
#ifdef STRICT_PE_FORMAT
1027
        /* FIXME: This is not currently implemented.  */
1028
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1029
#else
1030
0
        sec_flags &= ~SEC_LINK_ONCE;
1031
0
#endif
1032
0
        break;
1033
1034
13
      default:  /* 0 means "no symbol" */
1035
        /* debug$F gets this case; other implications ???  */
1036
13
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1037
13
        break;
1038
13
      }
1039
1040
13
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1041
13
    if (*slot == NULL)
1042
0
      return false;
1043
13
    struct comdat_hash_entry *newentry = *slot;
1044
13
    newentry->sec_flags = sec_flags;
1045
13
    newentry->symname = bfd_strdup (symname);
1046
13
    newentry->target_index = isym.n_scnum;
1047
13
    newentry->isym = isym;
1048
13
    newentry->comdat_symbol = -1;
1049
13
  }
1050
260
      else
1051
260
  {
1052
260
    struct comdat_hash_entry *entry = *slot;
1053
1054
260
    if (entry->comdat_symbol != -1)
1055
253
      continue;
1056
1057
7
    char *target_name = strchr (entry->symname, '$');
1058
7
    if (target_name != NULL)
1059
0
      {
1060
        /* Gas mode: the first matching on partial name.  */
1061
1062
0
        target_name += 1;
1063
#ifndef TARGET_UNDERSCORE
1064
#define TARGET_UNDERSCORE 0
1065
#endif
1066
        /* Is this the name we're looking for ?  */
1067
0
        if (strcmp (target_name,
1068
0
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1069
0
    {
1070
      /* Not the name we're looking for */
1071
0
      continue;
1072
0
    }
1073
0
      }
1074
    /* MSVC mode: the lexically second symbol (or drop through
1075
       from the above).  */
1076
    /* This must the second symbol with the section #.  It is
1077
       the actual symbol name.  Intel puts the two adjacent, but
1078
       Alpha (at least) spreads them out.  */
1079
1080
7
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1081
7
    entry->comdat_name = bfd_strdup (symname);
1082
7
  }
1083
273
    }
1084
1085
4
  return true;
1086
4
}
pe-arm.c:fill_comdat_hash
Line
Count
Source
890
4
{
891
4
  bfd_byte *esymstart, *esym, *esymend;
892
893
  /* Unfortunately, the PE format stores essential information in the
894
     symbol table, of all places.  We need to extract that information
895
     now, so that objdump and the linker will know how to handle the
896
     section without worrying about the symbols.  We can't call
897
     slurp_symtab, because the linker doesn't want the swapped symbols.  */
898
899
  /* COMDAT sections are special.  The first symbol is the section
900
     symbol, which tells what kind of COMDAT section it is.  The
901
     second symbol is the "comdat symbol" - the one with the unique
902
     name.  GNU uses the section symbol for the unique name; MS uses
903
     ".text" for every comdat section.  Sigh.  - DJ.  */
904
905
  /* This is not mirrored in sec_to_styp_flags(), but there doesn't
906
     seem to be a need to, either, and it would at best be rather messy.  */
907
908
4
  if (! _bfd_coff_get_external_symbols (abfd))
909
0
    return true;
910
911
4
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
912
4
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
913
914
4
  for (struct internal_syment isym;
915
280
       esym < esymend;
916
276
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
917
276
    {
918
276
      char buf[SYMNMLEN + 1];
919
276
      const char *symname;
920
276
      flagword sec_flags = SEC_LINK_ONCE;
921
922
276
      bfd_coff_swap_sym_in (abfd, esym, &isym);
923
924
      /* According to the MSVC documentation, the first TWO entries
925
   with the section # are both of interest to us.  The first one
926
   is the "section symbol" (section name).  The second is the
927
   comdat symbol name.  Here, we've found the first qualifying
928
   entry; we distinguish it from the second with a state flag.
929
930
   In the case of gas-generated (at least until that is fixed)
931
   .o files, it isn't necessarily the second one.  It may be
932
   some other later symbol.
933
934
   Since gas also doesn't follow MS conventions and emits the
935
   section similar to .text$<name>, where <something> is the
936
   name we're looking for, we distinguish the two as follows:
937
938
   If the section name is simply a section name (no $) we
939
   presume it's MS-generated, and look at precisely the second
940
   symbol for the comdat name.  If the section name has a $, we
941
   assume it's gas-generated, and look for <something> (whatever
942
   follows the $) as the comdat symbol.  */
943
944
      /* All 3 branches use this.  */
945
276
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
946
947
      /* PR 17512 file: 078-11867-0.004  */
948
276
      if (symname == NULL)
949
3
  {
950
3
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
951
3
            abfd);
952
3
    continue;
953
3
  }
954
955
273
      union internal_auxent aux;
956
957
273
      struct comdat_hash_entry needle;
958
273
      needle.target_index = isym.n_scnum;
959
960
273
      void **slot
961
273
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
962
273
      if (slot == NULL)
963
0
  return false;
964
965
273
      if (*slot == NULL)
966
13
  {
967
13
    if (isym.n_numaux == 0)
968
7
      aux.x_scn.x_comdat = 0;
969
6
    else
970
6
      {
971
        /* PR 17512: file: e2cfe54f.  */
972
6
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
973
0
    {
974
      /* xgettext:c-format */
975
0
      _bfd_error_handler (_("%pB: warning: no symbol for"
976
0
          " section '%s' found"),
977
0
              abfd, symname);
978
0
      continue;
979
0
    }
980
6
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
981
6
            isym.n_type, isym.n_sclass, 0,
982
6
            isym.n_numaux, &aux);
983
6
      }
984
985
    /* FIXME: Microsoft uses NODUPLICATES and ASSOCIATIVE, but
986
       gnu uses ANY and SAME_SIZE.  Unfortunately, gnu doesn't
987
       do the comdat symbols right.  So, until we can fix it to
988
       do the right thing, we are temporarily disabling comdats
989
       for the MS types (they're used in DLLs and C++, but we
990
       don't support *their* C++ libraries anyway - DJ.  */
991
992
    /* Cygwin does not follow the MS style, and uses ANY and
993
       SAME_SIZE where NODUPLICATES and ASSOCIATIVE should be
994
       used.  For Interix, we just do the right thing up
995
       front.  */
996
997
13
    switch (aux.x_scn.x_comdat)
998
13
      {
999
0
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1000
#ifdef STRICT_PE_FORMAT
1001
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1002
#else
1003
0
        sec_flags &= ~SEC_LINK_ONCE;
1004
0
#endif
1005
0
        break;
1006
1007
0
      case IMAGE_COMDAT_SELECT_ANY:
1008
0
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1009
0
        break;
1010
1011
0
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1012
0
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1013
0
        break;
1014
1015
0
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1016
        /* Not yet fully implemented ??? */
1017
0
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1018
0
        break;
1019
1020
        /* debug$S gets this case; other implications ???  */
1021
1022
        /* There may be no symbol.  We'll search the whole
1023
     table.  Is this the right place to play this game?
1024
     Or should we do it when reading it in?  */
1025
0
      case IMAGE_COMDAT_SELECT_ASSOCIATIVE:
1026
#ifdef STRICT_PE_FORMAT
1027
        /* FIXME: This is not currently implemented.  */
1028
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1029
#else
1030
0
        sec_flags &= ~SEC_LINK_ONCE;
1031
0
#endif
1032
0
        break;
1033
1034
13
      default:  /* 0 means "no symbol" */
1035
        /* debug$F gets this case; other implications ???  */
1036
13
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1037
13
        break;
1038
13
      }
1039
1040
13
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1041
13
    if (*slot == NULL)
1042
0
      return false;
1043
13
    struct comdat_hash_entry *newentry = *slot;
1044
13
    newentry->sec_flags = sec_flags;
1045
13
    newentry->symname = bfd_strdup (symname);
1046
13
    newentry->target_index = isym.n_scnum;
1047
13
    newentry->isym = isym;
1048
13
    newentry->comdat_symbol = -1;
1049
13
  }
1050
260
      else
1051
260
  {
1052
260
    struct comdat_hash_entry *entry = *slot;
1053
1054
260
    if (entry->comdat_symbol != -1)
1055
253
      continue;
1056
1057
7
    char *target_name = strchr (entry->symname, '$');
1058
7
    if (target_name != NULL)
1059
0
      {
1060
        /* Gas mode: the first matching on partial name.  */
1061
1062
0
        target_name += 1;
1063
#ifndef TARGET_UNDERSCORE
1064
#define TARGET_UNDERSCORE 0
1065
#endif
1066
        /* Is this the name we're looking for ?  */
1067
0
        if (strcmp (target_name,
1068
0
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1069
0
    {
1070
      /* Not the name we're looking for */
1071
0
      continue;
1072
0
    }
1073
0
      }
1074
    /* MSVC mode: the lexically second symbol (or drop through
1075
       from the above).  */
1076
    /* This must the second symbol with the section #.  It is
1077
       the actual symbol name.  Intel puts the two adjacent, but
1078
       Alpha (at least) spreads them out.  */
1079
1080
7
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1081
7
    entry->comdat_name = bfd_strdup (symname);
1082
7
  }
1083
273
    }
1084
1085
4
  return true;
1086
4
}
pe-i386.c:fill_comdat_hash
Line
Count
Source
890
141
{
891
141
  bfd_byte *esymstart, *esym, *esymend;
892
893
  /* Unfortunately, the PE format stores essential information in the
894
     symbol table, of all places.  We need to extract that information
895
     now, so that objdump and the linker will know how to handle the
896
     section without worrying about the symbols.  We can't call
897
     slurp_symtab, because the linker doesn't want the swapped symbols.  */
898
899
  /* COMDAT sections are special.  The first symbol is the section
900
     symbol, which tells what kind of COMDAT section it is.  The
901
     second symbol is the "comdat symbol" - the one with the unique
902
     name.  GNU uses the section symbol for the unique name; MS uses
903
     ".text" for every comdat section.  Sigh.  - DJ.  */
904
905
  /* This is not mirrored in sec_to_styp_flags(), but there doesn't
906
     seem to be a need to, either, and it would at best be rather messy.  */
907
908
141
  if (! _bfd_coff_get_external_symbols (abfd))
909
26
    return true;
910
911
115
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
912
115
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
913
914
115
  for (struct internal_syment isym;
915
8.22k
       esym < esymend;
916
8.10k
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
917
8.10k
    {
918
8.10k
      char buf[SYMNMLEN + 1];
919
8.10k
      const char *symname;
920
8.10k
      flagword sec_flags = SEC_LINK_ONCE;
921
922
8.10k
      bfd_coff_swap_sym_in (abfd, esym, &isym);
923
924
      /* According to the MSVC documentation, the first TWO entries
925
   with the section # are both of interest to us.  The first one
926
   is the "section symbol" (section name).  The second is the
927
   comdat symbol name.  Here, we've found the first qualifying
928
   entry; we distinguish it from the second with a state flag.
929
930
   In the case of gas-generated (at least until that is fixed)
931
   .o files, it isn't necessarily the second one.  It may be
932
   some other later symbol.
933
934
   Since gas also doesn't follow MS conventions and emits the
935
   section similar to .text$<name>, where <something> is the
936
   name we're looking for, we distinguish the two as follows:
937
938
   If the section name is simply a section name (no $) we
939
   presume it's MS-generated, and look at precisely the second
940
   symbol for the comdat name.  If the section name has a $, we
941
   assume it's gas-generated, and look for <something> (whatever
942
   follows the $) as the comdat symbol.  */
943
944
      /* All 3 branches use this.  */
945
8.10k
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
946
947
      /* PR 17512 file: 078-11867-0.004  */
948
8.10k
      if (symname == NULL)
949
1.82k
  {
950
1.82k
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
951
1.82k
            abfd);
952
1.82k
    continue;
953
1.82k
  }
954
955
6.28k
      union internal_auxent aux;
956
957
6.28k
      struct comdat_hash_entry needle;
958
6.28k
      needle.target_index = isym.n_scnum;
959
960
6.28k
      void **slot
961
6.28k
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
962
6.28k
      if (slot == NULL)
963
0
  return false;
964
965
6.28k
      if (*slot == NULL)
966
1.41k
  {
967
1.41k
    if (isym.n_numaux == 0)
968
712
      aux.x_scn.x_comdat = 0;
969
700
    else
970
700
      {
971
        /* PR 17512: file: e2cfe54f.  */
972
700
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
973
32
    {
974
      /* xgettext:c-format */
975
32
      _bfd_error_handler (_("%pB: warning: no symbol for"
976
32
          " section '%s' found"),
977
32
              abfd, symname);
978
32
      continue;
979
32
    }
980
668
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
981
668
            isym.n_type, isym.n_sclass, 0,
982
668
            isym.n_numaux, &aux);
983
668
      }
984
985
    /* FIXME: Microsoft uses NODUPLICATES and ASSOCIATIVE, but
986
       gnu uses ANY and SAME_SIZE.  Unfortunately, gnu doesn't
987
       do the comdat symbols right.  So, until we can fix it to
988
       do the right thing, we are temporarily disabling comdats
989
       for the MS types (they're used in DLLs and C++, but we
990
       don't support *their* C++ libraries anyway - DJ.  */
991
992
    /* Cygwin does not follow the MS style, and uses ANY and
993
       SAME_SIZE where NODUPLICATES and ASSOCIATIVE should be
994
       used.  For Interix, we just do the right thing up
995
       front.  */
996
997
1.38k
    switch (aux.x_scn.x_comdat)
998
1.38k
      {
999
1
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1000
#ifdef STRICT_PE_FORMAT
1001
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1002
#else
1003
1
        sec_flags &= ~SEC_LINK_ONCE;
1004
1
#endif
1005
1
        break;
1006
1007
0
      case IMAGE_COMDAT_SELECT_ANY:
1008
0
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1009
0
        break;
1010
1011
0
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1012
0
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1013
0
        break;
1014
1015
0
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1016
        /* Not yet fully implemented ??? */
1017
0
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1018
0
        break;
1019
1020
        /* debug$S gets this case; other implications ???  */
1021
1022
        /* There may be no symbol.  We'll search the whole
1023
     table.  Is this the right place to play this game?
1024
     Or should we do it when reading it in?  */
1025
0
      case IMAGE_COMDAT_SELECT_ASSOCIATIVE:
1026
#ifdef STRICT_PE_FORMAT
1027
        /* FIXME: This is not currently implemented.  */
1028
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1029
#else
1030
0
        sec_flags &= ~SEC_LINK_ONCE;
1031
0
#endif
1032
0
        break;
1033
1034
1.37k
      default:  /* 0 means "no symbol" */
1035
        /* debug$F gets this case; other implications ???  */
1036
1.37k
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1037
1.37k
        break;
1038
1.38k
      }
1039
1040
1.38k
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1041
1.38k
    if (*slot == NULL)
1042
0
      return false;
1043
1.38k
    struct comdat_hash_entry *newentry = *slot;
1044
1.38k
    newentry->sec_flags = sec_flags;
1045
1.38k
    newentry->symname = bfd_strdup (symname);
1046
1.38k
    newentry->target_index = isym.n_scnum;
1047
1.38k
    newentry->isym = isym;
1048
1.38k
    newentry->comdat_symbol = -1;
1049
1.38k
  }
1050
4.87k
      else
1051
4.87k
  {
1052
4.87k
    struct comdat_hash_entry *entry = *slot;
1053
1054
4.87k
    if (entry->comdat_symbol != -1)
1055
4.62k
      continue;
1056
1057
249
    char *target_name = strchr (entry->symname, '$');
1058
249
    if (target_name != NULL)
1059
3
      {
1060
        /* Gas mode: the first matching on partial name.  */
1061
1062
3
        target_name += 1;
1063
#ifndef TARGET_UNDERSCORE
1064
#define TARGET_UNDERSCORE 0
1065
#endif
1066
        /* Is this the name we're looking for ?  */
1067
3
        if (strcmp (target_name,
1068
3
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1069
3
    {
1070
      /* Not the name we're looking for */
1071
3
      continue;
1072
3
    }
1073
3
      }
1074
    /* MSVC mode: the lexically second symbol (or drop through
1075
       from the above).  */
1076
    /* This must the second symbol with the section #.  It is
1077
       the actual symbol name.  Intel puts the two adjacent, but
1078
       Alpha (at least) spreads them out.  */
1079
1080
246
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1081
246
    entry->comdat_name = bfd_strdup (symname);
1082
246
  }
1083
6.28k
    }
1084
1085
115
  return true;
1086
115
}
pe-mcore.c:fill_comdat_hash
Line
Count
Source
890
1
{
891
1
  bfd_byte *esymstart, *esym, *esymend;
892
893
  /* Unfortunately, the PE format stores essential information in the
894
     symbol table, of all places.  We need to extract that information
895
     now, so that objdump and the linker will know how to handle the
896
     section without worrying about the symbols.  We can't call
897
     slurp_symtab, because the linker doesn't want the swapped symbols.  */
898
899
  /* COMDAT sections are special.  The first symbol is the section
900
     symbol, which tells what kind of COMDAT section it is.  The
901
     second symbol is the "comdat symbol" - the one with the unique
902
     name.  GNU uses the section symbol for the unique name; MS uses
903
     ".text" for every comdat section.  Sigh.  - DJ.  */
904
905
  /* This is not mirrored in sec_to_styp_flags(), but there doesn't
906
     seem to be a need to, either, and it would at best be rather messy.  */
907
908
1
  if (! _bfd_coff_get_external_symbols (abfd))
909
0
    return true;
910
911
1
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
912
1
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
913
914
1
  for (struct internal_syment isym;
915
648
       esym < esymend;
916
647
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
917
647
    {
918
647
      char buf[SYMNMLEN + 1];
919
647
      const char *symname;
920
647
      flagword sec_flags = SEC_LINK_ONCE;
921
922
647
      bfd_coff_swap_sym_in (abfd, esym, &isym);
923
924
      /* According to the MSVC documentation, the first TWO entries
925
   with the section # are both of interest to us.  The first one
926
   is the "section symbol" (section name).  The second is the
927
   comdat symbol name.  Here, we've found the first qualifying
928
   entry; we distinguish it from the second with a state flag.
929
930
   In the case of gas-generated (at least until that is fixed)
931
   .o files, it isn't necessarily the second one.  It may be
932
   some other later symbol.
933
934
   Since gas also doesn't follow MS conventions and emits the
935
   section similar to .text$<name>, where <something> is the
936
   name we're looking for, we distinguish the two as follows:
937
938
   If the section name is simply a section name (no $) we
939
   presume it's MS-generated, and look at precisely the second
940
   symbol for the comdat name.  If the section name has a $, we
941
   assume it's gas-generated, and look for <something> (whatever
942
   follows the $) as the comdat symbol.  */
943
944
      /* All 3 branches use this.  */
945
647
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
946
947
      /* PR 17512 file: 078-11867-0.004  */
948
647
      if (symname == NULL)
949
176
  {
950
176
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
951
176
            abfd);
952
176
    continue;
953
176
  }
954
955
471
      union internal_auxent aux;
956
957
471
      struct comdat_hash_entry needle;
958
471
      needle.target_index = isym.n_scnum;
959
960
471
      void **slot
961
471
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
962
471
      if (slot == NULL)
963
0
  return false;
964
965
471
      if (*slot == NULL)
966
198
  {
967
198
    if (isym.n_numaux == 0)
968
61
      aux.x_scn.x_comdat = 0;
969
137
    else
970
137
      {
971
        /* PR 17512: file: e2cfe54f.  */
972
137
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
973
0
    {
974
      /* xgettext:c-format */
975
0
      _bfd_error_handler (_("%pB: warning: no symbol for"
976
0
          " section '%s' found"),
977
0
              abfd, symname);
978
0
      continue;
979
0
    }
980
137
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
981
137
            isym.n_type, isym.n_sclass, 0,
982
137
            isym.n_numaux, &aux);
983
137
      }
984
985
    /* FIXME: Microsoft uses NODUPLICATES and ASSOCIATIVE, but
986
       gnu uses ANY and SAME_SIZE.  Unfortunately, gnu doesn't
987
       do the comdat symbols right.  So, until we can fix it to
988
       do the right thing, we are temporarily disabling comdats
989
       for the MS types (they're used in DLLs and C++, but we
990
       don't support *their* C++ libraries anyway - DJ.  */
991
992
    /* Cygwin does not follow the MS style, and uses ANY and
993
       SAME_SIZE where NODUPLICATES and ASSOCIATIVE should be
994
       used.  For Interix, we just do the right thing up
995
       front.  */
996
997
198
    switch (aux.x_scn.x_comdat)
998
198
      {
999
0
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1000
#ifdef STRICT_PE_FORMAT
1001
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1002
#else
1003
0
        sec_flags &= ~SEC_LINK_ONCE;
1004
0
#endif
1005
0
        break;
1006
1007
0
      case IMAGE_COMDAT_SELECT_ANY:
1008
0
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1009
0
        break;
1010
1011
0
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1012
0
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1013
0
        break;
1014
1015
0
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1016
        /* Not yet fully implemented ??? */
1017
0
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1018
0
        break;
1019
1020
        /* debug$S gets this case; other implications ???  */
1021
1022
        /* There may be no symbol.  We'll search the whole
1023
     table.  Is this the right place to play this game?
1024
     Or should we do it when reading it in?  */
1025
0
      case IMAGE_COMDAT_SELECT_ASSOCIATIVE:
1026
#ifdef STRICT_PE_FORMAT
1027
        /* FIXME: This is not currently implemented.  */
1028
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1029
#else
1030
0
        sec_flags &= ~SEC_LINK_ONCE;
1031
0
#endif
1032
0
        break;
1033
1034
198
      default:  /* 0 means "no symbol" */
1035
        /* debug$F gets this case; other implications ???  */
1036
198
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1037
198
        break;
1038
198
      }
1039
1040
198
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1041
198
    if (*slot == NULL)
1042
0
      return false;
1043
198
    struct comdat_hash_entry *newentry = *slot;
1044
198
    newentry->sec_flags = sec_flags;
1045
198
    newentry->symname = bfd_strdup (symname);
1046
198
    newentry->target_index = isym.n_scnum;
1047
198
    newentry->isym = isym;
1048
198
    newentry->comdat_symbol = -1;
1049
198
  }
1050
273
      else
1051
273
  {
1052
273
    struct comdat_hash_entry *entry = *slot;
1053
1054
273
    if (entry->comdat_symbol != -1)
1055
261
      continue;
1056
1057
12
    char *target_name = strchr (entry->symname, '$');
1058
12
    if (target_name != NULL)
1059
0
      {
1060
        /* Gas mode: the first matching on partial name.  */
1061
1062
0
        target_name += 1;
1063
0
#ifndef TARGET_UNDERSCORE
1064
0
#define TARGET_UNDERSCORE 0
1065
0
#endif
1066
        /* Is this the name we're looking for ?  */
1067
0
        if (strcmp (target_name,
1068
0
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1069
0
    {
1070
      /* Not the name we're looking for */
1071
0
      continue;
1072
0
    }
1073
0
      }
1074
    /* MSVC mode: the lexically second symbol (or drop through
1075
       from the above).  */
1076
    /* This must the second symbol with the section #.  It is
1077
       the actual symbol name.  Intel puts the two adjacent, but
1078
       Alpha (at least) spreads them out.  */
1079
1080
12
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1081
12
    entry->comdat_name = bfd_strdup (symname);
1082
12
  }
1083
471
    }
1084
1085
1
  return true;
1086
1
}
pe-sh.c:fill_comdat_hash
Line
Count
Source
890
763
{
891
763
  bfd_byte *esymstart, *esym, *esymend;
892
893
  /* Unfortunately, the PE format stores essential information in the
894
     symbol table, of all places.  We need to extract that information
895
     now, so that objdump and the linker will know how to handle the
896
     section without worrying about the symbols.  We can't call
897
     slurp_symtab, because the linker doesn't want the swapped symbols.  */
898
899
  /* COMDAT sections are special.  The first symbol is the section
900
     symbol, which tells what kind of COMDAT section it is.  The
901
     second symbol is the "comdat symbol" - the one with the unique
902
     name.  GNU uses the section symbol for the unique name; MS uses
903
     ".text" for every comdat section.  Sigh.  - DJ.  */
904
905
  /* This is not mirrored in sec_to_styp_flags(), but there doesn't
906
     seem to be a need to, either, and it would at best be rather messy.  */
907
908
763
  if (! _bfd_coff_get_external_symbols (abfd))
909
0
    return true;
910
911
763
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
912
763
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
913
914
763
  for (struct internal_syment isym;
915
304k
       esym < esymend;
916
304k
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
917
304k
    {
918
304k
      char buf[SYMNMLEN + 1];
919
304k
      const char *symname;
920
304k
      flagword sec_flags = SEC_LINK_ONCE;
921
922
304k
      bfd_coff_swap_sym_in (abfd, esym, &isym);
923
924
      /* According to the MSVC documentation, the first TWO entries
925
   with the section # are both of interest to us.  The first one
926
   is the "section symbol" (section name).  The second is the
927
   comdat symbol name.  Here, we've found the first qualifying
928
   entry; we distinguish it from the second with a state flag.
929
930
   In the case of gas-generated (at least until that is fixed)
931
   .o files, it isn't necessarily the second one.  It may be
932
   some other later symbol.
933
934
   Since gas also doesn't follow MS conventions and emits the
935
   section similar to .text$<name>, where <something> is the
936
   name we're looking for, we distinguish the two as follows:
937
938
   If the section name is simply a section name (no $) we
939
   presume it's MS-generated, and look at precisely the second
940
   symbol for the comdat name.  If the section name has a $, we
941
   assume it's gas-generated, and look for <something> (whatever
942
   follows the $) as the comdat symbol.  */
943
944
      /* All 3 branches use this.  */
945
304k
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
946
947
      /* PR 17512 file: 078-11867-0.004  */
948
304k
      if (symname == NULL)
949
54.6k
  {
950
54.6k
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
951
54.6k
            abfd);
952
54.6k
    continue;
953
54.6k
  }
954
955
249k
      union internal_auxent aux;
956
957
249k
      struct comdat_hash_entry needle;
958
249k
      needle.target_index = isym.n_scnum;
959
960
249k
      void **slot
961
249k
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
962
249k
      if (slot == NULL)
963
0
  return false;
964
965
249k
      if (*slot == NULL)
966
33.7k
  {
967
33.7k
    if (isym.n_numaux == 0)
968
10.2k
      aux.x_scn.x_comdat = 0;
969
23.4k
    else
970
23.4k
      {
971
        /* PR 17512: file: e2cfe54f.  */
972
23.4k
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
973
214
    {
974
      /* xgettext:c-format */
975
214
      _bfd_error_handler (_("%pB: warning: no symbol for"
976
214
          " section '%s' found"),
977
214
              abfd, symname);
978
214
      continue;
979
214
    }
980
23.2k
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
981
23.2k
            isym.n_type, isym.n_sclass, 0,
982
23.2k
            isym.n_numaux, &aux);
983
23.2k
      }
984
985
    /* FIXME: Microsoft uses NODUPLICATES and ASSOCIATIVE, but
986
       gnu uses ANY and SAME_SIZE.  Unfortunately, gnu doesn't
987
       do the comdat symbols right.  So, until we can fix it to
988
       do the right thing, we are temporarily disabling comdats
989
       for the MS types (they're used in DLLs and C++, but we
990
       don't support *their* C++ libraries anyway - DJ.  */
991
992
    /* Cygwin does not follow the MS style, and uses ANY and
993
       SAME_SIZE where NODUPLICATES and ASSOCIATIVE should be
994
       used.  For Interix, we just do the right thing up
995
       front.  */
996
997
33.4k
    switch (aux.x_scn.x_comdat)
998
33.4k
      {
999
16
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1000
#ifdef STRICT_PE_FORMAT
1001
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1002
#else
1003
16
        sec_flags &= ~SEC_LINK_ONCE;
1004
16
#endif
1005
16
        break;
1006
1007
1
      case IMAGE_COMDAT_SELECT_ANY:
1008
1
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1009
1
        break;
1010
1011
0
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1012
0
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1013
0
        break;
1014
1015
0
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1016
        /* Not yet fully implemented ??? */
1017
0
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1018
0
        break;
1019
1020
        /* debug$S gets this case; other implications ???  */
1021
1022
        /* There may be no symbol.  We'll search the whole
1023
     table.  Is this the right place to play this game?
1024
     Or should we do it when reading it in?  */
1025
0
      case IMAGE_COMDAT_SELECT_ASSOCIATIVE:
1026
#ifdef STRICT_PE_FORMAT
1027
        /* FIXME: This is not currently implemented.  */
1028
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1029
#else
1030
0
        sec_flags &= ~SEC_LINK_ONCE;
1031
0
#endif
1032
0
        break;
1033
1034
33.4k
      default:  /* 0 means "no symbol" */
1035
        /* debug$F gets this case; other implications ???  */
1036
33.4k
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1037
33.4k
        break;
1038
33.4k
      }
1039
1040
33.4k
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1041
33.4k
    if (*slot == NULL)
1042
0
      return false;
1043
33.4k
    struct comdat_hash_entry *newentry = *slot;
1044
33.4k
    newentry->sec_flags = sec_flags;
1045
33.4k
    newentry->symname = bfd_strdup (symname);
1046
33.4k
    newentry->target_index = isym.n_scnum;
1047
33.4k
    newentry->isym = isym;
1048
33.4k
    newentry->comdat_symbol = -1;
1049
33.4k
  }
1050
215k
      else
1051
215k
  {
1052
215k
    struct comdat_hash_entry *entry = *slot;
1053
1054
215k
    if (entry->comdat_symbol != -1)
1055
210k
      continue;
1056
1057
5.30k
    char *target_name = strchr (entry->symname, '$');
1058
5.30k
    if (target_name != NULL)
1059
16
      {
1060
        /* Gas mode: the first matching on partial name.  */
1061
1062
16
        target_name += 1;
1063
#ifndef TARGET_UNDERSCORE
1064
#define TARGET_UNDERSCORE 0
1065
#endif
1066
        /* Is this the name we're looking for ?  */
1067
16
        if (strcmp (target_name,
1068
16
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1069
16
    {
1070
      /* Not the name we're looking for */
1071
16
      continue;
1072
16
    }
1073
16
      }
1074
    /* MSVC mode: the lexically second symbol (or drop through
1075
       from the above).  */
1076
    /* This must the second symbol with the section #.  It is
1077
       the actual symbol name.  Intel puts the two adjacent, but
1078
       Alpha (at least) spreads them out.  */
1079
1080
5.29k
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1081
5.29k
    entry->comdat_name = bfd_strdup (symname);
1082
5.29k
  }
1083
249k
    }
1084
1085
763
  return true;
1086
763
}
Unexecuted instantiation: pei-arm-wince.c:fill_comdat_hash
Unexecuted instantiation: pei-arm.c:fill_comdat_hash
Unexecuted instantiation: pei-mcore.c:fill_comdat_hash
pei-sh.c:fill_comdat_hash
Line
Count
Source
890
7
{
891
7
  bfd_byte *esymstart, *esym, *esymend;
892
893
  /* Unfortunately, the PE format stores essential information in the
894
     symbol table, of all places.  We need to extract that information
895
     now, so that objdump and the linker will know how to handle the
896
     section without worrying about the symbols.  We can't call
897
     slurp_symtab, because the linker doesn't want the swapped symbols.  */
898
899
  /* COMDAT sections are special.  The first symbol is the section
900
     symbol, which tells what kind of COMDAT section it is.  The
901
     second symbol is the "comdat symbol" - the one with the unique
902
     name.  GNU uses the section symbol for the unique name; MS uses
903
     ".text" for every comdat section.  Sigh.  - DJ.  */
904
905
  /* This is not mirrored in sec_to_styp_flags(), but there doesn't
906
     seem to be a need to, either, and it would at best be rather messy.  */
907
908
7
  if (! _bfd_coff_get_external_symbols (abfd))
909
0
    return true;
910
911
7
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
912
7
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
913
914
7
  for (struct internal_syment isym;
915
4.34k
       esym < esymend;
916
4.33k
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
917
4.33k
    {
918
4.33k
      char buf[SYMNMLEN + 1];
919
4.33k
      const char *symname;
920
4.33k
      flagword sec_flags = SEC_LINK_ONCE;
921
922
4.33k
      bfd_coff_swap_sym_in (abfd, esym, &isym);
923
924
      /* According to the MSVC documentation, the first TWO entries
925
   with the section # are both of interest to us.  The first one
926
   is the "section symbol" (section name).  The second is the
927
   comdat symbol name.  Here, we've found the first qualifying
928
   entry; we distinguish it from the second with a state flag.
929
930
   In the case of gas-generated (at least until that is fixed)
931
   .o files, it isn't necessarily the second one.  It may be
932
   some other later symbol.
933
934
   Since gas also doesn't follow MS conventions and emits the
935
   section similar to .text$<name>, where <something> is the
936
   name we're looking for, we distinguish the two as follows:
937
938
   If the section name is simply a section name (no $) we
939
   presume it's MS-generated, and look at precisely the second
940
   symbol for the comdat name.  If the section name has a $, we
941
   assume it's gas-generated, and look for <something> (whatever
942
   follows the $) as the comdat symbol.  */
943
944
      /* All 3 branches use this.  */
945
4.33k
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
946
947
      /* PR 17512 file: 078-11867-0.004  */
948
4.33k
      if (symname == NULL)
949
893
  {
950
893
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
951
893
            abfd);
952
893
    continue;
953
893
  }
954
955
3.44k
      union internal_auxent aux;
956
957
3.44k
      struct comdat_hash_entry needle;
958
3.44k
      needle.target_index = isym.n_scnum;
959
960
3.44k
      void **slot
961
3.44k
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
962
3.44k
      if (slot == NULL)
963
0
  return false;
964
965
3.44k
      if (*slot == NULL)
966
253
  {
967
253
    if (isym.n_numaux == 0)
968
179
      aux.x_scn.x_comdat = 0;
969
74
    else
970
74
      {
971
        /* PR 17512: file: e2cfe54f.  */
972
74
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
973
0
    {
974
      /* xgettext:c-format */
975
0
      _bfd_error_handler (_("%pB: warning: no symbol for"
976
0
          " section '%s' found"),
977
0
              abfd, symname);
978
0
      continue;
979
0
    }
980
74
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
981
74
            isym.n_type, isym.n_sclass, 0,
982
74
            isym.n_numaux, &aux);
983
74
      }
984
985
    /* FIXME: Microsoft uses NODUPLICATES and ASSOCIATIVE, but
986
       gnu uses ANY and SAME_SIZE.  Unfortunately, gnu doesn't
987
       do the comdat symbols right.  So, until we can fix it to
988
       do the right thing, we are temporarily disabling comdats
989
       for the MS types (they're used in DLLs and C++, but we
990
       don't support *their* C++ libraries anyway - DJ.  */
991
992
    /* Cygwin does not follow the MS style, and uses ANY and
993
       SAME_SIZE where NODUPLICATES and ASSOCIATIVE should be
994
       used.  For Interix, we just do the right thing up
995
       front.  */
996
997
253
    switch (aux.x_scn.x_comdat)
998
253
      {
999
0
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1000
#ifdef STRICT_PE_FORMAT
1001
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1002
#else
1003
0
        sec_flags &= ~SEC_LINK_ONCE;
1004
0
#endif
1005
0
        break;
1006
1007
0
      case IMAGE_COMDAT_SELECT_ANY:
1008
0
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1009
0
        break;
1010
1011
0
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1012
0
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1013
0
        break;
1014
1015
0
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1016
        /* Not yet fully implemented ??? */
1017
0
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1018
0
        break;
1019
1020
        /* debug$S gets this case; other implications ???  */
1021
1022
        /* There may be no symbol.  We'll search the whole
1023
     table.  Is this the right place to play this game?
1024
     Or should we do it when reading it in?  */
1025
0
      case IMAGE_COMDAT_SELECT_ASSOCIATIVE:
1026
#ifdef STRICT_PE_FORMAT
1027
        /* FIXME: This is not currently implemented.  */
1028
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1029
#else
1030
0
        sec_flags &= ~SEC_LINK_ONCE;
1031
0
#endif
1032
0
        break;
1033
1034
253
      default:  /* 0 means "no symbol" */
1035
        /* debug$F gets this case; other implications ???  */
1036
253
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1037
253
        break;
1038
253
      }
1039
1040
253
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1041
253
    if (*slot == NULL)
1042
0
      return false;
1043
253
    struct comdat_hash_entry *newentry = *slot;
1044
253
    newentry->sec_flags = sec_flags;
1045
253
    newentry->symname = bfd_strdup (symname);
1046
253
    newentry->target_index = isym.n_scnum;
1047
253
    newentry->isym = isym;
1048
253
    newentry->comdat_symbol = -1;
1049
253
  }
1050
3.19k
      else
1051
3.19k
  {
1052
3.19k
    struct comdat_hash_entry *entry = *slot;
1053
1054
3.19k
    if (entry->comdat_symbol != -1)
1055
3.13k
      continue;
1056
1057
61
    char *target_name = strchr (entry->symname, '$');
1058
61
    if (target_name != NULL)
1059
0
      {
1060
        /* Gas mode: the first matching on partial name.  */
1061
1062
0
        target_name += 1;
1063
#ifndef TARGET_UNDERSCORE
1064
#define TARGET_UNDERSCORE 0
1065
#endif
1066
        /* Is this the name we're looking for ?  */
1067
0
        if (strcmp (target_name,
1068
0
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1069
0
    {
1070
      /* Not the name we're looking for */
1071
0
      continue;
1072
0
    }
1073
0
      }
1074
    /* MSVC mode: the lexically second symbol (or drop through
1075
       from the above).  */
1076
    /* This must the second symbol with the section #.  It is
1077
       the actual symbol name.  Intel puts the two adjacent, but
1078
       Alpha (at least) spreads them out.  */
1079
1080
61
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1081
61
    entry->comdat_name = bfd_strdup (symname);
1082
61
  }
1083
3.44k
    }
1084
1085
7
  return true;
1086
7
}
1087
1088
static bool
1089
insert_coff_comdat_info (bfd *abfd, asection *section, const char *symname,
1090
       long symbol)
1091
114
{
1092
114
  struct coff_comdat_info *comdat;
1093
114
  size_t len = strlen (symname) + 1;
1094
1095
114
  comdat = bfd_alloc (abfd, sizeof (*comdat) + len);
1096
114
  if (comdat == NULL)
1097
0
    return false;
1098
1099
114
  coff_section_data (abfd, section)->comdat = comdat;
1100
114
  comdat->symbol = symbol;
1101
114
  char *newname = (char *) (comdat + 1);
1102
114
  comdat->name = newname;
1103
114
  memcpy (newname, symname, len);
1104
114
  return true;
1105
114
}
pei-i386.c:insert_coff_comdat_info
Line
Count
Source
1091
1
{
1092
1
  struct coff_comdat_info *comdat;
1093
1
  size_t len = strlen (symname) + 1;
1094
1095
1
  comdat = bfd_alloc (abfd, sizeof (*comdat) + len);
1096
1
  if (comdat == NULL)
1097
0
    return false;
1098
1099
1
  coff_section_data (abfd, section)->comdat = comdat;
1100
1
  comdat->symbol = symbol;
1101
1
  char *newname = (char *) (comdat + 1);
1102
1
  comdat->name = newname;
1103
1
  memcpy (newname, symname, len);
1104
1
  return true;
1105
1
}
pe-x86_64.c:insert_coff_comdat_info
Line
Count
Source
1091
1
{
1092
1
  struct coff_comdat_info *comdat;
1093
1
  size_t len = strlen (symname) + 1;
1094
1095
1
  comdat = bfd_alloc (abfd, sizeof (*comdat) + len);
1096
1
  if (comdat == NULL)
1097
0
    return false;
1098
1099
1
  coff_section_data (abfd, section)->comdat = comdat;
1100
1
  comdat->symbol = symbol;
1101
1
  char *newname = (char *) (comdat + 1);
1102
1
  comdat->name = newname;
1103
1
  memcpy (newname, symname, len);
1104
1
  return true;
1105
1
}
pei-x86_64.c:insert_coff_comdat_info
Line
Count
Source
1091
4
{
1092
4
  struct coff_comdat_info *comdat;
1093
4
  size_t len = strlen (symname) + 1;
1094
1095
4
  comdat = bfd_alloc (abfd, sizeof (*comdat) + len);
1096
4
  if (comdat == NULL)
1097
0
    return false;
1098
1099
4
  coff_section_data (abfd, section)->comdat = comdat;
1100
4
  comdat->symbol = symbol;
1101
4
  char *newname = (char *) (comdat + 1);
1102
4
  comdat->name = newname;
1103
4
  memcpy (newname, symname, len);
1104
4
  return true;
1105
4
}
Unexecuted instantiation: pe-aarch64.c:insert_coff_comdat_info
Unexecuted instantiation: pei-aarch64.c:insert_coff_comdat_info
Unexecuted instantiation: pei-ia64.c:insert_coff_comdat_info
pei-loongarch64.c:insert_coff_comdat_info
Line
Count
Source
1091
2
{
1092
2
  struct coff_comdat_info *comdat;
1093
2
  size_t len = strlen (symname) + 1;
1094
1095
2
  comdat = bfd_alloc (abfd, sizeof (*comdat) + len);
1096
2
  if (comdat == NULL)
1097
0
    return false;
1098
1099
2
  coff_section_data (abfd, section)->comdat = comdat;
1100
2
  comdat->symbol = symbol;
1101
2
  char *newname = (char *) (comdat + 1);
1102
2
  comdat->name = newname;
1103
2
  memcpy (newname, symname, len);
1104
2
  return true;
1105
2
}
Unexecuted instantiation: pe-arm-wince.c:insert_coff_comdat_info
Unexecuted instantiation: pe-arm.c:insert_coff_comdat_info
pe-i386.c:insert_coff_comdat_info
Line
Count
Source
1091
3
{
1092
3
  struct coff_comdat_info *comdat;
1093
3
  size_t len = strlen (symname) + 1;
1094
1095
3
  comdat = bfd_alloc (abfd, sizeof (*comdat) + len);
1096
3
  if (comdat == NULL)
1097
0
    return false;
1098
1099
3
  coff_section_data (abfd, section)->comdat = comdat;
1100
3
  comdat->symbol = symbol;
1101
3
  char *newname = (char *) (comdat + 1);
1102
3
  comdat->name = newname;
1103
3
  memcpy (newname, symname, len);
1104
3
  return true;
1105
3
}
Unexecuted instantiation: pe-mcore.c:insert_coff_comdat_info
pe-sh.c:insert_coff_comdat_info
Line
Count
Source
1091
103
{
1092
103
  struct coff_comdat_info *comdat;
1093
103
  size_t len = strlen (symname) + 1;
1094
1095
103
  comdat = bfd_alloc (abfd, sizeof (*comdat) + len);
1096
103
  if (comdat == NULL)
1097
0
    return false;
1098
1099
103
  coff_section_data (abfd, section)->comdat = comdat;
1100
103
  comdat->symbol = symbol;
1101
103
  char *newname = (char *) (comdat + 1);
1102
103
  comdat->name = newname;
1103
103
  memcpy (newname, symname, len);
1104
103
  return true;
1105
103
}
Unexecuted instantiation: pei-arm-wince.c:insert_coff_comdat_info
Unexecuted instantiation: pei-arm.c:insert_coff_comdat_info
Unexecuted instantiation: pei-mcore.c:insert_coff_comdat_info
Unexecuted instantiation: pei-sh.c:insert_coff_comdat_info
1106
1107
static bool
1108
handle_COMDAT (bfd *abfd, flagword *sec_flags, const char *name,
1109
         asection *section)
1110
1.96k
{
1111
1.96k
  if (pe_data (abfd)->comdat_hash == NULL)
1112
1.17k
    {
1113
1.17k
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1114
1.17k
             comdat_delf);
1115
1.17k
      if (pe_data (abfd)->comdat_hash == NULL)
1116
0
  return false;
1117
1.17k
    }
1118
1119
1.96k
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1120
1.21k
    if (! fill_comdat_hash (abfd))
1121
0
      return false;
1122
1123
1.96k
  struct comdat_hash_entry *found
1124
1.96k
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1125
1.96k
  if (found != NULL)
1126
746
    {
1127
746
      struct internal_syment isym = found->isym;
1128
1129
      /* If it isn't the stuff we're expecting, die;  The MS
1130
   documentation is vague, but it appears that the second entry
1131
   serves BOTH as the comdat symbol and the defining symbol
1132
   record (either C_STAT or C_EXT, possibly with an aux entry
1133
   with debug information if it's a function.)  It appears the
1134
   only way to find the second one is to count.  (On Intel, they
1135
   appear to be adjacent, but on Alpha, they have been found
1136
   separated.)
1137
1138
   Here, we think we've found the first one, but there's some
1139
   checking we can do to be sure.  */
1140
1141
746
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1142
746
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1143
622
  {
1144
    /* Malformed input files can trigger this test.
1145
       cf PR 21781.  */
1146
622
    _bfd_error_handler
1147
622
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1148
622
       abfd, found->symname);
1149
622
    return false;
1150
622
  }
1151
1152
      /* FIXME LATER: MSVC generates section names like .text for
1153
   comdats.  Gas generates names like .text$foo__Fv (in the case
1154
   of a function).  See comment above for more.  */
1155
1156
124
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1157
  /* xgettext:c-format */
1158
1
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1159
1
            " does not match section name '%s'"),
1160
1
          abfd, found->symname, name);
1161
1162
124
      if (found->comdat_symbol != -1)
1163
114
  {
1164
114
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1165
114
           found->comdat_symbol))
1166
0
      return false;
1167
114
  }
1168
124
      *sec_flags = *sec_flags | found->sec_flags;
1169
124
      return true;
1170
124
    }
1171
1.21k
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1172
1.21k
  return true;
1173
1.96k
}
pei-i386.c:handle_COMDAT
Line
Count
Source
1110
42
{
1111
42
  if (pe_data (abfd)->comdat_hash == NULL)
1112
42
    {
1113
42
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1114
42
             comdat_delf);
1115
42
      if (pe_data (abfd)->comdat_hash == NULL)
1116
0
  return false;
1117
42
    }
1118
1119
42
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1120
42
    if (! fill_comdat_hash (abfd))
1121
0
      return false;
1122
1123
42
  struct comdat_hash_entry *found
1124
42
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1125
42
  if (found != NULL)
1126
13
    {
1127
13
      struct internal_syment isym = found->isym;
1128
1129
      /* If it isn't the stuff we're expecting, die;  The MS
1130
   documentation is vague, but it appears that the second entry
1131
   serves BOTH as the comdat symbol and the defining symbol
1132
   record (either C_STAT or C_EXT, possibly with an aux entry
1133
   with debug information if it's a function.)  It appears the
1134
   only way to find the second one is to count.  (On Intel, they
1135
   appear to be adjacent, but on Alpha, they have been found
1136
   separated.)
1137
1138
   Here, we think we've found the first one, but there's some
1139
   checking we can do to be sure.  */
1140
1141
13
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1142
13
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1143
12
  {
1144
    /* Malformed input files can trigger this test.
1145
       cf PR 21781.  */
1146
12
    _bfd_error_handler
1147
12
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1148
12
       abfd, found->symname);
1149
12
    return false;
1150
12
  }
1151
1152
      /* FIXME LATER: MSVC generates section names like .text for
1153
   comdats.  Gas generates names like .text$foo__Fv (in the case
1154
   of a function).  See comment above for more.  */
1155
1156
1
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1157
  /* xgettext:c-format */
1158
0
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1159
0
            " does not match section name '%s'"),
1160
0
          abfd, found->symname, name);
1161
1162
1
      if (found->comdat_symbol != -1)
1163
1
  {
1164
1
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1165
1
           found->comdat_symbol))
1166
0
      return false;
1167
1
  }
1168
1
      *sec_flags = *sec_flags | found->sec_flags;
1169
1
      return true;
1170
1
    }
1171
29
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1172
29
  return true;
1173
42
}
pe-x86_64.c:handle_COMDAT
Line
Count
Source
1110
40
{
1111
40
  if (pe_data (abfd)->comdat_hash == NULL)
1112
37
    {
1113
37
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1114
37
             comdat_delf);
1115
37
      if (pe_data (abfd)->comdat_hash == NULL)
1116
0
  return false;
1117
37
    }
1118
1119
40
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1120
40
    if (! fill_comdat_hash (abfd))
1121
0
      return false;
1122
1123
40
  struct comdat_hash_entry *found
1124
40
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1125
40
  if (found != NULL)
1126
16
    {
1127
16
      struct internal_syment isym = found->isym;
1128
1129
      /* If it isn't the stuff we're expecting, die;  The MS
1130
   documentation is vague, but it appears that the second entry
1131
   serves BOTH as the comdat symbol and the defining symbol
1132
   record (either C_STAT or C_EXT, possibly with an aux entry
1133
   with debug information if it's a function.)  It appears the
1134
   only way to find the second one is to count.  (On Intel, they
1135
   appear to be adjacent, but on Alpha, they have been found
1136
   separated.)
1137
1138
   Here, we think we've found the first one, but there's some
1139
   checking we can do to be sure.  */
1140
1141
16
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1142
16
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1143
15
  {
1144
    /* Malformed input files can trigger this test.
1145
       cf PR 21781.  */
1146
15
    _bfd_error_handler
1147
15
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1148
15
       abfd, found->symname);
1149
15
    return false;
1150
15
  }
1151
1152
      /* FIXME LATER: MSVC generates section names like .text for
1153
   comdats.  Gas generates names like .text$foo__Fv (in the case
1154
   of a function).  See comment above for more.  */
1155
1156
1
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1157
  /* xgettext:c-format */
1158
0
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1159
0
            " does not match section name '%s'"),
1160
0
          abfd, found->symname, name);
1161
1162
1
      if (found->comdat_symbol != -1)
1163
1
  {
1164
1
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1165
1
           found->comdat_symbol))
1166
0
      return false;
1167
1
  }
1168
1
      *sec_flags = *sec_flags | found->sec_flags;
1169
1
      return true;
1170
1
    }
1171
24
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1172
24
  return true;
1173
40
}
pei-x86_64.c:handle_COMDAT
Line
Count
Source
1110
46
{
1111
46
  if (pe_data (abfd)->comdat_hash == NULL)
1112
35
    {
1113
35
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1114
35
             comdat_delf);
1115
35
      if (pe_data (abfd)->comdat_hash == NULL)
1116
0
  return false;
1117
35
    }
1118
1119
46
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1120
35
    if (! fill_comdat_hash (abfd))
1121
0
      return false;
1122
1123
46
  struct comdat_hash_entry *found
1124
46
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1125
46
  if (found != NULL)
1126
8
    {
1127
8
      struct internal_syment isym = found->isym;
1128
1129
      /* If it isn't the stuff we're expecting, die;  The MS
1130
   documentation is vague, but it appears that the second entry
1131
   serves BOTH as the comdat symbol and the defining symbol
1132
   record (either C_STAT or C_EXT, possibly with an aux entry
1133
   with debug information if it's a function.)  It appears the
1134
   only way to find the second one is to count.  (On Intel, they
1135
   appear to be adjacent, but on Alpha, they have been found
1136
   separated.)
1137
1138
   Here, we think we've found the first one, but there's some
1139
   checking we can do to be sure.  */
1140
1141
8
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1142
8
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1143
4
  {
1144
    /* Malformed input files can trigger this test.
1145
       cf PR 21781.  */
1146
4
    _bfd_error_handler
1147
4
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1148
4
       abfd, found->symname);
1149
4
    return false;
1150
4
  }
1151
1152
      /* FIXME LATER: MSVC generates section names like .text for
1153
   comdats.  Gas generates names like .text$foo__Fv (in the case
1154
   of a function).  See comment above for more.  */
1155
1156
4
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1157
  /* xgettext:c-format */
1158
0
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1159
0
            " does not match section name '%s'"),
1160
0
          abfd, found->symname, name);
1161
1162
4
      if (found->comdat_symbol != -1)
1163
4
  {
1164
4
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1165
4
           found->comdat_symbol))
1166
0
      return false;
1167
4
  }
1168
4
      *sec_flags = *sec_flags | found->sec_flags;
1169
4
      return true;
1170
4
    }
1171
38
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1172
38
  return true;
1173
46
}
pe-aarch64.c:handle_COMDAT
Line
Count
Source
1110
60
{
1111
60
  if (pe_data (abfd)->comdat_hash == NULL)
1112
58
    {
1113
58
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1114
58
             comdat_delf);
1115
58
      if (pe_data (abfd)->comdat_hash == NULL)
1116
0
  return false;
1117
58
    }
1118
1119
60
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1120
58
    if (! fill_comdat_hash (abfd))
1121
0
      return false;
1122
1123
60
  struct comdat_hash_entry *found
1124
60
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1125
60
  if (found != NULL)
1126
21
    {
1127
21
      struct internal_syment isym = found->isym;
1128
1129
      /* If it isn't the stuff we're expecting, die;  The MS
1130
   documentation is vague, but it appears that the second entry
1131
   serves BOTH as the comdat symbol and the defining symbol
1132
   record (either C_STAT or C_EXT, possibly with an aux entry
1133
   with debug information if it's a function.)  It appears the
1134
   only way to find the second one is to count.  (On Intel, they
1135
   appear to be adjacent, but on Alpha, they have been found
1136
   separated.)
1137
1138
   Here, we think we've found the first one, but there's some
1139
   checking we can do to be sure.  */
1140
1141
21
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1142
21
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1143
20
  {
1144
    /* Malformed input files can trigger this test.
1145
       cf PR 21781.  */
1146
20
    _bfd_error_handler
1147
20
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1148
20
       abfd, found->symname);
1149
20
    return false;
1150
20
  }
1151
1152
      /* FIXME LATER: MSVC generates section names like .text for
1153
   comdats.  Gas generates names like .text$foo__Fv (in the case
1154
   of a function).  See comment above for more.  */
1155
1156
1
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1157
  /* xgettext:c-format */
1158
0
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1159
0
            " does not match section name '%s'"),
1160
0
          abfd, found->symname, name);
1161
1162
1
      if (found->comdat_symbol != -1)
1163
0
  {
1164
0
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1165
0
           found->comdat_symbol))
1166
0
      return false;
1167
0
  }
1168
1
      *sec_flags = *sec_flags | found->sec_flags;
1169
1
      return true;
1170
1
    }
1171
39
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1172
39
  return true;
1173
60
}
pei-aarch64.c:handle_COMDAT
Line
Count
Source
1110
272
{
1111
272
  if (pe_data (abfd)->comdat_hash == NULL)
1112
47
    {
1113
47
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1114
47
             comdat_delf);
1115
47
      if (pe_data (abfd)->comdat_hash == NULL)
1116
0
  return false;
1117
47
    }
1118
1119
272
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1120
47
    if (! fill_comdat_hash (abfd))
1121
0
      return false;
1122
1123
272
  struct comdat_hash_entry *found
1124
272
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1125
272
  if (found != NULL)
1126
2
    {
1127
2
      struct internal_syment isym = found->isym;
1128
1129
      /* If it isn't the stuff we're expecting, die;  The MS
1130
   documentation is vague, but it appears that the second entry
1131
   serves BOTH as the comdat symbol and the defining symbol
1132
   record (either C_STAT or C_EXT, possibly with an aux entry
1133
   with debug information if it's a function.)  It appears the
1134
   only way to find the second one is to count.  (On Intel, they
1135
   appear to be adjacent, but on Alpha, they have been found
1136
   separated.)
1137
1138
   Here, we think we've found the first one, but there's some
1139
   checking we can do to be sure.  */
1140
1141
2
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1142
2
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1143
2
  {
1144
    /* Malformed input files can trigger this test.
1145
       cf PR 21781.  */
1146
2
    _bfd_error_handler
1147
2
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1148
2
       abfd, found->symname);
1149
2
    return false;
1150
2
  }
1151
1152
      /* FIXME LATER: MSVC generates section names like .text for
1153
   comdats.  Gas generates names like .text$foo__Fv (in the case
1154
   of a function).  See comment above for more.  */
1155
1156
0
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1157
  /* xgettext:c-format */
1158
0
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1159
0
            " does not match section name '%s'"),
1160
0
          abfd, found->symname, name);
1161
1162
0
      if (found->comdat_symbol != -1)
1163
0
  {
1164
0
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1165
0
           found->comdat_symbol))
1166
0
      return false;
1167
0
  }
1168
0
      *sec_flags = *sec_flags | found->sec_flags;
1169
0
      return true;
1170
0
    }
1171
270
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1172
270
  return true;
1173
272
}
pei-ia64.c:handle_COMDAT
Line
Count
Source
1110
10
{
1111
10
  if (pe_data (abfd)->comdat_hash == NULL)
1112
10
    {
1113
10
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1114
10
             comdat_delf);
1115
10
      if (pe_data (abfd)->comdat_hash == NULL)
1116
0
  return false;
1117
10
    }
1118
1119
10
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1120
10
    if (! fill_comdat_hash (abfd))
1121
0
      return false;
1122
1123
10
  struct comdat_hash_entry *found
1124
10
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1125
10
  if (found != NULL)
1126
4
    {
1127
4
      struct internal_syment isym = found->isym;
1128
1129
      /* If it isn't the stuff we're expecting, die;  The MS
1130
   documentation is vague, but it appears that the second entry
1131
   serves BOTH as the comdat symbol and the defining symbol
1132
   record (either C_STAT or C_EXT, possibly with an aux entry
1133
   with debug information if it's a function.)  It appears the
1134
   only way to find the second one is to count.  (On Intel, they
1135
   appear to be adjacent, but on Alpha, they have been found
1136
   separated.)
1137
1138
   Here, we think we've found the first one, but there's some
1139
   checking we can do to be sure.  */
1140
1141
4
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1142
4
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1143
4
  {
1144
    /* Malformed input files can trigger this test.
1145
       cf PR 21781.  */
1146
4
    _bfd_error_handler
1147
4
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1148
4
       abfd, found->symname);
1149
4
    return false;
1150
4
  }
1151
1152
      /* FIXME LATER: MSVC generates section names like .text for
1153
   comdats.  Gas generates names like .text$foo__Fv (in the case
1154
   of a function).  See comment above for more.  */
1155
1156
0
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1157
  /* xgettext:c-format */
1158
0
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1159
0
            " does not match section name '%s'"),
1160
0
          abfd, found->symname, name);
1161
1162
0
      if (found->comdat_symbol != -1)
1163
0
  {
1164
0
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1165
0
           found->comdat_symbol))
1166
0
      return false;
1167
0
  }
1168
0
      *sec_flags = *sec_flags | found->sec_flags;
1169
0
      return true;
1170
0
    }
1171
6
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1172
6
  return true;
1173
10
}
pei-loongarch64.c:handle_COMDAT
Line
Count
Source
1110
63
{
1111
63
  if (pe_data (abfd)->comdat_hash == NULL)
1112
63
    {
1113
63
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1114
63
             comdat_delf);
1115
63
      if (pe_data (abfd)->comdat_hash == NULL)
1116
0
  return false;
1117
63
    }
1118
1119
63
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1120
63
    if (! fill_comdat_hash (abfd))
1121
0
      return false;
1122
1123
63
  struct comdat_hash_entry *found
1124
63
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1125
63
  if (found != NULL)
1126
18
    {
1127
18
      struct internal_syment isym = found->isym;
1128
1129
      /* If it isn't the stuff we're expecting, die;  The MS
1130
   documentation is vague, but it appears that the second entry
1131
   serves BOTH as the comdat symbol and the defining symbol
1132
   record (either C_STAT or C_EXT, possibly with an aux entry
1133
   with debug information if it's a function.)  It appears the
1134
   only way to find the second one is to count.  (On Intel, they
1135
   appear to be adjacent, but on Alpha, they have been found
1136
   separated.)
1137
1138
   Here, we think we've found the first one, but there's some
1139
   checking we can do to be sure.  */
1140
1141
18
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1142
18
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1143
14
  {
1144
    /* Malformed input files can trigger this test.
1145
       cf PR 21781.  */
1146
14
    _bfd_error_handler
1147
14
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1148
14
       abfd, found->symname);
1149
14
    return false;
1150
14
  }
1151
1152
      /* FIXME LATER: MSVC generates section names like .text for
1153
   comdats.  Gas generates names like .text$foo__Fv (in the case
1154
   of a function).  See comment above for more.  */
1155
1156
4
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1157
  /* xgettext:c-format */
1158
1
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1159
1
            " does not match section name '%s'"),
1160
1
          abfd, found->symname, name);
1161
1162
4
      if (found->comdat_symbol != -1)
1163
2
  {
1164
2
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1165
2
           found->comdat_symbol))
1166
0
      return false;
1167
2
  }
1168
4
      *sec_flags = *sec_flags | found->sec_flags;
1169
4
      return true;
1170
4
    }
1171
45
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1172
45
  return true;
1173
63
}
pe-arm-wince.c:handle_COMDAT
Line
Count
Source
1110
4
{
1111
4
  if (pe_data (abfd)->comdat_hash == NULL)
1112
4
    {
1113
4
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1114
4
             comdat_delf);
1115
4
      if (pe_data (abfd)->comdat_hash == NULL)
1116
0
  return false;
1117
4
    }
1118
1119
4
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1120
4
    if (! fill_comdat_hash (abfd))
1121
0
      return false;
1122
1123
4
  struct comdat_hash_entry *found
1124
4
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1125
4
  if (found != NULL)
1126
3
    {
1127
3
      struct internal_syment isym = found->isym;
1128
1129
      /* If it isn't the stuff we're expecting, die;  The MS
1130
   documentation is vague, but it appears that the second entry
1131
   serves BOTH as the comdat symbol and the defining symbol
1132
   record (either C_STAT or C_EXT, possibly with an aux entry
1133
   with debug information if it's a function.)  It appears the
1134
   only way to find the second one is to count.  (On Intel, they
1135
   appear to be adjacent, but on Alpha, they have been found
1136
   separated.)
1137
1138
   Here, we think we've found the first one, but there's some
1139
   checking we can do to be sure.  */
1140
1141
3
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1142
3
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1143
3
  {
1144
    /* Malformed input files can trigger this test.
1145
       cf PR 21781.  */
1146
3
    _bfd_error_handler
1147
3
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1148
3
       abfd, found->symname);
1149
3
    return false;
1150
3
  }
1151
1152
      /* FIXME LATER: MSVC generates section names like .text for
1153
   comdats.  Gas generates names like .text$foo__Fv (in the case
1154
   of a function).  See comment above for more.  */
1155
1156
0
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1157
  /* xgettext:c-format */
1158
0
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1159
0
            " does not match section name '%s'"),
1160
0
          abfd, found->symname, name);
1161
1162
0
      if (found->comdat_symbol != -1)
1163
0
  {
1164
0
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1165
0
           found->comdat_symbol))
1166
0
      return false;
1167
0
  }
1168
0
      *sec_flags = *sec_flags | found->sec_flags;
1169
0
      return true;
1170
0
    }
1171
1
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1172
1
  return true;
1173
4
}
pe-arm.c:handle_COMDAT
Line
Count
Source
1110
4
{
1111
4
  if (pe_data (abfd)->comdat_hash == NULL)
1112
4
    {
1113
4
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1114
4
             comdat_delf);
1115
4
      if (pe_data (abfd)->comdat_hash == NULL)
1116
0
  return false;
1117
4
    }
1118
1119
4
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1120
4
    if (! fill_comdat_hash (abfd))
1121
0
      return false;
1122
1123
4
  struct comdat_hash_entry *found
1124
4
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1125
4
  if (found != NULL)
1126
3
    {
1127
3
      struct internal_syment isym = found->isym;
1128
1129
      /* If it isn't the stuff we're expecting, die;  The MS
1130
   documentation is vague, but it appears that the second entry
1131
   serves BOTH as the comdat symbol and the defining symbol
1132
   record (either C_STAT or C_EXT, possibly with an aux entry
1133
   with debug information if it's a function.)  It appears the
1134
   only way to find the second one is to count.  (On Intel, they
1135
   appear to be adjacent, but on Alpha, they have been found
1136
   separated.)
1137
1138
   Here, we think we've found the first one, but there's some
1139
   checking we can do to be sure.  */
1140
1141
3
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1142
3
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1143
3
  {
1144
    /* Malformed input files can trigger this test.
1145
       cf PR 21781.  */
1146
3
    _bfd_error_handler
1147
3
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1148
3
       abfd, found->symname);
1149
3
    return false;
1150
3
  }
1151
1152
      /* FIXME LATER: MSVC generates section names like .text for
1153
   comdats.  Gas generates names like .text$foo__Fv (in the case
1154
   of a function).  See comment above for more.  */
1155
1156
0
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1157
  /* xgettext:c-format */
1158
0
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1159
0
            " does not match section name '%s'"),
1160
0
          abfd, found->symname, name);
1161
1162
0
      if (found->comdat_symbol != -1)
1163
0
  {
1164
0
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1165
0
           found->comdat_symbol))
1166
0
      return false;
1167
0
  }
1168
0
      *sec_flags = *sec_flags | found->sec_flags;
1169
0
      return true;
1170
0
    }
1171
1
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1172
1
  return true;
1173
4
}
pe-i386.c:handle_COMDAT
Line
Count
Source
1110
141
{
1111
141
  if (pe_data (abfd)->comdat_hash == NULL)
1112
99
    {
1113
99
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1114
99
             comdat_delf);
1115
99
      if (pe_data (abfd)->comdat_hash == NULL)
1116
0
  return false;
1117
99
    }
1118
1119
141
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1120
141
    if (! fill_comdat_hash (abfd))
1121
0
      return false;
1122
1123
141
  struct comdat_hash_entry *found
1124
141
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1125
141
  if (found != NULL)
1126
18
    {
1127
18
      struct internal_syment isym = found->isym;
1128
1129
      /* If it isn't the stuff we're expecting, die;  The MS
1130
   documentation is vague, but it appears that the second entry
1131
   serves BOTH as the comdat symbol and the defining symbol
1132
   record (either C_STAT or C_EXT, possibly with an aux entry
1133
   with debug information if it's a function.)  It appears the
1134
   only way to find the second one is to count.  (On Intel, they
1135
   appear to be adjacent, but on Alpha, they have been found
1136
   separated.)
1137
1138
   Here, we think we've found the first one, but there's some
1139
   checking we can do to be sure.  */
1140
1141
18
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1142
18
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1143
10
  {
1144
    /* Malformed input files can trigger this test.
1145
       cf PR 21781.  */
1146
10
    _bfd_error_handler
1147
10
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1148
10
       abfd, found->symname);
1149
10
    return false;
1150
10
  }
1151
1152
      /* FIXME LATER: MSVC generates section names like .text for
1153
   comdats.  Gas generates names like .text$foo__Fv (in the case
1154
   of a function).  See comment above for more.  */
1155
1156
8
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1157
  /* xgettext:c-format */
1158
0
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1159
0
            " does not match section name '%s'"),
1160
0
          abfd, found->symname, name);
1161
1162
8
      if (found->comdat_symbol != -1)
1163
3
  {
1164
3
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1165
3
           found->comdat_symbol))
1166
0
      return false;
1167
3
  }
1168
8
      *sec_flags = *sec_flags | found->sec_flags;
1169
8
      return true;
1170
8
    }
1171
123
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1172
123
  return true;
1173
141
}
pe-mcore.c:handle_COMDAT
Line
Count
Source
1110
1
{
1111
1
  if (pe_data (abfd)->comdat_hash == NULL)
1112
1
    {
1113
1
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1114
1
             comdat_delf);
1115
1
      if (pe_data (abfd)->comdat_hash == NULL)
1116
0
  return false;
1117
1
    }
1118
1119
1
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1120
1
    if (! fill_comdat_hash (abfd))
1121
0
      return false;
1122
1123
1
  struct comdat_hash_entry *found
1124
1
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1125
1
  if (found != NULL)
1126
1
    {
1127
1
      struct internal_syment isym = found->isym;
1128
1129
      /* If it isn't the stuff we're expecting, die;  The MS
1130
   documentation is vague, but it appears that the second entry
1131
   serves BOTH as the comdat symbol and the defining symbol
1132
   record (either C_STAT or C_EXT, possibly with an aux entry
1133
   with debug information if it's a function.)  It appears the
1134
   only way to find the second one is to count.  (On Intel, they
1135
   appear to be adjacent, but on Alpha, they have been found
1136
   separated.)
1137
1138
   Here, we think we've found the first one, but there's some
1139
   checking we can do to be sure.  */
1140
1141
1
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1142
1
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1143
1
  {
1144
    /* Malformed input files can trigger this test.
1145
       cf PR 21781.  */
1146
1
    _bfd_error_handler
1147
1
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1148
1
       abfd, found->symname);
1149
1
    return false;
1150
1
  }
1151
1152
      /* FIXME LATER: MSVC generates section names like .text for
1153
   comdats.  Gas generates names like .text$foo__Fv (in the case
1154
   of a function).  See comment above for more.  */
1155
1156
0
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1157
  /* xgettext:c-format */
1158
0
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1159
0
            " does not match section name '%s'"),
1160
0
          abfd, found->symname, name);
1161
1162
0
      if (found->comdat_symbol != -1)
1163
0
  {
1164
0
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1165
0
           found->comdat_symbol))
1166
0
      return false;
1167
0
  }
1168
0
      *sec_flags = *sec_flags | found->sec_flags;
1169
0
      return true;
1170
0
    }
1171
0
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1172
0
  return true;
1173
1
}
pe-sh.c:handle_COMDAT
Line
Count
Source
1110
1.27k
{
1111
1.27k
  if (pe_data (abfd)->comdat_hash == NULL)
1112
763
    {
1113
763
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1114
763
             comdat_delf);
1115
763
      if (pe_data (abfd)->comdat_hash == NULL)
1116
0
  return false;
1117
763
    }
1118
1119
1.27k
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1120
763
    if (! fill_comdat_hash (abfd))
1121
0
      return false;
1122
1123
1.27k
  struct comdat_hash_entry *found
1124
1.27k
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1125
1.27k
  if (found != NULL)
1126
639
    {
1127
639
      struct internal_syment isym = found->isym;
1128
1129
      /* If it isn't the stuff we're expecting, die;  The MS
1130
   documentation is vague, but it appears that the second entry
1131
   serves BOTH as the comdat symbol and the defining symbol
1132
   record (either C_STAT or C_EXT, possibly with an aux entry
1133
   with debug information if it's a function.)  It appears the
1134
   only way to find the second one is to count.  (On Intel, they
1135
   appear to be adjacent, but on Alpha, they have been found
1136
   separated.)
1137
1138
   Here, we think we've found the first one, but there's some
1139
   checking we can do to be sure.  */
1140
1141
639
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1142
639
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1143
534
  {
1144
    /* Malformed input files can trigger this test.
1145
       cf PR 21781.  */
1146
534
    _bfd_error_handler
1147
534
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1148
534
       abfd, found->symname);
1149
534
    return false;
1150
534
  }
1151
1152
      /* FIXME LATER: MSVC generates section names like .text for
1153
   comdats.  Gas generates names like .text$foo__Fv (in the case
1154
   of a function).  See comment above for more.  */
1155
1156
105
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1157
  /* xgettext:c-format */
1158
0
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1159
0
            " does not match section name '%s'"),
1160
0
          abfd, found->symname, name);
1161
1162
105
      if (found->comdat_symbol != -1)
1163
103
  {
1164
103
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1165
103
           found->comdat_symbol))
1166
0
      return false;
1167
103
  }
1168
105
      *sec_flags = *sec_flags | found->sec_flags;
1169
105
      return true;
1170
105
    }
1171
634
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1172
634
  return true;
1173
1.27k
}
Unexecuted instantiation: pei-arm-wince.c:handle_COMDAT
Unexecuted instantiation: pei-arm.c:handle_COMDAT
Unexecuted instantiation: pei-mcore.c:handle_COMDAT
pei-sh.c:handle_COMDAT
Line
Count
Source
1110
7
{
1111
7
  if (pe_data (abfd)->comdat_hash == NULL)
1112
7
    {
1113
7
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1114
7
             comdat_delf);
1115
7
      if (pe_data (abfd)->comdat_hash == NULL)
1116
0
  return false;
1117
7
    }
1118
1119
7
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1120
7
    if (! fill_comdat_hash (abfd))
1121
0
      return false;
1122
1123
7
  struct comdat_hash_entry *found
1124
7
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1125
7
  if (found != NULL)
1126
0
    {
1127
0
      struct internal_syment isym = found->isym;
1128
1129
      /* If it isn't the stuff we're expecting, die;  The MS
1130
   documentation is vague, but it appears that the second entry
1131
   serves BOTH as the comdat symbol and the defining symbol
1132
   record (either C_STAT or C_EXT, possibly with an aux entry
1133
   with debug information if it's a function.)  It appears the
1134
   only way to find the second one is to count.  (On Intel, they
1135
   appear to be adjacent, but on Alpha, they have been found
1136
   separated.)
1137
1138
   Here, we think we've found the first one, but there's some
1139
   checking we can do to be sure.  */
1140
1141
0
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1142
0
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1143
0
  {
1144
    /* Malformed input files can trigger this test.
1145
       cf PR 21781.  */
1146
0
    _bfd_error_handler
1147
0
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1148
0
       abfd, found->symname);
1149
0
    return false;
1150
0
  }
1151
1152
      /* FIXME LATER: MSVC generates section names like .text for
1153
   comdats.  Gas generates names like .text$foo__Fv (in the case
1154
   of a function).  See comment above for more.  */
1155
1156
0
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1157
  /* xgettext:c-format */
1158
0
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1159
0
            " does not match section name '%s'"),
1160
0
          abfd, found->symname, name);
1161
1162
0
      if (found->comdat_symbol != -1)
1163
0
  {
1164
0
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1165
0
           found->comdat_symbol))
1166
0
      return false;
1167
0
  }
1168
0
      *sec_flags = *sec_flags | found->sec_flags;
1169
0
      return true;
1170
0
    }
1171
7
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1172
7
  return true;
1173
7
}
1174
1175
1176
/* The PE version; see above for the general comments.
1177
1178
   Since to set the SEC_LINK_ONCE and associated flags, we have to
1179
   look at the symbol table anyway, we return the symbol table index
1180
   of the symbol being used as the COMDAT symbol.  This is admittedly
1181
   ugly, but there's really nowhere else that we have access to the
1182
   required information.  FIXME: Is the COMDAT symbol index used for
1183
   any purpose other than objdump?  */
1184
1185
static bool
1186
styp_to_sec_flags (bfd *abfd,
1187
       void * hdr,
1188
       const char *name,
1189
       asection *section,
1190
       flagword *flags_ptr)
1191
19.3k
{
1192
19.3k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1193
19.3k
  unsigned long styp_flags = internal_s->s_flags;
1194
19.3k
  flagword sec_flags;
1195
19.3k
  bool result = true;
1196
19.3k
  bool is_dbg = false;
1197
1198
19.3k
  if (startswith (name, DOT_DEBUG)
1199
19.3k
      || startswith (name, DOT_ZDEBUG)
1200
19.3k
#ifdef COFF_LONG_SECTION_NAMES
1201
19.3k
      || startswith (name, GNU_LINKONCE_WI)
1202
19.3k
      || startswith (name, GNU_LINKONCE_WT)
1203
      /* FIXME: These definitions ought to be in a header file.  */
1204
19.3k
#define GNU_DEBUGLINK   ".gnu_debuglink"
1205
19.3k
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1206
19.3k
      || startswith (name, GNU_DEBUGLINK)
1207
19.3k
      || startswith (name, GNU_DEBUGALTLINK)
1208
19.3k
#endif
1209
19.3k
      || startswith (name, ".stab"))
1210
362
    is_dbg = true;
1211
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1212
19.3k
  sec_flags = SEC_READONLY;
1213
1214
  /* If section disallows read, then set the NOREAD flag. */
1215
19.3k
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1216
17.4k
    sec_flags |= SEC_COFF_NOREAD;
1217
1218
  /* Process each flag bit in styp_flags in turn.  */
1219
70.8k
  while (styp_flags)
1220
51.4k
    {
1221
51.4k
      unsigned long flag = styp_flags & - styp_flags;
1222
51.4k
      char * unhandled = NULL;
1223
1224
51.4k
      styp_flags &= ~ flag;
1225
1226
      /* We infer from the distinct read/write/execute bits the settings
1227
   of some of the bfd flags; the actual values, should we need them,
1228
   are also in pei_section_data (abfd, section)->pe_flags.  */
1229
1230
51.4k
      switch (flag)
1231
51.4k
  {
1232
647
  case STYP_DSECT:
1233
647
    unhandled = "STYP_DSECT";
1234
647
    break;
1235
431
  case STYP_GROUP:
1236
431
    unhandled = "STYP_GROUP";
1237
431
    break;
1238
318
  case STYP_COPY:
1239
318
    unhandled = "STYP_COPY";
1240
318
    break;
1241
420
  case STYP_OVER:
1242
420
    unhandled = "STYP_OVER";
1243
420
    break;
1244
0
#ifdef SEC_NEVER_LOAD
1245
2.99k
  case STYP_NOLOAD:
1246
2.99k
    sec_flags |= SEC_NEVER_LOAD;
1247
2.99k
    break;
1248
0
#endif
1249
1.87k
  case IMAGE_SCN_MEM_READ:
1250
1.87k
    sec_flags &= ~SEC_COFF_NOREAD;
1251
1.87k
    break;
1252
2.17k
  case IMAGE_SCN_TYPE_NO_PAD:
1253
    /* Skip.  */
1254
2.17k
    break;
1255
872
  case IMAGE_SCN_LNK_OTHER:
1256
872
    unhandled = "IMAGE_SCN_LNK_OTHER";
1257
872
    break;
1258
717
  case IMAGE_SCN_MEM_NOT_CACHED:
1259
717
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1260
717
    break;
1261
2.27k
  case IMAGE_SCN_MEM_NOT_PAGED:
1262
    /* Generate a warning message rather using the 'unhandled'
1263
       variable as this will allow some .sys files generate by
1264
       other toolchains to be processed.  See bugzilla issue 196.  */
1265
    /* xgettext:c-format */
1266
2.27k
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1267
2.27k
        " %s in section %s"),
1268
2.27k
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1269
2.27k
    break;
1270
1.52k
  case IMAGE_SCN_MEM_EXECUTE:
1271
1.52k
    sec_flags |= SEC_CODE;
1272
1.52k
    break;
1273
1.75k
  case IMAGE_SCN_MEM_WRITE:
1274
1.75k
    sec_flags &= ~ SEC_READONLY;
1275
1.75k
    break;
1276
2.85k
  case IMAGE_SCN_MEM_DISCARDABLE:
1277
    /* The MS PE spec says that debug sections are DISCARDABLE,
1278
       but the presence of a DISCARDABLE flag does not necessarily
1279
       mean that a given section contains debug information.  Thus
1280
       we only set the SEC_DEBUGGING flag on sections that we
1281
       recognise as containing debug information.  */
1282
2.85k
       if (is_dbg
1283
2.85k
#ifdef _COMMENT
1284
2.85k
        || strcmp (name, _COMMENT) == 0
1285
2.85k
#endif
1286
2.85k
        )
1287
273
      {
1288
273
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1289
273
      }
1290
2.85k
    break;
1291
1.49k
  case IMAGE_SCN_MEM_SHARED:
1292
1.49k
    sec_flags |= SEC_COFF_SHARED;
1293
1.49k
    break;
1294
2.85k
  case IMAGE_SCN_LNK_REMOVE:
1295
2.85k
    if (!is_dbg)
1296
2.84k
      sec_flags |= SEC_EXCLUDE;
1297
2.85k
    break;
1298
1.05k
  case IMAGE_SCN_CNT_CODE:
1299
1.05k
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1300
1.05k
    break;
1301
1.54k
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1302
1.54k
    if (is_dbg)
1303
214
      sec_flags |= SEC_DEBUGGING;
1304
1.32k
    else
1305
1.32k
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1306
1.54k
    break;
1307
1.74k
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1308
1.74k
    sec_flags |= SEC_ALLOC;
1309
1.74k
    break;
1310
2.64k
  case IMAGE_SCN_LNK_INFO:
1311
    /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
1312
       defined.  coff_compute_section_file_positions uses
1313
       COFF_PAGE_SIZE to ensure that the low order bits of the
1314
       section VMA and the file offset match.  If we don't know
1315
       COFF_PAGE_SIZE, we can't ensure the correct correspondence,
1316
       and demand page loading of the file will fail.  */
1317
#ifdef COFF_PAGE_SIZE
1318
662
    sec_flags |= SEC_DEBUGGING;
1319
#endif
1320
2.64k
    break;
1321
1.96k
  case IMAGE_SCN_LNK_COMDAT:
1322
    /* COMDAT gets very special treatment.  */
1323
1.96k
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1324
622
      result = false;
1325
1.96k
    break;
1326
19.2k
  default:
1327
    /* Silently ignore for now.  */
1328
19.2k
    break;
1329
51.4k
  }
1330
1331
      /* If the section flag was not handled, report it here.  */
1332
51.4k
      if (unhandled != NULL)
1333
3.40k
  {
1334
3.40k
    _bfd_error_handler
1335
      /* xgettext:c-format */
1336
3.40k
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1337
3.40k
       abfd, name, unhandled, flag);
1338
3.40k
    result = false;
1339
3.40k
  }
1340
51.4k
    }
1341
1342
19.3k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1343
19.3k
      && (startswith (name, ".sbss")
1344
0
    || startswith (name, ".sdata")))
1345
0
    sec_flags |= SEC_SMALL_DATA;
1346
1347
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
1348
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
1349
     only link a single copy of the section.  This is used to support
1350
     g++.  g++ will emit each template expansion in its own section.
1351
     The symbols will be defined as weak, so that multiple definitions
1352
     are permitted.  The GNU linker extension is to actually discard
1353
     all but one of the sections.  */
1354
2.50k
  if (startswith (name, ".gnu.linkonce"))
1355
0
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
1356
#endif
1357
1358
19.3k
  if (flags_ptr)
1359
19.3k
    * flags_ptr = sec_flags;
1360
1361
19.3k
  return result;
1362
19.3k
}
pei-i386.c:styp_to_sec_flags
Line
Count
Source
1191
177
{
1192
177
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1193
177
  unsigned long styp_flags = internal_s->s_flags;
1194
177
  flagword sec_flags;
1195
177
  bool result = true;
1196
177
  bool is_dbg = false;
1197
1198
177
  if (startswith (name, DOT_DEBUG)
1199
177
      || startswith (name, DOT_ZDEBUG)
1200
177
#ifdef COFF_LONG_SECTION_NAMES
1201
177
      || startswith (name, GNU_LINKONCE_WI)
1202
177
      || startswith (name, GNU_LINKONCE_WT)
1203
      /* FIXME: These definitions ought to be in a header file.  */
1204
177
#define GNU_DEBUGLINK   ".gnu_debuglink"
1205
177
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1206
177
      || startswith (name, GNU_DEBUGLINK)
1207
177
      || startswith (name, GNU_DEBUGALTLINK)
1208
177
#endif
1209
177
      || startswith (name, ".stab"))
1210
1
    is_dbg = true;
1211
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1212
177
  sec_flags = SEC_READONLY;
1213
1214
  /* If section disallows read, then set the NOREAD flag. */
1215
177
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1216
153
    sec_flags |= SEC_COFF_NOREAD;
1217
1218
  /* Process each flag bit in styp_flags in turn.  */
1219
736
  while (styp_flags)
1220
559
    {
1221
559
      unsigned long flag = styp_flags & - styp_flags;
1222
559
      char * unhandled = NULL;
1223
1224
559
      styp_flags &= ~ flag;
1225
1226
      /* We infer from the distinct read/write/execute bits the settings
1227
   of some of the bfd flags; the actual values, should we need them,
1228
   are also in pei_section_data (abfd, section)->pe_flags.  */
1229
1230
559
      switch (flag)
1231
559
  {
1232
6
  case STYP_DSECT:
1233
6
    unhandled = "STYP_DSECT";
1234
6
    break;
1235
2
  case STYP_GROUP:
1236
2
    unhandled = "STYP_GROUP";
1237
2
    break;
1238
0
  case STYP_COPY:
1239
0
    unhandled = "STYP_COPY";
1240
0
    break;
1241
2
  case STYP_OVER:
1242
2
    unhandled = "STYP_OVER";
1243
2
    break;
1244
0
#ifdef SEC_NEVER_LOAD
1245
0
  case STYP_NOLOAD:
1246
0
    sec_flags |= SEC_NEVER_LOAD;
1247
0
    break;
1248
0
#endif
1249
24
  case IMAGE_SCN_MEM_READ:
1250
24
    sec_flags &= ~SEC_COFF_NOREAD;
1251
24
    break;
1252
4
  case IMAGE_SCN_TYPE_NO_PAD:
1253
    /* Skip.  */
1254
4
    break;
1255
2
  case IMAGE_SCN_LNK_OTHER:
1256
2
    unhandled = "IMAGE_SCN_LNK_OTHER";
1257
2
    break;
1258
2
  case IMAGE_SCN_MEM_NOT_CACHED:
1259
2
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1260
2
    break;
1261
0
  case IMAGE_SCN_MEM_NOT_PAGED:
1262
    /* Generate a warning message rather using the 'unhandled'
1263
       variable as this will allow some .sys files generate by
1264
       other toolchains to be processed.  See bugzilla issue 196.  */
1265
    /* xgettext:c-format */
1266
0
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1267
0
        " %s in section %s"),
1268
0
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1269
0
    break;
1270
4
  case IMAGE_SCN_MEM_EXECUTE:
1271
4
    sec_flags |= SEC_CODE;
1272
4
    break;
1273
51
  case IMAGE_SCN_MEM_WRITE:
1274
51
    sec_flags &= ~ SEC_READONLY;
1275
51
    break;
1276
2
  case IMAGE_SCN_MEM_DISCARDABLE:
1277
    /* The MS PE spec says that debug sections are DISCARDABLE,
1278
       but the presence of a DISCARDABLE flag does not necessarily
1279
       mean that a given section contains debug information.  Thus
1280
       we only set the SEC_DEBUGGING flag on sections that we
1281
       recognise as containing debug information.  */
1282
2
       if (is_dbg
1283
2
#ifdef _COMMENT
1284
2
        || strcmp (name, _COMMENT) == 0
1285
2
#endif
1286
2
        )
1287
1
      {
1288
1
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1289
1
      }
1290
2
    break;
1291
0
  case IMAGE_SCN_MEM_SHARED:
1292
0
    sec_flags |= SEC_COFF_SHARED;
1293
0
    break;
1294
42
  case IMAGE_SCN_LNK_REMOVE:
1295
42
    if (!is_dbg)
1296
42
      sec_flags |= SEC_EXCLUDE;
1297
42
    break;
1298
4
  case IMAGE_SCN_CNT_CODE:
1299
4
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1300
4
    break;
1301
17
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1302
17
    if (is_dbg)
1303
1
      sec_flags |= SEC_DEBUGGING;
1304
16
    else
1305
16
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1306
17
    break;
1307
45
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1308
45
    sec_flags |= SEC_ALLOC;
1309
45
    break;
1310
0
  case IMAGE_SCN_LNK_INFO:
1311
    /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
1312
       defined.  coff_compute_section_file_positions uses
1313
       COFF_PAGE_SIZE to ensure that the low order bits of the
1314
       section VMA and the file offset match.  If we don't know
1315
       COFF_PAGE_SIZE, we can't ensure the correct correspondence,
1316
       and demand page loading of the file will fail.  */
1317
0
#ifdef COFF_PAGE_SIZE
1318
0
    sec_flags |= SEC_DEBUGGING;
1319
0
#endif
1320
0
    break;
1321
42
  case IMAGE_SCN_LNK_COMDAT:
1322
    /* COMDAT gets very special treatment.  */
1323
42
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1324
12
      result = false;
1325
42
    break;
1326
310
  default:
1327
    /* Silently ignore for now.  */
1328
310
    break;
1329
559
  }
1330
1331
      /* If the section flag was not handled, report it here.  */
1332
559
      if (unhandled != NULL)
1333
14
  {
1334
14
    _bfd_error_handler
1335
      /* xgettext:c-format */
1336
14
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1337
14
       abfd, name, unhandled, flag);
1338
14
    result = false;
1339
14
  }
1340
559
    }
1341
1342
177
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1343
177
      && (startswith (name, ".sbss")
1344
0
    || startswith (name, ".sdata")))
1345
0
    sec_flags |= SEC_SMALL_DATA;
1346
1347
177
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
1348
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
1349
     only link a single copy of the section.  This is used to support
1350
     g++.  g++ will emit each template expansion in its own section.
1351
     The symbols will be defined as weak, so that multiple definitions
1352
     are permitted.  The GNU linker extension is to actually discard
1353
     all but one of the sections.  */
1354
177
  if (startswith (name, ".gnu.linkonce"))
1355
0
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
1356
177
#endif
1357
1358
177
  if (flags_ptr)
1359
177
    * flags_ptr = sec_flags;
1360
1361
177
  return result;
1362
177
}
pe-x86_64.c:styp_to_sec_flags
Line
Count
Source
1191
529
{
1192
529
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1193
529
  unsigned long styp_flags = internal_s->s_flags;
1194
529
  flagword sec_flags;
1195
529
  bool result = true;
1196
529
  bool is_dbg = false;
1197
1198
529
  if (startswith (name, DOT_DEBUG)
1199
529
      || startswith (name, DOT_ZDEBUG)
1200
529
#ifdef COFF_LONG_SECTION_NAMES
1201
529
      || startswith (name, GNU_LINKONCE_WI)
1202
529
      || startswith (name, GNU_LINKONCE_WT)
1203
      /* FIXME: These definitions ought to be in a header file.  */
1204
529
#define GNU_DEBUGLINK   ".gnu_debuglink"
1205
529
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1206
529
      || startswith (name, GNU_DEBUGLINK)
1207
529
      || startswith (name, GNU_DEBUGALTLINK)
1208
529
#endif
1209
529
      || startswith (name, ".stab"))
1210
15
    is_dbg = true;
1211
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1212
529
  sec_flags = SEC_READONLY;
1213
1214
  /* If section disallows read, then set the NOREAD flag. */
1215
529
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1216
499
    sec_flags |= SEC_COFF_NOREAD;
1217
1218
  /* Process each flag bit in styp_flags in turn.  */
1219
1.67k
  while (styp_flags)
1220
1.14k
    {
1221
1.14k
      unsigned long flag = styp_flags & - styp_flags;
1222
1.14k
      char * unhandled = NULL;
1223
1224
1.14k
      styp_flags &= ~ flag;
1225
1226
      /* We infer from the distinct read/write/execute bits the settings
1227
   of some of the bfd flags; the actual values, should we need them,
1228
   are also in pei_section_data (abfd, section)->pe_flags.  */
1229
1230
1.14k
      switch (flag)
1231
1.14k
  {
1232
19
  case STYP_DSECT:
1233
19
    unhandled = "STYP_DSECT";
1234
19
    break;
1235
28
  case STYP_GROUP:
1236
28
    unhandled = "STYP_GROUP";
1237
28
    break;
1238
18
  case STYP_COPY:
1239
18
    unhandled = "STYP_COPY";
1240
18
    break;
1241
17
  case STYP_OVER:
1242
17
    unhandled = "STYP_OVER";
1243
17
    break;
1244
0
#ifdef SEC_NEVER_LOAD
1245
42
  case STYP_NOLOAD:
1246
42
    sec_flags |= SEC_NEVER_LOAD;
1247
42
    break;
1248
0
#endif
1249
30
  case IMAGE_SCN_MEM_READ:
1250
30
    sec_flags &= ~SEC_COFF_NOREAD;
1251
30
    break;
1252
38
  case IMAGE_SCN_TYPE_NO_PAD:
1253
    /* Skip.  */
1254
38
    break;
1255
29
  case IMAGE_SCN_LNK_OTHER:
1256
29
    unhandled = "IMAGE_SCN_LNK_OTHER";
1257
29
    break;
1258
25
  case IMAGE_SCN_MEM_NOT_CACHED:
1259
25
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1260
25
    break;
1261
46
  case IMAGE_SCN_MEM_NOT_PAGED:
1262
    /* Generate a warning message rather using the 'unhandled'
1263
       variable as this will allow some .sys files generate by
1264
       other toolchains to be processed.  See bugzilla issue 196.  */
1265
    /* xgettext:c-format */
1266
46
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1267
46
        " %s in section %s"),
1268
46
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1269
46
    break;
1270
47
  case IMAGE_SCN_MEM_EXECUTE:
1271
47
    sec_flags |= SEC_CODE;
1272
47
    break;
1273
32
  case IMAGE_SCN_MEM_WRITE:
1274
32
    sec_flags &= ~ SEC_READONLY;
1275
32
    break;
1276
67
  case IMAGE_SCN_MEM_DISCARDABLE:
1277
    /* The MS PE spec says that debug sections are DISCARDABLE,
1278
       but the presence of a DISCARDABLE flag does not necessarily
1279
       mean that a given section contains debug information.  Thus
1280
       we only set the SEC_DEBUGGING flag on sections that we
1281
       recognise as containing debug information.  */
1282
67
       if (is_dbg
1283
67
#ifdef _COMMENT
1284
67
        || strcmp (name, _COMMENT) == 0
1285
67
#endif
1286
67
        )
1287
3
      {
1288
3
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1289
3
      }
1290
67
    break;
1291
57
  case IMAGE_SCN_MEM_SHARED:
1292
57
    sec_flags |= SEC_COFF_SHARED;
1293
57
    break;
1294
48
  case IMAGE_SCN_LNK_REMOVE:
1295
48
    if (!is_dbg)
1296
45
      sec_flags |= SEC_EXCLUDE;
1297
48
    break;
1298
28
  case IMAGE_SCN_CNT_CODE:
1299
28
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1300
28
    break;
1301
21
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1302
21
    if (is_dbg)
1303
5
      sec_flags |= SEC_DEBUGGING;
1304
16
    else
1305
16
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1306
21
    break;
1307
18
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1308
18
    sec_flags |= SEC_ALLOC;
1309
18
    break;
1310
56
  case IMAGE_SCN_LNK_INFO:
1311
    /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
1312
       defined.  coff_compute_section_file_positions uses
1313
       COFF_PAGE_SIZE to ensure that the low order bits of the
1314
       section VMA and the file offset match.  If we don't know
1315
       COFF_PAGE_SIZE, we can't ensure the correct correspondence,
1316
       and demand page loading of the file will fail.  */
1317
56
#ifdef COFF_PAGE_SIZE
1318
56
    sec_flags |= SEC_DEBUGGING;
1319
56
#endif
1320
56
    break;
1321
40
  case IMAGE_SCN_LNK_COMDAT:
1322
    /* COMDAT gets very special treatment.  */
1323
40
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1324
15
      result = false;
1325
40
    break;
1326
440
  default:
1327
    /* Silently ignore for now.  */
1328
440
    break;
1329
1.14k
  }
1330
1331
      /* If the section flag was not handled, report it here.  */
1332
1.14k
      if (unhandled != NULL)
1333
136
  {
1334
136
    _bfd_error_handler
1335
      /* xgettext:c-format */
1336
136
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1337
136
       abfd, name, unhandled, flag);
1338
136
    result = false;
1339
136
  }
1340
1.14k
    }
1341
1342
529
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1343
529
      && (startswith (name, ".sbss")
1344
0
    || startswith (name, ".sdata")))
1345
0
    sec_flags |= SEC_SMALL_DATA;
1346
1347
529
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
1348
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
1349
     only link a single copy of the section.  This is used to support
1350
     g++.  g++ will emit each template expansion in its own section.
1351
     The symbols will be defined as weak, so that multiple definitions
1352
     are permitted.  The GNU linker extension is to actually discard
1353
     all but one of the sections.  */
1354
529
  if (startswith (name, ".gnu.linkonce"))
1355
0
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
1356
529
#endif
1357
1358
529
  if (flags_ptr)
1359
529
    * flags_ptr = sec_flags;
1360
1361
529
  return result;
1362
529
}
pei-x86_64.c:styp_to_sec_flags
Line
Count
Source
1191
766
{
1192
766
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1193
766
  unsigned long styp_flags = internal_s->s_flags;
1194
766
  flagword sec_flags;
1195
766
  bool result = true;
1196
766
  bool is_dbg = false;
1197
1198
766
  if (startswith (name, DOT_DEBUG)
1199
766
      || startswith (name, DOT_ZDEBUG)
1200
766
#ifdef COFF_LONG_SECTION_NAMES
1201
766
      || startswith (name, GNU_LINKONCE_WI)
1202
766
      || startswith (name, GNU_LINKONCE_WT)
1203
      /* FIXME: These definitions ought to be in a header file.  */
1204
766
#define GNU_DEBUGLINK   ".gnu_debuglink"
1205
766
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1206
766
      || startswith (name, GNU_DEBUGLINK)
1207
766
      || startswith (name, GNU_DEBUGALTLINK)
1208
766
#endif
1209
766
      || startswith (name, ".stab"))
1210
174
    is_dbg = true;
1211
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1212
766
  sec_flags = SEC_READONLY;
1213
1214
  /* If section disallows read, then set the NOREAD flag. */
1215
766
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1216
357
    sec_flags |= SEC_COFF_NOREAD;
1217
1218
  /* Process each flag bit in styp_flags in turn.  */
1219
2.39k
  while (styp_flags)
1220
1.63k
    {
1221
1.63k
      unsigned long flag = styp_flags & - styp_flags;
1222
1.63k
      char * unhandled = NULL;
1223
1224
1.63k
      styp_flags &= ~ flag;
1225
1226
      /* We infer from the distinct read/write/execute bits the settings
1227
   of some of the bfd flags; the actual values, should we need them,
1228
   are also in pei_section_data (abfd, section)->pe_flags.  */
1229
1230
1.63k
      switch (flag)
1231
1.63k
  {
1232
6
  case STYP_DSECT:
1233
6
    unhandled = "STYP_DSECT";
1234
6
    break;
1235
5
  case STYP_GROUP:
1236
5
    unhandled = "STYP_GROUP";
1237
5
    break;
1238
3
  case STYP_COPY:
1239
3
    unhandled = "STYP_COPY";
1240
3
    break;
1241
3
  case STYP_OVER:
1242
3
    unhandled = "STYP_OVER";
1243
3
    break;
1244
0
#ifdef SEC_NEVER_LOAD
1245
63
  case STYP_NOLOAD:
1246
63
    sec_flags |= SEC_NEVER_LOAD;
1247
63
    break;
1248
0
#endif
1249
409
  case IMAGE_SCN_MEM_READ:
1250
409
    sec_flags &= ~SEC_COFF_NOREAD;
1251
409
    break;
1252
4
  case IMAGE_SCN_TYPE_NO_PAD:
1253
    /* Skip.  */
1254
4
    break;
1255
8
  case IMAGE_SCN_LNK_OTHER:
1256
8
    unhandled = "IMAGE_SCN_LNK_OTHER";
1257
8
    break;
1258
3
  case IMAGE_SCN_MEM_NOT_CACHED:
1259
3
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1260
3
    break;
1261
4
  case IMAGE_SCN_MEM_NOT_PAGED:
1262
    /* Generate a warning message rather using the 'unhandled'
1263
       variable as this will allow some .sys files generate by
1264
       other toolchains to be processed.  See bugzilla issue 196.  */
1265
    /* xgettext:c-format */
1266
4
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1267
4
        " %s in section %s"),
1268
4
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1269
4
    break;
1270
23
  case IMAGE_SCN_MEM_EXECUTE:
1271
23
    sec_flags |= SEC_CODE;
1272
23
    break;
1273
75
  case IMAGE_SCN_MEM_WRITE:
1274
75
    sec_flags &= ~ SEC_READONLY;
1275
75
    break;
1276
293
  case IMAGE_SCN_MEM_DISCARDABLE:
1277
    /* The MS PE spec says that debug sections are DISCARDABLE,
1278
       but the presence of a DISCARDABLE flag does not necessarily
1279
       mean that a given section contains debug information.  Thus
1280
       we only set the SEC_DEBUGGING flag on sections that we
1281
       recognise as containing debug information.  */
1282
293
       if (is_dbg
1283
293
#ifdef _COMMENT
1284
293
        || strcmp (name, _COMMENT) == 0
1285
293
#endif
1286
293
        )
1287
174
      {
1288
174
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1289
174
      }
1290
293
    break;
1291
5
  case IMAGE_SCN_MEM_SHARED:
1292
5
    sec_flags |= SEC_COFF_SHARED;
1293
5
    break;
1294
8
  case IMAGE_SCN_LNK_REMOVE:
1295
8
    if (!is_dbg)
1296
6
      sec_flags |= SEC_EXCLUDE;
1297
8
    break;
1298
21
  case IMAGE_SCN_CNT_CODE:
1299
21
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1300
21
    break;
1301
390
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1302
390
    if (is_dbg)
1303
174
      sec_flags |= SEC_DEBUGGING;
1304
216
    else
1305
216
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1306
390
    break;
1307
20
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1308
20
    sec_flags |= SEC_ALLOC;
1309
20
    break;
1310
55
  case IMAGE_SCN_LNK_INFO:
1311
    /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
1312
       defined.  coff_compute_section_file_positions uses
1313
       COFF_PAGE_SIZE to ensure that the low order bits of the
1314
       section VMA and the file offset match.  If we don't know
1315
       COFF_PAGE_SIZE, we can't ensure the correct correspondence,
1316
       and demand page loading of the file will fail.  */
1317
55
#ifdef COFF_PAGE_SIZE
1318
55
    sec_flags |= SEC_DEBUGGING;
1319
55
#endif
1320
55
    break;
1321
46
  case IMAGE_SCN_LNK_COMDAT:
1322
    /* COMDAT gets very special treatment.  */
1323
46
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1324
4
      result = false;
1325
46
    break;
1326
188
  default:
1327
    /* Silently ignore for now.  */
1328
188
    break;
1329
1.63k
  }
1330
1331
      /* If the section flag was not handled, report it here.  */
1332
1.63k
      if (unhandled != NULL)
1333
28
  {
1334
28
    _bfd_error_handler
1335
      /* xgettext:c-format */
1336
28
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1337
28
       abfd, name, unhandled, flag);
1338
28
    result = false;
1339
28
  }
1340
1.63k
    }
1341
1342
766
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1343
766
      && (startswith (name, ".sbss")
1344
0
    || startswith (name, ".sdata")))
1345
0
    sec_flags |= SEC_SMALL_DATA;
1346
1347
766
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
1348
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
1349
     only link a single copy of the section.  This is used to support
1350
     g++.  g++ will emit each template expansion in its own section.
1351
     The symbols will be defined as weak, so that multiple definitions
1352
     are permitted.  The GNU linker extension is to actually discard
1353
     all but one of the sections.  */
1354
766
  if (startswith (name, ".gnu.linkonce"))
1355
0
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
1356
766
#endif
1357
1358
766
  if (flags_ptr)
1359
766
    * flags_ptr = sec_flags;
1360
1361
766
  return result;
1362
766
}
pe-aarch64.c:styp_to_sec_flags
Line
Count
Source
1191
179
{
1192
179
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1193
179
  unsigned long styp_flags = internal_s->s_flags;
1194
179
  flagword sec_flags;
1195
179
  bool result = true;
1196
179
  bool is_dbg = false;
1197
1198
179
  if (startswith (name, DOT_DEBUG)
1199
179
      || startswith (name, DOT_ZDEBUG)
1200
179
#ifdef COFF_LONG_SECTION_NAMES
1201
179
      || startswith (name, GNU_LINKONCE_WI)
1202
179
      || startswith (name, GNU_LINKONCE_WT)
1203
      /* FIXME: These definitions ought to be in a header file.  */
1204
179
#define GNU_DEBUGLINK   ".gnu_debuglink"
1205
179
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1206
179
      || startswith (name, GNU_DEBUGLINK)
1207
179
      || startswith (name, GNU_DEBUGALTLINK)
1208
179
#endif
1209
179
      || startswith (name, ".stab"))
1210
36
    is_dbg = true;
1211
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1212
179
  sec_flags = SEC_READONLY;
1213
1214
  /* If section disallows read, then set the NOREAD flag. */
1215
179
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1216
141
    sec_flags |= SEC_COFF_NOREAD;
1217
1218
  /* Process each flag bit in styp_flags in turn.  */
1219
1.10k
  while (styp_flags)
1220
927
    {
1221
927
      unsigned long flag = styp_flags & - styp_flags;
1222
927
      char * unhandled = NULL;
1223
1224
927
      styp_flags &= ~ flag;
1225
1226
      /* We infer from the distinct read/write/execute bits the settings
1227
   of some of the bfd flags; the actual values, should we need them,
1228
   are also in pei_section_data (abfd, section)->pe_flags.  */
1229
1230
927
      switch (flag)
1231
927
  {
1232
2
  case STYP_DSECT:
1233
2
    unhandled = "STYP_DSECT";
1234
2
    break;
1235
2
  case STYP_GROUP:
1236
2
    unhandled = "STYP_GROUP";
1237
2
    break;
1238
2
  case STYP_COPY:
1239
2
    unhandled = "STYP_COPY";
1240
2
    break;
1241
2
  case STYP_OVER:
1242
2
    unhandled = "STYP_OVER";
1243
2
    break;
1244
0
#ifdef SEC_NEVER_LOAD
1245
2
  case STYP_NOLOAD:
1246
2
    sec_flags |= SEC_NEVER_LOAD;
1247
2
    break;
1248
0
#endif
1249
38
  case IMAGE_SCN_MEM_READ:
1250
38
    sec_flags &= ~SEC_COFF_NOREAD;
1251
38
    break;
1252
36
  case IMAGE_SCN_TYPE_NO_PAD:
1253
    /* Skip.  */
1254
36
    break;
1255
2
  case IMAGE_SCN_LNK_OTHER:
1256
2
    unhandled = "IMAGE_SCN_LNK_OTHER";
1257
2
    break;
1258
2
  case IMAGE_SCN_MEM_NOT_CACHED:
1259
2
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1260
2
    break;
1261
73
  case IMAGE_SCN_MEM_NOT_PAGED:
1262
    /* Generate a warning message rather using the 'unhandled'
1263
       variable as this will allow some .sys files generate by
1264
       other toolchains to be processed.  See bugzilla issue 196.  */
1265
    /* xgettext:c-format */
1266
73
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1267
73
        " %s in section %s"),
1268
73
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1269
73
    break;
1270
58
  case IMAGE_SCN_MEM_EXECUTE:
1271
58
    sec_flags |= SEC_CODE;
1272
58
    break;
1273
3
  case IMAGE_SCN_MEM_WRITE:
1274
3
    sec_flags &= ~ SEC_READONLY;
1275
3
    break;
1276
95
  case IMAGE_SCN_MEM_DISCARDABLE:
1277
    /* The MS PE spec says that debug sections are DISCARDABLE,
1278
       but the presence of a DISCARDABLE flag does not necessarily
1279
       mean that a given section contains debug information.  Thus
1280
       we only set the SEC_DEBUGGING flag on sections that we
1281
       recognise as containing debug information.  */
1282
95
       if (is_dbg
1283
95
#ifdef _COMMENT
1284
95
        || strcmp (name, _COMMENT) == 0
1285
95
#endif
1286
95
        )
1287
34
      {
1288
34
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1289
34
      }
1290
95
    break;
1291
95
  case IMAGE_SCN_MEM_SHARED:
1292
95
    sec_flags |= SEC_COFF_SHARED;
1293
95
    break;
1294
94
  case IMAGE_SCN_LNK_REMOVE:
1295
94
    if (!is_dbg)
1296
94
      sec_flags |= SEC_EXCLUDE;
1297
94
    break;
1298
2
  case IMAGE_SCN_CNT_CODE:
1299
2
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1300
2
    break;
1301
2
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1302
2
    if (is_dbg)
1303
0
      sec_flags |= SEC_DEBUGGING;
1304
2
    else
1305
2
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1306
2
    break;
1307
2
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1308
2
    sec_flags |= SEC_ALLOC;
1309
2
    break;
1310
2
  case IMAGE_SCN_LNK_INFO:
1311
    /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
1312
       defined.  coff_compute_section_file_positions uses
1313
       COFF_PAGE_SIZE to ensure that the low order bits of the
1314
       section VMA and the file offset match.  If we don't know
1315
       COFF_PAGE_SIZE, we can't ensure the correct correspondence,
1316
       and demand page loading of the file will fail.  */
1317
2
#ifdef COFF_PAGE_SIZE
1318
2
    sec_flags |= SEC_DEBUGGING;
1319
2
#endif
1320
2
    break;
1321
60
  case IMAGE_SCN_LNK_COMDAT:
1322
    /* COMDAT gets very special treatment.  */
1323
60
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1324
20
      result = false;
1325
60
    break;
1326
353
  default:
1327
    /* Silently ignore for now.  */
1328
353
    break;
1329
927
  }
1330
1331
      /* If the section flag was not handled, report it here.  */
1332
927
      if (unhandled != NULL)
1333
12
  {
1334
12
    _bfd_error_handler
1335
      /* xgettext:c-format */
1336
12
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1337
12
       abfd, name, unhandled, flag);
1338
12
    result = false;
1339
12
  }
1340
927
    }
1341
1342
179
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1343
179
      && (startswith (name, ".sbss")
1344
0
    || startswith (name, ".sdata")))
1345
0
    sec_flags |= SEC_SMALL_DATA;
1346
1347
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
1348
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
1349
     only link a single copy of the section.  This is used to support
1350
     g++.  g++ will emit each template expansion in its own section.
1351
     The symbols will be defined as weak, so that multiple definitions
1352
     are permitted.  The GNU linker extension is to actually discard
1353
     all but one of the sections.  */
1354
  if (startswith (name, ".gnu.linkonce"))
1355
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
1356
#endif
1357
1358
179
  if (flags_ptr)
1359
179
    * flags_ptr = sec_flags;
1360
1361
179
  return result;
1362
179
}
pei-aarch64.c:styp_to_sec_flags
Line
Count
Source
1191
5.44k
{
1192
5.44k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1193
5.44k
  unsigned long styp_flags = internal_s->s_flags;
1194
5.44k
  flagword sec_flags;
1195
5.44k
  bool result = true;
1196
5.44k
  bool is_dbg = false;
1197
1198
5.44k
  if (startswith (name, DOT_DEBUG)
1199
5.44k
      || startswith (name, DOT_ZDEBUG)
1200
5.44k
#ifdef COFF_LONG_SECTION_NAMES
1201
5.44k
      || startswith (name, GNU_LINKONCE_WI)
1202
5.44k
      || startswith (name, GNU_LINKONCE_WT)
1203
      /* FIXME: These definitions ought to be in a header file.  */
1204
5.44k
#define GNU_DEBUGLINK   ".gnu_debuglink"
1205
5.44k
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1206
5.44k
      || startswith (name, GNU_DEBUGLINK)
1207
5.44k
      || startswith (name, GNU_DEBUGALTLINK)
1208
5.44k
#endif
1209
5.44k
      || startswith (name, ".stab"))
1210
0
    is_dbg = true;
1211
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1212
5.44k
  sec_flags = SEC_READONLY;
1213
1214
  /* If section disallows read, then set the NOREAD flag. */
1215
5.44k
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1216
5.39k
    sec_flags |= SEC_COFF_NOREAD;
1217
1218
  /* Process each flag bit in styp_flags in turn.  */
1219
7.84k
  while (styp_flags)
1220
2.39k
    {
1221
2.39k
      unsigned long flag = styp_flags & - styp_flags;
1222
2.39k
      char * unhandled = NULL;
1223
1224
2.39k
      styp_flags &= ~ flag;
1225
1226
      /* We infer from the distinct read/write/execute bits the settings
1227
   of some of the bfd flags; the actual values, should we need them,
1228
   are also in pei_section_data (abfd, section)->pe_flags.  */
1229
1230
2.39k
      switch (flag)
1231
2.39k
  {
1232
20
  case STYP_DSECT:
1233
20
    unhandled = "STYP_DSECT";
1234
20
    break;
1235
20
  case STYP_GROUP:
1236
20
    unhandled = "STYP_GROUP";
1237
20
    break;
1238
24
  case STYP_COPY:
1239
24
    unhandled = "STYP_COPY";
1240
24
    break;
1241
16
  case STYP_OVER:
1242
16
    unhandled = "STYP_OVER";
1243
16
    break;
1244
0
#ifdef SEC_NEVER_LOAD
1245
53
  case STYP_NOLOAD:
1246
53
    sec_flags |= SEC_NEVER_LOAD;
1247
53
    break;
1248
0
#endif
1249
54
  case IMAGE_SCN_MEM_READ:
1250
54
    sec_flags &= ~SEC_COFF_NOREAD;
1251
54
    break;
1252
28
  case IMAGE_SCN_TYPE_NO_PAD:
1253
    /* Skip.  */
1254
28
    break;
1255
12
  case IMAGE_SCN_LNK_OTHER:
1256
12
    unhandled = "IMAGE_SCN_LNK_OTHER";
1257
12
    break;
1258
22
  case IMAGE_SCN_MEM_NOT_CACHED:
1259
22
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1260
22
    break;
1261
30
  case IMAGE_SCN_MEM_NOT_PAGED:
1262
    /* Generate a warning message rather using the 'unhandled'
1263
       variable as this will allow some .sys files generate by
1264
       other toolchains to be processed.  See bugzilla issue 196.  */
1265
    /* xgettext:c-format */
1266
30
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1267
30
        " %s in section %s"),
1268
30
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1269
30
    break;
1270
45
  case IMAGE_SCN_MEM_EXECUTE:
1271
45
    sec_flags |= SEC_CODE;
1272
45
    break;
1273
37
  case IMAGE_SCN_MEM_WRITE:
1274
37
    sec_flags &= ~ SEC_READONLY;
1275
37
    break;
1276
63
  case IMAGE_SCN_MEM_DISCARDABLE:
1277
    /* The MS PE spec says that debug sections are DISCARDABLE,
1278
       but the presence of a DISCARDABLE flag does not necessarily
1279
       mean that a given section contains debug information.  Thus
1280
       we only set the SEC_DEBUGGING flag on sections that we
1281
       recognise as containing debug information.  */
1282
63
       if (is_dbg
1283
63
#ifdef _COMMENT
1284
63
        || strcmp (name, _COMMENT) == 0
1285
63
#endif
1286
63
        )
1287
0
      {
1288
0
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1289
0
      }
1290
63
    break;
1291
35
  case IMAGE_SCN_MEM_SHARED:
1292
35
    sec_flags |= SEC_COFF_SHARED;
1293
35
    break;
1294
272
  case IMAGE_SCN_LNK_REMOVE:
1295
272
    if (!is_dbg)
1296
272
      sec_flags |= SEC_EXCLUDE;
1297
272
    break;
1298
24
  case IMAGE_SCN_CNT_CODE:
1299
24
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1300
24
    break;
1301
28
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1302
28
    if (is_dbg)
1303
0
      sec_flags |= SEC_DEBUGGING;
1304
28
    else
1305
28
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1306
28
    break;
1307
45
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1308
45
    sec_flags |= SEC_ALLOC;
1309
45
    break;
1310
49
  case IMAGE_SCN_LNK_INFO:
1311
    /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
1312
       defined.  coff_compute_section_file_positions uses
1313
       COFF_PAGE_SIZE to ensure that the low order bits of the
1314
       section VMA and the file offset match.  If we don't know
1315
       COFF_PAGE_SIZE, we can't ensure the correct correspondence,
1316
       and demand page loading of the file will fail.  */
1317
49
#ifdef COFF_PAGE_SIZE
1318
49
    sec_flags |= SEC_DEBUGGING;
1319
49
#endif
1320
49
    break;
1321
272
  case IMAGE_SCN_LNK_COMDAT:
1322
    /* COMDAT gets very special treatment.  */
1323
272
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1324
2
      result = false;
1325
272
    break;
1326
1.24k
  default:
1327
    /* Silently ignore for now.  */
1328
1.24k
    break;
1329
2.39k
  }
1330
1331
      /* If the section flag was not handled, report it here.  */
1332
2.39k
      if (unhandled != NULL)
1333
114
  {
1334
114
    _bfd_error_handler
1335
      /* xgettext:c-format */
1336
114
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1337
114
       abfd, name, unhandled, flag);
1338
114
    result = false;
1339
114
  }
1340
2.39k
    }
1341
1342
5.44k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1343
5.44k
      && (startswith (name, ".sbss")
1344
0
    || startswith (name, ".sdata")))
1345
0
    sec_flags |= SEC_SMALL_DATA;
1346
1347
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
1348
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
1349
     only link a single copy of the section.  This is used to support
1350
     g++.  g++ will emit each template expansion in its own section.
1351
     The symbols will be defined as weak, so that multiple definitions
1352
     are permitted.  The GNU linker extension is to actually discard
1353
     all but one of the sections.  */
1354
  if (startswith (name, ".gnu.linkonce"))
1355
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
1356
#endif
1357
1358
5.44k
  if (flags_ptr)
1359
5.44k
    * flags_ptr = sec_flags;
1360
1361
5.44k
  return result;
1362
5.44k
}
pei-ia64.c:styp_to_sec_flags
Line
Count
Source
1191
155
{
1192
155
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1193
155
  unsigned long styp_flags = internal_s->s_flags;
1194
155
  flagword sec_flags;
1195
155
  bool result = true;
1196
155
  bool is_dbg = false;
1197
1198
155
  if (startswith (name, DOT_DEBUG)
1199
155
      || startswith (name, DOT_ZDEBUG)
1200
155
#ifdef COFF_LONG_SECTION_NAMES
1201
155
      || startswith (name, GNU_LINKONCE_WI)
1202
155
      || startswith (name, GNU_LINKONCE_WT)
1203
      /* FIXME: These definitions ought to be in a header file.  */
1204
155
#define GNU_DEBUGLINK   ".gnu_debuglink"
1205
155
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1206
155
      || startswith (name, GNU_DEBUGLINK)
1207
155
      || startswith (name, GNU_DEBUGALTLINK)
1208
155
#endif
1209
155
      || startswith (name, ".stab"))
1210
0
    is_dbg = true;
1211
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1212
155
  sec_flags = SEC_READONLY;
1213
1214
  /* If section disallows read, then set the NOREAD flag. */
1215
155
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1216
145
    sec_flags |= SEC_COFF_NOREAD;
1217
1218
  /* Process each flag bit in styp_flags in turn.  */
1219
549
  while (styp_flags)
1220
394
    {
1221
394
      unsigned long flag = styp_flags & - styp_flags;
1222
394
      char * unhandled = NULL;
1223
1224
394
      styp_flags &= ~ flag;
1225
1226
      /* We infer from the distinct read/write/execute bits the settings
1227
   of some of the bfd flags; the actual values, should we need them,
1228
   are also in pei_section_data (abfd, section)->pe_flags.  */
1229
1230
394
      switch (flag)
1231
394
  {
1232
6
  case STYP_DSECT:
1233
6
    unhandled = "STYP_DSECT";
1234
6
    break;
1235
6
  case STYP_GROUP:
1236
6
    unhandled = "STYP_GROUP";
1237
6
    break;
1238
8
  case STYP_COPY:
1239
8
    unhandled = "STYP_COPY";
1240
8
    break;
1241
8
  case STYP_OVER:
1242
8
    unhandled = "STYP_OVER";
1243
8
    break;
1244
0
#ifdef SEC_NEVER_LOAD
1245
6
  case STYP_NOLOAD:
1246
6
    sec_flags |= SEC_NEVER_LOAD;
1247
6
    break;
1248
0
#endif
1249
10
  case IMAGE_SCN_MEM_READ:
1250
10
    sec_flags &= ~SEC_COFF_NOREAD;
1251
10
    break;
1252
8
  case IMAGE_SCN_TYPE_NO_PAD:
1253
    /* Skip.  */
1254
8
    break;
1255
10
  case IMAGE_SCN_LNK_OTHER:
1256
10
    unhandled = "IMAGE_SCN_LNK_OTHER";
1257
10
    break;
1258
8
  case IMAGE_SCN_MEM_NOT_CACHED:
1259
8
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1260
8
    break;
1261
9
  case IMAGE_SCN_MEM_NOT_PAGED:
1262
    /* Generate a warning message rather using the 'unhandled'
1263
       variable as this will allow some .sys files generate by
1264
       other toolchains to be processed.  See bugzilla issue 196.  */
1265
    /* xgettext:c-format */
1266
9
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1267
9
        " %s in section %s"),
1268
9
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1269
9
    break;
1270
10
  case IMAGE_SCN_MEM_EXECUTE:
1271
10
    sec_flags |= SEC_CODE;
1272
10
    break;
1273
8
  case IMAGE_SCN_MEM_WRITE:
1274
8
    sec_flags &= ~ SEC_READONLY;
1275
8
    break;
1276
7
  case IMAGE_SCN_MEM_DISCARDABLE:
1277
    /* The MS PE spec says that debug sections are DISCARDABLE,
1278
       but the presence of a DISCARDABLE flag does not necessarily
1279
       mean that a given section contains debug information.  Thus
1280
       we only set the SEC_DEBUGGING flag on sections that we
1281
       recognise as containing debug information.  */
1282
7
       if (is_dbg
1283
7
#ifdef _COMMENT
1284
7
        || strcmp (name, _COMMENT) == 0
1285
7
#endif
1286
7
        )
1287
0
      {
1288
0
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1289
0
      }
1290
7
    break;
1291
43
  case IMAGE_SCN_MEM_SHARED:
1292
43
    sec_flags |= SEC_COFF_SHARED;
1293
43
    break;
1294
8
  case IMAGE_SCN_LNK_REMOVE:
1295
8
    if (!is_dbg)
1296
8
      sec_flags |= SEC_EXCLUDE;
1297
8
    break;
1298
6
  case IMAGE_SCN_CNT_CODE:
1299
6
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1300
6
    break;
1301
8
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1302
8
    if (is_dbg)
1303
0
      sec_flags |= SEC_DEBUGGING;
1304
8
    else
1305
8
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1306
8
    break;
1307
6
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1308
6
    sec_flags |= SEC_ALLOC;
1309
6
    break;
1310
8
  case IMAGE_SCN_LNK_INFO:
1311
    /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
1312
       defined.  coff_compute_section_file_positions uses
1313
       COFF_PAGE_SIZE to ensure that the low order bits of the
1314
       section VMA and the file offset match.  If we don't know
1315
       COFF_PAGE_SIZE, we can't ensure the correct correspondence,
1316
       and demand page loading of the file will fail.  */
1317
8
#ifdef COFF_PAGE_SIZE
1318
8
    sec_flags |= SEC_DEBUGGING;
1319
8
#endif
1320
8
    break;
1321
10
  case IMAGE_SCN_LNK_COMDAT:
1322
    /* COMDAT gets very special treatment.  */
1323
10
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1324
4
      result = false;
1325
10
    break;
1326
201
  default:
1327
    /* Silently ignore for now.  */
1328
201
    break;
1329
394
  }
1330
1331
      /* If the section flag was not handled, report it here.  */
1332
394
      if (unhandled != NULL)
1333
46
  {
1334
46
    _bfd_error_handler
1335
      /* xgettext:c-format */
1336
46
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1337
46
       abfd, name, unhandled, flag);
1338
46
    result = false;
1339
46
  }
1340
394
    }
1341
1342
155
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1343
155
      && (startswith (name, ".sbss")
1344
0
    || startswith (name, ".sdata")))
1345
0
    sec_flags |= SEC_SMALL_DATA;
1346
1347
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
1348
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
1349
     only link a single copy of the section.  This is used to support
1350
     g++.  g++ will emit each template expansion in its own section.
1351
     The symbols will be defined as weak, so that multiple definitions
1352
     are permitted.  The GNU linker extension is to actually discard
1353
     all but one of the sections.  */
1354
  if (startswith (name, ".gnu.linkonce"))
1355
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
1356
#endif
1357
1358
155
  if (flags_ptr)
1359
155
    * flags_ptr = sec_flags;
1360
1361
155
  return result;
1362
155
}
pei-loongarch64.c:styp_to_sec_flags
Line
Count
Source
1191
399
{
1192
399
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1193
399
  unsigned long styp_flags = internal_s->s_flags;
1194
399
  flagword sec_flags;
1195
399
  bool result = true;
1196
399
  bool is_dbg = false;
1197
1198
399
  if (startswith (name, DOT_DEBUG)
1199
399
      || startswith (name, DOT_ZDEBUG)
1200
399
#ifdef COFF_LONG_SECTION_NAMES
1201
399
      || startswith (name, GNU_LINKONCE_WI)
1202
399
      || startswith (name, GNU_LINKONCE_WT)
1203
      /* FIXME: These definitions ought to be in a header file.  */
1204
399
#define GNU_DEBUGLINK   ".gnu_debuglink"
1205
399
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1206
399
      || startswith (name, GNU_DEBUGLINK)
1207
399
      || startswith (name, GNU_DEBUGALTLINK)
1208
399
#endif
1209
399
      || startswith (name, ".stab"))
1210
30
    is_dbg = true;
1211
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1212
399
  sec_flags = SEC_READONLY;
1213
1214
  /* If section disallows read, then set the NOREAD flag. */
1215
399
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1216
397
    sec_flags |= SEC_COFF_NOREAD;
1217
1218
  /* Process each flag bit in styp_flags in turn.  */
1219
1.09k
  while (styp_flags)
1220
694
    {
1221
694
      unsigned long flag = styp_flags & - styp_flags;
1222
694
      char * unhandled = NULL;
1223
1224
694
      styp_flags &= ~ flag;
1225
1226
      /* We infer from the distinct read/write/execute bits the settings
1227
   of some of the bfd flags; the actual values, should we need them,
1228
   are also in pei_section_data (abfd, section)->pe_flags.  */
1229
1230
694
      switch (flag)
1231
694
  {
1232
2
  case STYP_DSECT:
1233
2
    unhandled = "STYP_DSECT";
1234
2
    break;
1235
2
  case STYP_GROUP:
1236
2
    unhandled = "STYP_GROUP";
1237
2
    break;
1238
0
  case STYP_COPY:
1239
0
    unhandled = "STYP_COPY";
1240
0
    break;
1241
0
  case STYP_OVER:
1242
0
    unhandled = "STYP_OVER";
1243
0
    break;
1244
0
#ifdef SEC_NEVER_LOAD
1245
11
  case STYP_NOLOAD:
1246
11
    sec_flags |= SEC_NEVER_LOAD;
1247
11
    break;
1248
0
#endif
1249
2
  case IMAGE_SCN_MEM_READ:
1250
2
    sec_flags &= ~SEC_COFF_NOREAD;
1251
2
    break;
1252
16
  case IMAGE_SCN_TYPE_NO_PAD:
1253
    /* Skip.  */
1254
16
    break;
1255
0
  case IMAGE_SCN_LNK_OTHER:
1256
0
    unhandled = "IMAGE_SCN_LNK_OTHER";
1257
0
    break;
1258
20
  case IMAGE_SCN_MEM_NOT_CACHED:
1259
20
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1260
20
    break;
1261
20
  case IMAGE_SCN_MEM_NOT_PAGED:
1262
    /* Generate a warning message rather using the 'unhandled'
1263
       variable as this will allow some .sys files generate by
1264
       other toolchains to be processed.  See bugzilla issue 196.  */
1265
    /* xgettext:c-format */
1266
20
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1267
20
        " %s in section %s"),
1268
20
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1269
20
    break;
1270
16
  case IMAGE_SCN_MEM_EXECUTE:
1271
16
    sec_flags |= SEC_CODE;
1272
16
    break;
1273
11
  case IMAGE_SCN_MEM_WRITE:
1274
11
    sec_flags &= ~ SEC_READONLY;
1275
11
    break;
1276
56
  case IMAGE_SCN_MEM_DISCARDABLE:
1277
    /* The MS PE spec says that debug sections are DISCARDABLE,
1278
       but the presence of a DISCARDABLE flag does not necessarily
1279
       mean that a given section contains debug information.  Thus
1280
       we only set the SEC_DEBUGGING flag on sections that we
1281
       recognise as containing debug information.  */
1282
56
       if (is_dbg
1283
56
#ifdef _COMMENT
1284
56
        || strcmp (name, _COMMENT) == 0
1285
56
#endif
1286
56
        )
1287
0
      {
1288
0
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1289
0
      }
1290
56
    break;
1291
12
  case IMAGE_SCN_MEM_SHARED:
1292
12
    sec_flags |= SEC_COFF_SHARED;
1293
12
    break;
1294
38
  case IMAGE_SCN_LNK_REMOVE:
1295
38
    if (!is_dbg)
1296
38
      sec_flags |= SEC_EXCLUDE;
1297
38
    break;
1298
11
  case IMAGE_SCN_CNT_CODE:
1299
11
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1300
11
    break;
1301
3
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1302
3
    if (is_dbg)
1303
0
      sec_flags |= SEC_DEBUGGING;
1304
3
    else
1305
3
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1306
3
    break;
1307
14
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1308
14
    sec_flags |= SEC_ALLOC;
1309
14
    break;
1310
39
  case IMAGE_SCN_LNK_INFO:
1311
    /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
1312
       defined.  coff_compute_section_file_positions uses
1313
       COFF_PAGE_SIZE to ensure that the low order bits of the
1314
       section VMA and the file offset match.  If we don't know
1315
       COFF_PAGE_SIZE, we can't ensure the correct correspondence,
1316
       and demand page loading of the file will fail.  */
1317
39
#ifdef COFF_PAGE_SIZE
1318
39
    sec_flags |= SEC_DEBUGGING;
1319
39
#endif
1320
39
    break;
1321
63
  case IMAGE_SCN_LNK_COMDAT:
1322
    /* COMDAT gets very special treatment.  */
1323
63
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1324
14
      result = false;
1325
63
    break;
1326
358
  default:
1327
    /* Silently ignore for now.  */
1328
358
    break;
1329
694
  }
1330
1331
      /* If the section flag was not handled, report it here.  */
1332
694
      if (unhandled != NULL)
1333
24
  {
1334
24
    _bfd_error_handler
1335
      /* xgettext:c-format */
1336
24
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1337
24
       abfd, name, unhandled, flag);
1338
24
    result = false;
1339
24
  }
1340
694
    }
1341
1342
399
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1343
399
      && (startswith (name, ".sbss")
1344
0
    || startswith (name, ".sdata")))
1345
0
    sec_flags |= SEC_SMALL_DATA;
1346
1347
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
1348
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
1349
     only link a single copy of the section.  This is used to support
1350
     g++.  g++ will emit each template expansion in its own section.
1351
     The symbols will be defined as weak, so that multiple definitions
1352
     are permitted.  The GNU linker extension is to actually discard
1353
     all but one of the sections.  */
1354
  if (startswith (name, ".gnu.linkonce"))
1355
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
1356
#endif
1357
1358
399
  if (flags_ptr)
1359
399
    * flags_ptr = sec_flags;
1360
1361
399
  return result;
1362
399
}
pe-arm-wince.c:styp_to_sec_flags
Line
Count
Source
1191
4
{
1192
4
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1193
4
  unsigned long styp_flags = internal_s->s_flags;
1194
4
  flagword sec_flags;
1195
4
  bool result = true;
1196
4
  bool is_dbg = false;
1197
1198
4
  if (startswith (name, DOT_DEBUG)
1199
4
      || startswith (name, DOT_ZDEBUG)
1200
4
#ifdef COFF_LONG_SECTION_NAMES
1201
4
      || startswith (name, GNU_LINKONCE_WI)
1202
4
      || startswith (name, GNU_LINKONCE_WT)
1203
      /* FIXME: These definitions ought to be in a header file.  */
1204
4
#define GNU_DEBUGLINK   ".gnu_debuglink"
1205
4
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1206
4
      || startswith (name, GNU_DEBUGLINK)
1207
4
      || startswith (name, GNU_DEBUGALTLINK)
1208
4
#endif
1209
4
      || startswith (name, ".stab"))
1210
0
    is_dbg = true;
1211
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1212
4
  sec_flags = SEC_READONLY;
1213
1214
  /* If section disallows read, then set the NOREAD flag. */
1215
4
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1216
0
    sec_flags |= SEC_COFF_NOREAD;
1217
1218
  /* Process each flag bit in styp_flags in turn.  */
1219
49
  while (styp_flags)
1220
45
    {
1221
45
      unsigned long flag = styp_flags & - styp_flags;
1222
45
      char * unhandled = NULL;
1223
1224
45
      styp_flags &= ~ flag;
1225
1226
      /* We infer from the distinct read/write/execute bits the settings
1227
   of some of the bfd flags; the actual values, should we need them,
1228
   are also in pei_section_data (abfd, section)->pe_flags.  */
1229
1230
45
      switch (flag)
1231
45
  {
1232
0
  case STYP_DSECT:
1233
0
    unhandled = "STYP_DSECT";
1234
0
    break;
1235
0
  case STYP_GROUP:
1236
0
    unhandled = "STYP_GROUP";
1237
0
    break;
1238
0
  case STYP_COPY:
1239
0
    unhandled = "STYP_COPY";
1240
0
    break;
1241
1
  case STYP_OVER:
1242
1
    unhandled = "STYP_OVER";
1243
1
    break;
1244
0
#ifdef SEC_NEVER_LOAD
1245
0
  case STYP_NOLOAD:
1246
0
    sec_flags |= SEC_NEVER_LOAD;
1247
0
    break;
1248
0
#endif
1249
4
  case IMAGE_SCN_MEM_READ:
1250
4
    sec_flags &= ~SEC_COFF_NOREAD;
1251
4
    break;
1252
0
  case IMAGE_SCN_TYPE_NO_PAD:
1253
    /* Skip.  */
1254
0
    break;
1255
1
  case IMAGE_SCN_LNK_OTHER:
1256
1
    unhandled = "IMAGE_SCN_LNK_OTHER";
1257
1
    break;
1258
1
  case IMAGE_SCN_MEM_NOT_CACHED:
1259
1
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1260
1
    break;
1261
1
  case IMAGE_SCN_MEM_NOT_PAGED:
1262
    /* Generate a warning message rather using the 'unhandled'
1263
       variable as this will allow some .sys files generate by
1264
       other toolchains to be processed.  See bugzilla issue 196.  */
1265
    /* xgettext:c-format */
1266
1
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1267
1
        " %s in section %s"),
1268
1
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1269
1
    break;
1270
4
  case IMAGE_SCN_MEM_EXECUTE:
1271
4
    sec_flags |= SEC_CODE;
1272
4
    break;
1273
4
  case IMAGE_SCN_MEM_WRITE:
1274
4
    sec_flags &= ~ SEC_READONLY;
1275
4
    break;
1276
1
  case IMAGE_SCN_MEM_DISCARDABLE:
1277
    /* The MS PE spec says that debug sections are DISCARDABLE,
1278
       but the presence of a DISCARDABLE flag does not necessarily
1279
       mean that a given section contains debug information.  Thus
1280
       we only set the SEC_DEBUGGING flag on sections that we
1281
       recognise as containing debug information.  */
1282
1
       if (is_dbg
1283
1
#ifdef _COMMENT
1284
1
        || strcmp (name, _COMMENT) == 0
1285
1
#endif
1286
1
        )
1287
0
      {
1288
0
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1289
0
      }
1290
1
    break;
1291
4
  case IMAGE_SCN_MEM_SHARED:
1292
4
    sec_flags |= SEC_COFF_SHARED;
1293
4
    break;
1294
1
  case IMAGE_SCN_LNK_REMOVE:
1295
1
    if (!is_dbg)
1296
1
      sec_flags |= SEC_EXCLUDE;
1297
1
    break;
1298
0
  case IMAGE_SCN_CNT_CODE:
1299
0
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1300
0
    break;
1301
0
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1302
0
    if (is_dbg)
1303
0
      sec_flags |= SEC_DEBUGGING;
1304
0
    else
1305
0
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1306
0
    break;
1307
0
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1308
0
    sec_flags |= SEC_ALLOC;
1309
0
    break;
1310
4
  case IMAGE_SCN_LNK_INFO:
1311
    /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
1312
       defined.  coff_compute_section_file_positions uses
1313
       COFF_PAGE_SIZE to ensure that the low order bits of the
1314
       section VMA and the file offset match.  If we don't know
1315
       COFF_PAGE_SIZE, we can't ensure the correct correspondence,
1316
       and demand page loading of the file will fail.  */
1317
4
#ifdef COFF_PAGE_SIZE
1318
4
    sec_flags |= SEC_DEBUGGING;
1319
4
#endif
1320
4
    break;
1321
4
  case IMAGE_SCN_LNK_COMDAT:
1322
    /* COMDAT gets very special treatment.  */
1323
4
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1324
3
      result = false;
1325
4
    break;
1326
15
  default:
1327
    /* Silently ignore for now.  */
1328
15
    break;
1329
45
  }
1330
1331
      /* If the section flag was not handled, report it here.  */
1332
45
      if (unhandled != NULL)
1333
3
  {
1334
3
    _bfd_error_handler
1335
      /* xgettext:c-format */
1336
3
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1337
3
       abfd, name, unhandled, flag);
1338
3
    result = false;
1339
3
  }
1340
45
    }
1341
1342
4
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1343
4
      && (startswith (name, ".sbss")
1344
0
    || startswith (name, ".sdata")))
1345
0
    sec_flags |= SEC_SMALL_DATA;
1346
1347
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
1348
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
1349
     only link a single copy of the section.  This is used to support
1350
     g++.  g++ will emit each template expansion in its own section.
1351
     The symbols will be defined as weak, so that multiple definitions
1352
     are permitted.  The GNU linker extension is to actually discard
1353
     all but one of the sections.  */
1354
  if (startswith (name, ".gnu.linkonce"))
1355
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
1356
#endif
1357
1358
4
  if (flags_ptr)
1359
4
    * flags_ptr = sec_flags;
1360
1361
4
  return result;
1362
4
}
pe-arm.c:styp_to_sec_flags
Line
Count
Source
1191
4
{
1192
4
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1193
4
  unsigned long styp_flags = internal_s->s_flags;
1194
4
  flagword sec_flags;
1195
4
  bool result = true;
1196
4
  bool is_dbg = false;
1197
1198
4
  if (startswith (name, DOT_DEBUG)
1199
4
      || startswith (name, DOT_ZDEBUG)
1200
4
#ifdef COFF_LONG_SECTION_NAMES
1201
4
      || startswith (name, GNU_LINKONCE_WI)
1202
4
      || startswith (name, GNU_LINKONCE_WT)
1203
      /* FIXME: These definitions ought to be in a header file.  */
1204
4
#define GNU_DEBUGLINK   ".gnu_debuglink"
1205
4
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1206
4
      || startswith (name, GNU_DEBUGLINK)
1207
4
      || startswith (name, GNU_DEBUGALTLINK)
1208
4
#endif
1209
4
      || startswith (name, ".stab"))
1210
0
    is_dbg = true;
1211
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1212
4
  sec_flags = SEC_READONLY;
1213
1214
  /* If section disallows read, then set the NOREAD flag. */
1215
4
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1216
0
    sec_flags |= SEC_COFF_NOREAD;
1217
1218
  /* Process each flag bit in styp_flags in turn.  */
1219
49
  while (styp_flags)
1220
45
    {
1221
45
      unsigned long flag = styp_flags & - styp_flags;
1222
45
      char * unhandled = NULL;
1223
1224
45
      styp_flags &= ~ flag;
1225
1226
      /* We infer from the distinct read/write/execute bits the settings
1227
   of some of the bfd flags; the actual values, should we need them,
1228
   are also in pei_section_data (abfd, section)->pe_flags.  */
1229
1230
45
      switch (flag)
1231
45
  {
1232
0
  case STYP_DSECT:
1233
0
    unhandled = "STYP_DSECT";
1234
0
    break;
1235
0
  case STYP_GROUP:
1236
0
    unhandled = "STYP_GROUP";
1237
0
    break;
1238
0
  case STYP_COPY:
1239
0
    unhandled = "STYP_COPY";
1240
0
    break;
1241
1
  case STYP_OVER:
1242
1
    unhandled = "STYP_OVER";
1243
1
    break;
1244
0
#ifdef SEC_NEVER_LOAD
1245
0
  case STYP_NOLOAD:
1246
0
    sec_flags |= SEC_NEVER_LOAD;
1247
0
    break;
1248
0
#endif
1249
4
  case IMAGE_SCN_MEM_READ:
1250
4
    sec_flags &= ~SEC_COFF_NOREAD;
1251
4
    break;
1252
0
  case IMAGE_SCN_TYPE_NO_PAD:
1253
    /* Skip.  */
1254
0
    break;
1255
1
  case IMAGE_SCN_LNK_OTHER:
1256
1
    unhandled = "IMAGE_SCN_LNK_OTHER";
1257
1
    break;
1258
1
  case IMAGE_SCN_MEM_NOT_CACHED:
1259
1
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1260
1
    break;
1261
1
  case IMAGE_SCN_MEM_NOT_PAGED:
1262
    /* Generate a warning message rather using the 'unhandled'
1263
       variable as this will allow some .sys files generate by
1264
       other toolchains to be processed.  See bugzilla issue 196.  */
1265
    /* xgettext:c-format */
1266
1
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1267
1
        " %s in section %s"),
1268
1
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1269
1
    break;
1270
4
  case IMAGE_SCN_MEM_EXECUTE:
1271
4
    sec_flags |= SEC_CODE;
1272
4
    break;
1273
4
  case IMAGE_SCN_MEM_WRITE:
1274
4
    sec_flags &= ~ SEC_READONLY;
1275
4
    break;
1276
1
  case IMAGE_SCN_MEM_DISCARDABLE:
1277
    /* The MS PE spec says that debug sections are DISCARDABLE,
1278
       but the presence of a DISCARDABLE flag does not necessarily
1279
       mean that a given section contains debug information.  Thus
1280
       we only set the SEC_DEBUGGING flag on sections that we
1281
       recognise as containing debug information.  */
1282
1
       if (is_dbg
1283
1
#ifdef _COMMENT
1284
1
        || strcmp (name, _COMMENT) == 0
1285
1
#endif
1286
1
        )
1287
0
      {
1288
0
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1289
0
      }
1290
1
    break;
1291
4
  case IMAGE_SCN_MEM_SHARED:
1292
4
    sec_flags |= SEC_COFF_SHARED;
1293
4
    break;
1294
1
  case IMAGE_SCN_LNK_REMOVE:
1295
1
    if (!is_dbg)
1296
1
      sec_flags |= SEC_EXCLUDE;
1297
1
    break;
1298
0
  case IMAGE_SCN_CNT_CODE:
1299
0
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1300
0
    break;
1301
0
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1302
0
    if (is_dbg)
1303
0
      sec_flags |= SEC_DEBUGGING;
1304
0
    else
1305
0
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1306
0
    break;
1307
0
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1308
0
    sec_flags |= SEC_ALLOC;
1309
0
    break;
1310
4
  case IMAGE_SCN_LNK_INFO:
1311
    /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
1312
       defined.  coff_compute_section_file_positions uses
1313
       COFF_PAGE_SIZE to ensure that the low order bits of the
1314
       section VMA and the file offset match.  If we don't know
1315
       COFF_PAGE_SIZE, we can't ensure the correct correspondence,
1316
       and demand page loading of the file will fail.  */
1317
4
#ifdef COFF_PAGE_SIZE
1318
4
    sec_flags |= SEC_DEBUGGING;
1319
4
#endif
1320
4
    break;
1321
4
  case IMAGE_SCN_LNK_COMDAT:
1322
    /* COMDAT gets very special treatment.  */
1323
4
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1324
3
      result = false;
1325
4
    break;
1326
15
  default:
1327
    /* Silently ignore for now.  */
1328
15
    break;
1329
45
  }
1330
1331
      /* If the section flag was not handled, report it here.  */
1332
45
      if (unhandled != NULL)
1333
3
  {
1334
3
    _bfd_error_handler
1335
      /* xgettext:c-format */
1336
3
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1337
3
       abfd, name, unhandled, flag);
1338
3
    result = false;
1339
3
  }
1340
45
    }
1341
1342
4
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1343
4
      && (startswith (name, ".sbss")
1344
0
    || startswith (name, ".sdata")))
1345
0
    sec_flags |= SEC_SMALL_DATA;
1346
1347
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
1348
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
1349
     only link a single copy of the section.  This is used to support
1350
     g++.  g++ will emit each template expansion in its own section.
1351
     The symbols will be defined as weak, so that multiple definitions
1352
     are permitted.  The GNU linker extension is to actually discard
1353
     all but one of the sections.  */
1354
  if (startswith (name, ".gnu.linkonce"))
1355
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
1356
#endif
1357
1358
4
  if (flags_ptr)
1359
4
    * flags_ptr = sec_flags;
1360
1361
4
  return result;
1362
4
}
pe-i386.c:styp_to_sec_flags
Line
Count
Source
1191
1.03k
{
1192
1.03k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1193
1.03k
  unsigned long styp_flags = internal_s->s_flags;
1194
1.03k
  flagword sec_flags;
1195
1.03k
  bool result = true;
1196
1.03k
  bool is_dbg = false;
1197
1198
1.03k
  if (startswith (name, DOT_DEBUG)
1199
1.03k
      || startswith (name, DOT_ZDEBUG)
1200
1.03k
#ifdef COFF_LONG_SECTION_NAMES
1201
1.03k
      || startswith (name, GNU_LINKONCE_WI)
1202
1.03k
      || startswith (name, GNU_LINKONCE_WT)
1203
      /* FIXME: These definitions ought to be in a header file.  */
1204
1.03k
#define GNU_DEBUGLINK   ".gnu_debuglink"
1205
1.03k
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1206
1.03k
      || startswith (name, GNU_DEBUGLINK)
1207
1.03k
      || startswith (name, GNU_DEBUGALTLINK)
1208
1.03k
#endif
1209
1.03k
      || startswith (name, ".stab"))
1210
21
    is_dbg = true;
1211
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1212
1.03k
  sec_flags = SEC_READONLY;
1213
1214
  /* If section disallows read, then set the NOREAD flag. */
1215
1.03k
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1216
739
    sec_flags |= SEC_COFF_NOREAD;
1217
1218
  /* Process each flag bit in styp_flags in turn.  */
1219
6.26k
  while (styp_flags)
1220
5.22k
    {
1221
5.22k
      unsigned long flag = styp_flags & - styp_flags;
1222
5.22k
      char * unhandled = NULL;
1223
1224
5.22k
      styp_flags &= ~ flag;
1225
1226
      /* We infer from the distinct read/write/execute bits the settings
1227
   of some of the bfd flags; the actual values, should we need them,
1228
   are also in pei_section_data (abfd, section)->pe_flags.  */
1229
1230
5.22k
      switch (flag)
1231
5.22k
  {
1232
14
  case STYP_DSECT:
1233
14
    unhandled = "STYP_DSECT";
1234
14
    break;
1235
14
  case STYP_GROUP:
1236
14
    unhandled = "STYP_GROUP";
1237
14
    break;
1238
6
  case STYP_COPY:
1239
6
    unhandled = "STYP_COPY";
1240
6
    break;
1241
71
  case STYP_OVER:
1242
71
    unhandled = "STYP_OVER";
1243
71
    break;
1244
0
#ifdef SEC_NEVER_LOAD
1245
113
  case STYP_NOLOAD:
1246
113
    sec_flags |= SEC_NEVER_LOAD;
1247
113
    break;
1248
0
#endif
1249
294
  case IMAGE_SCN_MEM_READ:
1250
294
    sec_flags &= ~SEC_COFF_NOREAD;
1251
294
    break;
1252
111
  case IMAGE_SCN_TYPE_NO_PAD:
1253
    /* Skip.  */
1254
111
    break;
1255
13
  case IMAGE_SCN_LNK_OTHER:
1256
13
    unhandled = "IMAGE_SCN_LNK_OTHER";
1257
13
    break;
1258
71
  case IMAGE_SCN_MEM_NOT_CACHED:
1259
71
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1260
71
    break;
1261
180
  case IMAGE_SCN_MEM_NOT_PAGED:
1262
    /* Generate a warning message rather using the 'unhandled'
1263
       variable as this will allow some .sys files generate by
1264
       other toolchains to be processed.  See bugzilla issue 196.  */
1265
    /* xgettext:c-format */
1266
180
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1267
180
        " %s in section %s"),
1268
180
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1269
180
    break;
1270
204
  case IMAGE_SCN_MEM_EXECUTE:
1271
204
    sec_flags |= SEC_CODE;
1272
204
    break;
1273
328
  case IMAGE_SCN_MEM_WRITE:
1274
328
    sec_flags &= ~ SEC_READONLY;
1275
328
    break;
1276
182
  case IMAGE_SCN_MEM_DISCARDABLE:
1277
    /* The MS PE spec says that debug sections are DISCARDABLE,
1278
       but the presence of a DISCARDABLE flag does not necessarily
1279
       mean that a given section contains debug information.  Thus
1280
       we only set the SEC_DEBUGGING flag on sections that we
1281
       recognise as containing debug information.  */
1282
182
       if (is_dbg
1283
182
#ifdef _COMMENT
1284
182
        || strcmp (name, _COMMENT) == 0
1285
182
#endif
1286
182
        )
1287
6
      {
1288
6
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1289
6
      }
1290
182
    break;
1291
62
  case IMAGE_SCN_MEM_SHARED:
1292
62
    sec_flags |= SEC_COFF_SHARED;
1293
62
    break;
1294
224
  case IMAGE_SCN_LNK_REMOVE:
1295
224
    if (!is_dbg)
1296
222
      sec_flags |= SEC_EXCLUDE;
1297
224
    break;
1298
164
  case IMAGE_SCN_CNT_CODE:
1299
164
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1300
164
    break;
1301
236
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1302
236
    if (is_dbg)
1303
2
      sec_flags |= SEC_DEBUGGING;
1304
234
    else
1305
234
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1306
236
    break;
1307
272
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1308
272
    sec_flags |= SEC_ALLOC;
1309
272
    break;
1310
161
  case IMAGE_SCN_LNK_INFO:
1311
    /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
1312
       defined.  coff_compute_section_file_positions uses
1313
       COFF_PAGE_SIZE to ensure that the low order bits of the
1314
       section VMA and the file offset match.  If we don't know
1315
       COFF_PAGE_SIZE, we can't ensure the correct correspondence,
1316
       and demand page loading of the file will fail.  */
1317
161
#ifdef COFF_PAGE_SIZE
1318
161
    sec_flags |= SEC_DEBUGGING;
1319
161
#endif
1320
161
    break;
1321
141
  case IMAGE_SCN_LNK_COMDAT:
1322
    /* COMDAT gets very special treatment.  */
1323
141
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1324
10
      result = false;
1325
141
    break;
1326
2.36k
  default:
1327
    /* Silently ignore for now.  */
1328
2.36k
    break;
1329
5.22k
  }
1330
1331
      /* If the section flag was not handled, report it here.  */
1332
5.22k
      if (unhandled != NULL)
1333
189
  {
1334
189
    _bfd_error_handler
1335
      /* xgettext:c-format */
1336
189
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1337
189
       abfd, name, unhandled, flag);
1338
189
    result = false;
1339
189
  }
1340
5.22k
    }
1341
1342
1.03k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1343
1.03k
      && (startswith (name, ".sbss")
1344
0
    || startswith (name, ".sdata")))
1345
0
    sec_flags |= SEC_SMALL_DATA;
1346
1347
1.03k
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
1348
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
1349
     only link a single copy of the section.  This is used to support
1350
     g++.  g++ will emit each template expansion in its own section.
1351
     The symbols will be defined as weak, so that multiple definitions
1352
     are permitted.  The GNU linker extension is to actually discard
1353
     all but one of the sections.  */
1354
1.03k
  if (startswith (name, ".gnu.linkonce"))
1355
0
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
1356
1.03k
#endif
1357
1358
1.03k
  if (flags_ptr)
1359
1.03k
    * flags_ptr = sec_flags;
1360
1361
1.03k
  return result;
1362
1.03k
}
pe-mcore.c:styp_to_sec_flags
Line
Count
Source
1191
200
{
1192
200
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1193
200
  unsigned long styp_flags = internal_s->s_flags;
1194
200
  flagword sec_flags;
1195
200
  bool result = true;
1196
200
  bool is_dbg = false;
1197
1198
200
  if (startswith (name, DOT_DEBUG)
1199
200
      || startswith (name, DOT_ZDEBUG)
1200
200
#ifdef COFF_LONG_SECTION_NAMES
1201
200
      || startswith (name, GNU_LINKONCE_WI)
1202
200
      || startswith (name, GNU_LINKONCE_WT)
1203
      /* FIXME: These definitions ought to be in a header file.  */
1204
200
#define GNU_DEBUGLINK   ".gnu_debuglink"
1205
200
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1206
200
      || startswith (name, GNU_DEBUGLINK)
1207
200
      || startswith (name, GNU_DEBUGALTLINK)
1208
200
#endif
1209
200
      || startswith (name, ".stab"))
1210
0
    is_dbg = true;
1211
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1212
200
  sec_flags = SEC_READONLY;
1213
1214
  /* If section disallows read, then set the NOREAD flag. */
1215
200
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1216
199
    sec_flags |= SEC_COFF_NOREAD;
1217
1218
  /* Process each flag bit in styp_flags in turn.  */
1219
247
  while (styp_flags)
1220
47
    {
1221
47
      unsigned long flag = styp_flags & - styp_flags;
1222
47
      char * unhandled = NULL;
1223
1224
47
      styp_flags &= ~ flag;
1225
1226
      /* We infer from the distinct read/write/execute bits the settings
1227
   of some of the bfd flags; the actual values, should we need them,
1228
   are also in pei_section_data (abfd, section)->pe_flags.  */
1229
1230
47
      switch (flag)
1231
47
  {
1232
1
  case STYP_DSECT:
1233
1
    unhandled = "STYP_DSECT";
1234
1
    break;
1235
1
  case STYP_GROUP:
1236
1
    unhandled = "STYP_GROUP";
1237
1
    break;
1238
0
  case STYP_COPY:
1239
0
    unhandled = "STYP_COPY";
1240
0
    break;
1241
0
  case STYP_OVER:
1242
0
    unhandled = "STYP_OVER";
1243
0
    break;
1244
0
#ifdef SEC_NEVER_LOAD
1245
5
  case STYP_NOLOAD:
1246
5
    sec_flags |= SEC_NEVER_LOAD;
1247
5
    break;
1248
0
#endif
1249
1
  case IMAGE_SCN_MEM_READ:
1250
1
    sec_flags &= ~SEC_COFF_NOREAD;
1251
1
    break;
1252
0
  case IMAGE_SCN_TYPE_NO_PAD:
1253
    /* Skip.  */
1254
0
    break;
1255
0
  case IMAGE_SCN_LNK_OTHER:
1256
0
    unhandled = "IMAGE_SCN_LNK_OTHER";
1257
0
    break;
1258
1
  case IMAGE_SCN_MEM_NOT_CACHED:
1259
1
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1260
1
    break;
1261
1
  case IMAGE_SCN_MEM_NOT_PAGED:
1262
    /* Generate a warning message rather using the 'unhandled'
1263
       variable as this will allow some .sys files generate by
1264
       other toolchains to be processed.  See bugzilla issue 196.  */
1265
    /* xgettext:c-format */
1266
1
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1267
1
        " %s in section %s"),
1268
1
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1269
1
    break;
1270
1
  case IMAGE_SCN_MEM_EXECUTE:
1271
1
    sec_flags |= SEC_CODE;
1272
1
    break;
1273
0
  case IMAGE_SCN_MEM_WRITE:
1274
0
    sec_flags &= ~ SEC_READONLY;
1275
0
    break;
1276
2
  case IMAGE_SCN_MEM_DISCARDABLE:
1277
    /* The MS PE spec says that debug sections are DISCARDABLE,
1278
       but the presence of a DISCARDABLE flag does not necessarily
1279
       mean that a given section contains debug information.  Thus
1280
       we only set the SEC_DEBUGGING flag on sections that we
1281
       recognise as containing debug information.  */
1282
2
       if (is_dbg
1283
2
#ifdef _COMMENT
1284
2
        || strcmp (name, _COMMENT) == 0
1285
2
#endif
1286
2
        )
1287
0
      {
1288
0
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1289
0
      }
1290
2
    break;
1291
0
  case IMAGE_SCN_MEM_SHARED:
1292
0
    sec_flags |= SEC_COFF_SHARED;
1293
0
    break;
1294
9
  case IMAGE_SCN_LNK_REMOVE:
1295
9
    if (!is_dbg)
1296
9
      sec_flags |= SEC_EXCLUDE;
1297
9
    break;
1298
1
  case IMAGE_SCN_CNT_CODE:
1299
1
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1300
1
    break;
1301
1
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1302
1
    if (is_dbg)
1303
0
      sec_flags |= SEC_DEBUGGING;
1304
1
    else
1305
1
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1306
1
    break;
1307
0
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1308
0
    sec_flags |= SEC_ALLOC;
1309
0
    break;
1310
0
  case IMAGE_SCN_LNK_INFO:
1311
    /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
1312
       defined.  coff_compute_section_file_positions uses
1313
       COFF_PAGE_SIZE to ensure that the low order bits of the
1314
       section VMA and the file offset match.  If we don't know
1315
       COFF_PAGE_SIZE, we can't ensure the correct correspondence,
1316
       and demand page loading of the file will fail.  */
1317
0
#ifdef COFF_PAGE_SIZE
1318
0
    sec_flags |= SEC_DEBUGGING;
1319
0
#endif
1320
0
    break;
1321
1
  case IMAGE_SCN_LNK_COMDAT:
1322
    /* COMDAT gets very special treatment.  */
1323
1
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1324
1
      result = false;
1325
1
    break;
1326
22
  default:
1327
    /* Silently ignore for now.  */
1328
22
    break;
1329
47
  }
1330
1331
      /* If the section flag was not handled, report it here.  */
1332
47
      if (unhandled != NULL)
1333
3
  {
1334
3
    _bfd_error_handler
1335
      /* xgettext:c-format */
1336
3
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1337
3
       abfd, name, unhandled, flag);
1338
3
    result = false;
1339
3
  }
1340
47
    }
1341
1342
200
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1343
200
      && (startswith (name, ".sbss")
1344
0
    || startswith (name, ".sdata")))
1345
0
    sec_flags |= SEC_SMALL_DATA;
1346
1347
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
1348
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
1349
     only link a single copy of the section.  This is used to support
1350
     g++.  g++ will emit each template expansion in its own section.
1351
     The symbols will be defined as weak, so that multiple definitions
1352
     are permitted.  The GNU linker extension is to actually discard
1353
     all but one of the sections.  */
1354
  if (startswith (name, ".gnu.linkonce"))
1355
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
1356
#endif
1357
1358
200
  if (flags_ptr)
1359
200
    * flags_ptr = sec_flags;
1360
1361
200
  return result;
1362
200
}
pe-sh.c:styp_to_sec_flags
Line
Count
Source
1191
4.81k
{
1192
4.81k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1193
4.81k
  unsigned long styp_flags = internal_s->s_flags;
1194
4.81k
  flagword sec_flags;
1195
4.81k
  bool result = true;
1196
4.81k
  bool is_dbg = false;
1197
1198
4.81k
  if (startswith (name, DOT_DEBUG)
1199
4.81k
      || startswith (name, DOT_ZDEBUG)
1200
4.81k
#ifdef COFF_LONG_SECTION_NAMES
1201
4.81k
      || startswith (name, GNU_LINKONCE_WI)
1202
4.81k
      || startswith (name, GNU_LINKONCE_WT)
1203
      /* FIXME: These definitions ought to be in a header file.  */
1204
4.81k
#define GNU_DEBUGLINK   ".gnu_debuglink"
1205
4.81k
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1206
4.81k
      || startswith (name, GNU_DEBUGLINK)
1207
4.81k
      || startswith (name, GNU_DEBUGALTLINK)
1208
4.81k
#endif
1209
4.81k
      || startswith (name, ".stab"))
1210
84
    is_dbg = true;
1211
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1212
4.81k
  sec_flags = SEC_READONLY;
1213
1214
  /* If section disallows read, then set the NOREAD flag. */
1215
4.81k
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1216
4.07k
    sec_flags |= SEC_COFF_NOREAD;
1217
1218
  /* Process each flag bit in styp_flags in turn.  */
1219
38.4k
  while (styp_flags)
1220
33.6k
    {
1221
33.6k
      unsigned long flag = styp_flags & - styp_flags;
1222
33.6k
      char * unhandled = NULL;
1223
1224
33.6k
      styp_flags &= ~ flag;
1225
1226
      /* We infer from the distinct read/write/execute bits the settings
1227
   of some of the bfd flags; the actual values, should we need them,
1228
   are also in pei_section_data (abfd, section)->pe_flags.  */
1229
1230
33.6k
      switch (flag)
1231
33.6k
  {
1232
571
  case STYP_DSECT:
1233
571
    unhandled = "STYP_DSECT";
1234
571
    break;
1235
351
  case STYP_GROUP:
1236
351
    unhandled = "STYP_GROUP";
1237
351
    break;
1238
256
  case STYP_COPY:
1239
256
    unhandled = "STYP_COPY";
1240
256
    break;
1241
299
  case STYP_OVER:
1242
299
    unhandled = "STYP_OVER";
1243
299
    break;
1244
0
#ifdef SEC_NEVER_LOAD
1245
2.42k
  case STYP_NOLOAD:
1246
2.42k
    sec_flags |= SEC_NEVER_LOAD;
1247
2.42k
    break;
1248
0
#endif
1249
737
  case IMAGE_SCN_MEM_READ:
1250
737
    sec_flags &= ~SEC_COFF_NOREAD;
1251
737
    break;
1252
1.71k
  case IMAGE_SCN_TYPE_NO_PAD:
1253
    /* Skip.  */
1254
1.71k
    break;
1255
792
  case IMAGE_SCN_LNK_OTHER:
1256
792
    unhandled = "IMAGE_SCN_LNK_OTHER";
1257
792
    break;
1258
558
  case IMAGE_SCN_MEM_NOT_CACHED:
1259
558
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1260
558
    break;
1261
1.69k
  case IMAGE_SCN_MEM_NOT_PAGED:
1262
    /* Generate a warning message rather using the 'unhandled'
1263
       variable as this will allow some .sys files generate by
1264
       other toolchains to be processed.  See bugzilla issue 196.  */
1265
    /* xgettext:c-format */
1266
1.69k
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1267
1.69k
        " %s in section %s"),
1268
1.69k
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1269
1.69k
    break;
1270
836
  case IMAGE_SCN_MEM_EXECUTE:
1271
836
    sec_flags |= SEC_CODE;
1272
836
    break;
1273
1.07k
  case IMAGE_SCN_MEM_WRITE:
1274
1.07k
    sec_flags &= ~ SEC_READONLY;
1275
1.07k
    break;
1276
1.81k
  case IMAGE_SCN_MEM_DISCARDABLE:
1277
    /* The MS PE spec says that debug sections are DISCARDABLE,
1278
       but the presence of a DISCARDABLE flag does not necessarily
1279
       mean that a given section contains debug information.  Thus
1280
       we only set the SEC_DEBUGGING flag on sections that we
1281
       recognise as containing debug information.  */
1282
1.81k
       if (is_dbg
1283
1.81k
#ifdef _COMMENT
1284
1.81k
        || strcmp (name, _COMMENT) == 0
1285
1.81k
#endif
1286
1.81k
        )
1287
55
      {
1288
55
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1289
55
      }
1290
1.81k
    break;
1291
1.17k
  case IMAGE_SCN_MEM_SHARED:
1292
1.17k
    sec_flags |= SEC_COFF_SHARED;
1293
1.17k
    break;
1294
1.89k
  case IMAGE_SCN_LNK_REMOVE:
1295
1.89k
    if (!is_dbg)
1296
1.88k
      sec_flags |= SEC_EXCLUDE;
1297
1.89k
    break;
1298
530
  case IMAGE_SCN_CNT_CODE:
1299
530
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1300
530
    break;
1301
563
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1302
563
    if (is_dbg)
1303
32
      sec_flags |= SEC_DEBUGGING;
1304
531
    else
1305
531
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1306
563
    break;
1307
1.19k
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1308
1.19k
    sec_flags |= SEC_ALLOC;
1309
1.19k
    break;
1310
1.98k
  case IMAGE_SCN_LNK_INFO:
1311
    /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
1312
       defined.  coff_compute_section_file_positions uses
1313
       COFF_PAGE_SIZE to ensure that the low order bits of the
1314
       section VMA and the file offset match.  If we don't know
1315
       COFF_PAGE_SIZE, we can't ensure the correct correspondence,
1316
       and demand page loading of the file will fail.  */
1317
#ifdef COFF_PAGE_SIZE
1318
    sec_flags |= SEC_DEBUGGING;
1319
#endif
1320
1.98k
    break;
1321
1.27k
  case IMAGE_SCN_LNK_COMDAT:
1322
    /* COMDAT gets very special treatment.  */
1323
1.27k
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1324
534
      result = false;
1325
1.27k
    break;
1326
11.8k
  default:
1327
    /* Silently ignore for now.  */
1328
11.8k
    break;
1329
33.6k
  }
1330
1331
      /* If the section flag was not handled, report it here.  */
1332
33.6k
      if (unhandled != NULL)
1333
2.82k
  {
1334
2.82k
    _bfd_error_handler
1335
      /* xgettext:c-format */
1336
2.82k
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1337
2.82k
       abfd, name, unhandled, flag);
1338
2.82k
    result = false;
1339
2.82k
  }
1340
33.6k
    }
1341
1342
4.81k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1343
4.81k
      && (startswith (name, ".sbss")
1344
0
    || startswith (name, ".sdata")))
1345
0
    sec_flags |= SEC_SMALL_DATA;
1346
1347
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
1348
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
1349
     only link a single copy of the section.  This is used to support
1350
     g++.  g++ will emit each template expansion in its own section.
1351
     The symbols will be defined as weak, so that multiple definitions
1352
     are permitted.  The GNU linker extension is to actually discard
1353
     all but one of the sections.  */
1354
  if (startswith (name, ".gnu.linkonce"))
1355
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
1356
#endif
1357
1358
4.81k
  if (flags_ptr)
1359
4.81k
    * flags_ptr = sec_flags;
1360
1361
4.81k
  return result;
1362
4.81k
}
pei-arm-wince.c:styp_to_sec_flags
Line
Count
Source
1191
4.11k
{
1192
4.11k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1193
4.11k
  unsigned long styp_flags = internal_s->s_flags;
1194
4.11k
  flagword sec_flags;
1195
4.11k
  bool result = true;
1196
4.11k
  bool is_dbg = false;
1197
1198
4.11k
  if (startswith (name, DOT_DEBUG)
1199
4.11k
      || startswith (name, DOT_ZDEBUG)
1200
4.11k
#ifdef COFF_LONG_SECTION_NAMES
1201
4.11k
      || startswith (name, GNU_LINKONCE_WI)
1202
4.11k
      || startswith (name, GNU_LINKONCE_WT)
1203
      /* FIXME: These definitions ought to be in a header file.  */
1204
4.11k
#define GNU_DEBUGLINK   ".gnu_debuglink"
1205
4.11k
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1206
4.11k
      || startswith (name, GNU_DEBUGLINK)
1207
4.11k
      || startswith (name, GNU_DEBUGALTLINK)
1208
4.11k
#endif
1209
4.11k
      || startswith (name, ".stab"))
1210
1
    is_dbg = true;
1211
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1212
4.11k
  sec_flags = SEC_READONLY;
1213
1214
  /* If section disallows read, then set the NOREAD flag. */
1215
4.11k
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1216
4.11k
    sec_flags |= SEC_COFF_NOREAD;
1217
1218
  /* Process each flag bit in styp_flags in turn.  */
1219
4.14k
  while (styp_flags)
1220
27
    {
1221
27
      unsigned long flag = styp_flags & - styp_flags;
1222
27
      char * unhandled = NULL;
1223
1224
27
      styp_flags &= ~ flag;
1225
1226
      /* We infer from the distinct read/write/execute bits the settings
1227
   of some of the bfd flags; the actual values, should we need them,
1228
   are also in pei_section_data (abfd, section)->pe_flags.  */
1229
1230
27
      switch (flag)
1231
27
  {
1232
0
  case STYP_DSECT:
1233
0
    unhandled = "STYP_DSECT";
1234
0
    break;
1235
0
  case STYP_GROUP:
1236
0
    unhandled = "STYP_GROUP";
1237
0
    break;
1238
1
  case STYP_COPY:
1239
1
    unhandled = "STYP_COPY";
1240
1
    break;
1241
0
  case STYP_OVER:
1242
0
    unhandled = "STYP_OVER";
1243
0
    break;
1244
0
#ifdef SEC_NEVER_LOAD
1245
1
  case STYP_NOLOAD:
1246
1
    sec_flags |= SEC_NEVER_LOAD;
1247
1
    break;
1248
0
#endif
1249
1
  case IMAGE_SCN_MEM_READ:
1250
1
    sec_flags &= ~SEC_COFF_NOREAD;
1251
1
    break;
1252
1
  case IMAGE_SCN_TYPE_NO_PAD:
1253
    /* Skip.  */
1254
1
    break;
1255
1
  case IMAGE_SCN_LNK_OTHER:
1256
1
    unhandled = "IMAGE_SCN_LNK_OTHER";
1257
1
    break;
1258
2
  case IMAGE_SCN_MEM_NOT_CACHED:
1259
2
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1260
2
    break;
1261
1
  case IMAGE_SCN_MEM_NOT_PAGED:
1262
    /* Generate a warning message rather using the 'unhandled'
1263
       variable as this will allow some .sys files generate by
1264
       other toolchains to be processed.  See bugzilla issue 196.  */
1265
    /* xgettext:c-format */
1266
1
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1267
1
        " %s in section %s"),
1268
1
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1269
1
    break;
1270
2
  case IMAGE_SCN_MEM_EXECUTE:
1271
2
    sec_flags |= SEC_CODE;
1272
2
    break;
1273
0
  case IMAGE_SCN_MEM_WRITE:
1274
0
    sec_flags &= ~ SEC_READONLY;
1275
0
    break;
1276
1
  case IMAGE_SCN_MEM_DISCARDABLE:
1277
    /* The MS PE spec says that debug sections are DISCARDABLE,
1278
       but the presence of a DISCARDABLE flag does not necessarily
1279
       mean that a given section contains debug information.  Thus
1280
       we only set the SEC_DEBUGGING flag on sections that we
1281
       recognise as containing debug information.  */
1282
1
       if (is_dbg
1283
1
#ifdef _COMMENT
1284
1
        || strcmp (name, _COMMENT) == 0
1285
1
#endif
1286
1
        )
1287
0
      {
1288
0
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1289
0
      }
1290
1
    break;
1291
1
  case IMAGE_SCN_MEM_SHARED:
1292
1
    sec_flags |= SEC_COFF_SHARED;
1293
1
    break;
1294
0
  case IMAGE_SCN_LNK_REMOVE:
1295
0
    if (!is_dbg)
1296
0
      sec_flags |= SEC_EXCLUDE;
1297
0
    break;
1298
1
  case IMAGE_SCN_CNT_CODE:
1299
1
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1300
1
    break;
1301
1
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1302
1
    if (is_dbg)
1303
0
      sec_flags |= SEC_DEBUGGING;
1304
1
    else
1305
1
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1306
1
    break;
1307
1
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1308
1
    sec_flags |= SEC_ALLOC;
1309
1
    break;
1310
0
  case IMAGE_SCN_LNK_INFO:
1311
    /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
1312
       defined.  coff_compute_section_file_positions uses
1313
       COFF_PAGE_SIZE to ensure that the low order bits of the
1314
       section VMA and the file offset match.  If we don't know
1315
       COFF_PAGE_SIZE, we can't ensure the correct correspondence,
1316
       and demand page loading of the file will fail.  */
1317
0
#ifdef COFF_PAGE_SIZE
1318
0
    sec_flags |= SEC_DEBUGGING;
1319
0
#endif
1320
0
    break;
1321
0
  case IMAGE_SCN_LNK_COMDAT:
1322
    /* COMDAT gets very special treatment.  */
1323
0
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1324
0
      result = false;
1325
0
    break;
1326
12
  default:
1327
    /* Silently ignore for now.  */
1328
12
    break;
1329
27
  }
1330
1331
      /* If the section flag was not handled, report it here.  */
1332
27
      if (unhandled != NULL)
1333
4
  {
1334
4
    _bfd_error_handler
1335
      /* xgettext:c-format */
1336
4
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1337
4
       abfd, name, unhandled, flag);
1338
4
    result = false;
1339
4
  }
1340
27
    }
1341
1342
4.11k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1343
4.11k
      && (startswith (name, ".sbss")
1344
0
    || startswith (name, ".sdata")))
1345
0
    sec_flags |= SEC_SMALL_DATA;
1346
1347
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
1348
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
1349
     only link a single copy of the section.  This is used to support
1350
     g++.  g++ will emit each template expansion in its own section.
1351
     The symbols will be defined as weak, so that multiple definitions
1352
     are permitted.  The GNU linker extension is to actually discard
1353
     all but one of the sections.  */
1354
  if (startswith (name, ".gnu.linkonce"))
1355
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
1356
#endif
1357
1358
4.11k
  if (flags_ptr)
1359
4.11k
    * flags_ptr = sec_flags;
1360
1361
4.11k
  return result;
1362
4.11k
}
pei-arm.c:styp_to_sec_flags
Line
Count
Source
1191
21
{
1192
21
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1193
21
  unsigned long styp_flags = internal_s->s_flags;
1194
21
  flagword sec_flags;
1195
21
  bool result = true;
1196
21
  bool is_dbg = false;
1197
1198
21
  if (startswith (name, DOT_DEBUG)
1199
21
      || startswith (name, DOT_ZDEBUG)
1200
21
#ifdef COFF_LONG_SECTION_NAMES
1201
21
      || startswith (name, GNU_LINKONCE_WI)
1202
21
      || startswith (name, GNU_LINKONCE_WT)
1203
      /* FIXME: These definitions ought to be in a header file.  */
1204
21
#define GNU_DEBUGLINK   ".gnu_debuglink"
1205
21
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1206
21
      || startswith (name, GNU_DEBUGLINK)
1207
21
      || startswith (name, GNU_DEBUGALTLINK)
1208
21
#endif
1209
21
      || startswith (name, ".stab"))
1210
0
    is_dbg = true;
1211
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1212
21
  sec_flags = SEC_READONLY;
1213
1214
  /* If section disallows read, then set the NOREAD flag. */
1215
21
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1216
21
    sec_flags |= SEC_COFF_NOREAD;
1217
1218
  /* Process each flag bit in styp_flags in turn.  */
1219
31
  while (styp_flags)
1220
10
    {
1221
10
      unsigned long flag = styp_flags & - styp_flags;
1222
10
      char * unhandled = NULL;
1223
1224
10
      styp_flags &= ~ flag;
1225
1226
      /* We infer from the distinct read/write/execute bits the settings
1227
   of some of the bfd flags; the actual values, should we need them,
1228
   are also in pei_section_data (abfd, section)->pe_flags.  */
1229
1230
10
      switch (flag)
1231
10
  {
1232
0
  case STYP_DSECT:
1233
0
    unhandled = "STYP_DSECT";
1234
0
    break;
1235
0
  case STYP_GROUP:
1236
0
    unhandled = "STYP_GROUP";
1237
0
    break;
1238
0
  case STYP_COPY:
1239
0
    unhandled = "STYP_COPY";
1240
0
    break;
1241
0
  case STYP_OVER:
1242
0
    unhandled = "STYP_OVER";
1243
0
    break;
1244
0
#ifdef SEC_NEVER_LOAD
1245
1
  case STYP_NOLOAD:
1246
1
    sec_flags |= SEC_NEVER_LOAD;
1247
1
    break;
1248
0
#endif
1249
0
  case IMAGE_SCN_MEM_READ:
1250
0
    sec_flags &= ~SEC_COFF_NOREAD;
1251
0
    break;
1252
0
  case IMAGE_SCN_TYPE_NO_PAD:
1253
    /* Skip.  */
1254
0
    break;
1255
1
  case IMAGE_SCN_LNK_OTHER:
1256
1
    unhandled = "IMAGE_SCN_LNK_OTHER";
1257
1
    break;
1258
1
  case IMAGE_SCN_MEM_NOT_CACHED:
1259
1
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1260
1
    break;
1261
0
  case IMAGE_SCN_MEM_NOT_PAGED:
1262
    /* Generate a warning message rather using the 'unhandled'
1263
       variable as this will allow some .sys files generate by
1264
       other toolchains to be processed.  See bugzilla issue 196.  */
1265
    /* xgettext:c-format */
1266
0
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1267
0
        " %s in section %s"),
1268
0
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1269
0
    break;
1270
1
  case IMAGE_SCN_MEM_EXECUTE:
1271
1
    sec_flags |= SEC_CODE;
1272
1
    break;
1273
1
  case IMAGE_SCN_MEM_WRITE:
1274
1
    sec_flags &= ~ SEC_READONLY;
1275
1
    break;
1276
1
  case IMAGE_SCN_MEM_DISCARDABLE:
1277
    /* The MS PE spec says that debug sections are DISCARDABLE,
1278
       but the presence of a DISCARDABLE flag does not necessarily
1279
       mean that a given section contains debug information.  Thus
1280
       we only set the SEC_DEBUGGING flag on sections that we
1281
       recognise as containing debug information.  */
1282
1
       if (is_dbg
1283
1
#ifdef _COMMENT
1284
1
        || strcmp (name, _COMMENT) == 0
1285
1
#endif
1286
1
        )
1287
0
      {
1288
0
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1289
0
      }
1290
1
    break;
1291
0
  case IMAGE_SCN_MEM_SHARED:
1292
0
    sec_flags |= SEC_COFF_SHARED;
1293
0
    break;
1294
0
  case IMAGE_SCN_LNK_REMOVE:
1295
0
    if (!is_dbg)
1296
0
      sec_flags |= SEC_EXCLUDE;
1297
0
    break;
1298
0
  case IMAGE_SCN_CNT_CODE:
1299
0
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1300
0
    break;
1301
0
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1302
0
    if (is_dbg)
1303
0
      sec_flags |= SEC_DEBUGGING;
1304
0
    else
1305
0
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1306
0
    break;
1307
0
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1308
0
    sec_flags |= SEC_ALLOC;
1309
0
    break;
1310
0
  case IMAGE_SCN_LNK_INFO:
1311
    /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
1312
       defined.  coff_compute_section_file_positions uses
1313
       COFF_PAGE_SIZE to ensure that the low order bits of the
1314
       section VMA and the file offset match.  If we don't know
1315
       COFF_PAGE_SIZE, we can't ensure the correct correspondence,
1316
       and demand page loading of the file will fail.  */
1317
0
#ifdef COFF_PAGE_SIZE
1318
0
    sec_flags |= SEC_DEBUGGING;
1319
0
#endif
1320
0
    break;
1321
0
  case IMAGE_SCN_LNK_COMDAT:
1322
    /* COMDAT gets very special treatment.  */
1323
0
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1324
0
      result = false;
1325
0
    break;
1326
4
  default:
1327
    /* Silently ignore for now.  */
1328
4
    break;
1329
10
  }
1330
1331
      /* If the section flag was not handled, report it here.  */
1332
10
      if (unhandled != NULL)
1333
2
  {
1334
2
    _bfd_error_handler
1335
      /* xgettext:c-format */
1336
2
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1337
2
       abfd, name, unhandled, flag);
1338
2
    result = false;
1339
2
  }
1340
10
    }
1341
1342
21
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1343
21
      && (startswith (name, ".sbss")
1344
0
    || startswith (name, ".sdata")))
1345
0
    sec_flags |= SEC_SMALL_DATA;
1346
1347
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
1348
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
1349
     only link a single copy of the section.  This is used to support
1350
     g++.  g++ will emit each template expansion in its own section.
1351
     The symbols will be defined as weak, so that multiple definitions
1352
     are permitted.  The GNU linker extension is to actually discard
1353
     all but one of the sections.  */
1354
  if (startswith (name, ".gnu.linkonce"))
1355
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
1356
#endif
1357
1358
21
  if (flags_ptr)
1359
21
    * flags_ptr = sec_flags;
1360
1361
21
  return result;
1362
21
}
pei-mcore.c:styp_to_sec_flags
Line
Count
Source
1191
10
{
1192
10
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1193
10
  unsigned long styp_flags = internal_s->s_flags;
1194
10
  flagword sec_flags;
1195
10
  bool result = true;
1196
10
  bool is_dbg = false;
1197
1198
10
  if (startswith (name, DOT_DEBUG)
1199
10
      || startswith (name, DOT_ZDEBUG)
1200
10
#ifdef COFF_LONG_SECTION_NAMES
1201
10
      || startswith (name, GNU_LINKONCE_WI)
1202
10
      || startswith (name, GNU_LINKONCE_WT)
1203
      /* FIXME: These definitions ought to be in a header file.  */
1204
10
#define GNU_DEBUGLINK   ".gnu_debuglink"
1205
10
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1206
10
      || startswith (name, GNU_DEBUGLINK)
1207
10
      || startswith (name, GNU_DEBUGALTLINK)
1208
10
#endif
1209
10
      || startswith (name, ".stab"))
1210
0
    is_dbg = true;
1211
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1212
10
  sec_flags = SEC_READONLY;
1213
1214
  /* If section disallows read, then set the NOREAD flag. */
1215
10
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1216
7
    sec_flags |= SEC_COFF_NOREAD;
1217
1218
  /* Process each flag bit in styp_flags in turn.  */
1219
71
  while (styp_flags)
1220
61
    {
1221
61
      unsigned long flag = styp_flags & - styp_flags;
1222
61
      char * unhandled = NULL;
1223
1224
61
      styp_flags &= ~ flag;
1225
1226
      /* We infer from the distinct read/write/execute bits the settings
1227
   of some of the bfd flags; the actual values, should we need them,
1228
   are also in pei_section_data (abfd, section)->pe_flags.  */
1229
1230
61
      switch (flag)
1231
61
  {
1232
0
  case STYP_DSECT:
1233
0
    unhandled = "STYP_DSECT";
1234
0
    break;
1235
0
  case STYP_GROUP:
1236
0
    unhandled = "STYP_GROUP";
1237
0
    break;
1238
0
  case STYP_COPY:
1239
0
    unhandled = "STYP_COPY";
1240
0
    break;
1241
0
  case STYP_OVER:
1242
0
    unhandled = "STYP_OVER";
1243
0
    break;
1244
0
#ifdef SEC_NEVER_LOAD
1245
6
  case STYP_NOLOAD:
1246
6
    sec_flags |= SEC_NEVER_LOAD;
1247
6
    break;
1248
0
#endif
1249
3
  case IMAGE_SCN_MEM_READ:
1250
3
    sec_flags &= ~SEC_COFF_NOREAD;
1251
3
    break;
1252
6
  case IMAGE_SCN_TYPE_NO_PAD:
1253
    /* Skip.  */
1254
6
    break;
1255
0
  case IMAGE_SCN_LNK_OTHER:
1256
0
    unhandled = "IMAGE_SCN_LNK_OTHER";
1257
0
    break;
1258
0
  case IMAGE_SCN_MEM_NOT_CACHED:
1259
0
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1260
0
    break;
1261
3
  case IMAGE_SCN_MEM_NOT_PAGED:
1262
    /* Generate a warning message rather using the 'unhandled'
1263
       variable as this will allow some .sys files generate by
1264
       other toolchains to be processed.  See bugzilla issue 196.  */
1265
    /* xgettext:c-format */
1266
3
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1267
3
        " %s in section %s"),
1268
3
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1269
3
    break;
1270
0
  case IMAGE_SCN_MEM_EXECUTE:
1271
0
    sec_flags |= SEC_CODE;
1272
0
    break;
1273
3
  case IMAGE_SCN_MEM_WRITE:
1274
3
    sec_flags &= ~ SEC_READONLY;
1275
3
    break;
1276
3
  case IMAGE_SCN_MEM_DISCARDABLE:
1277
    /* The MS PE spec says that debug sections are DISCARDABLE,
1278
       but the presence of a DISCARDABLE flag does not necessarily
1279
       mean that a given section contains debug information.  Thus
1280
       we only set the SEC_DEBUGGING flag on sections that we
1281
       recognise as containing debug information.  */
1282
3
       if (is_dbg
1283
3
#ifdef _COMMENT
1284
3
        || strcmp (name, _COMMENT) == 0
1285
3
#endif
1286
3
        )
1287
0
      {
1288
0
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1289
0
      }
1290
3
    break;
1291
0
  case IMAGE_SCN_MEM_SHARED:
1292
0
    sec_flags |= SEC_COFF_SHARED;
1293
0
    break;
1294
3
  case IMAGE_SCN_LNK_REMOVE:
1295
3
    if (!is_dbg)
1296
3
      sec_flags |= SEC_EXCLUDE;
1297
3
    break;
1298
0
  case IMAGE_SCN_CNT_CODE:
1299
0
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1300
0
    break;
1301
3
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1302
3
    if (is_dbg)
1303
0
      sec_flags |= SEC_DEBUGGING;
1304
3
    else
1305
3
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1306
3
    break;
1307
0
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1308
0
    sec_flags |= SEC_ALLOC;
1309
0
    break;
1310
3
  case IMAGE_SCN_LNK_INFO:
1311
    /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
1312
       defined.  coff_compute_section_file_positions uses
1313
       COFF_PAGE_SIZE to ensure that the low order bits of the
1314
       section VMA and the file offset match.  If we don't know
1315
       COFF_PAGE_SIZE, we can't ensure the correct correspondence,
1316
       and demand page loading of the file will fail.  */
1317
3
#ifdef COFF_PAGE_SIZE
1318
3
    sec_flags |= SEC_DEBUGGING;
1319
3
#endif
1320
3
    break;
1321
0
  case IMAGE_SCN_LNK_COMDAT:
1322
    /* COMDAT gets very special treatment.  */
1323
0
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1324
0
      result = false;
1325
0
    break;
1326
28
  default:
1327
    /* Silently ignore for now.  */
1328
28
    break;
1329
61
  }
1330
1331
      /* If the section flag was not handled, report it here.  */
1332
61
      if (unhandled != NULL)
1333
0
  {
1334
0
    _bfd_error_handler
1335
      /* xgettext:c-format */
1336
0
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1337
0
       abfd, name, unhandled, flag);
1338
0
    result = false;
1339
0
  }
1340
61
    }
1341
1342
10
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1343
10
      && (startswith (name, ".sbss")
1344
0
    || startswith (name, ".sdata")))
1345
0
    sec_flags |= SEC_SMALL_DATA;
1346
1347
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
1348
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
1349
     only link a single copy of the section.  This is used to support
1350
     g++.  g++ will emit each template expansion in its own section.
1351
     The symbols will be defined as weak, so that multiple definitions
1352
     are permitted.  The GNU linker extension is to actually discard
1353
     all but one of the sections.  */
1354
  if (startswith (name, ".gnu.linkonce"))
1355
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
1356
#endif
1357
1358
10
  if (flags_ptr)
1359
10
    * flags_ptr = sec_flags;
1360
1361
10
  return result;
1362
10
}
pei-sh.c:styp_to_sec_flags
Line
Count
Source
1191
1.52k
{
1192
1.52k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1193
1.52k
  unsigned long styp_flags = internal_s->s_flags;
1194
1.52k
  flagword sec_flags;
1195
1.52k
  bool result = true;
1196
1.52k
  bool is_dbg = false;
1197
1198
1.52k
  if (startswith (name, DOT_DEBUG)
1199
1.52k
      || startswith (name, DOT_ZDEBUG)
1200
1.52k
#ifdef COFF_LONG_SECTION_NAMES
1201
1.52k
      || startswith (name, GNU_LINKONCE_WI)
1202
1.52k
      || startswith (name, GNU_LINKONCE_WT)
1203
      /* FIXME: These definitions ought to be in a header file.  */
1204
1.52k
#define GNU_DEBUGLINK   ".gnu_debuglink"
1205
1.52k
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1206
1.52k
      || startswith (name, GNU_DEBUGLINK)
1207
1.52k
      || startswith (name, GNU_DEBUGALTLINK)
1208
1.52k
#endif
1209
1.52k
      || startswith (name, ".stab"))
1210
0
    is_dbg = true;
1211
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1212
1.52k
  sec_flags = SEC_READONLY;
1213
1214
  /* If section disallows read, then set the NOREAD flag. */
1215
1.52k
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1216
1.25k
    sec_flags |= SEC_COFF_NOREAD;
1217
1218
  /* Process each flag bit in styp_flags in turn.  */
1219
6.13k
  while (styp_flags)
1220
4.61k
    {
1221
4.61k
      unsigned long flag = styp_flags & - styp_flags;
1222
4.61k
      char * unhandled = NULL;
1223
1224
4.61k
      styp_flags &= ~ flag;
1225
1226
      /* We infer from the distinct read/write/execute bits the settings
1227
   of some of the bfd flags; the actual values, should we need them,
1228
   are also in pei_section_data (abfd, section)->pe_flags.  */
1229
1230
4.61k
      switch (flag)
1231
4.61k
  {
1232
0
  case STYP_DSECT:
1233
0
    unhandled = "STYP_DSECT";
1234
0
    break;
1235
0
  case STYP_GROUP:
1236
0
    unhandled = "STYP_GROUP";
1237
0
    break;
1238
0
  case STYP_COPY:
1239
0
    unhandled = "STYP_COPY";
1240
0
    break;
1241
0
  case STYP_OVER:
1242
0
    unhandled = "STYP_OVER";
1243
0
    break;
1244
0
#ifdef SEC_NEVER_LOAD
1245
267
  case STYP_NOLOAD:
1246
267
    sec_flags |= SEC_NEVER_LOAD;
1247
267
    break;
1248
0
#endif
1249
267
  case IMAGE_SCN_MEM_READ:
1250
267
    sec_flags &= ~SEC_COFF_NOREAD;
1251
267
    break;
1252
209
  case IMAGE_SCN_TYPE_NO_PAD:
1253
    /* Skip.  */
1254
209
    break;
1255
0
  case IMAGE_SCN_LNK_OTHER:
1256
0
    unhandled = "IMAGE_SCN_LNK_OTHER";
1257
0
    break;
1258
0
  case IMAGE_SCN_MEM_NOT_CACHED:
1259
0
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1260
0
    break;
1261
209
  case IMAGE_SCN_MEM_NOT_PAGED:
1262
    /* Generate a warning message rather using the 'unhandled'
1263
       variable as this will allow some .sys files generate by
1264
       other toolchains to be processed.  See bugzilla issue 196.  */
1265
    /* xgettext:c-format */
1266
209
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1267
209
        " %s in section %s"),
1268
209
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1269
209
    break;
1270
267
  case IMAGE_SCN_MEM_EXECUTE:
1271
267
    sec_flags |= SEC_CODE;
1272
267
    break;
1273
123
  case IMAGE_SCN_MEM_WRITE:
1274
123
    sec_flags &= ~ SEC_READONLY;
1275
123
    break;
1276
267
  case IMAGE_SCN_MEM_DISCARDABLE:
1277
    /* The MS PE spec says that debug sections are DISCARDABLE,
1278
       but the presence of a DISCARDABLE flag does not necessarily
1279
       mean that a given section contains debug information.  Thus
1280
       we only set the SEC_DEBUGGING flag on sections that we
1281
       recognise as containing debug information.  */
1282
267
       if (is_dbg
1283
267
#ifdef _COMMENT
1284
267
        || strcmp (name, _COMMENT) == 0
1285
267
#endif
1286
267
        )
1287
0
      {
1288
0
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1289
0
      }
1290
267
    break;
1291
1
  case IMAGE_SCN_MEM_SHARED:
1292
1
    sec_flags |= SEC_COFF_SHARED;
1293
1
    break;
1294
216
  case IMAGE_SCN_LNK_REMOVE:
1295
216
    if (!is_dbg)
1296
216
      sec_flags |= SEC_EXCLUDE;
1297
216
    break;
1298
267
  case IMAGE_SCN_CNT_CODE:
1299
267
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1300
267
    break;
1301
267
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1302
267
    if (is_dbg)
1303
0
      sec_flags |= SEC_DEBUGGING;
1304
267
    else
1305
267
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1306
267
    break;
1307
123
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1308
123
    sec_flags |= SEC_ALLOC;
1309
123
    break;
1310
281
  case IMAGE_SCN_LNK_INFO:
1311
    /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
1312
       defined.  coff_compute_section_file_positions uses
1313
       COFF_PAGE_SIZE to ensure that the low order bits of the
1314
       section VMA and the file offset match.  If we don't know
1315
       COFF_PAGE_SIZE, we can't ensure the correct correspondence,
1316
       and demand page loading of the file will fail.  */
1317
281
#ifdef COFF_PAGE_SIZE
1318
281
    sec_flags |= SEC_DEBUGGING;
1319
281
#endif
1320
281
    break;
1321
7
  case IMAGE_SCN_LNK_COMDAT:
1322
    /* COMDAT gets very special treatment.  */
1323
7
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1324
0
      result = false;
1325
7
    break;
1326
1.83k
  default:
1327
    /* Silently ignore for now.  */
1328
1.83k
    break;
1329
4.61k
  }
1330
1331
      /* If the section flag was not handled, report it here.  */
1332
4.61k
      if (unhandled != NULL)
1333
0
  {
1334
0
    _bfd_error_handler
1335
      /* xgettext:c-format */
1336
0
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1337
0
       abfd, name, unhandled, flag);
1338
0
    result = false;
1339
0
  }
1340
4.61k
    }
1341
1342
1.52k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1343
1.52k
      && (startswith (name, ".sbss")
1344
0
    || startswith (name, ".sdata")))
1345
0
    sec_flags |= SEC_SMALL_DATA;
1346
1347
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
1348
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
1349
     only link a single copy of the section.  This is used to support
1350
     g++.  g++ will emit each template expansion in its own section.
1351
     The symbols will be defined as weak, so that multiple definitions
1352
     are permitted.  The GNU linker extension is to actually discard
1353
     all but one of the sections.  */
1354
  if (startswith (name, ".gnu.linkonce"))
1355
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
1356
#endif
1357
1358
1.52k
  if (flags_ptr)
1359
1.52k
    * flags_ptr = sec_flags;
1360
1361
1.52k
  return result;
1362
1.52k
}
1363
1364
#endif /* COFF_WITH_PE */
1365
1366
0
#define get_index(symbol) ((symbol)->udata.i)
1367
1368
/*
1369
INTERNAL_DEFINITION
1370
  bfd_coff_backend_data
1371
1372
INTERNAL
1373
.{* COFF symbol classifications.  *}
1374
.
1375
.enum coff_symbol_classification
1376
.{
1377
.  {* Global symbol.  *}
1378
.  COFF_SYMBOL_GLOBAL,
1379
.  {* Common symbol.  *}
1380
.  COFF_SYMBOL_COMMON,
1381
.  {* Undefined symbol.  *}
1382
.  COFF_SYMBOL_UNDEFINED,
1383
.  {* Local symbol.  *}
1384
.  COFF_SYMBOL_LOCAL,
1385
.  {* PE section symbol.  *}
1386
.  COFF_SYMBOL_PE_SECTION
1387
.};
1388
.
1389
.typedef asection * (*coff_gc_mark_hook_fn)
1390
.  (asection *, struct bfd_link_info *, struct internal_reloc *,
1391
.   struct coff_link_hash_entry *, struct internal_syment *);
1392
.
1393
1394
Special entry points for gdb to swap in coff symbol table parts:
1395
1396
CODE_FRAGMENT
1397
.typedef struct
1398
.{
1399
.  void (*_bfd_coff_swap_aux_in)
1400
.    (bfd *, void *, int, int, int, int, void *);
1401
.
1402
.  void (*_bfd_coff_swap_sym_in)
1403
.    (bfd *, void *, void *);
1404
.
1405
.  void (*_bfd_coff_swap_lineno_in)
1406
.    (bfd *, void *, void *);
1407
.
1408
.  unsigned int (*_bfd_coff_swap_aux_out)
1409
.    (bfd *, void *, int, int, int, int, void *);
1410
.
1411
.  unsigned int (*_bfd_coff_swap_sym_out)
1412
.    (bfd *, void *, void *);
1413
.
1414
.  unsigned int (*_bfd_coff_swap_lineno_out)
1415
.    (bfd *, void *, void *);
1416
.
1417
.  unsigned int (*_bfd_coff_swap_reloc_out)
1418
.    (bfd *, void *, void *);
1419
.
1420
.  unsigned int (*_bfd_coff_swap_filehdr_out)
1421
.    (bfd *, void *, void *);
1422
.
1423
.  unsigned int (*_bfd_coff_swap_aouthdr_out)
1424
.    (bfd *, void *, void *);
1425
.
1426
.  unsigned int (*_bfd_coff_swap_scnhdr_out)
1427
.    (bfd *, void *, void *);
1428
.
1429
.  unsigned int _bfd_filhsz;
1430
.  unsigned int _bfd_aoutsz;
1431
.  unsigned int _bfd_scnhsz;
1432
.  unsigned int _bfd_symesz;
1433
.  unsigned int _bfd_auxesz;
1434
.  unsigned int _bfd_relsz;
1435
.  unsigned int _bfd_linesz;
1436
.  unsigned int _bfd_filnmlen;
1437
.  bool _bfd_coff_long_filenames;
1438
.
1439
.  bool _bfd_coff_long_section_names;
1440
.  bool (*_bfd_coff_set_long_section_names)
1441
.    (bfd *, int);
1442
.
1443
.  unsigned int _bfd_coff_default_section_alignment_power;
1444
.  bool _bfd_coff_force_symnames_in_strings;
1445
.  unsigned int _bfd_coff_debug_string_prefix_length;
1446
.  unsigned int _bfd_coff_max_nscns;
1447
.
1448
.  void (*_bfd_coff_swap_filehdr_in)
1449
.    (bfd *, void *, void *);
1450
.
1451
.  void (*_bfd_coff_swap_aouthdr_in)
1452
.    (bfd *, void *, void *);
1453
.
1454
.  void (*_bfd_coff_swap_scnhdr_in)
1455
.    (bfd *, void *, void *);
1456
.
1457
.  void (*_bfd_coff_swap_reloc_in)
1458
.    (bfd *abfd, void *, void *);
1459
.
1460
.  bool (*_bfd_coff_bad_format_hook)
1461
.    (bfd *, void *);
1462
.
1463
.  bool (*_bfd_coff_set_arch_mach_hook)
1464
.    (bfd *, void *);
1465
.
1466
.  void * (*_bfd_coff_mkobject_hook)
1467
.    (bfd *, void *, void *);
1468
.
1469
.  bool (*_bfd_styp_to_sec_flags_hook)
1470
.    (bfd *, void *, const char *, asection *, flagword *);
1471
.
1472
.  void (*_bfd_set_alignment_hook)
1473
.    (bfd *, asection *, void *);
1474
.
1475
.  bool (*_bfd_coff_slurp_symbol_table)
1476
.    (bfd *);
1477
.
1478
.  bool (*_bfd_coff_symname_in_debug)
1479
.    (bfd *, struct internal_syment *);
1480
.
1481
.  bool (*_bfd_coff_pointerize_aux_hook)
1482
.    (bfd *, combined_entry_type *, combined_entry_type *,
1483
.     unsigned int, combined_entry_type *);
1484
.
1485
.  bool (*_bfd_coff_print_aux)
1486
.    (bfd *, FILE *, combined_entry_type *, combined_entry_type *,
1487
.     combined_entry_type *, unsigned int);
1488
.
1489
.  bool (*_bfd_coff_reloc16_extra_cases)
1490
.    (bfd *, struct bfd_link_info *, struct bfd_link_order *, arelent *,
1491
.     bfd_byte *, size_t *, size_t *);
1492
.
1493
.  int (*_bfd_coff_reloc16_estimate)
1494
.    (bfd *, asection *, arelent *, unsigned int,
1495
.     struct bfd_link_info *);
1496
.
1497
.  enum coff_symbol_classification (*_bfd_coff_classify_symbol)
1498
.    (bfd *, struct internal_syment *);
1499
.
1500
.  bool (*_bfd_coff_compute_section_file_positions)
1501
.    (bfd *);
1502
.
1503
.  bool (*_bfd_coff_start_final_link)
1504
.    (bfd *, struct bfd_link_info *);
1505
.
1506
.  bool (*_bfd_coff_relocate_section)
1507
.    (bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
1508
.     struct internal_reloc *, struct internal_syment *, asection **);
1509
.
1510
.  reloc_howto_type *(*_bfd_coff_rtype_to_howto)
1511
.    (bfd *, asection *, struct internal_reloc *,
1512
.     struct coff_link_hash_entry *, struct internal_syment *, bfd_vma *);
1513
.
1514
.  bool (*_bfd_coff_adjust_symndx)
1515
.    (bfd *, struct bfd_link_info *, bfd *, asection *,
1516
.     struct internal_reloc *, bool *);
1517
.
1518
.  bool (*_bfd_coff_link_add_one_symbol)
1519
.    (struct bfd_link_info *, bfd *, const char *, flagword,
1520
.     asection *, bfd_vma, const char *, bool, bool,
1521
.     struct bfd_link_hash_entry **);
1522
.
1523
.  bool (*_bfd_coff_link_output_has_begun)
1524
.    (bfd *, struct coff_final_link_info *);
1525
.
1526
.  bool (*_bfd_coff_final_link_postscript)
1527
.    (bfd *, struct coff_final_link_info *);
1528
.
1529
.  bool (*_bfd_coff_print_pdata)
1530
.    (bfd *, void *);
1531
.
1532
.} bfd_coff_backend_data;
1533
.
1534
1535
INTERNAL
1536
.#define coff_backend_info(abfd) \
1537
.  ((const bfd_coff_backend_data *) (abfd)->xvec->backend_data)
1538
.
1539
.#define bfd_coff_swap_aux_in(a,e,t,c,ind,num,i) \
1540
.  ((coff_backend_info (a)->_bfd_coff_swap_aux_in) (a,e,t,c,ind,num,i))
1541
.
1542
.#define bfd_coff_swap_sym_in(a,e,i) \
1543
.  ((coff_backend_info (a)->_bfd_coff_swap_sym_in) (a,e,i))
1544
.
1545
.#define bfd_coff_swap_lineno_in(a,e,i) \
1546
.  ((coff_backend_info ( a)->_bfd_coff_swap_lineno_in) (a,e,i))
1547
.
1548
.#define bfd_coff_swap_reloc_out(abfd, i, o) \
1549
.  ((coff_backend_info (abfd)->_bfd_coff_swap_reloc_out) (abfd, i, o))
1550
.
1551
.#define bfd_coff_swap_lineno_out(abfd, i, o) \
1552
.  ((coff_backend_info (abfd)->_bfd_coff_swap_lineno_out) (abfd, i, o))
1553
.
1554
.#define bfd_coff_swap_aux_out(a,i,t,c,ind,num,o) \
1555
.  ((coff_backend_info (a)->_bfd_coff_swap_aux_out) (a,i,t,c,ind,num,o))
1556
.
1557
.#define bfd_coff_swap_sym_out(abfd, i,o) \
1558
.  ((coff_backend_info (abfd)->_bfd_coff_swap_sym_out) (abfd, i, o))
1559
.
1560
.#define bfd_coff_swap_scnhdr_out(abfd, i,o) \
1561
.  ((coff_backend_info (abfd)->_bfd_coff_swap_scnhdr_out) (abfd, i, o))
1562
.
1563
.#define bfd_coff_swap_filehdr_out(abfd, i,o) \
1564
.  ((coff_backend_info (abfd)->_bfd_coff_swap_filehdr_out) (abfd, i, o))
1565
.
1566
.#define bfd_coff_swap_aouthdr_out(abfd, i,o) \
1567
.  ((coff_backend_info (abfd)->_bfd_coff_swap_aouthdr_out) (abfd, i, o))
1568
.
1569
.#define bfd_coff_filhsz(abfd) (coff_backend_info (abfd)->_bfd_filhsz)
1570
.#define bfd_coff_aoutsz(abfd) (coff_backend_info (abfd)->_bfd_aoutsz)
1571
.#define bfd_coff_scnhsz(abfd) (coff_backend_info (abfd)->_bfd_scnhsz)
1572
.#define bfd_coff_symesz(abfd) (coff_backend_info (abfd)->_bfd_symesz)
1573
.#define bfd_coff_auxesz(abfd) (coff_backend_info (abfd)->_bfd_auxesz)
1574
.#define bfd_coff_relsz(abfd)  (coff_backend_info (abfd)->_bfd_relsz)
1575
.#define bfd_coff_linesz(abfd) (coff_backend_info (abfd)->_bfd_linesz)
1576
.#define bfd_coff_filnmlen(abfd) (coff_backend_info (abfd)->_bfd_filnmlen)
1577
.#define bfd_coff_long_filenames(abfd) \
1578
.  (coff_backend_info (abfd)->_bfd_coff_long_filenames)
1579
.#define bfd_coff_long_section_names(abfd) \
1580
.  (coff_data (abfd)->long_section_names)
1581
.#define bfd_coff_set_long_section_names(abfd, enable) \
1582
.  ((coff_backend_info (abfd)->_bfd_coff_set_long_section_names) (abfd, enable))
1583
.#define bfd_coff_default_section_alignment_power(abfd) \
1584
.  (coff_backend_info (abfd)->_bfd_coff_default_section_alignment_power)
1585
.#define bfd_coff_max_nscns(abfd) \
1586
.  (coff_backend_info (abfd)->_bfd_coff_max_nscns)
1587
.
1588
.#define bfd_coff_swap_filehdr_in(abfd, i,o) \
1589
.  ((coff_backend_info (abfd)->_bfd_coff_swap_filehdr_in) (abfd, i, o))
1590
.
1591
.#define bfd_coff_swap_aouthdr_in(abfd, i,o) \
1592
.  ((coff_backend_info (abfd)->_bfd_coff_swap_aouthdr_in) (abfd, i, o))
1593
.
1594
.#define bfd_coff_swap_scnhdr_in(abfd, i,o) \
1595
.  ((coff_backend_info (abfd)->_bfd_coff_swap_scnhdr_in) (abfd, i, o))
1596
.
1597
.#define bfd_coff_swap_reloc_in(abfd, i, o) \
1598
.  ((coff_backend_info (abfd)->_bfd_coff_swap_reloc_in) (abfd, i, o))
1599
.
1600
.#define bfd_coff_bad_format_hook(abfd, filehdr) \
1601
.  ((coff_backend_info (abfd)->_bfd_coff_bad_format_hook) (abfd, filehdr))
1602
.
1603
.#define bfd_coff_set_arch_mach_hook(abfd, filehdr)\
1604
.  ((coff_backend_info (abfd)->_bfd_coff_set_arch_mach_hook) (abfd, filehdr))
1605
.#define bfd_coff_mkobject_hook(abfd, filehdr, aouthdr)\
1606
.  ((coff_backend_info (abfd)->_bfd_coff_mkobject_hook)\
1607
.   (abfd, filehdr, aouthdr))
1608
.
1609
.#define bfd_coff_styp_to_sec_flags_hook(abfd, scnhdr, name, section, flags_ptr)\
1610
.  ((coff_backend_info (abfd)->_bfd_styp_to_sec_flags_hook)\
1611
.   (abfd, scnhdr, name, section, flags_ptr))
1612
.
1613
.#define bfd_coff_set_alignment_hook(abfd, sec, scnhdr)\
1614
.  ((coff_backend_info (abfd)->_bfd_set_alignment_hook) (abfd, sec, scnhdr))
1615
.
1616
.#define bfd_coff_slurp_symbol_table(abfd)\
1617
.  ((coff_backend_info (abfd)->_bfd_coff_slurp_symbol_table) (abfd))
1618
.
1619
.#define bfd_coff_symname_in_debug(abfd, sym)\
1620
.  ((coff_backend_info (abfd)->_bfd_coff_symname_in_debug) (abfd, sym))
1621
.
1622
.#define bfd_coff_force_symnames_in_strings(abfd)\
1623
.  (coff_backend_info (abfd)->_bfd_coff_force_symnames_in_strings)
1624
.
1625
.#define bfd_coff_debug_string_prefix_length(abfd)\
1626
.  (coff_backend_info (abfd)->_bfd_coff_debug_string_prefix_length)
1627
.
1628
.#define bfd_coff_print_aux(abfd, file, base, symbol, aux, indaux)\
1629
.  ((coff_backend_info (abfd)->_bfd_coff_print_aux)\
1630
.   (abfd, file, base, symbol, aux, indaux))
1631
.
1632
.#define bfd_coff_reloc16_extra_cases(abfd, link_info, link_order,\
1633
.             reloc, data, src_ptr, dst_ptr)\
1634
.  ((coff_backend_info (abfd)->_bfd_coff_reloc16_extra_cases)\
1635
.   (abfd, link_info, link_order, reloc, data, src_ptr, dst_ptr))
1636
.
1637
.#define bfd_coff_reloc16_estimate(abfd, section, reloc, shrink, link_info)\
1638
.  ((coff_backend_info (abfd)->_bfd_coff_reloc16_estimate)\
1639
.   (abfd, section, reloc, shrink, link_info))
1640
.
1641
.#define bfd_coff_classify_symbol(abfd, sym)\
1642
.  ((coff_backend_info (abfd)->_bfd_coff_classify_symbol)\
1643
.   (abfd, sym))
1644
.
1645
.#define bfd_coff_compute_section_file_positions(abfd)\
1646
.  ((coff_backend_info (abfd)->_bfd_coff_compute_section_file_positions)\
1647
.   (abfd))
1648
.
1649
.#define bfd_coff_start_final_link(obfd, info)\
1650
.  ((coff_backend_info (obfd)->_bfd_coff_start_final_link)\
1651
.   (obfd, info))
1652
.#define bfd_coff_relocate_section(obfd,info,ibfd,o,con,rel,isyms,secs)\
1653
.  ((coff_backend_info (ibfd)->_bfd_coff_relocate_section)\
1654
.   (obfd, info, ibfd, o, con, rel, isyms, secs))
1655
.#define bfd_coff_rtype_to_howto(abfd, sec, rel, h, sym, addendp)\
1656
.  ((coff_backend_info (abfd)->_bfd_coff_rtype_to_howto)\
1657
.   (abfd, sec, rel, h, sym, addendp))
1658
.#define bfd_coff_adjust_symndx(obfd, info, ibfd, sec, rel, adjustedp)\
1659
.  ((coff_backend_info (abfd)->_bfd_coff_adjust_symndx)\
1660
.   (obfd, info, ibfd, sec, rel, adjustedp))
1661
.#define bfd_coff_link_add_one_symbol(info, abfd, name, flags, section,\
1662
.             value, string, cp, coll, hashp)\
1663
.  ((coff_backend_info (abfd)->_bfd_coff_link_add_one_symbol)\
1664
.   (info, abfd, name, flags, section, value, string, cp, coll, hashp))
1665
.
1666
.#define bfd_coff_link_output_has_begun(a,p) \
1667
.  ((coff_backend_info (a)->_bfd_coff_link_output_has_begun) (a, p))
1668
.#define bfd_coff_final_link_postscript(a,p) \
1669
.  ((coff_backend_info (a)->_bfd_coff_final_link_postscript) (a, p))
1670
.
1671
.#define bfd_coff_have_print_pdata(a) \
1672
.  (coff_backend_info (a)->_bfd_coff_print_pdata)
1673
.#define bfd_coff_print_pdata(a,p) \
1674
.  ((coff_backend_info (a)->_bfd_coff_print_pdata) (a, p))
1675
.
1676
.{* Macro: Returns true if the bfd is a PE executable as opposed to a
1677
.   PE object file.  *}
1678
.#define bfd_pei_p(abfd) \
1679
.  (startswith ((abfd)->xvec->name, "pei-"))
1680
*/
1681
1682
/* See whether the magic number matches.  */
1683
1684
static bool
1685
coff_bad_format_hook (bfd * abfd ATTRIBUTE_UNUSED, void * filehdr)
1686
119k
{
1687
119k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
119k
  if (BADMAG (*internal_f))
1690
114k
    return false;
1691
1692
5.35k
  return true;
1693
119k
}
pei-i386.c:coff_bad_format_hook
Line
Count
Source
1686
460
{
1687
460
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
460
  if (BADMAG (*internal_f))
1690
380
    return false;
1691
1692
80
  return true;
1693
460
}
pe-x86_64.c:coff_bad_format_hook
Line
Count
Source
1686
9.49k
{
1687
9.49k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
9.49k
  if (BADMAG (*internal_f))
1690
9.36k
    return false;
1691
1692
133
  return true;
1693
9.49k
}
pei-x86_64.c:coff_bad_format_hook
Line
Count
Source
1686
462
{
1687
462
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
462
  if (BADMAG (*internal_f))
1690
386
    return false;
1691
1692
76
  return true;
1693
462
}
coff-x86_64.c:coff_bad_format_hook
Line
Count
Source
1686
4.73k
{
1687
4.73k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
4.73k
  if (BADMAG (*internal_f))
1690
4.63k
    return false;
1691
1692
101
  return true;
1693
4.73k
}
Unexecuted instantiation: coff64-rs6000.c:coff_bad_format_hook
pe-aarch64.c:coff_bad_format_hook
Line
Count
Source
1686
4.73k
{
1687
4.73k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
4.73k
  if (BADMAG (*internal_f))
1690
4.67k
    return false;
1691
1692
61
  return true;
1693
4.73k
}
pei-aarch64.c:coff_bad_format_hook
Line
Count
Source
1686
458
{
1687
458
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
458
  if (BADMAG (*internal_f))
1690
395
    return false;
1691
1692
63
  return true;
1693
458
}
pei-ia64.c:coff_bad_format_hook
Line
Count
Source
1686
239
{
1687
239
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
239
  if (BADMAG (*internal_f))
1690
164
    return false;
1691
1692
75
  return true;
1693
239
}
pei-loongarch64.c:coff_bad_format_hook
Line
Count
Source
1686
456
{
1687
456
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
456
  if (BADMAG (*internal_f))
1690
323
    return false;
1691
1692
133
  return true;
1693
456
}
cf-i386lynx.c:coff_bad_format_hook
Line
Count
Source
1686
4.73k
{
1687
4.73k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
4.73k
  if (BADMAG (*internal_f))
1690
4.58k
    return false;
1691
1692
150
  return true;
1693
4.73k
}
coff-go32.c:coff_bad_format_hook
Line
Count
Source
1686
4.73k
{
1687
4.73k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
4.73k
  if (BADMAG (*internal_f))
1690
4.65k
    return false;
1691
1692
74
  return true;
1693
4.73k
}
coff-i386.c:coff_bad_format_hook
Line
Count
Source
1686
4.73k
{
1687
4.73k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
4.73k
  if (BADMAG (*internal_f))
1690
4.65k
    return false;
1691
1692
74
  return true;
1693
4.73k
}
coff-rs6000.c:coff_bad_format_hook
Line
Count
Source
1686
4.51k
{
1687
4.51k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
4.51k
  if (BADMAG (*internal_f))
1690
4.38k
    return false;
1691
1692
133
  return true;
1693
4.51k
}
coff-sh.c:coff_bad_format_hook
Line
Count
Source
1686
14.6k
{
1687
14.6k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
14.6k
  if (BADMAG (*internal_f))
1690
12.2k
    return false;
1691
1692
2.41k
  return true;
1693
14.6k
}
coff-stgo32.c:coff_bad_format_hook
Line
Count
Source
1686
106
{
1687
106
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
106
  if (BADMAG (*internal_f))
1690
0
    return false;
1691
1692
106
  return true;
1693
106
}
coff-tic30.c:coff_bad_format_hook
Line
Count
Source
1686
4.51k
{
1687
4.51k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
4.51k
  if (BADMAG (*internal_f))
1690
4.47k
    return false;
1691
1692
40
  return true;
1693
4.51k
}
Unexecuted instantiation: coff-tic4x.c:coff_bad_format_hook
coff-tic54x.c:coff_bad_format_hook
Line
Count
Source
1686
9.03k
{
1687
9.03k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
9.03k
  if (BADMAG (*internal_f))
1690
9.03k
    return false;
1691
1692
0
  return true;
1693
9.03k
}
coff-z80.c:coff_bad_format_hook
Line
Count
Source
1686
4.51k
{
1687
4.51k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
4.51k
  if (BADMAG (*internal_f))
1690
4.47k
    return false;
1691
1692
42
  return true;
1693
4.51k
}
coff-z8k.c:coff_bad_format_hook
Line
Count
Source
1686
4.51k
{
1687
4.51k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
4.51k
  if (BADMAG (*internal_f))
1690
4.46k
    return false;
1691
1692
49
  return true;
1693
4.51k
}
pe-arm-wince.c:coff_bad_format_hook
Line
Count
Source
1686
9.03k
{
1687
9.03k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
9.03k
  if (BADMAG (*internal_f))
1690
9.02k
    return false;
1691
1692
5
  return true;
1693
9.03k
}
pe-arm.c:coff_bad_format_hook
Line
Count
Source
1686
9.03k
{
1687
9.03k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
9.03k
  if (BADMAG (*internal_f))
1690
9.02k
    return false;
1691
1692
5
  return true;
1693
9.03k
}
pe-i386.c:coff_bad_format_hook
Line
Count
Source
1686
9.46k
{
1687
9.46k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
9.46k
  if (BADMAG (*internal_f))
1690
9.31k
    return false;
1691
1692
152
  return true;
1693
9.46k
}
pe-mcore.c:coff_bad_format_hook
Line
Count
Source
1686
9.03k
{
1687
9.03k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
9.03k
  if (BADMAG (*internal_f))
1690
8.99k
    return false;
1691
1692
38
  return true;
1693
9.03k
}
pe-sh.c:coff_bad_format_hook
Line
Count
Source
1686
4.51k
{
1687
4.51k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
4.51k
  if (BADMAG (*internal_f))
1690
3.22k
    return false;
1691
1692
1.29k
  return true;
1693
4.51k
}
pei-arm-wince.c:coff_bad_format_hook
Line
Count
Source
1686
396
{
1687
396
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
396
  if (BADMAG (*internal_f))
1690
382
    return false;
1691
1692
14
  return true;
1693
396
}
pei-arm.c:coff_bad_format_hook
Line
Count
Source
1686
396
{
1687
396
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
396
  if (BADMAG (*internal_f))
1690
382
    return false;
1691
1692
14
  return true;
1693
396
}
pei-mcore.c:coff_bad_format_hook
Line
Count
Source
1686
395
{
1687
395
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
395
  if (BADMAG (*internal_f))
1690
390
    return false;
1691
1692
5
  return true;
1693
395
}
pei-sh.c:coff_bad_format_hook
Line
Count
Source
1686
395
{
1687
395
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
395
  if (BADMAG (*internal_f))
1690
375
    return false;
1691
1692
20
  return true;
1693
395
}
1694
1695
#ifdef TICOFF
1696
static bool
1697
ticoff0_bad_format_hook (bfd *abfd ATTRIBUTE_UNUSED, void * filehdr)
1698
9.03k
{
1699
9.03k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1700
1701
9.03k
  if (COFF0_BADMAG (*internal_f))
1702
8.96k
    return false;
1703
1704
68
  return true;
1705
9.03k
}
Unexecuted instantiation: coff-tic4x.c:ticoff0_bad_format_hook
coff-tic54x.c:ticoff0_bad_format_hook
Line
Count
Source
1698
9.03k
{
1699
9.03k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1700
1701
9.03k
  if (COFF0_BADMAG (*internal_f))
1702
8.96k
    return false;
1703
1704
68
  return true;
1705
9.03k
}
1706
#endif
1707
1708
#ifdef TICOFF
1709
static bool
1710
ticoff1_bad_format_hook (bfd *abfd ATTRIBUTE_UNUSED, void * filehdr)
1711
9.03k
{
1712
9.03k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1713
1714
9.03k
  if (COFF1_BADMAG (*internal_f))
1715
9.03k
    return false;
1716
1717
0
  return true;
1718
9.03k
}
Unexecuted instantiation: coff-tic4x.c:ticoff1_bad_format_hook
coff-tic54x.c:ticoff1_bad_format_hook
Line
Count
Source
1711
9.03k
{
1712
9.03k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1713
1714
9.03k
  if (COFF1_BADMAG (*internal_f))
1715
9.03k
    return false;
1716
1717
0
  return true;
1718
9.03k
}
1719
#endif
1720
1721
/* Check whether this section uses an alignment other than the
1722
   default.  */
1723
1724
static void
1725
coff_set_custom_section_alignment (bfd *abfd ATTRIBUTE_UNUSED,
1726
           asection *section,
1727
           const struct coff_section_alignment_entry *alignment_table,
1728
           const unsigned int table_size)
1729
1.13M
{
1730
1.13M
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
1.13M
  unsigned int i;
1732
1733
6.22M
  for (i = 0; i < table_size; ++i)
1734
5.09M
    {
1735
5.09M
      const char *secname = bfd_section_name (section);
1736
1737
5.09M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
5.09M
    ? strcmp (alignment_table[i].name, secname) == 0
1739
5.09M
    : strncmp (alignment_table[i].name, secname,
1740
2.58M
         alignment_table[i].comparison_length) == 0)
1741
1.56k
  break;
1742
5.09M
    }
1743
1.13M
  if (i >= table_size)
1744
1.13M
    return;
1745
1746
1.56k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
1.56k
      && default_alignment < alignment_table[i].default_alignment_min)
1748
179
    return;
1749
1750
1.38k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
0
      && default_alignment > alignment_table[i].default_alignment_max
1753
#endif
1754
1.38k
      )
1755
0
    return;
1756
1757
1.38k
  section->alignment_power = alignment_table[i].alignment_power;
1758
1.38k
}
pei-i386.c:coff_set_custom_section_alignment
Line
Count
Source
1729
193
{
1730
193
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
193
  unsigned int i;
1732
1733
1.72k
  for (i = 0; i < table_size; ++i)
1734
1.53k
    {
1735
1.53k
      const char *secname = bfd_section_name (section);
1736
1737
1.53k
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
1.53k
    ? strcmp (alignment_table[i].name, secname) == 0
1739
1.53k
    : strncmp (alignment_table[i].name, secname,
1740
957
         alignment_table[i].comparison_length) == 0)
1741
2
  break;
1742
1.53k
    }
1743
193
  if (i >= table_size)
1744
191
    return;
1745
1746
2
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
2
      && default_alignment < alignment_table[i].default_alignment_min)
1748
0
    return;
1749
1750
2
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
2
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
2
      && default_alignment > alignment_table[i].default_alignment_max
1753
2
#endif
1754
2
      )
1755
0
    return;
1756
1757
2
  section->alignment_power = alignment_table[i].alignment_power;
1758
2
}
pe-x86_64.c:coff_set_custom_section_alignment
Line
Count
Source
1729
538
{
1730
538
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
538
  unsigned int i;
1732
1733
7.40k
  for (i = 0; i < table_size; ++i)
1734
6.88k
    {
1735
6.88k
      const char *secname = bfd_section_name (section);
1736
1737
6.88k
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
6.88k
    ? strcmp (alignment_table[i].name, secname) == 0
1739
6.88k
    : strncmp (alignment_table[i].name, secname,
1740
4.76k
         alignment_table[i].comparison_length) == 0)
1741
17
  break;
1742
6.88k
    }
1743
538
  if (i >= table_size)
1744
521
    return;
1745
1746
17
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
17
      && default_alignment < alignment_table[i].default_alignment_min)
1748
0
    return;
1749
1750
17
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
17
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
17
      && default_alignment > alignment_table[i].default_alignment_max
1753
17
#endif
1754
17
      )
1755
0
    return;
1756
1757
17
  section->alignment_power = alignment_table[i].alignment_power;
1758
17
}
pei-x86_64.c:coff_set_custom_section_alignment
Line
Count
Source
1729
849
{
1730
849
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
849
  unsigned int i;
1732
1733
8.71k
  for (i = 0; i < table_size; ++i)
1734
8.18k
    {
1735
8.18k
      const char *secname = bfd_section_name (section);
1736
1737
8.18k
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
8.18k
    ? strcmp (alignment_table[i].name, secname) == 0
1739
8.18k
    : strncmp (alignment_table[i].name, secname,
1740
5.52k
         alignment_table[i].comparison_length) == 0)
1741
314
  break;
1742
8.18k
    }
1743
849
  if (i >= table_size)
1744
535
    return;
1745
1746
314
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
314
      && default_alignment < alignment_table[i].default_alignment_min)
1748
3
    return;
1749
1750
311
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
311
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
311
      && default_alignment > alignment_table[i].default_alignment_max
1753
311
#endif
1754
311
      )
1755
0
    return;
1756
1757
311
  section->alignment_power = alignment_table[i].alignment_power;
1758
311
}
coff-x86_64.c:coff_set_custom_section_alignment
Line
Count
Source
1729
20.3k
{
1730
20.3k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
20.3k
  unsigned int i;
1732
1733
101k
  for (i = 0; i < table_size; ++i)
1734
81.5k
    {
1735
81.5k
      const char *secname = bfd_section_name (section);
1736
1737
81.5k
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
81.5k
    ? strcmp (alignment_table[i].name, secname) == 0
1739
81.5k
    : strncmp (alignment_table[i].name, secname,
1740
40.7k
         alignment_table[i].comparison_length) == 0)
1741
0
  break;
1742
81.5k
    }
1743
20.3k
  if (i >= table_size)
1744
20.3k
    return;
1745
1746
0
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
0
      && default_alignment < alignment_table[i].default_alignment_min)
1748
0
    return;
1749
1750
0
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
0
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
0
      && default_alignment > alignment_table[i].default_alignment_max
1753
0
#endif
1754
0
      )
1755
0
    return;
1756
1757
0
  section->alignment_power = alignment_table[i].alignment_power;
1758
0
}
coff64-rs6000.c:coff_set_custom_section_alignment
Line
Count
Source
1729
180k
{
1730
180k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
180k
  unsigned int i;
1732
1733
899k
  for (i = 0; i < table_size; ++i)
1734
720k
    {
1735
720k
      const char *secname = bfd_section_name (section);
1736
1737
720k
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
720k
    ? strcmp (alignment_table[i].name, secname) == 0
1739
720k
    : strncmp (alignment_table[i].name, secname,
1740
360k
         alignment_table[i].comparison_length) == 0)
1741
271
  break;
1742
720k
    }
1743
180k
  if (i >= table_size)
1744
179k
    return;
1745
1746
271
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
271
      && default_alignment < alignment_table[i].default_alignment_min)
1748
0
    return;
1749
1750
271
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
271
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
271
      && default_alignment > alignment_table[i].default_alignment_max
1753
271
#endif
1754
271
      )
1755
0
    return;
1756
1757
271
  section->alignment_power = alignment_table[i].alignment_power;
1758
271
}
pe-aarch64.c:coff_set_custom_section_alignment
Line
Count
Source
1729
186
{
1730
186
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
186
  unsigned int i;
1732
1733
2.20k
  for (i = 0; i < table_size; ++i)
1734
2.05k
    {
1735
2.05k
      const char *secname = bfd_section_name (section);
1736
1737
2.05k
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
2.05k
    ? strcmp (alignment_table[i].name, secname) == 0
1739
2.05k
    : strncmp (alignment_table[i].name, secname,
1740
822
         alignment_table[i].comparison_length) == 0)
1741
36
  break;
1742
2.05k
    }
1743
186
  if (i >= table_size)
1744
150
    return;
1745
1746
36
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
36
      && default_alignment < alignment_table[i].default_alignment_min)
1748
0
    return;
1749
1750
36
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
36
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
36
      && default_alignment > alignment_table[i].default_alignment_max
1753
36
#endif
1754
36
      )
1755
0
    return;
1756
1757
36
  section->alignment_power = alignment_table[i].alignment_power;
1758
36
}
pei-aarch64.c:coff_set_custom_section_alignment
Line
Count
Source
1729
5.47k
{
1730
5.47k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
5.47k
  unsigned int i;
1732
1733
71.1k
  for (i = 0; i < table_size; ++i)
1734
65.6k
    {
1735
65.6k
      const char *secname = bfd_section_name (section);
1736
1737
65.6k
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
65.6k
    ? strcmp (alignment_table[i].name, secname) == 0
1739
65.6k
    : strncmp (alignment_table[i].name, secname,
1740
27.3k
         alignment_table[i].comparison_length) == 0)
1741
4
  break;
1742
65.6k
    }
1743
5.47k
  if (i >= table_size)
1744
5.46k
    return;
1745
1746
4
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
4
      && default_alignment < alignment_table[i].default_alignment_min)
1748
2
    return;
1749
1750
2
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
2
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
2
      && default_alignment > alignment_table[i].default_alignment_max
1753
2
#endif
1754
2
      )
1755
0
    return;
1756
1757
2
  section->alignment_power = alignment_table[i].alignment_power;
1758
2
}
pei-ia64.c:coff_set_custom_section_alignment
Line
Count
Source
1729
162
{
1730
162
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
162
  unsigned int i;
1732
1733
810
  for (i = 0; i < table_size; ++i)
1734
648
    {
1735
648
      const char *secname = bfd_section_name (section);
1736
1737
648
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
648
    ? strcmp (alignment_table[i].name, secname) == 0
1739
648
    : strncmp (alignment_table[i].name, secname,
1740
324
         alignment_table[i].comparison_length) == 0)
1741
0
  break;
1742
648
    }
1743
162
  if (i >= table_size)
1744
162
    return;
1745
1746
0
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
0
      && default_alignment < alignment_table[i].default_alignment_min)
1748
0
    return;
1749
1750
0
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
0
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
0
      && default_alignment > alignment_table[i].default_alignment_max
1753
0
#endif
1754
0
      )
1755
0
    return;
1756
1757
0
  section->alignment_power = alignment_table[i].alignment_power;
1758
0
}
pei-loongarch64.c:coff_set_custom_section_alignment
Line
Count
Source
1729
415
{
1730
415
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
415
  unsigned int i;
1732
1733
5.32k
  for (i = 0; i < table_size; ++i)
1734
4.93k
    {
1735
4.93k
      const char *secname = bfd_section_name (section);
1736
1737
4.93k
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
4.93k
    ? strcmp (alignment_table[i].name, secname) == 0
1739
4.93k
    : strncmp (alignment_table[i].name, secname,
1740
2.07k
         alignment_table[i].comparison_length) == 0)
1741
24
  break;
1742
4.93k
    }
1743
415
  if (i >= table_size)
1744
391
    return;
1745
1746
24
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
24
      && default_alignment < alignment_table[i].default_alignment_min)
1748
24
    return;
1749
1750
0
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
0
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
0
      && default_alignment > alignment_table[i].default_alignment_max
1753
0
#endif
1754
0
      )
1755
0
    return;
1756
1757
0
  section->alignment_power = alignment_table[i].alignment_power;
1758
0
}
cf-i386lynx.c:coff_set_custom_section_alignment
Line
Count
Source
1729
82.1k
{
1730
82.1k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
82.1k
  unsigned int i;
1732
1733
410k
  for (i = 0; i < table_size; ++i)
1734
328k
    {
1735
328k
      const char *secname = bfd_section_name (section);
1736
1737
328k
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
328k
    ? strcmp (alignment_table[i].name, secname) == 0
1739
328k
    : strncmp (alignment_table[i].name, secname,
1740
164k
         alignment_table[i].comparison_length) == 0)
1741
120
  break;
1742
328k
    }
1743
82.1k
  if (i >= table_size)
1744
82.0k
    return;
1745
1746
120
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
120
      && default_alignment < alignment_table[i].default_alignment_min)
1748
42
    return;
1749
1750
78
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
78
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
78
      && default_alignment > alignment_table[i].default_alignment_max
1753
78
#endif
1754
78
      )
1755
0
    return;
1756
1757
78
  section->alignment_power = alignment_table[i].alignment_power;
1758
78
}
coff-go32.c:coff_set_custom_section_alignment
Line
Count
Source
1729
7.68k
{
1730
7.68k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
7.68k
  unsigned int i;
1732
1733
122k
  for (i = 0; i < table_size; ++i)
1734
115k
    {
1735
115k
      const char *secname = bfd_section_name (section);
1736
1737
115k
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
115k
    ? strcmp (alignment_table[i].name, secname) == 0
1739
115k
    : strncmp (alignment_table[i].name, secname,
1740
99.6k
         alignment_table[i].comparison_length) == 0)
1741
24
  break;
1742
115k
    }
1743
7.68k
  if (i >= table_size)
1744
7.65k
    return;
1745
1746
24
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
24
      && default_alignment < alignment_table[i].default_alignment_min)
1748
2
    return;
1749
1750
22
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
22
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
22
      && default_alignment > alignment_table[i].default_alignment_max
1753
22
#endif
1754
22
      )
1755
0
    return;
1756
1757
22
  section->alignment_power = alignment_table[i].alignment_power;
1758
22
}
coff-i386.c:coff_set_custom_section_alignment
Line
Count
Source
1729
7.92k
{
1730
7.92k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
7.92k
  unsigned int i;
1732
1733
39.6k
  for (i = 0; i < table_size; ++i)
1734
31.6k
    {
1735
31.6k
      const char *secname = bfd_section_name (section);
1736
1737
31.6k
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
31.6k
    ? strcmp (alignment_table[i].name, secname) == 0
1739
31.6k
    : strncmp (alignment_table[i].name, secname,
1740
15.8k
         alignment_table[i].comparison_length) == 0)
1741
2
  break;
1742
31.6k
    }
1743
7.92k
  if (i >= table_size)
1744
7.91k
    return;
1745
1746
2
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
2
      && default_alignment < alignment_table[i].default_alignment_min)
1748
2
    return;
1749
1750
0
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
0
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
0
      && default_alignment > alignment_table[i].default_alignment_max
1753
0
#endif
1754
0
      )
1755
0
    return;
1756
1757
0
  section->alignment_power = alignment_table[i].alignment_power;
1758
0
}
coff-rs6000.c:coff_set_custom_section_alignment
Line
Count
Source
1729
220k
{
1730
220k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
220k
  unsigned int i;
1732
1733
1.10M
  for (i = 0; i < table_size; ++i)
1734
882k
    {
1735
882k
      const char *secname = bfd_section_name (section);
1736
1737
882k
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
882k
    ? strcmp (alignment_table[i].name, secname) == 0
1739
882k
    : strncmp (alignment_table[i].name, secname,
1740
441k
         alignment_table[i].comparison_length) == 0)
1741
1
  break;
1742
882k
    }
1743
220k
  if (i >= table_size)
1744
220k
    return;
1745
1746
1
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
1
      && default_alignment < alignment_table[i].default_alignment_min)
1748
0
    return;
1749
1750
1
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
1
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
1
      && default_alignment > alignment_table[i].default_alignment_max
1753
1
#endif
1754
1
      )
1755
0
    return;
1756
1757
1
  section->alignment_power = alignment_table[i].alignment_power;
1758
1
}
coff-sh.c:coff_set_custom_section_alignment
Line
Count
Source
1729
360k
{
1730
360k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
360k
  unsigned int i;
1732
1733
1.80M
  for (i = 0; i < table_size; ++i)
1734
1.44M
    {
1735
1.44M
      const char *secname = bfd_section_name (section);
1736
1737
1.44M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
1.44M
    ? strcmp (alignment_table[i].name, secname) == 0
1739
1.44M
    : strncmp (alignment_table[i].name, secname,
1740
721k
         alignment_table[i].comparison_length) == 0)
1741
254
  break;
1742
1.44M
    }
1743
360k
  if (i >= table_size)
1744
360k
    return;
1745
1746
254
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
254
      && default_alignment < alignment_table[i].default_alignment_min)
1748
0
    return;
1749
1750
254
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
254
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
254
      && default_alignment > alignment_table[i].default_alignment_max
1753
254
#endif
1754
254
      )
1755
0
    return;
1756
1757
254
  section->alignment_power = alignment_table[i].alignment_power;
1758
254
}
coff-stgo32.c:coff_set_custom_section_alignment
Line
Count
Source
1729
92.9k
{
1730
92.9k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
92.9k
  unsigned int i;
1732
1733
834k
  for (i = 0; i < table_size; ++i)
1734
741k
    {
1735
741k
      const char *secname = bfd_section_name (section);
1736
1737
741k
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
741k
    ? strcmp (alignment_table[i].name, secname) == 0
1739
741k
    : strncmp (alignment_table[i].name, secname,
1740
370k
         alignment_table[i].comparison_length) == 0)
1741
413
  break;
1742
741k
    }
1743
92.9k
  if (i >= table_size)
1744
92.5k
    return;
1745
1746
413
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
413
      && default_alignment < alignment_table[i].default_alignment_min)
1748
68
    return;
1749
1750
345
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
345
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
345
      && default_alignment > alignment_table[i].default_alignment_max
1753
345
#endif
1754
345
      )
1755
0
    return;
1756
1757
345
  section->alignment_power = alignment_table[i].alignment_power;
1758
345
}
coff-tic30.c:coff_set_custom_section_alignment
Line
Count
Source
1729
10.6k
{
1730
10.6k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
10.6k
  unsigned int i;
1732
1733
53.3k
  for (i = 0; i < table_size; ++i)
1734
42.6k
    {
1735
42.6k
      const char *secname = bfd_section_name (section);
1736
1737
42.6k
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
42.6k
    ? strcmp (alignment_table[i].name, secname) == 0
1739
42.6k
    : strncmp (alignment_table[i].name, secname,
1740
21.3k
         alignment_table[i].comparison_length) == 0)
1741
31
  break;
1742
42.6k
    }
1743
10.6k
  if (i >= table_size)
1744
10.6k
    return;
1745
1746
31
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
31
      && default_alignment < alignment_table[i].default_alignment_min)
1748
11
    return;
1749
1750
20
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
20
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
20
      && default_alignment > alignment_table[i].default_alignment_max
1753
20
#endif
1754
20
      )
1755
0
    return;
1756
1757
20
  section->alignment_power = alignment_table[i].alignment_power;
1758
20
}
Unexecuted instantiation: coff-tic4x.c:coff_set_custom_section_alignment
coff-tic54x.c:coff_set_custom_section_alignment
Line
Count
Source
1729
22.8k
{
1730
22.8k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
22.8k
  unsigned int i;
1732
1733
114k
  for (i = 0; i < table_size; ++i)
1734
91.4k
    {
1735
91.4k
      const char *secname = bfd_section_name (section);
1736
1737
91.4k
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
91.4k
    ? strcmp (alignment_table[i].name, secname) == 0
1739
91.4k
    : strncmp (alignment_table[i].name, secname,
1740
45.7k
         alignment_table[i].comparison_length) == 0)
1741
3
  break;
1742
91.4k
    }
1743
22.8k
  if (i >= table_size)
1744
22.8k
    return;
1745
1746
3
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
3
      && default_alignment < alignment_table[i].default_alignment_min)
1748
3
    return;
1749
1750
0
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
      && default_alignment > alignment_table[i].default_alignment_max
1753
#endif
1754
0
      )
1755
0
    return;
1756
1757
0
  section->alignment_power = alignment_table[i].alignment_power;
1758
0
}
coff-z80.c:coff_set_custom_section_alignment
Line
Count
Source
1729
9.17k
{
1730
9.17k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
9.17k
  unsigned int i;
1732
1733
45.8k
  for (i = 0; i < table_size; ++i)
1734
36.7k
    {
1735
36.7k
      const char *secname = bfd_section_name (section);
1736
1737
36.7k
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
36.7k
    ? strcmp (alignment_table[i].name, secname) == 0
1739
36.7k
    : strncmp (alignment_table[i].name, secname,
1740
18.3k
         alignment_table[i].comparison_length) == 0)
1741
1
  break;
1742
36.7k
    }
1743
9.17k
  if (i >= table_size)
1744
9.17k
    return;
1745
1746
1
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
1
      && default_alignment < alignment_table[i].default_alignment_min)
1748
1
    return;
1749
1750
0
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
      && default_alignment > alignment_table[i].default_alignment_max
1753
#endif
1754
0
      )
1755
0
    return;
1756
1757
0
  section->alignment_power = alignment_table[i].alignment_power;
1758
0
}
coff-z8k.c:coff_set_custom_section_alignment
Line
Count
Source
1729
99.5k
{
1730
99.5k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
99.5k
  unsigned int i;
1732
1733
497k
  for (i = 0; i < table_size; ++i)
1734
398k
    {
1735
398k
      const char *secname = bfd_section_name (section);
1736
1737
398k
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
398k
    ? strcmp (alignment_table[i].name, secname) == 0
1739
398k
    : strncmp (alignment_table[i].name, secname,
1740
199k
         alignment_table[i].comparison_length) == 0)
1741
24
  break;
1742
398k
    }
1743
99.5k
  if (i >= table_size)
1744
99.5k
    return;
1745
1746
24
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
24
      && default_alignment < alignment_table[i].default_alignment_min)
1748
19
    return;
1749
1750
5
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
5
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
5
      && default_alignment > alignment_table[i].default_alignment_max
1753
5
#endif
1754
5
      )
1755
0
    return;
1756
1757
5
  section->alignment_power = alignment_table[i].alignment_power;
1758
5
}
pe-arm-wince.c:coff_set_custom_section_alignment
Line
Count
Source
1729
4
{
1730
4
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
4
  unsigned int i;
1732
1733
56
  for (i = 0; i < table_size; ++i)
1734
52
    {
1735
52
      const char *secname = bfd_section_name (section);
1736
1737
52
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
52
    ? strcmp (alignment_table[i].name, secname) == 0
1739
52
    : strncmp (alignment_table[i].name, secname,
1740
24
         alignment_table[i].comparison_length) == 0)
1741
0
  break;
1742
52
    }
1743
4
  if (i >= table_size)
1744
4
    return;
1745
1746
0
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
0
      && default_alignment < alignment_table[i].default_alignment_min)
1748
0
    return;
1749
1750
0
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
0
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
0
      && default_alignment > alignment_table[i].default_alignment_max
1753
0
#endif
1754
0
      )
1755
0
    return;
1756
1757
0
  section->alignment_power = alignment_table[i].alignment_power;
1758
0
}
pe-arm.c:coff_set_custom_section_alignment
Line
Count
Source
1729
4
{
1730
4
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
4
  unsigned int i;
1732
1733
56
  for (i = 0; i < table_size; ++i)
1734
52
    {
1735
52
      const char *secname = bfd_section_name (section);
1736
1737
52
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
52
    ? strcmp (alignment_table[i].name, secname) == 0
1739
52
    : strncmp (alignment_table[i].name, secname,
1740
24
         alignment_table[i].comparison_length) == 0)
1741
0
  break;
1742
52
    }
1743
4
  if (i >= table_size)
1744
4
    return;
1745
1746
0
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
0
      && default_alignment < alignment_table[i].default_alignment_min)
1748
0
    return;
1749
1750
0
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
0
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
0
      && default_alignment > alignment_table[i].default_alignment_max
1753
0
#endif
1754
0
      )
1755
0
    return;
1756
1757
0
  section->alignment_power = alignment_table[i].alignment_power;
1758
0
}
pe-i386.c:coff_set_custom_section_alignment
Line
Count
Source
1729
1.53k
{
1730
1.53k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
1.53k
  unsigned int i;
1732
1733
15.2k
  for (i = 0; i < table_size; ++i)
1734
13.7k
    {
1735
13.7k
      const char *secname = bfd_section_name (section);
1736
1737
13.7k
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
13.7k
    ? strcmp (alignment_table[i].name, secname) == 0
1739
13.7k
    : strncmp (alignment_table[i].name, secname,
1740
9.14k
         alignment_table[i].comparison_length) == 0)
1741
23
  break;
1742
13.7k
    }
1743
1.53k
  if (i >= table_size)
1744
1.51k
    return;
1745
1746
23
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
23
      && default_alignment < alignment_table[i].default_alignment_min)
1748
1
    return;
1749
1750
22
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
22
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
22
      && default_alignment > alignment_table[i].default_alignment_max
1753
22
#endif
1754
22
      )
1755
0
    return;
1756
1757
22
  section->alignment_power = alignment_table[i].alignment_power;
1758
22
}
pe-mcore.c:coff_set_custom_section_alignment
Line
Count
Source
1729
224
{
1730
224
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
224
  unsigned int i;
1732
1733
1.12k
  for (i = 0; i < table_size; ++i)
1734
896
    {
1735
896
      const char *secname = bfd_section_name (section);
1736
1737
896
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
896
    ? strcmp (alignment_table[i].name, secname) == 0
1739
896
    : strncmp (alignment_table[i].name, secname,
1740
448
         alignment_table[i].comparison_length) == 0)
1741
0
  break;
1742
896
    }
1743
224
  if (i >= table_size)
1744
224
    return;
1745
1746
0
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
0
      && default_alignment < alignment_table[i].default_alignment_min)
1748
0
    return;
1749
1750
0
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
0
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
0
      && default_alignment > alignment_table[i].default_alignment_max
1753
0
#endif
1754
0
      )
1755
0
    return;
1756
1757
0
  section->alignment_power = alignment_table[i].alignment_power;
1758
0
}
pe-sh.c:coff_set_custom_section_alignment
Line
Count
Source
1729
5.04k
{
1730
5.04k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
5.04k
  unsigned int i;
1732
1733
25.2k
  for (i = 0; i < table_size; ++i)
1734
20.1k
    {
1735
20.1k
      const char *secname = bfd_section_name (section);
1736
1737
20.1k
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
20.1k
    ? strcmp (alignment_table[i].name, secname) == 0
1739
20.1k
    : strncmp (alignment_table[i].name, secname,
1740
10.0k
         alignment_table[i].comparison_length) == 0)
1741
0
  break;
1742
20.1k
    }
1743
5.04k
  if (i >= table_size)
1744
5.04k
    return;
1745
1746
0
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
0
      && default_alignment < alignment_table[i].default_alignment_min)
1748
0
    return;
1749
1750
0
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
0
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
0
      && default_alignment > alignment_table[i].default_alignment_max
1753
0
#endif
1754
0
      )
1755
0
    return;
1756
1757
0
  section->alignment_power = alignment_table[i].alignment_power;
1758
0
}
pei-arm-wince.c:coff_set_custom_section_alignment
Line
Count
Source
1729
4.11k
{
1730
4.11k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
4.11k
  unsigned int i;
1732
1733
53.4k
  for (i = 0; i < table_size; ++i)
1734
49.3k
    {
1735
49.3k
      const char *secname = bfd_section_name (section);
1736
1737
49.3k
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
49.3k
    ? strcmp (alignment_table[i].name, secname) == 0
1739
49.3k
    : strncmp (alignment_table[i].name, secname,
1740
20.5k
         alignment_table[i].comparison_length) == 0)
1741
3
  break;
1742
49.3k
    }
1743
4.11k
  if (i >= table_size)
1744
4.11k
    return;
1745
1746
3
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
3
      && default_alignment < alignment_table[i].default_alignment_min)
1748
1
    return;
1749
1750
2
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
2
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
2
      && default_alignment > alignment_table[i].default_alignment_max
1753
2
#endif
1754
2
      )
1755
0
    return;
1756
1757
2
  section->alignment_power = alignment_table[i].alignment_power;
1758
2
}
pei-arm.c:coff_set_custom_section_alignment
Line
Count
Source
1729
26
{
1730
26
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
26
  unsigned int i;
1732
1733
338
  for (i = 0; i < table_size; ++i)
1734
312
    {
1735
312
      const char *secname = bfd_section_name (section);
1736
1737
312
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
312
    ? strcmp (alignment_table[i].name, secname) == 0
1739
312
    : strncmp (alignment_table[i].name, secname,
1740
130
         alignment_table[i].comparison_length) == 0)
1741
0
  break;
1742
312
    }
1743
26
  if (i >= table_size)
1744
26
    return;
1745
1746
0
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
0
      && default_alignment < alignment_table[i].default_alignment_min)
1748
0
    return;
1749
1750
0
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
0
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
0
      && default_alignment > alignment_table[i].default_alignment_max
1753
0
#endif
1754
0
      )
1755
0
    return;
1756
1757
0
  section->alignment_power = alignment_table[i].alignment_power;
1758
0
}
pei-mcore.c:coff_set_custom_section_alignment
Line
Count
Source
1729
10
{
1730
10
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
10
  unsigned int i;
1732
1733
50
  for (i = 0; i < table_size; ++i)
1734
40
    {
1735
40
      const char *secname = bfd_section_name (section);
1736
1737
40
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
40
    ? strcmp (alignment_table[i].name, secname) == 0
1739
40
    : strncmp (alignment_table[i].name, secname,
1740
20
         alignment_table[i].comparison_length) == 0)
1741
0
  break;
1742
40
    }
1743
10
  if (i >= table_size)
1744
10
    return;
1745
1746
0
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
0
      && default_alignment < alignment_table[i].default_alignment_min)
1748
0
    return;
1749
1750
0
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
0
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
0
      && default_alignment > alignment_table[i].default_alignment_max
1753
0
#endif
1754
0
      )
1755
0
    return;
1756
1757
0
  section->alignment_power = alignment_table[i].alignment_power;
1758
0
}
pei-sh.c:coff_set_custom_section_alignment
Line
Count
Source
1729
1.52k
{
1730
1.52k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
1.52k
  unsigned int i;
1732
1733
7.63k
  for (i = 0; i < table_size; ++i)
1734
6.10k
    {
1735
6.10k
      const char *secname = bfd_section_name (section);
1736
1737
6.10k
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
6.10k
    ? strcmp (alignment_table[i].name, secname) == 0
1739
6.10k
    : strncmp (alignment_table[i].name, secname,
1740
3.05k
         alignment_table[i].comparison_length) == 0)
1741
0
  break;
1742
6.10k
    }
1743
1.52k
  if (i >= table_size)
1744
1.52k
    return;
1745
1746
0
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
0
      && default_alignment < alignment_table[i].default_alignment_min)
1748
0
    return;
1749
1750
0
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
0
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
0
      && default_alignment > alignment_table[i].default_alignment_max
1753
0
#endif
1754
0
      )
1755
0
    return;
1756
1757
0
  section->alignment_power = alignment_table[i].alignment_power;
1758
0
}
1759
1760
/* Custom section alignment records.  */
1761
1762
static const struct coff_section_alignment_entry
1763
coff_section_alignment_table[] =
1764
{
1765
#ifdef COFF_SECTION_ALIGNMENT_ENTRIES
1766
  COFF_SECTION_ALIGNMENT_ENTRIES,
1767
#endif
1768
  /* There must not be any gaps between .stabstr sections.  */
1769
  { COFF_SECTION_NAME_PARTIAL_MATCH (".stabstr"),
1770
    1, COFF_ALIGNMENT_FIELD_EMPTY, 0 },
1771
  /* The .stab section must be aligned to 2**2 at most, to avoid gaps.  */
1772
  { COFF_SECTION_NAME_PARTIAL_MATCH (".stab"),
1773
    3, COFF_ALIGNMENT_FIELD_EMPTY, 2 },
1774
  /* Similarly for the .ctors and .dtors sections.  */
1775
  { COFF_SECTION_NAME_EXACT_MATCH (".ctors"),
1776
    3, COFF_ALIGNMENT_FIELD_EMPTY, 2 },
1777
  { COFF_SECTION_NAME_EXACT_MATCH (".dtors"),
1778
    3, COFF_ALIGNMENT_FIELD_EMPTY, 2 }
1779
};
1780
1781
static const unsigned int coff_section_alignment_table_size =
1782
  sizeof coff_section_alignment_table / sizeof coff_section_alignment_table[0];
1783
1784
/* Initialize a section structure with information peculiar to this
1785
   particular implementation of COFF.  */
1786
1787
static bool
1788
coff_new_section_hook (bfd * abfd, asection * section)
1789
1.13M
{
1790
1.13M
  combined_entry_type *native;
1791
1.13M
  size_t amt;
1792
1.13M
  unsigned char sclass = C_STAT;
1793
1794
1.13M
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1795
1796
#ifdef RS6000COFF_C
1797
400k
  if (bfd_xcoff_text_align_power (abfd) != 0
1798
400k
      && strcmp (bfd_section_name (section), ".text") == 0)
1799
19
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1800
400k
  else if (bfd_xcoff_data_align_power (abfd) != 0
1801
400k
      && strcmp (bfd_section_name (section), ".data") == 0)
1802
0
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1803
400k
  else
1804
400k
    {
1805
400k
      int i;
1806
1807
4.80M
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1808
4.40M
  if (strcmp (bfd_section_name (section),
1809
4.40M
        xcoff_dwsect_names[i].xcoff_name) == 0)
1810
5
    {
1811
5
      section->alignment_power = 0;
1812
5
      sclass = C_DWARF;
1813
5
      break;
1814
5
    }
1815
400k
    }
1816
#endif
1817
1818
  /* Set up the section symbol.  */
1819
1.13M
  if (!_bfd_generic_new_section_hook (abfd, section))
1820
0
    return false;
1821
1822
  /* Allocate aux records for section symbols, to store size and
1823
     related info.
1824
1825
     @@ The 10 is a guess at a plausible maximum number of aux entries
1826
     (but shouldn't be a constant).  */
1827
1.13M
  amt = sizeof (combined_entry_type) * 10;
1828
1.13M
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
1.13M
  if (native == NULL)
1830
0
    return false;
1831
1832
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1833
     symbol information, since they'll be overridden by the BFD symbol
1834
     anyhow.  However, we do need to set the type and storage class,
1835
     in case this symbol winds up getting written out.  The value 0
1836
     for n_numaux is already correct.  */
1837
1838
1.13M
  native->is_sym = true;
1839
1.13M
  native->u.syment.n_type = T_NULL;
1840
1.13M
  native->u.syment.n_sclass = sclass;
1841
1842
1.13M
  coffsymbol (section->symbol)->native = native;
1843
1844
1.13M
  coff_set_custom_section_alignment (abfd, section,
1845
1.13M
             coff_section_alignment_table,
1846
1.13M
             coff_section_alignment_table_size);
1847
1848
1.13M
  return true;
1849
1.13M
}
pei-i386.c:coff_new_section_hook
Line
Count
Source
1789
193
{
1790
193
  combined_entry_type *native;
1791
193
  size_t amt;
1792
193
  unsigned char sclass = C_STAT;
1793
1794
193
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1795
1796
#ifdef RS6000COFF_C
1797
  if (bfd_xcoff_text_align_power (abfd) != 0
1798
      && strcmp (bfd_section_name (section), ".text") == 0)
1799
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1800
  else if (bfd_xcoff_data_align_power (abfd) != 0
1801
      && strcmp (bfd_section_name (section), ".data") == 0)
1802
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1803
  else
1804
    {
1805
      int i;
1806
1807
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1808
  if (strcmp (bfd_section_name (section),
1809
        xcoff_dwsect_names[i].xcoff_name) == 0)
1810
    {
1811
      section->alignment_power = 0;
1812
      sclass = C_DWARF;
1813
      break;
1814
    }
1815
    }
1816
#endif
1817
1818
  /* Set up the section symbol.  */
1819
193
  if (!_bfd_generic_new_section_hook (abfd, section))
1820
0
    return false;
1821
1822
  /* Allocate aux records for section symbols, to store size and
1823
     related info.
1824
1825
     @@ The 10 is a guess at a plausible maximum number of aux entries
1826
     (but shouldn't be a constant).  */
1827
193
  amt = sizeof (combined_entry_type) * 10;
1828
193
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
193
  if (native == NULL)
1830
0
    return false;
1831
1832
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1833
     symbol information, since they'll be overridden by the BFD symbol
1834
     anyhow.  However, we do need to set the type and storage class,
1835
     in case this symbol winds up getting written out.  The value 0
1836
     for n_numaux is already correct.  */
1837
1838
193
  native->is_sym = true;
1839
193
  native->u.syment.n_type = T_NULL;
1840
193
  native->u.syment.n_sclass = sclass;
1841
1842
193
  coffsymbol (section->symbol)->native = native;
1843
1844
193
  coff_set_custom_section_alignment (abfd, section,
1845
193
             coff_section_alignment_table,
1846
193
             coff_section_alignment_table_size);
1847
1848
193
  return true;
1849
193
}
pe-x86_64.c:coff_new_section_hook
Line
Count
Source
1789
538
{
1790
538
  combined_entry_type *native;
1791
538
  size_t amt;
1792
538
  unsigned char sclass = C_STAT;
1793
1794
538
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1795
1796
#ifdef RS6000COFF_C
1797
  if (bfd_xcoff_text_align_power (abfd) != 0
1798
      && strcmp (bfd_section_name (section), ".text") == 0)
1799
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1800
  else if (bfd_xcoff_data_align_power (abfd) != 0
1801
      && strcmp (bfd_section_name (section), ".data") == 0)
1802
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1803
  else
1804
    {
1805
      int i;
1806
1807
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1808
  if (strcmp (bfd_section_name (section),
1809
        xcoff_dwsect_names[i].xcoff_name) == 0)
1810
    {
1811
      section->alignment_power = 0;
1812
      sclass = C_DWARF;
1813
      break;
1814
    }
1815
    }
1816
#endif
1817
1818
  /* Set up the section symbol.  */
1819
538
  if (!_bfd_generic_new_section_hook (abfd, section))
1820
0
    return false;
1821
1822
  /* Allocate aux records for section symbols, to store size and
1823
     related info.
1824
1825
     @@ The 10 is a guess at a plausible maximum number of aux entries
1826
     (but shouldn't be a constant).  */
1827
538
  amt = sizeof (combined_entry_type) * 10;
1828
538
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
538
  if (native == NULL)
1830
0
    return false;
1831
1832
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1833
     symbol information, since they'll be overridden by the BFD symbol
1834
     anyhow.  However, we do need to set the type and storage class,
1835
     in case this symbol winds up getting written out.  The value 0
1836
     for n_numaux is already correct.  */
1837
1838
538
  native->is_sym = true;
1839
538
  native->u.syment.n_type = T_NULL;
1840
538
  native->u.syment.n_sclass = sclass;
1841
1842
538
  coffsymbol (section->symbol)->native = native;
1843
1844
538
  coff_set_custom_section_alignment (abfd, section,
1845
538
             coff_section_alignment_table,
1846
538
             coff_section_alignment_table_size);
1847
1848
538
  return true;
1849
538
}
pei-x86_64.c:coff_new_section_hook
Line
Count
Source
1789
849
{
1790
849
  combined_entry_type *native;
1791
849
  size_t amt;
1792
849
  unsigned char sclass = C_STAT;
1793
1794
849
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1795
1796
#ifdef RS6000COFF_C
1797
  if (bfd_xcoff_text_align_power (abfd) != 0
1798
      && strcmp (bfd_section_name (section), ".text") == 0)
1799
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1800
  else if (bfd_xcoff_data_align_power (abfd) != 0
1801
      && strcmp (bfd_section_name (section), ".data") == 0)
1802
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1803
  else
1804
    {
1805
      int i;
1806
1807
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1808
  if (strcmp (bfd_section_name (section),
1809
        xcoff_dwsect_names[i].xcoff_name) == 0)
1810
    {
1811
      section->alignment_power = 0;
1812
      sclass = C_DWARF;
1813
      break;
1814
    }
1815
    }
1816
#endif
1817
1818
  /* Set up the section symbol.  */
1819
849
  if (!_bfd_generic_new_section_hook (abfd, section))
1820
0
    return false;
1821
1822
  /* Allocate aux records for section symbols, to store size and
1823
     related info.
1824
1825
     @@ The 10 is a guess at a plausible maximum number of aux entries
1826
     (but shouldn't be a constant).  */
1827
849
  amt = sizeof (combined_entry_type) * 10;
1828
849
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
849
  if (native == NULL)
1830
0
    return false;
1831
1832
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1833
     symbol information, since they'll be overridden by the BFD symbol
1834
     anyhow.  However, we do need to set the type and storage class,
1835
     in case this symbol winds up getting written out.  The value 0
1836
     for n_numaux is already correct.  */
1837
1838
849
  native->is_sym = true;
1839
849
  native->u.syment.n_type = T_NULL;
1840
849
  native->u.syment.n_sclass = sclass;
1841
1842
849
  coffsymbol (section->symbol)->native = native;
1843
1844
849
  coff_set_custom_section_alignment (abfd, section,
1845
849
             coff_section_alignment_table,
1846
849
             coff_section_alignment_table_size);
1847
1848
849
  return true;
1849
849
}
coff-x86_64.c:coff_new_section_hook
Line
Count
Source
1789
20.3k
{
1790
20.3k
  combined_entry_type *native;
1791
20.3k
  size_t amt;
1792
20.3k
  unsigned char sclass = C_STAT;
1793
1794
20.3k
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1795
1796
#ifdef RS6000COFF_C
1797
  if (bfd_xcoff_text_align_power (abfd) != 0
1798
      && strcmp (bfd_section_name (section), ".text") == 0)
1799
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1800
  else if (bfd_xcoff_data_align_power (abfd) != 0
1801
      && strcmp (bfd_section_name (section), ".data") == 0)
1802
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1803
  else
1804
    {
1805
      int i;
1806
1807
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1808
  if (strcmp (bfd_section_name (section),
1809
        xcoff_dwsect_names[i].xcoff_name) == 0)
1810
    {
1811
      section->alignment_power = 0;
1812
      sclass = C_DWARF;
1813
      break;
1814
    }
1815
    }
1816
#endif
1817
1818
  /* Set up the section symbol.  */
1819
20.3k
  if (!_bfd_generic_new_section_hook (abfd, section))
1820
0
    return false;
1821
1822
  /* Allocate aux records for section symbols, to store size and
1823
     related info.
1824
1825
     @@ The 10 is a guess at a plausible maximum number of aux entries
1826
     (but shouldn't be a constant).  */
1827
20.3k
  amt = sizeof (combined_entry_type) * 10;
1828
20.3k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
20.3k
  if (native == NULL)
1830
0
    return false;
1831
1832
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1833
     symbol information, since they'll be overridden by the BFD symbol
1834
     anyhow.  However, we do need to set the type and storage class,
1835
     in case this symbol winds up getting written out.  The value 0
1836
     for n_numaux is already correct.  */
1837
1838
20.3k
  native->is_sym = true;
1839
20.3k
  native->u.syment.n_type = T_NULL;
1840
20.3k
  native->u.syment.n_sclass = sclass;
1841
1842
20.3k
  coffsymbol (section->symbol)->native = native;
1843
1844
20.3k
  coff_set_custom_section_alignment (abfd, section,
1845
20.3k
             coff_section_alignment_table,
1846
20.3k
             coff_section_alignment_table_size);
1847
1848
20.3k
  return true;
1849
20.3k
}
coff64-rs6000.c:coff_new_section_hook
Line
Count
Source
1789
180k
{
1790
180k
  combined_entry_type *native;
1791
180k
  size_t amt;
1792
180k
  unsigned char sclass = C_STAT;
1793
1794
180k
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1795
1796
180k
#ifdef RS6000COFF_C
1797
180k
  if (bfd_xcoff_text_align_power (abfd) != 0
1798
180k
      && strcmp (bfd_section_name (section), ".text") == 0)
1799
0
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1800
180k
  else if (bfd_xcoff_data_align_power (abfd) != 0
1801
180k
      && strcmp (bfd_section_name (section), ".data") == 0)
1802
0
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1803
180k
  else
1804
180k
    {
1805
180k
      int i;
1806
1807
2.16M
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1808
1.98M
  if (strcmp (bfd_section_name (section),
1809
1.98M
        xcoff_dwsect_names[i].xcoff_name) == 0)
1810
5
    {
1811
5
      section->alignment_power = 0;
1812
5
      sclass = C_DWARF;
1813
5
      break;
1814
5
    }
1815
180k
    }
1816
180k
#endif
1817
1818
  /* Set up the section symbol.  */
1819
180k
  if (!_bfd_generic_new_section_hook (abfd, section))
1820
0
    return false;
1821
1822
  /* Allocate aux records for section symbols, to store size and
1823
     related info.
1824
1825
     @@ The 10 is a guess at a plausible maximum number of aux entries
1826
     (but shouldn't be a constant).  */
1827
180k
  amt = sizeof (combined_entry_type) * 10;
1828
180k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
180k
  if (native == NULL)
1830
0
    return false;
1831
1832
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1833
     symbol information, since they'll be overridden by the BFD symbol
1834
     anyhow.  However, we do need to set the type and storage class,
1835
     in case this symbol winds up getting written out.  The value 0
1836
     for n_numaux is already correct.  */
1837
1838
180k
  native->is_sym = true;
1839
180k
  native->u.syment.n_type = T_NULL;
1840
180k
  native->u.syment.n_sclass = sclass;
1841
1842
180k
  coffsymbol (section->symbol)->native = native;
1843
1844
180k
  coff_set_custom_section_alignment (abfd, section,
1845
180k
             coff_section_alignment_table,
1846
180k
             coff_section_alignment_table_size);
1847
1848
180k
  return true;
1849
180k
}
pe-aarch64.c:coff_new_section_hook
Line
Count
Source
1789
186
{
1790
186
  combined_entry_type *native;
1791
186
  size_t amt;
1792
186
  unsigned char sclass = C_STAT;
1793
1794
186
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1795
1796
#ifdef RS6000COFF_C
1797
  if (bfd_xcoff_text_align_power (abfd) != 0
1798
      && strcmp (bfd_section_name (section), ".text") == 0)
1799
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1800
  else if (bfd_xcoff_data_align_power (abfd) != 0
1801
      && strcmp (bfd_section_name (section), ".data") == 0)
1802
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1803
  else
1804
    {
1805
      int i;
1806
1807
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1808
  if (strcmp (bfd_section_name (section),
1809
        xcoff_dwsect_names[i].xcoff_name) == 0)
1810
    {
1811
      section->alignment_power = 0;
1812
      sclass = C_DWARF;
1813
      break;
1814
    }
1815
    }
1816
#endif
1817
1818
  /* Set up the section symbol.  */
1819
186
  if (!_bfd_generic_new_section_hook (abfd, section))
1820
0
    return false;
1821
1822
  /* Allocate aux records for section symbols, to store size and
1823
     related info.
1824
1825
     @@ The 10 is a guess at a plausible maximum number of aux entries
1826
     (but shouldn't be a constant).  */
1827
186
  amt = sizeof (combined_entry_type) * 10;
1828
186
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
186
  if (native == NULL)
1830
0
    return false;
1831
1832
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1833
     symbol information, since they'll be overridden by the BFD symbol
1834
     anyhow.  However, we do need to set the type and storage class,
1835
     in case this symbol winds up getting written out.  The value 0
1836
     for n_numaux is already correct.  */
1837
1838
186
  native->is_sym = true;
1839
186
  native->u.syment.n_type = T_NULL;
1840
186
  native->u.syment.n_sclass = sclass;
1841
1842
186
  coffsymbol (section->symbol)->native = native;
1843
1844
186
  coff_set_custom_section_alignment (abfd, section,
1845
186
             coff_section_alignment_table,
1846
186
             coff_section_alignment_table_size);
1847
1848
186
  return true;
1849
186
}
pei-aarch64.c:coff_new_section_hook
Line
Count
Source
1789
5.47k
{
1790
5.47k
  combined_entry_type *native;
1791
5.47k
  size_t amt;
1792
5.47k
  unsigned char sclass = C_STAT;
1793
1794
5.47k
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1795
1796
#ifdef RS6000COFF_C
1797
  if (bfd_xcoff_text_align_power (abfd) != 0
1798
      && strcmp (bfd_section_name (section), ".text") == 0)
1799
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1800
  else if (bfd_xcoff_data_align_power (abfd) != 0
1801
      && strcmp (bfd_section_name (section), ".data") == 0)
1802
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1803
  else
1804
    {
1805
      int i;
1806
1807
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1808
  if (strcmp (bfd_section_name (section),
1809
        xcoff_dwsect_names[i].xcoff_name) == 0)
1810
    {
1811
      section->alignment_power = 0;
1812
      sclass = C_DWARF;
1813
      break;
1814
    }
1815
    }
1816
#endif
1817
1818
  /* Set up the section symbol.  */
1819
5.47k
  if (!_bfd_generic_new_section_hook (abfd, section))
1820
0
    return false;
1821
1822
  /* Allocate aux records for section symbols, to store size and
1823
     related info.
1824
1825
     @@ The 10 is a guess at a plausible maximum number of aux entries
1826
     (but shouldn't be a constant).  */
1827
5.47k
  amt = sizeof (combined_entry_type) * 10;
1828
5.47k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
5.47k
  if (native == NULL)
1830
0
    return false;
1831
1832
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1833
     symbol information, since they'll be overridden by the BFD symbol
1834
     anyhow.  However, we do need to set the type and storage class,
1835
     in case this symbol winds up getting written out.  The value 0
1836
     for n_numaux is already correct.  */
1837
1838
5.47k
  native->is_sym = true;
1839
5.47k
  native->u.syment.n_type = T_NULL;
1840
5.47k
  native->u.syment.n_sclass = sclass;
1841
1842
5.47k
  coffsymbol (section->symbol)->native = native;
1843
1844
5.47k
  coff_set_custom_section_alignment (abfd, section,
1845
5.47k
             coff_section_alignment_table,
1846
5.47k
             coff_section_alignment_table_size);
1847
1848
5.47k
  return true;
1849
5.47k
}
pei-ia64.c:coff_new_section_hook
Line
Count
Source
1789
162
{
1790
162
  combined_entry_type *native;
1791
162
  size_t amt;
1792
162
  unsigned char sclass = C_STAT;
1793
1794
162
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1795
1796
#ifdef RS6000COFF_C
1797
  if (bfd_xcoff_text_align_power (abfd) != 0
1798
      && strcmp (bfd_section_name (section), ".text") == 0)
1799
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1800
  else if (bfd_xcoff_data_align_power (abfd) != 0
1801
      && strcmp (bfd_section_name (section), ".data") == 0)
1802
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1803
  else
1804
    {
1805
      int i;
1806
1807
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1808
  if (strcmp (bfd_section_name (section),
1809
        xcoff_dwsect_names[i].xcoff_name) == 0)
1810
    {
1811
      section->alignment_power = 0;
1812
      sclass = C_DWARF;
1813
      break;
1814
    }
1815
    }
1816
#endif
1817
1818
  /* Set up the section symbol.  */
1819
162
  if (!_bfd_generic_new_section_hook (abfd, section))
1820
0
    return false;
1821
1822
  /* Allocate aux records for section symbols, to store size and
1823
     related info.
1824
1825
     @@ The 10 is a guess at a plausible maximum number of aux entries
1826
     (but shouldn't be a constant).  */
1827
162
  amt = sizeof (combined_entry_type) * 10;
1828
162
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
162
  if (native == NULL)
1830
0
    return false;
1831
1832
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1833
     symbol information, since they'll be overridden by the BFD symbol
1834
     anyhow.  However, we do need to set the type and storage class,
1835
     in case this symbol winds up getting written out.  The value 0
1836
     for n_numaux is already correct.  */
1837
1838
162
  native->is_sym = true;
1839
162
  native->u.syment.n_type = T_NULL;
1840
162
  native->u.syment.n_sclass = sclass;
1841
1842
162
  coffsymbol (section->symbol)->native = native;
1843
1844
162
  coff_set_custom_section_alignment (abfd, section,
1845
162
             coff_section_alignment_table,
1846
162
             coff_section_alignment_table_size);
1847
1848
162
  return true;
1849
162
}
pei-loongarch64.c:coff_new_section_hook
Line
Count
Source
1789
415
{
1790
415
  combined_entry_type *native;
1791
415
  size_t amt;
1792
415
  unsigned char sclass = C_STAT;
1793
1794
415
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1795
1796
#ifdef RS6000COFF_C
1797
  if (bfd_xcoff_text_align_power (abfd) != 0
1798
      && strcmp (bfd_section_name (section), ".text") == 0)
1799
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1800
  else if (bfd_xcoff_data_align_power (abfd) != 0
1801
      && strcmp (bfd_section_name (section), ".data") == 0)
1802
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1803
  else
1804
    {
1805
      int i;
1806
1807
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1808
  if (strcmp (bfd_section_name (section),
1809
        xcoff_dwsect_names[i].xcoff_name) == 0)
1810
    {
1811
      section->alignment_power = 0;
1812
      sclass = C_DWARF;
1813
      break;
1814
    }
1815
    }
1816
#endif
1817
1818
  /* Set up the section symbol.  */
1819
415
  if (!_bfd_generic_new_section_hook (abfd, section))
1820
0
    return false;
1821
1822
  /* Allocate aux records for section symbols, to store size and
1823
     related info.
1824
1825
     @@ The 10 is a guess at a plausible maximum number of aux entries
1826
     (but shouldn't be a constant).  */
1827
415
  amt = sizeof (combined_entry_type) * 10;
1828
415
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
415
  if (native == NULL)
1830
0
    return false;
1831
1832
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1833
     symbol information, since they'll be overridden by the BFD symbol
1834
     anyhow.  However, we do need to set the type and storage class,
1835
     in case this symbol winds up getting written out.  The value 0
1836
     for n_numaux is already correct.  */
1837
1838
415
  native->is_sym = true;
1839
415
  native->u.syment.n_type = T_NULL;
1840
415
  native->u.syment.n_sclass = sclass;
1841
1842
415
  coffsymbol (section->symbol)->native = native;
1843
1844
415
  coff_set_custom_section_alignment (abfd, section,
1845
415
             coff_section_alignment_table,
1846
415
             coff_section_alignment_table_size);
1847
1848
415
  return true;
1849
415
}
cf-i386lynx.c:coff_new_section_hook
Line
Count
Source
1789
82.1k
{
1790
82.1k
  combined_entry_type *native;
1791
82.1k
  size_t amt;
1792
82.1k
  unsigned char sclass = C_STAT;
1793
1794
82.1k
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1795
1796
#ifdef RS6000COFF_C
1797
  if (bfd_xcoff_text_align_power (abfd) != 0
1798
      && strcmp (bfd_section_name (section), ".text") == 0)
1799
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1800
  else if (bfd_xcoff_data_align_power (abfd) != 0
1801
      && strcmp (bfd_section_name (section), ".data") == 0)
1802
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1803
  else
1804
    {
1805
      int i;
1806
1807
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1808
  if (strcmp (bfd_section_name (section),
1809
        xcoff_dwsect_names[i].xcoff_name) == 0)
1810
    {
1811
      section->alignment_power = 0;
1812
      sclass = C_DWARF;
1813
      break;
1814
    }
1815
    }
1816
#endif
1817
1818
  /* Set up the section symbol.  */
1819
82.1k
  if (!_bfd_generic_new_section_hook (abfd, section))
1820
0
    return false;
1821
1822
  /* Allocate aux records for section symbols, to store size and
1823
     related info.
1824
1825
     @@ The 10 is a guess at a plausible maximum number of aux entries
1826
     (but shouldn't be a constant).  */
1827
82.1k
  amt = sizeof (combined_entry_type) * 10;
1828
82.1k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
82.1k
  if (native == NULL)
1830
0
    return false;
1831
1832
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1833
     symbol information, since they'll be overridden by the BFD symbol
1834
     anyhow.  However, we do need to set the type and storage class,
1835
     in case this symbol winds up getting written out.  The value 0
1836
     for n_numaux is already correct.  */
1837
1838
82.1k
  native->is_sym = true;
1839
82.1k
  native->u.syment.n_type = T_NULL;
1840
82.1k
  native->u.syment.n_sclass = sclass;
1841
1842
82.1k
  coffsymbol (section->symbol)->native = native;
1843
1844
82.1k
  coff_set_custom_section_alignment (abfd, section,
1845
82.1k
             coff_section_alignment_table,
1846
82.1k
             coff_section_alignment_table_size);
1847
1848
82.1k
  return true;
1849
82.1k
}
coff-go32.c:coff_new_section_hook
Line
Count
Source
1789
7.68k
{
1790
7.68k
  combined_entry_type *native;
1791
7.68k
  size_t amt;
1792
7.68k
  unsigned char sclass = C_STAT;
1793
1794
7.68k
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1795
1796
#ifdef RS6000COFF_C
1797
  if (bfd_xcoff_text_align_power (abfd) != 0
1798
      && strcmp (bfd_section_name (section), ".text") == 0)
1799
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1800
  else if (bfd_xcoff_data_align_power (abfd) != 0
1801
      && strcmp (bfd_section_name (section), ".data") == 0)
1802
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1803
  else
1804
    {
1805
      int i;
1806
1807
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1808
  if (strcmp (bfd_section_name (section),
1809
        xcoff_dwsect_names[i].xcoff_name) == 0)
1810
    {
1811
      section->alignment_power = 0;
1812
      sclass = C_DWARF;
1813
      break;
1814
    }
1815
    }
1816
#endif
1817
1818
  /* Set up the section symbol.  */
1819
7.68k
  if (!_bfd_generic_new_section_hook (abfd, section))
1820
0
    return false;
1821
1822
  /* Allocate aux records for section symbols, to store size and
1823
     related info.
1824
1825
     @@ The 10 is a guess at a plausible maximum number of aux entries
1826
     (but shouldn't be a constant).  */
1827
7.68k
  amt = sizeof (combined_entry_type) * 10;
1828
7.68k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
7.68k
  if (native == NULL)
1830
0
    return false;
1831
1832
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1833
     symbol information, since they'll be overridden by the BFD symbol
1834
     anyhow.  However, we do need to set the type and storage class,
1835
     in case this symbol winds up getting written out.  The value 0
1836
     for n_numaux is already correct.  */
1837
1838
7.68k
  native->is_sym = true;
1839
7.68k
  native->u.syment.n_type = T_NULL;
1840
7.68k
  native->u.syment.n_sclass = sclass;
1841
1842
7.68k
  coffsymbol (section->symbol)->native = native;
1843
1844
7.68k
  coff_set_custom_section_alignment (abfd, section,
1845
7.68k
             coff_section_alignment_table,
1846
7.68k
             coff_section_alignment_table_size);
1847
1848
7.68k
  return true;
1849
7.68k
}
coff-i386.c:coff_new_section_hook
Line
Count
Source
1789
7.92k
{
1790
7.92k
  combined_entry_type *native;
1791
7.92k
  size_t amt;
1792
7.92k
  unsigned char sclass = C_STAT;
1793
1794
7.92k
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1795
1796
#ifdef RS6000COFF_C
1797
  if (bfd_xcoff_text_align_power (abfd) != 0
1798
      && strcmp (bfd_section_name (section), ".text") == 0)
1799
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1800
  else if (bfd_xcoff_data_align_power (abfd) != 0
1801
      && strcmp (bfd_section_name (section), ".data") == 0)
1802
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1803
  else
1804
    {
1805
      int i;
1806
1807
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1808
  if (strcmp (bfd_section_name (section),
1809
        xcoff_dwsect_names[i].xcoff_name) == 0)
1810
    {
1811
      section->alignment_power = 0;
1812
      sclass = C_DWARF;
1813
      break;
1814
    }
1815
    }
1816
#endif
1817
1818
  /* Set up the section symbol.  */
1819
7.92k
  if (!_bfd_generic_new_section_hook (abfd, section))
1820
0
    return false;
1821
1822
  /* Allocate aux records for section symbols, to store size and
1823
     related info.
1824
1825
     @@ The 10 is a guess at a plausible maximum number of aux entries
1826
     (but shouldn't be a constant).  */
1827
7.92k
  amt = sizeof (combined_entry_type) * 10;
1828
7.92k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
7.92k
  if (native == NULL)
1830
0
    return false;
1831
1832
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1833
     symbol information, since they'll be overridden by the BFD symbol
1834
     anyhow.  However, we do need to set the type and storage class,
1835
     in case this symbol winds up getting written out.  The value 0
1836
     for n_numaux is already correct.  */
1837
1838
7.92k
  native->is_sym = true;
1839
7.92k
  native->u.syment.n_type = T_NULL;
1840
7.92k
  native->u.syment.n_sclass = sclass;
1841
1842
7.92k
  coffsymbol (section->symbol)->native = native;
1843
1844
7.92k
  coff_set_custom_section_alignment (abfd, section,
1845
7.92k
             coff_section_alignment_table,
1846
7.92k
             coff_section_alignment_table_size);
1847
1848
7.92k
  return true;
1849
7.92k
}
coff-rs6000.c:coff_new_section_hook
Line
Count
Source
1789
220k
{
1790
220k
  combined_entry_type *native;
1791
220k
  size_t amt;
1792
220k
  unsigned char sclass = C_STAT;
1793
1794
220k
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1795
1796
220k
#ifdef RS6000COFF_C
1797
220k
  if (bfd_xcoff_text_align_power (abfd) != 0
1798
220k
      && strcmp (bfd_section_name (section), ".text") == 0)
1799
19
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1800
220k
  else if (bfd_xcoff_data_align_power (abfd) != 0
1801
220k
      && strcmp (bfd_section_name (section), ".data") == 0)
1802
0
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1803
220k
  else
1804
220k
    {
1805
220k
      int i;
1806
1807
2.64M
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1808
2.42M
  if (strcmp (bfd_section_name (section),
1809
2.42M
        xcoff_dwsect_names[i].xcoff_name) == 0)
1810
0
    {
1811
0
      section->alignment_power = 0;
1812
0
      sclass = C_DWARF;
1813
0
      break;
1814
0
    }
1815
220k
    }
1816
220k
#endif
1817
1818
  /* Set up the section symbol.  */
1819
220k
  if (!_bfd_generic_new_section_hook (abfd, section))
1820
0
    return false;
1821
1822
  /* Allocate aux records for section symbols, to store size and
1823
     related info.
1824
1825
     @@ The 10 is a guess at a plausible maximum number of aux entries
1826
     (but shouldn't be a constant).  */
1827
220k
  amt = sizeof (combined_entry_type) * 10;
1828
220k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
220k
  if (native == NULL)
1830
0
    return false;
1831
1832
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1833
     symbol information, since they'll be overridden by the BFD symbol
1834
     anyhow.  However, we do need to set the type and storage class,
1835
     in case this symbol winds up getting written out.  The value 0
1836
     for n_numaux is already correct.  */
1837
1838
220k
  native->is_sym = true;
1839
220k
  native->u.syment.n_type = T_NULL;
1840
220k
  native->u.syment.n_sclass = sclass;
1841
1842
220k
  coffsymbol (section->symbol)->native = native;
1843
1844
220k
  coff_set_custom_section_alignment (abfd, section,
1845
220k
             coff_section_alignment_table,
1846
220k
             coff_section_alignment_table_size);
1847
1848
220k
  return true;
1849
220k
}
coff-sh.c:coff_new_section_hook
Line
Count
Source
1789
360k
{
1790
360k
  combined_entry_type *native;
1791
360k
  size_t amt;
1792
360k
  unsigned char sclass = C_STAT;
1793
1794
360k
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1795
1796
#ifdef RS6000COFF_C
1797
  if (bfd_xcoff_text_align_power (abfd) != 0
1798
      && strcmp (bfd_section_name (section), ".text") == 0)
1799
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1800
  else if (bfd_xcoff_data_align_power (abfd) != 0
1801
      && strcmp (bfd_section_name (section), ".data") == 0)
1802
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1803
  else
1804
    {
1805
      int i;
1806
1807
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1808
  if (strcmp (bfd_section_name (section),
1809
        xcoff_dwsect_names[i].xcoff_name) == 0)
1810
    {
1811
      section->alignment_power = 0;
1812
      sclass = C_DWARF;
1813
      break;
1814
    }
1815
    }
1816
#endif
1817
1818
  /* Set up the section symbol.  */
1819
360k
  if (!_bfd_generic_new_section_hook (abfd, section))
1820
0
    return false;
1821
1822
  /* Allocate aux records for section symbols, to store size and
1823
     related info.
1824
1825
     @@ The 10 is a guess at a plausible maximum number of aux entries
1826
     (but shouldn't be a constant).  */
1827
360k
  amt = sizeof (combined_entry_type) * 10;
1828
360k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
360k
  if (native == NULL)
1830
0
    return false;
1831
1832
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1833
     symbol information, since they'll be overridden by the BFD symbol
1834
     anyhow.  However, we do need to set the type and storage class,
1835
     in case this symbol winds up getting written out.  The value 0
1836
     for n_numaux is already correct.  */
1837
1838
360k
  native->is_sym = true;
1839
360k
  native->u.syment.n_type = T_NULL;
1840
360k
  native->u.syment.n_sclass = sclass;
1841
1842
360k
  coffsymbol (section->symbol)->native = native;
1843
1844
360k
  coff_set_custom_section_alignment (abfd, section,
1845
360k
             coff_section_alignment_table,
1846
360k
             coff_section_alignment_table_size);
1847
1848
360k
  return true;
1849
360k
}
coff-stgo32.c:coff_new_section_hook
Line
Count
Source
1789
92.9k
{
1790
92.9k
  combined_entry_type *native;
1791
92.9k
  size_t amt;
1792
92.9k
  unsigned char sclass = C_STAT;
1793
1794
92.9k
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1795
1796
#ifdef RS6000COFF_C
1797
  if (bfd_xcoff_text_align_power (abfd) != 0
1798
      && strcmp (bfd_section_name (section), ".text") == 0)
1799
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1800
  else if (bfd_xcoff_data_align_power (abfd) != 0
1801
      && strcmp (bfd_section_name (section), ".data") == 0)
1802
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1803
  else
1804
    {
1805
      int i;
1806
1807
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1808
  if (strcmp (bfd_section_name (section),
1809
        xcoff_dwsect_names[i].xcoff_name) == 0)
1810
    {
1811
      section->alignment_power = 0;
1812
      sclass = C_DWARF;
1813
      break;
1814
    }
1815
    }
1816
#endif
1817
1818
  /* Set up the section symbol.  */
1819
92.9k
  if (!_bfd_generic_new_section_hook (abfd, section))
1820
0
    return false;
1821
1822
  /* Allocate aux records for section symbols, to store size and
1823
     related info.
1824
1825
     @@ The 10 is a guess at a plausible maximum number of aux entries
1826
     (but shouldn't be a constant).  */
1827
92.9k
  amt = sizeof (combined_entry_type) * 10;
1828
92.9k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
92.9k
  if (native == NULL)
1830
0
    return false;
1831
1832
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1833
     symbol information, since they'll be overridden by the BFD symbol
1834
     anyhow.  However, we do need to set the type and storage class,
1835
     in case this symbol winds up getting written out.  The value 0
1836
     for n_numaux is already correct.  */
1837
1838
92.9k
  native->is_sym = true;
1839
92.9k
  native->u.syment.n_type = T_NULL;
1840
92.9k
  native->u.syment.n_sclass = sclass;
1841
1842
92.9k
  coffsymbol (section->symbol)->native = native;
1843
1844
92.9k
  coff_set_custom_section_alignment (abfd, section,
1845
92.9k
             coff_section_alignment_table,
1846
92.9k
             coff_section_alignment_table_size);
1847
1848
92.9k
  return true;
1849
92.9k
}
coff-tic30.c:coff_new_section_hook
Line
Count
Source
1789
10.6k
{
1790
10.6k
  combined_entry_type *native;
1791
10.6k
  size_t amt;
1792
10.6k
  unsigned char sclass = C_STAT;
1793
1794
10.6k
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1795
1796
#ifdef RS6000COFF_C
1797
  if (bfd_xcoff_text_align_power (abfd) != 0
1798
      && strcmp (bfd_section_name (section), ".text") == 0)
1799
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1800
  else if (bfd_xcoff_data_align_power (abfd) != 0
1801
      && strcmp (bfd_section_name (section), ".data") == 0)
1802
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1803
  else
1804
    {
1805
      int i;
1806
1807
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1808
  if (strcmp (bfd_section_name (section),
1809
        xcoff_dwsect_names[i].xcoff_name) == 0)
1810
    {
1811
      section->alignment_power = 0;
1812
      sclass = C_DWARF;
1813
      break;
1814
    }
1815
    }
1816
#endif
1817
1818
  /* Set up the section symbol.  */
1819
10.6k
  if (!_bfd_generic_new_section_hook (abfd, section))
1820
0
    return false;
1821
1822
  /* Allocate aux records for section symbols, to store size and
1823
     related info.
1824
1825
     @@ The 10 is a guess at a plausible maximum number of aux entries
1826
     (but shouldn't be a constant).  */
1827
10.6k
  amt = sizeof (combined_entry_type) * 10;
1828
10.6k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
10.6k
  if (native == NULL)
1830
0
    return false;
1831
1832
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1833
     symbol information, since they'll be overridden by the BFD symbol
1834
     anyhow.  However, we do need to set the type and storage class,
1835
     in case this symbol winds up getting written out.  The value 0
1836
     for n_numaux is already correct.  */
1837
1838
10.6k
  native->is_sym = true;
1839
10.6k
  native->u.syment.n_type = T_NULL;
1840
10.6k
  native->u.syment.n_sclass = sclass;
1841
1842
10.6k
  coffsymbol (section->symbol)->native = native;
1843
1844
10.6k
  coff_set_custom_section_alignment (abfd, section,
1845
10.6k
             coff_section_alignment_table,
1846
10.6k
             coff_section_alignment_table_size);
1847
1848
10.6k
  return true;
1849
10.6k
}
Unexecuted instantiation: coff-tic4x.c:coff_new_section_hook
coff-tic54x.c:coff_new_section_hook
Line
Count
Source
1789
22.8k
{
1790
22.8k
  combined_entry_type *native;
1791
22.8k
  size_t amt;
1792
22.8k
  unsigned char sclass = C_STAT;
1793
1794
22.8k
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1795
1796
#ifdef RS6000COFF_C
1797
  if (bfd_xcoff_text_align_power (abfd) != 0
1798
      && strcmp (bfd_section_name (section), ".text") == 0)
1799
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1800
  else if (bfd_xcoff_data_align_power (abfd) != 0
1801
      && strcmp (bfd_section_name (section), ".data") == 0)
1802
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1803
  else
1804
    {
1805
      int i;
1806
1807
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1808
  if (strcmp (bfd_section_name (section),
1809
        xcoff_dwsect_names[i].xcoff_name) == 0)
1810
    {
1811
      section->alignment_power = 0;
1812
      sclass = C_DWARF;
1813
      break;
1814
    }
1815
    }
1816
#endif
1817
1818
  /* Set up the section symbol.  */
1819
22.8k
  if (!_bfd_generic_new_section_hook (abfd, section))
1820
0
    return false;
1821
1822
  /* Allocate aux records for section symbols, to store size and
1823
     related info.
1824
1825
     @@ The 10 is a guess at a plausible maximum number of aux entries
1826
     (but shouldn't be a constant).  */
1827
22.8k
  amt = sizeof (combined_entry_type) * 10;
1828
22.8k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
22.8k
  if (native == NULL)
1830
0
    return false;
1831
1832
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1833
     symbol information, since they'll be overridden by the BFD symbol
1834
     anyhow.  However, we do need to set the type and storage class,
1835
     in case this symbol winds up getting written out.  The value 0
1836
     for n_numaux is already correct.  */
1837
1838
22.8k
  native->is_sym = true;
1839
22.8k
  native->u.syment.n_type = T_NULL;
1840
22.8k
  native->u.syment.n_sclass = sclass;
1841
1842
22.8k
  coffsymbol (section->symbol)->native = native;
1843
1844
22.8k
  coff_set_custom_section_alignment (abfd, section,
1845
22.8k
             coff_section_alignment_table,
1846
22.8k
             coff_section_alignment_table_size);
1847
1848
22.8k
  return true;
1849
22.8k
}
coff-z80.c:coff_new_section_hook
Line
Count
Source
1789
9.17k
{
1790
9.17k
  combined_entry_type *native;
1791
9.17k
  size_t amt;
1792
9.17k
  unsigned char sclass = C_STAT;
1793
1794
9.17k
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1795
1796
#ifdef RS6000COFF_C
1797
  if (bfd_xcoff_text_align_power (abfd) != 0
1798
      && strcmp (bfd_section_name (section), ".text") == 0)
1799
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1800
  else if (bfd_xcoff_data_align_power (abfd) != 0
1801
      && strcmp (bfd_section_name (section), ".data") == 0)
1802
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1803
  else
1804
    {
1805
      int i;
1806
1807
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1808
  if (strcmp (bfd_section_name (section),
1809
        xcoff_dwsect_names[i].xcoff_name) == 0)
1810
    {
1811
      section->alignment_power = 0;
1812
      sclass = C_DWARF;
1813
      break;
1814
    }
1815
    }
1816
#endif
1817
1818
  /* Set up the section symbol.  */
1819
9.17k
  if (!_bfd_generic_new_section_hook (abfd, section))
1820
0
    return false;
1821
1822
  /* Allocate aux records for section symbols, to store size and
1823
     related info.
1824
1825
     @@ The 10 is a guess at a plausible maximum number of aux entries
1826
     (but shouldn't be a constant).  */
1827
9.17k
  amt = sizeof (combined_entry_type) * 10;
1828
9.17k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
9.17k
  if (native == NULL)
1830
0
    return false;
1831
1832
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1833
     symbol information, since they'll be overridden by the BFD symbol
1834
     anyhow.  However, we do need to set the type and storage class,
1835
     in case this symbol winds up getting written out.  The value 0
1836
     for n_numaux is already correct.  */
1837
1838
9.17k
  native->is_sym = true;
1839
9.17k
  native->u.syment.n_type = T_NULL;
1840
9.17k
  native->u.syment.n_sclass = sclass;
1841
1842
9.17k
  coffsymbol (section->symbol)->native = native;
1843
1844
9.17k
  coff_set_custom_section_alignment (abfd, section,
1845
9.17k
             coff_section_alignment_table,
1846
9.17k
             coff_section_alignment_table_size);
1847
1848
9.17k
  return true;
1849
9.17k
}
coff-z8k.c:coff_new_section_hook
Line
Count
Source
1789
99.5k
{
1790
99.5k
  combined_entry_type *native;
1791
99.5k
  size_t amt;
1792
99.5k
  unsigned char sclass = C_STAT;
1793
1794
99.5k
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1795
1796
#ifdef RS6000COFF_C
1797
  if (bfd_xcoff_text_align_power (abfd) != 0
1798
      && strcmp (bfd_section_name (section), ".text") == 0)
1799
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1800
  else if (bfd_xcoff_data_align_power (abfd) != 0
1801
      && strcmp (bfd_section_name (section), ".data") == 0)
1802
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1803
  else
1804
    {
1805
      int i;
1806
1807
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1808
  if (strcmp (bfd_section_name (section),
1809
        xcoff_dwsect_names[i].xcoff_name) == 0)
1810
    {
1811
      section->alignment_power = 0;
1812
      sclass = C_DWARF;
1813
      break;
1814
    }
1815
    }
1816
#endif
1817
1818
  /* Set up the section symbol.  */
1819
99.5k
  if (!_bfd_generic_new_section_hook (abfd, section))
1820
0
    return false;
1821
1822
  /* Allocate aux records for section symbols, to store size and
1823
     related info.
1824
1825
     @@ The 10 is a guess at a plausible maximum number of aux entries
1826
     (but shouldn't be a constant).  */
1827
99.5k
  amt = sizeof (combined_entry_type) * 10;
1828
99.5k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
99.5k
  if (native == NULL)
1830
0
    return false;
1831
1832
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1833
     symbol information, since they'll be overridden by the BFD symbol
1834
     anyhow.  However, we do need to set the type and storage class,
1835
     in case this symbol winds up getting written out.  The value 0
1836
     for n_numaux is already correct.  */
1837
1838
99.5k
  native->is_sym = true;
1839
99.5k
  native->u.syment.n_type = T_NULL;
1840
99.5k
  native->u.syment.n_sclass = sclass;
1841
1842
99.5k
  coffsymbol (section->symbol)->native = native;
1843
1844
99.5k
  coff_set_custom_section_alignment (abfd, section,
1845
99.5k
             coff_section_alignment_table,
1846
99.5k
             coff_section_alignment_table_size);
1847
1848
99.5k
  return true;
1849
99.5k
}
pe-arm-wince.c:coff_new_section_hook
Line
Count
Source
1789
4
{
1790
4
  combined_entry_type *native;
1791
4
  size_t amt;
1792
4
  unsigned char sclass = C_STAT;
1793
1794
4
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1795
1796
#ifdef RS6000COFF_C
1797
  if (bfd_xcoff_text_align_power (abfd) != 0
1798
      && strcmp (bfd_section_name (section), ".text") == 0)
1799
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1800
  else if (bfd_xcoff_data_align_power (abfd) != 0
1801
      && strcmp (bfd_section_name (section), ".data") == 0)
1802
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1803
  else
1804
    {
1805
      int i;
1806
1807
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1808
  if (strcmp (bfd_section_name (section),
1809
        xcoff_dwsect_names[i].xcoff_name) == 0)
1810
    {
1811
      section->alignment_power = 0;
1812
      sclass = C_DWARF;
1813
      break;
1814
    }
1815
    }
1816
#endif
1817
1818
  /* Set up the section symbol.  */
1819
4
  if (!_bfd_generic_new_section_hook (abfd, section))
1820
0
    return false;
1821
1822
  /* Allocate aux records for section symbols, to store size and
1823
     related info.
1824
1825
     @@ The 10 is a guess at a plausible maximum number of aux entries
1826
     (but shouldn't be a constant).  */
1827
4
  amt = sizeof (combined_entry_type) * 10;
1828
4
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
4
  if (native == NULL)
1830
0
    return false;
1831
1832
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1833
     symbol information, since they'll be overridden by the BFD symbol
1834
     anyhow.  However, we do need to set the type and storage class,
1835
     in case this symbol winds up getting written out.  The value 0
1836
     for n_numaux is already correct.  */
1837
1838
4
  native->is_sym = true;
1839
4
  native->u.syment.n_type = T_NULL;
1840
4
  native->u.syment.n_sclass = sclass;
1841
1842
4
  coffsymbol (section->symbol)->native = native;
1843
1844
4
  coff_set_custom_section_alignment (abfd, section,
1845
4
             coff_section_alignment_table,
1846
4
             coff_section_alignment_table_size);
1847
1848
4
  return true;
1849
4
}
pe-arm.c:coff_new_section_hook
Line
Count
Source
1789
4
{
1790
4
  combined_entry_type *native;
1791
4
  size_t amt;
1792
4
  unsigned char sclass = C_STAT;
1793
1794
4
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1795
1796
#ifdef RS6000COFF_C
1797
  if (bfd_xcoff_text_align_power (abfd) != 0
1798
      && strcmp (bfd_section_name (section), ".text") == 0)
1799
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1800
  else if (bfd_xcoff_data_align_power (abfd) != 0
1801
      && strcmp (bfd_section_name (section), ".data") == 0)
1802
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1803
  else
1804
    {
1805
      int i;
1806
1807
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1808
  if (strcmp (bfd_section_name (section),
1809
        xcoff_dwsect_names[i].xcoff_name) == 0)
1810
    {
1811
      section->alignment_power = 0;
1812
      sclass = C_DWARF;
1813
      break;
1814
    }
1815
    }
1816
#endif
1817
1818
  /* Set up the section symbol.  */
1819
4
  if (!_bfd_generic_new_section_hook (abfd, section))
1820
0
    return false;
1821
1822
  /* Allocate aux records for section symbols, to store size and
1823
     related info.
1824
1825
     @@ The 10 is a guess at a plausible maximum number of aux entries
1826
     (but shouldn't be a constant).  */
1827
4
  amt = sizeof (combined_entry_type) * 10;
1828
4
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
4
  if (native == NULL)
1830
0
    return false;
1831
1832
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1833
     symbol information, since they'll be overridden by the BFD symbol
1834
     anyhow.  However, we do need to set the type and storage class,
1835
     in case this symbol winds up getting written out.  The value 0
1836
     for n_numaux is already correct.  */
1837
1838
4
  native->is_sym = true;
1839
4
  native->u.syment.n_type = T_NULL;
1840
4
  native->u.syment.n_sclass = sclass;
1841
1842
4
  coffsymbol (section->symbol)->native = native;
1843
1844
4
  coff_set_custom_section_alignment (abfd, section,
1845
4
             coff_section_alignment_table,
1846
4
             coff_section_alignment_table_size);
1847
1848
4
  return true;
1849
4
}
pe-i386.c:coff_new_section_hook
Line
Count
Source
1789
1.53k
{
1790
1.53k
  combined_entry_type *native;
1791
1.53k
  size_t amt;
1792
1.53k
  unsigned char sclass = C_STAT;
1793
1794
1.53k
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1795
1796
#ifdef RS6000COFF_C
1797
  if (bfd_xcoff_text_align_power (abfd) != 0
1798
      && strcmp (bfd_section_name (section), ".text") == 0)
1799
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1800
  else if (bfd_xcoff_data_align_power (abfd) != 0
1801
      && strcmp (bfd_section_name (section), ".data") == 0)
1802
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1803
  else
1804
    {
1805
      int i;
1806
1807
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1808
  if (strcmp (bfd_section_name (section),
1809
        xcoff_dwsect_names[i].xcoff_name) == 0)
1810
    {
1811
      section->alignment_power = 0;
1812
      sclass = C_DWARF;
1813
      break;
1814
    }
1815
    }
1816
#endif
1817
1818
  /* Set up the section symbol.  */
1819
1.53k
  if (!_bfd_generic_new_section_hook (abfd, section))
1820
0
    return false;
1821
1822
  /* Allocate aux records for section symbols, to store size and
1823
     related info.
1824
1825
     @@ The 10 is a guess at a plausible maximum number of aux entries
1826
     (but shouldn't be a constant).  */
1827
1.53k
  amt = sizeof (combined_entry_type) * 10;
1828
1.53k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
1.53k
  if (native == NULL)
1830
0
    return false;
1831
1832
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1833
     symbol information, since they'll be overridden by the BFD symbol
1834
     anyhow.  However, we do need to set the type and storage class,
1835
     in case this symbol winds up getting written out.  The value 0
1836
     for n_numaux is already correct.  */
1837
1838
1.53k
  native->is_sym = true;
1839
1.53k
  native->u.syment.n_type = T_NULL;
1840
1.53k
  native->u.syment.n_sclass = sclass;
1841
1842
1.53k
  coffsymbol (section->symbol)->native = native;
1843
1844
1.53k
  coff_set_custom_section_alignment (abfd, section,
1845
1.53k
             coff_section_alignment_table,
1846
1.53k
             coff_section_alignment_table_size);
1847
1848
1.53k
  return true;
1849
1.53k
}
pe-mcore.c:coff_new_section_hook
Line
Count
Source
1789
224
{
1790
224
  combined_entry_type *native;
1791
224
  size_t amt;
1792
224
  unsigned char sclass = C_STAT;
1793
1794
224
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1795
1796
#ifdef RS6000COFF_C
1797
  if (bfd_xcoff_text_align_power (abfd) != 0
1798
      && strcmp (bfd_section_name (section), ".text") == 0)
1799
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1800
  else if (bfd_xcoff_data_align_power (abfd) != 0
1801
      && strcmp (bfd_section_name (section), ".data") == 0)
1802
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1803
  else
1804
    {
1805
      int i;
1806
1807
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1808
  if (strcmp (bfd_section_name (section),
1809
        xcoff_dwsect_names[i].xcoff_name) == 0)
1810
    {
1811
      section->alignment_power = 0;
1812
      sclass = C_DWARF;
1813
      break;
1814
    }
1815
    }
1816
#endif
1817
1818
  /* Set up the section symbol.  */
1819
224
  if (!_bfd_generic_new_section_hook (abfd, section))
1820
0
    return false;
1821
1822
  /* Allocate aux records for section symbols, to store size and
1823
     related info.
1824
1825
     @@ The 10 is a guess at a plausible maximum number of aux entries
1826
     (but shouldn't be a constant).  */
1827
224
  amt = sizeof (combined_entry_type) * 10;
1828
224
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
224
  if (native == NULL)
1830
0
    return false;
1831
1832
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1833
     symbol information, since they'll be overridden by the BFD symbol
1834
     anyhow.  However, we do need to set the type and storage class,
1835
     in case this symbol winds up getting written out.  The value 0
1836
     for n_numaux is already correct.  */
1837
1838
224
  native->is_sym = true;
1839
224
  native->u.syment.n_type = T_NULL;
1840
224
  native->u.syment.n_sclass = sclass;
1841
1842
224
  coffsymbol (section->symbol)->native = native;
1843
1844
224
  coff_set_custom_section_alignment (abfd, section,
1845
224
             coff_section_alignment_table,
1846
224
             coff_section_alignment_table_size);
1847
1848
224
  return true;
1849
224
}
pe-sh.c:coff_new_section_hook
Line
Count
Source
1789
5.04k
{
1790
5.04k
  combined_entry_type *native;
1791
5.04k
  size_t amt;
1792
5.04k
  unsigned char sclass = C_STAT;
1793
1794
5.04k
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1795
1796
#ifdef RS6000COFF_C
1797
  if (bfd_xcoff_text_align_power (abfd) != 0
1798
      && strcmp (bfd_section_name (section), ".text") == 0)
1799
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1800
  else if (bfd_xcoff_data_align_power (abfd) != 0
1801
      && strcmp (bfd_section_name (section), ".data") == 0)
1802
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1803
  else
1804
    {
1805
      int i;
1806
1807
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1808
  if (strcmp (bfd_section_name (section),
1809
        xcoff_dwsect_names[i].xcoff_name) == 0)
1810
    {
1811
      section->alignment_power = 0;
1812
      sclass = C_DWARF;
1813
      break;
1814
    }
1815
    }
1816
#endif
1817
1818
  /* Set up the section symbol.  */
1819
5.04k
  if (!_bfd_generic_new_section_hook (abfd, section))
1820
0
    return false;
1821
1822
  /* Allocate aux records for section symbols, to store size and
1823
     related info.
1824
1825
     @@ The 10 is a guess at a plausible maximum number of aux entries
1826
     (but shouldn't be a constant).  */
1827
5.04k
  amt = sizeof (combined_entry_type) * 10;
1828
5.04k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
5.04k
  if (native == NULL)
1830
0
    return false;
1831
1832
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1833
     symbol information, since they'll be overridden by the BFD symbol
1834
     anyhow.  However, we do need to set the type and storage class,
1835
     in case this symbol winds up getting written out.  The value 0
1836
     for n_numaux is already correct.  */
1837
1838
5.04k
  native->is_sym = true;
1839
5.04k
  native->u.syment.n_type = T_NULL;
1840
5.04k
  native->u.syment.n_sclass = sclass;
1841
1842
5.04k
  coffsymbol (section->symbol)->native = native;
1843
1844
5.04k
  coff_set_custom_section_alignment (abfd, section,
1845
5.04k
             coff_section_alignment_table,
1846
5.04k
             coff_section_alignment_table_size);
1847
1848
5.04k
  return true;
1849
5.04k
}
pei-arm-wince.c:coff_new_section_hook
Line
Count
Source
1789
4.11k
{
1790
4.11k
  combined_entry_type *native;
1791
4.11k
  size_t amt;
1792
4.11k
  unsigned char sclass = C_STAT;
1793
1794
4.11k
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1795
1796
#ifdef RS6000COFF_C
1797
  if (bfd_xcoff_text_align_power (abfd) != 0
1798
      && strcmp (bfd_section_name (section), ".text") == 0)
1799
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1800
  else if (bfd_xcoff_data_align_power (abfd) != 0
1801
      && strcmp (bfd_section_name (section), ".data") == 0)
1802
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1803
  else
1804
    {
1805
      int i;
1806
1807
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1808
  if (strcmp (bfd_section_name (section),
1809
        xcoff_dwsect_names[i].xcoff_name) == 0)
1810
    {
1811
      section->alignment_power = 0;
1812
      sclass = C_DWARF;
1813
      break;
1814
    }
1815
    }
1816
#endif
1817
1818
  /* Set up the section symbol.  */
1819
4.11k
  if (!_bfd_generic_new_section_hook (abfd, section))
1820
0
    return false;
1821
1822
  /* Allocate aux records for section symbols, to store size and
1823
     related info.
1824
1825
     @@ The 10 is a guess at a plausible maximum number of aux entries
1826
     (but shouldn't be a constant).  */
1827
4.11k
  amt = sizeof (combined_entry_type) * 10;
1828
4.11k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
4.11k
  if (native == NULL)
1830
0
    return false;
1831
1832
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1833
     symbol information, since they'll be overridden by the BFD symbol
1834
     anyhow.  However, we do need to set the type and storage class,
1835
     in case this symbol winds up getting written out.  The value 0
1836
     for n_numaux is already correct.  */
1837
1838
4.11k
  native->is_sym = true;
1839
4.11k
  native->u.syment.n_type = T_NULL;
1840
4.11k
  native->u.syment.n_sclass = sclass;
1841
1842
4.11k
  coffsymbol (section->symbol)->native = native;
1843
1844
4.11k
  coff_set_custom_section_alignment (abfd, section,
1845
4.11k
             coff_section_alignment_table,
1846
4.11k
             coff_section_alignment_table_size);
1847
1848
4.11k
  return true;
1849
4.11k
}
pei-arm.c:coff_new_section_hook
Line
Count
Source
1789
26
{
1790
26
  combined_entry_type *native;
1791
26
  size_t amt;
1792
26
  unsigned char sclass = C_STAT;
1793
1794
26
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1795
1796
#ifdef RS6000COFF_C
1797
  if (bfd_xcoff_text_align_power (abfd) != 0
1798
      && strcmp (bfd_section_name (section), ".text") == 0)
1799
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1800
  else if (bfd_xcoff_data_align_power (abfd) != 0
1801
      && strcmp (bfd_section_name (section), ".data") == 0)
1802
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1803
  else
1804
    {
1805
      int i;
1806
1807
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1808
  if (strcmp (bfd_section_name (section),
1809
        xcoff_dwsect_names[i].xcoff_name) == 0)
1810
    {
1811
      section->alignment_power = 0;
1812
      sclass = C_DWARF;
1813
      break;
1814
    }
1815
    }
1816
#endif
1817
1818
  /* Set up the section symbol.  */
1819
26
  if (!_bfd_generic_new_section_hook (abfd, section))
1820
0
    return false;
1821
1822
  /* Allocate aux records for section symbols, to store size and
1823
     related info.
1824
1825
     @@ The 10 is a guess at a plausible maximum number of aux entries
1826
     (but shouldn't be a constant).  */
1827
26
  amt = sizeof (combined_entry_type) * 10;
1828
26
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
26
  if (native == NULL)
1830
0
    return false;
1831
1832
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1833
     symbol information, since they'll be overridden by the BFD symbol
1834
     anyhow.  However, we do need to set the type and storage class,
1835
     in case this symbol winds up getting written out.  The value 0
1836
     for n_numaux is already correct.  */
1837
1838
26
  native->is_sym = true;
1839
26
  native->u.syment.n_type = T_NULL;
1840
26
  native->u.syment.n_sclass = sclass;
1841
1842
26
  coffsymbol (section->symbol)->native = native;
1843
1844
26
  coff_set_custom_section_alignment (abfd, section,
1845
26
             coff_section_alignment_table,
1846
26
             coff_section_alignment_table_size);
1847
1848
26
  return true;
1849
26
}
pei-mcore.c:coff_new_section_hook
Line
Count
Source
1789
10
{
1790
10
  combined_entry_type *native;
1791
10
  size_t amt;
1792
10
  unsigned char sclass = C_STAT;
1793
1794
10
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1795
1796
#ifdef RS6000COFF_C
1797
  if (bfd_xcoff_text_align_power (abfd) != 0
1798
      && strcmp (bfd_section_name (section), ".text") == 0)
1799
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1800
  else if (bfd_xcoff_data_align_power (abfd) != 0
1801
      && strcmp (bfd_section_name (section), ".data") == 0)
1802
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1803
  else
1804
    {
1805
      int i;
1806
1807
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1808
  if (strcmp (bfd_section_name (section),
1809
        xcoff_dwsect_names[i].xcoff_name) == 0)
1810
    {
1811
      section->alignment_power = 0;
1812
      sclass = C_DWARF;
1813
      break;
1814
    }
1815
    }
1816
#endif
1817
1818
  /* Set up the section symbol.  */
1819
10
  if (!_bfd_generic_new_section_hook (abfd, section))
1820
0
    return false;
1821
1822
  /* Allocate aux records for section symbols, to store size and
1823
     related info.
1824
1825
     @@ The 10 is a guess at a plausible maximum number of aux entries
1826
     (but shouldn't be a constant).  */
1827
10
  amt = sizeof (combined_entry_type) * 10;
1828
10
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
10
  if (native == NULL)
1830
0
    return false;
1831
1832
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1833
     symbol information, since they'll be overridden by the BFD symbol
1834
     anyhow.  However, we do need to set the type and storage class,
1835
     in case this symbol winds up getting written out.  The value 0
1836
     for n_numaux is already correct.  */
1837
1838
10
  native->is_sym = true;
1839
10
  native->u.syment.n_type = T_NULL;
1840
10
  native->u.syment.n_sclass = sclass;
1841
1842
10
  coffsymbol (section->symbol)->native = native;
1843
1844
10
  coff_set_custom_section_alignment (abfd, section,
1845
10
             coff_section_alignment_table,
1846
10
             coff_section_alignment_table_size);
1847
1848
10
  return true;
1849
10
}
pei-sh.c:coff_new_section_hook
Line
Count
Source
1789
1.52k
{
1790
1.52k
  combined_entry_type *native;
1791
1.52k
  size_t amt;
1792
1.52k
  unsigned char sclass = C_STAT;
1793
1794
1.52k
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1795
1796
#ifdef RS6000COFF_C
1797
  if (bfd_xcoff_text_align_power (abfd) != 0
1798
      && strcmp (bfd_section_name (section), ".text") == 0)
1799
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1800
  else if (bfd_xcoff_data_align_power (abfd) != 0
1801
      && strcmp (bfd_section_name (section), ".data") == 0)
1802
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1803
  else
1804
    {
1805
      int i;
1806
1807
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1808
  if (strcmp (bfd_section_name (section),
1809
        xcoff_dwsect_names[i].xcoff_name) == 0)
1810
    {
1811
      section->alignment_power = 0;
1812
      sclass = C_DWARF;
1813
      break;
1814
    }
1815
    }
1816
#endif
1817
1818
  /* Set up the section symbol.  */
1819
1.52k
  if (!_bfd_generic_new_section_hook (abfd, section))
1820
0
    return false;
1821
1822
  /* Allocate aux records for section symbols, to store size and
1823
     related info.
1824
1825
     @@ The 10 is a guess at a plausible maximum number of aux entries
1826
     (but shouldn't be a constant).  */
1827
1.52k
  amt = sizeof (combined_entry_type) * 10;
1828
1.52k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
1.52k
  if (native == NULL)
1830
0
    return false;
1831
1832
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1833
     symbol information, since they'll be overridden by the BFD symbol
1834
     anyhow.  However, we do need to set the type and storage class,
1835
     in case this symbol winds up getting written out.  The value 0
1836
     for n_numaux is already correct.  */
1837
1838
1.52k
  native->is_sym = true;
1839
1.52k
  native->u.syment.n_type = T_NULL;
1840
1.52k
  native->u.syment.n_sclass = sclass;
1841
1842
1.52k
  coffsymbol (section->symbol)->native = native;
1843
1844
1.52k
  coff_set_custom_section_alignment (abfd, section,
1845
1.52k
             coff_section_alignment_table,
1846
1.52k
             coff_section_alignment_table_size);
1847
1848
1.52k
  return true;
1849
1.52k
}
1850
1851
#ifdef COFF_ALIGN_IN_SECTION_HEADER
1852
1853
/* Set the alignment of a BFD section.  */
1854
1855
static void
1856
coff_set_alignment_hook (bfd * abfd ATTRIBUTE_UNUSED,
1857
       asection * section,
1858
       void * scnhdr)
1859
32.0k
{
1860
32.0k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1861
32.0k
  unsigned int i;
1862
1863
32.0k
#ifdef COFF_DECODE_ALIGNMENT
1864
32.0k
  i = COFF_DECODE_ALIGNMENT(hdr->s_flags);
1865
32.0k
#endif
1866
32.0k
  section->alignment_power = i;
1867
1868
#ifdef coff_set_section_load_page
1869
22.8k
  coff_set_section_load_page (section, hdr->s_page);
1870
#endif
1871
32.0k
}
Unexecuted instantiation: coff-tic4x.c:coff_set_alignment_hook
coff-tic54x.c:coff_set_alignment_hook
Line
Count
Source
1859
22.8k
{
1860
22.8k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1861
22.8k
  unsigned int i;
1862
1863
22.8k
#ifdef COFF_DECODE_ALIGNMENT
1864
22.8k
  i = COFF_DECODE_ALIGNMENT(hdr->s_flags);
1865
22.8k
#endif
1866
22.8k
  section->alignment_power = i;
1867
1868
22.8k
#ifdef coff_set_section_load_page
1869
22.8k
  coff_set_section_load_page (section, hdr->s_page);
1870
22.8k
#endif
1871
22.8k
}
coff-z80.c:coff_set_alignment_hook
Line
Count
Source
1859
9.17k
{
1860
9.17k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1861
9.17k
  unsigned int i;
1862
1863
9.17k
#ifdef COFF_DECODE_ALIGNMENT
1864
9.17k
  i = COFF_DECODE_ALIGNMENT(hdr->s_flags);
1865
9.17k
#endif
1866
9.17k
  section->alignment_power = i;
1867
1868
#ifdef coff_set_section_load_page
1869
  coff_set_section_load_page (section, hdr->s_page);
1870
#endif
1871
9.17k
}
1872
1873
#else /* ! COFF_ALIGN_IN_SECTION_HEADER */
1874
#ifdef COFF_WITH_PE
1875
1876
static void
1877
coff_set_alignment_hook (bfd * abfd ATTRIBUTE_UNUSED,
1878
       asection * section,
1879
       void * scnhdr)
1880
19.3k
{
1881
19.3k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1882
19.3k
  size_t amt;
1883
19.3k
  unsigned int alignment_power_const
1884
19.3k
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1885
1886
19.3k
  switch (alignment_power_const)
1887
19.3k
    {
1888
263
    case IMAGE_SCN_ALIGN_8192BYTES:
1889
281
    case IMAGE_SCN_ALIGN_4096BYTES:
1890
469
    case IMAGE_SCN_ALIGN_2048BYTES:
1891
687
    case IMAGE_SCN_ALIGN_1024BYTES:
1892
714
    case IMAGE_SCN_ALIGN_512BYTES:
1893
763
    case IMAGE_SCN_ALIGN_256BYTES:
1894
1.91k
    case IMAGE_SCN_ALIGN_128BYTES:
1895
2.03k
    case IMAGE_SCN_ALIGN_64BYTES:
1896
2.20k
    case IMAGE_SCN_ALIGN_32BYTES:
1897
2.22k
    case IMAGE_SCN_ALIGN_16BYTES:
1898
2.67k
    case IMAGE_SCN_ALIGN_8BYTES:
1899
2.72k
    case IMAGE_SCN_ALIGN_4BYTES:
1900
3.09k
    case IMAGE_SCN_ALIGN_2BYTES:
1901
3.10k
    case IMAGE_SCN_ALIGN_1BYTES:
1902
3.10k
      section->alignment_power
1903
3.10k
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1904
3.10k
      break;
1905
16.2k
    default:
1906
16.2k
      break;
1907
19.3k
    }
1908
1909
  /* In a PE image file, the s_paddr field holds the virtual size of a
1910
     section, while the s_size field holds the raw size.  We also keep
1911
     the original section flag value, since not every bit can be
1912
     mapped onto a generic BFD section bit.  */
1913
19.3k
  if (coff_section_data (abfd, section) == NULL)
1914
19.3k
    {
1915
19.3k
      amt = sizeof (struct coff_section_tdata);
1916
19.3k
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1917
19.3k
      if (section->used_by_bfd == NULL)
1918
  /* FIXME: Return error.  */
1919
0
  abort ();
1920
19.3k
    }
1921
1922
19.3k
  if (pei_section_data (abfd, section) == NULL)
1923
19.3k
    {
1924
19.3k
      amt = sizeof (struct pei_section_tdata);
1925
19.3k
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1926
19.3k
      if (coff_section_data (abfd, section)->tdata == NULL)
1927
  /* FIXME: Return error.  */
1928
0
  abort ();
1929
19.3k
    }
1930
19.3k
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1931
19.3k
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1932
1933
19.3k
  section->lma = hdr->s_vaddr;
1934
1935
  /* Check for extended relocs.  */
1936
19.3k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1937
1.21k
    {
1938
1.21k
      struct external_reloc dst;
1939
1.21k
      struct internal_reloc n;
1940
1.21k
      file_ptr oldpos = bfd_tell (abfd);
1941
1.21k
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1942
1943
1.21k
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1944
0
  return;
1945
1.21k
      if (bfd_read (& dst, relsz, abfd) != relsz)
1946
1.06k
  return;
1947
1948
148
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1949
148
      if (bfd_seek (abfd, oldpos, 0) != 0)
1950
0
  return;
1951
148
      if (n.r_vaddr < 0x10000)
1952
30
  {
1953
30
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1954
30
    bfd_set_error (bfd_error_bad_value);
1955
30
    return;
1956
30
  }
1957
118
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1958
118
      section->rel_filepos += relsz;
1959
118
    }
1960
18.1k
  else if (hdr->s_nreloc == 0xffff)
1961
5
    _bfd_error_handler
1962
5
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1963
5
       abfd);
1964
19.3k
}
pei-i386.c:coff_set_alignment_hook
Line
Count
Source
1880
177
{
1881
177
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1882
177
  size_t amt;
1883
177
  unsigned int alignment_power_const
1884
177
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1885
1886
177
  switch (alignment_power_const)
1887
177
    {
1888
0
    case IMAGE_SCN_ALIGN_8192BYTES:
1889
0
    case IMAGE_SCN_ALIGN_4096BYTES:
1890
0
    case IMAGE_SCN_ALIGN_2048BYTES:
1891
0
    case IMAGE_SCN_ALIGN_1024BYTES:
1892
0
    case IMAGE_SCN_ALIGN_512BYTES:
1893
0
    case IMAGE_SCN_ALIGN_256BYTES:
1894
2
    case IMAGE_SCN_ALIGN_128BYTES:
1895
2
    case IMAGE_SCN_ALIGN_64BYTES:
1896
9
    case IMAGE_SCN_ALIGN_32BYTES:
1897
13
    case IMAGE_SCN_ALIGN_16BYTES:
1898
17
    case IMAGE_SCN_ALIGN_8BYTES:
1899
45
    case IMAGE_SCN_ALIGN_4BYTES:
1900
45
    case IMAGE_SCN_ALIGN_2BYTES:
1901
45
    case IMAGE_SCN_ALIGN_1BYTES:
1902
45
      section->alignment_power
1903
45
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1904
45
      break;
1905
132
    default:
1906
132
      break;
1907
177
    }
1908
1909
  /* In a PE image file, the s_paddr field holds the virtual size of a
1910
     section, while the s_size field holds the raw size.  We also keep
1911
     the original section flag value, since not every bit can be
1912
     mapped onto a generic BFD section bit.  */
1913
177
  if (coff_section_data (abfd, section) == NULL)
1914
177
    {
1915
177
      amt = sizeof (struct coff_section_tdata);
1916
177
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1917
177
      if (section->used_by_bfd == NULL)
1918
  /* FIXME: Return error.  */
1919
0
  abort ();
1920
177
    }
1921
1922
177
  if (pei_section_data (abfd, section) == NULL)
1923
177
    {
1924
177
      amt = sizeof (struct pei_section_tdata);
1925
177
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1926
177
      if (coff_section_data (abfd, section)->tdata == NULL)
1927
  /* FIXME: Return error.  */
1928
0
  abort ();
1929
177
    }
1930
177
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1931
177
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1932
1933
177
  section->lma = hdr->s_vaddr;
1934
1935
  /* Check for extended relocs.  */
1936
177
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1937
30
    {
1938
30
      struct external_reloc dst;
1939
30
      struct internal_reloc n;
1940
30
      file_ptr oldpos = bfd_tell (abfd);
1941
30
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1942
1943
30
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1944
0
  return;
1945
30
      if (bfd_read (& dst, relsz, abfd) != relsz)
1946
24
  return;
1947
1948
6
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1949
6
      if (bfd_seek (abfd, oldpos, 0) != 0)
1950
0
  return;
1951
6
      if (n.r_vaddr < 0x10000)
1952
0
  {
1953
0
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1954
0
    bfd_set_error (bfd_error_bad_value);
1955
0
    return;
1956
0
  }
1957
6
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1958
6
      section->rel_filepos += relsz;
1959
6
    }
1960
147
  else if (hdr->s_nreloc == 0xffff)
1961
0
    _bfd_error_handler
1962
0
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1963
0
       abfd);
1964
177
}
pe-x86_64.c:coff_set_alignment_hook
Line
Count
Source
1880
529
{
1881
529
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1882
529
  size_t amt;
1883
529
  unsigned int alignment_power_const
1884
529
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1885
1886
529
  switch (alignment_power_const)
1887
529
    {
1888
3
    case IMAGE_SCN_ALIGN_8192BYTES:
1889
3
    case IMAGE_SCN_ALIGN_4096BYTES:
1890
3
    case IMAGE_SCN_ALIGN_2048BYTES:
1891
13
    case IMAGE_SCN_ALIGN_1024BYTES:
1892
21
    case IMAGE_SCN_ALIGN_512BYTES:
1893
29
    case IMAGE_SCN_ALIGN_256BYTES:
1894
35
    case IMAGE_SCN_ALIGN_128BYTES:
1895
43
    case IMAGE_SCN_ALIGN_64BYTES:
1896
46
    case IMAGE_SCN_ALIGN_32BYTES:
1897
53
    case IMAGE_SCN_ALIGN_16BYTES:
1898
53
    case IMAGE_SCN_ALIGN_8BYTES:
1899
55
    case IMAGE_SCN_ALIGN_4BYTES:
1900
56
    case IMAGE_SCN_ALIGN_2BYTES:
1901
58
    case IMAGE_SCN_ALIGN_1BYTES:
1902
58
      section->alignment_power
1903
58
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1904
58
      break;
1905
471
    default:
1906
471
      break;
1907
529
    }
1908
1909
  /* In a PE image file, the s_paddr field holds the virtual size of a
1910
     section, while the s_size field holds the raw size.  We also keep
1911
     the original section flag value, since not every bit can be
1912
     mapped onto a generic BFD section bit.  */
1913
529
  if (coff_section_data (abfd, section) == NULL)
1914
529
    {
1915
529
      amt = sizeof (struct coff_section_tdata);
1916
529
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1917
529
      if (section->used_by_bfd == NULL)
1918
  /* FIXME: Return error.  */
1919
0
  abort ();
1920
529
    }
1921
1922
529
  if (pei_section_data (abfd, section) == NULL)
1923
529
    {
1924
529
      amt = sizeof (struct pei_section_tdata);
1925
529
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1926
529
      if (coff_section_data (abfd, section)->tdata == NULL)
1927
  /* FIXME: Return error.  */
1928
0
  abort ();
1929
529
    }
1930
529
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1931
529
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1932
1933
529
  section->lma = hdr->s_vaddr;
1934
1935
  /* Check for extended relocs.  */
1936
529
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1937
38
    {
1938
38
      struct external_reloc dst;
1939
38
      struct internal_reloc n;
1940
38
      file_ptr oldpos = bfd_tell (abfd);
1941
38
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1942
1943
38
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1944
0
  return;
1945
38
      if (bfd_read (& dst, relsz, abfd) != relsz)
1946
31
  return;
1947
1948
7
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1949
7
      if (bfd_seek (abfd, oldpos, 0) != 0)
1950
0
  return;
1951
7
      if (n.r_vaddr < 0x10000)
1952
0
  {
1953
0
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1954
0
    bfd_set_error (bfd_error_bad_value);
1955
0
    return;
1956
0
  }
1957
7
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1958
7
      section->rel_filepos += relsz;
1959
7
    }
1960
491
  else if (hdr->s_nreloc == 0xffff)
1961
3
    _bfd_error_handler
1962
3
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1963
3
       abfd);
1964
529
}
pei-x86_64.c:coff_set_alignment_hook
Line
Count
Source
1880
766
{
1881
766
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1882
766
  size_t amt;
1883
766
  unsigned int alignment_power_const
1884
766
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1885
1886
766
  switch (alignment_power_const)
1887
766
    {
1888
0
    case IMAGE_SCN_ALIGN_8192BYTES:
1889
0
    case IMAGE_SCN_ALIGN_4096BYTES:
1890
21
    case IMAGE_SCN_ALIGN_2048BYTES:
1891
23
    case IMAGE_SCN_ALIGN_1024BYTES:
1892
23
    case IMAGE_SCN_ALIGN_512BYTES:
1893
27
    case IMAGE_SCN_ALIGN_256BYTES:
1894
27
    case IMAGE_SCN_ALIGN_128BYTES:
1895
27
    case IMAGE_SCN_ALIGN_64BYTES:
1896
27
    case IMAGE_SCN_ALIGN_32BYTES:
1897
27
    case IMAGE_SCN_ALIGN_16BYTES:
1898
31
    case IMAGE_SCN_ALIGN_8BYTES:
1899
31
    case IMAGE_SCN_ALIGN_4BYTES:
1900
31
    case IMAGE_SCN_ALIGN_2BYTES:
1901
31
    case IMAGE_SCN_ALIGN_1BYTES:
1902
31
      section->alignment_power
1903
31
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1904
31
      break;
1905
735
    default:
1906
735
      break;
1907
766
    }
1908
1909
  /* In a PE image file, the s_paddr field holds the virtual size of a
1910
     section, while the s_size field holds the raw size.  We also keep
1911
     the original section flag value, since not every bit can be
1912
     mapped onto a generic BFD section bit.  */
1913
766
  if (coff_section_data (abfd, section) == NULL)
1914
766
    {
1915
766
      amt = sizeof (struct coff_section_tdata);
1916
766
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1917
766
      if (section->used_by_bfd == NULL)
1918
  /* FIXME: Return error.  */
1919
0
  abort ();
1920
766
    }
1921
1922
766
  if (pei_section_data (abfd, section) == NULL)
1923
766
    {
1924
766
      amt = sizeof (struct pei_section_tdata);
1925
766
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1926
766
      if (coff_section_data (abfd, section)->tdata == NULL)
1927
  /* FIXME: Return error.  */
1928
0
  abort ();
1929
766
    }
1930
766
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1931
766
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1932
1933
766
  section->lma = hdr->s_vaddr;
1934
1935
  /* Check for extended relocs.  */
1936
766
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1937
26
    {
1938
26
      struct external_reloc dst;
1939
26
      struct internal_reloc n;
1940
26
      file_ptr oldpos = bfd_tell (abfd);
1941
26
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1942
1943
26
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1944
0
  return;
1945
26
      if (bfd_read (& dst, relsz, abfd) != relsz)
1946
4
  return;
1947
1948
22
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1949
22
      if (bfd_seek (abfd, oldpos, 0) != 0)
1950
0
  return;
1951
22
      if (n.r_vaddr < 0x10000)
1952
14
  {
1953
14
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1954
14
    bfd_set_error (bfd_error_bad_value);
1955
14
    return;
1956
14
  }
1957
8
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1958
8
      section->rel_filepos += relsz;
1959
8
    }
1960
740
  else if (hdr->s_nreloc == 0xffff)
1961
0
    _bfd_error_handler
1962
0
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1963
0
       abfd);
1964
766
}
pe-aarch64.c:coff_set_alignment_hook
Line
Count
Source
1880
179
{
1881
179
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1882
179
  size_t amt;
1883
179
  unsigned int alignment_power_const
1884
179
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1885
1886
179
  switch (alignment_power_const)
1887
179
    {
1888
0
    case IMAGE_SCN_ALIGN_8192BYTES:
1889
0
    case IMAGE_SCN_ALIGN_4096BYTES:
1890
0
    case IMAGE_SCN_ALIGN_2048BYTES:
1891
0
    case IMAGE_SCN_ALIGN_1024BYTES:
1892
0
    case IMAGE_SCN_ALIGN_512BYTES:
1893
0
    case IMAGE_SCN_ALIGN_256BYTES:
1894
1
    case IMAGE_SCN_ALIGN_128BYTES:
1895
1
    case IMAGE_SCN_ALIGN_64BYTES:
1896
1
    case IMAGE_SCN_ALIGN_32BYTES:
1897
1
    case IMAGE_SCN_ALIGN_16BYTES:
1898
1
    case IMAGE_SCN_ALIGN_8BYTES:
1899
1
    case IMAGE_SCN_ALIGN_4BYTES:
1900
37
    case IMAGE_SCN_ALIGN_2BYTES:
1901
37
    case IMAGE_SCN_ALIGN_1BYTES:
1902
37
      section->alignment_power
1903
37
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1904
37
      break;
1905
142
    default:
1906
142
      break;
1907
179
    }
1908
1909
  /* In a PE image file, the s_paddr field holds the virtual size of a
1910
     section, while the s_size field holds the raw size.  We also keep
1911
     the original section flag value, since not every bit can be
1912
     mapped onto a generic BFD section bit.  */
1913
179
  if (coff_section_data (abfd, section) == NULL)
1914
179
    {
1915
179
      amt = sizeof (struct coff_section_tdata);
1916
179
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1917
179
      if (section->used_by_bfd == NULL)
1918
  /* FIXME: Return error.  */
1919
0
  abort ();
1920
179
    }
1921
1922
179
  if (pei_section_data (abfd, section) == NULL)
1923
179
    {
1924
179
      amt = sizeof (struct pei_section_tdata);
1925
179
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1926
179
      if (coff_section_data (abfd, section)->tdata == NULL)
1927
  /* FIXME: Return error.  */
1928
0
  abort ();
1929
179
    }
1930
179
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1931
179
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1932
1933
179
  section->lma = hdr->s_vaddr;
1934
1935
  /* Check for extended relocs.  */
1936
179
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1937
38
    {
1938
38
      struct external_reloc dst;
1939
38
      struct internal_reloc n;
1940
38
      file_ptr oldpos = bfd_tell (abfd);
1941
38
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1942
1943
38
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1944
0
  return;
1945
38
      if (bfd_read (& dst, relsz, abfd) != relsz)
1946
38
  return;
1947
1948
0
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1949
0
      if (bfd_seek (abfd, oldpos, 0) != 0)
1950
0
  return;
1951
0
      if (n.r_vaddr < 0x10000)
1952
0
  {
1953
0
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1954
0
    bfd_set_error (bfd_error_bad_value);
1955
0
    return;
1956
0
  }
1957
0
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1958
0
      section->rel_filepos += relsz;
1959
0
    }
1960
141
  else if (hdr->s_nreloc == 0xffff)
1961
0
    _bfd_error_handler
1962
0
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1963
0
       abfd);
1964
179
}
pei-aarch64.c:coff_set_alignment_hook
Line
Count
Source
1880
5.44k
{
1881
5.44k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1882
5.44k
  size_t amt;
1883
5.44k
  unsigned int alignment_power_const
1884
5.44k
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1885
1886
5.44k
  switch (alignment_power_const)
1887
5.44k
    {
1888
2
    case IMAGE_SCN_ALIGN_8192BYTES:
1889
2
    case IMAGE_SCN_ALIGN_4096BYTES:
1890
14
    case IMAGE_SCN_ALIGN_2048BYTES:
1891
109
    case IMAGE_SCN_ALIGN_1024BYTES:
1892
111
    case IMAGE_SCN_ALIGN_512BYTES:
1893
111
    case IMAGE_SCN_ALIGN_256BYTES:
1894
111
    case IMAGE_SCN_ALIGN_128BYTES:
1895
113
    case IMAGE_SCN_ALIGN_64BYTES:
1896
123
    case IMAGE_SCN_ALIGN_32BYTES:
1897
125
    case IMAGE_SCN_ALIGN_16BYTES:
1898
125
    case IMAGE_SCN_ALIGN_8BYTES:
1899
127
    case IMAGE_SCN_ALIGN_4BYTES:
1900
127
    case IMAGE_SCN_ALIGN_2BYTES:
1901
131
    case IMAGE_SCN_ALIGN_1BYTES:
1902
131
      section->alignment_power
1903
131
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1904
131
      break;
1905
5.31k
    default:
1906
5.31k
      break;
1907
5.44k
    }
1908
1909
  /* In a PE image file, the s_paddr field holds the virtual size of a
1910
     section, while the s_size field holds the raw size.  We also keep
1911
     the original section flag value, since not every bit can be
1912
     mapped onto a generic BFD section bit.  */
1913
5.44k
  if (coff_section_data (abfd, section) == NULL)
1914
5.44k
    {
1915
5.44k
      amt = sizeof (struct coff_section_tdata);
1916
5.44k
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1917
5.44k
      if (section->used_by_bfd == NULL)
1918
  /* FIXME: Return error.  */
1919
0
  abort ();
1920
5.44k
    }
1921
1922
5.44k
  if (pei_section_data (abfd, section) == NULL)
1923
5.44k
    {
1924
5.44k
      amt = sizeof (struct pei_section_tdata);
1925
5.44k
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1926
5.44k
      if (coff_section_data (abfd, section)->tdata == NULL)
1927
  /* FIXME: Return error.  */
1928
0
  abort ();
1929
5.44k
    }
1930
5.44k
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1931
5.44k
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1932
1933
5.44k
  section->lma = hdr->s_vaddr;
1934
1935
  /* Check for extended relocs.  */
1936
5.44k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1937
33
    {
1938
33
      struct external_reloc dst;
1939
33
      struct internal_reloc n;
1940
33
      file_ptr oldpos = bfd_tell (abfd);
1941
33
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1942
1943
33
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1944
0
  return;
1945
33
      if (bfd_read (& dst, relsz, abfd) != relsz)
1946
2
  return;
1947
1948
31
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1949
31
      if (bfd_seek (abfd, oldpos, 0) != 0)
1950
0
  return;
1951
31
      if (n.r_vaddr < 0x10000)
1952
15
  {
1953
15
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1954
15
    bfd_set_error (bfd_error_bad_value);
1955
15
    return;
1956
15
  }
1957
16
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1958
16
      section->rel_filepos += relsz;
1959
16
    }
1960
5.41k
  else if (hdr->s_nreloc == 0xffff)
1961
0
    _bfd_error_handler
1962
0
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1963
0
       abfd);
1964
5.44k
}
pei-ia64.c:coff_set_alignment_hook
Line
Count
Source
1880
155
{
1881
155
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1882
155
  size_t amt;
1883
155
  unsigned int alignment_power_const
1884
155
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1885
1886
155
  switch (alignment_power_const)
1887
155
    {
1888
0
    case IMAGE_SCN_ALIGN_8192BYTES:
1889
0
    case IMAGE_SCN_ALIGN_4096BYTES:
1890
0
    case IMAGE_SCN_ALIGN_2048BYTES:
1891
0
    case IMAGE_SCN_ALIGN_1024BYTES:
1892
0
    case IMAGE_SCN_ALIGN_512BYTES:
1893
0
    case IMAGE_SCN_ALIGN_256BYTES:
1894
0
    case IMAGE_SCN_ALIGN_128BYTES:
1895
0
    case IMAGE_SCN_ALIGN_64BYTES:
1896
2
    case IMAGE_SCN_ALIGN_32BYTES:
1897
2
    case IMAGE_SCN_ALIGN_16BYTES:
1898
2
    case IMAGE_SCN_ALIGN_8BYTES:
1899
2
    case IMAGE_SCN_ALIGN_4BYTES:
1900
2
    case IMAGE_SCN_ALIGN_2BYTES:
1901
2
    case IMAGE_SCN_ALIGN_1BYTES:
1902
2
      section->alignment_power
1903
2
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1904
2
      break;
1905
153
    default:
1906
153
      break;
1907
155
    }
1908
1909
  /* In a PE image file, the s_paddr field holds the virtual size of a
1910
     section, while the s_size field holds the raw size.  We also keep
1911
     the original section flag value, since not every bit can be
1912
     mapped onto a generic BFD section bit.  */
1913
155
  if (coff_section_data (abfd, section) == NULL)
1914
155
    {
1915
155
      amt = sizeof (struct coff_section_tdata);
1916
155
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1917
155
      if (section->used_by_bfd == NULL)
1918
  /* FIXME: Return error.  */
1919
0
  abort ();
1920
155
    }
1921
1922
155
  if (pei_section_data (abfd, section) == NULL)
1923
155
    {
1924
155
      amt = sizeof (struct pei_section_tdata);
1925
155
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1926
155
      if (coff_section_data (abfd, section)->tdata == NULL)
1927
  /* FIXME: Return error.  */
1928
0
  abort ();
1929
155
    }
1930
155
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1931
155
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1932
1933
155
  section->lma = hdr->s_vaddr;
1934
1935
  /* Check for extended relocs.  */
1936
155
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1937
11
    {
1938
11
      struct external_reloc dst;
1939
11
      struct internal_reloc n;
1940
11
      file_ptr oldpos = bfd_tell (abfd);
1941
11
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1942
1943
11
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1944
0
  return;
1945
11
      if (bfd_read (& dst, relsz, abfd) != relsz)
1946
6
  return;
1947
1948
5
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1949
5
      if (bfd_seek (abfd, oldpos, 0) != 0)
1950
0
  return;
1951
5
      if (n.r_vaddr < 0x10000)
1952
1
  {
1953
1
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1954
1
    bfd_set_error (bfd_error_bad_value);
1955
1
    return;
1956
1
  }
1957
4
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1958
4
      section->rel_filepos += relsz;
1959
4
    }
1960
144
  else if (hdr->s_nreloc == 0xffff)
1961
0
    _bfd_error_handler
1962
0
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1963
0
       abfd);
1964
155
}
pei-loongarch64.c:coff_set_alignment_hook
Line
Count
Source
1880
399
{
1881
399
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1882
399
  size_t amt;
1883
399
  unsigned int alignment_power_const
1884
399
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1885
1886
399
  switch (alignment_power_const)
1887
399
    {
1888
2
    case IMAGE_SCN_ALIGN_8192BYTES:
1889
18
    case IMAGE_SCN_ALIGN_4096BYTES:
1890
18
    case IMAGE_SCN_ALIGN_2048BYTES:
1891
18
    case IMAGE_SCN_ALIGN_1024BYTES:
1892
21
    case IMAGE_SCN_ALIGN_512BYTES:
1893
27
    case IMAGE_SCN_ALIGN_256BYTES:
1894
35
    case IMAGE_SCN_ALIGN_128BYTES:
1895
35
    case IMAGE_SCN_ALIGN_64BYTES:
1896
35
    case IMAGE_SCN_ALIGN_32BYTES:
1897
37
    case IMAGE_SCN_ALIGN_16BYTES:
1898
37
    case IMAGE_SCN_ALIGN_8BYTES:
1899
45
    case IMAGE_SCN_ALIGN_4BYTES:
1900
65
    case IMAGE_SCN_ALIGN_2BYTES:
1901
65
    case IMAGE_SCN_ALIGN_1BYTES:
1902
65
      section->alignment_power
1903
65
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1904
65
      break;
1905
334
    default:
1906
334
      break;
1907
399
    }
1908
1909
  /* In a PE image file, the s_paddr field holds the virtual size of a
1910
     section, while the s_size field holds the raw size.  We also keep
1911
     the original section flag value, since not every bit can be
1912
     mapped onto a generic BFD section bit.  */
1913
399
  if (coff_section_data (abfd, section) == NULL)
1914
399
    {
1915
399
      amt = sizeof (struct coff_section_tdata);
1916
399
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1917
399
      if (section->used_by_bfd == NULL)
1918
  /* FIXME: Return error.  */
1919
0
  abort ();
1920
399
    }
1921
1922
399
  if (pei_section_data (abfd, section) == NULL)
1923
399
    {
1924
399
      amt = sizeof (struct pei_section_tdata);
1925
399
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1926
399
      if (coff_section_data (abfd, section)->tdata == NULL)
1927
  /* FIXME: Return error.  */
1928
0
  abort ();
1929
399
    }
1930
399
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1931
399
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1932
1933
399
  section->lma = hdr->s_vaddr;
1934
1935
  /* Check for extended relocs.  */
1936
399
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1937
10
    {
1938
10
      struct external_reloc dst;
1939
10
      struct internal_reloc n;
1940
10
      file_ptr oldpos = bfd_tell (abfd);
1941
10
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1942
1943
10
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1944
0
  return;
1945
10
      if (bfd_read (& dst, relsz, abfd) != relsz)
1946
8
  return;
1947
1948
2
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1949
2
      if (bfd_seek (abfd, oldpos, 0) != 0)
1950
0
  return;
1951
2
      if (n.r_vaddr < 0x10000)
1952
0
  {
1953
0
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1954
0
    bfd_set_error (bfd_error_bad_value);
1955
0
    return;
1956
0
  }
1957
2
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1958
2
      section->rel_filepos += relsz;
1959
2
    }
1960
389
  else if (hdr->s_nreloc == 0xffff)
1961
0
    _bfd_error_handler
1962
0
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1963
0
       abfd);
1964
399
}
pe-arm-wince.c:coff_set_alignment_hook
Line
Count
Source
1880
4
{
1881
4
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1882
4
  size_t amt;
1883
4
  unsigned int alignment_power_const
1884
4
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1885
1886
4
  switch (alignment_power_const)
1887
4
    {
1888
0
    case IMAGE_SCN_ALIGN_8192BYTES:
1889
0
    case IMAGE_SCN_ALIGN_4096BYTES:
1890
0
    case IMAGE_SCN_ALIGN_2048BYTES:
1891
0
    case IMAGE_SCN_ALIGN_1024BYTES:
1892
0
    case IMAGE_SCN_ALIGN_512BYTES:
1893
0
    case IMAGE_SCN_ALIGN_256BYTES:
1894
0
    case IMAGE_SCN_ALIGN_128BYTES:
1895
0
    case IMAGE_SCN_ALIGN_64BYTES:
1896
0
    case IMAGE_SCN_ALIGN_32BYTES:
1897
0
    case IMAGE_SCN_ALIGN_16BYTES:
1898
0
    case IMAGE_SCN_ALIGN_8BYTES:
1899
0
    case IMAGE_SCN_ALIGN_4BYTES:
1900
0
    case IMAGE_SCN_ALIGN_2BYTES:
1901
0
    case IMAGE_SCN_ALIGN_1BYTES:
1902
0
      section->alignment_power
1903
0
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1904
0
      break;
1905
4
    default:
1906
4
      break;
1907
4
    }
1908
1909
  /* In a PE image file, the s_paddr field holds the virtual size of a
1910
     section, while the s_size field holds the raw size.  We also keep
1911
     the original section flag value, since not every bit can be
1912
     mapped onto a generic BFD section bit.  */
1913
4
  if (coff_section_data (abfd, section) == NULL)
1914
4
    {
1915
4
      amt = sizeof (struct coff_section_tdata);
1916
4
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1917
4
      if (section->used_by_bfd == NULL)
1918
  /* FIXME: Return error.  */
1919
0
  abort ();
1920
4
    }
1921
1922
4
  if (pei_section_data (abfd, section) == NULL)
1923
4
    {
1924
4
      amt = sizeof (struct pei_section_tdata);
1925
4
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1926
4
      if (coff_section_data (abfd, section)->tdata == NULL)
1927
  /* FIXME: Return error.  */
1928
0
  abort ();
1929
4
    }
1930
4
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1931
4
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1932
1933
4
  section->lma = hdr->s_vaddr;
1934
1935
  /* Check for extended relocs.  */
1936
4
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1937
4
    {
1938
4
      struct external_reloc dst;
1939
4
      struct internal_reloc n;
1940
4
      file_ptr oldpos = bfd_tell (abfd);
1941
4
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1942
1943
4
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1944
0
  return;
1945
4
      if (bfd_read (& dst, relsz, abfd) != relsz)
1946
3
  return;
1947
1948
1
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1949
1
      if (bfd_seek (abfd, oldpos, 0) != 0)
1950
0
  return;
1951
1
      if (n.r_vaddr < 0x10000)
1952
0
  {
1953
0
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1954
0
    bfd_set_error (bfd_error_bad_value);
1955
0
    return;
1956
0
  }
1957
1
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1958
1
      section->rel_filepos += relsz;
1959
1
    }
1960
0
  else if (hdr->s_nreloc == 0xffff)
1961
0
    _bfd_error_handler
1962
0
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1963
0
       abfd);
1964
4
}
pe-arm.c:coff_set_alignment_hook
Line
Count
Source
1880
4
{
1881
4
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1882
4
  size_t amt;
1883
4
  unsigned int alignment_power_const
1884
4
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1885
1886
4
  switch (alignment_power_const)
1887
4
    {
1888
0
    case IMAGE_SCN_ALIGN_8192BYTES:
1889
0
    case IMAGE_SCN_ALIGN_4096BYTES:
1890
0
    case IMAGE_SCN_ALIGN_2048BYTES:
1891
0
    case IMAGE_SCN_ALIGN_1024BYTES:
1892
0
    case IMAGE_SCN_ALIGN_512BYTES:
1893
0
    case IMAGE_SCN_ALIGN_256BYTES:
1894
0
    case IMAGE_SCN_ALIGN_128BYTES:
1895
0
    case IMAGE_SCN_ALIGN_64BYTES:
1896
0
    case IMAGE_SCN_ALIGN_32BYTES:
1897
0
    case IMAGE_SCN_ALIGN_16BYTES:
1898
0
    case IMAGE_SCN_ALIGN_8BYTES:
1899
0
    case IMAGE_SCN_ALIGN_4BYTES:
1900
0
    case IMAGE_SCN_ALIGN_2BYTES:
1901
0
    case IMAGE_SCN_ALIGN_1BYTES:
1902
0
      section->alignment_power
1903
0
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1904
0
      break;
1905
4
    default:
1906
4
      break;
1907
4
    }
1908
1909
  /* In a PE image file, the s_paddr field holds the virtual size of a
1910
     section, while the s_size field holds the raw size.  We also keep
1911
     the original section flag value, since not every bit can be
1912
     mapped onto a generic BFD section bit.  */
1913
4
  if (coff_section_data (abfd, section) == NULL)
1914
4
    {
1915
4
      amt = sizeof (struct coff_section_tdata);
1916
4
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1917
4
      if (section->used_by_bfd == NULL)
1918
  /* FIXME: Return error.  */
1919
0
  abort ();
1920
4
    }
1921
1922
4
  if (pei_section_data (abfd, section) == NULL)
1923
4
    {
1924
4
      amt = sizeof (struct pei_section_tdata);
1925
4
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1926
4
      if (coff_section_data (abfd, section)->tdata == NULL)
1927
  /* FIXME: Return error.  */
1928
0
  abort ();
1929
4
    }
1930
4
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1931
4
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1932
1933
4
  section->lma = hdr->s_vaddr;
1934
1935
  /* Check for extended relocs.  */
1936
4
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1937
4
    {
1938
4
      struct external_reloc dst;
1939
4
      struct internal_reloc n;
1940
4
      file_ptr oldpos = bfd_tell (abfd);
1941
4
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1942
1943
4
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1944
0
  return;
1945
4
      if (bfd_read (& dst, relsz, abfd) != relsz)
1946
3
  return;
1947
1948
1
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1949
1
      if (bfd_seek (abfd, oldpos, 0) != 0)
1950
0
  return;
1951
1
      if (n.r_vaddr < 0x10000)
1952
0
  {
1953
0
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1954
0
    bfd_set_error (bfd_error_bad_value);
1955
0
    return;
1956
0
  }
1957
1
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1958
1
      section->rel_filepos += relsz;
1959
1
    }
1960
0
  else if (hdr->s_nreloc == 0xffff)
1961
0
    _bfd_error_handler
1962
0
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1963
0
       abfd);
1964
4
}
pe-i386.c:coff_set_alignment_hook
Line
Count
Source
1880
1.03k
{
1881
1.03k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1882
1.03k
  size_t amt;
1883
1.03k
  unsigned int alignment_power_const
1884
1.03k
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1885
1886
1.03k
  switch (alignment_power_const)
1887
1.03k
    {
1888
133
    case IMAGE_SCN_ALIGN_8192BYTES:
1889
135
    case IMAGE_SCN_ALIGN_4096BYTES:
1890
231
    case IMAGE_SCN_ALIGN_2048BYTES:
1891
237
    case IMAGE_SCN_ALIGN_1024BYTES:
1892
245
    case IMAGE_SCN_ALIGN_512BYTES:
1893
245
    case IMAGE_SCN_ALIGN_256BYTES:
1894
253
    case IMAGE_SCN_ALIGN_128BYTES:
1895
257
    case IMAGE_SCN_ALIGN_64BYTES:
1896
257
    case IMAGE_SCN_ALIGN_32BYTES:
1897
257
    case IMAGE_SCN_ALIGN_16BYTES:
1898
274
    case IMAGE_SCN_ALIGN_8BYTES:
1899
274
    case IMAGE_SCN_ALIGN_4BYTES:
1900
281
    case IMAGE_SCN_ALIGN_2BYTES:
1901
285
    case IMAGE_SCN_ALIGN_1BYTES:
1902
285
      section->alignment_power
1903
285
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1904
285
      break;
1905
748
    default:
1906
748
      break;
1907
1.03k
    }
1908
1909
  /* In a PE image file, the s_paddr field holds the virtual size of a
1910
     section, while the s_size field holds the raw size.  We also keep
1911
     the original section flag value, since not every bit can be
1912
     mapped onto a generic BFD section bit.  */
1913
1.03k
  if (coff_section_data (abfd, section) == NULL)
1914
1.03k
    {
1915
1.03k
      amt = sizeof (struct coff_section_tdata);
1916
1.03k
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1917
1.03k
      if (section->used_by_bfd == NULL)
1918
  /* FIXME: Return error.  */
1919
0
  abort ();
1920
1.03k
    }
1921
1922
1.03k
  if (pei_section_data (abfd, section) == NULL)
1923
1.03k
    {
1924
1.03k
      amt = sizeof (struct pei_section_tdata);
1925
1.03k
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1926
1.03k
      if (coff_section_data (abfd, section)->tdata == NULL)
1927
  /* FIXME: Return error.  */
1928
0
  abort ();
1929
1.03k
    }
1930
1.03k
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1931
1.03k
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1932
1933
1.03k
  section->lma = hdr->s_vaddr;
1934
1935
  /* Check for extended relocs.  */
1936
1.03k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1937
82
    {
1938
82
      struct external_reloc dst;
1939
82
      struct internal_reloc n;
1940
82
      file_ptr oldpos = bfd_tell (abfd);
1941
82
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1942
1943
82
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1944
0
  return;
1945
82
      if (bfd_read (& dst, relsz, abfd) != relsz)
1946
72
  return;
1947
1948
10
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1949
10
      if (bfd_seek (abfd, oldpos, 0) != 0)
1950
0
  return;
1951
10
      if (n.r_vaddr < 0x10000)
1952
0
  {
1953
0
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1954
0
    bfd_set_error (bfd_error_bad_value);
1955
0
    return;
1956
0
  }
1957
10
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1958
10
      section->rel_filepos += relsz;
1959
10
    }
1960
951
  else if (hdr->s_nreloc == 0xffff)
1961
1
    _bfd_error_handler
1962
1
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1963
1
       abfd);
1964
1.03k
}
pe-mcore.c:coff_set_alignment_hook
Line
Count
Source
1880
200
{
1881
200
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1882
200
  size_t amt;
1883
200
  unsigned int alignment_power_const
1884
200
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1885
1886
200
  switch (alignment_power_const)
1887
200
    {
1888
0
    case IMAGE_SCN_ALIGN_8192BYTES:
1889
0
    case IMAGE_SCN_ALIGN_4096BYTES:
1890
0
    case IMAGE_SCN_ALIGN_2048BYTES:
1891
0
    case IMAGE_SCN_ALIGN_1024BYTES:
1892
0
    case IMAGE_SCN_ALIGN_512BYTES:
1893
0
    case IMAGE_SCN_ALIGN_256BYTES:
1894
0
    case IMAGE_SCN_ALIGN_128BYTES:
1895
1
    case IMAGE_SCN_ALIGN_64BYTES:
1896
1
    case IMAGE_SCN_ALIGN_32BYTES:
1897
1
    case IMAGE_SCN_ALIGN_16BYTES:
1898
1
    case IMAGE_SCN_ALIGN_8BYTES:
1899
1
    case IMAGE_SCN_ALIGN_4BYTES:
1900
2
    case IMAGE_SCN_ALIGN_2BYTES:
1901
2
    case IMAGE_SCN_ALIGN_1BYTES:
1902
2
      section->alignment_power
1903
2
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1904
2
      break;
1905
198
    default:
1906
198
      break;
1907
200
    }
1908
1909
  /* In a PE image file, the s_paddr field holds the virtual size of a
1910
     section, while the s_size field holds the raw size.  We also keep
1911
     the original section flag value, since not every bit can be
1912
     mapped onto a generic BFD section bit.  */
1913
200
  if (coff_section_data (abfd, section) == NULL)
1914
200
    {
1915
200
      amt = sizeof (struct coff_section_tdata);
1916
200
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1917
200
      if (section->used_by_bfd == NULL)
1918
  /* FIXME: Return error.  */
1919
0
  abort ();
1920
200
    }
1921
1922
200
  if (pei_section_data (abfd, section) == NULL)
1923
200
    {
1924
200
      amt = sizeof (struct pei_section_tdata);
1925
200
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1926
200
      if (coff_section_data (abfd, section)->tdata == NULL)
1927
  /* FIXME: Return error.  */
1928
0
  abort ();
1929
200
    }
1930
200
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1931
200
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1932
1933
200
  section->lma = hdr->s_vaddr;
1934
1935
  /* Check for extended relocs.  */
1936
200
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1937
6
    {
1938
6
      struct external_reloc dst;
1939
6
      struct internal_reloc n;
1940
6
      file_ptr oldpos = bfd_tell (abfd);
1941
6
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1942
1943
6
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1944
0
  return;
1945
6
      if (bfd_read (& dst, relsz, abfd) != relsz)
1946
5
  return;
1947
1948
1
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1949
1
      if (bfd_seek (abfd, oldpos, 0) != 0)
1950
0
  return;
1951
1
      if (n.r_vaddr < 0x10000)
1952
0
  {
1953
0
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1954
0
    bfd_set_error (bfd_error_bad_value);
1955
0
    return;
1956
0
  }
1957
1
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1958
1
      section->rel_filepos += relsz;
1959
1
    }
1960
194
  else if (hdr->s_nreloc == 0xffff)
1961
0
    _bfd_error_handler
1962
0
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1963
0
       abfd);
1964
200
}
pe-sh.c:coff_set_alignment_hook
Line
Count
Source
1880
4.81k
{
1881
4.81k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1882
4.81k
  size_t amt;
1883
4.81k
  unsigned int alignment_power_const
1884
4.81k
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1885
1886
4.81k
  switch (alignment_power_const)
1887
4.81k
    {
1888
0
    case IMAGE_SCN_ALIGN_8192BYTES:
1889
0
    case IMAGE_SCN_ALIGN_4096BYTES:
1890
59
    case IMAGE_SCN_ALIGN_2048BYTES:
1891
164
    case IMAGE_SCN_ALIGN_1024BYTES:
1892
164
    case IMAGE_SCN_ALIGN_512BYTES:
1893
195
    case IMAGE_SCN_ALIGN_256BYTES:
1894
1.31k
    case IMAGE_SCN_ALIGN_128BYTES:
1895
1.42k
    case IMAGE_SCN_ALIGN_64BYTES:
1896
1.42k
    case IMAGE_SCN_ALIGN_32BYTES:
1897
1.42k
    case IMAGE_SCN_ALIGN_16BYTES:
1898
1.85k
    case IMAGE_SCN_ALIGN_8BYTES:
1899
1.85k
    case IMAGE_SCN_ALIGN_4BYTES:
1900
2.16k
    case IMAGE_SCN_ALIGN_2BYTES:
1901
2.16k
    case IMAGE_SCN_ALIGN_1BYTES:
1902
2.16k
      section->alignment_power
1903
2.16k
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1904
2.16k
      break;
1905
2.65k
    default:
1906
2.65k
      break;
1907
4.81k
    }
1908
1909
  /* In a PE image file, the s_paddr field holds the virtual size of a
1910
     section, while the s_size field holds the raw size.  We also keep
1911
     the original section flag value, since not every bit can be
1912
     mapped onto a generic BFD section bit.  */
1913
4.81k
  if (coff_section_data (abfd, section) == NULL)
1914
4.81k
    {
1915
4.81k
      amt = sizeof (struct coff_section_tdata);
1916
4.81k
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1917
4.81k
      if (section->used_by_bfd == NULL)
1918
  /* FIXME: Return error.  */
1919
0
  abort ();
1920
4.81k
    }
1921
1922
4.81k
  if (pei_section_data (abfd, section) == NULL)
1923
4.81k
    {
1924
4.81k
      amt = sizeof (struct pei_section_tdata);
1925
4.81k
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1926
4.81k
      if (coff_section_data (abfd, section)->tdata == NULL)
1927
  /* FIXME: Return error.  */
1928
0
  abort ();
1929
4.81k
    }
1930
4.81k
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1931
4.81k
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1932
1933
4.81k
  section->lma = hdr->s_vaddr;
1934
1935
  /* Check for extended relocs.  */
1936
4.81k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1937
922
    {
1938
922
      struct external_reloc dst;
1939
922
      struct internal_reloc n;
1940
922
      file_ptr oldpos = bfd_tell (abfd);
1941
922
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1942
1943
922
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1944
0
  return;
1945
922
      if (bfd_read (& dst, relsz, abfd) != relsz)
1946
861
  return;
1947
1948
61
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1949
61
      if (bfd_seek (abfd, oldpos, 0) != 0)
1950
0
  return;
1951
61
      if (n.r_vaddr < 0x10000)
1952
0
  {
1953
0
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1954
0
    bfd_set_error (bfd_error_bad_value);
1955
0
    return;
1956
0
  }
1957
61
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1958
61
      section->rel_filepos += relsz;
1959
61
    }
1960
3.89k
  else if (hdr->s_nreloc == 0xffff)
1961
1
    _bfd_error_handler
1962
1
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1963
1
       abfd);
1964
4.81k
}
pei-arm-wince.c:coff_set_alignment_hook
Line
Count
Source
1880
4.11k
{
1881
4.11k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1882
4.11k
  size_t amt;
1883
4.11k
  unsigned int alignment_power_const
1884
4.11k
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1885
1886
4.11k
  switch (alignment_power_const)
1887
4.11k
    {
1888
0
    case IMAGE_SCN_ALIGN_8192BYTES:
1889
0
    case IMAGE_SCN_ALIGN_4096BYTES:
1890
0
    case IMAGE_SCN_ALIGN_2048BYTES:
1891
0
    case IMAGE_SCN_ALIGN_1024BYTES:
1892
0
    case IMAGE_SCN_ALIGN_512BYTES:
1893
0
    case IMAGE_SCN_ALIGN_256BYTES:
1894
0
    case IMAGE_SCN_ALIGN_128BYTES:
1895
0
    case IMAGE_SCN_ALIGN_64BYTES:
1896
0
    case IMAGE_SCN_ALIGN_32BYTES:
1897
1
    case IMAGE_SCN_ALIGN_16BYTES:
1898
1
    case IMAGE_SCN_ALIGN_8BYTES:
1899
1
    case IMAGE_SCN_ALIGN_4BYTES:
1900
2
    case IMAGE_SCN_ALIGN_2BYTES:
1901
2
    case IMAGE_SCN_ALIGN_1BYTES:
1902
2
      section->alignment_power
1903
2
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1904
2
      break;
1905
4.11k
    default:
1906
4.11k
      break;
1907
4.11k
    }
1908
1909
  /* In a PE image file, the s_paddr field holds the virtual size of a
1910
     section, while the s_size field holds the raw size.  We also keep
1911
     the original section flag value, since not every bit can be
1912
     mapped onto a generic BFD section bit.  */
1913
4.11k
  if (coff_section_data (abfd, section) == NULL)
1914
4.11k
    {
1915
4.11k
      amt = sizeof (struct coff_section_tdata);
1916
4.11k
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1917
4.11k
      if (section->used_by_bfd == NULL)
1918
  /* FIXME: Return error.  */
1919
0
  abort ();
1920
4.11k
    }
1921
1922
4.11k
  if (pei_section_data (abfd, section) == NULL)
1923
4.11k
    {
1924
4.11k
      amt = sizeof (struct pei_section_tdata);
1925
4.11k
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1926
4.11k
      if (coff_section_data (abfd, section)->tdata == NULL)
1927
  /* FIXME: Return error.  */
1928
0
  abort ();
1929
4.11k
    }
1930
4.11k
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1931
4.11k
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1932
1933
4.11k
  section->lma = hdr->s_vaddr;
1934
1935
  /* Check for extended relocs.  */
1936
4.11k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1937
2
    {
1938
2
      struct external_reloc dst;
1939
2
      struct internal_reloc n;
1940
2
      file_ptr oldpos = bfd_tell (abfd);
1941
2
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1942
1943
2
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1944
0
  return;
1945
2
      if (bfd_read (& dst, relsz, abfd) != relsz)
1946
2
  return;
1947
1948
0
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1949
0
      if (bfd_seek (abfd, oldpos, 0) != 0)
1950
0
  return;
1951
0
      if (n.r_vaddr < 0x10000)
1952
0
  {
1953
0
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1954
0
    bfd_set_error (bfd_error_bad_value);
1955
0
    return;
1956
0
  }
1957
0
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1958
0
      section->rel_filepos += relsz;
1959
0
    }
1960
4.11k
  else if (hdr->s_nreloc == 0xffff)
1961
0
    _bfd_error_handler
1962
0
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1963
0
       abfd);
1964
4.11k
}
pei-arm.c:coff_set_alignment_hook
Line
Count
Source
1880
21
{
1881
21
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1882
21
  size_t amt;
1883
21
  unsigned int alignment_power_const
1884
21
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1885
1886
21
  switch (alignment_power_const)
1887
21
    {
1888
0
    case IMAGE_SCN_ALIGN_8192BYTES:
1889
0
    case IMAGE_SCN_ALIGN_4096BYTES:
1890
0
    case IMAGE_SCN_ALIGN_2048BYTES:
1891
0
    case IMAGE_SCN_ALIGN_1024BYTES:
1892
0
    case IMAGE_SCN_ALIGN_512BYTES:
1893
0
    case IMAGE_SCN_ALIGN_256BYTES:
1894
1
    case IMAGE_SCN_ALIGN_128BYTES:
1895
1
    case IMAGE_SCN_ALIGN_64BYTES:
1896
1
    case IMAGE_SCN_ALIGN_32BYTES:
1897
1
    case IMAGE_SCN_ALIGN_16BYTES:
1898
1
    case IMAGE_SCN_ALIGN_8BYTES:
1899
1
    case IMAGE_SCN_ALIGN_4BYTES:
1900
1
    case IMAGE_SCN_ALIGN_2BYTES:
1901
1
    case IMAGE_SCN_ALIGN_1BYTES:
1902
1
      section->alignment_power
1903
1
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1904
1
      break;
1905
20
    default:
1906
20
      break;
1907
21
    }
1908
1909
  /* In a PE image file, the s_paddr field holds the virtual size of a
1910
     section, while the s_size field holds the raw size.  We also keep
1911
     the original section flag value, since not every bit can be
1912
     mapped onto a generic BFD section bit.  */
1913
21
  if (coff_section_data (abfd, section) == NULL)
1914
21
    {
1915
21
      amt = sizeof (struct coff_section_tdata);
1916
21
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1917
21
      if (section->used_by_bfd == NULL)
1918
  /* FIXME: Return error.  */
1919
0
  abort ();
1920
21
    }
1921
1922
21
  if (pei_section_data (abfd, section) == NULL)
1923
21
    {
1924
21
      amt = sizeof (struct pei_section_tdata);
1925
21
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1926
21
      if (coff_section_data (abfd, section)->tdata == NULL)
1927
  /* FIXME: Return error.  */
1928
0
  abort ();
1929
21
    }
1930
21
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1931
21
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1932
1933
21
  section->lma = hdr->s_vaddr;
1934
1935
  /* Check for extended relocs.  */
1936
21
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1937
1
    {
1938
1
      struct external_reloc dst;
1939
1
      struct internal_reloc n;
1940
1
      file_ptr oldpos = bfd_tell (abfd);
1941
1
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1942
1943
1
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1944
0
  return;
1945
1
      if (bfd_read (& dst, relsz, abfd) != relsz)
1946
1
  return;
1947
1948
0
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1949
0
      if (bfd_seek (abfd, oldpos, 0) != 0)
1950
0
  return;
1951
0
      if (n.r_vaddr < 0x10000)
1952
0
  {
1953
0
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1954
0
    bfd_set_error (bfd_error_bad_value);
1955
0
    return;
1956
0
  }
1957
0
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1958
0
      section->rel_filepos += relsz;
1959
0
    }
1960
20
  else if (hdr->s_nreloc == 0xffff)
1961
0
    _bfd_error_handler
1962
0
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1963
0
       abfd);
1964
21
}
pei-mcore.c:coff_set_alignment_hook
Line
Count
Source
1880
10
{
1881
10
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1882
10
  size_t amt;
1883
10
  unsigned int alignment_power_const
1884
10
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1885
1886
10
  switch (alignment_power_const)
1887
10
    {
1888
0
    case IMAGE_SCN_ALIGN_8192BYTES:
1889
0
    case IMAGE_SCN_ALIGN_4096BYTES:
1890
0
    case IMAGE_SCN_ALIGN_2048BYTES:
1891
0
    case IMAGE_SCN_ALIGN_1024BYTES:
1892
0
    case IMAGE_SCN_ALIGN_512BYTES:
1893
0
    case IMAGE_SCN_ALIGN_256BYTES:
1894
0
    case IMAGE_SCN_ALIGN_128BYTES:
1895
0
    case IMAGE_SCN_ALIGN_64BYTES:
1896
0
    case IMAGE_SCN_ALIGN_32BYTES:
1897
4
    case IMAGE_SCN_ALIGN_16BYTES:
1898
7
    case IMAGE_SCN_ALIGN_8BYTES:
1899
7
    case IMAGE_SCN_ALIGN_4BYTES:
1900
7
    case IMAGE_SCN_ALIGN_2BYTES:
1901
7
    case IMAGE_SCN_ALIGN_1BYTES:
1902
7
      section->alignment_power
1903
7
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1904
7
      break;
1905
3
    default:
1906
3
      break;
1907
10
    }
1908
1909
  /* In a PE image file, the s_paddr field holds the virtual size of a
1910
     section, while the s_size field holds the raw size.  We also keep
1911
     the original section flag value, since not every bit can be
1912
     mapped onto a generic BFD section bit.  */
1913
10
  if (coff_section_data (abfd, section) == NULL)
1914
10
    {
1915
10
      amt = sizeof (struct coff_section_tdata);
1916
10
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1917
10
      if (section->used_by_bfd == NULL)
1918
  /* FIXME: Return error.  */
1919
0
  abort ();
1920
10
    }
1921
1922
10
  if (pei_section_data (abfd, section) == NULL)
1923
10
    {
1924
10
      amt = sizeof (struct pei_section_tdata);
1925
10
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1926
10
      if (coff_section_data (abfd, section)->tdata == NULL)
1927
  /* FIXME: Return error.  */
1928
0
  abort ();
1929
10
    }
1930
10
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1931
10
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1932
1933
10
  section->lma = hdr->s_vaddr;
1934
1935
  /* Check for extended relocs.  */
1936
10
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1937
1
    {
1938
1
      struct external_reloc dst;
1939
1
      struct internal_reloc n;
1940
1
      file_ptr oldpos = bfd_tell (abfd);
1941
1
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1942
1943
1
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1944
0
  return;
1945
1
      if (bfd_read (& dst, relsz, abfd) != relsz)
1946
1
  return;
1947
1948
0
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1949
0
      if (bfd_seek (abfd, oldpos, 0) != 0)
1950
0
  return;
1951
0
      if (n.r_vaddr < 0x10000)
1952
0
  {
1953
0
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1954
0
    bfd_set_error (bfd_error_bad_value);
1955
0
    return;
1956
0
  }
1957
0
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1958
0
      section->rel_filepos += relsz;
1959
0
    }
1960
9
  else if (hdr->s_nreloc == 0xffff)
1961
0
    _bfd_error_handler
1962
0
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1963
0
       abfd);
1964
10
}
pei-sh.c:coff_set_alignment_hook
Line
Count
Source
1880
1.52k
{
1881
1.52k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1882
1.52k
  size_t amt;
1883
1.52k
  unsigned int alignment_power_const
1884
1.52k
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1885
1886
1.52k
  switch (alignment_power_const)
1887
1.52k
    {
1888
123
    case IMAGE_SCN_ALIGN_8192BYTES:
1889
123
    case IMAGE_SCN_ALIGN_4096BYTES:
1890
123
    case IMAGE_SCN_ALIGN_2048BYTES:
1891
123
    case IMAGE_SCN_ALIGN_1024BYTES:
1892
129
    case IMAGE_SCN_ALIGN_512BYTES:
1893
129
    case IMAGE_SCN_ALIGN_256BYTES:
1894
130
    case IMAGE_SCN_ALIGN_128BYTES:
1895
130
    case IMAGE_SCN_ALIGN_64BYTES:
1896
274
    case IMAGE_SCN_ALIGN_32BYTES:
1897
274
    case IMAGE_SCN_ALIGN_16BYTES:
1898
274
    case IMAGE_SCN_ALIGN_8BYTES:
1899
274
    case IMAGE_SCN_ALIGN_4BYTES:
1900
274
    case IMAGE_SCN_ALIGN_2BYTES:
1901
274
    case IMAGE_SCN_ALIGN_1BYTES:
1902
274
      section->alignment_power
1903
274
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1904
274
      break;
1905
1.24k
    default:
1906
1.24k
      break;
1907
1.52k
    }
1908
1909
  /* In a PE image file, the s_paddr field holds the virtual size of a
1910
     section, while the s_size field holds the raw size.  We also keep
1911
     the original section flag value, since not every bit can be
1912
     mapped onto a generic BFD section bit.  */
1913
1.52k
  if (coff_section_data (abfd, section) == NULL)
1914
1.52k
    {
1915
1.52k
      amt = sizeof (struct coff_section_tdata);
1916
1.52k
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1917
1.52k
      if (section->used_by_bfd == NULL)
1918
  /* FIXME: Return error.  */
1919
0
  abort ();
1920
1.52k
    }
1921
1922
1.52k
  if (pei_section_data (abfd, section) == NULL)
1923
1.52k
    {
1924
1.52k
      amt = sizeof (struct pei_section_tdata);
1925
1.52k
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1926
1.52k
      if (coff_section_data (abfd, section)->tdata == NULL)
1927
  /* FIXME: Return error.  */
1928
0
  abort ();
1929
1.52k
    }
1930
1.52k
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1931
1.52k
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1932
1933
1.52k
  section->lma = hdr->s_vaddr;
1934
1935
  /* Check for extended relocs.  */
1936
1.52k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1937
7
    {
1938
7
      struct external_reloc dst;
1939
7
      struct internal_reloc n;
1940
7
      file_ptr oldpos = bfd_tell (abfd);
1941
7
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1942
1943
7
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1944
0
  return;
1945
7
      if (bfd_read (& dst, relsz, abfd) != relsz)
1946
6
  return;
1947
1948
1
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1949
1
      if (bfd_seek (abfd, oldpos, 0) != 0)
1950
0
  return;
1951
1
      if (n.r_vaddr < 0x10000)
1952
0
  {
1953
0
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1954
0
    bfd_set_error (bfd_error_bad_value);
1955
0
    return;
1956
0
  }
1957
1
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1958
1
      section->rel_filepos += relsz;
1959
1
    }
1960
1.51k
  else if (hdr->s_nreloc == 0xffff)
1961
0
    _bfd_error_handler
1962
0
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1963
0
       abfd);
1964
1.52k
}
1965
#undef ALIGN_SET
1966
#undef ELIFALIGN_SET
1967
1968
#else /* ! COFF_WITH_PE */
1969
#ifdef RS6000COFF_C
1970
1971
/* We grossly abuse this function to handle XCOFF overflow headers.
1972
   When we see one, we correct the reloc and line number counts in the
1973
   real header, and remove the section we just created.  */
1974
1975
static void
1976
coff_set_alignment_hook (bfd *abfd, asection *section, void * scnhdr)
1977
400k
{
1978
400k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1979
400k
  asection *real_sec;
1980
1981
400k
  if ((hdr->s_flags & STYP_OVRFLO) == 0)
1982
265k
    return;
1983
1984
135k
  real_sec = coff_section_from_bfd_index (abfd, (int) hdr->s_nreloc);
1985
135k
  if (real_sec == NULL)
1986
0
    return;
1987
1988
135k
  real_sec->reloc_count = hdr->s_paddr;
1989
135k
  real_sec->lineno_count = hdr->s_vaddr;
1990
1991
135k
  if (!bfd_section_removed_from_list (abfd, section))
1992
135k
    {
1993
135k
      bfd_section_list_remove (abfd, section);
1994
135k
      --abfd->section_count;
1995
135k
    }
1996
135k
}
coff64-rs6000.c:coff_set_alignment_hook
Line
Count
Source
1977
180k
{
1978
180k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1979
180k
  asection *real_sec;
1980
1981
180k
  if ((hdr->s_flags & STYP_OVRFLO) == 0)
1982
157k
    return;
1983
1984
22.4k
  real_sec = coff_section_from_bfd_index (abfd, (int) hdr->s_nreloc);
1985
22.4k
  if (real_sec == NULL)
1986
0
    return;
1987
1988
22.4k
  real_sec->reloc_count = hdr->s_paddr;
1989
22.4k
  real_sec->lineno_count = hdr->s_vaddr;
1990
1991
22.4k
  if (!bfd_section_removed_from_list (abfd, section))
1992
22.4k
    {
1993
22.4k
      bfd_section_list_remove (abfd, section);
1994
22.4k
      --abfd->section_count;
1995
22.4k
    }
1996
22.4k
}
coff-rs6000.c:coff_set_alignment_hook
Line
Count
Source
1977
220k
{
1978
220k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1979
220k
  asection *real_sec;
1980
1981
220k
  if ((hdr->s_flags & STYP_OVRFLO) == 0)
1982
107k
    return;
1983
1984
113k
  real_sec = coff_section_from_bfd_index (abfd, (int) hdr->s_nreloc);
1985
113k
  if (real_sec == NULL)
1986
0
    return;
1987
1988
113k
  real_sec->reloc_count = hdr->s_paddr;
1989
113k
  real_sec->lineno_count = hdr->s_vaddr;
1990
1991
113k
  if (!bfd_section_removed_from_list (abfd, section))
1992
113k
    {
1993
113k
      bfd_section_list_remove (abfd, section);
1994
113k
      --abfd->section_count;
1995
113k
    }
1996
113k
}
1997
1998
#else /* ! RS6000COFF_C */
1999
#if defined (COFF_GO32_EXE) || defined (COFF_GO32)
2000
2001
static void
2002
coff_set_alignment_hook (bfd * abfd, asection * section, void * scnhdr)
2003
100k
{
2004
100k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
2005
2006
  /* Check for extended relocs.  */
2007
100k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
2008
31.7k
    {
2009
31.7k
      struct external_reloc dst;
2010
31.7k
      struct internal_reloc n;
2011
31.7k
      const file_ptr oldpos = bfd_tell (abfd);
2012
31.7k
      const bfd_size_type relsz = bfd_coff_relsz (abfd);
2013
2014
31.7k
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
2015
0
  return;
2016
31.7k
      if (bfd_read (& dst, relsz, abfd) != relsz)
2017
29.2k
  return;
2018
2019
2.51k
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
2020
2.51k
      if (bfd_seek (abfd, oldpos, 0) != 0)
2021
0
  return;
2022
2.51k
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
2023
2.51k
      section->rel_filepos += relsz;
2024
2.51k
    }
2025
68.8k
  else if (hdr->s_nreloc == 0xffff)
2026
610
    _bfd_error_handler
2027
610
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
2028
610
       abfd);
2029
100k
}
coff-go32.c:coff_set_alignment_hook
Line
Count
Source
2003
7.68k
{
2004
7.68k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
2005
2006
  /* Check for extended relocs.  */
2007
7.68k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
2008
1.77k
    {
2009
1.77k
      struct external_reloc dst;
2010
1.77k
      struct internal_reloc n;
2011
1.77k
      const file_ptr oldpos = bfd_tell (abfd);
2012
1.77k
      const bfd_size_type relsz = bfd_coff_relsz (abfd);
2013
2014
1.77k
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
2015
0
  return;
2016
1.77k
      if (bfd_read (& dst, relsz, abfd) != relsz)
2017
1.58k
  return;
2018
2019
196
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
2020
196
      if (bfd_seek (abfd, oldpos, 0) != 0)
2021
0
  return;
2022
196
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
2023
196
      section->rel_filepos += relsz;
2024
196
    }
2025
5.90k
  else if (hdr->s_nreloc == 0xffff)
2026
55
    _bfd_error_handler
2027
55
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
2028
55
       abfd);
2029
7.68k
}
coff-stgo32.c:coff_set_alignment_hook
Line
Count
Source
2003
92.9k
{
2004
92.9k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
2005
2006
  /* Check for extended relocs.  */
2007
92.9k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
2008
29.9k
    {
2009
29.9k
      struct external_reloc dst;
2010
29.9k
      struct internal_reloc n;
2011
29.9k
      const file_ptr oldpos = bfd_tell (abfd);
2012
29.9k
      const bfd_size_type relsz = bfd_coff_relsz (abfd);
2013
2014
29.9k
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
2015
0
  return;
2016
29.9k
      if (bfd_read (& dst, relsz, abfd) != relsz)
2017
27.6k
  return;
2018
2019
2.32k
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
2020
2.32k
      if (bfd_seek (abfd, oldpos, 0) != 0)
2021
0
  return;
2022
2.32k
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
2023
2.32k
      section->rel_filepos += relsz;
2024
2.32k
    }
2025
62.9k
  else if (hdr->s_nreloc == 0xffff)
2026
555
    _bfd_error_handler
2027
555
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
2028
555
       abfd);
2029
92.9k
}
2030
2031
#else /* ! COFF_GO32_EXE && ! COFF_GO32 */
2032
2033
static void
2034
coff_set_alignment_hook (bfd *abfd ATTRIBUTE_UNUSED,
2035
       asection *section ATTRIBUTE_UNUSED,
2036
       void *scnhdr ATTRIBUTE_UNUSED)
2037
580k
{
2038
580k
}
coff-x86_64.c:coff_set_alignment_hook
Line
Count
Source
2037
20.3k
{
2038
20.3k
}
cf-i386lynx.c:coff_set_alignment_hook
Line
Count
Source
2037
82.1k
{
2038
82.1k
}
coff-i386.c:coff_set_alignment_hook
Line
Count
Source
2037
7.92k
{
2038
7.92k
}
coff-sh.c:coff_set_alignment_hook
Line
Count
Source
2037
360k
{
2038
360k
}
coff-tic30.c:coff_set_alignment_hook
Line
Count
Source
2037
10.6k
{
2038
10.6k
}
coff-z8k.c:coff_set_alignment_hook
Line
Count
Source
2037
98.5k
{
2038
98.5k
}
2039
2040
#endif /* ! COFF_GO32_EXE && ! COFF_GO32 */
2041
#endif /* ! RS6000COFF_C */
2042
#endif /* ! COFF_WITH_PE */
2043
#endif /* ! COFF_ALIGN_IN_SECTION_HEADER */
2044
2045
#ifndef coff_mkobject
2046
2047
static bool
2048
coff_mkobject (bfd * abfd)
2049
3.18k
{
2050
3.18k
  coff_data_type *coff;
2051
3.18k
  size_t amt = sizeof (coff_data_type);
2052
2053
3.18k
  abfd->tdata.coff_obj_data = bfd_zalloc (abfd, amt);
2054
3.18k
  if (abfd->tdata.coff_obj_data == NULL)
2055
0
    return false;
2056
2057
3.18k
  coff = coff_data (abfd);
2058
3.18k
  coff->symbols = NULL;
2059
3.18k
  coff->conversion_table = NULL;
2060
3.18k
  coff->raw_syments = NULL;
2061
3.18k
  coff->relocbase = 0;
2062
3.18k
  coff->local_toc_sym_map = 0;
2063
2064
3.18k
  bfd_coff_long_section_names (abfd)
2065
3.18k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
2066
2067
/*  make_abs_section(abfd);*/
2068
2069
3.18k
  return true;
2070
3.18k
}
coff-x86_64.c:coff_mkobject
Line
Count
Source
2049
153
{
2050
153
  coff_data_type *coff;
2051
153
  size_t amt = sizeof (coff_data_type);
2052
2053
153
  abfd->tdata.coff_obj_data = bfd_zalloc (abfd, amt);
2054
153
  if (abfd->tdata.coff_obj_data == NULL)
2055
0
    return false;
2056
2057
153
  coff = coff_data (abfd);
2058
153
  coff->symbols = NULL;
2059
153
  coff->conversion_table = NULL;
2060
153
  coff->raw_syments = NULL;
2061
153
  coff->relocbase = 0;
2062
153
  coff->local_toc_sym_map = 0;
2063
2064
153
  bfd_coff_long_section_names (abfd)
2065
153
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
2066
2067
/*  make_abs_section(abfd);*/
2068
2069
153
  return true;
2070
153
}
cf-i386lynx.c:coff_mkobject
Line
Count
Source
2049
90
{
2050
90
  coff_data_type *coff;
2051
90
  size_t amt = sizeof (coff_data_type);
2052
2053
90
  abfd->tdata.coff_obj_data = bfd_zalloc (abfd, amt);
2054
90
  if (abfd->tdata.coff_obj_data == NULL)
2055
0
    return false;
2056
2057
90
  coff = coff_data (abfd);
2058
90
  coff->symbols = NULL;
2059
90
  coff->conversion_table = NULL;
2060
90
  coff->raw_syments = NULL;
2061
90
  coff->relocbase = 0;
2062
90
  coff->local_toc_sym_map = 0;
2063
2064
90
  bfd_coff_long_section_names (abfd)
2065
90
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
2066
2067
/*  make_abs_section(abfd);*/
2068
2069
90
  return true;
2070
90
}
coff-i386.c:coff_mkobject
Line
Count
Source
2049
14
{
2050
14
  coff_data_type *coff;
2051
14
  size_t amt = sizeof (coff_data_type);
2052
2053
14
  abfd->tdata.coff_obj_data = bfd_zalloc (abfd, amt);
2054
14
  if (abfd->tdata.coff_obj_data == NULL)
2055
0
    return false;
2056
2057
14
  coff = coff_data (abfd);
2058
14
  coff->symbols = NULL;
2059
14
  coff->conversion_table = NULL;
2060
14
  coff->raw_syments = NULL;
2061
14
  coff->relocbase = 0;
2062
14
  coff->local_toc_sym_map = 0;
2063
2064
14
  bfd_coff_long_section_names (abfd)
2065
14
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
2066
2067
/*  make_abs_section(abfd);*/
2068
2069
14
  return true;
2070
14
}
coff-sh.c:coff_mkobject
Line
Count
Source
2049
2.53k
{
2050
2.53k
  coff_data_type *coff;
2051
2.53k
  size_t amt = sizeof (coff_data_type);
2052
2053
2.53k
  abfd->tdata.coff_obj_data = bfd_zalloc (abfd, amt);
2054
2.53k
  if (abfd->tdata.coff_obj_data == NULL)
2055
0
    return false;
2056
2057
2.53k
  coff = coff_data (abfd);
2058
2.53k
  coff->symbols = NULL;
2059
2.53k
  coff->conversion_table = NULL;
2060
2.53k
  coff->raw_syments = NULL;
2061
2.53k
  coff->relocbase = 0;
2062
2.53k
  coff->local_toc_sym_map = 0;
2063
2064
2.53k
  bfd_coff_long_section_names (abfd)
2065
2.53k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
2066
2067
/*  make_abs_section(abfd);*/
2068
2069
2.53k
  return true;
2070
2.53k
}
coff-tic30.c:coff_mkobject
Line
Count
Source
2049
80
{
2050
80
  coff_data_type *coff;
2051
80
  size_t amt = sizeof (coff_data_type);
2052
2053
80
  abfd->tdata.coff_obj_data = bfd_zalloc (abfd, amt);
2054
80
  if (abfd->tdata.coff_obj_data == NULL)
2055
0
    return false;
2056
2057
80
  coff = coff_data (abfd);
2058
80
  coff->symbols = NULL;
2059
80
  coff->conversion_table = NULL;
2060
80
  coff->raw_syments = NULL;
2061
80
  coff->relocbase = 0;
2062
80
  coff->local_toc_sym_map = 0;
2063
2064
80
  bfd_coff_long_section_names (abfd)
2065
80
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
2066
2067
/*  make_abs_section(abfd);*/
2068
2069
80
  return true;
2070
80
}
Unexecuted instantiation: coff-tic4x.c:coff_mkobject
coff-tic54x.c:coff_mkobject
Line
Count
Source
2049
136
{
2050
136
  coff_data_type *coff;
2051
136
  size_t amt = sizeof (coff_data_type);
2052
2053
136
  abfd->tdata.coff_obj_data = bfd_zalloc (abfd, amt);
2054
136
  if (abfd->tdata.coff_obj_data == NULL)
2055
0
    return false;
2056
2057
136
  coff = coff_data (abfd);
2058
136
  coff->symbols = NULL;
2059
136
  coff->conversion_table = NULL;
2060
136
  coff->raw_syments = NULL;
2061
136
  coff->relocbase = 0;
2062
136
  coff->local_toc_sym_map = 0;
2063
2064
136
  bfd_coff_long_section_names (abfd)
2065
136
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
2066
2067
/*  make_abs_section(abfd);*/
2068
2069
136
  return true;
2070
136
}
coff-z80.c:coff_mkobject
Line
Count
Source
2049
84
{
2050
84
  coff_data_type *coff;
2051
84
  size_t amt = sizeof (coff_data_type);
2052
2053
84
  abfd->tdata.coff_obj_data = bfd_zalloc (abfd, amt);
2054
84
  if (abfd->tdata.coff_obj_data == NULL)
2055
0
    return false;
2056
2057
84
  coff = coff_data (abfd);
2058
84
  coff->symbols = NULL;
2059
84
  coff->conversion_table = NULL;
2060
84
  coff->raw_syments = NULL;
2061
84
  coff->relocbase = 0;
2062
84
  coff->local_toc_sym_map = 0;
2063
2064
84
  bfd_coff_long_section_names (abfd)
2065
84
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
2066
2067
/*  make_abs_section(abfd);*/
2068
2069
84
  return true;
2070
84
}
coff-z8k.c:coff_mkobject
Line
Count
Source
2049
98
{
2050
98
  coff_data_type *coff;
2051
98
  size_t amt = sizeof (coff_data_type);
2052
2053
98
  abfd->tdata.coff_obj_data = bfd_zalloc (abfd, amt);
2054
98
  if (abfd->tdata.coff_obj_data == NULL)
2055
0
    return false;
2056
2057
98
  coff = coff_data (abfd);
2058
98
  coff->symbols = NULL;
2059
98
  coff->conversion_table = NULL;
2060
98
  coff->raw_syments = NULL;
2061
98
  coff->relocbase = 0;
2062
98
  coff->local_toc_sym_map = 0;
2063
2064
98
  bfd_coff_long_section_names (abfd)
2065
98
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
2066
2067
/*  make_abs_section(abfd);*/
2068
2069
98
  return true;
2070
98
}
2071
#endif
2072
2073
/* Create the COFF backend specific information.  */
2074
2075
#ifndef coff_mkobject_hook
2076
static void *
2077
coff_mkobject_hook (bfd * abfd,
2078
        void * filehdr,
2079
        void * aouthdr ATTRIBUTE_UNUSED)
2080
4.45k
{
2081
4.45k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2082
4.45k
  coff_data_type *coff;
2083
2084
4.45k
  if (! coff_mkobject (abfd))
2085
0
    return NULL;
2086
2087
4.45k
  coff = coff_data (abfd);
2088
2089
4.45k
  coff->sym_filepos = internal_f->f_symptr;
2090
2091
  /* These members communicate important constants about the symbol
2092
     table to GDB's symbol-reading code.  These `constants'
2093
     unfortunately vary among coff implementations...  */
2094
4.45k
  coff->local_n_btmask = N_BTMASK;
2095
4.45k
  coff->local_n_btshft = N_BTSHFT;
2096
4.45k
  coff->local_n_tmask = N_TMASK;
2097
4.45k
  coff->local_n_tshift = N_TSHIFT;
2098
4.45k
  coff->local_symesz = bfd_coff_symesz (abfd);
2099
4.45k
  coff->local_auxesz = bfd_coff_auxesz (abfd);
2100
4.45k
  coff->local_linesz = bfd_coff_linesz (abfd);
2101
2102
4.45k
  coff->timestamp = internal_f->f_timdat;
2103
2104
4.45k
  obj_raw_syment_count (abfd) =
2105
4.45k
    obj_conv_table_size (abfd) =
2106
4.45k
      internal_f->f_nsyms;
2107
2108
#ifdef RS6000COFF_C
2109
1.55k
  if ((internal_f->f_flags & F_SHROBJ) != 0)
2110
374
    abfd->flags |= DYNAMIC;
2111
1.55k
  if (aouthdr != NULL && internal_f->f_opthdr >= bfd_coff_aoutsz (abfd))
2112
0
    {
2113
0
      struct internal_aouthdr *internal_a =
2114
0
  (struct internal_aouthdr *) aouthdr;
2115
0
      struct xcoff_tdata *xcoff;
2116
2117
0
      xcoff = xcoff_data (abfd);
2118
# ifdef U803XTOCMAGIC
2119
0
      xcoff->xcoff64 = internal_f->f_magic == U803XTOCMAGIC;
2120
# else
2121
      xcoff->xcoff64 = 0;
2122
# endif
2123
0
      xcoff->full_aouthdr = true;
2124
0
      xcoff->toc = internal_a->o_toc;
2125
0
      xcoff->sntoc = internal_a->o_sntoc;
2126
0
      xcoff->snentry = internal_a->o_snentry;
2127
0
      bfd_xcoff_text_align_power (abfd) = internal_a->o_algntext;
2128
0
      bfd_xcoff_data_align_power (abfd) = internal_a->o_algndata;
2129
0
      xcoff->modtype = internal_a->o_modtype;
2130
0
      xcoff->cputype = internal_a->o_cputype;
2131
0
      xcoff->maxdata = internal_a->o_maxdata;
2132
0
      xcoff->maxstack = internal_a->o_maxstack;
2133
0
    }
2134
#endif
2135
2136
#ifdef ARM
2137
  /* Set the flags field from the COFF header read in.  */
2138
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
2139
    coff->flags = 0;
2140
#endif
2141
2142
#ifdef COFF_WITH_PE
2143
  /* FIXME: I'm not sure this is ever executed, since peicode.h
2144
     defines coff_mkobject_hook.  */
2145
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
2146
    abfd->flags |= HAS_DEBUG;
2147
#endif
2148
2149
4.45k
  return coff;
2150
4.45k
}
coff-x86_64.c:coff_mkobject_hook
Line
Count
Source
2080
94
{
2081
94
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2082
94
  coff_data_type *coff;
2083
2084
94
  if (! coff_mkobject (abfd))
2085
0
    return NULL;
2086
2087
94
  coff = coff_data (abfd);
2088
2089
94
  coff->sym_filepos = internal_f->f_symptr;
2090
2091
  /* These members communicate important constants about the symbol
2092
     table to GDB's symbol-reading code.  These `constants'
2093
     unfortunately vary among coff implementations...  */
2094
94
  coff->local_n_btmask = N_BTMASK;
2095
94
  coff->local_n_btshft = N_BTSHFT;
2096
94
  coff->local_n_tmask = N_TMASK;
2097
94
  coff->local_n_tshift = N_TSHIFT;
2098
94
  coff->local_symesz = bfd_coff_symesz (abfd);
2099
94
  coff->local_auxesz = bfd_coff_auxesz (abfd);
2100
94
  coff->local_linesz = bfd_coff_linesz (abfd);
2101
2102
94
  coff->timestamp = internal_f->f_timdat;
2103
2104
94
  obj_raw_syment_count (abfd) =
2105
94
    obj_conv_table_size (abfd) =
2106
94
      internal_f->f_nsyms;
2107
2108
#ifdef RS6000COFF_C
2109
  if ((internal_f->f_flags & F_SHROBJ) != 0)
2110
    abfd->flags |= DYNAMIC;
2111
  if (aouthdr != NULL && internal_f->f_opthdr >= bfd_coff_aoutsz (abfd))
2112
    {
2113
      struct internal_aouthdr *internal_a =
2114
  (struct internal_aouthdr *) aouthdr;
2115
      struct xcoff_tdata *xcoff;
2116
2117
      xcoff = xcoff_data (abfd);
2118
# ifdef U803XTOCMAGIC
2119
      xcoff->xcoff64 = internal_f->f_magic == U803XTOCMAGIC;
2120
# else
2121
      xcoff->xcoff64 = 0;
2122
# endif
2123
      xcoff->full_aouthdr = true;
2124
      xcoff->toc = internal_a->o_toc;
2125
      xcoff->sntoc = internal_a->o_sntoc;
2126
      xcoff->snentry = internal_a->o_snentry;
2127
      bfd_xcoff_text_align_power (abfd) = internal_a->o_algntext;
2128
      bfd_xcoff_data_align_power (abfd) = internal_a->o_algndata;
2129
      xcoff->modtype = internal_a->o_modtype;
2130
      xcoff->cputype = internal_a->o_cputype;
2131
      xcoff->maxdata = internal_a->o_maxdata;
2132
      xcoff->maxstack = internal_a->o_maxstack;
2133
    }
2134
#endif
2135
2136
#ifdef ARM
2137
  /* Set the flags field from the COFF header read in.  */
2138
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
2139
    coff->flags = 0;
2140
#endif
2141
2142
#ifdef COFF_WITH_PE
2143
  /* FIXME: I'm not sure this is ever executed, since peicode.h
2144
     defines coff_mkobject_hook.  */
2145
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
2146
    abfd->flags |= HAS_DEBUG;
2147
#endif
2148
2149
94
  return coff;
2150
94
}
coff64-rs6000.c:coff_mkobject_hook
Line
Count
Source
2080
1.42k
{
2081
1.42k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2082
1.42k
  coff_data_type *coff;
2083
2084
1.42k
  if (! coff_mkobject (abfd))
2085
0
    return NULL;
2086
2087
1.42k
  coff = coff_data (abfd);
2088
2089
1.42k
  coff->sym_filepos = internal_f->f_symptr;
2090
2091
  /* These members communicate important constants about the symbol
2092
     table to GDB's symbol-reading code.  These `constants'
2093
     unfortunately vary among coff implementations...  */
2094
1.42k
  coff->local_n_btmask = N_BTMASK;
2095
1.42k
  coff->local_n_btshft = N_BTSHFT;
2096
1.42k
  coff->local_n_tmask = N_TMASK;
2097
1.42k
  coff->local_n_tshift = N_TSHIFT;
2098
1.42k
  coff->local_symesz = bfd_coff_symesz (abfd);
2099
1.42k
  coff->local_auxesz = bfd_coff_auxesz (abfd);
2100
1.42k
  coff->local_linesz = bfd_coff_linesz (abfd);
2101
2102
1.42k
  coff->timestamp = internal_f->f_timdat;
2103
2104
1.42k
  obj_raw_syment_count (abfd) =
2105
1.42k
    obj_conv_table_size (abfd) =
2106
1.42k
      internal_f->f_nsyms;
2107
2108
1.42k
#ifdef RS6000COFF_C
2109
1.42k
  if ((internal_f->f_flags & F_SHROBJ) != 0)
2110
372
    abfd->flags |= DYNAMIC;
2111
1.42k
  if (aouthdr != NULL && internal_f->f_opthdr >= bfd_coff_aoutsz (abfd))
2112
0
    {
2113
0
      struct internal_aouthdr *internal_a =
2114
0
  (struct internal_aouthdr *) aouthdr;
2115
0
      struct xcoff_tdata *xcoff;
2116
2117
0
      xcoff = xcoff_data (abfd);
2118
0
# ifdef U803XTOCMAGIC
2119
0
      xcoff->xcoff64 = internal_f->f_magic == U803XTOCMAGIC;
2120
# else
2121
      xcoff->xcoff64 = 0;
2122
# endif
2123
0
      xcoff->full_aouthdr = true;
2124
0
      xcoff->toc = internal_a->o_toc;
2125
0
      xcoff->sntoc = internal_a->o_sntoc;
2126
0
      xcoff->snentry = internal_a->o_snentry;
2127
0
      bfd_xcoff_text_align_power (abfd) = internal_a->o_algntext;
2128
0
      bfd_xcoff_data_align_power (abfd) = internal_a->o_algndata;
2129
0
      xcoff->modtype = internal_a->o_modtype;
2130
0
      xcoff->cputype = internal_a->o_cputype;
2131
0
      xcoff->maxdata = internal_a->o_maxdata;
2132
0
      xcoff->maxstack = internal_a->o_maxstack;
2133
0
    }
2134
1.42k
#endif
2135
2136
#ifdef ARM
2137
  /* Set the flags field from the COFF header read in.  */
2138
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
2139
    coff->flags = 0;
2140
#endif
2141
2142
#ifdef COFF_WITH_PE
2143
  /* FIXME: I'm not sure this is ever executed, since peicode.h
2144
     defines coff_mkobject_hook.  */
2145
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
2146
    abfd->flags |= HAS_DEBUG;
2147
#endif
2148
2149
1.42k
  return coff;
2150
1.42k
}
cf-i386lynx.c:coff_mkobject_hook
Line
Count
Source
2080
90
{
2081
90
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2082
90
  coff_data_type *coff;
2083
2084
90
  if (! coff_mkobject (abfd))
2085
0
    return NULL;
2086
2087
90
  coff = coff_data (abfd);
2088
2089
90
  coff->sym_filepos = internal_f->f_symptr;
2090
2091
  /* These members communicate important constants about the symbol
2092
     table to GDB's symbol-reading code.  These `constants'
2093
     unfortunately vary among coff implementations...  */
2094
90
  coff->local_n_btmask = N_BTMASK;
2095
90
  coff->local_n_btshft = N_BTSHFT;
2096
90
  coff->local_n_tmask = N_TMASK;
2097
90
  coff->local_n_tshift = N_TSHIFT;
2098
90
  coff->local_symesz = bfd_coff_symesz (abfd);
2099
90
  coff->local_auxesz = bfd_coff_auxesz (abfd);
2100
90
  coff->local_linesz = bfd_coff_linesz (abfd);
2101
2102
90
  coff->timestamp = internal_f->f_timdat;
2103
2104
90
  obj_raw_syment_count (abfd) =
2105
90
    obj_conv_table_size (abfd) =
2106
90
      internal_f->f_nsyms;
2107
2108
#ifdef RS6000COFF_C
2109
  if ((internal_f->f_flags & F_SHROBJ) != 0)
2110
    abfd->flags |= DYNAMIC;
2111
  if (aouthdr != NULL && internal_f->f_opthdr >= bfd_coff_aoutsz (abfd))
2112
    {
2113
      struct internal_aouthdr *internal_a =
2114
  (struct internal_aouthdr *) aouthdr;
2115
      struct xcoff_tdata *xcoff;
2116
2117
      xcoff = xcoff_data (abfd);
2118
# ifdef U803XTOCMAGIC
2119
      xcoff->xcoff64 = internal_f->f_magic == U803XTOCMAGIC;
2120
# else
2121
      xcoff->xcoff64 = 0;
2122
# endif
2123
      xcoff->full_aouthdr = true;
2124
      xcoff->toc = internal_a->o_toc;
2125
      xcoff->sntoc = internal_a->o_sntoc;
2126
      xcoff->snentry = internal_a->o_snentry;
2127
      bfd_xcoff_text_align_power (abfd) = internal_a->o_algntext;
2128
      bfd_xcoff_data_align_power (abfd) = internal_a->o_algndata;
2129
      xcoff->modtype = internal_a->o_modtype;
2130
      xcoff->cputype = internal_a->o_cputype;
2131
      xcoff->maxdata = internal_a->o_maxdata;
2132
      xcoff->maxstack = internal_a->o_maxstack;
2133
    }
2134
#endif
2135
2136
#ifdef ARM
2137
  /* Set the flags field from the COFF header read in.  */
2138
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
2139
    coff->flags = 0;
2140
#endif
2141
2142
#ifdef COFF_WITH_PE
2143
  /* FIXME: I'm not sure this is ever executed, since peicode.h
2144
     defines coff_mkobject_hook.  */
2145
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
2146
    abfd->flags |= HAS_DEBUG;
2147
#endif
2148
2149
90
  return coff;
2150
90
}
coff-go32.c:coff_mkobject_hook
Line
Count
Source
2080
14
{
2081
14
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2082
14
  coff_data_type *coff;
2083
2084
14
  if (! coff_mkobject (abfd))
2085
0
    return NULL;
2086
2087
14
  coff = coff_data (abfd);
2088
2089
14
  coff->sym_filepos = internal_f->f_symptr;
2090
2091
  /* These members communicate important constants about the symbol
2092
     table to GDB's symbol-reading code.  These `constants'
2093
     unfortunately vary among coff implementations...  */
2094
14
  coff->local_n_btmask = N_BTMASK;
2095
14
  coff->local_n_btshft = N_BTSHFT;
2096
14
  coff->local_n_tmask = N_TMASK;
2097
14
  coff->local_n_tshift = N_TSHIFT;
2098
14
  coff->local_symesz = bfd_coff_symesz (abfd);
2099
14
  coff->local_auxesz = bfd_coff_auxesz (abfd);
2100
14
  coff->local_linesz = bfd_coff_linesz (abfd);
2101
2102
14
  coff->timestamp = internal_f->f_timdat;
2103
2104
14
  obj_raw_syment_count (abfd) =
2105
14
    obj_conv_table_size (abfd) =
2106
14
      internal_f->f_nsyms;
2107
2108
#ifdef RS6000COFF_C
2109
  if ((internal_f->f_flags & F_SHROBJ) != 0)
2110
    abfd->flags |= DYNAMIC;
2111
  if (aouthdr != NULL && internal_f->f_opthdr >= bfd_coff_aoutsz (abfd))
2112
    {
2113
      struct internal_aouthdr *internal_a =
2114
  (struct internal_aouthdr *) aouthdr;
2115
      struct xcoff_tdata *xcoff;
2116
2117
      xcoff = xcoff_data (abfd);
2118
# ifdef U803XTOCMAGIC
2119
      xcoff->xcoff64 = internal_f->f_magic == U803XTOCMAGIC;
2120
# else
2121
      xcoff->xcoff64 = 0;
2122
# endif
2123
      xcoff->full_aouthdr = true;
2124
      xcoff->toc = internal_a->o_toc;
2125
      xcoff->sntoc = internal_a->o_sntoc;
2126
      xcoff->snentry = internal_a->o_snentry;
2127
      bfd_xcoff_text_align_power (abfd) = internal_a->o_algntext;
2128
      bfd_xcoff_data_align_power (abfd) = internal_a->o_algndata;
2129
      xcoff->modtype = internal_a->o_modtype;
2130
      xcoff->cputype = internal_a->o_cputype;
2131
      xcoff->maxdata = internal_a->o_maxdata;
2132
      xcoff->maxstack = internal_a->o_maxstack;
2133
    }
2134
#endif
2135
2136
#ifdef ARM
2137
  /* Set the flags field from the COFF header read in.  */
2138
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
2139
    coff->flags = 0;
2140
#endif
2141
2142
#ifdef COFF_WITH_PE
2143
  /* FIXME: I'm not sure this is ever executed, since peicode.h
2144
     defines coff_mkobject_hook.  */
2145
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
2146
    abfd->flags |= HAS_DEBUG;
2147
#endif
2148
2149
14
  return coff;
2150
14
}
coff-i386.c:coff_mkobject_hook
Line
Count
Source
2080
14
{
2081
14
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2082
14
  coff_data_type *coff;
2083
2084
14
  if (! coff_mkobject (abfd))
2085
0
    return NULL;
2086
2087
14
  coff = coff_data (abfd);
2088
2089
14
  coff->sym_filepos = internal_f->f_symptr;
2090
2091
  /* These members communicate important constants about the symbol
2092
     table to GDB's symbol-reading code.  These `constants'
2093
     unfortunately vary among coff implementations...  */
2094
14
  coff->local_n_btmask = N_BTMASK;
2095
14
  coff->local_n_btshft = N_BTSHFT;
2096
14
  coff->local_n_tmask = N_TMASK;
2097
14
  coff->local_n_tshift = N_TSHIFT;
2098
14
  coff->local_symesz = bfd_coff_symesz (abfd);
2099
14
  coff->local_auxesz = bfd_coff_auxesz (abfd);
2100
14
  coff->local_linesz = bfd_coff_linesz (abfd);
2101
2102
14
  coff->timestamp = internal_f->f_timdat;
2103
2104
14
  obj_raw_syment_count (abfd) =
2105
14
    obj_conv_table_size (abfd) =
2106
14
      internal_f->f_nsyms;
2107
2108
#ifdef RS6000COFF_C
2109
  if ((internal_f->f_flags & F_SHROBJ) != 0)
2110
    abfd->flags |= DYNAMIC;
2111
  if (aouthdr != NULL && internal_f->f_opthdr >= bfd_coff_aoutsz (abfd))
2112
    {
2113
      struct internal_aouthdr *internal_a =
2114
  (struct internal_aouthdr *) aouthdr;
2115
      struct xcoff_tdata *xcoff;
2116
2117
      xcoff = xcoff_data (abfd);
2118
# ifdef U803XTOCMAGIC
2119
      xcoff->xcoff64 = internal_f->f_magic == U803XTOCMAGIC;
2120
# else
2121
      xcoff->xcoff64 = 0;
2122
# endif
2123
      xcoff->full_aouthdr = true;
2124
      xcoff->toc = internal_a->o_toc;
2125
      xcoff->sntoc = internal_a->o_sntoc;
2126
      xcoff->snentry = internal_a->o_snentry;
2127
      bfd_xcoff_text_align_power (abfd) = internal_a->o_algntext;
2128
      bfd_xcoff_data_align_power (abfd) = internal_a->o_algndata;
2129
      xcoff->modtype = internal_a->o_modtype;
2130
      xcoff->cputype = internal_a->o_cputype;
2131
      xcoff->maxdata = internal_a->o_maxdata;
2132
      xcoff->maxstack = internal_a->o_maxstack;
2133
    }
2134
#endif
2135
2136
#ifdef ARM
2137
  /* Set the flags field from the COFF header read in.  */
2138
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
2139
    coff->flags = 0;
2140
#endif
2141
2142
#ifdef COFF_WITH_PE
2143
  /* FIXME: I'm not sure this is ever executed, since peicode.h
2144
     defines coff_mkobject_hook.  */
2145
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
2146
    abfd->flags |= HAS_DEBUG;
2147
#endif
2148
2149
14
  return coff;
2150
14
}
coff-rs6000.c:coff_mkobject_hook
Line
Count
Source
2080
133
{
2081
133
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2082
133
  coff_data_type *coff;
2083
2084
133
  if (! coff_mkobject (abfd))
2085
0
    return NULL;
2086
2087
133
  coff = coff_data (abfd);
2088
2089
133
  coff->sym_filepos = internal_f->f_symptr;
2090
2091
  /* These members communicate important constants about the symbol
2092
     table to GDB's symbol-reading code.  These `constants'
2093
     unfortunately vary among coff implementations...  */
2094
133
  coff->local_n_btmask = N_BTMASK;
2095
133
  coff->local_n_btshft = N_BTSHFT;
2096
133
  coff->local_n_tmask = N_TMASK;
2097
133
  coff->local_n_tshift = N_TSHIFT;
2098
133
  coff->local_symesz = bfd_coff_symesz (abfd);
2099
133
  coff->local_auxesz = bfd_coff_auxesz (abfd);
2100
133
  coff->local_linesz = bfd_coff_linesz (abfd);
2101
2102
133
  coff->timestamp = internal_f->f_timdat;
2103
2104
133
  obj_raw_syment_count (abfd) =
2105
133
    obj_conv_table_size (abfd) =
2106
133
      internal_f->f_nsyms;
2107
2108
133
#ifdef RS6000COFF_C
2109
133
  if ((internal_f->f_flags & F_SHROBJ) != 0)
2110
2
    abfd->flags |= DYNAMIC;
2111
133
  if (aouthdr != NULL && internal_f->f_opthdr >= bfd_coff_aoutsz (abfd))
2112
0
    {
2113
0
      struct internal_aouthdr *internal_a =
2114
0
  (struct internal_aouthdr *) aouthdr;
2115
0
      struct xcoff_tdata *xcoff;
2116
2117
0
      xcoff = xcoff_data (abfd);
2118
# ifdef U803XTOCMAGIC
2119
      xcoff->xcoff64 = internal_f->f_magic == U803XTOCMAGIC;
2120
# else
2121
0
      xcoff->xcoff64 = 0;
2122
0
# endif
2123
0
      xcoff->full_aouthdr = true;
2124
0
      xcoff->toc = internal_a->o_toc;
2125
0
      xcoff->sntoc = internal_a->o_sntoc;
2126
0
      xcoff->snentry = internal_a->o_snentry;
2127
0
      bfd_xcoff_text_align_power (abfd) = internal_a->o_algntext;
2128
0
      bfd_xcoff_data_align_power (abfd) = internal_a->o_algndata;
2129
0
      xcoff->modtype = internal_a->o_modtype;
2130
0
      xcoff->cputype = internal_a->o_cputype;
2131
0
      xcoff->maxdata = internal_a->o_maxdata;
2132
0
      xcoff->maxstack = internal_a->o_maxstack;
2133
0
    }
2134
133
#endif
2135
2136
#ifdef ARM
2137
  /* Set the flags field from the COFF header read in.  */
2138
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
2139
    coff->flags = 0;
2140
#endif
2141
2142
#ifdef COFF_WITH_PE
2143
  /* FIXME: I'm not sure this is ever executed, since peicode.h
2144
     defines coff_mkobject_hook.  */
2145
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
2146
    abfd->flags |= HAS_DEBUG;
2147
#endif
2148
2149
133
  return coff;
2150
133
}
coff-sh.c:coff_mkobject_hook
Line
Count
Source
2080
2.38k
{
2081
2.38k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2082
2.38k
  coff_data_type *coff;
2083
2084
2.38k
  if (! coff_mkobject (abfd))
2085
0
    return NULL;
2086
2087
2.38k
  coff = coff_data (abfd);
2088
2089
2.38k
  coff->sym_filepos = internal_f->f_symptr;
2090
2091
  /* These members communicate important constants about the symbol
2092
     table to GDB's symbol-reading code.  These `constants'
2093
     unfortunately vary among coff implementations...  */
2094
2.38k
  coff->local_n_btmask = N_BTMASK;
2095
2.38k
  coff->local_n_btshft = N_BTSHFT;
2096
2.38k
  coff->local_n_tmask = N_TMASK;
2097
2.38k
  coff->local_n_tshift = N_TSHIFT;
2098
2.38k
  coff->local_symesz = bfd_coff_symesz (abfd);
2099
2.38k
  coff->local_auxesz = bfd_coff_auxesz (abfd);
2100
2.38k
  coff->local_linesz = bfd_coff_linesz (abfd);
2101
2102
2.38k
  coff->timestamp = internal_f->f_timdat;
2103
2104
2.38k
  obj_raw_syment_count (abfd) =
2105
2.38k
    obj_conv_table_size (abfd) =
2106
2.38k
      internal_f->f_nsyms;
2107
2108
#ifdef RS6000COFF_C
2109
  if ((internal_f->f_flags & F_SHROBJ) != 0)
2110
    abfd->flags |= DYNAMIC;
2111
  if (aouthdr != NULL && internal_f->f_opthdr >= bfd_coff_aoutsz (abfd))
2112
    {
2113
      struct internal_aouthdr *internal_a =
2114
  (struct internal_aouthdr *) aouthdr;
2115
      struct xcoff_tdata *xcoff;
2116
2117
      xcoff = xcoff_data (abfd);
2118
# ifdef U803XTOCMAGIC
2119
      xcoff->xcoff64 = internal_f->f_magic == U803XTOCMAGIC;
2120
# else
2121
      xcoff->xcoff64 = 0;
2122
# endif
2123
      xcoff->full_aouthdr = true;
2124
      xcoff->toc = internal_a->o_toc;
2125
      xcoff->sntoc = internal_a->o_sntoc;
2126
      xcoff->snentry = internal_a->o_snentry;
2127
      bfd_xcoff_text_align_power (abfd) = internal_a->o_algntext;
2128
      bfd_xcoff_data_align_power (abfd) = internal_a->o_algndata;
2129
      xcoff->modtype = internal_a->o_modtype;
2130
      xcoff->cputype = internal_a->o_cputype;
2131
      xcoff->maxdata = internal_a->o_maxdata;
2132
      xcoff->maxstack = internal_a->o_maxstack;
2133
    }
2134
#endif
2135
2136
#ifdef ARM
2137
  /* Set the flags field from the COFF header read in.  */
2138
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
2139
    coff->flags = 0;
2140
#endif
2141
2142
#ifdef COFF_WITH_PE
2143
  /* FIXME: I'm not sure this is ever executed, since peicode.h
2144
     defines coff_mkobject_hook.  */
2145
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
2146
    abfd->flags |= HAS_DEBUG;
2147
#endif
2148
2149
2.38k
  return coff;
2150
2.38k
}
coff-stgo32.c:coff_mkobject_hook
Line
Count
Source
2080
106
{
2081
106
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2082
106
  coff_data_type *coff;
2083
2084
106
  if (! coff_mkobject (abfd))
2085
0
    return NULL;
2086
2087
106
  coff = coff_data (abfd);
2088
2089
106
  coff->sym_filepos = internal_f->f_symptr;
2090
2091
  /* These members communicate important constants about the symbol
2092
     table to GDB's symbol-reading code.  These `constants'
2093
     unfortunately vary among coff implementations...  */
2094
106
  coff->local_n_btmask = N_BTMASK;
2095
106
  coff->local_n_btshft = N_BTSHFT;
2096
106
  coff->local_n_tmask = N_TMASK;
2097
106
  coff->local_n_tshift = N_TSHIFT;
2098
106
  coff->local_symesz = bfd_coff_symesz (abfd);
2099
106
  coff->local_auxesz = bfd_coff_auxesz (abfd);
2100
106
  coff->local_linesz = bfd_coff_linesz (abfd);
2101
2102
106
  coff->timestamp = internal_f->f_timdat;
2103
2104
106
  obj_raw_syment_count (abfd) =
2105
106
    obj_conv_table_size (abfd) =
2106
106
      internal_f->f_nsyms;
2107
2108
#ifdef RS6000COFF_C
2109
  if ((internal_f->f_flags & F_SHROBJ) != 0)
2110
    abfd->flags |= DYNAMIC;
2111
  if (aouthdr != NULL && internal_f->f_opthdr >= bfd_coff_aoutsz (abfd))
2112
    {
2113
      struct internal_aouthdr *internal_a =
2114
  (struct internal_aouthdr *) aouthdr;
2115
      struct xcoff_tdata *xcoff;
2116
2117
      xcoff = xcoff_data (abfd);
2118
# ifdef U803XTOCMAGIC
2119
      xcoff->xcoff64 = internal_f->f_magic == U803XTOCMAGIC;
2120
# else
2121
      xcoff->xcoff64 = 0;
2122
# endif
2123
      xcoff->full_aouthdr = true;
2124
      xcoff->toc = internal_a->o_toc;
2125
      xcoff->sntoc = internal_a->o_sntoc;
2126
      xcoff->snentry = internal_a->o_snentry;
2127
      bfd_xcoff_text_align_power (abfd) = internal_a->o_algntext;
2128
      bfd_xcoff_data_align_power (abfd) = internal_a->o_algndata;
2129
      xcoff->modtype = internal_a->o_modtype;
2130
      xcoff->cputype = internal_a->o_cputype;
2131
      xcoff->maxdata = internal_a->o_maxdata;
2132
      xcoff->maxstack = internal_a->o_maxstack;
2133
    }
2134
#endif
2135
2136
#ifdef ARM
2137
  /* Set the flags field from the COFF header read in.  */
2138
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
2139
    coff->flags = 0;
2140
#endif
2141
2142
#ifdef COFF_WITH_PE
2143
  /* FIXME: I'm not sure this is ever executed, since peicode.h
2144
     defines coff_mkobject_hook.  */
2145
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
2146
    abfd->flags |= HAS_DEBUG;
2147
#endif
2148
2149
106
  return coff;
2150
106
}
coff-tic30.c:coff_mkobject_hook
Line
Count
Source
2080
40
{
2081
40
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2082
40
  coff_data_type *coff;
2083
2084
40
  if (! coff_mkobject (abfd))
2085
0
    return NULL;
2086
2087
40
  coff = coff_data (abfd);
2088
2089
40
  coff->sym_filepos = internal_f->f_symptr;
2090
2091
  /* These members communicate important constants about the symbol
2092
     table to GDB's symbol-reading code.  These `constants'
2093
     unfortunately vary among coff implementations...  */
2094
40
  coff->local_n_btmask = N_BTMASK;
2095
40
  coff->local_n_btshft = N_BTSHFT;
2096
40
  coff->local_n_tmask = N_TMASK;
2097
40
  coff->local_n_tshift = N_TSHIFT;
2098
40
  coff->local_symesz = bfd_coff_symesz (abfd);
2099
40
  coff->local_auxesz = bfd_coff_auxesz (abfd);
2100
40
  coff->local_linesz = bfd_coff_linesz (abfd);
2101
2102
40
  coff->timestamp = internal_f->f_timdat;
2103
2104
40
  obj_raw_syment_count (abfd) =
2105
40
    obj_conv_table_size (abfd) =
2106
40
      internal_f->f_nsyms;
2107
2108
#ifdef RS6000COFF_C
2109
  if ((internal_f->f_flags & F_SHROBJ) != 0)
2110
    abfd->flags |= DYNAMIC;
2111
  if (aouthdr != NULL && internal_f->f_opthdr >= bfd_coff_aoutsz (abfd))
2112
    {
2113
      struct internal_aouthdr *internal_a =
2114
  (struct internal_aouthdr *) aouthdr;
2115
      struct xcoff_tdata *xcoff;
2116
2117
      xcoff = xcoff_data (abfd);
2118
# ifdef U803XTOCMAGIC
2119
      xcoff->xcoff64 = internal_f->f_magic == U803XTOCMAGIC;
2120
# else
2121
      xcoff->xcoff64 = 0;
2122
# endif
2123
      xcoff->full_aouthdr = true;
2124
      xcoff->toc = internal_a->o_toc;
2125
      xcoff->sntoc = internal_a->o_sntoc;
2126
      xcoff->snentry = internal_a->o_snentry;
2127
      bfd_xcoff_text_align_power (abfd) = internal_a->o_algntext;
2128
      bfd_xcoff_data_align_power (abfd) = internal_a->o_algndata;
2129
      xcoff->modtype = internal_a->o_modtype;
2130
      xcoff->cputype = internal_a->o_cputype;
2131
      xcoff->maxdata = internal_a->o_maxdata;
2132
      xcoff->maxstack = internal_a->o_maxstack;
2133
    }
2134
#endif
2135
2136
#ifdef ARM
2137
  /* Set the flags field from the COFF header read in.  */
2138
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
2139
    coff->flags = 0;
2140
#endif
2141
2142
#ifdef COFF_WITH_PE
2143
  /* FIXME: I'm not sure this is ever executed, since peicode.h
2144
     defines coff_mkobject_hook.  */
2145
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
2146
    abfd->flags |= HAS_DEBUG;
2147
#endif
2148
2149
40
  return coff;
2150
40
}
Unexecuted instantiation: coff-tic4x.c:coff_mkobject_hook
coff-tic54x.c:coff_mkobject_hook
Line
Count
Source
2080
68
{
2081
68
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2082
68
  coff_data_type *coff;
2083
2084
68
  if (! coff_mkobject (abfd))
2085
0
    return NULL;
2086
2087
68
  coff = coff_data (abfd);
2088
2089
68
  coff->sym_filepos = internal_f->f_symptr;
2090
2091
  /* These members communicate important constants about the symbol
2092
     table to GDB's symbol-reading code.  These `constants'
2093
     unfortunately vary among coff implementations...  */
2094
68
  coff->local_n_btmask = N_BTMASK;
2095
68
  coff->local_n_btshft = N_BTSHFT;
2096
68
  coff->local_n_tmask = N_TMASK;
2097
68
  coff->local_n_tshift = N_TSHIFT;
2098
68
  coff->local_symesz = bfd_coff_symesz (abfd);
2099
68
  coff->local_auxesz = bfd_coff_auxesz (abfd);
2100
68
  coff->local_linesz = bfd_coff_linesz (abfd);
2101
2102
68
  coff->timestamp = internal_f->f_timdat;
2103
2104
68
  obj_raw_syment_count (abfd) =
2105
68
    obj_conv_table_size (abfd) =
2106
68
      internal_f->f_nsyms;
2107
2108
#ifdef RS6000COFF_C
2109
  if ((internal_f->f_flags & F_SHROBJ) != 0)
2110
    abfd->flags |= DYNAMIC;
2111
  if (aouthdr != NULL && internal_f->f_opthdr >= bfd_coff_aoutsz (abfd))
2112
    {
2113
      struct internal_aouthdr *internal_a =
2114
  (struct internal_aouthdr *) aouthdr;
2115
      struct xcoff_tdata *xcoff;
2116
2117
      xcoff = xcoff_data (abfd);
2118
# ifdef U803XTOCMAGIC
2119
      xcoff->xcoff64 = internal_f->f_magic == U803XTOCMAGIC;
2120
# else
2121
      xcoff->xcoff64 = 0;
2122
# endif
2123
      xcoff->full_aouthdr = true;
2124
      xcoff->toc = internal_a->o_toc;
2125
      xcoff->sntoc = internal_a->o_sntoc;
2126
      xcoff->snentry = internal_a->o_snentry;
2127
      bfd_xcoff_text_align_power (abfd) = internal_a->o_algntext;
2128
      bfd_xcoff_data_align_power (abfd) = internal_a->o_algndata;
2129
      xcoff->modtype = internal_a->o_modtype;
2130
      xcoff->cputype = internal_a->o_cputype;
2131
      xcoff->maxdata = internal_a->o_maxdata;
2132
      xcoff->maxstack = internal_a->o_maxstack;
2133
    }
2134
#endif
2135
2136
#ifdef ARM
2137
  /* Set the flags field from the COFF header read in.  */
2138
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
2139
    coff->flags = 0;
2140
#endif
2141
2142
#ifdef COFF_WITH_PE
2143
  /* FIXME: I'm not sure this is ever executed, since peicode.h
2144
     defines coff_mkobject_hook.  */
2145
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
2146
    abfd->flags |= HAS_DEBUG;
2147
#endif
2148
2149
68
  return coff;
2150
68
}
coff-z80.c:coff_mkobject_hook
Line
Count
Source
2080
42
{
2081
42
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2082
42
  coff_data_type *coff;
2083
2084
42
  if (! coff_mkobject (abfd))
2085
0
    return NULL;
2086
2087
42
  coff = coff_data (abfd);
2088
2089
42
  coff->sym_filepos = internal_f->f_symptr;
2090
2091
  /* These members communicate important constants about the symbol
2092
     table to GDB's symbol-reading code.  These `constants'
2093
     unfortunately vary among coff implementations...  */
2094
42
  coff->local_n_btmask = N_BTMASK;
2095
42
  coff->local_n_btshft = N_BTSHFT;
2096
42
  coff->local_n_tmask = N_TMASK;
2097
42
  coff->local_n_tshift = N_TSHIFT;
2098
42
  coff->local_symesz = bfd_coff_symesz (abfd);
2099
42
  coff->local_auxesz = bfd_coff_auxesz (abfd);
2100
42
  coff->local_linesz = bfd_coff_linesz (abfd);
2101
2102
42
  coff->timestamp = internal_f->f_timdat;
2103
2104
42
  obj_raw_syment_count (abfd) =
2105
42
    obj_conv_table_size (abfd) =
2106
42
      internal_f->f_nsyms;
2107
2108
#ifdef RS6000COFF_C
2109
  if ((internal_f->f_flags & F_SHROBJ) != 0)
2110
    abfd->flags |= DYNAMIC;
2111
  if (aouthdr != NULL && internal_f->f_opthdr >= bfd_coff_aoutsz (abfd))
2112
    {
2113
      struct internal_aouthdr *internal_a =
2114
  (struct internal_aouthdr *) aouthdr;
2115
      struct xcoff_tdata *xcoff;
2116
2117
      xcoff = xcoff_data (abfd);
2118
# ifdef U803XTOCMAGIC
2119
      xcoff->xcoff64 = internal_f->f_magic == U803XTOCMAGIC;
2120
# else
2121
      xcoff->xcoff64 = 0;
2122
# endif
2123
      xcoff->full_aouthdr = true;
2124
      xcoff->toc = internal_a->o_toc;
2125
      xcoff->sntoc = internal_a->o_sntoc;
2126
      xcoff->snentry = internal_a->o_snentry;
2127
      bfd_xcoff_text_align_power (abfd) = internal_a->o_algntext;
2128
      bfd_xcoff_data_align_power (abfd) = internal_a->o_algndata;
2129
      xcoff->modtype = internal_a->o_modtype;
2130
      xcoff->cputype = internal_a->o_cputype;
2131
      xcoff->maxdata = internal_a->o_maxdata;
2132
      xcoff->maxstack = internal_a->o_maxstack;
2133
    }
2134
#endif
2135
2136
#ifdef ARM
2137
  /* Set the flags field from the COFF header read in.  */
2138
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
2139
    coff->flags = 0;
2140
#endif
2141
2142
#ifdef COFF_WITH_PE
2143
  /* FIXME: I'm not sure this is ever executed, since peicode.h
2144
     defines coff_mkobject_hook.  */
2145
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
2146
    abfd->flags |= HAS_DEBUG;
2147
#endif
2148
2149
42
  return coff;
2150
42
}
coff-z8k.c:coff_mkobject_hook
Line
Count
Source
2080
49
{
2081
49
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2082
49
  coff_data_type *coff;
2083
2084
49
  if (! coff_mkobject (abfd))
2085
0
    return NULL;
2086
2087
49
  coff = coff_data (abfd);
2088
2089
49
  coff->sym_filepos = internal_f->f_symptr;
2090
2091
  /* These members communicate important constants about the symbol
2092
     table to GDB's symbol-reading code.  These `constants'
2093
     unfortunately vary among coff implementations...  */
2094
49
  coff->local_n_btmask = N_BTMASK;
2095
49
  coff->local_n_btshft = N_BTSHFT;
2096
49
  coff->local_n_tmask = N_TMASK;
2097
49
  coff->local_n_tshift = N_TSHIFT;
2098
49
  coff->local_symesz = bfd_coff_symesz (abfd);
2099
49
  coff->local_auxesz = bfd_coff_auxesz (abfd);
2100
49
  coff->local_linesz = bfd_coff_linesz (abfd);
2101
2102
49
  coff->timestamp = internal_f->f_timdat;
2103
2104
49
  obj_raw_syment_count (abfd) =
2105
49
    obj_conv_table_size (abfd) =
2106
49
      internal_f->f_nsyms;
2107
2108
#ifdef RS6000COFF_C
2109
  if ((internal_f->f_flags & F_SHROBJ) != 0)
2110
    abfd->flags |= DYNAMIC;
2111
  if (aouthdr != NULL && internal_f->f_opthdr >= bfd_coff_aoutsz (abfd))
2112
    {
2113
      struct internal_aouthdr *internal_a =
2114
  (struct internal_aouthdr *) aouthdr;
2115
      struct xcoff_tdata *xcoff;
2116
2117
      xcoff = xcoff_data (abfd);
2118
# ifdef U803XTOCMAGIC
2119
      xcoff->xcoff64 = internal_f->f_magic == U803XTOCMAGIC;
2120
# else
2121
      xcoff->xcoff64 = 0;
2122
# endif
2123
      xcoff->full_aouthdr = true;
2124
      xcoff->toc = internal_a->o_toc;
2125
      xcoff->sntoc = internal_a->o_sntoc;
2126
      xcoff->snentry = internal_a->o_snentry;
2127
      bfd_xcoff_text_align_power (abfd) = internal_a->o_algntext;
2128
      bfd_xcoff_data_align_power (abfd) = internal_a->o_algndata;
2129
      xcoff->modtype = internal_a->o_modtype;
2130
      xcoff->cputype = internal_a->o_cputype;
2131
      xcoff->maxdata = internal_a->o_maxdata;
2132
      xcoff->maxstack = internal_a->o_maxstack;
2133
    }
2134
#endif
2135
2136
#ifdef ARM
2137
  /* Set the flags field from the COFF header read in.  */
2138
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
2139
    coff->flags = 0;
2140
#endif
2141
2142
#ifdef COFF_WITH_PE
2143
  /* FIXME: I'm not sure this is ever executed, since peicode.h
2144
     defines coff_mkobject_hook.  */
2145
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
2146
    abfd->flags |= HAS_DEBUG;
2147
#endif
2148
2149
49
  return coff;
2150
49
}
2151
#endif
2152
2153
/* Determine the machine architecture and type.  FIXME: This is target
2154
   dependent because the magic numbers are defined in the target
2155
   dependent header files.  But there is no particular need for this.
2156
   If the magic numbers were moved to a separate file, this function
2157
   would be target independent and would also be much more successful
2158
   at linking together COFF files for different architectures.  */
2159
2160
static bool
2161
coff_set_arch_mach_hook (bfd *abfd, void * filehdr)
2162
6.61k
{
2163
6.61k
  unsigned long machine;
2164
6.61k
  enum bfd_architecture arch;
2165
6.61k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
6.61k
  machine = 0;
2169
6.61k
  switch (internal_f->f_magic)
2170
6.61k
    {
2171
#ifdef I386MAGIC
2172
19
    case I386MAGIC:
2173
66
    case I386PTXMAGIC:
2174
66
    case I386AIXMAGIC:   /* Danbury PS/2 AIX C Compiler.  */
2175
245
    case LYNXCOFFMAGIC:
2176
245
    case I386_APPLE_MAGIC:
2177
245
    case I386_FREEBSD_MAGIC:
2178
245
    case I386_LINUX_MAGIC:
2179
454
    case I386_NETBSD_MAGIC:
2180
454
      arch = bfd_arch_i386;
2181
454
      break;
2182
0
#endif
2183
#ifdef AMD64MAGIC
2184
78
    case AMD64MAGIC:
2185
292
    case AMD64_APPLE_MAGIC:
2186
292
    case AMD64_FREEBSD_MAGIC:
2187
292
    case AMD64_LINUX_MAGIC:
2188
303
    case AMD64_NETBSD_MAGIC:
2189
303
      arch = bfd_arch_i386;
2190
303
      machine = bfd_mach_x86_64;
2191
303
      break;
2192
0
#endif
2193
#ifdef IA64MAGIC
2194
75
    case IA64MAGIC:
2195
75
      arch = bfd_arch_ia64;
2196
75
      break;
2197
0
#endif
2198
#ifdef ARMMAGIC
2199
21
    case ARMMAGIC:
2200
21
    case ARMPEMAGIC:
2201
21
    case THUMBPEMAGIC:
2202
21
      arch = bfd_arch_arm;
2203
21
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2204
21
      if (machine == bfd_mach_arm_unknown)
2205
21
  {
2206
21
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2207
21
      {
2208
3
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2209
6
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2210
0
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2211
3
      default:
2212
3
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2213
0
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2214
0
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2215
        /* The COFF header does not have enough bits available
2216
     to cover all the different ARM architectures.  So
2217
     we interpret F_ARM_5, the highest flag value to mean
2218
     "the highest ARM architecture known to BFD" which is
2219
     currently the XScale.  */
2220
9
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2221
21
      }
2222
21
  }
2223
21
      break;
2224
21
#endif
2225
#ifdef AARCH64MAGIC
2226
124
    case AARCH64MAGIC:
2227
124
      arch = bfd_arch_aarch64;
2228
124
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2229
124
      break;
2230
0
#endif
2231
#ifdef LOONGARCH64MAGIC
2232
133
    case LOONGARCH64MAGIC:
2233
133
      arch = bfd_arch_loongarch;
2234
133
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2235
133
      break;
2236
0
#endif
2237
#ifdef Z80MAGIC
2238
42
    case Z80MAGIC:
2239
42
      arch = bfd_arch_z80;
2240
42
      switch (internal_f->f_flags & F_MACHMASK)
2241
42
  {
2242
0
  case bfd_mach_z80strict << 12:
2243
0
  case bfd_mach_z80 << 12:
2244
0
  case bfd_mach_z80n << 12:
2245
0
  case bfd_mach_z80full << 12:
2246
0
  case bfd_mach_r800 << 12:
2247
0
  case bfd_mach_gbz80 << 12:
2248
6
  case bfd_mach_z180 << 12:
2249
40
  case bfd_mach_ez80_z80 << 12:
2250
42
  case bfd_mach_ez80_adl << 12:
2251
42
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2252
42
    break;
2253
0
  default:
2254
0
    return false;
2255
42
  }
2256
42
      break;
2257
42
#endif
2258
#ifdef Z8KMAGIC
2259
49
    case Z8KMAGIC:
2260
49
      arch = bfd_arch_z8k;
2261
49
      switch (internal_f->f_flags & F_MACHMASK)
2262
49
  {
2263
8
  case F_Z8001:
2264
8
    machine = bfd_mach_z8001;
2265
8
    break;
2266
41
  case F_Z8002:
2267
41
    machine = bfd_mach_z8002;
2268
41
    break;
2269
0
  default:
2270
0
    return false;
2271
49
  }
2272
49
      break;
2273
49
#endif
2274
2275
#ifdef RS6000COFF_C
2276
#ifdef XCOFF64
2277
92
    case U64_TOCMAGIC:
2278
1.42k
    case U803XTOCMAGIC:
2279
#else
2280
131
    case U802ROMAGIC:
2281
131
    case U802WRMAGIC:
2282
133
    case U802TOCMAGIC:
2283
#endif
2284
133
      {
2285
133
  int cputype;
2286
2287
1.55k
  if (xcoff_data (abfd)->cputype != -1)
2288
0
    cputype = xcoff_data (abfd)->cputype & 0xff;
2289
1.55k
  else
2290
1.55k
    {
2291
      /* We did not get a value from the a.out header.  If the
2292
         file has not been stripped, we may be able to get the
2293
         architecture information from the first symbol, if it
2294
         is a .file symbol.  */
2295
1.55k
      if (obj_raw_syment_count (abfd) == 0)
2296
4
        cputype = 0;
2297
1.55k
      else
2298
1.55k
        {
2299
1.55k
    bfd_byte *buf;
2300
1.55k
    struct internal_syment sym;
2301
1.55k
    bfd_size_type amt = bfd_coff_symesz (abfd);
2302
2303
1.55k
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2304
0
      return false;
2305
1.55k
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2306
1.55k
    if (buf == NULL)
2307
0
      return false;
2308
1.55k
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2309
1.55k
    if (sym.n_sclass == C_FILE)
2310
2
      cputype = sym.n_type & 0xff;
2311
1.55k
    else
2312
1.55k
      cputype = 0;
2313
1.55k
    free (buf);
2314
1.55k
        }
2315
1.55k
    }
2316
2317
  /* FIXME: We don't handle all cases here.  */
2318
1.55k
  switch (cputype)
2319
1.55k
    {
2320
2
    default:
2321
1.55k
    case 0:
2322
1.55k
      arch = bfd_xcoff_architecture (abfd);
2323
1.55k
      machine = bfd_xcoff_machine (abfd);
2324
1.55k
      break;
2325
2326
0
    case 1:
2327
0
      arch = bfd_arch_powerpc;
2328
0
      machine = bfd_mach_ppc_601;
2329
0
      break;
2330
0
    case 2: /* 64 bit PowerPC */
2331
0
      arch = bfd_arch_powerpc;
2332
0
      machine = bfd_mach_ppc_620;
2333
0
      break;
2334
0
    case 3:
2335
0
      arch = bfd_arch_powerpc;
2336
0
      machine = bfd_mach_ppc;
2337
0
      break;
2338
0
    case 4:
2339
0
      arch = bfd_arch_rs6000;
2340
0
      machine = bfd_mach_rs6k;
2341
0
      break;
2342
1.55k
    }
2343
1.55k
      }
2344
1.55k
      break;
2345
1.55k
#endif
2346
2347
#ifdef SH_ARCH_MAGIC_BIG
2348
3.69k
    case SH_ARCH_MAGIC_BIG:
2349
3.69k
    case SH_ARCH_MAGIC_LITTLE:
2350
#ifdef COFF_WITH_PE
2351
1.31k
    case SH_ARCH_MAGIC_WINCE:
2352
#endif
2353
1.31k
      arch = bfd_arch_sh;
2354
1.31k
      break;
2355
0
#endif
2356
2357
#ifdef MIPS_ARCH_MAGIC_WINCE
2358
    case MIPS_ARCH_MAGIC_WINCE:
2359
      arch = bfd_arch_mips;
2360
      break;
2361
#endif
2362
2363
#ifdef SPARCMAGIC
2364
    case SPARCMAGIC:
2365
#ifdef LYNXCOFFMAGIC
2366
    case LYNXCOFFMAGIC:
2367
#endif
2368
      arch = bfd_arch_sparc;
2369
      break;
2370
#endif
2371
2372
#ifdef TIC30MAGIC
2373
40
    case TIC30MAGIC:
2374
40
      arch = bfd_arch_tic30;
2375
40
      break;
2376
0
#endif
2377
2378
#ifdef TICOFF0MAGIC
2379
#ifdef TICOFF_TARGET_ARCH
2380
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2381
68
    case TICOFF0MAGIC:
2382
68
      arch = TICOFF_TARGET_ARCH;
2383
68
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2384
68
      break;
2385
0
#endif
2386
0
#endif
2387
2388
#ifdef TICOFF1MAGIC
2389
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2390
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2391
0
    case TICOFF1MAGIC:
2392
0
    case TICOFF2MAGIC:
2393
0
      switch (internal_f->f_target_id)
2394
0
  {
2395
0
#ifdef TI_TARGET_ID
2396
0
  case TI_TARGET_ID:
2397
0
    arch = TICOFF_TARGET_ARCH;
2398
0
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2399
0
    break;
2400
0
#endif
2401
0
  default:
2402
0
    arch = bfd_arch_obscure;
2403
0
    _bfd_error_handler
2404
0
      (_("unrecognized TI COFF target id '0x%x'"),
2405
0
       internal_f->f_target_id);
2406
0
    break;
2407
0
  }
2408
0
      break;
2409
0
#endif
2410
2411
#ifdef MCOREMAGIC
2412
43
    case MCOREMAGIC:
2413
43
      arch = bfd_arch_mcore;
2414
43
      break;
2415
0
#endif
2416
2417
2
    default:      /* Unreadable input file type.  */
2418
2
      arch = bfd_arch_obscure;
2419
2
      break;
2420
6.61k
    }
2421
2422
6.61k
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
6.61k
  return true;
2424
6.61k
}
pei-i386.c:coff_set_arch_mach_hook
Line
Count
Source
2162
80
{
2163
80
  unsigned long machine;
2164
80
  enum bfd_architecture arch;
2165
80
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
80
  machine = 0;
2169
80
  switch (internal_f->f_magic)
2170
80
    {
2171
0
#ifdef I386MAGIC
2172
13
    case I386MAGIC:
2173
13
    case I386PTXMAGIC:
2174
13
    case I386AIXMAGIC:   /* Danbury PS/2 AIX C Compiler.  */
2175
80
    case LYNXCOFFMAGIC:
2176
80
    case I386_APPLE_MAGIC:
2177
80
    case I386_FREEBSD_MAGIC:
2178
80
    case I386_LINUX_MAGIC:
2179
80
    case I386_NETBSD_MAGIC:
2180
80
      arch = bfd_arch_i386;
2181
80
      break;
2182
0
#endif
2183
#ifdef AMD64MAGIC
2184
    case AMD64MAGIC:
2185
    case AMD64_APPLE_MAGIC:
2186
    case AMD64_FREEBSD_MAGIC:
2187
    case AMD64_LINUX_MAGIC:
2188
    case AMD64_NETBSD_MAGIC:
2189
      arch = bfd_arch_i386;
2190
      machine = bfd_mach_x86_64;
2191
      break;
2192
#endif
2193
#ifdef IA64MAGIC
2194
    case IA64MAGIC:
2195
      arch = bfd_arch_ia64;
2196
      break;
2197
#endif
2198
#ifdef ARMMAGIC
2199
    case ARMMAGIC:
2200
    case ARMPEMAGIC:
2201
    case THUMBPEMAGIC:
2202
      arch = bfd_arch_arm;
2203
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2204
      if (machine == bfd_mach_arm_unknown)
2205
  {
2206
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2207
      {
2208
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2209
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2210
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2211
      default:
2212
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2213
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2214
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2215
        /* The COFF header does not have enough bits available
2216
     to cover all the different ARM architectures.  So
2217
     we interpret F_ARM_5, the highest flag value to mean
2218
     "the highest ARM architecture known to BFD" which is
2219
     currently the XScale.  */
2220
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2221
      }
2222
  }
2223
      break;
2224
#endif
2225
#ifdef AARCH64MAGIC
2226
    case AARCH64MAGIC:
2227
      arch = bfd_arch_aarch64;
2228
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2229
      break;
2230
#endif
2231
#ifdef LOONGARCH64MAGIC
2232
    case LOONGARCH64MAGIC:
2233
      arch = bfd_arch_loongarch;
2234
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2235
      break;
2236
#endif
2237
#ifdef Z80MAGIC
2238
    case Z80MAGIC:
2239
      arch = bfd_arch_z80;
2240
      switch (internal_f->f_flags & F_MACHMASK)
2241
  {
2242
  case bfd_mach_z80strict << 12:
2243
  case bfd_mach_z80 << 12:
2244
  case bfd_mach_z80n << 12:
2245
  case bfd_mach_z80full << 12:
2246
  case bfd_mach_r800 << 12:
2247
  case bfd_mach_gbz80 << 12:
2248
  case bfd_mach_z180 << 12:
2249
  case bfd_mach_ez80_z80 << 12:
2250
  case bfd_mach_ez80_adl << 12:
2251
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2252
    break;
2253
  default:
2254
    return false;
2255
  }
2256
      break;
2257
#endif
2258
#ifdef Z8KMAGIC
2259
    case Z8KMAGIC:
2260
      arch = bfd_arch_z8k;
2261
      switch (internal_f->f_flags & F_MACHMASK)
2262
  {
2263
  case F_Z8001:
2264
    machine = bfd_mach_z8001;
2265
    break;
2266
  case F_Z8002:
2267
    machine = bfd_mach_z8002;
2268
    break;
2269
  default:
2270
    return false;
2271
  }
2272
      break;
2273
#endif
2274
2275
#ifdef RS6000COFF_C
2276
#ifdef XCOFF64
2277
    case U64_TOCMAGIC:
2278
    case U803XTOCMAGIC:
2279
#else
2280
    case U802ROMAGIC:
2281
    case U802WRMAGIC:
2282
    case U802TOCMAGIC:
2283
#endif
2284
      {
2285
  int cputype;
2286
2287
  if (xcoff_data (abfd)->cputype != -1)
2288
    cputype = xcoff_data (abfd)->cputype & 0xff;
2289
  else
2290
    {
2291
      /* We did not get a value from the a.out header.  If the
2292
         file has not been stripped, we may be able to get the
2293
         architecture information from the first symbol, if it
2294
         is a .file symbol.  */
2295
      if (obj_raw_syment_count (abfd) == 0)
2296
        cputype = 0;
2297
      else
2298
        {
2299
    bfd_byte *buf;
2300
    struct internal_syment sym;
2301
    bfd_size_type amt = bfd_coff_symesz (abfd);
2302
2303
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2304
      return false;
2305
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2306
    if (buf == NULL)
2307
      return false;
2308
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2309
    if (sym.n_sclass == C_FILE)
2310
      cputype = sym.n_type & 0xff;
2311
    else
2312
      cputype = 0;
2313
    free (buf);
2314
        }
2315
    }
2316
2317
  /* FIXME: We don't handle all cases here.  */
2318
  switch (cputype)
2319
    {
2320
    default:
2321
    case 0:
2322
      arch = bfd_xcoff_architecture (abfd);
2323
      machine = bfd_xcoff_machine (abfd);
2324
      break;
2325
2326
    case 1:
2327
      arch = bfd_arch_powerpc;
2328
      machine = bfd_mach_ppc_601;
2329
      break;
2330
    case 2: /* 64 bit PowerPC */
2331
      arch = bfd_arch_powerpc;
2332
      machine = bfd_mach_ppc_620;
2333
      break;
2334
    case 3:
2335
      arch = bfd_arch_powerpc;
2336
      machine = bfd_mach_ppc;
2337
      break;
2338
    case 4:
2339
      arch = bfd_arch_rs6000;
2340
      machine = bfd_mach_rs6k;
2341
      break;
2342
    }
2343
      }
2344
      break;
2345
#endif
2346
2347
#ifdef SH_ARCH_MAGIC_BIG
2348
    case SH_ARCH_MAGIC_BIG:
2349
    case SH_ARCH_MAGIC_LITTLE:
2350
#ifdef COFF_WITH_PE
2351
    case SH_ARCH_MAGIC_WINCE:
2352
#endif
2353
      arch = bfd_arch_sh;
2354
      break;
2355
#endif
2356
2357
#ifdef MIPS_ARCH_MAGIC_WINCE
2358
    case MIPS_ARCH_MAGIC_WINCE:
2359
      arch = bfd_arch_mips;
2360
      break;
2361
#endif
2362
2363
#ifdef SPARCMAGIC
2364
    case SPARCMAGIC:
2365
#ifdef LYNXCOFFMAGIC
2366
    case LYNXCOFFMAGIC:
2367
#endif
2368
      arch = bfd_arch_sparc;
2369
      break;
2370
#endif
2371
2372
#ifdef TIC30MAGIC
2373
    case TIC30MAGIC:
2374
      arch = bfd_arch_tic30;
2375
      break;
2376
#endif
2377
2378
#ifdef TICOFF0MAGIC
2379
#ifdef TICOFF_TARGET_ARCH
2380
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2381
    case TICOFF0MAGIC:
2382
      arch = TICOFF_TARGET_ARCH;
2383
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2384
      break;
2385
#endif
2386
#endif
2387
2388
#ifdef TICOFF1MAGIC
2389
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2390
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2391
    case TICOFF1MAGIC:
2392
    case TICOFF2MAGIC:
2393
      switch (internal_f->f_target_id)
2394
  {
2395
#ifdef TI_TARGET_ID
2396
  case TI_TARGET_ID:
2397
    arch = TICOFF_TARGET_ARCH;
2398
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2399
    break;
2400
#endif
2401
  default:
2402
    arch = bfd_arch_obscure;
2403
    _bfd_error_handler
2404
      (_("unrecognized TI COFF target id '0x%x'"),
2405
       internal_f->f_target_id);
2406
    break;
2407
  }
2408
      break;
2409
#endif
2410
2411
#ifdef MCOREMAGIC
2412
    case MCOREMAGIC:
2413
      arch = bfd_arch_mcore;
2414
      break;
2415
#endif
2416
2417
0
    default:      /* Unreadable input file type.  */
2418
0
      arch = bfd_arch_obscure;
2419
0
      break;
2420
80
    }
2421
2422
80
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
80
  return true;
2424
80
}
pe-x86_64.c:coff_set_arch_mach_hook
Line
Count
Source
2162
133
{
2163
133
  unsigned long machine;
2164
133
  enum bfd_architecture arch;
2165
133
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
133
  machine = 0;
2169
133
  switch (internal_f->f_magic)
2170
133
    {
2171
#ifdef I386MAGIC
2172
    case I386MAGIC:
2173
    case I386PTXMAGIC:
2174
    case I386AIXMAGIC:    /* Danbury PS/2 AIX C Compiler.  */
2175
    case LYNXCOFFMAGIC:
2176
    case I386_APPLE_MAGIC:
2177
    case I386_FREEBSD_MAGIC:
2178
    case I386_LINUX_MAGIC:
2179
    case I386_NETBSD_MAGIC:
2180
      arch = bfd_arch_i386;
2181
      break;
2182
#endif
2183
0
#ifdef AMD64MAGIC
2184
1
    case AMD64MAGIC:
2185
127
    case AMD64_APPLE_MAGIC:
2186
127
    case AMD64_FREEBSD_MAGIC:
2187
127
    case AMD64_LINUX_MAGIC:
2188
133
    case AMD64_NETBSD_MAGIC:
2189
133
      arch = bfd_arch_i386;
2190
133
      machine = bfd_mach_x86_64;
2191
133
      break;
2192
0
#endif
2193
#ifdef IA64MAGIC
2194
    case IA64MAGIC:
2195
      arch = bfd_arch_ia64;
2196
      break;
2197
#endif
2198
#ifdef ARMMAGIC
2199
    case ARMMAGIC:
2200
    case ARMPEMAGIC:
2201
    case THUMBPEMAGIC:
2202
      arch = bfd_arch_arm;
2203
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2204
      if (machine == bfd_mach_arm_unknown)
2205
  {
2206
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2207
      {
2208
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2209
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2210
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2211
      default:
2212
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2213
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2214
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2215
        /* The COFF header does not have enough bits available
2216
     to cover all the different ARM architectures.  So
2217
     we interpret F_ARM_5, the highest flag value to mean
2218
     "the highest ARM architecture known to BFD" which is
2219
     currently the XScale.  */
2220
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2221
      }
2222
  }
2223
      break;
2224
#endif
2225
#ifdef AARCH64MAGIC
2226
    case AARCH64MAGIC:
2227
      arch = bfd_arch_aarch64;
2228
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2229
      break;
2230
#endif
2231
#ifdef LOONGARCH64MAGIC
2232
    case LOONGARCH64MAGIC:
2233
      arch = bfd_arch_loongarch;
2234
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2235
      break;
2236
#endif
2237
#ifdef Z80MAGIC
2238
    case Z80MAGIC:
2239
      arch = bfd_arch_z80;
2240
      switch (internal_f->f_flags & F_MACHMASK)
2241
  {
2242
  case bfd_mach_z80strict << 12:
2243
  case bfd_mach_z80 << 12:
2244
  case bfd_mach_z80n << 12:
2245
  case bfd_mach_z80full << 12:
2246
  case bfd_mach_r800 << 12:
2247
  case bfd_mach_gbz80 << 12:
2248
  case bfd_mach_z180 << 12:
2249
  case bfd_mach_ez80_z80 << 12:
2250
  case bfd_mach_ez80_adl << 12:
2251
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2252
    break;
2253
  default:
2254
    return false;
2255
  }
2256
      break;
2257
#endif
2258
#ifdef Z8KMAGIC
2259
    case Z8KMAGIC:
2260
      arch = bfd_arch_z8k;
2261
      switch (internal_f->f_flags & F_MACHMASK)
2262
  {
2263
  case F_Z8001:
2264
    machine = bfd_mach_z8001;
2265
    break;
2266
  case F_Z8002:
2267
    machine = bfd_mach_z8002;
2268
    break;
2269
  default:
2270
    return false;
2271
  }
2272
      break;
2273
#endif
2274
2275
#ifdef RS6000COFF_C
2276
#ifdef XCOFF64
2277
    case U64_TOCMAGIC:
2278
    case U803XTOCMAGIC:
2279
#else
2280
    case U802ROMAGIC:
2281
    case U802WRMAGIC:
2282
    case U802TOCMAGIC:
2283
#endif
2284
      {
2285
  int cputype;
2286
2287
  if (xcoff_data (abfd)->cputype != -1)
2288
    cputype = xcoff_data (abfd)->cputype & 0xff;
2289
  else
2290
    {
2291
      /* We did not get a value from the a.out header.  If the
2292
         file has not been stripped, we may be able to get the
2293
         architecture information from the first symbol, if it
2294
         is a .file symbol.  */
2295
      if (obj_raw_syment_count (abfd) == 0)
2296
        cputype = 0;
2297
      else
2298
        {
2299
    bfd_byte *buf;
2300
    struct internal_syment sym;
2301
    bfd_size_type amt = bfd_coff_symesz (abfd);
2302
2303
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2304
      return false;
2305
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2306
    if (buf == NULL)
2307
      return false;
2308
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2309
    if (sym.n_sclass == C_FILE)
2310
      cputype = sym.n_type & 0xff;
2311
    else
2312
      cputype = 0;
2313
    free (buf);
2314
        }
2315
    }
2316
2317
  /* FIXME: We don't handle all cases here.  */
2318
  switch (cputype)
2319
    {
2320
    default:
2321
    case 0:
2322
      arch = bfd_xcoff_architecture (abfd);
2323
      machine = bfd_xcoff_machine (abfd);
2324
      break;
2325
2326
    case 1:
2327
      arch = bfd_arch_powerpc;
2328
      machine = bfd_mach_ppc_601;
2329
      break;
2330
    case 2: /* 64 bit PowerPC */
2331
      arch = bfd_arch_powerpc;
2332
      machine = bfd_mach_ppc_620;
2333
      break;
2334
    case 3:
2335
      arch = bfd_arch_powerpc;
2336
      machine = bfd_mach_ppc;
2337
      break;
2338
    case 4:
2339
      arch = bfd_arch_rs6000;
2340
      machine = bfd_mach_rs6k;
2341
      break;
2342
    }
2343
      }
2344
      break;
2345
#endif
2346
2347
#ifdef SH_ARCH_MAGIC_BIG
2348
    case SH_ARCH_MAGIC_BIG:
2349
    case SH_ARCH_MAGIC_LITTLE:
2350
#ifdef COFF_WITH_PE
2351
    case SH_ARCH_MAGIC_WINCE:
2352
#endif
2353
      arch = bfd_arch_sh;
2354
      break;
2355
#endif
2356
2357
#ifdef MIPS_ARCH_MAGIC_WINCE
2358
    case MIPS_ARCH_MAGIC_WINCE:
2359
      arch = bfd_arch_mips;
2360
      break;
2361
#endif
2362
2363
#ifdef SPARCMAGIC
2364
    case SPARCMAGIC:
2365
#ifdef LYNXCOFFMAGIC
2366
    case LYNXCOFFMAGIC:
2367
#endif
2368
      arch = bfd_arch_sparc;
2369
      break;
2370
#endif
2371
2372
#ifdef TIC30MAGIC
2373
    case TIC30MAGIC:
2374
      arch = bfd_arch_tic30;
2375
      break;
2376
#endif
2377
2378
#ifdef TICOFF0MAGIC
2379
#ifdef TICOFF_TARGET_ARCH
2380
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2381
    case TICOFF0MAGIC:
2382
      arch = TICOFF_TARGET_ARCH;
2383
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2384
      break;
2385
#endif
2386
#endif
2387
2388
#ifdef TICOFF1MAGIC
2389
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2390
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2391
    case TICOFF1MAGIC:
2392
    case TICOFF2MAGIC:
2393
      switch (internal_f->f_target_id)
2394
  {
2395
#ifdef TI_TARGET_ID
2396
  case TI_TARGET_ID:
2397
    arch = TICOFF_TARGET_ARCH;
2398
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2399
    break;
2400
#endif
2401
  default:
2402
    arch = bfd_arch_obscure;
2403
    _bfd_error_handler
2404
      (_("unrecognized TI COFF target id '0x%x'"),
2405
       internal_f->f_target_id);
2406
    break;
2407
  }
2408
      break;
2409
#endif
2410
2411
#ifdef MCOREMAGIC
2412
    case MCOREMAGIC:
2413
      arch = bfd_arch_mcore;
2414
      break;
2415
#endif
2416
2417
0
    default:      /* Unreadable input file type.  */
2418
0
      arch = bfd_arch_obscure;
2419
0
      break;
2420
133
    }
2421
2422
133
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
133
  return true;
2424
133
}
pei-x86_64.c:coff_set_arch_mach_hook
Line
Count
Source
2162
76
{
2163
76
  unsigned long machine;
2164
76
  enum bfd_architecture arch;
2165
76
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
76
  machine = 0;
2169
76
  switch (internal_f->f_magic)
2170
76
    {
2171
#ifdef I386MAGIC
2172
    case I386MAGIC:
2173
    case I386PTXMAGIC:
2174
    case I386AIXMAGIC:    /* Danbury PS/2 AIX C Compiler.  */
2175
    case LYNXCOFFMAGIC:
2176
    case I386_APPLE_MAGIC:
2177
    case I386_FREEBSD_MAGIC:
2178
    case I386_LINUX_MAGIC:
2179
    case I386_NETBSD_MAGIC:
2180
      arch = bfd_arch_i386;
2181
      break;
2182
#endif
2183
0
#ifdef AMD64MAGIC
2184
76
    case AMD64MAGIC:
2185
76
    case AMD64_APPLE_MAGIC:
2186
76
    case AMD64_FREEBSD_MAGIC:
2187
76
    case AMD64_LINUX_MAGIC:
2188
76
    case AMD64_NETBSD_MAGIC:
2189
76
      arch = bfd_arch_i386;
2190
76
      machine = bfd_mach_x86_64;
2191
76
      break;
2192
0
#endif
2193
#ifdef IA64MAGIC
2194
    case IA64MAGIC:
2195
      arch = bfd_arch_ia64;
2196
      break;
2197
#endif
2198
#ifdef ARMMAGIC
2199
    case ARMMAGIC:
2200
    case ARMPEMAGIC:
2201
    case THUMBPEMAGIC:
2202
      arch = bfd_arch_arm;
2203
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2204
      if (machine == bfd_mach_arm_unknown)
2205
  {
2206
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2207
      {
2208
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2209
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2210
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2211
      default:
2212
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2213
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2214
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2215
        /* The COFF header does not have enough bits available
2216
     to cover all the different ARM architectures.  So
2217
     we interpret F_ARM_5, the highest flag value to mean
2218
     "the highest ARM architecture known to BFD" which is
2219
     currently the XScale.  */
2220
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2221
      }
2222
  }
2223
      break;
2224
#endif
2225
#ifdef AARCH64MAGIC
2226
    case AARCH64MAGIC:
2227
      arch = bfd_arch_aarch64;
2228
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2229
      break;
2230
#endif
2231
#ifdef LOONGARCH64MAGIC
2232
    case LOONGARCH64MAGIC:
2233
      arch = bfd_arch_loongarch;
2234
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2235
      break;
2236
#endif
2237
#ifdef Z80MAGIC
2238
    case Z80MAGIC:
2239
      arch = bfd_arch_z80;
2240
      switch (internal_f->f_flags & F_MACHMASK)
2241
  {
2242
  case bfd_mach_z80strict << 12:
2243
  case bfd_mach_z80 << 12:
2244
  case bfd_mach_z80n << 12:
2245
  case bfd_mach_z80full << 12:
2246
  case bfd_mach_r800 << 12:
2247
  case bfd_mach_gbz80 << 12:
2248
  case bfd_mach_z180 << 12:
2249
  case bfd_mach_ez80_z80 << 12:
2250
  case bfd_mach_ez80_adl << 12:
2251
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2252
    break;
2253
  default:
2254
    return false;
2255
  }
2256
      break;
2257
#endif
2258
#ifdef Z8KMAGIC
2259
    case Z8KMAGIC:
2260
      arch = bfd_arch_z8k;
2261
      switch (internal_f->f_flags & F_MACHMASK)
2262
  {
2263
  case F_Z8001:
2264
    machine = bfd_mach_z8001;
2265
    break;
2266
  case F_Z8002:
2267
    machine = bfd_mach_z8002;
2268
    break;
2269
  default:
2270
    return false;
2271
  }
2272
      break;
2273
#endif
2274
2275
#ifdef RS6000COFF_C
2276
#ifdef XCOFF64
2277
    case U64_TOCMAGIC:
2278
    case U803XTOCMAGIC:
2279
#else
2280
    case U802ROMAGIC:
2281
    case U802WRMAGIC:
2282
    case U802TOCMAGIC:
2283
#endif
2284
      {
2285
  int cputype;
2286
2287
  if (xcoff_data (abfd)->cputype != -1)
2288
    cputype = xcoff_data (abfd)->cputype & 0xff;
2289
  else
2290
    {
2291
      /* We did not get a value from the a.out header.  If the
2292
         file has not been stripped, we may be able to get the
2293
         architecture information from the first symbol, if it
2294
         is a .file symbol.  */
2295
      if (obj_raw_syment_count (abfd) == 0)
2296
        cputype = 0;
2297
      else
2298
        {
2299
    bfd_byte *buf;
2300
    struct internal_syment sym;
2301
    bfd_size_type amt = bfd_coff_symesz (abfd);
2302
2303
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2304
      return false;
2305
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2306
    if (buf == NULL)
2307
      return false;
2308
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2309
    if (sym.n_sclass == C_FILE)
2310
      cputype = sym.n_type & 0xff;
2311
    else
2312
      cputype = 0;
2313
    free (buf);
2314
        }
2315
    }
2316
2317
  /* FIXME: We don't handle all cases here.  */
2318
  switch (cputype)
2319
    {
2320
    default:
2321
    case 0:
2322
      arch = bfd_xcoff_architecture (abfd);
2323
      machine = bfd_xcoff_machine (abfd);
2324
      break;
2325
2326
    case 1:
2327
      arch = bfd_arch_powerpc;
2328
      machine = bfd_mach_ppc_601;
2329
      break;
2330
    case 2: /* 64 bit PowerPC */
2331
      arch = bfd_arch_powerpc;
2332
      machine = bfd_mach_ppc_620;
2333
      break;
2334
    case 3:
2335
      arch = bfd_arch_powerpc;
2336
      machine = bfd_mach_ppc;
2337
      break;
2338
    case 4:
2339
      arch = bfd_arch_rs6000;
2340
      machine = bfd_mach_rs6k;
2341
      break;
2342
    }
2343
      }
2344
      break;
2345
#endif
2346
2347
#ifdef SH_ARCH_MAGIC_BIG
2348
    case SH_ARCH_MAGIC_BIG:
2349
    case SH_ARCH_MAGIC_LITTLE:
2350
#ifdef COFF_WITH_PE
2351
    case SH_ARCH_MAGIC_WINCE:
2352
#endif
2353
      arch = bfd_arch_sh;
2354
      break;
2355
#endif
2356
2357
#ifdef MIPS_ARCH_MAGIC_WINCE
2358
    case MIPS_ARCH_MAGIC_WINCE:
2359
      arch = bfd_arch_mips;
2360
      break;
2361
#endif
2362
2363
#ifdef SPARCMAGIC
2364
    case SPARCMAGIC:
2365
#ifdef LYNXCOFFMAGIC
2366
    case LYNXCOFFMAGIC:
2367
#endif
2368
      arch = bfd_arch_sparc;
2369
      break;
2370
#endif
2371
2372
#ifdef TIC30MAGIC
2373
    case TIC30MAGIC:
2374
      arch = bfd_arch_tic30;
2375
      break;
2376
#endif
2377
2378
#ifdef TICOFF0MAGIC
2379
#ifdef TICOFF_TARGET_ARCH
2380
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2381
    case TICOFF0MAGIC:
2382
      arch = TICOFF_TARGET_ARCH;
2383
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2384
      break;
2385
#endif
2386
#endif
2387
2388
#ifdef TICOFF1MAGIC
2389
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2390
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2391
    case TICOFF1MAGIC:
2392
    case TICOFF2MAGIC:
2393
      switch (internal_f->f_target_id)
2394
  {
2395
#ifdef TI_TARGET_ID
2396
  case TI_TARGET_ID:
2397
    arch = TICOFF_TARGET_ARCH;
2398
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2399
    break;
2400
#endif
2401
  default:
2402
    arch = bfd_arch_obscure;
2403
    _bfd_error_handler
2404
      (_("unrecognized TI COFF target id '0x%x'"),
2405
       internal_f->f_target_id);
2406
    break;
2407
  }
2408
      break;
2409
#endif
2410
2411
#ifdef MCOREMAGIC
2412
    case MCOREMAGIC:
2413
      arch = bfd_arch_mcore;
2414
      break;
2415
#endif
2416
2417
0
    default:      /* Unreadable input file type.  */
2418
0
      arch = bfd_arch_obscure;
2419
0
      break;
2420
76
    }
2421
2422
76
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
76
  return true;
2424
76
}
coff-x86_64.c:coff_set_arch_mach_hook
Line
Count
Source
2162
94
{
2163
94
  unsigned long machine;
2164
94
  enum bfd_architecture arch;
2165
94
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
94
  machine = 0;
2169
94
  switch (internal_f->f_magic)
2170
94
    {
2171
#ifdef I386MAGIC
2172
    case I386MAGIC:
2173
    case I386PTXMAGIC:
2174
    case I386AIXMAGIC:    /* Danbury PS/2 AIX C Compiler.  */
2175
    case LYNXCOFFMAGIC:
2176
    case I386_APPLE_MAGIC:
2177
    case I386_FREEBSD_MAGIC:
2178
    case I386_LINUX_MAGIC:
2179
    case I386_NETBSD_MAGIC:
2180
      arch = bfd_arch_i386;
2181
      break;
2182
#endif
2183
0
#ifdef AMD64MAGIC
2184
1
    case AMD64MAGIC:
2185
89
    case AMD64_APPLE_MAGIC:
2186
89
    case AMD64_FREEBSD_MAGIC:
2187
89
    case AMD64_LINUX_MAGIC:
2188
94
    case AMD64_NETBSD_MAGIC:
2189
94
      arch = bfd_arch_i386;
2190
94
      machine = bfd_mach_x86_64;
2191
94
      break;
2192
0
#endif
2193
#ifdef IA64MAGIC
2194
    case IA64MAGIC:
2195
      arch = bfd_arch_ia64;
2196
      break;
2197
#endif
2198
#ifdef ARMMAGIC
2199
    case ARMMAGIC:
2200
    case ARMPEMAGIC:
2201
    case THUMBPEMAGIC:
2202
      arch = bfd_arch_arm;
2203
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2204
      if (machine == bfd_mach_arm_unknown)
2205
  {
2206
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2207
      {
2208
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2209
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2210
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2211
      default:
2212
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2213
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2214
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2215
        /* The COFF header does not have enough bits available
2216
     to cover all the different ARM architectures.  So
2217
     we interpret F_ARM_5, the highest flag value to mean
2218
     "the highest ARM architecture known to BFD" which is
2219
     currently the XScale.  */
2220
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2221
      }
2222
  }
2223
      break;
2224
#endif
2225
#ifdef AARCH64MAGIC
2226
    case AARCH64MAGIC:
2227
      arch = bfd_arch_aarch64;
2228
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2229
      break;
2230
#endif
2231
#ifdef LOONGARCH64MAGIC
2232
    case LOONGARCH64MAGIC:
2233
      arch = bfd_arch_loongarch;
2234
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2235
      break;
2236
#endif
2237
#ifdef Z80MAGIC
2238
    case Z80MAGIC:
2239
      arch = bfd_arch_z80;
2240
      switch (internal_f->f_flags & F_MACHMASK)
2241
  {
2242
  case bfd_mach_z80strict << 12:
2243
  case bfd_mach_z80 << 12:
2244
  case bfd_mach_z80n << 12:
2245
  case bfd_mach_z80full << 12:
2246
  case bfd_mach_r800 << 12:
2247
  case bfd_mach_gbz80 << 12:
2248
  case bfd_mach_z180 << 12:
2249
  case bfd_mach_ez80_z80 << 12:
2250
  case bfd_mach_ez80_adl << 12:
2251
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2252
    break;
2253
  default:
2254
    return false;
2255
  }
2256
      break;
2257
#endif
2258
#ifdef Z8KMAGIC
2259
    case Z8KMAGIC:
2260
      arch = bfd_arch_z8k;
2261
      switch (internal_f->f_flags & F_MACHMASK)
2262
  {
2263
  case F_Z8001:
2264
    machine = bfd_mach_z8001;
2265
    break;
2266
  case F_Z8002:
2267
    machine = bfd_mach_z8002;
2268
    break;
2269
  default:
2270
    return false;
2271
  }
2272
      break;
2273
#endif
2274
2275
#ifdef RS6000COFF_C
2276
#ifdef XCOFF64
2277
    case U64_TOCMAGIC:
2278
    case U803XTOCMAGIC:
2279
#else
2280
    case U802ROMAGIC:
2281
    case U802WRMAGIC:
2282
    case U802TOCMAGIC:
2283
#endif
2284
      {
2285
  int cputype;
2286
2287
  if (xcoff_data (abfd)->cputype != -1)
2288
    cputype = xcoff_data (abfd)->cputype & 0xff;
2289
  else
2290
    {
2291
      /* We did not get a value from the a.out header.  If the
2292
         file has not been stripped, we may be able to get the
2293
         architecture information from the first symbol, if it
2294
         is a .file symbol.  */
2295
      if (obj_raw_syment_count (abfd) == 0)
2296
        cputype = 0;
2297
      else
2298
        {
2299
    bfd_byte *buf;
2300
    struct internal_syment sym;
2301
    bfd_size_type amt = bfd_coff_symesz (abfd);
2302
2303
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2304
      return false;
2305
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2306
    if (buf == NULL)
2307
      return false;
2308
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2309
    if (sym.n_sclass == C_FILE)
2310
      cputype = sym.n_type & 0xff;
2311
    else
2312
      cputype = 0;
2313
    free (buf);
2314
        }
2315
    }
2316
2317
  /* FIXME: We don't handle all cases here.  */
2318
  switch (cputype)
2319
    {
2320
    default:
2321
    case 0:
2322
      arch = bfd_xcoff_architecture (abfd);
2323
      machine = bfd_xcoff_machine (abfd);
2324
      break;
2325
2326
    case 1:
2327
      arch = bfd_arch_powerpc;
2328
      machine = bfd_mach_ppc_601;
2329
      break;
2330
    case 2: /* 64 bit PowerPC */
2331
      arch = bfd_arch_powerpc;
2332
      machine = bfd_mach_ppc_620;
2333
      break;
2334
    case 3:
2335
      arch = bfd_arch_powerpc;
2336
      machine = bfd_mach_ppc;
2337
      break;
2338
    case 4:
2339
      arch = bfd_arch_rs6000;
2340
      machine = bfd_mach_rs6k;
2341
      break;
2342
    }
2343
      }
2344
      break;
2345
#endif
2346
2347
#ifdef SH_ARCH_MAGIC_BIG
2348
    case SH_ARCH_MAGIC_BIG:
2349
    case SH_ARCH_MAGIC_LITTLE:
2350
#ifdef COFF_WITH_PE
2351
    case SH_ARCH_MAGIC_WINCE:
2352
#endif
2353
      arch = bfd_arch_sh;
2354
      break;
2355
#endif
2356
2357
#ifdef MIPS_ARCH_MAGIC_WINCE
2358
    case MIPS_ARCH_MAGIC_WINCE:
2359
      arch = bfd_arch_mips;
2360
      break;
2361
#endif
2362
2363
#ifdef SPARCMAGIC
2364
    case SPARCMAGIC:
2365
#ifdef LYNXCOFFMAGIC
2366
    case LYNXCOFFMAGIC:
2367
#endif
2368
      arch = bfd_arch_sparc;
2369
      break;
2370
#endif
2371
2372
#ifdef TIC30MAGIC
2373
    case TIC30MAGIC:
2374
      arch = bfd_arch_tic30;
2375
      break;
2376
#endif
2377
2378
#ifdef TICOFF0MAGIC
2379
#ifdef TICOFF_TARGET_ARCH
2380
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2381
    case TICOFF0MAGIC:
2382
      arch = TICOFF_TARGET_ARCH;
2383
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2384
      break;
2385
#endif
2386
#endif
2387
2388
#ifdef TICOFF1MAGIC
2389
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2390
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2391
    case TICOFF1MAGIC:
2392
    case TICOFF2MAGIC:
2393
      switch (internal_f->f_target_id)
2394
  {
2395
#ifdef TI_TARGET_ID
2396
  case TI_TARGET_ID:
2397
    arch = TICOFF_TARGET_ARCH;
2398
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2399
    break;
2400
#endif
2401
  default:
2402
    arch = bfd_arch_obscure;
2403
    _bfd_error_handler
2404
      (_("unrecognized TI COFF target id '0x%x'"),
2405
       internal_f->f_target_id);
2406
    break;
2407
  }
2408
      break;
2409
#endif
2410
2411
#ifdef MCOREMAGIC
2412
    case MCOREMAGIC:
2413
      arch = bfd_arch_mcore;
2414
      break;
2415
#endif
2416
2417
0
    default:      /* Unreadable input file type.  */
2418
0
      arch = bfd_arch_obscure;
2419
0
      break;
2420
94
    }
2421
2422
94
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
94
  return true;
2424
94
}
coff64-rs6000.c:coff_set_arch_mach_hook
Line
Count
Source
2162
1.42k
{
2163
1.42k
  unsigned long machine;
2164
1.42k
  enum bfd_architecture arch;
2165
1.42k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
1.42k
  machine = 0;
2169
1.42k
  switch (internal_f->f_magic)
2170
1.42k
    {
2171
#ifdef I386MAGIC
2172
    case I386MAGIC:
2173
    case I386PTXMAGIC:
2174
    case I386AIXMAGIC:    /* Danbury PS/2 AIX C Compiler.  */
2175
    case LYNXCOFFMAGIC:
2176
    case I386_APPLE_MAGIC:
2177
    case I386_FREEBSD_MAGIC:
2178
    case I386_LINUX_MAGIC:
2179
    case I386_NETBSD_MAGIC:
2180
      arch = bfd_arch_i386;
2181
      break;
2182
#endif
2183
#ifdef AMD64MAGIC
2184
    case AMD64MAGIC:
2185
    case AMD64_APPLE_MAGIC:
2186
    case AMD64_FREEBSD_MAGIC:
2187
    case AMD64_LINUX_MAGIC:
2188
    case AMD64_NETBSD_MAGIC:
2189
      arch = bfd_arch_i386;
2190
      machine = bfd_mach_x86_64;
2191
      break;
2192
#endif
2193
#ifdef IA64MAGIC
2194
    case IA64MAGIC:
2195
      arch = bfd_arch_ia64;
2196
      break;
2197
#endif
2198
#ifdef ARMMAGIC
2199
    case ARMMAGIC:
2200
    case ARMPEMAGIC:
2201
    case THUMBPEMAGIC:
2202
      arch = bfd_arch_arm;
2203
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2204
      if (machine == bfd_mach_arm_unknown)
2205
  {
2206
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2207
      {
2208
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2209
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2210
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2211
      default:
2212
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2213
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2214
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2215
        /* The COFF header does not have enough bits available
2216
     to cover all the different ARM architectures.  So
2217
     we interpret F_ARM_5, the highest flag value to mean
2218
     "the highest ARM architecture known to BFD" which is
2219
     currently the XScale.  */
2220
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2221
      }
2222
  }
2223
      break;
2224
#endif
2225
#ifdef AARCH64MAGIC
2226
    case AARCH64MAGIC:
2227
      arch = bfd_arch_aarch64;
2228
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2229
      break;
2230
#endif
2231
#ifdef LOONGARCH64MAGIC
2232
    case LOONGARCH64MAGIC:
2233
      arch = bfd_arch_loongarch;
2234
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2235
      break;
2236
#endif
2237
#ifdef Z80MAGIC
2238
    case Z80MAGIC:
2239
      arch = bfd_arch_z80;
2240
      switch (internal_f->f_flags & F_MACHMASK)
2241
  {
2242
  case bfd_mach_z80strict << 12:
2243
  case bfd_mach_z80 << 12:
2244
  case bfd_mach_z80n << 12:
2245
  case bfd_mach_z80full << 12:
2246
  case bfd_mach_r800 << 12:
2247
  case bfd_mach_gbz80 << 12:
2248
  case bfd_mach_z180 << 12:
2249
  case bfd_mach_ez80_z80 << 12:
2250
  case bfd_mach_ez80_adl << 12:
2251
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2252
    break;
2253
  default:
2254
    return false;
2255
  }
2256
      break;
2257
#endif
2258
#ifdef Z8KMAGIC
2259
    case Z8KMAGIC:
2260
      arch = bfd_arch_z8k;
2261
      switch (internal_f->f_flags & F_MACHMASK)
2262
  {
2263
  case F_Z8001:
2264
    machine = bfd_mach_z8001;
2265
    break;
2266
  case F_Z8002:
2267
    machine = bfd_mach_z8002;
2268
    break;
2269
  default:
2270
    return false;
2271
  }
2272
      break;
2273
#endif
2274
2275
0
#ifdef RS6000COFF_C
2276
0
#ifdef XCOFF64
2277
92
    case U64_TOCMAGIC:
2278
1.42k
    case U803XTOCMAGIC:
2279
#else
2280
    case U802ROMAGIC:
2281
    case U802WRMAGIC:
2282
    case U802TOCMAGIC:
2283
#endif
2284
1.42k
      {
2285
1.42k
  int cputype;
2286
2287
1.42k
  if (xcoff_data (abfd)->cputype != -1)
2288
0
    cputype = xcoff_data (abfd)->cputype & 0xff;
2289
1.42k
  else
2290
1.42k
    {
2291
      /* We did not get a value from the a.out header.  If the
2292
         file has not been stripped, we may be able to get the
2293
         architecture information from the first symbol, if it
2294
         is a .file symbol.  */
2295
1.42k
      if (obj_raw_syment_count (abfd) == 0)
2296
2
        cputype = 0;
2297
1.42k
      else
2298
1.42k
        {
2299
1.42k
    bfd_byte *buf;
2300
1.42k
    struct internal_syment sym;
2301
1.42k
    bfd_size_type amt = bfd_coff_symesz (abfd);
2302
2303
1.42k
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2304
0
      return false;
2305
1.42k
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2306
1.42k
    if (buf == NULL)
2307
0
      return false;
2308
1.42k
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2309
1.42k
    if (sym.n_sclass == C_FILE)
2310
0
      cputype = sym.n_type & 0xff;
2311
1.42k
    else
2312
1.42k
      cputype = 0;
2313
1.42k
    free (buf);
2314
1.42k
        }
2315
1.42k
    }
2316
2317
  /* FIXME: We don't handle all cases here.  */
2318
1.42k
  switch (cputype)
2319
1.42k
    {
2320
0
    default:
2321
1.42k
    case 0:
2322
1.42k
      arch = bfd_xcoff_architecture (abfd);
2323
1.42k
      machine = bfd_xcoff_machine (abfd);
2324
1.42k
      break;
2325
2326
0
    case 1:
2327
0
      arch = bfd_arch_powerpc;
2328
0
      machine = bfd_mach_ppc_601;
2329
0
      break;
2330
0
    case 2: /* 64 bit PowerPC */
2331
0
      arch = bfd_arch_powerpc;
2332
0
      machine = bfd_mach_ppc_620;
2333
0
      break;
2334
0
    case 3:
2335
0
      arch = bfd_arch_powerpc;
2336
0
      machine = bfd_mach_ppc;
2337
0
      break;
2338
0
    case 4:
2339
0
      arch = bfd_arch_rs6000;
2340
0
      machine = bfd_mach_rs6k;
2341
0
      break;
2342
1.42k
    }
2343
1.42k
      }
2344
1.42k
      break;
2345
1.42k
#endif
2346
2347
#ifdef SH_ARCH_MAGIC_BIG
2348
    case SH_ARCH_MAGIC_BIG:
2349
    case SH_ARCH_MAGIC_LITTLE:
2350
#ifdef COFF_WITH_PE
2351
    case SH_ARCH_MAGIC_WINCE:
2352
#endif
2353
      arch = bfd_arch_sh;
2354
      break;
2355
#endif
2356
2357
#ifdef MIPS_ARCH_MAGIC_WINCE
2358
    case MIPS_ARCH_MAGIC_WINCE:
2359
      arch = bfd_arch_mips;
2360
      break;
2361
#endif
2362
2363
#ifdef SPARCMAGIC
2364
    case SPARCMAGIC:
2365
#ifdef LYNXCOFFMAGIC
2366
    case LYNXCOFFMAGIC:
2367
#endif
2368
      arch = bfd_arch_sparc;
2369
      break;
2370
#endif
2371
2372
#ifdef TIC30MAGIC
2373
    case TIC30MAGIC:
2374
      arch = bfd_arch_tic30;
2375
      break;
2376
#endif
2377
2378
#ifdef TICOFF0MAGIC
2379
#ifdef TICOFF_TARGET_ARCH
2380
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2381
    case TICOFF0MAGIC:
2382
      arch = TICOFF_TARGET_ARCH;
2383
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2384
      break;
2385
#endif
2386
#endif
2387
2388
#ifdef TICOFF1MAGIC
2389
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2390
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2391
    case TICOFF1MAGIC:
2392
    case TICOFF2MAGIC:
2393
      switch (internal_f->f_target_id)
2394
  {
2395
#ifdef TI_TARGET_ID
2396
  case TI_TARGET_ID:
2397
    arch = TICOFF_TARGET_ARCH;
2398
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2399
    break;
2400
#endif
2401
  default:
2402
    arch = bfd_arch_obscure;
2403
    _bfd_error_handler
2404
      (_("unrecognized TI COFF target id '0x%x'"),
2405
       internal_f->f_target_id);
2406
    break;
2407
  }
2408
      break;
2409
#endif
2410
2411
#ifdef MCOREMAGIC
2412
    case MCOREMAGIC:
2413
      arch = bfd_arch_mcore;
2414
      break;
2415
#endif
2416
2417
1.42k
    default:      /* Unreadable input file type.  */
2418
0
      arch = bfd_arch_obscure;
2419
0
      break;
2420
1.42k
    }
2421
2422
1.42k
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
1.42k
  return true;
2424
1.42k
}
pe-aarch64.c:coff_set_arch_mach_hook
Line
Count
Source
2162
61
{
2163
61
  unsigned long machine;
2164
61
  enum bfd_architecture arch;
2165
61
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
61
  machine = 0;
2169
61
  switch (internal_f->f_magic)
2170
61
    {
2171
#ifdef I386MAGIC
2172
    case I386MAGIC:
2173
    case I386PTXMAGIC:
2174
    case I386AIXMAGIC:    /* Danbury PS/2 AIX C Compiler.  */
2175
    case LYNXCOFFMAGIC:
2176
    case I386_APPLE_MAGIC:
2177
    case I386_FREEBSD_MAGIC:
2178
    case I386_LINUX_MAGIC:
2179
    case I386_NETBSD_MAGIC:
2180
      arch = bfd_arch_i386;
2181
      break;
2182
#endif
2183
#ifdef AMD64MAGIC
2184
    case AMD64MAGIC:
2185
    case AMD64_APPLE_MAGIC:
2186
    case AMD64_FREEBSD_MAGIC:
2187
    case AMD64_LINUX_MAGIC:
2188
    case AMD64_NETBSD_MAGIC:
2189
      arch = bfd_arch_i386;
2190
      machine = bfd_mach_x86_64;
2191
      break;
2192
#endif
2193
#ifdef IA64MAGIC
2194
    case IA64MAGIC:
2195
      arch = bfd_arch_ia64;
2196
      break;
2197
#endif
2198
#ifdef ARMMAGIC
2199
    case ARMMAGIC:
2200
    case ARMPEMAGIC:
2201
    case THUMBPEMAGIC:
2202
      arch = bfd_arch_arm;
2203
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2204
      if (machine == bfd_mach_arm_unknown)
2205
  {
2206
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2207
      {
2208
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2209
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2210
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2211
      default:
2212
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2213
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2214
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2215
        /* The COFF header does not have enough bits available
2216
     to cover all the different ARM architectures.  So
2217
     we interpret F_ARM_5, the highest flag value to mean
2218
     "the highest ARM architecture known to BFD" which is
2219
     currently the XScale.  */
2220
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2221
      }
2222
  }
2223
      break;
2224
#endif
2225
0
#ifdef AARCH64MAGIC
2226
61
    case AARCH64MAGIC:
2227
61
      arch = bfd_arch_aarch64;
2228
61
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2229
61
      break;
2230
0
#endif
2231
#ifdef LOONGARCH64MAGIC
2232
    case LOONGARCH64MAGIC:
2233
      arch = bfd_arch_loongarch;
2234
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2235
      break;
2236
#endif
2237
#ifdef Z80MAGIC
2238
    case Z80MAGIC:
2239
      arch = bfd_arch_z80;
2240
      switch (internal_f->f_flags & F_MACHMASK)
2241
  {
2242
  case bfd_mach_z80strict << 12:
2243
  case bfd_mach_z80 << 12:
2244
  case bfd_mach_z80n << 12:
2245
  case bfd_mach_z80full << 12:
2246
  case bfd_mach_r800 << 12:
2247
  case bfd_mach_gbz80 << 12:
2248
  case bfd_mach_z180 << 12:
2249
  case bfd_mach_ez80_z80 << 12:
2250
  case bfd_mach_ez80_adl << 12:
2251
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2252
    break;
2253
  default:
2254
    return false;
2255
  }
2256
      break;
2257
#endif
2258
#ifdef Z8KMAGIC
2259
    case Z8KMAGIC:
2260
      arch = bfd_arch_z8k;
2261
      switch (internal_f->f_flags & F_MACHMASK)
2262
  {
2263
  case F_Z8001:
2264
    machine = bfd_mach_z8001;
2265
    break;
2266
  case F_Z8002:
2267
    machine = bfd_mach_z8002;
2268
    break;
2269
  default:
2270
    return false;
2271
  }
2272
      break;
2273
#endif
2274
2275
#ifdef RS6000COFF_C
2276
#ifdef XCOFF64
2277
    case U64_TOCMAGIC:
2278
    case U803XTOCMAGIC:
2279
#else
2280
    case U802ROMAGIC:
2281
    case U802WRMAGIC:
2282
    case U802TOCMAGIC:
2283
#endif
2284
      {
2285
  int cputype;
2286
2287
  if (xcoff_data (abfd)->cputype != -1)
2288
    cputype = xcoff_data (abfd)->cputype & 0xff;
2289
  else
2290
    {
2291
      /* We did not get a value from the a.out header.  If the
2292
         file has not been stripped, we may be able to get the
2293
         architecture information from the first symbol, if it
2294
         is a .file symbol.  */
2295
      if (obj_raw_syment_count (abfd) == 0)
2296
        cputype = 0;
2297
      else
2298
        {
2299
    bfd_byte *buf;
2300
    struct internal_syment sym;
2301
    bfd_size_type amt = bfd_coff_symesz (abfd);
2302
2303
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2304
      return false;
2305
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2306
    if (buf == NULL)
2307
      return false;
2308
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2309
    if (sym.n_sclass == C_FILE)
2310
      cputype = sym.n_type & 0xff;
2311
    else
2312
      cputype = 0;
2313
    free (buf);
2314
        }
2315
    }
2316
2317
  /* FIXME: We don't handle all cases here.  */
2318
  switch (cputype)
2319
    {
2320
    default:
2321
    case 0:
2322
      arch = bfd_xcoff_architecture (abfd);
2323
      machine = bfd_xcoff_machine (abfd);
2324
      break;
2325
2326
    case 1:
2327
      arch = bfd_arch_powerpc;
2328
      machine = bfd_mach_ppc_601;
2329
      break;
2330
    case 2: /* 64 bit PowerPC */
2331
      arch = bfd_arch_powerpc;
2332
      machine = bfd_mach_ppc_620;
2333
      break;
2334
    case 3:
2335
      arch = bfd_arch_powerpc;
2336
      machine = bfd_mach_ppc;
2337
      break;
2338
    case 4:
2339
      arch = bfd_arch_rs6000;
2340
      machine = bfd_mach_rs6k;
2341
      break;
2342
    }
2343
      }
2344
      break;
2345
#endif
2346
2347
#ifdef SH_ARCH_MAGIC_BIG
2348
    case SH_ARCH_MAGIC_BIG:
2349
    case SH_ARCH_MAGIC_LITTLE:
2350
#ifdef COFF_WITH_PE
2351
    case SH_ARCH_MAGIC_WINCE:
2352
#endif
2353
      arch = bfd_arch_sh;
2354
      break;
2355
#endif
2356
2357
#ifdef MIPS_ARCH_MAGIC_WINCE
2358
    case MIPS_ARCH_MAGIC_WINCE:
2359
      arch = bfd_arch_mips;
2360
      break;
2361
#endif
2362
2363
#ifdef SPARCMAGIC
2364
    case SPARCMAGIC:
2365
#ifdef LYNXCOFFMAGIC
2366
    case LYNXCOFFMAGIC:
2367
#endif
2368
      arch = bfd_arch_sparc;
2369
      break;
2370
#endif
2371
2372
#ifdef TIC30MAGIC
2373
    case TIC30MAGIC:
2374
      arch = bfd_arch_tic30;
2375
      break;
2376
#endif
2377
2378
#ifdef TICOFF0MAGIC
2379
#ifdef TICOFF_TARGET_ARCH
2380
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2381
    case TICOFF0MAGIC:
2382
      arch = TICOFF_TARGET_ARCH;
2383
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2384
      break;
2385
#endif
2386
#endif
2387
2388
#ifdef TICOFF1MAGIC
2389
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2390
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2391
    case TICOFF1MAGIC:
2392
    case TICOFF2MAGIC:
2393
      switch (internal_f->f_target_id)
2394
  {
2395
#ifdef TI_TARGET_ID
2396
  case TI_TARGET_ID:
2397
    arch = TICOFF_TARGET_ARCH;
2398
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2399
    break;
2400
#endif
2401
  default:
2402
    arch = bfd_arch_obscure;
2403
    _bfd_error_handler
2404
      (_("unrecognized TI COFF target id '0x%x'"),
2405
       internal_f->f_target_id);
2406
    break;
2407
  }
2408
      break;
2409
#endif
2410
2411
#ifdef MCOREMAGIC
2412
    case MCOREMAGIC:
2413
      arch = bfd_arch_mcore;
2414
      break;
2415
#endif
2416
2417
0
    default:      /* Unreadable input file type.  */
2418
0
      arch = bfd_arch_obscure;
2419
0
      break;
2420
61
    }
2421
2422
61
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
61
  return true;
2424
61
}
pei-aarch64.c:coff_set_arch_mach_hook
Line
Count
Source
2162
63
{
2163
63
  unsigned long machine;
2164
63
  enum bfd_architecture arch;
2165
63
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
63
  machine = 0;
2169
63
  switch (internal_f->f_magic)
2170
63
    {
2171
#ifdef I386MAGIC
2172
    case I386MAGIC:
2173
    case I386PTXMAGIC:
2174
    case I386AIXMAGIC:    /* Danbury PS/2 AIX C Compiler.  */
2175
    case LYNXCOFFMAGIC:
2176
    case I386_APPLE_MAGIC:
2177
    case I386_FREEBSD_MAGIC:
2178
    case I386_LINUX_MAGIC:
2179
    case I386_NETBSD_MAGIC:
2180
      arch = bfd_arch_i386;
2181
      break;
2182
#endif
2183
#ifdef AMD64MAGIC
2184
    case AMD64MAGIC:
2185
    case AMD64_APPLE_MAGIC:
2186
    case AMD64_FREEBSD_MAGIC:
2187
    case AMD64_LINUX_MAGIC:
2188
    case AMD64_NETBSD_MAGIC:
2189
      arch = bfd_arch_i386;
2190
      machine = bfd_mach_x86_64;
2191
      break;
2192
#endif
2193
#ifdef IA64MAGIC
2194
    case IA64MAGIC:
2195
      arch = bfd_arch_ia64;
2196
      break;
2197
#endif
2198
#ifdef ARMMAGIC
2199
    case ARMMAGIC:
2200
    case ARMPEMAGIC:
2201
    case THUMBPEMAGIC:
2202
      arch = bfd_arch_arm;
2203
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2204
      if (machine == bfd_mach_arm_unknown)
2205
  {
2206
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2207
      {
2208
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2209
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2210
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2211
      default:
2212
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2213
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2214
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2215
        /* The COFF header does not have enough bits available
2216
     to cover all the different ARM architectures.  So
2217
     we interpret F_ARM_5, the highest flag value to mean
2218
     "the highest ARM architecture known to BFD" which is
2219
     currently the XScale.  */
2220
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2221
      }
2222
  }
2223
      break;
2224
#endif
2225
0
#ifdef AARCH64MAGIC
2226
63
    case AARCH64MAGIC:
2227
63
      arch = bfd_arch_aarch64;
2228
63
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2229
63
      break;
2230
0
#endif
2231
#ifdef LOONGARCH64MAGIC
2232
    case LOONGARCH64MAGIC:
2233
      arch = bfd_arch_loongarch;
2234
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2235
      break;
2236
#endif
2237
#ifdef Z80MAGIC
2238
    case Z80MAGIC:
2239
      arch = bfd_arch_z80;
2240
      switch (internal_f->f_flags & F_MACHMASK)
2241
  {
2242
  case bfd_mach_z80strict << 12:
2243
  case bfd_mach_z80 << 12:
2244
  case bfd_mach_z80n << 12:
2245
  case bfd_mach_z80full << 12:
2246
  case bfd_mach_r800 << 12:
2247
  case bfd_mach_gbz80 << 12:
2248
  case bfd_mach_z180 << 12:
2249
  case bfd_mach_ez80_z80 << 12:
2250
  case bfd_mach_ez80_adl << 12:
2251
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2252
    break;
2253
  default:
2254
    return false;
2255
  }
2256
      break;
2257
#endif
2258
#ifdef Z8KMAGIC
2259
    case Z8KMAGIC:
2260
      arch = bfd_arch_z8k;
2261
      switch (internal_f->f_flags & F_MACHMASK)
2262
  {
2263
  case F_Z8001:
2264
    machine = bfd_mach_z8001;
2265
    break;
2266
  case F_Z8002:
2267
    machine = bfd_mach_z8002;
2268
    break;
2269
  default:
2270
    return false;
2271
  }
2272
      break;
2273
#endif
2274
2275
#ifdef RS6000COFF_C
2276
#ifdef XCOFF64
2277
    case U64_TOCMAGIC:
2278
    case U803XTOCMAGIC:
2279
#else
2280
    case U802ROMAGIC:
2281
    case U802WRMAGIC:
2282
    case U802TOCMAGIC:
2283
#endif
2284
      {
2285
  int cputype;
2286
2287
  if (xcoff_data (abfd)->cputype != -1)
2288
    cputype = xcoff_data (abfd)->cputype & 0xff;
2289
  else
2290
    {
2291
      /* We did not get a value from the a.out header.  If the
2292
         file has not been stripped, we may be able to get the
2293
         architecture information from the first symbol, if it
2294
         is a .file symbol.  */
2295
      if (obj_raw_syment_count (abfd) == 0)
2296
        cputype = 0;
2297
      else
2298
        {
2299
    bfd_byte *buf;
2300
    struct internal_syment sym;
2301
    bfd_size_type amt = bfd_coff_symesz (abfd);
2302
2303
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2304
      return false;
2305
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2306
    if (buf == NULL)
2307
      return false;
2308
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2309
    if (sym.n_sclass == C_FILE)
2310
      cputype = sym.n_type & 0xff;
2311
    else
2312
      cputype = 0;
2313
    free (buf);
2314
        }
2315
    }
2316
2317
  /* FIXME: We don't handle all cases here.  */
2318
  switch (cputype)
2319
    {
2320
    default:
2321
    case 0:
2322
      arch = bfd_xcoff_architecture (abfd);
2323
      machine = bfd_xcoff_machine (abfd);
2324
      break;
2325
2326
    case 1:
2327
      arch = bfd_arch_powerpc;
2328
      machine = bfd_mach_ppc_601;
2329
      break;
2330
    case 2: /* 64 bit PowerPC */
2331
      arch = bfd_arch_powerpc;
2332
      machine = bfd_mach_ppc_620;
2333
      break;
2334
    case 3:
2335
      arch = bfd_arch_powerpc;
2336
      machine = bfd_mach_ppc;
2337
      break;
2338
    case 4:
2339
      arch = bfd_arch_rs6000;
2340
      machine = bfd_mach_rs6k;
2341
      break;
2342
    }
2343
      }
2344
      break;
2345
#endif
2346
2347
#ifdef SH_ARCH_MAGIC_BIG
2348
    case SH_ARCH_MAGIC_BIG:
2349
    case SH_ARCH_MAGIC_LITTLE:
2350
#ifdef COFF_WITH_PE
2351
    case SH_ARCH_MAGIC_WINCE:
2352
#endif
2353
      arch = bfd_arch_sh;
2354
      break;
2355
#endif
2356
2357
#ifdef MIPS_ARCH_MAGIC_WINCE
2358
    case MIPS_ARCH_MAGIC_WINCE:
2359
      arch = bfd_arch_mips;
2360
      break;
2361
#endif
2362
2363
#ifdef SPARCMAGIC
2364
    case SPARCMAGIC:
2365
#ifdef LYNXCOFFMAGIC
2366
    case LYNXCOFFMAGIC:
2367
#endif
2368
      arch = bfd_arch_sparc;
2369
      break;
2370
#endif
2371
2372
#ifdef TIC30MAGIC
2373
    case TIC30MAGIC:
2374
      arch = bfd_arch_tic30;
2375
      break;
2376
#endif
2377
2378
#ifdef TICOFF0MAGIC
2379
#ifdef TICOFF_TARGET_ARCH
2380
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2381
    case TICOFF0MAGIC:
2382
      arch = TICOFF_TARGET_ARCH;
2383
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2384
      break;
2385
#endif
2386
#endif
2387
2388
#ifdef TICOFF1MAGIC
2389
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2390
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2391
    case TICOFF1MAGIC:
2392
    case TICOFF2MAGIC:
2393
      switch (internal_f->f_target_id)
2394
  {
2395
#ifdef TI_TARGET_ID
2396
  case TI_TARGET_ID:
2397
    arch = TICOFF_TARGET_ARCH;
2398
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2399
    break;
2400
#endif
2401
  default:
2402
    arch = bfd_arch_obscure;
2403
    _bfd_error_handler
2404
      (_("unrecognized TI COFF target id '0x%x'"),
2405
       internal_f->f_target_id);
2406
    break;
2407
  }
2408
      break;
2409
#endif
2410
2411
#ifdef MCOREMAGIC
2412
    case MCOREMAGIC:
2413
      arch = bfd_arch_mcore;
2414
      break;
2415
#endif
2416
2417
0
    default:      /* Unreadable input file type.  */
2418
0
      arch = bfd_arch_obscure;
2419
0
      break;
2420
63
    }
2421
2422
63
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
63
  return true;
2424
63
}
pei-ia64.c:coff_set_arch_mach_hook
Line
Count
Source
2162
75
{
2163
75
  unsigned long machine;
2164
75
  enum bfd_architecture arch;
2165
75
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
75
  machine = 0;
2169
75
  switch (internal_f->f_magic)
2170
75
    {
2171
#ifdef I386MAGIC
2172
    case I386MAGIC:
2173
    case I386PTXMAGIC:
2174
    case I386AIXMAGIC:    /* Danbury PS/2 AIX C Compiler.  */
2175
    case LYNXCOFFMAGIC:
2176
    case I386_APPLE_MAGIC:
2177
    case I386_FREEBSD_MAGIC:
2178
    case I386_LINUX_MAGIC:
2179
    case I386_NETBSD_MAGIC:
2180
      arch = bfd_arch_i386;
2181
      break;
2182
#endif
2183
#ifdef AMD64MAGIC
2184
    case AMD64MAGIC:
2185
    case AMD64_APPLE_MAGIC:
2186
    case AMD64_FREEBSD_MAGIC:
2187
    case AMD64_LINUX_MAGIC:
2188
    case AMD64_NETBSD_MAGIC:
2189
      arch = bfd_arch_i386;
2190
      machine = bfd_mach_x86_64;
2191
      break;
2192
#endif
2193
0
#ifdef IA64MAGIC
2194
75
    case IA64MAGIC:
2195
75
      arch = bfd_arch_ia64;
2196
75
      break;
2197
0
#endif
2198
#ifdef ARMMAGIC
2199
    case ARMMAGIC:
2200
    case ARMPEMAGIC:
2201
    case THUMBPEMAGIC:
2202
      arch = bfd_arch_arm;
2203
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2204
      if (machine == bfd_mach_arm_unknown)
2205
  {
2206
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2207
      {
2208
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2209
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2210
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2211
      default:
2212
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2213
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2214
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2215
        /* The COFF header does not have enough bits available
2216
     to cover all the different ARM architectures.  So
2217
     we interpret F_ARM_5, the highest flag value to mean
2218
     "the highest ARM architecture known to BFD" which is
2219
     currently the XScale.  */
2220
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2221
      }
2222
  }
2223
      break;
2224
#endif
2225
#ifdef AARCH64MAGIC
2226
    case AARCH64MAGIC:
2227
      arch = bfd_arch_aarch64;
2228
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2229
      break;
2230
#endif
2231
#ifdef LOONGARCH64MAGIC
2232
    case LOONGARCH64MAGIC:
2233
      arch = bfd_arch_loongarch;
2234
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2235
      break;
2236
#endif
2237
#ifdef Z80MAGIC
2238
    case Z80MAGIC:
2239
      arch = bfd_arch_z80;
2240
      switch (internal_f->f_flags & F_MACHMASK)
2241
  {
2242
  case bfd_mach_z80strict << 12:
2243
  case bfd_mach_z80 << 12:
2244
  case bfd_mach_z80n << 12:
2245
  case bfd_mach_z80full << 12:
2246
  case bfd_mach_r800 << 12:
2247
  case bfd_mach_gbz80 << 12:
2248
  case bfd_mach_z180 << 12:
2249
  case bfd_mach_ez80_z80 << 12:
2250
  case bfd_mach_ez80_adl << 12:
2251
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2252
    break;
2253
  default:
2254
    return false;
2255
  }
2256
      break;
2257
#endif
2258
#ifdef Z8KMAGIC
2259
    case Z8KMAGIC:
2260
      arch = bfd_arch_z8k;
2261
      switch (internal_f->f_flags & F_MACHMASK)
2262
  {
2263
  case F_Z8001:
2264
    machine = bfd_mach_z8001;
2265
    break;
2266
  case F_Z8002:
2267
    machine = bfd_mach_z8002;
2268
    break;
2269
  default:
2270
    return false;
2271
  }
2272
      break;
2273
#endif
2274
2275
#ifdef RS6000COFF_C
2276
#ifdef XCOFF64
2277
    case U64_TOCMAGIC:
2278
    case U803XTOCMAGIC:
2279
#else
2280
    case U802ROMAGIC:
2281
    case U802WRMAGIC:
2282
    case U802TOCMAGIC:
2283
#endif
2284
      {
2285
  int cputype;
2286
2287
  if (xcoff_data (abfd)->cputype != -1)
2288
    cputype = xcoff_data (abfd)->cputype & 0xff;
2289
  else
2290
    {
2291
      /* We did not get a value from the a.out header.  If the
2292
         file has not been stripped, we may be able to get the
2293
         architecture information from the first symbol, if it
2294
         is a .file symbol.  */
2295
      if (obj_raw_syment_count (abfd) == 0)
2296
        cputype = 0;
2297
      else
2298
        {
2299
    bfd_byte *buf;
2300
    struct internal_syment sym;
2301
    bfd_size_type amt = bfd_coff_symesz (abfd);
2302
2303
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2304
      return false;
2305
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2306
    if (buf == NULL)
2307
      return false;
2308
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2309
    if (sym.n_sclass == C_FILE)
2310
      cputype = sym.n_type & 0xff;
2311
    else
2312
      cputype = 0;
2313
    free (buf);
2314
        }
2315
    }
2316
2317
  /* FIXME: We don't handle all cases here.  */
2318
  switch (cputype)
2319
    {
2320
    default:
2321
    case 0:
2322
      arch = bfd_xcoff_architecture (abfd);
2323
      machine = bfd_xcoff_machine (abfd);
2324
      break;
2325
2326
    case 1:
2327
      arch = bfd_arch_powerpc;
2328
      machine = bfd_mach_ppc_601;
2329
      break;
2330
    case 2: /* 64 bit PowerPC */
2331
      arch = bfd_arch_powerpc;
2332
      machine = bfd_mach_ppc_620;
2333
      break;
2334
    case 3:
2335
      arch = bfd_arch_powerpc;
2336
      machine = bfd_mach_ppc;
2337
      break;
2338
    case 4:
2339
      arch = bfd_arch_rs6000;
2340
      machine = bfd_mach_rs6k;
2341
      break;
2342
    }
2343
      }
2344
      break;
2345
#endif
2346
2347
#ifdef SH_ARCH_MAGIC_BIG
2348
    case SH_ARCH_MAGIC_BIG:
2349
    case SH_ARCH_MAGIC_LITTLE:
2350
#ifdef COFF_WITH_PE
2351
    case SH_ARCH_MAGIC_WINCE:
2352
#endif
2353
      arch = bfd_arch_sh;
2354
      break;
2355
#endif
2356
2357
#ifdef MIPS_ARCH_MAGIC_WINCE
2358
    case MIPS_ARCH_MAGIC_WINCE:
2359
      arch = bfd_arch_mips;
2360
      break;
2361
#endif
2362
2363
#ifdef SPARCMAGIC
2364
    case SPARCMAGIC:
2365
#ifdef LYNXCOFFMAGIC
2366
    case LYNXCOFFMAGIC:
2367
#endif
2368
      arch = bfd_arch_sparc;
2369
      break;
2370
#endif
2371
2372
#ifdef TIC30MAGIC
2373
    case TIC30MAGIC:
2374
      arch = bfd_arch_tic30;
2375
      break;
2376
#endif
2377
2378
#ifdef TICOFF0MAGIC
2379
#ifdef TICOFF_TARGET_ARCH
2380
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2381
    case TICOFF0MAGIC:
2382
      arch = TICOFF_TARGET_ARCH;
2383
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2384
      break;
2385
#endif
2386
#endif
2387
2388
#ifdef TICOFF1MAGIC
2389
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2390
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2391
    case TICOFF1MAGIC:
2392
    case TICOFF2MAGIC:
2393
      switch (internal_f->f_target_id)
2394
  {
2395
#ifdef TI_TARGET_ID
2396
  case TI_TARGET_ID:
2397
    arch = TICOFF_TARGET_ARCH;
2398
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2399
    break;
2400
#endif
2401
  default:
2402
    arch = bfd_arch_obscure;
2403
    _bfd_error_handler
2404
      (_("unrecognized TI COFF target id '0x%x'"),
2405
       internal_f->f_target_id);
2406
    break;
2407
  }
2408
      break;
2409
#endif
2410
2411
#ifdef MCOREMAGIC
2412
    case MCOREMAGIC:
2413
      arch = bfd_arch_mcore;
2414
      break;
2415
#endif
2416
2417
0
    default:      /* Unreadable input file type.  */
2418
0
      arch = bfd_arch_obscure;
2419
0
      break;
2420
75
    }
2421
2422
75
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
75
  return true;
2424
75
}
pei-loongarch64.c:coff_set_arch_mach_hook
Line
Count
Source
2162
133
{
2163
133
  unsigned long machine;
2164
133
  enum bfd_architecture arch;
2165
133
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
133
  machine = 0;
2169
133
  switch (internal_f->f_magic)
2170
133
    {
2171
#ifdef I386MAGIC
2172
    case I386MAGIC:
2173
    case I386PTXMAGIC:
2174
    case I386AIXMAGIC:    /* Danbury PS/2 AIX C Compiler.  */
2175
    case LYNXCOFFMAGIC:
2176
    case I386_APPLE_MAGIC:
2177
    case I386_FREEBSD_MAGIC:
2178
    case I386_LINUX_MAGIC:
2179
    case I386_NETBSD_MAGIC:
2180
      arch = bfd_arch_i386;
2181
      break;
2182
#endif
2183
#ifdef AMD64MAGIC
2184
    case AMD64MAGIC:
2185
    case AMD64_APPLE_MAGIC:
2186
    case AMD64_FREEBSD_MAGIC:
2187
    case AMD64_LINUX_MAGIC:
2188
    case AMD64_NETBSD_MAGIC:
2189
      arch = bfd_arch_i386;
2190
      machine = bfd_mach_x86_64;
2191
      break;
2192
#endif
2193
#ifdef IA64MAGIC
2194
    case IA64MAGIC:
2195
      arch = bfd_arch_ia64;
2196
      break;
2197
#endif
2198
#ifdef ARMMAGIC
2199
    case ARMMAGIC:
2200
    case ARMPEMAGIC:
2201
    case THUMBPEMAGIC:
2202
      arch = bfd_arch_arm;
2203
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2204
      if (machine == bfd_mach_arm_unknown)
2205
  {
2206
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2207
      {
2208
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2209
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2210
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2211
      default:
2212
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2213
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2214
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2215
        /* The COFF header does not have enough bits available
2216
     to cover all the different ARM architectures.  So
2217
     we interpret F_ARM_5, the highest flag value to mean
2218
     "the highest ARM architecture known to BFD" which is
2219
     currently the XScale.  */
2220
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2221
      }
2222
  }
2223
      break;
2224
#endif
2225
#ifdef AARCH64MAGIC
2226
    case AARCH64MAGIC:
2227
      arch = bfd_arch_aarch64;
2228
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2229
      break;
2230
#endif
2231
0
#ifdef LOONGARCH64MAGIC
2232
133
    case LOONGARCH64MAGIC:
2233
133
      arch = bfd_arch_loongarch;
2234
133
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2235
133
      break;
2236
0
#endif
2237
#ifdef Z80MAGIC
2238
    case Z80MAGIC:
2239
      arch = bfd_arch_z80;
2240
      switch (internal_f->f_flags & F_MACHMASK)
2241
  {
2242
  case bfd_mach_z80strict << 12:
2243
  case bfd_mach_z80 << 12:
2244
  case bfd_mach_z80n << 12:
2245
  case bfd_mach_z80full << 12:
2246
  case bfd_mach_r800 << 12:
2247
  case bfd_mach_gbz80 << 12:
2248
  case bfd_mach_z180 << 12:
2249
  case bfd_mach_ez80_z80 << 12:
2250
  case bfd_mach_ez80_adl << 12:
2251
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2252
    break;
2253
  default:
2254
    return false;
2255
  }
2256
      break;
2257
#endif
2258
#ifdef Z8KMAGIC
2259
    case Z8KMAGIC:
2260
      arch = bfd_arch_z8k;
2261
      switch (internal_f->f_flags & F_MACHMASK)
2262
  {
2263
  case F_Z8001:
2264
    machine = bfd_mach_z8001;
2265
    break;
2266
  case F_Z8002:
2267
    machine = bfd_mach_z8002;
2268
    break;
2269
  default:
2270
    return false;
2271
  }
2272
      break;
2273
#endif
2274
2275
#ifdef RS6000COFF_C
2276
#ifdef XCOFF64
2277
    case U64_TOCMAGIC:
2278
    case U803XTOCMAGIC:
2279
#else
2280
    case U802ROMAGIC:
2281
    case U802WRMAGIC:
2282
    case U802TOCMAGIC:
2283
#endif
2284
      {
2285
  int cputype;
2286
2287
  if (xcoff_data (abfd)->cputype != -1)
2288
    cputype = xcoff_data (abfd)->cputype & 0xff;
2289
  else
2290
    {
2291
      /* We did not get a value from the a.out header.  If the
2292
         file has not been stripped, we may be able to get the
2293
         architecture information from the first symbol, if it
2294
         is a .file symbol.  */
2295
      if (obj_raw_syment_count (abfd) == 0)
2296
        cputype = 0;
2297
      else
2298
        {
2299
    bfd_byte *buf;
2300
    struct internal_syment sym;
2301
    bfd_size_type amt = bfd_coff_symesz (abfd);
2302
2303
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2304
      return false;
2305
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2306
    if (buf == NULL)
2307
      return false;
2308
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2309
    if (sym.n_sclass == C_FILE)
2310
      cputype = sym.n_type & 0xff;
2311
    else
2312
      cputype = 0;
2313
    free (buf);
2314
        }
2315
    }
2316
2317
  /* FIXME: We don't handle all cases here.  */
2318
  switch (cputype)
2319
    {
2320
    default:
2321
    case 0:
2322
      arch = bfd_xcoff_architecture (abfd);
2323
      machine = bfd_xcoff_machine (abfd);
2324
      break;
2325
2326
    case 1:
2327
      arch = bfd_arch_powerpc;
2328
      machine = bfd_mach_ppc_601;
2329
      break;
2330
    case 2: /* 64 bit PowerPC */
2331
      arch = bfd_arch_powerpc;
2332
      machine = bfd_mach_ppc_620;
2333
      break;
2334
    case 3:
2335
      arch = bfd_arch_powerpc;
2336
      machine = bfd_mach_ppc;
2337
      break;
2338
    case 4:
2339
      arch = bfd_arch_rs6000;
2340
      machine = bfd_mach_rs6k;
2341
      break;
2342
    }
2343
      }
2344
      break;
2345
#endif
2346
2347
#ifdef SH_ARCH_MAGIC_BIG
2348
    case SH_ARCH_MAGIC_BIG:
2349
    case SH_ARCH_MAGIC_LITTLE:
2350
#ifdef COFF_WITH_PE
2351
    case SH_ARCH_MAGIC_WINCE:
2352
#endif
2353
      arch = bfd_arch_sh;
2354
      break;
2355
#endif
2356
2357
#ifdef MIPS_ARCH_MAGIC_WINCE
2358
    case MIPS_ARCH_MAGIC_WINCE:
2359
      arch = bfd_arch_mips;
2360
      break;
2361
#endif
2362
2363
#ifdef SPARCMAGIC
2364
    case SPARCMAGIC:
2365
#ifdef LYNXCOFFMAGIC
2366
    case LYNXCOFFMAGIC:
2367
#endif
2368
      arch = bfd_arch_sparc;
2369
      break;
2370
#endif
2371
2372
#ifdef TIC30MAGIC
2373
    case TIC30MAGIC:
2374
      arch = bfd_arch_tic30;
2375
      break;
2376
#endif
2377
2378
#ifdef TICOFF0MAGIC
2379
#ifdef TICOFF_TARGET_ARCH
2380
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2381
    case TICOFF0MAGIC:
2382
      arch = TICOFF_TARGET_ARCH;
2383
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2384
      break;
2385
#endif
2386
#endif
2387
2388
#ifdef TICOFF1MAGIC
2389
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2390
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2391
    case TICOFF1MAGIC:
2392
    case TICOFF2MAGIC:
2393
      switch (internal_f->f_target_id)
2394
  {
2395
#ifdef TI_TARGET_ID
2396
  case TI_TARGET_ID:
2397
    arch = TICOFF_TARGET_ARCH;
2398
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2399
    break;
2400
#endif
2401
  default:
2402
    arch = bfd_arch_obscure;
2403
    _bfd_error_handler
2404
      (_("unrecognized TI COFF target id '0x%x'"),
2405
       internal_f->f_target_id);
2406
    break;
2407
  }
2408
      break;
2409
#endif
2410
2411
#ifdef MCOREMAGIC
2412
    case MCOREMAGIC:
2413
      arch = bfd_arch_mcore;
2414
      break;
2415
#endif
2416
2417
0
    default:      /* Unreadable input file type.  */
2418
0
      arch = bfd_arch_obscure;
2419
0
      break;
2420
133
    }
2421
2422
133
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
133
  return true;
2424
133
}
cf-i386lynx.c:coff_set_arch_mach_hook
Line
Count
Source
2162
90
{
2163
90
  unsigned long machine;
2164
90
  enum bfd_architecture arch;
2165
90
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
90
  machine = 0;
2169
90
  switch (internal_f->f_magic)
2170
90
    {
2171
0
#ifdef I386MAGIC
2172
2
    case I386MAGIC:
2173
17
    case I386PTXMAGIC:
2174
17
    case I386AIXMAGIC:   /* Danbury PS/2 AIX C Compiler.  */
2175
30
    case LYNXCOFFMAGIC:
2176
30
    case I386_APPLE_MAGIC:
2177
30
    case I386_FREEBSD_MAGIC:
2178
30
    case I386_LINUX_MAGIC:
2179
90
    case I386_NETBSD_MAGIC:
2180
90
      arch = bfd_arch_i386;
2181
90
      break;
2182
0
#endif
2183
#ifdef AMD64MAGIC
2184
    case AMD64MAGIC:
2185
    case AMD64_APPLE_MAGIC:
2186
    case AMD64_FREEBSD_MAGIC:
2187
    case AMD64_LINUX_MAGIC:
2188
    case AMD64_NETBSD_MAGIC:
2189
      arch = bfd_arch_i386;
2190
      machine = bfd_mach_x86_64;
2191
      break;
2192
#endif
2193
#ifdef IA64MAGIC
2194
    case IA64MAGIC:
2195
      arch = bfd_arch_ia64;
2196
      break;
2197
#endif
2198
#ifdef ARMMAGIC
2199
    case ARMMAGIC:
2200
    case ARMPEMAGIC:
2201
    case THUMBPEMAGIC:
2202
      arch = bfd_arch_arm;
2203
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2204
      if (machine == bfd_mach_arm_unknown)
2205
  {
2206
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2207
      {
2208
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2209
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2210
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2211
      default:
2212
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2213
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2214
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2215
        /* The COFF header does not have enough bits available
2216
     to cover all the different ARM architectures.  So
2217
     we interpret F_ARM_5, the highest flag value to mean
2218
     "the highest ARM architecture known to BFD" which is
2219
     currently the XScale.  */
2220
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2221
      }
2222
  }
2223
      break;
2224
#endif
2225
#ifdef AARCH64MAGIC
2226
    case AARCH64MAGIC:
2227
      arch = bfd_arch_aarch64;
2228
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2229
      break;
2230
#endif
2231
#ifdef LOONGARCH64MAGIC
2232
    case LOONGARCH64MAGIC:
2233
      arch = bfd_arch_loongarch;
2234
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2235
      break;
2236
#endif
2237
#ifdef Z80MAGIC
2238
    case Z80MAGIC:
2239
      arch = bfd_arch_z80;
2240
      switch (internal_f->f_flags & F_MACHMASK)
2241
  {
2242
  case bfd_mach_z80strict << 12:
2243
  case bfd_mach_z80 << 12:
2244
  case bfd_mach_z80n << 12:
2245
  case bfd_mach_z80full << 12:
2246
  case bfd_mach_r800 << 12:
2247
  case bfd_mach_gbz80 << 12:
2248
  case bfd_mach_z180 << 12:
2249
  case bfd_mach_ez80_z80 << 12:
2250
  case bfd_mach_ez80_adl << 12:
2251
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2252
    break;
2253
  default:
2254
    return false;
2255
  }
2256
      break;
2257
#endif
2258
#ifdef Z8KMAGIC
2259
    case Z8KMAGIC:
2260
      arch = bfd_arch_z8k;
2261
      switch (internal_f->f_flags & F_MACHMASK)
2262
  {
2263
  case F_Z8001:
2264
    machine = bfd_mach_z8001;
2265
    break;
2266
  case F_Z8002:
2267
    machine = bfd_mach_z8002;
2268
    break;
2269
  default:
2270
    return false;
2271
  }
2272
      break;
2273
#endif
2274
2275
#ifdef RS6000COFF_C
2276
#ifdef XCOFF64
2277
    case U64_TOCMAGIC:
2278
    case U803XTOCMAGIC:
2279
#else
2280
    case U802ROMAGIC:
2281
    case U802WRMAGIC:
2282
    case U802TOCMAGIC:
2283
#endif
2284
      {
2285
  int cputype;
2286
2287
  if (xcoff_data (abfd)->cputype != -1)
2288
    cputype = xcoff_data (abfd)->cputype & 0xff;
2289
  else
2290
    {
2291
      /* We did not get a value from the a.out header.  If the
2292
         file has not been stripped, we may be able to get the
2293
         architecture information from the first symbol, if it
2294
         is a .file symbol.  */
2295
      if (obj_raw_syment_count (abfd) == 0)
2296
        cputype = 0;
2297
      else
2298
        {
2299
    bfd_byte *buf;
2300
    struct internal_syment sym;
2301
    bfd_size_type amt = bfd_coff_symesz (abfd);
2302
2303
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2304
      return false;
2305
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2306
    if (buf == NULL)
2307
      return false;
2308
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2309
    if (sym.n_sclass == C_FILE)
2310
      cputype = sym.n_type & 0xff;
2311
    else
2312
      cputype = 0;
2313
    free (buf);
2314
        }
2315
    }
2316
2317
  /* FIXME: We don't handle all cases here.  */
2318
  switch (cputype)
2319
    {
2320
    default:
2321
    case 0:
2322
      arch = bfd_xcoff_architecture (abfd);
2323
      machine = bfd_xcoff_machine (abfd);
2324
      break;
2325
2326
    case 1:
2327
      arch = bfd_arch_powerpc;
2328
      machine = bfd_mach_ppc_601;
2329
      break;
2330
    case 2: /* 64 bit PowerPC */
2331
      arch = bfd_arch_powerpc;
2332
      machine = bfd_mach_ppc_620;
2333
      break;
2334
    case 3:
2335
      arch = bfd_arch_powerpc;
2336
      machine = bfd_mach_ppc;
2337
      break;
2338
    case 4:
2339
      arch = bfd_arch_rs6000;
2340
      machine = bfd_mach_rs6k;
2341
      break;
2342
    }
2343
      }
2344
      break;
2345
#endif
2346
2347
#ifdef SH_ARCH_MAGIC_BIG
2348
    case SH_ARCH_MAGIC_BIG:
2349
    case SH_ARCH_MAGIC_LITTLE:
2350
#ifdef COFF_WITH_PE
2351
    case SH_ARCH_MAGIC_WINCE:
2352
#endif
2353
      arch = bfd_arch_sh;
2354
      break;
2355
#endif
2356
2357
#ifdef MIPS_ARCH_MAGIC_WINCE
2358
    case MIPS_ARCH_MAGIC_WINCE:
2359
      arch = bfd_arch_mips;
2360
      break;
2361
#endif
2362
2363
#ifdef SPARCMAGIC
2364
    case SPARCMAGIC:
2365
#ifdef LYNXCOFFMAGIC
2366
    case LYNXCOFFMAGIC:
2367
#endif
2368
      arch = bfd_arch_sparc;
2369
      break;
2370
#endif
2371
2372
#ifdef TIC30MAGIC
2373
    case TIC30MAGIC:
2374
      arch = bfd_arch_tic30;
2375
      break;
2376
#endif
2377
2378
#ifdef TICOFF0MAGIC
2379
#ifdef TICOFF_TARGET_ARCH
2380
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2381
    case TICOFF0MAGIC:
2382
      arch = TICOFF_TARGET_ARCH;
2383
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2384
      break;
2385
#endif
2386
#endif
2387
2388
#ifdef TICOFF1MAGIC
2389
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2390
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2391
    case TICOFF1MAGIC:
2392
    case TICOFF2MAGIC:
2393
      switch (internal_f->f_target_id)
2394
  {
2395
#ifdef TI_TARGET_ID
2396
  case TI_TARGET_ID:
2397
    arch = TICOFF_TARGET_ARCH;
2398
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2399
    break;
2400
#endif
2401
  default:
2402
    arch = bfd_arch_obscure;
2403
    _bfd_error_handler
2404
      (_("unrecognized TI COFF target id '0x%x'"),
2405
       internal_f->f_target_id);
2406
    break;
2407
  }
2408
      break;
2409
#endif
2410
2411
#ifdef MCOREMAGIC
2412
    case MCOREMAGIC:
2413
      arch = bfd_arch_mcore;
2414
      break;
2415
#endif
2416
2417
0
    default:      /* Unreadable input file type.  */
2418
0
      arch = bfd_arch_obscure;
2419
0
      break;
2420
90
    }
2421
2422
90
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
90
  return true;
2424
90
}
coff-go32.c:coff_set_arch_mach_hook
Line
Count
Source
2162
14
{
2163
14
  unsigned long machine;
2164
14
  enum bfd_architecture arch;
2165
14
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
14
  machine = 0;
2169
14
  switch (internal_f->f_magic)
2170
14
    {
2171
0
#ifdef I386MAGIC
2172
0
    case I386MAGIC:
2173
1
    case I386PTXMAGIC:
2174
1
    case I386AIXMAGIC:   /* Danbury PS/2 AIX C Compiler.  */
2175
14
    case LYNXCOFFMAGIC:
2176
14
    case I386_APPLE_MAGIC:
2177
14
    case I386_FREEBSD_MAGIC:
2178
14
    case I386_LINUX_MAGIC:
2179
14
    case I386_NETBSD_MAGIC:
2180
14
      arch = bfd_arch_i386;
2181
14
      break;
2182
0
#endif
2183
#ifdef AMD64MAGIC
2184
    case AMD64MAGIC:
2185
    case AMD64_APPLE_MAGIC:
2186
    case AMD64_FREEBSD_MAGIC:
2187
    case AMD64_LINUX_MAGIC:
2188
    case AMD64_NETBSD_MAGIC:
2189
      arch = bfd_arch_i386;
2190
      machine = bfd_mach_x86_64;
2191
      break;
2192
#endif
2193
#ifdef IA64MAGIC
2194
    case IA64MAGIC:
2195
      arch = bfd_arch_ia64;
2196
      break;
2197
#endif
2198
#ifdef ARMMAGIC
2199
    case ARMMAGIC:
2200
    case ARMPEMAGIC:
2201
    case THUMBPEMAGIC:
2202
      arch = bfd_arch_arm;
2203
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2204
      if (machine == bfd_mach_arm_unknown)
2205
  {
2206
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2207
      {
2208
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2209
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2210
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2211
      default:
2212
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2213
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2214
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2215
        /* The COFF header does not have enough bits available
2216
     to cover all the different ARM architectures.  So
2217
     we interpret F_ARM_5, the highest flag value to mean
2218
     "the highest ARM architecture known to BFD" which is
2219
     currently the XScale.  */
2220
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2221
      }
2222
  }
2223
      break;
2224
#endif
2225
#ifdef AARCH64MAGIC
2226
    case AARCH64MAGIC:
2227
      arch = bfd_arch_aarch64;
2228
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2229
      break;
2230
#endif
2231
#ifdef LOONGARCH64MAGIC
2232
    case LOONGARCH64MAGIC:
2233
      arch = bfd_arch_loongarch;
2234
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2235
      break;
2236
#endif
2237
#ifdef Z80MAGIC
2238
    case Z80MAGIC:
2239
      arch = bfd_arch_z80;
2240
      switch (internal_f->f_flags & F_MACHMASK)
2241
  {
2242
  case bfd_mach_z80strict << 12:
2243
  case bfd_mach_z80 << 12:
2244
  case bfd_mach_z80n << 12:
2245
  case bfd_mach_z80full << 12:
2246
  case bfd_mach_r800 << 12:
2247
  case bfd_mach_gbz80 << 12:
2248
  case bfd_mach_z180 << 12:
2249
  case bfd_mach_ez80_z80 << 12:
2250
  case bfd_mach_ez80_adl << 12:
2251
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2252
    break;
2253
  default:
2254
    return false;
2255
  }
2256
      break;
2257
#endif
2258
#ifdef Z8KMAGIC
2259
    case Z8KMAGIC:
2260
      arch = bfd_arch_z8k;
2261
      switch (internal_f->f_flags & F_MACHMASK)
2262
  {
2263
  case F_Z8001:
2264
    machine = bfd_mach_z8001;
2265
    break;
2266
  case F_Z8002:
2267
    machine = bfd_mach_z8002;
2268
    break;
2269
  default:
2270
    return false;
2271
  }
2272
      break;
2273
#endif
2274
2275
#ifdef RS6000COFF_C
2276
#ifdef XCOFF64
2277
    case U64_TOCMAGIC:
2278
    case U803XTOCMAGIC:
2279
#else
2280
    case U802ROMAGIC:
2281
    case U802WRMAGIC:
2282
    case U802TOCMAGIC:
2283
#endif
2284
      {
2285
  int cputype;
2286
2287
  if (xcoff_data (abfd)->cputype != -1)
2288
    cputype = xcoff_data (abfd)->cputype & 0xff;
2289
  else
2290
    {
2291
      /* We did not get a value from the a.out header.  If the
2292
         file has not been stripped, we may be able to get the
2293
         architecture information from the first symbol, if it
2294
         is a .file symbol.  */
2295
      if (obj_raw_syment_count (abfd) == 0)
2296
        cputype = 0;
2297
      else
2298
        {
2299
    bfd_byte *buf;
2300
    struct internal_syment sym;
2301
    bfd_size_type amt = bfd_coff_symesz (abfd);
2302
2303
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2304
      return false;
2305
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2306
    if (buf == NULL)
2307
      return false;
2308
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2309
    if (sym.n_sclass == C_FILE)
2310
      cputype = sym.n_type & 0xff;
2311
    else
2312
      cputype = 0;
2313
    free (buf);
2314
        }
2315
    }
2316
2317
  /* FIXME: We don't handle all cases here.  */
2318
  switch (cputype)
2319
    {
2320
    default:
2321
    case 0:
2322
      arch = bfd_xcoff_architecture (abfd);
2323
      machine = bfd_xcoff_machine (abfd);
2324
      break;
2325
2326
    case 1:
2327
      arch = bfd_arch_powerpc;
2328
      machine = bfd_mach_ppc_601;
2329
      break;
2330
    case 2: /* 64 bit PowerPC */
2331
      arch = bfd_arch_powerpc;
2332
      machine = bfd_mach_ppc_620;
2333
      break;
2334
    case 3:
2335
      arch = bfd_arch_powerpc;
2336
      machine = bfd_mach_ppc;
2337
      break;
2338
    case 4:
2339
      arch = bfd_arch_rs6000;
2340
      machine = bfd_mach_rs6k;
2341
      break;
2342
    }
2343
      }
2344
      break;
2345
#endif
2346
2347
#ifdef SH_ARCH_MAGIC_BIG
2348
    case SH_ARCH_MAGIC_BIG:
2349
    case SH_ARCH_MAGIC_LITTLE:
2350
#ifdef COFF_WITH_PE
2351
    case SH_ARCH_MAGIC_WINCE:
2352
#endif
2353
      arch = bfd_arch_sh;
2354
      break;
2355
#endif
2356
2357
#ifdef MIPS_ARCH_MAGIC_WINCE
2358
    case MIPS_ARCH_MAGIC_WINCE:
2359
      arch = bfd_arch_mips;
2360
      break;
2361
#endif
2362
2363
#ifdef SPARCMAGIC
2364
    case SPARCMAGIC:
2365
#ifdef LYNXCOFFMAGIC
2366
    case LYNXCOFFMAGIC:
2367
#endif
2368
      arch = bfd_arch_sparc;
2369
      break;
2370
#endif
2371
2372
#ifdef TIC30MAGIC
2373
    case TIC30MAGIC:
2374
      arch = bfd_arch_tic30;
2375
      break;
2376
#endif
2377
2378
#ifdef TICOFF0MAGIC
2379
#ifdef TICOFF_TARGET_ARCH
2380
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2381
    case TICOFF0MAGIC:
2382
      arch = TICOFF_TARGET_ARCH;
2383
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2384
      break;
2385
#endif
2386
#endif
2387
2388
#ifdef TICOFF1MAGIC
2389
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2390
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2391
    case TICOFF1MAGIC:
2392
    case TICOFF2MAGIC:
2393
      switch (internal_f->f_target_id)
2394
  {
2395
#ifdef TI_TARGET_ID
2396
  case TI_TARGET_ID:
2397
    arch = TICOFF_TARGET_ARCH;
2398
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2399
    break;
2400
#endif
2401
  default:
2402
    arch = bfd_arch_obscure;
2403
    _bfd_error_handler
2404
      (_("unrecognized TI COFF target id '0x%x'"),
2405
       internal_f->f_target_id);
2406
    break;
2407
  }
2408
      break;
2409
#endif
2410
2411
#ifdef MCOREMAGIC
2412
    case MCOREMAGIC:
2413
      arch = bfd_arch_mcore;
2414
      break;
2415
#endif
2416
2417
0
    default:      /* Unreadable input file type.  */
2418
0
      arch = bfd_arch_obscure;
2419
0
      break;
2420
14
    }
2421
2422
14
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
14
  return true;
2424
14
}
coff-i386.c:coff_set_arch_mach_hook
Line
Count
Source
2162
14
{
2163
14
  unsigned long machine;
2164
14
  enum bfd_architecture arch;
2165
14
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
14
  machine = 0;
2169
14
  switch (internal_f->f_magic)
2170
14
    {
2171
0
#ifdef I386MAGIC
2172
0
    case I386MAGIC:
2173
1
    case I386PTXMAGIC:
2174
1
    case I386AIXMAGIC:   /* Danbury PS/2 AIX C Compiler.  */
2175
14
    case LYNXCOFFMAGIC:
2176
14
    case I386_APPLE_MAGIC:
2177
14
    case I386_FREEBSD_MAGIC:
2178
14
    case I386_LINUX_MAGIC:
2179
14
    case I386_NETBSD_MAGIC:
2180
14
      arch = bfd_arch_i386;
2181
14
      break;
2182
0
#endif
2183
#ifdef AMD64MAGIC
2184
    case AMD64MAGIC:
2185
    case AMD64_APPLE_MAGIC:
2186
    case AMD64_FREEBSD_MAGIC:
2187
    case AMD64_LINUX_MAGIC:
2188
    case AMD64_NETBSD_MAGIC:
2189
      arch = bfd_arch_i386;
2190
      machine = bfd_mach_x86_64;
2191
      break;
2192
#endif
2193
#ifdef IA64MAGIC
2194
    case IA64MAGIC:
2195
      arch = bfd_arch_ia64;
2196
      break;
2197
#endif
2198
#ifdef ARMMAGIC
2199
    case ARMMAGIC:
2200
    case ARMPEMAGIC:
2201
    case THUMBPEMAGIC:
2202
      arch = bfd_arch_arm;
2203
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2204
      if (machine == bfd_mach_arm_unknown)
2205
  {
2206
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2207
      {
2208
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2209
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2210
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2211
      default:
2212
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2213
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2214
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2215
        /* The COFF header does not have enough bits available
2216
     to cover all the different ARM architectures.  So
2217
     we interpret F_ARM_5, the highest flag value to mean
2218
     "the highest ARM architecture known to BFD" which is
2219
     currently the XScale.  */
2220
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2221
      }
2222
  }
2223
      break;
2224
#endif
2225
#ifdef AARCH64MAGIC
2226
    case AARCH64MAGIC:
2227
      arch = bfd_arch_aarch64;
2228
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2229
      break;
2230
#endif
2231
#ifdef LOONGARCH64MAGIC
2232
    case LOONGARCH64MAGIC:
2233
      arch = bfd_arch_loongarch;
2234
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2235
      break;
2236
#endif
2237
#ifdef Z80MAGIC
2238
    case Z80MAGIC:
2239
      arch = bfd_arch_z80;
2240
      switch (internal_f->f_flags & F_MACHMASK)
2241
  {
2242
  case bfd_mach_z80strict << 12:
2243
  case bfd_mach_z80 << 12:
2244
  case bfd_mach_z80n << 12:
2245
  case bfd_mach_z80full << 12:
2246
  case bfd_mach_r800 << 12:
2247
  case bfd_mach_gbz80 << 12:
2248
  case bfd_mach_z180 << 12:
2249
  case bfd_mach_ez80_z80 << 12:
2250
  case bfd_mach_ez80_adl << 12:
2251
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2252
    break;
2253
  default:
2254
    return false;
2255
  }
2256
      break;
2257
#endif
2258
#ifdef Z8KMAGIC
2259
    case Z8KMAGIC:
2260
      arch = bfd_arch_z8k;
2261
      switch (internal_f->f_flags & F_MACHMASK)
2262
  {
2263
  case F_Z8001:
2264
    machine = bfd_mach_z8001;
2265
    break;
2266
  case F_Z8002:
2267
    machine = bfd_mach_z8002;
2268
    break;
2269
  default:
2270
    return false;
2271
  }
2272
      break;
2273
#endif
2274
2275
#ifdef RS6000COFF_C
2276
#ifdef XCOFF64
2277
    case U64_TOCMAGIC:
2278
    case U803XTOCMAGIC:
2279
#else
2280
    case U802ROMAGIC:
2281
    case U802WRMAGIC:
2282
    case U802TOCMAGIC:
2283
#endif
2284
      {
2285
  int cputype;
2286
2287
  if (xcoff_data (abfd)->cputype != -1)
2288
    cputype = xcoff_data (abfd)->cputype & 0xff;
2289
  else
2290
    {
2291
      /* We did not get a value from the a.out header.  If the
2292
         file has not been stripped, we may be able to get the
2293
         architecture information from the first symbol, if it
2294
         is a .file symbol.  */
2295
      if (obj_raw_syment_count (abfd) == 0)
2296
        cputype = 0;
2297
      else
2298
        {
2299
    bfd_byte *buf;
2300
    struct internal_syment sym;
2301
    bfd_size_type amt = bfd_coff_symesz (abfd);
2302
2303
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2304
      return false;
2305
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2306
    if (buf == NULL)
2307
      return false;
2308
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2309
    if (sym.n_sclass == C_FILE)
2310
      cputype = sym.n_type & 0xff;
2311
    else
2312
      cputype = 0;
2313
    free (buf);
2314
        }
2315
    }
2316
2317
  /* FIXME: We don't handle all cases here.  */
2318
  switch (cputype)
2319
    {
2320
    default:
2321
    case 0:
2322
      arch = bfd_xcoff_architecture (abfd);
2323
      machine = bfd_xcoff_machine (abfd);
2324
      break;
2325
2326
    case 1:
2327
      arch = bfd_arch_powerpc;
2328
      machine = bfd_mach_ppc_601;
2329
      break;
2330
    case 2: /* 64 bit PowerPC */
2331
      arch = bfd_arch_powerpc;
2332
      machine = bfd_mach_ppc_620;
2333
      break;
2334
    case 3:
2335
      arch = bfd_arch_powerpc;
2336
      machine = bfd_mach_ppc;
2337
      break;
2338
    case 4:
2339
      arch = bfd_arch_rs6000;
2340
      machine = bfd_mach_rs6k;
2341
      break;
2342
    }
2343
      }
2344
      break;
2345
#endif
2346
2347
#ifdef SH_ARCH_MAGIC_BIG
2348
    case SH_ARCH_MAGIC_BIG:
2349
    case SH_ARCH_MAGIC_LITTLE:
2350
#ifdef COFF_WITH_PE
2351
    case SH_ARCH_MAGIC_WINCE:
2352
#endif
2353
      arch = bfd_arch_sh;
2354
      break;
2355
#endif
2356
2357
#ifdef MIPS_ARCH_MAGIC_WINCE
2358
    case MIPS_ARCH_MAGIC_WINCE:
2359
      arch = bfd_arch_mips;
2360
      break;
2361
#endif
2362
2363
#ifdef SPARCMAGIC
2364
    case SPARCMAGIC:
2365
#ifdef LYNXCOFFMAGIC
2366
    case LYNXCOFFMAGIC:
2367
#endif
2368
      arch = bfd_arch_sparc;
2369
      break;
2370
#endif
2371
2372
#ifdef TIC30MAGIC
2373
    case TIC30MAGIC:
2374
      arch = bfd_arch_tic30;
2375
      break;
2376
#endif
2377
2378
#ifdef TICOFF0MAGIC
2379
#ifdef TICOFF_TARGET_ARCH
2380
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2381
    case TICOFF0MAGIC:
2382
      arch = TICOFF_TARGET_ARCH;
2383
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2384
      break;
2385
#endif
2386
#endif
2387
2388
#ifdef TICOFF1MAGIC
2389
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2390
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2391
    case TICOFF1MAGIC:
2392
    case TICOFF2MAGIC:
2393
      switch (internal_f->f_target_id)
2394
  {
2395
#ifdef TI_TARGET_ID
2396
  case TI_TARGET_ID:
2397
    arch = TICOFF_TARGET_ARCH;
2398
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2399
    break;
2400
#endif
2401
  default:
2402
    arch = bfd_arch_obscure;
2403
    _bfd_error_handler
2404
      (_("unrecognized TI COFF target id '0x%x'"),
2405
       internal_f->f_target_id);
2406
    break;
2407
  }
2408
      break;
2409
#endif
2410
2411
#ifdef MCOREMAGIC
2412
    case MCOREMAGIC:
2413
      arch = bfd_arch_mcore;
2414
      break;
2415
#endif
2416
2417
0
    default:      /* Unreadable input file type.  */
2418
0
      arch = bfd_arch_obscure;
2419
0
      break;
2420
14
    }
2421
2422
14
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
14
  return true;
2424
14
}
coff-rs6000.c:coff_set_arch_mach_hook
Line
Count
Source
2162
133
{
2163
133
  unsigned long machine;
2164
133
  enum bfd_architecture arch;
2165
133
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
133
  machine = 0;
2169
133
  switch (internal_f->f_magic)
2170
133
    {
2171
#ifdef I386MAGIC
2172
    case I386MAGIC:
2173
    case I386PTXMAGIC:
2174
    case I386AIXMAGIC:    /* Danbury PS/2 AIX C Compiler.  */
2175
    case LYNXCOFFMAGIC:
2176
    case I386_APPLE_MAGIC:
2177
    case I386_FREEBSD_MAGIC:
2178
    case I386_LINUX_MAGIC:
2179
    case I386_NETBSD_MAGIC:
2180
      arch = bfd_arch_i386;
2181
      break;
2182
#endif
2183
#ifdef AMD64MAGIC
2184
    case AMD64MAGIC:
2185
    case AMD64_APPLE_MAGIC:
2186
    case AMD64_FREEBSD_MAGIC:
2187
    case AMD64_LINUX_MAGIC:
2188
    case AMD64_NETBSD_MAGIC:
2189
      arch = bfd_arch_i386;
2190
      machine = bfd_mach_x86_64;
2191
      break;
2192
#endif
2193
#ifdef IA64MAGIC
2194
    case IA64MAGIC:
2195
      arch = bfd_arch_ia64;
2196
      break;
2197
#endif
2198
#ifdef ARMMAGIC
2199
    case ARMMAGIC:
2200
    case ARMPEMAGIC:
2201
    case THUMBPEMAGIC:
2202
      arch = bfd_arch_arm;
2203
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2204
      if (machine == bfd_mach_arm_unknown)
2205
  {
2206
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2207
      {
2208
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2209
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2210
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2211
      default:
2212
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2213
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2214
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2215
        /* The COFF header does not have enough bits available
2216
     to cover all the different ARM architectures.  So
2217
     we interpret F_ARM_5, the highest flag value to mean
2218
     "the highest ARM architecture known to BFD" which is
2219
     currently the XScale.  */
2220
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2221
      }
2222
  }
2223
      break;
2224
#endif
2225
#ifdef AARCH64MAGIC
2226
    case AARCH64MAGIC:
2227
      arch = bfd_arch_aarch64;
2228
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2229
      break;
2230
#endif
2231
#ifdef LOONGARCH64MAGIC
2232
    case LOONGARCH64MAGIC:
2233
      arch = bfd_arch_loongarch;
2234
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2235
      break;
2236
#endif
2237
#ifdef Z80MAGIC
2238
    case Z80MAGIC:
2239
      arch = bfd_arch_z80;
2240
      switch (internal_f->f_flags & F_MACHMASK)
2241
  {
2242
  case bfd_mach_z80strict << 12:
2243
  case bfd_mach_z80 << 12:
2244
  case bfd_mach_z80n << 12:
2245
  case bfd_mach_z80full << 12:
2246
  case bfd_mach_r800 << 12:
2247
  case bfd_mach_gbz80 << 12:
2248
  case bfd_mach_z180 << 12:
2249
  case bfd_mach_ez80_z80 << 12:
2250
  case bfd_mach_ez80_adl << 12:
2251
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2252
    break;
2253
  default:
2254
    return false;
2255
  }
2256
      break;
2257
#endif
2258
#ifdef Z8KMAGIC
2259
    case Z8KMAGIC:
2260
      arch = bfd_arch_z8k;
2261
      switch (internal_f->f_flags & F_MACHMASK)
2262
  {
2263
  case F_Z8001:
2264
    machine = bfd_mach_z8001;
2265
    break;
2266
  case F_Z8002:
2267
    machine = bfd_mach_z8002;
2268
    break;
2269
  default:
2270
    return false;
2271
  }
2272
      break;
2273
#endif
2274
2275
0
#ifdef RS6000COFF_C
2276
#ifdef XCOFF64
2277
    case U64_TOCMAGIC:
2278
    case U803XTOCMAGIC:
2279
#else
2280
131
    case U802ROMAGIC:
2281
131
    case U802WRMAGIC:
2282
133
    case U802TOCMAGIC:
2283
133
#endif
2284
133
      {
2285
133
  int cputype;
2286
2287
133
  if (xcoff_data (abfd)->cputype != -1)
2288
0
    cputype = xcoff_data (abfd)->cputype & 0xff;
2289
133
  else
2290
133
    {
2291
      /* We did not get a value from the a.out header.  If the
2292
         file has not been stripped, we may be able to get the
2293
         architecture information from the first symbol, if it
2294
         is a .file symbol.  */
2295
133
      if (obj_raw_syment_count (abfd) == 0)
2296
2
        cputype = 0;
2297
131
      else
2298
131
        {
2299
131
    bfd_byte *buf;
2300
131
    struct internal_syment sym;
2301
131
    bfd_size_type amt = bfd_coff_symesz (abfd);
2302
2303
131
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2304
0
      return false;
2305
131
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2306
131
    if (buf == NULL)
2307
0
      return false;
2308
131
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2309
131
    if (sym.n_sclass == C_FILE)
2310
2
      cputype = sym.n_type & 0xff;
2311
129
    else
2312
129
      cputype = 0;
2313
131
    free (buf);
2314
131
        }
2315
133
    }
2316
2317
  /* FIXME: We don't handle all cases here.  */
2318
133
  switch (cputype)
2319
133
    {
2320
2
    default:
2321
133
    case 0:
2322
133
      arch = bfd_xcoff_architecture (abfd);
2323
133
      machine = bfd_xcoff_machine (abfd);
2324
133
      break;
2325
2326
0
    case 1:
2327
0
      arch = bfd_arch_powerpc;
2328
0
      machine = bfd_mach_ppc_601;
2329
0
      break;
2330
0
    case 2: /* 64 bit PowerPC */
2331
0
      arch = bfd_arch_powerpc;
2332
0
      machine = bfd_mach_ppc_620;
2333
0
      break;
2334
0
    case 3:
2335
0
      arch = bfd_arch_powerpc;
2336
0
      machine = bfd_mach_ppc;
2337
0
      break;
2338
0
    case 4:
2339
0
      arch = bfd_arch_rs6000;
2340
0
      machine = bfd_mach_rs6k;
2341
0
      break;
2342
133
    }
2343
133
      }
2344
133
      break;
2345
133
#endif
2346
2347
#ifdef SH_ARCH_MAGIC_BIG
2348
    case SH_ARCH_MAGIC_BIG:
2349
    case SH_ARCH_MAGIC_LITTLE:
2350
#ifdef COFF_WITH_PE
2351
    case SH_ARCH_MAGIC_WINCE:
2352
#endif
2353
      arch = bfd_arch_sh;
2354
      break;
2355
#endif
2356
2357
#ifdef MIPS_ARCH_MAGIC_WINCE
2358
    case MIPS_ARCH_MAGIC_WINCE:
2359
      arch = bfd_arch_mips;
2360
      break;
2361
#endif
2362
2363
#ifdef SPARCMAGIC
2364
    case SPARCMAGIC:
2365
#ifdef LYNXCOFFMAGIC
2366
    case LYNXCOFFMAGIC:
2367
#endif
2368
      arch = bfd_arch_sparc;
2369
      break;
2370
#endif
2371
2372
#ifdef TIC30MAGIC
2373
    case TIC30MAGIC:
2374
      arch = bfd_arch_tic30;
2375
      break;
2376
#endif
2377
2378
#ifdef TICOFF0MAGIC
2379
#ifdef TICOFF_TARGET_ARCH
2380
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2381
    case TICOFF0MAGIC:
2382
      arch = TICOFF_TARGET_ARCH;
2383
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2384
      break;
2385
#endif
2386
#endif
2387
2388
#ifdef TICOFF1MAGIC
2389
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2390
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2391
    case TICOFF1MAGIC:
2392
    case TICOFF2MAGIC:
2393
      switch (internal_f->f_target_id)
2394
  {
2395
#ifdef TI_TARGET_ID
2396
  case TI_TARGET_ID:
2397
    arch = TICOFF_TARGET_ARCH;
2398
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2399
    break;
2400
#endif
2401
  default:
2402
    arch = bfd_arch_obscure;
2403
    _bfd_error_handler
2404
      (_("unrecognized TI COFF target id '0x%x'"),
2405
       internal_f->f_target_id);
2406
    break;
2407
  }
2408
      break;
2409
#endif
2410
2411
#ifdef MCOREMAGIC
2412
    case MCOREMAGIC:
2413
      arch = bfd_arch_mcore;
2414
      break;
2415
#endif
2416
2417
133
    default:      /* Unreadable input file type.  */
2418
0
      arch = bfd_arch_obscure;
2419
0
      break;
2420
133
    }
2421
2422
133
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
133
  return true;
2424
133
}
coff-sh.c:coff_set_arch_mach_hook
Line
Count
Source
2162
2.38k
{
2163
2.38k
  unsigned long machine;
2164
2.38k
  enum bfd_architecture arch;
2165
2.38k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
2.38k
  machine = 0;
2169
2.38k
  switch (internal_f->f_magic)
2170
2.38k
    {
2171
#ifdef I386MAGIC
2172
    case I386MAGIC:
2173
    case I386PTXMAGIC:
2174
    case I386AIXMAGIC:    /* Danbury PS/2 AIX C Compiler.  */
2175
    case LYNXCOFFMAGIC:
2176
    case I386_APPLE_MAGIC:
2177
    case I386_FREEBSD_MAGIC:
2178
    case I386_LINUX_MAGIC:
2179
    case I386_NETBSD_MAGIC:
2180
      arch = bfd_arch_i386;
2181
      break;
2182
#endif
2183
#ifdef AMD64MAGIC
2184
    case AMD64MAGIC:
2185
    case AMD64_APPLE_MAGIC:
2186
    case AMD64_FREEBSD_MAGIC:
2187
    case AMD64_LINUX_MAGIC:
2188
    case AMD64_NETBSD_MAGIC:
2189
      arch = bfd_arch_i386;
2190
      machine = bfd_mach_x86_64;
2191
      break;
2192
#endif
2193
#ifdef IA64MAGIC
2194
    case IA64MAGIC:
2195
      arch = bfd_arch_ia64;
2196
      break;
2197
#endif
2198
#ifdef ARMMAGIC
2199
    case ARMMAGIC:
2200
    case ARMPEMAGIC:
2201
    case THUMBPEMAGIC:
2202
      arch = bfd_arch_arm;
2203
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2204
      if (machine == bfd_mach_arm_unknown)
2205
  {
2206
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2207
      {
2208
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2209
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2210
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2211
      default:
2212
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2213
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2214
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2215
        /* The COFF header does not have enough bits available
2216
     to cover all the different ARM architectures.  So
2217
     we interpret F_ARM_5, the highest flag value to mean
2218
     "the highest ARM architecture known to BFD" which is
2219
     currently the XScale.  */
2220
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2221
      }
2222
  }
2223
      break;
2224
#endif
2225
#ifdef AARCH64MAGIC
2226
    case AARCH64MAGIC:
2227
      arch = bfd_arch_aarch64;
2228
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2229
      break;
2230
#endif
2231
#ifdef LOONGARCH64MAGIC
2232
    case LOONGARCH64MAGIC:
2233
      arch = bfd_arch_loongarch;
2234
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2235
      break;
2236
#endif
2237
#ifdef Z80MAGIC
2238
    case Z80MAGIC:
2239
      arch = bfd_arch_z80;
2240
      switch (internal_f->f_flags & F_MACHMASK)
2241
  {
2242
  case bfd_mach_z80strict << 12:
2243
  case bfd_mach_z80 << 12:
2244
  case bfd_mach_z80n << 12:
2245
  case bfd_mach_z80full << 12:
2246
  case bfd_mach_r800 << 12:
2247
  case bfd_mach_gbz80 << 12:
2248
  case bfd_mach_z180 << 12:
2249
  case bfd_mach_ez80_z80 << 12:
2250
  case bfd_mach_ez80_adl << 12:
2251
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2252
    break;
2253
  default:
2254
    return false;
2255
  }
2256
      break;
2257
#endif
2258
#ifdef Z8KMAGIC
2259
    case Z8KMAGIC:
2260
      arch = bfd_arch_z8k;
2261
      switch (internal_f->f_flags & F_MACHMASK)
2262
  {
2263
  case F_Z8001:
2264
    machine = bfd_mach_z8001;
2265
    break;
2266
  case F_Z8002:
2267
    machine = bfd_mach_z8002;
2268
    break;
2269
  default:
2270
    return false;
2271
  }
2272
      break;
2273
#endif
2274
2275
#ifdef RS6000COFF_C
2276
#ifdef XCOFF64
2277
    case U64_TOCMAGIC:
2278
    case U803XTOCMAGIC:
2279
#else
2280
    case U802ROMAGIC:
2281
    case U802WRMAGIC:
2282
    case U802TOCMAGIC:
2283
#endif
2284
      {
2285
  int cputype;
2286
2287
  if (xcoff_data (abfd)->cputype != -1)
2288
    cputype = xcoff_data (abfd)->cputype & 0xff;
2289
  else
2290
    {
2291
      /* We did not get a value from the a.out header.  If the
2292
         file has not been stripped, we may be able to get the
2293
         architecture information from the first symbol, if it
2294
         is a .file symbol.  */
2295
      if (obj_raw_syment_count (abfd) == 0)
2296
        cputype = 0;
2297
      else
2298
        {
2299
    bfd_byte *buf;
2300
    struct internal_syment sym;
2301
    bfd_size_type amt = bfd_coff_symesz (abfd);
2302
2303
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2304
      return false;
2305
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2306
    if (buf == NULL)
2307
      return false;
2308
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2309
    if (sym.n_sclass == C_FILE)
2310
      cputype = sym.n_type & 0xff;
2311
    else
2312
      cputype = 0;
2313
    free (buf);
2314
        }
2315
    }
2316
2317
  /* FIXME: We don't handle all cases here.  */
2318
  switch (cputype)
2319
    {
2320
    default:
2321
    case 0:
2322
      arch = bfd_xcoff_architecture (abfd);
2323
      machine = bfd_xcoff_machine (abfd);
2324
      break;
2325
2326
    case 1:
2327
      arch = bfd_arch_powerpc;
2328
      machine = bfd_mach_ppc_601;
2329
      break;
2330
    case 2: /* 64 bit PowerPC */
2331
      arch = bfd_arch_powerpc;
2332
      machine = bfd_mach_ppc_620;
2333
      break;
2334
    case 3:
2335
      arch = bfd_arch_powerpc;
2336
      machine = bfd_mach_ppc;
2337
      break;
2338
    case 4:
2339
      arch = bfd_arch_rs6000;
2340
      machine = bfd_mach_rs6k;
2341
      break;
2342
    }
2343
      }
2344
      break;
2345
#endif
2346
2347
0
#ifdef SH_ARCH_MAGIC_BIG
2348
2.38k
    case SH_ARCH_MAGIC_BIG:
2349
2.38k
    case SH_ARCH_MAGIC_LITTLE:
2350
#ifdef COFF_WITH_PE
2351
    case SH_ARCH_MAGIC_WINCE:
2352
#endif
2353
2.38k
      arch = bfd_arch_sh;
2354
2.38k
      break;
2355
0
#endif
2356
2357
#ifdef MIPS_ARCH_MAGIC_WINCE
2358
    case MIPS_ARCH_MAGIC_WINCE:
2359
      arch = bfd_arch_mips;
2360
      break;
2361
#endif
2362
2363
#ifdef SPARCMAGIC
2364
    case SPARCMAGIC:
2365
#ifdef LYNXCOFFMAGIC
2366
    case LYNXCOFFMAGIC:
2367
#endif
2368
      arch = bfd_arch_sparc;
2369
      break;
2370
#endif
2371
2372
#ifdef TIC30MAGIC
2373
    case TIC30MAGIC:
2374
      arch = bfd_arch_tic30;
2375
      break;
2376
#endif
2377
2378
#ifdef TICOFF0MAGIC
2379
#ifdef TICOFF_TARGET_ARCH
2380
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2381
    case TICOFF0MAGIC:
2382
      arch = TICOFF_TARGET_ARCH;
2383
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2384
      break;
2385
#endif
2386
#endif
2387
2388
#ifdef TICOFF1MAGIC
2389
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2390
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2391
    case TICOFF1MAGIC:
2392
    case TICOFF2MAGIC:
2393
      switch (internal_f->f_target_id)
2394
  {
2395
#ifdef TI_TARGET_ID
2396
  case TI_TARGET_ID:
2397
    arch = TICOFF_TARGET_ARCH;
2398
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2399
    break;
2400
#endif
2401
  default:
2402
    arch = bfd_arch_obscure;
2403
    _bfd_error_handler
2404
      (_("unrecognized TI COFF target id '0x%x'"),
2405
       internal_f->f_target_id);
2406
    break;
2407
  }
2408
      break;
2409
#endif
2410
2411
#ifdef MCOREMAGIC
2412
    case MCOREMAGIC:
2413
      arch = bfd_arch_mcore;
2414
      break;
2415
#endif
2416
2417
0
    default:      /* Unreadable input file type.  */
2418
0
      arch = bfd_arch_obscure;
2419
0
      break;
2420
2.38k
    }
2421
2422
2.38k
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
2.38k
  return true;
2424
2.38k
}
coff-stgo32.c:coff_set_arch_mach_hook
Line
Count
Source
2162
106
{
2163
106
  unsigned long machine;
2164
106
  enum bfd_architecture arch;
2165
106
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
106
  machine = 0;
2169
106
  switch (internal_f->f_magic)
2170
106
    {
2171
0
#ifdef I386MAGIC
2172
2
    case I386MAGIC:
2173
17
    case I386PTXMAGIC:
2174
17
    case I386AIXMAGIC:   /* Danbury PS/2 AIX C Compiler.  */
2175
17
    case LYNXCOFFMAGIC:
2176
17
    case I386_APPLE_MAGIC:
2177
17
    case I386_FREEBSD_MAGIC:
2178
17
    case I386_LINUX_MAGIC:
2179
106
    case I386_NETBSD_MAGIC:
2180
106
      arch = bfd_arch_i386;
2181
106
      break;
2182
0
#endif
2183
#ifdef AMD64MAGIC
2184
    case AMD64MAGIC:
2185
    case AMD64_APPLE_MAGIC:
2186
    case AMD64_FREEBSD_MAGIC:
2187
    case AMD64_LINUX_MAGIC:
2188
    case AMD64_NETBSD_MAGIC:
2189
      arch = bfd_arch_i386;
2190
      machine = bfd_mach_x86_64;
2191
      break;
2192
#endif
2193
#ifdef IA64MAGIC
2194
    case IA64MAGIC:
2195
      arch = bfd_arch_ia64;
2196
      break;
2197
#endif
2198
#ifdef ARMMAGIC
2199
    case ARMMAGIC:
2200
    case ARMPEMAGIC:
2201
    case THUMBPEMAGIC:
2202
      arch = bfd_arch_arm;
2203
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2204
      if (machine == bfd_mach_arm_unknown)
2205
  {
2206
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2207
      {
2208
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2209
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2210
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2211
      default:
2212
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2213
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2214
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2215
        /* The COFF header does not have enough bits available
2216
     to cover all the different ARM architectures.  So
2217
     we interpret F_ARM_5, the highest flag value to mean
2218
     "the highest ARM architecture known to BFD" which is
2219
     currently the XScale.  */
2220
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2221
      }
2222
  }
2223
      break;
2224
#endif
2225
#ifdef AARCH64MAGIC
2226
    case AARCH64MAGIC:
2227
      arch = bfd_arch_aarch64;
2228
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2229
      break;
2230
#endif
2231
#ifdef LOONGARCH64MAGIC
2232
    case LOONGARCH64MAGIC:
2233
      arch = bfd_arch_loongarch;
2234
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2235
      break;
2236
#endif
2237
#ifdef Z80MAGIC
2238
    case Z80MAGIC:
2239
      arch = bfd_arch_z80;
2240
      switch (internal_f->f_flags & F_MACHMASK)
2241
  {
2242
  case bfd_mach_z80strict << 12:
2243
  case bfd_mach_z80 << 12:
2244
  case bfd_mach_z80n << 12:
2245
  case bfd_mach_z80full << 12:
2246
  case bfd_mach_r800 << 12:
2247
  case bfd_mach_gbz80 << 12:
2248
  case bfd_mach_z180 << 12:
2249
  case bfd_mach_ez80_z80 << 12:
2250
  case bfd_mach_ez80_adl << 12:
2251
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2252
    break;
2253
  default:
2254
    return false;
2255
  }
2256
      break;
2257
#endif
2258
#ifdef Z8KMAGIC
2259
    case Z8KMAGIC:
2260
      arch = bfd_arch_z8k;
2261
      switch (internal_f->f_flags & F_MACHMASK)
2262
  {
2263
  case F_Z8001:
2264
    machine = bfd_mach_z8001;
2265
    break;
2266
  case F_Z8002:
2267
    machine = bfd_mach_z8002;
2268
    break;
2269
  default:
2270
    return false;
2271
  }
2272
      break;
2273
#endif
2274
2275
#ifdef RS6000COFF_C
2276
#ifdef XCOFF64
2277
    case U64_TOCMAGIC:
2278
    case U803XTOCMAGIC:
2279
#else
2280
    case U802ROMAGIC:
2281
    case U802WRMAGIC:
2282
    case U802TOCMAGIC:
2283
#endif
2284
      {
2285
  int cputype;
2286
2287
  if (xcoff_data (abfd)->cputype != -1)
2288
    cputype = xcoff_data (abfd)->cputype & 0xff;
2289
  else
2290
    {
2291
      /* We did not get a value from the a.out header.  If the
2292
         file has not been stripped, we may be able to get the
2293
         architecture information from the first symbol, if it
2294
         is a .file symbol.  */
2295
      if (obj_raw_syment_count (abfd) == 0)
2296
        cputype = 0;
2297
      else
2298
        {
2299
    bfd_byte *buf;
2300
    struct internal_syment sym;
2301
    bfd_size_type amt = bfd_coff_symesz (abfd);
2302
2303
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2304
      return false;
2305
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2306
    if (buf == NULL)
2307
      return false;
2308
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2309
    if (sym.n_sclass == C_FILE)
2310
      cputype = sym.n_type & 0xff;
2311
    else
2312
      cputype = 0;
2313
    free (buf);
2314
        }
2315
    }
2316
2317
  /* FIXME: We don't handle all cases here.  */
2318
  switch (cputype)
2319
    {
2320
    default:
2321
    case 0:
2322
      arch = bfd_xcoff_architecture (abfd);
2323
      machine = bfd_xcoff_machine (abfd);
2324
      break;
2325
2326
    case 1:
2327
      arch = bfd_arch_powerpc;
2328
      machine = bfd_mach_ppc_601;
2329
      break;
2330
    case 2: /* 64 bit PowerPC */
2331
      arch = bfd_arch_powerpc;
2332
      machine = bfd_mach_ppc_620;
2333
      break;
2334
    case 3:
2335
      arch = bfd_arch_powerpc;
2336
      machine = bfd_mach_ppc;
2337
      break;
2338
    case 4:
2339
      arch = bfd_arch_rs6000;
2340
      machine = bfd_mach_rs6k;
2341
      break;
2342
    }
2343
      }
2344
      break;
2345
#endif
2346
2347
#ifdef SH_ARCH_MAGIC_BIG
2348
    case SH_ARCH_MAGIC_BIG:
2349
    case SH_ARCH_MAGIC_LITTLE:
2350
#ifdef COFF_WITH_PE
2351
    case SH_ARCH_MAGIC_WINCE:
2352
#endif
2353
      arch = bfd_arch_sh;
2354
      break;
2355
#endif
2356
2357
#ifdef MIPS_ARCH_MAGIC_WINCE
2358
    case MIPS_ARCH_MAGIC_WINCE:
2359
      arch = bfd_arch_mips;
2360
      break;
2361
#endif
2362
2363
#ifdef SPARCMAGIC
2364
    case SPARCMAGIC:
2365
#ifdef LYNXCOFFMAGIC
2366
    case LYNXCOFFMAGIC:
2367
#endif
2368
      arch = bfd_arch_sparc;
2369
      break;
2370
#endif
2371
2372
#ifdef TIC30MAGIC
2373
    case TIC30MAGIC:
2374
      arch = bfd_arch_tic30;
2375
      break;
2376
#endif
2377
2378
#ifdef TICOFF0MAGIC
2379
#ifdef TICOFF_TARGET_ARCH
2380
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2381
    case TICOFF0MAGIC:
2382
      arch = TICOFF_TARGET_ARCH;
2383
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2384
      break;
2385
#endif
2386
#endif
2387
2388
#ifdef TICOFF1MAGIC
2389
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2390
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2391
    case TICOFF1MAGIC:
2392
    case TICOFF2MAGIC:
2393
      switch (internal_f->f_target_id)
2394
  {
2395
#ifdef TI_TARGET_ID
2396
  case TI_TARGET_ID:
2397
    arch = TICOFF_TARGET_ARCH;
2398
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2399
    break;
2400
#endif
2401
  default:
2402
    arch = bfd_arch_obscure;
2403
    _bfd_error_handler
2404
      (_("unrecognized TI COFF target id '0x%x'"),
2405
       internal_f->f_target_id);
2406
    break;
2407
  }
2408
      break;
2409
#endif
2410
2411
#ifdef MCOREMAGIC
2412
    case MCOREMAGIC:
2413
      arch = bfd_arch_mcore;
2414
      break;
2415
#endif
2416
2417
0
    default:      /* Unreadable input file type.  */
2418
0
      arch = bfd_arch_obscure;
2419
0
      break;
2420
106
    }
2421
2422
106
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
106
  return true;
2424
106
}
coff-tic30.c:coff_set_arch_mach_hook
Line
Count
Source
2162
40
{
2163
40
  unsigned long machine;
2164
40
  enum bfd_architecture arch;
2165
40
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
40
  machine = 0;
2169
40
  switch (internal_f->f_magic)
2170
40
    {
2171
#ifdef I386MAGIC
2172
    case I386MAGIC:
2173
    case I386PTXMAGIC:
2174
    case I386AIXMAGIC:    /* Danbury PS/2 AIX C Compiler.  */
2175
    case LYNXCOFFMAGIC:
2176
    case I386_APPLE_MAGIC:
2177
    case I386_FREEBSD_MAGIC:
2178
    case I386_LINUX_MAGIC:
2179
    case I386_NETBSD_MAGIC:
2180
      arch = bfd_arch_i386;
2181
      break;
2182
#endif
2183
#ifdef AMD64MAGIC
2184
    case AMD64MAGIC:
2185
    case AMD64_APPLE_MAGIC:
2186
    case AMD64_FREEBSD_MAGIC:
2187
    case AMD64_LINUX_MAGIC:
2188
    case AMD64_NETBSD_MAGIC:
2189
      arch = bfd_arch_i386;
2190
      machine = bfd_mach_x86_64;
2191
      break;
2192
#endif
2193
#ifdef IA64MAGIC
2194
    case IA64MAGIC:
2195
      arch = bfd_arch_ia64;
2196
      break;
2197
#endif
2198
#ifdef ARMMAGIC
2199
    case ARMMAGIC:
2200
    case ARMPEMAGIC:
2201
    case THUMBPEMAGIC:
2202
      arch = bfd_arch_arm;
2203
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2204
      if (machine == bfd_mach_arm_unknown)
2205
  {
2206
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2207
      {
2208
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2209
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2210
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2211
      default:
2212
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2213
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2214
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2215
        /* The COFF header does not have enough bits available
2216
     to cover all the different ARM architectures.  So
2217
     we interpret F_ARM_5, the highest flag value to mean
2218
     "the highest ARM architecture known to BFD" which is
2219
     currently the XScale.  */
2220
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2221
      }
2222
  }
2223
      break;
2224
#endif
2225
#ifdef AARCH64MAGIC
2226
    case AARCH64MAGIC:
2227
      arch = bfd_arch_aarch64;
2228
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2229
      break;
2230
#endif
2231
#ifdef LOONGARCH64MAGIC
2232
    case LOONGARCH64MAGIC:
2233
      arch = bfd_arch_loongarch;
2234
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2235
      break;
2236
#endif
2237
#ifdef Z80MAGIC
2238
    case Z80MAGIC:
2239
      arch = bfd_arch_z80;
2240
      switch (internal_f->f_flags & F_MACHMASK)
2241
  {
2242
  case bfd_mach_z80strict << 12:
2243
  case bfd_mach_z80 << 12:
2244
  case bfd_mach_z80n << 12:
2245
  case bfd_mach_z80full << 12:
2246
  case bfd_mach_r800 << 12:
2247
  case bfd_mach_gbz80 << 12:
2248
  case bfd_mach_z180 << 12:
2249
  case bfd_mach_ez80_z80 << 12:
2250
  case bfd_mach_ez80_adl << 12:
2251
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2252
    break;
2253
  default:
2254
    return false;
2255
  }
2256
      break;
2257
#endif
2258
#ifdef Z8KMAGIC
2259
    case Z8KMAGIC:
2260
      arch = bfd_arch_z8k;
2261
      switch (internal_f->f_flags & F_MACHMASK)
2262
  {
2263
  case F_Z8001:
2264
    machine = bfd_mach_z8001;
2265
    break;
2266
  case F_Z8002:
2267
    machine = bfd_mach_z8002;
2268
    break;
2269
  default:
2270
    return false;
2271
  }
2272
      break;
2273
#endif
2274
2275
#ifdef RS6000COFF_C
2276
#ifdef XCOFF64
2277
    case U64_TOCMAGIC:
2278
    case U803XTOCMAGIC:
2279
#else
2280
    case U802ROMAGIC:
2281
    case U802WRMAGIC:
2282
    case U802TOCMAGIC:
2283
#endif
2284
      {
2285
  int cputype;
2286
2287
  if (xcoff_data (abfd)->cputype != -1)
2288
    cputype = xcoff_data (abfd)->cputype & 0xff;
2289
  else
2290
    {
2291
      /* We did not get a value from the a.out header.  If the
2292
         file has not been stripped, we may be able to get the
2293
         architecture information from the first symbol, if it
2294
         is a .file symbol.  */
2295
      if (obj_raw_syment_count (abfd) == 0)
2296
        cputype = 0;
2297
      else
2298
        {
2299
    bfd_byte *buf;
2300
    struct internal_syment sym;
2301
    bfd_size_type amt = bfd_coff_symesz (abfd);
2302
2303
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2304
      return false;
2305
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2306
    if (buf == NULL)
2307
      return false;
2308
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2309
    if (sym.n_sclass == C_FILE)
2310
      cputype = sym.n_type & 0xff;
2311
    else
2312
      cputype = 0;
2313
    free (buf);
2314
        }
2315
    }
2316
2317
  /* FIXME: We don't handle all cases here.  */
2318
  switch (cputype)
2319
    {
2320
    default:
2321
    case 0:
2322
      arch = bfd_xcoff_architecture (abfd);
2323
      machine = bfd_xcoff_machine (abfd);
2324
      break;
2325
2326
    case 1:
2327
      arch = bfd_arch_powerpc;
2328
      machine = bfd_mach_ppc_601;
2329
      break;
2330
    case 2: /* 64 bit PowerPC */
2331
      arch = bfd_arch_powerpc;
2332
      machine = bfd_mach_ppc_620;
2333
      break;
2334
    case 3:
2335
      arch = bfd_arch_powerpc;
2336
      machine = bfd_mach_ppc;
2337
      break;
2338
    case 4:
2339
      arch = bfd_arch_rs6000;
2340
      machine = bfd_mach_rs6k;
2341
      break;
2342
    }
2343
      }
2344
      break;
2345
#endif
2346
2347
#ifdef SH_ARCH_MAGIC_BIG
2348
    case SH_ARCH_MAGIC_BIG:
2349
    case SH_ARCH_MAGIC_LITTLE:
2350
#ifdef COFF_WITH_PE
2351
    case SH_ARCH_MAGIC_WINCE:
2352
#endif
2353
      arch = bfd_arch_sh;
2354
      break;
2355
#endif
2356
2357
#ifdef MIPS_ARCH_MAGIC_WINCE
2358
    case MIPS_ARCH_MAGIC_WINCE:
2359
      arch = bfd_arch_mips;
2360
      break;
2361
#endif
2362
2363
#ifdef SPARCMAGIC
2364
    case SPARCMAGIC:
2365
#ifdef LYNXCOFFMAGIC
2366
    case LYNXCOFFMAGIC:
2367
#endif
2368
      arch = bfd_arch_sparc;
2369
      break;
2370
#endif
2371
2372
0
#ifdef TIC30MAGIC
2373
40
    case TIC30MAGIC:
2374
40
      arch = bfd_arch_tic30;
2375
40
      break;
2376
0
#endif
2377
2378
#ifdef TICOFF0MAGIC
2379
#ifdef TICOFF_TARGET_ARCH
2380
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2381
    case TICOFF0MAGIC:
2382
      arch = TICOFF_TARGET_ARCH;
2383
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2384
      break;
2385
#endif
2386
#endif
2387
2388
#ifdef TICOFF1MAGIC
2389
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2390
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2391
    case TICOFF1MAGIC:
2392
    case TICOFF2MAGIC:
2393
      switch (internal_f->f_target_id)
2394
  {
2395
#ifdef TI_TARGET_ID
2396
  case TI_TARGET_ID:
2397
    arch = TICOFF_TARGET_ARCH;
2398
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2399
    break;
2400
#endif
2401
  default:
2402
    arch = bfd_arch_obscure;
2403
    _bfd_error_handler
2404
      (_("unrecognized TI COFF target id '0x%x'"),
2405
       internal_f->f_target_id);
2406
    break;
2407
  }
2408
      break;
2409
#endif
2410
2411
#ifdef MCOREMAGIC
2412
    case MCOREMAGIC:
2413
      arch = bfd_arch_mcore;
2414
      break;
2415
#endif
2416
2417
0
    default:      /* Unreadable input file type.  */
2418
0
      arch = bfd_arch_obscure;
2419
0
      break;
2420
40
    }
2421
2422
40
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
40
  return true;
2424
40
}
Unexecuted instantiation: coff-tic4x.c:coff_set_arch_mach_hook
coff-tic54x.c:coff_set_arch_mach_hook
Line
Count
Source
2162
68
{
2163
68
  unsigned long machine;
2164
68
  enum bfd_architecture arch;
2165
68
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
68
  machine = 0;
2169
68
  switch (internal_f->f_magic)
2170
68
    {
2171
#ifdef I386MAGIC
2172
    case I386MAGIC:
2173
    case I386PTXMAGIC:
2174
    case I386AIXMAGIC:    /* Danbury PS/2 AIX C Compiler.  */
2175
    case LYNXCOFFMAGIC:
2176
    case I386_APPLE_MAGIC:
2177
    case I386_FREEBSD_MAGIC:
2178
    case I386_LINUX_MAGIC:
2179
    case I386_NETBSD_MAGIC:
2180
      arch = bfd_arch_i386;
2181
      break;
2182
#endif
2183
#ifdef AMD64MAGIC
2184
    case AMD64MAGIC:
2185
    case AMD64_APPLE_MAGIC:
2186
    case AMD64_FREEBSD_MAGIC:
2187
    case AMD64_LINUX_MAGIC:
2188
    case AMD64_NETBSD_MAGIC:
2189
      arch = bfd_arch_i386;
2190
      machine = bfd_mach_x86_64;
2191
      break;
2192
#endif
2193
#ifdef IA64MAGIC
2194
    case IA64MAGIC:
2195
      arch = bfd_arch_ia64;
2196
      break;
2197
#endif
2198
#ifdef ARMMAGIC
2199
    case ARMMAGIC:
2200
    case ARMPEMAGIC:
2201
    case THUMBPEMAGIC:
2202
      arch = bfd_arch_arm;
2203
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2204
      if (machine == bfd_mach_arm_unknown)
2205
  {
2206
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2207
      {
2208
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2209
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2210
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2211
      default:
2212
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2213
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2214
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2215
        /* The COFF header does not have enough bits available
2216
     to cover all the different ARM architectures.  So
2217
     we interpret F_ARM_5, the highest flag value to mean
2218
     "the highest ARM architecture known to BFD" which is
2219
     currently the XScale.  */
2220
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2221
      }
2222
  }
2223
      break;
2224
#endif
2225
#ifdef AARCH64MAGIC
2226
    case AARCH64MAGIC:
2227
      arch = bfd_arch_aarch64;
2228
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2229
      break;
2230
#endif
2231
#ifdef LOONGARCH64MAGIC
2232
    case LOONGARCH64MAGIC:
2233
      arch = bfd_arch_loongarch;
2234
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2235
      break;
2236
#endif
2237
#ifdef Z80MAGIC
2238
    case Z80MAGIC:
2239
      arch = bfd_arch_z80;
2240
      switch (internal_f->f_flags & F_MACHMASK)
2241
  {
2242
  case bfd_mach_z80strict << 12:
2243
  case bfd_mach_z80 << 12:
2244
  case bfd_mach_z80n << 12:
2245
  case bfd_mach_z80full << 12:
2246
  case bfd_mach_r800 << 12:
2247
  case bfd_mach_gbz80 << 12:
2248
  case bfd_mach_z180 << 12:
2249
  case bfd_mach_ez80_z80 << 12:
2250
  case bfd_mach_ez80_adl << 12:
2251
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2252
    break;
2253
  default:
2254
    return false;
2255
  }
2256
      break;
2257
#endif
2258
#ifdef Z8KMAGIC
2259
    case Z8KMAGIC:
2260
      arch = bfd_arch_z8k;
2261
      switch (internal_f->f_flags & F_MACHMASK)
2262
  {
2263
  case F_Z8001:
2264
    machine = bfd_mach_z8001;
2265
    break;
2266
  case F_Z8002:
2267
    machine = bfd_mach_z8002;
2268
    break;
2269
  default:
2270
    return false;
2271
  }
2272
      break;
2273
#endif
2274
2275
#ifdef RS6000COFF_C
2276
#ifdef XCOFF64
2277
    case U64_TOCMAGIC:
2278
    case U803XTOCMAGIC:
2279
#else
2280
    case U802ROMAGIC:
2281
    case U802WRMAGIC:
2282
    case U802TOCMAGIC:
2283
#endif
2284
      {
2285
  int cputype;
2286
2287
  if (xcoff_data (abfd)->cputype != -1)
2288
    cputype = xcoff_data (abfd)->cputype & 0xff;
2289
  else
2290
    {
2291
      /* We did not get a value from the a.out header.  If the
2292
         file has not been stripped, we may be able to get the
2293
         architecture information from the first symbol, if it
2294
         is a .file symbol.  */
2295
      if (obj_raw_syment_count (abfd) == 0)
2296
        cputype = 0;
2297
      else
2298
        {
2299
    bfd_byte *buf;
2300
    struct internal_syment sym;
2301
    bfd_size_type amt = bfd_coff_symesz (abfd);
2302
2303
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2304
      return false;
2305
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2306
    if (buf == NULL)
2307
      return false;
2308
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2309
    if (sym.n_sclass == C_FILE)
2310
      cputype = sym.n_type & 0xff;
2311
    else
2312
      cputype = 0;
2313
    free (buf);
2314
        }
2315
    }
2316
2317
  /* FIXME: We don't handle all cases here.  */
2318
  switch (cputype)
2319
    {
2320
    default:
2321
    case 0:
2322
      arch = bfd_xcoff_architecture (abfd);
2323
      machine = bfd_xcoff_machine (abfd);
2324
      break;
2325
2326
    case 1:
2327
      arch = bfd_arch_powerpc;
2328
      machine = bfd_mach_ppc_601;
2329
      break;
2330
    case 2: /* 64 bit PowerPC */
2331
      arch = bfd_arch_powerpc;
2332
      machine = bfd_mach_ppc_620;
2333
      break;
2334
    case 3:
2335
      arch = bfd_arch_powerpc;
2336
      machine = bfd_mach_ppc;
2337
      break;
2338
    case 4:
2339
      arch = bfd_arch_rs6000;
2340
      machine = bfd_mach_rs6k;
2341
      break;
2342
    }
2343
      }
2344
      break;
2345
#endif
2346
2347
#ifdef SH_ARCH_MAGIC_BIG
2348
    case SH_ARCH_MAGIC_BIG:
2349
    case SH_ARCH_MAGIC_LITTLE:
2350
#ifdef COFF_WITH_PE
2351
    case SH_ARCH_MAGIC_WINCE:
2352
#endif
2353
      arch = bfd_arch_sh;
2354
      break;
2355
#endif
2356
2357
#ifdef MIPS_ARCH_MAGIC_WINCE
2358
    case MIPS_ARCH_MAGIC_WINCE:
2359
      arch = bfd_arch_mips;
2360
      break;
2361
#endif
2362
2363
#ifdef SPARCMAGIC
2364
    case SPARCMAGIC:
2365
#ifdef LYNXCOFFMAGIC
2366
    case LYNXCOFFMAGIC:
2367
#endif
2368
      arch = bfd_arch_sparc;
2369
      break;
2370
#endif
2371
2372
#ifdef TIC30MAGIC
2373
    case TIC30MAGIC:
2374
      arch = bfd_arch_tic30;
2375
      break;
2376
#endif
2377
2378
0
#ifdef TICOFF0MAGIC
2379
0
#ifdef TICOFF_TARGET_ARCH
2380
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2381
68
    case TICOFF0MAGIC:
2382
68
      arch = TICOFF_TARGET_ARCH;
2383
68
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2384
68
      break;
2385
0
#endif
2386
0
#endif
2387
2388
0
#ifdef TICOFF1MAGIC
2389
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2390
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2391
0
    case TICOFF1MAGIC:
2392
0
    case TICOFF2MAGIC:
2393
0
      switch (internal_f->f_target_id)
2394
0
  {
2395
0
#ifdef TI_TARGET_ID
2396
0
  case TI_TARGET_ID:
2397
0
    arch = TICOFF_TARGET_ARCH;
2398
0
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2399
0
    break;
2400
0
#endif
2401
0
  default:
2402
0
    arch = bfd_arch_obscure;
2403
0
    _bfd_error_handler
2404
0
      (_("unrecognized TI COFF target id '0x%x'"),
2405
0
       internal_f->f_target_id);
2406
0
    break;
2407
0
  }
2408
0
      break;
2409
0
#endif
2410
2411
#ifdef MCOREMAGIC
2412
    case MCOREMAGIC:
2413
      arch = bfd_arch_mcore;
2414
      break;
2415
#endif
2416
2417
0
    default:      /* Unreadable input file type.  */
2418
0
      arch = bfd_arch_obscure;
2419
0
      break;
2420
68
    }
2421
2422
68
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
68
  return true;
2424
68
}
coff-z80.c:coff_set_arch_mach_hook
Line
Count
Source
2162
42
{
2163
42
  unsigned long machine;
2164
42
  enum bfd_architecture arch;
2165
42
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
42
  machine = 0;
2169
42
  switch (internal_f->f_magic)
2170
42
    {
2171
#ifdef I386MAGIC
2172
    case I386MAGIC:
2173
    case I386PTXMAGIC:
2174
    case I386AIXMAGIC:    /* Danbury PS/2 AIX C Compiler.  */
2175
    case LYNXCOFFMAGIC:
2176
    case I386_APPLE_MAGIC:
2177
    case I386_FREEBSD_MAGIC:
2178
    case I386_LINUX_MAGIC:
2179
    case I386_NETBSD_MAGIC:
2180
      arch = bfd_arch_i386;
2181
      break;
2182
#endif
2183
#ifdef AMD64MAGIC
2184
    case AMD64MAGIC:
2185
    case AMD64_APPLE_MAGIC:
2186
    case AMD64_FREEBSD_MAGIC:
2187
    case AMD64_LINUX_MAGIC:
2188
    case AMD64_NETBSD_MAGIC:
2189
      arch = bfd_arch_i386;
2190
      machine = bfd_mach_x86_64;
2191
      break;
2192
#endif
2193
#ifdef IA64MAGIC
2194
    case IA64MAGIC:
2195
      arch = bfd_arch_ia64;
2196
      break;
2197
#endif
2198
#ifdef ARMMAGIC
2199
    case ARMMAGIC:
2200
    case ARMPEMAGIC:
2201
    case THUMBPEMAGIC:
2202
      arch = bfd_arch_arm;
2203
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2204
      if (machine == bfd_mach_arm_unknown)
2205
  {
2206
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2207
      {
2208
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2209
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2210
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2211
      default:
2212
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2213
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2214
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2215
        /* The COFF header does not have enough bits available
2216
     to cover all the different ARM architectures.  So
2217
     we interpret F_ARM_5, the highest flag value to mean
2218
     "the highest ARM architecture known to BFD" which is
2219
     currently the XScale.  */
2220
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2221
      }
2222
  }
2223
      break;
2224
#endif
2225
#ifdef AARCH64MAGIC
2226
    case AARCH64MAGIC:
2227
      arch = bfd_arch_aarch64;
2228
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2229
      break;
2230
#endif
2231
#ifdef LOONGARCH64MAGIC
2232
    case LOONGARCH64MAGIC:
2233
      arch = bfd_arch_loongarch;
2234
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2235
      break;
2236
#endif
2237
0
#ifdef Z80MAGIC
2238
42
    case Z80MAGIC:
2239
42
      arch = bfd_arch_z80;
2240
42
      switch (internal_f->f_flags & F_MACHMASK)
2241
42
  {
2242
0
  case bfd_mach_z80strict << 12:
2243
0
  case bfd_mach_z80 << 12:
2244
0
  case bfd_mach_z80n << 12:
2245
0
  case bfd_mach_z80full << 12:
2246
0
  case bfd_mach_r800 << 12:
2247
0
  case bfd_mach_gbz80 << 12:
2248
6
  case bfd_mach_z180 << 12:
2249
40
  case bfd_mach_ez80_z80 << 12:
2250
42
  case bfd_mach_ez80_adl << 12:
2251
42
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2252
42
    break;
2253
0
  default:
2254
0
    return false;
2255
42
  }
2256
42
      break;
2257
42
#endif
2258
#ifdef Z8KMAGIC
2259
    case Z8KMAGIC:
2260
      arch = bfd_arch_z8k;
2261
      switch (internal_f->f_flags & F_MACHMASK)
2262
  {
2263
  case F_Z8001:
2264
    machine = bfd_mach_z8001;
2265
    break;
2266
  case F_Z8002:
2267
    machine = bfd_mach_z8002;
2268
    break;
2269
  default:
2270
    return false;
2271
  }
2272
      break;
2273
#endif
2274
2275
#ifdef RS6000COFF_C
2276
#ifdef XCOFF64
2277
    case U64_TOCMAGIC:
2278
    case U803XTOCMAGIC:
2279
#else
2280
    case U802ROMAGIC:
2281
    case U802WRMAGIC:
2282
    case U802TOCMAGIC:
2283
#endif
2284
      {
2285
  int cputype;
2286
2287
  if (xcoff_data (abfd)->cputype != -1)
2288
    cputype = xcoff_data (abfd)->cputype & 0xff;
2289
  else
2290
    {
2291
      /* We did not get a value from the a.out header.  If the
2292
         file has not been stripped, we may be able to get the
2293
         architecture information from the first symbol, if it
2294
         is a .file symbol.  */
2295
      if (obj_raw_syment_count (abfd) == 0)
2296
        cputype = 0;
2297
      else
2298
        {
2299
    bfd_byte *buf;
2300
    struct internal_syment sym;
2301
    bfd_size_type amt = bfd_coff_symesz (abfd);
2302
2303
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2304
      return false;
2305
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2306
    if (buf == NULL)
2307
      return false;
2308
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2309
    if (sym.n_sclass == C_FILE)
2310
      cputype = sym.n_type & 0xff;
2311
    else
2312
      cputype = 0;
2313
    free (buf);
2314
        }
2315
    }
2316
2317
  /* FIXME: We don't handle all cases here.  */
2318
  switch (cputype)
2319
    {
2320
    default:
2321
    case 0:
2322
      arch = bfd_xcoff_architecture (abfd);
2323
      machine = bfd_xcoff_machine (abfd);
2324
      break;
2325
2326
    case 1:
2327
      arch = bfd_arch_powerpc;
2328
      machine = bfd_mach_ppc_601;
2329
      break;
2330
    case 2: /* 64 bit PowerPC */
2331
      arch = bfd_arch_powerpc;
2332
      machine = bfd_mach_ppc_620;
2333
      break;
2334
    case 3:
2335
      arch = bfd_arch_powerpc;
2336
      machine = bfd_mach_ppc;
2337
      break;
2338
    case 4:
2339
      arch = bfd_arch_rs6000;
2340
      machine = bfd_mach_rs6k;
2341
      break;
2342
    }
2343
      }
2344
      break;
2345
#endif
2346
2347
#ifdef SH_ARCH_MAGIC_BIG
2348
    case SH_ARCH_MAGIC_BIG:
2349
    case SH_ARCH_MAGIC_LITTLE:
2350
#ifdef COFF_WITH_PE
2351
    case SH_ARCH_MAGIC_WINCE:
2352
#endif
2353
      arch = bfd_arch_sh;
2354
      break;
2355
#endif
2356
2357
#ifdef MIPS_ARCH_MAGIC_WINCE
2358
    case MIPS_ARCH_MAGIC_WINCE:
2359
      arch = bfd_arch_mips;
2360
      break;
2361
#endif
2362
2363
#ifdef SPARCMAGIC
2364
    case SPARCMAGIC:
2365
#ifdef LYNXCOFFMAGIC
2366
    case LYNXCOFFMAGIC:
2367
#endif
2368
      arch = bfd_arch_sparc;
2369
      break;
2370
#endif
2371
2372
#ifdef TIC30MAGIC
2373
    case TIC30MAGIC:
2374
      arch = bfd_arch_tic30;
2375
      break;
2376
#endif
2377
2378
#ifdef TICOFF0MAGIC
2379
#ifdef TICOFF_TARGET_ARCH
2380
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2381
    case TICOFF0MAGIC:
2382
      arch = TICOFF_TARGET_ARCH;
2383
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2384
      break;
2385
#endif
2386
#endif
2387
2388
#ifdef TICOFF1MAGIC
2389
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2390
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2391
    case TICOFF1MAGIC:
2392
    case TICOFF2MAGIC:
2393
      switch (internal_f->f_target_id)
2394
  {
2395
#ifdef TI_TARGET_ID
2396
  case TI_TARGET_ID:
2397
    arch = TICOFF_TARGET_ARCH;
2398
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2399
    break;
2400
#endif
2401
  default:
2402
    arch = bfd_arch_obscure;
2403
    _bfd_error_handler
2404
      (_("unrecognized TI COFF target id '0x%x'"),
2405
       internal_f->f_target_id);
2406
    break;
2407
  }
2408
      break;
2409
#endif
2410
2411
#ifdef MCOREMAGIC
2412
    case MCOREMAGIC:
2413
      arch = bfd_arch_mcore;
2414
      break;
2415
#endif
2416
2417
42
    default:      /* Unreadable input file type.  */
2418
0
      arch = bfd_arch_obscure;
2419
0
      break;
2420
42
    }
2421
2422
42
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
42
  return true;
2424
42
}
coff-z8k.c:coff_set_arch_mach_hook
Line
Count
Source
2162
49
{
2163
49
  unsigned long machine;
2164
49
  enum bfd_architecture arch;
2165
49
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
49
  machine = 0;
2169
49
  switch (internal_f->f_magic)
2170
49
    {
2171
#ifdef I386MAGIC
2172
    case I386MAGIC:
2173
    case I386PTXMAGIC:
2174
    case I386AIXMAGIC:    /* Danbury PS/2 AIX C Compiler.  */
2175
    case LYNXCOFFMAGIC:
2176
    case I386_APPLE_MAGIC:
2177
    case I386_FREEBSD_MAGIC:
2178
    case I386_LINUX_MAGIC:
2179
    case I386_NETBSD_MAGIC:
2180
      arch = bfd_arch_i386;
2181
      break;
2182
#endif
2183
#ifdef AMD64MAGIC
2184
    case AMD64MAGIC:
2185
    case AMD64_APPLE_MAGIC:
2186
    case AMD64_FREEBSD_MAGIC:
2187
    case AMD64_LINUX_MAGIC:
2188
    case AMD64_NETBSD_MAGIC:
2189
      arch = bfd_arch_i386;
2190
      machine = bfd_mach_x86_64;
2191
      break;
2192
#endif
2193
#ifdef IA64MAGIC
2194
    case IA64MAGIC:
2195
      arch = bfd_arch_ia64;
2196
      break;
2197
#endif
2198
#ifdef ARMMAGIC
2199
    case ARMMAGIC:
2200
    case ARMPEMAGIC:
2201
    case THUMBPEMAGIC:
2202
      arch = bfd_arch_arm;
2203
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2204
      if (machine == bfd_mach_arm_unknown)
2205
  {
2206
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2207
      {
2208
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2209
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2210
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2211
      default:
2212
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2213
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2214
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2215
        /* The COFF header does not have enough bits available
2216
     to cover all the different ARM architectures.  So
2217
     we interpret F_ARM_5, the highest flag value to mean
2218
     "the highest ARM architecture known to BFD" which is
2219
     currently the XScale.  */
2220
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2221
      }
2222
  }
2223
      break;
2224
#endif
2225
#ifdef AARCH64MAGIC
2226
    case AARCH64MAGIC:
2227
      arch = bfd_arch_aarch64;
2228
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2229
      break;
2230
#endif
2231
#ifdef LOONGARCH64MAGIC
2232
    case LOONGARCH64MAGIC:
2233
      arch = bfd_arch_loongarch;
2234
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2235
      break;
2236
#endif
2237
#ifdef Z80MAGIC
2238
    case Z80MAGIC:
2239
      arch = bfd_arch_z80;
2240
      switch (internal_f->f_flags & F_MACHMASK)
2241
  {
2242
  case bfd_mach_z80strict << 12:
2243
  case bfd_mach_z80 << 12:
2244
  case bfd_mach_z80n << 12:
2245
  case bfd_mach_z80full << 12:
2246
  case bfd_mach_r800 << 12:
2247
  case bfd_mach_gbz80 << 12:
2248
  case bfd_mach_z180 << 12:
2249
  case bfd_mach_ez80_z80 << 12:
2250
  case bfd_mach_ez80_adl << 12:
2251
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2252
    break;
2253
  default:
2254
    return false;
2255
  }
2256
      break;
2257
#endif
2258
0
#ifdef Z8KMAGIC
2259
49
    case Z8KMAGIC:
2260
49
      arch = bfd_arch_z8k;
2261
49
      switch (internal_f->f_flags & F_MACHMASK)
2262
49
  {
2263
8
  case F_Z8001:
2264
8
    machine = bfd_mach_z8001;
2265
8
    break;
2266
41
  case F_Z8002:
2267
41
    machine = bfd_mach_z8002;
2268
41
    break;
2269
0
  default:
2270
0
    return false;
2271
49
  }
2272
49
      break;
2273
49
#endif
2274
2275
#ifdef RS6000COFF_C
2276
#ifdef XCOFF64
2277
    case U64_TOCMAGIC:
2278
    case U803XTOCMAGIC:
2279
#else
2280
    case U802ROMAGIC:
2281
    case U802WRMAGIC:
2282
    case U802TOCMAGIC:
2283
#endif
2284
      {
2285
  int cputype;
2286
2287
  if (xcoff_data (abfd)->cputype != -1)
2288
    cputype = xcoff_data (abfd)->cputype & 0xff;
2289
  else
2290
    {
2291
      /* We did not get a value from the a.out header.  If the
2292
         file has not been stripped, we may be able to get the
2293
         architecture information from the first symbol, if it
2294
         is a .file symbol.  */
2295
      if (obj_raw_syment_count (abfd) == 0)
2296
        cputype = 0;
2297
      else
2298
        {
2299
    bfd_byte *buf;
2300
    struct internal_syment sym;
2301
    bfd_size_type amt = bfd_coff_symesz (abfd);
2302
2303
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2304
      return false;
2305
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2306
    if (buf == NULL)
2307
      return false;
2308
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2309
    if (sym.n_sclass == C_FILE)
2310
      cputype = sym.n_type & 0xff;
2311
    else
2312
      cputype = 0;
2313
    free (buf);
2314
        }
2315
    }
2316
2317
  /* FIXME: We don't handle all cases here.  */
2318
  switch (cputype)
2319
    {
2320
    default:
2321
    case 0:
2322
      arch = bfd_xcoff_architecture (abfd);
2323
      machine = bfd_xcoff_machine (abfd);
2324
      break;
2325
2326
    case 1:
2327
      arch = bfd_arch_powerpc;
2328
      machine = bfd_mach_ppc_601;
2329
      break;
2330
    case 2: /* 64 bit PowerPC */
2331
      arch = bfd_arch_powerpc;
2332
      machine = bfd_mach_ppc_620;
2333
      break;
2334
    case 3:
2335
      arch = bfd_arch_powerpc;
2336
      machine = bfd_mach_ppc;
2337
      break;
2338
    case 4:
2339
      arch = bfd_arch_rs6000;
2340
      machine = bfd_mach_rs6k;
2341
      break;
2342
    }
2343
      }
2344
      break;
2345
#endif
2346
2347
#ifdef SH_ARCH_MAGIC_BIG
2348
    case SH_ARCH_MAGIC_BIG:
2349
    case SH_ARCH_MAGIC_LITTLE:
2350
#ifdef COFF_WITH_PE
2351
    case SH_ARCH_MAGIC_WINCE:
2352
#endif
2353
      arch = bfd_arch_sh;
2354
      break;
2355
#endif
2356
2357
#ifdef MIPS_ARCH_MAGIC_WINCE
2358
    case MIPS_ARCH_MAGIC_WINCE:
2359
      arch = bfd_arch_mips;
2360
      break;
2361
#endif
2362
2363
#ifdef SPARCMAGIC
2364
    case SPARCMAGIC:
2365
#ifdef LYNXCOFFMAGIC
2366
    case LYNXCOFFMAGIC:
2367
#endif
2368
      arch = bfd_arch_sparc;
2369
      break;
2370
#endif
2371
2372
#ifdef TIC30MAGIC
2373
    case TIC30MAGIC:
2374
      arch = bfd_arch_tic30;
2375
      break;
2376
#endif
2377
2378
#ifdef TICOFF0MAGIC
2379
#ifdef TICOFF_TARGET_ARCH
2380
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2381
    case TICOFF0MAGIC:
2382
      arch = TICOFF_TARGET_ARCH;
2383
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2384
      break;
2385
#endif
2386
#endif
2387
2388
#ifdef TICOFF1MAGIC
2389
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2390
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2391
    case TICOFF1MAGIC:
2392
    case TICOFF2MAGIC:
2393
      switch (internal_f->f_target_id)
2394
  {
2395
#ifdef TI_TARGET_ID
2396
  case TI_TARGET_ID:
2397
    arch = TICOFF_TARGET_ARCH;
2398
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2399
    break;
2400
#endif
2401
  default:
2402
    arch = bfd_arch_obscure;
2403
    _bfd_error_handler
2404
      (_("unrecognized TI COFF target id '0x%x'"),
2405
       internal_f->f_target_id);
2406
    break;
2407
  }
2408
      break;
2409
#endif
2410
2411
#ifdef MCOREMAGIC
2412
    case MCOREMAGIC:
2413
      arch = bfd_arch_mcore;
2414
      break;
2415
#endif
2416
2417
49
    default:      /* Unreadable input file type.  */
2418
0
      arch = bfd_arch_obscure;
2419
0
      break;
2420
49
    }
2421
2422
49
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
49
  return true;
2424
49
}
pe-arm-wince.c:coff_set_arch_mach_hook
Line
Count
Source
2162
4
{
2163
4
  unsigned long machine;
2164
4
  enum bfd_architecture arch;
2165
4
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
4
  machine = 0;
2169
4
  switch (internal_f->f_magic)
2170
4
    {
2171
#ifdef I386MAGIC
2172
    case I386MAGIC:
2173
    case I386PTXMAGIC:
2174
    case I386AIXMAGIC:    /* Danbury PS/2 AIX C Compiler.  */
2175
    case LYNXCOFFMAGIC:
2176
    case I386_APPLE_MAGIC:
2177
    case I386_FREEBSD_MAGIC:
2178
    case I386_LINUX_MAGIC:
2179
    case I386_NETBSD_MAGIC:
2180
      arch = bfd_arch_i386;
2181
      break;
2182
#endif
2183
#ifdef AMD64MAGIC
2184
    case AMD64MAGIC:
2185
    case AMD64_APPLE_MAGIC:
2186
    case AMD64_FREEBSD_MAGIC:
2187
    case AMD64_LINUX_MAGIC:
2188
    case AMD64_NETBSD_MAGIC:
2189
      arch = bfd_arch_i386;
2190
      machine = bfd_mach_x86_64;
2191
      break;
2192
#endif
2193
#ifdef IA64MAGIC
2194
    case IA64MAGIC:
2195
      arch = bfd_arch_ia64;
2196
      break;
2197
#endif
2198
0
#ifdef ARMMAGIC
2199
4
    case ARMMAGIC:
2200
4
    case ARMPEMAGIC:
2201
4
    case THUMBPEMAGIC:
2202
4
      arch = bfd_arch_arm;
2203
4
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2204
4
      if (machine == bfd_mach_arm_unknown)
2205
4
  {
2206
4
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2207
4
      {
2208
0
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2209
3
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2210
0
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2211
1
      default:
2212
1
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2213
0
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2214
0
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2215
        /* The COFF header does not have enough bits available
2216
     to cover all the different ARM architectures.  So
2217
     we interpret F_ARM_5, the highest flag value to mean
2218
     "the highest ARM architecture known to BFD" which is
2219
     currently the XScale.  */
2220
0
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2221
4
      }
2222
4
  }
2223
4
      break;
2224
4
#endif
2225
#ifdef AARCH64MAGIC
2226
    case AARCH64MAGIC:
2227
      arch = bfd_arch_aarch64;
2228
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2229
      break;
2230
#endif
2231
#ifdef LOONGARCH64MAGIC
2232
    case LOONGARCH64MAGIC:
2233
      arch = bfd_arch_loongarch;
2234
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2235
      break;
2236
#endif
2237
#ifdef Z80MAGIC
2238
    case Z80MAGIC:
2239
      arch = bfd_arch_z80;
2240
      switch (internal_f->f_flags & F_MACHMASK)
2241
  {
2242
  case bfd_mach_z80strict << 12:
2243
  case bfd_mach_z80 << 12:
2244
  case bfd_mach_z80n << 12:
2245
  case bfd_mach_z80full << 12:
2246
  case bfd_mach_r800 << 12:
2247
  case bfd_mach_gbz80 << 12:
2248
  case bfd_mach_z180 << 12:
2249
  case bfd_mach_ez80_z80 << 12:
2250
  case bfd_mach_ez80_adl << 12:
2251
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2252
    break;
2253
  default:
2254
    return false;
2255
  }
2256
      break;
2257
#endif
2258
#ifdef Z8KMAGIC
2259
    case Z8KMAGIC:
2260
      arch = bfd_arch_z8k;
2261
      switch (internal_f->f_flags & F_MACHMASK)
2262
  {
2263
  case F_Z8001:
2264
    machine = bfd_mach_z8001;
2265
    break;
2266
  case F_Z8002:
2267
    machine = bfd_mach_z8002;
2268
    break;
2269
  default:
2270
    return false;
2271
  }
2272
      break;
2273
#endif
2274
2275
#ifdef RS6000COFF_C
2276
#ifdef XCOFF64
2277
    case U64_TOCMAGIC:
2278
    case U803XTOCMAGIC:
2279
#else
2280
    case U802ROMAGIC:
2281
    case U802WRMAGIC:
2282
    case U802TOCMAGIC:
2283
#endif
2284
      {
2285
  int cputype;
2286
2287
  if (xcoff_data (abfd)->cputype != -1)
2288
    cputype = xcoff_data (abfd)->cputype & 0xff;
2289
  else
2290
    {
2291
      /* We did not get a value from the a.out header.  If the
2292
         file has not been stripped, we may be able to get the
2293
         architecture information from the first symbol, if it
2294
         is a .file symbol.  */
2295
      if (obj_raw_syment_count (abfd) == 0)
2296
        cputype = 0;
2297
      else
2298
        {
2299
    bfd_byte *buf;
2300
    struct internal_syment sym;
2301
    bfd_size_type amt = bfd_coff_symesz (abfd);
2302
2303
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2304
      return false;
2305
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2306
    if (buf == NULL)
2307
      return false;
2308
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2309
    if (sym.n_sclass == C_FILE)
2310
      cputype = sym.n_type & 0xff;
2311
    else
2312
      cputype = 0;
2313
    free (buf);
2314
        }
2315
    }
2316
2317
  /* FIXME: We don't handle all cases here.  */
2318
  switch (cputype)
2319
    {
2320
    default:
2321
    case 0:
2322
      arch = bfd_xcoff_architecture (abfd);
2323
      machine = bfd_xcoff_machine (abfd);
2324
      break;
2325
2326
    case 1:
2327
      arch = bfd_arch_powerpc;
2328
      machine = bfd_mach_ppc_601;
2329
      break;
2330
    case 2: /* 64 bit PowerPC */
2331
      arch = bfd_arch_powerpc;
2332
      machine = bfd_mach_ppc_620;
2333
      break;
2334
    case 3:
2335
      arch = bfd_arch_powerpc;
2336
      machine = bfd_mach_ppc;
2337
      break;
2338
    case 4:
2339
      arch = bfd_arch_rs6000;
2340
      machine = bfd_mach_rs6k;
2341
      break;
2342
    }
2343
      }
2344
      break;
2345
#endif
2346
2347
#ifdef SH_ARCH_MAGIC_BIG
2348
    case SH_ARCH_MAGIC_BIG:
2349
    case SH_ARCH_MAGIC_LITTLE:
2350
#ifdef COFF_WITH_PE
2351
    case SH_ARCH_MAGIC_WINCE:
2352
#endif
2353
      arch = bfd_arch_sh;
2354
      break;
2355
#endif
2356
2357
#ifdef MIPS_ARCH_MAGIC_WINCE
2358
    case MIPS_ARCH_MAGIC_WINCE:
2359
      arch = bfd_arch_mips;
2360
      break;
2361
#endif
2362
2363
#ifdef SPARCMAGIC
2364
    case SPARCMAGIC:
2365
#ifdef LYNXCOFFMAGIC
2366
    case LYNXCOFFMAGIC:
2367
#endif
2368
      arch = bfd_arch_sparc;
2369
      break;
2370
#endif
2371
2372
#ifdef TIC30MAGIC
2373
    case TIC30MAGIC:
2374
      arch = bfd_arch_tic30;
2375
      break;
2376
#endif
2377
2378
#ifdef TICOFF0MAGIC
2379
#ifdef TICOFF_TARGET_ARCH
2380
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2381
    case TICOFF0MAGIC:
2382
      arch = TICOFF_TARGET_ARCH;
2383
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2384
      break;
2385
#endif
2386
#endif
2387
2388
#ifdef TICOFF1MAGIC
2389
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2390
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2391
    case TICOFF1MAGIC:
2392
    case TICOFF2MAGIC:
2393
      switch (internal_f->f_target_id)
2394
  {
2395
#ifdef TI_TARGET_ID
2396
  case TI_TARGET_ID:
2397
    arch = TICOFF_TARGET_ARCH;
2398
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2399
    break;
2400
#endif
2401
  default:
2402
    arch = bfd_arch_obscure;
2403
    _bfd_error_handler
2404
      (_("unrecognized TI COFF target id '0x%x'"),
2405
       internal_f->f_target_id);
2406
    break;
2407
  }
2408
      break;
2409
#endif
2410
2411
#ifdef MCOREMAGIC
2412
    case MCOREMAGIC:
2413
      arch = bfd_arch_mcore;
2414
      break;
2415
#endif
2416
2417
4
    default:      /* Unreadable input file type.  */
2418
0
      arch = bfd_arch_obscure;
2419
0
      break;
2420
4
    }
2421
2422
4
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
4
  return true;
2424
4
}
pe-arm.c:coff_set_arch_mach_hook
Line
Count
Source
2162
4
{
2163
4
  unsigned long machine;
2164
4
  enum bfd_architecture arch;
2165
4
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
4
  machine = 0;
2169
4
  switch (internal_f->f_magic)
2170
4
    {
2171
#ifdef I386MAGIC
2172
    case I386MAGIC:
2173
    case I386PTXMAGIC:
2174
    case I386AIXMAGIC:    /* Danbury PS/2 AIX C Compiler.  */
2175
    case LYNXCOFFMAGIC:
2176
    case I386_APPLE_MAGIC:
2177
    case I386_FREEBSD_MAGIC:
2178
    case I386_LINUX_MAGIC:
2179
    case I386_NETBSD_MAGIC:
2180
      arch = bfd_arch_i386;
2181
      break;
2182
#endif
2183
#ifdef AMD64MAGIC
2184
    case AMD64MAGIC:
2185
    case AMD64_APPLE_MAGIC:
2186
    case AMD64_FREEBSD_MAGIC:
2187
    case AMD64_LINUX_MAGIC:
2188
    case AMD64_NETBSD_MAGIC:
2189
      arch = bfd_arch_i386;
2190
      machine = bfd_mach_x86_64;
2191
      break;
2192
#endif
2193
#ifdef IA64MAGIC
2194
    case IA64MAGIC:
2195
      arch = bfd_arch_ia64;
2196
      break;
2197
#endif
2198
0
#ifdef ARMMAGIC
2199
4
    case ARMMAGIC:
2200
4
    case ARMPEMAGIC:
2201
4
    case THUMBPEMAGIC:
2202
4
      arch = bfd_arch_arm;
2203
4
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2204
4
      if (machine == bfd_mach_arm_unknown)
2205
4
  {
2206
4
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2207
4
      {
2208
0
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2209
3
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2210
0
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2211
1
      default:
2212
1
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2213
0
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2214
0
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2215
        /* The COFF header does not have enough bits available
2216
     to cover all the different ARM architectures.  So
2217
     we interpret F_ARM_5, the highest flag value to mean
2218
     "the highest ARM architecture known to BFD" which is
2219
     currently the XScale.  */
2220
0
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2221
4
      }
2222
4
  }
2223
4
      break;
2224
4
#endif
2225
#ifdef AARCH64MAGIC
2226
    case AARCH64MAGIC:
2227
      arch = bfd_arch_aarch64;
2228
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2229
      break;
2230
#endif
2231
#ifdef LOONGARCH64MAGIC
2232
    case LOONGARCH64MAGIC:
2233
      arch = bfd_arch_loongarch;
2234
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2235
      break;
2236
#endif
2237
#ifdef Z80MAGIC
2238
    case Z80MAGIC:
2239
      arch = bfd_arch_z80;
2240
      switch (internal_f->f_flags & F_MACHMASK)
2241
  {
2242
  case bfd_mach_z80strict << 12:
2243
  case bfd_mach_z80 << 12:
2244
  case bfd_mach_z80n << 12:
2245
  case bfd_mach_z80full << 12:
2246
  case bfd_mach_r800 << 12:
2247
  case bfd_mach_gbz80 << 12:
2248
  case bfd_mach_z180 << 12:
2249
  case bfd_mach_ez80_z80 << 12:
2250
  case bfd_mach_ez80_adl << 12:
2251
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2252
    break;
2253
  default:
2254
    return false;
2255
  }
2256
      break;
2257
#endif
2258
#ifdef Z8KMAGIC
2259
    case Z8KMAGIC:
2260
      arch = bfd_arch_z8k;
2261
      switch (internal_f->f_flags & F_MACHMASK)
2262
  {
2263
  case F_Z8001:
2264
    machine = bfd_mach_z8001;
2265
    break;
2266
  case F_Z8002:
2267
    machine = bfd_mach_z8002;
2268
    break;
2269
  default:
2270
    return false;
2271
  }
2272
      break;
2273
#endif
2274
2275
#ifdef RS6000COFF_C
2276
#ifdef XCOFF64
2277
    case U64_TOCMAGIC:
2278
    case U803XTOCMAGIC:
2279
#else
2280
    case U802ROMAGIC:
2281
    case U802WRMAGIC:
2282
    case U802TOCMAGIC:
2283
#endif
2284
      {
2285
  int cputype;
2286
2287
  if (xcoff_data (abfd)->cputype != -1)
2288
    cputype = xcoff_data (abfd)->cputype & 0xff;
2289
  else
2290
    {
2291
      /* We did not get a value from the a.out header.  If the
2292
         file has not been stripped, we may be able to get the
2293
         architecture information from the first symbol, if it
2294
         is a .file symbol.  */
2295
      if (obj_raw_syment_count (abfd) == 0)
2296
        cputype = 0;
2297
      else
2298
        {
2299
    bfd_byte *buf;
2300
    struct internal_syment sym;
2301
    bfd_size_type amt = bfd_coff_symesz (abfd);
2302
2303
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2304
      return false;
2305
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2306
    if (buf == NULL)
2307
      return false;
2308
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2309
    if (sym.n_sclass == C_FILE)
2310
      cputype = sym.n_type & 0xff;
2311
    else
2312
      cputype = 0;
2313
    free (buf);
2314
        }
2315
    }
2316
2317
  /* FIXME: We don't handle all cases here.  */
2318
  switch (cputype)
2319
    {
2320
    default:
2321
    case 0:
2322
      arch = bfd_xcoff_architecture (abfd);
2323
      machine = bfd_xcoff_machine (abfd);
2324
      break;
2325
2326
    case 1:
2327
      arch = bfd_arch_powerpc;
2328
      machine = bfd_mach_ppc_601;
2329
      break;
2330
    case 2: /* 64 bit PowerPC */
2331
      arch = bfd_arch_powerpc;
2332
      machine = bfd_mach_ppc_620;
2333
      break;
2334
    case 3:
2335
      arch = bfd_arch_powerpc;
2336
      machine = bfd_mach_ppc;
2337
      break;
2338
    case 4:
2339
      arch = bfd_arch_rs6000;
2340
      machine = bfd_mach_rs6k;
2341
      break;
2342
    }
2343
      }
2344
      break;
2345
#endif
2346
2347
#ifdef SH_ARCH_MAGIC_BIG
2348
    case SH_ARCH_MAGIC_BIG:
2349
    case SH_ARCH_MAGIC_LITTLE:
2350
#ifdef COFF_WITH_PE
2351
    case SH_ARCH_MAGIC_WINCE:
2352
#endif
2353
      arch = bfd_arch_sh;
2354
      break;
2355
#endif
2356
2357
#ifdef MIPS_ARCH_MAGIC_WINCE
2358
    case MIPS_ARCH_MAGIC_WINCE:
2359
      arch = bfd_arch_mips;
2360
      break;
2361
#endif
2362
2363
#ifdef SPARCMAGIC
2364
    case SPARCMAGIC:
2365
#ifdef LYNXCOFFMAGIC
2366
    case LYNXCOFFMAGIC:
2367
#endif
2368
      arch = bfd_arch_sparc;
2369
      break;
2370
#endif
2371
2372
#ifdef TIC30MAGIC
2373
    case TIC30MAGIC:
2374
      arch = bfd_arch_tic30;
2375
      break;
2376
#endif
2377
2378
#ifdef TICOFF0MAGIC
2379
#ifdef TICOFF_TARGET_ARCH
2380
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2381
    case TICOFF0MAGIC:
2382
      arch = TICOFF_TARGET_ARCH;
2383
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2384
      break;
2385
#endif
2386
#endif
2387
2388
#ifdef TICOFF1MAGIC
2389
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2390
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2391
    case TICOFF1MAGIC:
2392
    case TICOFF2MAGIC:
2393
      switch (internal_f->f_target_id)
2394
  {
2395
#ifdef TI_TARGET_ID
2396
  case TI_TARGET_ID:
2397
    arch = TICOFF_TARGET_ARCH;
2398
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2399
    break;
2400
#endif
2401
  default:
2402
    arch = bfd_arch_obscure;
2403
    _bfd_error_handler
2404
      (_("unrecognized TI COFF target id '0x%x'"),
2405
       internal_f->f_target_id);
2406
    break;
2407
  }
2408
      break;
2409
#endif
2410
2411
#ifdef MCOREMAGIC
2412
    case MCOREMAGIC:
2413
      arch = bfd_arch_mcore;
2414
      break;
2415
#endif
2416
2417
4
    default:      /* Unreadable input file type.  */
2418
0
      arch = bfd_arch_obscure;
2419
0
      break;
2420
4
    }
2421
2422
4
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
4
  return true;
2424
4
}
pe-i386.c:coff_set_arch_mach_hook
Line
Count
Source
2162
150
{
2163
150
  unsigned long machine;
2164
150
  enum bfd_architecture arch;
2165
150
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
150
  machine = 0;
2169
150
  switch (internal_f->f_magic)
2170
150
    {
2171
0
#ifdef I386MAGIC
2172
2
    case I386MAGIC:
2173
17
    case I386PTXMAGIC:
2174
17
    case I386AIXMAGIC:   /* Danbury PS/2 AIX C Compiler.  */
2175
90
    case LYNXCOFFMAGIC:
2176
90
    case I386_APPLE_MAGIC:
2177
90
    case I386_FREEBSD_MAGIC:
2178
90
    case I386_LINUX_MAGIC:
2179
150
    case I386_NETBSD_MAGIC:
2180
150
      arch = bfd_arch_i386;
2181
150
      break;
2182
0
#endif
2183
#ifdef AMD64MAGIC
2184
    case AMD64MAGIC:
2185
    case AMD64_APPLE_MAGIC:
2186
    case AMD64_FREEBSD_MAGIC:
2187
    case AMD64_LINUX_MAGIC:
2188
    case AMD64_NETBSD_MAGIC:
2189
      arch = bfd_arch_i386;
2190
      machine = bfd_mach_x86_64;
2191
      break;
2192
#endif
2193
#ifdef IA64MAGIC
2194
    case IA64MAGIC:
2195
      arch = bfd_arch_ia64;
2196
      break;
2197
#endif
2198
#ifdef ARMMAGIC
2199
    case ARMMAGIC:
2200
    case ARMPEMAGIC:
2201
    case THUMBPEMAGIC:
2202
      arch = bfd_arch_arm;
2203
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2204
      if (machine == bfd_mach_arm_unknown)
2205
  {
2206
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2207
      {
2208
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2209
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2210
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2211
      default:
2212
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2213
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2214
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2215
        /* The COFF header does not have enough bits available
2216
     to cover all the different ARM architectures.  So
2217
     we interpret F_ARM_5, the highest flag value to mean
2218
     "the highest ARM architecture known to BFD" which is
2219
     currently the XScale.  */
2220
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2221
      }
2222
  }
2223
      break;
2224
#endif
2225
#ifdef AARCH64MAGIC
2226
    case AARCH64MAGIC:
2227
      arch = bfd_arch_aarch64;
2228
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2229
      break;
2230
#endif
2231
#ifdef LOONGARCH64MAGIC
2232
    case LOONGARCH64MAGIC:
2233
      arch = bfd_arch_loongarch;
2234
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2235
      break;
2236
#endif
2237
#ifdef Z80MAGIC
2238
    case Z80MAGIC:
2239
      arch = bfd_arch_z80;
2240
      switch (internal_f->f_flags & F_MACHMASK)
2241
  {
2242
  case bfd_mach_z80strict << 12:
2243
  case bfd_mach_z80 << 12:
2244
  case bfd_mach_z80n << 12:
2245
  case bfd_mach_z80full << 12:
2246
  case bfd_mach_r800 << 12:
2247
  case bfd_mach_gbz80 << 12:
2248
  case bfd_mach_z180 << 12:
2249
  case bfd_mach_ez80_z80 << 12:
2250
  case bfd_mach_ez80_adl << 12:
2251
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2252
    break;
2253
  default:
2254
    return false;
2255
  }
2256
      break;
2257
#endif
2258
#ifdef Z8KMAGIC
2259
    case Z8KMAGIC:
2260
      arch = bfd_arch_z8k;
2261
      switch (internal_f->f_flags & F_MACHMASK)
2262
  {
2263
  case F_Z8001:
2264
    machine = bfd_mach_z8001;
2265
    break;
2266
  case F_Z8002:
2267
    machine = bfd_mach_z8002;
2268
    break;
2269
  default:
2270
    return false;
2271
  }
2272
      break;
2273
#endif
2274
2275
#ifdef RS6000COFF_C
2276
#ifdef XCOFF64
2277
    case U64_TOCMAGIC:
2278
    case U803XTOCMAGIC:
2279
#else
2280
    case U802ROMAGIC:
2281
    case U802WRMAGIC:
2282
    case U802TOCMAGIC:
2283
#endif
2284
      {
2285
  int cputype;
2286
2287
  if (xcoff_data (abfd)->cputype != -1)
2288
    cputype = xcoff_data (abfd)->cputype & 0xff;
2289
  else
2290
    {
2291
      /* We did not get a value from the a.out header.  If the
2292
         file has not been stripped, we may be able to get the
2293
         architecture information from the first symbol, if it
2294
         is a .file symbol.  */
2295
      if (obj_raw_syment_count (abfd) == 0)
2296
        cputype = 0;
2297
      else
2298
        {
2299
    bfd_byte *buf;
2300
    struct internal_syment sym;
2301
    bfd_size_type amt = bfd_coff_symesz (abfd);
2302
2303
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2304
      return false;
2305
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2306
    if (buf == NULL)
2307
      return false;
2308
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2309
    if (sym.n_sclass == C_FILE)
2310
      cputype = sym.n_type & 0xff;
2311
    else
2312
      cputype = 0;
2313
    free (buf);
2314
        }
2315
    }
2316
2317
  /* FIXME: We don't handle all cases here.  */
2318
  switch (cputype)
2319
    {
2320
    default:
2321
    case 0:
2322
      arch = bfd_xcoff_architecture (abfd);
2323
      machine = bfd_xcoff_machine (abfd);
2324
      break;
2325
2326
    case 1:
2327
      arch = bfd_arch_powerpc;
2328
      machine = bfd_mach_ppc_601;
2329
      break;
2330
    case 2: /* 64 bit PowerPC */
2331
      arch = bfd_arch_powerpc;
2332
      machine = bfd_mach_ppc_620;
2333
      break;
2334
    case 3:
2335
      arch = bfd_arch_powerpc;
2336
      machine = bfd_mach_ppc;
2337
      break;
2338
    case 4:
2339
      arch = bfd_arch_rs6000;
2340
      machine = bfd_mach_rs6k;
2341
      break;
2342
    }
2343
      }
2344
      break;
2345
#endif
2346
2347
#ifdef SH_ARCH_MAGIC_BIG
2348
    case SH_ARCH_MAGIC_BIG:
2349
    case SH_ARCH_MAGIC_LITTLE:
2350
#ifdef COFF_WITH_PE
2351
    case SH_ARCH_MAGIC_WINCE:
2352
#endif
2353
      arch = bfd_arch_sh;
2354
      break;
2355
#endif
2356
2357
#ifdef MIPS_ARCH_MAGIC_WINCE
2358
    case MIPS_ARCH_MAGIC_WINCE:
2359
      arch = bfd_arch_mips;
2360
      break;
2361
#endif
2362
2363
#ifdef SPARCMAGIC
2364
    case SPARCMAGIC:
2365
#ifdef LYNXCOFFMAGIC
2366
    case LYNXCOFFMAGIC:
2367
#endif
2368
      arch = bfd_arch_sparc;
2369
      break;
2370
#endif
2371
2372
#ifdef TIC30MAGIC
2373
    case TIC30MAGIC:
2374
      arch = bfd_arch_tic30;
2375
      break;
2376
#endif
2377
2378
#ifdef TICOFF0MAGIC
2379
#ifdef TICOFF_TARGET_ARCH
2380
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2381
    case TICOFF0MAGIC:
2382
      arch = TICOFF_TARGET_ARCH;
2383
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2384
      break;
2385
#endif
2386
#endif
2387
2388
#ifdef TICOFF1MAGIC
2389
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2390
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2391
    case TICOFF1MAGIC:
2392
    case TICOFF2MAGIC:
2393
      switch (internal_f->f_target_id)
2394
  {
2395
#ifdef TI_TARGET_ID
2396
  case TI_TARGET_ID:
2397
    arch = TICOFF_TARGET_ARCH;
2398
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2399
    break;
2400
#endif
2401
  default:
2402
    arch = bfd_arch_obscure;
2403
    _bfd_error_handler
2404
      (_("unrecognized TI COFF target id '0x%x'"),
2405
       internal_f->f_target_id);
2406
    break;
2407
  }
2408
      break;
2409
#endif
2410
2411
#ifdef MCOREMAGIC
2412
    case MCOREMAGIC:
2413
      arch = bfd_arch_mcore;
2414
      break;
2415
#endif
2416
2417
0
    default:      /* Unreadable input file type.  */
2418
0
      arch = bfd_arch_obscure;
2419
0
      break;
2420
150
    }
2421
2422
150
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
150
  return true;
2424
150
}
pe-mcore.c:coff_set_arch_mach_hook
Line
Count
Source
2162
38
{
2163
38
  unsigned long machine;
2164
38
  enum bfd_architecture arch;
2165
38
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
38
  machine = 0;
2169
38
  switch (internal_f->f_magic)
2170
38
    {
2171
#ifdef I386MAGIC
2172
    case I386MAGIC:
2173
    case I386PTXMAGIC:
2174
    case I386AIXMAGIC:    /* Danbury PS/2 AIX C Compiler.  */
2175
    case LYNXCOFFMAGIC:
2176
    case I386_APPLE_MAGIC:
2177
    case I386_FREEBSD_MAGIC:
2178
    case I386_LINUX_MAGIC:
2179
    case I386_NETBSD_MAGIC:
2180
      arch = bfd_arch_i386;
2181
      break;
2182
#endif
2183
#ifdef AMD64MAGIC
2184
    case AMD64MAGIC:
2185
    case AMD64_APPLE_MAGIC:
2186
    case AMD64_FREEBSD_MAGIC:
2187
    case AMD64_LINUX_MAGIC:
2188
    case AMD64_NETBSD_MAGIC:
2189
      arch = bfd_arch_i386;
2190
      machine = bfd_mach_x86_64;
2191
      break;
2192
#endif
2193
#ifdef IA64MAGIC
2194
    case IA64MAGIC:
2195
      arch = bfd_arch_ia64;
2196
      break;
2197
#endif
2198
#ifdef ARMMAGIC
2199
    case ARMMAGIC:
2200
    case ARMPEMAGIC:
2201
    case THUMBPEMAGIC:
2202
      arch = bfd_arch_arm;
2203
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2204
      if (machine == bfd_mach_arm_unknown)
2205
  {
2206
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2207
      {
2208
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2209
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2210
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2211
      default:
2212
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2213
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2214
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2215
        /* The COFF header does not have enough bits available
2216
     to cover all the different ARM architectures.  So
2217
     we interpret F_ARM_5, the highest flag value to mean
2218
     "the highest ARM architecture known to BFD" which is
2219
     currently the XScale.  */
2220
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2221
      }
2222
  }
2223
      break;
2224
#endif
2225
#ifdef AARCH64MAGIC
2226
    case AARCH64MAGIC:
2227
      arch = bfd_arch_aarch64;
2228
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2229
      break;
2230
#endif
2231
#ifdef LOONGARCH64MAGIC
2232
    case LOONGARCH64MAGIC:
2233
      arch = bfd_arch_loongarch;
2234
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2235
      break;
2236
#endif
2237
#ifdef Z80MAGIC
2238
    case Z80MAGIC:
2239
      arch = bfd_arch_z80;
2240
      switch (internal_f->f_flags & F_MACHMASK)
2241
  {
2242
  case bfd_mach_z80strict << 12:
2243
  case bfd_mach_z80 << 12:
2244
  case bfd_mach_z80n << 12:
2245
  case bfd_mach_z80full << 12:
2246
  case bfd_mach_r800 << 12:
2247
  case bfd_mach_gbz80 << 12:
2248
  case bfd_mach_z180 << 12:
2249
  case bfd_mach_ez80_z80 << 12:
2250
  case bfd_mach_ez80_adl << 12:
2251
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2252
    break;
2253
  default:
2254
    return false;
2255
  }
2256
      break;
2257
#endif
2258
#ifdef Z8KMAGIC
2259
    case Z8KMAGIC:
2260
      arch = bfd_arch_z8k;
2261
      switch (internal_f->f_flags & F_MACHMASK)
2262
  {
2263
  case F_Z8001:
2264
    machine = bfd_mach_z8001;
2265
    break;
2266
  case F_Z8002:
2267
    machine = bfd_mach_z8002;
2268
    break;
2269
  default:
2270
    return false;
2271
  }
2272
      break;
2273
#endif
2274
2275
#ifdef RS6000COFF_C
2276
#ifdef XCOFF64
2277
    case U64_TOCMAGIC:
2278
    case U803XTOCMAGIC:
2279
#else
2280
    case U802ROMAGIC:
2281
    case U802WRMAGIC:
2282
    case U802TOCMAGIC:
2283
#endif
2284
      {
2285
  int cputype;
2286
2287
  if (xcoff_data (abfd)->cputype != -1)
2288
    cputype = xcoff_data (abfd)->cputype & 0xff;
2289
  else
2290
    {
2291
      /* We did not get a value from the a.out header.  If the
2292
         file has not been stripped, we may be able to get the
2293
         architecture information from the first symbol, if it
2294
         is a .file symbol.  */
2295
      if (obj_raw_syment_count (abfd) == 0)
2296
        cputype = 0;
2297
      else
2298
        {
2299
    bfd_byte *buf;
2300
    struct internal_syment sym;
2301
    bfd_size_type amt = bfd_coff_symesz (abfd);
2302
2303
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2304
      return false;
2305
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2306
    if (buf == NULL)
2307
      return false;
2308
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2309
    if (sym.n_sclass == C_FILE)
2310
      cputype = sym.n_type & 0xff;
2311
    else
2312
      cputype = 0;
2313
    free (buf);
2314
        }
2315
    }
2316
2317
  /* FIXME: We don't handle all cases here.  */
2318
  switch (cputype)
2319
    {
2320
    default:
2321
    case 0:
2322
      arch = bfd_xcoff_architecture (abfd);
2323
      machine = bfd_xcoff_machine (abfd);
2324
      break;
2325
2326
    case 1:
2327
      arch = bfd_arch_powerpc;
2328
      machine = bfd_mach_ppc_601;
2329
      break;
2330
    case 2: /* 64 bit PowerPC */
2331
      arch = bfd_arch_powerpc;
2332
      machine = bfd_mach_ppc_620;
2333
      break;
2334
    case 3:
2335
      arch = bfd_arch_powerpc;
2336
      machine = bfd_mach_ppc;
2337
      break;
2338
    case 4:
2339
      arch = bfd_arch_rs6000;
2340
      machine = bfd_mach_rs6k;
2341
      break;
2342
    }
2343
      }
2344
      break;
2345
#endif
2346
2347
#ifdef SH_ARCH_MAGIC_BIG
2348
    case SH_ARCH_MAGIC_BIG:
2349
    case SH_ARCH_MAGIC_LITTLE:
2350
#ifdef COFF_WITH_PE
2351
    case SH_ARCH_MAGIC_WINCE:
2352
#endif
2353
      arch = bfd_arch_sh;
2354
      break;
2355
#endif
2356
2357
#ifdef MIPS_ARCH_MAGIC_WINCE
2358
    case MIPS_ARCH_MAGIC_WINCE:
2359
      arch = bfd_arch_mips;
2360
      break;
2361
#endif
2362
2363
#ifdef SPARCMAGIC
2364
    case SPARCMAGIC:
2365
#ifdef LYNXCOFFMAGIC
2366
    case LYNXCOFFMAGIC:
2367
#endif
2368
      arch = bfd_arch_sparc;
2369
      break;
2370
#endif
2371
2372
#ifdef TIC30MAGIC
2373
    case TIC30MAGIC:
2374
      arch = bfd_arch_tic30;
2375
      break;
2376
#endif
2377
2378
#ifdef TICOFF0MAGIC
2379
#ifdef TICOFF_TARGET_ARCH
2380
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2381
    case TICOFF0MAGIC:
2382
      arch = TICOFF_TARGET_ARCH;
2383
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2384
      break;
2385
#endif
2386
#endif
2387
2388
#ifdef TICOFF1MAGIC
2389
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2390
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2391
    case TICOFF1MAGIC:
2392
    case TICOFF2MAGIC:
2393
      switch (internal_f->f_target_id)
2394
  {
2395
#ifdef TI_TARGET_ID
2396
  case TI_TARGET_ID:
2397
    arch = TICOFF_TARGET_ARCH;
2398
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2399
    break;
2400
#endif
2401
  default:
2402
    arch = bfd_arch_obscure;
2403
    _bfd_error_handler
2404
      (_("unrecognized TI COFF target id '0x%x'"),
2405
       internal_f->f_target_id);
2406
    break;
2407
  }
2408
      break;
2409
#endif
2410
2411
0
#ifdef MCOREMAGIC
2412
38
    case MCOREMAGIC:
2413
38
      arch = bfd_arch_mcore;
2414
38
      break;
2415
0
#endif
2416
2417
0
    default:      /* Unreadable input file type.  */
2418
0
      arch = bfd_arch_obscure;
2419
0
      break;
2420
38
    }
2421
2422
38
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
38
  return true;
2424
38
}
pe-sh.c:coff_set_arch_mach_hook
Line
Count
Source
2162
1.29k
{
2163
1.29k
  unsigned long machine;
2164
1.29k
  enum bfd_architecture arch;
2165
1.29k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
1.29k
  machine = 0;
2169
1.29k
  switch (internal_f->f_magic)
2170
1.29k
    {
2171
#ifdef I386MAGIC
2172
    case I386MAGIC:
2173
    case I386PTXMAGIC:
2174
    case I386AIXMAGIC:    /* Danbury PS/2 AIX C Compiler.  */
2175
    case LYNXCOFFMAGIC:
2176
    case I386_APPLE_MAGIC:
2177
    case I386_FREEBSD_MAGIC:
2178
    case I386_LINUX_MAGIC:
2179
    case I386_NETBSD_MAGIC:
2180
      arch = bfd_arch_i386;
2181
      break;
2182
#endif
2183
#ifdef AMD64MAGIC
2184
    case AMD64MAGIC:
2185
    case AMD64_APPLE_MAGIC:
2186
    case AMD64_FREEBSD_MAGIC:
2187
    case AMD64_LINUX_MAGIC:
2188
    case AMD64_NETBSD_MAGIC:
2189
      arch = bfd_arch_i386;
2190
      machine = bfd_mach_x86_64;
2191
      break;
2192
#endif
2193
#ifdef IA64MAGIC
2194
    case IA64MAGIC:
2195
      arch = bfd_arch_ia64;
2196
      break;
2197
#endif
2198
#ifdef ARMMAGIC
2199
    case ARMMAGIC:
2200
    case ARMPEMAGIC:
2201
    case THUMBPEMAGIC:
2202
      arch = bfd_arch_arm;
2203
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2204
      if (machine == bfd_mach_arm_unknown)
2205
  {
2206
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2207
      {
2208
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2209
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2210
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2211
      default:
2212
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2213
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2214
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2215
        /* The COFF header does not have enough bits available
2216
     to cover all the different ARM architectures.  So
2217
     we interpret F_ARM_5, the highest flag value to mean
2218
     "the highest ARM architecture known to BFD" which is
2219
     currently the XScale.  */
2220
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2221
      }
2222
  }
2223
      break;
2224
#endif
2225
#ifdef AARCH64MAGIC
2226
    case AARCH64MAGIC:
2227
      arch = bfd_arch_aarch64;
2228
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2229
      break;
2230
#endif
2231
#ifdef LOONGARCH64MAGIC
2232
    case LOONGARCH64MAGIC:
2233
      arch = bfd_arch_loongarch;
2234
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2235
      break;
2236
#endif
2237
#ifdef Z80MAGIC
2238
    case Z80MAGIC:
2239
      arch = bfd_arch_z80;
2240
      switch (internal_f->f_flags & F_MACHMASK)
2241
  {
2242
  case bfd_mach_z80strict << 12:
2243
  case bfd_mach_z80 << 12:
2244
  case bfd_mach_z80n << 12:
2245
  case bfd_mach_z80full << 12:
2246
  case bfd_mach_r800 << 12:
2247
  case bfd_mach_gbz80 << 12:
2248
  case bfd_mach_z180 << 12:
2249
  case bfd_mach_ez80_z80 << 12:
2250
  case bfd_mach_ez80_adl << 12:
2251
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2252
    break;
2253
  default:
2254
    return false;
2255
  }
2256
      break;
2257
#endif
2258
#ifdef Z8KMAGIC
2259
    case Z8KMAGIC:
2260
      arch = bfd_arch_z8k;
2261
      switch (internal_f->f_flags & F_MACHMASK)
2262
  {
2263
  case F_Z8001:
2264
    machine = bfd_mach_z8001;
2265
    break;
2266
  case F_Z8002:
2267
    machine = bfd_mach_z8002;
2268
    break;
2269
  default:
2270
    return false;
2271
  }
2272
      break;
2273
#endif
2274
2275
#ifdef RS6000COFF_C
2276
#ifdef XCOFF64
2277
    case U64_TOCMAGIC:
2278
    case U803XTOCMAGIC:
2279
#else
2280
    case U802ROMAGIC:
2281
    case U802WRMAGIC:
2282
    case U802TOCMAGIC:
2283
#endif
2284
      {
2285
  int cputype;
2286
2287
  if (xcoff_data (abfd)->cputype != -1)
2288
    cputype = xcoff_data (abfd)->cputype & 0xff;
2289
  else
2290
    {
2291
      /* We did not get a value from the a.out header.  If the
2292
         file has not been stripped, we may be able to get the
2293
         architecture information from the first symbol, if it
2294
         is a .file symbol.  */
2295
      if (obj_raw_syment_count (abfd) == 0)
2296
        cputype = 0;
2297
      else
2298
        {
2299
    bfd_byte *buf;
2300
    struct internal_syment sym;
2301
    bfd_size_type amt = bfd_coff_symesz (abfd);
2302
2303
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2304
      return false;
2305
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2306
    if (buf == NULL)
2307
      return false;
2308
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2309
    if (sym.n_sclass == C_FILE)
2310
      cputype = sym.n_type & 0xff;
2311
    else
2312
      cputype = 0;
2313
    free (buf);
2314
        }
2315
    }
2316
2317
  /* FIXME: We don't handle all cases here.  */
2318
  switch (cputype)
2319
    {
2320
    default:
2321
    case 0:
2322
      arch = bfd_xcoff_architecture (abfd);
2323
      machine = bfd_xcoff_machine (abfd);
2324
      break;
2325
2326
    case 1:
2327
      arch = bfd_arch_powerpc;
2328
      machine = bfd_mach_ppc_601;
2329
      break;
2330
    case 2: /* 64 bit PowerPC */
2331
      arch = bfd_arch_powerpc;
2332
      machine = bfd_mach_ppc_620;
2333
      break;
2334
    case 3:
2335
      arch = bfd_arch_powerpc;
2336
      machine = bfd_mach_ppc;
2337
      break;
2338
    case 4:
2339
      arch = bfd_arch_rs6000;
2340
      machine = bfd_mach_rs6k;
2341
      break;
2342
    }
2343
      }
2344
      break;
2345
#endif
2346
2347
0
#ifdef SH_ARCH_MAGIC_BIG
2348
1.29k
    case SH_ARCH_MAGIC_BIG:
2349
1.29k
    case SH_ARCH_MAGIC_LITTLE:
2350
1.29k
#ifdef COFF_WITH_PE
2351
1.29k
    case SH_ARCH_MAGIC_WINCE:
2352
1.29k
#endif
2353
1.29k
      arch = bfd_arch_sh;
2354
1.29k
      break;
2355
0
#endif
2356
2357
#ifdef MIPS_ARCH_MAGIC_WINCE
2358
    case MIPS_ARCH_MAGIC_WINCE:
2359
      arch = bfd_arch_mips;
2360
      break;
2361
#endif
2362
2363
#ifdef SPARCMAGIC
2364
    case SPARCMAGIC:
2365
#ifdef LYNXCOFFMAGIC
2366
    case LYNXCOFFMAGIC:
2367
#endif
2368
      arch = bfd_arch_sparc;
2369
      break;
2370
#endif
2371
2372
#ifdef TIC30MAGIC
2373
    case TIC30MAGIC:
2374
      arch = bfd_arch_tic30;
2375
      break;
2376
#endif
2377
2378
#ifdef TICOFF0MAGIC
2379
#ifdef TICOFF_TARGET_ARCH
2380
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2381
    case TICOFF0MAGIC:
2382
      arch = TICOFF_TARGET_ARCH;
2383
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2384
      break;
2385
#endif
2386
#endif
2387
2388
#ifdef TICOFF1MAGIC
2389
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2390
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2391
    case TICOFF1MAGIC:
2392
    case TICOFF2MAGIC:
2393
      switch (internal_f->f_target_id)
2394
  {
2395
#ifdef TI_TARGET_ID
2396
  case TI_TARGET_ID:
2397
    arch = TICOFF_TARGET_ARCH;
2398
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2399
    break;
2400
#endif
2401
  default:
2402
    arch = bfd_arch_obscure;
2403
    _bfd_error_handler
2404
      (_("unrecognized TI COFF target id '0x%x'"),
2405
       internal_f->f_target_id);
2406
    break;
2407
  }
2408
      break;
2409
#endif
2410
2411
#ifdef MCOREMAGIC
2412
    case MCOREMAGIC:
2413
      arch = bfd_arch_mcore;
2414
      break;
2415
#endif
2416
2417
0
    default:      /* Unreadable input file type.  */
2418
0
      arch = bfd_arch_obscure;
2419
0
      break;
2420
1.29k
    }
2421
2422
1.29k
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
1.29k
  return true;
2424
1.29k
}
pei-arm-wince.c:coff_set_arch_mach_hook
Line
Count
Source
2162
7
{
2163
7
  unsigned long machine;
2164
7
  enum bfd_architecture arch;
2165
7
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
7
  machine = 0;
2169
7
  switch (internal_f->f_magic)
2170
7
    {
2171
#ifdef I386MAGIC
2172
    case I386MAGIC:
2173
    case I386PTXMAGIC:
2174
    case I386AIXMAGIC:    /* Danbury PS/2 AIX C Compiler.  */
2175
    case LYNXCOFFMAGIC:
2176
    case I386_APPLE_MAGIC:
2177
    case I386_FREEBSD_MAGIC:
2178
    case I386_LINUX_MAGIC:
2179
    case I386_NETBSD_MAGIC:
2180
      arch = bfd_arch_i386;
2181
      break;
2182
#endif
2183
#ifdef AMD64MAGIC
2184
    case AMD64MAGIC:
2185
    case AMD64_APPLE_MAGIC:
2186
    case AMD64_FREEBSD_MAGIC:
2187
    case AMD64_LINUX_MAGIC:
2188
    case AMD64_NETBSD_MAGIC:
2189
      arch = bfd_arch_i386;
2190
      machine = bfd_mach_x86_64;
2191
      break;
2192
#endif
2193
#ifdef IA64MAGIC
2194
    case IA64MAGIC:
2195
      arch = bfd_arch_ia64;
2196
      break;
2197
#endif
2198
0
#ifdef ARMMAGIC
2199
6
    case ARMMAGIC:
2200
6
    case ARMPEMAGIC:
2201
6
    case THUMBPEMAGIC:
2202
6
      arch = bfd_arch_arm;
2203
6
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2204
6
      if (machine == bfd_mach_arm_unknown)
2205
6
  {
2206
6
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2207
6
      {
2208
2
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2209
0
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2210
0
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2211
0
      default:
2212
0
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2213
0
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2214
0
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2215
        /* The COFF header does not have enough bits available
2216
     to cover all the different ARM architectures.  So
2217
     we interpret F_ARM_5, the highest flag value to mean
2218
     "the highest ARM architecture known to BFD" which is
2219
     currently the XScale.  */
2220
4
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2221
6
      }
2222
6
  }
2223
6
      break;
2224
6
#endif
2225
#ifdef AARCH64MAGIC
2226
    case AARCH64MAGIC:
2227
      arch = bfd_arch_aarch64;
2228
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2229
      break;
2230
#endif
2231
#ifdef LOONGARCH64MAGIC
2232
    case LOONGARCH64MAGIC:
2233
      arch = bfd_arch_loongarch;
2234
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2235
      break;
2236
#endif
2237
#ifdef Z80MAGIC
2238
    case Z80MAGIC:
2239
      arch = bfd_arch_z80;
2240
      switch (internal_f->f_flags & F_MACHMASK)
2241
  {
2242
  case bfd_mach_z80strict << 12:
2243
  case bfd_mach_z80 << 12:
2244
  case bfd_mach_z80n << 12:
2245
  case bfd_mach_z80full << 12:
2246
  case bfd_mach_r800 << 12:
2247
  case bfd_mach_gbz80 << 12:
2248
  case bfd_mach_z180 << 12:
2249
  case bfd_mach_ez80_z80 << 12:
2250
  case bfd_mach_ez80_adl << 12:
2251
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2252
    break;
2253
  default:
2254
    return false;
2255
  }
2256
      break;
2257
#endif
2258
#ifdef Z8KMAGIC
2259
    case Z8KMAGIC:
2260
      arch = bfd_arch_z8k;
2261
      switch (internal_f->f_flags & F_MACHMASK)
2262
  {
2263
  case F_Z8001:
2264
    machine = bfd_mach_z8001;
2265
    break;
2266
  case F_Z8002:
2267
    machine = bfd_mach_z8002;
2268
    break;
2269
  default:
2270
    return false;
2271
  }
2272
      break;
2273
#endif
2274
2275
#ifdef RS6000COFF_C
2276
#ifdef XCOFF64
2277
    case U64_TOCMAGIC:
2278
    case U803XTOCMAGIC:
2279
#else
2280
    case U802ROMAGIC:
2281
    case U802WRMAGIC:
2282
    case U802TOCMAGIC:
2283
#endif
2284
      {
2285
  int cputype;
2286
2287
  if (xcoff_data (abfd)->cputype != -1)
2288
    cputype = xcoff_data (abfd)->cputype & 0xff;
2289
  else
2290
    {
2291
      /* We did not get a value from the a.out header.  If the
2292
         file has not been stripped, we may be able to get the
2293
         architecture information from the first symbol, if it
2294
         is a .file symbol.  */
2295
      if (obj_raw_syment_count (abfd) == 0)
2296
        cputype = 0;
2297
      else
2298
        {
2299
    bfd_byte *buf;
2300
    struct internal_syment sym;
2301
    bfd_size_type amt = bfd_coff_symesz (abfd);
2302
2303
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2304
      return false;
2305
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2306
    if (buf == NULL)
2307
      return false;
2308
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2309
    if (sym.n_sclass == C_FILE)
2310
      cputype = sym.n_type & 0xff;
2311
    else
2312
      cputype = 0;
2313
    free (buf);
2314
        }
2315
    }
2316
2317
  /* FIXME: We don't handle all cases here.  */
2318
  switch (cputype)
2319
    {
2320
    default:
2321
    case 0:
2322
      arch = bfd_xcoff_architecture (abfd);
2323
      machine = bfd_xcoff_machine (abfd);
2324
      break;
2325
2326
    case 1:
2327
      arch = bfd_arch_powerpc;
2328
      machine = bfd_mach_ppc_601;
2329
      break;
2330
    case 2: /* 64 bit PowerPC */
2331
      arch = bfd_arch_powerpc;
2332
      machine = bfd_mach_ppc_620;
2333
      break;
2334
    case 3:
2335
      arch = bfd_arch_powerpc;
2336
      machine = bfd_mach_ppc;
2337
      break;
2338
    case 4:
2339
      arch = bfd_arch_rs6000;
2340
      machine = bfd_mach_rs6k;
2341
      break;
2342
    }
2343
      }
2344
      break;
2345
#endif
2346
2347
#ifdef SH_ARCH_MAGIC_BIG
2348
    case SH_ARCH_MAGIC_BIG:
2349
    case SH_ARCH_MAGIC_LITTLE:
2350
#ifdef COFF_WITH_PE
2351
    case SH_ARCH_MAGIC_WINCE:
2352
#endif
2353
      arch = bfd_arch_sh;
2354
      break;
2355
#endif
2356
2357
#ifdef MIPS_ARCH_MAGIC_WINCE
2358
    case MIPS_ARCH_MAGIC_WINCE:
2359
      arch = bfd_arch_mips;
2360
      break;
2361
#endif
2362
2363
#ifdef SPARCMAGIC
2364
    case SPARCMAGIC:
2365
#ifdef LYNXCOFFMAGIC
2366
    case LYNXCOFFMAGIC:
2367
#endif
2368
      arch = bfd_arch_sparc;
2369
      break;
2370
#endif
2371
2372
#ifdef TIC30MAGIC
2373
    case TIC30MAGIC:
2374
      arch = bfd_arch_tic30;
2375
      break;
2376
#endif
2377
2378
#ifdef TICOFF0MAGIC
2379
#ifdef TICOFF_TARGET_ARCH
2380
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2381
    case TICOFF0MAGIC:
2382
      arch = TICOFF_TARGET_ARCH;
2383
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2384
      break;
2385
#endif
2386
#endif
2387
2388
#ifdef TICOFF1MAGIC
2389
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2390
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2391
    case TICOFF1MAGIC:
2392
    case TICOFF2MAGIC:
2393
      switch (internal_f->f_target_id)
2394
  {
2395
#ifdef TI_TARGET_ID
2396
  case TI_TARGET_ID:
2397
    arch = TICOFF_TARGET_ARCH;
2398
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2399
    break;
2400
#endif
2401
  default:
2402
    arch = bfd_arch_obscure;
2403
    _bfd_error_handler
2404
      (_("unrecognized TI COFF target id '0x%x'"),
2405
       internal_f->f_target_id);
2406
    break;
2407
  }
2408
      break;
2409
#endif
2410
2411
#ifdef MCOREMAGIC
2412
    case MCOREMAGIC:
2413
      arch = bfd_arch_mcore;
2414
      break;
2415
#endif
2416
2417
6
    default:      /* Unreadable input file type.  */
2418
1
      arch = bfd_arch_obscure;
2419
1
      break;
2420
7
    }
2421
2422
7
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
7
  return true;
2424
7
}
pei-arm.c:coff_set_arch_mach_hook
Line
Count
Source
2162
8
{
2163
8
  unsigned long machine;
2164
8
  enum bfd_architecture arch;
2165
8
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
8
  machine = 0;
2169
8
  switch (internal_f->f_magic)
2170
8
    {
2171
#ifdef I386MAGIC
2172
    case I386MAGIC:
2173
    case I386PTXMAGIC:
2174
    case I386AIXMAGIC:    /* Danbury PS/2 AIX C Compiler.  */
2175
    case LYNXCOFFMAGIC:
2176
    case I386_APPLE_MAGIC:
2177
    case I386_FREEBSD_MAGIC:
2178
    case I386_LINUX_MAGIC:
2179
    case I386_NETBSD_MAGIC:
2180
      arch = bfd_arch_i386;
2181
      break;
2182
#endif
2183
#ifdef AMD64MAGIC
2184
    case AMD64MAGIC:
2185
    case AMD64_APPLE_MAGIC:
2186
    case AMD64_FREEBSD_MAGIC:
2187
    case AMD64_LINUX_MAGIC:
2188
    case AMD64_NETBSD_MAGIC:
2189
      arch = bfd_arch_i386;
2190
      machine = bfd_mach_x86_64;
2191
      break;
2192
#endif
2193
#ifdef IA64MAGIC
2194
    case IA64MAGIC:
2195
      arch = bfd_arch_ia64;
2196
      break;
2197
#endif
2198
0
#ifdef ARMMAGIC
2199
7
    case ARMMAGIC:
2200
7
    case ARMPEMAGIC:
2201
7
    case THUMBPEMAGIC:
2202
7
      arch = bfd_arch_arm;
2203
7
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2204
7
      if (machine == bfd_mach_arm_unknown)
2205
7
  {
2206
7
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2207
7
      {
2208
1
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2209
0
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2210
0
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2211
1
      default:
2212
1
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2213
0
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2214
0
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2215
        /* The COFF header does not have enough bits available
2216
     to cover all the different ARM architectures.  So
2217
     we interpret F_ARM_5, the highest flag value to mean
2218
     "the highest ARM architecture known to BFD" which is
2219
     currently the XScale.  */
2220
5
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2221
7
      }
2222
7
  }
2223
7
      break;
2224
7
#endif
2225
#ifdef AARCH64MAGIC
2226
    case AARCH64MAGIC:
2227
      arch = bfd_arch_aarch64;
2228
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2229
      break;
2230
#endif
2231
#ifdef LOONGARCH64MAGIC
2232
    case LOONGARCH64MAGIC:
2233
      arch = bfd_arch_loongarch;
2234
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2235
      break;
2236
#endif
2237
#ifdef Z80MAGIC
2238
    case Z80MAGIC:
2239
      arch = bfd_arch_z80;
2240
      switch (internal_f->f_flags & F_MACHMASK)
2241
  {
2242
  case bfd_mach_z80strict << 12:
2243
  case bfd_mach_z80 << 12:
2244
  case bfd_mach_z80n << 12:
2245
  case bfd_mach_z80full << 12:
2246
  case bfd_mach_r800 << 12:
2247
  case bfd_mach_gbz80 << 12:
2248
  case bfd_mach_z180 << 12:
2249
  case bfd_mach_ez80_z80 << 12:
2250
  case bfd_mach_ez80_adl << 12:
2251
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2252
    break;
2253
  default:
2254
    return false;
2255
  }
2256
      break;
2257
#endif
2258
#ifdef Z8KMAGIC
2259
    case Z8KMAGIC:
2260
      arch = bfd_arch_z8k;
2261
      switch (internal_f->f_flags & F_MACHMASK)
2262
  {
2263
  case F_Z8001:
2264
    machine = bfd_mach_z8001;
2265
    break;
2266
  case F_Z8002:
2267
    machine = bfd_mach_z8002;
2268
    break;
2269
  default:
2270
    return false;
2271
  }
2272
      break;
2273
#endif
2274
2275
#ifdef RS6000COFF_C
2276
#ifdef XCOFF64
2277
    case U64_TOCMAGIC:
2278
    case U803XTOCMAGIC:
2279
#else
2280
    case U802ROMAGIC:
2281
    case U802WRMAGIC:
2282
    case U802TOCMAGIC:
2283
#endif
2284
      {
2285
  int cputype;
2286
2287
  if (xcoff_data (abfd)->cputype != -1)
2288
    cputype = xcoff_data (abfd)->cputype & 0xff;
2289
  else
2290
    {
2291
      /* We did not get a value from the a.out header.  If the
2292
         file has not been stripped, we may be able to get the
2293
         architecture information from the first symbol, if it
2294
         is a .file symbol.  */
2295
      if (obj_raw_syment_count (abfd) == 0)
2296
        cputype = 0;
2297
      else
2298
        {
2299
    bfd_byte *buf;
2300
    struct internal_syment sym;
2301
    bfd_size_type amt = bfd_coff_symesz (abfd);
2302
2303
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2304
      return false;
2305
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2306
    if (buf == NULL)
2307
      return false;
2308
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2309
    if (sym.n_sclass == C_FILE)
2310
      cputype = sym.n_type & 0xff;
2311
    else
2312
      cputype = 0;
2313
    free (buf);
2314
        }
2315
    }
2316
2317
  /* FIXME: We don't handle all cases here.  */
2318
  switch (cputype)
2319
    {
2320
    default:
2321
    case 0:
2322
      arch = bfd_xcoff_architecture (abfd);
2323
      machine = bfd_xcoff_machine (abfd);
2324
      break;
2325
2326
    case 1:
2327
      arch = bfd_arch_powerpc;
2328
      machine = bfd_mach_ppc_601;
2329
      break;
2330
    case 2: /* 64 bit PowerPC */
2331
      arch = bfd_arch_powerpc;
2332
      machine = bfd_mach_ppc_620;
2333
      break;
2334
    case 3:
2335
      arch = bfd_arch_powerpc;
2336
      machine = bfd_mach_ppc;
2337
      break;
2338
    case 4:
2339
      arch = bfd_arch_rs6000;
2340
      machine = bfd_mach_rs6k;
2341
      break;
2342
    }
2343
      }
2344
      break;
2345
#endif
2346
2347
#ifdef SH_ARCH_MAGIC_BIG
2348
    case SH_ARCH_MAGIC_BIG:
2349
    case SH_ARCH_MAGIC_LITTLE:
2350
#ifdef COFF_WITH_PE
2351
    case SH_ARCH_MAGIC_WINCE:
2352
#endif
2353
      arch = bfd_arch_sh;
2354
      break;
2355
#endif
2356
2357
#ifdef MIPS_ARCH_MAGIC_WINCE
2358
    case MIPS_ARCH_MAGIC_WINCE:
2359
      arch = bfd_arch_mips;
2360
      break;
2361
#endif
2362
2363
#ifdef SPARCMAGIC
2364
    case SPARCMAGIC:
2365
#ifdef LYNXCOFFMAGIC
2366
    case LYNXCOFFMAGIC:
2367
#endif
2368
      arch = bfd_arch_sparc;
2369
      break;
2370
#endif
2371
2372
#ifdef TIC30MAGIC
2373
    case TIC30MAGIC:
2374
      arch = bfd_arch_tic30;
2375
      break;
2376
#endif
2377
2378
#ifdef TICOFF0MAGIC
2379
#ifdef TICOFF_TARGET_ARCH
2380
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2381
    case TICOFF0MAGIC:
2382
      arch = TICOFF_TARGET_ARCH;
2383
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2384
      break;
2385
#endif
2386
#endif
2387
2388
#ifdef TICOFF1MAGIC
2389
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2390
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2391
    case TICOFF1MAGIC:
2392
    case TICOFF2MAGIC:
2393
      switch (internal_f->f_target_id)
2394
  {
2395
#ifdef TI_TARGET_ID
2396
  case TI_TARGET_ID:
2397
    arch = TICOFF_TARGET_ARCH;
2398
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2399
    break;
2400
#endif
2401
  default:
2402
    arch = bfd_arch_obscure;
2403
    _bfd_error_handler
2404
      (_("unrecognized TI COFF target id '0x%x'"),
2405
       internal_f->f_target_id);
2406
    break;
2407
  }
2408
      break;
2409
#endif
2410
2411
#ifdef MCOREMAGIC
2412
    case MCOREMAGIC:
2413
      arch = bfd_arch_mcore;
2414
      break;
2415
#endif
2416
2417
7
    default:      /* Unreadable input file type.  */
2418
1
      arch = bfd_arch_obscure;
2419
1
      break;
2420
8
    }
2421
2422
8
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
8
  return true;
2424
8
}
pei-mcore.c:coff_set_arch_mach_hook
Line
Count
Source
2162
5
{
2163
5
  unsigned long machine;
2164
5
  enum bfd_architecture arch;
2165
5
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
5
  machine = 0;
2169
5
  switch (internal_f->f_magic)
2170
5
    {
2171
#ifdef I386MAGIC
2172
    case I386MAGIC:
2173
    case I386PTXMAGIC:
2174
    case I386AIXMAGIC:    /* Danbury PS/2 AIX C Compiler.  */
2175
    case LYNXCOFFMAGIC:
2176
    case I386_APPLE_MAGIC:
2177
    case I386_FREEBSD_MAGIC:
2178
    case I386_LINUX_MAGIC:
2179
    case I386_NETBSD_MAGIC:
2180
      arch = bfd_arch_i386;
2181
      break;
2182
#endif
2183
#ifdef AMD64MAGIC
2184
    case AMD64MAGIC:
2185
    case AMD64_APPLE_MAGIC:
2186
    case AMD64_FREEBSD_MAGIC:
2187
    case AMD64_LINUX_MAGIC:
2188
    case AMD64_NETBSD_MAGIC:
2189
      arch = bfd_arch_i386;
2190
      machine = bfd_mach_x86_64;
2191
      break;
2192
#endif
2193
#ifdef IA64MAGIC
2194
    case IA64MAGIC:
2195
      arch = bfd_arch_ia64;
2196
      break;
2197
#endif
2198
#ifdef ARMMAGIC
2199
    case ARMMAGIC:
2200
    case ARMPEMAGIC:
2201
    case THUMBPEMAGIC:
2202
      arch = bfd_arch_arm;
2203
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2204
      if (machine == bfd_mach_arm_unknown)
2205
  {
2206
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2207
      {
2208
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2209
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2210
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2211
      default:
2212
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2213
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2214
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2215
        /* The COFF header does not have enough bits available
2216
     to cover all the different ARM architectures.  So
2217
     we interpret F_ARM_5, the highest flag value to mean
2218
     "the highest ARM architecture known to BFD" which is
2219
     currently the XScale.  */
2220
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2221
      }
2222
  }
2223
      break;
2224
#endif
2225
#ifdef AARCH64MAGIC
2226
    case AARCH64MAGIC:
2227
      arch = bfd_arch_aarch64;
2228
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2229
      break;
2230
#endif
2231
#ifdef LOONGARCH64MAGIC
2232
    case LOONGARCH64MAGIC:
2233
      arch = bfd_arch_loongarch;
2234
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2235
      break;
2236
#endif
2237
#ifdef Z80MAGIC
2238
    case Z80MAGIC:
2239
      arch = bfd_arch_z80;
2240
      switch (internal_f->f_flags & F_MACHMASK)
2241
  {
2242
  case bfd_mach_z80strict << 12:
2243
  case bfd_mach_z80 << 12:
2244
  case bfd_mach_z80n << 12:
2245
  case bfd_mach_z80full << 12:
2246
  case bfd_mach_r800 << 12:
2247
  case bfd_mach_gbz80 << 12:
2248
  case bfd_mach_z180 << 12:
2249
  case bfd_mach_ez80_z80 << 12:
2250
  case bfd_mach_ez80_adl << 12:
2251
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2252
    break;
2253
  default:
2254
    return false;
2255
  }
2256
      break;
2257
#endif
2258
#ifdef Z8KMAGIC
2259
    case Z8KMAGIC:
2260
      arch = bfd_arch_z8k;
2261
      switch (internal_f->f_flags & F_MACHMASK)
2262
  {
2263
  case F_Z8001:
2264
    machine = bfd_mach_z8001;
2265
    break;
2266
  case F_Z8002:
2267
    machine = bfd_mach_z8002;
2268
    break;
2269
  default:
2270
    return false;
2271
  }
2272
      break;
2273
#endif
2274
2275
#ifdef RS6000COFF_C
2276
#ifdef XCOFF64
2277
    case U64_TOCMAGIC:
2278
    case U803XTOCMAGIC:
2279
#else
2280
    case U802ROMAGIC:
2281
    case U802WRMAGIC:
2282
    case U802TOCMAGIC:
2283
#endif
2284
      {
2285
  int cputype;
2286
2287
  if (xcoff_data (abfd)->cputype != -1)
2288
    cputype = xcoff_data (abfd)->cputype & 0xff;
2289
  else
2290
    {
2291
      /* We did not get a value from the a.out header.  If the
2292
         file has not been stripped, we may be able to get the
2293
         architecture information from the first symbol, if it
2294
         is a .file symbol.  */
2295
      if (obj_raw_syment_count (abfd) == 0)
2296
        cputype = 0;
2297
      else
2298
        {
2299
    bfd_byte *buf;
2300
    struct internal_syment sym;
2301
    bfd_size_type amt = bfd_coff_symesz (abfd);
2302
2303
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2304
      return false;
2305
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2306
    if (buf == NULL)
2307
      return false;
2308
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2309
    if (sym.n_sclass == C_FILE)
2310
      cputype = sym.n_type & 0xff;
2311
    else
2312
      cputype = 0;
2313
    free (buf);
2314
        }
2315
    }
2316
2317
  /* FIXME: We don't handle all cases here.  */
2318
  switch (cputype)
2319
    {
2320
    default:
2321
    case 0:
2322
      arch = bfd_xcoff_architecture (abfd);
2323
      machine = bfd_xcoff_machine (abfd);
2324
      break;
2325
2326
    case 1:
2327
      arch = bfd_arch_powerpc;
2328
      machine = bfd_mach_ppc_601;
2329
      break;
2330
    case 2: /* 64 bit PowerPC */
2331
      arch = bfd_arch_powerpc;
2332
      machine = bfd_mach_ppc_620;
2333
      break;
2334
    case 3:
2335
      arch = bfd_arch_powerpc;
2336
      machine = bfd_mach_ppc;
2337
      break;
2338
    case 4:
2339
      arch = bfd_arch_rs6000;
2340
      machine = bfd_mach_rs6k;
2341
      break;
2342
    }
2343
      }
2344
      break;
2345
#endif
2346
2347
#ifdef SH_ARCH_MAGIC_BIG
2348
    case SH_ARCH_MAGIC_BIG:
2349
    case SH_ARCH_MAGIC_LITTLE:
2350
#ifdef COFF_WITH_PE
2351
    case SH_ARCH_MAGIC_WINCE:
2352
#endif
2353
      arch = bfd_arch_sh;
2354
      break;
2355
#endif
2356
2357
#ifdef MIPS_ARCH_MAGIC_WINCE
2358
    case MIPS_ARCH_MAGIC_WINCE:
2359
      arch = bfd_arch_mips;
2360
      break;
2361
#endif
2362
2363
#ifdef SPARCMAGIC
2364
    case SPARCMAGIC:
2365
#ifdef LYNXCOFFMAGIC
2366
    case LYNXCOFFMAGIC:
2367
#endif
2368
      arch = bfd_arch_sparc;
2369
      break;
2370
#endif
2371
2372
#ifdef TIC30MAGIC
2373
    case TIC30MAGIC:
2374
      arch = bfd_arch_tic30;
2375
      break;
2376
#endif
2377
2378
#ifdef TICOFF0MAGIC
2379
#ifdef TICOFF_TARGET_ARCH
2380
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2381
    case TICOFF0MAGIC:
2382
      arch = TICOFF_TARGET_ARCH;
2383
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2384
      break;
2385
#endif
2386
#endif
2387
2388
#ifdef TICOFF1MAGIC
2389
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2390
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2391
    case TICOFF1MAGIC:
2392
    case TICOFF2MAGIC:
2393
      switch (internal_f->f_target_id)
2394
  {
2395
#ifdef TI_TARGET_ID
2396
  case TI_TARGET_ID:
2397
    arch = TICOFF_TARGET_ARCH;
2398
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2399
    break;
2400
#endif
2401
  default:
2402
    arch = bfd_arch_obscure;
2403
    _bfd_error_handler
2404
      (_("unrecognized TI COFF target id '0x%x'"),
2405
       internal_f->f_target_id);
2406
    break;
2407
  }
2408
      break;
2409
#endif
2410
2411
0
#ifdef MCOREMAGIC
2412
5
    case MCOREMAGIC:
2413
5
      arch = bfd_arch_mcore;
2414
5
      break;
2415
0
#endif
2416
2417
0
    default:      /* Unreadable input file type.  */
2418
0
      arch = bfd_arch_obscure;
2419
0
      break;
2420
5
    }
2421
2422
5
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
5
  return true;
2424
5
}
pei-sh.c:coff_set_arch_mach_hook
Line
Count
Source
2162
20
{
2163
20
  unsigned long machine;
2164
20
  enum bfd_architecture arch;
2165
20
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
20
  machine = 0;
2169
20
  switch (internal_f->f_magic)
2170
20
    {
2171
#ifdef I386MAGIC
2172
    case I386MAGIC:
2173
    case I386PTXMAGIC:
2174
    case I386AIXMAGIC:    /* Danbury PS/2 AIX C Compiler.  */
2175
    case LYNXCOFFMAGIC:
2176
    case I386_APPLE_MAGIC:
2177
    case I386_FREEBSD_MAGIC:
2178
    case I386_LINUX_MAGIC:
2179
    case I386_NETBSD_MAGIC:
2180
      arch = bfd_arch_i386;
2181
      break;
2182
#endif
2183
#ifdef AMD64MAGIC
2184
    case AMD64MAGIC:
2185
    case AMD64_APPLE_MAGIC:
2186
    case AMD64_FREEBSD_MAGIC:
2187
    case AMD64_LINUX_MAGIC:
2188
    case AMD64_NETBSD_MAGIC:
2189
      arch = bfd_arch_i386;
2190
      machine = bfd_mach_x86_64;
2191
      break;
2192
#endif
2193
#ifdef IA64MAGIC
2194
    case IA64MAGIC:
2195
      arch = bfd_arch_ia64;
2196
      break;
2197
#endif
2198
#ifdef ARMMAGIC
2199
    case ARMMAGIC:
2200
    case ARMPEMAGIC:
2201
    case THUMBPEMAGIC:
2202
      arch = bfd_arch_arm;
2203
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2204
      if (machine == bfd_mach_arm_unknown)
2205
  {
2206
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2207
      {
2208
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2209
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2210
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2211
      default:
2212
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2213
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2214
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2215
        /* The COFF header does not have enough bits available
2216
     to cover all the different ARM architectures.  So
2217
     we interpret F_ARM_5, the highest flag value to mean
2218
     "the highest ARM architecture known to BFD" which is
2219
     currently the XScale.  */
2220
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2221
      }
2222
  }
2223
      break;
2224
#endif
2225
#ifdef AARCH64MAGIC
2226
    case AARCH64MAGIC:
2227
      arch = bfd_arch_aarch64;
2228
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2229
      break;
2230
#endif
2231
#ifdef LOONGARCH64MAGIC
2232
    case LOONGARCH64MAGIC:
2233
      arch = bfd_arch_loongarch;
2234
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2235
      break;
2236
#endif
2237
#ifdef Z80MAGIC
2238
    case Z80MAGIC:
2239
      arch = bfd_arch_z80;
2240
      switch (internal_f->f_flags & F_MACHMASK)
2241
  {
2242
  case bfd_mach_z80strict << 12:
2243
  case bfd_mach_z80 << 12:
2244
  case bfd_mach_z80n << 12:
2245
  case bfd_mach_z80full << 12:
2246
  case bfd_mach_r800 << 12:
2247
  case bfd_mach_gbz80 << 12:
2248
  case bfd_mach_z180 << 12:
2249
  case bfd_mach_ez80_z80 << 12:
2250
  case bfd_mach_ez80_adl << 12:
2251
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2252
    break;
2253
  default:
2254
    return false;
2255
  }
2256
      break;
2257
#endif
2258
#ifdef Z8KMAGIC
2259
    case Z8KMAGIC:
2260
      arch = bfd_arch_z8k;
2261
      switch (internal_f->f_flags & F_MACHMASK)
2262
  {
2263
  case F_Z8001:
2264
    machine = bfd_mach_z8001;
2265
    break;
2266
  case F_Z8002:
2267
    machine = bfd_mach_z8002;
2268
    break;
2269
  default:
2270
    return false;
2271
  }
2272
      break;
2273
#endif
2274
2275
#ifdef RS6000COFF_C
2276
#ifdef XCOFF64
2277
    case U64_TOCMAGIC:
2278
    case U803XTOCMAGIC:
2279
#else
2280
    case U802ROMAGIC:
2281
    case U802WRMAGIC:
2282
    case U802TOCMAGIC:
2283
#endif
2284
      {
2285
  int cputype;
2286
2287
  if (xcoff_data (abfd)->cputype != -1)
2288
    cputype = xcoff_data (abfd)->cputype & 0xff;
2289
  else
2290
    {
2291
      /* We did not get a value from the a.out header.  If the
2292
         file has not been stripped, we may be able to get the
2293
         architecture information from the first symbol, if it
2294
         is a .file symbol.  */
2295
      if (obj_raw_syment_count (abfd) == 0)
2296
        cputype = 0;
2297
      else
2298
        {
2299
    bfd_byte *buf;
2300
    struct internal_syment sym;
2301
    bfd_size_type amt = bfd_coff_symesz (abfd);
2302
2303
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2304
      return false;
2305
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2306
    if (buf == NULL)
2307
      return false;
2308
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2309
    if (sym.n_sclass == C_FILE)
2310
      cputype = sym.n_type & 0xff;
2311
    else
2312
      cputype = 0;
2313
    free (buf);
2314
        }
2315
    }
2316
2317
  /* FIXME: We don't handle all cases here.  */
2318
  switch (cputype)
2319
    {
2320
    default:
2321
    case 0:
2322
      arch = bfd_xcoff_architecture (abfd);
2323
      machine = bfd_xcoff_machine (abfd);
2324
      break;
2325
2326
    case 1:
2327
      arch = bfd_arch_powerpc;
2328
      machine = bfd_mach_ppc_601;
2329
      break;
2330
    case 2: /* 64 bit PowerPC */
2331
      arch = bfd_arch_powerpc;
2332
      machine = bfd_mach_ppc_620;
2333
      break;
2334
    case 3:
2335
      arch = bfd_arch_powerpc;
2336
      machine = bfd_mach_ppc;
2337
      break;
2338
    case 4:
2339
      arch = bfd_arch_rs6000;
2340
      machine = bfd_mach_rs6k;
2341
      break;
2342
    }
2343
      }
2344
      break;
2345
#endif
2346
2347
0
#ifdef SH_ARCH_MAGIC_BIG
2348
20
    case SH_ARCH_MAGIC_BIG:
2349
20
    case SH_ARCH_MAGIC_LITTLE:
2350
20
#ifdef COFF_WITH_PE
2351
20
    case SH_ARCH_MAGIC_WINCE:
2352
20
#endif
2353
20
      arch = bfd_arch_sh;
2354
20
      break;
2355
0
#endif
2356
2357
#ifdef MIPS_ARCH_MAGIC_WINCE
2358
    case MIPS_ARCH_MAGIC_WINCE:
2359
      arch = bfd_arch_mips;
2360
      break;
2361
#endif
2362
2363
#ifdef SPARCMAGIC
2364
    case SPARCMAGIC:
2365
#ifdef LYNXCOFFMAGIC
2366
    case LYNXCOFFMAGIC:
2367
#endif
2368
      arch = bfd_arch_sparc;
2369
      break;
2370
#endif
2371
2372
#ifdef TIC30MAGIC
2373
    case TIC30MAGIC:
2374
      arch = bfd_arch_tic30;
2375
      break;
2376
#endif
2377
2378
#ifdef TICOFF0MAGIC
2379
#ifdef TICOFF_TARGET_ARCH
2380
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2381
    case TICOFF0MAGIC:
2382
      arch = TICOFF_TARGET_ARCH;
2383
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2384
      break;
2385
#endif
2386
#endif
2387
2388
#ifdef TICOFF1MAGIC
2389
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2390
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2391
    case TICOFF1MAGIC:
2392
    case TICOFF2MAGIC:
2393
      switch (internal_f->f_target_id)
2394
  {
2395
#ifdef TI_TARGET_ID
2396
  case TI_TARGET_ID:
2397
    arch = TICOFF_TARGET_ARCH;
2398
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2399
    break;
2400
#endif
2401
  default:
2402
    arch = bfd_arch_obscure;
2403
    _bfd_error_handler
2404
      (_("unrecognized TI COFF target id '0x%x'"),
2405
       internal_f->f_target_id);
2406
    break;
2407
  }
2408
      break;
2409
#endif
2410
2411
#ifdef MCOREMAGIC
2412
    case MCOREMAGIC:
2413
      arch = bfd_arch_mcore;
2414
      break;
2415
#endif
2416
2417
0
    default:      /* Unreadable input file type.  */
2418
0
      arch = bfd_arch_obscure;
2419
0
      break;
2420
20
    }
2421
2422
20
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
20
  return true;
2424
20
}
2425
2426
static bool
2427
symname_in_debug_hook (bfd *abfd ATTRIBUTE_UNUSED,
2428
           struct internal_syment *sym ATTRIBUTE_UNUSED)
2429
95.8k
{
2430
#ifdef SYMNAME_IN_DEBUG
2431
28.4k
  return SYMNAME_IN_DEBUG (sym) != 0;
2432
#else
2433
  return false;
2434
#endif
2435
95.8k
}
pei-i386.c:symname_in_debug_hook
Line
Count
Source
2429
1.63k
{
2430
#ifdef SYMNAME_IN_DEBUG
2431
  return SYMNAME_IN_DEBUG (sym) != 0;
2432
#else
2433
1.63k
  return false;
2434
1.63k
#endif
2435
1.63k
}
pe-x86_64.c:symname_in_debug_hook
Line
Count
Source
2429
5.08k
{
2430
#ifdef SYMNAME_IN_DEBUG
2431
  return SYMNAME_IN_DEBUG (sym) != 0;
2432
#else
2433
5.08k
  return false;
2434
5.08k
#endif
2435
5.08k
}
pei-x86_64.c:symname_in_debug_hook
Line
Count
Source
2429
2.96k
{
2430
#ifdef SYMNAME_IN_DEBUG
2431
  return SYMNAME_IN_DEBUG (sym) != 0;
2432
#else
2433
2.96k
  return false;
2434
2.96k
#endif
2435
2.96k
}
coff-x86_64.c:symname_in_debug_hook
Line
Count
Source
2429
6.73k
{
2430
#ifdef SYMNAME_IN_DEBUG
2431
  return SYMNAME_IN_DEBUG (sym) != 0;
2432
#else
2433
6.73k
  return false;
2434
6.73k
#endif
2435
6.73k
}
coff64-rs6000.c:symname_in_debug_hook
Line
Count
Source
2429
24.4k
{
2430
24.4k
#ifdef SYMNAME_IN_DEBUG
2431
24.4k
  return SYMNAME_IN_DEBUG (sym) != 0;
2432
#else
2433
  return false;
2434
#endif
2435
24.4k
}
pe-aarch64.c:symname_in_debug_hook
Line
Count
Source
2429
258
{
2430
#ifdef SYMNAME_IN_DEBUG
2431
  return SYMNAME_IN_DEBUG (sym) != 0;
2432
#else
2433
258
  return false;
2434
258
#endif
2435
258
}
pei-aarch64.c:symname_in_debug_hook
Line
Count
Source
2429
1.18k
{
2430
#ifdef SYMNAME_IN_DEBUG
2431
  return SYMNAME_IN_DEBUG (sym) != 0;
2432
#else
2433
1.18k
  return false;
2434
1.18k
#endif
2435
1.18k
}
pei-ia64.c:symname_in_debug_hook
Line
Count
Source
2429
4.13k
{
2430
#ifdef SYMNAME_IN_DEBUG
2431
  return SYMNAME_IN_DEBUG (sym) != 0;
2432
#else
2433
4.13k
  return false;
2434
4.13k
#endif
2435
4.13k
}
pei-loongarch64.c:symname_in_debug_hook
Line
Count
Source
2429
3.69k
{
2430
#ifdef SYMNAME_IN_DEBUG
2431
  return SYMNAME_IN_DEBUG (sym) != 0;
2432
#else
2433
3.69k
  return false;
2434
3.69k
#endif
2435
3.69k
}
Unexecuted instantiation: cf-i386lynx.c:symname_in_debug_hook
Unexecuted instantiation: coff-go32.c:symname_in_debug_hook
Unexecuted instantiation: coff-i386.c:symname_in_debug_hook
coff-rs6000.c:symname_in_debug_hook
Line
Count
Source
2429
3.93k
{
2430
3.93k
#ifdef SYMNAME_IN_DEBUG
2431
3.93k
  return SYMNAME_IN_DEBUG (sym) != 0;
2432
#else
2433
  return false;
2434
#endif
2435
3.93k
}
coff-sh.c:symname_in_debug_hook
Line
Count
Source
2429
9.34k
{
2430
#ifdef SYMNAME_IN_DEBUG
2431
  return SYMNAME_IN_DEBUG (sym) != 0;
2432
#else
2433
9.34k
  return false;
2434
9.34k
#endif
2435
9.34k
}
Unexecuted instantiation: coff-stgo32.c:symname_in_debug_hook
coff-tic30.c:symname_in_debug_hook
Line
Count
Source
2429
1.87k
{
2430
#ifdef SYMNAME_IN_DEBUG
2431
  return SYMNAME_IN_DEBUG (sym) != 0;
2432
#else
2433
1.87k
  return false;
2434
1.87k
#endif
2435
1.87k
}
Unexecuted instantiation: coff-tic4x.c:symname_in_debug_hook
coff-tic54x.c:symname_in_debug_hook
Line
Count
Source
2429
5.98k
{
2430
#ifdef SYMNAME_IN_DEBUG
2431
  return SYMNAME_IN_DEBUG (sym) != 0;
2432
#else
2433
5.98k
  return false;
2434
5.98k
#endif
2435
5.98k
}
coff-z80.c:symname_in_debug_hook
Line
Count
Source
2429
3.99k
{
2430
#ifdef SYMNAME_IN_DEBUG
2431
  return SYMNAME_IN_DEBUG (sym) != 0;
2432
#else
2433
3.99k
  return false;
2434
3.99k
#endif
2435
3.99k
}
coff-z8k.c:symname_in_debug_hook
Line
Count
Source
2429
2.56k
{
2430
#ifdef SYMNAME_IN_DEBUG
2431
  return SYMNAME_IN_DEBUG (sym) != 0;
2432
#else
2433
2.56k
  return false;
2434
2.56k
#endif
2435
2.56k
}
Unexecuted instantiation: pe-arm-wince.c:symname_in_debug_hook
Unexecuted instantiation: pe-arm.c:symname_in_debug_hook
pe-i386.c:symname_in_debug_hook
Line
Count
Source
2429
1.68k
{
2430
#ifdef SYMNAME_IN_DEBUG
2431
  return SYMNAME_IN_DEBUG (sym) != 0;
2432
#else
2433
1.68k
  return false;
2434
1.68k
#endif
2435
1.68k
}
pe-mcore.c:symname_in_debug_hook
Line
Count
Source
2429
8.38k
{
2430
#ifdef SYMNAME_IN_DEBUG
2431
  return SYMNAME_IN_DEBUG (sym) != 0;
2432
#else
2433
8.38k
  return false;
2434
8.38k
#endif
2435
8.38k
}
pe-sh.c:symname_in_debug_hook
Line
Count
Source
2429
6.05k
{
2430
#ifdef SYMNAME_IN_DEBUG
2431
  return SYMNAME_IN_DEBUG (sym) != 0;
2432
#else
2433
6.05k
  return false;
2434
6.05k
#endif
2435
6.05k
}
Unexecuted instantiation: pei-arm-wince.c:symname_in_debug_hook
pei-arm.c:symname_in_debug_hook
Line
Count
Source
2429
171
{
2430
#ifdef SYMNAME_IN_DEBUG
2431
  return SYMNAME_IN_DEBUG (sym) != 0;
2432
#else
2433
171
  return false;
2434
171
#endif
2435
171
}
pei-mcore.c:symname_in_debug_hook
Line
Count
Source
2429
1
{
2430
#ifdef SYMNAME_IN_DEBUG
2431
  return SYMNAME_IN_DEBUG (sym) != 0;
2432
#else
2433
1
  return false;
2434
1
#endif
2435
1
}
pei-sh.c:symname_in_debug_hook
Line
Count
Source
2429
1.71k
{
2430
#ifdef SYMNAME_IN_DEBUG
2431
  return SYMNAME_IN_DEBUG (sym) != 0;
2432
#else
2433
1.71k
  return false;
2434
1.71k
#endif
2435
1.71k
}
2436
2437
#ifdef RS6000COFF_C
2438
2439
#ifdef XCOFF64
2440
#define FORCE_SYMNAMES_IN_STRINGS
2441
#endif
2442
2443
/* Handle the csect auxent of a C_EXT, C_AIX_WEAKEXT or C_HIDEXT symbol.  */
2444
2445
static bool
2446
coff_pointerize_aux_hook (bfd *abfd ATTRIBUTE_UNUSED,
2447
        combined_entry_type *table_base,
2448
        combined_entry_type *symbol,
2449
        unsigned int indaux,
2450
        combined_entry_type *aux)
2451
2.29M
{
2452
2.29M
  BFD_ASSERT (symbol->is_sym);
2453
2.29M
  int n_sclass = symbol->u.syment.n_sclass;
2454
2455
2.29M
  if (CSECT_SYM_P (n_sclass)
2456
2.29M
      && indaux + 1 == symbol->u.syment.n_numaux)
2457
2.58k
    {
2458
2.58k
      BFD_ASSERT (! aux->is_sym);
2459
2.58k
      if (SMTYP_SMTYP (aux->u.auxent.x_csect.x_smtyp) == XTY_LD
2460
2.58k
    && aux->u.auxent.x_csect.x_scnlen.u64 < obj_raw_syment_count (abfd))
2461
319
  {
2462
319
    aux->u.auxent.x_csect.x_scnlen.p =
2463
319
      table_base + aux->u.auxent.x_csect.x_scnlen.u64;
2464
319
    aux->fix_scnlen = 1;
2465
319
  }
2466
2467
      /* Return TRUE to indicate that the caller should not do any
2468
   further work on this auxent.  */
2469
2.58k
      return true;
2470
2.58k
    }
2471
2472
  /* Return FALSE to indicate that this auxent should be handled by
2473
     the caller.  */
2474
2.29M
  return false;
2475
2.29M
}
coff64-rs6000.c:coff_pointerize_aux_hook
Line
Count
Source
2451
437k
{
2452
437k
  BFD_ASSERT (symbol->is_sym);
2453
437k
  int n_sclass = symbol->u.syment.n_sclass;
2454
2455
437k
  if (CSECT_SYM_P (n_sclass)
2456
437k
      && indaux + 1 == symbol->u.syment.n_numaux)
2457
1.73k
    {
2458
1.73k
      BFD_ASSERT (! aux->is_sym);
2459
1.73k
      if (SMTYP_SMTYP (aux->u.auxent.x_csect.x_smtyp) == XTY_LD
2460
1.73k
    && aux->u.auxent.x_csect.x_scnlen.u64 < obj_raw_syment_count (abfd))
2461
0
  {
2462
0
    aux->u.auxent.x_csect.x_scnlen.p =
2463
0
      table_base + aux->u.auxent.x_csect.x_scnlen.u64;
2464
0
    aux->fix_scnlen = 1;
2465
0
  }
2466
2467
      /* Return TRUE to indicate that the caller should not do any
2468
   further work on this auxent.  */
2469
1.73k
      return true;
2470
1.73k
    }
2471
2472
  /* Return FALSE to indicate that this auxent should be handled by
2473
     the caller.  */
2474
436k
  return false;
2475
437k
}
coff-rs6000.c:coff_pointerize_aux_hook
Line
Count
Source
2451
1.85M
{
2452
1.85M
  BFD_ASSERT (symbol->is_sym);
2453
1.85M
  int n_sclass = symbol->u.syment.n_sclass;
2454
2455
1.85M
  if (CSECT_SYM_P (n_sclass)
2456
1.85M
      && indaux + 1 == symbol->u.syment.n_numaux)
2457
847
    {
2458
847
      BFD_ASSERT (! aux->is_sym);
2459
847
      if (SMTYP_SMTYP (aux->u.auxent.x_csect.x_smtyp) == XTY_LD
2460
847
    && aux->u.auxent.x_csect.x_scnlen.u64 < obj_raw_syment_count (abfd))
2461
319
  {
2462
319
    aux->u.auxent.x_csect.x_scnlen.p =
2463
319
      table_base + aux->u.auxent.x_csect.x_scnlen.u64;
2464
319
    aux->fix_scnlen = 1;
2465
319
  }
2466
2467
      /* Return TRUE to indicate that the caller should not do any
2468
   further work on this auxent.  */
2469
847
      return true;
2470
847
    }
2471
2472
  /* Return FALSE to indicate that this auxent should be handled by
2473
     the caller.  */
2474
1.85M
  return false;
2475
1.85M
}
2476
2477
#else
2478
#define coff_pointerize_aux_hook 0
2479
#endif /* ! RS6000COFF_C */
2480
2481
/* Print an aux entry.  This returns TRUE if it has printed it.  */
2482
2483
static bool
2484
coff_print_aux (bfd *abfd ATTRIBUTE_UNUSED,
2485
    FILE *file ATTRIBUTE_UNUSED,
2486
    combined_entry_type *table_base ATTRIBUTE_UNUSED,
2487
    combined_entry_type *symbol ATTRIBUTE_UNUSED,
2488
    combined_entry_type *aux ATTRIBUTE_UNUSED,
2489
    unsigned int indaux ATTRIBUTE_UNUSED)
2490
0
{
2491
0
  BFD_ASSERT (symbol->is_sym);
2492
0
  BFD_ASSERT (! aux->is_sym);
2493
#ifdef RS6000COFF_C
2494
0
  if (CSECT_SYM_P (symbol->u.syment.n_sclass)
2495
0
      && indaux + 1 == symbol->u.syment.n_numaux)
2496
0
    {
2497
      /* This is a csect entry.  */
2498
0
      fprintf (file, "AUX ");
2499
0
      if (SMTYP_SMTYP (aux->u.auxent.x_csect.x_smtyp) != XTY_LD)
2500
0
  {
2501
0
    BFD_ASSERT (! aux->fix_scnlen);
2502
0
    fprintf (file, "val %5" PRIu64,
2503
0
       aux->u.auxent.x_csect.x_scnlen.u64);
2504
0
  }
2505
0
      else
2506
0
  {
2507
0
    fprintf (file, "indx ");
2508
0
    if (! aux->fix_scnlen)
2509
0
      fprintf (file, "%4" PRIu64,
2510
0
         aux->u.auxent.x_csect.x_scnlen.u64);
2511
0
    else
2512
0
      fprintf (file, "%4ld",
2513
0
         (long) (aux->u.auxent.x_csect.x_scnlen.p - table_base));
2514
0
  }
2515
0
      fprintf (file,
2516
0
         " prmhsh %u snhsh %u typ %d algn %d clss %u stb %u snstb %u",
2517
0
         aux->u.auxent.x_csect.x_parmhash,
2518
0
         (unsigned int) aux->u.auxent.x_csect.x_snhash,
2519
0
         SMTYP_SMTYP (aux->u.auxent.x_csect.x_smtyp),
2520
0
         SMTYP_ALIGN (aux->u.auxent.x_csect.x_smtyp),
2521
0
         (unsigned int) aux->u.auxent.x_csect.x_smclas,
2522
0
         aux->u.auxent.x_csect.x_stab,
2523
0
         (unsigned int) aux->u.auxent.x_csect.x_snstab);
2524
0
      return true;
2525
0
    }
2526
0
#endif
2527
2528
  /* Return FALSE to indicate that no special action was taken.  */
2529
0
  return false;
2530
0
}
Unexecuted instantiation: pei-i386.c:coff_print_aux
Unexecuted instantiation: pe-x86_64.c:coff_print_aux
Unexecuted instantiation: pei-x86_64.c:coff_print_aux
Unexecuted instantiation: coff-x86_64.c:coff_print_aux
Unexecuted instantiation: coff64-rs6000.c:coff_print_aux
Unexecuted instantiation: pe-aarch64.c:coff_print_aux
Unexecuted instantiation: pei-aarch64.c:coff_print_aux
Unexecuted instantiation: pei-ia64.c:coff_print_aux
Unexecuted instantiation: pei-loongarch64.c:coff_print_aux
Unexecuted instantiation: cf-i386lynx.c:coff_print_aux
Unexecuted instantiation: coff-go32.c:coff_print_aux
Unexecuted instantiation: coff-i386.c:coff_print_aux
Unexecuted instantiation: coff-rs6000.c:coff_print_aux
Unexecuted instantiation: coff-sh.c:coff_print_aux
Unexecuted instantiation: coff-stgo32.c:coff_print_aux
Unexecuted instantiation: coff-tic30.c:coff_print_aux
Unexecuted instantiation: coff-tic4x.c:coff_print_aux
Unexecuted instantiation: coff-tic54x.c:coff_print_aux
Unexecuted instantiation: coff-z80.c:coff_print_aux
Unexecuted instantiation: coff-z8k.c:coff_print_aux
Unexecuted instantiation: pe-arm-wince.c:coff_print_aux
Unexecuted instantiation: pe-arm.c:coff_print_aux
Unexecuted instantiation: pe-i386.c:coff_print_aux
Unexecuted instantiation: pe-mcore.c:coff_print_aux
Unexecuted instantiation: pe-sh.c:coff_print_aux
Unexecuted instantiation: pei-arm-wince.c:coff_print_aux
Unexecuted instantiation: pei-arm.c:coff_print_aux
Unexecuted instantiation: pei-mcore.c:coff_print_aux
Unexecuted instantiation: pei-sh.c:coff_print_aux
2531
2532
/*
2533
SUBSUBSECTION
2534
  Writing relocations
2535
2536
  To write relocations, the back end steps though the
2537
  canonical relocation table and create an
2538
  @code{internal_reloc}. The symbol index to use is removed from
2539
  the @code{offset} field in the symbol table supplied.  The
2540
  address comes directly from the sum of the section base
2541
  address and the relocation offset; the type is dug directly
2542
  from the howto field.  Then the @code{internal_reloc} is
2543
  swapped into the shape of an @code{external_reloc} and written
2544
  out to disk.
2545
2546
*/
2547
2548
#ifdef TARG_AUX
2549
2550
2551
/* AUX's ld wants relocations to be sorted.  */
2552
static int
2553
compare_arelent_ptr (const void * x, const void * y)
2554
{
2555
  const arelent **a = (const arelent **) x;
2556
  const arelent **b = (const arelent **) y;
2557
  bfd_size_type aadr = (*a)->address;
2558
  bfd_size_type badr = (*b)->address;
2559
2560
  return (aadr < badr ? -1 : badr < aadr ? 1 : 0);
2561
}
2562
2563
#endif /* TARG_AUX */
2564
2565
static bool
2566
coff_write_relocs (bfd * abfd, int first_undef)
2567
7
{
2568
7
  asection *s;
2569
2570
581
  for (s = abfd->sections; s != NULL; s = s->next)
2571
574
    {
2572
574
      unsigned int i;
2573
574
      struct external_reloc dst;
2574
574
      arelent **p;
2575
2576
574
#ifndef TARG_AUX
2577
574
      p = s->orelocation;
2578
#else
2579
      {
2580
  /* Sort relocations before we write them out.  */
2581
  bfd_size_type amt;
2582
2583
  amt = s->reloc_count;
2584
  amt *= sizeof (arelent *);
2585
  p = bfd_malloc (amt);
2586
  if (p == NULL)
2587
    {
2588
      if (s->reloc_count > 0)
2589
        return false;
2590
    }
2591
  else
2592
    {
2593
      memcpy (p, s->orelocation, (size_t) amt);
2594
      qsort (p, s->reloc_count, sizeof (arelent *), compare_arelent_ptr);
2595
    }
2596
      }
2597
#endif
2598
2599
574
      if (bfd_seek (abfd, s->rel_filepos, SEEK_SET) != 0)
2600
0
  return false;
2601
2602
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
2603
574
      if ((obj_pe (abfd) || obj_go32 (abfd)) && s->reloc_count >= 0xffff)
2604
0
  {
2605
    /* Encode real count here as first reloc.  */
2606
0
    struct internal_reloc n;
2607
2608
0
    memset (& n, 0, sizeof (n));
2609
    /* Add one to count *this* reloc (grr).  */
2610
0
    n.r_vaddr = s->reloc_count + 1;
2611
0
    coff_swap_reloc_out (abfd, &n, &dst);
2612
0
    if (bfd_write (&dst, bfd_coff_relsz (abfd), abfd)
2613
0
        != bfd_coff_relsz (abfd))
2614
0
      return false;
2615
0
  }
2616
574
#endif
2617
2618
574
      for (i = 0; i < s->reloc_count; i++)
2619
0
  {
2620
0
    struct internal_reloc n;
2621
0
    arelent *q = p[i];
2622
2623
0
    memset (& n, 0, sizeof (n));
2624
2625
    /* Now we've renumbered the symbols we know where the
2626
       undefined symbols live in the table.  Check the reloc
2627
       entries for symbols who's output bfd isn't the right one.
2628
       This is because the symbol was undefined (which means
2629
       that all the pointers are never made to point to the same
2630
       place). This is a bad thing,'cause the symbols attached
2631
       to the output bfd are indexed, so that the relocation
2632
       entries know which symbol index they point to.  So we
2633
       have to look up the output symbol here.  */
2634
2635
0
    if (q->sym_ptr_ptr[0] != NULL && q->sym_ptr_ptr[0]->the_bfd != abfd)
2636
0
      {
2637
0
        int j;
2638
0
        const char *sname = q->sym_ptr_ptr[0]->name;
2639
0
        asymbol **outsyms = abfd->outsymbols;
2640
2641
0
        for (j = first_undef; outsyms[j]; j++)
2642
0
    {
2643
0
      const char *intable = outsyms[j]->name;
2644
2645
0
      if (strcmp (intable, sname) == 0)
2646
0
        {
2647
          /* Got a hit, so repoint the reloc.  */
2648
0
          q->sym_ptr_ptr = outsyms + j;
2649
0
          break;
2650
0
        }
2651
0
    }
2652
0
      }
2653
2654
0
    n.r_vaddr = q->address + s->vma;
2655
2656
#ifdef R_IHCONST
2657
    /* The 29k const/consth reloc pair is a real kludge.  The consth
2658
       part doesn't have a symbol; it has an offset.  So rebuilt
2659
       that here.  */
2660
    if (q->howto->type == R_IHCONST)
2661
      n.r_symndx = q->addend;
2662
    else
2663
#endif
2664
0
      if (q->sym_ptr_ptr && q->sym_ptr_ptr[0] != NULL)
2665
0
        {
2666
#ifdef SECTION_RELATIVE_ABSOLUTE_SYMBOL_P
2667
0
    if (SECTION_RELATIVE_ABSOLUTE_SYMBOL_P (q, s))
2668
#else
2669
0
    if ((*q->sym_ptr_ptr)->section == bfd_abs_section_ptr
2670
0
        && ((*q->sym_ptr_ptr)->flags & BSF_SECTION_SYM) != 0)
2671
0
#endif
2672
      /* This is a relocation relative to the absolute symbol.  */
2673
0
      n.r_symndx = -1;
2674
0
    else
2675
0
      {
2676
0
        n.r_symndx = get_index ((*(q->sym_ptr_ptr)));
2677
        /* Check to see if the symbol reloc points to a symbol
2678
           we don't have in our symbol table.  */
2679
0
        if (n.r_symndx > obj_conv_table_size (abfd))
2680
0
          {
2681
0
      bfd_set_error (bfd_error_bad_value);
2682
      /* xgettext:c-format */
2683
0
      _bfd_error_handler (_("%pB: reloc against a non-existent"
2684
0
                " symbol index: %ld"),
2685
0
              abfd, n.r_symndx);
2686
0
      return false;
2687
0
          }
2688
0
      }
2689
0
        }
2690
2691
#ifdef SWAP_OUT_RELOC_OFFSET
2692
0
    n.r_offset = q->addend;
2693
0
#endif
2694
2695
#ifdef SELECT_RELOC
2696
    /* Work out reloc type from what is required.  */
2697
0
    if (q->howto)
2698
0
      SELECT_RELOC (n, q->howto);
2699
#else
2700
0
    if (q->howto)
2701
0
      n.r_type = q->howto->type;
2702
#endif
2703
0
    coff_swap_reloc_out (abfd, &n, &dst);
2704
2705
0
    if (bfd_write (&dst, bfd_coff_relsz (abfd), abfd)
2706
0
        != bfd_coff_relsz (abfd))
2707
0
      return false;
2708
0
  }
2709
2710
#ifdef TARG_AUX
2711
      free (p);
2712
#endif
2713
574
    }
2714
2715
7
  return true;
2716
7
}
Unexecuted instantiation: pei-i386.c:coff_write_relocs
Unexecuted instantiation: pe-x86_64.c:coff_write_relocs
pei-x86_64.c:coff_write_relocs
Line
Count
Source
2567
3
{
2568
3
  asection *s;
2569
2570
72
  for (s = abfd->sections; s != NULL; s = s->next)
2571
69
    {
2572
69
      unsigned int i;
2573
69
      struct external_reloc dst;
2574
69
      arelent **p;
2575
2576
69
#ifndef TARG_AUX
2577
69
      p = s->orelocation;
2578
#else
2579
      {
2580
  /* Sort relocations before we write them out.  */
2581
  bfd_size_type amt;
2582
2583
  amt = s->reloc_count;
2584
  amt *= sizeof (arelent *);
2585
  p = bfd_malloc (amt);
2586
  if (p == NULL)
2587
    {
2588
      if (s->reloc_count > 0)
2589
        return false;
2590
    }
2591
  else
2592
    {
2593
      memcpy (p, s->orelocation, (size_t) amt);
2594
      qsort (p, s->reloc_count, sizeof (arelent *), compare_arelent_ptr);
2595
    }
2596
      }
2597
#endif
2598
2599
69
      if (bfd_seek (abfd, s->rel_filepos, SEEK_SET) != 0)
2600
0
  return false;
2601
2602
69
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
2603
69
      if ((obj_pe (abfd) || obj_go32 (abfd)) && s->reloc_count >= 0xffff)
2604
0
  {
2605
    /* Encode real count here as first reloc.  */
2606
0
    struct internal_reloc n;
2607
2608
0
    memset (& n, 0, sizeof (n));
2609
    /* Add one to count *this* reloc (grr).  */
2610
0
    n.r_vaddr = s->reloc_count + 1;
2611
0
    coff_swap_reloc_out (abfd, &n, &dst);
2612
0
    if (bfd_write (&dst, bfd_coff_relsz (abfd), abfd)
2613
0
        != bfd_coff_relsz (abfd))
2614
0
      return false;
2615
0
  }
2616
69
#endif
2617
2618
69
      for (i = 0; i < s->reloc_count; i++)
2619
0
  {
2620
0
    struct internal_reloc n;
2621
0
    arelent *q = p[i];
2622
2623
0
    memset (& n, 0, sizeof (n));
2624
2625
    /* Now we've renumbered the symbols we know where the
2626
       undefined symbols live in the table.  Check the reloc
2627
       entries for symbols who's output bfd isn't the right one.
2628
       This is because the symbol was undefined (which means
2629
       that all the pointers are never made to point to the same
2630
       place). This is a bad thing,'cause the symbols attached
2631
       to the output bfd are indexed, so that the relocation
2632
       entries know which symbol index they point to.  So we
2633
       have to look up the output symbol here.  */
2634
2635
0
    if (q->sym_ptr_ptr[0] != NULL && q->sym_ptr_ptr[0]->the_bfd != abfd)
2636
0
      {
2637
0
        int j;
2638
0
        const char *sname = q->sym_ptr_ptr[0]->name;
2639
0
        asymbol **outsyms = abfd->outsymbols;
2640
2641
0
        for (j = first_undef; outsyms[j]; j++)
2642
0
    {
2643
0
      const char *intable = outsyms[j]->name;
2644
2645
0
      if (strcmp (intable, sname) == 0)
2646
0
        {
2647
          /* Got a hit, so repoint the reloc.  */
2648
0
          q->sym_ptr_ptr = outsyms + j;
2649
0
          break;
2650
0
        }
2651
0
    }
2652
0
      }
2653
2654
0
    n.r_vaddr = q->address + s->vma;
2655
2656
#ifdef R_IHCONST
2657
    /* The 29k const/consth reloc pair is a real kludge.  The consth
2658
       part doesn't have a symbol; it has an offset.  So rebuilt
2659
       that here.  */
2660
    if (q->howto->type == R_IHCONST)
2661
      n.r_symndx = q->addend;
2662
    else
2663
#endif
2664
0
      if (q->sym_ptr_ptr && q->sym_ptr_ptr[0] != NULL)
2665
0
        {
2666
#ifdef SECTION_RELATIVE_ABSOLUTE_SYMBOL_P
2667
    if (SECTION_RELATIVE_ABSOLUTE_SYMBOL_P (q, s))
2668
#else
2669
0
    if ((*q->sym_ptr_ptr)->section == bfd_abs_section_ptr
2670
0
        && ((*q->sym_ptr_ptr)->flags & BSF_SECTION_SYM) != 0)
2671
0
#endif
2672
      /* This is a relocation relative to the absolute symbol.  */
2673
0
      n.r_symndx = -1;
2674
0
    else
2675
0
      {
2676
0
        n.r_symndx = get_index ((*(q->sym_ptr_ptr)));
2677
        /* Check to see if the symbol reloc points to a symbol
2678
           we don't have in our symbol table.  */
2679
0
        if (n.r_symndx > obj_conv_table_size (abfd))
2680
0
          {
2681
0
      bfd_set_error (bfd_error_bad_value);
2682
      /* xgettext:c-format */
2683
0
      _bfd_error_handler (_("%pB: reloc against a non-existent"
2684
0
                " symbol index: %ld"),
2685
0
              abfd, n.r_symndx);
2686
0
      return false;
2687
0
          }
2688
0
      }
2689
0
        }
2690
2691
#ifdef SWAP_OUT_RELOC_OFFSET
2692
    n.r_offset = q->addend;
2693
#endif
2694
2695
0
#ifdef SELECT_RELOC
2696
    /* Work out reloc type from what is required.  */
2697
0
    if (q->howto)
2698
0
      SELECT_RELOC (n, q->howto);
2699
#else
2700
    if (q->howto)
2701
      n.r_type = q->howto->type;
2702
#endif
2703
0
    coff_swap_reloc_out (abfd, &n, &dst);
2704
2705
0
    if (bfd_write (&dst, bfd_coff_relsz (abfd), abfd)
2706
0
        != bfd_coff_relsz (abfd))
2707
0
      return false;
2708
0
  }
2709
2710
#ifdef TARG_AUX
2711
      free (p);
2712
#endif
2713
69
    }
2714
2715
3
  return true;
2716
3
}
Unexecuted instantiation: coff-x86_64.c:coff_write_relocs
Unexecuted instantiation: coff64-rs6000.c:coff_write_relocs
pe-aarch64.c:coff_write_relocs
Line
Count
Source
2567
1
{
2568
1
  asection *s;
2569
2570
2
  for (s = abfd->sections; s != NULL; s = s->next)
2571
1
    {
2572
1
      unsigned int i;
2573
1
      struct external_reloc dst;
2574
1
      arelent **p;
2575
2576
1
#ifndef TARG_AUX
2577
1
      p = s->orelocation;
2578
#else
2579
      {
2580
  /* Sort relocations before we write them out.  */
2581
  bfd_size_type amt;
2582
2583
  amt = s->reloc_count;
2584
  amt *= sizeof (arelent *);
2585
  p = bfd_malloc (amt);
2586
  if (p == NULL)
2587
    {
2588
      if (s->reloc_count > 0)
2589
        return false;
2590
    }
2591
  else
2592
    {
2593
      memcpy (p, s->orelocation, (size_t) amt);
2594
      qsort (p, s->reloc_count, sizeof (arelent *), compare_arelent_ptr);
2595
    }
2596
      }
2597
#endif
2598
2599
1
      if (bfd_seek (abfd, s->rel_filepos, SEEK_SET) != 0)
2600
0
  return false;
2601
2602
1
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
2603
1
      if ((obj_pe (abfd) || obj_go32 (abfd)) && s->reloc_count >= 0xffff)
2604
0
  {
2605
    /* Encode real count here as first reloc.  */
2606
0
    struct internal_reloc n;
2607
2608
0
    memset (& n, 0, sizeof (n));
2609
    /* Add one to count *this* reloc (grr).  */
2610
0
    n.r_vaddr = s->reloc_count + 1;
2611
0
    coff_swap_reloc_out (abfd, &n, &dst);
2612
0
    if (bfd_write (&dst, bfd_coff_relsz (abfd), abfd)
2613
0
        != bfd_coff_relsz (abfd))
2614
0
      return false;
2615
0
  }
2616
1
#endif
2617
2618
1
      for (i = 0; i < s->reloc_count; i++)
2619
0
  {
2620
0
    struct internal_reloc n;
2621
0
    arelent *q = p[i];
2622
2623
0
    memset (& n, 0, sizeof (n));
2624
2625
    /* Now we've renumbered the symbols we know where the
2626
       undefined symbols live in the table.  Check the reloc
2627
       entries for symbols who's output bfd isn't the right one.
2628
       This is because the symbol was undefined (which means
2629
       that all the pointers are never made to point to the same
2630
       place). This is a bad thing,'cause the symbols attached
2631
       to the output bfd are indexed, so that the relocation
2632
       entries know which symbol index they point to.  So we
2633
       have to look up the output symbol here.  */
2634
2635
0
    if (q->sym_ptr_ptr[0] != NULL && q->sym_ptr_ptr[0]->the_bfd != abfd)
2636
0
      {
2637
0
        int j;
2638
0
        const char *sname = q->sym_ptr_ptr[0]->name;
2639
0
        asymbol **outsyms = abfd->outsymbols;
2640
2641
0
        for (j = first_undef; outsyms[j]; j++)
2642
0
    {
2643
0
      const char *intable = outsyms[j]->name;
2644
2645
0
      if (strcmp (intable, sname) == 0)
2646
0
        {
2647
          /* Got a hit, so repoint the reloc.  */
2648
0
          q->sym_ptr_ptr = outsyms + j;
2649
0
          break;
2650
0
        }
2651
0
    }
2652
0
      }
2653
2654
0
    n.r_vaddr = q->address + s->vma;
2655
2656
#ifdef R_IHCONST
2657
    /* The 29k const/consth reloc pair is a real kludge.  The consth
2658
       part doesn't have a symbol; it has an offset.  So rebuilt
2659
       that here.  */
2660
    if (q->howto->type == R_IHCONST)
2661
      n.r_symndx = q->addend;
2662
    else
2663
#endif
2664
0
      if (q->sym_ptr_ptr && q->sym_ptr_ptr[0] != NULL)
2665
0
        {
2666
#ifdef SECTION_RELATIVE_ABSOLUTE_SYMBOL_P
2667
    if (SECTION_RELATIVE_ABSOLUTE_SYMBOL_P (q, s))
2668
#else
2669
0
    if ((*q->sym_ptr_ptr)->section == bfd_abs_section_ptr
2670
0
        && ((*q->sym_ptr_ptr)->flags & BSF_SECTION_SYM) != 0)
2671
0
#endif
2672
      /* This is a relocation relative to the absolute symbol.  */
2673
0
      n.r_symndx = -1;
2674
0
    else
2675
0
      {
2676
0
        n.r_symndx = get_index ((*(q->sym_ptr_ptr)));
2677
        /* Check to see if the symbol reloc points to a symbol
2678
           we don't have in our symbol table.  */
2679
0
        if (n.r_symndx > obj_conv_table_size (abfd))
2680
0
          {
2681
0
      bfd_set_error (bfd_error_bad_value);
2682
      /* xgettext:c-format */
2683
0
      _bfd_error_handler (_("%pB: reloc against a non-existent"
2684
0
                " symbol index: %ld"),
2685
0
              abfd, n.r_symndx);
2686
0
      return false;
2687
0
          }
2688
0
      }
2689
0
        }
2690
2691
#ifdef SWAP_OUT_RELOC_OFFSET
2692
    n.r_offset = q->addend;
2693
#endif
2694
2695
0
#ifdef SELECT_RELOC
2696
    /* Work out reloc type from what is required.  */
2697
0
    if (q->howto)
2698
0
      SELECT_RELOC (n, q->howto);
2699
#else
2700
    if (q->howto)
2701
      n.r_type = q->howto->type;
2702
#endif
2703
0
    coff_swap_reloc_out (abfd, &n, &dst);
2704
2705
0
    if (bfd_write (&dst, bfd_coff_relsz (abfd), abfd)
2706
0
        != bfd_coff_relsz (abfd))
2707
0
      return false;
2708
0
  }
2709
2710
#ifdef TARG_AUX
2711
      free (p);
2712
#endif
2713
1
    }
2714
2715
1
  return true;
2716
1
}
Unexecuted instantiation: pei-aarch64.c:coff_write_relocs
Unexecuted instantiation: pei-ia64.c:coff_write_relocs
Unexecuted instantiation: pei-loongarch64.c:coff_write_relocs
Unexecuted instantiation: cf-i386lynx.c:coff_write_relocs
Unexecuted instantiation: coff-go32.c:coff_write_relocs
Unexecuted instantiation: coff-i386.c:coff_write_relocs
Unexecuted instantiation: coff-rs6000.c:coff_write_relocs
Unexecuted instantiation: coff-sh.c:coff_write_relocs
Unexecuted instantiation: coff-stgo32.c:coff_write_relocs
Unexecuted instantiation: coff-tic30.c:coff_write_relocs
Unexecuted instantiation: coff-tic4x.c:coff_write_relocs
Unexecuted instantiation: coff-tic54x.c:coff_write_relocs
Unexecuted instantiation: coff-z80.c:coff_write_relocs
Unexecuted instantiation: coff-z8k.c:coff_write_relocs
Unexecuted instantiation: pe-arm-wince.c:coff_write_relocs
Unexecuted instantiation: pe-arm.c:coff_write_relocs
pe-i386.c:coff_write_relocs
Line
Count
Source
2567
1
{
2568
1
  asection *s;
2569
2570
498
  for (s = abfd->sections; s != NULL; s = s->next)
2571
497
    {
2572
497
      unsigned int i;
2573
497
      struct external_reloc dst;
2574
497
      arelent **p;
2575
2576
497
#ifndef TARG_AUX
2577
497
      p = s->orelocation;
2578
#else
2579
      {
2580
  /* Sort relocations before we write them out.  */
2581
  bfd_size_type amt;
2582
2583
  amt = s->reloc_count;
2584
  amt *= sizeof (arelent *);
2585
  p = bfd_malloc (amt);
2586
  if (p == NULL)
2587
    {
2588
      if (s->reloc_count > 0)
2589
        return false;
2590
    }
2591
  else
2592
    {
2593
      memcpy (p, s->orelocation, (size_t) amt);
2594
      qsort (p, s->reloc_count, sizeof (arelent *), compare_arelent_ptr);
2595
    }
2596
      }
2597
#endif
2598
2599
497
      if (bfd_seek (abfd, s->rel_filepos, SEEK_SET) != 0)
2600
0
  return false;
2601
2602
497
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
2603
497
      if ((obj_pe (abfd) || obj_go32 (abfd)) && s->reloc_count >= 0xffff)
2604
0
  {
2605
    /* Encode real count here as first reloc.  */
2606
0
    struct internal_reloc n;
2607
2608
0
    memset (& n, 0, sizeof (n));
2609
    /* Add one to count *this* reloc (grr).  */
2610
0
    n.r_vaddr = s->reloc_count + 1;
2611
0
    coff_swap_reloc_out (abfd, &n, &dst);
2612
0
    if (bfd_write (&dst, bfd_coff_relsz (abfd), abfd)
2613
0
        != bfd_coff_relsz (abfd))
2614
0
      return false;
2615
0
  }
2616
497
#endif
2617
2618
497
      for (i = 0; i < s->reloc_count; i++)
2619
0
  {
2620
0
    struct internal_reloc n;
2621
0
    arelent *q = p[i];
2622
2623
0
    memset (& n, 0, sizeof (n));
2624
2625
    /* Now we've renumbered the symbols we know where the
2626
       undefined symbols live in the table.  Check the reloc
2627
       entries for symbols who's output bfd isn't the right one.
2628
       This is because the symbol was undefined (which means
2629
       that all the pointers are never made to point to the same
2630
       place). This is a bad thing,'cause the symbols attached
2631
       to the output bfd are indexed, so that the relocation
2632
       entries know which symbol index they point to.  So we
2633
       have to look up the output symbol here.  */
2634
2635
0
    if (q->sym_ptr_ptr[0] != NULL && q->sym_ptr_ptr[0]->the_bfd != abfd)
2636
0
      {
2637
0
        int j;
2638
0
        const char *sname = q->sym_ptr_ptr[0]->name;
2639
0
        asymbol **outsyms = abfd->outsymbols;
2640
2641
0
        for (j = first_undef; outsyms[j]; j++)
2642
0
    {
2643
0
      const char *intable = outsyms[j]->name;
2644
2645
0
      if (strcmp (intable, sname) == 0)
2646
0
        {
2647
          /* Got a hit, so repoint the reloc.  */
2648
0
          q->sym_ptr_ptr = outsyms + j;
2649
0
          break;
2650
0
        }
2651
0
    }
2652
0
      }
2653
2654
0
    n.r_vaddr = q->address + s->vma;
2655
2656
#ifdef R_IHCONST
2657
    /* The 29k const/consth reloc pair is a real kludge.  The consth
2658
       part doesn't have a symbol; it has an offset.  So rebuilt
2659
       that here.  */
2660
    if (q->howto->type == R_IHCONST)
2661
      n.r_symndx = q->addend;
2662
    else
2663
#endif
2664
0
      if (q->sym_ptr_ptr && q->sym_ptr_ptr[0] != NULL)
2665
0
        {
2666
#ifdef SECTION_RELATIVE_ABSOLUTE_SYMBOL_P
2667
    if (SECTION_RELATIVE_ABSOLUTE_SYMBOL_P (q, s))
2668
#else
2669
0
    if ((*q->sym_ptr_ptr)->section == bfd_abs_section_ptr
2670
0
        && ((*q->sym_ptr_ptr)->flags & BSF_SECTION_SYM) != 0)
2671
0
#endif
2672
      /* This is a relocation relative to the absolute symbol.  */
2673
0
      n.r_symndx = -1;
2674
0
    else
2675
0
      {
2676
0
        n.r_symndx = get_index ((*(q->sym_ptr_ptr)));
2677
        /* Check to see if the symbol reloc points to a symbol
2678
           we don't have in our symbol table.  */
2679
0
        if (n.r_symndx > obj_conv_table_size (abfd))
2680
0
          {
2681
0
      bfd_set_error (bfd_error_bad_value);
2682
      /* xgettext:c-format */
2683
0
      _bfd_error_handler (_("%pB: reloc against a non-existent"
2684
0
                " symbol index: %ld"),
2685
0
              abfd, n.r_symndx);
2686
0
      return false;
2687
0
          }
2688
0
      }
2689
0
        }
2690
2691
#ifdef SWAP_OUT_RELOC_OFFSET
2692
    n.r_offset = q->addend;
2693
#endif
2694
2695
0
#ifdef SELECT_RELOC
2696
    /* Work out reloc type from what is required.  */
2697
0
    if (q->howto)
2698
0
      SELECT_RELOC (n, q->howto);
2699
#else
2700
    if (q->howto)
2701
      n.r_type = q->howto->type;
2702
#endif
2703
0
    coff_swap_reloc_out (abfd, &n, &dst);
2704
2705
0
    if (bfd_write (&dst, bfd_coff_relsz (abfd), abfd)
2706
0
        != bfd_coff_relsz (abfd))
2707
0
      return false;
2708
0
  }
2709
2710
#ifdef TARG_AUX
2711
      free (p);
2712
#endif
2713
497
    }
2714
2715
1
  return true;
2716
1
}
pe-mcore.c:coff_write_relocs
Line
Count
Source
2567
2
{
2568
2
  asection *s;
2569
2570
9
  for (s = abfd->sections; s != NULL; s = s->next)
2571
7
    {
2572
7
      unsigned int i;
2573
7
      struct external_reloc dst;
2574
7
      arelent **p;
2575
2576
7
#ifndef TARG_AUX
2577
7
      p = s->orelocation;
2578
#else
2579
      {
2580
  /* Sort relocations before we write them out.  */
2581
  bfd_size_type amt;
2582
2583
  amt = s->reloc_count;
2584
  amt *= sizeof (arelent *);
2585
  p = bfd_malloc (amt);
2586
  if (p == NULL)
2587
    {
2588
      if (s->reloc_count > 0)
2589
        return false;
2590
    }
2591
  else
2592
    {
2593
      memcpy (p, s->orelocation, (size_t) amt);
2594
      qsort (p, s->reloc_count, sizeof (arelent *), compare_arelent_ptr);
2595
    }
2596
      }
2597
#endif
2598
2599
7
      if (bfd_seek (abfd, s->rel_filepos, SEEK_SET) != 0)
2600
0
  return false;
2601
2602
7
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
2603
7
      if ((obj_pe (abfd) || obj_go32 (abfd)) && s->reloc_count >= 0xffff)
2604
0
  {
2605
    /* Encode real count here as first reloc.  */
2606
0
    struct internal_reloc n;
2607
2608
0
    memset (& n, 0, sizeof (n));
2609
    /* Add one to count *this* reloc (grr).  */
2610
0
    n.r_vaddr = s->reloc_count + 1;
2611
0
    coff_swap_reloc_out (abfd, &n, &dst);
2612
0
    if (bfd_write (&dst, bfd_coff_relsz (abfd), abfd)
2613
0
        != bfd_coff_relsz (abfd))
2614
0
      return false;
2615
0
  }
2616
7
#endif
2617
2618
7
      for (i = 0; i < s->reloc_count; i++)
2619
0
  {
2620
0
    struct internal_reloc n;
2621
0
    arelent *q = p[i];
2622
2623
0
    memset (& n, 0, sizeof (n));
2624
2625
    /* Now we've renumbered the symbols we know where the
2626
       undefined symbols live in the table.  Check the reloc
2627
       entries for symbols who's output bfd isn't the right one.
2628
       This is because the symbol was undefined (which means
2629
       that all the pointers are never made to point to the same
2630
       place). This is a bad thing,'cause the symbols attached
2631
       to the output bfd are indexed, so that the relocation
2632
       entries know which symbol index they point to.  So we
2633
       have to look up the output symbol here.  */
2634
2635
0
    if (q->sym_ptr_ptr[0] != NULL && q->sym_ptr_ptr[0]->the_bfd != abfd)
2636
0
      {
2637
0
        int j;
2638
0
        const char *sname = q->sym_ptr_ptr[0]->name;
2639
0
        asymbol **outsyms = abfd->outsymbols;
2640
2641
0
        for (j = first_undef; outsyms[j]; j++)
2642
0
    {
2643
0
      const char *intable = outsyms[j]->name;
2644
2645
0
      if (strcmp (intable, sname) == 0)
2646
0
        {
2647
          /* Got a hit, so repoint the reloc.  */
2648
0
          q->sym_ptr_ptr = outsyms + j;
2649
0
          break;
2650
0
        }
2651
0
    }
2652
0
      }
2653
2654
0
    n.r_vaddr = q->address + s->vma;
2655
2656
#ifdef R_IHCONST
2657
    /* The 29k const/consth reloc pair is a real kludge.  The consth
2658
       part doesn't have a symbol; it has an offset.  So rebuilt
2659
       that here.  */
2660
    if (q->howto->type == R_IHCONST)
2661
      n.r_symndx = q->addend;
2662
    else
2663
#endif
2664
0
      if (q->sym_ptr_ptr && q->sym_ptr_ptr[0] != NULL)
2665
0
        {
2666
#ifdef SECTION_RELATIVE_ABSOLUTE_SYMBOL_P
2667
    if (SECTION_RELATIVE_ABSOLUTE_SYMBOL_P (q, s))
2668
#else
2669
0
    if ((*q->sym_ptr_ptr)->section == bfd_abs_section_ptr
2670
0
        && ((*q->sym_ptr_ptr)->flags & BSF_SECTION_SYM) != 0)
2671
0
#endif
2672
      /* This is a relocation relative to the absolute symbol.  */
2673
0
      n.r_symndx = -1;
2674
0
    else
2675
0
      {
2676
0
        n.r_symndx = get_index ((*(q->sym_ptr_ptr)));
2677
        /* Check to see if the symbol reloc points to a symbol
2678
           we don't have in our symbol table.  */
2679
0
        if (n.r_symndx > obj_conv_table_size (abfd))
2680
0
          {
2681
0
      bfd_set_error (bfd_error_bad_value);
2682
      /* xgettext:c-format */
2683
0
      _bfd_error_handler (_("%pB: reloc against a non-existent"
2684
0
                " symbol index: %ld"),
2685
0
              abfd, n.r_symndx);
2686
0
      return false;
2687
0
          }
2688
0
      }
2689
0
        }
2690
2691
0
#ifdef SWAP_OUT_RELOC_OFFSET
2692
0
    n.r_offset = q->addend;
2693
0
#endif
2694
2695
0
#ifdef SELECT_RELOC
2696
    /* Work out reloc type from what is required.  */
2697
0
    if (q->howto)
2698
0
      SELECT_RELOC (n, q->howto);
2699
#else
2700
    if (q->howto)
2701
      n.r_type = q->howto->type;
2702
#endif
2703
0
    coff_swap_reloc_out (abfd, &n, &dst);
2704
2705
0
    if (bfd_write (&dst, bfd_coff_relsz (abfd), abfd)
2706
0
        != bfd_coff_relsz (abfd))
2707
0
      return false;
2708
0
  }
2709
2710
#ifdef TARG_AUX
2711
      free (p);
2712
#endif
2713
7
    }
2714
2715
2
  return true;
2716
2
}
Unexecuted instantiation: pe-sh.c:coff_write_relocs
Unexecuted instantiation: pei-arm-wince.c:coff_write_relocs
Unexecuted instantiation: pei-arm.c:coff_write_relocs
Unexecuted instantiation: pei-mcore.c:coff_write_relocs
Unexecuted instantiation: pei-sh.c:coff_write_relocs
2717
2718
/* Set flags and magic number of a coff file from architecture and machine
2719
   type.  Result is TRUE if we can represent the arch&type, FALSE if not.  */
2720
2721
static bool
2722
coff_set_flags (bfd * abfd,
2723
    unsigned int *magicp ATTRIBUTE_UNUSED,
2724
    unsigned short *flagsp ATTRIBUTE_UNUSED)
2725
1.21k
{
2726
1.21k
  switch (bfd_get_arch (abfd))
2727
1.21k
    {
2728
#ifdef Z80MAGIC
2729
42
    case bfd_arch_z80:
2730
42
      *magicp = Z80MAGIC;
2731
42
      switch (bfd_get_mach (abfd))
2732
42
  {
2733
0
  case bfd_mach_z80strict:
2734
0
  case bfd_mach_z80:
2735
0
  case bfd_mach_z80n:
2736
0
  case bfd_mach_z80full:
2737
0
  case bfd_mach_r800:
2738
0
  case bfd_mach_gbz80:
2739
6
  case bfd_mach_z180:
2740
40
  case bfd_mach_ez80_z80:
2741
42
  case bfd_mach_ez80_adl:
2742
42
    *flagsp = bfd_get_mach (abfd) << 12;
2743
42
    break;
2744
0
  default:
2745
0
    return false;
2746
42
  }
2747
42
      return true;
2748
0
#endif
2749
2750
#ifdef Z8KMAGIC
2751
52
    case bfd_arch_z8k:
2752
52
      *magicp = Z8KMAGIC;
2753
2754
52
      switch (bfd_get_mach (abfd))
2755
52
  {
2756
11
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2757
41
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2758
0
  default:       return false;
2759
52
  }
2760
52
      return true;
2761
0
#endif
2762
2763
#ifdef TIC30MAGIC
2764
40
    case bfd_arch_tic30:
2765
40
      *magicp = TIC30MAGIC;
2766
40
      return true;
2767
0
#endif
2768
2769
#ifdef TICOFF_DEFAULT_MAGIC
2770
68
    case TICOFF_TARGET_ARCH:
2771
      /* If there's no indication of which version we want, use the default.  */
2772
68
      if (!abfd->xvec )
2773
0
  *magicp = TICOFF_DEFAULT_MAGIC;
2774
68
      else
2775
68
  {
2776
    /* We may want to output in a different COFF version.  */
2777
68
    switch (abfd->xvec->name[4])
2778
68
      {
2779
68
      case '0':
2780
68
        *magicp = TICOFF0MAGIC;
2781
68
        break;
2782
0
      case '1':
2783
0
        *magicp = TICOFF1MAGIC;
2784
0
        break;
2785
0
      case '2':
2786
0
        *magicp = TICOFF2MAGIC;
2787
0
        break;
2788
0
      default:
2789
0
        return false;
2790
68
      }
2791
68
  }
2792
68
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2793
68
      return true;
2794
0
#endif
2795
2796
#ifdef AARCH64MAGIC
2797
69
    case bfd_arch_aarch64:
2798
69
      * magicp = AARCH64MAGIC;
2799
69
      return true;
2800
0
#endif
2801
2802
#ifdef LOONGARCH64MAGIC
2803
92
    case bfd_arch_loongarch:
2804
92
      * magicp = LOONGARCH64MAGIC;
2805
92
      return true;
2806
0
#endif
2807
2808
#ifdef ARMMAGIC
2809
13
    case bfd_arch_arm:
2810
#ifdef ARM_WINCE
2811
      * magicp = ARMPEMAGIC;
2812
#else
2813
13
      * magicp = ARMMAGIC;
2814
13
#endif
2815
13
      * flagsp = 0;
2816
13
      if (APCS_SET (abfd))
2817
1
  {
2818
1
    if (APCS_26_FLAG (abfd))
2819
0
      * flagsp |= F_APCS26;
2820
2821
1
    if (APCS_FLOAT_FLAG (abfd))
2822
0
      * flagsp |= F_APCS_FLOAT;
2823
2824
1
    if (PIC_FLAG (abfd))
2825
0
      * flagsp |= F_PIC;
2826
1
  }
2827
13
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2828
0
  * flagsp |= F_INTERWORK;
2829
13
      switch (bfd_get_mach (abfd))
2830
13
  {
2831
3
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2832
0
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2833
0
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2834
1
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2835
0
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2836
0
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2837
0
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2838
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2839
       See also the comment in coff_set_arch_mach_hook().  */
2840
0
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2841
0
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2842
9
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2843
13
  }
2844
13
      return true;
2845
0
#endif
2846
2847
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2848
278
    case bfd_arch_i386:
2849
#if defined(I386MAGIC)
2850
113
      *magicp = I386MAGIC;
2851
#endif
2852
#if defined LYNXOS
2853
      /* Just overwrite the usual value if we're doing Lynx.  */
2854
0
      *magicp = LYNXCOFFMAGIC;
2855
#endif
2856
#if defined AMD64MAGIC
2857
165
      *magicp = AMD64MAGIC;
2858
#endif
2859
278
      return true;
2860
0
#endif
2861
2862
#ifdef IA64MAGIC
2863
63
    case bfd_arch_ia64:
2864
63
      *magicp = IA64MAGIC;
2865
63
      return true;
2866
0
#endif
2867
2868
#ifdef SH_ARCH_MAGIC_BIG
2869
206
    case bfd_arch_sh:
2870
#ifdef COFF_IMAGE_WITH_PE
2871
21
      *magicp = SH_ARCH_MAGIC_WINCE;
2872
#else
2873
185
      if (bfd_big_endian (abfd))
2874
7
  *magicp = SH_ARCH_MAGIC_BIG;
2875
178
      else
2876
178
  *magicp = SH_ARCH_MAGIC_LITTLE;
2877
#endif
2878
206
      return true;
2879
0
#endif
2880
2881
#ifdef MIPS_ARCH_MAGIC_WINCE
2882
    case bfd_arch_mips:
2883
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2884
      return true;
2885
#endif
2886
2887
#ifdef SPARCMAGIC
2888
    case bfd_arch_sparc:
2889
      *magicp = SPARCMAGIC;
2890
#ifdef LYNXOS
2891
      /* Just overwrite the usual value if we're doing Lynx.  */
2892
      *magicp = LYNXCOFFMAGIC;
2893
#endif
2894
      return true;
2895
#endif
2896
2897
#ifdef RS6000COFF_C
2898
133
    case bfd_arch_rs6000:
2899
250
    case bfd_arch_powerpc:
2900
250
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2901
250
      *magicp = bfd_xcoff_magic_number (abfd);
2902
250
      return true;
2903
0
#endif
2904
2905
#ifdef MCOREMAGIC
2906
44
    case bfd_arch_mcore:
2907
44
      * magicp = MCOREMAGIC;
2908
44
      return true;
2909
0
#endif
2910
2911
0
    default:      /* Unknown architecture.  */
2912
0
      break;
2913
1.21k
    }
2914
2915
0
  return false;
2916
1.21k
}
pei-i386.c:coff_set_flags
Line
Count
Source
2725
59
{
2726
59
  switch (bfd_get_arch (abfd))
2727
59
    {
2728
#ifdef Z80MAGIC
2729
    case bfd_arch_z80:
2730
      *magicp = Z80MAGIC;
2731
      switch (bfd_get_mach (abfd))
2732
  {
2733
  case bfd_mach_z80strict:
2734
  case bfd_mach_z80:
2735
  case bfd_mach_z80n:
2736
  case bfd_mach_z80full:
2737
  case bfd_mach_r800:
2738
  case bfd_mach_gbz80:
2739
  case bfd_mach_z180:
2740
  case bfd_mach_ez80_z80:
2741
  case bfd_mach_ez80_adl:
2742
    *flagsp = bfd_get_mach (abfd) << 12;
2743
    break;
2744
  default:
2745
    return false;
2746
  }
2747
      return true;
2748
#endif
2749
2750
#ifdef Z8KMAGIC
2751
    case bfd_arch_z8k:
2752
      *magicp = Z8KMAGIC;
2753
2754
      switch (bfd_get_mach (abfd))
2755
  {
2756
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2757
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2758
  default:       return false;
2759
  }
2760
      return true;
2761
#endif
2762
2763
#ifdef TIC30MAGIC
2764
    case bfd_arch_tic30:
2765
      *magicp = TIC30MAGIC;
2766
      return true;
2767
#endif
2768
2769
#ifdef TICOFF_DEFAULT_MAGIC
2770
    case TICOFF_TARGET_ARCH:
2771
      /* If there's no indication of which version we want, use the default.  */
2772
      if (!abfd->xvec )
2773
  *magicp = TICOFF_DEFAULT_MAGIC;
2774
      else
2775
  {
2776
    /* We may want to output in a different COFF version.  */
2777
    switch (abfd->xvec->name[4])
2778
      {
2779
      case '0':
2780
        *magicp = TICOFF0MAGIC;
2781
        break;
2782
      case '1':
2783
        *magicp = TICOFF1MAGIC;
2784
        break;
2785
      case '2':
2786
        *magicp = TICOFF2MAGIC;
2787
        break;
2788
      default:
2789
        return false;
2790
      }
2791
  }
2792
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2793
      return true;
2794
#endif
2795
2796
#ifdef AARCH64MAGIC
2797
    case bfd_arch_aarch64:
2798
      * magicp = AARCH64MAGIC;
2799
      return true;
2800
#endif
2801
2802
#ifdef LOONGARCH64MAGIC
2803
    case bfd_arch_loongarch:
2804
      * magicp = LOONGARCH64MAGIC;
2805
      return true;
2806
#endif
2807
2808
#ifdef ARMMAGIC
2809
    case bfd_arch_arm:
2810
#ifdef ARM_WINCE
2811
      * magicp = ARMPEMAGIC;
2812
#else
2813
      * magicp = ARMMAGIC;
2814
#endif
2815
      * flagsp = 0;
2816
      if (APCS_SET (abfd))
2817
  {
2818
    if (APCS_26_FLAG (abfd))
2819
      * flagsp |= F_APCS26;
2820
2821
    if (APCS_FLOAT_FLAG (abfd))
2822
      * flagsp |= F_APCS_FLOAT;
2823
2824
    if (PIC_FLAG (abfd))
2825
      * flagsp |= F_PIC;
2826
  }
2827
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2828
  * flagsp |= F_INTERWORK;
2829
      switch (bfd_get_mach (abfd))
2830
  {
2831
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2832
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2833
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2834
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2835
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2836
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2837
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2838
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2839
       See also the comment in coff_set_arch_mach_hook().  */
2840
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2841
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2842
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2843
  }
2844
      return true;
2845
#endif
2846
2847
0
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2848
59
    case bfd_arch_i386:
2849
59
#if defined(I386MAGIC)
2850
59
      *magicp = I386MAGIC;
2851
59
#endif
2852
#if defined LYNXOS
2853
      /* Just overwrite the usual value if we're doing Lynx.  */
2854
      *magicp = LYNXCOFFMAGIC;
2855
#endif
2856
#if defined AMD64MAGIC
2857
      *magicp = AMD64MAGIC;
2858
#endif
2859
59
      return true;
2860
0
#endif
2861
2862
#ifdef IA64MAGIC
2863
    case bfd_arch_ia64:
2864
      *magicp = IA64MAGIC;
2865
      return true;
2866
#endif
2867
2868
#ifdef SH_ARCH_MAGIC_BIG
2869
    case bfd_arch_sh:
2870
#ifdef COFF_IMAGE_WITH_PE
2871
      *magicp = SH_ARCH_MAGIC_WINCE;
2872
#else
2873
      if (bfd_big_endian (abfd))
2874
  *magicp = SH_ARCH_MAGIC_BIG;
2875
      else
2876
  *magicp = SH_ARCH_MAGIC_LITTLE;
2877
#endif
2878
      return true;
2879
#endif
2880
2881
#ifdef MIPS_ARCH_MAGIC_WINCE
2882
    case bfd_arch_mips:
2883
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2884
      return true;
2885
#endif
2886
2887
#ifdef SPARCMAGIC
2888
    case bfd_arch_sparc:
2889
      *magicp = SPARCMAGIC;
2890
#ifdef LYNXOS
2891
      /* Just overwrite the usual value if we're doing Lynx.  */
2892
      *magicp = LYNXCOFFMAGIC;
2893
#endif
2894
      return true;
2895
#endif
2896
2897
#ifdef RS6000COFF_C
2898
    case bfd_arch_rs6000:
2899
    case bfd_arch_powerpc:
2900
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2901
      *magicp = bfd_xcoff_magic_number (abfd);
2902
      return true;
2903
#endif
2904
2905
#ifdef MCOREMAGIC
2906
    case bfd_arch_mcore:
2907
      * magicp = MCOREMAGIC;
2908
      return true;
2909
#endif
2910
2911
0
    default:      /* Unknown architecture.  */
2912
0
      break;
2913
59
    }
2914
2915
0
  return false;
2916
59
}
pe-x86_64.c:coff_set_flags
Line
Count
Source
2725
43
{
2726
43
  switch (bfd_get_arch (abfd))
2727
43
    {
2728
#ifdef Z80MAGIC
2729
    case bfd_arch_z80:
2730
      *magicp = Z80MAGIC;
2731
      switch (bfd_get_mach (abfd))
2732
  {
2733
  case bfd_mach_z80strict:
2734
  case bfd_mach_z80:
2735
  case bfd_mach_z80n:
2736
  case bfd_mach_z80full:
2737
  case bfd_mach_r800:
2738
  case bfd_mach_gbz80:
2739
  case bfd_mach_z180:
2740
  case bfd_mach_ez80_z80:
2741
  case bfd_mach_ez80_adl:
2742
    *flagsp = bfd_get_mach (abfd) << 12;
2743
    break;
2744
  default:
2745
    return false;
2746
  }
2747
      return true;
2748
#endif
2749
2750
#ifdef Z8KMAGIC
2751
    case bfd_arch_z8k:
2752
      *magicp = Z8KMAGIC;
2753
2754
      switch (bfd_get_mach (abfd))
2755
  {
2756
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2757
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2758
  default:       return false;
2759
  }
2760
      return true;
2761
#endif
2762
2763
#ifdef TIC30MAGIC
2764
    case bfd_arch_tic30:
2765
      *magicp = TIC30MAGIC;
2766
      return true;
2767
#endif
2768
2769
#ifdef TICOFF_DEFAULT_MAGIC
2770
    case TICOFF_TARGET_ARCH:
2771
      /* If there's no indication of which version we want, use the default.  */
2772
      if (!abfd->xvec )
2773
  *magicp = TICOFF_DEFAULT_MAGIC;
2774
      else
2775
  {
2776
    /* We may want to output in a different COFF version.  */
2777
    switch (abfd->xvec->name[4])
2778
      {
2779
      case '0':
2780
        *magicp = TICOFF0MAGIC;
2781
        break;
2782
      case '1':
2783
        *magicp = TICOFF1MAGIC;
2784
        break;
2785
      case '2':
2786
        *magicp = TICOFF2MAGIC;
2787
        break;
2788
      default:
2789
        return false;
2790
      }
2791
  }
2792
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2793
      return true;
2794
#endif
2795
2796
#ifdef AARCH64MAGIC
2797
    case bfd_arch_aarch64:
2798
      * magicp = AARCH64MAGIC;
2799
      return true;
2800
#endif
2801
2802
#ifdef LOONGARCH64MAGIC
2803
    case bfd_arch_loongarch:
2804
      * magicp = LOONGARCH64MAGIC;
2805
      return true;
2806
#endif
2807
2808
#ifdef ARMMAGIC
2809
    case bfd_arch_arm:
2810
#ifdef ARM_WINCE
2811
      * magicp = ARMPEMAGIC;
2812
#else
2813
      * magicp = ARMMAGIC;
2814
#endif
2815
      * flagsp = 0;
2816
      if (APCS_SET (abfd))
2817
  {
2818
    if (APCS_26_FLAG (abfd))
2819
      * flagsp |= F_APCS26;
2820
2821
    if (APCS_FLOAT_FLAG (abfd))
2822
      * flagsp |= F_APCS_FLOAT;
2823
2824
    if (PIC_FLAG (abfd))
2825
      * flagsp |= F_PIC;
2826
  }
2827
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2828
  * flagsp |= F_INTERWORK;
2829
      switch (bfd_get_mach (abfd))
2830
  {
2831
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2832
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2833
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2834
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2835
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2836
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2837
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2838
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2839
       See also the comment in coff_set_arch_mach_hook().  */
2840
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2841
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2842
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2843
  }
2844
      return true;
2845
#endif
2846
2847
0
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2848
43
    case bfd_arch_i386:
2849
#if defined(I386MAGIC)
2850
      *magicp = I386MAGIC;
2851
#endif
2852
#if defined LYNXOS
2853
      /* Just overwrite the usual value if we're doing Lynx.  */
2854
      *magicp = LYNXCOFFMAGIC;
2855
#endif
2856
43
#if defined AMD64MAGIC
2857
43
      *magicp = AMD64MAGIC;
2858
43
#endif
2859
43
      return true;
2860
0
#endif
2861
2862
#ifdef IA64MAGIC
2863
    case bfd_arch_ia64:
2864
      *magicp = IA64MAGIC;
2865
      return true;
2866
#endif
2867
2868
#ifdef SH_ARCH_MAGIC_BIG
2869
    case bfd_arch_sh:
2870
#ifdef COFF_IMAGE_WITH_PE
2871
      *magicp = SH_ARCH_MAGIC_WINCE;
2872
#else
2873
      if (bfd_big_endian (abfd))
2874
  *magicp = SH_ARCH_MAGIC_BIG;
2875
      else
2876
  *magicp = SH_ARCH_MAGIC_LITTLE;
2877
#endif
2878
      return true;
2879
#endif
2880
2881
#ifdef MIPS_ARCH_MAGIC_WINCE
2882
    case bfd_arch_mips:
2883
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2884
      return true;
2885
#endif
2886
2887
#ifdef SPARCMAGIC
2888
    case bfd_arch_sparc:
2889
      *magicp = SPARCMAGIC;
2890
#ifdef LYNXOS
2891
      /* Just overwrite the usual value if we're doing Lynx.  */
2892
      *magicp = LYNXCOFFMAGIC;
2893
#endif
2894
      return true;
2895
#endif
2896
2897
#ifdef RS6000COFF_C
2898
    case bfd_arch_rs6000:
2899
    case bfd_arch_powerpc:
2900
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2901
      *magicp = bfd_xcoff_magic_number (abfd);
2902
      return true;
2903
#endif
2904
2905
#ifdef MCOREMAGIC
2906
    case bfd_arch_mcore:
2907
      * magicp = MCOREMAGIC;
2908
      return true;
2909
#endif
2910
2911
0
    default:      /* Unknown architecture.  */
2912
0
      break;
2913
43
    }
2914
2915
0
  return false;
2916
43
}
pei-x86_64.c:coff_set_flags
Line
Count
Source
2725
61
{
2726
61
  switch (bfd_get_arch (abfd))
2727
61
    {
2728
#ifdef Z80MAGIC
2729
    case bfd_arch_z80:
2730
      *magicp = Z80MAGIC;
2731
      switch (bfd_get_mach (abfd))
2732
  {
2733
  case bfd_mach_z80strict:
2734
  case bfd_mach_z80:
2735
  case bfd_mach_z80n:
2736
  case bfd_mach_z80full:
2737
  case bfd_mach_r800:
2738
  case bfd_mach_gbz80:
2739
  case bfd_mach_z180:
2740
  case bfd_mach_ez80_z80:
2741
  case bfd_mach_ez80_adl:
2742
    *flagsp = bfd_get_mach (abfd) << 12;
2743
    break;
2744
  default:
2745
    return false;
2746
  }
2747
      return true;
2748
#endif
2749
2750
#ifdef Z8KMAGIC
2751
    case bfd_arch_z8k:
2752
      *magicp = Z8KMAGIC;
2753
2754
      switch (bfd_get_mach (abfd))
2755
  {
2756
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2757
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2758
  default:       return false;
2759
  }
2760
      return true;
2761
#endif
2762
2763
#ifdef TIC30MAGIC
2764
    case bfd_arch_tic30:
2765
      *magicp = TIC30MAGIC;
2766
      return true;
2767
#endif
2768
2769
#ifdef TICOFF_DEFAULT_MAGIC
2770
    case TICOFF_TARGET_ARCH:
2771
      /* If there's no indication of which version we want, use the default.  */
2772
      if (!abfd->xvec )
2773
  *magicp = TICOFF_DEFAULT_MAGIC;
2774
      else
2775
  {
2776
    /* We may want to output in a different COFF version.  */
2777
    switch (abfd->xvec->name[4])
2778
      {
2779
      case '0':
2780
        *magicp = TICOFF0MAGIC;
2781
        break;
2782
      case '1':
2783
        *magicp = TICOFF1MAGIC;
2784
        break;
2785
      case '2':
2786
        *magicp = TICOFF2MAGIC;
2787
        break;
2788
      default:
2789
        return false;
2790
      }
2791
  }
2792
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2793
      return true;
2794
#endif
2795
2796
#ifdef AARCH64MAGIC
2797
    case bfd_arch_aarch64:
2798
      * magicp = AARCH64MAGIC;
2799
      return true;
2800
#endif
2801
2802
#ifdef LOONGARCH64MAGIC
2803
    case bfd_arch_loongarch:
2804
      * magicp = LOONGARCH64MAGIC;
2805
      return true;
2806
#endif
2807
2808
#ifdef ARMMAGIC
2809
    case bfd_arch_arm:
2810
#ifdef ARM_WINCE
2811
      * magicp = ARMPEMAGIC;
2812
#else
2813
      * magicp = ARMMAGIC;
2814
#endif
2815
      * flagsp = 0;
2816
      if (APCS_SET (abfd))
2817
  {
2818
    if (APCS_26_FLAG (abfd))
2819
      * flagsp |= F_APCS26;
2820
2821
    if (APCS_FLOAT_FLAG (abfd))
2822
      * flagsp |= F_APCS_FLOAT;
2823
2824
    if (PIC_FLAG (abfd))
2825
      * flagsp |= F_PIC;
2826
  }
2827
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2828
  * flagsp |= F_INTERWORK;
2829
      switch (bfd_get_mach (abfd))
2830
  {
2831
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2832
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2833
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2834
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2835
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2836
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2837
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2838
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2839
       See also the comment in coff_set_arch_mach_hook().  */
2840
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2841
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2842
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2843
  }
2844
      return true;
2845
#endif
2846
2847
0
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2848
61
    case bfd_arch_i386:
2849
#if defined(I386MAGIC)
2850
      *magicp = I386MAGIC;
2851
#endif
2852
#if defined LYNXOS
2853
      /* Just overwrite the usual value if we're doing Lynx.  */
2854
      *magicp = LYNXCOFFMAGIC;
2855
#endif
2856
61
#if defined AMD64MAGIC
2857
61
      *magicp = AMD64MAGIC;
2858
61
#endif
2859
61
      return true;
2860
0
#endif
2861
2862
#ifdef IA64MAGIC
2863
    case bfd_arch_ia64:
2864
      *magicp = IA64MAGIC;
2865
      return true;
2866
#endif
2867
2868
#ifdef SH_ARCH_MAGIC_BIG
2869
    case bfd_arch_sh:
2870
#ifdef COFF_IMAGE_WITH_PE
2871
      *magicp = SH_ARCH_MAGIC_WINCE;
2872
#else
2873
      if (bfd_big_endian (abfd))
2874
  *magicp = SH_ARCH_MAGIC_BIG;
2875
      else
2876
  *magicp = SH_ARCH_MAGIC_LITTLE;
2877
#endif
2878
      return true;
2879
#endif
2880
2881
#ifdef MIPS_ARCH_MAGIC_WINCE
2882
    case bfd_arch_mips:
2883
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2884
      return true;
2885
#endif
2886
2887
#ifdef SPARCMAGIC
2888
    case bfd_arch_sparc:
2889
      *magicp = SPARCMAGIC;
2890
#ifdef LYNXOS
2891
      /* Just overwrite the usual value if we're doing Lynx.  */
2892
      *magicp = LYNXCOFFMAGIC;
2893
#endif
2894
      return true;
2895
#endif
2896
2897
#ifdef RS6000COFF_C
2898
    case bfd_arch_rs6000:
2899
    case bfd_arch_powerpc:
2900
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2901
      *magicp = bfd_xcoff_magic_number (abfd);
2902
      return true;
2903
#endif
2904
2905
#ifdef MCOREMAGIC
2906
    case bfd_arch_mcore:
2907
      * magicp = MCOREMAGIC;
2908
      return true;
2909
#endif
2910
2911
0
    default:      /* Unknown architecture.  */
2912
0
      break;
2913
61
    }
2914
2915
0
  return false;
2916
61
}
coff-x86_64.c:coff_set_flags
Line
Count
Source
2725
61
{
2726
61
  switch (bfd_get_arch (abfd))
2727
61
    {
2728
#ifdef Z80MAGIC
2729
    case bfd_arch_z80:
2730
      *magicp = Z80MAGIC;
2731
      switch (bfd_get_mach (abfd))
2732
  {
2733
  case bfd_mach_z80strict:
2734
  case bfd_mach_z80:
2735
  case bfd_mach_z80n:
2736
  case bfd_mach_z80full:
2737
  case bfd_mach_r800:
2738
  case bfd_mach_gbz80:
2739
  case bfd_mach_z180:
2740
  case bfd_mach_ez80_z80:
2741
  case bfd_mach_ez80_adl:
2742
    *flagsp = bfd_get_mach (abfd) << 12;
2743
    break;
2744
  default:
2745
    return false;
2746
  }
2747
      return true;
2748
#endif
2749
2750
#ifdef Z8KMAGIC
2751
    case bfd_arch_z8k:
2752
      *magicp = Z8KMAGIC;
2753
2754
      switch (bfd_get_mach (abfd))
2755
  {
2756
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2757
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2758
  default:       return false;
2759
  }
2760
      return true;
2761
#endif
2762
2763
#ifdef TIC30MAGIC
2764
    case bfd_arch_tic30:
2765
      *magicp = TIC30MAGIC;
2766
      return true;
2767
#endif
2768
2769
#ifdef TICOFF_DEFAULT_MAGIC
2770
    case TICOFF_TARGET_ARCH:
2771
      /* If there's no indication of which version we want, use the default.  */
2772
      if (!abfd->xvec )
2773
  *magicp = TICOFF_DEFAULT_MAGIC;
2774
      else
2775
  {
2776
    /* We may want to output in a different COFF version.  */
2777
    switch (abfd->xvec->name[4])
2778
      {
2779
      case '0':
2780
        *magicp = TICOFF0MAGIC;
2781
        break;
2782
      case '1':
2783
        *magicp = TICOFF1MAGIC;
2784
        break;
2785
      case '2':
2786
        *magicp = TICOFF2MAGIC;
2787
        break;
2788
      default:
2789
        return false;
2790
      }
2791
  }
2792
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2793
      return true;
2794
#endif
2795
2796
#ifdef AARCH64MAGIC
2797
    case bfd_arch_aarch64:
2798
      * magicp = AARCH64MAGIC;
2799
      return true;
2800
#endif
2801
2802
#ifdef LOONGARCH64MAGIC
2803
    case bfd_arch_loongarch:
2804
      * magicp = LOONGARCH64MAGIC;
2805
      return true;
2806
#endif
2807
2808
#ifdef ARMMAGIC
2809
    case bfd_arch_arm:
2810
#ifdef ARM_WINCE
2811
      * magicp = ARMPEMAGIC;
2812
#else
2813
      * magicp = ARMMAGIC;
2814
#endif
2815
      * flagsp = 0;
2816
      if (APCS_SET (abfd))
2817
  {
2818
    if (APCS_26_FLAG (abfd))
2819
      * flagsp |= F_APCS26;
2820
2821
    if (APCS_FLOAT_FLAG (abfd))
2822
      * flagsp |= F_APCS_FLOAT;
2823
2824
    if (PIC_FLAG (abfd))
2825
      * flagsp |= F_PIC;
2826
  }
2827
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2828
  * flagsp |= F_INTERWORK;
2829
      switch (bfd_get_mach (abfd))
2830
  {
2831
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2832
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2833
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2834
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2835
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2836
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2837
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2838
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2839
       See also the comment in coff_set_arch_mach_hook().  */
2840
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2841
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2842
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2843
  }
2844
      return true;
2845
#endif
2846
2847
0
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2848
61
    case bfd_arch_i386:
2849
#if defined(I386MAGIC)
2850
      *magicp = I386MAGIC;
2851
#endif
2852
#if defined LYNXOS
2853
      /* Just overwrite the usual value if we're doing Lynx.  */
2854
      *magicp = LYNXCOFFMAGIC;
2855
#endif
2856
61
#if defined AMD64MAGIC
2857
61
      *magicp = AMD64MAGIC;
2858
61
#endif
2859
61
      return true;
2860
0
#endif
2861
2862
#ifdef IA64MAGIC
2863
    case bfd_arch_ia64:
2864
      *magicp = IA64MAGIC;
2865
      return true;
2866
#endif
2867
2868
#ifdef SH_ARCH_MAGIC_BIG
2869
    case bfd_arch_sh:
2870
#ifdef COFF_IMAGE_WITH_PE
2871
      *magicp = SH_ARCH_MAGIC_WINCE;
2872
#else
2873
      if (bfd_big_endian (abfd))
2874
  *magicp = SH_ARCH_MAGIC_BIG;
2875
      else
2876
  *magicp = SH_ARCH_MAGIC_LITTLE;
2877
#endif
2878
      return true;
2879
#endif
2880
2881
#ifdef MIPS_ARCH_MAGIC_WINCE
2882
    case bfd_arch_mips:
2883
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2884
      return true;
2885
#endif
2886
2887
#ifdef SPARCMAGIC
2888
    case bfd_arch_sparc:
2889
      *magicp = SPARCMAGIC;
2890
#ifdef LYNXOS
2891
      /* Just overwrite the usual value if we're doing Lynx.  */
2892
      *magicp = LYNXCOFFMAGIC;
2893
#endif
2894
      return true;
2895
#endif
2896
2897
#ifdef RS6000COFF_C
2898
    case bfd_arch_rs6000:
2899
    case bfd_arch_powerpc:
2900
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2901
      *magicp = bfd_xcoff_magic_number (abfd);
2902
      return true;
2903
#endif
2904
2905
#ifdef MCOREMAGIC
2906
    case bfd_arch_mcore:
2907
      * magicp = MCOREMAGIC;
2908
      return true;
2909
#endif
2910
2911
0
    default:      /* Unknown architecture.  */
2912
0
      break;
2913
61
    }
2914
2915
0
  return false;
2916
61
}
coff64-rs6000.c:coff_set_flags
Line
Count
Source
2725
117
{
2726
117
  switch (bfd_get_arch (abfd))
2727
117
    {
2728
#ifdef Z80MAGIC
2729
    case bfd_arch_z80:
2730
      *magicp = Z80MAGIC;
2731
      switch (bfd_get_mach (abfd))
2732
  {
2733
  case bfd_mach_z80strict:
2734
  case bfd_mach_z80:
2735
  case bfd_mach_z80n:
2736
  case bfd_mach_z80full:
2737
  case bfd_mach_r800:
2738
  case bfd_mach_gbz80:
2739
  case bfd_mach_z180:
2740
  case bfd_mach_ez80_z80:
2741
  case bfd_mach_ez80_adl:
2742
    *flagsp = bfd_get_mach (abfd) << 12;
2743
    break;
2744
  default:
2745
    return false;
2746
  }
2747
      return true;
2748
#endif
2749
2750
#ifdef Z8KMAGIC
2751
    case bfd_arch_z8k:
2752
      *magicp = Z8KMAGIC;
2753
2754
      switch (bfd_get_mach (abfd))
2755
  {
2756
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2757
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2758
  default:       return false;
2759
  }
2760
      return true;
2761
#endif
2762
2763
#ifdef TIC30MAGIC
2764
    case bfd_arch_tic30:
2765
      *magicp = TIC30MAGIC;
2766
      return true;
2767
#endif
2768
2769
#ifdef TICOFF_DEFAULT_MAGIC
2770
    case TICOFF_TARGET_ARCH:
2771
      /* If there's no indication of which version we want, use the default.  */
2772
      if (!abfd->xvec )
2773
  *magicp = TICOFF_DEFAULT_MAGIC;
2774
      else
2775
  {
2776
    /* We may want to output in a different COFF version.  */
2777
    switch (abfd->xvec->name[4])
2778
      {
2779
      case '0':
2780
        *magicp = TICOFF0MAGIC;
2781
        break;
2782
      case '1':
2783
        *magicp = TICOFF1MAGIC;
2784
        break;
2785
      case '2':
2786
        *magicp = TICOFF2MAGIC;
2787
        break;
2788
      default:
2789
        return false;
2790
      }
2791
  }
2792
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2793
      return true;
2794
#endif
2795
2796
#ifdef AARCH64MAGIC
2797
    case bfd_arch_aarch64:
2798
      * magicp = AARCH64MAGIC;
2799
      return true;
2800
#endif
2801
2802
#ifdef LOONGARCH64MAGIC
2803
    case bfd_arch_loongarch:
2804
      * magicp = LOONGARCH64MAGIC;
2805
      return true;
2806
#endif
2807
2808
#ifdef ARMMAGIC
2809
    case bfd_arch_arm:
2810
#ifdef ARM_WINCE
2811
      * magicp = ARMPEMAGIC;
2812
#else
2813
      * magicp = ARMMAGIC;
2814
#endif
2815
      * flagsp = 0;
2816
      if (APCS_SET (abfd))
2817
  {
2818
    if (APCS_26_FLAG (abfd))
2819
      * flagsp |= F_APCS26;
2820
2821
    if (APCS_FLOAT_FLAG (abfd))
2822
      * flagsp |= F_APCS_FLOAT;
2823
2824
    if (PIC_FLAG (abfd))
2825
      * flagsp |= F_PIC;
2826
  }
2827
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2828
  * flagsp |= F_INTERWORK;
2829
      switch (bfd_get_mach (abfd))
2830
  {
2831
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2832
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2833
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2834
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2835
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2836
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2837
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2838
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2839
       See also the comment in coff_set_arch_mach_hook().  */
2840
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2841
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2842
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2843
  }
2844
      return true;
2845
#endif
2846
2847
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2848
    case bfd_arch_i386:
2849
#if defined(I386MAGIC)
2850
      *magicp = I386MAGIC;
2851
#endif
2852
#if defined LYNXOS
2853
      /* Just overwrite the usual value if we're doing Lynx.  */
2854
      *magicp = LYNXCOFFMAGIC;
2855
#endif
2856
#if defined AMD64MAGIC
2857
      *magicp = AMD64MAGIC;
2858
#endif
2859
      return true;
2860
#endif
2861
2862
#ifdef IA64MAGIC
2863
    case bfd_arch_ia64:
2864
      *magicp = IA64MAGIC;
2865
      return true;
2866
#endif
2867
2868
#ifdef SH_ARCH_MAGIC_BIG
2869
    case bfd_arch_sh:
2870
#ifdef COFF_IMAGE_WITH_PE
2871
      *magicp = SH_ARCH_MAGIC_WINCE;
2872
#else
2873
      if (bfd_big_endian (abfd))
2874
  *magicp = SH_ARCH_MAGIC_BIG;
2875
      else
2876
  *magicp = SH_ARCH_MAGIC_LITTLE;
2877
#endif
2878
      return true;
2879
#endif
2880
2881
#ifdef MIPS_ARCH_MAGIC_WINCE
2882
    case bfd_arch_mips:
2883
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2884
      return true;
2885
#endif
2886
2887
#ifdef SPARCMAGIC
2888
    case bfd_arch_sparc:
2889
      *magicp = SPARCMAGIC;
2890
#ifdef LYNXOS
2891
      /* Just overwrite the usual value if we're doing Lynx.  */
2892
      *magicp = LYNXCOFFMAGIC;
2893
#endif
2894
      return true;
2895
#endif
2896
2897
0
#ifdef RS6000COFF_C
2898
0
    case bfd_arch_rs6000:
2899
117
    case bfd_arch_powerpc:
2900
117
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2901
117
      *magicp = bfd_xcoff_magic_number (abfd);
2902
117
      return true;
2903
0
#endif
2904
2905
#ifdef MCOREMAGIC
2906
    case bfd_arch_mcore:
2907
      * magicp = MCOREMAGIC;
2908
      return true;
2909
#endif
2910
2911
0
    default:      /* Unknown architecture.  */
2912
0
      break;
2913
117
    }
2914
2915
0
  return false;
2916
117
}
pe-aarch64.c:coff_set_flags
Line
Count
Source
2725
40
{
2726
40
  switch (bfd_get_arch (abfd))
2727
40
    {
2728
#ifdef Z80MAGIC
2729
    case bfd_arch_z80:
2730
      *magicp = Z80MAGIC;
2731
      switch (bfd_get_mach (abfd))
2732
  {
2733
  case bfd_mach_z80strict:
2734
  case bfd_mach_z80:
2735
  case bfd_mach_z80n:
2736
  case bfd_mach_z80full:
2737
  case bfd_mach_r800:
2738
  case bfd_mach_gbz80:
2739
  case bfd_mach_z180:
2740
  case bfd_mach_ez80_z80:
2741
  case bfd_mach_ez80_adl:
2742
    *flagsp = bfd_get_mach (abfd) << 12;
2743
    break;
2744
  default:
2745
    return false;
2746
  }
2747
      return true;
2748
#endif
2749
2750
#ifdef Z8KMAGIC
2751
    case bfd_arch_z8k:
2752
      *magicp = Z8KMAGIC;
2753
2754
      switch (bfd_get_mach (abfd))
2755
  {
2756
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2757
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2758
  default:       return false;
2759
  }
2760
      return true;
2761
#endif
2762
2763
#ifdef TIC30MAGIC
2764
    case bfd_arch_tic30:
2765
      *magicp = TIC30MAGIC;
2766
      return true;
2767
#endif
2768
2769
#ifdef TICOFF_DEFAULT_MAGIC
2770
    case TICOFF_TARGET_ARCH:
2771
      /* If there's no indication of which version we want, use the default.  */
2772
      if (!abfd->xvec )
2773
  *magicp = TICOFF_DEFAULT_MAGIC;
2774
      else
2775
  {
2776
    /* We may want to output in a different COFF version.  */
2777
    switch (abfd->xvec->name[4])
2778
      {
2779
      case '0':
2780
        *magicp = TICOFF0MAGIC;
2781
        break;
2782
      case '1':
2783
        *magicp = TICOFF1MAGIC;
2784
        break;
2785
      case '2':
2786
        *magicp = TICOFF2MAGIC;
2787
        break;
2788
      default:
2789
        return false;
2790
      }
2791
  }
2792
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2793
      return true;
2794
#endif
2795
2796
0
#ifdef AARCH64MAGIC
2797
40
    case bfd_arch_aarch64:
2798
40
      * magicp = AARCH64MAGIC;
2799
40
      return true;
2800
0
#endif
2801
2802
#ifdef LOONGARCH64MAGIC
2803
    case bfd_arch_loongarch:
2804
      * magicp = LOONGARCH64MAGIC;
2805
      return true;
2806
#endif
2807
2808
#ifdef ARMMAGIC
2809
    case bfd_arch_arm:
2810
#ifdef ARM_WINCE
2811
      * magicp = ARMPEMAGIC;
2812
#else
2813
      * magicp = ARMMAGIC;
2814
#endif
2815
      * flagsp = 0;
2816
      if (APCS_SET (abfd))
2817
  {
2818
    if (APCS_26_FLAG (abfd))
2819
      * flagsp |= F_APCS26;
2820
2821
    if (APCS_FLOAT_FLAG (abfd))
2822
      * flagsp |= F_APCS_FLOAT;
2823
2824
    if (PIC_FLAG (abfd))
2825
      * flagsp |= F_PIC;
2826
  }
2827
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2828
  * flagsp |= F_INTERWORK;
2829
      switch (bfd_get_mach (abfd))
2830
  {
2831
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2832
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2833
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2834
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2835
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2836
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2837
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2838
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2839
       See also the comment in coff_set_arch_mach_hook().  */
2840
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2841
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2842
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2843
  }
2844
      return true;
2845
#endif
2846
2847
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2848
    case bfd_arch_i386:
2849
#if defined(I386MAGIC)
2850
      *magicp = I386MAGIC;
2851
#endif
2852
#if defined LYNXOS
2853
      /* Just overwrite the usual value if we're doing Lynx.  */
2854
      *magicp = LYNXCOFFMAGIC;
2855
#endif
2856
#if defined AMD64MAGIC
2857
      *magicp = AMD64MAGIC;
2858
#endif
2859
      return true;
2860
#endif
2861
2862
#ifdef IA64MAGIC
2863
    case bfd_arch_ia64:
2864
      *magicp = IA64MAGIC;
2865
      return true;
2866
#endif
2867
2868
#ifdef SH_ARCH_MAGIC_BIG
2869
    case bfd_arch_sh:
2870
#ifdef COFF_IMAGE_WITH_PE
2871
      *magicp = SH_ARCH_MAGIC_WINCE;
2872
#else
2873
      if (bfd_big_endian (abfd))
2874
  *magicp = SH_ARCH_MAGIC_BIG;
2875
      else
2876
  *magicp = SH_ARCH_MAGIC_LITTLE;
2877
#endif
2878
      return true;
2879
#endif
2880
2881
#ifdef MIPS_ARCH_MAGIC_WINCE
2882
    case bfd_arch_mips:
2883
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2884
      return true;
2885
#endif
2886
2887
#ifdef SPARCMAGIC
2888
    case bfd_arch_sparc:
2889
      *magicp = SPARCMAGIC;
2890
#ifdef LYNXOS
2891
      /* Just overwrite the usual value if we're doing Lynx.  */
2892
      *magicp = LYNXCOFFMAGIC;
2893
#endif
2894
      return true;
2895
#endif
2896
2897
#ifdef RS6000COFF_C
2898
    case bfd_arch_rs6000:
2899
    case bfd_arch_powerpc:
2900
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2901
      *magicp = bfd_xcoff_magic_number (abfd);
2902
      return true;
2903
#endif
2904
2905
#ifdef MCOREMAGIC
2906
    case bfd_arch_mcore:
2907
      * magicp = MCOREMAGIC;
2908
      return true;
2909
#endif
2910
2911
0
    default:      /* Unknown architecture.  */
2912
0
      break;
2913
40
    }
2914
2915
0
  return false;
2916
40
}
pei-aarch64.c:coff_set_flags
Line
Count
Source
2725
29
{
2726
29
  switch (bfd_get_arch (abfd))
2727
29
    {
2728
#ifdef Z80MAGIC
2729
    case bfd_arch_z80:
2730
      *magicp = Z80MAGIC;
2731
      switch (bfd_get_mach (abfd))
2732
  {
2733
  case bfd_mach_z80strict:
2734
  case bfd_mach_z80:
2735
  case bfd_mach_z80n:
2736
  case bfd_mach_z80full:
2737
  case bfd_mach_r800:
2738
  case bfd_mach_gbz80:
2739
  case bfd_mach_z180:
2740
  case bfd_mach_ez80_z80:
2741
  case bfd_mach_ez80_adl:
2742
    *flagsp = bfd_get_mach (abfd) << 12;
2743
    break;
2744
  default:
2745
    return false;
2746
  }
2747
      return true;
2748
#endif
2749
2750
#ifdef Z8KMAGIC
2751
    case bfd_arch_z8k:
2752
      *magicp = Z8KMAGIC;
2753
2754
      switch (bfd_get_mach (abfd))
2755
  {
2756
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2757
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2758
  default:       return false;
2759
  }
2760
      return true;
2761
#endif
2762
2763
#ifdef TIC30MAGIC
2764
    case bfd_arch_tic30:
2765
      *magicp = TIC30MAGIC;
2766
      return true;
2767
#endif
2768
2769
#ifdef TICOFF_DEFAULT_MAGIC
2770
    case TICOFF_TARGET_ARCH:
2771
      /* If there's no indication of which version we want, use the default.  */
2772
      if (!abfd->xvec )
2773
  *magicp = TICOFF_DEFAULT_MAGIC;
2774
      else
2775
  {
2776
    /* We may want to output in a different COFF version.  */
2777
    switch (abfd->xvec->name[4])
2778
      {
2779
      case '0':
2780
        *magicp = TICOFF0MAGIC;
2781
        break;
2782
      case '1':
2783
        *magicp = TICOFF1MAGIC;
2784
        break;
2785
      case '2':
2786
        *magicp = TICOFF2MAGIC;
2787
        break;
2788
      default:
2789
        return false;
2790
      }
2791
  }
2792
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2793
      return true;
2794
#endif
2795
2796
0
#ifdef AARCH64MAGIC
2797
29
    case bfd_arch_aarch64:
2798
29
      * magicp = AARCH64MAGIC;
2799
29
      return true;
2800
0
#endif
2801
2802
#ifdef LOONGARCH64MAGIC
2803
    case bfd_arch_loongarch:
2804
      * magicp = LOONGARCH64MAGIC;
2805
      return true;
2806
#endif
2807
2808
#ifdef ARMMAGIC
2809
    case bfd_arch_arm:
2810
#ifdef ARM_WINCE
2811
      * magicp = ARMPEMAGIC;
2812
#else
2813
      * magicp = ARMMAGIC;
2814
#endif
2815
      * flagsp = 0;
2816
      if (APCS_SET (abfd))
2817
  {
2818
    if (APCS_26_FLAG (abfd))
2819
      * flagsp |= F_APCS26;
2820
2821
    if (APCS_FLOAT_FLAG (abfd))
2822
      * flagsp |= F_APCS_FLOAT;
2823
2824
    if (PIC_FLAG (abfd))
2825
      * flagsp |= F_PIC;
2826
  }
2827
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2828
  * flagsp |= F_INTERWORK;
2829
      switch (bfd_get_mach (abfd))
2830
  {
2831
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2832
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2833
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2834
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2835
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2836
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2837
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2838
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2839
       See also the comment in coff_set_arch_mach_hook().  */
2840
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2841
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2842
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2843
  }
2844
      return true;
2845
#endif
2846
2847
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2848
    case bfd_arch_i386:
2849
#if defined(I386MAGIC)
2850
      *magicp = I386MAGIC;
2851
#endif
2852
#if defined LYNXOS
2853
      /* Just overwrite the usual value if we're doing Lynx.  */
2854
      *magicp = LYNXCOFFMAGIC;
2855
#endif
2856
#if defined AMD64MAGIC
2857
      *magicp = AMD64MAGIC;
2858
#endif
2859
      return true;
2860
#endif
2861
2862
#ifdef IA64MAGIC
2863
    case bfd_arch_ia64:
2864
      *magicp = IA64MAGIC;
2865
      return true;
2866
#endif
2867
2868
#ifdef SH_ARCH_MAGIC_BIG
2869
    case bfd_arch_sh:
2870
#ifdef COFF_IMAGE_WITH_PE
2871
      *magicp = SH_ARCH_MAGIC_WINCE;
2872
#else
2873
      if (bfd_big_endian (abfd))
2874
  *magicp = SH_ARCH_MAGIC_BIG;
2875
      else
2876
  *magicp = SH_ARCH_MAGIC_LITTLE;
2877
#endif
2878
      return true;
2879
#endif
2880
2881
#ifdef MIPS_ARCH_MAGIC_WINCE
2882
    case bfd_arch_mips:
2883
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2884
      return true;
2885
#endif
2886
2887
#ifdef SPARCMAGIC
2888
    case bfd_arch_sparc:
2889
      *magicp = SPARCMAGIC;
2890
#ifdef LYNXOS
2891
      /* Just overwrite the usual value if we're doing Lynx.  */
2892
      *magicp = LYNXCOFFMAGIC;
2893
#endif
2894
      return true;
2895
#endif
2896
2897
#ifdef RS6000COFF_C
2898
    case bfd_arch_rs6000:
2899
    case bfd_arch_powerpc:
2900
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2901
      *magicp = bfd_xcoff_magic_number (abfd);
2902
      return true;
2903
#endif
2904
2905
#ifdef MCOREMAGIC
2906
    case bfd_arch_mcore:
2907
      * magicp = MCOREMAGIC;
2908
      return true;
2909
#endif
2910
2911
0
    default:      /* Unknown architecture.  */
2912
0
      break;
2913
29
    }
2914
2915
0
  return false;
2916
29
}
pei-ia64.c:coff_set_flags
Line
Count
Source
2725
63
{
2726
63
  switch (bfd_get_arch (abfd))
2727
63
    {
2728
#ifdef Z80MAGIC
2729
    case bfd_arch_z80:
2730
      *magicp = Z80MAGIC;
2731
      switch (bfd_get_mach (abfd))
2732
  {
2733
  case bfd_mach_z80strict:
2734
  case bfd_mach_z80:
2735
  case bfd_mach_z80n:
2736
  case bfd_mach_z80full:
2737
  case bfd_mach_r800:
2738
  case bfd_mach_gbz80:
2739
  case bfd_mach_z180:
2740
  case bfd_mach_ez80_z80:
2741
  case bfd_mach_ez80_adl:
2742
    *flagsp = bfd_get_mach (abfd) << 12;
2743
    break;
2744
  default:
2745
    return false;
2746
  }
2747
      return true;
2748
#endif
2749
2750
#ifdef Z8KMAGIC
2751
    case bfd_arch_z8k:
2752
      *magicp = Z8KMAGIC;
2753
2754
      switch (bfd_get_mach (abfd))
2755
  {
2756
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2757
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2758
  default:       return false;
2759
  }
2760
      return true;
2761
#endif
2762
2763
#ifdef TIC30MAGIC
2764
    case bfd_arch_tic30:
2765
      *magicp = TIC30MAGIC;
2766
      return true;
2767
#endif
2768
2769
#ifdef TICOFF_DEFAULT_MAGIC
2770
    case TICOFF_TARGET_ARCH:
2771
      /* If there's no indication of which version we want, use the default.  */
2772
      if (!abfd->xvec )
2773
  *magicp = TICOFF_DEFAULT_MAGIC;
2774
      else
2775
  {
2776
    /* We may want to output in a different COFF version.  */
2777
    switch (abfd->xvec->name[4])
2778
      {
2779
      case '0':
2780
        *magicp = TICOFF0MAGIC;
2781
        break;
2782
      case '1':
2783
        *magicp = TICOFF1MAGIC;
2784
        break;
2785
      case '2':
2786
        *magicp = TICOFF2MAGIC;
2787
        break;
2788
      default:
2789
        return false;
2790
      }
2791
  }
2792
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2793
      return true;
2794
#endif
2795
2796
#ifdef AARCH64MAGIC
2797
    case bfd_arch_aarch64:
2798
      * magicp = AARCH64MAGIC;
2799
      return true;
2800
#endif
2801
2802
#ifdef LOONGARCH64MAGIC
2803
    case bfd_arch_loongarch:
2804
      * magicp = LOONGARCH64MAGIC;
2805
      return true;
2806
#endif
2807
2808
#ifdef ARMMAGIC
2809
    case bfd_arch_arm:
2810
#ifdef ARM_WINCE
2811
      * magicp = ARMPEMAGIC;
2812
#else
2813
      * magicp = ARMMAGIC;
2814
#endif
2815
      * flagsp = 0;
2816
      if (APCS_SET (abfd))
2817
  {
2818
    if (APCS_26_FLAG (abfd))
2819
      * flagsp |= F_APCS26;
2820
2821
    if (APCS_FLOAT_FLAG (abfd))
2822
      * flagsp |= F_APCS_FLOAT;
2823
2824
    if (PIC_FLAG (abfd))
2825
      * flagsp |= F_PIC;
2826
  }
2827
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2828
  * flagsp |= F_INTERWORK;
2829
      switch (bfd_get_mach (abfd))
2830
  {
2831
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2832
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2833
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2834
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2835
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2836
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2837
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2838
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2839
       See also the comment in coff_set_arch_mach_hook().  */
2840
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2841
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2842
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2843
  }
2844
      return true;
2845
#endif
2846
2847
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2848
    case bfd_arch_i386:
2849
#if defined(I386MAGIC)
2850
      *magicp = I386MAGIC;
2851
#endif
2852
#if defined LYNXOS
2853
      /* Just overwrite the usual value if we're doing Lynx.  */
2854
      *magicp = LYNXCOFFMAGIC;
2855
#endif
2856
#if defined AMD64MAGIC
2857
      *magicp = AMD64MAGIC;
2858
#endif
2859
      return true;
2860
#endif
2861
2862
0
#ifdef IA64MAGIC
2863
63
    case bfd_arch_ia64:
2864
63
      *magicp = IA64MAGIC;
2865
63
      return true;
2866
0
#endif
2867
2868
#ifdef SH_ARCH_MAGIC_BIG
2869
    case bfd_arch_sh:
2870
#ifdef COFF_IMAGE_WITH_PE
2871
      *magicp = SH_ARCH_MAGIC_WINCE;
2872
#else
2873
      if (bfd_big_endian (abfd))
2874
  *magicp = SH_ARCH_MAGIC_BIG;
2875
      else
2876
  *magicp = SH_ARCH_MAGIC_LITTLE;
2877
#endif
2878
      return true;
2879
#endif
2880
2881
#ifdef MIPS_ARCH_MAGIC_WINCE
2882
    case bfd_arch_mips:
2883
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2884
      return true;
2885
#endif
2886
2887
#ifdef SPARCMAGIC
2888
    case bfd_arch_sparc:
2889
      *magicp = SPARCMAGIC;
2890
#ifdef LYNXOS
2891
      /* Just overwrite the usual value if we're doing Lynx.  */
2892
      *magicp = LYNXCOFFMAGIC;
2893
#endif
2894
      return true;
2895
#endif
2896
2897
#ifdef RS6000COFF_C
2898
    case bfd_arch_rs6000:
2899
    case bfd_arch_powerpc:
2900
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2901
      *magicp = bfd_xcoff_magic_number (abfd);
2902
      return true;
2903
#endif
2904
2905
#ifdef MCOREMAGIC
2906
    case bfd_arch_mcore:
2907
      * magicp = MCOREMAGIC;
2908
      return true;
2909
#endif
2910
2911
0
    default:      /* Unknown architecture.  */
2912
0
      break;
2913
63
    }
2914
2915
0
  return false;
2916
63
}
pei-loongarch64.c:coff_set_flags
Line
Count
Source
2725
92
{
2726
92
  switch (bfd_get_arch (abfd))
2727
92
    {
2728
#ifdef Z80MAGIC
2729
    case bfd_arch_z80:
2730
      *magicp = Z80MAGIC;
2731
      switch (bfd_get_mach (abfd))
2732
  {
2733
  case bfd_mach_z80strict:
2734
  case bfd_mach_z80:
2735
  case bfd_mach_z80n:
2736
  case bfd_mach_z80full:
2737
  case bfd_mach_r800:
2738
  case bfd_mach_gbz80:
2739
  case bfd_mach_z180:
2740
  case bfd_mach_ez80_z80:
2741
  case bfd_mach_ez80_adl:
2742
    *flagsp = bfd_get_mach (abfd) << 12;
2743
    break;
2744
  default:
2745
    return false;
2746
  }
2747
      return true;
2748
#endif
2749
2750
#ifdef Z8KMAGIC
2751
    case bfd_arch_z8k:
2752
      *magicp = Z8KMAGIC;
2753
2754
      switch (bfd_get_mach (abfd))
2755
  {
2756
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2757
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2758
  default:       return false;
2759
  }
2760
      return true;
2761
#endif
2762
2763
#ifdef TIC30MAGIC
2764
    case bfd_arch_tic30:
2765
      *magicp = TIC30MAGIC;
2766
      return true;
2767
#endif
2768
2769
#ifdef TICOFF_DEFAULT_MAGIC
2770
    case TICOFF_TARGET_ARCH:
2771
      /* If there's no indication of which version we want, use the default.  */
2772
      if (!abfd->xvec )
2773
  *magicp = TICOFF_DEFAULT_MAGIC;
2774
      else
2775
  {
2776
    /* We may want to output in a different COFF version.  */
2777
    switch (abfd->xvec->name[4])
2778
      {
2779
      case '0':
2780
        *magicp = TICOFF0MAGIC;
2781
        break;
2782
      case '1':
2783
        *magicp = TICOFF1MAGIC;
2784
        break;
2785
      case '2':
2786
        *magicp = TICOFF2MAGIC;
2787
        break;
2788
      default:
2789
        return false;
2790
      }
2791
  }
2792
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2793
      return true;
2794
#endif
2795
2796
#ifdef AARCH64MAGIC
2797
    case bfd_arch_aarch64:
2798
      * magicp = AARCH64MAGIC;
2799
      return true;
2800
#endif
2801
2802
0
#ifdef LOONGARCH64MAGIC
2803
92
    case bfd_arch_loongarch:
2804
92
      * magicp = LOONGARCH64MAGIC;
2805
92
      return true;
2806
0
#endif
2807
2808
#ifdef ARMMAGIC
2809
    case bfd_arch_arm:
2810
#ifdef ARM_WINCE
2811
      * magicp = ARMPEMAGIC;
2812
#else
2813
      * magicp = ARMMAGIC;
2814
#endif
2815
      * flagsp = 0;
2816
      if (APCS_SET (abfd))
2817
  {
2818
    if (APCS_26_FLAG (abfd))
2819
      * flagsp |= F_APCS26;
2820
2821
    if (APCS_FLOAT_FLAG (abfd))
2822
      * flagsp |= F_APCS_FLOAT;
2823
2824
    if (PIC_FLAG (abfd))
2825
      * flagsp |= F_PIC;
2826
  }
2827
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2828
  * flagsp |= F_INTERWORK;
2829
      switch (bfd_get_mach (abfd))
2830
  {
2831
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2832
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2833
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2834
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2835
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2836
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2837
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2838
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2839
       See also the comment in coff_set_arch_mach_hook().  */
2840
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2841
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2842
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2843
  }
2844
      return true;
2845
#endif
2846
2847
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2848
    case bfd_arch_i386:
2849
#if defined(I386MAGIC)
2850
      *magicp = I386MAGIC;
2851
#endif
2852
#if defined LYNXOS
2853
      /* Just overwrite the usual value if we're doing Lynx.  */
2854
      *magicp = LYNXCOFFMAGIC;
2855
#endif
2856
#if defined AMD64MAGIC
2857
      *magicp = AMD64MAGIC;
2858
#endif
2859
      return true;
2860
#endif
2861
2862
#ifdef IA64MAGIC
2863
    case bfd_arch_ia64:
2864
      *magicp = IA64MAGIC;
2865
      return true;
2866
#endif
2867
2868
#ifdef SH_ARCH_MAGIC_BIG
2869
    case bfd_arch_sh:
2870
#ifdef COFF_IMAGE_WITH_PE
2871
      *magicp = SH_ARCH_MAGIC_WINCE;
2872
#else
2873
      if (bfd_big_endian (abfd))
2874
  *magicp = SH_ARCH_MAGIC_BIG;
2875
      else
2876
  *magicp = SH_ARCH_MAGIC_LITTLE;
2877
#endif
2878
      return true;
2879
#endif
2880
2881
#ifdef MIPS_ARCH_MAGIC_WINCE
2882
    case bfd_arch_mips:
2883
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2884
      return true;
2885
#endif
2886
2887
#ifdef SPARCMAGIC
2888
    case bfd_arch_sparc:
2889
      *magicp = SPARCMAGIC;
2890
#ifdef LYNXOS
2891
      /* Just overwrite the usual value if we're doing Lynx.  */
2892
      *magicp = LYNXCOFFMAGIC;
2893
#endif
2894
      return true;
2895
#endif
2896
2897
#ifdef RS6000COFF_C
2898
    case bfd_arch_rs6000:
2899
    case bfd_arch_powerpc:
2900
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2901
      *magicp = bfd_xcoff_magic_number (abfd);
2902
      return true;
2903
#endif
2904
2905
#ifdef MCOREMAGIC
2906
    case bfd_arch_mcore:
2907
      * magicp = MCOREMAGIC;
2908
      return true;
2909
#endif
2910
2911
0
    default:      /* Unknown architecture.  */
2912
0
      break;
2913
92
    }
2914
2915
0
  return false;
2916
92
}
Unexecuted instantiation: cf-i386lynx.c:coff_set_flags
Unexecuted instantiation: coff-go32.c:coff_set_flags
Unexecuted instantiation: coff-i386.c:coff_set_flags
coff-rs6000.c:coff_set_flags
Line
Count
Source
2725
133
{
2726
133
  switch (bfd_get_arch (abfd))
2727
133
    {
2728
#ifdef Z80MAGIC
2729
    case bfd_arch_z80:
2730
      *magicp = Z80MAGIC;
2731
      switch (bfd_get_mach (abfd))
2732
  {
2733
  case bfd_mach_z80strict:
2734
  case bfd_mach_z80:
2735
  case bfd_mach_z80n:
2736
  case bfd_mach_z80full:
2737
  case bfd_mach_r800:
2738
  case bfd_mach_gbz80:
2739
  case bfd_mach_z180:
2740
  case bfd_mach_ez80_z80:
2741
  case bfd_mach_ez80_adl:
2742
    *flagsp = bfd_get_mach (abfd) << 12;
2743
    break;
2744
  default:
2745
    return false;
2746
  }
2747
      return true;
2748
#endif
2749
2750
#ifdef Z8KMAGIC
2751
    case bfd_arch_z8k:
2752
      *magicp = Z8KMAGIC;
2753
2754
      switch (bfd_get_mach (abfd))
2755
  {
2756
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2757
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2758
  default:       return false;
2759
  }
2760
      return true;
2761
#endif
2762
2763
#ifdef TIC30MAGIC
2764
    case bfd_arch_tic30:
2765
      *magicp = TIC30MAGIC;
2766
      return true;
2767
#endif
2768
2769
#ifdef TICOFF_DEFAULT_MAGIC
2770
    case TICOFF_TARGET_ARCH:
2771
      /* If there's no indication of which version we want, use the default.  */
2772
      if (!abfd->xvec )
2773
  *magicp = TICOFF_DEFAULT_MAGIC;
2774
      else
2775
  {
2776
    /* We may want to output in a different COFF version.  */
2777
    switch (abfd->xvec->name[4])
2778
      {
2779
      case '0':
2780
        *magicp = TICOFF0MAGIC;
2781
        break;
2782
      case '1':
2783
        *magicp = TICOFF1MAGIC;
2784
        break;
2785
      case '2':
2786
        *magicp = TICOFF2MAGIC;
2787
        break;
2788
      default:
2789
        return false;
2790
      }
2791
  }
2792
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2793
      return true;
2794
#endif
2795
2796
#ifdef AARCH64MAGIC
2797
    case bfd_arch_aarch64:
2798
      * magicp = AARCH64MAGIC;
2799
      return true;
2800
#endif
2801
2802
#ifdef LOONGARCH64MAGIC
2803
    case bfd_arch_loongarch:
2804
      * magicp = LOONGARCH64MAGIC;
2805
      return true;
2806
#endif
2807
2808
#ifdef ARMMAGIC
2809
    case bfd_arch_arm:
2810
#ifdef ARM_WINCE
2811
      * magicp = ARMPEMAGIC;
2812
#else
2813
      * magicp = ARMMAGIC;
2814
#endif
2815
      * flagsp = 0;
2816
      if (APCS_SET (abfd))
2817
  {
2818
    if (APCS_26_FLAG (abfd))
2819
      * flagsp |= F_APCS26;
2820
2821
    if (APCS_FLOAT_FLAG (abfd))
2822
      * flagsp |= F_APCS_FLOAT;
2823
2824
    if (PIC_FLAG (abfd))
2825
      * flagsp |= F_PIC;
2826
  }
2827
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2828
  * flagsp |= F_INTERWORK;
2829
      switch (bfd_get_mach (abfd))
2830
  {
2831
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2832
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2833
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2834
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2835
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2836
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2837
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2838
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2839
       See also the comment in coff_set_arch_mach_hook().  */
2840
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2841
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2842
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2843
  }
2844
      return true;
2845
#endif
2846
2847
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2848
    case bfd_arch_i386:
2849
#if defined(I386MAGIC)
2850
      *magicp = I386MAGIC;
2851
#endif
2852
#if defined LYNXOS
2853
      /* Just overwrite the usual value if we're doing Lynx.  */
2854
      *magicp = LYNXCOFFMAGIC;
2855
#endif
2856
#if defined AMD64MAGIC
2857
      *magicp = AMD64MAGIC;
2858
#endif
2859
      return true;
2860
#endif
2861
2862
#ifdef IA64MAGIC
2863
    case bfd_arch_ia64:
2864
      *magicp = IA64MAGIC;
2865
      return true;
2866
#endif
2867
2868
#ifdef SH_ARCH_MAGIC_BIG
2869
    case bfd_arch_sh:
2870
#ifdef COFF_IMAGE_WITH_PE
2871
      *magicp = SH_ARCH_MAGIC_WINCE;
2872
#else
2873
      if (bfd_big_endian (abfd))
2874
  *magicp = SH_ARCH_MAGIC_BIG;
2875
      else
2876
  *magicp = SH_ARCH_MAGIC_LITTLE;
2877
#endif
2878
      return true;
2879
#endif
2880
2881
#ifdef MIPS_ARCH_MAGIC_WINCE
2882
    case bfd_arch_mips:
2883
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2884
      return true;
2885
#endif
2886
2887
#ifdef SPARCMAGIC
2888
    case bfd_arch_sparc:
2889
      *magicp = SPARCMAGIC;
2890
#ifdef LYNXOS
2891
      /* Just overwrite the usual value if we're doing Lynx.  */
2892
      *magicp = LYNXCOFFMAGIC;
2893
#endif
2894
      return true;
2895
#endif
2896
2897
0
#ifdef RS6000COFF_C
2898
133
    case bfd_arch_rs6000:
2899
133
    case bfd_arch_powerpc:
2900
133
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2901
133
      *magicp = bfd_xcoff_magic_number (abfd);
2902
133
      return true;
2903
0
#endif
2904
2905
#ifdef MCOREMAGIC
2906
    case bfd_arch_mcore:
2907
      * magicp = MCOREMAGIC;
2908
      return true;
2909
#endif
2910
2911
0
    default:      /* Unknown architecture.  */
2912
0
      break;
2913
133
    }
2914
2915
0
  return false;
2916
133
}
coff-sh.c:coff_set_flags
Line
Count
Source
2725
153
{
2726
153
  switch (bfd_get_arch (abfd))
2727
153
    {
2728
#ifdef Z80MAGIC
2729
    case bfd_arch_z80:
2730
      *magicp = Z80MAGIC;
2731
      switch (bfd_get_mach (abfd))
2732
  {
2733
  case bfd_mach_z80strict:
2734
  case bfd_mach_z80:
2735
  case bfd_mach_z80n:
2736
  case bfd_mach_z80full:
2737
  case bfd_mach_r800:
2738
  case bfd_mach_gbz80:
2739
  case bfd_mach_z180:
2740
  case bfd_mach_ez80_z80:
2741
  case bfd_mach_ez80_adl:
2742
    *flagsp = bfd_get_mach (abfd) << 12;
2743
    break;
2744
  default:
2745
    return false;
2746
  }
2747
      return true;
2748
#endif
2749
2750
#ifdef Z8KMAGIC
2751
    case bfd_arch_z8k:
2752
      *magicp = Z8KMAGIC;
2753
2754
      switch (bfd_get_mach (abfd))
2755
  {
2756
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2757
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2758
  default:       return false;
2759
  }
2760
      return true;
2761
#endif
2762
2763
#ifdef TIC30MAGIC
2764
    case bfd_arch_tic30:
2765
      *magicp = TIC30MAGIC;
2766
      return true;
2767
#endif
2768
2769
#ifdef TICOFF_DEFAULT_MAGIC
2770
    case TICOFF_TARGET_ARCH:
2771
      /* If there's no indication of which version we want, use the default.  */
2772
      if (!abfd->xvec )
2773
  *magicp = TICOFF_DEFAULT_MAGIC;
2774
      else
2775
  {
2776
    /* We may want to output in a different COFF version.  */
2777
    switch (abfd->xvec->name[4])
2778
      {
2779
      case '0':
2780
        *magicp = TICOFF0MAGIC;
2781
        break;
2782
      case '1':
2783
        *magicp = TICOFF1MAGIC;
2784
        break;
2785
      case '2':
2786
        *magicp = TICOFF2MAGIC;
2787
        break;
2788
      default:
2789
        return false;
2790
      }
2791
  }
2792
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2793
      return true;
2794
#endif
2795
2796
#ifdef AARCH64MAGIC
2797
    case bfd_arch_aarch64:
2798
      * magicp = AARCH64MAGIC;
2799
      return true;
2800
#endif
2801
2802
#ifdef LOONGARCH64MAGIC
2803
    case bfd_arch_loongarch:
2804
      * magicp = LOONGARCH64MAGIC;
2805
      return true;
2806
#endif
2807
2808
#ifdef ARMMAGIC
2809
    case bfd_arch_arm:
2810
#ifdef ARM_WINCE
2811
      * magicp = ARMPEMAGIC;
2812
#else
2813
      * magicp = ARMMAGIC;
2814
#endif
2815
      * flagsp = 0;
2816
      if (APCS_SET (abfd))
2817
  {
2818
    if (APCS_26_FLAG (abfd))
2819
      * flagsp |= F_APCS26;
2820
2821
    if (APCS_FLOAT_FLAG (abfd))
2822
      * flagsp |= F_APCS_FLOAT;
2823
2824
    if (PIC_FLAG (abfd))
2825
      * flagsp |= F_PIC;
2826
  }
2827
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2828
  * flagsp |= F_INTERWORK;
2829
      switch (bfd_get_mach (abfd))
2830
  {
2831
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2832
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2833
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2834
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2835
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2836
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2837
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2838
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2839
       See also the comment in coff_set_arch_mach_hook().  */
2840
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2841
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2842
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2843
  }
2844
      return true;
2845
#endif
2846
2847
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2848
    case bfd_arch_i386:
2849
#if defined(I386MAGIC)
2850
      *magicp = I386MAGIC;
2851
#endif
2852
#if defined LYNXOS
2853
      /* Just overwrite the usual value if we're doing Lynx.  */
2854
      *magicp = LYNXCOFFMAGIC;
2855
#endif
2856
#if defined AMD64MAGIC
2857
      *magicp = AMD64MAGIC;
2858
#endif
2859
      return true;
2860
#endif
2861
2862
#ifdef IA64MAGIC
2863
    case bfd_arch_ia64:
2864
      *magicp = IA64MAGIC;
2865
      return true;
2866
#endif
2867
2868
0
#ifdef SH_ARCH_MAGIC_BIG
2869
153
    case bfd_arch_sh:
2870
#ifdef COFF_IMAGE_WITH_PE
2871
      *magicp = SH_ARCH_MAGIC_WINCE;
2872
#else
2873
153
      if (bfd_big_endian (abfd))
2874
7
  *magicp = SH_ARCH_MAGIC_BIG;
2875
146
      else
2876
146
  *magicp = SH_ARCH_MAGIC_LITTLE;
2877
153
#endif
2878
153
      return true;
2879
0
#endif
2880
2881
#ifdef MIPS_ARCH_MAGIC_WINCE
2882
    case bfd_arch_mips:
2883
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2884
      return true;
2885
#endif
2886
2887
#ifdef SPARCMAGIC
2888
    case bfd_arch_sparc:
2889
      *magicp = SPARCMAGIC;
2890
#ifdef LYNXOS
2891
      /* Just overwrite the usual value if we're doing Lynx.  */
2892
      *magicp = LYNXCOFFMAGIC;
2893
#endif
2894
      return true;
2895
#endif
2896
2897
#ifdef RS6000COFF_C
2898
    case bfd_arch_rs6000:
2899
    case bfd_arch_powerpc:
2900
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2901
      *magicp = bfd_xcoff_magic_number (abfd);
2902
      return true;
2903
#endif
2904
2905
#ifdef MCOREMAGIC
2906
    case bfd_arch_mcore:
2907
      * magicp = MCOREMAGIC;
2908
      return true;
2909
#endif
2910
2911
0
    default:      /* Unknown architecture.  */
2912
0
      break;
2913
153
    }
2914
2915
0
  return false;
2916
153
}
Unexecuted instantiation: coff-stgo32.c:coff_set_flags
coff-tic30.c:coff_set_flags
Line
Count
Source
2725
40
{
2726
40
  switch (bfd_get_arch (abfd))
2727
40
    {
2728
#ifdef Z80MAGIC
2729
    case bfd_arch_z80:
2730
      *magicp = Z80MAGIC;
2731
      switch (bfd_get_mach (abfd))
2732
  {
2733
  case bfd_mach_z80strict:
2734
  case bfd_mach_z80:
2735
  case bfd_mach_z80n:
2736
  case bfd_mach_z80full:
2737
  case bfd_mach_r800:
2738
  case bfd_mach_gbz80:
2739
  case bfd_mach_z180:
2740
  case bfd_mach_ez80_z80:
2741
  case bfd_mach_ez80_adl:
2742
    *flagsp = bfd_get_mach (abfd) << 12;
2743
    break;
2744
  default:
2745
    return false;
2746
  }
2747
      return true;
2748
#endif
2749
2750
#ifdef Z8KMAGIC
2751
    case bfd_arch_z8k:
2752
      *magicp = Z8KMAGIC;
2753
2754
      switch (bfd_get_mach (abfd))
2755
  {
2756
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2757
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2758
  default:       return false;
2759
  }
2760
      return true;
2761
#endif
2762
2763
0
#ifdef TIC30MAGIC
2764
40
    case bfd_arch_tic30:
2765
40
      *magicp = TIC30MAGIC;
2766
40
      return true;
2767
0
#endif
2768
2769
#ifdef TICOFF_DEFAULT_MAGIC
2770
    case TICOFF_TARGET_ARCH:
2771
      /* If there's no indication of which version we want, use the default.  */
2772
      if (!abfd->xvec )
2773
  *magicp = TICOFF_DEFAULT_MAGIC;
2774
      else
2775
  {
2776
    /* We may want to output in a different COFF version.  */
2777
    switch (abfd->xvec->name[4])
2778
      {
2779
      case '0':
2780
        *magicp = TICOFF0MAGIC;
2781
        break;
2782
      case '1':
2783
        *magicp = TICOFF1MAGIC;
2784
        break;
2785
      case '2':
2786
        *magicp = TICOFF2MAGIC;
2787
        break;
2788
      default:
2789
        return false;
2790
      }
2791
  }
2792
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2793
      return true;
2794
#endif
2795
2796
#ifdef AARCH64MAGIC
2797
    case bfd_arch_aarch64:
2798
      * magicp = AARCH64MAGIC;
2799
      return true;
2800
#endif
2801
2802
#ifdef LOONGARCH64MAGIC
2803
    case bfd_arch_loongarch:
2804
      * magicp = LOONGARCH64MAGIC;
2805
      return true;
2806
#endif
2807
2808
#ifdef ARMMAGIC
2809
    case bfd_arch_arm:
2810
#ifdef ARM_WINCE
2811
      * magicp = ARMPEMAGIC;
2812
#else
2813
      * magicp = ARMMAGIC;
2814
#endif
2815
      * flagsp = 0;
2816
      if (APCS_SET (abfd))
2817
  {
2818
    if (APCS_26_FLAG (abfd))
2819
      * flagsp |= F_APCS26;
2820
2821
    if (APCS_FLOAT_FLAG (abfd))
2822
      * flagsp |= F_APCS_FLOAT;
2823
2824
    if (PIC_FLAG (abfd))
2825
      * flagsp |= F_PIC;
2826
  }
2827
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2828
  * flagsp |= F_INTERWORK;
2829
      switch (bfd_get_mach (abfd))
2830
  {
2831
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2832
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2833
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2834
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2835
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2836
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2837
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2838
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2839
       See also the comment in coff_set_arch_mach_hook().  */
2840
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2841
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2842
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2843
  }
2844
      return true;
2845
#endif
2846
2847
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2848
    case bfd_arch_i386:
2849
#if defined(I386MAGIC)
2850
      *magicp = I386MAGIC;
2851
#endif
2852
#if defined LYNXOS
2853
      /* Just overwrite the usual value if we're doing Lynx.  */
2854
      *magicp = LYNXCOFFMAGIC;
2855
#endif
2856
#if defined AMD64MAGIC
2857
      *magicp = AMD64MAGIC;
2858
#endif
2859
      return true;
2860
#endif
2861
2862
#ifdef IA64MAGIC
2863
    case bfd_arch_ia64:
2864
      *magicp = IA64MAGIC;
2865
      return true;
2866
#endif
2867
2868
#ifdef SH_ARCH_MAGIC_BIG
2869
    case bfd_arch_sh:
2870
#ifdef COFF_IMAGE_WITH_PE
2871
      *magicp = SH_ARCH_MAGIC_WINCE;
2872
#else
2873
      if (bfd_big_endian (abfd))
2874
  *magicp = SH_ARCH_MAGIC_BIG;
2875
      else
2876
  *magicp = SH_ARCH_MAGIC_LITTLE;
2877
#endif
2878
      return true;
2879
#endif
2880
2881
#ifdef MIPS_ARCH_MAGIC_WINCE
2882
    case bfd_arch_mips:
2883
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2884
      return true;
2885
#endif
2886
2887
#ifdef SPARCMAGIC
2888
    case bfd_arch_sparc:
2889
      *magicp = SPARCMAGIC;
2890
#ifdef LYNXOS
2891
      /* Just overwrite the usual value if we're doing Lynx.  */
2892
      *magicp = LYNXCOFFMAGIC;
2893
#endif
2894
      return true;
2895
#endif
2896
2897
#ifdef RS6000COFF_C
2898
    case bfd_arch_rs6000:
2899
    case bfd_arch_powerpc:
2900
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2901
      *magicp = bfd_xcoff_magic_number (abfd);
2902
      return true;
2903
#endif
2904
2905
#ifdef MCOREMAGIC
2906
    case bfd_arch_mcore:
2907
      * magicp = MCOREMAGIC;
2908
      return true;
2909
#endif
2910
2911
0
    default:      /* Unknown architecture.  */
2912
0
      break;
2913
40
    }
2914
2915
0
  return false;
2916
40
}
Unexecuted instantiation: coff-tic4x.c:coff_set_flags
coff-tic54x.c:coff_set_flags
Line
Count
Source
2725
68
{
2726
68
  switch (bfd_get_arch (abfd))
2727
68
    {
2728
#ifdef Z80MAGIC
2729
    case bfd_arch_z80:
2730
      *magicp = Z80MAGIC;
2731
      switch (bfd_get_mach (abfd))
2732
  {
2733
  case bfd_mach_z80strict:
2734
  case bfd_mach_z80:
2735
  case bfd_mach_z80n:
2736
  case bfd_mach_z80full:
2737
  case bfd_mach_r800:
2738
  case bfd_mach_gbz80:
2739
  case bfd_mach_z180:
2740
  case bfd_mach_ez80_z80:
2741
  case bfd_mach_ez80_adl:
2742
    *flagsp = bfd_get_mach (abfd) << 12;
2743
    break;
2744
  default:
2745
    return false;
2746
  }
2747
      return true;
2748
#endif
2749
2750
#ifdef Z8KMAGIC
2751
    case bfd_arch_z8k:
2752
      *magicp = Z8KMAGIC;
2753
2754
      switch (bfd_get_mach (abfd))
2755
  {
2756
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2757
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2758
  default:       return false;
2759
  }
2760
      return true;
2761
#endif
2762
2763
#ifdef TIC30MAGIC
2764
    case bfd_arch_tic30:
2765
      *magicp = TIC30MAGIC;
2766
      return true;
2767
#endif
2768
2769
0
#ifdef TICOFF_DEFAULT_MAGIC
2770
68
    case TICOFF_TARGET_ARCH:
2771
      /* If there's no indication of which version we want, use the default.  */
2772
68
      if (!abfd->xvec )
2773
0
  *magicp = TICOFF_DEFAULT_MAGIC;
2774
68
      else
2775
68
  {
2776
    /* We may want to output in a different COFF version.  */
2777
68
    switch (abfd->xvec->name[4])
2778
68
      {
2779
68
      case '0':
2780
68
        *magicp = TICOFF0MAGIC;
2781
68
        break;
2782
0
      case '1':
2783
0
        *magicp = TICOFF1MAGIC;
2784
0
        break;
2785
0
      case '2':
2786
0
        *magicp = TICOFF2MAGIC;
2787
0
        break;
2788
0
      default:
2789
0
        return false;
2790
68
      }
2791
68
  }
2792
68
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2793
68
      return true;
2794
0
#endif
2795
2796
#ifdef AARCH64MAGIC
2797
    case bfd_arch_aarch64:
2798
      * magicp = AARCH64MAGIC;
2799
      return true;
2800
#endif
2801
2802
#ifdef LOONGARCH64MAGIC
2803
    case bfd_arch_loongarch:
2804
      * magicp = LOONGARCH64MAGIC;
2805
      return true;
2806
#endif
2807
2808
#ifdef ARMMAGIC
2809
    case bfd_arch_arm:
2810
#ifdef ARM_WINCE
2811
      * magicp = ARMPEMAGIC;
2812
#else
2813
      * magicp = ARMMAGIC;
2814
#endif
2815
      * flagsp = 0;
2816
      if (APCS_SET (abfd))
2817
  {
2818
    if (APCS_26_FLAG (abfd))
2819
      * flagsp |= F_APCS26;
2820
2821
    if (APCS_FLOAT_FLAG (abfd))
2822
      * flagsp |= F_APCS_FLOAT;
2823
2824
    if (PIC_FLAG (abfd))
2825
      * flagsp |= F_PIC;
2826
  }
2827
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2828
  * flagsp |= F_INTERWORK;
2829
      switch (bfd_get_mach (abfd))
2830
  {
2831
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2832
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2833
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2834
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2835
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2836
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2837
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2838
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2839
       See also the comment in coff_set_arch_mach_hook().  */
2840
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2841
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2842
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2843
  }
2844
      return true;
2845
#endif
2846
2847
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2848
    case bfd_arch_i386:
2849
#if defined(I386MAGIC)
2850
      *magicp = I386MAGIC;
2851
#endif
2852
#if defined LYNXOS
2853
      /* Just overwrite the usual value if we're doing Lynx.  */
2854
      *magicp = LYNXCOFFMAGIC;
2855
#endif
2856
#if defined AMD64MAGIC
2857
      *magicp = AMD64MAGIC;
2858
#endif
2859
      return true;
2860
#endif
2861
2862
#ifdef IA64MAGIC
2863
    case bfd_arch_ia64:
2864
      *magicp = IA64MAGIC;
2865
      return true;
2866
#endif
2867
2868
#ifdef SH_ARCH_MAGIC_BIG
2869
    case bfd_arch_sh:
2870
#ifdef COFF_IMAGE_WITH_PE
2871
      *magicp = SH_ARCH_MAGIC_WINCE;
2872
#else
2873
      if (bfd_big_endian (abfd))
2874
  *magicp = SH_ARCH_MAGIC_BIG;
2875
      else
2876
  *magicp = SH_ARCH_MAGIC_LITTLE;
2877
#endif
2878
      return true;
2879
#endif
2880
2881
#ifdef MIPS_ARCH_MAGIC_WINCE
2882
    case bfd_arch_mips:
2883
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2884
      return true;
2885
#endif
2886
2887
#ifdef SPARCMAGIC
2888
    case bfd_arch_sparc:
2889
      *magicp = SPARCMAGIC;
2890
#ifdef LYNXOS
2891
      /* Just overwrite the usual value if we're doing Lynx.  */
2892
      *magicp = LYNXCOFFMAGIC;
2893
#endif
2894
      return true;
2895
#endif
2896
2897
#ifdef RS6000COFF_C
2898
    case bfd_arch_rs6000:
2899
    case bfd_arch_powerpc:
2900
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2901
      *magicp = bfd_xcoff_magic_number (abfd);
2902
      return true;
2903
#endif
2904
2905
#ifdef MCOREMAGIC
2906
    case bfd_arch_mcore:
2907
      * magicp = MCOREMAGIC;
2908
      return true;
2909
#endif
2910
2911
0
    default:      /* Unknown architecture.  */
2912
0
      break;
2913
68
    }
2914
2915
0
  return false;
2916
68
}
coff-z80.c:coff_set_flags
Line
Count
Source
2725
42
{
2726
42
  switch (bfd_get_arch (abfd))
2727
42
    {
2728
0
#ifdef Z80MAGIC
2729
42
    case bfd_arch_z80:
2730
42
      *magicp = Z80MAGIC;
2731
42
      switch (bfd_get_mach (abfd))
2732
42
  {
2733
0
  case bfd_mach_z80strict:
2734
0
  case bfd_mach_z80:
2735
0
  case bfd_mach_z80n:
2736
0
  case bfd_mach_z80full:
2737
0
  case bfd_mach_r800:
2738
0
  case bfd_mach_gbz80:
2739
6
  case bfd_mach_z180:
2740
40
  case bfd_mach_ez80_z80:
2741
42
  case bfd_mach_ez80_adl:
2742
42
    *flagsp = bfd_get_mach (abfd) << 12;
2743
42
    break;
2744
0
  default:
2745
0
    return false;
2746
42
  }
2747
42
      return true;
2748
0
#endif
2749
2750
#ifdef Z8KMAGIC
2751
    case bfd_arch_z8k:
2752
      *magicp = Z8KMAGIC;
2753
2754
      switch (bfd_get_mach (abfd))
2755
  {
2756
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2757
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2758
  default:       return false;
2759
  }
2760
      return true;
2761
#endif
2762
2763
#ifdef TIC30MAGIC
2764
    case bfd_arch_tic30:
2765
      *magicp = TIC30MAGIC;
2766
      return true;
2767
#endif
2768
2769
#ifdef TICOFF_DEFAULT_MAGIC
2770
    case TICOFF_TARGET_ARCH:
2771
      /* If there's no indication of which version we want, use the default.  */
2772
      if (!abfd->xvec )
2773
  *magicp = TICOFF_DEFAULT_MAGIC;
2774
      else
2775
  {
2776
    /* We may want to output in a different COFF version.  */
2777
    switch (abfd->xvec->name[4])
2778
      {
2779
      case '0':
2780
        *magicp = TICOFF0MAGIC;
2781
        break;
2782
      case '1':
2783
        *magicp = TICOFF1MAGIC;
2784
        break;
2785
      case '2':
2786
        *magicp = TICOFF2MAGIC;
2787
        break;
2788
      default:
2789
        return false;
2790
      }
2791
  }
2792
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2793
      return true;
2794
#endif
2795
2796
#ifdef AARCH64MAGIC
2797
    case bfd_arch_aarch64:
2798
      * magicp = AARCH64MAGIC;
2799
      return true;
2800
#endif
2801
2802
#ifdef LOONGARCH64MAGIC
2803
    case bfd_arch_loongarch:
2804
      * magicp = LOONGARCH64MAGIC;
2805
      return true;
2806
#endif
2807
2808
#ifdef ARMMAGIC
2809
    case bfd_arch_arm:
2810
#ifdef ARM_WINCE
2811
      * magicp = ARMPEMAGIC;
2812
#else
2813
      * magicp = ARMMAGIC;
2814
#endif
2815
      * flagsp = 0;
2816
      if (APCS_SET (abfd))
2817
  {
2818
    if (APCS_26_FLAG (abfd))
2819
      * flagsp |= F_APCS26;
2820
2821
    if (APCS_FLOAT_FLAG (abfd))
2822
      * flagsp |= F_APCS_FLOAT;
2823
2824
    if (PIC_FLAG (abfd))
2825
      * flagsp |= F_PIC;
2826
  }
2827
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2828
  * flagsp |= F_INTERWORK;
2829
      switch (bfd_get_mach (abfd))
2830
  {
2831
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2832
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2833
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2834
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2835
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2836
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2837
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2838
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2839
       See also the comment in coff_set_arch_mach_hook().  */
2840
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2841
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2842
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2843
  }
2844
      return true;
2845
#endif
2846
2847
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2848
    case bfd_arch_i386:
2849
#if defined(I386MAGIC)
2850
      *magicp = I386MAGIC;
2851
#endif
2852
#if defined LYNXOS
2853
      /* Just overwrite the usual value if we're doing Lynx.  */
2854
      *magicp = LYNXCOFFMAGIC;
2855
#endif
2856
#if defined AMD64MAGIC
2857
      *magicp = AMD64MAGIC;
2858
#endif
2859
      return true;
2860
#endif
2861
2862
#ifdef IA64MAGIC
2863
    case bfd_arch_ia64:
2864
      *magicp = IA64MAGIC;
2865
      return true;
2866
#endif
2867
2868
#ifdef SH_ARCH_MAGIC_BIG
2869
    case bfd_arch_sh:
2870
#ifdef COFF_IMAGE_WITH_PE
2871
      *magicp = SH_ARCH_MAGIC_WINCE;
2872
#else
2873
      if (bfd_big_endian (abfd))
2874
  *magicp = SH_ARCH_MAGIC_BIG;
2875
      else
2876
  *magicp = SH_ARCH_MAGIC_LITTLE;
2877
#endif
2878
      return true;
2879
#endif
2880
2881
#ifdef MIPS_ARCH_MAGIC_WINCE
2882
    case bfd_arch_mips:
2883
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2884
      return true;
2885
#endif
2886
2887
#ifdef SPARCMAGIC
2888
    case bfd_arch_sparc:
2889
      *magicp = SPARCMAGIC;
2890
#ifdef LYNXOS
2891
      /* Just overwrite the usual value if we're doing Lynx.  */
2892
      *magicp = LYNXCOFFMAGIC;
2893
#endif
2894
      return true;
2895
#endif
2896
2897
#ifdef RS6000COFF_C
2898
    case bfd_arch_rs6000:
2899
    case bfd_arch_powerpc:
2900
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2901
      *magicp = bfd_xcoff_magic_number (abfd);
2902
      return true;
2903
#endif
2904
2905
#ifdef MCOREMAGIC
2906
    case bfd_arch_mcore:
2907
      * magicp = MCOREMAGIC;
2908
      return true;
2909
#endif
2910
2911
0
    default:      /* Unknown architecture.  */
2912
0
      break;
2913
42
    }
2914
2915
0
  return false;
2916
42
}
coff-z8k.c:coff_set_flags
Line
Count
Source
2725
52
{
2726
52
  switch (bfd_get_arch (abfd))
2727
52
    {
2728
#ifdef Z80MAGIC
2729
    case bfd_arch_z80:
2730
      *magicp = Z80MAGIC;
2731
      switch (bfd_get_mach (abfd))
2732
  {
2733
  case bfd_mach_z80strict:
2734
  case bfd_mach_z80:
2735
  case bfd_mach_z80n:
2736
  case bfd_mach_z80full:
2737
  case bfd_mach_r800:
2738
  case bfd_mach_gbz80:
2739
  case bfd_mach_z180:
2740
  case bfd_mach_ez80_z80:
2741
  case bfd_mach_ez80_adl:
2742
    *flagsp = bfd_get_mach (abfd) << 12;
2743
    break;
2744
  default:
2745
    return false;
2746
  }
2747
      return true;
2748
#endif
2749
2750
0
#ifdef Z8KMAGIC
2751
52
    case bfd_arch_z8k:
2752
52
      *magicp = Z8KMAGIC;
2753
2754
52
      switch (bfd_get_mach (abfd))
2755
52
  {
2756
11
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2757
41
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2758
0
  default:       return false;
2759
52
  }
2760
52
      return true;
2761
0
#endif
2762
2763
#ifdef TIC30MAGIC
2764
    case bfd_arch_tic30:
2765
      *magicp = TIC30MAGIC;
2766
      return true;
2767
#endif
2768
2769
#ifdef TICOFF_DEFAULT_MAGIC
2770
    case TICOFF_TARGET_ARCH:
2771
      /* If there's no indication of which version we want, use the default.  */
2772
      if (!abfd->xvec )
2773
  *magicp = TICOFF_DEFAULT_MAGIC;
2774
      else
2775
  {
2776
    /* We may want to output in a different COFF version.  */
2777
    switch (abfd->xvec->name[4])
2778
      {
2779
      case '0':
2780
        *magicp = TICOFF0MAGIC;
2781
        break;
2782
      case '1':
2783
        *magicp = TICOFF1MAGIC;
2784
        break;
2785
      case '2':
2786
        *magicp = TICOFF2MAGIC;
2787
        break;
2788
      default:
2789
        return false;
2790
      }
2791
  }
2792
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2793
      return true;
2794
#endif
2795
2796
#ifdef AARCH64MAGIC
2797
    case bfd_arch_aarch64:
2798
      * magicp = AARCH64MAGIC;
2799
      return true;
2800
#endif
2801
2802
#ifdef LOONGARCH64MAGIC
2803
    case bfd_arch_loongarch:
2804
      * magicp = LOONGARCH64MAGIC;
2805
      return true;
2806
#endif
2807
2808
#ifdef ARMMAGIC
2809
    case bfd_arch_arm:
2810
#ifdef ARM_WINCE
2811
      * magicp = ARMPEMAGIC;
2812
#else
2813
      * magicp = ARMMAGIC;
2814
#endif
2815
      * flagsp = 0;
2816
      if (APCS_SET (abfd))
2817
  {
2818
    if (APCS_26_FLAG (abfd))
2819
      * flagsp |= F_APCS26;
2820
2821
    if (APCS_FLOAT_FLAG (abfd))
2822
      * flagsp |= F_APCS_FLOAT;
2823
2824
    if (PIC_FLAG (abfd))
2825
      * flagsp |= F_PIC;
2826
  }
2827
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2828
  * flagsp |= F_INTERWORK;
2829
      switch (bfd_get_mach (abfd))
2830
  {
2831
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2832
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2833
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2834
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2835
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2836
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2837
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2838
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2839
       See also the comment in coff_set_arch_mach_hook().  */
2840
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2841
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2842
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2843
  }
2844
      return true;
2845
#endif
2846
2847
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2848
    case bfd_arch_i386:
2849
#if defined(I386MAGIC)
2850
      *magicp = I386MAGIC;
2851
#endif
2852
#if defined LYNXOS
2853
      /* Just overwrite the usual value if we're doing Lynx.  */
2854
      *magicp = LYNXCOFFMAGIC;
2855
#endif
2856
#if defined AMD64MAGIC
2857
      *magicp = AMD64MAGIC;
2858
#endif
2859
      return true;
2860
#endif
2861
2862
#ifdef IA64MAGIC
2863
    case bfd_arch_ia64:
2864
      *magicp = IA64MAGIC;
2865
      return true;
2866
#endif
2867
2868
#ifdef SH_ARCH_MAGIC_BIG
2869
    case bfd_arch_sh:
2870
#ifdef COFF_IMAGE_WITH_PE
2871
      *magicp = SH_ARCH_MAGIC_WINCE;
2872
#else
2873
      if (bfd_big_endian (abfd))
2874
  *magicp = SH_ARCH_MAGIC_BIG;
2875
      else
2876
  *magicp = SH_ARCH_MAGIC_LITTLE;
2877
#endif
2878
      return true;
2879
#endif
2880
2881
#ifdef MIPS_ARCH_MAGIC_WINCE
2882
    case bfd_arch_mips:
2883
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2884
      return true;
2885
#endif
2886
2887
#ifdef SPARCMAGIC
2888
    case bfd_arch_sparc:
2889
      *magicp = SPARCMAGIC;
2890
#ifdef LYNXOS
2891
      /* Just overwrite the usual value if we're doing Lynx.  */
2892
      *magicp = LYNXCOFFMAGIC;
2893
#endif
2894
      return true;
2895
#endif
2896
2897
#ifdef RS6000COFF_C
2898
    case bfd_arch_rs6000:
2899
    case bfd_arch_powerpc:
2900
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2901
      *magicp = bfd_xcoff_magic_number (abfd);
2902
      return true;
2903
#endif
2904
2905
#ifdef MCOREMAGIC
2906
    case bfd_arch_mcore:
2907
      * magicp = MCOREMAGIC;
2908
      return true;
2909
#endif
2910
2911
0
    default:      /* Unknown architecture.  */
2912
0
      break;
2913
52
    }
2914
2915
0
  return false;
2916
52
}
Unexecuted instantiation: pe-arm-wince.c:coff_set_flags
Unexecuted instantiation: pe-arm.c:coff_set_flags
pe-i386.c:coff_set_flags
Line
Count
Source
2725
54
{
2726
54
  switch (bfd_get_arch (abfd))
2727
54
    {
2728
#ifdef Z80MAGIC
2729
    case bfd_arch_z80:
2730
      *magicp = Z80MAGIC;
2731
      switch (bfd_get_mach (abfd))
2732
  {
2733
  case bfd_mach_z80strict:
2734
  case bfd_mach_z80:
2735
  case bfd_mach_z80n:
2736
  case bfd_mach_z80full:
2737
  case bfd_mach_r800:
2738
  case bfd_mach_gbz80:
2739
  case bfd_mach_z180:
2740
  case bfd_mach_ez80_z80:
2741
  case bfd_mach_ez80_adl:
2742
    *flagsp = bfd_get_mach (abfd) << 12;
2743
    break;
2744
  default:
2745
    return false;
2746
  }
2747
      return true;
2748
#endif
2749
2750
#ifdef Z8KMAGIC
2751
    case bfd_arch_z8k:
2752
      *magicp = Z8KMAGIC;
2753
2754
      switch (bfd_get_mach (abfd))
2755
  {
2756
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2757
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2758
  default:       return false;
2759
  }
2760
      return true;
2761
#endif
2762
2763
#ifdef TIC30MAGIC
2764
    case bfd_arch_tic30:
2765
      *magicp = TIC30MAGIC;
2766
      return true;
2767
#endif
2768
2769
#ifdef TICOFF_DEFAULT_MAGIC
2770
    case TICOFF_TARGET_ARCH:
2771
      /* If there's no indication of which version we want, use the default.  */
2772
      if (!abfd->xvec )
2773
  *magicp = TICOFF_DEFAULT_MAGIC;
2774
      else
2775
  {
2776
    /* We may want to output in a different COFF version.  */
2777
    switch (abfd->xvec->name[4])
2778
      {
2779
      case '0':
2780
        *magicp = TICOFF0MAGIC;
2781
        break;
2782
      case '1':
2783
        *magicp = TICOFF1MAGIC;
2784
        break;
2785
      case '2':
2786
        *magicp = TICOFF2MAGIC;
2787
        break;
2788
      default:
2789
        return false;
2790
      }
2791
  }
2792
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2793
      return true;
2794
#endif
2795
2796
#ifdef AARCH64MAGIC
2797
    case bfd_arch_aarch64:
2798
      * magicp = AARCH64MAGIC;
2799
      return true;
2800
#endif
2801
2802
#ifdef LOONGARCH64MAGIC
2803
    case bfd_arch_loongarch:
2804
      * magicp = LOONGARCH64MAGIC;
2805
      return true;
2806
#endif
2807
2808
#ifdef ARMMAGIC
2809
    case bfd_arch_arm:
2810
#ifdef ARM_WINCE
2811
      * magicp = ARMPEMAGIC;
2812
#else
2813
      * magicp = ARMMAGIC;
2814
#endif
2815
      * flagsp = 0;
2816
      if (APCS_SET (abfd))
2817
  {
2818
    if (APCS_26_FLAG (abfd))
2819
      * flagsp |= F_APCS26;
2820
2821
    if (APCS_FLOAT_FLAG (abfd))
2822
      * flagsp |= F_APCS_FLOAT;
2823
2824
    if (PIC_FLAG (abfd))
2825
      * flagsp |= F_PIC;
2826
  }
2827
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2828
  * flagsp |= F_INTERWORK;
2829
      switch (bfd_get_mach (abfd))
2830
  {
2831
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2832
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2833
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2834
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2835
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2836
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2837
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2838
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2839
       See also the comment in coff_set_arch_mach_hook().  */
2840
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2841
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2842
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2843
  }
2844
      return true;
2845
#endif
2846
2847
0
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2848
54
    case bfd_arch_i386:
2849
54
#if defined(I386MAGIC)
2850
54
      *magicp = I386MAGIC;
2851
54
#endif
2852
#if defined LYNXOS
2853
      /* Just overwrite the usual value if we're doing Lynx.  */
2854
      *magicp = LYNXCOFFMAGIC;
2855
#endif
2856
#if defined AMD64MAGIC
2857
      *magicp = AMD64MAGIC;
2858
#endif
2859
54
      return true;
2860
0
#endif
2861
2862
#ifdef IA64MAGIC
2863
    case bfd_arch_ia64:
2864
      *magicp = IA64MAGIC;
2865
      return true;
2866
#endif
2867
2868
#ifdef SH_ARCH_MAGIC_BIG
2869
    case bfd_arch_sh:
2870
#ifdef COFF_IMAGE_WITH_PE
2871
      *magicp = SH_ARCH_MAGIC_WINCE;
2872
#else
2873
      if (bfd_big_endian (abfd))
2874
  *magicp = SH_ARCH_MAGIC_BIG;
2875
      else
2876
  *magicp = SH_ARCH_MAGIC_LITTLE;
2877
#endif
2878
      return true;
2879
#endif
2880
2881
#ifdef MIPS_ARCH_MAGIC_WINCE
2882
    case bfd_arch_mips:
2883
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2884
      return true;
2885
#endif
2886
2887
#ifdef SPARCMAGIC
2888
    case bfd_arch_sparc:
2889
      *magicp = SPARCMAGIC;
2890
#ifdef LYNXOS
2891
      /* Just overwrite the usual value if we're doing Lynx.  */
2892
      *magicp = LYNXCOFFMAGIC;
2893
#endif
2894
      return true;
2895
#endif
2896
2897
#ifdef RS6000COFF_C
2898
    case bfd_arch_rs6000:
2899
    case bfd_arch_powerpc:
2900
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2901
      *magicp = bfd_xcoff_magic_number (abfd);
2902
      return true;
2903
#endif
2904
2905
#ifdef MCOREMAGIC
2906
    case bfd_arch_mcore:
2907
      * magicp = MCOREMAGIC;
2908
      return true;
2909
#endif
2910
2911
0
    default:      /* Unknown architecture.  */
2912
0
      break;
2913
54
    }
2914
2915
0
  return false;
2916
54
}
pe-mcore.c:coff_set_flags
Line
Count
Source
2725
39
{
2726
39
  switch (bfd_get_arch (abfd))
2727
39
    {
2728
#ifdef Z80MAGIC
2729
    case bfd_arch_z80:
2730
      *magicp = Z80MAGIC;
2731
      switch (bfd_get_mach (abfd))
2732
  {
2733
  case bfd_mach_z80strict:
2734
  case bfd_mach_z80:
2735
  case bfd_mach_z80n:
2736
  case bfd_mach_z80full:
2737
  case bfd_mach_r800:
2738
  case bfd_mach_gbz80:
2739
  case bfd_mach_z180:
2740
  case bfd_mach_ez80_z80:
2741
  case bfd_mach_ez80_adl:
2742
    *flagsp = bfd_get_mach (abfd) << 12;
2743
    break;
2744
  default:
2745
    return false;
2746
  }
2747
      return true;
2748
#endif
2749
2750
#ifdef Z8KMAGIC
2751
    case bfd_arch_z8k:
2752
      *magicp = Z8KMAGIC;
2753
2754
      switch (bfd_get_mach (abfd))
2755
  {
2756
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2757
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2758
  default:       return false;
2759
  }
2760
      return true;
2761
#endif
2762
2763
#ifdef TIC30MAGIC
2764
    case bfd_arch_tic30:
2765
      *magicp = TIC30MAGIC;
2766
      return true;
2767
#endif
2768
2769
#ifdef TICOFF_DEFAULT_MAGIC
2770
    case TICOFF_TARGET_ARCH:
2771
      /* If there's no indication of which version we want, use the default.  */
2772
      if (!abfd->xvec )
2773
  *magicp = TICOFF_DEFAULT_MAGIC;
2774
      else
2775
  {
2776
    /* We may want to output in a different COFF version.  */
2777
    switch (abfd->xvec->name[4])
2778
      {
2779
      case '0':
2780
        *magicp = TICOFF0MAGIC;
2781
        break;
2782
      case '1':
2783
        *magicp = TICOFF1MAGIC;
2784
        break;
2785
      case '2':
2786
        *magicp = TICOFF2MAGIC;
2787
        break;
2788
      default:
2789
        return false;
2790
      }
2791
  }
2792
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2793
      return true;
2794
#endif
2795
2796
#ifdef AARCH64MAGIC
2797
    case bfd_arch_aarch64:
2798
      * magicp = AARCH64MAGIC;
2799
      return true;
2800
#endif
2801
2802
#ifdef LOONGARCH64MAGIC
2803
    case bfd_arch_loongarch:
2804
      * magicp = LOONGARCH64MAGIC;
2805
      return true;
2806
#endif
2807
2808
#ifdef ARMMAGIC
2809
    case bfd_arch_arm:
2810
#ifdef ARM_WINCE
2811
      * magicp = ARMPEMAGIC;
2812
#else
2813
      * magicp = ARMMAGIC;
2814
#endif
2815
      * flagsp = 0;
2816
      if (APCS_SET (abfd))
2817
  {
2818
    if (APCS_26_FLAG (abfd))
2819
      * flagsp |= F_APCS26;
2820
2821
    if (APCS_FLOAT_FLAG (abfd))
2822
      * flagsp |= F_APCS_FLOAT;
2823
2824
    if (PIC_FLAG (abfd))
2825
      * flagsp |= F_PIC;
2826
  }
2827
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2828
  * flagsp |= F_INTERWORK;
2829
      switch (bfd_get_mach (abfd))
2830
  {
2831
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2832
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2833
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2834
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2835
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2836
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2837
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2838
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2839
       See also the comment in coff_set_arch_mach_hook().  */
2840
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2841
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2842
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2843
  }
2844
      return true;
2845
#endif
2846
2847
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2848
    case bfd_arch_i386:
2849
#if defined(I386MAGIC)
2850
      *magicp = I386MAGIC;
2851
#endif
2852
#if defined LYNXOS
2853
      /* Just overwrite the usual value if we're doing Lynx.  */
2854
      *magicp = LYNXCOFFMAGIC;
2855
#endif
2856
#if defined AMD64MAGIC
2857
      *magicp = AMD64MAGIC;
2858
#endif
2859
      return true;
2860
#endif
2861
2862
#ifdef IA64MAGIC
2863
    case bfd_arch_ia64:
2864
      *magicp = IA64MAGIC;
2865
      return true;
2866
#endif
2867
2868
#ifdef SH_ARCH_MAGIC_BIG
2869
    case bfd_arch_sh:
2870
#ifdef COFF_IMAGE_WITH_PE
2871
      *magicp = SH_ARCH_MAGIC_WINCE;
2872
#else
2873
      if (bfd_big_endian (abfd))
2874
  *magicp = SH_ARCH_MAGIC_BIG;
2875
      else
2876
  *magicp = SH_ARCH_MAGIC_LITTLE;
2877
#endif
2878
      return true;
2879
#endif
2880
2881
#ifdef MIPS_ARCH_MAGIC_WINCE
2882
    case bfd_arch_mips:
2883
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2884
      return true;
2885
#endif
2886
2887
#ifdef SPARCMAGIC
2888
    case bfd_arch_sparc:
2889
      *magicp = SPARCMAGIC;
2890
#ifdef LYNXOS
2891
      /* Just overwrite the usual value if we're doing Lynx.  */
2892
      *magicp = LYNXCOFFMAGIC;
2893
#endif
2894
      return true;
2895
#endif
2896
2897
#ifdef RS6000COFF_C
2898
    case bfd_arch_rs6000:
2899
    case bfd_arch_powerpc:
2900
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2901
      *magicp = bfd_xcoff_magic_number (abfd);
2902
      return true;
2903
#endif
2904
2905
0
#ifdef MCOREMAGIC
2906
39
    case bfd_arch_mcore:
2907
39
      * magicp = MCOREMAGIC;
2908
39
      return true;
2909
0
#endif
2910
2911
0
    default:      /* Unknown architecture.  */
2912
0
      break;
2913
39
    }
2914
2915
0
  return false;
2916
39
}
pe-sh.c:coff_set_flags
Line
Count
Source
2725
32
{
2726
32
  switch (bfd_get_arch (abfd))
2727
32
    {
2728
#ifdef Z80MAGIC
2729
    case bfd_arch_z80:
2730
      *magicp = Z80MAGIC;
2731
      switch (bfd_get_mach (abfd))
2732
  {
2733
  case bfd_mach_z80strict:
2734
  case bfd_mach_z80:
2735
  case bfd_mach_z80n:
2736
  case bfd_mach_z80full:
2737
  case bfd_mach_r800:
2738
  case bfd_mach_gbz80:
2739
  case bfd_mach_z180:
2740
  case bfd_mach_ez80_z80:
2741
  case bfd_mach_ez80_adl:
2742
    *flagsp = bfd_get_mach (abfd) << 12;
2743
    break;
2744
  default:
2745
    return false;
2746
  }
2747
      return true;
2748
#endif
2749
2750
#ifdef Z8KMAGIC
2751
    case bfd_arch_z8k:
2752
      *magicp = Z8KMAGIC;
2753
2754
      switch (bfd_get_mach (abfd))
2755
  {
2756
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2757
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2758
  default:       return false;
2759
  }
2760
      return true;
2761
#endif
2762
2763
#ifdef TIC30MAGIC
2764
    case bfd_arch_tic30:
2765
      *magicp = TIC30MAGIC;
2766
      return true;
2767
#endif
2768
2769
#ifdef TICOFF_DEFAULT_MAGIC
2770
    case TICOFF_TARGET_ARCH:
2771
      /* If there's no indication of which version we want, use the default.  */
2772
      if (!abfd->xvec )
2773
  *magicp = TICOFF_DEFAULT_MAGIC;
2774
      else
2775
  {
2776
    /* We may want to output in a different COFF version.  */
2777
    switch (abfd->xvec->name[4])
2778
      {
2779
      case '0':
2780
        *magicp = TICOFF0MAGIC;
2781
        break;
2782
      case '1':
2783
        *magicp = TICOFF1MAGIC;
2784
        break;
2785
      case '2':
2786
        *magicp = TICOFF2MAGIC;
2787
        break;
2788
      default:
2789
        return false;
2790
      }
2791
  }
2792
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2793
      return true;
2794
#endif
2795
2796
#ifdef AARCH64MAGIC
2797
    case bfd_arch_aarch64:
2798
      * magicp = AARCH64MAGIC;
2799
      return true;
2800
#endif
2801
2802
#ifdef LOONGARCH64MAGIC
2803
    case bfd_arch_loongarch:
2804
      * magicp = LOONGARCH64MAGIC;
2805
      return true;
2806
#endif
2807
2808
#ifdef ARMMAGIC
2809
    case bfd_arch_arm:
2810
#ifdef ARM_WINCE
2811
      * magicp = ARMPEMAGIC;
2812
#else
2813
      * magicp = ARMMAGIC;
2814
#endif
2815
      * flagsp = 0;
2816
      if (APCS_SET (abfd))
2817
  {
2818
    if (APCS_26_FLAG (abfd))
2819
      * flagsp |= F_APCS26;
2820
2821
    if (APCS_FLOAT_FLAG (abfd))
2822
      * flagsp |= F_APCS_FLOAT;
2823
2824
    if (PIC_FLAG (abfd))
2825
      * flagsp |= F_PIC;
2826
  }
2827
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2828
  * flagsp |= F_INTERWORK;
2829
      switch (bfd_get_mach (abfd))
2830
  {
2831
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2832
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2833
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2834
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2835
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2836
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2837
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2838
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2839
       See also the comment in coff_set_arch_mach_hook().  */
2840
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2841
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2842
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2843
  }
2844
      return true;
2845
#endif
2846
2847
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2848
    case bfd_arch_i386:
2849
#if defined(I386MAGIC)
2850
      *magicp = I386MAGIC;
2851
#endif
2852
#if defined LYNXOS
2853
      /* Just overwrite the usual value if we're doing Lynx.  */
2854
      *magicp = LYNXCOFFMAGIC;
2855
#endif
2856
#if defined AMD64MAGIC
2857
      *magicp = AMD64MAGIC;
2858
#endif
2859
      return true;
2860
#endif
2861
2862
#ifdef IA64MAGIC
2863
    case bfd_arch_ia64:
2864
      *magicp = IA64MAGIC;
2865
      return true;
2866
#endif
2867
2868
0
#ifdef SH_ARCH_MAGIC_BIG
2869
32
    case bfd_arch_sh:
2870
#ifdef COFF_IMAGE_WITH_PE
2871
      *magicp = SH_ARCH_MAGIC_WINCE;
2872
#else
2873
32
      if (bfd_big_endian (abfd))
2874
0
  *magicp = SH_ARCH_MAGIC_BIG;
2875
32
      else
2876
32
  *magicp = SH_ARCH_MAGIC_LITTLE;
2877
32
#endif
2878
32
      return true;
2879
0
#endif
2880
2881
#ifdef MIPS_ARCH_MAGIC_WINCE
2882
    case bfd_arch_mips:
2883
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2884
      return true;
2885
#endif
2886
2887
#ifdef SPARCMAGIC
2888
    case bfd_arch_sparc:
2889
      *magicp = SPARCMAGIC;
2890
#ifdef LYNXOS
2891
      /* Just overwrite the usual value if we're doing Lynx.  */
2892
      *magicp = LYNXCOFFMAGIC;
2893
#endif
2894
      return true;
2895
#endif
2896
2897
#ifdef RS6000COFF_C
2898
    case bfd_arch_rs6000:
2899
    case bfd_arch_powerpc:
2900
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2901
      *magicp = bfd_xcoff_magic_number (abfd);
2902
      return true;
2903
#endif
2904
2905
#ifdef MCOREMAGIC
2906
    case bfd_arch_mcore:
2907
      * magicp = MCOREMAGIC;
2908
      return true;
2909
#endif
2910
2911
0
    default:      /* Unknown architecture.  */
2912
0
      break;
2913
32
    }
2914
2915
0
  return false;
2916
32
}
pei-arm-wince.c:coff_set_flags
Line
Count
Source
2725
6
{
2726
6
  switch (bfd_get_arch (abfd))
2727
6
    {
2728
#ifdef Z80MAGIC
2729
    case bfd_arch_z80:
2730
      *magicp = Z80MAGIC;
2731
      switch (bfd_get_mach (abfd))
2732
  {
2733
  case bfd_mach_z80strict:
2734
  case bfd_mach_z80:
2735
  case bfd_mach_z80n:
2736
  case bfd_mach_z80full:
2737
  case bfd_mach_r800:
2738
  case bfd_mach_gbz80:
2739
  case bfd_mach_z180:
2740
  case bfd_mach_ez80_z80:
2741
  case bfd_mach_ez80_adl:
2742
    *flagsp = bfd_get_mach (abfd) << 12;
2743
    break;
2744
  default:
2745
    return false;
2746
  }
2747
      return true;
2748
#endif
2749
2750
#ifdef Z8KMAGIC
2751
    case bfd_arch_z8k:
2752
      *magicp = Z8KMAGIC;
2753
2754
      switch (bfd_get_mach (abfd))
2755
  {
2756
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2757
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2758
  default:       return false;
2759
  }
2760
      return true;
2761
#endif
2762
2763
#ifdef TIC30MAGIC
2764
    case bfd_arch_tic30:
2765
      *magicp = TIC30MAGIC;
2766
      return true;
2767
#endif
2768
2769
#ifdef TICOFF_DEFAULT_MAGIC
2770
    case TICOFF_TARGET_ARCH:
2771
      /* If there's no indication of which version we want, use the default.  */
2772
      if (!abfd->xvec )
2773
  *magicp = TICOFF_DEFAULT_MAGIC;
2774
      else
2775
  {
2776
    /* We may want to output in a different COFF version.  */
2777
    switch (abfd->xvec->name[4])
2778
      {
2779
      case '0':
2780
        *magicp = TICOFF0MAGIC;
2781
        break;
2782
      case '1':
2783
        *magicp = TICOFF1MAGIC;
2784
        break;
2785
      case '2':
2786
        *magicp = TICOFF2MAGIC;
2787
        break;
2788
      default:
2789
        return false;
2790
      }
2791
  }
2792
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2793
      return true;
2794
#endif
2795
2796
#ifdef AARCH64MAGIC
2797
    case bfd_arch_aarch64:
2798
      * magicp = AARCH64MAGIC;
2799
      return true;
2800
#endif
2801
2802
#ifdef LOONGARCH64MAGIC
2803
    case bfd_arch_loongarch:
2804
      * magicp = LOONGARCH64MAGIC;
2805
      return true;
2806
#endif
2807
2808
0
#ifdef ARMMAGIC
2809
6
    case bfd_arch_arm:
2810
#ifdef ARM_WINCE
2811
      * magicp = ARMPEMAGIC;
2812
#else
2813
6
      * magicp = ARMMAGIC;
2814
6
#endif
2815
6
      * flagsp = 0;
2816
6
      if (APCS_SET (abfd))
2817
1
  {
2818
1
    if (APCS_26_FLAG (abfd))
2819
0
      * flagsp |= F_APCS26;
2820
2821
1
    if (APCS_FLOAT_FLAG (abfd))
2822
0
      * flagsp |= F_APCS_FLOAT;
2823
2824
1
    if (PIC_FLAG (abfd))
2825
0
      * flagsp |= F_PIC;
2826
1
  }
2827
6
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2828
0
  * flagsp |= F_INTERWORK;
2829
6
      switch (bfd_get_mach (abfd))
2830
6
  {
2831
2
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2832
0
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2833
0
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2834
0
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2835
0
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2836
0
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2837
0
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2838
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2839
       See also the comment in coff_set_arch_mach_hook().  */
2840
0
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2841
0
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2842
4
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2843
6
  }
2844
6
      return true;
2845
0
#endif
2846
2847
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2848
    case bfd_arch_i386:
2849
#if defined(I386MAGIC)
2850
      *magicp = I386MAGIC;
2851
#endif
2852
#if defined LYNXOS
2853
      /* Just overwrite the usual value if we're doing Lynx.  */
2854
      *magicp = LYNXCOFFMAGIC;
2855
#endif
2856
#if defined AMD64MAGIC
2857
      *magicp = AMD64MAGIC;
2858
#endif
2859
      return true;
2860
#endif
2861
2862
#ifdef IA64MAGIC
2863
    case bfd_arch_ia64:
2864
      *magicp = IA64MAGIC;
2865
      return true;
2866
#endif
2867
2868
#ifdef SH_ARCH_MAGIC_BIG
2869
    case bfd_arch_sh:
2870
#ifdef COFF_IMAGE_WITH_PE
2871
      *magicp = SH_ARCH_MAGIC_WINCE;
2872
#else
2873
      if (bfd_big_endian (abfd))
2874
  *magicp = SH_ARCH_MAGIC_BIG;
2875
      else
2876
  *magicp = SH_ARCH_MAGIC_LITTLE;
2877
#endif
2878
      return true;
2879
#endif
2880
2881
#ifdef MIPS_ARCH_MAGIC_WINCE
2882
    case bfd_arch_mips:
2883
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2884
      return true;
2885
#endif
2886
2887
#ifdef SPARCMAGIC
2888
    case bfd_arch_sparc:
2889
      *magicp = SPARCMAGIC;
2890
#ifdef LYNXOS
2891
      /* Just overwrite the usual value if we're doing Lynx.  */
2892
      *magicp = LYNXCOFFMAGIC;
2893
#endif
2894
      return true;
2895
#endif
2896
2897
#ifdef RS6000COFF_C
2898
    case bfd_arch_rs6000:
2899
    case bfd_arch_powerpc:
2900
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2901
      *magicp = bfd_xcoff_magic_number (abfd);
2902
      return true;
2903
#endif
2904
2905
#ifdef MCOREMAGIC
2906
    case bfd_arch_mcore:
2907
      * magicp = MCOREMAGIC;
2908
      return true;
2909
#endif
2910
2911
0
    default:      /* Unknown architecture.  */
2912
0
      break;
2913
6
    }
2914
2915
0
  return false;
2916
6
}
pei-arm.c:coff_set_flags
Line
Count
Source
2725
7
{
2726
7
  switch (bfd_get_arch (abfd))
2727
7
    {
2728
#ifdef Z80MAGIC
2729
    case bfd_arch_z80:
2730
      *magicp = Z80MAGIC;
2731
      switch (bfd_get_mach (abfd))
2732
  {
2733
  case bfd_mach_z80strict:
2734
  case bfd_mach_z80:
2735
  case bfd_mach_z80n:
2736
  case bfd_mach_z80full:
2737
  case bfd_mach_r800:
2738
  case bfd_mach_gbz80:
2739
  case bfd_mach_z180:
2740
  case bfd_mach_ez80_z80:
2741
  case bfd_mach_ez80_adl:
2742
    *flagsp = bfd_get_mach (abfd) << 12;
2743
    break;
2744
  default:
2745
    return false;
2746
  }
2747
      return true;
2748
#endif
2749
2750
#ifdef Z8KMAGIC
2751
    case bfd_arch_z8k:
2752
      *magicp = Z8KMAGIC;
2753
2754
      switch (bfd_get_mach (abfd))
2755
  {
2756
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2757
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2758
  default:       return false;
2759
  }
2760
      return true;
2761
#endif
2762
2763
#ifdef TIC30MAGIC
2764
    case bfd_arch_tic30:
2765
      *magicp = TIC30MAGIC;
2766
      return true;
2767
#endif
2768
2769
#ifdef TICOFF_DEFAULT_MAGIC
2770
    case TICOFF_TARGET_ARCH:
2771
      /* If there's no indication of which version we want, use the default.  */
2772
      if (!abfd->xvec )
2773
  *magicp = TICOFF_DEFAULT_MAGIC;
2774
      else
2775
  {
2776
    /* We may want to output in a different COFF version.  */
2777
    switch (abfd->xvec->name[4])
2778
      {
2779
      case '0':
2780
        *magicp = TICOFF0MAGIC;
2781
        break;
2782
      case '1':
2783
        *magicp = TICOFF1MAGIC;
2784
        break;
2785
      case '2':
2786
        *magicp = TICOFF2MAGIC;
2787
        break;
2788
      default:
2789
        return false;
2790
      }
2791
  }
2792
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2793
      return true;
2794
#endif
2795
2796
#ifdef AARCH64MAGIC
2797
    case bfd_arch_aarch64:
2798
      * magicp = AARCH64MAGIC;
2799
      return true;
2800
#endif
2801
2802
#ifdef LOONGARCH64MAGIC
2803
    case bfd_arch_loongarch:
2804
      * magicp = LOONGARCH64MAGIC;
2805
      return true;
2806
#endif
2807
2808
0
#ifdef ARMMAGIC
2809
7
    case bfd_arch_arm:
2810
#ifdef ARM_WINCE
2811
      * magicp = ARMPEMAGIC;
2812
#else
2813
7
      * magicp = ARMMAGIC;
2814
7
#endif
2815
7
      * flagsp = 0;
2816
7
      if (APCS_SET (abfd))
2817
0
  {
2818
0
    if (APCS_26_FLAG (abfd))
2819
0
      * flagsp |= F_APCS26;
2820
2821
0
    if (APCS_FLOAT_FLAG (abfd))
2822
0
      * flagsp |= F_APCS_FLOAT;
2823
2824
0
    if (PIC_FLAG (abfd))
2825
0
      * flagsp |= F_PIC;
2826
0
  }
2827
7
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2828
0
  * flagsp |= F_INTERWORK;
2829
7
      switch (bfd_get_mach (abfd))
2830
7
  {
2831
1
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2832
0
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2833
0
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2834
1
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2835
0
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2836
0
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2837
0
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2838
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2839
       See also the comment in coff_set_arch_mach_hook().  */
2840
0
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2841
0
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2842
5
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2843
7
  }
2844
7
      return true;
2845
0
#endif
2846
2847
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2848
    case bfd_arch_i386:
2849
#if defined(I386MAGIC)
2850
      *magicp = I386MAGIC;
2851
#endif
2852
#if defined LYNXOS
2853
      /* Just overwrite the usual value if we're doing Lynx.  */
2854
      *magicp = LYNXCOFFMAGIC;
2855
#endif
2856
#if defined AMD64MAGIC
2857
      *magicp = AMD64MAGIC;
2858
#endif
2859
      return true;
2860
#endif
2861
2862
#ifdef IA64MAGIC
2863
    case bfd_arch_ia64:
2864
      *magicp = IA64MAGIC;
2865
      return true;
2866
#endif
2867
2868
#ifdef SH_ARCH_MAGIC_BIG
2869
    case bfd_arch_sh:
2870
#ifdef COFF_IMAGE_WITH_PE
2871
      *magicp = SH_ARCH_MAGIC_WINCE;
2872
#else
2873
      if (bfd_big_endian (abfd))
2874
  *magicp = SH_ARCH_MAGIC_BIG;
2875
      else
2876
  *magicp = SH_ARCH_MAGIC_LITTLE;
2877
#endif
2878
      return true;
2879
#endif
2880
2881
#ifdef MIPS_ARCH_MAGIC_WINCE
2882
    case bfd_arch_mips:
2883
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2884
      return true;
2885
#endif
2886
2887
#ifdef SPARCMAGIC
2888
    case bfd_arch_sparc:
2889
      *magicp = SPARCMAGIC;
2890
#ifdef LYNXOS
2891
      /* Just overwrite the usual value if we're doing Lynx.  */
2892
      *magicp = LYNXCOFFMAGIC;
2893
#endif
2894
      return true;
2895
#endif
2896
2897
#ifdef RS6000COFF_C
2898
    case bfd_arch_rs6000:
2899
    case bfd_arch_powerpc:
2900
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2901
      *magicp = bfd_xcoff_magic_number (abfd);
2902
      return true;
2903
#endif
2904
2905
#ifdef MCOREMAGIC
2906
    case bfd_arch_mcore:
2907
      * magicp = MCOREMAGIC;
2908
      return true;
2909
#endif
2910
2911
0
    default:      /* Unknown architecture.  */
2912
0
      break;
2913
7
    }
2914
2915
0
  return false;
2916
7
}
pei-mcore.c:coff_set_flags
Line
Count
Source
2725
5
{
2726
5
  switch (bfd_get_arch (abfd))
2727
5
    {
2728
#ifdef Z80MAGIC
2729
    case bfd_arch_z80:
2730
      *magicp = Z80MAGIC;
2731
      switch (bfd_get_mach (abfd))
2732
  {
2733
  case bfd_mach_z80strict:
2734
  case bfd_mach_z80:
2735
  case bfd_mach_z80n:
2736
  case bfd_mach_z80full:
2737
  case bfd_mach_r800:
2738
  case bfd_mach_gbz80:
2739
  case bfd_mach_z180:
2740
  case bfd_mach_ez80_z80:
2741
  case bfd_mach_ez80_adl:
2742
    *flagsp = bfd_get_mach (abfd) << 12;
2743
    break;
2744
  default:
2745
    return false;
2746
  }
2747
      return true;
2748
#endif
2749
2750
#ifdef Z8KMAGIC
2751
    case bfd_arch_z8k:
2752
      *magicp = Z8KMAGIC;
2753
2754
      switch (bfd_get_mach (abfd))
2755
  {
2756
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2757
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2758
  default:       return false;
2759
  }
2760
      return true;
2761
#endif
2762
2763
#ifdef TIC30MAGIC
2764
    case bfd_arch_tic30:
2765
      *magicp = TIC30MAGIC;
2766
      return true;
2767
#endif
2768
2769
#ifdef TICOFF_DEFAULT_MAGIC
2770
    case TICOFF_TARGET_ARCH:
2771
      /* If there's no indication of which version we want, use the default.  */
2772
      if (!abfd->xvec )
2773
  *magicp = TICOFF_DEFAULT_MAGIC;
2774
      else
2775
  {
2776
    /* We may want to output in a different COFF version.  */
2777
    switch (abfd->xvec->name[4])
2778
      {
2779
      case '0':
2780
        *magicp = TICOFF0MAGIC;
2781
        break;
2782
      case '1':
2783
        *magicp = TICOFF1MAGIC;
2784
        break;
2785
      case '2':
2786
        *magicp = TICOFF2MAGIC;
2787
        break;
2788
      default:
2789
        return false;
2790
      }
2791
  }
2792
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2793
      return true;
2794
#endif
2795
2796
#ifdef AARCH64MAGIC
2797
    case bfd_arch_aarch64:
2798
      * magicp = AARCH64MAGIC;
2799
      return true;
2800
#endif
2801
2802
#ifdef LOONGARCH64MAGIC
2803
    case bfd_arch_loongarch:
2804
      * magicp = LOONGARCH64MAGIC;
2805
      return true;
2806
#endif
2807
2808
#ifdef ARMMAGIC
2809
    case bfd_arch_arm:
2810
#ifdef ARM_WINCE
2811
      * magicp = ARMPEMAGIC;
2812
#else
2813
      * magicp = ARMMAGIC;
2814
#endif
2815
      * flagsp = 0;
2816
      if (APCS_SET (abfd))
2817
  {
2818
    if (APCS_26_FLAG (abfd))
2819
      * flagsp |= F_APCS26;
2820
2821
    if (APCS_FLOAT_FLAG (abfd))
2822
      * flagsp |= F_APCS_FLOAT;
2823
2824
    if (PIC_FLAG (abfd))
2825
      * flagsp |= F_PIC;
2826
  }
2827
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2828
  * flagsp |= F_INTERWORK;
2829
      switch (bfd_get_mach (abfd))
2830
  {
2831
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2832
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2833
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2834
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2835
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2836
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2837
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2838
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2839
       See also the comment in coff_set_arch_mach_hook().  */
2840
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2841
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2842
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2843
  }
2844
      return true;
2845
#endif
2846
2847
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2848
    case bfd_arch_i386:
2849
#if defined(I386MAGIC)
2850
      *magicp = I386MAGIC;
2851
#endif
2852
#if defined LYNXOS
2853
      /* Just overwrite the usual value if we're doing Lynx.  */
2854
      *magicp = LYNXCOFFMAGIC;
2855
#endif
2856
#if defined AMD64MAGIC
2857
      *magicp = AMD64MAGIC;
2858
#endif
2859
      return true;
2860
#endif
2861
2862
#ifdef IA64MAGIC
2863
    case bfd_arch_ia64:
2864
      *magicp = IA64MAGIC;
2865
      return true;
2866
#endif
2867
2868
#ifdef SH_ARCH_MAGIC_BIG
2869
    case bfd_arch_sh:
2870
#ifdef COFF_IMAGE_WITH_PE
2871
      *magicp = SH_ARCH_MAGIC_WINCE;
2872
#else
2873
      if (bfd_big_endian (abfd))
2874
  *magicp = SH_ARCH_MAGIC_BIG;
2875
      else
2876
  *magicp = SH_ARCH_MAGIC_LITTLE;
2877
#endif
2878
      return true;
2879
#endif
2880
2881
#ifdef MIPS_ARCH_MAGIC_WINCE
2882
    case bfd_arch_mips:
2883
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2884
      return true;
2885
#endif
2886
2887
#ifdef SPARCMAGIC
2888
    case bfd_arch_sparc:
2889
      *magicp = SPARCMAGIC;
2890
#ifdef LYNXOS
2891
      /* Just overwrite the usual value if we're doing Lynx.  */
2892
      *magicp = LYNXCOFFMAGIC;
2893
#endif
2894
      return true;
2895
#endif
2896
2897
#ifdef RS6000COFF_C
2898
    case bfd_arch_rs6000:
2899
    case bfd_arch_powerpc:
2900
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2901
      *magicp = bfd_xcoff_magic_number (abfd);
2902
      return true;
2903
#endif
2904
2905
0
#ifdef MCOREMAGIC
2906
5
    case bfd_arch_mcore:
2907
5
      * magicp = MCOREMAGIC;
2908
5
      return true;
2909
0
#endif
2910
2911
0
    default:      /* Unknown architecture.  */
2912
0
      break;
2913
5
    }
2914
2915
0
  return false;
2916
5
}
pei-sh.c:coff_set_flags
Line
Count
Source
2725
21
{
2726
21
  switch (bfd_get_arch (abfd))
2727
21
    {
2728
#ifdef Z80MAGIC
2729
    case bfd_arch_z80:
2730
      *magicp = Z80MAGIC;
2731
      switch (bfd_get_mach (abfd))
2732
  {
2733
  case bfd_mach_z80strict:
2734
  case bfd_mach_z80:
2735
  case bfd_mach_z80n:
2736
  case bfd_mach_z80full:
2737
  case bfd_mach_r800:
2738
  case bfd_mach_gbz80:
2739
  case bfd_mach_z180:
2740
  case bfd_mach_ez80_z80:
2741
  case bfd_mach_ez80_adl:
2742
    *flagsp = bfd_get_mach (abfd) << 12;
2743
    break;
2744
  default:
2745
    return false;
2746
  }
2747
      return true;
2748
#endif
2749
2750
#ifdef Z8KMAGIC
2751
    case bfd_arch_z8k:
2752
      *magicp = Z8KMAGIC;
2753
2754
      switch (bfd_get_mach (abfd))
2755
  {
2756
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2757
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2758
  default:       return false;
2759
  }
2760
      return true;
2761
#endif
2762
2763
#ifdef TIC30MAGIC
2764
    case bfd_arch_tic30:
2765
      *magicp = TIC30MAGIC;
2766
      return true;
2767
#endif
2768
2769
#ifdef TICOFF_DEFAULT_MAGIC
2770
    case TICOFF_TARGET_ARCH:
2771
      /* If there's no indication of which version we want, use the default.  */
2772
      if (!abfd->xvec )
2773
  *magicp = TICOFF_DEFAULT_MAGIC;
2774
      else
2775
  {
2776
    /* We may want to output in a different COFF version.  */
2777
    switch (abfd->xvec->name[4])
2778
      {
2779
      case '0':
2780
        *magicp = TICOFF0MAGIC;
2781
        break;
2782
      case '1':
2783
        *magicp = TICOFF1MAGIC;
2784
        break;
2785
      case '2':
2786
        *magicp = TICOFF2MAGIC;
2787
        break;
2788
      default:
2789
        return false;
2790
      }
2791
  }
2792
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2793
      return true;
2794
#endif
2795
2796
#ifdef AARCH64MAGIC
2797
    case bfd_arch_aarch64:
2798
      * magicp = AARCH64MAGIC;
2799
      return true;
2800
#endif
2801
2802
#ifdef LOONGARCH64MAGIC
2803
    case bfd_arch_loongarch:
2804
      * magicp = LOONGARCH64MAGIC;
2805
      return true;
2806
#endif
2807
2808
#ifdef ARMMAGIC
2809
    case bfd_arch_arm:
2810
#ifdef ARM_WINCE
2811
      * magicp = ARMPEMAGIC;
2812
#else
2813
      * magicp = ARMMAGIC;
2814
#endif
2815
      * flagsp = 0;
2816
      if (APCS_SET (abfd))
2817
  {
2818
    if (APCS_26_FLAG (abfd))
2819
      * flagsp |= F_APCS26;
2820
2821
    if (APCS_FLOAT_FLAG (abfd))
2822
      * flagsp |= F_APCS_FLOAT;
2823
2824
    if (PIC_FLAG (abfd))
2825
      * flagsp |= F_PIC;
2826
  }
2827
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2828
  * flagsp |= F_INTERWORK;
2829
      switch (bfd_get_mach (abfd))
2830
  {
2831
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2832
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2833
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2834
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2835
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2836
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2837
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2838
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2839
       See also the comment in coff_set_arch_mach_hook().  */
2840
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2841
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2842
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2843
  }
2844
      return true;
2845
#endif
2846
2847
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2848
    case bfd_arch_i386:
2849
#if defined(I386MAGIC)
2850
      *magicp = I386MAGIC;
2851
#endif
2852
#if defined LYNXOS
2853
      /* Just overwrite the usual value if we're doing Lynx.  */
2854
      *magicp = LYNXCOFFMAGIC;
2855
#endif
2856
#if defined AMD64MAGIC
2857
      *magicp = AMD64MAGIC;
2858
#endif
2859
      return true;
2860
#endif
2861
2862
#ifdef IA64MAGIC
2863
    case bfd_arch_ia64:
2864
      *magicp = IA64MAGIC;
2865
      return true;
2866
#endif
2867
2868
0
#ifdef SH_ARCH_MAGIC_BIG
2869
21
    case bfd_arch_sh:
2870
21
#ifdef COFF_IMAGE_WITH_PE
2871
21
      *magicp = SH_ARCH_MAGIC_WINCE;
2872
#else
2873
      if (bfd_big_endian (abfd))
2874
  *magicp = SH_ARCH_MAGIC_BIG;
2875
      else
2876
  *magicp = SH_ARCH_MAGIC_LITTLE;
2877
#endif
2878
21
      return true;
2879
0
#endif
2880
2881
#ifdef MIPS_ARCH_MAGIC_WINCE
2882
    case bfd_arch_mips:
2883
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2884
      return true;
2885
#endif
2886
2887
#ifdef SPARCMAGIC
2888
    case bfd_arch_sparc:
2889
      *magicp = SPARCMAGIC;
2890
#ifdef LYNXOS
2891
      /* Just overwrite the usual value if we're doing Lynx.  */
2892
      *magicp = LYNXCOFFMAGIC;
2893
#endif
2894
      return true;
2895
#endif
2896
2897
#ifdef RS6000COFF_C
2898
    case bfd_arch_rs6000:
2899
    case bfd_arch_powerpc:
2900
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2901
      *magicp = bfd_xcoff_magic_number (abfd);
2902
      return true;
2903
#endif
2904
2905
#ifdef MCOREMAGIC
2906
    case bfd_arch_mcore:
2907
      * magicp = MCOREMAGIC;
2908
      return true;
2909
#endif
2910
2911
0
    default:      /* Unknown architecture.  */
2912
0
      break;
2913
21
    }
2914
2915
0
  return false;
2916
21
}
2917
2918
static bool
2919
coff_set_arch_mach (bfd * abfd,
2920
        enum bfd_architecture arch,
2921
        unsigned long machine)
2922
1.19k
{
2923
1.19k
  unsigned dummy1;
2924
1.19k
  unsigned short dummy2;
2925
2926
1.19k
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2927
3
    return false;
2928
2929
1.18k
  if (arch != bfd_arch_unknown
2930
1.18k
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2931
0
    return false;   /* We can't represent this type.  */
2932
2933
1.18k
  return true;     /* We're easy...  */
2934
1.18k
}
pei-i386.c:coff_set_arch_mach
Line
Count
Source
2922
56
{
2923
56
  unsigned dummy1;
2924
56
  unsigned short dummy2;
2925
2926
56
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2927
0
    return false;
2928
2929
56
  if (arch != bfd_arch_unknown
2930
56
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2931
0
    return false;   /* We can't represent this type.  */
2932
2933
56
  return true;     /* We're easy...  */
2934
56
}
pe-x86_64.c:coff_set_arch_mach
Line
Count
Source
2922
42
{
2923
42
  unsigned dummy1;
2924
42
  unsigned short dummy2;
2925
2926
42
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2927
0
    return false;
2928
2929
42
  if (arch != bfd_arch_unknown
2930
42
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2931
0
    return false;   /* We can't represent this type.  */
2932
2933
42
  return true;     /* We're easy...  */
2934
42
}
pei-x86_64.c:coff_set_arch_mach
Line
Count
Source
2922
53
{
2923
53
  unsigned dummy1;
2924
53
  unsigned short dummy2;
2925
2926
53
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2927
0
    return false;
2928
2929
53
  if (arch != bfd_arch_unknown
2930
53
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2931
0
    return false;   /* We can't represent this type.  */
2932
2933
53
  return true;     /* We're easy...  */
2934
53
}
coff-x86_64.c:coff_set_arch_mach
Line
Count
Source
2922
59
{
2923
59
  unsigned dummy1;
2924
59
  unsigned short dummy2;
2925
2926
59
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2927
0
    return false;
2928
2929
59
  if (arch != bfd_arch_unknown
2930
59
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2931
0
    return false;   /* We can't represent this type.  */
2932
2933
59
  return true;     /* We're easy...  */
2934
59
}
coff64-rs6000.c:coff_set_arch_mach
Line
Count
Source
2922
116
{
2923
116
  unsigned dummy1;
2924
116
  unsigned short dummy2;
2925
2926
116
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2927
0
    return false;
2928
2929
116
  if (arch != bfd_arch_unknown
2930
116
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2931
0
    return false;   /* We can't represent this type.  */
2932
2933
116
  return true;     /* We're easy...  */
2934
116
}
pe-aarch64.c:coff_set_arch_mach
Line
Count
Source
2922
39
{
2923
39
  unsigned dummy1;
2924
39
  unsigned short dummy2;
2925
2926
39
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2927
0
    return false;
2928
2929
39
  if (arch != bfd_arch_unknown
2930
39
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2931
0
    return false;   /* We can't represent this type.  */
2932
2933
39
  return true;     /* We're easy...  */
2934
39
}
pei-aarch64.c:coff_set_arch_mach
Line
Count
Source
2922
27
{
2923
27
  unsigned dummy1;
2924
27
  unsigned short dummy2;
2925
2926
27
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2927
0
    return false;
2928
2929
27
  if (arch != bfd_arch_unknown
2930
27
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2931
0
    return false;   /* We can't represent this type.  */
2932
2933
27
  return true;     /* We're easy...  */
2934
27
}
pei-ia64.c:coff_set_arch_mach
Line
Count
Source
2922
63
{
2923
63
  unsigned dummy1;
2924
63
  unsigned short dummy2;
2925
2926
63
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2927
0
    return false;
2928
2929
63
  if (arch != bfd_arch_unknown
2930
63
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2931
0
    return false;   /* We can't represent this type.  */
2932
2933
63
  return true;     /* We're easy...  */
2934
63
}
pei-loongarch64.c:coff_set_arch_mach
Line
Count
Source
2922
95
{
2923
95
  unsigned dummy1;
2924
95
  unsigned short dummy2;
2925
2926
95
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2927
3
    return false;
2928
2929
92
  if (arch != bfd_arch_unknown
2930
92
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2931
0
    return false;   /* We can't represent this type.  */
2932
2933
92
  return true;     /* We're easy...  */
2934
92
}
Unexecuted instantiation: cf-i386lynx.c:coff_set_arch_mach
Unexecuted instantiation: coff-go32.c:coff_set_arch_mach
Unexecuted instantiation: coff-i386.c:coff_set_arch_mach
coff-rs6000.c:coff_set_arch_mach
Line
Count
Source
2922
133
{
2923
133
  unsigned dummy1;
2924
133
  unsigned short dummy2;
2925
2926
133
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2927
0
    return false;
2928
2929
133
  if (arch != bfd_arch_unknown
2930
133
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2931
0
    return false;   /* We can't represent this type.  */
2932
2933
133
  return true;     /* We're easy...  */
2934
133
}
coff-sh.c:coff_set_arch_mach
Line
Count
Source
2922
152
{
2923
152
  unsigned dummy1;
2924
152
  unsigned short dummy2;
2925
2926
152
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2927
0
    return false;
2928
2929
152
  if (arch != bfd_arch_unknown
2930
152
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2931
0
    return false;   /* We can't represent this type.  */
2932
2933
152
  return true;     /* We're easy...  */
2934
152
}
Unexecuted instantiation: coff-stgo32.c:coff_set_arch_mach
coff-tic30.c:coff_set_arch_mach
Line
Count
Source
2922
40
{
2923
40
  unsigned dummy1;
2924
40
  unsigned short dummy2;
2925
2926
40
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2927
0
    return false;
2928
2929
40
  if (arch != bfd_arch_unknown
2930
40
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2931
0
    return false;   /* We can't represent this type.  */
2932
2933
40
  return true;     /* We're easy...  */
2934
40
}
Unexecuted instantiation: coff-tic4x.c:coff_set_arch_mach
coff-tic54x.c:coff_set_arch_mach
Line
Count
Source
2922
68
{
2923
68
  unsigned dummy1;
2924
68
  unsigned short dummy2;
2925
2926
68
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2927
0
    return false;
2928
2929
68
  if (arch != bfd_arch_unknown
2930
68
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2931
0
    return false;   /* We can't represent this type.  */
2932
2933
68
  return true;     /* We're easy...  */
2934
68
}
coff-z80.c:coff_set_arch_mach
Line
Count
Source
2922
42
{
2923
42
  unsigned dummy1;
2924
42
  unsigned short dummy2;
2925
2926
42
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2927
0
    return false;
2928
2929
42
  if (arch != bfd_arch_unknown
2930
42
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2931
0
    return false;   /* We can't represent this type.  */
2932
2933
42
  return true;     /* We're easy...  */
2934
42
}
coff-z8k.c:coff_set_arch_mach
Line
Count
Source
2922
49
{
2923
49
  unsigned dummy1;
2924
49
  unsigned short dummy2;
2925
2926
49
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2927
0
    return false;
2928
2929
49
  if (arch != bfd_arch_unknown
2930
49
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2931
0
    return false;   /* We can't represent this type.  */
2932
2933
49
  return true;     /* We're easy...  */
2934
49
}
Unexecuted instantiation: pe-arm-wince.c:coff_set_arch_mach
Unexecuted instantiation: pe-arm.c:coff_set_arch_mach
pe-i386.c:coff_set_arch_mach
Line
Count
Source
2922
51
{
2923
51
  unsigned dummy1;
2924
51
  unsigned short dummy2;
2925
2926
51
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2927
0
    return false;
2928
2929
51
  if (arch != bfd_arch_unknown
2930
51
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2931
0
    return false;   /* We can't represent this type.  */
2932
2933
51
  return true;     /* We're easy...  */
2934
51
}
pe-mcore.c:coff_set_arch_mach
Line
Count
Source
2922
37
{
2923
37
  unsigned dummy1;
2924
37
  unsigned short dummy2;
2925
2926
37
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2927
0
    return false;
2928
2929
37
  if (arch != bfd_arch_unknown
2930
37
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2931
0
    return false;   /* We can't represent this type.  */
2932
2933
37
  return true;     /* We're easy...  */
2934
37
}
pe-sh.c:coff_set_arch_mach
Line
Count
Source
2922
32
{
2923
32
  unsigned dummy1;
2924
32
  unsigned short dummy2;
2925
2926
32
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2927
0
    return false;
2928
2929
32
  if (arch != bfd_arch_unknown
2930
32
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2931
0
    return false;   /* We can't represent this type.  */
2932
2933
32
  return true;     /* We're easy...  */
2934
32
}
pei-arm-wince.c:coff_set_arch_mach
Line
Count
Source
2922
5
{
2923
5
  unsigned dummy1;
2924
5
  unsigned short dummy2;
2925
2926
5
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2927
0
    return false;
2928
2929
5
  if (arch != bfd_arch_unknown
2930
5
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2931
0
    return false;   /* We can't represent this type.  */
2932
2933
5
  return true;     /* We're easy...  */
2934
5
}
pei-arm.c:coff_set_arch_mach
Line
Count
Source
2922
7
{
2923
7
  unsigned dummy1;
2924
7
  unsigned short dummy2;
2925
2926
7
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2927
0
    return false;
2928
2929
7
  if (arch != bfd_arch_unknown
2930
7
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2931
0
    return false;   /* We can't represent this type.  */
2932
2933
7
  return true;     /* We're easy...  */
2934
7
}
pei-mcore.c:coff_set_arch_mach
Line
Count
Source
2922
5
{
2923
5
  unsigned dummy1;
2924
5
  unsigned short dummy2;
2925
2926
5
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2927
0
    return false;
2928
2929
5
  if (arch != bfd_arch_unknown
2930
5
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2931
0
    return false;   /* We can't represent this type.  */
2932
2933
5
  return true;     /* We're easy...  */
2934
5
}
pei-sh.c:coff_set_arch_mach
Line
Count
Source
2922
20
{
2923
20
  unsigned dummy1;
2924
20
  unsigned short dummy2;
2925
2926
20
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2927
0
    return false;
2928
2929
20
  if (arch != bfd_arch_unknown
2930
20
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2931
0
    return false;   /* We can't represent this type.  */
2932
2933
20
  return true;     /* We're easy...  */
2934
20
}
2935
2936
#ifdef COFF_IMAGE_WITH_PE
2937
2938
/* This is used to sort sections by VMA, as required by PE image
2939
   files.  */
2940
2941
static int
2942
sort_by_secaddr (const void * arg1, const void * arg2)
2943
212
{
2944
212
  const asection *a = *(const asection **) arg1;
2945
212
  const asection *b = *(const asection **) arg2;
2946
2947
212
  if (a->vma < b->vma)
2948
140
    return -1;
2949
72
  else if (a->vma > b->vma)
2950
63
    return 1;
2951
2952
9
  return 0;
2953
212
}
pei-i386.c:sort_by_secaddr
Line
Count
Source
2943
17
{
2944
17
  const asection *a = *(const asection **) arg1;
2945
17
  const asection *b = *(const asection **) arg2;
2946
2947
17
  if (a->vma < b->vma)
2948
17
    return -1;
2949
0
  else if (a->vma > b->vma)
2950
0
    return 1;
2951
2952
0
  return 0;
2953
17
}
pei-x86_64.c:sort_by_secaddr
Line
Count
Source
2943
192
{
2944
192
  const asection *a = *(const asection **) arg1;
2945
192
  const asection *b = *(const asection **) arg2;
2946
2947
192
  if (a->vma < b->vma)
2948
123
    return -1;
2949
69
  else if (a->vma > b->vma)
2950
63
    return 1;
2951
2952
6
  return 0;
2953
192
}
pei-aarch64.c:sort_by_secaddr
Line
Count
Source
2943
2
{
2944
2
  const asection *a = *(const asection **) arg1;
2945
2
  const asection *b = *(const asection **) arg2;
2946
2947
2
  if (a->vma < b->vma)
2948
0
    return -1;
2949
2
  else if (a->vma > b->vma)
2950
0
    return 1;
2951
2952
2
  return 0;
2953
2
}
Unexecuted instantiation: pei-ia64.c:sort_by_secaddr
Unexecuted instantiation: pei-loongarch64.c:sort_by_secaddr
pei-arm-wince.c:sort_by_secaddr
Line
Count
Source
2943
1
{
2944
1
  const asection *a = *(const asection **) arg1;
2945
1
  const asection *b = *(const asection **) arg2;
2946
2947
1
  if (a->vma < b->vma)
2948
0
    return -1;
2949
1
  else if (a->vma > b->vma)
2950
0
    return 1;
2951
2952
1
  return 0;
2953
1
}
Unexecuted instantiation: pei-arm.c:sort_by_secaddr
Unexecuted instantiation: pei-mcore.c:sort_by_secaddr
Unexecuted instantiation: pei-sh.c:sort_by_secaddr
2954
2955
#endif /* COFF_IMAGE_WITH_PE */
2956
2957
/* Calculate the file position for each section.  */
2958
2959
#define ALIGN_SECTIONS_IN_FILE
2960
#ifdef TICOFF
2961
#undef ALIGN_SECTIONS_IN_FILE
2962
#endif
2963
2964
static bool
2965
coff_compute_section_file_positions (bfd * abfd)
2966
32
{
2967
32
  asection *current;
2968
32
  file_ptr sofar = bfd_coff_filhsz (abfd);
2969
32
  bool align_adjust;
2970
32
  unsigned int target_index;
2971
#ifdef ALIGN_SECTIONS_IN_FILE
2972
  asection *previous = NULL;
2973
  file_ptr old_sofar;
2974
#endif
2975
2976
#ifdef COFF_IMAGE_WITH_PE
2977
  unsigned int page_size;
2978
2979
15
  if (coff_data (abfd)->link_info
2980
15
      || (pe_data (abfd) && pe_data (abfd)->pe_opthdr.FileAlignment))
2981
13
    {
2982
13
      page_size = pe_data (abfd)->pe_opthdr.FileAlignment;
2983
2984
      /* If no file alignment has been set, default to one.
2985
   This repairs 'ld -r' for arm-wince-pe target.  */
2986
13
      if (page_size == 0)
2987
0
  page_size = 1;
2988
13
    }
2989
2
  else
2990
2
    page_size = PE_DEF_FILE_ALIGNMENT;
2991
#else
2992
#ifdef COFF_PAGE_SIZE
2993
9
  unsigned int page_size = COFF_PAGE_SIZE;
2994
#endif
2995
#endif
2996
2997
#ifdef RS6000COFF_C
2998
  /* On XCOFF, if we have symbols, set up the .debug section.  */
2999
1
  if (bfd_get_symcount (abfd) > 0)
3000
0
    {
3001
0
      bfd_size_type sz;
3002
0
      bfd_size_type i, symcount;
3003
0
      asymbol **symp;
3004
3005
      sz = 0;
3006
      symcount = bfd_get_symcount (abfd);
3007
0
      for (symp = abfd->outsymbols, i = 0; i < symcount; symp++, i++)
3008
0
  {
3009
0
    coff_symbol_type *cf;
3010
3011
0
    cf = coff_symbol_from (*symp);
3012
0
    if (cf != NULL
3013
0
        && cf->native != NULL
3014
0
        && cf->native->is_sym
3015
0
        && SYMNAME_IN_DEBUG (&cf->native->u.syment))
3016
0
      {
3017
0
        size_t len;
3018
3019
0
        len = strlen (bfd_asymbol_name (*symp));
3020
0
        if (len > SYMNMLEN || bfd_coff_force_symnames_in_strings (abfd))
3021
0
    sz += len + 1 + bfd_coff_debug_string_prefix_length (abfd);
3022
0
      }
3023
0
  }
3024
0
      if (sz > 0)
3025
0
  {
3026
0
    asection *dsec;
3027
3028
0
    dsec = bfd_make_section_old_way (abfd, DOT_DEBUG);
3029
0
    if (dsec == NULL)
3030
0
      abort ();
3031
0
    dsec->size = sz;
3032
0
    dsec->flags |= SEC_HAS_CONTENTS;
3033
0
  }
3034
0
    }
3035
1
#endif
3036
3037
32
  if (bfd_get_start_address (abfd))
3038
    /*  A start address may have been added to the original file. In this
3039
  case it will need an optional header to record it.  */
3040
5
    abfd->flags |= EXEC_P;
3041
3042
32
  if (abfd->flags & EXEC_P)
3043
20
    sofar += bfd_coff_aoutsz (abfd);
3044
#ifdef RS6000COFF_C
3045
1
  else if (xcoff_data (abfd)->full_aouthdr)
3046
0
    sofar += bfd_coff_aoutsz (abfd);
3047
1
  else
3048
1
    sofar += SMALL_AOUTSZ;
3049
#endif
3050
3051
32
  sofar += abfd->section_count * bfd_coff_scnhsz (abfd);
3052
3053
#ifdef RS6000COFF_C
3054
  /* XCOFF handles overflows in the reloc and line number count fields
3055
     by allocating a new section header to hold the correct counts.  */
3056
1
  for (current = abfd->sections; current != NULL; current = current->next)
3057
0
    if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3058
0
      sofar += bfd_coff_scnhsz (abfd);
3059
#endif
3060
3061
32
  if (coff_data (abfd)->section_by_target_index)
3062
0
    htab_empty (coff_data (abfd)->section_by_target_index);
3063
3064
#ifdef COFF_IMAGE_WITH_PE
3065
  {
3066
    /* PE requires the sections to be in memory order when listed in
3067
       the section headers.  It also does not like empty loadable
3068
       sections.  The sections apparently do not have to be in the
3069
       right order in the image file itself, but we do need to get the
3070
       target_index values right.  */
3071
3072
    unsigned int count;
3073
    asection **section_list;
3074
    unsigned int i;
3075
    bfd_size_type amt;
3076
3077
#ifdef COFF_PAGE_SIZE
3078
    /* Clear D_PAGED if section / file alignment aren't suitable for
3079
       paging at COFF_PAGE_SIZE granularity.  */
3080
15
   if (pe_data (abfd)->pe_opthdr.SectionAlignment < COFF_PAGE_SIZE
3081
15
       || page_size < COFF_PAGE_SIZE)
3082
14
     abfd->flags &= ~D_PAGED;
3083
#endif
3084
3085
    count = 0;
3086
109
    for (current = abfd->sections; current != NULL; current = current->next)
3087
94
      ++count;
3088
3089
    /* We allocate an extra cell to simplify the final loop.  */
3090
    amt = sizeof (struct asection *) * (count + 1);
3091
    section_list = (asection **) bfd_malloc (amt);
3092
15
    if (section_list == NULL)
3093
0
      return false;
3094
3095
15
    i = 0;
3096
109
    for (current = abfd->sections; current != NULL; current = current->next)
3097
94
      {
3098
94
  section_list[i] = current;
3099
94
  ++i;
3100
94
      }
3101
15
    section_list[i] = NULL;
3102
3103
15
    qsort (section_list, count, sizeof (asection *), sort_by_secaddr);
3104
3105
    /* Rethread the linked list into sorted order; at the same time,
3106
       assign target_index values.  */
3107
15
    target_index = 1;
3108
15
    abfd->sections = NULL;
3109
15
    abfd->section_last = NULL;
3110
109
    for (i = 0; i < count; i++)
3111
94
      {
3112
94
  current = section_list[i];
3113
94
  bfd_section_list_append (abfd, current);
3114
3115
  /* Later, if the section has zero size, we'll be throwing it
3116
     away, so we don't want to number it now.  Note that having
3117
     a zero size and having real contents are different
3118
     concepts: .bss has no contents, but (usually) non-zero
3119
     size.  */
3120
94
  if (current->size == 0)
3121
0
    {
3122
      /* Discard.  However, it still might have (valid) symbols
3123
         in it, so arbitrarily set it to section 1 (indexing is
3124
         1-based here; usually .text).  __end__ and other
3125
         contents of .endsection really have this happen.
3126
         FIXME: This seems somewhat dubious.  */
3127
0
      current->target_index = 1;
3128
0
    }
3129
94
  else
3130
94
    current->target_index = target_index++;
3131
94
      }
3132
3133
15
    free (section_list);
3134
15
  }
3135
#else /* ! COFF_IMAGE_WITH_PE */
3136
  {
3137
    /* Set the target_index field.  */
3138
    target_index = 1;
3139
1.54k
    for (current = abfd->sections; current != NULL; current = current->next)
3140
1.52k
      current->target_index = target_index++;
3141
  }
3142
#endif /* ! COFF_IMAGE_WITH_PE */
3143
3144
32
  if (target_index >= bfd_coff_max_nscns (abfd))
3145
0
    {
3146
0
      bfd_set_error (bfd_error_file_too_big);
3147
0
      _bfd_error_handler
3148
  /* xgettext:c-format */
3149
0
  (_("%pB: too many sections (%d)"), abfd, target_index);
3150
0
      return false;
3151
0
    }
3152
3153
32
  align_adjust = false;
3154
32
  for (current = abfd->sections;
3155
1.64k
       current != NULL;
3156
1.61k
       current = current->next)
3157
1.61k
    {
3158
#ifdef COFF_IMAGE_WITH_PE
3159
      /* With PE we have to pad each section to be a multiple of its
3160
   page size too, and remember both sizes.  */
3161
94
      if (coff_section_data (abfd, current) == NULL)
3162
12
  {
3163
12
    size_t amt = sizeof (struct coff_section_tdata);
3164
3165
    current->used_by_bfd = bfd_zalloc (abfd, amt);
3166
12
    if (current->used_by_bfd == NULL)
3167
0
      return false;
3168
12
  }
3169
94
      if (pei_section_data (abfd, current) == NULL)
3170
12
  {
3171
12
    size_t amt = sizeof (struct pei_section_tdata);
3172
3173
12
    coff_section_data (abfd, current)->tdata = bfd_zalloc (abfd, amt);
3174
12
    if (coff_section_data (abfd, current)->tdata == NULL)
3175
0
      return false;
3176
12
  }
3177
94
      if (pei_section_data (abfd, current)->virt_size == 0)
3178
12
  pei_section_data (abfd, current)->virt_size = current->size;
3179
94
#endif
3180
3181
      /* Only deal with sections which have contents.  */
3182
1.61k
      if (!(current->flags & SEC_HAS_CONTENTS))
3183
1.50k
  continue;
3184
3185
109
      current->rawsize = current->size;
3186
3187
#ifdef COFF_IMAGE_WITH_PE
3188
      /* Make sure we skip empty sections in a PE image.  */
3189
90
      if (current->size == 0)
3190
0
  continue;
3191
90
#endif
3192
3193
      /* Align the sections in the file to the same boundary on
3194
   which they are aligned in virtual memory.  */
3195
#ifdef ALIGN_SECTIONS_IN_FILE
3196
109
      if ((abfd->flags & EXEC_P) != 0)
3197
99
  {
3198
    /* Make sure this section is aligned on the right boundary - by
3199
       padding the previous section up if necessary.  */
3200
99
    old_sofar = sofar;
3201
3202
#ifdef COFF_IMAGE_WITH_PE
3203
84
    sofar = BFD_ALIGN (sofar, page_size);
3204
#else
3205
15
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3206
#endif
3207
3208
#ifdef RS6000COFF_C
3209
    /* Make sure the file offset and the vma of .text/.data are at the
3210
       same page offset, so that the file can be mmap'ed without being
3211
       relocated.  Failing that, AIX is able to load and execute the
3212
       program, but it will be silently relocated (possible as
3213
       executables are PIE).  But the relocation is slightly costly and
3214
       complexify the use of addr2line or gdb.  So better to avoid it,
3215
       like does the native linker.  Usually gnu ld makes sure that
3216
       the vma of .text is the file offset so this issue shouldn't
3217
       appear unless you are stripping such an executable.
3218
3219
       AIX loader checks the text section alignment of (vma - filepos),
3220
       and the native linker doesn't try to align the text sections.
3221
       For example:
3222
3223
       0 .text       000054cc  10000128  10000128  00000128  2**5
3224
           CONTENTS, ALLOC, LOAD, CODE
3225
3226
       Don't perform the above tweak if the previous one is .tdata,
3227
       as it will increase the memory allocated for every threads
3228
       created and not just improve performances with gdb.
3229
    */
3230
3231
0
    if ((current->flags & SEC_LOAD) != 0
3232
0
        && (!strcmp (current->name, _TEXT)
3233
0
      || !strcmp (current->name, _DATA))
3234
0
        && (previous == NULL || strcmp(previous->name, _TDATA)))
3235
0
      {
3236
0
        bfd_vma align = 4096;
3237
0
        bfd_vma sofar_off = sofar % align;
3238
0
        bfd_vma vma_off = current->vma % align;
3239
3240
0
        if (vma_off > sofar_off)
3241
0
    sofar += vma_off - sofar_off;
3242
0
        else if (vma_off < sofar_off)
3243
0
    sofar += align + vma_off - sofar_off;
3244
0
      }
3245
#endif
3246
99
    if (previous != NULL
3247
99
        && (previous->flags & SEC_LOAD) != 0)
3248
60
      previous->size += sofar - old_sofar;
3249
99
  }
3250
3251
90
#endif
3252
3253
      /* In demand paged files the low order bits of the file offset
3254
   must match the low order bits of the virtual address.  */
3255
#ifdef COFF_PAGE_SIZE
3256
94
      if ((abfd->flags & D_PAGED) != 0
3257
94
    && (current->flags & SEC_ALLOC) != 0)
3258
0
  sofar += (current->vma - (bfd_vma) sofar) % page_size;
3259
#endif
3260
90
      current->filepos = sofar;
3261
3262
#ifdef COFF_IMAGE_WITH_PE
3263
      /* Set the padded size.  */
3264
      current->size = (current->size + page_size - 1) & -page_size;
3265
#endif
3266
3267
90
      sofar += current->size;
3268
3269
#ifdef ALIGN_SECTIONS_IN_FILE
3270
      /* Make sure that this section is of the right size too.  */
3271
109
      if ((abfd->flags & EXEC_P) == 0)
3272
10
  {
3273
10
    bfd_size_type old_size;
3274
3275
10
    old_size = current->size;
3276
10
    current->size = BFD_ALIGN (current->size,
3277
10
             (bfd_vma) 1 << current->alignment_power);
3278
10
    align_adjust = current->size != old_size;
3279
10
    sofar += current->size - old_size;
3280
10
  }
3281
99
      else
3282
99
  {
3283
99
    old_sofar = sofar;
3284
#ifdef COFF_IMAGE_WITH_PE
3285
84
    sofar = BFD_ALIGN (sofar, page_size);
3286
#else
3287
15
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3288
#endif
3289
99
    align_adjust = sofar != old_sofar;
3290
99
    current->size += sofar - old_sofar;
3291
99
  }
3292
#endif
3293
3294
#ifdef COFF_IMAGE_WITH_PE
3295
      /* For PE we need to make sure we pad out to the aligned
3296
   size, in case the caller only writes out data to the
3297
   unaligned size.  */
3298
90
      if (pei_section_data (abfd, current)->virt_size < current->size)
3299
68
  align_adjust = true;
3300
#endif
3301
3302
#ifdef _LIB
3303
      /* Force .lib sections to start at zero.  The vma is then
3304
   incremented in coff_set_section_contents.  This is right for
3305
   SVR3.2.  */
3306
109
      if (strcmp (current->name, _LIB) == 0)
3307
0
  bfd_set_section_vma (current, 0);
3308
#endif
3309
3310
#ifdef ALIGN_SECTIONS_IN_FILE
3311
      previous = current;
3312
#endif
3313
90
    }
3314
3315
  /* It is now safe to write to the output file.  If we needed an
3316
     alignment adjustment for the last section, then make sure that
3317
     there is a byte at offset sofar.  If there are no symbols and no
3318
     relocs, then nothing follows the last section.  If we don't force
3319
     the last byte out, then the file may appear to be truncated.  */
3320
32
  if (align_adjust)
3321
9
    {
3322
9
      bfd_byte b;
3323
3324
9
      b = 0;
3325
9
      if (bfd_seek (abfd, sofar - 1, SEEK_SET) != 0
3326
9
    || bfd_write (&b, 1, abfd) != 1)
3327
0
  return false;
3328
9
    }
3329
3330
  /* Make sure the relocations are aligned.  We don't need to make
3331
     sure that this byte exists, because it will only matter if there
3332
     really are relocs.  */
3333
32
  sofar = BFD_ALIGN (sofar,
3334
32
         (bfd_vma) 1 << COFF_DEFAULT_SECTION_ALIGNMENT_POWER);
3335
3336
32
  obj_relocbase (abfd) = sofar;
3337
32
  abfd->output_has_begun = true;
3338
3339
32
  return true;
3340
15
}
pei-i386.c:coff_compute_section_file_positions
Line
Count
Source
2966
3
{
2967
3
  asection *current;
2968
3
  file_ptr sofar = bfd_coff_filhsz (abfd);
2969
3
  bool align_adjust;
2970
3
  unsigned int target_index;
2971
3
#ifdef ALIGN_SECTIONS_IN_FILE
2972
3
  asection *previous = NULL;
2973
3
  file_ptr old_sofar;
2974
3
#endif
2975
2976
3
#ifdef COFF_IMAGE_WITH_PE
2977
3
  unsigned int page_size;
2978
2979
3
  if (coff_data (abfd)->link_info
2980
3
      || (pe_data (abfd) && pe_data (abfd)->pe_opthdr.FileAlignment))
2981
3
    {
2982
3
      page_size = pe_data (abfd)->pe_opthdr.FileAlignment;
2983
2984
      /* If no file alignment has been set, default to one.
2985
   This repairs 'ld -r' for arm-wince-pe target.  */
2986
3
      if (page_size == 0)
2987
0
  page_size = 1;
2988
3
    }
2989
0
  else
2990
0
    page_size = PE_DEF_FILE_ALIGNMENT;
2991
#else
2992
#ifdef COFF_PAGE_SIZE
2993
  unsigned int page_size = COFF_PAGE_SIZE;
2994
#endif
2995
#endif
2996
2997
#ifdef RS6000COFF_C
2998
  /* On XCOFF, if we have symbols, set up the .debug section.  */
2999
  if (bfd_get_symcount (abfd) > 0)
3000
    {
3001
      bfd_size_type sz;
3002
      bfd_size_type i, symcount;
3003
      asymbol **symp;
3004
3005
      sz = 0;
3006
      symcount = bfd_get_symcount (abfd);
3007
      for (symp = abfd->outsymbols, i = 0; i < symcount; symp++, i++)
3008
  {
3009
    coff_symbol_type *cf;
3010
3011
    cf = coff_symbol_from (*symp);
3012
    if (cf != NULL
3013
        && cf->native != NULL
3014
        && cf->native->is_sym
3015
        && SYMNAME_IN_DEBUG (&cf->native->u.syment))
3016
      {
3017
        size_t len;
3018
3019
        len = strlen (bfd_asymbol_name (*symp));
3020
        if (len > SYMNMLEN || bfd_coff_force_symnames_in_strings (abfd))
3021
    sz += len + 1 + bfd_coff_debug_string_prefix_length (abfd);
3022
      }
3023
  }
3024
      if (sz > 0)
3025
  {
3026
    asection *dsec;
3027
3028
    dsec = bfd_make_section_old_way (abfd, DOT_DEBUG);
3029
    if (dsec == NULL)
3030
      abort ();
3031
    dsec->size = sz;
3032
    dsec->flags |= SEC_HAS_CONTENTS;
3033
  }
3034
    }
3035
#endif
3036
3037
3
  if (bfd_get_start_address (abfd))
3038
    /*  A start address may have been added to the original file. In this
3039
  case it will need an optional header to record it.  */
3040
2
    abfd->flags |= EXEC_P;
3041
3042
3
  if (abfd->flags & EXEC_P)
3043
3
    sofar += bfd_coff_aoutsz (abfd);
3044
#ifdef RS6000COFF_C
3045
  else if (xcoff_data (abfd)->full_aouthdr)
3046
    sofar += bfd_coff_aoutsz (abfd);
3047
  else
3048
    sofar += SMALL_AOUTSZ;
3049
#endif
3050
3051
3
  sofar += abfd->section_count * bfd_coff_scnhsz (abfd);
3052
3053
#ifdef RS6000COFF_C
3054
  /* XCOFF handles overflows in the reloc and line number count fields
3055
     by allocating a new section header to hold the correct counts.  */
3056
  for (current = abfd->sections; current != NULL; current = current->next)
3057
    if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3058
      sofar += bfd_coff_scnhsz (abfd);
3059
#endif
3060
3061
3
  if (coff_data (abfd)->section_by_target_index)
3062
0
    htab_empty (coff_data (abfd)->section_by_target_index);
3063
3064
3
#ifdef COFF_IMAGE_WITH_PE
3065
3
  {
3066
    /* PE requires the sections to be in memory order when listed in
3067
       the section headers.  It also does not like empty loadable
3068
       sections.  The sections apparently do not have to be in the
3069
       right order in the image file itself, but we do need to get the
3070
       target_index values right.  */
3071
3072
3
    unsigned int count;
3073
3
    asection **section_list;
3074
3
    unsigned int i;
3075
3
    bfd_size_type amt;
3076
3077
3
#ifdef COFF_PAGE_SIZE
3078
    /* Clear D_PAGED if section / file alignment aren't suitable for
3079
       paging at COFF_PAGE_SIZE granularity.  */
3080
3
   if (pe_data (abfd)->pe_opthdr.SectionAlignment < COFF_PAGE_SIZE
3081
3
       || page_size < COFF_PAGE_SIZE)
3082
2
     abfd->flags &= ~D_PAGED;
3083
3
#endif
3084
3085
3
    count = 0;
3086
16
    for (current = abfd->sections; current != NULL; current = current->next)
3087
13
      ++count;
3088
3089
    /* We allocate an extra cell to simplify the final loop.  */
3090
3
    amt = sizeof (struct asection *) * (count + 1);
3091
3
    section_list = (asection **) bfd_malloc (amt);
3092
3
    if (section_list == NULL)
3093
0
      return false;
3094
3095
3
    i = 0;
3096
16
    for (current = abfd->sections; current != NULL; current = current->next)
3097
13
      {
3098
13
  section_list[i] = current;
3099
13
  ++i;
3100
13
      }
3101
3
    section_list[i] = NULL;
3102
3103
3
    qsort (section_list, count, sizeof (asection *), sort_by_secaddr);
3104
3105
    /* Rethread the linked list into sorted order; at the same time,
3106
       assign target_index values.  */
3107
3
    target_index = 1;
3108
3
    abfd->sections = NULL;
3109
3
    abfd->section_last = NULL;
3110
16
    for (i = 0; i < count; i++)
3111
13
      {
3112
13
  current = section_list[i];
3113
13
  bfd_section_list_append (abfd, current);
3114
3115
  /* Later, if the section has zero size, we'll be throwing it
3116
     away, so we don't want to number it now.  Note that having
3117
     a zero size and having real contents are different
3118
     concepts: .bss has no contents, but (usually) non-zero
3119
     size.  */
3120
13
  if (current->size == 0)
3121
0
    {
3122
      /* Discard.  However, it still might have (valid) symbols
3123
         in it, so arbitrarily set it to section 1 (indexing is
3124
         1-based here; usually .text).  __end__ and other
3125
         contents of .endsection really have this happen.
3126
         FIXME: This seems somewhat dubious.  */
3127
0
      current->target_index = 1;
3128
0
    }
3129
13
  else
3130
13
    current->target_index = target_index++;
3131
13
      }
3132
3133
3
    free (section_list);
3134
3
  }
3135
#else /* ! COFF_IMAGE_WITH_PE */
3136
  {
3137
    /* Set the target_index field.  */
3138
    target_index = 1;
3139
    for (current = abfd->sections; current != NULL; current = current->next)
3140
      current->target_index = target_index++;
3141
  }
3142
#endif /* ! COFF_IMAGE_WITH_PE */
3143
3144
3
  if (target_index >= bfd_coff_max_nscns (abfd))
3145
0
    {
3146
0
      bfd_set_error (bfd_error_file_too_big);
3147
0
      _bfd_error_handler
3148
  /* xgettext:c-format */
3149
0
  (_("%pB: too many sections (%d)"), abfd, target_index);
3150
0
      return false;
3151
0
    }
3152
3153
3
  align_adjust = false;
3154
3
  for (current = abfd->sections;
3155
16
       current != NULL;
3156
13
       current = current->next)
3157
13
    {
3158
13
#ifdef COFF_IMAGE_WITH_PE
3159
      /* With PE we have to pad each section to be a multiple of its
3160
   page size too, and remember both sizes.  */
3161
13
      if (coff_section_data (abfd, current) == NULL)
3162
0
  {
3163
0
    size_t amt = sizeof (struct coff_section_tdata);
3164
3165
0
    current->used_by_bfd = bfd_zalloc (abfd, amt);
3166
0
    if (current->used_by_bfd == NULL)
3167
0
      return false;
3168
0
  }
3169
13
      if (pei_section_data (abfd, current) == NULL)
3170
0
  {
3171
0
    size_t amt = sizeof (struct pei_section_tdata);
3172
3173
0
    coff_section_data (abfd, current)->tdata = bfd_zalloc (abfd, amt);
3174
0
    if (coff_section_data (abfd, current)->tdata == NULL)
3175
0
      return false;
3176
0
  }
3177
13
      if (pei_section_data (abfd, current)->virt_size == 0)
3178
0
  pei_section_data (abfd, current)->virt_size = current->size;
3179
13
#endif
3180
3181
      /* Only deal with sections which have contents.  */
3182
13
      if (!(current->flags & SEC_HAS_CONTENTS))
3183
1
  continue;
3184
3185
12
      current->rawsize = current->size;
3186
3187
12
#ifdef COFF_IMAGE_WITH_PE
3188
      /* Make sure we skip empty sections in a PE image.  */
3189
12
      if (current->size == 0)
3190
0
  continue;
3191
12
#endif
3192
3193
      /* Align the sections in the file to the same boundary on
3194
   which they are aligned in virtual memory.  */
3195
12
#ifdef ALIGN_SECTIONS_IN_FILE
3196
12
      if ((abfd->flags & EXEC_P) != 0)
3197
12
  {
3198
    /* Make sure this section is aligned on the right boundary - by
3199
       padding the previous section up if necessary.  */
3200
12
    old_sofar = sofar;
3201
3202
12
#ifdef COFF_IMAGE_WITH_PE
3203
12
    sofar = BFD_ALIGN (sofar, page_size);
3204
#else
3205
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3206
#endif
3207
3208
#ifdef RS6000COFF_C
3209
    /* Make sure the file offset and the vma of .text/.data are at the
3210
       same page offset, so that the file can be mmap'ed without being
3211
       relocated.  Failing that, AIX is able to load and execute the
3212
       program, but it will be silently relocated (possible as
3213
       executables are PIE).  But the relocation is slightly costly and
3214
       complexify the use of addr2line or gdb.  So better to avoid it,
3215
       like does the native linker.  Usually gnu ld makes sure that
3216
       the vma of .text is the file offset so this issue shouldn't
3217
       appear unless you are stripping such an executable.
3218
3219
       AIX loader checks the text section alignment of (vma - filepos),
3220
       and the native linker doesn't try to align the text sections.
3221
       For example:
3222
3223
       0 .text       000054cc  10000128  10000128  00000128  2**5
3224
           CONTENTS, ALLOC, LOAD, CODE
3225
3226
       Don't perform the above tweak if the previous one is .tdata,
3227
       as it will increase the memory allocated for every threads
3228
       created and not just improve performances with gdb.
3229
    */
3230
3231
    if ((current->flags & SEC_LOAD) != 0
3232
        && (!strcmp (current->name, _TEXT)
3233
      || !strcmp (current->name, _DATA))
3234
        && (previous == NULL || strcmp(previous->name, _TDATA)))
3235
      {
3236
        bfd_vma align = 4096;
3237
        bfd_vma sofar_off = sofar % align;
3238
        bfd_vma vma_off = current->vma % align;
3239
3240
        if (vma_off > sofar_off)
3241
    sofar += vma_off - sofar_off;
3242
        else if (vma_off < sofar_off)
3243
    sofar += align + vma_off - sofar_off;
3244
      }
3245
#endif
3246
12
    if (previous != NULL
3247
12
        && (previous->flags & SEC_LOAD) != 0)
3248
10
      previous->size += sofar - old_sofar;
3249
12
  }
3250
3251
12
#endif
3252
3253
      /* In demand paged files the low order bits of the file offset
3254
   must match the low order bits of the virtual address.  */
3255
12
#ifdef COFF_PAGE_SIZE
3256
12
      if ((abfd->flags & D_PAGED) != 0
3257
12
    && (current->flags & SEC_ALLOC) != 0)
3258
0
  sofar += (current->vma - (bfd_vma) sofar) % page_size;
3259
12
#endif
3260
12
      current->filepos = sofar;
3261
3262
12
#ifdef COFF_IMAGE_WITH_PE
3263
      /* Set the padded size.  */
3264
12
      current->size = (current->size + page_size - 1) & -page_size;
3265
12
#endif
3266
3267
12
      sofar += current->size;
3268
3269
12
#ifdef ALIGN_SECTIONS_IN_FILE
3270
      /* Make sure that this section is of the right size too.  */
3271
12
      if ((abfd->flags & EXEC_P) == 0)
3272
0
  {
3273
0
    bfd_size_type old_size;
3274
3275
0
    old_size = current->size;
3276
0
    current->size = BFD_ALIGN (current->size,
3277
0
             (bfd_vma) 1 << current->alignment_power);
3278
0
    align_adjust = current->size != old_size;
3279
0
    sofar += current->size - old_size;
3280
0
  }
3281
12
      else
3282
12
  {
3283
12
    old_sofar = sofar;
3284
12
#ifdef COFF_IMAGE_WITH_PE
3285
12
    sofar = BFD_ALIGN (sofar, page_size);
3286
#else
3287
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3288
#endif
3289
12
    align_adjust = sofar != old_sofar;
3290
12
    current->size += sofar - old_sofar;
3291
12
  }
3292
12
#endif
3293
3294
12
#ifdef COFF_IMAGE_WITH_PE
3295
      /* For PE we need to make sure we pad out to the aligned
3296
   size, in case the caller only writes out data to the
3297
   unaligned size.  */
3298
12
      if (pei_section_data (abfd, current)->virt_size < current->size)
3299
12
  align_adjust = true;
3300
12
#endif
3301
3302
12
#ifdef _LIB
3303
      /* Force .lib sections to start at zero.  The vma is then
3304
   incremented in coff_set_section_contents.  This is right for
3305
   SVR3.2.  */
3306
12
      if (strcmp (current->name, _LIB) == 0)
3307
0
  bfd_set_section_vma (current, 0);
3308
12
#endif
3309
3310
12
#ifdef ALIGN_SECTIONS_IN_FILE
3311
12
      previous = current;
3312
12
#endif
3313
12
    }
3314
3315
  /* It is now safe to write to the output file.  If we needed an
3316
     alignment adjustment for the last section, then make sure that
3317
     there is a byte at offset sofar.  If there are no symbols and no
3318
     relocs, then nothing follows the last section.  If we don't force
3319
     the last byte out, then the file may appear to be truncated.  */
3320
3
  if (align_adjust)
3321
2
    {
3322
2
      bfd_byte b;
3323
3324
2
      b = 0;
3325
2
      if (bfd_seek (abfd, sofar - 1, SEEK_SET) != 0
3326
2
    || bfd_write (&b, 1, abfd) != 1)
3327
0
  return false;
3328
2
    }
3329
3330
  /* Make sure the relocations are aligned.  We don't need to make
3331
     sure that this byte exists, because it will only matter if there
3332
     really are relocs.  */
3333
3
  sofar = BFD_ALIGN (sofar,
3334
3
         (bfd_vma) 1 << COFF_DEFAULT_SECTION_ALIGNMENT_POWER);
3335
3336
3
  obj_relocbase (abfd) = sofar;
3337
3
  abfd->output_has_begun = true;
3338
3339
3
  return true;
3340
3
}
pe-x86_64.c:coff_compute_section_file_positions
Line
Count
Source
2966
1
{
2967
1
  asection *current;
2968
1
  file_ptr sofar = bfd_coff_filhsz (abfd);
2969
1
  bool align_adjust;
2970
1
  unsigned int target_index;
2971
1
#ifdef ALIGN_SECTIONS_IN_FILE
2972
1
  asection *previous = NULL;
2973
1
  file_ptr old_sofar;
2974
1
#endif
2975
2976
#ifdef COFF_IMAGE_WITH_PE
2977
  unsigned int page_size;
2978
2979
  if (coff_data (abfd)->link_info
2980
      || (pe_data (abfd) && pe_data (abfd)->pe_opthdr.FileAlignment))
2981
    {
2982
      page_size = pe_data (abfd)->pe_opthdr.FileAlignment;
2983
2984
      /* If no file alignment has been set, default to one.
2985
   This repairs 'ld -r' for arm-wince-pe target.  */
2986
      if (page_size == 0)
2987
  page_size = 1;
2988
    }
2989
  else
2990
    page_size = PE_DEF_FILE_ALIGNMENT;
2991
#else
2992
1
#ifdef COFF_PAGE_SIZE
2993
1
  unsigned int page_size = COFF_PAGE_SIZE;
2994
1
#endif
2995
1
#endif
2996
2997
#ifdef RS6000COFF_C
2998
  /* On XCOFF, if we have symbols, set up the .debug section.  */
2999
  if (bfd_get_symcount (abfd) > 0)
3000
    {
3001
      bfd_size_type sz;
3002
      bfd_size_type i, symcount;
3003
      asymbol **symp;
3004
3005
      sz = 0;
3006
      symcount = bfd_get_symcount (abfd);
3007
      for (symp = abfd->outsymbols, i = 0; i < symcount; symp++, i++)
3008
  {
3009
    coff_symbol_type *cf;
3010
3011
    cf = coff_symbol_from (*symp);
3012
    if (cf != NULL
3013
        && cf->native != NULL
3014
        && cf->native->is_sym
3015
        && SYMNAME_IN_DEBUG (&cf->native->u.syment))
3016
      {
3017
        size_t len;
3018
3019
        len = strlen (bfd_asymbol_name (*symp));
3020
        if (len > SYMNMLEN || bfd_coff_force_symnames_in_strings (abfd))
3021
    sz += len + 1 + bfd_coff_debug_string_prefix_length (abfd);
3022
      }
3023
  }
3024
      if (sz > 0)
3025
  {
3026
    asection *dsec;
3027
3028
    dsec = bfd_make_section_old_way (abfd, DOT_DEBUG);
3029
    if (dsec == NULL)
3030
      abort ();
3031
    dsec->size = sz;
3032
    dsec->flags |= SEC_HAS_CONTENTS;
3033
  }
3034
    }
3035
#endif
3036
3037
1
  if (bfd_get_start_address (abfd))
3038
    /*  A start address may have been added to the original file. In this
3039
  case it will need an optional header to record it.  */
3040
0
    abfd->flags |= EXEC_P;
3041
3042
1
  if (abfd->flags & EXEC_P)
3043
0
    sofar += bfd_coff_aoutsz (abfd);
3044
#ifdef RS6000COFF_C
3045
  else if (xcoff_data (abfd)->full_aouthdr)
3046
    sofar += bfd_coff_aoutsz (abfd);
3047
  else
3048
    sofar += SMALL_AOUTSZ;
3049
#endif
3050
3051
1
  sofar += abfd->section_count * bfd_coff_scnhsz (abfd);
3052
3053
#ifdef RS6000COFF_C
3054
  /* XCOFF handles overflows in the reloc and line number count fields
3055
     by allocating a new section header to hold the correct counts.  */
3056
  for (current = abfd->sections; current != NULL; current = current->next)
3057
    if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3058
      sofar += bfd_coff_scnhsz (abfd);
3059
#endif
3060
3061
1
  if (coff_data (abfd)->section_by_target_index)
3062
0
    htab_empty (coff_data (abfd)->section_by_target_index);
3063
3064
#ifdef COFF_IMAGE_WITH_PE
3065
  {
3066
    /* PE requires the sections to be in memory order when listed in
3067
       the section headers.  It also does not like empty loadable
3068
       sections.  The sections apparently do not have to be in the
3069
       right order in the image file itself, but we do need to get the
3070
       target_index values right.  */
3071
3072
    unsigned int count;
3073
    asection **section_list;
3074
    unsigned int i;
3075
    bfd_size_type amt;
3076
3077
#ifdef COFF_PAGE_SIZE
3078
    /* Clear D_PAGED if section / file alignment aren't suitable for
3079
       paging at COFF_PAGE_SIZE granularity.  */
3080
   if (pe_data (abfd)->pe_opthdr.SectionAlignment < COFF_PAGE_SIZE
3081
       || page_size < COFF_PAGE_SIZE)
3082
     abfd->flags &= ~D_PAGED;
3083
#endif
3084
3085
    count = 0;
3086
    for (current = abfd->sections; current != NULL; current = current->next)
3087
      ++count;
3088
3089
    /* We allocate an extra cell to simplify the final loop.  */
3090
    amt = sizeof (struct asection *) * (count + 1);
3091
    section_list = (asection **) bfd_malloc (amt);
3092
    if (section_list == NULL)
3093
      return false;
3094
3095
    i = 0;
3096
    for (current = abfd->sections; current != NULL; current = current->next)
3097
      {
3098
  section_list[i] = current;
3099
  ++i;
3100
      }
3101
    section_list[i] = NULL;
3102
3103
    qsort (section_list, count, sizeof (asection *), sort_by_secaddr);
3104
3105
    /* Rethread the linked list into sorted order; at the same time,
3106
       assign target_index values.  */
3107
    target_index = 1;
3108
    abfd->sections = NULL;
3109
    abfd->section_last = NULL;
3110
    for (i = 0; i < count; i++)
3111
      {
3112
  current = section_list[i];
3113
  bfd_section_list_append (abfd, current);
3114
3115
  /* Later, if the section has zero size, we'll be throwing it
3116
     away, so we don't want to number it now.  Note that having
3117
     a zero size and having real contents are different
3118
     concepts: .bss has no contents, but (usually) non-zero
3119
     size.  */
3120
  if (current->size == 0)
3121
    {
3122
      /* Discard.  However, it still might have (valid) symbols
3123
         in it, so arbitrarily set it to section 1 (indexing is
3124
         1-based here; usually .text).  __end__ and other
3125
         contents of .endsection really have this happen.
3126
         FIXME: This seems somewhat dubious.  */
3127
      current->target_index = 1;
3128
    }
3129
  else
3130
    current->target_index = target_index++;
3131
      }
3132
3133
    free (section_list);
3134
  }
3135
#else /* ! COFF_IMAGE_WITH_PE */
3136
1
  {
3137
    /* Set the target_index field.  */
3138
1
    target_index = 1;
3139
1
    for (current = abfd->sections; current != NULL; current = current->next)
3140
0
      current->target_index = target_index++;
3141
1
  }
3142
1
#endif /* ! COFF_IMAGE_WITH_PE */
3143
3144
1
  if (target_index >= bfd_coff_max_nscns (abfd))
3145
0
    {
3146
0
      bfd_set_error (bfd_error_file_too_big);
3147
0
      _bfd_error_handler
3148
  /* xgettext:c-format */
3149
0
  (_("%pB: too many sections (%d)"), abfd, target_index);
3150
0
      return false;
3151
0
    }
3152
3153
1
  align_adjust = false;
3154
1
  for (current = abfd->sections;
3155
1
       current != NULL;
3156
1
       current = current->next)
3157
0
    {
3158
#ifdef COFF_IMAGE_WITH_PE
3159
      /* With PE we have to pad each section to be a multiple of its
3160
   page size too, and remember both sizes.  */
3161
      if (coff_section_data (abfd, current) == NULL)
3162
  {
3163
    size_t amt = sizeof (struct coff_section_tdata);
3164
3165
    current->used_by_bfd = bfd_zalloc (abfd, amt);
3166
    if (current->used_by_bfd == NULL)
3167
      return false;
3168
  }
3169
      if (pei_section_data (abfd, current) == NULL)
3170
  {
3171
    size_t amt = sizeof (struct pei_section_tdata);
3172
3173
    coff_section_data (abfd, current)->tdata = bfd_zalloc (abfd, amt);
3174
    if (coff_section_data (abfd, current)->tdata == NULL)
3175
      return false;
3176
  }
3177
      if (pei_section_data (abfd, current)->virt_size == 0)
3178
  pei_section_data (abfd, current)->virt_size = current->size;
3179
#endif
3180
3181
      /* Only deal with sections which have contents.  */
3182
0
      if (!(current->flags & SEC_HAS_CONTENTS))
3183
0
  continue;
3184
3185
0
      current->rawsize = current->size;
3186
3187
#ifdef COFF_IMAGE_WITH_PE
3188
      /* Make sure we skip empty sections in a PE image.  */
3189
      if (current->size == 0)
3190
  continue;
3191
#endif
3192
3193
      /* Align the sections in the file to the same boundary on
3194
   which they are aligned in virtual memory.  */
3195
0
#ifdef ALIGN_SECTIONS_IN_FILE
3196
0
      if ((abfd->flags & EXEC_P) != 0)
3197
0
  {
3198
    /* Make sure this section is aligned on the right boundary - by
3199
       padding the previous section up if necessary.  */
3200
0
    old_sofar = sofar;
3201
3202
#ifdef COFF_IMAGE_WITH_PE
3203
    sofar = BFD_ALIGN (sofar, page_size);
3204
#else
3205
0
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3206
0
#endif
3207
3208
#ifdef RS6000COFF_C
3209
    /* Make sure the file offset and the vma of .text/.data are at the
3210
       same page offset, so that the file can be mmap'ed without being
3211
       relocated.  Failing that, AIX is able to load and execute the
3212
       program, but it will be silently relocated (possible as
3213
       executables are PIE).  But the relocation is slightly costly and
3214
       complexify the use of addr2line or gdb.  So better to avoid it,
3215
       like does the native linker.  Usually gnu ld makes sure that
3216
       the vma of .text is the file offset so this issue shouldn't
3217
       appear unless you are stripping such an executable.
3218
3219
       AIX loader checks the text section alignment of (vma - filepos),
3220
       and the native linker doesn't try to align the text sections.
3221
       For example:
3222
3223
       0 .text       000054cc  10000128  10000128  00000128  2**5
3224
           CONTENTS, ALLOC, LOAD, CODE
3225
3226
       Don't perform the above tweak if the previous one is .tdata,
3227
       as it will increase the memory allocated for every threads
3228
       created and not just improve performances with gdb.
3229
    */
3230
3231
    if ((current->flags & SEC_LOAD) != 0
3232
        && (!strcmp (current->name, _TEXT)
3233
      || !strcmp (current->name, _DATA))
3234
        && (previous == NULL || strcmp(previous->name, _TDATA)))
3235
      {
3236
        bfd_vma align = 4096;
3237
        bfd_vma sofar_off = sofar % align;
3238
        bfd_vma vma_off = current->vma % align;
3239
3240
        if (vma_off > sofar_off)
3241
    sofar += vma_off - sofar_off;
3242
        else if (vma_off < sofar_off)
3243
    sofar += align + vma_off - sofar_off;
3244
      }
3245
#endif
3246
0
    if (previous != NULL
3247
0
        && (previous->flags & SEC_LOAD) != 0)
3248
0
      previous->size += sofar - old_sofar;
3249
0
  }
3250
3251
0
#endif
3252
3253
      /* In demand paged files the low order bits of the file offset
3254
   must match the low order bits of the virtual address.  */
3255
0
#ifdef COFF_PAGE_SIZE
3256
0
      if ((abfd->flags & D_PAGED) != 0
3257
0
    && (current->flags & SEC_ALLOC) != 0)
3258
0
  sofar += (current->vma - (bfd_vma) sofar) % page_size;
3259
0
#endif
3260
0
      current->filepos = sofar;
3261
3262
#ifdef COFF_IMAGE_WITH_PE
3263
      /* Set the padded size.  */
3264
      current->size = (current->size + page_size - 1) & -page_size;
3265
#endif
3266
3267
0
      sofar += current->size;
3268
3269
0
#ifdef ALIGN_SECTIONS_IN_FILE
3270
      /* Make sure that this section is of the right size too.  */
3271
0
      if ((abfd->flags & EXEC_P) == 0)
3272
0
  {
3273
0
    bfd_size_type old_size;
3274
3275
0
    old_size = current->size;
3276
0
    current->size = BFD_ALIGN (current->size,
3277
0
             (bfd_vma) 1 << current->alignment_power);
3278
0
    align_adjust = current->size != old_size;
3279
0
    sofar += current->size - old_size;
3280
0
  }
3281
0
      else
3282
0
  {
3283
0
    old_sofar = sofar;
3284
#ifdef COFF_IMAGE_WITH_PE
3285
    sofar = BFD_ALIGN (sofar, page_size);
3286
#else
3287
0
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3288
0
#endif
3289
0
    align_adjust = sofar != old_sofar;
3290
0
    current->size += sofar - old_sofar;
3291
0
  }
3292
0
#endif
3293
3294
#ifdef COFF_IMAGE_WITH_PE
3295
      /* For PE we need to make sure we pad out to the aligned
3296
   size, in case the caller only writes out data to the
3297
   unaligned size.  */
3298
      if (pei_section_data (abfd, current)->virt_size < current->size)
3299
  align_adjust = true;
3300
#endif
3301
3302
0
#ifdef _LIB
3303
      /* Force .lib sections to start at zero.  The vma is then
3304
   incremented in coff_set_section_contents.  This is right for
3305
   SVR3.2.  */
3306
0
      if (strcmp (current->name, _LIB) == 0)
3307
0
  bfd_set_section_vma (current, 0);
3308
0
#endif
3309
3310
0
#ifdef ALIGN_SECTIONS_IN_FILE
3311
0
      previous = current;
3312
0
#endif
3313
0
    }
3314
3315
  /* It is now safe to write to the output file.  If we needed an
3316
     alignment adjustment for the last section, then make sure that
3317
     there is a byte at offset sofar.  If there are no symbols and no
3318
     relocs, then nothing follows the last section.  If we don't force
3319
     the last byte out, then the file may appear to be truncated.  */
3320
1
  if (align_adjust)
3321
0
    {
3322
0
      bfd_byte b;
3323
3324
0
      b = 0;
3325
0
      if (bfd_seek (abfd, sofar - 1, SEEK_SET) != 0
3326
0
    || bfd_write (&b, 1, abfd) != 1)
3327
0
  return false;
3328
0
    }
3329
3330
  /* Make sure the relocations are aligned.  We don't need to make
3331
     sure that this byte exists, because it will only matter if there
3332
     really are relocs.  */
3333
1
  sofar = BFD_ALIGN (sofar,
3334
1
         (bfd_vma) 1 << COFF_DEFAULT_SECTION_ALIGNMENT_POWER);
3335
3336
1
  obj_relocbase (abfd) = sofar;
3337
1
  abfd->output_has_begun = true;
3338
3339
1
  return true;
3340
1
}
pei-x86_64.c:coff_compute_section_file_positions
Line
Count
Source
2966
8
{
2967
8
  asection *current;
2968
8
  file_ptr sofar = bfd_coff_filhsz (abfd);
2969
8
  bool align_adjust;
2970
8
  unsigned int target_index;
2971
8
#ifdef ALIGN_SECTIONS_IN_FILE
2972
8
  asection *previous = NULL;
2973
8
  file_ptr old_sofar;
2974
8
#endif
2975
2976
8
#ifdef COFF_IMAGE_WITH_PE
2977
8
  unsigned int page_size;
2978
2979
8
  if (coff_data (abfd)->link_info
2980
8
      || (pe_data (abfd) && pe_data (abfd)->pe_opthdr.FileAlignment))
2981
8
    {
2982
8
      page_size = pe_data (abfd)->pe_opthdr.FileAlignment;
2983
2984
      /* If no file alignment has been set, default to one.
2985
   This repairs 'ld -r' for arm-wince-pe target.  */
2986
8
      if (page_size == 0)
2987
0
  page_size = 1;
2988
8
    }
2989
0
  else
2990
0
    page_size = PE_DEF_FILE_ALIGNMENT;
2991
#else
2992
#ifdef COFF_PAGE_SIZE
2993
  unsigned int page_size = COFF_PAGE_SIZE;
2994
#endif
2995
#endif
2996
2997
#ifdef RS6000COFF_C
2998
  /* On XCOFF, if we have symbols, set up the .debug section.  */
2999
  if (bfd_get_symcount (abfd) > 0)
3000
    {
3001
      bfd_size_type sz;
3002
      bfd_size_type i, symcount;
3003
      asymbol **symp;
3004
3005
      sz = 0;
3006
      symcount = bfd_get_symcount (abfd);
3007
      for (symp = abfd->outsymbols, i = 0; i < symcount; symp++, i++)
3008
  {
3009
    coff_symbol_type *cf;
3010
3011
    cf = coff_symbol_from (*symp);
3012
    if (cf != NULL
3013
        && cf->native != NULL
3014
        && cf->native->is_sym
3015
        && SYMNAME_IN_DEBUG (&cf->native->u.syment))
3016
      {
3017
        size_t len;
3018
3019
        len = strlen (bfd_asymbol_name (*symp));
3020
        if (len > SYMNMLEN || bfd_coff_force_symnames_in_strings (abfd))
3021
    sz += len + 1 + bfd_coff_debug_string_prefix_length (abfd);
3022
      }
3023
  }
3024
      if (sz > 0)
3025
  {
3026
    asection *dsec;
3027
3028
    dsec = bfd_make_section_old_way (abfd, DOT_DEBUG);
3029
    if (dsec == NULL)
3030
      abort ();
3031
    dsec->size = sz;
3032
    dsec->flags |= SEC_HAS_CONTENTS;
3033
  }
3034
    }
3035
#endif
3036
3037
8
  if (bfd_get_start_address (abfd))
3038
    /*  A start address may have been added to the original file. In this
3039
  case it will need an optional header to record it.  */
3040
3
    abfd->flags |= EXEC_P;
3041
3042
8
  if (abfd->flags & EXEC_P)
3043
8
    sofar += bfd_coff_aoutsz (abfd);
3044
#ifdef RS6000COFF_C
3045
  else if (xcoff_data (abfd)->full_aouthdr)
3046
    sofar += bfd_coff_aoutsz (abfd);
3047
  else
3048
    sofar += SMALL_AOUTSZ;
3049
#endif
3050
3051
8
  sofar += abfd->section_count * bfd_coff_scnhsz (abfd);
3052
3053
#ifdef RS6000COFF_C
3054
  /* XCOFF handles overflows in the reloc and line number count fields
3055
     by allocating a new section header to hold the correct counts.  */
3056
  for (current = abfd->sections; current != NULL; current = current->next)
3057
    if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3058
      sofar += bfd_coff_scnhsz (abfd);
3059
#endif
3060
3061
8
  if (coff_data (abfd)->section_by_target_index)
3062
0
    htab_empty (coff_data (abfd)->section_by_target_index);
3063
3064
8
#ifdef COFF_IMAGE_WITH_PE
3065
8
  {
3066
    /* PE requires the sections to be in memory order when listed in
3067
       the section headers.  It also does not like empty loadable
3068
       sections.  The sections apparently do not have to be in the
3069
       right order in the image file itself, but we do need to get the
3070
       target_index values right.  */
3071
3072
8
    unsigned int count;
3073
8
    asection **section_list;
3074
8
    unsigned int i;
3075
8
    bfd_size_type amt;
3076
3077
8
#ifdef COFF_PAGE_SIZE
3078
    /* Clear D_PAGED if section / file alignment aren't suitable for
3079
       paging at COFF_PAGE_SIZE granularity.  */
3080
8
   if (pe_data (abfd)->pe_opthdr.SectionAlignment < COFF_PAGE_SIZE
3081
8
       || page_size < COFF_PAGE_SIZE)
3082
8
     abfd->flags &= ~D_PAGED;
3083
8
#endif
3084
3085
8
    count = 0;
3086
83
    for (current = abfd->sections; current != NULL; current = current->next)
3087
75
      ++count;
3088
3089
    /* We allocate an extra cell to simplify the final loop.  */
3090
8
    amt = sizeof (struct asection *) * (count + 1);
3091
8
    section_list = (asection **) bfd_malloc (amt);
3092
8
    if (section_list == NULL)
3093
0
      return false;
3094
3095
8
    i = 0;
3096
83
    for (current = abfd->sections; current != NULL; current = current->next)
3097
75
      {
3098
75
  section_list[i] = current;
3099
75
  ++i;
3100
75
      }
3101
8
    section_list[i] = NULL;
3102
3103
8
    qsort (section_list, count, sizeof (asection *), sort_by_secaddr);
3104
3105
    /* Rethread the linked list into sorted order; at the same time,
3106
       assign target_index values.  */
3107
8
    target_index = 1;
3108
8
    abfd->sections = NULL;
3109
8
    abfd->section_last = NULL;
3110
83
    for (i = 0; i < count; i++)
3111
75
      {
3112
75
  current = section_list[i];
3113
75
  bfd_section_list_append (abfd, current);
3114
3115
  /* Later, if the section has zero size, we'll be throwing it
3116
     away, so we don't want to number it now.  Note that having
3117
     a zero size and having real contents are different
3118
     concepts: .bss has no contents, but (usually) non-zero
3119
     size.  */
3120
75
  if (current->size == 0)
3121
0
    {
3122
      /* Discard.  However, it still might have (valid) symbols
3123
         in it, so arbitrarily set it to section 1 (indexing is
3124
         1-based here; usually .text).  __end__ and other
3125
         contents of .endsection really have this happen.
3126
         FIXME: This seems somewhat dubious.  */
3127
0
      current->target_index = 1;
3128
0
    }
3129
75
  else
3130
75
    current->target_index = target_index++;
3131
75
      }
3132
3133
8
    free (section_list);
3134
8
  }
3135
#else /* ! COFF_IMAGE_WITH_PE */
3136
  {
3137
    /* Set the target_index field.  */
3138
    target_index = 1;
3139
    for (current = abfd->sections; current != NULL; current = current->next)
3140
      current->target_index = target_index++;
3141
  }
3142
#endif /* ! COFF_IMAGE_WITH_PE */
3143
3144
8
  if (target_index >= bfd_coff_max_nscns (abfd))
3145
0
    {
3146
0
      bfd_set_error (bfd_error_file_too_big);
3147
0
      _bfd_error_handler
3148
  /* xgettext:c-format */
3149
0
  (_("%pB: too many sections (%d)"), abfd, target_index);
3150
0
      return false;
3151
0
    }
3152
3153
8
  align_adjust = false;
3154
8
  for (current = abfd->sections;
3155
83
       current != NULL;
3156
75
       current = current->next)
3157
75
    {
3158
75
#ifdef COFF_IMAGE_WITH_PE
3159
      /* With PE we have to pad each section to be a multiple of its
3160
   page size too, and remember both sizes.  */
3161
75
      if (coff_section_data (abfd, current) == NULL)
3162
6
  {
3163
6
    size_t amt = sizeof (struct coff_section_tdata);
3164
3165
6
    current->used_by_bfd = bfd_zalloc (abfd, amt);
3166
6
    if (current->used_by_bfd == NULL)
3167
0
      return false;
3168
6
  }
3169
75
      if (pei_section_data (abfd, current) == NULL)
3170
6
  {
3171
6
    size_t amt = sizeof (struct pei_section_tdata);
3172
3173
6
    coff_section_data (abfd, current)->tdata = bfd_zalloc (abfd, amt);
3174
6
    if (coff_section_data (abfd, current)->tdata == NULL)
3175
0
      return false;
3176
6
  }
3177
75
      if (pei_section_data (abfd, current)->virt_size == 0)
3178
6
  pei_section_data (abfd, current)->virt_size = current->size;
3179
75
#endif
3180
3181
      /* Only deal with sections which have contents.  */
3182
75
      if (!(current->flags & SEC_HAS_CONTENTS))
3183
3
  continue;
3184
3185
72
      current->rawsize = current->size;
3186
3187
72
#ifdef COFF_IMAGE_WITH_PE
3188
      /* Make sure we skip empty sections in a PE image.  */
3189
72
      if (current->size == 0)
3190
0
  continue;
3191
72
#endif
3192
3193
      /* Align the sections in the file to the same boundary on
3194
   which they are aligned in virtual memory.  */
3195
72
#ifdef ALIGN_SECTIONS_IN_FILE
3196
72
      if ((abfd->flags & EXEC_P) != 0)
3197
72
  {
3198
    /* Make sure this section is aligned on the right boundary - by
3199
       padding the previous section up if necessary.  */
3200
72
    old_sofar = sofar;
3201
3202
72
#ifdef COFF_IMAGE_WITH_PE
3203
72
    sofar = BFD_ALIGN (sofar, page_size);
3204
#else
3205
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3206
#endif
3207
3208
#ifdef RS6000COFF_C
3209
    /* Make sure the file offset and the vma of .text/.data are at the
3210
       same page offset, so that the file can be mmap'ed without being
3211
       relocated.  Failing that, AIX is able to load and execute the
3212
       program, but it will be silently relocated (possible as
3213
       executables are PIE).  But the relocation is slightly costly and
3214
       complexify the use of addr2line or gdb.  So better to avoid it,
3215
       like does the native linker.  Usually gnu ld makes sure that
3216
       the vma of .text is the file offset so this issue shouldn't
3217
       appear unless you are stripping such an executable.
3218
3219
       AIX loader checks the text section alignment of (vma - filepos),
3220
       and the native linker doesn't try to align the text sections.
3221
       For example:
3222
3223
       0 .text       000054cc  10000128  10000128  00000128  2**5
3224
           CONTENTS, ALLOC, LOAD, CODE
3225
3226
       Don't perform the above tweak if the previous one is .tdata,
3227
       as it will increase the memory allocated for every threads
3228
       created and not just improve performances with gdb.
3229
    */
3230
3231
    if ((current->flags & SEC_LOAD) != 0
3232
        && (!strcmp (current->name, _TEXT)
3233
      || !strcmp (current->name, _DATA))
3234
        && (previous == NULL || strcmp(previous->name, _TDATA)))
3235
      {
3236
        bfd_vma align = 4096;
3237
        bfd_vma sofar_off = sofar % align;
3238
        bfd_vma vma_off = current->vma % align;
3239
3240
        if (vma_off > sofar_off)
3241
    sofar += vma_off - sofar_off;
3242
        else if (vma_off < sofar_off)
3243
    sofar += align + vma_off - sofar_off;
3244
      }
3245
#endif
3246
72
    if (previous != NULL
3247
72
        && (previous->flags & SEC_LOAD) != 0)
3248
39
      previous->size += sofar - old_sofar;
3249
72
  }
3250
3251
72
#endif
3252
3253
      /* In demand paged files the low order bits of the file offset
3254
   must match the low order bits of the virtual address.  */
3255
72
#ifdef COFF_PAGE_SIZE
3256
72
      if ((abfd->flags & D_PAGED) != 0
3257
72
    && (current->flags & SEC_ALLOC) != 0)
3258
0
  sofar += (current->vma - (bfd_vma) sofar) % page_size;
3259
72
#endif
3260
72
      current->filepos = sofar;
3261
3262
72
#ifdef COFF_IMAGE_WITH_PE
3263
      /* Set the padded size.  */
3264
72
      current->size = (current->size + page_size - 1) & -page_size;
3265
72
#endif
3266
3267
72
      sofar += current->size;
3268
3269
72
#ifdef ALIGN_SECTIONS_IN_FILE
3270
      /* Make sure that this section is of the right size too.  */
3271
72
      if ((abfd->flags & EXEC_P) == 0)
3272
0
  {
3273
0
    bfd_size_type old_size;
3274
3275
0
    old_size = current->size;
3276
0
    current->size = BFD_ALIGN (current->size,
3277
0
             (bfd_vma) 1 << current->alignment_power);
3278
0
    align_adjust = current->size != old_size;
3279
0
    sofar += current->size - old_size;
3280
0
  }
3281
72
      else
3282
72
  {
3283
72
    old_sofar = sofar;
3284
72
#ifdef COFF_IMAGE_WITH_PE
3285
72
    sofar = BFD_ALIGN (sofar, page_size);
3286
#else
3287
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3288
#endif
3289
72
    align_adjust = sofar != old_sofar;
3290
72
    current->size += sofar - old_sofar;
3291
72
  }
3292
72
#endif
3293
3294
72
#ifdef COFF_IMAGE_WITH_PE
3295
      /* For PE we need to make sure we pad out to the aligned
3296
   size, in case the caller only writes out data to the
3297
   unaligned size.  */
3298
72
      if (pei_section_data (abfd, current)->virt_size < current->size)
3299
52
  align_adjust = true;
3300
72
#endif
3301
3302
72
#ifdef _LIB
3303
      /* Force .lib sections to start at zero.  The vma is then
3304
   incremented in coff_set_section_contents.  This is right for
3305
   SVR3.2.  */
3306
72
      if (strcmp (current->name, _LIB) == 0)
3307
0
  bfd_set_section_vma (current, 0);
3308
72
#endif
3309
3310
72
#ifdef ALIGN_SECTIONS_IN_FILE
3311
72
      previous = current;
3312
72
#endif
3313
72
    }
3314
3315
  /* It is now safe to write to the output file.  If we needed an
3316
     alignment adjustment for the last section, then make sure that
3317
     there is a byte at offset sofar.  If there are no symbols and no
3318
     relocs, then nothing follows the last section.  If we don't force
3319
     the last byte out, then the file may appear to be truncated.  */
3320
8
  if (align_adjust)
3321
4
    {
3322
4
      bfd_byte b;
3323
3324
4
      b = 0;
3325
4
      if (bfd_seek (abfd, sofar - 1, SEEK_SET) != 0
3326
4
    || bfd_write (&b, 1, abfd) != 1)
3327
0
  return false;
3328
4
    }
3329
3330
  /* Make sure the relocations are aligned.  We don't need to make
3331
     sure that this byte exists, because it will only matter if there
3332
     really are relocs.  */
3333
8
  sofar = BFD_ALIGN (sofar,
3334
8
         (bfd_vma) 1 << COFF_DEFAULT_SECTION_ALIGNMENT_POWER);
3335
3336
8
  obj_relocbase (abfd) = sofar;
3337
8
  abfd->output_has_begun = true;
3338
3339
8
  return true;
3340
8
}
coff-x86_64.c:coff_compute_section_file_positions
Line
Count
Source
2966
2
{
2967
2
  asection *current;
2968
2
  file_ptr sofar = bfd_coff_filhsz (abfd);
2969
2
  bool align_adjust;
2970
2
  unsigned int target_index;
2971
2
#ifdef ALIGN_SECTIONS_IN_FILE
2972
2
  asection *previous = NULL;
2973
2
  file_ptr old_sofar;
2974
2
#endif
2975
2976
#ifdef COFF_IMAGE_WITH_PE
2977
  unsigned int page_size;
2978
2979
  if (coff_data (abfd)->link_info
2980
      || (pe_data (abfd) && pe_data (abfd)->pe_opthdr.FileAlignment))
2981
    {
2982
      page_size = pe_data (abfd)->pe_opthdr.FileAlignment;
2983
2984
      /* If no file alignment has been set, default to one.
2985
   This repairs 'ld -r' for arm-wince-pe target.  */
2986
      if (page_size == 0)
2987
  page_size = 1;
2988
    }
2989
  else
2990
    page_size = PE_DEF_FILE_ALIGNMENT;
2991
#else
2992
2
#ifdef COFF_PAGE_SIZE
2993
2
  unsigned int page_size = COFF_PAGE_SIZE;
2994
2
#endif
2995
2
#endif
2996
2997
#ifdef RS6000COFF_C
2998
  /* On XCOFF, if we have symbols, set up the .debug section.  */
2999
  if (bfd_get_symcount (abfd) > 0)
3000
    {
3001
      bfd_size_type sz;
3002
      bfd_size_type i, symcount;
3003
      asymbol **symp;
3004
3005
      sz = 0;
3006
      symcount = bfd_get_symcount (abfd);
3007
      for (symp = abfd->outsymbols, i = 0; i < symcount; symp++, i++)
3008
  {
3009
    coff_symbol_type *cf;
3010
3011
    cf = coff_symbol_from (*symp);
3012
    if (cf != NULL
3013
        && cf->native != NULL
3014
        && cf->native->is_sym
3015
        && SYMNAME_IN_DEBUG (&cf->native->u.syment))
3016
      {
3017
        size_t len;
3018
3019
        len = strlen (bfd_asymbol_name (*symp));
3020
        if (len > SYMNMLEN || bfd_coff_force_symnames_in_strings (abfd))
3021
    sz += len + 1 + bfd_coff_debug_string_prefix_length (abfd);
3022
      }
3023
  }
3024
      if (sz > 0)
3025
  {
3026
    asection *dsec;
3027
3028
    dsec = bfd_make_section_old_way (abfd, DOT_DEBUG);
3029
    if (dsec == NULL)
3030
      abort ();
3031
    dsec->size = sz;
3032
    dsec->flags |= SEC_HAS_CONTENTS;
3033
  }
3034
    }
3035
#endif
3036
3037
2
  if (bfd_get_start_address (abfd))
3038
    /*  A start address may have been added to the original file. In this
3039
  case it will need an optional header to record it.  */
3040
0
    abfd->flags |= EXEC_P;
3041
3042
2
  if (abfd->flags & EXEC_P)
3043
2
    sofar += bfd_coff_aoutsz (abfd);
3044
#ifdef RS6000COFF_C
3045
  else if (xcoff_data (abfd)->full_aouthdr)
3046
    sofar += bfd_coff_aoutsz (abfd);
3047
  else
3048
    sofar += SMALL_AOUTSZ;
3049
#endif
3050
3051
2
  sofar += abfd->section_count * bfd_coff_scnhsz (abfd);
3052
3053
#ifdef RS6000COFF_C
3054
  /* XCOFF handles overflows in the reloc and line number count fields
3055
     by allocating a new section header to hold the correct counts.  */
3056
  for (current = abfd->sections; current != NULL; current = current->next)
3057
    if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3058
      sofar += bfd_coff_scnhsz (abfd);
3059
#endif
3060
3061
2
  if (coff_data (abfd)->section_by_target_index)
3062
0
    htab_empty (coff_data (abfd)->section_by_target_index);
3063
3064
#ifdef COFF_IMAGE_WITH_PE
3065
  {
3066
    /* PE requires the sections to be in memory order when listed in
3067
       the section headers.  It also does not like empty loadable
3068
       sections.  The sections apparently do not have to be in the
3069
       right order in the image file itself, but we do need to get the
3070
       target_index values right.  */
3071
3072
    unsigned int count;
3073
    asection **section_list;
3074
    unsigned int i;
3075
    bfd_size_type amt;
3076
3077
#ifdef COFF_PAGE_SIZE
3078
    /* Clear D_PAGED if section / file alignment aren't suitable for
3079
       paging at COFF_PAGE_SIZE granularity.  */
3080
   if (pe_data (abfd)->pe_opthdr.SectionAlignment < COFF_PAGE_SIZE
3081
       || page_size < COFF_PAGE_SIZE)
3082
     abfd->flags &= ~D_PAGED;
3083
#endif
3084
3085
    count = 0;
3086
    for (current = abfd->sections; current != NULL; current = current->next)
3087
      ++count;
3088
3089
    /* We allocate an extra cell to simplify the final loop.  */
3090
    amt = sizeof (struct asection *) * (count + 1);
3091
    section_list = (asection **) bfd_malloc (amt);
3092
    if (section_list == NULL)
3093
      return false;
3094
3095
    i = 0;
3096
    for (current = abfd->sections; current != NULL; current = current->next)
3097
      {
3098
  section_list[i] = current;
3099
  ++i;
3100
      }
3101
    section_list[i] = NULL;
3102
3103
    qsort (section_list, count, sizeof (asection *), sort_by_secaddr);
3104
3105
    /* Rethread the linked list into sorted order; at the same time,
3106
       assign target_index values.  */
3107
    target_index = 1;
3108
    abfd->sections = NULL;
3109
    abfd->section_last = NULL;
3110
    for (i = 0; i < count; i++)
3111
      {
3112
  current = section_list[i];
3113
  bfd_section_list_append (abfd, current);
3114
3115
  /* Later, if the section has zero size, we'll be throwing it
3116
     away, so we don't want to number it now.  Note that having
3117
     a zero size and having real contents are different
3118
     concepts: .bss has no contents, but (usually) non-zero
3119
     size.  */
3120
  if (current->size == 0)
3121
    {
3122
      /* Discard.  However, it still might have (valid) symbols
3123
         in it, so arbitrarily set it to section 1 (indexing is
3124
         1-based here; usually .text).  __end__ and other
3125
         contents of .endsection really have this happen.
3126
         FIXME: This seems somewhat dubious.  */
3127
      current->target_index = 1;
3128
    }
3129
  else
3130
    current->target_index = target_index++;
3131
      }
3132
3133
    free (section_list);
3134
  }
3135
#else /* ! COFF_IMAGE_WITH_PE */
3136
2
  {
3137
    /* Set the target_index field.  */
3138
2
    target_index = 1;
3139
2
    for (current = abfd->sections; current != NULL; current = current->next)
3140
0
      current->target_index = target_index++;
3141
2
  }
3142
2
#endif /* ! COFF_IMAGE_WITH_PE */
3143
3144
2
  if (target_index >= bfd_coff_max_nscns (abfd))
3145
0
    {
3146
0
      bfd_set_error (bfd_error_file_too_big);
3147
0
      _bfd_error_handler
3148
  /* xgettext:c-format */
3149
0
  (_("%pB: too many sections (%d)"), abfd, target_index);
3150
0
      return false;
3151
0
    }
3152
3153
2
  align_adjust = false;
3154
2
  for (current = abfd->sections;
3155
2
       current != NULL;
3156
2
       current = current->next)
3157
0
    {
3158
#ifdef COFF_IMAGE_WITH_PE
3159
      /* With PE we have to pad each section to be a multiple of its
3160
   page size too, and remember both sizes.  */
3161
      if (coff_section_data (abfd, current) == NULL)
3162
  {
3163
    size_t amt = sizeof (struct coff_section_tdata);
3164
3165
    current->used_by_bfd = bfd_zalloc (abfd, amt);
3166
    if (current->used_by_bfd == NULL)
3167
      return false;
3168
  }
3169
      if (pei_section_data (abfd, current) == NULL)
3170
  {
3171
    size_t amt = sizeof (struct pei_section_tdata);
3172
3173
    coff_section_data (abfd, current)->tdata = bfd_zalloc (abfd, amt);
3174
    if (coff_section_data (abfd, current)->tdata == NULL)
3175
      return false;
3176
  }
3177
      if (pei_section_data (abfd, current)->virt_size == 0)
3178
  pei_section_data (abfd, current)->virt_size = current->size;
3179
#endif
3180
3181
      /* Only deal with sections which have contents.  */
3182
0
      if (!(current->flags & SEC_HAS_CONTENTS))
3183
0
  continue;
3184
3185
0
      current->rawsize = current->size;
3186
3187
#ifdef COFF_IMAGE_WITH_PE
3188
      /* Make sure we skip empty sections in a PE image.  */
3189
      if (current->size == 0)
3190
  continue;
3191
#endif
3192
3193
      /* Align the sections in the file to the same boundary on
3194
   which they are aligned in virtual memory.  */
3195
0
#ifdef ALIGN_SECTIONS_IN_FILE
3196
0
      if ((abfd->flags & EXEC_P) != 0)
3197
0
  {
3198
    /* Make sure this section is aligned on the right boundary - by
3199
       padding the previous section up if necessary.  */
3200
0
    old_sofar = sofar;
3201
3202
#ifdef COFF_IMAGE_WITH_PE
3203
    sofar = BFD_ALIGN (sofar, page_size);
3204
#else
3205
0
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3206
0
#endif
3207
3208
#ifdef RS6000COFF_C
3209
    /* Make sure the file offset and the vma of .text/.data are at the
3210
       same page offset, so that the file can be mmap'ed without being
3211
       relocated.  Failing that, AIX is able to load and execute the
3212
       program, but it will be silently relocated (possible as
3213
       executables are PIE).  But the relocation is slightly costly and
3214
       complexify the use of addr2line or gdb.  So better to avoid it,
3215
       like does the native linker.  Usually gnu ld makes sure that
3216
       the vma of .text is the file offset so this issue shouldn't
3217
       appear unless you are stripping such an executable.
3218
3219
       AIX loader checks the text section alignment of (vma - filepos),
3220
       and the native linker doesn't try to align the text sections.
3221
       For example:
3222
3223
       0 .text       000054cc  10000128  10000128  00000128  2**5
3224
           CONTENTS, ALLOC, LOAD, CODE
3225
3226
       Don't perform the above tweak if the previous one is .tdata,
3227
       as it will increase the memory allocated for every threads
3228
       created and not just improve performances with gdb.
3229
    */
3230
3231
    if ((current->flags & SEC_LOAD) != 0
3232
        && (!strcmp (current->name, _TEXT)
3233
      || !strcmp (current->name, _DATA))
3234
        && (previous == NULL || strcmp(previous->name, _TDATA)))
3235
      {
3236
        bfd_vma align = 4096;
3237
        bfd_vma sofar_off = sofar % align;
3238
        bfd_vma vma_off = current->vma % align;
3239
3240
        if (vma_off > sofar_off)
3241
    sofar += vma_off - sofar_off;
3242
        else if (vma_off < sofar_off)
3243
    sofar += align + vma_off - sofar_off;
3244
      }
3245
#endif
3246
0
    if (previous != NULL
3247
0
        && (previous->flags & SEC_LOAD) != 0)
3248
0
      previous->size += sofar - old_sofar;
3249
0
  }
3250
3251
0
#endif
3252
3253
      /* In demand paged files the low order bits of the file offset
3254
   must match the low order bits of the virtual address.  */
3255
0
#ifdef COFF_PAGE_SIZE
3256
0
      if ((abfd->flags & D_PAGED) != 0
3257
0
    && (current->flags & SEC_ALLOC) != 0)
3258
0
  sofar += (current->vma - (bfd_vma) sofar) % page_size;
3259
0
#endif
3260
0
      current->filepos = sofar;
3261
3262
#ifdef COFF_IMAGE_WITH_PE
3263
      /* Set the padded size.  */
3264
      current->size = (current->size + page_size - 1) & -page_size;
3265
#endif
3266
3267
0
      sofar += current->size;
3268
3269
0
#ifdef ALIGN_SECTIONS_IN_FILE
3270
      /* Make sure that this section is of the right size too.  */
3271
0
      if ((abfd->flags & EXEC_P) == 0)
3272
0
  {
3273
0
    bfd_size_type old_size;
3274
3275
0
    old_size = current->size;
3276
0
    current->size = BFD_ALIGN (current->size,
3277
0
             (bfd_vma) 1 << current->alignment_power);
3278
0
    align_adjust = current->size != old_size;
3279
0
    sofar += current->size - old_size;
3280
0
  }
3281
0
      else
3282
0
  {
3283
0
    old_sofar = sofar;
3284
#ifdef COFF_IMAGE_WITH_PE
3285
    sofar = BFD_ALIGN (sofar, page_size);
3286
#else
3287
0
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3288
0
#endif
3289
0
    align_adjust = sofar != old_sofar;
3290
0
    current->size += sofar - old_sofar;
3291
0
  }
3292
0
#endif
3293
3294
#ifdef COFF_IMAGE_WITH_PE
3295
      /* For PE we need to make sure we pad out to the aligned
3296
   size, in case the caller only writes out data to the
3297
   unaligned size.  */
3298
      if (pei_section_data (abfd, current)->virt_size < current->size)
3299
  align_adjust = true;
3300
#endif
3301
3302
0
#ifdef _LIB
3303
      /* Force .lib sections to start at zero.  The vma is then
3304
   incremented in coff_set_section_contents.  This is right for
3305
   SVR3.2.  */
3306
0
      if (strcmp (current->name, _LIB) == 0)
3307
0
  bfd_set_section_vma (current, 0);
3308
0
#endif
3309
3310
0
#ifdef ALIGN_SECTIONS_IN_FILE
3311
0
      previous = current;
3312
0
#endif
3313
0
    }
3314
3315
  /* It is now safe to write to the output file.  If we needed an
3316
     alignment adjustment for the last section, then make sure that
3317
     there is a byte at offset sofar.  If there are no symbols and no
3318
     relocs, then nothing follows the last section.  If we don't force
3319
     the last byte out, then the file may appear to be truncated.  */
3320
2
  if (align_adjust)
3321
0
    {
3322
0
      bfd_byte b;
3323
3324
0
      b = 0;
3325
0
      if (bfd_seek (abfd, sofar - 1, SEEK_SET) != 0
3326
0
    || bfd_write (&b, 1, abfd) != 1)
3327
0
  return false;
3328
0
    }
3329
3330
  /* Make sure the relocations are aligned.  We don't need to make
3331
     sure that this byte exists, because it will only matter if there
3332
     really are relocs.  */
3333
2
  sofar = BFD_ALIGN (sofar,
3334
2
         (bfd_vma) 1 << COFF_DEFAULT_SECTION_ALIGNMENT_POWER);
3335
3336
2
  obj_relocbase (abfd) = sofar;
3337
2
  abfd->output_has_begun = true;
3338
3339
2
  return true;
3340
2
}
coff64-rs6000.c:coff_compute_section_file_positions
Line
Count
Source
2966
1
{
2967
1
  asection *current;
2968
1
  file_ptr sofar = bfd_coff_filhsz (abfd);
2969
1
  bool align_adjust;
2970
1
  unsigned int target_index;
2971
1
#ifdef ALIGN_SECTIONS_IN_FILE
2972
1
  asection *previous = NULL;
2973
1
  file_ptr old_sofar;
2974
1
#endif
2975
2976
#ifdef COFF_IMAGE_WITH_PE
2977
  unsigned int page_size;
2978
2979
  if (coff_data (abfd)->link_info
2980
      || (pe_data (abfd) && pe_data (abfd)->pe_opthdr.FileAlignment))
2981
    {
2982
      page_size = pe_data (abfd)->pe_opthdr.FileAlignment;
2983
2984
      /* If no file alignment has been set, default to one.
2985
   This repairs 'ld -r' for arm-wince-pe target.  */
2986
      if (page_size == 0)
2987
  page_size = 1;
2988
    }
2989
  else
2990
    page_size = PE_DEF_FILE_ALIGNMENT;
2991
#else
2992
#ifdef COFF_PAGE_SIZE
2993
  unsigned int page_size = COFF_PAGE_SIZE;
2994
#endif
2995
1
#endif
2996
2997
1
#ifdef RS6000COFF_C
2998
  /* On XCOFF, if we have symbols, set up the .debug section.  */
2999
1
  if (bfd_get_symcount (abfd) > 0)
3000
0
    {
3001
0
      bfd_size_type sz;
3002
0
      bfd_size_type i, symcount;
3003
0
      asymbol **symp;
3004
3005
0
      sz = 0;
3006
0
      symcount = bfd_get_symcount (abfd);
3007
0
      for (symp = abfd->outsymbols, i = 0; i < symcount; symp++, i++)
3008
0
  {
3009
0
    coff_symbol_type *cf;
3010
3011
0
    cf = coff_symbol_from (*symp);
3012
0
    if (cf != NULL
3013
0
        && cf->native != NULL
3014
0
        && cf->native->is_sym
3015
0
        && SYMNAME_IN_DEBUG (&cf->native->u.syment))
3016
0
      {
3017
0
        size_t len;
3018
3019
0
        len = strlen (bfd_asymbol_name (*symp));
3020
0
        if (len > SYMNMLEN || bfd_coff_force_symnames_in_strings (abfd))
3021
0
    sz += len + 1 + bfd_coff_debug_string_prefix_length (abfd);
3022
0
      }
3023
0
  }
3024
0
      if (sz > 0)
3025
0
  {
3026
0
    asection *dsec;
3027
3028
0
    dsec = bfd_make_section_old_way (abfd, DOT_DEBUG);
3029
0
    if (dsec == NULL)
3030
0
      abort ();
3031
0
    dsec->size = sz;
3032
0
    dsec->flags |= SEC_HAS_CONTENTS;
3033
0
  }
3034
0
    }
3035
1
#endif
3036
3037
1
  if (bfd_get_start_address (abfd))
3038
    /*  A start address may have been added to the original file. In this
3039
  case it will need an optional header to record it.  */
3040
0
    abfd->flags |= EXEC_P;
3041
3042
1
  if (abfd->flags & EXEC_P)
3043
0
    sofar += bfd_coff_aoutsz (abfd);
3044
1
#ifdef RS6000COFF_C
3045
1
  else if (xcoff_data (abfd)->full_aouthdr)
3046
0
    sofar += bfd_coff_aoutsz (abfd);
3047
1
  else
3048
1
    sofar += SMALL_AOUTSZ;
3049
1
#endif
3050
3051
1
  sofar += abfd->section_count * bfd_coff_scnhsz (abfd);
3052
3053
1
#ifdef RS6000COFF_C
3054
  /* XCOFF handles overflows in the reloc and line number count fields
3055
     by allocating a new section header to hold the correct counts.  */
3056
1
  for (current = abfd->sections; current != NULL; current = current->next)
3057
0
    if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3058
0
      sofar += bfd_coff_scnhsz (abfd);
3059
1
#endif
3060
3061
1
  if (coff_data (abfd)->section_by_target_index)
3062
0
    htab_empty (coff_data (abfd)->section_by_target_index);
3063
3064
#ifdef COFF_IMAGE_WITH_PE
3065
  {
3066
    /* PE requires the sections to be in memory order when listed in
3067
       the section headers.  It also does not like empty loadable
3068
       sections.  The sections apparently do not have to be in the
3069
       right order in the image file itself, but we do need to get the
3070
       target_index values right.  */
3071
3072
    unsigned int count;
3073
    asection **section_list;
3074
    unsigned int i;
3075
    bfd_size_type amt;
3076
3077
#ifdef COFF_PAGE_SIZE
3078
    /* Clear D_PAGED if section / file alignment aren't suitable for
3079
       paging at COFF_PAGE_SIZE granularity.  */
3080
   if (pe_data (abfd)->pe_opthdr.SectionAlignment < COFF_PAGE_SIZE
3081
       || page_size < COFF_PAGE_SIZE)
3082
     abfd->flags &= ~D_PAGED;
3083
#endif
3084
3085
    count = 0;
3086
    for (current = abfd->sections; current != NULL; current = current->next)
3087
      ++count;
3088
3089
    /* We allocate an extra cell to simplify the final loop.  */
3090
    amt = sizeof (struct asection *) * (count + 1);
3091
    section_list = (asection **) bfd_malloc (amt);
3092
    if (section_list == NULL)
3093
      return false;
3094
3095
    i = 0;
3096
    for (current = abfd->sections; current != NULL; current = current->next)
3097
      {
3098
  section_list[i] = current;
3099
  ++i;
3100
      }
3101
    section_list[i] = NULL;
3102
3103
    qsort (section_list, count, sizeof (asection *), sort_by_secaddr);
3104
3105
    /* Rethread the linked list into sorted order; at the same time,
3106
       assign target_index values.  */
3107
    target_index = 1;
3108
    abfd->sections = NULL;
3109
    abfd->section_last = NULL;
3110
    for (i = 0; i < count; i++)
3111
      {
3112
  current = section_list[i];
3113
  bfd_section_list_append (abfd, current);
3114
3115
  /* Later, if the section has zero size, we'll be throwing it
3116
     away, so we don't want to number it now.  Note that having
3117
     a zero size and having real contents are different
3118
     concepts: .bss has no contents, but (usually) non-zero
3119
     size.  */
3120
  if (current->size == 0)
3121
    {
3122
      /* Discard.  However, it still might have (valid) symbols
3123
         in it, so arbitrarily set it to section 1 (indexing is
3124
         1-based here; usually .text).  __end__ and other
3125
         contents of .endsection really have this happen.
3126
         FIXME: This seems somewhat dubious.  */
3127
      current->target_index = 1;
3128
    }
3129
  else
3130
    current->target_index = target_index++;
3131
      }
3132
3133
    free (section_list);
3134
  }
3135
#else /* ! COFF_IMAGE_WITH_PE */
3136
1
  {
3137
    /* Set the target_index field.  */
3138
1
    target_index = 1;
3139
1
    for (current = abfd->sections; current != NULL; current = current->next)
3140
0
      current->target_index = target_index++;
3141
1
  }
3142
1
#endif /* ! COFF_IMAGE_WITH_PE */
3143
3144
1
  if (target_index >= bfd_coff_max_nscns (abfd))
3145
0
    {
3146
0
      bfd_set_error (bfd_error_file_too_big);
3147
0
      _bfd_error_handler
3148
  /* xgettext:c-format */
3149
0
  (_("%pB: too many sections (%d)"), abfd, target_index);
3150
0
      return false;
3151
0
    }
3152
3153
1
  align_adjust = false;
3154
1
  for (current = abfd->sections;
3155
1
       current != NULL;
3156
1
       current = current->next)
3157
0
    {
3158
#ifdef COFF_IMAGE_WITH_PE
3159
      /* With PE we have to pad each section to be a multiple of its
3160
   page size too, and remember both sizes.  */
3161
      if (coff_section_data (abfd, current) == NULL)
3162
  {
3163
    size_t amt = sizeof (struct coff_section_tdata);
3164
3165
    current->used_by_bfd = bfd_zalloc (abfd, amt);
3166
    if (current->used_by_bfd == NULL)
3167
      return false;
3168
  }
3169
      if (pei_section_data (abfd, current) == NULL)
3170
  {
3171
    size_t amt = sizeof (struct pei_section_tdata);
3172
3173
    coff_section_data (abfd, current)->tdata = bfd_zalloc (abfd, amt);
3174
    if (coff_section_data (abfd, current)->tdata == NULL)
3175
      return false;
3176
  }
3177
      if (pei_section_data (abfd, current)->virt_size == 0)
3178
  pei_section_data (abfd, current)->virt_size = current->size;
3179
#endif
3180
3181
      /* Only deal with sections which have contents.  */
3182
0
      if (!(current->flags & SEC_HAS_CONTENTS))
3183
0
  continue;
3184
3185
0
      current->rawsize = current->size;
3186
3187
#ifdef COFF_IMAGE_WITH_PE
3188
      /* Make sure we skip empty sections in a PE image.  */
3189
      if (current->size == 0)
3190
  continue;
3191
#endif
3192
3193
      /* Align the sections in the file to the same boundary on
3194
   which they are aligned in virtual memory.  */
3195
0
#ifdef ALIGN_SECTIONS_IN_FILE
3196
0
      if ((abfd->flags & EXEC_P) != 0)
3197
0
  {
3198
    /* Make sure this section is aligned on the right boundary - by
3199
       padding the previous section up if necessary.  */
3200
0
    old_sofar = sofar;
3201
3202
#ifdef COFF_IMAGE_WITH_PE
3203
    sofar = BFD_ALIGN (sofar, page_size);
3204
#else
3205
0
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3206
0
#endif
3207
3208
0
#ifdef RS6000COFF_C
3209
    /* Make sure the file offset and the vma of .text/.data are at the
3210
       same page offset, so that the file can be mmap'ed without being
3211
       relocated.  Failing that, AIX is able to load and execute the
3212
       program, but it will be silently relocated (possible as
3213
       executables are PIE).  But the relocation is slightly costly and
3214
       complexify the use of addr2line or gdb.  So better to avoid it,
3215
       like does the native linker.  Usually gnu ld makes sure that
3216
       the vma of .text is the file offset so this issue shouldn't
3217
       appear unless you are stripping such an executable.
3218
3219
       AIX loader checks the text section alignment of (vma - filepos),
3220
       and the native linker doesn't try to align the text sections.
3221
       For example:
3222
3223
       0 .text       000054cc  10000128  10000128  00000128  2**5
3224
           CONTENTS, ALLOC, LOAD, CODE
3225
3226
       Don't perform the above tweak if the previous one is .tdata,
3227
       as it will increase the memory allocated for every threads
3228
       created and not just improve performances with gdb.
3229
    */
3230
3231
0
    if ((current->flags & SEC_LOAD) != 0
3232
0
        && (!strcmp (current->name, _TEXT)
3233
0
      || !strcmp (current->name, _DATA))
3234
0
        && (previous == NULL || strcmp(previous->name, _TDATA)))
3235
0
      {
3236
0
        bfd_vma align = 4096;
3237
0
        bfd_vma sofar_off = sofar % align;
3238
0
        bfd_vma vma_off = current->vma % align;
3239
3240
0
        if (vma_off > sofar_off)
3241
0
    sofar += vma_off - sofar_off;
3242
0
        else if (vma_off < sofar_off)
3243
0
    sofar += align + vma_off - sofar_off;
3244
0
      }
3245
0
#endif
3246
0
    if (previous != NULL
3247
0
        && (previous->flags & SEC_LOAD) != 0)
3248
0
      previous->size += sofar - old_sofar;
3249
0
  }
3250
3251
0
#endif
3252
3253
      /* In demand paged files the low order bits of the file offset
3254
   must match the low order bits of the virtual address.  */
3255
#ifdef COFF_PAGE_SIZE
3256
      if ((abfd->flags & D_PAGED) != 0
3257
    && (current->flags & SEC_ALLOC) != 0)
3258
  sofar += (current->vma - (bfd_vma) sofar) % page_size;
3259
#endif
3260
0
      current->filepos = sofar;
3261
3262
#ifdef COFF_IMAGE_WITH_PE
3263
      /* Set the padded size.  */
3264
      current->size = (current->size + page_size - 1) & -page_size;
3265
#endif
3266
3267
0
      sofar += current->size;
3268
3269
0
#ifdef ALIGN_SECTIONS_IN_FILE
3270
      /* Make sure that this section is of the right size too.  */
3271
0
      if ((abfd->flags & EXEC_P) == 0)
3272
0
  {
3273
0
    bfd_size_type old_size;
3274
3275
0
    old_size = current->size;
3276
0
    current->size = BFD_ALIGN (current->size,
3277
0
             (bfd_vma) 1 << current->alignment_power);
3278
0
    align_adjust = current->size != old_size;
3279
0
    sofar += current->size - old_size;
3280
0
  }
3281
0
      else
3282
0
  {
3283
0
    old_sofar = sofar;
3284
#ifdef COFF_IMAGE_WITH_PE
3285
    sofar = BFD_ALIGN (sofar, page_size);
3286
#else
3287
0
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3288
0
#endif
3289
0
    align_adjust = sofar != old_sofar;
3290
0
    current->size += sofar - old_sofar;
3291
0
  }
3292
0
#endif
3293
3294
#ifdef COFF_IMAGE_WITH_PE
3295
      /* For PE we need to make sure we pad out to the aligned
3296
   size, in case the caller only writes out data to the
3297
   unaligned size.  */
3298
      if (pei_section_data (abfd, current)->virt_size < current->size)
3299
  align_adjust = true;
3300
#endif
3301
3302
#ifdef _LIB
3303
      /* Force .lib sections to start at zero.  The vma is then
3304
   incremented in coff_set_section_contents.  This is right for
3305
   SVR3.2.  */
3306
      if (strcmp (current->name, _LIB) == 0)
3307
  bfd_set_section_vma (current, 0);
3308
#endif
3309
3310
0
#ifdef ALIGN_SECTIONS_IN_FILE
3311
0
      previous = current;
3312
0
#endif
3313
0
    }
3314
3315
  /* It is now safe to write to the output file.  If we needed an
3316
     alignment adjustment for the last section, then make sure that
3317
     there is a byte at offset sofar.  If there are no symbols and no
3318
     relocs, then nothing follows the last section.  If we don't force
3319
     the last byte out, then the file may appear to be truncated.  */
3320
1
  if (align_adjust)
3321
0
    {
3322
0
      bfd_byte b;
3323
3324
0
      b = 0;
3325
0
      if (bfd_seek (abfd, sofar - 1, SEEK_SET) != 0
3326
0
    || bfd_write (&b, 1, abfd) != 1)
3327
0
  return false;
3328
0
    }
3329
3330
  /* Make sure the relocations are aligned.  We don't need to make
3331
     sure that this byte exists, because it will only matter if there
3332
     really are relocs.  */
3333
1
  sofar = BFD_ALIGN (sofar,
3334
1
         (bfd_vma) 1 << COFF_DEFAULT_SECTION_ALIGNMENT_POWER);
3335
3336
1
  obj_relocbase (abfd) = sofar;
3337
1
  abfd->output_has_begun = true;
3338
3339
1
  return true;
3340
1
}
pe-aarch64.c:coff_compute_section_file_positions
Line
Count
Source
2966
1
{
2967
1
  asection *current;
2968
1
  file_ptr sofar = bfd_coff_filhsz (abfd);
2969
1
  bool align_adjust;
2970
1
  unsigned int target_index;
2971
1
#ifdef ALIGN_SECTIONS_IN_FILE
2972
1
  asection *previous = NULL;
2973
1
  file_ptr old_sofar;
2974
1
#endif
2975
2976
#ifdef COFF_IMAGE_WITH_PE
2977
  unsigned int page_size;
2978
2979
  if (coff_data (abfd)->link_info
2980
      || (pe_data (abfd) && pe_data (abfd)->pe_opthdr.FileAlignment))
2981
    {
2982
      page_size = pe_data (abfd)->pe_opthdr.FileAlignment;
2983
2984
      /* If no file alignment has been set, default to one.
2985
   This repairs 'ld -r' for arm-wince-pe target.  */
2986
      if (page_size == 0)
2987
  page_size = 1;
2988
    }
2989
  else
2990
    page_size = PE_DEF_FILE_ALIGNMENT;
2991
#else
2992
1
#ifdef COFF_PAGE_SIZE
2993
1
  unsigned int page_size = COFF_PAGE_SIZE;
2994
1
#endif
2995
1
#endif
2996
2997
#ifdef RS6000COFF_C
2998
  /* On XCOFF, if we have symbols, set up the .debug section.  */
2999
  if (bfd_get_symcount (abfd) > 0)
3000
    {
3001
      bfd_size_type sz;
3002
      bfd_size_type i, symcount;
3003
      asymbol **symp;
3004
3005
      sz = 0;
3006
      symcount = bfd_get_symcount (abfd);
3007
      for (symp = abfd->outsymbols, i = 0; i < symcount; symp++, i++)
3008
  {
3009
    coff_symbol_type *cf;
3010
3011
    cf = coff_symbol_from (*symp);
3012
    if (cf != NULL
3013
        && cf->native != NULL
3014
        && cf->native->is_sym
3015
        && SYMNAME_IN_DEBUG (&cf->native->u.syment))
3016
      {
3017
        size_t len;
3018
3019
        len = strlen (bfd_asymbol_name (*symp));
3020
        if (len > SYMNMLEN || bfd_coff_force_symnames_in_strings (abfd))
3021
    sz += len + 1 + bfd_coff_debug_string_prefix_length (abfd);
3022
      }
3023
  }
3024
      if (sz > 0)
3025
  {
3026
    asection *dsec;
3027
3028
    dsec = bfd_make_section_old_way (abfd, DOT_DEBUG);
3029
    if (dsec == NULL)
3030
      abort ();
3031
    dsec->size = sz;
3032
    dsec->flags |= SEC_HAS_CONTENTS;
3033
  }
3034
    }
3035
#endif
3036
3037
1
  if (bfd_get_start_address (abfd))
3038
    /*  A start address may have been added to the original file. In this
3039
  case it will need an optional header to record it.  */
3040
0
    abfd->flags |= EXEC_P;
3041
3042
1
  if (abfd->flags & EXEC_P)
3043
0
    sofar += bfd_coff_aoutsz (abfd);
3044
#ifdef RS6000COFF_C
3045
  else if (xcoff_data (abfd)->full_aouthdr)
3046
    sofar += bfd_coff_aoutsz (abfd);
3047
  else
3048
    sofar += SMALL_AOUTSZ;
3049
#endif
3050
3051
1
  sofar += abfd->section_count * bfd_coff_scnhsz (abfd);
3052
3053
#ifdef RS6000COFF_C
3054
  /* XCOFF handles overflows in the reloc and line number count fields
3055
     by allocating a new section header to hold the correct counts.  */
3056
  for (current = abfd->sections; current != NULL; current = current->next)
3057
    if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3058
      sofar += bfd_coff_scnhsz (abfd);
3059
#endif
3060
3061
1
  if (coff_data (abfd)->section_by_target_index)
3062
0
    htab_empty (coff_data (abfd)->section_by_target_index);
3063
3064
#ifdef COFF_IMAGE_WITH_PE
3065
  {
3066
    /* PE requires the sections to be in memory order when listed in
3067
       the section headers.  It also does not like empty loadable
3068
       sections.  The sections apparently do not have to be in the
3069
       right order in the image file itself, but we do need to get the
3070
       target_index values right.  */
3071
3072
    unsigned int count;
3073
    asection **section_list;
3074
    unsigned int i;
3075
    bfd_size_type amt;
3076
3077
#ifdef COFF_PAGE_SIZE
3078
    /* Clear D_PAGED if section / file alignment aren't suitable for
3079
       paging at COFF_PAGE_SIZE granularity.  */
3080
   if (pe_data (abfd)->pe_opthdr.SectionAlignment < COFF_PAGE_SIZE
3081
       || page_size < COFF_PAGE_SIZE)
3082
     abfd->flags &= ~D_PAGED;
3083
#endif
3084
3085
    count = 0;
3086
    for (current = abfd->sections; current != NULL; current = current->next)
3087
      ++count;
3088
3089
    /* We allocate an extra cell to simplify the final loop.  */
3090
    amt = sizeof (struct asection *) * (count + 1);
3091
    section_list = (asection **) bfd_malloc (amt);
3092
    if (section_list == NULL)
3093
      return false;
3094
3095
    i = 0;
3096
    for (current = abfd->sections; current != NULL; current = current->next)
3097
      {
3098
  section_list[i] = current;
3099
  ++i;
3100
      }
3101
    section_list[i] = NULL;
3102
3103
    qsort (section_list, count, sizeof (asection *), sort_by_secaddr);
3104
3105
    /* Rethread the linked list into sorted order; at the same time,
3106
       assign target_index values.  */
3107
    target_index = 1;
3108
    abfd->sections = NULL;
3109
    abfd->section_last = NULL;
3110
    for (i = 0; i < count; i++)
3111
      {
3112
  current = section_list[i];
3113
  bfd_section_list_append (abfd, current);
3114
3115
  /* Later, if the section has zero size, we'll be throwing it
3116
     away, so we don't want to number it now.  Note that having
3117
     a zero size and having real contents are different
3118
     concepts: .bss has no contents, but (usually) non-zero
3119
     size.  */
3120
  if (current->size == 0)
3121
    {
3122
      /* Discard.  However, it still might have (valid) symbols
3123
         in it, so arbitrarily set it to section 1 (indexing is
3124
         1-based here; usually .text).  __end__ and other
3125
         contents of .endsection really have this happen.
3126
         FIXME: This seems somewhat dubious.  */
3127
      current->target_index = 1;
3128
    }
3129
  else
3130
    current->target_index = target_index++;
3131
      }
3132
3133
    free (section_list);
3134
  }
3135
#else /* ! COFF_IMAGE_WITH_PE */
3136
1
  {
3137
    /* Set the target_index field.  */
3138
1
    target_index = 1;
3139
2
    for (current = abfd->sections; current != NULL; current = current->next)
3140
1
      current->target_index = target_index++;
3141
1
  }
3142
1
#endif /* ! COFF_IMAGE_WITH_PE */
3143
3144
1
  if (target_index >= bfd_coff_max_nscns (abfd))
3145
0
    {
3146
0
      bfd_set_error (bfd_error_file_too_big);
3147
0
      _bfd_error_handler
3148
  /* xgettext:c-format */
3149
0
  (_("%pB: too many sections (%d)"), abfd, target_index);
3150
0
      return false;
3151
0
    }
3152
3153
1
  align_adjust = false;
3154
1
  for (current = abfd->sections;
3155
2
       current != NULL;
3156
1
       current = current->next)
3157
1
    {
3158
#ifdef COFF_IMAGE_WITH_PE
3159
      /* With PE we have to pad each section to be a multiple of its
3160
   page size too, and remember both sizes.  */
3161
      if (coff_section_data (abfd, current) == NULL)
3162
  {
3163
    size_t amt = sizeof (struct coff_section_tdata);
3164
3165
    current->used_by_bfd = bfd_zalloc (abfd, amt);
3166
    if (current->used_by_bfd == NULL)
3167
      return false;
3168
  }
3169
      if (pei_section_data (abfd, current) == NULL)
3170
  {
3171
    size_t amt = sizeof (struct pei_section_tdata);
3172
3173
    coff_section_data (abfd, current)->tdata = bfd_zalloc (abfd, amt);
3174
    if (coff_section_data (abfd, current)->tdata == NULL)
3175
      return false;
3176
  }
3177
      if (pei_section_data (abfd, current)->virt_size == 0)
3178
  pei_section_data (abfd, current)->virt_size = current->size;
3179
#endif
3180
3181
      /* Only deal with sections which have contents.  */
3182
1
      if (!(current->flags & SEC_HAS_CONTENTS))
3183
0
  continue;
3184
3185
1
      current->rawsize = current->size;
3186
3187
#ifdef COFF_IMAGE_WITH_PE
3188
      /* Make sure we skip empty sections in a PE image.  */
3189
      if (current->size == 0)
3190
  continue;
3191
#endif
3192
3193
      /* Align the sections in the file to the same boundary on
3194
   which they are aligned in virtual memory.  */
3195
1
#ifdef ALIGN_SECTIONS_IN_FILE
3196
1
      if ((abfd->flags & EXEC_P) != 0)
3197
0
  {
3198
    /* Make sure this section is aligned on the right boundary - by
3199
       padding the previous section up if necessary.  */
3200
0
    old_sofar = sofar;
3201
3202
#ifdef COFF_IMAGE_WITH_PE
3203
    sofar = BFD_ALIGN (sofar, page_size);
3204
#else
3205
0
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3206
0
#endif
3207
3208
#ifdef RS6000COFF_C
3209
    /* Make sure the file offset and the vma of .text/.data are at the
3210
       same page offset, so that the file can be mmap'ed without being
3211
       relocated.  Failing that, AIX is able to load and execute the
3212
       program, but it will be silently relocated (possible as
3213
       executables are PIE).  But the relocation is slightly costly and
3214
       complexify the use of addr2line or gdb.  So better to avoid it,
3215
       like does the native linker.  Usually gnu ld makes sure that
3216
       the vma of .text is the file offset so this issue shouldn't
3217
       appear unless you are stripping such an executable.
3218
3219
       AIX loader checks the text section alignment of (vma - filepos),
3220
       and the native linker doesn't try to align the text sections.
3221
       For example:
3222
3223
       0 .text       000054cc  10000128  10000128  00000128  2**5
3224
           CONTENTS, ALLOC, LOAD, CODE
3225
3226
       Don't perform the above tweak if the previous one is .tdata,
3227
       as it will increase the memory allocated for every threads
3228
       created and not just improve performances with gdb.
3229
    */
3230
3231
    if ((current->flags & SEC_LOAD) != 0
3232
        && (!strcmp (current->name, _TEXT)
3233
      || !strcmp (current->name, _DATA))
3234
        && (previous == NULL || strcmp(previous->name, _TDATA)))
3235
      {
3236
        bfd_vma align = 4096;
3237
        bfd_vma sofar_off = sofar % align;
3238
        bfd_vma vma_off = current->vma % align;
3239
3240
        if (vma_off > sofar_off)
3241
    sofar += vma_off - sofar_off;
3242
        else if (vma_off < sofar_off)
3243
    sofar += align + vma_off - sofar_off;
3244
      }
3245
#endif
3246
0
    if (previous != NULL
3247
0
        && (previous->flags & SEC_LOAD) != 0)
3248
0
      previous->size += sofar - old_sofar;
3249
0
  }
3250
3251
1
#endif
3252
3253
      /* In demand paged files the low order bits of the file offset
3254
   must match the low order bits of the virtual address.  */
3255
1
#ifdef COFF_PAGE_SIZE
3256
1
      if ((abfd->flags & D_PAGED) != 0
3257
1
    && (current->flags & SEC_ALLOC) != 0)
3258
0
  sofar += (current->vma - (bfd_vma) sofar) % page_size;
3259
1
#endif
3260
1
      current->filepos = sofar;
3261
3262
#ifdef COFF_IMAGE_WITH_PE
3263
      /* Set the padded size.  */
3264
      current->size = (current->size + page_size - 1) & -page_size;
3265
#endif
3266
3267
1
      sofar += current->size;
3268
3269
1
#ifdef ALIGN_SECTIONS_IN_FILE
3270
      /* Make sure that this section is of the right size too.  */
3271
1
      if ((abfd->flags & EXEC_P) == 0)
3272
1
  {
3273
1
    bfd_size_type old_size;
3274
3275
1
    old_size = current->size;
3276
1
    current->size = BFD_ALIGN (current->size,
3277
1
             (bfd_vma) 1 << current->alignment_power);
3278
1
    align_adjust = current->size != old_size;
3279
1
    sofar += current->size - old_size;
3280
1
  }
3281
0
      else
3282
0
  {
3283
0
    old_sofar = sofar;
3284
#ifdef COFF_IMAGE_WITH_PE
3285
    sofar = BFD_ALIGN (sofar, page_size);
3286
#else
3287
0
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3288
0
#endif
3289
0
    align_adjust = sofar != old_sofar;
3290
0
    current->size += sofar - old_sofar;
3291
0
  }
3292
1
#endif
3293
3294
#ifdef COFF_IMAGE_WITH_PE
3295
      /* For PE we need to make sure we pad out to the aligned
3296
   size, in case the caller only writes out data to the
3297
   unaligned size.  */
3298
      if (pei_section_data (abfd, current)->virt_size < current->size)
3299
  align_adjust = true;
3300
#endif
3301
3302
1
#ifdef _LIB
3303
      /* Force .lib sections to start at zero.  The vma is then
3304
   incremented in coff_set_section_contents.  This is right for
3305
   SVR3.2.  */
3306
1
      if (strcmp (current->name, _LIB) == 0)
3307
0
  bfd_set_section_vma (current, 0);
3308
1
#endif
3309
3310
1
#ifdef ALIGN_SECTIONS_IN_FILE
3311
1
      previous = current;
3312
1
#endif
3313
1
    }
3314
3315
  /* It is now safe to write to the output file.  If we needed an
3316
     alignment adjustment for the last section, then make sure that
3317
     there is a byte at offset sofar.  If there are no symbols and no
3318
     relocs, then nothing follows the last section.  If we don't force
3319
     the last byte out, then the file may appear to be truncated.  */
3320
1
  if (align_adjust)
3321
0
    {
3322
0
      bfd_byte b;
3323
3324
0
      b = 0;
3325
0
      if (bfd_seek (abfd, sofar - 1, SEEK_SET) != 0
3326
0
    || bfd_write (&b, 1, abfd) != 1)
3327
0
  return false;
3328
0
    }
3329
3330
  /* Make sure the relocations are aligned.  We don't need to make
3331
     sure that this byte exists, because it will only matter if there
3332
     really are relocs.  */
3333
1
  sofar = BFD_ALIGN (sofar,
3334
1
         (bfd_vma) 1 << COFF_DEFAULT_SECTION_ALIGNMENT_POWER);
3335
3336
1
  obj_relocbase (abfd) = sofar;
3337
1
  abfd->output_has_begun = true;
3338
3339
1
  return true;
3340
1
}
pei-aarch64.c:coff_compute_section_file_positions
Line
Count
Source
2966
2
{
2967
2
  asection *current;
2968
2
  file_ptr sofar = bfd_coff_filhsz (abfd);
2969
2
  bool align_adjust;
2970
2
  unsigned int target_index;
2971
2
#ifdef ALIGN_SECTIONS_IN_FILE
2972
2
  asection *previous = NULL;
2973
2
  file_ptr old_sofar;
2974
2
#endif
2975
2976
2
#ifdef COFF_IMAGE_WITH_PE
2977
2
  unsigned int page_size;
2978
2979
2
  if (coff_data (abfd)->link_info
2980
2
      || (pe_data (abfd) && pe_data (abfd)->pe_opthdr.FileAlignment))
2981
0
    {
2982
0
      page_size = pe_data (abfd)->pe_opthdr.FileAlignment;
2983
2984
      /* If no file alignment has been set, default to one.
2985
   This repairs 'ld -r' for arm-wince-pe target.  */
2986
0
      if (page_size == 0)
2987
0
  page_size = 1;
2988
0
    }
2989
2
  else
2990
2
    page_size = PE_DEF_FILE_ALIGNMENT;
2991
#else
2992
#ifdef COFF_PAGE_SIZE
2993
  unsigned int page_size = COFF_PAGE_SIZE;
2994
#endif
2995
#endif
2996
2997
#ifdef RS6000COFF_C
2998
  /* On XCOFF, if we have symbols, set up the .debug section.  */
2999
  if (bfd_get_symcount (abfd) > 0)
3000
    {
3001
      bfd_size_type sz;
3002
      bfd_size_type i, symcount;
3003
      asymbol **symp;
3004
3005
      sz = 0;
3006
      symcount = bfd_get_symcount (abfd);
3007
      for (symp = abfd->outsymbols, i = 0; i < symcount; symp++, i++)
3008
  {
3009
    coff_symbol_type *cf;
3010
3011
    cf = coff_symbol_from (*symp);
3012
    if (cf != NULL
3013
        && cf->native != NULL
3014
        && cf->native->is_sym
3015
        && SYMNAME_IN_DEBUG (&cf->native->u.syment))
3016
      {
3017
        size_t len;
3018
3019
        len = strlen (bfd_asymbol_name (*symp));
3020
        if (len > SYMNMLEN || bfd_coff_force_symnames_in_strings (abfd))
3021
    sz += len + 1 + bfd_coff_debug_string_prefix_length (abfd);
3022
      }
3023
  }
3024
      if (sz > 0)
3025
  {
3026
    asection *dsec;
3027
3028
    dsec = bfd_make_section_old_way (abfd, DOT_DEBUG);
3029
    if (dsec == NULL)
3030
      abort ();
3031
    dsec->size = sz;
3032
    dsec->flags |= SEC_HAS_CONTENTS;
3033
  }
3034
    }
3035
#endif
3036
3037
2
  if (bfd_get_start_address (abfd))
3038
    /*  A start address may have been added to the original file. In this
3039
  case it will need an optional header to record it.  */
3040
0
    abfd->flags |= EXEC_P;
3041
3042
2
  if (abfd->flags & EXEC_P)
3043
0
    sofar += bfd_coff_aoutsz (abfd);
3044
#ifdef RS6000COFF_C
3045
  else if (xcoff_data (abfd)->full_aouthdr)
3046
    sofar += bfd_coff_aoutsz (abfd);
3047
  else
3048
    sofar += SMALL_AOUTSZ;
3049
#endif
3050
3051
2
  sofar += abfd->section_count * bfd_coff_scnhsz (abfd);
3052
3053
#ifdef RS6000COFF_C
3054
  /* XCOFF handles overflows in the reloc and line number count fields
3055
     by allocating a new section header to hold the correct counts.  */
3056
  for (current = abfd->sections; current != NULL; current = current->next)
3057
    if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3058
      sofar += bfd_coff_scnhsz (abfd);
3059
#endif
3060
3061
2
  if (coff_data (abfd)->section_by_target_index)
3062
0
    htab_empty (coff_data (abfd)->section_by_target_index);
3063
3064
2
#ifdef COFF_IMAGE_WITH_PE
3065
2
  {
3066
    /* PE requires the sections to be in memory order when listed in
3067
       the section headers.  It also does not like empty loadable
3068
       sections.  The sections apparently do not have to be in the
3069
       right order in the image file itself, but we do need to get the
3070
       target_index values right.  */
3071
3072
2
    unsigned int count;
3073
2
    asection **section_list;
3074
2
    unsigned int i;
3075
2
    bfd_size_type amt;
3076
3077
2
#ifdef COFF_PAGE_SIZE
3078
    /* Clear D_PAGED if section / file alignment aren't suitable for
3079
       paging at COFF_PAGE_SIZE granularity.  */
3080
2
   if (pe_data (abfd)->pe_opthdr.SectionAlignment < COFF_PAGE_SIZE
3081
2
       || page_size < COFF_PAGE_SIZE)
3082
2
     abfd->flags &= ~D_PAGED;
3083
2
#endif
3084
3085
2
    count = 0;
3086
6
    for (current = abfd->sections; current != NULL; current = current->next)
3087
4
      ++count;
3088
3089
    /* We allocate an extra cell to simplify the final loop.  */
3090
2
    amt = sizeof (struct asection *) * (count + 1);
3091
2
    section_list = (asection **) bfd_malloc (amt);
3092
2
    if (section_list == NULL)
3093
0
      return false;
3094
3095
2
    i = 0;
3096
6
    for (current = abfd->sections; current != NULL; current = current->next)
3097
4
      {
3098
4
  section_list[i] = current;
3099
4
  ++i;
3100
4
      }
3101
2
    section_list[i] = NULL;
3102
3103
2
    qsort (section_list, count, sizeof (asection *), sort_by_secaddr);
3104
3105
    /* Rethread the linked list into sorted order; at the same time,
3106
       assign target_index values.  */
3107
2
    target_index = 1;
3108
2
    abfd->sections = NULL;
3109
2
    abfd->section_last = NULL;
3110
6
    for (i = 0; i < count; i++)
3111
4
      {
3112
4
  current = section_list[i];
3113
4
  bfd_section_list_append (abfd, current);
3114
3115
  /* Later, if the section has zero size, we'll be throwing it
3116
     away, so we don't want to number it now.  Note that having
3117
     a zero size and having real contents are different
3118
     concepts: .bss has no contents, but (usually) non-zero
3119
     size.  */
3120
4
  if (current->size == 0)
3121
0
    {
3122
      /* Discard.  However, it still might have (valid) symbols
3123
         in it, so arbitrarily set it to section 1 (indexing is
3124
         1-based here; usually .text).  __end__ and other
3125
         contents of .endsection really have this happen.
3126
         FIXME: This seems somewhat dubious.  */
3127
0
      current->target_index = 1;
3128
0
    }
3129
4
  else
3130
4
    current->target_index = target_index++;
3131
4
      }
3132
3133
2
    free (section_list);
3134
2
  }
3135
#else /* ! COFF_IMAGE_WITH_PE */
3136
  {
3137
    /* Set the target_index field.  */
3138
    target_index = 1;
3139
    for (current = abfd->sections; current != NULL; current = current->next)
3140
      current->target_index = target_index++;
3141
  }
3142
#endif /* ! COFF_IMAGE_WITH_PE */
3143
3144
2
  if (target_index >= bfd_coff_max_nscns (abfd))
3145
0
    {
3146
0
      bfd_set_error (bfd_error_file_too_big);
3147
0
      _bfd_error_handler
3148
  /* xgettext:c-format */
3149
0
  (_("%pB: too many sections (%d)"), abfd, target_index);
3150
0
      return false;
3151
0
    }
3152
3153
2
  align_adjust = false;
3154
2
  for (current = abfd->sections;
3155
6
       current != NULL;
3156
4
       current = current->next)
3157
4
    {
3158
4
#ifdef COFF_IMAGE_WITH_PE
3159
      /* With PE we have to pad each section to be a multiple of its
3160
   page size too, and remember both sizes.  */
3161
4
      if (coff_section_data (abfd, current) == NULL)
3162
4
  {
3163
4
    size_t amt = sizeof (struct coff_section_tdata);
3164
3165
4
    current->used_by_bfd = bfd_zalloc (abfd, amt);
3166
4
    if (current->used_by_bfd == NULL)
3167
0
      return false;
3168
4
  }
3169
4
      if (pei_section_data (abfd, current) == NULL)
3170
4
  {
3171
4
    size_t amt = sizeof (struct pei_section_tdata);
3172
3173
4
    coff_section_data (abfd, current)->tdata = bfd_zalloc (abfd, amt);
3174
4
    if (coff_section_data (abfd, current)->tdata == NULL)
3175
0
      return false;
3176
4
  }
3177
4
      if (pei_section_data (abfd, current)->virt_size == 0)
3178
4
  pei_section_data (abfd, current)->virt_size = current->size;
3179
4
#endif
3180
3181
      /* Only deal with sections which have contents.  */
3182
4
      if (!(current->flags & SEC_HAS_CONTENTS))
3183
0
  continue;
3184
3185
4
      current->rawsize = current->size;
3186
3187
4
#ifdef COFF_IMAGE_WITH_PE
3188
      /* Make sure we skip empty sections in a PE image.  */
3189
4
      if (current->size == 0)
3190
0
  continue;
3191
4
#endif
3192
3193
      /* Align the sections in the file to the same boundary on
3194
   which they are aligned in virtual memory.  */
3195
4
#ifdef ALIGN_SECTIONS_IN_FILE
3196
4
      if ((abfd->flags & EXEC_P) != 0)
3197
0
  {
3198
    /* Make sure this section is aligned on the right boundary - by
3199
       padding the previous section up if necessary.  */
3200
0
    old_sofar = sofar;
3201
3202
0
#ifdef COFF_IMAGE_WITH_PE
3203
0
    sofar = BFD_ALIGN (sofar, page_size);
3204
#else
3205
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3206
#endif
3207
3208
#ifdef RS6000COFF_C
3209
    /* Make sure the file offset and the vma of .text/.data are at the
3210
       same page offset, so that the file can be mmap'ed without being
3211
       relocated.  Failing that, AIX is able to load and execute the
3212
       program, but it will be silently relocated (possible as
3213
       executables are PIE).  But the relocation is slightly costly and
3214
       complexify the use of addr2line or gdb.  So better to avoid it,
3215
       like does the native linker.  Usually gnu ld makes sure that
3216
       the vma of .text is the file offset so this issue shouldn't
3217
       appear unless you are stripping such an executable.
3218
3219
       AIX loader checks the text section alignment of (vma - filepos),
3220
       and the native linker doesn't try to align the text sections.
3221
       For example:
3222
3223
       0 .text       000054cc  10000128  10000128  00000128  2**5
3224
           CONTENTS, ALLOC, LOAD, CODE
3225
3226
       Don't perform the above tweak if the previous one is .tdata,
3227
       as it will increase the memory allocated for every threads
3228
       created and not just improve performances with gdb.
3229
    */
3230
3231
    if ((current->flags & SEC_LOAD) != 0
3232
        && (!strcmp (current->name, _TEXT)
3233
      || !strcmp (current->name, _DATA))
3234
        && (previous == NULL || strcmp(previous->name, _TDATA)))
3235
      {
3236
        bfd_vma align = 4096;
3237
        bfd_vma sofar_off = sofar % align;
3238
        bfd_vma vma_off = current->vma % align;
3239
3240
        if (vma_off > sofar_off)
3241
    sofar += vma_off - sofar_off;
3242
        else if (vma_off < sofar_off)
3243
    sofar += align + vma_off - sofar_off;
3244
      }
3245
#endif
3246
0
    if (previous != NULL
3247
0
        && (previous->flags & SEC_LOAD) != 0)
3248
0
      previous->size += sofar - old_sofar;
3249
0
  }
3250
3251
4
#endif
3252
3253
      /* In demand paged files the low order bits of the file offset
3254
   must match the low order bits of the virtual address.  */
3255
4
#ifdef COFF_PAGE_SIZE
3256
4
      if ((abfd->flags & D_PAGED) != 0
3257
4
    && (current->flags & SEC_ALLOC) != 0)
3258
0
  sofar += (current->vma - (bfd_vma) sofar) % page_size;
3259
4
#endif
3260
4
      current->filepos = sofar;
3261
3262
4
#ifdef COFF_IMAGE_WITH_PE
3263
      /* Set the padded size.  */
3264
4
      current->size = (current->size + page_size - 1) & -page_size;
3265
4
#endif
3266
3267
4
      sofar += current->size;
3268
3269
4
#ifdef ALIGN_SECTIONS_IN_FILE
3270
      /* Make sure that this section is of the right size too.  */
3271
4
      if ((abfd->flags & EXEC_P) == 0)
3272
4
  {
3273
4
    bfd_size_type old_size;
3274
3275
4
    old_size = current->size;
3276
4
    current->size = BFD_ALIGN (current->size,
3277
4
             (bfd_vma) 1 << current->alignment_power);
3278
4
    align_adjust = current->size != old_size;
3279
4
    sofar += current->size - old_size;
3280
4
  }
3281
0
      else
3282
0
  {
3283
0
    old_sofar = sofar;
3284
0
#ifdef COFF_IMAGE_WITH_PE
3285
0
    sofar = BFD_ALIGN (sofar, page_size);
3286
#else
3287
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3288
#endif
3289
0
    align_adjust = sofar != old_sofar;
3290
0
    current->size += sofar - old_sofar;
3291
0
  }
3292
4
#endif
3293
3294
4
#ifdef COFF_IMAGE_WITH_PE
3295
      /* For PE we need to make sure we pad out to the aligned
3296
   size, in case the caller only writes out data to the
3297
   unaligned size.  */
3298
4
      if (pei_section_data (abfd, current)->virt_size < current->size)
3299
4
  align_adjust = true;
3300
4
#endif
3301
3302
4
#ifdef _LIB
3303
      /* Force .lib sections to start at zero.  The vma is then
3304
   incremented in coff_set_section_contents.  This is right for
3305
   SVR3.2.  */
3306
4
      if (strcmp (current->name, _LIB) == 0)
3307
0
  bfd_set_section_vma (current, 0);
3308
4
#endif
3309
3310
4
#ifdef ALIGN_SECTIONS_IN_FILE
3311
4
      previous = current;
3312
4
#endif
3313
4
    }
3314
3315
  /* It is now safe to write to the output file.  If we needed an
3316
     alignment adjustment for the last section, then make sure that
3317
     there is a byte at offset sofar.  If there are no symbols and no
3318
     relocs, then nothing follows the last section.  If we don't force
3319
     the last byte out, then the file may appear to be truncated.  */
3320
2
  if (align_adjust)
3321
2
    {
3322
2
      bfd_byte b;
3323
3324
2
      b = 0;
3325
2
      if (bfd_seek (abfd, sofar - 1, SEEK_SET) != 0
3326
2
    || bfd_write (&b, 1, abfd) != 1)
3327
0
  return false;
3328
2
    }
3329
3330
  /* Make sure the relocations are aligned.  We don't need to make
3331
     sure that this byte exists, because it will only matter if there
3332
     really are relocs.  */
3333
2
  sofar = BFD_ALIGN (sofar,
3334
2
         (bfd_vma) 1 << COFF_DEFAULT_SECTION_ALIGNMENT_POWER);
3335
3336
2
  obj_relocbase (abfd) = sofar;
3337
2
  abfd->output_has_begun = true;
3338
3339
2
  return true;
3340
2
}
Unexecuted instantiation: pei-ia64.c:coff_compute_section_file_positions
Unexecuted instantiation: pei-loongarch64.c:coff_compute_section_file_positions
Unexecuted instantiation: cf-i386lynx.c:coff_compute_section_file_positions
Unexecuted instantiation: coff-go32.c:coff_compute_section_file_positions
Unexecuted instantiation: coff-i386.c:coff_compute_section_file_positions
Unexecuted instantiation: coff-rs6000.c:coff_compute_section_file_positions
coff-sh.c:coff_compute_section_file_positions
Line
Count
Source
2966
1
{
2967
1
  asection *current;
2968
1
  file_ptr sofar = bfd_coff_filhsz (abfd);
2969
1
  bool align_adjust;
2970
1
  unsigned int target_index;
2971
1
#ifdef ALIGN_SECTIONS_IN_FILE
2972
1
  asection *previous = NULL;
2973
1
  file_ptr old_sofar;
2974
1
#endif
2975
2976
#ifdef COFF_IMAGE_WITH_PE
2977
  unsigned int page_size;
2978
2979
  if (coff_data (abfd)->link_info
2980
      || (pe_data (abfd) && pe_data (abfd)->pe_opthdr.FileAlignment))
2981
    {
2982
      page_size = pe_data (abfd)->pe_opthdr.FileAlignment;
2983
2984
      /* If no file alignment has been set, default to one.
2985
   This repairs 'ld -r' for arm-wince-pe target.  */
2986
      if (page_size == 0)
2987
  page_size = 1;
2988
    }
2989
  else
2990
    page_size = PE_DEF_FILE_ALIGNMENT;
2991
#else
2992
#ifdef COFF_PAGE_SIZE
2993
  unsigned int page_size = COFF_PAGE_SIZE;
2994
#endif
2995
1
#endif
2996
2997
#ifdef RS6000COFF_C
2998
  /* On XCOFF, if we have symbols, set up the .debug section.  */
2999
  if (bfd_get_symcount (abfd) > 0)
3000
    {
3001
      bfd_size_type sz;
3002
      bfd_size_type i, symcount;
3003
      asymbol **symp;
3004
3005
      sz = 0;
3006
      symcount = bfd_get_symcount (abfd);
3007
      for (symp = abfd->outsymbols, i = 0; i < symcount; symp++, i++)
3008
  {
3009
    coff_symbol_type *cf;
3010
3011
    cf = coff_symbol_from (*symp);
3012
    if (cf != NULL
3013
        && cf->native != NULL
3014
        && cf->native->is_sym
3015
        && SYMNAME_IN_DEBUG (&cf->native->u.syment))
3016
      {
3017
        size_t len;
3018
3019
        len = strlen (bfd_asymbol_name (*symp));
3020
        if (len > SYMNMLEN || bfd_coff_force_symnames_in_strings (abfd))
3021
    sz += len + 1 + bfd_coff_debug_string_prefix_length (abfd);
3022
      }
3023
  }
3024
      if (sz > 0)
3025
  {
3026
    asection *dsec;
3027
3028
    dsec = bfd_make_section_old_way (abfd, DOT_DEBUG);
3029
    if (dsec == NULL)
3030
      abort ();
3031
    dsec->size = sz;
3032
    dsec->flags |= SEC_HAS_CONTENTS;
3033
  }
3034
    }
3035
#endif
3036
3037
1
  if (bfd_get_start_address (abfd))
3038
    /*  A start address may have been added to the original file. In this
3039
  case it will need an optional header to record it.  */
3040
0
    abfd->flags |= EXEC_P;
3041
3042
1
  if (abfd->flags & EXEC_P)
3043
0
    sofar += bfd_coff_aoutsz (abfd);
3044
#ifdef RS6000COFF_C
3045
  else if (xcoff_data (abfd)->full_aouthdr)
3046
    sofar += bfd_coff_aoutsz (abfd);
3047
  else
3048
    sofar += SMALL_AOUTSZ;
3049
#endif
3050
3051
1
  sofar += abfd->section_count * bfd_coff_scnhsz (abfd);
3052
3053
#ifdef RS6000COFF_C
3054
  /* XCOFF handles overflows in the reloc and line number count fields
3055
     by allocating a new section header to hold the correct counts.  */
3056
  for (current = abfd->sections; current != NULL; current = current->next)
3057
    if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3058
      sofar += bfd_coff_scnhsz (abfd);
3059
#endif
3060
3061
1
  if (coff_data (abfd)->section_by_target_index)
3062
0
    htab_empty (coff_data (abfd)->section_by_target_index);
3063
3064
#ifdef COFF_IMAGE_WITH_PE
3065
  {
3066
    /* PE requires the sections to be in memory order when listed in
3067
       the section headers.  It also does not like empty loadable
3068
       sections.  The sections apparently do not have to be in the
3069
       right order in the image file itself, but we do need to get the
3070
       target_index values right.  */
3071
3072
    unsigned int count;
3073
    asection **section_list;
3074
    unsigned int i;
3075
    bfd_size_type amt;
3076
3077
#ifdef COFF_PAGE_SIZE
3078
    /* Clear D_PAGED if section / file alignment aren't suitable for
3079
       paging at COFF_PAGE_SIZE granularity.  */
3080
   if (pe_data (abfd)->pe_opthdr.SectionAlignment < COFF_PAGE_SIZE
3081
       || page_size < COFF_PAGE_SIZE)
3082
     abfd->flags &= ~D_PAGED;
3083
#endif
3084
3085
    count = 0;
3086
    for (current = abfd->sections; current != NULL; current = current->next)
3087
      ++count;
3088
3089
    /* We allocate an extra cell to simplify the final loop.  */
3090
    amt = sizeof (struct asection *) * (count + 1);
3091
    section_list = (asection **) bfd_malloc (amt);
3092
    if (section_list == NULL)
3093
      return false;
3094
3095
    i = 0;
3096
    for (current = abfd->sections; current != NULL; current = current->next)
3097
      {
3098
  section_list[i] = current;
3099
  ++i;
3100
      }
3101
    section_list[i] = NULL;
3102
3103
    qsort (section_list, count, sizeof (asection *), sort_by_secaddr);
3104
3105
    /* Rethread the linked list into sorted order; at the same time,
3106
       assign target_index values.  */
3107
    target_index = 1;
3108
    abfd->sections = NULL;
3109
    abfd->section_last = NULL;
3110
    for (i = 0; i < count; i++)
3111
      {
3112
  current = section_list[i];
3113
  bfd_section_list_append (abfd, current);
3114
3115
  /* Later, if the section has zero size, we'll be throwing it
3116
     away, so we don't want to number it now.  Note that having
3117
     a zero size and having real contents are different
3118
     concepts: .bss has no contents, but (usually) non-zero
3119
     size.  */
3120
  if (current->size == 0)
3121
    {
3122
      /* Discard.  However, it still might have (valid) symbols
3123
         in it, so arbitrarily set it to section 1 (indexing is
3124
         1-based here; usually .text).  __end__ and other
3125
         contents of .endsection really have this happen.
3126
         FIXME: This seems somewhat dubious.  */
3127
      current->target_index = 1;
3128
    }
3129
  else
3130
    current->target_index = target_index++;
3131
      }
3132
3133
    free (section_list);
3134
  }
3135
#else /* ! COFF_IMAGE_WITH_PE */
3136
1
  {
3137
    /* Set the target_index field.  */
3138
1
    target_index = 1;
3139
1
    for (current = abfd->sections; current != NULL; current = current->next)
3140
0
      current->target_index = target_index++;
3141
1
  }
3142
1
#endif /* ! COFF_IMAGE_WITH_PE */
3143
3144
1
  if (target_index >= bfd_coff_max_nscns (abfd))
3145
0
    {
3146
0
      bfd_set_error (bfd_error_file_too_big);
3147
0
      _bfd_error_handler
3148
  /* xgettext:c-format */
3149
0
  (_("%pB: too many sections (%d)"), abfd, target_index);
3150
0
      return false;
3151
0
    }
3152
3153
1
  align_adjust = false;
3154
1
  for (current = abfd->sections;
3155
1
       current != NULL;
3156
1
       current = current->next)
3157
0
    {
3158
#ifdef COFF_IMAGE_WITH_PE
3159
      /* With PE we have to pad each section to be a multiple of its
3160
   page size too, and remember both sizes.  */
3161
      if (coff_section_data (abfd, current) == NULL)
3162
  {
3163
    size_t amt = sizeof (struct coff_section_tdata);
3164
3165
    current->used_by_bfd = bfd_zalloc (abfd, amt);
3166
    if (current->used_by_bfd == NULL)
3167
      return false;
3168
  }
3169
      if (pei_section_data (abfd, current) == NULL)
3170
  {
3171
    size_t amt = sizeof (struct pei_section_tdata);
3172
3173
    coff_section_data (abfd, current)->tdata = bfd_zalloc (abfd, amt);
3174
    if (coff_section_data (abfd, current)->tdata == NULL)
3175
      return false;
3176
  }
3177
      if (pei_section_data (abfd, current)->virt_size == 0)
3178
  pei_section_data (abfd, current)->virt_size = current->size;
3179
#endif
3180
3181
      /* Only deal with sections which have contents.  */
3182
0
      if (!(current->flags & SEC_HAS_CONTENTS))
3183
0
  continue;
3184
3185
0
      current->rawsize = current->size;
3186
3187
#ifdef COFF_IMAGE_WITH_PE
3188
      /* Make sure we skip empty sections in a PE image.  */
3189
      if (current->size == 0)
3190
  continue;
3191
#endif
3192
3193
      /* Align the sections in the file to the same boundary on
3194
   which they are aligned in virtual memory.  */
3195
0
#ifdef ALIGN_SECTIONS_IN_FILE
3196
0
      if ((abfd->flags & EXEC_P) != 0)
3197
0
  {
3198
    /* Make sure this section is aligned on the right boundary - by
3199
       padding the previous section up if necessary.  */
3200
0
    old_sofar = sofar;
3201
3202
#ifdef COFF_IMAGE_WITH_PE
3203
    sofar = BFD_ALIGN (sofar, page_size);
3204
#else
3205
0
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3206
0
#endif
3207
3208
#ifdef RS6000COFF_C
3209
    /* Make sure the file offset and the vma of .text/.data are at the
3210
       same page offset, so that the file can be mmap'ed without being
3211
       relocated.  Failing that, AIX is able to load and execute the
3212
       program, but it will be silently relocated (possible as
3213
       executables are PIE).  But the relocation is slightly costly and
3214
       complexify the use of addr2line or gdb.  So better to avoid it,
3215
       like does the native linker.  Usually gnu ld makes sure that
3216
       the vma of .text is the file offset so this issue shouldn't
3217
       appear unless you are stripping such an executable.
3218
3219
       AIX loader checks the text section alignment of (vma - filepos),
3220
       and the native linker doesn't try to align the text sections.
3221
       For example:
3222
3223
       0 .text       000054cc  10000128  10000128  00000128  2**5
3224
           CONTENTS, ALLOC, LOAD, CODE
3225
3226
       Don't perform the above tweak if the previous one is .tdata,
3227
       as it will increase the memory allocated for every threads
3228
       created and not just improve performances with gdb.
3229
    */
3230
3231
    if ((current->flags & SEC_LOAD) != 0
3232
        && (!strcmp (current->name, _TEXT)
3233
      || !strcmp (current->name, _DATA))
3234
        && (previous == NULL || strcmp(previous->name, _TDATA)))
3235
      {
3236
        bfd_vma align = 4096;
3237
        bfd_vma sofar_off = sofar % align;
3238
        bfd_vma vma_off = current->vma % align;
3239
3240
        if (vma_off > sofar_off)
3241
    sofar += vma_off - sofar_off;
3242
        else if (vma_off < sofar_off)
3243
    sofar += align + vma_off - sofar_off;
3244
      }
3245
#endif
3246
0
    if (previous != NULL
3247
0
        && (previous->flags & SEC_LOAD) != 0)
3248
0
      previous->size += sofar - old_sofar;
3249
0
  }
3250
3251
0
#endif
3252
3253
      /* In demand paged files the low order bits of the file offset
3254
   must match the low order bits of the virtual address.  */
3255
#ifdef COFF_PAGE_SIZE
3256
      if ((abfd->flags & D_PAGED) != 0
3257
    && (current->flags & SEC_ALLOC) != 0)
3258
  sofar += (current->vma - (bfd_vma) sofar) % page_size;
3259
#endif
3260
0
      current->filepos = sofar;
3261
3262
#ifdef COFF_IMAGE_WITH_PE
3263
      /* Set the padded size.  */
3264
      current->size = (current->size + page_size - 1) & -page_size;
3265
#endif
3266
3267
0
      sofar += current->size;
3268
3269
0
#ifdef ALIGN_SECTIONS_IN_FILE
3270
      /* Make sure that this section is of the right size too.  */
3271
0
      if ((abfd->flags & EXEC_P) == 0)
3272
0
  {
3273
0
    bfd_size_type old_size;
3274
3275
0
    old_size = current->size;
3276
0
    current->size = BFD_ALIGN (current->size,
3277
0
             (bfd_vma) 1 << current->alignment_power);
3278
0
    align_adjust = current->size != old_size;
3279
0
    sofar += current->size - old_size;
3280
0
  }
3281
0
      else
3282
0
  {
3283
0
    old_sofar = sofar;
3284
#ifdef COFF_IMAGE_WITH_PE
3285
    sofar = BFD_ALIGN (sofar, page_size);
3286
#else
3287
0
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3288
0
#endif
3289
0
    align_adjust = sofar != old_sofar;
3290
0
    current->size += sofar - old_sofar;
3291
0
  }
3292
0
#endif
3293
3294
#ifdef COFF_IMAGE_WITH_PE
3295
      /* For PE we need to make sure we pad out to the aligned
3296
   size, in case the caller only writes out data to the
3297
   unaligned size.  */
3298
      if (pei_section_data (abfd, current)->virt_size < current->size)
3299
  align_adjust = true;
3300
#endif
3301
3302
0
#ifdef _LIB
3303
      /* Force .lib sections to start at zero.  The vma is then
3304
   incremented in coff_set_section_contents.  This is right for
3305
   SVR3.2.  */
3306
0
      if (strcmp (current->name, _LIB) == 0)
3307
0
  bfd_set_section_vma (current, 0);
3308
0
#endif
3309
3310
0
#ifdef ALIGN_SECTIONS_IN_FILE
3311
0
      previous = current;
3312
0
#endif
3313
0
    }
3314
3315
  /* It is now safe to write to the output file.  If we needed an
3316
     alignment adjustment for the last section, then make sure that
3317
     there is a byte at offset sofar.  If there are no symbols and no
3318
     relocs, then nothing follows the last section.  If we don't force
3319
     the last byte out, then the file may appear to be truncated.  */
3320
1
  if (align_adjust)
3321
0
    {
3322
0
      bfd_byte b;
3323
3324
0
      b = 0;
3325
0
      if (bfd_seek (abfd, sofar - 1, SEEK_SET) != 0
3326
0
    || bfd_write (&b, 1, abfd) != 1)
3327
0
  return false;
3328
0
    }
3329
3330
  /* Make sure the relocations are aligned.  We don't need to make
3331
     sure that this byte exists, because it will only matter if there
3332
     really are relocs.  */
3333
1
  sofar = BFD_ALIGN (sofar,
3334
1
         (bfd_vma) 1 << COFF_DEFAULT_SECTION_ALIGNMENT_POWER);
3335
3336
1
  obj_relocbase (abfd) = sofar;
3337
1
  abfd->output_has_begun = true;
3338
3339
1
  return true;
3340
1
}
Unexecuted instantiation: coff-stgo32.c:coff_compute_section_file_positions
Unexecuted instantiation: coff-tic30.c:coff_compute_section_file_positions
Unexecuted instantiation: coff-tic4x.c:coff_compute_section_file_positions
Unexecuted instantiation: coff-tic54x.c:coff_compute_section_file_positions
Unexecuted instantiation: coff-z80.c:coff_compute_section_file_positions
coff-z8k.c:coff_compute_section_file_positions
Line
Count
Source
2966
6
{
2967
6
  asection *current;
2968
6
  file_ptr sofar = bfd_coff_filhsz (abfd);
2969
6
  bool align_adjust;
2970
6
  unsigned int target_index;
2971
6
#ifdef ALIGN_SECTIONS_IN_FILE
2972
6
  asection *previous = NULL;
2973
6
  file_ptr old_sofar;
2974
6
#endif
2975
2976
#ifdef COFF_IMAGE_WITH_PE
2977
  unsigned int page_size;
2978
2979
  if (coff_data (abfd)->link_info
2980
      || (pe_data (abfd) && pe_data (abfd)->pe_opthdr.FileAlignment))
2981
    {
2982
      page_size = pe_data (abfd)->pe_opthdr.FileAlignment;
2983
2984
      /* If no file alignment has been set, default to one.
2985
   This repairs 'ld -r' for arm-wince-pe target.  */
2986
      if (page_size == 0)
2987
  page_size = 1;
2988
    }
2989
  else
2990
    page_size = PE_DEF_FILE_ALIGNMENT;
2991
#else
2992
#ifdef COFF_PAGE_SIZE
2993
  unsigned int page_size = COFF_PAGE_SIZE;
2994
#endif
2995
6
#endif
2996
2997
#ifdef RS6000COFF_C
2998
  /* On XCOFF, if we have symbols, set up the .debug section.  */
2999
  if (bfd_get_symcount (abfd) > 0)
3000
    {
3001
      bfd_size_type sz;
3002
      bfd_size_type i, symcount;
3003
      asymbol **symp;
3004
3005
      sz = 0;
3006
      symcount = bfd_get_symcount (abfd);
3007
      for (symp = abfd->outsymbols, i = 0; i < symcount; symp++, i++)
3008
  {
3009
    coff_symbol_type *cf;
3010
3011
    cf = coff_symbol_from (*symp);
3012
    if (cf != NULL
3013
        && cf->native != NULL
3014
        && cf->native->is_sym
3015
        && SYMNAME_IN_DEBUG (&cf->native->u.syment))
3016
      {
3017
        size_t len;
3018
3019
        len = strlen (bfd_asymbol_name (*symp));
3020
        if (len > SYMNMLEN || bfd_coff_force_symnames_in_strings (abfd))
3021
    sz += len + 1 + bfd_coff_debug_string_prefix_length (abfd);
3022
      }
3023
  }
3024
      if (sz > 0)
3025
  {
3026
    asection *dsec;
3027
3028
    dsec = bfd_make_section_old_way (abfd, DOT_DEBUG);
3029
    if (dsec == NULL)
3030
      abort ();
3031
    dsec->size = sz;
3032
    dsec->flags |= SEC_HAS_CONTENTS;
3033
  }
3034
    }
3035
#endif
3036
3037
6
  if (bfd_get_start_address (abfd))
3038
    /*  A start address may have been added to the original file. In this
3039
  case it will need an optional header to record it.  */
3040
0
    abfd->flags |= EXEC_P;
3041
3042
6
  if (abfd->flags & EXEC_P)
3043
6
    sofar += bfd_coff_aoutsz (abfd);
3044
#ifdef RS6000COFF_C
3045
  else if (xcoff_data (abfd)->full_aouthdr)
3046
    sofar += bfd_coff_aoutsz (abfd);
3047
  else
3048
    sofar += SMALL_AOUTSZ;
3049
#endif
3050
3051
6
  sofar += abfd->section_count * bfd_coff_scnhsz (abfd);
3052
3053
#ifdef RS6000COFF_C
3054
  /* XCOFF handles overflows in the reloc and line number count fields
3055
     by allocating a new section header to hold the correct counts.  */
3056
  for (current = abfd->sections; current != NULL; current = current->next)
3057
    if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3058
      sofar += bfd_coff_scnhsz (abfd);
3059
#endif
3060
3061
6
  if (coff_data (abfd)->section_by_target_index)
3062
0
    htab_empty (coff_data (abfd)->section_by_target_index);
3063
3064
#ifdef COFF_IMAGE_WITH_PE
3065
  {
3066
    /* PE requires the sections to be in memory order when listed in
3067
       the section headers.  It also does not like empty loadable
3068
       sections.  The sections apparently do not have to be in the
3069
       right order in the image file itself, but we do need to get the
3070
       target_index values right.  */
3071
3072
    unsigned int count;
3073
    asection **section_list;
3074
    unsigned int i;
3075
    bfd_size_type amt;
3076
3077
#ifdef COFF_PAGE_SIZE
3078
    /* Clear D_PAGED if section / file alignment aren't suitable for
3079
       paging at COFF_PAGE_SIZE granularity.  */
3080
   if (pe_data (abfd)->pe_opthdr.SectionAlignment < COFF_PAGE_SIZE
3081
       || page_size < COFF_PAGE_SIZE)
3082
     abfd->flags &= ~D_PAGED;
3083
#endif
3084
3085
    count = 0;
3086
    for (current = abfd->sections; current != NULL; current = current->next)
3087
      ++count;
3088
3089
    /* We allocate an extra cell to simplify the final loop.  */
3090
    amt = sizeof (struct asection *) * (count + 1);
3091
    section_list = (asection **) bfd_malloc (amt);
3092
    if (section_list == NULL)
3093
      return false;
3094
3095
    i = 0;
3096
    for (current = abfd->sections; current != NULL; current = current->next)
3097
      {
3098
  section_list[i] = current;
3099
  ++i;
3100
      }
3101
    section_list[i] = NULL;
3102
3103
    qsort (section_list, count, sizeof (asection *), sort_by_secaddr);
3104
3105
    /* Rethread the linked list into sorted order; at the same time,
3106
       assign target_index values.  */
3107
    target_index = 1;
3108
    abfd->sections = NULL;
3109
    abfd->section_last = NULL;
3110
    for (i = 0; i < count; i++)
3111
      {
3112
  current = section_list[i];
3113
  bfd_section_list_append (abfd, current);
3114
3115
  /* Later, if the section has zero size, we'll be throwing it
3116
     away, so we don't want to number it now.  Note that having
3117
     a zero size and having real contents are different
3118
     concepts: .bss has no contents, but (usually) non-zero
3119
     size.  */
3120
  if (current->size == 0)
3121
    {
3122
      /* Discard.  However, it still might have (valid) symbols
3123
         in it, so arbitrarily set it to section 1 (indexing is
3124
         1-based here; usually .text).  __end__ and other
3125
         contents of .endsection really have this happen.
3126
         FIXME: This seems somewhat dubious.  */
3127
      current->target_index = 1;
3128
    }
3129
  else
3130
    current->target_index = target_index++;
3131
      }
3132
3133
    free (section_list);
3134
  }
3135
#else /* ! COFF_IMAGE_WITH_PE */
3136
6
  {
3137
    /* Set the target_index field.  */
3138
6
    target_index = 1;
3139
1.02k
    for (current = abfd->sections; current != NULL; current = current->next)
3140
1.01k
      current->target_index = target_index++;
3141
6
  }
3142
6
#endif /* ! COFF_IMAGE_WITH_PE */
3143
3144
6
  if (target_index >= bfd_coff_max_nscns (abfd))
3145
0
    {
3146
0
      bfd_set_error (bfd_error_file_too_big);
3147
0
      _bfd_error_handler
3148
  /* xgettext:c-format */
3149
0
  (_("%pB: too many sections (%d)"), abfd, target_index);
3150
0
      return false;
3151
0
    }
3152
3153
6
  align_adjust = false;
3154
6
  for (current = abfd->sections;
3155
1.02k
       current != NULL;
3156
1.01k
       current = current->next)
3157
1.01k
    {
3158
#ifdef COFF_IMAGE_WITH_PE
3159
      /* With PE we have to pad each section to be a multiple of its
3160
   page size too, and remember both sizes.  */
3161
      if (coff_section_data (abfd, current) == NULL)
3162
  {
3163
    size_t amt = sizeof (struct coff_section_tdata);
3164
3165
    current->used_by_bfd = bfd_zalloc (abfd, amt);
3166
    if (current->used_by_bfd == NULL)
3167
      return false;
3168
  }
3169
      if (pei_section_data (abfd, current) == NULL)
3170
  {
3171
    size_t amt = sizeof (struct pei_section_tdata);
3172
3173
    coff_section_data (abfd, current)->tdata = bfd_zalloc (abfd, amt);
3174
    if (coff_section_data (abfd, current)->tdata == NULL)
3175
      return false;
3176
  }
3177
      if (pei_section_data (abfd, current)->virt_size == 0)
3178
  pei_section_data (abfd, current)->virt_size = current->size;
3179
#endif
3180
3181
      /* Only deal with sections which have contents.  */
3182
1.01k
      if (!(current->flags & SEC_HAS_CONTENTS))
3183
1.00k
  continue;
3184
3185
15
      current->rawsize = current->size;
3186
3187
#ifdef COFF_IMAGE_WITH_PE
3188
      /* Make sure we skip empty sections in a PE image.  */
3189
      if (current->size == 0)
3190
  continue;
3191
#endif
3192
3193
      /* Align the sections in the file to the same boundary on
3194
   which they are aligned in virtual memory.  */
3195
15
#ifdef ALIGN_SECTIONS_IN_FILE
3196
15
      if ((abfd->flags & EXEC_P) != 0)
3197
15
  {
3198
    /* Make sure this section is aligned on the right boundary - by
3199
       padding the previous section up if necessary.  */
3200
15
    old_sofar = sofar;
3201
3202
#ifdef COFF_IMAGE_WITH_PE
3203
    sofar = BFD_ALIGN (sofar, page_size);
3204
#else
3205
15
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3206
15
#endif
3207
3208
#ifdef RS6000COFF_C
3209
    /* Make sure the file offset and the vma of .text/.data are at the
3210
       same page offset, so that the file can be mmap'ed without being
3211
       relocated.  Failing that, AIX is able to load and execute the
3212
       program, but it will be silently relocated (possible as
3213
       executables are PIE).  But the relocation is slightly costly and
3214
       complexify the use of addr2line or gdb.  So better to avoid it,
3215
       like does the native linker.  Usually gnu ld makes sure that
3216
       the vma of .text is the file offset so this issue shouldn't
3217
       appear unless you are stripping such an executable.
3218
3219
       AIX loader checks the text section alignment of (vma - filepos),
3220
       and the native linker doesn't try to align the text sections.
3221
       For example:
3222
3223
       0 .text       000054cc  10000128  10000128  00000128  2**5
3224
           CONTENTS, ALLOC, LOAD, CODE
3225
3226
       Don't perform the above tweak if the previous one is .tdata,
3227
       as it will increase the memory allocated for every threads
3228
       created and not just improve performances with gdb.
3229
    */
3230
3231
    if ((current->flags & SEC_LOAD) != 0
3232
        && (!strcmp (current->name, _TEXT)
3233
      || !strcmp (current->name, _DATA))
3234
        && (previous == NULL || strcmp(previous->name, _TDATA)))
3235
      {
3236
        bfd_vma align = 4096;
3237
        bfd_vma sofar_off = sofar % align;
3238
        bfd_vma vma_off = current->vma % align;
3239
3240
        if (vma_off > sofar_off)
3241
    sofar += vma_off - sofar_off;
3242
        else if (vma_off < sofar_off)
3243
    sofar += align + vma_off - sofar_off;
3244
      }
3245
#endif
3246
15
    if (previous != NULL
3247
15
        && (previous->flags & SEC_LOAD) != 0)
3248
11
      previous->size += sofar - old_sofar;
3249
15
  }
3250
3251
15
#endif
3252
3253
      /* In demand paged files the low order bits of the file offset
3254
   must match the low order bits of the virtual address.  */
3255
#ifdef COFF_PAGE_SIZE
3256
      if ((abfd->flags & D_PAGED) != 0
3257
    && (current->flags & SEC_ALLOC) != 0)
3258
  sofar += (current->vma - (bfd_vma) sofar) % page_size;
3259
#endif
3260
15
      current->filepos = sofar;
3261
3262
#ifdef COFF_IMAGE_WITH_PE
3263
      /* Set the padded size.  */
3264
      current->size = (current->size + page_size - 1) & -page_size;
3265
#endif
3266
3267
15
      sofar += current->size;
3268
3269
15
#ifdef ALIGN_SECTIONS_IN_FILE
3270
      /* Make sure that this section is of the right size too.  */
3271
15
      if ((abfd->flags & EXEC_P) == 0)
3272
0
  {
3273
0
    bfd_size_type old_size;
3274
3275
0
    old_size = current->size;
3276
0
    current->size = BFD_ALIGN (current->size,
3277
0
             (bfd_vma) 1 << current->alignment_power);
3278
0
    align_adjust = current->size != old_size;
3279
0
    sofar += current->size - old_size;
3280
0
  }
3281
15
      else
3282
15
  {
3283
15
    old_sofar = sofar;
3284
#ifdef COFF_IMAGE_WITH_PE
3285
    sofar = BFD_ALIGN (sofar, page_size);
3286
#else
3287
15
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3288
15
#endif
3289
15
    align_adjust = sofar != old_sofar;
3290
15
    current->size += sofar - old_sofar;
3291
15
  }
3292
15
#endif
3293
3294
#ifdef COFF_IMAGE_WITH_PE
3295
      /* For PE we need to make sure we pad out to the aligned
3296
   size, in case the caller only writes out data to the
3297
   unaligned size.  */
3298
      if (pei_section_data (abfd, current)->virt_size < current->size)
3299
  align_adjust = true;
3300
#endif
3301
3302
15
#ifdef _LIB
3303
      /* Force .lib sections to start at zero.  The vma is then
3304
   incremented in coff_set_section_contents.  This is right for
3305
   SVR3.2.  */
3306
15
      if (strcmp (current->name, _LIB) == 0)
3307
0
  bfd_set_section_vma (current, 0);
3308
15
#endif
3309
3310
15
#ifdef ALIGN_SECTIONS_IN_FILE
3311
15
      previous = current;
3312
15
#endif
3313
15
    }
3314
3315
  /* It is now safe to write to the output file.  If we needed an
3316
     alignment adjustment for the last section, then make sure that
3317
     there is a byte at offset sofar.  If there are no symbols and no
3318
     relocs, then nothing follows the last section.  If we don't force
3319
     the last byte out, then the file may appear to be truncated.  */
3320
6
  if (align_adjust)
3321
1
    {
3322
1
      bfd_byte b;
3323
3324
1
      b = 0;
3325
1
      if (bfd_seek (abfd, sofar - 1, SEEK_SET) != 0
3326
1
    || bfd_write (&b, 1, abfd) != 1)
3327
0
  return false;
3328
1
    }
3329
3330
  /* Make sure the relocations are aligned.  We don't need to make
3331
     sure that this byte exists, because it will only matter if there
3332
     really are relocs.  */
3333
6
  sofar = BFD_ALIGN (sofar,
3334
6
         (bfd_vma) 1 << COFF_DEFAULT_SECTION_ALIGNMENT_POWER);
3335
3336
6
  obj_relocbase (abfd) = sofar;
3337
6
  abfd->output_has_begun = true;
3338
3339
6
  return true;
3340
6
}
Unexecuted instantiation: pe-arm-wince.c:coff_compute_section_file_positions
Unexecuted instantiation: pe-arm.c:coff_compute_section_file_positions
pe-i386.c:coff_compute_section_file_positions
Line
Count
Source
2966
3
{
2967
3
  asection *current;
2968
3
  file_ptr sofar = bfd_coff_filhsz (abfd);
2969
3
  bool align_adjust;
2970
3
  unsigned int target_index;
2971
3
#ifdef ALIGN_SECTIONS_IN_FILE
2972
3
  asection *previous = NULL;
2973
3
  file_ptr old_sofar;
2974
3
#endif
2975
2976
#ifdef COFF_IMAGE_WITH_PE
2977
  unsigned int page_size;
2978
2979
  if (coff_data (abfd)->link_info
2980
      || (pe_data (abfd) && pe_data (abfd)->pe_opthdr.FileAlignment))
2981
    {
2982
      page_size = pe_data (abfd)->pe_opthdr.FileAlignment;
2983
2984
      /* If no file alignment has been set, default to one.
2985
   This repairs 'ld -r' for arm-wince-pe target.  */
2986
      if (page_size == 0)
2987
  page_size = 1;
2988
    }
2989
  else
2990
    page_size = PE_DEF_FILE_ALIGNMENT;
2991
#else
2992
3
#ifdef COFF_PAGE_SIZE
2993
3
  unsigned int page_size = COFF_PAGE_SIZE;
2994
3
#endif
2995
3
#endif
2996
2997
#ifdef RS6000COFF_C
2998
  /* On XCOFF, if we have symbols, set up the .debug section.  */
2999
  if (bfd_get_symcount (abfd) > 0)
3000
    {
3001
      bfd_size_type sz;
3002
      bfd_size_type i, symcount;
3003
      asymbol **symp;
3004
3005
      sz = 0;
3006
      symcount = bfd_get_symcount (abfd);
3007
      for (symp = abfd->outsymbols, i = 0; i < symcount; symp++, i++)
3008
  {
3009
    coff_symbol_type *cf;
3010
3011
    cf = coff_symbol_from (*symp);
3012
    if (cf != NULL
3013
        && cf->native != NULL
3014
        && cf->native->is_sym
3015
        && SYMNAME_IN_DEBUG (&cf->native->u.syment))
3016
      {
3017
        size_t len;
3018
3019
        len = strlen (bfd_asymbol_name (*symp));
3020
        if (len > SYMNMLEN || bfd_coff_force_symnames_in_strings (abfd))
3021
    sz += len + 1 + bfd_coff_debug_string_prefix_length (abfd);
3022
      }
3023
  }
3024
      if (sz > 0)
3025
  {
3026
    asection *dsec;
3027
3028
    dsec = bfd_make_section_old_way (abfd, DOT_DEBUG);
3029
    if (dsec == NULL)
3030
      abort ();
3031
    dsec->size = sz;
3032
    dsec->flags |= SEC_HAS_CONTENTS;
3033
  }
3034
    }
3035
#endif
3036
3037
3
  if (bfd_get_start_address (abfd))
3038
    /*  A start address may have been added to the original file. In this
3039
  case it will need an optional header to record it.  */
3040
0
    abfd->flags |= EXEC_P;
3041
3042
3
  if (abfd->flags & EXEC_P)
3043
0
    sofar += bfd_coff_aoutsz (abfd);
3044
#ifdef RS6000COFF_C
3045
  else if (xcoff_data (abfd)->full_aouthdr)
3046
    sofar += bfd_coff_aoutsz (abfd);
3047
  else
3048
    sofar += SMALL_AOUTSZ;
3049
#endif
3050
3051
3
  sofar += abfd->section_count * bfd_coff_scnhsz (abfd);
3052
3053
#ifdef RS6000COFF_C
3054
  /* XCOFF handles overflows in the reloc and line number count fields
3055
     by allocating a new section header to hold the correct counts.  */
3056
  for (current = abfd->sections; current != NULL; current = current->next)
3057
    if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3058
      sofar += bfd_coff_scnhsz (abfd);
3059
#endif
3060
3061
3
  if (coff_data (abfd)->section_by_target_index)
3062
0
    htab_empty (coff_data (abfd)->section_by_target_index);
3063
3064
#ifdef COFF_IMAGE_WITH_PE
3065
  {
3066
    /* PE requires the sections to be in memory order when listed in
3067
       the section headers.  It also does not like empty loadable
3068
       sections.  The sections apparently do not have to be in the
3069
       right order in the image file itself, but we do need to get the
3070
       target_index values right.  */
3071
3072
    unsigned int count;
3073
    asection **section_list;
3074
    unsigned int i;
3075
    bfd_size_type amt;
3076
3077
#ifdef COFF_PAGE_SIZE
3078
    /* Clear D_PAGED if section / file alignment aren't suitable for
3079
       paging at COFF_PAGE_SIZE granularity.  */
3080
   if (pe_data (abfd)->pe_opthdr.SectionAlignment < COFF_PAGE_SIZE
3081
       || page_size < COFF_PAGE_SIZE)
3082
     abfd->flags &= ~D_PAGED;
3083
#endif
3084
3085
    count = 0;
3086
    for (current = abfd->sections; current != NULL; current = current->next)
3087
      ++count;
3088
3089
    /* We allocate an extra cell to simplify the final loop.  */
3090
    amt = sizeof (struct asection *) * (count + 1);
3091
    section_list = (asection **) bfd_malloc (amt);
3092
    if (section_list == NULL)
3093
      return false;
3094
3095
    i = 0;
3096
    for (current = abfd->sections; current != NULL; current = current->next)
3097
      {
3098
  section_list[i] = current;
3099
  ++i;
3100
      }
3101
    section_list[i] = NULL;
3102
3103
    qsort (section_list, count, sizeof (asection *), sort_by_secaddr);
3104
3105
    /* Rethread the linked list into sorted order; at the same time,
3106
       assign target_index values.  */
3107
    target_index = 1;
3108
    abfd->sections = NULL;
3109
    abfd->section_last = NULL;
3110
    for (i = 0; i < count; i++)
3111
      {
3112
  current = section_list[i];
3113
  bfd_section_list_append (abfd, current);
3114
3115
  /* Later, if the section has zero size, we'll be throwing it
3116
     away, so we don't want to number it now.  Note that having
3117
     a zero size and having real contents are different
3118
     concepts: .bss has no contents, but (usually) non-zero
3119
     size.  */
3120
  if (current->size == 0)
3121
    {
3122
      /* Discard.  However, it still might have (valid) symbols
3123
         in it, so arbitrarily set it to section 1 (indexing is
3124
         1-based here; usually .text).  __end__ and other
3125
         contents of .endsection really have this happen.
3126
         FIXME: This seems somewhat dubious.  */
3127
      current->target_index = 1;
3128
    }
3129
  else
3130
    current->target_index = target_index++;
3131
      }
3132
3133
    free (section_list);
3134
  }
3135
#else /* ! COFF_IMAGE_WITH_PE */
3136
3
  {
3137
    /* Set the target_index field.  */
3138
3
    target_index = 1;
3139
502
    for (current = abfd->sections; current != NULL; current = current->next)
3140
499
      current->target_index = target_index++;
3141
3
  }
3142
3
#endif /* ! COFF_IMAGE_WITH_PE */
3143
3144
3
  if (target_index >= bfd_coff_max_nscns (abfd))
3145
0
    {
3146
0
      bfd_set_error (bfd_error_file_too_big);
3147
0
      _bfd_error_handler
3148
  /* xgettext:c-format */
3149
0
  (_("%pB: too many sections (%d)"), abfd, target_index);
3150
0
      return false;
3151
0
    }
3152
3153
3
  align_adjust = false;
3154
3
  for (current = abfd->sections;
3155
502
       current != NULL;
3156
499
       current = current->next)
3157
499
    {
3158
#ifdef COFF_IMAGE_WITH_PE
3159
      /* With PE we have to pad each section to be a multiple of its
3160
   page size too, and remember both sizes.  */
3161
      if (coff_section_data (abfd, current) == NULL)
3162
  {
3163
    size_t amt = sizeof (struct coff_section_tdata);
3164
3165
    current->used_by_bfd = bfd_zalloc (abfd, amt);
3166
    if (current->used_by_bfd == NULL)
3167
      return false;
3168
  }
3169
      if (pei_section_data (abfd, current) == NULL)
3170
  {
3171
    size_t amt = sizeof (struct pei_section_tdata);
3172
3173
    coff_section_data (abfd, current)->tdata = bfd_zalloc (abfd, amt);
3174
    if (coff_section_data (abfd, current)->tdata == NULL)
3175
      return false;
3176
  }
3177
      if (pei_section_data (abfd, current)->virt_size == 0)
3178
  pei_section_data (abfd, current)->virt_size = current->size;
3179
#endif
3180
3181
      /* Only deal with sections which have contents.  */
3182
499
      if (!(current->flags & SEC_HAS_CONTENTS))
3183
496
  continue;
3184
3185
3
      current->rawsize = current->size;
3186
3187
#ifdef COFF_IMAGE_WITH_PE
3188
      /* Make sure we skip empty sections in a PE image.  */
3189
      if (current->size == 0)
3190
  continue;
3191
#endif
3192
3193
      /* Align the sections in the file to the same boundary on
3194
   which they are aligned in virtual memory.  */
3195
3
#ifdef ALIGN_SECTIONS_IN_FILE
3196
3
      if ((abfd->flags & EXEC_P) != 0)
3197
0
  {
3198
    /* Make sure this section is aligned on the right boundary - by
3199
       padding the previous section up if necessary.  */
3200
0
    old_sofar = sofar;
3201
3202
#ifdef COFF_IMAGE_WITH_PE
3203
    sofar = BFD_ALIGN (sofar, page_size);
3204
#else
3205
0
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3206
0
#endif
3207
3208
#ifdef RS6000COFF_C
3209
    /* Make sure the file offset and the vma of .text/.data are at the
3210
       same page offset, so that the file can be mmap'ed without being
3211
       relocated.  Failing that, AIX is able to load and execute the
3212
       program, but it will be silently relocated (possible as
3213
       executables are PIE).  But the relocation is slightly costly and
3214
       complexify the use of addr2line or gdb.  So better to avoid it,
3215
       like does the native linker.  Usually gnu ld makes sure that
3216
       the vma of .text is the file offset so this issue shouldn't
3217
       appear unless you are stripping such an executable.
3218
3219
       AIX loader checks the text section alignment of (vma - filepos),
3220
       and the native linker doesn't try to align the text sections.
3221
       For example:
3222
3223
       0 .text       000054cc  10000128  10000128  00000128  2**5
3224
           CONTENTS, ALLOC, LOAD, CODE
3225
3226
       Don't perform the above tweak if the previous one is .tdata,
3227
       as it will increase the memory allocated for every threads
3228
       created and not just improve performances with gdb.
3229
    */
3230
3231
    if ((current->flags & SEC_LOAD) != 0
3232
        && (!strcmp (current->name, _TEXT)
3233
      || !strcmp (current->name, _DATA))
3234
        && (previous == NULL || strcmp(previous->name, _TDATA)))
3235
      {
3236
        bfd_vma align = 4096;
3237
        bfd_vma sofar_off = sofar % align;
3238
        bfd_vma vma_off = current->vma % align;
3239
3240
        if (vma_off > sofar_off)
3241
    sofar += vma_off - sofar_off;
3242
        else if (vma_off < sofar_off)
3243
    sofar += align + vma_off - sofar_off;
3244
      }
3245
#endif
3246
0
    if (previous != NULL
3247
0
        && (previous->flags & SEC_LOAD) != 0)
3248
0
      previous->size += sofar - old_sofar;
3249
0
  }
3250
3251
3
#endif
3252
3253
      /* In demand paged files the low order bits of the file offset
3254
   must match the low order bits of the virtual address.  */
3255
3
#ifdef COFF_PAGE_SIZE
3256
3
      if ((abfd->flags & D_PAGED) != 0
3257
3
    && (current->flags & SEC_ALLOC) != 0)
3258
0
  sofar += (current->vma - (bfd_vma) sofar) % page_size;
3259
3
#endif
3260
3
      current->filepos = sofar;
3261
3262
#ifdef COFF_IMAGE_WITH_PE
3263
      /* Set the padded size.  */
3264
      current->size = (current->size + page_size - 1) & -page_size;
3265
#endif
3266
3267
3
      sofar += current->size;
3268
3269
3
#ifdef ALIGN_SECTIONS_IN_FILE
3270
      /* Make sure that this section is of the right size too.  */
3271
3
      if ((abfd->flags & EXEC_P) == 0)
3272
3
  {
3273
3
    bfd_size_type old_size;
3274
3275
3
    old_size = current->size;
3276
3
    current->size = BFD_ALIGN (current->size,
3277
3
             (bfd_vma) 1 << current->alignment_power);
3278
3
    align_adjust = current->size != old_size;
3279
3
    sofar += current->size - old_size;
3280
3
  }
3281
0
      else
3282
0
  {
3283
0
    old_sofar = sofar;
3284
#ifdef COFF_IMAGE_WITH_PE
3285
    sofar = BFD_ALIGN (sofar, page_size);
3286
#else
3287
0
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3288
0
#endif
3289
0
    align_adjust = sofar != old_sofar;
3290
0
    current->size += sofar - old_sofar;
3291
0
  }
3292
3
#endif
3293
3294
#ifdef COFF_IMAGE_WITH_PE
3295
      /* For PE we need to make sure we pad out to the aligned
3296
   size, in case the caller only writes out data to the
3297
   unaligned size.  */
3298
      if (pei_section_data (abfd, current)->virt_size < current->size)
3299
  align_adjust = true;
3300
#endif
3301
3302
3
#ifdef _LIB
3303
      /* Force .lib sections to start at zero.  The vma is then
3304
   incremented in coff_set_section_contents.  This is right for
3305
   SVR3.2.  */
3306
3
      if (strcmp (current->name, _LIB) == 0)
3307
0
  bfd_set_section_vma (current, 0);
3308
3
#endif
3309
3310
3
#ifdef ALIGN_SECTIONS_IN_FILE
3311
3
      previous = current;
3312
3
#endif
3313
3
    }
3314
3315
  /* It is now safe to write to the output file.  If we needed an
3316
     alignment adjustment for the last section, then make sure that
3317
     there is a byte at offset sofar.  If there are no symbols and no
3318
     relocs, then nothing follows the last section.  If we don't force
3319
     the last byte out, then the file may appear to be truncated.  */
3320
3
  if (align_adjust)
3321
0
    {
3322
0
      bfd_byte b;
3323
3324
0
      b = 0;
3325
0
      if (bfd_seek (abfd, sofar - 1, SEEK_SET) != 0
3326
0
    || bfd_write (&b, 1, abfd) != 1)
3327
0
  return false;
3328
0
    }
3329
3330
  /* Make sure the relocations are aligned.  We don't need to make
3331
     sure that this byte exists, because it will only matter if there
3332
     really are relocs.  */
3333
3
  sofar = BFD_ALIGN (sofar,
3334
3
         (bfd_vma) 1 << COFF_DEFAULT_SECTION_ALIGNMENT_POWER);
3335
3336
3
  obj_relocbase (abfd) = sofar;
3337
3
  abfd->output_has_begun = true;
3338
3339
3
  return true;
3340
3
}
pe-mcore.c:coff_compute_section_file_positions
Line
Count
Source
2966
2
{
2967
2
  asection *current;
2968
2
  file_ptr sofar = bfd_coff_filhsz (abfd);
2969
2
  bool align_adjust;
2970
2
  unsigned int target_index;
2971
2
#ifdef ALIGN_SECTIONS_IN_FILE
2972
2
  asection *previous = NULL;
2973
2
  file_ptr old_sofar;
2974
2
#endif
2975
2976
#ifdef COFF_IMAGE_WITH_PE
2977
  unsigned int page_size;
2978
2979
  if (coff_data (abfd)->link_info
2980
      || (pe_data (abfd) && pe_data (abfd)->pe_opthdr.FileAlignment))
2981
    {
2982
      page_size = pe_data (abfd)->pe_opthdr.FileAlignment;
2983
2984
      /* If no file alignment has been set, default to one.
2985
   This repairs 'ld -r' for arm-wince-pe target.  */
2986
      if (page_size == 0)
2987
  page_size = 1;
2988
    }
2989
  else
2990
    page_size = PE_DEF_FILE_ALIGNMENT;
2991
#else
2992
2
#ifdef COFF_PAGE_SIZE
2993
2
  unsigned int page_size = COFF_PAGE_SIZE;
2994
2
#endif
2995
2
#endif
2996
2997
#ifdef RS6000COFF_C
2998
  /* On XCOFF, if we have symbols, set up the .debug section.  */
2999
  if (bfd_get_symcount (abfd) > 0)
3000
    {
3001
      bfd_size_type sz;
3002
      bfd_size_type i, symcount;
3003
      asymbol **symp;
3004
3005
      sz = 0;
3006
      symcount = bfd_get_symcount (abfd);
3007
      for (symp = abfd->outsymbols, i = 0; i < symcount; symp++, i++)
3008
  {
3009
    coff_symbol_type *cf;
3010
3011
    cf = coff_symbol_from (*symp);
3012
    if (cf != NULL
3013
        && cf->native != NULL
3014
        && cf->native->is_sym
3015
        && SYMNAME_IN_DEBUG (&cf->native->u.syment))
3016
      {
3017
        size_t len;
3018
3019
        len = strlen (bfd_asymbol_name (*symp));
3020
        if (len > SYMNMLEN || bfd_coff_force_symnames_in_strings (abfd))
3021
    sz += len + 1 + bfd_coff_debug_string_prefix_length (abfd);
3022
      }
3023
  }
3024
      if (sz > 0)
3025
  {
3026
    asection *dsec;
3027
3028
    dsec = bfd_make_section_old_way (abfd, DOT_DEBUG);
3029
    if (dsec == NULL)
3030
      abort ();
3031
    dsec->size = sz;
3032
    dsec->flags |= SEC_HAS_CONTENTS;
3033
  }
3034
    }
3035
#endif
3036
3037
2
  if (bfd_get_start_address (abfd))
3038
    /*  A start address may have been added to the original file. In this
3039
  case it will need an optional header to record it.  */
3040
0
    abfd->flags |= EXEC_P;
3041
3042
2
  if (abfd->flags & EXEC_P)
3043
1
    sofar += bfd_coff_aoutsz (abfd);
3044
#ifdef RS6000COFF_C
3045
  else if (xcoff_data (abfd)->full_aouthdr)
3046
    sofar += bfd_coff_aoutsz (abfd);
3047
  else
3048
    sofar += SMALL_AOUTSZ;
3049
#endif
3050
3051
2
  sofar += abfd->section_count * bfd_coff_scnhsz (abfd);
3052
3053
#ifdef RS6000COFF_C
3054
  /* XCOFF handles overflows in the reloc and line number count fields
3055
     by allocating a new section header to hold the correct counts.  */
3056
  for (current = abfd->sections; current != NULL; current = current->next)
3057
    if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3058
      sofar += bfd_coff_scnhsz (abfd);
3059
#endif
3060
3061
2
  if (coff_data (abfd)->section_by_target_index)
3062
0
    htab_empty (coff_data (abfd)->section_by_target_index);
3063
3064
#ifdef COFF_IMAGE_WITH_PE
3065
  {
3066
    /* PE requires the sections to be in memory order when listed in
3067
       the section headers.  It also does not like empty loadable
3068
       sections.  The sections apparently do not have to be in the
3069
       right order in the image file itself, but we do need to get the
3070
       target_index values right.  */
3071
3072
    unsigned int count;
3073
    asection **section_list;
3074
    unsigned int i;
3075
    bfd_size_type amt;
3076
3077
#ifdef COFF_PAGE_SIZE
3078
    /* Clear D_PAGED if section / file alignment aren't suitable for
3079
       paging at COFF_PAGE_SIZE granularity.  */
3080
   if (pe_data (abfd)->pe_opthdr.SectionAlignment < COFF_PAGE_SIZE
3081
       || page_size < COFF_PAGE_SIZE)
3082
     abfd->flags &= ~D_PAGED;
3083
#endif
3084
3085
    count = 0;
3086
    for (current = abfd->sections; current != NULL; current = current->next)
3087
      ++count;
3088
3089
    /* We allocate an extra cell to simplify the final loop.  */
3090
    amt = sizeof (struct asection *) * (count + 1);
3091
    section_list = (asection **) bfd_malloc (amt);
3092
    if (section_list == NULL)
3093
      return false;
3094
3095
    i = 0;
3096
    for (current = abfd->sections; current != NULL; current = current->next)
3097
      {
3098
  section_list[i] = current;
3099
  ++i;
3100
      }
3101
    section_list[i] = NULL;
3102
3103
    qsort (section_list, count, sizeof (asection *), sort_by_secaddr);
3104
3105
    /* Rethread the linked list into sorted order; at the same time,
3106
       assign target_index values.  */
3107
    target_index = 1;
3108
    abfd->sections = NULL;
3109
    abfd->section_last = NULL;
3110
    for (i = 0; i < count; i++)
3111
      {
3112
  current = section_list[i];
3113
  bfd_section_list_append (abfd, current);
3114
3115
  /* Later, if the section has zero size, we'll be throwing it
3116
     away, so we don't want to number it now.  Note that having
3117
     a zero size and having real contents are different
3118
     concepts: .bss has no contents, but (usually) non-zero
3119
     size.  */
3120
  if (current->size == 0)
3121
    {
3122
      /* Discard.  However, it still might have (valid) symbols
3123
         in it, so arbitrarily set it to section 1 (indexing is
3124
         1-based here; usually .text).  __end__ and other
3125
         contents of .endsection really have this happen.
3126
         FIXME: This seems somewhat dubious.  */
3127
      current->target_index = 1;
3128
    }
3129
  else
3130
    current->target_index = target_index++;
3131
      }
3132
3133
    free (section_list);
3134
  }
3135
#else /* ! COFF_IMAGE_WITH_PE */
3136
2
  {
3137
    /* Set the target_index field.  */
3138
2
    target_index = 1;
3139
9
    for (current = abfd->sections; current != NULL; current = current->next)
3140
7
      current->target_index = target_index++;
3141
2
  }
3142
2
#endif /* ! COFF_IMAGE_WITH_PE */
3143
3144
2
  if (target_index >= bfd_coff_max_nscns (abfd))
3145
0
    {
3146
0
      bfd_set_error (bfd_error_file_too_big);
3147
0
      _bfd_error_handler
3148
  /* xgettext:c-format */
3149
0
  (_("%pB: too many sections (%d)"), abfd, target_index);
3150
0
      return false;
3151
0
    }
3152
3153
2
  align_adjust = false;
3154
2
  for (current = abfd->sections;
3155
9
       current != NULL;
3156
7
       current = current->next)
3157
7
    {
3158
#ifdef COFF_IMAGE_WITH_PE
3159
      /* With PE we have to pad each section to be a multiple of its
3160
   page size too, and remember both sizes.  */
3161
      if (coff_section_data (abfd, current) == NULL)
3162
  {
3163
    size_t amt = sizeof (struct coff_section_tdata);
3164
3165
    current->used_by_bfd = bfd_zalloc (abfd, amt);
3166
    if (current->used_by_bfd == NULL)
3167
      return false;
3168
  }
3169
      if (pei_section_data (abfd, current) == NULL)
3170
  {
3171
    size_t amt = sizeof (struct pei_section_tdata);
3172
3173
    coff_section_data (abfd, current)->tdata = bfd_zalloc (abfd, amt);
3174
    if (coff_section_data (abfd, current)->tdata == NULL)
3175
      return false;
3176
  }
3177
      if (pei_section_data (abfd, current)->virt_size == 0)
3178
  pei_section_data (abfd, current)->virt_size = current->size;
3179
#endif
3180
3181
      /* Only deal with sections which have contents.  */
3182
7
      if (!(current->flags & SEC_HAS_CONTENTS))
3183
7
  continue;
3184
3185
0
      current->rawsize = current->size;
3186
3187
#ifdef COFF_IMAGE_WITH_PE
3188
      /* Make sure we skip empty sections in a PE image.  */
3189
      if (current->size == 0)
3190
  continue;
3191
#endif
3192
3193
      /* Align the sections in the file to the same boundary on
3194
   which they are aligned in virtual memory.  */
3195
0
#ifdef ALIGN_SECTIONS_IN_FILE
3196
0
      if ((abfd->flags & EXEC_P) != 0)
3197
0
  {
3198
    /* Make sure this section is aligned on the right boundary - by
3199
       padding the previous section up if necessary.  */
3200
0
    old_sofar = sofar;
3201
3202
#ifdef COFF_IMAGE_WITH_PE
3203
    sofar = BFD_ALIGN (sofar, page_size);
3204
#else
3205
0
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3206
0
#endif
3207
3208
#ifdef RS6000COFF_C
3209
    /* Make sure the file offset and the vma of .text/.data are at the
3210
       same page offset, so that the file can be mmap'ed without being
3211
       relocated.  Failing that, AIX is able to load and execute the
3212
       program, but it will be silently relocated (possible as
3213
       executables are PIE).  But the relocation is slightly costly and
3214
       complexify the use of addr2line or gdb.  So better to avoid it,
3215
       like does the native linker.  Usually gnu ld makes sure that
3216
       the vma of .text is the file offset so this issue shouldn't
3217
       appear unless you are stripping such an executable.
3218
3219
       AIX loader checks the text section alignment of (vma - filepos),
3220
       and the native linker doesn't try to align the text sections.
3221
       For example:
3222
3223
       0 .text       000054cc  10000128  10000128  00000128  2**5
3224
           CONTENTS, ALLOC, LOAD, CODE
3225
3226
       Don't perform the above tweak if the previous one is .tdata,
3227
       as it will increase the memory allocated for every threads
3228
       created and not just improve performances with gdb.
3229
    */
3230
3231
    if ((current->flags & SEC_LOAD) != 0
3232
        && (!strcmp (current->name, _TEXT)
3233
      || !strcmp (current->name, _DATA))
3234
        && (previous == NULL || strcmp(previous->name, _TDATA)))
3235
      {
3236
        bfd_vma align = 4096;
3237
        bfd_vma sofar_off = sofar % align;
3238
        bfd_vma vma_off = current->vma % align;
3239
3240
        if (vma_off > sofar_off)
3241
    sofar += vma_off - sofar_off;
3242
        else if (vma_off < sofar_off)
3243
    sofar += align + vma_off - sofar_off;
3244
      }
3245
#endif
3246
0
    if (previous != NULL
3247
0
        && (previous->flags & SEC_LOAD) != 0)
3248
0
      previous->size += sofar - old_sofar;
3249
0
  }
3250
3251
0
#endif
3252
3253
      /* In demand paged files the low order bits of the file offset
3254
   must match the low order bits of the virtual address.  */
3255
0
#ifdef COFF_PAGE_SIZE
3256
0
      if ((abfd->flags & D_PAGED) != 0
3257
0
    && (current->flags & SEC_ALLOC) != 0)
3258
0
  sofar += (current->vma - (bfd_vma) sofar) % page_size;
3259
0
#endif
3260
0
      current->filepos = sofar;
3261
3262
#ifdef COFF_IMAGE_WITH_PE
3263
      /* Set the padded size.  */
3264
      current->size = (current->size + page_size - 1) & -page_size;
3265
#endif
3266
3267
0
      sofar += current->size;
3268
3269
0
#ifdef ALIGN_SECTIONS_IN_FILE
3270
      /* Make sure that this section is of the right size too.  */
3271
0
      if ((abfd->flags & EXEC_P) == 0)
3272
0
  {
3273
0
    bfd_size_type old_size;
3274
3275
0
    old_size = current->size;
3276
0
    current->size = BFD_ALIGN (current->size,
3277
0
             (bfd_vma) 1 << current->alignment_power);
3278
0
    align_adjust = current->size != old_size;
3279
0
    sofar += current->size - old_size;
3280
0
  }
3281
0
      else
3282
0
  {
3283
0
    old_sofar = sofar;
3284
#ifdef COFF_IMAGE_WITH_PE
3285
    sofar = BFD_ALIGN (sofar, page_size);
3286
#else
3287
0
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3288
0
#endif
3289
0
    align_adjust = sofar != old_sofar;
3290
0
    current->size += sofar - old_sofar;
3291
0
  }
3292
0
#endif
3293
3294
#ifdef COFF_IMAGE_WITH_PE
3295
      /* For PE we need to make sure we pad out to the aligned
3296
   size, in case the caller only writes out data to the
3297
   unaligned size.  */
3298
      if (pei_section_data (abfd, current)->virt_size < current->size)
3299
  align_adjust = true;
3300
#endif
3301
3302
0
#ifdef _LIB
3303
      /* Force .lib sections to start at zero.  The vma is then
3304
   incremented in coff_set_section_contents.  This is right for
3305
   SVR3.2.  */
3306
0
      if (strcmp (current->name, _LIB) == 0)
3307
0
  bfd_set_section_vma (current, 0);
3308
0
#endif
3309
3310
0
#ifdef ALIGN_SECTIONS_IN_FILE
3311
0
      previous = current;
3312
0
#endif
3313
0
    }
3314
3315
  /* It is now safe to write to the output file.  If we needed an
3316
     alignment adjustment for the last section, then make sure that
3317
     there is a byte at offset sofar.  If there are no symbols and no
3318
     relocs, then nothing follows the last section.  If we don't force
3319
     the last byte out, then the file may appear to be truncated.  */
3320
2
  if (align_adjust)
3321
0
    {
3322
0
      bfd_byte b;
3323
3324
0
      b = 0;
3325
0
      if (bfd_seek (abfd, sofar - 1, SEEK_SET) != 0
3326
0
    || bfd_write (&b, 1, abfd) != 1)
3327
0
  return false;
3328
0
    }
3329
3330
  /* Make sure the relocations are aligned.  We don't need to make
3331
     sure that this byte exists, because it will only matter if there
3332
     really are relocs.  */
3333
2
  sofar = BFD_ALIGN (sofar,
3334
2
         (bfd_vma) 1 << COFF_DEFAULT_SECTION_ALIGNMENT_POWER);
3335
3336
2
  obj_relocbase (abfd) = sofar;
3337
2
  abfd->output_has_begun = true;
3338
3339
2
  return true;
3340
2
}
Unexecuted instantiation: pe-sh.c:coff_compute_section_file_positions
pei-arm-wince.c:coff_compute_section_file_positions
Line
Count
Source
2966
1
{
2967
1
  asection *current;
2968
1
  file_ptr sofar = bfd_coff_filhsz (abfd);
2969
1
  bool align_adjust;
2970
1
  unsigned int target_index;
2971
1
#ifdef ALIGN_SECTIONS_IN_FILE
2972
1
  asection *previous = NULL;
2973
1
  file_ptr old_sofar;
2974
1
#endif
2975
2976
1
#ifdef COFF_IMAGE_WITH_PE
2977
1
  unsigned int page_size;
2978
2979
1
  if (coff_data (abfd)->link_info
2980
1
      || (pe_data (abfd) && pe_data (abfd)->pe_opthdr.FileAlignment))
2981
1
    {
2982
1
      page_size = pe_data (abfd)->pe_opthdr.FileAlignment;
2983
2984
      /* If no file alignment has been set, default to one.
2985
   This repairs 'ld -r' for arm-wince-pe target.  */
2986
1
      if (page_size == 0)
2987
0
  page_size = 1;
2988
1
    }
2989
0
  else
2990
0
    page_size = PE_DEF_FILE_ALIGNMENT;
2991
#else
2992
#ifdef COFF_PAGE_SIZE
2993
  unsigned int page_size = COFF_PAGE_SIZE;
2994
#endif
2995
#endif
2996
2997
#ifdef RS6000COFF_C
2998
  /* On XCOFF, if we have symbols, set up the .debug section.  */
2999
  if (bfd_get_symcount (abfd) > 0)
3000
    {
3001
      bfd_size_type sz;
3002
      bfd_size_type i, symcount;
3003
      asymbol **symp;
3004
3005
      sz = 0;
3006
      symcount = bfd_get_symcount (abfd);
3007
      for (symp = abfd->outsymbols, i = 0; i < symcount; symp++, i++)
3008
  {
3009
    coff_symbol_type *cf;
3010
3011
    cf = coff_symbol_from (*symp);
3012
    if (cf != NULL
3013
        && cf->native != NULL
3014
        && cf->native->is_sym
3015
        && SYMNAME_IN_DEBUG (&cf->native->u.syment))
3016
      {
3017
        size_t len;
3018
3019
        len = strlen (bfd_asymbol_name (*symp));
3020
        if (len > SYMNMLEN || bfd_coff_force_symnames_in_strings (abfd))
3021
    sz += len + 1 + bfd_coff_debug_string_prefix_length (abfd);
3022
      }
3023
  }
3024
      if (sz > 0)
3025
  {
3026
    asection *dsec;
3027
3028
    dsec = bfd_make_section_old_way (abfd, DOT_DEBUG);
3029
    if (dsec == NULL)
3030
      abort ();
3031
    dsec->size = sz;
3032
    dsec->flags |= SEC_HAS_CONTENTS;
3033
  }
3034
    }
3035
#endif
3036
3037
1
  if (bfd_get_start_address (abfd))
3038
    /*  A start address may have been added to the original file. In this
3039
  case it will need an optional header to record it.  */
3040
0
    abfd->flags |= EXEC_P;
3041
3042
1
  if (abfd->flags & EXEC_P)
3043
0
    sofar += bfd_coff_aoutsz (abfd);
3044
#ifdef RS6000COFF_C
3045
  else if (xcoff_data (abfd)->full_aouthdr)
3046
    sofar += bfd_coff_aoutsz (abfd);
3047
  else
3048
    sofar += SMALL_AOUTSZ;
3049
#endif
3050
3051
1
  sofar += abfd->section_count * bfd_coff_scnhsz (abfd);
3052
3053
#ifdef RS6000COFF_C
3054
  /* XCOFF handles overflows in the reloc and line number count fields
3055
     by allocating a new section header to hold the correct counts.  */
3056
  for (current = abfd->sections; current != NULL; current = current->next)
3057
    if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3058
      sofar += bfd_coff_scnhsz (abfd);
3059
#endif
3060
3061
1
  if (coff_data (abfd)->section_by_target_index)
3062
0
    htab_empty (coff_data (abfd)->section_by_target_index);
3063
3064
1
#ifdef COFF_IMAGE_WITH_PE
3065
1
  {
3066
    /* PE requires the sections to be in memory order when listed in
3067
       the section headers.  It also does not like empty loadable
3068
       sections.  The sections apparently do not have to be in the
3069
       right order in the image file itself, but we do need to get the
3070
       target_index values right.  */
3071
3072
1
    unsigned int count;
3073
1
    asection **section_list;
3074
1
    unsigned int i;
3075
1
    bfd_size_type amt;
3076
3077
1
#ifdef COFF_PAGE_SIZE
3078
    /* Clear D_PAGED if section / file alignment aren't suitable for
3079
       paging at COFF_PAGE_SIZE granularity.  */
3080
1
   if (pe_data (abfd)->pe_opthdr.SectionAlignment < COFF_PAGE_SIZE
3081
1
       || page_size < COFF_PAGE_SIZE)
3082
1
     abfd->flags &= ~D_PAGED;
3083
1
#endif
3084
3085
1
    count = 0;
3086
3
    for (current = abfd->sections; current != NULL; current = current->next)
3087
2
      ++count;
3088
3089
    /* We allocate an extra cell to simplify the final loop.  */
3090
1
    amt = sizeof (struct asection *) * (count + 1);
3091
1
    section_list = (asection **) bfd_malloc (amt);
3092
1
    if (section_list == NULL)
3093
0
      return false;
3094
3095
1
    i = 0;
3096
3
    for (current = abfd->sections; current != NULL; current = current->next)
3097
2
      {
3098
2
  section_list[i] = current;
3099
2
  ++i;
3100
2
      }
3101
1
    section_list[i] = NULL;
3102
3103
1
    qsort (section_list, count, sizeof (asection *), sort_by_secaddr);
3104
3105
    /* Rethread the linked list into sorted order; at the same time,
3106
       assign target_index values.  */
3107
1
    target_index = 1;
3108
1
    abfd->sections = NULL;
3109
1
    abfd->section_last = NULL;
3110
3
    for (i = 0; i < count; i++)
3111
2
      {
3112
2
  current = section_list[i];
3113
2
  bfd_section_list_append (abfd, current);
3114
3115
  /* Later, if the section has zero size, we'll be throwing it
3116
     away, so we don't want to number it now.  Note that having
3117
     a zero size and having real contents are different
3118
     concepts: .bss has no contents, but (usually) non-zero
3119
     size.  */
3120
2
  if (current->size == 0)
3121
0
    {
3122
      /* Discard.  However, it still might have (valid) symbols
3123
         in it, so arbitrarily set it to section 1 (indexing is
3124
         1-based here; usually .text).  __end__ and other
3125
         contents of .endsection really have this happen.
3126
         FIXME: This seems somewhat dubious.  */
3127
0
      current->target_index = 1;
3128
0
    }
3129
2
  else
3130
2
    current->target_index = target_index++;
3131
2
      }
3132
3133
1
    free (section_list);
3134
1
  }
3135
#else /* ! COFF_IMAGE_WITH_PE */
3136
  {
3137
    /* Set the target_index field.  */
3138
    target_index = 1;
3139
    for (current = abfd->sections; current != NULL; current = current->next)
3140
      current->target_index = target_index++;
3141
  }
3142
#endif /* ! COFF_IMAGE_WITH_PE */
3143
3144
1
  if (target_index >= bfd_coff_max_nscns (abfd))
3145
0
    {
3146
0
      bfd_set_error (bfd_error_file_too_big);
3147
0
      _bfd_error_handler
3148
  /* xgettext:c-format */
3149
0
  (_("%pB: too many sections (%d)"), abfd, target_index);
3150
0
      return false;
3151
0
    }
3152
3153
1
  align_adjust = false;
3154
1
  for (current = abfd->sections;
3155
3
       current != NULL;
3156
2
       current = current->next)
3157
2
    {
3158
2
#ifdef COFF_IMAGE_WITH_PE
3159
      /* With PE we have to pad each section to be a multiple of its
3160
   page size too, and remember both sizes.  */
3161
2
      if (coff_section_data (abfd, current) == NULL)
3162
2
  {
3163
2
    size_t amt = sizeof (struct coff_section_tdata);
3164
3165
2
    current->used_by_bfd = bfd_zalloc (abfd, amt);
3166
2
    if (current->used_by_bfd == NULL)
3167
0
      return false;
3168
2
  }
3169
2
      if (pei_section_data (abfd, current) == NULL)
3170
2
  {
3171
2
    size_t amt = sizeof (struct pei_section_tdata);
3172
3173
2
    coff_section_data (abfd, current)->tdata = bfd_zalloc (abfd, amt);
3174
2
    if (coff_section_data (abfd, current)->tdata == NULL)
3175
0
      return false;
3176
2
  }
3177
2
      if (pei_section_data (abfd, current)->virt_size == 0)
3178
2
  pei_section_data (abfd, current)->virt_size = current->size;
3179
2
#endif
3180
3181
      /* Only deal with sections which have contents.  */
3182
2
      if (!(current->flags & SEC_HAS_CONTENTS))
3183
0
  continue;
3184
3185
2
      current->rawsize = current->size;
3186
3187
2
#ifdef COFF_IMAGE_WITH_PE
3188
      /* Make sure we skip empty sections in a PE image.  */
3189
2
      if (current->size == 0)
3190
0
  continue;
3191
2
#endif
3192
3193
      /* Align the sections in the file to the same boundary on
3194
   which they are aligned in virtual memory.  */
3195
2
#ifdef ALIGN_SECTIONS_IN_FILE
3196
2
      if ((abfd->flags & EXEC_P) != 0)
3197
0
  {
3198
    /* Make sure this section is aligned on the right boundary - by
3199
       padding the previous section up if necessary.  */
3200
0
    old_sofar = sofar;
3201
3202
0
#ifdef COFF_IMAGE_WITH_PE
3203
0
    sofar = BFD_ALIGN (sofar, page_size);
3204
#else
3205
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3206
#endif
3207
3208
#ifdef RS6000COFF_C
3209
    /* Make sure the file offset and the vma of .text/.data are at the
3210
       same page offset, so that the file can be mmap'ed without being
3211
       relocated.  Failing that, AIX is able to load and execute the
3212
       program, but it will be silently relocated (possible as
3213
       executables are PIE).  But the relocation is slightly costly and
3214
       complexify the use of addr2line or gdb.  So better to avoid it,
3215
       like does the native linker.  Usually gnu ld makes sure that
3216
       the vma of .text is the file offset so this issue shouldn't
3217
       appear unless you are stripping such an executable.
3218
3219
       AIX loader checks the text section alignment of (vma - filepos),
3220
       and the native linker doesn't try to align the text sections.
3221
       For example:
3222
3223
       0 .text       000054cc  10000128  10000128  00000128  2**5
3224
           CONTENTS, ALLOC, LOAD, CODE
3225
3226
       Don't perform the above tweak if the previous one is .tdata,
3227
       as it will increase the memory allocated for every threads
3228
       created and not just improve performances with gdb.
3229
    */
3230
3231
    if ((current->flags & SEC_LOAD) != 0
3232
        && (!strcmp (current->name, _TEXT)
3233
      || !strcmp (current->name, _DATA))
3234
        && (previous == NULL || strcmp(previous->name, _TDATA)))
3235
      {
3236
        bfd_vma align = 4096;
3237
        bfd_vma sofar_off = sofar % align;
3238
        bfd_vma vma_off = current->vma % align;
3239
3240
        if (vma_off > sofar_off)
3241
    sofar += vma_off - sofar_off;
3242
        else if (vma_off < sofar_off)
3243
    sofar += align + vma_off - sofar_off;
3244
      }
3245
#endif
3246
0
    if (previous != NULL
3247
0
        && (previous->flags & SEC_LOAD) != 0)
3248
0
      previous->size += sofar - old_sofar;
3249
0
  }
3250
3251
2
#endif
3252
3253
      /* In demand paged files the low order bits of the file offset
3254
   must match the low order bits of the virtual address.  */
3255
2
#ifdef COFF_PAGE_SIZE
3256
2
      if ((abfd->flags & D_PAGED) != 0
3257
2
    && (current->flags & SEC_ALLOC) != 0)
3258
0
  sofar += (current->vma - (bfd_vma) sofar) % page_size;
3259
2
#endif
3260
2
      current->filepos = sofar;
3261
3262
2
#ifdef COFF_IMAGE_WITH_PE
3263
      /* Set the padded size.  */
3264
2
      current->size = (current->size + page_size - 1) & -page_size;
3265
2
#endif
3266
3267
2
      sofar += current->size;
3268
3269
2
#ifdef ALIGN_SECTIONS_IN_FILE
3270
      /* Make sure that this section is of the right size too.  */
3271
2
      if ((abfd->flags & EXEC_P) == 0)
3272
2
  {
3273
2
    bfd_size_type old_size;
3274
3275
2
    old_size = current->size;
3276
2
    current->size = BFD_ALIGN (current->size,
3277
2
             (bfd_vma) 1 << current->alignment_power);
3278
2
    align_adjust = current->size != old_size;
3279
2
    sofar += current->size - old_size;
3280
2
  }
3281
0
      else
3282
0
  {
3283
0
    old_sofar = sofar;
3284
0
#ifdef COFF_IMAGE_WITH_PE
3285
0
    sofar = BFD_ALIGN (sofar, page_size);
3286
#else
3287
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3288
#endif
3289
0
    align_adjust = sofar != old_sofar;
3290
0
    current->size += sofar - old_sofar;
3291
0
  }
3292
2
#endif
3293
3294
2
#ifdef COFF_IMAGE_WITH_PE
3295
      /* For PE we need to make sure we pad out to the aligned
3296
   size, in case the caller only writes out data to the
3297
   unaligned size.  */
3298
2
      if (pei_section_data (abfd, current)->virt_size < current->size)
3299
0
  align_adjust = true;
3300
2
#endif
3301
3302
2
#ifdef _LIB
3303
      /* Force .lib sections to start at zero.  The vma is then
3304
   incremented in coff_set_section_contents.  This is right for
3305
   SVR3.2.  */
3306
2
      if (strcmp (current->name, _LIB) == 0)
3307
0
  bfd_set_section_vma (current, 0);
3308
2
#endif
3309
3310
2
#ifdef ALIGN_SECTIONS_IN_FILE
3311
2
      previous = current;
3312
2
#endif
3313
2
    }
3314
3315
  /* It is now safe to write to the output file.  If we needed an
3316
     alignment adjustment for the last section, then make sure that
3317
     there is a byte at offset sofar.  If there are no symbols and no
3318
     relocs, then nothing follows the last section.  If we don't force
3319
     the last byte out, then the file may appear to be truncated.  */
3320
1
  if (align_adjust)
3321
0
    {
3322
0
      bfd_byte b;
3323
3324
0
      b = 0;
3325
0
      if (bfd_seek (abfd, sofar - 1, SEEK_SET) != 0
3326
0
    || bfd_write (&b, 1, abfd) != 1)
3327
0
  return false;
3328
0
    }
3329
3330
  /* Make sure the relocations are aligned.  We don't need to make
3331
     sure that this byte exists, because it will only matter if there
3332
     really are relocs.  */
3333
1
  sofar = BFD_ALIGN (sofar,
3334
1
         (bfd_vma) 1 << COFF_DEFAULT_SECTION_ALIGNMENT_POWER);
3335
3336
1
  obj_relocbase (abfd) = sofar;
3337
1
  abfd->output_has_begun = true;
3338
3339
1
  return true;
3340
1
}
Unexecuted instantiation: pei-arm.c:coff_compute_section_file_positions
Unexecuted instantiation: pei-mcore.c:coff_compute_section_file_positions
pei-sh.c:coff_compute_section_file_positions
Line
Count
Source
2966
1
{
2967
1
  asection *current;
2968
1
  file_ptr sofar = bfd_coff_filhsz (abfd);
2969
1
  bool align_adjust;
2970
1
  unsigned int target_index;
2971
1
#ifdef ALIGN_SECTIONS_IN_FILE
2972
1
  asection *previous = NULL;
2973
1
  file_ptr old_sofar;
2974
1
#endif
2975
2976
1
#ifdef COFF_IMAGE_WITH_PE
2977
1
  unsigned int page_size;
2978
2979
1
  if (coff_data (abfd)->link_info
2980
1
      || (pe_data (abfd) && pe_data (abfd)->pe_opthdr.FileAlignment))
2981
1
    {
2982
1
      page_size = pe_data (abfd)->pe_opthdr.FileAlignment;
2983
2984
      /* If no file alignment has been set, default to one.
2985
   This repairs 'ld -r' for arm-wince-pe target.  */
2986
1
      if (page_size == 0)
2987
0
  page_size = 1;
2988
1
    }
2989
0
  else
2990
0
    page_size = PE_DEF_FILE_ALIGNMENT;
2991
#else
2992
#ifdef COFF_PAGE_SIZE
2993
  unsigned int page_size = COFF_PAGE_SIZE;
2994
#endif
2995
#endif
2996
2997
#ifdef RS6000COFF_C
2998
  /* On XCOFF, if we have symbols, set up the .debug section.  */
2999
  if (bfd_get_symcount (abfd) > 0)
3000
    {
3001
      bfd_size_type sz;
3002
      bfd_size_type i, symcount;
3003
      asymbol **symp;
3004
3005
      sz = 0;
3006
      symcount = bfd_get_symcount (abfd);
3007
      for (symp = abfd->outsymbols, i = 0; i < symcount; symp++, i++)
3008
  {
3009
    coff_symbol_type *cf;
3010
3011
    cf = coff_symbol_from (*symp);
3012
    if (cf != NULL
3013
        && cf->native != NULL
3014
        && cf->native->is_sym
3015
        && SYMNAME_IN_DEBUG (&cf->native->u.syment))
3016
      {
3017
        size_t len;
3018
3019
        len = strlen (bfd_asymbol_name (*symp));
3020
        if (len > SYMNMLEN || bfd_coff_force_symnames_in_strings (abfd))
3021
    sz += len + 1 + bfd_coff_debug_string_prefix_length (abfd);
3022
      }
3023
  }
3024
      if (sz > 0)
3025
  {
3026
    asection *dsec;
3027
3028
    dsec = bfd_make_section_old_way (abfd, DOT_DEBUG);
3029
    if (dsec == NULL)
3030
      abort ();
3031
    dsec->size = sz;
3032
    dsec->flags |= SEC_HAS_CONTENTS;
3033
  }
3034
    }
3035
#endif
3036
3037
1
  if (bfd_get_start_address (abfd))
3038
    /*  A start address may have been added to the original file. In this
3039
  case it will need an optional header to record it.  */
3040
0
    abfd->flags |= EXEC_P;
3041
3042
1
  if (abfd->flags & EXEC_P)
3043
0
    sofar += bfd_coff_aoutsz (abfd);
3044
#ifdef RS6000COFF_C
3045
  else if (xcoff_data (abfd)->full_aouthdr)
3046
    sofar += bfd_coff_aoutsz (abfd);
3047
  else
3048
    sofar += SMALL_AOUTSZ;
3049
#endif
3050
3051
1
  sofar += abfd->section_count * bfd_coff_scnhsz (abfd);
3052
3053
#ifdef RS6000COFF_C
3054
  /* XCOFF handles overflows in the reloc and line number count fields
3055
     by allocating a new section header to hold the correct counts.  */
3056
  for (current = abfd->sections; current != NULL; current = current->next)
3057
    if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3058
      sofar += bfd_coff_scnhsz (abfd);
3059
#endif
3060
3061
1
  if (coff_data (abfd)->section_by_target_index)
3062
0
    htab_empty (coff_data (abfd)->section_by_target_index);
3063
3064
1
#ifdef COFF_IMAGE_WITH_PE
3065
1
  {
3066
    /* PE requires the sections to be in memory order when listed in
3067
       the section headers.  It also does not like empty loadable
3068
       sections.  The sections apparently do not have to be in the
3069
       right order in the image file itself, but we do need to get the
3070
       target_index values right.  */
3071
3072
1
    unsigned int count;
3073
1
    asection **section_list;
3074
1
    unsigned int i;
3075
1
    bfd_size_type amt;
3076
3077
1
#ifdef COFF_PAGE_SIZE
3078
    /* Clear D_PAGED if section / file alignment aren't suitable for
3079
       paging at COFF_PAGE_SIZE granularity.  */
3080
1
   if (pe_data (abfd)->pe_opthdr.SectionAlignment < COFF_PAGE_SIZE
3081
1
       || page_size < COFF_PAGE_SIZE)
3082
1
     abfd->flags &= ~D_PAGED;
3083
1
#endif
3084
3085
1
    count = 0;
3086
1
    for (current = abfd->sections; current != NULL; current = current->next)
3087
0
      ++count;
3088
3089
    /* We allocate an extra cell to simplify the final loop.  */
3090
1
    amt = sizeof (struct asection *) * (count + 1);
3091
1
    section_list = (asection **) bfd_malloc (amt);
3092
1
    if (section_list == NULL)
3093
0
      return false;
3094
3095
1
    i = 0;
3096
1
    for (current = abfd->sections; current != NULL; current = current->next)
3097
0
      {
3098
0
  section_list[i] = current;
3099
0
  ++i;
3100
0
      }
3101
1
    section_list[i] = NULL;
3102
3103
1
    qsort (section_list, count, sizeof (asection *), sort_by_secaddr);
3104
3105
    /* Rethread the linked list into sorted order; at the same time,
3106
       assign target_index values.  */
3107
1
    target_index = 1;
3108
1
    abfd->sections = NULL;
3109
1
    abfd->section_last = NULL;
3110
1
    for (i = 0; i < count; i++)
3111
0
      {
3112
0
  current = section_list[i];
3113
0
  bfd_section_list_append (abfd, current);
3114
3115
  /* Later, if the section has zero size, we'll be throwing it
3116
     away, so we don't want to number it now.  Note that having
3117
     a zero size and having real contents are different
3118
     concepts: .bss has no contents, but (usually) non-zero
3119
     size.  */
3120
0
  if (current->size == 0)
3121
0
    {
3122
      /* Discard.  However, it still might have (valid) symbols
3123
         in it, so arbitrarily set it to section 1 (indexing is
3124
         1-based here; usually .text).  __end__ and other
3125
         contents of .endsection really have this happen.
3126
         FIXME: This seems somewhat dubious.  */
3127
0
      current->target_index = 1;
3128
0
    }
3129
0
  else
3130
0
    current->target_index = target_index++;
3131
0
      }
3132
3133
1
    free (section_list);
3134
1
  }
3135
#else /* ! COFF_IMAGE_WITH_PE */
3136
  {
3137
    /* Set the target_index field.  */
3138
    target_index = 1;
3139
    for (current = abfd->sections; current != NULL; current = current->next)
3140
      current->target_index = target_index++;
3141
  }
3142
#endif /* ! COFF_IMAGE_WITH_PE */
3143
3144
1
  if (target_index >= bfd_coff_max_nscns (abfd))
3145
0
    {
3146
0
      bfd_set_error (bfd_error_file_too_big);
3147
0
      _bfd_error_handler
3148
  /* xgettext:c-format */
3149
0
  (_("%pB: too many sections (%d)"), abfd, target_index);
3150
0
      return false;
3151
0
    }
3152
3153
1
  align_adjust = false;
3154
1
  for (current = abfd->sections;
3155
1
       current != NULL;
3156
1
       current = current->next)
3157
0
    {
3158
0
#ifdef COFF_IMAGE_WITH_PE
3159
      /* With PE we have to pad each section to be a multiple of its
3160
   page size too, and remember both sizes.  */
3161
0
      if (coff_section_data (abfd, current) == NULL)
3162
0
  {
3163
0
    size_t amt = sizeof (struct coff_section_tdata);
3164
3165
0
    current->used_by_bfd = bfd_zalloc (abfd, amt);
3166
0
    if (current->used_by_bfd == NULL)
3167
0
      return false;
3168
0
  }
3169
0
      if (pei_section_data (abfd, current) == NULL)
3170
0
  {
3171
0
    size_t amt = sizeof (struct pei_section_tdata);
3172
3173
0
    coff_section_data (abfd, current)->tdata = bfd_zalloc (abfd, amt);
3174
0
    if (coff_section_data (abfd, current)->tdata == NULL)
3175
0
      return false;
3176
0
  }
3177
0
      if (pei_section_data (abfd, current)->virt_size == 0)
3178
0
  pei_section_data (abfd, current)->virt_size = current->size;
3179
0
#endif
3180
3181
      /* Only deal with sections which have contents.  */
3182
0
      if (!(current->flags & SEC_HAS_CONTENTS))
3183
0
  continue;
3184
3185
0
      current->rawsize = current->size;
3186
3187
0
#ifdef COFF_IMAGE_WITH_PE
3188
      /* Make sure we skip empty sections in a PE image.  */
3189
0
      if (current->size == 0)
3190
0
  continue;
3191
0
#endif
3192
3193
      /* Align the sections in the file to the same boundary on
3194
   which they are aligned in virtual memory.  */
3195
0
#ifdef ALIGN_SECTIONS_IN_FILE
3196
0
      if ((abfd->flags & EXEC_P) != 0)
3197
0
  {
3198
    /* Make sure this section is aligned on the right boundary - by
3199
       padding the previous section up if necessary.  */
3200
0
    old_sofar = sofar;
3201
3202
0
#ifdef COFF_IMAGE_WITH_PE
3203
0
    sofar = BFD_ALIGN (sofar, page_size);
3204
#else
3205
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3206
#endif
3207
3208
#ifdef RS6000COFF_C
3209
    /* Make sure the file offset and the vma of .text/.data are at the
3210
       same page offset, so that the file can be mmap'ed without being
3211
       relocated.  Failing that, AIX is able to load and execute the
3212
       program, but it will be silently relocated (possible as
3213
       executables are PIE).  But the relocation is slightly costly and
3214
       complexify the use of addr2line or gdb.  So better to avoid it,
3215
       like does the native linker.  Usually gnu ld makes sure that
3216
       the vma of .text is the file offset so this issue shouldn't
3217
       appear unless you are stripping such an executable.
3218
3219
       AIX loader checks the text section alignment of (vma - filepos),
3220
       and the native linker doesn't try to align the text sections.
3221
       For example:
3222
3223
       0 .text       000054cc  10000128  10000128  00000128  2**5
3224
           CONTENTS, ALLOC, LOAD, CODE
3225
3226
       Don't perform the above tweak if the previous one is .tdata,
3227
       as it will increase the memory allocated for every threads
3228
       created and not just improve performances with gdb.
3229
    */
3230
3231
    if ((current->flags & SEC_LOAD) != 0
3232
        && (!strcmp (current->name, _TEXT)
3233
      || !strcmp (current->name, _DATA))
3234
        && (previous == NULL || strcmp(previous->name, _TDATA)))
3235
      {
3236
        bfd_vma align = 4096;
3237
        bfd_vma sofar_off = sofar % align;
3238
        bfd_vma vma_off = current->vma % align;
3239
3240
        if (vma_off > sofar_off)
3241
    sofar += vma_off - sofar_off;
3242
        else if (vma_off < sofar_off)
3243
    sofar += align + vma_off - sofar_off;
3244
      }
3245
#endif
3246
0
    if (previous != NULL
3247
0
        && (previous->flags & SEC_LOAD) != 0)
3248
0
      previous->size += sofar - old_sofar;
3249
0
  }
3250
3251
0
#endif
3252
3253
      /* In demand paged files the low order bits of the file offset
3254
   must match the low order bits of the virtual address.  */
3255
0
#ifdef COFF_PAGE_SIZE
3256
0
      if ((abfd->flags & D_PAGED) != 0
3257
0
    && (current->flags & SEC_ALLOC) != 0)
3258
0
  sofar += (current->vma - (bfd_vma) sofar) % page_size;
3259
0
#endif
3260
0
      current->filepos = sofar;
3261
3262
0
#ifdef COFF_IMAGE_WITH_PE
3263
      /* Set the padded size.  */
3264
0
      current->size = (current->size + page_size - 1) & -page_size;
3265
0
#endif
3266
3267
0
      sofar += current->size;
3268
3269
0
#ifdef ALIGN_SECTIONS_IN_FILE
3270
      /* Make sure that this section is of the right size too.  */
3271
0
      if ((abfd->flags & EXEC_P) == 0)
3272
0
  {
3273
0
    bfd_size_type old_size;
3274
3275
0
    old_size = current->size;
3276
0
    current->size = BFD_ALIGN (current->size,
3277
0
             (bfd_vma) 1 << current->alignment_power);
3278
0
    align_adjust = current->size != old_size;
3279
0
    sofar += current->size - old_size;
3280
0
  }
3281
0
      else
3282
0
  {
3283
0
    old_sofar = sofar;
3284
0
#ifdef COFF_IMAGE_WITH_PE
3285
0
    sofar = BFD_ALIGN (sofar, page_size);
3286
#else
3287
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3288
#endif
3289
0
    align_adjust = sofar != old_sofar;
3290
0
    current->size += sofar - old_sofar;
3291
0
  }
3292
0
#endif
3293
3294
0
#ifdef COFF_IMAGE_WITH_PE
3295
      /* For PE we need to make sure we pad out to the aligned
3296
   size, in case the caller only writes out data to the
3297
   unaligned size.  */
3298
0
      if (pei_section_data (abfd, current)->virt_size < current->size)
3299
0
  align_adjust = true;
3300
0
#endif
3301
3302
0
#ifdef _LIB
3303
      /* Force .lib sections to start at zero.  The vma is then
3304
   incremented in coff_set_section_contents.  This is right for
3305
   SVR3.2.  */
3306
0
      if (strcmp (current->name, _LIB) == 0)
3307
0
  bfd_set_section_vma (current, 0);
3308
0
#endif
3309
3310
0
#ifdef ALIGN_SECTIONS_IN_FILE
3311
0
      previous = current;
3312
0
#endif
3313
0
    }
3314
3315
  /* It is now safe to write to the output file.  If we needed an
3316
     alignment adjustment for the last section, then make sure that
3317
     there is a byte at offset sofar.  If there are no symbols and no
3318
     relocs, then nothing follows the last section.  If we don't force
3319
     the last byte out, then the file may appear to be truncated.  */
3320
1
  if (align_adjust)
3321
0
    {
3322
0
      bfd_byte b;
3323
3324
0
      b = 0;
3325
0
      if (bfd_seek (abfd, sofar - 1, SEEK_SET) != 0
3326
0
    || bfd_write (&b, 1, abfd) != 1)
3327
0
  return false;
3328
0
    }
3329
3330
  /* Make sure the relocations are aligned.  We don't need to make
3331
     sure that this byte exists, because it will only matter if there
3332
     really are relocs.  */
3333
1
  sofar = BFD_ALIGN (sofar,
3334
1
         (bfd_vma) 1 << COFF_DEFAULT_SECTION_ALIGNMENT_POWER);
3335
3336
1
  obj_relocbase (abfd) = sofar;
3337
1
  abfd->output_has_begun = true;
3338
3339
1
  return true;
3340
1
}
3341
3342
#ifdef COFF_IMAGE_WITH_PE
3343
3344
static bool
3345
coff_read_word (bfd *abfd, unsigned int *value, unsigned int *pelength)
3346
11
{
3347
11
  unsigned char b[2];
3348
11
  int status;
3349
3350
11
  status = bfd_read (b, 2, abfd);
3351
11
  if (status < 1)
3352
0
    {
3353
0
      *value = 0;
3354
0
      return false;
3355
0
    }
3356
3357
11
  if (status == 1)
3358
0
    *value = (unsigned int) b[0];
3359
11
  else
3360
11
    *value = (unsigned int) (b[0] + (b[1] << 8));
3361
3362
11
  *pelength += status;
3363
3364
11
  return true;
3365
11
}
pei-i386.c:coff_read_word
Line
Count
Source
3346
3
{
3347
3
  unsigned char b[2];
3348
3
  int status;
3349
3350
3
  status = bfd_read (b, 2, abfd);
3351
3
  if (status < 1)
3352
0
    {
3353
0
      *value = 0;
3354
0
      return false;
3355
0
    }
3356
3357
3
  if (status == 1)
3358
0
    *value = (unsigned int) b[0];
3359
3
  else
3360
3
    *value = (unsigned int) (b[0] + (b[1] << 8));
3361
3362
3
  *pelength += status;
3363
3364
3
  return true;
3365
3
}
pei-x86_64.c:coff_read_word
Line
Count
Source
3346
8
{
3347
8
  unsigned char b[2];
3348
8
  int status;
3349
3350
8
  status = bfd_read (b, 2, abfd);
3351
8
  if (status < 1)
3352
0
    {
3353
0
      *value = 0;
3354
0
      return false;
3355
0
    }
3356
3357
8
  if (status == 1)
3358
0
    *value = (unsigned int) b[0];
3359
8
  else
3360
8
    *value = (unsigned int) (b[0] + (b[1] << 8));
3361
3362
8
  *pelength += status;
3363
3364
8
  return true;
3365
8
}
Unexecuted instantiation: pei-aarch64.c:coff_read_word
Unexecuted instantiation: pei-ia64.c:coff_read_word
Unexecuted instantiation: pei-loongarch64.c:coff_read_word
Unexecuted instantiation: pei-arm-wince.c:coff_read_word
Unexecuted instantiation: pei-arm.c:coff_read_word
Unexecuted instantiation: pei-mcore.c:coff_read_word
Unexecuted instantiation: pei-sh.c:coff_read_word
3366
3367
/* Read a two byte number from buffer B returning the result in VALUE.
3368
   No more than BUF_SIZE bytes will be read.
3369
   Returns true upobn success, false otherwise.
3370
   If successful, increases the value stored in PELENGTH by the number
3371
   of bytes read.  */
3372
3373
static bool
3374
coff_read_word_from_buffer (unsigned char *  b,
3375
          int              buf_size,
3376
                            unsigned int *   value,
3377
          unsigned int *   pelength)
3378
322k
{
3379
322k
  if (buf_size < 1)
3380
0
    {
3381
0
      *value = 0;
3382
0
      return false;
3383
0
    }
3384
3385
322k
  if (buf_size == 1)
3386
4
    {
3387
4
      *value = (unsigned int)b[0];
3388
4
      *pelength += 1;
3389
4
    }
3390
322k
  else
3391
322k
    {
3392
322k
      *value = (unsigned int)(b[0] + (b[1] << 8));
3393
322k
      *pelength += 2;
3394
322k
    }
3395
3396
322k
  return true;
3397
322k
}
pei-i386.c:coff_read_word_from_buffer
Line
Count
Source
3378
218k
{
3379
218k
  if (buf_size < 1)
3380
0
    {
3381
0
      *value = 0;
3382
0
      return false;
3383
0
    }
3384
3385
218k
  if (buf_size == 1)
3386
1
    {
3387
1
      *value = (unsigned int)b[0];
3388
1
      *pelength += 1;
3389
1
    }
3390
218k
  else
3391
218k
    {
3392
218k
      *value = (unsigned int)(b[0] + (b[1] << 8));
3393
218k
      *pelength += 2;
3394
218k
    }
3395
3396
218k
  return true;
3397
218k
}
pei-x86_64.c:coff_read_word_from_buffer
Line
Count
Source
3378
103k
{
3379
103k
  if (buf_size < 1)
3380
0
    {
3381
0
      *value = 0;
3382
0
      return false;
3383
0
    }
3384
3385
103k
  if (buf_size == 1)
3386
3
    {
3387
3
      *value = (unsigned int)b[0];
3388
3
      *pelength += 1;
3389
3
    }
3390
103k
  else
3391
103k
    {
3392
103k
      *value = (unsigned int)(b[0] + (b[1] << 8));
3393
103k
      *pelength += 2;
3394
103k
    }
3395
3396
103k
  return true;
3397
103k
}
Unexecuted instantiation: pei-aarch64.c:coff_read_word_from_buffer
Unexecuted instantiation: pei-ia64.c:coff_read_word_from_buffer
Unexecuted instantiation: pei-loongarch64.c:coff_read_word_from_buffer
Unexecuted instantiation: pei-arm-wince.c:coff_read_word_from_buffer
Unexecuted instantiation: pei-arm.c:coff_read_word_from_buffer
Unexecuted instantiation: pei-mcore.c:coff_read_word_from_buffer
Unexecuted instantiation: pei-sh.c:coff_read_word_from_buffer
3398
3399
33
#define COFF_CHECKSUM_BUFFER_SIZE 0x800000
3400
3401
static unsigned int
3402
coff_compute_checksum (bfd *abfd, unsigned int *pelength)
3403
11
{
3404
11
  file_ptr filepos;
3405
11
  unsigned int value;
3406
11
  unsigned int total;
3407
11
  unsigned char *buf;
3408
11
  int buf_size;
3409
3410
11
  total = 0;
3411
11
  *pelength = 0;
3412
11
  filepos = (file_ptr) 0;
3413
11
  buf = (unsigned char *) bfd_malloc (COFF_CHECKSUM_BUFFER_SIZE);
3414
11
  if (buf == NULL)
3415
0
    return 0;
3416
11
  buf_size = 0;
3417
3418
11
  do
3419
22
    {
3420
22
      unsigned char *cur_buf;
3421
22
      int cur_buf_size;
3422
3423
22
      if (bfd_seek (abfd, filepos, SEEK_SET) != 0)
3424
0
  return 0;
3425
3426
22
      buf_size = bfd_read (buf, COFF_CHECKSUM_BUFFER_SIZE, abfd);
3427
22
      cur_buf_size = buf_size;
3428
22
      cur_buf = buf;
3429
3430
322k
      while (cur_buf_size > 0)
3431
322k
        {
3432
322k
          coff_read_word_from_buffer (cur_buf, cur_buf_size, &value, pelength);
3433
322k
          cur_buf += 2;
3434
322k
          cur_buf_size -= 2;
3435
322k
          total += value;
3436
322k
          total = 0xffff & (total + (total >> 0x10));
3437
322k
        }
3438
3439
22
      filepos += buf_size;
3440
22
    }
3441
22
  while (buf_size > 0);
3442
3443
11
  free (buf);
3444
3445
11
  return (0xffff & (total + (total >> 0x10)));
3446
11
}
pei-i386.c:coff_compute_checksum
Line
Count
Source
3403
3
{
3404
3
  file_ptr filepos;
3405
3
  unsigned int value;
3406
3
  unsigned int total;
3407
3
  unsigned char *buf;
3408
3
  int buf_size;
3409
3410
3
  total = 0;
3411
3
  *pelength = 0;
3412
3
  filepos = (file_ptr) 0;
3413
3
  buf = (unsigned char *) bfd_malloc (COFF_CHECKSUM_BUFFER_SIZE);
3414
3
  if (buf == NULL)
3415
0
    return 0;
3416
3
  buf_size = 0;
3417
3418
3
  do
3419
6
    {
3420
6
      unsigned char *cur_buf;
3421
6
      int cur_buf_size;
3422
3423
6
      if (bfd_seek (abfd, filepos, SEEK_SET) != 0)
3424
0
  return 0;
3425
3426
6
      buf_size = bfd_read (buf, COFF_CHECKSUM_BUFFER_SIZE, abfd);
3427
6
      cur_buf_size = buf_size;
3428
6
      cur_buf = buf;
3429
3430
218k
      while (cur_buf_size > 0)
3431
218k
        {
3432
218k
          coff_read_word_from_buffer (cur_buf, cur_buf_size, &value, pelength);
3433
218k
          cur_buf += 2;
3434
218k
          cur_buf_size -= 2;
3435
218k
          total += value;
3436
218k
          total = 0xffff & (total + (total >> 0x10));
3437
218k
        }
3438
3439
6
      filepos += buf_size;
3440
6
    }
3441
6
  while (buf_size > 0);
3442
3443
3
  free (buf);
3444
3445
3
  return (0xffff & (total + (total >> 0x10)));
3446
3
}
pei-x86_64.c:coff_compute_checksum
Line
Count
Source
3403
8
{
3404
8
  file_ptr filepos;
3405
8
  unsigned int value;
3406
8
  unsigned int total;
3407
8
  unsigned char *buf;
3408
8
  int buf_size;
3409
3410
8
  total = 0;
3411
8
  *pelength = 0;
3412
8
  filepos = (file_ptr) 0;
3413
8
  buf = (unsigned char *) bfd_malloc (COFF_CHECKSUM_BUFFER_SIZE);
3414
8
  if (buf == NULL)
3415
0
    return 0;
3416
8
  buf_size = 0;
3417
3418
8
  do
3419
16
    {
3420
16
      unsigned char *cur_buf;
3421
16
      int cur_buf_size;
3422
3423
16
      if (bfd_seek (abfd, filepos, SEEK_SET) != 0)
3424
0
  return 0;
3425
3426
16
      buf_size = bfd_read (buf, COFF_CHECKSUM_BUFFER_SIZE, abfd);
3427
16
      cur_buf_size = buf_size;
3428
16
      cur_buf = buf;
3429
3430
103k
      while (cur_buf_size > 0)
3431
103k
        {
3432
103k
          coff_read_word_from_buffer (cur_buf, cur_buf_size, &value, pelength);
3433
103k
          cur_buf += 2;
3434
103k
          cur_buf_size -= 2;
3435
103k
          total += value;
3436
103k
          total = 0xffff & (total + (total >> 0x10));
3437
103k
        }
3438
3439
16
      filepos += buf_size;
3440
16
    }
3441
16
  while (buf_size > 0);
3442
3443
8
  free (buf);
3444
3445
8
  return (0xffff & (total + (total >> 0x10)));
3446
8
}
Unexecuted instantiation: pei-aarch64.c:coff_compute_checksum
Unexecuted instantiation: pei-ia64.c:coff_compute_checksum
Unexecuted instantiation: pei-loongarch64.c:coff_compute_checksum
Unexecuted instantiation: pei-arm-wince.c:coff_compute_checksum
Unexecuted instantiation: pei-arm.c:coff_compute_checksum
Unexecuted instantiation: pei-mcore.c:coff_compute_checksum
Unexecuted instantiation: pei-sh.c:coff_compute_checksum
3447
3448
static bool
3449
coff_apply_checksum (bfd *abfd)
3450
11
{
3451
11
  unsigned int computed;
3452
11
  unsigned int checksum = 0;
3453
11
  unsigned int peheader;
3454
11
  unsigned int pelength;
3455
3456
11
  if (bfd_seek (abfd, 0x3c, SEEK_SET) != 0)
3457
0
    return false;
3458
3459
11
  if (!coff_read_word (abfd, &peheader, &pelength))
3460
0
    return false;
3461
3462
11
  if (bfd_seek (abfd, peheader + 0x58, SEEK_SET) != 0)
3463
0
    return false;
3464
3465
11
  checksum = 0;
3466
11
  if (bfd_write (&checksum, 4, abfd) != 4)
3467
0
    return false;
3468
3469
11
  if (bfd_seek (abfd, peheader, SEEK_SET) != 0)
3470
0
    return false;
3471
3472
11
  computed = coff_compute_checksum (abfd, &pelength);
3473
3474
11
  checksum = computed + pelength;
3475
3476
11
  if (bfd_seek (abfd, peheader + 0x58, SEEK_SET) != 0)
3477
0
    return false;
3478
3479
11
  return bfd_write (&checksum, 4, abfd) == 4;
3480
11
}
pei-i386.c:coff_apply_checksum
Line
Count
Source
3450
3
{
3451
3
  unsigned int computed;
3452
3
  unsigned int checksum = 0;
3453
3
  unsigned int peheader;
3454
3
  unsigned int pelength;
3455
3456
3
  if (bfd_seek (abfd, 0x3c, SEEK_SET) != 0)
3457
0
    return false;
3458
3459
3
  if (!coff_read_word (abfd, &peheader, &pelength))
3460
0
    return false;
3461
3462
3
  if (bfd_seek (abfd, peheader + 0x58, SEEK_SET) != 0)
3463
0
    return false;
3464
3465
3
  checksum = 0;
3466
3
  if (bfd_write (&checksum, 4, abfd) != 4)
3467
0
    return false;
3468
3469
3
  if (bfd_seek (abfd, peheader, SEEK_SET) != 0)
3470
0
    return false;
3471
3472
3
  computed = coff_compute_checksum (abfd, &pelength);
3473
3474
3
  checksum = computed + pelength;
3475
3476
3
  if (bfd_seek (abfd, peheader + 0x58, SEEK_SET) != 0)
3477
0
    return false;
3478
3479
3
  return bfd_write (&checksum, 4, abfd) == 4;
3480
3
}
pei-x86_64.c:coff_apply_checksum
Line
Count
Source
3450
8
{
3451
8
  unsigned int computed;
3452
8
  unsigned int checksum = 0;
3453
8
  unsigned int peheader;
3454
8
  unsigned int pelength;
3455
3456
8
  if (bfd_seek (abfd, 0x3c, SEEK_SET) != 0)
3457
0
    return false;
3458
3459
8
  if (!coff_read_word (abfd, &peheader, &pelength))
3460
0
    return false;
3461
3462
8
  if (bfd_seek (abfd, peheader + 0x58, SEEK_SET) != 0)
3463
0
    return false;
3464
3465
8
  checksum = 0;
3466
8
  if (bfd_write (&checksum, 4, abfd) != 4)
3467
0
    return false;
3468
3469
8
  if (bfd_seek (abfd, peheader, SEEK_SET) != 0)
3470
0
    return false;
3471
3472
8
  computed = coff_compute_checksum (abfd, &pelength);
3473
3474
8
  checksum = computed + pelength;
3475
3476
8
  if (bfd_seek (abfd, peheader + 0x58, SEEK_SET) != 0)
3477
0
    return false;
3478
3479
8
  return bfd_write (&checksum, 4, abfd) == 4;
3480
8
}
Unexecuted instantiation: pei-aarch64.c:coff_apply_checksum
Unexecuted instantiation: pei-ia64.c:coff_apply_checksum
Unexecuted instantiation: pei-loongarch64.c:coff_apply_checksum
Unexecuted instantiation: pei-arm-wince.c:coff_apply_checksum
Unexecuted instantiation: pei-arm.c:coff_apply_checksum
Unexecuted instantiation: pei-mcore.c:coff_apply_checksum
Unexecuted instantiation: pei-sh.c:coff_apply_checksum
3481
3482
#endif /* COFF_IMAGE_WITH_PE */
3483
3484
static bool
3485
coff_write_object_contents (bfd * abfd)
3486
29
{
3487
29
  asection *current;
3488
29
  bool hasrelocs = false;
3489
29
  bool haslinno = false;
3490
#ifdef COFF_IMAGE_WITH_PE
3491
  bool hasdebug = false;
3492
#endif
3493
29
  file_ptr scn_base;
3494
29
  file_ptr reloc_base;
3495
29
  file_ptr lineno_base;
3496
29
  file_ptr sym_base;
3497
29
  unsigned long reloc_size = 0, reloc_count = 0;
3498
29
  unsigned long lnno_size = 0;
3499
29
  bool long_section_names;
3500
29
  asection *text_sec = NULL;
3501
29
  asection *data_sec = NULL;
3502
29
  asection *bss_sec = NULL;
3503
#ifdef RS6000COFF_C
3504
  asection *tdata_sec = NULL;
3505
  asection *tbss_sec = NULL;
3506
#endif
3507
29
  struct internal_filehdr internal_f;
3508
29
  struct internal_aouthdr internal_a;
3509
#ifdef COFF_LONG_SECTION_NAMES
3510
22
  size_t string_size = STRING_SIZE_SIZE;
3511
#endif
3512
3513
29
  bfd_set_error (bfd_error_system_call);
3514
3515
  /* Make a pass through the symbol table to count line number entries and
3516
     put them into the correct asections.  */
3517
29
  lnno_size = coff_count_linenumbers (abfd) * bfd_coff_linesz (abfd);
3518
3519
29
  if (! abfd->output_has_begun)
3520
16
    {
3521
16
      if (! coff_compute_section_file_positions (abfd))
3522
0
  return false;
3523
16
    }
3524
3525
29
  reloc_base = obj_relocbase (abfd);
3526
3527
  /* Work out the size of the reloc and linno areas.  */
3528
3529
884
  for (current = abfd->sections; current != NULL; current =
3530
855
       current->next)
3531
855
    {
3532
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3533
      /* We store the actual reloc count in the first reloc's addr.  */
3534
601
      if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3535
0
  reloc_count ++;
3536
#endif
3537
855
      reloc_count += current->reloc_count;
3538
855
    }
3539
3540
29
  reloc_size = reloc_count * bfd_coff_relsz (abfd);
3541
3542
29
  lineno_base = reloc_base + reloc_size;
3543
29
  sym_base = lineno_base + lnno_size;
3544
3545
  /* Indicate in each section->line_filepos its actual file address.  */
3546
884
  for (current = abfd->sections; current != NULL; current =
3547
855
       current->next)
3548
855
    {
3549
855
      if (current->lineno_count)
3550
0
  {
3551
0
    current->line_filepos = lineno_base;
3552
0
    current->moving_line_filepos = lineno_base;
3553
0
    lineno_base += current->lineno_count * bfd_coff_linesz (abfd);
3554
0
  }
3555
855
      else
3556
855
  current->line_filepos = 0;
3557
3558
855
      if (current->reloc_count)
3559
0
  {
3560
0
    current->rel_filepos = reloc_base;
3561
0
    reloc_base += current->reloc_count * bfd_coff_relsz (abfd);
3562
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3563
    /* Extra reloc to hold real count.  */
3564
0
    if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3565
0
      reloc_base += bfd_coff_relsz (abfd);
3566
#endif
3567
0
  }
3568
855
      else
3569
855
  current->rel_filepos = 0;
3570
855
    }
3571
3572
  /* Write section headers to the file.  */
3573
29
  internal_f.f_nscns = 0;
3574
3575
29
  if ((abfd->flags & EXEC_P) != 0)
3576
17
    scn_base = bfd_coff_filhsz (abfd) + bfd_coff_aoutsz (abfd);
3577
12
  else
3578
12
    {
3579
12
      scn_base = bfd_coff_filhsz (abfd);
3580
#ifdef RS6000COFF_C
3581
#ifndef XCOFF64
3582
0
      if (xcoff_data (abfd)->full_aouthdr)
3583
0
  scn_base += bfd_coff_aoutsz (abfd);
3584
0
      else
3585
0
  scn_base += SMALL_AOUTSZ;
3586
#endif
3587
#endif
3588
12
    }
3589
3590
29
  if (bfd_seek (abfd, scn_base, SEEK_SET) != 0)
3591
0
    return false;
3592
3593
29
  long_section_names = false;
3594
29
  for (current = abfd->sections;
3595
884
       current != NULL;
3596
855
       current = current->next)
3597
855
    {
3598
855
      struct internal_scnhdr section;
3599
#ifdef COFF_IMAGE_WITH_PE
3600
      bool is_reloc_section = false;
3601
3602
94
      if (strcmp (current->name, DOT_RELOC) == 0)
3603
4
  {
3604
4
    is_reloc_section = true;
3605
4
    hasrelocs = true;
3606
4
    pe_data (abfd)->has_reloc_section = 1;
3607
4
  }
3608
#endif
3609
3610
855
      internal_f.f_nscns++;
3611
3612
855
      strncpy (section.s_name, current->name, SCNNMLEN);
3613
3614
#ifdef COFF_LONG_SECTION_NAMES
3615
      /* Handle long section names as in PE.  This must be compatible
3616
   with the code in coff_write_symbols and _bfd_coff_final_link.  */
3617
601
      if (bfd_coff_long_section_names (abfd))
3618
591
  {
3619
591
    size_t len;
3620
3621
    len = strlen (current->name);
3622
591
    if (len > SCNNMLEN)
3623
31
      {
3624
3625
        /* An inherent limitation of the /nnnnnnn notation used to indicate
3626
     the offset of the long name in the string table is that we
3627
     cannot address entries beyone the ten million byte boundary.  */
3628
31
        if (string_size < 10000000)
3629
31
    {
3630
      /* The s_name field is defined to be NUL-padded but need not
3631
         be NUL-terminated.  We use a temporary buffer so that we
3632
         can still sprintf all eight chars without splatting a
3633
         terminating NUL over the first byte of the following
3634
         member (s_paddr).  */
3635
      /* PR 21096: The +20 is to stop a bogus warning from gcc7
3636
         about a possible buffer overflow.  */
3637
      char s_name_buf[SCNNMLEN + 1 + 20];
3638
3639
      /* We do not need to use snprintf here as we have already
3640
         verified that string_size is not too big, plus we have
3641
         an overlarge buffer, just in case.  */
3642
31
      sprintf (s_name_buf, "/%lu", (unsigned long) string_size);
3643
      /* Then strncpy takes care of any padding for us.  */
3644
31
      strncpy (section.s_name, s_name_buf, SCNNMLEN);
3645
31
    }
3646
0
        else
3647
#ifdef COFF_WITH_PE
3648
0
    {
3649
      /* PE use a base 64 encoding for long section names whose
3650
         index is very large.  But contrary to RFC 4648, there is
3651
         no padding: 6 characters must be generated.  */
3652
0
      static const char base64[] =
3653
0
        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
3654
0
        "abcdefghijklmnopqrstuvwxyz"
3655
0
        "0123456789+/";
3656
0
      unsigned long off = string_size;
3657
0
      unsigned i;
3658
3659
0
      section.s_name[0] = '/';
3660
0
      section.s_name[1] = '/';
3661
0
      for (i = SCNNMLEN - 1; i >= 2; i--)
3662
0
        {
3663
0
          section.s_name[i] = base64[off & 0x3f];
3664
0
          off >>= 6;
3665
0
        }
3666
0
    }
3667
#endif
3668
31
        if (string_size > 0xffffffffUL - (len + 1)
3669
#ifndef COFF_WITH_PE
3670
0
      || string_size >= 10000000
3671
#endif
3672
0
      )
3673
0
    {
3674
0
      bfd_set_error (bfd_error_file_too_big);
3675
0
      _bfd_error_handler
3676
        /* xgettext:c-format */
3677
0
        (_("%pB: section %pA: string table overflow at offset %ld"),
3678
0
        abfd, current, (unsigned long) string_size);
3679
0
      return false;
3680
0
    }
3681
3682
31
        string_size += len + 1;
3683
31
        long_section_names = true;
3684
31
      }
3685
591
  }
3686
601
#endif
3687
3688
#ifdef _LIB
3689
      /* Always set s_vaddr of .lib to 0.  This is right for SVR3.2
3690
   Ian Taylor <ian@cygnus.com>.  */
3691
855
      if (strcmp (current->name, _LIB) == 0)
3692
0
  section.s_vaddr = 0;
3693
855
      else
3694
855
#endif
3695
855
      section.s_vaddr = current->vma;
3696
601
      section.s_paddr = current->lma;
3697
601
      section.s_size =  current->size;
3698
#ifdef coff_get_section_load_page
3699
0
      section.s_page = coff_get_section_load_page (current);
3700
#else
3701
      section.s_page = 0;
3702
#endif
3703
3704
#ifdef COFF_WITH_PE
3705
      section.s_paddr = 0;
3706
#endif
3707
#ifdef COFF_IMAGE_WITH_PE
3708
      /* Reminder: s_paddr holds the virtual size of the section.  */
3709
94
      if (coff_section_data (abfd, current) != NULL
3710
94
    && pei_section_data (abfd, current) != NULL)
3711
94
  section.s_paddr = pei_section_data (abfd, current)->virt_size;
3712
0
      else
3713
0
  section.s_paddr = 0;
3714
#endif
3715
3716
      /* If this section has no size or is unloadable then the scnptr
3717
   will be 0 too.  */
3718
855
      if (current->size == 0
3719
855
    || (current->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
3720
759
  section.s_scnptr = 0;
3721
96
      else
3722
96
  section.s_scnptr = current->filepos;
3723
3724
601
      section.s_relptr = current->rel_filepos;
3725
601
      section.s_lnnoptr = current->line_filepos;
3726
601
      section.s_nreloc = current->reloc_count;
3727
601
      section.s_nlnno = current->lineno_count;
3728
#ifndef COFF_IMAGE_WITH_PE
3729
      /* In PEI, relocs come in the .reloc section.  */
3730
761
      if (current->reloc_count != 0)
3731
0
  hasrelocs = true;
3732
#endif
3733
855
      if (current->lineno_count != 0)
3734
0
  haslinno = true;
3735
#ifdef COFF_IMAGE_WITH_PE
3736
94
      if ((current->flags & SEC_DEBUGGING) != 0
3737
94
    && ! is_reloc_section)
3738
39
  hasdebug = true;
3739
#endif
3740
3741
#ifdef RS6000COFF_C
3742
#ifndef XCOFF64
3743
      /* Indicate the use of an XCOFF overflow section header.  */
3744
0
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3745
0
  {
3746
0
    section.s_nreloc = 0xffff;
3747
0
    section.s_nlnno = 0xffff;
3748
0
  }
3749
#endif
3750
#endif
3751
3752
601
      section.s_flags = sec_to_styp_flags (current->name, current->flags);
3753
3754
855
      if (!strcmp (current->name, _TEXT))
3755
5
  text_sec = current;
3756
850
      else if (!strcmp (current->name, _DATA))
3757
5
  data_sec = current;
3758
845
      else if (!strcmp (current->name, _BSS))
3759
4
  bss_sec = current;
3760
#ifdef RS6000COFF_C
3761
0
      else if (!strcmp (current->name, _TDATA))
3762
0
  tdata_sec = current;
3763
0
      else if (!strcmp (current->name, _TBSS))
3764
0
  tbss_sec = current;
3765
#endif
3766
3767
3768
#ifdef COFF_ENCODE_ALIGNMENT
3769
601
      if (COFF_ENCODE_ALIGNMENT (abfd, section, current->alignment_power)
3770
601
    && (COFF_DECODE_ALIGNMENT (section.s_flags)
3771
507
        != current->alignment_power))
3772
0
  {
3773
0
    bool warn = (coff_data (abfd)->link_info
3774
0
           && !bfd_link_relocatable (coff_data (abfd)->link_info));
3775
3776
0
    _bfd_error_handler
3777
      /* xgettext:c-format */
3778
0
      (_("%pB:%s section %s: alignment 2**%u not representable"),
3779
0
       abfd, warn ? " warning:" : "", current->name,
3780
0
       current->alignment_power);
3781
0
    if (!warn)
3782
0
      {
3783
0
        bfd_set_error (bfd_error_nonrepresentable_section);
3784
0
        return false;
3785
0
      }
3786
0
  }
3787
94
#endif
3788
3789
#ifdef COFF_IMAGE_WITH_PE
3790
      /* Suppress output of the sections if they are null.  ld
3791
   includes the bss and data sections even if there is no size
3792
   assigned to them.  NT loader doesn't like it if these section
3793
   headers are included if the sections themselves are not
3794
   needed.  See also coff_compute_section_file_positions.  */
3795
94
      if (section.s_size == 0)
3796
0
  internal_f.f_nscns--;
3797
94
      else
3798
94
#endif
3799
94
  {
3800
855
    SCNHDR buff;
3801
855
    bfd_size_type amt = bfd_coff_scnhsz (abfd);
3802
3803
855
    if (bfd_coff_swap_scnhdr_out (abfd, &section, &buff) == 0
3804
855
        || bfd_write (& buff, amt, abfd) != amt)
3805
0
      return false;
3806
94
  }
3807
3808
#ifdef COFF_WITH_PE
3809
      /* PE stores COMDAT section information in the symbol table.  If
3810
   this section is supposed to have some COMDAT info, track down
3811
   the symbol in the symbol table and modify it.  */
3812
601
      if ((current->flags & SEC_LINK_ONCE) != 0)
3813
1
  {
3814
1
    unsigned int i, count;
3815
1
    asymbol **psym;
3816
1
    coff_symbol_type *csym = NULL;
3817
1
    asymbol **psymsec;
3818
3819
    psymsec = NULL;
3820
    count = bfd_get_symcount (abfd);
3821
160
    for (i = 0, psym = abfd->outsymbols; i < count; i++, psym++)
3822
159
      {
3823
159
        if ((*psym)->section != current)
3824
159
    continue;
3825
3826
        /* Remember the location of the first symbol in this
3827
     section.  */
3828
0
        if (psymsec == NULL)
3829
0
    psymsec = psym;
3830
3831
        /* See if this is the section symbol.  */
3832
0
        if (strcmp ((*psym)->name, current->name) == 0)
3833
0
    {
3834
0
      csym = coff_symbol_from (*psym);
3835
0
      if (csym == NULL
3836
0
          || csym->native == NULL
3837
0
          || ! csym->native->is_sym
3838
0
          || csym->native->u.syment.n_numaux < 1
3839
0
          || csym->native->u.syment.n_sclass != C_STAT
3840
0
          || csym->native->u.syment.n_type != T_NULL)
3841
0
        continue;
3842
3843
      /* Here *PSYM is the section symbol for CURRENT.  */
3844
3845
0
      break;
3846
0
    }
3847
0
      }
3848
3849
    /* Did we find it?
3850
       Note that we might not if we're converting the file from
3851
       some other object file format.  */
3852
1
    if (i < count)
3853
0
      {
3854
0
        combined_entry_type *aux;
3855
3856
        /* We don't touch the x_checksum field.  The
3857
     x_associated field is not currently supported.  */
3858
3859
0
        aux = csym->native + 1;
3860
0
        BFD_ASSERT (! aux->is_sym);
3861
0
        switch (current->flags & SEC_LINK_DUPLICATES)
3862
0
    {
3863
0
    case SEC_LINK_DUPLICATES_DISCARD:
3864
0
      aux->u.auxent.x_scn.x_comdat = IMAGE_COMDAT_SELECT_ANY;
3865
0
      break;
3866
3867
0
    case SEC_LINK_DUPLICATES_ONE_ONLY:
3868
0
      aux->u.auxent.x_scn.x_comdat =
3869
0
        IMAGE_COMDAT_SELECT_NODUPLICATES;
3870
0
      break;
3871
3872
0
    case SEC_LINK_DUPLICATES_SAME_SIZE:
3873
0
      aux->u.auxent.x_scn.x_comdat =
3874
0
        IMAGE_COMDAT_SELECT_SAME_SIZE;
3875
0
      break;
3876
3877
0
    case SEC_LINK_DUPLICATES_SAME_CONTENTS:
3878
0
      aux->u.auxent.x_scn.x_comdat =
3879
0
        IMAGE_COMDAT_SELECT_EXACT_MATCH;
3880
0
      break;
3881
0
    }
3882
3883
        /* The COMDAT symbol must be the first symbol from this
3884
     section in the symbol table.  In order to make this
3885
     work, we move the COMDAT symbol before the first
3886
     symbol we found in the search above.  It's OK to
3887
     rearrange the symbol table at this point, because
3888
     coff_renumber_symbols is going to rearrange it
3889
     further and fix up all the aux entries.  */
3890
0
        if (psym != psymsec)
3891
0
    {
3892
0
      asymbol *hold;
3893
0
      asymbol **pcopy;
3894
3895
0
      hold = *psym;
3896
0
      for (pcopy = psym; pcopy > psymsec; pcopy--)
3897
0
        pcopy[0] = pcopy[-1];
3898
0
      *psymsec = hold;
3899
0
    }
3900
0
      }
3901
1
  }
3902
#endif /* COFF_WITH_PE */
3903
601
    }
3904
3905
#ifdef RS6000COFF_C
3906
#ifndef XCOFF64
3907
  /* XCOFF handles overflows in the reloc and line number count fields
3908
     by creating a new section header to hold the correct values.  */
3909
0
  for (current = abfd->sections; current != NULL; current = current->next)
3910
0
    {
3911
0
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3912
0
  {
3913
0
    struct internal_scnhdr scnhdr;
3914
0
    SCNHDR buff;
3915
0
    bfd_size_type amt;
3916
3917
0
    internal_f.f_nscns++;
3918
0
    memcpy (scnhdr.s_name, ".ovrflo", 8);
3919
0
    scnhdr.s_paddr = current->reloc_count;
3920
0
    scnhdr.s_vaddr = current->lineno_count;
3921
0
    scnhdr.s_size = 0;
3922
0
    scnhdr.s_scnptr = 0;
3923
0
    scnhdr.s_relptr = current->rel_filepos;
3924
0
    scnhdr.s_lnnoptr = current->line_filepos;
3925
0
    scnhdr.s_nreloc = current->target_index;
3926
0
    scnhdr.s_nlnno = current->target_index;
3927
0
    scnhdr.s_flags = STYP_OVRFLO;
3928
0
    amt = bfd_coff_scnhsz (abfd);
3929
0
    if (bfd_coff_swap_scnhdr_out (abfd, &scnhdr, &buff) == 0
3930
0
        || bfd_write (& buff, amt, abfd) != amt)
3931
0
      return false;
3932
0
  }
3933
0
    }
3934
0
#endif
3935
#endif
3936
3937
#if defined (COFF_GO32_EXE) || defined (COFF_GO32)
3938
  /* Pad section headers.  */
3939
0
  if ((abfd->flags & EXEC_P) != 0)
3940
0
    {
3941
0
      asection *s = abfd->sections;
3942
0
      while (s != NULL && s->filepos == 0)
3943
0
  s = s->next;
3944
0
      if (s != NULL)
3945
0
  {
3946
0
    file_ptr cur_ptr
3947
0
      = scn_base + abfd->section_count * bfd_coff_scnhsz (abfd);
3948
0
    file_ptr fill_size = s->filepos - cur_ptr;
3949
0
    if (fill_size > 0)
3950
0
      {
3951
0
        bfd_byte *b = bfd_zmalloc (fill_size);
3952
0
        if (!b)
3953
0
    return false;
3954
0
        if (bfd_write (b, fill_size, abfd) != (ufile_ptr) fill_size)
3955
0
    {
3956
0
      free (b);
3957
0
      return false;
3958
0
    }
3959
0
        free (b);
3960
0
      }
3961
0
  }
3962
0
    }
3963
0
#endif
3964
3965
  /* OK, now set up the filehdr...  */
3966
3967
  /* Don't include the internal abs section in the section count */
3968
3969
  /* We will NOT put a fucking timestamp in the header here. Every time you
3970
     put it back, I will come in and take it out again.  I'm sorry.  This
3971
     field does not belong here.  We fill it with a 0 so it compares the
3972
     same but is not a reasonable time. -- gnu@cygnus.com  */
3973
29
  internal_f.f_timdat = 0;
3974
29
  internal_f.f_flags = 0;
3975
3976
29
  if (abfd->flags & EXEC_P)
3977
17
    internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3978
12
  else
3979
12
    {
3980
12
      internal_f.f_opthdr = 0;
3981
#ifdef RS6000COFF_C
3982
#ifndef XCOFF64
3983
0
      if (xcoff_data (abfd)->full_aouthdr)
3984
0
  internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3985
0
      else
3986
0
  internal_f.f_opthdr = SMALL_AOUTSZ;
3987
#endif
3988
#endif
3989
12
    }
3990
3991
29
  if (!hasrelocs)
3992
25
    internal_f.f_flags |= F_RELFLG;
3993
29
  if (!haslinno)
3994
29
    internal_f.f_flags |= F_LNNO;
3995
29
  if (abfd->flags & EXEC_P)
3996
17
    internal_f.f_flags |= F_EXEC;
3997
#ifdef COFF_IMAGE_WITH_PE
3998
15
  if (! hasdebug)
3999
5
    internal_f.f_flags |= IMAGE_FILE_DEBUG_STRIPPED;
4000
15
  if (pe_data (abfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
4001
10
    internal_f.f_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
4002
#endif
4003
4004
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
4005
#ifdef COFF_WITH_PE
4006
10
  internal_f.f_flags |= IMAGE_FILE_32BIT_MACHINE;
4007
#else
4008
7
  if (bfd_little_endian (abfd))
4009
2
    internal_f.f_flags |= F_AR32WR;
4010
5
  else
4011
5
    internal_f.f_flags |= F_AR32W;
4012
#endif
4013
#endif
4014
4015
#ifdef TI_TARGET_ID
4016
  /* Target id is used in TI COFF v1 and later; COFF0 won't use this field,
4017
     but it doesn't hurt to set it internally.  */
4018
0
  internal_f.f_target_id = TI_TARGET_ID;
4019
#endif
4020
4021
  /* FIXME, should do something about the other byte orders and
4022
     architectures.  */
4023
4024
#ifdef RS6000COFF_C
4025
1
  if ((abfd->flags & DYNAMIC) != 0)
4026
0
    internal_f.f_flags |= F_SHROBJ;
4027
1
  if (bfd_get_section_by_name (abfd, _LOADER) != NULL)
4028
0
    internal_f.f_flags |= F_DYNLOAD;
4029
#endif
4030
4031
29
  memset (&internal_a, 0, sizeof internal_a);
4032
4033
  /* Set up architecture-dependent stuff.  */
4034
29
  {
4035
29
    unsigned int magic = 0;
4036
29
    unsigned short flags = 0;
4037
4038
29
    coff_set_flags (abfd, &magic, &flags);
4039
29
    internal_f.f_magic = magic;
4040
29
    internal_f.f_flags |= flags;
4041
    /* ...and the "opt"hdr...  */
4042
4043
#ifdef TICOFF_AOUT_MAGIC
4044
0
    internal_a.magic = TICOFF_AOUT_MAGIC;
4045
#define __A_MAGIC_SET__
4046
#endif
4047
4048
#if defined(ARM)
4049
#define __A_MAGIC_SET__
4050
1
    internal_a.magic = ZMAGIC;
4051
#endif
4052
4053
#if defined(AARCH64)
4054
#define __A_MAGIC_SET__
4055
3
    internal_a.magic = ZMAGIC;
4056
#endif
4057
4058
#if defined(LOONGARCH64)
4059
#define __A_MAGIC_SET__
4060
0
    internal_a.magic = ZMAGIC;
4061
#endif
4062
4063
#if defined MCORE_PE
4064
#define __A_MAGIC_SET__
4065
2
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR_MAGIC;
4066
#endif
4067
4068
#if defined(I386)
4069
#define __A_MAGIC_SET__
4070
#if defined LYNXOS
4071
0
    internal_a.magic = LYNXCOFFMAGIC;
4072
#elif defined AMD64
4073
11
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR64_MAGIC;
4074
#else
4075
6
    internal_a.magic = ZMAGIC;
4076
#endif
4077
#endif /* I386 */
4078
4079
#if defined(IA64)
4080
#define __A_MAGIC_SET__
4081
0
    internal_a.magic = PE32PMAGIC;
4082
#endif /* IA64 */
4083
4084
#if defined(SPARC)
4085
#define __A_MAGIC_SET__
4086
#if defined(LYNXOS)
4087
    internal_a.magic = LYNXCOFFMAGIC;
4088
#endif /* LYNXOS */
4089
#endif /* SPARC */
4090
4091
#ifdef RS6000COFF_C
4092
#define __A_MAGIC_SET__
4093
1
    internal_a.magic = (abfd->flags & D_PAGED) ? RS6K_AOUTHDR_ZMAGIC :
4094
1
    (abfd->flags & WP_TEXT) ? RS6K_AOUTHDR_NMAGIC :
4095
1
    RS6K_AOUTHDR_OMAGIC;
4096
#endif
4097
4098
#if defined(SH) && defined(COFF_WITH_PE)
4099
#define __A_MAGIC_SET__
4100
1
    internal_a.magic = SH_PE_MAGIC;
4101
#endif
4102
4103
#if defined(MIPS) && defined(COFF_WITH_PE)
4104
#define __A_MAGIC_SET__
4105
    internal_a.magic = MIPS_PE_MAGIC;
4106
#endif
4107
4108
#ifndef __A_MAGIC_SET__
4109
#include "Your aouthdr magic number is not being set!"
4110
#else
4111
29
#undef __A_MAGIC_SET__
4112
29
#endif
4113
29
  }
4114
4115
#ifdef RS6000COFF_C
4116
  /* XCOFF 32bit needs this to have new behaviour for n_type field.  */
4117
  internal_a.vstamp = 2;
4118
#else
4119
  /* FIXME: Does anybody ever set this to another value?  */
4120
  internal_a.vstamp = 0;
4121
#endif
4122
4123
  /* Now should write relocs, strings, syms.  */
4124
29
  obj_sym_filepos (abfd) = sym_base;
4125
4126
29
  if (bfd_get_symcount (abfd) != 0)
4127
7
    {
4128
7
      int firstundef;
4129
4130
7
      if (!coff_renumber_symbols (abfd, &firstundef))
4131
0
  return false;
4132
7
      coff_mangle_symbols (abfd);
4133
7
      if (! coff_write_symbols (abfd))
4134
0
  return false;
4135
7
      if (! coff_write_linenumbers (abfd))
4136
0
  return false;
4137
7
      if (! coff_write_relocs (abfd, firstundef))
4138
0
  return false;
4139
7
    }
4140
#ifdef COFF_LONG_SECTION_NAMES
4141
15
  else if (long_section_names && ! obj_coff_strings_written (abfd))
4142
1
    {
4143
      /* If we have long section names we have to write out the string
4144
   table even if there are no symbols.  */
4145
1
      if (! coff_write_symbols (abfd))
4146
0
  return false;
4147
1
    }
4148
22
#endif
4149
  /* If bfd_get_symcount (abfd) != 0, then we are not using the COFF
4150
     backend linker, and obj_raw_syment_count is not valid until after
4151
     coff_write_symbols is called.  */
4152
29
  if (obj_raw_syment_count (abfd) != 0)
4153
7
    {
4154
7
      internal_f.f_symptr = sym_base;
4155
#ifdef RS6000COFF_C
4156
      /* AIX appears to require that F_RELFLG not be set if there are
4157
   local symbols but no relocations.  */
4158
0
      internal_f.f_flags &=~ F_RELFLG;
4159
#endif
4160
7
    }
4161
22
  else
4162
22
    {
4163
22
      if (long_section_names)
4164
1
  internal_f.f_symptr = sym_base;
4165
21
      else
4166
21
  internal_f.f_symptr = 0;
4167
22
      internal_f.f_flags |= F_LSYMS;
4168
22
    }
4169
4170
29
  if (text_sec)
4171
5
    {
4172
5
      internal_a.tsize = text_sec->size;
4173
5
      internal_a.text_start = internal_a.tsize ? text_sec->vma : 0;
4174
5
    }
4175
29
  if (data_sec)
4176
5
    {
4177
5
      internal_a.dsize = data_sec->size;
4178
5
      internal_a.data_start = internal_a.dsize ? data_sec->vma : 0;
4179
5
    }
4180
29
  if (bss_sec)
4181
4
    {
4182
4
      internal_a.bsize = bss_sec->size;
4183
4
      if (internal_a.bsize && bss_sec->vma < internal_a.data_start)
4184
0
  internal_a.data_start = bss_sec->vma;
4185
4
    }
4186
4187
29
  internal_a.entry = bfd_get_start_address (abfd);
4188
29
  internal_f.f_nsyms = obj_raw_syment_count (abfd);
4189
4190
#ifdef RS6000COFF_C
4191
1
  if (xcoff_data (abfd)->full_aouthdr)
4192
0
    {
4193
0
      bfd_vma toc;
4194
0
      asection *loader_sec;
4195
4196
      internal_a.vstamp = 2;
4197
4198
0
      internal_a.o_snentry = xcoff_data (abfd)->snentry;
4199
0
      if (internal_a.o_snentry == 0)
4200
0
  internal_a.entry = (bfd_vma) -1;
4201
4202
0
      if (text_sec != NULL)
4203
0
  {
4204
0
    internal_a.o_sntext = text_sec->target_index;
4205
0
    internal_a.o_algntext = bfd_section_alignment (text_sec);
4206
0
  }
4207
0
      else
4208
0
  {
4209
0
    internal_a.o_sntext = 0;
4210
0
    internal_a.o_algntext = 0;
4211
0
  }
4212
0
      if (data_sec != NULL)
4213
0
  {
4214
0
    internal_a.o_sndata = data_sec->target_index;
4215
0
    internal_a.o_algndata = bfd_section_alignment (data_sec);
4216
0
  }
4217
0
      else
4218
0
  {
4219
0
    internal_a.o_sndata = 0;
4220
0
    internal_a.o_algndata = 0;
4221
0
  }
4222
      loader_sec = bfd_get_section_by_name (abfd, ".loader");
4223
0
      if (loader_sec != NULL)
4224
0
  internal_a.o_snloader = loader_sec->target_index;
4225
0
      else
4226
0
  internal_a.o_snloader = 0;
4227
0
      if (bss_sec != NULL)
4228
0
  internal_a.o_snbss = bss_sec->target_index;
4229
0
      else
4230
0
  internal_a.o_snbss = 0;
4231
4232
0
      if (tdata_sec != NULL)
4233
0
  {
4234
0
    internal_a.o_sntdata = tdata_sec->target_index;
4235
    /* TODO: o_flags should be set to RS6K_AOUTHDR_TLS_LE
4236
       if there is at least one R_TLS_LE relocations.  */
4237
0
    internal_a.o_flags = 0;
4238
#ifdef XCOFF64
4239
    internal_a.o_x64flags = 0;
4240
#endif
4241
0
  }
4242
0
      else
4243
0
  {
4244
0
    internal_a.o_sntdata = 0;
4245
0
    internal_a.o_flags = 0;
4246
#ifdef XCOFF64
4247
    internal_a.o_x64flags = 0;
4248
#endif
4249
0
  }
4250
0
      if (tbss_sec != NULL)
4251
0
    internal_a.o_sntbss = tbss_sec->target_index;
4252
0
      else
4253
0
    internal_a.o_sntbss = 0;
4254
4255
0
      toc = xcoff_data (abfd)->toc;
4256
      internal_a.o_toc = toc;
4257
0
      internal_a.o_sntoc = xcoff_data (abfd)->sntoc;
4258
4259
0
      internal_a.o_modtype = xcoff_data (abfd)->modtype;
4260
0
      if (xcoff_data (abfd)->cputype != -1)
4261
0
  internal_a.o_cputype = xcoff_data (abfd)->cputype;
4262
0
      else
4263
0
  {
4264
0
    switch (bfd_get_arch (abfd))
4265
0
      {
4266
0
      case bfd_arch_rs6000:
4267
0
        internal_a.o_cputype = 4;
4268
0
        break;
4269
0
      case bfd_arch_powerpc:
4270
0
        if (bfd_get_mach (abfd) == bfd_mach_ppc)
4271
0
    internal_a.o_cputype = 3;
4272
0
        else if (bfd_get_mach (abfd) == bfd_mach_ppc_620)
4273
0
    internal_a.o_cputype = 2;
4274
0
        else
4275
0
    internal_a.o_cputype = 1;
4276
0
        break;
4277
0
      default:
4278
0
        abort ();
4279
0
      }
4280
0
  }
4281
0
      internal_a.o_maxstack = xcoff_data (abfd)->maxstack;
4282
0
      internal_a.o_maxdata = xcoff_data (abfd)->maxdata;
4283
0
    }
4284
1
#endif
4285
4286
#ifdef COFF_WITH_PE
4287
  {
4288
    /* After object contents are finalized so we can compute a reasonable hash,
4289
       but before header is written so we can update it to point to debug directory.  */
4290
22
    struct pe_tdata *pe = pe_data (abfd);
4291
4292
22
    if (pe->build_id.after_write_object_contents != NULL)
4293
0
      (*pe->build_id.after_write_object_contents) (abfd);
4294
  }
4295
#endif
4296
4297
  /* Now write header.  */
4298
29
  if (bfd_seek (abfd, 0, SEEK_SET) != 0)
4299
0
    return false;
4300
4301
29
  {
4302
29
    char * buff;
4303
29
    bfd_size_type amount = bfd_coff_filhsz (abfd);
4304
4305
29
    buff = (char *) bfd_malloc (amount);
4306
29
    if (buff == NULL)
4307
0
      return false;
4308
4309
29
    bfd_coff_swap_filehdr_out (abfd, & internal_f, buff);
4310
29
    amount = bfd_write (buff, amount, abfd);
4311
4312
29
    free (buff);
4313
4314
29
    if (amount != bfd_coff_filhsz (abfd))
4315
0
      return false;
4316
29
  }
4317
4318
29
  if (abfd->flags & EXEC_P)
4319
17
    {
4320
      /* Note that peicode.h fills in a PEAOUTHDR, not an AOUTHDR.
4321
   include/coff/pe.h sets AOUTSZ == sizeof (PEAOUTHDR)).  */
4322
17
      char * buff;
4323
17
      bfd_size_type amount = bfd_coff_aoutsz (abfd);
4324
4325
17
      buff = (char *) bfd_malloc (amount);
4326
17
      if (buff == NULL)
4327
0
  return false;
4328
4329
17
      coff_swap_aouthdr_out (abfd, & internal_a, buff);
4330
12
      amount = bfd_write (buff, amount, abfd);
4331
4332
12
      free (buff);
4333
4334
17
      if (amount != bfd_coff_aoutsz (abfd))
4335
0
  return false;
4336
4337
#ifdef COFF_IMAGE_WITH_PE
4338
11
      if (! coff_apply_checksum (abfd))
4339
0
  return false;
4340
#endif
4341
11
    }
4342
#ifdef RS6000COFF_C
4343
#ifndef XCOFF64
4344
  else
4345
0
    {
4346
0
      AOUTHDR buff;
4347
0
      size_t size;
4348
4349
      /* XCOFF32 seems to always write at least a small a.out header.  */
4350
0
      coff_swap_aouthdr_out (abfd, & internal_a, & buff);
4351
0
      if (xcoff_data (abfd)->full_aouthdr)
4352
0
  size = bfd_coff_aoutsz (abfd);
4353
0
      else
4354
0
  size = SMALL_AOUTSZ;
4355
0
      if (bfd_write (&buff, size, abfd) != size)
4356
0
  return false;
4357
0
    }
4358
0
#endif
4359
#endif
4360
4361
29
  return true;
4362
29
}
pei-i386.c:coff_write_object_contents
Line
Count
Source
3486
3
{
3487
3
  asection *current;
3488
3
  bool hasrelocs = false;
3489
3
  bool haslinno = false;
3490
3
#ifdef COFF_IMAGE_WITH_PE
3491
3
  bool hasdebug = false;
3492
3
#endif
3493
3
  file_ptr scn_base;
3494
3
  file_ptr reloc_base;
3495
3
  file_ptr lineno_base;
3496
3
  file_ptr sym_base;
3497
3
  unsigned long reloc_size = 0, reloc_count = 0;
3498
3
  unsigned long lnno_size = 0;
3499
3
  bool long_section_names;
3500
3
  asection *text_sec = NULL;
3501
3
  asection *data_sec = NULL;
3502
3
  asection *bss_sec = NULL;
3503
#ifdef RS6000COFF_C
3504
  asection *tdata_sec = NULL;
3505
  asection *tbss_sec = NULL;
3506
#endif
3507
3
  struct internal_filehdr internal_f;
3508
3
  struct internal_aouthdr internal_a;
3509
3
#ifdef COFF_LONG_SECTION_NAMES
3510
3
  size_t string_size = STRING_SIZE_SIZE;
3511
3
#endif
3512
3513
3
  bfd_set_error (bfd_error_system_call);
3514
3515
  /* Make a pass through the symbol table to count line number entries and
3516
     put them into the correct asections.  */
3517
3
  lnno_size = coff_count_linenumbers (abfd) * bfd_coff_linesz (abfd);
3518
3519
3
  if (! abfd->output_has_begun)
3520
1
    {
3521
1
      if (! coff_compute_section_file_positions (abfd))
3522
0
  return false;
3523
1
    }
3524
3525
3
  reloc_base = obj_relocbase (abfd);
3526
3527
  /* Work out the size of the reloc and linno areas.  */
3528
3529
16
  for (current = abfd->sections; current != NULL; current =
3530
13
       current->next)
3531
13
    {
3532
13
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3533
      /* We store the actual reloc count in the first reloc's addr.  */
3534
13
      if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3535
0
  reloc_count ++;
3536
13
#endif
3537
13
      reloc_count += current->reloc_count;
3538
13
    }
3539
3540
3
  reloc_size = reloc_count * bfd_coff_relsz (abfd);
3541
3542
3
  lineno_base = reloc_base + reloc_size;
3543
3
  sym_base = lineno_base + lnno_size;
3544
3545
  /* Indicate in each section->line_filepos its actual file address.  */
3546
16
  for (current = abfd->sections; current != NULL; current =
3547
13
       current->next)
3548
13
    {
3549
13
      if (current->lineno_count)
3550
0
  {
3551
0
    current->line_filepos = lineno_base;
3552
0
    current->moving_line_filepos = lineno_base;
3553
0
    lineno_base += current->lineno_count * bfd_coff_linesz (abfd);
3554
0
  }
3555
13
      else
3556
13
  current->line_filepos = 0;
3557
3558
13
      if (current->reloc_count)
3559
0
  {
3560
0
    current->rel_filepos = reloc_base;
3561
0
    reloc_base += current->reloc_count * bfd_coff_relsz (abfd);
3562
0
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3563
    /* Extra reloc to hold real count.  */
3564
0
    if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3565
0
      reloc_base += bfd_coff_relsz (abfd);
3566
0
#endif
3567
0
  }
3568
13
      else
3569
13
  current->rel_filepos = 0;
3570
13
    }
3571
3572
  /* Write section headers to the file.  */
3573
3
  internal_f.f_nscns = 0;
3574
3575
3
  if ((abfd->flags & EXEC_P) != 0)
3576
3
    scn_base = bfd_coff_filhsz (abfd) + bfd_coff_aoutsz (abfd);
3577
0
  else
3578
0
    {
3579
0
      scn_base = bfd_coff_filhsz (abfd);
3580
#ifdef RS6000COFF_C
3581
#ifndef XCOFF64
3582
      if (xcoff_data (abfd)->full_aouthdr)
3583
  scn_base += bfd_coff_aoutsz (abfd);
3584
      else
3585
  scn_base += SMALL_AOUTSZ;
3586
#endif
3587
#endif
3588
0
    }
3589
3590
3
  if (bfd_seek (abfd, scn_base, SEEK_SET) != 0)
3591
0
    return false;
3592
3593
3
  long_section_names = false;
3594
3
  for (current = abfd->sections;
3595
16
       current != NULL;
3596
13
       current = current->next)
3597
13
    {
3598
13
      struct internal_scnhdr section;
3599
13
#ifdef COFF_IMAGE_WITH_PE
3600
13
      bool is_reloc_section = false;
3601
3602
13
      if (strcmp (current->name, DOT_RELOC) == 0)
3603
1
  {
3604
1
    is_reloc_section = true;
3605
1
    hasrelocs = true;
3606
1
    pe_data (abfd)->has_reloc_section = 1;
3607
1
  }
3608
13
#endif
3609
3610
13
      internal_f.f_nscns++;
3611
3612
13
      strncpy (section.s_name, current->name, SCNNMLEN);
3613
3614
13
#ifdef COFF_LONG_SECTION_NAMES
3615
      /* Handle long section names as in PE.  This must be compatible
3616
   with the code in coff_write_symbols and _bfd_coff_final_link.  */
3617
13
      if (bfd_coff_long_section_names (abfd))
3618
9
  {
3619
9
    size_t len;
3620
3621
9
    len = strlen (current->name);
3622
9
    if (len > SCNNMLEN)
3623
2
      {
3624
3625
        /* An inherent limitation of the /nnnnnnn notation used to indicate
3626
     the offset of the long name in the string table is that we
3627
     cannot address entries beyone the ten million byte boundary.  */
3628
2
        if (string_size < 10000000)
3629
2
    {
3630
      /* The s_name field is defined to be NUL-padded but need not
3631
         be NUL-terminated.  We use a temporary buffer so that we
3632
         can still sprintf all eight chars without splatting a
3633
         terminating NUL over the first byte of the following
3634
         member (s_paddr).  */
3635
      /* PR 21096: The +20 is to stop a bogus warning from gcc7
3636
         about a possible buffer overflow.  */
3637
2
      char s_name_buf[SCNNMLEN + 1 + 20];
3638
3639
      /* We do not need to use snprintf here as we have already
3640
         verified that string_size is not too big, plus we have
3641
         an overlarge buffer, just in case.  */
3642
2
      sprintf (s_name_buf, "/%lu", (unsigned long) string_size);
3643
      /* Then strncpy takes care of any padding for us.  */
3644
2
      strncpy (section.s_name, s_name_buf, SCNNMLEN);
3645
2
    }
3646
0
        else
3647
0
#ifdef COFF_WITH_PE
3648
0
    {
3649
      /* PE use a base 64 encoding for long section names whose
3650
         index is very large.  But contrary to RFC 4648, there is
3651
         no padding: 6 characters must be generated.  */
3652
0
      static const char base64[] =
3653
0
        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
3654
0
        "abcdefghijklmnopqrstuvwxyz"
3655
0
        "0123456789+/";
3656
0
      unsigned long off = string_size;
3657
0
      unsigned i;
3658
3659
0
      section.s_name[0] = '/';
3660
0
      section.s_name[1] = '/';
3661
0
      for (i = SCNNMLEN - 1; i >= 2; i--)
3662
0
        {
3663
0
          section.s_name[i] = base64[off & 0x3f];
3664
0
          off >>= 6;
3665
0
        }
3666
0
    }
3667
2
#endif
3668
2
        if (string_size > 0xffffffffUL - (len + 1)
3669
#ifndef COFF_WITH_PE
3670
      || string_size >= 10000000
3671
#endif
3672
2
      )
3673
0
    {
3674
0
      bfd_set_error (bfd_error_file_too_big);
3675
0
      _bfd_error_handler
3676
        /* xgettext:c-format */
3677
0
        (_("%pB: section %pA: string table overflow at offset %ld"),
3678
0
        abfd, current, (unsigned long) string_size);
3679
0
      return false;
3680
0
    }
3681
3682
2
        string_size += len + 1;
3683
2
        long_section_names = true;
3684
2
      }
3685
9
  }
3686
13
#endif
3687
3688
13
#ifdef _LIB
3689
      /* Always set s_vaddr of .lib to 0.  This is right for SVR3.2
3690
   Ian Taylor <ian@cygnus.com>.  */
3691
13
      if (strcmp (current->name, _LIB) == 0)
3692
0
  section.s_vaddr = 0;
3693
13
      else
3694
13
#endif
3695
13
      section.s_vaddr = current->vma;
3696
13
      section.s_paddr = current->lma;
3697
13
      section.s_size =  current->size;
3698
#ifdef coff_get_section_load_page
3699
      section.s_page = coff_get_section_load_page (current);
3700
#else
3701
13
      section.s_page = 0;
3702
13
#endif
3703
3704
13
#ifdef COFF_WITH_PE
3705
13
      section.s_paddr = 0;
3706
13
#endif
3707
13
#ifdef COFF_IMAGE_WITH_PE
3708
      /* Reminder: s_paddr holds the virtual size of the section.  */
3709
13
      if (coff_section_data (abfd, current) != NULL
3710
13
    && pei_section_data (abfd, current) != NULL)
3711
13
  section.s_paddr = pei_section_data (abfd, current)->virt_size;
3712
0
      else
3713
0
  section.s_paddr = 0;
3714
13
#endif
3715
3716
      /* If this section has no size or is unloadable then the scnptr
3717
   will be 0 too.  */
3718
13
      if (current->size == 0
3719
13
    || (current->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
3720
1
  section.s_scnptr = 0;
3721
12
      else
3722
12
  section.s_scnptr = current->filepos;
3723
3724
13
      section.s_relptr = current->rel_filepos;
3725
13
      section.s_lnnoptr = current->line_filepos;
3726
13
      section.s_nreloc = current->reloc_count;
3727
13
      section.s_nlnno = current->lineno_count;
3728
#ifndef COFF_IMAGE_WITH_PE
3729
      /* In PEI, relocs come in the .reloc section.  */
3730
      if (current->reloc_count != 0)
3731
  hasrelocs = true;
3732
#endif
3733
13
      if (current->lineno_count != 0)
3734
0
  haslinno = true;
3735
13
#ifdef COFF_IMAGE_WITH_PE
3736
13
      if ((current->flags & SEC_DEBUGGING) != 0
3737
13
    && ! is_reloc_section)
3738
1
  hasdebug = true;
3739
13
#endif
3740
3741
#ifdef RS6000COFF_C
3742
#ifndef XCOFF64
3743
      /* Indicate the use of an XCOFF overflow section header.  */
3744
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3745
  {
3746
    section.s_nreloc = 0xffff;
3747
    section.s_nlnno = 0xffff;
3748
  }
3749
#endif
3750
#endif
3751
3752
13
      section.s_flags = sec_to_styp_flags (current->name, current->flags);
3753
3754
13
      if (!strcmp (current->name, _TEXT))
3755
2
  text_sec = current;
3756
11
      else if (!strcmp (current->name, _DATA))
3757
2
  data_sec = current;
3758
9
      else if (!strcmp (current->name, _BSS))
3759
1
  bss_sec = current;
3760
#ifdef RS6000COFF_C
3761
      else if (!strcmp (current->name, _TDATA))
3762
  tdata_sec = current;
3763
      else if (!strcmp (current->name, _TBSS))
3764
  tbss_sec = current;
3765
#endif
3766
3767
3768
13
#ifdef COFF_ENCODE_ALIGNMENT
3769
13
      if (COFF_ENCODE_ALIGNMENT (abfd, section, current->alignment_power)
3770
13
    && (COFF_DECODE_ALIGNMENT (section.s_flags)
3771
0
        != current->alignment_power))
3772
0
  {
3773
0
    bool warn = (coff_data (abfd)->link_info
3774
0
           && !bfd_link_relocatable (coff_data (abfd)->link_info));
3775
3776
0
    _bfd_error_handler
3777
      /* xgettext:c-format */
3778
0
      (_("%pB:%s section %s: alignment 2**%u not representable"),
3779
0
       abfd, warn ? " warning:" : "", current->name,
3780
0
       current->alignment_power);
3781
0
    if (!warn)
3782
0
      {
3783
0
        bfd_set_error (bfd_error_nonrepresentable_section);
3784
0
        return false;
3785
0
      }
3786
0
  }
3787
13
#endif
3788
3789
13
#ifdef COFF_IMAGE_WITH_PE
3790
      /* Suppress output of the sections if they are null.  ld
3791
   includes the bss and data sections even if there is no size
3792
   assigned to them.  NT loader doesn't like it if these section
3793
   headers are included if the sections themselves are not
3794
   needed.  See also coff_compute_section_file_positions.  */
3795
13
      if (section.s_size == 0)
3796
0
  internal_f.f_nscns--;
3797
13
      else
3798
13
#endif
3799
13
  {
3800
13
    SCNHDR buff;
3801
13
    bfd_size_type amt = bfd_coff_scnhsz (abfd);
3802
3803
13
    if (bfd_coff_swap_scnhdr_out (abfd, &section, &buff) == 0
3804
13
        || bfd_write (& buff, amt, abfd) != amt)
3805
0
      return false;
3806
13
  }
3807
3808
13
#ifdef COFF_WITH_PE
3809
      /* PE stores COMDAT section information in the symbol table.  If
3810
   this section is supposed to have some COMDAT info, track down
3811
   the symbol in the symbol table and modify it.  */
3812
13
      if ((current->flags & SEC_LINK_ONCE) != 0)
3813
0
  {
3814
0
    unsigned int i, count;
3815
0
    asymbol **psym;
3816
0
    coff_symbol_type *csym = NULL;
3817
0
    asymbol **psymsec;
3818
3819
0
    psymsec = NULL;
3820
0
    count = bfd_get_symcount (abfd);
3821
0
    for (i = 0, psym = abfd->outsymbols; i < count; i++, psym++)
3822
0
      {
3823
0
        if ((*psym)->section != current)
3824
0
    continue;
3825
3826
        /* Remember the location of the first symbol in this
3827
     section.  */
3828
0
        if (psymsec == NULL)
3829
0
    psymsec = psym;
3830
3831
        /* See if this is the section symbol.  */
3832
0
        if (strcmp ((*psym)->name, current->name) == 0)
3833
0
    {
3834
0
      csym = coff_symbol_from (*psym);
3835
0
      if (csym == NULL
3836
0
          || csym->native == NULL
3837
0
          || ! csym->native->is_sym
3838
0
          || csym->native->u.syment.n_numaux < 1
3839
0
          || csym->native->u.syment.n_sclass != C_STAT
3840
0
          || csym->native->u.syment.n_type != T_NULL)
3841
0
        continue;
3842
3843
      /* Here *PSYM is the section symbol for CURRENT.  */
3844
3845
0
      break;
3846
0
    }
3847
0
      }
3848
3849
    /* Did we find it?
3850
       Note that we might not if we're converting the file from
3851
       some other object file format.  */
3852
0
    if (i < count)
3853
0
      {
3854
0
        combined_entry_type *aux;
3855
3856
        /* We don't touch the x_checksum field.  The
3857
     x_associated field is not currently supported.  */
3858
3859
0
        aux = csym->native + 1;
3860
0
        BFD_ASSERT (! aux->is_sym);
3861
0
        switch (current->flags & SEC_LINK_DUPLICATES)
3862
0
    {
3863
0
    case SEC_LINK_DUPLICATES_DISCARD:
3864
0
      aux->u.auxent.x_scn.x_comdat = IMAGE_COMDAT_SELECT_ANY;
3865
0
      break;
3866
3867
0
    case SEC_LINK_DUPLICATES_ONE_ONLY:
3868
0
      aux->u.auxent.x_scn.x_comdat =
3869
0
        IMAGE_COMDAT_SELECT_NODUPLICATES;
3870
0
      break;
3871
3872
0
    case SEC_LINK_DUPLICATES_SAME_SIZE:
3873
0
      aux->u.auxent.x_scn.x_comdat =
3874
0
        IMAGE_COMDAT_SELECT_SAME_SIZE;
3875
0
      break;
3876
3877
0
    case SEC_LINK_DUPLICATES_SAME_CONTENTS:
3878
0
      aux->u.auxent.x_scn.x_comdat =
3879
0
        IMAGE_COMDAT_SELECT_EXACT_MATCH;
3880
0
      break;
3881
0
    }
3882
3883
        /* The COMDAT symbol must be the first symbol from this
3884
     section in the symbol table.  In order to make this
3885
     work, we move the COMDAT symbol before the first
3886
     symbol we found in the search above.  It's OK to
3887
     rearrange the symbol table at this point, because
3888
     coff_renumber_symbols is going to rearrange it
3889
     further and fix up all the aux entries.  */
3890
0
        if (psym != psymsec)
3891
0
    {
3892
0
      asymbol *hold;
3893
0
      asymbol **pcopy;
3894
3895
0
      hold = *psym;
3896
0
      for (pcopy = psym; pcopy > psymsec; pcopy--)
3897
0
        pcopy[0] = pcopy[-1];
3898
0
      *psymsec = hold;
3899
0
    }
3900
0
      }
3901
0
  }
3902
13
#endif /* COFF_WITH_PE */
3903
13
    }
3904
3905
#ifdef RS6000COFF_C
3906
#ifndef XCOFF64
3907
  /* XCOFF handles overflows in the reloc and line number count fields
3908
     by creating a new section header to hold the correct values.  */
3909
  for (current = abfd->sections; current != NULL; current = current->next)
3910
    {
3911
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3912
  {
3913
    struct internal_scnhdr scnhdr;
3914
    SCNHDR buff;
3915
    bfd_size_type amt;
3916
3917
    internal_f.f_nscns++;
3918
    memcpy (scnhdr.s_name, ".ovrflo", 8);
3919
    scnhdr.s_paddr = current->reloc_count;
3920
    scnhdr.s_vaddr = current->lineno_count;
3921
    scnhdr.s_size = 0;
3922
    scnhdr.s_scnptr = 0;
3923
    scnhdr.s_relptr = current->rel_filepos;
3924
    scnhdr.s_lnnoptr = current->line_filepos;
3925
    scnhdr.s_nreloc = current->target_index;
3926
    scnhdr.s_nlnno = current->target_index;
3927
    scnhdr.s_flags = STYP_OVRFLO;
3928
    amt = bfd_coff_scnhsz (abfd);
3929
    if (bfd_coff_swap_scnhdr_out (abfd, &scnhdr, &buff) == 0
3930
        || bfd_write (& buff, amt, abfd) != amt)
3931
      return false;
3932
  }
3933
    }
3934
#endif
3935
#endif
3936
3937
#if defined (COFF_GO32_EXE) || defined (COFF_GO32)
3938
  /* Pad section headers.  */
3939
  if ((abfd->flags & EXEC_P) != 0)
3940
    {
3941
      asection *s = abfd->sections;
3942
      while (s != NULL && s->filepos == 0)
3943
  s = s->next;
3944
      if (s != NULL)
3945
  {
3946
    file_ptr cur_ptr
3947
      = scn_base + abfd->section_count * bfd_coff_scnhsz (abfd);
3948
    file_ptr fill_size = s->filepos - cur_ptr;
3949
    if (fill_size > 0)
3950
      {
3951
        bfd_byte *b = bfd_zmalloc (fill_size);
3952
        if (!b)
3953
    return false;
3954
        if (bfd_write (b, fill_size, abfd) != (ufile_ptr) fill_size)
3955
    {
3956
      free (b);
3957
      return false;
3958
    }
3959
        free (b);
3960
      }
3961
  }
3962
    }
3963
#endif
3964
3965
  /* OK, now set up the filehdr...  */
3966
3967
  /* Don't include the internal abs section in the section count */
3968
3969
  /* We will NOT put a fucking timestamp in the header here. Every time you
3970
     put it back, I will come in and take it out again.  I'm sorry.  This
3971
     field does not belong here.  We fill it with a 0 so it compares the
3972
     same but is not a reasonable time. -- gnu@cygnus.com  */
3973
3
  internal_f.f_timdat = 0;
3974
3
  internal_f.f_flags = 0;
3975
3976
3
  if (abfd->flags & EXEC_P)
3977
3
    internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3978
0
  else
3979
0
    {
3980
0
      internal_f.f_opthdr = 0;
3981
#ifdef RS6000COFF_C
3982
#ifndef XCOFF64
3983
      if (xcoff_data (abfd)->full_aouthdr)
3984
  internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3985
      else
3986
  internal_f.f_opthdr = SMALL_AOUTSZ;
3987
#endif
3988
#endif
3989
0
    }
3990
3991
3
  if (!hasrelocs)
3992
2
    internal_f.f_flags |= F_RELFLG;
3993
3
  if (!haslinno)
3994
3
    internal_f.f_flags |= F_LNNO;
3995
3
  if (abfd->flags & EXEC_P)
3996
3
    internal_f.f_flags |= F_EXEC;
3997
3
#ifdef COFF_IMAGE_WITH_PE
3998
3
  if (! hasdebug)
3999
2
    internal_f.f_flags |= IMAGE_FILE_DEBUG_STRIPPED;
4000
3
  if (pe_data (abfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
4001
1
    internal_f.f_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
4002
3
#endif
4003
4004
3
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
4005
3
#ifdef COFF_WITH_PE
4006
3
  internal_f.f_flags |= IMAGE_FILE_32BIT_MACHINE;
4007
#else
4008
  if (bfd_little_endian (abfd))
4009
    internal_f.f_flags |= F_AR32WR;
4010
  else
4011
    internal_f.f_flags |= F_AR32W;
4012
#endif
4013
3
#endif
4014
4015
#ifdef TI_TARGET_ID
4016
  /* Target id is used in TI COFF v1 and later; COFF0 won't use this field,
4017
     but it doesn't hurt to set it internally.  */
4018
  internal_f.f_target_id = TI_TARGET_ID;
4019
#endif
4020
4021
  /* FIXME, should do something about the other byte orders and
4022
     architectures.  */
4023
4024
#ifdef RS6000COFF_C
4025
  if ((abfd->flags & DYNAMIC) != 0)
4026
    internal_f.f_flags |= F_SHROBJ;
4027
  if (bfd_get_section_by_name (abfd, _LOADER) != NULL)
4028
    internal_f.f_flags |= F_DYNLOAD;
4029
#endif
4030
4031
3
  memset (&internal_a, 0, sizeof internal_a);
4032
4033
  /* Set up architecture-dependent stuff.  */
4034
3
  {
4035
3
    unsigned int magic = 0;
4036
3
    unsigned short flags = 0;
4037
4038
3
    coff_set_flags (abfd, &magic, &flags);
4039
3
    internal_f.f_magic = magic;
4040
3
    internal_f.f_flags |= flags;
4041
    /* ...and the "opt"hdr...  */
4042
4043
#ifdef TICOFF_AOUT_MAGIC
4044
    internal_a.magic = TICOFF_AOUT_MAGIC;
4045
#define __A_MAGIC_SET__
4046
#endif
4047
4048
#if defined(ARM)
4049
#define __A_MAGIC_SET__
4050
    internal_a.magic = ZMAGIC;
4051
#endif
4052
4053
#if defined(AARCH64)
4054
#define __A_MAGIC_SET__
4055
    internal_a.magic = ZMAGIC;
4056
#endif
4057
4058
#if defined(LOONGARCH64)
4059
#define __A_MAGIC_SET__
4060
    internal_a.magic = ZMAGIC;
4061
#endif
4062
4063
#if defined MCORE_PE
4064
#define __A_MAGIC_SET__
4065
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR_MAGIC;
4066
#endif
4067
4068
3
#if defined(I386)
4069
3
#define __A_MAGIC_SET__
4070
#if defined LYNXOS
4071
    internal_a.magic = LYNXCOFFMAGIC;
4072
#elif defined AMD64
4073
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR64_MAGIC;
4074
#else
4075
3
    internal_a.magic = ZMAGIC;
4076
3
#endif
4077
3
#endif /* I386 */
4078
4079
#if defined(IA64)
4080
#define __A_MAGIC_SET__
4081
    internal_a.magic = PE32PMAGIC;
4082
#endif /* IA64 */
4083
4084
#if defined(SPARC)
4085
#define __A_MAGIC_SET__
4086
#if defined(LYNXOS)
4087
    internal_a.magic = LYNXCOFFMAGIC;
4088
#endif /* LYNXOS */
4089
#endif /* SPARC */
4090
4091
#ifdef RS6000COFF_C
4092
#define __A_MAGIC_SET__
4093
    internal_a.magic = (abfd->flags & D_PAGED) ? RS6K_AOUTHDR_ZMAGIC :
4094
    (abfd->flags & WP_TEXT) ? RS6K_AOUTHDR_NMAGIC :
4095
    RS6K_AOUTHDR_OMAGIC;
4096
#endif
4097
4098
#if defined(SH) && defined(COFF_WITH_PE)
4099
#define __A_MAGIC_SET__
4100
    internal_a.magic = SH_PE_MAGIC;
4101
#endif
4102
4103
#if defined(MIPS) && defined(COFF_WITH_PE)
4104
#define __A_MAGIC_SET__
4105
    internal_a.magic = MIPS_PE_MAGIC;
4106
#endif
4107
4108
#ifndef __A_MAGIC_SET__
4109
#include "Your aouthdr magic number is not being set!"
4110
#else
4111
3
#undef __A_MAGIC_SET__
4112
3
#endif
4113
3
  }
4114
4115
#ifdef RS6000COFF_C
4116
  /* XCOFF 32bit needs this to have new behaviour for n_type field.  */
4117
  internal_a.vstamp = 2;
4118
#else
4119
  /* FIXME: Does anybody ever set this to another value?  */
4120
3
  internal_a.vstamp = 0;
4121
3
#endif
4122
4123
  /* Now should write relocs, strings, syms.  */
4124
3
  obj_sym_filepos (abfd) = sym_base;
4125
4126
3
  if (bfd_get_symcount (abfd) != 0)
4127
0
    {
4128
0
      int firstundef;
4129
4130
0
      if (!coff_renumber_symbols (abfd, &firstundef))
4131
0
  return false;
4132
0
      coff_mangle_symbols (abfd);
4133
0
      if (! coff_write_symbols (abfd))
4134
0
  return false;
4135
0
      if (! coff_write_linenumbers (abfd))
4136
0
  return false;
4137
0
      if (! coff_write_relocs (abfd, firstundef))
4138
0
  return false;
4139
0
    }
4140
3
#ifdef COFF_LONG_SECTION_NAMES
4141
3
  else if (long_section_names && ! obj_coff_strings_written (abfd))
4142
1
    {
4143
      /* If we have long section names we have to write out the string
4144
   table even if there are no symbols.  */
4145
1
      if (! coff_write_symbols (abfd))
4146
0
  return false;
4147
1
    }
4148
3
#endif
4149
  /* If bfd_get_symcount (abfd) != 0, then we are not using the COFF
4150
     backend linker, and obj_raw_syment_count is not valid until after
4151
     coff_write_symbols is called.  */
4152
3
  if (obj_raw_syment_count (abfd) != 0)
4153
0
    {
4154
0
      internal_f.f_symptr = sym_base;
4155
#ifdef RS6000COFF_C
4156
      /* AIX appears to require that F_RELFLG not be set if there are
4157
   local symbols but no relocations.  */
4158
      internal_f.f_flags &=~ F_RELFLG;
4159
#endif
4160
0
    }
4161
3
  else
4162
3
    {
4163
3
      if (long_section_names)
4164
1
  internal_f.f_symptr = sym_base;
4165
2
      else
4166
2
  internal_f.f_symptr = 0;
4167
3
      internal_f.f_flags |= F_LSYMS;
4168
3
    }
4169
4170
3
  if (text_sec)
4171
2
    {
4172
2
      internal_a.tsize = text_sec->size;
4173
2
      internal_a.text_start = internal_a.tsize ? text_sec->vma : 0;
4174
2
    }
4175
3
  if (data_sec)
4176
2
    {
4177
2
      internal_a.dsize = data_sec->size;
4178
2
      internal_a.data_start = internal_a.dsize ? data_sec->vma : 0;
4179
2
    }
4180
3
  if (bss_sec)
4181
1
    {
4182
1
      internal_a.bsize = bss_sec->size;
4183
1
      if (internal_a.bsize && bss_sec->vma < internal_a.data_start)
4184
0
  internal_a.data_start = bss_sec->vma;
4185
1
    }
4186
4187
3
  internal_a.entry = bfd_get_start_address (abfd);
4188
3
  internal_f.f_nsyms = obj_raw_syment_count (abfd);
4189
4190
#ifdef RS6000COFF_C
4191
  if (xcoff_data (abfd)->full_aouthdr)
4192
    {
4193
      bfd_vma toc;
4194
      asection *loader_sec;
4195
4196
      internal_a.vstamp = 2;
4197
4198
      internal_a.o_snentry = xcoff_data (abfd)->snentry;
4199
      if (internal_a.o_snentry == 0)
4200
  internal_a.entry = (bfd_vma) -1;
4201
4202
      if (text_sec != NULL)
4203
  {
4204
    internal_a.o_sntext = text_sec->target_index;
4205
    internal_a.o_algntext = bfd_section_alignment (text_sec);
4206
  }
4207
      else
4208
  {
4209
    internal_a.o_sntext = 0;
4210
    internal_a.o_algntext = 0;
4211
  }
4212
      if (data_sec != NULL)
4213
  {
4214
    internal_a.o_sndata = data_sec->target_index;
4215
    internal_a.o_algndata = bfd_section_alignment (data_sec);
4216
  }
4217
      else
4218
  {
4219
    internal_a.o_sndata = 0;
4220
    internal_a.o_algndata = 0;
4221
  }
4222
      loader_sec = bfd_get_section_by_name (abfd, ".loader");
4223
      if (loader_sec != NULL)
4224
  internal_a.o_snloader = loader_sec->target_index;
4225
      else
4226
  internal_a.o_snloader = 0;
4227
      if (bss_sec != NULL)
4228
  internal_a.o_snbss = bss_sec->target_index;
4229
      else
4230
  internal_a.o_snbss = 0;
4231
4232
      if (tdata_sec != NULL)
4233
  {
4234
    internal_a.o_sntdata = tdata_sec->target_index;
4235
    /* TODO: o_flags should be set to RS6K_AOUTHDR_TLS_LE
4236
       if there is at least one R_TLS_LE relocations.  */
4237
    internal_a.o_flags = 0;
4238
#ifdef XCOFF64
4239
    internal_a.o_x64flags = 0;
4240
#endif
4241
  }
4242
      else
4243
  {
4244
    internal_a.o_sntdata = 0;
4245
    internal_a.o_flags = 0;
4246
#ifdef XCOFF64
4247
    internal_a.o_x64flags = 0;
4248
#endif
4249
  }
4250
      if (tbss_sec != NULL)
4251
    internal_a.o_sntbss = tbss_sec->target_index;
4252
      else
4253
    internal_a.o_sntbss = 0;
4254
4255
      toc = xcoff_data (abfd)->toc;
4256
      internal_a.o_toc = toc;
4257
      internal_a.o_sntoc = xcoff_data (abfd)->sntoc;
4258
4259
      internal_a.o_modtype = xcoff_data (abfd)->modtype;
4260
      if (xcoff_data (abfd)->cputype != -1)
4261
  internal_a.o_cputype = xcoff_data (abfd)->cputype;
4262
      else
4263
  {
4264
    switch (bfd_get_arch (abfd))
4265
      {
4266
      case bfd_arch_rs6000:
4267
        internal_a.o_cputype = 4;
4268
        break;
4269
      case bfd_arch_powerpc:
4270
        if (bfd_get_mach (abfd) == bfd_mach_ppc)
4271
    internal_a.o_cputype = 3;
4272
        else if (bfd_get_mach (abfd) == bfd_mach_ppc_620)
4273
    internal_a.o_cputype = 2;
4274
        else
4275
    internal_a.o_cputype = 1;
4276
        break;
4277
      default:
4278
        abort ();
4279
      }
4280
  }
4281
      internal_a.o_maxstack = xcoff_data (abfd)->maxstack;
4282
      internal_a.o_maxdata = xcoff_data (abfd)->maxdata;
4283
    }
4284
#endif
4285
4286
3
#ifdef COFF_WITH_PE
4287
3
  {
4288
    /* After object contents are finalized so we can compute a reasonable hash,
4289
       but before header is written so we can update it to point to debug directory.  */
4290
3
    struct pe_tdata *pe = pe_data (abfd);
4291
4292
3
    if (pe->build_id.after_write_object_contents != NULL)
4293
0
      (*pe->build_id.after_write_object_contents) (abfd);
4294
3
  }
4295
3
#endif
4296
4297
  /* Now write header.  */
4298
3
  if (bfd_seek (abfd, 0, SEEK_SET) != 0)
4299
0
    return false;
4300
4301
3
  {
4302
3
    char * buff;
4303
3
    bfd_size_type amount = bfd_coff_filhsz (abfd);
4304
4305
3
    buff = (char *) bfd_malloc (amount);
4306
3
    if (buff == NULL)
4307
0
      return false;
4308
4309
3
    bfd_coff_swap_filehdr_out (abfd, & internal_f, buff);
4310
3
    amount = bfd_write (buff, amount, abfd);
4311
4312
3
    free (buff);
4313
4314
3
    if (amount != bfd_coff_filhsz (abfd))
4315
0
      return false;
4316
3
  }
4317
4318
3
  if (abfd->flags & EXEC_P)
4319
3
    {
4320
      /* Note that peicode.h fills in a PEAOUTHDR, not an AOUTHDR.
4321
   include/coff/pe.h sets AOUTSZ == sizeof (PEAOUTHDR)).  */
4322
3
      char * buff;
4323
3
      bfd_size_type amount = bfd_coff_aoutsz (abfd);
4324
4325
3
      buff = (char *) bfd_malloc (amount);
4326
3
      if (buff == NULL)
4327
0
  return false;
4328
4329
3
      coff_swap_aouthdr_out (abfd, & internal_a, buff);
4330
3
      amount = bfd_write (buff, amount, abfd);
4331
4332
3
      free (buff);
4333
4334
3
      if (amount != bfd_coff_aoutsz (abfd))
4335
0
  return false;
4336
4337
3
#ifdef COFF_IMAGE_WITH_PE
4338
3
      if (! coff_apply_checksum (abfd))
4339
0
  return false;
4340
3
#endif
4341
3
    }
4342
#ifdef RS6000COFF_C
4343
#ifndef XCOFF64
4344
  else
4345
    {
4346
      AOUTHDR buff;
4347
      size_t size;
4348
4349
      /* XCOFF32 seems to always write at least a small a.out header.  */
4350
      coff_swap_aouthdr_out (abfd, & internal_a, & buff);
4351
      if (xcoff_data (abfd)->full_aouthdr)
4352
  size = bfd_coff_aoutsz (abfd);
4353
      else
4354
  size = SMALL_AOUTSZ;
4355
      if (bfd_write (&buff, size, abfd) != size)
4356
  return false;
4357
    }
4358
#endif
4359
#endif
4360
4361
3
  return true;
4362
3
}
pe-x86_64.c:coff_write_object_contents
Line
Count
Source
3486
1
{
3487
1
  asection *current;
3488
1
  bool hasrelocs = false;
3489
1
  bool haslinno = false;
3490
#ifdef COFF_IMAGE_WITH_PE
3491
  bool hasdebug = false;
3492
#endif
3493
1
  file_ptr scn_base;
3494
1
  file_ptr reloc_base;
3495
1
  file_ptr lineno_base;
3496
1
  file_ptr sym_base;
3497
1
  unsigned long reloc_size = 0, reloc_count = 0;
3498
1
  unsigned long lnno_size = 0;
3499
1
  bool long_section_names;
3500
1
  asection *text_sec = NULL;
3501
1
  asection *data_sec = NULL;
3502
1
  asection *bss_sec = NULL;
3503
#ifdef RS6000COFF_C
3504
  asection *tdata_sec = NULL;
3505
  asection *tbss_sec = NULL;
3506
#endif
3507
1
  struct internal_filehdr internal_f;
3508
1
  struct internal_aouthdr internal_a;
3509
1
#ifdef COFF_LONG_SECTION_NAMES
3510
1
  size_t string_size = STRING_SIZE_SIZE;
3511
1
#endif
3512
3513
1
  bfd_set_error (bfd_error_system_call);
3514
3515
  /* Make a pass through the symbol table to count line number entries and
3516
     put them into the correct asections.  */
3517
1
  lnno_size = coff_count_linenumbers (abfd) * bfd_coff_linesz (abfd);
3518
3519
1
  if (! abfd->output_has_begun)
3520
1
    {
3521
1
      if (! coff_compute_section_file_positions (abfd))
3522
0
  return false;
3523
1
    }
3524
3525
1
  reloc_base = obj_relocbase (abfd);
3526
3527
  /* Work out the size of the reloc and linno areas.  */
3528
3529
1
  for (current = abfd->sections; current != NULL; current =
3530
0
       current->next)
3531
0
    {
3532
0
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3533
      /* We store the actual reloc count in the first reloc's addr.  */
3534
0
      if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3535
0
  reloc_count ++;
3536
0
#endif
3537
0
      reloc_count += current->reloc_count;
3538
0
    }
3539
3540
1
  reloc_size = reloc_count * bfd_coff_relsz (abfd);
3541
3542
1
  lineno_base = reloc_base + reloc_size;
3543
1
  sym_base = lineno_base + lnno_size;
3544
3545
  /* Indicate in each section->line_filepos its actual file address.  */
3546
1
  for (current = abfd->sections; current != NULL; current =
3547
0
       current->next)
3548
0
    {
3549
0
      if (current->lineno_count)
3550
0
  {
3551
0
    current->line_filepos = lineno_base;
3552
0
    current->moving_line_filepos = lineno_base;
3553
0
    lineno_base += current->lineno_count * bfd_coff_linesz (abfd);
3554
0
  }
3555
0
      else
3556
0
  current->line_filepos = 0;
3557
3558
0
      if (current->reloc_count)
3559
0
  {
3560
0
    current->rel_filepos = reloc_base;
3561
0
    reloc_base += current->reloc_count * bfd_coff_relsz (abfd);
3562
0
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3563
    /* Extra reloc to hold real count.  */
3564
0
    if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3565
0
      reloc_base += bfd_coff_relsz (abfd);
3566
0
#endif
3567
0
  }
3568
0
      else
3569
0
  current->rel_filepos = 0;
3570
0
    }
3571
3572
  /* Write section headers to the file.  */
3573
1
  internal_f.f_nscns = 0;
3574
3575
1
  if ((abfd->flags & EXEC_P) != 0)
3576
0
    scn_base = bfd_coff_filhsz (abfd) + bfd_coff_aoutsz (abfd);
3577
1
  else
3578
1
    {
3579
1
      scn_base = bfd_coff_filhsz (abfd);
3580
#ifdef RS6000COFF_C
3581
#ifndef XCOFF64
3582
      if (xcoff_data (abfd)->full_aouthdr)
3583
  scn_base += bfd_coff_aoutsz (abfd);
3584
      else
3585
  scn_base += SMALL_AOUTSZ;
3586
#endif
3587
#endif
3588
1
    }
3589
3590
1
  if (bfd_seek (abfd, scn_base, SEEK_SET) != 0)
3591
0
    return false;
3592
3593
1
  long_section_names = false;
3594
1
  for (current = abfd->sections;
3595
1
       current != NULL;
3596
1
       current = current->next)
3597
0
    {
3598
0
      struct internal_scnhdr section;
3599
#ifdef COFF_IMAGE_WITH_PE
3600
      bool is_reloc_section = false;
3601
3602
      if (strcmp (current->name, DOT_RELOC) == 0)
3603
  {
3604
    is_reloc_section = true;
3605
    hasrelocs = true;
3606
    pe_data (abfd)->has_reloc_section = 1;
3607
  }
3608
#endif
3609
3610
0
      internal_f.f_nscns++;
3611
3612
0
      strncpy (section.s_name, current->name, SCNNMLEN);
3613
3614
0
#ifdef COFF_LONG_SECTION_NAMES
3615
      /* Handle long section names as in PE.  This must be compatible
3616
   with the code in coff_write_symbols and _bfd_coff_final_link.  */
3617
0
      if (bfd_coff_long_section_names (abfd))
3618
0
  {
3619
0
    size_t len;
3620
3621
0
    len = strlen (current->name);
3622
0
    if (len > SCNNMLEN)
3623
0
      {
3624
3625
        /* An inherent limitation of the /nnnnnnn notation used to indicate
3626
     the offset of the long name in the string table is that we
3627
     cannot address entries beyone the ten million byte boundary.  */
3628
0
        if (string_size < 10000000)
3629
0
    {
3630
      /* The s_name field is defined to be NUL-padded but need not
3631
         be NUL-terminated.  We use a temporary buffer so that we
3632
         can still sprintf all eight chars without splatting a
3633
         terminating NUL over the first byte of the following
3634
         member (s_paddr).  */
3635
      /* PR 21096: The +20 is to stop a bogus warning from gcc7
3636
         about a possible buffer overflow.  */
3637
0
      char s_name_buf[SCNNMLEN + 1 + 20];
3638
3639
      /* We do not need to use snprintf here as we have already
3640
         verified that string_size is not too big, plus we have
3641
         an overlarge buffer, just in case.  */
3642
0
      sprintf (s_name_buf, "/%lu", (unsigned long) string_size);
3643
      /* Then strncpy takes care of any padding for us.  */
3644
0
      strncpy (section.s_name, s_name_buf, SCNNMLEN);
3645
0
    }
3646
0
        else
3647
0
#ifdef COFF_WITH_PE
3648
0
    {
3649
      /* PE use a base 64 encoding for long section names whose
3650
         index is very large.  But contrary to RFC 4648, there is
3651
         no padding: 6 characters must be generated.  */
3652
0
      static const char base64[] =
3653
0
        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
3654
0
        "abcdefghijklmnopqrstuvwxyz"
3655
0
        "0123456789+/";
3656
0
      unsigned long off = string_size;
3657
0
      unsigned i;
3658
3659
0
      section.s_name[0] = '/';
3660
0
      section.s_name[1] = '/';
3661
0
      for (i = SCNNMLEN - 1; i >= 2; i--)
3662
0
        {
3663
0
          section.s_name[i] = base64[off & 0x3f];
3664
0
          off >>= 6;
3665
0
        }
3666
0
    }
3667
0
#endif
3668
0
        if (string_size > 0xffffffffUL - (len + 1)
3669
#ifndef COFF_WITH_PE
3670
      || string_size >= 10000000
3671
#endif
3672
0
      )
3673
0
    {
3674
0
      bfd_set_error (bfd_error_file_too_big);
3675
0
      _bfd_error_handler
3676
        /* xgettext:c-format */
3677
0
        (_("%pB: section %pA: string table overflow at offset %ld"),
3678
0
        abfd, current, (unsigned long) string_size);
3679
0
      return false;
3680
0
    }
3681
3682
0
        string_size += len + 1;
3683
0
        long_section_names = true;
3684
0
      }
3685
0
  }
3686
0
#endif
3687
3688
0
#ifdef _LIB
3689
      /* Always set s_vaddr of .lib to 0.  This is right for SVR3.2
3690
   Ian Taylor <ian@cygnus.com>.  */
3691
0
      if (strcmp (current->name, _LIB) == 0)
3692
0
  section.s_vaddr = 0;
3693
0
      else
3694
0
#endif
3695
0
      section.s_vaddr = current->vma;
3696
0
      section.s_paddr = current->lma;
3697
0
      section.s_size =  current->size;
3698
#ifdef coff_get_section_load_page
3699
      section.s_page = coff_get_section_load_page (current);
3700
#else
3701
0
      section.s_page = 0;
3702
0
#endif
3703
3704
0
#ifdef COFF_WITH_PE
3705
0
      section.s_paddr = 0;
3706
0
#endif
3707
#ifdef COFF_IMAGE_WITH_PE
3708
      /* Reminder: s_paddr holds the virtual size of the section.  */
3709
      if (coff_section_data (abfd, current) != NULL
3710
    && pei_section_data (abfd, current) != NULL)
3711
  section.s_paddr = pei_section_data (abfd, current)->virt_size;
3712
      else
3713
  section.s_paddr = 0;
3714
#endif
3715
3716
      /* If this section has no size or is unloadable then the scnptr
3717
   will be 0 too.  */
3718
0
      if (current->size == 0
3719
0
    || (current->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
3720
0
  section.s_scnptr = 0;
3721
0
      else
3722
0
  section.s_scnptr = current->filepos;
3723
3724
0
      section.s_relptr = current->rel_filepos;
3725
0
      section.s_lnnoptr = current->line_filepos;
3726
0
      section.s_nreloc = current->reloc_count;
3727
0
      section.s_nlnno = current->lineno_count;
3728
0
#ifndef COFF_IMAGE_WITH_PE
3729
      /* In PEI, relocs come in the .reloc section.  */
3730
0
      if (current->reloc_count != 0)
3731
0
  hasrelocs = true;
3732
0
#endif
3733
0
      if (current->lineno_count != 0)
3734
0
  haslinno = true;
3735
#ifdef COFF_IMAGE_WITH_PE
3736
      if ((current->flags & SEC_DEBUGGING) != 0
3737
    && ! is_reloc_section)
3738
  hasdebug = true;
3739
#endif
3740
3741
#ifdef RS6000COFF_C
3742
#ifndef XCOFF64
3743
      /* Indicate the use of an XCOFF overflow section header.  */
3744
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3745
  {
3746
    section.s_nreloc = 0xffff;
3747
    section.s_nlnno = 0xffff;
3748
  }
3749
#endif
3750
#endif
3751
3752
0
      section.s_flags = sec_to_styp_flags (current->name, current->flags);
3753
3754
0
      if (!strcmp (current->name, _TEXT))
3755
0
  text_sec = current;
3756
0
      else if (!strcmp (current->name, _DATA))
3757
0
  data_sec = current;
3758
0
      else if (!strcmp (current->name, _BSS))
3759
0
  bss_sec = current;
3760
#ifdef RS6000COFF_C
3761
      else if (!strcmp (current->name, _TDATA))
3762
  tdata_sec = current;
3763
      else if (!strcmp (current->name, _TBSS))
3764
  tbss_sec = current;
3765
#endif
3766
3767
3768
0
#ifdef COFF_ENCODE_ALIGNMENT
3769
0
      if (COFF_ENCODE_ALIGNMENT (abfd, section, current->alignment_power)
3770
0
    && (COFF_DECODE_ALIGNMENT (section.s_flags)
3771
0
        != current->alignment_power))
3772
0
  {
3773
0
    bool warn = (coff_data (abfd)->link_info
3774
0
           && !bfd_link_relocatable (coff_data (abfd)->link_info));
3775
3776
0
    _bfd_error_handler
3777
      /* xgettext:c-format */
3778
0
      (_("%pB:%s section %s: alignment 2**%u not representable"),
3779
0
       abfd, warn ? " warning:" : "", current->name,
3780
0
       current->alignment_power);
3781
0
    if (!warn)
3782
0
      {
3783
0
        bfd_set_error (bfd_error_nonrepresentable_section);
3784
0
        return false;
3785
0
      }
3786
0
  }
3787
0
#endif
3788
3789
#ifdef COFF_IMAGE_WITH_PE
3790
      /* Suppress output of the sections if they are null.  ld
3791
   includes the bss and data sections even if there is no size
3792
   assigned to them.  NT loader doesn't like it if these section
3793
   headers are included if the sections themselves are not
3794
   needed.  See also coff_compute_section_file_positions.  */
3795
      if (section.s_size == 0)
3796
  internal_f.f_nscns--;
3797
      else
3798
#endif
3799
0
  {
3800
0
    SCNHDR buff;
3801
0
    bfd_size_type amt = bfd_coff_scnhsz (abfd);
3802
3803
0
    if (bfd_coff_swap_scnhdr_out (abfd, &section, &buff) == 0
3804
0
        || bfd_write (& buff, amt, abfd) != amt)
3805
0
      return false;
3806
0
  }
3807
3808
0
#ifdef COFF_WITH_PE
3809
      /* PE stores COMDAT section information in the symbol table.  If
3810
   this section is supposed to have some COMDAT info, track down
3811
   the symbol in the symbol table and modify it.  */
3812
0
      if ((current->flags & SEC_LINK_ONCE) != 0)
3813
0
  {
3814
0
    unsigned int i, count;
3815
0
    asymbol **psym;
3816
0
    coff_symbol_type *csym = NULL;
3817
0
    asymbol **psymsec;
3818
3819
0
    psymsec = NULL;
3820
0
    count = bfd_get_symcount (abfd);
3821
0
    for (i = 0, psym = abfd->outsymbols; i < count; i++, psym++)
3822
0
      {
3823
0
        if ((*psym)->section != current)
3824
0
    continue;
3825
3826
        /* Remember the location of the first symbol in this
3827
     section.  */
3828
0
        if (psymsec == NULL)
3829
0
    psymsec = psym;
3830
3831
        /* See if this is the section symbol.  */
3832
0
        if (strcmp ((*psym)->name, current->name) == 0)
3833
0
    {
3834
0
      csym = coff_symbol_from (*psym);
3835
0
      if (csym == NULL
3836
0
          || csym->native == NULL
3837
0
          || ! csym->native->is_sym
3838
0
          || csym->native->u.syment.n_numaux < 1
3839
0
          || csym->native->u.syment.n_sclass != C_STAT
3840
0
          || csym->native->u.syment.n_type != T_NULL)
3841
0
        continue;
3842
3843
      /* Here *PSYM is the section symbol for CURRENT.  */
3844
3845
0
      break;
3846
0
    }
3847
0
      }
3848
3849
    /* Did we find it?
3850
       Note that we might not if we're converting the file from
3851
       some other object file format.  */
3852
0
    if (i < count)
3853
0
      {
3854
0
        combined_entry_type *aux;
3855
3856
        /* We don't touch the x_checksum field.  The
3857
     x_associated field is not currently supported.  */
3858
3859
0
        aux = csym->native + 1;
3860
0
        BFD_ASSERT (! aux->is_sym);
3861
0
        switch (current->flags & SEC_LINK_DUPLICATES)
3862
0
    {
3863
0
    case SEC_LINK_DUPLICATES_DISCARD:
3864
0
      aux->u.auxent.x_scn.x_comdat = IMAGE_COMDAT_SELECT_ANY;
3865
0
      break;
3866
3867
0
    case SEC_LINK_DUPLICATES_ONE_ONLY:
3868
0
      aux->u.auxent.x_scn.x_comdat =
3869
0
        IMAGE_COMDAT_SELECT_NODUPLICATES;
3870
0
      break;
3871
3872
0
    case SEC_LINK_DUPLICATES_SAME_SIZE:
3873
0
      aux->u.auxent.x_scn.x_comdat =
3874
0
        IMAGE_COMDAT_SELECT_SAME_SIZE;
3875
0
      break;
3876
3877
0
    case SEC_LINK_DUPLICATES_SAME_CONTENTS:
3878
0
      aux->u.auxent.x_scn.x_comdat =
3879
0
        IMAGE_COMDAT_SELECT_EXACT_MATCH;
3880
0
      break;
3881
0
    }
3882
3883
        /* The COMDAT symbol must be the first symbol from this
3884
     section in the symbol table.  In order to make this
3885
     work, we move the COMDAT symbol before the first
3886
     symbol we found in the search above.  It's OK to
3887
     rearrange the symbol table at this point, because
3888
     coff_renumber_symbols is going to rearrange it
3889
     further and fix up all the aux entries.  */
3890
0
        if (psym != psymsec)
3891
0
    {
3892
0
      asymbol *hold;
3893
0
      asymbol **pcopy;
3894
3895
0
      hold = *psym;
3896
0
      for (pcopy = psym; pcopy > psymsec; pcopy--)
3897
0
        pcopy[0] = pcopy[-1];
3898
0
      *psymsec = hold;
3899
0
    }
3900
0
      }
3901
0
  }
3902
0
#endif /* COFF_WITH_PE */
3903
0
    }
3904
3905
#ifdef RS6000COFF_C
3906
#ifndef XCOFF64
3907
  /* XCOFF handles overflows in the reloc and line number count fields
3908
     by creating a new section header to hold the correct values.  */
3909
  for (current = abfd->sections; current != NULL; current = current->next)
3910
    {
3911
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3912
  {
3913
    struct internal_scnhdr scnhdr;
3914
    SCNHDR buff;
3915
    bfd_size_type amt;
3916
3917
    internal_f.f_nscns++;
3918
    memcpy (scnhdr.s_name, ".ovrflo", 8);
3919
    scnhdr.s_paddr = current->reloc_count;
3920
    scnhdr.s_vaddr = current->lineno_count;
3921
    scnhdr.s_size = 0;
3922
    scnhdr.s_scnptr = 0;
3923
    scnhdr.s_relptr = current->rel_filepos;
3924
    scnhdr.s_lnnoptr = current->line_filepos;
3925
    scnhdr.s_nreloc = current->target_index;
3926
    scnhdr.s_nlnno = current->target_index;
3927
    scnhdr.s_flags = STYP_OVRFLO;
3928
    amt = bfd_coff_scnhsz (abfd);
3929
    if (bfd_coff_swap_scnhdr_out (abfd, &scnhdr, &buff) == 0
3930
        || bfd_write (& buff, amt, abfd) != amt)
3931
      return false;
3932
  }
3933
    }
3934
#endif
3935
#endif
3936
3937
#if defined (COFF_GO32_EXE) || defined (COFF_GO32)
3938
  /* Pad section headers.  */
3939
  if ((abfd->flags & EXEC_P) != 0)
3940
    {
3941
      asection *s = abfd->sections;
3942
      while (s != NULL && s->filepos == 0)
3943
  s = s->next;
3944
      if (s != NULL)
3945
  {
3946
    file_ptr cur_ptr
3947
      = scn_base + abfd->section_count * bfd_coff_scnhsz (abfd);
3948
    file_ptr fill_size = s->filepos - cur_ptr;
3949
    if (fill_size > 0)
3950
      {
3951
        bfd_byte *b = bfd_zmalloc (fill_size);
3952
        if (!b)
3953
    return false;
3954
        if (bfd_write (b, fill_size, abfd) != (ufile_ptr) fill_size)
3955
    {
3956
      free (b);
3957
      return false;
3958
    }
3959
        free (b);
3960
      }
3961
  }
3962
    }
3963
#endif
3964
3965
  /* OK, now set up the filehdr...  */
3966
3967
  /* Don't include the internal abs section in the section count */
3968
3969
  /* We will NOT put a fucking timestamp in the header here. Every time you
3970
     put it back, I will come in and take it out again.  I'm sorry.  This
3971
     field does not belong here.  We fill it with a 0 so it compares the
3972
     same but is not a reasonable time. -- gnu@cygnus.com  */
3973
1
  internal_f.f_timdat = 0;
3974
1
  internal_f.f_flags = 0;
3975
3976
1
  if (abfd->flags & EXEC_P)
3977
0
    internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3978
1
  else
3979
1
    {
3980
1
      internal_f.f_opthdr = 0;
3981
#ifdef RS6000COFF_C
3982
#ifndef XCOFF64
3983
      if (xcoff_data (abfd)->full_aouthdr)
3984
  internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3985
      else
3986
  internal_f.f_opthdr = SMALL_AOUTSZ;
3987
#endif
3988
#endif
3989
1
    }
3990
3991
1
  if (!hasrelocs)
3992
1
    internal_f.f_flags |= F_RELFLG;
3993
1
  if (!haslinno)
3994
1
    internal_f.f_flags |= F_LNNO;
3995
1
  if (abfd->flags & EXEC_P)
3996
0
    internal_f.f_flags |= F_EXEC;
3997
#ifdef COFF_IMAGE_WITH_PE
3998
  if (! hasdebug)
3999
    internal_f.f_flags |= IMAGE_FILE_DEBUG_STRIPPED;
4000
  if (pe_data (abfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
4001
    internal_f.f_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
4002
#endif
4003
4004
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
4005
#ifdef COFF_WITH_PE
4006
  internal_f.f_flags |= IMAGE_FILE_32BIT_MACHINE;
4007
#else
4008
  if (bfd_little_endian (abfd))
4009
    internal_f.f_flags |= F_AR32WR;
4010
  else
4011
    internal_f.f_flags |= F_AR32W;
4012
#endif
4013
#endif
4014
4015
#ifdef TI_TARGET_ID
4016
  /* Target id is used in TI COFF v1 and later; COFF0 won't use this field,
4017
     but it doesn't hurt to set it internally.  */
4018
  internal_f.f_target_id = TI_TARGET_ID;
4019
#endif
4020
4021
  /* FIXME, should do something about the other byte orders and
4022
     architectures.  */
4023
4024
#ifdef RS6000COFF_C
4025
  if ((abfd->flags & DYNAMIC) != 0)
4026
    internal_f.f_flags |= F_SHROBJ;
4027
  if (bfd_get_section_by_name (abfd, _LOADER) != NULL)
4028
    internal_f.f_flags |= F_DYNLOAD;
4029
#endif
4030
4031
1
  memset (&internal_a, 0, sizeof internal_a);
4032
4033
  /* Set up architecture-dependent stuff.  */
4034
1
  {
4035
1
    unsigned int magic = 0;
4036
1
    unsigned short flags = 0;
4037
4038
1
    coff_set_flags (abfd, &magic, &flags);
4039
1
    internal_f.f_magic = magic;
4040
1
    internal_f.f_flags |= flags;
4041
    /* ...and the "opt"hdr...  */
4042
4043
#ifdef TICOFF_AOUT_MAGIC
4044
    internal_a.magic = TICOFF_AOUT_MAGIC;
4045
#define __A_MAGIC_SET__
4046
#endif
4047
4048
#if defined(ARM)
4049
#define __A_MAGIC_SET__
4050
    internal_a.magic = ZMAGIC;
4051
#endif
4052
4053
#if defined(AARCH64)
4054
#define __A_MAGIC_SET__
4055
    internal_a.magic = ZMAGIC;
4056
#endif
4057
4058
#if defined(LOONGARCH64)
4059
#define __A_MAGIC_SET__
4060
    internal_a.magic = ZMAGIC;
4061
#endif
4062
4063
#if defined MCORE_PE
4064
#define __A_MAGIC_SET__
4065
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR_MAGIC;
4066
#endif
4067
4068
1
#if defined(I386)
4069
1
#define __A_MAGIC_SET__
4070
#if defined LYNXOS
4071
    internal_a.magic = LYNXCOFFMAGIC;
4072
#elif defined AMD64
4073
1
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR64_MAGIC;
4074
#else
4075
    internal_a.magic = ZMAGIC;
4076
#endif
4077
1
#endif /* I386 */
4078
4079
#if defined(IA64)
4080
#define __A_MAGIC_SET__
4081
    internal_a.magic = PE32PMAGIC;
4082
#endif /* IA64 */
4083
4084
#if defined(SPARC)
4085
#define __A_MAGIC_SET__
4086
#if defined(LYNXOS)
4087
    internal_a.magic = LYNXCOFFMAGIC;
4088
#endif /* LYNXOS */
4089
#endif /* SPARC */
4090
4091
#ifdef RS6000COFF_C
4092
#define __A_MAGIC_SET__
4093
    internal_a.magic = (abfd->flags & D_PAGED) ? RS6K_AOUTHDR_ZMAGIC :
4094
    (abfd->flags & WP_TEXT) ? RS6K_AOUTHDR_NMAGIC :
4095
    RS6K_AOUTHDR_OMAGIC;
4096
#endif
4097
4098
#if defined(SH) && defined(COFF_WITH_PE)
4099
#define __A_MAGIC_SET__
4100
    internal_a.magic = SH_PE_MAGIC;
4101
#endif
4102
4103
#if defined(MIPS) && defined(COFF_WITH_PE)
4104
#define __A_MAGIC_SET__
4105
    internal_a.magic = MIPS_PE_MAGIC;
4106
#endif
4107
4108
#ifndef __A_MAGIC_SET__
4109
#include "Your aouthdr magic number is not being set!"
4110
#else
4111
1
#undef __A_MAGIC_SET__
4112
1
#endif
4113
1
  }
4114
4115
#ifdef RS6000COFF_C
4116
  /* XCOFF 32bit needs this to have new behaviour for n_type field.  */
4117
  internal_a.vstamp = 2;
4118
#else
4119
  /* FIXME: Does anybody ever set this to another value?  */
4120
1
  internal_a.vstamp = 0;
4121
1
#endif
4122
4123
  /* Now should write relocs, strings, syms.  */
4124
1
  obj_sym_filepos (abfd) = sym_base;
4125
4126
1
  if (bfd_get_symcount (abfd) != 0)
4127
0
    {
4128
0
      int firstundef;
4129
4130
0
      if (!coff_renumber_symbols (abfd, &firstundef))
4131
0
  return false;
4132
0
      coff_mangle_symbols (abfd);
4133
0
      if (! coff_write_symbols (abfd))
4134
0
  return false;
4135
0
      if (! coff_write_linenumbers (abfd))
4136
0
  return false;
4137
0
      if (! coff_write_relocs (abfd, firstundef))
4138
0
  return false;
4139
0
    }
4140
1
#ifdef COFF_LONG_SECTION_NAMES
4141
1
  else if (long_section_names && ! obj_coff_strings_written (abfd))
4142
0
    {
4143
      /* If we have long section names we have to write out the string
4144
   table even if there are no symbols.  */
4145
0
      if (! coff_write_symbols (abfd))
4146
0
  return false;
4147
0
    }
4148
1
#endif
4149
  /* If bfd_get_symcount (abfd) != 0, then we are not using the COFF
4150
     backend linker, and obj_raw_syment_count is not valid until after
4151
     coff_write_symbols is called.  */
4152
1
  if (obj_raw_syment_count (abfd) != 0)
4153
0
    {
4154
0
      internal_f.f_symptr = sym_base;
4155
#ifdef RS6000COFF_C
4156
      /* AIX appears to require that F_RELFLG not be set if there are
4157
   local symbols but no relocations.  */
4158
      internal_f.f_flags &=~ F_RELFLG;
4159
#endif
4160
0
    }
4161
1
  else
4162
1
    {
4163
1
      if (long_section_names)
4164
0
  internal_f.f_symptr = sym_base;
4165
1
      else
4166
1
  internal_f.f_symptr = 0;
4167
1
      internal_f.f_flags |= F_LSYMS;
4168
1
    }
4169
4170
1
  if (text_sec)
4171
0
    {
4172
0
      internal_a.tsize = text_sec->size;
4173
0
      internal_a.text_start = internal_a.tsize ? text_sec->vma : 0;
4174
0
    }
4175
1
  if (data_sec)
4176
0
    {
4177
0
      internal_a.dsize = data_sec->size;
4178
0
      internal_a.data_start = internal_a.dsize ? data_sec->vma : 0;
4179
0
    }
4180
1
  if (bss_sec)
4181
0
    {
4182
0
      internal_a.bsize = bss_sec->size;
4183
0
      if (internal_a.bsize && bss_sec->vma < internal_a.data_start)
4184
0
  internal_a.data_start = bss_sec->vma;
4185
0
    }
4186
4187
1
  internal_a.entry = bfd_get_start_address (abfd);
4188
1
  internal_f.f_nsyms = obj_raw_syment_count (abfd);
4189
4190
#ifdef RS6000COFF_C
4191
  if (xcoff_data (abfd)->full_aouthdr)
4192
    {
4193
      bfd_vma toc;
4194
      asection *loader_sec;
4195
4196
      internal_a.vstamp = 2;
4197
4198
      internal_a.o_snentry = xcoff_data (abfd)->snentry;
4199
      if (internal_a.o_snentry == 0)
4200
  internal_a.entry = (bfd_vma) -1;
4201
4202
      if (text_sec != NULL)
4203
  {
4204
    internal_a.o_sntext = text_sec->target_index;
4205
    internal_a.o_algntext = bfd_section_alignment (text_sec);
4206
  }
4207
      else
4208
  {
4209
    internal_a.o_sntext = 0;
4210
    internal_a.o_algntext = 0;
4211
  }
4212
      if (data_sec != NULL)
4213
  {
4214
    internal_a.o_sndata = data_sec->target_index;
4215
    internal_a.o_algndata = bfd_section_alignment (data_sec);
4216
  }
4217
      else
4218
  {
4219
    internal_a.o_sndata = 0;
4220
    internal_a.o_algndata = 0;
4221
  }
4222
      loader_sec = bfd_get_section_by_name (abfd, ".loader");
4223
      if (loader_sec != NULL)
4224
  internal_a.o_snloader = loader_sec->target_index;
4225
      else
4226
  internal_a.o_snloader = 0;
4227
      if (bss_sec != NULL)
4228
  internal_a.o_snbss = bss_sec->target_index;
4229
      else
4230
  internal_a.o_snbss = 0;
4231
4232
      if (tdata_sec != NULL)
4233
  {
4234
    internal_a.o_sntdata = tdata_sec->target_index;
4235
    /* TODO: o_flags should be set to RS6K_AOUTHDR_TLS_LE
4236
       if there is at least one R_TLS_LE relocations.  */
4237
    internal_a.o_flags = 0;
4238
#ifdef XCOFF64
4239
    internal_a.o_x64flags = 0;
4240
#endif
4241
  }
4242
      else
4243
  {
4244
    internal_a.o_sntdata = 0;
4245
    internal_a.o_flags = 0;
4246
#ifdef XCOFF64
4247
    internal_a.o_x64flags = 0;
4248
#endif
4249
  }
4250
      if (tbss_sec != NULL)
4251
    internal_a.o_sntbss = tbss_sec->target_index;
4252
      else
4253
    internal_a.o_sntbss = 0;
4254
4255
      toc = xcoff_data (abfd)->toc;
4256
      internal_a.o_toc = toc;
4257
      internal_a.o_sntoc = xcoff_data (abfd)->sntoc;
4258
4259
      internal_a.o_modtype = xcoff_data (abfd)->modtype;
4260
      if (xcoff_data (abfd)->cputype != -1)
4261
  internal_a.o_cputype = xcoff_data (abfd)->cputype;
4262
      else
4263
  {
4264
    switch (bfd_get_arch (abfd))
4265
      {
4266
      case bfd_arch_rs6000:
4267
        internal_a.o_cputype = 4;
4268
        break;
4269
      case bfd_arch_powerpc:
4270
        if (bfd_get_mach (abfd) == bfd_mach_ppc)
4271
    internal_a.o_cputype = 3;
4272
        else if (bfd_get_mach (abfd) == bfd_mach_ppc_620)
4273
    internal_a.o_cputype = 2;
4274
        else
4275
    internal_a.o_cputype = 1;
4276
        break;
4277
      default:
4278
        abort ();
4279
      }
4280
  }
4281
      internal_a.o_maxstack = xcoff_data (abfd)->maxstack;
4282
      internal_a.o_maxdata = xcoff_data (abfd)->maxdata;
4283
    }
4284
#endif
4285
4286
1
#ifdef COFF_WITH_PE
4287
1
  {
4288
    /* After object contents are finalized so we can compute a reasonable hash,
4289
       but before header is written so we can update it to point to debug directory.  */
4290
1
    struct pe_tdata *pe = pe_data (abfd);
4291
4292
1
    if (pe->build_id.after_write_object_contents != NULL)
4293
0
      (*pe->build_id.after_write_object_contents) (abfd);
4294
1
  }
4295
1
#endif
4296
4297
  /* Now write header.  */
4298
1
  if (bfd_seek (abfd, 0, SEEK_SET) != 0)
4299
0
    return false;
4300
4301
1
  {
4302
1
    char * buff;
4303
1
    bfd_size_type amount = bfd_coff_filhsz (abfd);
4304
4305
1
    buff = (char *) bfd_malloc (amount);
4306
1
    if (buff == NULL)
4307
0
      return false;
4308
4309
1
    bfd_coff_swap_filehdr_out (abfd, & internal_f, buff);
4310
1
    amount = bfd_write (buff, amount, abfd);
4311
4312
1
    free (buff);
4313
4314
1
    if (amount != bfd_coff_filhsz (abfd))
4315
0
      return false;
4316
1
  }
4317
4318
1
  if (abfd->flags & EXEC_P)
4319
0
    {
4320
      /* Note that peicode.h fills in a PEAOUTHDR, not an AOUTHDR.
4321
   include/coff/pe.h sets AOUTSZ == sizeof (PEAOUTHDR)).  */
4322
0
      char * buff;
4323
0
      bfd_size_type amount = bfd_coff_aoutsz (abfd);
4324
4325
0
      buff = (char *) bfd_malloc (amount);
4326
0
      if (buff == NULL)
4327
0
  return false;
4328
4329
0
      coff_swap_aouthdr_out (abfd, & internal_a, buff);
4330
0
      amount = bfd_write (buff, amount, abfd);
4331
4332
0
      free (buff);
4333
4334
0
      if (amount != bfd_coff_aoutsz (abfd))
4335
0
  return false;
4336
4337
#ifdef COFF_IMAGE_WITH_PE
4338
      if (! coff_apply_checksum (abfd))
4339
  return false;
4340
#endif
4341
0
    }
4342
#ifdef RS6000COFF_C
4343
#ifndef XCOFF64
4344
  else
4345
    {
4346
      AOUTHDR buff;
4347
      size_t size;
4348
4349
      /* XCOFF32 seems to always write at least a small a.out header.  */
4350
      coff_swap_aouthdr_out (abfd, & internal_a, & buff);
4351
      if (xcoff_data (abfd)->full_aouthdr)
4352
  size = bfd_coff_aoutsz (abfd);
4353
      else
4354
  size = SMALL_AOUTSZ;
4355
      if (bfd_write (&buff, size, abfd) != size)
4356
  return false;
4357
    }
4358
#endif
4359
#endif
4360
4361
1
  return true;
4362
1
}
pei-x86_64.c:coff_write_object_contents
Line
Count
Source
3486
8
{
3487
8
  asection *current;
3488
8
  bool hasrelocs = false;
3489
8
  bool haslinno = false;
3490
8
#ifdef COFF_IMAGE_WITH_PE
3491
8
  bool hasdebug = false;
3492
8
#endif
3493
8
  file_ptr scn_base;
3494
8
  file_ptr reloc_base;
3495
8
  file_ptr lineno_base;
3496
8
  file_ptr sym_base;
3497
8
  unsigned long reloc_size = 0, reloc_count = 0;
3498
8
  unsigned long lnno_size = 0;
3499
8
  bool long_section_names;
3500
8
  asection *text_sec = NULL;
3501
8
  asection *data_sec = NULL;
3502
8
  asection *bss_sec = NULL;
3503
#ifdef RS6000COFF_C
3504
  asection *tdata_sec = NULL;
3505
  asection *tbss_sec = NULL;
3506
#endif
3507
8
  struct internal_filehdr internal_f;
3508
8
  struct internal_aouthdr internal_a;
3509
8
#ifdef COFF_LONG_SECTION_NAMES
3510
8
  size_t string_size = STRING_SIZE_SIZE;
3511
8
#endif
3512
3513
8
  bfd_set_error (bfd_error_system_call);
3514
3515
  /* Make a pass through the symbol table to count line number entries and
3516
     put them into the correct asections.  */
3517
8
  lnno_size = coff_count_linenumbers (abfd) * bfd_coff_linesz (abfd);
3518
3519
8
  if (! abfd->output_has_begun)
3520
2
    {
3521
2
      if (! coff_compute_section_file_positions (abfd))
3522
0
  return false;
3523
2
    }
3524
3525
8
  reloc_base = obj_relocbase (abfd);
3526
3527
  /* Work out the size of the reloc and linno areas.  */
3528
3529
83
  for (current = abfd->sections; current != NULL; current =
3530
75
       current->next)
3531
75
    {
3532
75
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3533
      /* We store the actual reloc count in the first reloc's addr.  */
3534
75
      if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3535
0
  reloc_count ++;
3536
75
#endif
3537
75
      reloc_count += current->reloc_count;
3538
75
    }
3539
3540
8
  reloc_size = reloc_count * bfd_coff_relsz (abfd);
3541
3542
8
  lineno_base = reloc_base + reloc_size;
3543
8
  sym_base = lineno_base + lnno_size;
3544
3545
  /* Indicate in each section->line_filepos its actual file address.  */
3546
83
  for (current = abfd->sections; current != NULL; current =
3547
75
       current->next)
3548
75
    {
3549
75
      if (current->lineno_count)
3550
0
  {
3551
0
    current->line_filepos = lineno_base;
3552
0
    current->moving_line_filepos = lineno_base;
3553
0
    lineno_base += current->lineno_count * bfd_coff_linesz (abfd);
3554
0
  }
3555
75
      else
3556
75
  current->line_filepos = 0;
3557
3558
75
      if (current->reloc_count)
3559
0
  {
3560
0
    current->rel_filepos = reloc_base;
3561
0
    reloc_base += current->reloc_count * bfd_coff_relsz (abfd);
3562
0
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3563
    /* Extra reloc to hold real count.  */
3564
0
    if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3565
0
      reloc_base += bfd_coff_relsz (abfd);
3566
0
#endif
3567
0
  }
3568
75
      else
3569
75
  current->rel_filepos = 0;
3570
75
    }
3571
3572
  /* Write section headers to the file.  */
3573
8
  internal_f.f_nscns = 0;
3574
3575
8
  if ((abfd->flags & EXEC_P) != 0)
3576
8
    scn_base = bfd_coff_filhsz (abfd) + bfd_coff_aoutsz (abfd);
3577
0
  else
3578
0
    {
3579
0
      scn_base = bfd_coff_filhsz (abfd);
3580
#ifdef RS6000COFF_C
3581
#ifndef XCOFF64
3582
      if (xcoff_data (abfd)->full_aouthdr)
3583
  scn_base += bfd_coff_aoutsz (abfd);
3584
      else
3585
  scn_base += SMALL_AOUTSZ;
3586
#endif
3587
#endif
3588
0
    }
3589
3590
8
  if (bfd_seek (abfd, scn_base, SEEK_SET) != 0)
3591
0
    return false;
3592
3593
8
  long_section_names = false;
3594
8
  for (current = abfd->sections;
3595
83
       current != NULL;
3596
75
       current = current->next)
3597
75
    {
3598
75
      struct internal_scnhdr section;
3599
75
#ifdef COFF_IMAGE_WITH_PE
3600
75
      bool is_reloc_section = false;
3601
3602
75
      if (strcmp (current->name, DOT_RELOC) == 0)
3603
3
  {
3604
3
    is_reloc_section = true;
3605
3
    hasrelocs = true;
3606
3
    pe_data (abfd)->has_reloc_section = 1;
3607
3
  }
3608
75
#endif
3609
3610
75
      internal_f.f_nscns++;
3611
3612
75
      strncpy (section.s_name, current->name, SCNNMLEN);
3613
3614
75
#ifdef COFF_LONG_SECTION_NAMES
3615
      /* Handle long section names as in PE.  This must be compatible
3616
   with the code in coff_write_symbols and _bfd_coff_final_link.  */
3617
75
      if (bfd_coff_long_section_names (abfd))
3618
75
  {
3619
75
    size_t len;
3620
3621
75
    len = strlen (current->name);
3622
75
    if (len > SCNNMLEN)
3623
29
      {
3624
3625
        /* An inherent limitation of the /nnnnnnn notation used to indicate
3626
     the offset of the long name in the string table is that we
3627
     cannot address entries beyone the ten million byte boundary.  */
3628
29
        if (string_size < 10000000)
3629
29
    {
3630
      /* The s_name field is defined to be NUL-padded but need not
3631
         be NUL-terminated.  We use a temporary buffer so that we
3632
         can still sprintf all eight chars without splatting a
3633
         terminating NUL over the first byte of the following
3634
         member (s_paddr).  */
3635
      /* PR 21096: The +20 is to stop a bogus warning from gcc7
3636
         about a possible buffer overflow.  */
3637
29
      char s_name_buf[SCNNMLEN + 1 + 20];
3638
3639
      /* We do not need to use snprintf here as we have already
3640
         verified that string_size is not too big, plus we have
3641
         an overlarge buffer, just in case.  */
3642
29
      sprintf (s_name_buf, "/%lu", (unsigned long) string_size);
3643
      /* Then strncpy takes care of any padding for us.  */
3644
29
      strncpy (section.s_name, s_name_buf, SCNNMLEN);
3645
29
    }
3646
0
        else
3647
0
#ifdef COFF_WITH_PE
3648
0
    {
3649
      /* PE use a base 64 encoding for long section names whose
3650
         index is very large.  But contrary to RFC 4648, there is
3651
         no padding: 6 characters must be generated.  */
3652
0
      static const char base64[] =
3653
0
        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
3654
0
        "abcdefghijklmnopqrstuvwxyz"
3655
0
        "0123456789+/";
3656
0
      unsigned long off = string_size;
3657
0
      unsigned i;
3658
3659
0
      section.s_name[0] = '/';
3660
0
      section.s_name[1] = '/';
3661
0
      for (i = SCNNMLEN - 1; i >= 2; i--)
3662
0
        {
3663
0
          section.s_name[i] = base64[off & 0x3f];
3664
0
          off >>= 6;
3665
0
        }
3666
0
    }
3667
29
#endif
3668
29
        if (string_size > 0xffffffffUL - (len + 1)
3669
#ifndef COFF_WITH_PE
3670
      || string_size >= 10000000
3671
#endif
3672
29
      )
3673
0
    {
3674
0
      bfd_set_error (bfd_error_file_too_big);
3675
0
      _bfd_error_handler
3676
        /* xgettext:c-format */
3677
0
        (_("%pB: section %pA: string table overflow at offset %ld"),
3678
0
        abfd, current, (unsigned long) string_size);
3679
0
      return false;
3680
0
    }
3681
3682
29
        string_size += len + 1;
3683
29
        long_section_names = true;
3684
29
      }
3685
75
  }
3686
75
#endif
3687
3688
75
#ifdef _LIB
3689
      /* Always set s_vaddr of .lib to 0.  This is right for SVR3.2
3690
   Ian Taylor <ian@cygnus.com>.  */
3691
75
      if (strcmp (current->name, _LIB) == 0)
3692
0
  section.s_vaddr = 0;
3693
75
      else
3694
75
#endif
3695
75
      section.s_vaddr = current->vma;
3696
75
      section.s_paddr = current->lma;
3697
75
      section.s_size =  current->size;
3698
#ifdef coff_get_section_load_page
3699
      section.s_page = coff_get_section_load_page (current);
3700
#else
3701
75
      section.s_page = 0;
3702
75
#endif
3703
3704
75
#ifdef COFF_WITH_PE
3705
75
      section.s_paddr = 0;
3706
75
#endif
3707
75
#ifdef COFF_IMAGE_WITH_PE
3708
      /* Reminder: s_paddr holds the virtual size of the section.  */
3709
75
      if (coff_section_data (abfd, current) != NULL
3710
75
    && pei_section_data (abfd, current) != NULL)
3711
75
  section.s_paddr = pei_section_data (abfd, current)->virt_size;
3712
0
      else
3713
0
  section.s_paddr = 0;
3714
75
#endif
3715
3716
      /* If this section has no size or is unloadable then the scnptr
3717
   will be 0 too.  */
3718
75
      if (current->size == 0
3719
75
    || (current->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
3720
3
  section.s_scnptr = 0;
3721
72
      else
3722
72
  section.s_scnptr = current->filepos;
3723
3724
75
      section.s_relptr = current->rel_filepos;
3725
75
      section.s_lnnoptr = current->line_filepos;
3726
75
      section.s_nreloc = current->reloc_count;
3727
75
      section.s_nlnno = current->lineno_count;
3728
#ifndef COFF_IMAGE_WITH_PE
3729
      /* In PEI, relocs come in the .reloc section.  */
3730
      if (current->reloc_count != 0)
3731
  hasrelocs = true;
3732
#endif
3733
75
      if (current->lineno_count != 0)
3734
0
  haslinno = true;
3735
75
#ifdef COFF_IMAGE_WITH_PE
3736
75
      if ((current->flags & SEC_DEBUGGING) != 0
3737
75
    && ! is_reloc_section)
3738
32
  hasdebug = true;
3739
75
#endif
3740
3741
#ifdef RS6000COFF_C
3742
#ifndef XCOFF64
3743
      /* Indicate the use of an XCOFF overflow section header.  */
3744
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3745
  {
3746
    section.s_nreloc = 0xffff;
3747
    section.s_nlnno = 0xffff;
3748
  }
3749
#endif
3750
#endif
3751
3752
75
      section.s_flags = sec_to_styp_flags (current->name, current->flags);
3753
3754
75
      if (!strcmp (current->name, _TEXT))
3755
3
  text_sec = current;
3756
72
      else if (!strcmp (current->name, _DATA))
3757
3
  data_sec = current;
3758
69
      else if (!strcmp (current->name, _BSS))
3759
3
  bss_sec = current;
3760
#ifdef RS6000COFF_C
3761
      else if (!strcmp (current->name, _TDATA))
3762
  tdata_sec = current;
3763
      else if (!strcmp (current->name, _TBSS))
3764
  tbss_sec = current;
3765
#endif
3766
3767
3768
75
#ifdef COFF_ENCODE_ALIGNMENT
3769
75
      if (COFF_ENCODE_ALIGNMENT (abfd, section, current->alignment_power)
3770
75
    && (COFF_DECODE_ALIGNMENT (section.s_flags)
3771
0
        != current->alignment_power))
3772
0
  {
3773
0
    bool warn = (coff_data (abfd)->link_info
3774
0
           && !bfd_link_relocatable (coff_data (abfd)->link_info));
3775
3776
0
    _bfd_error_handler
3777
      /* xgettext:c-format */
3778
0
      (_("%pB:%s section %s: alignment 2**%u not representable"),
3779
0
       abfd, warn ? " warning:" : "", current->name,
3780
0
       current->alignment_power);
3781
0
    if (!warn)
3782
0
      {
3783
0
        bfd_set_error (bfd_error_nonrepresentable_section);
3784
0
        return false;
3785
0
      }
3786
0
  }
3787
75
#endif
3788
3789
75
#ifdef COFF_IMAGE_WITH_PE
3790
      /* Suppress output of the sections if they are null.  ld
3791
   includes the bss and data sections even if there is no size
3792
   assigned to them.  NT loader doesn't like it if these section
3793
   headers are included if the sections themselves are not
3794
   needed.  See also coff_compute_section_file_positions.  */
3795
75
      if (section.s_size == 0)
3796
0
  internal_f.f_nscns--;
3797
75
      else
3798
75
#endif
3799
75
  {
3800
75
    SCNHDR buff;
3801
75
    bfd_size_type amt = bfd_coff_scnhsz (abfd);
3802
3803
75
    if (bfd_coff_swap_scnhdr_out (abfd, &section, &buff) == 0
3804
75
        || bfd_write (& buff, amt, abfd) != amt)
3805
0
      return false;
3806
75
  }
3807
3808
75
#ifdef COFF_WITH_PE
3809
      /* PE stores COMDAT section information in the symbol table.  If
3810
   this section is supposed to have some COMDAT info, track down
3811
   the symbol in the symbol table and modify it.  */
3812
75
      if ((current->flags & SEC_LINK_ONCE) != 0)
3813
0
  {
3814
0
    unsigned int i, count;
3815
0
    asymbol **psym;
3816
0
    coff_symbol_type *csym = NULL;
3817
0
    asymbol **psymsec;
3818
3819
0
    psymsec = NULL;
3820
0
    count = bfd_get_symcount (abfd);
3821
0
    for (i = 0, psym = abfd->outsymbols; i < count; i++, psym++)
3822
0
      {
3823
0
        if ((*psym)->section != current)
3824
0
    continue;
3825
3826
        /* Remember the location of the first symbol in this
3827
     section.  */
3828
0
        if (psymsec == NULL)
3829
0
    psymsec = psym;
3830
3831
        /* See if this is the section symbol.  */
3832
0
        if (strcmp ((*psym)->name, current->name) == 0)
3833
0
    {
3834
0
      csym = coff_symbol_from (*psym);
3835
0
      if (csym == NULL
3836
0
          || csym->native == NULL
3837
0
          || ! csym->native->is_sym
3838
0
          || csym->native->u.syment.n_numaux < 1
3839
0
          || csym->native->u.syment.n_sclass != C_STAT
3840
0
          || csym->native->u.syment.n_type != T_NULL)
3841
0
        continue;
3842
3843
      /* Here *PSYM is the section symbol for CURRENT.  */
3844
3845
0
      break;
3846
0
    }
3847
0
      }
3848
3849
    /* Did we find it?
3850
       Note that we might not if we're converting the file from
3851
       some other object file format.  */
3852
0
    if (i < count)
3853
0
      {
3854
0
        combined_entry_type *aux;
3855
3856
        /* We don't touch the x_checksum field.  The
3857
     x_associated field is not currently supported.  */
3858
3859
0
        aux = csym->native + 1;
3860
0
        BFD_ASSERT (! aux->is_sym);
3861
0
        switch (current->flags & SEC_LINK_DUPLICATES)
3862
0
    {
3863
0
    case SEC_LINK_DUPLICATES_DISCARD:
3864
0
      aux->u.auxent.x_scn.x_comdat = IMAGE_COMDAT_SELECT_ANY;
3865
0
      break;
3866
3867
0
    case SEC_LINK_DUPLICATES_ONE_ONLY:
3868
0
      aux->u.auxent.x_scn.x_comdat =
3869
0
        IMAGE_COMDAT_SELECT_NODUPLICATES;
3870
0
      break;
3871
3872
0
    case SEC_LINK_DUPLICATES_SAME_SIZE:
3873
0
      aux->u.auxent.x_scn.x_comdat =
3874
0
        IMAGE_COMDAT_SELECT_SAME_SIZE;
3875
0
      break;
3876
3877
0
    case SEC_LINK_DUPLICATES_SAME_CONTENTS:
3878
0
      aux->u.auxent.x_scn.x_comdat =
3879
0
        IMAGE_COMDAT_SELECT_EXACT_MATCH;
3880
0
      break;
3881
0
    }
3882
3883
        /* The COMDAT symbol must be the first symbol from this
3884
     section in the symbol table.  In order to make this
3885
     work, we move the COMDAT symbol before the first
3886
     symbol we found in the search above.  It's OK to
3887
     rearrange the symbol table at this point, because
3888
     coff_renumber_symbols is going to rearrange it
3889
     further and fix up all the aux entries.  */
3890
0
        if (psym != psymsec)
3891
0
    {
3892
0
      asymbol *hold;
3893
0
      asymbol **pcopy;
3894
3895
0
      hold = *psym;
3896
0
      for (pcopy = psym; pcopy > psymsec; pcopy--)
3897
0
        pcopy[0] = pcopy[-1];
3898
0
      *psymsec = hold;
3899
0
    }
3900
0
      }
3901
0
  }
3902
75
#endif /* COFF_WITH_PE */
3903
75
    }
3904
3905
#ifdef RS6000COFF_C
3906
#ifndef XCOFF64
3907
  /* XCOFF handles overflows in the reloc and line number count fields
3908
     by creating a new section header to hold the correct values.  */
3909
  for (current = abfd->sections; current != NULL; current = current->next)
3910
    {
3911
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3912
  {
3913
    struct internal_scnhdr scnhdr;
3914
    SCNHDR buff;
3915
    bfd_size_type amt;
3916
3917
    internal_f.f_nscns++;
3918
    memcpy (scnhdr.s_name, ".ovrflo", 8);
3919
    scnhdr.s_paddr = current->reloc_count;
3920
    scnhdr.s_vaddr = current->lineno_count;
3921
    scnhdr.s_size = 0;
3922
    scnhdr.s_scnptr = 0;
3923
    scnhdr.s_relptr = current->rel_filepos;
3924
    scnhdr.s_lnnoptr = current->line_filepos;
3925
    scnhdr.s_nreloc = current->target_index;
3926
    scnhdr.s_nlnno = current->target_index;
3927
    scnhdr.s_flags = STYP_OVRFLO;
3928
    amt = bfd_coff_scnhsz (abfd);
3929
    if (bfd_coff_swap_scnhdr_out (abfd, &scnhdr, &buff) == 0
3930
        || bfd_write (& buff, amt, abfd) != amt)
3931
      return false;
3932
  }
3933
    }
3934
#endif
3935
#endif
3936
3937
#if defined (COFF_GO32_EXE) || defined (COFF_GO32)
3938
  /* Pad section headers.  */
3939
  if ((abfd->flags & EXEC_P) != 0)
3940
    {
3941
      asection *s = abfd->sections;
3942
      while (s != NULL && s->filepos == 0)
3943
  s = s->next;
3944
      if (s != NULL)
3945
  {
3946
    file_ptr cur_ptr
3947
      = scn_base + abfd->section_count * bfd_coff_scnhsz (abfd);
3948
    file_ptr fill_size = s->filepos - cur_ptr;
3949
    if (fill_size > 0)
3950
      {
3951
        bfd_byte *b = bfd_zmalloc (fill_size);
3952
        if (!b)
3953
    return false;
3954
        if (bfd_write (b, fill_size, abfd) != (ufile_ptr) fill_size)
3955
    {
3956
      free (b);
3957
      return false;
3958
    }
3959
        free (b);
3960
      }
3961
  }
3962
    }
3963
#endif
3964
3965
  /* OK, now set up the filehdr...  */
3966
3967
  /* Don't include the internal abs section in the section count */
3968
3969
  /* We will NOT put a fucking timestamp in the header here. Every time you
3970
     put it back, I will come in and take it out again.  I'm sorry.  This
3971
     field does not belong here.  We fill it with a 0 so it compares the
3972
     same but is not a reasonable time. -- gnu@cygnus.com  */
3973
8
  internal_f.f_timdat = 0;
3974
8
  internal_f.f_flags = 0;
3975
3976
8
  if (abfd->flags & EXEC_P)
3977
8
    internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3978
0
  else
3979
0
    {
3980
0
      internal_f.f_opthdr = 0;
3981
#ifdef RS6000COFF_C
3982
#ifndef XCOFF64
3983
      if (xcoff_data (abfd)->full_aouthdr)
3984
  internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3985
      else
3986
  internal_f.f_opthdr = SMALL_AOUTSZ;
3987
#endif
3988
#endif
3989
0
    }
3990
3991
8
  if (!hasrelocs)
3992
5
    internal_f.f_flags |= F_RELFLG;
3993
8
  if (!haslinno)
3994
8
    internal_f.f_flags |= F_LNNO;
3995
8
  if (abfd->flags & EXEC_P)
3996
8
    internal_f.f_flags |= F_EXEC;
3997
8
#ifdef COFF_IMAGE_WITH_PE
3998
8
  if (! hasdebug)
3999
2
    internal_f.f_flags |= IMAGE_FILE_DEBUG_STRIPPED;
4000
8
  if (pe_data (abfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
4001
8
    internal_f.f_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
4002
8
#endif
4003
4004
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
4005
#ifdef COFF_WITH_PE
4006
  internal_f.f_flags |= IMAGE_FILE_32BIT_MACHINE;
4007
#else
4008
  if (bfd_little_endian (abfd))
4009
    internal_f.f_flags |= F_AR32WR;
4010
  else
4011
    internal_f.f_flags |= F_AR32W;
4012
#endif
4013
#endif
4014
4015
#ifdef TI_TARGET_ID
4016
  /* Target id is used in TI COFF v1 and later; COFF0 won't use this field,
4017
     but it doesn't hurt to set it internally.  */
4018
  internal_f.f_target_id = TI_TARGET_ID;
4019
#endif
4020
4021
  /* FIXME, should do something about the other byte orders and
4022
     architectures.  */
4023
4024
#ifdef RS6000COFF_C
4025
  if ((abfd->flags & DYNAMIC) != 0)
4026
    internal_f.f_flags |= F_SHROBJ;
4027
  if (bfd_get_section_by_name (abfd, _LOADER) != NULL)
4028
    internal_f.f_flags |= F_DYNLOAD;
4029
#endif
4030
4031
8
  memset (&internal_a, 0, sizeof internal_a);
4032
4033
  /* Set up architecture-dependent stuff.  */
4034
8
  {
4035
8
    unsigned int magic = 0;
4036
8
    unsigned short flags = 0;
4037
4038
8
    coff_set_flags (abfd, &magic, &flags);
4039
8
    internal_f.f_magic = magic;
4040
8
    internal_f.f_flags |= flags;
4041
    /* ...and the "opt"hdr...  */
4042
4043
#ifdef TICOFF_AOUT_MAGIC
4044
    internal_a.magic = TICOFF_AOUT_MAGIC;
4045
#define __A_MAGIC_SET__
4046
#endif
4047
4048
#if defined(ARM)
4049
#define __A_MAGIC_SET__
4050
    internal_a.magic = ZMAGIC;
4051
#endif
4052
4053
#if defined(AARCH64)
4054
#define __A_MAGIC_SET__
4055
    internal_a.magic = ZMAGIC;
4056
#endif
4057
4058
#if defined(LOONGARCH64)
4059
#define __A_MAGIC_SET__
4060
    internal_a.magic = ZMAGIC;
4061
#endif
4062
4063
#if defined MCORE_PE
4064
#define __A_MAGIC_SET__
4065
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR_MAGIC;
4066
#endif
4067
4068
8
#if defined(I386)
4069
8
#define __A_MAGIC_SET__
4070
#if defined LYNXOS
4071
    internal_a.magic = LYNXCOFFMAGIC;
4072
#elif defined AMD64
4073
8
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR64_MAGIC;
4074
#else
4075
    internal_a.magic = ZMAGIC;
4076
#endif
4077
8
#endif /* I386 */
4078
4079
#if defined(IA64)
4080
#define __A_MAGIC_SET__
4081
    internal_a.magic = PE32PMAGIC;
4082
#endif /* IA64 */
4083
4084
#if defined(SPARC)
4085
#define __A_MAGIC_SET__
4086
#if defined(LYNXOS)
4087
    internal_a.magic = LYNXCOFFMAGIC;
4088
#endif /* LYNXOS */
4089
#endif /* SPARC */
4090
4091
#ifdef RS6000COFF_C
4092
#define __A_MAGIC_SET__
4093
    internal_a.magic = (abfd->flags & D_PAGED) ? RS6K_AOUTHDR_ZMAGIC :
4094
    (abfd->flags & WP_TEXT) ? RS6K_AOUTHDR_NMAGIC :
4095
    RS6K_AOUTHDR_OMAGIC;
4096
#endif
4097
4098
#if defined(SH) && defined(COFF_WITH_PE)
4099
#define __A_MAGIC_SET__
4100
    internal_a.magic = SH_PE_MAGIC;
4101
#endif
4102
4103
#if defined(MIPS) && defined(COFF_WITH_PE)
4104
#define __A_MAGIC_SET__
4105
    internal_a.magic = MIPS_PE_MAGIC;
4106
#endif
4107
4108
#ifndef __A_MAGIC_SET__
4109
#include "Your aouthdr magic number is not being set!"
4110
#else
4111
8
#undef __A_MAGIC_SET__
4112
8
#endif
4113
8
  }
4114
4115
#ifdef RS6000COFF_C
4116
  /* XCOFF 32bit needs this to have new behaviour for n_type field.  */
4117
  internal_a.vstamp = 2;
4118
#else
4119
  /* FIXME: Does anybody ever set this to another value?  */
4120
8
  internal_a.vstamp = 0;
4121
8
#endif
4122
4123
  /* Now should write relocs, strings, syms.  */
4124
8
  obj_sym_filepos (abfd) = sym_base;
4125
4126
8
  if (bfd_get_symcount (abfd) != 0)
4127
3
    {
4128
3
      int firstundef;
4129
4130
3
      if (!coff_renumber_symbols (abfd, &firstundef))
4131
0
  return false;
4132
3
      coff_mangle_symbols (abfd);
4133
3
      if (! coff_write_symbols (abfd))
4134
0
  return false;
4135
3
      if (! coff_write_linenumbers (abfd))
4136
0
  return false;
4137
3
      if (! coff_write_relocs (abfd, firstundef))
4138
0
  return false;
4139
3
    }
4140
5
#ifdef COFF_LONG_SECTION_NAMES
4141
5
  else if (long_section_names && ! obj_coff_strings_written (abfd))
4142
0
    {
4143
      /* If we have long section names we have to write out the string
4144
   table even if there are no symbols.  */
4145
0
      if (! coff_write_symbols (abfd))
4146
0
  return false;
4147
0
    }
4148
8
#endif
4149
  /* If bfd_get_symcount (abfd) != 0, then we are not using the COFF
4150
     backend linker, and obj_raw_syment_count is not valid until after
4151
     coff_write_symbols is called.  */
4152
8
  if (obj_raw_syment_count (abfd) != 0)
4153
3
    {
4154
3
      internal_f.f_symptr = sym_base;
4155
#ifdef RS6000COFF_C
4156
      /* AIX appears to require that F_RELFLG not be set if there are
4157
   local symbols but no relocations.  */
4158
      internal_f.f_flags &=~ F_RELFLG;
4159
#endif
4160
3
    }
4161
5
  else
4162
5
    {
4163
5
      if (long_section_names)
4164
0
  internal_f.f_symptr = sym_base;
4165
5
      else
4166
5
  internal_f.f_symptr = 0;
4167
5
      internal_f.f_flags |= F_LSYMS;
4168
5
    }
4169
4170
8
  if (text_sec)
4171
3
    {
4172
3
      internal_a.tsize = text_sec->size;
4173
3
      internal_a.text_start = internal_a.tsize ? text_sec->vma : 0;
4174
3
    }
4175
8
  if (data_sec)
4176
3
    {
4177
3
      internal_a.dsize = data_sec->size;
4178
3
      internal_a.data_start = internal_a.dsize ? data_sec->vma : 0;
4179
3
    }
4180
8
  if (bss_sec)
4181
3
    {
4182
3
      internal_a.bsize = bss_sec->size;
4183
3
      if (internal_a.bsize && bss_sec->vma < internal_a.data_start)
4184
0
  internal_a.data_start = bss_sec->vma;
4185
3
    }
4186
4187
8
  internal_a.entry = bfd_get_start_address (abfd);
4188
8
  internal_f.f_nsyms = obj_raw_syment_count (abfd);
4189
4190
#ifdef RS6000COFF_C
4191
  if (xcoff_data (abfd)->full_aouthdr)
4192
    {
4193
      bfd_vma toc;
4194
      asection *loader_sec;
4195
4196
      internal_a.vstamp = 2;
4197
4198
      internal_a.o_snentry = xcoff_data (abfd)->snentry;
4199
      if (internal_a.o_snentry == 0)
4200
  internal_a.entry = (bfd_vma) -1;
4201
4202
      if (text_sec != NULL)
4203
  {
4204
    internal_a.o_sntext = text_sec->target_index;
4205
    internal_a.o_algntext = bfd_section_alignment (text_sec);
4206
  }
4207
      else
4208
  {
4209
    internal_a.o_sntext = 0;
4210
    internal_a.o_algntext = 0;
4211
  }
4212
      if (data_sec != NULL)
4213
  {
4214
    internal_a.o_sndata = data_sec->target_index;
4215
    internal_a.o_algndata = bfd_section_alignment (data_sec);
4216
  }
4217
      else
4218
  {
4219
    internal_a.o_sndata = 0;
4220
    internal_a.o_algndata = 0;
4221
  }
4222
      loader_sec = bfd_get_section_by_name (abfd, ".loader");
4223
      if (loader_sec != NULL)
4224
  internal_a.o_snloader = loader_sec->target_index;
4225
      else
4226
  internal_a.o_snloader = 0;
4227
      if (bss_sec != NULL)
4228
  internal_a.o_snbss = bss_sec->target_index;
4229
      else
4230
  internal_a.o_snbss = 0;
4231
4232
      if (tdata_sec != NULL)
4233
  {
4234
    internal_a.o_sntdata = tdata_sec->target_index;
4235
    /* TODO: o_flags should be set to RS6K_AOUTHDR_TLS_LE
4236
       if there is at least one R_TLS_LE relocations.  */
4237
    internal_a.o_flags = 0;
4238
#ifdef XCOFF64
4239
    internal_a.o_x64flags = 0;
4240
#endif
4241
  }
4242
      else
4243
  {
4244
    internal_a.o_sntdata = 0;
4245
    internal_a.o_flags = 0;
4246
#ifdef XCOFF64
4247
    internal_a.o_x64flags = 0;
4248
#endif
4249
  }
4250
      if (tbss_sec != NULL)
4251
    internal_a.o_sntbss = tbss_sec->target_index;
4252
      else
4253
    internal_a.o_sntbss = 0;
4254
4255
      toc = xcoff_data (abfd)->toc;
4256
      internal_a.o_toc = toc;
4257
      internal_a.o_sntoc = xcoff_data (abfd)->sntoc;
4258
4259
      internal_a.o_modtype = xcoff_data (abfd)->modtype;
4260
      if (xcoff_data (abfd)->cputype != -1)
4261
  internal_a.o_cputype = xcoff_data (abfd)->cputype;
4262
      else
4263
  {
4264
    switch (bfd_get_arch (abfd))
4265
      {
4266
      case bfd_arch_rs6000:
4267
        internal_a.o_cputype = 4;
4268
        break;
4269
      case bfd_arch_powerpc:
4270
        if (bfd_get_mach (abfd) == bfd_mach_ppc)
4271
    internal_a.o_cputype = 3;
4272
        else if (bfd_get_mach (abfd) == bfd_mach_ppc_620)
4273
    internal_a.o_cputype = 2;
4274
        else
4275
    internal_a.o_cputype = 1;
4276
        break;
4277
      default:
4278
        abort ();
4279
      }
4280
  }
4281
      internal_a.o_maxstack = xcoff_data (abfd)->maxstack;
4282
      internal_a.o_maxdata = xcoff_data (abfd)->maxdata;
4283
    }
4284
#endif
4285
4286
8
#ifdef COFF_WITH_PE
4287
8
  {
4288
    /* After object contents are finalized so we can compute a reasonable hash,
4289
       but before header is written so we can update it to point to debug directory.  */
4290
8
    struct pe_tdata *pe = pe_data (abfd);
4291
4292
8
    if (pe->build_id.after_write_object_contents != NULL)
4293
0
      (*pe->build_id.after_write_object_contents) (abfd);
4294
8
  }
4295
8
#endif
4296
4297
  /* Now write header.  */
4298
8
  if (bfd_seek (abfd, 0, SEEK_SET) != 0)
4299
0
    return false;
4300
4301
8
  {
4302
8
    char * buff;
4303
8
    bfd_size_type amount = bfd_coff_filhsz (abfd);
4304
4305
8
    buff = (char *) bfd_malloc (amount);
4306
8
    if (buff == NULL)
4307
0
      return false;
4308
4309
8
    bfd_coff_swap_filehdr_out (abfd, & internal_f, buff);
4310
8
    amount = bfd_write (buff, amount, abfd);
4311
4312
8
    free (buff);
4313
4314
8
    if (amount != bfd_coff_filhsz (abfd))
4315
0
      return false;
4316
8
  }
4317
4318
8
  if (abfd->flags & EXEC_P)
4319
8
    {
4320
      /* Note that peicode.h fills in a PEAOUTHDR, not an AOUTHDR.
4321
   include/coff/pe.h sets AOUTSZ == sizeof (PEAOUTHDR)).  */
4322
8
      char * buff;
4323
8
      bfd_size_type amount = bfd_coff_aoutsz (abfd);
4324
4325
8
      buff = (char *) bfd_malloc (amount);
4326
8
      if (buff == NULL)
4327
0
  return false;
4328
4329
8
      coff_swap_aouthdr_out (abfd, & internal_a, buff);
4330
8
      amount = bfd_write (buff, amount, abfd);
4331
4332
8
      free (buff);
4333
4334
8
      if (amount != bfd_coff_aoutsz (abfd))
4335
0
  return false;
4336
4337
8
#ifdef COFF_IMAGE_WITH_PE
4338
8
      if (! coff_apply_checksum (abfd))
4339
0
  return false;
4340
8
#endif
4341
8
    }
4342
#ifdef RS6000COFF_C
4343
#ifndef XCOFF64
4344
  else
4345
    {
4346
      AOUTHDR buff;
4347
      size_t size;
4348
4349
      /* XCOFF32 seems to always write at least a small a.out header.  */
4350
      coff_swap_aouthdr_out (abfd, & internal_a, & buff);
4351
      if (xcoff_data (abfd)->full_aouthdr)
4352
  size = bfd_coff_aoutsz (abfd);
4353
      else
4354
  size = SMALL_AOUTSZ;
4355
      if (bfd_write (&buff, size, abfd) != size)
4356
  return false;
4357
    }
4358
#endif
4359
#endif
4360
4361
8
  return true;
4362
8
}
coff-x86_64.c:coff_write_object_contents
Line
Count
Source
3486
2
{
3487
2
  asection *current;
3488
2
  bool hasrelocs = false;
3489
2
  bool haslinno = false;
3490
#ifdef COFF_IMAGE_WITH_PE
3491
  bool hasdebug = false;
3492
#endif
3493
2
  file_ptr scn_base;
3494
2
  file_ptr reloc_base;
3495
2
  file_ptr lineno_base;
3496
2
  file_ptr sym_base;
3497
2
  unsigned long reloc_size = 0, reloc_count = 0;
3498
2
  unsigned long lnno_size = 0;
3499
2
  bool long_section_names;
3500
2
  asection *text_sec = NULL;
3501
2
  asection *data_sec = NULL;
3502
2
  asection *bss_sec = NULL;
3503
#ifdef RS6000COFF_C
3504
  asection *tdata_sec = NULL;
3505
  asection *tbss_sec = NULL;
3506
#endif
3507
2
  struct internal_filehdr internal_f;
3508
2
  struct internal_aouthdr internal_a;
3509
#ifdef COFF_LONG_SECTION_NAMES
3510
  size_t string_size = STRING_SIZE_SIZE;
3511
#endif
3512
3513
2
  bfd_set_error (bfd_error_system_call);
3514
3515
  /* Make a pass through the symbol table to count line number entries and
3516
     put them into the correct asections.  */
3517
2
  lnno_size = coff_count_linenumbers (abfd) * bfd_coff_linesz (abfd);
3518
3519
2
  if (! abfd->output_has_begun)
3520
2
    {
3521
2
      if (! coff_compute_section_file_positions (abfd))
3522
0
  return false;
3523
2
    }
3524
3525
2
  reloc_base = obj_relocbase (abfd);
3526
3527
  /* Work out the size of the reloc and linno areas.  */
3528
3529
2
  for (current = abfd->sections; current != NULL; current =
3530
0
       current->next)
3531
0
    {
3532
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3533
      /* We store the actual reloc count in the first reloc's addr.  */
3534
      if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3535
  reloc_count ++;
3536
#endif
3537
0
      reloc_count += current->reloc_count;
3538
0
    }
3539
3540
2
  reloc_size = reloc_count * bfd_coff_relsz (abfd);
3541
3542
2
  lineno_base = reloc_base + reloc_size;
3543
2
  sym_base = lineno_base + lnno_size;
3544
3545
  /* Indicate in each section->line_filepos its actual file address.  */
3546
2
  for (current = abfd->sections; current != NULL; current =
3547
0
       current->next)
3548
0
    {
3549
0
      if (current->lineno_count)
3550
0
  {
3551
0
    current->line_filepos = lineno_base;
3552
0
    current->moving_line_filepos = lineno_base;
3553
0
    lineno_base += current->lineno_count * bfd_coff_linesz (abfd);
3554
0
  }
3555
0
      else
3556
0
  current->line_filepos = 0;
3557
3558
0
      if (current->reloc_count)
3559
0
  {
3560
0
    current->rel_filepos = reloc_base;
3561
0
    reloc_base += current->reloc_count * bfd_coff_relsz (abfd);
3562
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3563
    /* Extra reloc to hold real count.  */
3564
    if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3565
      reloc_base += bfd_coff_relsz (abfd);
3566
#endif
3567
0
  }
3568
0
      else
3569
0
  current->rel_filepos = 0;
3570
0
    }
3571
3572
  /* Write section headers to the file.  */
3573
2
  internal_f.f_nscns = 0;
3574
3575
2
  if ((abfd->flags & EXEC_P) != 0)
3576
2
    scn_base = bfd_coff_filhsz (abfd) + bfd_coff_aoutsz (abfd);
3577
0
  else
3578
0
    {
3579
0
      scn_base = bfd_coff_filhsz (abfd);
3580
#ifdef RS6000COFF_C
3581
#ifndef XCOFF64
3582
      if (xcoff_data (abfd)->full_aouthdr)
3583
  scn_base += bfd_coff_aoutsz (abfd);
3584
      else
3585
  scn_base += SMALL_AOUTSZ;
3586
#endif
3587
#endif
3588
0
    }
3589
3590
2
  if (bfd_seek (abfd, scn_base, SEEK_SET) != 0)
3591
0
    return false;
3592
3593
2
  long_section_names = false;
3594
2
  for (current = abfd->sections;
3595
2
       current != NULL;
3596
2
       current = current->next)
3597
0
    {
3598
0
      struct internal_scnhdr section;
3599
#ifdef COFF_IMAGE_WITH_PE
3600
      bool is_reloc_section = false;
3601
3602
      if (strcmp (current->name, DOT_RELOC) == 0)
3603
  {
3604
    is_reloc_section = true;
3605
    hasrelocs = true;
3606
    pe_data (abfd)->has_reloc_section = 1;
3607
  }
3608
#endif
3609
3610
0
      internal_f.f_nscns++;
3611
3612
0
      strncpy (section.s_name, current->name, SCNNMLEN);
3613
3614
#ifdef COFF_LONG_SECTION_NAMES
3615
      /* Handle long section names as in PE.  This must be compatible
3616
   with the code in coff_write_symbols and _bfd_coff_final_link.  */
3617
      if (bfd_coff_long_section_names (abfd))
3618
  {
3619
    size_t len;
3620
3621
    len = strlen (current->name);
3622
    if (len > SCNNMLEN)
3623
      {
3624
3625
        /* An inherent limitation of the /nnnnnnn notation used to indicate
3626
     the offset of the long name in the string table is that we
3627
     cannot address entries beyone the ten million byte boundary.  */
3628
        if (string_size < 10000000)
3629
    {
3630
      /* The s_name field is defined to be NUL-padded but need not
3631
         be NUL-terminated.  We use a temporary buffer so that we
3632
         can still sprintf all eight chars without splatting a
3633
         terminating NUL over the first byte of the following
3634
         member (s_paddr).  */
3635
      /* PR 21096: The +20 is to stop a bogus warning from gcc7
3636
         about a possible buffer overflow.  */
3637
      char s_name_buf[SCNNMLEN + 1 + 20];
3638
3639
      /* We do not need to use snprintf here as we have already
3640
         verified that string_size is not too big, plus we have
3641
         an overlarge buffer, just in case.  */
3642
      sprintf (s_name_buf, "/%lu", (unsigned long) string_size);
3643
      /* Then strncpy takes care of any padding for us.  */
3644
      strncpy (section.s_name, s_name_buf, SCNNMLEN);
3645
    }
3646
        else
3647
#ifdef COFF_WITH_PE
3648
    {
3649
      /* PE use a base 64 encoding for long section names whose
3650
         index is very large.  But contrary to RFC 4648, there is
3651
         no padding: 6 characters must be generated.  */
3652
      static const char base64[] =
3653
        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
3654
        "abcdefghijklmnopqrstuvwxyz"
3655
        "0123456789+/";
3656
      unsigned long off = string_size;
3657
      unsigned i;
3658
3659
      section.s_name[0] = '/';
3660
      section.s_name[1] = '/';
3661
      for (i = SCNNMLEN - 1; i >= 2; i--)
3662
        {
3663
          section.s_name[i] = base64[off & 0x3f];
3664
          off >>= 6;
3665
        }
3666
    }
3667
#endif
3668
        if (string_size > 0xffffffffUL - (len + 1)
3669
#ifndef COFF_WITH_PE
3670
      || string_size >= 10000000
3671
#endif
3672
      )
3673
    {
3674
      bfd_set_error (bfd_error_file_too_big);
3675
      _bfd_error_handler
3676
        /* xgettext:c-format */
3677
        (_("%pB: section %pA: string table overflow at offset %ld"),
3678
        abfd, current, (unsigned long) string_size);
3679
      return false;
3680
    }
3681
3682
        string_size += len + 1;
3683
        long_section_names = true;
3684
      }
3685
  }
3686
#endif
3687
3688
0
#ifdef _LIB
3689
      /* Always set s_vaddr of .lib to 0.  This is right for SVR3.2
3690
   Ian Taylor <ian@cygnus.com>.  */
3691
0
      if (strcmp (current->name, _LIB) == 0)
3692
0
  section.s_vaddr = 0;
3693
0
      else
3694
0
#endif
3695
0
      section.s_vaddr = current->vma;
3696
0
      section.s_paddr = current->lma;
3697
0
      section.s_size =  current->size;
3698
#ifdef coff_get_section_load_page
3699
      section.s_page = coff_get_section_load_page (current);
3700
#else
3701
0
      section.s_page = 0;
3702
0
#endif
3703
3704
#ifdef COFF_WITH_PE
3705
      section.s_paddr = 0;
3706
#endif
3707
#ifdef COFF_IMAGE_WITH_PE
3708
      /* Reminder: s_paddr holds the virtual size of the section.  */
3709
      if (coff_section_data (abfd, current) != NULL
3710
    && pei_section_data (abfd, current) != NULL)
3711
  section.s_paddr = pei_section_data (abfd, current)->virt_size;
3712
      else
3713
  section.s_paddr = 0;
3714
#endif
3715
3716
      /* If this section has no size or is unloadable then the scnptr
3717
   will be 0 too.  */
3718
0
      if (current->size == 0
3719
0
    || (current->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
3720
0
  section.s_scnptr = 0;
3721
0
      else
3722
0
  section.s_scnptr = current->filepos;
3723
3724
0
      section.s_relptr = current->rel_filepos;
3725
0
      section.s_lnnoptr = current->line_filepos;
3726
0
      section.s_nreloc = current->reloc_count;
3727
0
      section.s_nlnno = current->lineno_count;
3728
0
#ifndef COFF_IMAGE_WITH_PE
3729
      /* In PEI, relocs come in the .reloc section.  */
3730
0
      if (current->reloc_count != 0)
3731
0
  hasrelocs = true;
3732
0
#endif
3733
0
      if (current->lineno_count != 0)
3734
0
  haslinno = true;
3735
#ifdef COFF_IMAGE_WITH_PE
3736
      if ((current->flags & SEC_DEBUGGING) != 0
3737
    && ! is_reloc_section)
3738
  hasdebug = true;
3739
#endif
3740
3741
#ifdef RS6000COFF_C
3742
#ifndef XCOFF64
3743
      /* Indicate the use of an XCOFF overflow section header.  */
3744
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3745
  {
3746
    section.s_nreloc = 0xffff;
3747
    section.s_nlnno = 0xffff;
3748
  }
3749
#endif
3750
#endif
3751
3752
0
      section.s_flags = sec_to_styp_flags (current->name, current->flags);
3753
3754
0
      if (!strcmp (current->name, _TEXT))
3755
0
  text_sec = current;
3756
0
      else if (!strcmp (current->name, _DATA))
3757
0
  data_sec = current;
3758
0
      else if (!strcmp (current->name, _BSS))
3759
0
  bss_sec = current;
3760
#ifdef RS6000COFF_C
3761
      else if (!strcmp (current->name, _TDATA))
3762
  tdata_sec = current;
3763
      else if (!strcmp (current->name, _TBSS))
3764
  tbss_sec = current;
3765
#endif
3766
3767
3768
#ifdef COFF_ENCODE_ALIGNMENT
3769
      if (COFF_ENCODE_ALIGNMENT (abfd, section, current->alignment_power)
3770
    && (COFF_DECODE_ALIGNMENT (section.s_flags)
3771
        != current->alignment_power))
3772
  {
3773
    bool warn = (coff_data (abfd)->link_info
3774
           && !bfd_link_relocatable (coff_data (abfd)->link_info));
3775
3776
    _bfd_error_handler
3777
      /* xgettext:c-format */
3778
      (_("%pB:%s section %s: alignment 2**%u not representable"),
3779
       abfd, warn ? " warning:" : "", current->name,
3780
       current->alignment_power);
3781
    if (!warn)
3782
      {
3783
        bfd_set_error (bfd_error_nonrepresentable_section);
3784
        return false;
3785
      }
3786
  }
3787
#endif
3788
3789
#ifdef COFF_IMAGE_WITH_PE
3790
      /* Suppress output of the sections if they are null.  ld
3791
   includes the bss and data sections even if there is no size
3792
   assigned to them.  NT loader doesn't like it if these section
3793
   headers are included if the sections themselves are not
3794
   needed.  See also coff_compute_section_file_positions.  */
3795
      if (section.s_size == 0)
3796
  internal_f.f_nscns--;
3797
      else
3798
#endif
3799
0
  {
3800
0
    SCNHDR buff;
3801
0
    bfd_size_type amt = bfd_coff_scnhsz (abfd);
3802
3803
0
    if (bfd_coff_swap_scnhdr_out (abfd, &section, &buff) == 0
3804
0
        || bfd_write (& buff, amt, abfd) != amt)
3805
0
      return false;
3806
0
  }
3807
3808
#ifdef COFF_WITH_PE
3809
      /* PE stores COMDAT section information in the symbol table.  If
3810
   this section is supposed to have some COMDAT info, track down
3811
   the symbol in the symbol table and modify it.  */
3812
      if ((current->flags & SEC_LINK_ONCE) != 0)
3813
  {
3814
    unsigned int i, count;
3815
    asymbol **psym;
3816
    coff_symbol_type *csym = NULL;
3817
    asymbol **psymsec;
3818
3819
    psymsec = NULL;
3820
    count = bfd_get_symcount (abfd);
3821
    for (i = 0, psym = abfd->outsymbols; i < count; i++, psym++)
3822
      {
3823
        if ((*psym)->section != current)
3824
    continue;
3825
3826
        /* Remember the location of the first symbol in this
3827
     section.  */
3828
        if (psymsec == NULL)
3829
    psymsec = psym;
3830
3831
        /* See if this is the section symbol.  */
3832
        if (strcmp ((*psym)->name, current->name) == 0)
3833
    {
3834
      csym = coff_symbol_from (*psym);
3835
      if (csym == NULL
3836
          || csym->native == NULL
3837
          || ! csym->native->is_sym
3838
          || csym->native->u.syment.n_numaux < 1
3839
          || csym->native->u.syment.n_sclass != C_STAT
3840
          || csym->native->u.syment.n_type != T_NULL)
3841
        continue;
3842
3843
      /* Here *PSYM is the section symbol for CURRENT.  */
3844
3845
      break;
3846
    }
3847
      }
3848
3849
    /* Did we find it?
3850
       Note that we might not if we're converting the file from
3851
       some other object file format.  */
3852
    if (i < count)
3853
      {
3854
        combined_entry_type *aux;
3855
3856
        /* We don't touch the x_checksum field.  The
3857
     x_associated field is not currently supported.  */
3858
3859
        aux = csym->native + 1;
3860
        BFD_ASSERT (! aux->is_sym);
3861
        switch (current->flags & SEC_LINK_DUPLICATES)
3862
    {
3863
    case SEC_LINK_DUPLICATES_DISCARD:
3864
      aux->u.auxent.x_scn.x_comdat = IMAGE_COMDAT_SELECT_ANY;
3865
      break;
3866
3867
    case SEC_LINK_DUPLICATES_ONE_ONLY:
3868
      aux->u.auxent.x_scn.x_comdat =
3869
        IMAGE_COMDAT_SELECT_NODUPLICATES;
3870
      break;
3871
3872
    case SEC_LINK_DUPLICATES_SAME_SIZE:
3873
      aux->u.auxent.x_scn.x_comdat =
3874
        IMAGE_COMDAT_SELECT_SAME_SIZE;
3875
      break;
3876
3877
    case SEC_LINK_DUPLICATES_SAME_CONTENTS:
3878
      aux->u.auxent.x_scn.x_comdat =
3879
        IMAGE_COMDAT_SELECT_EXACT_MATCH;
3880
      break;
3881
    }
3882
3883
        /* The COMDAT symbol must be the first symbol from this
3884
     section in the symbol table.  In order to make this
3885
     work, we move the COMDAT symbol before the first
3886
     symbol we found in the search above.  It's OK to
3887
     rearrange the symbol table at this point, because
3888
     coff_renumber_symbols is going to rearrange it
3889
     further and fix up all the aux entries.  */
3890
        if (psym != psymsec)
3891
    {
3892
      asymbol *hold;
3893
      asymbol **pcopy;
3894
3895
      hold = *psym;
3896
      for (pcopy = psym; pcopy > psymsec; pcopy--)
3897
        pcopy[0] = pcopy[-1];
3898
      *psymsec = hold;
3899
    }
3900
      }
3901
  }
3902
#endif /* COFF_WITH_PE */
3903
0
    }
3904
3905
#ifdef RS6000COFF_C
3906
#ifndef XCOFF64
3907
  /* XCOFF handles overflows in the reloc and line number count fields
3908
     by creating a new section header to hold the correct values.  */
3909
  for (current = abfd->sections; current != NULL; current = current->next)
3910
    {
3911
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3912
  {
3913
    struct internal_scnhdr scnhdr;
3914
    SCNHDR buff;
3915
    bfd_size_type amt;
3916
3917
    internal_f.f_nscns++;
3918
    memcpy (scnhdr.s_name, ".ovrflo", 8);
3919
    scnhdr.s_paddr = current->reloc_count;
3920
    scnhdr.s_vaddr = current->lineno_count;
3921
    scnhdr.s_size = 0;
3922
    scnhdr.s_scnptr = 0;
3923
    scnhdr.s_relptr = current->rel_filepos;
3924
    scnhdr.s_lnnoptr = current->line_filepos;
3925
    scnhdr.s_nreloc = current->target_index;
3926
    scnhdr.s_nlnno = current->target_index;
3927
    scnhdr.s_flags = STYP_OVRFLO;
3928
    amt = bfd_coff_scnhsz (abfd);
3929
    if (bfd_coff_swap_scnhdr_out (abfd, &scnhdr, &buff) == 0
3930
        || bfd_write (& buff, amt, abfd) != amt)
3931
      return false;
3932
  }
3933
    }
3934
#endif
3935
#endif
3936
3937
#if defined (COFF_GO32_EXE) || defined (COFF_GO32)
3938
  /* Pad section headers.  */
3939
  if ((abfd->flags & EXEC_P) != 0)
3940
    {
3941
      asection *s = abfd->sections;
3942
      while (s != NULL && s->filepos == 0)
3943
  s = s->next;
3944
      if (s != NULL)
3945
  {
3946
    file_ptr cur_ptr
3947
      = scn_base + abfd->section_count * bfd_coff_scnhsz (abfd);
3948
    file_ptr fill_size = s->filepos - cur_ptr;
3949
    if (fill_size > 0)
3950
      {
3951
        bfd_byte *b = bfd_zmalloc (fill_size);
3952
        if (!b)
3953
    return false;
3954
        if (bfd_write (b, fill_size, abfd) != (ufile_ptr) fill_size)
3955
    {
3956
      free (b);
3957
      return false;
3958
    }
3959
        free (b);
3960
      }
3961
  }
3962
    }
3963
#endif
3964
3965
  /* OK, now set up the filehdr...  */
3966
3967
  /* Don't include the internal abs section in the section count */
3968
3969
  /* We will NOT put a fucking timestamp in the header here. Every time you
3970
     put it back, I will come in and take it out again.  I'm sorry.  This
3971
     field does not belong here.  We fill it with a 0 so it compares the
3972
     same but is not a reasonable time. -- gnu@cygnus.com  */
3973
2
  internal_f.f_timdat = 0;
3974
2
  internal_f.f_flags = 0;
3975
3976
2
  if (abfd->flags & EXEC_P)
3977
2
    internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3978
0
  else
3979
0
    {
3980
0
      internal_f.f_opthdr = 0;
3981
#ifdef RS6000COFF_C
3982
#ifndef XCOFF64
3983
      if (xcoff_data (abfd)->full_aouthdr)
3984
  internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3985
      else
3986
  internal_f.f_opthdr = SMALL_AOUTSZ;
3987
#endif
3988
#endif
3989
0
    }
3990
3991
2
  if (!hasrelocs)
3992
2
    internal_f.f_flags |= F_RELFLG;
3993
2
  if (!haslinno)
3994
2
    internal_f.f_flags |= F_LNNO;
3995
2
  if (abfd->flags & EXEC_P)
3996
2
    internal_f.f_flags |= F_EXEC;
3997
#ifdef COFF_IMAGE_WITH_PE
3998
  if (! hasdebug)
3999
    internal_f.f_flags |= IMAGE_FILE_DEBUG_STRIPPED;
4000
  if (pe_data (abfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
4001
    internal_f.f_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
4002
#endif
4003
4004
2
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
4005
#ifdef COFF_WITH_PE
4006
  internal_f.f_flags |= IMAGE_FILE_32BIT_MACHINE;
4007
#else
4008
2
  if (bfd_little_endian (abfd))
4009
2
    internal_f.f_flags |= F_AR32WR;
4010
0
  else
4011
0
    internal_f.f_flags |= F_AR32W;
4012
2
#endif
4013
2
#endif
4014
4015
#ifdef TI_TARGET_ID
4016
  /* Target id is used in TI COFF v1 and later; COFF0 won't use this field,
4017
     but it doesn't hurt to set it internally.  */
4018
  internal_f.f_target_id = TI_TARGET_ID;
4019
#endif
4020
4021
  /* FIXME, should do something about the other byte orders and
4022
     architectures.  */
4023
4024
#ifdef RS6000COFF_C
4025
  if ((abfd->flags & DYNAMIC) != 0)
4026
    internal_f.f_flags |= F_SHROBJ;
4027
  if (bfd_get_section_by_name (abfd, _LOADER) != NULL)
4028
    internal_f.f_flags |= F_DYNLOAD;
4029
#endif
4030
4031
2
  memset (&internal_a, 0, sizeof internal_a);
4032
4033
  /* Set up architecture-dependent stuff.  */
4034
2
  {
4035
2
    unsigned int magic = 0;
4036
2
    unsigned short flags = 0;
4037
4038
2
    coff_set_flags (abfd, &magic, &flags);
4039
2
    internal_f.f_magic = magic;
4040
2
    internal_f.f_flags |= flags;
4041
    /* ...and the "opt"hdr...  */
4042
4043
#ifdef TICOFF_AOUT_MAGIC
4044
    internal_a.magic = TICOFF_AOUT_MAGIC;
4045
#define __A_MAGIC_SET__
4046
#endif
4047
4048
#if defined(ARM)
4049
#define __A_MAGIC_SET__
4050
    internal_a.magic = ZMAGIC;
4051
#endif
4052
4053
#if defined(AARCH64)
4054
#define __A_MAGIC_SET__
4055
    internal_a.magic = ZMAGIC;
4056
#endif
4057
4058
#if defined(LOONGARCH64)
4059
#define __A_MAGIC_SET__
4060
    internal_a.magic = ZMAGIC;
4061
#endif
4062
4063
#if defined MCORE_PE
4064
#define __A_MAGIC_SET__
4065
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR_MAGIC;
4066
#endif
4067
4068
2
#if defined(I386)
4069
2
#define __A_MAGIC_SET__
4070
#if defined LYNXOS
4071
    internal_a.magic = LYNXCOFFMAGIC;
4072
#elif defined AMD64
4073
2
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR64_MAGIC;
4074
#else
4075
    internal_a.magic = ZMAGIC;
4076
#endif
4077
2
#endif /* I386 */
4078
4079
#if defined(IA64)
4080
#define __A_MAGIC_SET__
4081
    internal_a.magic = PE32PMAGIC;
4082
#endif /* IA64 */
4083
4084
#if defined(SPARC)
4085
#define __A_MAGIC_SET__
4086
#if defined(LYNXOS)
4087
    internal_a.magic = LYNXCOFFMAGIC;
4088
#endif /* LYNXOS */
4089
#endif /* SPARC */
4090
4091
#ifdef RS6000COFF_C
4092
#define __A_MAGIC_SET__
4093
    internal_a.magic = (abfd->flags & D_PAGED) ? RS6K_AOUTHDR_ZMAGIC :
4094
    (abfd->flags & WP_TEXT) ? RS6K_AOUTHDR_NMAGIC :
4095
    RS6K_AOUTHDR_OMAGIC;
4096
#endif
4097
4098
#if defined(SH) && defined(COFF_WITH_PE)
4099
#define __A_MAGIC_SET__
4100
    internal_a.magic = SH_PE_MAGIC;
4101
#endif
4102
4103
#if defined(MIPS) && defined(COFF_WITH_PE)
4104
#define __A_MAGIC_SET__
4105
    internal_a.magic = MIPS_PE_MAGIC;
4106
#endif
4107
4108
#ifndef __A_MAGIC_SET__
4109
#include "Your aouthdr magic number is not being set!"
4110
#else
4111
2
#undef __A_MAGIC_SET__
4112
2
#endif
4113
2
  }
4114
4115
#ifdef RS6000COFF_C
4116
  /* XCOFF 32bit needs this to have new behaviour for n_type field.  */
4117
  internal_a.vstamp = 2;
4118
#else
4119
  /* FIXME: Does anybody ever set this to another value?  */
4120
2
  internal_a.vstamp = 0;
4121
2
#endif
4122
4123
  /* Now should write relocs, strings, syms.  */
4124
2
  obj_sym_filepos (abfd) = sym_base;
4125
4126
2
  if (bfd_get_symcount (abfd) != 0)
4127
0
    {
4128
0
      int firstundef;
4129
4130
0
      if (!coff_renumber_symbols (abfd, &firstundef))
4131
0
  return false;
4132
0
      coff_mangle_symbols (abfd);
4133
0
      if (! coff_write_symbols (abfd))
4134
0
  return false;
4135
0
      if (! coff_write_linenumbers (abfd))
4136
0
  return false;
4137
0
      if (! coff_write_relocs (abfd, firstundef))
4138
0
  return false;
4139
0
    }
4140
#ifdef COFF_LONG_SECTION_NAMES
4141
  else if (long_section_names && ! obj_coff_strings_written (abfd))
4142
    {
4143
      /* If we have long section names we have to write out the string
4144
   table even if there are no symbols.  */
4145
      if (! coff_write_symbols (abfd))
4146
  return false;
4147
    }
4148
#endif
4149
  /* If bfd_get_symcount (abfd) != 0, then we are not using the COFF
4150
     backend linker, and obj_raw_syment_count is not valid until after
4151
     coff_write_symbols is called.  */
4152
2
  if (obj_raw_syment_count (abfd) != 0)
4153
0
    {
4154
0
      internal_f.f_symptr = sym_base;
4155
#ifdef RS6000COFF_C
4156
      /* AIX appears to require that F_RELFLG not be set if there are
4157
   local symbols but no relocations.  */
4158
      internal_f.f_flags &=~ F_RELFLG;
4159
#endif
4160
0
    }
4161
2
  else
4162
2
    {
4163
2
      if (long_section_names)
4164
0
  internal_f.f_symptr = sym_base;
4165
2
      else
4166
2
  internal_f.f_symptr = 0;
4167
2
      internal_f.f_flags |= F_LSYMS;
4168
2
    }
4169
4170
2
  if (text_sec)
4171
0
    {
4172
0
      internal_a.tsize = text_sec->size;
4173
0
      internal_a.text_start = internal_a.tsize ? text_sec->vma : 0;
4174
0
    }
4175
2
  if (data_sec)
4176
0
    {
4177
0
      internal_a.dsize = data_sec->size;
4178
0
      internal_a.data_start = internal_a.dsize ? data_sec->vma : 0;
4179
0
    }
4180
2
  if (bss_sec)
4181
0
    {
4182
0
      internal_a.bsize = bss_sec->size;
4183
0
      if (internal_a.bsize && bss_sec->vma < internal_a.data_start)
4184
0
  internal_a.data_start = bss_sec->vma;
4185
0
    }
4186
4187
2
  internal_a.entry = bfd_get_start_address (abfd);
4188
2
  internal_f.f_nsyms = obj_raw_syment_count (abfd);
4189
4190
#ifdef RS6000COFF_C
4191
  if (xcoff_data (abfd)->full_aouthdr)
4192
    {
4193
      bfd_vma toc;
4194
      asection *loader_sec;
4195
4196
      internal_a.vstamp = 2;
4197
4198
      internal_a.o_snentry = xcoff_data (abfd)->snentry;
4199
      if (internal_a.o_snentry == 0)
4200
  internal_a.entry = (bfd_vma) -1;
4201
4202
      if (text_sec != NULL)
4203
  {
4204
    internal_a.o_sntext = text_sec->target_index;
4205
    internal_a.o_algntext = bfd_section_alignment (text_sec);
4206
  }
4207
      else
4208
  {
4209
    internal_a.o_sntext = 0;
4210
    internal_a.o_algntext = 0;
4211
  }
4212
      if (data_sec != NULL)
4213
  {
4214
    internal_a.o_sndata = data_sec->target_index;
4215
    internal_a.o_algndata = bfd_section_alignment (data_sec);
4216
  }
4217
      else
4218
  {
4219
    internal_a.o_sndata = 0;
4220
    internal_a.o_algndata = 0;
4221
  }
4222
      loader_sec = bfd_get_section_by_name (abfd, ".loader");
4223
      if (loader_sec != NULL)
4224
  internal_a.o_snloader = loader_sec->target_index;
4225
      else
4226
  internal_a.o_snloader = 0;
4227
      if (bss_sec != NULL)
4228
  internal_a.o_snbss = bss_sec->target_index;
4229
      else
4230
  internal_a.o_snbss = 0;
4231
4232
      if (tdata_sec != NULL)
4233
  {
4234
    internal_a.o_sntdata = tdata_sec->target_index;
4235
    /* TODO: o_flags should be set to RS6K_AOUTHDR_TLS_LE
4236
       if there is at least one R_TLS_LE relocations.  */
4237
    internal_a.o_flags = 0;
4238
#ifdef XCOFF64
4239
    internal_a.o_x64flags = 0;
4240
#endif
4241
  }
4242
      else
4243
  {
4244
    internal_a.o_sntdata = 0;
4245
    internal_a.o_flags = 0;
4246
#ifdef XCOFF64
4247
    internal_a.o_x64flags = 0;
4248
#endif
4249
  }
4250
      if (tbss_sec != NULL)
4251
    internal_a.o_sntbss = tbss_sec->target_index;
4252
      else
4253
    internal_a.o_sntbss = 0;
4254
4255
      toc = xcoff_data (abfd)->toc;
4256
      internal_a.o_toc = toc;
4257
      internal_a.o_sntoc = xcoff_data (abfd)->sntoc;
4258
4259
      internal_a.o_modtype = xcoff_data (abfd)->modtype;
4260
      if (xcoff_data (abfd)->cputype != -1)
4261
  internal_a.o_cputype = xcoff_data (abfd)->cputype;
4262
      else
4263
  {
4264
    switch (bfd_get_arch (abfd))
4265
      {
4266
      case bfd_arch_rs6000:
4267
        internal_a.o_cputype = 4;
4268
        break;
4269
      case bfd_arch_powerpc:
4270
        if (bfd_get_mach (abfd) == bfd_mach_ppc)
4271
    internal_a.o_cputype = 3;
4272
        else if (bfd_get_mach (abfd) == bfd_mach_ppc_620)
4273
    internal_a.o_cputype = 2;
4274
        else
4275
    internal_a.o_cputype = 1;
4276
        break;
4277
      default:
4278
        abort ();
4279
      }
4280
  }
4281
      internal_a.o_maxstack = xcoff_data (abfd)->maxstack;
4282
      internal_a.o_maxdata = xcoff_data (abfd)->maxdata;
4283
    }
4284
#endif
4285
4286
#ifdef COFF_WITH_PE
4287
  {
4288
    /* After object contents are finalized so we can compute a reasonable hash,
4289
       but before header is written so we can update it to point to debug directory.  */
4290
    struct pe_tdata *pe = pe_data (abfd);
4291
4292
    if (pe->build_id.after_write_object_contents != NULL)
4293
      (*pe->build_id.after_write_object_contents) (abfd);
4294
  }
4295
#endif
4296
4297
  /* Now write header.  */
4298
2
  if (bfd_seek (abfd, 0, SEEK_SET) != 0)
4299
0
    return false;
4300
4301
2
  {
4302
2
    char * buff;
4303
2
    bfd_size_type amount = bfd_coff_filhsz (abfd);
4304
4305
2
    buff = (char *) bfd_malloc (amount);
4306
2
    if (buff == NULL)
4307
0
      return false;
4308
4309
2
    bfd_coff_swap_filehdr_out (abfd, & internal_f, buff);
4310
2
    amount = bfd_write (buff, amount, abfd);
4311
4312
2
    free (buff);
4313
4314
2
    if (amount != bfd_coff_filhsz (abfd))
4315
0
      return false;
4316
2
  }
4317
4318
2
  if (abfd->flags & EXEC_P)
4319
2
    {
4320
      /* Note that peicode.h fills in a PEAOUTHDR, not an AOUTHDR.
4321
   include/coff/pe.h sets AOUTSZ == sizeof (PEAOUTHDR)).  */
4322
2
      char * buff;
4323
2
      bfd_size_type amount = bfd_coff_aoutsz (abfd);
4324
4325
2
      buff = (char *) bfd_malloc (amount);
4326
2
      if (buff == NULL)
4327
0
  return false;
4328
4329
2
      coff_swap_aouthdr_out (abfd, & internal_a, buff);
4330
2
      amount = bfd_write (buff, amount, abfd);
4331
4332
2
      free (buff);
4333
4334
2
      if (amount != bfd_coff_aoutsz (abfd))
4335
0
  return false;
4336
4337
#ifdef COFF_IMAGE_WITH_PE
4338
      if (! coff_apply_checksum (abfd))
4339
  return false;
4340
#endif
4341
2
    }
4342
#ifdef RS6000COFF_C
4343
#ifndef XCOFF64
4344
  else
4345
    {
4346
      AOUTHDR buff;
4347
      size_t size;
4348
4349
      /* XCOFF32 seems to always write at least a small a.out header.  */
4350
      coff_swap_aouthdr_out (abfd, & internal_a, & buff);
4351
      if (xcoff_data (abfd)->full_aouthdr)
4352
  size = bfd_coff_aoutsz (abfd);
4353
      else
4354
  size = SMALL_AOUTSZ;
4355
      if (bfd_write (&buff, size, abfd) != size)
4356
  return false;
4357
    }
4358
#endif
4359
#endif
4360
4361
2
  return true;
4362
2
}
coff64-rs6000.c:coff_write_object_contents
Line
Count
Source
3486
1
{
3487
1
  asection *current;
3488
1
  bool hasrelocs = false;
3489
1
  bool haslinno = false;
3490
#ifdef COFF_IMAGE_WITH_PE
3491
  bool hasdebug = false;
3492
#endif
3493
1
  file_ptr scn_base;
3494
1
  file_ptr reloc_base;
3495
1
  file_ptr lineno_base;
3496
1
  file_ptr sym_base;
3497
1
  unsigned long reloc_size = 0, reloc_count = 0;
3498
1
  unsigned long lnno_size = 0;
3499
1
  bool long_section_names;
3500
1
  asection *text_sec = NULL;
3501
1
  asection *data_sec = NULL;
3502
1
  asection *bss_sec = NULL;
3503
1
#ifdef RS6000COFF_C
3504
1
  asection *tdata_sec = NULL;
3505
1
  asection *tbss_sec = NULL;
3506
1
#endif
3507
1
  struct internal_filehdr internal_f;
3508
1
  struct internal_aouthdr internal_a;
3509
#ifdef COFF_LONG_SECTION_NAMES
3510
  size_t string_size = STRING_SIZE_SIZE;
3511
#endif
3512
3513
1
  bfd_set_error (bfd_error_system_call);
3514
3515
  /* Make a pass through the symbol table to count line number entries and
3516
     put them into the correct asections.  */
3517
1
  lnno_size = coff_count_linenumbers (abfd) * bfd_coff_linesz (abfd);
3518
3519
1
  if (! abfd->output_has_begun)
3520
1
    {
3521
1
      if (! coff_compute_section_file_positions (abfd))
3522
0
  return false;
3523
1
    }
3524
3525
1
  reloc_base = obj_relocbase (abfd);
3526
3527
  /* Work out the size of the reloc and linno areas.  */
3528
3529
1
  for (current = abfd->sections; current != NULL; current =
3530
0
       current->next)
3531
0
    {
3532
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3533
      /* We store the actual reloc count in the first reloc's addr.  */
3534
      if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3535
  reloc_count ++;
3536
#endif
3537
0
      reloc_count += current->reloc_count;
3538
0
    }
3539
3540
1
  reloc_size = reloc_count * bfd_coff_relsz (abfd);
3541
3542
1
  lineno_base = reloc_base + reloc_size;
3543
1
  sym_base = lineno_base + lnno_size;
3544
3545
  /* Indicate in each section->line_filepos its actual file address.  */
3546
1
  for (current = abfd->sections; current != NULL; current =
3547
0
       current->next)
3548
0
    {
3549
0
      if (current->lineno_count)
3550
0
  {
3551
0
    current->line_filepos = lineno_base;
3552
0
    current->moving_line_filepos = lineno_base;
3553
0
    lineno_base += current->lineno_count * bfd_coff_linesz (abfd);
3554
0
  }
3555
0
      else
3556
0
  current->line_filepos = 0;
3557
3558
0
      if (current->reloc_count)
3559
0
  {
3560
0
    current->rel_filepos = reloc_base;
3561
0
    reloc_base += current->reloc_count * bfd_coff_relsz (abfd);
3562
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3563
    /* Extra reloc to hold real count.  */
3564
    if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3565
      reloc_base += bfd_coff_relsz (abfd);
3566
#endif
3567
0
  }
3568
0
      else
3569
0
  current->rel_filepos = 0;
3570
0
    }
3571
3572
  /* Write section headers to the file.  */
3573
1
  internal_f.f_nscns = 0;
3574
3575
1
  if ((abfd->flags & EXEC_P) != 0)
3576
0
    scn_base = bfd_coff_filhsz (abfd) + bfd_coff_aoutsz (abfd);
3577
1
  else
3578
1
    {
3579
1
      scn_base = bfd_coff_filhsz (abfd);
3580
1
#ifdef RS6000COFF_C
3581
#ifndef XCOFF64
3582
      if (xcoff_data (abfd)->full_aouthdr)
3583
  scn_base += bfd_coff_aoutsz (abfd);
3584
      else
3585
  scn_base += SMALL_AOUTSZ;
3586
#endif
3587
1
#endif
3588
1
    }
3589
3590
1
  if (bfd_seek (abfd, scn_base, SEEK_SET) != 0)
3591
0
    return false;
3592
3593
1
  long_section_names = false;
3594
1
  for (current = abfd->sections;
3595
1
       current != NULL;
3596
1
       current = current->next)
3597
0
    {
3598
0
      struct internal_scnhdr section;
3599
#ifdef COFF_IMAGE_WITH_PE
3600
      bool is_reloc_section = false;
3601
3602
      if (strcmp (current->name, DOT_RELOC) == 0)
3603
  {
3604
    is_reloc_section = true;
3605
    hasrelocs = true;
3606
    pe_data (abfd)->has_reloc_section = 1;
3607
  }
3608
#endif
3609
3610
0
      internal_f.f_nscns++;
3611
3612
0
      strncpy (section.s_name, current->name, SCNNMLEN);
3613
3614
#ifdef COFF_LONG_SECTION_NAMES
3615
      /* Handle long section names as in PE.  This must be compatible
3616
   with the code in coff_write_symbols and _bfd_coff_final_link.  */
3617
      if (bfd_coff_long_section_names (abfd))
3618
  {
3619
    size_t len;
3620
3621
    len = strlen (current->name);
3622
    if (len > SCNNMLEN)
3623
      {
3624
3625
        /* An inherent limitation of the /nnnnnnn notation used to indicate
3626
     the offset of the long name in the string table is that we
3627
     cannot address entries beyone the ten million byte boundary.  */
3628
        if (string_size < 10000000)
3629
    {
3630
      /* The s_name field is defined to be NUL-padded but need not
3631
         be NUL-terminated.  We use a temporary buffer so that we
3632
         can still sprintf all eight chars without splatting a
3633
         terminating NUL over the first byte of the following
3634
         member (s_paddr).  */
3635
      /* PR 21096: The +20 is to stop a bogus warning from gcc7
3636
         about a possible buffer overflow.  */
3637
      char s_name_buf[SCNNMLEN + 1 + 20];
3638
3639
      /* We do not need to use snprintf here as we have already
3640
         verified that string_size is not too big, plus we have
3641
         an overlarge buffer, just in case.  */
3642
      sprintf (s_name_buf, "/%lu", (unsigned long) string_size);
3643
      /* Then strncpy takes care of any padding for us.  */
3644
      strncpy (section.s_name, s_name_buf, SCNNMLEN);
3645
    }
3646
        else
3647
#ifdef COFF_WITH_PE
3648
    {
3649
      /* PE use a base 64 encoding for long section names whose
3650
         index is very large.  But contrary to RFC 4648, there is
3651
         no padding: 6 characters must be generated.  */
3652
      static const char base64[] =
3653
        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
3654
        "abcdefghijklmnopqrstuvwxyz"
3655
        "0123456789+/";
3656
      unsigned long off = string_size;
3657
      unsigned i;
3658
3659
      section.s_name[0] = '/';
3660
      section.s_name[1] = '/';
3661
      for (i = SCNNMLEN - 1; i >= 2; i--)
3662
        {
3663
          section.s_name[i] = base64[off & 0x3f];
3664
          off >>= 6;
3665
        }
3666
    }
3667
#endif
3668
        if (string_size > 0xffffffffUL - (len + 1)
3669
#ifndef COFF_WITH_PE
3670
      || string_size >= 10000000
3671
#endif
3672
      )
3673
    {
3674
      bfd_set_error (bfd_error_file_too_big);
3675
      _bfd_error_handler
3676
        /* xgettext:c-format */
3677
        (_("%pB: section %pA: string table overflow at offset %ld"),
3678
        abfd, current, (unsigned long) string_size);
3679
      return false;
3680
    }
3681
3682
        string_size += len + 1;
3683
        long_section_names = true;
3684
      }
3685
  }
3686
#endif
3687
3688
#ifdef _LIB
3689
      /* Always set s_vaddr of .lib to 0.  This is right for SVR3.2
3690
   Ian Taylor <ian@cygnus.com>.  */
3691
      if (strcmp (current->name, _LIB) == 0)
3692
  section.s_vaddr = 0;
3693
      else
3694
#endif
3695
0
      section.s_vaddr = current->vma;
3696
0
      section.s_paddr = current->lma;
3697
0
      section.s_size =  current->size;
3698
#ifdef coff_get_section_load_page
3699
      section.s_page = coff_get_section_load_page (current);
3700
#else
3701
0
      section.s_page = 0;
3702
0
#endif
3703
3704
#ifdef COFF_WITH_PE
3705
      section.s_paddr = 0;
3706
#endif
3707
#ifdef COFF_IMAGE_WITH_PE
3708
      /* Reminder: s_paddr holds the virtual size of the section.  */
3709
      if (coff_section_data (abfd, current) != NULL
3710
    && pei_section_data (abfd, current) != NULL)
3711
  section.s_paddr = pei_section_data (abfd, current)->virt_size;
3712
      else
3713
  section.s_paddr = 0;
3714
#endif
3715
3716
      /* If this section has no size or is unloadable then the scnptr
3717
   will be 0 too.  */
3718
0
      if (current->size == 0
3719
0
    || (current->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
3720
0
  section.s_scnptr = 0;
3721
0
      else
3722
0
  section.s_scnptr = current->filepos;
3723
3724
0
      section.s_relptr = current->rel_filepos;
3725
0
      section.s_lnnoptr = current->line_filepos;
3726
0
      section.s_nreloc = current->reloc_count;
3727
0
      section.s_nlnno = current->lineno_count;
3728
0
#ifndef COFF_IMAGE_WITH_PE
3729
      /* In PEI, relocs come in the .reloc section.  */
3730
0
      if (current->reloc_count != 0)
3731
0
  hasrelocs = true;
3732
0
#endif
3733
0
      if (current->lineno_count != 0)
3734
0
  haslinno = true;
3735
#ifdef COFF_IMAGE_WITH_PE
3736
      if ((current->flags & SEC_DEBUGGING) != 0
3737
    && ! is_reloc_section)
3738
  hasdebug = true;
3739
#endif
3740
3741
0
#ifdef RS6000COFF_C
3742
#ifndef XCOFF64
3743
      /* Indicate the use of an XCOFF overflow section header.  */
3744
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3745
  {
3746
    section.s_nreloc = 0xffff;
3747
    section.s_nlnno = 0xffff;
3748
  }
3749
#endif
3750
0
#endif
3751
3752
0
      section.s_flags = sec_to_styp_flags (current->name, current->flags);
3753
3754
0
      if (!strcmp (current->name, _TEXT))
3755
0
  text_sec = current;
3756
0
      else if (!strcmp (current->name, _DATA))
3757
0
  data_sec = current;
3758
0
      else if (!strcmp (current->name, _BSS))
3759
0
  bss_sec = current;
3760
0
#ifdef RS6000COFF_C
3761
0
      else if (!strcmp (current->name, _TDATA))
3762
0
  tdata_sec = current;
3763
0
      else if (!strcmp (current->name, _TBSS))
3764
0
  tbss_sec = current;
3765
0
#endif
3766
3767
3768
#ifdef COFF_ENCODE_ALIGNMENT
3769
      if (COFF_ENCODE_ALIGNMENT (abfd, section, current->alignment_power)
3770
    && (COFF_DECODE_ALIGNMENT (section.s_flags)
3771
        != current->alignment_power))
3772
  {
3773
    bool warn = (coff_data (abfd)->link_info
3774
           && !bfd_link_relocatable (coff_data (abfd)->link_info));
3775
3776
    _bfd_error_handler
3777
      /* xgettext:c-format */
3778
      (_("%pB:%s section %s: alignment 2**%u not representable"),
3779
       abfd, warn ? " warning:" : "", current->name,
3780
       current->alignment_power);
3781
    if (!warn)
3782
      {
3783
        bfd_set_error (bfd_error_nonrepresentable_section);
3784
        return false;
3785
      }
3786
  }
3787
#endif
3788
3789
#ifdef COFF_IMAGE_WITH_PE
3790
      /* Suppress output of the sections if they are null.  ld
3791
   includes the bss and data sections even if there is no size
3792
   assigned to them.  NT loader doesn't like it if these section
3793
   headers are included if the sections themselves are not
3794
   needed.  See also coff_compute_section_file_positions.  */
3795
      if (section.s_size == 0)
3796
  internal_f.f_nscns--;
3797
      else
3798
#endif
3799
0
  {
3800
0
    SCNHDR buff;
3801
0
    bfd_size_type amt = bfd_coff_scnhsz (abfd);
3802
3803
0
    if (bfd_coff_swap_scnhdr_out (abfd, &section, &buff) == 0
3804
0
        || bfd_write (& buff, amt, abfd) != amt)
3805
0
      return false;
3806
0
  }
3807
3808
#ifdef COFF_WITH_PE
3809
      /* PE stores COMDAT section information in the symbol table.  If
3810
   this section is supposed to have some COMDAT info, track down
3811
   the symbol in the symbol table and modify it.  */
3812
      if ((current->flags & SEC_LINK_ONCE) != 0)
3813
  {
3814
    unsigned int i, count;
3815
    asymbol **psym;
3816
    coff_symbol_type *csym = NULL;
3817
    asymbol **psymsec;
3818
3819
    psymsec = NULL;
3820
    count = bfd_get_symcount (abfd);
3821
    for (i = 0, psym = abfd->outsymbols; i < count; i++, psym++)
3822
      {
3823
        if ((*psym)->section != current)
3824
    continue;
3825
3826
        /* Remember the location of the first symbol in this
3827
     section.  */
3828
        if (psymsec == NULL)
3829
    psymsec = psym;
3830
3831
        /* See if this is the section symbol.  */
3832
        if (strcmp ((*psym)->name, current->name) == 0)
3833
    {
3834
      csym = coff_symbol_from (*psym);
3835
      if (csym == NULL
3836
          || csym->native == NULL
3837
          || ! csym->native->is_sym
3838
          || csym->native->u.syment.n_numaux < 1
3839
          || csym->native->u.syment.n_sclass != C_STAT
3840
          || csym->native->u.syment.n_type != T_NULL)
3841
        continue;
3842
3843
      /* Here *PSYM is the section symbol for CURRENT.  */
3844
3845
      break;
3846
    }
3847
      }
3848
3849
    /* Did we find it?
3850
       Note that we might not if we're converting the file from
3851
       some other object file format.  */
3852
    if (i < count)
3853
      {
3854
        combined_entry_type *aux;
3855
3856
        /* We don't touch the x_checksum field.  The
3857
     x_associated field is not currently supported.  */
3858
3859
        aux = csym->native + 1;
3860
        BFD_ASSERT (! aux->is_sym);
3861
        switch (current->flags & SEC_LINK_DUPLICATES)
3862
    {
3863
    case SEC_LINK_DUPLICATES_DISCARD:
3864
      aux->u.auxent.x_scn.x_comdat = IMAGE_COMDAT_SELECT_ANY;
3865
      break;
3866
3867
    case SEC_LINK_DUPLICATES_ONE_ONLY:
3868
      aux->u.auxent.x_scn.x_comdat =
3869
        IMAGE_COMDAT_SELECT_NODUPLICATES;
3870
      break;
3871
3872
    case SEC_LINK_DUPLICATES_SAME_SIZE:
3873
      aux->u.auxent.x_scn.x_comdat =
3874
        IMAGE_COMDAT_SELECT_SAME_SIZE;
3875
      break;
3876
3877
    case SEC_LINK_DUPLICATES_SAME_CONTENTS:
3878
      aux->u.auxent.x_scn.x_comdat =
3879
        IMAGE_COMDAT_SELECT_EXACT_MATCH;
3880
      break;
3881
    }
3882
3883
        /* The COMDAT symbol must be the first symbol from this
3884
     section in the symbol table.  In order to make this
3885
     work, we move the COMDAT symbol before the first
3886
     symbol we found in the search above.  It's OK to
3887
     rearrange the symbol table at this point, because
3888
     coff_renumber_symbols is going to rearrange it
3889
     further and fix up all the aux entries.  */
3890
        if (psym != psymsec)
3891
    {
3892
      asymbol *hold;
3893
      asymbol **pcopy;
3894
3895
      hold = *psym;
3896
      for (pcopy = psym; pcopy > psymsec; pcopy--)
3897
        pcopy[0] = pcopy[-1];
3898
      *psymsec = hold;
3899
    }
3900
      }
3901
  }
3902
#endif /* COFF_WITH_PE */
3903
0
    }
3904
3905
1
#ifdef RS6000COFF_C
3906
#ifndef XCOFF64
3907
  /* XCOFF handles overflows in the reloc and line number count fields
3908
     by creating a new section header to hold the correct values.  */
3909
  for (current = abfd->sections; current != NULL; current = current->next)
3910
    {
3911
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3912
  {
3913
    struct internal_scnhdr scnhdr;
3914
    SCNHDR buff;
3915
    bfd_size_type amt;
3916
3917
    internal_f.f_nscns++;
3918
    memcpy (scnhdr.s_name, ".ovrflo", 8);
3919
    scnhdr.s_paddr = current->reloc_count;
3920
    scnhdr.s_vaddr = current->lineno_count;
3921
    scnhdr.s_size = 0;
3922
    scnhdr.s_scnptr = 0;
3923
    scnhdr.s_relptr = current->rel_filepos;
3924
    scnhdr.s_lnnoptr = current->line_filepos;
3925
    scnhdr.s_nreloc = current->target_index;
3926
    scnhdr.s_nlnno = current->target_index;
3927
    scnhdr.s_flags = STYP_OVRFLO;
3928
    amt = bfd_coff_scnhsz (abfd);
3929
    if (bfd_coff_swap_scnhdr_out (abfd, &scnhdr, &buff) == 0
3930
        || bfd_write (& buff, amt, abfd) != amt)
3931
      return false;
3932
  }
3933
    }
3934
#endif
3935
1
#endif
3936
3937
#if defined (COFF_GO32_EXE) || defined (COFF_GO32)
3938
  /* Pad section headers.  */
3939
  if ((abfd->flags & EXEC_P) != 0)
3940
    {
3941
      asection *s = abfd->sections;
3942
      while (s != NULL && s->filepos == 0)
3943
  s = s->next;
3944
      if (s != NULL)
3945
  {
3946
    file_ptr cur_ptr
3947
      = scn_base + abfd->section_count * bfd_coff_scnhsz (abfd);
3948
    file_ptr fill_size = s->filepos - cur_ptr;
3949
    if (fill_size > 0)
3950
      {
3951
        bfd_byte *b = bfd_zmalloc (fill_size);
3952
        if (!b)
3953
    return false;
3954
        if (bfd_write (b, fill_size, abfd) != (ufile_ptr) fill_size)
3955
    {
3956
      free (b);
3957
      return false;
3958
    }
3959
        free (b);
3960
      }
3961
  }
3962
    }
3963
#endif
3964
3965
  /* OK, now set up the filehdr...  */
3966
3967
  /* Don't include the internal abs section in the section count */
3968
3969
  /* We will NOT put a fucking timestamp in the header here. Every time you
3970
     put it back, I will come in and take it out again.  I'm sorry.  This
3971
     field does not belong here.  We fill it with a 0 so it compares the
3972
     same but is not a reasonable time. -- gnu@cygnus.com  */
3973
1
  internal_f.f_timdat = 0;
3974
1
  internal_f.f_flags = 0;
3975
3976
1
  if (abfd->flags & EXEC_P)
3977
0
    internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3978
1
  else
3979
1
    {
3980
1
      internal_f.f_opthdr = 0;
3981
1
#ifdef RS6000COFF_C
3982
#ifndef XCOFF64
3983
      if (xcoff_data (abfd)->full_aouthdr)
3984
  internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3985
      else
3986
  internal_f.f_opthdr = SMALL_AOUTSZ;
3987
#endif
3988
1
#endif
3989
1
    }
3990
3991
1
  if (!hasrelocs)
3992
1
    internal_f.f_flags |= F_RELFLG;
3993
1
  if (!haslinno)
3994
1
    internal_f.f_flags |= F_LNNO;
3995
1
  if (abfd->flags & EXEC_P)
3996
0
    internal_f.f_flags |= F_EXEC;
3997
#ifdef COFF_IMAGE_WITH_PE
3998
  if (! hasdebug)
3999
    internal_f.f_flags |= IMAGE_FILE_DEBUG_STRIPPED;
4000
  if (pe_data (abfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
4001
    internal_f.f_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
4002
#endif
4003
4004
1
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
4005
#ifdef COFF_WITH_PE
4006
  internal_f.f_flags |= IMAGE_FILE_32BIT_MACHINE;
4007
#else
4008
1
  if (bfd_little_endian (abfd))
4009
0
    internal_f.f_flags |= F_AR32WR;
4010
1
  else
4011
1
    internal_f.f_flags |= F_AR32W;
4012
1
#endif
4013
1
#endif
4014
4015
#ifdef TI_TARGET_ID
4016
  /* Target id is used in TI COFF v1 and later; COFF0 won't use this field,
4017
     but it doesn't hurt to set it internally.  */
4018
  internal_f.f_target_id = TI_TARGET_ID;
4019
#endif
4020
4021
  /* FIXME, should do something about the other byte orders and
4022
     architectures.  */
4023
4024
1
#ifdef RS6000COFF_C
4025
1
  if ((abfd->flags & DYNAMIC) != 0)
4026
0
    internal_f.f_flags |= F_SHROBJ;
4027
1
  if (bfd_get_section_by_name (abfd, _LOADER) != NULL)
4028
0
    internal_f.f_flags |= F_DYNLOAD;
4029
1
#endif
4030
4031
1
  memset (&internal_a, 0, sizeof internal_a);
4032
4033
  /* Set up architecture-dependent stuff.  */
4034
1
  {
4035
1
    unsigned int magic = 0;
4036
1
    unsigned short flags = 0;
4037
4038
1
    coff_set_flags (abfd, &magic, &flags);
4039
1
    internal_f.f_magic = magic;
4040
1
    internal_f.f_flags |= flags;
4041
    /* ...and the "opt"hdr...  */
4042
4043
#ifdef TICOFF_AOUT_MAGIC
4044
    internal_a.magic = TICOFF_AOUT_MAGIC;
4045
#define __A_MAGIC_SET__
4046
#endif
4047
4048
#if defined(ARM)
4049
#define __A_MAGIC_SET__
4050
    internal_a.magic = ZMAGIC;
4051
#endif
4052
4053
#if defined(AARCH64)
4054
#define __A_MAGIC_SET__
4055
    internal_a.magic = ZMAGIC;
4056
#endif
4057
4058
#if defined(LOONGARCH64)
4059
#define __A_MAGIC_SET__
4060
    internal_a.magic = ZMAGIC;
4061
#endif
4062
4063
#if defined MCORE_PE
4064
#define __A_MAGIC_SET__
4065
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR_MAGIC;
4066
#endif
4067
4068
#if defined(I386)
4069
#define __A_MAGIC_SET__
4070
#if defined LYNXOS
4071
    internal_a.magic = LYNXCOFFMAGIC;
4072
#elif defined AMD64
4073
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR64_MAGIC;
4074
#else
4075
    internal_a.magic = ZMAGIC;
4076
#endif
4077
#endif /* I386 */
4078
4079
#if defined(IA64)
4080
#define __A_MAGIC_SET__
4081
    internal_a.magic = PE32PMAGIC;
4082
#endif /* IA64 */
4083
4084
#if defined(SPARC)
4085
#define __A_MAGIC_SET__
4086
#if defined(LYNXOS)
4087
    internal_a.magic = LYNXCOFFMAGIC;
4088
#endif /* LYNXOS */
4089
#endif /* SPARC */
4090
4091
1
#ifdef RS6000COFF_C
4092
1
#define __A_MAGIC_SET__
4093
1
    internal_a.magic = (abfd->flags & D_PAGED) ? RS6K_AOUTHDR_ZMAGIC :
4094
1
    (abfd->flags & WP_TEXT) ? RS6K_AOUTHDR_NMAGIC :
4095
1
    RS6K_AOUTHDR_OMAGIC;
4096
1
#endif
4097
4098
#if defined(SH) && defined(COFF_WITH_PE)
4099
#define __A_MAGIC_SET__
4100
    internal_a.magic = SH_PE_MAGIC;
4101
#endif
4102
4103
#if defined(MIPS) && defined(COFF_WITH_PE)
4104
#define __A_MAGIC_SET__
4105
    internal_a.magic = MIPS_PE_MAGIC;
4106
#endif
4107
4108
#ifndef __A_MAGIC_SET__
4109
#include "Your aouthdr magic number is not being set!"
4110
#else
4111
1
#undef __A_MAGIC_SET__
4112
1
#endif
4113
1
  }
4114
4115
1
#ifdef RS6000COFF_C
4116
  /* XCOFF 32bit needs this to have new behaviour for n_type field.  */
4117
1
  internal_a.vstamp = 2;
4118
#else
4119
  /* FIXME: Does anybody ever set this to another value?  */
4120
  internal_a.vstamp = 0;
4121
#endif
4122
4123
  /* Now should write relocs, strings, syms.  */
4124
1
  obj_sym_filepos (abfd) = sym_base;
4125
4126
1
  if (bfd_get_symcount (abfd) != 0)
4127
0
    {
4128
0
      int firstundef;
4129
4130
0
      if (!coff_renumber_symbols (abfd, &firstundef))
4131
0
  return false;
4132
0
      coff_mangle_symbols (abfd);
4133
0
      if (! coff_write_symbols (abfd))
4134
0
  return false;
4135
0
      if (! coff_write_linenumbers (abfd))
4136
0
  return false;
4137
0
      if (! coff_write_relocs (abfd, firstundef))
4138
0
  return false;
4139
0
    }
4140
#ifdef COFF_LONG_SECTION_NAMES
4141
  else if (long_section_names && ! obj_coff_strings_written (abfd))
4142
    {
4143
      /* If we have long section names we have to write out the string
4144
   table even if there are no symbols.  */
4145
      if (! coff_write_symbols (abfd))
4146
  return false;
4147
    }
4148
#endif
4149
  /* If bfd_get_symcount (abfd) != 0, then we are not using the COFF
4150
     backend linker, and obj_raw_syment_count is not valid until after
4151
     coff_write_symbols is called.  */
4152
1
  if (obj_raw_syment_count (abfd) != 0)
4153
0
    {
4154
0
      internal_f.f_symptr = sym_base;
4155
0
#ifdef RS6000COFF_C
4156
      /* AIX appears to require that F_RELFLG not be set if there are
4157
   local symbols but no relocations.  */
4158
0
      internal_f.f_flags &=~ F_RELFLG;
4159
0
#endif
4160
0
    }
4161
1
  else
4162
1
    {
4163
1
      if (long_section_names)
4164
0
  internal_f.f_symptr = sym_base;
4165
1
      else
4166
1
  internal_f.f_symptr = 0;
4167
1
      internal_f.f_flags |= F_LSYMS;
4168
1
    }
4169
4170
1
  if (text_sec)
4171
0
    {
4172
0
      internal_a.tsize = text_sec->size;
4173
0
      internal_a.text_start = internal_a.tsize ? text_sec->vma : 0;
4174
0
    }
4175
1
  if (data_sec)
4176
0
    {
4177
0
      internal_a.dsize = data_sec->size;
4178
0
      internal_a.data_start = internal_a.dsize ? data_sec->vma : 0;
4179
0
    }
4180
1
  if (bss_sec)
4181
0
    {
4182
0
      internal_a.bsize = bss_sec->size;
4183
0
      if (internal_a.bsize && bss_sec->vma < internal_a.data_start)
4184
0
  internal_a.data_start = bss_sec->vma;
4185
0
    }
4186
4187
1
  internal_a.entry = bfd_get_start_address (abfd);
4188
1
  internal_f.f_nsyms = obj_raw_syment_count (abfd);
4189
4190
1
#ifdef RS6000COFF_C
4191
1
  if (xcoff_data (abfd)->full_aouthdr)
4192
0
    {
4193
0
      bfd_vma toc;
4194
0
      asection *loader_sec;
4195
4196
0
      internal_a.vstamp = 2;
4197
4198
0
      internal_a.o_snentry = xcoff_data (abfd)->snentry;
4199
0
      if (internal_a.o_snentry == 0)
4200
0
  internal_a.entry = (bfd_vma) -1;
4201
4202
0
      if (text_sec != NULL)
4203
0
  {
4204
0
    internal_a.o_sntext = text_sec->target_index;
4205
0
    internal_a.o_algntext = bfd_section_alignment (text_sec);
4206
0
  }
4207
0
      else
4208
0
  {
4209
0
    internal_a.o_sntext = 0;
4210
0
    internal_a.o_algntext = 0;
4211
0
  }
4212
0
      if (data_sec != NULL)
4213
0
  {
4214
0
    internal_a.o_sndata = data_sec->target_index;
4215
0
    internal_a.o_algndata = bfd_section_alignment (data_sec);
4216
0
  }
4217
0
      else
4218
0
  {
4219
0
    internal_a.o_sndata = 0;
4220
0
    internal_a.o_algndata = 0;
4221
0
  }
4222
0
      loader_sec = bfd_get_section_by_name (abfd, ".loader");
4223
0
      if (loader_sec != NULL)
4224
0
  internal_a.o_snloader = loader_sec->target_index;
4225
0
      else
4226
0
  internal_a.o_snloader = 0;
4227
0
      if (bss_sec != NULL)
4228
0
  internal_a.o_snbss = bss_sec->target_index;
4229
0
      else
4230
0
  internal_a.o_snbss = 0;
4231
4232
0
      if (tdata_sec != NULL)
4233
0
  {
4234
0
    internal_a.o_sntdata = tdata_sec->target_index;
4235
    /* TODO: o_flags should be set to RS6K_AOUTHDR_TLS_LE
4236
       if there is at least one R_TLS_LE relocations.  */
4237
0
    internal_a.o_flags = 0;
4238
0
#ifdef XCOFF64
4239
0
    internal_a.o_x64flags = 0;
4240
0
#endif
4241
0
  }
4242
0
      else
4243
0
  {
4244
0
    internal_a.o_sntdata = 0;
4245
0
    internal_a.o_flags = 0;
4246
0
#ifdef XCOFF64
4247
0
    internal_a.o_x64flags = 0;
4248
0
#endif
4249
0
  }
4250
0
      if (tbss_sec != NULL)
4251
0
    internal_a.o_sntbss = tbss_sec->target_index;
4252
0
      else
4253
0
    internal_a.o_sntbss = 0;
4254
4255
0
      toc = xcoff_data (abfd)->toc;
4256
0
      internal_a.o_toc = toc;
4257
0
      internal_a.o_sntoc = xcoff_data (abfd)->sntoc;
4258
4259
0
      internal_a.o_modtype = xcoff_data (abfd)->modtype;
4260
0
      if (xcoff_data (abfd)->cputype != -1)
4261
0
  internal_a.o_cputype = xcoff_data (abfd)->cputype;
4262
0
      else
4263
0
  {
4264
0
    switch (bfd_get_arch (abfd))
4265
0
      {
4266
0
      case bfd_arch_rs6000:
4267
0
        internal_a.o_cputype = 4;
4268
0
        break;
4269
0
      case bfd_arch_powerpc:
4270
0
        if (bfd_get_mach (abfd) == bfd_mach_ppc)
4271
0
    internal_a.o_cputype = 3;
4272
0
        else if (bfd_get_mach (abfd) == bfd_mach_ppc_620)
4273
0
    internal_a.o_cputype = 2;
4274
0
        else
4275
0
    internal_a.o_cputype = 1;
4276
0
        break;
4277
0
      default:
4278
0
        abort ();
4279
0
      }
4280
0
  }
4281
0
      internal_a.o_maxstack = xcoff_data (abfd)->maxstack;
4282
0
      internal_a.o_maxdata = xcoff_data (abfd)->maxdata;
4283
0
    }
4284
1
#endif
4285
4286
#ifdef COFF_WITH_PE
4287
  {
4288
    /* After object contents are finalized so we can compute a reasonable hash,
4289
       but before header is written so we can update it to point to debug directory.  */
4290
    struct pe_tdata *pe = pe_data (abfd);
4291
4292
    if (pe->build_id.after_write_object_contents != NULL)
4293
      (*pe->build_id.after_write_object_contents) (abfd);
4294
  }
4295
#endif
4296
4297
  /* Now write header.  */
4298
1
  if (bfd_seek (abfd, 0, SEEK_SET) != 0)
4299
0
    return false;
4300
4301
1
  {
4302
1
    char * buff;
4303
1
    bfd_size_type amount = bfd_coff_filhsz (abfd);
4304
4305
1
    buff = (char *) bfd_malloc (amount);
4306
1
    if (buff == NULL)
4307
0
      return false;
4308
4309
1
    bfd_coff_swap_filehdr_out (abfd, & internal_f, buff);
4310
1
    amount = bfd_write (buff, amount, abfd);
4311
4312
1
    free (buff);
4313
4314
1
    if (amount != bfd_coff_filhsz (abfd))
4315
0
      return false;
4316
1
  }
4317
4318
1
  if (abfd->flags & EXEC_P)
4319
0
    {
4320
      /* Note that peicode.h fills in a PEAOUTHDR, not an AOUTHDR.
4321
   include/coff/pe.h sets AOUTSZ == sizeof (PEAOUTHDR)).  */
4322
0
      char * buff;
4323
0
      bfd_size_type amount = bfd_coff_aoutsz (abfd);
4324
4325
0
      buff = (char *) bfd_malloc (amount);
4326
0
      if (buff == NULL)
4327
0
  return false;
4328
4329
0
      coff_swap_aouthdr_out (abfd, & internal_a, buff);
4330
0
      amount = bfd_write (buff, amount, abfd);
4331
4332
0
      free (buff);
4333
4334
0
      if (amount != bfd_coff_aoutsz (abfd))
4335
0
  return false;
4336
4337
#ifdef COFF_IMAGE_WITH_PE
4338
      if (! coff_apply_checksum (abfd))
4339
  return false;
4340
#endif
4341
0
    }
4342
1
#ifdef RS6000COFF_C
4343
#ifndef XCOFF64
4344
  else
4345
    {
4346
      AOUTHDR buff;
4347
      size_t size;
4348
4349
      /* XCOFF32 seems to always write at least a small a.out header.  */
4350
      coff_swap_aouthdr_out (abfd, & internal_a, & buff);
4351
      if (xcoff_data (abfd)->full_aouthdr)
4352
  size = bfd_coff_aoutsz (abfd);
4353
      else
4354
  size = SMALL_AOUTSZ;
4355
      if (bfd_write (&buff, size, abfd) != size)
4356
  return false;
4357
    }
4358
#endif
4359
1
#endif
4360
4361
1
  return true;
4362
1
}
pe-aarch64.c:coff_write_object_contents
Line
Count
Source
3486
1
{
3487
1
  asection *current;
3488
1
  bool hasrelocs = false;
3489
1
  bool haslinno = false;
3490
#ifdef COFF_IMAGE_WITH_PE
3491
  bool hasdebug = false;
3492
#endif
3493
1
  file_ptr scn_base;
3494
1
  file_ptr reloc_base;
3495
1
  file_ptr lineno_base;
3496
1
  file_ptr sym_base;
3497
1
  unsigned long reloc_size = 0, reloc_count = 0;
3498
1
  unsigned long lnno_size = 0;
3499
1
  bool long_section_names;
3500
1
  asection *text_sec = NULL;
3501
1
  asection *data_sec = NULL;
3502
1
  asection *bss_sec = NULL;
3503
#ifdef RS6000COFF_C
3504
  asection *tdata_sec = NULL;
3505
  asection *tbss_sec = NULL;
3506
#endif
3507
1
  struct internal_filehdr internal_f;
3508
1
  struct internal_aouthdr internal_a;
3509
1
#ifdef COFF_LONG_SECTION_NAMES
3510
1
  size_t string_size = STRING_SIZE_SIZE;
3511
1
#endif
3512
3513
1
  bfd_set_error (bfd_error_system_call);
3514
3515
  /* Make a pass through the symbol table to count line number entries and
3516
     put them into the correct asections.  */
3517
1
  lnno_size = coff_count_linenumbers (abfd) * bfd_coff_linesz (abfd);
3518
3519
1
  if (! abfd->output_has_begun)
3520
1
    {
3521
1
      if (! coff_compute_section_file_positions (abfd))
3522
0
  return false;
3523
1
    }
3524
3525
1
  reloc_base = obj_relocbase (abfd);
3526
3527
  /* Work out the size of the reloc and linno areas.  */
3528
3529
2
  for (current = abfd->sections; current != NULL; current =
3530
1
       current->next)
3531
1
    {
3532
1
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3533
      /* We store the actual reloc count in the first reloc's addr.  */
3534
1
      if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3535
0
  reloc_count ++;
3536
1
#endif
3537
1
      reloc_count += current->reloc_count;
3538
1
    }
3539
3540
1
  reloc_size = reloc_count * bfd_coff_relsz (abfd);
3541
3542
1
  lineno_base = reloc_base + reloc_size;
3543
1
  sym_base = lineno_base + lnno_size;
3544
3545
  /* Indicate in each section->line_filepos its actual file address.  */
3546
2
  for (current = abfd->sections; current != NULL; current =
3547
1
       current->next)
3548
1
    {
3549
1
      if (current->lineno_count)
3550
0
  {
3551
0
    current->line_filepos = lineno_base;
3552
0
    current->moving_line_filepos = lineno_base;
3553
0
    lineno_base += current->lineno_count * bfd_coff_linesz (abfd);
3554
0
  }
3555
1
      else
3556
1
  current->line_filepos = 0;
3557
3558
1
      if (current->reloc_count)
3559
0
  {
3560
0
    current->rel_filepos = reloc_base;
3561
0
    reloc_base += current->reloc_count * bfd_coff_relsz (abfd);
3562
0
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3563
    /* Extra reloc to hold real count.  */
3564
0
    if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3565
0
      reloc_base += bfd_coff_relsz (abfd);
3566
0
#endif
3567
0
  }
3568
1
      else
3569
1
  current->rel_filepos = 0;
3570
1
    }
3571
3572
  /* Write section headers to the file.  */
3573
1
  internal_f.f_nscns = 0;
3574
3575
1
  if ((abfd->flags & EXEC_P) != 0)
3576
0
    scn_base = bfd_coff_filhsz (abfd) + bfd_coff_aoutsz (abfd);
3577
1
  else
3578
1
    {
3579
1
      scn_base = bfd_coff_filhsz (abfd);
3580
#ifdef RS6000COFF_C
3581
#ifndef XCOFF64
3582
      if (xcoff_data (abfd)->full_aouthdr)
3583
  scn_base += bfd_coff_aoutsz (abfd);
3584
      else
3585
  scn_base += SMALL_AOUTSZ;
3586
#endif
3587
#endif
3588
1
    }
3589
3590
1
  if (bfd_seek (abfd, scn_base, SEEK_SET) != 0)
3591
0
    return false;
3592
3593
1
  long_section_names = false;
3594
1
  for (current = abfd->sections;
3595
2
       current != NULL;
3596
1
       current = current->next)
3597
1
    {
3598
1
      struct internal_scnhdr section;
3599
#ifdef COFF_IMAGE_WITH_PE
3600
      bool is_reloc_section = false;
3601
3602
      if (strcmp (current->name, DOT_RELOC) == 0)
3603
  {
3604
    is_reloc_section = true;
3605
    hasrelocs = true;
3606
    pe_data (abfd)->has_reloc_section = 1;
3607
  }
3608
#endif
3609
3610
1
      internal_f.f_nscns++;
3611
3612
1
      strncpy (section.s_name, current->name, SCNNMLEN);
3613
3614
1
#ifdef COFF_LONG_SECTION_NAMES
3615
      /* Handle long section names as in PE.  This must be compatible
3616
   with the code in coff_write_symbols and _bfd_coff_final_link.  */
3617
1
      if (bfd_coff_long_section_names (abfd))
3618
1
  {
3619
1
    size_t len;
3620
3621
1
    len = strlen (current->name);
3622
1
    if (len > SCNNMLEN)
3623
0
      {
3624
3625
        /* An inherent limitation of the /nnnnnnn notation used to indicate
3626
     the offset of the long name in the string table is that we
3627
     cannot address entries beyone the ten million byte boundary.  */
3628
0
        if (string_size < 10000000)
3629
0
    {
3630
      /* The s_name field is defined to be NUL-padded but need not
3631
         be NUL-terminated.  We use a temporary buffer so that we
3632
         can still sprintf all eight chars without splatting a
3633
         terminating NUL over the first byte of the following
3634
         member (s_paddr).  */
3635
      /* PR 21096: The +20 is to stop a bogus warning from gcc7
3636
         about a possible buffer overflow.  */
3637
0
      char s_name_buf[SCNNMLEN + 1 + 20];
3638
3639
      /* We do not need to use snprintf here as we have already
3640
         verified that string_size is not too big, plus we have
3641
         an overlarge buffer, just in case.  */
3642
0
      sprintf (s_name_buf, "/%lu", (unsigned long) string_size);
3643
      /* Then strncpy takes care of any padding for us.  */
3644
0
      strncpy (section.s_name, s_name_buf, SCNNMLEN);
3645
0
    }
3646
0
        else
3647
0
#ifdef COFF_WITH_PE
3648
0
    {
3649
      /* PE use a base 64 encoding for long section names whose
3650
         index is very large.  But contrary to RFC 4648, there is
3651
         no padding: 6 characters must be generated.  */
3652
0
      static const char base64[] =
3653
0
        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
3654
0
        "abcdefghijklmnopqrstuvwxyz"
3655
0
        "0123456789+/";
3656
0
      unsigned long off = string_size;
3657
0
      unsigned i;
3658
3659
0
      section.s_name[0] = '/';
3660
0
      section.s_name[1] = '/';
3661
0
      for (i = SCNNMLEN - 1; i >= 2; i--)
3662
0
        {
3663
0
          section.s_name[i] = base64[off & 0x3f];
3664
0
          off >>= 6;
3665
0
        }
3666
0
    }
3667
0
#endif
3668
0
        if (string_size > 0xffffffffUL - (len + 1)
3669
#ifndef COFF_WITH_PE
3670
      || string_size >= 10000000
3671
#endif
3672
0
      )
3673
0
    {
3674
0
      bfd_set_error (bfd_error_file_too_big);
3675
0
      _bfd_error_handler
3676
        /* xgettext:c-format */
3677
0
        (_("%pB: section %pA: string table overflow at offset %ld"),
3678
0
        abfd, current, (unsigned long) string_size);
3679
0
      return false;
3680
0
    }
3681
3682
0
        string_size += len + 1;
3683
0
        long_section_names = true;
3684
0
      }
3685
1
  }
3686
1
#endif
3687
3688
1
#ifdef _LIB
3689
      /* Always set s_vaddr of .lib to 0.  This is right for SVR3.2
3690
   Ian Taylor <ian@cygnus.com>.  */
3691
1
      if (strcmp (current->name, _LIB) == 0)
3692
0
  section.s_vaddr = 0;
3693
1
      else
3694
1
#endif
3695
1
      section.s_vaddr = current->vma;
3696
1
      section.s_paddr = current->lma;
3697
1
      section.s_size =  current->size;
3698
#ifdef coff_get_section_load_page
3699
      section.s_page = coff_get_section_load_page (current);
3700
#else
3701
1
      section.s_page = 0;
3702
1
#endif
3703
3704
1
#ifdef COFF_WITH_PE
3705
1
      section.s_paddr = 0;
3706
1
#endif
3707
#ifdef COFF_IMAGE_WITH_PE
3708
      /* Reminder: s_paddr holds the virtual size of the section.  */
3709
      if (coff_section_data (abfd, current) != NULL
3710
    && pei_section_data (abfd, current) != NULL)
3711
  section.s_paddr = pei_section_data (abfd, current)->virt_size;
3712
      else
3713
  section.s_paddr = 0;
3714
#endif
3715
3716
      /* If this section has no size or is unloadable then the scnptr
3717
   will be 0 too.  */
3718
1
      if (current->size == 0
3719
1
    || (current->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
3720
1
  section.s_scnptr = 0;
3721
0
      else
3722
0
  section.s_scnptr = current->filepos;
3723
3724
1
      section.s_relptr = current->rel_filepos;
3725
1
      section.s_lnnoptr = current->line_filepos;
3726
1
      section.s_nreloc = current->reloc_count;
3727
1
      section.s_nlnno = current->lineno_count;
3728
1
#ifndef COFF_IMAGE_WITH_PE
3729
      /* In PEI, relocs come in the .reloc section.  */
3730
1
      if (current->reloc_count != 0)
3731
0
  hasrelocs = true;
3732
1
#endif
3733
1
      if (current->lineno_count != 0)
3734
0
  haslinno = true;
3735
#ifdef COFF_IMAGE_WITH_PE
3736
      if ((current->flags & SEC_DEBUGGING) != 0
3737
    && ! is_reloc_section)
3738
  hasdebug = true;
3739
#endif
3740
3741
#ifdef RS6000COFF_C
3742
#ifndef XCOFF64
3743
      /* Indicate the use of an XCOFF overflow section header.  */
3744
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3745
  {
3746
    section.s_nreloc = 0xffff;
3747
    section.s_nlnno = 0xffff;
3748
  }
3749
#endif
3750
#endif
3751
3752
1
      section.s_flags = sec_to_styp_flags (current->name, current->flags);
3753
3754
1
      if (!strcmp (current->name, _TEXT))
3755
0
  text_sec = current;
3756
1
      else if (!strcmp (current->name, _DATA))
3757
0
  data_sec = current;
3758
1
      else if (!strcmp (current->name, _BSS))
3759
0
  bss_sec = current;
3760
#ifdef RS6000COFF_C
3761
      else if (!strcmp (current->name, _TDATA))
3762
  tdata_sec = current;
3763
      else if (!strcmp (current->name, _TBSS))
3764
  tbss_sec = current;
3765
#endif
3766
3767
3768
1
#ifdef COFF_ENCODE_ALIGNMENT
3769
1
      if (COFF_ENCODE_ALIGNMENT (abfd, section, current->alignment_power)
3770
1
    && (COFF_DECODE_ALIGNMENT (section.s_flags)
3771
1
        != current->alignment_power))
3772
0
  {
3773
0
    bool warn = (coff_data (abfd)->link_info
3774
0
           && !bfd_link_relocatable (coff_data (abfd)->link_info));
3775
3776
0
    _bfd_error_handler
3777
      /* xgettext:c-format */
3778
0
      (_("%pB:%s section %s: alignment 2**%u not representable"),
3779
0
       abfd, warn ? " warning:" : "", current->name,
3780
0
       current->alignment_power);
3781
0
    if (!warn)
3782
0
      {
3783
0
        bfd_set_error (bfd_error_nonrepresentable_section);
3784
0
        return false;
3785
0
      }
3786
0
  }
3787
1
#endif
3788
3789
#ifdef COFF_IMAGE_WITH_PE
3790
      /* Suppress output of the sections if they are null.  ld
3791
   includes the bss and data sections even if there is no size
3792
   assigned to them.  NT loader doesn't like it if these section
3793
   headers are included if the sections themselves are not
3794
   needed.  See also coff_compute_section_file_positions.  */
3795
      if (section.s_size == 0)
3796
  internal_f.f_nscns--;
3797
      else
3798
#endif
3799
1
  {
3800
1
    SCNHDR buff;
3801
1
    bfd_size_type amt = bfd_coff_scnhsz (abfd);
3802
3803
1
    if (bfd_coff_swap_scnhdr_out (abfd, &section, &buff) == 0
3804
1
        || bfd_write (& buff, amt, abfd) != amt)
3805
0
      return false;
3806
1
  }
3807
3808
1
#ifdef COFF_WITH_PE
3809
      /* PE stores COMDAT section information in the symbol table.  If
3810
   this section is supposed to have some COMDAT info, track down
3811
   the symbol in the symbol table and modify it.  */
3812
1
      if ((current->flags & SEC_LINK_ONCE) != 0)
3813
0
  {
3814
0
    unsigned int i, count;
3815
0
    asymbol **psym;
3816
0
    coff_symbol_type *csym = NULL;
3817
0
    asymbol **psymsec;
3818
3819
0
    psymsec = NULL;
3820
0
    count = bfd_get_symcount (abfd);
3821
0
    for (i = 0, psym = abfd->outsymbols; i < count; i++, psym++)
3822
0
      {
3823
0
        if ((*psym)->section != current)
3824
0
    continue;
3825
3826
        /* Remember the location of the first symbol in this
3827
     section.  */
3828
0
        if (psymsec == NULL)
3829
0
    psymsec = psym;
3830
3831
        /* See if this is the section symbol.  */
3832
0
        if (strcmp ((*psym)->name, current->name) == 0)
3833
0
    {
3834
0
      csym = coff_symbol_from (*psym);
3835
0
      if (csym == NULL
3836
0
          || csym->native == NULL
3837
0
          || ! csym->native->is_sym
3838
0
          || csym->native->u.syment.n_numaux < 1
3839
0
          || csym->native->u.syment.n_sclass != C_STAT
3840
0
          || csym->native->u.syment.n_type != T_NULL)
3841
0
        continue;
3842
3843
      /* Here *PSYM is the section symbol for CURRENT.  */
3844
3845
0
      break;
3846
0
    }
3847
0
      }
3848
3849
    /* Did we find it?
3850
       Note that we might not if we're converting the file from
3851
       some other object file format.  */
3852
0
    if (i < count)
3853
0
      {
3854
0
        combined_entry_type *aux;
3855
3856
        /* We don't touch the x_checksum field.  The
3857
     x_associated field is not currently supported.  */
3858
3859
0
        aux = csym->native + 1;
3860
0
        BFD_ASSERT (! aux->is_sym);
3861
0
        switch (current->flags & SEC_LINK_DUPLICATES)
3862
0
    {
3863
0
    case SEC_LINK_DUPLICATES_DISCARD:
3864
0
      aux->u.auxent.x_scn.x_comdat = IMAGE_COMDAT_SELECT_ANY;
3865
0
      break;
3866
3867
0
    case SEC_LINK_DUPLICATES_ONE_ONLY:
3868
0
      aux->u.auxent.x_scn.x_comdat =
3869
0
        IMAGE_COMDAT_SELECT_NODUPLICATES;
3870
0
      break;
3871
3872
0
    case SEC_LINK_DUPLICATES_SAME_SIZE:
3873
0
      aux->u.auxent.x_scn.x_comdat =
3874
0
        IMAGE_COMDAT_SELECT_SAME_SIZE;
3875
0
      break;
3876
3877
0
    case SEC_LINK_DUPLICATES_SAME_CONTENTS:
3878
0
      aux->u.auxent.x_scn.x_comdat =
3879
0
        IMAGE_COMDAT_SELECT_EXACT_MATCH;
3880
0
      break;
3881
0
    }
3882
3883
        /* The COMDAT symbol must be the first symbol from this
3884
     section in the symbol table.  In order to make this
3885
     work, we move the COMDAT symbol before the first
3886
     symbol we found in the search above.  It's OK to
3887
     rearrange the symbol table at this point, because
3888
     coff_renumber_symbols is going to rearrange it
3889
     further and fix up all the aux entries.  */
3890
0
        if (psym != psymsec)
3891
0
    {
3892
0
      asymbol *hold;
3893
0
      asymbol **pcopy;
3894
3895
0
      hold = *psym;
3896
0
      for (pcopy = psym; pcopy > psymsec; pcopy--)
3897
0
        pcopy[0] = pcopy[-1];
3898
0
      *psymsec = hold;
3899
0
    }
3900
0
      }
3901
0
  }
3902
1
#endif /* COFF_WITH_PE */
3903
1
    }
3904
3905
#ifdef RS6000COFF_C
3906
#ifndef XCOFF64
3907
  /* XCOFF handles overflows in the reloc and line number count fields
3908
     by creating a new section header to hold the correct values.  */
3909
  for (current = abfd->sections; current != NULL; current = current->next)
3910
    {
3911
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3912
  {
3913
    struct internal_scnhdr scnhdr;
3914
    SCNHDR buff;
3915
    bfd_size_type amt;
3916
3917
    internal_f.f_nscns++;
3918
    memcpy (scnhdr.s_name, ".ovrflo", 8);
3919
    scnhdr.s_paddr = current->reloc_count;
3920
    scnhdr.s_vaddr = current->lineno_count;
3921
    scnhdr.s_size = 0;
3922
    scnhdr.s_scnptr = 0;
3923
    scnhdr.s_relptr = current->rel_filepos;
3924
    scnhdr.s_lnnoptr = current->line_filepos;
3925
    scnhdr.s_nreloc = current->target_index;
3926
    scnhdr.s_nlnno = current->target_index;
3927
    scnhdr.s_flags = STYP_OVRFLO;
3928
    amt = bfd_coff_scnhsz (abfd);
3929
    if (bfd_coff_swap_scnhdr_out (abfd, &scnhdr, &buff) == 0
3930
        || bfd_write (& buff, amt, abfd) != amt)
3931
      return false;
3932
  }
3933
    }
3934
#endif
3935
#endif
3936
3937
#if defined (COFF_GO32_EXE) || defined (COFF_GO32)
3938
  /* Pad section headers.  */
3939
  if ((abfd->flags & EXEC_P) != 0)
3940
    {
3941
      asection *s = abfd->sections;
3942
      while (s != NULL && s->filepos == 0)
3943
  s = s->next;
3944
      if (s != NULL)
3945
  {
3946
    file_ptr cur_ptr
3947
      = scn_base + abfd->section_count * bfd_coff_scnhsz (abfd);
3948
    file_ptr fill_size = s->filepos - cur_ptr;
3949
    if (fill_size > 0)
3950
      {
3951
        bfd_byte *b = bfd_zmalloc (fill_size);
3952
        if (!b)
3953
    return false;
3954
        if (bfd_write (b, fill_size, abfd) != (ufile_ptr) fill_size)
3955
    {
3956
      free (b);
3957
      return false;
3958
    }
3959
        free (b);
3960
      }
3961
  }
3962
    }
3963
#endif
3964
3965
  /* OK, now set up the filehdr...  */
3966
3967
  /* Don't include the internal abs section in the section count */
3968
3969
  /* We will NOT put a fucking timestamp in the header here. Every time you
3970
     put it back, I will come in and take it out again.  I'm sorry.  This
3971
     field does not belong here.  We fill it with a 0 so it compares the
3972
     same but is not a reasonable time. -- gnu@cygnus.com  */
3973
1
  internal_f.f_timdat = 0;
3974
1
  internal_f.f_flags = 0;
3975
3976
1
  if (abfd->flags & EXEC_P)
3977
0
    internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3978
1
  else
3979
1
    {
3980
1
      internal_f.f_opthdr = 0;
3981
#ifdef RS6000COFF_C
3982
#ifndef XCOFF64
3983
      if (xcoff_data (abfd)->full_aouthdr)
3984
  internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3985
      else
3986
  internal_f.f_opthdr = SMALL_AOUTSZ;
3987
#endif
3988
#endif
3989
1
    }
3990
3991
1
  if (!hasrelocs)
3992
1
    internal_f.f_flags |= F_RELFLG;
3993
1
  if (!haslinno)
3994
1
    internal_f.f_flags |= F_LNNO;
3995
1
  if (abfd->flags & EXEC_P)
3996
0
    internal_f.f_flags |= F_EXEC;
3997
#ifdef COFF_IMAGE_WITH_PE
3998
  if (! hasdebug)
3999
    internal_f.f_flags |= IMAGE_FILE_DEBUG_STRIPPED;
4000
  if (pe_data (abfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
4001
    internal_f.f_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
4002
#endif
4003
4004
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
4005
#ifdef COFF_WITH_PE
4006
  internal_f.f_flags |= IMAGE_FILE_32BIT_MACHINE;
4007
#else
4008
  if (bfd_little_endian (abfd))
4009
    internal_f.f_flags |= F_AR32WR;
4010
  else
4011
    internal_f.f_flags |= F_AR32W;
4012
#endif
4013
#endif
4014
4015
#ifdef TI_TARGET_ID
4016
  /* Target id is used in TI COFF v1 and later; COFF0 won't use this field,
4017
     but it doesn't hurt to set it internally.  */
4018
  internal_f.f_target_id = TI_TARGET_ID;
4019
#endif
4020
4021
  /* FIXME, should do something about the other byte orders and
4022
     architectures.  */
4023
4024
#ifdef RS6000COFF_C
4025
  if ((abfd->flags & DYNAMIC) != 0)
4026
    internal_f.f_flags |= F_SHROBJ;
4027
  if (bfd_get_section_by_name (abfd, _LOADER) != NULL)
4028
    internal_f.f_flags |= F_DYNLOAD;
4029
#endif
4030
4031
1
  memset (&internal_a, 0, sizeof internal_a);
4032
4033
  /* Set up architecture-dependent stuff.  */
4034
1
  {
4035
1
    unsigned int magic = 0;
4036
1
    unsigned short flags = 0;
4037
4038
1
    coff_set_flags (abfd, &magic, &flags);
4039
1
    internal_f.f_magic = magic;
4040
1
    internal_f.f_flags |= flags;
4041
    /* ...and the "opt"hdr...  */
4042
4043
#ifdef TICOFF_AOUT_MAGIC
4044
    internal_a.magic = TICOFF_AOUT_MAGIC;
4045
#define __A_MAGIC_SET__
4046
#endif
4047
4048
#if defined(ARM)
4049
#define __A_MAGIC_SET__
4050
    internal_a.magic = ZMAGIC;
4051
#endif
4052
4053
1
#if defined(AARCH64)
4054
1
#define __A_MAGIC_SET__
4055
1
    internal_a.magic = ZMAGIC;
4056
1
#endif
4057
4058
#if defined(LOONGARCH64)
4059
#define __A_MAGIC_SET__
4060
    internal_a.magic = ZMAGIC;
4061
#endif
4062
4063
#if defined MCORE_PE
4064
#define __A_MAGIC_SET__
4065
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR_MAGIC;
4066
#endif
4067
4068
#if defined(I386)
4069
#define __A_MAGIC_SET__
4070
#if defined LYNXOS
4071
    internal_a.magic = LYNXCOFFMAGIC;
4072
#elif defined AMD64
4073
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR64_MAGIC;
4074
#else
4075
    internal_a.magic = ZMAGIC;
4076
#endif
4077
#endif /* I386 */
4078
4079
#if defined(IA64)
4080
#define __A_MAGIC_SET__
4081
    internal_a.magic = PE32PMAGIC;
4082
#endif /* IA64 */
4083
4084
#if defined(SPARC)
4085
#define __A_MAGIC_SET__
4086
#if defined(LYNXOS)
4087
    internal_a.magic = LYNXCOFFMAGIC;
4088
#endif /* LYNXOS */
4089
#endif /* SPARC */
4090
4091
#ifdef RS6000COFF_C
4092
#define __A_MAGIC_SET__
4093
    internal_a.magic = (abfd->flags & D_PAGED) ? RS6K_AOUTHDR_ZMAGIC :
4094
    (abfd->flags & WP_TEXT) ? RS6K_AOUTHDR_NMAGIC :
4095
    RS6K_AOUTHDR_OMAGIC;
4096
#endif
4097
4098
#if defined(SH) && defined(COFF_WITH_PE)
4099
#define __A_MAGIC_SET__
4100
    internal_a.magic = SH_PE_MAGIC;
4101
#endif
4102
4103
#if defined(MIPS) && defined(COFF_WITH_PE)
4104
#define __A_MAGIC_SET__
4105
    internal_a.magic = MIPS_PE_MAGIC;
4106
#endif
4107
4108
#ifndef __A_MAGIC_SET__
4109
#include "Your aouthdr magic number is not being set!"
4110
#else
4111
1
#undef __A_MAGIC_SET__
4112
1
#endif
4113
1
  }
4114
4115
#ifdef RS6000COFF_C
4116
  /* XCOFF 32bit needs this to have new behaviour for n_type field.  */
4117
  internal_a.vstamp = 2;
4118
#else
4119
  /* FIXME: Does anybody ever set this to another value?  */
4120
1
  internal_a.vstamp = 0;
4121
1
#endif
4122
4123
  /* Now should write relocs, strings, syms.  */
4124
1
  obj_sym_filepos (abfd) = sym_base;
4125
4126
1
  if (bfd_get_symcount (abfd) != 0)
4127
1
    {
4128
1
      int firstundef;
4129
4130
1
      if (!coff_renumber_symbols (abfd, &firstundef))
4131
0
  return false;
4132
1
      coff_mangle_symbols (abfd);
4133
1
      if (! coff_write_symbols (abfd))
4134
0
  return false;
4135
1
      if (! coff_write_linenumbers (abfd))
4136
0
  return false;
4137
1
      if (! coff_write_relocs (abfd, firstundef))
4138
0
  return false;
4139
1
    }
4140
0
#ifdef COFF_LONG_SECTION_NAMES
4141
0
  else if (long_section_names && ! obj_coff_strings_written (abfd))
4142
0
    {
4143
      /* If we have long section names we have to write out the string
4144
   table even if there are no symbols.  */
4145
0
      if (! coff_write_symbols (abfd))
4146
0
  return false;
4147
0
    }
4148
1
#endif
4149
  /* If bfd_get_symcount (abfd) != 0, then we are not using the COFF
4150
     backend linker, and obj_raw_syment_count is not valid until after
4151
     coff_write_symbols is called.  */
4152
1
  if (obj_raw_syment_count (abfd) != 0)
4153
1
    {
4154
1
      internal_f.f_symptr = sym_base;
4155
#ifdef RS6000COFF_C
4156
      /* AIX appears to require that F_RELFLG not be set if there are
4157
   local symbols but no relocations.  */
4158
      internal_f.f_flags &=~ F_RELFLG;
4159
#endif
4160
1
    }
4161
0
  else
4162
0
    {
4163
0
      if (long_section_names)
4164
0
  internal_f.f_symptr = sym_base;
4165
0
      else
4166
0
  internal_f.f_symptr = 0;
4167
0
      internal_f.f_flags |= F_LSYMS;
4168
0
    }
4169
4170
1
  if (text_sec)
4171
0
    {
4172
0
      internal_a.tsize = text_sec->size;
4173
0
      internal_a.text_start = internal_a.tsize ? text_sec->vma : 0;
4174
0
    }
4175
1
  if (data_sec)
4176
0
    {
4177
0
      internal_a.dsize = data_sec->size;
4178
0
      internal_a.data_start = internal_a.dsize ? data_sec->vma : 0;
4179
0
    }
4180
1
  if (bss_sec)
4181
0
    {
4182
0
      internal_a.bsize = bss_sec->size;
4183
0
      if (internal_a.bsize && bss_sec->vma < internal_a.data_start)
4184
0
  internal_a.data_start = bss_sec->vma;
4185
0
    }
4186
4187
1
  internal_a.entry = bfd_get_start_address (abfd);
4188
1
  internal_f.f_nsyms = obj_raw_syment_count (abfd);
4189
4190
#ifdef RS6000COFF_C
4191
  if (xcoff_data (abfd)->full_aouthdr)
4192
    {
4193
      bfd_vma toc;
4194
      asection *loader_sec;
4195
4196
      internal_a.vstamp = 2;
4197
4198
      internal_a.o_snentry = xcoff_data (abfd)->snentry;
4199
      if (internal_a.o_snentry == 0)
4200
  internal_a.entry = (bfd_vma) -1;
4201
4202
      if (text_sec != NULL)
4203
  {
4204
    internal_a.o_sntext = text_sec->target_index;
4205
    internal_a.o_algntext = bfd_section_alignment (text_sec);
4206
  }
4207
      else
4208
  {
4209
    internal_a.o_sntext = 0;
4210
    internal_a.o_algntext = 0;
4211
  }
4212
      if (data_sec != NULL)
4213
  {
4214
    internal_a.o_sndata = data_sec->target_index;
4215
    internal_a.o_algndata = bfd_section_alignment (data_sec);
4216
  }
4217
      else
4218
  {
4219
    internal_a.o_sndata = 0;
4220
    internal_a.o_algndata = 0;
4221
  }
4222
      loader_sec = bfd_get_section_by_name (abfd, ".loader");
4223
      if (loader_sec != NULL)
4224
  internal_a.o_snloader = loader_sec->target_index;
4225
      else
4226
  internal_a.o_snloader = 0;
4227
      if (bss_sec != NULL)
4228
  internal_a.o_snbss = bss_sec->target_index;
4229
      else
4230
  internal_a.o_snbss = 0;
4231
4232
      if (tdata_sec != NULL)
4233
  {
4234
    internal_a.o_sntdata = tdata_sec->target_index;
4235
    /* TODO: o_flags should be set to RS6K_AOUTHDR_TLS_LE
4236
       if there is at least one R_TLS_LE relocations.  */
4237
    internal_a.o_flags = 0;
4238
#ifdef XCOFF64
4239
    internal_a.o_x64flags = 0;
4240
#endif
4241
  }
4242
      else
4243
  {
4244
    internal_a.o_sntdata = 0;
4245
    internal_a.o_flags = 0;
4246
#ifdef XCOFF64
4247
    internal_a.o_x64flags = 0;
4248
#endif
4249
  }
4250
      if (tbss_sec != NULL)
4251
    internal_a.o_sntbss = tbss_sec->target_index;
4252
      else
4253
    internal_a.o_sntbss = 0;
4254
4255
      toc = xcoff_data (abfd)->toc;
4256
      internal_a.o_toc = toc;
4257
      internal_a.o_sntoc = xcoff_data (abfd)->sntoc;
4258
4259
      internal_a.o_modtype = xcoff_data (abfd)->modtype;
4260
      if (xcoff_data (abfd)->cputype != -1)
4261
  internal_a.o_cputype = xcoff_data (abfd)->cputype;
4262
      else
4263
  {
4264
    switch (bfd_get_arch (abfd))
4265
      {
4266
      case bfd_arch_rs6000:
4267
        internal_a.o_cputype = 4;
4268
        break;
4269
      case bfd_arch_powerpc:
4270
        if (bfd_get_mach (abfd) == bfd_mach_ppc)
4271
    internal_a.o_cputype = 3;
4272
        else if (bfd_get_mach (abfd) == bfd_mach_ppc_620)
4273
    internal_a.o_cputype = 2;
4274
        else
4275
    internal_a.o_cputype = 1;
4276
        break;
4277
      default:
4278
        abort ();
4279
      }
4280
  }
4281
      internal_a.o_maxstack = xcoff_data (abfd)->maxstack;
4282
      internal_a.o_maxdata = xcoff_data (abfd)->maxdata;
4283
    }
4284
#endif
4285
4286
1
#ifdef COFF_WITH_PE
4287
1
  {
4288
    /* After object contents are finalized so we can compute a reasonable hash,
4289
       but before header is written so we can update it to point to debug directory.  */
4290
1
    struct pe_tdata *pe = pe_data (abfd);
4291
4292
1
    if (pe->build_id.after_write_object_contents != NULL)
4293
0
      (*pe->build_id.after_write_object_contents) (abfd);
4294
1
  }
4295
1
#endif
4296
4297
  /* Now write header.  */
4298
1
  if (bfd_seek (abfd, 0, SEEK_SET) != 0)
4299
0
    return false;
4300
4301
1
  {
4302
1
    char * buff;
4303
1
    bfd_size_type amount = bfd_coff_filhsz (abfd);
4304
4305
1
    buff = (char *) bfd_malloc (amount);
4306
1
    if (buff == NULL)
4307
0
      return false;
4308
4309
1
    bfd_coff_swap_filehdr_out (abfd, & internal_f, buff);
4310
1
    amount = bfd_write (buff, amount, abfd);
4311
4312
1
    free (buff);
4313
4314
1
    if (amount != bfd_coff_filhsz (abfd))
4315
0
      return false;
4316
1
  }
4317
4318
1
  if (abfd->flags & EXEC_P)
4319
0
    {
4320
      /* Note that peicode.h fills in a PEAOUTHDR, not an AOUTHDR.
4321
   include/coff/pe.h sets AOUTSZ == sizeof (PEAOUTHDR)).  */
4322
0
      char * buff;
4323
0
      bfd_size_type amount = bfd_coff_aoutsz (abfd);
4324
4325
0
      buff = (char *) bfd_malloc (amount);
4326
0
      if (buff == NULL)
4327
0
  return false;
4328
4329
0
      coff_swap_aouthdr_out (abfd, & internal_a, buff);
4330
0
      amount = bfd_write (buff, amount, abfd);
4331
4332
0
      free (buff);
4333
4334
0
      if (amount != bfd_coff_aoutsz (abfd))
4335
0
  return false;
4336
4337
#ifdef COFF_IMAGE_WITH_PE
4338
      if (! coff_apply_checksum (abfd))
4339
  return false;
4340
#endif
4341
0
    }
4342
#ifdef RS6000COFF_C
4343
#ifndef XCOFF64
4344
  else
4345
    {
4346
      AOUTHDR buff;
4347
      size_t size;
4348
4349
      /* XCOFF32 seems to always write at least a small a.out header.  */
4350
      coff_swap_aouthdr_out (abfd, & internal_a, & buff);
4351
      if (xcoff_data (abfd)->full_aouthdr)
4352
  size = bfd_coff_aoutsz (abfd);
4353
      else
4354
  size = SMALL_AOUTSZ;
4355
      if (bfd_write (&buff, size, abfd) != size)
4356
  return false;
4357
    }
4358
#endif
4359
#endif
4360
4361
1
  return true;
4362
1
}
pei-aarch64.c:coff_write_object_contents
Line
Count
Source
3486
2
{
3487
2
  asection *current;
3488
2
  bool hasrelocs = false;
3489
2
  bool haslinno = false;
3490
2
#ifdef COFF_IMAGE_WITH_PE
3491
2
  bool hasdebug = false;
3492
2
#endif
3493
2
  file_ptr scn_base;
3494
2
  file_ptr reloc_base;
3495
2
  file_ptr lineno_base;
3496
2
  file_ptr sym_base;
3497
2
  unsigned long reloc_size = 0, reloc_count = 0;
3498
2
  unsigned long lnno_size = 0;
3499
2
  bool long_section_names;
3500
2
  asection *text_sec = NULL;
3501
2
  asection *data_sec = NULL;
3502
2
  asection *bss_sec = NULL;
3503
#ifdef RS6000COFF_C
3504
  asection *tdata_sec = NULL;
3505
  asection *tbss_sec = NULL;
3506
#endif
3507
2
  struct internal_filehdr internal_f;
3508
2
  struct internal_aouthdr internal_a;
3509
2
#ifdef COFF_LONG_SECTION_NAMES
3510
2
  size_t string_size = STRING_SIZE_SIZE;
3511
2
#endif
3512
3513
2
  bfd_set_error (bfd_error_system_call);
3514
3515
  /* Make a pass through the symbol table to count line number entries and
3516
     put them into the correct asections.  */
3517
2
  lnno_size = coff_count_linenumbers (abfd) * bfd_coff_linesz (abfd);
3518
3519
2
  if (! abfd->output_has_begun)
3520
0
    {
3521
0
      if (! coff_compute_section_file_positions (abfd))
3522
0
  return false;
3523
0
    }
3524
3525
2
  reloc_base = obj_relocbase (abfd);
3526
3527
  /* Work out the size of the reloc and linno areas.  */
3528
3529
6
  for (current = abfd->sections; current != NULL; current =
3530
4
       current->next)
3531
4
    {
3532
4
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3533
      /* We store the actual reloc count in the first reloc's addr.  */
3534
4
      if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3535
0
  reloc_count ++;
3536
4
#endif
3537
4
      reloc_count += current->reloc_count;
3538
4
    }
3539
3540
2
  reloc_size = reloc_count * bfd_coff_relsz (abfd);
3541
3542
2
  lineno_base = reloc_base + reloc_size;
3543
2
  sym_base = lineno_base + lnno_size;
3544
3545
  /* Indicate in each section->line_filepos its actual file address.  */
3546
6
  for (current = abfd->sections; current != NULL; current =
3547
4
       current->next)
3548
4
    {
3549
4
      if (current->lineno_count)
3550
0
  {
3551
0
    current->line_filepos = lineno_base;
3552
0
    current->moving_line_filepos = lineno_base;
3553
0
    lineno_base += current->lineno_count * bfd_coff_linesz (abfd);
3554
0
  }
3555
4
      else
3556
4
  current->line_filepos = 0;
3557
3558
4
      if (current->reloc_count)
3559
0
  {
3560
0
    current->rel_filepos = reloc_base;
3561
0
    reloc_base += current->reloc_count * bfd_coff_relsz (abfd);
3562
0
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3563
    /* Extra reloc to hold real count.  */
3564
0
    if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3565
0
      reloc_base += bfd_coff_relsz (abfd);
3566
0
#endif
3567
0
  }
3568
4
      else
3569
4
  current->rel_filepos = 0;
3570
4
    }
3571
3572
  /* Write section headers to the file.  */
3573
2
  internal_f.f_nscns = 0;
3574
3575
2
  if ((abfd->flags & EXEC_P) != 0)
3576
0
    scn_base = bfd_coff_filhsz (abfd) + bfd_coff_aoutsz (abfd);
3577
2
  else
3578
2
    {
3579
2
      scn_base = bfd_coff_filhsz (abfd);
3580
#ifdef RS6000COFF_C
3581
#ifndef XCOFF64
3582
      if (xcoff_data (abfd)->full_aouthdr)
3583
  scn_base += bfd_coff_aoutsz (abfd);
3584
      else
3585
  scn_base += SMALL_AOUTSZ;
3586
#endif
3587
#endif
3588
2
    }
3589
3590
2
  if (bfd_seek (abfd, scn_base, SEEK_SET) != 0)
3591
0
    return false;
3592
3593
2
  long_section_names = false;
3594
2
  for (current = abfd->sections;
3595
6
       current != NULL;
3596
4
       current = current->next)
3597
4
    {
3598
4
      struct internal_scnhdr section;
3599
4
#ifdef COFF_IMAGE_WITH_PE
3600
4
      bool is_reloc_section = false;
3601
3602
4
      if (strcmp (current->name, DOT_RELOC) == 0)
3603
0
  {
3604
0
    is_reloc_section = true;
3605
0
    hasrelocs = true;
3606
0
    pe_data (abfd)->has_reloc_section = 1;
3607
0
  }
3608
4
#endif
3609
3610
4
      internal_f.f_nscns++;
3611
3612
4
      strncpy (section.s_name, current->name, SCNNMLEN);
3613
3614
4
#ifdef COFF_LONG_SECTION_NAMES
3615
      /* Handle long section names as in PE.  This must be compatible
3616
   with the code in coff_write_symbols and _bfd_coff_final_link.  */
3617
4
      if (bfd_coff_long_section_names (abfd))
3618
0
  {
3619
0
    size_t len;
3620
3621
0
    len = strlen (current->name);
3622
0
    if (len > SCNNMLEN)
3623
0
      {
3624
3625
        /* An inherent limitation of the /nnnnnnn notation used to indicate
3626
     the offset of the long name in the string table is that we
3627
     cannot address entries beyone the ten million byte boundary.  */
3628
0
        if (string_size < 10000000)
3629
0
    {
3630
      /* The s_name field is defined to be NUL-padded but need not
3631
         be NUL-terminated.  We use a temporary buffer so that we
3632
         can still sprintf all eight chars without splatting a
3633
         terminating NUL over the first byte of the following
3634
         member (s_paddr).  */
3635
      /* PR 21096: The +20 is to stop a bogus warning from gcc7
3636
         about a possible buffer overflow.  */
3637
0
      char s_name_buf[SCNNMLEN + 1 + 20];
3638
3639
      /* We do not need to use snprintf here as we have already
3640
         verified that string_size is not too big, plus we have
3641
         an overlarge buffer, just in case.  */
3642
0
      sprintf (s_name_buf, "/%lu", (unsigned long) string_size);
3643
      /* Then strncpy takes care of any padding for us.  */
3644
0
      strncpy (section.s_name, s_name_buf, SCNNMLEN);
3645
0
    }
3646
0
        else
3647
0
#ifdef COFF_WITH_PE
3648
0
    {
3649
      /* PE use a base 64 encoding for long section names whose
3650
         index is very large.  But contrary to RFC 4648, there is
3651
         no padding: 6 characters must be generated.  */
3652
0
      static const char base64[] =
3653
0
        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
3654
0
        "abcdefghijklmnopqrstuvwxyz"
3655
0
        "0123456789+/";
3656
0
      unsigned long off = string_size;
3657
0
      unsigned i;
3658
3659
0
      section.s_name[0] = '/';
3660
0
      section.s_name[1] = '/';
3661
0
      for (i = SCNNMLEN - 1; i >= 2; i--)
3662
0
        {
3663
0
          section.s_name[i] = base64[off & 0x3f];
3664
0
          off >>= 6;
3665
0
        }
3666
0
    }
3667
0
#endif
3668
0
        if (string_size > 0xffffffffUL - (len + 1)
3669
#ifndef COFF_WITH_PE
3670
      || string_size >= 10000000
3671
#endif
3672
0
      )
3673
0
    {
3674
0
      bfd_set_error (bfd_error_file_too_big);
3675
0
      _bfd_error_handler
3676
        /* xgettext:c-format */
3677
0
        (_("%pB: section %pA: string table overflow at offset %ld"),
3678
0
        abfd, current, (unsigned long) string_size);
3679
0
      return false;
3680
0
    }
3681
3682
0
        string_size += len + 1;
3683
0
        long_section_names = true;
3684
0
      }
3685
0
  }
3686
4
#endif
3687
3688
4
#ifdef _LIB
3689
      /* Always set s_vaddr of .lib to 0.  This is right for SVR3.2
3690
   Ian Taylor <ian@cygnus.com>.  */
3691
4
      if (strcmp (current->name, _LIB) == 0)
3692
0
  section.s_vaddr = 0;
3693
4
      else
3694
4
#endif
3695
4
      section.s_vaddr = current->vma;
3696
4
      section.s_paddr = current->lma;
3697
4
      section.s_size =  current->size;
3698
#ifdef coff_get_section_load_page
3699
      section.s_page = coff_get_section_load_page (current);
3700
#else
3701
4
      section.s_page = 0;
3702
4
#endif
3703
3704
4
#ifdef COFF_WITH_PE
3705
4
      section.s_paddr = 0;
3706
4
#endif
3707
4
#ifdef COFF_IMAGE_WITH_PE
3708
      /* Reminder: s_paddr holds the virtual size of the section.  */
3709
4
      if (coff_section_data (abfd, current) != NULL
3710
4
    && pei_section_data (abfd, current) != NULL)
3711
4
  section.s_paddr = pei_section_data (abfd, current)->virt_size;
3712
0
      else
3713
0
  section.s_paddr = 0;
3714
4
#endif
3715
3716
      /* If this section has no size or is unloadable then the scnptr
3717
   will be 0 too.  */
3718
4
      if (current->size == 0
3719
4
    || (current->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
3720
0
  section.s_scnptr = 0;
3721
4
      else
3722
4
  section.s_scnptr = current->filepos;
3723
3724
4
      section.s_relptr = current->rel_filepos;
3725
4
      section.s_lnnoptr = current->line_filepos;
3726
4
      section.s_nreloc = current->reloc_count;
3727
4
      section.s_nlnno = current->lineno_count;
3728
#ifndef COFF_IMAGE_WITH_PE
3729
      /* In PEI, relocs come in the .reloc section.  */
3730
      if (current->reloc_count != 0)
3731
  hasrelocs = true;
3732
#endif
3733
4
      if (current->lineno_count != 0)
3734
0
  haslinno = true;
3735
4
#ifdef COFF_IMAGE_WITH_PE
3736
4
      if ((current->flags & SEC_DEBUGGING) != 0
3737
4
    && ! is_reloc_section)
3738
4
  hasdebug = true;
3739
4
#endif
3740
3741
#ifdef RS6000COFF_C
3742
#ifndef XCOFF64
3743
      /* Indicate the use of an XCOFF overflow section header.  */
3744
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3745
  {
3746
    section.s_nreloc = 0xffff;
3747
    section.s_nlnno = 0xffff;
3748
  }
3749
#endif
3750
#endif
3751
3752
4
      section.s_flags = sec_to_styp_flags (current->name, current->flags);
3753
3754
4
      if (!strcmp (current->name, _TEXT))
3755
0
  text_sec = current;
3756
4
      else if (!strcmp (current->name, _DATA))
3757
0
  data_sec = current;
3758
4
      else if (!strcmp (current->name, _BSS))
3759
0
  bss_sec = current;
3760
#ifdef RS6000COFF_C
3761
      else if (!strcmp (current->name, _TDATA))
3762
  tdata_sec = current;
3763
      else if (!strcmp (current->name, _TBSS))
3764
  tbss_sec = current;
3765
#endif
3766
3767
3768
4
#ifdef COFF_ENCODE_ALIGNMENT
3769
4
      if (COFF_ENCODE_ALIGNMENT (abfd, section, current->alignment_power)
3770
4
    && (COFF_DECODE_ALIGNMENT (section.s_flags)
3771
4
        != current->alignment_power))
3772
0
  {
3773
0
    bool warn = (coff_data (abfd)->link_info
3774
0
           && !bfd_link_relocatable (coff_data (abfd)->link_info));
3775
3776
0
    _bfd_error_handler
3777
      /* xgettext:c-format */
3778
0
      (_("%pB:%s section %s: alignment 2**%u not representable"),
3779
0
       abfd, warn ? " warning:" : "", current->name,
3780
0
       current->alignment_power);
3781
0
    if (!warn)
3782
0
      {
3783
0
        bfd_set_error (bfd_error_nonrepresentable_section);
3784
0
        return false;
3785
0
      }
3786
0
  }
3787
4
#endif
3788
3789
4
#ifdef COFF_IMAGE_WITH_PE
3790
      /* Suppress output of the sections if they are null.  ld
3791
   includes the bss and data sections even if there is no size
3792
   assigned to them.  NT loader doesn't like it if these section
3793
   headers are included if the sections themselves are not
3794
   needed.  See also coff_compute_section_file_positions.  */
3795
4
      if (section.s_size == 0)
3796
0
  internal_f.f_nscns--;
3797
4
      else
3798
4
#endif
3799
4
  {
3800
4
    SCNHDR buff;
3801
4
    bfd_size_type amt = bfd_coff_scnhsz (abfd);
3802
3803
4
    if (bfd_coff_swap_scnhdr_out (abfd, &section, &buff) == 0
3804
4
        || bfd_write (& buff, amt, abfd) != amt)
3805
0
      return false;
3806
4
  }
3807
3808
4
#ifdef COFF_WITH_PE
3809
      /* PE stores COMDAT section information in the symbol table.  If
3810
   this section is supposed to have some COMDAT info, track down
3811
   the symbol in the symbol table and modify it.  */
3812
4
      if ((current->flags & SEC_LINK_ONCE) != 0)
3813
0
  {
3814
0
    unsigned int i, count;
3815
0
    asymbol **psym;
3816
0
    coff_symbol_type *csym = NULL;
3817
0
    asymbol **psymsec;
3818
3819
0
    psymsec = NULL;
3820
0
    count = bfd_get_symcount (abfd);
3821
0
    for (i = 0, psym = abfd->outsymbols; i < count; i++, psym++)
3822
0
      {
3823
0
        if ((*psym)->section != current)
3824
0
    continue;
3825
3826
        /* Remember the location of the first symbol in this
3827
     section.  */
3828
0
        if (psymsec == NULL)
3829
0
    psymsec = psym;
3830
3831
        /* See if this is the section symbol.  */
3832
0
        if (strcmp ((*psym)->name, current->name) == 0)
3833
0
    {
3834
0
      csym = coff_symbol_from (*psym);
3835
0
      if (csym == NULL
3836
0
          || csym->native == NULL
3837
0
          || ! csym->native->is_sym
3838
0
          || csym->native->u.syment.n_numaux < 1
3839
0
          || csym->native->u.syment.n_sclass != C_STAT
3840
0
          || csym->native->u.syment.n_type != T_NULL)
3841
0
        continue;
3842
3843
      /* Here *PSYM is the section symbol for CURRENT.  */
3844
3845
0
      break;
3846
0
    }
3847
0
      }
3848
3849
    /* Did we find it?
3850
       Note that we might not if we're converting the file from
3851
       some other object file format.  */
3852
0
    if (i < count)
3853
0
      {
3854
0
        combined_entry_type *aux;
3855
3856
        /* We don't touch the x_checksum field.  The
3857
     x_associated field is not currently supported.  */
3858
3859
0
        aux = csym->native + 1;
3860
0
        BFD_ASSERT (! aux->is_sym);
3861
0
        switch (current->flags & SEC_LINK_DUPLICATES)
3862
0
    {
3863
0
    case SEC_LINK_DUPLICATES_DISCARD:
3864
0
      aux->u.auxent.x_scn.x_comdat = IMAGE_COMDAT_SELECT_ANY;
3865
0
      break;
3866
3867
0
    case SEC_LINK_DUPLICATES_ONE_ONLY:
3868
0
      aux->u.auxent.x_scn.x_comdat =
3869
0
        IMAGE_COMDAT_SELECT_NODUPLICATES;
3870
0
      break;
3871
3872
0
    case SEC_LINK_DUPLICATES_SAME_SIZE:
3873
0
      aux->u.auxent.x_scn.x_comdat =
3874
0
        IMAGE_COMDAT_SELECT_SAME_SIZE;
3875
0
      break;
3876
3877
0
    case SEC_LINK_DUPLICATES_SAME_CONTENTS:
3878
0
      aux->u.auxent.x_scn.x_comdat =
3879
0
        IMAGE_COMDAT_SELECT_EXACT_MATCH;
3880
0
      break;
3881
0
    }
3882
3883
        /* The COMDAT symbol must be the first symbol from this
3884
     section in the symbol table.  In order to make this
3885
     work, we move the COMDAT symbol before the first
3886
     symbol we found in the search above.  It's OK to
3887
     rearrange the symbol table at this point, because
3888
     coff_renumber_symbols is going to rearrange it
3889
     further and fix up all the aux entries.  */
3890
0
        if (psym != psymsec)
3891
0
    {
3892
0
      asymbol *hold;
3893
0
      asymbol **pcopy;
3894
3895
0
      hold = *psym;
3896
0
      for (pcopy = psym; pcopy > psymsec; pcopy--)
3897
0
        pcopy[0] = pcopy[-1];
3898
0
      *psymsec = hold;
3899
0
    }
3900
0
      }
3901
0
  }
3902
4
#endif /* COFF_WITH_PE */
3903
4
    }
3904
3905
#ifdef RS6000COFF_C
3906
#ifndef XCOFF64
3907
  /* XCOFF handles overflows in the reloc and line number count fields
3908
     by creating a new section header to hold the correct values.  */
3909
  for (current = abfd->sections; current != NULL; current = current->next)
3910
    {
3911
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3912
  {
3913
    struct internal_scnhdr scnhdr;
3914
    SCNHDR buff;
3915
    bfd_size_type amt;
3916
3917
    internal_f.f_nscns++;
3918
    memcpy (scnhdr.s_name, ".ovrflo", 8);
3919
    scnhdr.s_paddr = current->reloc_count;
3920
    scnhdr.s_vaddr = current->lineno_count;
3921
    scnhdr.s_size = 0;
3922
    scnhdr.s_scnptr = 0;
3923
    scnhdr.s_relptr = current->rel_filepos;
3924
    scnhdr.s_lnnoptr = current->line_filepos;
3925
    scnhdr.s_nreloc = current->target_index;
3926
    scnhdr.s_nlnno = current->target_index;
3927
    scnhdr.s_flags = STYP_OVRFLO;
3928
    amt = bfd_coff_scnhsz (abfd);
3929
    if (bfd_coff_swap_scnhdr_out (abfd, &scnhdr, &buff) == 0
3930
        || bfd_write (& buff, amt, abfd) != amt)
3931
      return false;
3932
  }
3933
    }
3934
#endif
3935
#endif
3936
3937
#if defined (COFF_GO32_EXE) || defined (COFF_GO32)
3938
  /* Pad section headers.  */
3939
  if ((abfd->flags & EXEC_P) != 0)
3940
    {
3941
      asection *s = abfd->sections;
3942
      while (s != NULL && s->filepos == 0)
3943
  s = s->next;
3944
      if (s != NULL)
3945
  {
3946
    file_ptr cur_ptr
3947
      = scn_base + abfd->section_count * bfd_coff_scnhsz (abfd);
3948
    file_ptr fill_size = s->filepos - cur_ptr;
3949
    if (fill_size > 0)
3950
      {
3951
        bfd_byte *b = bfd_zmalloc (fill_size);
3952
        if (!b)
3953
    return false;
3954
        if (bfd_write (b, fill_size, abfd) != (ufile_ptr) fill_size)
3955
    {
3956
      free (b);
3957
      return false;
3958
    }
3959
        free (b);
3960
      }
3961
  }
3962
    }
3963
#endif
3964
3965
  /* OK, now set up the filehdr...  */
3966
3967
  /* Don't include the internal abs section in the section count */
3968
3969
  /* We will NOT put a fucking timestamp in the header here. Every time you
3970
     put it back, I will come in and take it out again.  I'm sorry.  This
3971
     field does not belong here.  We fill it with a 0 so it compares the
3972
     same but is not a reasonable time. -- gnu@cygnus.com  */
3973
2
  internal_f.f_timdat = 0;
3974
2
  internal_f.f_flags = 0;
3975
3976
2
  if (abfd->flags & EXEC_P)
3977
0
    internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3978
2
  else
3979
2
    {
3980
2
      internal_f.f_opthdr = 0;
3981
#ifdef RS6000COFF_C
3982
#ifndef XCOFF64
3983
      if (xcoff_data (abfd)->full_aouthdr)
3984
  internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3985
      else
3986
  internal_f.f_opthdr = SMALL_AOUTSZ;
3987
#endif
3988
#endif
3989
2
    }
3990
3991
2
  if (!hasrelocs)
3992
2
    internal_f.f_flags |= F_RELFLG;
3993
2
  if (!haslinno)
3994
2
    internal_f.f_flags |= F_LNNO;
3995
2
  if (abfd->flags & EXEC_P)
3996
0
    internal_f.f_flags |= F_EXEC;
3997
2
#ifdef COFF_IMAGE_WITH_PE
3998
2
  if (! hasdebug)
3999
0
    internal_f.f_flags |= IMAGE_FILE_DEBUG_STRIPPED;
4000
2
  if (pe_data (abfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
4001
0
    internal_f.f_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
4002
2
#endif
4003
4004
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
4005
#ifdef COFF_WITH_PE
4006
  internal_f.f_flags |= IMAGE_FILE_32BIT_MACHINE;
4007
#else
4008
  if (bfd_little_endian (abfd))
4009
    internal_f.f_flags |= F_AR32WR;
4010
  else
4011
    internal_f.f_flags |= F_AR32W;
4012
#endif
4013
#endif
4014
4015
#ifdef TI_TARGET_ID
4016
  /* Target id is used in TI COFF v1 and later; COFF0 won't use this field,
4017
     but it doesn't hurt to set it internally.  */
4018
  internal_f.f_target_id = TI_TARGET_ID;
4019
#endif
4020
4021
  /* FIXME, should do something about the other byte orders and
4022
     architectures.  */
4023
4024
#ifdef RS6000COFF_C
4025
  if ((abfd->flags & DYNAMIC) != 0)
4026
    internal_f.f_flags |= F_SHROBJ;
4027
  if (bfd_get_section_by_name (abfd, _LOADER) != NULL)
4028
    internal_f.f_flags |= F_DYNLOAD;
4029
#endif
4030
4031
2
  memset (&internal_a, 0, sizeof internal_a);
4032
4033
  /* Set up architecture-dependent stuff.  */
4034
2
  {
4035
2
    unsigned int magic = 0;
4036
2
    unsigned short flags = 0;
4037
4038
2
    coff_set_flags (abfd, &magic, &flags);
4039
2
    internal_f.f_magic = magic;
4040
2
    internal_f.f_flags |= flags;
4041
    /* ...and the "opt"hdr...  */
4042
4043
#ifdef TICOFF_AOUT_MAGIC
4044
    internal_a.magic = TICOFF_AOUT_MAGIC;
4045
#define __A_MAGIC_SET__
4046
#endif
4047
4048
#if defined(ARM)
4049
#define __A_MAGIC_SET__
4050
    internal_a.magic = ZMAGIC;
4051
#endif
4052
4053
2
#if defined(AARCH64)
4054
2
#define __A_MAGIC_SET__
4055
2
    internal_a.magic = ZMAGIC;
4056
2
#endif
4057
4058
#if defined(LOONGARCH64)
4059
#define __A_MAGIC_SET__
4060
    internal_a.magic = ZMAGIC;
4061
#endif
4062
4063
#if defined MCORE_PE
4064
#define __A_MAGIC_SET__
4065
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR_MAGIC;
4066
#endif
4067
4068
#if defined(I386)
4069
#define __A_MAGIC_SET__
4070
#if defined LYNXOS
4071
    internal_a.magic = LYNXCOFFMAGIC;
4072
#elif defined AMD64
4073
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR64_MAGIC;
4074
#else
4075
    internal_a.magic = ZMAGIC;
4076
#endif
4077
#endif /* I386 */
4078
4079
#if defined(IA64)
4080
#define __A_MAGIC_SET__
4081
    internal_a.magic = PE32PMAGIC;
4082
#endif /* IA64 */
4083
4084
#if defined(SPARC)
4085
#define __A_MAGIC_SET__
4086
#if defined(LYNXOS)
4087
    internal_a.magic = LYNXCOFFMAGIC;
4088
#endif /* LYNXOS */
4089
#endif /* SPARC */
4090
4091
#ifdef RS6000COFF_C
4092
#define __A_MAGIC_SET__
4093
    internal_a.magic = (abfd->flags & D_PAGED) ? RS6K_AOUTHDR_ZMAGIC :
4094
    (abfd->flags & WP_TEXT) ? RS6K_AOUTHDR_NMAGIC :
4095
    RS6K_AOUTHDR_OMAGIC;
4096
#endif
4097
4098
#if defined(SH) && defined(COFF_WITH_PE)
4099
#define __A_MAGIC_SET__
4100
    internal_a.magic = SH_PE_MAGIC;
4101
#endif
4102
4103
#if defined(MIPS) && defined(COFF_WITH_PE)
4104
#define __A_MAGIC_SET__
4105
    internal_a.magic = MIPS_PE_MAGIC;
4106
#endif
4107
4108
#ifndef __A_MAGIC_SET__
4109
#include "Your aouthdr magic number is not being set!"
4110
#else
4111
2
#undef __A_MAGIC_SET__
4112
2
#endif
4113
2
  }
4114
4115
#ifdef RS6000COFF_C
4116
  /* XCOFF 32bit needs this to have new behaviour for n_type field.  */
4117
  internal_a.vstamp = 2;
4118
#else
4119
  /* FIXME: Does anybody ever set this to another value?  */
4120
2
  internal_a.vstamp = 0;
4121
2
#endif
4122
4123
  /* Now should write relocs, strings, syms.  */
4124
2
  obj_sym_filepos (abfd) = sym_base;
4125
4126
2
  if (bfd_get_symcount (abfd) != 0)
4127
0
    {
4128
0
      int firstundef;
4129
4130
0
      if (!coff_renumber_symbols (abfd, &firstundef))
4131
0
  return false;
4132
0
      coff_mangle_symbols (abfd);
4133
0
      if (! coff_write_symbols (abfd))
4134
0
  return false;
4135
0
      if (! coff_write_linenumbers (abfd))
4136
0
  return false;
4137
0
      if (! coff_write_relocs (abfd, firstundef))
4138
0
  return false;
4139
0
    }
4140
2
#ifdef COFF_LONG_SECTION_NAMES
4141
2
  else if (long_section_names && ! obj_coff_strings_written (abfd))
4142
0
    {
4143
      /* If we have long section names we have to write out the string
4144
   table even if there are no symbols.  */
4145
0
      if (! coff_write_symbols (abfd))
4146
0
  return false;
4147
0
    }
4148
2
#endif
4149
  /* If bfd_get_symcount (abfd) != 0, then we are not using the COFF
4150
     backend linker, and obj_raw_syment_count is not valid until after
4151
     coff_write_symbols is called.  */
4152
2
  if (obj_raw_syment_count (abfd) != 0)
4153
0
    {
4154
0
      internal_f.f_symptr = sym_base;
4155
#ifdef RS6000COFF_C
4156
      /* AIX appears to require that F_RELFLG not be set if there are
4157
   local symbols but no relocations.  */
4158
      internal_f.f_flags &=~ F_RELFLG;
4159
#endif
4160
0
    }
4161
2
  else
4162
2
    {
4163
2
      if (long_section_names)
4164
0
  internal_f.f_symptr = sym_base;
4165
2
      else
4166
2
  internal_f.f_symptr = 0;
4167
2
      internal_f.f_flags |= F_LSYMS;
4168
2
    }
4169
4170
2
  if (text_sec)
4171
0
    {
4172
0
      internal_a.tsize = text_sec->size;
4173
0
      internal_a.text_start = internal_a.tsize ? text_sec->vma : 0;
4174
0
    }
4175
2
  if (data_sec)
4176
0
    {
4177
0
      internal_a.dsize = data_sec->size;
4178
0
      internal_a.data_start = internal_a.dsize ? data_sec->vma : 0;
4179
0
    }
4180
2
  if (bss_sec)
4181
0
    {
4182
0
      internal_a.bsize = bss_sec->size;
4183
0
      if (internal_a.bsize && bss_sec->vma < internal_a.data_start)
4184
0
  internal_a.data_start = bss_sec->vma;
4185
0
    }
4186
4187
2
  internal_a.entry = bfd_get_start_address (abfd);
4188
2
  internal_f.f_nsyms = obj_raw_syment_count (abfd);
4189
4190
#ifdef RS6000COFF_C
4191
  if (xcoff_data (abfd)->full_aouthdr)
4192
    {
4193
      bfd_vma toc;
4194
      asection *loader_sec;
4195
4196
      internal_a.vstamp = 2;
4197
4198
      internal_a.o_snentry = xcoff_data (abfd)->snentry;
4199
      if (internal_a.o_snentry == 0)
4200
  internal_a.entry = (bfd_vma) -1;
4201
4202
      if (text_sec != NULL)
4203
  {
4204
    internal_a.o_sntext = text_sec->target_index;
4205
    internal_a.o_algntext = bfd_section_alignment (text_sec);
4206
  }
4207
      else
4208
  {
4209
    internal_a.o_sntext = 0;
4210
    internal_a.o_algntext = 0;
4211
  }
4212
      if (data_sec != NULL)
4213
  {
4214
    internal_a.o_sndata = data_sec->target_index;
4215
    internal_a.o_algndata = bfd_section_alignment (data_sec);
4216
  }
4217
      else
4218
  {
4219
    internal_a.o_sndata = 0;
4220
    internal_a.o_algndata = 0;
4221
  }
4222
      loader_sec = bfd_get_section_by_name (abfd, ".loader");
4223
      if (loader_sec != NULL)
4224
  internal_a.o_snloader = loader_sec->target_index;
4225
      else
4226
  internal_a.o_snloader = 0;
4227
      if (bss_sec != NULL)
4228
  internal_a.o_snbss = bss_sec->target_index;
4229
      else
4230
  internal_a.o_snbss = 0;
4231
4232
      if (tdata_sec != NULL)
4233
  {
4234
    internal_a.o_sntdata = tdata_sec->target_index;
4235
    /* TODO: o_flags should be set to RS6K_AOUTHDR_TLS_LE
4236
       if there is at least one R_TLS_LE relocations.  */
4237
    internal_a.o_flags = 0;
4238
#ifdef XCOFF64
4239
    internal_a.o_x64flags = 0;
4240
#endif
4241
  }
4242
      else
4243
  {
4244
    internal_a.o_sntdata = 0;
4245
    internal_a.o_flags = 0;
4246
#ifdef XCOFF64
4247
    internal_a.o_x64flags = 0;
4248
#endif
4249
  }
4250
      if (tbss_sec != NULL)
4251
    internal_a.o_sntbss = tbss_sec->target_index;
4252
      else
4253
    internal_a.o_sntbss = 0;
4254
4255
      toc = xcoff_data (abfd)->toc;
4256
      internal_a.o_toc = toc;
4257
      internal_a.o_sntoc = xcoff_data (abfd)->sntoc;
4258
4259
      internal_a.o_modtype = xcoff_data (abfd)->modtype;
4260
      if (xcoff_data (abfd)->cputype != -1)
4261
  internal_a.o_cputype = xcoff_data (abfd)->cputype;
4262
      else
4263
  {
4264
    switch (bfd_get_arch (abfd))
4265
      {
4266
      case bfd_arch_rs6000:
4267
        internal_a.o_cputype = 4;
4268
        break;
4269
      case bfd_arch_powerpc:
4270
        if (bfd_get_mach (abfd) == bfd_mach_ppc)
4271
    internal_a.o_cputype = 3;
4272
        else if (bfd_get_mach (abfd) == bfd_mach_ppc_620)
4273
    internal_a.o_cputype = 2;
4274
        else
4275
    internal_a.o_cputype = 1;
4276
        break;
4277
      default:
4278
        abort ();
4279
      }
4280
  }
4281
      internal_a.o_maxstack = xcoff_data (abfd)->maxstack;
4282
      internal_a.o_maxdata = xcoff_data (abfd)->maxdata;
4283
    }
4284
#endif
4285
4286
2
#ifdef COFF_WITH_PE
4287
2
  {
4288
    /* After object contents are finalized so we can compute a reasonable hash,
4289
       but before header is written so we can update it to point to debug directory.  */
4290
2
    struct pe_tdata *pe = pe_data (abfd);
4291
4292
2
    if (pe->build_id.after_write_object_contents != NULL)
4293
0
      (*pe->build_id.after_write_object_contents) (abfd);
4294
2
  }
4295
2
#endif
4296
4297
  /* Now write header.  */
4298
2
  if (bfd_seek (abfd, 0, SEEK_SET) != 0)
4299
0
    return false;
4300
4301
2
  {
4302
2
    char * buff;
4303
2
    bfd_size_type amount = bfd_coff_filhsz (abfd);
4304
4305
2
    buff = (char *) bfd_malloc (amount);
4306
2
    if (buff == NULL)
4307
0
      return false;
4308
4309
2
    bfd_coff_swap_filehdr_out (abfd, & internal_f, buff);
4310
2
    amount = bfd_write (buff, amount, abfd);
4311
4312
2
    free (buff);
4313
4314
2
    if (amount != bfd_coff_filhsz (abfd))
4315
0
      return false;
4316
2
  }
4317
4318
2
  if (abfd->flags & EXEC_P)
4319
0
    {
4320
      /* Note that peicode.h fills in a PEAOUTHDR, not an AOUTHDR.
4321
   include/coff/pe.h sets AOUTSZ == sizeof (PEAOUTHDR)).  */
4322
0
      char * buff;
4323
0
      bfd_size_type amount = bfd_coff_aoutsz (abfd);
4324
4325
0
      buff = (char *) bfd_malloc (amount);
4326
0
      if (buff == NULL)
4327
0
  return false;
4328
4329
0
      coff_swap_aouthdr_out (abfd, & internal_a, buff);
4330
0
      amount = bfd_write (buff, amount, abfd);
4331
4332
0
      free (buff);
4333
4334
0
      if (amount != bfd_coff_aoutsz (abfd))
4335
0
  return false;
4336
4337
0
#ifdef COFF_IMAGE_WITH_PE
4338
0
      if (! coff_apply_checksum (abfd))
4339
0
  return false;
4340
0
#endif
4341
0
    }
4342
#ifdef RS6000COFF_C
4343
#ifndef XCOFF64
4344
  else
4345
    {
4346
      AOUTHDR buff;
4347
      size_t size;
4348
4349
      /* XCOFF32 seems to always write at least a small a.out header.  */
4350
      coff_swap_aouthdr_out (abfd, & internal_a, & buff);
4351
      if (xcoff_data (abfd)->full_aouthdr)
4352
  size = bfd_coff_aoutsz (abfd);
4353
      else
4354
  size = SMALL_AOUTSZ;
4355
      if (bfd_write (&buff, size, abfd) != size)
4356
  return false;
4357
    }
4358
#endif
4359
#endif
4360
4361
2
  return true;
4362
2
}
Unexecuted instantiation: pei-ia64.c:coff_write_object_contents
Unexecuted instantiation: pei-loongarch64.c:coff_write_object_contents
Unexecuted instantiation: cf-i386lynx.c:coff_write_object_contents
Unexecuted instantiation: coff-go32.c:coff_write_object_contents
Unexecuted instantiation: coff-i386.c:coff_write_object_contents
Unexecuted instantiation: coff-rs6000.c:coff_write_object_contents
coff-sh.c:coff_write_object_contents
Line
Count
Source
3486
1
{
3487
1
  asection *current;
3488
1
  bool hasrelocs = false;
3489
1
  bool haslinno = false;
3490
#ifdef COFF_IMAGE_WITH_PE
3491
  bool hasdebug = false;
3492
#endif
3493
1
  file_ptr scn_base;
3494
1
  file_ptr reloc_base;
3495
1
  file_ptr lineno_base;
3496
1
  file_ptr sym_base;
3497
1
  unsigned long reloc_size = 0, reloc_count = 0;
3498
1
  unsigned long lnno_size = 0;
3499
1
  bool long_section_names;
3500
1
  asection *text_sec = NULL;
3501
1
  asection *data_sec = NULL;
3502
1
  asection *bss_sec = NULL;
3503
#ifdef RS6000COFF_C
3504
  asection *tdata_sec = NULL;
3505
  asection *tbss_sec = NULL;
3506
#endif
3507
1
  struct internal_filehdr internal_f;
3508
1
  struct internal_aouthdr internal_a;
3509
#ifdef COFF_LONG_SECTION_NAMES
3510
  size_t string_size = STRING_SIZE_SIZE;
3511
#endif
3512
3513
1
  bfd_set_error (bfd_error_system_call);
3514
3515
  /* Make a pass through the symbol table to count line number entries and
3516
     put them into the correct asections.  */
3517
1
  lnno_size = coff_count_linenumbers (abfd) * bfd_coff_linesz (abfd);
3518
3519
1
  if (! abfd->output_has_begun)
3520
1
    {
3521
1
      if (! coff_compute_section_file_positions (abfd))
3522
0
  return false;
3523
1
    }
3524
3525
1
  reloc_base = obj_relocbase (abfd);
3526
3527
  /* Work out the size of the reloc and linno areas.  */
3528
3529
1
  for (current = abfd->sections; current != NULL; current =
3530
0
       current->next)
3531
0
    {
3532
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3533
      /* We store the actual reloc count in the first reloc's addr.  */
3534
      if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3535
  reloc_count ++;
3536
#endif
3537
0
      reloc_count += current->reloc_count;
3538
0
    }
3539
3540
1
  reloc_size = reloc_count * bfd_coff_relsz (abfd);
3541
3542
1
  lineno_base = reloc_base + reloc_size;
3543
1
  sym_base = lineno_base + lnno_size;
3544
3545
  /* Indicate in each section->line_filepos its actual file address.  */
3546
1
  for (current = abfd->sections; current != NULL; current =
3547
0
       current->next)
3548
0
    {
3549
0
      if (current->lineno_count)
3550
0
  {
3551
0
    current->line_filepos = lineno_base;
3552
0
    current->moving_line_filepos = lineno_base;
3553
0
    lineno_base += current->lineno_count * bfd_coff_linesz (abfd);
3554
0
  }
3555
0
      else
3556
0
  current->line_filepos = 0;
3557
3558
0
      if (current->reloc_count)
3559
0
  {
3560
0
    current->rel_filepos = reloc_base;
3561
0
    reloc_base += current->reloc_count * bfd_coff_relsz (abfd);
3562
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3563
    /* Extra reloc to hold real count.  */
3564
    if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3565
      reloc_base += bfd_coff_relsz (abfd);
3566
#endif
3567
0
  }
3568
0
      else
3569
0
  current->rel_filepos = 0;
3570
0
    }
3571
3572
  /* Write section headers to the file.  */
3573
1
  internal_f.f_nscns = 0;
3574
3575
1
  if ((abfd->flags & EXEC_P) != 0)
3576
0
    scn_base = bfd_coff_filhsz (abfd) + bfd_coff_aoutsz (abfd);
3577
1
  else
3578
1
    {
3579
1
      scn_base = bfd_coff_filhsz (abfd);
3580
#ifdef RS6000COFF_C
3581
#ifndef XCOFF64
3582
      if (xcoff_data (abfd)->full_aouthdr)
3583
  scn_base += bfd_coff_aoutsz (abfd);
3584
      else
3585
  scn_base += SMALL_AOUTSZ;
3586
#endif
3587
#endif
3588
1
    }
3589
3590
1
  if (bfd_seek (abfd, scn_base, SEEK_SET) != 0)
3591
0
    return false;
3592
3593
1
  long_section_names = false;
3594
1
  for (current = abfd->sections;
3595
1
       current != NULL;
3596
1
       current = current->next)
3597
0
    {
3598
0
      struct internal_scnhdr section;
3599
#ifdef COFF_IMAGE_WITH_PE
3600
      bool is_reloc_section = false;
3601
3602
      if (strcmp (current->name, DOT_RELOC) == 0)
3603
  {
3604
    is_reloc_section = true;
3605
    hasrelocs = true;
3606
    pe_data (abfd)->has_reloc_section = 1;
3607
  }
3608
#endif
3609
3610
0
      internal_f.f_nscns++;
3611
3612
0
      strncpy (section.s_name, current->name, SCNNMLEN);
3613
3614
#ifdef COFF_LONG_SECTION_NAMES
3615
      /* Handle long section names as in PE.  This must be compatible
3616
   with the code in coff_write_symbols and _bfd_coff_final_link.  */
3617
      if (bfd_coff_long_section_names (abfd))
3618
  {
3619
    size_t len;
3620
3621
    len = strlen (current->name);
3622
    if (len > SCNNMLEN)
3623
      {
3624
3625
        /* An inherent limitation of the /nnnnnnn notation used to indicate
3626
     the offset of the long name in the string table is that we
3627
     cannot address entries beyone the ten million byte boundary.  */
3628
        if (string_size < 10000000)
3629
    {
3630
      /* The s_name field is defined to be NUL-padded but need not
3631
         be NUL-terminated.  We use a temporary buffer so that we
3632
         can still sprintf all eight chars without splatting a
3633
         terminating NUL over the first byte of the following
3634
         member (s_paddr).  */
3635
      /* PR 21096: The +20 is to stop a bogus warning from gcc7
3636
         about a possible buffer overflow.  */
3637
      char s_name_buf[SCNNMLEN + 1 + 20];
3638
3639
      /* We do not need to use snprintf here as we have already
3640
         verified that string_size is not too big, plus we have
3641
         an overlarge buffer, just in case.  */
3642
      sprintf (s_name_buf, "/%lu", (unsigned long) string_size);
3643
      /* Then strncpy takes care of any padding for us.  */
3644
      strncpy (section.s_name, s_name_buf, SCNNMLEN);
3645
    }
3646
        else
3647
#ifdef COFF_WITH_PE
3648
    {
3649
      /* PE use a base 64 encoding for long section names whose
3650
         index is very large.  But contrary to RFC 4648, there is
3651
         no padding: 6 characters must be generated.  */
3652
      static const char base64[] =
3653
        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
3654
        "abcdefghijklmnopqrstuvwxyz"
3655
        "0123456789+/";
3656
      unsigned long off = string_size;
3657
      unsigned i;
3658
3659
      section.s_name[0] = '/';
3660
      section.s_name[1] = '/';
3661
      for (i = SCNNMLEN - 1; i >= 2; i--)
3662
        {
3663
          section.s_name[i] = base64[off & 0x3f];
3664
          off >>= 6;
3665
        }
3666
    }
3667
#endif
3668
        if (string_size > 0xffffffffUL - (len + 1)
3669
#ifndef COFF_WITH_PE
3670
      || string_size >= 10000000
3671
#endif
3672
      )
3673
    {
3674
      bfd_set_error (bfd_error_file_too_big);
3675
      _bfd_error_handler
3676
        /* xgettext:c-format */
3677
        (_("%pB: section %pA: string table overflow at offset %ld"),
3678
        abfd, current, (unsigned long) string_size);
3679
      return false;
3680
    }
3681
3682
        string_size += len + 1;
3683
        long_section_names = true;
3684
      }
3685
  }
3686
#endif
3687
3688
0
#ifdef _LIB
3689
      /* Always set s_vaddr of .lib to 0.  This is right for SVR3.2
3690
   Ian Taylor <ian@cygnus.com>.  */
3691
0
      if (strcmp (current->name, _LIB) == 0)
3692
0
  section.s_vaddr = 0;
3693
0
      else
3694
0
#endif
3695
0
      section.s_vaddr = current->vma;
3696
0
      section.s_paddr = current->lma;
3697
0
      section.s_size =  current->size;
3698
#ifdef coff_get_section_load_page
3699
      section.s_page = coff_get_section_load_page (current);
3700
#else
3701
0
      section.s_page = 0;
3702
0
#endif
3703
3704
#ifdef COFF_WITH_PE
3705
      section.s_paddr = 0;
3706
#endif
3707
#ifdef COFF_IMAGE_WITH_PE
3708
      /* Reminder: s_paddr holds the virtual size of the section.  */
3709
      if (coff_section_data (abfd, current) != NULL
3710
    && pei_section_data (abfd, current) != NULL)
3711
  section.s_paddr = pei_section_data (abfd, current)->virt_size;
3712
      else
3713
  section.s_paddr = 0;
3714
#endif
3715
3716
      /* If this section has no size or is unloadable then the scnptr
3717
   will be 0 too.  */
3718
0
      if (current->size == 0
3719
0
    || (current->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
3720
0
  section.s_scnptr = 0;
3721
0
      else
3722
0
  section.s_scnptr = current->filepos;
3723
3724
0
      section.s_relptr = current->rel_filepos;
3725
0
      section.s_lnnoptr = current->line_filepos;
3726
0
      section.s_nreloc = current->reloc_count;
3727
0
      section.s_nlnno = current->lineno_count;
3728
0
#ifndef COFF_IMAGE_WITH_PE
3729
      /* In PEI, relocs come in the .reloc section.  */
3730
0
      if (current->reloc_count != 0)
3731
0
  hasrelocs = true;
3732
0
#endif
3733
0
      if (current->lineno_count != 0)
3734
0
  haslinno = true;
3735
#ifdef COFF_IMAGE_WITH_PE
3736
      if ((current->flags & SEC_DEBUGGING) != 0
3737
    && ! is_reloc_section)
3738
  hasdebug = true;
3739
#endif
3740
3741
#ifdef RS6000COFF_C
3742
#ifndef XCOFF64
3743
      /* Indicate the use of an XCOFF overflow section header.  */
3744
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3745
  {
3746
    section.s_nreloc = 0xffff;
3747
    section.s_nlnno = 0xffff;
3748
  }
3749
#endif
3750
#endif
3751
3752
0
      section.s_flags = sec_to_styp_flags (current->name, current->flags);
3753
3754
0
      if (!strcmp (current->name, _TEXT))
3755
0
  text_sec = current;
3756
0
      else if (!strcmp (current->name, _DATA))
3757
0
  data_sec = current;
3758
0
      else if (!strcmp (current->name, _BSS))
3759
0
  bss_sec = current;
3760
#ifdef RS6000COFF_C
3761
      else if (!strcmp (current->name, _TDATA))
3762
  tdata_sec = current;
3763
      else if (!strcmp (current->name, _TBSS))
3764
  tbss_sec = current;
3765
#endif
3766
3767
3768
#ifdef COFF_ENCODE_ALIGNMENT
3769
      if (COFF_ENCODE_ALIGNMENT (abfd, section, current->alignment_power)
3770
    && (COFF_DECODE_ALIGNMENT (section.s_flags)
3771
        != current->alignment_power))
3772
  {
3773
    bool warn = (coff_data (abfd)->link_info
3774
           && !bfd_link_relocatable (coff_data (abfd)->link_info));
3775
3776
    _bfd_error_handler
3777
      /* xgettext:c-format */
3778
      (_("%pB:%s section %s: alignment 2**%u not representable"),
3779
       abfd, warn ? " warning:" : "", current->name,
3780
       current->alignment_power);
3781
    if (!warn)
3782
      {
3783
        bfd_set_error (bfd_error_nonrepresentable_section);
3784
        return false;
3785
      }
3786
  }
3787
#endif
3788
3789
#ifdef COFF_IMAGE_WITH_PE
3790
      /* Suppress output of the sections if they are null.  ld
3791
   includes the bss and data sections even if there is no size
3792
   assigned to them.  NT loader doesn't like it if these section
3793
   headers are included if the sections themselves are not
3794
   needed.  See also coff_compute_section_file_positions.  */
3795
      if (section.s_size == 0)
3796
  internal_f.f_nscns--;
3797
      else
3798
#endif
3799
0
  {
3800
0
    SCNHDR buff;
3801
0
    bfd_size_type amt = bfd_coff_scnhsz (abfd);
3802
3803
0
    if (bfd_coff_swap_scnhdr_out (abfd, &section, &buff) == 0
3804
0
        || bfd_write (& buff, amt, abfd) != amt)
3805
0
      return false;
3806
0
  }
3807
3808
#ifdef COFF_WITH_PE
3809
      /* PE stores COMDAT section information in the symbol table.  If
3810
   this section is supposed to have some COMDAT info, track down
3811
   the symbol in the symbol table and modify it.  */
3812
      if ((current->flags & SEC_LINK_ONCE) != 0)
3813
  {
3814
    unsigned int i, count;
3815
    asymbol **psym;
3816
    coff_symbol_type *csym = NULL;
3817
    asymbol **psymsec;
3818
3819
    psymsec = NULL;
3820
    count = bfd_get_symcount (abfd);
3821
    for (i = 0, psym = abfd->outsymbols; i < count; i++, psym++)
3822
      {
3823
        if ((*psym)->section != current)
3824
    continue;
3825
3826
        /* Remember the location of the first symbol in this
3827
     section.  */
3828
        if (psymsec == NULL)
3829
    psymsec = psym;
3830
3831
        /* See if this is the section symbol.  */
3832
        if (strcmp ((*psym)->name, current->name) == 0)
3833
    {
3834
      csym = coff_symbol_from (*psym);
3835
      if (csym == NULL
3836
          || csym->native == NULL
3837
          || ! csym->native->is_sym
3838
          || csym->native->u.syment.n_numaux < 1
3839
          || csym->native->u.syment.n_sclass != C_STAT
3840
          || csym->native->u.syment.n_type != T_NULL)
3841
        continue;
3842
3843
      /* Here *PSYM is the section symbol for CURRENT.  */
3844
3845
      break;
3846
    }
3847
      }
3848
3849
    /* Did we find it?
3850
       Note that we might not if we're converting the file from
3851
       some other object file format.  */
3852
    if (i < count)
3853
      {
3854
        combined_entry_type *aux;
3855
3856
        /* We don't touch the x_checksum field.  The
3857
     x_associated field is not currently supported.  */
3858
3859
        aux = csym->native + 1;
3860
        BFD_ASSERT (! aux->is_sym);
3861
        switch (current->flags & SEC_LINK_DUPLICATES)
3862
    {
3863
    case SEC_LINK_DUPLICATES_DISCARD:
3864
      aux->u.auxent.x_scn.x_comdat = IMAGE_COMDAT_SELECT_ANY;
3865
      break;
3866
3867
    case SEC_LINK_DUPLICATES_ONE_ONLY:
3868
      aux->u.auxent.x_scn.x_comdat =
3869
        IMAGE_COMDAT_SELECT_NODUPLICATES;
3870
      break;
3871
3872
    case SEC_LINK_DUPLICATES_SAME_SIZE:
3873
      aux->u.auxent.x_scn.x_comdat =
3874
        IMAGE_COMDAT_SELECT_SAME_SIZE;
3875
      break;
3876
3877
    case SEC_LINK_DUPLICATES_SAME_CONTENTS:
3878
      aux->u.auxent.x_scn.x_comdat =
3879
        IMAGE_COMDAT_SELECT_EXACT_MATCH;
3880
      break;
3881
    }
3882
3883
        /* The COMDAT symbol must be the first symbol from this
3884
     section in the symbol table.  In order to make this
3885
     work, we move the COMDAT symbol before the first
3886
     symbol we found in the search above.  It's OK to
3887
     rearrange the symbol table at this point, because
3888
     coff_renumber_symbols is going to rearrange it
3889
     further and fix up all the aux entries.  */
3890
        if (psym != psymsec)
3891
    {
3892
      asymbol *hold;
3893
      asymbol **pcopy;
3894
3895
      hold = *psym;
3896
      for (pcopy = psym; pcopy > psymsec; pcopy--)
3897
        pcopy[0] = pcopy[-1];
3898
      *psymsec = hold;
3899
    }
3900
      }
3901
  }
3902
#endif /* COFF_WITH_PE */
3903
0
    }
3904
3905
#ifdef RS6000COFF_C
3906
#ifndef XCOFF64
3907
  /* XCOFF handles overflows in the reloc and line number count fields
3908
     by creating a new section header to hold the correct values.  */
3909
  for (current = abfd->sections; current != NULL; current = current->next)
3910
    {
3911
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3912
  {
3913
    struct internal_scnhdr scnhdr;
3914
    SCNHDR buff;
3915
    bfd_size_type amt;
3916
3917
    internal_f.f_nscns++;
3918
    memcpy (scnhdr.s_name, ".ovrflo", 8);
3919
    scnhdr.s_paddr = current->reloc_count;
3920
    scnhdr.s_vaddr = current->lineno_count;
3921
    scnhdr.s_size = 0;
3922
    scnhdr.s_scnptr = 0;
3923
    scnhdr.s_relptr = current->rel_filepos;
3924
    scnhdr.s_lnnoptr = current->line_filepos;
3925
    scnhdr.s_nreloc = current->target_index;
3926
    scnhdr.s_nlnno = current->target_index;
3927
    scnhdr.s_flags = STYP_OVRFLO;
3928
    amt = bfd_coff_scnhsz (abfd);
3929
    if (bfd_coff_swap_scnhdr_out (abfd, &scnhdr, &buff) == 0
3930
        || bfd_write (& buff, amt, abfd) != amt)
3931
      return false;
3932
  }
3933
    }
3934
#endif
3935
#endif
3936
3937
#if defined (COFF_GO32_EXE) || defined (COFF_GO32)
3938
  /* Pad section headers.  */
3939
  if ((abfd->flags & EXEC_P) != 0)
3940
    {
3941
      asection *s = abfd->sections;
3942
      while (s != NULL && s->filepos == 0)
3943
  s = s->next;
3944
      if (s != NULL)
3945
  {
3946
    file_ptr cur_ptr
3947
      = scn_base + abfd->section_count * bfd_coff_scnhsz (abfd);
3948
    file_ptr fill_size = s->filepos - cur_ptr;
3949
    if (fill_size > 0)
3950
      {
3951
        bfd_byte *b = bfd_zmalloc (fill_size);
3952
        if (!b)
3953
    return false;
3954
        if (bfd_write (b, fill_size, abfd) != (ufile_ptr) fill_size)
3955
    {
3956
      free (b);
3957
      return false;
3958
    }
3959
        free (b);
3960
      }
3961
  }
3962
    }
3963
#endif
3964
3965
  /* OK, now set up the filehdr...  */
3966
3967
  /* Don't include the internal abs section in the section count */
3968
3969
  /* We will NOT put a fucking timestamp in the header here. Every time you
3970
     put it back, I will come in and take it out again.  I'm sorry.  This
3971
     field does not belong here.  We fill it with a 0 so it compares the
3972
     same but is not a reasonable time. -- gnu@cygnus.com  */
3973
1
  internal_f.f_timdat = 0;
3974
1
  internal_f.f_flags = 0;
3975
3976
1
  if (abfd->flags & EXEC_P)
3977
0
    internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3978
1
  else
3979
1
    {
3980
1
      internal_f.f_opthdr = 0;
3981
#ifdef RS6000COFF_C
3982
#ifndef XCOFF64
3983
      if (xcoff_data (abfd)->full_aouthdr)
3984
  internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3985
      else
3986
  internal_f.f_opthdr = SMALL_AOUTSZ;
3987
#endif
3988
#endif
3989
1
    }
3990
3991
1
  if (!hasrelocs)
3992
1
    internal_f.f_flags |= F_RELFLG;
3993
1
  if (!haslinno)
3994
1
    internal_f.f_flags |= F_LNNO;
3995
1
  if (abfd->flags & EXEC_P)
3996
0
    internal_f.f_flags |= F_EXEC;
3997
#ifdef COFF_IMAGE_WITH_PE
3998
  if (! hasdebug)
3999
    internal_f.f_flags |= IMAGE_FILE_DEBUG_STRIPPED;
4000
  if (pe_data (abfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
4001
    internal_f.f_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
4002
#endif
4003
4004
1
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
4005
#ifdef COFF_WITH_PE
4006
  internal_f.f_flags |= IMAGE_FILE_32BIT_MACHINE;
4007
#else
4008
1
  if (bfd_little_endian (abfd))
4009
0
    internal_f.f_flags |= F_AR32WR;
4010
1
  else
4011
1
    internal_f.f_flags |= F_AR32W;
4012
1
#endif
4013
1
#endif
4014
4015
#ifdef TI_TARGET_ID
4016
  /* Target id is used in TI COFF v1 and later; COFF0 won't use this field,
4017
     but it doesn't hurt to set it internally.  */
4018
  internal_f.f_target_id = TI_TARGET_ID;
4019
#endif
4020
4021
  /* FIXME, should do something about the other byte orders and
4022
     architectures.  */
4023
4024
#ifdef RS6000COFF_C
4025
  if ((abfd->flags & DYNAMIC) != 0)
4026
    internal_f.f_flags |= F_SHROBJ;
4027
  if (bfd_get_section_by_name (abfd, _LOADER) != NULL)
4028
    internal_f.f_flags |= F_DYNLOAD;
4029
#endif
4030
4031
1
  memset (&internal_a, 0, sizeof internal_a);
4032
4033
  /* Set up architecture-dependent stuff.  */
4034
1
  {
4035
1
    unsigned int magic = 0;
4036
1
    unsigned short flags = 0;
4037
4038
1
    coff_set_flags (abfd, &magic, &flags);
4039
1
    internal_f.f_magic = magic;
4040
1
    internal_f.f_flags |= flags;
4041
    /* ...and the "opt"hdr...  */
4042
4043
#ifdef TICOFF_AOUT_MAGIC
4044
    internal_a.magic = TICOFF_AOUT_MAGIC;
4045
#define __A_MAGIC_SET__
4046
#endif
4047
4048
#if defined(ARM)
4049
#define __A_MAGIC_SET__
4050
    internal_a.magic = ZMAGIC;
4051
#endif
4052
4053
#if defined(AARCH64)
4054
#define __A_MAGIC_SET__
4055
    internal_a.magic = ZMAGIC;
4056
#endif
4057
4058
#if defined(LOONGARCH64)
4059
#define __A_MAGIC_SET__
4060
    internal_a.magic = ZMAGIC;
4061
#endif
4062
4063
#if defined MCORE_PE
4064
#define __A_MAGIC_SET__
4065
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR_MAGIC;
4066
#endif
4067
4068
#if defined(I386)
4069
#define __A_MAGIC_SET__
4070
#if defined LYNXOS
4071
    internal_a.magic = LYNXCOFFMAGIC;
4072
#elif defined AMD64
4073
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR64_MAGIC;
4074
#else
4075
    internal_a.magic = ZMAGIC;
4076
#endif
4077
#endif /* I386 */
4078
4079
#if defined(IA64)
4080
#define __A_MAGIC_SET__
4081
    internal_a.magic = PE32PMAGIC;
4082
#endif /* IA64 */
4083
4084
#if defined(SPARC)
4085
#define __A_MAGIC_SET__
4086
#if defined(LYNXOS)
4087
    internal_a.magic = LYNXCOFFMAGIC;
4088
#endif /* LYNXOS */
4089
#endif /* SPARC */
4090
4091
#ifdef RS6000COFF_C
4092
#define __A_MAGIC_SET__
4093
    internal_a.magic = (abfd->flags & D_PAGED) ? RS6K_AOUTHDR_ZMAGIC :
4094
    (abfd->flags & WP_TEXT) ? RS6K_AOUTHDR_NMAGIC :
4095
    RS6K_AOUTHDR_OMAGIC;
4096
#endif
4097
4098
#if defined(SH) && defined(COFF_WITH_PE)
4099
#define __A_MAGIC_SET__
4100
    internal_a.magic = SH_PE_MAGIC;
4101
#endif
4102
4103
#if defined(MIPS) && defined(COFF_WITH_PE)
4104
#define __A_MAGIC_SET__
4105
    internal_a.magic = MIPS_PE_MAGIC;
4106
#endif
4107
4108
#ifndef __A_MAGIC_SET__
4109
#include "Your aouthdr magic number is not being set!"
4110
#else
4111
1
#undef __A_MAGIC_SET__
4112
1
#endif
4113
1
  }
4114
4115
#ifdef RS6000COFF_C
4116
  /* XCOFF 32bit needs this to have new behaviour for n_type field.  */
4117
  internal_a.vstamp = 2;
4118
#else
4119
  /* FIXME: Does anybody ever set this to another value?  */
4120
1
  internal_a.vstamp = 0;
4121
1
#endif
4122
4123
  /* Now should write relocs, strings, syms.  */
4124
1
  obj_sym_filepos (abfd) = sym_base;
4125
4126
1
  if (bfd_get_symcount (abfd) != 0)
4127
0
    {
4128
0
      int firstundef;
4129
4130
0
      if (!coff_renumber_symbols (abfd, &firstundef))
4131
0
  return false;
4132
0
      coff_mangle_symbols (abfd);
4133
0
      if (! coff_write_symbols (abfd))
4134
0
  return false;
4135
0
      if (! coff_write_linenumbers (abfd))
4136
0
  return false;
4137
0
      if (! coff_write_relocs (abfd, firstundef))
4138
0
  return false;
4139
0
    }
4140
#ifdef COFF_LONG_SECTION_NAMES
4141
  else if (long_section_names && ! obj_coff_strings_written (abfd))
4142
    {
4143
      /* If we have long section names we have to write out the string
4144
   table even if there are no symbols.  */
4145
      if (! coff_write_symbols (abfd))
4146
  return false;
4147
    }
4148
#endif
4149
  /* If bfd_get_symcount (abfd) != 0, then we are not using the COFF
4150
     backend linker, and obj_raw_syment_count is not valid until after
4151
     coff_write_symbols is called.  */
4152
1
  if (obj_raw_syment_count (abfd) != 0)
4153
0
    {
4154
0
      internal_f.f_symptr = sym_base;
4155
#ifdef RS6000COFF_C
4156
      /* AIX appears to require that F_RELFLG not be set if there are
4157
   local symbols but no relocations.  */
4158
      internal_f.f_flags &=~ F_RELFLG;
4159
#endif
4160
0
    }
4161
1
  else
4162
1
    {
4163
1
      if (long_section_names)
4164
0
  internal_f.f_symptr = sym_base;
4165
1
      else
4166
1
  internal_f.f_symptr = 0;
4167
1
      internal_f.f_flags |= F_LSYMS;
4168
1
    }
4169
4170
1
  if (text_sec)
4171
0
    {
4172
0
      internal_a.tsize = text_sec->size;
4173
0
      internal_a.text_start = internal_a.tsize ? text_sec->vma : 0;
4174
0
    }
4175
1
  if (data_sec)
4176
0
    {
4177
0
      internal_a.dsize = data_sec->size;
4178
0
      internal_a.data_start = internal_a.dsize ? data_sec->vma : 0;
4179
0
    }
4180
1
  if (bss_sec)
4181
0
    {
4182
0
      internal_a.bsize = bss_sec->size;
4183
0
      if (internal_a.bsize && bss_sec->vma < internal_a.data_start)
4184
0
  internal_a.data_start = bss_sec->vma;
4185
0
    }
4186
4187
1
  internal_a.entry = bfd_get_start_address (abfd);
4188
1
  internal_f.f_nsyms = obj_raw_syment_count (abfd);
4189
4190
#ifdef RS6000COFF_C
4191
  if (xcoff_data (abfd)->full_aouthdr)
4192
    {
4193
      bfd_vma toc;
4194
      asection *loader_sec;
4195
4196
      internal_a.vstamp = 2;
4197
4198
      internal_a.o_snentry = xcoff_data (abfd)->snentry;
4199
      if (internal_a.o_snentry == 0)
4200
  internal_a.entry = (bfd_vma) -1;
4201
4202
      if (text_sec != NULL)
4203
  {
4204
    internal_a.o_sntext = text_sec->target_index;
4205
    internal_a.o_algntext = bfd_section_alignment (text_sec);
4206
  }
4207
      else
4208
  {
4209
    internal_a.o_sntext = 0;
4210
    internal_a.o_algntext = 0;
4211
  }
4212
      if (data_sec != NULL)
4213
  {
4214
    internal_a.o_sndata = data_sec->target_index;
4215
    internal_a.o_algndata = bfd_section_alignment (data_sec);
4216
  }
4217
      else
4218
  {
4219
    internal_a.o_sndata = 0;
4220
    internal_a.o_algndata = 0;
4221
  }
4222
      loader_sec = bfd_get_section_by_name (abfd, ".loader");
4223
      if (loader_sec != NULL)
4224
  internal_a.o_snloader = loader_sec->target_index;
4225
      else
4226
  internal_a.o_snloader = 0;
4227
      if (bss_sec != NULL)
4228
  internal_a.o_snbss = bss_sec->target_index;
4229
      else
4230
  internal_a.o_snbss = 0;
4231
4232
      if (tdata_sec != NULL)
4233
  {
4234
    internal_a.o_sntdata = tdata_sec->target_index;
4235
    /* TODO: o_flags should be set to RS6K_AOUTHDR_TLS_LE
4236
       if there is at least one R_TLS_LE relocations.  */
4237
    internal_a.o_flags = 0;
4238
#ifdef XCOFF64
4239
    internal_a.o_x64flags = 0;
4240
#endif
4241
  }
4242
      else
4243
  {
4244
    internal_a.o_sntdata = 0;
4245
    internal_a.o_flags = 0;
4246
#ifdef XCOFF64
4247
    internal_a.o_x64flags = 0;
4248
#endif
4249
  }
4250
      if (tbss_sec != NULL)
4251
    internal_a.o_sntbss = tbss_sec->target_index;
4252
      else
4253
    internal_a.o_sntbss = 0;
4254
4255
      toc = xcoff_data (abfd)->toc;
4256
      internal_a.o_toc = toc;
4257
      internal_a.o_sntoc = xcoff_data (abfd)->sntoc;
4258
4259
      internal_a.o_modtype = xcoff_data (abfd)->modtype;
4260
      if (xcoff_data (abfd)->cputype != -1)
4261
  internal_a.o_cputype = xcoff_data (abfd)->cputype;
4262
      else
4263
  {
4264
    switch (bfd_get_arch (abfd))
4265
      {
4266
      case bfd_arch_rs6000:
4267
        internal_a.o_cputype = 4;
4268
        break;
4269
      case bfd_arch_powerpc:
4270
        if (bfd_get_mach (abfd) == bfd_mach_ppc)
4271
    internal_a.o_cputype = 3;
4272
        else if (bfd_get_mach (abfd) == bfd_mach_ppc_620)
4273
    internal_a.o_cputype = 2;
4274
        else
4275
    internal_a.o_cputype = 1;
4276
        break;
4277
      default:
4278
        abort ();
4279
      }
4280
  }
4281
      internal_a.o_maxstack = xcoff_data (abfd)->maxstack;
4282
      internal_a.o_maxdata = xcoff_data (abfd)->maxdata;
4283
    }
4284
#endif
4285
4286
#ifdef COFF_WITH_PE
4287
  {
4288
    /* After object contents are finalized so we can compute a reasonable hash,
4289
       but before header is written so we can update it to point to debug directory.  */
4290
    struct pe_tdata *pe = pe_data (abfd);
4291
4292
    if (pe->build_id.after_write_object_contents != NULL)
4293
      (*pe->build_id.after_write_object_contents) (abfd);
4294
  }
4295
#endif
4296
4297
  /* Now write header.  */
4298
1
  if (bfd_seek (abfd, 0, SEEK_SET) != 0)
4299
0
    return false;
4300
4301
1
  {
4302
1
    char * buff;
4303
1
    bfd_size_type amount = bfd_coff_filhsz (abfd);
4304
4305
1
    buff = (char *) bfd_malloc (amount);
4306
1
    if (buff == NULL)
4307
0
      return false;
4308
4309
1
    bfd_coff_swap_filehdr_out (abfd, & internal_f, buff);
4310
1
    amount = bfd_write (buff, amount, abfd);
4311
4312
1
    free (buff);
4313
4314
1
    if (amount != bfd_coff_filhsz (abfd))
4315
0
      return false;
4316
1
  }
4317
4318
1
  if (abfd->flags & EXEC_P)
4319
0
    {
4320
      /* Note that peicode.h fills in a PEAOUTHDR, not an AOUTHDR.
4321
   include/coff/pe.h sets AOUTSZ == sizeof (PEAOUTHDR)).  */
4322
0
      char * buff;
4323
0
      bfd_size_type amount = bfd_coff_aoutsz (abfd);
4324
4325
0
      buff = (char *) bfd_malloc (amount);
4326
0
      if (buff == NULL)
4327
0
  return false;
4328
4329
0
      coff_swap_aouthdr_out (abfd, & internal_a, buff);
4330
0
      amount = bfd_write (buff, amount, abfd);
4331
4332
0
      free (buff);
4333
4334
0
      if (amount != bfd_coff_aoutsz (abfd))
4335
0
  return false;
4336
4337
#ifdef COFF_IMAGE_WITH_PE
4338
      if (! coff_apply_checksum (abfd))
4339
  return false;
4340
#endif
4341
0
    }
4342
#ifdef RS6000COFF_C
4343
#ifndef XCOFF64
4344
  else
4345
    {
4346
      AOUTHDR buff;
4347
      size_t size;
4348
4349
      /* XCOFF32 seems to always write at least a small a.out header.  */
4350
      coff_swap_aouthdr_out (abfd, & internal_a, & buff);
4351
      if (xcoff_data (abfd)->full_aouthdr)
4352
  size = bfd_coff_aoutsz (abfd);
4353
      else
4354
  size = SMALL_AOUTSZ;
4355
      if (bfd_write (&buff, size, abfd) != size)
4356
  return false;
4357
    }
4358
#endif
4359
#endif
4360
4361
1
  return true;
4362
1
}
Unexecuted instantiation: coff-stgo32.c:coff_write_object_contents
Unexecuted instantiation: coff-tic30.c:coff_write_object_contents
Unexecuted instantiation: coff-tic4x.c:coff_write_object_contents
Unexecuted instantiation: coff-tic54x.c:coff_write_object_contents
Unexecuted instantiation: coff-z80.c:coff_write_object_contents
coff-z8k.c:coff_write_object_contents
Line
Count
Source
3486
3
{
3487
3
  asection *current;
3488
3
  bool hasrelocs = false;
3489
3
  bool haslinno = false;
3490
#ifdef COFF_IMAGE_WITH_PE
3491
  bool hasdebug = false;
3492
#endif
3493
3
  file_ptr scn_base;
3494
3
  file_ptr reloc_base;
3495
3
  file_ptr lineno_base;
3496
3
  file_ptr sym_base;
3497
3
  unsigned long reloc_size = 0, reloc_count = 0;
3498
3
  unsigned long lnno_size = 0;
3499
3
  bool long_section_names;
3500
3
  asection *text_sec = NULL;
3501
3
  asection *data_sec = NULL;
3502
3
  asection *bss_sec = NULL;
3503
#ifdef RS6000COFF_C
3504
  asection *tdata_sec = NULL;
3505
  asection *tbss_sec = NULL;
3506
#endif
3507
3
  struct internal_filehdr internal_f;
3508
3
  struct internal_aouthdr internal_a;
3509
#ifdef COFF_LONG_SECTION_NAMES
3510
  size_t string_size = STRING_SIZE_SIZE;
3511
#endif
3512
3513
3
  bfd_set_error (bfd_error_system_call);
3514
3515
  /* Make a pass through the symbol table to count line number entries and
3516
     put them into the correct asections.  */
3517
3
  lnno_size = coff_count_linenumbers (abfd) * bfd_coff_linesz (abfd);
3518
3519
3
  if (! abfd->output_has_begun)
3520
2
    {
3521
2
      if (! coff_compute_section_file_positions (abfd))
3522
0
  return false;
3523
2
    }
3524
3525
3
  reloc_base = obj_relocbase (abfd);
3526
3527
  /* Work out the size of the reloc and linno areas.  */
3528
3529
257
  for (current = abfd->sections; current != NULL; current =
3530
254
       current->next)
3531
254
    {
3532
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3533
      /* We store the actual reloc count in the first reloc's addr.  */
3534
      if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3535
  reloc_count ++;
3536
#endif
3537
254
      reloc_count += current->reloc_count;
3538
254
    }
3539
3540
3
  reloc_size = reloc_count * bfd_coff_relsz (abfd);
3541
3542
3
  lineno_base = reloc_base + reloc_size;
3543
3
  sym_base = lineno_base + lnno_size;
3544
3545
  /* Indicate in each section->line_filepos its actual file address.  */
3546
257
  for (current = abfd->sections; current != NULL; current =
3547
254
       current->next)
3548
254
    {
3549
254
      if (current->lineno_count)
3550
0
  {
3551
0
    current->line_filepos = lineno_base;
3552
0
    current->moving_line_filepos = lineno_base;
3553
0
    lineno_base += current->lineno_count * bfd_coff_linesz (abfd);
3554
0
  }
3555
254
      else
3556
254
  current->line_filepos = 0;
3557
3558
254
      if (current->reloc_count)
3559
0
  {
3560
0
    current->rel_filepos = reloc_base;
3561
0
    reloc_base += current->reloc_count * bfd_coff_relsz (abfd);
3562
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3563
    /* Extra reloc to hold real count.  */
3564
    if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3565
      reloc_base += bfd_coff_relsz (abfd);
3566
#endif
3567
0
  }
3568
254
      else
3569
254
  current->rel_filepos = 0;
3570
254
    }
3571
3572
  /* Write section headers to the file.  */
3573
3
  internal_f.f_nscns = 0;
3574
3575
3
  if ((abfd->flags & EXEC_P) != 0)
3576
3
    scn_base = bfd_coff_filhsz (abfd) + bfd_coff_aoutsz (abfd);
3577
0
  else
3578
0
    {
3579
0
      scn_base = bfd_coff_filhsz (abfd);
3580
#ifdef RS6000COFF_C
3581
#ifndef XCOFF64
3582
      if (xcoff_data (abfd)->full_aouthdr)
3583
  scn_base += bfd_coff_aoutsz (abfd);
3584
      else
3585
  scn_base += SMALL_AOUTSZ;
3586
#endif
3587
#endif
3588
0
    }
3589
3590
3
  if (bfd_seek (abfd, scn_base, SEEK_SET) != 0)
3591
0
    return false;
3592
3593
3
  long_section_names = false;
3594
3
  for (current = abfd->sections;
3595
257
       current != NULL;
3596
254
       current = current->next)
3597
254
    {
3598
254
      struct internal_scnhdr section;
3599
#ifdef COFF_IMAGE_WITH_PE
3600
      bool is_reloc_section = false;
3601
3602
      if (strcmp (current->name, DOT_RELOC) == 0)
3603
  {
3604
    is_reloc_section = true;
3605
    hasrelocs = true;
3606
    pe_data (abfd)->has_reloc_section = 1;
3607
  }
3608
#endif
3609
3610
254
      internal_f.f_nscns++;
3611
3612
254
      strncpy (section.s_name, current->name, SCNNMLEN);
3613
3614
#ifdef COFF_LONG_SECTION_NAMES
3615
      /* Handle long section names as in PE.  This must be compatible
3616
   with the code in coff_write_symbols and _bfd_coff_final_link.  */
3617
      if (bfd_coff_long_section_names (abfd))
3618
  {
3619
    size_t len;
3620
3621
    len = strlen (current->name);
3622
    if (len > SCNNMLEN)
3623
      {
3624
3625
        /* An inherent limitation of the /nnnnnnn notation used to indicate
3626
     the offset of the long name in the string table is that we
3627
     cannot address entries beyone the ten million byte boundary.  */
3628
        if (string_size < 10000000)
3629
    {
3630
      /* The s_name field is defined to be NUL-padded but need not
3631
         be NUL-terminated.  We use a temporary buffer so that we
3632
         can still sprintf all eight chars without splatting a
3633
         terminating NUL over the first byte of the following
3634
         member (s_paddr).  */
3635
      /* PR 21096: The +20 is to stop a bogus warning from gcc7
3636
         about a possible buffer overflow.  */
3637
      char s_name_buf[SCNNMLEN + 1 + 20];
3638
3639
      /* We do not need to use snprintf here as we have already
3640
         verified that string_size is not too big, plus we have
3641
         an overlarge buffer, just in case.  */
3642
      sprintf (s_name_buf, "/%lu", (unsigned long) string_size);
3643
      /* Then strncpy takes care of any padding for us.  */
3644
      strncpy (section.s_name, s_name_buf, SCNNMLEN);
3645
    }
3646
        else
3647
#ifdef COFF_WITH_PE
3648
    {
3649
      /* PE use a base 64 encoding for long section names whose
3650
         index is very large.  But contrary to RFC 4648, there is
3651
         no padding: 6 characters must be generated.  */
3652
      static const char base64[] =
3653
        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
3654
        "abcdefghijklmnopqrstuvwxyz"
3655
        "0123456789+/";
3656
      unsigned long off = string_size;
3657
      unsigned i;
3658
3659
      section.s_name[0] = '/';
3660
      section.s_name[1] = '/';
3661
      for (i = SCNNMLEN - 1; i >= 2; i--)
3662
        {
3663
          section.s_name[i] = base64[off & 0x3f];
3664
          off >>= 6;
3665
        }
3666
    }
3667
#endif
3668
        if (string_size > 0xffffffffUL - (len + 1)
3669
#ifndef COFF_WITH_PE
3670
      || string_size >= 10000000
3671
#endif
3672
      )
3673
    {
3674
      bfd_set_error (bfd_error_file_too_big);
3675
      _bfd_error_handler
3676
        /* xgettext:c-format */
3677
        (_("%pB: section %pA: string table overflow at offset %ld"),
3678
        abfd, current, (unsigned long) string_size);
3679
      return false;
3680
    }
3681
3682
        string_size += len + 1;
3683
        long_section_names = true;
3684
      }
3685
  }
3686
#endif
3687
3688
254
#ifdef _LIB
3689
      /* Always set s_vaddr of .lib to 0.  This is right for SVR3.2
3690
   Ian Taylor <ian@cygnus.com>.  */
3691
254
      if (strcmp (current->name, _LIB) == 0)
3692
0
  section.s_vaddr = 0;
3693
254
      else
3694
254
#endif
3695
254
      section.s_vaddr = current->vma;
3696
254
      section.s_paddr = current->lma;
3697
254
      section.s_size =  current->size;
3698
#ifdef coff_get_section_load_page
3699
      section.s_page = coff_get_section_load_page (current);
3700
#else
3701
254
      section.s_page = 0;
3702
254
#endif
3703
3704
#ifdef COFF_WITH_PE
3705
      section.s_paddr = 0;
3706
#endif
3707
#ifdef COFF_IMAGE_WITH_PE
3708
      /* Reminder: s_paddr holds the virtual size of the section.  */
3709
      if (coff_section_data (abfd, current) != NULL
3710
    && pei_section_data (abfd, current) != NULL)
3711
  section.s_paddr = pei_section_data (abfd, current)->virt_size;
3712
      else
3713
  section.s_paddr = 0;
3714
#endif
3715
3716
      /* If this section has no size or is unloadable then the scnptr
3717
   will be 0 too.  */
3718
254
      if (current->size == 0
3719
254
    || (current->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
3720
250
  section.s_scnptr = 0;
3721
4
      else
3722
4
  section.s_scnptr = current->filepos;
3723
3724
254
      section.s_relptr = current->rel_filepos;
3725
254
      section.s_lnnoptr = current->line_filepos;
3726
254
      section.s_nreloc = current->reloc_count;
3727
254
      section.s_nlnno = current->lineno_count;
3728
254
#ifndef COFF_IMAGE_WITH_PE
3729
      /* In PEI, relocs come in the .reloc section.  */
3730
254
      if (current->reloc_count != 0)
3731
0
  hasrelocs = true;
3732
254
#endif
3733
254
      if (current->lineno_count != 0)
3734
0
  haslinno = true;
3735
#ifdef COFF_IMAGE_WITH_PE
3736
      if ((current->flags & SEC_DEBUGGING) != 0
3737
    && ! is_reloc_section)
3738
  hasdebug = true;
3739
#endif
3740
3741
#ifdef RS6000COFF_C
3742
#ifndef XCOFF64
3743
      /* Indicate the use of an XCOFF overflow section header.  */
3744
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3745
  {
3746
    section.s_nreloc = 0xffff;
3747
    section.s_nlnno = 0xffff;
3748
  }
3749
#endif
3750
#endif
3751
3752
254
      section.s_flags = sec_to_styp_flags (current->name, current->flags);
3753
3754
254
      if (!strcmp (current->name, _TEXT))
3755
0
  text_sec = current;
3756
254
      else if (!strcmp (current->name, _DATA))
3757
0
  data_sec = current;
3758
254
      else if (!strcmp (current->name, _BSS))
3759
0
  bss_sec = current;
3760
#ifdef RS6000COFF_C
3761
      else if (!strcmp (current->name, _TDATA))
3762
  tdata_sec = current;
3763
      else if (!strcmp (current->name, _TBSS))
3764
  tbss_sec = current;
3765
#endif
3766
3767
3768
#ifdef COFF_ENCODE_ALIGNMENT
3769
      if (COFF_ENCODE_ALIGNMENT (abfd, section, current->alignment_power)
3770
    && (COFF_DECODE_ALIGNMENT (section.s_flags)
3771
        != current->alignment_power))
3772
  {
3773
    bool warn = (coff_data (abfd)->link_info
3774
           && !bfd_link_relocatable (coff_data (abfd)->link_info));
3775
3776
    _bfd_error_handler
3777
      /* xgettext:c-format */
3778
      (_("%pB:%s section %s: alignment 2**%u not representable"),
3779
       abfd, warn ? " warning:" : "", current->name,
3780
       current->alignment_power);
3781
    if (!warn)
3782
      {
3783
        bfd_set_error (bfd_error_nonrepresentable_section);
3784
        return false;
3785
      }
3786
  }
3787
#endif
3788
3789
#ifdef COFF_IMAGE_WITH_PE
3790
      /* Suppress output of the sections if they are null.  ld
3791
   includes the bss and data sections even if there is no size
3792
   assigned to them.  NT loader doesn't like it if these section
3793
   headers are included if the sections themselves are not
3794
   needed.  See also coff_compute_section_file_positions.  */
3795
      if (section.s_size == 0)
3796
  internal_f.f_nscns--;
3797
      else
3798
#endif
3799
254
  {
3800
254
    SCNHDR buff;
3801
254
    bfd_size_type amt = bfd_coff_scnhsz (abfd);
3802
3803
254
    if (bfd_coff_swap_scnhdr_out (abfd, &section, &buff) == 0
3804
254
        || bfd_write (& buff, amt, abfd) != amt)
3805
0
      return false;
3806
254
  }
3807
3808
#ifdef COFF_WITH_PE
3809
      /* PE stores COMDAT section information in the symbol table.  If
3810
   this section is supposed to have some COMDAT info, track down
3811
   the symbol in the symbol table and modify it.  */
3812
      if ((current->flags & SEC_LINK_ONCE) != 0)
3813
  {
3814
    unsigned int i, count;
3815
    asymbol **psym;
3816
    coff_symbol_type *csym = NULL;
3817
    asymbol **psymsec;
3818
3819
    psymsec = NULL;
3820
    count = bfd_get_symcount (abfd);
3821
    for (i = 0, psym = abfd->outsymbols; i < count; i++, psym++)
3822
      {
3823
        if ((*psym)->section != current)
3824
    continue;
3825
3826
        /* Remember the location of the first symbol in this
3827
     section.  */
3828
        if (psymsec == NULL)
3829
    psymsec = psym;
3830
3831
        /* See if this is the section symbol.  */
3832
        if (strcmp ((*psym)->name, current->name) == 0)
3833
    {
3834
      csym = coff_symbol_from (*psym);
3835
      if (csym == NULL
3836
          || csym->native == NULL
3837
          || ! csym->native->is_sym
3838
          || csym->native->u.syment.n_numaux < 1
3839
          || csym->native->u.syment.n_sclass != C_STAT
3840
          || csym->native->u.syment.n_type != T_NULL)
3841
        continue;
3842
3843
      /* Here *PSYM is the section symbol for CURRENT.  */
3844
3845
      break;
3846
    }
3847
      }
3848
3849
    /* Did we find it?
3850
       Note that we might not if we're converting the file from
3851
       some other object file format.  */
3852
    if (i < count)
3853
      {
3854
        combined_entry_type *aux;
3855
3856
        /* We don't touch the x_checksum field.  The
3857
     x_associated field is not currently supported.  */
3858
3859
        aux = csym->native + 1;
3860
        BFD_ASSERT (! aux->is_sym);
3861
        switch (current->flags & SEC_LINK_DUPLICATES)
3862
    {
3863
    case SEC_LINK_DUPLICATES_DISCARD:
3864
      aux->u.auxent.x_scn.x_comdat = IMAGE_COMDAT_SELECT_ANY;
3865
      break;
3866
3867
    case SEC_LINK_DUPLICATES_ONE_ONLY:
3868
      aux->u.auxent.x_scn.x_comdat =
3869
        IMAGE_COMDAT_SELECT_NODUPLICATES;
3870
      break;
3871
3872
    case SEC_LINK_DUPLICATES_SAME_SIZE:
3873
      aux->u.auxent.x_scn.x_comdat =
3874
        IMAGE_COMDAT_SELECT_SAME_SIZE;
3875
      break;
3876
3877
    case SEC_LINK_DUPLICATES_SAME_CONTENTS:
3878
      aux->u.auxent.x_scn.x_comdat =
3879
        IMAGE_COMDAT_SELECT_EXACT_MATCH;
3880
      break;
3881
    }
3882
3883
        /* The COMDAT symbol must be the first symbol from this
3884
     section in the symbol table.  In order to make this
3885
     work, we move the COMDAT symbol before the first
3886
     symbol we found in the search above.  It's OK to
3887
     rearrange the symbol table at this point, because
3888
     coff_renumber_symbols is going to rearrange it
3889
     further and fix up all the aux entries.  */
3890
        if (psym != psymsec)
3891
    {
3892
      asymbol *hold;
3893
      asymbol **pcopy;
3894
3895
      hold = *psym;
3896
      for (pcopy = psym; pcopy > psymsec; pcopy--)
3897
        pcopy[0] = pcopy[-1];
3898
      *psymsec = hold;
3899
    }
3900
      }
3901
  }
3902
#endif /* COFF_WITH_PE */
3903
254
    }
3904
3905
#ifdef RS6000COFF_C
3906
#ifndef XCOFF64
3907
  /* XCOFF handles overflows in the reloc and line number count fields
3908
     by creating a new section header to hold the correct values.  */
3909
  for (current = abfd->sections; current != NULL; current = current->next)
3910
    {
3911
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3912
  {
3913
    struct internal_scnhdr scnhdr;
3914
    SCNHDR buff;
3915
    bfd_size_type amt;
3916
3917
    internal_f.f_nscns++;
3918
    memcpy (scnhdr.s_name, ".ovrflo", 8);
3919
    scnhdr.s_paddr = current->reloc_count;
3920
    scnhdr.s_vaddr = current->lineno_count;
3921
    scnhdr.s_size = 0;
3922
    scnhdr.s_scnptr = 0;
3923
    scnhdr.s_relptr = current->rel_filepos;
3924
    scnhdr.s_lnnoptr = current->line_filepos;
3925
    scnhdr.s_nreloc = current->target_index;
3926
    scnhdr.s_nlnno = current->target_index;
3927
    scnhdr.s_flags = STYP_OVRFLO;
3928
    amt = bfd_coff_scnhsz (abfd);
3929
    if (bfd_coff_swap_scnhdr_out (abfd, &scnhdr, &buff) == 0
3930
        || bfd_write (& buff, amt, abfd) != amt)
3931
      return false;
3932
  }
3933
    }
3934
#endif
3935
#endif
3936
3937
#if defined (COFF_GO32_EXE) || defined (COFF_GO32)
3938
  /* Pad section headers.  */
3939
  if ((abfd->flags & EXEC_P) != 0)
3940
    {
3941
      asection *s = abfd->sections;
3942
      while (s != NULL && s->filepos == 0)
3943
  s = s->next;
3944
      if (s != NULL)
3945
  {
3946
    file_ptr cur_ptr
3947
      = scn_base + abfd->section_count * bfd_coff_scnhsz (abfd);
3948
    file_ptr fill_size = s->filepos - cur_ptr;
3949
    if (fill_size > 0)
3950
      {
3951
        bfd_byte *b = bfd_zmalloc (fill_size);
3952
        if (!b)
3953
    return false;
3954
        if (bfd_write (b, fill_size, abfd) != (ufile_ptr) fill_size)
3955
    {
3956
      free (b);
3957
      return false;
3958
    }
3959
        free (b);
3960
      }
3961
  }
3962
    }
3963
#endif
3964
3965
  /* OK, now set up the filehdr...  */
3966
3967
  /* Don't include the internal abs section in the section count */
3968
3969
  /* We will NOT put a fucking timestamp in the header here. Every time you
3970
     put it back, I will come in and take it out again.  I'm sorry.  This
3971
     field does not belong here.  We fill it with a 0 so it compares the
3972
     same but is not a reasonable time. -- gnu@cygnus.com  */
3973
3
  internal_f.f_timdat = 0;
3974
3
  internal_f.f_flags = 0;
3975
3976
3
  if (abfd->flags & EXEC_P)
3977
3
    internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3978
0
  else
3979
0
    {
3980
0
      internal_f.f_opthdr = 0;
3981
#ifdef RS6000COFF_C
3982
#ifndef XCOFF64
3983
      if (xcoff_data (abfd)->full_aouthdr)
3984
  internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3985
      else
3986
  internal_f.f_opthdr = SMALL_AOUTSZ;
3987
#endif
3988
#endif
3989
0
    }
3990
3991
3
  if (!hasrelocs)
3992
3
    internal_f.f_flags |= F_RELFLG;
3993
3
  if (!haslinno)
3994
3
    internal_f.f_flags |= F_LNNO;
3995
3
  if (abfd->flags & EXEC_P)
3996
3
    internal_f.f_flags |= F_EXEC;
3997
#ifdef COFF_IMAGE_WITH_PE
3998
  if (! hasdebug)
3999
    internal_f.f_flags |= IMAGE_FILE_DEBUG_STRIPPED;
4000
  if (pe_data (abfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
4001
    internal_f.f_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
4002
#endif
4003
4004
3
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
4005
#ifdef COFF_WITH_PE
4006
  internal_f.f_flags |= IMAGE_FILE_32BIT_MACHINE;
4007
#else
4008
3
  if (bfd_little_endian (abfd))
4009
0
    internal_f.f_flags |= F_AR32WR;
4010
3
  else
4011
3
    internal_f.f_flags |= F_AR32W;
4012
3
#endif
4013
3
#endif
4014
4015
#ifdef TI_TARGET_ID
4016
  /* Target id is used in TI COFF v1 and later; COFF0 won't use this field,
4017
     but it doesn't hurt to set it internally.  */
4018
  internal_f.f_target_id = TI_TARGET_ID;
4019
#endif
4020
4021
  /* FIXME, should do something about the other byte orders and
4022
     architectures.  */
4023
4024
#ifdef RS6000COFF_C
4025
  if ((abfd->flags & DYNAMIC) != 0)
4026
    internal_f.f_flags |= F_SHROBJ;
4027
  if (bfd_get_section_by_name (abfd, _LOADER) != NULL)
4028
    internal_f.f_flags |= F_DYNLOAD;
4029
#endif
4030
4031
3
  memset (&internal_a, 0, sizeof internal_a);
4032
4033
  /* Set up architecture-dependent stuff.  */
4034
3
  {
4035
3
    unsigned int magic = 0;
4036
3
    unsigned short flags = 0;
4037
4038
3
    coff_set_flags (abfd, &magic, &flags);
4039
3
    internal_f.f_magic = magic;
4040
3
    internal_f.f_flags |= flags;
4041
    /* ...and the "opt"hdr...  */
4042
4043
#ifdef TICOFF_AOUT_MAGIC
4044
    internal_a.magic = TICOFF_AOUT_MAGIC;
4045
#define __A_MAGIC_SET__
4046
#endif
4047
4048
#if defined(ARM)
4049
#define __A_MAGIC_SET__
4050
    internal_a.magic = ZMAGIC;
4051
#endif
4052
4053
#if defined(AARCH64)
4054
#define __A_MAGIC_SET__
4055
    internal_a.magic = ZMAGIC;
4056
#endif
4057
4058
#if defined(LOONGARCH64)
4059
#define __A_MAGIC_SET__
4060
    internal_a.magic = ZMAGIC;
4061
#endif
4062
4063
#if defined MCORE_PE
4064
#define __A_MAGIC_SET__
4065
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR_MAGIC;
4066
#endif
4067
4068
#if defined(I386)
4069
#define __A_MAGIC_SET__
4070
#if defined LYNXOS
4071
    internal_a.magic = LYNXCOFFMAGIC;
4072
#elif defined AMD64
4073
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR64_MAGIC;
4074
#else
4075
    internal_a.magic = ZMAGIC;
4076
#endif
4077
#endif /* I386 */
4078
4079
#if defined(IA64)
4080
#define __A_MAGIC_SET__
4081
    internal_a.magic = PE32PMAGIC;
4082
#endif /* IA64 */
4083
4084
#if defined(SPARC)
4085
#define __A_MAGIC_SET__
4086
#if defined(LYNXOS)
4087
    internal_a.magic = LYNXCOFFMAGIC;
4088
#endif /* LYNXOS */
4089
#endif /* SPARC */
4090
4091
#ifdef RS6000COFF_C
4092
#define __A_MAGIC_SET__
4093
    internal_a.magic = (abfd->flags & D_PAGED) ? RS6K_AOUTHDR_ZMAGIC :
4094
    (abfd->flags & WP_TEXT) ? RS6K_AOUTHDR_NMAGIC :
4095
    RS6K_AOUTHDR_OMAGIC;
4096
#endif
4097
4098
#if defined(SH) && defined(COFF_WITH_PE)
4099
#define __A_MAGIC_SET__
4100
    internal_a.magic = SH_PE_MAGIC;
4101
#endif
4102
4103
#if defined(MIPS) && defined(COFF_WITH_PE)
4104
#define __A_MAGIC_SET__
4105
    internal_a.magic = MIPS_PE_MAGIC;
4106
#endif
4107
4108
#ifndef __A_MAGIC_SET__
4109
#include "Your aouthdr magic number is not being set!"
4110
#else
4111
3
#undef __A_MAGIC_SET__
4112
3
#endif
4113
3
  }
4114
4115
#ifdef RS6000COFF_C
4116
  /* XCOFF 32bit needs this to have new behaviour for n_type field.  */
4117
  internal_a.vstamp = 2;
4118
#else
4119
  /* FIXME: Does anybody ever set this to another value?  */
4120
3
  internal_a.vstamp = 0;
4121
3
#endif
4122
4123
  /* Now should write relocs, strings, syms.  */
4124
3
  obj_sym_filepos (abfd) = sym_base;
4125
4126
3
  if (bfd_get_symcount (abfd) != 0)
4127
0
    {
4128
0
      int firstundef;
4129
4130
0
      if (!coff_renumber_symbols (abfd, &firstundef))
4131
0
  return false;
4132
0
      coff_mangle_symbols (abfd);
4133
0
      if (! coff_write_symbols (abfd))
4134
0
  return false;
4135
0
      if (! coff_write_linenumbers (abfd))
4136
0
  return false;
4137
0
      if (! coff_write_relocs (abfd, firstundef))
4138
0
  return false;
4139
0
    }
4140
#ifdef COFF_LONG_SECTION_NAMES
4141
  else if (long_section_names && ! obj_coff_strings_written (abfd))
4142
    {
4143
      /* If we have long section names we have to write out the string
4144
   table even if there are no symbols.  */
4145
      if (! coff_write_symbols (abfd))
4146
  return false;
4147
    }
4148
#endif
4149
  /* If bfd_get_symcount (abfd) != 0, then we are not using the COFF
4150
     backend linker, and obj_raw_syment_count is not valid until after
4151
     coff_write_symbols is called.  */
4152
3
  if (obj_raw_syment_count (abfd) != 0)
4153
0
    {
4154
0
      internal_f.f_symptr = sym_base;
4155
#ifdef RS6000COFF_C
4156
      /* AIX appears to require that F_RELFLG not be set if there are
4157
   local symbols but no relocations.  */
4158
      internal_f.f_flags &=~ F_RELFLG;
4159
#endif
4160
0
    }
4161
3
  else
4162
3
    {
4163
3
      if (long_section_names)
4164
0
  internal_f.f_symptr = sym_base;
4165
3
      else
4166
3
  internal_f.f_symptr = 0;
4167
3
      internal_f.f_flags |= F_LSYMS;
4168
3
    }
4169
4170
3
  if (text_sec)
4171
0
    {
4172
0
      internal_a.tsize = text_sec->size;
4173
0
      internal_a.text_start = internal_a.tsize ? text_sec->vma : 0;
4174
0
    }
4175
3
  if (data_sec)
4176
0
    {
4177
0
      internal_a.dsize = data_sec->size;
4178
0
      internal_a.data_start = internal_a.dsize ? data_sec->vma : 0;
4179
0
    }
4180
3
  if (bss_sec)
4181
0
    {
4182
0
      internal_a.bsize = bss_sec->size;
4183
0
      if (internal_a.bsize && bss_sec->vma < internal_a.data_start)
4184
0
  internal_a.data_start = bss_sec->vma;
4185
0
    }
4186
4187
3
  internal_a.entry = bfd_get_start_address (abfd);
4188
3
  internal_f.f_nsyms = obj_raw_syment_count (abfd);
4189
4190
#ifdef RS6000COFF_C
4191
  if (xcoff_data (abfd)->full_aouthdr)
4192
    {
4193
      bfd_vma toc;
4194
      asection *loader_sec;
4195
4196
      internal_a.vstamp = 2;
4197
4198
      internal_a.o_snentry = xcoff_data (abfd)->snentry;
4199
      if (internal_a.o_snentry == 0)
4200
  internal_a.entry = (bfd_vma) -1;
4201
4202
      if (text_sec != NULL)
4203
  {
4204
    internal_a.o_sntext = text_sec->target_index;
4205
    internal_a.o_algntext = bfd_section_alignment (text_sec);
4206
  }
4207
      else
4208
  {
4209
    internal_a.o_sntext = 0;
4210
    internal_a.o_algntext = 0;
4211
  }
4212
      if (data_sec != NULL)
4213
  {
4214
    internal_a.o_sndata = data_sec->target_index;
4215
    internal_a.o_algndata = bfd_section_alignment (data_sec);
4216
  }
4217
      else
4218
  {
4219
    internal_a.o_sndata = 0;
4220
    internal_a.o_algndata = 0;
4221
  }
4222
      loader_sec = bfd_get_section_by_name (abfd, ".loader");
4223
      if (loader_sec != NULL)
4224
  internal_a.o_snloader = loader_sec->target_index;
4225
      else
4226
  internal_a.o_snloader = 0;
4227
      if (bss_sec != NULL)
4228
  internal_a.o_snbss = bss_sec->target_index;
4229
      else
4230
  internal_a.o_snbss = 0;
4231
4232
      if (tdata_sec != NULL)
4233
  {
4234
    internal_a.o_sntdata = tdata_sec->target_index;
4235
    /* TODO: o_flags should be set to RS6K_AOUTHDR_TLS_LE
4236
       if there is at least one R_TLS_LE relocations.  */
4237
    internal_a.o_flags = 0;
4238
#ifdef XCOFF64
4239
    internal_a.o_x64flags = 0;
4240
#endif
4241
  }
4242
      else
4243
  {
4244
    internal_a.o_sntdata = 0;
4245
    internal_a.o_flags = 0;
4246
#ifdef XCOFF64
4247
    internal_a.o_x64flags = 0;
4248
#endif
4249
  }
4250
      if (tbss_sec != NULL)
4251
    internal_a.o_sntbss = tbss_sec->target_index;
4252
      else
4253
    internal_a.o_sntbss = 0;
4254
4255
      toc = xcoff_data (abfd)->toc;
4256
      internal_a.o_toc = toc;
4257
      internal_a.o_sntoc = xcoff_data (abfd)->sntoc;
4258
4259
      internal_a.o_modtype = xcoff_data (abfd)->modtype;
4260
      if (xcoff_data (abfd)->cputype != -1)
4261
  internal_a.o_cputype = xcoff_data (abfd)->cputype;
4262
      else
4263
  {
4264
    switch (bfd_get_arch (abfd))
4265
      {
4266
      case bfd_arch_rs6000:
4267
        internal_a.o_cputype = 4;
4268
        break;
4269
      case bfd_arch_powerpc:
4270
        if (bfd_get_mach (abfd) == bfd_mach_ppc)
4271
    internal_a.o_cputype = 3;
4272
        else if (bfd_get_mach (abfd) == bfd_mach_ppc_620)
4273
    internal_a.o_cputype = 2;
4274
        else
4275
    internal_a.o_cputype = 1;
4276
        break;
4277
      default:
4278
        abort ();
4279
      }
4280
  }
4281
      internal_a.o_maxstack = xcoff_data (abfd)->maxstack;
4282
      internal_a.o_maxdata = xcoff_data (abfd)->maxdata;
4283
    }
4284
#endif
4285
4286
#ifdef COFF_WITH_PE
4287
  {
4288
    /* After object contents are finalized so we can compute a reasonable hash,
4289
       but before header is written so we can update it to point to debug directory.  */
4290
    struct pe_tdata *pe = pe_data (abfd);
4291
4292
    if (pe->build_id.after_write_object_contents != NULL)
4293
      (*pe->build_id.after_write_object_contents) (abfd);
4294
  }
4295
#endif
4296
4297
  /* Now write header.  */
4298
3
  if (bfd_seek (abfd, 0, SEEK_SET) != 0)
4299
0
    return false;
4300
4301
3
  {
4302
3
    char * buff;
4303
3
    bfd_size_type amount = bfd_coff_filhsz (abfd);
4304
4305
3
    buff = (char *) bfd_malloc (amount);
4306
3
    if (buff == NULL)
4307
0
      return false;
4308
4309
3
    bfd_coff_swap_filehdr_out (abfd, & internal_f, buff);
4310
3
    amount = bfd_write (buff, amount, abfd);
4311
4312
3
    free (buff);
4313
4314
3
    if (amount != bfd_coff_filhsz (abfd))
4315
0
      return false;
4316
3
  }
4317
4318
3
  if (abfd->flags & EXEC_P)
4319
3
    {
4320
      /* Note that peicode.h fills in a PEAOUTHDR, not an AOUTHDR.
4321
   include/coff/pe.h sets AOUTSZ == sizeof (PEAOUTHDR)).  */
4322
3
      char * buff;
4323
3
      bfd_size_type amount = bfd_coff_aoutsz (abfd);
4324
4325
3
      buff = (char *) bfd_malloc (amount);
4326
3
      if (buff == NULL)
4327
0
  return false;
4328
4329
3
      coff_swap_aouthdr_out (abfd, & internal_a, buff);
4330
3
      amount = bfd_write (buff, amount, abfd);
4331
4332
3
      free (buff);
4333
4334
3
      if (amount != bfd_coff_aoutsz (abfd))
4335
0
  return false;
4336
4337
#ifdef COFF_IMAGE_WITH_PE
4338
      if (! coff_apply_checksum (abfd))
4339
  return false;
4340
#endif
4341
3
    }
4342
#ifdef RS6000COFF_C
4343
#ifndef XCOFF64
4344
  else
4345
    {
4346
      AOUTHDR buff;
4347
      size_t size;
4348
4349
      /* XCOFF32 seems to always write at least a small a.out header.  */
4350
      coff_swap_aouthdr_out (abfd, & internal_a, & buff);
4351
      if (xcoff_data (abfd)->full_aouthdr)
4352
  size = bfd_coff_aoutsz (abfd);
4353
      else
4354
  size = SMALL_AOUTSZ;
4355
      if (bfd_write (&buff, size, abfd) != size)
4356
  return false;
4357
    }
4358
#endif
4359
#endif
4360
4361
3
  return true;
4362
3
}
Unexecuted instantiation: pe-arm-wince.c:coff_write_object_contents
Unexecuted instantiation: pe-arm.c:coff_write_object_contents
pe-i386.c:coff_write_object_contents
Line
Count
Source
3486
3
{
3487
3
  asection *current;
3488
3
  bool hasrelocs = false;
3489
3
  bool haslinno = false;
3490
#ifdef COFF_IMAGE_WITH_PE
3491
  bool hasdebug = false;
3492
#endif
3493
3
  file_ptr scn_base;
3494
3
  file_ptr reloc_base;
3495
3
  file_ptr lineno_base;
3496
3
  file_ptr sym_base;
3497
3
  unsigned long reloc_size = 0, reloc_count = 0;
3498
3
  unsigned long lnno_size = 0;
3499
3
  bool long_section_names;
3500
3
  asection *text_sec = NULL;
3501
3
  asection *data_sec = NULL;
3502
3
  asection *bss_sec = NULL;
3503
#ifdef RS6000COFF_C
3504
  asection *tdata_sec = NULL;
3505
  asection *tbss_sec = NULL;
3506
#endif
3507
3
  struct internal_filehdr internal_f;
3508
3
  struct internal_aouthdr internal_a;
3509
3
#ifdef COFF_LONG_SECTION_NAMES
3510
3
  size_t string_size = STRING_SIZE_SIZE;
3511
3
#endif
3512
3513
3
  bfd_set_error (bfd_error_system_call);
3514
3515
  /* Make a pass through the symbol table to count line number entries and
3516
     put them into the correct asections.  */
3517
3
  lnno_size = coff_count_linenumbers (abfd) * bfd_coff_linesz (abfd);
3518
3519
3
  if (! abfd->output_has_begun)
3520
2
    {
3521
2
      if (! coff_compute_section_file_positions (abfd))
3522
0
  return false;
3523
2
    }
3524
3525
3
  reloc_base = obj_relocbase (abfd);
3526
3527
  /* Work out the size of the reloc and linno areas.  */
3528
3529
502
  for (current = abfd->sections; current != NULL; current =
3530
499
       current->next)
3531
499
    {
3532
499
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3533
      /* We store the actual reloc count in the first reloc's addr.  */
3534
499
      if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3535
0
  reloc_count ++;
3536
499
#endif
3537
499
      reloc_count += current->reloc_count;
3538
499
    }
3539
3540
3
  reloc_size = reloc_count * bfd_coff_relsz (abfd);
3541
3542
3
  lineno_base = reloc_base + reloc_size;
3543
3
  sym_base = lineno_base + lnno_size;
3544
3545
  /* Indicate in each section->line_filepos its actual file address.  */
3546
502
  for (current = abfd->sections; current != NULL; current =
3547
499
       current->next)
3548
499
    {
3549
499
      if (current->lineno_count)
3550
0
  {
3551
0
    current->line_filepos = lineno_base;
3552
0
    current->moving_line_filepos = lineno_base;
3553
0
    lineno_base += current->lineno_count * bfd_coff_linesz (abfd);
3554
0
  }
3555
499
      else
3556
499
  current->line_filepos = 0;
3557
3558
499
      if (current->reloc_count)
3559
0
  {
3560
0
    current->rel_filepos = reloc_base;
3561
0
    reloc_base += current->reloc_count * bfd_coff_relsz (abfd);
3562
0
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3563
    /* Extra reloc to hold real count.  */
3564
0
    if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3565
0
      reloc_base += bfd_coff_relsz (abfd);
3566
0
#endif
3567
0
  }
3568
499
      else
3569
499
  current->rel_filepos = 0;
3570
499
    }
3571
3572
  /* Write section headers to the file.  */
3573
3
  internal_f.f_nscns = 0;
3574
3575
3
  if ((abfd->flags & EXEC_P) != 0)
3576
0
    scn_base = bfd_coff_filhsz (abfd) + bfd_coff_aoutsz (abfd);
3577
3
  else
3578
3
    {
3579
3
      scn_base = bfd_coff_filhsz (abfd);
3580
#ifdef RS6000COFF_C
3581
#ifndef XCOFF64
3582
      if (xcoff_data (abfd)->full_aouthdr)
3583
  scn_base += bfd_coff_aoutsz (abfd);
3584
      else
3585
  scn_base += SMALL_AOUTSZ;
3586
#endif
3587
#endif
3588
3
    }
3589
3590
3
  if (bfd_seek (abfd, scn_base, SEEK_SET) != 0)
3591
0
    return false;
3592
3593
3
  long_section_names = false;
3594
3
  for (current = abfd->sections;
3595
502
       current != NULL;
3596
499
       current = current->next)
3597
499
    {
3598
499
      struct internal_scnhdr section;
3599
#ifdef COFF_IMAGE_WITH_PE
3600
      bool is_reloc_section = false;
3601
3602
      if (strcmp (current->name, DOT_RELOC) == 0)
3603
  {
3604
    is_reloc_section = true;
3605
    hasrelocs = true;
3606
    pe_data (abfd)->has_reloc_section = 1;
3607
  }
3608
#endif
3609
3610
499
      internal_f.f_nscns++;
3611
3612
499
      strncpy (section.s_name, current->name, SCNNMLEN);
3613
3614
499
#ifdef COFF_LONG_SECTION_NAMES
3615
      /* Handle long section names as in PE.  This must be compatible
3616
   with the code in coff_write_symbols and _bfd_coff_final_link.  */
3617
499
      if (bfd_coff_long_section_names (abfd))
3618
499
  {
3619
499
    size_t len;
3620
3621
499
    len = strlen (current->name);
3622
499
    if (len > SCNNMLEN)
3623
0
      {
3624
3625
        /* An inherent limitation of the /nnnnnnn notation used to indicate
3626
     the offset of the long name in the string table is that we
3627
     cannot address entries beyone the ten million byte boundary.  */
3628
0
        if (string_size < 10000000)
3629
0
    {
3630
      /* The s_name field is defined to be NUL-padded but need not
3631
         be NUL-terminated.  We use a temporary buffer so that we
3632
         can still sprintf all eight chars without splatting a
3633
         terminating NUL over the first byte of the following
3634
         member (s_paddr).  */
3635
      /* PR 21096: The +20 is to stop a bogus warning from gcc7
3636
         about a possible buffer overflow.  */
3637
0
      char s_name_buf[SCNNMLEN + 1 + 20];
3638
3639
      /* We do not need to use snprintf here as we have already
3640
         verified that string_size is not too big, plus we have
3641
         an overlarge buffer, just in case.  */
3642
0
      sprintf (s_name_buf, "/%lu", (unsigned long) string_size);
3643
      /* Then strncpy takes care of any padding for us.  */
3644
0
      strncpy (section.s_name, s_name_buf, SCNNMLEN);
3645
0
    }
3646
0
        else
3647
0
#ifdef COFF_WITH_PE
3648
0
    {
3649
      /* PE use a base 64 encoding for long section names whose
3650
         index is very large.  But contrary to RFC 4648, there is
3651
         no padding: 6 characters must be generated.  */
3652
0
      static const char base64[] =
3653
0
        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
3654
0
        "abcdefghijklmnopqrstuvwxyz"
3655
0
        "0123456789+/";
3656
0
      unsigned long off = string_size;
3657
0
      unsigned i;
3658
3659
0
      section.s_name[0] = '/';
3660
0
      section.s_name[1] = '/';
3661
0
      for (i = SCNNMLEN - 1; i >= 2; i--)
3662
0
        {
3663
0
          section.s_name[i] = base64[off & 0x3f];
3664
0
          off >>= 6;
3665
0
        }
3666
0
    }
3667
0
#endif
3668
0
        if (string_size > 0xffffffffUL - (len + 1)
3669
#ifndef COFF_WITH_PE
3670
      || string_size >= 10000000
3671
#endif
3672
0
      )
3673
0
    {
3674
0
      bfd_set_error (bfd_error_file_too_big);
3675
0
      _bfd_error_handler
3676
        /* xgettext:c-format */
3677
0
        (_("%pB: section %pA: string table overflow at offset %ld"),
3678
0
        abfd, current, (unsigned long) string_size);
3679
0
      return false;
3680
0
    }
3681
3682
0
        string_size += len + 1;
3683
0
        long_section_names = true;
3684
0
      }
3685
499
  }
3686
499
#endif
3687
3688
499
#ifdef _LIB
3689
      /* Always set s_vaddr of .lib to 0.  This is right for SVR3.2
3690
   Ian Taylor <ian@cygnus.com>.  */
3691
499
      if (strcmp (current->name, _LIB) == 0)
3692
0
  section.s_vaddr = 0;
3693
499
      else
3694
499
#endif
3695
499
      section.s_vaddr = current->vma;
3696
499
      section.s_paddr = current->lma;
3697
499
      section.s_size =  current->size;
3698
#ifdef coff_get_section_load_page
3699
      section.s_page = coff_get_section_load_page (current);
3700
#else
3701
499
      section.s_page = 0;
3702
499
#endif
3703
3704
499
#ifdef COFF_WITH_PE
3705
499
      section.s_paddr = 0;
3706
499
#endif
3707
#ifdef COFF_IMAGE_WITH_PE
3708
      /* Reminder: s_paddr holds the virtual size of the section.  */
3709
      if (coff_section_data (abfd, current) != NULL
3710
    && pei_section_data (abfd, current) != NULL)
3711
  section.s_paddr = pei_section_data (abfd, current)->virt_size;
3712
      else
3713
  section.s_paddr = 0;
3714
#endif
3715
3716
      /* If this section has no size or is unloadable then the scnptr
3717
   will be 0 too.  */
3718
499
      if (current->size == 0
3719
499
    || (current->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
3720
497
  section.s_scnptr = 0;
3721
2
      else
3722
2
  section.s_scnptr = current->filepos;
3723
3724
499
      section.s_relptr = current->rel_filepos;
3725
499
      section.s_lnnoptr = current->line_filepos;
3726
499
      section.s_nreloc = current->reloc_count;
3727
499
      section.s_nlnno = current->lineno_count;
3728
499
#ifndef COFF_IMAGE_WITH_PE
3729
      /* In PEI, relocs come in the .reloc section.  */
3730
499
      if (current->reloc_count != 0)
3731
0
  hasrelocs = true;
3732
499
#endif
3733
499
      if (current->lineno_count != 0)
3734
0
  haslinno = true;
3735
#ifdef COFF_IMAGE_WITH_PE
3736
      if ((current->flags & SEC_DEBUGGING) != 0
3737
    && ! is_reloc_section)
3738
  hasdebug = true;
3739
#endif
3740
3741
#ifdef RS6000COFF_C
3742
#ifndef XCOFF64
3743
      /* Indicate the use of an XCOFF overflow section header.  */
3744
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3745
  {
3746
    section.s_nreloc = 0xffff;
3747
    section.s_nlnno = 0xffff;
3748
  }
3749
#endif
3750
#endif
3751
3752
499
      section.s_flags = sec_to_styp_flags (current->name, current->flags);
3753
3754
499
      if (!strcmp (current->name, _TEXT))
3755
0
  text_sec = current;
3756
499
      else if (!strcmp (current->name, _DATA))
3757
0
  data_sec = current;
3758
499
      else if (!strcmp (current->name, _BSS))
3759
0
  bss_sec = current;
3760
#ifdef RS6000COFF_C
3761
      else if (!strcmp (current->name, _TDATA))
3762
  tdata_sec = current;
3763
      else if (!strcmp (current->name, _TBSS))
3764
  tbss_sec = current;
3765
#endif
3766
3767
3768
499
#ifdef COFF_ENCODE_ALIGNMENT
3769
499
      if (COFF_ENCODE_ALIGNMENT (abfd, section, current->alignment_power)
3770
499
    && (COFF_DECODE_ALIGNMENT (section.s_flags)
3771
499
        != current->alignment_power))
3772
0
  {
3773
0
    bool warn = (coff_data (abfd)->link_info
3774
0
           && !bfd_link_relocatable (coff_data (abfd)->link_info));
3775
3776
0
    _bfd_error_handler
3777
      /* xgettext:c-format */
3778
0
      (_("%pB:%s section %s: alignment 2**%u not representable"),
3779
0
       abfd, warn ? " warning:" : "", current->name,
3780
0
       current->alignment_power);
3781
0
    if (!warn)
3782
0
      {
3783
0
        bfd_set_error (bfd_error_nonrepresentable_section);
3784
0
        return false;
3785
0
      }
3786
0
  }
3787
499
#endif
3788
3789
#ifdef COFF_IMAGE_WITH_PE
3790
      /* Suppress output of the sections if they are null.  ld
3791
   includes the bss and data sections even if there is no size
3792
   assigned to them.  NT loader doesn't like it if these section
3793
   headers are included if the sections themselves are not
3794
   needed.  See also coff_compute_section_file_positions.  */
3795
      if (section.s_size == 0)
3796
  internal_f.f_nscns--;
3797
      else
3798
#endif
3799
499
  {
3800
499
    SCNHDR buff;
3801
499
    bfd_size_type amt = bfd_coff_scnhsz (abfd);
3802
3803
499
    if (bfd_coff_swap_scnhdr_out (abfd, &section, &buff) == 0
3804
499
        || bfd_write (& buff, amt, abfd) != amt)
3805
0
      return false;
3806
499
  }
3807
3808
499
#ifdef COFF_WITH_PE
3809
      /* PE stores COMDAT section information in the symbol table.  If
3810
   this section is supposed to have some COMDAT info, track down
3811
   the symbol in the symbol table and modify it.  */
3812
499
      if ((current->flags & SEC_LINK_ONCE) != 0)
3813
1
  {
3814
1
    unsigned int i, count;
3815
1
    asymbol **psym;
3816
1
    coff_symbol_type *csym = NULL;
3817
1
    asymbol **psymsec;
3818
3819
1
    psymsec = NULL;
3820
1
    count = bfd_get_symcount (abfd);
3821
160
    for (i = 0, psym = abfd->outsymbols; i < count; i++, psym++)
3822
159
      {
3823
159
        if ((*psym)->section != current)
3824
159
    continue;
3825
3826
        /* Remember the location of the first symbol in this
3827
     section.  */
3828
0
        if (psymsec == NULL)
3829
0
    psymsec = psym;
3830
3831
        /* See if this is the section symbol.  */
3832
0
        if (strcmp ((*psym)->name, current->name) == 0)
3833
0
    {
3834
0
      csym = coff_symbol_from (*psym);
3835
0
      if (csym == NULL
3836
0
          || csym->native == NULL
3837
0
          || ! csym->native->is_sym
3838
0
          || csym->native->u.syment.n_numaux < 1
3839
0
          || csym->native->u.syment.n_sclass != C_STAT
3840
0
          || csym->native->u.syment.n_type != T_NULL)
3841
0
        continue;
3842
3843
      /* Here *PSYM is the section symbol for CURRENT.  */
3844
3845
0
      break;
3846
0
    }
3847
0
      }
3848
3849
    /* Did we find it?
3850
       Note that we might not if we're converting the file from
3851
       some other object file format.  */
3852
1
    if (i < count)
3853
0
      {
3854
0
        combined_entry_type *aux;
3855
3856
        /* We don't touch the x_checksum field.  The
3857
     x_associated field is not currently supported.  */
3858
3859
0
        aux = csym->native + 1;
3860
0
        BFD_ASSERT (! aux->is_sym);
3861
0
        switch (current->flags & SEC_LINK_DUPLICATES)
3862
0
    {
3863
0
    case SEC_LINK_DUPLICATES_DISCARD:
3864
0
      aux->u.auxent.x_scn.x_comdat = IMAGE_COMDAT_SELECT_ANY;
3865
0
      break;
3866
3867
0
    case SEC_LINK_DUPLICATES_ONE_ONLY:
3868
0
      aux->u.auxent.x_scn.x_comdat =
3869
0
        IMAGE_COMDAT_SELECT_NODUPLICATES;
3870
0
      break;
3871
3872
0
    case SEC_LINK_DUPLICATES_SAME_SIZE:
3873
0
      aux->u.auxent.x_scn.x_comdat =
3874
0
        IMAGE_COMDAT_SELECT_SAME_SIZE;
3875
0
      break;
3876
3877
0
    case SEC_LINK_DUPLICATES_SAME_CONTENTS:
3878
0
      aux->u.auxent.x_scn.x_comdat =
3879
0
        IMAGE_COMDAT_SELECT_EXACT_MATCH;
3880
0
      break;
3881
0
    }
3882
3883
        /* The COMDAT symbol must be the first symbol from this
3884
     section in the symbol table.  In order to make this
3885
     work, we move the COMDAT symbol before the first
3886
     symbol we found in the search above.  It's OK to
3887
     rearrange the symbol table at this point, because
3888
     coff_renumber_symbols is going to rearrange it
3889
     further and fix up all the aux entries.  */
3890
0
        if (psym != psymsec)
3891
0
    {
3892
0
      asymbol *hold;
3893
0
      asymbol **pcopy;
3894
3895
0
      hold = *psym;
3896
0
      for (pcopy = psym; pcopy > psymsec; pcopy--)
3897
0
        pcopy[0] = pcopy[-1];
3898
0
      *psymsec = hold;
3899
0
    }
3900
0
      }
3901
1
  }
3902
499
#endif /* COFF_WITH_PE */
3903
499
    }
3904
3905
#ifdef RS6000COFF_C
3906
#ifndef XCOFF64
3907
  /* XCOFF handles overflows in the reloc and line number count fields
3908
     by creating a new section header to hold the correct values.  */
3909
  for (current = abfd->sections; current != NULL; current = current->next)
3910
    {
3911
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3912
  {
3913
    struct internal_scnhdr scnhdr;
3914
    SCNHDR buff;
3915
    bfd_size_type amt;
3916
3917
    internal_f.f_nscns++;
3918
    memcpy (scnhdr.s_name, ".ovrflo", 8);
3919
    scnhdr.s_paddr = current->reloc_count;
3920
    scnhdr.s_vaddr = current->lineno_count;
3921
    scnhdr.s_size = 0;
3922
    scnhdr.s_scnptr = 0;
3923
    scnhdr.s_relptr = current->rel_filepos;
3924
    scnhdr.s_lnnoptr = current->line_filepos;
3925
    scnhdr.s_nreloc = current->target_index;
3926
    scnhdr.s_nlnno = current->target_index;
3927
    scnhdr.s_flags = STYP_OVRFLO;
3928
    amt = bfd_coff_scnhsz (abfd);
3929
    if (bfd_coff_swap_scnhdr_out (abfd, &scnhdr, &buff) == 0
3930
        || bfd_write (& buff, amt, abfd) != amt)
3931
      return false;
3932
  }
3933
    }
3934
#endif
3935
#endif
3936
3937
#if defined (COFF_GO32_EXE) || defined (COFF_GO32)
3938
  /* Pad section headers.  */
3939
  if ((abfd->flags & EXEC_P) != 0)
3940
    {
3941
      asection *s = abfd->sections;
3942
      while (s != NULL && s->filepos == 0)
3943
  s = s->next;
3944
      if (s != NULL)
3945
  {
3946
    file_ptr cur_ptr
3947
      = scn_base + abfd->section_count * bfd_coff_scnhsz (abfd);
3948
    file_ptr fill_size = s->filepos - cur_ptr;
3949
    if (fill_size > 0)
3950
      {
3951
        bfd_byte *b = bfd_zmalloc (fill_size);
3952
        if (!b)
3953
    return false;
3954
        if (bfd_write (b, fill_size, abfd) != (ufile_ptr) fill_size)
3955
    {
3956
      free (b);
3957
      return false;
3958
    }
3959
        free (b);
3960
      }
3961
  }
3962
    }
3963
#endif
3964
3965
  /* OK, now set up the filehdr...  */
3966
3967
  /* Don't include the internal abs section in the section count */
3968
3969
  /* We will NOT put a fucking timestamp in the header here. Every time you
3970
     put it back, I will come in and take it out again.  I'm sorry.  This
3971
     field does not belong here.  We fill it with a 0 so it compares the
3972
     same but is not a reasonable time. -- gnu@cygnus.com  */
3973
3
  internal_f.f_timdat = 0;
3974
3
  internal_f.f_flags = 0;
3975
3976
3
  if (abfd->flags & EXEC_P)
3977
0
    internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3978
3
  else
3979
3
    {
3980
3
      internal_f.f_opthdr = 0;
3981
#ifdef RS6000COFF_C
3982
#ifndef XCOFF64
3983
      if (xcoff_data (abfd)->full_aouthdr)
3984
  internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3985
      else
3986
  internal_f.f_opthdr = SMALL_AOUTSZ;
3987
#endif
3988
#endif
3989
3
    }
3990
3991
3
  if (!hasrelocs)
3992
3
    internal_f.f_flags |= F_RELFLG;
3993
3
  if (!haslinno)
3994
3
    internal_f.f_flags |= F_LNNO;
3995
3
  if (abfd->flags & EXEC_P)
3996
0
    internal_f.f_flags |= F_EXEC;
3997
#ifdef COFF_IMAGE_WITH_PE
3998
  if (! hasdebug)
3999
    internal_f.f_flags |= IMAGE_FILE_DEBUG_STRIPPED;
4000
  if (pe_data (abfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
4001
    internal_f.f_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
4002
#endif
4003
4004
3
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
4005
3
#ifdef COFF_WITH_PE
4006
3
  internal_f.f_flags |= IMAGE_FILE_32BIT_MACHINE;
4007
#else
4008
  if (bfd_little_endian (abfd))
4009
    internal_f.f_flags |= F_AR32WR;
4010
  else
4011
    internal_f.f_flags |= F_AR32W;
4012
#endif
4013
3
#endif
4014
4015
#ifdef TI_TARGET_ID
4016
  /* Target id is used in TI COFF v1 and later; COFF0 won't use this field,
4017
     but it doesn't hurt to set it internally.  */
4018
  internal_f.f_target_id = TI_TARGET_ID;
4019
#endif
4020
4021
  /* FIXME, should do something about the other byte orders and
4022
     architectures.  */
4023
4024
#ifdef RS6000COFF_C
4025
  if ((abfd->flags & DYNAMIC) != 0)
4026
    internal_f.f_flags |= F_SHROBJ;
4027
  if (bfd_get_section_by_name (abfd, _LOADER) != NULL)
4028
    internal_f.f_flags |= F_DYNLOAD;
4029
#endif
4030
4031
3
  memset (&internal_a, 0, sizeof internal_a);
4032
4033
  /* Set up architecture-dependent stuff.  */
4034
3
  {
4035
3
    unsigned int magic = 0;
4036
3
    unsigned short flags = 0;
4037
4038
3
    coff_set_flags (abfd, &magic, &flags);
4039
3
    internal_f.f_magic = magic;
4040
3
    internal_f.f_flags |= flags;
4041
    /* ...and the "opt"hdr...  */
4042
4043
#ifdef TICOFF_AOUT_MAGIC
4044
    internal_a.magic = TICOFF_AOUT_MAGIC;
4045
#define __A_MAGIC_SET__
4046
#endif
4047
4048
#if defined(ARM)
4049
#define __A_MAGIC_SET__
4050
    internal_a.magic = ZMAGIC;
4051
#endif
4052
4053
#if defined(AARCH64)
4054
#define __A_MAGIC_SET__
4055
    internal_a.magic = ZMAGIC;
4056
#endif
4057
4058
#if defined(LOONGARCH64)
4059
#define __A_MAGIC_SET__
4060
    internal_a.magic = ZMAGIC;
4061
#endif
4062
4063
#if defined MCORE_PE
4064
#define __A_MAGIC_SET__
4065
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR_MAGIC;
4066
#endif
4067
4068
3
#if defined(I386)
4069
3
#define __A_MAGIC_SET__
4070
#if defined LYNXOS
4071
    internal_a.magic = LYNXCOFFMAGIC;
4072
#elif defined AMD64
4073
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR64_MAGIC;
4074
#else
4075
3
    internal_a.magic = ZMAGIC;
4076
3
#endif
4077
3
#endif /* I386 */
4078
4079
#if defined(IA64)
4080
#define __A_MAGIC_SET__
4081
    internal_a.magic = PE32PMAGIC;
4082
#endif /* IA64 */
4083
4084
#if defined(SPARC)
4085
#define __A_MAGIC_SET__
4086
#if defined(LYNXOS)
4087
    internal_a.magic = LYNXCOFFMAGIC;
4088
#endif /* LYNXOS */
4089
#endif /* SPARC */
4090
4091
#ifdef RS6000COFF_C
4092
#define __A_MAGIC_SET__
4093
    internal_a.magic = (abfd->flags & D_PAGED) ? RS6K_AOUTHDR_ZMAGIC :
4094
    (abfd->flags & WP_TEXT) ? RS6K_AOUTHDR_NMAGIC :
4095
    RS6K_AOUTHDR_OMAGIC;
4096
#endif
4097
4098
#if defined(SH) && defined(COFF_WITH_PE)
4099
#define __A_MAGIC_SET__
4100
    internal_a.magic = SH_PE_MAGIC;
4101
#endif
4102
4103
#if defined(MIPS) && defined(COFF_WITH_PE)
4104
#define __A_MAGIC_SET__
4105
    internal_a.magic = MIPS_PE_MAGIC;
4106
#endif
4107
4108
#ifndef __A_MAGIC_SET__
4109
#include "Your aouthdr magic number is not being set!"
4110
#else
4111
3
#undef __A_MAGIC_SET__
4112
3
#endif
4113
3
  }
4114
4115
#ifdef RS6000COFF_C
4116
  /* XCOFF 32bit needs this to have new behaviour for n_type field.  */
4117
  internal_a.vstamp = 2;
4118
#else
4119
  /* FIXME: Does anybody ever set this to another value?  */
4120
3
  internal_a.vstamp = 0;
4121
3
#endif
4122
4123
  /* Now should write relocs, strings, syms.  */
4124
3
  obj_sym_filepos (abfd) = sym_base;
4125
4126
3
  if (bfd_get_symcount (abfd) != 0)
4127
1
    {
4128
1
      int firstundef;
4129
4130
1
      if (!coff_renumber_symbols (abfd, &firstundef))
4131
0
  return false;
4132
1
      coff_mangle_symbols (abfd);
4133
1
      if (! coff_write_symbols (abfd))
4134
0
  return false;
4135
1
      if (! coff_write_linenumbers (abfd))
4136
0
  return false;
4137
1
      if (! coff_write_relocs (abfd, firstundef))
4138
0
  return false;
4139
1
    }
4140
2
#ifdef COFF_LONG_SECTION_NAMES
4141
2
  else if (long_section_names && ! obj_coff_strings_written (abfd))
4142
0
    {
4143
      /* If we have long section names we have to write out the string
4144
   table even if there are no symbols.  */
4145
0
      if (! coff_write_symbols (abfd))
4146
0
  return false;
4147
0
    }
4148
3
#endif
4149
  /* If bfd_get_symcount (abfd) != 0, then we are not using the COFF
4150
     backend linker, and obj_raw_syment_count is not valid until after
4151
     coff_write_symbols is called.  */
4152
3
  if (obj_raw_syment_count (abfd) != 0)
4153
1
    {
4154
1
      internal_f.f_symptr = sym_base;
4155
#ifdef RS6000COFF_C
4156
      /* AIX appears to require that F_RELFLG not be set if there are
4157
   local symbols but no relocations.  */
4158
      internal_f.f_flags &=~ F_RELFLG;
4159
#endif
4160
1
    }
4161
2
  else
4162
2
    {
4163
2
      if (long_section_names)
4164
0
  internal_f.f_symptr = sym_base;
4165
2
      else
4166
2
  internal_f.f_symptr = 0;
4167
2
      internal_f.f_flags |= F_LSYMS;
4168
2
    }
4169
4170
3
  if (text_sec)
4171
0
    {
4172
0
      internal_a.tsize = text_sec->size;
4173
0
      internal_a.text_start = internal_a.tsize ? text_sec->vma : 0;
4174
0
    }
4175
3
  if (data_sec)
4176
0
    {
4177
0
      internal_a.dsize = data_sec->size;
4178
0
      internal_a.data_start = internal_a.dsize ? data_sec->vma : 0;
4179
0
    }
4180
3
  if (bss_sec)
4181
0
    {
4182
0
      internal_a.bsize = bss_sec->size;
4183
0
      if (internal_a.bsize && bss_sec->vma < internal_a.data_start)
4184
0
  internal_a.data_start = bss_sec->vma;
4185
0
    }
4186
4187
3
  internal_a.entry = bfd_get_start_address (abfd);
4188
3
  internal_f.f_nsyms = obj_raw_syment_count (abfd);
4189
4190
#ifdef RS6000COFF_C
4191
  if (xcoff_data (abfd)->full_aouthdr)
4192
    {
4193
      bfd_vma toc;
4194
      asection *loader_sec;
4195
4196
      internal_a.vstamp = 2;
4197
4198
      internal_a.o_snentry = xcoff_data (abfd)->snentry;
4199
      if (internal_a.o_snentry == 0)
4200
  internal_a.entry = (bfd_vma) -1;
4201
4202
      if (text_sec != NULL)
4203
  {
4204
    internal_a.o_sntext = text_sec->target_index;
4205
    internal_a.o_algntext = bfd_section_alignment (text_sec);
4206
  }
4207
      else
4208
  {
4209
    internal_a.o_sntext = 0;
4210
    internal_a.o_algntext = 0;
4211
  }
4212
      if (data_sec != NULL)
4213
  {
4214
    internal_a.o_sndata = data_sec->target_index;
4215
    internal_a.o_algndata = bfd_section_alignment (data_sec);
4216
  }
4217
      else
4218
  {
4219
    internal_a.o_sndata = 0;
4220
    internal_a.o_algndata = 0;
4221
  }
4222
      loader_sec = bfd_get_section_by_name (abfd, ".loader");
4223
      if (loader_sec != NULL)
4224
  internal_a.o_snloader = loader_sec->target_index;
4225
      else
4226
  internal_a.o_snloader = 0;
4227
      if (bss_sec != NULL)
4228
  internal_a.o_snbss = bss_sec->target_index;
4229
      else
4230
  internal_a.o_snbss = 0;
4231
4232
      if (tdata_sec != NULL)
4233
  {
4234
    internal_a.o_sntdata = tdata_sec->target_index;
4235
    /* TODO: o_flags should be set to RS6K_AOUTHDR_TLS_LE
4236
       if there is at least one R_TLS_LE relocations.  */
4237
    internal_a.o_flags = 0;
4238
#ifdef XCOFF64
4239
    internal_a.o_x64flags = 0;
4240
#endif
4241
  }
4242
      else
4243
  {
4244
    internal_a.o_sntdata = 0;
4245
    internal_a.o_flags = 0;
4246
#ifdef XCOFF64
4247
    internal_a.o_x64flags = 0;
4248
#endif
4249
  }
4250
      if (tbss_sec != NULL)
4251
    internal_a.o_sntbss = tbss_sec->target_index;
4252
      else
4253
    internal_a.o_sntbss = 0;
4254
4255
      toc = xcoff_data (abfd)->toc;
4256
      internal_a.o_toc = toc;
4257
      internal_a.o_sntoc = xcoff_data (abfd)->sntoc;
4258
4259
      internal_a.o_modtype = xcoff_data (abfd)->modtype;
4260
      if (xcoff_data (abfd)->cputype != -1)
4261
  internal_a.o_cputype = xcoff_data (abfd)->cputype;
4262
      else
4263
  {
4264
    switch (bfd_get_arch (abfd))
4265
      {
4266
      case bfd_arch_rs6000:
4267
        internal_a.o_cputype = 4;
4268
        break;
4269
      case bfd_arch_powerpc:
4270
        if (bfd_get_mach (abfd) == bfd_mach_ppc)
4271
    internal_a.o_cputype = 3;
4272
        else if (bfd_get_mach (abfd) == bfd_mach_ppc_620)
4273
    internal_a.o_cputype = 2;
4274
        else
4275
    internal_a.o_cputype = 1;
4276
        break;
4277
      default:
4278
        abort ();
4279
      }
4280
  }
4281
      internal_a.o_maxstack = xcoff_data (abfd)->maxstack;
4282
      internal_a.o_maxdata = xcoff_data (abfd)->maxdata;
4283
    }
4284
#endif
4285
4286
3
#ifdef COFF_WITH_PE
4287
3
  {
4288
    /* After object contents are finalized so we can compute a reasonable hash,
4289
       but before header is written so we can update it to point to debug directory.  */
4290
3
    struct pe_tdata *pe = pe_data (abfd);
4291
4292
3
    if (pe->build_id.after_write_object_contents != NULL)
4293
0
      (*pe->build_id.after_write_object_contents) (abfd);
4294
3
  }
4295
3
#endif
4296
4297
  /* Now write header.  */
4298
3
  if (bfd_seek (abfd, 0, SEEK_SET) != 0)
4299
0
    return false;
4300
4301
3
  {
4302
3
    char * buff;
4303
3
    bfd_size_type amount = bfd_coff_filhsz (abfd);
4304
4305
3
    buff = (char *) bfd_malloc (amount);
4306
3
    if (buff == NULL)
4307
0
      return false;
4308
4309
3
    bfd_coff_swap_filehdr_out (abfd, & internal_f, buff);
4310
3
    amount = bfd_write (buff, amount, abfd);
4311
4312
3
    free (buff);
4313
4314
3
    if (amount != bfd_coff_filhsz (abfd))
4315
0
      return false;
4316
3
  }
4317
4318
3
  if (abfd->flags & EXEC_P)
4319
0
    {
4320
      /* Note that peicode.h fills in a PEAOUTHDR, not an AOUTHDR.
4321
   include/coff/pe.h sets AOUTSZ == sizeof (PEAOUTHDR)).  */
4322
0
      char * buff;
4323
0
      bfd_size_type amount = bfd_coff_aoutsz (abfd);
4324
4325
0
      buff = (char *) bfd_malloc (amount);
4326
0
      if (buff == NULL)
4327
0
  return false;
4328
4329
0
      coff_swap_aouthdr_out (abfd, & internal_a, buff);
4330
0
      amount = bfd_write (buff, amount, abfd);
4331
4332
0
      free (buff);
4333
4334
0
      if (amount != bfd_coff_aoutsz (abfd))
4335
0
  return false;
4336
4337
#ifdef COFF_IMAGE_WITH_PE
4338
      if (! coff_apply_checksum (abfd))
4339
  return false;
4340
#endif
4341
0
    }
4342
#ifdef RS6000COFF_C
4343
#ifndef XCOFF64
4344
  else
4345
    {
4346
      AOUTHDR buff;
4347
      size_t size;
4348
4349
      /* XCOFF32 seems to always write at least a small a.out header.  */
4350
      coff_swap_aouthdr_out (abfd, & internal_a, & buff);
4351
      if (xcoff_data (abfd)->full_aouthdr)
4352
  size = bfd_coff_aoutsz (abfd);
4353
      else
4354
  size = SMALL_AOUTSZ;
4355
      if (bfd_write (&buff, size, abfd) != size)
4356
  return false;
4357
    }
4358
#endif
4359
#endif
4360
4361
3
  return true;
4362
3
}
pe-mcore.c:coff_write_object_contents
Line
Count
Source
3486
2
{
3487
2
  asection *current;
3488
2
  bool hasrelocs = false;
3489
2
  bool haslinno = false;
3490
#ifdef COFF_IMAGE_WITH_PE
3491
  bool hasdebug = false;
3492
#endif
3493
2
  file_ptr scn_base;
3494
2
  file_ptr reloc_base;
3495
2
  file_ptr lineno_base;
3496
2
  file_ptr sym_base;
3497
2
  unsigned long reloc_size = 0, reloc_count = 0;
3498
2
  unsigned long lnno_size = 0;
3499
2
  bool long_section_names;
3500
2
  asection *text_sec = NULL;
3501
2
  asection *data_sec = NULL;
3502
2
  asection *bss_sec = NULL;
3503
#ifdef RS6000COFF_C
3504
  asection *tdata_sec = NULL;
3505
  asection *tbss_sec = NULL;
3506
#endif
3507
2
  struct internal_filehdr internal_f;
3508
2
  struct internal_aouthdr internal_a;
3509
2
#ifdef COFF_LONG_SECTION_NAMES
3510
2
  size_t string_size = STRING_SIZE_SIZE;
3511
2
#endif
3512
3513
2
  bfd_set_error (bfd_error_system_call);
3514
3515
  /* Make a pass through the symbol table to count line number entries and
3516
     put them into the correct asections.  */
3517
2
  lnno_size = coff_count_linenumbers (abfd) * bfd_coff_linesz (abfd);
3518
3519
2
  if (! abfd->output_has_begun)
3520
2
    {
3521
2
      if (! coff_compute_section_file_positions (abfd))
3522
0
  return false;
3523
2
    }
3524
3525
2
  reloc_base = obj_relocbase (abfd);
3526
3527
  /* Work out the size of the reloc and linno areas.  */
3528
3529
9
  for (current = abfd->sections; current != NULL; current =
3530
7
       current->next)
3531
7
    {
3532
7
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3533
      /* We store the actual reloc count in the first reloc's addr.  */
3534
7
      if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3535
0
  reloc_count ++;
3536
7
#endif
3537
7
      reloc_count += current->reloc_count;
3538
7
    }
3539
3540
2
  reloc_size = reloc_count * bfd_coff_relsz (abfd);
3541
3542
2
  lineno_base = reloc_base + reloc_size;
3543
2
  sym_base = lineno_base + lnno_size;
3544
3545
  /* Indicate in each section->line_filepos its actual file address.  */
3546
9
  for (current = abfd->sections; current != NULL; current =
3547
7
       current->next)
3548
7
    {
3549
7
      if (current->lineno_count)
3550
0
  {
3551
0
    current->line_filepos = lineno_base;
3552
0
    current->moving_line_filepos = lineno_base;
3553
0
    lineno_base += current->lineno_count * bfd_coff_linesz (abfd);
3554
0
  }
3555
7
      else
3556
7
  current->line_filepos = 0;
3557
3558
7
      if (current->reloc_count)
3559
0
  {
3560
0
    current->rel_filepos = reloc_base;
3561
0
    reloc_base += current->reloc_count * bfd_coff_relsz (abfd);
3562
0
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3563
    /* Extra reloc to hold real count.  */
3564
0
    if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3565
0
      reloc_base += bfd_coff_relsz (abfd);
3566
0
#endif
3567
0
  }
3568
7
      else
3569
7
  current->rel_filepos = 0;
3570
7
    }
3571
3572
  /* Write section headers to the file.  */
3573
2
  internal_f.f_nscns = 0;
3574
3575
2
  if ((abfd->flags & EXEC_P) != 0)
3576
1
    scn_base = bfd_coff_filhsz (abfd) + bfd_coff_aoutsz (abfd);
3577
1
  else
3578
1
    {
3579
1
      scn_base = bfd_coff_filhsz (abfd);
3580
#ifdef RS6000COFF_C
3581
#ifndef XCOFF64
3582
      if (xcoff_data (abfd)->full_aouthdr)
3583
  scn_base += bfd_coff_aoutsz (abfd);
3584
      else
3585
  scn_base += SMALL_AOUTSZ;
3586
#endif
3587
#endif
3588
1
    }
3589
3590
2
  if (bfd_seek (abfd, scn_base, SEEK_SET) != 0)
3591
0
    return false;
3592
3593
2
  long_section_names = false;
3594
2
  for (current = abfd->sections;
3595
9
       current != NULL;
3596
7
       current = current->next)
3597
7
    {
3598
7
      struct internal_scnhdr section;
3599
#ifdef COFF_IMAGE_WITH_PE
3600
      bool is_reloc_section = false;
3601
3602
      if (strcmp (current->name, DOT_RELOC) == 0)
3603
  {
3604
    is_reloc_section = true;
3605
    hasrelocs = true;
3606
    pe_data (abfd)->has_reloc_section = 1;
3607
  }
3608
#endif
3609
3610
7
      internal_f.f_nscns++;
3611
3612
7
      strncpy (section.s_name, current->name, SCNNMLEN);
3613
3614
7
#ifdef COFF_LONG_SECTION_NAMES
3615
      /* Handle long section names as in PE.  This must be compatible
3616
   with the code in coff_write_symbols and _bfd_coff_final_link.  */
3617
7
      if (bfd_coff_long_section_names (abfd))
3618
7
  {
3619
7
    size_t len;
3620
3621
7
    len = strlen (current->name);
3622
7
    if (len > SCNNMLEN)
3623
0
      {
3624
3625
        /* An inherent limitation of the /nnnnnnn notation used to indicate
3626
     the offset of the long name in the string table is that we
3627
     cannot address entries beyone the ten million byte boundary.  */
3628
0
        if (string_size < 10000000)
3629
0
    {
3630
      /* The s_name field is defined to be NUL-padded but need not
3631
         be NUL-terminated.  We use a temporary buffer so that we
3632
         can still sprintf all eight chars without splatting a
3633
         terminating NUL over the first byte of the following
3634
         member (s_paddr).  */
3635
      /* PR 21096: The +20 is to stop a bogus warning from gcc7
3636
         about a possible buffer overflow.  */
3637
0
      char s_name_buf[SCNNMLEN + 1 + 20];
3638
3639
      /* We do not need to use snprintf here as we have already
3640
         verified that string_size is not too big, plus we have
3641
         an overlarge buffer, just in case.  */
3642
0
      sprintf (s_name_buf, "/%lu", (unsigned long) string_size);
3643
      /* Then strncpy takes care of any padding for us.  */
3644
0
      strncpy (section.s_name, s_name_buf, SCNNMLEN);
3645
0
    }
3646
0
        else
3647
0
#ifdef COFF_WITH_PE
3648
0
    {
3649
      /* PE use a base 64 encoding for long section names whose
3650
         index is very large.  But contrary to RFC 4648, there is
3651
         no padding: 6 characters must be generated.  */
3652
0
      static const char base64[] =
3653
0
        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
3654
0
        "abcdefghijklmnopqrstuvwxyz"
3655
0
        "0123456789+/";
3656
0
      unsigned long off = string_size;
3657
0
      unsigned i;
3658
3659
0
      section.s_name[0] = '/';
3660
0
      section.s_name[1] = '/';
3661
0
      for (i = SCNNMLEN - 1; i >= 2; i--)
3662
0
        {
3663
0
          section.s_name[i] = base64[off & 0x3f];
3664
0
          off >>= 6;
3665
0
        }
3666
0
    }
3667
0
#endif
3668
0
        if (string_size > 0xffffffffUL - (len + 1)
3669
#ifndef COFF_WITH_PE
3670
      || string_size >= 10000000
3671
#endif
3672
0
      )
3673
0
    {
3674
0
      bfd_set_error (bfd_error_file_too_big);
3675
0
      _bfd_error_handler
3676
        /* xgettext:c-format */
3677
0
        (_("%pB: section %pA: string table overflow at offset %ld"),
3678
0
        abfd, current, (unsigned long) string_size);
3679
0
      return false;
3680
0
    }
3681
3682
0
        string_size += len + 1;
3683
0
        long_section_names = true;
3684
0
      }
3685
7
  }
3686
7
#endif
3687
3688
7
#ifdef _LIB
3689
      /* Always set s_vaddr of .lib to 0.  This is right for SVR3.2
3690
   Ian Taylor <ian@cygnus.com>.  */
3691
7
      if (strcmp (current->name, _LIB) == 0)
3692
0
  section.s_vaddr = 0;
3693
7
      else
3694
7
#endif
3695
7
      section.s_vaddr = current->vma;
3696
7
      section.s_paddr = current->lma;
3697
7
      section.s_size =  current->size;
3698
#ifdef coff_get_section_load_page
3699
      section.s_page = coff_get_section_load_page (current);
3700
#else
3701
7
      section.s_page = 0;
3702
7
#endif
3703
3704
7
#ifdef COFF_WITH_PE
3705
7
      section.s_paddr = 0;
3706
7
#endif
3707
#ifdef COFF_IMAGE_WITH_PE
3708
      /* Reminder: s_paddr holds the virtual size of the section.  */
3709
      if (coff_section_data (abfd, current) != NULL
3710
    && pei_section_data (abfd, current) != NULL)
3711
  section.s_paddr = pei_section_data (abfd, current)->virt_size;
3712
      else
3713
  section.s_paddr = 0;
3714
#endif
3715
3716
      /* If this section has no size or is unloadable then the scnptr
3717
   will be 0 too.  */
3718
7
      if (current->size == 0
3719
7
    || (current->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
3720
7
  section.s_scnptr = 0;
3721
0
      else
3722
0
  section.s_scnptr = current->filepos;
3723
3724
7
      section.s_relptr = current->rel_filepos;
3725
7
      section.s_lnnoptr = current->line_filepos;
3726
7
      section.s_nreloc = current->reloc_count;
3727
7
      section.s_nlnno = current->lineno_count;
3728
7
#ifndef COFF_IMAGE_WITH_PE
3729
      /* In PEI, relocs come in the .reloc section.  */
3730
7
      if (current->reloc_count != 0)
3731
0
  hasrelocs = true;
3732
7
#endif
3733
7
      if (current->lineno_count != 0)
3734
0
  haslinno = true;
3735
#ifdef COFF_IMAGE_WITH_PE
3736
      if ((current->flags & SEC_DEBUGGING) != 0
3737
    && ! is_reloc_section)
3738
  hasdebug = true;
3739
#endif
3740
3741
#ifdef RS6000COFF_C
3742
#ifndef XCOFF64
3743
      /* Indicate the use of an XCOFF overflow section header.  */
3744
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3745
  {
3746
    section.s_nreloc = 0xffff;
3747
    section.s_nlnno = 0xffff;
3748
  }
3749
#endif
3750
#endif
3751
3752
7
      section.s_flags = sec_to_styp_flags (current->name, current->flags);
3753
3754
7
      if (!strcmp (current->name, _TEXT))
3755
0
  text_sec = current;
3756
7
      else if (!strcmp (current->name, _DATA))
3757
0
  data_sec = current;
3758
7
      else if (!strcmp (current->name, _BSS))
3759
0
  bss_sec = current;
3760
#ifdef RS6000COFF_C
3761
      else if (!strcmp (current->name, _TDATA))
3762
  tdata_sec = current;
3763
      else if (!strcmp (current->name, _TBSS))
3764
  tbss_sec = current;
3765
#endif
3766
3767
3768
7
#ifdef COFF_ENCODE_ALIGNMENT
3769
7
      if (COFF_ENCODE_ALIGNMENT (abfd, section, current->alignment_power)
3770
7
    && (COFF_DECODE_ALIGNMENT (section.s_flags)
3771
1
        != current->alignment_power))
3772
0
  {
3773
0
    bool warn = (coff_data (abfd)->link_info
3774
0
           && !bfd_link_relocatable (coff_data (abfd)->link_info));
3775
3776
0
    _bfd_error_handler
3777
      /* xgettext:c-format */
3778
0
      (_("%pB:%s section %s: alignment 2**%u not representable"),
3779
0
       abfd, warn ? " warning:" : "", current->name,
3780
0
       current->alignment_power);
3781
0
    if (!warn)
3782
0
      {
3783
0
        bfd_set_error (bfd_error_nonrepresentable_section);
3784
0
        return false;
3785
0
      }
3786
0
  }
3787
7
#endif
3788
3789
#ifdef COFF_IMAGE_WITH_PE
3790
      /* Suppress output of the sections if they are null.  ld
3791
   includes the bss and data sections even if there is no size
3792
   assigned to them.  NT loader doesn't like it if these section
3793
   headers are included if the sections themselves are not
3794
   needed.  See also coff_compute_section_file_positions.  */
3795
      if (section.s_size == 0)
3796
  internal_f.f_nscns--;
3797
      else
3798
#endif
3799
7
  {
3800
7
    SCNHDR buff;
3801
7
    bfd_size_type amt = bfd_coff_scnhsz (abfd);
3802
3803
7
    if (bfd_coff_swap_scnhdr_out (abfd, &section, &buff) == 0
3804
7
        || bfd_write (& buff, amt, abfd) != amt)
3805
0
      return false;
3806
7
  }
3807
3808
7
#ifdef COFF_WITH_PE
3809
      /* PE stores COMDAT section information in the symbol table.  If
3810
   this section is supposed to have some COMDAT info, track down
3811
   the symbol in the symbol table and modify it.  */
3812
7
      if ((current->flags & SEC_LINK_ONCE) != 0)
3813
0
  {
3814
0
    unsigned int i, count;
3815
0
    asymbol **psym;
3816
0
    coff_symbol_type *csym = NULL;
3817
0
    asymbol **psymsec;
3818
3819
0
    psymsec = NULL;
3820
0
    count = bfd_get_symcount (abfd);
3821
0
    for (i = 0, psym = abfd->outsymbols; i < count; i++, psym++)
3822
0
      {
3823
0
        if ((*psym)->section != current)
3824
0
    continue;
3825
3826
        /* Remember the location of the first symbol in this
3827
     section.  */
3828
0
        if (psymsec == NULL)
3829
0
    psymsec = psym;
3830
3831
        /* See if this is the section symbol.  */
3832
0
        if (strcmp ((*psym)->name, current->name) == 0)
3833
0
    {
3834
0
      csym = coff_symbol_from (*psym);
3835
0
      if (csym == NULL
3836
0
          || csym->native == NULL
3837
0
          || ! csym->native->is_sym
3838
0
          || csym->native->u.syment.n_numaux < 1
3839
0
          || csym->native->u.syment.n_sclass != C_STAT
3840
0
          || csym->native->u.syment.n_type != T_NULL)
3841
0
        continue;
3842
3843
      /* Here *PSYM is the section symbol for CURRENT.  */
3844
3845
0
      break;
3846
0
    }
3847
0
      }
3848
3849
    /* Did we find it?
3850
       Note that we might not if we're converting the file from
3851
       some other object file format.  */
3852
0
    if (i < count)
3853
0
      {
3854
0
        combined_entry_type *aux;
3855
3856
        /* We don't touch the x_checksum field.  The
3857
     x_associated field is not currently supported.  */
3858
3859
0
        aux = csym->native + 1;
3860
0
        BFD_ASSERT (! aux->is_sym);
3861
0
        switch (current->flags & SEC_LINK_DUPLICATES)
3862
0
    {
3863
0
    case SEC_LINK_DUPLICATES_DISCARD:
3864
0
      aux->u.auxent.x_scn.x_comdat = IMAGE_COMDAT_SELECT_ANY;
3865
0
      break;
3866
3867
0
    case SEC_LINK_DUPLICATES_ONE_ONLY:
3868
0
      aux->u.auxent.x_scn.x_comdat =
3869
0
        IMAGE_COMDAT_SELECT_NODUPLICATES;
3870
0
      break;
3871
3872
0
    case SEC_LINK_DUPLICATES_SAME_SIZE:
3873
0
      aux->u.auxent.x_scn.x_comdat =
3874
0
        IMAGE_COMDAT_SELECT_SAME_SIZE;
3875
0
      break;
3876
3877
0
    case SEC_LINK_DUPLICATES_SAME_CONTENTS:
3878
0
      aux->u.auxent.x_scn.x_comdat =
3879
0
        IMAGE_COMDAT_SELECT_EXACT_MATCH;
3880
0
      break;
3881
0
    }
3882
3883
        /* The COMDAT symbol must be the first symbol from this
3884
     section in the symbol table.  In order to make this
3885
     work, we move the COMDAT symbol before the first
3886
     symbol we found in the search above.  It's OK to
3887
     rearrange the symbol table at this point, because
3888
     coff_renumber_symbols is going to rearrange it
3889
     further and fix up all the aux entries.  */
3890
0
        if (psym != psymsec)
3891
0
    {
3892
0
      asymbol *hold;
3893
0
      asymbol **pcopy;
3894
3895
0
      hold = *psym;
3896
0
      for (pcopy = psym; pcopy > psymsec; pcopy--)
3897
0
        pcopy[0] = pcopy[-1];
3898
0
      *psymsec = hold;
3899
0
    }
3900
0
      }
3901
0
  }
3902
7
#endif /* COFF_WITH_PE */
3903
7
    }
3904
3905
#ifdef RS6000COFF_C
3906
#ifndef XCOFF64
3907
  /* XCOFF handles overflows in the reloc and line number count fields
3908
     by creating a new section header to hold the correct values.  */
3909
  for (current = abfd->sections; current != NULL; current = current->next)
3910
    {
3911
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3912
  {
3913
    struct internal_scnhdr scnhdr;
3914
    SCNHDR buff;
3915
    bfd_size_type amt;
3916
3917
    internal_f.f_nscns++;
3918
    memcpy (scnhdr.s_name, ".ovrflo", 8);
3919
    scnhdr.s_paddr = current->reloc_count;
3920
    scnhdr.s_vaddr = current->lineno_count;
3921
    scnhdr.s_size = 0;
3922
    scnhdr.s_scnptr = 0;
3923
    scnhdr.s_relptr = current->rel_filepos;
3924
    scnhdr.s_lnnoptr = current->line_filepos;
3925
    scnhdr.s_nreloc = current->target_index;
3926
    scnhdr.s_nlnno = current->target_index;
3927
    scnhdr.s_flags = STYP_OVRFLO;
3928
    amt = bfd_coff_scnhsz (abfd);
3929
    if (bfd_coff_swap_scnhdr_out (abfd, &scnhdr, &buff) == 0
3930
        || bfd_write (& buff, amt, abfd) != amt)
3931
      return false;
3932
  }
3933
    }
3934
#endif
3935
#endif
3936
3937
#if defined (COFF_GO32_EXE) || defined (COFF_GO32)
3938
  /* Pad section headers.  */
3939
  if ((abfd->flags & EXEC_P) != 0)
3940
    {
3941
      asection *s = abfd->sections;
3942
      while (s != NULL && s->filepos == 0)
3943
  s = s->next;
3944
      if (s != NULL)
3945
  {
3946
    file_ptr cur_ptr
3947
      = scn_base + abfd->section_count * bfd_coff_scnhsz (abfd);
3948
    file_ptr fill_size = s->filepos - cur_ptr;
3949
    if (fill_size > 0)
3950
      {
3951
        bfd_byte *b = bfd_zmalloc (fill_size);
3952
        if (!b)
3953
    return false;
3954
        if (bfd_write (b, fill_size, abfd) != (ufile_ptr) fill_size)
3955
    {
3956
      free (b);
3957
      return false;
3958
    }
3959
        free (b);
3960
      }
3961
  }
3962
    }
3963
#endif
3964
3965
  /* OK, now set up the filehdr...  */
3966
3967
  /* Don't include the internal abs section in the section count */
3968
3969
  /* We will NOT put a fucking timestamp in the header here. Every time you
3970
     put it back, I will come in and take it out again.  I'm sorry.  This
3971
     field does not belong here.  We fill it with a 0 so it compares the
3972
     same but is not a reasonable time. -- gnu@cygnus.com  */
3973
2
  internal_f.f_timdat = 0;
3974
2
  internal_f.f_flags = 0;
3975
3976
2
  if (abfd->flags & EXEC_P)
3977
1
    internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3978
1
  else
3979
1
    {
3980
1
      internal_f.f_opthdr = 0;
3981
#ifdef RS6000COFF_C
3982
#ifndef XCOFF64
3983
      if (xcoff_data (abfd)->full_aouthdr)
3984
  internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3985
      else
3986
  internal_f.f_opthdr = SMALL_AOUTSZ;
3987
#endif
3988
#endif
3989
1
    }
3990
3991
2
  if (!hasrelocs)
3992
2
    internal_f.f_flags |= F_RELFLG;
3993
2
  if (!haslinno)
3994
2
    internal_f.f_flags |= F_LNNO;
3995
2
  if (abfd->flags & EXEC_P)
3996
1
    internal_f.f_flags |= F_EXEC;
3997
#ifdef COFF_IMAGE_WITH_PE
3998
  if (! hasdebug)
3999
    internal_f.f_flags |= IMAGE_FILE_DEBUG_STRIPPED;
4000
  if (pe_data (abfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
4001
    internal_f.f_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
4002
#endif
4003
4004
2
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
4005
2
#ifdef COFF_WITH_PE
4006
2
  internal_f.f_flags |= IMAGE_FILE_32BIT_MACHINE;
4007
#else
4008
  if (bfd_little_endian (abfd))
4009
    internal_f.f_flags |= F_AR32WR;
4010
  else
4011
    internal_f.f_flags |= F_AR32W;
4012
#endif
4013
2
#endif
4014
4015
#ifdef TI_TARGET_ID
4016
  /* Target id is used in TI COFF v1 and later; COFF0 won't use this field,
4017
     but it doesn't hurt to set it internally.  */
4018
  internal_f.f_target_id = TI_TARGET_ID;
4019
#endif
4020
4021
  /* FIXME, should do something about the other byte orders and
4022
     architectures.  */
4023
4024
#ifdef RS6000COFF_C
4025
  if ((abfd->flags & DYNAMIC) != 0)
4026
    internal_f.f_flags |= F_SHROBJ;
4027
  if (bfd_get_section_by_name (abfd, _LOADER) != NULL)
4028
    internal_f.f_flags |= F_DYNLOAD;
4029
#endif
4030
4031
2
  memset (&internal_a, 0, sizeof internal_a);
4032
4033
  /* Set up architecture-dependent stuff.  */
4034
2
  {
4035
2
    unsigned int magic = 0;
4036
2
    unsigned short flags = 0;
4037
4038
2
    coff_set_flags (abfd, &magic, &flags);
4039
2
    internal_f.f_magic = magic;
4040
2
    internal_f.f_flags |= flags;
4041
    /* ...and the "opt"hdr...  */
4042
4043
#ifdef TICOFF_AOUT_MAGIC
4044
    internal_a.magic = TICOFF_AOUT_MAGIC;
4045
#define __A_MAGIC_SET__
4046
#endif
4047
4048
#if defined(ARM)
4049
#define __A_MAGIC_SET__
4050
    internal_a.magic = ZMAGIC;
4051
#endif
4052
4053
#if defined(AARCH64)
4054
#define __A_MAGIC_SET__
4055
    internal_a.magic = ZMAGIC;
4056
#endif
4057
4058
#if defined(LOONGARCH64)
4059
#define __A_MAGIC_SET__
4060
    internal_a.magic = ZMAGIC;
4061
#endif
4062
4063
2
#if defined MCORE_PE
4064
2
#define __A_MAGIC_SET__
4065
2
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR_MAGIC;
4066
2
#endif
4067
4068
#if defined(I386)
4069
#define __A_MAGIC_SET__
4070
#if defined LYNXOS
4071
    internal_a.magic = LYNXCOFFMAGIC;
4072
#elif defined AMD64
4073
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR64_MAGIC;
4074
#else
4075
    internal_a.magic = ZMAGIC;
4076
#endif
4077
#endif /* I386 */
4078
4079
#if defined(IA64)
4080
#define __A_MAGIC_SET__
4081
    internal_a.magic = PE32PMAGIC;
4082
#endif /* IA64 */
4083
4084
#if defined(SPARC)
4085
#define __A_MAGIC_SET__
4086
#if defined(LYNXOS)
4087
    internal_a.magic = LYNXCOFFMAGIC;
4088
#endif /* LYNXOS */
4089
#endif /* SPARC */
4090
4091
#ifdef RS6000COFF_C
4092
#define __A_MAGIC_SET__
4093
    internal_a.magic = (abfd->flags & D_PAGED) ? RS6K_AOUTHDR_ZMAGIC :
4094
    (abfd->flags & WP_TEXT) ? RS6K_AOUTHDR_NMAGIC :
4095
    RS6K_AOUTHDR_OMAGIC;
4096
#endif
4097
4098
#if defined(SH) && defined(COFF_WITH_PE)
4099
#define __A_MAGIC_SET__
4100
    internal_a.magic = SH_PE_MAGIC;
4101
#endif
4102
4103
#if defined(MIPS) && defined(COFF_WITH_PE)
4104
#define __A_MAGIC_SET__
4105
    internal_a.magic = MIPS_PE_MAGIC;
4106
#endif
4107
4108
#ifndef __A_MAGIC_SET__
4109
#include "Your aouthdr magic number is not being set!"
4110
#else
4111
2
#undef __A_MAGIC_SET__
4112
2
#endif
4113
2
  }
4114
4115
#ifdef RS6000COFF_C
4116
  /* XCOFF 32bit needs this to have new behaviour for n_type field.  */
4117
  internal_a.vstamp = 2;
4118
#else
4119
  /* FIXME: Does anybody ever set this to another value?  */
4120
2
  internal_a.vstamp = 0;
4121
2
#endif
4122
4123
  /* Now should write relocs, strings, syms.  */
4124
2
  obj_sym_filepos (abfd) = sym_base;
4125
4126
2
  if (bfd_get_symcount (abfd) != 0)
4127
2
    {
4128
2
      int firstundef;
4129
4130
2
      if (!coff_renumber_symbols (abfd, &firstundef))
4131
0
  return false;
4132
2
      coff_mangle_symbols (abfd);
4133
2
      if (! coff_write_symbols (abfd))
4134
0
  return false;
4135
2
      if (! coff_write_linenumbers (abfd))
4136
0
  return false;
4137
2
      if (! coff_write_relocs (abfd, firstundef))
4138
0
  return false;
4139
2
    }
4140
0
#ifdef COFF_LONG_SECTION_NAMES
4141
0
  else if (long_section_names && ! obj_coff_strings_written (abfd))
4142
0
    {
4143
      /* If we have long section names we have to write out the string
4144
   table even if there are no symbols.  */
4145
0
      if (! coff_write_symbols (abfd))
4146
0
  return false;
4147
0
    }
4148
2
#endif
4149
  /* If bfd_get_symcount (abfd) != 0, then we are not using the COFF
4150
     backend linker, and obj_raw_syment_count is not valid until after
4151
     coff_write_symbols is called.  */
4152
2
  if (obj_raw_syment_count (abfd) != 0)
4153
2
    {
4154
2
      internal_f.f_symptr = sym_base;
4155
#ifdef RS6000COFF_C
4156
      /* AIX appears to require that F_RELFLG not be set if there are
4157
   local symbols but no relocations.  */
4158
      internal_f.f_flags &=~ F_RELFLG;
4159
#endif
4160
2
    }
4161
0
  else
4162
0
    {
4163
0
      if (long_section_names)
4164
0
  internal_f.f_symptr = sym_base;
4165
0
      else
4166
0
  internal_f.f_symptr = 0;
4167
0
      internal_f.f_flags |= F_LSYMS;
4168
0
    }
4169
4170
2
  if (text_sec)
4171
0
    {
4172
0
      internal_a.tsize = text_sec->size;
4173
0
      internal_a.text_start = internal_a.tsize ? text_sec->vma : 0;
4174
0
    }
4175
2
  if (data_sec)
4176
0
    {
4177
0
      internal_a.dsize = data_sec->size;
4178
0
      internal_a.data_start = internal_a.dsize ? data_sec->vma : 0;
4179
0
    }
4180
2
  if (bss_sec)
4181
0
    {
4182
0
      internal_a.bsize = bss_sec->size;
4183
0
      if (internal_a.bsize && bss_sec->vma < internal_a.data_start)
4184
0
  internal_a.data_start = bss_sec->vma;
4185
0
    }
4186
4187
2
  internal_a.entry = bfd_get_start_address (abfd);
4188
2
  internal_f.f_nsyms = obj_raw_syment_count (abfd);
4189
4190
#ifdef RS6000COFF_C
4191
  if (xcoff_data (abfd)->full_aouthdr)
4192
    {
4193
      bfd_vma toc;
4194
      asection *loader_sec;
4195
4196
      internal_a.vstamp = 2;
4197
4198
      internal_a.o_snentry = xcoff_data (abfd)->snentry;
4199
      if (internal_a.o_snentry == 0)
4200
  internal_a.entry = (bfd_vma) -1;
4201
4202
      if (text_sec != NULL)
4203
  {
4204
    internal_a.o_sntext = text_sec->target_index;
4205
    internal_a.o_algntext = bfd_section_alignment (text_sec);
4206
  }
4207
      else
4208
  {
4209
    internal_a.o_sntext = 0;
4210
    internal_a.o_algntext = 0;
4211
  }
4212
      if (data_sec != NULL)
4213
  {
4214
    internal_a.o_sndata = data_sec->target_index;
4215
    internal_a.o_algndata = bfd_section_alignment (data_sec);
4216
  }
4217
      else
4218
  {
4219
    internal_a.o_sndata = 0;
4220
    internal_a.o_algndata = 0;
4221
  }
4222
      loader_sec = bfd_get_section_by_name (abfd, ".loader");
4223
      if (loader_sec != NULL)
4224
  internal_a.o_snloader = loader_sec->target_index;
4225
      else
4226
  internal_a.o_snloader = 0;
4227
      if (bss_sec != NULL)
4228
  internal_a.o_snbss = bss_sec->target_index;
4229
      else
4230
  internal_a.o_snbss = 0;
4231
4232
      if (tdata_sec != NULL)
4233
  {
4234
    internal_a.o_sntdata = tdata_sec->target_index;
4235
    /* TODO: o_flags should be set to RS6K_AOUTHDR_TLS_LE
4236
       if there is at least one R_TLS_LE relocations.  */
4237
    internal_a.o_flags = 0;
4238
#ifdef XCOFF64
4239
    internal_a.o_x64flags = 0;
4240
#endif
4241
  }
4242
      else
4243
  {
4244
    internal_a.o_sntdata = 0;
4245
    internal_a.o_flags = 0;
4246
#ifdef XCOFF64
4247
    internal_a.o_x64flags = 0;
4248
#endif
4249
  }
4250
      if (tbss_sec != NULL)
4251
    internal_a.o_sntbss = tbss_sec->target_index;
4252
      else
4253
    internal_a.o_sntbss = 0;
4254
4255
      toc = xcoff_data (abfd)->toc;
4256
      internal_a.o_toc = toc;
4257
      internal_a.o_sntoc = xcoff_data (abfd)->sntoc;
4258
4259
      internal_a.o_modtype = xcoff_data (abfd)->modtype;
4260
      if (xcoff_data (abfd)->cputype != -1)
4261
  internal_a.o_cputype = xcoff_data (abfd)->cputype;
4262
      else
4263
  {
4264
    switch (bfd_get_arch (abfd))
4265
      {
4266
      case bfd_arch_rs6000:
4267
        internal_a.o_cputype = 4;
4268
        break;
4269
      case bfd_arch_powerpc:
4270
        if (bfd_get_mach (abfd) == bfd_mach_ppc)
4271
    internal_a.o_cputype = 3;
4272
        else if (bfd_get_mach (abfd) == bfd_mach_ppc_620)
4273
    internal_a.o_cputype = 2;
4274
        else
4275
    internal_a.o_cputype = 1;
4276
        break;
4277
      default:
4278
        abort ();
4279
      }
4280
  }
4281
      internal_a.o_maxstack = xcoff_data (abfd)->maxstack;
4282
      internal_a.o_maxdata = xcoff_data (abfd)->maxdata;
4283
    }
4284
#endif
4285
4286
2
#ifdef COFF_WITH_PE
4287
2
  {
4288
    /* After object contents are finalized so we can compute a reasonable hash,
4289
       but before header is written so we can update it to point to debug directory.  */
4290
2
    struct pe_tdata *pe = pe_data (abfd);
4291
4292
2
    if (pe->build_id.after_write_object_contents != NULL)
4293
0
      (*pe->build_id.after_write_object_contents) (abfd);
4294
2
  }
4295
2
#endif
4296
4297
  /* Now write header.  */
4298
2
  if (bfd_seek (abfd, 0, SEEK_SET) != 0)
4299
0
    return false;
4300
4301
2
  {
4302
2
    char * buff;
4303
2
    bfd_size_type amount = bfd_coff_filhsz (abfd);
4304
4305
2
    buff = (char *) bfd_malloc (amount);
4306
2
    if (buff == NULL)
4307
0
      return false;
4308
4309
2
    bfd_coff_swap_filehdr_out (abfd, & internal_f, buff);
4310
2
    amount = bfd_write (buff, amount, abfd);
4311
4312
2
    free (buff);
4313
4314
2
    if (amount != bfd_coff_filhsz (abfd))
4315
0
      return false;
4316
2
  }
4317
4318
2
  if (abfd->flags & EXEC_P)
4319
1
    {
4320
      /* Note that peicode.h fills in a PEAOUTHDR, not an AOUTHDR.
4321
   include/coff/pe.h sets AOUTSZ == sizeof (PEAOUTHDR)).  */
4322
1
      char * buff;
4323
1
      bfd_size_type amount = bfd_coff_aoutsz (abfd);
4324
4325
1
      buff = (char *) bfd_malloc (amount);
4326
1
      if (buff == NULL)
4327
0
  return false;
4328
4329
1
      coff_swap_aouthdr_out (abfd, & internal_a, buff);
4330
1
      amount = bfd_write (buff, amount, abfd);
4331
4332
1
      free (buff);
4333
4334
1
      if (amount != bfd_coff_aoutsz (abfd))
4335
0
  return false;
4336
4337
#ifdef COFF_IMAGE_WITH_PE
4338
      if (! coff_apply_checksum (abfd))
4339
  return false;
4340
#endif
4341
1
    }
4342
#ifdef RS6000COFF_C
4343
#ifndef XCOFF64
4344
  else
4345
    {
4346
      AOUTHDR buff;
4347
      size_t size;
4348
4349
      /* XCOFF32 seems to always write at least a small a.out header.  */
4350
      coff_swap_aouthdr_out (abfd, & internal_a, & buff);
4351
      if (xcoff_data (abfd)->full_aouthdr)
4352
  size = bfd_coff_aoutsz (abfd);
4353
      else
4354
  size = SMALL_AOUTSZ;
4355
      if (bfd_write (&buff, size, abfd) != size)
4356
  return false;
4357
    }
4358
#endif
4359
#endif
4360
4361
2
  return true;
4362
2
}
Unexecuted instantiation: pe-sh.c:coff_write_object_contents
pei-arm-wince.c:coff_write_object_contents
Line
Count
Source
3486
1
{
3487
1
  asection *current;
3488
1
  bool hasrelocs = false;
3489
1
  bool haslinno = false;
3490
1
#ifdef COFF_IMAGE_WITH_PE
3491
1
  bool hasdebug = false;
3492
1
#endif
3493
1
  file_ptr scn_base;
3494
1
  file_ptr reloc_base;
3495
1
  file_ptr lineno_base;
3496
1
  file_ptr sym_base;
3497
1
  unsigned long reloc_size = 0, reloc_count = 0;
3498
1
  unsigned long lnno_size = 0;
3499
1
  bool long_section_names;
3500
1
  asection *text_sec = NULL;
3501
1
  asection *data_sec = NULL;
3502
1
  asection *bss_sec = NULL;
3503
#ifdef RS6000COFF_C
3504
  asection *tdata_sec = NULL;
3505
  asection *tbss_sec = NULL;
3506
#endif
3507
1
  struct internal_filehdr internal_f;
3508
1
  struct internal_aouthdr internal_a;
3509
1
#ifdef COFF_LONG_SECTION_NAMES
3510
1
  size_t string_size = STRING_SIZE_SIZE;
3511
1
#endif
3512
3513
1
  bfd_set_error (bfd_error_system_call);
3514
3515
  /* Make a pass through the symbol table to count line number entries and
3516
     put them into the correct asections.  */
3517
1
  lnno_size = coff_count_linenumbers (abfd) * bfd_coff_linesz (abfd);
3518
3519
1
  if (! abfd->output_has_begun)
3520
0
    {
3521
0
      if (! coff_compute_section_file_positions (abfd))
3522
0
  return false;
3523
0
    }
3524
3525
1
  reloc_base = obj_relocbase (abfd);
3526
3527
  /* Work out the size of the reloc and linno areas.  */
3528
3529
3
  for (current = abfd->sections; current != NULL; current =
3530
2
       current->next)
3531
2
    {
3532
2
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3533
      /* We store the actual reloc count in the first reloc's addr.  */
3534
2
      if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3535
0
  reloc_count ++;
3536
2
#endif
3537
2
      reloc_count += current->reloc_count;
3538
2
    }
3539
3540
1
  reloc_size = reloc_count * bfd_coff_relsz (abfd);
3541
3542
1
  lineno_base = reloc_base + reloc_size;
3543
1
  sym_base = lineno_base + lnno_size;
3544
3545
  /* Indicate in each section->line_filepos its actual file address.  */
3546
3
  for (current = abfd->sections; current != NULL; current =
3547
2
       current->next)
3548
2
    {
3549
2
      if (current->lineno_count)
3550
0
  {
3551
0
    current->line_filepos = lineno_base;
3552
0
    current->moving_line_filepos = lineno_base;
3553
0
    lineno_base += current->lineno_count * bfd_coff_linesz (abfd);
3554
0
  }
3555
2
      else
3556
2
  current->line_filepos = 0;
3557
3558
2
      if (current->reloc_count)
3559
0
  {
3560
0
    current->rel_filepos = reloc_base;
3561
0
    reloc_base += current->reloc_count * bfd_coff_relsz (abfd);
3562
0
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3563
    /* Extra reloc to hold real count.  */
3564
0
    if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3565
0
      reloc_base += bfd_coff_relsz (abfd);
3566
0
#endif
3567
0
  }
3568
2
      else
3569
2
  current->rel_filepos = 0;
3570
2
    }
3571
3572
  /* Write section headers to the file.  */
3573
1
  internal_f.f_nscns = 0;
3574
3575
1
  if ((abfd->flags & EXEC_P) != 0)
3576
0
    scn_base = bfd_coff_filhsz (abfd) + bfd_coff_aoutsz (abfd);
3577
1
  else
3578
1
    {
3579
1
      scn_base = bfd_coff_filhsz (abfd);
3580
#ifdef RS6000COFF_C
3581
#ifndef XCOFF64
3582
      if (xcoff_data (abfd)->full_aouthdr)
3583
  scn_base += bfd_coff_aoutsz (abfd);
3584
      else
3585
  scn_base += SMALL_AOUTSZ;
3586
#endif
3587
#endif
3588
1
    }
3589
3590
1
  if (bfd_seek (abfd, scn_base, SEEK_SET) != 0)
3591
0
    return false;
3592
3593
1
  long_section_names = false;
3594
1
  for (current = abfd->sections;
3595
3
       current != NULL;
3596
2
       current = current->next)
3597
2
    {
3598
2
      struct internal_scnhdr section;
3599
2
#ifdef COFF_IMAGE_WITH_PE
3600
2
      bool is_reloc_section = false;
3601
3602
2
      if (strcmp (current->name, DOT_RELOC) == 0)
3603
0
  {
3604
0
    is_reloc_section = true;
3605
0
    hasrelocs = true;
3606
0
    pe_data (abfd)->has_reloc_section = 1;
3607
0
  }
3608
2
#endif
3609
3610
2
      internal_f.f_nscns++;
3611
3612
2
      strncpy (section.s_name, current->name, SCNNMLEN);
3613
3614
2
#ifdef COFF_LONG_SECTION_NAMES
3615
      /* Handle long section names as in PE.  This must be compatible
3616
   with the code in coff_write_symbols and _bfd_coff_final_link.  */
3617
2
      if (bfd_coff_long_section_names (abfd))
3618
0
  {
3619
0
    size_t len;
3620
3621
0
    len = strlen (current->name);
3622
0
    if (len > SCNNMLEN)
3623
0
      {
3624
3625
        /* An inherent limitation of the /nnnnnnn notation used to indicate
3626
     the offset of the long name in the string table is that we
3627
     cannot address entries beyone the ten million byte boundary.  */
3628
0
        if (string_size < 10000000)
3629
0
    {
3630
      /* The s_name field is defined to be NUL-padded but need not
3631
         be NUL-terminated.  We use a temporary buffer so that we
3632
         can still sprintf all eight chars without splatting a
3633
         terminating NUL over the first byte of the following
3634
         member (s_paddr).  */
3635
      /* PR 21096: The +20 is to stop a bogus warning from gcc7
3636
         about a possible buffer overflow.  */
3637
0
      char s_name_buf[SCNNMLEN + 1 + 20];
3638
3639
      /* We do not need to use snprintf here as we have already
3640
         verified that string_size is not too big, plus we have
3641
         an overlarge buffer, just in case.  */
3642
0
      sprintf (s_name_buf, "/%lu", (unsigned long) string_size);
3643
      /* Then strncpy takes care of any padding for us.  */
3644
0
      strncpy (section.s_name, s_name_buf, SCNNMLEN);
3645
0
    }
3646
0
        else
3647
0
#ifdef COFF_WITH_PE
3648
0
    {
3649
      /* PE use a base 64 encoding for long section names whose
3650
         index is very large.  But contrary to RFC 4648, there is
3651
         no padding: 6 characters must be generated.  */
3652
0
      static const char base64[] =
3653
0
        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
3654
0
        "abcdefghijklmnopqrstuvwxyz"
3655
0
        "0123456789+/";
3656
0
      unsigned long off = string_size;
3657
0
      unsigned i;
3658
3659
0
      section.s_name[0] = '/';
3660
0
      section.s_name[1] = '/';
3661
0
      for (i = SCNNMLEN - 1; i >= 2; i--)
3662
0
        {
3663
0
          section.s_name[i] = base64[off & 0x3f];
3664
0
          off >>= 6;
3665
0
        }
3666
0
    }
3667
0
#endif
3668
0
        if (string_size > 0xffffffffUL - (len + 1)
3669
#ifndef COFF_WITH_PE
3670
      || string_size >= 10000000
3671
#endif
3672
0
      )
3673
0
    {
3674
0
      bfd_set_error (bfd_error_file_too_big);
3675
0
      _bfd_error_handler
3676
        /* xgettext:c-format */
3677
0
        (_("%pB: section %pA: string table overflow at offset %ld"),
3678
0
        abfd, current, (unsigned long) string_size);
3679
0
      return false;
3680
0
    }
3681
3682
0
        string_size += len + 1;
3683
0
        long_section_names = true;
3684
0
      }
3685
0
  }
3686
2
#endif
3687
3688
2
#ifdef _LIB
3689
      /* Always set s_vaddr of .lib to 0.  This is right for SVR3.2
3690
   Ian Taylor <ian@cygnus.com>.  */
3691
2
      if (strcmp (current->name, _LIB) == 0)
3692
0
  section.s_vaddr = 0;
3693
2
      else
3694
2
#endif
3695
2
      section.s_vaddr = current->vma;
3696
2
      section.s_paddr = current->lma;
3697
2
      section.s_size =  current->size;
3698
#ifdef coff_get_section_load_page
3699
      section.s_page = coff_get_section_load_page (current);
3700
#else
3701
2
      section.s_page = 0;
3702
2
#endif
3703
3704
2
#ifdef COFF_WITH_PE
3705
2
      section.s_paddr = 0;
3706
2
#endif
3707
2
#ifdef COFF_IMAGE_WITH_PE
3708
      /* Reminder: s_paddr holds the virtual size of the section.  */
3709
2
      if (coff_section_data (abfd, current) != NULL
3710
2
    && pei_section_data (abfd, current) != NULL)
3711
2
  section.s_paddr = pei_section_data (abfd, current)->virt_size;
3712
0
      else
3713
0
  section.s_paddr = 0;
3714
2
#endif
3715
3716
      /* If this section has no size or is unloadable then the scnptr
3717
   will be 0 too.  */
3718
2
      if (current->size == 0
3719
2
    || (current->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
3720
0
  section.s_scnptr = 0;
3721
2
      else
3722
2
  section.s_scnptr = current->filepos;
3723
3724
2
      section.s_relptr = current->rel_filepos;
3725
2
      section.s_lnnoptr = current->line_filepos;
3726
2
      section.s_nreloc = current->reloc_count;
3727
2
      section.s_nlnno = current->lineno_count;
3728
#ifndef COFF_IMAGE_WITH_PE
3729
      /* In PEI, relocs come in the .reloc section.  */
3730
      if (current->reloc_count != 0)
3731
  hasrelocs = true;
3732
#endif
3733
2
      if (current->lineno_count != 0)
3734
0
  haslinno = true;
3735
2
#ifdef COFF_IMAGE_WITH_PE
3736
2
      if ((current->flags & SEC_DEBUGGING) != 0
3737
2
    && ! is_reloc_section)
3738
2
  hasdebug = true;
3739
2
#endif
3740
3741
#ifdef RS6000COFF_C
3742
#ifndef XCOFF64
3743
      /* Indicate the use of an XCOFF overflow section header.  */
3744
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3745
  {
3746
    section.s_nreloc = 0xffff;
3747
    section.s_nlnno = 0xffff;
3748
  }
3749
#endif
3750
#endif
3751
3752
2
      section.s_flags = sec_to_styp_flags (current->name, current->flags);
3753
3754
2
      if (!strcmp (current->name, _TEXT))
3755
0
  text_sec = current;
3756
2
      else if (!strcmp (current->name, _DATA))
3757
0
  data_sec = current;
3758
2
      else if (!strcmp (current->name, _BSS))
3759
0
  bss_sec = current;
3760
#ifdef RS6000COFF_C
3761
      else if (!strcmp (current->name, _TDATA))
3762
  tdata_sec = current;
3763
      else if (!strcmp (current->name, _TBSS))
3764
  tbss_sec = current;
3765
#endif
3766
3767
3768
2
#ifdef COFF_ENCODE_ALIGNMENT
3769
2
      if (COFF_ENCODE_ALIGNMENT (abfd, section, current->alignment_power)
3770
2
    && (COFF_DECODE_ALIGNMENT (section.s_flags)
3771
2
        != current->alignment_power))
3772
0
  {
3773
0
    bool warn = (coff_data (abfd)->link_info
3774
0
           && !bfd_link_relocatable (coff_data (abfd)->link_info));
3775
3776
0
    _bfd_error_handler
3777
      /* xgettext:c-format */
3778
0
      (_("%pB:%s section %s: alignment 2**%u not representable"),
3779
0
       abfd, warn ? " warning:" : "", current->name,
3780
0
       current->alignment_power);
3781
0
    if (!warn)
3782
0
      {
3783
0
        bfd_set_error (bfd_error_nonrepresentable_section);
3784
0
        return false;
3785
0
      }
3786
0
  }
3787
2
#endif
3788
3789
2
#ifdef COFF_IMAGE_WITH_PE
3790
      /* Suppress output of the sections if they are null.  ld
3791
   includes the bss and data sections even if there is no size
3792
   assigned to them.  NT loader doesn't like it if these section
3793
   headers are included if the sections themselves are not
3794
   needed.  See also coff_compute_section_file_positions.  */
3795
2
      if (section.s_size == 0)
3796
0
  internal_f.f_nscns--;
3797
2
      else
3798
2
#endif
3799
2
  {
3800
2
    SCNHDR buff;
3801
2
    bfd_size_type amt = bfd_coff_scnhsz (abfd);
3802
3803
2
    if (bfd_coff_swap_scnhdr_out (abfd, &section, &buff) == 0
3804
2
        || bfd_write (& buff, amt, abfd) != amt)
3805
0
      return false;
3806
2
  }
3807
3808
2
#ifdef COFF_WITH_PE
3809
      /* PE stores COMDAT section information in the symbol table.  If
3810
   this section is supposed to have some COMDAT info, track down
3811
   the symbol in the symbol table and modify it.  */
3812
2
      if ((current->flags & SEC_LINK_ONCE) != 0)
3813
0
  {
3814
0
    unsigned int i, count;
3815
0
    asymbol **psym;
3816
0
    coff_symbol_type *csym = NULL;
3817
0
    asymbol **psymsec;
3818
3819
0
    psymsec = NULL;
3820
0
    count = bfd_get_symcount (abfd);
3821
0
    for (i = 0, psym = abfd->outsymbols; i < count; i++, psym++)
3822
0
      {
3823
0
        if ((*psym)->section != current)
3824
0
    continue;
3825
3826
        /* Remember the location of the first symbol in this
3827
     section.  */
3828
0
        if (psymsec == NULL)
3829
0
    psymsec = psym;
3830
3831
        /* See if this is the section symbol.  */
3832
0
        if (strcmp ((*psym)->name, current->name) == 0)
3833
0
    {
3834
0
      csym = coff_symbol_from (*psym);
3835
0
      if (csym == NULL
3836
0
          || csym->native == NULL
3837
0
          || ! csym->native->is_sym
3838
0
          || csym->native->u.syment.n_numaux < 1
3839
0
          || csym->native->u.syment.n_sclass != C_STAT
3840
0
          || csym->native->u.syment.n_type != T_NULL)
3841
0
        continue;
3842
3843
      /* Here *PSYM is the section symbol for CURRENT.  */
3844
3845
0
      break;
3846
0
    }
3847
0
      }
3848
3849
    /* Did we find it?
3850
       Note that we might not if we're converting the file from
3851
       some other object file format.  */
3852
0
    if (i < count)
3853
0
      {
3854
0
        combined_entry_type *aux;
3855
3856
        /* We don't touch the x_checksum field.  The
3857
     x_associated field is not currently supported.  */
3858
3859
0
        aux = csym->native + 1;
3860
0
        BFD_ASSERT (! aux->is_sym);
3861
0
        switch (current->flags & SEC_LINK_DUPLICATES)
3862
0
    {
3863
0
    case SEC_LINK_DUPLICATES_DISCARD:
3864
0
      aux->u.auxent.x_scn.x_comdat = IMAGE_COMDAT_SELECT_ANY;
3865
0
      break;
3866
3867
0
    case SEC_LINK_DUPLICATES_ONE_ONLY:
3868
0
      aux->u.auxent.x_scn.x_comdat =
3869
0
        IMAGE_COMDAT_SELECT_NODUPLICATES;
3870
0
      break;
3871
3872
0
    case SEC_LINK_DUPLICATES_SAME_SIZE:
3873
0
      aux->u.auxent.x_scn.x_comdat =
3874
0
        IMAGE_COMDAT_SELECT_SAME_SIZE;
3875
0
      break;
3876
3877
0
    case SEC_LINK_DUPLICATES_SAME_CONTENTS:
3878
0
      aux->u.auxent.x_scn.x_comdat =
3879
0
        IMAGE_COMDAT_SELECT_EXACT_MATCH;
3880
0
      break;
3881
0
    }
3882
3883
        /* The COMDAT symbol must be the first symbol from this
3884
     section in the symbol table.  In order to make this
3885
     work, we move the COMDAT symbol before the first
3886
     symbol we found in the search above.  It's OK to
3887
     rearrange the symbol table at this point, because
3888
     coff_renumber_symbols is going to rearrange it
3889
     further and fix up all the aux entries.  */
3890
0
        if (psym != psymsec)
3891
0
    {
3892
0
      asymbol *hold;
3893
0
      asymbol **pcopy;
3894
3895
0
      hold = *psym;
3896
0
      for (pcopy = psym; pcopy > psymsec; pcopy--)
3897
0
        pcopy[0] = pcopy[-1];
3898
0
      *psymsec = hold;
3899
0
    }
3900
0
      }
3901
0
  }
3902
2
#endif /* COFF_WITH_PE */
3903
2
    }
3904
3905
#ifdef RS6000COFF_C
3906
#ifndef XCOFF64
3907
  /* XCOFF handles overflows in the reloc and line number count fields
3908
     by creating a new section header to hold the correct values.  */
3909
  for (current = abfd->sections; current != NULL; current = current->next)
3910
    {
3911
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3912
  {
3913
    struct internal_scnhdr scnhdr;
3914
    SCNHDR buff;
3915
    bfd_size_type amt;
3916
3917
    internal_f.f_nscns++;
3918
    memcpy (scnhdr.s_name, ".ovrflo", 8);
3919
    scnhdr.s_paddr = current->reloc_count;
3920
    scnhdr.s_vaddr = current->lineno_count;
3921
    scnhdr.s_size = 0;
3922
    scnhdr.s_scnptr = 0;
3923
    scnhdr.s_relptr = current->rel_filepos;
3924
    scnhdr.s_lnnoptr = current->line_filepos;
3925
    scnhdr.s_nreloc = current->target_index;
3926
    scnhdr.s_nlnno = current->target_index;
3927
    scnhdr.s_flags = STYP_OVRFLO;
3928
    amt = bfd_coff_scnhsz (abfd);
3929
    if (bfd_coff_swap_scnhdr_out (abfd, &scnhdr, &buff) == 0
3930
        || bfd_write (& buff, amt, abfd) != amt)
3931
      return false;
3932
  }
3933
    }
3934
#endif
3935
#endif
3936
3937
#if defined (COFF_GO32_EXE) || defined (COFF_GO32)
3938
  /* Pad section headers.  */
3939
  if ((abfd->flags & EXEC_P) != 0)
3940
    {
3941
      asection *s = abfd->sections;
3942
      while (s != NULL && s->filepos == 0)
3943
  s = s->next;
3944
      if (s != NULL)
3945
  {
3946
    file_ptr cur_ptr
3947
      = scn_base + abfd->section_count * bfd_coff_scnhsz (abfd);
3948
    file_ptr fill_size = s->filepos - cur_ptr;
3949
    if (fill_size > 0)
3950
      {
3951
        bfd_byte *b = bfd_zmalloc (fill_size);
3952
        if (!b)
3953
    return false;
3954
        if (bfd_write (b, fill_size, abfd) != (ufile_ptr) fill_size)
3955
    {
3956
      free (b);
3957
      return false;
3958
    }
3959
        free (b);
3960
      }
3961
  }
3962
    }
3963
#endif
3964
3965
  /* OK, now set up the filehdr...  */
3966
3967
  /* Don't include the internal abs section in the section count */
3968
3969
  /* We will NOT put a fucking timestamp in the header here. Every time you
3970
     put it back, I will come in and take it out again.  I'm sorry.  This
3971
     field does not belong here.  We fill it with a 0 so it compares the
3972
     same but is not a reasonable time. -- gnu@cygnus.com  */
3973
1
  internal_f.f_timdat = 0;
3974
1
  internal_f.f_flags = 0;
3975
3976
1
  if (abfd->flags & EXEC_P)
3977
0
    internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3978
1
  else
3979
1
    {
3980
1
      internal_f.f_opthdr = 0;
3981
#ifdef RS6000COFF_C
3982
#ifndef XCOFF64
3983
      if (xcoff_data (abfd)->full_aouthdr)
3984
  internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3985
      else
3986
  internal_f.f_opthdr = SMALL_AOUTSZ;
3987
#endif
3988
#endif
3989
1
    }
3990
3991
1
  if (!hasrelocs)
3992
1
    internal_f.f_flags |= F_RELFLG;
3993
1
  if (!haslinno)
3994
1
    internal_f.f_flags |= F_LNNO;
3995
1
  if (abfd->flags & EXEC_P)
3996
0
    internal_f.f_flags |= F_EXEC;
3997
1
#ifdef COFF_IMAGE_WITH_PE
3998
1
  if (! hasdebug)
3999
0
    internal_f.f_flags |= IMAGE_FILE_DEBUG_STRIPPED;
4000
1
  if (pe_data (abfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
4001
0
    internal_f.f_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
4002
1
#endif
4003
4004
1
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
4005
1
#ifdef COFF_WITH_PE
4006
1
  internal_f.f_flags |= IMAGE_FILE_32BIT_MACHINE;
4007
#else
4008
  if (bfd_little_endian (abfd))
4009
    internal_f.f_flags |= F_AR32WR;
4010
  else
4011
    internal_f.f_flags |= F_AR32W;
4012
#endif
4013
1
#endif
4014
4015
#ifdef TI_TARGET_ID
4016
  /* Target id is used in TI COFF v1 and later; COFF0 won't use this field,
4017
     but it doesn't hurt to set it internally.  */
4018
  internal_f.f_target_id = TI_TARGET_ID;
4019
#endif
4020
4021
  /* FIXME, should do something about the other byte orders and
4022
     architectures.  */
4023
4024
#ifdef RS6000COFF_C
4025
  if ((abfd->flags & DYNAMIC) != 0)
4026
    internal_f.f_flags |= F_SHROBJ;
4027
  if (bfd_get_section_by_name (abfd, _LOADER) != NULL)
4028
    internal_f.f_flags |= F_DYNLOAD;
4029
#endif
4030
4031
1
  memset (&internal_a, 0, sizeof internal_a);
4032
4033
  /* Set up architecture-dependent stuff.  */
4034
1
  {
4035
1
    unsigned int magic = 0;
4036
1
    unsigned short flags = 0;
4037
4038
1
    coff_set_flags (abfd, &magic, &flags);
4039
1
    internal_f.f_magic = magic;
4040
1
    internal_f.f_flags |= flags;
4041
    /* ...and the "opt"hdr...  */
4042
4043
#ifdef TICOFF_AOUT_MAGIC
4044
    internal_a.magic = TICOFF_AOUT_MAGIC;
4045
#define __A_MAGIC_SET__
4046
#endif
4047
4048
1
#if defined(ARM)
4049
1
#define __A_MAGIC_SET__
4050
1
    internal_a.magic = ZMAGIC;
4051
1
#endif
4052
4053
#if defined(AARCH64)
4054
#define __A_MAGIC_SET__
4055
    internal_a.magic = ZMAGIC;
4056
#endif
4057
4058
#if defined(LOONGARCH64)
4059
#define __A_MAGIC_SET__
4060
    internal_a.magic = ZMAGIC;
4061
#endif
4062
4063
#if defined MCORE_PE
4064
#define __A_MAGIC_SET__
4065
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR_MAGIC;
4066
#endif
4067
4068
#if defined(I386)
4069
#define __A_MAGIC_SET__
4070
#if defined LYNXOS
4071
    internal_a.magic = LYNXCOFFMAGIC;
4072
#elif defined AMD64
4073
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR64_MAGIC;
4074
#else
4075
    internal_a.magic = ZMAGIC;
4076
#endif
4077
#endif /* I386 */
4078
4079
#if defined(IA64)
4080
#define __A_MAGIC_SET__
4081
    internal_a.magic = PE32PMAGIC;
4082
#endif /* IA64 */
4083
4084
#if defined(SPARC)
4085
#define __A_MAGIC_SET__
4086
#if defined(LYNXOS)
4087
    internal_a.magic = LYNXCOFFMAGIC;
4088
#endif /* LYNXOS */
4089
#endif /* SPARC */
4090
4091
#ifdef RS6000COFF_C
4092
#define __A_MAGIC_SET__
4093
    internal_a.magic = (abfd->flags & D_PAGED) ? RS6K_AOUTHDR_ZMAGIC :
4094
    (abfd->flags & WP_TEXT) ? RS6K_AOUTHDR_NMAGIC :
4095
    RS6K_AOUTHDR_OMAGIC;
4096
#endif
4097
4098
#if defined(SH) && defined(COFF_WITH_PE)
4099
#define __A_MAGIC_SET__
4100
    internal_a.magic = SH_PE_MAGIC;
4101
#endif
4102
4103
#if defined(MIPS) && defined(COFF_WITH_PE)
4104
#define __A_MAGIC_SET__
4105
    internal_a.magic = MIPS_PE_MAGIC;
4106
#endif
4107
4108
#ifndef __A_MAGIC_SET__
4109
#include "Your aouthdr magic number is not being set!"
4110
#else
4111
1
#undef __A_MAGIC_SET__
4112
1
#endif
4113
1
  }
4114
4115
#ifdef RS6000COFF_C
4116
  /* XCOFF 32bit needs this to have new behaviour for n_type field.  */
4117
  internal_a.vstamp = 2;
4118
#else
4119
  /* FIXME: Does anybody ever set this to another value?  */
4120
1
  internal_a.vstamp = 0;
4121
1
#endif
4122
4123
  /* Now should write relocs, strings, syms.  */
4124
1
  obj_sym_filepos (abfd) = sym_base;
4125
4126
1
  if (bfd_get_symcount (abfd) != 0)
4127
0
    {
4128
0
      int firstundef;
4129
4130
0
      if (!coff_renumber_symbols (abfd, &firstundef))
4131
0
  return false;
4132
0
      coff_mangle_symbols (abfd);
4133
0
      if (! coff_write_symbols (abfd))
4134
0
  return false;
4135
0
      if (! coff_write_linenumbers (abfd))
4136
0
  return false;
4137
0
      if (! coff_write_relocs (abfd, firstundef))
4138
0
  return false;
4139
0
    }
4140
1
#ifdef COFF_LONG_SECTION_NAMES
4141
1
  else if (long_section_names && ! obj_coff_strings_written (abfd))
4142
0
    {
4143
      /* If we have long section names we have to write out the string
4144
   table even if there are no symbols.  */
4145
0
      if (! coff_write_symbols (abfd))
4146
0
  return false;
4147
0
    }
4148
1
#endif
4149
  /* If bfd_get_symcount (abfd) != 0, then we are not using the COFF
4150
     backend linker, and obj_raw_syment_count is not valid until after
4151
     coff_write_symbols is called.  */
4152
1
  if (obj_raw_syment_count (abfd) != 0)
4153
0
    {
4154
0
      internal_f.f_symptr = sym_base;
4155
#ifdef RS6000COFF_C
4156
      /* AIX appears to require that F_RELFLG not be set if there are
4157
   local symbols but no relocations.  */
4158
      internal_f.f_flags &=~ F_RELFLG;
4159
#endif
4160
0
    }
4161
1
  else
4162
1
    {
4163
1
      if (long_section_names)
4164
0
  internal_f.f_symptr = sym_base;
4165
1
      else
4166
1
  internal_f.f_symptr = 0;
4167
1
      internal_f.f_flags |= F_LSYMS;
4168
1
    }
4169
4170
1
  if (text_sec)
4171
0
    {
4172
0
      internal_a.tsize = text_sec->size;
4173
0
      internal_a.text_start = internal_a.tsize ? text_sec->vma : 0;
4174
0
    }
4175
1
  if (data_sec)
4176
0
    {
4177
0
      internal_a.dsize = data_sec->size;
4178
0
      internal_a.data_start = internal_a.dsize ? data_sec->vma : 0;
4179
0
    }
4180
1
  if (bss_sec)
4181
0
    {
4182
0
      internal_a.bsize = bss_sec->size;
4183
0
      if (internal_a.bsize && bss_sec->vma < internal_a.data_start)
4184
0
  internal_a.data_start = bss_sec->vma;
4185
0
    }
4186
4187
1
  internal_a.entry = bfd_get_start_address (abfd);
4188
1
  internal_f.f_nsyms = obj_raw_syment_count (abfd);
4189
4190
#ifdef RS6000COFF_C
4191
  if (xcoff_data (abfd)->full_aouthdr)
4192
    {
4193
      bfd_vma toc;
4194
      asection *loader_sec;
4195
4196
      internal_a.vstamp = 2;
4197
4198
      internal_a.o_snentry = xcoff_data (abfd)->snentry;
4199
      if (internal_a.o_snentry == 0)
4200
  internal_a.entry = (bfd_vma) -1;
4201
4202
      if (text_sec != NULL)
4203
  {
4204
    internal_a.o_sntext = text_sec->target_index;
4205
    internal_a.o_algntext = bfd_section_alignment (text_sec);
4206
  }
4207
      else
4208
  {
4209
    internal_a.o_sntext = 0;
4210
    internal_a.o_algntext = 0;
4211
  }
4212
      if (data_sec != NULL)
4213
  {
4214
    internal_a.o_sndata = data_sec->target_index;
4215
    internal_a.o_algndata = bfd_section_alignment (data_sec);
4216
  }
4217
      else
4218
  {
4219
    internal_a.o_sndata = 0;
4220
    internal_a.o_algndata = 0;
4221
  }
4222
      loader_sec = bfd_get_section_by_name (abfd, ".loader");
4223
      if (loader_sec != NULL)
4224
  internal_a.o_snloader = loader_sec->target_index;
4225
      else
4226
  internal_a.o_snloader = 0;
4227
      if (bss_sec != NULL)
4228
  internal_a.o_snbss = bss_sec->target_index;
4229
      else
4230
  internal_a.o_snbss = 0;
4231
4232
      if (tdata_sec != NULL)
4233
  {
4234
    internal_a.o_sntdata = tdata_sec->target_index;
4235
    /* TODO: o_flags should be set to RS6K_AOUTHDR_TLS_LE
4236
       if there is at least one R_TLS_LE relocations.  */
4237
    internal_a.o_flags = 0;
4238
#ifdef XCOFF64
4239
    internal_a.o_x64flags = 0;
4240
#endif
4241
  }
4242
      else
4243
  {
4244
    internal_a.o_sntdata = 0;
4245
    internal_a.o_flags = 0;
4246
#ifdef XCOFF64
4247
    internal_a.o_x64flags = 0;
4248
#endif
4249
  }
4250
      if (tbss_sec != NULL)
4251
    internal_a.o_sntbss = tbss_sec->target_index;
4252
      else
4253
    internal_a.o_sntbss = 0;
4254
4255
      toc = xcoff_data (abfd)->toc;
4256
      internal_a.o_toc = toc;
4257
      internal_a.o_sntoc = xcoff_data (abfd)->sntoc;
4258
4259
      internal_a.o_modtype = xcoff_data (abfd)->modtype;
4260
      if (xcoff_data (abfd)->cputype != -1)
4261
  internal_a.o_cputype = xcoff_data (abfd)->cputype;
4262
      else
4263
  {
4264
    switch (bfd_get_arch (abfd))
4265
      {
4266
      case bfd_arch_rs6000:
4267
        internal_a.o_cputype = 4;
4268
        break;
4269
      case bfd_arch_powerpc:
4270
        if (bfd_get_mach (abfd) == bfd_mach_ppc)
4271
    internal_a.o_cputype = 3;
4272
        else if (bfd_get_mach (abfd) == bfd_mach_ppc_620)
4273
    internal_a.o_cputype = 2;
4274
        else
4275
    internal_a.o_cputype = 1;
4276
        break;
4277
      default:
4278
        abort ();
4279
      }
4280
  }
4281
      internal_a.o_maxstack = xcoff_data (abfd)->maxstack;
4282
      internal_a.o_maxdata = xcoff_data (abfd)->maxdata;
4283
    }
4284
#endif
4285
4286
1
#ifdef COFF_WITH_PE
4287
1
  {
4288
    /* After object contents are finalized so we can compute a reasonable hash,
4289
       but before header is written so we can update it to point to debug directory.  */
4290
1
    struct pe_tdata *pe = pe_data (abfd);
4291
4292
1
    if (pe->build_id.after_write_object_contents != NULL)
4293
0
      (*pe->build_id.after_write_object_contents) (abfd);
4294
1
  }
4295
1
#endif
4296
4297
  /* Now write header.  */
4298
1
  if (bfd_seek (abfd, 0, SEEK_SET) != 0)
4299
0
    return false;
4300
4301
1
  {
4302
1
    char * buff;
4303
1
    bfd_size_type amount = bfd_coff_filhsz (abfd);
4304
4305
1
    buff = (char *) bfd_malloc (amount);
4306
1
    if (buff == NULL)
4307
0
      return false;
4308
4309
1
    bfd_coff_swap_filehdr_out (abfd, & internal_f, buff);
4310
1
    amount = bfd_write (buff, amount, abfd);
4311
4312
1
    free (buff);
4313
4314
1
    if (amount != bfd_coff_filhsz (abfd))
4315
0
      return false;
4316
1
  }
4317
4318
1
  if (abfd->flags & EXEC_P)
4319
0
    {
4320
      /* Note that peicode.h fills in a PEAOUTHDR, not an AOUTHDR.
4321
   include/coff/pe.h sets AOUTSZ == sizeof (PEAOUTHDR)).  */
4322
0
      char * buff;
4323
0
      bfd_size_type amount = bfd_coff_aoutsz (abfd);
4324
4325
0
      buff = (char *) bfd_malloc (amount);
4326
0
      if (buff == NULL)
4327
0
  return false;
4328
4329
0
      coff_swap_aouthdr_out (abfd, & internal_a, buff);
4330
0
      amount = bfd_write (buff, amount, abfd);
4331
4332
0
      free (buff);
4333
4334
0
      if (amount != bfd_coff_aoutsz (abfd))
4335
0
  return false;
4336
4337
0
#ifdef COFF_IMAGE_WITH_PE
4338
0
      if (! coff_apply_checksum (abfd))
4339
0
  return false;
4340
0
#endif
4341
0
    }
4342
#ifdef RS6000COFF_C
4343
#ifndef XCOFF64
4344
  else
4345
    {
4346
      AOUTHDR buff;
4347
      size_t size;
4348
4349
      /* XCOFF32 seems to always write at least a small a.out header.  */
4350
      coff_swap_aouthdr_out (abfd, & internal_a, & buff);
4351
      if (xcoff_data (abfd)->full_aouthdr)
4352
  size = bfd_coff_aoutsz (abfd);
4353
      else
4354
  size = SMALL_AOUTSZ;
4355
      if (bfd_write (&buff, size, abfd) != size)
4356
  return false;
4357
    }
4358
#endif
4359
#endif
4360
4361
1
  return true;
4362
1
}
Unexecuted instantiation: pei-arm.c:coff_write_object_contents
Unexecuted instantiation: pei-mcore.c:coff_write_object_contents
pei-sh.c:coff_write_object_contents
Line
Count
Source
3486
1
{
3487
1
  asection *current;
3488
1
  bool hasrelocs = false;
3489
1
  bool haslinno = false;
3490
1
#ifdef COFF_IMAGE_WITH_PE
3491
1
  bool hasdebug = false;
3492
1
#endif
3493
1
  file_ptr scn_base;
3494
1
  file_ptr reloc_base;
3495
1
  file_ptr lineno_base;
3496
1
  file_ptr sym_base;
3497
1
  unsigned long reloc_size = 0, reloc_count = 0;
3498
1
  unsigned long lnno_size = 0;
3499
1
  bool long_section_names;
3500
1
  asection *text_sec = NULL;
3501
1
  asection *data_sec = NULL;
3502
1
  asection *bss_sec = NULL;
3503
#ifdef RS6000COFF_C
3504
  asection *tdata_sec = NULL;
3505
  asection *tbss_sec = NULL;
3506
#endif
3507
1
  struct internal_filehdr internal_f;
3508
1
  struct internal_aouthdr internal_a;
3509
1
#ifdef COFF_LONG_SECTION_NAMES
3510
1
  size_t string_size = STRING_SIZE_SIZE;
3511
1
#endif
3512
3513
1
  bfd_set_error (bfd_error_system_call);
3514
3515
  /* Make a pass through the symbol table to count line number entries and
3516
     put them into the correct asections.  */
3517
1
  lnno_size = coff_count_linenumbers (abfd) * bfd_coff_linesz (abfd);
3518
3519
1
  if (! abfd->output_has_begun)
3520
1
    {
3521
1
      if (! coff_compute_section_file_positions (abfd))
3522
0
  return false;
3523
1
    }
3524
3525
1
  reloc_base = obj_relocbase (abfd);
3526
3527
  /* Work out the size of the reloc and linno areas.  */
3528
3529
1
  for (current = abfd->sections; current != NULL; current =
3530
0
       current->next)
3531
0
    {
3532
0
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3533
      /* We store the actual reloc count in the first reloc's addr.  */
3534
0
      if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3535
0
  reloc_count ++;
3536
0
#endif
3537
0
      reloc_count += current->reloc_count;
3538
0
    }
3539
3540
1
  reloc_size = reloc_count * bfd_coff_relsz (abfd);
3541
3542
1
  lineno_base = reloc_base + reloc_size;
3543
1
  sym_base = lineno_base + lnno_size;
3544
3545
  /* Indicate in each section->line_filepos its actual file address.  */
3546
1
  for (current = abfd->sections; current != NULL; current =
3547
0
       current->next)
3548
0
    {
3549
0
      if (current->lineno_count)
3550
0
  {
3551
0
    current->line_filepos = lineno_base;
3552
0
    current->moving_line_filepos = lineno_base;
3553
0
    lineno_base += current->lineno_count * bfd_coff_linesz (abfd);
3554
0
  }
3555
0
      else
3556
0
  current->line_filepos = 0;
3557
3558
0
      if (current->reloc_count)
3559
0
  {
3560
0
    current->rel_filepos = reloc_base;
3561
0
    reloc_base += current->reloc_count * bfd_coff_relsz (abfd);
3562
0
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3563
    /* Extra reloc to hold real count.  */
3564
0
    if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3565
0
      reloc_base += bfd_coff_relsz (abfd);
3566
0
#endif
3567
0
  }
3568
0
      else
3569
0
  current->rel_filepos = 0;
3570
0
    }
3571
3572
  /* Write section headers to the file.  */
3573
1
  internal_f.f_nscns = 0;
3574
3575
1
  if ((abfd->flags & EXEC_P) != 0)
3576
0
    scn_base = bfd_coff_filhsz (abfd) + bfd_coff_aoutsz (abfd);
3577
1
  else
3578
1
    {
3579
1
      scn_base = bfd_coff_filhsz (abfd);
3580
#ifdef RS6000COFF_C
3581
#ifndef XCOFF64
3582
      if (xcoff_data (abfd)->full_aouthdr)
3583
  scn_base += bfd_coff_aoutsz (abfd);
3584
      else
3585
  scn_base += SMALL_AOUTSZ;
3586
#endif
3587
#endif
3588
1
    }
3589
3590
1
  if (bfd_seek (abfd, scn_base, SEEK_SET) != 0)
3591
0
    return false;
3592
3593
1
  long_section_names = false;
3594
1
  for (current = abfd->sections;
3595
1
       current != NULL;
3596
1
       current = current->next)
3597
0
    {
3598
0
      struct internal_scnhdr section;
3599
0
#ifdef COFF_IMAGE_WITH_PE
3600
0
      bool is_reloc_section = false;
3601
3602
0
      if (strcmp (current->name, DOT_RELOC) == 0)
3603
0
  {
3604
0
    is_reloc_section = true;
3605
0
    hasrelocs = true;
3606
0
    pe_data (abfd)->has_reloc_section = 1;
3607
0
  }
3608
0
#endif
3609
3610
0
      internal_f.f_nscns++;
3611
3612
0
      strncpy (section.s_name, current->name, SCNNMLEN);
3613
3614
0
#ifdef COFF_LONG_SECTION_NAMES
3615
      /* Handle long section names as in PE.  This must be compatible
3616
   with the code in coff_write_symbols and _bfd_coff_final_link.  */
3617
0
      if (bfd_coff_long_section_names (abfd))
3618
0
  {
3619
0
    size_t len;
3620
3621
0
    len = strlen (current->name);
3622
0
    if (len > SCNNMLEN)
3623
0
      {
3624
3625
        /* An inherent limitation of the /nnnnnnn notation used to indicate
3626
     the offset of the long name in the string table is that we
3627
     cannot address entries beyone the ten million byte boundary.  */
3628
0
        if (string_size < 10000000)
3629
0
    {
3630
      /* The s_name field is defined to be NUL-padded but need not
3631
         be NUL-terminated.  We use a temporary buffer so that we
3632
         can still sprintf all eight chars without splatting a
3633
         terminating NUL over the first byte of the following
3634
         member (s_paddr).  */
3635
      /* PR 21096: The +20 is to stop a bogus warning from gcc7
3636
         about a possible buffer overflow.  */
3637
0
      char s_name_buf[SCNNMLEN + 1 + 20];
3638
3639
      /* We do not need to use snprintf here as we have already
3640
         verified that string_size is not too big, plus we have
3641
         an overlarge buffer, just in case.  */
3642
0
      sprintf (s_name_buf, "/%lu", (unsigned long) string_size);
3643
      /* Then strncpy takes care of any padding for us.  */
3644
0
      strncpy (section.s_name, s_name_buf, SCNNMLEN);
3645
0
    }
3646
0
        else
3647
0
#ifdef COFF_WITH_PE
3648
0
    {
3649
      /* PE use a base 64 encoding for long section names whose
3650
         index is very large.  But contrary to RFC 4648, there is
3651
         no padding: 6 characters must be generated.  */
3652
0
      static const char base64[] =
3653
0
        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
3654
0
        "abcdefghijklmnopqrstuvwxyz"
3655
0
        "0123456789+/";
3656
0
      unsigned long off = string_size;
3657
0
      unsigned i;
3658
3659
0
      section.s_name[0] = '/';
3660
0
      section.s_name[1] = '/';
3661
0
      for (i = SCNNMLEN - 1; i >= 2; i--)
3662
0
        {
3663
0
          section.s_name[i] = base64[off & 0x3f];
3664
0
          off >>= 6;
3665
0
        }
3666
0
    }
3667
0
#endif
3668
0
        if (string_size > 0xffffffffUL - (len + 1)
3669
#ifndef COFF_WITH_PE
3670
      || string_size >= 10000000
3671
#endif
3672
0
      )
3673
0
    {
3674
0
      bfd_set_error (bfd_error_file_too_big);
3675
0
      _bfd_error_handler
3676
        /* xgettext:c-format */
3677
0
        (_("%pB: section %pA: string table overflow at offset %ld"),
3678
0
        abfd, current, (unsigned long) string_size);
3679
0
      return false;
3680
0
    }
3681
3682
0
        string_size += len + 1;
3683
0
        long_section_names = true;
3684
0
      }
3685
0
  }
3686
0
#endif
3687
3688
0
#ifdef _LIB
3689
      /* Always set s_vaddr of .lib to 0.  This is right for SVR3.2
3690
   Ian Taylor <ian@cygnus.com>.  */
3691
0
      if (strcmp (current->name, _LIB) == 0)
3692
0
  section.s_vaddr = 0;
3693
0
      else
3694
0
#endif
3695
0
      section.s_vaddr = current->vma;
3696
0
      section.s_paddr = current->lma;
3697
0
      section.s_size =  current->size;
3698
#ifdef coff_get_section_load_page
3699
      section.s_page = coff_get_section_load_page (current);
3700
#else
3701
0
      section.s_page = 0;
3702
0
#endif
3703
3704
0
#ifdef COFF_WITH_PE
3705
0
      section.s_paddr = 0;
3706
0
#endif
3707
0
#ifdef COFF_IMAGE_WITH_PE
3708
      /* Reminder: s_paddr holds the virtual size of the section.  */
3709
0
      if (coff_section_data (abfd, current) != NULL
3710
0
    && pei_section_data (abfd, current) != NULL)
3711
0
  section.s_paddr = pei_section_data (abfd, current)->virt_size;
3712
0
      else
3713
0
  section.s_paddr = 0;
3714
0
#endif
3715
3716
      /* If this section has no size or is unloadable then the scnptr
3717
   will be 0 too.  */
3718
0
      if (current->size == 0
3719
0
    || (current->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
3720
0
  section.s_scnptr = 0;
3721
0
      else
3722
0
  section.s_scnptr = current->filepos;
3723
3724
0
      section.s_relptr = current->rel_filepos;
3725
0
      section.s_lnnoptr = current->line_filepos;
3726
0
      section.s_nreloc = current->reloc_count;
3727
0
      section.s_nlnno = current->lineno_count;
3728
#ifndef COFF_IMAGE_WITH_PE
3729
      /* In PEI, relocs come in the .reloc section.  */
3730
      if (current->reloc_count != 0)
3731
  hasrelocs = true;
3732
#endif
3733
0
      if (current->lineno_count != 0)
3734
0
  haslinno = true;
3735
0
#ifdef COFF_IMAGE_WITH_PE
3736
0
      if ((current->flags & SEC_DEBUGGING) != 0
3737
0
    && ! is_reloc_section)
3738
0
  hasdebug = true;
3739
0
#endif
3740
3741
#ifdef RS6000COFF_C
3742
#ifndef XCOFF64
3743
      /* Indicate the use of an XCOFF overflow section header.  */
3744
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3745
  {
3746
    section.s_nreloc = 0xffff;
3747
    section.s_nlnno = 0xffff;
3748
  }
3749
#endif
3750
#endif
3751
3752
0
      section.s_flags = sec_to_styp_flags (current->name, current->flags);
3753
3754
0
      if (!strcmp (current->name, _TEXT))
3755
0
  text_sec = current;
3756
0
      else if (!strcmp (current->name, _DATA))
3757
0
  data_sec = current;
3758
0
      else if (!strcmp (current->name, _BSS))
3759
0
  bss_sec = current;
3760
#ifdef RS6000COFF_C
3761
      else if (!strcmp (current->name, _TDATA))
3762
  tdata_sec = current;
3763
      else if (!strcmp (current->name, _TBSS))
3764
  tbss_sec = current;
3765
#endif
3766
3767
3768
0
#ifdef COFF_ENCODE_ALIGNMENT
3769
0
      if (COFF_ENCODE_ALIGNMENT (abfd, section, current->alignment_power)
3770
0
    && (COFF_DECODE_ALIGNMENT (section.s_flags)
3771
0
        != current->alignment_power))
3772
0
  {
3773
0
    bool warn = (coff_data (abfd)->link_info
3774
0
           && !bfd_link_relocatable (coff_data (abfd)->link_info));
3775
3776
0
    _bfd_error_handler
3777
      /* xgettext:c-format */
3778
0
      (_("%pB:%s section %s: alignment 2**%u not representable"),
3779
0
       abfd, warn ? " warning:" : "", current->name,
3780
0
       current->alignment_power);
3781
0
    if (!warn)
3782
0
      {
3783
0
        bfd_set_error (bfd_error_nonrepresentable_section);
3784
0
        return false;
3785
0
      }
3786
0
  }
3787
0
#endif
3788
3789
0
#ifdef COFF_IMAGE_WITH_PE
3790
      /* Suppress output of the sections if they are null.  ld
3791
   includes the bss and data sections even if there is no size
3792
   assigned to them.  NT loader doesn't like it if these section
3793
   headers are included if the sections themselves are not
3794
   needed.  See also coff_compute_section_file_positions.  */
3795
0
      if (section.s_size == 0)
3796
0
  internal_f.f_nscns--;
3797
0
      else
3798
0
#endif
3799
0
  {
3800
0
    SCNHDR buff;
3801
0
    bfd_size_type amt = bfd_coff_scnhsz (abfd);
3802
3803
0
    if (bfd_coff_swap_scnhdr_out (abfd, &section, &buff) == 0
3804
0
        || bfd_write (& buff, amt, abfd) != amt)
3805
0
      return false;
3806
0
  }
3807
3808
0
#ifdef COFF_WITH_PE
3809
      /* PE stores COMDAT section information in the symbol table.  If
3810
   this section is supposed to have some COMDAT info, track down
3811
   the symbol in the symbol table and modify it.  */
3812
0
      if ((current->flags & SEC_LINK_ONCE) != 0)
3813
0
  {
3814
0
    unsigned int i, count;
3815
0
    asymbol **psym;
3816
0
    coff_symbol_type *csym = NULL;
3817
0
    asymbol **psymsec;
3818
3819
0
    psymsec = NULL;
3820
0
    count = bfd_get_symcount (abfd);
3821
0
    for (i = 0, psym = abfd->outsymbols; i < count; i++, psym++)
3822
0
      {
3823
0
        if ((*psym)->section != current)
3824
0
    continue;
3825
3826
        /* Remember the location of the first symbol in this
3827
     section.  */
3828
0
        if (psymsec == NULL)
3829
0
    psymsec = psym;
3830
3831
        /* See if this is the section symbol.  */
3832
0
        if (strcmp ((*psym)->name, current->name) == 0)
3833
0
    {
3834
0
      csym = coff_symbol_from (*psym);
3835
0
      if (csym == NULL
3836
0
          || csym->native == NULL
3837
0
          || ! csym->native->is_sym
3838
0
          || csym->native->u.syment.n_numaux < 1
3839
0
          || csym->native->u.syment.n_sclass != C_STAT
3840
0
          || csym->native->u.syment.n_type != T_NULL)
3841
0
        continue;
3842
3843
      /* Here *PSYM is the section symbol for CURRENT.  */
3844
3845
0
      break;
3846
0
    }
3847
0
      }
3848
3849
    /* Did we find it?
3850
       Note that we might not if we're converting the file from
3851
       some other object file format.  */
3852
0
    if (i < count)
3853
0
      {
3854
0
        combined_entry_type *aux;
3855
3856
        /* We don't touch the x_checksum field.  The
3857
     x_associated field is not currently supported.  */
3858
3859
0
        aux = csym->native + 1;
3860
0
        BFD_ASSERT (! aux->is_sym);
3861
0
        switch (current->flags & SEC_LINK_DUPLICATES)
3862
0
    {
3863
0
    case SEC_LINK_DUPLICATES_DISCARD:
3864
0
      aux->u.auxent.x_scn.x_comdat = IMAGE_COMDAT_SELECT_ANY;
3865
0
      break;
3866
3867
0
    case SEC_LINK_DUPLICATES_ONE_ONLY:
3868
0
      aux->u.auxent.x_scn.x_comdat =
3869
0
        IMAGE_COMDAT_SELECT_NODUPLICATES;
3870
0
      break;
3871
3872
0
    case SEC_LINK_DUPLICATES_SAME_SIZE:
3873
0
      aux->u.auxent.x_scn.x_comdat =
3874
0
        IMAGE_COMDAT_SELECT_SAME_SIZE;
3875
0
      break;
3876
3877
0
    case SEC_LINK_DUPLICATES_SAME_CONTENTS:
3878
0
      aux->u.auxent.x_scn.x_comdat =
3879
0
        IMAGE_COMDAT_SELECT_EXACT_MATCH;
3880
0
      break;
3881
0
    }
3882
3883
        /* The COMDAT symbol must be the first symbol from this
3884
     section in the symbol table.  In order to make this
3885
     work, we move the COMDAT symbol before the first
3886
     symbol we found in the search above.  It's OK to
3887
     rearrange the symbol table at this point, because
3888
     coff_renumber_symbols is going to rearrange it
3889
     further and fix up all the aux entries.  */
3890
0
        if (psym != psymsec)
3891
0
    {
3892
0
      asymbol *hold;
3893
0
      asymbol **pcopy;
3894
3895
0
      hold = *psym;
3896
0
      for (pcopy = psym; pcopy > psymsec; pcopy--)
3897
0
        pcopy[0] = pcopy[-1];
3898
0
      *psymsec = hold;
3899
0
    }
3900
0
      }
3901
0
  }
3902
0
#endif /* COFF_WITH_PE */
3903
0
    }
3904
3905
#ifdef RS6000COFF_C
3906
#ifndef XCOFF64
3907
  /* XCOFF handles overflows in the reloc and line number count fields
3908
     by creating a new section header to hold the correct values.  */
3909
  for (current = abfd->sections; current != NULL; current = current->next)
3910
    {
3911
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3912
  {
3913
    struct internal_scnhdr scnhdr;
3914
    SCNHDR buff;
3915
    bfd_size_type amt;
3916
3917
    internal_f.f_nscns++;
3918
    memcpy (scnhdr.s_name, ".ovrflo", 8);
3919
    scnhdr.s_paddr = current->reloc_count;
3920
    scnhdr.s_vaddr = current->lineno_count;
3921
    scnhdr.s_size = 0;
3922
    scnhdr.s_scnptr = 0;
3923
    scnhdr.s_relptr = current->rel_filepos;
3924
    scnhdr.s_lnnoptr = current->line_filepos;
3925
    scnhdr.s_nreloc = current->target_index;
3926
    scnhdr.s_nlnno = current->target_index;
3927
    scnhdr.s_flags = STYP_OVRFLO;
3928
    amt = bfd_coff_scnhsz (abfd);
3929
    if (bfd_coff_swap_scnhdr_out (abfd, &scnhdr, &buff) == 0
3930
        || bfd_write (& buff, amt, abfd) != amt)
3931
      return false;
3932
  }
3933
    }
3934
#endif
3935
#endif
3936
3937
#if defined (COFF_GO32_EXE) || defined (COFF_GO32)
3938
  /* Pad section headers.  */
3939
  if ((abfd->flags & EXEC_P) != 0)
3940
    {
3941
      asection *s = abfd->sections;
3942
      while (s != NULL && s->filepos == 0)
3943
  s = s->next;
3944
      if (s != NULL)
3945
  {
3946
    file_ptr cur_ptr
3947
      = scn_base + abfd->section_count * bfd_coff_scnhsz (abfd);
3948
    file_ptr fill_size = s->filepos - cur_ptr;
3949
    if (fill_size > 0)
3950
      {
3951
        bfd_byte *b = bfd_zmalloc (fill_size);
3952
        if (!b)
3953
    return false;
3954
        if (bfd_write (b, fill_size, abfd) != (ufile_ptr) fill_size)
3955
    {
3956
      free (b);
3957
      return false;
3958
    }
3959
        free (b);
3960
      }
3961
  }
3962
    }
3963
#endif
3964
3965
  /* OK, now set up the filehdr...  */
3966
3967
  /* Don't include the internal abs section in the section count */
3968
3969
  /* We will NOT put a fucking timestamp in the header here. Every time you
3970
     put it back, I will come in and take it out again.  I'm sorry.  This
3971
     field does not belong here.  We fill it with a 0 so it compares the
3972
     same but is not a reasonable time. -- gnu@cygnus.com  */
3973
1
  internal_f.f_timdat = 0;
3974
1
  internal_f.f_flags = 0;
3975
3976
1
  if (abfd->flags & EXEC_P)
3977
0
    internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3978
1
  else
3979
1
    {
3980
1
      internal_f.f_opthdr = 0;
3981
#ifdef RS6000COFF_C
3982
#ifndef XCOFF64
3983
      if (xcoff_data (abfd)->full_aouthdr)
3984
  internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3985
      else
3986
  internal_f.f_opthdr = SMALL_AOUTSZ;
3987
#endif
3988
#endif
3989
1
    }
3990
3991
1
  if (!hasrelocs)
3992
1
    internal_f.f_flags |= F_RELFLG;
3993
1
  if (!haslinno)
3994
1
    internal_f.f_flags |= F_LNNO;
3995
1
  if (abfd->flags & EXEC_P)
3996
0
    internal_f.f_flags |= F_EXEC;
3997
1
#ifdef COFF_IMAGE_WITH_PE
3998
1
  if (! hasdebug)
3999
1
    internal_f.f_flags |= IMAGE_FILE_DEBUG_STRIPPED;
4000
1
  if (pe_data (abfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
4001
1
    internal_f.f_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
4002
1
#endif
4003
4004
1
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
4005
1
#ifdef COFF_WITH_PE
4006
1
  internal_f.f_flags |= IMAGE_FILE_32BIT_MACHINE;
4007
#else
4008
  if (bfd_little_endian (abfd))
4009
    internal_f.f_flags |= F_AR32WR;
4010
  else
4011
    internal_f.f_flags |= F_AR32W;
4012
#endif
4013
1
#endif
4014
4015
#ifdef TI_TARGET_ID
4016
  /* Target id is used in TI COFF v1 and later; COFF0 won't use this field,
4017
     but it doesn't hurt to set it internally.  */
4018
  internal_f.f_target_id = TI_TARGET_ID;
4019
#endif
4020
4021
  /* FIXME, should do something about the other byte orders and
4022
     architectures.  */
4023
4024
#ifdef RS6000COFF_C
4025
  if ((abfd->flags & DYNAMIC) != 0)
4026
    internal_f.f_flags |= F_SHROBJ;
4027
  if (bfd_get_section_by_name (abfd, _LOADER) != NULL)
4028
    internal_f.f_flags |= F_DYNLOAD;
4029
#endif
4030
4031
1
  memset (&internal_a, 0, sizeof internal_a);
4032
4033
  /* Set up architecture-dependent stuff.  */
4034
1
  {
4035
1
    unsigned int magic = 0;
4036
1
    unsigned short flags = 0;
4037
4038
1
    coff_set_flags (abfd, &magic, &flags);
4039
1
    internal_f.f_magic = magic;
4040
1
    internal_f.f_flags |= flags;
4041
    /* ...and the "opt"hdr...  */
4042
4043
#ifdef TICOFF_AOUT_MAGIC
4044
    internal_a.magic = TICOFF_AOUT_MAGIC;
4045
#define __A_MAGIC_SET__
4046
#endif
4047
4048
#if defined(ARM)
4049
#define __A_MAGIC_SET__
4050
    internal_a.magic = ZMAGIC;
4051
#endif
4052
4053
#if defined(AARCH64)
4054
#define __A_MAGIC_SET__
4055
    internal_a.magic = ZMAGIC;
4056
#endif
4057
4058
#if defined(LOONGARCH64)
4059
#define __A_MAGIC_SET__
4060
    internal_a.magic = ZMAGIC;
4061
#endif
4062
4063
#if defined MCORE_PE
4064
#define __A_MAGIC_SET__
4065
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR_MAGIC;
4066
#endif
4067
4068
#if defined(I386)
4069
#define __A_MAGIC_SET__
4070
#if defined LYNXOS
4071
    internal_a.magic = LYNXCOFFMAGIC;
4072
#elif defined AMD64
4073
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR64_MAGIC;
4074
#else
4075
    internal_a.magic = ZMAGIC;
4076
#endif
4077
#endif /* I386 */
4078
4079
#if defined(IA64)
4080
#define __A_MAGIC_SET__
4081
    internal_a.magic = PE32PMAGIC;
4082
#endif /* IA64 */
4083
4084
#if defined(SPARC)
4085
#define __A_MAGIC_SET__
4086
#if defined(LYNXOS)
4087
    internal_a.magic = LYNXCOFFMAGIC;
4088
#endif /* LYNXOS */
4089
#endif /* SPARC */
4090
4091
#ifdef RS6000COFF_C
4092
#define __A_MAGIC_SET__
4093
    internal_a.magic = (abfd->flags & D_PAGED) ? RS6K_AOUTHDR_ZMAGIC :
4094
    (abfd->flags & WP_TEXT) ? RS6K_AOUTHDR_NMAGIC :
4095
    RS6K_AOUTHDR_OMAGIC;
4096
#endif
4097
4098
1
#if defined(SH) && defined(COFF_WITH_PE)
4099
1
#define __A_MAGIC_SET__
4100
1
    internal_a.magic = SH_PE_MAGIC;
4101
1
#endif
4102
4103
#if defined(MIPS) && defined(COFF_WITH_PE)
4104
#define __A_MAGIC_SET__
4105
    internal_a.magic = MIPS_PE_MAGIC;
4106
#endif
4107
4108
#ifndef __A_MAGIC_SET__
4109
#include "Your aouthdr magic number is not being set!"
4110
#else
4111
1
#undef __A_MAGIC_SET__
4112
1
#endif
4113
1
  }
4114
4115
#ifdef RS6000COFF_C
4116
  /* XCOFF 32bit needs this to have new behaviour for n_type field.  */
4117
  internal_a.vstamp = 2;
4118
#else
4119
  /* FIXME: Does anybody ever set this to another value?  */
4120
1
  internal_a.vstamp = 0;
4121
1
#endif
4122
4123
  /* Now should write relocs, strings, syms.  */
4124
1
  obj_sym_filepos (abfd) = sym_base;
4125
4126
1
  if (bfd_get_symcount (abfd) != 0)
4127
0
    {
4128
0
      int firstundef;
4129
4130
0
      if (!coff_renumber_symbols (abfd, &firstundef))
4131
0
  return false;
4132
0
      coff_mangle_symbols (abfd);
4133
0
      if (! coff_write_symbols (abfd))
4134
0
  return false;
4135
0
      if (! coff_write_linenumbers (abfd))
4136
0
  return false;
4137
0
      if (! coff_write_relocs (abfd, firstundef))
4138
0
  return false;
4139
0
    }
4140
1
#ifdef COFF_LONG_SECTION_NAMES
4141
1
  else if (long_section_names && ! obj_coff_strings_written (abfd))
4142
0
    {
4143
      /* If we have long section names we have to write out the string
4144
   table even if there are no symbols.  */
4145
0
      if (! coff_write_symbols (abfd))
4146
0
  return false;
4147
0
    }
4148
1
#endif
4149
  /* If bfd_get_symcount (abfd) != 0, then we are not using the COFF
4150
     backend linker, and obj_raw_syment_count is not valid until after
4151
     coff_write_symbols is called.  */
4152
1
  if (obj_raw_syment_count (abfd) != 0)
4153
0
    {
4154
0
      internal_f.f_symptr = sym_base;
4155
#ifdef RS6000COFF_C
4156
      /* AIX appears to require that F_RELFLG not be set if there are
4157
   local symbols but no relocations.  */
4158
      internal_f.f_flags &=~ F_RELFLG;
4159
#endif
4160
0
    }
4161
1
  else
4162
1
    {
4163
1
      if (long_section_names)
4164
0
  internal_f.f_symptr = sym_base;
4165
1
      else
4166
1
  internal_f.f_symptr = 0;
4167
1
      internal_f.f_flags |= F_LSYMS;
4168
1
    }
4169
4170
1
  if (text_sec)
4171
0
    {
4172
0
      internal_a.tsize = text_sec->size;
4173
0
      internal_a.text_start = internal_a.tsize ? text_sec->vma : 0;
4174
0
    }
4175
1
  if (data_sec)
4176
0
    {
4177
0
      internal_a.dsize = data_sec->size;
4178
0
      internal_a.data_start = internal_a.dsize ? data_sec->vma : 0;
4179
0
    }
4180
1
  if (bss_sec)
4181
0
    {
4182
0
      internal_a.bsize = bss_sec->size;
4183
0
      if (internal_a.bsize && bss_sec->vma < internal_a.data_start)
4184
0
  internal_a.data_start = bss_sec->vma;
4185
0
    }
4186
4187
1
  internal_a.entry = bfd_get_start_address (abfd);
4188
1
  internal_f.f_nsyms = obj_raw_syment_count (abfd);
4189
4190
#ifdef RS6000COFF_C
4191
  if (xcoff_data (abfd)->full_aouthdr)
4192
    {
4193
      bfd_vma toc;
4194
      asection *loader_sec;
4195
4196
      internal_a.vstamp = 2;
4197
4198
      internal_a.o_snentry = xcoff_data (abfd)->snentry;
4199
      if (internal_a.o_snentry == 0)
4200
  internal_a.entry = (bfd_vma) -1;
4201
4202
      if (text_sec != NULL)
4203
  {
4204
    internal_a.o_sntext = text_sec->target_index;
4205
    internal_a.o_algntext = bfd_section_alignment (text_sec);
4206
  }
4207
      else
4208
  {
4209
    internal_a.o_sntext = 0;
4210
    internal_a.o_algntext = 0;
4211
  }
4212
      if (data_sec != NULL)
4213
  {
4214
    internal_a.o_sndata = data_sec->target_index;
4215
    internal_a.o_algndata = bfd_section_alignment (data_sec);
4216
  }
4217
      else
4218
  {
4219
    internal_a.o_sndata = 0;
4220
    internal_a.o_algndata = 0;
4221
  }
4222
      loader_sec = bfd_get_section_by_name (abfd, ".loader");
4223
      if (loader_sec != NULL)
4224
  internal_a.o_snloader = loader_sec->target_index;
4225
      else
4226
  internal_a.o_snloader = 0;
4227
      if (bss_sec != NULL)
4228
  internal_a.o_snbss = bss_sec->target_index;
4229
      else
4230
  internal_a.o_snbss = 0;
4231
4232
      if (tdata_sec != NULL)
4233
  {
4234
    internal_a.o_sntdata = tdata_sec->target_index;
4235
    /* TODO: o_flags should be set to RS6K_AOUTHDR_TLS_LE
4236
       if there is at least one R_TLS_LE relocations.  */
4237
    internal_a.o_flags = 0;
4238
#ifdef XCOFF64
4239
    internal_a.o_x64flags = 0;
4240
#endif
4241
  }
4242
      else
4243
  {
4244
    internal_a.o_sntdata = 0;
4245
    internal_a.o_flags = 0;
4246
#ifdef XCOFF64
4247
    internal_a.o_x64flags = 0;
4248
#endif
4249
  }
4250
      if (tbss_sec != NULL)
4251
    internal_a.o_sntbss = tbss_sec->target_index;
4252
      else
4253
    internal_a.o_sntbss = 0;
4254
4255
      toc = xcoff_data (abfd)->toc;
4256
      internal_a.o_toc = toc;
4257
      internal_a.o_sntoc = xcoff_data (abfd)->sntoc;
4258
4259
      internal_a.o_modtype = xcoff_data (abfd)->modtype;
4260
      if (xcoff_data (abfd)->cputype != -1)
4261
  internal_a.o_cputype = xcoff_data (abfd)->cputype;
4262
      else
4263
  {
4264
    switch (bfd_get_arch (abfd))
4265
      {
4266
      case bfd_arch_rs6000:
4267
        internal_a.o_cputype = 4;
4268
        break;
4269
      case bfd_arch_powerpc:
4270
        if (bfd_get_mach (abfd) == bfd_mach_ppc)
4271
    internal_a.o_cputype = 3;
4272
        else if (bfd_get_mach (abfd) == bfd_mach_ppc_620)
4273
    internal_a.o_cputype = 2;
4274
        else
4275
    internal_a.o_cputype = 1;
4276
        break;
4277
      default:
4278
        abort ();
4279
      }
4280
  }
4281
      internal_a.o_maxstack = xcoff_data (abfd)->maxstack;
4282
      internal_a.o_maxdata = xcoff_data (abfd)->maxdata;
4283
    }
4284
#endif
4285
4286
1
#ifdef COFF_WITH_PE
4287
1
  {
4288
    /* After object contents are finalized so we can compute a reasonable hash,
4289
       but before header is written so we can update it to point to debug directory.  */
4290
1
    struct pe_tdata *pe = pe_data (abfd);
4291
4292
1
    if (pe->build_id.after_write_object_contents != NULL)
4293
0
      (*pe->build_id.after_write_object_contents) (abfd);
4294
1
  }
4295
1
#endif
4296
4297
  /* Now write header.  */
4298
1
  if (bfd_seek (abfd, 0, SEEK_SET) != 0)
4299
0
    return false;
4300
4301
1
  {
4302
1
    char * buff;
4303
1
    bfd_size_type amount = bfd_coff_filhsz (abfd);
4304
4305
1
    buff = (char *) bfd_malloc (amount);
4306
1
    if (buff == NULL)
4307
0
      return false;
4308
4309
1
    bfd_coff_swap_filehdr_out (abfd, & internal_f, buff);
4310
1
    amount = bfd_write (buff, amount, abfd);
4311
4312
1
    free (buff);
4313
4314
1
    if (amount != bfd_coff_filhsz (abfd))
4315
0
      return false;
4316
1
  }
4317
4318
1
  if (abfd->flags & EXEC_P)
4319
0
    {
4320
      /* Note that peicode.h fills in a PEAOUTHDR, not an AOUTHDR.
4321
   include/coff/pe.h sets AOUTSZ == sizeof (PEAOUTHDR)).  */
4322
0
      char * buff;
4323
0
      bfd_size_type amount = bfd_coff_aoutsz (abfd);
4324
4325
0
      buff = (char *) bfd_malloc (amount);
4326
0
      if (buff == NULL)
4327
0
  return false;
4328
4329
0
      coff_swap_aouthdr_out (abfd, & internal_a, buff);
4330
0
      amount = bfd_write (buff, amount, abfd);
4331
4332
0
      free (buff);
4333
4334
0
      if (amount != bfd_coff_aoutsz (abfd))
4335
0
  return false;
4336
4337
0
#ifdef COFF_IMAGE_WITH_PE
4338
0
      if (! coff_apply_checksum (abfd))
4339
0
  return false;
4340
0
#endif
4341
0
    }
4342
#ifdef RS6000COFF_C
4343
#ifndef XCOFF64
4344
  else
4345
    {
4346
      AOUTHDR buff;
4347
      size_t size;
4348
4349
      /* XCOFF32 seems to always write at least a small a.out header.  */
4350
      coff_swap_aouthdr_out (abfd, & internal_a, & buff);
4351
      if (xcoff_data (abfd)->full_aouthdr)
4352
  size = bfd_coff_aoutsz (abfd);
4353
      else
4354
  size = SMALL_AOUTSZ;
4355
      if (bfd_write (&buff, size, abfd) != size)
4356
  return false;
4357
    }
4358
#endif
4359
#endif
4360
4361
1
  return true;
4362
1
}
4363
4364
static bool
4365
coff_set_section_contents (bfd * abfd,
4366
         sec_ptr section,
4367
         const void * location,
4368
         file_ptr offset,
4369
         bfd_size_type count)
4370
101
{
4371
101
  if (! abfd->output_has_begun)  /* Set by bfd.c handler.  */
4372
16
    {
4373
16
      if (! coff_compute_section_file_positions (abfd))
4374
0
  return false;
4375
16
    }
4376
4377
#if defined(_LIB) && !defined(TARG_AUX)
4378
   /* The physical address field of a .lib section is used to hold the
4379
      number of shared libraries in the section.  This code counts the
4380
      number of sections being written, and increments the lma field
4381
      with the number.
4382
4383
      I have found no documentation on the contents of this section.
4384
      Experimentation indicates that the section contains zero or more
4385
      records, each of which has the following structure:
4386
4387
      - a (four byte) word holding the length of this record, in words,
4388
      - a word that always seems to be set to "2",
4389
      - the path to a shared library, null-terminated and then padded
4390
  to a whole word boundary.
4391
4392
      bfd_assert calls have been added to alert if an attempt is made
4393
      to write a section which doesn't follow these assumptions.  The
4394
      code has been tested on ISC 4.1 by me, and on SCO by Robert Lipe
4395
      <robertl@arnet.com> (Thanks!).
4396
4397
      Gvran Uddeborg <gvran@uddeborg.pp.se>.  */
4398
101
    if (strcmp (section->name, _LIB) == 0)
4399
0
      {
4400
0
  bfd_byte *rec, *recend;
4401
4402
  rec = (bfd_byte *) location;
4403
  recend = rec + count;
4404
0
  while (recend - rec >= 4)
4405
0
    {
4406
0
      size_t len = bfd_get_32 (abfd, rec);
4407
0
      if (len == 0 || len > (size_t) (recend - rec) / 4)
4408
0
        break;
4409
0
      rec += len * 4;
4410
0
      ++section->lma;
4411
0
    }
4412
4413
0
  BFD_ASSERT (rec == recend);
4414
0
      }
4415
101
#endif
4416
4417
  /* Don't write out bss sections - one way to do this is to
4418
       see if the filepos has not been set.  */
4419
101
  if (section->filepos == 0)
4420
0
    return true;
4421
4422
101
  if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0)
4423
0
    return false;
4424
4425
101
  if (count == 0)
4426
0
    return true;
4427
4428
101
  return bfd_write (location, count, abfd) == count;
4429
101
}
pei-i386.c:coff_set_section_contents
Line
Count
Source
4370
14
{
4371
14
  if (! abfd->output_has_begun)  /* Set by bfd.c handler.  */
4372
2
    {
4373
2
      if (! coff_compute_section_file_positions (abfd))
4374
0
  return false;
4375
2
    }
4376
4377
14
#if defined(_LIB) && !defined(TARG_AUX)
4378
   /* The physical address field of a .lib section is used to hold the
4379
      number of shared libraries in the section.  This code counts the
4380
      number of sections being written, and increments the lma field
4381
      with the number.
4382
4383
      I have found no documentation on the contents of this section.
4384
      Experimentation indicates that the section contains zero or more
4385
      records, each of which has the following structure:
4386
4387
      - a (four byte) word holding the length of this record, in words,
4388
      - a word that always seems to be set to "2",
4389
      - the path to a shared library, null-terminated and then padded
4390
  to a whole word boundary.
4391
4392
      bfd_assert calls have been added to alert if an attempt is made
4393
      to write a section which doesn't follow these assumptions.  The
4394
      code has been tested on ISC 4.1 by me, and on SCO by Robert Lipe
4395
      <robertl@arnet.com> (Thanks!).
4396
4397
      Gvran Uddeborg <gvran@uddeborg.pp.se>.  */
4398
14
    if (strcmp (section->name, _LIB) == 0)
4399
0
      {
4400
0
  bfd_byte *rec, *recend;
4401
4402
0
  rec = (bfd_byte *) location;
4403
0
  recend = rec + count;
4404
0
  while (recend - rec >= 4)
4405
0
    {
4406
0
      size_t len = bfd_get_32 (abfd, rec);
4407
0
      if (len == 0 || len > (size_t) (recend - rec) / 4)
4408
0
        break;
4409
0
      rec += len * 4;
4410
0
      ++section->lma;
4411
0
    }
4412
4413
0
  BFD_ASSERT (rec == recend);
4414
0
      }
4415
14
#endif
4416
4417
  /* Don't write out bss sections - one way to do this is to
4418
       see if the filepos has not been set.  */
4419
14
  if (section->filepos == 0)
4420
0
    return true;
4421
4422
14
  if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0)
4423
0
    return false;
4424
4425
14
  if (count == 0)
4426
0
    return true;
4427
4428
14
  return bfd_write (location, count, abfd) == count;
4429
14
}
Unexecuted instantiation: pe-x86_64.c:coff_set_section_contents
pei-x86_64.c:coff_set_section_contents
Line
Count
Source
4370
75
{
4371
75
  if (! abfd->output_has_begun)  /* Set by bfd.c handler.  */
4372
6
    {
4373
6
      if (! coff_compute_section_file_positions (abfd))
4374
0
  return false;
4375
6
    }
4376
4377
75
#if defined(_LIB) && !defined(TARG_AUX)
4378
   /* The physical address field of a .lib section is used to hold the
4379
      number of shared libraries in the section.  This code counts the
4380
      number of sections being written, and increments the lma field
4381
      with the number.
4382
4383
      I have found no documentation on the contents of this section.
4384
      Experimentation indicates that the section contains zero or more
4385
      records, each of which has the following structure:
4386
4387
      - a (four byte) word holding the length of this record, in words,
4388
      - a word that always seems to be set to "2",
4389
      - the path to a shared library, null-terminated and then padded
4390
  to a whole word boundary.
4391
4392
      bfd_assert calls have been added to alert if an attempt is made
4393
      to write a section which doesn't follow these assumptions.  The
4394
      code has been tested on ISC 4.1 by me, and on SCO by Robert Lipe
4395
      <robertl@arnet.com> (Thanks!).
4396
4397
      Gvran Uddeborg <gvran@uddeborg.pp.se>.  */
4398
75
    if (strcmp (section->name, _LIB) == 0)
4399
0
      {
4400
0
  bfd_byte *rec, *recend;
4401
4402
0
  rec = (bfd_byte *) location;
4403
0
  recend = rec + count;
4404
0
  while (recend - rec >= 4)
4405
0
    {
4406
0
      size_t len = bfd_get_32 (abfd, rec);
4407
0
      if (len == 0 || len > (size_t) (recend - rec) / 4)
4408
0
        break;
4409
0
      rec += len * 4;
4410
0
      ++section->lma;
4411
0
    }
4412
4413
0
  BFD_ASSERT (rec == recend);
4414
0
      }
4415
75
#endif
4416
4417
  /* Don't write out bss sections - one way to do this is to
4418
       see if the filepos has not been set.  */
4419
75
  if (section->filepos == 0)
4420
0
    return true;
4421
4422
75
  if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0)
4423
0
    return false;
4424
4425
75
  if (count == 0)
4426
0
    return true;
4427
4428
75
  return bfd_write (location, count, abfd) == count;
4429
75
}
Unexecuted instantiation: coff-x86_64.c:coff_set_section_contents
Unexecuted instantiation: coff64-rs6000.c:coff_set_section_contents
Unexecuted instantiation: pe-aarch64.c:coff_set_section_contents
pei-aarch64.c:coff_set_section_contents
Line
Count
Source
4370
4
{
4371
4
  if (! abfd->output_has_begun)  /* Set by bfd.c handler.  */
4372
2
    {
4373
2
      if (! coff_compute_section_file_positions (abfd))
4374
0
  return false;
4375
2
    }
4376
4377
4
#if defined(_LIB) && !defined(TARG_AUX)
4378
   /* The physical address field of a .lib section is used to hold the
4379
      number of shared libraries in the section.  This code counts the
4380
      number of sections being written, and increments the lma field
4381
      with the number.
4382
4383
      I have found no documentation on the contents of this section.
4384
      Experimentation indicates that the section contains zero or more
4385
      records, each of which has the following structure:
4386
4387
      - a (four byte) word holding the length of this record, in words,
4388
      - a word that always seems to be set to "2",
4389
      - the path to a shared library, null-terminated and then padded
4390
  to a whole word boundary.
4391
4392
      bfd_assert calls have been added to alert if an attempt is made
4393
      to write a section which doesn't follow these assumptions.  The
4394
      code has been tested on ISC 4.1 by me, and on SCO by Robert Lipe
4395
      <robertl@arnet.com> (Thanks!).
4396
4397
      Gvran Uddeborg <gvran@uddeborg.pp.se>.  */
4398
4
    if (strcmp (section->name, _LIB) == 0)
4399
0
      {
4400
0
  bfd_byte *rec, *recend;
4401
4402
0
  rec = (bfd_byte *) location;
4403
0
  recend = rec + count;
4404
0
  while (recend - rec >= 4)
4405
0
    {
4406
0
      size_t len = bfd_get_32 (abfd, rec);
4407
0
      if (len == 0 || len > (size_t) (recend - rec) / 4)
4408
0
        break;
4409
0
      rec += len * 4;
4410
0
      ++section->lma;
4411
0
    }
4412
4413
0
  BFD_ASSERT (rec == recend);
4414
0
      }
4415
4
#endif
4416
4417
  /* Don't write out bss sections - one way to do this is to
4418
       see if the filepos has not been set.  */
4419
4
  if (section->filepos == 0)
4420
0
    return true;
4421
4422
4
  if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0)
4423
0
    return false;
4424
4425
4
  if (count == 0)
4426
0
    return true;
4427
4428
4
  return bfd_write (location, count, abfd) == count;
4429
4
}
Unexecuted instantiation: pei-ia64.c:coff_set_section_contents
Unexecuted instantiation: pei-loongarch64.c:coff_set_section_contents
Unexecuted instantiation: cf-i386lynx.c:coff_set_section_contents
Unexecuted instantiation: coff-go32.c:coff_set_section_contents
Unexecuted instantiation: coff-i386.c:coff_set_section_contents
Unexecuted instantiation: coff-rs6000.c:coff_set_section_contents
Unexecuted instantiation: coff-sh.c:coff_set_section_contents
Unexecuted instantiation: coff-stgo32.c:coff_set_section_contents
Unexecuted instantiation: coff-tic30.c:coff_set_section_contents
Unexecuted instantiation: coff-tic4x.c:coff_set_section_contents
Unexecuted instantiation: coff-tic54x.c:coff_set_section_contents
Unexecuted instantiation: coff-z80.c:coff_set_section_contents
coff-z8k.c:coff_set_section_contents
Line
Count
Source
4370
4
{
4371
4
  if (! abfd->output_has_begun) /* Set by bfd.c handler.  */
4372
4
    {
4373
4
      if (! coff_compute_section_file_positions (abfd))
4374
0
  return false;
4375
4
    }
4376
4377
4
#if defined(_LIB) && !defined(TARG_AUX)
4378
   /* The physical address field of a .lib section is used to hold the
4379
      number of shared libraries in the section.  This code counts the
4380
      number of sections being written, and increments the lma field
4381
      with the number.
4382
4383
      I have found no documentation on the contents of this section.
4384
      Experimentation indicates that the section contains zero or more
4385
      records, each of which has the following structure:
4386
4387
      - a (four byte) word holding the length of this record, in words,
4388
      - a word that always seems to be set to "2",
4389
      - the path to a shared library, null-terminated and then padded
4390
  to a whole word boundary.
4391
4392
      bfd_assert calls have been added to alert if an attempt is made
4393
      to write a section which doesn't follow these assumptions.  The
4394
      code has been tested on ISC 4.1 by me, and on SCO by Robert Lipe
4395
      <robertl@arnet.com> (Thanks!).
4396
4397
      Gvran Uddeborg <gvran@uddeborg.pp.se>.  */
4398
4
    if (strcmp (section->name, _LIB) == 0)
4399
0
      {
4400
0
  bfd_byte *rec, *recend;
4401
4402
0
  rec = (bfd_byte *) location;
4403
0
  recend = rec + count;
4404
0
  while (recend - rec >= 4)
4405
0
    {
4406
0
      size_t len = bfd_get_32 (abfd, rec);
4407
0
      if (len == 0 || len > (size_t) (recend - rec) / 4)
4408
0
        break;
4409
0
      rec += len * 4;
4410
0
      ++section->lma;
4411
0
    }
4412
4413
0
  BFD_ASSERT (rec == recend);
4414
0
      }
4415
4
#endif
4416
4417
  /* Don't write out bss sections - one way to do this is to
4418
       see if the filepos has not been set.  */
4419
4
  if (section->filepos == 0)
4420
0
    return true;
4421
4422
4
  if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0)
4423
0
    return false;
4424
4425
4
  if (count == 0)
4426
0
    return true;
4427
4428
4
  return bfd_write (location, count, abfd) == count;
4429
4
}
Unexecuted instantiation: pe-arm-wince.c:coff_set_section_contents
Unexecuted instantiation: pe-arm.c:coff_set_section_contents
pe-i386.c:coff_set_section_contents
Line
Count
Source
4370
2
{
4371
2
  if (! abfd->output_has_begun)  /* Set by bfd.c handler.  */
4372
1
    {
4373
1
      if (! coff_compute_section_file_positions (abfd))
4374
0
  return false;
4375
1
    }
4376
4377
2
#if defined(_LIB) && !defined(TARG_AUX)
4378
   /* The physical address field of a .lib section is used to hold the
4379
      number of shared libraries in the section.  This code counts the
4380
      number of sections being written, and increments the lma field
4381
      with the number.
4382
4383
      I have found no documentation on the contents of this section.
4384
      Experimentation indicates that the section contains zero or more
4385
      records, each of which has the following structure:
4386
4387
      - a (four byte) word holding the length of this record, in words,
4388
      - a word that always seems to be set to "2",
4389
      - the path to a shared library, null-terminated and then padded
4390
  to a whole word boundary.
4391
4392
      bfd_assert calls have been added to alert if an attempt is made
4393
      to write a section which doesn't follow these assumptions.  The
4394
      code has been tested on ISC 4.1 by me, and on SCO by Robert Lipe
4395
      <robertl@arnet.com> (Thanks!).
4396
4397
      Gvran Uddeborg <gvran@uddeborg.pp.se>.  */
4398
2
    if (strcmp (section->name, _LIB) == 0)
4399
0
      {
4400
0
  bfd_byte *rec, *recend;
4401
4402
0
  rec = (bfd_byte *) location;
4403
0
  recend = rec + count;
4404
0
  while (recend - rec >= 4)
4405
0
    {
4406
0
      size_t len = bfd_get_32 (abfd, rec);
4407
0
      if (len == 0 || len > (size_t) (recend - rec) / 4)
4408
0
        break;
4409
0
      rec += len * 4;
4410
0
      ++section->lma;
4411
0
    }
4412
4413
0
  BFD_ASSERT (rec == recend);
4414
0
      }
4415
2
#endif
4416
4417
  /* Don't write out bss sections - one way to do this is to
4418
       see if the filepos has not been set.  */
4419
2
  if (section->filepos == 0)
4420
0
    return true;
4421
4422
2
  if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0)
4423
0
    return false;
4424
4425
2
  if (count == 0)
4426
0
    return true;
4427
4428
2
  return bfd_write (location, count, abfd) == count;
4429
2
}
Unexecuted instantiation: pe-mcore.c:coff_set_section_contents
Unexecuted instantiation: pe-sh.c:coff_set_section_contents
pei-arm-wince.c:coff_set_section_contents
Line
Count
Source
4370
2
{
4371
2
  if (! abfd->output_has_begun)  /* Set by bfd.c handler.  */
4372
1
    {
4373
1
      if (! coff_compute_section_file_positions (abfd))
4374
0
  return false;
4375
1
    }
4376
4377
2
#if defined(_LIB) && !defined(TARG_AUX)
4378
   /* The physical address field of a .lib section is used to hold the
4379
      number of shared libraries in the section.  This code counts the
4380
      number of sections being written, and increments the lma field
4381
      with the number.
4382
4383
      I have found no documentation on the contents of this section.
4384
      Experimentation indicates that the section contains zero or more
4385
      records, each of which has the following structure:
4386
4387
      - a (four byte) word holding the length of this record, in words,
4388
      - a word that always seems to be set to "2",
4389
      - the path to a shared library, null-terminated and then padded
4390
  to a whole word boundary.
4391
4392
      bfd_assert calls have been added to alert if an attempt is made
4393
      to write a section which doesn't follow these assumptions.  The
4394
      code has been tested on ISC 4.1 by me, and on SCO by Robert Lipe
4395
      <robertl@arnet.com> (Thanks!).
4396
4397
      Gvran Uddeborg <gvran@uddeborg.pp.se>.  */
4398
2
    if (strcmp (section->name, _LIB) == 0)
4399
0
      {
4400
0
  bfd_byte *rec, *recend;
4401
4402
0
  rec = (bfd_byte *) location;
4403
0
  recend = rec + count;
4404
0
  while (recend - rec >= 4)
4405
0
    {
4406
0
      size_t len = bfd_get_32 (abfd, rec);
4407
0
      if (len == 0 || len > (size_t) (recend - rec) / 4)
4408
0
        break;
4409
0
      rec += len * 4;
4410
0
      ++section->lma;
4411
0
    }
4412
4413
0
  BFD_ASSERT (rec == recend);
4414
0
      }
4415
2
#endif
4416
4417
  /* Don't write out bss sections - one way to do this is to
4418
       see if the filepos has not been set.  */
4419
2
  if (section->filepos == 0)
4420
0
    return true;
4421
4422
2
  if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0)
4423
0
    return false;
4424
4425
2
  if (count == 0)
4426
0
    return true;
4427
4428
2
  return bfd_write (location, count, abfd) == count;
4429
2
}
Unexecuted instantiation: pei-arm.c:coff_set_section_contents
Unexecuted instantiation: pei-mcore.c:coff_set_section_contents
Unexecuted instantiation: pei-sh.c:coff_set_section_contents
4430
4431
static void *
4432
buy_and_read (bfd *abfd, file_ptr where,
4433
        bfd_size_type nmemb, bfd_size_type size)
4434
682
{
4435
682
  size_t amt;
4436
4437
682
  if (_bfd_mul_overflow (nmemb, size, &amt))
4438
0
    {
4439
0
      bfd_set_error (bfd_error_file_too_big);
4440
0
      return NULL;
4441
0
    }
4442
682
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4443
42
    return NULL;
4444
640
  return _bfd_malloc_and_read (abfd, amt, amt);
4445
682
}
pei-i386.c:buy_and_read
Line
Count
Source
4434
29
{
4435
29
  size_t amt;
4436
4437
29
  if (_bfd_mul_overflow (nmemb, size, &amt))
4438
0
    {
4439
0
      bfd_set_error (bfd_error_file_too_big);
4440
0
      return NULL;
4441
0
    }
4442
29
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4443
0
    return NULL;
4444
29
  return _bfd_malloc_and_read (abfd, amt, amt);
4445
29
}
pe-x86_64.c:buy_and_read
Line
Count
Source
4434
23
{
4435
23
  size_t amt;
4436
4437
23
  if (_bfd_mul_overflow (nmemb, size, &amt))
4438
0
    {
4439
0
      bfd_set_error (bfd_error_file_too_big);
4440
0
      return NULL;
4441
0
    }
4442
23
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4443
0
    return NULL;
4444
23
  return _bfd_malloc_and_read (abfd, amt, amt);
4445
23
}
pei-x86_64.c:buy_and_read
Line
Count
Source
4434
31
{
4435
31
  size_t amt;
4436
4437
31
  if (_bfd_mul_overflow (nmemb, size, &amt))
4438
0
    {
4439
0
      bfd_set_error (bfd_error_file_too_big);
4440
0
      return NULL;
4441
0
    }
4442
31
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4443
0
    return NULL;
4444
31
  return _bfd_malloc_and_read (abfd, amt, amt);
4445
31
}
coff-x86_64.c:buy_and_read
Line
Count
Source
4434
46
{
4435
46
  size_t amt;
4436
4437
46
  if (_bfd_mul_overflow (nmemb, size, &amt))
4438
0
    {
4439
0
      bfd_set_error (bfd_error_file_too_big);
4440
0
      return NULL;
4441
0
    }
4442
46
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4443
0
    return NULL;
4444
46
  return _bfd_malloc_and_read (abfd, amt, amt);
4445
46
}
coff64-rs6000.c:buy_and_read
Line
Count
Source
4434
82
{
4435
82
  size_t amt;
4436
4437
82
  if (_bfd_mul_overflow (nmemb, size, &amt))
4438
0
    {
4439
0
      bfd_set_error (bfd_error_file_too_big);
4440
0
      return NULL;
4441
0
    }
4442
82
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4443
42
    return NULL;
4444
40
  return _bfd_malloc_and_read (abfd, amt, amt);
4445
82
}
pe-aarch64.c:buy_and_read
Line
Count
Source
4434
26
{
4435
26
  size_t amt;
4436
4437
26
  if (_bfd_mul_overflow (nmemb, size, &amt))
4438
0
    {
4439
0
      bfd_set_error (bfd_error_file_too_big);
4440
0
      return NULL;
4441
0
    }
4442
26
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4443
0
    return NULL;
4444
26
  return _bfd_malloc_and_read (abfd, amt, amt);
4445
26
}
pei-aarch64.c:buy_and_read
Line
Count
Source
4434
13
{
4435
13
  size_t amt;
4436
4437
13
  if (_bfd_mul_overflow (nmemb, size, &amt))
4438
0
    {
4439
0
      bfd_set_error (bfd_error_file_too_big);
4440
0
      return NULL;
4441
0
    }
4442
13
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4443
0
    return NULL;
4444
13
  return _bfd_malloc_and_read (abfd, amt, amt);
4445
13
}
pei-ia64.c:buy_and_read
Line
Count
Source
4434
26
{
4435
26
  size_t amt;
4436
4437
26
  if (_bfd_mul_overflow (nmemb, size, &amt))
4438
0
    {
4439
0
      bfd_set_error (bfd_error_file_too_big);
4440
0
      return NULL;
4441
0
    }
4442
26
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4443
0
    return NULL;
4444
26
  return _bfd_malloc_and_read (abfd, amt, amt);
4445
26
}
pei-loongarch64.c:buy_and_read
Line
Count
Source
4434
25
{
4435
25
  size_t amt;
4436
4437
25
  if (_bfd_mul_overflow (nmemb, size, &amt))
4438
0
    {
4439
0
      bfd_set_error (bfd_error_file_too_big);
4440
0
      return NULL;
4441
0
    }
4442
25
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4443
0
    return NULL;
4444
25
  return _bfd_malloc_and_read (abfd, amt, amt);
4445
25
}
Unexecuted instantiation: cf-i386lynx.c:buy_and_read
Unexecuted instantiation: coff-go32.c:buy_and_read
Unexecuted instantiation: coff-i386.c:buy_and_read
coff-rs6000.c:buy_and_read
Line
Count
Source
4434
64
{
4435
64
  size_t amt;
4436
4437
64
  if (_bfd_mul_overflow (nmemb, size, &amt))
4438
0
    {
4439
0
      bfd_set_error (bfd_error_file_too_big);
4440
0
      return NULL;
4441
0
    }
4442
64
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4443
0
    return NULL;
4444
64
  return _bfd_malloc_and_read (abfd, amt, amt);
4445
64
}
coff-sh.c:buy_and_read
Line
Count
Source
4434
59
{
4435
59
  size_t amt;
4436
4437
59
  if (_bfd_mul_overflow (nmemb, size, &amt))
4438
0
    {
4439
0
      bfd_set_error (bfd_error_file_too_big);
4440
0
      return NULL;
4441
0
    }
4442
59
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4443
0
    return NULL;
4444
59
  return _bfd_malloc_and_read (abfd, amt, amt);
4445
59
}
Unexecuted instantiation: coff-stgo32.c:buy_and_read
coff-tic30.c:buy_and_read
Line
Count
Source
4434
22
{
4435
22
  size_t amt;
4436
4437
22
  if (_bfd_mul_overflow (nmemb, size, &amt))
4438
0
    {
4439
0
      bfd_set_error (bfd_error_file_too_big);
4440
0
      return NULL;
4441
0
    }
4442
22
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4443
0
    return NULL;
4444
22
  return _bfd_malloc_and_read (abfd, amt, amt);
4445
22
}
Unexecuted instantiation: coff-tic4x.c:buy_and_read
coff-tic54x.c:buy_and_read
Line
Count
Source
4434
39
{
4435
39
  size_t amt;
4436
4437
39
  if (_bfd_mul_overflow (nmemb, size, &amt))
4438
0
    {
4439
0
      bfd_set_error (bfd_error_file_too_big);
4440
0
      return NULL;
4441
0
    }
4442
39
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4443
0
    return NULL;
4444
39
  return _bfd_malloc_and_read (abfd, amt, amt);
4445
39
}
coff-z80.c:buy_and_read
Line
Count
Source
4434
26
{
4435
26
  size_t amt;
4436
4437
26
  if (_bfd_mul_overflow (nmemb, size, &amt))
4438
0
    {
4439
0
      bfd_set_error (bfd_error_file_too_big);
4440
0
      return NULL;
4441
0
    }
4442
26
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4443
0
    return NULL;
4444
26
  return _bfd_malloc_and_read (abfd, amt, amt);
4445
26
}
coff-z8k.c:buy_and_read
Line
Count
Source
4434
35
{
4435
35
  size_t amt;
4436
4437
35
  if (_bfd_mul_overflow (nmemb, size, &amt))
4438
0
    {
4439
0
      bfd_set_error (bfd_error_file_too_big);
4440
0
      return NULL;
4441
0
    }
4442
35
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4443
0
    return NULL;
4444
35
  return _bfd_malloc_and_read (abfd, amt, amt);
4445
35
}
Unexecuted instantiation: pe-arm-wince.c:buy_and_read
Unexecuted instantiation: pe-arm.c:buy_and_read
pe-i386.c:buy_and_read
Line
Count
Source
4434
37
{
4435
37
  size_t amt;
4436
4437
37
  if (_bfd_mul_overflow (nmemb, size, &amt))
4438
0
    {
4439
0
      bfd_set_error (bfd_error_file_too_big);
4440
0
      return NULL;
4441
0
    }
4442
37
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4443
0
    return NULL;
4444
37
  return _bfd_malloc_and_read (abfd, amt, amt);
4445
37
}
pe-mcore.c:buy_and_read
Line
Count
Source
4434
45
{
4435
45
  size_t amt;
4436
4437
45
  if (_bfd_mul_overflow (nmemb, size, &amt))
4438
0
    {
4439
0
      bfd_set_error (bfd_error_file_too_big);
4440
0
      return NULL;
4441
0
    }
4442
45
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4443
0
    return NULL;
4444
45
  return _bfd_malloc_and_read (abfd, amt, amt);
4445
45
}
pe-sh.c:buy_and_read
Line
Count
Source
4434
21
{
4435
21
  size_t amt;
4436
4437
21
  if (_bfd_mul_overflow (nmemb, size, &amt))
4438
0
    {
4439
0
      bfd_set_error (bfd_error_file_too_big);
4440
0
      return NULL;
4441
0
    }
4442
21
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4443
0
    return NULL;
4444
21
  return _bfd_malloc_and_read (abfd, amt, amt);
4445
21
}
pei-arm-wince.c:buy_and_read
Line
Count
Source
4434
5
{
4435
5
  size_t amt;
4436
4437
5
  if (_bfd_mul_overflow (nmemb, size, &amt))
4438
0
    {
4439
0
      bfd_set_error (bfd_error_file_too_big);
4440
0
      return NULL;
4441
0
    }
4442
5
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4443
0
    return NULL;
4444
5
  return _bfd_malloc_and_read (abfd, amt, amt);
4445
5
}
pei-arm.c:buy_and_read
Line
Count
Source
4434
7
{
4435
7
  size_t amt;
4436
4437
7
  if (_bfd_mul_overflow (nmemb, size, &amt))
4438
0
    {
4439
0
      bfd_set_error (bfd_error_file_too_big);
4440
0
      return NULL;
4441
0
    }
4442
7
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4443
0
    return NULL;
4444
7
  return _bfd_malloc_and_read (abfd, amt, amt);
4445
7
}
pei-mcore.c:buy_and_read
Line
Count
Source
4434
5
{
4435
5
  size_t amt;
4436
4437
5
  if (_bfd_mul_overflow (nmemb, size, &amt))
4438
0
    {
4439
0
      bfd_set_error (bfd_error_file_too_big);
4440
0
      return NULL;
4441
0
    }
4442
5
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4443
0
    return NULL;
4444
5
  return _bfd_malloc_and_read (abfd, amt, amt);
4445
5
}
pei-sh.c:buy_and_read
Line
Count
Source
4434
16
{
4435
16
  size_t amt;
4436
4437
16
  if (_bfd_mul_overflow (nmemb, size, &amt))
4438
0
    {
4439
0
      bfd_set_error (bfd_error_file_too_big);
4440
0
      return NULL;
4441
0
    }
4442
16
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4443
0
    return NULL;
4444
16
  return _bfd_malloc_and_read (abfd, amt, amt);
4445
16
}
4446
4447
/*
4448
SUBSUBSECTION
4449
  Reading linenumbers
4450
4451
  Creating the linenumber table is done by reading in the entire
4452
  coff linenumber table, and creating another table for internal use.
4453
4454
  A coff linenumber table is structured so that each function
4455
  is marked as having a line number of 0. Each line within the
4456
  function is an offset from the first line in the function. The
4457
  base of the line number information for the table is stored in
4458
  the symbol associated with the function.
4459
4460
  Note: The PE format uses line number 0 for a flag indicating a
4461
  new source file.
4462
4463
  The information is copied from the external to the internal
4464
  table, and each symbol which marks a function is marked by
4465
  pointing its...
4466
4467
  How does this work ?
4468
*/
4469
4470
static int
4471
coff_sort_func_alent (const void * arg1, const void * arg2)
4472
1.48M
{
4473
1.48M
  const alent *al1 = *(const alent **) arg1;
4474
1.48M
  const alent *al2 = *(const alent **) arg2;
4475
1.48M
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4476
1.48M
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4477
4478
1.48M
  if (s1 == NULL || s2 == NULL)
4479
0
    return 0;
4480
1.48M
  if (s1->symbol.value < s2->symbol.value)
4481
11.1k
    return -1;
4482
1.47M
  else if (s1->symbol.value > s2->symbol.value)
4483
309k
    return 1;
4484
4485
1.16M
  return 0;
4486
1.48M
}
pei-i386.c:coff_sort_func_alent
Line
Count
Source
4472
7.00k
{
4473
7.00k
  const alent *al1 = *(const alent **) arg1;
4474
7.00k
  const alent *al2 = *(const alent **) arg2;
4475
7.00k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4476
7.00k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4477
4478
7.00k
  if (s1 == NULL || s2 == NULL)
4479
0
    return 0;
4480
7.00k
  if (s1->symbol.value < s2->symbol.value)
4481
389
    return -1;
4482
6.61k
  else if (s1->symbol.value > s2->symbol.value)
4483
917
    return 1;
4484
4485
5.70k
  return 0;
4486
7.00k
}
pe-x86_64.c:coff_sort_func_alent
Line
Count
Source
4472
6.72k
{
4473
6.72k
  const alent *al1 = *(const alent **) arg1;
4474
6.72k
  const alent *al2 = *(const alent **) arg2;
4475
6.72k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4476
6.72k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4477
4478
6.72k
  if (s1 == NULL || s2 == NULL)
4479
0
    return 0;
4480
6.72k
  if (s1->symbol.value < s2->symbol.value)
4481
170
    return -1;
4482
6.55k
  else if (s1->symbol.value > s2->symbol.value)
4483
2.09k
    return 1;
4484
4485
4.46k
  return 0;
4486
6.72k
}
pei-x86_64.c:coff_sort_func_alent
Line
Count
Source
4472
67.3k
{
4473
67.3k
  const alent *al1 = *(const alent **) arg1;
4474
67.3k
  const alent *al2 = *(const alent **) arg2;
4475
67.3k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4476
67.3k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4477
4478
67.3k
  if (s1 == NULL || s2 == NULL)
4479
0
    return 0;
4480
67.3k
  if (s1->symbol.value < s2->symbol.value)
4481
430
    return -1;
4482
66.9k
  else if (s1->symbol.value > s2->symbol.value)
4483
1.48k
    return 1;
4484
4485
65.4k
  return 0;
4486
67.3k
}
coff-x86_64.c:coff_sort_func_alent
Line
Count
Source
4472
275k
{
4473
275k
  const alent *al1 = *(const alent **) arg1;
4474
275k
  const alent *al2 = *(const alent **) arg2;
4475
275k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4476
275k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4477
4478
275k
  if (s1 == NULL || s2 == NULL)
4479
0
    return 0;
4480
275k
  if (s1->symbol.value < s2->symbol.value)
4481
2.36k
    return -1;
4482
273k
  else if (s1->symbol.value > s2->symbol.value)
4483
83.0k
    return 1;
4484
4485
190k
  return 0;
4486
275k
}
coff64-rs6000.c:coff_sort_func_alent
Line
Count
Source
4472
246k
{
4473
246k
  const alent *al1 = *(const alent **) arg1;
4474
246k
  const alent *al2 = *(const alent **) arg2;
4475
246k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4476
246k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4477
4478
246k
  if (s1 == NULL || s2 == NULL)
4479
0
    return 0;
4480
246k
  if (s1->symbol.value < s2->symbol.value)
4481
1.50k
    return -1;
4482
245k
  else if (s1->symbol.value > s2->symbol.value)
4483
52.5k
    return 1;
4484
4485
192k
  return 0;
4486
246k
}
pe-aarch64.c:coff_sort_func_alent
Line
Count
Source
4472
4.71k
{
4473
4.71k
  const alent *al1 = *(const alent **) arg1;
4474
4.71k
  const alent *al2 = *(const alent **) arg2;
4475
4.71k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4476
4.71k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4477
4478
4.71k
  if (s1 == NULL || s2 == NULL)
4479
0
    return 0;
4480
4.71k
  if (s1->symbol.value < s2->symbol.value)
4481
94
    return -1;
4482
4.62k
  else if (s1->symbol.value > s2->symbol.value)
4483
235
    return 1;
4484
4485
4.38k
  return 0;
4486
4.71k
}
pei-aarch64.c:coff_sort_func_alent
Line
Count
Source
4472
1.54k
{
4473
1.54k
  const alent *al1 = *(const alent **) arg1;
4474
1.54k
  const alent *al2 = *(const alent **) arg2;
4475
1.54k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4476
1.54k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4477
4478
1.54k
  if (s1 == NULL || s2 == NULL)
4479
0
    return 0;
4480
1.54k
  if (s1->symbol.value < s2->symbol.value)
4481
14
    return -1;
4482
1.52k
  else if (s1->symbol.value > s2->symbol.value)
4483
20
    return 1;
4484
4485
1.50k
  return 0;
4486
1.54k
}
pei-ia64.c:coff_sort_func_alent
Line
Count
Source
4472
52.5k
{
4473
52.5k
  const alent *al1 = *(const alent **) arg1;
4474
52.5k
  const alent *al2 = *(const alent **) arg2;
4475
52.5k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4476
52.5k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4477
4478
52.5k
  if (s1 == NULL || s2 == NULL)
4479
0
    return 0;
4480
52.5k
  if (s1->symbol.value < s2->symbol.value)
4481
565
    return -1;
4482
51.9k
  else if (s1->symbol.value > s2->symbol.value)
4483
4.79k
    return 1;
4484
4485
47.1k
  return 0;
4486
52.5k
}
pei-loongarch64.c:coff_sort_func_alent
Line
Count
Source
4472
18.0k
{
4473
18.0k
  const alent *al1 = *(const alent **) arg1;
4474
18.0k
  const alent *al2 = *(const alent **) arg2;
4475
18.0k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4476
18.0k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4477
4478
18.0k
  if (s1 == NULL || s2 == NULL)
4479
0
    return 0;
4480
18.0k
  if (s1->symbol.value < s2->symbol.value)
4481
240
    return -1;
4482
17.8k
  else if (s1->symbol.value > s2->symbol.value)
4483
2.62k
    return 1;
4484
4485
15.2k
  return 0;
4486
18.0k
}
Unexecuted instantiation: cf-i386lynx.c:coff_sort_func_alent
Unexecuted instantiation: coff-go32.c:coff_sort_func_alent
Unexecuted instantiation: coff-i386.c:coff_sort_func_alent
coff-rs6000.c:coff_sort_func_alent
Line
Count
Source
4472
73.9k
{
4473
73.9k
  const alent *al1 = *(const alent **) arg1;
4474
73.9k
  const alent *al2 = *(const alent **) arg2;
4475
73.9k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4476
73.9k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4477
4478
73.9k
  if (s1 == NULL || s2 == NULL)
4479
0
    return 0;
4480
73.9k
  if (s1->symbol.value < s2->symbol.value)
4481
335
    return -1;
4482
73.6k
  else if (s1->symbol.value > s2->symbol.value)
4483
5.35k
    return 1;
4484
4485
68.2k
  return 0;
4486
73.9k
}
coff-sh.c:coff_sort_func_alent
Line
Count
Source
4472
39.3k
{
4473
39.3k
  const alent *al1 = *(const alent **) arg1;
4474
39.3k
  const alent *al2 = *(const alent **) arg2;
4475
39.3k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4476
39.3k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4477
4478
39.3k
  if (s1 == NULL || s2 == NULL)
4479
0
    return 0;
4480
39.3k
  if (s1->symbol.value < s2->symbol.value)
4481
172
    return -1;
4482
39.1k
  else if (s1->symbol.value > s2->symbol.value)
4483
8.40k
    return 1;
4484
4485
30.7k
  return 0;
4486
39.3k
}
Unexecuted instantiation: coff-stgo32.c:coff_sort_func_alent
coff-tic30.c:coff_sort_func_alent
Line
Count
Source
4472
65.4k
{
4473
65.4k
  const alent *al1 = *(const alent **) arg1;
4474
65.4k
  const alent *al2 = *(const alent **) arg2;
4475
65.4k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4476
65.4k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4477
4478
65.4k
  if (s1 == NULL || s2 == NULL)
4479
0
    return 0;
4480
65.4k
  if (s1->symbol.value < s2->symbol.value)
4481
191
    return -1;
4482
65.3k
  else if (s1->symbol.value > s2->symbol.value)
4483
8.22k
    return 1;
4484
4485
57.0k
  return 0;
4486
65.4k
}
Unexecuted instantiation: coff-tic4x.c:coff_sort_func_alent
coff-tic54x.c:coff_sort_func_alent
Line
Count
Source
4472
109k
{
4473
109k
  const alent *al1 = *(const alent **) arg1;
4474
109k
  const alent *al2 = *(const alent **) arg2;
4475
109k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4476
109k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4477
4478
109k
  if (s1 == NULL || s2 == NULL)
4479
0
    return 0;
4480
109k
  if (s1->symbol.value < s2->symbol.value)
4481
1.61k
    return -1;
4482
107k
  else if (s1->symbol.value > s2->symbol.value)
4483
24.0k
    return 1;
4484
4485
83.4k
  return 0;
4486
109k
}
coff-z80.c:coff_sort_func_alent
Line
Count
Source
4472
35.2k
{
4473
35.2k
  const alent *al1 = *(const alent **) arg1;
4474
35.2k
  const alent *al2 = *(const alent **) arg2;
4475
35.2k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4476
35.2k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4477
4478
35.2k
  if (s1 == NULL || s2 == NULL)
4479
0
    return 0;
4480
35.2k
  if (s1->symbol.value < s2->symbol.value)
4481
338
    return -1;
4482
34.8k
  else if (s1->symbol.value > s2->symbol.value)
4483
3.86k
    return 1;
4484
4485
30.9k
  return 0;
4486
35.2k
}
coff-z8k.c:coff_sort_func_alent
Line
Count
Source
4472
66.7k
{
4473
66.7k
  const alent *al1 = *(const alent **) arg1;
4474
66.7k
  const alent *al2 = *(const alent **) arg2;
4475
66.7k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4476
66.7k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4477
4478
66.7k
  if (s1 == NULL || s2 == NULL)
4479
0
    return 0;
4480
66.7k
  if (s1->symbol.value < s2->symbol.value)
4481
842
    return -1;
4482
65.8k
  else if (s1->symbol.value > s2->symbol.value)
4483
15.3k
    return 1;
4484
4485
50.5k
  return 0;
4486
66.7k
}
Unexecuted instantiation: pe-arm-wince.c:coff_sort_func_alent
Unexecuted instantiation: pe-arm.c:coff_sort_func_alent
pe-i386.c:coff_sort_func_alent
Line
Count
Source
4472
1.47k
{
4473
1.47k
  const alent *al1 = *(const alent **) arg1;
4474
1.47k
  const alent *al2 = *(const alent **) arg2;
4475
1.47k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4476
1.47k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4477
4478
1.47k
  if (s1 == NULL || s2 == NULL)
4479
0
    return 0;
4480
1.47k
  if (s1->symbol.value < s2->symbol.value)
4481
13
    return -1;
4482
1.46k
  else if (s1->symbol.value > s2->symbol.value)
4483
48
    return 1;
4484
4485
1.41k
  return 0;
4486
1.47k
}
pe-mcore.c:coff_sort_func_alent
Line
Count
Source
4472
142k
{
4473
142k
  const alent *al1 = *(const alent **) arg1;
4474
142k
  const alent *al2 = *(const alent **) arg2;
4475
142k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4476
142k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4477
4478
142k
  if (s1 == NULL || s2 == NULL)
4479
0
    return 0;
4480
142k
  if (s1->symbol.value < s2->symbol.value)
4481
100
    return -1;
4482
142k
  else if (s1->symbol.value > s2->symbol.value)
4483
26.9k
    return 1;
4484
4485
115k
  return 0;
4486
142k
}
pe-sh.c:coff_sort_func_alent
Line
Count
Source
4472
97.4k
{
4473
97.4k
  const alent *al1 = *(const alent **) arg1;
4474
97.4k
  const alent *al2 = *(const alent **) arg2;
4475
97.4k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4476
97.4k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4477
4478
97.4k
  if (s1 == NULL || s2 == NULL)
4479
0
    return 0;
4480
97.4k
  if (s1->symbol.value < s2->symbol.value)
4481
262
    return -1;
4482
97.2k
  else if (s1->symbol.value > s2->symbol.value)
4483
21.1k
    return 1;
4484
4485
76.0k
  return 0;
4486
97.4k
}
pei-arm-wince.c:coff_sort_func_alent
Line
Count
Source
4472
29.0k
{
4473
29.0k
  const alent *al1 = *(const alent **) arg1;
4474
29.0k
  const alent *al2 = *(const alent **) arg2;
4475
29.0k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4476
29.0k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4477
4478
29.0k
  if (s1 == NULL || s2 == NULL)
4479
0
    return 0;
4480
29.0k
  if (s1->symbol.value < s2->symbol.value)
4481
216
    return -1;
4482
28.8k
  else if (s1->symbol.value > s2->symbol.value)
4483
8.42k
    return 1;
4484
4485
20.4k
  return 0;
4486
29.0k
}
pei-arm.c:coff_sort_func_alent
Line
Count
Source
4472
37.9k
{
4473
37.9k
  const alent *al1 = *(const alent **) arg1;
4474
37.9k
  const alent *al2 = *(const alent **) arg2;
4475
37.9k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4476
37.9k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4477
4478
37.9k
  if (s1 == NULL || s2 == NULL)
4479
0
    return 0;
4480
37.9k
  if (s1->symbol.value < s2->symbol.value)
4481
897
    return -1;
4482
37.0k
  else if (s1->symbol.value > s2->symbol.value)
4483
8.18k
    return 1;
4484
4485
28.8k
  return 0;
4486
37.9k
}
pei-mcore.c:coff_sort_func_alent
Line
Count
Source
4472
105k
{
4473
105k
  const alent *al1 = *(const alent **) arg1;
4474
105k
  const alent *al2 = *(const alent **) arg2;
4475
105k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4476
105k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4477
4478
105k
  if (s1 == NULL || s2 == NULL)
4479
0
    return 0;
4480
105k
  if (s1->symbol.value < s2->symbol.value)
4481
361
    return -1;
4482
105k
  else if (s1->symbol.value > s2->symbol.value)
4483
31.4k
    return 1;
4484
4485
73.6k
  return 0;
4486
105k
}
Unexecuted instantiation: pei-sh.c:coff_sort_func_alent
4487
4488
static bool
4489
coff_slurp_line_table (bfd *abfd, asection *asect)
4490
12.1k
{
4491
12.1k
  LINENO *native_lineno;
4492
12.1k
  alent *lineno_cache;
4493
12.1k
  unsigned int counter;
4494
12.1k
  alent *cache_ptr;
4495
12.1k
  bfd_vma prev_offset = 0;
4496
12.1k
  bool ordered = true;
4497
12.1k
  unsigned int nbr_func;
4498
12.1k
  LINENO *src;
4499
12.1k
  bool have_func;
4500
12.1k
  bool ret = true;
4501
12.1k
  size_t amt;
4502
4503
12.1k
  if (asect->lineno_count == 0)
4504
11.5k
    return true;
4505
4506
682
  BFD_ASSERT (asect->lineno == NULL);
4507
4508
682
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4509
682
             asect->lineno_count,
4510
682
             bfd_coff_linesz (abfd));
4511
682
  if (native_lineno == NULL)
4512
359
    {
4513
359
      _bfd_error_handler
4514
359
  (_("%pB: warning: line number table read failed"), abfd);
4515
359
      return false;
4516
359
    }
4517
4518
323
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4519
0
    {
4520
0
      bfd_set_error (bfd_error_file_too_big);
4521
0
      free (native_lineno);
4522
0
      return false;
4523
0
    }
4524
323
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4525
323
  if (lineno_cache == NULL)
4526
0
    {
4527
0
      free (native_lineno);
4528
0
      return false;
4529
0
    }
4530
4531
323
  cache_ptr = lineno_cache;
4532
323
  asect->lineno = lineno_cache;
4533
323
  src = native_lineno;
4534
323
  nbr_func = 0;
4535
323
  have_func = false;
4536
4537
1.24M
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4538
1.24M
    {
4539
1.24M
      struct internal_lineno dst;
4540
4541
1.24M
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4542
1.24M
      cache_ptr->line_number = dst.l_lnno;
4543
      /* Appease memory checkers that get all excited about
4544
   uninitialised memory when copying alents if u.offset is
4545
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4546
1.24M
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4547
4548
1.24M
      if (cache_ptr->line_number == 0)
4549
432k
  {
4550
432k
    combined_entry_type * ent;
4551
432k
    unsigned long symndx;
4552
432k
    coff_symbol_type *sym;
4553
4554
432k
    have_func = false;
4555
432k
    symndx = dst.l_addr.l_symndx;
4556
432k
    if (symndx >= obj_raw_syment_count (abfd))
4557
161k
      {
4558
161k
        _bfd_error_handler
4559
    /* xgettext:c-format */
4560
161k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4561
161k
     abfd, symndx, counter);
4562
161k
        cache_ptr->line_number = -1;
4563
161k
        ret = false;
4564
161k
        continue;
4565
161k
      }
4566
4567
270k
    ent = obj_raw_syments (abfd) + symndx;
4568
    /* FIXME: We should not be casting between ints and
4569
       pointers like this.  */
4570
270k
    if (! ent->is_sym)
4571
30.8k
      {
4572
30.8k
        _bfd_error_handler
4573
    /* xgettext:c-format */
4574
30.8k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4575
30.8k
     abfd, symndx, counter);
4576
30.8k
        cache_ptr->line_number = -1;
4577
30.8k
        ret = false;
4578
30.8k
        continue;
4579
30.8k
      }
4580
240k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4581
4582
    /* PR 17512 file: 078-10659-0.004  */
4583
240k
    if (sym < obj_symbols (abfd)
4584
240k
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4585
0
      {
4586
0
        _bfd_error_handler
4587
    /* xgettext:c-format */
4588
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4589
0
     abfd, counter);
4590
0
        cache_ptr->line_number = -1;
4591
0
        ret = false;
4592
0
        continue;
4593
0
      }
4594
4595
240k
    have_func = true;
4596
240k
    nbr_func++;
4597
240k
    cache_ptr->u.sym = (asymbol *) sym;
4598
240k
    if (sym->lineno != NULL)
4599
237k
      _bfd_error_handler
4600
        /* xgettext:c-format */
4601
237k
        (_("%pB: warning: duplicate line number information for `%s'"),
4602
237k
         abfd, bfd_asymbol_name (&sym->symbol));
4603
4604
240k
    sym->lineno = cache_ptr;
4605
240k
    if (sym->symbol.value < prev_offset)
4606
3.95k
      ordered = false;
4607
240k
    prev_offset = sym->symbol.value;
4608
240k
  }
4609
809k
      else if (!have_func)
4610
  /* Drop line information that has no associated function.
4611
     PR 17521: file: 078-10659-0.004.  */
4612
482k
  continue;
4613
326k
      else
4614
326k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4615
566k
      cache_ptr++;
4616
566k
    }
4617
4618
323
  asect->lineno_count = cache_ptr - lineno_cache;
4619
323
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4620
323
  free (native_lineno);
4621
4622
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4623
323
  if (!ordered)
4624
193
    {
4625
      /* Sort the table.  */
4626
193
      alent **func_table;
4627
193
      alent *n_lineno_cache;
4628
4629
      /* Create a table of functions.  */
4630
193
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4631
0
  {
4632
0
    bfd_set_error (bfd_error_file_too_big);
4633
0
    ret = false;
4634
0
  }
4635
193
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4636
193
  {
4637
193
    alent **p = func_table;
4638
193
    unsigned int i;
4639
4640
529k
    for (i = 0; i < asect->lineno_count; i++)
4641
529k
      if (lineno_cache[i].line_number == 0)
4642
224k
        *p++ = &lineno_cache[i];
4643
4644
193
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4645
4646
    /* Sort by functions.  */
4647
193
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4648
4649
    /* Create the new sorted table.  */
4650
193
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4651
0
      {
4652
0
        bfd_set_error (bfd_error_file_too_big);
4653
0
        ret = false;
4654
0
      }
4655
193
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4656
193
      {
4657
193
        alent *n_cache_ptr = n_lineno_cache;
4658
4659
224k
        for (i = 0; i < nbr_func; i++)
4660
224k
    {
4661
224k
      coff_symbol_type *sym;
4662
224k
      alent *old_ptr = func_table[i];
4663
4664
      /* Update the function entry.  */
4665
224k
      sym = (coff_symbol_type *) old_ptr->u.sym;
4666
      /* PR binutils/17512: Point the lineno to where
4667
         this entry will be after the memcpy below.  */
4668
224k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4669
      /* Copy the function and line number entries.  */
4670
224k
      do
4671
529k
        *n_cache_ptr++ = *old_ptr++;
4672
529k
      while (old_ptr->line_number != 0);
4673
224k
    }
4674
4675
193
        memcpy (lineno_cache, n_lineno_cache,
4676
193
          asect->lineno_count * sizeof (alent));
4677
193
      }
4678
0
    else
4679
0
      ret = false;
4680
193
    bfd_release (abfd, func_table);
4681
193
  }
4682
0
      else
4683
0
  ret = false;
4684
193
    }
4685
4686
323
  return ret;
4687
323
}
pei-i386.c:coff_slurp_line_table
Line
Count
Source
4490
43
{
4491
43
  LINENO *native_lineno;
4492
43
  alent *lineno_cache;
4493
43
  unsigned int counter;
4494
43
  alent *cache_ptr;
4495
43
  bfd_vma prev_offset = 0;
4496
43
  bool ordered = true;
4497
43
  unsigned int nbr_func;
4498
43
  LINENO *src;
4499
43
  bool have_func;
4500
43
  bool ret = true;
4501
43
  size_t amt;
4502
4503
43
  if (asect->lineno_count == 0)
4504
14
    return true;
4505
4506
29
  BFD_ASSERT (asect->lineno == NULL);
4507
4508
29
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4509
29
             asect->lineno_count,
4510
29
             bfd_coff_linesz (abfd));
4511
29
  if (native_lineno == NULL)
4512
26
    {
4513
26
      _bfd_error_handler
4514
26
  (_("%pB: warning: line number table read failed"), abfd);
4515
26
      return false;
4516
26
    }
4517
4518
3
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4519
0
    {
4520
0
      bfd_set_error (bfd_error_file_too_big);
4521
0
      free (native_lineno);
4522
0
      return false;
4523
0
    }
4524
3
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4525
3
  if (lineno_cache == NULL)
4526
0
    {
4527
0
      free (native_lineno);
4528
0
      return false;
4529
0
    }
4530
4531
3
  cache_ptr = lineno_cache;
4532
3
  asect->lineno = lineno_cache;
4533
3
  src = native_lineno;
4534
3
  nbr_func = 0;
4535
3
  have_func = false;
4536
4537
6.14k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4538
6.14k
    {
4539
6.14k
      struct internal_lineno dst;
4540
4541
6.14k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4542
6.14k
      cache_ptr->line_number = dst.l_lnno;
4543
      /* Appease memory checkers that get all excited about
4544
   uninitialised memory when copying alents if u.offset is
4545
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4546
6.14k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4547
4548
6.14k
      if (cache_ptr->line_number == 0)
4549
2.76k
  {
4550
2.76k
    combined_entry_type * ent;
4551
2.76k
    unsigned long symndx;
4552
2.76k
    coff_symbol_type *sym;
4553
4554
2.76k
    have_func = false;
4555
2.76k
    symndx = dst.l_addr.l_symndx;
4556
2.76k
    if (symndx >= obj_raw_syment_count (abfd))
4557
1.28k
      {
4558
1.28k
        _bfd_error_handler
4559
    /* xgettext:c-format */
4560
1.28k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4561
1.28k
     abfd, symndx, counter);
4562
1.28k
        cache_ptr->line_number = -1;
4563
1.28k
        ret = false;
4564
1.28k
        continue;
4565
1.28k
      }
4566
4567
1.47k
    ent = obj_raw_syments (abfd) + symndx;
4568
    /* FIXME: We should not be casting between ints and
4569
       pointers like this.  */
4570
1.47k
    if (! ent->is_sym)
4571
49
      {
4572
49
        _bfd_error_handler
4573
    /* xgettext:c-format */
4574
49
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4575
49
     abfd, symndx, counter);
4576
49
        cache_ptr->line_number = -1;
4577
49
        ret = false;
4578
49
        continue;
4579
49
      }
4580
1.42k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4581
4582
    /* PR 17512 file: 078-10659-0.004  */
4583
1.42k
    if (sym < obj_symbols (abfd)
4584
1.42k
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4585
0
      {
4586
0
        _bfd_error_handler
4587
    /* xgettext:c-format */
4588
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4589
0
     abfd, counter);
4590
0
        cache_ptr->line_number = -1;
4591
0
        ret = false;
4592
0
        continue;
4593
0
      }
4594
4595
1.42k
    have_func = true;
4596
1.42k
    nbr_func++;
4597
1.42k
    cache_ptr->u.sym = (asymbol *) sym;
4598
1.42k
    if (sym->lineno != NULL)
4599
1.37k
      _bfd_error_handler
4600
        /* xgettext:c-format */
4601
1.37k
        (_("%pB: warning: duplicate line number information for `%s'"),
4602
1.37k
         abfd, bfd_asymbol_name (&sym->symbol));
4603
4604
1.42k
    sym->lineno = cache_ptr;
4605
1.42k
    if (sym->symbol.value < prev_offset)
4606
91
      ordered = false;
4607
1.42k
    prev_offset = sym->symbol.value;
4608
1.42k
  }
4609
3.38k
      else if (!have_func)
4610
  /* Drop line information that has no associated function.
4611
     PR 17521: file: 078-10659-0.004.  */
4612
1.88k
  continue;
4613
1.50k
      else
4614
1.50k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4615
2.92k
      cache_ptr++;
4616
2.92k
    }
4617
4618
3
  asect->lineno_count = cache_ptr - lineno_cache;
4619
3
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4620
3
  free (native_lineno);
4621
4622
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4623
3
  if (!ordered)
4624
3
    {
4625
      /* Sort the table.  */
4626
3
      alent **func_table;
4627
3
      alent *n_lineno_cache;
4628
4629
      /* Create a table of functions.  */
4630
3
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4631
0
  {
4632
0
    bfd_set_error (bfd_error_file_too_big);
4633
0
    ret = false;
4634
0
  }
4635
3
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4636
3
  {
4637
3
    alent **p = func_table;
4638
3
    unsigned int i;
4639
4640
2.93k
    for (i = 0; i < asect->lineno_count; i++)
4641
2.92k
      if (lineno_cache[i].line_number == 0)
4642
1.42k
        *p++ = &lineno_cache[i];
4643
4644
3
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4645
4646
    /* Sort by functions.  */
4647
3
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4648
4649
    /* Create the new sorted table.  */
4650
3
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4651
0
      {
4652
0
        bfd_set_error (bfd_error_file_too_big);
4653
0
        ret = false;
4654
0
      }
4655
3
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4656
3
      {
4657
3
        alent *n_cache_ptr = n_lineno_cache;
4658
4659
1.42k
        for (i = 0; i < nbr_func; i++)
4660
1.42k
    {
4661
1.42k
      coff_symbol_type *sym;
4662
1.42k
      alent *old_ptr = func_table[i];
4663
4664
      /* Update the function entry.  */
4665
1.42k
      sym = (coff_symbol_type *) old_ptr->u.sym;
4666
      /* PR binutils/17512: Point the lineno to where
4667
         this entry will be after the memcpy below.  */
4668
1.42k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4669
      /* Copy the function and line number entries.  */
4670
1.42k
      do
4671
2.92k
        *n_cache_ptr++ = *old_ptr++;
4672
2.92k
      while (old_ptr->line_number != 0);
4673
1.42k
    }
4674
4675
3
        memcpy (lineno_cache, n_lineno_cache,
4676
3
          asect->lineno_count * sizeof (alent));
4677
3
      }
4678
0
    else
4679
0
      ret = false;
4680
3
    bfd_release (abfd, func_table);
4681
3
  }
4682
0
      else
4683
0
  ret = false;
4684
3
    }
4685
4686
3
  return ret;
4687
3
}
pe-x86_64.c:coff_slurp_line_table
Line
Count
Source
4490
66
{
4491
66
  LINENO *native_lineno;
4492
66
  alent *lineno_cache;
4493
66
  unsigned int counter;
4494
66
  alent *cache_ptr;
4495
66
  bfd_vma prev_offset = 0;
4496
66
  bool ordered = true;
4497
66
  unsigned int nbr_func;
4498
66
  LINENO *src;
4499
66
  bool have_func;
4500
66
  bool ret = true;
4501
66
  size_t amt;
4502
4503
66
  if (asect->lineno_count == 0)
4504
43
    return true;
4505
4506
23
  BFD_ASSERT (asect->lineno == NULL);
4507
4508
23
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4509
23
             asect->lineno_count,
4510
23
             bfd_coff_linesz (abfd));
4511
23
  if (native_lineno == NULL)
4512
11
    {
4513
11
      _bfd_error_handler
4514
11
  (_("%pB: warning: line number table read failed"), abfd);
4515
11
      return false;
4516
11
    }
4517
4518
12
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4519
0
    {
4520
0
      bfd_set_error (bfd_error_file_too_big);
4521
0
      free (native_lineno);
4522
0
      return false;
4523
0
    }
4524
12
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4525
12
  if (lineno_cache == NULL)
4526
0
    {
4527
0
      free (native_lineno);
4528
0
      return false;
4529
0
    }
4530
4531
12
  cache_ptr = lineno_cache;
4532
12
  asect->lineno = lineno_cache;
4533
12
  src = native_lineno;
4534
12
  nbr_func = 0;
4535
12
  have_func = false;
4536
4537
7.77k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4538
7.75k
    {
4539
7.75k
      struct internal_lineno dst;
4540
4541
7.75k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4542
7.75k
      cache_ptr->line_number = dst.l_lnno;
4543
      /* Appease memory checkers that get all excited about
4544
   uninitialised memory when copying alents if u.offset is
4545
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4546
7.75k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4547
4548
7.75k
      if (cache_ptr->line_number == 0)
4549
3.77k
  {
4550
3.77k
    combined_entry_type * ent;
4551
3.77k
    unsigned long symndx;
4552
3.77k
    coff_symbol_type *sym;
4553
4554
3.77k
    have_func = false;
4555
3.77k
    symndx = dst.l_addr.l_symndx;
4556
3.77k
    if (symndx >= obj_raw_syment_count (abfd))
4557
2.16k
      {
4558
2.16k
        _bfd_error_handler
4559
    /* xgettext:c-format */
4560
2.16k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4561
2.16k
     abfd, symndx, counter);
4562
2.16k
        cache_ptr->line_number = -1;
4563
2.16k
        ret = false;
4564
2.16k
        continue;
4565
2.16k
      }
4566
4567
1.61k
    ent = obj_raw_syments (abfd) + symndx;
4568
    /* FIXME: We should not be casting between ints and
4569
       pointers like this.  */
4570
1.61k
    if (! ent->is_sym)
4571
521
      {
4572
521
        _bfd_error_handler
4573
    /* xgettext:c-format */
4574
521
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4575
521
     abfd, symndx, counter);
4576
521
        cache_ptr->line_number = -1;
4577
521
        ret = false;
4578
521
        continue;
4579
521
      }
4580
1.09k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4581
4582
    /* PR 17512 file: 078-10659-0.004  */
4583
1.09k
    if (sym < obj_symbols (abfd)
4584
1.09k
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4585
0
      {
4586
0
        _bfd_error_handler
4587
    /* xgettext:c-format */
4588
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4589
0
     abfd, counter);
4590
0
        cache_ptr->line_number = -1;
4591
0
        ret = false;
4592
0
        continue;
4593
0
      }
4594
4595
1.09k
    have_func = true;
4596
1.09k
    nbr_func++;
4597
1.09k
    cache_ptr->u.sym = (asymbol *) sym;
4598
1.09k
    if (sym->lineno != NULL)
4599
1.04k
      _bfd_error_handler
4600
        /* xgettext:c-format */
4601
1.04k
        (_("%pB: warning: duplicate line number information for `%s'"),
4602
1.04k
         abfd, bfd_asymbol_name (&sym->symbol));
4603
4604
1.09k
    sym->lineno = cache_ptr;
4605
1.09k
    if (sym->symbol.value < prev_offset)
4606
48
      ordered = false;
4607
1.09k
    prev_offset = sym->symbol.value;
4608
1.09k
  }
4609
3.98k
      else if (!have_func)
4610
  /* Drop line information that has no associated function.
4611
     PR 17521: file: 078-10659-0.004.  */
4612
3.08k
  continue;
4613
893
      else
4614
893
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4615
1.98k
      cache_ptr++;
4616
1.98k
    }
4617
4618
12
  asect->lineno_count = cache_ptr - lineno_cache;
4619
12
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4620
12
  free (native_lineno);
4621
4622
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4623
12
  if (!ordered)
4624
2
    {
4625
      /* Sort the table.  */
4626
2
      alent **func_table;
4627
2
      alent *n_lineno_cache;
4628
4629
      /* Create a table of functions.  */
4630
2
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4631
0
  {
4632
0
    bfd_set_error (bfd_error_file_too_big);
4633
0
    ret = false;
4634
0
  }
4635
2
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4636
2
  {
4637
2
    alent **p = func_table;
4638
2
    unsigned int i;
4639
4640
1.98k
    for (i = 0; i < asect->lineno_count; i++)
4641
1.98k
      if (lineno_cache[i].line_number == 0)
4642
1.09k
        *p++ = &lineno_cache[i];
4643
4644
2
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4645
4646
    /* Sort by functions.  */
4647
2
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4648
4649
    /* Create the new sorted table.  */
4650
2
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4651
0
      {
4652
0
        bfd_set_error (bfd_error_file_too_big);
4653
0
        ret = false;
4654
0
      }
4655
2
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4656
2
      {
4657
2
        alent *n_cache_ptr = n_lineno_cache;
4658
4659
1.09k
        for (i = 0; i < nbr_func; i++)
4660
1.09k
    {
4661
1.09k
      coff_symbol_type *sym;
4662
1.09k
      alent *old_ptr = func_table[i];
4663
4664
      /* Update the function entry.  */
4665
1.09k
      sym = (coff_symbol_type *) old_ptr->u.sym;
4666
      /* PR binutils/17512: Point the lineno to where
4667
         this entry will be after the memcpy below.  */
4668
1.09k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4669
      /* Copy the function and line number entries.  */
4670
1.09k
      do
4671
1.98k
        *n_cache_ptr++ = *old_ptr++;
4672
1.98k
      while (old_ptr->line_number != 0);
4673
1.09k
    }
4674
4675
2
        memcpy (lineno_cache, n_lineno_cache,
4676
2
          asect->lineno_count * sizeof (alent));
4677
2
      }
4678
0
    else
4679
0
      ret = false;
4680
2
    bfd_release (abfd, func_table);
4681
2
  }
4682
0
      else
4683
0
  ret = false;
4684
2
    }
4685
4686
12
  return ret;
4687
12
}
pei-x86_64.c:coff_slurp_line_table
Line
Count
Source
4490
371
{
4491
371
  LINENO *native_lineno;
4492
371
  alent *lineno_cache;
4493
371
  unsigned int counter;
4494
371
  alent *cache_ptr;
4495
371
  bfd_vma prev_offset = 0;
4496
371
  bool ordered = true;
4497
371
  unsigned int nbr_func;
4498
371
  LINENO *src;
4499
371
  bool have_func;
4500
371
  bool ret = true;
4501
371
  size_t amt;
4502
4503
371
  if (asect->lineno_count == 0)
4504
340
    return true;
4505
4506
31
  BFD_ASSERT (asect->lineno == NULL);
4507
4508
31
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4509
31
             asect->lineno_count,
4510
31
             bfd_coff_linesz (abfd));
4511
31
  if (native_lineno == NULL)
4512
26
    {
4513
26
      _bfd_error_handler
4514
26
  (_("%pB: warning: line number table read failed"), abfd);
4515
26
      return false;
4516
26
    }
4517
4518
5
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4519
0
    {
4520
0
      bfd_set_error (bfd_error_file_too_big);
4521
0
      free (native_lineno);
4522
0
      return false;
4523
0
    }
4524
5
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4525
5
  if (lineno_cache == NULL)
4526
0
    {
4527
0
      free (native_lineno);
4528
0
      return false;
4529
0
    }
4530
4531
5
  cache_ptr = lineno_cache;
4532
5
  asect->lineno = lineno_cache;
4533
5
  src = native_lineno;
4534
5
  nbr_func = 0;
4535
5
  have_func = false;
4536
4537
20.4k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4538
20.4k
    {
4539
20.4k
      struct internal_lineno dst;
4540
4541
20.4k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4542
20.4k
      cache_ptr->line_number = dst.l_lnno;
4543
      /* Appease memory checkers that get all excited about
4544
   uninitialised memory when copying alents if u.offset is
4545
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4546
20.4k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4547
4548
20.4k
      if (cache_ptr->line_number == 0)
4549
14.8k
  {
4550
14.8k
    combined_entry_type * ent;
4551
14.8k
    unsigned long symndx;
4552
14.8k
    coff_symbol_type *sym;
4553
4554
14.8k
    have_func = false;
4555
14.8k
    symndx = dst.l_addr.l_symndx;
4556
14.8k
    if (symndx >= obj_raw_syment_count (abfd))
4557
2.49k
      {
4558
2.49k
        _bfd_error_handler
4559
    /* xgettext:c-format */
4560
2.49k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4561
2.49k
     abfd, symndx, counter);
4562
2.49k
        cache_ptr->line_number = -1;
4563
2.49k
        ret = false;
4564
2.49k
        continue;
4565
2.49k
      }
4566
4567
12.3k
    ent = obj_raw_syments (abfd) + symndx;
4568
    /* FIXME: We should not be casting between ints and
4569
       pointers like this.  */
4570
12.3k
    if (! ent->is_sym)
4571
235
      {
4572
235
        _bfd_error_handler
4573
    /* xgettext:c-format */
4574
235
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4575
235
     abfd, symndx, counter);
4576
235
        cache_ptr->line_number = -1;
4577
235
        ret = false;
4578
235
        continue;
4579
235
      }
4580
12.1k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4581
4582
    /* PR 17512 file: 078-10659-0.004  */
4583
12.1k
    if (sym < obj_symbols (abfd)
4584
12.1k
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4585
0
      {
4586
0
        _bfd_error_handler
4587
    /* xgettext:c-format */
4588
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4589
0
     abfd, counter);
4590
0
        cache_ptr->line_number = -1;
4591
0
        ret = false;
4592
0
        continue;
4593
0
      }
4594
4595
12.1k
    have_func = true;
4596
12.1k
    nbr_func++;
4597
12.1k
    cache_ptr->u.sym = (asymbol *) sym;
4598
12.1k
    if (sym->lineno != NULL)
4599
11.9k
      _bfd_error_handler
4600
        /* xgettext:c-format */
4601
11.9k
        (_("%pB: warning: duplicate line number information for `%s'"),
4602
11.9k
         abfd, bfd_asymbol_name (&sym->symbol));
4603
4604
12.1k
    sym->lineno = cache_ptr;
4605
12.1k
    if (sym->symbol.value < prev_offset)
4606
242
      ordered = false;
4607
12.1k
    prev_offset = sym->symbol.value;
4608
12.1k
  }
4609
5.64k
      else if (!have_func)
4610
  /* Drop line information that has no associated function.
4611
     PR 17521: file: 078-10659-0.004.  */
4612
1.49k
  continue;
4613
4.14k
      else
4614
4.14k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4615
16.2k
      cache_ptr++;
4616
16.2k
    }
4617
4618
5
  asect->lineno_count = cache_ptr - lineno_cache;
4619
5
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4620
5
  free (native_lineno);
4621
4622
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4623
5
  if (!ordered)
4624
5
    {
4625
      /* Sort the table.  */
4626
5
      alent **func_table;
4627
5
      alent *n_lineno_cache;
4628
4629
      /* Create a table of functions.  */
4630
5
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4631
0
  {
4632
0
    bfd_set_error (bfd_error_file_too_big);
4633
0
    ret = false;
4634
0
  }
4635
5
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4636
5
  {
4637
5
    alent **p = func_table;
4638
5
    unsigned int i;
4639
4640
16.2k
    for (i = 0; i < asect->lineno_count; i++)
4641
16.2k
      if (lineno_cache[i].line_number == 0)
4642
12.1k
        *p++ = &lineno_cache[i];
4643
4644
5
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4645
4646
    /* Sort by functions.  */
4647
5
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4648
4649
    /* Create the new sorted table.  */
4650
5
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4651
0
      {
4652
0
        bfd_set_error (bfd_error_file_too_big);
4653
0
        ret = false;
4654
0
      }
4655
5
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4656
5
      {
4657
5
        alent *n_cache_ptr = n_lineno_cache;
4658
4659
12.1k
        for (i = 0; i < nbr_func; i++)
4660
12.1k
    {
4661
12.1k
      coff_symbol_type *sym;
4662
12.1k
      alent *old_ptr = func_table[i];
4663
4664
      /* Update the function entry.  */
4665
12.1k
      sym = (coff_symbol_type *) old_ptr->u.sym;
4666
      /* PR binutils/17512: Point the lineno to where
4667
         this entry will be after the memcpy below.  */
4668
12.1k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4669
      /* Copy the function and line number entries.  */
4670
12.1k
      do
4671
16.2k
        *n_cache_ptr++ = *old_ptr++;
4672
16.2k
      while (old_ptr->line_number != 0);
4673
12.1k
    }
4674
4675
5
        memcpy (lineno_cache, n_lineno_cache,
4676
5
          asect->lineno_count * sizeof (alent));
4677
5
      }
4678
0
    else
4679
0
      ret = false;
4680
5
    bfd_release (abfd, func_table);
4681
5
  }
4682
0
      else
4683
0
  ret = false;
4684
5
    }
4685
4686
5
  return ret;
4687
5
}
coff-x86_64.c:coff_slurp_line_table
Line
Count
Source
4490
1.63k
{
4491
1.63k
  LINENO *native_lineno;
4492
1.63k
  alent *lineno_cache;
4493
1.63k
  unsigned int counter;
4494
1.63k
  alent *cache_ptr;
4495
1.63k
  bfd_vma prev_offset = 0;
4496
1.63k
  bool ordered = true;
4497
1.63k
  unsigned int nbr_func;
4498
1.63k
  LINENO *src;
4499
1.63k
  bool have_func;
4500
1.63k
  bool ret = true;
4501
1.63k
  size_t amt;
4502
4503
1.63k
  if (asect->lineno_count == 0)
4504
1.58k
    return true;
4505
4506
46
  BFD_ASSERT (asect->lineno == NULL);
4507
4508
46
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4509
46
             asect->lineno_count,
4510
46
             bfd_coff_linesz (abfd));
4511
46
  if (native_lineno == NULL)
4512
20
    {
4513
20
      _bfd_error_handler
4514
20
  (_("%pB: warning: line number table read failed"), abfd);
4515
20
      return false;
4516
20
    }
4517
4518
26
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4519
0
    {
4520
0
      bfd_set_error (bfd_error_file_too_big);
4521
0
      free (native_lineno);
4522
0
      return false;
4523
0
    }
4524
26
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4525
26
  if (lineno_cache == NULL)
4526
0
    {
4527
0
      free (native_lineno);
4528
0
      return false;
4529
0
    }
4530
4531
26
  cache_ptr = lineno_cache;
4532
26
  asect->lineno = lineno_cache;
4533
26
  src = native_lineno;
4534
26
  nbr_func = 0;
4535
26
  have_func = false;
4536
4537
246k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4538
246k
    {
4539
246k
      struct internal_lineno dst;
4540
4541
246k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4542
246k
      cache_ptr->line_number = dst.l_lnno;
4543
      /* Appease memory checkers that get all excited about
4544
   uninitialised memory when copying alents if u.offset is
4545
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4546
246k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4547
4548
246k
      if (cache_ptr->line_number == 0)
4549
81.5k
  {
4550
81.5k
    combined_entry_type * ent;
4551
81.5k
    unsigned long symndx;
4552
81.5k
    coff_symbol_type *sym;
4553
4554
81.5k
    have_func = false;
4555
81.5k
    symndx = dst.l_addr.l_symndx;
4556
81.5k
    if (symndx >= obj_raw_syment_count (abfd))
4557
36.0k
      {
4558
36.0k
        _bfd_error_handler
4559
    /* xgettext:c-format */
4560
36.0k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4561
36.0k
     abfd, symndx, counter);
4562
36.0k
        cache_ptr->line_number = -1;
4563
36.0k
        ret = false;
4564
36.0k
        continue;
4565
36.0k
      }
4566
4567
45.4k
    ent = obj_raw_syments (abfd) + symndx;
4568
    /* FIXME: We should not be casting between ints and
4569
       pointers like this.  */
4570
45.4k
    if (! ent->is_sym)
4571
11.2k
      {
4572
11.2k
        _bfd_error_handler
4573
    /* xgettext:c-format */
4574
11.2k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4575
11.2k
     abfd, symndx, counter);
4576
11.2k
        cache_ptr->line_number = -1;
4577
11.2k
        ret = false;
4578
11.2k
        continue;
4579
11.2k
      }
4580
34.2k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4581
4582
    /* PR 17512 file: 078-10659-0.004  */
4583
34.2k
    if (sym < obj_symbols (abfd)
4584
34.2k
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4585
0
      {
4586
0
        _bfd_error_handler
4587
    /* xgettext:c-format */
4588
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4589
0
     abfd, counter);
4590
0
        cache_ptr->line_number = -1;
4591
0
        ret = false;
4592
0
        continue;
4593
0
      }
4594
4595
34.2k
    have_func = true;
4596
34.2k
    nbr_func++;
4597
34.2k
    cache_ptr->u.sym = (asymbol *) sym;
4598
34.2k
    if (sym->lineno != NULL)
4599
33.8k
      _bfd_error_handler
4600
        /* xgettext:c-format */
4601
33.8k
        (_("%pB: warning: duplicate line number information for `%s'"),
4602
33.8k
         abfd, bfd_asymbol_name (&sym->symbol));
4603
4604
34.2k
    sym->lineno = cache_ptr;
4605
34.2k
    if (sym->symbol.value < prev_offset)
4606
751
      ordered = false;
4607
34.2k
    prev_offset = sym->symbol.value;
4608
34.2k
  }
4609
164k
      else if (!have_func)
4610
  /* Drop line information that has no associated function.
4611
     PR 17521: file: 078-10659-0.004.  */
4612
118k
  continue;
4613
46.8k
      else
4614
46.8k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4615
81.1k
      cache_ptr++;
4616
81.1k
    }
4617
4618
26
  asect->lineno_count = cache_ptr - lineno_cache;
4619
26
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4620
26
  free (native_lineno);
4621
4622
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4623
26
  if (!ordered)
4624
17
    {
4625
      /* Sort the table.  */
4626
17
      alent **func_table;
4627
17
      alent *n_lineno_cache;
4628
4629
      /* Create a table of functions.  */
4630
17
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4631
0
  {
4632
0
    bfd_set_error (bfd_error_file_too_big);
4633
0
    ret = false;
4634
0
  }
4635
17
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4636
17
  {
4637
17
    alent **p = func_table;
4638
17
    unsigned int i;
4639
4640
81.1k
    for (i = 0; i < asect->lineno_count; i++)
4641
81.1k
      if (lineno_cache[i].line_number == 0)
4642
34.2k
        *p++ = &lineno_cache[i];
4643
4644
17
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4645
4646
    /* Sort by functions.  */
4647
17
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4648
4649
    /* Create the new sorted table.  */
4650
17
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4651
0
      {
4652
0
        bfd_set_error (bfd_error_file_too_big);
4653
0
        ret = false;
4654
0
      }
4655
17
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4656
17
      {
4657
17
        alent *n_cache_ptr = n_lineno_cache;
4658
4659
34.2k
        for (i = 0; i < nbr_func; i++)
4660
34.2k
    {
4661
34.2k
      coff_symbol_type *sym;
4662
34.2k
      alent *old_ptr = func_table[i];
4663
4664
      /* Update the function entry.  */
4665
34.2k
      sym = (coff_symbol_type *) old_ptr->u.sym;
4666
      /* PR binutils/17512: Point the lineno to where
4667
         this entry will be after the memcpy below.  */
4668
34.2k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4669
      /* Copy the function and line number entries.  */
4670
34.2k
      do
4671
81.1k
        *n_cache_ptr++ = *old_ptr++;
4672
81.1k
      while (old_ptr->line_number != 0);
4673
34.2k
    }
4674
4675
17
        memcpy (lineno_cache, n_lineno_cache,
4676
17
          asect->lineno_count * sizeof (alent));
4677
17
      }
4678
0
    else
4679
0
      ret = false;
4680
17
    bfd_release (abfd, func_table);
4681
17
  }
4682
0
      else
4683
0
  ret = false;
4684
17
    }
4685
4686
26
  return ret;
4687
26
}
coff64-rs6000.c:coff_slurp_line_table
Line
Count
Source
4490
513
{
4491
513
  LINENO *native_lineno;
4492
513
  alent *lineno_cache;
4493
513
  unsigned int counter;
4494
513
  alent *cache_ptr;
4495
513
  bfd_vma prev_offset = 0;
4496
513
  bool ordered = true;
4497
513
  unsigned int nbr_func;
4498
513
  LINENO *src;
4499
513
  bool have_func;
4500
513
  bool ret = true;
4501
513
  size_t amt;
4502
4503
513
  if (asect->lineno_count == 0)
4504
431
    return true;
4505
4506
82
  BFD_ASSERT (asect->lineno == NULL);
4507
4508
82
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4509
82
             asect->lineno_count,
4510
82
             bfd_coff_linesz (abfd));
4511
82
  if (native_lineno == NULL)
4512
49
    {
4513
49
      _bfd_error_handler
4514
49
  (_("%pB: warning: line number table read failed"), abfd);
4515
49
      return false;
4516
49
    }
4517
4518
33
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4519
0
    {
4520
0
      bfd_set_error (bfd_error_file_too_big);
4521
0
      free (native_lineno);
4522
0
      return false;
4523
0
    }
4524
33
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4525
33
  if (lineno_cache == NULL)
4526
0
    {
4527
0
      free (native_lineno);
4528
0
      return false;
4529
0
    }
4530
4531
33
  cache_ptr = lineno_cache;
4532
33
  asect->lineno = lineno_cache;
4533
33
  src = native_lineno;
4534
33
  nbr_func = 0;
4535
33
  have_func = false;
4536
4537
240k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4538
239k
    {
4539
239k
      struct internal_lineno dst;
4540
4541
239k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4542
239k
      cache_ptr->line_number = dst.l_lnno;
4543
      /* Appease memory checkers that get all excited about
4544
   uninitialised memory when copying alents if u.offset is
4545
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4546
239k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4547
4548
239k
      if (cache_ptr->line_number == 0)
4549
65.2k
  {
4550
65.2k
    combined_entry_type * ent;
4551
65.2k
    unsigned long symndx;
4552
65.2k
    coff_symbol_type *sym;
4553
4554
65.2k
    have_func = false;
4555
65.2k
    symndx = dst.l_addr.l_symndx;
4556
65.2k
    if (symndx >= obj_raw_syment_count (abfd))
4557
19.4k
      {
4558
19.4k
        _bfd_error_handler
4559
    /* xgettext:c-format */
4560
19.4k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4561
19.4k
     abfd, symndx, counter);
4562
19.4k
        cache_ptr->line_number = -1;
4563
19.4k
        ret = false;
4564
19.4k
        continue;
4565
19.4k
      }
4566
4567
45.8k
    ent = obj_raw_syments (abfd) + symndx;
4568
    /* FIXME: We should not be casting between ints and
4569
       pointers like this.  */
4570
45.8k
    if (! ent->is_sym)
4571
3.63k
      {
4572
3.63k
        _bfd_error_handler
4573
    /* xgettext:c-format */
4574
3.63k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4575
3.63k
     abfd, symndx, counter);
4576
3.63k
        cache_ptr->line_number = -1;
4577
3.63k
        ret = false;
4578
3.63k
        continue;
4579
3.63k
      }
4580
42.1k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4581
4582
    /* PR 17512 file: 078-10659-0.004  */
4583
42.1k
    if (sym < obj_symbols (abfd)
4584
42.1k
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4585
0
      {
4586
0
        _bfd_error_handler
4587
    /* xgettext:c-format */
4588
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4589
0
     abfd, counter);
4590
0
        cache_ptr->line_number = -1;
4591
0
        ret = false;
4592
0
        continue;
4593
0
      }
4594
4595
42.1k
    have_func = true;
4596
42.1k
    nbr_func++;
4597
42.1k
    cache_ptr->u.sym = (asymbol *) sym;
4598
42.1k
    if (sym->lineno != NULL)
4599
41.9k
      _bfd_error_handler
4600
        /* xgettext:c-format */
4601
41.9k
        (_("%pB: warning: duplicate line number information for `%s'"),
4602
41.9k
         abfd, bfd_asymbol_name (&sym->symbol));
4603
4604
42.1k
    sym->lineno = cache_ptr;
4605
42.1k
    if (sym->symbol.value < prev_offset)
4606
457
      ordered = false;
4607
42.1k
    prev_offset = sym->symbol.value;
4608
42.1k
  }
4609
174k
      else if (!have_func)
4610
  /* Drop line information that has no associated function.
4611
     PR 17521: file: 078-10659-0.004.  */
4612
88.2k
  continue;
4613
86.4k
      else
4614
86.4k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4615
128k
      cache_ptr++;
4616
128k
    }
4617
4618
33
  asect->lineno_count = cache_ptr - lineno_cache;
4619
33
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4620
33
  free (native_lineno);
4621
4622
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4623
33
  if (!ordered)
4624
28
    {
4625
      /* Sort the table.  */
4626
28
      alent **func_table;
4627
28
      alent *n_lineno_cache;
4628
4629
      /* Create a table of functions.  */
4630
28
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4631
0
  {
4632
0
    bfd_set_error (bfd_error_file_too_big);
4633
0
    ret = false;
4634
0
  }
4635
28
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4636
28
  {
4637
28
    alent **p = func_table;
4638
28
    unsigned int i;
4639
4640
112k
    for (i = 0; i < asect->lineno_count; i++)
4641
112k
      if (lineno_cache[i].line_number == 0)
4642
37.4k
        *p++ = &lineno_cache[i];
4643
4644
28
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4645
4646
    /* Sort by functions.  */
4647
28
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4648
4649
    /* Create the new sorted table.  */
4650
28
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4651
0
      {
4652
0
        bfd_set_error (bfd_error_file_too_big);
4653
0
        ret = false;
4654
0
      }
4655
28
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4656
28
      {
4657
28
        alent *n_cache_ptr = n_lineno_cache;
4658
4659
37.4k
        for (i = 0; i < nbr_func; i++)
4660
37.4k
    {
4661
37.4k
      coff_symbol_type *sym;
4662
37.4k
      alent *old_ptr = func_table[i];
4663
4664
      /* Update the function entry.  */
4665
37.4k
      sym = (coff_symbol_type *) old_ptr->u.sym;
4666
      /* PR binutils/17512: Point the lineno to where
4667
         this entry will be after the memcpy below.  */
4668
37.4k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4669
      /* Copy the function and line number entries.  */
4670
37.4k
      do
4671
112k
        *n_cache_ptr++ = *old_ptr++;
4672
112k
      while (old_ptr->line_number != 0);
4673
37.4k
    }
4674
4675
28
        memcpy (lineno_cache, n_lineno_cache,
4676
28
          asect->lineno_count * sizeof (alent));
4677
28
      }
4678
0
    else
4679
0
      ret = false;
4680
28
    bfd_release (abfd, func_table);
4681
28
  }
4682
0
      else
4683
0
  ret = false;
4684
28
    }
4685
4686
33
  return ret;
4687
33
}
pe-aarch64.c:coff_slurp_line_table
Line
Count
Source
4490
33
{
4491
33
  LINENO *native_lineno;
4492
33
  alent *lineno_cache;
4493
33
  unsigned int counter;
4494
33
  alent *cache_ptr;
4495
33
  bfd_vma prev_offset = 0;
4496
33
  bool ordered = true;
4497
33
  unsigned int nbr_func;
4498
33
  LINENO *src;
4499
33
  bool have_func;
4500
33
  bool ret = true;
4501
33
  size_t amt;
4502
4503
33
  if (asect->lineno_count == 0)
4504
7
    return true;
4505
4506
26
  BFD_ASSERT (asect->lineno == NULL);
4507
4508
26
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4509
26
             asect->lineno_count,
4510
26
             bfd_coff_linesz (abfd));
4511
26
  if (native_lineno == NULL)
4512
12
    {
4513
12
      _bfd_error_handler
4514
12
  (_("%pB: warning: line number table read failed"), abfd);
4515
12
      return false;
4516
12
    }
4517
4518
14
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4519
0
    {
4520
0
      bfd_set_error (bfd_error_file_too_big);
4521
0
      free (native_lineno);
4522
0
      return false;
4523
0
    }
4524
14
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4525
14
  if (lineno_cache == NULL)
4526
0
    {
4527
0
      free (native_lineno);
4528
0
      return false;
4529
0
    }
4530
4531
14
  cache_ptr = lineno_cache;
4532
14
  asect->lineno = lineno_cache;
4533
14
  src = native_lineno;
4534
14
  nbr_func = 0;
4535
14
  have_func = false;
4536
4537
9.63k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4538
9.62k
    {
4539
9.62k
      struct internal_lineno dst;
4540
4541
9.62k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4542
9.62k
      cache_ptr->line_number = dst.l_lnno;
4543
      /* Appease memory checkers that get all excited about
4544
   uninitialised memory when copying alents if u.offset is
4545
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4546
9.62k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4547
4548
9.62k
      if (cache_ptr->line_number == 0)
4549
4.35k
  {
4550
4.35k
    combined_entry_type * ent;
4551
4.35k
    unsigned long symndx;
4552
4.35k
    coff_symbol_type *sym;
4553
4554
4.35k
    have_func = false;
4555
4.35k
    symndx = dst.l_addr.l_symndx;
4556
4.35k
    if (symndx >= obj_raw_syment_count (abfd))
4557
3.20k
      {
4558
3.20k
        _bfd_error_handler
4559
    /* xgettext:c-format */
4560
3.20k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4561
3.20k
     abfd, symndx, counter);
4562
3.20k
        cache_ptr->line_number = -1;
4563
3.20k
        ret = false;
4564
3.20k
        continue;
4565
3.20k
      }
4566
4567
1.15k
    ent = obj_raw_syments (abfd) + symndx;
4568
    /* FIXME: We should not be casting between ints and
4569
       pointers like this.  */
4570
1.15k
    if (! ent->is_sym)
4571
144
      {
4572
144
        _bfd_error_handler
4573
    /* xgettext:c-format */
4574
144
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4575
144
     abfd, symndx, counter);
4576
144
        cache_ptr->line_number = -1;
4577
144
        ret = false;
4578
144
        continue;
4579
144
      }
4580
1.01k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4581
4582
    /* PR 17512 file: 078-10659-0.004  */
4583
1.01k
    if (sym < obj_symbols (abfd)
4584
1.01k
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4585
0
      {
4586
0
        _bfd_error_handler
4587
    /* xgettext:c-format */
4588
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4589
0
     abfd, counter);
4590
0
        cache_ptr->line_number = -1;
4591
0
        ret = false;
4592
0
        continue;
4593
0
      }
4594
4595
1.01k
    have_func = true;
4596
1.01k
    nbr_func++;
4597
1.01k
    cache_ptr->u.sym = (asymbol *) sym;
4598
1.01k
    if (sym->lineno != NULL)
4599
1.00k
      _bfd_error_handler
4600
        /* xgettext:c-format */
4601
1.00k
        (_("%pB: warning: duplicate line number information for `%s'"),
4602
1.00k
         abfd, bfd_asymbol_name (&sym->symbol));
4603
4604
1.01k
    sym->lineno = cache_ptr;
4605
1.01k
    if (sym->symbol.value < prev_offset)
4606
17
      ordered = false;
4607
1.01k
    prev_offset = sym->symbol.value;
4608
1.01k
  }
4609
5.26k
      else if (!have_func)
4610
  /* Drop line information that has no associated function.
4611
     PR 17521: file: 078-10659-0.004.  */
4612
3.74k
  continue;
4613
1.51k
      else
4614
1.51k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4615
2.52k
      cache_ptr++;
4616
2.52k
    }
4617
4618
14
  asect->lineno_count = cache_ptr - lineno_cache;
4619
14
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4620
14
  free (native_lineno);
4621
4622
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4623
14
  if (!ordered)
4624
2
    {
4625
      /* Sort the table.  */
4626
2
      alent **func_table;
4627
2
      alent *n_lineno_cache;
4628
4629
      /* Create a table of functions.  */
4630
2
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4631
0
  {
4632
0
    bfd_set_error (bfd_error_file_too_big);
4633
0
    ret = false;
4634
0
  }
4635
2
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4636
2
  {
4637
2
    alent **p = func_table;
4638
2
    unsigned int i;
4639
4640
2.53k
    for (i = 0; i < asect->lineno_count; i++)
4641
2.52k
      if (lineno_cache[i].line_number == 0)
4642
1.01k
        *p++ = &lineno_cache[i];
4643
4644
2
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4645
4646
    /* Sort by functions.  */
4647
2
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4648
4649
    /* Create the new sorted table.  */
4650
2
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4651
0
      {
4652
0
        bfd_set_error (bfd_error_file_too_big);
4653
0
        ret = false;
4654
0
      }
4655
2
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4656
2
      {
4657
2
        alent *n_cache_ptr = n_lineno_cache;
4658
4659
1.01k
        for (i = 0; i < nbr_func; i++)
4660
1.01k
    {
4661
1.01k
      coff_symbol_type *sym;
4662
1.01k
      alent *old_ptr = func_table[i];
4663
4664
      /* Update the function entry.  */
4665
1.01k
      sym = (coff_symbol_type *) old_ptr->u.sym;
4666
      /* PR binutils/17512: Point the lineno to where
4667
         this entry will be after the memcpy below.  */
4668
1.01k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4669
      /* Copy the function and line number entries.  */
4670
1.01k
      do
4671
2.52k
        *n_cache_ptr++ = *old_ptr++;
4672
2.52k
      while (old_ptr->line_number != 0);
4673
1.01k
    }
4674
4675
2
        memcpy (lineno_cache, n_lineno_cache,
4676
2
          asect->lineno_count * sizeof (alent));
4677
2
      }
4678
0
    else
4679
0
      ret = false;
4680
2
    bfd_release (abfd, func_table);
4681
2
  }
4682
0
      else
4683
0
  ret = false;
4684
2
    }
4685
4686
14
  return ret;
4687
14
}
pei-aarch64.c:coff_slurp_line_table
Line
Count
Source
4490
1.02k
{
4491
1.02k
  LINENO *native_lineno;
4492
1.02k
  alent *lineno_cache;
4493
1.02k
  unsigned int counter;
4494
1.02k
  alent *cache_ptr;
4495
1.02k
  bfd_vma prev_offset = 0;
4496
1.02k
  bool ordered = true;
4497
1.02k
  unsigned int nbr_func;
4498
1.02k
  LINENO *src;
4499
1.02k
  bool have_func;
4500
1.02k
  bool ret = true;
4501
1.02k
  size_t amt;
4502
4503
1.02k
  if (asect->lineno_count == 0)
4504
1.00k
    return true;
4505
4506
13
  BFD_ASSERT (asect->lineno == NULL);
4507
4508
13
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4509
13
             asect->lineno_count,
4510
13
             bfd_coff_linesz (abfd));
4511
13
  if (native_lineno == NULL)
4512
11
    {
4513
11
      _bfd_error_handler
4514
11
  (_("%pB: warning: line number table read failed"), abfd);
4515
11
      return false;
4516
11
    }
4517
4518
2
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4519
0
    {
4520
0
      bfd_set_error (bfd_error_file_too_big);
4521
0
      free (native_lineno);
4522
0
      return false;
4523
0
    }
4524
2
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4525
2
  if (lineno_cache == NULL)
4526
0
    {
4527
0
      free (native_lineno);
4528
0
      return false;
4529
0
    }
4530
4531
2
  cache_ptr = lineno_cache;
4532
2
  asect->lineno = lineno_cache;
4533
2
  src = native_lineno;
4534
2
  nbr_func = 0;
4535
2
  have_func = false;
4536
4537
1.83k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4538
1.82k
    {
4539
1.82k
      struct internal_lineno dst;
4540
4541
1.82k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4542
1.82k
      cache_ptr->line_number = dst.l_lnno;
4543
      /* Appease memory checkers that get all excited about
4544
   uninitialised memory when copying alents if u.offset is
4545
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4546
1.82k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4547
4548
1.82k
      if (cache_ptr->line_number == 0)
4549
748
  {
4550
748
    combined_entry_type * ent;
4551
748
    unsigned long symndx;
4552
748
    coff_symbol_type *sym;
4553
4554
748
    have_func = false;
4555
748
    symndx = dst.l_addr.l_symndx;
4556
748
    if (symndx >= obj_raw_syment_count (abfd))
4557
349
      {
4558
349
        _bfd_error_handler
4559
    /* xgettext:c-format */
4560
349
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4561
349
     abfd, symndx, counter);
4562
349
        cache_ptr->line_number = -1;
4563
349
        ret = false;
4564
349
        continue;
4565
349
      }
4566
4567
399
    ent = obj_raw_syments (abfd) + symndx;
4568
    /* FIXME: We should not be casting between ints and
4569
       pointers like this.  */
4570
399
    if (! ent->is_sym)
4571
14
      {
4572
14
        _bfd_error_handler
4573
    /* xgettext:c-format */
4574
14
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4575
14
     abfd, symndx, counter);
4576
14
        cache_ptr->line_number = -1;
4577
14
        ret = false;
4578
14
        continue;
4579
14
      }
4580
385
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4581
4582
    /* PR 17512 file: 078-10659-0.004  */
4583
385
    if (sym < obj_symbols (abfd)
4584
385
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4585
0
      {
4586
0
        _bfd_error_handler
4587
    /* xgettext:c-format */
4588
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4589
0
     abfd, counter);
4590
0
        cache_ptr->line_number = -1;
4591
0
        ret = false;
4592
0
        continue;
4593
0
      }
4594
4595
385
    have_func = true;
4596
385
    nbr_func++;
4597
385
    cache_ptr->u.sym = (asymbol *) sym;
4598
385
    if (sym->lineno != NULL)
4599
380
      _bfd_error_handler
4600
        /* xgettext:c-format */
4601
380
        (_("%pB: warning: duplicate line number information for `%s'"),
4602
380
         abfd, bfd_asymbol_name (&sym->symbol));
4603
4604
385
    sym->lineno = cache_ptr;
4605
385
    if (sym->symbol.value < prev_offset)
4606
4
      ordered = false;
4607
385
    prev_offset = sym->symbol.value;
4608
385
  }
4609
1.08k
      else if (!have_func)
4610
  /* Drop line information that has no associated function.
4611
     PR 17521: file: 078-10659-0.004.  */
4612
582
  continue;
4613
499
      else
4614
499
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4615
884
      cache_ptr++;
4616
884
    }
4617
4618
2
  asect->lineno_count = cache_ptr - lineno_cache;
4619
2
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4620
2
  free (native_lineno);
4621
4622
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4623
2
  if (!ordered)
4624
1
    {
4625
      /* Sort the table.  */
4626
1
      alent **func_table;
4627
1
      alent *n_lineno_cache;
4628
4629
      /* Create a table of functions.  */
4630
1
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4631
0
  {
4632
0
    bfd_set_error (bfd_error_file_too_big);
4633
0
    ret = false;
4634
0
  }
4635
1
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4636
1
  {
4637
1
    alent **p = func_table;
4638
1
    unsigned int i;
4639
4640
857
    for (i = 0; i < asect->lineno_count; i++)
4641
856
      if (lineno_cache[i].line_number == 0)
4642
372
        *p++ = &lineno_cache[i];
4643
4644
1
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4645
4646
    /* Sort by functions.  */
4647
1
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4648
4649
    /* Create the new sorted table.  */
4650
1
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4651
0
      {
4652
0
        bfd_set_error (bfd_error_file_too_big);
4653
0
        ret = false;
4654
0
      }
4655
1
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4656
1
      {
4657
1
        alent *n_cache_ptr = n_lineno_cache;
4658
4659
373
        for (i = 0; i < nbr_func; i++)
4660
372
    {
4661
372
      coff_symbol_type *sym;
4662
372
      alent *old_ptr = func_table[i];
4663
4664
      /* Update the function entry.  */
4665
372
      sym = (coff_symbol_type *) old_ptr->u.sym;
4666
      /* PR binutils/17512: Point the lineno to where
4667
         this entry will be after the memcpy below.  */
4668
372
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4669
      /* Copy the function and line number entries.  */
4670
372
      do
4671
856
        *n_cache_ptr++ = *old_ptr++;
4672
856
      while (old_ptr->line_number != 0);
4673
372
    }
4674
4675
1
        memcpy (lineno_cache, n_lineno_cache,
4676
1
          asect->lineno_count * sizeof (alent));
4677
1
      }
4678
0
    else
4679
0
      ret = false;
4680
1
    bfd_release (abfd, func_table);
4681
1
  }
4682
0
      else
4683
0
  ret = false;
4684
1
    }
4685
4686
2
  return ret;
4687
2
}
pei-ia64.c:coff_slurp_line_table
Line
Count
Source
4490
27
{
4491
27
  LINENO *native_lineno;
4492
27
  alent *lineno_cache;
4493
27
  unsigned int counter;
4494
27
  alent *cache_ptr;
4495
27
  bfd_vma prev_offset = 0;
4496
27
  bool ordered = true;
4497
27
  unsigned int nbr_func;
4498
27
  LINENO *src;
4499
27
  bool have_func;
4500
27
  bool ret = true;
4501
27
  size_t amt;
4502
4503
27
  if (asect->lineno_count == 0)
4504
1
    return true;
4505
4506
26
  BFD_ASSERT (asect->lineno == NULL);
4507
4508
26
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4509
26
             asect->lineno_count,
4510
26
             bfd_coff_linesz (abfd));
4511
26
  if (native_lineno == NULL)
4512
2
    {
4513
2
      _bfd_error_handler
4514
2
  (_("%pB: warning: line number table read failed"), abfd);
4515
2
      return false;
4516
2
    }
4517
4518
24
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4519
0
    {
4520
0
      bfd_set_error (bfd_error_file_too_big);
4521
0
      free (native_lineno);
4522
0
      return false;
4523
0
    }
4524
24
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4525
24
  if (lineno_cache == NULL)
4526
0
    {
4527
0
      free (native_lineno);
4528
0
      return false;
4529
0
    }
4530
4531
24
  cache_ptr = lineno_cache;
4532
24
  asect->lineno = lineno_cache;
4533
24
  src = native_lineno;
4534
24
  nbr_func = 0;
4535
24
  have_func = false;
4536
4537
56.0k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4538
56.0k
    {
4539
56.0k
      struct internal_lineno dst;
4540
4541
56.0k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4542
56.0k
      cache_ptr->line_number = dst.l_lnno;
4543
      /* Appease memory checkers that get all excited about
4544
   uninitialised memory when copying alents if u.offset is
4545
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4546
56.0k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4547
4548
56.0k
      if (cache_ptr->line_number == 0)
4549
26.3k
  {
4550
26.3k
    combined_entry_type * ent;
4551
26.3k
    unsigned long symndx;
4552
26.3k
    coff_symbol_type *sym;
4553
4554
26.3k
    have_func = false;
4555
26.3k
    symndx = dst.l_addr.l_symndx;
4556
26.3k
    if (symndx >= obj_raw_syment_count (abfd))
4557
12.0k
      {
4558
12.0k
        _bfd_error_handler
4559
    /* xgettext:c-format */
4560
12.0k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4561
12.0k
     abfd, symndx, counter);
4562
12.0k
        cache_ptr->line_number = -1;
4563
12.0k
        ret = false;
4564
12.0k
        continue;
4565
12.0k
      }
4566
4567
14.3k
    ent = obj_raw_syments (abfd) + symndx;
4568
    /* FIXME: We should not be casting between ints and
4569
       pointers like this.  */
4570
14.3k
    if (! ent->is_sym)
4571
3.72k
      {
4572
3.72k
        _bfd_error_handler
4573
    /* xgettext:c-format */
4574
3.72k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4575
3.72k
     abfd, symndx, counter);
4576
3.72k
        cache_ptr->line_number = -1;
4577
3.72k
        ret = false;
4578
3.72k
        continue;
4579
3.72k
      }
4580
10.5k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4581
4582
    /* PR 17512 file: 078-10659-0.004  */
4583
10.5k
    if (sym < obj_symbols (abfd)
4584
10.5k
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4585
0
      {
4586
0
        _bfd_error_handler
4587
    /* xgettext:c-format */
4588
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4589
0
     abfd, counter);
4590
0
        cache_ptr->line_number = -1;
4591
0
        ret = false;
4592
0
        continue;
4593
0
      }
4594
4595
10.5k
    have_func = true;
4596
10.5k
    nbr_func++;
4597
10.5k
    cache_ptr->u.sym = (asymbol *) sym;
4598
10.5k
    if (sym->lineno != NULL)
4599
10.3k
      _bfd_error_handler
4600
        /* xgettext:c-format */
4601
10.3k
        (_("%pB: warning: duplicate line number information for `%s'"),
4602
10.3k
         abfd, bfd_asymbol_name (&sym->symbol));
4603
4604
10.5k
    sym->lineno = cache_ptr;
4605
10.5k
    if (sym->symbol.value < prev_offset)
4606
141
      ordered = false;
4607
10.5k
    prev_offset = sym->symbol.value;
4608
10.5k
  }
4609
29.7k
      else if (!have_func)
4610
  /* Drop line information that has no associated function.
4611
     PR 17521: file: 078-10659-0.004.  */
4612
18.4k
  continue;
4613
11.3k
      else
4614
11.3k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4615
21.8k
      cache_ptr++;
4616
21.8k
    }
4617
4618
24
  asect->lineno_count = cache_ptr - lineno_cache;
4619
24
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4620
24
  free (native_lineno);
4621
4622
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4623
24
  if (!ordered)
4624
24
    {
4625
      /* Sort the table.  */
4626
24
      alent **func_table;
4627
24
      alent *n_lineno_cache;
4628
4629
      /* Create a table of functions.  */
4630
24
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4631
0
  {
4632
0
    bfd_set_error (bfd_error_file_too_big);
4633
0
    ret = false;
4634
0
  }
4635
24
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4636
24
  {
4637
24
    alent **p = func_table;
4638
24
    unsigned int i;
4639
4640
21.9k
    for (i = 0; i < asect->lineno_count; i++)
4641
21.8k
      if (lineno_cache[i].line_number == 0)
4642
10.5k
        *p++ = &lineno_cache[i];
4643
4644
24
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4645
4646
    /* Sort by functions.  */
4647
24
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4648
4649
    /* Create the new sorted table.  */
4650
24
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4651
0
      {
4652
0
        bfd_set_error (bfd_error_file_too_big);
4653
0
        ret = false;
4654
0
      }
4655
24
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4656
24
      {
4657
24
        alent *n_cache_ptr = n_lineno_cache;
4658
4659
10.6k
        for (i = 0; i < nbr_func; i++)
4660
10.5k
    {
4661
10.5k
      coff_symbol_type *sym;
4662
10.5k
      alent *old_ptr = func_table[i];
4663
4664
      /* Update the function entry.  */
4665
10.5k
      sym = (coff_symbol_type *) old_ptr->u.sym;
4666
      /* PR binutils/17512: Point the lineno to where
4667
         this entry will be after the memcpy below.  */
4668
10.5k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4669
      /* Copy the function and line number entries.  */
4670
10.5k
      do
4671
21.8k
        *n_cache_ptr++ = *old_ptr++;
4672
21.8k
      while (old_ptr->line_number != 0);
4673
10.5k
    }
4674
4675
24
        memcpy (lineno_cache, n_lineno_cache,
4676
24
          asect->lineno_count * sizeof (alent));
4677
24
      }
4678
0
    else
4679
0
      ret = false;
4680
24
    bfd_release (abfd, func_table);
4681
24
  }
4682
0
      else
4683
0
  ret = false;
4684
24
    }
4685
4686
24
  return ret;
4687
24
}
pei-loongarch64.c:coff_slurp_line_table
Line
Count
Source
4490
121
{
4491
121
  LINENO *native_lineno;
4492
121
  alent *lineno_cache;
4493
121
  unsigned int counter;
4494
121
  alent *cache_ptr;
4495
121
  bfd_vma prev_offset = 0;
4496
121
  bool ordered = true;
4497
121
  unsigned int nbr_func;
4498
121
  LINENO *src;
4499
121
  bool have_func;
4500
121
  bool ret = true;
4501
121
  size_t amt;
4502
4503
121
  if (asect->lineno_count == 0)
4504
96
    return true;
4505
4506
25
  BFD_ASSERT (asect->lineno == NULL);
4507
4508
25
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4509
25
             asect->lineno_count,
4510
25
             bfd_coff_linesz (abfd));
4511
25
  if (native_lineno == NULL)
4512
11
    {
4513
11
      _bfd_error_handler
4514
11
  (_("%pB: warning: line number table read failed"), abfd);
4515
11
      return false;
4516
11
    }
4517
4518
14
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4519
0
    {
4520
0
      bfd_set_error (bfd_error_file_too_big);
4521
0
      free (native_lineno);
4522
0
      return false;
4523
0
    }
4524
14
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4525
14
  if (lineno_cache == NULL)
4526
0
    {
4527
0
      free (native_lineno);
4528
0
      return false;
4529
0
    }
4530
4531
14
  cache_ptr = lineno_cache;
4532
14
  asect->lineno = lineno_cache;
4533
14
  src = native_lineno;
4534
14
  nbr_func = 0;
4535
14
  have_func = false;
4536
4537
20.9k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4538
20.9k
    {
4539
20.9k
      struct internal_lineno dst;
4540
4541
20.9k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4542
20.9k
      cache_ptr->line_number = dst.l_lnno;
4543
      /* Appease memory checkers that get all excited about
4544
   uninitialised memory when copying alents if u.offset is
4545
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4546
20.9k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4547
4548
20.9k
      if (cache_ptr->line_number == 0)
4549
10.1k
  {
4550
10.1k
    combined_entry_type * ent;
4551
10.1k
    unsigned long symndx;
4552
10.1k
    coff_symbol_type *sym;
4553
4554
10.1k
    have_func = false;
4555
10.1k
    symndx = dst.l_addr.l_symndx;
4556
10.1k
    if (symndx >= obj_raw_syment_count (abfd))
4557
4.49k
      {
4558
4.49k
        _bfd_error_handler
4559
    /* xgettext:c-format */
4560
4.49k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4561
4.49k
     abfd, symndx, counter);
4562
4.49k
        cache_ptr->line_number = -1;
4563
4.49k
        ret = false;
4564
4.49k
        continue;
4565
4.49k
      }
4566
4567
5.66k
    ent = obj_raw_syments (abfd) + symndx;
4568
    /* FIXME: We should not be casting between ints and
4569
       pointers like this.  */
4570
5.66k
    if (! ent->is_sym)
4571
1.42k
      {
4572
1.42k
        _bfd_error_handler
4573
    /* xgettext:c-format */
4574
1.42k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4575
1.42k
     abfd, symndx, counter);
4576
1.42k
        cache_ptr->line_number = -1;
4577
1.42k
        ret = false;
4578
1.42k
        continue;
4579
1.42k
      }
4580
4.24k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4581
4582
    /* PR 17512 file: 078-10659-0.004  */
4583
4.24k
    if (sym < obj_symbols (abfd)
4584
4.24k
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4585
0
      {
4586
0
        _bfd_error_handler
4587
    /* xgettext:c-format */
4588
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4589
0
     abfd, counter);
4590
0
        cache_ptr->line_number = -1;
4591
0
        ret = false;
4592
0
        continue;
4593
0
      }
4594
4595
4.24k
    have_func = true;
4596
4.24k
    nbr_func++;
4597
4.24k
    cache_ptr->u.sym = (asymbol *) sym;
4598
4.24k
    if (sym->lineno != NULL)
4599
4.16k
      _bfd_error_handler
4600
        /* xgettext:c-format */
4601
4.16k
        (_("%pB: warning: duplicate line number information for `%s'"),
4602
4.16k
         abfd, bfd_asymbol_name (&sym->symbol));
4603
4604
4.24k
    sym->lineno = cache_ptr;
4605
4.24k
    if (sym->symbol.value < prev_offset)
4606
82
      ordered = false;
4607
4.24k
    prev_offset = sym->symbol.value;
4608
4.24k
  }
4609
10.7k
      else if (!have_func)
4610
  /* Drop line information that has no associated function.
4611
     PR 17521: file: 078-10659-0.004.  */
4612
6.85k
  continue;
4613
3.88k
      else
4614
3.88k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4615
8.12k
      cache_ptr++;
4616
8.12k
    }
4617
4618
14
  asect->lineno_count = cache_ptr - lineno_cache;
4619
14
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4620
14
  free (native_lineno);
4621
4622
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4623
14
  if (!ordered)
4624
13
    {
4625
      /* Sort the table.  */
4626
13
      alent **func_table;
4627
13
      alent *n_lineno_cache;
4628
4629
      /* Create a table of functions.  */
4630
13
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4631
0
  {
4632
0
    bfd_set_error (bfd_error_file_too_big);
4633
0
    ret = false;
4634
0
  }
4635
13
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4636
13
  {
4637
13
    alent **p = func_table;
4638
13
    unsigned int i;
4639
4640
7.15k
    for (i = 0; i < asect->lineno_count; i++)
4641
7.14k
      if (lineno_cache[i].line_number == 0)
4642
3.92k
        *p++ = &lineno_cache[i];
4643
4644
13
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4645
4646
    /* Sort by functions.  */
4647
13
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4648
4649
    /* Create the new sorted table.  */
4650
13
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4651
0
      {
4652
0
        bfd_set_error (bfd_error_file_too_big);
4653
0
        ret = false;
4654
0
      }
4655
13
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4656
13
      {
4657
13
        alent *n_cache_ptr = n_lineno_cache;
4658
4659
3.93k
        for (i = 0; i < nbr_func; i++)
4660
3.92k
    {
4661
3.92k
      coff_symbol_type *sym;
4662
3.92k
      alent *old_ptr = func_table[i];
4663
4664
      /* Update the function entry.  */
4665
3.92k
      sym = (coff_symbol_type *) old_ptr->u.sym;
4666
      /* PR binutils/17512: Point the lineno to where
4667
         this entry will be after the memcpy below.  */
4668
3.92k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4669
      /* Copy the function and line number entries.  */
4670
3.92k
      do
4671
7.14k
        *n_cache_ptr++ = *old_ptr++;
4672
7.14k
      while (old_ptr->line_number != 0);
4673
3.92k
    }
4674
4675
13
        memcpy (lineno_cache, n_lineno_cache,
4676
13
          asect->lineno_count * sizeof (alent));
4677
13
      }
4678
0
    else
4679
0
      ret = false;
4680
13
    bfd_release (abfd, func_table);
4681
13
  }
4682
0
      else
4683
0
  ret = false;
4684
13
    }
4685
4686
14
  return ret;
4687
14
}
Unexecuted instantiation: cf-i386lynx.c:coff_slurp_line_table
Unexecuted instantiation: coff-go32.c:coff_slurp_line_table
Unexecuted instantiation: coff-i386.c:coff_slurp_line_table
coff-rs6000.c:coff_slurp_line_table
Line
Count
Source
4490
320
{
4491
320
  LINENO *native_lineno;
4492
320
  alent *lineno_cache;
4493
320
  unsigned int counter;
4494
320
  alent *cache_ptr;
4495
320
  bfd_vma prev_offset = 0;
4496
320
  bool ordered = true;
4497
320
  unsigned int nbr_func;
4498
320
  LINENO *src;
4499
320
  bool have_func;
4500
320
  bool ret = true;
4501
320
  size_t amt;
4502
4503
320
  if (asect->lineno_count == 0)
4504
256
    return true;
4505
4506
64
  BFD_ASSERT (asect->lineno == NULL);
4507
4508
64
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4509
64
             asect->lineno_count,
4510
64
             bfd_coff_linesz (abfd));
4511
64
  if (native_lineno == NULL)
4512
50
    {
4513
50
      _bfd_error_handler
4514
50
  (_("%pB: warning: line number table read failed"), abfd);
4515
50
      return false;
4516
50
    }
4517
4518
14
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4519
0
    {
4520
0
      bfd_set_error (bfd_error_file_too_big);
4521
0
      free (native_lineno);
4522
0
      return false;
4523
0
    }
4524
14
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4525
14
  if (lineno_cache == NULL)
4526
0
    {
4527
0
      free (native_lineno);
4528
0
      return false;
4529
0
    }
4530
4531
14
  cache_ptr = lineno_cache;
4532
14
  asect->lineno = lineno_cache;
4533
14
  src = native_lineno;
4534
14
  nbr_func = 0;
4535
14
  have_func = false;
4536
4537
28.9k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4538
28.9k
    {
4539
28.9k
      struct internal_lineno dst;
4540
4541
28.9k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4542
28.9k
      cache_ptr->line_number = dst.l_lnno;
4543
      /* Appease memory checkers that get all excited about
4544
   uninitialised memory when copying alents if u.offset is
4545
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4546
28.9k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4547
4548
28.9k
      if (cache_ptr->line_number == 0)
4549
17.2k
  {
4550
17.2k
    combined_entry_type * ent;
4551
17.2k
    unsigned long symndx;
4552
17.2k
    coff_symbol_type *sym;
4553
4554
17.2k
    have_func = false;
4555
17.2k
    symndx = dst.l_addr.l_symndx;
4556
17.2k
    if (symndx >= obj_raw_syment_count (abfd))
4557
3.13k
      {
4558
3.13k
        _bfd_error_handler
4559
    /* xgettext:c-format */
4560
3.13k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4561
3.13k
     abfd, symndx, counter);
4562
3.13k
        cache_ptr->line_number = -1;
4563
3.13k
        ret = false;
4564
3.13k
        continue;
4565
3.13k
      }
4566
4567
14.0k
    ent = obj_raw_syments (abfd) + symndx;
4568
    /* FIXME: We should not be casting between ints and
4569
       pointers like this.  */
4570
14.0k
    if (! ent->is_sym)
4571
767
      {
4572
767
        _bfd_error_handler
4573
    /* xgettext:c-format */
4574
767
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4575
767
     abfd, symndx, counter);
4576
767
        cache_ptr->line_number = -1;
4577
767
        ret = false;
4578
767
        continue;
4579
767
      }
4580
13.3k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4581
4582
    /* PR 17512 file: 078-10659-0.004  */
4583
13.3k
    if (sym < obj_symbols (abfd)
4584
13.3k
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4585
0
      {
4586
0
        _bfd_error_handler
4587
    /* xgettext:c-format */
4588
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4589
0
     abfd, counter);
4590
0
        cache_ptr->line_number = -1;
4591
0
        ret = false;
4592
0
        continue;
4593
0
      }
4594
4595
13.3k
    have_func = true;
4596
13.3k
    nbr_func++;
4597
13.3k
    cache_ptr->u.sym = (asymbol *) sym;
4598
13.3k
    if (sym->lineno != NULL)
4599
13.2k
      _bfd_error_handler
4600
        /* xgettext:c-format */
4601
13.2k
        (_("%pB: warning: duplicate line number information for `%s'"),
4602
13.2k
         abfd, bfd_asymbol_name (&sym->symbol));
4603
4604
13.3k
    sym->lineno = cache_ptr;
4605
13.3k
    if (sym->symbol.value < prev_offset)
4606
205
      ordered = false;
4607
13.3k
    prev_offset = sym->symbol.value;
4608
13.3k
  }
4609
11.7k
      else if (!have_func)
4610
  /* Drop line information that has no associated function.
4611
     PR 17521: file: 078-10659-0.004.  */
4612
6.48k
  continue;
4613
5.23k
      else
4614
5.23k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4615
18.5k
      cache_ptr++;
4616
18.5k
    }
4617
4618
14
  asect->lineno_count = cache_ptr - lineno_cache;
4619
14
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4620
14
  free (native_lineno);
4621
4622
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4623
14
  if (!ordered)
4624
11
    {
4625
      /* Sort the table.  */
4626
11
      alent **func_table;
4627
11
      alent *n_lineno_cache;
4628
4629
      /* Create a table of functions.  */
4630
11
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4631
0
  {
4632
0
    bfd_set_error (bfd_error_file_too_big);
4633
0
    ret = false;
4634
0
  }
4635
11
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4636
11
  {
4637
11
    alent **p = func_table;
4638
11
    unsigned int i;
4639
4640
17.8k
    for (i = 0; i < asect->lineno_count; i++)
4641
17.8k
      if (lineno_cache[i].line_number == 0)
4642
13.0k
        *p++ = &lineno_cache[i];
4643
4644
11
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4645
4646
    /* Sort by functions.  */
4647
11
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4648
4649
    /* Create the new sorted table.  */
4650
11
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4651
0
      {
4652
0
        bfd_set_error (bfd_error_file_too_big);
4653
0
        ret = false;
4654
0
      }
4655
11
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4656
11
      {
4657
11
        alent *n_cache_ptr = n_lineno_cache;
4658
4659
13.0k
        for (i = 0; i < nbr_func; i++)
4660
13.0k
    {
4661
13.0k
      coff_symbol_type *sym;
4662
13.0k
      alent *old_ptr = func_table[i];
4663
4664
      /* Update the function entry.  */
4665
13.0k
      sym = (coff_symbol_type *) old_ptr->u.sym;
4666
      /* PR binutils/17512: Point the lineno to where
4667
         this entry will be after the memcpy below.  */
4668
13.0k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4669
      /* Copy the function and line number entries.  */
4670
13.0k
      do
4671
17.8k
        *n_cache_ptr++ = *old_ptr++;
4672
17.8k
      while (old_ptr->line_number != 0);
4673
13.0k
    }
4674
4675
11
        memcpy (lineno_cache, n_lineno_cache,
4676
11
          asect->lineno_count * sizeof (alent));
4677
11
      }
4678
0
    else
4679
0
      ret = false;
4680
11
    bfd_release (abfd, func_table);
4681
11
  }
4682
0
      else
4683
0
  ret = false;
4684
11
    }
4685
4686
14
  return ret;
4687
14
}
coff-sh.c:coff_slurp_line_table
Line
Count
Source
4490
375
{
4491
375
  LINENO *native_lineno;
4492
375
  alent *lineno_cache;
4493
375
  unsigned int counter;
4494
375
  alent *cache_ptr;
4495
375
  bfd_vma prev_offset = 0;
4496
375
  bool ordered = true;
4497
375
  unsigned int nbr_func;
4498
375
  LINENO *src;
4499
375
  bool have_func;
4500
375
  bool ret = true;
4501
375
  size_t amt;
4502
4503
375
  if (asect->lineno_count == 0)
4504
316
    return true;
4505
4506
59
  BFD_ASSERT (asect->lineno == NULL);
4507
4508
59
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4509
59
             asect->lineno_count,
4510
59
             bfd_coff_linesz (abfd));
4511
59
  if (native_lineno == NULL)
4512
22
    {
4513
22
      _bfd_error_handler
4514
22
  (_("%pB: warning: line number table read failed"), abfd);
4515
22
      return false;
4516
22
    }
4517
4518
37
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4519
0
    {
4520
0
      bfd_set_error (bfd_error_file_too_big);
4521
0
      free (native_lineno);
4522
0
      return false;
4523
0
    }
4524
37
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4525
37
  if (lineno_cache == NULL)
4526
0
    {
4527
0
      free (native_lineno);
4528
0
      return false;
4529
0
    }
4530
4531
37
  cache_ptr = lineno_cache;
4532
37
  asect->lineno = lineno_cache;
4533
37
  src = native_lineno;
4534
37
  nbr_func = 0;
4535
37
  have_func = false;
4536
4537
44.5k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4538
44.5k
    {
4539
44.5k
      struct internal_lineno dst;
4540
4541
44.5k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4542
44.5k
      cache_ptr->line_number = dst.l_lnno;
4543
      /* Appease memory checkers that get all excited about
4544
   uninitialised memory when copying alents if u.offset is
4545
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4546
44.5k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4547
4548
44.5k
      if (cache_ptr->line_number == 0)
4549
13.8k
  {
4550
13.8k
    combined_entry_type * ent;
4551
13.8k
    unsigned long symndx;
4552
13.8k
    coff_symbol_type *sym;
4553
4554
13.8k
    have_func = false;
4555
13.8k
    symndx = dst.l_addr.l_symndx;
4556
13.8k
    if (symndx >= obj_raw_syment_count (abfd))
4557
5.57k
      {
4558
5.57k
        _bfd_error_handler
4559
    /* xgettext:c-format */
4560
5.57k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4561
5.57k
     abfd, symndx, counter);
4562
5.57k
        cache_ptr->line_number = -1;
4563
5.57k
        ret = false;
4564
5.57k
        continue;
4565
5.57k
      }
4566
4567
8.30k
    ent = obj_raw_syments (abfd) + symndx;
4568
    /* FIXME: We should not be casting between ints and
4569
       pointers like this.  */
4570
8.30k
    if (! ent->is_sym)
4571
1.10k
      {
4572
1.10k
        _bfd_error_handler
4573
    /* xgettext:c-format */
4574
1.10k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4575
1.10k
     abfd, symndx, counter);
4576
1.10k
        cache_ptr->line_number = -1;
4577
1.10k
        ret = false;
4578
1.10k
        continue;
4579
1.10k
      }
4580
7.19k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4581
4582
    /* PR 17512 file: 078-10659-0.004  */
4583
7.19k
    if (sym < obj_symbols (abfd)
4584
7.19k
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4585
0
      {
4586
0
        _bfd_error_handler
4587
    /* xgettext:c-format */
4588
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4589
0
     abfd, counter);
4590
0
        cache_ptr->line_number = -1;
4591
0
        ret = false;
4592
0
        continue;
4593
0
      }
4594
4595
7.19k
    have_func = true;
4596
7.19k
    nbr_func++;
4597
7.19k
    cache_ptr->u.sym = (asymbol *) sym;
4598
7.19k
    if (sym->lineno != NULL)
4599
7.06k
      _bfd_error_handler
4600
        /* xgettext:c-format */
4601
7.06k
        (_("%pB: warning: duplicate line number information for `%s'"),
4602
7.06k
         abfd, bfd_asymbol_name (&sym->symbol));
4603
4604
7.19k
    sym->lineno = cache_ptr;
4605
7.19k
    if (sym->symbol.value < prev_offset)
4606
69
      ordered = false;
4607
7.19k
    prev_offset = sym->symbol.value;
4608
7.19k
  }
4609
30.6k
      else if (!have_func)
4610
  /* Drop line information that has no associated function.
4611
     PR 17521: file: 078-10659-0.004.  */
4612
17.4k
  continue;
4613
13.2k
      else
4614
13.2k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4615
20.4k
      cache_ptr++;
4616
20.4k
    }
4617
4618
37
  asect->lineno_count = cache_ptr - lineno_cache;
4619
37
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4620
37
  free (native_lineno);
4621
4622
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4623
37
  if (!ordered)
4624
16
    {
4625
      /* Sort the table.  */
4626
16
      alent **func_table;
4627
16
      alent *n_lineno_cache;
4628
4629
      /* Create a table of functions.  */
4630
16
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4631
0
  {
4632
0
    bfd_set_error (bfd_error_file_too_big);
4633
0
    ret = false;
4634
0
  }
4635
16
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4636
16
  {
4637
16
    alent **p = func_table;
4638
16
    unsigned int i;
4639
4640
19.0k
    for (i = 0; i < asect->lineno_count; i++)
4641
19.0k
      if (lineno_cache[i].line_number == 0)
4642
6.54k
        *p++ = &lineno_cache[i];
4643
4644
16
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4645
4646
    /* Sort by functions.  */
4647
16
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4648
4649
    /* Create the new sorted table.  */
4650
16
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4651
0
      {
4652
0
        bfd_set_error (bfd_error_file_too_big);
4653
0
        ret = false;
4654
0
      }
4655
16
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4656
16
      {
4657
16
        alent *n_cache_ptr = n_lineno_cache;
4658
4659
6.56k
        for (i = 0; i < nbr_func; i++)
4660
6.54k
    {
4661
6.54k
      coff_symbol_type *sym;
4662
6.54k
      alent *old_ptr = func_table[i];
4663
4664
      /* Update the function entry.  */
4665
6.54k
      sym = (coff_symbol_type *) old_ptr->u.sym;
4666
      /* PR binutils/17512: Point the lineno to where
4667
         this entry will be after the memcpy below.  */
4668
6.54k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4669
      /* Copy the function and line number entries.  */
4670
6.54k
      do
4671
19.0k
        *n_cache_ptr++ = *old_ptr++;
4672
19.0k
      while (old_ptr->line_number != 0);
4673
6.54k
    }
4674
4675
16
        memcpy (lineno_cache, n_lineno_cache,
4676
16
          asect->lineno_count * sizeof (alent));
4677
16
      }
4678
0
    else
4679
0
      ret = false;
4680
16
    bfd_release (abfd, func_table);
4681
16
  }
4682
0
      else
4683
0
  ret = false;
4684
16
    }
4685
4686
37
  return ret;
4687
37
}
Unexecuted instantiation: coff-stgo32.c:coff_slurp_line_table
coff-tic30.c:coff_slurp_line_table
Line
Count
Source
4490
82
{
4491
82
  LINENO *native_lineno;
4492
82
  alent *lineno_cache;
4493
82
  unsigned int counter;
4494
82
  alent *cache_ptr;
4495
82
  bfd_vma prev_offset = 0;
4496
82
  bool ordered = true;
4497
82
  unsigned int nbr_func;
4498
82
  LINENO *src;
4499
82
  bool have_func;
4500
82
  bool ret = true;
4501
82
  size_t amt;
4502
4503
82
  if (asect->lineno_count == 0)
4504
60
    return true;
4505
4506
22
  BFD_ASSERT (asect->lineno == NULL);
4507
4508
22
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4509
22
             asect->lineno_count,
4510
22
             bfd_coff_linesz (abfd));
4511
22
  if (native_lineno == NULL)
4512
14
    {
4513
14
      _bfd_error_handler
4514
14
  (_("%pB: warning: line number table read failed"), abfd);
4515
14
      return false;
4516
14
    }
4517
4518
8
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4519
0
    {
4520
0
      bfd_set_error (bfd_error_file_too_big);
4521
0
      free (native_lineno);
4522
0
      return false;
4523
0
    }
4524
8
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4525
8
  if (lineno_cache == NULL)
4526
0
    {
4527
0
      free (native_lineno);
4528
0
      return false;
4529
0
    }
4530
4531
8
  cache_ptr = lineno_cache;
4532
8
  asect->lineno = lineno_cache;
4533
8
  src = native_lineno;
4534
8
  nbr_func = 0;
4535
8
  have_func = false;
4536
4537
26.7k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4538
26.6k
    {
4539
26.6k
      struct internal_lineno dst;
4540
4541
26.6k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4542
26.6k
      cache_ptr->line_number = dst.l_lnno;
4543
      /* Appease memory checkers that get all excited about
4544
   uninitialised memory when copying alents if u.offset is
4545
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4546
26.6k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4547
4548
26.6k
      if (cache_ptr->line_number == 0)
4549
12.7k
  {
4550
12.7k
    combined_entry_type * ent;
4551
12.7k
    unsigned long symndx;
4552
12.7k
    coff_symbol_type *sym;
4553
4554
12.7k
    have_func = false;
4555
12.7k
    symndx = dst.l_addr.l_symndx;
4556
12.7k
    if (symndx >= obj_raw_syment_count (abfd))
4557
2.10k
      {
4558
2.10k
        _bfd_error_handler
4559
    /* xgettext:c-format */
4560
2.10k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4561
2.10k
     abfd, symndx, counter);
4562
2.10k
        cache_ptr->line_number = -1;
4563
2.10k
        ret = false;
4564
2.10k
        continue;
4565
2.10k
      }
4566
4567
10.6k
    ent = obj_raw_syments (abfd) + symndx;
4568
    /* FIXME: We should not be casting between ints and
4569
       pointers like this.  */
4570
10.6k
    if (! ent->is_sym)
4571
416
      {
4572
416
        _bfd_error_handler
4573
    /* xgettext:c-format */
4574
416
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4575
416
     abfd, symndx, counter);
4576
416
        cache_ptr->line_number = -1;
4577
416
        ret = false;
4578
416
        continue;
4579
416
      }
4580
10.2k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4581
4582
    /* PR 17512 file: 078-10659-0.004  */
4583
10.2k
    if (sym < obj_symbols (abfd)
4584
10.2k
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4585
0
      {
4586
0
        _bfd_error_handler
4587
    /* xgettext:c-format */
4588
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4589
0
     abfd, counter);
4590
0
        cache_ptr->line_number = -1;
4591
0
        ret = false;
4592
0
        continue;
4593
0
      }
4594
4595
10.2k
    have_func = true;
4596
10.2k
    nbr_func++;
4597
10.2k
    cache_ptr->u.sym = (asymbol *) sym;
4598
10.2k
    if (sym->lineno != NULL)
4599
10.1k
      _bfd_error_handler
4600
        /* xgettext:c-format */
4601
10.1k
        (_("%pB: warning: duplicate line number information for `%s'"),
4602
10.1k
         abfd, bfd_asymbol_name (&sym->symbol));
4603
4604
10.2k
    sym->lineno = cache_ptr;
4605
10.2k
    if (sym->symbol.value < prev_offset)
4606
95
      ordered = false;
4607
10.2k
    prev_offset = sym->symbol.value;
4608
10.2k
  }
4609
13.9k
      else if (!have_func)
4610
  /* Drop line information that has no associated function.
4611
     PR 17521: file: 078-10659-0.004.  */
4612
6.84k
  continue;
4613
7.08k
      else
4614
7.08k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4615
17.3k
      cache_ptr++;
4616
17.3k
    }
4617
4618
8
  asect->lineno_count = cache_ptr - lineno_cache;
4619
8
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4620
8
  free (native_lineno);
4621
4622
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4623
8
  if (!ordered)
4624
4
    {
4625
      /* Sort the table.  */
4626
4
      alent **func_table;
4627
4
      alent *n_lineno_cache;
4628
4629
      /* Create a table of functions.  */
4630
4
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4631
0
  {
4632
0
    bfd_set_error (bfd_error_file_too_big);
4633
0
    ret = false;
4634
0
  }
4635
4
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4636
4
  {
4637
4
    alent **p = func_table;
4638
4
    unsigned int i;
4639
4640
17.3k
    for (i = 0; i < asect->lineno_count; i++)
4641
17.3k
      if (lineno_cache[i].line_number == 0)
4642
10.2k
        *p++ = &lineno_cache[i];
4643
4644
4
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4645
4646
    /* Sort by functions.  */
4647
4
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4648
4649
    /* Create the new sorted table.  */
4650
4
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4651
0
      {
4652
0
        bfd_set_error (bfd_error_file_too_big);
4653
0
        ret = false;
4654
0
      }
4655
4
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4656
4
      {
4657
4
        alent *n_cache_ptr = n_lineno_cache;
4658
4659
10.2k
        for (i = 0; i < nbr_func; i++)
4660
10.2k
    {
4661
10.2k
      coff_symbol_type *sym;
4662
10.2k
      alent *old_ptr = func_table[i];
4663
4664
      /* Update the function entry.  */
4665
10.2k
      sym = (coff_symbol_type *) old_ptr->u.sym;
4666
      /* PR binutils/17512: Point the lineno to where
4667
         this entry will be after the memcpy below.  */
4668
10.2k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4669
      /* Copy the function and line number entries.  */
4670
10.2k
      do
4671
17.3k
        *n_cache_ptr++ = *old_ptr++;
4672
17.3k
      while (old_ptr->line_number != 0);
4673
10.2k
    }
4674
4675
4
        memcpy (lineno_cache, n_lineno_cache,
4676
4
          asect->lineno_count * sizeof (alent));
4677
4
      }
4678
0
    else
4679
0
      ret = false;
4680
4
    bfd_release (abfd, func_table);
4681
4
  }
4682
0
      else
4683
0
  ret = false;
4684
4
    }
4685
4686
8
  return ret;
4687
8
}
Unexecuted instantiation: coff-tic4x.c:coff_slurp_line_table
coff-tic54x.c:coff_slurp_line_table
Line
Count
Source
4490
71
{
4491
71
  LINENO *native_lineno;
4492
71
  alent *lineno_cache;
4493
71
  unsigned int counter;
4494
71
  alent *cache_ptr;
4495
71
  bfd_vma prev_offset = 0;
4496
71
  bool ordered = true;
4497
71
  unsigned int nbr_func;
4498
71
  LINENO *src;
4499
71
  bool have_func;
4500
71
  bool ret = true;
4501
71
  size_t amt;
4502
4503
71
  if (asect->lineno_count == 0)
4504
32
    return true;
4505
4506
39
  BFD_ASSERT (asect->lineno == NULL);
4507
4508
39
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4509
39
             asect->lineno_count,
4510
39
             bfd_coff_linesz (abfd));
4511
39
  if (native_lineno == NULL)
4512
24
    {
4513
24
      _bfd_error_handler
4514
24
  (_("%pB: warning: line number table read failed"), abfd);
4515
24
      return false;
4516
24
    }
4517
4518
15
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4519
0
    {
4520
0
      bfd_set_error (bfd_error_file_too_big);
4521
0
      free (native_lineno);
4522
0
      return false;
4523
0
    }
4524
15
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4525
15
  if (lineno_cache == NULL)
4526
0
    {
4527
0
      free (native_lineno);
4528
0
      return false;
4529
0
    }
4530
4531
15
  cache_ptr = lineno_cache;
4532
15
  asect->lineno = lineno_cache;
4533
15
  src = native_lineno;
4534
15
  nbr_func = 0;
4535
15
  have_func = false;
4536
4537
77.3k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4538
77.3k
    {
4539
77.3k
      struct internal_lineno dst;
4540
4541
77.3k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4542
77.3k
      cache_ptr->line_number = dst.l_lnno;
4543
      /* Appease memory checkers that get all excited about
4544
   uninitialised memory when copying alents if u.offset is
4545
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4546
77.3k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4547
4548
77.3k
      if (cache_ptr->line_number == 0)
4549
34.3k
  {
4550
34.3k
    combined_entry_type * ent;
4551
34.3k
    unsigned long symndx;
4552
34.3k
    coff_symbol_type *sym;
4553
4554
34.3k
    have_func = false;
4555
34.3k
    symndx = dst.l_addr.l_symndx;
4556
34.3k
    if (symndx >= obj_raw_syment_count (abfd))
4557
14.7k
      {
4558
14.7k
        _bfd_error_handler
4559
    /* xgettext:c-format */
4560
14.7k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4561
14.7k
     abfd, symndx, counter);
4562
14.7k
        cache_ptr->line_number = -1;
4563
14.7k
        ret = false;
4564
14.7k
        continue;
4565
14.7k
      }
4566
4567
19.5k
    ent = obj_raw_syments (abfd) + symndx;
4568
    /* FIXME: We should not be casting between ints and
4569
       pointers like this.  */
4570
19.5k
    if (! ent->is_sym)
4571
3.20k
      {
4572
3.20k
        _bfd_error_handler
4573
    /* xgettext:c-format */
4574
3.20k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4575
3.20k
     abfd, symndx, counter);
4576
3.20k
        cache_ptr->line_number = -1;
4577
3.20k
        ret = false;
4578
3.20k
        continue;
4579
3.20k
      }
4580
16.3k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4581
4582
    /* PR 17512 file: 078-10659-0.004  */
4583
16.3k
    if (sym < obj_symbols (abfd)
4584
16.3k
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4585
0
      {
4586
0
        _bfd_error_handler
4587
    /* xgettext:c-format */
4588
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4589
0
     abfd, counter);
4590
0
        cache_ptr->line_number = -1;
4591
0
        ret = false;
4592
0
        continue;
4593
0
      }
4594
4595
16.3k
    have_func = true;
4596
16.3k
    nbr_func++;
4597
16.3k
    cache_ptr->u.sym = (asymbol *) sym;
4598
16.3k
    if (sym->lineno != NULL)
4599
16.2k
      _bfd_error_handler
4600
        /* xgettext:c-format */
4601
16.2k
        (_("%pB: warning: duplicate line number information for `%s'"),
4602
16.2k
         abfd, bfd_asymbol_name (&sym->symbol));
4603
4604
16.3k
    sym->lineno = cache_ptr;
4605
16.3k
    if (sym->symbol.value < prev_offset)
4606
586
      ordered = false;
4607
16.3k
    prev_offset = sym->symbol.value;
4608
16.3k
  }
4609
43.0k
      else if (!have_func)
4610
  /* Drop line information that has no associated function.
4611
     PR 17521: file: 078-10659-0.004.  */
4612
28.3k
  continue;
4613
14.6k
      else
4614
14.6k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4615
31.0k
      cache_ptr++;
4616
31.0k
    }
4617
4618
15
  asect->lineno_count = cache_ptr - lineno_cache;
4619
15
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4620
15
  free (native_lineno);
4621
4622
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4623
15
  if (!ordered)
4624
10
    {
4625
      /* Sort the table.  */
4626
10
      alent **func_table;
4627
10
      alent *n_lineno_cache;
4628
4629
      /* Create a table of functions.  */
4630
10
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4631
0
  {
4632
0
    bfd_set_error (bfd_error_file_too_big);
4633
0
    ret = false;
4634
0
  }
4635
10
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4636
10
  {
4637
10
    alent **p = func_table;
4638
10
    unsigned int i;
4639
4640
30.8k
    for (i = 0; i < asect->lineno_count; i++)
4641
30.8k
      if (lineno_cache[i].line_number == 0)
4642
16.2k
        *p++ = &lineno_cache[i];
4643
4644
10
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4645
4646
    /* Sort by functions.  */
4647
10
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4648
4649
    /* Create the new sorted table.  */
4650
10
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4651
0
      {
4652
0
        bfd_set_error (bfd_error_file_too_big);
4653
0
        ret = false;
4654
0
      }
4655
10
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4656
10
      {
4657
10
        alent *n_cache_ptr = n_lineno_cache;
4658
4659
16.2k
        for (i = 0; i < nbr_func; i++)
4660
16.2k
    {
4661
16.2k
      coff_symbol_type *sym;
4662
16.2k
      alent *old_ptr = func_table[i];
4663
4664
      /* Update the function entry.  */
4665
16.2k
      sym = (coff_symbol_type *) old_ptr->u.sym;
4666
      /* PR binutils/17512: Point the lineno to where
4667
         this entry will be after the memcpy below.  */
4668
16.2k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4669
      /* Copy the function and line number entries.  */
4670
16.2k
      do
4671
30.8k
        *n_cache_ptr++ = *old_ptr++;
4672
30.8k
      while (old_ptr->line_number != 0);
4673
16.2k
    }
4674
4675
10
        memcpy (lineno_cache, n_lineno_cache,
4676
10
          asect->lineno_count * sizeof (alent));
4677
10
      }
4678
0
    else
4679
0
      ret = false;
4680
10
    bfd_release (abfd, func_table);
4681
10
  }
4682
0
      else
4683
0
  ret = false;
4684
10
    }
4685
4686
15
  return ret;
4687
15
}
coff-z80.c:coff_slurp_line_table
Line
Count
Source
4490
157
{
4491
157
  LINENO *native_lineno;
4492
157
  alent *lineno_cache;
4493
157
  unsigned int counter;
4494
157
  alent *cache_ptr;
4495
157
  bfd_vma prev_offset = 0;
4496
157
  bool ordered = true;
4497
157
  unsigned int nbr_func;
4498
157
  LINENO *src;
4499
157
  bool have_func;
4500
157
  bool ret = true;
4501
157
  size_t amt;
4502
4503
157
  if (asect->lineno_count == 0)
4504
131
    return true;
4505
4506
26
  BFD_ASSERT (asect->lineno == NULL);
4507
4508
26
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4509
26
             asect->lineno_count,
4510
26
             bfd_coff_linesz (abfd));
4511
26
  if (native_lineno == NULL)
4512
14
    {
4513
14
      _bfd_error_handler
4514
14
  (_("%pB: warning: line number table read failed"), abfd);
4515
14
      return false;
4516
14
    }
4517
4518
12
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4519
0
    {
4520
0
      bfd_set_error (bfd_error_file_too_big);
4521
0
      free (native_lineno);
4522
0
      return false;
4523
0
    }
4524
12
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4525
12
  if (lineno_cache == NULL)
4526
0
    {
4527
0
      free (native_lineno);
4528
0
      return false;
4529
0
    }
4530
4531
12
  cache_ptr = lineno_cache;
4532
12
  asect->lineno = lineno_cache;
4533
12
  src = native_lineno;
4534
12
  nbr_func = 0;
4535
12
  have_func = false;
4536
4537
33.4k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4538
33.3k
    {
4539
33.3k
      struct internal_lineno dst;
4540
4541
33.3k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4542
33.3k
      cache_ptr->line_number = dst.l_lnno;
4543
      /* Appease memory checkers that get all excited about
4544
   uninitialised memory when copying alents if u.offset is
4545
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4546
33.3k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4547
4548
33.3k
      if (cache_ptr->line_number == 0)
4549
9.89k
  {
4550
9.89k
    combined_entry_type * ent;
4551
9.89k
    unsigned long symndx;
4552
9.89k
    coff_symbol_type *sym;
4553
4554
9.89k
    have_func = false;
4555
9.89k
    symndx = dst.l_addr.l_symndx;
4556
9.89k
    if (symndx >= obj_raw_syment_count (abfd))
4557
2.52k
      {
4558
2.52k
        _bfd_error_handler
4559
    /* xgettext:c-format */
4560
2.52k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4561
2.52k
     abfd, symndx, counter);
4562
2.52k
        cache_ptr->line_number = -1;
4563
2.52k
        ret = false;
4564
2.52k
        continue;
4565
2.52k
      }
4566
4567
7.36k
    ent = obj_raw_syments (abfd) + symndx;
4568
    /* FIXME: We should not be casting between ints and
4569
       pointers like this.  */
4570
7.36k
    if (! ent->is_sym)
4571
458
      {
4572
458
        _bfd_error_handler
4573
    /* xgettext:c-format */
4574
458
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4575
458
     abfd, symndx, counter);
4576
458
        cache_ptr->line_number = -1;
4577
458
        ret = false;
4578
458
        continue;
4579
458
      }
4580
6.91k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4581
4582
    /* PR 17512 file: 078-10659-0.004  */
4583
6.91k
    if (sym < obj_symbols (abfd)
4584
6.91k
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4585
0
      {
4586
0
        _bfd_error_handler
4587
    /* xgettext:c-format */
4588
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4589
0
     abfd, counter);
4590
0
        cache_ptr->line_number = -1;
4591
0
        ret = false;
4592
0
        continue;
4593
0
      }
4594
4595
6.91k
    have_func = true;
4596
6.91k
    nbr_func++;
4597
6.91k
    cache_ptr->u.sym = (asymbol *) sym;
4598
6.91k
    if (sym->lineno != NULL)
4599
6.79k
      _bfd_error_handler
4600
        /* xgettext:c-format */
4601
6.79k
        (_("%pB: warning: duplicate line number information for `%s'"),
4602
6.79k
         abfd, bfd_asymbol_name (&sym->symbol));
4603
4604
6.91k
    sym->lineno = cache_ptr;
4605
6.91k
    if (sym->symbol.value < prev_offset)
4606
142
      ordered = false;
4607
6.91k
    prev_offset = sym->symbol.value;
4608
6.91k
  }
4609
23.4k
      else if (!have_func)
4610
  /* Drop line information that has no associated function.
4611
     PR 17521: file: 078-10659-0.004.  */
4612
10.4k
  continue;
4613
13.0k
      else
4614
13.0k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4615
19.9k
      cache_ptr++;
4616
19.9k
    }
4617
4618
12
  asect->lineno_count = cache_ptr - lineno_cache;
4619
12
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4620
12
  free (native_lineno);
4621
4622
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4623
12
  if (!ordered)
4624
10
    {
4625
      /* Sort the table.  */
4626
10
      alent **func_table;
4627
10
      alent *n_lineno_cache;
4628
4629
      /* Create a table of functions.  */
4630
10
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4631
0
  {
4632
0
    bfd_set_error (bfd_error_file_too_big);
4633
0
    ret = false;
4634
0
  }
4635
10
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4636
10
  {
4637
10
    alent **p = func_table;
4638
10
    unsigned int i;
4639
4640
19.9k
    for (i = 0; i < asect->lineno_count; i++)
4641
19.9k
      if (lineno_cache[i].line_number == 0)
4642
6.89k
        *p++ = &lineno_cache[i];
4643
4644
10
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4645
4646
    /* Sort by functions.  */
4647
10
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4648
4649
    /* Create the new sorted table.  */
4650
10
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4651
0
      {
4652
0
        bfd_set_error (bfd_error_file_too_big);
4653
0
        ret = false;
4654
0
      }
4655
10
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4656
10
      {
4657
10
        alent *n_cache_ptr = n_lineno_cache;
4658
4659
6.90k
        for (i = 0; i < nbr_func; i++)
4660
6.89k
    {
4661
6.89k
      coff_symbol_type *sym;
4662
6.89k
      alent *old_ptr = func_table[i];
4663
4664
      /* Update the function entry.  */
4665
6.89k
      sym = (coff_symbol_type *) old_ptr->u.sym;
4666
      /* PR binutils/17512: Point the lineno to where
4667
         this entry will be after the memcpy below.  */
4668
6.89k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4669
      /* Copy the function and line number entries.  */
4670
6.89k
      do
4671
19.9k
        *n_cache_ptr++ = *old_ptr++;
4672
19.9k
      while (old_ptr->line_number != 0);
4673
6.89k
    }
4674
4675
10
        memcpy (lineno_cache, n_lineno_cache,
4676
10
          asect->lineno_count * sizeof (alent));
4677
10
      }
4678
0
    else
4679
0
      ret = false;
4680
10
    bfd_release (abfd, func_table);
4681
10
  }
4682
0
      else
4683
0
  ret = false;
4684
10
    }
4685
4686
12
  return ret;
4687
12
}
coff-z8k.c:coff_slurp_line_table
Line
Count
Source
4490
1.65k
{
4491
1.65k
  LINENO *native_lineno;
4492
1.65k
  alent *lineno_cache;
4493
1.65k
  unsigned int counter;
4494
1.65k
  alent *cache_ptr;
4495
1.65k
  bfd_vma prev_offset = 0;
4496
1.65k
  bool ordered = true;
4497
1.65k
  unsigned int nbr_func;
4498
1.65k
  LINENO *src;
4499
1.65k
  bool have_func;
4500
1.65k
  bool ret = true;
4501
1.65k
  size_t amt;
4502
4503
1.65k
  if (asect->lineno_count == 0)
4504
1.62k
    return true;
4505
4506
35
  BFD_ASSERT (asect->lineno == NULL);
4507
4508
35
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4509
35
             asect->lineno_count,
4510
35
             bfd_coff_linesz (abfd));
4511
35
  if (native_lineno == NULL)
4512
5
    {
4513
5
      _bfd_error_handler
4514
5
  (_("%pB: warning: line number table read failed"), abfd);
4515
5
      return false;
4516
5
    }
4517
4518
30
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4519
0
    {
4520
0
      bfd_set_error (bfd_error_file_too_big);
4521
0
      free (native_lineno);
4522
0
      return false;
4523
0
    }
4524
30
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4525
30
  if (lineno_cache == NULL)
4526
0
    {
4527
0
      free (native_lineno);
4528
0
      return false;
4529
0
    }
4530
4531
30
  cache_ptr = lineno_cache;
4532
30
  asect->lineno = lineno_cache;
4533
30
  src = native_lineno;
4534
30
  nbr_func = 0;
4535
30
  have_func = false;
4536
4537
105k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4538
105k
    {
4539
105k
      struct internal_lineno dst;
4540
4541
105k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4542
105k
      cache_ptr->line_number = dst.l_lnno;
4543
      /* Appease memory checkers that get all excited about
4544
   uninitialised memory when copying alents if u.offset is
4545
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4546
105k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4547
4548
105k
      if (cache_ptr->line_number == 0)
4549
22.4k
  {
4550
22.4k
    combined_entry_type * ent;
4551
22.4k
    unsigned long symndx;
4552
22.4k
    coff_symbol_type *sym;
4553
4554
22.4k
    have_func = false;
4555
22.4k
    symndx = dst.l_addr.l_symndx;
4556
22.4k
    if (symndx >= obj_raw_syment_count (abfd))
4557
10.2k
      {
4558
10.2k
        _bfd_error_handler
4559
    /* xgettext:c-format */
4560
10.2k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4561
10.2k
     abfd, symndx, counter);
4562
10.2k
        cache_ptr->line_number = -1;
4563
10.2k
        ret = false;
4564
10.2k
        continue;
4565
10.2k
      }
4566
4567
12.2k
    ent = obj_raw_syments (abfd) + symndx;
4568
    /* FIXME: We should not be casting between ints and
4569
       pointers like this.  */
4570
12.2k
    if (! ent->is_sym)
4571
408
      {
4572
408
        _bfd_error_handler
4573
    /* xgettext:c-format */
4574
408
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4575
408
     abfd, symndx, counter);
4576
408
        cache_ptr->line_number = -1;
4577
408
        ret = false;
4578
408
        continue;
4579
408
      }
4580
11.8k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4581
4582
    /* PR 17512 file: 078-10659-0.004  */
4583
11.8k
    if (sym < obj_symbols (abfd)
4584
11.8k
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4585
0
      {
4586
0
        _bfd_error_handler
4587
    /* xgettext:c-format */
4588
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4589
0
     abfd, counter);
4590
0
        cache_ptr->line_number = -1;
4591
0
        ret = false;
4592
0
        continue;
4593
0
      }
4594
4595
11.8k
    have_func = true;
4596
11.8k
    nbr_func++;
4597
11.8k
    cache_ptr->u.sym = (asymbol *) sym;
4598
11.8k
    if (sym->lineno != NULL)
4599
11.7k
      _bfd_error_handler
4600
        /* xgettext:c-format */
4601
11.7k
        (_("%pB: warning: duplicate line number information for `%s'"),
4602
11.7k
         abfd, bfd_asymbol_name (&sym->symbol));
4603
4604
11.8k
    sym->lineno = cache_ptr;
4605
11.8k
    if (sym->symbol.value < prev_offset)
4606
253
      ordered = false;
4607
11.8k
    prev_offset = sym->symbol.value;
4608
11.8k
  }
4609
83.4k
      else if (!have_func)
4610
  /* Drop line information that has no associated function.
4611
     PR 17521: file: 078-10659-0.004.  */
4612
48.3k
  continue;
4613
35.1k
      else
4614
35.1k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4615
47.0k
      cache_ptr++;
4616
47.0k
    }
4617
4618
30
  asect->lineno_count = cache_ptr - lineno_cache;
4619
30
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4620
30
  free (native_lineno);
4621
4622
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4623
30
  if (!ordered)
4624
11
    {
4625
      /* Sort the table.  */
4626
11
      alent **func_table;
4627
11
      alent *n_lineno_cache;
4628
4629
      /* Create a table of functions.  */
4630
11
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4631
0
  {
4632
0
    bfd_set_error (bfd_error_file_too_big);
4633
0
    ret = false;
4634
0
  }
4635
11
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4636
11
  {
4637
11
    alent **p = func_table;
4638
11
    unsigned int i;
4639
4640
43.5k
    for (i = 0; i < asect->lineno_count; i++)
4641
43.5k
      if (lineno_cache[i].line_number == 0)
4642
10.2k
        *p++ = &lineno_cache[i];
4643
4644
11
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4645
4646
    /* Sort by functions.  */
4647
11
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4648
4649
    /* Create the new sorted table.  */
4650
11
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4651
0
      {
4652
0
        bfd_set_error (bfd_error_file_too_big);
4653
0
        ret = false;
4654
0
      }
4655
11
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4656
11
      {
4657
11
        alent *n_cache_ptr = n_lineno_cache;
4658
4659
10.2k
        for (i = 0; i < nbr_func; i++)
4660
10.2k
    {
4661
10.2k
      coff_symbol_type *sym;
4662
10.2k
      alent *old_ptr = func_table[i];
4663
4664
      /* Update the function entry.  */
4665
10.2k
      sym = (coff_symbol_type *) old_ptr->u.sym;
4666
      /* PR binutils/17512: Point the lineno to where
4667
         this entry will be after the memcpy below.  */
4668
10.2k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4669
      /* Copy the function and line number entries.  */
4670
10.2k
      do
4671
43.5k
        *n_cache_ptr++ = *old_ptr++;
4672
43.5k
      while (old_ptr->line_number != 0);
4673
10.2k
    }
4674
4675
11
        memcpy (lineno_cache, n_lineno_cache,
4676
11
          asect->lineno_count * sizeof (alent));
4677
11
      }
4678
0
    else
4679
0
      ret = false;
4680
11
    bfd_release (abfd, func_table);
4681
11
  }
4682
0
      else
4683
0
  ret = false;
4684
11
    }
4685
4686
30
  return ret;
4687
30
}
Unexecuted instantiation: pe-arm-wince.c:coff_slurp_line_table
Unexecuted instantiation: pe-arm.c:coff_slurp_line_table
pe-i386.c:coff_slurp_line_table
Line
Count
Source
4490
545
{
4491
545
  LINENO *native_lineno;
4492
545
  alent *lineno_cache;
4493
545
  unsigned int counter;
4494
545
  alent *cache_ptr;
4495
545
  bfd_vma prev_offset = 0;
4496
545
  bool ordered = true;
4497
545
  unsigned int nbr_func;
4498
545
  LINENO *src;
4499
545
  bool have_func;
4500
545
  bool ret = true;
4501
545
  size_t amt;
4502
4503
545
  if (asect->lineno_count == 0)
4504
508
    return true;
4505
4506
37
  BFD_ASSERT (asect->lineno == NULL);
4507
4508
37
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4509
37
             asect->lineno_count,
4510
37
             bfd_coff_linesz (abfd));
4511
37
  if (native_lineno == NULL)
4512
31
    {
4513
31
      _bfd_error_handler
4514
31
  (_("%pB: warning: line number table read failed"), abfd);
4515
31
      return false;
4516
31
    }
4517
4518
6
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4519
0
    {
4520
0
      bfd_set_error (bfd_error_file_too_big);
4521
0
      free (native_lineno);
4522
0
      return false;
4523
0
    }
4524
6
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4525
6
  if (lineno_cache == NULL)
4526
0
    {
4527
0
      free (native_lineno);
4528
0
      return false;
4529
0
    }
4530
4531
6
  cache_ptr = lineno_cache;
4532
6
  asect->lineno = lineno_cache;
4533
6
  src = native_lineno;
4534
6
  nbr_func = 0;
4535
6
  have_func = false;
4536
4537
7.98k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4538
7.98k
    {
4539
7.98k
      struct internal_lineno dst;
4540
4541
7.98k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4542
7.98k
      cache_ptr->line_number = dst.l_lnno;
4543
      /* Appease memory checkers that get all excited about
4544
   uninitialised memory when copying alents if u.offset is
4545
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4546
7.98k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4547
4548
7.98k
      if (cache_ptr->line_number == 0)
4549
1.93k
  {
4550
1.93k
    combined_entry_type * ent;
4551
1.93k
    unsigned long symndx;
4552
1.93k
    coff_symbol_type *sym;
4553
4554
1.93k
    have_func = false;
4555
1.93k
    symndx = dst.l_addr.l_symndx;
4556
1.93k
    if (symndx >= obj_raw_syment_count (abfd))
4557
790
      {
4558
790
        _bfd_error_handler
4559
    /* xgettext:c-format */
4560
790
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4561
790
     abfd, symndx, counter);
4562
790
        cache_ptr->line_number = -1;
4563
790
        ret = false;
4564
790
        continue;
4565
790
      }
4566
4567
1.14k
    ent = obj_raw_syments (abfd) + symndx;
4568
    /* FIXME: We should not be casting between ints and
4569
       pointers like this.  */
4570
1.14k
    if (! ent->is_sym)
4571
47
      {
4572
47
        _bfd_error_handler
4573
    /* xgettext:c-format */
4574
47
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4575
47
     abfd, symndx, counter);
4576
47
        cache_ptr->line_number = -1;
4577
47
        ret = false;
4578
47
        continue;
4579
47
      }
4580
1.10k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4581
4582
    /* PR 17512 file: 078-10659-0.004  */
4583
1.10k
    if (sym < obj_symbols (abfd)
4584
1.10k
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4585
0
      {
4586
0
        _bfd_error_handler
4587
    /* xgettext:c-format */
4588
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4589
0
     abfd, counter);
4590
0
        cache_ptr->line_number = -1;
4591
0
        ret = false;
4592
0
        continue;
4593
0
      }
4594
4595
1.10k
    have_func = true;
4596
1.10k
    nbr_func++;
4597
1.10k
    cache_ptr->u.sym = (asymbol *) sym;
4598
1.10k
    if (sym->lineno != NULL)
4599
1.02k
      _bfd_error_handler
4600
        /* xgettext:c-format */
4601
1.02k
        (_("%pB: warning: duplicate line number information for `%s'"),
4602
1.02k
         abfd, bfd_asymbol_name (&sym->symbol));
4603
4604
1.10k
    sym->lineno = cache_ptr;
4605
1.10k
    if (sym->symbol.value < prev_offset)
4606
7
      ordered = false;
4607
1.10k
    prev_offset = sym->symbol.value;
4608
1.10k
  }
4609
6.04k
      else if (!have_func)
4610
  /* Drop line information that has no associated function.
4611
     PR 17521: file: 078-10659-0.004.  */
4612
1.17k
  continue;
4613
4.86k
      else
4614
4.86k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4615
5.96k
      cache_ptr++;
4616
5.96k
    }
4617
4618
6
  asect->lineno_count = cache_ptr - lineno_cache;
4619
6
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4620
6
  free (native_lineno);
4621
4622
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4623
6
  if (!ordered)
4624
2
    {
4625
      /* Sort the table.  */
4626
2
      alent **func_table;
4627
2
      alent *n_lineno_cache;
4628
4629
      /* Create a table of functions.  */
4630
2
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4631
0
  {
4632
0
    bfd_set_error (bfd_error_file_too_big);
4633
0
    ret = false;
4634
0
  }
4635
2
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4636
2
  {
4637
2
    alent **p = func_table;
4638
2
    unsigned int i;
4639
4640
1.67k
    for (i = 0; i < asect->lineno_count; i++)
4641
1.67k
      if (lineno_cache[i].line_number == 0)
4642
385
        *p++ = &lineno_cache[i];
4643
4644
2
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4645
4646
    /* Sort by functions.  */
4647
2
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4648
4649
    /* Create the new sorted table.  */
4650
2
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4651
0
      {
4652
0
        bfd_set_error (bfd_error_file_too_big);
4653
0
        ret = false;
4654
0
      }
4655
2
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4656
2
      {
4657
2
        alent *n_cache_ptr = n_lineno_cache;
4658
4659
387
        for (i = 0; i < nbr_func; i++)
4660
385
    {
4661
385
      coff_symbol_type *sym;
4662
385
      alent *old_ptr = func_table[i];
4663
4664
      /* Update the function entry.  */
4665
385
      sym = (coff_symbol_type *) old_ptr->u.sym;
4666
      /* PR binutils/17512: Point the lineno to where
4667
         this entry will be after the memcpy below.  */
4668
385
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4669
      /* Copy the function and line number entries.  */
4670
385
      do
4671
1.67k
        *n_cache_ptr++ = *old_ptr++;
4672
1.67k
      while (old_ptr->line_number != 0);
4673
385
    }
4674
4675
2
        memcpy (lineno_cache, n_lineno_cache,
4676
2
          asect->lineno_count * sizeof (alent));
4677
2
      }
4678
0
    else
4679
0
      ret = false;
4680
2
    bfd_release (abfd, func_table);
4681
2
  }
4682
0
      else
4683
0
  ret = false;
4684
2
    }
4685
4686
6
  return ret;
4687
6
}
pe-mcore.c:coff_slurp_line_table
Line
Count
Source
4490
168
{
4491
168
  LINENO *native_lineno;
4492
168
  alent *lineno_cache;
4493
168
  unsigned int counter;
4494
168
  alent *cache_ptr;
4495
168
  bfd_vma prev_offset = 0;
4496
168
  bool ordered = true;
4497
168
  unsigned int nbr_func;
4498
168
  LINENO *src;
4499
168
  bool have_func;
4500
168
  bool ret = true;
4501
168
  size_t amt;
4502
4503
168
  if (asect->lineno_count == 0)
4504
123
    return true;
4505
4506
45
  BFD_ASSERT (asect->lineno == NULL);
4507
4508
45
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4509
45
             asect->lineno_count,
4510
45
             bfd_coff_linesz (abfd));
4511
45
  if (native_lineno == NULL)
4512
0
    {
4513
0
      _bfd_error_handler
4514
0
  (_("%pB: warning: line number table read failed"), abfd);
4515
0
      return false;
4516
0
    }
4517
4518
45
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4519
0
    {
4520
0
      bfd_set_error (bfd_error_file_too_big);
4521
0
      free (native_lineno);
4522
0
      return false;
4523
0
    }
4524
45
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4525
45
  if (lineno_cache == NULL)
4526
0
    {
4527
0
      free (native_lineno);
4528
0
      return false;
4529
0
    }
4530
4531
45
  cache_ptr = lineno_cache;
4532
45
  asect->lineno = lineno_cache;
4533
45
  src = native_lineno;
4534
45
  nbr_func = 0;
4535
45
  have_func = false;
4536
4537
88.9k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4538
88.9k
    {
4539
88.9k
      struct internal_lineno dst;
4540
4541
88.9k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4542
88.9k
      cache_ptr->line_number = dst.l_lnno;
4543
      /* Appease memory checkers that get all excited about
4544
   uninitialised memory when copying alents if u.offset is
4545
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4546
88.9k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4547
4548
88.9k
      if (cache_ptr->line_number == 0)
4549
42.6k
  {
4550
42.6k
    combined_entry_type * ent;
4551
42.6k
    unsigned long symndx;
4552
42.6k
    coff_symbol_type *sym;
4553
4554
42.6k
    have_func = false;
4555
42.6k
    symndx = dst.l_addr.l_symndx;
4556
42.6k
    if (symndx >= obj_raw_syment_count (abfd))
4557
13.1k
      {
4558
13.1k
        _bfd_error_handler
4559
    /* xgettext:c-format */
4560
13.1k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4561
13.1k
     abfd, symndx, counter);
4562
13.1k
        cache_ptr->line_number = -1;
4563
13.1k
        ret = false;
4564
13.1k
        continue;
4565
13.1k
      }
4566
4567
29.4k
    ent = obj_raw_syments (abfd) + symndx;
4568
    /* FIXME: We should not be casting between ints and
4569
       pointers like this.  */
4570
29.4k
    if (! ent->is_sym)
4571
984
      {
4572
984
        _bfd_error_handler
4573
    /* xgettext:c-format */
4574
984
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4575
984
     abfd, symndx, counter);
4576
984
        cache_ptr->line_number = -1;
4577
984
        ret = false;
4578
984
        continue;
4579
984
      }
4580
28.4k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4581
4582
    /* PR 17512 file: 078-10659-0.004  */
4583
28.4k
    if (sym < obj_symbols (abfd)
4584
28.4k
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4585
0
      {
4586
0
        _bfd_error_handler
4587
    /* xgettext:c-format */
4588
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4589
0
     abfd, counter);
4590
0
        cache_ptr->line_number = -1;
4591
0
        ret = false;
4592
0
        continue;
4593
0
      }
4594
4595
28.4k
    have_func = true;
4596
28.4k
    nbr_func++;
4597
28.4k
    cache_ptr->u.sym = (asymbol *) sym;
4598
28.4k
    if (sym->lineno != NULL)
4599
28.1k
      _bfd_error_handler
4600
        /* xgettext:c-format */
4601
28.1k
        (_("%pB: warning: duplicate line number information for `%s'"),
4602
28.1k
         abfd, bfd_asymbol_name (&sym->symbol));
4603
4604
28.4k
    sym->lineno = cache_ptr;
4605
28.4k
    if (sym->symbol.value < prev_offset)
4606
107
      ordered = false;
4607
28.4k
    prev_offset = sym->symbol.value;
4608
28.4k
  }
4609
46.2k
      else if (!have_func)
4610
  /* Drop line information that has no associated function.
4611
     PR 17521: file: 078-10659-0.004.  */
4612
26.3k
  continue;
4613
19.9k
      else
4614
19.9k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4615
48.3k
      cache_ptr++;
4616
48.3k
    }
4617
4618
45
  asect->lineno_count = cache_ptr - lineno_cache;
4619
45
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4620
45
  free (native_lineno);
4621
4622
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4623
45
  if (!ordered)
4624
14
    {
4625
      /* Sort the table.  */
4626
14
      alent **func_table;
4627
14
      alent *n_lineno_cache;
4628
4629
      /* Create a table of functions.  */
4630
14
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4631
0
  {
4632
0
    bfd_set_error (bfd_error_file_too_big);
4633
0
    ret = false;
4634
0
  }
4635
14
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4636
14
  {
4637
14
    alent **p = func_table;
4638
14
    unsigned int i;
4639
4640
40.3k
    for (i = 0; i < asect->lineno_count; i++)
4641
40.2k
      if (lineno_cache[i].line_number == 0)
4642
21.5k
        *p++ = &lineno_cache[i];
4643
4644
14
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4645
4646
    /* Sort by functions.  */
4647
14
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4648
4649
    /* Create the new sorted table.  */
4650
14
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4651
0
      {
4652
0
        bfd_set_error (bfd_error_file_too_big);
4653
0
        ret = false;
4654
0
      }
4655
14
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4656
14
      {
4657
14
        alent *n_cache_ptr = n_lineno_cache;
4658
4659
21.5k
        for (i = 0; i < nbr_func; i++)
4660
21.5k
    {
4661
21.5k
      coff_symbol_type *sym;
4662
21.5k
      alent *old_ptr = func_table[i];
4663
4664
      /* Update the function entry.  */
4665
21.5k
      sym = (coff_symbol_type *) old_ptr->u.sym;
4666
      /* PR binutils/17512: Point the lineno to where
4667
         this entry will be after the memcpy below.  */
4668
21.5k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4669
      /* Copy the function and line number entries.  */
4670
21.5k
      do
4671
40.2k
        *n_cache_ptr++ = *old_ptr++;
4672
40.2k
      while (old_ptr->line_number != 0);
4673
21.5k
    }
4674
4675
14
        memcpy (lineno_cache, n_lineno_cache,
4676
14
          asect->lineno_count * sizeof (alent));
4677
14
      }
4678
0
    else
4679
0
      ret = false;
4680
14
    bfd_release (abfd, func_table);
4681
14
  }
4682
0
      else
4683
0
  ret = false;
4684
14
    }
4685
4686
45
  return ret;
4687
45
}
pe-sh.c:coff_slurp_line_table
Line
Count
Source
4490
120
{
4491
120
  LINENO *native_lineno;
4492
120
  alent *lineno_cache;
4493
120
  unsigned int counter;
4494
120
  alent *cache_ptr;
4495
120
  bfd_vma prev_offset = 0;
4496
120
  bool ordered = true;
4497
120
  unsigned int nbr_func;
4498
120
  LINENO *src;
4499
120
  bool have_func;
4500
120
  bool ret = true;
4501
120
  size_t amt;
4502
4503
120
  if (asect->lineno_count == 0)
4504
99
    return true;
4505
4506
21
  BFD_ASSERT (asect->lineno == NULL);
4507
4508
21
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4509
21
             asect->lineno_count,
4510
21
             bfd_coff_linesz (abfd));
4511
21
  if (native_lineno == NULL)
4512
15
    {
4513
15
      _bfd_error_handler
4514
15
  (_("%pB: warning: line number table read failed"), abfd);
4515
15
      return false;
4516
15
    }
4517
4518
6
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4519
0
    {
4520
0
      bfd_set_error (bfd_error_file_too_big);
4521
0
      free (native_lineno);
4522
0
      return false;
4523
0
    }
4524
6
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4525
6
  if (lineno_cache == NULL)
4526
0
    {
4527
0
      free (native_lineno);
4528
0
      return false;
4529
0
    }
4530
4531
6
  cache_ptr = lineno_cache;
4532
6
  asect->lineno = lineno_cache;
4533
6
  src = native_lineno;
4534
6
  nbr_func = 0;
4535
6
  have_func = false;
4536
4537
49.4k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4538
49.4k
    {
4539
49.4k
      struct internal_lineno dst;
4540
4541
49.4k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4542
49.4k
      cache_ptr->line_number = dst.l_lnno;
4543
      /* Appease memory checkers that get all excited about
4544
   uninitialised memory when copying alents if u.offset is
4545
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4546
49.4k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4547
4548
49.4k
      if (cache_ptr->line_number == 0)
4549
25.3k
  {
4550
25.3k
    combined_entry_type * ent;
4551
25.3k
    unsigned long symndx;
4552
25.3k
    coff_symbol_type *sym;
4553
4554
25.3k
    have_func = false;
4555
25.3k
    symndx = dst.l_addr.l_symndx;
4556
25.3k
    if (symndx >= obj_raw_syment_count (abfd))
4557
10.0k
      {
4558
10.0k
        _bfd_error_handler
4559
    /* xgettext:c-format */
4560
10.0k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4561
10.0k
     abfd, symndx, counter);
4562
10.0k
        cache_ptr->line_number = -1;
4563
10.0k
        ret = false;
4564
10.0k
        continue;
4565
10.0k
      }
4566
4567
15.3k
    ent = obj_raw_syments (abfd) + symndx;
4568
    /* FIXME: We should not be casting between ints and
4569
       pointers like this.  */
4570
15.3k
    if (! ent->is_sym)
4571
1.75k
      {
4572
1.75k
        _bfd_error_handler
4573
    /* xgettext:c-format */
4574
1.75k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4575
1.75k
     abfd, symndx, counter);
4576
1.75k
        cache_ptr->line_number = -1;
4577
1.75k
        ret = false;
4578
1.75k
        continue;
4579
1.75k
      }
4580
13.5k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4581
4582
    /* PR 17512 file: 078-10659-0.004  */
4583
13.5k
    if (sym < obj_symbols (abfd)
4584
13.5k
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4585
0
      {
4586
0
        _bfd_error_handler
4587
    /* xgettext:c-format */
4588
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4589
0
     abfd, counter);
4590
0
        cache_ptr->line_number = -1;
4591
0
        ret = false;
4592
0
        continue;
4593
0
      }
4594
4595
13.5k
    have_func = true;
4596
13.5k
    nbr_func++;
4597
13.5k
    cache_ptr->u.sym = (asymbol *) sym;
4598
13.5k
    if (sym->lineno != NULL)
4599
13.4k
      _bfd_error_handler
4600
        /* xgettext:c-format */
4601
13.4k
        (_("%pB: warning: duplicate line number information for `%s'"),
4602
13.4k
         abfd, bfd_asymbol_name (&sym->symbol));
4603
4604
13.5k
    sym->lineno = cache_ptr;
4605
13.5k
    if (sym->symbol.value < prev_offset)
4606
103
      ordered = false;
4607
13.5k
    prev_offset = sym->symbol.value;
4608
13.5k
  }
4609
24.0k
      else if (!have_func)
4610
  /* Drop line information that has no associated function.
4611
     PR 17521: file: 078-10659-0.004.  */
4612
12.8k
  continue;
4613
11.2k
      else
4614
11.2k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4615
24.8k
      cache_ptr++;
4616
24.8k
    }
4617
4618
6
  asect->lineno_count = cache_ptr - lineno_cache;
4619
6
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4620
6
  free (native_lineno);
4621
4622
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4623
6
  if (!ordered)
4624
5
    {
4625
      /* Sort the table.  */
4626
5
      alent **func_table;
4627
5
      alent *n_lineno_cache;
4628
4629
      /* Create a table of functions.  */
4630
5
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4631
0
  {
4632
0
    bfd_set_error (bfd_error_file_too_big);
4633
0
    ret = false;
4634
0
  }
4635
5
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4636
5
  {
4637
5
    alent **p = func_table;
4638
5
    unsigned int i;
4639
4640
24.6k
    for (i = 0; i < asect->lineno_count; i++)
4641
24.6k
      if (lineno_cache[i].line_number == 0)
4642
13.5k
        *p++ = &lineno_cache[i];
4643
4644
5
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4645
4646
    /* Sort by functions.  */
4647
5
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4648
4649
    /* Create the new sorted table.  */
4650
5
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4651
0
      {
4652
0
        bfd_set_error (bfd_error_file_too_big);
4653
0
        ret = false;
4654
0
      }
4655
5
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4656
5
      {
4657
5
        alent *n_cache_ptr = n_lineno_cache;
4658
4659
13.5k
        for (i = 0; i < nbr_func; i++)
4660
13.5k
    {
4661
13.5k
      coff_symbol_type *sym;
4662
13.5k
      alent *old_ptr = func_table[i];
4663
4664
      /* Update the function entry.  */
4665
13.5k
      sym = (coff_symbol_type *) old_ptr->u.sym;
4666
      /* PR binutils/17512: Point the lineno to where
4667
         this entry will be after the memcpy below.  */
4668
13.5k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4669
      /* Copy the function and line number entries.  */
4670
13.5k
      do
4671
24.6k
        *n_cache_ptr++ = *old_ptr++;
4672
24.6k
      while (old_ptr->line_number != 0);
4673
13.5k
    }
4674
4675
5
        memcpy (lineno_cache, n_lineno_cache,
4676
5
          asect->lineno_count * sizeof (alent));
4677
5
      }
4678
0
    else
4679
0
      ret = false;
4680
5
    bfd_release (abfd, func_table);
4681
5
  }
4682
0
      else
4683
0
  ret = false;
4684
5
    }
4685
4686
6
  return ret;
4687
6
}
pei-arm-wince.c:coff_slurp_line_table
Line
Count
Source
4490
4.10k
{
4491
4.10k
  LINENO *native_lineno;
4492
4.10k
  alent *lineno_cache;
4493
4.10k
  unsigned int counter;
4494
4.10k
  alent *cache_ptr;
4495
4.10k
  bfd_vma prev_offset = 0;
4496
4.10k
  bool ordered = true;
4497
4.10k
  unsigned int nbr_func;
4498
4.10k
  LINENO *src;
4499
4.10k
  bool have_func;
4500
4.10k
  bool ret = true;
4501
4.10k
  size_t amt;
4502
4503
4.10k
  if (asect->lineno_count == 0)
4504
4.10k
    return true;
4505
4506
5
  BFD_ASSERT (asect->lineno == NULL);
4507
4508
5
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4509
5
             asect->lineno_count,
4510
5
             bfd_coff_linesz (abfd));
4511
5
  if (native_lineno == NULL)
4512
0
    {
4513
0
      _bfd_error_handler
4514
0
  (_("%pB: warning: line number table read failed"), abfd);
4515
0
      return false;
4516
0
    }
4517
4518
5
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4519
0
    {
4520
0
      bfd_set_error (bfd_error_file_too_big);
4521
0
      free (native_lineno);
4522
0
      return false;
4523
0
    }
4524
5
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4525
5
  if (lineno_cache == NULL)
4526
0
    {
4527
0
      free (native_lineno);
4528
0
      return false;
4529
0
    }
4530
4531
5
  cache_ptr = lineno_cache;
4532
5
  asect->lineno = lineno_cache;
4533
5
  src = native_lineno;
4534
5
  nbr_func = 0;
4535
5
  have_func = false;
4536
4537
17.3k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4538
17.3k
    {
4539
17.3k
      struct internal_lineno dst;
4540
4541
17.3k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4542
17.3k
      cache_ptr->line_number = dst.l_lnno;
4543
      /* Appease memory checkers that get all excited about
4544
   uninitialised memory when copying alents if u.offset is
4545
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4546
17.3k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4547
4548
17.3k
      if (cache_ptr->line_number == 0)
4549
8.19k
  {
4550
8.19k
    combined_entry_type * ent;
4551
8.19k
    unsigned long symndx;
4552
8.19k
    coff_symbol_type *sym;
4553
4554
8.19k
    have_func = false;
4555
8.19k
    symndx = dst.l_addr.l_symndx;
4556
8.19k
    if (symndx >= obj_raw_syment_count (abfd))
4557
3.66k
      {
4558
3.66k
        _bfd_error_handler
4559
    /* xgettext:c-format */
4560
3.66k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4561
3.66k
     abfd, symndx, counter);
4562
3.66k
        cache_ptr->line_number = -1;
4563
3.66k
        ret = false;
4564
3.66k
        continue;
4565
3.66k
      }
4566
4567
4.53k
    ent = obj_raw_syments (abfd) + symndx;
4568
    /* FIXME: We should not be casting between ints and
4569
       pointers like this.  */
4570
4.53k
    if (! ent->is_sym)
4571
35
      {
4572
35
        _bfd_error_handler
4573
    /* xgettext:c-format */
4574
35
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4575
35
     abfd, symndx, counter);
4576
35
        cache_ptr->line_number = -1;
4577
35
        ret = false;
4578
35
        continue;
4579
35
      }
4580
4.50k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4581
4582
    /* PR 17512 file: 078-10659-0.004  */
4583
4.50k
    if (sym < obj_symbols (abfd)
4584
4.50k
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4585
0
      {
4586
0
        _bfd_error_handler
4587
    /* xgettext:c-format */
4588
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4589
0
     abfd, counter);
4590
0
        cache_ptr->line_number = -1;
4591
0
        ret = false;
4592
0
        continue;
4593
0
      }
4594
4595
4.50k
    have_func = true;
4596
4.50k
    nbr_func++;
4597
4.50k
    cache_ptr->u.sym = (asymbol *) sym;
4598
4.50k
    if (sym->lineno != NULL)
4599
4.49k
      _bfd_error_handler
4600
        /* xgettext:c-format */
4601
4.49k
        (_("%pB: warning: duplicate line number information for `%s'"),
4602
4.49k
         abfd, bfd_asymbol_name (&sym->symbol));
4603
4604
4.50k
    sym->lineno = cache_ptr;
4605
4.50k
    if (sym->symbol.value < prev_offset)
4606
134
      ordered = false;
4607
4.50k
    prev_offset = sym->symbol.value;
4608
4.50k
  }
4609
9.16k
      else if (!have_func)
4610
  /* Drop line information that has no associated function.
4611
     PR 17521: file: 078-10659-0.004.  */
4612
5.28k
  continue;
4613
3.87k
      else
4614
3.87k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4615
8.37k
      cache_ptr++;
4616
8.37k
    }
4617
4618
5
  asect->lineno_count = cache_ptr - lineno_cache;
4619
5
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4620
5
  free (native_lineno);
4621
4622
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4623
5
  if (!ordered)
4624
3
    {
4625
      /* Sort the table.  */
4626
3
      alent **func_table;
4627
3
      alent *n_lineno_cache;
4628
4629
      /* Create a table of functions.  */
4630
3
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4631
0
  {
4632
0
    bfd_set_error (bfd_error_file_too_big);
4633
0
    ret = false;
4634
0
  }
4635
3
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4636
3
  {
4637
3
    alent **p = func_table;
4638
3
    unsigned int i;
4639
4640
6.80k
    for (i = 0; i < asect->lineno_count; i++)
4641
6.80k
      if (lineno_cache[i].line_number == 0)
4642
4.11k
        *p++ = &lineno_cache[i];
4643
4644
3
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4645
4646
    /* Sort by functions.  */
4647
3
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4648
4649
    /* Create the new sorted table.  */
4650
3
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4651
0
      {
4652
0
        bfd_set_error (bfd_error_file_too_big);
4653
0
        ret = false;
4654
0
      }
4655
3
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4656
3
      {
4657
3
        alent *n_cache_ptr = n_lineno_cache;
4658
4659
4.11k
        for (i = 0; i < nbr_func; i++)
4660
4.11k
    {
4661
4.11k
      coff_symbol_type *sym;
4662
4.11k
      alent *old_ptr = func_table[i];
4663
4664
      /* Update the function entry.  */
4665
4.11k
      sym = (coff_symbol_type *) old_ptr->u.sym;
4666
      /* PR binutils/17512: Point the lineno to where
4667
         this entry will be after the memcpy below.  */
4668
4.11k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4669
      /* Copy the function and line number entries.  */
4670
4.11k
      do
4671
6.80k
        *n_cache_ptr++ = *old_ptr++;
4672
6.80k
      while (old_ptr->line_number != 0);
4673
4.11k
    }
4674
4675
3
        memcpy (lineno_cache, n_lineno_cache,
4676
3
          asect->lineno_count * sizeof (alent));
4677
3
      }
4678
0
    else
4679
0
      ret = false;
4680
3
    bfd_release (abfd, func_table);
4681
3
  }
4682
0
      else
4683
0
  ret = false;
4684
3
    }
4685
4686
5
  return ret;
4687
5
}
pei-arm.c:coff_slurp_line_table
Line
Count
Source
4490
9
{
4491
9
  LINENO *native_lineno;
4492
9
  alent *lineno_cache;
4493
9
  unsigned int counter;
4494
9
  alent *cache_ptr;
4495
9
  bfd_vma prev_offset = 0;
4496
9
  bool ordered = true;
4497
9
  unsigned int nbr_func;
4498
9
  LINENO *src;
4499
9
  bool have_func;
4500
9
  bool ret = true;
4501
9
  size_t amt;
4502
4503
9
  if (asect->lineno_count == 0)
4504
2
    return true;
4505
4506
7
  BFD_ASSERT (asect->lineno == NULL);
4507
4508
7
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4509
7
             asect->lineno_count,
4510
7
             bfd_coff_linesz (abfd));
4511
7
  if (native_lineno == NULL)
4512
0
    {
4513
0
      _bfd_error_handler
4514
0
  (_("%pB: warning: line number table read failed"), abfd);
4515
0
      return false;
4516
0
    }
4517
4518
7
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4519
0
    {
4520
0
      bfd_set_error (bfd_error_file_too_big);
4521
0
      free (native_lineno);
4522
0
      return false;
4523
0
    }
4524
7
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4525
7
  if (lineno_cache == NULL)
4526
0
    {
4527
0
      free (native_lineno);
4528
0
      return false;
4529
0
    }
4530
4531
7
  cache_ptr = lineno_cache;
4532
7
  asect->lineno = lineno_cache;
4533
7
  src = native_lineno;
4534
7
  nbr_func = 0;
4535
7
  have_func = false;
4536
4537
83.9k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4538
83.9k
    {
4539
83.9k
      struct internal_lineno dst;
4540
4541
83.9k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4542
83.9k
      cache_ptr->line_number = dst.l_lnno;
4543
      /* Appease memory checkers that get all excited about
4544
   uninitialised memory when copying alents if u.offset is
4545
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4546
83.9k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4547
4548
83.9k
      if (cache_ptr->line_number == 0)
4549
11.2k
  {
4550
11.2k
    combined_entry_type * ent;
4551
11.2k
    unsigned long symndx;
4552
11.2k
    coff_symbol_type *sym;
4553
4554
11.2k
    have_func = false;
4555
11.2k
    symndx = dst.l_addr.l_symndx;
4556
11.2k
    if (symndx >= obj_raw_syment_count (abfd))
4557
4.63k
      {
4558
4.63k
        _bfd_error_handler
4559
    /* xgettext:c-format */
4560
4.63k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4561
4.63k
     abfd, symndx, counter);
4562
4.63k
        cache_ptr->line_number = -1;
4563
4.63k
        ret = false;
4564
4.63k
        continue;
4565
4.63k
      }
4566
4567
6.61k
    ent = obj_raw_syments (abfd) + symndx;
4568
    /* FIXME: We should not be casting between ints and
4569
       pointers like this.  */
4570
6.61k
    if (! ent->is_sym)
4571
632
      {
4572
632
        _bfd_error_handler
4573
    /* xgettext:c-format */
4574
632
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4575
632
     abfd, symndx, counter);
4576
632
        cache_ptr->line_number = -1;
4577
632
        ret = false;
4578
632
        continue;
4579
632
      }
4580
5.98k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4581
4582
    /* PR 17512 file: 078-10659-0.004  */
4583
5.98k
    if (sym < obj_symbols (abfd)
4584
5.98k
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4585
0
      {
4586
0
        _bfd_error_handler
4587
    /* xgettext:c-format */
4588
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4589
0
     abfd, counter);
4590
0
        cache_ptr->line_number = -1;
4591
0
        ret = false;
4592
0
        continue;
4593
0
      }
4594
4595
5.98k
    have_func = true;
4596
5.98k
    nbr_func++;
4597
5.98k
    cache_ptr->u.sym = (asymbol *) sym;
4598
5.98k
    if (sym->lineno != NULL)
4599
5.88k
      _bfd_error_handler
4600
        /* xgettext:c-format */
4601
5.88k
        (_("%pB: warning: duplicate line number information for `%s'"),
4602
5.88k
         abfd, bfd_asymbol_name (&sym->symbol));
4603
4604
5.98k
    sym->lineno = cache_ptr;
4605
5.98k
    if (sym->symbol.value < prev_offset)
4606
215
      ordered = false;
4607
5.98k
    prev_offset = sym->symbol.value;
4608
5.98k
  }
4609
72.7k
      else if (!have_func)
4610
  /* Drop line information that has no associated function.
4611
     PR 17521: file: 078-10659-0.004.  */
4612
50.4k
  continue;
4613
22.2k
      else
4614
22.2k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4615
28.2k
      cache_ptr++;
4616
28.2k
    }
4617
4618
7
  asect->lineno_count = cache_ptr - lineno_cache;
4619
7
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4620
7
  free (native_lineno);
4621
4622
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4623
7
  if (!ordered)
4624
7
    {
4625
      /* Sort the table.  */
4626
7
      alent **func_table;
4627
7
      alent *n_lineno_cache;
4628
4629
      /* Create a table of functions.  */
4630
7
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4631
0
  {
4632
0
    bfd_set_error (bfd_error_file_too_big);
4633
0
    ret = false;
4634
0
  }
4635
7
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4636
7
  {
4637
7
    alent **p = func_table;
4638
7
    unsigned int i;
4639
4640
28.2k
    for (i = 0; i < asect->lineno_count; i++)
4641
28.2k
      if (lineno_cache[i].line_number == 0)
4642
5.98k
        *p++ = &lineno_cache[i];
4643
4644
7
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4645
4646
    /* Sort by functions.  */
4647
7
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4648
4649
    /* Create the new sorted table.  */
4650
7
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4651
0
      {
4652
0
        bfd_set_error (bfd_error_file_too_big);
4653
0
        ret = false;
4654
0
      }
4655
7
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4656
7
      {
4657
7
        alent *n_cache_ptr = n_lineno_cache;
4658
4659
5.98k
        for (i = 0; i < nbr_func; i++)
4660
5.98k
    {
4661
5.98k
      coff_symbol_type *sym;
4662
5.98k
      alent *old_ptr = func_table[i];
4663
4664
      /* Update the function entry.  */
4665
5.98k
      sym = (coff_symbol_type *) old_ptr->u.sym;
4666
      /* PR binutils/17512: Point the lineno to where
4667
         this entry will be after the memcpy below.  */
4668
5.98k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4669
      /* Copy the function and line number entries.  */
4670
5.98k
      do
4671
28.2k
        *n_cache_ptr++ = *old_ptr++;
4672
28.2k
      while (old_ptr->line_number != 0);
4673
5.98k
    }
4674
4675
7
        memcpy (lineno_cache, n_lineno_cache,
4676
7
          asect->lineno_count * sizeof (alent));
4677
7
      }
4678
0
    else
4679
0
      ret = false;
4680
7
    bfd_release (abfd, func_table);
4681
7
  }
4682
0
      else
4683
0
  ret = false;
4684
7
    }
4685
4686
7
  return ret;
4687
7
}
pei-mcore.c:coff_slurp_line_table
Line
Count
Source
4490
5
{
4491
5
  LINENO *native_lineno;
4492
5
  alent *lineno_cache;
4493
5
  unsigned int counter;
4494
5
  alent *cache_ptr;
4495
5
  bfd_vma prev_offset = 0;
4496
5
  bool ordered = true;
4497
5
  unsigned int nbr_func;
4498
5
  LINENO *src;
4499
5
  bool have_func;
4500
5
  bool ret = true;
4501
5
  size_t amt;
4502
4503
5
  if (asect->lineno_count == 0)
4504
0
    return true;
4505
4506
5
  BFD_ASSERT (asect->lineno == NULL);
4507
4508
5
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4509
5
             asect->lineno_count,
4510
5
             bfd_coff_linesz (abfd));
4511
5
  if (native_lineno == NULL)
4512
0
    {
4513
0
      _bfd_error_handler
4514
0
  (_("%pB: warning: line number table read failed"), abfd);
4515
0
      return false;
4516
0
    }
4517
4518
5
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4519
0
    {
4520
0
      bfd_set_error (bfd_error_file_too_big);
4521
0
      free (native_lineno);
4522
0
      return false;
4523
0
    }
4524
5
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4525
5
  if (lineno_cache == NULL)
4526
0
    {
4527
0
      free (native_lineno);
4528
0
      return false;
4529
0
    }
4530
4531
5
  cache_ptr = lineno_cache;
4532
5
  asect->lineno = lineno_cache;
4533
5
  src = native_lineno;
4534
5
  nbr_func = 0;
4535
5
  have_func = false;
4536
4537
68.0k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4538
68.0k
    {
4539
68.0k
      struct internal_lineno dst;
4540
4541
68.0k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4542
68.0k
      cache_ptr->line_number = dst.l_lnno;
4543
      /* Appease memory checkers that get all excited about
4544
   uninitialised memory when copying alents if u.offset is
4545
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4546
68.0k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4547
4548
68.0k
      if (cache_ptr->line_number == 0)
4549
23.0k
  {
4550
23.0k
    combined_entry_type * ent;
4551
23.0k
    unsigned long symndx;
4552
23.0k
    coff_symbol_type *sym;
4553
4554
23.0k
    have_func = false;
4555
23.0k
    symndx = dst.l_addr.l_symndx;
4556
23.0k
    if (symndx >= obj_raw_syment_count (abfd))
4557
9.65k
      {
4558
9.65k
        _bfd_error_handler
4559
    /* xgettext:c-format */
4560
9.65k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4561
9.65k
     abfd, symndx, counter);
4562
9.65k
        cache_ptr->line_number = -1;
4563
9.65k
        ret = false;
4564
9.65k
        continue;
4565
9.65k
      }
4566
4567
13.3k
    ent = obj_raw_syments (abfd) + symndx;
4568
    /* FIXME: We should not be casting between ints and
4569
       pointers like this.  */
4570
13.3k
    if (! ent->is_sym)
4571
96
      {
4572
96
        _bfd_error_handler
4573
    /* xgettext:c-format */
4574
96
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4575
96
     abfd, symndx, counter);
4576
96
        cache_ptr->line_number = -1;
4577
96
        ret = false;
4578
96
        continue;
4579
96
      }
4580
13.2k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4581
4582
    /* PR 17512 file: 078-10659-0.004  */
4583
13.2k
    if (sym < obj_symbols (abfd)
4584
13.2k
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4585
0
      {
4586
0
        _bfd_error_handler
4587
    /* xgettext:c-format */
4588
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4589
0
     abfd, counter);
4590
0
        cache_ptr->line_number = -1;
4591
0
        ret = false;
4592
0
        continue;
4593
0
      }
4594
4595
13.2k
    have_func = true;
4596
13.2k
    nbr_func++;
4597
13.2k
    cache_ptr->u.sym = (asymbol *) sym;
4598
13.2k
    if (sym->lineno != NULL)
4599
13.2k
      _bfd_error_handler
4600
        /* xgettext:c-format */
4601
13.2k
        (_("%pB: warning: duplicate line number information for `%s'"),
4602
13.2k
         abfd, bfd_asymbol_name (&sym->symbol));
4603
4604
13.2k
    sym->lineno = cache_ptr;
4605
13.2k
    if (sym->symbol.value < prev_offset)
4606
209
      ordered = false;
4607
13.2k
    prev_offset = sym->symbol.value;
4608
13.2k
  }
4609
45.0k
      else if (!have_func)
4610
  /* Drop line information that has no associated function.
4611
     PR 17521: file: 078-10659-0.004.  */
4612
26.1k
  continue;
4613
18.8k
      else
4614
18.8k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4615
32.1k
      cache_ptr++;
4616
32.1k
    }
4617
4618
5
  asect->lineno_count = cache_ptr - lineno_cache;
4619
5
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4620
5
  free (native_lineno);
4621
4622
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4623
5
  if (!ordered)
4624
5
    {
4625
      /* Sort the table.  */
4626
5
      alent **func_table;
4627
5
      alent *n_lineno_cache;
4628
4629
      /* Create a table of functions.  */
4630
5
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4631
0
  {
4632
0
    bfd_set_error (bfd_error_file_too_big);
4633
0
    ret = false;
4634
0
  }
4635
5
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4636
5
  {
4637
5
    alent **p = func_table;
4638
5
    unsigned int i;
4639
4640
32.1k
    for (i = 0; i < asect->lineno_count; i++)
4641
32.1k
      if (lineno_cache[i].line_number == 0)
4642
13.2k
        *p++ = &lineno_cache[i];
4643
4644
5
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4645
4646
    /* Sort by functions.  */
4647
5
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4648
4649
    /* Create the new sorted table.  */
4650
5
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4651
0
      {
4652
0
        bfd_set_error (bfd_error_file_too_big);
4653
0
        ret = false;
4654
0
      }
4655
5
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4656
5
      {
4657
5
        alent *n_cache_ptr = n_lineno_cache;
4658
4659
13.2k
        for (i = 0; i < nbr_func; i++)
4660
13.2k
    {
4661
13.2k
      coff_symbol_type *sym;
4662
13.2k
      alent *old_ptr = func_table[i];
4663
4664
      /* Update the function entry.  */
4665
13.2k
      sym = (coff_symbol_type *) old_ptr->u.sym;
4666
      /* PR binutils/17512: Point the lineno to where
4667
         this entry will be after the memcpy below.  */
4668
13.2k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4669
      /* Copy the function and line number entries.  */
4670
13.2k
      do
4671
32.1k
        *n_cache_ptr++ = *old_ptr++;
4672
32.1k
      while (old_ptr->line_number != 0);
4673
13.2k
    }
4674
4675
5
        memcpy (lineno_cache, n_lineno_cache,
4676
5
          asect->lineno_count * sizeof (alent));
4677
5
      }
4678
0
    else
4679
0
      ret = false;
4680
5
    bfd_release (abfd, func_table);
4681
5
  }
4682
0
      else
4683
0
  ret = false;
4684
5
    }
4685
4686
5
  return ret;
4687
5
}
pei-sh.c:coff_slurp_line_table
Line
Count
Source
4490
746
{
4491
746
  LINENO *native_lineno;
4492
746
  alent *lineno_cache;
4493
746
  unsigned int counter;
4494
746
  alent *cache_ptr;
4495
746
  bfd_vma prev_offset = 0;
4496
746
  bool ordered = true;
4497
746
  unsigned int nbr_func;
4498
746
  LINENO *src;
4499
746
  bool have_func;
4500
746
  bool ret = true;
4501
746
  size_t amt;
4502
4503
746
  if (asect->lineno_count == 0)
4504
730
    return true;
4505
4506
16
  BFD_ASSERT (asect->lineno == NULL);
4507
4508
16
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4509
16
             asect->lineno_count,
4510
16
             bfd_coff_linesz (abfd));
4511
16
  if (native_lineno == NULL)
4512
16
    {
4513
16
      _bfd_error_handler
4514
16
  (_("%pB: warning: line number table read failed"), abfd);
4515
16
      return false;
4516
16
    }
4517
4518
0
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4519
0
    {
4520
0
      bfd_set_error (bfd_error_file_too_big);
4521
0
      free (native_lineno);
4522
0
      return false;
4523
0
    }
4524
0
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4525
0
  if (lineno_cache == NULL)
4526
0
    {
4527
0
      free (native_lineno);
4528
0
      return false;
4529
0
    }
4530
4531
0
  cache_ptr = lineno_cache;
4532
0
  asect->lineno = lineno_cache;
4533
0
  src = native_lineno;
4534
0
  nbr_func = 0;
4535
0
  have_func = false;
4536
4537
0
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4538
0
    {
4539
0
      struct internal_lineno dst;
4540
4541
0
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4542
0
      cache_ptr->line_number = dst.l_lnno;
4543
      /* Appease memory checkers that get all excited about
4544
   uninitialised memory when copying alents if u.offset is
4545
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4546
0
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4547
4548
0
      if (cache_ptr->line_number == 0)
4549
0
  {
4550
0
    combined_entry_type * ent;
4551
0
    unsigned long symndx;
4552
0
    coff_symbol_type *sym;
4553
4554
0
    have_func = false;
4555
0
    symndx = dst.l_addr.l_symndx;
4556
0
    if (symndx >= obj_raw_syment_count (abfd))
4557
0
      {
4558
0
        _bfd_error_handler
4559
    /* xgettext:c-format */
4560
0
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4561
0
     abfd, symndx, counter);
4562
0
        cache_ptr->line_number = -1;
4563
0
        ret = false;
4564
0
        continue;
4565
0
      }
4566
4567
0
    ent = obj_raw_syments (abfd) + symndx;
4568
    /* FIXME: We should not be casting between ints and
4569
       pointers like this.  */
4570
0
    if (! ent->is_sym)
4571
0
      {
4572
0
        _bfd_error_handler
4573
    /* xgettext:c-format */
4574
0
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4575
0
     abfd, symndx, counter);
4576
0
        cache_ptr->line_number = -1;
4577
0
        ret = false;
4578
0
        continue;
4579
0
      }
4580
0
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4581
4582
    /* PR 17512 file: 078-10659-0.004  */
4583
0
    if (sym < obj_symbols (abfd)
4584
0
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4585
0
      {
4586
0
        _bfd_error_handler
4587
    /* xgettext:c-format */
4588
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4589
0
     abfd, counter);
4590
0
        cache_ptr->line_number = -1;
4591
0
        ret = false;
4592
0
        continue;
4593
0
      }
4594
4595
0
    have_func = true;
4596
0
    nbr_func++;
4597
0
    cache_ptr->u.sym = (asymbol *) sym;
4598
0
    if (sym->lineno != NULL)
4599
0
      _bfd_error_handler
4600
        /* xgettext:c-format */
4601
0
        (_("%pB: warning: duplicate line number information for `%s'"),
4602
0
         abfd, bfd_asymbol_name (&sym->symbol));
4603
4604
0
    sym->lineno = cache_ptr;
4605
0
    if (sym->symbol.value < prev_offset)
4606
0
      ordered = false;
4607
0
    prev_offset = sym->symbol.value;
4608
0
  }
4609
0
      else if (!have_func)
4610
  /* Drop line information that has no associated function.
4611
     PR 17521: file: 078-10659-0.004.  */
4612
0
  continue;
4613
0
      else
4614
0
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4615
0
      cache_ptr++;
4616
0
    }
4617
4618
0
  asect->lineno_count = cache_ptr - lineno_cache;
4619
0
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4620
0
  free (native_lineno);
4621
4622
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4623
0
  if (!ordered)
4624
0
    {
4625
      /* Sort the table.  */
4626
0
      alent **func_table;
4627
0
      alent *n_lineno_cache;
4628
4629
      /* Create a table of functions.  */
4630
0
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4631
0
  {
4632
0
    bfd_set_error (bfd_error_file_too_big);
4633
0
    ret = false;
4634
0
  }
4635
0
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4636
0
  {
4637
0
    alent **p = func_table;
4638
0
    unsigned int i;
4639
4640
0
    for (i = 0; i < asect->lineno_count; i++)
4641
0
      if (lineno_cache[i].line_number == 0)
4642
0
        *p++ = &lineno_cache[i];
4643
4644
0
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4645
4646
    /* Sort by functions.  */
4647
0
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4648
4649
    /* Create the new sorted table.  */
4650
0
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4651
0
      {
4652
0
        bfd_set_error (bfd_error_file_too_big);
4653
0
        ret = false;
4654
0
      }
4655
0
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4656
0
      {
4657
0
        alent *n_cache_ptr = n_lineno_cache;
4658
4659
0
        for (i = 0; i < nbr_func; i++)
4660
0
    {
4661
0
      coff_symbol_type *sym;
4662
0
      alent *old_ptr = func_table[i];
4663
4664
      /* Update the function entry.  */
4665
0
      sym = (coff_symbol_type *) old_ptr->u.sym;
4666
      /* PR binutils/17512: Point the lineno to where
4667
         this entry will be after the memcpy below.  */
4668
0
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4669
      /* Copy the function and line number entries.  */
4670
0
      do
4671
0
        *n_cache_ptr++ = *old_ptr++;
4672
0
      while (old_ptr->line_number != 0);
4673
0
    }
4674
4675
0
        memcpy (lineno_cache, n_lineno_cache,
4676
0
          asect->lineno_count * sizeof (alent));
4677
0
      }
4678
0
    else
4679
0
      ret = false;
4680
0
    bfd_release (abfd, func_table);
4681
0
  }
4682
0
      else
4683
0
  ret = false;
4684
0
    }
4685
4686
0
  return ret;
4687
0
}
4688
4689
/* Slurp in the symbol table, converting it to generic form.  Note
4690
   that if coff_relocate_section is defined, the linker will read
4691
   symbols via coff_link_add_symbols, rather than via this routine.  */
4692
4693
static bool
4694
coff_slurp_symbol_table (bfd * abfd)
4695
1.22k
{
4696
1.22k
  combined_entry_type *native_symbols;
4697
1.22k
  coff_symbol_type *cached_area;
4698
1.22k
  unsigned int *table_ptr;
4699
1.22k
  unsigned int number_of_symbols = 0;
4700
1.22k
  bool ret = true;
4701
1.22k
  size_t amt;
4702
4703
1.22k
  if (obj_symbols (abfd))
4704
33
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
1.18k
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
442
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
746
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
746
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
746
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
746
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
746
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
746
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
746
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
746
  if (table_ptr == NULL)
4729
0
    return false;
4730
746
  else
4731
746
    {
4732
746
      coff_symbol_type *dst = cached_area;
4733
746
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
746
      unsigned int this_index = 0;
4735
4736
372k
      while (this_index < last_native_index)
4737
371k
  {
4738
371k
    combined_entry_type *src = native_symbols + this_index;
4739
371k
    table_ptr[this_index] = number_of_symbols;
4740
4741
371k
    dst->symbol.the_bfd = abfd;
4742
371k
    BFD_ASSERT (src->is_sym);
4743
371k
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4744
    /* We use the native name field to point to the cached field.  */
4745
371k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
371k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
371k
                 src->u.syment.n_scnum);
4748
371k
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
371k
    dst->symbol.value = 0;
4751
371k
    dst->done_lineno = false;
4752
4753
371k
    switch (src->u.syment.n_sclass)
4754
371k
      {
4755
10.4k
      case C_EXT:
4756
10.7k
      case C_WEAKEXT:
4757
#if defined ARM
4758
18
      case C_THUMBEXT:
4759
18
      case C_THUMBEXTFUNC:
4760
#endif
4761
#ifdef RS6000COFF_C
4762
2.36k
      case C_HIDEXT:
4763
2.36k
#ifndef AIX_WEAK_SUPPORT
4764
2.49k
      case C_AIX_WEAKEXT:
4765
#endif
4766
#endif
4767
2.49k
#ifdef C_SYSTEM
4768
11.1k
      case C_SYSTEM: /* System Wide variable.  */
4769
11.1k
#endif
4770
#ifdef COFF_WITH_PE
4771
      /* In PE, 0x68 (104) denotes a section symbol.  */
4772
5.92k
      case C_SECTION:
4773
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4774
6.02k
      case C_NT_WEAK:
4775
#endif
4776
6.02k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
6.02k
    {
4778
9.52k
    case COFF_SYMBOL_GLOBAL:
4779
9.52k
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4780
#if defined COFF_WITH_PE
4781
      /* PE sets the symbol to a value relative to the
4782
         start of the section.  */
4783
      dst->symbol.value = src->u.syment.n_value;
4784
#else
4785
      dst->symbol.value = (src->u.syment.n_value
4786
               - dst->symbol.section->vma);
4787
#endif
4788
9.52k
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
327
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
9.52k
      break;
4793
4794
1.13k
    case COFF_SYMBOL_COMMON:
4795
1.13k
      dst->symbol.section = bfd_com_section_ptr;
4796
1.13k
      dst->symbol.value = src->u.syment.n_value;
4797
1.13k
      break;
4798
4799
538
    case COFF_SYMBOL_UNDEFINED:
4800
538
      dst->symbol.section = bfd_und_section_ptr;
4801
538
      dst->symbol.value = 0;
4802
538
      break;
4803
4804
0
    case COFF_SYMBOL_PE_SECTION:
4805
0
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4806
0
      dst->symbol.value = 0;
4807
0
      break;
4808
4809
51
    case COFF_SYMBOL_LOCAL:
4810
51
      dst->symbol.flags = BSF_LOCAL;
4811
#if defined COFF_WITH_PE
4812
      /* PE sets the symbol to a value relative to the
4813
         start of the section.  */
4814
      dst->symbol.value = src->u.syment.n_value;
4815
#else
4816
      dst->symbol.value = (src->u.syment.n_value
4817
               - dst->symbol.section->vma);
4818
#endif
4819
51
      if (ISFCN ((src->u.syment.n_type)))
4820
16
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4821
51
      break;
4822
6.02k
    }
4823
4824
#ifdef RS6000COFF_C
4825
        /* A symbol with a csect entry should not go at the end.  */
4826
2.57k
        if (src->u.syment.n_numaux > 0)
4827
1.96k
    dst->symbol.flags |= BSF_NOT_AT_END;
4828
#endif
4829
4830
#ifdef COFF_WITH_PE
4831
6.02k
        if (src->u.syment.n_sclass == C_NT_WEAK)
4832
97
    dst->symbol.flags |= BSF_WEAK;
4833
4834
6.02k
        if (src->u.syment.n_sclass == C_SECTION
4835
6.02k
      && src->u.syment.n_scnum > 0)
4836
0
    dst->symbol.flags = BSF_LOCAL;
4837
#endif
4838
11.2k
        if (src->u.syment.n_sclass == C_WEAKEXT
4839
#ifdef RS6000COFF_C
4840
2.48k
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4841
#endif
4842
2.65k
      )
4843
340
    dst->symbol.flags |= BSF_WEAK;
4844
4845
2.65k
        break;
4846
4847
4.20k
      case C_STAT:  /* Static.  */
4848
#if defined ARM
4849
46
      case C_THUMBSTAT:    /* Thumb static.  */
4850
46
      case C_THUMBLABEL:   /* Thumb label.  */
4851
54
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4852
#endif
4853
#ifdef RS6000COFF_C
4854
878
      case C_DWARF:  /* A label in a dwarf section.  */
4855
980
      case C_INFO:  /* A label in a comment section.  */
4856
#endif
4857
5.10k
      case C_LABEL:  /* Label.  */
4858
5.10k
        if (src->u.syment.n_scnum == N_DEBUG)
4859
0
    dst->symbol.flags = BSF_DEBUGGING;
4860
5.10k
        else
4861
5.10k
    dst->symbol.flags = BSF_LOCAL;
4862
4863
        /* Base the value as an index from the base of the
4864
     section, if there is one.  */
4865
5.10k
        if (dst->symbol.section)
4866
5.10k
    {
4867
#if defined COFF_WITH_PE
4868
      /* PE sets the symbol to a value relative to the
4869
         start of the section.  */
4870
      dst->symbol.value = src->u.syment.n_value;
4871
#else
4872
      dst->symbol.value = (src->u.syment.n_value
4873
               - dst->symbol.section->vma);
4874
#endif
4875
5.10k
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
5.10k
        break;
4879
4880
887
      case C_FILE: /* File name.  */
4881
887
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
2.25k
      case C_MOS:   /* Member of structure.  */
4884
2.53k
      case C_EOS:   /* End of structure.  */
4885
3.08k
      case C_REGPARM: /* Register parameter.  */
4886
6.52k
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
8.20k
      case C_TPDEF: /* Type definition.  */
4889
9.90k
      case C_ARG:
4890
25.5k
      case C_AUTO: /* Automatic variable.  */
4891
27.0k
      case C_FIELD: /* Bit field.  */
4892
27.7k
      case C_ENTAG: /* Enumeration tag.  */
4893
29.7k
      case C_MOE:   /* Member of enumeration.  */
4894
31.7k
      case C_MOU:   /* Member of union.  */
4895
34.4k
      case C_UNTAG: /* Union tag.  */
4896
36.7k
      case C_STRTAG: /* Structure tag.  */
4897
#ifdef RS6000COFF_C
4898
9.99k
      case C_GSYM:
4899
10.4k
      case C_LSYM:
4900
10.4k
      case C_PSYM:
4901
10.7k
      case C_RSYM:
4902
11.5k
      case C_RPSYM:
4903
11.7k
      case C_STSYM:
4904
11.7k
      case C_TCSYM:
4905
11.9k
      case C_BCOMM:
4906
12.0k
      case C_ECOML:
4907
12.1k
      case C_ECOMM:
4908
12.2k
      case C_DECL:
4909
12.2k
      case C_ENTRY:
4910
12.3k
      case C_FUN:
4911
12.4k
      case C_ESTAT:
4912
#endif
4913
39.4k
        dst->symbol.flags |= BSF_DEBUGGING;
4914
12.4k
        dst->symbol.value = (src->u.syment.n_value);
4915
12.4k
        break;
4916
4917
#ifdef RS6000COFF_C
4918
123
      case C_BINCL: /* Beginning of include file.  */
4919
209
      case C_EINCL: /* Ending of include file.  */
4920
        /* The value is actually a pointer into the line numbers
4921
     of the file.  We locate the line number entry, and
4922
     set the section to the section which contains it, and
4923
     the value to the index in that section.  */
4924
209
        {
4925
209
    asection *sec;
4926
4927
209
    dst->symbol.flags = BSF_DEBUGGING;
4928
12.8k
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4929
12.6k
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4930
12.6k
          && ((file_ptr) (sec->line_filepos
4931
5.02k
              + sec->lineno_count * bfd_coff_linesz (abfd))
4932
5.02k
        > (file_ptr) src->u.syment.n_value))
4933
74
        break;
4934
209
    if (sec == NULL)
4935
135
      dst->symbol.value = 0;
4936
74
    else
4937
74
      {
4938
74
        dst->symbol.section = sec;
4939
74
        dst->symbol.value = ((src->u.syment.n_value
4940
74
            - sec->line_filepos)
4941
74
           / bfd_coff_linesz (abfd));
4942
74
        src->fix_line = 1;
4943
74
      }
4944
209
        }
4945
209
        break;
4946
4947
59
      case C_BSTAT:
4948
59
        dst->symbol.flags = BSF_DEBUGGING;
4949
4950
59
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4951
58
    dst->symbol.value = 0;
4952
1
        else
4953
1
    {
4954
      /* The value is actually a symbol index.  Save a pointer
4955
         to the symbol instead of the index.  FIXME: This
4956
         should use a union.  */
4957
1
      src->u.syment.n_value
4958
1
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4959
1
      dst->symbol.value = src->u.syment.n_value;
4960
1
      src->fix_value = 1;
4961
1
    }
4962
59
        break;
4963
0
#endif
4964
4965
303
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
715
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
2.15k
      case C_EFCN: /* Physical end of function.  */
4968
#if defined COFF_WITH_PE
4969
        /* PE sets the symbol to a value relative to the start
4970
     of the section.  */
4971
        dst->symbol.value = src->u.syment.n_value;
4972
877
        if (strcmp (dst->symbol.name, ".bf") != 0)
4973
877
    {
4974
      /* PE uses funny values for .ef and .lf; don't
4975
         relocate them.  */
4976
877
      dst->symbol.flags = BSF_DEBUGGING;
4977
877
    }
4978
0
        else
4979
0
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4980
#else
4981
        /* Base the value as an index from the base of the
4982
     section.  */
4983
1.27k
        dst->symbol.flags = BSF_LOCAL;
4984
        dst->symbol.value = (src->u.syment.n_value
4985
           - dst->symbol.section->vma);
4986
#endif
4987
2.15k
        break;
4988
4989
550
      case C_STATLAB: /* Static load time label.  */
4990
550
        dst->symbol.value = src->u.syment.n_value;
4991
550
        dst->symbol.flags = BSF_GLOBAL;
4992
550
        break;
4993
4994
271k
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
271k
        if (src->u.syment.n_type == 0
4998
271k
      && src->u.syment.n_value == 0
4999
271k
      && src->u.syment.n_scnum == 0)
5000
157k
    break;
5001
#ifdef RS6000COFF_C
5002
        /* XCOFF specific: deleted entry.  */
5003
24.7k
        if (src->u.syment.n_value == C_NULL_VALUE)
5004
0
    break;
5005
24.7k
#endif
5006
        /* Fall through.  */
5007
114k
      case C_EXTDEF: /* External definition.  */
5008
114k
      case C_ULABEL: /* Undefined label.  */
5009
115k
      case C_USTATIC: /* Undefined static.  */
5010
#ifndef COFF_WITH_PE
5011
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5012
         class to represent a section symbol.  */
5013
66.4k
      case C_LINE: /* line # reformatted as symbol table entry.  */
5014
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5015
66.5k
      case C_ALIAS: /* Duplicate tag.  */
5016
66.5k
#endif
5017
        /* New storage classes for TI COFF.  */
5018
#ifdef TICOFF
5019
7.73k
      case C_UEXT: /* Tentative external definition.  */
5020
#endif
5021
115k
      case C_EXTLAB: /* External load time label.  */
5022
154k
      default:
5023
154k
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
154k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
154k
     abfd, src->u.syment.n_sclass,
5027
154k
     dst->symbol.section->name, dst->symbol.name);
5028
154k
        ret = false;
5029
        /* Fall through.  */
5030
154k
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5031
        /* PR 20722: These symbols can also be generated by
5032
     building DLLs with --gc-sections enabled.  */
5033
154k
        dst->symbol.flags = BSF_DEBUGGING;
5034
154k
        dst->symbol.value = (src->u.syment.n_value);
5035
154k
        break;
5036
371k
      }
5037
5038
371k
    dst->native = src;
5039
371k
    dst->symbol.udata.i = 0;
5040
371k
    dst->lineno = NULL;
5041
5042
371k
    this_index += (src->u.syment.n_numaux) + 1;
5043
371k
    dst++;
5044
371k
    number_of_symbols++;
5045
371k
  }
5046
746
    }
5047
5048
746
  obj_symbols (abfd) = cached_area;
5049
746
  obj_raw_syments (abfd) = native_symbols;
5050
5051
746
  abfd->symcount = number_of_symbols;
5052
746
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
746
  {
5055
746
    asection *p;
5056
5057
746
    p = abfd->sections;
5058
12.3k
    while (p)
5059
12.1k
      {
5060
12.1k
  if (! coff_slurp_line_table (abfd, p))
5061
600
    return false;
5062
11.5k
  p = p->next;
5063
11.5k
      }
5064
746
  }
5065
5066
146
  return ret;
5067
746
}
pei-i386.c:coff_slurp_symbol_table
Line
Count
Source
4695
59
{
4696
59
  combined_entry_type *native_symbols;
4697
59
  coff_symbol_type *cached_area;
4698
59
  unsigned int *table_ptr;
4699
59
  unsigned int number_of_symbols = 0;
4700
59
  bool ret = true;
4701
59
  size_t amt;
4702
4703
59
  if (obj_symbols (abfd))
4704
3
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
56
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
24
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
32
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
32
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
32
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
32
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
32
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
32
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
32
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
32
  if (table_ptr == NULL)
4729
0
    return false;
4730
32
  else
4731
32
    {
4732
32
      coff_symbol_type *dst = cached_area;
4733
32
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
32
      unsigned int this_index = 0;
4735
4736
4.42k
      while (this_index < last_native_index)
4737
4.39k
  {
4738
4.39k
    combined_entry_type *src = native_symbols + this_index;
4739
4.39k
    table_ptr[this_index] = number_of_symbols;
4740
4741
4.39k
    dst->symbol.the_bfd = abfd;
4742
4.39k
    BFD_ASSERT (src->is_sym);
4743
4.39k
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4744
    /* We use the native name field to point to the cached field.  */
4745
4.39k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
4.39k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
4.39k
                 src->u.syment.n_scnum);
4748
4.39k
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
4.39k
    dst->symbol.value = 0;
4751
4.39k
    dst->done_lineno = false;
4752
4753
4.39k
    switch (src->u.syment.n_sclass)
4754
4.39k
      {
4755
78
      case C_EXT:
4756
83
      case C_WEAKEXT:
4757
#if defined ARM
4758
      case C_THUMBEXT:
4759
      case C_THUMBEXTFUNC:
4760
#endif
4761
#ifdef RS6000COFF_C
4762
      case C_HIDEXT:
4763
#ifndef AIX_WEAK_SUPPORT
4764
      case C_AIX_WEAKEXT:
4765
#endif
4766
#endif
4767
83
#ifdef C_SYSTEM
4768
88
      case C_SYSTEM: /* System Wide variable.  */
4769
88
#endif
4770
88
#ifdef COFF_WITH_PE
4771
      /* In PE, 0x68 (104) denotes a section symbol.  */
4772
93
      case C_SECTION:
4773
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4774
99
      case C_NT_WEAK:
4775
99
#endif
4776
99
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
99
    {
4778
70
    case COFF_SYMBOL_GLOBAL:
4779
70
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4780
70
#if defined COFF_WITH_PE
4781
      /* PE sets the symbol to a value relative to the
4782
         start of the section.  */
4783
70
      dst->symbol.value = src->u.syment.n_value;
4784
#else
4785
      dst->symbol.value = (src->u.syment.n_value
4786
               - dst->symbol.section->vma);
4787
#endif
4788
70
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
1
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
70
      break;
4793
4794
19
    case COFF_SYMBOL_COMMON:
4795
19
      dst->symbol.section = bfd_com_section_ptr;
4796
19
      dst->symbol.value = src->u.syment.n_value;
4797
19
      break;
4798
4799
10
    case COFF_SYMBOL_UNDEFINED:
4800
10
      dst->symbol.section = bfd_und_section_ptr;
4801
10
      dst->symbol.value = 0;
4802
10
      break;
4803
4804
0
    case COFF_SYMBOL_PE_SECTION:
4805
0
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4806
0
      dst->symbol.value = 0;
4807
0
      break;
4808
4809
0
    case COFF_SYMBOL_LOCAL:
4810
0
      dst->symbol.flags = BSF_LOCAL;
4811
0
#if defined COFF_WITH_PE
4812
      /* PE sets the symbol to a value relative to the
4813
         start of the section.  */
4814
0
      dst->symbol.value = src->u.syment.n_value;
4815
#else
4816
      dst->symbol.value = (src->u.syment.n_value
4817
               - dst->symbol.section->vma);
4818
#endif
4819
0
      if (ISFCN ((src->u.syment.n_type)))
4820
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4821
0
      break;
4822
99
    }
4823
4824
#ifdef RS6000COFF_C
4825
        /* A symbol with a csect entry should not go at the end.  */
4826
        if (src->u.syment.n_numaux > 0)
4827
    dst->symbol.flags |= BSF_NOT_AT_END;
4828
#endif
4829
4830
99
#ifdef COFF_WITH_PE
4831
99
        if (src->u.syment.n_sclass == C_NT_WEAK)
4832
6
    dst->symbol.flags |= BSF_WEAK;
4833
4834
99
        if (src->u.syment.n_sclass == C_SECTION
4835
99
      && src->u.syment.n_scnum > 0)
4836
0
    dst->symbol.flags = BSF_LOCAL;
4837
99
#endif
4838
99
        if (src->u.syment.n_sclass == C_WEAKEXT
4839
#ifdef RS6000COFF_C
4840
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4841
#endif
4842
99
      )
4843
5
    dst->symbol.flags |= BSF_WEAK;
4844
4845
99
        break;
4846
4847
25
      case C_STAT:  /* Static.  */
4848
#if defined ARM
4849
      case C_THUMBSTAT:    /* Thumb static.  */
4850
      case C_THUMBLABEL:   /* Thumb label.  */
4851
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4852
#endif
4853
#ifdef RS6000COFF_C
4854
      case C_DWARF:  /* A label in a dwarf section.  */
4855
      case C_INFO:   /* A label in a comment section.  */
4856
#endif
4857
29
      case C_LABEL:  /* Label.  */
4858
29
        if (src->u.syment.n_scnum == N_DEBUG)
4859
0
    dst->symbol.flags = BSF_DEBUGGING;
4860
29
        else
4861
29
    dst->symbol.flags = BSF_LOCAL;
4862
4863
        /* Base the value as an index from the base of the
4864
     section, if there is one.  */
4865
29
        if (dst->symbol.section)
4866
29
    {
4867
29
#if defined COFF_WITH_PE
4868
      /* PE sets the symbol to a value relative to the
4869
         start of the section.  */
4870
29
      dst->symbol.value = src->u.syment.n_value;
4871
#else
4872
      dst->symbol.value = (src->u.syment.n_value
4873
               - dst->symbol.section->vma);
4874
#endif
4875
29
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
29
        break;
4879
4880
25
      case C_FILE: /* File name.  */
4881
25
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
33
      case C_MOS:   /* Member of structure.  */
4884
35
      case C_EOS:   /* End of structure.  */
4885
62
      case C_REGPARM: /* Register parameter.  */
4886
81
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
104
      case C_TPDEF: /* Type definition.  */
4889
106
      case C_ARG:
4890
542
      case C_AUTO: /* Automatic variable.  */
4891
552
      case C_FIELD: /* Bit field.  */
4892
557
      case C_ENTAG: /* Enumeration tag.  */
4893
588
      case C_MOE:   /* Member of enumeration.  */
4894
604
      case C_MOU:   /* Member of union.  */
4895
624
      case C_UNTAG: /* Union tag.  */
4896
651
      case C_STRTAG: /* Structure tag.  */
4897
#ifdef RS6000COFF_C
4898
      case C_GSYM:
4899
      case C_LSYM:
4900
      case C_PSYM:
4901
      case C_RSYM:
4902
      case C_RPSYM:
4903
      case C_STSYM:
4904
      case C_TCSYM:
4905
      case C_BCOMM:
4906
      case C_ECOML:
4907
      case C_ECOMM:
4908
      case C_DECL:
4909
      case C_ENTRY:
4910
      case C_FUN:
4911
      case C_ESTAT:
4912
#endif
4913
651
        dst->symbol.flags |= BSF_DEBUGGING;
4914
651
        dst->symbol.value = (src->u.syment.n_value);
4915
651
        break;
4916
4917
#ifdef RS6000COFF_C
4918
      case C_BINCL: /* Beginning of include file.  */
4919
      case C_EINCL: /* Ending of include file.  */
4920
        /* The value is actually a pointer into the line numbers
4921
     of the file.  We locate the line number entry, and
4922
     set the section to the section which contains it, and
4923
     the value to the index in that section.  */
4924
        {
4925
    asection *sec;
4926
4927
    dst->symbol.flags = BSF_DEBUGGING;
4928
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4929
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4930
          && ((file_ptr) (sec->line_filepos
4931
              + sec->lineno_count * bfd_coff_linesz (abfd))
4932
        > (file_ptr) src->u.syment.n_value))
4933
        break;
4934
    if (sec == NULL)
4935
      dst->symbol.value = 0;
4936
    else
4937
      {
4938
        dst->symbol.section = sec;
4939
        dst->symbol.value = ((src->u.syment.n_value
4940
            - sec->line_filepos)
4941
           / bfd_coff_linesz (abfd));
4942
        src->fix_line = 1;
4943
      }
4944
        }
4945
        break;
4946
4947
      case C_BSTAT:
4948
        dst->symbol.flags = BSF_DEBUGGING;
4949
4950
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4951
    dst->symbol.value = 0;
4952
        else
4953
    {
4954
      /* The value is actually a symbol index.  Save a pointer
4955
         to the symbol instead of the index.  FIXME: This
4956
         should use a union.  */
4957
      src->u.syment.n_value
4958
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4959
      dst->symbol.value = src->u.syment.n_value;
4960
      src->fix_value = 1;
4961
    }
4962
        break;
4963
#endif
4964
4965
3
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
8
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
23
      case C_EFCN: /* Physical end of function.  */
4968
23
#if defined COFF_WITH_PE
4969
        /* PE sets the symbol to a value relative to the start
4970
     of the section.  */
4971
23
        dst->symbol.value = src->u.syment.n_value;
4972
23
        if (strcmp (dst->symbol.name, ".bf") != 0)
4973
23
    {
4974
      /* PE uses funny values for .ef and .lf; don't
4975
         relocate them.  */
4976
23
      dst->symbol.flags = BSF_DEBUGGING;
4977
23
    }
4978
0
        else
4979
0
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4980
#else
4981
        /* Base the value as an index from the base of the
4982
     section.  */
4983
        dst->symbol.flags = BSF_LOCAL;
4984
        dst->symbol.value = (src->u.syment.n_value
4985
           - dst->symbol.section->vma);
4986
#endif
4987
23
        break;
4988
4989
3
      case C_STATLAB: /* Static load time label.  */
4990
3
        dst->symbol.value = src->u.syment.n_value;
4991
3
        dst->symbol.flags = BSF_GLOBAL;
4992
3
        break;
4993
4994
2.80k
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
2.80k
        if (src->u.syment.n_type == 0
4998
2.80k
      && src->u.syment.n_value == 0
4999
2.80k
      && src->u.syment.n_scnum == 0)
5000
487
    break;
5001
#ifdef RS6000COFF_C
5002
        /* XCOFF specific: deleted entry.  */
5003
        if (src->u.syment.n_value == C_NULL_VALUE)
5004
    break;
5005
#endif
5006
        /* Fall through.  */
5007
2.32k
      case C_EXTDEF: /* External definition.  */
5008
2.32k
      case C_ULABEL: /* Undefined label.  */
5009
2.33k
      case C_USTATIC: /* Undefined static.  */
5010
#ifndef COFF_WITH_PE
5011
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5012
         class to represent a section symbol.  */
5013
      case C_LINE:  /* line # reformatted as symbol table entry.  */
5014
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5015
      case C_ALIAS: /* Duplicate tag.  */
5016
#endif
5017
        /* New storage classes for TI COFF.  */
5018
#ifdef TICOFF
5019
      case C_UEXT:  /* Tentative external definition.  */
5020
#endif
5021
2.33k
      case C_EXTLAB: /* External load time label.  */
5022
3.09k
      default:
5023
3.09k
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
3.09k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
3.09k
     abfd, src->u.syment.n_sclass,
5027
3.09k
     dst->symbol.section->name, dst->symbol.name);
5028
3.09k
        ret = false;
5029
        /* Fall through.  */
5030
3.10k
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5031
        /* PR 20722: These symbols can also be generated by
5032
     building DLLs with --gc-sections enabled.  */
5033
3.10k
        dst->symbol.flags = BSF_DEBUGGING;
5034
3.10k
        dst->symbol.value = (src->u.syment.n_value);
5035
3.10k
        break;
5036
4.39k
      }
5037
5038
4.39k
    dst->native = src;
5039
4.39k
    dst->symbol.udata.i = 0;
5040
4.39k
    dst->lineno = NULL;
5041
5042
4.39k
    this_index += (src->u.syment.n_numaux) + 1;
5043
4.39k
    dst++;
5044
4.39k
    number_of_symbols++;
5045
4.39k
  }
5046
32
    }
5047
5048
32
  obj_symbols (abfd) = cached_area;
5049
32
  obj_raw_syments (abfd) = native_symbols;
5050
5051
32
  abfd->symcount = number_of_symbols;
5052
32
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
32
  {
5055
32
    asection *p;
5056
5057
32
    p = abfd->sections;
5058
46
    while (p)
5059
43
      {
5060
43
  if (! coff_slurp_line_table (abfd, p))
5061
29
    return false;
5062
14
  p = p->next;
5063
14
      }
5064
32
  }
5065
5066
3
  return ret;
5067
32
}
pe-x86_64.c:coff_slurp_symbol_table
Line
Count
Source
4695
43
{
4696
43
  combined_entry_type *native_symbols;
4697
43
  coff_symbol_type *cached_area;
4698
43
  unsigned int *table_ptr;
4699
43
  unsigned int number_of_symbols = 0;
4700
43
  bool ret = true;
4701
43
  size_t amt;
4702
4703
43
  if (obj_symbols (abfd))
4704
1
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
42
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
16
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
26
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
26
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
26
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
26
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
26
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
26
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
26
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
26
  if (table_ptr == NULL)
4729
0
    return false;
4730
26
  else
4731
26
    {
4732
26
      coff_symbol_type *dst = cached_area;
4733
26
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
26
      unsigned int this_index = 0;
4735
4736
15.9k
      while (this_index < last_native_index)
4737
15.9k
  {
4738
15.9k
    combined_entry_type *src = native_symbols + this_index;
4739
15.9k
    table_ptr[this_index] = number_of_symbols;
4740
4741
15.9k
    dst->symbol.the_bfd = abfd;
4742
15.9k
    BFD_ASSERT (src->is_sym);
4743
15.9k
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4744
    /* We use the native name field to point to the cached field.  */
4745
15.9k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
15.9k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
15.9k
                 src->u.syment.n_scnum);
4748
15.9k
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
15.9k
    dst->symbol.value = 0;
4751
15.9k
    dst->done_lineno = false;
4752
4753
15.9k
    switch (src->u.syment.n_sclass)
4754
15.9k
      {
4755
228
      case C_EXT:
4756
233
      case C_WEAKEXT:
4757
#if defined ARM
4758
      case C_THUMBEXT:
4759
      case C_THUMBEXTFUNC:
4760
#endif
4761
#ifdef RS6000COFF_C
4762
      case C_HIDEXT:
4763
#ifndef AIX_WEAK_SUPPORT
4764
      case C_AIX_WEAKEXT:
4765
#endif
4766
#endif
4767
233
#ifdef C_SYSTEM
4768
272
      case C_SYSTEM: /* System Wide variable.  */
4769
272
#endif
4770
272
#ifdef COFF_WITH_PE
4771
      /* In PE, 0x68 (104) denotes a section symbol.  */
4772
272
      case C_SECTION:
4773
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4774
283
      case C_NT_WEAK:
4775
283
#endif
4776
283
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
283
    {
4778
163
    case COFF_SYMBOL_GLOBAL:
4779
163
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4780
163
#if defined COFF_WITH_PE
4781
      /* PE sets the symbol to a value relative to the
4782
         start of the section.  */
4783
163
      dst->symbol.value = src->u.syment.n_value;
4784
#else
4785
      dst->symbol.value = (src->u.syment.n_value
4786
               - dst->symbol.section->vma);
4787
#endif
4788
163
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
6
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
163
      break;
4793
4794
107
    case COFF_SYMBOL_COMMON:
4795
107
      dst->symbol.section = bfd_com_section_ptr;
4796
107
      dst->symbol.value = src->u.syment.n_value;
4797
107
      break;
4798
4799
13
    case COFF_SYMBOL_UNDEFINED:
4800
13
      dst->symbol.section = bfd_und_section_ptr;
4801
13
      dst->symbol.value = 0;
4802
13
      break;
4803
4804
0
    case COFF_SYMBOL_PE_SECTION:
4805
0
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4806
0
      dst->symbol.value = 0;
4807
0
      break;
4808
4809
0
    case COFF_SYMBOL_LOCAL:
4810
0
      dst->symbol.flags = BSF_LOCAL;
4811
0
#if defined COFF_WITH_PE
4812
      /* PE sets the symbol to a value relative to the
4813
         start of the section.  */
4814
0
      dst->symbol.value = src->u.syment.n_value;
4815
#else
4816
      dst->symbol.value = (src->u.syment.n_value
4817
               - dst->symbol.section->vma);
4818
#endif
4819
0
      if (ISFCN ((src->u.syment.n_type)))
4820
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4821
0
      break;
4822
283
    }
4823
4824
#ifdef RS6000COFF_C
4825
        /* A symbol with a csect entry should not go at the end.  */
4826
        if (src->u.syment.n_numaux > 0)
4827
    dst->symbol.flags |= BSF_NOT_AT_END;
4828
#endif
4829
4830
283
#ifdef COFF_WITH_PE
4831
283
        if (src->u.syment.n_sclass == C_NT_WEAK)
4832
11
    dst->symbol.flags |= BSF_WEAK;
4833
4834
283
        if (src->u.syment.n_sclass == C_SECTION
4835
283
      && src->u.syment.n_scnum > 0)
4836
0
    dst->symbol.flags = BSF_LOCAL;
4837
283
#endif
4838
283
        if (src->u.syment.n_sclass == C_WEAKEXT
4839
#ifdef RS6000COFF_C
4840
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4841
#endif
4842
283
      )
4843
5
    dst->symbol.flags |= BSF_WEAK;
4844
4845
283
        break;
4846
4847
261
      case C_STAT:  /* Static.  */
4848
#if defined ARM
4849
      case C_THUMBSTAT:    /* Thumb static.  */
4850
      case C_THUMBLABEL:   /* Thumb label.  */
4851
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4852
#endif
4853
#ifdef RS6000COFF_C
4854
      case C_DWARF:  /* A label in a dwarf section.  */
4855
      case C_INFO:   /* A label in a comment section.  */
4856
#endif
4857
283
      case C_LABEL:  /* Label.  */
4858
283
        if (src->u.syment.n_scnum == N_DEBUG)
4859
0
    dst->symbol.flags = BSF_DEBUGGING;
4860
283
        else
4861
283
    dst->symbol.flags = BSF_LOCAL;
4862
4863
        /* Base the value as an index from the base of the
4864
     section, if there is one.  */
4865
283
        if (dst->symbol.section)
4866
283
    {
4867
283
#if defined COFF_WITH_PE
4868
      /* PE sets the symbol to a value relative to the
4869
         start of the section.  */
4870
283
      dst->symbol.value = src->u.syment.n_value;
4871
#else
4872
      dst->symbol.value = (src->u.syment.n_value
4873
               - dst->symbol.section->vma);
4874
#endif
4875
283
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
283
        break;
4879
4880
35
      case C_FILE: /* File name.  */
4881
35
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
161
      case C_MOS:   /* Member of structure.  */
4884
170
      case C_EOS:   /* End of structure.  */
4885
194
      case C_REGPARM: /* Register parameter.  */
4886
217
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
239
      case C_TPDEF: /* Type definition.  */
4889
468
      case C_ARG:
4890
1.34k
      case C_AUTO: /* Automatic variable.  */
4891
1.35k
      case C_FIELD: /* Bit field.  */
4892
1.37k
      case C_ENTAG: /* Enumeration tag.  */
4893
1.42k
      case C_MOE:   /* Member of enumeration.  */
4894
1.46k
      case C_MOU:   /* Member of union.  */
4895
1.49k
      case C_UNTAG: /* Union tag.  */
4896
1.60k
      case C_STRTAG: /* Structure tag.  */
4897
#ifdef RS6000COFF_C
4898
      case C_GSYM:
4899
      case C_LSYM:
4900
      case C_PSYM:
4901
      case C_RSYM:
4902
      case C_RPSYM:
4903
      case C_STSYM:
4904
      case C_TCSYM:
4905
      case C_BCOMM:
4906
      case C_ECOML:
4907
      case C_ECOMM:
4908
      case C_DECL:
4909
      case C_ENTRY:
4910
      case C_FUN:
4911
      case C_ESTAT:
4912
#endif
4913
1.60k
        dst->symbol.flags |= BSF_DEBUGGING;
4914
1.60k
        dst->symbol.value = (src->u.syment.n_value);
4915
1.60k
        break;
4916
4917
#ifdef RS6000COFF_C
4918
      case C_BINCL: /* Beginning of include file.  */
4919
      case C_EINCL: /* Ending of include file.  */
4920
        /* The value is actually a pointer into the line numbers
4921
     of the file.  We locate the line number entry, and
4922
     set the section to the section which contains it, and
4923
     the value to the index in that section.  */
4924
        {
4925
    asection *sec;
4926
4927
    dst->symbol.flags = BSF_DEBUGGING;
4928
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4929
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4930
          && ((file_ptr) (sec->line_filepos
4931
              + sec->lineno_count * bfd_coff_linesz (abfd))
4932
        > (file_ptr) src->u.syment.n_value))
4933
        break;
4934
    if (sec == NULL)
4935
      dst->symbol.value = 0;
4936
    else
4937
      {
4938
        dst->symbol.section = sec;
4939
        dst->symbol.value = ((src->u.syment.n_value
4940
            - sec->line_filepos)
4941
           / bfd_coff_linesz (abfd));
4942
        src->fix_line = 1;
4943
      }
4944
        }
4945
        break;
4946
4947
      case C_BSTAT:
4948
        dst->symbol.flags = BSF_DEBUGGING;
4949
4950
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4951
    dst->symbol.value = 0;
4952
        else
4953
    {
4954
      /* The value is actually a symbol index.  Save a pointer
4955
         to the symbol instead of the index.  FIXME: This
4956
         should use a union.  */
4957
      src->u.syment.n_value
4958
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4959
      dst->symbol.value = src->u.syment.n_value;
4960
      src->fix_value = 1;
4961
    }
4962
        break;
4963
#endif
4964
4965
9
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
47
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
114
      case C_EFCN: /* Physical end of function.  */
4968
114
#if defined COFF_WITH_PE
4969
        /* PE sets the symbol to a value relative to the start
4970
     of the section.  */
4971
114
        dst->symbol.value = src->u.syment.n_value;
4972
114
        if (strcmp (dst->symbol.name, ".bf") != 0)
4973
114
    {
4974
      /* PE uses funny values for .ef and .lf; don't
4975
         relocate them.  */
4976
114
      dst->symbol.flags = BSF_DEBUGGING;
4977
114
    }
4978
0
        else
4979
0
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4980
#else
4981
        /* Base the value as an index from the base of the
4982
     section.  */
4983
        dst->symbol.flags = BSF_LOCAL;
4984
        dst->symbol.value = (src->u.syment.n_value
4985
           - dst->symbol.section->vma);
4986
#endif
4987
114
        break;
4988
4989
14
      case C_STATLAB: /* Static load time label.  */
4990
14
        dst->symbol.value = src->u.syment.n_value;
4991
14
        dst->symbol.flags = BSF_GLOBAL;
4992
14
        break;
4993
4994
11.8k
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
11.8k
        if (src->u.syment.n_type == 0
4998
11.8k
      && src->u.syment.n_value == 0
4999
11.8k
      && src->u.syment.n_scnum == 0)
5000
4.49k
    break;
5001
#ifdef RS6000COFF_C
5002
        /* XCOFF specific: deleted entry.  */
5003
        if (src->u.syment.n_value == C_NULL_VALUE)
5004
    break;
5005
#endif
5006
        /* Fall through.  */
5007
7.37k
      case C_EXTDEF: /* External definition.  */
5008
7.38k
      case C_ULABEL: /* Undefined label.  */
5009
7.39k
      case C_USTATIC: /* Undefined static.  */
5010
#ifndef COFF_WITH_PE
5011
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5012
         class to represent a section symbol.  */
5013
      case C_LINE:  /* line # reformatted as symbol table entry.  */
5014
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5015
      case C_ALIAS: /* Duplicate tag.  */
5016
#endif
5017
        /* New storage classes for TI COFF.  */
5018
#ifdef TICOFF
5019
      case C_UEXT:  /* Tentative external definition.  */
5020
#endif
5021
7.40k
      case C_EXTLAB: /* External load time label.  */
5022
9.13k
      default:
5023
9.13k
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
9.13k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
9.13k
     abfd, src->u.syment.n_sclass,
5027
9.13k
     dst->symbol.section->name, dst->symbol.name);
5028
9.13k
        ret = false;
5029
        /* Fall through.  */
5030
9.15k
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5031
        /* PR 20722: These symbols can also be generated by
5032
     building DLLs with --gc-sections enabled.  */
5033
9.15k
        dst->symbol.flags = BSF_DEBUGGING;
5034
9.15k
        dst->symbol.value = (src->u.syment.n_value);
5035
9.15k
        break;
5036
15.9k
      }
5037
5038
15.9k
    dst->native = src;
5039
15.9k
    dst->symbol.udata.i = 0;
5040
15.9k
    dst->lineno = NULL;
5041
5042
15.9k
    this_index += (src->u.syment.n_numaux) + 1;
5043
15.9k
    dst++;
5044
15.9k
    number_of_symbols++;
5045
15.9k
  }
5046
26
    }
5047
5048
26
  obj_symbols (abfd) = cached_area;
5049
26
  obj_raw_syments (abfd) = native_symbols;
5050
5051
26
  abfd->symcount = number_of_symbols;
5052
26
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
26
  {
5055
26
    asection *p;
5056
5057
26
    p = abfd->sections;
5058
79
    while (p)
5059
66
      {
5060
66
  if (! coff_slurp_line_table (abfd, p))
5061
13
    return false;
5062
53
  p = p->next;
5063
53
      }
5064
26
  }
5065
5066
13
  return ret;
5067
26
}
pei-x86_64.c:coff_slurp_symbol_table
Line
Count
Source
4695
61
{
4696
61
  combined_entry_type *native_symbols;
4697
61
  coff_symbol_type *cached_area;
4698
61
  unsigned int *table_ptr;
4699
61
  unsigned int number_of_symbols = 0;
4700
61
  bool ret = true;
4701
61
  size_t amt;
4702
4703
61
  if (obj_symbols (abfd))
4704
8
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
53
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
6
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
47
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
47
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
47
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
47
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
47
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
47
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
47
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
47
  if (table_ptr == NULL)
4729
0
    return false;
4730
47
  else
4731
47
    {
4732
47
      coff_symbol_type *dst = cached_area;
4733
47
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
47
      unsigned int this_index = 0;
4735
4736
7.45k
      while (this_index < last_native_index)
4737
7.41k
  {
4738
7.41k
    combined_entry_type *src = native_symbols + this_index;
4739
7.41k
    table_ptr[this_index] = number_of_symbols;
4740
4741
7.41k
    dst->symbol.the_bfd = abfd;
4742
7.41k
    BFD_ASSERT (src->is_sym);
4743
7.41k
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4744
    /* We use the native name field to point to the cached field.  */
4745
7.41k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
7.41k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
7.41k
                 src->u.syment.n_scnum);
4748
7.41k
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
7.41k
    dst->symbol.value = 0;
4751
7.41k
    dst->done_lineno = false;
4752
4753
7.41k
    switch (src->u.syment.n_sclass)
4754
7.41k
      {
4755
1.25k
      case C_EXT:
4756
1.25k
      case C_WEAKEXT:
4757
#if defined ARM
4758
      case C_THUMBEXT:
4759
      case C_THUMBEXTFUNC:
4760
#endif
4761
#ifdef RS6000COFF_C
4762
      case C_HIDEXT:
4763
#ifndef AIX_WEAK_SUPPORT
4764
      case C_AIX_WEAKEXT:
4765
#endif
4766
#endif
4767
1.25k
#ifdef C_SYSTEM
4768
1.26k
      case C_SYSTEM: /* System Wide variable.  */
4769
1.26k
#endif
4770
1.26k
#ifdef COFF_WITH_PE
4771
      /* In PE, 0x68 (104) denotes a section symbol.  */
4772
1.27k
      case C_SECTION:
4773
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4774
1.27k
      case C_NT_WEAK:
4775
1.27k
#endif
4776
1.27k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
1.27k
    {
4778
1.03k
    case COFF_SYMBOL_GLOBAL:
4779
1.03k
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4780
1.03k
#if defined COFF_WITH_PE
4781
      /* PE sets the symbol to a value relative to the
4782
         start of the section.  */
4783
1.03k
      dst->symbol.value = src->u.syment.n_value;
4784
#else
4785
      dst->symbol.value = (src->u.syment.n_value
4786
               - dst->symbol.section->vma);
4787
#endif
4788
1.03k
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
147
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
1.03k
      break;
4793
4794
16
    case COFF_SYMBOL_COMMON:
4795
16
      dst->symbol.section = bfd_com_section_ptr;
4796
16
      dst->symbol.value = src->u.syment.n_value;
4797
16
      break;
4798
4799
225
    case COFF_SYMBOL_UNDEFINED:
4800
225
      dst->symbol.section = bfd_und_section_ptr;
4801
225
      dst->symbol.value = 0;
4802
225
      break;
4803
4804
0
    case COFF_SYMBOL_PE_SECTION:
4805
0
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4806
0
      dst->symbol.value = 0;
4807
0
      break;
4808
4809
0
    case COFF_SYMBOL_LOCAL:
4810
0
      dst->symbol.flags = BSF_LOCAL;
4811
0
#if defined COFF_WITH_PE
4812
      /* PE sets the symbol to a value relative to the
4813
         start of the section.  */
4814
0
      dst->symbol.value = src->u.syment.n_value;
4815
#else
4816
      dst->symbol.value = (src->u.syment.n_value
4817
               - dst->symbol.section->vma);
4818
#endif
4819
0
      if (ISFCN ((src->u.syment.n_type)))
4820
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4821
0
      break;
4822
1.27k
    }
4823
4824
#ifdef RS6000COFF_C
4825
        /* A symbol with a csect entry should not go at the end.  */
4826
        if (src->u.syment.n_numaux > 0)
4827
    dst->symbol.flags |= BSF_NOT_AT_END;
4828
#endif
4829
4830
1.27k
#ifdef COFF_WITH_PE
4831
1.27k
        if (src->u.syment.n_sclass == C_NT_WEAK)
4832
8
    dst->symbol.flags |= BSF_WEAK;
4833
4834
1.27k
        if (src->u.syment.n_sclass == C_SECTION
4835
1.27k
      && src->u.syment.n_scnum > 0)
4836
0
    dst->symbol.flags = BSF_LOCAL;
4837
1.27k
#endif
4838
1.27k
        if (src->u.syment.n_sclass == C_WEAKEXT
4839
#ifdef RS6000COFF_C
4840
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4841
#endif
4842
1.27k
      )
4843
1
    dst->symbol.flags |= BSF_WEAK;
4844
4845
1.27k
        break;
4846
4847
1.33k
      case C_STAT:  /* Static.  */
4848
#if defined ARM
4849
      case C_THUMBSTAT:    /* Thumb static.  */
4850
      case C_THUMBLABEL:   /* Thumb label.  */
4851
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4852
#endif
4853
#ifdef RS6000COFF_C
4854
      case C_DWARF:  /* A label in a dwarf section.  */
4855
      case C_INFO:   /* A label in a comment section.  */
4856
#endif
4857
1.35k
      case C_LABEL:  /* Label.  */
4858
1.35k
        if (src->u.syment.n_scnum == N_DEBUG)
4859
0
    dst->symbol.flags = BSF_DEBUGGING;
4860
1.35k
        else
4861
1.35k
    dst->symbol.flags = BSF_LOCAL;
4862
4863
        /* Base the value as an index from the base of the
4864
     section, if there is one.  */
4865
1.35k
        if (dst->symbol.section)
4866
1.35k
    {
4867
1.35k
#if defined COFF_WITH_PE
4868
      /* PE sets the symbol to a value relative to the
4869
         start of the section.  */
4870
1.35k
      dst->symbol.value = src->u.syment.n_value;
4871
#else
4872
      dst->symbol.value = (src->u.syment.n_value
4873
               - dst->symbol.section->vma);
4874
#endif
4875
1.35k
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
1.35k
        break;
4879
4880
130
      case C_FILE: /* File name.  */
4881
130
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
154
      case C_MOS:   /* Member of structure.  */
4884
159
      case C_EOS:   /* End of structure.  */
4885
161
      case C_REGPARM: /* Register parameter.  */
4886
165
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
199
      case C_TPDEF: /* Type definition.  */
4889
216
      case C_ARG:
4890
446
      case C_AUTO: /* Automatic variable.  */
4891
455
      case C_FIELD: /* Bit field.  */
4892
490
      case C_ENTAG: /* Enumeration tag.  */
4893
503
      case C_MOE:   /* Member of enumeration.  */
4894
512
      case C_MOU:   /* Member of union.  */
4895
527
      case C_UNTAG: /* Union tag.  */
4896
546
      case C_STRTAG: /* Structure tag.  */
4897
#ifdef RS6000COFF_C
4898
      case C_GSYM:
4899
      case C_LSYM:
4900
      case C_PSYM:
4901
      case C_RSYM:
4902
      case C_RPSYM:
4903
      case C_STSYM:
4904
      case C_TCSYM:
4905
      case C_BCOMM:
4906
      case C_ECOML:
4907
      case C_ECOMM:
4908
      case C_DECL:
4909
      case C_ENTRY:
4910
      case C_FUN:
4911
      case C_ESTAT:
4912
#endif
4913
546
        dst->symbol.flags |= BSF_DEBUGGING;
4914
546
        dst->symbol.value = (src->u.syment.n_value);
4915
546
        break;
4916
4917
#ifdef RS6000COFF_C
4918
      case C_BINCL: /* Beginning of include file.  */
4919
      case C_EINCL: /* Ending of include file.  */
4920
        /* The value is actually a pointer into the line numbers
4921
     of the file.  We locate the line number entry, and
4922
     set the section to the section which contains it, and
4923
     the value to the index in that section.  */
4924
        {
4925
    asection *sec;
4926
4927
    dst->symbol.flags = BSF_DEBUGGING;
4928
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4929
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4930
          && ((file_ptr) (sec->line_filepos
4931
              + sec->lineno_count * bfd_coff_linesz (abfd))
4932
        > (file_ptr) src->u.syment.n_value))
4933
        break;
4934
    if (sec == NULL)
4935
      dst->symbol.value = 0;
4936
    else
4937
      {
4938
        dst->symbol.section = sec;
4939
        dst->symbol.value = ((src->u.syment.n_value
4940
            - sec->line_filepos)
4941
           / bfd_coff_linesz (abfd));
4942
        src->fix_line = 1;
4943
      }
4944
        }
4945
        break;
4946
4947
      case C_BSTAT:
4948
        dst->symbol.flags = BSF_DEBUGGING;
4949
4950
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4951
    dst->symbol.value = 0;
4952
        else
4953
    {
4954
      /* The value is actually a symbol index.  Save a pointer
4955
         to the symbol instead of the index.  FIXME: This
4956
         should use a union.  */
4957
      src->u.syment.n_value
4958
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4959
      dst->symbol.value = src->u.syment.n_value;
4960
      src->fix_value = 1;
4961
    }
4962
        break;
4963
#endif
4964
4965
16
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
25
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
54
      case C_EFCN: /* Physical end of function.  */
4968
54
#if defined COFF_WITH_PE
4969
        /* PE sets the symbol to a value relative to the start
4970
     of the section.  */
4971
54
        dst->symbol.value = src->u.syment.n_value;
4972
54
        if (strcmp (dst->symbol.name, ".bf") != 0)
4973
54
    {
4974
      /* PE uses funny values for .ef and .lf; don't
4975
         relocate them.  */
4976
54
      dst->symbol.flags = BSF_DEBUGGING;
4977
54
    }
4978
0
        else
4979
0
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4980
#else
4981
        /* Base the value as an index from the base of the
4982
     section.  */
4983
        dst->symbol.flags = BSF_LOCAL;
4984
        dst->symbol.value = (src->u.syment.n_value
4985
           - dst->symbol.section->vma);
4986
#endif
4987
54
        break;
4988
4989
1
      case C_STATLAB: /* Static load time label.  */
4990
1
        dst->symbol.value = src->u.syment.n_value;
4991
1
        dst->symbol.flags = BSF_GLOBAL;
4992
1
        break;
4993
4994
3.57k
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
3.57k
        if (src->u.syment.n_type == 0
4998
3.57k
      && src->u.syment.n_value == 0
4999
3.57k
      && src->u.syment.n_scnum == 0)
5000
1.43k
    break;
5001
#ifdef RS6000COFF_C
5002
        /* XCOFF specific: deleted entry.  */
5003
        if (src->u.syment.n_value == C_NULL_VALUE)
5004
    break;
5005
#endif
5006
        /* Fall through.  */
5007
2.13k
      case C_EXTDEF: /* External definition.  */
5008
2.14k
      case C_ULABEL: /* Undefined label.  */
5009
2.14k
      case C_USTATIC: /* Undefined static.  */
5010
#ifndef COFF_WITH_PE
5011
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5012
         class to represent a section symbol.  */
5013
      case C_LINE:  /* line # reformatted as symbol table entry.  */
5014
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5015
      case C_ALIAS: /* Duplicate tag.  */
5016
#endif
5017
        /* New storage classes for TI COFF.  */
5018
#ifdef TICOFF
5019
      case C_UEXT:  /* Tentative external definition.  */
5020
#endif
5021
2.15k
      case C_EXTLAB: /* External load time label.  */
5022
2.73k
      default:
5023
2.73k
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
2.73k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
2.73k
     abfd, src->u.syment.n_sclass,
5027
2.73k
     dst->symbol.section->name, dst->symbol.name);
5028
2.73k
        ret = false;
5029
        /* Fall through.  */
5030
2.74k
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5031
        /* PR 20722: These symbols can also be generated by
5032
     building DLLs with --gc-sections enabled.  */
5033
2.74k
        dst->symbol.flags = BSF_DEBUGGING;
5034
2.74k
        dst->symbol.value = (src->u.syment.n_value);
5035
2.74k
        break;
5036
7.41k
      }
5037
5038
7.41k
    dst->native = src;
5039
7.41k
    dst->symbol.udata.i = 0;
5040
7.41k
    dst->lineno = NULL;
5041
5042
7.41k
    this_index += (src->u.syment.n_numaux) + 1;
5043
7.41k
    dst++;
5044
7.41k
    number_of_symbols++;
5045
7.41k
  }
5046
47
    }
5047
5048
47
  obj_symbols (abfd) = cached_area;
5049
47
  obj_raw_syments (abfd) = native_symbols;
5050
5051
47
  abfd->symcount = number_of_symbols;
5052
47
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
47
  {
5055
47
    asection *p;
5056
5057
47
    p = abfd->sections;
5058
387
    while (p)
5059
371
      {
5060
371
  if (! coff_slurp_line_table (abfd, p))
5061
31
    return false;
5062
340
  p = p->next;
5063
340
      }
5064
47
  }
5065
5066
16
  return ret;
5067
47
}
coff-x86_64.c:coff_slurp_symbol_table
Line
Count
Source
4695
61
{
4696
61
  combined_entry_type *native_symbols;
4697
61
  coff_symbol_type *cached_area;
4698
61
  unsigned int *table_ptr;
4699
61
  unsigned int number_of_symbols = 0;
4700
61
  bool ret = true;
4701
61
  size_t amt;
4702
4703
61
  if (obj_symbols (abfd))
4704
2
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
59
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
17
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
42
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
42
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
42
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
42
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
42
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
42
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
42
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
42
  if (table_ptr == NULL)
4729
0
    return false;
4730
42
  else
4731
42
    {
4732
42
      coff_symbol_type *dst = cached_area;
4733
42
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
42
      unsigned int this_index = 0;
4735
4736
19.9k
      while (this_index < last_native_index)
4737
19.9k
  {
4738
19.9k
    combined_entry_type *src = native_symbols + this_index;
4739
19.9k
    table_ptr[this_index] = number_of_symbols;
4740
4741
19.9k
    dst->symbol.the_bfd = abfd;
4742
19.9k
    BFD_ASSERT (src->is_sym);
4743
19.9k
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4744
    /* We use the native name field to point to the cached field.  */
4745
19.9k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
19.9k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
19.9k
                 src->u.syment.n_scnum);
4748
19.9k
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
19.9k
    dst->symbol.value = 0;
4751
19.9k
    dst->done_lineno = false;
4752
4753
19.9k
    switch (src->u.syment.n_sclass)
4754
19.9k
      {
4755
280
      case C_EXT:
4756
287
      case C_WEAKEXT:
4757
#if defined ARM
4758
      case C_THUMBEXT:
4759
      case C_THUMBEXTFUNC:
4760
#endif
4761
#ifdef RS6000COFF_C
4762
      case C_HIDEXT:
4763
#ifndef AIX_WEAK_SUPPORT
4764
      case C_AIX_WEAKEXT:
4765
#endif
4766
#endif
4767
287
#ifdef C_SYSTEM
4768
301
      case C_SYSTEM: /* System Wide variable.  */
4769
301
#endif
4770
#ifdef COFF_WITH_PE
4771
      /* In PE, 0x68 (104) denotes a section symbol.  */
4772
      case C_SECTION:
4773
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4774
      case C_NT_WEAK:
4775
#endif
4776
301
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
301
    {
4778
208
    case COFF_SYMBOL_GLOBAL:
4779
208
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4780
#if defined COFF_WITH_PE
4781
      /* PE sets the symbol to a value relative to the
4782
         start of the section.  */
4783
      dst->symbol.value = src->u.syment.n_value;
4784
#else
4785
208
      dst->symbol.value = (src->u.syment.n_value
4786
208
               - dst->symbol.section->vma);
4787
208
#endif
4788
208
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
10
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
208
      break;
4793
4794
83
    case COFF_SYMBOL_COMMON:
4795
83
      dst->symbol.section = bfd_com_section_ptr;
4796
83
      dst->symbol.value = src->u.syment.n_value;
4797
83
      break;
4798
4799
10
    case COFF_SYMBOL_UNDEFINED:
4800
10
      dst->symbol.section = bfd_und_section_ptr;
4801
10
      dst->symbol.value = 0;
4802
10
      break;
4803
4804
0
    case COFF_SYMBOL_PE_SECTION:
4805
0
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4806
0
      dst->symbol.value = 0;
4807
0
      break;
4808
4809
0
    case COFF_SYMBOL_LOCAL:
4810
0
      dst->symbol.flags = BSF_LOCAL;
4811
#if defined COFF_WITH_PE
4812
      /* PE sets the symbol to a value relative to the
4813
         start of the section.  */
4814
      dst->symbol.value = src->u.syment.n_value;
4815
#else
4816
0
      dst->symbol.value = (src->u.syment.n_value
4817
0
               - dst->symbol.section->vma);
4818
0
#endif
4819
0
      if (ISFCN ((src->u.syment.n_type)))
4820
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4821
0
      break;
4822
301
    }
4823
4824
#ifdef RS6000COFF_C
4825
        /* A symbol with a csect entry should not go at the end.  */
4826
        if (src->u.syment.n_numaux > 0)
4827
    dst->symbol.flags |= BSF_NOT_AT_END;
4828
#endif
4829
4830
#ifdef COFF_WITH_PE
4831
        if (src->u.syment.n_sclass == C_NT_WEAK)
4832
    dst->symbol.flags |= BSF_WEAK;
4833
4834
        if (src->u.syment.n_sclass == C_SECTION
4835
      && src->u.syment.n_scnum > 0)
4836
    dst->symbol.flags = BSF_LOCAL;
4837
#endif
4838
301
        if (src->u.syment.n_sclass == C_WEAKEXT
4839
#ifdef RS6000COFF_C
4840
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4841
#endif
4842
301
      )
4843
7
    dst->symbol.flags |= BSF_WEAK;
4844
4845
301
        break;
4846
4847
155
      case C_STAT:  /* Static.  */
4848
#if defined ARM
4849
      case C_THUMBSTAT:    /* Thumb static.  */
4850
      case C_THUMBLABEL:   /* Thumb label.  */
4851
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4852
#endif
4853
#ifdef RS6000COFF_C
4854
      case C_DWARF:  /* A label in a dwarf section.  */
4855
      case C_INFO:   /* A label in a comment section.  */
4856
#endif
4857
180
      case C_LABEL:  /* Label.  */
4858
180
        if (src->u.syment.n_scnum == N_DEBUG)
4859
0
    dst->symbol.flags = BSF_DEBUGGING;
4860
180
        else
4861
180
    dst->symbol.flags = BSF_LOCAL;
4862
4863
        /* Base the value as an index from the base of the
4864
     section, if there is one.  */
4865
180
        if (dst->symbol.section)
4866
180
    {
4867
#if defined COFF_WITH_PE
4868
      /* PE sets the symbol to a value relative to the
4869
         start of the section.  */
4870
      dst->symbol.value = src->u.syment.n_value;
4871
#else
4872
180
      dst->symbol.value = (src->u.syment.n_value
4873
180
               - dst->symbol.section->vma);
4874
180
#endif
4875
180
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
180
        break;
4879
4880
49
      case C_FILE: /* File name.  */
4881
49
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
131
      case C_MOS:   /* Member of structure.  */
4884
144
      case C_EOS:   /* End of structure.  */
4885
170
      case C_REGPARM: /* Register parameter.  */
4886
310
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
338
      case C_TPDEF: /* Type definition.  */
4889
838
      case C_ARG:
4890
2.33k
      case C_AUTO: /* Automatic variable.  */
4891
2.37k
      case C_FIELD: /* Bit field.  */
4892
2.39k
      case C_ENTAG: /* Enumeration tag.  */
4893
2.49k
      case C_MOE:   /* Member of enumeration.  */
4894
2.56k
      case C_MOU:   /* Member of union.  */
4895
2.59k
      case C_UNTAG: /* Union tag.  */
4896
2.74k
      case C_STRTAG: /* Structure tag.  */
4897
#ifdef RS6000COFF_C
4898
      case C_GSYM:
4899
      case C_LSYM:
4900
      case C_PSYM:
4901
      case C_RSYM:
4902
      case C_RPSYM:
4903
      case C_STSYM:
4904
      case C_TCSYM:
4905
      case C_BCOMM:
4906
      case C_ECOML:
4907
      case C_ECOMM:
4908
      case C_DECL:
4909
      case C_ENTRY:
4910
      case C_FUN:
4911
      case C_ESTAT:
4912
#endif
4913
2.74k
        dst->symbol.flags |= BSF_DEBUGGING;
4914
2.74k
        dst->symbol.value = (src->u.syment.n_value);
4915
2.74k
        break;
4916
4917
#ifdef RS6000COFF_C
4918
      case C_BINCL: /* Beginning of include file.  */
4919
      case C_EINCL: /* Ending of include file.  */
4920
        /* The value is actually a pointer into the line numbers
4921
     of the file.  We locate the line number entry, and
4922
     set the section to the section which contains it, and
4923
     the value to the index in that section.  */
4924
        {
4925
    asection *sec;
4926
4927
    dst->symbol.flags = BSF_DEBUGGING;
4928
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4929
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4930
          && ((file_ptr) (sec->line_filepos
4931
              + sec->lineno_count * bfd_coff_linesz (abfd))
4932
        > (file_ptr) src->u.syment.n_value))
4933
        break;
4934
    if (sec == NULL)
4935
      dst->symbol.value = 0;
4936
    else
4937
      {
4938
        dst->symbol.section = sec;
4939
        dst->symbol.value = ((src->u.syment.n_value
4940
            - sec->line_filepos)
4941
           / bfd_coff_linesz (abfd));
4942
        src->fix_line = 1;
4943
      }
4944
        }
4945
        break;
4946
4947
      case C_BSTAT:
4948
        dst->symbol.flags = BSF_DEBUGGING;
4949
4950
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4951
    dst->symbol.value = 0;
4952
        else
4953
    {
4954
      /* The value is actually a symbol index.  Save a pointer
4955
         to the symbol instead of the index.  FIXME: This
4956
         should use a union.  */
4957
      src->u.syment.n_value
4958
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4959
      dst->symbol.value = src->u.syment.n_value;
4960
      src->fix_value = 1;
4961
    }
4962
        break;
4963
#endif
4964
4965
16
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
41
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
114
      case C_EFCN: /* Physical end of function.  */
4968
#if defined COFF_WITH_PE
4969
        /* PE sets the symbol to a value relative to the start
4970
     of the section.  */
4971
        dst->symbol.value = src->u.syment.n_value;
4972
        if (strcmp (dst->symbol.name, ".bf") != 0)
4973
    {
4974
      /* PE uses funny values for .ef and .lf; don't
4975
         relocate them.  */
4976
      dst->symbol.flags = BSF_DEBUGGING;
4977
    }
4978
        else
4979
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4980
#else
4981
        /* Base the value as an index from the base of the
4982
     section.  */
4983
114
        dst->symbol.flags = BSF_LOCAL;
4984
114
        dst->symbol.value = (src->u.syment.n_value
4985
114
           - dst->symbol.section->vma);
4986
114
#endif
4987
114
        break;
4988
4989
127
      case C_STATLAB: /* Static load time label.  */
4990
127
        dst->symbol.value = src->u.syment.n_value;
4991
127
        dst->symbol.flags = BSF_GLOBAL;
4992
127
        break;
4993
4994
13.9k
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
13.9k
        if (src->u.syment.n_type == 0
4998
13.9k
      && src->u.syment.n_value == 0
4999
13.9k
      && src->u.syment.n_scnum == 0)
5000
4.41k
    break;
5001
#ifdef RS6000COFF_C
5002
        /* XCOFF specific: deleted entry.  */
5003
        if (src->u.syment.n_value == C_NULL_VALUE)
5004
    break;
5005
#endif
5006
        /* Fall through.  */
5007
9.62k
      case C_EXTDEF: /* External definition.  */
5008
9.63k
      case C_ULABEL: /* Undefined label.  */
5009
9.64k
      case C_USTATIC: /* Undefined static.  */
5010
9.64k
#ifndef COFF_WITH_PE
5011
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5012
         class to represent a section symbol.  */
5013
9.65k
      case C_LINE: /* line # reformatted as symbol table entry.  */
5014
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5015
9.66k
      case C_ALIAS: /* Duplicate tag.  */
5016
9.66k
#endif
5017
        /* New storage classes for TI COFF.  */
5018
#ifdef TICOFF
5019
      case C_UEXT:  /* Tentative external definition.  */
5020
#endif
5021
9.66k
      case C_EXTLAB: /* External load time label.  */
5022
12.0k
      default:
5023
12.0k
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
12.0k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
12.0k
     abfd, src->u.syment.n_sclass,
5027
12.0k
     dst->symbol.section->name, dst->symbol.name);
5028
12.0k
        ret = false;
5029
        /* Fall through.  */
5030
12.0k
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5031
        /* PR 20722: These symbols can also be generated by
5032
     building DLLs with --gc-sections enabled.  */
5033
12.0k
        dst->symbol.flags = BSF_DEBUGGING;
5034
12.0k
        dst->symbol.value = (src->u.syment.n_value);
5035
12.0k
        break;
5036
19.9k
      }
5037
5038
19.9k
    dst->native = src;
5039
19.9k
    dst->symbol.udata.i = 0;
5040
19.9k
    dst->lineno = NULL;
5041
5042
19.9k
    this_index += (src->u.syment.n_numaux) + 1;
5043
19.9k
    dst++;
5044
19.9k
    number_of_symbols++;
5045
19.9k
  }
5046
42
    }
5047
5048
42
  obj_symbols (abfd) = cached_area;
5049
42
  obj_raw_syments (abfd) = native_symbols;
5050
5051
42
  abfd->symcount = number_of_symbols;
5052
42
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
42
  {
5055
42
    asection *p;
5056
5057
42
    p = abfd->sections;
5058
1.63k
    while (p)
5059
1.63k
      {
5060
1.63k
  if (! coff_slurp_line_table (abfd, p))
5061
38
    return false;
5062
1.59k
  p = p->next;
5063
1.59k
      }
5064
42
  }
5065
5066
4
  return ret;
5067
42
}
coff64-rs6000.c:coff_slurp_symbol_table
Line
Count
Source
4695
117
{
4696
117
  combined_entry_type *native_symbols;
4697
117
  coff_symbol_type *cached_area;
4698
117
  unsigned int *table_ptr;
4699
117
  unsigned int number_of_symbols = 0;
4700
117
  bool ret = true;
4701
117
  size_t amt;
4702
4703
117
  if (obj_symbols (abfd))
4704
1
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
116
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
33
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
83
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
83
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
83
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
83
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
83
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
83
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
83
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
83
  if (table_ptr == NULL)
4729
0
    return false;
4730
83
  else
4731
83
    {
4732
83
      coff_symbol_type *dst = cached_area;
4733
83
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
83
      unsigned int this_index = 0;
4735
4736
45.5k
      while (this_index < last_native_index)
4737
45.5k
  {
4738
45.5k
    combined_entry_type *src = native_symbols + this_index;
4739
45.5k
    table_ptr[this_index] = number_of_symbols;
4740
4741
45.5k
    dst->symbol.the_bfd = abfd;
4742
45.5k
    BFD_ASSERT (src->is_sym);
4743
45.5k
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4744
    /* We use the native name field to point to the cached field.  */
4745
45.5k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
45.5k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
45.5k
                 src->u.syment.n_scnum);
4748
45.5k
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
45.5k
    dst->symbol.value = 0;
4751
45.5k
    dst->done_lineno = false;
4752
4753
45.5k
    switch (src->u.syment.n_sclass)
4754
45.5k
      {
4755
1.61k
      case C_EXT:
4756
1.64k
      case C_WEAKEXT:
4757
#if defined ARM
4758
      case C_THUMBEXT:
4759
      case C_THUMBEXTFUNC:
4760
#endif
4761
1.64k
#ifdef RS6000COFF_C
4762
1.66k
      case C_HIDEXT:
4763
1.66k
#ifndef AIX_WEAK_SUPPORT
4764
1.72k
      case C_AIX_WEAKEXT:
4765
1.72k
#endif
4766
1.72k
#endif
4767
1.72k
#ifdef C_SYSTEM
4768
1.74k
      case C_SYSTEM: /* System Wide variable.  */
4769
1.74k
#endif
4770
#ifdef COFF_WITH_PE
4771
      /* In PE, 0x68 (104) denotes a section symbol.  */
4772
      case C_SECTION:
4773
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4774
      case C_NT_WEAK:
4775
#endif
4776
1.74k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
1.74k
    {
4778
1.33k
    case COFF_SYMBOL_GLOBAL:
4779
1.33k
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4780
#if defined COFF_WITH_PE
4781
      /* PE sets the symbol to a value relative to the
4782
         start of the section.  */
4783
      dst->symbol.value = src->u.syment.n_value;
4784
#else
4785
1.33k
      dst->symbol.value = (src->u.syment.n_value
4786
1.33k
               - dst->symbol.section->vma);
4787
1.33k
#endif
4788
1.33k
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
39
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
1.33k
      break;
4793
4794
291
    case COFF_SYMBOL_COMMON:
4795
291
      dst->symbol.section = bfd_com_section_ptr;
4796
291
      dst->symbol.value = src->u.syment.n_value;
4797
291
      break;
4798
4799
111
    case COFF_SYMBOL_UNDEFINED:
4800
111
      dst->symbol.section = bfd_und_section_ptr;
4801
111
      dst->symbol.value = 0;
4802
111
      break;
4803
4804
0
    case COFF_SYMBOL_PE_SECTION:
4805
0
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4806
0
      dst->symbol.value = 0;
4807
0
      break;
4808
4809
11
    case COFF_SYMBOL_LOCAL:
4810
11
      dst->symbol.flags = BSF_LOCAL;
4811
#if defined COFF_WITH_PE
4812
      /* PE sets the symbol to a value relative to the
4813
         start of the section.  */
4814
      dst->symbol.value = src->u.syment.n_value;
4815
#else
4816
11
      dst->symbol.value = (src->u.syment.n_value
4817
11
               - dst->symbol.section->vma);
4818
11
#endif
4819
11
      if (ISFCN ((src->u.syment.n_type)))
4820
4
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4821
11
      break;
4822
1.74k
    }
4823
4824
1.74k
#ifdef RS6000COFF_C
4825
        /* A symbol with a csect entry should not go at the end.  */
4826
1.74k
        if (src->u.syment.n_numaux > 0)
4827
1.21k
    dst->symbol.flags |= BSF_NOT_AT_END;
4828
1.74k
#endif
4829
4830
#ifdef COFF_WITH_PE
4831
        if (src->u.syment.n_sclass == C_NT_WEAK)
4832
    dst->symbol.flags |= BSF_WEAK;
4833
4834
        if (src->u.syment.n_sclass == C_SECTION
4835
      && src->u.syment.n_scnum > 0)
4836
    dst->symbol.flags = BSF_LOCAL;
4837
#endif
4838
1.74k
        if (src->u.syment.n_sclass == C_WEAKEXT
4839
1.74k
#ifdef RS6000COFF_C
4840
1.74k
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4841
1.74k
#endif
4842
1.74k
      )
4843
85
    dst->symbol.flags |= BSF_WEAK;
4844
4845
1.74k
        break;
4846
4847
590
      case C_STAT:  /* Static.  */
4848
#if defined ARM
4849
      case C_THUMBSTAT:    /* Thumb static.  */
4850
      case C_THUMBLABEL:   /* Thumb label.  */
4851
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4852
#endif
4853
590
#ifdef RS6000COFF_C
4854
667
      case C_DWARF:  /* A label in a dwarf section.  */
4855
706
      case C_INFO:  /* A label in a comment section.  */
4856
706
#endif
4857
848
      case C_LABEL:  /* Label.  */
4858
848
        if (src->u.syment.n_scnum == N_DEBUG)
4859
0
    dst->symbol.flags = BSF_DEBUGGING;
4860
848
        else
4861
848
    dst->symbol.flags = BSF_LOCAL;
4862
4863
        /* Base the value as an index from the base of the
4864
     section, if there is one.  */
4865
848
        if (dst->symbol.section)
4866
848
    {
4867
#if defined COFF_WITH_PE
4868
      /* PE sets the symbol to a value relative to the
4869
         start of the section.  */
4870
      dst->symbol.value = src->u.syment.n_value;
4871
#else
4872
848
      dst->symbol.value = (src->u.syment.n_value
4873
848
               - dst->symbol.section->vma);
4874
848
#endif
4875
848
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
848
        break;
4879
4880
82
      case C_FILE: /* File name.  */
4881
82
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
501
      case C_MOS:   /* Member of structure.  */
4884
533
      case C_EOS:   /* End of structure.  */
4885
621
      case C_REGPARM: /* Register parameter.  */
4886
719
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
815
      case C_TPDEF: /* Type definition.  */
4889
899
      case C_ARG:
4890
3.55k
      case C_AUTO: /* Automatic variable.  */
4891
3.63k
      case C_FIELD: /* Bit field.  */
4892
3.73k
      case C_ENTAG: /* Enumeration tag.  */
4893
4.20k
      case C_MOE:   /* Member of enumeration.  */
4894
4.52k
      case C_MOU:   /* Member of union.  */
4895
4.61k
      case C_UNTAG: /* Union tag.  */
4896
4.88k
      case C_STRTAG: /* Structure tag.  */
4897
4.88k
#ifdef RS6000COFF_C
4898
4.95k
      case C_GSYM:
4899
4.97k
      case C_LSYM:
4900
4.99k
      case C_PSYM:
4901
5.02k
      case C_RSYM:
4902
5.05k
      case C_RPSYM:
4903
5.21k
      case C_STSYM:
4904
5.23k
      case C_TCSYM:
4905
5.25k
      case C_BCOMM:
4906
5.28k
      case C_ECOML:
4907
5.30k
      case C_ECOMM:
4908
5.32k
      case C_DECL:
4909
5.33k
      case C_ENTRY:
4910
5.36k
      case C_FUN:
4911
5.41k
      case C_ESTAT:
4912
5.41k
#endif
4913
5.41k
        dst->symbol.flags |= BSF_DEBUGGING;
4914
5.41k
        dst->symbol.value = (src->u.syment.n_value);
4915
5.41k
        break;
4916
4917
0
#ifdef RS6000COFF_C
4918
48
      case C_BINCL: /* Beginning of include file.  */
4919
70
      case C_EINCL: /* Ending of include file.  */
4920
        /* The value is actually a pointer into the line numbers
4921
     of the file.  We locate the line number entry, and
4922
     set the section to the section which contains it, and
4923
     the value to the index in that section.  */
4924
70
        {
4925
70
    asection *sec;
4926
4927
70
    dst->symbol.flags = BSF_DEBUGGING;
4928
5.11k
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4929
5.06k
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4930
5.06k
          && ((file_ptr) (sec->line_filepos
4931
2.10k
              + sec->lineno_count * bfd_coff_linesz (abfd))
4932
2.10k
        > (file_ptr) src->u.syment.n_value))
4933
19
        break;
4934
70
    if (sec == NULL)
4935
51
      dst->symbol.value = 0;
4936
19
    else
4937
19
      {
4938
19
        dst->symbol.section = sec;
4939
19
        dst->symbol.value = ((src->u.syment.n_value
4940
19
            - sec->line_filepos)
4941
19
           / bfd_coff_linesz (abfd));
4942
19
        src->fix_line = 1;
4943
19
      }
4944
70
        }
4945
70
        break;
4946
4947
31
      case C_BSTAT:
4948
31
        dst->symbol.flags = BSF_DEBUGGING;
4949
4950
31
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4951
30
    dst->symbol.value = 0;
4952
1
        else
4953
1
    {
4954
      /* The value is actually a symbol index.  Save a pointer
4955
         to the symbol instead of the index.  FIXME: This
4956
         should use a union.  */
4957
1
      src->u.syment.n_value
4958
1
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4959
1
      dst->symbol.value = src->u.syment.n_value;
4960
1
      src->fix_value = 1;
4961
1
    }
4962
31
        break;
4963
0
#endif
4964
4965
52
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
96
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
317
      case C_EFCN: /* Physical end of function.  */
4968
#if defined COFF_WITH_PE
4969
        /* PE sets the symbol to a value relative to the start
4970
     of the section.  */
4971
        dst->symbol.value = src->u.syment.n_value;
4972
        if (strcmp (dst->symbol.name, ".bf") != 0)
4973
    {
4974
      /* PE uses funny values for .ef and .lf; don't
4975
         relocate them.  */
4976
      dst->symbol.flags = BSF_DEBUGGING;
4977
    }
4978
        else
4979
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4980
#else
4981
        /* Base the value as an index from the base of the
4982
     section.  */
4983
317
        dst->symbol.flags = BSF_LOCAL;
4984
317
        dst->symbol.value = (src->u.syment.n_value
4985
317
           - dst->symbol.section->vma);
4986
317
#endif
4987
317
        break;
4988
4989
61
      case C_STATLAB: /* Static load time label.  */
4990
61
        dst->symbol.value = src->u.syment.n_value;
4991
61
        dst->symbol.flags = BSF_GLOBAL;
4992
61
        break;
4993
4994
31.6k
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
31.6k
        if (src->u.syment.n_type == 0
4998
31.6k
      && src->u.syment.n_value == 0
4999
31.6k
      && src->u.syment.n_scnum == 0)
5000
11.5k
    break;
5001
20.0k
#ifdef RS6000COFF_C
5002
        /* XCOFF specific: deleted entry.  */
5003
20.0k
        if (src->u.syment.n_value == C_NULL_VALUE)
5004
0
    break;
5005
20.0k
#endif
5006
        /* Fall through.  */
5007
20.1k
      case C_EXTDEF: /* External definition.  */
5008
20.2k
      case C_ULABEL: /* Undefined label.  */
5009
20.2k
      case C_USTATIC: /* Undefined static.  */
5010
20.2k
#ifndef COFF_WITH_PE
5011
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5012
         class to represent a section symbol.  */
5013
20.3k
      case C_LINE: /* line # reformatted as symbol table entry.  */
5014
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5015
20.3k
      case C_ALIAS: /* Duplicate tag.  */
5016
20.3k
#endif
5017
        /* New storage classes for TI COFF.  */
5018
#ifdef TICOFF
5019
      case C_UEXT:  /* Tentative external definition.  */
5020
#endif
5021
20.4k
      case C_EXTLAB: /* External load time label.  */
5022
25.4k
      default:
5023
25.4k
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
25.4k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
25.4k
     abfd, src->u.syment.n_sclass,
5027
25.4k
     dst->symbol.section->name, dst->symbol.name);
5028
25.4k
        ret = false;
5029
        /* Fall through.  */
5030
25.4k
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5031
        /* PR 20722: These symbols can also be generated by
5032
     building DLLs with --gc-sections enabled.  */
5033
25.4k
        dst->symbol.flags = BSF_DEBUGGING;
5034
25.4k
        dst->symbol.value = (src->u.syment.n_value);
5035
25.4k
        break;
5036
45.5k
      }
5037
5038
45.5k
    dst->native = src;
5039
45.5k
    dst->symbol.udata.i = 0;
5040
45.5k
    dst->lineno = NULL;
5041
5042
45.5k
    this_index += (src->u.syment.n_numaux) + 1;
5043
45.5k
    dst++;
5044
45.5k
    number_of_symbols++;
5045
45.5k
  }
5046
83
    }
5047
5048
83
  obj_symbols (abfd) = cached_area;
5049
83
  obj_raw_syments (abfd) = native_symbols;
5050
5051
83
  abfd->symcount = number_of_symbols;
5052
83
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
83
  {
5055
83
    asection *p;
5056
5057
83
    p = abfd->sections;
5058
514
    while (p)
5059
513
      {
5060
513
  if (! coff_slurp_line_table (abfd, p))
5061
82
    return false;
5062
431
  p = p->next;
5063
431
      }
5064
83
  }
5065
5066
1
  return ret;
5067
83
}
pe-aarch64.c:coff_slurp_symbol_table
Line
Count
Source
4695
40
{
4696
40
  combined_entry_type *native_symbols;
4697
40
  coff_symbol_type *cached_area;
4698
40
  unsigned int *table_ptr;
4699
40
  unsigned int number_of_symbols = 0;
4700
40
  bool ret = true;
4701
40
  size_t amt;
4702
4703
40
  if (obj_symbols (abfd))
4704
1
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
39
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
24
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
15
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
15
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
15
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
15
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
15
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
15
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
15
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
15
  if (table_ptr == NULL)
4729
0
    return false;
4730
15
  else
4731
15
    {
4732
15
      coff_symbol_type *dst = cached_area;
4733
15
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
15
      unsigned int this_index = 0;
4735
4736
1.22k
      while (this_index < last_native_index)
4737
1.21k
  {
4738
1.21k
    combined_entry_type *src = native_symbols + this_index;
4739
1.21k
    table_ptr[this_index] = number_of_symbols;
4740
4741
1.21k
    dst->symbol.the_bfd = abfd;
4742
1.21k
    BFD_ASSERT (src->is_sym);
4743
1.21k
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4744
    /* We use the native name field to point to the cached field.  */
4745
1.21k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
1.21k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
1.21k
                 src->u.syment.n_scnum);
4748
1.21k
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
1.21k
    dst->symbol.value = 0;
4751
1.21k
    dst->done_lineno = false;
4752
4753
1.21k
    switch (src->u.syment.n_sclass)
4754
1.21k
      {
4755
49
      case C_EXT:
4756
49
      case C_WEAKEXT:
4757
#if defined ARM
4758
      case C_THUMBEXT:
4759
      case C_THUMBEXTFUNC:
4760
#endif
4761
#ifdef RS6000COFF_C
4762
      case C_HIDEXT:
4763
#ifndef AIX_WEAK_SUPPORT
4764
      case C_AIX_WEAKEXT:
4765
#endif
4766
#endif
4767
49
#ifdef C_SYSTEM
4768
49
      case C_SYSTEM: /* System Wide variable.  */
4769
49
#endif
4770
49
#ifdef COFF_WITH_PE
4771
      /* In PE, 0x68 (104) denotes a section symbol.  */
4772
49
      case C_SECTION:
4773
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4774
52
      case C_NT_WEAK:
4775
52
#endif
4776
52
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
52
    {
4778
46
    case COFF_SYMBOL_GLOBAL:
4779
46
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4780
46
#if defined COFF_WITH_PE
4781
      /* PE sets the symbol to a value relative to the
4782
         start of the section.  */
4783
46
      dst->symbol.value = src->u.syment.n_value;
4784
#else
4785
      dst->symbol.value = (src->u.syment.n_value
4786
               - dst->symbol.section->vma);
4787
#endif
4788
46
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
2
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
46
      break;
4793
4794
6
    case COFF_SYMBOL_COMMON:
4795
6
      dst->symbol.section = bfd_com_section_ptr;
4796
6
      dst->symbol.value = src->u.syment.n_value;
4797
6
      break;
4798
4799
0
    case COFF_SYMBOL_UNDEFINED:
4800
0
      dst->symbol.section = bfd_und_section_ptr;
4801
0
      dst->symbol.value = 0;
4802
0
      break;
4803
4804
0
    case COFF_SYMBOL_PE_SECTION:
4805
0
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4806
0
      dst->symbol.value = 0;
4807
0
      break;
4808
4809
0
    case COFF_SYMBOL_LOCAL:
4810
0
      dst->symbol.flags = BSF_LOCAL;
4811
0
#if defined COFF_WITH_PE
4812
      /* PE sets the symbol to a value relative to the
4813
         start of the section.  */
4814
0
      dst->symbol.value = src->u.syment.n_value;
4815
#else
4816
      dst->symbol.value = (src->u.syment.n_value
4817
               - dst->symbol.section->vma);
4818
#endif
4819
0
      if (ISFCN ((src->u.syment.n_type)))
4820
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4821
0
      break;
4822
52
    }
4823
4824
#ifdef RS6000COFF_C
4825
        /* A symbol with a csect entry should not go at the end.  */
4826
        if (src->u.syment.n_numaux > 0)
4827
    dst->symbol.flags |= BSF_NOT_AT_END;
4828
#endif
4829
4830
52
#ifdef COFF_WITH_PE
4831
52
        if (src->u.syment.n_sclass == C_NT_WEAK)
4832
3
    dst->symbol.flags |= BSF_WEAK;
4833
4834
52
        if (src->u.syment.n_sclass == C_SECTION
4835
52
      && src->u.syment.n_scnum > 0)
4836
0
    dst->symbol.flags = BSF_LOCAL;
4837
52
#endif
4838
52
        if (src->u.syment.n_sclass == C_WEAKEXT
4839
#ifdef RS6000COFF_C
4840
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4841
#endif
4842
52
      )
4843
0
    dst->symbol.flags |= BSF_WEAK;
4844
4845
52
        break;
4846
4847
21
      case C_STAT:  /* Static.  */
4848
#if defined ARM
4849
      case C_THUMBSTAT:    /* Thumb static.  */
4850
      case C_THUMBLABEL:   /* Thumb label.  */
4851
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4852
#endif
4853
#ifdef RS6000COFF_C
4854
      case C_DWARF:  /* A label in a dwarf section.  */
4855
      case C_INFO:   /* A label in a comment section.  */
4856
#endif
4857
26
      case C_LABEL:  /* Label.  */
4858
26
        if (src->u.syment.n_scnum == N_DEBUG)
4859
0
    dst->symbol.flags = BSF_DEBUGGING;
4860
26
        else
4861
26
    dst->symbol.flags = BSF_LOCAL;
4862
4863
        /* Base the value as an index from the base of the
4864
     section, if there is one.  */
4865
26
        if (dst->symbol.section)
4866
26
    {
4867
26
#if defined COFF_WITH_PE
4868
      /* PE sets the symbol to a value relative to the
4869
         start of the section.  */
4870
26
      dst->symbol.value = src->u.syment.n_value;
4871
#else
4872
      dst->symbol.value = (src->u.syment.n_value
4873
               - dst->symbol.section->vma);
4874
#endif
4875
26
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
26
        break;
4879
4880
12
      case C_FILE: /* File name.  */
4881
12
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
33
      case C_MOS:   /* Member of structure.  */
4884
40
      case C_EOS:   /* End of structure.  */
4885
50
      case C_REGPARM: /* Register parameter.  */
4886
51
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
51
      case C_TPDEF: /* Type definition.  */
4889
52
      case C_ARG:
4890
77
      case C_AUTO: /* Automatic variable.  */
4891
80
      case C_FIELD: /* Bit field.  */
4892
81
      case C_ENTAG: /* Enumeration tag.  */
4893
85
      case C_MOE:   /* Member of enumeration.  */
4894
85
      case C_MOU:   /* Member of union.  */
4895
86
      case C_UNTAG: /* Union tag.  */
4896
109
      case C_STRTAG: /* Structure tag.  */
4897
#ifdef RS6000COFF_C
4898
      case C_GSYM:
4899
      case C_LSYM:
4900
      case C_PSYM:
4901
      case C_RSYM:
4902
      case C_RPSYM:
4903
      case C_STSYM:
4904
      case C_TCSYM:
4905
      case C_BCOMM:
4906
      case C_ECOML:
4907
      case C_ECOMM:
4908
      case C_DECL:
4909
      case C_ENTRY:
4910
      case C_FUN:
4911
      case C_ESTAT:
4912
#endif
4913
109
        dst->symbol.flags |= BSF_DEBUGGING;
4914
109
        dst->symbol.value = (src->u.syment.n_value);
4915
109
        break;
4916
4917
#ifdef RS6000COFF_C
4918
      case C_BINCL: /* Beginning of include file.  */
4919
      case C_EINCL: /* Ending of include file.  */
4920
        /* The value is actually a pointer into the line numbers
4921
     of the file.  We locate the line number entry, and
4922
     set the section to the section which contains it, and
4923
     the value to the index in that section.  */
4924
        {
4925
    asection *sec;
4926
4927
    dst->symbol.flags = BSF_DEBUGGING;
4928
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4929
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4930
          && ((file_ptr) (sec->line_filepos
4931
              + sec->lineno_count * bfd_coff_linesz (abfd))
4932
        > (file_ptr) src->u.syment.n_value))
4933
        break;
4934
    if (sec == NULL)
4935
      dst->symbol.value = 0;
4936
    else
4937
      {
4938
        dst->symbol.section = sec;
4939
        dst->symbol.value = ((src->u.syment.n_value
4940
            - sec->line_filepos)
4941
           / bfd_coff_linesz (abfd));
4942
        src->fix_line = 1;
4943
      }
4944
        }
4945
        break;
4946
4947
      case C_BSTAT:
4948
        dst->symbol.flags = BSF_DEBUGGING;
4949
4950
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4951
    dst->symbol.value = 0;
4952
        else
4953
    {
4954
      /* The value is actually a symbol index.  Save a pointer
4955
         to the symbol instead of the index.  FIXME: This
4956
         should use a union.  */
4957
      src->u.syment.n_value
4958
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4959
      dst->symbol.value = src->u.syment.n_value;
4960
      src->fix_value = 1;
4961
    }
4962
        break;
4963
#endif
4964
4965
21
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
37
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
42
      case C_EFCN: /* Physical end of function.  */
4968
42
#if defined COFF_WITH_PE
4969
        /* PE sets the symbol to a value relative to the start
4970
     of the section.  */
4971
42
        dst->symbol.value = src->u.syment.n_value;
4972
42
        if (strcmp (dst->symbol.name, ".bf") != 0)
4973
42
    {
4974
      /* PE uses funny values for .ef and .lf; don't
4975
         relocate them.  */
4976
42
      dst->symbol.flags = BSF_DEBUGGING;
4977
42
    }
4978
0
        else
4979
0
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4980
#else
4981
        /* Base the value as an index from the base of the
4982
     section.  */
4983
        dst->symbol.flags = BSF_LOCAL;
4984
        dst->symbol.value = (src->u.syment.n_value
4985
           - dst->symbol.section->vma);
4986
#endif
4987
42
        break;
4988
4989
4
      case C_STATLAB: /* Static load time label.  */
4990
4
        dst->symbol.value = src->u.syment.n_value;
4991
4
        dst->symbol.flags = BSF_GLOBAL;
4992
4
        break;
4993
4994
747
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
747
        if (src->u.syment.n_type == 0
4998
747
      && src->u.syment.n_value == 0
4999
747
      && src->u.syment.n_scnum == 0)
5000
464
    break;
5001
#ifdef RS6000COFF_C
5002
        /* XCOFF specific: deleted entry.  */
5003
        if (src->u.syment.n_value == C_NULL_VALUE)
5004
    break;
5005
#endif
5006
        /* Fall through.  */
5007
291
      case C_EXTDEF: /* External definition.  */
5008
292
      case C_ULABEL: /* Undefined label.  */
5009
294
      case C_USTATIC: /* Undefined static.  */
5010
#ifndef COFF_WITH_PE
5011
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5012
         class to represent a section symbol.  */
5013
      case C_LINE:  /* line # reformatted as symbol table entry.  */
5014
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5015
      case C_ALIAS: /* Duplicate tag.  */
5016
#endif
5017
        /* New storage classes for TI COFF.  */
5018
#ifdef TICOFF
5019
      case C_UEXT:  /* Tentative external definition.  */
5020
#endif
5021
294
      case C_EXTLAB: /* External load time label.  */
5022
511
      default:
5023
511
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
511
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
511
     abfd, src->u.syment.n_sclass,
5027
511
     dst->symbol.section->name, dst->symbol.name);
5028
511
        ret = false;
5029
        /* Fall through.  */
5030
514
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5031
        /* PR 20722: These symbols can also be generated by
5032
     building DLLs with --gc-sections enabled.  */
5033
514
        dst->symbol.flags = BSF_DEBUGGING;
5034
514
        dst->symbol.value = (src->u.syment.n_value);
5035
514
        break;
5036
1.21k
      }
5037
5038
1.21k
    dst->native = src;
5039
1.21k
    dst->symbol.udata.i = 0;
5040
1.21k
    dst->lineno = NULL;
5041
5042
1.21k
    this_index += (src->u.syment.n_numaux) + 1;
5043
1.21k
    dst++;
5044
1.21k
    number_of_symbols++;
5045
1.21k
  }
5046
15
    }
5047
5048
15
  obj_symbols (abfd) = cached_area;
5049
15
  obj_raw_syments (abfd) = native_symbols;
5050
5051
15
  abfd->symcount = number_of_symbols;
5052
15
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
15
  {
5055
15
    asection *p;
5056
5057
15
    p = abfd->sections;
5058
34
    while (p)
5059
33
      {
5060
33
  if (! coff_slurp_line_table (abfd, p))
5061
14
    return false;
5062
19
  p = p->next;
5063
19
      }
5064
15
  }
5065
5066
1
  return ret;
5067
15
}
pei-aarch64.c:coff_slurp_symbol_table
Line
Count
Source
4695
29
{
4696
29
  combined_entry_type *native_symbols;
4697
29
  coff_symbol_type *cached_area;
4698
29
  unsigned int *table_ptr;
4699
29
  unsigned int number_of_symbols = 0;
4700
29
  bool ret = true;
4701
29
  size_t amt;
4702
4703
29
  if (obj_symbols (abfd))
4704
2
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
27
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
10
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
17
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
17
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
17
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
17
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
17
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
17
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
17
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
17
  if (table_ptr == NULL)
4729
0
    return false;
4730
17
  else
4731
17
    {
4732
17
      coff_symbol_type *dst = cached_area;
4733
17
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
17
      unsigned int this_index = 0;
4735
4736
14.6k
      while (this_index < last_native_index)
4737
14.6k
  {
4738
14.6k
    combined_entry_type *src = native_symbols + this_index;
4739
14.6k
    table_ptr[this_index] = number_of_symbols;
4740
4741
14.6k
    dst->symbol.the_bfd = abfd;
4742
14.6k
    BFD_ASSERT (src->is_sym);
4743
14.6k
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4744
    /* We use the native name field to point to the cached field.  */
4745
14.6k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
14.6k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
14.6k
                 src->u.syment.n_scnum);
4748
14.6k
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
14.6k
    dst->symbol.value = 0;
4751
14.6k
    dst->done_lineno = false;
4752
4753
14.6k
    switch (src->u.syment.n_sclass)
4754
14.6k
      {
4755
209
      case C_EXT:
4756
209
      case C_WEAKEXT:
4757
#if defined ARM
4758
      case C_THUMBEXT:
4759
      case C_THUMBEXTFUNC:
4760
#endif
4761
#ifdef RS6000COFF_C
4762
      case C_HIDEXT:
4763
#ifndef AIX_WEAK_SUPPORT
4764
      case C_AIX_WEAKEXT:
4765
#endif
4766
#endif
4767
209
#ifdef C_SYSTEM
4768
213
      case C_SYSTEM: /* System Wide variable.  */
4769
213
#endif
4770
213
#ifdef COFF_WITH_PE
4771
      /* In PE, 0x68 (104) denotes a section symbol.  */
4772
214
      case C_SECTION:
4773
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4774
215
      case C_NT_WEAK:
4775
215
#endif
4776
215
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
215
    {
4778
196
    case COFF_SYMBOL_GLOBAL:
4779
196
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4780
196
#if defined COFF_WITH_PE
4781
      /* PE sets the symbol to a value relative to the
4782
         start of the section.  */
4783
196
      dst->symbol.value = src->u.syment.n_value;
4784
#else
4785
      dst->symbol.value = (src->u.syment.n_value
4786
               - dst->symbol.section->vma);
4787
#endif
4788
196
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
196
      break;
4793
4794
11
    case COFF_SYMBOL_COMMON:
4795
11
      dst->symbol.section = bfd_com_section_ptr;
4796
11
      dst->symbol.value = src->u.syment.n_value;
4797
11
      break;
4798
4799
8
    case COFF_SYMBOL_UNDEFINED:
4800
8
      dst->symbol.section = bfd_und_section_ptr;
4801
8
      dst->symbol.value = 0;
4802
8
      break;
4803
4804
0
    case COFF_SYMBOL_PE_SECTION:
4805
0
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4806
0
      dst->symbol.value = 0;
4807
0
      break;
4808
4809
0
    case COFF_SYMBOL_LOCAL:
4810
0
      dst->symbol.flags = BSF_LOCAL;
4811
0
#if defined COFF_WITH_PE
4812
      /* PE sets the symbol to a value relative to the
4813
         start of the section.  */
4814
0
      dst->symbol.value = src->u.syment.n_value;
4815
#else
4816
      dst->symbol.value = (src->u.syment.n_value
4817
               - dst->symbol.section->vma);
4818
#endif
4819
0
      if (ISFCN ((src->u.syment.n_type)))
4820
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4821
0
      break;
4822
215
    }
4823
4824
#ifdef RS6000COFF_C
4825
        /* A symbol with a csect entry should not go at the end.  */
4826
        if (src->u.syment.n_numaux > 0)
4827
    dst->symbol.flags |= BSF_NOT_AT_END;
4828
#endif
4829
4830
215
#ifdef COFF_WITH_PE
4831
215
        if (src->u.syment.n_sclass == C_NT_WEAK)
4832
1
    dst->symbol.flags |= BSF_WEAK;
4833
4834
215
        if (src->u.syment.n_sclass == C_SECTION
4835
215
      && src->u.syment.n_scnum > 0)
4836
0
    dst->symbol.flags = BSF_LOCAL;
4837
215
#endif
4838
215
        if (src->u.syment.n_sclass == C_WEAKEXT
4839
#ifdef RS6000COFF_C
4840
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4841
#endif
4842
215
      )
4843
0
    dst->symbol.flags |= BSF_WEAK;
4844
4845
215
        break;
4846
4847
16
      case C_STAT:  /* Static.  */
4848
#if defined ARM
4849
      case C_THUMBSTAT:    /* Thumb static.  */
4850
      case C_THUMBLABEL:   /* Thumb label.  */
4851
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4852
#endif
4853
#ifdef RS6000COFF_C
4854
      case C_DWARF:  /* A label in a dwarf section.  */
4855
      case C_INFO:   /* A label in a comment section.  */
4856
#endif
4857
27
      case C_LABEL:  /* Label.  */
4858
27
        if (src->u.syment.n_scnum == N_DEBUG)
4859
0
    dst->symbol.flags = BSF_DEBUGGING;
4860
27
        else
4861
27
    dst->symbol.flags = BSF_LOCAL;
4862
4863
        /* Base the value as an index from the base of the
4864
     section, if there is one.  */
4865
27
        if (dst->symbol.section)
4866
27
    {
4867
27
#if defined COFF_WITH_PE
4868
      /* PE sets the symbol to a value relative to the
4869
         start of the section.  */
4870
27
      dst->symbol.value = src->u.syment.n_value;
4871
#else
4872
      dst->symbol.value = (src->u.syment.n_value
4873
               - dst->symbol.section->vma);
4874
#endif
4875
27
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
27
        break;
4879
4880
6
      case C_FILE: /* File name.  */
4881
6
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
9
      case C_MOS:   /* Member of structure.  */
4884
14
      case C_EOS:   /* End of structure.  */
4885
14
      case C_REGPARM: /* Register parameter.  */
4886
17
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
34
      case C_TPDEF: /* Type definition.  */
4889
57
      case C_ARG:
4890
274
      case C_AUTO: /* Automatic variable.  */
4891
277
      case C_FIELD: /* Bit field.  */
4892
305
      case C_ENTAG: /* Enumeration tag.  */
4893
318
      case C_MOE:   /* Member of enumeration.  */
4894
321
      case C_MOU:   /* Member of union.  */
4895
337
      case C_UNTAG: /* Union tag.  */
4896
407
      case C_STRTAG: /* Structure tag.  */
4897
#ifdef RS6000COFF_C
4898
      case C_GSYM:
4899
      case C_LSYM:
4900
      case C_PSYM:
4901
      case C_RSYM:
4902
      case C_RPSYM:
4903
      case C_STSYM:
4904
      case C_TCSYM:
4905
      case C_BCOMM:
4906
      case C_ECOML:
4907
      case C_ECOMM:
4908
      case C_DECL:
4909
      case C_ENTRY:
4910
      case C_FUN:
4911
      case C_ESTAT:
4912
#endif
4913
407
        dst->symbol.flags |= BSF_DEBUGGING;
4914
407
        dst->symbol.value = (src->u.syment.n_value);
4915
407
        break;
4916
4917
#ifdef RS6000COFF_C
4918
      case C_BINCL: /* Beginning of include file.  */
4919
      case C_EINCL: /* Ending of include file.  */
4920
        /* The value is actually a pointer into the line numbers
4921
     of the file.  We locate the line number entry, and
4922
     set the section to the section which contains it, and
4923
     the value to the index in that section.  */
4924
        {
4925
    asection *sec;
4926
4927
    dst->symbol.flags = BSF_DEBUGGING;
4928
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4929
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4930
          && ((file_ptr) (sec->line_filepos
4931
              + sec->lineno_count * bfd_coff_linesz (abfd))
4932
        > (file_ptr) src->u.syment.n_value))
4933
        break;
4934
    if (sec == NULL)
4935
      dst->symbol.value = 0;
4936
    else
4937
      {
4938
        dst->symbol.section = sec;
4939
        dst->symbol.value = ((src->u.syment.n_value
4940
            - sec->line_filepos)
4941
           / bfd_coff_linesz (abfd));
4942
        src->fix_line = 1;
4943
      }
4944
        }
4945
        break;
4946
4947
      case C_BSTAT:
4948
        dst->symbol.flags = BSF_DEBUGGING;
4949
4950
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4951
    dst->symbol.value = 0;
4952
        else
4953
    {
4954
      /* The value is actually a symbol index.  Save a pointer
4955
         to the symbol instead of the index.  FIXME: This
4956
         should use a union.  */
4957
      src->u.syment.n_value
4958
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4959
      dst->symbol.value = src->u.syment.n_value;
4960
      src->fix_value = 1;
4961
    }
4962
        break;
4963
#endif
4964
4965
1
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
9
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
17
      case C_EFCN: /* Physical end of function.  */
4968
17
#if defined COFF_WITH_PE
4969
        /* PE sets the symbol to a value relative to the start
4970
     of the section.  */
4971
17
        dst->symbol.value = src->u.syment.n_value;
4972
17
        if (strcmp (dst->symbol.name, ".bf") != 0)
4973
17
    {
4974
      /* PE uses funny values for .ef and .lf; don't
4975
         relocate them.  */
4976
17
      dst->symbol.flags = BSF_DEBUGGING;
4977
17
    }
4978
0
        else
4979
0
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4980
#else
4981
        /* Base the value as an index from the base of the
4982
     section.  */
4983
        dst->symbol.flags = BSF_LOCAL;
4984
        dst->symbol.value = (src->u.syment.n_value
4985
           - dst->symbol.section->vma);
4986
#endif
4987
17
        break;
4988
4989
4
      case C_STATLAB: /* Static load time label.  */
4990
4
        dst->symbol.value = src->u.syment.n_value;
4991
4
        dst->symbol.flags = BSF_GLOBAL;
4992
4
        break;
4993
4994
13.5k
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
13.5k
        if (src->u.syment.n_type == 0
4998
13.5k
      && src->u.syment.n_value == 0
4999
13.5k
      && src->u.syment.n_scnum == 0)
5000
11.8k
    break;
5001
#ifdef RS6000COFF_C
5002
        /* XCOFF specific: deleted entry.  */
5003
        if (src->u.syment.n_value == C_NULL_VALUE)
5004
    break;
5005
#endif
5006
        /* Fall through.  */
5007
1.66k
      case C_EXTDEF: /* External definition.  */
5008
1.66k
      case C_ULABEL: /* Undefined label.  */
5009
1.66k
      case C_USTATIC: /* Undefined static.  */
5010
#ifndef COFF_WITH_PE
5011
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5012
         class to represent a section symbol.  */
5013
      case C_LINE:  /* line # reformatted as symbol table entry.  */
5014
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5015
      case C_ALIAS: /* Duplicate tag.  */
5016
#endif
5017
        /* New storage classes for TI COFF.  */
5018
#ifdef TICOFF
5019
      case C_UEXT:  /* Tentative external definition.  */
5020
#endif
5021
1.66k
      case C_EXTLAB: /* External load time label.  */
5022
2.06k
      default:
5023
2.06k
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
2.06k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
2.06k
     abfd, src->u.syment.n_sclass,
5027
2.06k
     dst->symbol.section->name, dst->symbol.name);
5028
2.06k
        ret = false;
5029
        /* Fall through.  */
5030
2.06k
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5031
        /* PR 20722: These symbols can also be generated by
5032
     building DLLs with --gc-sections enabled.  */
5033
2.06k
        dst->symbol.flags = BSF_DEBUGGING;
5034
2.06k
        dst->symbol.value = (src->u.syment.n_value);
5035
2.06k
        break;
5036
14.6k
      }
5037
5038
14.6k
    dst->native = src;
5039
14.6k
    dst->symbol.udata.i = 0;
5040
14.6k
    dst->lineno = NULL;
5041
5042
14.6k
    this_index += (src->u.syment.n_numaux) + 1;
5043
14.6k
    dst++;
5044
14.6k
    number_of_symbols++;
5045
14.6k
  }
5046
17
    }
5047
5048
17
  obj_symbols (abfd) = cached_area;
5049
17
  obj_raw_syments (abfd) = native_symbols;
5050
5051
17
  abfd->symcount = number_of_symbols;
5052
17
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
17
  {
5055
17
    asection *p;
5056
5057
17
    p = abfd->sections;
5058
1.02k
    while (p)
5059
1.02k
      {
5060
1.02k
  if (! coff_slurp_line_table (abfd, p))
5061
13
    return false;
5062
1.00k
  p = p->next;
5063
1.00k
      }
5064
17
  }
5065
5066
4
  return ret;
5067
17
}
pei-ia64.c:coff_slurp_symbol_table
Line
Count
Source
4695
63
{
4696
63
  combined_entry_type *native_symbols;
4697
63
  coff_symbol_type *cached_area;
4698
63
  unsigned int *table_ptr;
4699
63
  unsigned int number_of_symbols = 0;
4700
63
  bool ret = true;
4701
63
  size_t amt;
4702
4703
63
  if (obj_symbols (abfd))
4704
0
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
63
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
36
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
27
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
27
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
27
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
27
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
27
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
27
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
27
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
27
  if (table_ptr == NULL)
4729
0
    return false;
4730
27
  else
4731
27
    {
4732
27
      coff_symbol_type *dst = cached_area;
4733
27
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
27
      unsigned int this_index = 0;
4735
4736
10.1k
      while (this_index < last_native_index)
4737
10.1k
  {
4738
10.1k
    combined_entry_type *src = native_symbols + this_index;
4739
10.1k
    table_ptr[this_index] = number_of_symbols;
4740
4741
10.1k
    dst->symbol.the_bfd = abfd;
4742
10.1k
    BFD_ASSERT (src->is_sym);
4743
10.1k
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4744
    /* We use the native name field to point to the cached field.  */
4745
10.1k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
10.1k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
10.1k
                 src->u.syment.n_scnum);
4748
10.1k
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
10.1k
    dst->symbol.value = 0;
4751
10.1k
    dst->done_lineno = false;
4752
4753
10.1k
    switch (src->u.syment.n_sclass)
4754
10.1k
      {
4755
182
      case C_EXT:
4756
187
      case C_WEAKEXT:
4757
#if defined ARM
4758
      case C_THUMBEXT:
4759
      case C_THUMBEXTFUNC:
4760
#endif
4761
#ifdef RS6000COFF_C
4762
      case C_HIDEXT:
4763
#ifndef AIX_WEAK_SUPPORT
4764
      case C_AIX_WEAKEXT:
4765
#endif
4766
#endif
4767
187
#ifdef C_SYSTEM
4768
190
      case C_SYSTEM: /* System Wide variable.  */
4769
190
#endif
4770
190
#ifdef COFF_WITH_PE
4771
      /* In PE, 0x68 (104) denotes a section symbol.  */
4772
190
      case C_SECTION:
4773
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4774
199
      case C_NT_WEAK:
4775
199
#endif
4776
199
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
199
    {
4778
114
    case COFF_SYMBOL_GLOBAL:
4779
114
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4780
114
#if defined COFF_WITH_PE
4781
      /* PE sets the symbol to a value relative to the
4782
         start of the section.  */
4783
114
      dst->symbol.value = src->u.syment.n_value;
4784
#else
4785
      dst->symbol.value = (src->u.syment.n_value
4786
               - dst->symbol.section->vma);
4787
#endif
4788
114
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
2
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
114
      break;
4793
4794
77
    case COFF_SYMBOL_COMMON:
4795
77
      dst->symbol.section = bfd_com_section_ptr;
4796
77
      dst->symbol.value = src->u.syment.n_value;
4797
77
      break;
4798
4799
8
    case COFF_SYMBOL_UNDEFINED:
4800
8
      dst->symbol.section = bfd_und_section_ptr;
4801
8
      dst->symbol.value = 0;
4802
8
      break;
4803
4804
0
    case COFF_SYMBOL_PE_SECTION:
4805
0
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4806
0
      dst->symbol.value = 0;
4807
0
      break;
4808
4809
0
    case COFF_SYMBOL_LOCAL:
4810
0
      dst->symbol.flags = BSF_LOCAL;
4811
0
#if defined COFF_WITH_PE
4812
      /* PE sets the symbol to a value relative to the
4813
         start of the section.  */
4814
0
      dst->symbol.value = src->u.syment.n_value;
4815
#else
4816
      dst->symbol.value = (src->u.syment.n_value
4817
               - dst->symbol.section->vma);
4818
#endif
4819
0
      if (ISFCN ((src->u.syment.n_type)))
4820
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4821
0
      break;
4822
199
    }
4823
4824
#ifdef RS6000COFF_C
4825
        /* A symbol with a csect entry should not go at the end.  */
4826
        if (src->u.syment.n_numaux > 0)
4827
    dst->symbol.flags |= BSF_NOT_AT_END;
4828
#endif
4829
4830
199
#ifdef COFF_WITH_PE
4831
199
        if (src->u.syment.n_sclass == C_NT_WEAK)
4832
9
    dst->symbol.flags |= BSF_WEAK;
4833
4834
199
        if (src->u.syment.n_sclass == C_SECTION
4835
199
      && src->u.syment.n_scnum > 0)
4836
0
    dst->symbol.flags = BSF_LOCAL;
4837
199
#endif
4838
199
        if (src->u.syment.n_sclass == C_WEAKEXT
4839
#ifdef RS6000COFF_C
4840
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4841
#endif
4842
199
      )
4843
5
    dst->symbol.flags |= BSF_WEAK;
4844
4845
199
        break;
4846
4847
24
      case C_STAT:  /* Static.  */
4848
#if defined ARM
4849
      case C_THUMBSTAT:    /* Thumb static.  */
4850
      case C_THUMBLABEL:   /* Thumb label.  */
4851
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4852
#endif
4853
#ifdef RS6000COFF_C
4854
      case C_DWARF:  /* A label in a dwarf section.  */
4855
      case C_INFO:   /* A label in a comment section.  */
4856
#endif
4857
35
      case C_LABEL:  /* Label.  */
4858
35
        if (src->u.syment.n_scnum == N_DEBUG)
4859
0
    dst->symbol.flags = BSF_DEBUGGING;
4860
35
        else
4861
35
    dst->symbol.flags = BSF_LOCAL;
4862
4863
        /* Base the value as an index from the base of the
4864
     section, if there is one.  */
4865
35
        if (dst->symbol.section)
4866
35
    {
4867
35
#if defined COFF_WITH_PE
4868
      /* PE sets the symbol to a value relative to the
4869
         start of the section.  */
4870
35
      dst->symbol.value = src->u.syment.n_value;
4871
#else
4872
      dst->symbol.value = (src->u.syment.n_value
4873
               - dst->symbol.section->vma);
4874
#endif
4875
35
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
35
        break;
4879
4880
30
      case C_FILE: /* File name.  */
4881
30
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
50
      case C_MOS:   /* Member of structure.  */
4884
70
      case C_EOS:   /* End of structure.  */
4885
72
      case C_REGPARM: /* Register parameter.  */
4886
87
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
98
      case C_TPDEF: /* Type definition.  */
4889
133
      case C_ARG:
4890
875
      case C_AUTO: /* Automatic variable.  */
4891
877
      case C_FIELD: /* Bit field.  */
4892
896
      case C_ENTAG: /* Enumeration tag.  */
4893
990
      case C_MOE:   /* Member of enumeration.  */
4894
1.00k
      case C_MOU:   /* Member of union.  */
4895
1.03k
      case C_UNTAG: /* Union tag.  */
4896
1.24k
      case C_STRTAG: /* Structure tag.  */
4897
#ifdef RS6000COFF_C
4898
      case C_GSYM:
4899
      case C_LSYM:
4900
      case C_PSYM:
4901
      case C_RSYM:
4902
      case C_RPSYM:
4903
      case C_STSYM:
4904
      case C_TCSYM:
4905
      case C_BCOMM:
4906
      case C_ECOML:
4907
      case C_ECOMM:
4908
      case C_DECL:
4909
      case C_ENTRY:
4910
      case C_FUN:
4911
      case C_ESTAT:
4912
#endif
4913
1.24k
        dst->symbol.flags |= BSF_DEBUGGING;
4914
1.24k
        dst->symbol.value = (src->u.syment.n_value);
4915
1.24k
        break;
4916
4917
#ifdef RS6000COFF_C
4918
      case C_BINCL: /* Beginning of include file.  */
4919
      case C_EINCL: /* Ending of include file.  */
4920
        /* The value is actually a pointer into the line numbers
4921
     of the file.  We locate the line number entry, and
4922
     set the section to the section which contains it, and
4923
     the value to the index in that section.  */
4924
        {
4925
    asection *sec;
4926
4927
    dst->symbol.flags = BSF_DEBUGGING;
4928
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4929
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4930
          && ((file_ptr) (sec->line_filepos
4931
              + sec->lineno_count * bfd_coff_linesz (abfd))
4932
        > (file_ptr) src->u.syment.n_value))
4933
        break;
4934
    if (sec == NULL)
4935
      dst->symbol.value = 0;
4936
    else
4937
      {
4938
        dst->symbol.section = sec;
4939
        dst->symbol.value = ((src->u.syment.n_value
4940
            - sec->line_filepos)
4941
           / bfd_coff_linesz (abfd));
4942
        src->fix_line = 1;
4943
      }
4944
        }
4945
        break;
4946
4947
      case C_BSTAT:
4948
        dst->symbol.flags = BSF_DEBUGGING;
4949
4950
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4951
    dst->symbol.value = 0;
4952
        else
4953
    {
4954
      /* The value is actually a symbol index.  Save a pointer
4955
         to the symbol instead of the index.  FIXME: This
4956
         should use a union.  */
4957
      src->u.syment.n_value
4958
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4959
      dst->symbol.value = src->u.syment.n_value;
4960
      src->fix_value = 1;
4961
    }
4962
        break;
4963
#endif
4964
4965
6
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
23
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
73
      case C_EFCN: /* Physical end of function.  */
4968
73
#if defined COFF_WITH_PE
4969
        /* PE sets the symbol to a value relative to the start
4970
     of the section.  */
4971
73
        dst->symbol.value = src->u.syment.n_value;
4972
73
        if (strcmp (dst->symbol.name, ".bf") != 0)
4973
73
    {
4974
      /* PE uses funny values for .ef and .lf; don't
4975
         relocate them.  */
4976
73
      dst->symbol.flags = BSF_DEBUGGING;
4977
73
    }
4978
0
        else
4979
0
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4980
#else
4981
        /* Base the value as an index from the base of the
4982
     section.  */
4983
        dst->symbol.flags = BSF_LOCAL;
4984
        dst->symbol.value = (src->u.syment.n_value
4985
           - dst->symbol.section->vma);
4986
#endif
4987
73
        break;
4988
4989
8
      case C_STATLAB: /* Static load time label.  */
4990
8
        dst->symbol.value = src->u.syment.n_value;
4991
8
        dst->symbol.flags = BSF_GLOBAL;
4992
8
        break;
4993
4994
7.26k
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
7.26k
        if (src->u.syment.n_type == 0
4998
7.26k
      && src->u.syment.n_value == 0
4999
7.26k
      && src->u.syment.n_scnum == 0)
5000
1.70k
    break;
5001
#ifdef RS6000COFF_C
5002
        /* XCOFF specific: deleted entry.  */
5003
        if (src->u.syment.n_value == C_NULL_VALUE)
5004
    break;
5005
#endif
5006
        /* Fall through.  */
5007
5.57k
      case C_EXTDEF: /* External definition.  */
5008
5.57k
      case C_ULABEL: /* Undefined label.  */
5009
5.58k
      case C_USTATIC: /* Undefined static.  */
5010
#ifndef COFF_WITH_PE
5011
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5012
         class to represent a section symbol.  */
5013
      case C_LINE:  /* line # reformatted as symbol table entry.  */
5014
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5015
      case C_ALIAS: /* Duplicate tag.  */
5016
#endif
5017
        /* New storage classes for TI COFF.  */
5018
#ifdef TICOFF
5019
      case C_UEXT:  /* Tentative external definition.  */
5020
#endif
5021
5.58k
      case C_EXTLAB: /* External load time label.  */
5022
6.86k
      default:
5023
6.86k
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
6.86k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
6.86k
     abfd, src->u.syment.n_sclass,
5027
6.86k
     dst->symbol.section->name, dst->symbol.name);
5028
6.86k
        ret = false;
5029
        /* Fall through.  */
5030
6.87k
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5031
        /* PR 20722: These symbols can also be generated by
5032
     building DLLs with --gc-sections enabled.  */
5033
6.87k
        dst->symbol.flags = BSF_DEBUGGING;
5034
6.87k
        dst->symbol.value = (src->u.syment.n_value);
5035
6.87k
        break;
5036
10.1k
      }
5037
5038
10.1k
    dst->native = src;
5039
10.1k
    dst->symbol.udata.i = 0;
5040
10.1k
    dst->lineno = NULL;
5041
5042
10.1k
    this_index += (src->u.syment.n_numaux) + 1;
5043
10.1k
    dst++;
5044
10.1k
    number_of_symbols++;
5045
10.1k
  }
5046
27
    }
5047
5048
27
  obj_symbols (abfd) = cached_area;
5049
27
  obj_raw_syments (abfd) = native_symbols;
5050
5051
27
  abfd->symcount = number_of_symbols;
5052
27
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
27
  {
5055
27
    asection *p;
5056
5057
27
    p = abfd->sections;
5058
28
    while (p)
5059
27
      {
5060
27
  if (! coff_slurp_line_table (abfd, p))
5061
26
    return false;
5062
1
  p = p->next;
5063
1
      }
5064
27
  }
5065
5066
1
  return ret;
5067
27
}
pei-loongarch64.c:coff_slurp_symbol_table
Line
Count
Source
4695
92
{
4696
92
  combined_entry_type *native_symbols;
4697
92
  coff_symbol_type *cached_area;
4698
92
  unsigned int *table_ptr;
4699
92
  unsigned int number_of_symbols = 0;
4700
92
  bool ret = true;
4701
92
  size_t amt;
4702
4703
92
  if (obj_symbols (abfd))
4704
0
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
92
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
48
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
44
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
44
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
44
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
44
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
44
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
44
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
44
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
44
  if (table_ptr == NULL)
4729
0
    return false;
4730
44
  else
4731
44
    {
4732
44
      coff_symbol_type *dst = cached_area;
4733
44
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
44
      unsigned int this_index = 0;
4735
4736
9.98k
      while (this_index < last_native_index)
4737
9.94k
  {
4738
9.94k
    combined_entry_type *src = native_symbols + this_index;
4739
9.94k
    table_ptr[this_index] = number_of_symbols;
4740
4741
9.94k
    dst->symbol.the_bfd = abfd;
4742
9.94k
    BFD_ASSERT (src->is_sym);
4743
9.94k
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4744
    /* We use the native name field to point to the cached field.  */
4745
9.94k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
9.94k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
9.94k
                 src->u.syment.n_scnum);
4748
9.94k
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
9.94k
    dst->symbol.value = 0;
4751
9.94k
    dst->done_lineno = false;
4752
4753
9.94k
    switch (src->u.syment.n_sclass)
4754
9.94k
      {
4755
211
      case C_EXT:
4756
217
      case C_WEAKEXT:
4757
#if defined ARM
4758
      case C_THUMBEXT:
4759
      case C_THUMBEXTFUNC:
4760
#endif
4761
#ifdef RS6000COFF_C
4762
      case C_HIDEXT:
4763
#ifndef AIX_WEAK_SUPPORT
4764
      case C_AIX_WEAKEXT:
4765
#endif
4766
#endif
4767
217
#ifdef C_SYSTEM
4768
229
      case C_SYSTEM: /* System Wide variable.  */
4769
229
#endif
4770
229
#ifdef COFF_WITH_PE
4771
      /* In PE, 0x68 (104) denotes a section symbol.  */
4772
229
      case C_SECTION:
4773
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4774
247
      case C_NT_WEAK:
4775
247
#endif
4776
247
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
247
    {
4778
202
    case COFF_SYMBOL_GLOBAL:
4779
202
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4780
202
#if defined COFF_WITH_PE
4781
      /* PE sets the symbol to a value relative to the
4782
         start of the section.  */
4783
202
      dst->symbol.value = src->u.syment.n_value;
4784
#else
4785
      dst->symbol.value = (src->u.syment.n_value
4786
               - dst->symbol.section->vma);
4787
#endif
4788
202
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
13
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
202
      break;
4793
4794
42
    case COFF_SYMBOL_COMMON:
4795
42
      dst->symbol.section = bfd_com_section_ptr;
4796
42
      dst->symbol.value = src->u.syment.n_value;
4797
42
      break;
4798
4799
3
    case COFF_SYMBOL_UNDEFINED:
4800
3
      dst->symbol.section = bfd_und_section_ptr;
4801
3
      dst->symbol.value = 0;
4802
3
      break;
4803
4804
0
    case COFF_SYMBOL_PE_SECTION:
4805
0
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4806
0
      dst->symbol.value = 0;
4807
0
      break;
4808
4809
0
    case COFF_SYMBOL_LOCAL:
4810
0
      dst->symbol.flags = BSF_LOCAL;
4811
0
#if defined COFF_WITH_PE
4812
      /* PE sets the symbol to a value relative to the
4813
         start of the section.  */
4814
0
      dst->symbol.value = src->u.syment.n_value;
4815
#else
4816
      dst->symbol.value = (src->u.syment.n_value
4817
               - dst->symbol.section->vma);
4818
#endif
4819
0
      if (ISFCN ((src->u.syment.n_type)))
4820
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4821
0
      break;
4822
247
    }
4823
4824
#ifdef RS6000COFF_C
4825
        /* A symbol with a csect entry should not go at the end.  */
4826
        if (src->u.syment.n_numaux > 0)
4827
    dst->symbol.flags |= BSF_NOT_AT_END;
4828
#endif
4829
4830
247
#ifdef COFF_WITH_PE
4831
247
        if (src->u.syment.n_sclass == C_NT_WEAK)
4832
18
    dst->symbol.flags |= BSF_WEAK;
4833
4834
247
        if (src->u.syment.n_sclass == C_SECTION
4835
247
      && src->u.syment.n_scnum > 0)
4836
0
    dst->symbol.flags = BSF_LOCAL;
4837
247
#endif
4838
247
        if (src->u.syment.n_sclass == C_WEAKEXT
4839
#ifdef RS6000COFF_C
4840
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4841
#endif
4842
247
      )
4843
6
    dst->symbol.flags |= BSF_WEAK;
4844
4845
247
        break;
4846
4847
211
      case C_STAT:  /* Static.  */
4848
#if defined ARM
4849
      case C_THUMBSTAT:    /* Thumb static.  */
4850
      case C_THUMBLABEL:   /* Thumb label.  */
4851
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4852
#endif
4853
#ifdef RS6000COFF_C
4854
      case C_DWARF:  /* A label in a dwarf section.  */
4855
      case C_INFO:   /* A label in a comment section.  */
4856
#endif
4857
244
      case C_LABEL:  /* Label.  */
4858
244
        if (src->u.syment.n_scnum == N_DEBUG)
4859
0
    dst->symbol.flags = BSF_DEBUGGING;
4860
244
        else
4861
244
    dst->symbol.flags = BSF_LOCAL;
4862
4863
        /* Base the value as an index from the base of the
4864
     section, if there is one.  */
4865
244
        if (dst->symbol.section)
4866
244
    {
4867
244
#if defined COFF_WITH_PE
4868
      /* PE sets the symbol to a value relative to the
4869
         start of the section.  */
4870
244
      dst->symbol.value = src->u.syment.n_value;
4871
#else
4872
      dst->symbol.value = (src->u.syment.n_value
4873
               - dst->symbol.section->vma);
4874
#endif
4875
244
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
244
        break;
4879
4880
50
      case C_FILE: /* File name.  */
4881
50
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
78
      case C_MOS:   /* Member of structure.  */
4884
80
      case C_EOS:   /* End of structure.  */
4885
110
      case C_REGPARM: /* Register parameter.  */
4886
264
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
290
      case C_TPDEF: /* Type definition.  */
4889
359
      case C_ARG:
4890
953
      case C_AUTO: /* Automatic variable.  */
4891
1.01k
      case C_FIELD: /* Bit field.  */
4892
1.04k
      case C_ENTAG: /* Enumeration tag.  */
4893
1.10k
      case C_MOE:   /* Member of enumeration.  */
4894
1.12k
      case C_MOU:   /* Member of union.  */
4895
1.15k
      case C_UNTAG: /* Union tag.  */
4896
1.26k
      case C_STRTAG: /* Structure tag.  */
4897
#ifdef RS6000COFF_C
4898
      case C_GSYM:
4899
      case C_LSYM:
4900
      case C_PSYM:
4901
      case C_RSYM:
4902
      case C_RPSYM:
4903
      case C_STSYM:
4904
      case C_TCSYM:
4905
      case C_BCOMM:
4906
      case C_ECOML:
4907
      case C_ECOMM:
4908
      case C_DECL:
4909
      case C_ENTRY:
4910
      case C_FUN:
4911
      case C_ESTAT:
4912
#endif
4913
1.26k
        dst->symbol.flags |= BSF_DEBUGGING;
4914
1.26k
        dst->symbol.value = (src->u.syment.n_value);
4915
1.26k
        break;
4916
4917
#ifdef RS6000COFF_C
4918
      case C_BINCL: /* Beginning of include file.  */
4919
      case C_EINCL: /* Ending of include file.  */
4920
        /* The value is actually a pointer into the line numbers
4921
     of the file.  We locate the line number entry, and
4922
     set the section to the section which contains it, and
4923
     the value to the index in that section.  */
4924
        {
4925
    asection *sec;
4926
4927
    dst->symbol.flags = BSF_DEBUGGING;
4928
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4929
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4930
          && ((file_ptr) (sec->line_filepos
4931
              + sec->lineno_count * bfd_coff_linesz (abfd))
4932
        > (file_ptr) src->u.syment.n_value))
4933
        break;
4934
    if (sec == NULL)
4935
      dst->symbol.value = 0;
4936
    else
4937
      {
4938
        dst->symbol.section = sec;
4939
        dst->symbol.value = ((src->u.syment.n_value
4940
            - sec->line_filepos)
4941
           / bfd_coff_linesz (abfd));
4942
        src->fix_line = 1;
4943
      }
4944
        }
4945
        break;
4946
4947
      case C_BSTAT:
4948
        dst->symbol.flags = BSF_DEBUGGING;
4949
4950
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4951
    dst->symbol.value = 0;
4952
        else
4953
    {
4954
      /* The value is actually a symbol index.  Save a pointer
4955
         to the symbol instead of the index.  FIXME: This
4956
         should use a union.  */
4957
      src->u.syment.n_value
4958
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4959
      dst->symbol.value = src->u.syment.n_value;
4960
      src->fix_value = 1;
4961
    }
4962
        break;
4963
#endif
4964
4965
15
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
27
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
99
      case C_EFCN: /* Physical end of function.  */
4968
99
#if defined COFF_WITH_PE
4969
        /* PE sets the symbol to a value relative to the start
4970
     of the section.  */
4971
99
        dst->symbol.value = src->u.syment.n_value;
4972
99
        if (strcmp (dst->symbol.name, ".bf") != 0)
4973
99
    {
4974
      /* PE uses funny values for .ef and .lf; don't
4975
         relocate them.  */
4976
99
      dst->symbol.flags = BSF_DEBUGGING;
4977
99
    }
4978
0
        else
4979
0
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4980
#else
4981
        /* Base the value as an index from the base of the
4982
     section.  */
4983
        dst->symbol.flags = BSF_LOCAL;
4984
        dst->symbol.value = (src->u.syment.n_value
4985
           - dst->symbol.section->vma);
4986
#endif
4987
99
        break;
4988
4989
19
      case C_STATLAB: /* Static load time label.  */
4990
19
        dst->symbol.value = src->u.syment.n_value;
4991
19
        dst->symbol.flags = BSF_GLOBAL;
4992
19
        break;
4993
4994
6.26k
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
6.26k
        if (src->u.syment.n_type == 0
4998
6.26k
      && src->u.syment.n_value == 0
4999
6.26k
      && src->u.syment.n_scnum == 0)
5000
1.55k
    break;
5001
#ifdef RS6000COFF_C
5002
        /* XCOFF specific: deleted entry.  */
5003
        if (src->u.syment.n_value == C_NULL_VALUE)
5004
    break;
5005
#endif
5006
        /* Fall through.  */
5007
4.73k
      case C_EXTDEF: /* External definition.  */
5008
4.75k
      case C_ULABEL: /* Undefined label.  */
5009
4.76k
      case C_USTATIC: /* Undefined static.  */
5010
#ifndef COFF_WITH_PE
5011
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5012
         class to represent a section symbol.  */
5013
      case C_LINE:  /* line # reformatted as symbol table entry.  */
5014
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5015
      case C_ALIAS: /* Duplicate tag.  */
5016
#endif
5017
        /* New storage classes for TI COFF.  */
5018
#ifdef TICOFF
5019
      case C_UEXT:  /* Tentative external definition.  */
5020
#endif
5021
4.78k
      case C_EXTLAB: /* External load time label.  */
5022
6.51k
      default:
5023
6.51k
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
6.51k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
6.51k
     abfd, src->u.syment.n_sclass,
5027
6.51k
     dst->symbol.section->name, dst->symbol.name);
5028
6.51k
        ret = false;
5029
        /* Fall through.  */
5030
6.51k
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5031
        /* PR 20722: These symbols can also be generated by
5032
     building DLLs with --gc-sections enabled.  */
5033
6.51k
        dst->symbol.flags = BSF_DEBUGGING;
5034
6.51k
        dst->symbol.value = (src->u.syment.n_value);
5035
6.51k
        break;
5036
9.94k
      }
5037
5038
9.94k
    dst->native = src;
5039
9.94k
    dst->symbol.udata.i = 0;
5040
9.94k
    dst->lineno = NULL;
5041
5042
9.94k
    this_index += (src->u.syment.n_numaux) + 1;
5043
9.94k
    dst++;
5044
9.94k
    number_of_symbols++;
5045
9.94k
  }
5046
44
    }
5047
5048
44
  obj_symbols (abfd) = cached_area;
5049
44
  obj_raw_syments (abfd) = native_symbols;
5050
5051
44
  abfd->symcount = number_of_symbols;
5052
44
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
44
  {
5055
44
    asection *p;
5056
5057
44
    p = abfd->sections;
5058
140
    while (p)
5059
121
      {
5060
121
  if (! coff_slurp_line_table (abfd, p))
5061
25
    return false;
5062
96
  p = p->next;
5063
96
      }
5064
44
  }
5065
5066
19
  return ret;
5067
44
}
Unexecuted instantiation: cf-i386lynx.c:coff_slurp_symbol_table
Unexecuted instantiation: coff-go32.c:coff_slurp_symbol_table
Unexecuted instantiation: coff-i386.c:coff_slurp_symbol_table
coff-rs6000.c:coff_slurp_symbol_table
Line
Count
Source
4695
133
{
4696
133
  combined_entry_type *native_symbols;
4697
133
  coff_symbol_type *cached_area;
4698
133
  unsigned int *table_ptr;
4699
133
  unsigned int number_of_symbols = 0;
4700
133
  bool ret = true;
4701
133
  size_t amt;
4702
4703
133
  if (obj_symbols (abfd))
4704
0
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
133
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
36
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
97
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
97
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
97
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
97
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
97
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
97
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
97
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
97
  if (table_ptr == NULL)
4729
0
    return false;
4730
97
  else
4731
97
    {
4732
97
      coff_symbol_type *dst = cached_area;
4733
97
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
97
      unsigned int this_index = 0;
4735
4736
64.8k
      while (this_index < last_native_index)
4737
64.7k
  {
4738
64.7k
    combined_entry_type *src = native_symbols + this_index;
4739
64.7k
    table_ptr[this_index] = number_of_symbols;
4740
4741
64.7k
    dst->symbol.the_bfd = abfd;
4742
64.7k
    BFD_ASSERT (src->is_sym);
4743
64.7k
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4744
    /* We use the native name field to point to the cached field.  */
4745
64.7k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
64.7k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
64.7k
                 src->u.syment.n_scnum);
4748
64.7k
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
64.7k
    dst->symbol.value = 0;
4751
64.7k
    dst->done_lineno = false;
4752
4753
64.7k
    switch (src->u.syment.n_sclass)
4754
64.7k
      {
4755
608
      case C_EXT:
4756
661
      case C_WEAKEXT:
4757
#if defined ARM
4758
      case C_THUMBEXT:
4759
      case C_THUMBEXTFUNC:
4760
#endif
4761
661
#ifdef RS6000COFF_C
4762
703
      case C_HIDEXT:
4763
703
#ifndef AIX_WEAK_SUPPORT
4764
778
      case C_AIX_WEAKEXT:
4765
778
#endif
4766
778
#endif
4767
778
#ifdef C_SYSTEM
4768
826
      case C_SYSTEM: /* System Wide variable.  */
4769
826
#endif
4770
#ifdef COFF_WITH_PE
4771
      /* In PE, 0x68 (104) denotes a section symbol.  */
4772
      case C_SECTION:
4773
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4774
      case C_NT_WEAK:
4775
#endif
4776
826
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
826
    {
4778
726
    case COFF_SYMBOL_GLOBAL:
4779
726
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4780
#if defined COFF_WITH_PE
4781
      /* PE sets the symbol to a value relative to the
4782
         start of the section.  */
4783
      dst->symbol.value = src->u.syment.n_value;
4784
#else
4785
726
      dst->symbol.value = (src->u.syment.n_value
4786
726
               - dst->symbol.section->vma);
4787
726
#endif
4788
726
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
65
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
726
      break;
4793
4794
35
    case COFF_SYMBOL_COMMON:
4795
35
      dst->symbol.section = bfd_com_section_ptr;
4796
35
      dst->symbol.value = src->u.syment.n_value;
4797
35
      break;
4798
4799
25
    case COFF_SYMBOL_UNDEFINED:
4800
25
      dst->symbol.section = bfd_und_section_ptr;
4801
25
      dst->symbol.value = 0;
4802
25
      break;
4803
4804
0
    case COFF_SYMBOL_PE_SECTION:
4805
0
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4806
0
      dst->symbol.value = 0;
4807
0
      break;
4808
4809
40
    case COFF_SYMBOL_LOCAL:
4810
40
      dst->symbol.flags = BSF_LOCAL;
4811
#if defined COFF_WITH_PE
4812
      /* PE sets the symbol to a value relative to the
4813
         start of the section.  */
4814
      dst->symbol.value = src->u.syment.n_value;
4815
#else
4816
40
      dst->symbol.value = (src->u.syment.n_value
4817
40
               - dst->symbol.section->vma);
4818
40
#endif
4819
40
      if (ISFCN ((src->u.syment.n_type)))
4820
12
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4821
40
      break;
4822
826
    }
4823
4824
826
#ifdef RS6000COFF_C
4825
        /* A symbol with a csect entry should not go at the end.  */
4826
826
        if (src->u.syment.n_numaux > 0)
4827
751
    dst->symbol.flags |= BSF_NOT_AT_END;
4828
826
#endif
4829
4830
#ifdef COFF_WITH_PE
4831
        if (src->u.syment.n_sclass == C_NT_WEAK)
4832
    dst->symbol.flags |= BSF_WEAK;
4833
4834
        if (src->u.syment.n_sclass == C_SECTION
4835
      && src->u.syment.n_scnum > 0)
4836
    dst->symbol.flags = BSF_LOCAL;
4837
#endif
4838
826
        if (src->u.syment.n_sclass == C_WEAKEXT
4839
826
#ifdef RS6000COFF_C
4840
826
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4841
826
#endif
4842
826
      )
4843
128
    dst->symbol.flags |= BSF_WEAK;
4844
4845
826
        break;
4846
4847
146
      case C_STAT:  /* Static.  */
4848
#if defined ARM
4849
      case C_THUMBSTAT:    /* Thumb static.  */
4850
      case C_THUMBLABEL:   /* Thumb label.  */
4851
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4852
#endif
4853
146
#ifdef RS6000COFF_C
4854
211
      case C_DWARF:  /* A label in a dwarf section.  */
4855
274
      case C_INFO:  /* A label in a comment section.  */
4856
274
#endif
4857
355
      case C_LABEL:  /* Label.  */
4858
355
        if (src->u.syment.n_scnum == N_DEBUG)
4859
0
    dst->symbol.flags = BSF_DEBUGGING;
4860
355
        else
4861
355
    dst->symbol.flags = BSF_LOCAL;
4862
4863
        /* Base the value as an index from the base of the
4864
     section, if there is one.  */
4865
355
        if (dst->symbol.section)
4866
355
    {
4867
#if defined COFF_WITH_PE
4868
      /* PE sets the symbol to a value relative to the
4869
         start of the section.  */
4870
      dst->symbol.value = src->u.syment.n_value;
4871
#else
4872
355
      dst->symbol.value = (src->u.syment.n_value
4873
355
               - dst->symbol.section->vma);
4874
355
#endif
4875
355
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
355
        break;
4879
4880
122
      case C_FILE: /* File name.  */
4881
122
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
214
      case C_MOS:   /* Member of structure.  */
4884
256
      case C_EOS:   /* End of structure.  */
4885
360
      case C_REGPARM: /* Register parameter.  */
4886
417
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
864
      case C_TPDEF: /* Type definition.  */
4889
923
      case C_ARG:
4890
2.06k
      case C_AUTO: /* Automatic variable.  */
4891
2.75k
      case C_FIELD: /* Bit field.  */
4892
2.86k
      case C_ENTAG: /* Enumeration tag.  */
4893
2.96k
      case C_MOE:   /* Member of enumeration.  */
4894
3.11k
      case C_MOU:   /* Member of union.  */
4895
4.84k
      case C_UNTAG: /* Union tag.  */
4896
4.94k
      case C_STRTAG: /* Structure tag.  */
4897
4.94k
#ifdef RS6000COFF_C
4898
5.03k
      case C_GSYM:
4899
5.42k
      case C_LSYM:
4900
5.47k
      case C_PSYM:
4901
5.73k
      case C_RSYM:
4902
6.47k
      case C_RPSYM:
4903
6.51k
      case C_STSYM:
4904
6.55k
      case C_TCSYM:
4905
6.67k
      case C_BCOMM:
4906
6.76k
      case C_ECOML:
4907
6.81k
      case C_ECOMM:
4908
6.87k
      case C_DECL:
4909
6.92k
      case C_ENTRY:
4910
6.97k
      case C_FUN:
4911
7.08k
      case C_ESTAT:
4912
7.08k
#endif
4913
7.08k
        dst->symbol.flags |= BSF_DEBUGGING;
4914
7.08k
        dst->symbol.value = (src->u.syment.n_value);
4915
7.08k
        break;
4916
4917
0
#ifdef RS6000COFF_C
4918
75
      case C_BINCL: /* Beginning of include file.  */
4919
139
      case C_EINCL: /* Ending of include file.  */
4920
        /* The value is actually a pointer into the line numbers
4921
     of the file.  We locate the line number entry, and
4922
     set the section to the section which contains it, and
4923
     the value to the index in that section.  */
4924
139
        {
4925
139
    asection *sec;
4926
4927
139
    dst->symbol.flags = BSF_DEBUGGING;
4928
7.69k
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4929
7.61k
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4930
7.61k
          && ((file_ptr) (sec->line_filepos
4931
2.91k
              + sec->lineno_count * bfd_coff_linesz (abfd))
4932
2.91k
        > (file_ptr) src->u.syment.n_value))
4933
55
        break;
4934
139
    if (sec == NULL)
4935
84
      dst->symbol.value = 0;
4936
55
    else
4937
55
      {
4938
55
        dst->symbol.section = sec;
4939
55
        dst->symbol.value = ((src->u.syment.n_value
4940
55
            - sec->line_filepos)
4941
55
           / bfd_coff_linesz (abfd));
4942
55
        src->fix_line = 1;
4943
55
      }
4944
139
        }
4945
139
        break;
4946
4947
28
      case C_BSTAT:
4948
28
        dst->symbol.flags = BSF_DEBUGGING;
4949
4950
28
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4951
28
    dst->symbol.value = 0;
4952
0
        else
4953
0
    {
4954
      /* The value is actually a symbol index.  Save a pointer
4955
         to the symbol instead of the index.  FIXME: This
4956
         should use a union.  */
4957
0
      src->u.syment.n_value
4958
0
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4959
0
      dst->symbol.value = src->u.syment.n_value;
4960
0
      src->fix_value = 1;
4961
0
    }
4962
28
        break;
4963
0
#endif
4964
4965
50
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
92
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
221
      case C_EFCN: /* Physical end of function.  */
4968
#if defined COFF_WITH_PE
4969
        /* PE sets the symbol to a value relative to the start
4970
     of the section.  */
4971
        dst->symbol.value = src->u.syment.n_value;
4972
        if (strcmp (dst->symbol.name, ".bf") != 0)
4973
    {
4974
      /* PE uses funny values for .ef and .lf; don't
4975
         relocate them.  */
4976
      dst->symbol.flags = BSF_DEBUGGING;
4977
    }
4978
        else
4979
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4980
#else
4981
        /* Base the value as an index from the base of the
4982
     section.  */
4983
221
        dst->symbol.flags = BSF_LOCAL;
4984
221
        dst->symbol.value = (src->u.syment.n_value
4985
221
           - dst->symbol.section->vma);
4986
221
#endif
4987
221
        break;
4988
4989
44
      case C_STATLAB: /* Static load time label.  */
4990
44
        dst->symbol.value = src->u.syment.n_value;
4991
44
        dst->symbol.flags = BSF_GLOBAL;
4992
44
        break;
4993
4994
46.8k
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
46.8k
        if (src->u.syment.n_type == 0
4998
46.8k
      && src->u.syment.n_value == 0
4999
46.8k
      && src->u.syment.n_scnum == 0)
5000
42.1k
    break;
5001
4.65k
#ifdef RS6000COFF_C
5002
        /* XCOFF specific: deleted entry.  */
5003
4.65k
        if (src->u.syment.n_value == C_NULL_VALUE)
5004
0
    break;
5005
4.65k
#endif
5006
        /* Fall through.  */
5007
4.72k
      case C_EXTDEF: /* External definition.  */
5008
4.80k
      case C_ULABEL: /* Undefined label.  */
5009
4.92k
      case C_USTATIC: /* Undefined static.  */
5010
4.92k
#ifndef COFF_WITH_PE
5011
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5012
         class to represent a section symbol.  */
5013
4.96k
      case C_LINE: /* line # reformatted as symbol table entry.  */
5014
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5015
5.01k
      case C_ALIAS: /* Duplicate tag.  */
5016
5.01k
#endif
5017
        /* New storage classes for TI COFF.  */
5018
#ifdef TICOFF
5019
      case C_UEXT:  /* Tentative external definition.  */
5020
#endif
5021
5.08k
      case C_EXTLAB: /* External load time label.  */
5022
13.8k
      default:
5023
13.8k
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
13.8k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
13.8k
     abfd, src->u.syment.n_sclass,
5027
13.8k
     dst->symbol.section->name, dst->symbol.name);
5028
13.8k
        ret = false;
5029
        /* Fall through.  */
5030
13.9k
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5031
        /* PR 20722: These symbols can also be generated by
5032
     building DLLs with --gc-sections enabled.  */
5033
13.9k
        dst->symbol.flags = BSF_DEBUGGING;
5034
13.9k
        dst->symbol.value = (src->u.syment.n_value);
5035
13.9k
        break;
5036
64.7k
      }
5037
5038
64.7k
    dst->native = src;
5039
64.7k
    dst->symbol.udata.i = 0;
5040
64.7k
    dst->lineno = NULL;
5041
5042
64.7k
    this_index += (src->u.syment.n_numaux) + 1;
5043
64.7k
    dst++;
5044
64.7k
    number_of_symbols++;
5045
64.7k
  }
5046
97
    }
5047
5048
97
  obj_symbols (abfd) = cached_area;
5049
97
  obj_raw_syments (abfd) = native_symbols;
5050
5051
97
  abfd->symcount = number_of_symbols;
5052
97
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
97
  {
5055
97
    asection *p;
5056
5057
97
    p = abfd->sections;
5058
353
    while (p)
5059
320
      {
5060
320
  if (! coff_slurp_line_table (abfd, p))
5061
64
    return false;
5062
256
  p = p->next;
5063
256
      }
5064
97
  }
5065
5066
33
  return ret;
5067
97
}
coff-sh.c:coff_slurp_symbol_table
Line
Count
Source
4695
153
{
4696
153
  combined_entry_type *native_symbols;
4697
153
  coff_symbol_type *cached_area;
4698
153
  unsigned int *table_ptr;
4699
153
  unsigned int number_of_symbols = 0;
4700
153
  bool ret = true;
4701
153
  size_t amt;
4702
4703
153
  if (obj_symbols (abfd))
4704
1
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
152
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
103
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
49
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
49
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
49
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
49
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
49
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
49
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
49
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
49
  if (table_ptr == NULL)
4729
0
    return false;
4730
49
  else
4731
49
    {
4732
49
      coff_symbol_type *dst = cached_area;
4733
49
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
49
      unsigned int this_index = 0;
4735
4736
31.9k
      while (this_index < last_native_index)
4737
31.9k
  {
4738
31.9k
    combined_entry_type *src = native_symbols + this_index;
4739
31.9k
    table_ptr[this_index] = number_of_symbols;
4740
4741
31.9k
    dst->symbol.the_bfd = abfd;
4742
31.9k
    BFD_ASSERT (src->is_sym);
4743
31.9k
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4744
    /* We use the native name field to point to the cached field.  */
4745
31.9k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
31.9k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
31.9k
                 src->u.syment.n_scnum);
4748
31.9k
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
31.9k
    dst->symbol.value = 0;
4751
31.9k
    dst->done_lineno = false;
4752
4753
31.9k
    switch (src->u.syment.n_sclass)
4754
31.9k
      {
4755
787
      case C_EXT:
4756
811
      case C_WEAKEXT:
4757
#if defined ARM
4758
      case C_THUMBEXT:
4759
      case C_THUMBEXTFUNC:
4760
#endif
4761
#ifdef RS6000COFF_C
4762
      case C_HIDEXT:
4763
#ifndef AIX_WEAK_SUPPORT
4764
      case C_AIX_WEAKEXT:
4765
#endif
4766
#endif
4767
811
#ifdef C_SYSTEM
4768
828
      case C_SYSTEM: /* System Wide variable.  */
4769
828
#endif
4770
#ifdef COFF_WITH_PE
4771
      /* In PE, 0x68 (104) denotes a section symbol.  */
4772
      case C_SECTION:
4773
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4774
      case C_NT_WEAK:
4775
#endif
4776
828
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
828
    {
4778
680
    case COFF_SYMBOL_GLOBAL:
4779
680
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4780
#if defined COFF_WITH_PE
4781
      /* PE sets the symbol to a value relative to the
4782
         start of the section.  */
4783
      dst->symbol.value = src->u.syment.n_value;
4784
#else
4785
680
      dst->symbol.value = (src->u.syment.n_value
4786
680
               - dst->symbol.section->vma);
4787
680
#endif
4788
680
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
9
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
680
      break;
4793
4794
130
    case COFF_SYMBOL_COMMON:
4795
130
      dst->symbol.section = bfd_com_section_ptr;
4796
130
      dst->symbol.value = src->u.syment.n_value;
4797
130
      break;
4798
4799
18
    case COFF_SYMBOL_UNDEFINED:
4800
18
      dst->symbol.section = bfd_und_section_ptr;
4801
18
      dst->symbol.value = 0;
4802
18
      break;
4803
4804
0
    case COFF_SYMBOL_PE_SECTION:
4805
0
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4806
0
      dst->symbol.value = 0;
4807
0
      break;
4808
4809
0
    case COFF_SYMBOL_LOCAL:
4810
0
      dst->symbol.flags = BSF_LOCAL;
4811
#if defined COFF_WITH_PE
4812
      /* PE sets the symbol to a value relative to the
4813
         start of the section.  */
4814
      dst->symbol.value = src->u.syment.n_value;
4815
#else
4816
0
      dst->symbol.value = (src->u.syment.n_value
4817
0
               - dst->symbol.section->vma);
4818
0
#endif
4819
0
      if (ISFCN ((src->u.syment.n_type)))
4820
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4821
0
      break;
4822
828
    }
4823
4824
#ifdef RS6000COFF_C
4825
        /* A symbol with a csect entry should not go at the end.  */
4826
        if (src->u.syment.n_numaux > 0)
4827
    dst->symbol.flags |= BSF_NOT_AT_END;
4828
#endif
4829
4830
#ifdef COFF_WITH_PE
4831
        if (src->u.syment.n_sclass == C_NT_WEAK)
4832
    dst->symbol.flags |= BSF_WEAK;
4833
4834
        if (src->u.syment.n_sclass == C_SECTION
4835
      && src->u.syment.n_scnum > 0)
4836
    dst->symbol.flags = BSF_LOCAL;
4837
#endif
4838
828
        if (src->u.syment.n_sclass == C_WEAKEXT
4839
#ifdef RS6000COFF_C
4840
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4841
#endif
4842
828
      )
4843
24
    dst->symbol.flags |= BSF_WEAK;
4844
4845
828
        break;
4846
4847
253
      case C_STAT:  /* Static.  */
4848
#if defined ARM
4849
      case C_THUMBSTAT:    /* Thumb static.  */
4850
      case C_THUMBLABEL:   /* Thumb label.  */
4851
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4852
#endif
4853
#ifdef RS6000COFF_C
4854
      case C_DWARF:  /* A label in a dwarf section.  */
4855
      case C_INFO:   /* A label in a comment section.  */
4856
#endif
4857
309
      case C_LABEL:  /* Label.  */
4858
309
        if (src->u.syment.n_scnum == N_DEBUG)
4859
0
    dst->symbol.flags = BSF_DEBUGGING;
4860
309
        else
4861
309
    dst->symbol.flags = BSF_LOCAL;
4862
4863
        /* Base the value as an index from the base of the
4864
     section, if there is one.  */
4865
309
        if (dst->symbol.section)
4866
309
    {
4867
#if defined COFF_WITH_PE
4868
      /* PE sets the symbol to a value relative to the
4869
         start of the section.  */
4870
      dst->symbol.value = src->u.syment.n_value;
4871
#else
4872
309
      dst->symbol.value = (src->u.syment.n_value
4873
309
               - dst->symbol.section->vma);
4874
309
#endif
4875
309
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
309
        break;
4879
4880
71
      case C_FILE: /* File name.  */
4881
71
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
105
      case C_MOS:   /* Member of structure.  */
4884
124
      case C_EOS:   /* End of structure.  */
4885
158
      case C_REGPARM: /* Register parameter.  */
4886
229
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
458
      case C_TPDEF: /* Type definition.  */
4889
593
      case C_ARG:
4890
2.40k
      case C_AUTO: /* Automatic variable.  */
4891
2.48k
      case C_FIELD: /* Bit field.  */
4892
2.53k
      case C_ENTAG: /* Enumeration tag.  */
4893
2.74k
      case C_MOE:   /* Member of enumeration.  */
4894
2.84k
      case C_MOU:   /* Member of union.  */
4895
2.89k
      case C_UNTAG: /* Union tag.  */
4896
3.27k
      case C_STRTAG: /* Structure tag.  */
4897
#ifdef RS6000COFF_C
4898
      case C_GSYM:
4899
      case C_LSYM:
4900
      case C_PSYM:
4901
      case C_RSYM:
4902
      case C_RPSYM:
4903
      case C_STSYM:
4904
      case C_TCSYM:
4905
      case C_BCOMM:
4906
      case C_ECOML:
4907
      case C_ECOMM:
4908
      case C_DECL:
4909
      case C_ENTRY:
4910
      case C_FUN:
4911
      case C_ESTAT:
4912
#endif
4913
3.27k
        dst->symbol.flags |= BSF_DEBUGGING;
4914
3.27k
        dst->symbol.value = (src->u.syment.n_value);
4915
3.27k
        break;
4916
4917
#ifdef RS6000COFF_C
4918
      case C_BINCL: /* Beginning of include file.  */
4919
      case C_EINCL: /* Ending of include file.  */
4920
        /* The value is actually a pointer into the line numbers
4921
     of the file.  We locate the line number entry, and
4922
     set the section to the section which contains it, and
4923
     the value to the index in that section.  */
4924
        {
4925
    asection *sec;
4926
4927
    dst->symbol.flags = BSF_DEBUGGING;
4928
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4929
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4930
          && ((file_ptr) (sec->line_filepos
4931
              + sec->lineno_count * bfd_coff_linesz (abfd))
4932
        > (file_ptr) src->u.syment.n_value))
4933
        break;
4934
    if (sec == NULL)
4935
      dst->symbol.value = 0;
4936
    else
4937
      {
4938
        dst->symbol.section = sec;
4939
        dst->symbol.value = ((src->u.syment.n_value
4940
            - sec->line_filepos)
4941
           / bfd_coff_linesz (abfd));
4942
        src->fix_line = 1;
4943
      }
4944
        }
4945
        break;
4946
4947
      case C_BSTAT:
4948
        dst->symbol.flags = BSF_DEBUGGING;
4949
4950
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4951
    dst->symbol.value = 0;
4952
        else
4953
    {
4954
      /* The value is actually a symbol index.  Save a pointer
4955
         to the symbol instead of the index.  FIXME: This
4956
         should use a union.  */
4957
      src->u.syment.n_value
4958
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4959
      dst->symbol.value = src->u.syment.n_value;
4960
      src->fix_value = 1;
4961
    }
4962
        break;
4963
#endif
4964
4965
24
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
67
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
237
      case C_EFCN: /* Physical end of function.  */
4968
#if defined COFF_WITH_PE
4969
        /* PE sets the symbol to a value relative to the start
4970
     of the section.  */
4971
        dst->symbol.value = src->u.syment.n_value;
4972
        if (strcmp (dst->symbol.name, ".bf") != 0)
4973
    {
4974
      /* PE uses funny values for .ef and .lf; don't
4975
         relocate them.  */
4976
      dst->symbol.flags = BSF_DEBUGGING;
4977
    }
4978
        else
4979
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4980
#else
4981
        /* Base the value as an index from the base of the
4982
     section.  */
4983
237
        dst->symbol.flags = BSF_LOCAL;
4984
237
        dst->symbol.value = (src->u.syment.n_value
4985
237
           - dst->symbol.section->vma);
4986
237
#endif
4987
237
        break;
4988
4989
43
      case C_STATLAB: /* Static load time label.  */
4990
43
        dst->symbol.value = src->u.syment.n_value;
4991
43
        dst->symbol.flags = BSF_GLOBAL;
4992
43
        break;
4993
4994
23.6k
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
23.6k
        if (src->u.syment.n_type == 0
4998
23.6k
      && src->u.syment.n_value == 0
4999
23.6k
      && src->u.syment.n_scnum == 0)
5000
10.6k
    break;
5001
#ifdef RS6000COFF_C
5002
        /* XCOFF specific: deleted entry.  */
5003
        if (src->u.syment.n_value == C_NULL_VALUE)
5004
    break;
5005
#endif
5006
        /* Fall through.  */
5007
13.0k
      case C_EXTDEF: /* External definition.  */
5008
13.0k
      case C_ULABEL: /* Undefined label.  */
5009
13.0k
      case C_USTATIC: /* Undefined static.  */
5010
13.0k
#ifndef COFF_WITH_PE
5011
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5012
         class to represent a section symbol.  */
5013
13.0k
      case C_LINE: /* line # reformatted as symbol table entry.  */
5014
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5015
13.0k
      case C_ALIAS: /* Duplicate tag.  */
5016
13.0k
#endif
5017
        /* New storage classes for TI COFF.  */
5018
#ifdef TICOFF
5019
      case C_UEXT:  /* Tentative external definition.  */
5020
#endif
5021
13.1k
      case C_EXTLAB: /* External load time label.  */
5022
16.5k
      default:
5023
16.5k
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
16.5k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
16.5k
     abfd, src->u.syment.n_sclass,
5027
16.5k
     dst->symbol.section->name, dst->symbol.name);
5028
16.5k
        ret = false;
5029
        /* Fall through.  */
5030
16.5k
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5031
        /* PR 20722: These symbols can also be generated by
5032
     building DLLs with --gc-sections enabled.  */
5033
16.5k
        dst->symbol.flags = BSF_DEBUGGING;
5034
16.5k
        dst->symbol.value = (src->u.syment.n_value);
5035
16.5k
        break;
5036
31.9k
      }
5037
5038
31.9k
    dst->native = src;
5039
31.9k
    dst->symbol.udata.i = 0;
5040
31.9k
    dst->lineno = NULL;
5041
5042
31.9k
    this_index += (src->u.syment.n_numaux) + 1;
5043
31.9k
    dst++;
5044
31.9k
    number_of_symbols++;
5045
31.9k
  }
5046
49
    }
5047
5048
49
  obj_symbols (abfd) = cached_area;
5049
49
  obj_raw_syments (abfd) = native_symbols;
5050
5051
49
  abfd->symcount = number_of_symbols;
5052
49
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
49
  {
5055
49
    asection *p;
5056
5057
49
    p = abfd->sections;
5058
379
    while (p)
5059
375
      {
5060
375
  if (! coff_slurp_line_table (abfd, p))
5061
45
    return false;
5062
330
  p = p->next;
5063
330
      }
5064
49
  }
5065
5066
4
  return ret;
5067
49
}
Unexecuted instantiation: coff-stgo32.c:coff_slurp_symbol_table
coff-tic30.c:coff_slurp_symbol_table
Line
Count
Source
4695
40
{
4696
40
  combined_entry_type *native_symbols;
4697
40
  coff_symbol_type *cached_area;
4698
40
  unsigned int *table_ptr;
4699
40
  unsigned int number_of_symbols = 0;
4700
40
  bool ret = true;
4701
40
  size_t amt;
4702
4703
40
  if (obj_symbols (abfd))
4704
0
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
40
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
20
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
20
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
20
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
20
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
20
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
20
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
20
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
20
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
20
  if (table_ptr == NULL)
4729
0
    return false;
4730
20
  else
4731
20
    {
4732
20
      coff_symbol_type *dst = cached_area;
4733
20
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
20
      unsigned int this_index = 0;
4735
4736
8.56k
      while (this_index < last_native_index)
4737
8.54k
  {
4738
8.54k
    combined_entry_type *src = native_symbols + this_index;
4739
8.54k
    table_ptr[this_index] = number_of_symbols;
4740
4741
8.54k
    dst->symbol.the_bfd = abfd;
4742
8.54k
    BFD_ASSERT (src->is_sym);
4743
8.54k
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4744
    /* We use the native name field to point to the cached field.  */
4745
8.54k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
8.54k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
8.54k
                 src->u.syment.n_scnum);
4748
8.54k
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
8.54k
    dst->symbol.value = 0;
4751
8.54k
    dst->done_lineno = false;
4752
4753
8.54k
    switch (src->u.syment.n_sclass)
4754
8.54k
      {
4755
49
      case C_EXT:
4756
54
      case C_WEAKEXT:
4757
#if defined ARM
4758
      case C_THUMBEXT:
4759
      case C_THUMBEXTFUNC:
4760
#endif
4761
#ifdef RS6000COFF_C
4762
      case C_HIDEXT:
4763
#ifndef AIX_WEAK_SUPPORT
4764
      case C_AIX_WEAKEXT:
4765
#endif
4766
#endif
4767
54
#ifdef C_SYSTEM
4768
59
      case C_SYSTEM: /* System Wide variable.  */
4769
59
#endif
4770
#ifdef COFF_WITH_PE
4771
      /* In PE, 0x68 (104) denotes a section symbol.  */
4772
      case C_SECTION:
4773
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4774
      case C_NT_WEAK:
4775
#endif
4776
59
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
59
    {
4778
46
    case COFF_SYMBOL_GLOBAL:
4779
46
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4780
#if defined COFF_WITH_PE
4781
      /* PE sets the symbol to a value relative to the
4782
         start of the section.  */
4783
      dst->symbol.value = src->u.syment.n_value;
4784
#else
4785
46
      dst->symbol.value = (src->u.syment.n_value
4786
46
               - dst->symbol.section->vma);
4787
46
#endif
4788
46
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
46
      break;
4793
4794
8
    case COFF_SYMBOL_COMMON:
4795
8
      dst->symbol.section = bfd_com_section_ptr;
4796
8
      dst->symbol.value = src->u.syment.n_value;
4797
8
      break;
4798
4799
5
    case COFF_SYMBOL_UNDEFINED:
4800
5
      dst->symbol.section = bfd_und_section_ptr;
4801
5
      dst->symbol.value = 0;
4802
5
      break;
4803
4804
0
    case COFF_SYMBOL_PE_SECTION:
4805
0
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4806
0
      dst->symbol.value = 0;
4807
0
      break;
4808
4809
0
    case COFF_SYMBOL_LOCAL:
4810
0
      dst->symbol.flags = BSF_LOCAL;
4811
#if defined COFF_WITH_PE
4812
      /* PE sets the symbol to a value relative to the
4813
         start of the section.  */
4814
      dst->symbol.value = src->u.syment.n_value;
4815
#else
4816
0
      dst->symbol.value = (src->u.syment.n_value
4817
0
               - dst->symbol.section->vma);
4818
0
#endif
4819
0
      if (ISFCN ((src->u.syment.n_type)))
4820
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4821
0
      break;
4822
59
    }
4823
4824
#ifdef RS6000COFF_C
4825
        /* A symbol with a csect entry should not go at the end.  */
4826
        if (src->u.syment.n_numaux > 0)
4827
    dst->symbol.flags |= BSF_NOT_AT_END;
4828
#endif
4829
4830
#ifdef COFF_WITH_PE
4831
        if (src->u.syment.n_sclass == C_NT_WEAK)
4832
    dst->symbol.flags |= BSF_WEAK;
4833
4834
        if (src->u.syment.n_sclass == C_SECTION
4835
      && src->u.syment.n_scnum > 0)
4836
    dst->symbol.flags = BSF_LOCAL;
4837
#endif
4838
59
        if (src->u.syment.n_sclass == C_WEAKEXT
4839
#ifdef RS6000COFF_C
4840
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4841
#endif
4842
59
      )
4843
5
    dst->symbol.flags |= BSF_WEAK;
4844
4845
59
        break;
4846
4847
58
      case C_STAT:  /* Static.  */
4848
#if defined ARM
4849
      case C_THUMBSTAT:    /* Thumb static.  */
4850
      case C_THUMBLABEL:   /* Thumb label.  */
4851
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4852
#endif
4853
#ifdef RS6000COFF_C
4854
      case C_DWARF:  /* A label in a dwarf section.  */
4855
      case C_INFO:   /* A label in a comment section.  */
4856
#endif
4857
63
      case C_LABEL:  /* Label.  */
4858
63
        if (src->u.syment.n_scnum == N_DEBUG)
4859
0
    dst->symbol.flags = BSF_DEBUGGING;
4860
63
        else
4861
63
    dst->symbol.flags = BSF_LOCAL;
4862
4863
        /* Base the value as an index from the base of the
4864
     section, if there is one.  */
4865
63
        if (dst->symbol.section)
4866
63
    {
4867
#if defined COFF_WITH_PE
4868
      /* PE sets the symbol to a value relative to the
4869
         start of the section.  */
4870
      dst->symbol.value = src->u.syment.n_value;
4871
#else
4872
63
      dst->symbol.value = (src->u.syment.n_value
4873
63
               - dst->symbol.section->vma);
4874
63
#endif
4875
63
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
63
        break;
4879
4880
20
      case C_FILE: /* File name.  */
4881
20
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
34
      case C_MOS:   /* Member of structure.  */
4884
36
      case C_EOS:   /* End of structure.  */
4885
41
      case C_REGPARM: /* Register parameter.  */
4886
584
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
598
      case C_TPDEF: /* Type definition.  */
4889
613
      case C_ARG:
4890
1.11k
      case C_AUTO: /* Automatic variable.  */
4891
1.12k
      case C_FIELD: /* Bit field.  */
4892
1.13k
      case C_ENTAG: /* Enumeration tag.  */
4893
1.15k
      case C_MOE:   /* Member of enumeration.  */
4894
1.31k
      case C_MOU:   /* Member of union.  */
4895
1.32k
      case C_UNTAG: /* Union tag.  */
4896
1.35k
      case C_STRTAG: /* Structure tag.  */
4897
#ifdef RS6000COFF_C
4898
      case C_GSYM:
4899
      case C_LSYM:
4900
      case C_PSYM:
4901
      case C_RSYM:
4902
      case C_RPSYM:
4903
      case C_STSYM:
4904
      case C_TCSYM:
4905
      case C_BCOMM:
4906
      case C_ECOML:
4907
      case C_ECOMM:
4908
      case C_DECL:
4909
      case C_ENTRY:
4910
      case C_FUN:
4911
      case C_ESTAT:
4912
#endif
4913
1.35k
        dst->symbol.flags |= BSF_DEBUGGING;
4914
1.35k
        dst->symbol.value = (src->u.syment.n_value);
4915
1.35k
        break;
4916
4917
#ifdef RS6000COFF_C
4918
      case C_BINCL: /* Beginning of include file.  */
4919
      case C_EINCL: /* Ending of include file.  */
4920
        /* The value is actually a pointer into the line numbers
4921
     of the file.  We locate the line number entry, and
4922
     set the section to the section which contains it, and
4923
     the value to the index in that section.  */
4924
        {
4925
    asection *sec;
4926
4927
    dst->symbol.flags = BSF_DEBUGGING;
4928
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4929
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4930
          && ((file_ptr) (sec->line_filepos
4931
              + sec->lineno_count * bfd_coff_linesz (abfd))
4932
        > (file_ptr) src->u.syment.n_value))
4933
        break;
4934
    if (sec == NULL)
4935
      dst->symbol.value = 0;
4936
    else
4937
      {
4938
        dst->symbol.section = sec;
4939
        dst->symbol.value = ((src->u.syment.n_value
4940
            - sec->line_filepos)
4941
           / bfd_coff_linesz (abfd));
4942
        src->fix_line = 1;
4943
      }
4944
        }
4945
        break;
4946
4947
      case C_BSTAT:
4948
        dst->symbol.flags = BSF_DEBUGGING;
4949
4950
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4951
    dst->symbol.value = 0;
4952
        else
4953
    {
4954
      /* The value is actually a symbol index.  Save a pointer
4955
         to the symbol instead of the index.  FIXME: This
4956
         should use a union.  */
4957
      src->u.syment.n_value
4958
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4959
      dst->symbol.value = src->u.syment.n_value;
4960
      src->fix_value = 1;
4961
    }
4962
        break;
4963
#endif
4964
4965
4
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
11
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
54
      case C_EFCN: /* Physical end of function.  */
4968
#if defined COFF_WITH_PE
4969
        /* PE sets the symbol to a value relative to the start
4970
     of the section.  */
4971
        dst->symbol.value = src->u.syment.n_value;
4972
        if (strcmp (dst->symbol.name, ".bf") != 0)
4973
    {
4974
      /* PE uses funny values for .ef and .lf; don't
4975
         relocate them.  */
4976
      dst->symbol.flags = BSF_DEBUGGING;
4977
    }
4978
        else
4979
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4980
#else
4981
        /* Base the value as an index from the base of the
4982
     section.  */
4983
54
        dst->symbol.flags = BSF_LOCAL;
4984
54
        dst->symbol.value = (src->u.syment.n_value
4985
54
           - dst->symbol.section->vma);
4986
54
#endif
4987
54
        break;
4988
4989
11
      case C_STATLAB: /* Static load time label.  */
4990
11
        dst->symbol.value = src->u.syment.n_value;
4991
11
        dst->symbol.flags = BSF_GLOBAL;
4992
11
        break;
4993
4994
6.16k
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
6.16k
        if (src->u.syment.n_type == 0
4998
6.16k
      && src->u.syment.n_value == 0
4999
6.16k
      && src->u.syment.n_scnum == 0)
5000
3.73k
    break;
5001
#ifdef RS6000COFF_C
5002
        /* XCOFF specific: deleted entry.  */
5003
        if (src->u.syment.n_value == C_NULL_VALUE)
5004
    break;
5005
#endif
5006
        /* Fall through.  */
5007
2.44k
      case C_EXTDEF: /* External definition.  */
5008
2.44k
      case C_ULABEL: /* Undefined label.  */
5009
2.45k
      case C_USTATIC: /* Undefined static.  */
5010
2.45k
#ifndef COFF_WITH_PE
5011
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5012
         class to represent a section symbol.  */
5013
2.46k
      case C_LINE: /* line # reformatted as symbol table entry.  */
5014
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5015
2.46k
      case C_ALIAS: /* Duplicate tag.  */
5016
2.46k
#endif
5017
        /* New storage classes for TI COFF.  */
5018
#ifdef TICOFF
5019
      case C_UEXT:  /* Tentative external definition.  */
5020
#endif
5021
2.46k
      case C_EXTLAB: /* External load time label.  */
5022
3.26k
      default:
5023
3.26k
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
3.26k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
3.26k
     abfd, src->u.syment.n_sclass,
5027
3.26k
     dst->symbol.section->name, dst->symbol.name);
5028
3.26k
        ret = false;
5029
        /* Fall through.  */
5030
3.27k
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5031
        /* PR 20722: These symbols can also be generated by
5032
     building DLLs with --gc-sections enabled.  */
5033
3.27k
        dst->symbol.flags = BSF_DEBUGGING;
5034
3.27k
        dst->symbol.value = (src->u.syment.n_value);
5035
3.27k
        break;
5036
8.54k
      }
5037
5038
8.54k
    dst->native = src;
5039
8.54k
    dst->symbol.udata.i = 0;
5040
8.54k
    dst->lineno = NULL;
5041
5042
8.54k
    this_index += (src->u.syment.n_numaux) + 1;
5043
8.54k
    dst++;
5044
8.54k
    number_of_symbols++;
5045
8.54k
  }
5046
20
    }
5047
5048
20
  obj_symbols (abfd) = cached_area;
5049
20
  obj_raw_syments (abfd) = native_symbols;
5050
5051
20
  abfd->symcount = number_of_symbols;
5052
20
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
20
  {
5055
20
    asection *p;
5056
5057
20
    p = abfd->sections;
5058
83
    while (p)
5059
82
      {
5060
82
  if (! coff_slurp_line_table (abfd, p))
5061
19
    return false;
5062
63
  p = p->next;
5063
63
      }
5064
20
  }
5065
5066
1
  return ret;
5067
20
}
Unexecuted instantiation: coff-tic4x.c:coff_slurp_symbol_table
coff-tic54x.c:coff_slurp_symbol_table
Line
Count
Source
4695
68
{
4696
68
  combined_entry_type *native_symbols;
4697
68
  coff_symbol_type *cached_area;
4698
68
  unsigned int *table_ptr;
4699
68
  unsigned int number_of_symbols = 0;
4700
68
  bool ret = true;
4701
68
  size_t amt;
4702
4703
68
  if (obj_symbols (abfd))
4704
0
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
68
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
23
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
45
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
45
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
45
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
45
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
45
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
45
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
45
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
45
  if (table_ptr == NULL)
4729
0
    return false;
4730
45
  else
4731
45
    {
4732
45
      coff_symbol_type *dst = cached_area;
4733
45
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
45
      unsigned int this_index = 0;
4735
4736
19.0k
      while (this_index < last_native_index)
4737
19.0k
  {
4738
19.0k
    combined_entry_type *src = native_symbols + this_index;
4739
19.0k
    table_ptr[this_index] = number_of_symbols;
4740
4741
19.0k
    dst->symbol.the_bfd = abfd;
4742
19.0k
    BFD_ASSERT (src->is_sym);
4743
19.0k
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4744
    /* We use the native name field to point to the cached field.  */
4745
19.0k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
19.0k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
19.0k
                 src->u.syment.n_scnum);
4748
19.0k
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
19.0k
    dst->symbol.value = 0;
4751
19.0k
    dst->done_lineno = false;
4752
4753
19.0k
    switch (src->u.syment.n_sclass)
4754
19.0k
      {
4755
330
      case C_EXT:
4756
340
      case C_WEAKEXT:
4757
#if defined ARM
4758
      case C_THUMBEXT:
4759
      case C_THUMBEXTFUNC:
4760
#endif
4761
#ifdef RS6000COFF_C
4762
      case C_HIDEXT:
4763
#ifndef AIX_WEAK_SUPPORT
4764
      case C_AIX_WEAKEXT:
4765
#endif
4766
#endif
4767
340
#ifdef C_SYSTEM
4768
353
      case C_SYSTEM: /* System Wide variable.  */
4769
353
#endif
4770
#ifdef COFF_WITH_PE
4771
      /* In PE, 0x68 (104) denotes a section symbol.  */
4772
      case C_SECTION:
4773
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4774
      case C_NT_WEAK:
4775
#endif
4776
353
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
353
    {
4778
280
    case COFF_SYMBOL_GLOBAL:
4779
280
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4780
#if defined COFF_WITH_PE
4781
      /* PE sets the symbol to a value relative to the
4782
         start of the section.  */
4783
      dst->symbol.value = src->u.syment.n_value;
4784
#else
4785
280
      dst->symbol.value = (src->u.syment.n_value
4786
280
               - dst->symbol.section->vma);
4787
280
#endif
4788
280
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
3
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
280
      break;
4793
4794
60
    case COFF_SYMBOL_COMMON:
4795
60
      dst->symbol.section = bfd_com_section_ptr;
4796
60
      dst->symbol.value = src->u.syment.n_value;
4797
60
      break;
4798
4799
13
    case COFF_SYMBOL_UNDEFINED:
4800
13
      dst->symbol.section = bfd_und_section_ptr;
4801
13
      dst->symbol.value = 0;
4802
13
      break;
4803
4804
0
    case COFF_SYMBOL_PE_SECTION:
4805
0
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4806
0
      dst->symbol.value = 0;
4807
0
      break;
4808
4809
0
    case COFF_SYMBOL_LOCAL:
4810
0
      dst->symbol.flags = BSF_LOCAL;
4811
#if defined COFF_WITH_PE
4812
      /* PE sets the symbol to a value relative to the
4813
         start of the section.  */
4814
      dst->symbol.value = src->u.syment.n_value;
4815
#else
4816
0
      dst->symbol.value = (src->u.syment.n_value
4817
0
               - dst->symbol.section->vma);
4818
0
#endif
4819
0
      if (ISFCN ((src->u.syment.n_type)))
4820
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4821
0
      break;
4822
353
    }
4823
4824
#ifdef RS6000COFF_C
4825
        /* A symbol with a csect entry should not go at the end.  */
4826
        if (src->u.syment.n_numaux > 0)
4827
    dst->symbol.flags |= BSF_NOT_AT_END;
4828
#endif
4829
4830
#ifdef COFF_WITH_PE
4831
        if (src->u.syment.n_sclass == C_NT_WEAK)
4832
    dst->symbol.flags |= BSF_WEAK;
4833
4834
        if (src->u.syment.n_sclass == C_SECTION
4835
      && src->u.syment.n_scnum > 0)
4836
    dst->symbol.flags = BSF_LOCAL;
4837
#endif
4838
353
        if (src->u.syment.n_sclass == C_WEAKEXT
4839
#ifdef RS6000COFF_C
4840
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4841
#endif
4842
353
      )
4843
10
    dst->symbol.flags |= BSF_WEAK;
4844
4845
353
        break;
4846
4847
222
      case C_STAT:  /* Static.  */
4848
#if defined ARM
4849
      case C_THUMBSTAT:    /* Thumb static.  */
4850
      case C_THUMBLABEL:   /* Thumb label.  */
4851
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4852
#endif
4853
#ifdef RS6000COFF_C
4854
      case C_DWARF:  /* A label in a dwarf section.  */
4855
      case C_INFO:   /* A label in a comment section.  */
4856
#endif
4857
259
      case C_LABEL:  /* Label.  */
4858
259
        if (src->u.syment.n_scnum == N_DEBUG)
4859
0
    dst->symbol.flags = BSF_DEBUGGING;
4860
259
        else
4861
259
    dst->symbol.flags = BSF_LOCAL;
4862
4863
        /* Base the value as an index from the base of the
4864
     section, if there is one.  */
4865
259
        if (dst->symbol.section)
4866
259
    {
4867
#if defined COFF_WITH_PE
4868
      /* PE sets the symbol to a value relative to the
4869
         start of the section.  */
4870
      dst->symbol.value = src->u.syment.n_value;
4871
#else
4872
259
      dst->symbol.value = (src->u.syment.n_value
4873
259
               - dst->symbol.section->vma);
4874
259
#endif
4875
259
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
259
        break;
4879
4880
72
      case C_FILE: /* File name.  */
4881
72
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
127
      case C_MOS:   /* Member of structure.  */
4884
146
      case C_EOS:   /* End of structure.  */
4885
155
      case C_REGPARM: /* Register parameter.  */
4886
196
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
230
      case C_TPDEF: /* Type definition.  */
4889
265
      case C_ARG:
4890
1.29k
      case C_AUTO: /* Automatic variable.  */
4891
1.32k
      case C_FIELD: /* Bit field.  */
4892
1.36k
      case C_ENTAG: /* Enumeration tag.  */
4893
1.52k
      case C_MOE:   /* Member of enumeration.  */
4894
1.61k
      case C_MOU:   /* Member of union.  */
4895
2.11k
      case C_UNTAG: /* Union tag.  */
4896
2.19k
      case C_STRTAG: /* Structure tag.  */
4897
#ifdef RS6000COFF_C
4898
      case C_GSYM:
4899
      case C_LSYM:
4900
      case C_PSYM:
4901
      case C_RSYM:
4902
      case C_RPSYM:
4903
      case C_STSYM:
4904
      case C_TCSYM:
4905
      case C_BCOMM:
4906
      case C_ECOML:
4907
      case C_ECOMM:
4908
      case C_DECL:
4909
      case C_ENTRY:
4910
      case C_FUN:
4911
      case C_ESTAT:
4912
#endif
4913
2.19k
        dst->symbol.flags |= BSF_DEBUGGING;
4914
2.19k
        dst->symbol.value = (src->u.syment.n_value);
4915
2.19k
        break;
4916
4917
#ifdef RS6000COFF_C
4918
      case C_BINCL: /* Beginning of include file.  */
4919
      case C_EINCL: /* Ending of include file.  */
4920
        /* The value is actually a pointer into the line numbers
4921
     of the file.  We locate the line number entry, and
4922
     set the section to the section which contains it, and
4923
     the value to the index in that section.  */
4924
        {
4925
    asection *sec;
4926
4927
    dst->symbol.flags = BSF_DEBUGGING;
4928
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4929
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4930
          && ((file_ptr) (sec->line_filepos
4931
              + sec->lineno_count * bfd_coff_linesz (abfd))
4932
        > (file_ptr) src->u.syment.n_value))
4933
        break;
4934
    if (sec == NULL)
4935
      dst->symbol.value = 0;
4936
    else
4937
      {
4938
        dst->symbol.section = sec;
4939
        dst->symbol.value = ((src->u.syment.n_value
4940
            - sec->line_filepos)
4941
           / bfd_coff_linesz (abfd));
4942
        src->fix_line = 1;
4943
      }
4944
        }
4945
        break;
4946
4947
      case C_BSTAT:
4948
        dst->symbol.flags = BSF_DEBUGGING;
4949
4950
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4951
    dst->symbol.value = 0;
4952
        else
4953
    {
4954
      /* The value is actually a symbol index.  Save a pointer
4955
         to the symbol instead of the index.  FIXME: This
4956
         should use a union.  */
4957
      src->u.syment.n_value
4958
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4959
      dst->symbol.value = src->u.syment.n_value;
4960
      src->fix_value = 1;
4961
    }
4962
        break;
4963
#endif
4964
4965
18
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
58
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
157
      case C_EFCN: /* Physical end of function.  */
4968
#if defined COFF_WITH_PE
4969
        /* PE sets the symbol to a value relative to the start
4970
     of the section.  */
4971
        dst->symbol.value = src->u.syment.n_value;
4972
        if (strcmp (dst->symbol.name, ".bf") != 0)
4973
    {
4974
      /* PE uses funny values for .ef and .lf; don't
4975
         relocate them.  */
4976
      dst->symbol.flags = BSF_DEBUGGING;
4977
    }
4978
        else
4979
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4980
#else
4981
        /* Base the value as an index from the base of the
4982
     section.  */
4983
157
        dst->symbol.flags = BSF_LOCAL;
4984
157
        dst->symbol.value = (src->u.syment.n_value
4985
157
           - dst->symbol.section->vma);
4986
157
#endif
4987
157
        break;
4988
4989
8
      case C_STATLAB: /* Static load time label.  */
4990
8
        dst->symbol.value = src->u.syment.n_value;
4991
8
        dst->symbol.flags = BSF_GLOBAL;
4992
8
        break;
4993
4994
13.3k
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
13.3k
        if (src->u.syment.n_type == 0
4998
13.3k
      && src->u.syment.n_value == 0
4999
13.3k
      && src->u.syment.n_scnum == 0)
5000
5.66k
    break;
5001
#ifdef RS6000COFF_C
5002
        /* XCOFF specific: deleted entry.  */
5003
        if (src->u.syment.n_value == C_NULL_VALUE)
5004
    break;
5005
#endif
5006
        /* Fall through.  */
5007
7.67k
      case C_EXTDEF: /* External definition.  */
5008
7.69k
      case C_ULABEL: /* Undefined label.  */
5009
7.69k
      case C_USTATIC: /* Undefined static.  */
5010
7.69k
#ifndef COFF_WITH_PE
5011
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5012
         class to represent a section symbol.  */
5013
7.70k
      case C_LINE: /* line # reformatted as symbol table entry.  */
5014
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5015
7.70k
      case C_ALIAS: /* Duplicate tag.  */
5016
7.70k
#endif
5017
        /* New storage classes for TI COFF.  */
5018
7.70k
#ifdef TICOFF
5019
7.73k
      case C_UEXT: /* Tentative external definition.  */
5020
7.73k
#endif
5021
7.74k
      case C_EXTLAB: /* External load time label.  */
5022
10.3k
      default:
5023
10.3k
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
10.3k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
10.3k
     abfd, src->u.syment.n_sclass,
5027
10.3k
     dst->symbol.section->name, dst->symbol.name);
5028
10.3k
        ret = false;
5029
        /* Fall through.  */
5030
10.3k
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5031
        /* PR 20722: These symbols can also be generated by
5032
     building DLLs with --gc-sections enabled.  */
5033
10.3k
        dst->symbol.flags = BSF_DEBUGGING;
5034
10.3k
        dst->symbol.value = (src->u.syment.n_value);
5035
10.3k
        break;
5036
19.0k
      }
5037
5038
19.0k
    dst->native = src;
5039
19.0k
    dst->symbol.udata.i = 0;
5040
19.0k
    dst->lineno = NULL;
5041
5042
19.0k
    this_index += (src->u.syment.n_numaux) + 1;
5043
19.0k
    dst++;
5044
19.0k
    number_of_symbols++;
5045
19.0k
  }
5046
45
    }
5047
5048
45
  obj_symbols (abfd) = cached_area;
5049
45
  obj_raw_syments (abfd) = native_symbols;
5050
5051
45
  abfd->symcount = number_of_symbols;
5052
45
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
45
  {
5055
45
    asection *p;
5056
5057
45
    p = abfd->sections;
5058
77
    while (p)
5059
71
      {
5060
71
  if (! coff_slurp_line_table (abfd, p))
5061
39
    return false;
5062
32
  p = p->next;
5063
32
      }
5064
45
  }
5065
5066
6
  return ret;
5067
45
}
coff-z80.c:coff_slurp_symbol_table
Line
Count
Source
4695
42
{
4696
42
  combined_entry_type *native_symbols;
4697
42
  coff_symbol_type *cached_area;
4698
42
  unsigned int *table_ptr;
4699
42
  unsigned int number_of_symbols = 0;
4700
42
  bool ret = true;
4701
42
  size_t amt;
4702
4703
42
  if (obj_symbols (abfd))
4704
0
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
42
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
13
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
29
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
29
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
29
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
29
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
29
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
29
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
29
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
29
  if (table_ptr == NULL)
4729
0
    return false;
4730
29
  else
4731
29
    {
4732
29
      coff_symbol_type *dst = cached_area;
4733
29
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
29
      unsigned int this_index = 0;
4735
4736
13.5k
      while (this_index < last_native_index)
4737
13.5k
  {
4738
13.5k
    combined_entry_type *src = native_symbols + this_index;
4739
13.5k
    table_ptr[this_index] = number_of_symbols;
4740
4741
13.5k
    dst->symbol.the_bfd = abfd;
4742
13.5k
    BFD_ASSERT (src->is_sym);
4743
13.5k
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4744
    /* We use the native name field to point to the cached field.  */
4745
13.5k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
13.5k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
13.5k
                 src->u.syment.n_scnum);
4748
13.5k
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
13.5k
    dst->symbol.value = 0;
4751
13.5k
    dst->done_lineno = false;
4752
4753
13.5k
    switch (src->u.syment.n_sclass)
4754
13.5k
      {
4755
852
      case C_EXT:
4756
858
      case C_WEAKEXT:
4757
#if defined ARM
4758
      case C_THUMBEXT:
4759
      case C_THUMBEXTFUNC:
4760
#endif
4761
#ifdef RS6000COFF_C
4762
      case C_HIDEXT:
4763
#ifndef AIX_WEAK_SUPPORT
4764
      case C_AIX_WEAKEXT:
4765
#endif
4766
#endif
4767
858
#ifdef C_SYSTEM
4768
863
      case C_SYSTEM: /* System Wide variable.  */
4769
863
#endif
4770
#ifdef COFF_WITH_PE
4771
      /* In PE, 0x68 (104) denotes a section symbol.  */
4772
      case C_SECTION:
4773
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4774
      case C_NT_WEAK:
4775
#endif
4776
863
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
863
    {
4778
792
    case COFF_SYMBOL_GLOBAL:
4779
792
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4780
#if defined COFF_WITH_PE
4781
      /* PE sets the symbol to a value relative to the
4782
         start of the section.  */
4783
      dst->symbol.value = src->u.syment.n_value;
4784
#else
4785
792
      dst->symbol.value = (src->u.syment.n_value
4786
792
               - dst->symbol.section->vma);
4787
792
#endif
4788
792
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
6
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
792
      break;
4793
4794
57
    case COFF_SYMBOL_COMMON:
4795
57
      dst->symbol.section = bfd_com_section_ptr;
4796
57
      dst->symbol.value = src->u.syment.n_value;
4797
57
      break;
4798
4799
14
    case COFF_SYMBOL_UNDEFINED:
4800
14
      dst->symbol.section = bfd_und_section_ptr;
4801
14
      dst->symbol.value = 0;
4802
14
      break;
4803
4804
0
    case COFF_SYMBOL_PE_SECTION:
4805
0
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4806
0
      dst->symbol.value = 0;
4807
0
      break;
4808
4809
0
    case COFF_SYMBOL_LOCAL:
4810
0
      dst->symbol.flags = BSF_LOCAL;
4811
#if defined COFF_WITH_PE
4812
      /* PE sets the symbol to a value relative to the
4813
         start of the section.  */
4814
      dst->symbol.value = src->u.syment.n_value;
4815
#else
4816
0
      dst->symbol.value = (src->u.syment.n_value
4817
0
               - dst->symbol.section->vma);
4818
0
#endif
4819
0
      if (ISFCN ((src->u.syment.n_type)))
4820
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4821
0
      break;
4822
863
    }
4823
4824
#ifdef RS6000COFF_C
4825
        /* A symbol with a csect entry should not go at the end.  */
4826
        if (src->u.syment.n_numaux > 0)
4827
    dst->symbol.flags |= BSF_NOT_AT_END;
4828
#endif
4829
4830
#ifdef COFF_WITH_PE
4831
        if (src->u.syment.n_sclass == C_NT_WEAK)
4832
    dst->symbol.flags |= BSF_WEAK;
4833
4834
        if (src->u.syment.n_sclass == C_SECTION
4835
      && src->u.syment.n_scnum > 0)
4836
    dst->symbol.flags = BSF_LOCAL;
4837
#endif
4838
863
        if (src->u.syment.n_sclass == C_WEAKEXT
4839
#ifdef RS6000COFF_C
4840
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4841
#endif
4842
863
      )
4843
6
    dst->symbol.flags |= BSF_WEAK;
4844
4845
863
        break;
4846
4847
72
      case C_STAT:  /* Static.  */
4848
#if defined ARM
4849
      case C_THUMBSTAT:    /* Thumb static.  */
4850
      case C_THUMBLABEL:   /* Thumb label.  */
4851
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4852
#endif
4853
#ifdef RS6000COFF_C
4854
      case C_DWARF:  /* A label in a dwarf section.  */
4855
      case C_INFO:   /* A label in a comment section.  */
4856
#endif
4857
93
      case C_LABEL:  /* Label.  */
4858
93
        if (src->u.syment.n_scnum == N_DEBUG)
4859
0
    dst->symbol.flags = BSF_DEBUGGING;
4860
93
        else
4861
93
    dst->symbol.flags = BSF_LOCAL;
4862
4863
        /* Base the value as an index from the base of the
4864
     section, if there is one.  */
4865
93
        if (dst->symbol.section)
4866
93
    {
4867
#if defined COFF_WITH_PE
4868
      /* PE sets the symbol to a value relative to the
4869
         start of the section.  */
4870
      dst->symbol.value = src->u.syment.n_value;
4871
#else
4872
93
      dst->symbol.value = (src->u.syment.n_value
4873
93
               - dst->symbol.section->vma);
4874
93
#endif
4875
93
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
93
        break;
4879
4880
29
      case C_FILE: /* File name.  */
4881
29
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
110
      case C_MOS:   /* Member of structure.  */
4884
112
      case C_EOS:   /* End of structure.  */
4885
151
      case C_REGPARM: /* Register parameter.  */
4886
211
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
267
      case C_TPDEF: /* Type definition.  */
4889
338
      case C_ARG:
4890
800
      case C_AUTO: /* Automatic variable.  */
4891
867
      case C_FIELD: /* Bit field.  */
4892
907
      case C_ENTAG: /* Enumeration tag.  */
4893
1.05k
      case C_MOE:   /* Member of enumeration.  */
4894
1.09k
      case C_MOU:   /* Member of union.  */
4895
1.13k
      case C_UNTAG: /* Union tag.  */
4896
1.24k
      case C_STRTAG: /* Structure tag.  */
4897
#ifdef RS6000COFF_C
4898
      case C_GSYM:
4899
      case C_LSYM:
4900
      case C_PSYM:
4901
      case C_RSYM:
4902
      case C_RPSYM:
4903
      case C_STSYM:
4904
      case C_TCSYM:
4905
      case C_BCOMM:
4906
      case C_ECOML:
4907
      case C_ECOMM:
4908
      case C_DECL:
4909
      case C_ENTRY:
4910
      case C_FUN:
4911
      case C_ESTAT:
4912
#endif
4913
1.24k
        dst->symbol.flags |= BSF_DEBUGGING;
4914
1.24k
        dst->symbol.value = (src->u.syment.n_value);
4915
1.24k
        break;
4916
4917
#ifdef RS6000COFF_C
4918
      case C_BINCL: /* Beginning of include file.  */
4919
      case C_EINCL: /* Ending of include file.  */
4920
        /* The value is actually a pointer into the line numbers
4921
     of the file.  We locate the line number entry, and
4922
     set the section to the section which contains it, and
4923
     the value to the index in that section.  */
4924
        {
4925
    asection *sec;
4926
4927
    dst->symbol.flags = BSF_DEBUGGING;
4928
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4929
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4930
          && ((file_ptr) (sec->line_filepos
4931
              + sec->lineno_count * bfd_coff_linesz (abfd))
4932
        > (file_ptr) src->u.syment.n_value))
4933
        break;
4934
    if (sec == NULL)
4935
      dst->symbol.value = 0;
4936
    else
4937
      {
4938
        dst->symbol.section = sec;
4939
        dst->symbol.value = ((src->u.syment.n_value
4940
            - sec->line_filepos)
4941
           / bfd_coff_linesz (abfd));
4942
        src->fix_line = 1;
4943
      }
4944
        }
4945
        break;
4946
4947
      case C_BSTAT:
4948
        dst->symbol.flags = BSF_DEBUGGING;
4949
4950
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4951
    dst->symbol.value = 0;
4952
        else
4953
    {
4954
      /* The value is actually a symbol index.  Save a pointer
4955
         to the symbol instead of the index.  FIXME: This
4956
         should use a union.  */
4957
      src->u.syment.n_value
4958
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4959
      dst->symbol.value = src->u.syment.n_value;
4960
      src->fix_value = 1;
4961
    }
4962
        break;
4963
#endif
4964
4965
13
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
38
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
107
      case C_EFCN: /* Physical end of function.  */
4968
#if defined COFF_WITH_PE
4969
        /* PE sets the symbol to a value relative to the start
4970
     of the section.  */
4971
        dst->symbol.value = src->u.syment.n_value;
4972
        if (strcmp (dst->symbol.name, ".bf") != 0)
4973
    {
4974
      /* PE uses funny values for .ef and .lf; don't
4975
         relocate them.  */
4976
      dst->symbol.flags = BSF_DEBUGGING;
4977
    }
4978
        else
4979
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4980
#else
4981
        /* Base the value as an index from the base of the
4982
     section.  */
4983
107
        dst->symbol.flags = BSF_LOCAL;
4984
107
        dst->symbol.value = (src->u.syment.n_value
4985
107
           - dst->symbol.section->vma);
4986
107
#endif
4987
107
        break;
4988
4989
127
      case C_STATLAB: /* Static load time label.  */
4990
127
        dst->symbol.value = src->u.syment.n_value;
4991
127
        dst->symbol.flags = BSF_GLOBAL;
4992
127
        break;
4993
4994
9.75k
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
9.75k
        if (src->u.syment.n_type == 0
4998
9.75k
      && src->u.syment.n_value == 0
4999
9.75k
      && src->u.syment.n_scnum == 0)
5000
4.69k
    break;
5001
#ifdef RS6000COFF_C
5002
        /* XCOFF specific: deleted entry.  */
5003
        if (src->u.syment.n_value == C_NULL_VALUE)
5004
    break;
5005
#endif
5006
        /* Fall through.  */
5007
5.08k
      case C_EXTDEF: /* External definition.  */
5008
5.09k
      case C_ULABEL: /* Undefined label.  */
5009
5.10k
      case C_USTATIC: /* Undefined static.  */
5010
5.10k
#ifndef COFF_WITH_PE
5011
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5012
         class to represent a section symbol.  */
5013
5.11k
      case C_LINE: /* line # reformatted as symbol table entry.  */
5014
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5015
5.13k
      case C_ALIAS: /* Duplicate tag.  */
5016
5.13k
#endif
5017
        /* New storage classes for TI COFF.  */
5018
#ifdef TICOFF
5019
      case C_UEXT:  /* Tentative external definition.  */
5020
#endif
5021
5.14k
      case C_EXTLAB: /* External load time label.  */
5022
6.41k
      default:
5023
6.41k
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
6.41k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
6.41k
     abfd, src->u.syment.n_sclass,
5027
6.41k
     dst->symbol.section->name, dst->symbol.name);
5028
6.41k
        ret = false;
5029
        /* Fall through.  */
5030
6.42k
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5031
        /* PR 20722: These symbols can also be generated by
5032
     building DLLs with --gc-sections enabled.  */
5033
6.42k
        dst->symbol.flags = BSF_DEBUGGING;
5034
6.42k
        dst->symbol.value = (src->u.syment.n_value);
5035
6.42k
        break;
5036
13.5k
      }
5037
5038
13.5k
    dst->native = src;
5039
13.5k
    dst->symbol.udata.i = 0;
5040
13.5k
    dst->lineno = NULL;
5041
5042
13.5k
    this_index += (src->u.syment.n_numaux) + 1;
5043
13.5k
    dst++;
5044
13.5k
    number_of_symbols++;
5045
13.5k
  }
5046
29
    }
5047
5048
29
  obj_symbols (abfd) = cached_area;
5049
29
  obj_raw_syments (abfd) = native_symbols;
5050
5051
29
  abfd->symcount = number_of_symbols;
5052
29
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
29
  {
5055
29
    asection *p;
5056
5057
29
    p = abfd->sections;
5058
160
    while (p)
5059
157
      {
5060
157
  if (! coff_slurp_line_table (abfd, p))
5061
26
    return false;
5062
131
  p = p->next;
5063
131
      }
5064
29
  }
5065
5066
3
  return ret;
5067
29
}
coff-z8k.c:coff_slurp_symbol_table
Line
Count
Source
4695
55
{
4696
55
  combined_entry_type *native_symbols;
4697
55
  coff_symbol_type *cached_area;
4698
55
  unsigned int *table_ptr;
4699
55
  unsigned int number_of_symbols = 0;
4700
55
  bool ret = true;
4701
55
  size_t amt;
4702
4703
55
  if (obj_symbols (abfd))
4704
6
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
49
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
21
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
28
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
28
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
28
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
28
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
28
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
28
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
28
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
28
  if (table_ptr == NULL)
4729
0
    return false;
4730
28
  else
4731
28
    {
4732
28
      coff_symbol_type *dst = cached_area;
4733
28
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
28
      unsigned int this_index = 0;
4735
4736
6.85k
      while (this_index < last_native_index)
4737
6.83k
  {
4738
6.83k
    combined_entry_type *src = native_symbols + this_index;
4739
6.83k
    table_ptr[this_index] = number_of_symbols;
4740
4741
6.83k
    dst->symbol.the_bfd = abfd;
4742
6.83k
    BFD_ASSERT (src->is_sym);
4743
6.83k
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4744
    /* We use the native name field to point to the cached field.  */
4745
6.83k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
6.83k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
6.83k
                 src->u.syment.n_scnum);
4748
6.83k
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
6.83k
    dst->symbol.value = 0;
4751
6.83k
    dst->done_lineno = false;
4752
4753
6.83k
    switch (src->u.syment.n_sclass)
4754
6.83k
      {
4755
237
      case C_EXT:
4756
239
      case C_WEAKEXT:
4757
#if defined ARM
4758
      case C_THUMBEXT:
4759
      case C_THUMBEXTFUNC:
4760
#endif
4761
#ifdef RS6000COFF_C
4762
      case C_HIDEXT:
4763
#ifndef AIX_WEAK_SUPPORT
4764
      case C_AIX_WEAKEXT:
4765
#endif
4766
#endif
4767
239
#ifdef C_SYSTEM
4768
246
      case C_SYSTEM: /* System Wide variable.  */
4769
246
#endif
4770
#ifdef COFF_WITH_PE
4771
      /* In PE, 0x68 (104) denotes a section symbol.  */
4772
      case C_SECTION:
4773
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4774
      case C_NT_WEAK:
4775
#endif
4776
246
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
246
    {
4778
180
    case COFF_SYMBOL_GLOBAL:
4779
180
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4780
#if defined COFF_WITH_PE
4781
      /* PE sets the symbol to a value relative to the
4782
         start of the section.  */
4783
      dst->symbol.value = src->u.syment.n_value;
4784
#else
4785
180
      dst->symbol.value = (src->u.syment.n_value
4786
180
               - dst->symbol.section->vma);
4787
180
#endif
4788
180
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
5
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
180
      break;
4793
4794
52
    case COFF_SYMBOL_COMMON:
4795
52
      dst->symbol.section = bfd_com_section_ptr;
4796
52
      dst->symbol.value = src->u.syment.n_value;
4797
52
      break;
4798
4799
14
    case COFF_SYMBOL_UNDEFINED:
4800
14
      dst->symbol.section = bfd_und_section_ptr;
4801
14
      dst->symbol.value = 0;
4802
14
      break;
4803
4804
0
    case COFF_SYMBOL_PE_SECTION:
4805
0
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4806
0
      dst->symbol.value = 0;
4807
0
      break;
4808
4809
0
    case COFF_SYMBOL_LOCAL:
4810
0
      dst->symbol.flags = BSF_LOCAL;
4811
#if defined COFF_WITH_PE
4812
      /* PE sets the symbol to a value relative to the
4813
         start of the section.  */
4814
      dst->symbol.value = src->u.syment.n_value;
4815
#else
4816
0
      dst->symbol.value = (src->u.syment.n_value
4817
0
               - dst->symbol.section->vma);
4818
0
#endif
4819
0
      if (ISFCN ((src->u.syment.n_type)))
4820
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4821
0
      break;
4822
246
    }
4823
4824
#ifdef RS6000COFF_C
4825
        /* A symbol with a csect entry should not go at the end.  */
4826
        if (src->u.syment.n_numaux > 0)
4827
    dst->symbol.flags |= BSF_NOT_AT_END;
4828
#endif
4829
4830
#ifdef COFF_WITH_PE
4831
        if (src->u.syment.n_sclass == C_NT_WEAK)
4832
    dst->symbol.flags |= BSF_WEAK;
4833
4834
        if (src->u.syment.n_sclass == C_SECTION
4835
      && src->u.syment.n_scnum > 0)
4836
    dst->symbol.flags = BSF_LOCAL;
4837
#endif
4838
246
        if (src->u.syment.n_sclass == C_WEAKEXT
4839
#ifdef RS6000COFF_C
4840
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4841
#endif
4842
246
      )
4843
2
    dst->symbol.flags |= BSF_WEAK;
4844
4845
246
        break;
4846
4847
52
      case C_STAT:  /* Static.  */
4848
#if defined ARM
4849
      case C_THUMBSTAT:    /* Thumb static.  */
4850
      case C_THUMBLABEL:   /* Thumb label.  */
4851
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4852
#endif
4853
#ifdef RS6000COFF_C
4854
      case C_DWARF:  /* A label in a dwarf section.  */
4855
      case C_INFO:   /* A label in a comment section.  */
4856
#endif
4857
79
      case C_LABEL:  /* Label.  */
4858
79
        if (src->u.syment.n_scnum == N_DEBUG)
4859
0
    dst->symbol.flags = BSF_DEBUGGING;
4860
79
        else
4861
79
    dst->symbol.flags = BSF_LOCAL;
4862
4863
        /* Base the value as an index from the base of the
4864
     section, if there is one.  */
4865
79
        if (dst->symbol.section)
4866
79
    {
4867
#if defined COFF_WITH_PE
4868
      /* PE sets the symbol to a value relative to the
4869
         start of the section.  */
4870
      dst->symbol.value = src->u.syment.n_value;
4871
#else
4872
79
      dst->symbol.value = (src->u.syment.n_value
4873
79
               - dst->symbol.section->vma);
4874
79
#endif
4875
79
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
79
        break;
4879
4880
23
      case C_FILE: /* File name.  */
4881
23
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
31
      case C_MOS:   /* Member of structure.  */
4884
49
      case C_EOS:   /* End of structure.  */
4885
52
      case C_REGPARM: /* Register parameter.  */
4886
65
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
77
      case C_TPDEF: /* Type definition.  */
4889
326
      case C_ARG:
4890
765
      case C_AUTO: /* Automatic variable.  */
4891
772
      case C_FIELD: /* Bit field.  */
4892
779
      case C_ENTAG: /* Enumeration tag.  */
4893
811
      case C_MOE:   /* Member of enumeration.  */
4894
822
      case C_MOU:   /* Member of union.  */
4895
830
      case C_UNTAG: /* Union tag.  */
4896
979
      case C_STRTAG: /* Structure tag.  */
4897
#ifdef RS6000COFF_C
4898
      case C_GSYM:
4899
      case C_LSYM:
4900
      case C_PSYM:
4901
      case C_RSYM:
4902
      case C_RPSYM:
4903
      case C_STSYM:
4904
      case C_TCSYM:
4905
      case C_BCOMM:
4906
      case C_ECOML:
4907
      case C_ECOMM:
4908
      case C_DECL:
4909
      case C_ENTRY:
4910
      case C_FUN:
4911
      case C_ESTAT:
4912
#endif
4913
979
        dst->symbol.flags |= BSF_DEBUGGING;
4914
979
        dst->symbol.value = (src->u.syment.n_value);
4915
979
        break;
4916
4917
#ifdef RS6000COFF_C
4918
      case C_BINCL: /* Beginning of include file.  */
4919
      case C_EINCL: /* Ending of include file.  */
4920
        /* The value is actually a pointer into the line numbers
4921
     of the file.  We locate the line number entry, and
4922
     set the section to the section which contains it, and
4923
     the value to the index in that section.  */
4924
        {
4925
    asection *sec;
4926
4927
    dst->symbol.flags = BSF_DEBUGGING;
4928
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4929
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4930
          && ((file_ptr) (sec->line_filepos
4931
              + sec->lineno_count * bfd_coff_linesz (abfd))
4932
        > (file_ptr) src->u.syment.n_value))
4933
        break;
4934
    if (sec == NULL)
4935
      dst->symbol.value = 0;
4936
    else
4937
      {
4938
        dst->symbol.section = sec;
4939
        dst->symbol.value = ((src->u.syment.n_value
4940
            - sec->line_filepos)
4941
           / bfd_coff_linesz (abfd));
4942
        src->fix_line = 1;
4943
      }
4944
        }
4945
        break;
4946
4947
      case C_BSTAT:
4948
        dst->symbol.flags = BSF_DEBUGGING;
4949
4950
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4951
    dst->symbol.value = 0;
4952
        else
4953
    {
4954
      /* The value is actually a symbol index.  Save a pointer
4955
         to the symbol instead of the index.  FIXME: This
4956
         should use a union.  */
4957
      src->u.syment.n_value
4958
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4959
      dst->symbol.value = src->u.syment.n_value;
4960
      src->fix_value = 1;
4961
    }
4962
        break;
4963
#endif
4964
4965
8
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
18
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
71
      case C_EFCN: /* Physical end of function.  */
4968
#if defined COFF_WITH_PE
4969
        /* PE sets the symbol to a value relative to the start
4970
     of the section.  */
4971
        dst->symbol.value = src->u.syment.n_value;
4972
        if (strcmp (dst->symbol.name, ".bf") != 0)
4973
    {
4974
      /* PE uses funny values for .ef and .lf; don't
4975
         relocate them.  */
4976
      dst->symbol.flags = BSF_DEBUGGING;
4977
    }
4978
        else
4979
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4980
#else
4981
        /* Base the value as an index from the base of the
4982
     section.  */
4983
71
        dst->symbol.flags = BSF_LOCAL;
4984
71
        dst->symbol.value = (src->u.syment.n_value
4985
71
           - dst->symbol.section->vma);
4986
71
#endif
4987
71
        break;
4988
4989
6
      case C_STATLAB: /* Static load time label.  */
4990
6
        dst->symbol.value = src->u.syment.n_value;
4991
6
        dst->symbol.flags = BSF_GLOBAL;
4992
6
        break;
4993
4994
4.69k
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
4.69k
        if (src->u.syment.n_type == 0
4998
4.69k
      && src->u.syment.n_value == 0
4999
4.69k
      && src->u.syment.n_scnum == 0)
5000
1.58k
    break;
5001
#ifdef RS6000COFF_C
5002
        /* XCOFF specific: deleted entry.  */
5003
        if (src->u.syment.n_value == C_NULL_VALUE)
5004
    break;
5005
#endif
5006
        /* Fall through.  */
5007
3.13k
      case C_EXTDEF: /* External definition.  */
5008
3.14k
      case C_ULABEL: /* Undefined label.  */
5009
3.15k
      case C_USTATIC: /* Undefined static.  */
5010
3.15k
#ifndef COFF_WITH_PE
5011
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5012
         class to represent a section symbol.  */
5013
3.15k
      case C_LINE: /* line # reformatted as symbol table entry.  */
5014
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5015
3.15k
      case C_ALIAS: /* Duplicate tag.  */
5016
3.15k
#endif
5017
        /* New storage classes for TI COFF.  */
5018
#ifdef TICOFF
5019
      case C_UEXT:  /* Tentative external definition.  */
5020
#endif
5021
3.16k
      case C_EXTLAB: /* External load time label.  */
5022
3.85k
      default:
5023
3.85k
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
3.85k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
3.85k
     abfd, src->u.syment.n_sclass,
5027
3.85k
     dst->symbol.section->name, dst->symbol.name);
5028
3.85k
        ret = false;
5029
        /* Fall through.  */
5030
3.86k
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5031
        /* PR 20722: These symbols can also be generated by
5032
     building DLLs with --gc-sections enabled.  */
5033
3.86k
        dst->symbol.flags = BSF_DEBUGGING;
5034
3.86k
        dst->symbol.value = (src->u.syment.n_value);
5035
3.86k
        break;
5036
6.83k
      }
5037
5038
6.83k
    dst->native = src;
5039
6.83k
    dst->symbol.udata.i = 0;
5040
6.83k
    dst->lineno = NULL;
5041
5042
6.83k
    this_index += (src->u.syment.n_numaux) + 1;
5043
6.83k
    dst++;
5044
6.83k
    number_of_symbols++;
5045
6.83k
  }
5046
28
    }
5047
5048
28
  obj_symbols (abfd) = cached_area;
5049
28
  obj_raw_syments (abfd) = native_symbols;
5050
5051
28
  abfd->symcount = number_of_symbols;
5052
28
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
28
  {
5055
28
    asection *p;
5056
5057
28
    p = abfd->sections;
5058
1.66k
    while (p)
5059
1.65k
      {
5060
1.65k
  if (! coff_slurp_line_table (abfd, p))
5061
22
    return false;
5062
1.63k
  p = p->next;
5063
1.63k
      }
5064
28
  }
5065
5066
6
  return ret;
5067
28
}
Unexecuted instantiation: pe-arm-wince.c:coff_slurp_symbol_table
Unexecuted instantiation: pe-arm.c:coff_slurp_symbol_table
pe-i386.c:coff_slurp_symbol_table
Line
Count
Source
4695
54
{
4696
54
  combined_entry_type *native_symbols;
4697
54
  coff_symbol_type *cached_area;
4698
54
  unsigned int *table_ptr;
4699
54
  unsigned int number_of_symbols = 0;
4700
54
  bool ret = true;
4701
54
  size_t amt;
4702
4703
54
  if (obj_symbols (abfd))
4704
3
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
51
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
8
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
43
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
43
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
43
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
43
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
43
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
43
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
43
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
43
  if (table_ptr == NULL)
4729
0
    return false;
4730
43
  else
4731
43
    {
4732
43
      coff_symbol_type *dst = cached_area;
4733
43
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
43
      unsigned int this_index = 0;
4735
4736
7.36k
      while (this_index < last_native_index)
4737
7.31k
  {
4738
7.31k
    combined_entry_type *src = native_symbols + this_index;
4739
7.31k
    table_ptr[this_index] = number_of_symbols;
4740
4741
7.31k
    dst->symbol.the_bfd = abfd;
4742
7.31k
    BFD_ASSERT (src->is_sym);
4743
7.31k
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4744
    /* We use the native name field to point to the cached field.  */
4745
7.31k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
7.31k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
7.31k
                 src->u.syment.n_scnum);
4748
7.31k
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
7.31k
    dst->symbol.value = 0;
4751
7.31k
    dst->done_lineno = false;
4752
4753
7.31k
    switch (src->u.syment.n_sclass)
4754
7.31k
      {
4755
113
      case C_EXT:
4756
121
      case C_WEAKEXT:
4757
#if defined ARM
4758
      case C_THUMBEXT:
4759
      case C_THUMBEXTFUNC:
4760
#endif
4761
#ifdef RS6000COFF_C
4762
      case C_HIDEXT:
4763
#ifndef AIX_WEAK_SUPPORT
4764
      case C_AIX_WEAKEXT:
4765
#endif
4766
#endif
4767
121
#ifdef C_SYSTEM
4768
124
      case C_SYSTEM: /* System Wide variable.  */
4769
124
#endif
4770
124
#ifdef COFF_WITH_PE
4771
      /* In PE, 0x68 (104) denotes a section symbol.  */
4772
124
      case C_SECTION:
4773
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4774
133
      case C_NT_WEAK:
4775
133
#endif
4776
133
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
133
    {
4778
94
    case COFF_SYMBOL_GLOBAL:
4779
94
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4780
94
#if defined COFF_WITH_PE
4781
      /* PE sets the symbol to a value relative to the
4782
         start of the section.  */
4783
94
      dst->symbol.value = src->u.syment.n_value;
4784
#else
4785
      dst->symbol.value = (src->u.syment.n_value
4786
               - dst->symbol.section->vma);
4787
#endif
4788
94
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
5
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
94
      break;
4793
4794
23
    case COFF_SYMBOL_COMMON:
4795
23
      dst->symbol.section = bfd_com_section_ptr;
4796
23
      dst->symbol.value = src->u.syment.n_value;
4797
23
      break;
4798
4799
16
    case COFF_SYMBOL_UNDEFINED:
4800
16
      dst->symbol.section = bfd_und_section_ptr;
4801
16
      dst->symbol.value = 0;
4802
16
      break;
4803
4804
0
    case COFF_SYMBOL_PE_SECTION:
4805
0
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4806
0
      dst->symbol.value = 0;
4807
0
      break;
4808
4809
0
    case COFF_SYMBOL_LOCAL:
4810
0
      dst->symbol.flags = BSF_LOCAL;
4811
0
#if defined COFF_WITH_PE
4812
      /* PE sets the symbol to a value relative to the
4813
         start of the section.  */
4814
0
      dst->symbol.value = src->u.syment.n_value;
4815
#else
4816
      dst->symbol.value = (src->u.syment.n_value
4817
               - dst->symbol.section->vma);
4818
#endif
4819
0
      if (ISFCN ((src->u.syment.n_type)))
4820
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4821
0
      break;
4822
133
    }
4823
4824
#ifdef RS6000COFF_C
4825
        /* A symbol with a csect entry should not go at the end.  */
4826
        if (src->u.syment.n_numaux > 0)
4827
    dst->symbol.flags |= BSF_NOT_AT_END;
4828
#endif
4829
4830
133
#ifdef COFF_WITH_PE
4831
133
        if (src->u.syment.n_sclass == C_NT_WEAK)
4832
9
    dst->symbol.flags |= BSF_WEAK;
4833
4834
133
        if (src->u.syment.n_sclass == C_SECTION
4835
133
      && src->u.syment.n_scnum > 0)
4836
0
    dst->symbol.flags = BSF_LOCAL;
4837
133
#endif
4838
133
        if (src->u.syment.n_sclass == C_WEAKEXT
4839
#ifdef RS6000COFF_C
4840
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4841
#endif
4842
133
      )
4843
8
    dst->symbol.flags |= BSF_WEAK;
4844
4845
133
        break;
4846
4847
39
      case C_STAT:  /* Static.  */
4848
#if defined ARM
4849
      case C_THUMBSTAT:    /* Thumb static.  */
4850
      case C_THUMBLABEL:   /* Thumb label.  */
4851
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4852
#endif
4853
#ifdef RS6000COFF_C
4854
      case C_DWARF:  /* A label in a dwarf section.  */
4855
      case C_INFO:   /* A label in a comment section.  */
4856
#endif
4857
69
      case C_LABEL:  /* Label.  */
4858
69
        if (src->u.syment.n_scnum == N_DEBUG)
4859
0
    dst->symbol.flags = BSF_DEBUGGING;
4860
69
        else
4861
69
    dst->symbol.flags = BSF_LOCAL;
4862
4863
        /* Base the value as an index from the base of the
4864
     section, if there is one.  */
4865
69
        if (dst->symbol.section)
4866
69
    {
4867
69
#if defined COFF_WITH_PE
4868
      /* PE sets the symbol to a value relative to the
4869
         start of the section.  */
4870
69
      dst->symbol.value = src->u.syment.n_value;
4871
#else
4872
      dst->symbol.value = (src->u.syment.n_value
4873
               - dst->symbol.section->vma);
4874
#endif
4875
69
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
69
        break;
4879
4880
6
      case C_FILE: /* File name.  */
4881
6
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
28
      case C_MOS:   /* Member of structure.  */
4884
60
      case C_EOS:   /* End of structure.  */
4885
96
      case C_REGPARM: /* Register parameter.  */
4886
163
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
191
      case C_TPDEF: /* Type definition.  */
4889
207
      case C_ARG:
4890
329
      case C_AUTO: /* Automatic variable.  */
4891
483
      case C_FIELD: /* Bit field.  */
4892
531
      case C_ENTAG: /* Enumeration tag.  */
4893
576
      case C_MOE:   /* Member of enumeration.  */
4894
592
      case C_MOU:   /* Member of union.  */
4895
606
      case C_UNTAG: /* Union tag.  */
4896
620
      case C_STRTAG: /* Structure tag.  */
4897
#ifdef RS6000COFF_C
4898
      case C_GSYM:
4899
      case C_LSYM:
4900
      case C_PSYM:
4901
      case C_RSYM:
4902
      case C_RPSYM:
4903
      case C_STSYM:
4904
      case C_TCSYM:
4905
      case C_BCOMM:
4906
      case C_ECOML:
4907
      case C_ECOMM:
4908
      case C_DECL:
4909
      case C_ENTRY:
4910
      case C_FUN:
4911
      case C_ESTAT:
4912
#endif
4913
620
        dst->symbol.flags |= BSF_DEBUGGING;
4914
620
        dst->symbol.value = (src->u.syment.n_value);
4915
620
        break;
4916
4917
#ifdef RS6000COFF_C
4918
      case C_BINCL: /* Beginning of include file.  */
4919
      case C_EINCL: /* Ending of include file.  */
4920
        /* The value is actually a pointer into the line numbers
4921
     of the file.  We locate the line number entry, and
4922
     set the section to the section which contains it, and
4923
     the value to the index in that section.  */
4924
        {
4925
    asection *sec;
4926
4927
    dst->symbol.flags = BSF_DEBUGGING;
4928
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4929
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4930
          && ((file_ptr) (sec->line_filepos
4931
              + sec->lineno_count * bfd_coff_linesz (abfd))
4932
        > (file_ptr) src->u.syment.n_value))
4933
        break;
4934
    if (sec == NULL)
4935
      dst->symbol.value = 0;
4936
    else
4937
      {
4938
        dst->symbol.section = sec;
4939
        dst->symbol.value = ((src->u.syment.n_value
4940
            - sec->line_filepos)
4941
           / bfd_coff_linesz (abfd));
4942
        src->fix_line = 1;
4943
      }
4944
        }
4945
        break;
4946
4947
      case C_BSTAT:
4948
        dst->symbol.flags = BSF_DEBUGGING;
4949
4950
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4951
    dst->symbol.value = 0;
4952
        else
4953
    {
4954
      /* The value is actually a symbol index.  Save a pointer
4955
         to the symbol instead of the index.  FIXME: This
4956
         should use a union.  */
4957
      src->u.syment.n_value
4958
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4959
      dst->symbol.value = src->u.syment.n_value;
4960
      src->fix_value = 1;
4961
    }
4962
        break;
4963
#endif
4964
4965
6
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
13
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
75
      case C_EFCN: /* Physical end of function.  */
4968
75
#if defined COFF_WITH_PE
4969
        /* PE sets the symbol to a value relative to the start
4970
     of the section.  */
4971
75
        dst->symbol.value = src->u.syment.n_value;
4972
75
        if (strcmp (dst->symbol.name, ".bf") != 0)
4973
75
    {
4974
      /* PE uses funny values for .ef and .lf; don't
4975
         relocate them.  */
4976
75
      dst->symbol.flags = BSF_DEBUGGING;
4977
75
    }
4978
0
        else
4979
0
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4980
#else
4981
        /* Base the value as an index from the base of the
4982
     section.  */
4983
        dst->symbol.flags = BSF_LOCAL;
4984
        dst->symbol.value = (src->u.syment.n_value
4985
           - dst->symbol.section->vma);
4986
#endif
4987
75
        break;
4988
4989
14
      case C_STATLAB: /* Static load time label.  */
4990
14
        dst->symbol.value = src->u.syment.n_value;
4991
14
        dst->symbol.flags = BSF_GLOBAL;
4992
14
        break;
4993
4994
5.61k
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
5.61k
        if (src->u.syment.n_type == 0
4998
5.61k
      && src->u.syment.n_value == 0
4999
5.61k
      && src->u.syment.n_scnum == 0)
5000
3.50k
    break;
5001
#ifdef RS6000COFF_C
5002
        /* XCOFF specific: deleted entry.  */
5003
        if (src->u.syment.n_value == C_NULL_VALUE)
5004
    break;
5005
#endif
5006
        /* Fall through.  */
5007
2.12k
      case C_EXTDEF: /* External definition.  */
5008
2.13k
      case C_ULABEL: /* Undefined label.  */
5009
2.14k
      case C_USTATIC: /* Undefined static.  */
5010
#ifndef COFF_WITH_PE
5011
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5012
         class to represent a section symbol.  */
5013
      case C_LINE:  /* line # reformatted as symbol table entry.  */
5014
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5015
      case C_ALIAS: /* Duplicate tag.  */
5016
#endif
5017
        /* New storage classes for TI COFF.  */
5018
#ifdef TICOFF
5019
      case C_UEXT:  /* Tentative external definition.  */
5020
#endif
5021
2.14k
      case C_EXTLAB: /* External load time label.  */
5022
2.90k
      default:
5023
2.90k
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
2.90k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
2.90k
     abfd, src->u.syment.n_sclass,
5027
2.90k
     dst->symbol.section->name, dst->symbol.name);
5028
2.90k
        ret = false;
5029
        /* Fall through.  */
5030
2.90k
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5031
        /* PR 20722: These symbols can also be generated by
5032
     building DLLs with --gc-sections enabled.  */
5033
2.90k
        dst->symbol.flags = BSF_DEBUGGING;
5034
2.90k
        dst->symbol.value = (src->u.syment.n_value);
5035
2.90k
        break;
5036
7.31k
      }
5037
5038
7.31k
    dst->native = src;
5039
7.31k
    dst->symbol.udata.i = 0;
5040
7.31k
    dst->lineno = NULL;
5041
5042
7.31k
    this_index += (src->u.syment.n_numaux) + 1;
5043
7.31k
    dst++;
5044
7.31k
    number_of_symbols++;
5045
7.31k
  }
5046
43
    }
5047
5048
43
  obj_symbols (abfd) = cached_area;
5049
43
  obj_raw_syments (abfd) = native_symbols;
5050
5051
43
  abfd->symcount = number_of_symbols;
5052
43
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
43
  {
5055
43
    asection *p;
5056
5057
43
    p = abfd->sections;
5058
552
    while (p)
5059
545
      {
5060
545
  if (! coff_slurp_line_table (abfd, p))
5061
36
    return false;
5062
509
  p = p->next;
5063
509
      }
5064
43
  }
5065
5066
7
  return ret;
5067
43
}
pe-mcore.c:coff_slurp_symbol_table
Line
Count
Source
4695
40
{
4696
40
  combined_entry_type *native_symbols;
4697
40
  coff_symbol_type *cached_area;
4698
40
  unsigned int *table_ptr;
4699
40
  unsigned int number_of_symbols = 0;
4700
40
  bool ret = true;
4701
40
  size_t amt;
4702
4703
40
  if (obj_symbols (abfd))
4704
3
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
37
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
0
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
37
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
37
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
37
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
37
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
37
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
37
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
37
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
37
  if (table_ptr == NULL)
4729
0
    return false;
4730
37
  else
4731
37
    {
4732
37
      coff_symbol_type *dst = cached_area;
4733
37
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
37
      unsigned int this_index = 0;
4735
4736
55.6k
      while (this_index < last_native_index)
4737
55.5k
  {
4738
55.5k
    combined_entry_type *src = native_symbols + this_index;
4739
55.5k
    table_ptr[this_index] = number_of_symbols;
4740
4741
55.5k
    dst->symbol.the_bfd = abfd;
4742
55.5k
    BFD_ASSERT (src->is_sym);
4743
55.5k
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4744
    /* We use the native name field to point to the cached field.  */
4745
55.5k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
55.5k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
55.5k
                 src->u.syment.n_scnum);
4748
55.5k
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
55.5k
    dst->symbol.value = 0;
4751
55.5k
    dst->done_lineno = false;
4752
4753
55.5k
    switch (src->u.syment.n_sclass)
4754
55.5k
      {
4755
584
      case C_EXT:
4756
614
      case C_WEAKEXT:
4757
#if defined ARM
4758
      case C_THUMBEXT:
4759
      case C_THUMBEXTFUNC:
4760
#endif
4761
#ifdef RS6000COFF_C
4762
      case C_HIDEXT:
4763
#ifndef AIX_WEAK_SUPPORT
4764
      case C_AIX_WEAKEXT:
4765
#endif
4766
#endif
4767
614
#ifdef C_SYSTEM
4768
620
      case C_SYSTEM: /* System Wide variable.  */
4769
620
#endif
4770
620
#ifdef COFF_WITH_PE
4771
      /* In PE, 0x68 (104) denotes a section symbol.  */
4772
631
      case C_SECTION:
4773
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4774
649
      case C_NT_WEAK:
4775
649
#endif
4776
649
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
649
    {
4778
577
    case COFF_SYMBOL_GLOBAL:
4779
577
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4780
577
#if defined COFF_WITH_PE
4781
      /* PE sets the symbol to a value relative to the
4782
         start of the section.  */
4783
577
      dst->symbol.value = src->u.syment.n_value;
4784
#else
4785
      dst->symbol.value = (src->u.syment.n_value
4786
               - dst->symbol.section->vma);
4787
#endif
4788
577
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
9
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
577
      break;
4793
4794
38
    case COFF_SYMBOL_COMMON:
4795
38
      dst->symbol.section = bfd_com_section_ptr;
4796
38
      dst->symbol.value = src->u.syment.n_value;
4797
38
      break;
4798
4799
34
    case COFF_SYMBOL_UNDEFINED:
4800
34
      dst->symbol.section = bfd_und_section_ptr;
4801
34
      dst->symbol.value = 0;
4802
34
      break;
4803
4804
0
    case COFF_SYMBOL_PE_SECTION:
4805
0
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4806
0
      dst->symbol.value = 0;
4807
0
      break;
4808
4809
0
    case COFF_SYMBOL_LOCAL:
4810
0
      dst->symbol.flags = BSF_LOCAL;
4811
0
#if defined COFF_WITH_PE
4812
      /* PE sets the symbol to a value relative to the
4813
         start of the section.  */
4814
0
      dst->symbol.value = src->u.syment.n_value;
4815
#else
4816
      dst->symbol.value = (src->u.syment.n_value
4817
               - dst->symbol.section->vma);
4818
#endif
4819
0
      if (ISFCN ((src->u.syment.n_type)))
4820
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4821
0
      break;
4822
649
    }
4823
4824
#ifdef RS6000COFF_C
4825
        /* A symbol with a csect entry should not go at the end.  */
4826
        if (src->u.syment.n_numaux > 0)
4827
    dst->symbol.flags |= BSF_NOT_AT_END;
4828
#endif
4829
4830
649
#ifdef COFF_WITH_PE
4831
649
        if (src->u.syment.n_sclass == C_NT_WEAK)
4832
18
    dst->symbol.flags |= BSF_WEAK;
4833
4834
649
        if (src->u.syment.n_sclass == C_SECTION
4835
649
      && src->u.syment.n_scnum > 0)
4836
0
    dst->symbol.flags = BSF_LOCAL;
4837
649
#endif
4838
649
        if (src->u.syment.n_sclass == C_WEAKEXT
4839
#ifdef RS6000COFF_C
4840
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4841
#endif
4842
649
      )
4843
30
    dst->symbol.flags |= BSF_WEAK;
4844
4845
649
        break;
4846
4847
405
      case C_STAT:  /* Static.  */
4848
#if defined ARM
4849
      case C_THUMBSTAT:    /* Thumb static.  */
4850
      case C_THUMBLABEL:   /* Thumb label.  */
4851
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4852
#endif
4853
#ifdef RS6000COFF_C
4854
      case C_DWARF:  /* A label in a dwarf section.  */
4855
      case C_INFO:   /* A label in a comment section.  */
4856
#endif
4857
450
      case C_LABEL:  /* Label.  */
4858
450
        if (src->u.syment.n_scnum == N_DEBUG)
4859
0
    dst->symbol.flags = BSF_DEBUGGING;
4860
450
        else
4861
450
    dst->symbol.flags = BSF_LOCAL;
4862
4863
        /* Base the value as an index from the base of the
4864
     section, if there is one.  */
4865
450
        if (dst->symbol.section)
4866
450
    {
4867
450
#if defined COFF_WITH_PE
4868
      /* PE sets the symbol to a value relative to the
4869
         start of the section.  */
4870
450
      dst->symbol.value = src->u.syment.n_value;
4871
#else
4872
      dst->symbol.value = (src->u.syment.n_value
4873
               - dst->symbol.section->vma);
4874
#endif
4875
450
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
450
        break;
4879
4880
80
      case C_FILE: /* File name.  */
4881
80
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
308
      case C_MOS:   /* Member of structure.  */
4884
330
      case C_EOS:   /* End of structure.  */
4885
426
      case C_REGPARM: /* Register parameter.  */
4886
532
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
608
      case C_TPDEF: /* Type definition.  */
4889
645
      case C_ARG:
4890
1.81k
      case C_AUTO: /* Automatic variable.  */
4891
1.97k
      case C_FIELD: /* Bit field.  */
4892
2.06k
      case C_ENTAG: /* Enumeration tag.  */
4893
2.20k
      case C_MOE:   /* Member of enumeration.  */
4894
2.93k
      case C_MOU:   /* Member of union.  */
4895
2.99k
      case C_UNTAG: /* Union tag.  */
4896
3.19k
      case C_STRTAG: /* Structure tag.  */
4897
#ifdef RS6000COFF_C
4898
      case C_GSYM:
4899
      case C_LSYM:
4900
      case C_PSYM:
4901
      case C_RSYM:
4902
      case C_RPSYM:
4903
      case C_STSYM:
4904
      case C_TCSYM:
4905
      case C_BCOMM:
4906
      case C_ECOML:
4907
      case C_ECOMM:
4908
      case C_DECL:
4909
      case C_ENTRY:
4910
      case C_FUN:
4911
      case C_ESTAT:
4912
#endif
4913
3.19k
        dst->symbol.flags |= BSF_DEBUGGING;
4914
3.19k
        dst->symbol.value = (src->u.syment.n_value);
4915
3.19k
        break;
4916
4917
#ifdef RS6000COFF_C
4918
      case C_BINCL: /* Beginning of include file.  */
4919
      case C_EINCL: /* Ending of include file.  */
4920
        /* The value is actually a pointer into the line numbers
4921
     of the file.  We locate the line number entry, and
4922
     set the section to the section which contains it, and
4923
     the value to the index in that section.  */
4924
        {
4925
    asection *sec;
4926
4927
    dst->symbol.flags = BSF_DEBUGGING;
4928
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4929
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4930
          && ((file_ptr) (sec->line_filepos
4931
              + sec->lineno_count * bfd_coff_linesz (abfd))
4932
        > (file_ptr) src->u.syment.n_value))
4933
        break;
4934
    if (sec == NULL)
4935
      dst->symbol.value = 0;
4936
    else
4937
      {
4938
        dst->symbol.section = sec;
4939
        dst->symbol.value = ((src->u.syment.n_value
4940
            - sec->line_filepos)
4941
           / bfd_coff_linesz (abfd));
4942
        src->fix_line = 1;
4943
      }
4944
        }
4945
        break;
4946
4947
      case C_BSTAT:
4948
        dst->symbol.flags = BSF_DEBUGGING;
4949
4950
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4951
    dst->symbol.value = 0;
4952
        else
4953
    {
4954
      /* The value is actually a symbol index.  Save a pointer
4955
         to the symbol instead of the index.  FIXME: This
4956
         should use a union.  */
4957
      src->u.syment.n_value
4958
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4959
      dst->symbol.value = src->u.syment.n_value;
4960
      src->fix_value = 1;
4961
    }
4962
        break;
4963
#endif
4964
4965
17
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
55
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
207
      case C_EFCN: /* Physical end of function.  */
4968
207
#if defined COFF_WITH_PE
4969
        /* PE sets the symbol to a value relative to the start
4970
     of the section.  */
4971
207
        dst->symbol.value = src->u.syment.n_value;
4972
207
        if (strcmp (dst->symbol.name, ".bf") != 0)
4973
207
    {
4974
      /* PE uses funny values for .ef and .lf; don't
4975
         relocate them.  */
4976
207
      dst->symbol.flags = BSF_DEBUGGING;
4977
207
    }
4978
0
        else
4979
0
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4980
#else
4981
        /* Base the value as an index from the base of the
4982
     section.  */
4983
        dst->symbol.flags = BSF_LOCAL;
4984
        dst->symbol.value = (src->u.syment.n_value
4985
           - dst->symbol.section->vma);
4986
#endif
4987
207
        break;
4988
4989
22
      case C_STATLAB: /* Static load time label.  */
4990
22
        dst->symbol.value = src->u.syment.n_value;
4991
22
        dst->symbol.flags = BSF_GLOBAL;
4992
22
        break;
4993
4994
46.9k
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
46.9k
        if (src->u.syment.n_type == 0
4998
46.9k
      && src->u.syment.n_value == 0
4999
46.9k
      && src->u.syment.n_scnum == 0)
5000
35.2k
    break;
5001
#ifdef RS6000COFF_C
5002
        /* XCOFF specific: deleted entry.  */
5003
        if (src->u.syment.n_value == C_NULL_VALUE)
5004
    break;
5005
#endif
5006
        /* Fall through.  */
5007
11.8k
      case C_EXTDEF: /* External definition.  */
5008
11.8k
      case C_ULABEL: /* Undefined label.  */
5009
11.8k
      case C_USTATIC: /* Undefined static.  */
5010
#ifndef COFF_WITH_PE
5011
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5012
         class to represent a section symbol.  */
5013
      case C_LINE:  /* line # reformatted as symbol table entry.  */
5014
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5015
      case C_ALIAS: /* Duplicate tag.  */
5016
#endif
5017
        /* New storage classes for TI COFF.  */
5018
#ifdef TICOFF
5019
      case C_UEXT:  /* Tentative external definition.  */
5020
#endif
5021
11.8k
      case C_EXTLAB: /* External load time label.  */
5022
15.8k
      default:
5023
15.8k
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
15.8k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
15.8k
     abfd, src->u.syment.n_sclass,
5027
15.8k
     dst->symbol.section->name, dst->symbol.name);
5028
15.8k
        ret = false;
5029
        /* Fall through.  */
5030
15.8k
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5031
        /* PR 20722: These symbols can also be generated by
5032
     building DLLs with --gc-sections enabled.  */
5033
15.8k
        dst->symbol.flags = BSF_DEBUGGING;
5034
15.8k
        dst->symbol.value = (src->u.syment.n_value);
5035
15.8k
        break;
5036
55.5k
      }
5037
5038
55.5k
    dst->native = src;
5039
55.5k
    dst->symbol.udata.i = 0;
5040
55.5k
    dst->lineno = NULL;
5041
5042
55.5k
    this_index += (src->u.syment.n_numaux) + 1;
5043
55.5k
    dst++;
5044
55.5k
    number_of_symbols++;
5045
55.5k
  }
5046
37
    }
5047
5048
37
  obj_symbols (abfd) = cached_area;
5049
37
  obj_raw_syments (abfd) = native_symbols;
5050
5051
37
  abfd->symcount = number_of_symbols;
5052
37
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
37
  {
5055
37
    asection *p;
5056
5057
37
    p = abfd->sections;
5058
180
    while (p)
5059
168
      {
5060
168
  if (! coff_slurp_line_table (abfd, p))
5061
25
    return false;
5062
143
  p = p->next;
5063
143
      }
5064
37
  }
5065
5066
12
  return ret;
5067
37
}
pe-sh.c:coff_slurp_symbol_table
Line
Count
Source
4695
32
{
4696
32
  combined_entry_type *native_symbols;
4697
32
  coff_symbol_type *cached_area;
4698
32
  unsigned int *table_ptr;
4699
32
  unsigned int number_of_symbols = 0;
4700
32
  bool ret = true;
4701
32
  size_t amt;
4702
4703
32
  if (obj_symbols (abfd))
4704
0
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
32
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
1
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
31
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
31
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
31
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
31
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
31
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
31
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
31
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
31
  if (table_ptr == NULL)
4729
0
    return false;
4730
31
  else
4731
31
    {
4732
31
      coff_symbol_type *dst = cached_area;
4733
31
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
31
      unsigned int this_index = 0;
4735
4736
28.3k
      while (this_index < last_native_index)
4737
28.3k
  {
4738
28.3k
    combined_entry_type *src = native_symbols + this_index;
4739
28.3k
    table_ptr[this_index] = number_of_symbols;
4740
4741
28.3k
    dst->symbol.the_bfd = abfd;
4742
28.3k
    BFD_ASSERT (src->is_sym);
4743
28.3k
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4744
    /* We use the native name field to point to the cached field.  */
4745
28.3k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
28.3k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
28.3k
                 src->u.syment.n_scnum);
4748
28.3k
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
28.3k
    dst->symbol.value = 0;
4751
28.3k
    dst->done_lineno = false;
4752
4753
28.3k
    switch (src->u.syment.n_sclass)
4754
28.3k
      {
4755
2.77k
      case C_EXT:
4756
2.77k
      case C_WEAKEXT:
4757
#if defined ARM
4758
      case C_THUMBEXT:
4759
      case C_THUMBEXTFUNC:
4760
#endif
4761
#ifdef RS6000COFF_C
4762
      case C_HIDEXT:
4763
#ifndef AIX_WEAK_SUPPORT
4764
      case C_AIX_WEAKEXT:
4765
#endif
4766
#endif
4767
2.77k
#ifdef C_SYSTEM
4768
2.78k
      case C_SYSTEM: /* System Wide variable.  */
4769
2.78k
#endif
4770
2.78k
#ifdef COFF_WITH_PE
4771
      /* In PE, 0x68 (104) denotes a section symbol.  */
4772
2.78k
      case C_SECTION:
4773
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4774
2.79k
      case C_NT_WEAK:
4775
2.79k
#endif
4776
2.79k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
2.79k
    {
4778
2.73k
    case COFF_SYMBOL_GLOBAL:
4779
2.73k
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4780
2.73k
#if defined COFF_WITH_PE
4781
      /* PE sets the symbol to a value relative to the
4782
         start of the section.  */
4783
2.73k
      dst->symbol.value = src->u.syment.n_value;
4784
#else
4785
      dst->symbol.value = (src->u.syment.n_value
4786
               - dst->symbol.section->vma);
4787
#endif
4788
2.73k
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
5
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
2.73k
      break;
4793
4794
52
    case COFF_SYMBOL_COMMON:
4795
52
      dst->symbol.section = bfd_com_section_ptr;
4796
52
      dst->symbol.value = src->u.syment.n_value;
4797
52
      break;
4798
4799
7
    case COFF_SYMBOL_UNDEFINED:
4800
7
      dst->symbol.section = bfd_und_section_ptr;
4801
7
      dst->symbol.value = 0;
4802
7
      break;
4803
4804
0
    case COFF_SYMBOL_PE_SECTION:
4805
0
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4806
0
      dst->symbol.value = 0;
4807
0
      break;
4808
4809
0
    case COFF_SYMBOL_LOCAL:
4810
0
      dst->symbol.flags = BSF_LOCAL;
4811
0
#if defined COFF_WITH_PE
4812
      /* PE sets the symbol to a value relative to the
4813
         start of the section.  */
4814
0
      dst->symbol.value = src->u.syment.n_value;
4815
#else
4816
      dst->symbol.value = (src->u.syment.n_value
4817
               - dst->symbol.section->vma);
4818
#endif
4819
0
      if (ISFCN ((src->u.syment.n_type)))
4820
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4821
0
      break;
4822
2.79k
    }
4823
4824
#ifdef RS6000COFF_C
4825
        /* A symbol with a csect entry should not go at the end.  */
4826
        if (src->u.syment.n_numaux > 0)
4827
    dst->symbol.flags |= BSF_NOT_AT_END;
4828
#endif
4829
4830
2.79k
#ifdef COFF_WITH_PE
4831
2.79k
        if (src->u.syment.n_sclass == C_NT_WEAK)
4832
13
    dst->symbol.flags |= BSF_WEAK;
4833
4834
2.79k
        if (src->u.syment.n_sclass == C_SECTION
4835
2.79k
      && src->u.syment.n_scnum > 0)
4836
0
    dst->symbol.flags = BSF_LOCAL;
4837
2.79k
#endif
4838
2.79k
        if (src->u.syment.n_sclass == C_WEAKEXT
4839
#ifdef RS6000COFF_C
4840
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4841
#endif
4842
2.79k
      )
4843
7
    dst->symbol.flags |= BSF_WEAK;
4844
4845
2.79k
        break;
4846
4847
191
      case C_STAT:  /* Static.  */
4848
#if defined ARM
4849
      case C_THUMBSTAT:    /* Thumb static.  */
4850
      case C_THUMBLABEL:   /* Thumb label.  */
4851
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4852
#endif
4853
#ifdef RS6000COFF_C
4854
      case C_DWARF:  /* A label in a dwarf section.  */
4855
      case C_INFO:   /* A label in a comment section.  */
4856
#endif
4857
259
      case C_LABEL:  /* Label.  */
4858
259
        if (src->u.syment.n_scnum == N_DEBUG)
4859
0
    dst->symbol.flags = BSF_DEBUGGING;
4860
259
        else
4861
259
    dst->symbol.flags = BSF_LOCAL;
4862
4863
        /* Base the value as an index from the base of the
4864
     section, if there is one.  */
4865
259
        if (dst->symbol.section)
4866
259
    {
4867
259
#if defined COFF_WITH_PE
4868
      /* PE sets the symbol to a value relative to the
4869
         start of the section.  */
4870
259
      dst->symbol.value = src->u.syment.n_value;
4871
#else
4872
      dst->symbol.value = (src->u.syment.n_value
4873
               - dst->symbol.section->vma);
4874
#endif
4875
259
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
259
        break;
4879
4880
31
      case C_FILE: /* File name.  */
4881
31
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
64
      case C_MOS:   /* Member of structure.  */
4884
82
      case C_EOS:   /* End of structure.  */
4885
87
      case C_REGPARM: /* Register parameter.  */
4886
2.10k
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
2.61k
      case C_TPDEF: /* Type definition.  */
4889
2.73k
      case C_ARG:
4890
4.17k
      case C_AUTO: /* Automatic variable.  */
4891
4.19k
      case C_FIELD: /* Bit field.  */
4892
4.24k
      case C_ENTAG: /* Enumeration tag.  */
4893
4.49k
      case C_MOE:   /* Member of enumeration.  */
4894
4.72k
      case C_MOU:   /* Member of union.  */
4895
4.75k
      case C_UNTAG: /* Union tag.  */
4896
5.00k
      case C_STRTAG: /* Structure tag.  */
4897
#ifdef RS6000COFF_C
4898
      case C_GSYM:
4899
      case C_LSYM:
4900
      case C_PSYM:
4901
      case C_RSYM:
4902
      case C_RPSYM:
4903
      case C_STSYM:
4904
      case C_TCSYM:
4905
      case C_BCOMM:
4906
      case C_ECOML:
4907
      case C_ECOMM:
4908
      case C_DECL:
4909
      case C_ENTRY:
4910
      case C_FUN:
4911
      case C_ESTAT:
4912
#endif
4913
5.00k
        dst->symbol.flags |= BSF_DEBUGGING;
4914
5.00k
        dst->symbol.value = (src->u.syment.n_value);
4915
5.00k
        break;
4916
4917
#ifdef RS6000COFF_C
4918
      case C_BINCL: /* Beginning of include file.  */
4919
      case C_EINCL: /* Ending of include file.  */
4920
        /* The value is actually a pointer into the line numbers
4921
     of the file.  We locate the line number entry, and
4922
     set the section to the section which contains it, and
4923
     the value to the index in that section.  */
4924
        {
4925
    asection *sec;
4926
4927
    dst->symbol.flags = BSF_DEBUGGING;
4928
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4929
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4930
          && ((file_ptr) (sec->line_filepos
4931
              + sec->lineno_count * bfd_coff_linesz (abfd))
4932
        > (file_ptr) src->u.syment.n_value))
4933
        break;
4934
    if (sec == NULL)
4935
      dst->symbol.value = 0;
4936
    else
4937
      {
4938
        dst->symbol.section = sec;
4939
        dst->symbol.value = ((src->u.syment.n_value
4940
            - sec->line_filepos)
4941
           / bfd_coff_linesz (abfd));
4942
        src->fix_line = 1;
4943
      }
4944
        }
4945
        break;
4946
4947
      case C_BSTAT:
4948
        dst->symbol.flags = BSF_DEBUGGING;
4949
4950
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4951
    dst->symbol.value = 0;
4952
        else
4953
    {
4954
      /* The value is actually a symbol index.  Save a pointer
4955
         to the symbol instead of the index.  FIXME: This
4956
         should use a union.  */
4957
      src->u.syment.n_value
4958
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4959
      dst->symbol.value = src->u.syment.n_value;
4960
      src->fix_value = 1;
4961
    }
4962
        break;
4963
#endif
4964
4965
20
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
41
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
145
      case C_EFCN: /* Physical end of function.  */
4968
145
#if defined COFF_WITH_PE
4969
        /* PE sets the symbol to a value relative to the start
4970
     of the section.  */
4971
145
        dst->symbol.value = src->u.syment.n_value;
4972
145
        if (strcmp (dst->symbol.name, ".bf") != 0)
4973
145
    {
4974
      /* PE uses funny values for .ef and .lf; don't
4975
         relocate them.  */
4976
145
      dst->symbol.flags = BSF_DEBUGGING;
4977
145
    }
4978
0
        else
4979
0
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4980
#else
4981
        /* Base the value as an index from the base of the
4982
     section.  */
4983
        dst->symbol.flags = BSF_LOCAL;
4984
        dst->symbol.value = (src->u.syment.n_value
4985
           - dst->symbol.section->vma);
4986
#endif
4987
145
        break;
4988
4989
27
      case C_STATLAB: /* Static load time label.  */
4990
27
        dst->symbol.value = src->u.syment.n_value;
4991
27
        dst->symbol.flags = BSF_GLOBAL;
4992
27
        break;
4993
4994
18.1k
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
18.1k
        if (src->u.syment.n_type == 0
4998
18.1k
      && src->u.syment.n_value == 0
4999
18.1k
      && src->u.syment.n_scnum == 0)
5000
10.2k
    break;
5001
#ifdef RS6000COFF_C
5002
        /* XCOFF specific: deleted entry.  */
5003
        if (src->u.syment.n_value == C_NULL_VALUE)
5004
    break;
5005
#endif
5006
        /* Fall through.  */
5007
7.88k
      case C_EXTDEF: /* External definition.  */
5008
7.89k
      case C_ULABEL: /* Undefined label.  */
5009
7.90k
      case C_USTATIC: /* Undefined static.  */
5010
#ifndef COFF_WITH_PE
5011
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5012
         class to represent a section symbol.  */
5013
      case C_LINE:  /* line # reformatted as symbol table entry.  */
5014
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5015
      case C_ALIAS: /* Duplicate tag.  */
5016
#endif
5017
        /* New storage classes for TI COFF.  */
5018
#ifdef TICOFF
5019
      case C_UEXT:  /* Tentative external definition.  */
5020
#endif
5021
7.91k
      case C_EXTLAB: /* External load time label.  */
5022
9.81k
      default:
5023
9.81k
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
9.81k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
9.81k
     abfd, src->u.syment.n_sclass,
5027
9.81k
     dst->symbol.section->name, dst->symbol.name);
5028
9.81k
        ret = false;
5029
        /* Fall through.  */
5030
9.84k
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5031
        /* PR 20722: These symbols can also be generated by
5032
     building DLLs with --gc-sections enabled.  */
5033
9.84k
        dst->symbol.flags = BSF_DEBUGGING;
5034
9.84k
        dst->symbol.value = (src->u.syment.n_value);
5035
9.84k
        break;
5036
28.3k
      }
5037
5038
28.3k
    dst->native = src;
5039
28.3k
    dst->symbol.udata.i = 0;
5040
28.3k
    dst->lineno = NULL;
5041
5042
28.3k
    this_index += (src->u.syment.n_numaux) + 1;
5043
28.3k
    dst++;
5044
28.3k
    number_of_symbols++;
5045
28.3k
  }
5046
31
    }
5047
5048
31
  obj_symbols (abfd) = cached_area;
5049
31
  obj_raw_syments (abfd) = native_symbols;
5050
5051
31
  abfd->symcount = number_of_symbols;
5052
31
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
31
  {
5055
31
    asection *p;
5056
5057
31
    p = abfd->sections;
5058
130
    while (p)
5059
120
      {
5060
120
  if (! coff_slurp_line_table (abfd, p))
5061
21
    return false;
5062
99
  p = p->next;
5063
99
      }
5064
31
  }
5065
5066
10
  return ret;
5067
31
}
pei-arm-wince.c:coff_slurp_symbol_table
Line
Count
Source
4695
6
{
4696
6
  combined_entry_type *native_symbols;
4697
6
  coff_symbol_type *cached_area;
4698
6
  unsigned int *table_ptr;
4699
6
  unsigned int number_of_symbols = 0;
4700
6
  bool ret = true;
4701
6
  size_t amt;
4702
4703
6
  if (obj_symbols (abfd))
4704
1
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
5
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
0
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
5
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
5
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
5
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
5
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
5
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
5
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
5
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
5
  if (table_ptr == NULL)
4729
0
    return false;
4730
5
  else
4731
5
    {
4732
5
      coff_symbol_type *dst = cached_area;
4733
5
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
5
      unsigned int this_index = 0;
4735
4736
20
      while (this_index < last_native_index)
4737
15
  {
4738
15
    combined_entry_type *src = native_symbols + this_index;
4739
15
    table_ptr[this_index] = number_of_symbols;
4740
4741
15
    dst->symbol.the_bfd = abfd;
4742
15
    BFD_ASSERT (src->is_sym);
4743
15
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4744
    /* We use the native name field to point to the cached field.  */
4745
15
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
15
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
15
                 src->u.syment.n_scnum);
4748
15
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
15
    dst->symbol.value = 0;
4751
15
    dst->done_lineno = false;
4752
4753
15
    switch (src->u.syment.n_sclass)
4754
15
      {
4755
6
      case C_EXT:
4756
6
      case C_WEAKEXT:
4757
6
#if defined ARM
4758
6
      case C_THUMBEXT:
4759
6
      case C_THUMBEXTFUNC:
4760
6
#endif
4761
#ifdef RS6000COFF_C
4762
      case C_HIDEXT:
4763
#ifndef AIX_WEAK_SUPPORT
4764
      case C_AIX_WEAKEXT:
4765
#endif
4766
#endif
4767
6
#ifdef C_SYSTEM
4768
6
      case C_SYSTEM: /* System Wide variable.  */
4769
6
#endif
4770
6
#ifdef COFF_WITH_PE
4771
      /* In PE, 0x68 (104) denotes a section symbol.  */
4772
6
      case C_SECTION:
4773
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4774
6
      case C_NT_WEAK:
4775
6
#endif
4776
6
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
6
    {
4778
6
    case COFF_SYMBOL_GLOBAL:
4779
6
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4780
6
#if defined COFF_WITH_PE
4781
      /* PE sets the symbol to a value relative to the
4782
         start of the section.  */
4783
6
      dst->symbol.value = src->u.syment.n_value;
4784
#else
4785
      dst->symbol.value = (src->u.syment.n_value
4786
               - dst->symbol.section->vma);
4787
#endif
4788
6
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
6
      break;
4793
4794
0
    case COFF_SYMBOL_COMMON:
4795
0
      dst->symbol.section = bfd_com_section_ptr;
4796
0
      dst->symbol.value = src->u.syment.n_value;
4797
0
      break;
4798
4799
0
    case COFF_SYMBOL_UNDEFINED:
4800
0
      dst->symbol.section = bfd_und_section_ptr;
4801
0
      dst->symbol.value = 0;
4802
0
      break;
4803
4804
0
    case COFF_SYMBOL_PE_SECTION:
4805
0
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4806
0
      dst->symbol.value = 0;
4807
0
      break;
4808
4809
0
    case COFF_SYMBOL_LOCAL:
4810
0
      dst->symbol.flags = BSF_LOCAL;
4811
0
#if defined COFF_WITH_PE
4812
      /* PE sets the symbol to a value relative to the
4813
         start of the section.  */
4814
0
      dst->symbol.value = src->u.syment.n_value;
4815
#else
4816
      dst->symbol.value = (src->u.syment.n_value
4817
               - dst->symbol.section->vma);
4818
#endif
4819
0
      if (ISFCN ((src->u.syment.n_type)))
4820
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4821
0
      break;
4822
6
    }
4823
4824
#ifdef RS6000COFF_C
4825
        /* A symbol with a csect entry should not go at the end.  */
4826
        if (src->u.syment.n_numaux > 0)
4827
    dst->symbol.flags |= BSF_NOT_AT_END;
4828
#endif
4829
4830
6
#ifdef COFF_WITH_PE
4831
6
        if (src->u.syment.n_sclass == C_NT_WEAK)
4832
0
    dst->symbol.flags |= BSF_WEAK;
4833
4834
6
        if (src->u.syment.n_sclass == C_SECTION
4835
6
      && src->u.syment.n_scnum > 0)
4836
0
    dst->symbol.flags = BSF_LOCAL;
4837
6
#endif
4838
6
        if (src->u.syment.n_sclass == C_WEAKEXT
4839
#ifdef RS6000COFF_C
4840
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4841
#endif
4842
6
      )
4843
0
    dst->symbol.flags |= BSF_WEAK;
4844
4845
6
        break;
4846
4847
1
      case C_STAT:  /* Static.  */
4848
1
#if defined ARM
4849
1
      case C_THUMBSTAT:    /* Thumb static.  */
4850
1
      case C_THUMBLABEL:   /* Thumb label.  */
4851
1
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4852
1
#endif
4853
#ifdef RS6000COFF_C
4854
      case C_DWARF:  /* A label in a dwarf section.  */
4855
      case C_INFO:   /* A label in a comment section.  */
4856
#endif
4857
1
      case C_LABEL:  /* Label.  */
4858
1
        if (src->u.syment.n_scnum == N_DEBUG)
4859
0
    dst->symbol.flags = BSF_DEBUGGING;
4860
1
        else
4861
1
    dst->symbol.flags = BSF_LOCAL;
4862
4863
        /* Base the value as an index from the base of the
4864
     section, if there is one.  */
4865
1
        if (dst->symbol.section)
4866
1
    {
4867
1
#if defined COFF_WITH_PE
4868
      /* PE sets the symbol to a value relative to the
4869
         start of the section.  */
4870
1
      dst->symbol.value = src->u.syment.n_value;
4871
#else
4872
      dst->symbol.value = (src->u.syment.n_value
4873
               - dst->symbol.section->vma);
4874
#endif
4875
1
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
1
        break;
4879
4880
0
      case C_FILE: /* File name.  */
4881
0
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
0
      case C_MOS:   /* Member of structure.  */
4884
0
      case C_EOS:   /* End of structure.  */
4885
0
      case C_REGPARM: /* Register parameter.  */
4886
0
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
0
      case C_TPDEF: /* Type definition.  */
4889
0
      case C_ARG:
4890
0
      case C_AUTO: /* Automatic variable.  */
4891
0
      case C_FIELD: /* Bit field.  */
4892
0
      case C_ENTAG: /* Enumeration tag.  */
4893
0
      case C_MOE:   /* Member of enumeration.  */
4894
0
      case C_MOU:   /* Member of union.  */
4895
0
      case C_UNTAG: /* Union tag.  */
4896
0
      case C_STRTAG: /* Structure tag.  */
4897
#ifdef RS6000COFF_C
4898
      case C_GSYM:
4899
      case C_LSYM:
4900
      case C_PSYM:
4901
      case C_RSYM:
4902
      case C_RPSYM:
4903
      case C_STSYM:
4904
      case C_TCSYM:
4905
      case C_BCOMM:
4906
      case C_ECOML:
4907
      case C_ECOMM:
4908
      case C_DECL:
4909
      case C_ENTRY:
4910
      case C_FUN:
4911
      case C_ESTAT:
4912
#endif
4913
0
        dst->symbol.flags |= BSF_DEBUGGING;
4914
0
        dst->symbol.value = (src->u.syment.n_value);
4915
0
        break;
4916
4917
#ifdef RS6000COFF_C
4918
      case C_BINCL: /* Beginning of include file.  */
4919
      case C_EINCL: /* Ending of include file.  */
4920
        /* The value is actually a pointer into the line numbers
4921
     of the file.  We locate the line number entry, and
4922
     set the section to the section which contains it, and
4923
     the value to the index in that section.  */
4924
        {
4925
    asection *sec;
4926
4927
    dst->symbol.flags = BSF_DEBUGGING;
4928
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4929
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4930
          && ((file_ptr) (sec->line_filepos
4931
              + sec->lineno_count * bfd_coff_linesz (abfd))
4932
        > (file_ptr) src->u.syment.n_value))
4933
        break;
4934
    if (sec == NULL)
4935
      dst->symbol.value = 0;
4936
    else
4937
      {
4938
        dst->symbol.section = sec;
4939
        dst->symbol.value = ((src->u.syment.n_value
4940
            - sec->line_filepos)
4941
           / bfd_coff_linesz (abfd));
4942
        src->fix_line = 1;
4943
      }
4944
        }
4945
        break;
4946
4947
      case C_BSTAT:
4948
        dst->symbol.flags = BSF_DEBUGGING;
4949
4950
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4951
    dst->symbol.value = 0;
4952
        else
4953
    {
4954
      /* The value is actually a symbol index.  Save a pointer
4955
         to the symbol instead of the index.  FIXME: This
4956
         should use a union.  */
4957
      src->u.syment.n_value
4958
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4959
      dst->symbol.value = src->u.syment.n_value;
4960
      src->fix_value = 1;
4961
    }
4962
        break;
4963
#endif
4964
4965
1
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
1
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
1
      case C_EFCN: /* Physical end of function.  */
4968
1
#if defined COFF_WITH_PE
4969
        /* PE sets the symbol to a value relative to the start
4970
     of the section.  */
4971
1
        dst->symbol.value = src->u.syment.n_value;
4972
1
        if (strcmp (dst->symbol.name, ".bf") != 0)
4973
1
    {
4974
      /* PE uses funny values for .ef and .lf; don't
4975
         relocate them.  */
4976
1
      dst->symbol.flags = BSF_DEBUGGING;
4977
1
    }
4978
0
        else
4979
0
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4980
#else
4981
        /* Base the value as an index from the base of the
4982
     section.  */
4983
        dst->symbol.flags = BSF_LOCAL;
4984
        dst->symbol.value = (src->u.syment.n_value
4985
           - dst->symbol.section->vma);
4986
#endif
4987
1
        break;
4988
4989
0
      case C_STATLAB: /* Static load time label.  */
4990
0
        dst->symbol.value = src->u.syment.n_value;
4991
0
        dst->symbol.flags = BSF_GLOBAL;
4992
0
        break;
4993
4994
7
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
7
        if (src->u.syment.n_type == 0
4998
7
      && src->u.syment.n_value == 0
4999
7
      && src->u.syment.n_scnum == 0)
5000
0
    break;
5001
#ifdef RS6000COFF_C
5002
        /* XCOFF specific: deleted entry.  */
5003
        if (src->u.syment.n_value == C_NULL_VALUE)
5004
    break;
5005
#endif
5006
        /* Fall through.  */
5007
7
      case C_EXTDEF: /* External definition.  */
5008
7
      case C_ULABEL: /* Undefined label.  */
5009
7
      case C_USTATIC: /* Undefined static.  */
5010
#ifndef COFF_WITH_PE
5011
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5012
         class to represent a section symbol.  */
5013
      case C_LINE:  /* line # reformatted as symbol table entry.  */
5014
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5015
      case C_ALIAS: /* Duplicate tag.  */
5016
#endif
5017
        /* New storage classes for TI COFF.  */
5018
#ifdef TICOFF
5019
      case C_UEXT:  /* Tentative external definition.  */
5020
#endif
5021
7
      case C_EXTLAB: /* External load time label.  */
5022
7
      default:
5023
7
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
7
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
7
     abfd, src->u.syment.n_sclass,
5027
7
     dst->symbol.section->name, dst->symbol.name);
5028
7
        ret = false;
5029
        /* Fall through.  */
5030
7
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5031
        /* PR 20722: These symbols can also be generated by
5032
     building DLLs with --gc-sections enabled.  */
5033
7
        dst->symbol.flags = BSF_DEBUGGING;
5034
7
        dst->symbol.value = (src->u.syment.n_value);
5035
7
        break;
5036
15
      }
5037
5038
15
    dst->native = src;
5039
15
    dst->symbol.udata.i = 0;
5040
15
    dst->lineno = NULL;
5041
5042
15
    this_index += (src->u.syment.n_numaux) + 1;
5043
15
    dst++;
5044
15
    number_of_symbols++;
5045
15
  }
5046
5
    }
5047
5048
5
  obj_symbols (abfd) = cached_area;
5049
5
  obj_raw_syments (abfd) = native_symbols;
5050
5051
5
  abfd->symcount = number_of_symbols;
5052
5
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
5
  {
5055
5
    asection *p;
5056
5057
5
    p = abfd->sections;
5058
4.10k
    while (p)
5059
4.10k
      {
5060
4.10k
  if (! coff_slurp_line_table (abfd, p))
5061
4
    return false;
5062
4.10k
  p = p->next;
5063
4.10k
      }
5064
5
  }
5065
5066
1
  return ret;
5067
5
}
pei-arm.c:coff_slurp_symbol_table
Line
Count
Source
4695
7
{
4696
7
  combined_entry_type *native_symbols;
4697
7
  coff_symbol_type *cached_area;
4698
7
  unsigned int *table_ptr;
4699
7
  unsigned int number_of_symbols = 0;
4700
7
  bool ret = true;
4701
7
  size_t amt;
4702
4703
7
  if (obj_symbols (abfd))
4704
0
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
7
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
0
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
7
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
7
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
7
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
7
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
7
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
7
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
7
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
7
  if (table_ptr == NULL)
4729
0
    return false;
4730
7
  else
4731
7
    {
4732
7
      coff_symbol_type *dst = cached_area;
4733
7
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
7
      unsigned int this_index = 0;
4735
4736
388
      while (this_index < last_native_index)
4737
381
  {
4738
381
    combined_entry_type *src = native_symbols + this_index;
4739
381
    table_ptr[this_index] = number_of_symbols;
4740
4741
381
    dst->symbol.the_bfd = abfd;
4742
381
    BFD_ASSERT (src->is_sym);
4743
381
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4744
    /* We use the native name field to point to the cached field.  */
4745
381
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
381
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
381
                 src->u.syment.n_scnum);
4748
381
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
381
    dst->symbol.value = 0;
4751
381
    dst->done_lineno = false;
4752
4753
381
    switch (src->u.syment.n_sclass)
4754
381
      {
4755
11
      case C_EXT:
4756
12
      case C_WEAKEXT:
4757
12
#if defined ARM
4758
12
      case C_THUMBEXT:
4759
12
      case C_THUMBEXTFUNC:
4760
12
#endif
4761
#ifdef RS6000COFF_C
4762
      case C_HIDEXT:
4763
#ifndef AIX_WEAK_SUPPORT
4764
      case C_AIX_WEAKEXT:
4765
#endif
4766
#endif
4767
12
#ifdef C_SYSTEM
4768
13
      case C_SYSTEM: /* System Wide variable.  */
4769
13
#endif
4770
13
#ifdef COFF_WITH_PE
4771
      /* In PE, 0x68 (104) denotes a section symbol.  */
4772
13
      case C_SECTION:
4773
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4774
13
      case C_NT_WEAK:
4775
13
#endif
4776
13
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
13
    {
4778
8
    case COFF_SYMBOL_GLOBAL:
4779
8
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4780
8
#if defined COFF_WITH_PE
4781
      /* PE sets the symbol to a value relative to the
4782
         start of the section.  */
4783
8
      dst->symbol.value = src->u.syment.n_value;
4784
#else
4785
      dst->symbol.value = (src->u.syment.n_value
4786
               - dst->symbol.section->vma);
4787
#endif
4788
8
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
8
      break;
4793
4794
5
    case COFF_SYMBOL_COMMON:
4795
5
      dst->symbol.section = bfd_com_section_ptr;
4796
5
      dst->symbol.value = src->u.syment.n_value;
4797
5
      break;
4798
4799
0
    case COFF_SYMBOL_UNDEFINED:
4800
0
      dst->symbol.section = bfd_und_section_ptr;
4801
0
      dst->symbol.value = 0;
4802
0
      break;
4803
4804
0
    case COFF_SYMBOL_PE_SECTION:
4805
0
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4806
0
      dst->symbol.value = 0;
4807
0
      break;
4808
4809
0
    case COFF_SYMBOL_LOCAL:
4810
0
      dst->symbol.flags = BSF_LOCAL;
4811
0
#if defined COFF_WITH_PE
4812
      /* PE sets the symbol to a value relative to the
4813
         start of the section.  */
4814
0
      dst->symbol.value = src->u.syment.n_value;
4815
#else
4816
      dst->symbol.value = (src->u.syment.n_value
4817
               - dst->symbol.section->vma);
4818
#endif
4819
0
      if (ISFCN ((src->u.syment.n_type)))
4820
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4821
0
      break;
4822
13
    }
4823
4824
#ifdef RS6000COFF_C
4825
        /* A symbol with a csect entry should not go at the end.  */
4826
        if (src->u.syment.n_numaux > 0)
4827
    dst->symbol.flags |= BSF_NOT_AT_END;
4828
#endif
4829
4830
13
#ifdef COFF_WITH_PE
4831
13
        if (src->u.syment.n_sclass == C_NT_WEAK)
4832
0
    dst->symbol.flags |= BSF_WEAK;
4833
4834
13
        if (src->u.syment.n_sclass == C_SECTION
4835
13
      && src->u.syment.n_scnum > 0)
4836
0
    dst->symbol.flags = BSF_LOCAL;
4837
13
#endif
4838
13
        if (src->u.syment.n_sclass == C_WEAKEXT
4839
#ifdef RS6000COFF_C
4840
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4841
#endif
4842
13
      )
4843
1
    dst->symbol.flags |= BSF_WEAK;
4844
4845
13
        break;
4846
4847
45
      case C_STAT:  /* Static.  */
4848
45
#if defined ARM
4849
45
      case C_THUMBSTAT:    /* Thumb static.  */
4850
45
      case C_THUMBLABEL:   /* Thumb label.  */
4851
53
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4852
53
#endif
4853
#ifdef RS6000COFF_C
4854
      case C_DWARF:  /* A label in a dwarf section.  */
4855
      case C_INFO:   /* A label in a comment section.  */
4856
#endif
4857
53
      case C_LABEL:  /* Label.  */
4858
53
        if (src->u.syment.n_scnum == N_DEBUG)
4859
0
    dst->symbol.flags = BSF_DEBUGGING;
4860
53
        else
4861
53
    dst->symbol.flags = BSF_LOCAL;
4862
4863
        /* Base the value as an index from the base of the
4864
     section, if there is one.  */
4865
53
        if (dst->symbol.section)
4866
53
    {
4867
53
#if defined COFF_WITH_PE
4868
      /* PE sets the symbol to a value relative to the
4869
         start of the section.  */
4870
53
      dst->symbol.value = src->u.syment.n_value;
4871
#else
4872
      dst->symbol.value = (src->u.syment.n_value
4873
               - dst->symbol.section->vma);
4874
#endif
4875
53
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
53
        break;
4879
4880
0
      case C_FILE: /* File name.  */
4881
0
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
4
      case C_MOS:   /* Member of structure.  */
4884
4
      case C_EOS:   /* End of structure.  */
4885
4
      case C_REGPARM: /* Register parameter.  */
4886
4
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
4
      case C_TPDEF: /* Type definition.  */
4889
4
      case C_ARG:
4890
28
      case C_AUTO: /* Automatic variable.  */
4891
29
      case C_FIELD: /* Bit field.  */
4892
33
      case C_ENTAG: /* Enumeration tag.  */
4893
33
      case C_MOE:   /* Member of enumeration.  */
4894
33
      case C_MOU:   /* Member of union.  */
4895
33
      case C_UNTAG: /* Union tag.  */
4896
33
      case C_STRTAG: /* Structure tag.  */
4897
#ifdef RS6000COFF_C
4898
      case C_GSYM:
4899
      case C_LSYM:
4900
      case C_PSYM:
4901
      case C_RSYM:
4902
      case C_RPSYM:
4903
      case C_STSYM:
4904
      case C_TCSYM:
4905
      case C_BCOMM:
4906
      case C_ECOML:
4907
      case C_ECOMM:
4908
      case C_DECL:
4909
      case C_ENTRY:
4910
      case C_FUN:
4911
      case C_ESTAT:
4912
#endif
4913
33
        dst->symbol.flags |= BSF_DEBUGGING;
4914
33
        dst->symbol.value = (src->u.syment.n_value);
4915
33
        break;
4916
4917
#ifdef RS6000COFF_C
4918
      case C_BINCL: /* Beginning of include file.  */
4919
      case C_EINCL: /* Ending of include file.  */
4920
        /* The value is actually a pointer into the line numbers
4921
     of the file.  We locate the line number entry, and
4922
     set the section to the section which contains it, and
4923
     the value to the index in that section.  */
4924
        {
4925
    asection *sec;
4926
4927
    dst->symbol.flags = BSF_DEBUGGING;
4928
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4929
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4930
          && ((file_ptr) (sec->line_filepos
4931
              + sec->lineno_count * bfd_coff_linesz (abfd))
4932
        > (file_ptr) src->u.syment.n_value))
4933
        break;
4934
    if (sec == NULL)
4935
      dst->symbol.value = 0;
4936
    else
4937
      {
4938
        dst->symbol.section = sec;
4939
        dst->symbol.value = ((src->u.syment.n_value
4940
            - sec->line_filepos)
4941
           / bfd_coff_linesz (abfd));
4942
        src->fix_line = 1;
4943
      }
4944
        }
4945
        break;
4946
4947
      case C_BSTAT:
4948
        dst->symbol.flags = BSF_DEBUGGING;
4949
4950
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4951
    dst->symbol.value = 0;
4952
        else
4953
    {
4954
      /* The value is actually a symbol index.  Save a pointer
4955
         to the symbol instead of the index.  FIXME: This
4956
         should use a union.  */
4957
      src->u.syment.n_value
4958
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4959
      dst->symbol.value = src->u.syment.n_value;
4960
      src->fix_value = 1;
4961
    }
4962
        break;
4963
#endif
4964
4965
0
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
0
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
0
      case C_EFCN: /* Physical end of function.  */
4968
0
#if defined COFF_WITH_PE
4969
        /* PE sets the symbol to a value relative to the start
4970
     of the section.  */
4971
0
        dst->symbol.value = src->u.syment.n_value;
4972
0
        if (strcmp (dst->symbol.name, ".bf") != 0)
4973
0
    {
4974
      /* PE uses funny values for .ef and .lf; don't
4975
         relocate them.  */
4976
0
      dst->symbol.flags = BSF_DEBUGGING;
4977
0
    }
4978
0
        else
4979
0
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4980
#else
4981
        /* Base the value as an index from the base of the
4982
     section.  */
4983
        dst->symbol.flags = BSF_LOCAL;
4984
        dst->symbol.value = (src->u.syment.n_value
4985
           - dst->symbol.section->vma);
4986
#endif
4987
0
        break;
4988
4989
0
      case C_STATLAB: /* Static load time label.  */
4990
0
        dst->symbol.value = src->u.syment.n_value;
4991
0
        dst->symbol.flags = BSF_GLOBAL;
4992
0
        break;
4993
4994
218
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
218
        if (src->u.syment.n_type == 0
4998
218
      && src->u.syment.n_value == 0
4999
218
      && src->u.syment.n_scnum == 0)
5000
2
    break;
5001
#ifdef RS6000COFF_C
5002
        /* XCOFF specific: deleted entry.  */
5003
        if (src->u.syment.n_value == C_NULL_VALUE)
5004
    break;
5005
#endif
5006
        /* Fall through.  */
5007
216
      case C_EXTDEF: /* External definition.  */
5008
216
      case C_ULABEL: /* Undefined label.  */
5009
216
      case C_USTATIC: /* Undefined static.  */
5010
#ifndef COFF_WITH_PE
5011
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5012
         class to represent a section symbol.  */
5013
      case C_LINE:  /* line # reformatted as symbol table entry.  */
5014
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5015
      case C_ALIAS: /* Duplicate tag.  */
5016
#endif
5017
        /* New storage classes for TI COFF.  */
5018
#ifdef TICOFF
5019
      case C_UEXT:  /* Tentative external definition.  */
5020
#endif
5021
216
      case C_EXTLAB: /* External load time label.  */
5022
280
      default:
5023
280
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
280
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
280
     abfd, src->u.syment.n_sclass,
5027
280
     dst->symbol.section->name, dst->symbol.name);
5028
280
        ret = false;
5029
        /* Fall through.  */
5030
280
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5031
        /* PR 20722: These symbols can also be generated by
5032
     building DLLs with --gc-sections enabled.  */
5033
280
        dst->symbol.flags = BSF_DEBUGGING;
5034
280
        dst->symbol.value = (src->u.syment.n_value);
5035
280
        break;
5036
381
      }
5037
5038
381
    dst->native = src;
5039
381
    dst->symbol.udata.i = 0;
5040
381
    dst->lineno = NULL;
5041
5042
381
    this_index += (src->u.syment.n_numaux) + 1;
5043
381
    dst++;
5044
381
    number_of_symbols++;
5045
381
  }
5046
7
    }
5047
5048
7
  obj_symbols (abfd) = cached_area;
5049
7
  obj_raw_syments (abfd) = native_symbols;
5050
5051
7
  abfd->symcount = number_of_symbols;
5052
7
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
7
  {
5055
7
    asection *p;
5056
5057
7
    p = abfd->sections;
5058
9
    while (p)
5059
9
      {
5060
9
  if (! coff_slurp_line_table (abfd, p))
5061
7
    return false;
5062
2
  p = p->next;
5063
2
      }
5064
7
  }
5065
5066
0
  return ret;
5067
7
}
pei-mcore.c:coff_slurp_symbol_table
Line
Count
Source
4695
5
{
4696
5
  combined_entry_type *native_symbols;
4697
5
  coff_symbol_type *cached_area;
4698
5
  unsigned int *table_ptr;
4699
5
  unsigned int number_of_symbols = 0;
4700
5
  bool ret = true;
4701
5
  size_t amt;
4702
4703
5
  if (obj_symbols (abfd))
4704
0
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
5
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
0
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
5
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
5
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
5
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
5
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
5
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
5
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
5
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
5
  if (table_ptr == NULL)
4729
0
    return false;
4730
5
  else
4731
5
    {
4732
5
      coff_symbol_type *dst = cached_area;
4733
5
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
5
      unsigned int this_index = 0;
4735
4736
23
      while (this_index < last_native_index)
4737
18
  {
4738
18
    combined_entry_type *src = native_symbols + this_index;
4739
18
    table_ptr[this_index] = number_of_symbols;
4740
4741
18
    dst->symbol.the_bfd = abfd;
4742
18
    BFD_ASSERT (src->is_sym);
4743
18
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4744
    /* We use the native name field to point to the cached field.  */
4745
18
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
18
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
18
                 src->u.syment.n_scnum);
4748
18
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
18
    dst->symbol.value = 0;
4751
18
    dst->done_lineno = false;
4752
4753
18
    switch (src->u.syment.n_sclass)
4754
18
      {
4755
4
      case C_EXT:
4756
7
      case C_WEAKEXT:
4757
#if defined ARM
4758
      case C_THUMBEXT:
4759
      case C_THUMBEXTFUNC:
4760
#endif
4761
#ifdef RS6000COFF_C
4762
      case C_HIDEXT:
4763
#ifndef AIX_WEAK_SUPPORT
4764
      case C_AIX_WEAKEXT:
4765
#endif
4766
#endif
4767
7
#ifdef C_SYSTEM
4768
10
      case C_SYSTEM: /* System Wide variable.  */
4769
10
#endif
4770
10
#ifdef COFF_WITH_PE
4771
      /* In PE, 0x68 (104) denotes a section symbol.  */
4772
10
      case C_SECTION:
4773
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4774
10
      case C_NT_WEAK:
4775
10
#endif
4776
10
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
10
    {
4778
6
    case COFF_SYMBOL_GLOBAL:
4779
6
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4780
6
#if defined COFF_WITH_PE
4781
      /* PE sets the symbol to a value relative to the
4782
         start of the section.  */
4783
6
      dst->symbol.value = src->u.syment.n_value;
4784
#else
4785
      dst->symbol.value = (src->u.syment.n_value
4786
               - dst->symbol.section->vma);
4787
#endif
4788
6
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
6
      break;
4793
4794
4
    case COFF_SYMBOL_COMMON:
4795
4
      dst->symbol.section = bfd_com_section_ptr;
4796
4
      dst->symbol.value = src->u.syment.n_value;
4797
4
      break;
4798
4799
0
    case COFF_SYMBOL_UNDEFINED:
4800
0
      dst->symbol.section = bfd_und_section_ptr;
4801
0
      dst->symbol.value = 0;
4802
0
      break;
4803
4804
0
    case COFF_SYMBOL_PE_SECTION:
4805
0
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4806
0
      dst->symbol.value = 0;
4807
0
      break;
4808
4809
0
    case COFF_SYMBOL_LOCAL:
4810
0
      dst->symbol.flags = BSF_LOCAL;
4811
0
#if defined COFF_WITH_PE
4812
      /* PE sets the symbol to a value relative to the
4813
         start of the section.  */
4814
0
      dst->symbol.value = src->u.syment.n_value;
4815
#else
4816
      dst->symbol.value = (src->u.syment.n_value
4817
               - dst->symbol.section->vma);
4818
#endif
4819
0
      if (ISFCN ((src->u.syment.n_type)))
4820
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4821
0
      break;
4822
10
    }
4823
4824
#ifdef RS6000COFF_C
4825
        /* A symbol with a csect entry should not go at the end.  */
4826
        if (src->u.syment.n_numaux > 0)
4827
    dst->symbol.flags |= BSF_NOT_AT_END;
4828
#endif
4829
4830
10
#ifdef COFF_WITH_PE
4831
10
        if (src->u.syment.n_sclass == C_NT_WEAK)
4832
0
    dst->symbol.flags |= BSF_WEAK;
4833
4834
10
        if (src->u.syment.n_sclass == C_SECTION
4835
10
      && src->u.syment.n_scnum > 0)
4836
0
    dst->symbol.flags = BSF_LOCAL;
4837
10
#endif
4838
10
        if (src->u.syment.n_sclass == C_WEAKEXT
4839
#ifdef RS6000COFF_C
4840
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4841
#endif
4842
10
      )
4843
3
    dst->symbol.flags |= BSF_WEAK;
4844
4845
10
        break;
4846
4847
1
      case C_STAT:  /* Static.  */
4848
#if defined ARM
4849
      case C_THUMBSTAT:    /* Thumb static.  */
4850
      case C_THUMBLABEL:   /* Thumb label.  */
4851
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4852
#endif
4853
#ifdef RS6000COFF_C
4854
      case C_DWARF:  /* A label in a dwarf section.  */
4855
      case C_INFO:   /* A label in a comment section.  */
4856
#endif
4857
1
      case C_LABEL:  /* Label.  */
4858
1
        if (src->u.syment.n_scnum == N_DEBUG)
4859
0
    dst->symbol.flags = BSF_DEBUGGING;
4860
1
        else
4861
1
    dst->symbol.flags = BSF_LOCAL;
4862
4863
        /* Base the value as an index from the base of the
4864
     section, if there is one.  */
4865
1
        if (dst->symbol.section)
4866
1
    {
4867
1
#if defined COFF_WITH_PE
4868
      /* PE sets the symbol to a value relative to the
4869
         start of the section.  */
4870
1
      dst->symbol.value = src->u.syment.n_value;
4871
#else
4872
      dst->symbol.value = (src->u.syment.n_value
4873
               - dst->symbol.section->vma);
4874
#endif
4875
1
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
1
        break;
4879
4880
0
      case C_FILE: /* File name.  */
4881
0
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
0
      case C_MOS:   /* Member of structure.  */
4884
0
      case C_EOS:   /* End of structure.  */
4885
0
      case C_REGPARM: /* Register parameter.  */
4886
0
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
0
      case C_TPDEF: /* Type definition.  */
4889
3
      case C_ARG:
4890
4
      case C_AUTO: /* Automatic variable.  */
4891
4
      case C_FIELD: /* Bit field.  */
4892
4
      case C_ENTAG: /* Enumeration tag.  */
4893
4
      case C_MOE:   /* Member of enumeration.  */
4894
4
      case C_MOU:   /* Member of union.  */
4895
4
      case C_UNTAG: /* Union tag.  */
4896
4
      case C_STRTAG: /* Structure tag.  */
4897
#ifdef RS6000COFF_C
4898
      case C_GSYM:
4899
      case C_LSYM:
4900
      case C_PSYM:
4901
      case C_RSYM:
4902
      case C_RPSYM:
4903
      case C_STSYM:
4904
      case C_TCSYM:
4905
      case C_BCOMM:
4906
      case C_ECOML:
4907
      case C_ECOMM:
4908
      case C_DECL:
4909
      case C_ENTRY:
4910
      case C_FUN:
4911
      case C_ESTAT:
4912
#endif
4913
4
        dst->symbol.flags |= BSF_DEBUGGING;
4914
4
        dst->symbol.value = (src->u.syment.n_value);
4915
4
        break;
4916
4917
#ifdef RS6000COFF_C
4918
      case C_BINCL: /* Beginning of include file.  */
4919
      case C_EINCL: /* Ending of include file.  */
4920
        /* The value is actually a pointer into the line numbers
4921
     of the file.  We locate the line number entry, and
4922
     set the section to the section which contains it, and
4923
     the value to the index in that section.  */
4924
        {
4925
    asection *sec;
4926
4927
    dst->symbol.flags = BSF_DEBUGGING;
4928
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4929
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4930
          && ((file_ptr) (sec->line_filepos
4931
              + sec->lineno_count * bfd_coff_linesz (abfd))
4932
        > (file_ptr) src->u.syment.n_value))
4933
        break;
4934
    if (sec == NULL)
4935
      dst->symbol.value = 0;
4936
    else
4937
      {
4938
        dst->symbol.section = sec;
4939
        dst->symbol.value = ((src->u.syment.n_value
4940
            - sec->line_filepos)
4941
           / bfd_coff_linesz (abfd));
4942
        src->fix_line = 1;
4943
      }
4944
        }
4945
        break;
4946
4947
      case C_BSTAT:
4948
        dst->symbol.flags = BSF_DEBUGGING;
4949
4950
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4951
    dst->symbol.value = 0;
4952
        else
4953
    {
4954
      /* The value is actually a symbol index.  Save a pointer
4955
         to the symbol instead of the index.  FIXME: This
4956
         should use a union.  */
4957
      src->u.syment.n_value
4958
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4959
      dst->symbol.value = src->u.syment.n_value;
4960
      src->fix_value = 1;
4961
    }
4962
        break;
4963
#endif
4964
4965
0
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
0
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
0
      case C_EFCN: /* Physical end of function.  */
4968
0
#if defined COFF_WITH_PE
4969
        /* PE sets the symbol to a value relative to the start
4970
     of the section.  */
4971
0
        dst->symbol.value = src->u.syment.n_value;
4972
0
        if (strcmp (dst->symbol.name, ".bf") != 0)
4973
0
    {
4974
      /* PE uses funny values for .ef and .lf; don't
4975
         relocate them.  */
4976
0
      dst->symbol.flags = BSF_DEBUGGING;
4977
0
    }
4978
0
        else
4979
0
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4980
#else
4981
        /* Base the value as an index from the base of the
4982
     section.  */
4983
        dst->symbol.flags = BSF_LOCAL;
4984
        dst->symbol.value = (src->u.syment.n_value
4985
           - dst->symbol.section->vma);
4986
#endif
4987
0
        break;
4988
4989
0
      case C_STATLAB: /* Static load time label.  */
4990
0
        dst->symbol.value = src->u.syment.n_value;
4991
0
        dst->symbol.flags = BSF_GLOBAL;
4992
0
        break;
4993
4994
3
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
3
        if (src->u.syment.n_type == 0
4998
3
      && src->u.syment.n_value == 0
4999
3
      && src->u.syment.n_scnum == 0)
5000
0
    break;
5001
#ifdef RS6000COFF_C
5002
        /* XCOFF specific: deleted entry.  */
5003
        if (src->u.syment.n_value == C_NULL_VALUE)
5004
    break;
5005
#endif
5006
        /* Fall through.  */
5007
3
      case C_EXTDEF: /* External definition.  */
5008
3
      case C_ULABEL: /* Undefined label.  */
5009
3
      case C_USTATIC: /* Undefined static.  */
5010
#ifndef COFF_WITH_PE
5011
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5012
         class to represent a section symbol.  */
5013
      case C_LINE:  /* line # reformatted as symbol table entry.  */
5014
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5015
      case C_ALIAS: /* Duplicate tag.  */
5016
#endif
5017
        /* New storage classes for TI COFF.  */
5018
#ifdef TICOFF
5019
      case C_UEXT:  /* Tentative external definition.  */
5020
#endif
5021
3
      case C_EXTLAB: /* External load time label.  */
5022
3
      default:
5023
3
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
3
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
3
     abfd, src->u.syment.n_sclass,
5027
3
     dst->symbol.section->name, dst->symbol.name);
5028
3
        ret = false;
5029
        /* Fall through.  */
5030
3
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5031
        /* PR 20722: These symbols can also be generated by
5032
     building DLLs with --gc-sections enabled.  */
5033
3
        dst->symbol.flags = BSF_DEBUGGING;
5034
3
        dst->symbol.value = (src->u.syment.n_value);
5035
3
        break;
5036
18
      }
5037
5038
18
    dst->native = src;
5039
18
    dst->symbol.udata.i = 0;
5040
18
    dst->lineno = NULL;
5041
5042
18
    this_index += (src->u.syment.n_numaux) + 1;
5043
18
    dst++;
5044
18
    number_of_symbols++;
5045
18
  }
5046
5
    }
5047
5048
5
  obj_symbols (abfd) = cached_area;
5049
5
  obj_raw_syments (abfd) = native_symbols;
5050
5051
5
  abfd->symcount = number_of_symbols;
5052
5
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
5
  {
5055
5
    asection *p;
5056
5057
5
    p = abfd->sections;
5058
5
    while (p)
5059
5
      {
5060
5
  if (! coff_slurp_line_table (abfd, p))
5061
5
    return false;
5062
0
  p = p->next;
5063
0
      }
5064
5
  }
5065
5066
0
  return ret;
5067
5
}
pei-sh.c:coff_slurp_symbol_table
Line
Count
Source
4695
21
{
4696
21
  combined_entry_type *native_symbols;
4697
21
  coff_symbol_type *cached_area;
4698
21
  unsigned int *table_ptr;
4699
21
  unsigned int number_of_symbols = 0;
4700
21
  bool ret = true;
4701
21
  size_t amt;
4702
4703
21
  if (obj_symbols (abfd))
4704
1
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
20
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
3
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
17
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
17
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
17
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
17
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
17
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
17
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
17
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
17
  if (table_ptr == NULL)
4729
0
    return false;
4730
17
  else
4731
17
    {
4732
17
      coff_symbol_type *dst = cached_area;
4733
17
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
17
      unsigned int this_index = 0;
4735
4736
6.09k
      while (this_index < last_native_index)
4737
6.08k
  {
4738
6.08k
    combined_entry_type *src = native_symbols + this_index;
4739
6.08k
    table_ptr[this_index] = number_of_symbols;
4740
4741
6.08k
    dst->symbol.the_bfd = abfd;
4742
6.08k
    BFD_ASSERT (src->is_sym);
4743
6.08k
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4744
    /* We use the native name field to point to the cached field.  */
4745
6.08k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
6.08k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
6.08k
                 src->u.syment.n_scnum);
4748
6.08k
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
6.08k
    dst->symbol.value = 0;
4751
6.08k
    dst->done_lineno = false;
4752
4753
6.08k
    switch (src->u.syment.n_sclass)
4754
6.08k
      {
4755
36
      case C_EXT:
4756
38
      case C_WEAKEXT:
4757
#if defined ARM
4758
      case C_THUMBEXT:
4759
      case C_THUMBEXTFUNC:
4760
#endif
4761
#ifdef RS6000COFF_C
4762
      case C_HIDEXT:
4763
#ifndef AIX_WEAK_SUPPORT
4764
      case C_AIX_WEAKEXT:
4765
#endif
4766
#endif
4767
38
#ifdef C_SYSTEM
4768
43
      case C_SYSTEM: /* System Wide variable.  */
4769
43
#endif
4770
43
#ifdef COFF_WITH_PE
4771
      /* In PE, 0x68 (104) denotes a section symbol.  */
4772
43
      case C_SECTION:
4773
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4774
44
      case C_NT_WEAK:
4775
44
#endif
4776
44
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
44
    {
4778
21
    case COFF_SYMBOL_GLOBAL:
4779
21
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4780
21
#if defined COFF_WITH_PE
4781
      /* PE sets the symbol to a value relative to the
4782
         start of the section.  */
4783
21
      dst->symbol.value = src->u.syment.n_value;
4784
#else
4785
      dst->symbol.value = (src->u.syment.n_value
4786
               - dst->symbol.section->vma);
4787
#endif
4788
21
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
21
      break;
4793
4794
19
    case COFF_SYMBOL_COMMON:
4795
19
      dst->symbol.section = bfd_com_section_ptr;
4796
19
      dst->symbol.value = src->u.syment.n_value;
4797
19
      break;
4798
4799
4
    case COFF_SYMBOL_UNDEFINED:
4800
4
      dst->symbol.section = bfd_und_section_ptr;
4801
4
      dst->symbol.value = 0;
4802
4
      break;
4803
4804
0
    case COFF_SYMBOL_PE_SECTION:
4805
0
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4806
0
      dst->symbol.value = 0;
4807
0
      break;
4808
4809
0
    case COFF_SYMBOL_LOCAL:
4810
0
      dst->symbol.flags = BSF_LOCAL;
4811
0
#if defined COFF_WITH_PE
4812
      /* PE sets the symbol to a value relative to the
4813
         start of the section.  */
4814
0
      dst->symbol.value = src->u.syment.n_value;
4815
#else
4816
      dst->symbol.value = (src->u.syment.n_value
4817
               - dst->symbol.section->vma);
4818
#endif
4819
0
      if (ISFCN ((src->u.syment.n_type)))
4820
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4821
0
      break;
4822
44
    }
4823
4824
#ifdef RS6000COFF_C
4825
        /* A symbol with a csect entry should not go at the end.  */
4826
        if (src->u.syment.n_numaux > 0)
4827
    dst->symbol.flags |= BSF_NOT_AT_END;
4828
#endif
4829
4830
44
#ifdef COFF_WITH_PE
4831
44
        if (src->u.syment.n_sclass == C_NT_WEAK)
4832
1
    dst->symbol.flags |= BSF_WEAK;
4833
4834
44
        if (src->u.syment.n_sclass == C_SECTION
4835
44
      && src->u.syment.n_scnum > 0)
4836
0
    dst->symbol.flags = BSF_LOCAL;
4837
44
#endif
4838
44
        if (src->u.syment.n_sclass == C_WEAKEXT
4839
#ifdef RS6000COFF_C
4840
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4841
#endif
4842
44
      )
4843
2
    dst->symbol.flags |= BSF_WEAK;
4844
4845
44
        break;
4846
4847
84
      case C_STAT:  /* Static.  */
4848
#if defined ARM
4849
      case C_THUMBSTAT:    /* Thumb static.  */
4850
      case C_THUMBLABEL:   /* Thumb label.  */
4851
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4852
#endif
4853
#ifdef RS6000COFF_C
4854
      case C_DWARF:  /* A label in a dwarf section.  */
4855
      case C_INFO:   /* A label in a comment section.  */
4856
#endif
4857
85
      case C_LABEL:  /* Label.  */
4858
85
        if (src->u.syment.n_scnum == N_DEBUG)
4859
0
    dst->symbol.flags = BSF_DEBUGGING;
4860
85
        else
4861
85
    dst->symbol.flags = BSF_LOCAL;
4862
4863
        /* Base the value as an index from the base of the
4864
     section, if there is one.  */
4865
85
        if (dst->symbol.section)
4866
85
    {
4867
85
#if defined COFF_WITH_PE
4868
      /* PE sets the symbol to a value relative to the
4869
         start of the section.  */
4870
85
      dst->symbol.value = src->u.syment.n_value;
4871
#else
4872
      dst->symbol.value = (src->u.syment.n_value
4873
               - dst->symbol.section->vma);
4874
#endif
4875
85
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
85
        break;
4879
4880
14
      case C_FILE: /* File name.  */
4881
14
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
76
      case C_MOS:   /* Member of structure.  */
4884
94
      case C_EOS:   /* End of structure.  */
4885
100
      case C_REGPARM: /* Register parameter.  */
4886
105
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
117
      case C_TPDEF: /* Type definition.  */
4889
126
      case C_ARG:
4890
377
      case C_AUTO: /* Automatic variable.  */
4891
404
      case C_FIELD: /* Bit field.  */
4892
415
      case C_ENTAG: /* Enumeration tag.  */
4893
462
      case C_MOE:   /* Member of enumeration.  */
4894
465
      case C_MOU:   /* Member of union.  */
4895
477
      case C_UNTAG: /* Union tag.  */
4896
497
      case C_STRTAG: /* Structure tag.  */
4897
#ifdef RS6000COFF_C
4898
      case C_GSYM:
4899
      case C_LSYM:
4900
      case C_PSYM:
4901
      case C_RSYM:
4902
      case C_RPSYM:
4903
      case C_STSYM:
4904
      case C_TCSYM:
4905
      case C_BCOMM:
4906
      case C_ECOML:
4907
      case C_ECOMM:
4908
      case C_DECL:
4909
      case C_ENTRY:
4910
      case C_FUN:
4911
      case C_ESTAT:
4912
#endif
4913
497
        dst->symbol.flags |= BSF_DEBUGGING;
4914
497
        dst->symbol.value = (src->u.syment.n_value);
4915
497
        break;
4916
4917
#ifdef RS6000COFF_C
4918
      case C_BINCL: /* Beginning of include file.  */
4919
      case C_EINCL: /* Ending of include file.  */
4920
        /* The value is actually a pointer into the line numbers
4921
     of the file.  We locate the line number entry, and
4922
     set the section to the section which contains it, and
4923
     the value to the index in that section.  */
4924
        {
4925
    asection *sec;
4926
4927
    dst->symbol.flags = BSF_DEBUGGING;
4928
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4929
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4930
          && ((file_ptr) (sec->line_filepos
4931
              + sec->lineno_count * bfd_coff_linesz (abfd))
4932
        > (file_ptr) src->u.syment.n_value))
4933
        break;
4934
    if (sec == NULL)
4935
      dst->symbol.value = 0;
4936
    else
4937
      {
4938
        dst->symbol.section = sec;
4939
        dst->symbol.value = ((src->u.syment.n_value
4940
            - sec->line_filepos)
4941
           / bfd_coff_linesz (abfd));
4942
        src->fix_line = 1;
4943
      }
4944
        }
4945
        break;
4946
4947
      case C_BSTAT:
4948
        dst->symbol.flags = BSF_DEBUGGING;
4949
4950
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4951
    dst->symbol.value = 0;
4952
        else
4953
    {
4954
      /* The value is actually a symbol index.  Save a pointer
4955
         to the symbol instead of the index.  FIXME: This
4956
         should use a union.  */
4957
      src->u.syment.n_value
4958
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4959
      dst->symbol.value = src->u.syment.n_value;
4960
      src->fix_value = 1;
4961
    }
4962
        break;
4963
#endif
4964
4965
3
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
8
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
27
      case C_EFCN: /* Physical end of function.  */
4968
27
#if defined COFF_WITH_PE
4969
        /* PE sets the symbol to a value relative to the start
4970
     of the section.  */
4971
27
        dst->symbol.value = src->u.syment.n_value;
4972
27
        if (strcmp (dst->symbol.name, ".bf") != 0)
4973
27
    {
4974
      /* PE uses funny values for .ef and .lf; don't
4975
         relocate them.  */
4976
27
      dst->symbol.flags = BSF_DEBUGGING;
4977
27
    }
4978
0
        else
4979
0
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4980
#else
4981
        /* Base the value as an index from the base of the
4982
     section.  */
4983
        dst->symbol.flags = BSF_LOCAL;
4984
        dst->symbol.value = (src->u.syment.n_value
4985
           - dst->symbol.section->vma);
4986
#endif
4987
27
        break;
4988
4989
7
      case C_STATLAB: /* Static load time label.  */
4990
7
        dst->symbol.value = src->u.syment.n_value;
4991
7
        dst->symbol.flags = BSF_GLOBAL;
4992
7
        break;
4993
4994
4.89k
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
4.89k
        if (src->u.syment.n_type == 0
4998
4.89k
      && src->u.syment.n_value == 0
4999
4.89k
      && src->u.syment.n_scnum == 0)
5000
2.33k
    break;
5001
#ifdef RS6000COFF_C
5002
        /* XCOFF specific: deleted entry.  */
5003
        if (src->u.syment.n_value == C_NULL_VALUE)
5004
    break;
5005
#endif
5006
        /* Fall through.  */
5007
2.57k
      case C_EXTDEF: /* External definition.  */
5008
2.57k
      case C_ULABEL: /* Undefined label.  */
5009
2.57k
      case C_USTATIC: /* Undefined static.  */
5010
#ifndef COFF_WITH_PE
5011
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5012
         class to represent a section symbol.  */
5013
      case C_LINE:  /* line # reformatted as symbol table entry.  */
5014
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5015
      case C_ALIAS: /* Duplicate tag.  */
5016
#endif
5017
        /* New storage classes for TI COFF.  */
5018
#ifdef TICOFF
5019
      case C_UEXT:  /* Tentative external definition.  */
5020
#endif
5021
2.58k
      case C_EXTLAB: /* External load time label.  */
5022
3.04k
      default:
5023
3.04k
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
3.04k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
3.04k
     abfd, src->u.syment.n_sclass,
5027
3.04k
     dst->symbol.section->name, dst->symbol.name);
5028
3.04k
        ret = false;
5029
        /* Fall through.  */
5030
3.08k
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5031
        /* PR 20722: These symbols can also be generated by
5032
     building DLLs with --gc-sections enabled.  */
5033
3.08k
        dst->symbol.flags = BSF_DEBUGGING;
5034
3.08k
        dst->symbol.value = (src->u.syment.n_value);
5035
3.08k
        break;
5036
6.08k
      }
5037
5038
6.08k
    dst->native = src;
5039
6.08k
    dst->symbol.udata.i = 0;
5040
6.08k
    dst->lineno = NULL;
5041
5042
6.08k
    this_index += (src->u.syment.n_numaux) + 1;
5043
6.08k
    dst++;
5044
6.08k
    number_of_symbols++;
5045
6.08k
  }
5046
17
    }
5047
5048
17
  obj_symbols (abfd) = cached_area;
5049
17
  obj_raw_syments (abfd) = native_symbols;
5050
5051
17
  abfd->symcount = number_of_symbols;
5052
17
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
17
  {
5055
17
    asection *p;
5056
5057
17
    p = abfd->sections;
5058
747
    while (p)
5059
746
      {
5060
746
  if (! coff_slurp_line_table (abfd, p))
5061
16
    return false;
5062
730
  p = p->next;
5063
730
      }
5064
17
  }
5065
5066
1
  return ret;
5067
17
}
5068
5069
/* Classify a COFF symbol.  A couple of targets have globally visible
5070
   symbols which are not class C_EXT, and this handles those.  It also
5071
   recognizes some special PE cases.  */
5072
5073
static enum coff_symbol_classification
5074
coff_classify_symbol (bfd *abfd,
5075
          struct internal_syment *syment)
5076
23.1k
{
5077
  /* FIXME: This partially duplicates the switch in
5078
     coff_slurp_symbol_table.  */
5079
23.1k
  switch (syment->n_sclass)
5080
23.1k
    {
5081
10.7k
    case C_EXT:
5082
10.9k
    case C_WEAKEXT:
5083
#ifdef ARM
5084
18
    case C_THUMBEXT:
5085
18
    case C_THUMBEXTFUNC:
5086
#endif
5087
#ifdef RS6000COFF_C
5088
2.36k
    case C_HIDEXT:
5089
2.36k
#ifndef AIX_WEAK_SUPPORT
5090
2.49k
    case C_AIX_WEAKEXT:
5091
#endif
5092
#endif
5093
2.49k
#ifdef C_SYSTEM
5094
11.4k
    case C_SYSTEM:
5095
11.4k
#endif
5096
#ifdef COFF_WITH_PE
5097
6.28k
    case C_NT_WEAK:
5098
#endif
5099
11.5k
      if (syment->n_scnum == 0)
5100
1.78k
  {
5101
1.78k
    if (syment->n_value == 0)
5102
611
      return COFF_SYMBOL_UNDEFINED;
5103
1.16k
    else
5104
1.16k
      return COFF_SYMBOL_COMMON;
5105
1.78k
  }
5106
#ifdef RS6000COFF_C
5107
2.10k
      if (syment->n_sclass == C_HIDEXT)
5108
51
  return COFF_SYMBOL_LOCAL;
5109
2.05k
#endif
5110
9.67k
      return COFF_SYMBOL_GLOBAL;
5111
5112
11.6k
    default:
5113
11.6k
      break;
5114
23.1k
    }
5115
5116
#ifdef COFF_WITH_PE
5117
11.6k
  if (syment->n_sclass == C_STAT)
5118
418
    {
5119
418
      if (syment->n_scnum == 0)
5120
  /* The Microsoft compiler sometimes generates these if a
5121
     small static function is inlined every time it is used.
5122
     The function is discarded, but the symbol table entry
5123
     remains.  */
5124
131
  return COFF_SYMBOL_LOCAL;
5125
5126
#ifdef STRICT_PE_FORMAT
5127
      /* This is correct for Microsoft generated objects, but it
5128
   breaks gas generated objects.  */
5129
      if (syment->n_value == 0)
5130
  {
5131
    const asection *sec;
5132
    const char *name;
5133
    char buf[SYMNMLEN + 1];
5134
5135
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5136
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5137
    if (sec != NULL && name != NULL
5138
        && (strcmp (bfd_section_name (sec), name) == 0))
5139
      return COFF_SYMBOL_PE_SECTION;
5140
  }
5141
#endif
5142
5143
287
      return COFF_SYMBOL_LOCAL;
5144
418
    }
5145
5146
11.2k
  if (syment->n_sclass == C_SECTION)
5147
26
    {
5148
      /* In some cases in a DLL generated by the Microsoft linker, the
5149
   n_value field will contain garbage.  FIXME: This should
5150
   probably be handled by the swapping function instead.  */
5151
26
      syment->n_value = 0;
5152
26
      if (syment->n_scnum == 0)
5153
26
  return COFF_SYMBOL_UNDEFINED;
5154
0
      return COFF_SYMBOL_PE_SECTION;
5155
26
    }
5156
11.2k
#endif /* COFF_WITH_PE */
5157
5158
  /* If it is not a global symbol, we presume it is a local symbol.  */
5159
11.2k
  if (syment->n_scnum == 0)
5160
11.1k
    {
5161
11.1k
      char buf[SYMNMLEN + 1];
5162
5163
11.1k
      _bfd_error_handler
5164
  /* xgettext:c-format */
5165
11.1k
  (_("warning: %pB: local symbol `%s' has no section"),
5166
11.1k
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5167
11.1k
    }
5168
5169
11.2k
  return COFF_SYMBOL_LOCAL;
5170
11.2k
}
pei-i386.c:coff_classify_symbol
Line
Count
Source
5076
99
{
5077
  /* FIXME: This partially duplicates the switch in
5078
     coff_slurp_symbol_table.  */
5079
99
  switch (syment->n_sclass)
5080
99
    {
5081
78
    case C_EXT:
5082
83
    case C_WEAKEXT:
5083
#ifdef ARM
5084
    case C_THUMBEXT:
5085
    case C_THUMBEXTFUNC:
5086
#endif
5087
#ifdef RS6000COFF_C
5088
    case C_HIDEXT:
5089
#ifndef AIX_WEAK_SUPPORT
5090
    case C_AIX_WEAKEXT:
5091
#endif
5092
#endif
5093
83
#ifdef C_SYSTEM
5094
88
    case C_SYSTEM:
5095
88
#endif
5096
88
#ifdef COFF_WITH_PE
5097
94
    case C_NT_WEAK:
5098
94
#endif
5099
94
      if (syment->n_scnum == 0)
5100
24
  {
5101
24
    if (syment->n_value == 0)
5102
5
      return COFF_SYMBOL_UNDEFINED;
5103
19
    else
5104
19
      return COFF_SYMBOL_COMMON;
5105
24
  }
5106
#ifdef RS6000COFF_C
5107
      if (syment->n_sclass == C_HIDEXT)
5108
  return COFF_SYMBOL_LOCAL;
5109
#endif
5110
70
      return COFF_SYMBOL_GLOBAL;
5111
5112
5
    default:
5113
5
      break;
5114
99
    }
5115
5116
5
#ifdef COFF_WITH_PE
5117
5
  if (syment->n_sclass == C_STAT)
5118
0
    {
5119
0
      if (syment->n_scnum == 0)
5120
  /* The Microsoft compiler sometimes generates these if a
5121
     small static function is inlined every time it is used.
5122
     The function is discarded, but the symbol table entry
5123
     remains.  */
5124
0
  return COFF_SYMBOL_LOCAL;
5125
5126
#ifdef STRICT_PE_FORMAT
5127
      /* This is correct for Microsoft generated objects, but it
5128
   breaks gas generated objects.  */
5129
      if (syment->n_value == 0)
5130
  {
5131
    const asection *sec;
5132
    const char *name;
5133
    char buf[SYMNMLEN + 1];
5134
5135
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5136
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5137
    if (sec != NULL && name != NULL
5138
        && (strcmp (bfd_section_name (sec), name) == 0))
5139
      return COFF_SYMBOL_PE_SECTION;
5140
  }
5141
#endif
5142
5143
0
      return COFF_SYMBOL_LOCAL;
5144
0
    }
5145
5146
5
  if (syment->n_sclass == C_SECTION)
5147
5
    {
5148
      /* In some cases in a DLL generated by the Microsoft linker, the
5149
   n_value field will contain garbage.  FIXME: This should
5150
   probably be handled by the swapping function instead.  */
5151
5
      syment->n_value = 0;
5152
5
      if (syment->n_scnum == 0)
5153
5
  return COFF_SYMBOL_UNDEFINED;
5154
0
      return COFF_SYMBOL_PE_SECTION;
5155
5
    }
5156
0
#endif /* COFF_WITH_PE */
5157
5158
  /* If it is not a global symbol, we presume it is a local symbol.  */
5159
0
  if (syment->n_scnum == 0)
5160
0
    {
5161
0
      char buf[SYMNMLEN + 1];
5162
5163
0
      _bfd_error_handler
5164
  /* xgettext:c-format */
5165
0
  (_("warning: %pB: local symbol `%s' has no section"),
5166
0
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5167
0
    }
5168
5169
0
  return COFF_SYMBOL_LOCAL;
5170
5
}
pe-x86_64.c:coff_classify_symbol
Line
Count
Source
5076
283
{
5077
  /* FIXME: This partially duplicates the switch in
5078
     coff_slurp_symbol_table.  */
5079
283
  switch (syment->n_sclass)
5080
283
    {
5081
228
    case C_EXT:
5082
233
    case C_WEAKEXT:
5083
#ifdef ARM
5084
    case C_THUMBEXT:
5085
    case C_THUMBEXTFUNC:
5086
#endif
5087
#ifdef RS6000COFF_C
5088
    case C_HIDEXT:
5089
#ifndef AIX_WEAK_SUPPORT
5090
    case C_AIX_WEAKEXT:
5091
#endif
5092
#endif
5093
233
#ifdef C_SYSTEM
5094
272
    case C_SYSTEM:
5095
272
#endif
5096
272
#ifdef COFF_WITH_PE
5097
283
    case C_NT_WEAK:
5098
283
#endif
5099
283
      if (syment->n_scnum == 0)
5100
120
  {
5101
120
    if (syment->n_value == 0)
5102
13
      return COFF_SYMBOL_UNDEFINED;
5103
107
    else
5104
107
      return COFF_SYMBOL_COMMON;
5105
120
  }
5106
#ifdef RS6000COFF_C
5107
      if (syment->n_sclass == C_HIDEXT)
5108
  return COFF_SYMBOL_LOCAL;
5109
#endif
5110
163
      return COFF_SYMBOL_GLOBAL;
5111
5112
0
    default:
5113
0
      break;
5114
283
    }
5115
5116
0
#ifdef COFF_WITH_PE
5117
0
  if (syment->n_sclass == C_STAT)
5118
0
    {
5119
0
      if (syment->n_scnum == 0)
5120
  /* The Microsoft compiler sometimes generates these if a
5121
     small static function is inlined every time it is used.
5122
     The function is discarded, but the symbol table entry
5123
     remains.  */
5124
0
  return COFF_SYMBOL_LOCAL;
5125
5126
#ifdef STRICT_PE_FORMAT
5127
      /* This is correct for Microsoft generated objects, but it
5128
   breaks gas generated objects.  */
5129
      if (syment->n_value == 0)
5130
  {
5131
    const asection *sec;
5132
    const char *name;
5133
    char buf[SYMNMLEN + 1];
5134
5135
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5136
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5137
    if (sec != NULL && name != NULL
5138
        && (strcmp (bfd_section_name (sec), name) == 0))
5139
      return COFF_SYMBOL_PE_SECTION;
5140
  }
5141
#endif
5142
5143
0
      return COFF_SYMBOL_LOCAL;
5144
0
    }
5145
5146
0
  if (syment->n_sclass == C_SECTION)
5147
0
    {
5148
      /* In some cases in a DLL generated by the Microsoft linker, the
5149
   n_value field will contain garbage.  FIXME: This should
5150
   probably be handled by the swapping function instead.  */
5151
0
      syment->n_value = 0;
5152
0
      if (syment->n_scnum == 0)
5153
0
  return COFF_SYMBOL_UNDEFINED;
5154
0
      return COFF_SYMBOL_PE_SECTION;
5155
0
    }
5156
0
#endif /* COFF_WITH_PE */
5157
5158
  /* If it is not a global symbol, we presume it is a local symbol.  */
5159
0
  if (syment->n_scnum == 0)
5160
0
    {
5161
0
      char buf[SYMNMLEN + 1];
5162
5163
0
      _bfd_error_handler
5164
  /* xgettext:c-format */
5165
0
  (_("warning: %pB: local symbol `%s' has no section"),
5166
0
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5167
0
    }
5168
5169
0
  return COFF_SYMBOL_LOCAL;
5170
0
}
pei-x86_64.c:coff_classify_symbol
Line
Count
Source
5076
1.91k
{
5077
  /* FIXME: This partially duplicates the switch in
5078
     coff_slurp_symbol_table.  */
5079
1.91k
  switch (syment->n_sclass)
5080
1.91k
    {
5081
1.54k
    case C_EXT:
5082
1.54k
    case C_WEAKEXT:
5083
#ifdef ARM
5084
    case C_THUMBEXT:
5085
    case C_THUMBEXTFUNC:
5086
#endif
5087
#ifdef RS6000COFF_C
5088
    case C_HIDEXT:
5089
#ifndef AIX_WEAK_SUPPORT
5090
    case C_AIX_WEAKEXT:
5091
#endif
5092
#endif
5093
1.54k
#ifdef C_SYSTEM
5094
1.55k
    case C_SYSTEM:
5095
1.55k
#endif
5096
1.55k
#ifdef COFF_WITH_PE
5097
1.56k
    case C_NT_WEAK:
5098
1.56k
#endif
5099
1.56k
      if (syment->n_scnum == 0)
5100
367
  {
5101
367
    if (syment->n_value == 0)
5102
317
      return COFF_SYMBOL_UNDEFINED;
5103
50
    else
5104
50
      return COFF_SYMBOL_COMMON;
5105
367
  }
5106
#ifdef RS6000COFF_C
5107
      if (syment->n_sclass == C_HIDEXT)
5108
  return COFF_SYMBOL_LOCAL;
5109
#endif
5110
1.19k
      return COFF_SYMBOL_GLOBAL;
5111
5112
359
    default:
5113
359
      break;
5114
1.91k
    }
5115
5116
359
#ifdef COFF_WITH_PE
5117
359
  if (syment->n_sclass == C_STAT)
5118
290
    {
5119
290
      if (syment->n_scnum == 0)
5120
  /* The Microsoft compiler sometimes generates these if a
5121
     small static function is inlined every time it is used.
5122
     The function is discarded, but the symbol table entry
5123
     remains.  */
5124
3
  return COFF_SYMBOL_LOCAL;
5125
5126
#ifdef STRICT_PE_FORMAT
5127
      /* This is correct for Microsoft generated objects, but it
5128
   breaks gas generated objects.  */
5129
      if (syment->n_value == 0)
5130
  {
5131
    const asection *sec;
5132
    const char *name;
5133
    char buf[SYMNMLEN + 1];
5134
5135
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5136
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5137
    if (sec != NULL && name != NULL
5138
        && (strcmp (bfd_section_name (sec), name) == 0))
5139
      return COFF_SYMBOL_PE_SECTION;
5140
  }
5141
#endif
5142
5143
287
      return COFF_SYMBOL_LOCAL;
5144
290
    }
5145
5146
69
  if (syment->n_sclass == C_SECTION)
5147
7
    {
5148
      /* In some cases in a DLL generated by the Microsoft linker, the
5149
   n_value field will contain garbage.  FIXME: This should
5150
   probably be handled by the swapping function instead.  */
5151
7
      syment->n_value = 0;
5152
7
      if (syment->n_scnum == 0)
5153
7
  return COFF_SYMBOL_UNDEFINED;
5154
0
      return COFF_SYMBOL_PE_SECTION;
5155
7
    }
5156
62
#endif /* COFF_WITH_PE */
5157
5158
  /* If it is not a global symbol, we presume it is a local symbol.  */
5159
62
  if (syment->n_scnum == 0)
5160
31
    {
5161
31
      char buf[SYMNMLEN + 1];
5162
5163
31
      _bfd_error_handler
5164
  /* xgettext:c-format */
5165
31
  (_("warning: %pB: local symbol `%s' has no section"),
5166
31
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5167
31
    }
5168
5169
62
  return COFF_SYMBOL_LOCAL;
5170
69
}
coff-x86_64.c:coff_classify_symbol
Line
Count
Source
5076
301
{
5077
  /* FIXME: This partially duplicates the switch in
5078
     coff_slurp_symbol_table.  */
5079
301
  switch (syment->n_sclass)
5080
301
    {
5081
280
    case C_EXT:
5082
287
    case C_WEAKEXT:
5083
#ifdef ARM
5084
    case C_THUMBEXT:
5085
    case C_THUMBEXTFUNC:
5086
#endif
5087
#ifdef RS6000COFF_C
5088
    case C_HIDEXT:
5089
#ifndef AIX_WEAK_SUPPORT
5090
    case C_AIX_WEAKEXT:
5091
#endif
5092
#endif
5093
287
#ifdef C_SYSTEM
5094
301
    case C_SYSTEM:
5095
301
#endif
5096
#ifdef COFF_WITH_PE
5097
    case C_NT_WEAK:
5098
#endif
5099
301
      if (syment->n_scnum == 0)
5100
93
  {
5101
93
    if (syment->n_value == 0)
5102
10
      return COFF_SYMBOL_UNDEFINED;
5103
83
    else
5104
83
      return COFF_SYMBOL_COMMON;
5105
93
  }
5106
#ifdef RS6000COFF_C
5107
      if (syment->n_sclass == C_HIDEXT)
5108
  return COFF_SYMBOL_LOCAL;
5109
#endif
5110
208
      return COFF_SYMBOL_GLOBAL;
5111
5112
0
    default:
5113
0
      break;
5114
301
    }
5115
5116
#ifdef COFF_WITH_PE
5117
  if (syment->n_sclass == C_STAT)
5118
    {
5119
      if (syment->n_scnum == 0)
5120
  /* The Microsoft compiler sometimes generates these if a
5121
     small static function is inlined every time it is used.
5122
     The function is discarded, but the symbol table entry
5123
     remains.  */
5124
  return COFF_SYMBOL_LOCAL;
5125
5126
#ifdef STRICT_PE_FORMAT
5127
      /* This is correct for Microsoft generated objects, but it
5128
   breaks gas generated objects.  */
5129
      if (syment->n_value == 0)
5130
  {
5131
    const asection *sec;
5132
    const char *name;
5133
    char buf[SYMNMLEN + 1];
5134
5135
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5136
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5137
    if (sec != NULL && name != NULL
5138
        && (strcmp (bfd_section_name (sec), name) == 0))
5139
      return COFF_SYMBOL_PE_SECTION;
5140
  }
5141
#endif
5142
5143
      return COFF_SYMBOL_LOCAL;
5144
    }
5145
5146
  if (syment->n_sclass == C_SECTION)
5147
    {
5148
      /* In some cases in a DLL generated by the Microsoft linker, the
5149
   n_value field will contain garbage.  FIXME: This should
5150
   probably be handled by the swapping function instead.  */
5151
      syment->n_value = 0;
5152
      if (syment->n_scnum == 0)
5153
  return COFF_SYMBOL_UNDEFINED;
5154
      return COFF_SYMBOL_PE_SECTION;
5155
    }
5156
#endif /* COFF_WITH_PE */
5157
5158
  /* If it is not a global symbol, we presume it is a local symbol.  */
5159
0
  if (syment->n_scnum == 0)
5160
0
    {
5161
0
      char buf[SYMNMLEN + 1];
5162
5163
0
      _bfd_error_handler
5164
  /* xgettext:c-format */
5165
0
  (_("warning: %pB: local symbol `%s' has no section"),
5166
0
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5167
0
    }
5168
5169
0
  return COFF_SYMBOL_LOCAL;
5170
301
}
coff64-rs6000.c:coff_classify_symbol
Line
Count
Source
5076
1.74k
{
5077
  /* FIXME: This partially duplicates the switch in
5078
     coff_slurp_symbol_table.  */
5079
1.74k
  switch (syment->n_sclass)
5080
1.74k
    {
5081
1.61k
    case C_EXT:
5082
1.64k
    case C_WEAKEXT:
5083
#ifdef ARM
5084
    case C_THUMBEXT:
5085
    case C_THUMBEXTFUNC:
5086
#endif
5087
1.64k
#ifdef RS6000COFF_C
5088
1.66k
    case C_HIDEXT:
5089
1.66k
#ifndef AIX_WEAK_SUPPORT
5090
1.72k
    case C_AIX_WEAKEXT:
5091
1.72k
#endif
5092
1.72k
#endif
5093
1.72k
#ifdef C_SYSTEM
5094
1.74k
    case C_SYSTEM:
5095
1.74k
#endif
5096
#ifdef COFF_WITH_PE
5097
    case C_NT_WEAK:
5098
#endif
5099
1.74k
      if (syment->n_scnum == 0)
5100
402
  {
5101
402
    if (syment->n_value == 0)
5102
111
      return COFF_SYMBOL_UNDEFINED;
5103
291
    else
5104
291
      return COFF_SYMBOL_COMMON;
5105
402
  }
5106
1.34k
#ifdef RS6000COFF_C
5107
1.34k
      if (syment->n_sclass == C_HIDEXT)
5108
11
  return COFF_SYMBOL_LOCAL;
5109
1.33k
#endif
5110
1.33k
      return COFF_SYMBOL_GLOBAL;
5111
5112
0
    default:
5113
0
      break;
5114
1.74k
    }
5115
5116
#ifdef COFF_WITH_PE
5117
  if (syment->n_sclass == C_STAT)
5118
    {
5119
      if (syment->n_scnum == 0)
5120
  /* The Microsoft compiler sometimes generates these if a
5121
     small static function is inlined every time it is used.
5122
     The function is discarded, but the symbol table entry
5123
     remains.  */
5124
  return COFF_SYMBOL_LOCAL;
5125
5126
#ifdef STRICT_PE_FORMAT
5127
      /* This is correct for Microsoft generated objects, but it
5128
   breaks gas generated objects.  */
5129
      if (syment->n_value == 0)
5130
  {
5131
    const asection *sec;
5132
    const char *name;
5133
    char buf[SYMNMLEN + 1];
5134
5135
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5136
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5137
    if (sec != NULL && name != NULL
5138
        && (strcmp (bfd_section_name (sec), name) == 0))
5139
      return COFF_SYMBOL_PE_SECTION;
5140
  }
5141
#endif
5142
5143
      return COFF_SYMBOL_LOCAL;
5144
    }
5145
5146
  if (syment->n_sclass == C_SECTION)
5147
    {
5148
      /* In some cases in a DLL generated by the Microsoft linker, the
5149
   n_value field will contain garbage.  FIXME: This should
5150
   probably be handled by the swapping function instead.  */
5151
      syment->n_value = 0;
5152
      if (syment->n_scnum == 0)
5153
  return COFF_SYMBOL_UNDEFINED;
5154
      return COFF_SYMBOL_PE_SECTION;
5155
    }
5156
#endif /* COFF_WITH_PE */
5157
5158
  /* If it is not a global symbol, we presume it is a local symbol.  */
5159
0
  if (syment->n_scnum == 0)
5160
0
    {
5161
0
      char buf[SYMNMLEN + 1];
5162
5163
0
      _bfd_error_handler
5164
  /* xgettext:c-format */
5165
0
  (_("warning: %pB: local symbol `%s' has no section"),
5166
0
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5167
0
    }
5168
5169
0
  return COFF_SYMBOL_LOCAL;
5170
1.74k
}
pe-aarch64.c:coff_classify_symbol
Line
Count
Source
5076
181
{
5077
  /* FIXME: This partially duplicates the switch in
5078
     coff_slurp_symbol_table.  */
5079
181
  switch (syment->n_sclass)
5080
181
    {
5081
49
    case C_EXT:
5082
49
    case C_WEAKEXT:
5083
#ifdef ARM
5084
    case C_THUMBEXT:
5085
    case C_THUMBEXTFUNC:
5086
#endif
5087
#ifdef RS6000COFF_C
5088
    case C_HIDEXT:
5089
#ifndef AIX_WEAK_SUPPORT
5090
    case C_AIX_WEAKEXT:
5091
#endif
5092
#endif
5093
49
#ifdef C_SYSTEM
5094
49
    case C_SYSTEM:
5095
49
#endif
5096
49
#ifdef COFF_WITH_PE
5097
52
    case C_NT_WEAK:
5098
52
#endif
5099
52
      if (syment->n_scnum == 0)
5100
6
  {
5101
6
    if (syment->n_value == 0)
5102
0
      return COFF_SYMBOL_UNDEFINED;
5103
6
    else
5104
6
      return COFF_SYMBOL_COMMON;
5105
6
  }
5106
#ifdef RS6000COFF_C
5107
      if (syment->n_sclass == C_HIDEXT)
5108
  return COFF_SYMBOL_LOCAL;
5109
#endif
5110
46
      return COFF_SYMBOL_GLOBAL;
5111
5112
129
    default:
5113
129
      break;
5114
181
    }
5115
5116
129
#ifdef COFF_WITH_PE
5117
129
  if (syment->n_sclass == C_STAT)
5118
0
    {
5119
0
      if (syment->n_scnum == 0)
5120
  /* The Microsoft compiler sometimes generates these if a
5121
     small static function is inlined every time it is used.
5122
     The function is discarded, but the symbol table entry
5123
     remains.  */
5124
0
  return COFF_SYMBOL_LOCAL;
5125
5126
#ifdef STRICT_PE_FORMAT
5127
      /* This is correct for Microsoft generated objects, but it
5128
   breaks gas generated objects.  */
5129
      if (syment->n_value == 0)
5130
  {
5131
    const asection *sec;
5132
    const char *name;
5133
    char buf[SYMNMLEN + 1];
5134
5135
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5136
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5137
    if (sec != NULL && name != NULL
5138
        && (strcmp (bfd_section_name (sec), name) == 0))
5139
      return COFF_SYMBOL_PE_SECTION;
5140
  }
5141
#endif
5142
5143
0
      return COFF_SYMBOL_LOCAL;
5144
0
    }
5145
5146
129
  if (syment->n_sclass == C_SECTION)
5147
0
    {
5148
      /* In some cases in a DLL generated by the Microsoft linker, the
5149
   n_value field will contain garbage.  FIXME: This should
5150
   probably be handled by the swapping function instead.  */
5151
0
      syment->n_value = 0;
5152
0
      if (syment->n_scnum == 0)
5153
0
  return COFF_SYMBOL_UNDEFINED;
5154
0
      return COFF_SYMBOL_PE_SECTION;
5155
0
    }
5156
129
#endif /* COFF_WITH_PE */
5157
5158
  /* If it is not a global symbol, we presume it is a local symbol.  */
5159
129
  if (syment->n_scnum == 0)
5160
129
    {
5161
129
      char buf[SYMNMLEN + 1];
5162
5163
129
      _bfd_error_handler
5164
  /* xgettext:c-format */
5165
129
  (_("warning: %pB: local symbol `%s' has no section"),
5166
129
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5167
129
    }
5168
5169
129
  return COFF_SYMBOL_LOCAL;
5170
129
}
pei-aarch64.c:coff_classify_symbol
Line
Count
Source
5076
215
{
5077
  /* FIXME: This partially duplicates the switch in
5078
     coff_slurp_symbol_table.  */
5079
215
  switch (syment->n_sclass)
5080
215
    {
5081
209
    case C_EXT:
5082
209
    case C_WEAKEXT:
5083
#ifdef ARM
5084
    case C_THUMBEXT:
5085
    case C_THUMBEXTFUNC:
5086
#endif
5087
#ifdef RS6000COFF_C
5088
    case C_HIDEXT:
5089
#ifndef AIX_WEAK_SUPPORT
5090
    case C_AIX_WEAKEXT:
5091
#endif
5092
#endif
5093
209
#ifdef C_SYSTEM
5094
213
    case C_SYSTEM:
5095
213
#endif
5096
213
#ifdef COFF_WITH_PE
5097
214
    case C_NT_WEAK:
5098
214
#endif
5099
214
      if (syment->n_scnum == 0)
5100
18
  {
5101
18
    if (syment->n_value == 0)
5102
7
      return COFF_SYMBOL_UNDEFINED;
5103
11
    else
5104
11
      return COFF_SYMBOL_COMMON;
5105
18
  }
5106
#ifdef RS6000COFF_C
5107
      if (syment->n_sclass == C_HIDEXT)
5108
  return COFF_SYMBOL_LOCAL;
5109
#endif
5110
196
      return COFF_SYMBOL_GLOBAL;
5111
5112
1
    default:
5113
1
      break;
5114
215
    }
5115
5116
1
#ifdef COFF_WITH_PE
5117
1
  if (syment->n_sclass == C_STAT)
5118
0
    {
5119
0
      if (syment->n_scnum == 0)
5120
  /* The Microsoft compiler sometimes generates these if a
5121
     small static function is inlined every time it is used.
5122
     The function is discarded, but the symbol table entry
5123
     remains.  */
5124
0
  return COFF_SYMBOL_LOCAL;
5125
5126
#ifdef STRICT_PE_FORMAT
5127
      /* This is correct for Microsoft generated objects, but it
5128
   breaks gas generated objects.  */
5129
      if (syment->n_value == 0)
5130
  {
5131
    const asection *sec;
5132
    const char *name;
5133
    char buf[SYMNMLEN + 1];
5134
5135
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5136
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5137
    if (sec != NULL && name != NULL
5138
        && (strcmp (bfd_section_name (sec), name) == 0))
5139
      return COFF_SYMBOL_PE_SECTION;
5140
  }
5141
#endif
5142
5143
0
      return COFF_SYMBOL_LOCAL;
5144
0
    }
5145
5146
1
  if (syment->n_sclass == C_SECTION)
5147
1
    {
5148
      /* In some cases in a DLL generated by the Microsoft linker, the
5149
   n_value field will contain garbage.  FIXME: This should
5150
   probably be handled by the swapping function instead.  */
5151
1
      syment->n_value = 0;
5152
1
      if (syment->n_scnum == 0)
5153
1
  return COFF_SYMBOL_UNDEFINED;
5154
0
      return COFF_SYMBOL_PE_SECTION;
5155
1
    }
5156
0
#endif /* COFF_WITH_PE */
5157
5158
  /* If it is not a global symbol, we presume it is a local symbol.  */
5159
0
  if (syment->n_scnum == 0)
5160
0
    {
5161
0
      char buf[SYMNMLEN + 1];
5162
5163
0
      _bfd_error_handler
5164
  /* xgettext:c-format */
5165
0
  (_("warning: %pB: local symbol `%s' has no section"),
5166
0
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5167
0
    }
5168
5169
0
  return COFF_SYMBOL_LOCAL;
5170
1
}
pei-ia64.c:coff_classify_symbol
Line
Count
Source
5076
199
{
5077
  /* FIXME: This partially duplicates the switch in
5078
     coff_slurp_symbol_table.  */
5079
199
  switch (syment->n_sclass)
5080
199
    {
5081
182
    case C_EXT:
5082
187
    case C_WEAKEXT:
5083
#ifdef ARM
5084
    case C_THUMBEXT:
5085
    case C_THUMBEXTFUNC:
5086
#endif
5087
#ifdef RS6000COFF_C
5088
    case C_HIDEXT:
5089
#ifndef AIX_WEAK_SUPPORT
5090
    case C_AIX_WEAKEXT:
5091
#endif
5092
#endif
5093
187
#ifdef C_SYSTEM
5094
190
    case C_SYSTEM:
5095
190
#endif
5096
190
#ifdef COFF_WITH_PE
5097
199
    case C_NT_WEAK:
5098
199
#endif
5099
199
      if (syment->n_scnum == 0)
5100
85
  {
5101
85
    if (syment->n_value == 0)
5102
8
      return COFF_SYMBOL_UNDEFINED;
5103
77
    else
5104
77
      return COFF_SYMBOL_COMMON;
5105
85
  }
5106
#ifdef RS6000COFF_C
5107
      if (syment->n_sclass == C_HIDEXT)
5108
  return COFF_SYMBOL_LOCAL;
5109
#endif
5110
114
      return COFF_SYMBOL_GLOBAL;
5111
5112
0
    default:
5113
0
      break;
5114
199
    }
5115
5116
0
#ifdef COFF_WITH_PE
5117
0
  if (syment->n_sclass == C_STAT)
5118
0
    {
5119
0
      if (syment->n_scnum == 0)
5120
  /* The Microsoft compiler sometimes generates these if a
5121
     small static function is inlined every time it is used.
5122
     The function is discarded, but the symbol table entry
5123
     remains.  */
5124
0
  return COFF_SYMBOL_LOCAL;
5125
5126
#ifdef STRICT_PE_FORMAT
5127
      /* This is correct for Microsoft generated objects, but it
5128
   breaks gas generated objects.  */
5129
      if (syment->n_value == 0)
5130
  {
5131
    const asection *sec;
5132
    const char *name;
5133
    char buf[SYMNMLEN + 1];
5134
5135
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5136
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5137
    if (sec != NULL && name != NULL
5138
        && (strcmp (bfd_section_name (sec), name) == 0))
5139
      return COFF_SYMBOL_PE_SECTION;
5140
  }
5141
#endif
5142
5143
0
      return COFF_SYMBOL_LOCAL;
5144
0
    }
5145
5146
0
  if (syment->n_sclass == C_SECTION)
5147
0
    {
5148
      /* In some cases in a DLL generated by the Microsoft linker, the
5149
   n_value field will contain garbage.  FIXME: This should
5150
   probably be handled by the swapping function instead.  */
5151
0
      syment->n_value = 0;
5152
0
      if (syment->n_scnum == 0)
5153
0
  return COFF_SYMBOL_UNDEFINED;
5154
0
      return COFF_SYMBOL_PE_SECTION;
5155
0
    }
5156
0
#endif /* COFF_WITH_PE */
5157
5158
  /* If it is not a global symbol, we presume it is a local symbol.  */
5159
0
  if (syment->n_scnum == 0)
5160
0
    {
5161
0
      char buf[SYMNMLEN + 1];
5162
5163
0
      _bfd_error_handler
5164
  /* xgettext:c-format */
5165
0
  (_("warning: %pB: local symbol `%s' has no section"),
5166
0
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5167
0
    }
5168
5169
0
  return COFF_SYMBOL_LOCAL;
5170
0
}
pei-loongarch64.c:coff_classify_symbol
Line
Count
Source
5076
247
{
5077
  /* FIXME: This partially duplicates the switch in
5078
     coff_slurp_symbol_table.  */
5079
247
  switch (syment->n_sclass)
5080
247
    {
5081
211
    case C_EXT:
5082
217
    case C_WEAKEXT:
5083
#ifdef ARM
5084
    case C_THUMBEXT:
5085
    case C_THUMBEXTFUNC:
5086
#endif
5087
#ifdef RS6000COFF_C
5088
    case C_HIDEXT:
5089
#ifndef AIX_WEAK_SUPPORT
5090
    case C_AIX_WEAKEXT:
5091
#endif
5092
#endif
5093
217
#ifdef C_SYSTEM
5094
229
    case C_SYSTEM:
5095
229
#endif
5096
229
#ifdef COFF_WITH_PE
5097
247
    case C_NT_WEAK:
5098
247
#endif
5099
247
      if (syment->n_scnum == 0)
5100
45
  {
5101
45
    if (syment->n_value == 0)
5102
3
      return COFF_SYMBOL_UNDEFINED;
5103
42
    else
5104
42
      return COFF_SYMBOL_COMMON;
5105
45
  }
5106
#ifdef RS6000COFF_C
5107
      if (syment->n_sclass == C_HIDEXT)
5108
  return COFF_SYMBOL_LOCAL;
5109
#endif
5110
202
      return COFF_SYMBOL_GLOBAL;
5111
5112
0
    default:
5113
0
      break;
5114
247
    }
5115
5116
0
#ifdef COFF_WITH_PE
5117
0
  if (syment->n_sclass == C_STAT)
5118
0
    {
5119
0
      if (syment->n_scnum == 0)
5120
  /* The Microsoft compiler sometimes generates these if a
5121
     small static function is inlined every time it is used.
5122
     The function is discarded, but the symbol table entry
5123
     remains.  */
5124
0
  return COFF_SYMBOL_LOCAL;
5125
5126
#ifdef STRICT_PE_FORMAT
5127
      /* This is correct for Microsoft generated objects, but it
5128
   breaks gas generated objects.  */
5129
      if (syment->n_value == 0)
5130
  {
5131
    const asection *sec;
5132
    const char *name;
5133
    char buf[SYMNMLEN + 1];
5134
5135
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5136
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5137
    if (sec != NULL && name != NULL
5138
        && (strcmp (bfd_section_name (sec), name) == 0))
5139
      return COFF_SYMBOL_PE_SECTION;
5140
  }
5141
#endif
5142
5143
0
      return COFF_SYMBOL_LOCAL;
5144
0
    }
5145
5146
0
  if (syment->n_sclass == C_SECTION)
5147
0
    {
5148
      /* In some cases in a DLL generated by the Microsoft linker, the
5149
   n_value field will contain garbage.  FIXME: This should
5150
   probably be handled by the swapping function instead.  */
5151
0
      syment->n_value = 0;
5152
0
      if (syment->n_scnum == 0)
5153
0
  return COFF_SYMBOL_UNDEFINED;
5154
0
      return COFF_SYMBOL_PE_SECTION;
5155
0
    }
5156
0
#endif /* COFF_WITH_PE */
5157
5158
  /* If it is not a global symbol, we presume it is a local symbol.  */
5159
0
  if (syment->n_scnum == 0)
5160
0
    {
5161
0
      char buf[SYMNMLEN + 1];
5162
5163
0
      _bfd_error_handler
5164
  /* xgettext:c-format */
5165
0
  (_("warning: %pB: local symbol `%s' has no section"),
5166
0
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5167
0
    }
5168
5169
0
  return COFF_SYMBOL_LOCAL;
5170
0
}
Unexecuted instantiation: cf-i386lynx.c:coff_classify_symbol
Unexecuted instantiation: coff-go32.c:coff_classify_symbol
Unexecuted instantiation: coff-i386.c:coff_classify_symbol
coff-rs6000.c:coff_classify_symbol
Line
Count
Source
5076
826
{
5077
  /* FIXME: This partially duplicates the switch in
5078
     coff_slurp_symbol_table.  */
5079
826
  switch (syment->n_sclass)
5080
826
    {
5081
608
    case C_EXT:
5082
661
    case C_WEAKEXT:
5083
#ifdef ARM
5084
    case C_THUMBEXT:
5085
    case C_THUMBEXTFUNC:
5086
#endif
5087
661
#ifdef RS6000COFF_C
5088
703
    case C_HIDEXT:
5089
703
#ifndef AIX_WEAK_SUPPORT
5090
778
    case C_AIX_WEAKEXT:
5091
778
#endif
5092
778
#endif
5093
778
#ifdef C_SYSTEM
5094
826
    case C_SYSTEM:
5095
826
#endif
5096
#ifdef COFF_WITH_PE
5097
    case C_NT_WEAK:
5098
#endif
5099
826
      if (syment->n_scnum == 0)
5100
60
  {
5101
60
    if (syment->n_value == 0)
5102
25
      return COFF_SYMBOL_UNDEFINED;
5103
35
    else
5104
35
      return COFF_SYMBOL_COMMON;
5105
60
  }
5106
766
#ifdef RS6000COFF_C
5107
766
      if (syment->n_sclass == C_HIDEXT)
5108
40
  return COFF_SYMBOL_LOCAL;
5109
726
#endif
5110
726
      return COFF_SYMBOL_GLOBAL;
5111
5112
0
    default:
5113
0
      break;
5114
826
    }
5115
5116
#ifdef COFF_WITH_PE
5117
  if (syment->n_sclass == C_STAT)
5118
    {
5119
      if (syment->n_scnum == 0)
5120
  /* The Microsoft compiler sometimes generates these if a
5121
     small static function is inlined every time it is used.
5122
     The function is discarded, but the symbol table entry
5123
     remains.  */
5124
  return COFF_SYMBOL_LOCAL;
5125
5126
#ifdef STRICT_PE_FORMAT
5127
      /* This is correct for Microsoft generated objects, but it
5128
   breaks gas generated objects.  */
5129
      if (syment->n_value == 0)
5130
  {
5131
    const asection *sec;
5132
    const char *name;
5133
    char buf[SYMNMLEN + 1];
5134
5135
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5136
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5137
    if (sec != NULL && name != NULL
5138
        && (strcmp (bfd_section_name (sec), name) == 0))
5139
      return COFF_SYMBOL_PE_SECTION;
5140
  }
5141
#endif
5142
5143
      return COFF_SYMBOL_LOCAL;
5144
    }
5145
5146
  if (syment->n_sclass == C_SECTION)
5147
    {
5148
      /* In some cases in a DLL generated by the Microsoft linker, the
5149
   n_value field will contain garbage.  FIXME: This should
5150
   probably be handled by the swapping function instead.  */
5151
      syment->n_value = 0;
5152
      if (syment->n_scnum == 0)
5153
  return COFF_SYMBOL_UNDEFINED;
5154
      return COFF_SYMBOL_PE_SECTION;
5155
    }
5156
#endif /* COFF_WITH_PE */
5157
5158
  /* If it is not a global symbol, we presume it is a local symbol.  */
5159
0
  if (syment->n_scnum == 0)
5160
0
    {
5161
0
      char buf[SYMNMLEN + 1];
5162
5163
0
      _bfd_error_handler
5164
  /* xgettext:c-format */
5165
0
  (_("warning: %pB: local symbol `%s' has no section"),
5166
0
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5167
0
    }
5168
5169
0
  return COFF_SYMBOL_LOCAL;
5170
826
}
coff-sh.c:coff_classify_symbol
Line
Count
Source
5076
828
{
5077
  /* FIXME: This partially duplicates the switch in
5078
     coff_slurp_symbol_table.  */
5079
828
  switch (syment->n_sclass)
5080
828
    {
5081
787
    case C_EXT:
5082
811
    case C_WEAKEXT:
5083
#ifdef ARM
5084
    case C_THUMBEXT:
5085
    case C_THUMBEXTFUNC:
5086
#endif
5087
#ifdef RS6000COFF_C
5088
    case C_HIDEXT:
5089
#ifndef AIX_WEAK_SUPPORT
5090
    case C_AIX_WEAKEXT:
5091
#endif
5092
#endif
5093
811
#ifdef C_SYSTEM
5094
828
    case C_SYSTEM:
5095
828
#endif
5096
#ifdef COFF_WITH_PE
5097
    case C_NT_WEAK:
5098
#endif
5099
828
      if (syment->n_scnum == 0)
5100
148
  {
5101
148
    if (syment->n_value == 0)
5102
18
      return COFF_SYMBOL_UNDEFINED;
5103
130
    else
5104
130
      return COFF_SYMBOL_COMMON;
5105
148
  }
5106
#ifdef RS6000COFF_C
5107
      if (syment->n_sclass == C_HIDEXT)
5108
  return COFF_SYMBOL_LOCAL;
5109
#endif
5110
680
      return COFF_SYMBOL_GLOBAL;
5111
5112
0
    default:
5113
0
      break;
5114
828
    }
5115
5116
#ifdef COFF_WITH_PE
5117
  if (syment->n_sclass == C_STAT)
5118
    {
5119
      if (syment->n_scnum == 0)
5120
  /* The Microsoft compiler sometimes generates these if a
5121
     small static function is inlined every time it is used.
5122
     The function is discarded, but the symbol table entry
5123
     remains.  */
5124
  return COFF_SYMBOL_LOCAL;
5125
5126
#ifdef STRICT_PE_FORMAT
5127
      /* This is correct for Microsoft generated objects, but it
5128
   breaks gas generated objects.  */
5129
      if (syment->n_value == 0)
5130
  {
5131
    const asection *sec;
5132
    const char *name;
5133
    char buf[SYMNMLEN + 1];
5134
5135
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5136
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5137
    if (sec != NULL && name != NULL
5138
        && (strcmp (bfd_section_name (sec), name) == 0))
5139
      return COFF_SYMBOL_PE_SECTION;
5140
  }
5141
#endif
5142
5143
      return COFF_SYMBOL_LOCAL;
5144
    }
5145
5146
  if (syment->n_sclass == C_SECTION)
5147
    {
5148
      /* In some cases in a DLL generated by the Microsoft linker, the
5149
   n_value field will contain garbage.  FIXME: This should
5150
   probably be handled by the swapping function instead.  */
5151
      syment->n_value = 0;
5152
      if (syment->n_scnum == 0)
5153
  return COFF_SYMBOL_UNDEFINED;
5154
      return COFF_SYMBOL_PE_SECTION;
5155
    }
5156
#endif /* COFF_WITH_PE */
5157
5158
  /* If it is not a global symbol, we presume it is a local symbol.  */
5159
0
  if (syment->n_scnum == 0)
5160
0
    {
5161
0
      char buf[SYMNMLEN + 1];
5162
5163
0
      _bfd_error_handler
5164
  /* xgettext:c-format */
5165
0
  (_("warning: %pB: local symbol `%s' has no section"),
5166
0
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5167
0
    }
5168
5169
0
  return COFF_SYMBOL_LOCAL;
5170
828
}
Unexecuted instantiation: coff-stgo32.c:coff_classify_symbol
coff-tic30.c:coff_classify_symbol
Line
Count
Source
5076
59
{
5077
  /* FIXME: This partially duplicates the switch in
5078
     coff_slurp_symbol_table.  */
5079
59
  switch (syment->n_sclass)
5080
59
    {
5081
49
    case C_EXT:
5082
54
    case C_WEAKEXT:
5083
#ifdef ARM
5084
    case C_THUMBEXT:
5085
    case C_THUMBEXTFUNC:
5086
#endif
5087
#ifdef RS6000COFF_C
5088
    case C_HIDEXT:
5089
#ifndef AIX_WEAK_SUPPORT
5090
    case C_AIX_WEAKEXT:
5091
#endif
5092
#endif
5093
54
#ifdef C_SYSTEM
5094
59
    case C_SYSTEM:
5095
59
#endif
5096
#ifdef COFF_WITH_PE
5097
    case C_NT_WEAK:
5098
#endif
5099
59
      if (syment->n_scnum == 0)
5100
13
  {
5101
13
    if (syment->n_value == 0)
5102
5
      return COFF_SYMBOL_UNDEFINED;
5103
8
    else
5104
8
      return COFF_SYMBOL_COMMON;
5105
13
  }
5106
#ifdef RS6000COFF_C
5107
      if (syment->n_sclass == C_HIDEXT)
5108
  return COFF_SYMBOL_LOCAL;
5109
#endif
5110
46
      return COFF_SYMBOL_GLOBAL;
5111
5112
0
    default:
5113
0
      break;
5114
59
    }
5115
5116
#ifdef COFF_WITH_PE
5117
  if (syment->n_sclass == C_STAT)
5118
    {
5119
      if (syment->n_scnum == 0)
5120
  /* The Microsoft compiler sometimes generates these if a
5121
     small static function is inlined every time it is used.
5122
     The function is discarded, but the symbol table entry
5123
     remains.  */
5124
  return COFF_SYMBOL_LOCAL;
5125
5126
#ifdef STRICT_PE_FORMAT
5127
      /* This is correct for Microsoft generated objects, but it
5128
   breaks gas generated objects.  */
5129
      if (syment->n_value == 0)
5130
  {
5131
    const asection *sec;
5132
    const char *name;
5133
    char buf[SYMNMLEN + 1];
5134
5135
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5136
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5137
    if (sec != NULL && name != NULL
5138
        && (strcmp (bfd_section_name (sec), name) == 0))
5139
      return COFF_SYMBOL_PE_SECTION;
5140
  }
5141
#endif
5142
5143
      return COFF_SYMBOL_LOCAL;
5144
    }
5145
5146
  if (syment->n_sclass == C_SECTION)
5147
    {
5148
      /* In some cases in a DLL generated by the Microsoft linker, the
5149
   n_value field will contain garbage.  FIXME: This should
5150
   probably be handled by the swapping function instead.  */
5151
      syment->n_value = 0;
5152
      if (syment->n_scnum == 0)
5153
  return COFF_SYMBOL_UNDEFINED;
5154
      return COFF_SYMBOL_PE_SECTION;
5155
    }
5156
#endif /* COFF_WITH_PE */
5157
5158
  /* If it is not a global symbol, we presume it is a local symbol.  */
5159
0
  if (syment->n_scnum == 0)
5160
0
    {
5161
0
      char buf[SYMNMLEN + 1];
5162
5163
0
      _bfd_error_handler
5164
  /* xgettext:c-format */
5165
0
  (_("warning: %pB: local symbol `%s' has no section"),
5166
0
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5167
0
    }
5168
5169
0
  return COFF_SYMBOL_LOCAL;
5170
59
}
Unexecuted instantiation: coff-tic4x.c:coff_classify_symbol
coff-tic54x.c:coff_classify_symbol
Line
Count
Source
5076
353
{
5077
  /* FIXME: This partially duplicates the switch in
5078
     coff_slurp_symbol_table.  */
5079
353
  switch (syment->n_sclass)
5080
353
    {
5081
330
    case C_EXT:
5082
340
    case C_WEAKEXT:
5083
#ifdef ARM
5084
    case C_THUMBEXT:
5085
    case C_THUMBEXTFUNC:
5086
#endif
5087
#ifdef RS6000COFF_C
5088
    case C_HIDEXT:
5089
#ifndef AIX_WEAK_SUPPORT
5090
    case C_AIX_WEAKEXT:
5091
#endif
5092
#endif
5093
340
#ifdef C_SYSTEM
5094
353
    case C_SYSTEM:
5095
353
#endif
5096
#ifdef COFF_WITH_PE
5097
    case C_NT_WEAK:
5098
#endif
5099
353
      if (syment->n_scnum == 0)
5100
73
  {
5101
73
    if (syment->n_value == 0)
5102
13
      return COFF_SYMBOL_UNDEFINED;
5103
60
    else
5104
60
      return COFF_SYMBOL_COMMON;
5105
73
  }
5106
#ifdef RS6000COFF_C
5107
      if (syment->n_sclass == C_HIDEXT)
5108
  return COFF_SYMBOL_LOCAL;
5109
#endif
5110
280
      return COFF_SYMBOL_GLOBAL;
5111
5112
0
    default:
5113
0
      break;
5114
353
    }
5115
5116
#ifdef COFF_WITH_PE
5117
  if (syment->n_sclass == C_STAT)
5118
    {
5119
      if (syment->n_scnum == 0)
5120
  /* The Microsoft compiler sometimes generates these if a
5121
     small static function is inlined every time it is used.
5122
     The function is discarded, but the symbol table entry
5123
     remains.  */
5124
  return COFF_SYMBOL_LOCAL;
5125
5126
#ifdef STRICT_PE_FORMAT
5127
      /* This is correct for Microsoft generated objects, but it
5128
   breaks gas generated objects.  */
5129
      if (syment->n_value == 0)
5130
  {
5131
    const asection *sec;
5132
    const char *name;
5133
    char buf[SYMNMLEN + 1];
5134
5135
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5136
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5137
    if (sec != NULL && name != NULL
5138
        && (strcmp (bfd_section_name (sec), name) == 0))
5139
      return COFF_SYMBOL_PE_SECTION;
5140
  }
5141
#endif
5142
5143
      return COFF_SYMBOL_LOCAL;
5144
    }
5145
5146
  if (syment->n_sclass == C_SECTION)
5147
    {
5148
      /* In some cases in a DLL generated by the Microsoft linker, the
5149
   n_value field will contain garbage.  FIXME: This should
5150
   probably be handled by the swapping function instead.  */
5151
      syment->n_value = 0;
5152
      if (syment->n_scnum == 0)
5153
  return COFF_SYMBOL_UNDEFINED;
5154
      return COFF_SYMBOL_PE_SECTION;
5155
    }
5156
#endif /* COFF_WITH_PE */
5157
5158
  /* If it is not a global symbol, we presume it is a local symbol.  */
5159
0
  if (syment->n_scnum == 0)
5160
0
    {
5161
0
      char buf[SYMNMLEN + 1];
5162
5163
0
      _bfd_error_handler
5164
  /* xgettext:c-format */
5165
0
  (_("warning: %pB: local symbol `%s' has no section"),
5166
0
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5167
0
    }
5168
5169
0
  return COFF_SYMBOL_LOCAL;
5170
353
}
coff-z80.c:coff_classify_symbol
Line
Count
Source
5076
863
{
5077
  /* FIXME: This partially duplicates the switch in
5078
     coff_slurp_symbol_table.  */
5079
863
  switch (syment->n_sclass)
5080
863
    {
5081
852
    case C_EXT:
5082
858
    case C_WEAKEXT:
5083
#ifdef ARM
5084
    case C_THUMBEXT:
5085
    case C_THUMBEXTFUNC:
5086
#endif
5087
#ifdef RS6000COFF_C
5088
    case C_HIDEXT:
5089
#ifndef AIX_WEAK_SUPPORT
5090
    case C_AIX_WEAKEXT:
5091
#endif
5092
#endif
5093
858
#ifdef C_SYSTEM
5094
863
    case C_SYSTEM:
5095
863
#endif
5096
#ifdef COFF_WITH_PE
5097
    case C_NT_WEAK:
5098
#endif
5099
863
      if (syment->n_scnum == 0)
5100
71
  {
5101
71
    if (syment->n_value == 0)
5102
14
      return COFF_SYMBOL_UNDEFINED;
5103
57
    else
5104
57
      return COFF_SYMBOL_COMMON;
5105
71
  }
5106
#ifdef RS6000COFF_C
5107
      if (syment->n_sclass == C_HIDEXT)
5108
  return COFF_SYMBOL_LOCAL;
5109
#endif
5110
792
      return COFF_SYMBOL_GLOBAL;
5111
5112
0
    default:
5113
0
      break;
5114
863
    }
5115
5116
#ifdef COFF_WITH_PE
5117
  if (syment->n_sclass == C_STAT)
5118
    {
5119
      if (syment->n_scnum == 0)
5120
  /* The Microsoft compiler sometimes generates these if a
5121
     small static function is inlined every time it is used.
5122
     The function is discarded, but the symbol table entry
5123
     remains.  */
5124
  return COFF_SYMBOL_LOCAL;
5125
5126
#ifdef STRICT_PE_FORMAT
5127
      /* This is correct for Microsoft generated objects, but it
5128
   breaks gas generated objects.  */
5129
      if (syment->n_value == 0)
5130
  {
5131
    const asection *sec;
5132
    const char *name;
5133
    char buf[SYMNMLEN + 1];
5134
5135
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5136
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5137
    if (sec != NULL && name != NULL
5138
        && (strcmp (bfd_section_name (sec), name) == 0))
5139
      return COFF_SYMBOL_PE_SECTION;
5140
  }
5141
#endif
5142
5143
      return COFF_SYMBOL_LOCAL;
5144
    }
5145
5146
  if (syment->n_sclass == C_SECTION)
5147
    {
5148
      /* In some cases in a DLL generated by the Microsoft linker, the
5149
   n_value field will contain garbage.  FIXME: This should
5150
   probably be handled by the swapping function instead.  */
5151
      syment->n_value = 0;
5152
      if (syment->n_scnum == 0)
5153
  return COFF_SYMBOL_UNDEFINED;
5154
      return COFF_SYMBOL_PE_SECTION;
5155
    }
5156
#endif /* COFF_WITH_PE */
5157
5158
  /* If it is not a global symbol, we presume it is a local symbol.  */
5159
0
  if (syment->n_scnum == 0)
5160
0
    {
5161
0
      char buf[SYMNMLEN + 1];
5162
5163
0
      _bfd_error_handler
5164
  /* xgettext:c-format */
5165
0
  (_("warning: %pB: local symbol `%s' has no section"),
5166
0
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5167
0
    }
5168
5169
0
  return COFF_SYMBOL_LOCAL;
5170
863
}
coff-z8k.c:coff_classify_symbol
Line
Count
Source
5076
246
{
5077
  /* FIXME: This partially duplicates the switch in
5078
     coff_slurp_symbol_table.  */
5079
246
  switch (syment->n_sclass)
5080
246
    {
5081
237
    case C_EXT:
5082
239
    case C_WEAKEXT:
5083
#ifdef ARM
5084
    case C_THUMBEXT:
5085
    case C_THUMBEXTFUNC:
5086
#endif
5087
#ifdef RS6000COFF_C
5088
    case C_HIDEXT:
5089
#ifndef AIX_WEAK_SUPPORT
5090
    case C_AIX_WEAKEXT:
5091
#endif
5092
#endif
5093
239
#ifdef C_SYSTEM
5094
246
    case C_SYSTEM:
5095
246
#endif
5096
#ifdef COFF_WITH_PE
5097
    case C_NT_WEAK:
5098
#endif
5099
246
      if (syment->n_scnum == 0)
5100
66
  {
5101
66
    if (syment->n_value == 0)
5102
14
      return COFF_SYMBOL_UNDEFINED;
5103
52
    else
5104
52
      return COFF_SYMBOL_COMMON;
5105
66
  }
5106
#ifdef RS6000COFF_C
5107
      if (syment->n_sclass == C_HIDEXT)
5108
  return COFF_SYMBOL_LOCAL;
5109
#endif
5110
180
      return COFF_SYMBOL_GLOBAL;
5111
5112
0
    default:
5113
0
      break;
5114
246
    }
5115
5116
#ifdef COFF_WITH_PE
5117
  if (syment->n_sclass == C_STAT)
5118
    {
5119
      if (syment->n_scnum == 0)
5120
  /* The Microsoft compiler sometimes generates these if a
5121
     small static function is inlined every time it is used.
5122
     The function is discarded, but the symbol table entry
5123
     remains.  */
5124
  return COFF_SYMBOL_LOCAL;
5125
5126
#ifdef STRICT_PE_FORMAT
5127
      /* This is correct for Microsoft generated objects, but it
5128
   breaks gas generated objects.  */
5129
      if (syment->n_value == 0)
5130
  {
5131
    const asection *sec;
5132
    const char *name;
5133
    char buf[SYMNMLEN + 1];
5134
5135
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5136
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5137
    if (sec != NULL && name != NULL
5138
        && (strcmp (bfd_section_name (sec), name) == 0))
5139
      return COFF_SYMBOL_PE_SECTION;
5140
  }
5141
#endif
5142
5143
      return COFF_SYMBOL_LOCAL;
5144
    }
5145
5146
  if (syment->n_sclass == C_SECTION)
5147
    {
5148
      /* In some cases in a DLL generated by the Microsoft linker, the
5149
   n_value field will contain garbage.  FIXME: This should
5150
   probably be handled by the swapping function instead.  */
5151
      syment->n_value = 0;
5152
      if (syment->n_scnum == 0)
5153
  return COFF_SYMBOL_UNDEFINED;
5154
      return COFF_SYMBOL_PE_SECTION;
5155
    }
5156
#endif /* COFF_WITH_PE */
5157
5158
  /* If it is not a global symbol, we presume it is a local symbol.  */
5159
0
  if (syment->n_scnum == 0)
5160
0
    {
5161
0
      char buf[SYMNMLEN + 1];
5162
5163
0
      _bfd_error_handler
5164
  /* xgettext:c-format */
5165
0
  (_("warning: %pB: local symbol `%s' has no section"),
5166
0
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5167
0
    }
5168
5169
0
  return COFF_SYMBOL_LOCAL;
5170
246
}
Unexecuted instantiation: pe-arm-wince.c:coff_classify_symbol
Unexecuted instantiation: pe-arm.c:coff_classify_symbol
pe-i386.c:coff_classify_symbol
Line
Count
Source
5076
292
{
5077
  /* FIXME: This partially duplicates the switch in
5078
     coff_slurp_symbol_table.  */
5079
292
  switch (syment->n_sclass)
5080
292
    {
5081
113
    case C_EXT:
5082
121
    case C_WEAKEXT:
5083
#ifdef ARM
5084
    case C_THUMBEXT:
5085
    case C_THUMBEXTFUNC:
5086
#endif
5087
#ifdef RS6000COFF_C
5088
    case C_HIDEXT:
5089
#ifndef AIX_WEAK_SUPPORT
5090
    case C_AIX_WEAKEXT:
5091
#endif
5092
#endif
5093
121
#ifdef C_SYSTEM
5094
124
    case C_SYSTEM:
5095
124
#endif
5096
124
#ifdef COFF_WITH_PE
5097
133
    case C_NT_WEAK:
5098
133
#endif
5099
133
      if (syment->n_scnum == 0)
5100
39
  {
5101
39
    if (syment->n_value == 0)
5102
16
      return COFF_SYMBOL_UNDEFINED;
5103
23
    else
5104
23
      return COFF_SYMBOL_COMMON;
5105
39
  }
5106
#ifdef RS6000COFF_C
5107
      if (syment->n_sclass == C_HIDEXT)
5108
  return COFF_SYMBOL_LOCAL;
5109
#endif
5110
94
      return COFF_SYMBOL_GLOBAL;
5111
5112
159
    default:
5113
159
      break;
5114
292
    }
5115
5116
159
#ifdef COFF_WITH_PE
5117
159
  if (syment->n_sclass == C_STAT)
5118
0
    {
5119
0
      if (syment->n_scnum == 0)
5120
  /* The Microsoft compiler sometimes generates these if a
5121
     small static function is inlined every time it is used.
5122
     The function is discarded, but the symbol table entry
5123
     remains.  */
5124
0
  return COFF_SYMBOL_LOCAL;
5125
5126
#ifdef STRICT_PE_FORMAT
5127
      /* This is correct for Microsoft generated objects, but it
5128
   breaks gas generated objects.  */
5129
      if (syment->n_value == 0)
5130
  {
5131
    const asection *sec;
5132
    const char *name;
5133
    char buf[SYMNMLEN + 1];
5134
5135
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5136
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5137
    if (sec != NULL && name != NULL
5138
        && (strcmp (bfd_section_name (sec), name) == 0))
5139
      return COFF_SYMBOL_PE_SECTION;
5140
  }
5141
#endif
5142
5143
0
      return COFF_SYMBOL_LOCAL;
5144
0
    }
5145
5146
159
  if (syment->n_sclass == C_SECTION)
5147
0
    {
5148
      /* In some cases in a DLL generated by the Microsoft linker, the
5149
   n_value field will contain garbage.  FIXME: This should
5150
   probably be handled by the swapping function instead.  */
5151
0
      syment->n_value = 0;
5152
0
      if (syment->n_scnum == 0)
5153
0
  return COFF_SYMBOL_UNDEFINED;
5154
0
      return COFF_SYMBOL_PE_SECTION;
5155
0
    }
5156
159
#endif /* COFF_WITH_PE */
5157
5158
  /* If it is not a global symbol, we presume it is a local symbol.  */
5159
159
  if (syment->n_scnum == 0)
5160
158
    {
5161
158
      char buf[SYMNMLEN + 1];
5162
5163
158
      _bfd_error_handler
5164
  /* xgettext:c-format */
5165
158
  (_("warning: %pB: local symbol `%s' has no section"),
5166
158
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5167
158
    }
5168
5169
159
  return COFF_SYMBOL_LOCAL;
5170
159
}
pe-mcore.c:coff_classify_symbol
Line
Count
Source
5076
11.6k
{
5077
  /* FIXME: This partially duplicates the switch in
5078
     coff_slurp_symbol_table.  */
5079
11.6k
  switch (syment->n_sclass)
5080
11.6k
    {
5081
584
    case C_EXT:
5082
614
    case C_WEAKEXT:
5083
#ifdef ARM
5084
    case C_THUMBEXT:
5085
    case C_THUMBEXTFUNC:
5086
#endif
5087
#ifdef RS6000COFF_C
5088
    case C_HIDEXT:
5089
#ifndef AIX_WEAK_SUPPORT
5090
    case C_AIX_WEAKEXT:
5091
#endif
5092
#endif
5093
614
#ifdef C_SYSTEM
5094
620
    case C_SYSTEM:
5095
620
#endif
5096
620
#ifdef COFF_WITH_PE
5097
638
    case C_NT_WEAK:
5098
638
#endif
5099
638
      if (syment->n_scnum == 0)
5100
61
  {
5101
61
    if (syment->n_value == 0)
5102
23
      return COFF_SYMBOL_UNDEFINED;
5103
38
    else
5104
38
      return COFF_SYMBOL_COMMON;
5105
61
  }
5106
#ifdef RS6000COFF_C
5107
      if (syment->n_sclass == C_HIDEXT)
5108
  return COFF_SYMBOL_LOCAL;
5109
#endif
5110
577
      return COFF_SYMBOL_GLOBAL;
5111
5112
11.0k
    default:
5113
11.0k
      break;
5114
11.6k
    }
5115
5116
11.0k
#ifdef COFF_WITH_PE
5117
11.0k
  if (syment->n_sclass == C_STAT)
5118
128
    {
5119
128
      if (syment->n_scnum == 0)
5120
  /* The Microsoft compiler sometimes generates these if a
5121
     small static function is inlined every time it is used.
5122
     The function is discarded, but the symbol table entry
5123
     remains.  */
5124
128
  return COFF_SYMBOL_LOCAL;
5125
5126
#ifdef STRICT_PE_FORMAT
5127
      /* This is correct for Microsoft generated objects, but it
5128
   breaks gas generated objects.  */
5129
      if (syment->n_value == 0)
5130
  {
5131
    const asection *sec;
5132
    const char *name;
5133
    char buf[SYMNMLEN + 1];
5134
5135
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5136
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5137
    if (sec != NULL && name != NULL
5138
        && (strcmp (bfd_section_name (sec), name) == 0))
5139
      return COFF_SYMBOL_PE_SECTION;
5140
  }
5141
#endif
5142
5143
0
      return COFF_SYMBOL_LOCAL;
5144
128
    }
5145
5146
10.8k
  if (syment->n_sclass == C_SECTION)
5147
11
    {
5148
      /* In some cases in a DLL generated by the Microsoft linker, the
5149
   n_value field will contain garbage.  FIXME: This should
5150
   probably be handled by the swapping function instead.  */
5151
11
      syment->n_value = 0;
5152
11
      if (syment->n_scnum == 0)
5153
11
  return COFF_SYMBOL_UNDEFINED;
5154
0
      return COFF_SYMBOL_PE_SECTION;
5155
11
    }
5156
10.8k
#endif /* COFF_WITH_PE */
5157
5158
  /* If it is not a global symbol, we presume it is a local symbol.  */
5159
10.8k
  if (syment->n_scnum == 0)
5160
10.8k
    {
5161
10.8k
      char buf[SYMNMLEN + 1];
5162
5163
10.8k
      _bfd_error_handler
5164
  /* xgettext:c-format */
5165
10.8k
  (_("warning: %pB: local symbol `%s' has no section"),
5166
10.8k
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5167
10.8k
    }
5168
5169
10.8k
  return COFF_SYMBOL_LOCAL;
5170
10.8k
}
pe-sh.c:coff_classify_symbol
Line
Count
Source
5076
2.79k
{
5077
  /* FIXME: This partially duplicates the switch in
5078
     coff_slurp_symbol_table.  */
5079
2.79k
  switch (syment->n_sclass)
5080
2.79k
    {
5081
2.77k
    case C_EXT:
5082
2.77k
    case C_WEAKEXT:
5083
#ifdef ARM
5084
    case C_THUMBEXT:
5085
    case C_THUMBEXTFUNC:
5086
#endif
5087
#ifdef RS6000COFF_C
5088
    case C_HIDEXT:
5089
#ifndef AIX_WEAK_SUPPORT
5090
    case C_AIX_WEAKEXT:
5091
#endif
5092
#endif
5093
2.77k
#ifdef C_SYSTEM
5094
2.78k
    case C_SYSTEM:
5095
2.78k
#endif
5096
2.78k
#ifdef COFF_WITH_PE
5097
2.79k
    case C_NT_WEAK:
5098
2.79k
#endif
5099
2.79k
      if (syment->n_scnum == 0)
5100
57
  {
5101
57
    if (syment->n_value == 0)
5102
5
      return COFF_SYMBOL_UNDEFINED;
5103
52
    else
5104
52
      return COFF_SYMBOL_COMMON;
5105
57
  }
5106
#ifdef RS6000COFF_C
5107
      if (syment->n_sclass == C_HIDEXT)
5108
  return COFF_SYMBOL_LOCAL;
5109
#endif
5110
2.73k
      return COFF_SYMBOL_GLOBAL;
5111
5112
2
    default:
5113
2
      break;
5114
2.79k
    }
5115
5116
2
#ifdef COFF_WITH_PE
5117
2
  if (syment->n_sclass == C_STAT)
5118
0
    {
5119
0
      if (syment->n_scnum == 0)
5120
  /* The Microsoft compiler sometimes generates these if a
5121
     small static function is inlined every time it is used.
5122
     The function is discarded, but the symbol table entry
5123
     remains.  */
5124
0
  return COFF_SYMBOL_LOCAL;
5125
5126
#ifdef STRICT_PE_FORMAT
5127
      /* This is correct for Microsoft generated objects, but it
5128
   breaks gas generated objects.  */
5129
      if (syment->n_value == 0)
5130
  {
5131
    const asection *sec;
5132
    const char *name;
5133
    char buf[SYMNMLEN + 1];
5134
5135
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5136
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5137
    if (sec != NULL && name != NULL
5138
        && (strcmp (bfd_section_name (sec), name) == 0))
5139
      return COFF_SYMBOL_PE_SECTION;
5140
  }
5141
#endif
5142
5143
0
      return COFF_SYMBOL_LOCAL;
5144
0
    }
5145
5146
2
  if (syment->n_sclass == C_SECTION)
5147
2
    {
5148
      /* In some cases in a DLL generated by the Microsoft linker, the
5149
   n_value field will contain garbage.  FIXME: This should
5150
   probably be handled by the swapping function instead.  */
5151
2
      syment->n_value = 0;
5152
2
      if (syment->n_scnum == 0)
5153
2
  return COFF_SYMBOL_UNDEFINED;
5154
0
      return COFF_SYMBOL_PE_SECTION;
5155
2
    }
5156
0
#endif /* COFF_WITH_PE */
5157
5158
  /* If it is not a global symbol, we presume it is a local symbol.  */
5159
0
  if (syment->n_scnum == 0)
5160
0
    {
5161
0
      char buf[SYMNMLEN + 1];
5162
5163
0
      _bfd_error_handler
5164
  /* xgettext:c-format */
5165
0
  (_("warning: %pB: local symbol `%s' has no section"),
5166
0
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5167
0
    }
5168
5169
0
  return COFF_SYMBOL_LOCAL;
5170
2
}
pei-arm-wince.c:coff_classify_symbol
Line
Count
Source
5076
6
{
5077
  /* FIXME: This partially duplicates the switch in
5078
     coff_slurp_symbol_table.  */
5079
6
  switch (syment->n_sclass)
5080
6
    {
5081
6
    case C_EXT:
5082
6
    case C_WEAKEXT:
5083
6
#ifdef ARM
5084
6
    case C_THUMBEXT:
5085
6
    case C_THUMBEXTFUNC:
5086
6
#endif
5087
#ifdef RS6000COFF_C
5088
    case C_HIDEXT:
5089
#ifndef AIX_WEAK_SUPPORT
5090
    case C_AIX_WEAKEXT:
5091
#endif
5092
#endif
5093
6
#ifdef C_SYSTEM
5094
6
    case C_SYSTEM:
5095
6
#endif
5096
6
#ifdef COFF_WITH_PE
5097
6
    case C_NT_WEAK:
5098
6
#endif
5099
6
      if (syment->n_scnum == 0)
5100
0
  {
5101
0
    if (syment->n_value == 0)
5102
0
      return COFF_SYMBOL_UNDEFINED;
5103
0
    else
5104
0
      return COFF_SYMBOL_COMMON;
5105
0
  }
5106
#ifdef RS6000COFF_C
5107
      if (syment->n_sclass == C_HIDEXT)
5108
  return COFF_SYMBOL_LOCAL;
5109
#endif
5110
6
      return COFF_SYMBOL_GLOBAL;
5111
5112
0
    default:
5113
0
      break;
5114
6
    }
5115
5116
0
#ifdef COFF_WITH_PE
5117
0
  if (syment->n_sclass == C_STAT)
5118
0
    {
5119
0
      if (syment->n_scnum == 0)
5120
  /* The Microsoft compiler sometimes generates these if a
5121
     small static function is inlined every time it is used.
5122
     The function is discarded, but the symbol table entry
5123
     remains.  */
5124
0
  return COFF_SYMBOL_LOCAL;
5125
5126
#ifdef STRICT_PE_FORMAT
5127
      /* This is correct for Microsoft generated objects, but it
5128
   breaks gas generated objects.  */
5129
      if (syment->n_value == 0)
5130
  {
5131
    const asection *sec;
5132
    const char *name;
5133
    char buf[SYMNMLEN + 1];
5134
5135
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5136
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5137
    if (sec != NULL && name != NULL
5138
        && (strcmp (bfd_section_name (sec), name) == 0))
5139
      return COFF_SYMBOL_PE_SECTION;
5140
  }
5141
#endif
5142
5143
0
      return COFF_SYMBOL_LOCAL;
5144
0
    }
5145
5146
0
  if (syment->n_sclass == C_SECTION)
5147
0
    {
5148
      /* In some cases in a DLL generated by the Microsoft linker, the
5149
   n_value field will contain garbage.  FIXME: This should
5150
   probably be handled by the swapping function instead.  */
5151
0
      syment->n_value = 0;
5152
0
      if (syment->n_scnum == 0)
5153
0
  return COFF_SYMBOL_UNDEFINED;
5154
0
      return COFF_SYMBOL_PE_SECTION;
5155
0
    }
5156
0
#endif /* COFF_WITH_PE */
5157
5158
  /* If it is not a global symbol, we presume it is a local symbol.  */
5159
0
  if (syment->n_scnum == 0)
5160
0
    {
5161
0
      char buf[SYMNMLEN + 1];
5162
5163
0
      _bfd_error_handler
5164
  /* xgettext:c-format */
5165
0
  (_("warning: %pB: local symbol `%s' has no section"),
5166
0
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5167
0
    }
5168
5169
0
  return COFF_SYMBOL_LOCAL;
5170
0
}
pei-arm.c:coff_classify_symbol
Line
Count
Source
5076
13
{
5077
  /* FIXME: This partially duplicates the switch in
5078
     coff_slurp_symbol_table.  */
5079
13
  switch (syment->n_sclass)
5080
13
    {
5081
11
    case C_EXT:
5082
12
    case C_WEAKEXT:
5083
12
#ifdef ARM
5084
12
    case C_THUMBEXT:
5085
12
    case C_THUMBEXTFUNC:
5086
12
#endif
5087
#ifdef RS6000COFF_C
5088
    case C_HIDEXT:
5089
#ifndef AIX_WEAK_SUPPORT
5090
    case C_AIX_WEAKEXT:
5091
#endif
5092
#endif
5093
12
#ifdef C_SYSTEM
5094
13
    case C_SYSTEM:
5095
13
#endif
5096
13
#ifdef COFF_WITH_PE
5097
13
    case C_NT_WEAK:
5098
13
#endif
5099
13
      if (syment->n_scnum == 0)
5100
5
  {
5101
5
    if (syment->n_value == 0)
5102
0
      return COFF_SYMBOL_UNDEFINED;
5103
5
    else
5104
5
      return COFF_SYMBOL_COMMON;
5105
5
  }
5106
#ifdef RS6000COFF_C
5107
      if (syment->n_sclass == C_HIDEXT)
5108
  return COFF_SYMBOL_LOCAL;
5109
#endif
5110
8
      return COFF_SYMBOL_GLOBAL;
5111
5112
0
    default:
5113
0
      break;
5114
13
    }
5115
5116
0
#ifdef COFF_WITH_PE
5117
0
  if (syment->n_sclass == C_STAT)
5118
0
    {
5119
0
      if (syment->n_scnum == 0)
5120
  /* The Microsoft compiler sometimes generates these if a
5121
     small static function is inlined every time it is used.
5122
     The function is discarded, but the symbol table entry
5123
     remains.  */
5124
0
  return COFF_SYMBOL_LOCAL;
5125
5126
#ifdef STRICT_PE_FORMAT
5127
      /* This is correct for Microsoft generated objects, but it
5128
   breaks gas generated objects.  */
5129
      if (syment->n_value == 0)
5130
  {
5131
    const asection *sec;
5132
    const char *name;
5133
    char buf[SYMNMLEN + 1];
5134
5135
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5136
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5137
    if (sec != NULL && name != NULL
5138
        && (strcmp (bfd_section_name (sec), name) == 0))
5139
      return COFF_SYMBOL_PE_SECTION;
5140
  }
5141
#endif
5142
5143
0
      return COFF_SYMBOL_LOCAL;
5144
0
    }
5145
5146
0
  if (syment->n_sclass == C_SECTION)
5147
0
    {
5148
      /* In some cases in a DLL generated by the Microsoft linker, the
5149
   n_value field will contain garbage.  FIXME: This should
5150
   probably be handled by the swapping function instead.  */
5151
0
      syment->n_value = 0;
5152
0
      if (syment->n_scnum == 0)
5153
0
  return COFF_SYMBOL_UNDEFINED;
5154
0
      return COFF_SYMBOL_PE_SECTION;
5155
0
    }
5156
0
#endif /* COFF_WITH_PE */
5157
5158
  /* If it is not a global symbol, we presume it is a local symbol.  */
5159
0
  if (syment->n_scnum == 0)
5160
0
    {
5161
0
      char buf[SYMNMLEN + 1];
5162
5163
0
      _bfd_error_handler
5164
  /* xgettext:c-format */
5165
0
  (_("warning: %pB: local symbol `%s' has no section"),
5166
0
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5167
0
    }
5168
5169
0
  return COFF_SYMBOL_LOCAL;
5170
0
}
pei-mcore.c:coff_classify_symbol
Line
Count
Source
5076
10
{
5077
  /* FIXME: This partially duplicates the switch in
5078
     coff_slurp_symbol_table.  */
5079
10
  switch (syment->n_sclass)
5080
10
    {
5081
4
    case C_EXT:
5082
7
    case C_WEAKEXT:
5083
#ifdef ARM
5084
    case C_THUMBEXT:
5085
    case C_THUMBEXTFUNC:
5086
#endif
5087
#ifdef RS6000COFF_C
5088
    case C_HIDEXT:
5089
#ifndef AIX_WEAK_SUPPORT
5090
    case C_AIX_WEAKEXT:
5091
#endif
5092
#endif
5093
7
#ifdef C_SYSTEM
5094
10
    case C_SYSTEM:
5095
10
#endif
5096
10
#ifdef COFF_WITH_PE
5097
10
    case C_NT_WEAK:
5098
10
#endif
5099
10
      if (syment->n_scnum == 0)
5100
4
  {
5101
4
    if (syment->n_value == 0)
5102
0
      return COFF_SYMBOL_UNDEFINED;
5103
4
    else
5104
4
      return COFF_SYMBOL_COMMON;
5105
4
  }
5106
#ifdef RS6000COFF_C
5107
      if (syment->n_sclass == C_HIDEXT)
5108
  return COFF_SYMBOL_LOCAL;
5109
#endif
5110
6
      return COFF_SYMBOL_GLOBAL;
5111
5112
0
    default:
5113
0
      break;
5114
10
    }
5115
5116
0
#ifdef COFF_WITH_PE
5117
0
  if (syment->n_sclass == C_STAT)
5118
0
    {
5119
0
      if (syment->n_scnum == 0)
5120
  /* The Microsoft compiler sometimes generates these if a
5121
     small static function is inlined every time it is used.
5122
     The function is discarded, but the symbol table entry
5123
     remains.  */
5124
0
  return COFF_SYMBOL_LOCAL;
5125
5126
#ifdef STRICT_PE_FORMAT
5127
      /* This is correct for Microsoft generated objects, but it
5128
   breaks gas generated objects.  */
5129
      if (syment->n_value == 0)
5130
  {
5131
    const asection *sec;
5132
    const char *name;
5133
    char buf[SYMNMLEN + 1];
5134
5135
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5136
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5137
    if (sec != NULL && name != NULL
5138
        && (strcmp (bfd_section_name (sec), name) == 0))
5139
      return COFF_SYMBOL_PE_SECTION;
5140
  }
5141
#endif
5142
5143
0
      return COFF_SYMBOL_LOCAL;
5144
0
    }
5145
5146
0
  if (syment->n_sclass == C_SECTION)
5147
0
    {
5148
      /* In some cases in a DLL generated by the Microsoft linker, the
5149
   n_value field will contain garbage.  FIXME: This should
5150
   probably be handled by the swapping function instead.  */
5151
0
      syment->n_value = 0;
5152
0
      if (syment->n_scnum == 0)
5153
0
  return COFF_SYMBOL_UNDEFINED;
5154
0
      return COFF_SYMBOL_PE_SECTION;
5155
0
    }
5156
0
#endif /* COFF_WITH_PE */
5157
5158
  /* If it is not a global symbol, we presume it is a local symbol.  */
5159
0
  if (syment->n_scnum == 0)
5160
0
    {
5161
0
      char buf[SYMNMLEN + 1];
5162
5163
0
      _bfd_error_handler
5164
  /* xgettext:c-format */
5165
0
  (_("warning: %pB: local symbol `%s' has no section"),
5166
0
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5167
0
    }
5168
5169
0
  return COFF_SYMBOL_LOCAL;
5170
0
}
pei-sh.c:coff_classify_symbol
Line
Count
Source
5076
44
{
5077
  /* FIXME: This partially duplicates the switch in
5078
     coff_slurp_symbol_table.  */
5079
44
  switch (syment->n_sclass)
5080
44
    {
5081
36
    case C_EXT:
5082
38
    case C_WEAKEXT:
5083
#ifdef ARM
5084
    case C_THUMBEXT:
5085
    case C_THUMBEXTFUNC:
5086
#endif
5087
#ifdef RS6000COFF_C
5088
    case C_HIDEXT:
5089
#ifndef AIX_WEAK_SUPPORT
5090
    case C_AIX_WEAKEXT:
5091
#endif
5092
#endif
5093
38
#ifdef C_SYSTEM
5094
43
    case C_SYSTEM:
5095
43
#endif
5096
43
#ifdef COFF_WITH_PE
5097
44
    case C_NT_WEAK:
5098
44
#endif
5099
44
      if (syment->n_scnum == 0)
5100
23
  {
5101
23
    if (syment->n_value == 0)
5102
4
      return COFF_SYMBOL_UNDEFINED;
5103
19
    else
5104
19
      return COFF_SYMBOL_COMMON;
5105
23
  }
5106
#ifdef RS6000COFF_C
5107
      if (syment->n_sclass == C_HIDEXT)
5108
  return COFF_SYMBOL_LOCAL;
5109
#endif
5110
21
      return COFF_SYMBOL_GLOBAL;
5111
5112
0
    default:
5113
0
      break;
5114
44
    }
5115
5116
0
#ifdef COFF_WITH_PE
5117
0
  if (syment->n_sclass == C_STAT)
5118
0
    {
5119
0
      if (syment->n_scnum == 0)
5120
  /* The Microsoft compiler sometimes generates these if a
5121
     small static function is inlined every time it is used.
5122
     The function is discarded, but the symbol table entry
5123
     remains.  */
5124
0
  return COFF_SYMBOL_LOCAL;
5125
5126
#ifdef STRICT_PE_FORMAT
5127
      /* This is correct for Microsoft generated objects, but it
5128
   breaks gas generated objects.  */
5129
      if (syment->n_value == 0)
5130
  {
5131
    const asection *sec;
5132
    const char *name;
5133
    char buf[SYMNMLEN + 1];
5134
5135
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5136
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5137
    if (sec != NULL && name != NULL
5138
        && (strcmp (bfd_section_name (sec), name) == 0))
5139
      return COFF_SYMBOL_PE_SECTION;
5140
  }
5141
#endif
5142
5143
0
      return COFF_SYMBOL_LOCAL;
5144
0
    }
5145
5146
0
  if (syment->n_sclass == C_SECTION)
5147
0
    {
5148
      /* In some cases in a DLL generated by the Microsoft linker, the
5149
   n_value field will contain garbage.  FIXME: This should
5150
   probably be handled by the swapping function instead.  */
5151
0
      syment->n_value = 0;
5152
0
      if (syment->n_scnum == 0)
5153
0
  return COFF_SYMBOL_UNDEFINED;
5154
0
      return COFF_SYMBOL_PE_SECTION;
5155
0
    }
5156
0
#endif /* COFF_WITH_PE */
5157
5158
  /* If it is not a global symbol, we presume it is a local symbol.  */
5159
0
  if (syment->n_scnum == 0)
5160
0
    {
5161
0
      char buf[SYMNMLEN + 1];
5162
5163
0
      _bfd_error_handler
5164
  /* xgettext:c-format */
5165
0
  (_("warning: %pB: local symbol `%s' has no section"),
5166
0
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5167
0
    }
5168
5169
0
  return COFF_SYMBOL_LOCAL;
5170
0
}
5171
5172
/*
5173
SUBSUBSECTION
5174
  Reading relocations
5175
5176
  Coff relocations are easily transformed into the internal BFD form
5177
  (@code{arelent}).
5178
5179
  Reading a coff relocation table is done in the following stages:
5180
5181
  o Read the entire coff relocation table into memory.
5182
5183
  o Process each relocation in turn; first swap it from the
5184
  external to the internal form.
5185
5186
  o Turn the symbol referenced in the relocation's symbol index
5187
  into a pointer into the canonical symbol table.
5188
  This table is the same as the one returned by a call to
5189
  @code{bfd_canonicalize_symtab}. The back end will call that
5190
  routine and save the result if a canonicalization hasn't been done.
5191
5192
  o The reloc index is turned into a pointer to a howto
5193
  structure, in a back end specific way. For instance, the 386
5194
  uses the @code{r_type} to directly produce an index
5195
  into a howto table vector.
5196
5197
  o Note that @code{arelent.addend} for COFF is often not what
5198
  most people understand as a relocation addend, but rather an
5199
  adjustment to the relocation addend stored in section contents
5200
  of relocatable object files.  The value found in section
5201
  contents may also be confusing, depending on both symbol value
5202
  and addend somewhat similar to the field value for a
5203
  final-linked object.  See @code{CALC_ADDEND}.
5204
*/
5205
5206
#ifdef COFF_WITH_PE
5207
0
#define COFF_PE_ADDEND_BIAS(ptr) 0 /* Symbol value not stored in raw data.  */
5208
#else
5209
0
#define COFF_PE_ADDEND_BIAS(ptr) ((ptr)->value)
5210
#endif
5211
5212
#ifndef CALC_ADDEND
5213
#define CALC_ADDEND(abfd, ptr, reloc, cache_ptr)    \
5214
0
  {               \
5215
0
    coff_symbol_type *coffsym = NULL;       \
5216
0
                \
5217
0
    if (ptr && bfd_asymbol_bfd (ptr) != abfd)     \
5218
0
      coffsym = (obj_symbols (abfd)       \
5219
0
     + (cache_ptr->sym_ptr_ptr - symbols));   \
5220
0
    else if (ptr)           \
5221
0
      coffsym = coff_symbol_from (ptr);       \
5222
0
    if (coffsym != NULL            \
5223
0
  && coffsym->native->is_sym        \
5224
0
  && coffsym->native->u.syment.n_scnum == 0)   \
5225
0
      cache_ptr->addend = 0;         \
5226
0
    else if (ptr && bfd_asymbol_bfd (ptr) == abfd    \
5227
0
       && ptr->section != NULL)       \
5228
0
      cache_ptr->addend = - (ptr->section->vma      \
5229
0
           + COFF_PE_ADDEND_BIAS (ptr));  \
5230
0
    else              \
5231
0
      cache_ptr->addend = 0;         \
5232
0
  }
5233
#endif
5234
5235
static bool
5236
coff_slurp_reloc_table (bfd * abfd, sec_ptr asect, asymbol ** symbols)
5237
104
{
5238
104
  bfd_byte *native_relocs;
5239
104
  arelent *reloc_cache;
5240
104
  arelent *cache_ptr;
5241
104
  unsigned int idx;
5242
104
  size_t amt;
5243
5244
104
  if (asect->relocation)
5245
0
    return true;
5246
104
  if (asect->reloc_count == 0)
5247
104
    return true;
5248
0
  if (asect->flags & SEC_CONSTRUCTOR)
5249
0
    return true;
5250
0
  if (!coff_slurp_symbol_table (abfd))
5251
0
    return false;
5252
5253
0
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5254
0
               asect->reloc_count,
5255
0
               bfd_coff_relsz (abfd));
5256
0
  if (native_relocs == NULL)
5257
0
    return false;
5258
5259
0
  if (_bfd_mul_overflow (asect->reloc_count, sizeof (arelent), &amt))
5260
0
    {
5261
0
      bfd_set_error (bfd_error_file_too_big);
5262
0
      return false;
5263
0
    }
5264
0
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5265
0
  if (reloc_cache == NULL)
5266
0
    {
5267
0
      free (native_relocs);
5268
0
      return false;
5269
0
    }
5270
5271
0
  for (idx = 0; idx < asect->reloc_count; idx++)
5272
0
    {
5273
0
      struct internal_reloc dst;
5274
0
      void *src;
5275
#ifndef RELOC_PROCESSING
5276
      asymbol *ptr;
5277
#endif
5278
5279
0
      cache_ptr = reloc_cache + idx;
5280
0
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5281
5282
0
      dst.r_offset = 0;
5283
0
      bfd_coff_swap_reloc_in (abfd, src, &dst);
5284
5285
#ifdef RELOC_PROCESSING
5286
0
      RELOC_PROCESSING (cache_ptr, &dst, symbols, abfd, asect);
5287
#else
5288
      cache_ptr->address = dst.r_vaddr;
5289
5290
0
      if (dst.r_symndx != -1 && symbols != NULL)
5291
0
  {
5292
0
    if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
5293
0
      {
5294
0
        _bfd_error_handler
5295
    /* xgettext:c-format */
5296
0
    (_("%pB: warning: illegal symbol index %ld in relocs"),
5297
0
     abfd, dst.r_symndx);
5298
0
        cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5299
0
        ptr = NULL;
5300
0
      }
5301
0
    else
5302
0
      {
5303
0
        cache_ptr->sym_ptr_ptr = (symbols
5304
0
          + obj_convert (abfd)[dst.r_symndx]);
5305
0
        ptr = *(cache_ptr->sym_ptr_ptr);
5306
0
      }
5307
0
  }
5308
0
      else
5309
0
  {
5310
0
    cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5311
0
    ptr = NULL;
5312
0
  }
5313
5314
      /* The symbols definitions that we have read in have been
5315
   relocated as if their sections started at 0. But the offsets
5316
   refering to the symbols in the raw data have not been
5317
   modified, so we have to have a negative addend to compensate.
5318
5319
   Note that symbols which used to be common must be left alone.  */
5320
5321
      /* Calculate any reloc addend by looking at the symbol.  */
5322
0
      CALC_ADDEND (abfd, ptr, dst, cache_ptr);
5323
      (void) ptr;
5324
5325
      cache_ptr->address -= asect->vma;
5326
      /* !! cache_ptr->section = NULL;*/
5327
5328
      /* Fill in the cache_ptr->howto field from dst.r_type.  */
5329
0
      RTYPE2HOWTO (cache_ptr, &dst);
5330
#endif  /* RELOC_PROCESSING */
5331
5332
0
      if (cache_ptr->howto == NULL)
5333
0
  {
5334
0
    _bfd_error_handler
5335
      /* xgettext:c-format */
5336
0
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5337
0
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5338
0
    bfd_set_error (bfd_error_bad_value);
5339
0
    free (native_relocs);
5340
0
    return false;
5341
0
  }
5342
0
    }
5343
5344
0
  free (native_relocs);
5345
0
  asect->relocation = reloc_cache;
5346
0
  return true;
5347
0
}
pei-i386.c:coff_slurp_reloc_table
Line
Count
Source
5237
13
{
5238
13
  bfd_byte *native_relocs;
5239
13
  arelent *reloc_cache;
5240
13
  arelent *cache_ptr;
5241
13
  unsigned int idx;
5242
13
  size_t amt;
5243
5244
13
  if (asect->relocation)
5245
0
    return true;
5246
13
  if (asect->reloc_count == 0)
5247
13
    return true;
5248
0
  if (asect->flags & SEC_CONSTRUCTOR)
5249
0
    return true;
5250
0
  if (!coff_slurp_symbol_table (abfd))
5251
0
    return false;
5252
5253
0
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5254
0
               asect->reloc_count,
5255
0
               bfd_coff_relsz (abfd));
5256
0
  if (native_relocs == NULL)
5257
0
    return false;
5258
5259
0
  if (_bfd_mul_overflow (asect->reloc_count, sizeof (arelent), &amt))
5260
0
    {
5261
0
      bfd_set_error (bfd_error_file_too_big);
5262
0
      return false;
5263
0
    }
5264
0
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5265
0
  if (reloc_cache == NULL)
5266
0
    {
5267
0
      free (native_relocs);
5268
0
      return false;
5269
0
    }
5270
5271
0
  for (idx = 0; idx < asect->reloc_count; idx++)
5272
0
    {
5273
0
      struct internal_reloc dst;
5274
0
      void *src;
5275
0
#ifndef RELOC_PROCESSING
5276
0
      asymbol *ptr;
5277
0
#endif
5278
5279
0
      cache_ptr = reloc_cache + idx;
5280
0
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5281
5282
0
      dst.r_offset = 0;
5283
0
      bfd_coff_swap_reloc_in (abfd, src, &dst);
5284
5285
#ifdef RELOC_PROCESSING
5286
      RELOC_PROCESSING (cache_ptr, &dst, symbols, abfd, asect);
5287
#else
5288
0
      cache_ptr->address = dst.r_vaddr;
5289
5290
0
      if (dst.r_symndx != -1 && symbols != NULL)
5291
0
  {
5292
0
    if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
5293
0
      {
5294
0
        _bfd_error_handler
5295
    /* xgettext:c-format */
5296
0
    (_("%pB: warning: illegal symbol index %ld in relocs"),
5297
0
     abfd, dst.r_symndx);
5298
0
        cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5299
0
        ptr = NULL;
5300
0
      }
5301
0
    else
5302
0
      {
5303
0
        cache_ptr->sym_ptr_ptr = (symbols
5304
0
          + obj_convert (abfd)[dst.r_symndx]);
5305
0
        ptr = *(cache_ptr->sym_ptr_ptr);
5306
0
      }
5307
0
  }
5308
0
      else
5309
0
  {
5310
0
    cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5311
0
    ptr = NULL;
5312
0
  }
5313
5314
      /* The symbols definitions that we have read in have been
5315
   relocated as if their sections started at 0. But the offsets
5316
   refering to the symbols in the raw data have not been
5317
   modified, so we have to have a negative addend to compensate.
5318
5319
   Note that symbols which used to be common must be left alone.  */
5320
5321
      /* Calculate any reloc addend by looking at the symbol.  */
5322
0
      CALC_ADDEND (abfd, ptr, dst, cache_ptr);
5323
0
      (void) ptr;
5324
5325
0
      cache_ptr->address -= asect->vma;
5326
      /* !! cache_ptr->section = NULL;*/
5327
5328
      /* Fill in the cache_ptr->howto field from dst.r_type.  */
5329
0
      RTYPE2HOWTO (cache_ptr, &dst);
5330
0
#endif  /* RELOC_PROCESSING */
5331
5332
0
      if (cache_ptr->howto == NULL)
5333
0
  {
5334
0
    _bfd_error_handler
5335
      /* xgettext:c-format */
5336
0
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5337
0
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5338
0
    bfd_set_error (bfd_error_bad_value);
5339
0
    free (native_relocs);
5340
0
    return false;
5341
0
  }
5342
0
    }
5343
5344
0
  free (native_relocs);
5345
0
  asect->relocation = reloc_cache;
5346
0
  return true;
5347
0
}
Unexecuted instantiation: pe-x86_64.c:coff_slurp_reloc_table
pei-x86_64.c:coff_slurp_reloc_table
Line
Count
Source
5237
69
{
5238
69
  bfd_byte *native_relocs;
5239
69
  arelent *reloc_cache;
5240
69
  arelent *cache_ptr;
5241
69
  unsigned int idx;
5242
69
  size_t amt;
5243
5244
69
  if (asect->relocation)
5245
0
    return true;
5246
69
  if (asect->reloc_count == 0)
5247
69
    return true;
5248
0
  if (asect->flags & SEC_CONSTRUCTOR)
5249
0
    return true;
5250
0
  if (!coff_slurp_symbol_table (abfd))
5251
0
    return false;
5252
5253
0
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5254
0
               asect->reloc_count,
5255
0
               bfd_coff_relsz (abfd));
5256
0
  if (native_relocs == NULL)
5257
0
    return false;
5258
5259
0
  if (_bfd_mul_overflow (asect->reloc_count, sizeof (arelent), &amt))
5260
0
    {
5261
0
      bfd_set_error (bfd_error_file_too_big);
5262
0
      return false;
5263
0
    }
5264
0
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5265
0
  if (reloc_cache == NULL)
5266
0
    {
5267
0
      free (native_relocs);
5268
0
      return false;
5269
0
    }
5270
5271
0
  for (idx = 0; idx < asect->reloc_count; idx++)
5272
0
    {
5273
0
      struct internal_reloc dst;
5274
0
      void *src;
5275
0
#ifndef RELOC_PROCESSING
5276
0
      asymbol *ptr;
5277
0
#endif
5278
5279
0
      cache_ptr = reloc_cache + idx;
5280
0
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5281
5282
0
      dst.r_offset = 0;
5283
0
      bfd_coff_swap_reloc_in (abfd, src, &dst);
5284
5285
#ifdef RELOC_PROCESSING
5286
      RELOC_PROCESSING (cache_ptr, &dst, symbols, abfd, asect);
5287
#else
5288
0
      cache_ptr->address = dst.r_vaddr;
5289
5290
0
      if (dst.r_symndx != -1 && symbols != NULL)
5291
0
  {
5292
0
    if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
5293
0
      {
5294
0
        _bfd_error_handler
5295
    /* xgettext:c-format */
5296
0
    (_("%pB: warning: illegal symbol index %ld in relocs"),
5297
0
     abfd, dst.r_symndx);
5298
0
        cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5299
0
        ptr = NULL;
5300
0
      }
5301
0
    else
5302
0
      {
5303
0
        cache_ptr->sym_ptr_ptr = (symbols
5304
0
          + obj_convert (abfd)[dst.r_symndx]);
5305
0
        ptr = *(cache_ptr->sym_ptr_ptr);
5306
0
      }
5307
0
  }
5308
0
      else
5309
0
  {
5310
0
    cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5311
0
    ptr = NULL;
5312
0
  }
5313
5314
      /* The symbols definitions that we have read in have been
5315
   relocated as if their sections started at 0. But the offsets
5316
   refering to the symbols in the raw data have not been
5317
   modified, so we have to have a negative addend to compensate.
5318
5319
   Note that symbols which used to be common must be left alone.  */
5320
5321
      /* Calculate any reloc addend by looking at the symbol.  */
5322
0
      CALC_ADDEND (abfd, ptr, dst, cache_ptr);
5323
0
      (void) ptr;
5324
5325
0
      cache_ptr->address -= asect->vma;
5326
      /* !! cache_ptr->section = NULL;*/
5327
5328
      /* Fill in the cache_ptr->howto field from dst.r_type.  */
5329
0
      RTYPE2HOWTO (cache_ptr, &dst);
5330
0
#endif  /* RELOC_PROCESSING */
5331
5332
0
      if (cache_ptr->howto == NULL)
5333
0
  {
5334
0
    _bfd_error_handler
5335
      /* xgettext:c-format */
5336
0
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5337
0
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5338
0
    bfd_set_error (bfd_error_bad_value);
5339
0
    free (native_relocs);
5340
0
    return false;
5341
0
  }
5342
0
    }
5343
5344
0
  free (native_relocs);
5345
0
  asect->relocation = reloc_cache;
5346
0
  return true;
5347
0
}
Unexecuted instantiation: coff-x86_64.c:coff_slurp_reloc_table
Unexecuted instantiation: coff64-rs6000.c:coff_slurp_reloc_table
Unexecuted instantiation: pe-aarch64.c:coff_slurp_reloc_table
Unexecuted instantiation: pei-aarch64.c:coff_slurp_reloc_table
Unexecuted instantiation: pei-ia64.c:coff_slurp_reloc_table
Unexecuted instantiation: pei-loongarch64.c:coff_slurp_reloc_table
Unexecuted instantiation: cf-i386lynx.c:coff_slurp_reloc_table
Unexecuted instantiation: coff-go32.c:coff_slurp_reloc_table
Unexecuted instantiation: coff-i386.c:coff_slurp_reloc_table
Unexecuted instantiation: coff-rs6000.c:coff_slurp_reloc_table
Unexecuted instantiation: coff-sh.c:coff_slurp_reloc_table
Unexecuted instantiation: coff-stgo32.c:coff_slurp_reloc_table
Unexecuted instantiation: coff-tic30.c:coff_slurp_reloc_table
Unexecuted instantiation: coff-tic4x.c:coff_slurp_reloc_table
Unexecuted instantiation: coff-tic54x.c:coff_slurp_reloc_table
Unexecuted instantiation: coff-z80.c:coff_slurp_reloc_table
coff-z8k.c:coff_slurp_reloc_table
Line
Count
Source
5237
20
{
5238
20
  bfd_byte *native_relocs;
5239
20
  arelent *reloc_cache;
5240
20
  arelent *cache_ptr;
5241
20
  unsigned int idx;
5242
20
  size_t amt;
5243
5244
20
  if (asect->relocation)
5245
0
    return true;
5246
20
  if (asect->reloc_count == 0)
5247
20
    return true;
5248
0
  if (asect->flags & SEC_CONSTRUCTOR)
5249
0
    return true;
5250
0
  if (!coff_slurp_symbol_table (abfd))
5251
0
    return false;
5252
5253
0
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5254
0
               asect->reloc_count,
5255
0
               bfd_coff_relsz (abfd));
5256
0
  if (native_relocs == NULL)
5257
0
    return false;
5258
5259
0
  if (_bfd_mul_overflow (asect->reloc_count, sizeof (arelent), &amt))
5260
0
    {
5261
0
      bfd_set_error (bfd_error_file_too_big);
5262
0
      return false;
5263
0
    }
5264
0
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5265
0
  if (reloc_cache == NULL)
5266
0
    {
5267
0
      free (native_relocs);
5268
0
      return false;
5269
0
    }
5270
5271
0
  for (idx = 0; idx < asect->reloc_count; idx++)
5272
0
    {
5273
0
      struct internal_reloc dst;
5274
0
      void *src;
5275
#ifndef RELOC_PROCESSING
5276
      asymbol *ptr;
5277
#endif
5278
5279
0
      cache_ptr = reloc_cache + idx;
5280
0
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5281
5282
0
      dst.r_offset = 0;
5283
0
      bfd_coff_swap_reloc_in (abfd, src, &dst);
5284
5285
0
#ifdef RELOC_PROCESSING
5286
0
      RELOC_PROCESSING (cache_ptr, &dst, symbols, abfd, asect);
5287
#else
5288
      cache_ptr->address = dst.r_vaddr;
5289
5290
      if (dst.r_symndx != -1 && symbols != NULL)
5291
  {
5292
    if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
5293
      {
5294
        _bfd_error_handler
5295
    /* xgettext:c-format */
5296
    (_("%pB: warning: illegal symbol index %ld in relocs"),
5297
     abfd, dst.r_symndx);
5298
        cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5299
        ptr = NULL;
5300
      }
5301
    else
5302
      {
5303
        cache_ptr->sym_ptr_ptr = (symbols
5304
          + obj_convert (abfd)[dst.r_symndx]);
5305
        ptr = *(cache_ptr->sym_ptr_ptr);
5306
      }
5307
  }
5308
      else
5309
  {
5310
    cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5311
    ptr = NULL;
5312
  }
5313
5314
      /* The symbols definitions that we have read in have been
5315
   relocated as if their sections started at 0. But the offsets
5316
   refering to the symbols in the raw data have not been
5317
   modified, so we have to have a negative addend to compensate.
5318
5319
   Note that symbols which used to be common must be left alone.  */
5320
5321
      /* Calculate any reloc addend by looking at the symbol.  */
5322
      CALC_ADDEND (abfd, ptr, dst, cache_ptr);
5323
      (void) ptr;
5324
5325
      cache_ptr->address -= asect->vma;
5326
      /* !! cache_ptr->section = NULL;*/
5327
5328
      /* Fill in the cache_ptr->howto field from dst.r_type.  */
5329
      RTYPE2HOWTO (cache_ptr, &dst);
5330
#endif  /* RELOC_PROCESSING */
5331
5332
0
      if (cache_ptr->howto == NULL)
5333
0
  {
5334
0
    _bfd_error_handler
5335
      /* xgettext:c-format */
5336
0
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5337
0
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5338
0
    bfd_set_error (bfd_error_bad_value);
5339
0
    free (native_relocs);
5340
0
    return false;
5341
0
  }
5342
0
    }
5343
5344
0
  free (native_relocs);
5345
0
  asect->relocation = reloc_cache;
5346
0
  return true;
5347
0
}
Unexecuted instantiation: pe-arm-wince.c:coff_slurp_reloc_table
Unexecuted instantiation: pe-arm.c:coff_slurp_reloc_table
pe-i386.c:coff_slurp_reloc_table
Line
Count
Source
5237
1
{
5238
1
  bfd_byte *native_relocs;
5239
1
  arelent *reloc_cache;
5240
1
  arelent *cache_ptr;
5241
1
  unsigned int idx;
5242
1
  size_t amt;
5243
5244
1
  if (asect->relocation)
5245
0
    return true;
5246
1
  if (asect->reloc_count == 0)
5247
1
    return true;
5248
0
  if (asect->flags & SEC_CONSTRUCTOR)
5249
0
    return true;
5250
0
  if (!coff_slurp_symbol_table (abfd))
5251
0
    return false;
5252
5253
0
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5254
0
               asect->reloc_count,
5255
0
               bfd_coff_relsz (abfd));
5256
0
  if (native_relocs == NULL)
5257
0
    return false;
5258
5259
0
  if (_bfd_mul_overflow (asect->reloc_count, sizeof (arelent), &amt))
5260
0
    {
5261
0
      bfd_set_error (bfd_error_file_too_big);
5262
0
      return false;
5263
0
    }
5264
0
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5265
0
  if (reloc_cache == NULL)
5266
0
    {
5267
0
      free (native_relocs);
5268
0
      return false;
5269
0
    }
5270
5271
0
  for (idx = 0; idx < asect->reloc_count; idx++)
5272
0
    {
5273
0
      struct internal_reloc dst;
5274
0
      void *src;
5275
0
#ifndef RELOC_PROCESSING
5276
0
      asymbol *ptr;
5277
0
#endif
5278
5279
0
      cache_ptr = reloc_cache + idx;
5280
0
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5281
5282
0
      dst.r_offset = 0;
5283
0
      bfd_coff_swap_reloc_in (abfd, src, &dst);
5284
5285
#ifdef RELOC_PROCESSING
5286
      RELOC_PROCESSING (cache_ptr, &dst, symbols, abfd, asect);
5287
#else
5288
0
      cache_ptr->address = dst.r_vaddr;
5289
5290
0
      if (dst.r_symndx != -1 && symbols != NULL)
5291
0
  {
5292
0
    if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
5293
0
      {
5294
0
        _bfd_error_handler
5295
    /* xgettext:c-format */
5296
0
    (_("%pB: warning: illegal symbol index %ld in relocs"),
5297
0
     abfd, dst.r_symndx);
5298
0
        cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5299
0
        ptr = NULL;
5300
0
      }
5301
0
    else
5302
0
      {
5303
0
        cache_ptr->sym_ptr_ptr = (symbols
5304
0
          + obj_convert (abfd)[dst.r_symndx]);
5305
0
        ptr = *(cache_ptr->sym_ptr_ptr);
5306
0
      }
5307
0
  }
5308
0
      else
5309
0
  {
5310
0
    cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5311
0
    ptr = NULL;
5312
0
  }
5313
5314
      /* The symbols definitions that we have read in have been
5315
   relocated as if their sections started at 0. But the offsets
5316
   refering to the symbols in the raw data have not been
5317
   modified, so we have to have a negative addend to compensate.
5318
5319
   Note that symbols which used to be common must be left alone.  */
5320
5321
      /* Calculate any reloc addend by looking at the symbol.  */
5322
0
      CALC_ADDEND (abfd, ptr, dst, cache_ptr);
5323
0
      (void) ptr;
5324
5325
0
      cache_ptr->address -= asect->vma;
5326
      /* !! cache_ptr->section = NULL;*/
5327
5328
      /* Fill in the cache_ptr->howto field from dst.r_type.  */
5329
0
      RTYPE2HOWTO (cache_ptr, &dst);
5330
0
#endif  /* RELOC_PROCESSING */
5331
5332
0
      if (cache_ptr->howto == NULL)
5333
0
  {
5334
0
    _bfd_error_handler
5335
      /* xgettext:c-format */
5336
0
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5337
0
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5338
0
    bfd_set_error (bfd_error_bad_value);
5339
0
    free (native_relocs);
5340
0
    return false;
5341
0
  }
5342
0
    }
5343
5344
0
  free (native_relocs);
5345
0
  asect->relocation = reloc_cache;
5346
0
  return true;
5347
0
}
pe-mcore.c:coff_slurp_reloc_table
Line
Count
Source
5237
1
{
5238
1
  bfd_byte *native_relocs;
5239
1
  arelent *reloc_cache;
5240
1
  arelent *cache_ptr;
5241
1
  unsigned int idx;
5242
1
  size_t amt;
5243
5244
1
  if (asect->relocation)
5245
0
    return true;
5246
1
  if (asect->reloc_count == 0)
5247
1
    return true;
5248
0
  if (asect->flags & SEC_CONSTRUCTOR)
5249
0
    return true;
5250
0
  if (!coff_slurp_symbol_table (abfd))
5251
0
    return false;
5252
5253
0
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5254
0
               asect->reloc_count,
5255
0
               bfd_coff_relsz (abfd));
5256
0
  if (native_relocs == NULL)
5257
0
    return false;
5258
5259
0
  if (_bfd_mul_overflow (asect->reloc_count, sizeof (arelent), &amt))
5260
0
    {
5261
0
      bfd_set_error (bfd_error_file_too_big);
5262
0
      return false;
5263
0
    }
5264
0
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5265
0
  if (reloc_cache == NULL)
5266
0
    {
5267
0
      free (native_relocs);
5268
0
      return false;
5269
0
    }
5270
5271
0
  for (idx = 0; idx < asect->reloc_count; idx++)
5272
0
    {
5273
0
      struct internal_reloc dst;
5274
0
      void *src;
5275
0
#ifndef RELOC_PROCESSING
5276
0
      asymbol *ptr;
5277
0
#endif
5278
5279
0
      cache_ptr = reloc_cache + idx;
5280
0
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5281
5282
0
      dst.r_offset = 0;
5283
0
      bfd_coff_swap_reloc_in (abfd, src, &dst);
5284
5285
#ifdef RELOC_PROCESSING
5286
      RELOC_PROCESSING (cache_ptr, &dst, symbols, abfd, asect);
5287
#else
5288
0
      cache_ptr->address = dst.r_vaddr;
5289
5290
0
      if (dst.r_symndx != -1 && symbols != NULL)
5291
0
  {
5292
0
    if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
5293
0
      {
5294
0
        _bfd_error_handler
5295
    /* xgettext:c-format */
5296
0
    (_("%pB: warning: illegal symbol index %ld in relocs"),
5297
0
     abfd, dst.r_symndx);
5298
0
        cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5299
0
        ptr = NULL;
5300
0
      }
5301
0
    else
5302
0
      {
5303
0
        cache_ptr->sym_ptr_ptr = (symbols
5304
0
          + obj_convert (abfd)[dst.r_symndx]);
5305
0
        ptr = *(cache_ptr->sym_ptr_ptr);
5306
0
      }
5307
0
  }
5308
0
      else
5309
0
  {
5310
0
    cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5311
0
    ptr = NULL;
5312
0
  }
5313
5314
      /* The symbols definitions that we have read in have been
5315
   relocated as if their sections started at 0. But the offsets
5316
   refering to the symbols in the raw data have not been
5317
   modified, so we have to have a negative addend to compensate.
5318
5319
   Note that symbols which used to be common must be left alone.  */
5320
5321
      /* Calculate any reloc addend by looking at the symbol.  */
5322
0
      CALC_ADDEND (abfd, ptr, dst, cache_ptr);
5323
0
      (void) ptr;
5324
5325
0
      cache_ptr->address -= asect->vma;
5326
      /* !! cache_ptr->section = NULL;*/
5327
5328
      /* Fill in the cache_ptr->howto field from dst.r_type.  */
5329
0
      RTYPE2HOWTO (cache_ptr, &dst);
5330
0
#endif  /* RELOC_PROCESSING */
5331
5332
0
      if (cache_ptr->howto == NULL)
5333
0
  {
5334
0
    _bfd_error_handler
5335
      /* xgettext:c-format */
5336
0
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5337
0
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5338
0
    bfd_set_error (bfd_error_bad_value);
5339
0
    free (native_relocs);
5340
0
    return false;
5341
0
  }
5342
0
    }
5343
5344
0
  free (native_relocs);
5345
0
  asect->relocation = reloc_cache;
5346
0
  return true;
5347
0
}
Unexecuted instantiation: pe-sh.c:coff_slurp_reloc_table
Unexecuted instantiation: pei-arm-wince.c:coff_slurp_reloc_table
Unexecuted instantiation: pei-arm.c:coff_slurp_reloc_table
Unexecuted instantiation: pei-mcore.c:coff_slurp_reloc_table
Unexecuted instantiation: pei-sh.c:coff_slurp_reloc_table
5348
5349
#ifndef coff_rtype_to_howto
5350
#ifdef RTYPE2HOWTO
5351
5352
/* Get the howto structure for a reloc.  This is only used if the file
5353
   including this one defines coff_relocate_section to be
5354
   _bfd_coff_generic_relocate_section, so it is OK if it does not
5355
   always work.  It is the responsibility of the including file to
5356
   make sure it is reasonable if it is needed.  */
5357
5358
static reloc_howto_type *
5359
coff_rtype_to_howto (bfd *abfd ATTRIBUTE_UNUSED,
5360
         asection *sec ATTRIBUTE_UNUSED,
5361
         struct internal_reloc *rel ATTRIBUTE_UNUSED,
5362
         struct coff_link_hash_entry *h ATTRIBUTE_UNUSED,
5363
         struct internal_syment *sym ATTRIBUTE_UNUSED,
5364
         bfd_vma *addendp ATTRIBUTE_UNUSED)
5365
0
{
5366
0
  arelent genrel;
5367
5368
0
  genrel.howto = NULL;
5369
0
  RTYPE2HOWTO (&genrel, rel);
5370
0
  return genrel.howto;
5371
0
}
Unexecuted instantiation: coff64-rs6000.c:coff_rtype_to_howto
Unexecuted instantiation: pei-ia64.c:coff_rtype_to_howto
Unexecuted instantiation: pei-loongarch64.c:coff_rtype_to_howto
Unexecuted instantiation: coff-rs6000.c:coff_rtype_to_howto
Unexecuted instantiation: coff-sh.c:coff_rtype_to_howto
Unexecuted instantiation: coff-tic30.c:coff_rtype_to_howto
Unexecuted instantiation: coff-z80.c:coff_rtype_to_howto
Unexecuted instantiation: coff-z8k.c:coff_rtype_to_howto
5372
5373
#else /* ! defined (RTYPE2HOWTO) */
5374
5375
#define coff_rtype_to_howto NULL
5376
5377
#endif /* ! defined (RTYPE2HOWTO) */
5378
#endif /* ! defined (coff_rtype_to_howto) */
5379
5380
/* This is stupid.  This function should be a boolean predicate.  */
5381
5382
static long
5383
coff_canonicalize_reloc (bfd * abfd,
5384
       sec_ptr section,
5385
       arelent ** relptr,
5386
       asymbol ** symbols)
5387
104
{
5388
104
  arelent *tblptr = section->relocation;
5389
104
  unsigned int count = 0;
5390
5391
104
  if (section->flags & SEC_CONSTRUCTOR)
5392
0
    {
5393
      /* This section has relocs made up by us, they are not in the
5394
   file, so take them out of their chain and place them into
5395
   the data area provided.  */
5396
0
      arelent_chain *chain = section->constructor_chain;
5397
5398
0
      for (count = 0; count < section->reloc_count; count++)
5399
0
  {
5400
0
    *relptr++ = &chain->relent;
5401
0
    chain = chain->next;
5402
0
  }
5403
0
    }
5404
104
  else
5405
104
    {
5406
104
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5407
0
  return -1;
5408
5409
104
      tblptr = section->relocation;
5410
5411
104
      for (; count++ < section->reloc_count;)
5412
0
  *relptr++ = tblptr++;
5413
104
    }
5414
104
  *relptr = 0;
5415
104
  return section->reloc_count;
5416
104
}
pei-i386.c:coff_canonicalize_reloc
Line
Count
Source
5387
13
{
5388
13
  arelent *tblptr = section->relocation;
5389
13
  unsigned int count = 0;
5390
5391
13
  if (section->flags & SEC_CONSTRUCTOR)
5392
0
    {
5393
      /* This section has relocs made up by us, they are not in the
5394
   file, so take them out of their chain and place them into
5395
   the data area provided.  */
5396
0
      arelent_chain *chain = section->constructor_chain;
5397
5398
0
      for (count = 0; count < section->reloc_count; count++)
5399
0
  {
5400
0
    *relptr++ = &chain->relent;
5401
0
    chain = chain->next;
5402
0
  }
5403
0
    }
5404
13
  else
5405
13
    {
5406
13
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5407
0
  return -1;
5408
5409
13
      tblptr = section->relocation;
5410
5411
13
      for (; count++ < section->reloc_count;)
5412
0
  *relptr++ = tblptr++;
5413
13
    }
5414
13
  *relptr = 0;
5415
13
  return section->reloc_count;
5416
13
}
Unexecuted instantiation: pe-x86_64.c:coff_canonicalize_reloc
pei-x86_64.c:coff_canonicalize_reloc
Line
Count
Source
5387
69
{
5388
69
  arelent *tblptr = section->relocation;
5389
69
  unsigned int count = 0;
5390
5391
69
  if (section->flags & SEC_CONSTRUCTOR)
5392
0
    {
5393
      /* This section has relocs made up by us, they are not in the
5394
   file, so take them out of their chain and place them into
5395
   the data area provided.  */
5396
0
      arelent_chain *chain = section->constructor_chain;
5397
5398
0
      for (count = 0; count < section->reloc_count; count++)
5399
0
  {
5400
0
    *relptr++ = &chain->relent;
5401
0
    chain = chain->next;
5402
0
  }
5403
0
    }
5404
69
  else
5405
69
    {
5406
69
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5407
0
  return -1;
5408
5409
69
      tblptr = section->relocation;
5410
5411
69
      for (; count++ < section->reloc_count;)
5412
0
  *relptr++ = tblptr++;
5413
69
    }
5414
69
  *relptr = 0;
5415
69
  return section->reloc_count;
5416
69
}
Unexecuted instantiation: coff-x86_64.c:coff_canonicalize_reloc
Unexecuted instantiation: coff64-rs6000.c:coff_canonicalize_reloc
Unexecuted instantiation: pe-aarch64.c:coff_canonicalize_reloc
Unexecuted instantiation: pei-aarch64.c:coff_canonicalize_reloc
Unexecuted instantiation: pei-ia64.c:coff_canonicalize_reloc
Unexecuted instantiation: pei-loongarch64.c:coff_canonicalize_reloc
Unexecuted instantiation: cf-i386lynx.c:coff_canonicalize_reloc
Unexecuted instantiation: coff-go32.c:coff_canonicalize_reloc
Unexecuted instantiation: coff-i386.c:coff_canonicalize_reloc
Unexecuted instantiation: coff-rs6000.c:coff_canonicalize_reloc
Unexecuted instantiation: coff-sh.c:coff_canonicalize_reloc
Unexecuted instantiation: coff-stgo32.c:coff_canonicalize_reloc
Unexecuted instantiation: coff-tic30.c:coff_canonicalize_reloc
Unexecuted instantiation: coff-tic4x.c:coff_canonicalize_reloc
Unexecuted instantiation: coff-tic54x.c:coff_canonicalize_reloc
Unexecuted instantiation: coff-z80.c:coff_canonicalize_reloc
coff-z8k.c:coff_canonicalize_reloc
Line
Count
Source
5387
20
{
5388
20
  arelent *tblptr = section->relocation;
5389
20
  unsigned int count = 0;
5390
5391
20
  if (section->flags & SEC_CONSTRUCTOR)
5392
0
    {
5393
      /* This section has relocs made up by us, they are not in the
5394
   file, so take them out of their chain and place them into
5395
   the data area provided.  */
5396
0
      arelent_chain *chain = section->constructor_chain;
5397
5398
0
      for (count = 0; count < section->reloc_count; count++)
5399
0
  {
5400
0
    *relptr++ = &chain->relent;
5401
0
    chain = chain->next;
5402
0
  }
5403
0
    }
5404
20
  else
5405
20
    {
5406
20
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5407
0
  return -1;
5408
5409
20
      tblptr = section->relocation;
5410
5411
20
      for (; count++ < section->reloc_count;)
5412
0
  *relptr++ = tblptr++;
5413
20
    }
5414
20
  *relptr = 0;
5415
20
  return section->reloc_count;
5416
20
}
Unexecuted instantiation: pe-arm-wince.c:coff_canonicalize_reloc
Unexecuted instantiation: pe-arm.c:coff_canonicalize_reloc
pe-i386.c:coff_canonicalize_reloc
Line
Count
Source
5387
1
{
5388
1
  arelent *tblptr = section->relocation;
5389
1
  unsigned int count = 0;
5390
5391
1
  if (section->flags & SEC_CONSTRUCTOR)
5392
0
    {
5393
      /* This section has relocs made up by us, they are not in the
5394
   file, so take them out of their chain and place them into
5395
   the data area provided.  */
5396
0
      arelent_chain *chain = section->constructor_chain;
5397
5398
0
      for (count = 0; count < section->reloc_count; count++)
5399
0
  {
5400
0
    *relptr++ = &chain->relent;
5401
0
    chain = chain->next;
5402
0
  }
5403
0
    }
5404
1
  else
5405
1
    {
5406
1
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5407
0
  return -1;
5408
5409
1
      tblptr = section->relocation;
5410
5411
1
      for (; count++ < section->reloc_count;)
5412
0
  *relptr++ = tblptr++;
5413
1
    }
5414
1
  *relptr = 0;
5415
1
  return section->reloc_count;
5416
1
}
pe-mcore.c:coff_canonicalize_reloc
Line
Count
Source
5387
1
{
5388
1
  arelent *tblptr = section->relocation;
5389
1
  unsigned int count = 0;
5390
5391
1
  if (section->flags & SEC_CONSTRUCTOR)
5392
0
    {
5393
      /* This section has relocs made up by us, they are not in the
5394
   file, so take them out of their chain and place them into
5395
   the data area provided.  */
5396
0
      arelent_chain *chain = section->constructor_chain;
5397
5398
0
      for (count = 0; count < section->reloc_count; count++)
5399
0
  {
5400
0
    *relptr++ = &chain->relent;
5401
0
    chain = chain->next;
5402
0
  }
5403
0
    }
5404
1
  else
5405
1
    {
5406
1
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5407
0
  return -1;
5408
5409
1
      tblptr = section->relocation;
5410
5411
1
      for (; count++ < section->reloc_count;)
5412
0
  *relptr++ = tblptr++;
5413
1
    }
5414
1
  *relptr = 0;
5415
1
  return section->reloc_count;
5416
1
}
Unexecuted instantiation: pe-sh.c:coff_canonicalize_reloc
Unexecuted instantiation: pei-arm-wince.c:coff_canonicalize_reloc
Unexecuted instantiation: pei-arm.c:coff_canonicalize_reloc
Unexecuted instantiation: pei-mcore.c:coff_canonicalize_reloc
Unexecuted instantiation: pei-sh.c:coff_canonicalize_reloc
5417
5418
#ifndef coff_set_reloc
5419
#define coff_set_reloc _bfd_generic_set_reloc
5420
#endif
5421
5422
#ifndef coff_reloc16_estimate
5423
#define coff_reloc16_estimate dummy_reloc16_estimate
5424
5425
static int
5426
dummy_reloc16_estimate (bfd *abfd ATTRIBUTE_UNUSED,
5427
      asection *input_section ATTRIBUTE_UNUSED,
5428
      arelent *reloc ATTRIBUTE_UNUSED,
5429
      unsigned int shrink ATTRIBUTE_UNUSED,
5430
      struct bfd_link_info *link_info ATTRIBUTE_UNUSED)
5431
0
{
5432
0
  abort ();
5433
0
  return 0;
5434
0
}
Unexecuted instantiation: pei-i386.c:dummy_reloc16_estimate
Unexecuted instantiation: pe-x86_64.c:dummy_reloc16_estimate
Unexecuted instantiation: pei-x86_64.c:dummy_reloc16_estimate
Unexecuted instantiation: coff-x86_64.c:dummy_reloc16_estimate
Unexecuted instantiation: coff64-rs6000.c:dummy_reloc16_estimate
Unexecuted instantiation: pe-aarch64.c:dummy_reloc16_estimate
Unexecuted instantiation: pei-aarch64.c:dummy_reloc16_estimate
Unexecuted instantiation: pei-ia64.c:dummy_reloc16_estimate
Unexecuted instantiation: pei-loongarch64.c:dummy_reloc16_estimate
Unexecuted instantiation: cf-i386lynx.c:dummy_reloc16_estimate
Unexecuted instantiation: coff-go32.c:dummy_reloc16_estimate
Unexecuted instantiation: coff-i386.c:dummy_reloc16_estimate
Unexecuted instantiation: coff-rs6000.c:dummy_reloc16_estimate
Unexecuted instantiation: coff-sh.c:dummy_reloc16_estimate
Unexecuted instantiation: coff-stgo32.c:dummy_reloc16_estimate
Unexecuted instantiation: coff-tic30.c:dummy_reloc16_estimate
Unexecuted instantiation: coff-tic4x.c:dummy_reloc16_estimate
Unexecuted instantiation: coff-tic54x.c:dummy_reloc16_estimate
Unexecuted instantiation: coff-z80.c:dummy_reloc16_estimate
Unexecuted instantiation: coff-z8k.c:dummy_reloc16_estimate
Unexecuted instantiation: pe-arm-wince.c:dummy_reloc16_estimate
Unexecuted instantiation: pe-arm.c:dummy_reloc16_estimate
Unexecuted instantiation: pe-i386.c:dummy_reloc16_estimate
Unexecuted instantiation: pe-mcore.c:dummy_reloc16_estimate
Unexecuted instantiation: pe-sh.c:dummy_reloc16_estimate
Unexecuted instantiation: pei-arm-wince.c:dummy_reloc16_estimate
Unexecuted instantiation: pei-arm.c:dummy_reloc16_estimate
Unexecuted instantiation: pei-mcore.c:dummy_reloc16_estimate
Unexecuted instantiation: pei-sh.c:dummy_reloc16_estimate
5435
5436
#endif
5437
5438
#ifndef coff_reloc16_extra_cases
5439
5440
#define coff_reloc16_extra_cases dummy_reloc16_extra_cases
5441
5442
static bool
5443
dummy_reloc16_extra_cases (bfd *abfd ATTRIBUTE_UNUSED,
5444
         struct bfd_link_info *link_info ATTRIBUTE_UNUSED,
5445
         struct bfd_link_order *link_order ATTRIBUTE_UNUSED,
5446
         arelent *reloc ATTRIBUTE_UNUSED,
5447
         bfd_byte *data ATTRIBUTE_UNUSED,
5448
         size_t *src_ptr ATTRIBUTE_UNUSED,
5449
         size_t *dst_ptr ATTRIBUTE_UNUSED)
5450
0
{
5451
0
  return false;
5452
0
}
Unexecuted instantiation: pei-i386.c:dummy_reloc16_extra_cases
Unexecuted instantiation: pe-x86_64.c:dummy_reloc16_extra_cases
Unexecuted instantiation: pei-x86_64.c:dummy_reloc16_extra_cases
Unexecuted instantiation: coff-x86_64.c:dummy_reloc16_extra_cases
Unexecuted instantiation: coff64-rs6000.c:dummy_reloc16_extra_cases
Unexecuted instantiation: pe-aarch64.c:dummy_reloc16_extra_cases
Unexecuted instantiation: pei-aarch64.c:dummy_reloc16_extra_cases
Unexecuted instantiation: pei-ia64.c:dummy_reloc16_extra_cases
Unexecuted instantiation: pei-loongarch64.c:dummy_reloc16_extra_cases
Unexecuted instantiation: cf-i386lynx.c:dummy_reloc16_extra_cases
Unexecuted instantiation: coff-go32.c:dummy_reloc16_extra_cases
Unexecuted instantiation: coff-i386.c:dummy_reloc16_extra_cases
Unexecuted instantiation: coff-rs6000.c:dummy_reloc16_extra_cases
Unexecuted instantiation: coff-sh.c:dummy_reloc16_extra_cases
Unexecuted instantiation: coff-stgo32.c:dummy_reloc16_extra_cases
Unexecuted instantiation: coff-tic30.c:dummy_reloc16_extra_cases
Unexecuted instantiation: coff-tic4x.c:dummy_reloc16_extra_cases
Unexecuted instantiation: coff-tic54x.c:dummy_reloc16_extra_cases
Unexecuted instantiation: pe-arm-wince.c:dummy_reloc16_extra_cases
Unexecuted instantiation: pe-arm.c:dummy_reloc16_extra_cases
Unexecuted instantiation: pe-i386.c:dummy_reloc16_extra_cases
Unexecuted instantiation: pe-mcore.c:dummy_reloc16_extra_cases
Unexecuted instantiation: pe-sh.c:dummy_reloc16_extra_cases
Unexecuted instantiation: pei-arm-wince.c:dummy_reloc16_extra_cases
Unexecuted instantiation: pei-arm.c:dummy_reloc16_extra_cases
Unexecuted instantiation: pei-mcore.c:dummy_reloc16_extra_cases
Unexecuted instantiation: pei-sh.c:dummy_reloc16_extra_cases
5453
#endif
5454
5455
/* If coff_relocate_section is defined, we can use the optimized COFF
5456
   backend linker.  Otherwise we must continue to use the old linker.  */
5457
5458
#ifdef coff_relocate_section
5459
5460
#ifndef coff_bfd_link_hash_table_create
5461
#define coff_bfd_link_hash_table_create _bfd_coff_link_hash_table_create
5462
#endif
5463
#ifndef coff_bfd_link_add_symbols
5464
#define coff_bfd_link_add_symbols _bfd_coff_link_add_symbols
5465
#endif
5466
#ifndef coff_bfd_final_link
5467
#define coff_bfd_final_link _bfd_coff_final_link
5468
#endif
5469
5470
#else /* ! defined (coff_relocate_section) */
5471
5472
#define coff_relocate_section NULL
5473
#ifndef coff_bfd_link_hash_table_create
5474
#define coff_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
5475
#endif
5476
#ifndef coff_bfd_link_add_symbols
5477
#define coff_bfd_link_add_symbols _bfd_generic_link_add_symbols
5478
#endif
5479
#define coff_bfd_final_link _bfd_generic_final_link
5480
5481
#endif /* ! defined (coff_relocate_section) */
5482
5483
#define coff_bfd_link_just_syms      _bfd_generic_link_just_syms
5484
#define coff_bfd_copy_link_hash_symbol_type \
5485
  _bfd_generic_copy_link_hash_symbol_type
5486
#define coff_bfd_link_split_section  _bfd_generic_link_split_section
5487
5488
#define coff_bfd_link_check_relocs   _bfd_generic_link_check_relocs
5489
5490
#ifndef coff_start_final_link
5491
#define coff_start_final_link NULL
5492
#endif
5493
5494
#ifndef coff_adjust_symndx
5495
#define coff_adjust_symndx NULL
5496
#endif
5497
5498
#ifndef coff_link_add_one_symbol
5499
#define coff_link_add_one_symbol _bfd_generic_link_add_one_symbol
5500
#endif
5501
5502
#ifndef coff_link_output_has_begun
5503
5504
static bool
5505
coff_link_output_has_begun (bfd * abfd,
5506
          struct coff_final_link_info * info ATTRIBUTE_UNUSED)
5507
0
{
5508
0
  return abfd->output_has_begun;
5509
0
}
Unexecuted instantiation: pei-i386.c:coff_link_output_has_begun
Unexecuted instantiation: pe-x86_64.c:coff_link_output_has_begun
Unexecuted instantiation: pei-x86_64.c:coff_link_output_has_begun
Unexecuted instantiation: coff-x86_64.c:coff_link_output_has_begun
Unexecuted instantiation: coff64-rs6000.c:coff_link_output_has_begun
Unexecuted instantiation: pe-aarch64.c:coff_link_output_has_begun
Unexecuted instantiation: pei-aarch64.c:coff_link_output_has_begun
Unexecuted instantiation: pei-ia64.c:coff_link_output_has_begun
Unexecuted instantiation: pei-loongarch64.c:coff_link_output_has_begun
Unexecuted instantiation: cf-i386lynx.c:coff_link_output_has_begun
Unexecuted instantiation: coff-go32.c:coff_link_output_has_begun
Unexecuted instantiation: coff-i386.c:coff_link_output_has_begun
Unexecuted instantiation: coff-rs6000.c:coff_link_output_has_begun
Unexecuted instantiation: coff-sh.c:coff_link_output_has_begun
Unexecuted instantiation: coff-stgo32.c:coff_link_output_has_begun
Unexecuted instantiation: coff-tic30.c:coff_link_output_has_begun
Unexecuted instantiation: coff-tic4x.c:coff_link_output_has_begun
Unexecuted instantiation: coff-tic54x.c:coff_link_output_has_begun
Unexecuted instantiation: coff-z80.c:coff_link_output_has_begun
Unexecuted instantiation: coff-z8k.c:coff_link_output_has_begun
Unexecuted instantiation: pe-i386.c:coff_link_output_has_begun
Unexecuted instantiation: pe-mcore.c:coff_link_output_has_begun
Unexecuted instantiation: pe-sh.c:coff_link_output_has_begun
Unexecuted instantiation: pei-mcore.c:coff_link_output_has_begun
Unexecuted instantiation: pei-sh.c:coff_link_output_has_begun
5510
#endif
5511
5512
#ifndef coff_final_link_postscript
5513
5514
static bool
5515
coff_final_link_postscript (bfd * abfd ATTRIBUTE_UNUSED,
5516
          struct coff_final_link_info * pfinfo ATTRIBUTE_UNUSED)
5517
0
{
5518
0
  return true;
5519
0
}
Unexecuted instantiation: coff-x86_64.c:coff_final_link_postscript
Unexecuted instantiation: coff64-rs6000.c:coff_final_link_postscript
Unexecuted instantiation: cf-i386lynx.c:coff_final_link_postscript
Unexecuted instantiation: coff-go32.c:coff_final_link_postscript
Unexecuted instantiation: coff-i386.c:coff_final_link_postscript
Unexecuted instantiation: coff-rs6000.c:coff_final_link_postscript
Unexecuted instantiation: coff-sh.c:coff_final_link_postscript
Unexecuted instantiation: coff-stgo32.c:coff_final_link_postscript
Unexecuted instantiation: coff-tic30.c:coff_final_link_postscript
Unexecuted instantiation: coff-tic4x.c:coff_final_link_postscript
Unexecuted instantiation: coff-tic54x.c:coff_final_link_postscript
Unexecuted instantiation: coff-z80.c:coff_final_link_postscript
Unexecuted instantiation: coff-z8k.c:coff_final_link_postscript
5520
#endif
5521
5522
#ifndef coff_SWAP_aux_in
5523
#define coff_SWAP_aux_in coff_swap_aux_in
5524
#endif
5525
#ifndef coff_SWAP_sym_in
5526
#define coff_SWAP_sym_in coff_swap_sym_in
5527
#endif
5528
#ifndef coff_SWAP_lineno_in
5529
#define coff_SWAP_lineno_in coff_swap_lineno_in
5530
#endif
5531
#ifndef coff_SWAP_aux_out
5532
#define coff_SWAP_aux_out coff_swap_aux_out
5533
#endif
5534
#ifndef coff_SWAP_sym_out
5535
#define coff_SWAP_sym_out coff_swap_sym_out
5536
#endif
5537
#ifndef coff_SWAP_lineno_out
5538
#define coff_SWAP_lineno_out coff_swap_lineno_out
5539
#endif
5540
#ifndef coff_SWAP_reloc_out
5541
#define coff_SWAP_reloc_out coff_swap_reloc_out
5542
#endif
5543
#ifndef coff_SWAP_filehdr_out
5544
#define coff_SWAP_filehdr_out coff_swap_filehdr_out
5545
#endif
5546
#ifndef coff_SWAP_aouthdr_out
5547
#define coff_SWAP_aouthdr_out coff_swap_aouthdr_out
5548
#endif
5549
#ifndef coff_SWAP_scnhdr_out
5550
#define coff_SWAP_scnhdr_out coff_swap_scnhdr_out
5551
#endif
5552
#ifndef coff_SWAP_reloc_in
5553
#define coff_SWAP_reloc_in coff_swap_reloc_in
5554
#endif
5555
#ifndef coff_SWAP_filehdr_in
5556
#define coff_SWAP_filehdr_in coff_swap_filehdr_in
5557
#endif
5558
#ifndef coff_SWAP_aouthdr_in
5559
#define coff_SWAP_aouthdr_in coff_swap_aouthdr_in
5560
#endif
5561
#ifndef coff_SWAP_scnhdr_in
5562
#define coff_SWAP_scnhdr_in coff_swap_scnhdr_in
5563
#endif
5564
5565
#define COFF_SWAP_TABLE (void *) &bfd_coff_std_swap_table
5566
5567
static const bfd_coff_backend_data bfd_coff_std_swap_table ATTRIBUTE_UNUSED =
5568
{
5569
  coff_SWAP_aux_in, coff_SWAP_sym_in, coff_SWAP_lineno_in,
5570
  coff_SWAP_aux_out, coff_SWAP_sym_out,
5571
  coff_SWAP_lineno_out, coff_SWAP_reloc_out,
5572
  coff_SWAP_filehdr_out, coff_SWAP_aouthdr_out,
5573
  coff_SWAP_scnhdr_out,
5574
  FILHSZ, AOUTSZ, SCNHSZ, SYMESZ, AUXESZ, RELSZ, LINESZ, FILNMLEN,
5575
#ifdef COFF_LONG_FILENAMES
5576
  true,
5577
#else
5578
  false,
5579
#endif
5580
  COFF_DEFAULT_LONG_SECTION_NAMES,
5581
  COFF_DEFAULT_SECTION_ALIGNMENT_POWER,
5582
#ifdef COFF_FORCE_SYMBOLS_IN_STRINGS
5583
  true,
5584
#else
5585
  false,
5586
#endif
5587
#ifdef COFF_DEBUG_STRING_WIDE_PREFIX
5588
  4,
5589
#else
5590
  2,
5591
#endif
5592
  32768,
5593
  coff_SWAP_filehdr_in, coff_SWAP_aouthdr_in, coff_SWAP_scnhdr_in,
5594
  coff_SWAP_reloc_in, coff_bad_format_hook, coff_set_arch_mach_hook,
5595
  coff_mkobject_hook, styp_to_sec_flags, coff_set_alignment_hook,
5596
  coff_slurp_symbol_table, symname_in_debug_hook, coff_pointerize_aux_hook,
5597
  coff_print_aux, coff_reloc16_extra_cases, coff_reloc16_estimate,
5598
  coff_classify_symbol, coff_compute_section_file_positions,
5599
  coff_start_final_link, coff_relocate_section, coff_rtype_to_howto,
5600
  coff_adjust_symndx, coff_link_add_one_symbol,
5601
  coff_link_output_has_begun, coff_final_link_postscript,
5602
  bfd_pe_print_pdata
5603
};
5604
5605
#ifdef TICOFF
5606
/* COFF0 differs in file/section header size and relocation entry size.  */
5607
5608
static const bfd_coff_backend_data ticoff0_swap_table =
5609
{
5610
  coff_SWAP_aux_in, coff_SWAP_sym_in, coff_SWAP_lineno_in,
5611
  coff_SWAP_aux_out, coff_SWAP_sym_out,
5612
  coff_SWAP_lineno_out, coff_swap_reloc_v0_out,
5613
  coff_SWAP_filehdr_out, coff_SWAP_aouthdr_out,
5614
  coff_SWAP_scnhdr_out,
5615
  FILHSZ_V0, AOUTSZ, SCNHSZ_V01, SYMESZ, AUXESZ, RELSZ_V0, LINESZ, FILNMLEN,
5616
#ifdef COFF_LONG_FILENAMES
5617
  true,
5618
#else
5619
  false,
5620
#endif
5621
  COFF_DEFAULT_LONG_SECTION_NAMES,
5622
  COFF_DEFAULT_SECTION_ALIGNMENT_POWER,
5623
#ifdef COFF_FORCE_SYMBOLS_IN_STRINGS
5624
  true,
5625
#else
5626
  false,
5627
#endif
5628
#ifdef COFF_DEBUG_STRING_WIDE_PREFIX
5629
  4,
5630
#else
5631
  2,
5632
#endif
5633
  32768,
5634
  coff_SWAP_filehdr_in, coff_SWAP_aouthdr_in, coff_SWAP_scnhdr_in,
5635
  coff_swap_reloc_v0_in, ticoff0_bad_format_hook, coff_set_arch_mach_hook,
5636
  coff_mkobject_hook, styp_to_sec_flags, coff_set_alignment_hook,
5637
  coff_slurp_symbol_table, symname_in_debug_hook, coff_pointerize_aux_hook,
5638
  coff_print_aux, coff_reloc16_extra_cases, coff_reloc16_estimate,
5639
  coff_classify_symbol, coff_compute_section_file_positions,
5640
  coff_start_final_link, coff_relocate_section, coff_rtype_to_howto,
5641
  coff_adjust_symndx, coff_link_add_one_symbol,
5642
  coff_link_output_has_begun, coff_final_link_postscript,
5643
  bfd_pe_print_pdata
5644
};
5645
#endif
5646
5647
#ifdef TICOFF
5648
/* COFF1 differs in section header size.  */
5649
5650
static const bfd_coff_backend_data ticoff1_swap_table =
5651
{
5652
  coff_SWAP_aux_in, coff_SWAP_sym_in, coff_SWAP_lineno_in,
5653
  coff_SWAP_aux_out, coff_SWAP_sym_out,
5654
  coff_SWAP_lineno_out, coff_SWAP_reloc_out,
5655
  coff_SWAP_filehdr_out, coff_SWAP_aouthdr_out,
5656
  coff_SWAP_scnhdr_out,
5657
  FILHSZ, AOUTSZ, SCNHSZ_V01, SYMESZ, AUXESZ, RELSZ, LINESZ, FILNMLEN,
5658
#ifdef COFF_LONG_FILENAMES
5659
  true,
5660
#else
5661
  false,
5662
#endif
5663
  COFF_DEFAULT_LONG_SECTION_NAMES,
5664
  COFF_DEFAULT_SECTION_ALIGNMENT_POWER,
5665
#ifdef COFF_FORCE_SYMBOLS_IN_STRINGS
5666
  true,
5667
#else
5668
  false,
5669
#endif
5670
#ifdef COFF_DEBUG_STRING_WIDE_PREFIX
5671
  4,
5672
#else
5673
  2,
5674
#endif
5675
  32768,
5676
  coff_SWAP_filehdr_in, coff_SWAP_aouthdr_in, coff_SWAP_scnhdr_in,
5677
  coff_SWAP_reloc_in, ticoff1_bad_format_hook, coff_set_arch_mach_hook,
5678
  coff_mkobject_hook, styp_to_sec_flags, coff_set_alignment_hook,
5679
  coff_slurp_symbol_table, symname_in_debug_hook, coff_pointerize_aux_hook,
5680
  coff_print_aux, coff_reloc16_extra_cases, coff_reloc16_estimate,
5681
  coff_classify_symbol, coff_compute_section_file_positions,
5682
  coff_start_final_link, coff_relocate_section, coff_rtype_to_howto,
5683
  coff_adjust_symndx, coff_link_add_one_symbol,
5684
  coff_link_output_has_begun, coff_final_link_postscript,
5685
  bfd_pe_print_pdata  /* huh */
5686
};
5687
#endif
5688
5689
#ifdef COFF_WITH_PE_BIGOBJ
5690
/* The UID for bigobj files.  */
5691
5692
static const char header_bigobj_classid[16] =
5693
{
5694
  0xC7, 0xA1, 0xBA, 0xD1,
5695
  0xEE, 0xBA,
5696
  0xa9, 0x4b,
5697
  0xAF, 0x20,
5698
  0xFA, 0xF6, 0x6A, 0xA4, 0xDC, 0xB8
5699
};
5700
5701
/* Swap routines.  */
5702
5703
static void
5704
coff_bigobj_swap_filehdr_in (bfd * abfd, void * src, void * dst)
5705
9.46k
{
5706
9.46k
  struct external_ANON_OBJECT_HEADER_BIGOBJ *filehdr_src =
5707
9.46k
    (struct external_ANON_OBJECT_HEADER_BIGOBJ *) src;
5708
9.46k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
5709
5710
9.46k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->Machine);
5711
9.46k
  filehdr_dst->f_nscns  = H_GET_32 (abfd, filehdr_src->NumberOfSections);
5712
9.46k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->TimeDateStamp);
5713
9.46k
  filehdr_dst->f_symptr =
5714
9.46k
    GET_FILEHDR_SYMPTR (abfd, filehdr_src->PointerToSymbolTable);
5715
9.46k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->NumberOfSymbols);
5716
9.46k
  filehdr_dst->f_opthdr = 0;
5717
9.46k
  filehdr_dst->f_flags  = 0;
5718
5719
  /* Check other magic numbers.  */
5720
9.46k
  if (H_GET_16 (abfd, filehdr_src->Sig1) != IMAGE_FILE_MACHINE_UNKNOWN
5721
9.46k
      || H_GET_16 (abfd, filehdr_src->Sig2) != 0xffff
5722
9.46k
      || H_GET_16 (abfd, filehdr_src->Version) != 2
5723
9.46k
      || memcmp (filehdr_src->ClassID, header_bigobj_classid, 16) != 0)
5724
9.46k
    filehdr_dst->f_opthdr = 0xffff;
5725
5726
  /* Note that CLR metadata are ignored.  */
5727
9.46k
}
pe-x86_64.c:coff_bigobj_swap_filehdr_in
Line
Count
Source
5705
4.73k
{
5706
4.73k
  struct external_ANON_OBJECT_HEADER_BIGOBJ *filehdr_src =
5707
4.73k
    (struct external_ANON_OBJECT_HEADER_BIGOBJ *) src;
5708
4.73k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
5709
5710
4.73k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->Machine);
5711
4.73k
  filehdr_dst->f_nscns  = H_GET_32 (abfd, filehdr_src->NumberOfSections);
5712
4.73k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->TimeDateStamp);
5713
4.73k
  filehdr_dst->f_symptr =
5714
4.73k
    GET_FILEHDR_SYMPTR (abfd, filehdr_src->PointerToSymbolTable);
5715
4.73k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->NumberOfSymbols);
5716
4.73k
  filehdr_dst->f_opthdr = 0;
5717
4.73k
  filehdr_dst->f_flags  = 0;
5718
5719
  /* Check other magic numbers.  */
5720
4.73k
  if (H_GET_16 (abfd, filehdr_src->Sig1) != IMAGE_FILE_MACHINE_UNKNOWN
5721
4.73k
      || H_GET_16 (abfd, filehdr_src->Sig2) != 0xffff
5722
4.73k
      || H_GET_16 (abfd, filehdr_src->Version) != 2
5723
4.73k
      || memcmp (filehdr_src->ClassID, header_bigobj_classid, 16) != 0)
5724
4.73k
    filehdr_dst->f_opthdr = 0xffff;
5725
5726
  /* Note that CLR metadata are ignored.  */
5727
4.73k
}
pe-i386.c:coff_bigobj_swap_filehdr_in
Line
Count
Source
5705
4.73k
{
5706
4.73k
  struct external_ANON_OBJECT_HEADER_BIGOBJ *filehdr_src =
5707
4.73k
    (struct external_ANON_OBJECT_HEADER_BIGOBJ *) src;
5708
4.73k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
5709
5710
4.73k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->Machine);
5711
4.73k
  filehdr_dst->f_nscns  = H_GET_32 (abfd, filehdr_src->NumberOfSections);
5712
4.73k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->TimeDateStamp);
5713
4.73k
  filehdr_dst->f_symptr =
5714
4.73k
    GET_FILEHDR_SYMPTR (abfd, filehdr_src->PointerToSymbolTable);
5715
4.73k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->NumberOfSymbols);
5716
4.73k
  filehdr_dst->f_opthdr = 0;
5717
4.73k
  filehdr_dst->f_flags  = 0;
5718
5719
  /* Check other magic numbers.  */
5720
4.73k
  if (H_GET_16 (abfd, filehdr_src->Sig1) != IMAGE_FILE_MACHINE_UNKNOWN
5721
4.73k
      || H_GET_16 (abfd, filehdr_src->Sig2) != 0xffff
5722
4.73k
      || H_GET_16 (abfd, filehdr_src->Version) != 2
5723
4.73k
      || memcmp (filehdr_src->ClassID, header_bigobj_classid, 16) != 0)
5724
4.73k
    filehdr_dst->f_opthdr = 0xffff;
5725
5726
  /* Note that CLR metadata are ignored.  */
5727
4.73k
}
5728
5729
static unsigned int
5730
coff_bigobj_swap_filehdr_out (bfd *abfd, void * in, void * out)
5731
0
{
5732
0
  struct internal_filehdr *filehdr_in = (struct internal_filehdr *) in;
5733
0
  struct external_ANON_OBJECT_HEADER_BIGOBJ *filehdr_out =
5734
0
    (struct external_ANON_OBJECT_HEADER_BIGOBJ *) out;
5735
5736
0
  memset (filehdr_out, 0, sizeof (*filehdr_out));
5737
5738
0
  H_PUT_16 (abfd, IMAGE_FILE_MACHINE_UNKNOWN, filehdr_out->Sig1);
5739
0
  H_PUT_16 (abfd, 0xffff, filehdr_out->Sig2);
5740
0
  H_PUT_16 (abfd, 2, filehdr_out->Version);
5741
0
  memcpy (filehdr_out->ClassID, header_bigobj_classid, 16);
5742
0
  H_PUT_16 (abfd, filehdr_in->f_magic, filehdr_out->Machine);
5743
0
  H_PUT_32 (abfd, filehdr_in->f_nscns, filehdr_out->NumberOfSections);
5744
0
  H_PUT_32 (abfd, filehdr_in->f_timdat, filehdr_out->TimeDateStamp);
5745
0
  PUT_FILEHDR_SYMPTR (abfd, filehdr_in->f_symptr,
5746
0
          filehdr_out->PointerToSymbolTable);
5747
0
  H_PUT_32 (abfd, filehdr_in->f_nsyms, filehdr_out->NumberOfSymbols);
5748
5749
0
  return bfd_coff_filhsz (abfd);
5750
0
}
Unexecuted instantiation: pe-x86_64.c:coff_bigobj_swap_filehdr_out
Unexecuted instantiation: pe-i386.c:coff_bigobj_swap_filehdr_out
5751
5752
static void
5753
coff_bigobj_swap_sym_in (bfd * abfd, void * ext1, void * in1)
5754
0
{
5755
0
  SYMENT_BIGOBJ *ext = (SYMENT_BIGOBJ *) ext1;
5756
0
  struct internal_syment *in = (struct internal_syment *) in1;
5757
5758
0
  if (ext->e.e_name[0] == 0)
5759
0
    {
5760
0
      in->_n._n_n._n_zeroes = 0;
5761
0
      in->_n._n_n._n_offset = H_GET_32 (abfd, ext->e.e.e_offset);
5762
0
    }
5763
0
  else
5764
0
    {
5765
#if SYMNMLEN != E_SYMNMLEN
5766
#error we need to cope with truncating or extending SYMNMLEN
5767
#else
5768
0
      memcpy (in->_n._n_name, ext->e.e_name, SYMNMLEN);
5769
0
#endif
5770
0
    }
5771
5772
0
  in->n_value = H_GET_32 (abfd, ext->e_value);
5773
0
  BFD_ASSERT (sizeof (in->n_scnum) >= 4);
5774
0
  in->n_scnum = H_GET_32 (abfd, ext->e_scnum);
5775
0
  in->n_type = H_GET_16 (abfd, ext->e_type);
5776
0
  in->n_sclass = H_GET_8 (abfd, ext->e_sclass);
5777
0
  in->n_numaux = H_GET_8 (abfd, ext->e_numaux);
5778
0
}
Unexecuted instantiation: pe-x86_64.c:coff_bigobj_swap_sym_in
Unexecuted instantiation: pe-i386.c:coff_bigobj_swap_sym_in
5779
5780
static unsigned int
5781
coff_bigobj_swap_sym_out (bfd * abfd, void * inp, void * extp)
5782
0
{
5783
0
  struct internal_syment *in = (struct internal_syment *) inp;
5784
0
  SYMENT_BIGOBJ *ext = (SYMENT_BIGOBJ *) extp;
5785
5786
0
  if (in->_n._n_name[0] == 0)
5787
0
    {
5788
0
      H_PUT_32 (abfd, 0, ext->e.e.e_zeroes);
5789
0
      H_PUT_32 (abfd, in->_n._n_n._n_offset, ext->e.e.e_offset);
5790
0
    }
5791
0
  else
5792
0
    {
5793
#if SYMNMLEN != E_SYMNMLEN
5794
#error we need to cope with truncating or extending SYMNMLEN
5795
#else
5796
0
      memcpy (ext->e.e_name, in->_n._n_name, SYMNMLEN);
5797
0
#endif
5798
0
    }
5799
5800
0
  H_PUT_32 (abfd, in->n_value, ext->e_value);
5801
0
  H_PUT_32 (abfd, in->n_scnum, ext->e_scnum);
5802
5803
0
  H_PUT_16 (abfd, in->n_type, ext->e_type);
5804
0
  H_PUT_8 (abfd, in->n_sclass, ext->e_sclass);
5805
0
  H_PUT_8 (abfd, in->n_numaux, ext->e_numaux);
5806
5807
0
  return SYMESZ_BIGOBJ;
5808
0
}
Unexecuted instantiation: pe-x86_64.c:coff_bigobj_swap_sym_out
Unexecuted instantiation: pe-i386.c:coff_bigobj_swap_sym_out
5809
5810
static void
5811
coff_bigobj_swap_aux_in (bfd *abfd,
5812
       void * ext1,
5813
       int type,
5814
       int in_class,
5815
       int indx,
5816
       int numaux,
5817
       void * in1)
5818
0
{
5819
0
  AUXENT_BIGOBJ *ext = (AUXENT_BIGOBJ *) ext1;
5820
0
  union internal_auxent *in = (union internal_auxent *) in1;
5821
5822
  /* Make sure that all fields in the aux structure are
5823
     initialised.  */
5824
0
  memset (in, 0, sizeof * in);
5825
0
  switch (in_class)
5826
0
    {
5827
0
    case C_FILE:
5828
0
      if (numaux > 1)
5829
0
  {
5830
0
    if (indx == 0)
5831
0
      memcpy (in->x_file.x_n.x_fname, ext->File.Name,
5832
0
        numaux * sizeof (AUXENT_BIGOBJ));
5833
0
  }
5834
0
      else
5835
0
  memcpy (in->x_file.x_n.x_fname, ext->File.Name, sizeof (ext->File.Name));
5836
0
      break;
5837
5838
0
    case C_STAT:
5839
0
    case C_LEAFSTAT:
5840
0
    case C_HIDDEN:
5841
0
      if (type == T_NULL)
5842
0
  {
5843
0
    in->x_scn.x_scnlen = H_GET_32 (abfd, ext->Section.Length);
5844
0
    in->x_scn.x_nreloc =
5845
0
      H_GET_16 (abfd, ext->Section.NumberOfRelocations);
5846
0
    in->x_scn.x_nlinno =
5847
0
      H_GET_16 (abfd, ext->Section.NumberOfLinenumbers);
5848
0
    in->x_scn.x_checksum = H_GET_32 (abfd, ext->Section.Checksum);
5849
0
    in->x_scn.x_associated = H_GET_16 (abfd, ext->Section.Number)
5850
0
      | (H_GET_16 (abfd, ext->Section.HighNumber) << 16);
5851
0
    in->x_scn.x_comdat = H_GET_8 (abfd, ext->Section.Selection);
5852
0
    return;
5853
0
  }
5854
0
      break;
5855
5856
0
    default:
5857
0
      in->x_sym.x_tagndx.u32 = H_GET_32 (abfd, ext->Sym.WeakDefaultSymIndex);
5858
      /* Characteristics is ignored.  */
5859
0
      break;
5860
0
    }
5861
0
}
Unexecuted instantiation: pe-x86_64.c:coff_bigobj_swap_aux_in
Unexecuted instantiation: pe-i386.c:coff_bigobj_swap_aux_in
5862
5863
static unsigned int
5864
coff_bigobj_swap_aux_out (bfd * abfd,
5865
        void * inp,
5866
        int type,
5867
        int in_class,
5868
        int indx ATTRIBUTE_UNUSED,
5869
        int numaux ATTRIBUTE_UNUSED,
5870
        void * extp)
5871
0
{
5872
0
  union internal_auxent * in = (union internal_auxent *) inp;
5873
0
  AUXENT_BIGOBJ *ext = (AUXENT_BIGOBJ *) extp;
5874
5875
0
  memset (ext, 0, AUXESZ);
5876
5877
0
  switch (in_class)
5878
0
    {
5879
0
    case C_FILE:
5880
0
      memcpy (ext->File.Name, in->x_file.x_n.x_fname, sizeof (ext->File.Name));
5881
5882
0
      return AUXESZ;
5883
5884
0
    case C_STAT:
5885
0
    case C_LEAFSTAT:
5886
0
    case C_HIDDEN:
5887
0
      if (type == T_NULL)
5888
0
  {
5889
0
    H_PUT_32 (abfd, in->x_scn.x_scnlen, ext->Section.Length);
5890
0
    H_PUT_16 (abfd, in->x_scn.x_nreloc,
5891
0
        ext->Section.NumberOfRelocations);
5892
0
    H_PUT_16 (abfd, in->x_scn.x_nlinno,
5893
0
        ext->Section.NumberOfLinenumbers);
5894
0
    H_PUT_32 (abfd, in->x_scn.x_checksum, ext->Section.Checksum);
5895
0
    H_PUT_16 (abfd, in->x_scn.x_associated & 0xffff,
5896
0
        ext->Section.Number);
5897
0
    H_PUT_16 (abfd, (in->x_scn.x_associated >> 16),
5898
0
        ext->Section.HighNumber);
5899
0
    H_PUT_8 (abfd, in->x_scn.x_comdat, ext->Section.Selection);
5900
0
    return AUXESZ;
5901
0
  }
5902
0
      break;
5903
0
    }
5904
5905
0
  H_PUT_32 (abfd, in->x_sym.x_tagndx.u32, ext->Sym.WeakDefaultSymIndex);
5906
0
  H_PUT_32 (abfd, 1, ext->Sym.WeakSearchType);
5907
5908
0
  return AUXESZ;
5909
0
}
Unexecuted instantiation: pe-x86_64.c:coff_bigobj_swap_aux_out
Unexecuted instantiation: pe-i386.c:coff_bigobj_swap_aux_out
5910
5911
static const bfd_coff_backend_data bigobj_swap_table =
5912
{
5913
  coff_bigobj_swap_aux_in, coff_bigobj_swap_sym_in, coff_SWAP_lineno_in,
5914
  coff_bigobj_swap_aux_out, coff_bigobj_swap_sym_out,
5915
  coff_SWAP_lineno_out, coff_SWAP_reloc_out,
5916
  coff_bigobj_swap_filehdr_out, coff_SWAP_aouthdr_out,
5917
  coff_SWAP_scnhdr_out,
5918
  FILHSZ_BIGOBJ, AOUTSZ, SCNHSZ, SYMESZ_BIGOBJ, AUXESZ_BIGOBJ,
5919
   RELSZ, LINESZ, FILNMLEN_BIGOBJ,
5920
  true,
5921
  COFF_DEFAULT_LONG_SECTION_NAMES,
5922
  COFF_DEFAULT_SECTION_ALIGNMENT_POWER,
5923
  false,
5924
  2,
5925
  1U << 31,
5926
  coff_bigobj_swap_filehdr_in, coff_SWAP_aouthdr_in, coff_SWAP_scnhdr_in,
5927
  coff_SWAP_reloc_in, coff_bad_format_hook, coff_set_arch_mach_hook,
5928
  coff_mkobject_hook, styp_to_sec_flags, coff_set_alignment_hook,
5929
  coff_slurp_symbol_table, symname_in_debug_hook, coff_pointerize_aux_hook,
5930
  coff_print_aux, coff_reloc16_extra_cases, coff_reloc16_estimate,
5931
  coff_classify_symbol, coff_compute_section_file_positions,
5932
  coff_start_final_link, coff_relocate_section, coff_rtype_to_howto,
5933
  coff_adjust_symndx, coff_link_add_one_symbol,
5934
  coff_link_output_has_begun, coff_final_link_postscript,
5935
  bfd_pe_print_pdata  /* huh */
5936
};
5937
5938
#endif /* COFF_WITH_PE_BIGOBJ */
5939
5940
#ifndef coff_close_and_cleanup
5941
#define coff_close_and_cleanup        _bfd_generic_close_and_cleanup
5942
#endif
5943
5944
#ifndef coff_bfd_free_cached_info
5945
#define coff_bfd_free_cached_info     _bfd_coff_free_cached_info
5946
#endif
5947
5948
#ifndef coff_get_section_contents
5949
#define coff_get_section_contents     _bfd_generic_get_section_contents
5950
#endif
5951
5952
#ifndef coff_bfd_copy_private_symbol_data
5953
#define coff_bfd_copy_private_symbol_data   _bfd_generic_bfd_copy_private_symbol_data
5954
#endif
5955
5956
#ifndef coff_bfd_copy_private_header_data
5957
#define coff_bfd_copy_private_header_data   _bfd_generic_bfd_copy_private_header_data
5958
#endif
5959
5960
#ifndef coff_bfd_copy_private_section_data
5961
#define coff_bfd_copy_private_section_data  _bfd_generic_bfd_copy_private_section_data
5962
#endif
5963
5964
#ifndef coff_bfd_copy_private_bfd_data
5965
#define coff_bfd_copy_private_bfd_data      _bfd_generic_bfd_copy_private_bfd_data
5966
#endif
5967
5968
#ifndef coff_bfd_merge_private_bfd_data
5969
#define coff_bfd_merge_private_bfd_data     _bfd_generic_bfd_merge_private_bfd_data
5970
#endif
5971
5972
#ifndef coff_bfd_set_private_flags
5973
#define coff_bfd_set_private_flags      _bfd_generic_bfd_set_private_flags
5974
#endif
5975
5976
#ifndef coff_bfd_print_private_bfd_data
5977
#define coff_bfd_print_private_bfd_data     _bfd_generic_bfd_print_private_bfd_data
5978
#endif
5979
5980
#ifndef coff_bfd_is_local_label_name
5981
#define coff_bfd_is_local_label_name      _bfd_coff_is_local_label_name
5982
#endif
5983
5984
#ifndef coff_bfd_is_target_special_symbol
5985
#define coff_bfd_is_target_special_symbol   _bfd_bool_bfd_asymbol_false
5986
#endif
5987
5988
#ifndef coff_read_minisymbols
5989
#define coff_read_minisymbols       _bfd_generic_read_minisymbols
5990
#endif
5991
5992
#ifndef coff_minisymbol_to_symbol
5993
#define coff_minisymbol_to_symbol     _bfd_generic_minisymbol_to_symbol
5994
#endif
5995
5996
/* The reloc lookup routine must be supplied by each individual COFF
5997
   backend.  */
5998
#ifndef coff_bfd_reloc_type_lookup
5999
#define coff_bfd_reloc_type_lookup      _bfd_norelocs_bfd_reloc_type_lookup
6000
#endif
6001
#ifndef coff_bfd_reloc_name_lookup
6002
#define coff_bfd_reloc_name_lookup    _bfd_norelocs_bfd_reloc_name_lookup
6003
#endif
6004
6005
#ifndef coff_bfd_get_relocated_section_contents
6006
#define coff_bfd_get_relocated_section_contents \
6007
  bfd_generic_get_relocated_section_contents
6008
#endif
6009
6010
#ifndef coff_bfd_relax_section
6011
#define coff_bfd_relax_section        bfd_generic_relax_section
6012
#endif
6013
6014
#ifndef coff_bfd_gc_sections
6015
#define coff_bfd_gc_sections        bfd_coff_gc_sections
6016
#endif
6017
6018
#ifndef coff_bfd_lookup_section_flags
6019
#define coff_bfd_lookup_section_flags     bfd_generic_lookup_section_flags
6020
#endif
6021
6022
#ifndef coff_bfd_merge_sections
6023
#define coff_bfd_merge_sections       bfd_generic_merge_sections
6024
#endif
6025
6026
#ifndef coff_bfd_is_group_section
6027
#define coff_bfd_is_group_section     bfd_generic_is_group_section
6028
#endif
6029
6030
#ifndef coff_bfd_group_name
6031
#define coff_bfd_group_name       bfd_coff_group_name
6032
#endif
6033
6034
#ifndef coff_bfd_discard_group
6035
#define coff_bfd_discard_group        bfd_generic_discard_group
6036
#endif
6037
6038
#ifndef coff_section_already_linked
6039
#define coff_section_already_linked \
6040
  _bfd_coff_section_already_linked
6041
#endif
6042
6043
#ifndef coff_bfd_define_common_symbol
6044
#define coff_bfd_define_common_symbol     bfd_generic_define_common_symbol
6045
#endif
6046
6047
#ifndef coff_bfd_link_hide_symbol
6048
#define coff_bfd_link_hide_symbol     _bfd_generic_link_hide_symbol
6049
#endif
6050
6051
#ifndef coff_bfd_define_start_stop
6052
#define coff_bfd_define_start_stop      bfd_generic_define_start_stop
6053
#endif
6054
6055
#define CREATE_BIG_COFF_TARGET_VEC(VAR, NAME, EXTRA_O_FLAGS, EXTRA_S_FLAGS, UNDER, ALTERNATIVE, SWAP_TABLE) \
6056
const bfd_target VAR =              \
6057
{                 \
6058
  NAME ,                \
6059
  bfd_target_coff_flavour,            \
6060
  BFD_ENDIAN_BIG,   /* Data byte order is big.  */    \
6061
  BFD_ENDIAN_BIG,   /* Header byte order is big.  */  \
6062
  /* object flags */              \
6063
  (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG |      \
6064
   HAS_SYMS | HAS_LOCALS | WP_TEXT | EXTRA_O_FLAGS),      \
6065
  /* section flags */             \
6066
  (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | EXTRA_S_FLAGS),\
6067
  UNDER,      /* Leading symbol underscore.  */ \
6068
  '/',        /* AR_pad_char.  */     \
6069
  15,       /* AR_max_namelen.  */      \
6070
  0,        /* match priority.  */      \
6071
  TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols.  */ \
6072
                  \
6073
  /* Data conversion functions.  */         \
6074
  bfd_getb64, bfd_getb_signed_64, bfd_putb64,       \
6075
  bfd_getb32, bfd_getb_signed_32, bfd_putb32,       \
6076
  bfd_getb16, bfd_getb_signed_16, bfd_putb16,       \
6077
                  \
6078
  /* Header conversion functions.  */         \
6079
  bfd_getb64, bfd_getb_signed_64, bfd_putb64,       \
6080
  bfd_getb32, bfd_getb_signed_32, bfd_putb32,       \
6081
  bfd_getb16, bfd_getb_signed_16, bfd_putb16,       \
6082
                  \
6083
  {       /* bfd_check_format.  */    \
6084
    _bfd_dummy_target,              \
6085
    coff_object_p,              \
6086
    bfd_generic_archive_p,            \
6087
    _bfd_dummy_target             \
6088
  },                  \
6089
  {       /* bfd_set_format.  */      \
6090
    _bfd_bool_bfd_false_error,            \
6091
    coff_mkobject,              \
6092
    _bfd_generic_mkarchive,           \
6093
    _bfd_bool_bfd_false_error           \
6094
  },                  \
6095
  {       /* bfd_write_contents.  */    \
6096
    _bfd_bool_bfd_false_error,            \
6097
    coff_write_object_contents,           \
6098
    _bfd_write_archive_contents,          \
6099
    _bfd_bool_bfd_false_error           \
6100
  },                  \
6101
                  \
6102
  BFD_JUMP_TABLE_GENERIC (coff),          \
6103
  BFD_JUMP_TABLE_COPY (coff),           \
6104
  BFD_JUMP_TABLE_CORE (_bfd_nocore),          \
6105
  BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),       \
6106
  BFD_JUMP_TABLE_SYMBOLS (coff),          \
6107
  BFD_JUMP_TABLE_RELOCS (coff),           \
6108
  BFD_JUMP_TABLE_WRITE (coff),            \
6109
  BFD_JUMP_TABLE_LINK (coff),           \
6110
  BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),        \
6111
                  \
6112
  ALTERNATIVE,                \
6113
                  \
6114
  SWAP_TABLE                \
6115
};
6116
6117
#define CREATE_BIGHDR_COFF_TARGET_VEC(VAR, NAME, EXTRA_O_FLAGS, EXTRA_S_FLAGS, UNDER, ALTERNATIVE, SWAP_TABLE)  \
6118
const bfd_target VAR =              \
6119
{                 \
6120
  NAME ,                \
6121
  bfd_target_coff_flavour,            \
6122
  BFD_ENDIAN_LITTLE,    /* Data byte order is little.  */ \
6123
  BFD_ENDIAN_BIG,   /* Header byte order is big.  */  \
6124
  /* object flags */              \
6125
  (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG |      \
6126
   HAS_SYMS | HAS_LOCALS | WP_TEXT | EXTRA_O_FLAGS),      \
6127
  /* section flags */             \
6128
  (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | EXTRA_S_FLAGS),\
6129
  UNDER,      /* Leading symbol underscore.  */ \
6130
  '/',        /* AR_pad_char.  */     \
6131
  15,       /* AR_max_namelen.  */      \
6132
  0,        /* match priority.  */      \
6133
  TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols.  */ \
6134
                  \
6135
  /* Data conversion functions.  */         \
6136
  bfd_getb64, bfd_getb_signed_64, bfd_putb64,       \
6137
  bfd_getb32, bfd_getb_signed_32, bfd_putb32,       \
6138
  bfd_getb16, bfd_getb_signed_16, bfd_putb16,       \
6139
                  \
6140
  /* Header conversion functions.  */         \
6141
  bfd_getb64, bfd_getb_signed_64, bfd_putb64,       \
6142
  bfd_getb32, bfd_getb_signed_32, bfd_putb32,       \
6143
  bfd_getb16, bfd_getb_signed_16, bfd_putb16,       \
6144
                  \
6145
  {       /* bfd_check_format.  */    \
6146
    _bfd_dummy_target,              \
6147
    coff_object_p,              \
6148
    bfd_generic_archive_p,            \
6149
    _bfd_dummy_target             \
6150
  },                  \
6151
  {       /* bfd_set_format.  */      \
6152
    _bfd_bool_bfd_false_error,            \
6153
    coff_mkobject,              \
6154
    _bfd_generic_mkarchive,           \
6155
    _bfd_bool_bfd_false_error           \
6156
  },                  \
6157
  {       /* bfd_write_contents.  */    \
6158
    _bfd_bool_bfd_false_error,            \
6159
    coff_write_object_contents,           \
6160
    _bfd_write_archive_contents,          \
6161
    _bfd_bool_bfd_false_error           \
6162
  },                  \
6163
                  \
6164
  BFD_JUMP_TABLE_GENERIC (coff),          \
6165
  BFD_JUMP_TABLE_COPY (coff),           \
6166
  BFD_JUMP_TABLE_CORE (_bfd_nocore),          \
6167
  BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),       \
6168
  BFD_JUMP_TABLE_SYMBOLS (coff),          \
6169
  BFD_JUMP_TABLE_RELOCS (coff),           \
6170
  BFD_JUMP_TABLE_WRITE (coff),            \
6171
  BFD_JUMP_TABLE_LINK (coff),           \
6172
  BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),        \
6173
                  \
6174
  ALTERNATIVE,                \
6175
                  \
6176
  SWAP_TABLE                \
6177
};
6178
6179
#define CREATE_LITTLE_COFF_TARGET_VEC(VAR, NAME, EXTRA_O_FLAGS, EXTRA_S_FLAGS, UNDER, ALTERNATIVE, SWAP_TABLE)  \
6180
const bfd_target VAR =              \
6181
{                 \
6182
  NAME ,                \
6183
  bfd_target_coff_flavour,            \
6184
  BFD_ENDIAN_LITTLE,    /* Data byte order is little.  */ \
6185
  BFD_ENDIAN_LITTLE,    /* Header byte order is little.  */ \
6186
  /* object flags */            \
6187
  (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG |      \
6188
   HAS_SYMS | HAS_LOCALS | WP_TEXT | EXTRA_O_FLAGS),      \
6189
  /* section flags */           \
6190
  (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | EXTRA_S_FLAGS),\
6191
  UNDER,      /* Leading symbol underscore.  */ \
6192
  '/',        /* AR_pad_char.  */     \
6193
  15,       /* AR_max_namelen.  */      \
6194
  0,        /* match priority.  */      \
6195
  TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols.  */ \
6196
                  \
6197
  /* Data conversion functions.  */         \
6198
  bfd_getl64, bfd_getl_signed_64, bfd_putl64,       \
6199
  bfd_getl32, bfd_getl_signed_32, bfd_putl32,       \
6200
  bfd_getl16, bfd_getl_signed_16, bfd_putl16,       \
6201
  /* Header conversion functions.  */         \
6202
  bfd_getl64, bfd_getl_signed_64, bfd_putl64,       \
6203
  bfd_getl32, bfd_getl_signed_32, bfd_putl32,       \
6204
  bfd_getl16, bfd_getl_signed_16, bfd_putl16,       \
6205
                  \
6206
  {       /* bfd_check_format.  */    \
6207
    _bfd_dummy_target,              \
6208
    coff_object_p,              \
6209
    bfd_generic_archive_p,            \
6210
    _bfd_dummy_target             \
6211
  },                  \
6212
  {       /* bfd_set_format.  */      \
6213
    _bfd_bool_bfd_false_error,            \
6214
    coff_mkobject,              \
6215
    _bfd_generic_mkarchive,           \
6216
    _bfd_bool_bfd_false_error           \
6217
  },                  \
6218
  {       /* bfd_write_contents.  */    \
6219
    _bfd_bool_bfd_false_error,            \
6220
    coff_write_object_contents,           \
6221
    _bfd_write_archive_contents,          \
6222
    _bfd_bool_bfd_false_error           \
6223
  },                  \
6224
                  \
6225
  BFD_JUMP_TABLE_GENERIC (coff),          \
6226
  BFD_JUMP_TABLE_COPY (coff),           \
6227
  BFD_JUMP_TABLE_CORE (_bfd_nocore),          \
6228
  BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),       \
6229
  BFD_JUMP_TABLE_SYMBOLS (coff),          \
6230
  BFD_JUMP_TABLE_RELOCS (coff),           \
6231
  BFD_JUMP_TABLE_WRITE (coff),            \
6232
  BFD_JUMP_TABLE_LINK (coff),           \
6233
  BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),        \
6234
                  \
6235
  ALTERNATIVE,                \
6236
                  \
6237
  SWAP_TABLE                \
6238
};