Coverage Report

Created: 2025-06-24 06:45

/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-2025 Free Software Foundation, Inc.
3
   Written by Cygnus Support.
4
5
   This file is part of BFD, the Binary File Descriptor library.
6
7
   This program is free software; you can redistribute it and/or modify
8
   it under the terms of the GNU General Public License as published by
9
   the Free Software Foundation; either version 3 of the License, or
10
   (at your option) any later version.
11
12
   This program is distributed in the hope that it will be useful,
13
   but WITHOUT ANY WARRANTY; without even the implied warranty of
14
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
   GNU General Public License for more details.
16
17
   You should have received a copy of the GNU General Public License
18
   along with this program; if not, write to the Free Software
19
   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20
   MA 02110-1301, USA.  */
21
22
/* 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
16
#define STRING_SIZE_SIZE 4
364
365
58.8M
#define DOT_DEBUG ".debug"
366
58.6M
#define DOT_ZDEBUG  ".zdebug"
367
7.95M
#define GNU_LINKONCE_WI ".gnu.linkonce.wi."
368
7.95M
#define GNU_LINKONCE_WT ".gnu.linkonce.wt."
369
183
#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
11.9M
{
411
11.9M
  bfd_coff_long_section_names (abfd) = enable;
412
11.9M
  return true;
413
11.9M
}
pei-i386.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
454k
{
411
454k
  bfd_coff_long_section_names (abfd) = enable;
412
454k
  return true;
413
454k
}
pe-x86_64.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
1.20M
{
411
1.20M
  bfd_coff_long_section_names (abfd) = enable;
412
1.20M
  return true;
413
1.20M
}
pei-x86_64.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
440k
{
411
440k
  bfd_coff_long_section_names (abfd) = enable;
412
440k
  return true;
413
440k
}
pe-aarch64.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
277k
{
411
277k
  bfd_coff_long_section_names (abfd) = enable;
412
277k
  return true;
413
277k
}
pei-aarch64.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
365k
{
411
365k
  bfd_coff_long_section_names (abfd) = enable;
412
365k
  return true;
413
365k
}
pei-ia64.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
311k
{
411
311k
  bfd_coff_long_section_names (abfd) = enable;
412
311k
  return true;
413
311k
}
pei-loongarch64.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
309k
{
411
309k
  bfd_coff_long_section_names (abfd) = enable;
412
309k
  return true;
413
309k
}
pei-riscv64.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
274k
{
411
274k
  bfd_coff_long_section_names (abfd) = enable;
412
274k
  return true;
413
274k
}
coff-go32.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
5.21M
{
411
5.21M
  bfd_coff_long_section_names (abfd) = enable;
412
5.21M
  return true;
413
5.21M
}
coff-stgo32.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
1.19M
{
411
1.19M
  bfd_coff_long_section_names (abfd) = enable;
412
1.19M
  return true;
413
1.19M
}
pe-arm-wince.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
87.3k
{
411
87.3k
  bfd_coff_long_section_names (abfd) = enable;
412
87.3k
  return true;
413
87.3k
}
pe-arm.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
87.3k
{
411
87.3k
  bfd_coff_long_section_names (abfd) = enable;
412
87.3k
  return true;
413
87.3k
}
pe-i386.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
207k
{
411
207k
  bfd_coff_long_section_names (abfd) = enable;
412
207k
  return true;
413
207k
}
pe-mcore.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
219k
{
411
219k
  bfd_coff_long_section_names (abfd) = enable;
412
219k
  return true;
413
219k
}
pe-sh.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
165k
{
411
165k
  bfd_coff_long_section_names (abfd) = enable;
412
165k
  return true;
413
165k
}
pei-arm-wince.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
271k
{
411
271k
  bfd_coff_long_section_names (abfd) = enable;
412
271k
  return true;
413
271k
}
pei-arm.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
337k
{
411
337k
  bfd_coff_long_section_names (abfd) = enable;
412
337k
  return true;
413
337k
}
pei-mcore.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
262k
{
411
262k
  bfd_coff_long_section_names (abfd) = enable;
412
262k
  return true;
413
262k
}
pei-sh.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
287k
{
411
287k
  bfd_coff_long_section_names (abfd) = enable;
412
287k
  return true;
413
287k
}
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
121M
{
419
121M
  return false;
420
121M
}
coff-x86_64.c:bfd_coff_set_long_section_names_disallowed
Line
Count
Source
418
19.0M
{
419
19.0M
  return false;
420
19.0M
}
coff64-rs6000.c:bfd_coff_set_long_section_names_disallowed
Line
Count
Source
418
3.50M
{
419
3.50M
  return false;
420
3.50M
}
cf-i386lynx.c:bfd_coff_set_long_section_names_disallowed
Line
Count
Source
418
7.80M
{
419
7.80M
  return false;
420
7.80M
}
coff-i386.c:bfd_coff_set_long_section_names_disallowed
Line
Count
Source
418
6.65M
{
419
6.65M
  return false;
420
6.65M
}
coff-rs6000.c:bfd_coff_set_long_section_names_disallowed
Line
Count
Source
418
28.2M
{
419
28.2M
  return false;
420
28.2M
}
coff-sh.c:bfd_coff_set_long_section_names_disallowed
Line
Count
Source
418
10.5M
{
419
10.5M
  return false;
420
10.5M
}
coff-tic30.c:bfd_coff_set_long_section_names_disallowed
Line
Count
Source
418
12.7M
{
419
12.7M
  return false;
420
12.7M
}
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
13.0M
{
419
13.0M
  return false;
420
13.0M
}
coff-z80.c:bfd_coff_set_long_section_names_disallowed
Line
Count
Source
418
1.94M
{
419
1.94M
  return false;
420
1.94M
}
coff-z8k.c:bfd_coff_set_long_section_names_disallowed
Line
Count
Source
418
18.1M
{
419
18.1M
  return false;
420
18.1M
}
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
2
#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
269
{
447
269
  long styp_flags = 0;
448
449
269
  if (!strcmp (sec_name, _TEXT))
450
0
    {
451
0
      styp_flags = STYP_TEXT;
452
0
    }
453
269
  else if (!strcmp (sec_name, _DATA))
454
0
    {
455
0
      styp_flags = STYP_DATA;
456
0
    }
457
269
  else if (!strcmp (sec_name, _BSS))
458
0
    {
459
0
      styp_flags = STYP_BSS;
460
#ifdef _COMMENT
461
    }
462
269
  else if (!strcmp (sec_name, _COMMENT))
463
0
    {
464
0
      styp_flags = STYP_INFO;
465
#endif /* _COMMENT */
466
#ifdef _LIB
467
    }
468
269
  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
269
  else if (startswith (sec_name, DOT_DEBUG)
480
269
     || 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
269
  else if (startswith (sec_name, ".stab"))
489
2
    {
490
2
      styp_flags = STYP_DEBUG_INFO;
491
2
    }
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
267
  else if (sec_flags & SEC_CODE)
538
2
    {
539
2
      styp_flags = STYP_TEXT;
540
2
    }
541
265
  else if (sec_flags & SEC_DATA)
542
0
    {
543
0
      styp_flags = STYP_DATA;
544
0
    }
545
265
  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
265
  else if (sec_flags & SEC_LOAD)
554
264
    {
555
264
      styp_flags = STYP_TEXT;
556
264
    }
557
1
  else if (sec_flags & SEC_ALLOC)
558
1
    {
559
1
      styp_flags = STYP_BSS;
560
1
    }
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
269
#ifdef STYP_NOLOAD
573
269
  if ((sec_flags & (SEC_NEVER_LOAD | SEC_COFF_SHARED_LIBRARY)) != 0)
574
1
    styp_flags |= STYP_NOLOAD;
575
269
#endif
576
577
269
  return styp_flags;
578
269
}
coff-x86_64.c:sec_to_styp_flags
Line
Count
Source
446
269
{
447
269
  long styp_flags = 0;
448
449
269
  if (!strcmp (sec_name, _TEXT))
450
0
    {
451
0
      styp_flags = STYP_TEXT;
452
0
    }
453
269
  else if (!strcmp (sec_name, _DATA))
454
0
    {
455
0
      styp_flags = STYP_DATA;
456
0
    }
457
269
  else if (!strcmp (sec_name, _BSS))
458
0
    {
459
0
      styp_flags = STYP_BSS;
460
0
#ifdef _COMMENT
461
0
    }
462
269
  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
269
  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
269
  else if (startswith (sec_name, DOT_DEBUG)
480
269
     || 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
269
  else if (startswith (sec_name, ".stab"))
489
2
    {
490
2
      styp_flags = STYP_DEBUG_INFO;
491
2
    }
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
267
  else if (sec_flags & SEC_CODE)
538
2
    {
539
2
      styp_flags = STYP_TEXT;
540
2
    }
541
265
  else if (sec_flags & SEC_DATA)
542
0
    {
543
0
      styp_flags = STYP_DATA;
544
0
    }
545
265
  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
265
  else if (sec_flags & SEC_LOAD)
554
264
    {
555
264
      styp_flags = STYP_TEXT;
556
264
    }
557
1
  else if (sec_flags & SEC_ALLOC)
558
1
    {
559
1
      styp_flags = STYP_BSS;
560
1
    }
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
269
#ifdef STYP_NOLOAD
573
269
  if ((sec_flags & (SEC_NEVER_LOAD | SEC_COFF_SHARED_LIBRARY)) != 0)
574
1
    styp_flags |= STYP_NOLOAD;
575
269
#endif
576
577
269
  return styp_flags;
578
269
}
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
Unexecuted instantiation: coff-z8k.c:sec_to_styp_flags
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
183
{
591
183
  long styp_flags = 0;
592
183
  bool is_dbg = false;
593
594
183
  if (startswith (sec_name, DOT_DEBUG)
595
183
      || startswith (sec_name, DOT_ZDEBUG)
596
183
#ifdef COFF_LONG_SECTION_NAMES
597
183
      || startswith (sec_name, GNU_LINKONCE_WI)
598
183
      || startswith (sec_name, GNU_LINKONCE_WT)
599
183
#endif
600
183
      || startswith (sec_name, ".stab"))
601
21
    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
183
  if (is_dbg)
613
21
    {
614
21
      sec_flags &= (SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD
615
21
        | SEC_LINK_DUPLICATES_SAME_CONTENTS
616
21
        | SEC_LINK_DUPLICATES_SAME_SIZE);
617
21
      sec_flags |= SEC_DEBUGGING | SEC_READONLY;
618
21
    }
619
620
  /* skip LOAD */
621
  /* READONLY later */
622
  /* skip RELOC */
623
183
  if ((sec_flags & SEC_CODE) != 0)
624
2
    styp_flags |= IMAGE_SCN_CNT_CODE;
625
183
  if ((sec_flags & (SEC_DATA | SEC_DEBUGGING)) != 0)
626
35
    styp_flags |= IMAGE_SCN_CNT_INITIALIZED_DATA;
627
183
  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
0
  if ((sec_flags & SEC_IS_COMMON) != 0)
637
0
    styp_flags |= IMAGE_SCN_LNK_COMDAT;
638
#endif
639
183
  if ((sec_flags & SEC_DEBUGGING) != 0)
640
21
    styp_flags |= IMAGE_SCN_MEM_DISCARDABLE;
641
183
  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
0
  if (sec_flags & SEC_LINK_ONCE)
651
0
    styp_flags |= IMAGE_SCN_LNK_COMDAT;
652
0
  if ((sec_flags
653
0
       & (SEC_LINK_DUPLICATES_DISCARD | SEC_LINK_DUPLICATES_SAME_CONTENTS
654
0
    | SEC_LINK_DUPLICATES_SAME_SIZE)) != 0)
655
0
    styp_flags |= IMAGE_SCN_LNK_COMDAT;
656
#endif
657
658
  /* skip LINKER_CREATED */
659
660
183
  if ((sec_flags & SEC_COFF_NOREAD) == 0)
661
37
    styp_flags |= IMAGE_SCN_MEM_READ;     /* Invert NOREAD for read.  */
662
183
  if ((sec_flags & SEC_READONLY) == 0)
663
5
    styp_flags |= IMAGE_SCN_MEM_WRITE;    /* Invert READONLY for write.  */
664
183
  if (sec_flags & SEC_CODE)
665
2
    styp_flags |= IMAGE_SCN_MEM_EXECUTE;  /* CODE->EXECUTE.  */
666
183
  if (sec_flags & SEC_COFF_SHARED)
667
0
    styp_flags |= IMAGE_SCN_MEM_SHARED;   /* Shared remains meaningful.  */
668
669
183
  return styp_flags;
670
183
}
pei-i386.c:sec_to_styp_flags
Line
Count
Source
590
3
{
591
3
  long styp_flags = 0;
592
3
  bool is_dbg = false;
593
594
3
  if (startswith (sec_name, DOT_DEBUG)
595
3
      || startswith (sec_name, DOT_ZDEBUG)
596
3
#ifdef COFF_LONG_SECTION_NAMES
597
3
      || startswith (sec_name, GNU_LINKONCE_WI)
598
3
      || startswith (sec_name, GNU_LINKONCE_WT)
599
3
#endif
600
3
      || 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
3
  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
3
  if ((sec_flags & SEC_CODE) != 0)
624
0
    styp_flags |= IMAGE_SCN_CNT_CODE;
625
3
  if ((sec_flags & (SEC_DATA | SEC_DEBUGGING)) != 0)
626
0
    styp_flags |= IMAGE_SCN_CNT_INITIALIZED_DATA;
627
3
  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
3
  if ((sec_flags & SEC_DEBUGGING) != 0)
640
0
    styp_flags |= IMAGE_SCN_MEM_DISCARDABLE;
641
3
  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
3
  if ((sec_flags & SEC_COFF_NOREAD) == 0)
661
0
    styp_flags |= IMAGE_SCN_MEM_READ;     /* Invert NOREAD for read.  */
662
3
  if ((sec_flags & SEC_READONLY) == 0)
663
0
    styp_flags |= IMAGE_SCN_MEM_WRITE;    /* Invert READONLY for write.  */
664
3
  if (sec_flags & SEC_CODE)
665
0
    styp_flags |= IMAGE_SCN_MEM_EXECUTE;  /* CODE->EXECUTE.  */
666
3
  if (sec_flags & SEC_COFF_SHARED)
667
0
    styp_flags |= IMAGE_SCN_MEM_SHARED;   /* Shared remains meaningful.  */
668
669
3
  return styp_flags;
670
3
}
Unexecuted instantiation: pe-x86_64.c:sec_to_styp_flags
pei-x86_64.c:sec_to_styp_flags
Line
Count
Source
590
29
{
591
29
  long styp_flags = 0;
592
29
  bool is_dbg = false;
593
594
29
  if (startswith (sec_name, DOT_DEBUG)
595
29
      || startswith (sec_name, DOT_ZDEBUG)
596
29
#ifdef COFF_LONG_SECTION_NAMES
597
29
      || startswith (sec_name, GNU_LINKONCE_WI)
598
29
      || startswith (sec_name, GNU_LINKONCE_WT)
599
29
#endif
600
29
      || startswith (sec_name, ".stab"))
601
13
    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
29
  if (is_dbg)
613
13
    {
614
13
      sec_flags &= (SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD
615
13
        | SEC_LINK_DUPLICATES_SAME_CONTENTS
616
13
        | SEC_LINK_DUPLICATES_SAME_SIZE);
617
13
      sec_flags |= SEC_DEBUGGING | SEC_READONLY;
618
13
    }
619
620
  /* skip LOAD */
621
  /* READONLY later */
622
  /* skip RELOC */
623
29
  if ((sec_flags & SEC_CODE) != 0)
624
2
    styp_flags |= IMAGE_SCN_CNT_CODE;
625
29
  if ((sec_flags & (SEC_DATA | SEC_DEBUGGING)) != 0)
626
27
    styp_flags |= IMAGE_SCN_CNT_INITIALIZED_DATA;
627
29
  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
29
  if ((sec_flags & SEC_DEBUGGING) != 0)
640
13
    styp_flags |= IMAGE_SCN_MEM_DISCARDABLE;
641
29
  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
29
  if ((sec_flags & SEC_COFF_NOREAD) == 0)
661
29
    styp_flags |= IMAGE_SCN_MEM_READ;     /* Invert NOREAD for read.  */
662
29
  if ((sec_flags & SEC_READONLY) == 0)
663
5
    styp_flags |= IMAGE_SCN_MEM_WRITE;    /* Invert READONLY for write.  */
664
29
  if (sec_flags & SEC_CODE)
665
2
    styp_flags |= IMAGE_SCN_MEM_EXECUTE;  /* CODE->EXECUTE.  */
666
29
  if (sec_flags & SEC_COFF_SHARED)
667
0
    styp_flags |= IMAGE_SCN_MEM_SHARED;   /* Shared remains meaningful.  */
668
669
29
  return styp_flags;
670
29
}
Unexecuted instantiation: pe-aarch64.c:sec_to_styp_flags
pei-aarch64.c:sec_to_styp_flags
Line
Count
Source
590
133
{
591
133
  long styp_flags = 0;
592
133
  bool is_dbg = false;
593
594
133
  if (startswith (sec_name, DOT_DEBUG)
595
133
      || startswith (sec_name, DOT_ZDEBUG)
596
133
#ifdef COFF_LONG_SECTION_NAMES
597
133
      || startswith (sec_name, GNU_LINKONCE_WI)
598
133
      || startswith (sec_name, GNU_LINKONCE_WT)
599
133
#endif
600
133
      || 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
133
  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
133
  if ((sec_flags & SEC_CODE) != 0)
624
0
    styp_flags |= IMAGE_SCN_CNT_CODE;
625
133
  if ((sec_flags & (SEC_DATA | SEC_DEBUGGING)) != 0)
626
2
    styp_flags |= IMAGE_SCN_CNT_INITIALIZED_DATA;
627
133
  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
133
  if ((sec_flags & SEC_DEBUGGING) != 0)
640
2
    styp_flags |= IMAGE_SCN_MEM_DISCARDABLE;
641
133
  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
133
  if ((sec_flags & SEC_COFF_NOREAD) == 0)
661
2
    styp_flags |= IMAGE_SCN_MEM_READ;     /* Invert NOREAD for read.  */
662
133
  if ((sec_flags & SEC_READONLY) == 0)
663
0
    styp_flags |= IMAGE_SCN_MEM_WRITE;    /* Invert READONLY for write.  */
664
133
  if (sec_flags & SEC_CODE)
665
0
    styp_flags |= IMAGE_SCN_MEM_EXECUTE;  /* CODE->EXECUTE.  */
666
133
  if (sec_flags & SEC_COFF_SHARED)
667
0
    styp_flags |= IMAGE_SCN_MEM_SHARED;   /* Shared remains meaningful.  */
668
669
133
  return styp_flags;
670
133
}
pei-ia64.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-loongarch64.c:sec_to_styp_flags
pei-riscv64.c:sec_to_styp_flags
Line
Count
Source
590
16
{
591
16
  long styp_flags = 0;
592
16
  bool is_dbg = false;
593
594
16
  if (startswith (sec_name, DOT_DEBUG)
595
16
      || startswith (sec_name, DOT_ZDEBUG)
596
16
#ifdef COFF_LONG_SECTION_NAMES
597
16
      || startswith (sec_name, GNU_LINKONCE_WI)
598
16
      || startswith (sec_name, GNU_LINKONCE_WT)
599
16
#endif
600
16
      || 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
16
  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
16
  if ((sec_flags & SEC_CODE) != 0)
624
0
    styp_flags |= IMAGE_SCN_CNT_CODE;
625
16
  if ((sec_flags & (SEC_DATA | SEC_DEBUGGING)) != 0)
626
4
    styp_flags |= IMAGE_SCN_CNT_INITIALIZED_DATA;
627
16
  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
16
  if ((sec_flags & SEC_DEBUGGING) != 0)
640
4
    styp_flags |= IMAGE_SCN_MEM_DISCARDABLE;
641
16
  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
16
  if ((sec_flags & SEC_COFF_NOREAD) == 0)
661
4
    styp_flags |= IMAGE_SCN_MEM_READ;     /* Invert NOREAD for read.  */
662
16
  if ((sec_flags & SEC_READONLY) == 0)
663
0
    styp_flags |= IMAGE_SCN_MEM_WRITE;    /* Invert READONLY for write.  */
664
16
  if (sec_flags & SEC_CODE)
665
0
    styp_flags |= IMAGE_SCN_MEM_EXECUTE;  /* CODE->EXECUTE.  */
666
16
  if (sec_flags & SEC_COFF_SHARED)
667
0
    styp_flags |= IMAGE_SCN_MEM_SHARED;   /* Shared remains meaningful.  */
668
669
16
  return styp_flags;
670
16
}
Unexecuted instantiation: pe-arm-wince.c:sec_to_styp_flags
Unexecuted instantiation: pe-arm.c:sec_to_styp_flags
Unexecuted instantiation: pe-i386.c:sec_to_styp_flags
Unexecuted instantiation: pe-mcore.c:sec_to_styp_flags
Unexecuted instantiation: pe-sh.c:sec_to_styp_flags
Unexecuted instantiation: pei-arm-wince.c:sec_to_styp_flags
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
128M
{
688
128M
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
689
128M
  unsigned long styp_flags = internal_s->s_flags;
690
128M
  flagword sec_flags = 0;
691
692
#ifdef STYP_BLOCK
693
13.0M
  if (styp_flags & STYP_BLOCK)
694
3.80M
    sec_flags |= SEC_TIC54X_BLOCK;
695
#endif
696
697
#ifdef STYP_CLINK
698
13.0M
  if (styp_flags & STYP_CLINK)
699
3.96M
    sec_flags |= SEC_TIC54X_CLINK;
700
#endif
701
702
128M
#ifdef STYP_NOLOAD
703
128M
  if (styp_flags & STYP_NOLOAD)
704
37.4M
    sec_flags |= SEC_NEVER_LOAD;
705
128M
#endif /* STYP_NOLOAD */
706
707
  /* For 386 COFF, at least, an unloadable text or data section is
708
     actually a shared library section.  */
709
128M
  if (styp_flags & STYP_TEXT)
710
46.0M
    {
711
46.0M
      if (sec_flags & SEC_NEVER_LOAD)
712
24.6M
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
713
21.4M
      else
714
21.4M
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
715
46.0M
    }
716
82.0M
  else if (styp_flags & STYP_DATA)
717
9.81M
    {
718
9.81M
      if (sec_flags & SEC_NEVER_LOAD)
719
5.31M
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
720
4.50M
      else
721
4.50M
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
722
9.81M
    }
723
72.2M
  else if (styp_flags & STYP_BSS)
724
4.40M
    {
725
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
726
1.54M
      if (sec_flags & SEC_NEVER_LOAD)
727
597k
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
728
952k
      else
729
952k
#endif
730
3.80M
  sec_flags |= SEC_ALLOC;
731
4.40M
    }
732
67.8M
  else if (styp_flags & STYP_INFO)
733
8.56M
    {
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
2.85M
      sec_flags |= SEC_DEBUGGING;
742
#endif
743
8.56M
    }
744
59.2M
  else if (styp_flags & STYP_PAD)
745
3.45M
    sec_flags = 0;
746
#ifdef RS6000COFF_C
747
13.6M
  else if (styp_flags & STYP_TDATA)
748
753k
    {
749
753k
      if (sec_flags & SEC_NEVER_LOAD)
750
71.8k
  sec_flags |= SEC_DATA | SEC_THREAD_LOCAL | SEC_COFF_SHARED_LIBRARY;
751
681k
      else
752
681k
  sec_flags |= SEC_DATA | SEC_THREAD_LOCAL | SEC_LOAD | SEC_ALLOC;
753
753k
    }
754
12.9M
  else if (styp_flags & STYP_TBSS)
755
332k
    {
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
332k
  sec_flags |= SEC_ALLOC | SEC_THREAD_LOCAL;
762
332k
    }
763
12.5M
  else if (styp_flags & STYP_EXCEPT)
764
609k
    sec_flags |= SEC_LOAD;
765
11.9M
  else if (styp_flags & STYP_LOADER)
766
181k
    sec_flags |= SEC_LOAD;
767
11.7M
  else if (styp_flags & STYP_TYPCHK)
768
82.7k
    sec_flags |= SEC_LOAD;
769
11.7M
  else if (styp_flags & STYP_DWARF)
770
118k
    sec_flags |= SEC_DEBUGGING;
771
11.5M
#endif
772
53.7M
  else if (strcmp (name, _TEXT) == 0)
773
117k
    {
774
117k
      if (sec_flags & SEC_NEVER_LOAD)
775
38.7k
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
776
78.8k
      else
777
78.8k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
778
117k
    }
779
53.6M
  else if (strcmp (name, _DATA) == 0)
780
163k
    {
781
163k
      if (sec_flags & SEC_NEVER_LOAD)
782
35.8k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
783
127k
      else
784
127k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
785
163k
    }
786
53.4M
  else if (strcmp (name, _BSS) == 0)
787
85.4k
    {
788
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
789
35.4k
      if (sec_flags & SEC_NEVER_LOAD)
790
10.9k
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
791
24.5k
      else
792
24.5k
#endif
793
74.5k
  sec_flags |= SEC_ALLOC;
794
85.4k
    }
795
53.3M
  else if (startswith (name, DOT_DEBUG)
796
53.3M
     || startswith (name, DOT_ZDEBUG)
797
#ifdef _COMMENT
798
36.3M
     || strcmp (name, _COMMENT) == 0
799
#endif
800
#ifdef COFF_LONG_SECTION_NAMES
801
2.58M
     || startswith (name, GNU_LINKONCE_WI)
802
2.58M
     || startswith (name, GNU_LINKONCE_WT)
803
#endif
804
53.3M
     || startswith (name, ".stab"))
805
363k
    {
806
#ifdef COFF_PAGE_SIZE
807
130k
      sec_flags |= SEC_DEBUGGING;
808
#endif
809
363k
    }
810
#ifdef _LIB
811
36.2M
  else if (strcmp (name, _LIB) == 0)
812
28.4k
    ;
813
36.2M
#endif
814
#ifdef _LIT
815
  else if (strcmp (name, _LIT) == 0)
816
    sec_flags = SEC_LOAD | SEC_ALLOC | SEC_READONLY;
817
#endif
818
36.2M
  else
819
52.9M
    sec_flags |= SEC_ALLOC | SEC_LOAD;
820
821
128M
#ifdef STYP_LIT     /* A29k readonly text/data section type.  */
822
128M
  if ((styp_flags & STYP_LIT) == STYP_LIT)
823
13.5M
    sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
824
128M
#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
128M
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
832
128M
      && (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
6.36M
  if (startswith (name, ".gnu.linkonce"))
844
2.03k
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
845
#endif
846
847
128M
  if (flags_ptr == NULL)
848
0
    return false;
849
850
128M
  * flags_ptr = sec_flags;
851
128M
  return true;
852
128M
}
coff-x86_64.c:styp_to_sec_flags
Line
Count
Source
687
19.0M
{
688
19.0M
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
689
19.0M
  unsigned long styp_flags = internal_s->s_flags;
690
19.0M
  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
19.0M
#ifdef STYP_NOLOAD
703
19.0M
  if (styp_flags & STYP_NOLOAD)
704
5.63M
    sec_flags |= SEC_NEVER_LOAD;
705
19.0M
#endif /* STYP_NOLOAD */
706
707
  /* For 386 COFF, at least, an unloadable text or data section is
708
     actually a shared library section.  */
709
19.0M
  if (styp_flags & STYP_TEXT)
710
6.77M
    {
711
6.77M
      if (sec_flags & SEC_NEVER_LOAD)
712
3.64M
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
713
3.12M
      else
714
3.12M
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
715
6.77M
    }
716
12.2M
  else if (styp_flags & STYP_DATA)
717
1.48M
    {
718
1.48M
      if (sec_flags & SEC_NEVER_LOAD)
719
751k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
720
735k
      else
721
735k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
722
1.48M
    }
723
10.7M
  else if (styp_flags & STYP_BSS)
724
717k
    {
725
717k
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
726
717k
      if (sec_flags & SEC_NEVER_LOAD)
727
265k
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
728
452k
      else
729
452k
#endif
730
452k
  sec_flags |= SEC_ALLOC;
731
717k
    }
732
10.0M
  else if (styp_flags & STYP_INFO)
733
1.32M
    {
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
1.32M
#if defined (COFF_PAGE_SIZE) && !defined (COFF_ALIGN_IN_S_FLAGS)
741
1.32M
      sec_flags |= SEC_DEBUGGING;
742
1.32M
#endif
743
1.32M
    }
744
8.74M
  else if (styp_flags & STYP_PAD)
745
530k
    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
8.21M
  else if (strcmp (name, _TEXT) == 0)
773
13.6k
    {
774
13.6k
      if (sec_flags & SEC_NEVER_LOAD)
775
5.34k
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
776
8.31k
      else
777
8.31k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
778
13.6k
    }
779
8.20M
  else if (strcmp (name, _DATA) == 0)
780
20.3k
    {
781
20.3k
      if (sec_flags & SEC_NEVER_LOAD)
782
4.68k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
783
15.6k
      else
784
15.6k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
785
20.3k
    }
786
8.18M
  else if (strcmp (name, _BSS) == 0)
787
19.1k
    {
788
19.1k
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
789
19.1k
      if (sec_flags & SEC_NEVER_LOAD)
790
6.29k
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
791
12.8k
      else
792
12.8k
#endif
793
12.8k
  sec_flags |= SEC_ALLOC;
794
19.1k
    }
795
8.16M
  else if (startswith (name, DOT_DEBUG)
796
8.16M
     || startswith (name, DOT_ZDEBUG)
797
8.16M
#ifdef _COMMENT
798
8.16M
     || strcmp (name, _COMMENT) == 0
799
8.16M
#endif
800
#ifdef COFF_LONG_SECTION_NAMES
801
     || startswith (name, GNU_LINKONCE_WI)
802
     || startswith (name, GNU_LINKONCE_WT)
803
#endif
804
8.16M
     || startswith (name, ".stab"))
805
57.2k
    {
806
57.2k
#ifdef COFF_PAGE_SIZE
807
57.2k
      sec_flags |= SEC_DEBUGGING;
808
57.2k
#endif
809
57.2k
    }
810
8.10M
#ifdef _LIB
811
8.10M
  else if (strcmp (name, _LIB) == 0)
812
6.69k
    ;
813
8.09M
#endif
814
#ifdef _LIT
815
  else if (strcmp (name, _LIT) == 0)
816
    sec_flags = SEC_LOAD | SEC_ALLOC | SEC_READONLY;
817
#endif
818
8.09M
  else
819
8.09M
    sec_flags |= SEC_ALLOC | SEC_LOAD;
820
821
19.0M
#ifdef STYP_LIT     /* A29k readonly text/data section type.  */
822
19.0M
  if ((styp_flags & STYP_LIT) == STYP_LIT)
823
1.89M
    sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
824
19.0M
#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
19.0M
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
832
19.0M
      && (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
19.0M
  if (flags_ptr == NULL)
848
0
    return false;
849
850
19.0M
  * flags_ptr = sec_flags;
851
19.0M
  return true;
852
19.0M
}
coff64-rs6000.c:styp_to_sec_flags
Line
Count
Source
687
3.50M
{
688
3.50M
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
689
3.50M
  unsigned long styp_flags = internal_s->s_flags;
690
3.50M
  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
3.50M
#ifdef STYP_NOLOAD
703
3.50M
  if (styp_flags & STYP_NOLOAD)
704
1.05M
    sec_flags |= SEC_NEVER_LOAD;
705
3.50M
#endif /* STYP_NOLOAD */
706
707
  /* For 386 COFF, at least, an unloadable text or data section is
708
     actually a shared library section.  */
709
3.50M
  if (styp_flags & STYP_TEXT)
710
1.21M
    {
711
1.21M
      if (sec_flags & SEC_NEVER_LOAD)
712
678k
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
713
534k
      else
714
534k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
715
1.21M
    }
716
2.29M
  else if (styp_flags & STYP_DATA)
717
264k
    {
718
264k
      if (sec_flags & SEC_NEVER_LOAD)
719
153k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
720
110k
      else
721
110k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
722
264k
    }
723
2.02M
  else if (styp_flags & STYP_BSS)
724
123k
    {
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
123k
  sec_flags |= SEC_ALLOC;
731
123k
    }
732
1.90M
  else if (styp_flags & STYP_INFO)
733
235k
    {
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
235k
    }
744
1.66M
  else if (styp_flags & STYP_PAD)
745
104k
    sec_flags = 0;
746
1.56M
#ifdef RS6000COFF_C
747
1.56M
  else if (styp_flags & STYP_TDATA)
748
101k
    {
749
101k
      if (sec_flags & SEC_NEVER_LOAD)
750
12.0k
  sec_flags |= SEC_DATA | SEC_THREAD_LOCAL | SEC_COFF_SHARED_LIBRARY;
751
89.2k
      else
752
89.2k
  sec_flags |= SEC_DATA | SEC_THREAD_LOCAL | SEC_LOAD | SEC_ALLOC;
753
101k
    }
754
1.46M
  else if (styp_flags & STYP_TBSS)
755
47.6k
    {
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
47.6k
  sec_flags |= SEC_ALLOC | SEC_THREAD_LOCAL;
762
47.6k
    }
763
1.41M
  else if (styp_flags & STYP_EXCEPT)
764
86.2k
    sec_flags |= SEC_LOAD;
765
1.32M
  else if (styp_flags & STYP_LOADER)
766
29.5k
    sec_flags |= SEC_LOAD;
767
1.29M
  else if (styp_flags & STYP_TYPCHK)
768
13.2k
    sec_flags |= SEC_LOAD;
769
1.28M
  else if (styp_flags & STYP_DWARF)
770
15.1k
    sec_flags |= SEC_DEBUGGING;
771
1.27M
#endif
772
1.27M
  else if (strcmp (name, _TEXT) == 0)
773
6.38k
    {
774
6.38k
      if (sec_flags & SEC_NEVER_LOAD)
775
1.70k
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
776
4.68k
      else
777
4.68k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
778
6.38k
    }
779
1.26M
  else if (strcmp (name, _DATA) == 0)
780
9.14k
    {
781
9.14k
      if (sec_flags & SEC_NEVER_LOAD)
782
3.00k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
783
6.14k
      else
784
6.14k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
785
9.14k
    }
786
1.25M
  else if (strcmp (name, _BSS) == 0)
787
4.52k
    {
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.52k
  sec_flags |= SEC_ALLOC;
794
4.52k
    }
795
1.25M
  else if (startswith (name, DOT_DEBUG)
796
1.25M
     || 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
1.25M
     || startswith (name, ".stab"))
805
15.7k
    {
806
#ifdef COFF_PAGE_SIZE
807
      sec_flags |= SEC_DEBUGGING;
808
#endif
809
15.7k
    }
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
1.23M
  else
819
1.23M
    sec_flags |= SEC_ALLOC | SEC_LOAD;
820
821
3.50M
#ifdef STYP_LIT     /* A29k readonly text/data section type.  */
822
3.50M
  if ((styp_flags & STYP_LIT) == STYP_LIT)
823
394k
    sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
824
3.50M
#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
3.50M
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
832
3.50M
      && (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
3.50M
  if (flags_ptr == NULL)
848
0
    return false;
849
850
3.50M
  * flags_ptr = sec_flags;
851
3.50M
  return true;
852
3.50M
}
cf-i386lynx.c:styp_to_sec_flags
Line
Count
Source
687
7.80M
{
688
7.80M
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
689
7.80M
  unsigned long styp_flags = internal_s->s_flags;
690
7.80M
  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.80M
#ifdef STYP_NOLOAD
703
7.80M
  if (styp_flags & STYP_NOLOAD)
704
2.34M
    sec_flags |= SEC_NEVER_LOAD;
705
7.80M
#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.80M
  if (styp_flags & STYP_TEXT)
710
2.79M
    {
711
2.79M
      if (sec_flags & SEC_NEVER_LOAD)
712
1.47M
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
713
1.32M
      else
714
1.32M
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
715
2.79M
    }
716
5.00M
  else if (styp_flags & STYP_DATA)
717
689k
    {
718
689k
      if (sec_flags & SEC_NEVER_LOAD)
719
355k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
720
333k
      else
721
333k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
722
689k
    }
723
4.31M
  else if (styp_flags & STYP_BSS)
724
321k
    {
725
321k
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
726
321k
      if (sec_flags & SEC_NEVER_LOAD)
727
130k
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
728
191k
      else
729
191k
#endif
730
191k
  sec_flags |= SEC_ALLOC;
731
321k
    }
732
3.99M
  else if (styp_flags & STYP_INFO)
733
574k
    {
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
574k
#if defined (COFF_PAGE_SIZE) && !defined (COFF_ALIGN_IN_S_FLAGS)
741
574k
      sec_flags |= SEC_DEBUGGING;
742
574k
#endif
743
574k
    }
744
3.42M
  else if (styp_flags & STYP_PAD)
745
209k
    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.21M
  else if (strcmp (name, _TEXT) == 0)
773
6.00k
    {
774
6.00k
      if (sec_flags & SEC_NEVER_LOAD)
775
1.70k
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
776
4.29k
      else
777
4.29k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
778
6.00k
    }
779
3.20M
  else if (strcmp (name, _DATA) == 0)
780
10.8k
    {
781
10.8k
      if (sec_flags & SEC_NEVER_LOAD)
782
2.28k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
783
8.61k
      else
784
8.61k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
785
10.8k
    }
786
3.19M
  else if (strcmp (name, _BSS) == 0)
787
5.87k
    {
788
5.87k
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
789
5.87k
      if (sec_flags & SEC_NEVER_LOAD)
790
1.66k
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
791
4.20k
      else
792
4.20k
#endif
793
4.20k
  sec_flags |= SEC_ALLOC;
794
5.87k
    }
795
3.19M
  else if (startswith (name, DOT_DEBUG)
796
3.19M
     || startswith (name, DOT_ZDEBUG)
797
3.19M
#ifdef _COMMENT
798
3.19M
     || strcmp (name, _COMMENT) == 0
799
3.19M
#endif
800
#ifdef COFF_LONG_SECTION_NAMES
801
     || startswith (name, GNU_LINKONCE_WI)
802
     || startswith (name, GNU_LINKONCE_WT)
803
#endif
804
3.19M
     || startswith (name, ".stab"))
805
26.2k
    {
806
26.2k
#ifdef COFF_PAGE_SIZE
807
26.2k
      sec_flags |= SEC_DEBUGGING;
808
26.2k
#endif
809
26.2k
    }
810
3.16M
#ifdef _LIB
811
3.16M
  else if (strcmp (name, _LIB) == 0)
812
2.45k
    ;
813
3.16M
#endif
814
#ifdef _LIT
815
  else if (strcmp (name, _LIT) == 0)
816
    sec_flags = SEC_LOAD | SEC_ALLOC | SEC_READONLY;
817
#endif
818
3.16M
  else
819
3.16M
    sec_flags |= SEC_ALLOC | SEC_LOAD;
820
821
7.80M
#ifdef STYP_LIT     /* A29k readonly text/data section type.  */
822
7.80M
  if ((styp_flags & STYP_LIT) == STYP_LIT)
823
852k
    sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
824
7.80M
#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.80M
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
832
7.80M
      && (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.80M
  if (flags_ptr == NULL)
848
0
    return false;
849
850
7.80M
  * flags_ptr = sec_flags;
851
7.80M
  return true;
852
7.80M
}
coff-go32.c:styp_to_sec_flags
Line
Count
Source
687
5.17M
{
688
5.17M
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
689
5.17M
  unsigned long styp_flags = internal_s->s_flags;
690
5.17M
  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
5.17M
#ifdef STYP_NOLOAD
703
5.17M
  if (styp_flags & STYP_NOLOAD)
704
1.45M
    sec_flags |= SEC_NEVER_LOAD;
705
5.17M
#endif /* STYP_NOLOAD */
706
707
  /* For 386 COFF, at least, an unloadable text or data section is
708
     actually a shared library section.  */
709
5.17M
  if (styp_flags & STYP_TEXT)
710
1.77M
    {
711
1.77M
      if (sec_flags & SEC_NEVER_LOAD)
712
939k
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
713
835k
      else
714
835k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
715
1.77M
    }
716
3.39M
  else if (styp_flags & STYP_DATA)
717
402k
    {
718
402k
      if (sec_flags & SEC_NEVER_LOAD)
719
208k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
720
194k
      else
721
194k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
722
402k
    }
723
2.99M
  else if (styp_flags & STYP_BSS)
724
187k
    {
725
187k
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
726
187k
      if (sec_flags & SEC_NEVER_LOAD)
727
70.3k
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
728
117k
      else
729
117k
#endif
730
117k
  sec_flags |= SEC_ALLOC;
731
187k
    }
732
2.80M
  else if (styp_flags & STYP_INFO)
733
373k
    {
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
373k
#if defined (COFF_PAGE_SIZE) && !defined (COFF_ALIGN_IN_S_FLAGS)
741
373k
      sec_flags |= SEC_DEBUGGING;
742
373k
#endif
743
373k
    }
744
2.43M
  else if (styp_flags & STYP_PAD)
745
144k
    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
2.29M
  else if (strcmp (name, _TEXT) == 0)
773
4.71k
    {
774
4.71k
      if (sec_flags & SEC_NEVER_LOAD)
775
1.44k
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
776
3.27k
      else
777
3.27k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
778
4.71k
    }
779
2.28M
  else if (strcmp (name, _DATA) == 0)
780
7.84k
    {
781
7.84k
      if (sec_flags & SEC_NEVER_LOAD)
782
1.94k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
783
5.89k
      else
784
5.89k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
785
7.84k
    }
786
2.27M
  else if (strcmp (name, _BSS) == 0)
787
4.58k
    {
788
4.58k
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
789
4.58k
      if (sec_flags & SEC_NEVER_LOAD)
790
1.28k
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
791
3.30k
      else
792
3.30k
#endif
793
3.30k
  sec_flags |= SEC_ALLOC;
794
4.58k
    }
795
2.27M
  else if (startswith (name, DOT_DEBUG)
796
2.27M
     || startswith (name, DOT_ZDEBUG)
797
2.27M
#ifdef _COMMENT
798
2.27M
     || strcmp (name, _COMMENT) == 0
799
2.27M
#endif
800
2.27M
#ifdef COFF_LONG_SECTION_NAMES
801
2.27M
     || startswith (name, GNU_LINKONCE_WI)
802
2.27M
     || startswith (name, GNU_LINKONCE_WT)
803
2.27M
#endif
804
2.27M
     || startswith (name, ".stab"))
805
20.3k
    {
806
20.3k
#ifdef COFF_PAGE_SIZE
807
20.3k
      sec_flags |= SEC_DEBUGGING;
808
20.3k
#endif
809
20.3k
    }
810
2.25M
#ifdef _LIB
811
2.25M
  else if (strcmp (name, _LIB) == 0)
812
2.13k
    ;
813
2.25M
#endif
814
#ifdef _LIT
815
  else if (strcmp (name, _LIT) == 0)
816
    sec_flags = SEC_LOAD | SEC_ALLOC | SEC_READONLY;
817
#endif
818
2.25M
  else
819
2.25M
    sec_flags |= SEC_ALLOC | SEC_LOAD;
820
821
5.17M
#ifdef STYP_LIT     /* A29k readonly text/data section type.  */
822
5.17M
  if ((styp_flags & STYP_LIT) == STYP_LIT)
823
503k
    sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
824
5.17M
#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
5.17M
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
832
5.17M
      && (startswith (name, ".sbss")
833
0
    || startswith (name, ".sdata")))
834
0
    sec_flags |= SEC_SMALL_DATA;
835
836
5.17M
#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
5.17M
  if (startswith (name, ".gnu.linkonce"))
844
1.84k
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
845
5.17M
#endif
846
847
5.17M
  if (flags_ptr == NULL)
848
0
    return false;
849
850
5.17M
  * flags_ptr = sec_flags;
851
5.17M
  return true;
852
5.17M
}
coff-i386.c:styp_to_sec_flags
Line
Count
Source
687
6.65M
{
688
6.65M
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
689
6.65M
  unsigned long styp_flags = internal_s->s_flags;
690
6.65M
  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
6.65M
#ifdef STYP_NOLOAD
703
6.65M
  if (styp_flags & STYP_NOLOAD)
704
1.91M
    sec_flags |= SEC_NEVER_LOAD;
705
6.65M
#endif /* STYP_NOLOAD */
706
707
  /* For 386 COFF, at least, an unloadable text or data section is
708
     actually a shared library section.  */
709
6.65M
  if (styp_flags & STYP_TEXT)
710
2.33M
    {
711
2.33M
      if (sec_flags & SEC_NEVER_LOAD)
712
1.23M
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
713
1.09M
      else
714
1.09M
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
715
2.33M
    }
716
4.31M
  else if (styp_flags & STYP_DATA)
717
521k
    {
718
521k
      if (sec_flags & SEC_NEVER_LOAD)
719
273k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
720
248k
      else
721
248k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
722
521k
    }
723
3.79M
  else if (styp_flags & STYP_BSS)
724
236k
    {
725
236k
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
726
236k
      if (sec_flags & SEC_NEVER_LOAD)
727
92.5k
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
728
143k
      else
729
143k
#endif
730
143k
  sec_flags |= SEC_ALLOC;
731
236k
    }
732
3.55M
  else if (styp_flags & STYP_INFO)
733
487k
    {
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
487k
#if defined (COFF_PAGE_SIZE) && !defined (COFF_ALIGN_IN_S_FLAGS)
741
487k
      sec_flags |= SEC_DEBUGGING;
742
487k
#endif
743
487k
    }
744
3.07M
  else if (styp_flags & STYP_PAD)
745
175k
    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
2.89M
  else if (strcmp (name, _TEXT) == 0)
773
5.08k
    {
774
5.08k
      if (sec_flags & SEC_NEVER_LOAD)
775
1.57k
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
776
3.51k
      else
777
3.51k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
778
5.08k
    }
779
2.89M
  else if (strcmp (name, _DATA) == 0)
780
9.49k
    {
781
9.49k
      if (sec_flags & SEC_NEVER_LOAD)
782
2.19k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
783
7.29k
      else
784
7.29k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
785
9.49k
    }
786
2.88M
  else if (strcmp (name, _BSS) == 0)
787
5.43k
    {
788
5.43k
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
789
5.43k
      if (sec_flags & SEC_NEVER_LOAD)
790
1.59k
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
791
3.83k
      else
792
3.83k
#endif
793
3.83k
  sec_flags |= SEC_ALLOC;
794
5.43k
    }
795
2.87M
  else if (startswith (name, DOT_DEBUG)
796
2.87M
     || startswith (name, DOT_ZDEBUG)
797
2.87M
#ifdef _COMMENT
798
2.87M
     || strcmp (name, _COMMENT) == 0
799
2.87M
#endif
800
#ifdef COFF_LONG_SECTION_NAMES
801
     || startswith (name, GNU_LINKONCE_WI)
802
     || startswith (name, GNU_LINKONCE_WT)
803
#endif
804
2.87M
     || startswith (name, ".stab"))
805
21.5k
    {
806
21.5k
#ifdef COFF_PAGE_SIZE
807
21.5k
      sec_flags |= SEC_DEBUGGING;
808
21.5k
#endif
809
21.5k
    }
810
2.85M
#ifdef _LIB
811
2.85M
  else if (strcmp (name, _LIB) == 0)
812
2.14k
    ;
813
2.85M
#endif
814
#ifdef _LIT
815
  else if (strcmp (name, _LIT) == 0)
816
    sec_flags = SEC_LOAD | SEC_ALLOC | SEC_READONLY;
817
#endif
818
2.85M
  else
819
2.85M
    sec_flags |= SEC_ALLOC | SEC_LOAD;
820
821
6.65M
#ifdef STYP_LIT     /* A29k readonly text/data section type.  */
822
6.65M
  if ((styp_flags & STYP_LIT) == STYP_LIT)
823
661k
    sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
824
6.65M
#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
6.65M
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
832
6.65M
      && (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
6.65M
  if (flags_ptr == NULL)
848
0
    return false;
849
850
6.65M
  * flags_ptr = sec_flags;
851
6.65M
  return true;
852
6.65M
}
coff-rs6000.c:styp_to_sec_flags
Line
Count
Source
687
28.2M
{
688
28.2M
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
689
28.2M
  unsigned long styp_flags = internal_s->s_flags;
690
28.2M
  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
28.2M
#ifdef STYP_NOLOAD
703
28.2M
  if (styp_flags & STYP_NOLOAD)
704
8.37M
    sec_flags |= SEC_NEVER_LOAD;
705
28.2M
#endif /* STYP_NOLOAD */
706
707
  /* For 386 COFF, at least, an unloadable text or data section is
708
     actually a shared library section.  */
709
28.2M
  if (styp_flags & STYP_TEXT)
710
10.3M
    {
711
10.3M
      if (sec_flags & SEC_NEVER_LOAD)
712
5.46M
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
713
4.87M
      else
714
4.87M
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
715
10.3M
    }
716
17.9M
  else if (styp_flags & STYP_DATA)
717
2.33M
    {
718
2.33M
      if (sec_flags & SEC_NEVER_LOAD)
719
1.28M
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
720
1.05M
      else
721
1.05M
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
722
2.33M
    }
723
15.6M
  else if (styp_flags & STYP_BSS)
724
1.13M
    {
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
1.13M
  sec_flags |= SEC_ALLOC;
731
1.13M
    }
732
14.4M
  else if (styp_flags & STYP_INFO)
733
1.74M
    {
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.74M
    }
744
12.7M
  else if (styp_flags & STYP_PAD)
745
638k
    sec_flags = 0;
746
12.1M
#ifdef RS6000COFF_C
747
12.1M
  else if (styp_flags & STYP_TDATA)
748
652k
    {
749
652k
      if (sec_flags & SEC_NEVER_LOAD)
750
59.8k
  sec_flags |= SEC_DATA | SEC_THREAD_LOCAL | SEC_COFF_SHARED_LIBRARY;
751
592k
      else
752
592k
  sec_flags |= SEC_DATA | SEC_THREAD_LOCAL | SEC_LOAD | SEC_ALLOC;
753
652k
    }
754
11.4M
  else if (styp_flags & STYP_TBSS)
755
284k
    {
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
284k
  sec_flags |= SEC_ALLOC | SEC_THREAD_LOCAL;
762
284k
    }
763
11.1M
  else if (styp_flags & STYP_EXCEPT)
764
523k
    sec_flags |= SEC_LOAD;
765
10.6M
  else if (styp_flags & STYP_LOADER)
766
152k
    sec_flags |= SEC_LOAD;
767
10.4M
  else if (styp_flags & STYP_TYPCHK)
768
69.4k
    sec_flags |= SEC_LOAD;
769
10.4M
  else if (styp_flags & STYP_DWARF)
770
103k
    sec_flags |= SEC_DEBUGGING;
771
10.3M
#endif
772
10.3M
  else if (strcmp (name, _TEXT) == 0)
773
23.0k
    {
774
23.0k
      if (sec_flags & SEC_NEVER_LOAD)
775
7.52k
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
776
15.4k
      else
777
15.4k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
778
23.0k
    }
779
10.2M
  else if (strcmp (name, _DATA) == 0)
780
30.9k
    {
781
30.9k
      if (sec_flags & SEC_NEVER_LOAD)
782
5.18k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
783
25.7k
      else
784
25.7k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
785
30.9k
    }
786
10.2M
  else if (strcmp (name, _BSS) == 0)
787
13.6k
    {
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
13.6k
  sec_flags |= SEC_ALLOC;
794
13.6k
    }
795
10.2M
  else if (startswith (name, DOT_DEBUG)
796
10.2M
     || 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
10.2M
     || startswith (name, ".stab"))
805
36.3k
    {
806
#ifdef COFF_PAGE_SIZE
807
      sec_flags |= SEC_DEBUGGING;
808
#endif
809
36.3k
    }
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
10.2M
  else
819
10.2M
    sec_flags |= SEC_ALLOC | SEC_LOAD;
820
821
28.2M
#ifdef STYP_LIT     /* A29k readonly text/data section type.  */
822
28.2M
  if ((styp_flags & STYP_LIT) == STYP_LIT)
823
3.00M
    sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
824
28.2M
#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
28.2M
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
832
28.2M
      && (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
28.2M
  if (flags_ptr == NULL)
848
0
    return false;
849
850
28.2M
  * flags_ptr = sec_flags;
851
28.2M
  return true;
852
28.2M
}
coff-sh.c:styp_to_sec_flags
Line
Count
Source
687
10.5M
{
688
10.5M
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
689
10.5M
  unsigned long styp_flags = internal_s->s_flags;
690
10.5M
  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.5M
#ifdef STYP_NOLOAD
703
10.5M
  if (styp_flags & STYP_NOLOAD)
704
2.76M
    sec_flags |= SEC_NEVER_LOAD;
705
10.5M
#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.5M
  if (styp_flags & STYP_TEXT)
710
3.96M
    {
711
3.96M
      if (sec_flags & SEC_NEVER_LOAD)
712
1.80M
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
713
2.15M
      else
714
2.15M
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
715
3.96M
    }
716
6.61M
  else if (styp_flags & STYP_DATA)
717
661k
    {
718
661k
      if (sec_flags & SEC_NEVER_LOAD)
719
350k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
720
311k
      else
721
311k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
722
661k
    }
723
5.95M
  else if (styp_flags & STYP_BSS)
724
295k
    {
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
295k
  sec_flags |= SEC_ALLOC;
731
295k
    }
732
5.65M
  else if (styp_flags & STYP_INFO)
733
791k
    {
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
791k
    }
744
4.86M
  else if (styp_flags & STYP_PAD)
745
224k
    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.64M
  else if (strcmp (name, _TEXT) == 0)
773
12.1k
    {
774
12.1k
      if (sec_flags & SEC_NEVER_LOAD)
775
5.29k
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
776
6.84k
      else
777
6.84k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
778
12.1k
    }
779
4.62M
  else if (strcmp (name, _DATA) == 0)
780
8.32k
    {
781
8.32k
      if (sec_flags & SEC_NEVER_LOAD)
782
2.96k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
783
5.35k
      else
784
5.35k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
785
8.32k
    }
786
4.62M
  else if (strcmp (name, _BSS) == 0)
787
5.52k
    {
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
5.52k
  sec_flags |= SEC_ALLOC;
794
5.52k
    }
795
4.61M
  else if (startswith (name, DOT_DEBUG)
796
4.61M
     || startswith (name, DOT_ZDEBUG)
797
4.61M
#ifdef _COMMENT
798
4.61M
     || strcmp (name, _COMMENT) == 0
799
4.61M
#endif
800
#ifdef COFF_LONG_SECTION_NAMES
801
     || startswith (name, GNU_LINKONCE_WI)
802
     || startswith (name, GNU_LINKONCE_WT)
803
#endif
804
4.61M
     || startswith (name, ".stab"))
805
31.3k
    {
806
#ifdef COFF_PAGE_SIZE
807
      sec_flags |= SEC_DEBUGGING;
808
#endif
809
31.3k
    }
810
4.58M
#ifdef _LIB
811
4.58M
  else if (strcmp (name, _LIB) == 0)
812
3.63k
    ;
813
4.58M
#endif
814
#ifdef _LIT
815
  else if (strcmp (name, _LIT) == 0)
816
    sec_flags = SEC_LOAD | SEC_ALLOC | SEC_READONLY;
817
#endif
818
4.58M
  else
819
4.58M
    sec_flags |= SEC_ALLOC | SEC_LOAD;
820
821
10.5M
#ifdef STYP_LIT     /* A29k readonly text/data section type.  */
822
10.5M
  if ((styp_flags & STYP_LIT) == STYP_LIT)
823
1.45M
    sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
824
10.5M
#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.5M
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
832
10.5M
      && (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.5M
  if (flags_ptr == NULL)
848
0
    return false;
849
850
10.5M
  * flags_ptr = sec_flags;
851
10.5M
  return true;
852
10.5M
}
coff-stgo32.c:styp_to_sec_flags
Line
Count
Source
687
1.18M
{
688
1.18M
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
689
1.18M
  unsigned long styp_flags = internal_s->s_flags;
690
1.18M
  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
1.18M
#ifdef STYP_NOLOAD
703
1.18M
  if (styp_flags & STYP_NOLOAD)
704
439k
    sec_flags |= SEC_NEVER_LOAD;
705
1.18M
#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.18M
  if (styp_flags & STYP_TEXT)
710
475k
    {
711
475k
      if (sec_flags & SEC_NEVER_LOAD)
712
241k
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
713
233k
      else
714
233k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
715
475k
    }
716
712k
  else if (styp_flags & STYP_DATA)
717
170k
    {
718
170k
      if (sec_flags & SEC_NEVER_LOAD)
719
83.8k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
720
86.5k
      else
721
86.5k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
722
170k
    }
723
542k
  else if (styp_flags & STYP_BSS)
724
86.7k
    {
725
86.7k
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
726
86.7k
      if (sec_flags & SEC_NEVER_LOAD)
727
38.2k
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
728
48.4k
      else
729
48.4k
#endif
730
48.4k
  sec_flags |= SEC_ALLOC;
731
86.7k
    }
732
455k
  else if (styp_flags & STYP_INFO)
733
89.6k
    {
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
89.6k
#if defined (COFF_PAGE_SIZE) && !defined (COFF_ALIGN_IN_S_FLAGS)
741
89.6k
      sec_flags |= SEC_DEBUGGING;
742
89.6k
#endif
743
89.6k
    }
744
366k
  else if (styp_flags & STYP_PAD)
745
34.5k
    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
331k
  else if (strcmp (name, _TEXT) == 0)
773
935
    {
774
935
      if (sec_flags & SEC_NEVER_LOAD)
775
136
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
776
799
      else
777
799
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
778
935
    }
779
330k
  else if (strcmp (name, _DATA) == 0)
780
1.43k
    {
781
1.43k
      if (sec_flags & SEC_NEVER_LOAD)
782
97
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
783
1.33k
      else
784
1.33k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
785
1.43k
    }
786
329k
  else if (strcmp (name, _BSS) == 0)
787
450
    {
788
450
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
789
450
      if (sec_flags & SEC_NEVER_LOAD)
790
75
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
791
375
      else
792
375
#endif
793
375
  sec_flags |= SEC_ALLOC;
794
450
    }
795
328k
  else if (startswith (name, DOT_DEBUG)
796
328k
     || startswith (name, DOT_ZDEBUG)
797
328k
#ifdef _COMMENT
798
328k
     || strcmp (name, _COMMENT) == 0
799
328k
#endif
800
328k
#ifdef COFF_LONG_SECTION_NAMES
801
328k
     || startswith (name, GNU_LINKONCE_WI)
802
328k
     || startswith (name, GNU_LINKONCE_WT)
803
328k
#endif
804
328k
     || startswith (name, ".stab"))
805
4.78k
    {
806
4.78k
#ifdef COFF_PAGE_SIZE
807
4.78k
      sec_flags |= SEC_DEBUGGING;
808
4.78k
#endif
809
4.78k
    }
810
323k
#ifdef _LIB
811
323k
  else if (strcmp (name, _LIB) == 0)
812
321
    ;
813
323k
#endif
814
#ifdef _LIT
815
  else if (strcmp (name, _LIT) == 0)
816
    sec_flags = SEC_LOAD | SEC_ALLOC | SEC_READONLY;
817
#endif
818
323k
  else
819
323k
    sec_flags |= SEC_ALLOC | SEC_LOAD;
820
821
1.18M
#ifdef STYP_LIT     /* A29k readonly text/data section type.  */
822
1.18M
  if ((styp_flags & STYP_LIT) == STYP_LIT)
823
195k
    sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
824
1.18M
#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.18M
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
832
1.18M
      && (startswith (name, ".sbss")
833
0
    || startswith (name, ".sdata")))
834
0
    sec_flags |= SEC_SMALL_DATA;
835
836
1.18M
#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
1.18M
  if (startswith (name, ".gnu.linkonce"))
844
192
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
845
1.18M
#endif
846
847
1.18M
  if (flags_ptr == NULL)
848
0
    return false;
849
850
1.18M
  * flags_ptr = sec_flags;
851
1.18M
  return true;
852
1.18M
}
coff-tic30.c:styp_to_sec_flags
Line
Count
Source
687
12.7M
{
688
12.7M
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
689
12.7M
  unsigned long styp_flags = internal_s->s_flags;
690
12.7M
  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
12.7M
#ifdef STYP_NOLOAD
703
12.7M
  if (styp_flags & STYP_NOLOAD)
704
3.00M
    sec_flags |= SEC_NEVER_LOAD;
705
12.7M
#endif /* STYP_NOLOAD */
706
707
  /* For 386 COFF, at least, an unloadable text or data section is
708
     actually a shared library section.  */
709
12.7M
  if (styp_flags & STYP_TEXT)
710
3.66M
    {
711
3.66M
      if (sec_flags & SEC_NEVER_LOAD)
712
2.22M
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
713
1.44M
      else
714
1.44M
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
715
3.66M
    }
716
9.09M
  else if (styp_flags & STYP_DATA)
717
594k
    {
718
594k
      if (sec_flags & SEC_NEVER_LOAD)
719
281k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
720
313k
      else
721
313k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
722
594k
    }
723
8.49M
  else if (styp_flags & STYP_BSS)
724
286k
    {
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
286k
  sec_flags |= SEC_ALLOC;
731
286k
    }
732
8.21M
  else if (styp_flags & STYP_INFO)
733
638k
    {
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
638k
    }
744
7.57M
  else if (styp_flags & STYP_PAD)
745
596k
    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
6.97M
  else if (strcmp (name, _TEXT) == 0)
773
13.7k
    {
774
13.7k
      if (sec_flags & SEC_NEVER_LOAD)
775
4.34k
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
776
9.35k
      else
777
9.35k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
778
13.7k
    }
779
6.96M
  else if (strcmp (name, _DATA) == 0)
780
15.6k
    {
781
15.6k
      if (sec_flags & SEC_NEVER_LOAD)
782
4.74k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
783
10.9k
      else
784
10.9k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
785
15.6k
    }
786
6.94M
  else if (strcmp (name, _BSS) == 0)
787
6.62k
    {
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
6.62k
  sec_flags |= SEC_ALLOC;
794
6.62k
    }
795
6.94M
  else if (startswith (name, DOT_DEBUG)
796
6.94M
     || startswith (name, DOT_ZDEBUG)
797
6.94M
#ifdef _COMMENT
798
6.94M
     || strcmp (name, _COMMENT) == 0
799
6.94M
#endif
800
#ifdef COFF_LONG_SECTION_NAMES
801
     || startswith (name, GNU_LINKONCE_WI)
802
     || startswith (name, GNU_LINKONCE_WT)
803
#endif
804
6.94M
     || startswith (name, ".stab"))
805
36.6k
    {
806
#ifdef COFF_PAGE_SIZE
807
      sec_flags |= SEC_DEBUGGING;
808
#endif
809
36.6k
    }
810
6.90M
#ifdef _LIB
811
6.90M
  else if (strcmp (name, _LIB) == 0)
812
4.53k
    ;
813
6.89M
#endif
814
#ifdef _LIT
815
  else if (strcmp (name, _LIT) == 0)
816
    sec_flags = SEC_LOAD | SEC_ALLOC | SEC_READONLY;
817
#endif
818
6.89M
  else
819
6.89M
    sec_flags |= SEC_ALLOC | SEC_LOAD;
820
821
12.7M
#ifdef STYP_LIT     /* A29k readonly text/data section type.  */
822
12.7M
  if ((styp_flags & STYP_LIT) == STYP_LIT)
823
861k
    sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
824
12.7M
#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
12.7M
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
832
12.7M
      && (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
12.7M
  if (flags_ptr == NULL)
848
0
    return false;
849
850
12.7M
  * flags_ptr = sec_flags;
851
12.7M
  return true;
852
12.7M
}
Unexecuted instantiation: coff-tic4x.c:styp_to_sec_flags
coff-tic54x.c:styp_to_sec_flags
Line
Count
Source
687
13.0M
{
688
13.0M
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
689
13.0M
  unsigned long styp_flags = internal_s->s_flags;
690
13.0M
  flagword sec_flags = 0;
691
692
13.0M
#ifdef STYP_BLOCK
693
13.0M
  if (styp_flags & STYP_BLOCK)
694
3.80M
    sec_flags |= SEC_TIC54X_BLOCK;
695
13.0M
#endif
696
697
13.0M
#ifdef STYP_CLINK
698
13.0M
  if (styp_flags & STYP_CLINK)
699
3.96M
    sec_flags |= SEC_TIC54X_CLINK;
700
13.0M
#endif
701
702
13.0M
#ifdef STYP_NOLOAD
703
13.0M
  if (styp_flags & STYP_NOLOAD)
704
3.90M
    sec_flags |= SEC_NEVER_LOAD;
705
13.0M
#endif /* STYP_NOLOAD */
706
707
  /* For 386 COFF, at least, an unloadable text or data section is
708
     actually a shared library section.  */
709
13.0M
  if (styp_flags & STYP_TEXT)
710
5.12M
    {
711
5.12M
      if (sec_flags & SEC_NEVER_LOAD)
712
2.64M
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
713
2.48M
      else
714
2.48M
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
715
5.12M
    }
716
7.89M
  else if (styp_flags & STYP_DATA)
717
985k
    {
718
985k
      if (sec_flags & SEC_NEVER_LOAD)
719
584k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
720
401k
      else
721
401k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
722
985k
    }
723
6.91M
  else if (styp_flags & STYP_BSS)
724
375k
    {
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
375k
  sec_flags |= SEC_ALLOC;
731
375k
    }
732
6.53M
  else if (styp_flags & STYP_INFO)
733
877k
    {
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
877k
    }
744
5.66M
  else if (styp_flags & STYP_PAD)
745
264k
    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.39M
  else if (strcmp (name, _TEXT) == 0)
773
15.0k
    {
774
15.0k
      if (sec_flags & SEC_NEVER_LOAD)
775
5.04k
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
776
10.0k
      else
777
10.0k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
778
15.0k
    }
779
5.38M
  else if (strcmp (name, _DATA) == 0)
780
23.2k
    {
781
23.2k
      if (sec_flags & SEC_NEVER_LOAD)
782
4.06k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
783
19.1k
      else
784
19.1k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
785
23.2k
    }
786
5.35M
  else if (strcmp (name, _BSS) == 0)
787
9.05k
    {
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
9.05k
  sec_flags |= SEC_ALLOC;
794
9.05k
    }
795
5.34M
  else if (startswith (name, DOT_DEBUG)
796
5.34M
     || 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
5.34M
     || startswith (name, ".stab"))
805
42.4k
    {
806
#ifdef COFF_PAGE_SIZE
807
      sec_flags |= SEC_DEBUGGING;
808
#endif
809
42.4k
    }
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
5.30M
  else
819
5.30M
    sec_flags |= SEC_ALLOC | SEC_LOAD;
820
821
13.0M
#ifdef STYP_LIT     /* A29k readonly text/data section type.  */
822
13.0M
  if ((styp_flags & STYP_LIT) == STYP_LIT)
823
1.36M
    sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
824
13.0M
#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
13.0M
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
832
13.0M
      && (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
13.0M
  if (flags_ptr == NULL)
848
0
    return false;
849
850
13.0M
  * flags_ptr = sec_flags;
851
13.0M
  return true;
852
13.0M
}
coff-z80.c:styp_to_sec_flags
Line
Count
Source
687
1.94M
{
688
1.94M
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
689
1.94M
  unsigned long styp_flags = internal_s->s_flags;
690
1.94M
  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
1.94M
#ifdef STYP_NOLOAD
703
1.94M
  if (styp_flags & STYP_NOLOAD)
704
611k
    sec_flags |= SEC_NEVER_LOAD;
705
1.94M
#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.94M
  if (styp_flags & STYP_TEXT)
710
677k
    {
711
677k
      if (sec_flags & SEC_NEVER_LOAD)
712
370k
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
713
307k
      else
714
307k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
715
677k
    }
716
1.26M
  else if (styp_flags & STYP_DATA)
717
179k
    {
718
179k
      if (sec_flags & SEC_NEVER_LOAD)
719
103k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
720
76.3k
      else
721
76.3k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
722
179k
    }
723
1.08M
  else if (styp_flags & STYP_BSS)
724
69.8k
    {
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
69.8k
  sec_flags |= SEC_ALLOC;
731
69.8k
    }
732
1.01M
  else if (styp_flags & STYP_INFO)
733
148k
    {
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
148k
    }
744
864k
  else if (styp_flags & STYP_PAD)
745
52.0k
    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
812k
  else if (strcmp (name, _TEXT) == 0)
773
4.71k
    {
774
4.71k
      if (sec_flags & SEC_NEVER_LOAD)
775
1.26k
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
776
3.45k
      else
777
3.45k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
778
4.71k
    }
779
807k
  else if (strcmp (name, _DATA) == 0)
780
5.74k
    {
781
5.74k
      if (sec_flags & SEC_NEVER_LOAD)
782
1.38k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
783
4.36k
      else
784
4.36k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
785
5.74k
    }
786
801k
  else if (strcmp (name, _BSS) == 0)
787
2.84k
    {
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
2.84k
  sec_flags |= SEC_ALLOC;
794
2.84k
    }
795
798k
  else if (startswith (name, DOT_DEBUG)
796
798k
     || startswith (name, DOT_ZDEBUG)
797
798k
#ifdef _COMMENT
798
798k
     || strcmp (name, _COMMENT) == 0
799
798k
#endif
800
#ifdef COFF_LONG_SECTION_NAMES
801
     || startswith (name, GNU_LINKONCE_WI)
802
     || startswith (name, GNU_LINKONCE_WT)
803
#endif
804
798k
     || startswith (name, ".stab"))
805
22.1k
    {
806
#ifdef COFF_PAGE_SIZE
807
      sec_flags |= SEC_DEBUGGING;
808
#endif
809
22.1k
    }
810
776k
#ifdef _LIB
811
776k
  else if (strcmp (name, _LIB) == 0)
812
1.75k
    ;
813
774k
#endif
814
#ifdef _LIT
815
  else if (strcmp (name, _LIT) == 0)
816
    sec_flags = SEC_LOAD | SEC_ALLOC | SEC_READONLY;
817
#endif
818
774k
  else
819
774k
    sec_flags |= SEC_ALLOC | SEC_LOAD;
820
821
1.94M
#ifdef STYP_LIT     /* A29k readonly text/data section type.  */
822
1.94M
  if ((styp_flags & STYP_LIT) == STYP_LIT)
823
201k
    sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
824
1.94M
#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.94M
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
832
1.94M
      && (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
1.94M
  if (flags_ptr == NULL)
848
0
    return false;
849
850
1.94M
  * flags_ptr = sec_flags;
851
1.94M
  return true;
852
1.94M
}
coff-z8k.c:styp_to_sec_flags
Line
Count
Source
687
18.1M
{
688
18.1M
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
689
18.1M
  unsigned long styp_flags = internal_s->s_flags;
690
18.1M
  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
18.1M
#ifdef STYP_NOLOAD
703
18.1M
  if (styp_flags & STYP_NOLOAD)
704
5.95M
    sec_flags |= SEC_NEVER_LOAD;
705
18.1M
#endif /* STYP_NOLOAD */
706
707
  /* For 386 COFF, at least, an unloadable text or data section is
708
     actually a shared library section.  */
709
18.1M
  if (styp_flags & STYP_TEXT)
710
6.93M
    {
711
6.93M
      if (sec_flags & SEC_NEVER_LOAD)
712
3.95M
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
713
2.98M
      else
714
2.98M
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
715
6.93M
    }
716
11.2M
  else if (styp_flags & STYP_DATA)
717
1.52M
    {
718
1.52M
      if (sec_flags & SEC_NEVER_LOAD)
719
883k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
720
639k
      else
721
639k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
722
1.52M
    }
723
9.69M
  else if (styp_flags & STYP_BSS)
724
567k
    {
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
567k
  sec_flags |= SEC_ALLOC;
731
567k
    }
732
9.12M
  else if (styp_flags & STYP_INFO)
733
1.27M
    {
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.27M
    }
744
7.84M
  else if (styp_flags & STYP_PAD)
745
482k
    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
7.36M
  else if (strcmp (name, _TEXT) == 0)
773
12.2k
    {
774
12.2k
      if (sec_flags & SEC_NEVER_LOAD)
775
3.40k
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
776
8.82k
      else
777
8.82k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
778
12.2k
    }
779
7.35M
  else if (strcmp (name, _DATA) == 0)
780
20.0k
    {
781
20.0k
      if (sec_flags & SEC_NEVER_LOAD)
782
3.25k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
783
16.8k
      else
784
16.8k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
785
20.0k
    }
786
7.33M
  else if (strcmp (name, _BSS) == 0)
787
7.79k
    {
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
7.79k
  sec_flags |= SEC_ALLOC;
794
7.79k
    }
795
7.32M
  else if (startswith (name, DOT_DEBUG)
796
7.32M
     || startswith (name, DOT_ZDEBUG)
797
7.32M
#ifdef _COMMENT
798
7.32M
     || strcmp (name, _COMMENT) == 0
799
7.32M
#endif
800
#ifdef COFF_LONG_SECTION_NAMES
801
     || startswith (name, GNU_LINKONCE_WI)
802
     || startswith (name, GNU_LINKONCE_WT)
803
#endif
804
7.32M
     || startswith (name, ".stab"))
805
48.8k
    {
806
#ifdef COFF_PAGE_SIZE
807
      sec_flags |= SEC_DEBUGGING;
808
#endif
809
48.8k
    }
810
7.27M
#ifdef _LIB
811
7.27M
  else if (strcmp (name, _LIB) == 0)
812
4.82k
    ;
813
7.27M
#endif
814
#ifdef _LIT
815
  else if (strcmp (name, _LIT) == 0)
816
    sec_flags = SEC_LOAD | SEC_ALLOC | SEC_READONLY;
817
#endif
818
7.27M
  else
819
7.27M
    sec_flags |= SEC_ALLOC | SEC_LOAD;
820
821
18.1M
#ifdef STYP_LIT     /* A29k readonly text/data section type.  */
822
18.1M
  if ((styp_flags & STYP_LIT) == STYP_LIT)
823
2.14M
    sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
824
18.1M
#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
18.1M
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
832
18.1M
      && (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
18.1M
  if (flags_ptr == NULL)
848
0
    return false;
849
850
18.1M
  * flags_ptr = sec_flags;
851
18.1M
  return true;
852
18.1M
}
853
854
#else /* COFF_WITH_PE */
855
856
static hashval_t
857
comdat_hashf (const void *entry)
858
22.3M
{
859
22.3M
  const struct comdat_hash_entry *fe = entry;
860
22.3M
  return fe->target_index;
861
22.3M
}
pei-i386.c:comdat_hashf
Line
Count
Source
858
1.16M
{
859
1.16M
  const struct comdat_hash_entry *fe = entry;
860
1.16M
  return fe->target_index;
861
1.16M
}
pe-x86_64.c:comdat_hashf
Line
Count
Source
858
6.51M
{
859
6.51M
  const struct comdat_hash_entry *fe = entry;
860
6.51M
  return fe->target_index;
861
6.51M
}
pei-x86_64.c:comdat_hashf
Line
Count
Source
858
3.09M
{
859
3.09M
  const struct comdat_hash_entry *fe = entry;
860
3.09M
  return fe->target_index;
861
3.09M
}
pe-aarch64.c:comdat_hashf
Line
Count
Source
858
318k
{
859
318k
  const struct comdat_hash_entry *fe = entry;
860
318k
  return fe->target_index;
861
318k
}
pei-aarch64.c:comdat_hashf
Line
Count
Source
858
2.03M
{
859
2.03M
  const struct comdat_hash_entry *fe = entry;
860
2.03M
  return fe->target_index;
861
2.03M
}
pei-ia64.c:comdat_hashf
Line
Count
Source
858
1.69M
{
859
1.69M
  const struct comdat_hash_entry *fe = entry;
860
1.69M
  return fe->target_index;
861
1.69M
}
pei-loongarch64.c:comdat_hashf
Line
Count
Source
858
605k
{
859
605k
  const struct comdat_hash_entry *fe = entry;
860
605k
  return fe->target_index;
861
605k
}
pei-riscv64.c:comdat_hashf
Line
Count
Source
858
1.13M
{
859
1.13M
  const struct comdat_hash_entry *fe = entry;
860
1.13M
  return fe->target_index;
861
1.13M
}
pe-arm-wince.c:comdat_hashf
Line
Count
Source
858
582k
{
859
582k
  const struct comdat_hash_entry *fe = entry;
860
582k
  return fe->target_index;
861
582k
}
pe-arm.c:comdat_hashf
Line
Count
Source
858
582k
{
859
582k
  const struct comdat_hash_entry *fe = entry;
860
582k
  return fe->target_index;
861
582k
}
pe-i386.c:comdat_hashf
Line
Count
Source
858
650k
{
859
650k
  const struct comdat_hash_entry *fe = entry;
860
650k
  return fe->target_index;
861
650k
}
pe-mcore.c:comdat_hashf
Line
Count
Source
858
231k
{
859
231k
  const struct comdat_hash_entry *fe = entry;
860
231k
  return fe->target_index;
861
231k
}
pe-sh.c:comdat_hashf
Line
Count
Source
858
1.01M
{
859
1.01M
  const struct comdat_hash_entry *fe = entry;
860
1.01M
  return fe->target_index;
861
1.01M
}
pei-arm-wince.c:comdat_hashf
Line
Count
Source
858
870k
{
859
870k
  const struct comdat_hash_entry *fe = entry;
860
870k
  return fe->target_index;
861
870k
}
pei-arm.c:comdat_hashf
Line
Count
Source
858
935k
{
859
935k
  const struct comdat_hash_entry *fe = entry;
860
935k
  return fe->target_index;
861
935k
}
pei-mcore.c:comdat_hashf
Line
Count
Source
858
369k
{
859
369k
  const struct comdat_hash_entry *fe = entry;
860
369k
  return fe->target_index;
861
369k
}
pei-sh.c:comdat_hashf
Line
Count
Source
858
536k
{
859
536k
  const struct comdat_hash_entry *fe = entry;
860
536k
  return fe->target_index;
861
536k
}
862
863
static int
864
comdat_eqf (const void *e1, const void *e2)
865
18.7M
{
866
18.7M
  const struct comdat_hash_entry *fe1 = e1;
867
18.7M
  const struct comdat_hash_entry *fe2 = e2;
868
18.7M
  return fe1->target_index == fe2->target_index;
869
18.7M
}
pei-i386.c:comdat_eqf
Line
Count
Source
865
913k
{
866
913k
  const struct comdat_hash_entry *fe1 = e1;
867
913k
  const struct comdat_hash_entry *fe2 = e2;
868
913k
  return fe1->target_index == fe2->target_index;
869
913k
}
pe-x86_64.c:comdat_eqf
Line
Count
Source
865
5.92M
{
866
5.92M
  const struct comdat_hash_entry *fe1 = e1;
867
5.92M
  const struct comdat_hash_entry *fe2 = e2;
868
5.92M
  return fe1->target_index == fe2->target_index;
869
5.92M
}
pei-x86_64.c:comdat_eqf
Line
Count
Source
865
3.09M
{
866
3.09M
  const struct comdat_hash_entry *fe1 = e1;
867
3.09M
  const struct comdat_hash_entry *fe2 = e2;
868
3.09M
  return fe1->target_index == fe2->target_index;
869
3.09M
}
pe-aarch64.c:comdat_eqf
Line
Count
Source
865
224k
{
866
224k
  const struct comdat_hash_entry *fe1 = e1;
867
224k
  const struct comdat_hash_entry *fe2 = e2;
868
224k
  return fe1->target_index == fe2->target_index;
869
224k
}
pei-aarch64.c:comdat_eqf
Line
Count
Source
865
1.55M
{
866
1.55M
  const struct comdat_hash_entry *fe1 = e1;
867
1.55M
  const struct comdat_hash_entry *fe2 = e2;
868
1.55M
  return fe1->target_index == fe2->target_index;
869
1.55M
}
pei-ia64.c:comdat_eqf
Line
Count
Source
865
1.28M
{
866
1.28M
  const struct comdat_hash_entry *fe1 = e1;
867
1.28M
  const struct comdat_hash_entry *fe2 = e2;
868
1.28M
  return fe1->target_index == fe2->target_index;
869
1.28M
}
pei-loongarch64.c:comdat_eqf
Line
Count
Source
865
426k
{
866
426k
  const struct comdat_hash_entry *fe1 = e1;
867
426k
  const struct comdat_hash_entry *fe2 = e2;
868
426k
  return fe1->target_index == fe2->target_index;
869
426k
}
pei-riscv64.c:comdat_eqf
Line
Count
Source
865
874k
{
866
874k
  const struct comdat_hash_entry *fe1 = e1;
867
874k
  const struct comdat_hash_entry *fe2 = e2;
868
874k
  return fe1->target_index == fe2->target_index;
869
874k
}
pe-arm-wince.c:comdat_eqf
Line
Count
Source
865
438k
{
866
438k
  const struct comdat_hash_entry *fe1 = e1;
867
438k
  const struct comdat_hash_entry *fe2 = e2;
868
438k
  return fe1->target_index == fe2->target_index;
869
438k
}
pe-arm.c:comdat_eqf
Line
Count
Source
865
438k
{
866
438k
  const struct comdat_hash_entry *fe1 = e1;
867
438k
  const struct comdat_hash_entry *fe2 = e2;
868
438k
  return fe1->target_index == fe2->target_index;
869
438k
}
pe-i386.c:comdat_eqf
Line
Count
Source
865
475k
{
866
475k
  const struct comdat_hash_entry *fe1 = e1;
867
475k
  const struct comdat_hash_entry *fe2 = e2;
868
475k
  return fe1->target_index == fe2->target_index;
869
475k
}
pe-mcore.c:comdat_eqf
Line
Count
Source
865
136k
{
866
136k
  const struct comdat_hash_entry *fe1 = e1;
867
136k
  const struct comdat_hash_entry *fe2 = e2;
868
136k
  return fe1->target_index == fe2->target_index;
869
136k
}
pe-sh.c:comdat_eqf
Line
Count
Source
865
959k
{
866
959k
  const struct comdat_hash_entry *fe1 = e1;
867
959k
  const struct comdat_hash_entry *fe2 = e2;
868
959k
  return fe1->target_index == fe2->target_index;
869
959k
}
pei-arm-wince.c:comdat_eqf
Line
Count
Source
865
635k
{
866
635k
  const struct comdat_hash_entry *fe1 = e1;
867
635k
  const struct comdat_hash_entry *fe2 = e2;
868
635k
  return fe1->target_index == fe2->target_index;
869
635k
}
pei-arm.c:comdat_eqf
Line
Count
Source
865
680k
{
866
680k
  const struct comdat_hash_entry *fe1 = e1;
867
680k
  const struct comdat_hash_entry *fe2 = e2;
868
680k
  return fe1->target_index == fe2->target_index;
869
680k
}
pei-mcore.c:comdat_eqf
Line
Count
Source
865
250k
{
866
250k
  const struct comdat_hash_entry *fe1 = e1;
867
250k
  const struct comdat_hash_entry *fe2 = e2;
868
250k
  return fe1->target_index == fe2->target_index;
869
250k
}
pei-sh.c:comdat_eqf
Line
Count
Source
865
387k
{
866
387k
  const struct comdat_hash_entry *fe1 = e1;
867
387k
  const struct comdat_hash_entry *fe2 = e2;
868
387k
  return fe1->target_index == fe2->target_index;
869
387k
}
870
871
static void
872
comdat_delf (void *ent)
873
4.18M
{
874
4.18M
  struct comdat_hash_entry *e = ent;
875
4.18M
  free (e->comdat_name);
876
4.18M
  free (e->symname);
877
4.18M
  free (e);
878
4.18M
}
pei-i386.c:comdat_delf
Line
Count
Source
873
299k
{
874
299k
  struct comdat_hash_entry *e = ent;
875
299k
  free (e->comdat_name);
876
299k
  free (e->symname);
877
299k
  free (e);
878
299k
}
pe-x86_64.c:comdat_delf
Line
Count
Source
873
658k
{
874
658k
  struct comdat_hash_entry *e = ent;
875
658k
  free (e->comdat_name);
876
658k
  free (e->symname);
877
658k
  free (e);
878
658k
}
pei-x86_64.c:comdat_delf
Line
Count
Source
873
424k
{
874
424k
  struct comdat_hash_entry *e = ent;
875
424k
  free (e->comdat_name);
876
424k
  free (e->symname);
877
424k
  free (e);
878
424k
}
pe-aarch64.c:comdat_delf
Line
Count
Source
873
74.1k
{
874
74.1k
  struct comdat_hash_entry *e = ent;
875
74.1k
  free (e->comdat_name);
876
74.1k
  free (e->symname);
877
74.1k
  free (e);
878
74.1k
}
pei-aarch64.c:comdat_delf
Line
Count
Source
873
427k
{
874
427k
  struct comdat_hash_entry *e = ent;
875
427k
  free (e->comdat_name);
876
427k
  free (e->symname);
877
427k
  free (e);
878
427k
}
pei-ia64.c:comdat_delf
Line
Count
Source
873
423k
{
874
423k
  struct comdat_hash_entry *e = ent;
875
423k
  free (e->comdat_name);
876
423k
  free (e->symname);
877
423k
  free (e);
878
423k
}
pei-loongarch64.c:comdat_delf
Line
Count
Source
873
185k
{
874
185k
  struct comdat_hash_entry *e = ent;
875
185k
  free (e->comdat_name);
876
185k
  free (e->symname);
877
185k
  free (e);
878
185k
}
pei-riscv64.c:comdat_delf
Line
Count
Source
873
280k
{
874
280k
  struct comdat_hash_entry *e = ent;
875
280k
  free (e->comdat_name);
876
280k
  free (e->symname);
877
280k
  free (e);
878
280k
}
pe-arm-wince.c:comdat_delf
Line
Count
Source
873
150k
{
874
150k
  struct comdat_hash_entry *e = ent;
875
150k
  free (e->comdat_name);
876
150k
  free (e->symname);
877
150k
  free (e);
878
150k
}
pe-arm.c:comdat_delf
Line
Count
Source
873
150k
{
874
150k
  struct comdat_hash_entry *e = ent;
875
150k
  free (e->comdat_name);
876
150k
  free (e->symname);
877
150k
  free (e);
878
150k
}
pe-i386.c:comdat_delf
Line
Count
Source
873
152k
{
874
152k
  struct comdat_hash_entry *e = ent;
875
152k
  free (e->comdat_name);
876
152k
  free (e->symname);
877
152k
  free (e);
878
152k
}
pe-mcore.c:comdat_delf
Line
Count
Source
873
68.6k
{
874
68.6k
  struct comdat_hash_entry *e = ent;
875
68.6k
  free (e->comdat_name);
876
68.6k
  free (e->symname);
877
68.6k
  free (e);
878
68.6k
}
pe-sh.c:comdat_delf
Line
Count
Source
873
166k
{
874
166k
  struct comdat_hash_entry *e = ent;
875
166k
  free (e->comdat_name);
876
166k
  free (e->symname);
877
166k
  free (e);
878
166k
}
pei-arm-wince.c:comdat_delf
Line
Count
Source
873
235k
{
874
235k
  struct comdat_hash_entry *e = ent;
875
235k
  free (e->comdat_name);
876
235k
  free (e->symname);
877
235k
  free (e);
878
235k
}
pei-arm.c:comdat_delf
Line
Count
Source
873
247k
{
874
247k
  struct comdat_hash_entry *e = ent;
875
247k
  free (e->comdat_name);
876
247k
  free (e->symname);
877
247k
  free (e);
878
247k
}
pei-mcore.c:comdat_delf
Line
Count
Source
873
105k
{
874
105k
  struct comdat_hash_entry *e = ent;
875
105k
  free (e->comdat_name);
876
105k
  free (e->symname);
877
105k
  free (e);
878
105k
}
pei-sh.c:comdat_delf
Line
Count
Source
873
137k
{
874
137k
  struct comdat_hash_entry *e = ent;
875
137k
  free (e->comdat_name);
876
137k
  free (e->symname);
877
137k
  free (e);
878
137k
}
879
880
static struct comdat_hash_entry *
881
find_flags (htab_t comdat_hash, int target_index)
882
1.35M
{
883
1.35M
  struct comdat_hash_entry needle;
884
1.35M
  needle.target_index = target_index;
885
886
1.35M
  return htab_find (comdat_hash, &needle);
887
1.35M
}
pei-i386.c:find_flags
Line
Count
Source
882
103k
{
883
103k
  struct comdat_hash_entry needle;
884
103k
  needle.target_index = target_index;
885
886
103k
  return htab_find (comdat_hash, &needle);
887
103k
}
pe-x86_64.c:find_flags
Line
Count
Source
882
168k
{
883
168k
  struct comdat_hash_entry needle;
884
168k
  needle.target_index = target_index;
885
886
168k
  return htab_find (comdat_hash, &needle);
887
168k
}
pei-x86_64.c:find_flags
Line
Count
Source
882
117k
{
883
117k
  struct comdat_hash_entry needle;
884
117k
  needle.target_index = target_index;
885
886
117k
  return htab_find (comdat_hash, &needle);
887
117k
}
pe-aarch64.c:find_flags
Line
Count
Source
882
47.8k
{
883
47.8k
  struct comdat_hash_entry needle;
884
47.8k
  needle.target_index = target_index;
885
886
47.8k
  return htab_find (comdat_hash, &needle);
887
47.8k
}
pei-aarch64.c:find_flags
Line
Count
Source
882
99.4k
{
883
99.4k
  struct comdat_hash_entry needle;
884
99.4k
  needle.target_index = target_index;
885
886
99.4k
  return htab_find (comdat_hash, &needle);
887
99.4k
}
pei-ia64.c:find_flags
Line
Count
Source
882
81.5k
{
883
81.5k
  struct comdat_hash_entry needle;
884
81.5k
  needle.target_index = target_index;
885
886
81.5k
  return htab_find (comdat_hash, &needle);
887
81.5k
}
pei-loongarch64.c:find_flags
Line
Count
Source
882
72.3k
{
883
72.3k
  struct comdat_hash_entry needle;
884
72.3k
  needle.target_index = target_index;
885
886
72.3k
  return htab_find (comdat_hash, &needle);
887
72.3k
}
pei-riscv64.c:find_flags
Line
Count
Source
882
67.2k
{
883
67.2k
  struct comdat_hash_entry needle;
884
67.2k
  needle.target_index = target_index;
885
886
67.2k
  return htab_find (comdat_hash, &needle);
887
67.2k
}
pe-arm-wince.c:find_flags
Line
Count
Source
882
35.2k
{
883
35.2k
  struct comdat_hash_entry needle;
884
35.2k
  needle.target_index = target_index;
885
886
35.2k
  return htab_find (comdat_hash, &needle);
887
35.2k
}
pe-arm.c:find_flags
Line
Count
Source
882
35.2k
{
883
35.2k
  struct comdat_hash_entry needle;
884
35.2k
  needle.target_index = target_index;
885
886
35.2k
  return htab_find (comdat_hash, &needle);
887
35.2k
}
pe-i386.c:find_flags
Line
Count
Source
882
63.3k
{
883
63.3k
  struct comdat_hash_entry needle;
884
63.3k
  needle.target_index = target_index;
885
886
63.3k
  return htab_find (comdat_hash, &needle);
887
63.3k
}
pe-mcore.c:find_flags
Line
Count
Source
882
58.5k
{
883
58.5k
  struct comdat_hash_entry needle;
884
58.5k
  needle.target_index = target_index;
885
886
58.5k
  return htab_find (comdat_hash, &needle);
887
58.5k
}
pe-sh.c:find_flags
Line
Count
Source
882
50.9k
{
883
50.9k
  struct comdat_hash_entry needle;
884
50.9k
  needle.target_index = target_index;
885
886
50.9k
  return htab_find (comdat_hash, &needle);
887
50.9k
}
pei-arm-wince.c:find_flags
Line
Count
Source
882
94.6k
{
883
94.6k
  struct comdat_hash_entry needle;
884
94.6k
  needle.target_index = target_index;
885
886
94.6k
  return htab_find (comdat_hash, &needle);
887
94.6k
}
pei-arm.c:find_flags
Line
Count
Source
882
106k
{
883
106k
  struct comdat_hash_entry needle;
884
106k
  needle.target_index = target_index;
885
886
106k
  return htab_find (comdat_hash, &needle);
887
106k
}
pei-mcore.c:find_flags
Line
Count
Source
882
71.7k
{
883
71.7k
  struct comdat_hash_entry needle;
884
71.7k
  needle.target_index = target_index;
885
886
71.7k
  return htab_find (comdat_hash, &needle);
887
71.7k
}
pei-sh.c:find_flags
Line
Count
Source
882
84.7k
{
883
84.7k
  struct comdat_hash_entry needle;
884
84.7k
  needle.target_index = target_index;
885
886
84.7k
  return htab_find (comdat_hash, &needle);
887
84.7k
}
888
889
static bool
890
fill_comdat_hash (bfd *abfd)
891
1.08M
{
892
1.08M
  bfd_byte *esymstart, *esym, *esymend;
893
894
  /* Unfortunately, the PE format stores essential information in the
895
     symbol table, of all places.  We need to extract that information
896
     now, so that objdump and the linker will know how to handle the
897
     section without worrying about the symbols.  We can't call
898
     slurp_symtab, because the linker doesn't want the swapped symbols.  */
899
900
  /* COMDAT sections are special.  The first symbol is the section
901
     symbol, which tells what kind of COMDAT section it is.  The
902
     second symbol is the "comdat symbol" - the one with the unique
903
     name.  GNU uses the section symbol for the unique name; MS uses
904
     ".text" for every comdat section.  Sigh.  - DJ.  */
905
906
  /* This is not mirrored in sec_to_styp_flags(), but there doesn't
907
     seem to be a need to, either, and it would at best be rather messy.  */
908
909
1.08M
  if (! _bfd_coff_get_external_symbols (abfd))
910
389k
    return true;
911
912
700k
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
913
700k
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
914
915
700k
  for (struct internal_syment isym;
916
24.6M
       esym < esymend;
917
23.9M
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
918
23.9M
    {
919
23.9M
      char buf[SYMNMLEN + 1];
920
23.9M
      const char *symname;
921
23.9M
      flagword sec_flags = SEC_LINK_ONCE;
922
923
23.9M
      bfd_coff_swap_sym_in (abfd, esym, &isym);
924
925
      /* According to the MSVC documentation, the first TWO entries
926
   with the section # are both of interest to us.  The first one
927
   is the "section symbol" (section name).  The second is the
928
   comdat symbol name.  Here, we've found the first qualifying
929
   entry; we distinguish it from the second with a state flag.
930
931
   In the case of gas-generated (at least until that is fixed)
932
   .o files, it isn't necessarily the second one.  It may be
933
   some other later symbol.
934
935
   Since gas also doesn't follow MS conventions and emits the
936
   section similar to .text$<name>, where <something> is the
937
   name we're looking for, we distinguish the two as follows:
938
939
   If the section name is simply a section name (no $) we
940
   presume it's MS-generated, and look at precisely the second
941
   symbol for the comdat name.  If the section name has a $, we
942
   assume it's gas-generated, and look for <something> (whatever
943
   follows the $) as the comdat symbol.  */
944
945
      /* All 3 branches use this.  */
946
23.9M
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
947
948
      /* PR 17512 file: 078-11867-0.004  */
949
23.9M
      if (symname == NULL)
950
6.00M
  {
951
6.00M
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
952
6.00M
            abfd);
953
6.00M
    continue;
954
6.00M
  }
955
956
17.9M
      union internal_auxent aux;
957
958
17.9M
      struct comdat_hash_entry needle;
959
17.9M
      needle.target_index = isym.n_scnum;
960
961
17.9M
      void **slot
962
17.9M
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
963
17.9M
      if (slot == NULL)
964
0
  return false;
965
966
17.9M
      if (*slot == NULL)
967
4.20M
  {
968
4.20M
    if (isym.n_numaux != 1)
969
3.63M
      aux.x_scn.x_comdat = 0;
970
570k
    else
971
570k
      {
972
        /* PR 17512: file: e2cfe54f.  */
973
570k
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
974
21.7k
    {
975
      /* xgettext:c-format */
976
21.7k
      _bfd_error_handler (_("%pB: warning: no symbol for"
977
21.7k
          " section '%s' found"),
978
21.7k
              abfd, symname);
979
21.7k
      continue;
980
21.7k
    }
981
548k
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
982
548k
            isym.n_type, isym.n_sclass, 0,
983
548k
            isym.n_numaux, &aux);
984
548k
      }
985
986
    /* FIXME: Microsoft uses NODUPLICATES and ASSOCIATIVE, but
987
       gnu uses ANY and SAME_SIZE.  Unfortunately, gnu doesn't
988
       do the comdat symbols right.  So, until we can fix it to
989
       do the right thing, we are temporarily disabling comdats
990
       for the MS types (they're used in DLLs and C++, but we
991
       don't support *their* C++ libraries anyway - DJ.  */
992
993
    /* Cygwin does not follow the MS style, and uses ANY and
994
       SAME_SIZE where NODUPLICATES and ASSOCIATIVE should be
995
       used.  For Interix, we just do the right thing up
996
       front.  */
997
998
4.18M
    switch (aux.x_scn.x_comdat)
999
4.18M
      {
1000
31.8k
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1001
#ifdef STRICT_PE_FORMAT
1002
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1003
#else
1004
31.8k
        sec_flags &= ~SEC_LINK_ONCE;
1005
31.8k
#endif
1006
31.8k
        break;
1007
1008
3.30k
      case IMAGE_COMDAT_SELECT_ANY:
1009
3.30k
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1010
3.30k
        break;
1011
1012
1.14k
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1013
1.14k
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1014
1.14k
        break;
1015
1016
19.8k
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1017
        /* Not yet fully implemented ??? */
1018
19.8k
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1019
19.8k
        break;
1020
1021
        /* debug$S gets this case; other implications ???  */
1022
1023
        /* There may be no symbol.  We'll search the whole
1024
     table.  Is this the right place to play this game?
1025
     Or should we do it when reading it in?  */
1026
2.62k
      case IMAGE_COMDAT_SELECT_ASSOCIATIVE:
1027
#ifdef STRICT_PE_FORMAT
1028
        /* FIXME: This is not currently implemented.  */
1029
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1030
#else
1031
2.62k
        sec_flags &= ~SEC_LINK_ONCE;
1032
2.62k
#endif
1033
2.62k
        break;
1034
1035
4.12M
      default:  /* 0 means "no symbol" */
1036
        /* debug$F gets this case; other implications ???  */
1037
4.12M
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1038
4.12M
        break;
1039
4.18M
      }
1040
1041
4.18M
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1042
4.18M
    if (*slot == NULL)
1043
0
      return false;
1044
4.18M
    struct comdat_hash_entry *newentry = *slot;
1045
4.18M
    newentry->sec_flags = sec_flags;
1046
4.18M
    newentry->symname = bfd_strdup (symname);
1047
4.18M
    newentry->target_index = isym.n_scnum;
1048
4.18M
    newentry->isym = isym;
1049
4.18M
    newentry->comdat_symbol = -1;
1050
4.18M
  }
1051
13.7M
      else
1052
13.7M
  {
1053
13.7M
    struct comdat_hash_entry *entry = *slot;
1054
1055
13.7M
    if (entry->comdat_symbol != -1)
1056
12.5M
      continue;
1057
1058
1.15M
    char *target_name = strchr (entry->symname, '$');
1059
1.15M
    if (target_name != NULL)
1060
331k
      {
1061
        /* Gas mode: the first matching on partial name.  */
1062
1063
331k
        target_name += 1;
1064
#ifndef TARGET_UNDERSCORE
1065
97.8k
#define TARGET_UNDERSCORE 0
1066
#endif
1067
        /* Is this the name we're looking for ?  */
1068
331k
        if (strcmp (target_name,
1069
331k
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1070
291k
    {
1071
      /* Not the name we're looking for */
1072
291k
      continue;
1073
291k
    }
1074
331k
      }
1075
    /* MSVC mode: the lexically second symbol (or drop through
1076
       from the above).  */
1077
    /* This must the second symbol with the section #.  It is
1078
       the actual symbol name.  Intel puts the two adjacent, but
1079
       Alpha (at least) spreads them out.  */
1080
1081
861k
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1082
861k
    entry->comdat_name = bfd_strdup (symname);
1083
861k
  }
1084
17.9M
    }
1085
1086
700k
  return true;
1087
700k
}
pei-i386.c:fill_comdat_hash
Line
Count
Source
891
69.6k
{
892
69.6k
  bfd_byte *esymstart, *esym, *esymend;
893
894
  /* Unfortunately, the PE format stores essential information in the
895
     symbol table, of all places.  We need to extract that information
896
     now, so that objdump and the linker will know how to handle the
897
     section without worrying about the symbols.  We can't call
898
     slurp_symtab, because the linker doesn't want the swapped symbols.  */
899
900
  /* COMDAT sections are special.  The first symbol is the section
901
     symbol, which tells what kind of COMDAT section it is.  The
902
     second symbol is the "comdat symbol" - the one with the unique
903
     name.  GNU uses the section symbol for the unique name; MS uses
904
     ".text" for every comdat section.  Sigh.  - DJ.  */
905
906
  /* This is not mirrored in sec_to_styp_flags(), but there doesn't
907
     seem to be a need to, either, and it would at best be rather messy.  */
908
909
69.6k
  if (! _bfd_coff_get_external_symbols (abfd))
910
21.7k
    return true;
911
912
47.8k
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
913
47.8k
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
914
915
47.8k
  for (struct internal_syment isym;
916
1.27M
       esym < esymend;
917
1.22M
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
918
1.22M
    {
919
1.22M
      char buf[SYMNMLEN + 1];
920
1.22M
      const char *symname;
921
1.22M
      flagword sec_flags = SEC_LINK_ONCE;
922
923
1.22M
      bfd_coff_swap_sym_in (abfd, esym, &isym);
924
925
      /* According to the MSVC documentation, the first TWO entries
926
   with the section # are both of interest to us.  The first one
927
   is the "section symbol" (section name).  The second is the
928
   comdat symbol name.  Here, we've found the first qualifying
929
   entry; we distinguish it from the second with a state flag.
930
931
   In the case of gas-generated (at least until that is fixed)
932
   .o files, it isn't necessarily the second one.  It may be
933
   some other later symbol.
934
935
   Since gas also doesn't follow MS conventions and emits the
936
   section similar to .text$<name>, where <something> is the
937
   name we're looking for, we distinguish the two as follows:
938
939
   If the section name is simply a section name (no $) we
940
   presume it's MS-generated, and look at precisely the second
941
   symbol for the comdat name.  If the section name has a $, we
942
   assume it's gas-generated, and look for <something> (whatever
943
   follows the $) as the comdat symbol.  */
944
945
      /* All 3 branches use this.  */
946
1.22M
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
947
948
      /* PR 17512 file: 078-11867-0.004  */
949
1.22M
      if (symname == NULL)
950
379k
  {
951
379k
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
952
379k
            abfd);
953
379k
    continue;
954
379k
  }
955
956
846k
      union internal_auxent aux;
957
958
846k
      struct comdat_hash_entry needle;
959
846k
      needle.target_index = isym.n_scnum;
960
961
846k
      void **slot
962
846k
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
963
846k
      if (slot == NULL)
964
0
  return false;
965
966
846k
      if (*slot == NULL)
967
302k
  {
968
302k
    if (isym.n_numaux != 1)
969
264k
      aux.x_scn.x_comdat = 0;
970
37.8k
    else
971
37.8k
      {
972
        /* PR 17512: file: e2cfe54f.  */
973
37.8k
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
974
2.68k
    {
975
      /* xgettext:c-format */
976
2.68k
      _bfd_error_handler (_("%pB: warning: no symbol for"
977
2.68k
          " section '%s' found"),
978
2.68k
              abfd, symname);
979
2.68k
      continue;
980
2.68k
    }
981
35.1k
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
982
35.1k
            isym.n_type, isym.n_sclass, 0,
983
35.1k
            isym.n_numaux, &aux);
984
35.1k
      }
985
986
    /* FIXME: Microsoft uses NODUPLICATES and ASSOCIATIVE, but
987
       gnu uses ANY and SAME_SIZE.  Unfortunately, gnu doesn't
988
       do the comdat symbols right.  So, until we can fix it to
989
       do the right thing, we are temporarily disabling comdats
990
       for the MS types (they're used in DLLs and C++, but we
991
       don't support *their* C++ libraries anyway - DJ.  */
992
993
    /* Cygwin does not follow the MS style, and uses ANY and
994
       SAME_SIZE where NODUPLICATES and ASSOCIATIVE should be
995
       used.  For Interix, we just do the right thing up
996
       front.  */
997
998
299k
    switch (aux.x_scn.x_comdat)
999
299k
      {
1000
3.51k
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1001
#ifdef STRICT_PE_FORMAT
1002
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1003
#else
1004
3.51k
        sec_flags &= ~SEC_LINK_ONCE;
1005
3.51k
#endif
1006
3.51k
        break;
1007
1008
831
      case IMAGE_COMDAT_SELECT_ANY:
1009
831
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1010
831
        break;
1011
1012
18
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1013
18
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1014
18
        break;
1015
1016
1.77k
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1017
        /* Not yet fully implemented ??? */
1018
1.77k
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1019
1.77k
        break;
1020
1021
        /* debug$S gets this case; other implications ???  */
1022
1023
        /* There may be no symbol.  We'll search the whole
1024
     table.  Is this the right place to play this game?
1025
     Or should we do it when reading it in?  */
1026
43
      case IMAGE_COMDAT_SELECT_ASSOCIATIVE:
1027
#ifdef STRICT_PE_FORMAT
1028
        /* FIXME: This is not currently implemented.  */
1029
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1030
#else
1031
43
        sec_flags &= ~SEC_LINK_ONCE;
1032
43
#endif
1033
43
        break;
1034
1035
293k
      default:  /* 0 means "no symbol" */
1036
        /* debug$F gets this case; other implications ???  */
1037
293k
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1038
293k
        break;
1039
299k
      }
1040
1041
299k
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1042
299k
    if (*slot == NULL)
1043
0
      return false;
1044
299k
    struct comdat_hash_entry *newentry = *slot;
1045
299k
    newentry->sec_flags = sec_flags;
1046
299k
    newentry->symname = bfd_strdup (symname);
1047
299k
    newentry->target_index = isym.n_scnum;
1048
299k
    newentry->isym = isym;
1049
299k
    newentry->comdat_symbol = -1;
1050
299k
  }
1051
544k
      else
1052
544k
  {
1053
544k
    struct comdat_hash_entry *entry = *slot;
1054
1055
544k
    if (entry->comdat_symbol != -1)
1056
467k
      continue;
1057
1058
76.6k
    char *target_name = strchr (entry->symname, '$');
1059
76.6k
    if (target_name != NULL)
1060
13.1k
      {
1061
        /* Gas mode: the first matching on partial name.  */
1062
1063
13.1k
        target_name += 1;
1064
#ifndef TARGET_UNDERSCORE
1065
#define TARGET_UNDERSCORE 0
1066
#endif
1067
        /* Is this the name we're looking for ?  */
1068
13.1k
        if (strcmp (target_name,
1069
13.1k
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1070
8.17k
    {
1071
      /* Not the name we're looking for */
1072
8.17k
      continue;
1073
8.17k
    }
1074
13.1k
      }
1075
    /* MSVC mode: the lexically second symbol (or drop through
1076
       from the above).  */
1077
    /* This must the second symbol with the section #.  It is
1078
       the actual symbol name.  Intel puts the two adjacent, but
1079
       Alpha (at least) spreads them out.  */
1080
1081
68.5k
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1082
68.5k
    entry->comdat_name = bfd_strdup (symname);
1083
68.5k
  }
1084
846k
    }
1085
1086
47.8k
  return true;
1087
47.8k
}
pe-x86_64.c:fill_comdat_hash
Line
Count
Source
891
155k
{
892
155k
  bfd_byte *esymstart, *esym, *esymend;
893
894
  /* Unfortunately, the PE format stores essential information in the
895
     symbol table, of all places.  We need to extract that information
896
     now, so that objdump and the linker will know how to handle the
897
     section without worrying about the symbols.  We can't call
898
     slurp_symtab, because the linker doesn't want the swapped symbols.  */
899
900
  /* COMDAT sections are special.  The first symbol is the section
901
     symbol, which tells what kind of COMDAT section it is.  The
902
     second symbol is the "comdat symbol" - the one with the unique
903
     name.  GNU uses the section symbol for the unique name; MS uses
904
     ".text" for every comdat section.  Sigh.  - DJ.  */
905
906
  /* This is not mirrored in sec_to_styp_flags(), but there doesn't
907
     seem to be a need to, either, and it would at best be rather messy.  */
908
909
155k
  if (! _bfd_coff_get_external_symbols (abfd))
910
55.2k
    return true;
911
912
100k
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
913
100k
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
914
915
100k
  for (struct internal_syment isym;
916
6.77M
       esym < esymend;
917
6.67M
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
918
6.67M
    {
919
6.67M
      char buf[SYMNMLEN + 1];
920
6.67M
      const char *symname;
921
6.67M
      flagword sec_flags = SEC_LINK_ONCE;
922
923
6.67M
      bfd_coff_swap_sym_in (abfd, esym, &isym);
924
925
      /* According to the MSVC documentation, the first TWO entries
926
   with the section # are both of interest to us.  The first one
927
   is the "section symbol" (section name).  The second is the
928
   comdat symbol name.  Here, we've found the first qualifying
929
   entry; we distinguish it from the second with a state flag.
930
931
   In the case of gas-generated (at least until that is fixed)
932
   .o files, it isn't necessarily the second one.  It may be
933
   some other later symbol.
934
935
   Since gas also doesn't follow MS conventions and emits the
936
   section similar to .text$<name>, where <something> is the
937
   name we're looking for, we distinguish the two as follows:
938
939
   If the section name is simply a section name (no $) we
940
   presume it's MS-generated, and look at precisely the second
941
   symbol for the comdat name.  If the section name has a $, we
942
   assume it's gas-generated, and look for <something> (whatever
943
   follows the $) as the comdat symbol.  */
944
945
      /* All 3 branches use this.  */
946
6.67M
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
947
948
      /* PR 17512 file: 078-11867-0.004  */
949
6.67M
      if (symname == NULL)
950
825k
  {
951
825k
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
952
825k
            abfd);
953
825k
    continue;
954
825k
  }
955
956
5.85M
      union internal_auxent aux;
957
958
5.85M
      struct comdat_hash_entry needle;
959
5.85M
      needle.target_index = isym.n_scnum;
960
961
5.85M
      void **slot
962
5.85M
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
963
5.85M
      if (slot == NULL)
964
0
  return false;
965
966
5.85M
      if (*slot == NULL)
967
660k
  {
968
660k
    if (isym.n_numaux != 1)
969
570k
      aux.x_scn.x_comdat = 0;
970
89.9k
    else
971
89.9k
      {
972
        /* PR 17512: file: e2cfe54f.  */
973
89.9k
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
974
2.62k
    {
975
      /* xgettext:c-format */
976
2.62k
      _bfd_error_handler (_("%pB: warning: no symbol for"
977
2.62k
          " section '%s' found"),
978
2.62k
              abfd, symname);
979
2.62k
      continue;
980
2.62k
    }
981
87.3k
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
982
87.3k
            isym.n_type, isym.n_sclass, 0,
983
87.3k
            isym.n_numaux, &aux);
984
87.3k
      }
985
986
    /* FIXME: Microsoft uses NODUPLICATES and ASSOCIATIVE, but
987
       gnu uses ANY and SAME_SIZE.  Unfortunately, gnu doesn't
988
       do the comdat symbols right.  So, until we can fix it to
989
       do the right thing, we are temporarily disabling comdats
990
       for the MS types (they're used in DLLs and C++, but we
991
       don't support *their* C++ libraries anyway - DJ.  */
992
993
    /* Cygwin does not follow the MS style, and uses ANY and
994
       SAME_SIZE where NODUPLICATES and ASSOCIATIVE should be
995
       used.  For Interix, we just do the right thing up
996
       front.  */
997
998
658k
    switch (aux.x_scn.x_comdat)
999
658k
      {
1000
3.59k
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1001
#ifdef STRICT_PE_FORMAT
1002
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1003
#else
1004
3.59k
        sec_flags &= ~SEC_LINK_ONCE;
1005
3.59k
#endif
1006
3.59k
        break;
1007
1008
711
      case IMAGE_COMDAT_SELECT_ANY:
1009
711
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1010
711
        break;
1011
1012
342
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1013
342
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1014
342
        break;
1015
1016
2.61k
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1017
        /* Not yet fully implemented ??? */
1018
2.61k
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1019
2.61k
        break;
1020
1021
        /* debug$S gets this case; other implications ???  */
1022
1023
        /* There may be no symbol.  We'll search the whole
1024
     table.  Is this the right place to play this game?
1025
     Or should we do it when reading it in?  */
1026
6
      case IMAGE_COMDAT_SELECT_ASSOCIATIVE:
1027
#ifdef STRICT_PE_FORMAT
1028
        /* FIXME: This is not currently implemented.  */
1029
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1030
#else
1031
6
        sec_flags &= ~SEC_LINK_ONCE;
1032
6
#endif
1033
6
        break;
1034
1035
650k
      default:  /* 0 means "no symbol" */
1036
        /* debug$F gets this case; other implications ???  */
1037
650k
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1038
650k
        break;
1039
658k
      }
1040
1041
658k
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1042
658k
    if (*slot == NULL)
1043
0
      return false;
1044
658k
    struct comdat_hash_entry *newentry = *slot;
1045
658k
    newentry->sec_flags = sec_flags;
1046
658k
    newentry->symname = bfd_strdup (symname);
1047
658k
    newentry->target_index = isym.n_scnum;
1048
658k
    newentry->isym = isym;
1049
658k
    newentry->comdat_symbol = -1;
1050
658k
  }
1051
5.19M
      else
1052
5.19M
  {
1053
5.19M
    struct comdat_hash_entry *entry = *slot;
1054
1055
5.19M
    if (entry->comdat_symbol != -1)
1056
5.01M
      continue;
1057
1058
180k
    char *target_name = strchr (entry->symname, '$');
1059
180k
    if (target_name != NULL)
1060
47.2k
      {
1061
        /* Gas mode: the first matching on partial name.  */
1062
1063
47.2k
        target_name += 1;
1064
#ifndef TARGET_UNDERSCORE
1065
#define TARGET_UNDERSCORE 0
1066
#endif
1067
        /* Is this the name we're looking for ?  */
1068
47.2k
        if (strcmp (target_name,
1069
47.2k
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1070
45.3k
    {
1071
      /* Not the name we're looking for */
1072
45.3k
      continue;
1073
45.3k
    }
1074
47.2k
      }
1075
    /* MSVC mode: the lexically second symbol (or drop through
1076
       from the above).  */
1077
    /* This must the second symbol with the section #.  It is
1078
       the actual symbol name.  Intel puts the two adjacent, but
1079
       Alpha (at least) spreads them out.  */
1080
1081
135k
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1082
135k
    entry->comdat_name = bfd_strdup (symname);
1083
135k
  }
1084
5.85M
    }
1085
1086
100k
  return true;
1087
100k
}
pei-x86_64.c:fill_comdat_hash
Line
Count
Source
891
84.0k
{
892
84.0k
  bfd_byte *esymstart, *esym, *esymend;
893
894
  /* Unfortunately, the PE format stores essential information in the
895
     symbol table, of all places.  We need to extract that information
896
     now, so that objdump and the linker will know how to handle the
897
     section without worrying about the symbols.  We can't call
898
     slurp_symtab, because the linker doesn't want the swapped symbols.  */
899
900
  /* COMDAT sections are special.  The first symbol is the section
901
     symbol, which tells what kind of COMDAT section it is.  The
902
     second symbol is the "comdat symbol" - the one with the unique
903
     name.  GNU uses the section symbol for the unique name; MS uses
904
     ".text" for every comdat section.  Sigh.  - DJ.  */
905
906
  /* This is not mirrored in sec_to_styp_flags(), but there doesn't
907
     seem to be a need to, either, and it would at best be rather messy.  */
908
909
84.0k
  if (! _bfd_coff_get_external_symbols (abfd))
910
30.6k
    return true;
911
912
53.3k
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
913
53.3k
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
914
915
53.3k
  for (struct internal_syment isym;
916
3.71M
       esym < esymend;
917
3.66M
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
918
3.66M
    {
919
3.66M
      char buf[SYMNMLEN + 1];
920
3.66M
      const char *symname;
921
3.66M
      flagword sec_flags = SEC_LINK_ONCE;
922
923
3.66M
      bfd_coff_swap_sym_in (abfd, esym, &isym);
924
925
      /* According to the MSVC documentation, the first TWO entries
926
   with the section # are both of interest to us.  The first one
927
   is the "section symbol" (section name).  The second is the
928
   comdat symbol name.  Here, we've found the first qualifying
929
   entry; we distinguish it from the second with a state flag.
930
931
   In the case of gas-generated (at least until that is fixed)
932
   .o files, it isn't necessarily the second one.  It may be
933
   some other later symbol.
934
935
   Since gas also doesn't follow MS conventions and emits the
936
   section similar to .text$<name>, where <something> is the
937
   name we're looking for, we distinguish the two as follows:
938
939
   If the section name is simply a section name (no $) we
940
   presume it's MS-generated, and look at precisely the second
941
   symbol for the comdat name.  If the section name has a $, we
942
   assume it's gas-generated, and look for <something> (whatever
943
   follows the $) as the comdat symbol.  */
944
945
      /* All 3 branches use this.  */
946
3.66M
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
947
948
      /* PR 17512 file: 078-11867-0.004  */
949
3.66M
      if (symname == NULL)
950
998k
  {
951
998k
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
952
998k
            abfd);
953
998k
    continue;
954
998k
  }
955
956
2.66M
      union internal_auxent aux;
957
958
2.66M
      struct comdat_hash_entry needle;
959
2.66M
      needle.target_index = isym.n_scnum;
960
961
2.66M
      void **slot
962
2.66M
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
963
2.66M
      if (slot == NULL)
964
0
  return false;
965
966
2.66M
      if (*slot == NULL)
967
426k
  {
968
426k
    if (isym.n_numaux != 1)
969
378k
      aux.x_scn.x_comdat = 0;
970
47.3k
    else
971
47.3k
      {
972
        /* PR 17512: file: e2cfe54f.  */
973
47.3k
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
974
1.90k
    {
975
      /* xgettext:c-format */
976
1.90k
      _bfd_error_handler (_("%pB: warning: no symbol for"
977
1.90k
          " section '%s' found"),
978
1.90k
              abfd, symname);
979
1.90k
      continue;
980
1.90k
    }
981
45.4k
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
982
45.4k
            isym.n_type, isym.n_sclass, 0,
983
45.4k
            isym.n_numaux, &aux);
984
45.4k
      }
985
986
    /* FIXME: Microsoft uses NODUPLICATES and ASSOCIATIVE, but
987
       gnu uses ANY and SAME_SIZE.  Unfortunately, gnu doesn't
988
       do the comdat symbols right.  So, until we can fix it to
989
       do the right thing, we are temporarily disabling comdats
990
       for the MS types (they're used in DLLs and C++, but we
991
       don't support *their* C++ libraries anyway - DJ.  */
992
993
    /* Cygwin does not follow the MS style, and uses ANY and
994
       SAME_SIZE where NODUPLICATES and ASSOCIATIVE should be
995
       used.  For Interix, we just do the right thing up
996
       front.  */
997
998
424k
    switch (aux.x_scn.x_comdat)
999
424k
      {
1000
1.93k
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1001
#ifdef STRICT_PE_FORMAT
1002
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1003
#else
1004
1.93k
        sec_flags &= ~SEC_LINK_ONCE;
1005
1.93k
#endif
1006
1.93k
        break;
1007
1008
544
      case IMAGE_COMDAT_SELECT_ANY:
1009
544
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1010
544
        break;
1011
1012
10
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1013
10
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1014
10
        break;
1015
1016
1.68k
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1017
        /* Not yet fully implemented ??? */
1018
1.68k
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1019
1.68k
        break;
1020
1021
        /* debug$S gets this case; other implications ???  */
1022
1023
        /* There may be no symbol.  We'll search the whole
1024
     table.  Is this the right place to play this game?
1025
     Or should we do it when reading it in?  */
1026
57
      case IMAGE_COMDAT_SELECT_ASSOCIATIVE:
1027
#ifdef STRICT_PE_FORMAT
1028
        /* FIXME: This is not currently implemented.  */
1029
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1030
#else
1031
57
        sec_flags &= ~SEC_LINK_ONCE;
1032
57
#endif
1033
57
        break;
1034
1035
420k
      default:  /* 0 means "no symbol" */
1036
        /* debug$F gets this case; other implications ???  */
1037
420k
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1038
420k
        break;
1039
424k
      }
1040
1041
424k
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1042
424k
    if (*slot == NULL)
1043
0
      return false;
1044
424k
    struct comdat_hash_entry *newentry = *slot;
1045
424k
    newentry->sec_flags = sec_flags;
1046
424k
    newentry->symname = bfd_strdup (symname);
1047
424k
    newentry->target_index = isym.n_scnum;
1048
424k
    newentry->isym = isym;
1049
424k
    newentry->comdat_symbol = -1;
1050
424k
  }
1051
2.23M
      else
1052
2.23M
  {
1053
2.23M
    struct comdat_hash_entry *entry = *slot;
1054
1055
2.23M
    if (entry->comdat_symbol != -1)
1056
2.10M
      continue;
1057
1058
130k
    char *target_name = strchr (entry->symname, '$');
1059
130k
    if (target_name != NULL)
1060
17.4k
      {
1061
        /* Gas mode: the first matching on partial name.  */
1062
1063
17.4k
        target_name += 1;
1064
#ifndef TARGET_UNDERSCORE
1065
#define TARGET_UNDERSCORE 0
1066
#endif
1067
        /* Is this the name we're looking for ?  */
1068
17.4k
        if (strcmp (target_name,
1069
17.4k
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1070
15.0k
    {
1071
      /* Not the name we're looking for */
1072
15.0k
      continue;
1073
15.0k
    }
1074
17.4k
      }
1075
    /* MSVC mode: the lexically second symbol (or drop through
1076
       from the above).  */
1077
    /* This must the second symbol with the section #.  It is
1078
       the actual symbol name.  Intel puts the two adjacent, but
1079
       Alpha (at least) spreads them out.  */
1080
1081
115k
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1082
115k
    entry->comdat_name = bfd_strdup (symname);
1083
115k
  }
1084
2.66M
    }
1085
1086
53.3k
  return true;
1087
53.3k
}
pe-aarch64.c:fill_comdat_hash
Line
Count
Source
891
40.9k
{
892
40.9k
  bfd_byte *esymstart, *esym, *esymend;
893
894
  /* Unfortunately, the PE format stores essential information in the
895
     symbol table, of all places.  We need to extract that information
896
     now, so that objdump and the linker will know how to handle the
897
     section without worrying about the symbols.  We can't call
898
     slurp_symtab, because the linker doesn't want the swapped symbols.  */
899
900
  /* COMDAT sections are special.  The first symbol is the section
901
     symbol, which tells what kind of COMDAT section it is.  The
902
     second symbol is the "comdat symbol" - the one with the unique
903
     name.  GNU uses the section symbol for the unique name; MS uses
904
     ".text" for every comdat section.  Sigh.  - DJ.  */
905
906
  /* This is not mirrored in sec_to_styp_flags(), but there doesn't
907
     seem to be a need to, either, and it would at best be rather messy.  */
908
909
40.9k
  if (! _bfd_coff_get_external_symbols (abfd))
910
11.2k
    return true;
911
912
29.6k
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
913
29.6k
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
914
915
29.6k
  for (struct internal_syment isym;
916
363k
       esym < esymend;
917
334k
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
918
334k
    {
919
334k
      char buf[SYMNMLEN + 1];
920
334k
      const char *symname;
921
334k
      flagword sec_flags = SEC_LINK_ONCE;
922
923
334k
      bfd_coff_swap_sym_in (abfd, esym, &isym);
924
925
      /* According to the MSVC documentation, the first TWO entries
926
   with the section # are both of interest to us.  The first one
927
   is the "section symbol" (section name).  The second is the
928
   comdat symbol name.  Here, we've found the first qualifying
929
   entry; we distinguish it from the second with a state flag.
930
931
   In the case of gas-generated (at least until that is fixed)
932
   .o files, it isn't necessarily the second one.  It may be
933
   some other later symbol.
934
935
   Since gas also doesn't follow MS conventions and emits the
936
   section similar to .text$<name>, where <something> is the
937
   name we're looking for, we distinguish the two as follows:
938
939
   If the section name is simply a section name (no $) we
940
   presume it's MS-generated, and look at precisely the second
941
   symbol for the comdat name.  If the section name has a $, we
942
   assume it's gas-generated, and look for <something> (whatever
943
   follows the $) as the comdat symbol.  */
944
945
      /* All 3 branches use this.  */
946
334k
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
947
948
      /* PR 17512 file: 078-11867-0.004  */
949
334k
      if (symname == NULL)
950
85.3k
  {
951
85.3k
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
952
85.3k
            abfd);
953
85.3k
    continue;
954
85.3k
  }
955
956
248k
      union internal_auxent aux;
957
958
248k
      struct comdat_hash_entry needle;
959
248k
      needle.target_index = isym.n_scnum;
960
961
248k
      void **slot
962
248k
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
963
248k
      if (slot == NULL)
964
0
  return false;
965
966
248k
      if (*slot == NULL)
967
75.4k
  {
968
75.4k
    if (isym.n_numaux != 1)
969
62.1k
      aux.x_scn.x_comdat = 0;
970
13.2k
    else
971
13.2k
      {
972
        /* PR 17512: file: e2cfe54f.  */
973
13.2k
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
974
1.26k
    {
975
      /* xgettext:c-format */
976
1.26k
      _bfd_error_handler (_("%pB: warning: no symbol for"
977
1.26k
          " section '%s' found"),
978
1.26k
              abfd, symname);
979
1.26k
      continue;
980
1.26k
    }
981
11.9k
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
982
11.9k
            isym.n_type, isym.n_sclass, 0,
983
11.9k
            isym.n_numaux, &aux);
984
11.9k
      }
985
986
    /* FIXME: Microsoft uses NODUPLICATES and ASSOCIATIVE, but
987
       gnu uses ANY and SAME_SIZE.  Unfortunately, gnu doesn't
988
       do the comdat symbols right.  So, until we can fix it to
989
       do the right thing, we are temporarily disabling comdats
990
       for the MS types (they're used in DLLs and C++, but we
991
       don't support *their* C++ libraries anyway - DJ.  */
992
993
    /* Cygwin does not follow the MS style, and uses ANY and
994
       SAME_SIZE where NODUPLICATES and ASSOCIATIVE should be
995
       used.  For Interix, we just do the right thing up
996
       front.  */
997
998
74.1k
    switch (aux.x_scn.x_comdat)
999
74.1k
      {
1000
631
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1001
#ifdef STRICT_PE_FORMAT
1002
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1003
#else
1004
631
        sec_flags &= ~SEC_LINK_ONCE;
1005
631
#endif
1006
631
        break;
1007
1008
7
      case IMAGE_COMDAT_SELECT_ANY:
1009
7
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1010
7
        break;
1011
1012
239
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1013
239
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1014
239
        break;
1015
1016
331
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1017
        /* Not yet fully implemented ??? */
1018
331
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1019
331
        break;
1020
1021
        /* debug$S gets this case; other implications ???  */
1022
1023
        /* There may be no symbol.  We'll search the whole
1024
     table.  Is this the right place to play this game?
1025
     Or should we do it when reading it in?  */
1026
16
      case IMAGE_COMDAT_SELECT_ASSOCIATIVE:
1027
#ifdef STRICT_PE_FORMAT
1028
        /* FIXME: This is not currently implemented.  */
1029
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1030
#else
1031
16
        sec_flags &= ~SEC_LINK_ONCE;
1032
16
#endif
1033
16
        break;
1034
1035
72.9k
      default:  /* 0 means "no symbol" */
1036
        /* debug$F gets this case; other implications ???  */
1037
72.9k
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1038
72.9k
        break;
1039
74.1k
      }
1040
1041
74.1k
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1042
74.1k
    if (*slot == NULL)
1043
0
      return false;
1044
74.1k
    struct comdat_hash_entry *newentry = *slot;
1045
74.1k
    newentry->sec_flags = sec_flags;
1046
74.1k
    newentry->symname = bfd_strdup (symname);
1047
74.1k
    newentry->target_index = isym.n_scnum;
1048
74.1k
    newentry->isym = isym;
1049
74.1k
    newentry->comdat_symbol = -1;
1050
74.1k
  }
1051
173k
      else
1052
173k
  {
1053
173k
    struct comdat_hash_entry *entry = *slot;
1054
1055
173k
    if (entry->comdat_symbol != -1)
1056
145k
      continue;
1057
1058
27.8k
    char *target_name = strchr (entry->symname, '$');
1059
27.8k
    if (target_name != NULL)
1060
14.1k
      {
1061
        /* Gas mode: the first matching on partial name.  */
1062
1063
14.1k
        target_name += 1;
1064
14.1k
#ifndef TARGET_UNDERSCORE
1065
14.1k
#define TARGET_UNDERSCORE 0
1066
14.1k
#endif
1067
        /* Is this the name we're looking for ?  */
1068
14.1k
        if (strcmp (target_name,
1069
14.1k
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1070
13.0k
    {
1071
      /* Not the name we're looking for */
1072
13.0k
      continue;
1073
13.0k
    }
1074
14.1k
      }
1075
    /* MSVC mode: the lexically second symbol (or drop through
1076
       from the above).  */
1077
    /* This must the second symbol with the section #.  It is
1078
       the actual symbol name.  Intel puts the two adjacent, but
1079
       Alpha (at least) spreads them out.  */
1080
1081
14.7k
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1082
14.7k
    entry->comdat_name = bfd_strdup (symname);
1083
14.7k
  }
1084
248k
    }
1085
1086
29.6k
  return true;
1087
29.6k
}
pei-aarch64.c:fill_comdat_hash
Line
Count
Source
891
61.9k
{
892
61.9k
  bfd_byte *esymstart, *esym, *esymend;
893
894
  /* Unfortunately, the PE format stores essential information in the
895
     symbol table, of all places.  We need to extract that information
896
     now, so that objdump and the linker will know how to handle the
897
     section without worrying about the symbols.  We can't call
898
     slurp_symtab, because the linker doesn't want the swapped symbols.  */
899
900
  /* COMDAT sections are special.  The first symbol is the section
901
     symbol, which tells what kind of COMDAT section it is.  The
902
     second symbol is the "comdat symbol" - the one with the unique
903
     name.  GNU uses the section symbol for the unique name; MS uses
904
     ".text" for every comdat section.  Sigh.  - DJ.  */
905
906
  /* This is not mirrored in sec_to_styp_flags(), but there doesn't
907
     seem to be a need to, either, and it would at best be rather messy.  */
908
909
61.9k
  if (! _bfd_coff_get_external_symbols (abfd))
910
20.1k
    return true;
911
912
41.7k
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
913
41.7k
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
914
915
41.7k
  for (struct internal_syment isym;
916
2.20M
       esym < esymend;
917
2.15M
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
918
2.15M
    {
919
2.15M
      char buf[SYMNMLEN + 1];
920
2.15M
      const char *symname;
921
2.15M
      flagword sec_flags = SEC_LINK_ONCE;
922
923
2.15M
      bfd_coff_swap_sym_in (abfd, esym, &isym);
924
925
      /* According to the MSVC documentation, the first TWO entries
926
   with the section # are both of interest to us.  The first one
927
   is the "section symbol" (section name).  The second is the
928
   comdat symbol name.  Here, we've found the first qualifying
929
   entry; we distinguish it from the second with a state flag.
930
931
   In the case of gas-generated (at least until that is fixed)
932
   .o files, it isn't necessarily the second one.  It may be
933
   some other later symbol.
934
935
   Since gas also doesn't follow MS conventions and emits the
936
   section similar to .text$<name>, where <something> is the
937
   name we're looking for, we distinguish the two as follows:
938
939
   If the section name is simply a section name (no $) we
940
   presume it's MS-generated, and look at precisely the second
941
   symbol for the comdat name.  If the section name has a $, we
942
   assume it's gas-generated, and look for <something> (whatever
943
   follows the $) as the comdat symbol.  */
944
945
      /* All 3 branches use this.  */
946
2.15M
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
947
948
      /* PR 17512 file: 078-11867-0.004  */
949
2.15M
      if (symname == NULL)
950
627k
  {
951
627k
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
952
627k
            abfd);
953
627k
    continue;
954
627k
  }
955
956
1.53M
      union internal_auxent aux;
957
958
1.53M
      struct comdat_hash_entry needle;
959
1.53M
      needle.target_index = isym.n_scnum;
960
961
1.53M
      void **slot
962
1.53M
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
963
1.53M
      if (slot == NULL)
964
0
  return false;
965
966
1.53M
      if (*slot == NULL)
967
429k
  {
968
429k
    if (isym.n_numaux != 1)
969
371k
      aux.x_scn.x_comdat = 0;
970
57.3k
    else
971
57.3k
      {
972
        /* PR 17512: file: e2cfe54f.  */
973
57.3k
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
974
1.20k
    {
975
      /* xgettext:c-format */
976
1.20k
      _bfd_error_handler (_("%pB: warning: no symbol for"
977
1.20k
          " section '%s' found"),
978
1.20k
              abfd, symname);
979
1.20k
      continue;
980
1.20k
    }
981
56.1k
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
982
56.1k
            isym.n_type, isym.n_sclass, 0,
983
56.1k
            isym.n_numaux, &aux);
984
56.1k
      }
985
986
    /* FIXME: Microsoft uses NODUPLICATES and ASSOCIATIVE, but
987
       gnu uses ANY and SAME_SIZE.  Unfortunately, gnu doesn't
988
       do the comdat symbols right.  So, until we can fix it to
989
       do the right thing, we are temporarily disabling comdats
990
       for the MS types (they're used in DLLs and C++, but we
991
       don't support *their* C++ libraries anyway - DJ.  */
992
993
    /* Cygwin does not follow the MS style, and uses ANY and
994
       SAME_SIZE where NODUPLICATES and ASSOCIATIVE should be
995
       used.  For Interix, we just do the right thing up
996
       front.  */
997
998
427k
    switch (aux.x_scn.x_comdat)
999
427k
      {
1000
2.88k
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1001
#ifdef STRICT_PE_FORMAT
1002
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1003
#else
1004
2.88k
        sec_flags &= ~SEC_LINK_ONCE;
1005
2.88k
#endif
1006
2.88k
        break;
1007
1008
81
      case IMAGE_COMDAT_SELECT_ANY:
1009
81
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1010
81
        break;
1011
1012
21
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1013
21
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1014
21
        break;
1015
1016
1.96k
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1017
        /* Not yet fully implemented ??? */
1018
1.96k
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1019
1.96k
        break;
1020
1021
        /* debug$S gets this case; other implications ???  */
1022
1023
        /* There may be no symbol.  We'll search the whole
1024
     table.  Is this the right place to play this game?
1025
     Or should we do it when reading it in?  */
1026
34
      case IMAGE_COMDAT_SELECT_ASSOCIATIVE:
1027
#ifdef STRICT_PE_FORMAT
1028
        /* FIXME: This is not currently implemented.  */
1029
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1030
#else
1031
34
        sec_flags &= ~SEC_LINK_ONCE;
1032
34
#endif
1033
34
        break;
1034
1035
422k
      default:  /* 0 means "no symbol" */
1036
        /* debug$F gets this case; other implications ???  */
1037
422k
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1038
422k
        break;
1039
427k
      }
1040
1041
427k
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1042
427k
    if (*slot == NULL)
1043
0
      return false;
1044
427k
    struct comdat_hash_entry *newentry = *slot;
1045
427k
    newentry->sec_flags = sec_flags;
1046
427k
    newentry->symname = bfd_strdup (symname);
1047
427k
    newentry->target_index = isym.n_scnum;
1048
427k
    newentry->isym = isym;
1049
427k
    newentry->comdat_symbol = -1;
1050
427k
  }
1051
1.10M
      else
1052
1.10M
  {
1053
1.10M
    struct comdat_hash_entry *entry = *slot;
1054
1055
1.10M
    if (entry->comdat_symbol != -1)
1056
1.01M
      continue;
1057
1058
91.9k
    char *target_name = strchr (entry->symname, '$');
1059
91.9k
    if (target_name != NULL)
1060
16.7k
      {
1061
        /* Gas mode: the first matching on partial name.  */
1062
1063
16.7k
        target_name += 1;
1064
16.7k
#ifndef TARGET_UNDERSCORE
1065
16.7k
#define TARGET_UNDERSCORE 0
1066
16.7k
#endif
1067
        /* Is this the name we're looking for ?  */
1068
16.7k
        if (strcmp (target_name,
1069
16.7k
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1070
15.0k
    {
1071
      /* Not the name we're looking for */
1072
15.0k
      continue;
1073
15.0k
    }
1074
16.7k
      }
1075
    /* MSVC mode: the lexically second symbol (or drop through
1076
       from the above).  */
1077
    /* This must the second symbol with the section #.  It is
1078
       the actual symbol name.  Intel puts the two adjacent, but
1079
       Alpha (at least) spreads them out.  */
1080
1081
76.8k
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1082
76.8k
    entry->comdat_name = bfd_strdup (symname);
1083
76.8k
  }
1084
1.53M
    }
1085
1086
41.7k
  return true;
1087
41.7k
}
pei-ia64.c:fill_comdat_hash
Line
Count
Source
891
69.0k
{
892
69.0k
  bfd_byte *esymstart, *esym, *esymend;
893
894
  /* Unfortunately, the PE format stores essential information in the
895
     symbol table, of all places.  We need to extract that information
896
     now, so that objdump and the linker will know how to handle the
897
     section without worrying about the symbols.  We can't call
898
     slurp_symtab, because the linker doesn't want the swapped symbols.  */
899
900
  /* COMDAT sections are special.  The first symbol is the section
901
     symbol, which tells what kind of COMDAT section it is.  The
902
     second symbol is the "comdat symbol" - the one with the unique
903
     name.  GNU uses the section symbol for the unique name; MS uses
904
     ".text" for every comdat section.  Sigh.  - DJ.  */
905
906
  /* This is not mirrored in sec_to_styp_flags(), but there doesn't
907
     seem to be a need to, either, and it would at best be rather messy.  */
908
909
69.0k
  if (! _bfd_coff_get_external_symbols (abfd))
910
19.3k
    return true;
911
912
49.6k
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
913
49.6k
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
914
915
49.6k
  for (struct internal_syment isym;
916
2.03M
       esym < esymend;
917
1.98M
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
918
1.98M
    {
919
1.98M
      char buf[SYMNMLEN + 1];
920
1.98M
      const char *symname;
921
1.98M
      flagword sec_flags = SEC_LINK_ONCE;
922
923
1.98M
      bfd_coff_swap_sym_in (abfd, esym, &isym);
924
925
      /* According to the MSVC documentation, the first TWO entries
926
   with the section # are both of interest to us.  The first one
927
   is the "section symbol" (section name).  The second is the
928
   comdat symbol name.  Here, we've found the first qualifying
929
   entry; we distinguish it from the second with a state flag.
930
931
   In the case of gas-generated (at least until that is fixed)
932
   .o files, it isn't necessarily the second one.  It may be
933
   some other later symbol.
934
935
   Since gas also doesn't follow MS conventions and emits the
936
   section similar to .text$<name>, where <something> is the
937
   name we're looking for, we distinguish the two as follows:
938
939
   If the section name is simply a section name (no $) we
940
   presume it's MS-generated, and look at precisely the second
941
   symbol for the comdat name.  If the section name has a $, we
942
   assume it's gas-generated, and look for <something> (whatever
943
   follows the $) as the comdat symbol.  */
944
945
      /* All 3 branches use this.  */
946
1.98M
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
947
948
      /* PR 17512 file: 078-11867-0.004  */
949
1.98M
      if (symname == NULL)
950
711k
  {
951
711k
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
952
711k
            abfd);
953
711k
    continue;
954
711k
  }
955
956
1.27M
      union internal_auxent aux;
957
958
1.27M
      struct comdat_hash_entry needle;
959
1.27M
      needle.target_index = isym.n_scnum;
960
961
1.27M
      void **slot
962
1.27M
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
963
1.27M
      if (slot == NULL)
964
0
  return false;
965
966
1.27M
      if (*slot == NULL)
967
423k
  {
968
423k
    if (isym.n_numaux != 1)
969
367k
      aux.x_scn.x_comdat = 0;
970
56.4k
    else
971
56.4k
      {
972
        /* PR 17512: file: e2cfe54f.  */
973
56.4k
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
974
821
    {
975
      /* xgettext:c-format */
976
821
      _bfd_error_handler (_("%pB: warning: no symbol for"
977
821
          " section '%s' found"),
978
821
              abfd, symname);
979
821
      continue;
980
821
    }
981
55.5k
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
982
55.5k
            isym.n_type, isym.n_sclass, 0,
983
55.5k
            isym.n_numaux, &aux);
984
55.5k
      }
985
986
    /* FIXME: Microsoft uses NODUPLICATES and ASSOCIATIVE, but
987
       gnu uses ANY and SAME_SIZE.  Unfortunately, gnu doesn't
988
       do the comdat symbols right.  So, until we can fix it to
989
       do the right thing, we are temporarily disabling comdats
990
       for the MS types (they're used in DLLs and C++, but we
991
       don't support *their* C++ libraries anyway - DJ.  */
992
993
    /* Cygwin does not follow the MS style, and uses ANY and
994
       SAME_SIZE where NODUPLICATES and ASSOCIATIVE should be
995
       used.  For Interix, we just do the right thing up
996
       front.  */
997
998
423k
    switch (aux.x_scn.x_comdat)
999
423k
      {
1000
2.71k
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1001
#ifdef STRICT_PE_FORMAT
1002
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1003
#else
1004
2.71k
        sec_flags &= ~SEC_LINK_ONCE;
1005
2.71k
#endif
1006
2.71k
        break;
1007
1008
124
      case IMAGE_COMDAT_SELECT_ANY:
1009
124
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1010
124
        break;
1011
1012
412
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1013
412
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1014
412
        break;
1015
1016
1.49k
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1017
        /* Not yet fully implemented ??? */
1018
1.49k
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1019
1.49k
        break;
1020
1021
        /* debug$S gets this case; other implications ???  */
1022
1023
        /* There may be no symbol.  We'll search the whole
1024
     table.  Is this the right place to play this game?
1025
     Or should we do it when reading it in?  */
1026
752
      case IMAGE_COMDAT_SELECT_ASSOCIATIVE:
1027
#ifdef STRICT_PE_FORMAT
1028
        /* FIXME: This is not currently implemented.  */
1029
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1030
#else
1031
752
        sec_flags &= ~SEC_LINK_ONCE;
1032
752
#endif
1033
752
        break;
1034
1035
417k
      default:  /* 0 means "no symbol" */
1036
        /* debug$F gets this case; other implications ???  */
1037
417k
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1038
417k
        break;
1039
423k
      }
1040
1041
423k
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1042
423k
    if (*slot == NULL)
1043
0
      return false;
1044
423k
    struct comdat_hash_entry *newentry = *slot;
1045
423k
    newentry->sec_flags = sec_flags;
1046
423k
    newentry->symname = bfd_strdup (symname);
1047
423k
    newentry->target_index = isym.n_scnum;
1048
423k
    newentry->isym = isym;
1049
423k
    newentry->comdat_symbol = -1;
1050
423k
  }
1051
853k
      else
1052
853k
  {
1053
853k
    struct comdat_hash_entry *entry = *slot;
1054
1055
853k
    if (entry->comdat_symbol != -1)
1056
743k
      continue;
1057
1058
109k
    char *target_name = strchr (entry->symname, '$');
1059
109k
    if (target_name != NULL)
1060
32.9k
      {
1061
        /* Gas mode: the first matching on partial name.  */
1062
1063
32.9k
        target_name += 1;
1064
#ifndef TARGET_UNDERSCORE
1065
#define TARGET_UNDERSCORE 0
1066
#endif
1067
        /* Is this the name we're looking for ?  */
1068
32.9k
        if (strcmp (target_name,
1069
32.9k
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1070
28.4k
    {
1071
      /* Not the name we're looking for */
1072
28.4k
      continue;
1073
28.4k
    }
1074
32.9k
      }
1075
    /* MSVC mode: the lexically second symbol (or drop through
1076
       from the above).  */
1077
    /* This must the second symbol with the section #.  It is
1078
       the actual symbol name.  Intel puts the two adjacent, but
1079
       Alpha (at least) spreads them out.  */
1080
1081
81.4k
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1082
81.4k
    entry->comdat_name = bfd_strdup (symname);
1083
81.4k
  }
1084
1.27M
    }
1085
1086
49.6k
  return true;
1087
49.6k
}
pei-loongarch64.c:fill_comdat_hash
Line
Count
Source
891
66.0k
{
892
66.0k
  bfd_byte *esymstart, *esym, *esymend;
893
894
  /* Unfortunately, the PE format stores essential information in the
895
     symbol table, of all places.  We need to extract that information
896
     now, so that objdump and the linker will know how to handle the
897
     section without worrying about the symbols.  We can't call
898
     slurp_symtab, because the linker doesn't want the swapped symbols.  */
899
900
  /* COMDAT sections are special.  The first symbol is the section
901
     symbol, which tells what kind of COMDAT section it is.  The
902
     second symbol is the "comdat symbol" - the one with the unique
903
     name.  GNU uses the section symbol for the unique name; MS uses
904
     ".text" for every comdat section.  Sigh.  - DJ.  */
905
906
  /* This is not mirrored in sec_to_styp_flags(), but there doesn't
907
     seem to be a need to, either, and it would at best be rather messy.  */
908
909
66.0k
  if (! _bfd_coff_get_external_symbols (abfd))
910
24.1k
    return true;
911
912
41.9k
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
913
41.9k
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
914
915
41.9k
  for (struct internal_syment isym;
916
676k
       esym < esymend;
917
634k
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
918
634k
    {
919
634k
      char buf[SYMNMLEN + 1];
920
634k
      const char *symname;
921
634k
      flagword sec_flags = SEC_LINK_ONCE;
922
923
634k
      bfd_coff_swap_sym_in (abfd, esym, &isym);
924
925
      /* According to the MSVC documentation, the first TWO entries
926
   with the section # are both of interest to us.  The first one
927
   is the "section symbol" (section name).  The second is the
928
   comdat symbol name.  Here, we've found the first qualifying
929
   entry; we distinguish it from the second with a state flag.
930
931
   In the case of gas-generated (at least until that is fixed)
932
   .o files, it isn't necessarily the second one.  It may be
933
   some other later symbol.
934
935
   Since gas also doesn't follow MS conventions and emits the
936
   section similar to .text$<name>, where <something> is the
937
   name we're looking for, we distinguish the two as follows:
938
939
   If the section name is simply a section name (no $) we
940
   presume it's MS-generated, and look at precisely the second
941
   symbol for the comdat name.  If the section name has a $, we
942
   assume it's gas-generated, and look for <something> (whatever
943
   follows the $) as the comdat symbol.  */
944
945
      /* All 3 branches use this.  */
946
634k
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
947
948
      /* PR 17512 file: 078-11867-0.004  */
949
634k
      if (symname == NULL)
950
192k
  {
951
192k
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
952
192k
            abfd);
953
192k
    continue;
954
192k
  }
955
956
441k
      union internal_auxent aux;
957
958
441k
      struct comdat_hash_entry needle;
959
441k
      needle.target_index = isym.n_scnum;
960
961
441k
      void **slot
962
441k
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
963
441k
      if (slot == NULL)
964
0
  return false;
965
966
441k
      if (*slot == NULL)
967
186k
  {
968
186k
    if (isym.n_numaux != 1)
969
156k
      aux.x_scn.x_comdat = 0;
970
29.6k
    else
971
29.6k
      {
972
        /* PR 17512: file: e2cfe54f.  */
973
29.6k
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
974
1.19k
    {
975
      /* xgettext:c-format */
976
1.19k
      _bfd_error_handler (_("%pB: warning: no symbol for"
977
1.19k
          " section '%s' found"),
978
1.19k
              abfd, symname);
979
1.19k
      continue;
980
1.19k
    }
981
28.4k
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
982
28.4k
            isym.n_type, isym.n_sclass, 0,
983
28.4k
            isym.n_numaux, &aux);
984
28.4k
      }
985
986
    /* FIXME: Microsoft uses NODUPLICATES and ASSOCIATIVE, but
987
       gnu uses ANY and SAME_SIZE.  Unfortunately, gnu doesn't
988
       do the comdat symbols right.  So, until we can fix it to
989
       do the right thing, we are temporarily disabling comdats
990
       for the MS types (they're used in DLLs and C++, but we
991
       don't support *their* C++ libraries anyway - DJ.  */
992
993
    /* Cygwin does not follow the MS style, and uses ANY and
994
       SAME_SIZE where NODUPLICATES and ASSOCIATIVE should be
995
       used.  For Interix, we just do the right thing up
996
       front.  */
997
998
185k
    switch (aux.x_scn.x_comdat)
999
185k
      {
1000
1.61k
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1001
#ifdef STRICT_PE_FORMAT
1002
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1003
#else
1004
1.61k
        sec_flags &= ~SEC_LINK_ONCE;
1005
1.61k
#endif
1006
1.61k
        break;
1007
1008
248
      case IMAGE_COMDAT_SELECT_ANY:
1009
248
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1010
248
        break;
1011
1012
16
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1013
16
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1014
16
        break;
1015
1016
174
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1017
        /* Not yet fully implemented ??? */
1018
174
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1019
174
        break;
1020
1021
        /* debug$S gets this case; other implications ???  */
1022
1023
        /* There may be no symbol.  We'll search the whole
1024
     table.  Is this the right place to play this game?
1025
     Or should we do it when reading it in?  */
1026
707
      case IMAGE_COMDAT_SELECT_ASSOCIATIVE:
1027
#ifdef STRICT_PE_FORMAT
1028
        /* FIXME: This is not currently implemented.  */
1029
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1030
#else
1031
707
        sec_flags &= ~SEC_LINK_ONCE;
1032
707
#endif
1033
707
        break;
1034
1035
182k
      default:  /* 0 means "no symbol" */
1036
        /* debug$F gets this case; other implications ???  */
1037
182k
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1038
182k
        break;
1039
185k
      }
1040
1041
185k
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1042
185k
    if (*slot == NULL)
1043
0
      return false;
1044
185k
    struct comdat_hash_entry *newentry = *slot;
1045
185k
    newentry->sec_flags = sec_flags;
1046
185k
    newentry->symname = bfd_strdup (symname);
1047
185k
    newentry->target_index = isym.n_scnum;
1048
185k
    newentry->isym = isym;
1049
185k
    newentry->comdat_symbol = -1;
1050
185k
  }
1051
255k
      else
1052
255k
  {
1053
255k
    struct comdat_hash_entry *entry = *slot;
1054
1055
255k
    if (entry->comdat_symbol != -1)
1056
204k
      continue;
1057
1058
50.8k
    char *target_name = strchr (entry->symname, '$');
1059
50.8k
    if (target_name != NULL)
1060
20.2k
      {
1061
        /* Gas mode: the first matching on partial name.  */
1062
1063
20.2k
        target_name += 1;
1064
20.2k
#ifndef TARGET_UNDERSCORE
1065
20.2k
#define TARGET_UNDERSCORE 0
1066
20.2k
#endif
1067
        /* Is this the name we're looking for ?  */
1068
20.2k
        if (strcmp (target_name,
1069
20.2k
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1070
18.9k
    {
1071
      /* Not the name we're looking for */
1072
18.9k
      continue;
1073
18.9k
    }
1074
20.2k
      }
1075
    /* MSVC mode: the lexically second symbol (or drop through
1076
       from the above).  */
1077
    /* This must the second symbol with the section #.  It is
1078
       the actual symbol name.  Intel puts the two adjacent, but
1079
       Alpha (at least) spreads them out.  */
1080
1081
31.8k
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1082
31.8k
    entry->comdat_name = bfd_strdup (symname);
1083
31.8k
  }
1084
441k
    }
1085
1086
41.9k
  return true;
1087
41.9k
}
pei-riscv64.c:fill_comdat_hash
Line
Count
Source
891
59.7k
{
892
59.7k
  bfd_byte *esymstart, *esym, *esymend;
893
894
  /* Unfortunately, the PE format stores essential information in the
895
     symbol table, of all places.  We need to extract that information
896
     now, so that objdump and the linker will know how to handle the
897
     section without worrying about the symbols.  We can't call
898
     slurp_symtab, because the linker doesn't want the swapped symbols.  */
899
900
  /* COMDAT sections are special.  The first symbol is the section
901
     symbol, which tells what kind of COMDAT section it is.  The
902
     second symbol is the "comdat symbol" - the one with the unique
903
     name.  GNU uses the section symbol for the unique name; MS uses
904
     ".text" for every comdat section.  Sigh.  - DJ.  */
905
906
  /* This is not mirrored in sec_to_styp_flags(), but there doesn't
907
     seem to be a need to, either, and it would at best be rather messy.  */
908
909
59.7k
  if (! _bfd_coff_get_external_symbols (abfd))
910
20.8k
    return true;
911
912
38.9k
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
913
38.9k
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
914
915
38.9k
  for (struct internal_syment isym;
916
1.25M
       esym < esymend;
917
1.21M
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
918
1.21M
    {
919
1.21M
      char buf[SYMNMLEN + 1];
920
1.21M
      const char *symname;
921
1.21M
      flagword sec_flags = SEC_LINK_ONCE;
922
923
1.21M
      bfd_coff_swap_sym_in (abfd, esym, &isym);
924
925
      /* According to the MSVC documentation, the first TWO entries
926
   with the section # are both of interest to us.  The first one
927
   is the "section symbol" (section name).  The second is the
928
   comdat symbol name.  Here, we've found the first qualifying
929
   entry; we distinguish it from the second with a state flag.
930
931
   In the case of gas-generated (at least until that is fixed)
932
   .o files, it isn't necessarily the second one.  It may be
933
   some other later symbol.
934
935
   Since gas also doesn't follow MS conventions and emits the
936
   section similar to .text$<name>, where <something> is the
937
   name we're looking for, we distinguish the two as follows:
938
939
   If the section name is simply a section name (no $) we
940
   presume it's MS-generated, and look at precisely the second
941
   symbol for the comdat name.  If the section name has a $, we
942
   assume it's gas-generated, and look for <something> (whatever
943
   follows the $) as the comdat symbol.  */
944
945
      /* All 3 branches use this.  */
946
1.21M
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
947
948
      /* PR 17512 file: 078-11867-0.004  */
949
1.21M
      if (symname == NULL)
950
345k
  {
951
345k
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
952
345k
            abfd);
953
345k
    continue;
954
345k
  }
955
956
866k
      union internal_auxent aux;
957
958
866k
      struct comdat_hash_entry needle;
959
866k
      needle.target_index = isym.n_scnum;
960
961
866k
      void **slot
962
866k
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
963
866k
      if (slot == NULL)
964
0
  return false;
965
966
866k
      if (*slot == NULL)
967
281k
  {
968
281k
    if (isym.n_numaux != 1)
969
243k
      aux.x_scn.x_comdat = 0;
970
37.7k
    else
971
37.7k
      {
972
        /* PR 17512: file: e2cfe54f.  */
973
37.7k
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
974
1.02k
    {
975
      /* xgettext:c-format */
976
1.02k
      _bfd_error_handler (_("%pB: warning: no symbol for"
977
1.02k
          " section '%s' found"),
978
1.02k
              abfd, symname);
979
1.02k
      continue;
980
1.02k
    }
981
36.7k
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
982
36.7k
            isym.n_type, isym.n_sclass, 0,
983
36.7k
            isym.n_numaux, &aux);
984
36.7k
      }
985
986
    /* FIXME: Microsoft uses NODUPLICATES and ASSOCIATIVE, but
987
       gnu uses ANY and SAME_SIZE.  Unfortunately, gnu doesn't
988
       do the comdat symbols right.  So, until we can fix it to
989
       do the right thing, we are temporarily disabling comdats
990
       for the MS types (they're used in DLLs and C++, but we
991
       don't support *their* C++ libraries anyway - DJ.  */
992
993
    /* Cygwin does not follow the MS style, and uses ANY and
994
       SAME_SIZE where NODUPLICATES and ASSOCIATIVE should be
995
       used.  For Interix, we just do the right thing up
996
       front.  */
997
998
280k
    switch (aux.x_scn.x_comdat)
999
280k
      {
1000
2.84k
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1001
#ifdef STRICT_PE_FORMAT
1002
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1003
#else
1004
2.84k
        sec_flags &= ~SEC_LINK_ONCE;
1005
2.84k
#endif
1006
2.84k
        break;
1007
1008
27
      case IMAGE_COMDAT_SELECT_ANY:
1009
27
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1010
27
        break;
1011
1012
12
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1013
12
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1014
12
        break;
1015
1016
1.28k
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1017
        /* Not yet fully implemented ??? */
1018
1.28k
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1019
1.28k
        break;
1020
1021
        /* debug$S gets this case; other implications ???  */
1022
1023
        /* There may be no symbol.  We'll search the whole
1024
     table.  Is this the right place to play this game?
1025
     Or should we do it when reading it in?  */
1026
298
      case IMAGE_COMDAT_SELECT_ASSOCIATIVE:
1027
#ifdef STRICT_PE_FORMAT
1028
        /* FIXME: This is not currently implemented.  */
1029
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1030
#else
1031
298
        sec_flags &= ~SEC_LINK_ONCE;
1032
298
#endif
1033
298
        break;
1034
1035
276k
      default:  /* 0 means "no symbol" */
1036
        /* debug$F gets this case; other implications ???  */
1037
276k
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1038
276k
        break;
1039
280k
      }
1040
1041
280k
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1042
280k
    if (*slot == NULL)
1043
0
      return false;
1044
280k
    struct comdat_hash_entry *newentry = *slot;
1045
280k
    newentry->sec_flags = sec_flags;
1046
280k
    newentry->symname = bfd_strdup (symname);
1047
280k
    newentry->target_index = isym.n_scnum;
1048
280k
    newentry->isym = isym;
1049
280k
    newentry->comdat_symbol = -1;
1050
280k
  }
1051
584k
      else
1052
584k
  {
1053
584k
    struct comdat_hash_entry *entry = *slot;
1054
1055
584k
    if (entry->comdat_symbol != -1)
1056
519k
      continue;
1057
1058
65.5k
    char *target_name = strchr (entry->symname, '$');
1059
65.5k
    if (target_name != NULL)
1060
18.2k
      {
1061
        /* Gas mode: the first matching on partial name.  */
1062
1063
18.2k
        target_name += 1;
1064
18.2k
#ifndef TARGET_UNDERSCORE
1065
18.2k
#define TARGET_UNDERSCORE 0
1066
18.2k
#endif
1067
        /* Is this the name we're looking for ?  */
1068
18.2k
        if (strcmp (target_name,
1069
18.2k
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1070
17.2k
    {
1071
      /* Not the name we're looking for */
1072
17.2k
      continue;
1073
17.2k
    }
1074
18.2k
      }
1075
    /* MSVC mode: the lexically second symbol (or drop through
1076
       from the above).  */
1077
    /* This must the second symbol with the section #.  It is
1078
       the actual symbol name.  Intel puts the two adjacent, but
1079
       Alpha (at least) spreads them out.  */
1080
1081
48.3k
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1082
48.3k
    entry->comdat_name = bfd_strdup (symname);
1083
48.3k
  }
1084
866k
    }
1085
1086
38.9k
  return true;
1087
38.9k
}
pe-arm-wince.c:fill_comdat_hash
Line
Count
Source
891
27.5k
{
892
27.5k
  bfd_byte *esymstart, *esym, *esymend;
893
894
  /* Unfortunately, the PE format stores essential information in the
895
     symbol table, of all places.  We need to extract that information
896
     now, so that objdump and the linker will know how to handle the
897
     section without worrying about the symbols.  We can't call
898
     slurp_symtab, because the linker doesn't want the swapped symbols.  */
899
900
  /* COMDAT sections are special.  The first symbol is the section
901
     symbol, which tells what kind of COMDAT section it is.  The
902
     second symbol is the "comdat symbol" - the one with the unique
903
     name.  GNU uses the section symbol for the unique name; MS uses
904
     ".text" for every comdat section.  Sigh.  - DJ.  */
905
906
  /* This is not mirrored in sec_to_styp_flags(), but there doesn't
907
     seem to be a need to, either, and it would at best be rather messy.  */
908
909
27.5k
  if (! _bfd_coff_get_external_symbols (abfd))
910
10.8k
    return true;
911
912
16.6k
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
913
16.6k
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
914
915
16.6k
  for (struct internal_syment isym;
916
574k
       esym < esymend;
917
557k
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
918
557k
    {
919
557k
      char buf[SYMNMLEN + 1];
920
557k
      const char *symname;
921
557k
      flagword sec_flags = SEC_LINK_ONCE;
922
923
557k
      bfd_coff_swap_sym_in (abfd, esym, &isym);
924
925
      /* According to the MSVC documentation, the first TWO entries
926
   with the section # are both of interest to us.  The first one
927
   is the "section symbol" (section name).  The second is the
928
   comdat symbol name.  Here, we've found the first qualifying
929
   entry; we distinguish it from the second with a state flag.
930
931
   In the case of gas-generated (at least until that is fixed)
932
   .o files, it isn't necessarily the second one.  It may be
933
   some other later symbol.
934
935
   Since gas also doesn't follow MS conventions and emits the
936
   section similar to .text$<name>, where <something> is the
937
   name we're looking for, we distinguish the two as follows:
938
939
   If the section name is simply a section name (no $) we
940
   presume it's MS-generated, and look at precisely the second
941
   symbol for the comdat name.  If the section name has a $, we
942
   assume it's gas-generated, and look for <something> (whatever
943
   follows the $) as the comdat symbol.  */
944
945
      /* All 3 branches use this.  */
946
557k
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
947
948
      /* PR 17512 file: 078-11867-0.004  */
949
557k
      if (symname == NULL)
950
152k
  {
951
152k
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
952
152k
            abfd);
953
152k
    continue;
954
152k
  }
955
956
405k
      union internal_auxent aux;
957
958
405k
      struct comdat_hash_entry needle;
959
405k
      needle.target_index = isym.n_scnum;
960
961
405k
      void **slot
962
405k
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
963
405k
      if (slot == NULL)
964
0
  return false;
965
966
405k
      if (*slot == NULL)
967
151k
  {
968
151k
    if (isym.n_numaux != 1)
969
130k
      aux.x_scn.x_comdat = 0;
970
20.9k
    else
971
20.9k
      {
972
        /* PR 17512: file: e2cfe54f.  */
973
20.9k
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
974
418
    {
975
      /* xgettext:c-format */
976
418
      _bfd_error_handler (_("%pB: warning: no symbol for"
977
418
          " section '%s' found"),
978
418
              abfd, symname);
979
418
      continue;
980
418
    }
981
20.5k
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
982
20.5k
            isym.n_type, isym.n_sclass, 0,
983
20.5k
            isym.n_numaux, &aux);
984
20.5k
      }
985
986
    /* FIXME: Microsoft uses NODUPLICATES and ASSOCIATIVE, but
987
       gnu uses ANY and SAME_SIZE.  Unfortunately, gnu doesn't
988
       do the comdat symbols right.  So, until we can fix it to
989
       do the right thing, we are temporarily disabling comdats
990
       for the MS types (they're used in DLLs and C++, but we
991
       don't support *their* C++ libraries anyway - DJ.  */
992
993
    /* Cygwin does not follow the MS style, and uses ANY and
994
       SAME_SIZE where NODUPLICATES and ASSOCIATIVE should be
995
       used.  For Interix, we just do the right thing up
996
       front.  */
997
998
150k
    switch (aux.x_scn.x_comdat)
999
150k
      {
1000
580
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1001
#ifdef STRICT_PE_FORMAT
1002
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1003
#else
1004
580
        sec_flags &= ~SEC_LINK_ONCE;
1005
580
#endif
1006
580
        break;
1007
1008
3
      case IMAGE_COMDAT_SELECT_ANY:
1009
3
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1010
3
        break;
1011
1012
4
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1013
4
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1014
4
        break;
1015
1016
438
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1017
        /* Not yet fully implemented ??? */
1018
438
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1019
438
        break;
1020
1021
        /* debug$S gets this case; other implications ???  */
1022
1023
        /* There may be no symbol.  We'll search the whole
1024
     table.  Is this the right place to play this game?
1025
     Or should we do it when reading it in?  */
1026
2
      case IMAGE_COMDAT_SELECT_ASSOCIATIVE:
1027
#ifdef STRICT_PE_FORMAT
1028
        /* FIXME: This is not currently implemented.  */
1029
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1030
#else
1031
2
        sec_flags &= ~SEC_LINK_ONCE;
1032
2
#endif
1033
2
        break;
1034
1035
149k
      default:  /* 0 means "no symbol" */
1036
        /* debug$F gets this case; other implications ???  */
1037
149k
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1038
149k
        break;
1039
150k
      }
1040
1041
150k
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1042
150k
    if (*slot == NULL)
1043
0
      return false;
1044
150k
    struct comdat_hash_entry *newentry = *slot;
1045
150k
    newentry->sec_flags = sec_flags;
1046
150k
    newentry->symname = bfd_strdup (symname);
1047
150k
    newentry->target_index = isym.n_scnum;
1048
150k
    newentry->isym = isym;
1049
150k
    newentry->comdat_symbol = -1;
1050
150k
  }
1051
254k
      else
1052
254k
  {
1053
254k
    struct comdat_hash_entry *entry = *slot;
1054
1055
254k
    if (entry->comdat_symbol != -1)
1056
217k
      continue;
1057
1058
36.6k
    char *target_name = strchr (entry->symname, '$');
1059
36.6k
    if (target_name != NULL)
1060
11.4k
      {
1061
        /* Gas mode: the first matching on partial name.  */
1062
1063
11.4k
        target_name += 1;
1064
#ifndef TARGET_UNDERSCORE
1065
#define TARGET_UNDERSCORE 0
1066
#endif
1067
        /* Is this the name we're looking for ?  */
1068
11.4k
        if (strcmp (target_name,
1069
11.4k
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1070
10.6k
    {
1071
      /* Not the name we're looking for */
1072
10.6k
      continue;
1073
10.6k
    }
1074
11.4k
      }
1075
    /* MSVC mode: the lexically second symbol (or drop through
1076
       from the above).  */
1077
    /* This must the second symbol with the section #.  It is
1078
       the actual symbol name.  Intel puts the two adjacent, but
1079
       Alpha (at least) spreads them out.  */
1080
1081
25.9k
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1082
25.9k
    entry->comdat_name = bfd_strdup (symname);
1083
25.9k
  }
1084
405k
    }
1085
1086
16.6k
  return true;
1087
16.6k
}
pe-arm.c:fill_comdat_hash
Line
Count
Source
891
27.5k
{
892
27.5k
  bfd_byte *esymstart, *esym, *esymend;
893
894
  /* Unfortunately, the PE format stores essential information in the
895
     symbol table, of all places.  We need to extract that information
896
     now, so that objdump and the linker will know how to handle the
897
     section without worrying about the symbols.  We can't call
898
     slurp_symtab, because the linker doesn't want the swapped symbols.  */
899
900
  /* COMDAT sections are special.  The first symbol is the section
901
     symbol, which tells what kind of COMDAT section it is.  The
902
     second symbol is the "comdat symbol" - the one with the unique
903
     name.  GNU uses the section symbol for the unique name; MS uses
904
     ".text" for every comdat section.  Sigh.  - DJ.  */
905
906
  /* This is not mirrored in sec_to_styp_flags(), but there doesn't
907
     seem to be a need to, either, and it would at best be rather messy.  */
908
909
27.5k
  if (! _bfd_coff_get_external_symbols (abfd))
910
10.8k
    return true;
911
912
16.6k
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
913
16.6k
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
914
915
16.6k
  for (struct internal_syment isym;
916
574k
       esym < esymend;
917
557k
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
918
557k
    {
919
557k
      char buf[SYMNMLEN + 1];
920
557k
      const char *symname;
921
557k
      flagword sec_flags = SEC_LINK_ONCE;
922
923
557k
      bfd_coff_swap_sym_in (abfd, esym, &isym);
924
925
      /* According to the MSVC documentation, the first TWO entries
926
   with the section # are both of interest to us.  The first one
927
   is the "section symbol" (section name).  The second is the
928
   comdat symbol name.  Here, we've found the first qualifying
929
   entry; we distinguish it from the second with a state flag.
930
931
   In the case of gas-generated (at least until that is fixed)
932
   .o files, it isn't necessarily the second one.  It may be
933
   some other later symbol.
934
935
   Since gas also doesn't follow MS conventions and emits the
936
   section similar to .text$<name>, where <something> is the
937
   name we're looking for, we distinguish the two as follows:
938
939
   If the section name is simply a section name (no $) we
940
   presume it's MS-generated, and look at precisely the second
941
   symbol for the comdat name.  If the section name has a $, we
942
   assume it's gas-generated, and look for <something> (whatever
943
   follows the $) as the comdat symbol.  */
944
945
      /* All 3 branches use this.  */
946
557k
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
947
948
      /* PR 17512 file: 078-11867-0.004  */
949
557k
      if (symname == NULL)
950
152k
  {
951
152k
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
952
152k
            abfd);
953
152k
    continue;
954
152k
  }
955
956
405k
      union internal_auxent aux;
957
958
405k
      struct comdat_hash_entry needle;
959
405k
      needle.target_index = isym.n_scnum;
960
961
405k
      void **slot
962
405k
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
963
405k
      if (slot == NULL)
964
0
  return false;
965
966
405k
      if (*slot == NULL)
967
151k
  {
968
151k
    if (isym.n_numaux != 1)
969
130k
      aux.x_scn.x_comdat = 0;
970
20.9k
    else
971
20.9k
      {
972
        /* PR 17512: file: e2cfe54f.  */
973
20.9k
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
974
418
    {
975
      /* xgettext:c-format */
976
418
      _bfd_error_handler (_("%pB: warning: no symbol for"
977
418
          " section '%s' found"),
978
418
              abfd, symname);
979
418
      continue;
980
418
    }
981
20.5k
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
982
20.5k
            isym.n_type, isym.n_sclass, 0,
983
20.5k
            isym.n_numaux, &aux);
984
20.5k
      }
985
986
    /* FIXME: Microsoft uses NODUPLICATES and ASSOCIATIVE, but
987
       gnu uses ANY and SAME_SIZE.  Unfortunately, gnu doesn't
988
       do the comdat symbols right.  So, until we can fix it to
989
       do the right thing, we are temporarily disabling comdats
990
       for the MS types (they're used in DLLs and C++, but we
991
       don't support *their* C++ libraries anyway - DJ.  */
992
993
    /* Cygwin does not follow the MS style, and uses ANY and
994
       SAME_SIZE where NODUPLICATES and ASSOCIATIVE should be
995
       used.  For Interix, we just do the right thing up
996
       front.  */
997
998
150k
    switch (aux.x_scn.x_comdat)
999
150k
      {
1000
580
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1001
#ifdef STRICT_PE_FORMAT
1002
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1003
#else
1004
580
        sec_flags &= ~SEC_LINK_ONCE;
1005
580
#endif
1006
580
        break;
1007
1008
3
      case IMAGE_COMDAT_SELECT_ANY:
1009
3
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1010
3
        break;
1011
1012
4
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1013
4
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1014
4
        break;
1015
1016
438
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1017
        /* Not yet fully implemented ??? */
1018
438
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1019
438
        break;
1020
1021
        /* debug$S gets this case; other implications ???  */
1022
1023
        /* There may be no symbol.  We'll search the whole
1024
     table.  Is this the right place to play this game?
1025
     Or should we do it when reading it in?  */
1026
2
      case IMAGE_COMDAT_SELECT_ASSOCIATIVE:
1027
#ifdef STRICT_PE_FORMAT
1028
        /* FIXME: This is not currently implemented.  */
1029
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1030
#else
1031
2
        sec_flags &= ~SEC_LINK_ONCE;
1032
2
#endif
1033
2
        break;
1034
1035
149k
      default:  /* 0 means "no symbol" */
1036
        /* debug$F gets this case; other implications ???  */
1037
149k
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1038
149k
        break;
1039
150k
      }
1040
1041
150k
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1042
150k
    if (*slot == NULL)
1043
0
      return false;
1044
150k
    struct comdat_hash_entry *newentry = *slot;
1045
150k
    newentry->sec_flags = sec_flags;
1046
150k
    newentry->symname = bfd_strdup (symname);
1047
150k
    newentry->target_index = isym.n_scnum;
1048
150k
    newentry->isym = isym;
1049
150k
    newentry->comdat_symbol = -1;
1050
150k
  }
1051
254k
      else
1052
254k
  {
1053
254k
    struct comdat_hash_entry *entry = *slot;
1054
1055
254k
    if (entry->comdat_symbol != -1)
1056
219k
      continue;
1057
1058
34.7k
    char *target_name = strchr (entry->symname, '$');
1059
34.7k
    if (target_name != NULL)
1060
9.50k
      {
1061
        /* Gas mode: the first matching on partial name.  */
1062
1063
9.50k
        target_name += 1;
1064
#ifndef TARGET_UNDERSCORE
1065
#define TARGET_UNDERSCORE 0
1066
#endif
1067
        /* Is this the name we're looking for ?  */
1068
9.50k
        if (strcmp (target_name,
1069
9.50k
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1070
7.86k
    {
1071
      /* Not the name we're looking for */
1072
7.86k
      continue;
1073
7.86k
    }
1074
9.50k
      }
1075
    /* MSVC mode: the lexically second symbol (or drop through
1076
       from the above).  */
1077
    /* This must the second symbol with the section #.  It is
1078
       the actual symbol name.  Intel puts the two adjacent, but
1079
       Alpha (at least) spreads them out.  */
1080
1081
26.8k
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1082
26.8k
    entry->comdat_name = bfd_strdup (symname);
1083
26.8k
  }
1084
405k
    }
1085
1086
16.6k
  return true;
1087
16.6k
}
pe-i386.c:fill_comdat_hash
Line
Count
Source
891
54.7k
{
892
54.7k
  bfd_byte *esymstart, *esym, *esymend;
893
894
  /* Unfortunately, the PE format stores essential information in the
895
     symbol table, of all places.  We need to extract that information
896
     now, so that objdump and the linker will know how to handle the
897
     section without worrying about the symbols.  We can't call
898
     slurp_symtab, because the linker doesn't want the swapped symbols.  */
899
900
  /* COMDAT sections are special.  The first symbol is the section
901
     symbol, which tells what kind of COMDAT section it is.  The
902
     second symbol is the "comdat symbol" - the one with the unique
903
     name.  GNU uses the section symbol for the unique name; MS uses
904
     ".text" for every comdat section.  Sigh.  - DJ.  */
905
906
  /* This is not mirrored in sec_to_styp_flags(), but there doesn't
907
     seem to be a need to, either, and it would at best be rather messy.  */
908
909
54.7k
  if (! _bfd_coff_get_external_symbols (abfd))
910
22.9k
    return true;
911
912
31.8k
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
913
31.8k
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
914
915
31.8k
  for (struct internal_syment isym;
916
725k
       esym < esymend;
917
693k
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
918
693k
    {
919
693k
      char buf[SYMNMLEN + 1];
920
693k
      const char *symname;
921
693k
      flagword sec_flags = SEC_LINK_ONCE;
922
923
693k
      bfd_coff_swap_sym_in (abfd, esym, &isym);
924
925
      /* According to the MSVC documentation, the first TWO entries
926
   with the section # are both of interest to us.  The first one
927
   is the "section symbol" (section name).  The second is the
928
   comdat symbol name.  Here, we've found the first qualifying
929
   entry; we distinguish it from the second with a state flag.
930
931
   In the case of gas-generated (at least until that is fixed)
932
   .o files, it isn't necessarily the second one.  It may be
933
   some other later symbol.
934
935
   Since gas also doesn't follow MS conventions and emits the
936
   section similar to .text$<name>, where <something> is the
937
   name we're looking for, we distinguish the two as follows:
938
939
   If the section name is simply a section name (no $) we
940
   presume it's MS-generated, and look at precisely the second
941
   symbol for the comdat name.  If the section name has a $, we
942
   assume it's gas-generated, and look for <something> (whatever
943
   follows the $) as the comdat symbol.  */
944
945
      /* All 3 branches use this.  */
946
693k
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
947
948
      /* PR 17512 file: 078-11867-0.004  */
949
693k
      if (symname == NULL)
950
232k
  {
951
232k
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
952
232k
            abfd);
953
232k
    continue;
954
232k
  }
955
956
461k
      union internal_auxent aux;
957
958
461k
      struct comdat_hash_entry needle;
959
461k
      needle.target_index = isym.n_scnum;
960
961
461k
      void **slot
962
461k
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
963
461k
      if (slot == NULL)
964
0
  return false;
965
966
461k
      if (*slot == NULL)
967
152k
  {
968
152k
    if (isym.n_numaux != 1)
969
133k
      aux.x_scn.x_comdat = 0;
970
19.4k
    else
971
19.4k
      {
972
        /* PR 17512: file: e2cfe54f.  */
973
19.4k
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
974
658
    {
975
      /* xgettext:c-format */
976
658
      _bfd_error_handler (_("%pB: warning: no symbol for"
977
658
          " section '%s' found"),
978
658
              abfd, symname);
979
658
      continue;
980
658
    }
981
18.7k
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
982
18.7k
            isym.n_type, isym.n_sclass, 0,
983
18.7k
            isym.n_numaux, &aux);
984
18.7k
      }
985
986
    /* FIXME: Microsoft uses NODUPLICATES and ASSOCIATIVE, but
987
       gnu uses ANY and SAME_SIZE.  Unfortunately, gnu doesn't
988
       do the comdat symbols right.  So, until we can fix it to
989
       do the right thing, we are temporarily disabling comdats
990
       for the MS types (they're used in DLLs and C++, but we
991
       don't support *their* C++ libraries anyway - DJ.  */
992
993
    /* Cygwin does not follow the MS style, and uses ANY and
994
       SAME_SIZE where NODUPLICATES and ASSOCIATIVE should be
995
       used.  For Interix, we just do the right thing up
996
       front.  */
997
998
152k
    switch (aux.x_scn.x_comdat)
999
152k
      {
1000
1.18k
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1001
#ifdef STRICT_PE_FORMAT
1002
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1003
#else
1004
1.18k
        sec_flags &= ~SEC_LINK_ONCE;
1005
1.18k
#endif
1006
1.18k
        break;
1007
1008
11
      case IMAGE_COMDAT_SELECT_ANY:
1009
11
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1010
11
        break;
1011
1012
5
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1013
5
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1014
5
        break;
1015
1016
565
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1017
        /* Not yet fully implemented ??? */
1018
565
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1019
565
        break;
1020
1021
        /* debug$S gets this case; other implications ???  */
1022
1023
        /* There may be no symbol.  We'll search the whole
1024
     table.  Is this the right place to play this game?
1025
     Or should we do it when reading it in?  */
1026
43
      case IMAGE_COMDAT_SELECT_ASSOCIATIVE:
1027
#ifdef STRICT_PE_FORMAT
1028
        /* FIXME: This is not currently implemented.  */
1029
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1030
#else
1031
43
        sec_flags &= ~SEC_LINK_ONCE;
1032
43
#endif
1033
43
        break;
1034
1035
150k
      default:  /* 0 means "no symbol" */
1036
        /* debug$F gets this case; other implications ???  */
1037
150k
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1038
150k
        break;
1039
152k
      }
1040
1041
152k
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1042
152k
    if (*slot == NULL)
1043
0
      return false;
1044
152k
    struct comdat_hash_entry *newentry = *slot;
1045
152k
    newentry->sec_flags = sec_flags;
1046
152k
    newentry->symname = bfd_strdup (symname);
1047
152k
    newentry->target_index = isym.n_scnum;
1048
152k
    newentry->isym = isym;
1049
152k
    newentry->comdat_symbol = -1;
1050
152k
  }
1051
308k
      else
1052
308k
  {
1053
308k
    struct comdat_hash_entry *entry = *slot;
1054
1055
308k
    if (entry->comdat_symbol != -1)
1056
260k
      continue;
1057
1058
48.2k
    char *target_name = strchr (entry->symname, '$');
1059
48.2k
    if (target_name != NULL)
1060
17.0k
      {
1061
        /* Gas mode: the first matching on partial name.  */
1062
1063
17.0k
        target_name += 1;
1064
#ifndef TARGET_UNDERSCORE
1065
#define TARGET_UNDERSCORE 0
1066
#endif
1067
        /* Is this the name we're looking for ?  */
1068
17.0k
        if (strcmp (target_name,
1069
17.0k
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1070
15.3k
    {
1071
      /* Not the name we're looking for */
1072
15.3k
      continue;
1073
15.3k
    }
1074
17.0k
      }
1075
    /* MSVC mode: the lexically second symbol (or drop through
1076
       from the above).  */
1077
    /* This must the second symbol with the section #.  It is
1078
       the actual symbol name.  Intel puts the two adjacent, but
1079
       Alpha (at least) spreads them out.  */
1080
1081
32.8k
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1082
32.8k
    entry->comdat_name = bfd_strdup (symname);
1083
32.8k
  }
1084
461k
    }
1085
1086
31.8k
  return true;
1087
31.8k
}
pe-mcore.c:fill_comdat_hash
Line
Count
Source
891
44.2k
{
892
44.2k
  bfd_byte *esymstart, *esym, *esymend;
893
894
  /* Unfortunately, the PE format stores essential information in the
895
     symbol table, of all places.  We need to extract that information
896
     now, so that objdump and the linker will know how to handle the
897
     section without worrying about the symbols.  We can't call
898
     slurp_symtab, because the linker doesn't want the swapped symbols.  */
899
900
  /* COMDAT sections are special.  The first symbol is the section
901
     symbol, which tells what kind of COMDAT section it is.  The
902
     second symbol is the "comdat symbol" - the one with the unique
903
     name.  GNU uses the section symbol for the unique name; MS uses
904
     ".text" for every comdat section.  Sigh.  - DJ.  */
905
906
  /* This is not mirrored in sec_to_styp_flags(), but there doesn't
907
     seem to be a need to, either, and it would at best be rather messy.  */
908
909
44.2k
  if (! _bfd_coff_get_external_symbols (abfd))
910
13.5k
    return true;
911
912
30.6k
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
913
30.6k
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
914
915
30.6k
  for (struct internal_syment isym;
916
252k
       esym < esymend;
917
221k
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
918
221k
    {
919
221k
      char buf[SYMNMLEN + 1];
920
221k
      const char *symname;
921
221k
      flagword sec_flags = SEC_LINK_ONCE;
922
923
221k
      bfd_coff_swap_sym_in (abfd, esym, &isym);
924
925
      /* According to the MSVC documentation, the first TWO entries
926
   with the section # are both of interest to us.  The first one
927
   is the "section symbol" (section name).  The second is the
928
   comdat symbol name.  Here, we've found the first qualifying
929
   entry; we distinguish it from the second with a state flag.
930
931
   In the case of gas-generated (at least until that is fixed)
932
   .o files, it isn't necessarily the second one.  It may be
933
   some other later symbol.
934
935
   Since gas also doesn't follow MS conventions and emits the
936
   section similar to .text$<name>, where <something> is the
937
   name we're looking for, we distinguish the two as follows:
938
939
   If the section name is simply a section name (no $) we
940
   presume it's MS-generated, and look at precisely the second
941
   symbol for the comdat name.  If the section name has a $, we
942
   assume it's gas-generated, and look for <something> (whatever
943
   follows the $) as the comdat symbol.  */
944
945
      /* All 3 branches use this.  */
946
221k
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
947
948
      /* PR 17512 file: 078-11867-0.004  */
949
221k
      if (symname == NULL)
950
69.6k
  {
951
69.6k
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
952
69.6k
            abfd);
953
69.6k
    continue;
954
69.6k
  }
955
956
151k
      union internal_auxent aux;
957
958
151k
      struct comdat_hash_entry needle;
959
151k
      needle.target_index = isym.n_scnum;
960
961
151k
      void **slot
962
151k
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
963
151k
      if (slot == NULL)
964
0
  return false;
965
966
151k
      if (*slot == NULL)
967
69.3k
  {
968
69.3k
    if (isym.n_numaux != 1)
969
59.1k
      aux.x_scn.x_comdat = 0;
970
10.2k
    else
971
10.2k
      {
972
        /* PR 17512: file: e2cfe54f.  */
973
10.2k
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
974
722
    {
975
      /* xgettext:c-format */
976
722
      _bfd_error_handler (_("%pB: warning: no symbol for"
977
722
          " section '%s' found"),
978
722
              abfd, symname);
979
722
      continue;
980
722
    }
981
9.55k
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
982
9.55k
            isym.n_type, isym.n_sclass, 0,
983
9.55k
            isym.n_numaux, &aux);
984
9.55k
      }
985
986
    /* FIXME: Microsoft uses NODUPLICATES and ASSOCIATIVE, but
987
       gnu uses ANY and SAME_SIZE.  Unfortunately, gnu doesn't
988
       do the comdat symbols right.  So, until we can fix it to
989
       do the right thing, we are temporarily disabling comdats
990
       for the MS types (they're used in DLLs and C++, but we
991
       don't support *their* C++ libraries anyway - DJ.  */
992
993
    /* Cygwin does not follow the MS style, and uses ANY and
994
       SAME_SIZE where NODUPLICATES and ASSOCIATIVE should be
995
       used.  For Interix, we just do the right thing up
996
       front.  */
997
998
68.6k
    switch (aux.x_scn.x_comdat)
999
68.6k
      {
1000
649
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1001
#ifdef STRICT_PE_FORMAT
1002
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1003
#else
1004
649
        sec_flags &= ~SEC_LINK_ONCE;
1005
649
#endif
1006
649
        break;
1007
1008
241
      case IMAGE_COMDAT_SELECT_ANY:
1009
241
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1010
241
        break;
1011
1012
5
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1013
5
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1014
5
        break;
1015
1016
536
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1017
        /* Not yet fully implemented ??? */
1018
536
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1019
536
        break;
1020
1021
        /* debug$S gets this case; other implications ???  */
1022
1023
        /* There may be no symbol.  We'll search the whole
1024
     table.  Is this the right place to play this game?
1025
     Or should we do it when reading it in?  */
1026
0
      case IMAGE_COMDAT_SELECT_ASSOCIATIVE:
1027
#ifdef STRICT_PE_FORMAT
1028
        /* FIXME: This is not currently implemented.  */
1029
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1030
#else
1031
0
        sec_flags &= ~SEC_LINK_ONCE;
1032
0
#endif
1033
0
        break;
1034
1035
67.2k
      default:  /* 0 means "no symbol" */
1036
        /* debug$F gets this case; other implications ???  */
1037
67.2k
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1038
67.2k
        break;
1039
68.6k
      }
1040
1041
68.6k
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1042
68.6k
    if (*slot == NULL)
1043
0
      return false;
1044
68.6k
    struct comdat_hash_entry *newentry = *slot;
1045
68.6k
    newentry->sec_flags = sec_flags;
1046
68.6k
    newentry->symname = bfd_strdup (symname);
1047
68.6k
    newentry->target_index = isym.n_scnum;
1048
68.6k
    newentry->isym = isym;
1049
68.6k
    newentry->comdat_symbol = -1;
1050
68.6k
  }
1051
82.6k
      else
1052
82.6k
  {
1053
82.6k
    struct comdat_hash_entry *entry = *slot;
1054
1055
82.6k
    if (entry->comdat_symbol != -1)
1056
61.0k
      continue;
1057
1058
21.5k
    char *target_name = strchr (entry->symname, '$');
1059
21.5k
    if (target_name != NULL)
1060
7.81k
      {
1061
        /* Gas mode: the first matching on partial name.  */
1062
1063
7.81k
        target_name += 1;
1064
7.81k
#ifndef TARGET_UNDERSCORE
1065
7.81k
#define TARGET_UNDERSCORE 0
1066
7.81k
#endif
1067
        /* Is this the name we're looking for ?  */
1068
7.81k
        if (strcmp (target_name,
1069
7.81k
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1070
7.08k
    {
1071
      /* Not the name we're looking for */
1072
7.08k
      continue;
1073
7.08k
    }
1074
7.81k
      }
1075
    /* MSVC mode: the lexically second symbol (or drop through
1076
       from the above).  */
1077
    /* This must the second symbol with the section #.  It is
1078
       the actual symbol name.  Intel puts the two adjacent, but
1079
       Alpha (at least) spreads them out.  */
1080
1081
14.4k
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1082
14.4k
    entry->comdat_name = bfd_strdup (symname);
1083
14.4k
  }
1084
151k
    }
1085
1086
30.6k
  return true;
1087
30.6k
}
pe-sh.c:fill_comdat_hash
Line
Count
Source
891
44.5k
{
892
44.5k
  bfd_byte *esymstart, *esym, *esymend;
893
894
  /* Unfortunately, the PE format stores essential information in the
895
     symbol table, of all places.  We need to extract that information
896
     now, so that objdump and the linker will know how to handle the
897
     section without worrying about the symbols.  We can't call
898
     slurp_symtab, because the linker doesn't want the swapped symbols.  */
899
900
  /* COMDAT sections are special.  The first symbol is the section
901
     symbol, which tells what kind of COMDAT section it is.  The
902
     second symbol is the "comdat symbol" - the one with the unique
903
     name.  GNU uses the section symbol for the unique name; MS uses
904
     ".text" for every comdat section.  Sigh.  - DJ.  */
905
906
  /* This is not mirrored in sec_to_styp_flags(), but there doesn't
907
     seem to be a need to, either, and it would at best be rather messy.  */
908
909
44.5k
  if (! _bfd_coff_get_external_symbols (abfd))
910
15.4k
    return true;
911
912
29.0k
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
913
29.0k
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
914
915
29.0k
  for (struct internal_syment isym;
916
1.25M
       esym < esymend;
917
1.22M
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
918
1.22M
    {
919
1.22M
      char buf[SYMNMLEN + 1];
920
1.22M
      const char *symname;
921
1.22M
      flagword sec_flags = SEC_LINK_ONCE;
922
923
1.22M
      bfd_coff_swap_sym_in (abfd, esym, &isym);
924
925
      /* According to the MSVC documentation, the first TWO entries
926
   with the section # are both of interest to us.  The first one
927
   is the "section symbol" (section name).  The second is the
928
   comdat symbol name.  Here, we've found the first qualifying
929
   entry; we distinguish it from the second with a state flag.
930
931
   In the case of gas-generated (at least until that is fixed)
932
   .o files, it isn't necessarily the second one.  It may be
933
   some other later symbol.
934
935
   Since gas also doesn't follow MS conventions and emits the
936
   section similar to .text$<name>, where <something> is the
937
   name we're looking for, we distinguish the two as follows:
938
939
   If the section name is simply a section name (no $) we
940
   presume it's MS-generated, and look at precisely the second
941
   symbol for the comdat name.  If the section name has a $, we
942
   assume it's gas-generated, and look for <something> (whatever
943
   follows the $) as the comdat symbol.  */
944
945
      /* All 3 branches use this.  */
946
1.22M
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
947
948
      /* PR 17512 file: 078-11867-0.004  */
949
1.22M
      if (symname == NULL)
950
392k
  {
951
392k
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
952
392k
            abfd);
953
392k
    continue;
954
392k
  }
955
956
830k
      union internal_auxent aux;
957
958
830k
      struct comdat_hash_entry needle;
959
830k
      needle.target_index = isym.n_scnum;
960
961
830k
      void **slot
962
830k
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
963
830k
      if (slot == NULL)
964
0
  return false;
965
966
830k
      if (*slot == NULL)
967
166k
  {
968
166k
    if (isym.n_numaux != 1)
969
153k
      aux.x_scn.x_comdat = 0;
970
13.3k
    else
971
13.3k
      {
972
        /* PR 17512: file: e2cfe54f.  */
973
13.3k
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
974
522
    {
975
      /* xgettext:c-format */
976
522
      _bfd_error_handler (_("%pB: warning: no symbol for"
977
522
          " section '%s' found"),
978
522
              abfd, symname);
979
522
      continue;
980
522
    }
981
12.8k
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
982
12.8k
            isym.n_type, isym.n_sclass, 0,
983
12.8k
            isym.n_numaux, &aux);
984
12.8k
      }
985
986
    /* FIXME: Microsoft uses NODUPLICATES and ASSOCIATIVE, but
987
       gnu uses ANY and SAME_SIZE.  Unfortunately, gnu doesn't
988
       do the comdat symbols right.  So, until we can fix it to
989
       do the right thing, we are temporarily disabling comdats
990
       for the MS types (they're used in DLLs and C++, but we
991
       don't support *their* C++ libraries anyway - DJ.  */
992
993
    /* Cygwin does not follow the MS style, and uses ANY and
994
       SAME_SIZE where NODUPLICATES and ASSOCIATIVE should be
995
       used.  For Interix, we just do the right thing up
996
       front.  */
997
998
166k
    switch (aux.x_scn.x_comdat)
999
166k
      {
1000
862
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1001
#ifdef STRICT_PE_FORMAT
1002
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1003
#else
1004
862
        sec_flags &= ~SEC_LINK_ONCE;
1005
862
#endif
1006
862
        break;
1007
1008
1
      case IMAGE_COMDAT_SELECT_ANY:
1009
1
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1010
1
        break;
1011
1012
8
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1013
8
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1014
8
        break;
1015
1016
646
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1017
        /* Not yet fully implemented ??? */
1018
646
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1019
646
        break;
1020
1021
        /* debug$S gets this case; other implications ???  */
1022
1023
        /* There may be no symbol.  We'll search the whole
1024
     table.  Is this the right place to play this game?
1025
     Or should we do it when reading it in?  */
1026
100
      case IMAGE_COMDAT_SELECT_ASSOCIATIVE:
1027
#ifdef STRICT_PE_FORMAT
1028
        /* FIXME: This is not currently implemented.  */
1029
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1030
#else
1031
100
        sec_flags &= ~SEC_LINK_ONCE;
1032
100
#endif
1033
100
        break;
1034
1035
164k
      default:  /* 0 means "no symbol" */
1036
        /* debug$F gets this case; other implications ???  */
1037
164k
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1038
164k
        break;
1039
166k
      }
1040
1041
166k
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1042
166k
    if (*slot == NULL)
1043
0
      return false;
1044
166k
    struct comdat_hash_entry *newentry = *slot;
1045
166k
    newentry->sec_flags = sec_flags;
1046
166k
    newentry->symname = bfd_strdup (symname);
1047
166k
    newentry->target_index = isym.n_scnum;
1048
166k
    newentry->isym = isym;
1049
166k
    newentry->comdat_symbol = -1;
1050
166k
  }
1051
664k
      else
1052
664k
  {
1053
664k
    struct comdat_hash_entry *entry = *slot;
1054
1055
664k
    if (entry->comdat_symbol != -1)
1056
618k
      continue;
1057
1058
45.2k
    char *target_name = strchr (entry->symname, '$');
1059
45.2k
    if (target_name != NULL)
1060
5.11k
      {
1061
        /* Gas mode: the first matching on partial name.  */
1062
1063
5.11k
        target_name += 1;
1064
#ifndef TARGET_UNDERSCORE
1065
#define TARGET_UNDERSCORE 0
1066
#endif
1067
        /* Is this the name we're looking for ?  */
1068
5.11k
        if (strcmp (target_name,
1069
5.11k
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1070
3.28k
    {
1071
      /* Not the name we're looking for */
1072
3.28k
      continue;
1073
3.28k
    }
1074
5.11k
      }
1075
    /* MSVC mode: the lexically second symbol (or drop through
1076
       from the above).  */
1077
    /* This must the second symbol with the section #.  It is
1078
       the actual symbol name.  Intel puts the two adjacent, but
1079
       Alpha (at least) spreads them out.  */
1080
1081
42.0k
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1082
42.0k
    entry->comdat_name = bfd_strdup (symname);
1083
42.0k
  }
1084
830k
    }
1085
1086
29.0k
  return true;
1087
29.0k
}
pei-arm-wince.c:fill_comdat_hash
Line
Count
Source
891
74.9k
{
892
74.9k
  bfd_byte *esymstart, *esym, *esymend;
893
894
  /* Unfortunately, the PE format stores essential information in the
895
     symbol table, of all places.  We need to extract that information
896
     now, so that objdump and the linker will know how to handle the
897
     section without worrying about the symbols.  We can't call
898
     slurp_symtab, because the linker doesn't want the swapped symbols.  */
899
900
  /* COMDAT sections are special.  The first symbol is the section
901
     symbol, which tells what kind of COMDAT section it is.  The
902
     second symbol is the "comdat symbol" - the one with the unique
903
     name.  GNU uses the section symbol for the unique name; MS uses
904
     ".text" for every comdat section.  Sigh.  - DJ.  */
905
906
  /* This is not mirrored in sec_to_styp_flags(), but there doesn't
907
     seem to be a need to, either, and it would at best be rather messy.  */
908
909
74.9k
  if (! _bfd_coff_get_external_symbols (abfd))
910
28.8k
    return true;
911
912
46.0k
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
913
46.0k
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
914
915
46.0k
  for (struct internal_syment isym;
916
962k
       esym < esymend;
917
916k
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
918
916k
    {
919
916k
      char buf[SYMNMLEN + 1];
920
916k
      const char *symname;
921
916k
      flagword sec_flags = SEC_LINK_ONCE;
922
923
916k
      bfd_coff_swap_sym_in (abfd, esym, &isym);
924
925
      /* According to the MSVC documentation, the first TWO entries
926
   with the section # are both of interest to us.  The first one
927
   is the "section symbol" (section name).  The second is the
928
   comdat symbol name.  Here, we've found the first qualifying
929
   entry; we distinguish it from the second with a state flag.
930
931
   In the case of gas-generated (at least until that is fixed)
932
   .o files, it isn't necessarily the second one.  It may be
933
   some other later symbol.
934
935
   Since gas also doesn't follow MS conventions and emits the
936
   section similar to .text$<name>, where <something> is the
937
   name we're looking for, we distinguish the two as follows:
938
939
   If the section name is simply a section name (no $) we
940
   presume it's MS-generated, and look at precisely the second
941
   symbol for the comdat name.  If the section name has a $, we
942
   assume it's gas-generated, and look for <something> (whatever
943
   follows the $) as the comdat symbol.  */
944
945
      /* All 3 branches use this.  */
946
916k
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
947
948
      /* PR 17512 file: 078-11867-0.004  */
949
916k
      if (symname == NULL)
950
279k
  {
951
279k
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
952
279k
            abfd);
953
279k
    continue;
954
279k
  }
955
956
637k
      union internal_auxent aux;
957
958
637k
      struct comdat_hash_entry needle;
959
637k
      needle.target_index = isym.n_scnum;
960
961
637k
      void **slot
962
637k
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
963
637k
      if (slot == NULL)
964
0
  return false;
965
966
637k
      if (*slot == NULL)
967
236k
  {
968
236k
    if (isym.n_numaux != 1)
969
195k
      aux.x_scn.x_comdat = 0;
970
40.5k
    else
971
40.5k
      {
972
        /* PR 17512: file: e2cfe54f.  */
973
40.5k
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
974
1.41k
    {
975
      /* xgettext:c-format */
976
1.41k
      _bfd_error_handler (_("%pB: warning: no symbol for"
977
1.41k
          " section '%s' found"),
978
1.41k
              abfd, symname);
979
1.41k
      continue;
980
1.41k
    }
981
39.1k
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
982
39.1k
            isym.n_type, isym.n_sclass, 0,
983
39.1k
            isym.n_numaux, &aux);
984
39.1k
      }
985
986
    /* FIXME: Microsoft uses NODUPLICATES and ASSOCIATIVE, but
987
       gnu uses ANY and SAME_SIZE.  Unfortunately, gnu doesn't
988
       do the comdat symbols right.  So, until we can fix it to
989
       do the right thing, we are temporarily disabling comdats
990
       for the MS types (they're used in DLLs and C++, but we
991
       don't support *their* C++ libraries anyway - DJ.  */
992
993
    /* Cygwin does not follow the MS style, and uses ANY and
994
       SAME_SIZE where NODUPLICATES and ASSOCIATIVE should be
995
       used.  For Interix, we just do the right thing up
996
       front.  */
997
998
235k
    switch (aux.x_scn.x_comdat)
999
235k
      {
1000
3.08k
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1001
#ifdef STRICT_PE_FORMAT
1002
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1003
#else
1004
3.08k
        sec_flags &= ~SEC_LINK_ONCE;
1005
3.08k
#endif
1006
3.08k
        break;
1007
1008
33
      case IMAGE_COMDAT_SELECT_ANY:
1009
33
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1010
33
        break;
1011
1012
8
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1013
8
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1014
8
        break;
1015
1016
1.88k
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1017
        /* Not yet fully implemented ??? */
1018
1.88k
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1019
1.88k
        break;
1020
1021
        /* debug$S gets this case; other implications ???  */
1022
1023
        /* There may be no symbol.  We'll search the whole
1024
     table.  Is this the right place to play this game?
1025
     Or should we do it when reading it in?  */
1026
33
      case IMAGE_COMDAT_SELECT_ASSOCIATIVE:
1027
#ifdef STRICT_PE_FORMAT
1028
        /* FIXME: This is not currently implemented.  */
1029
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1030
#else
1031
33
        sec_flags &= ~SEC_LINK_ONCE;
1032
33
#endif
1033
33
        break;
1034
1035
229k
      default:  /* 0 means "no symbol" */
1036
        /* debug$F gets this case; other implications ???  */
1037
229k
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1038
229k
        break;
1039
235k
      }
1040
1041
235k
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1042
235k
    if (*slot == NULL)
1043
0
      return false;
1044
235k
    struct comdat_hash_entry *newentry = *slot;
1045
235k
    newentry->sec_flags = sec_flags;
1046
235k
    newentry->symname = bfd_strdup (symname);
1047
235k
    newentry->target_index = isym.n_scnum;
1048
235k
    newentry->isym = isym;
1049
235k
    newentry->comdat_symbol = -1;
1050
235k
  }
1051
400k
      else
1052
400k
  {
1053
400k
    struct comdat_hash_entry *entry = *slot;
1054
1055
400k
    if (entry->comdat_symbol != -1)
1056
322k
      continue;
1057
1058
78.0k
    char *target_name = strchr (entry->symname, '$');
1059
78.0k
    if (target_name != NULL)
1060
38.1k
      {
1061
        /* Gas mode: the first matching on partial name.  */
1062
1063
38.1k
        target_name += 1;
1064
#ifndef TARGET_UNDERSCORE
1065
#define TARGET_UNDERSCORE 0
1066
#endif
1067
        /* Is this the name we're looking for ?  */
1068
38.1k
        if (strcmp (target_name,
1069
38.1k
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1070
34.2k
    {
1071
      /* Not the name we're looking for */
1072
34.2k
      continue;
1073
34.2k
    }
1074
38.1k
      }
1075
    /* MSVC mode: the lexically second symbol (or drop through
1076
       from the above).  */
1077
    /* This must the second symbol with the section #.  It is
1078
       the actual symbol name.  Intel puts the two adjacent, but
1079
       Alpha (at least) spreads them out.  */
1080
1081
43.8k
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1082
43.8k
    entry->comdat_name = bfd_strdup (symname);
1083
43.8k
  }
1084
637k
    }
1085
1086
46.0k
  return true;
1087
46.0k
}
pei-arm.c:fill_comdat_hash
Line
Count
Source
891
86.8k
{
892
86.8k
  bfd_byte *esymstart, *esym, *esymend;
893
894
  /* Unfortunately, the PE format stores essential information in the
895
     symbol table, of all places.  We need to extract that information
896
     now, so that objdump and the linker will know how to handle the
897
     section without worrying about the symbols.  We can't call
898
     slurp_symtab, because the linker doesn't want the swapped symbols.  */
899
900
  /* COMDAT sections are special.  The first symbol is the section
901
     symbol, which tells what kind of COMDAT section it is.  The
902
     second symbol is the "comdat symbol" - the one with the unique
903
     name.  GNU uses the section symbol for the unique name; MS uses
904
     ".text" for every comdat section.  Sigh.  - DJ.  */
905
906
  /* This is not mirrored in sec_to_styp_flags(), but there doesn't
907
     seem to be a need to, either, and it would at best be rather messy.  */
908
909
86.8k
  if (! _bfd_coff_get_external_symbols (abfd))
910
35.9k
    return true;
911
912
50.8k
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
913
50.8k
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
914
915
50.8k
  for (struct internal_syment isym;
916
1.03M
       esym < esymend;
917
985k
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
918
985k
    {
919
985k
      char buf[SYMNMLEN + 1];
920
985k
      const char *symname;
921
985k
      flagword sec_flags = SEC_LINK_ONCE;
922
923
985k
      bfd_coff_swap_sym_in (abfd, esym, &isym);
924
925
      /* According to the MSVC documentation, the first TWO entries
926
   with the section # are both of interest to us.  The first one
927
   is the "section symbol" (section name).  The second is the
928
   comdat symbol name.  Here, we've found the first qualifying
929
   entry; we distinguish it from the second with a state flag.
930
931
   In the case of gas-generated (at least until that is fixed)
932
   .o files, it isn't necessarily the second one.  It may be
933
   some other later symbol.
934
935
   Since gas also doesn't follow MS conventions and emits the
936
   section similar to .text$<name>, where <something> is the
937
   name we're looking for, we distinguish the two as follows:
938
939
   If the section name is simply a section name (no $) we
940
   presume it's MS-generated, and look at precisely the second
941
   symbol for the comdat name.  If the section name has a $, we
942
   assume it's gas-generated, and look for <something> (whatever
943
   follows the $) as the comdat symbol.  */
944
945
      /* All 3 branches use this.  */
946
985k
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
947
948
      /* PR 17512 file: 078-11867-0.004  */
949
985k
      if (symname == NULL)
950
302k
  {
951
302k
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
952
302k
            abfd);
953
302k
    continue;
954
302k
  }
955
956
683k
      union internal_auxent aux;
957
958
683k
      struct comdat_hash_entry needle;
959
683k
      needle.target_index = isym.n_scnum;
960
961
683k
      void **slot
962
683k
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
963
683k
      if (slot == NULL)
964
0
  return false;
965
966
683k
      if (*slot == NULL)
967
249k
  {
968
249k
    if (isym.n_numaux != 1)
969
206k
      aux.x_scn.x_comdat = 0;
970
43.1k
    else
971
43.1k
      {
972
        /* PR 17512: file: e2cfe54f.  */
973
43.1k
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
974
2.30k
    {
975
      /* xgettext:c-format */
976
2.30k
      _bfd_error_handler (_("%pB: warning: no symbol for"
977
2.30k
          " section '%s' found"),
978
2.30k
              abfd, symname);
979
2.30k
      continue;
980
2.30k
    }
981
40.8k
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
982
40.8k
            isym.n_type, isym.n_sclass, 0,
983
40.8k
            isym.n_numaux, &aux);
984
40.8k
      }
985
986
    /* FIXME: Microsoft uses NODUPLICATES and ASSOCIATIVE, but
987
       gnu uses ANY and SAME_SIZE.  Unfortunately, gnu doesn't
988
       do the comdat symbols right.  So, until we can fix it to
989
       do the right thing, we are temporarily disabling comdats
990
       for the MS types (they're used in DLLs and C++, but we
991
       don't support *their* C++ libraries anyway - DJ.  */
992
993
    /* Cygwin does not follow the MS style, and uses ANY and
994
       SAME_SIZE where NODUPLICATES and ASSOCIATIVE should be
995
       used.  For Interix, we just do the right thing up
996
       front.  */
997
998
247k
    switch (aux.x_scn.x_comdat)
999
247k
      {
1000
3.08k
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1001
#ifdef STRICT_PE_FORMAT
1002
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1003
#else
1004
3.08k
        sec_flags &= ~SEC_LINK_ONCE;
1005
3.08k
#endif
1006
3.08k
        break;
1007
1008
34
      case IMAGE_COMDAT_SELECT_ANY:
1009
34
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1010
34
        break;
1011
1012
12
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1013
12
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1014
12
        break;
1015
1016
1.98k
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1017
        /* Not yet fully implemented ??? */
1018
1.98k
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1019
1.98k
        break;
1020
1021
        /* debug$S gets this case; other implications ???  */
1022
1023
        /* There may be no symbol.  We'll search the whole
1024
     table.  Is this the right place to play this game?
1025
     Or should we do it when reading it in?  */
1026
169
      case IMAGE_COMDAT_SELECT_ASSOCIATIVE:
1027
#ifdef STRICT_PE_FORMAT
1028
        /* FIXME: This is not currently implemented.  */
1029
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1030
#else
1031
169
        sec_flags &= ~SEC_LINK_ONCE;
1032
169
#endif
1033
169
        break;
1034
1035
242k
      default:  /* 0 means "no symbol" */
1036
        /* debug$F gets this case; other implications ???  */
1037
242k
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1038
242k
        break;
1039
247k
      }
1040
1041
247k
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1042
247k
    if (*slot == NULL)
1043
0
      return false;
1044
247k
    struct comdat_hash_entry *newentry = *slot;
1045
247k
    newentry->sec_flags = sec_flags;
1046
247k
    newentry->symname = bfd_strdup (symname);
1047
247k
    newentry->target_index = isym.n_scnum;
1048
247k
    newentry->isym = isym;
1049
247k
    newentry->comdat_symbol = -1;
1050
247k
  }
1051
433k
      else
1052
433k
  {
1053
433k
    struct comdat_hash_entry *entry = *slot;
1054
1055
433k
    if (entry->comdat_symbol != -1)
1056
361k
      continue;
1057
1058
71.9k
    char *target_name = strchr (entry->symname, '$');
1059
71.9k
    if (target_name != NULL)
1060
28.4k
      {
1061
        /* Gas mode: the first matching on partial name.  */
1062
1063
28.4k
        target_name += 1;
1064
#ifndef TARGET_UNDERSCORE
1065
#define TARGET_UNDERSCORE 0
1066
#endif
1067
        /* Is this the name we're looking for ?  */
1068
28.4k
        if (strcmp (target_name,
1069
28.4k
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1070
20.8k
    {
1071
      /* Not the name we're looking for */
1072
20.8k
      continue;
1073
20.8k
    }
1074
28.4k
      }
1075
    /* MSVC mode: the lexically second symbol (or drop through
1076
       from the above).  */
1077
    /* This must the second symbol with the section #.  It is
1078
       the actual symbol name.  Intel puts the two adjacent, but
1079
       Alpha (at least) spreads them out.  */
1080
1081
51.1k
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1082
51.1k
    entry->comdat_name = bfd_strdup (symname);
1083
51.1k
  }
1084
683k
    }
1085
1086
50.8k
  return true;
1087
50.8k
}
pei-mcore.c:fill_comdat_hash
Line
Count
Source
891
59.7k
{
892
59.7k
  bfd_byte *esymstart, *esym, *esymend;
893
894
  /* Unfortunately, the PE format stores essential information in the
895
     symbol table, of all places.  We need to extract that information
896
     now, so that objdump and the linker will know how to handle the
897
     section without worrying about the symbols.  We can't call
898
     slurp_symtab, because the linker doesn't want the swapped symbols.  */
899
900
  /* COMDAT sections are special.  The first symbol is the section
901
     symbol, which tells what kind of COMDAT section it is.  The
902
     second symbol is the "comdat symbol" - the one with the unique
903
     name.  GNU uses the section symbol for the unique name; MS uses
904
     ".text" for every comdat section.  Sigh.  - DJ.  */
905
906
  /* This is not mirrored in sec_to_styp_flags(), but there doesn't
907
     seem to be a need to, either, and it would at best be rather messy.  */
908
909
59.7k
  if (! _bfd_coff_get_external_symbols (abfd))
910
24.7k
    return true;
911
912
35.0k
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
913
35.0k
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
914
915
35.0k
  for (struct internal_syment isym;
916
399k
       esym < esymend;
917
364k
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
918
364k
    {
919
364k
      char buf[SYMNMLEN + 1];
920
364k
      const char *symname;
921
364k
      flagword sec_flags = SEC_LINK_ONCE;
922
923
364k
      bfd_coff_swap_sym_in (abfd, esym, &isym);
924
925
      /* According to the MSVC documentation, the first TWO entries
926
   with the section # are both of interest to us.  The first one
927
   is the "section symbol" (section name).  The second is the
928
   comdat symbol name.  Here, we've found the first qualifying
929
   entry; we distinguish it from the second with a state flag.
930
931
   In the case of gas-generated (at least until that is fixed)
932
   .o files, it isn't necessarily the second one.  It may be
933
   some other later symbol.
934
935
   Since gas also doesn't follow MS conventions and emits the
936
   section similar to .text$<name>, where <something> is the
937
   name we're looking for, we distinguish the two as follows:
938
939
   If the section name is simply a section name (no $) we
940
   presume it's MS-generated, and look at precisely the second
941
   symbol for the comdat name.  If the section name has a $, we
942
   assume it's gas-generated, and look for <something> (whatever
943
   follows the $) as the comdat symbol.  */
944
945
      /* All 3 branches use this.  */
946
364k
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
947
948
      /* PR 17512 file: 078-11867-0.004  */
949
364k
      if (symname == NULL)
950
108k
  {
951
108k
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
952
108k
            abfd);
953
108k
    continue;
954
108k
  }
955
956
255k
      union internal_auxent aux;
957
958
255k
      struct comdat_hash_entry needle;
959
255k
      needle.target_index = isym.n_scnum;
960
961
255k
      void **slot
962
255k
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
963
255k
      if (slot == NULL)
964
0
  return false;
965
966
255k
      if (*slot == NULL)
967
106k
  {
968
106k
    if (isym.n_numaux != 1)
969
93.6k
      aux.x_scn.x_comdat = 0;
970
13.2k
    else
971
13.2k
      {
972
        /* PR 17512: file: e2cfe54f.  */
973
13.2k
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
974
1.15k
    {
975
      /* xgettext:c-format */
976
1.15k
      _bfd_error_handler (_("%pB: warning: no symbol for"
977
1.15k
          " section '%s' found"),
978
1.15k
              abfd, symname);
979
1.15k
      continue;
980
1.15k
    }
981
12.0k
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
982
12.0k
            isym.n_type, isym.n_sclass, 0,
983
12.0k
            isym.n_numaux, &aux);
984
12.0k
      }
985
986
    /* FIXME: Microsoft uses NODUPLICATES and ASSOCIATIVE, but
987
       gnu uses ANY and SAME_SIZE.  Unfortunately, gnu doesn't
988
       do the comdat symbols right.  So, until we can fix it to
989
       do the right thing, we are temporarily disabling comdats
990
       for the MS types (they're used in DLLs and C++, but we
991
       don't support *their* C++ libraries anyway - DJ.  */
992
993
    /* Cygwin does not follow the MS style, and uses ANY and
994
       SAME_SIZE where NODUPLICATES and ASSOCIATIVE should be
995
       used.  For Interix, we just do the right thing up
996
       front.  */
997
998
105k
    switch (aux.x_scn.x_comdat)
999
105k
      {
1000
1.41k
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1001
#ifdef STRICT_PE_FORMAT
1002
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1003
#else
1004
1.41k
        sec_flags &= ~SEC_LINK_ONCE;
1005
1.41k
#endif
1006
1.41k
        break;
1007
1008
265
      case IMAGE_COMDAT_SELECT_ANY:
1009
265
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1010
265
        break;
1011
1012
14
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1013
14
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1014
14
        break;
1015
1016
437
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1017
        /* Not yet fully implemented ??? */
1018
437
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1019
437
        break;
1020
1021
        /* debug$S gets this case; other implications ???  */
1022
1023
        /* There may be no symbol.  We'll search the whole
1024
     table.  Is this the right place to play this game?
1025
     Or should we do it when reading it in?  */
1026
113
      case IMAGE_COMDAT_SELECT_ASSOCIATIVE:
1027
#ifdef STRICT_PE_FORMAT
1028
        /* FIXME: This is not currently implemented.  */
1029
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1030
#else
1031
113
        sec_flags &= ~SEC_LINK_ONCE;
1032
113
#endif
1033
113
        break;
1034
1035
103k
      default:  /* 0 means "no symbol" */
1036
        /* debug$F gets this case; other implications ???  */
1037
103k
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1038
103k
        break;
1039
105k
      }
1040
1041
105k
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1042
105k
    if (*slot == NULL)
1043
0
      return false;
1044
105k
    struct comdat_hash_entry *newentry = *slot;
1045
105k
    newentry->sec_flags = sec_flags;
1046
105k
    newentry->symname = bfd_strdup (symname);
1047
105k
    newentry->target_index = isym.n_scnum;
1048
105k
    newentry->isym = isym;
1049
105k
    newentry->comdat_symbol = -1;
1050
105k
  }
1051
148k
      else
1052
148k
  {
1053
148k
    struct comdat_hash_entry *entry = *slot;
1054
1055
148k
    if (entry->comdat_symbol != -1)
1056
108k
      continue;
1057
1058
39.9k
    char *target_name = strchr (entry->symname, '$');
1059
39.9k
    if (target_name != NULL)
1060
20.6k
      {
1061
        /* Gas mode: the first matching on partial name.  */
1062
1063
20.6k
        target_name += 1;
1064
20.6k
#ifndef TARGET_UNDERSCORE
1065
20.6k
#define TARGET_UNDERSCORE 0
1066
20.6k
#endif
1067
        /* Is this the name we're looking for ?  */
1068
20.6k
        if (strcmp (target_name,
1069
20.6k
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1070
19.6k
    {
1071
      /* Not the name we're looking for */
1072
19.6k
      continue;
1073
19.6k
    }
1074
20.6k
      }
1075
    /* MSVC mode: the lexically second symbol (or drop through
1076
       from the above).  */
1077
    /* This must the second symbol with the section #.  It is
1078
       the actual symbol name.  Intel puts the two adjacent, but
1079
       Alpha (at least) spreads them out.  */
1080
1081
20.2k
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1082
20.2k
    entry->comdat_name = bfd_strdup (symname);
1083
20.2k
  }
1084
255k
    }
1085
1086
35.0k
  return true;
1087
35.0k
}
pei-sh.c:fill_comdat_hash
Line
Count
Source
891
62.5k
{
892
62.5k
  bfd_byte *esymstart, *esym, *esymend;
893
894
  /* Unfortunately, the PE format stores essential information in the
895
     symbol table, of all places.  We need to extract that information
896
     now, so that objdump and the linker will know how to handle the
897
     section without worrying about the symbols.  We can't call
898
     slurp_symtab, because the linker doesn't want the swapped symbols.  */
899
900
  /* COMDAT sections are special.  The first symbol is the section
901
     symbol, which tells what kind of COMDAT section it is.  The
902
     second symbol is the "comdat symbol" - the one with the unique
903
     name.  GNU uses the section symbol for the unique name; MS uses
904
     ".text" for every comdat section.  Sigh.  - DJ.  */
905
906
  /* This is not mirrored in sec_to_styp_flags(), but there doesn't
907
     seem to be a need to, either, and it would at best be rather messy.  */
908
909
62.5k
  if (! _bfd_coff_get_external_symbols (abfd))
910
23.0k
    return true;
911
912
39.5k
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
913
39.5k
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
914
915
39.5k
  for (struct internal_syment isym;
916
579k
       esym < esymend;
917
539k
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
918
539k
    {
919
539k
      char buf[SYMNMLEN + 1];
920
539k
      const char *symname;
921
539k
      flagword sec_flags = SEC_LINK_ONCE;
922
923
539k
      bfd_coff_swap_sym_in (abfd, esym, &isym);
924
925
      /* According to the MSVC documentation, the first TWO entries
926
   with the section # are both of interest to us.  The first one
927
   is the "section symbol" (section name).  The second is the
928
   comdat symbol name.  Here, we've found the first qualifying
929
   entry; we distinguish it from the second with a state flag.
930
931
   In the case of gas-generated (at least until that is fixed)
932
   .o files, it isn't necessarily the second one.  It may be
933
   some other later symbol.
934
935
   Since gas also doesn't follow MS conventions and emits the
936
   section similar to .text$<name>, where <something> is the
937
   name we're looking for, we distinguish the two as follows:
938
939
   If the section name is simply a section name (no $) we
940
   presume it's MS-generated, and look at precisely the second
941
   symbol for the comdat name.  If the section name has a $, we
942
   assume it's gas-generated, and look for <something> (whatever
943
   follows the $) as the comdat symbol.  */
944
945
      /* All 3 branches use this.  */
946
539k
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
947
948
      /* PR 17512 file: 078-11867-0.004  */
949
539k
      if (symname == NULL)
950
151k
  {
951
151k
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
952
151k
            abfd);
953
151k
    continue;
954
151k
  }
955
956
388k
      union internal_auxent aux;
957
958
388k
      struct comdat_hash_entry needle;
959
388k
      needle.target_index = isym.n_scnum;
960
961
388k
      void **slot
962
388k
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
963
388k
      if (slot == NULL)
964
0
  return false;
965
966
388k
      if (*slot == NULL)
967
139k
  {
968
139k
    if (isym.n_numaux != 1)
969
120k
      aux.x_scn.x_comdat = 0;
970
18.9k
    else
971
18.9k
      {
972
        /* PR 17512: file: e2cfe54f.  */
973
18.9k
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
974
1.40k
    {
975
      /* xgettext:c-format */
976
1.40k
      _bfd_error_handler (_("%pB: warning: no symbol for"
977
1.40k
          " section '%s' found"),
978
1.40k
              abfd, symname);
979
1.40k
      continue;
980
1.40k
    }
981
17.5k
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
982
17.5k
            isym.n_type, isym.n_sclass, 0,
983
17.5k
            isym.n_numaux, &aux);
984
17.5k
      }
985
986
    /* FIXME: Microsoft uses NODUPLICATES and ASSOCIATIVE, but
987
       gnu uses ANY and SAME_SIZE.  Unfortunately, gnu doesn't
988
       do the comdat symbols right.  So, until we can fix it to
989
       do the right thing, we are temporarily disabling comdats
990
       for the MS types (they're used in DLLs and C++, but we
991
       don't support *their* C++ libraries anyway - DJ.  */
992
993
    /* Cygwin does not follow the MS style, and uses ANY and
994
       SAME_SIZE where NODUPLICATES and ASSOCIATIVE should be
995
       used.  For Interix, we just do the right thing up
996
       front.  */
997
998
137k
    switch (aux.x_scn.x_comdat)
999
137k
      {
1000
658
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1001
#ifdef STRICT_PE_FORMAT
1002
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1003
#else
1004
658
        sec_flags &= ~SEC_LINK_ONCE;
1005
658
#endif
1006
658
        break;
1007
1008
143
      case IMAGE_COMDAT_SELECT_ANY:
1009
143
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1010
143
        break;
1011
1012
11
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1013
11
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1014
11
        break;
1015
1016
1.59k
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1017
        /* Not yet fully implemented ??? */
1018
1.59k
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1019
1.59k
        break;
1020
1021
        /* debug$S gets this case; other implications ???  */
1022
1023
        /* There may be no symbol.  We'll search the whole
1024
     table.  Is this the right place to play this game?
1025
     Or should we do it when reading it in?  */
1026
247
      case IMAGE_COMDAT_SELECT_ASSOCIATIVE:
1027
#ifdef STRICT_PE_FORMAT
1028
        /* FIXME: This is not currently implemented.  */
1029
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1030
#else
1031
247
        sec_flags &= ~SEC_LINK_ONCE;
1032
247
#endif
1033
247
        break;
1034
1035
135k
      default:  /* 0 means "no symbol" */
1036
        /* debug$F gets this case; other implications ???  */
1037
135k
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1038
135k
        break;
1039
137k
      }
1040
1041
137k
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1042
137k
    if (*slot == NULL)
1043
0
      return false;
1044
137k
    struct comdat_hash_entry *newentry = *slot;
1045
137k
    newentry->sec_flags = sec_flags;
1046
137k
    newentry->symname = bfd_strdup (symname);
1047
137k
    newentry->target_index = isym.n_scnum;
1048
137k
    newentry->isym = isym;
1049
137k
    newentry->comdat_symbol = -1;
1050
137k
  }
1051
248k
      else
1052
248k
  {
1053
248k
    struct comdat_hash_entry *entry = *slot;
1054
1055
248k
    if (entry->comdat_symbol != -1)
1056
206k
      continue;
1057
1058
42.6k
    char *target_name = strchr (entry->symname, '$');
1059
42.6k
    if (target_name != NULL)
1060
13.6k
      {
1061
        /* Gas mode: the first matching on partial name.  */
1062
1063
13.6k
        target_name += 1;
1064
#ifndef TARGET_UNDERSCORE
1065
#define TARGET_UNDERSCORE 0
1066
#endif
1067
        /* Is this the name we're looking for ?  */
1068
13.6k
        if (strcmp (target_name,
1069
13.6k
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1070
11.5k
    {
1071
      /* Not the name we're looking for */
1072
11.5k
      continue;
1073
11.5k
    }
1074
13.6k
      }
1075
    /* MSVC mode: the lexically second symbol (or drop through
1076
       from the above).  */
1077
    /* This must the second symbol with the section #.  It is
1078
       the actual symbol name.  Intel puts the two adjacent, but
1079
       Alpha (at least) spreads them out.  */
1080
1081
31.1k
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1082
31.1k
    entry->comdat_name = bfd_strdup (symname);
1083
31.1k
  }
1084
388k
    }
1085
1086
39.5k
  return true;
1087
39.5k
}
1088
1089
static bool
1090
insert_coff_comdat_info (bfd *abfd, asection *section, const char *symname,
1091
       long symbol)
1092
39.5k
{
1093
39.5k
  struct coff_comdat_info *comdat;
1094
39.5k
  size_t len = strlen (symname) + 1;
1095
1096
39.5k
  comdat = bfd_alloc (abfd, sizeof (*comdat) + len);
1097
39.5k
  if (comdat == NULL)
1098
0
    return false;
1099
1100
39.5k
  coff_section_data (abfd, section)->comdat = comdat;
1101
39.5k
  comdat->symbol = symbol;
1102
39.5k
  char *newname = (char *) (comdat + 1);
1103
39.5k
  comdat->name = newname;
1104
39.5k
  memcpy (newname, symname, len);
1105
39.5k
  return true;
1106
39.5k
}
pei-i386.c:insert_coff_comdat_info
Line
Count
Source
1092
4.07k
{
1093
4.07k
  struct coff_comdat_info *comdat;
1094
4.07k
  size_t len = strlen (symname) + 1;
1095
1096
4.07k
  comdat = bfd_alloc (abfd, sizeof (*comdat) + len);
1097
4.07k
  if (comdat == NULL)
1098
0
    return false;
1099
1100
4.07k
  coff_section_data (abfd, section)->comdat = comdat;
1101
4.07k
  comdat->symbol = symbol;
1102
4.07k
  char *newname = (char *) (comdat + 1);
1103
4.07k
  comdat->name = newname;
1104
4.07k
  memcpy (newname, symname, len);
1105
4.07k
  return true;
1106
4.07k
}
pe-x86_64.c:insert_coff_comdat_info
Line
Count
Source
1092
3.31k
{
1093
3.31k
  struct coff_comdat_info *comdat;
1094
3.31k
  size_t len = strlen (symname) + 1;
1095
1096
3.31k
  comdat = bfd_alloc (abfd, sizeof (*comdat) + len);
1097
3.31k
  if (comdat == NULL)
1098
0
    return false;
1099
1100
3.31k
  coff_section_data (abfd, section)->comdat = comdat;
1101
3.31k
  comdat->symbol = symbol;
1102
3.31k
  char *newname = (char *) (comdat + 1);
1103
3.31k
  comdat->name = newname;
1104
3.31k
  memcpy (newname, symname, len);
1105
3.31k
  return true;
1106
3.31k
}
pei-x86_64.c:insert_coff_comdat_info
Line
Count
Source
1092
4.76k
{
1093
4.76k
  struct coff_comdat_info *comdat;
1094
4.76k
  size_t len = strlen (symname) + 1;
1095
1096
4.76k
  comdat = bfd_alloc (abfd, sizeof (*comdat) + len);
1097
4.76k
  if (comdat == NULL)
1098
0
    return false;
1099
1100
4.76k
  coff_section_data (abfd, section)->comdat = comdat;
1101
4.76k
  comdat->symbol = symbol;
1102
4.76k
  char *newname = (char *) (comdat + 1);
1103
4.76k
  comdat->name = newname;
1104
4.76k
  memcpy (newname, symname, len);
1105
4.76k
  return true;
1106
4.76k
}
pe-aarch64.c:insert_coff_comdat_info
Line
Count
Source
1092
499
{
1093
499
  struct coff_comdat_info *comdat;
1094
499
  size_t len = strlen (symname) + 1;
1095
1096
499
  comdat = bfd_alloc (abfd, sizeof (*comdat) + len);
1097
499
  if (comdat == NULL)
1098
0
    return false;
1099
1100
499
  coff_section_data (abfd, section)->comdat = comdat;
1101
499
  comdat->symbol = symbol;
1102
499
  char *newname = (char *) (comdat + 1);
1103
499
  comdat->name = newname;
1104
499
  memcpy (newname, symname, len);
1105
499
  return true;
1106
499
}
pei-aarch64.c:insert_coff_comdat_info
Line
Count
Source
1092
3.03k
{
1093
3.03k
  struct coff_comdat_info *comdat;
1094
3.03k
  size_t len = strlen (symname) + 1;
1095
1096
3.03k
  comdat = bfd_alloc (abfd, sizeof (*comdat) + len);
1097
3.03k
  if (comdat == NULL)
1098
0
    return false;
1099
1100
3.03k
  coff_section_data (abfd, section)->comdat = comdat;
1101
3.03k
  comdat->symbol = symbol;
1102
3.03k
  char *newname = (char *) (comdat + 1);
1103
3.03k
  comdat->name = newname;
1104
3.03k
  memcpy (newname, symname, len);
1105
3.03k
  return true;
1106
3.03k
}
pei-ia64.c:insert_coff_comdat_info
Line
Count
Source
1092
3.49k
{
1093
3.49k
  struct coff_comdat_info *comdat;
1094
3.49k
  size_t len = strlen (symname) + 1;
1095
1096
3.49k
  comdat = bfd_alloc (abfd, sizeof (*comdat) + len);
1097
3.49k
  if (comdat == NULL)
1098
0
    return false;
1099
1100
3.49k
  coff_section_data (abfd, section)->comdat = comdat;
1101
3.49k
  comdat->symbol = symbol;
1102
3.49k
  char *newname = (char *) (comdat + 1);
1103
3.49k
  comdat->name = newname;
1104
3.49k
  memcpy (newname, symname, len);
1105
3.49k
  return true;
1106
3.49k
}
pei-loongarch64.c:insert_coff_comdat_info
Line
Count
Source
1092
1.76k
{
1093
1.76k
  struct coff_comdat_info *comdat;
1094
1.76k
  size_t len = strlen (symname) + 1;
1095
1096
1.76k
  comdat = bfd_alloc (abfd, sizeof (*comdat) + len);
1097
1.76k
  if (comdat == NULL)
1098
0
    return false;
1099
1100
1.76k
  coff_section_data (abfd, section)->comdat = comdat;
1101
1.76k
  comdat->symbol = symbol;
1102
1.76k
  char *newname = (char *) (comdat + 1);
1103
1.76k
  comdat->name = newname;
1104
1.76k
  memcpy (newname, symname, len);
1105
1.76k
  return true;
1106
1.76k
}
pei-riscv64.c:insert_coff_comdat_info
Line
Count
Source
1092
1.35k
{
1093
1.35k
  struct coff_comdat_info *comdat;
1094
1.35k
  size_t len = strlen (symname) + 1;
1095
1096
1.35k
  comdat = bfd_alloc (abfd, sizeof (*comdat) + len);
1097
1.35k
  if (comdat == NULL)
1098
0
    return false;
1099
1100
1.35k
  coff_section_data (abfd, section)->comdat = comdat;
1101
1.35k
  comdat->symbol = symbol;
1102
1.35k
  char *newname = (char *) (comdat + 1);
1103
1.35k
  comdat->name = newname;
1104
1.35k
  memcpy (newname, symname, len);
1105
1.35k
  return true;
1106
1.35k
}
pe-arm-wince.c:insert_coff_comdat_info
Line
Count
Source
1092
1.63k
{
1093
1.63k
  struct coff_comdat_info *comdat;
1094
1.63k
  size_t len = strlen (symname) + 1;
1095
1096
1.63k
  comdat = bfd_alloc (abfd, sizeof (*comdat) + len);
1097
1.63k
  if (comdat == NULL)
1098
0
    return false;
1099
1100
1.63k
  coff_section_data (abfd, section)->comdat = comdat;
1101
1.63k
  comdat->symbol = symbol;
1102
1.63k
  char *newname = (char *) (comdat + 1);
1103
1.63k
  comdat->name = newname;
1104
1.63k
  memcpy (newname, symname, len);
1105
1.63k
  return true;
1106
1.63k
}
pe-arm.c:insert_coff_comdat_info
Line
Count
Source
1092
1.63k
{
1093
1.63k
  struct coff_comdat_info *comdat;
1094
1.63k
  size_t len = strlen (symname) + 1;
1095
1096
1.63k
  comdat = bfd_alloc (abfd, sizeof (*comdat) + len);
1097
1.63k
  if (comdat == NULL)
1098
0
    return false;
1099
1100
1.63k
  coff_section_data (abfd, section)->comdat = comdat;
1101
1.63k
  comdat->symbol = symbol;
1102
1.63k
  char *newname = (char *) (comdat + 1);
1103
1.63k
  comdat->name = newname;
1104
1.63k
  memcpy (newname, symname, len);
1105
1.63k
  return true;
1106
1.63k
}
pe-i386.c:insert_coff_comdat_info
Line
Count
Source
1092
1.29k
{
1093
1.29k
  struct coff_comdat_info *comdat;
1094
1.29k
  size_t len = strlen (symname) + 1;
1095
1096
1.29k
  comdat = bfd_alloc (abfd, sizeof (*comdat) + len);
1097
1.29k
  if (comdat == NULL)
1098
0
    return false;
1099
1100
1.29k
  coff_section_data (abfd, section)->comdat = comdat;
1101
1.29k
  comdat->symbol = symbol;
1102
1.29k
  char *newname = (char *) (comdat + 1);
1103
1.29k
  comdat->name = newname;
1104
1.29k
  memcpy (newname, symname, len);
1105
1.29k
  return true;
1106
1.29k
}
pe-mcore.c:insert_coff_comdat_info
Line
Count
Source
1092
710
{
1093
710
  struct coff_comdat_info *comdat;
1094
710
  size_t len = strlen (symname) + 1;
1095
1096
710
  comdat = bfd_alloc (abfd, sizeof (*comdat) + len);
1097
710
  if (comdat == NULL)
1098
0
    return false;
1099
1100
710
  coff_section_data (abfd, section)->comdat = comdat;
1101
710
  comdat->symbol = symbol;
1102
710
  char *newname = (char *) (comdat + 1);
1103
710
  comdat->name = newname;
1104
710
  memcpy (newname, symname, len);
1105
710
  return true;
1106
710
}
pe-sh.c:insert_coff_comdat_info
Line
Count
Source
1092
1.01k
{
1093
1.01k
  struct coff_comdat_info *comdat;
1094
1.01k
  size_t len = strlen (symname) + 1;
1095
1096
1.01k
  comdat = bfd_alloc (abfd, sizeof (*comdat) + len);
1097
1.01k
  if (comdat == NULL)
1098
0
    return false;
1099
1100
1.01k
  coff_section_data (abfd, section)->comdat = comdat;
1101
1.01k
  comdat->symbol = symbol;
1102
1.01k
  char *newname = (char *) (comdat + 1);
1103
1.01k
  comdat->name = newname;
1104
1.01k
  memcpy (newname, symname, len);
1105
1.01k
  return true;
1106
1.01k
}
pei-arm-wince.c:insert_coff_comdat_info
Line
Count
Source
1092
3.00k
{
1093
3.00k
  struct coff_comdat_info *comdat;
1094
3.00k
  size_t len = strlen (symname) + 1;
1095
1096
3.00k
  comdat = bfd_alloc (abfd, sizeof (*comdat) + len);
1097
3.00k
  if (comdat == NULL)
1098
0
    return false;
1099
1100
3.00k
  coff_section_data (abfd, section)->comdat = comdat;
1101
3.00k
  comdat->symbol = symbol;
1102
3.00k
  char *newname = (char *) (comdat + 1);
1103
3.00k
  comdat->name = newname;
1104
3.00k
  memcpy (newname, symname, len);
1105
3.00k
  return true;
1106
3.00k
}
pei-arm.c:insert_coff_comdat_info
Line
Count
Source
1092
3.02k
{
1093
3.02k
  struct coff_comdat_info *comdat;
1094
3.02k
  size_t len = strlen (symname) + 1;
1095
1096
3.02k
  comdat = bfd_alloc (abfd, sizeof (*comdat) + len);
1097
3.02k
  if (comdat == NULL)
1098
0
    return false;
1099
1100
3.02k
  coff_section_data (abfd, section)->comdat = comdat;
1101
3.02k
  comdat->symbol = symbol;
1102
3.02k
  char *newname = (char *) (comdat + 1);
1103
3.02k
  comdat->name = newname;
1104
3.02k
  memcpy (newname, symname, len);
1105
3.02k
  return true;
1106
3.02k
}
pei-mcore.c:insert_coff_comdat_info
Line
Count
Source
1092
1.51k
{
1093
1.51k
  struct coff_comdat_info *comdat;
1094
1.51k
  size_t len = strlen (symname) + 1;
1095
1096
1.51k
  comdat = bfd_alloc (abfd, sizeof (*comdat) + len);
1097
1.51k
  if (comdat == NULL)
1098
0
    return false;
1099
1100
1.51k
  coff_section_data (abfd, section)->comdat = comdat;
1101
1.51k
  comdat->symbol = symbol;
1102
1.51k
  char *newname = (char *) (comdat + 1);
1103
1.51k
  comdat->name = newname;
1104
1.51k
  memcpy (newname, symname, len);
1105
1.51k
  return true;
1106
1.51k
}
pei-sh.c:insert_coff_comdat_info
Line
Count
Source
1092
3.41k
{
1093
3.41k
  struct coff_comdat_info *comdat;
1094
3.41k
  size_t len = strlen (symname) + 1;
1095
1096
3.41k
  comdat = bfd_alloc (abfd, sizeof (*comdat) + len);
1097
3.41k
  if (comdat == NULL)
1098
0
    return false;
1099
1100
3.41k
  coff_section_data (abfd, section)->comdat = comdat;
1101
3.41k
  comdat->symbol = symbol;
1102
3.41k
  char *newname = (char *) (comdat + 1);
1103
3.41k
  comdat->name = newname;
1104
3.41k
  memcpy (newname, symname, len);
1105
3.41k
  return true;
1106
3.41k
}
1107
1108
static bool
1109
handle_COMDAT (bfd *abfd, flagword *sec_flags, const char *name,
1110
         asection *section)
1111
1.35M
{
1112
1.35M
  if (pe_data (abfd)->comdat_hash == NULL)
1113
913k
    {
1114
913k
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1115
913k
             comdat_delf);
1116
913k
      if (pe_data (abfd)->comdat_hash == NULL)
1117
0
  return false;
1118
913k
    }
1119
1120
1.35M
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1121
1.08M
    if (! fill_comdat_hash (abfd))
1122
0
      return false;
1123
1124
1.35M
  struct comdat_hash_entry *found
1125
1.35M
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1126
1.35M
  if (found != NULL)
1127
208k
    {
1128
208k
      struct internal_syment isym = found->isym;
1129
1130
      /* If it isn't the stuff we're expecting, die;  The MS
1131
   documentation is vague, but it appears that the second entry
1132
   serves BOTH as the comdat symbol and the defining symbol
1133
   record (either C_STAT or C_EXT, possibly with an aux entry
1134
   with debug information if it's a function.)  It appears the
1135
   only way to find the second one is to count.  (On Intel, they
1136
   appear to be adjacent, but on Alpha, they have been found
1137
   separated.)
1138
1139
   Here, we think we've found the first one, but there's some
1140
   checking we can do to be sure.  */
1141
1142
208k
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1143
208k
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1144
82.7k
  {
1145
    /* Malformed input files can trigger this test.
1146
       cf PR 21781.  */
1147
82.7k
    _bfd_error_handler
1148
82.7k
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1149
82.7k
       abfd, found->symname);
1150
82.7k
    return false;
1151
82.7k
  }
1152
1153
      /* FIXME LATER: MSVC generates section names like .text for
1154
   comdats.  Gas generates names like .text$foo__Fv (in the case
1155
   of a function).  See comment above for more.  */
1156
1157
126k
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1158
  /* xgettext:c-format */
1159
66.9k
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1160
66.9k
            " does not match section name '%s'"),
1161
66.9k
          abfd, found->symname, name);
1162
1163
126k
      if (found->comdat_symbol != -1)
1164
39.5k
  {
1165
39.5k
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1166
39.5k
           found->comdat_symbol))
1167
0
      return false;
1168
39.5k
  }
1169
126k
      *sec_flags = *sec_flags | found->sec_flags;
1170
126k
      return true;
1171
126k
    }
1172
1.15M
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1173
1.15M
  return true;
1174
1.35M
}
pei-i386.c:handle_COMDAT
Line
Count
Source
1111
103k
{
1112
103k
  if (pe_data (abfd)->comdat_hash == NULL)
1113
58.5k
    {
1114
58.5k
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1115
58.5k
             comdat_delf);
1116
58.5k
      if (pe_data (abfd)->comdat_hash == NULL)
1117
0
  return false;
1118
58.5k
    }
1119
1120
103k
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1121
69.6k
    if (! fill_comdat_hash (abfd))
1122
0
      return false;
1123
1124
103k
  struct comdat_hash_entry *found
1125
103k
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1126
103k
  if (found != NULL)
1127
18.5k
    {
1128
18.5k
      struct internal_syment isym = found->isym;
1129
1130
      /* If it isn't the stuff we're expecting, die;  The MS
1131
   documentation is vague, but it appears that the second entry
1132
   serves BOTH as the comdat symbol and the defining symbol
1133
   record (either C_STAT or C_EXT, possibly with an aux entry
1134
   with debug information if it's a function.)  It appears the
1135
   only way to find the second one is to count.  (On Intel, they
1136
   appear to be adjacent, but on Alpha, they have been found
1137
   separated.)
1138
1139
   Here, we think we've found the first one, but there's some
1140
   checking we can do to be sure.  */
1141
1142
18.5k
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1143
18.5k
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1144
5.04k
  {
1145
    /* Malformed input files can trigger this test.
1146
       cf PR 21781.  */
1147
5.04k
    _bfd_error_handler
1148
5.04k
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1149
5.04k
       abfd, found->symname);
1150
5.04k
    return false;
1151
5.04k
  }
1152
1153
      /* FIXME LATER: MSVC generates section names like .text for
1154
   comdats.  Gas generates names like .text$foo__Fv (in the case
1155
   of a function).  See comment above for more.  */
1156
1157
13.4k
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1158
  /* xgettext:c-format */
1159
8.62k
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1160
8.62k
            " does not match section name '%s'"),
1161
8.62k
          abfd, found->symname, name);
1162
1163
13.4k
      if (found->comdat_symbol != -1)
1164
4.07k
  {
1165
4.07k
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1166
4.07k
           found->comdat_symbol))
1167
0
      return false;
1168
4.07k
  }
1169
13.4k
      *sec_flags = *sec_flags | found->sec_flags;
1170
13.4k
      return true;
1171
13.4k
    }
1172
84.5k
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1173
84.5k
  return true;
1174
103k
}
pe-x86_64.c:handle_COMDAT
Line
Count
Source
1111
168k
{
1112
168k
  if (pe_data (abfd)->comdat_hash == NULL)
1113
142k
    {
1114
142k
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1115
142k
             comdat_delf);
1116
142k
      if (pe_data (abfd)->comdat_hash == NULL)
1117
0
  return false;
1118
142k
    }
1119
1120
168k
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1121
155k
    if (! fill_comdat_hash (abfd))
1122
0
      return false;
1123
1124
168k
  struct comdat_hash_entry *found
1125
168k
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1126
168k
  if (found != NULL)
1127
17.5k
    {
1128
17.5k
      struct internal_syment isym = found->isym;
1129
1130
      /* If it isn't the stuff we're expecting, die;  The MS
1131
   documentation is vague, but it appears that the second entry
1132
   serves BOTH as the comdat symbol and the defining symbol
1133
   record (either C_STAT or C_EXT, possibly with an aux entry
1134
   with debug information if it's a function.)  It appears the
1135
   only way to find the second one is to count.  (On Intel, they
1136
   appear to be adjacent, but on Alpha, they have been found
1137
   separated.)
1138
1139
   Here, we think we've found the first one, but there's some
1140
   checking we can do to be sure.  */
1141
1142
17.5k
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1143
17.5k
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1144
8.79k
  {
1145
    /* Malformed input files can trigger this test.
1146
       cf PR 21781.  */
1147
8.79k
    _bfd_error_handler
1148
8.79k
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1149
8.79k
       abfd, found->symname);
1150
8.79k
    return false;
1151
8.79k
  }
1152
1153
      /* FIXME LATER: MSVC generates section names like .text for
1154
   comdats.  Gas generates names like .text$foo__Fv (in the case
1155
   of a function).  See comment above for more.  */
1156
1157
8.75k
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1158
  /* xgettext:c-format */
1159
3.39k
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1160
3.39k
            " does not match section name '%s'"),
1161
3.39k
          abfd, found->symname, name);
1162
1163
8.75k
      if (found->comdat_symbol != -1)
1164
3.31k
  {
1165
3.31k
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1166
3.31k
           found->comdat_symbol))
1167
0
      return false;
1168
3.31k
  }
1169
8.75k
      *sec_flags = *sec_flags | found->sec_flags;
1170
8.75k
      return true;
1171
8.75k
    }
1172
150k
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1173
150k
  return true;
1174
168k
}
pei-x86_64.c:handle_COMDAT
Line
Count
Source
1111
117k
{
1112
117k
  if (pe_data (abfd)->comdat_hash == NULL)
1113
73.5k
    {
1114
73.5k
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1115
73.5k
             comdat_delf);
1116
73.5k
      if (pe_data (abfd)->comdat_hash == NULL)
1117
0
  return false;
1118
73.5k
    }
1119
1120
117k
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1121
84.0k
    if (! fill_comdat_hash (abfd))
1122
0
      return false;
1123
1124
117k
  struct comdat_hash_entry *found
1125
117k
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1126
117k
  if (found != NULL)
1127
19.2k
    {
1128
19.2k
      struct internal_syment isym = found->isym;
1129
1130
      /* If it isn't the stuff we're expecting, die;  The MS
1131
   documentation is vague, but it appears that the second entry
1132
   serves BOTH as the comdat symbol and the defining symbol
1133
   record (either C_STAT or C_EXT, possibly with an aux entry
1134
   with debug information if it's a function.)  It appears the
1135
   only way to find the second one is to count.  (On Intel, they
1136
   appear to be adjacent, but on Alpha, they have been found
1137
   separated.)
1138
1139
   Here, we think we've found the first one, but there's some
1140
   checking we can do to be sure.  */
1141
1142
19.2k
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1143
19.2k
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1144
4.28k
  {
1145
    /* Malformed input files can trigger this test.
1146
       cf PR 21781.  */
1147
4.28k
    _bfd_error_handler
1148
4.28k
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1149
4.28k
       abfd, found->symname);
1150
4.28k
    return false;
1151
4.28k
  }
1152
1153
      /* FIXME LATER: MSVC generates section names like .text for
1154
   comdats.  Gas generates names like .text$foo__Fv (in the case
1155
   of a function).  See comment above for more.  */
1156
1157
14.9k
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1158
  /* xgettext:c-format */
1159
8.69k
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1160
8.69k
            " does not match section name '%s'"),
1161
8.69k
          abfd, found->symname, name);
1162
1163
14.9k
      if (found->comdat_symbol != -1)
1164
4.76k
  {
1165
4.76k
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1166
4.76k
           found->comdat_symbol))
1167
0
      return false;
1168
4.76k
  }
1169
14.9k
      *sec_flags = *sec_flags | found->sec_flags;
1170
14.9k
      return true;
1171
14.9k
    }
1172
98.5k
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1173
98.5k
  return true;
1174
117k
}
pe-aarch64.c:handle_COMDAT
Line
Count
Source
1111
47.8k
{
1112
47.8k
  if (pe_data (abfd)->comdat_hash == NULL)
1113
35.4k
    {
1114
35.4k
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1115
35.4k
             comdat_delf);
1116
35.4k
      if (pe_data (abfd)->comdat_hash == NULL)
1117
0
  return false;
1118
35.4k
    }
1119
1120
47.8k
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1121
40.9k
    if (! fill_comdat_hash (abfd))
1122
0
      return false;
1123
1124
47.8k
  struct comdat_hash_entry *found
1125
47.8k
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1126
47.8k
  if (found != NULL)
1127
5.71k
    {
1128
5.71k
      struct internal_syment isym = found->isym;
1129
1130
      /* If it isn't the stuff we're expecting, die;  The MS
1131
   documentation is vague, but it appears that the second entry
1132
   serves BOTH as the comdat symbol and the defining symbol
1133
   record (either C_STAT or C_EXT, possibly with an aux entry
1134
   with debug information if it's a function.)  It appears the
1135
   only way to find the second one is to count.  (On Intel, they
1136
   appear to be adjacent, but on Alpha, they have been found
1137
   separated.)
1138
1139
   Here, we think we've found the first one, but there's some
1140
   checking we can do to be sure.  */
1141
1142
5.71k
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1143
5.71k
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1144
1.34k
  {
1145
    /* Malformed input files can trigger this test.
1146
       cf PR 21781.  */
1147
1.34k
    _bfd_error_handler
1148
1.34k
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1149
1.34k
       abfd, found->symname);
1150
1.34k
    return false;
1151
1.34k
  }
1152
1153
      /* FIXME LATER: MSVC generates section names like .text for
1154
   comdats.  Gas generates names like .text$foo__Fv (in the case
1155
   of a function).  See comment above for more.  */
1156
1157
4.36k
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1158
  /* xgettext:c-format */
1159
1.28k
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1160
1.28k
            " does not match section name '%s'"),
1161
1.28k
          abfd, found->symname, name);
1162
1163
4.36k
      if (found->comdat_symbol != -1)
1164
499
  {
1165
499
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1166
499
           found->comdat_symbol))
1167
0
      return false;
1168
499
  }
1169
4.36k
      *sec_flags = *sec_flags | found->sec_flags;
1170
4.36k
      return true;
1171
4.36k
    }
1172
42.1k
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1173
42.1k
  return true;
1174
47.8k
}
pei-aarch64.c:handle_COMDAT
Line
Count
Source
1111
99.4k
{
1112
99.4k
  if (pe_data (abfd)->comdat_hash == NULL)
1113
50.1k
    {
1114
50.1k
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1115
50.1k
             comdat_delf);
1116
50.1k
      if (pe_data (abfd)->comdat_hash == NULL)
1117
0
  return false;
1118
50.1k
    }
1119
1120
99.4k
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1121
61.9k
    if (! fill_comdat_hash (abfd))
1122
0
      return false;
1123
1124
99.4k
  struct comdat_hash_entry *found
1125
99.4k
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1126
99.4k
  if (found != NULL)
1127
15.1k
    {
1128
15.1k
      struct internal_syment isym = found->isym;
1129
1130
      /* If it isn't the stuff we're expecting, die;  The MS
1131
   documentation is vague, but it appears that the second entry
1132
   serves BOTH as the comdat symbol and the defining symbol
1133
   record (either C_STAT or C_EXT, possibly with an aux entry
1134
   with debug information if it's a function.)  It appears the
1135
   only way to find the second one is to count.  (On Intel, they
1136
   appear to be adjacent, but on Alpha, they have been found
1137
   separated.)
1138
1139
   Here, we think we've found the first one, but there's some
1140
   checking we can do to be sure.  */
1141
1142
15.1k
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1143
15.1k
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1144
7.61k
  {
1145
    /* Malformed input files can trigger this test.
1146
       cf PR 21781.  */
1147
7.61k
    _bfd_error_handler
1148
7.61k
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1149
7.61k
       abfd, found->symname);
1150
7.61k
    return false;
1151
7.61k
  }
1152
1153
      /* FIXME LATER: MSVC generates section names like .text for
1154
   comdats.  Gas generates names like .text$foo__Fv (in the case
1155
   of a function).  See comment above for more.  */
1156
1157
7.55k
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1158
  /* xgettext:c-format */
1159
4.64k
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1160
4.64k
            " does not match section name '%s'"),
1161
4.64k
          abfd, found->symname, name);
1162
1163
7.55k
      if (found->comdat_symbol != -1)
1164
3.03k
  {
1165
3.03k
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1166
3.03k
           found->comdat_symbol))
1167
0
      return false;
1168
3.03k
  }
1169
7.55k
      *sec_flags = *sec_flags | found->sec_flags;
1170
7.55k
      return true;
1171
7.55k
    }
1172
84.3k
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1173
84.3k
  return true;
1174
99.4k
}
pei-ia64.c:handle_COMDAT
Line
Count
Source
1111
81.5k
{
1112
81.5k
  if (pe_data (abfd)->comdat_hash == NULL)
1113
56.8k
    {
1114
56.8k
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1115
56.8k
             comdat_delf);
1116
56.8k
      if (pe_data (abfd)->comdat_hash == NULL)
1117
0
  return false;
1118
56.8k
    }
1119
1120
81.5k
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1121
69.0k
    if (! fill_comdat_hash (abfd))
1122
0
      return false;
1123
1124
81.5k
  struct comdat_hash_entry *found
1125
81.5k
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1126
81.5k
  if (found != NULL)
1127
16.1k
    {
1128
16.1k
      struct internal_syment isym = found->isym;
1129
1130
      /* If it isn't the stuff we're expecting, die;  The MS
1131
   documentation is vague, but it appears that the second entry
1132
   serves BOTH as the comdat symbol and the defining symbol
1133
   record (either C_STAT or C_EXT, possibly with an aux entry
1134
   with debug information if it's a function.)  It appears the
1135
   only way to find the second one is to count.  (On Intel, they
1136
   appear to be adjacent, but on Alpha, they have been found
1137
   separated.)
1138
1139
   Here, we think we've found the first one, but there's some
1140
   checking we can do to be sure.  */
1141
1142
16.1k
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1143
16.1k
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1144
7.93k
  {
1145
    /* Malformed input files can trigger this test.
1146
       cf PR 21781.  */
1147
7.93k
    _bfd_error_handler
1148
7.93k
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1149
7.93k
       abfd, found->symname);
1150
7.93k
    return false;
1151
7.93k
  }
1152
1153
      /* FIXME LATER: MSVC generates section names like .text for
1154
   comdats.  Gas generates names like .text$foo__Fv (in the case
1155
   of a function).  See comment above for more.  */
1156
1157
8.16k
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1158
  /* xgettext:c-format */
1159
4.90k
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1160
4.90k
            " does not match section name '%s'"),
1161
4.90k
          abfd, found->symname, name);
1162
1163
8.16k
      if (found->comdat_symbol != -1)
1164
3.49k
  {
1165
3.49k
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1166
3.49k
           found->comdat_symbol))
1167
0
      return false;
1168
3.49k
  }
1169
8.16k
      *sec_flags = *sec_flags | found->sec_flags;
1170
8.16k
      return true;
1171
8.16k
    }
1172
65.4k
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1173
65.4k
  return true;
1174
81.5k
}
pei-loongarch64.c:handle_COMDAT
Line
Count
Source
1111
72.3k
{
1112
72.3k
  if (pe_data (abfd)->comdat_hash == NULL)
1113
54.3k
    {
1114
54.3k
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1115
54.3k
             comdat_delf);
1116
54.3k
      if (pe_data (abfd)->comdat_hash == NULL)
1117
0
  return false;
1118
54.3k
    }
1119
1120
72.3k
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1121
66.0k
    if (! fill_comdat_hash (abfd))
1122
0
      return false;
1123
1124
72.3k
  struct comdat_hash_entry *found
1125
72.3k
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1126
72.3k
  if (found != NULL)
1127
9.55k
    {
1128
9.55k
      struct internal_syment isym = found->isym;
1129
1130
      /* If it isn't the stuff we're expecting, die;  The MS
1131
   documentation is vague, but it appears that the second entry
1132
   serves BOTH as the comdat symbol and the defining symbol
1133
   record (either C_STAT or C_EXT, possibly with an aux entry
1134
   with debug information if it's a function.)  It appears the
1135
   only way to find the second one is to count.  (On Intel, they
1136
   appear to be adjacent, but on Alpha, they have been found
1137
   separated.)
1138
1139
   Here, we think we've found the first one, but there's some
1140
   checking we can do to be sure.  */
1141
1142
9.55k
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1143
9.55k
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1144
3.56k
  {
1145
    /* Malformed input files can trigger this test.
1146
       cf PR 21781.  */
1147
3.56k
    _bfd_error_handler
1148
3.56k
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1149
3.56k
       abfd, found->symname);
1150
3.56k
    return false;
1151
3.56k
  }
1152
1153
      /* FIXME LATER: MSVC generates section names like .text for
1154
   comdats.  Gas generates names like .text$foo__Fv (in the case
1155
   of a function).  See comment above for more.  */
1156
1157
5.99k
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1158
  /* xgettext:c-format */
1159
2.57k
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1160
2.57k
            " does not match section name '%s'"),
1161
2.57k
          abfd, found->symname, name);
1162
1163
5.99k
      if (found->comdat_symbol != -1)
1164
1.76k
  {
1165
1.76k
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1166
1.76k
           found->comdat_symbol))
1167
0
      return false;
1168
1.76k
  }
1169
5.99k
      *sec_flags = *sec_flags | found->sec_flags;
1170
5.99k
      return true;
1171
5.99k
    }
1172
62.7k
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1173
62.7k
  return true;
1174
72.3k
}
pei-riscv64.c:handle_COMDAT
Line
Count
Source
1111
67.2k
{
1112
67.2k
  if (pe_data (abfd)->comdat_hash == NULL)
1113
49.9k
    {
1114
49.9k
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1115
49.9k
             comdat_delf);
1116
49.9k
      if (pe_data (abfd)->comdat_hash == NULL)
1117
0
  return false;
1118
49.9k
    }
1119
1120
67.2k
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1121
59.7k
    if (! fill_comdat_hash (abfd))
1122
0
      return false;
1123
1124
67.2k
  struct comdat_hash_entry *found
1125
67.2k
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1126
67.2k
  if (found != NULL)
1127
9.95k
    {
1128
9.95k
      struct internal_syment isym = found->isym;
1129
1130
      /* If it isn't the stuff we're expecting, die;  The MS
1131
   documentation is vague, but it appears that the second entry
1132
   serves BOTH as the comdat symbol and the defining symbol
1133
   record (either C_STAT or C_EXT, possibly with an aux entry
1134
   with debug information if it's a function.)  It appears the
1135
   only way to find the second one is to count.  (On Intel, they
1136
   appear to be adjacent, but on Alpha, they have been found
1137
   separated.)
1138
1139
   Here, we think we've found the first one, but there's some
1140
   checking we can do to be sure.  */
1141
1142
9.95k
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1143
9.95k
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1144
4.94k
  {
1145
    /* Malformed input files can trigger this test.
1146
       cf PR 21781.  */
1147
4.94k
    _bfd_error_handler
1148
4.94k
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1149
4.94k
       abfd, found->symname);
1150
4.94k
    return false;
1151
4.94k
  }
1152
1153
      /* FIXME LATER: MSVC generates section names like .text for
1154
   comdats.  Gas generates names like .text$foo__Fv (in the case
1155
   of a function).  See comment above for more.  */
1156
1157
5.01k
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1158
  /* xgettext:c-format */
1159
1.92k
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1160
1.92k
            " does not match section name '%s'"),
1161
1.92k
          abfd, found->symname, name);
1162
1163
5.01k
      if (found->comdat_symbol != -1)
1164
1.35k
  {
1165
1.35k
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1166
1.35k
           found->comdat_symbol))
1167
0
      return false;
1168
1.35k
  }
1169
5.01k
      *sec_flags = *sec_flags | found->sec_flags;
1170
5.01k
      return true;
1171
5.01k
    }
1172
57.3k
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1173
57.3k
  return true;
1174
67.2k
}
pe-arm-wince.c:handle_COMDAT
Line
Count
Source
1111
35.2k
{
1112
35.2k
  if (pe_data (abfd)->comdat_hash == NULL)
1113
22.4k
    {
1114
22.4k
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1115
22.4k
             comdat_delf);
1116
22.4k
      if (pe_data (abfd)->comdat_hash == NULL)
1117
0
  return false;
1118
22.4k
    }
1119
1120
35.2k
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1121
27.5k
    if (! fill_comdat_hash (abfd))
1122
0
      return false;
1123
1124
35.2k
  struct comdat_hash_entry *found
1125
35.2k
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1126
35.2k
  if (found != NULL)
1127
7.59k
    {
1128
7.59k
      struct internal_syment isym = found->isym;
1129
1130
      /* If it isn't the stuff we're expecting, die;  The MS
1131
   documentation is vague, but it appears that the second entry
1132
   serves BOTH as the comdat symbol and the defining symbol
1133
   record (either C_STAT or C_EXT, possibly with an aux entry
1134
   with debug information if it's a function.)  It appears the
1135
   only way to find the second one is to count.  (On Intel, they
1136
   appear to be adjacent, but on Alpha, they have been found
1137
   separated.)
1138
1139
   Here, we think we've found the first one, but there's some
1140
   checking we can do to be sure.  */
1141
1142
7.59k
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1143
7.59k
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1144
2.80k
  {
1145
    /* Malformed input files can trigger this test.
1146
       cf PR 21781.  */
1147
2.80k
    _bfd_error_handler
1148
2.80k
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1149
2.80k
       abfd, found->symname);
1150
2.80k
    return false;
1151
2.80k
  }
1152
1153
      /* FIXME LATER: MSVC generates section names like .text for
1154
   comdats.  Gas generates names like .text$foo__Fv (in the case
1155
   of a function).  See comment above for more.  */
1156
1157
4.79k
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1158
  /* xgettext:c-format */
1159
2.87k
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1160
2.87k
            " does not match section name '%s'"),
1161
2.87k
          abfd, found->symname, name);
1162
1163
4.79k
      if (found->comdat_symbol != -1)
1164
1.63k
  {
1165
1.63k
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1166
1.63k
           found->comdat_symbol))
1167
0
      return false;
1168
1.63k
  }
1169
4.79k
      *sec_flags = *sec_flags | found->sec_flags;
1170
4.79k
      return true;
1171
4.79k
    }
1172
27.6k
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1173
27.6k
  return true;
1174
35.2k
}
pe-arm.c:handle_COMDAT
Line
Count
Source
1111
35.2k
{
1112
35.2k
  if (pe_data (abfd)->comdat_hash == NULL)
1113
22.4k
    {
1114
22.4k
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1115
22.4k
             comdat_delf);
1116
22.4k
      if (pe_data (abfd)->comdat_hash == NULL)
1117
0
  return false;
1118
22.4k
    }
1119
1120
35.2k
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1121
27.5k
    if (! fill_comdat_hash (abfd))
1122
0
      return false;
1123
1124
35.2k
  struct comdat_hash_entry *found
1125
35.2k
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1126
35.2k
  if (found != NULL)
1127
7.59k
    {
1128
7.59k
      struct internal_syment isym = found->isym;
1129
1130
      /* If it isn't the stuff we're expecting, die;  The MS
1131
   documentation is vague, but it appears that the second entry
1132
   serves BOTH as the comdat symbol and the defining symbol
1133
   record (either C_STAT or C_EXT, possibly with an aux entry
1134
   with debug information if it's a function.)  It appears the
1135
   only way to find the second one is to count.  (On Intel, they
1136
   appear to be adjacent, but on Alpha, they have been found
1137
   separated.)
1138
1139
   Here, we think we've found the first one, but there's some
1140
   checking we can do to be sure.  */
1141
1142
7.59k
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1143
7.59k
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1144
2.80k
  {
1145
    /* Malformed input files can trigger this test.
1146
       cf PR 21781.  */
1147
2.80k
    _bfd_error_handler
1148
2.80k
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1149
2.80k
       abfd, found->symname);
1150
2.80k
    return false;
1151
2.80k
  }
1152
1153
      /* FIXME LATER: MSVC generates section names like .text for
1154
   comdats.  Gas generates names like .text$foo__Fv (in the case
1155
   of a function).  See comment above for more.  */
1156
1157
4.79k
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1158
  /* xgettext:c-format */
1159
2.87k
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1160
2.87k
            " does not match section name '%s'"),
1161
2.87k
          abfd, found->symname, name);
1162
1163
4.79k
      if (found->comdat_symbol != -1)
1164
1.63k
  {
1165
1.63k
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1166
1.63k
           found->comdat_symbol))
1167
0
      return false;
1168
1.63k
  }
1169
4.79k
      *sec_flags = *sec_flags | found->sec_flags;
1170
4.79k
      return true;
1171
4.79k
    }
1172
27.6k
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1173
27.6k
  return true;
1174
35.2k
}
pe-i386.c:handle_COMDAT
Line
Count
Source
1111
63.3k
{
1112
63.3k
  if (pe_data (abfd)->comdat_hash == NULL)
1113
44.0k
    {
1114
44.0k
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1115
44.0k
             comdat_delf);
1116
44.0k
      if (pe_data (abfd)->comdat_hash == NULL)
1117
0
  return false;
1118
44.0k
    }
1119
1120
63.3k
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1121
54.7k
    if (! fill_comdat_hash (abfd))
1122
0
      return false;
1123
1124
63.3k
  struct comdat_hash_entry *found
1125
63.3k
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1126
63.3k
  if (found != NULL)
1127
7.88k
    {
1128
7.88k
      struct internal_syment isym = found->isym;
1129
1130
      /* If it isn't the stuff we're expecting, die;  The MS
1131
   documentation is vague, but it appears that the second entry
1132
   serves BOTH as the comdat symbol and the defining symbol
1133
   record (either C_STAT or C_EXT, possibly with an aux entry
1134
   with debug information if it's a function.)  It appears the
1135
   only way to find the second one is to count.  (On Intel, they
1136
   appear to be adjacent, but on Alpha, they have been found
1137
   separated.)
1138
1139
   Here, we think we've found the first one, but there's some
1140
   checking we can do to be sure.  */
1141
1142
7.88k
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1143
7.88k
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1144
3.71k
  {
1145
    /* Malformed input files can trigger this test.
1146
       cf PR 21781.  */
1147
3.71k
    _bfd_error_handler
1148
3.71k
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1149
3.71k
       abfd, found->symname);
1150
3.71k
    return false;
1151
3.71k
  }
1152
1153
      /* FIXME LATER: MSVC generates section names like .text for
1154
   comdats.  Gas generates names like .text$foo__Fv (in the case
1155
   of a function).  See comment above for more.  */
1156
1157
4.17k
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1158
  /* xgettext:c-format */
1159
1.88k
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1160
1.88k
            " does not match section name '%s'"),
1161
1.88k
          abfd, found->symname, name);
1162
1163
4.17k
      if (found->comdat_symbol != -1)
1164
1.29k
  {
1165
1.29k
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1166
1.29k
           found->comdat_symbol))
1167
0
      return false;
1168
1.29k
  }
1169
4.17k
      *sec_flags = *sec_flags | found->sec_flags;
1170
4.17k
      return true;
1171
4.17k
    }
1172
55.4k
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1173
55.4k
  return true;
1174
63.3k
}
pe-mcore.c:handle_COMDAT
Line
Count
Source
1111
58.5k
{
1112
58.5k
  if (pe_data (abfd)->comdat_hash == NULL)
1113
35.7k
    {
1114
35.7k
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1115
35.7k
             comdat_delf);
1116
35.7k
      if (pe_data (abfd)->comdat_hash == NULL)
1117
0
  return false;
1118
35.7k
    }
1119
1120
58.5k
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1121
44.2k
    if (! fill_comdat_hash (abfd))
1122
0
      return false;
1123
1124
58.5k
  struct comdat_hash_entry *found
1125
58.5k
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1126
58.5k
  if (found != NULL)
1127
5.41k
    {
1128
5.41k
      struct internal_syment isym = found->isym;
1129
1130
      /* If it isn't the stuff we're expecting, die;  The MS
1131
   documentation is vague, but it appears that the second entry
1132
   serves BOTH as the comdat symbol and the defining symbol
1133
   record (either C_STAT or C_EXT, possibly with an aux entry
1134
   with debug information if it's a function.)  It appears the
1135
   only way to find the second one is to count.  (On Intel, they
1136
   appear to be adjacent, but on Alpha, they have been found
1137
   separated.)
1138
1139
   Here, we think we've found the first one, but there's some
1140
   checking we can do to be sure.  */
1141
1142
5.41k
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1143
5.41k
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1144
1.54k
  {
1145
    /* Malformed input files can trigger this test.
1146
       cf PR 21781.  */
1147
1.54k
    _bfd_error_handler
1148
1.54k
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1149
1.54k
       abfd, found->symname);
1150
1.54k
    return false;
1151
1.54k
  }
1152
1153
      /* FIXME LATER: MSVC generates section names like .text for
1154
   comdats.  Gas generates names like .text$foo__Fv (in the case
1155
   of a function).  See comment above for more.  */
1156
1157
3.87k
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1158
  /* xgettext:c-format */
1159
1.88k
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1160
1.88k
            " does not match section name '%s'"),
1161
1.88k
          abfd, found->symname, name);
1162
1163
3.87k
      if (found->comdat_symbol != -1)
1164
710
  {
1165
710
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1166
710
           found->comdat_symbol))
1167
0
      return false;
1168
710
  }
1169
3.87k
      *sec_flags = *sec_flags | found->sec_flags;
1170
3.87k
      return true;
1171
3.87k
    }
1172
53.1k
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1173
53.1k
  return true;
1174
58.5k
}
pe-sh.c:handle_COMDAT
Line
Count
Source
1111
50.9k
{
1112
50.9k
  if (pe_data (abfd)->comdat_hash == NULL)
1113
38.0k
    {
1114
38.0k
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1115
38.0k
             comdat_delf);
1116
38.0k
      if (pe_data (abfd)->comdat_hash == NULL)
1117
0
  return false;
1118
38.0k
    }
1119
1120
50.9k
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1121
44.5k
    if (! fill_comdat_hash (abfd))
1122
0
      return false;
1123
1124
50.9k
  struct comdat_hash_entry *found
1125
50.9k
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1126
50.9k
  if (found != NULL)
1127
6.26k
    {
1128
6.26k
      struct internal_syment isym = found->isym;
1129
1130
      /* If it isn't the stuff we're expecting, die;  The MS
1131
   documentation is vague, but it appears that the second entry
1132
   serves BOTH as the comdat symbol and the defining symbol
1133
   record (either C_STAT or C_EXT, possibly with an aux entry
1134
   with debug information if it's a function.)  It appears the
1135
   only way to find the second one is to count.  (On Intel, they
1136
   appear to be adjacent, but on Alpha, they have been found
1137
   separated.)
1138
1139
   Here, we think we've found the first one, but there's some
1140
   checking we can do to be sure.  */
1141
1142
6.26k
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1143
6.26k
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1144
2.76k
  {
1145
    /* Malformed input files can trigger this test.
1146
       cf PR 21781.  */
1147
2.76k
    _bfd_error_handler
1148
2.76k
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1149
2.76k
       abfd, found->symname);
1150
2.76k
    return false;
1151
2.76k
  }
1152
1153
      /* FIXME LATER: MSVC generates section names like .text for
1154
   comdats.  Gas generates names like .text$foo__Fv (in the case
1155
   of a function).  See comment above for more.  */
1156
1157
3.49k
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1158
  /* xgettext:c-format */
1159
1.56k
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1160
1.56k
            " does not match section name '%s'"),
1161
1.56k
          abfd, found->symname, name);
1162
1163
3.49k
      if (found->comdat_symbol != -1)
1164
1.01k
  {
1165
1.01k
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1166
1.01k
           found->comdat_symbol))
1167
0
      return false;
1168
1.01k
  }
1169
3.49k
      *sec_flags = *sec_flags | found->sec_flags;
1170
3.49k
      return true;
1171
3.49k
    }
1172
44.6k
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1173
44.6k
  return true;
1174
50.9k
}
pei-arm-wince.c:handle_COMDAT
Line
Count
Source
1111
94.6k
{
1112
94.6k
  if (pe_data (abfd)->comdat_hash == NULL)
1113
62.5k
    {
1114
62.5k
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1115
62.5k
             comdat_delf);
1116
62.5k
      if (pe_data (abfd)->comdat_hash == NULL)
1117
0
  return false;
1118
62.5k
    }
1119
1120
94.6k
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1121
74.9k
    if (! fill_comdat_hash (abfd))
1122
0
      return false;
1123
1124
94.6k
  struct comdat_hash_entry *found
1125
94.6k
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1126
94.6k
  if (found != NULL)
1127
17.4k
    {
1128
17.4k
      struct internal_syment isym = found->isym;
1129
1130
      /* If it isn't the stuff we're expecting, die;  The MS
1131
   documentation is vague, but it appears that the second entry
1132
   serves BOTH as the comdat symbol and the defining symbol
1133
   record (either C_STAT or C_EXT, possibly with an aux entry
1134
   with debug information if it's a function.)  It appears the
1135
   only way to find the second one is to count.  (On Intel, they
1136
   appear to be adjacent, but on Alpha, they have been found
1137
   separated.)
1138
1139
   Here, we think we've found the first one, but there's some
1140
   checking we can do to be sure.  */
1141
1142
17.4k
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1143
17.4k
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1144
7.94k
  {
1145
    /* Malformed input files can trigger this test.
1146
       cf PR 21781.  */
1147
7.94k
    _bfd_error_handler
1148
7.94k
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1149
7.94k
       abfd, found->symname);
1150
7.94k
    return false;
1151
7.94k
  }
1152
1153
      /* FIXME LATER: MSVC generates section names like .text for
1154
   comdats.  Gas generates names like .text$foo__Fv (in the case
1155
   of a function).  See comment above for more.  */
1156
1157
9.52k
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1158
  /* xgettext:c-format */
1159
5.12k
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1160
5.12k
            " does not match section name '%s'"),
1161
5.12k
          abfd, found->symname, name);
1162
1163
9.52k
      if (found->comdat_symbol != -1)
1164
3.00k
  {
1165
3.00k
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1166
3.00k
           found->comdat_symbol))
1167
0
      return false;
1168
3.00k
  }
1169
9.52k
      *sec_flags = *sec_flags | found->sec_flags;
1170
9.52k
      return true;
1171
9.52k
    }
1172
77.1k
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1173
77.1k
  return true;
1174
94.6k
}
pei-arm.c:handle_COMDAT
Line
Count
Source
1111
106k
{
1112
106k
  if (pe_data (abfd)->comdat_hash == NULL)
1113
72.7k
    {
1114
72.7k
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1115
72.7k
             comdat_delf);
1116
72.7k
      if (pe_data (abfd)->comdat_hash == NULL)
1117
0
  return false;
1118
72.7k
    }
1119
1120
106k
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1121
86.8k
    if (! fill_comdat_hash (abfd))
1122
0
      return false;
1123
1124
106k
  struct comdat_hash_entry *found
1125
106k
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1126
106k
  if (found != NULL)
1127
19.0k
    {
1128
19.0k
      struct internal_syment isym = found->isym;
1129
1130
      /* If it isn't the stuff we're expecting, die;  The MS
1131
   documentation is vague, but it appears that the second entry
1132
   serves BOTH as the comdat symbol and the defining symbol
1133
   record (either C_STAT or C_EXT, possibly with an aux entry
1134
   with debug information if it's a function.)  It appears the
1135
   only way to find the second one is to count.  (On Intel, they
1136
   appear to be adjacent, but on Alpha, they have been found
1137
   separated.)
1138
1139
   Here, we think we've found the first one, but there's some
1140
   checking we can do to be sure.  */
1141
1142
19.0k
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1143
19.0k
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1144
8.77k
  {
1145
    /* Malformed input files can trigger this test.
1146
       cf PR 21781.  */
1147
8.77k
    _bfd_error_handler
1148
8.77k
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1149
8.77k
       abfd, found->symname);
1150
8.77k
    return false;
1151
8.77k
  }
1152
1153
      /* FIXME LATER: MSVC generates section names like .text for
1154
   comdats.  Gas generates names like .text$foo__Fv (in the case
1155
   of a function).  See comment above for more.  */
1156
1157
10.2k
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1158
  /* xgettext:c-format */
1159
5.14k
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1160
5.14k
            " does not match section name '%s'"),
1161
5.14k
          abfd, found->symname, name);
1162
1163
10.2k
      if (found->comdat_symbol != -1)
1164
3.02k
  {
1165
3.02k
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1166
3.02k
           found->comdat_symbol))
1167
0
      return false;
1168
3.02k
  }
1169
10.2k
      *sec_flags = *sec_flags | found->sec_flags;
1170
10.2k
      return true;
1171
10.2k
    }
1172
87.9k
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1173
87.9k
  return true;
1174
106k
}
pei-mcore.c:handle_COMDAT
Line
Count
Source
1111
71.7k
{
1112
71.7k
  if (pe_data (abfd)->comdat_hash == NULL)
1113
45.3k
    {
1114
45.3k
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1115
45.3k
             comdat_delf);
1116
45.3k
      if (pe_data (abfd)->comdat_hash == NULL)
1117
0
  return false;
1118
45.3k
    }
1119
1120
71.7k
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1121
59.7k
    if (! fill_comdat_hash (abfd))
1122
0
      return false;
1123
1124
71.7k
  struct comdat_hash_entry *found
1125
71.7k
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1126
71.7k
  if (found != NULL)
1127
10.0k
    {
1128
10.0k
      struct internal_syment isym = found->isym;
1129
1130
      /* If it isn't the stuff we're expecting, die;  The MS
1131
   documentation is vague, but it appears that the second entry
1132
   serves BOTH as the comdat symbol and the defining symbol
1133
   record (either C_STAT or C_EXT, possibly with an aux entry
1134
   with debug information if it's a function.)  It appears the
1135
   only way to find the second one is to count.  (On Intel, they
1136
   appear to be adjacent, but on Alpha, they have been found
1137
   separated.)
1138
1139
   Here, we think we've found the first one, but there's some
1140
   checking we can do to be sure.  */
1141
1142
10.0k
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1143
10.0k
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1144
3.95k
  {
1145
    /* Malformed input files can trigger this test.
1146
       cf PR 21781.  */
1147
3.95k
    _bfd_error_handler
1148
3.95k
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1149
3.95k
       abfd, found->symname);
1150
3.95k
    return false;
1151
3.95k
  }
1152
1153
      /* FIXME LATER: MSVC generates section names like .text for
1154
   comdats.  Gas generates names like .text$foo__Fv (in the case
1155
   of a function).  See comment above for more.  */
1156
1157
6.07k
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1158
  /* xgettext:c-format */
1159
3.17k
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1160
3.17k
            " does not match section name '%s'"),
1161
3.17k
          abfd, found->symname, name);
1162
1163
6.07k
      if (found->comdat_symbol != -1)
1164
1.51k
  {
1165
1.51k
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1166
1.51k
           found->comdat_symbol))
1167
0
      return false;
1168
1.51k
  }
1169
6.07k
      *sec_flags = *sec_flags | found->sec_flags;
1170
6.07k
      return true;
1171
6.07k
    }
1172
61.6k
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1173
61.6k
  return true;
1174
71.7k
}
pei-sh.c:handle_COMDAT
Line
Count
Source
1111
84.7k
{
1112
84.7k
  if (pe_data (abfd)->comdat_hash == NULL)
1113
48.7k
    {
1114
48.7k
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1115
48.7k
             comdat_delf);
1116
48.7k
      if (pe_data (abfd)->comdat_hash == NULL)
1117
0
  return false;
1118
48.7k
    }
1119
1120
84.7k
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1121
62.5k
    if (! fill_comdat_hash (abfd))
1122
0
      return false;
1123
1124
84.7k
  struct comdat_hash_entry *found
1125
84.7k
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1126
84.7k
  if (found != NULL)
1127
15.7k
    {
1128
15.7k
      struct internal_syment isym = found->isym;
1129
1130
      /* If it isn't the stuff we're expecting, die;  The MS
1131
   documentation is vague, but it appears that the second entry
1132
   serves BOTH as the comdat symbol and the defining symbol
1133
   record (either C_STAT or C_EXT, possibly with an aux entry
1134
   with debug information if it's a function.)  It appears the
1135
   only way to find the second one is to count.  (On Intel, they
1136
   appear to be adjacent, but on Alpha, they have been found
1137
   separated.)
1138
1139
   Here, we think we've found the first one, but there's some
1140
   checking we can do to be sure.  */
1141
1142
15.7k
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1143
15.7k
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1144
4.93k
  {
1145
    /* Malformed input files can trigger this test.
1146
       cf PR 21781.  */
1147
4.93k
    _bfd_error_handler
1148
4.93k
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1149
4.93k
       abfd, found->symname);
1150
4.93k
    return false;
1151
4.93k
  }
1152
1153
      /* FIXME LATER: MSVC generates section names like .text for
1154
   comdats.  Gas generates names like .text$foo__Fv (in the case
1155
   of a function).  See comment above for more.  */
1156
1157
10.8k
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1158
  /* xgettext:c-format */
1159
6.41k
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1160
6.41k
            " does not match section name '%s'"),
1161
6.41k
          abfd, found->symname, name);
1162
1163
10.8k
      if (found->comdat_symbol != -1)
1164
3.41k
  {
1165
3.41k
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1166
3.41k
           found->comdat_symbol))
1167
0
      return false;
1168
3.41k
  }
1169
10.8k
      *sec_flags = *sec_flags | found->sec_flags;
1170
10.8k
      return true;
1171
10.8k
    }
1172
69.0k
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1173
69.0k
  return true;
1174
84.7k
}
1175
1176
1177
/* The PE version; see above for the general comments.
1178
1179
   Since to set the SEC_LINK_ONCE and associated flags, we have to
1180
   look at the symbol table anyway, we return the symbol table index
1181
   of the symbol being used as the COMDAT symbol.  This is admittedly
1182
   ugly, but there's really nowhere else that we have access to the
1183
   required information.  FIXME: Is the COMDAT symbol index used for
1184
   any purpose other than objdump?  */
1185
1186
static bool
1187
styp_to_sec_flags (bfd *abfd,
1188
       void * hdr,
1189
       const char *name,
1190
       asection *section,
1191
       flagword *flags_ptr)
1192
5.50M
{
1193
5.50M
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1194
5.50M
  unsigned long styp_flags = internal_s->s_flags;
1195
5.50M
  flagword sec_flags;
1196
5.50M
  bool result = true;
1197
5.50M
  bool is_dbg = false;
1198
1199
5.50M
  if (startswith (name, DOT_DEBUG)
1200
5.50M
      || startswith (name, DOT_ZDEBUG)
1201
5.50M
#ifdef COFF_LONG_SECTION_NAMES
1202
5.50M
      || startswith (name, GNU_LINKONCE_WI)
1203
5.50M
      || startswith (name, GNU_LINKONCE_WT)
1204
      /* FIXME: These definitions ought to be in a header file.  */
1205
5.50M
#define GNU_DEBUGLINK   ".gnu_debuglink"
1206
5.50M
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1207
5.50M
      || startswith (name, GNU_DEBUGLINK)
1208
5.50M
      || startswith (name, GNU_DEBUGALTLINK)
1209
5.50M
#endif
1210
5.50M
      || startswith (name, ".stab"))
1211
284k
    is_dbg = true;
1212
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1213
5.50M
  sec_flags = SEC_READONLY;
1214
1215
  /* If section disallows read, then set the NOREAD flag. */
1216
5.50M
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1217
4.37M
    sec_flags |= SEC_COFF_NOREAD;
1218
1219
  /* Process each flag bit in styp_flags in turn.  */
1220
35.7M
  while (styp_flags)
1221
30.2M
    {
1222
30.2M
      unsigned long flag = styp_flags & - styp_flags;
1223
30.2M
      char * unhandled = NULL;
1224
1225
30.2M
      styp_flags &= ~ flag;
1226
1227
      /* We infer from the distinct read/write/execute bits the settings
1228
   of some of the bfd flags; the actual values, should we need them,
1229
   are also in pei_section_data (abfd, section)->pe_flags.  */
1230
1231
30.2M
      switch (flag)
1232
30.2M
  {
1233
424k
  case STYP_DSECT:
1234
424k
    unhandled = "STYP_DSECT";
1235
424k
    break;
1236
405k
  case STYP_GROUP:
1237
405k
    unhandled = "STYP_GROUP";
1238
405k
    break;
1239
458k
  case STYP_COPY:
1240
458k
    unhandled = "STYP_COPY";
1241
458k
    break;
1242
443k
  case STYP_OVER:
1243
443k
    unhandled = "STYP_OVER";
1244
443k
    break;
1245
0
#ifdef SEC_NEVER_LOAD
1246
988k
  case STYP_NOLOAD:
1247
988k
    sec_flags |= SEC_NEVER_LOAD;
1248
988k
    break;
1249
0
#endif
1250
1.13M
  case IMAGE_SCN_MEM_READ:
1251
1.13M
    sec_flags &= ~SEC_COFF_NOREAD;
1252
1.13M
    break;
1253
935k
  case IMAGE_SCN_TYPE_NO_PAD:
1254
    /* Skip.  */
1255
935k
    break;
1256
449k
  case IMAGE_SCN_LNK_OTHER:
1257
449k
    unhandled = "IMAGE_SCN_LNK_OTHER";
1258
449k
    break;
1259
411k
  case IMAGE_SCN_MEM_NOT_CACHED:
1260
411k
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1261
411k
    break;
1262
1.14M
  case IMAGE_SCN_MEM_NOT_PAGED:
1263
    /* Generate a warning message rather using the 'unhandled'
1264
       variable as this will allow some .sys files generate by
1265
       other toolchains to be processed.  See bugzilla issue 196.  */
1266
    /* xgettext:c-format */
1267
1.14M
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1268
1.14M
        " %s in section %s"),
1269
1.14M
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1270
1.14M
    break;
1271
1.33M
  case IMAGE_SCN_MEM_EXECUTE:
1272
1.33M
    sec_flags |= SEC_CODE;
1273
1.33M
    break;
1274
906k
  case IMAGE_SCN_MEM_WRITE:
1275
906k
    sec_flags &= ~ SEC_READONLY;
1276
906k
    break;
1277
1.32M
  case IMAGE_SCN_MEM_DISCARDABLE:
1278
    /* The MS PE spec says that debug sections are DISCARDABLE,
1279
       but the presence of a DISCARDABLE flag does not necessarily
1280
       mean that a given section contains debug information.  Thus
1281
       we only set the SEC_DEBUGGING flag on sections that we
1282
       recognise as containing debug information.  */
1283
1.32M
       if (is_dbg
1284
1.32M
#ifdef _COMMENT
1285
1.32M
        || strcmp (name, _COMMENT) == 0
1286
1.32M
#endif
1287
1.32M
        )
1288
170k
      {
1289
170k
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1290
170k
      }
1291
1.32M
    break;
1292
878k
  case IMAGE_SCN_MEM_SHARED:
1293
878k
    sec_flags |= SEC_COFF_SHARED;
1294
878k
    break;
1295
1.25M
  case IMAGE_SCN_LNK_REMOVE:
1296
1.25M
    if (!is_dbg)
1297
1.13M
      sec_flags |= SEC_EXCLUDE;
1298
1.25M
    break;
1299
1.11M
  case IMAGE_SCN_CNT_CODE:
1300
1.11M
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1301
1.11M
    break;
1302
864k
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1303
864k
    if (is_dbg)
1304
89.7k
      sec_flags |= SEC_DEBUGGING;
1305
774k
    else
1306
774k
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1307
864k
    break;
1308
735k
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1309
735k
    sec_flags |= SEC_ALLOC;
1310
735k
    break;
1311
1.20M
  case IMAGE_SCN_LNK_INFO:
1312
    /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
1313
       defined.  coff_compute_section_file_positions uses
1314
       COFF_PAGE_SIZE to ensure that the low order bits of the
1315
       section VMA and the file offset match.  If we don't know
1316
       COFF_PAGE_SIZE, we can't ensure the correct correspondence,
1317
       and demand page loading of the file will fail.  */
1318
#ifdef COFF_PAGE_SIZE
1319
1.09M
    sec_flags |= SEC_DEBUGGING;
1320
#endif
1321
1.20M
    break;
1322
1.35M
  case IMAGE_SCN_LNK_COMDAT:
1323
    /* COMDAT gets very special treatment.  */
1324
1.35M
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1325
82.7k
      result = false;
1326
1.35M
    break;
1327
12.4M
  default:
1328
    /* Silently ignore for now.  */
1329
12.4M
    break;
1330
30.2M
  }
1331
1332
      /* If the section flag was not handled, report it here.  */
1333
30.2M
      if (unhandled != NULL)
1334
2.59M
  {
1335
2.59M
    _bfd_error_handler
1336
      /* xgettext:c-format */
1337
2.59M
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1338
2.59M
       abfd, name, unhandled, flag);
1339
2.59M
    result = false;
1340
2.59M
  }
1341
30.2M
    }
1342
1343
5.50M
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1344
5.50M
      && (startswith (name, ".sbss")
1345
0
    || startswith (name, ".sdata")))
1346
0
    sec_flags |= SEC_SMALL_DATA;
1347
1348
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
1349
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
1350
     only link a single copy of the section.  This is used to support
1351
     g++.  g++ will emit each template expansion in its own section.
1352
     The symbols will be defined as weak, so that multiple definitions
1353
     are permitted.  The GNU linker extension is to actually discard
1354
     all but one of the sections.  */
1355
2.27M
  if (startswith (name, ".gnu.linkonce"))
1356
2.70k
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
1357
#endif
1358
1359
5.50M
  if (flags_ptr)
1360
5.50M
    * flags_ptr = sec_flags;
1361
1362
5.50M
  return result;
1363
5.50M
}
pei-i386.c:styp_to_sec_flags
Line
Count
Source
1192
452k
{
1193
452k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1194
452k
  unsigned long styp_flags = internal_s->s_flags;
1195
452k
  flagword sec_flags;
1196
452k
  bool result = true;
1197
452k
  bool is_dbg = false;
1198
1199
452k
  if (startswith (name, DOT_DEBUG)
1200
452k
      || startswith (name, DOT_ZDEBUG)
1201
452k
#ifdef COFF_LONG_SECTION_NAMES
1202
452k
      || startswith (name, GNU_LINKONCE_WI)
1203
452k
      || startswith (name, GNU_LINKONCE_WT)
1204
      /* FIXME: These definitions ought to be in a header file.  */
1205
452k
#define GNU_DEBUGLINK   ".gnu_debuglink"
1206
452k
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1207
452k
      || startswith (name, GNU_DEBUGLINK)
1208
452k
      || startswith (name, GNU_DEBUGALTLINK)
1209
452k
#endif
1210
452k
      || startswith (name, ".stab"))
1211
19.4k
    is_dbg = true;
1212
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1213
452k
  sec_flags = SEC_READONLY;
1214
1215
  /* If section disallows read, then set the NOREAD flag. */
1216
452k
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1217
376k
    sec_flags |= SEC_COFF_NOREAD;
1218
1219
  /* Process each flag bit in styp_flags in turn.  */
1220
2.58M
  while (styp_flags)
1221
2.12M
    {
1222
2.12M
      unsigned long flag = styp_flags & - styp_flags;
1223
2.12M
      char * unhandled = NULL;
1224
1225
2.12M
      styp_flags &= ~ flag;
1226
1227
      /* We infer from the distinct read/write/execute bits the settings
1228
   of some of the bfd flags; the actual values, should we need them,
1229
   are also in pei_section_data (abfd, section)->pe_flags.  */
1230
1231
2.12M
      switch (flag)
1232
2.12M
  {
1233
21.8k
  case STYP_DSECT:
1234
21.8k
    unhandled = "STYP_DSECT";
1235
21.8k
    break;
1236
20.7k
  case STYP_GROUP:
1237
20.7k
    unhandled = "STYP_GROUP";
1238
20.7k
    break;
1239
23.2k
  case STYP_COPY:
1240
23.2k
    unhandled = "STYP_COPY";
1241
23.2k
    break;
1242
25.0k
  case STYP_OVER:
1243
25.0k
    unhandled = "STYP_OVER";
1244
25.0k
    break;
1245
0
#ifdef SEC_NEVER_LOAD
1246
57.0k
  case STYP_NOLOAD:
1247
57.0k
    sec_flags |= SEC_NEVER_LOAD;
1248
57.0k
    break;
1249
0
#endif
1250
75.9k
  case IMAGE_SCN_MEM_READ:
1251
75.9k
    sec_flags &= ~SEC_COFF_NOREAD;
1252
75.9k
    break;
1253
54.9k
  case IMAGE_SCN_TYPE_NO_PAD:
1254
    /* Skip.  */
1255
54.9k
    break;
1256
21.4k
  case IMAGE_SCN_LNK_OTHER:
1257
21.4k
    unhandled = "IMAGE_SCN_LNK_OTHER";
1258
21.4k
    break;
1259
19.6k
  case IMAGE_SCN_MEM_NOT_CACHED:
1260
19.6k
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1261
19.6k
    break;
1262
72.7k
  case IMAGE_SCN_MEM_NOT_PAGED:
1263
    /* Generate a warning message rather using the 'unhandled'
1264
       variable as this will allow some .sys files generate by
1265
       other toolchains to be processed.  See bugzilla issue 196.  */
1266
    /* xgettext:c-format */
1267
72.7k
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1268
72.7k
        " %s in section %s"),
1269
72.7k
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1270
72.7k
    break;
1271
132k
  case IMAGE_SCN_MEM_EXECUTE:
1272
132k
    sec_flags |= SEC_CODE;
1273
132k
    break;
1274
101k
  case IMAGE_SCN_MEM_WRITE:
1275
101k
    sec_flags &= ~ SEC_READONLY;
1276
101k
    break;
1277
90.3k
  case IMAGE_SCN_MEM_DISCARDABLE:
1278
    /* The MS PE spec says that debug sections are DISCARDABLE,
1279
       but the presence of a DISCARDABLE flag does not necessarily
1280
       mean that a given section contains debug information.  Thus
1281
       we only set the SEC_DEBUGGING flag on sections that we
1282
       recognise as containing debug information.  */
1283
90.3k
       if (is_dbg
1284
90.3k
#ifdef _COMMENT
1285
90.3k
        || strcmp (name, _COMMENT) == 0
1286
90.3k
#endif
1287
90.3k
        )
1288
11.5k
      {
1289
11.5k
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1290
11.5k
      }
1291
90.3k
    break;
1292
59.5k
  case IMAGE_SCN_MEM_SHARED:
1293
59.5k
    sec_flags |= SEC_COFF_SHARED;
1294
59.5k
    break;
1295
84.8k
  case IMAGE_SCN_LNK_REMOVE:
1296
84.8k
    if (!is_dbg)
1297
77.4k
      sec_flags |= SEC_EXCLUDE;
1298
84.8k
    break;
1299
76.3k
  case IMAGE_SCN_CNT_CODE:
1300
76.3k
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1301
76.3k
    break;
1302
58.0k
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1303
58.0k
    if (is_dbg)
1304
6.58k
      sec_flags |= SEC_DEBUGGING;
1305
51.5k
    else
1306
51.5k
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1307
58.0k
    break;
1308
51.2k
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1309
51.2k
    sec_flags |= SEC_ALLOC;
1310
51.2k
    break;
1311
68.7k
  case IMAGE_SCN_LNK_INFO:
1312
    /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
1313
       defined.  coff_compute_section_file_positions uses
1314
       COFF_PAGE_SIZE to ensure that the low order bits of the
1315
       section VMA and the file offset match.  If we don't know
1316
       COFF_PAGE_SIZE, we can't ensure the correct correspondence,
1317
       and demand page loading of the file will fail.  */
1318
68.7k
#ifdef COFF_PAGE_SIZE
1319
68.7k
    sec_flags |= SEC_DEBUGGING;
1320
68.7k
#endif
1321
68.7k
    break;
1322
103k
  case IMAGE_SCN_LNK_COMDAT:
1323
    /* COMDAT gets very special treatment.  */
1324
103k
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1325
5.04k
      result = false;
1326
103k
    break;
1327
907k
  default:
1328
    /* Silently ignore for now.  */
1329
907k
    break;
1330
2.12M
  }
1331
1332
      /* If the section flag was not handled, report it here.  */
1333
2.12M
      if (unhandled != NULL)
1334
131k
  {
1335
131k
    _bfd_error_handler
1336
      /* xgettext:c-format */
1337
131k
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1338
131k
       abfd, name, unhandled, flag);
1339
131k
    result = false;
1340
131k
  }
1341
2.12M
    }
1342
1343
452k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1344
452k
      && (startswith (name, ".sbss")
1345
0
    || startswith (name, ".sdata")))
1346
0
    sec_flags |= SEC_SMALL_DATA;
1347
1348
452k
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
1349
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
1350
     only link a single copy of the section.  This is used to support
1351
     g++.  g++ will emit each template expansion in its own section.
1352
     The symbols will be defined as weak, so that multiple definitions
1353
     are permitted.  The GNU linker extension is to actually discard
1354
     all but one of the sections.  */
1355
452k
  if (startswith (name, ".gnu.linkonce"))
1356
128
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
1357
452k
#endif
1358
1359
452k
  if (flags_ptr)
1360
452k
    * flags_ptr = sec_flags;
1361
1362
452k
  return result;
1363
452k
}
pe-x86_64.c:styp_to_sec_flags
Line
Count
Source
1192
1.19M
{
1193
1.19M
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1194
1.19M
  unsigned long styp_flags = internal_s->s_flags;
1195
1.19M
  flagword sec_flags;
1196
1.19M
  bool result = true;
1197
1.19M
  bool is_dbg = false;
1198
1199
1.19M
  if (startswith (name, DOT_DEBUG)
1200
1.19M
      || startswith (name, DOT_ZDEBUG)
1201
1.19M
#ifdef COFF_LONG_SECTION_NAMES
1202
1.19M
      || startswith (name, GNU_LINKONCE_WI)
1203
1.19M
      || startswith (name, GNU_LINKONCE_WT)
1204
      /* FIXME: These definitions ought to be in a header file.  */
1205
1.19M
#define GNU_DEBUGLINK   ".gnu_debuglink"
1206
1.19M
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1207
1.19M
      || startswith (name, GNU_DEBUGLINK)
1208
1.19M
      || startswith (name, GNU_DEBUGALTLINK)
1209
1.19M
#endif
1210
1.19M
      || startswith (name, ".stab"))
1211
39.2k
    is_dbg = true;
1212
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1213
1.19M
  sec_flags = SEC_READONLY;
1214
1215
  /* If section disallows read, then set the NOREAD flag. */
1216
1.19M
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1217
1.07M
    sec_flags |= SEC_COFF_NOREAD;
1218
1219
  /* Process each flag bit in styp_flags in turn.  */
1220
5.35M
  while (styp_flags)
1221
4.15M
    {
1222
4.15M
      unsigned long flag = styp_flags & - styp_flags;
1223
4.15M
      char * unhandled = NULL;
1224
1225
4.15M
      styp_flags &= ~ flag;
1226
1227
      /* We infer from the distinct read/write/execute bits the settings
1228
   of some of the bfd flags; the actual values, should we need them,
1229
   are also in pei_section_data (abfd, section)->pe_flags.  */
1230
1231
4.15M
      switch (flag)
1232
4.15M
  {
1233
78.8k
  case STYP_DSECT:
1234
78.8k
    unhandled = "STYP_DSECT";
1235
78.8k
    break;
1236
77.0k
  case STYP_GROUP:
1237
77.0k
    unhandled = "STYP_GROUP";
1238
77.0k
    break;
1239
87.8k
  case STYP_COPY:
1240
87.8k
    unhandled = "STYP_COPY";
1241
87.8k
    break;
1242
72.6k
  case STYP_OVER:
1243
72.6k
    unhandled = "STYP_OVER";
1244
72.6k
    break;
1245
0
#ifdef SEC_NEVER_LOAD
1246
187k
  case STYP_NOLOAD:
1247
187k
    sec_flags |= SEC_NEVER_LOAD;
1248
187k
    break;
1249
0
#endif
1250
117k
  case IMAGE_SCN_MEM_READ:
1251
117k
    sec_flags &= ~SEC_COFF_NOREAD;
1252
117k
    break;
1253
176k
  case IMAGE_SCN_TYPE_NO_PAD:
1254
    /* Skip.  */
1255
176k
    break;
1256
84.3k
  case IMAGE_SCN_LNK_OTHER:
1257
84.3k
    unhandled = "IMAGE_SCN_LNK_OTHER";
1258
84.3k
    break;
1259
68.1k
  case IMAGE_SCN_MEM_NOT_CACHED:
1260
68.1k
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1261
68.1k
    break;
1262
189k
  case IMAGE_SCN_MEM_NOT_PAGED:
1263
    /* Generate a warning message rather using the 'unhandled'
1264
       variable as this will allow some .sys files generate by
1265
       other toolchains to be processed.  See bugzilla issue 196.  */
1266
    /* xgettext:c-format */
1267
189k
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1268
189k
        " %s in section %s"),
1269
189k
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1270
189k
    break;
1271
147k
  case IMAGE_SCN_MEM_EXECUTE:
1272
147k
    sec_flags |= SEC_CODE;
1273
147k
    break;
1274
87.3k
  case IMAGE_SCN_MEM_WRITE:
1275
87.3k
    sec_flags &= ~ SEC_READONLY;
1276
87.3k
    break;
1277
195k
  case IMAGE_SCN_MEM_DISCARDABLE:
1278
    /* The MS PE spec says that debug sections are DISCARDABLE,
1279
       but the presence of a DISCARDABLE flag does not necessarily
1280
       mean that a given section contains debug information.  Thus
1281
       we only set the SEC_DEBUGGING flag on sections that we
1282
       recognise as containing debug information.  */
1283
195k
       if (is_dbg
1284
195k
#ifdef _COMMENT
1285
195k
        || strcmp (name, _COMMENT) == 0
1286
195k
#endif
1287
195k
        )
1288
16.0k
      {
1289
16.0k
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1290
16.0k
      }
1291
195k
    break;
1292
127k
  case IMAGE_SCN_MEM_SHARED:
1293
127k
    sec_flags |= SEC_COFF_SHARED;
1294
127k
    break;
1295
185k
  case IMAGE_SCN_LNK_REMOVE:
1296
185k
    if (!is_dbg)
1297
175k
      sec_flags |= SEC_EXCLUDE;
1298
185k
    break;
1299
150k
  case IMAGE_SCN_CNT_CODE:
1300
150k
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1301
150k
    break;
1302
109k
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1303
109k
    if (is_dbg)
1304
8.08k
      sec_flags |= SEC_DEBUGGING;
1305
101k
    else
1306
101k
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1307
109k
    break;
1308
81.4k
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1309
81.4k
    sec_flags |= SEC_ALLOC;
1310
81.4k
    break;
1311
187k
  case IMAGE_SCN_LNK_INFO:
1312
    /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
1313
       defined.  coff_compute_section_file_positions uses
1314
       COFF_PAGE_SIZE to ensure that the low order bits of the
1315
       section VMA and the file offset match.  If we don't know
1316
       COFF_PAGE_SIZE, we can't ensure the correct correspondence,
1317
       and demand page loading of the file will fail.  */
1318
187k
#ifdef COFF_PAGE_SIZE
1319
187k
    sec_flags |= SEC_DEBUGGING;
1320
187k
#endif
1321
187k
    break;
1322
168k
  case IMAGE_SCN_LNK_COMDAT:
1323
    /* COMDAT gets very special treatment.  */
1324
168k
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1325
8.79k
      result = false;
1326
168k
    break;
1327
1.57M
  default:
1328
    /* Silently ignore for now.  */
1329
1.57M
    break;
1330
4.15M
  }
1331
1332
      /* If the section flag was not handled, report it here.  */
1333
4.15M
      if (unhandled != NULL)
1334
468k
  {
1335
468k
    _bfd_error_handler
1336
      /* xgettext:c-format */
1337
468k
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1338
468k
       abfd, name, unhandled, flag);
1339
468k
    result = false;
1340
468k
  }
1341
4.15M
    }
1342
1343
1.19M
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1344
1.19M
      && (startswith (name, ".sbss")
1345
0
    || startswith (name, ".sdata")))
1346
0
    sec_flags |= SEC_SMALL_DATA;
1347
1348
1.19M
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
1349
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
1350
     only link a single copy of the section.  This is used to support
1351
     g++.  g++ will emit each template expansion in its own section.
1352
     The symbols will be defined as weak, so that multiple definitions
1353
     are permitted.  The GNU linker extension is to actually discard
1354
     all but one of the sections.  */
1355
1.19M
  if (startswith (name, ".gnu.linkonce"))
1356
0
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
1357
1.19M
#endif
1358
1359
1.19M
  if (flags_ptr)
1360
1.19M
    * flags_ptr = sec_flags;
1361
1362
1.19M
  return result;
1363
1.19M
}
pei-x86_64.c:styp_to_sec_flags
Line
Count
Source
1192
432k
{
1193
432k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1194
432k
  unsigned long styp_flags = internal_s->s_flags;
1195
432k
  flagword sec_flags;
1196
432k
  bool result = true;
1197
432k
  bool is_dbg = false;
1198
1199
432k
  if (startswith (name, DOT_DEBUG)
1200
432k
      || startswith (name, DOT_ZDEBUG)
1201
432k
#ifdef COFF_LONG_SECTION_NAMES
1202
432k
      || startswith (name, GNU_LINKONCE_WI)
1203
432k
      || startswith (name, GNU_LINKONCE_WT)
1204
      /* FIXME: These definitions ought to be in a header file.  */
1205
432k
#define GNU_DEBUGLINK   ".gnu_debuglink"
1206
432k
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1207
432k
      || startswith (name, GNU_DEBUGLINK)
1208
432k
      || startswith (name, GNU_DEBUGALTLINK)
1209
432k
#endif
1210
432k
      || startswith (name, ".stab"))
1211
42.2k
    is_dbg = true;
1212
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1213
432k
  sec_flags = SEC_READONLY;
1214
1215
  /* If section disallows read, then set the NOREAD flag. */
1216
432k
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1217
339k
    sec_flags |= SEC_COFF_NOREAD;
1218
1219
  /* Process each flag bit in styp_flags in turn.  */
1220
2.57M
  while (styp_flags)
1221
2.14M
    {
1222
2.14M
      unsigned long flag = styp_flags & - styp_flags;
1223
2.14M
      char * unhandled = NULL;
1224
1225
2.14M
      styp_flags &= ~ flag;
1226
1227
      /* We infer from the distinct read/write/execute bits the settings
1228
   of some of the bfd flags; the actual values, should we need them,
1229
   are also in pei_section_data (abfd, section)->pe_flags.  */
1230
1231
2.14M
      switch (flag)
1232
2.14M
  {
1233
20.0k
  case STYP_DSECT:
1234
20.0k
    unhandled = "STYP_DSECT";
1235
20.0k
    break;
1236
18.4k
  case STYP_GROUP:
1237
18.4k
    unhandled = "STYP_GROUP";
1238
18.4k
    break;
1239
22.2k
  case STYP_COPY:
1240
22.2k
    unhandled = "STYP_COPY";
1241
22.2k
    break;
1242
22.7k
  case STYP_OVER:
1243
22.7k
    unhandled = "STYP_OVER";
1244
22.7k
    break;
1245
0
#ifdef SEC_NEVER_LOAD
1246
60.4k
  case STYP_NOLOAD:
1247
60.4k
    sec_flags |= SEC_NEVER_LOAD;
1248
60.4k
    break;
1249
0
#endif
1250
93.9k
  case IMAGE_SCN_MEM_READ:
1251
93.9k
    sec_flags &= ~SEC_COFF_NOREAD;
1252
93.9k
    break;
1253
46.1k
  case IMAGE_SCN_TYPE_NO_PAD:
1254
    /* Skip.  */
1255
46.1k
    break;
1256
20.8k
  case IMAGE_SCN_LNK_OTHER:
1257
20.8k
    unhandled = "IMAGE_SCN_LNK_OTHER";
1258
20.8k
    break;
1259
20.3k
  case IMAGE_SCN_MEM_NOT_CACHED:
1260
20.3k
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1261
20.3k
    break;
1262
88.3k
  case IMAGE_SCN_MEM_NOT_PAGED:
1263
    /* Generate a warning message rather using the 'unhandled'
1264
       variable as this will allow some .sys files generate by
1265
       other toolchains to be processed.  See bugzilla issue 196.  */
1266
    /* xgettext:c-format */
1267
88.3k
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1268
88.3k
        " %s in section %s"),
1269
88.3k
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1270
88.3k
    break;
1271
86.0k
  case IMAGE_SCN_MEM_EXECUTE:
1272
86.0k
    sec_flags |= SEC_CODE;
1273
86.0k
    break;
1274
44.9k
  case IMAGE_SCN_MEM_WRITE:
1275
44.9k
    sec_flags &= ~ SEC_READONLY;
1276
44.9k
    break;
1277
106k
  case IMAGE_SCN_MEM_DISCARDABLE:
1278
    /* The MS PE spec says that debug sections are DISCARDABLE,
1279
       but the presence of a DISCARDABLE flag does not necessarily
1280
       mean that a given section contains debug information.  Thus
1281
       we only set the SEC_DEBUGGING flag on sections that we
1282
       recognise as containing debug information.  */
1283
106k
       if (is_dbg
1284
106k
#ifdef _COMMENT
1285
106k
        || strcmp (name, _COMMENT) == 0
1286
106k
#endif
1287
106k
        )
1288
26.4k
      {
1289
26.4k
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1290
26.4k
      }
1291
106k
    break;
1292
69.6k
  case IMAGE_SCN_MEM_SHARED:
1293
69.6k
    sec_flags |= SEC_COFF_SHARED;
1294
69.6k
    break;
1295
106k
  case IMAGE_SCN_LNK_REMOVE:
1296
106k
    if (!is_dbg)
1297
77.0k
      sec_flags |= SEC_EXCLUDE;
1298
106k
    break;
1299
94.4k
  case IMAGE_SCN_CNT_CODE:
1300
94.4k
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1301
94.4k
    break;
1302
53.9k
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1303
53.9k
    if (is_dbg)
1304
9.99k
      sec_flags |= SEC_DEBUGGING;
1305
43.9k
    else
1306
43.9k
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1307
53.9k
    break;
1308
38.5k
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1309
38.5k
    sec_flags |= SEC_ALLOC;
1310
38.5k
    break;
1311
103k
  case IMAGE_SCN_LNK_INFO:
1312
    /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
1313
       defined.  coff_compute_section_file_positions uses
1314
       COFF_PAGE_SIZE to ensure that the low order bits of the
1315
       section VMA and the file offset match.  If we don't know
1316
       COFF_PAGE_SIZE, we can't ensure the correct correspondence,
1317
       and demand page loading of the file will fail.  */
1318
103k
#ifdef COFF_PAGE_SIZE
1319
103k
    sec_flags |= SEC_DEBUGGING;
1320
103k
#endif
1321
103k
    break;
1322
117k
  case IMAGE_SCN_LNK_COMDAT:
1323
    /* COMDAT gets very special treatment.  */
1324
117k
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1325
4.28k
      result = false;
1326
117k
    break;
1327
910k
  default:
1328
    /* Silently ignore for now.  */
1329
910k
    break;
1330
2.14M
  }
1331
1332
      /* If the section flag was not handled, report it here.  */
1333
2.14M
      if (unhandled != NULL)
1334
124k
  {
1335
124k
    _bfd_error_handler
1336
      /* xgettext:c-format */
1337
124k
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1338
124k
       abfd, name, unhandled, flag);
1339
124k
    result = false;
1340
124k
  }
1341
2.14M
    }
1342
1343
432k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1344
432k
      && (startswith (name, ".sbss")
1345
0
    || startswith (name, ".sdata")))
1346
0
    sec_flags |= SEC_SMALL_DATA;
1347
1348
432k
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
1349
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
1350
     only link a single copy of the section.  This is used to support
1351
     g++.  g++ will emit each template expansion in its own section.
1352
     The symbols will be defined as weak, so that multiple definitions
1353
     are permitted.  The GNU linker extension is to actually discard
1354
     all but one of the sections.  */
1355
432k
  if (startswith (name, ".gnu.linkonce"))
1356
580
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
1357
432k
#endif
1358
1359
432k
  if (flags_ptr)
1360
432k
    * flags_ptr = sec_flags;
1361
1362
432k
  return result;
1363
432k
}
pe-aarch64.c:styp_to_sec_flags
Line
Count
Source
1192
276k
{
1193
276k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1194
276k
  unsigned long styp_flags = internal_s->s_flags;
1195
276k
  flagword sec_flags;
1196
276k
  bool result = true;
1197
276k
  bool is_dbg = false;
1198
1199
276k
  if (startswith (name, DOT_DEBUG)
1200
276k
      || startswith (name, DOT_ZDEBUG)
1201
276k
#ifdef COFF_LONG_SECTION_NAMES
1202
276k
      || startswith (name, GNU_LINKONCE_WI)
1203
276k
      || startswith (name, GNU_LINKONCE_WT)
1204
      /* FIXME: These definitions ought to be in a header file.  */
1205
276k
#define GNU_DEBUGLINK   ".gnu_debuglink"
1206
276k
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1207
276k
      || startswith (name, GNU_DEBUGLINK)
1208
276k
      || startswith (name, GNU_DEBUGALTLINK)
1209
276k
#endif
1210
276k
      || startswith (name, ".stab"))
1211
6.92k
    is_dbg = true;
1212
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1213
276k
  sec_flags = SEC_READONLY;
1214
1215
  /* If section disallows read, then set the NOREAD flag. */
1216
276k
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1217
236k
    sec_flags |= SEC_COFF_NOREAD;
1218
1219
  /* Process each flag bit in styp_flags in turn.  */
1220
1.19M
  while (styp_flags)
1221
917k
    {
1222
917k
      unsigned long flag = styp_flags & - styp_flags;
1223
917k
      char * unhandled = NULL;
1224
1225
917k
      styp_flags &= ~ flag;
1226
1227
      /* We infer from the distinct read/write/execute bits the settings
1228
   of some of the bfd flags; the actual values, should we need them,
1229
   are also in pei_section_data (abfd, section)->pe_flags.  */
1230
1231
917k
      switch (flag)
1232
917k
  {
1233
8.46k
  case STYP_DSECT:
1234
8.46k
    unhandled = "STYP_DSECT";
1235
8.46k
    break;
1236
8.47k
  case STYP_GROUP:
1237
8.47k
    unhandled = "STYP_GROUP";
1238
8.47k
    break;
1239
9.07k
  case STYP_COPY:
1240
9.07k
    unhandled = "STYP_COPY";
1241
9.07k
    break;
1242
9.02k
  case STYP_OVER:
1243
9.02k
    unhandled = "STYP_OVER";
1244
9.02k
    break;
1245
0
#ifdef SEC_NEVER_LOAD
1246
26.0k
  case STYP_NOLOAD:
1247
26.0k
    sec_flags |= SEC_NEVER_LOAD;
1248
26.0k
    break;
1249
0
#endif
1250
39.8k
  case IMAGE_SCN_MEM_READ:
1251
39.8k
    sec_flags &= ~SEC_COFF_NOREAD;
1252
39.8k
    break;
1253
26.7k
  case IMAGE_SCN_TYPE_NO_PAD:
1254
    /* Skip.  */
1255
26.7k
    break;
1256
8.87k
  case IMAGE_SCN_LNK_OTHER:
1257
8.87k
    unhandled = "IMAGE_SCN_LNK_OTHER";
1258
8.87k
    break;
1259
8.09k
  case IMAGE_SCN_MEM_NOT_CACHED:
1260
8.09k
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1261
8.09k
    break;
1262
34.5k
  case IMAGE_SCN_MEM_NOT_PAGED:
1263
    /* Generate a warning message rather using the 'unhandled'
1264
       variable as this will allow some .sys files generate by
1265
       other toolchains to be processed.  See bugzilla issue 196.  */
1266
    /* xgettext:c-format */
1267
34.5k
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1268
34.5k
        " %s in section %s"),
1269
34.5k
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1270
34.5k
    break;
1271
47.9k
  case IMAGE_SCN_MEM_EXECUTE:
1272
47.9k
    sec_flags |= SEC_CODE;
1273
47.9k
    break;
1274
26.8k
  case IMAGE_SCN_MEM_WRITE:
1275
26.8k
    sec_flags &= ~ SEC_READONLY;
1276
26.8k
    break;
1277
35.7k
  case IMAGE_SCN_MEM_DISCARDABLE:
1278
    /* The MS PE spec says that debug sections are DISCARDABLE,
1279
       but the presence of a DISCARDABLE flag does not necessarily
1280
       mean that a given section contains debug information.  Thus
1281
       we only set the SEC_DEBUGGING flag on sections that we
1282
       recognise as containing debug information.  */
1283
35.7k
       if (is_dbg
1284
35.7k
#ifdef _COMMENT
1285
35.7k
        || strcmp (name, _COMMENT) == 0
1286
35.7k
#endif
1287
35.7k
        )
1288
3.71k
      {
1289
3.71k
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1290
3.71k
      }
1291
35.7k
    break;
1292
24.9k
  case IMAGE_SCN_MEM_SHARED:
1293
24.9k
    sec_flags |= SEC_COFF_SHARED;
1294
24.9k
    break;
1295
28.9k
  case IMAGE_SCN_LNK_REMOVE:
1296
28.9k
    if (!is_dbg)
1297
26.8k
      sec_flags |= SEC_EXCLUDE;
1298
28.9k
    break;
1299
33.6k
  case IMAGE_SCN_CNT_CODE:
1300
33.6k
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1301
33.6k
    break;
1302
22.0k
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1303
22.0k
    if (is_dbg)
1304
1.46k
      sec_flags |= SEC_DEBUGGING;
1305
20.5k
    else
1306
20.5k
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1307
22.0k
    break;
1308
21.9k
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1309
21.9k
    sec_flags |= SEC_ALLOC;
1310
21.9k
    break;
1311
32.8k
  case IMAGE_SCN_LNK_INFO:
1312
    /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
1313
       defined.  coff_compute_section_file_positions uses
1314
       COFF_PAGE_SIZE to ensure that the low order bits of the
1315
       section VMA and the file offset match.  If we don't know
1316
       COFF_PAGE_SIZE, we can't ensure the correct correspondence,
1317
       and demand page loading of the file will fail.  */
1318
32.8k
#ifdef COFF_PAGE_SIZE
1319
32.8k
    sec_flags |= SEC_DEBUGGING;
1320
32.8k
#endif
1321
32.8k
    break;
1322
47.8k
  case IMAGE_SCN_LNK_COMDAT:
1323
    /* COMDAT gets very special treatment.  */
1324
47.8k
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1325
1.34k
      result = false;
1326
47.8k
    break;
1327
415k
  default:
1328
    /* Silently ignore for now.  */
1329
415k
    break;
1330
917k
  }
1331
1332
      /* If the section flag was not handled, report it here.  */
1333
917k
      if (unhandled != NULL)
1334
52.0k
  {
1335
52.0k
    _bfd_error_handler
1336
      /* xgettext:c-format */
1337
52.0k
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1338
52.0k
       abfd, name, unhandled, flag);
1339
52.0k
    result = false;
1340
52.0k
  }
1341
917k
    }
1342
1343
276k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1344
276k
      && (startswith (name, ".sbss")
1345
0
    || startswith (name, ".sdata")))
1346
0
    sec_flags |= SEC_SMALL_DATA;
1347
1348
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
1349
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
1350
     only link a single copy of the section.  This is used to support
1351
     g++.  g++ will emit each template expansion in its own section.
1352
     The symbols will be defined as weak, so that multiple definitions
1353
     are permitted.  The GNU linker extension is to actually discard
1354
     all but one of the sections.  */
1355
  if (startswith (name, ".gnu.linkonce"))
1356
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
1357
#endif
1358
1359
276k
  if (flags_ptr)
1360
276k
    * flags_ptr = sec_flags;
1361
1362
276k
  return result;
1363
276k
}
pei-aarch64.c:styp_to_sec_flags
Line
Count
Source
1192
364k
{
1193
364k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1194
364k
  unsigned long styp_flags = internal_s->s_flags;
1195
364k
  flagword sec_flags;
1196
364k
  bool result = true;
1197
364k
  bool is_dbg = false;
1198
1199
364k
  if (startswith (name, DOT_DEBUG)
1200
364k
      || startswith (name, DOT_ZDEBUG)
1201
364k
#ifdef COFF_LONG_SECTION_NAMES
1202
364k
      || startswith (name, GNU_LINKONCE_WI)
1203
364k
      || startswith (name, GNU_LINKONCE_WT)
1204
      /* FIXME: These definitions ought to be in a header file.  */
1205
364k
#define GNU_DEBUGLINK   ".gnu_debuglink"
1206
364k
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1207
364k
      || startswith (name, GNU_DEBUGLINK)
1208
364k
      || startswith (name, GNU_DEBUGALTLINK)
1209
364k
#endif
1210
364k
      || startswith (name, ".stab"))
1211
8.77k
    is_dbg = true;
1212
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1213
364k
  sec_flags = SEC_READONLY;
1214
1215
  /* If section disallows read, then set the NOREAD flag. */
1216
364k
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1217
274k
    sec_flags |= SEC_COFF_NOREAD;
1218
1219
  /* Process each flag bit in styp_flags in turn.  */
1220
2.29M
  while (styp_flags)
1221
1.92M
    {
1222
1.92M
      unsigned long flag = styp_flags & - styp_flags;
1223
1.92M
      char * unhandled = NULL;
1224
1225
1.92M
      styp_flags &= ~ flag;
1226
1227
      /* We infer from the distinct read/write/execute bits the settings
1228
   of some of the bfd flags; the actual values, should we need them,
1229
   are also in pei_section_data (abfd, section)->pe_flags.  */
1230
1231
1.92M
      switch (flag)
1232
1.92M
  {
1233
17.3k
  case STYP_DSECT:
1234
17.3k
    unhandled = "STYP_DSECT";
1235
17.3k
    break;
1236
17.6k
  case STYP_GROUP:
1237
17.6k
    unhandled = "STYP_GROUP";
1238
17.6k
    break;
1239
19.8k
  case STYP_COPY:
1240
19.8k
    unhandled = "STYP_COPY";
1241
19.8k
    break;
1242
20.9k
  case STYP_OVER:
1243
20.9k
    unhandled = "STYP_OVER";
1244
20.9k
    break;
1245
0
#ifdef SEC_NEVER_LOAD
1246
59.3k
  case STYP_NOLOAD:
1247
59.3k
    sec_flags |= SEC_NEVER_LOAD;
1248
59.3k
    break;
1249
0
#endif
1250
90.2k
  case IMAGE_SCN_MEM_READ:
1251
90.2k
    sec_flags &= ~SEC_COFF_NOREAD;
1252
90.2k
    break;
1253
56.7k
  case IMAGE_SCN_TYPE_NO_PAD:
1254
    /* Skip.  */
1255
56.7k
    break;
1256
18.1k
  case IMAGE_SCN_LNK_OTHER:
1257
18.1k
    unhandled = "IMAGE_SCN_LNK_OTHER";
1258
18.1k
    break;
1259
17.4k
  case IMAGE_SCN_MEM_NOT_CACHED:
1260
17.4k
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1261
17.4k
    break;
1262
72.5k
  case IMAGE_SCN_MEM_NOT_PAGED:
1263
    /* Generate a warning message rather using the 'unhandled'
1264
       variable as this will allow some .sys files generate by
1265
       other toolchains to be processed.  See bugzilla issue 196.  */
1266
    /* xgettext:c-format */
1267
72.5k
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1268
72.5k
        " %s in section %s"),
1269
72.5k
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1270
72.5k
    break;
1271
88.5k
  case IMAGE_SCN_MEM_EXECUTE:
1272
88.5k
    sec_flags |= SEC_CODE;
1273
88.5k
    break;
1274
81.4k
  case IMAGE_SCN_MEM_WRITE:
1275
81.4k
    sec_flags &= ~ SEC_READONLY;
1276
81.4k
    break;
1277
79.9k
  case IMAGE_SCN_MEM_DISCARDABLE:
1278
    /* The MS PE spec says that debug sections are DISCARDABLE,
1279
       but the presence of a DISCARDABLE flag does not necessarily
1280
       mean that a given section contains debug information.  Thus
1281
       we only set the SEC_DEBUGGING flag on sections that we
1282
       recognise as containing debug information.  */
1283
79.9k
       if (is_dbg
1284
79.9k
#ifdef _COMMENT
1285
79.9k
        || strcmp (name, _COMMENT) == 0
1286
79.9k
#endif
1287
79.9k
        )
1288
16.9k
      {
1289
16.9k
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1290
16.9k
      }
1291
79.9k
    break;
1292
55.8k
  case IMAGE_SCN_MEM_SHARED:
1293
55.8k
    sec_flags |= SEC_COFF_SHARED;
1294
55.8k
    break;
1295
103k
  case IMAGE_SCN_LNK_REMOVE:
1296
103k
    if (!is_dbg)
1297
99.1k
      sec_flags |= SEC_EXCLUDE;
1298
103k
    break;
1299
67.3k
  case IMAGE_SCN_CNT_CODE:
1300
67.3k
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1301
67.3k
    break;
1302
43.2k
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1303
43.2k
    if (is_dbg)
1304
3.37k
      sec_flags |= SEC_DEBUGGING;
1305
39.9k
    else
1306
39.9k
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1307
43.2k
    break;
1308
47.7k
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1309
47.7k
    sec_flags |= SEC_ALLOC;
1310
47.7k
    break;
1311
65.4k
  case IMAGE_SCN_LNK_INFO:
1312
    /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
1313
       defined.  coff_compute_section_file_positions uses
1314
       COFF_PAGE_SIZE to ensure that the low order bits of the
1315
       section VMA and the file offset match.  If we don't know
1316
       COFF_PAGE_SIZE, we can't ensure the correct correspondence,
1317
       and demand page loading of the file will fail.  */
1318
65.4k
#ifdef COFF_PAGE_SIZE
1319
65.4k
    sec_flags |= SEC_DEBUGGING;
1320
65.4k
#endif
1321
65.4k
    break;
1322
99.4k
  case IMAGE_SCN_LNK_COMDAT:
1323
    /* COMDAT gets very special treatment.  */
1324
99.4k
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1325
7.61k
      result = false;
1326
99.4k
    break;
1327
806k
  default:
1328
    /* Silently ignore for now.  */
1329
806k
    break;
1330
1.92M
  }
1331
1332
      /* If the section flag was not handled, report it here.  */
1333
1.92M
      if (unhandled != NULL)
1334
111k
  {
1335
111k
    _bfd_error_handler
1336
      /* xgettext:c-format */
1337
111k
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1338
111k
       abfd, name, unhandled, flag);
1339
111k
    result = false;
1340
111k
  }
1341
1.92M
    }
1342
1343
364k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1344
364k
      && (startswith (name, ".sbss")
1345
0
    || startswith (name, ".sdata")))
1346
0
    sec_flags |= SEC_SMALL_DATA;
1347
1348
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
1349
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
1350
     only link a single copy of the section.  This is used to support
1351
     g++.  g++ will emit each template expansion in its own section.
1352
     The symbols will be defined as weak, so that multiple definitions
1353
     are permitted.  The GNU linker extension is to actually discard
1354
     all but one of the sections.  */
1355
  if (startswith (name, ".gnu.linkonce"))
1356
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
1357
#endif
1358
1359
364k
  if (flags_ptr)
1360
364k
    * flags_ptr = sec_flags;
1361
1362
364k
  return result;
1363
364k
}
pei-ia64.c:styp_to_sec_flags
Line
Count
Source
1192
310k
{
1193
310k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1194
310k
  unsigned long styp_flags = internal_s->s_flags;
1195
310k
  flagword sec_flags;
1196
310k
  bool result = true;
1197
310k
  bool is_dbg = false;
1198
1199
310k
  if (startswith (name, DOT_DEBUG)
1200
310k
      || startswith (name, DOT_ZDEBUG)
1201
310k
#ifdef COFF_LONG_SECTION_NAMES
1202
310k
      || startswith (name, GNU_LINKONCE_WI)
1203
310k
      || startswith (name, GNU_LINKONCE_WT)
1204
      /* FIXME: These definitions ought to be in a header file.  */
1205
310k
#define GNU_DEBUGLINK   ".gnu_debuglink"
1206
310k
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1207
310k
      || startswith (name, GNU_DEBUGLINK)
1208
310k
      || startswith (name, GNU_DEBUGALTLINK)
1209
310k
#endif
1210
310k
      || startswith (name, ".stab"))
1211
14.2k
    is_dbg = true;
1212
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1213
310k
  sec_flags = SEC_READONLY;
1214
1215
  /* If section disallows read, then set the NOREAD flag. */
1216
310k
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1217
238k
    sec_flags |= SEC_COFF_NOREAD;
1218
1219
  /* Process each flag bit in styp_flags in turn.  */
1220
2.29M
  while (styp_flags)
1221
1.98M
    {
1222
1.98M
      unsigned long flag = styp_flags & - styp_flags;
1223
1.98M
      char * unhandled = NULL;
1224
1225
1.98M
      styp_flags &= ~ flag;
1226
1227
      /* We infer from the distinct read/write/execute bits the settings
1228
   of some of the bfd flags; the actual values, should we need them,
1229
   are also in pei_section_data (abfd, section)->pe_flags.  */
1230
1231
1.98M
      switch (flag)
1232
1.98M
  {
1233
25.6k
  case STYP_DSECT:
1234
25.6k
    unhandled = "STYP_DSECT";
1235
25.6k
    break;
1236
22.4k
  case STYP_GROUP:
1237
22.4k
    unhandled = "STYP_GROUP";
1238
22.4k
    break;
1239
25.5k
  case STYP_COPY:
1240
25.5k
    unhandled = "STYP_COPY";
1241
25.5k
    break;
1242
27.9k
  case STYP_OVER:
1243
27.9k
    unhandled = "STYP_OVER";
1244
27.9k
    break;
1245
0
#ifdef SEC_NEVER_LOAD
1246
67.9k
  case STYP_NOLOAD:
1247
67.9k
    sec_flags |= SEC_NEVER_LOAD;
1248
67.9k
    break;
1249
0
#endif
1250
71.8k
  case IMAGE_SCN_MEM_READ:
1251
71.8k
    sec_flags &= ~SEC_COFF_NOREAD;
1252
71.8k
    break;
1253
66.8k
  case IMAGE_SCN_TYPE_NO_PAD:
1254
    /* Skip.  */
1255
66.8k
    break;
1256
28.4k
  case IMAGE_SCN_LNK_OTHER:
1257
28.4k
    unhandled = "IMAGE_SCN_LNK_OTHER";
1258
28.4k
    break;
1259
23.1k
  case IMAGE_SCN_MEM_NOT_CACHED:
1260
23.1k
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1261
23.1k
    break;
1262
70.7k
  case IMAGE_SCN_MEM_NOT_PAGED:
1263
    /* Generate a warning message rather using the 'unhandled'
1264
       variable as this will allow some .sys files generate by
1265
       other toolchains to be processed.  See bugzilla issue 196.  */
1266
    /* xgettext:c-format */
1267
70.7k
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1268
70.7k
        " %s in section %s"),
1269
70.7k
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1270
70.7k
    break;
1271
84.7k
  case IMAGE_SCN_MEM_EXECUTE:
1272
84.7k
    sec_flags |= SEC_CODE;
1273
84.7k
    break;
1274
65.1k
  case IMAGE_SCN_MEM_WRITE:
1275
65.1k
    sec_flags &= ~ SEC_READONLY;
1276
65.1k
    break;
1277
88.7k
  case IMAGE_SCN_MEM_DISCARDABLE:
1278
    /* The MS PE spec says that debug sections are DISCARDABLE,
1279
       but the presence of a DISCARDABLE flag does not necessarily
1280
       mean that a given section contains debug information.  Thus
1281
       we only set the SEC_DEBUGGING flag on sections that we
1282
       recognise as containing debug information.  */
1283
88.7k
       if (is_dbg
1284
88.7k
#ifdef _COMMENT
1285
88.7k
        || strcmp (name, _COMMENT) == 0
1286
88.7k
#endif
1287
88.7k
        )
1288
9.63k
      {
1289
9.63k
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1290
9.63k
      }
1291
88.7k
    break;
1292
48.6k
  case IMAGE_SCN_MEM_SHARED:
1293
48.6k
    sec_flags |= SEC_COFF_SHARED;
1294
48.6k
    break;
1295
79.9k
  case IMAGE_SCN_LNK_REMOVE:
1296
79.9k
    if (!is_dbg)
1297
74.3k
      sec_flags |= SEC_EXCLUDE;
1298
79.9k
    break;
1299
72.7k
  case IMAGE_SCN_CNT_CODE:
1300
72.7k
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1301
72.7k
    break;
1302
56.2k
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1303
56.2k
    if (is_dbg)
1304
4.37k
      sec_flags |= SEC_DEBUGGING;
1305
51.8k
    else
1306
51.8k
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1307
56.2k
    break;
1308
60.5k
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1309
60.5k
    sec_flags |= SEC_ALLOC;
1310
60.5k
    break;
1311
86.6k
  case IMAGE_SCN_LNK_INFO:
1312
    /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
1313
       defined.  coff_compute_section_file_positions uses
1314
       COFF_PAGE_SIZE to ensure that the low order bits of the
1315
       section VMA and the file offset match.  If we don't know
1316
       COFF_PAGE_SIZE, we can't ensure the correct correspondence,
1317
       and demand page loading of the file will fail.  */
1318
86.6k
#ifdef COFF_PAGE_SIZE
1319
86.6k
    sec_flags |= SEC_DEBUGGING;
1320
86.6k
#endif
1321
86.6k
    break;
1322
81.5k
  case IMAGE_SCN_LNK_COMDAT:
1323
    /* COMDAT gets very special treatment.  */
1324
81.5k
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1325
7.93k
      result = false;
1326
81.5k
    break;
1327
830k
  default:
1328
    /* Silently ignore for now.  */
1329
830k
    break;
1330
1.98M
  }
1331
1332
      /* If the section flag was not handled, report it here.  */
1333
1.98M
      if (unhandled != NULL)
1334
153k
  {
1335
153k
    _bfd_error_handler
1336
      /* xgettext:c-format */
1337
153k
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1338
153k
       abfd, name, unhandled, flag);
1339
153k
    result = false;
1340
153k
  }
1341
1.98M
    }
1342
1343
310k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1344
310k
      && (startswith (name, ".sbss")
1345
0
    || startswith (name, ".sdata")))
1346
0
    sec_flags |= SEC_SMALL_DATA;
1347
1348
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
1349
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
1350
     only link a single copy of the section.  This is used to support
1351
     g++.  g++ will emit each template expansion in its own section.
1352
     The symbols will be defined as weak, so that multiple definitions
1353
     are permitted.  The GNU linker extension is to actually discard
1354
     all but one of the sections.  */
1355
  if (startswith (name, ".gnu.linkonce"))
1356
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
1357
#endif
1358
1359
310k
  if (flags_ptr)
1360
310k
    * flags_ptr = sec_flags;
1361
1362
310k
  return result;
1363
310k
}
pei-loongarch64.c:styp_to_sec_flags
Line
Count
Source
1192
307k
{
1193
307k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1194
307k
  unsigned long styp_flags = internal_s->s_flags;
1195
307k
  flagword sec_flags;
1196
307k
  bool result = true;
1197
307k
  bool is_dbg = false;
1198
1199
307k
  if (startswith (name, DOT_DEBUG)
1200
307k
      || startswith (name, DOT_ZDEBUG)
1201
307k
#ifdef COFF_LONG_SECTION_NAMES
1202
307k
      || startswith (name, GNU_LINKONCE_WI)
1203
307k
      || startswith (name, GNU_LINKONCE_WT)
1204
      /* FIXME: These definitions ought to be in a header file.  */
1205
307k
#define GNU_DEBUGLINK   ".gnu_debuglink"
1206
307k
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1207
307k
      || startswith (name, GNU_DEBUGLINK)
1208
307k
      || startswith (name, GNU_DEBUGALTLINK)
1209
307k
#endif
1210
307k
      || startswith (name, ".stab"))
1211
12.6k
    is_dbg = true;
1212
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1213
307k
  sec_flags = SEC_READONLY;
1214
1215
  /* If section disallows read, then set the NOREAD flag. */
1216
307k
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1217
240k
    sec_flags |= SEC_COFF_NOREAD;
1218
1219
  /* Process each flag bit in styp_flags in turn.  */
1220
2.04M
  while (styp_flags)
1221
1.73M
    {
1222
1.73M
      unsigned long flag = styp_flags & - styp_flags;
1223
1.73M
      char * unhandled = NULL;
1224
1225
1.73M
      styp_flags &= ~ flag;
1226
1227
      /* We infer from the distinct read/write/execute bits the settings
1228
   of some of the bfd flags; the actual values, should we need them,
1229
   are also in pei_section_data (abfd, section)->pe_flags.  */
1230
1231
1.73M
      switch (flag)
1232
1.73M
  {
1233
14.9k
  case STYP_DSECT:
1234
14.9k
    unhandled = "STYP_DSECT";
1235
14.9k
    break;
1236
14.2k
  case STYP_GROUP:
1237
14.2k
    unhandled = "STYP_GROUP";
1238
14.2k
    break;
1239
21.2k
  case STYP_COPY:
1240
21.2k
    unhandled = "STYP_COPY";
1241
21.2k
    break;
1242
14.4k
  case STYP_OVER:
1243
14.4k
    unhandled = "STYP_OVER";
1244
14.4k
    break;
1245
0
#ifdef SEC_NEVER_LOAD
1246
51.9k
  case STYP_NOLOAD:
1247
51.9k
    sec_flags |= SEC_NEVER_LOAD;
1248
51.9k
    break;
1249
0
#endif
1250
67.0k
  case IMAGE_SCN_MEM_READ:
1251
67.0k
    sec_flags &= ~SEC_COFF_NOREAD;
1252
67.0k
    break;
1253
52.6k
  case IMAGE_SCN_TYPE_NO_PAD:
1254
    /* Skip.  */
1255
52.6k
    break;
1256
15.9k
  case IMAGE_SCN_LNK_OTHER:
1257
15.9k
    unhandled = "IMAGE_SCN_LNK_OTHER";
1258
15.9k
    break;
1259
14.9k
  case IMAGE_SCN_MEM_NOT_CACHED:
1260
14.9k
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1261
14.9k
    break;
1262
72.4k
  case IMAGE_SCN_MEM_NOT_PAGED:
1263
    /* Generate a warning message rather using the 'unhandled'
1264
       variable as this will allow some .sys files generate by
1265
       other toolchains to be processed.  See bugzilla issue 196.  */
1266
    /* xgettext:c-format */
1267
72.4k
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1268
72.4k
        " %s in section %s"),
1269
72.4k
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1270
72.4k
    break;
1271
85.7k
  case IMAGE_SCN_MEM_EXECUTE:
1272
85.7k
    sec_flags |= SEC_CODE;
1273
85.7k
    break;
1274
54.4k
  case IMAGE_SCN_MEM_WRITE:
1275
54.4k
    sec_flags &= ~ SEC_READONLY;
1276
54.4k
    break;
1277
81.0k
  case IMAGE_SCN_MEM_DISCARDABLE:
1278
    /* The MS PE spec says that debug sections are DISCARDABLE,
1279
       but the presence of a DISCARDABLE flag does not necessarily
1280
       mean that a given section contains debug information.  Thus
1281
       we only set the SEC_DEBUGGING flag on sections that we
1282
       recognise as containing debug information.  */
1283
81.0k
       if (is_dbg
1284
81.0k
#ifdef _COMMENT
1285
81.0k
        || strcmp (name, _COMMENT) == 0
1286
81.0k
#endif
1287
81.0k
        )
1288
8.20k
      {
1289
8.20k
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1290
8.20k
      }
1291
81.0k
    break;
1292
50.2k
  case IMAGE_SCN_MEM_SHARED:
1293
50.2k
    sec_flags |= SEC_COFF_SHARED;
1294
50.2k
    break;
1295
81.9k
  case IMAGE_SCN_LNK_REMOVE:
1296
81.9k
    if (!is_dbg)
1297
77.2k
      sec_flags |= SEC_EXCLUDE;
1298
81.9k
    break;
1299
65.8k
  case IMAGE_SCN_CNT_CODE:
1300
65.8k
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1301
65.8k
    break;
1302
53.1k
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1303
53.1k
    if (is_dbg)
1304
4.99k
      sec_flags |= SEC_DEBUGGING;
1305
48.1k
    else
1306
48.1k
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1307
53.1k
    break;
1308
42.1k
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1309
42.1k
    sec_flags |= SEC_ALLOC;
1310
42.1k
    break;
1311
79.8k
  case IMAGE_SCN_LNK_INFO:
1312
    /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
1313
       defined.  coff_compute_section_file_positions uses
1314
       COFF_PAGE_SIZE to ensure that the low order bits of the
1315
       section VMA and the file offset match.  If we don't know
1316
       COFF_PAGE_SIZE, we can't ensure the correct correspondence,
1317
       and demand page loading of the file will fail.  */
1318
79.8k
#ifdef COFF_PAGE_SIZE
1319
79.8k
    sec_flags |= SEC_DEBUGGING;
1320
79.8k
#endif
1321
79.8k
    break;
1322
72.3k
  case IMAGE_SCN_LNK_COMDAT:
1323
    /* COMDAT gets very special treatment.  */
1324
72.3k
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1325
3.56k
      result = false;
1326
72.3k
    break;
1327
727k
  default:
1328
    /* Silently ignore for now.  */
1329
727k
    break;
1330
1.73M
  }
1331
1332
      /* If the section flag was not handled, report it here.  */
1333
1.73M
      if (unhandled != NULL)
1334
95.7k
  {
1335
95.7k
    _bfd_error_handler
1336
      /* xgettext:c-format */
1337
95.7k
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1338
95.7k
       abfd, name, unhandled, flag);
1339
95.7k
    result = false;
1340
95.7k
  }
1341
1.73M
    }
1342
1343
307k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1344
307k
      && (startswith (name, ".sbss")
1345
0
    || startswith (name, ".sdata")))
1346
0
    sec_flags |= SEC_SMALL_DATA;
1347
1348
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
1349
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
1350
     only link a single copy of the section.  This is used to support
1351
     g++.  g++ will emit each template expansion in its own section.
1352
     The symbols will be defined as weak, so that multiple definitions
1353
     are permitted.  The GNU linker extension is to actually discard
1354
     all but one of the sections.  */
1355
  if (startswith (name, ".gnu.linkonce"))
1356
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
1357
#endif
1358
1359
307k
  if (flags_ptr)
1360
307k
    * flags_ptr = sec_flags;
1361
1362
307k
  return result;
1363
307k
}
pei-riscv64.c:styp_to_sec_flags
Line
Count
Source
1192
273k
{
1193
273k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1194
273k
  unsigned long styp_flags = internal_s->s_flags;
1195
273k
  flagword sec_flags;
1196
273k
  bool result = true;
1197
273k
  bool is_dbg = false;
1198
1199
273k
  if (startswith (name, DOT_DEBUG)
1200
273k
      || startswith (name, DOT_ZDEBUG)
1201
273k
#ifdef COFF_LONG_SECTION_NAMES
1202
273k
      || startswith (name, GNU_LINKONCE_WI)
1203
273k
      || startswith (name, GNU_LINKONCE_WT)
1204
      /* FIXME: These definitions ought to be in a header file.  */
1205
273k
#define GNU_DEBUGLINK   ".gnu_debuglink"
1206
273k
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1207
273k
      || startswith (name, GNU_DEBUGLINK)
1208
273k
      || startswith (name, GNU_DEBUGALTLINK)
1209
273k
#endif
1210
273k
      || startswith (name, ".stab"))
1211
7.64k
    is_dbg = true;
1212
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1213
273k
  sec_flags = SEC_READONLY;
1214
1215
  /* If section disallows read, then set the NOREAD flag. */
1216
273k
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1217
212k
    sec_flags |= SEC_COFF_NOREAD;
1218
1219
  /* Process each flag bit in styp_flags in turn.  */
1220
1.78M
  while (styp_flags)
1221
1.51M
    {
1222
1.51M
      unsigned long flag = styp_flags & - styp_flags;
1223
1.51M
      char * unhandled = NULL;
1224
1225
1.51M
      styp_flags &= ~ flag;
1226
1227
      /* We infer from the distinct read/write/execute bits the settings
1228
   of some of the bfd flags; the actual values, should we need them,
1229
   are also in pei_section_data (abfd, section)->pe_flags.  */
1230
1231
1.51M
      switch (flag)
1232
1.51M
  {
1233
18.5k
  case STYP_DSECT:
1234
18.5k
    unhandled = "STYP_DSECT";
1235
18.5k
    break;
1236
20.0k
  case STYP_GROUP:
1237
20.0k
    unhandled = "STYP_GROUP";
1238
20.0k
    break;
1239
25.2k
  case STYP_COPY:
1240
25.2k
    unhandled = "STYP_COPY";
1241
25.2k
    break;
1242
18.4k
  case STYP_OVER:
1243
18.4k
    unhandled = "STYP_OVER";
1244
18.4k
    break;
1245
0
#ifdef SEC_NEVER_LOAD
1246
56.5k
  case STYP_NOLOAD:
1247
56.5k
    sec_flags |= SEC_NEVER_LOAD;
1248
56.5k
    break;
1249
0
#endif
1250
61.6k
  case IMAGE_SCN_MEM_READ:
1251
61.6k
    sec_flags &= ~SEC_COFF_NOREAD;
1252
61.6k
    break;
1253
54.5k
  case IMAGE_SCN_TYPE_NO_PAD:
1254
    /* Skip.  */
1255
54.5k
    break;
1256
19.9k
  case IMAGE_SCN_LNK_OTHER:
1257
19.9k
    unhandled = "IMAGE_SCN_LNK_OTHER";
1258
19.9k
    break;
1259
18.3k
  case IMAGE_SCN_MEM_NOT_CACHED:
1260
18.3k
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1261
18.3k
    break;
1262
65.5k
  case IMAGE_SCN_MEM_NOT_PAGED:
1263
    /* Generate a warning message rather using the 'unhandled'
1264
       variable as this will allow some .sys files generate by
1265
       other toolchains to be processed.  See bugzilla issue 196.  */
1266
    /* xgettext:c-format */
1267
65.5k
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1268
65.5k
        " %s in section %s"),
1269
65.5k
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1270
65.5k
    break;
1271
66.3k
  case IMAGE_SCN_MEM_EXECUTE:
1272
66.3k
    sec_flags |= SEC_CODE;
1273
66.3k
    break;
1274
41.8k
  case IMAGE_SCN_MEM_WRITE:
1275
41.8k
    sec_flags &= ~ SEC_READONLY;
1276
41.8k
    break;
1277
63.9k
  case IMAGE_SCN_MEM_DISCARDABLE:
1278
    /* The MS PE spec says that debug sections are DISCARDABLE,
1279
       but the presence of a DISCARDABLE flag does not necessarily
1280
       mean that a given section contains debug information.  Thus
1281
       we only set the SEC_DEBUGGING flag on sections that we
1282
       recognise as containing debug information.  */
1283
63.9k
       if (is_dbg
1284
63.9k
#ifdef _COMMENT
1285
63.9k
        || strcmp (name, _COMMENT) == 0
1286
63.9k
#endif
1287
63.9k
        )
1288
4.21k
      {
1289
4.21k
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1290
4.21k
      }
1291
63.9k
    break;
1292
48.9k
  case IMAGE_SCN_MEM_SHARED:
1293
48.9k
    sec_flags |= SEC_COFF_SHARED;
1294
48.9k
    break;
1295
64.7k
  case IMAGE_SCN_LNK_REMOVE:
1296
64.7k
    if (!is_dbg)
1297
61.1k
      sec_flags |= SEC_EXCLUDE;
1298
64.7k
    break;
1299
50.9k
  case IMAGE_SCN_CNT_CODE:
1300
50.9k
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1301
50.9k
    break;
1302
50.8k
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1303
50.8k
    if (is_dbg)
1304
2.89k
      sec_flags |= SEC_DEBUGGING;
1305
47.9k
    else
1306
47.9k
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1307
50.8k
    break;
1308
32.3k
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1309
32.3k
    sec_flags |= SEC_ALLOC;
1310
32.3k
    break;
1311
67.5k
  case IMAGE_SCN_LNK_INFO:
1312
    /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
1313
       defined.  coff_compute_section_file_positions uses
1314
       COFF_PAGE_SIZE to ensure that the low order bits of the
1315
       section VMA and the file offset match.  If we don't know
1316
       COFF_PAGE_SIZE, we can't ensure the correct correspondence,
1317
       and demand page loading of the file will fail.  */
1318
#ifdef COFF_PAGE_SIZE
1319
    sec_flags |= SEC_DEBUGGING;
1320
#endif
1321
67.5k
    break;
1322
67.2k
  case IMAGE_SCN_LNK_COMDAT:
1323
    /* COMDAT gets very special treatment.  */
1324
67.2k
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1325
4.94k
      result = false;
1326
67.2k
    break;
1327
602k
  default:
1328
    /* Silently ignore for now.  */
1329
602k
    break;
1330
1.51M
  }
1331
1332
      /* If the section flag was not handled, report it here.  */
1333
1.51M
      if (unhandled != NULL)
1334
120k
  {
1335
120k
    _bfd_error_handler
1336
      /* xgettext:c-format */
1337
120k
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1338
120k
       abfd, name, unhandled, flag);
1339
120k
    result = false;
1340
120k
  }
1341
1.51M
    }
1342
1343
273k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1344
273k
      && (startswith (name, ".sbss")
1345
0
    || startswith (name, ".sdata")))
1346
0
    sec_flags |= SEC_SMALL_DATA;
1347
1348
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
1349
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
1350
     only link a single copy of the section.  This is used to support
1351
     g++.  g++ will emit each template expansion in its own section.
1352
     The symbols will be defined as weak, so that multiple definitions
1353
     are permitted.  The GNU linker extension is to actually discard
1354
     all but one of the sections.  */
1355
  if (startswith (name, ".gnu.linkonce"))
1356
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
1357
#endif
1358
1359
273k
  if (flags_ptr)
1360
273k
    * flags_ptr = sec_flags;
1361
1362
273k
  return result;
1363
273k
}
pe-arm-wince.c:styp_to_sec_flags
Line
Count
Source
1192
86.3k
{
1193
86.3k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1194
86.3k
  unsigned long styp_flags = internal_s->s_flags;
1195
86.3k
  flagword sec_flags;
1196
86.3k
  bool result = true;
1197
86.3k
  bool is_dbg = false;
1198
1199
86.3k
  if (startswith (name, DOT_DEBUG)
1200
86.3k
      || startswith (name, DOT_ZDEBUG)
1201
86.3k
#ifdef COFF_LONG_SECTION_NAMES
1202
86.3k
      || startswith (name, GNU_LINKONCE_WI)
1203
86.3k
      || startswith (name, GNU_LINKONCE_WT)
1204
      /* FIXME: These definitions ought to be in a header file.  */
1205
86.3k
#define GNU_DEBUGLINK   ".gnu_debuglink"
1206
86.3k
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1207
86.3k
      || startswith (name, GNU_DEBUGLINK)
1208
86.3k
      || startswith (name, GNU_DEBUGALTLINK)
1209
86.3k
#endif
1210
86.3k
      || startswith (name, ".stab"))
1211
11.3k
    is_dbg = true;
1212
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1213
86.3k
  sec_flags = SEC_READONLY;
1214
1215
  /* If section disallows read, then set the NOREAD flag. */
1216
86.3k
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1217
59.8k
    sec_flags |= SEC_COFF_NOREAD;
1218
1219
  /* Process each flag bit in styp_flags in turn.  */
1220
862k
  while (styp_flags)
1221
776k
    {
1222
776k
      unsigned long flag = styp_flags & - styp_flags;
1223
776k
      char * unhandled = NULL;
1224
1225
776k
      styp_flags &= ~ flag;
1226
1227
      /* We infer from the distinct read/write/execute bits the settings
1228
   of some of the bfd flags; the actual values, should we need them,
1229
   are also in pei_section_data (abfd, section)->pe_flags.  */
1230
1231
776k
      switch (flag)
1232
776k
  {
1233
14.1k
  case STYP_DSECT:
1234
14.1k
    unhandled = "STYP_DSECT";
1235
14.1k
    break;
1236
14.0k
  case STYP_GROUP:
1237
14.0k
    unhandled = "STYP_GROUP";
1238
14.0k
    break;
1239
15.4k
  case STYP_COPY:
1240
15.4k
    unhandled = "STYP_COPY";
1241
15.4k
    break;
1242
14.2k
  case STYP_OVER:
1243
14.2k
    unhandled = "STYP_OVER";
1244
14.2k
    break;
1245
0
#ifdef SEC_NEVER_LOAD
1246
23.5k
  case STYP_NOLOAD:
1247
23.5k
    sec_flags |= SEC_NEVER_LOAD;
1248
23.5k
    break;
1249
0
#endif
1250
26.4k
  case IMAGE_SCN_MEM_READ:
1251
26.4k
    sec_flags &= ~SEC_COFF_NOREAD;
1252
26.4k
    break;
1253
21.6k
  case IMAGE_SCN_TYPE_NO_PAD:
1254
    /* Skip.  */
1255
21.6k
    break;
1256
13.9k
  case IMAGE_SCN_LNK_OTHER:
1257
13.9k
    unhandled = "IMAGE_SCN_LNK_OTHER";
1258
13.9k
    break;
1259
14.0k
  case IMAGE_SCN_MEM_NOT_CACHED:
1260
14.0k
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1261
14.0k
    break;
1262
25.4k
  case IMAGE_SCN_MEM_NOT_PAGED:
1263
    /* Generate a warning message rather using the 'unhandled'
1264
       variable as this will allow some .sys files generate by
1265
       other toolchains to be processed.  See bugzilla issue 196.  */
1266
    /* xgettext:c-format */
1267
25.4k
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1268
25.4k
        " %s in section %s"),
1269
25.4k
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1270
25.4k
    break;
1271
33.6k
  case IMAGE_SCN_MEM_EXECUTE:
1272
33.6k
    sec_flags |= SEC_CODE;
1273
33.6k
    break;
1274
18.8k
  case IMAGE_SCN_MEM_WRITE:
1275
18.8k
    sec_flags &= ~ SEC_READONLY;
1276
18.8k
    break;
1277
29.1k
  case IMAGE_SCN_MEM_DISCARDABLE:
1278
    /* The MS PE spec says that debug sections are DISCARDABLE,
1279
       but the presence of a DISCARDABLE flag does not necessarily
1280
       mean that a given section contains debug information.  Thus
1281
       we only set the SEC_DEBUGGING flag on sections that we
1282
       recognise as containing debug information.  */
1283
29.1k
       if (is_dbg
1284
29.1k
#ifdef _COMMENT
1285
29.1k
        || strcmp (name, _COMMENT) == 0
1286
29.1k
#endif
1287
29.1k
        )
1288
6.02k
      {
1289
6.02k
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1290
6.02k
      }
1291
29.1k
    break;
1292
23.6k
  case IMAGE_SCN_MEM_SHARED:
1293
23.6k
    sec_flags |= SEC_COFF_SHARED;
1294
23.6k
    break;
1295
30.8k
  case IMAGE_SCN_LNK_REMOVE:
1296
30.8k
    if (!is_dbg)
1297
24.1k
      sec_flags |= SEC_EXCLUDE;
1298
30.8k
    break;
1299
35.2k
  case IMAGE_SCN_CNT_CODE:
1300
35.2k
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1301
35.2k
    break;
1302
23.6k
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1303
23.6k
    if (is_dbg)
1304
3.98k
      sec_flags |= SEC_DEBUGGING;
1305
19.6k
    else
1306
19.6k
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1307
23.6k
    break;
1308
17.6k
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1309
17.6k
    sec_flags |= SEC_ALLOC;
1310
17.6k
    break;
1311
31.9k
  case IMAGE_SCN_LNK_INFO:
1312
    /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
1313
       defined.  coff_compute_section_file_positions uses
1314
       COFF_PAGE_SIZE to ensure that the low order bits of the
1315
       section VMA and the file offset match.  If we don't know
1316
       COFF_PAGE_SIZE, we can't ensure the correct correspondence,
1317
       and demand page loading of the file will fail.  */
1318
31.9k
#ifdef COFF_PAGE_SIZE
1319
31.9k
    sec_flags |= SEC_DEBUGGING;
1320
31.9k
#endif
1321
31.9k
    break;
1322
35.2k
  case IMAGE_SCN_LNK_COMDAT:
1323
    /* COMDAT gets very special treatment.  */
1324
35.2k
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1325
2.80k
      result = false;
1326
35.2k
    break;
1327
313k
  default:
1328
    /* Silently ignore for now.  */
1329
313k
    break;
1330
776k
  }
1331
1332
      /* If the section flag was not handled, report it here.  */
1333
776k
      if (unhandled != NULL)
1334
86.0k
  {
1335
86.0k
    _bfd_error_handler
1336
      /* xgettext:c-format */
1337
86.0k
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1338
86.0k
       abfd, name, unhandled, flag);
1339
86.0k
    result = false;
1340
86.0k
  }
1341
776k
    }
1342
1343
86.3k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1344
86.3k
      && (startswith (name, ".sbss")
1345
0
    || startswith (name, ".sdata")))
1346
0
    sec_flags |= SEC_SMALL_DATA;
1347
1348
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
1349
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
1350
     only link a single copy of the section.  This is used to support
1351
     g++.  g++ will emit each template expansion in its own section.
1352
     The symbols will be defined as weak, so that multiple definitions
1353
     are permitted.  The GNU linker extension is to actually discard
1354
     all but one of the sections.  */
1355
  if (startswith (name, ".gnu.linkonce"))
1356
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
1357
#endif
1358
1359
86.3k
  if (flags_ptr)
1360
86.3k
    * flags_ptr = sec_flags;
1361
1362
86.3k
  return result;
1363
86.3k
}
pe-arm.c:styp_to_sec_flags
Line
Count
Source
1192
86.3k
{
1193
86.3k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1194
86.3k
  unsigned long styp_flags = internal_s->s_flags;
1195
86.3k
  flagword sec_flags;
1196
86.3k
  bool result = true;
1197
86.3k
  bool is_dbg = false;
1198
1199
86.3k
  if (startswith (name, DOT_DEBUG)
1200
86.3k
      || startswith (name, DOT_ZDEBUG)
1201
86.3k
#ifdef COFF_LONG_SECTION_NAMES
1202
86.3k
      || startswith (name, GNU_LINKONCE_WI)
1203
86.3k
      || startswith (name, GNU_LINKONCE_WT)
1204
      /* FIXME: These definitions ought to be in a header file.  */
1205
86.3k
#define GNU_DEBUGLINK   ".gnu_debuglink"
1206
86.3k
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1207
86.3k
      || startswith (name, GNU_DEBUGLINK)
1208
86.3k
      || startswith (name, GNU_DEBUGALTLINK)
1209
86.3k
#endif
1210
86.3k
      || startswith (name, ".stab"))
1211
11.3k
    is_dbg = true;
1212
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1213
86.3k
  sec_flags = SEC_READONLY;
1214
1215
  /* If section disallows read, then set the NOREAD flag. */
1216
86.3k
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1217
59.8k
    sec_flags |= SEC_COFF_NOREAD;
1218
1219
  /* Process each flag bit in styp_flags in turn.  */
1220
862k
  while (styp_flags)
1221
776k
    {
1222
776k
      unsigned long flag = styp_flags & - styp_flags;
1223
776k
      char * unhandled = NULL;
1224
1225
776k
      styp_flags &= ~ flag;
1226
1227
      /* We infer from the distinct read/write/execute bits the settings
1228
   of some of the bfd flags; the actual values, should we need them,
1229
   are also in pei_section_data (abfd, section)->pe_flags.  */
1230
1231
776k
      switch (flag)
1232
776k
  {
1233
14.1k
  case STYP_DSECT:
1234
14.1k
    unhandled = "STYP_DSECT";
1235
14.1k
    break;
1236
14.0k
  case STYP_GROUP:
1237
14.0k
    unhandled = "STYP_GROUP";
1238
14.0k
    break;
1239
15.4k
  case STYP_COPY:
1240
15.4k
    unhandled = "STYP_COPY";
1241
15.4k
    break;
1242
14.2k
  case STYP_OVER:
1243
14.2k
    unhandled = "STYP_OVER";
1244
14.2k
    break;
1245
0
#ifdef SEC_NEVER_LOAD
1246
23.5k
  case STYP_NOLOAD:
1247
23.5k
    sec_flags |= SEC_NEVER_LOAD;
1248
23.5k
    break;
1249
0
#endif
1250
26.4k
  case IMAGE_SCN_MEM_READ:
1251
26.4k
    sec_flags &= ~SEC_COFF_NOREAD;
1252
26.4k
    break;
1253
21.6k
  case IMAGE_SCN_TYPE_NO_PAD:
1254
    /* Skip.  */
1255
21.6k
    break;
1256
13.9k
  case IMAGE_SCN_LNK_OTHER:
1257
13.9k
    unhandled = "IMAGE_SCN_LNK_OTHER";
1258
13.9k
    break;
1259
14.0k
  case IMAGE_SCN_MEM_NOT_CACHED:
1260
14.0k
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1261
14.0k
    break;
1262
25.4k
  case IMAGE_SCN_MEM_NOT_PAGED:
1263
    /* Generate a warning message rather using the 'unhandled'
1264
       variable as this will allow some .sys files generate by
1265
       other toolchains to be processed.  See bugzilla issue 196.  */
1266
    /* xgettext:c-format */
1267
25.4k
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1268
25.4k
        " %s in section %s"),
1269
25.4k
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1270
25.4k
    break;
1271
33.6k
  case IMAGE_SCN_MEM_EXECUTE:
1272
33.6k
    sec_flags |= SEC_CODE;
1273
33.6k
    break;
1274
18.8k
  case IMAGE_SCN_MEM_WRITE:
1275
18.8k
    sec_flags &= ~ SEC_READONLY;
1276
18.8k
    break;
1277
29.1k
  case IMAGE_SCN_MEM_DISCARDABLE:
1278
    /* The MS PE spec says that debug sections are DISCARDABLE,
1279
       but the presence of a DISCARDABLE flag does not necessarily
1280
       mean that a given section contains debug information.  Thus
1281
       we only set the SEC_DEBUGGING flag on sections that we
1282
       recognise as containing debug information.  */
1283
29.1k
       if (is_dbg
1284
29.1k
#ifdef _COMMENT
1285
29.1k
        || strcmp (name, _COMMENT) == 0
1286
29.1k
#endif
1287
29.1k
        )
1288
6.02k
      {
1289
6.02k
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1290
6.02k
      }
1291
29.1k
    break;
1292
23.6k
  case IMAGE_SCN_MEM_SHARED:
1293
23.6k
    sec_flags |= SEC_COFF_SHARED;
1294
23.6k
    break;
1295
30.8k
  case IMAGE_SCN_LNK_REMOVE:
1296
30.8k
    if (!is_dbg)
1297
24.1k
      sec_flags |= SEC_EXCLUDE;
1298
30.8k
    break;
1299
35.2k
  case IMAGE_SCN_CNT_CODE:
1300
35.2k
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1301
35.2k
    break;
1302
23.6k
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1303
23.6k
    if (is_dbg)
1304
3.98k
      sec_flags |= SEC_DEBUGGING;
1305
19.6k
    else
1306
19.6k
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1307
23.6k
    break;
1308
17.6k
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1309
17.6k
    sec_flags |= SEC_ALLOC;
1310
17.6k
    break;
1311
31.9k
  case IMAGE_SCN_LNK_INFO:
1312
    /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
1313
       defined.  coff_compute_section_file_positions uses
1314
       COFF_PAGE_SIZE to ensure that the low order bits of the
1315
       section VMA and the file offset match.  If we don't know
1316
       COFF_PAGE_SIZE, we can't ensure the correct correspondence,
1317
       and demand page loading of the file will fail.  */
1318
31.9k
#ifdef COFF_PAGE_SIZE
1319
31.9k
    sec_flags |= SEC_DEBUGGING;
1320
31.9k
#endif
1321
31.9k
    break;
1322
35.2k
  case IMAGE_SCN_LNK_COMDAT:
1323
    /* COMDAT gets very special treatment.  */
1324
35.2k
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1325
2.80k
      result = false;
1326
35.2k
    break;
1327
313k
  default:
1328
    /* Silently ignore for now.  */
1329
313k
    break;
1330
776k
  }
1331
1332
      /* If the section flag was not handled, report it here.  */
1333
776k
      if (unhandled != NULL)
1334
86.0k
  {
1335
86.0k
    _bfd_error_handler
1336
      /* xgettext:c-format */
1337
86.0k
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1338
86.0k
       abfd, name, unhandled, flag);
1339
86.0k
    result = false;
1340
86.0k
  }
1341
776k
    }
1342
1343
86.3k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1344
86.3k
      && (startswith (name, ".sbss")
1345
0
    || startswith (name, ".sdata")))
1346
0
    sec_flags |= SEC_SMALL_DATA;
1347
1348
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
1349
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
1350
     only link a single copy of the section.  This is used to support
1351
     g++.  g++ will emit each template expansion in its own section.
1352
     The symbols will be defined as weak, so that multiple definitions
1353
     are permitted.  The GNU linker extension is to actually discard
1354
     all but one of the sections.  */
1355
  if (startswith (name, ".gnu.linkonce"))
1356
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
1357
#endif
1358
1359
86.3k
  if (flags_ptr)
1360
86.3k
    * flags_ptr = sec_flags;
1361
1362
86.3k
  return result;
1363
86.3k
}
pe-i386.c:styp_to_sec_flags
Line
Count
Source
1192
191k
{
1193
191k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1194
191k
  unsigned long styp_flags = internal_s->s_flags;
1195
191k
  flagword sec_flags;
1196
191k
  bool result = true;
1197
191k
  bool is_dbg = false;
1198
1199
191k
  if (startswith (name, DOT_DEBUG)
1200
191k
      || startswith (name, DOT_ZDEBUG)
1201
191k
#ifdef COFF_LONG_SECTION_NAMES
1202
191k
      || startswith (name, GNU_LINKONCE_WI)
1203
191k
      || startswith (name, GNU_LINKONCE_WT)
1204
      /* FIXME: These definitions ought to be in a header file.  */
1205
191k
#define GNU_DEBUGLINK   ".gnu_debuglink"
1206
191k
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1207
191k
      || startswith (name, GNU_DEBUGLINK)
1208
191k
      || startswith (name, GNU_DEBUGALTLINK)
1209
191k
#endif
1210
191k
      || startswith (name, ".stab"))
1211
18.5k
    is_dbg = true;
1212
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1213
191k
  sec_flags = SEC_READONLY;
1214
1215
  /* If section disallows read, then set the NOREAD flag. */
1216
191k
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1217
144k
    sec_flags |= SEC_COFF_NOREAD;
1218
1219
  /* Process each flag bit in styp_flags in turn.  */
1220
1.66M
  while (styp_flags)
1221
1.47M
    {
1222
1.47M
      unsigned long flag = styp_flags & - styp_flags;
1223
1.47M
      char * unhandled = NULL;
1224
1225
1.47M
      styp_flags &= ~ flag;
1226
1227
      /* We infer from the distinct read/write/execute bits the settings
1228
   of some of the bfd flags; the actual values, should we need them,
1229
   are also in pei_section_data (abfd, section)->pe_flags.  */
1230
1231
1.47M
      switch (flag)
1232
1.47M
  {
1233
29.1k
  case STYP_DSECT:
1234
29.1k
    unhandled = "STYP_DSECT";
1235
29.1k
    break;
1236
27.0k
  case STYP_GROUP:
1237
27.0k
    unhandled = "STYP_GROUP";
1238
27.0k
    break;
1239
26.8k
  case STYP_COPY:
1240
26.8k
    unhandled = "STYP_COPY";
1241
26.8k
    break;
1242
32.9k
  case STYP_OVER:
1243
32.9k
    unhandled = "STYP_OVER";
1244
32.9k
    break;
1245
0
#ifdef SEC_NEVER_LOAD
1246
43.2k
  case STYP_NOLOAD:
1247
43.2k
    sec_flags |= SEC_NEVER_LOAD;
1248
43.2k
    break;
1249
0
#endif
1250
47.2k
  case IMAGE_SCN_MEM_READ:
1251
47.2k
    sec_flags &= ~SEC_COFF_NOREAD;
1252
47.2k
    break;
1253
41.3k
  case IMAGE_SCN_TYPE_NO_PAD:
1254
    /* Skip.  */
1255
41.3k
    break;
1256
30.9k
  case IMAGE_SCN_LNK_OTHER:
1257
30.9k
    unhandled = "IMAGE_SCN_LNK_OTHER";
1258
30.9k
    break;
1259
30.7k
  case IMAGE_SCN_MEM_NOT_CACHED:
1260
30.7k
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1261
30.7k
    break;
1262
48.9k
  case IMAGE_SCN_MEM_NOT_PAGED:
1263
    /* Generate a warning message rather using the 'unhandled'
1264
       variable as this will allow some .sys files generate by
1265
       other toolchains to be processed.  See bugzilla issue 196.  */
1266
    /* xgettext:c-format */
1267
48.9k
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1268
48.9k
        " %s in section %s"),
1269
48.9k
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1270
48.9k
    break;
1271
61.9k
  case IMAGE_SCN_MEM_EXECUTE:
1272
61.9k
    sec_flags |= SEC_CODE;
1273
61.9k
    break;
1274
42.0k
  case IMAGE_SCN_MEM_WRITE:
1275
42.0k
    sec_flags &= ~ SEC_READONLY;
1276
42.0k
    break;
1277
55.1k
  case IMAGE_SCN_MEM_DISCARDABLE:
1278
    /* The MS PE spec says that debug sections are DISCARDABLE,
1279
       but the presence of a DISCARDABLE flag does not necessarily
1280
       mean that a given section contains debug information.  Thus
1281
       we only set the SEC_DEBUGGING flag on sections that we
1282
       recognise as containing debug information.  */
1283
55.1k
       if (is_dbg
1284
55.1k
#ifdef _COMMENT
1285
55.1k
        || strcmp (name, _COMMENT) == 0
1286
55.1k
#endif
1287
55.1k
        )
1288
8.81k
      {
1289
8.81k
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1290
8.81k
      }
1291
55.1k
    break;
1292
40.9k
  case IMAGE_SCN_MEM_SHARED:
1293
40.9k
    sec_flags |= SEC_COFF_SHARED;
1294
40.9k
    break;
1295
52.0k
  case IMAGE_SCN_LNK_REMOVE:
1296
52.0k
    if (!is_dbg)
1297
45.2k
      sec_flags |= SEC_EXCLUDE;
1298
52.0k
    break;
1299
53.7k
  case IMAGE_SCN_CNT_CODE:
1300
53.7k
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1301
53.7k
    break;
1302
39.2k
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1303
39.2k
    if (is_dbg)
1304
5.65k
      sec_flags |= SEC_DEBUGGING;
1305
33.6k
    else
1306
33.6k
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1307
39.2k
    break;
1308
29.7k
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1309
29.7k
    sec_flags |= SEC_ALLOC;
1310
29.7k
    break;
1311
54.2k
  case IMAGE_SCN_LNK_INFO:
1312
    /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
1313
       defined.  coff_compute_section_file_positions uses
1314
       COFF_PAGE_SIZE to ensure that the low order bits of the
1315
       section VMA and the file offset match.  If we don't know
1316
       COFF_PAGE_SIZE, we can't ensure the correct correspondence,
1317
       and demand page loading of the file will fail.  */
1318
54.2k
#ifdef COFF_PAGE_SIZE
1319
54.2k
    sec_flags |= SEC_DEBUGGING;
1320
54.2k
#endif
1321
54.2k
    break;
1322
63.3k
  case IMAGE_SCN_LNK_COMDAT:
1323
    /* COMDAT gets very special treatment.  */
1324
63.3k
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1325
3.71k
      result = false;
1326
63.3k
    break;
1327
623k
  default:
1328
    /* Silently ignore for now.  */
1329
623k
    break;
1330
1.47M
  }
1331
1332
      /* If the section flag was not handled, report it here.  */
1333
1.47M
      if (unhandled != NULL)
1334
177k
  {
1335
177k
    _bfd_error_handler
1336
      /* xgettext:c-format */
1337
177k
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1338
177k
       abfd, name, unhandled, flag);
1339
177k
    result = false;
1340
177k
  }
1341
1.47M
    }
1342
1343
191k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1344
191k
      && (startswith (name, ".sbss")
1345
0
    || startswith (name, ".sdata")))
1346
0
    sec_flags |= SEC_SMALL_DATA;
1347
1348
191k
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
1349
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
1350
     only link a single copy of the section.  This is used to support
1351
     g++.  g++ will emit each template expansion in its own section.
1352
     The symbols will be defined as weak, so that multiple definitions
1353
     are permitted.  The GNU linker extension is to actually discard
1354
     all but one of the sections.  */
1355
191k
  if (startswith (name, ".gnu.linkonce"))
1356
2.00k
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
1357
191k
#endif
1358
1359
191k
  if (flags_ptr)
1360
191k
    * flags_ptr = sec_flags;
1361
1362
191k
  return result;
1363
191k
}
pe-mcore.c:styp_to_sec_flags
Line
Count
Source
1192
217k
{
1193
217k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1194
217k
  unsigned long styp_flags = internal_s->s_flags;
1195
217k
  flagword sec_flags;
1196
217k
  bool result = true;
1197
217k
  bool is_dbg = false;
1198
1199
217k
  if (startswith (name, DOT_DEBUG)
1200
217k
      || startswith (name, DOT_ZDEBUG)
1201
217k
#ifdef COFF_LONG_SECTION_NAMES
1202
217k
      || startswith (name, GNU_LINKONCE_WI)
1203
217k
      || startswith (name, GNU_LINKONCE_WT)
1204
      /* FIXME: These definitions ought to be in a header file.  */
1205
217k
#define GNU_DEBUGLINK   ".gnu_debuglink"
1206
217k
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1207
217k
      || startswith (name, GNU_DEBUGLINK)
1208
217k
      || startswith (name, GNU_DEBUGALTLINK)
1209
217k
#endif
1210
217k
      || startswith (name, ".stab"))
1211
17.4k
    is_dbg = true;
1212
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1213
217k
  sec_flags = SEC_READONLY;
1214
1215
  /* If section disallows read, then set the NOREAD flag. */
1216
217k
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1217
163k
    sec_flags |= SEC_COFF_NOREAD;
1218
1219
  /* Process each flag bit in styp_flags in turn.  */
1220
1.57M
  while (styp_flags)
1221
1.35M
    {
1222
1.35M
      unsigned long flag = styp_flags & - styp_flags;
1223
1.35M
      char * unhandled = NULL;
1224
1225
1.35M
      styp_flags &= ~ flag;
1226
1227
      /* We infer from the distinct read/write/execute bits the settings
1228
   of some of the bfd flags; the actual values, should we need them,
1229
   are also in pei_section_data (abfd, section)->pe_flags.  */
1230
1231
1.35M
      switch (flag)
1232
1.35M
  {
1233
6.81k
  case STYP_DSECT:
1234
6.81k
    unhandled = "STYP_DSECT";
1235
6.81k
    break;
1236
7.47k
  case STYP_GROUP:
1237
7.47k
    unhandled = "STYP_GROUP";
1238
7.47k
    break;
1239
7.61k
  case STYP_COPY:
1240
7.61k
    unhandled = "STYP_COPY";
1241
7.61k
    break;
1242
8.52k
  case STYP_OVER:
1243
8.52k
    unhandled = "STYP_OVER";
1244
8.52k
    break;
1245
0
#ifdef SEC_NEVER_LOAD
1246
48.1k
  case STYP_NOLOAD:
1247
48.1k
    sec_flags |= SEC_NEVER_LOAD;
1248
48.1k
    break;
1249
0
#endif
1250
54.5k
  case IMAGE_SCN_MEM_READ:
1251
54.5k
    sec_flags &= ~SEC_COFF_NOREAD;
1252
54.5k
    break;
1253
42.0k
  case IMAGE_SCN_TYPE_NO_PAD:
1254
    /* Skip.  */
1255
42.0k
    break;
1256
7.73k
  case IMAGE_SCN_LNK_OTHER:
1257
7.73k
    unhandled = "IMAGE_SCN_LNK_OTHER";
1258
7.73k
    break;
1259
6.81k
  case IMAGE_SCN_MEM_NOT_CACHED:
1260
6.81k
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1261
6.81k
    break;
1262
52.5k
  case IMAGE_SCN_MEM_NOT_PAGED:
1263
    /* Generate a warning message rather using the 'unhandled'
1264
       variable as this will allow some .sys files generate by
1265
       other toolchains to be processed.  See bugzilla issue 196.  */
1266
    /* xgettext:c-format */
1267
52.5k
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1268
52.5k
        " %s in section %s"),
1269
52.5k
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1270
52.5k
    break;
1271
61.1k
  case IMAGE_SCN_MEM_EXECUTE:
1272
61.1k
    sec_flags |= SEC_CODE;
1273
61.1k
    break;
1274
41.4k
  case IMAGE_SCN_MEM_WRITE:
1275
41.4k
    sec_flags &= ~ SEC_READONLY;
1276
41.4k
    break;
1277
58.5k
  case IMAGE_SCN_MEM_DISCARDABLE:
1278
    /* The MS PE spec says that debug sections are DISCARDABLE,
1279
       but the presence of a DISCARDABLE flag does not necessarily
1280
       mean that a given section contains debug information.  Thus
1281
       we only set the SEC_DEBUGGING flag on sections that we
1282
       recognise as containing debug information.  */
1283
58.5k
       if (is_dbg
1284
58.5k
#ifdef _COMMENT
1285
58.5k
        || strcmp (name, _COMMENT) == 0
1286
58.5k
#endif
1287
58.5k
        )
1288
9.30k
      {
1289
9.30k
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1290
9.30k
      }
1291
58.5k
    break;
1292
36.5k
  case IMAGE_SCN_MEM_SHARED:
1293
36.5k
    sec_flags |= SEC_COFF_SHARED;
1294
36.5k
    break;
1295
50.2k
  case IMAGE_SCN_LNK_REMOVE:
1296
50.2k
    if (!is_dbg)
1297
43.2k
      sec_flags |= SEC_EXCLUDE;
1298
50.2k
    break;
1299
62.9k
  case IMAGE_SCN_CNT_CODE:
1300
62.9k
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1301
62.9k
    break;
1302
54.9k
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1303
54.9k
    if (is_dbg)
1304
9.16k
      sec_flags |= SEC_DEBUGGING;
1305
45.8k
    else
1306
45.8k
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1307
54.9k
    break;
1308
43.2k
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1309
43.2k
    sec_flags |= SEC_ALLOC;
1310
43.2k
    break;
1311
57.7k
  case IMAGE_SCN_LNK_INFO:
1312
    /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
1313
       defined.  coff_compute_section_file_positions uses
1314
       COFF_PAGE_SIZE to ensure that the low order bits of the
1315
       section VMA and the file offset match.  If we don't know
1316
       COFF_PAGE_SIZE, we can't ensure the correct correspondence,
1317
       and demand page loading of the file will fail.  */
1318
57.7k
#ifdef COFF_PAGE_SIZE
1319
57.7k
    sec_flags |= SEC_DEBUGGING;
1320
57.7k
#endif
1321
57.7k
    break;
1322
58.5k
  case IMAGE_SCN_LNK_COMDAT:
1323
    /* COMDAT gets very special treatment.  */
1324
58.5k
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1325
1.54k
      result = false;
1326
58.5k
    break;
1327
590k
  default:
1328
    /* Silently ignore for now.  */
1329
590k
    break;
1330
1.35M
  }
1331
1332
      /* If the section flag was not handled, report it here.  */
1333
1.35M
      if (unhandled != NULL)
1334
44.9k
  {
1335
44.9k
    _bfd_error_handler
1336
      /* xgettext:c-format */
1337
44.9k
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1338
44.9k
       abfd, name, unhandled, flag);
1339
44.9k
    result = false;
1340
44.9k
  }
1341
1.35M
    }
1342
1343
217k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1344
217k
      && (startswith (name, ".sbss")
1345
0
    || startswith (name, ".sdata")))
1346
0
    sec_flags |= SEC_SMALL_DATA;
1347
1348
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
1349
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
1350
     only link a single copy of the section.  This is used to support
1351
     g++.  g++ will emit each template expansion in its own section.
1352
     The symbols will be defined as weak, so that multiple definitions
1353
     are permitted.  The GNU linker extension is to actually discard
1354
     all but one of the sections.  */
1355
  if (startswith (name, ".gnu.linkonce"))
1356
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
1357
#endif
1358
1359
217k
  if (flags_ptr)
1360
217k
    * flags_ptr = sec_flags;
1361
1362
217k
  return result;
1363
217k
}
pe-sh.c:styp_to_sec_flags
Line
Count
Source
1192
163k
{
1193
163k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1194
163k
  unsigned long styp_flags = internal_s->s_flags;
1195
163k
  flagword sec_flags;
1196
163k
  bool result = true;
1197
163k
  bool is_dbg = false;
1198
1199
163k
  if (startswith (name, DOT_DEBUG)
1200
163k
      || startswith (name, DOT_ZDEBUG)
1201
163k
#ifdef COFF_LONG_SECTION_NAMES
1202
163k
      || startswith (name, GNU_LINKONCE_WI)
1203
163k
      || startswith (name, GNU_LINKONCE_WT)
1204
      /* FIXME: These definitions ought to be in a header file.  */
1205
163k
#define GNU_DEBUGLINK   ".gnu_debuglink"
1206
163k
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1207
163k
      || startswith (name, GNU_DEBUGLINK)
1208
163k
      || startswith (name, GNU_DEBUGALTLINK)
1209
163k
#endif
1210
163k
      || startswith (name, ".stab"))
1211
9.37k
    is_dbg = true;
1212
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1213
163k
  sec_flags = SEC_READONLY;
1214
1215
  /* If section disallows read, then set the NOREAD flag. */
1216
163k
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1217
123k
    sec_flags |= SEC_COFF_NOREAD;
1218
1219
  /* Process each flag bit in styp_flags in turn.  */
1220
1.30M
  while (styp_flags)
1221
1.14M
    {
1222
1.14M
      unsigned long flag = styp_flags & - styp_flags;
1223
1.14M
      char * unhandled = NULL;
1224
1225
1.14M
      styp_flags &= ~ flag;
1226
1227
      /* We infer from the distinct read/write/execute bits the settings
1228
   of some of the bfd flags; the actual values, should we need them,
1229
   are also in pei_section_data (abfd, section)->pe_flags.  */
1230
1231
1.14M
      switch (flag)
1232
1.14M
  {
1233
20.2k
  case STYP_DSECT:
1234
20.2k
    unhandled = "STYP_DSECT";
1235
20.2k
    break;
1236
19.6k
  case STYP_GROUP:
1237
19.6k
    unhandled = "STYP_GROUP";
1238
19.6k
    break;
1239
19.2k
  case STYP_COPY:
1240
19.2k
    unhandled = "STYP_COPY";
1241
19.2k
    break;
1242
19.1k
  case STYP_OVER:
1243
19.1k
    unhandled = "STYP_OVER";
1244
19.1k
    break;
1245
0
#ifdef SEC_NEVER_LOAD
1246
37.0k
  case STYP_NOLOAD:
1247
37.0k
    sec_flags |= SEC_NEVER_LOAD;
1248
37.0k
    break;
1249
0
#endif
1250
40.2k
  case IMAGE_SCN_MEM_READ:
1251
40.2k
    sec_flags &= ~SEC_COFF_NOREAD;
1252
40.2k
    break;
1253
31.4k
  case IMAGE_SCN_TYPE_NO_PAD:
1254
    /* Skip.  */
1255
31.4k
    break;
1256
21.6k
  case IMAGE_SCN_LNK_OTHER:
1257
21.6k
    unhandled = "IMAGE_SCN_LNK_OTHER";
1258
21.6k
    break;
1259
17.3k
  case IMAGE_SCN_MEM_NOT_CACHED:
1260
17.3k
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1261
17.3k
    break;
1262
40.1k
  case IMAGE_SCN_MEM_NOT_PAGED:
1263
    /* Generate a warning message rather using the 'unhandled'
1264
       variable as this will allow some .sys files generate by
1265
       other toolchains to be processed.  See bugzilla issue 196.  */
1266
    /* xgettext:c-format */
1267
40.1k
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1268
40.1k
        " %s in section %s"),
1269
40.1k
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1270
40.1k
    break;
1271
52.5k
  case IMAGE_SCN_MEM_EXECUTE:
1272
52.5k
    sec_flags |= SEC_CODE;
1273
52.5k
    break;
1274
27.7k
  case IMAGE_SCN_MEM_WRITE:
1275
27.7k
    sec_flags &= ~ SEC_READONLY;
1276
27.7k
    break;
1277
43.4k
  case IMAGE_SCN_MEM_DISCARDABLE:
1278
    /* The MS PE spec says that debug sections are DISCARDABLE,
1279
       but the presence of a DISCARDABLE flag does not necessarily
1280
       mean that a given section contains debug information.  Thus
1281
       we only set the SEC_DEBUGGING flag on sections that we
1282
       recognise as containing debug information.  */
1283
43.4k
       if (is_dbg
1284
43.4k
#ifdef _COMMENT
1285
43.4k
        || strcmp (name, _COMMENT) == 0
1286
43.4k
#endif
1287
43.4k
        )
1288
6.27k
      {
1289
6.27k
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1290
6.27k
      }
1291
43.4k
    break;
1292
31.0k
  case IMAGE_SCN_MEM_SHARED:
1293
31.0k
    sec_flags |= SEC_COFF_SHARED;
1294
31.0k
    break;
1295
40.9k
  case IMAGE_SCN_LNK_REMOVE:
1296
40.9k
    if (!is_dbg)
1297
36.9k
      sec_flags |= SEC_EXCLUDE;
1298
40.9k
    break;
1299
43.3k
  case IMAGE_SCN_CNT_CODE:
1300
43.3k
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1301
43.3k
    break;
1302
36.1k
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1303
36.1k
    if (is_dbg)
1304
3.55k
      sec_flags |= SEC_DEBUGGING;
1305
32.6k
    else
1306
32.6k
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1307
36.1k
    break;
1308
27.9k
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1309
27.9k
    sec_flags |= SEC_ALLOC;
1310
27.9k
    break;
1311
41.9k
  case IMAGE_SCN_LNK_INFO:
1312
    /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
1313
       defined.  coff_compute_section_file_positions uses
1314
       COFF_PAGE_SIZE to ensure that the low order bits of the
1315
       section VMA and the file offset match.  If we don't know
1316
       COFF_PAGE_SIZE, we can't ensure the correct correspondence,
1317
       and demand page loading of the file will fail.  */
1318
#ifdef COFF_PAGE_SIZE
1319
    sec_flags |= SEC_DEBUGGING;
1320
#endif
1321
41.9k
    break;
1322
50.9k
  case IMAGE_SCN_LNK_COMDAT:
1323
    /* COMDAT gets very special treatment.  */
1324
50.9k
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1325
2.76k
      result = false;
1326
50.9k
    break;
1327
482k
  default:
1328
    /* Silently ignore for now.  */
1329
482k
    break;
1330
1.14M
  }
1331
1332
      /* If the section flag was not handled, report it here.  */
1333
1.14M
      if (unhandled != NULL)
1334
117k
  {
1335
117k
    _bfd_error_handler
1336
      /* xgettext:c-format */
1337
117k
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1338
117k
       abfd, name, unhandled, flag);
1339
117k
    result = false;
1340
117k
  }
1341
1.14M
    }
1342
1343
163k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1344
163k
      && (startswith (name, ".sbss")
1345
0
    || startswith (name, ".sdata")))
1346
0
    sec_flags |= SEC_SMALL_DATA;
1347
1348
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
1349
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
1350
     only link a single copy of the section.  This is used to support
1351
     g++.  g++ will emit each template expansion in its own section.
1352
     The symbols will be defined as weak, so that multiple definitions
1353
     are permitted.  The GNU linker extension is to actually discard
1354
     all but one of the sections.  */
1355
  if (startswith (name, ".gnu.linkonce"))
1356
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
1357
#endif
1358
1359
163k
  if (flags_ptr)
1360
163k
    * flags_ptr = sec_flags;
1361
1362
163k
  return result;
1363
163k
}
pei-arm-wince.c:styp_to_sec_flags
Line
Count
Source
1192
266k
{
1193
266k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1194
266k
  unsigned long styp_flags = internal_s->s_flags;
1195
266k
  flagword sec_flags;
1196
266k
  bool result = true;
1197
266k
  bool is_dbg = false;
1198
1199
266k
  if (startswith (name, DOT_DEBUG)
1200
266k
      || startswith (name, DOT_ZDEBUG)
1201
266k
#ifdef COFF_LONG_SECTION_NAMES
1202
266k
      || startswith (name, GNU_LINKONCE_WI)
1203
266k
      || startswith (name, GNU_LINKONCE_WT)
1204
      /* FIXME: These definitions ought to be in a header file.  */
1205
266k
#define GNU_DEBUGLINK   ".gnu_debuglink"
1206
266k
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1207
266k
      || startswith (name, GNU_DEBUGLINK)
1208
266k
      || startswith (name, GNU_DEBUGALTLINK)
1209
266k
#endif
1210
266k
      || startswith (name, ".stab"))
1211
14.4k
    is_dbg = true;
1212
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1213
266k
  sec_flags = SEC_READONLY;
1214
1215
  /* If section disallows read, then set the NOREAD flag. */
1216
266k
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1217
186k
    sec_flags |= SEC_COFF_NOREAD;
1218
1219
  /* Process each flag bit in styp_flags in turn.  */
1220
2.34M
  while (styp_flags)
1221
2.08M
    {
1222
2.08M
      unsigned long flag = styp_flags & - styp_flags;
1223
2.08M
      char * unhandled = NULL;
1224
1225
2.08M
      styp_flags &= ~ flag;
1226
1227
      /* We infer from the distinct read/write/execute bits the settings
1228
   of some of the bfd flags; the actual values, should we need them,
1229
   are also in pei_section_data (abfd, section)->pe_flags.  */
1230
1231
2.08M
      switch (flag)
1232
2.08M
  {
1233
40.2k
  case STYP_DSECT:
1234
40.2k
    unhandled = "STYP_DSECT";
1235
40.2k
    break;
1236
38.5k
  case STYP_GROUP:
1237
38.5k
    unhandled = "STYP_GROUP";
1238
38.5k
    break;
1239
41.7k
  case STYP_COPY:
1240
41.7k
    unhandled = "STYP_COPY";
1241
41.7k
    break;
1242
42.7k
  case STYP_OVER:
1243
42.7k
    unhandled = "STYP_OVER";
1244
42.7k
    break;
1245
0
#ifdef SEC_NEVER_LOAD
1246
61.4k
  case STYP_NOLOAD:
1247
61.4k
    sec_flags |= SEC_NEVER_LOAD;
1248
61.4k
    break;
1249
0
#endif
1250
79.5k
  case IMAGE_SCN_MEM_READ:
1251
79.5k
    sec_flags &= ~SEC_COFF_NOREAD;
1252
79.5k
    break;
1253
59.0k
  case IMAGE_SCN_TYPE_NO_PAD:
1254
    /* Skip.  */
1255
59.0k
    break;
1256
42.3k
  case IMAGE_SCN_LNK_OTHER:
1257
42.3k
    unhandled = "IMAGE_SCN_LNK_OTHER";
1258
42.3k
    break;
1259
43.1k
  case IMAGE_SCN_MEM_NOT_CACHED:
1260
43.1k
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1261
43.1k
    break;
1262
63.8k
  case IMAGE_SCN_MEM_NOT_PAGED:
1263
    /* Generate a warning message rather using the 'unhandled'
1264
       variable as this will allow some .sys files generate by
1265
       other toolchains to be processed.  See bugzilla issue 196.  */
1266
    /* xgettext:c-format */
1267
63.8k
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1268
63.8k
        " %s in section %s"),
1269
63.8k
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1270
63.8k
    break;
1271
84.9k
  case IMAGE_SCN_MEM_EXECUTE:
1272
84.9k
    sec_flags |= SEC_CODE;
1273
84.9k
    break;
1274
62.8k
  case IMAGE_SCN_MEM_WRITE:
1275
62.8k
    sec_flags &= ~ SEC_READONLY;
1276
62.8k
    break;
1277
85.4k
  case IMAGE_SCN_MEM_DISCARDABLE:
1278
    /* The MS PE spec says that debug sections are DISCARDABLE,
1279
       but the presence of a DISCARDABLE flag does not necessarily
1280
       mean that a given section contains debug information.  Thus
1281
       we only set the SEC_DEBUGGING flag on sections that we
1282
       recognise as containing debug information.  */
1283
85.4k
       if (is_dbg
1284
85.4k
#ifdef _COMMENT
1285
85.4k
        || strcmp (name, _COMMENT) == 0
1286
85.4k
#endif
1287
85.4k
        )
1288
7.26k
      {
1289
7.26k
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1290
7.26k
      }
1291
85.4k
    break;
1292
58.5k
  case IMAGE_SCN_MEM_SHARED:
1293
58.5k
    sec_flags |= SEC_COFF_SHARED;
1294
58.5k
    break;
1295
77.2k
  case IMAGE_SCN_LNK_REMOVE:
1296
77.2k
    if (!is_dbg)
1297
73.0k
      sec_flags |= SEC_EXCLUDE;
1298
77.2k
    break;
1299
63.9k
  case IMAGE_SCN_CNT_CODE:
1300
63.9k
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1301
63.9k
    break;
1302
62.1k
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1303
62.1k
    if (is_dbg)
1304
5.90k
      sec_flags |= SEC_DEBUGGING;
1305
56.2k
    else
1306
56.2k
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1307
62.1k
    break;
1308
52.9k
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1309
52.9k
    sec_flags |= SEC_ALLOC;
1310
52.9k
    break;
1311
73.3k
  case IMAGE_SCN_LNK_INFO:
1312
    /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
1313
       defined.  coff_compute_section_file_positions uses
1314
       COFF_PAGE_SIZE to ensure that the low order bits of the
1315
       section VMA and the file offset match.  If we don't know
1316
       COFF_PAGE_SIZE, we can't ensure the correct correspondence,
1317
       and demand page loading of the file will fail.  */
1318
73.3k
#ifdef COFF_PAGE_SIZE
1319
73.3k
    sec_flags |= SEC_DEBUGGING;
1320
73.3k
#endif
1321
73.3k
    break;
1322
94.6k
  case IMAGE_SCN_LNK_COMDAT:
1323
    /* COMDAT gets very special treatment.  */
1324
94.6k
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1325
7.94k
      result = false;
1326
94.6k
    break;
1327
852k
  default:
1328
    /* Silently ignore for now.  */
1329
852k
    break;
1330
2.08M
  }
1331
1332
      /* If the section flag was not handled, report it here.  */
1333
2.08M
      if (unhandled != NULL)
1334
248k
  {
1335
248k
    _bfd_error_handler
1336
      /* xgettext:c-format */
1337
248k
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1338
248k
       abfd, name, unhandled, flag);
1339
248k
    result = false;
1340
248k
  }
1341
2.08M
    }
1342
1343
266k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1344
266k
      && (startswith (name, ".sbss")
1345
0
    || startswith (name, ".sdata")))
1346
0
    sec_flags |= SEC_SMALL_DATA;
1347
1348
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
1349
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
1350
     only link a single copy of the section.  This is used to support
1351
     g++.  g++ will emit each template expansion in its own section.
1352
     The symbols will be defined as weak, so that multiple definitions
1353
     are permitted.  The GNU linker extension is to actually discard
1354
     all but one of the sections.  */
1355
  if (startswith (name, ".gnu.linkonce"))
1356
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
1357
#endif
1358
1359
266k
  if (flags_ptr)
1360
266k
    * flags_ptr = sec_flags;
1361
1362
266k
  return result;
1363
266k
}
pei-arm.c:styp_to_sec_flags
Line
Count
Source
1192
330k
{
1193
330k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1194
330k
  unsigned long styp_flags = internal_s->s_flags;
1195
330k
  flagword sec_flags;
1196
330k
  bool result = true;
1197
330k
  bool is_dbg = false;
1198
1199
330k
  if (startswith (name, DOT_DEBUG)
1200
330k
      || startswith (name, DOT_ZDEBUG)
1201
330k
#ifdef COFF_LONG_SECTION_NAMES
1202
330k
      || startswith (name, GNU_LINKONCE_WI)
1203
330k
      || startswith (name, GNU_LINKONCE_WT)
1204
      /* FIXME: These definitions ought to be in a header file.  */
1205
330k
#define GNU_DEBUGLINK   ".gnu_debuglink"
1206
330k
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1207
330k
      || startswith (name, GNU_DEBUGLINK)
1208
330k
      || startswith (name, GNU_DEBUGALTLINK)
1209
330k
#endif
1210
330k
      || startswith (name, ".stab"))
1211
18.4k
    is_dbg = true;
1212
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1213
330k
  sec_flags = SEC_READONLY;
1214
1215
  /* If section disallows read, then set the NOREAD flag. */
1216
330k
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1217
232k
    sec_flags |= SEC_COFF_NOREAD;
1218
1219
  /* Process each flag bit in styp_flags in turn.  */
1220
2.86M
  while (styp_flags)
1221
2.53M
    {
1222
2.53M
      unsigned long flag = styp_flags & - styp_flags;
1223
2.53M
      char * unhandled = NULL;
1224
1225
2.53M
      styp_flags &= ~ flag;
1226
1227
      /* We infer from the distinct read/write/execute bits the settings
1228
   of some of the bfd flags; the actual values, should we need them,
1229
   are also in pei_section_data (abfd, section)->pe_flags.  */
1230
1231
2.53M
      switch (flag)
1232
2.53M
  {
1233
47.4k
  case STYP_DSECT:
1234
47.4k
    unhandled = "STYP_DSECT";
1235
47.4k
    break;
1236
45.1k
  case STYP_GROUP:
1237
45.1k
    unhandled = "STYP_GROUP";
1238
45.1k
    break;
1239
49.3k
  case STYP_COPY:
1240
49.3k
    unhandled = "STYP_COPY";
1241
49.3k
    break;
1242
50.7k
  case STYP_OVER:
1243
50.7k
    unhandled = "STYP_OVER";
1244
50.7k
    break;
1245
0
#ifdef SEC_NEVER_LOAD
1246
74.8k
  case STYP_NOLOAD:
1247
74.8k
    sec_flags |= SEC_NEVER_LOAD;
1248
74.8k
    break;
1249
0
#endif
1250
98.1k
  case IMAGE_SCN_MEM_READ:
1251
98.1k
    sec_flags &= ~SEC_COFF_NOREAD;
1252
98.1k
    break;
1253
72.6k
  case IMAGE_SCN_TYPE_NO_PAD:
1254
    /* Skip.  */
1255
72.6k
    break;
1256
51.6k
  case IMAGE_SCN_LNK_OTHER:
1257
51.6k
    unhandled = "IMAGE_SCN_LNK_OTHER";
1258
51.6k
    break;
1259
52.2k
  case IMAGE_SCN_MEM_NOT_CACHED:
1260
52.2k
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1261
52.2k
    break;
1262
80.6k
  case IMAGE_SCN_MEM_NOT_PAGED:
1263
    /* Generate a warning message rather using the 'unhandled'
1264
       variable as this will allow some .sys files generate by
1265
       other toolchains to be processed.  See bugzilla issue 196.  */
1266
    /* xgettext:c-format */
1267
80.6k
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1268
80.6k
        " %s in section %s"),
1269
80.6k
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1270
80.6k
    break;
1271
102k
  case IMAGE_SCN_MEM_EXECUTE:
1272
102k
    sec_flags |= SEC_CODE;
1273
102k
    break;
1274
79.7k
  case IMAGE_SCN_MEM_WRITE:
1275
79.7k
    sec_flags &= ~ SEC_READONLY;
1276
79.7k
    break;
1277
105k
  case IMAGE_SCN_MEM_DISCARDABLE:
1278
    /* The MS PE spec says that debug sections are DISCARDABLE,
1279
       but the presence of a DISCARDABLE flag does not necessarily
1280
       mean that a given section contains debug information.  Thus
1281
       we only set the SEC_DEBUGGING flag on sections that we
1282
       recognise as containing debug information.  */
1283
105k
       if (is_dbg
1284
105k
#ifdef _COMMENT
1285
105k
        || strcmp (name, _COMMENT) == 0
1286
105k
#endif
1287
105k
        )
1288
8.16k
      {
1289
8.16k
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1290
8.16k
      }
1291
105k
    break;
1292
70.8k
  case IMAGE_SCN_MEM_SHARED:
1293
70.8k
    sec_flags |= SEC_COFF_SHARED;
1294
70.8k
    break;
1295
92.0k
  case IMAGE_SCN_LNK_REMOVE:
1296
92.0k
    if (!is_dbg)
1297
85.9k
      sec_flags |= SEC_EXCLUDE;
1298
92.0k
    break;
1299
81.9k
  case IMAGE_SCN_CNT_CODE:
1300
81.9k
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1301
81.9k
    break;
1302
76.4k
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1303
76.4k
    if (is_dbg)
1304
6.19k
      sec_flags |= SEC_DEBUGGING;
1305
70.2k
    else
1306
70.2k
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1307
76.4k
    break;
1308
68.5k
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1309
68.5k
    sec_flags |= SEC_ALLOC;
1310
68.5k
    break;
1311
90.7k
  case IMAGE_SCN_LNK_INFO:
1312
    /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
1313
       defined.  coff_compute_section_file_positions uses
1314
       COFF_PAGE_SIZE to ensure that the low order bits of the
1315
       section VMA and the file offset match.  If we don't know
1316
       COFF_PAGE_SIZE, we can't ensure the correct correspondence,
1317
       and demand page loading of the file will fail.  */
1318
90.7k
#ifdef COFF_PAGE_SIZE
1319
90.7k
    sec_flags |= SEC_DEBUGGING;
1320
90.7k
#endif
1321
90.7k
    break;
1322
106k
  case IMAGE_SCN_LNK_COMDAT:
1323
    /* COMDAT gets very special treatment.  */
1324
106k
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1325
8.77k
      result = false;
1326
106k
    break;
1327
1.04M
  default:
1328
    /* Silently ignore for now.  */
1329
1.04M
    break;
1330
2.53M
  }
1331
1332
      /* If the section flag was not handled, report it here.  */
1333
2.53M
      if (unhandled != NULL)
1334
296k
  {
1335
296k
    _bfd_error_handler
1336
      /* xgettext:c-format */
1337
296k
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1338
296k
       abfd, name, unhandled, flag);
1339
296k
    result = false;
1340
296k
  }
1341
2.53M
    }
1342
1343
330k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1344
330k
      && (startswith (name, ".sbss")
1345
0
    || startswith (name, ".sdata")))
1346
0
    sec_flags |= SEC_SMALL_DATA;
1347
1348
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
1349
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
1350
     only link a single copy of the section.  This is used to support
1351
     g++.  g++ will emit each template expansion in its own section.
1352
     The symbols will be defined as weak, so that multiple definitions
1353
     are permitted.  The GNU linker extension is to actually discard
1354
     all but one of the sections.  */
1355
  if (startswith (name, ".gnu.linkonce"))
1356
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
1357
#endif
1358
1359
330k
  if (flags_ptr)
1360
330k
    * flags_ptr = sec_flags;
1361
1362
330k
  return result;
1363
330k
}
pei-mcore.c:styp_to_sec_flags
Line
Count
Source
1192
260k
{
1193
260k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1194
260k
  unsigned long styp_flags = internal_s->s_flags;
1195
260k
  flagword sec_flags;
1196
260k
  bool result = true;
1197
260k
  bool is_dbg = false;
1198
1199
260k
  if (startswith (name, DOT_DEBUG)
1200
260k
      || startswith (name, DOT_ZDEBUG)
1201
260k
#ifdef COFF_LONG_SECTION_NAMES
1202
260k
      || startswith (name, GNU_LINKONCE_WI)
1203
260k
      || startswith (name, GNU_LINKONCE_WT)
1204
      /* FIXME: These definitions ought to be in a header file.  */
1205
260k
#define GNU_DEBUGLINK   ".gnu_debuglink"
1206
260k
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1207
260k
      || startswith (name, GNU_DEBUGLINK)
1208
260k
      || startswith (name, GNU_DEBUGALTLINK)
1209
260k
#endif
1210
260k
      || startswith (name, ".stab"))
1211
14.7k
    is_dbg = true;
1212
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1213
260k
  sec_flags = SEC_READONLY;
1214
1215
  /* If section disallows read, then set the NOREAD flag. */
1216
260k
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1217
195k
    sec_flags |= SEC_COFF_NOREAD;
1218
1219
  /* Process each flag bit in styp_flags in turn.  */
1220
1.98M
  while (styp_flags)
1221
1.72M
    {
1222
1.72M
      unsigned long flag = styp_flags & - styp_flags;
1223
1.72M
      char * unhandled = NULL;
1224
1225
1.72M
      styp_flags &= ~ flag;
1226
1227
      /* We infer from the distinct read/write/execute bits the settings
1228
   of some of the bfd flags; the actual values, should we need them,
1229
   are also in pei_section_data (abfd, section)->pe_flags.  */
1230
1231
1.72M
      switch (flag)
1232
1.72M
  {
1233
21.1k
  case STYP_DSECT:
1234
21.1k
    unhandled = "STYP_DSECT";
1235
21.1k
    break;
1236
17.7k
  case STYP_GROUP:
1237
17.7k
    unhandled = "STYP_GROUP";
1238
17.7k
    break;
1239
23.1k
  case STYP_COPY:
1240
23.1k
    unhandled = "STYP_COPY";
1241
23.1k
    break;
1242
20.9k
  case STYP_OVER:
1243
20.9k
    unhandled = "STYP_OVER";
1244
20.9k
    break;
1245
0
#ifdef SEC_NEVER_LOAD
1246
53.8k
  case STYP_NOLOAD:
1247
53.8k
    sec_flags |= SEC_NEVER_LOAD;
1248
53.8k
    break;
1249
0
#endif
1250
64.9k
  case IMAGE_SCN_MEM_READ:
1251
64.9k
    sec_flags &= ~SEC_COFF_NOREAD;
1252
64.9k
    break;
1253
52.3k
  case IMAGE_SCN_TYPE_NO_PAD:
1254
    /* Skip.  */
1255
52.3k
    break;
1256
22.0k
  case IMAGE_SCN_LNK_OTHER:
1257
22.0k
    unhandled = "IMAGE_SCN_LNK_OTHER";
1258
22.0k
    break;
1259
18.9k
  case IMAGE_SCN_MEM_NOT_CACHED:
1260
18.9k
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1261
18.9k
    break;
1262
59.2k
  case IMAGE_SCN_MEM_NOT_PAGED:
1263
    /* Generate a warning message rather using the 'unhandled'
1264
       variable as this will allow some .sys files generate by
1265
       other toolchains to be processed.  See bugzilla issue 196.  */
1266
    /* xgettext:c-format */
1267
59.2k
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1268
59.2k
        " %s in section %s"),
1269
59.2k
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1270
59.2k
    break;
1271
86.1k
  case IMAGE_SCN_MEM_EXECUTE:
1272
86.1k
    sec_flags |= SEC_CODE;
1273
86.1k
    break;
1274
53.2k
  case IMAGE_SCN_MEM_WRITE:
1275
53.2k
    sec_flags &= ~ SEC_READONLY;
1276
53.2k
    break;
1277
83.3k
  case IMAGE_SCN_MEM_DISCARDABLE:
1278
    /* The MS PE spec says that debug sections are DISCARDABLE,
1279
       but the presence of a DISCARDABLE flag does not necessarily
1280
       mean that a given section contains debug information.  Thus
1281
       we only set the SEC_DEBUGGING flag on sections that we
1282
       recognise as containing debug information.  */
1283
83.3k
       if (is_dbg
1284
83.3k
#ifdef _COMMENT
1285
83.3k
        || strcmp (name, _COMMENT) == 0
1286
83.3k
#endif
1287
83.3k
        )
1288
9.53k
      {
1289
9.53k
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1290
9.53k
      }
1291
83.3k
    break;
1292
46.6k
  case IMAGE_SCN_MEM_SHARED:
1293
46.6k
    sec_flags |= SEC_COFF_SHARED;
1294
46.6k
    break;
1295
69.2k
  case IMAGE_SCN_LNK_REMOVE:
1296
69.2k
    if (!is_dbg)
1297
62.1k
      sec_flags |= SEC_EXCLUDE;
1298
69.2k
    break;
1299
65.1k
  case IMAGE_SCN_CNT_CODE:
1300
65.1k
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1301
65.1k
    break;
1302
55.0k
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1303
55.0k
    if (is_dbg)
1304
4.69k
      sec_flags |= SEC_DEBUGGING;
1305
50.3k
    else
1306
50.3k
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1307
55.0k
    break;
1308
53.1k
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1309
53.1k
    sec_flags |= SEC_ALLOC;
1310
53.1k
    break;
1311
64.2k
  case IMAGE_SCN_LNK_INFO:
1312
    /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
1313
       defined.  coff_compute_section_file_positions uses
1314
       COFF_PAGE_SIZE to ensure that the low order bits of the
1315
       section VMA and the file offset match.  If we don't know
1316
       COFF_PAGE_SIZE, we can't ensure the correct correspondence,
1317
       and demand page loading of the file will fail.  */
1318
64.2k
#ifdef COFF_PAGE_SIZE
1319
64.2k
    sec_flags |= SEC_DEBUGGING;
1320
64.2k
#endif
1321
64.2k
    break;
1322
71.7k
  case IMAGE_SCN_LNK_COMDAT:
1323
    /* COMDAT gets very special treatment.  */
1324
71.7k
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1325
3.95k
      result = false;
1326
71.7k
    break;
1327
718k
  default:
1328
    /* Silently ignore for now.  */
1329
718k
    break;
1330
1.72M
  }
1331
1332
      /* If the section flag was not handled, report it here.  */
1333
1.72M
      if (unhandled != NULL)
1334
124k
  {
1335
124k
    _bfd_error_handler
1336
      /* xgettext:c-format */
1337
124k
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1338
124k
       abfd, name, unhandled, flag);
1339
124k
    result = false;
1340
124k
  }
1341
1.72M
    }
1342
1343
260k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1344
260k
      && (startswith (name, ".sbss")
1345
0
    || startswith (name, ".sdata")))
1346
0
    sec_flags |= SEC_SMALL_DATA;
1347
1348
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
1349
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
1350
     only link a single copy of the section.  This is used to support
1351
     g++.  g++ will emit each template expansion in its own section.
1352
     The symbols will be defined as weak, so that multiple definitions
1353
     are permitted.  The GNU linker extension is to actually discard
1354
     all but one of the sections.  */
1355
  if (startswith (name, ".gnu.linkonce"))
1356
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
1357
#endif
1358
1359
260k
  if (flags_ptr)
1360
260k
    * flags_ptr = sec_flags;
1361
1362
260k
  return result;
1363
260k
}
pei-sh.c:styp_to_sec_flags
Line
Count
Source
1192
284k
{
1193
284k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1194
284k
  unsigned long styp_flags = internal_s->s_flags;
1195
284k
  flagword sec_flags;
1196
284k
  bool result = true;
1197
284k
  bool is_dbg = false;
1198
1199
284k
  if (startswith (name, DOT_DEBUG)
1200
284k
      || startswith (name, DOT_ZDEBUG)
1201
284k
#ifdef COFF_LONG_SECTION_NAMES
1202
284k
      || startswith (name, GNU_LINKONCE_WI)
1203
284k
      || startswith (name, GNU_LINKONCE_WT)
1204
      /* FIXME: These definitions ought to be in a header file.  */
1205
284k
#define GNU_DEBUGLINK   ".gnu_debuglink"
1206
284k
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1207
284k
      || startswith (name, GNU_DEBUGLINK)
1208
284k
      || startswith (name, GNU_DEBUGALTLINK)
1209
284k
#endif
1210
284k
      || startswith (name, ".stab"))
1211
17.9k
    is_dbg = true;
1212
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1213
284k
  sec_flags = SEC_READONLY;
1214
1215
  /* If section disallows read, then set the NOREAD flag. */
1216
284k
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1217
208k
    sec_flags |= SEC_COFF_NOREAD;
1218
1219
  /* Process each flag bit in styp_flags in turn.  */
1220
2.17M
  while (styp_flags)
1221
1.89M
    {
1222
1.89M
      unsigned long flag = styp_flags & - styp_flags;
1223
1.89M
      char * unhandled = NULL;
1224
1225
1.89M
      styp_flags &= ~ flag;
1226
1227
      /* We infer from the distinct read/write/execute bits the settings
1228
   of some of the bfd flags; the actual values, should we need them,
1229
   are also in pei_section_data (abfd, section)->pe_flags.  */
1230
1231
1.89M
      switch (flag)
1232
1.89M
  {
1233
25.9k
  case STYP_DSECT:
1234
25.9k
    unhandled = "STYP_DSECT";
1235
25.9k
    break;
1236
22.9k
  case STYP_GROUP:
1237
22.9k
    unhandled = "STYP_GROUP";
1238
22.9k
    break;
1239
25.5k
  case STYP_COPY:
1240
25.5k
    unhandled = "STYP_COPY";
1241
25.5k
    break;
1242
28.2k
  case STYP_OVER:
1243
28.2k
    unhandled = "STYP_OVER";
1244
28.2k
    break;
1245
0
#ifdef SEC_NEVER_LOAD
1246
55.6k
  case STYP_NOLOAD:
1247
55.6k
    sec_flags |= SEC_NEVER_LOAD;
1248
55.6k
    break;
1249
0
#endif
1250
75.6k
  case IMAGE_SCN_MEM_READ:
1251
75.6k
    sec_flags &= ~SEC_COFF_NOREAD;
1252
75.6k
    break;
1253
58.3k
  case IMAGE_SCN_TYPE_NO_PAD:
1254
    /* Skip.  */
1255
58.3k
    break;
1256
27.0k
  case IMAGE_SCN_LNK_OTHER:
1257
27.0k
    unhandled = "IMAGE_SCN_LNK_OTHER";
1258
27.0k
    break;
1259
23.7k
  case IMAGE_SCN_MEM_NOT_CACHED:
1260
23.7k
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1261
23.7k
    break;
1262
82.1k
  case IMAGE_SCN_MEM_NOT_PAGED:
1263
    /* Generate a warning message rather using the 'unhandled'
1264
       variable as this will allow some .sys files generate by
1265
       other toolchains to be processed.  See bugzilla issue 196.  */
1266
    /* xgettext:c-format */
1267
82.1k
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1268
82.1k
        " %s in section %s"),
1269
82.1k
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1270
82.1k
    break;
1271
80.7k
  case IMAGE_SCN_MEM_EXECUTE:
1272
80.7k
    sec_flags |= SEC_CODE;
1273
80.7k
    break;
1274
57.4k
  case IMAGE_SCN_MEM_WRITE:
1275
57.4k
    sec_flags &= ~ SEC_READONLY;
1276
57.4k
    break;
1277
94.5k
  case IMAGE_SCN_MEM_DISCARDABLE:
1278
    /* The MS PE spec says that debug sections are DISCARDABLE,
1279
       but the presence of a DISCARDABLE flag does not necessarily
1280
       mean that a given section contains debug information.  Thus
1281
       we only set the SEC_DEBUGGING flag on sections that we
1282
       recognise as containing debug information.  */
1283
94.5k
       if (is_dbg
1284
94.5k
#ifdef _COMMENT
1285
94.5k
        || strcmp (name, _COMMENT) == 0
1286
94.5k
#endif
1287
94.5k
        )
1288
12.4k
      {
1289
12.4k
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1290
12.4k
      }
1291
94.5k
    break;
1292
60.6k
  case IMAGE_SCN_MEM_SHARED:
1293
60.6k
    sec_flags |= SEC_COFF_SHARED;
1294
60.6k
    break;
1295
77.0k
  case IMAGE_SCN_LNK_REMOVE:
1296
77.0k
    if (!is_dbg)
1297
70.1k
      sec_flags |= SEC_EXCLUDE;
1298
77.0k
    break;
1299
63.3k
  case IMAGE_SCN_CNT_CODE:
1300
63.3k
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1301
63.3k
    break;
1302
46.4k
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1303
46.4k
    if (is_dbg)
1304
4.84k
      sec_flags |= SEC_DEBUGGING;
1305
41.5k
    else
1306
41.5k
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1307
46.4k
    break;
1308
48.5k
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1309
48.5k
    sec_flags |= SEC_ALLOC;
1310
48.5k
    break;
1311
67.7k
  case IMAGE_SCN_LNK_INFO:
1312
    /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
1313
       defined.  coff_compute_section_file_positions uses
1314
       COFF_PAGE_SIZE to ensure that the low order bits of the
1315
       section VMA and the file offset match.  If we don't know
1316
       COFF_PAGE_SIZE, we can't ensure the correct correspondence,
1317
       and demand page loading of the file will fail.  */
1318
67.7k
#ifdef COFF_PAGE_SIZE
1319
67.7k
    sec_flags |= SEC_DEBUGGING;
1320
67.7k
#endif
1321
67.7k
    break;
1322
84.7k
  case IMAGE_SCN_LNK_COMDAT:
1323
    /* COMDAT gets very special treatment.  */
1324
84.7k
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1325
4.93k
      result = false;
1326
84.7k
    break;
1327
783k
  default:
1328
    /* Silently ignore for now.  */
1329
783k
    break;
1330
1.89M
  }
1331
1332
      /* If the section flag was not handled, report it here.  */
1333
1.89M
      if (unhandled != NULL)
1334
153k
  {
1335
153k
    _bfd_error_handler
1336
      /* xgettext:c-format */
1337
153k
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1338
153k
       abfd, name, unhandled, flag);
1339
153k
    result = false;
1340
153k
  }
1341
1.89M
    }
1342
1343
284k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1344
284k
      && (startswith (name, ".sbss")
1345
0
    || startswith (name, ".sdata")))
1346
0
    sec_flags |= SEC_SMALL_DATA;
1347
1348
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
1349
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
1350
     only link a single copy of the section.  This is used to support
1351
     g++.  g++ will emit each template expansion in its own section.
1352
     The symbols will be defined as weak, so that multiple definitions
1353
     are permitted.  The GNU linker extension is to actually discard
1354
     all but one of the sections.  */
1355
  if (startswith (name, ".gnu.linkonce"))
1356
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
1357
#endif
1358
1359
284k
  if (flags_ptr)
1360
284k
    * flags_ptr = sec_flags;
1361
1362
284k
  return result;
1363
284k
}
1364
1365
#endif /* COFF_WITH_PE */
1366
1367
0
#define get_index(symbol) ((symbol)->udata.i)
1368
1369
/*
1370
INTERNAL_DEFINITION
1371
  bfd_coff_backend_data
1372
1373
INTERNAL
1374
.{* COFF symbol classifications.  *}
1375
.
1376
.enum coff_symbol_classification
1377
.{
1378
.  {* Global symbol.  *}
1379
.  COFF_SYMBOL_GLOBAL,
1380
.  {* Common symbol.  *}
1381
.  COFF_SYMBOL_COMMON,
1382
.  {* Undefined symbol.  *}
1383
.  COFF_SYMBOL_UNDEFINED,
1384
.  {* Local symbol.  *}
1385
.  COFF_SYMBOL_LOCAL,
1386
.  {* PE section symbol.  *}
1387
.  COFF_SYMBOL_PE_SECTION
1388
.};
1389
.
1390
.typedef asection * (*coff_gc_mark_hook_fn)
1391
.  (asection *, struct bfd_link_info *, struct internal_reloc *,
1392
.   struct coff_link_hash_entry *, struct internal_syment *);
1393
.
1394
1395
Special entry points for gdb to swap in coff symbol table parts:
1396
1397
CODE_FRAGMENT
1398
.typedef struct
1399
.{
1400
.  void (*_bfd_coff_swap_aux_in)
1401
.    (bfd *, void *, int, int, int, int, void *);
1402
.
1403
.  void (*_bfd_coff_swap_sym_in)
1404
.    (bfd *, void *, void *);
1405
.
1406
.  void (*_bfd_coff_swap_lineno_in)
1407
.    (bfd *, void *, void *);
1408
.
1409
.  unsigned int (*_bfd_coff_swap_aux_out)
1410
.    (bfd *, void *, int, int, int, int, void *);
1411
.
1412
.  unsigned int (*_bfd_coff_swap_sym_out)
1413
.    (bfd *, void *, void *);
1414
.
1415
.  unsigned int (*_bfd_coff_swap_lineno_out)
1416
.    (bfd *, void *, void *);
1417
.
1418
.  unsigned int (*_bfd_coff_swap_reloc_out)
1419
.    (bfd *, void *, void *);
1420
.
1421
.  unsigned int (*_bfd_coff_swap_filehdr_out)
1422
.    (bfd *, void *, void *);
1423
.
1424
.  unsigned int (*_bfd_coff_swap_aouthdr_out)
1425
.    (bfd *, void *, void *);
1426
.
1427
.  unsigned int (*_bfd_coff_swap_scnhdr_out)
1428
.    (bfd *, void *, void *);
1429
.
1430
.  unsigned int _bfd_filhsz;
1431
.  unsigned int _bfd_aoutsz;
1432
.  unsigned int _bfd_scnhsz;
1433
.  unsigned int _bfd_symesz;
1434
.  unsigned int _bfd_auxesz;
1435
.  unsigned int _bfd_relsz;
1436
.  unsigned int _bfd_linesz;
1437
.  unsigned int _bfd_filnmlen;
1438
.  bool _bfd_coff_long_filenames;
1439
.
1440
.  bool _bfd_coff_long_section_names;
1441
.  bool (*_bfd_coff_set_long_section_names)
1442
.    (bfd *, int);
1443
.
1444
.  unsigned int _bfd_coff_default_section_alignment_power;
1445
.  bool _bfd_coff_force_symnames_in_strings;
1446
.  unsigned int _bfd_coff_debug_string_prefix_length;
1447
.  unsigned int _bfd_coff_max_nscns;
1448
.
1449
.  void (*_bfd_coff_swap_filehdr_in)
1450
.    (bfd *, void *, void *);
1451
.
1452
.  void (*_bfd_coff_swap_aouthdr_in)
1453
.    (bfd *, void *, void *);
1454
.
1455
.  void (*_bfd_coff_swap_scnhdr_in)
1456
.    (bfd *, void *, void *);
1457
.
1458
.  void (*_bfd_coff_swap_reloc_in)
1459
.    (bfd *abfd, void *, void *);
1460
.
1461
.  bool (*_bfd_coff_bad_format_hook)
1462
.    (bfd *, void *);
1463
.
1464
.  bool (*_bfd_coff_set_arch_mach_hook)
1465
.    (bfd *, void *);
1466
.
1467
.  void * (*_bfd_coff_mkobject_hook)
1468
.    (bfd *, void *, void *);
1469
.
1470
.  bool (*_bfd_styp_to_sec_flags_hook)
1471
.    (bfd *, void *, const char *, asection *, flagword *);
1472
.
1473
.  void (*_bfd_set_alignment_hook)
1474
.    (bfd *, asection *, void *);
1475
.
1476
.  bool (*_bfd_coff_slurp_symbol_table)
1477
.    (bfd *);
1478
.
1479
.  bool (*_bfd_coff_symname_in_debug)
1480
.    (bfd *, struct internal_syment *);
1481
.
1482
.  bool (*_bfd_coff_pointerize_aux_hook)
1483
.    (bfd *, combined_entry_type *, combined_entry_type *,
1484
.     unsigned int, combined_entry_type *);
1485
.
1486
.  bool (*_bfd_coff_print_aux)
1487
.    (bfd *, FILE *, combined_entry_type *, combined_entry_type *,
1488
.     combined_entry_type *, unsigned int);
1489
.
1490
.  bool (*_bfd_coff_reloc16_extra_cases)
1491
.    (bfd *, struct bfd_link_info *, struct bfd_link_order *, arelent *,
1492
.     bfd_byte *, size_t *, size_t *);
1493
.
1494
.  int (*_bfd_coff_reloc16_estimate)
1495
.    (bfd *, asection *, arelent *, unsigned int,
1496
.     struct bfd_link_info *);
1497
.
1498
.  enum coff_symbol_classification (*_bfd_coff_classify_symbol)
1499
.    (bfd *, struct internal_syment *);
1500
.
1501
.  bool (*_bfd_coff_compute_section_file_positions)
1502
.    (bfd *);
1503
.
1504
.  bool (*_bfd_coff_start_final_link)
1505
.    (bfd *, struct bfd_link_info *);
1506
.
1507
.  bool (*_bfd_coff_relocate_section)
1508
.    (bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
1509
.     struct internal_reloc *, struct internal_syment *, asection **);
1510
.
1511
.  reloc_howto_type *(*_bfd_coff_rtype_to_howto)
1512
.    (bfd *, asection *, struct internal_reloc *,
1513
.     struct coff_link_hash_entry *, struct internal_syment *, bfd_vma *);
1514
.
1515
.  bool (*_bfd_coff_adjust_symndx)
1516
.    (bfd *, struct bfd_link_info *, bfd *, asection *,
1517
.     struct internal_reloc *, bool *);
1518
.
1519
.  bool (*_bfd_coff_link_output_has_begun)
1520
.    (bfd *, struct coff_final_link_info *);
1521
.
1522
.  bool (*_bfd_coff_final_link_postscript)
1523
.    (bfd *, struct coff_final_link_info *);
1524
.
1525
.  bool (*_bfd_coff_print_pdata)
1526
.    (bfd *, void *);
1527
.
1528
.} bfd_coff_backend_data;
1529
.
1530
1531
INTERNAL
1532
.#define coff_backend_info(abfd) \
1533
.  ((const bfd_coff_backend_data *) (abfd)->xvec->backend_data)
1534
.
1535
.#define bfd_coff_swap_aux_in(a,e,t,c,ind,num,i) \
1536
.  ((coff_backend_info (a)->_bfd_coff_swap_aux_in) (a,e,t,c,ind,num,i))
1537
.
1538
.#define bfd_coff_swap_sym_in(a,e,i) \
1539
.  ((coff_backend_info (a)->_bfd_coff_swap_sym_in) (a,e,i))
1540
.
1541
.#define bfd_coff_swap_lineno_in(a,e,i) \
1542
.  ((coff_backend_info ( a)->_bfd_coff_swap_lineno_in) (a,e,i))
1543
.
1544
.#define bfd_coff_swap_reloc_out(abfd, i, o) \
1545
.  ((coff_backend_info (abfd)->_bfd_coff_swap_reloc_out) (abfd, i, o))
1546
.
1547
.#define bfd_coff_swap_lineno_out(abfd, i, o) \
1548
.  ((coff_backend_info (abfd)->_bfd_coff_swap_lineno_out) (abfd, i, o))
1549
.
1550
.#define bfd_coff_swap_aux_out(a,i,t,c,ind,num,o) \
1551
.  ((coff_backend_info (a)->_bfd_coff_swap_aux_out) (a,i,t,c,ind,num,o))
1552
.
1553
.#define bfd_coff_swap_sym_out(abfd, i,o) \
1554
.  ((coff_backend_info (abfd)->_bfd_coff_swap_sym_out) (abfd, i, o))
1555
.
1556
.#define bfd_coff_swap_scnhdr_out(abfd, i,o) \
1557
.  ((coff_backend_info (abfd)->_bfd_coff_swap_scnhdr_out) (abfd, i, o))
1558
.
1559
.#define bfd_coff_swap_filehdr_out(abfd, i,o) \
1560
.  ((coff_backend_info (abfd)->_bfd_coff_swap_filehdr_out) (abfd, i, o))
1561
.
1562
.#define bfd_coff_swap_aouthdr_out(abfd, i,o) \
1563
.  ((coff_backend_info (abfd)->_bfd_coff_swap_aouthdr_out) (abfd, i, o))
1564
.
1565
.#define bfd_coff_filhsz(abfd) (coff_backend_info (abfd)->_bfd_filhsz)
1566
.#define bfd_coff_aoutsz(abfd) (coff_backend_info (abfd)->_bfd_aoutsz)
1567
.#define bfd_coff_scnhsz(abfd) (coff_backend_info (abfd)->_bfd_scnhsz)
1568
.#define bfd_coff_symesz(abfd) (coff_backend_info (abfd)->_bfd_symesz)
1569
.#define bfd_coff_auxesz(abfd) (coff_backend_info (abfd)->_bfd_auxesz)
1570
.#define bfd_coff_relsz(abfd)  (coff_backend_info (abfd)->_bfd_relsz)
1571
.#define bfd_coff_linesz(abfd) (coff_backend_info (abfd)->_bfd_linesz)
1572
.#define bfd_coff_filnmlen(abfd) (coff_backend_info (abfd)->_bfd_filnmlen)
1573
.#define bfd_coff_long_filenames(abfd) \
1574
.  (coff_backend_info (abfd)->_bfd_coff_long_filenames)
1575
.#define bfd_coff_long_section_names(abfd) \
1576
.  (coff_data (abfd)->long_section_names)
1577
.#define bfd_coff_set_long_section_names(abfd, enable) \
1578
.  ((coff_backend_info (abfd)->_bfd_coff_set_long_section_names) (abfd, enable))
1579
.#define bfd_coff_default_section_alignment_power(abfd) \
1580
.  (coff_backend_info (abfd)->_bfd_coff_default_section_alignment_power)
1581
.#define bfd_coff_max_nscns(abfd) \
1582
.  (coff_backend_info (abfd)->_bfd_coff_max_nscns)
1583
.
1584
.#define bfd_coff_swap_filehdr_in(abfd, i,o) \
1585
.  ((coff_backend_info (abfd)->_bfd_coff_swap_filehdr_in) (abfd, i, o))
1586
.
1587
.#define bfd_coff_swap_aouthdr_in(abfd, i,o) \
1588
.  ((coff_backend_info (abfd)->_bfd_coff_swap_aouthdr_in) (abfd, i, o))
1589
.
1590
.#define bfd_coff_swap_scnhdr_in(abfd, i,o) \
1591
.  ((coff_backend_info (abfd)->_bfd_coff_swap_scnhdr_in) (abfd, i, o))
1592
.
1593
.#define bfd_coff_swap_reloc_in(abfd, i, o) \
1594
.  ((coff_backend_info (abfd)->_bfd_coff_swap_reloc_in) (abfd, i, o))
1595
.
1596
.#define bfd_coff_bad_format_hook(abfd, filehdr) \
1597
.  ((coff_backend_info (abfd)->_bfd_coff_bad_format_hook) (abfd, filehdr))
1598
.
1599
.#define bfd_coff_set_arch_mach_hook(abfd, filehdr)\
1600
.  ((coff_backend_info (abfd)->_bfd_coff_set_arch_mach_hook) (abfd, filehdr))
1601
.#define bfd_coff_mkobject_hook(abfd, filehdr, aouthdr)\
1602
.  ((coff_backend_info (abfd)->_bfd_coff_mkobject_hook)\
1603
.   (abfd, filehdr, aouthdr))
1604
.
1605
.#define bfd_coff_styp_to_sec_flags_hook(abfd, scnhdr, name, section, flags_ptr)\
1606
.  ((coff_backend_info (abfd)->_bfd_styp_to_sec_flags_hook)\
1607
.   (abfd, scnhdr, name, section, flags_ptr))
1608
.
1609
.#define bfd_coff_set_alignment_hook(abfd, sec, scnhdr)\
1610
.  ((coff_backend_info (abfd)->_bfd_set_alignment_hook) (abfd, sec, scnhdr))
1611
.
1612
.#define bfd_coff_slurp_symbol_table(abfd)\
1613
.  ((coff_backend_info (abfd)->_bfd_coff_slurp_symbol_table) (abfd))
1614
.
1615
.#define bfd_coff_symname_in_debug(abfd, sym)\
1616
.  ((coff_backend_info (abfd)->_bfd_coff_symname_in_debug) (abfd, sym))
1617
.
1618
.#define bfd_coff_force_symnames_in_strings(abfd)\
1619
.  (coff_backend_info (abfd)->_bfd_coff_force_symnames_in_strings)
1620
.
1621
.#define bfd_coff_debug_string_prefix_length(abfd)\
1622
.  (coff_backend_info (abfd)->_bfd_coff_debug_string_prefix_length)
1623
.
1624
.#define bfd_coff_print_aux(abfd, file, base, symbol, aux, indaux)\
1625
.  ((coff_backend_info (abfd)->_bfd_coff_print_aux)\
1626
.   (abfd, file, base, symbol, aux, indaux))
1627
.
1628
.#define bfd_coff_reloc16_extra_cases(abfd, link_info, link_order,\
1629
.             reloc, data, src_ptr, dst_ptr)\
1630
.  ((coff_backend_info (abfd)->_bfd_coff_reloc16_extra_cases)\
1631
.   (abfd, link_info, link_order, reloc, data, src_ptr, dst_ptr))
1632
.
1633
.#define bfd_coff_reloc16_estimate(abfd, section, reloc, shrink, link_info)\
1634
.  ((coff_backend_info (abfd)->_bfd_coff_reloc16_estimate)\
1635
.   (abfd, section, reloc, shrink, link_info))
1636
.
1637
.#define bfd_coff_classify_symbol(abfd, sym)\
1638
.  ((coff_backend_info (abfd)->_bfd_coff_classify_symbol)\
1639
.   (abfd, sym))
1640
.
1641
.#define bfd_coff_compute_section_file_positions(abfd)\
1642
.  ((coff_backend_info (abfd)->_bfd_coff_compute_section_file_positions)\
1643
.   (abfd))
1644
.
1645
.#define bfd_coff_start_final_link(obfd, info)\
1646
.  ((coff_backend_info (obfd)->_bfd_coff_start_final_link)\
1647
.   (obfd, info))
1648
.#define bfd_coff_relocate_section(obfd,info,ibfd,o,con,rel,isyms,secs)\
1649
.  ((coff_backend_info (ibfd)->_bfd_coff_relocate_section)\
1650
.   (obfd, info, ibfd, o, con, rel, isyms, secs))
1651
.#define bfd_coff_rtype_to_howto(abfd, sec, rel, h, sym, addendp)\
1652
.  ((coff_backend_info (abfd)->_bfd_coff_rtype_to_howto)\
1653
.   (abfd, sec, rel, h, sym, addendp))
1654
.#define bfd_coff_adjust_symndx(obfd, info, ibfd, sec, rel, adjustedp)\
1655
.  ((coff_backend_info (abfd)->_bfd_coff_adjust_symndx)\
1656
.   (obfd, info, ibfd, sec, rel, adjustedp))
1657
.
1658
.#define bfd_coff_link_output_has_begun(a,p) \
1659
.  ((coff_backend_info (a)->_bfd_coff_link_output_has_begun) (a, p))
1660
.#define bfd_coff_final_link_postscript(a,p) \
1661
.  ((coff_backend_info (a)->_bfd_coff_final_link_postscript) (a, p))
1662
.
1663
.#define bfd_coff_have_print_pdata(a) \
1664
.  (coff_backend_info (a)->_bfd_coff_print_pdata)
1665
.#define bfd_coff_print_pdata(a,p) \
1666
.  ((coff_backend_info (a)->_bfd_coff_print_pdata) (a, p))
1667
.
1668
.{* Macro: Returns true if the bfd is a PE executable as opposed to a
1669
.   PE object file.  *}
1670
.#define bfd_pei_p(abfd) \
1671
.  (startswith ((abfd)->xvec->name, "pei-"))
1672
*/
1673
1674
/* See whether the magic number matches.  */
1675
1676
static bool
1677
coff_bad_format_hook (bfd * abfd ATTRIBUTE_UNUSED, void * filehdr)
1678
97.2M
{
1679
97.2M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1680
1681
97.2M
  if (BADMAG (*internal_f))
1682
94.3M
    return false;
1683
1684
2.89M
  return true;
1685
97.2M
}
pei-i386.c:coff_bad_format_hook
Line
Count
Source
1678
1.11M
{
1679
1.11M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1680
1681
1.11M
  if (BADMAG (*internal_f))
1682
951k
    return false;
1683
1684
161k
  return true;
1685
1.11M
}
pe-x86_64.c:coff_bad_format_hook
Line
Count
Source
1678
6.48M
{
1679
6.48M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1680
1681
6.48M
  if (BADMAG (*internal_f))
1682
6.19M
    return false;
1683
1684
290k
  return true;
1685
6.48M
}
pei-x86_64.c:coff_bad_format_hook
Line
Count
Source
1678
1.11M
{
1679
1.11M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1680
1681
1.11M
  if (BADMAG (*internal_f))
1682
942k
    return false;
1683
1684
172k
  return true;
1685
1.11M
}
coff-x86_64.c:coff_bad_format_hook
Line
Count
Source
1678
3.37M
{
1679
3.37M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1680
1681
3.37M
  if (BADMAG (*internal_f))
1682
3.14M
    return false;
1683
1684
221k
  return true;
1685
3.37M
}
Unexecuted instantiation: coff64-rs6000.c:coff_bad_format_hook
pe-aarch64.c:coff_bad_format_hook
Line
Count
Source
1678
3.36M
{
1679
3.36M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1680
1681
3.36M
  if (BADMAG (*internal_f))
1682
3.30M
    return false;
1683
1684
69.3k
  return true;
1685
3.36M
}
pei-aarch64.c:coff_bad_format_hook
Line
Count
Source
1678
1.07M
{
1679
1.07M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1680
1681
1.07M
  if (BADMAG (*internal_f))
1682
955k
    return false;
1683
1684
115k
  return true;
1685
1.07M
}
pei-ia64.c:coff_bad_format_hook
Line
Count
Source
1678
1.04M
{
1679
1.04M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1680
1681
1.04M
  if (BADMAG (*internal_f))
1682
917k
    return false;
1683
1684
127k
  return true;
1685
1.04M
}
pei-loongarch64.c:coff_bad_format_hook
Line
Count
Source
1678
1.07M
{
1679
1.07M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1680
1681
1.07M
  if (BADMAG (*internal_f))
1682
965k
    return false;
1683
1684
105k
  return true;
1685
1.07M
}
pei-riscv64.c:coff_bad_format_hook
Line
Count
Source
1678
1.07M
{
1679
1.07M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1680
1681
1.07M
  if (BADMAG (*internal_f))
1682
976k
    return false;
1683
1684
94.5k
  return true;
1685
1.07M
}
cf-i386lynx.c:coff_bad_format_hook
Line
Count
Source
1678
3.36M
{
1679
3.36M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1680
1681
3.36M
  if (BADMAG (*internal_f))
1682
3.27M
    return false;
1683
1684
92.6k
  return true;
1685
3.36M
}
coff-go32.c:coff_bad_format_hook
Line
Count
Source
1678
3.36M
{
1679
3.36M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1680
1681
3.36M
  if (BADMAG (*internal_f))
1682
3.27M
    return false;
1683
1684
89.5k
  return true;
1685
3.36M
}
coff-i386.c:coff_bad_format_hook
Line
Count
Source
1678
3.36M
{
1679
3.36M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1680
1681
3.36M
  if (BADMAG (*internal_f))
1682
3.27M
    return false;
1683
1684
89.5k
  return true;
1685
3.36M
}
coff-rs6000.c:coff_bad_format_hook
Line
Count
Source
1678
3.35M
{
1679
3.35M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1680
1681
3.35M
  if (BADMAG (*internal_f))
1682
3.25M
    return false;
1683
1684
97.8k
  return true;
1685
3.35M
}
coff-sh.c:coff_bad_format_hook
Line
Count
Source
1678
13.2M
{
1679
13.2M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1680
1681
13.2M
  if (BADMAG (*internal_f))
1682
13.0M
    return false;
1683
1684
124k
  return true;
1685
13.2M
}
coff-stgo32.c:coff_bad_format_hook
Line
Count
Source
1678
3.56k
{
1679
3.56k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1680
1681
3.56k
  if (BADMAG (*internal_f))
1682
151
    return false;
1683
1684
3.41k
  return true;
1685
3.56k
}
coff-tic30.c:coff_bad_format_hook
Line
Count
Source
1678
3.35M
{
1679
3.35M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1680
1681
3.35M
  if (BADMAG (*internal_f))
1682
3.29M
    return false;
1683
1684
60.0k
  return true;
1685
3.35M
}
Unexecuted instantiation: coff-tic4x.c:coff_bad_format_hook
coff-tic54x.c:coff_bad_format_hook
Line
Count
Source
1678
6.66M
{
1679
6.66M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1680
1681
6.66M
  if (BADMAG (*internal_f))
1682
6.66M
    return false;
1683
1684
1.01k
  return true;
1685
6.66M
}
coff-z80.c:coff_bad_format_hook
Line
Count
Source
1678
3.35M
{
1679
3.35M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1680
1681
3.35M
  if (BADMAG (*internal_f))
1682
3.30M
    return false;
1683
1684
46.8k
  return true;
1685
3.35M
}
coff-z8k.c:coff_bad_format_hook
Line
Count
Source
1678
3.35M
{
1679
3.35M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1680
1681
3.35M
  if (BADMAG (*internal_f))
1682
3.30M
    return false;
1683
1684
51.4k
  return true;
1685
3.35M
}
pe-arm-wince.c:coff_bad_format_hook
Line
Count
Source
1678
6.70M
{
1679
6.70M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1680
1681
6.70M
  if (BADMAG (*internal_f))
1682
6.66M
    return false;
1683
1684
37.2k
  return true;
1685
6.70M
}
pe-arm.c:coff_bad_format_hook
Line
Count
Source
1678
6.70M
{
1679
6.70M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1680
1681
6.70M
  if (BADMAG (*internal_f))
1682
6.66M
    return false;
1683
1684
37.2k
  return true;
1685
6.70M
}
pe-i386.c:coff_bad_format_hook
Line
Count
Source
1678
6.41M
{
1679
6.41M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1680
1681
6.41M
  if (BADMAG (*internal_f))
1682
6.30M
    return false;
1683
1684
114k
  return true;
1685
6.41M
}
pe-mcore.c:coff_bad_format_hook
Line
Count
Source
1678
6.70M
{
1679
6.70M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1680
1681
6.70M
  if (BADMAG (*internal_f))
1682
6.63M
    return false;
1683
1684
68.8k
  return true;
1685
6.70M
}
pe-sh.c:coff_bad_format_hook
Line
Count
Source
1678
3.35M
{
1679
3.35M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1680
1681
3.35M
  if (BADMAG (*internal_f))
1682
3.29M
    return false;
1683
1684
62.8k
  return true;
1685
3.35M
}
pei-arm-wince.c:coff_bad_format_hook
Line
Count
Source
1678
1.06M
{
1679
1.06M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1680
1681
1.06M
  if (BADMAG (*internal_f))
1682
891k
    return false;
1683
1684
178k
  return true;
1685
1.06M
}
pei-arm.c:coff_bad_format_hook
Line
Count
Source
1678
1.06M
{
1679
1.06M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1680
1681
1.06M
  if (BADMAG (*internal_f))
1682
891k
    return false;
1683
1684
178k
  return true;
1685
1.06M
}
pei-mcore.c:coff_bad_format_hook
Line
Count
Source
1678
1.06M
{
1679
1.06M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1680
1681
1.06M
  if (BADMAG (*internal_f))
1682
971k
    return false;
1683
1684
97.5k
  return true;
1685
1.06M
}
pei-sh.c:coff_bad_format_hook
Line
Count
Source
1678
1.06M
{
1679
1.06M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1680
1681
1.06M
  if (BADMAG (*internal_f))
1682
967k
    return false;
1683
1684
101k
  return true;
1685
1.06M
}
1686
1687
#ifdef TICOFF
1688
static bool
1689
ticoff0_bad_format_hook (bfd *abfd ATTRIBUTE_UNUSED, void * filehdr)
1690
6.70M
{
1691
6.70M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1692
1693
6.70M
  if (COFF0_BADMAG (*internal_f))
1694
6.59M
    return false;
1695
1696
114k
  return true;
1697
6.70M
}
Unexecuted instantiation: coff-tic4x.c:ticoff0_bad_format_hook
coff-tic54x.c:ticoff0_bad_format_hook
Line
Count
Source
1690
6.70M
{
1691
6.70M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1692
1693
6.70M
  if (COFF0_BADMAG (*internal_f))
1694
6.59M
    return false;
1695
1696
114k
  return true;
1697
6.70M
}
1698
#endif
1699
1700
#ifdef TICOFF
1701
static bool
1702
ticoff1_bad_format_hook (bfd *abfd ATTRIBUTE_UNUSED, void * filehdr)
1703
6.66M
{
1704
6.66M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1705
1706
6.66M
  if (COFF1_BADMAG (*internal_f))
1707
6.65M
    return false;
1708
1709
5.08k
  return true;
1710
6.66M
}
Unexecuted instantiation: coff-tic4x.c:ticoff1_bad_format_hook
coff-tic54x.c:ticoff1_bad_format_hook
Line
Count
Source
1703
6.66M
{
1704
6.66M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1705
1706
6.66M
  if (COFF1_BADMAG (*internal_f))
1707
6.65M
    return false;
1708
1709
5.08k
  return true;
1710
6.66M
}
1711
#endif
1712
1713
/* Check whether this section uses an alignment other than the
1714
   default.  */
1715
1716
static void
1717
coff_set_custom_section_alignment (bfd *abfd ATTRIBUTE_UNUSED,
1718
           asection *section,
1719
           const struct coff_section_alignment_entry *alignment_table,
1720
           const unsigned int table_size)
1721
134M
{
1722
134M
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1723
134M
  unsigned int i;
1724
1725
767M
  for (i = 0; i < table_size; ++i)
1726
634M
    {
1727
634M
      const char *secname = bfd_section_name (section);
1728
1729
634M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1730
634M
    ? strcmp (alignment_table[i].name, secname) == 0
1731
634M
    : strncmp (alignment_table[i].name, secname,
1732
350M
         alignment_table[i].comparison_length) == 0)
1733
895k
  break;
1734
634M
    }
1735
134M
  if (i >= table_size)
1736
133M
    return;
1737
1738
895k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1739
895k
      && default_alignment < alignment_table[i].default_alignment_min)
1740
337k
    return;
1741
1742
558k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1743
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1744
0
      && default_alignment > alignment_table[i].default_alignment_max
1745
#endif
1746
558k
      )
1747
0
    return;
1748
1749
558k
  section->alignment_power = alignment_table[i].alignment_power;
1750
558k
}
pei-i386.c:coff_set_custom_section_alignment
Line
Count
Source
1721
497k
{
1722
497k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1723
497k
  unsigned int i;
1724
1725
4.61M
  for (i = 0; i < table_size; ++i)
1726
4.16M
    {
1727
4.16M
      const char *secname = bfd_section_name (section);
1728
1729
4.16M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1730
4.16M
    ? strcmp (alignment_table[i].name, secname) == 0
1731
4.16M
    : strncmp (alignment_table[i].name, secname,
1732
2.80M
         alignment_table[i].comparison_length) == 0)
1733
49.7k
  break;
1734
4.16M
    }
1735
497k
  if (i >= table_size)
1736
447k
    return;
1737
1738
49.7k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1739
49.7k
      && default_alignment < alignment_table[i].default_alignment_min)
1740
8.69k
    return;
1741
1742
41.0k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1743
41.0k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1744
41.0k
      && default_alignment > alignment_table[i].default_alignment_max
1745
41.0k
#endif
1746
41.0k
      )
1747
0
    return;
1748
1749
41.0k
  section->alignment_power = alignment_table[i].alignment_power;
1750
41.0k
}
pe-x86_64.c:coff_set_custom_section_alignment
Line
Count
Source
1721
1.21M
{
1722
1.21M
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1723
1.21M
  unsigned int i;
1724
1725
17.8M
  for (i = 0; i < table_size; ++i)
1726
16.6M
    {
1727
16.6M
      const char *secname = bfd_section_name (section);
1728
1729
16.6M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1730
16.6M
    ? strcmp (alignment_table[i].name, secname) == 0
1731
16.6M
    : strncmp (alignment_table[i].name, secname,
1732
11.9M
         alignment_table[i].comparison_length) == 0)
1733
57.4k
  break;
1734
16.6M
    }
1735
1.21M
  if (i >= table_size)
1736
1.15M
    return;
1737
1738
57.4k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1739
57.4k
      && default_alignment < alignment_table[i].default_alignment_min)
1740
13.1k
    return;
1741
1742
44.3k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1743
44.3k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1744
44.3k
      && default_alignment > alignment_table[i].default_alignment_max
1745
44.3k
#endif
1746
44.3k
      )
1747
0
    return;
1748
1749
44.3k
  section->alignment_power = alignment_table[i].alignment_power;
1750
44.3k
}
pei-x86_64.c:coff_set_custom_section_alignment
Line
Count
Source
1721
476k
{
1722
476k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1723
476k
  unsigned int i;
1724
1725
6.21M
  for (i = 0; i < table_size; ++i)
1726
5.81M
    {
1727
5.81M
      const char *secname = bfd_section_name (section);
1728
1729
5.81M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1730
5.81M
    ? strcmp (alignment_table[i].name, secname) == 0
1731
5.81M
    : strncmp (alignment_table[i].name, secname,
1732
4.08M
         alignment_table[i].comparison_length) == 0)
1733
74.3k
  break;
1734
5.81M
    }
1735
476k
  if (i >= table_size)
1736
402k
    return;
1737
1738
74.3k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1739
74.3k
      && default_alignment < alignment_table[i].default_alignment_min)
1740
21.8k
    return;
1741
1742
52.4k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1743
52.4k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1744
52.4k
      && default_alignment > alignment_table[i].default_alignment_max
1745
52.4k
#endif
1746
52.4k
      )
1747
0
    return;
1748
1749
52.4k
  section->alignment_power = alignment_table[i].alignment_power;
1750
52.4k
}
coff-x86_64.c:coff_set_custom_section_alignment
Line
Count
Source
1721
19.0M
{
1722
19.0M
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1723
19.0M
  unsigned int i;
1724
1725
95.0M
  for (i = 0; i < table_size; ++i)
1726
76.0M
    {
1727
76.0M
      const char *secname = bfd_section_name (section);
1728
1729
76.0M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1730
76.0M
    ? strcmp (alignment_table[i].name, secname) == 0
1731
76.0M
    : strncmp (alignment_table[i].name, secname,
1732
38.0M
         alignment_table[i].comparison_length) == 0)
1733
54.9k
  break;
1734
76.0M
    }
1735
19.0M
  if (i >= table_size)
1736
18.9M
    return;
1737
1738
54.9k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1739
54.9k
      && default_alignment < alignment_table[i].default_alignment_min)
1740
36.0k
    return;
1741
1742
18.9k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1743
18.9k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1744
18.9k
      && default_alignment > alignment_table[i].default_alignment_max
1745
18.9k
#endif
1746
18.9k
      )
1747
0
    return;
1748
1749
18.9k
  section->alignment_power = alignment_table[i].alignment_power;
1750
18.9k
}
coff64-rs6000.c:coff_set_custom_section_alignment
Line
Count
Source
1721
3.50M
{
1722
3.50M
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1723
3.50M
  unsigned int i;
1724
1725
17.4M
  for (i = 0; i < table_size; ++i)
1726
13.9M
    {
1727
13.9M
      const char *secname = bfd_section_name (section);
1728
1729
13.9M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1730
13.9M
    ? strcmp (alignment_table[i].name, secname) == 0
1731
13.9M
    : strncmp (alignment_table[i].name, secname,
1732
7.00M
         alignment_table[i].comparison_length) == 0)
1733
21.9k
  break;
1734
13.9M
    }
1735
3.50M
  if (i >= table_size)
1736
3.48M
    return;
1737
1738
21.9k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1739
21.9k
      && default_alignment < alignment_table[i].default_alignment_min)
1740
0
    return;
1741
1742
21.9k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1743
21.9k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1744
21.9k
      && default_alignment > alignment_table[i].default_alignment_max
1745
21.9k
#endif
1746
21.9k
      )
1747
0
    return;
1748
1749
21.9k
  section->alignment_power = alignment_table[i].alignment_power;
1750
21.9k
}
pe-aarch64.c:coff_set_custom_section_alignment
Line
Count
Source
1721
279k
{
1722
279k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1723
279k
  unsigned int i;
1724
1725
3.87M
  for (i = 0; i < table_size; ++i)
1726
3.60M
    {
1727
3.60M
      const char *secname = bfd_section_name (section);
1728
1729
3.60M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1730
3.60M
    ? strcmp (alignment_table[i].name, secname) == 0
1731
3.60M
    : strncmp (alignment_table[i].name, secname,
1732
1.66M
         alignment_table[i].comparison_length) == 0)
1733
7.16k
  break;
1734
3.60M
    }
1735
279k
  if (i >= table_size)
1736
272k
    return;
1737
1738
7.16k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1739
7.16k
      && default_alignment < alignment_table[i].default_alignment_min)
1740
2.54k
    return;
1741
1742
4.62k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1743
4.62k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1744
4.62k
      && default_alignment > alignment_table[i].default_alignment_max
1745
4.62k
#endif
1746
4.62k
      )
1747
0
    return;
1748
1749
4.62k
  section->alignment_power = alignment_table[i].alignment_power;
1750
4.62k
}
pei-aarch64.c:coff_set_custom_section_alignment
Line
Count
Source
1721
409k
{
1722
409k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1723
409k
  unsigned int i;
1724
1725
5.45M
  for (i = 0; i < table_size; ++i)
1726
5.07M
    {
1727
5.07M
      const char *secname = bfd_section_name (section);
1728
1729
5.07M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1730
5.07M
    ? strcmp (alignment_table[i].name, secname) == 0
1731
5.07M
    : strncmp (alignment_table[i].name, secname,
1732
2.31M
         alignment_table[i].comparison_length) == 0)
1733
34.8k
  break;
1734
5.07M
    }
1735
409k
  if (i >= table_size)
1736
374k
    return;
1737
1738
34.8k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1739
34.8k
      && default_alignment < alignment_table[i].default_alignment_min)
1740
3.68k
    return;
1741
1742
31.2k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1743
31.2k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1744
31.2k
      && default_alignment > alignment_table[i].default_alignment_max
1745
31.2k
#endif
1746
31.2k
      )
1747
0
    return;
1748
1749
31.2k
  section->alignment_power = alignment_table[i].alignment_power;
1750
31.2k
}
pei-ia64.c:coff_set_custom_section_alignment
Line
Count
Source
1721
330k
{
1722
330k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1723
330k
  unsigned int i;
1724
1725
1.62M
  for (i = 0; i < table_size; ++i)
1726
1.30M
    {
1727
1.30M
      const char *secname = bfd_section_name (section);
1728
1729
1.30M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1730
1.30M
    ? strcmp (alignment_table[i].name, secname) == 0
1731
1.30M
    : strncmp (alignment_table[i].name, secname,
1732
658k
         alignment_table[i].comparison_length) == 0)
1733
11.0k
  break;
1734
1.30M
    }
1735
330k
  if (i >= table_size)
1736
319k
    return;
1737
1738
11.0k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1739
11.0k
      && default_alignment < alignment_table[i].default_alignment_min)
1740
8.23k
    return;
1741
1742
2.82k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1743
2.82k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1744
2.82k
      && default_alignment > alignment_table[i].default_alignment_max
1745
2.82k
#endif
1746
2.82k
      )
1747
0
    return;
1748
1749
2.82k
  section->alignment_power = alignment_table[i].alignment_power;
1750
2.82k
}
pei-loongarch64.c:coff_set_custom_section_alignment
Line
Count
Source
1721
333k
{
1722
333k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1723
333k
  unsigned int i;
1724
1725
4.47M
  for (i = 0; i < table_size; ++i)
1726
4.17M
    {
1727
4.17M
      const char *secname = bfd_section_name (section);
1728
1729
4.17M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1730
4.17M
    ? strcmp (alignment_table[i].name, secname) == 0
1731
4.17M
    : strncmp (alignment_table[i].name, secname,
1732
1.90M
         alignment_table[i].comparison_length) == 0)
1733
27.0k
  break;
1734
4.17M
    }
1735
333k
  if (i >= table_size)
1736
306k
    return;
1737
1738
27.0k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1739
27.0k
      && default_alignment < alignment_table[i].default_alignment_min)
1740
4.46k
    return;
1741
1742
22.6k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1743
22.6k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1744
22.6k
      && default_alignment > alignment_table[i].default_alignment_max
1745
22.6k
#endif
1746
22.6k
      )
1747
0
    return;
1748
1749
22.6k
  section->alignment_power = alignment_table[i].alignment_power;
1750
22.6k
}
pei-riscv64.c:coff_set_custom_section_alignment
Line
Count
Source
1721
309k
{
1722
309k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1723
309k
  unsigned int i;
1724
1725
4.08M
  for (i = 0; i < table_size; ++i)
1726
3.81M
    {
1727
3.81M
      const char *secname = bfd_section_name (section);
1728
1729
3.81M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1730
3.81M
    ? strcmp (alignment_table[i].name, secname) == 0
1731
3.81M
    : strncmp (alignment_table[i].name, secname,
1732
1.72M
         alignment_table[i].comparison_length) == 0)
1733
30.4k
  break;
1734
3.81M
    }
1735
309k
  if (i >= table_size)
1736
278k
    return;
1737
1738
30.4k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1739
30.4k
      && default_alignment < alignment_table[i].default_alignment_min)
1740
3.53k
    return;
1741
1742
26.9k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1743
26.9k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1744
26.9k
      && default_alignment > alignment_table[i].default_alignment_max
1745
26.9k
#endif
1746
26.9k
      )
1747
0
    return;
1748
1749
26.9k
  section->alignment_power = alignment_table[i].alignment_power;
1750
26.9k
}
cf-i386lynx.c:coff_set_custom_section_alignment
Line
Count
Source
1721
7.80M
{
1722
7.80M
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1723
7.80M
  unsigned int i;
1724
1725
38.9M
  for (i = 0; i < table_size; ++i)
1726
31.1M
    {
1727
31.1M
      const char *secname = bfd_section_name (section);
1728
1729
31.1M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1730
31.1M
    ? strcmp (alignment_table[i].name, secname) == 0
1731
31.1M
    : strncmp (alignment_table[i].name, secname,
1732
15.6M
         alignment_table[i].comparison_length) == 0)
1733
28.3k
  break;
1734
31.1M
    }
1735
7.80M
  if (i >= table_size)
1736
7.77M
    return;
1737
1738
28.3k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1739
28.3k
      && default_alignment < alignment_table[i].default_alignment_min)
1740
17.8k
    return;
1741
1742
10.4k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1743
10.4k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1744
10.4k
      && default_alignment > alignment_table[i].default_alignment_max
1745
10.4k
#endif
1746
10.4k
      )
1747
0
    return;
1748
1749
10.4k
  section->alignment_power = alignment_table[i].alignment_power;
1750
10.4k
}
coff-go32.c:coff_set_custom_section_alignment
Line
Count
Source
1721
5.17M
{
1722
5.17M
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1723
5.17M
  unsigned int i;
1724
1725
82.3M
  for (i = 0; i < table_size; ++i)
1726
77.2M
    {
1727
77.2M
      const char *secname = bfd_section_name (section);
1728
1729
77.2M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1730
77.2M
    ? strcmp (alignment_table[i].name, secname) == 0
1731
77.2M
    : strncmp (alignment_table[i].name, secname,
1732
67.0M
         alignment_table[i].comparison_length) == 0)
1733
48.5k
  break;
1734
77.2M
    }
1735
5.17M
  if (i >= table_size)
1736
5.12M
    return;
1737
1738
48.5k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1739
48.5k
      && default_alignment < alignment_table[i].default_alignment_min)
1740
12.0k
    return;
1741
1742
36.5k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1743
36.5k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1744
36.5k
      && default_alignment > alignment_table[i].default_alignment_max
1745
36.5k
#endif
1746
36.5k
      )
1747
0
    return;
1748
1749
36.5k
  section->alignment_power = alignment_table[i].alignment_power;
1750
36.5k
}
coff-i386.c:coff_set_custom_section_alignment
Line
Count
Source
1721
6.65M
{
1722
6.65M
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1723
6.65M
  unsigned int i;
1724
1725
33.1M
  for (i = 0; i < table_size; ++i)
1726
26.5M
    {
1727
26.5M
      const char *secname = bfd_section_name (section);
1728
1729
26.5M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1730
26.5M
    ? strcmp (alignment_table[i].name, secname) == 0
1731
26.5M
    : strncmp (alignment_table[i].name, secname,
1732
13.2M
         alignment_table[i].comparison_length) == 0)
1733
21.1k
  break;
1734
26.5M
    }
1735
6.65M
  if (i >= table_size)
1736
6.62M
    return;
1737
1738
21.1k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1739
21.1k
      && default_alignment < alignment_table[i].default_alignment_min)
1740
14.3k
    return;
1741
1742
6.80k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1743
6.80k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1744
6.80k
      && default_alignment > alignment_table[i].default_alignment_max
1745
6.80k
#endif
1746
6.80k
      )
1747
0
    return;
1748
1749
6.80k
  section->alignment_power = alignment_table[i].alignment_power;
1750
6.80k
}
coff-rs6000.c:coff_set_custom_section_alignment
Line
Count
Source
1721
28.2M
{
1722
28.2M
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1723
28.2M
  unsigned int i;
1724
1725
141M
  for (i = 0; i < table_size; ++i)
1726
113M
    {
1727
113M
      const char *secname = bfd_section_name (section);
1728
1729
113M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1730
113M
    ? strcmp (alignment_table[i].name, secname) == 0
1731
113M
    : strncmp (alignment_table[i].name, secname,
1732
56.5M
         alignment_table[i].comparison_length) == 0)
1733
48.8k
  break;
1734
113M
    }
1735
28.2M
  if (i >= table_size)
1736
28.2M
    return;
1737
1738
48.8k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1739
48.8k
      && default_alignment < alignment_table[i].default_alignment_min)
1740
0
    return;
1741
1742
48.8k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1743
48.8k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1744
48.8k
      && default_alignment > alignment_table[i].default_alignment_max
1745
48.8k
#endif
1746
48.8k
      )
1747
0
    return;
1748
1749
48.8k
  section->alignment_power = alignment_table[i].alignment_power;
1750
48.8k
}
coff-sh.c:coff_set_custom_section_alignment
Line
Count
Source
1721
10.5M
{
1722
10.5M
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1723
10.5M
  unsigned int i;
1724
1725
52.7M
  for (i = 0; i < table_size; ++i)
1726
42.2M
    {
1727
42.2M
      const char *secname = bfd_section_name (section);
1728
1729
42.2M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1730
42.2M
    ? strcmp (alignment_table[i].name, secname) == 0
1731
42.2M
    : strncmp (alignment_table[i].name, secname,
1732
21.1M
         alignment_table[i].comparison_length) == 0)
1733
34.7k
  break;
1734
42.2M
    }
1735
10.5M
  if (i >= table_size)
1736
10.5M
    return;
1737
1738
34.7k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1739
34.7k
      && default_alignment < alignment_table[i].default_alignment_min)
1740
0
    return;
1741
1742
34.7k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1743
34.7k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1744
34.7k
      && default_alignment > alignment_table[i].default_alignment_max
1745
34.7k
#endif
1746
34.7k
      )
1747
0
    return;
1748
1749
34.7k
  section->alignment_power = alignment_table[i].alignment_power;
1750
34.7k
}
coff-stgo32.c:coff_set_custom_section_alignment
Line
Count
Source
1721
1.18M
{
1722
1.18M
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1723
1.18M
  unsigned int i;
1724
1725
10.6M
  for (i = 0; i < table_size; ++i)
1726
9.46M
    {
1727
9.46M
      const char *secname = bfd_section_name (section);
1728
1729
9.46M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1730
9.46M
    ? strcmp (alignment_table[i].name, secname) == 0
1731
9.46M
    : strncmp (alignment_table[i].name, secname,
1732
4.73M
         alignment_table[i].comparison_length) == 0)
1733
11.1k
  break;
1734
9.46M
    }
1735
1.18M
  if (i >= table_size)
1736
1.17M
    return;
1737
1738
11.1k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1739
11.1k
      && default_alignment < alignment_table[i].default_alignment_min)
1740
3.68k
    return;
1741
1742
7.50k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1743
7.50k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1744
7.50k
      && default_alignment > alignment_table[i].default_alignment_max
1745
7.50k
#endif
1746
7.50k
      )
1747
0
    return;
1748
1749
7.50k
  section->alignment_power = alignment_table[i].alignment_power;
1750
7.50k
}
coff-tic30.c:coff_set_custom_section_alignment
Line
Count
Source
1721
12.7M
{
1722
12.7M
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1723
12.7M
  unsigned int i;
1724
1725
63.7M
  for (i = 0; i < table_size; ++i)
1726
50.9M
    {
1727
50.9M
      const char *secname = bfd_section_name (section);
1728
1729
50.9M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1730
50.9M
    ? strcmp (alignment_table[i].name, secname) == 0
1731
50.9M
    : strncmp (alignment_table[i].name, secname,
1732
25.5M
         alignment_table[i].comparison_length) == 0)
1733
34.2k
  break;
1734
50.9M
    }
1735
12.7M
  if (i >= table_size)
1736
12.7M
    return;
1737
1738
34.2k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1739
34.2k
      && default_alignment < alignment_table[i].default_alignment_min)
1740
21.5k
    return;
1741
1742
12.7k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1743
12.7k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1744
12.7k
      && default_alignment > alignment_table[i].default_alignment_max
1745
12.7k
#endif
1746
12.7k
      )
1747
0
    return;
1748
1749
12.7k
  section->alignment_power = alignment_table[i].alignment_power;
1750
12.7k
}
Unexecuted instantiation: coff-tic4x.c:coff_set_custom_section_alignment
coff-tic54x.c:coff_set_custom_section_alignment
Line
Count
Source
1721
13.0M
{
1722
13.0M
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1723
13.0M
  unsigned int i;
1724
1725
65.0M
  for (i = 0; i < table_size; ++i)
1726
52.0M
    {
1727
52.0M
      const char *secname = bfd_section_name (section);
1728
1729
52.0M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1730
52.0M
    ? strcmp (alignment_table[i].name, secname) == 0
1731
52.0M
    : strncmp (alignment_table[i].name, secname,
1732
26.0M
         alignment_table[i].comparison_length) == 0)
1733
44.6k
  break;
1734
52.0M
    }
1735
13.0M
  if (i >= table_size)
1736
12.9M
    return;
1737
1738
44.6k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1739
44.6k
      && default_alignment < alignment_table[i].default_alignment_min)
1740
44.6k
    return;
1741
1742
0
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1743
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1744
      && default_alignment > alignment_table[i].default_alignment_max
1745
#endif
1746
0
      )
1747
0
    return;
1748
1749
0
  section->alignment_power = alignment_table[i].alignment_power;
1750
0
}
coff-z80.c:coff_set_custom_section_alignment
Line
Count
Source
1721
1.94M
{
1722
1.94M
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1723
1.94M
  unsigned int i;
1724
1725
9.64M
  for (i = 0; i < table_size; ++i)
1726
7.72M
    {
1727
7.72M
      const char *secname = bfd_section_name (section);
1728
1729
7.72M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1730
7.72M
    ? strcmp (alignment_table[i].name, secname) == 0
1731
7.72M
    : strncmp (alignment_table[i].name, secname,
1732
3.87M
         alignment_table[i].comparison_length) == 0)
1733
19.8k
  break;
1734
7.72M
    }
1735
1.94M
  if (i >= table_size)
1736
1.92M
    return;
1737
1738
19.8k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1739
19.8k
      && default_alignment < alignment_table[i].default_alignment_min)
1740
19.8k
    return;
1741
1742
0
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1743
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1744
      && default_alignment > alignment_table[i].default_alignment_max
1745
#endif
1746
0
      )
1747
0
    return;
1748
1749
0
  section->alignment_power = alignment_table[i].alignment_power;
1750
0
}
coff-z8k.c:coff_set_custom_section_alignment
Line
Count
Source
1721
18.1M
{
1722
18.1M
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1723
18.1M
  unsigned int i;
1724
1725
90.5M
  for (i = 0; i < table_size; ++i)
1726
72.4M
    {
1727
72.4M
      const char *secname = bfd_section_name (section);
1728
1729
72.4M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1730
72.4M
    ? strcmp (alignment_table[i].name, secname) == 0
1731
72.4M
    : strncmp (alignment_table[i].name, secname,
1732
36.2M
         alignment_table[i].comparison_length) == 0)
1733
67.6k
  break;
1734
72.4M
    }
1735
18.1M
  if (i >= table_size)
1736
18.0M
    return;
1737
1738
67.6k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1739
67.6k
      && default_alignment < alignment_table[i].default_alignment_min)
1740
44.8k
    return;
1741
1742
22.7k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1743
22.7k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1744
22.7k
      && default_alignment > alignment_table[i].default_alignment_max
1745
22.7k
#endif
1746
22.7k
      )
1747
0
    return;
1748
1749
22.7k
  section->alignment_power = alignment_table[i].alignment_power;
1750
22.7k
}
pe-arm-wince.c:coff_set_custom_section_alignment
Line
Count
Source
1721
90.7k
{
1722
90.7k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1723
90.7k
  unsigned int i;
1724
1725
1.29M
  for (i = 0; i < table_size; ++i)
1726
1.21M
    {
1727
1.21M
      const char *secname = bfd_section_name (section);
1728
1729
1.21M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1730
1.21M
    ? strcmp (alignment_table[i].name, secname) == 0
1731
1.21M
    : strncmp (alignment_table[i].name, secname,
1732
605k
         alignment_table[i].comparison_length) == 0)
1733
12.8k
  break;
1734
1.21M
    }
1735
90.7k
  if (i >= table_size)
1736
77.8k
    return;
1737
1738
12.8k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1739
12.8k
      && default_alignment < alignment_table[i].default_alignment_min)
1740
4.50k
    return;
1741
1742
8.38k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1743
8.38k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1744
8.38k
      && default_alignment > alignment_table[i].default_alignment_max
1745
8.38k
#endif
1746
8.38k
      )
1747
0
    return;
1748
1749
8.38k
  section->alignment_power = alignment_table[i].alignment_power;
1750
8.38k
}
pe-arm.c:coff_set_custom_section_alignment
Line
Count
Source
1721
90.7k
{
1722
90.7k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1723
90.7k
  unsigned int i;
1724
1725
1.29M
  for (i = 0; i < table_size; ++i)
1726
1.21M
    {
1727
1.21M
      const char *secname = bfd_section_name (section);
1728
1729
1.21M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1730
1.21M
    ? strcmp (alignment_table[i].name, secname) == 0
1731
1.21M
    : strncmp (alignment_table[i].name, secname,
1732
605k
         alignment_table[i].comparison_length) == 0)
1733
12.8k
  break;
1734
1.21M
    }
1735
90.7k
  if (i >= table_size)
1736
77.8k
    return;
1737
1738
12.8k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1739
12.8k
      && default_alignment < alignment_table[i].default_alignment_min)
1740
4.50k
    return;
1741
1742
8.38k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1743
8.38k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1744
8.38k
      && default_alignment > alignment_table[i].default_alignment_max
1745
8.38k
#endif
1746
8.38k
      )
1747
0
    return;
1748
1749
8.38k
  section->alignment_power = alignment_table[i].alignment_power;
1750
8.38k
}
pe-i386.c:coff_set_custom_section_alignment
Line
Count
Source
1721
195k
{
1722
195k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1723
195k
  unsigned int i;
1724
1725
2.06M
  for (i = 0; i < table_size; ++i)
1726
1.88M
    {
1727
1.88M
      const char *secname = bfd_section_name (section);
1728
1729
1.88M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1730
1.88M
    ? strcmp (alignment_table[i].name, secname) == 0
1731
1.88M
    : strncmp (alignment_table[i].name, secname,
1732
1.33M
         alignment_table[i].comparison_length) == 0)
1733
20.1k
  break;
1734
1.88M
    }
1735
195k
  if (i >= table_size)
1736
175k
    return;
1737
1738
20.1k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1739
20.1k
      && default_alignment < alignment_table[i].default_alignment_min)
1740
8.57k
    return;
1741
1742
11.6k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1743
11.6k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1744
11.6k
      && default_alignment > alignment_table[i].default_alignment_max
1745
11.6k
#endif
1746
11.6k
      )
1747
0
    return;
1748
1749
11.6k
  section->alignment_power = alignment_table[i].alignment_power;
1750
11.6k
}
pe-mcore.c:coff_set_custom_section_alignment
Line
Count
Source
1721
220k
{
1722
220k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1723
220k
  unsigned int i;
1724
1725
1.07M
  for (i = 0; i < table_size; ++i)
1726
862k
    {
1727
862k
      const char *secname = bfd_section_name (section);
1728
1729
862k
      if (alignment_table[i].comparison_length == (unsigned int) -1
1730
862k
    ? strcmp (alignment_table[i].name, secname) == 0
1731
862k
    : strncmp (alignment_table[i].name, secname,
1732
438k
         alignment_table[i].comparison_length) == 0)
1733
9.94k
  break;
1734
862k
    }
1735
220k
  if (i >= table_size)
1736
210k
    return;
1737
1738
9.94k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1739
9.94k
      && default_alignment < alignment_table[i].default_alignment_min)
1740
7.42k
    return;
1741
1742
2.51k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1743
2.51k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1744
2.51k
      && default_alignment > alignment_table[i].default_alignment_max
1745
2.51k
#endif
1746
2.51k
      )
1747
0
    return;
1748
1749
2.51k
  section->alignment_power = alignment_table[i].alignment_power;
1750
2.51k
}
pe-sh.c:coff_set_custom_section_alignment
Line
Count
Source
1721
168k
{
1722
168k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1723
168k
  unsigned int i;
1724
1725
822k
  for (i = 0; i < table_size; ++i)
1726
660k
    {
1727
660k
      const char *secname = bfd_section_name (section);
1728
1729
660k
      if (alignment_table[i].comparison_length == (unsigned int) -1
1730
660k
    ? strcmp (alignment_table[i].name, secname) == 0
1731
660k
    : strncmp (alignment_table[i].name, secname,
1732
335k
         alignment_table[i].comparison_length) == 0)
1733
6.40k
  break;
1734
660k
    }
1735
168k
  if (i >= table_size)
1736
161k
    return;
1737
1738
6.40k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1739
6.40k
      && default_alignment < alignment_table[i].default_alignment_min)
1740
5.18k
    return;
1741
1742
1.22k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1743
1.22k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1744
1.22k
      && default_alignment > alignment_table[i].default_alignment_max
1745
1.22k
#endif
1746
1.22k
      )
1747
0
    return;
1748
1749
1.22k
  section->alignment_power = alignment_table[i].alignment_power;
1750
1.22k
}
pei-arm-wince.c:coff_set_custom_section_alignment
Line
Count
Source
1721
278k
{
1722
278k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1723
278k
  unsigned int i;
1724
1725
3.82M
  for (i = 0; i < table_size; ++i)
1726
3.56M
    {
1727
3.56M
      const char *secname = bfd_section_name (section);
1728
1729
3.56M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1730
3.56M
    ? strcmp (alignment_table[i].name, secname) == 0
1731
3.56M
    : strncmp (alignment_table[i].name, secname,
1732
1.64M
         alignment_table[i].comparison_length) == 0)
1733
14.5k
  break;
1734
3.56M
    }
1735
278k
  if (i >= table_size)
1736
264k
    return;
1737
1738
14.5k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1739
14.5k
      && default_alignment < alignment_table[i].default_alignment_min)
1740
5.20k
    return;
1741
1742
9.30k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1743
9.30k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1744
9.30k
      && default_alignment > alignment_table[i].default_alignment_max
1745
9.30k
#endif
1746
9.30k
      )
1747
0
    return;
1748
1749
9.30k
  section->alignment_power = alignment_table[i].alignment_power;
1750
9.30k
}
pei-arm.c:coff_set_custom_section_alignment
Line
Count
Source
1721
396k
{
1722
396k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1723
396k
  unsigned int i;
1724
1725
4.96M
  for (i = 0; i < table_size; ++i)
1726
4.64M
    {
1727
4.64M
      const char *secname = bfd_section_name (section);
1728
1729
4.64M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1730
4.64M
    ? strcmp (alignment_table[i].name, secname) == 0
1731
4.64M
    : strncmp (alignment_table[i].name, secname,
1732
2.06M
         alignment_table[i].comparison_length) == 0)
1733
70.5k
  break;
1734
4.64M
    }
1735
396k
  if (i >= table_size)
1736
325k
    return;
1737
1738
70.5k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1739
70.5k
      && default_alignment < alignment_table[i].default_alignment_min)
1740
6.66k
    return;
1741
1742
63.9k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1743
63.9k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1744
63.9k
      && default_alignment > alignment_table[i].default_alignment_max
1745
63.9k
#endif
1746
63.9k
      )
1747
0
    return;
1748
1749
63.9k
  section->alignment_power = alignment_table[i].alignment_power;
1750
63.9k
}
pei-mcore.c:coff_set_custom_section_alignment
Line
Count
Source
1721
265k
{
1722
265k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1723
265k
  unsigned int i;
1724
1725
1.29M
  for (i = 0; i < table_size; ++i)
1726
1.04M
    {
1727
1.04M
      const char *secname = bfd_section_name (section);
1728
1729
1.04M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1730
1.04M
    ? strcmp (alignment_table[i].name, secname) == 0
1731
1.04M
    : strncmp (alignment_table[i].name, secname,
1732
528k
         alignment_table[i].comparison_length) == 0)
1733
9.79k
  break;
1734
1.04M
    }
1735
265k
  if (i >= table_size)
1736
255k
    return;
1737
1738
9.79k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1739
9.79k
      && default_alignment < alignment_table[i].default_alignment_min)
1740
7.53k
    return;
1741
1742
2.26k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1743
2.26k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1744
2.26k
      && default_alignment > alignment_table[i].default_alignment_max
1745
2.26k
#endif
1746
2.26k
      )
1747
0
    return;
1748
1749
2.26k
  section->alignment_power = alignment_table[i].alignment_power;
1750
2.26k
}
pei-sh.c:coff_set_custom_section_alignment
Line
Count
Source
1721
322k
{
1722
322k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1723
322k
  unsigned int i;
1724
1725
1.57M
  for (i = 0; i < table_size; ++i)
1726
1.26M
    {
1727
1.26M
      const char *secname = bfd_section_name (section);
1728
1729
1.26M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1730
1.26M
    ? strcmp (alignment_table[i].name, secname) == 0
1731
1.26M
    : strncmp (alignment_table[i].name, secname,
1732
641k
         alignment_table[i].comparison_length) == 0)
1733
10.2k
  break;
1734
1.26M
    }
1735
322k
  if (i >= table_size)
1736
312k
    return;
1737
1738
10.2k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1739
10.2k
      && default_alignment < alignment_table[i].default_alignment_min)
1740
6.77k
    return;
1741
1742
3.44k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1743
3.44k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1744
3.44k
      && default_alignment > alignment_table[i].default_alignment_max
1745
3.44k
#endif
1746
3.44k
      )
1747
0
    return;
1748
1749
3.44k
  section->alignment_power = alignment_table[i].alignment_power;
1750
3.44k
}
1751
1752
/* Custom section alignment records.  */
1753
1754
static const struct coff_section_alignment_entry
1755
coff_section_alignment_table[] =
1756
{
1757
#ifdef COFF_SECTION_ALIGNMENT_ENTRIES
1758
  COFF_SECTION_ALIGNMENT_ENTRIES,
1759
#endif
1760
  /* There must not be any gaps between .stabstr sections.  */
1761
  { COFF_SECTION_NAME_PARTIAL_MATCH (".stabstr"),
1762
    1, COFF_ALIGNMENT_FIELD_EMPTY, 0 },
1763
  /* The .stab section must be aligned to 2**2 at most, to avoid gaps.  */
1764
  { COFF_SECTION_NAME_PARTIAL_MATCH (".stab"),
1765
    3, COFF_ALIGNMENT_FIELD_EMPTY, 2 },
1766
  /* Similarly for the .ctors and .dtors sections.  */
1767
  { COFF_SECTION_NAME_EXACT_MATCH (".ctors"),
1768
    3, COFF_ALIGNMENT_FIELD_EMPTY, 2 },
1769
  { COFF_SECTION_NAME_EXACT_MATCH (".dtors"),
1770
    3, COFF_ALIGNMENT_FIELD_EMPTY, 2 }
1771
};
1772
1773
static const unsigned int coff_section_alignment_table_size =
1774
  sizeof coff_section_alignment_table / sizeof coff_section_alignment_table[0];
1775
1776
/* Initialize a section structure with information peculiar to this
1777
   particular implementation of COFF.  */
1778
1779
static bool
1780
coff_new_section_hook (bfd * abfd, asection * section)
1781
134M
{
1782
134M
  combined_entry_type *native;
1783
134M
  size_t amt;
1784
134M
  unsigned char sclass = C_STAT;
1785
1786
134M
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1787
1788
#ifdef RS6000COFF_C
1789
31.7M
  if (bfd_xcoff_text_align_power (abfd) != 0
1790
31.7M
      && strcmp (bfd_section_name (section), ".text") == 0)
1791
46.7k
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1792
31.7M
  else if (bfd_xcoff_data_align_power (abfd) != 0
1793
31.7M
      && strcmp (bfd_section_name (section), ".data") == 0)
1794
27.0k
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1795
31.7M
  else
1796
31.7M
    {
1797
31.7M
      int i;
1798
1799
380M
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1800
348M
  if (strcmp (bfd_section_name (section),
1801
348M
        xcoff_dwsect_names[i].xcoff_name) == 0)
1802
14.1k
    {
1803
14.1k
      section->alignment_power = 0;
1804
14.1k
      sclass = C_DWARF;
1805
14.1k
      break;
1806
14.1k
    }
1807
31.7M
    }
1808
#endif
1809
1810
  /* Set up the section symbol.  */
1811
134M
  if (!_bfd_generic_new_section_hook (abfd, section))
1812
0
    return false;
1813
1814
  /* Allocate aux records for section symbols, to store size and
1815
     related info.
1816
1817
     @@ The 10 is a guess at a plausible maximum number of aux entries
1818
     (but shouldn't be a constant).  */
1819
134M
  amt = sizeof (combined_entry_type) * 10;
1820
134M
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1821
134M
  if (native == NULL)
1822
0
    return false;
1823
1824
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1825
     symbol information, since they'll be overridden by the BFD symbol
1826
     anyhow.  However, we do need to set the type and storage class,
1827
     in case this symbol winds up getting written out.  The value 0
1828
     for n_numaux is already correct.  */
1829
1830
134M
  native->is_sym = true;
1831
134M
  native->u.syment.n_type = T_NULL;
1832
134M
  native->u.syment.n_sclass = sclass;
1833
1834
134M
  coffsymbol (section->symbol)->native = native;
1835
1836
134M
  coff_set_custom_section_alignment (abfd, section,
1837
134M
             coff_section_alignment_table,
1838
134M
             coff_section_alignment_table_size);
1839
1840
134M
  return true;
1841
134M
}
pei-i386.c:coff_new_section_hook
Line
Count
Source
1781
497k
{
1782
497k
  combined_entry_type *native;
1783
497k
  size_t amt;
1784
497k
  unsigned char sclass = C_STAT;
1785
1786
497k
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1787
1788
#ifdef RS6000COFF_C
1789
  if (bfd_xcoff_text_align_power (abfd) != 0
1790
      && strcmp (bfd_section_name (section), ".text") == 0)
1791
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1792
  else if (bfd_xcoff_data_align_power (abfd) != 0
1793
      && strcmp (bfd_section_name (section), ".data") == 0)
1794
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1795
  else
1796
    {
1797
      int i;
1798
1799
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1800
  if (strcmp (bfd_section_name (section),
1801
        xcoff_dwsect_names[i].xcoff_name) == 0)
1802
    {
1803
      section->alignment_power = 0;
1804
      sclass = C_DWARF;
1805
      break;
1806
    }
1807
    }
1808
#endif
1809
1810
  /* Set up the section symbol.  */
1811
497k
  if (!_bfd_generic_new_section_hook (abfd, section))
1812
0
    return false;
1813
1814
  /* Allocate aux records for section symbols, to store size and
1815
     related info.
1816
1817
     @@ The 10 is a guess at a plausible maximum number of aux entries
1818
     (but shouldn't be a constant).  */
1819
497k
  amt = sizeof (combined_entry_type) * 10;
1820
497k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1821
497k
  if (native == NULL)
1822
0
    return false;
1823
1824
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1825
     symbol information, since they'll be overridden by the BFD symbol
1826
     anyhow.  However, we do need to set the type and storage class,
1827
     in case this symbol winds up getting written out.  The value 0
1828
     for n_numaux is already correct.  */
1829
1830
497k
  native->is_sym = true;
1831
497k
  native->u.syment.n_type = T_NULL;
1832
497k
  native->u.syment.n_sclass = sclass;
1833
1834
497k
  coffsymbol (section->symbol)->native = native;
1835
1836
497k
  coff_set_custom_section_alignment (abfd, section,
1837
497k
             coff_section_alignment_table,
1838
497k
             coff_section_alignment_table_size);
1839
1840
497k
  return true;
1841
497k
}
pe-x86_64.c:coff_new_section_hook
Line
Count
Source
1781
1.21M
{
1782
1.21M
  combined_entry_type *native;
1783
1.21M
  size_t amt;
1784
1.21M
  unsigned char sclass = C_STAT;
1785
1786
1.21M
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1787
1788
#ifdef RS6000COFF_C
1789
  if (bfd_xcoff_text_align_power (abfd) != 0
1790
      && strcmp (bfd_section_name (section), ".text") == 0)
1791
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1792
  else if (bfd_xcoff_data_align_power (abfd) != 0
1793
      && strcmp (bfd_section_name (section), ".data") == 0)
1794
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1795
  else
1796
    {
1797
      int i;
1798
1799
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1800
  if (strcmp (bfd_section_name (section),
1801
        xcoff_dwsect_names[i].xcoff_name) == 0)
1802
    {
1803
      section->alignment_power = 0;
1804
      sclass = C_DWARF;
1805
      break;
1806
    }
1807
    }
1808
#endif
1809
1810
  /* Set up the section symbol.  */
1811
1.21M
  if (!_bfd_generic_new_section_hook (abfd, section))
1812
0
    return false;
1813
1814
  /* Allocate aux records for section symbols, to store size and
1815
     related info.
1816
1817
     @@ The 10 is a guess at a plausible maximum number of aux entries
1818
     (but shouldn't be a constant).  */
1819
1.21M
  amt = sizeof (combined_entry_type) * 10;
1820
1.21M
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1821
1.21M
  if (native == NULL)
1822
0
    return false;
1823
1824
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1825
     symbol information, since they'll be overridden by the BFD symbol
1826
     anyhow.  However, we do need to set the type and storage class,
1827
     in case this symbol winds up getting written out.  The value 0
1828
     for n_numaux is already correct.  */
1829
1830
1.21M
  native->is_sym = true;
1831
1.21M
  native->u.syment.n_type = T_NULL;
1832
1.21M
  native->u.syment.n_sclass = sclass;
1833
1834
1.21M
  coffsymbol (section->symbol)->native = native;
1835
1836
1.21M
  coff_set_custom_section_alignment (abfd, section,
1837
1.21M
             coff_section_alignment_table,
1838
1.21M
             coff_section_alignment_table_size);
1839
1840
1.21M
  return true;
1841
1.21M
}
pei-x86_64.c:coff_new_section_hook
Line
Count
Source
1781
476k
{
1782
476k
  combined_entry_type *native;
1783
476k
  size_t amt;
1784
476k
  unsigned char sclass = C_STAT;
1785
1786
476k
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1787
1788
#ifdef RS6000COFF_C
1789
  if (bfd_xcoff_text_align_power (abfd) != 0
1790
      && strcmp (bfd_section_name (section), ".text") == 0)
1791
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1792
  else if (bfd_xcoff_data_align_power (abfd) != 0
1793
      && strcmp (bfd_section_name (section), ".data") == 0)
1794
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1795
  else
1796
    {
1797
      int i;
1798
1799
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1800
  if (strcmp (bfd_section_name (section),
1801
        xcoff_dwsect_names[i].xcoff_name) == 0)
1802
    {
1803
      section->alignment_power = 0;
1804
      sclass = C_DWARF;
1805
      break;
1806
    }
1807
    }
1808
#endif
1809
1810
  /* Set up the section symbol.  */
1811
476k
  if (!_bfd_generic_new_section_hook (abfd, section))
1812
0
    return false;
1813
1814
  /* Allocate aux records for section symbols, to store size and
1815
     related info.
1816
1817
     @@ The 10 is a guess at a plausible maximum number of aux entries
1818
     (but shouldn't be a constant).  */
1819
476k
  amt = sizeof (combined_entry_type) * 10;
1820
476k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1821
476k
  if (native == NULL)
1822
0
    return false;
1823
1824
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1825
     symbol information, since they'll be overridden by the BFD symbol
1826
     anyhow.  However, we do need to set the type and storage class,
1827
     in case this symbol winds up getting written out.  The value 0
1828
     for n_numaux is already correct.  */
1829
1830
476k
  native->is_sym = true;
1831
476k
  native->u.syment.n_type = T_NULL;
1832
476k
  native->u.syment.n_sclass = sclass;
1833
1834
476k
  coffsymbol (section->symbol)->native = native;
1835
1836
476k
  coff_set_custom_section_alignment (abfd, section,
1837
476k
             coff_section_alignment_table,
1838
476k
             coff_section_alignment_table_size);
1839
1840
476k
  return true;
1841
476k
}
coff-x86_64.c:coff_new_section_hook
Line
Count
Source
1781
19.0M
{
1782
19.0M
  combined_entry_type *native;
1783
19.0M
  size_t amt;
1784
19.0M
  unsigned char sclass = C_STAT;
1785
1786
19.0M
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1787
1788
#ifdef RS6000COFF_C
1789
  if (bfd_xcoff_text_align_power (abfd) != 0
1790
      && strcmp (bfd_section_name (section), ".text") == 0)
1791
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1792
  else if (bfd_xcoff_data_align_power (abfd) != 0
1793
      && strcmp (bfd_section_name (section), ".data") == 0)
1794
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1795
  else
1796
    {
1797
      int i;
1798
1799
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1800
  if (strcmp (bfd_section_name (section),
1801
        xcoff_dwsect_names[i].xcoff_name) == 0)
1802
    {
1803
      section->alignment_power = 0;
1804
      sclass = C_DWARF;
1805
      break;
1806
    }
1807
    }
1808
#endif
1809
1810
  /* Set up the section symbol.  */
1811
19.0M
  if (!_bfd_generic_new_section_hook (abfd, section))
1812
0
    return false;
1813
1814
  /* Allocate aux records for section symbols, to store size and
1815
     related info.
1816
1817
     @@ The 10 is a guess at a plausible maximum number of aux entries
1818
     (but shouldn't be a constant).  */
1819
19.0M
  amt = sizeof (combined_entry_type) * 10;
1820
19.0M
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1821
19.0M
  if (native == NULL)
1822
0
    return false;
1823
1824
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1825
     symbol information, since they'll be overridden by the BFD symbol
1826
     anyhow.  However, we do need to set the type and storage class,
1827
     in case this symbol winds up getting written out.  The value 0
1828
     for n_numaux is already correct.  */
1829
1830
19.0M
  native->is_sym = true;
1831
19.0M
  native->u.syment.n_type = T_NULL;
1832
19.0M
  native->u.syment.n_sclass = sclass;
1833
1834
19.0M
  coffsymbol (section->symbol)->native = native;
1835
1836
19.0M
  coff_set_custom_section_alignment (abfd, section,
1837
19.0M
             coff_section_alignment_table,
1838
19.0M
             coff_section_alignment_table_size);
1839
1840
19.0M
  return true;
1841
19.0M
}
coff64-rs6000.c:coff_new_section_hook
Line
Count
Source
1781
3.50M
{
1782
3.50M
  combined_entry_type *native;
1783
3.50M
  size_t amt;
1784
3.50M
  unsigned char sclass = C_STAT;
1785
1786
3.50M
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1787
1788
3.50M
#ifdef RS6000COFF_C
1789
3.50M
  if (bfd_xcoff_text_align_power (abfd) != 0
1790
3.50M
      && strcmp (bfd_section_name (section), ".text") == 0)
1791
9.44k
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1792
3.49M
  else if (bfd_xcoff_data_align_power (abfd) != 0
1793
3.49M
      && strcmp (bfd_section_name (section), ".data") == 0)
1794
6.40k
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1795
3.48M
  else
1796
3.48M
    {
1797
3.48M
      int i;
1798
1799
41.8M
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1800
38.3M
  if (strcmp (bfd_section_name (section),
1801
38.3M
        xcoff_dwsect_names[i].xcoff_name) == 0)
1802
4.13k
    {
1803
4.13k
      section->alignment_power = 0;
1804
4.13k
      sclass = C_DWARF;
1805
4.13k
      break;
1806
4.13k
    }
1807
3.48M
    }
1808
3.50M
#endif
1809
1810
  /* Set up the section symbol.  */
1811
3.50M
  if (!_bfd_generic_new_section_hook (abfd, section))
1812
0
    return false;
1813
1814
  /* Allocate aux records for section symbols, to store size and
1815
     related info.
1816
1817
     @@ The 10 is a guess at a plausible maximum number of aux entries
1818
     (but shouldn't be a constant).  */
1819
3.50M
  amt = sizeof (combined_entry_type) * 10;
1820
3.50M
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1821
3.50M
  if (native == NULL)
1822
0
    return false;
1823
1824
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1825
     symbol information, since they'll be overridden by the BFD symbol
1826
     anyhow.  However, we do need to set the type and storage class,
1827
     in case this symbol winds up getting written out.  The value 0
1828
     for n_numaux is already correct.  */
1829
1830
3.50M
  native->is_sym = true;
1831
3.50M
  native->u.syment.n_type = T_NULL;
1832
3.50M
  native->u.syment.n_sclass = sclass;
1833
1834
3.50M
  coffsymbol (section->symbol)->native = native;
1835
1836
3.50M
  coff_set_custom_section_alignment (abfd, section,
1837
3.50M
             coff_section_alignment_table,
1838
3.50M
             coff_section_alignment_table_size);
1839
1840
3.50M
  return true;
1841
3.50M
}
pe-aarch64.c:coff_new_section_hook
Line
Count
Source
1781
279k
{
1782
279k
  combined_entry_type *native;
1783
279k
  size_t amt;
1784
279k
  unsigned char sclass = C_STAT;
1785
1786
279k
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1787
1788
#ifdef RS6000COFF_C
1789
  if (bfd_xcoff_text_align_power (abfd) != 0
1790
      && strcmp (bfd_section_name (section), ".text") == 0)
1791
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1792
  else if (bfd_xcoff_data_align_power (abfd) != 0
1793
      && strcmp (bfd_section_name (section), ".data") == 0)
1794
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1795
  else
1796
    {
1797
      int i;
1798
1799
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1800
  if (strcmp (bfd_section_name (section),
1801
        xcoff_dwsect_names[i].xcoff_name) == 0)
1802
    {
1803
      section->alignment_power = 0;
1804
      sclass = C_DWARF;
1805
      break;
1806
    }
1807
    }
1808
#endif
1809
1810
  /* Set up the section symbol.  */
1811
279k
  if (!_bfd_generic_new_section_hook (abfd, section))
1812
0
    return false;
1813
1814
  /* Allocate aux records for section symbols, to store size and
1815
     related info.
1816
1817
     @@ The 10 is a guess at a plausible maximum number of aux entries
1818
     (but shouldn't be a constant).  */
1819
279k
  amt = sizeof (combined_entry_type) * 10;
1820
279k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1821
279k
  if (native == NULL)
1822
0
    return false;
1823
1824
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1825
     symbol information, since they'll be overridden by the BFD symbol
1826
     anyhow.  However, we do need to set the type and storage class,
1827
     in case this symbol winds up getting written out.  The value 0
1828
     for n_numaux is already correct.  */
1829
1830
279k
  native->is_sym = true;
1831
279k
  native->u.syment.n_type = T_NULL;
1832
279k
  native->u.syment.n_sclass = sclass;
1833
1834
279k
  coffsymbol (section->symbol)->native = native;
1835
1836
279k
  coff_set_custom_section_alignment (abfd, section,
1837
279k
             coff_section_alignment_table,
1838
279k
             coff_section_alignment_table_size);
1839
1840
279k
  return true;
1841
279k
}
pei-aarch64.c:coff_new_section_hook
Line
Count
Source
1781
409k
{
1782
409k
  combined_entry_type *native;
1783
409k
  size_t amt;
1784
409k
  unsigned char sclass = C_STAT;
1785
1786
409k
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1787
1788
#ifdef RS6000COFF_C
1789
  if (bfd_xcoff_text_align_power (abfd) != 0
1790
      && strcmp (bfd_section_name (section), ".text") == 0)
1791
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1792
  else if (bfd_xcoff_data_align_power (abfd) != 0
1793
      && strcmp (bfd_section_name (section), ".data") == 0)
1794
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1795
  else
1796
    {
1797
      int i;
1798
1799
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1800
  if (strcmp (bfd_section_name (section),
1801
        xcoff_dwsect_names[i].xcoff_name) == 0)
1802
    {
1803
      section->alignment_power = 0;
1804
      sclass = C_DWARF;
1805
      break;
1806
    }
1807
    }
1808
#endif
1809
1810
  /* Set up the section symbol.  */
1811
409k
  if (!_bfd_generic_new_section_hook (abfd, section))
1812
0
    return false;
1813
1814
  /* Allocate aux records for section symbols, to store size and
1815
     related info.
1816
1817
     @@ The 10 is a guess at a plausible maximum number of aux entries
1818
     (but shouldn't be a constant).  */
1819
409k
  amt = sizeof (combined_entry_type) * 10;
1820
409k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1821
409k
  if (native == NULL)
1822
0
    return false;
1823
1824
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1825
     symbol information, since they'll be overridden by the BFD symbol
1826
     anyhow.  However, we do need to set the type and storage class,
1827
     in case this symbol winds up getting written out.  The value 0
1828
     for n_numaux is already correct.  */
1829
1830
409k
  native->is_sym = true;
1831
409k
  native->u.syment.n_type = T_NULL;
1832
409k
  native->u.syment.n_sclass = sclass;
1833
1834
409k
  coffsymbol (section->symbol)->native = native;
1835
1836
409k
  coff_set_custom_section_alignment (abfd, section,
1837
409k
             coff_section_alignment_table,
1838
409k
             coff_section_alignment_table_size);
1839
1840
409k
  return true;
1841
409k
}
pei-ia64.c:coff_new_section_hook
Line
Count
Source
1781
330k
{
1782
330k
  combined_entry_type *native;
1783
330k
  size_t amt;
1784
330k
  unsigned char sclass = C_STAT;
1785
1786
330k
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1787
1788
#ifdef RS6000COFF_C
1789
  if (bfd_xcoff_text_align_power (abfd) != 0
1790
      && strcmp (bfd_section_name (section), ".text") == 0)
1791
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1792
  else if (bfd_xcoff_data_align_power (abfd) != 0
1793
      && strcmp (bfd_section_name (section), ".data") == 0)
1794
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1795
  else
1796
    {
1797
      int i;
1798
1799
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1800
  if (strcmp (bfd_section_name (section),
1801
        xcoff_dwsect_names[i].xcoff_name) == 0)
1802
    {
1803
      section->alignment_power = 0;
1804
      sclass = C_DWARF;
1805
      break;
1806
    }
1807
    }
1808
#endif
1809
1810
  /* Set up the section symbol.  */
1811
330k
  if (!_bfd_generic_new_section_hook (abfd, section))
1812
0
    return false;
1813
1814
  /* Allocate aux records for section symbols, to store size and
1815
     related info.
1816
1817
     @@ The 10 is a guess at a plausible maximum number of aux entries
1818
     (but shouldn't be a constant).  */
1819
330k
  amt = sizeof (combined_entry_type) * 10;
1820
330k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1821
330k
  if (native == NULL)
1822
0
    return false;
1823
1824
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1825
     symbol information, since they'll be overridden by the BFD symbol
1826
     anyhow.  However, we do need to set the type and storage class,
1827
     in case this symbol winds up getting written out.  The value 0
1828
     for n_numaux is already correct.  */
1829
1830
330k
  native->is_sym = true;
1831
330k
  native->u.syment.n_type = T_NULL;
1832
330k
  native->u.syment.n_sclass = sclass;
1833
1834
330k
  coffsymbol (section->symbol)->native = native;
1835
1836
330k
  coff_set_custom_section_alignment (abfd, section,
1837
330k
             coff_section_alignment_table,
1838
330k
             coff_section_alignment_table_size);
1839
1840
330k
  return true;
1841
330k
}
pei-loongarch64.c:coff_new_section_hook
Line
Count
Source
1781
333k
{
1782
333k
  combined_entry_type *native;
1783
333k
  size_t amt;
1784
333k
  unsigned char sclass = C_STAT;
1785
1786
333k
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1787
1788
#ifdef RS6000COFF_C
1789
  if (bfd_xcoff_text_align_power (abfd) != 0
1790
      && strcmp (bfd_section_name (section), ".text") == 0)
1791
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1792
  else if (bfd_xcoff_data_align_power (abfd) != 0
1793
      && strcmp (bfd_section_name (section), ".data") == 0)
1794
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1795
  else
1796
    {
1797
      int i;
1798
1799
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1800
  if (strcmp (bfd_section_name (section),
1801
        xcoff_dwsect_names[i].xcoff_name) == 0)
1802
    {
1803
      section->alignment_power = 0;
1804
      sclass = C_DWARF;
1805
      break;
1806
    }
1807
    }
1808
#endif
1809
1810
  /* Set up the section symbol.  */
1811
333k
  if (!_bfd_generic_new_section_hook (abfd, section))
1812
0
    return false;
1813
1814
  /* Allocate aux records for section symbols, to store size and
1815
     related info.
1816
1817
     @@ The 10 is a guess at a plausible maximum number of aux entries
1818
     (but shouldn't be a constant).  */
1819
333k
  amt = sizeof (combined_entry_type) * 10;
1820
333k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1821
333k
  if (native == NULL)
1822
0
    return false;
1823
1824
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1825
     symbol information, since they'll be overridden by the BFD symbol
1826
     anyhow.  However, we do need to set the type and storage class,
1827
     in case this symbol winds up getting written out.  The value 0
1828
     for n_numaux is already correct.  */
1829
1830
333k
  native->is_sym = true;
1831
333k
  native->u.syment.n_type = T_NULL;
1832
333k
  native->u.syment.n_sclass = sclass;
1833
1834
333k
  coffsymbol (section->symbol)->native = native;
1835
1836
333k
  coff_set_custom_section_alignment (abfd, section,
1837
333k
             coff_section_alignment_table,
1838
333k
             coff_section_alignment_table_size);
1839
1840
333k
  return true;
1841
333k
}
pei-riscv64.c:coff_new_section_hook
Line
Count
Source
1781
309k
{
1782
309k
  combined_entry_type *native;
1783
309k
  size_t amt;
1784
309k
  unsigned char sclass = C_STAT;
1785
1786
309k
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1787
1788
#ifdef RS6000COFF_C
1789
  if (bfd_xcoff_text_align_power (abfd) != 0
1790
      && strcmp (bfd_section_name (section), ".text") == 0)
1791
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1792
  else if (bfd_xcoff_data_align_power (abfd) != 0
1793
      && strcmp (bfd_section_name (section), ".data") == 0)
1794
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1795
  else
1796
    {
1797
      int i;
1798
1799
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1800
  if (strcmp (bfd_section_name (section),
1801
        xcoff_dwsect_names[i].xcoff_name) == 0)
1802
    {
1803
      section->alignment_power = 0;
1804
      sclass = C_DWARF;
1805
      break;
1806
    }
1807
    }
1808
#endif
1809
1810
  /* Set up the section symbol.  */
1811
309k
  if (!_bfd_generic_new_section_hook (abfd, section))
1812
0
    return false;
1813
1814
  /* Allocate aux records for section symbols, to store size and
1815
     related info.
1816
1817
     @@ The 10 is a guess at a plausible maximum number of aux entries
1818
     (but shouldn't be a constant).  */
1819
309k
  amt = sizeof (combined_entry_type) * 10;
1820
309k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1821
309k
  if (native == NULL)
1822
0
    return false;
1823
1824
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1825
     symbol information, since they'll be overridden by the BFD symbol
1826
     anyhow.  However, we do need to set the type and storage class,
1827
     in case this symbol winds up getting written out.  The value 0
1828
     for n_numaux is already correct.  */
1829
1830
309k
  native->is_sym = true;
1831
309k
  native->u.syment.n_type = T_NULL;
1832
309k
  native->u.syment.n_sclass = sclass;
1833
1834
309k
  coffsymbol (section->symbol)->native = native;
1835
1836
309k
  coff_set_custom_section_alignment (abfd, section,
1837
309k
             coff_section_alignment_table,
1838
309k
             coff_section_alignment_table_size);
1839
1840
309k
  return true;
1841
309k
}
cf-i386lynx.c:coff_new_section_hook
Line
Count
Source
1781
7.80M
{
1782
7.80M
  combined_entry_type *native;
1783
7.80M
  size_t amt;
1784
7.80M
  unsigned char sclass = C_STAT;
1785
1786
7.80M
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1787
1788
#ifdef RS6000COFF_C
1789
  if (bfd_xcoff_text_align_power (abfd) != 0
1790
      && strcmp (bfd_section_name (section), ".text") == 0)
1791
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1792
  else if (bfd_xcoff_data_align_power (abfd) != 0
1793
      && strcmp (bfd_section_name (section), ".data") == 0)
1794
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1795
  else
1796
    {
1797
      int i;
1798
1799
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1800
  if (strcmp (bfd_section_name (section),
1801
        xcoff_dwsect_names[i].xcoff_name) == 0)
1802
    {
1803
      section->alignment_power = 0;
1804
      sclass = C_DWARF;
1805
      break;
1806
    }
1807
    }
1808
#endif
1809
1810
  /* Set up the section symbol.  */
1811
7.80M
  if (!_bfd_generic_new_section_hook (abfd, section))
1812
0
    return false;
1813
1814
  /* Allocate aux records for section symbols, to store size and
1815
     related info.
1816
1817
     @@ The 10 is a guess at a plausible maximum number of aux entries
1818
     (but shouldn't be a constant).  */
1819
7.80M
  amt = sizeof (combined_entry_type) * 10;
1820
7.80M
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1821
7.80M
  if (native == NULL)
1822
0
    return false;
1823
1824
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1825
     symbol information, since they'll be overridden by the BFD symbol
1826
     anyhow.  However, we do need to set the type and storage class,
1827
     in case this symbol winds up getting written out.  The value 0
1828
     for n_numaux is already correct.  */
1829
1830
7.80M
  native->is_sym = true;
1831
7.80M
  native->u.syment.n_type = T_NULL;
1832
7.80M
  native->u.syment.n_sclass = sclass;
1833
1834
7.80M
  coffsymbol (section->symbol)->native = native;
1835
1836
7.80M
  coff_set_custom_section_alignment (abfd, section,
1837
7.80M
             coff_section_alignment_table,
1838
7.80M
             coff_section_alignment_table_size);
1839
1840
7.80M
  return true;
1841
7.80M
}
coff-go32.c:coff_new_section_hook
Line
Count
Source
1781
5.17M
{
1782
5.17M
  combined_entry_type *native;
1783
5.17M
  size_t amt;
1784
5.17M
  unsigned char sclass = C_STAT;
1785
1786
5.17M
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1787
1788
#ifdef RS6000COFF_C
1789
  if (bfd_xcoff_text_align_power (abfd) != 0
1790
      && strcmp (bfd_section_name (section), ".text") == 0)
1791
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1792
  else if (bfd_xcoff_data_align_power (abfd) != 0
1793
      && strcmp (bfd_section_name (section), ".data") == 0)
1794
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1795
  else
1796
    {
1797
      int i;
1798
1799
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1800
  if (strcmp (bfd_section_name (section),
1801
        xcoff_dwsect_names[i].xcoff_name) == 0)
1802
    {
1803
      section->alignment_power = 0;
1804
      sclass = C_DWARF;
1805
      break;
1806
    }
1807
    }
1808
#endif
1809
1810
  /* Set up the section symbol.  */
1811
5.17M
  if (!_bfd_generic_new_section_hook (abfd, section))
1812
0
    return false;
1813
1814
  /* Allocate aux records for section symbols, to store size and
1815
     related info.
1816
1817
     @@ The 10 is a guess at a plausible maximum number of aux entries
1818
     (but shouldn't be a constant).  */
1819
5.17M
  amt = sizeof (combined_entry_type) * 10;
1820
5.17M
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1821
5.17M
  if (native == NULL)
1822
0
    return false;
1823
1824
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1825
     symbol information, since they'll be overridden by the BFD symbol
1826
     anyhow.  However, we do need to set the type and storage class,
1827
     in case this symbol winds up getting written out.  The value 0
1828
     for n_numaux is already correct.  */
1829
1830
5.17M
  native->is_sym = true;
1831
5.17M
  native->u.syment.n_type = T_NULL;
1832
5.17M
  native->u.syment.n_sclass = sclass;
1833
1834
5.17M
  coffsymbol (section->symbol)->native = native;
1835
1836
5.17M
  coff_set_custom_section_alignment (abfd, section,
1837
5.17M
             coff_section_alignment_table,
1838
5.17M
             coff_section_alignment_table_size);
1839
1840
5.17M
  return true;
1841
5.17M
}
coff-i386.c:coff_new_section_hook
Line
Count
Source
1781
6.65M
{
1782
6.65M
  combined_entry_type *native;
1783
6.65M
  size_t amt;
1784
6.65M
  unsigned char sclass = C_STAT;
1785
1786
6.65M
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1787
1788
#ifdef RS6000COFF_C
1789
  if (bfd_xcoff_text_align_power (abfd) != 0
1790
      && strcmp (bfd_section_name (section), ".text") == 0)
1791
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1792
  else if (bfd_xcoff_data_align_power (abfd) != 0
1793
      && strcmp (bfd_section_name (section), ".data") == 0)
1794
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1795
  else
1796
    {
1797
      int i;
1798
1799
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1800
  if (strcmp (bfd_section_name (section),
1801
        xcoff_dwsect_names[i].xcoff_name) == 0)
1802
    {
1803
      section->alignment_power = 0;
1804
      sclass = C_DWARF;
1805
      break;
1806
    }
1807
    }
1808
#endif
1809
1810
  /* Set up the section symbol.  */
1811
6.65M
  if (!_bfd_generic_new_section_hook (abfd, section))
1812
0
    return false;
1813
1814
  /* Allocate aux records for section symbols, to store size and
1815
     related info.
1816
1817
     @@ The 10 is a guess at a plausible maximum number of aux entries
1818
     (but shouldn't be a constant).  */
1819
6.65M
  amt = sizeof (combined_entry_type) * 10;
1820
6.65M
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1821
6.65M
  if (native == NULL)
1822
0
    return false;
1823
1824
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1825
     symbol information, since they'll be overridden by the BFD symbol
1826
     anyhow.  However, we do need to set the type and storage class,
1827
     in case this symbol winds up getting written out.  The value 0
1828
     for n_numaux is already correct.  */
1829
1830
6.65M
  native->is_sym = true;
1831
6.65M
  native->u.syment.n_type = T_NULL;
1832
6.65M
  native->u.syment.n_sclass = sclass;
1833
1834
6.65M
  coffsymbol (section->symbol)->native = native;
1835
1836
6.65M
  coff_set_custom_section_alignment (abfd, section,
1837
6.65M
             coff_section_alignment_table,
1838
6.65M
             coff_section_alignment_table_size);
1839
1840
6.65M
  return true;
1841
6.65M
}
coff-rs6000.c:coff_new_section_hook
Line
Count
Source
1781
28.2M
{
1782
28.2M
  combined_entry_type *native;
1783
28.2M
  size_t amt;
1784
28.2M
  unsigned char sclass = C_STAT;
1785
1786
28.2M
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1787
1788
28.2M
#ifdef RS6000COFF_C
1789
28.2M
  if (bfd_xcoff_text_align_power (abfd) != 0
1790
28.2M
      && strcmp (bfd_section_name (section), ".text") == 0)
1791
37.3k
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1792
28.2M
  else if (bfd_xcoff_data_align_power (abfd) != 0
1793
28.2M
      && strcmp (bfd_section_name (section), ".data") == 0)
1794
20.6k
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1795
28.2M
  else
1796
28.2M
    {
1797
28.2M
      int i;
1798
1799
338M
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1800
310M
  if (strcmp (bfd_section_name (section),
1801
310M
        xcoff_dwsect_names[i].xcoff_name) == 0)
1802
10.0k
    {
1803
10.0k
      section->alignment_power = 0;
1804
10.0k
      sclass = C_DWARF;
1805
10.0k
      break;
1806
10.0k
    }
1807
28.2M
    }
1808
28.2M
#endif
1809
1810
  /* Set up the section symbol.  */
1811
28.2M
  if (!_bfd_generic_new_section_hook (abfd, section))
1812
0
    return false;
1813
1814
  /* Allocate aux records for section symbols, to store size and
1815
     related info.
1816
1817
     @@ The 10 is a guess at a plausible maximum number of aux entries
1818
     (but shouldn't be a constant).  */
1819
28.2M
  amt = sizeof (combined_entry_type) * 10;
1820
28.2M
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1821
28.2M
  if (native == NULL)
1822
0
    return false;
1823
1824
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1825
     symbol information, since they'll be overridden by the BFD symbol
1826
     anyhow.  However, we do need to set the type and storage class,
1827
     in case this symbol winds up getting written out.  The value 0
1828
     for n_numaux is already correct.  */
1829
1830
28.2M
  native->is_sym = true;
1831
28.2M
  native->u.syment.n_type = T_NULL;
1832
28.2M
  native->u.syment.n_sclass = sclass;
1833
1834
28.2M
  coffsymbol (section->symbol)->native = native;
1835
1836
28.2M
  coff_set_custom_section_alignment (abfd, section,
1837
28.2M
             coff_section_alignment_table,
1838
28.2M
             coff_section_alignment_table_size);
1839
1840
28.2M
  return true;
1841
28.2M
}
coff-sh.c:coff_new_section_hook
Line
Count
Source
1781
10.5M
{
1782
10.5M
  combined_entry_type *native;
1783
10.5M
  size_t amt;
1784
10.5M
  unsigned char sclass = C_STAT;
1785
1786
10.5M
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1787
1788
#ifdef RS6000COFF_C
1789
  if (bfd_xcoff_text_align_power (abfd) != 0
1790
      && strcmp (bfd_section_name (section), ".text") == 0)
1791
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1792
  else if (bfd_xcoff_data_align_power (abfd) != 0
1793
      && strcmp (bfd_section_name (section), ".data") == 0)
1794
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1795
  else
1796
    {
1797
      int i;
1798
1799
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1800
  if (strcmp (bfd_section_name (section),
1801
        xcoff_dwsect_names[i].xcoff_name) == 0)
1802
    {
1803
      section->alignment_power = 0;
1804
      sclass = C_DWARF;
1805
      break;
1806
    }
1807
    }
1808
#endif
1809
1810
  /* Set up the section symbol.  */
1811
10.5M
  if (!_bfd_generic_new_section_hook (abfd, section))
1812
0
    return false;
1813
1814
  /* Allocate aux records for section symbols, to store size and
1815
     related info.
1816
1817
     @@ The 10 is a guess at a plausible maximum number of aux entries
1818
     (but shouldn't be a constant).  */
1819
10.5M
  amt = sizeof (combined_entry_type) * 10;
1820
10.5M
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1821
10.5M
  if (native == NULL)
1822
0
    return false;
1823
1824
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1825
     symbol information, since they'll be overridden by the BFD symbol
1826
     anyhow.  However, we do need to set the type and storage class,
1827
     in case this symbol winds up getting written out.  The value 0
1828
     for n_numaux is already correct.  */
1829
1830
10.5M
  native->is_sym = true;
1831
10.5M
  native->u.syment.n_type = T_NULL;
1832
10.5M
  native->u.syment.n_sclass = sclass;
1833
1834
10.5M
  coffsymbol (section->symbol)->native = native;
1835
1836
10.5M
  coff_set_custom_section_alignment (abfd, section,
1837
10.5M
             coff_section_alignment_table,
1838
10.5M
             coff_section_alignment_table_size);
1839
1840
10.5M
  return true;
1841
10.5M
}
coff-stgo32.c:coff_new_section_hook
Line
Count
Source
1781
1.18M
{
1782
1.18M
  combined_entry_type *native;
1783
1.18M
  size_t amt;
1784
1.18M
  unsigned char sclass = C_STAT;
1785
1786
1.18M
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1787
1788
#ifdef RS6000COFF_C
1789
  if (bfd_xcoff_text_align_power (abfd) != 0
1790
      && strcmp (bfd_section_name (section), ".text") == 0)
1791
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1792
  else if (bfd_xcoff_data_align_power (abfd) != 0
1793
      && strcmp (bfd_section_name (section), ".data") == 0)
1794
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1795
  else
1796
    {
1797
      int i;
1798
1799
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1800
  if (strcmp (bfd_section_name (section),
1801
        xcoff_dwsect_names[i].xcoff_name) == 0)
1802
    {
1803
      section->alignment_power = 0;
1804
      sclass = C_DWARF;
1805
      break;
1806
    }
1807
    }
1808
#endif
1809
1810
  /* Set up the section symbol.  */
1811
1.18M
  if (!_bfd_generic_new_section_hook (abfd, section))
1812
0
    return false;
1813
1814
  /* Allocate aux records for section symbols, to store size and
1815
     related info.
1816
1817
     @@ The 10 is a guess at a plausible maximum number of aux entries
1818
     (but shouldn't be a constant).  */
1819
1.18M
  amt = sizeof (combined_entry_type) * 10;
1820
1.18M
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1821
1.18M
  if (native == NULL)
1822
0
    return false;
1823
1824
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1825
     symbol information, since they'll be overridden by the BFD symbol
1826
     anyhow.  However, we do need to set the type and storage class,
1827
     in case this symbol winds up getting written out.  The value 0
1828
     for n_numaux is already correct.  */
1829
1830
1.18M
  native->is_sym = true;
1831
1.18M
  native->u.syment.n_type = T_NULL;
1832
1.18M
  native->u.syment.n_sclass = sclass;
1833
1834
1.18M
  coffsymbol (section->symbol)->native = native;
1835
1836
1.18M
  coff_set_custom_section_alignment (abfd, section,
1837
1.18M
             coff_section_alignment_table,
1838
1.18M
             coff_section_alignment_table_size);
1839
1840
1.18M
  return true;
1841
1.18M
}
coff-tic30.c:coff_new_section_hook
Line
Count
Source
1781
12.7M
{
1782
12.7M
  combined_entry_type *native;
1783
12.7M
  size_t amt;
1784
12.7M
  unsigned char sclass = C_STAT;
1785
1786
12.7M
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1787
1788
#ifdef RS6000COFF_C
1789
  if (bfd_xcoff_text_align_power (abfd) != 0
1790
      && strcmp (bfd_section_name (section), ".text") == 0)
1791
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1792
  else if (bfd_xcoff_data_align_power (abfd) != 0
1793
      && strcmp (bfd_section_name (section), ".data") == 0)
1794
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1795
  else
1796
    {
1797
      int i;
1798
1799
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1800
  if (strcmp (bfd_section_name (section),
1801
        xcoff_dwsect_names[i].xcoff_name) == 0)
1802
    {
1803
      section->alignment_power = 0;
1804
      sclass = C_DWARF;
1805
      break;
1806
    }
1807
    }
1808
#endif
1809
1810
  /* Set up the section symbol.  */
1811
12.7M
  if (!_bfd_generic_new_section_hook (abfd, section))
1812
0
    return false;
1813
1814
  /* Allocate aux records for section symbols, to store size and
1815
     related info.
1816
1817
     @@ The 10 is a guess at a plausible maximum number of aux entries
1818
     (but shouldn't be a constant).  */
1819
12.7M
  amt = sizeof (combined_entry_type) * 10;
1820
12.7M
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1821
12.7M
  if (native == NULL)
1822
0
    return false;
1823
1824
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1825
     symbol information, since they'll be overridden by the BFD symbol
1826
     anyhow.  However, we do need to set the type and storage class,
1827
     in case this symbol winds up getting written out.  The value 0
1828
     for n_numaux is already correct.  */
1829
1830
12.7M
  native->is_sym = true;
1831
12.7M
  native->u.syment.n_type = T_NULL;
1832
12.7M
  native->u.syment.n_sclass = sclass;
1833
1834
12.7M
  coffsymbol (section->symbol)->native = native;
1835
1836
12.7M
  coff_set_custom_section_alignment (abfd, section,
1837
12.7M
             coff_section_alignment_table,
1838
12.7M
             coff_section_alignment_table_size);
1839
1840
12.7M
  return true;
1841
12.7M
}
Unexecuted instantiation: coff-tic4x.c:coff_new_section_hook
coff-tic54x.c:coff_new_section_hook
Line
Count
Source
1781
13.0M
{
1782
13.0M
  combined_entry_type *native;
1783
13.0M
  size_t amt;
1784
13.0M
  unsigned char sclass = C_STAT;
1785
1786
13.0M
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1787
1788
#ifdef RS6000COFF_C
1789
  if (bfd_xcoff_text_align_power (abfd) != 0
1790
      && strcmp (bfd_section_name (section), ".text") == 0)
1791
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1792
  else if (bfd_xcoff_data_align_power (abfd) != 0
1793
      && strcmp (bfd_section_name (section), ".data") == 0)
1794
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1795
  else
1796
    {
1797
      int i;
1798
1799
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1800
  if (strcmp (bfd_section_name (section),
1801
        xcoff_dwsect_names[i].xcoff_name) == 0)
1802
    {
1803
      section->alignment_power = 0;
1804
      sclass = C_DWARF;
1805
      break;
1806
    }
1807
    }
1808
#endif
1809
1810
  /* Set up the section symbol.  */
1811
13.0M
  if (!_bfd_generic_new_section_hook (abfd, section))
1812
0
    return false;
1813
1814
  /* Allocate aux records for section symbols, to store size and
1815
     related info.
1816
1817
     @@ The 10 is a guess at a plausible maximum number of aux entries
1818
     (but shouldn't be a constant).  */
1819
13.0M
  amt = sizeof (combined_entry_type) * 10;
1820
13.0M
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1821
13.0M
  if (native == NULL)
1822
0
    return false;
1823
1824
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1825
     symbol information, since they'll be overridden by the BFD symbol
1826
     anyhow.  However, we do need to set the type and storage class,
1827
     in case this symbol winds up getting written out.  The value 0
1828
     for n_numaux is already correct.  */
1829
1830
13.0M
  native->is_sym = true;
1831
13.0M
  native->u.syment.n_type = T_NULL;
1832
13.0M
  native->u.syment.n_sclass = sclass;
1833
1834
13.0M
  coffsymbol (section->symbol)->native = native;
1835
1836
13.0M
  coff_set_custom_section_alignment (abfd, section,
1837
13.0M
             coff_section_alignment_table,
1838
13.0M
             coff_section_alignment_table_size);
1839
1840
13.0M
  return true;
1841
13.0M
}
coff-z80.c:coff_new_section_hook
Line
Count
Source
1781
1.94M
{
1782
1.94M
  combined_entry_type *native;
1783
1.94M
  size_t amt;
1784
1.94M
  unsigned char sclass = C_STAT;
1785
1786
1.94M
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1787
1788
#ifdef RS6000COFF_C
1789
  if (bfd_xcoff_text_align_power (abfd) != 0
1790
      && strcmp (bfd_section_name (section), ".text") == 0)
1791
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1792
  else if (bfd_xcoff_data_align_power (abfd) != 0
1793
      && strcmp (bfd_section_name (section), ".data") == 0)
1794
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1795
  else
1796
    {
1797
      int i;
1798
1799
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1800
  if (strcmp (bfd_section_name (section),
1801
        xcoff_dwsect_names[i].xcoff_name) == 0)
1802
    {
1803
      section->alignment_power = 0;
1804
      sclass = C_DWARF;
1805
      break;
1806
    }
1807
    }
1808
#endif
1809
1810
  /* Set up the section symbol.  */
1811
1.94M
  if (!_bfd_generic_new_section_hook (abfd, section))
1812
0
    return false;
1813
1814
  /* Allocate aux records for section symbols, to store size and
1815
     related info.
1816
1817
     @@ The 10 is a guess at a plausible maximum number of aux entries
1818
     (but shouldn't be a constant).  */
1819
1.94M
  amt = sizeof (combined_entry_type) * 10;
1820
1.94M
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1821
1.94M
  if (native == NULL)
1822
0
    return false;
1823
1824
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1825
     symbol information, since they'll be overridden by the BFD symbol
1826
     anyhow.  However, we do need to set the type and storage class,
1827
     in case this symbol winds up getting written out.  The value 0
1828
     for n_numaux is already correct.  */
1829
1830
1.94M
  native->is_sym = true;
1831
1.94M
  native->u.syment.n_type = T_NULL;
1832
1.94M
  native->u.syment.n_sclass = sclass;
1833
1834
1.94M
  coffsymbol (section->symbol)->native = native;
1835
1836
1.94M
  coff_set_custom_section_alignment (abfd, section,
1837
1.94M
             coff_section_alignment_table,
1838
1.94M
             coff_section_alignment_table_size);
1839
1840
1.94M
  return true;
1841
1.94M
}
coff-z8k.c:coff_new_section_hook
Line
Count
Source
1781
18.1M
{
1782
18.1M
  combined_entry_type *native;
1783
18.1M
  size_t amt;
1784
18.1M
  unsigned char sclass = C_STAT;
1785
1786
18.1M
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1787
1788
#ifdef RS6000COFF_C
1789
  if (bfd_xcoff_text_align_power (abfd) != 0
1790
      && strcmp (bfd_section_name (section), ".text") == 0)
1791
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1792
  else if (bfd_xcoff_data_align_power (abfd) != 0
1793
      && strcmp (bfd_section_name (section), ".data") == 0)
1794
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1795
  else
1796
    {
1797
      int i;
1798
1799
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1800
  if (strcmp (bfd_section_name (section),
1801
        xcoff_dwsect_names[i].xcoff_name) == 0)
1802
    {
1803
      section->alignment_power = 0;
1804
      sclass = C_DWARF;
1805
      break;
1806
    }
1807
    }
1808
#endif
1809
1810
  /* Set up the section symbol.  */
1811
18.1M
  if (!_bfd_generic_new_section_hook (abfd, section))
1812
0
    return false;
1813
1814
  /* Allocate aux records for section symbols, to store size and
1815
     related info.
1816
1817
     @@ The 10 is a guess at a plausible maximum number of aux entries
1818
     (but shouldn't be a constant).  */
1819
18.1M
  amt = sizeof (combined_entry_type) * 10;
1820
18.1M
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1821
18.1M
  if (native == NULL)
1822
0
    return false;
1823
1824
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1825
     symbol information, since they'll be overridden by the BFD symbol
1826
     anyhow.  However, we do need to set the type and storage class,
1827
     in case this symbol winds up getting written out.  The value 0
1828
     for n_numaux is already correct.  */
1829
1830
18.1M
  native->is_sym = true;
1831
18.1M
  native->u.syment.n_type = T_NULL;
1832
18.1M
  native->u.syment.n_sclass = sclass;
1833
1834
18.1M
  coffsymbol (section->symbol)->native = native;
1835
1836
18.1M
  coff_set_custom_section_alignment (abfd, section,
1837
18.1M
             coff_section_alignment_table,
1838
18.1M
             coff_section_alignment_table_size);
1839
1840
18.1M
  return true;
1841
18.1M
}
pe-arm-wince.c:coff_new_section_hook
Line
Count
Source
1781
90.7k
{
1782
90.7k
  combined_entry_type *native;
1783
90.7k
  size_t amt;
1784
90.7k
  unsigned char sclass = C_STAT;
1785
1786
90.7k
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1787
1788
#ifdef RS6000COFF_C
1789
  if (bfd_xcoff_text_align_power (abfd) != 0
1790
      && strcmp (bfd_section_name (section), ".text") == 0)
1791
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1792
  else if (bfd_xcoff_data_align_power (abfd) != 0
1793
      && strcmp (bfd_section_name (section), ".data") == 0)
1794
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1795
  else
1796
    {
1797
      int i;
1798
1799
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1800
  if (strcmp (bfd_section_name (section),
1801
        xcoff_dwsect_names[i].xcoff_name) == 0)
1802
    {
1803
      section->alignment_power = 0;
1804
      sclass = C_DWARF;
1805
      break;
1806
    }
1807
    }
1808
#endif
1809
1810
  /* Set up the section symbol.  */
1811
90.7k
  if (!_bfd_generic_new_section_hook (abfd, section))
1812
0
    return false;
1813
1814
  /* Allocate aux records for section symbols, to store size and
1815
     related info.
1816
1817
     @@ The 10 is a guess at a plausible maximum number of aux entries
1818
     (but shouldn't be a constant).  */
1819
90.7k
  amt = sizeof (combined_entry_type) * 10;
1820
90.7k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1821
90.7k
  if (native == NULL)
1822
0
    return false;
1823
1824
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1825
     symbol information, since they'll be overridden by the BFD symbol
1826
     anyhow.  However, we do need to set the type and storage class,
1827
     in case this symbol winds up getting written out.  The value 0
1828
     for n_numaux is already correct.  */
1829
1830
90.7k
  native->is_sym = true;
1831
90.7k
  native->u.syment.n_type = T_NULL;
1832
90.7k
  native->u.syment.n_sclass = sclass;
1833
1834
90.7k
  coffsymbol (section->symbol)->native = native;
1835
1836
90.7k
  coff_set_custom_section_alignment (abfd, section,
1837
90.7k
             coff_section_alignment_table,
1838
90.7k
             coff_section_alignment_table_size);
1839
1840
90.7k
  return true;
1841
90.7k
}
pe-arm.c:coff_new_section_hook
Line
Count
Source
1781
90.7k
{
1782
90.7k
  combined_entry_type *native;
1783
90.7k
  size_t amt;
1784
90.7k
  unsigned char sclass = C_STAT;
1785
1786
90.7k
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1787
1788
#ifdef RS6000COFF_C
1789
  if (bfd_xcoff_text_align_power (abfd) != 0
1790
      && strcmp (bfd_section_name (section), ".text") == 0)
1791
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1792
  else if (bfd_xcoff_data_align_power (abfd) != 0
1793
      && strcmp (bfd_section_name (section), ".data") == 0)
1794
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1795
  else
1796
    {
1797
      int i;
1798
1799
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1800
  if (strcmp (bfd_section_name (section),
1801
        xcoff_dwsect_names[i].xcoff_name) == 0)
1802
    {
1803
      section->alignment_power = 0;
1804
      sclass = C_DWARF;
1805
      break;
1806
    }
1807
    }
1808
#endif
1809
1810
  /* Set up the section symbol.  */
1811
90.7k
  if (!_bfd_generic_new_section_hook (abfd, section))
1812
0
    return false;
1813
1814
  /* Allocate aux records for section symbols, to store size and
1815
     related info.
1816
1817
     @@ The 10 is a guess at a plausible maximum number of aux entries
1818
     (but shouldn't be a constant).  */
1819
90.7k
  amt = sizeof (combined_entry_type) * 10;
1820
90.7k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1821
90.7k
  if (native == NULL)
1822
0
    return false;
1823
1824
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1825
     symbol information, since they'll be overridden by the BFD symbol
1826
     anyhow.  However, we do need to set the type and storage class,
1827
     in case this symbol winds up getting written out.  The value 0
1828
     for n_numaux is already correct.  */
1829
1830
90.7k
  native->is_sym = true;
1831
90.7k
  native->u.syment.n_type = T_NULL;
1832
90.7k
  native->u.syment.n_sclass = sclass;
1833
1834
90.7k
  coffsymbol (section->symbol)->native = native;
1835
1836
90.7k
  coff_set_custom_section_alignment (abfd, section,
1837
90.7k
             coff_section_alignment_table,
1838
90.7k
             coff_section_alignment_table_size);
1839
1840
90.7k
  return true;
1841
90.7k
}
pe-i386.c:coff_new_section_hook
Line
Count
Source
1781
195k
{
1782
195k
  combined_entry_type *native;
1783
195k
  size_t amt;
1784
195k
  unsigned char sclass = C_STAT;
1785
1786
195k
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1787
1788
#ifdef RS6000COFF_C
1789
  if (bfd_xcoff_text_align_power (abfd) != 0
1790
      && strcmp (bfd_section_name (section), ".text") == 0)
1791
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1792
  else if (bfd_xcoff_data_align_power (abfd) != 0
1793
      && strcmp (bfd_section_name (section), ".data") == 0)
1794
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1795
  else
1796
    {
1797
      int i;
1798
1799
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1800
  if (strcmp (bfd_section_name (section),
1801
        xcoff_dwsect_names[i].xcoff_name) == 0)
1802
    {
1803
      section->alignment_power = 0;
1804
      sclass = C_DWARF;
1805
      break;
1806
    }
1807
    }
1808
#endif
1809
1810
  /* Set up the section symbol.  */
1811
195k
  if (!_bfd_generic_new_section_hook (abfd, section))
1812
0
    return false;
1813
1814
  /* Allocate aux records for section symbols, to store size and
1815
     related info.
1816
1817
     @@ The 10 is a guess at a plausible maximum number of aux entries
1818
     (but shouldn't be a constant).  */
1819
195k
  amt = sizeof (combined_entry_type) * 10;
1820
195k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1821
195k
  if (native == NULL)
1822
0
    return false;
1823
1824
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1825
     symbol information, since they'll be overridden by the BFD symbol
1826
     anyhow.  However, we do need to set the type and storage class,
1827
     in case this symbol winds up getting written out.  The value 0
1828
     for n_numaux is already correct.  */
1829
1830
195k
  native->is_sym = true;
1831
195k
  native->u.syment.n_type = T_NULL;
1832
195k
  native->u.syment.n_sclass = sclass;
1833
1834
195k
  coffsymbol (section->symbol)->native = native;
1835
1836
195k
  coff_set_custom_section_alignment (abfd, section,
1837
195k
             coff_section_alignment_table,
1838
195k
             coff_section_alignment_table_size);
1839
1840
195k
  return true;
1841
195k
}
pe-mcore.c:coff_new_section_hook
Line
Count
Source
1781
220k
{
1782
220k
  combined_entry_type *native;
1783
220k
  size_t amt;
1784
220k
  unsigned char sclass = C_STAT;
1785
1786
220k
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1787
1788
#ifdef RS6000COFF_C
1789
  if (bfd_xcoff_text_align_power (abfd) != 0
1790
      && strcmp (bfd_section_name (section), ".text") == 0)
1791
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1792
  else if (bfd_xcoff_data_align_power (abfd) != 0
1793
      && strcmp (bfd_section_name (section), ".data") == 0)
1794
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1795
  else
1796
    {
1797
      int i;
1798
1799
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1800
  if (strcmp (bfd_section_name (section),
1801
        xcoff_dwsect_names[i].xcoff_name) == 0)
1802
    {
1803
      section->alignment_power = 0;
1804
      sclass = C_DWARF;
1805
      break;
1806
    }
1807
    }
1808
#endif
1809
1810
  /* Set up the section symbol.  */
1811
220k
  if (!_bfd_generic_new_section_hook (abfd, section))
1812
0
    return false;
1813
1814
  /* Allocate aux records for section symbols, to store size and
1815
     related info.
1816
1817
     @@ The 10 is a guess at a plausible maximum number of aux entries
1818
     (but shouldn't be a constant).  */
1819
220k
  amt = sizeof (combined_entry_type) * 10;
1820
220k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1821
220k
  if (native == NULL)
1822
0
    return false;
1823
1824
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1825
     symbol information, since they'll be overridden by the BFD symbol
1826
     anyhow.  However, we do need to set the type and storage class,
1827
     in case this symbol winds up getting written out.  The value 0
1828
     for n_numaux is already correct.  */
1829
1830
220k
  native->is_sym = true;
1831
220k
  native->u.syment.n_type = T_NULL;
1832
220k
  native->u.syment.n_sclass = sclass;
1833
1834
220k
  coffsymbol (section->symbol)->native = native;
1835
1836
220k
  coff_set_custom_section_alignment (abfd, section,
1837
220k
             coff_section_alignment_table,
1838
220k
             coff_section_alignment_table_size);
1839
1840
220k
  return true;
1841
220k
}
pe-sh.c:coff_new_section_hook
Line
Count
Source
1781
168k
{
1782
168k
  combined_entry_type *native;
1783
168k
  size_t amt;
1784
168k
  unsigned char sclass = C_STAT;
1785
1786
168k
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1787
1788
#ifdef RS6000COFF_C
1789
  if (bfd_xcoff_text_align_power (abfd) != 0
1790
      && strcmp (bfd_section_name (section), ".text") == 0)
1791
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1792
  else if (bfd_xcoff_data_align_power (abfd) != 0
1793
      && strcmp (bfd_section_name (section), ".data") == 0)
1794
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1795
  else
1796
    {
1797
      int i;
1798
1799
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1800
  if (strcmp (bfd_section_name (section),
1801
        xcoff_dwsect_names[i].xcoff_name) == 0)
1802
    {
1803
      section->alignment_power = 0;
1804
      sclass = C_DWARF;
1805
      break;
1806
    }
1807
    }
1808
#endif
1809
1810
  /* Set up the section symbol.  */
1811
168k
  if (!_bfd_generic_new_section_hook (abfd, section))
1812
0
    return false;
1813
1814
  /* Allocate aux records for section symbols, to store size and
1815
     related info.
1816
1817
     @@ The 10 is a guess at a plausible maximum number of aux entries
1818
     (but shouldn't be a constant).  */
1819
168k
  amt = sizeof (combined_entry_type) * 10;
1820
168k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1821
168k
  if (native == NULL)
1822
0
    return false;
1823
1824
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1825
     symbol information, since they'll be overridden by the BFD symbol
1826
     anyhow.  However, we do need to set the type and storage class,
1827
     in case this symbol winds up getting written out.  The value 0
1828
     for n_numaux is already correct.  */
1829
1830
168k
  native->is_sym = true;
1831
168k
  native->u.syment.n_type = T_NULL;
1832
168k
  native->u.syment.n_sclass = sclass;
1833
1834
168k
  coffsymbol (section->symbol)->native = native;
1835
1836
168k
  coff_set_custom_section_alignment (abfd, section,
1837
168k
             coff_section_alignment_table,
1838
168k
             coff_section_alignment_table_size);
1839
1840
168k
  return true;
1841
168k
}
pei-arm-wince.c:coff_new_section_hook
Line
Count
Source
1781
278k
{
1782
278k
  combined_entry_type *native;
1783
278k
  size_t amt;
1784
278k
  unsigned char sclass = C_STAT;
1785
1786
278k
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1787
1788
#ifdef RS6000COFF_C
1789
  if (bfd_xcoff_text_align_power (abfd) != 0
1790
      && strcmp (bfd_section_name (section), ".text") == 0)
1791
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1792
  else if (bfd_xcoff_data_align_power (abfd) != 0
1793
      && strcmp (bfd_section_name (section), ".data") == 0)
1794
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1795
  else
1796
    {
1797
      int i;
1798
1799
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1800
  if (strcmp (bfd_section_name (section),
1801
        xcoff_dwsect_names[i].xcoff_name) == 0)
1802
    {
1803
      section->alignment_power = 0;
1804
      sclass = C_DWARF;
1805
      break;
1806
    }
1807
    }
1808
#endif
1809
1810
  /* Set up the section symbol.  */
1811
278k
  if (!_bfd_generic_new_section_hook (abfd, section))
1812
0
    return false;
1813
1814
  /* Allocate aux records for section symbols, to store size and
1815
     related info.
1816
1817
     @@ The 10 is a guess at a plausible maximum number of aux entries
1818
     (but shouldn't be a constant).  */
1819
278k
  amt = sizeof (combined_entry_type) * 10;
1820
278k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1821
278k
  if (native == NULL)
1822
0
    return false;
1823
1824
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1825
     symbol information, since they'll be overridden by the BFD symbol
1826
     anyhow.  However, we do need to set the type and storage class,
1827
     in case this symbol winds up getting written out.  The value 0
1828
     for n_numaux is already correct.  */
1829
1830
278k
  native->is_sym = true;
1831
278k
  native->u.syment.n_type = T_NULL;
1832
278k
  native->u.syment.n_sclass = sclass;
1833
1834
278k
  coffsymbol (section->symbol)->native = native;
1835
1836
278k
  coff_set_custom_section_alignment (abfd, section,
1837
278k
             coff_section_alignment_table,
1838
278k
             coff_section_alignment_table_size);
1839
1840
278k
  return true;
1841
278k
}
pei-arm.c:coff_new_section_hook
Line
Count
Source
1781
396k
{
1782
396k
  combined_entry_type *native;
1783
396k
  size_t amt;
1784
396k
  unsigned char sclass = C_STAT;
1785
1786
396k
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1787
1788
#ifdef RS6000COFF_C
1789
  if (bfd_xcoff_text_align_power (abfd) != 0
1790
      && strcmp (bfd_section_name (section), ".text") == 0)
1791
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1792
  else if (bfd_xcoff_data_align_power (abfd) != 0
1793
      && strcmp (bfd_section_name (section), ".data") == 0)
1794
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1795
  else
1796
    {
1797
      int i;
1798
1799
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1800
  if (strcmp (bfd_section_name (section),
1801
        xcoff_dwsect_names[i].xcoff_name) == 0)
1802
    {
1803
      section->alignment_power = 0;
1804
      sclass = C_DWARF;
1805
      break;
1806
    }
1807
    }
1808
#endif
1809
1810
  /* Set up the section symbol.  */
1811
396k
  if (!_bfd_generic_new_section_hook (abfd, section))
1812
0
    return false;
1813
1814
  /* Allocate aux records for section symbols, to store size and
1815
     related info.
1816
1817
     @@ The 10 is a guess at a plausible maximum number of aux entries
1818
     (but shouldn't be a constant).  */
1819
396k
  amt = sizeof (combined_entry_type) * 10;
1820
396k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1821
396k
  if (native == NULL)
1822
0
    return false;
1823
1824
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1825
     symbol information, since they'll be overridden by the BFD symbol
1826
     anyhow.  However, we do need to set the type and storage class,
1827
     in case this symbol winds up getting written out.  The value 0
1828
     for n_numaux is already correct.  */
1829
1830
396k
  native->is_sym = true;
1831
396k
  native->u.syment.n_type = T_NULL;
1832
396k
  native->u.syment.n_sclass = sclass;
1833
1834
396k
  coffsymbol (section->symbol)->native = native;
1835
1836
396k
  coff_set_custom_section_alignment (abfd, section,
1837
396k
             coff_section_alignment_table,
1838
396k
             coff_section_alignment_table_size);
1839
1840
396k
  return true;
1841
396k
}
pei-mcore.c:coff_new_section_hook
Line
Count
Source
1781
265k
{
1782
265k
  combined_entry_type *native;
1783
265k
  size_t amt;
1784
265k
  unsigned char sclass = C_STAT;
1785
1786
265k
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1787
1788
#ifdef RS6000COFF_C
1789
  if (bfd_xcoff_text_align_power (abfd) != 0
1790
      && strcmp (bfd_section_name (section), ".text") == 0)
1791
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1792
  else if (bfd_xcoff_data_align_power (abfd) != 0
1793
      && strcmp (bfd_section_name (section), ".data") == 0)
1794
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1795
  else
1796
    {
1797
      int i;
1798
1799
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1800
  if (strcmp (bfd_section_name (section),
1801
        xcoff_dwsect_names[i].xcoff_name) == 0)
1802
    {
1803
      section->alignment_power = 0;
1804
      sclass = C_DWARF;
1805
      break;
1806
    }
1807
    }
1808
#endif
1809
1810
  /* Set up the section symbol.  */
1811
265k
  if (!_bfd_generic_new_section_hook (abfd, section))
1812
0
    return false;
1813
1814
  /* Allocate aux records for section symbols, to store size and
1815
     related info.
1816
1817
     @@ The 10 is a guess at a plausible maximum number of aux entries
1818
     (but shouldn't be a constant).  */
1819
265k
  amt = sizeof (combined_entry_type) * 10;
1820
265k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1821
265k
  if (native == NULL)
1822
0
    return false;
1823
1824
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1825
     symbol information, since they'll be overridden by the BFD symbol
1826
     anyhow.  However, we do need to set the type and storage class,
1827
     in case this symbol winds up getting written out.  The value 0
1828
     for n_numaux is already correct.  */
1829
1830
265k
  native->is_sym = true;
1831
265k
  native->u.syment.n_type = T_NULL;
1832
265k
  native->u.syment.n_sclass = sclass;
1833
1834
265k
  coffsymbol (section->symbol)->native = native;
1835
1836
265k
  coff_set_custom_section_alignment (abfd, section,
1837
265k
             coff_section_alignment_table,
1838
265k
             coff_section_alignment_table_size);
1839
1840
265k
  return true;
1841
265k
}
pei-sh.c:coff_new_section_hook
Line
Count
Source
1781
322k
{
1782
322k
  combined_entry_type *native;
1783
322k
  size_t amt;
1784
322k
  unsigned char sclass = C_STAT;
1785
1786
322k
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1787
1788
#ifdef RS6000COFF_C
1789
  if (bfd_xcoff_text_align_power (abfd) != 0
1790
      && strcmp (bfd_section_name (section), ".text") == 0)
1791
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1792
  else if (bfd_xcoff_data_align_power (abfd) != 0
1793
      && strcmp (bfd_section_name (section), ".data") == 0)
1794
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1795
  else
1796
    {
1797
      int i;
1798
1799
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1800
  if (strcmp (bfd_section_name (section),
1801
        xcoff_dwsect_names[i].xcoff_name) == 0)
1802
    {
1803
      section->alignment_power = 0;
1804
      sclass = C_DWARF;
1805
      break;
1806
    }
1807
    }
1808
#endif
1809
1810
  /* Set up the section symbol.  */
1811
322k
  if (!_bfd_generic_new_section_hook (abfd, section))
1812
0
    return false;
1813
1814
  /* Allocate aux records for section symbols, to store size and
1815
     related info.
1816
1817
     @@ The 10 is a guess at a plausible maximum number of aux entries
1818
     (but shouldn't be a constant).  */
1819
322k
  amt = sizeof (combined_entry_type) * 10;
1820
322k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1821
322k
  if (native == NULL)
1822
0
    return false;
1823
1824
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1825
     symbol information, since they'll be overridden by the BFD symbol
1826
     anyhow.  However, we do need to set the type and storage class,
1827
     in case this symbol winds up getting written out.  The value 0
1828
     for n_numaux is already correct.  */
1829
1830
322k
  native->is_sym = true;
1831
322k
  native->u.syment.n_type = T_NULL;
1832
322k
  native->u.syment.n_sclass = sclass;
1833
1834
322k
  coffsymbol (section->symbol)->native = native;
1835
1836
322k
  coff_set_custom_section_alignment (abfd, section,
1837
322k
             coff_section_alignment_table,
1838
322k
             coff_section_alignment_table_size);
1839
1840
322k
  return true;
1841
322k
}
1842
1843
#ifdef COFF_ALIGN_IN_SECTION_HEADER
1844
1845
/* Set the alignment of a BFD section.  */
1846
1847
static void
1848
coff_set_alignment_hook (bfd * abfd ATTRIBUTE_UNUSED,
1849
       asection * section,
1850
       void * scnhdr)
1851
14.9M
{
1852
14.9M
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1853
14.9M
  unsigned int i;
1854
1855
14.9M
#ifdef COFF_DECODE_ALIGNMENT
1856
14.9M
  i = COFF_DECODE_ALIGNMENT(hdr->s_flags);
1857
14.9M
#endif
1858
14.9M
  section->alignment_power = i;
1859
1860
#ifdef coff_set_section_load_page
1861
13.0M
  coff_set_section_load_page (section, hdr->s_page);
1862
#endif
1863
14.9M
}
Unexecuted instantiation: coff-tic4x.c:coff_set_alignment_hook
coff-tic54x.c:coff_set_alignment_hook
Line
Count
Source
1851
13.0M
{
1852
13.0M
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1853
13.0M
  unsigned int i;
1854
1855
13.0M
#ifdef COFF_DECODE_ALIGNMENT
1856
13.0M
  i = COFF_DECODE_ALIGNMENT(hdr->s_flags);
1857
13.0M
#endif
1858
13.0M
  section->alignment_power = i;
1859
1860
13.0M
#ifdef coff_set_section_load_page
1861
13.0M
  coff_set_section_load_page (section, hdr->s_page);
1862
13.0M
#endif
1863
13.0M
}
coff-z80.c:coff_set_alignment_hook
Line
Count
Source
1851
1.94M
{
1852
1.94M
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1853
1.94M
  unsigned int i;
1854
1855
1.94M
#ifdef COFF_DECODE_ALIGNMENT
1856
1.94M
  i = COFF_DECODE_ALIGNMENT(hdr->s_flags);
1857
1.94M
#endif
1858
1.94M
  section->alignment_power = i;
1859
1860
#ifdef coff_set_section_load_page
1861
  coff_set_section_load_page (section, hdr->s_page);
1862
#endif
1863
1.94M
}
1864
1865
#else /* ! COFF_ALIGN_IN_SECTION_HEADER */
1866
#ifdef COFF_WITH_PE
1867
1868
static void
1869
coff_set_alignment_hook (bfd * abfd ATTRIBUTE_UNUSED,
1870
       asection * section,
1871
       void * scnhdr)
1872
5.50M
{
1873
5.50M
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1874
5.50M
  size_t amt;
1875
5.50M
  unsigned int alignment_power_const
1876
5.50M
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1877
1878
5.50M
  switch (alignment_power_const)
1879
5.50M
    {
1880
156k
    case IMAGE_SCN_ALIGN_8192BYTES:
1881
193k
    case IMAGE_SCN_ALIGN_4096BYTES:
1882
299k
    case IMAGE_SCN_ALIGN_2048BYTES:
1883
337k
    case IMAGE_SCN_ALIGN_1024BYTES:
1884
444k
    case IMAGE_SCN_ALIGN_512BYTES:
1885
501k
    case IMAGE_SCN_ALIGN_256BYTES:
1886
601k
    case IMAGE_SCN_ALIGN_128BYTES:
1887
692k
    case IMAGE_SCN_ALIGN_64BYTES:
1888
869k
    case IMAGE_SCN_ALIGN_32BYTES:
1889
973k
    case IMAGE_SCN_ALIGN_16BYTES:
1890
1.10M
    case IMAGE_SCN_ALIGN_8BYTES:
1891
1.28M
    case IMAGE_SCN_ALIGN_4BYTES:
1892
1.61M
    case IMAGE_SCN_ALIGN_2BYTES:
1893
1.71M
    case IMAGE_SCN_ALIGN_1BYTES:
1894
1.71M
      section->alignment_power
1895
1.71M
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1896
1.71M
      break;
1897
3.78M
    default:
1898
3.78M
      break;
1899
5.50M
    }
1900
1901
  /* In a PE image file, the s_paddr field holds the virtual size of a
1902
     section, while the s_size field holds the raw size.  We also keep
1903
     the original section flag value, since not every bit can be
1904
     mapped onto a generic BFD section bit.  */
1905
5.50M
  if (coff_section_data (abfd, section) == NULL)
1906
5.50M
    {
1907
5.50M
      amt = sizeof (struct coff_section_tdata);
1908
5.50M
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1909
5.50M
      if (section->used_by_bfd == NULL)
1910
  /* FIXME: Return error.  */
1911
0
  abort ();
1912
5.50M
    }
1913
1914
5.50M
  if (pei_section_data (abfd, section) == NULL)
1915
5.50M
    {
1916
5.50M
      amt = sizeof (struct pei_section_tdata);
1917
5.50M
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1918
5.50M
      if (coff_section_data (abfd, section)->tdata == NULL)
1919
  /* FIXME: Return error.  */
1920
0
  abort ();
1921
5.50M
    }
1922
5.50M
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1923
5.50M
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1924
1925
5.50M
  section->lma = hdr->s_vaddr;
1926
1927
  /* Check for extended relocs.  */
1928
5.50M
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1929
937k
    {
1930
937k
      struct external_reloc dst;
1931
937k
      struct internal_reloc n;
1932
937k
      file_ptr oldpos = bfd_tell (abfd);
1933
937k
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1934
1935
937k
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1936
0
  return;
1937
937k
      if (bfd_read (& dst, relsz, abfd) != relsz)
1938
613k
  return;
1939
1940
324k
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1941
324k
      if (bfd_seek (abfd, oldpos, 0) != 0)
1942
0
  return;
1943
324k
      if (n.r_vaddr < 0x10000)
1944
99.7k
  {
1945
99.7k
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1946
99.7k
    bfd_set_error (bfd_error_bad_value);
1947
99.7k
    return;
1948
99.7k
  }
1949
224k
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1950
224k
      section->rel_filepos += relsz;
1951
224k
    }
1952
4.56M
  else if (hdr->s_nreloc == 0xffff)
1953
48.2k
    _bfd_error_handler
1954
48.2k
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1955
48.2k
       abfd);
1956
5.50M
}
pei-i386.c:coff_set_alignment_hook
Line
Count
Source
1872
452k
{
1873
452k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1874
452k
  size_t amt;
1875
452k
  unsigned int alignment_power_const
1876
452k
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1877
1878
452k
  switch (alignment_power_const)
1879
452k
    {
1880
11.3k
    case IMAGE_SCN_ALIGN_8192BYTES:
1881
13.1k
    case IMAGE_SCN_ALIGN_4096BYTES:
1882
17.8k
    case IMAGE_SCN_ALIGN_2048BYTES:
1883
19.0k
    case IMAGE_SCN_ALIGN_1024BYTES:
1884
30.5k
    case IMAGE_SCN_ALIGN_512BYTES:
1885
35.5k
    case IMAGE_SCN_ALIGN_256BYTES:
1886
44.1k
    case IMAGE_SCN_ALIGN_128BYTES:
1887
50.3k
    case IMAGE_SCN_ALIGN_64BYTES:
1888
63.8k
    case IMAGE_SCN_ALIGN_32BYTES:
1889
72.1k
    case IMAGE_SCN_ALIGN_16BYTES:
1890
79.9k
    case IMAGE_SCN_ALIGN_8BYTES:
1891
97.8k
    case IMAGE_SCN_ALIGN_4BYTES:
1892
121k
    case IMAGE_SCN_ALIGN_2BYTES:
1893
129k
    case IMAGE_SCN_ALIGN_1BYTES:
1894
129k
      section->alignment_power
1895
129k
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1896
129k
      break;
1897
322k
    default:
1898
322k
      break;
1899
452k
    }
1900
1901
  /* In a PE image file, the s_paddr field holds the virtual size of a
1902
     section, while the s_size field holds the raw size.  We also keep
1903
     the original section flag value, since not every bit can be
1904
     mapped onto a generic BFD section bit.  */
1905
452k
  if (coff_section_data (abfd, section) == NULL)
1906
452k
    {
1907
452k
      amt = sizeof (struct coff_section_tdata);
1908
452k
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1909
452k
      if (section->used_by_bfd == NULL)
1910
  /* FIXME: Return error.  */
1911
0
  abort ();
1912
452k
    }
1913
1914
452k
  if (pei_section_data (abfd, section) == NULL)
1915
452k
    {
1916
452k
      amt = sizeof (struct pei_section_tdata);
1917
452k
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1918
452k
      if (coff_section_data (abfd, section)->tdata == NULL)
1919
  /* FIXME: Return error.  */
1920
0
  abort ();
1921
452k
    }
1922
452k
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1923
452k
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1924
1925
452k
  section->lma = hdr->s_vaddr;
1926
1927
  /* Check for extended relocs.  */
1928
452k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1929
68.3k
    {
1930
68.3k
      struct external_reloc dst;
1931
68.3k
      struct internal_reloc n;
1932
68.3k
      file_ptr oldpos = bfd_tell (abfd);
1933
68.3k
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1934
1935
68.3k
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1936
0
  return;
1937
68.3k
      if (bfd_read (& dst, relsz, abfd) != relsz)
1938
40.7k
  return;
1939
1940
27.5k
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1941
27.5k
      if (bfd_seek (abfd, oldpos, 0) != 0)
1942
0
  return;
1943
27.5k
      if (n.r_vaddr < 0x10000)
1944
7.48k
  {
1945
7.48k
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1946
7.48k
    bfd_set_error (bfd_error_bad_value);
1947
7.48k
    return;
1948
7.48k
  }
1949
20.0k
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1950
20.0k
      section->rel_filepos += relsz;
1951
20.0k
    }
1952
384k
  else if (hdr->s_nreloc == 0xffff)
1953
0
    _bfd_error_handler
1954
0
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1955
0
       abfd);
1956
452k
}
pe-x86_64.c:coff_set_alignment_hook
Line
Count
Source
1872
1.19M
{
1873
1.19M
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1874
1.19M
  size_t amt;
1875
1.19M
  unsigned int alignment_power_const
1876
1.19M
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1877
1878
1.19M
  switch (alignment_power_const)
1879
1.19M
    {
1880
7.46k
    case IMAGE_SCN_ALIGN_8192BYTES:
1881
12.8k
    case IMAGE_SCN_ALIGN_4096BYTES:
1882
25.7k
    case IMAGE_SCN_ALIGN_2048BYTES:
1883
30.2k
    case IMAGE_SCN_ALIGN_1024BYTES:
1884
36.5k
    case IMAGE_SCN_ALIGN_512BYTES:
1885
44.8k
    case IMAGE_SCN_ALIGN_256BYTES:
1886
49.9k
    case IMAGE_SCN_ALIGN_128BYTES:
1887
61.7k
    case IMAGE_SCN_ALIGN_64BYTES:
1888
89.7k
    case IMAGE_SCN_ALIGN_32BYTES:
1889
103k
    case IMAGE_SCN_ALIGN_16BYTES:
1890
116k
    case IMAGE_SCN_ALIGN_8BYTES:
1891
155k
    case IMAGE_SCN_ALIGN_4BYTES:
1892
190k
    case IMAGE_SCN_ALIGN_2BYTES:
1893
199k
    case IMAGE_SCN_ALIGN_1BYTES:
1894
199k
      section->alignment_power
1895
199k
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1896
199k
      break;
1897
997k
    default:
1898
997k
      break;
1899
1.19M
    }
1900
1901
  /* In a PE image file, the s_paddr field holds the virtual size of a
1902
     section, while the s_size field holds the raw size.  We also keep
1903
     the original section flag value, since not every bit can be
1904
     mapped onto a generic BFD section bit.  */
1905
1.19M
  if (coff_section_data (abfd, section) == NULL)
1906
1.19M
    {
1907
1.19M
      amt = sizeof (struct coff_section_tdata);
1908
1.19M
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1909
1.19M
      if (section->used_by_bfd == NULL)
1910
  /* FIXME: Return error.  */
1911
0
  abort ();
1912
1.19M
    }
1913
1914
1.19M
  if (pei_section_data (abfd, section) == NULL)
1915
1.19M
    {
1916
1.19M
      amt = sizeof (struct pei_section_tdata);
1917
1.19M
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1918
1.19M
      if (coff_section_data (abfd, section)->tdata == NULL)
1919
  /* FIXME: Return error.  */
1920
0
  abort ();
1921
1.19M
    }
1922
1.19M
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1923
1.19M
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1924
1925
1.19M
  section->lma = hdr->s_vaddr;
1926
1927
  /* Check for extended relocs.  */
1928
1.19M
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1929
117k
    {
1930
117k
      struct external_reloc dst;
1931
117k
      struct internal_reloc n;
1932
117k
      file_ptr oldpos = bfd_tell (abfd);
1933
117k
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1934
1935
117k
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1936
0
  return;
1937
117k
      if (bfd_read (& dst, relsz, abfd) != relsz)
1938
81.8k
  return;
1939
1940
35.1k
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1941
35.1k
      if (bfd_seek (abfd, oldpos, 0) != 0)
1942
0
  return;
1943
35.1k
      if (n.r_vaddr < 0x10000)
1944
4.82k
  {
1945
4.82k
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1946
4.82k
    bfd_set_error (bfd_error_bad_value);
1947
4.82k
    return;
1948
4.82k
  }
1949
30.3k
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1950
30.3k
      section->rel_filepos += relsz;
1951
30.3k
    }
1952
1.07M
  else if (hdr->s_nreloc == 0xffff)
1953
21.9k
    _bfd_error_handler
1954
21.9k
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1955
21.9k
       abfd);
1956
1.19M
}
pei-x86_64.c:coff_set_alignment_hook
Line
Count
Source
1872
432k
{
1873
432k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1874
432k
  size_t amt;
1875
432k
  unsigned int alignment_power_const
1876
432k
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1877
1878
432k
  switch (alignment_power_const)
1879
432k
    {
1880
8.58k
    case IMAGE_SCN_ALIGN_8192BYTES:
1881
11.3k
    case IMAGE_SCN_ALIGN_4096BYTES:
1882
15.7k
    case IMAGE_SCN_ALIGN_2048BYTES:
1883
18.7k
    case IMAGE_SCN_ALIGN_1024BYTES:
1884
38.0k
    case IMAGE_SCN_ALIGN_512BYTES:
1885
39.4k
    case IMAGE_SCN_ALIGN_256BYTES:
1886
43.8k
    case IMAGE_SCN_ALIGN_128BYTES:
1887
50.9k
    case IMAGE_SCN_ALIGN_64BYTES:
1888
59.6k
    case IMAGE_SCN_ALIGN_32BYTES:
1889
77.1k
    case IMAGE_SCN_ALIGN_16BYTES:
1890
81.6k
    case IMAGE_SCN_ALIGN_8BYTES:
1891
90.3k
    case IMAGE_SCN_ALIGN_4BYTES:
1892
119k
    case IMAGE_SCN_ALIGN_2BYTES:
1893
139k
    case IMAGE_SCN_ALIGN_1BYTES:
1894
139k
      section->alignment_power
1895
139k
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1896
139k
      break;
1897
293k
    default:
1898
293k
      break;
1899
432k
    }
1900
1901
  /* In a PE image file, the s_paddr field holds the virtual size of a
1902
     section, while the s_size field holds the raw size.  We also keep
1903
     the original section flag value, since not every bit can be
1904
     mapped onto a generic BFD section bit.  */
1905
432k
  if (coff_section_data (abfd, section) == NULL)
1906
432k
    {
1907
432k
      amt = sizeof (struct coff_section_tdata);
1908
432k
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1909
432k
      if (section->used_by_bfd == NULL)
1910
  /* FIXME: Return error.  */
1911
0
  abort ();
1912
432k
    }
1913
1914
432k
  if (pei_section_data (abfd, section) == NULL)
1915
432k
    {
1916
432k
      amt = sizeof (struct pei_section_tdata);
1917
432k
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1918
432k
      if (coff_section_data (abfd, section)->tdata == NULL)
1919
  /* FIXME: Return error.  */
1920
0
  abort ();
1921
432k
    }
1922
432k
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1923
432k
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1924
1925
432k
  section->lma = hdr->s_vaddr;
1926
1927
  /* Check for extended relocs.  */
1928
432k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1929
57.2k
    {
1930
57.2k
      struct external_reloc dst;
1931
57.2k
      struct internal_reloc n;
1932
57.2k
      file_ptr oldpos = bfd_tell (abfd);
1933
57.2k
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1934
1935
57.2k
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1936
0
  return;
1937
57.2k
      if (bfd_read (& dst, relsz, abfd) != relsz)
1938
30.6k
  return;
1939
1940
26.5k
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1941
26.5k
      if (bfd_seek (abfd, oldpos, 0) != 0)
1942
0
  return;
1943
26.5k
      if (n.r_vaddr < 0x10000)
1944
5.44k
  {
1945
5.44k
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1946
5.44k
    bfd_set_error (bfd_error_bad_value);
1947
5.44k
    return;
1948
5.44k
  }
1949
21.1k
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1950
21.1k
      section->rel_filepos += relsz;
1951
21.1k
    }
1952
375k
  else if (hdr->s_nreloc == 0xffff)
1953
0
    _bfd_error_handler
1954
0
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1955
0
       abfd);
1956
432k
}
pe-aarch64.c:coff_set_alignment_hook
Line
Count
Source
1872
276k
{
1873
276k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1874
276k
  size_t amt;
1875
276k
  unsigned int alignment_power_const
1876
276k
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1877
1878
276k
  switch (alignment_power_const)
1879
276k
    {
1880
5.90k
    case IMAGE_SCN_ALIGN_8192BYTES:
1881
7.85k
    case IMAGE_SCN_ALIGN_4096BYTES:
1882
9.64k
    case IMAGE_SCN_ALIGN_2048BYTES:
1883
11.1k
    case IMAGE_SCN_ALIGN_1024BYTES:
1884
15.3k
    case IMAGE_SCN_ALIGN_512BYTES:
1885
17.8k
    case IMAGE_SCN_ALIGN_256BYTES:
1886
22.1k
    case IMAGE_SCN_ALIGN_128BYTES:
1887
31.4k
    case IMAGE_SCN_ALIGN_64BYTES:
1888
36.6k
    case IMAGE_SCN_ALIGN_32BYTES:
1889
39.1k
    case IMAGE_SCN_ALIGN_16BYTES:
1890
42.6k
    case IMAGE_SCN_ALIGN_8BYTES:
1891
47.8k
    case IMAGE_SCN_ALIGN_4BYTES:
1892
57.3k
    case IMAGE_SCN_ALIGN_2BYTES:
1893
61.0k
    case IMAGE_SCN_ALIGN_1BYTES:
1894
61.0k
      section->alignment_power
1895
61.0k
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1896
61.0k
      break;
1897
214k
    default:
1898
214k
      break;
1899
276k
    }
1900
1901
  /* In a PE image file, the s_paddr field holds the virtual size of a
1902
     section, while the s_size field holds the raw size.  We also keep
1903
     the original section flag value, since not every bit can be
1904
     mapped onto a generic BFD section bit.  */
1905
276k
  if (coff_section_data (abfd, section) == NULL)
1906
276k
    {
1907
276k
      amt = sizeof (struct coff_section_tdata);
1908
276k
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1909
276k
      if (section->used_by_bfd == NULL)
1910
  /* FIXME: Return error.  */
1911
0
  abort ();
1912
276k
    }
1913
1914
276k
  if (pei_section_data (abfd, section) == NULL)
1915
276k
    {
1916
276k
      amt = sizeof (struct pei_section_tdata);
1917
276k
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1918
276k
      if (coff_section_data (abfd, section)->tdata == NULL)
1919
  /* FIXME: Return error.  */
1920
0
  abort ();
1921
276k
    }
1922
276k
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1923
276k
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1924
1925
276k
  section->lma = hdr->s_vaddr;
1926
1927
  /* Check for extended relocs.  */
1928
276k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1929
39.6k
    {
1930
39.6k
      struct external_reloc dst;
1931
39.6k
      struct internal_reloc n;
1932
39.6k
      file_ptr oldpos = bfd_tell (abfd);
1933
39.6k
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1934
1935
39.6k
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1936
0
  return;
1937
39.6k
      if (bfd_read (& dst, relsz, abfd) != relsz)
1938
26.1k
  return;
1939
1940
13.4k
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1941
13.4k
      if (bfd_seek (abfd, oldpos, 0) != 0)
1942
0
  return;
1943
13.4k
      if (n.r_vaddr < 0x10000)
1944
3.59k
  {
1945
3.59k
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1946
3.59k
    bfd_set_error (bfd_error_bad_value);
1947
3.59k
    return;
1948
3.59k
  }
1949
9.88k
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1950
9.88k
      section->rel_filepos += relsz;
1951
9.88k
    }
1952
236k
  else if (hdr->s_nreloc == 0xffff)
1953
3.89k
    _bfd_error_handler
1954
3.89k
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1955
3.89k
       abfd);
1956
276k
}
pei-aarch64.c:coff_set_alignment_hook
Line
Count
Source
1872
364k
{
1873
364k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1874
364k
  size_t amt;
1875
364k
  unsigned int alignment_power_const
1876
364k
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1877
1878
364k
  switch (alignment_power_const)
1879
364k
    {
1880
10.5k
    case IMAGE_SCN_ALIGN_8192BYTES:
1881
14.6k
    case IMAGE_SCN_ALIGN_4096BYTES:
1882
18.4k
    case IMAGE_SCN_ALIGN_2048BYTES:
1883
19.5k
    case IMAGE_SCN_ALIGN_1024BYTES:
1884
25.6k
    case IMAGE_SCN_ALIGN_512BYTES:
1885
27.2k
    case IMAGE_SCN_ALIGN_256BYTES:
1886
41.3k
    case IMAGE_SCN_ALIGN_128BYTES:
1887
43.4k
    case IMAGE_SCN_ALIGN_64BYTES:
1888
58.3k
    case IMAGE_SCN_ALIGN_32BYTES:
1889
63.0k
    case IMAGE_SCN_ALIGN_16BYTES:
1890
68.6k
    case IMAGE_SCN_ALIGN_8BYTES:
1891
75.1k
    case IMAGE_SCN_ALIGN_4BYTES:
1892
99.1k
    case IMAGE_SCN_ALIGN_2BYTES:
1893
103k
    case IMAGE_SCN_ALIGN_1BYTES:
1894
103k
      section->alignment_power
1895
103k
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1896
103k
      break;
1897
261k
    default:
1898
261k
      break;
1899
364k
    }
1900
1901
  /* In a PE image file, the s_paddr field holds the virtual size of a
1902
     section, while the s_size field holds the raw size.  We also keep
1903
     the original section flag value, since not every bit can be
1904
     mapped onto a generic BFD section bit.  */
1905
364k
  if (coff_section_data (abfd, section) == NULL)
1906
364k
    {
1907
364k
      amt = sizeof (struct coff_section_tdata);
1908
364k
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1909
364k
      if (section->used_by_bfd == NULL)
1910
  /* FIXME: Return error.  */
1911
0
  abort ();
1912
364k
    }
1913
1914
364k
  if (pei_section_data (abfd, section) == NULL)
1915
364k
    {
1916
364k
      amt = sizeof (struct pei_section_tdata);
1917
364k
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1918
364k
      if (coff_section_data (abfd, section)->tdata == NULL)
1919
  /* FIXME: Return error.  */
1920
0
  abort ();
1921
364k
    }
1922
364k
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1923
364k
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1924
1925
364k
  section->lma = hdr->s_vaddr;
1926
1927
  /* Check for extended relocs.  */
1928
364k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1929
66.8k
    {
1930
66.8k
      struct external_reloc dst;
1931
66.8k
      struct internal_reloc n;
1932
66.8k
      file_ptr oldpos = bfd_tell (abfd);
1933
66.8k
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1934
1935
66.8k
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1936
0
  return;
1937
66.8k
      if (bfd_read (& dst, relsz, abfd) != relsz)
1938
28.6k
  return;
1939
1940
38.1k
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1941
38.1k
      if (bfd_seek (abfd, oldpos, 0) != 0)
1942
0
  return;
1943
38.1k
      if (n.r_vaddr < 0x10000)
1944
27.4k
  {
1945
27.4k
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1946
27.4k
    bfd_set_error (bfd_error_bad_value);
1947
27.4k
    return;
1948
27.4k
  }
1949
10.7k
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1950
10.7k
      section->rel_filepos += relsz;
1951
10.7k
    }
1952
297k
  else if (hdr->s_nreloc == 0xffff)
1953
0
    _bfd_error_handler
1954
0
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1955
0
       abfd);
1956
364k
}
pei-ia64.c:coff_set_alignment_hook
Line
Count
Source
1872
310k
{
1873
310k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1874
310k
  size_t amt;
1875
310k
  unsigned int alignment_power_const
1876
310k
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1877
1878
310k
  switch (alignment_power_const)
1879
310k
    {
1880
13.2k
    case IMAGE_SCN_ALIGN_8192BYTES:
1881
15.2k
    case IMAGE_SCN_ALIGN_4096BYTES:
1882
24.5k
    case IMAGE_SCN_ALIGN_2048BYTES:
1883
26.1k
    case IMAGE_SCN_ALIGN_1024BYTES:
1884
33.0k
    case IMAGE_SCN_ALIGN_512BYTES:
1885
38.1k
    case IMAGE_SCN_ALIGN_256BYTES:
1886
48.2k
    case IMAGE_SCN_ALIGN_128BYTES:
1887
53.6k
    case IMAGE_SCN_ALIGN_64BYTES:
1888
64.3k
    case IMAGE_SCN_ALIGN_32BYTES:
1889
69.5k
    case IMAGE_SCN_ALIGN_16BYTES:
1890
79.0k
    case IMAGE_SCN_ALIGN_8BYTES:
1891
90.6k
    case IMAGE_SCN_ALIGN_4BYTES:
1892
116k
    case IMAGE_SCN_ALIGN_2BYTES:
1893
121k
    case IMAGE_SCN_ALIGN_1BYTES:
1894
121k
      section->alignment_power
1895
121k
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1896
121k
      break;
1897
188k
    default:
1898
188k
      break;
1899
310k
    }
1900
1901
  /* In a PE image file, the s_paddr field holds the virtual size of a
1902
     section, while the s_size field holds the raw size.  We also keep
1903
     the original section flag value, since not every bit can be
1904
     mapped onto a generic BFD section bit.  */
1905
310k
  if (coff_section_data (abfd, section) == NULL)
1906
310k
    {
1907
310k
      amt = sizeof (struct coff_section_tdata);
1908
310k
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1909
310k
      if (section->used_by_bfd == NULL)
1910
  /* FIXME: Return error.  */
1911
0
  abort ();
1912
310k
    }
1913
1914
310k
  if (pei_section_data (abfd, section) == NULL)
1915
310k
    {
1916
310k
      amt = sizeof (struct pei_section_tdata);
1917
310k
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1918
310k
      if (coff_section_data (abfd, section)->tdata == NULL)
1919
  /* FIXME: Return error.  */
1920
0
  abort ();
1921
310k
    }
1922
310k
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1923
310k
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1924
1925
310k
  section->lma = hdr->s_vaddr;
1926
1927
  /* Check for extended relocs.  */
1928
310k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1929
54.4k
    {
1930
54.4k
      struct external_reloc dst;
1931
54.4k
      struct internal_reloc n;
1932
54.4k
      file_ptr oldpos = bfd_tell (abfd);
1933
54.4k
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1934
1935
54.4k
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1936
0
  return;
1937
54.4k
      if (bfd_read (& dst, relsz, abfd) != relsz)
1938
38.3k
  return;
1939
1940
16.0k
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1941
16.0k
      if (bfd_seek (abfd, oldpos, 0) != 0)
1942
0
  return;
1943
16.0k
      if (n.r_vaddr < 0x10000)
1944
4.31k
  {
1945
4.31k
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1946
4.31k
    bfd_set_error (bfd_error_bad_value);
1947
4.31k
    return;
1948
4.31k
  }
1949
11.7k
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1950
11.7k
      section->rel_filepos += relsz;
1951
11.7k
    }
1952
255k
  else if (hdr->s_nreloc == 0xffff)
1953
0
    _bfd_error_handler
1954
0
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1955
0
       abfd);
1956
310k
}
pei-loongarch64.c:coff_set_alignment_hook
Line
Count
Source
1872
307k
{
1873
307k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1874
307k
  size_t amt;
1875
307k
  unsigned int alignment_power_const
1876
307k
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1877
1878
307k
  switch (alignment_power_const)
1879
307k
    {
1880
14.4k
    case IMAGE_SCN_ALIGN_8192BYTES:
1881
15.7k
    case IMAGE_SCN_ALIGN_4096BYTES:
1882
23.0k
    case IMAGE_SCN_ALIGN_2048BYTES:
1883
24.7k
    case IMAGE_SCN_ALIGN_1024BYTES:
1884
31.0k
    case IMAGE_SCN_ALIGN_512BYTES:
1885
33.5k
    case IMAGE_SCN_ALIGN_256BYTES:
1886
40.2k
    case IMAGE_SCN_ALIGN_128BYTES:
1887
44.7k
    case IMAGE_SCN_ALIGN_64BYTES:
1888
57.5k
    case IMAGE_SCN_ALIGN_32BYTES:
1889
62.5k
    case IMAGE_SCN_ALIGN_16BYTES:
1890
71.0k
    case IMAGE_SCN_ALIGN_8BYTES:
1891
81.4k
    case IMAGE_SCN_ALIGN_4BYTES:
1892
99.3k
    case IMAGE_SCN_ALIGN_2BYTES:
1893
105k
    case IMAGE_SCN_ALIGN_1BYTES:
1894
105k
      section->alignment_power
1895
105k
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1896
105k
      break;
1897
202k
    default:
1898
202k
      break;
1899
307k
    }
1900
1901
  /* In a PE image file, the s_paddr field holds the virtual size of a
1902
     section, while the s_size field holds the raw size.  We also keep
1903
     the original section flag value, since not every bit can be
1904
     mapped onto a generic BFD section bit.  */
1905
307k
  if (coff_section_data (abfd, section) == NULL)
1906
307k
    {
1907
307k
      amt = sizeof (struct coff_section_tdata);
1908
307k
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1909
307k
      if (section->used_by_bfd == NULL)
1910
  /* FIXME: Return error.  */
1911
0
  abort ();
1912
307k
    }
1913
1914
307k
  if (pei_section_data (abfd, section) == NULL)
1915
307k
    {
1916
307k
      amt = sizeof (struct pei_section_tdata);
1917
307k
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1918
307k
      if (coff_section_data (abfd, section)->tdata == NULL)
1919
  /* FIXME: Return error.  */
1920
0
  abort ();
1921
307k
    }
1922
307k
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1923
307k
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1924
1925
307k
  section->lma = hdr->s_vaddr;
1926
1927
  /* Check for extended relocs.  */
1928
307k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1929
47.5k
    {
1930
47.5k
      struct external_reloc dst;
1931
47.5k
      struct internal_reloc n;
1932
47.5k
      file_ptr oldpos = bfd_tell (abfd);
1933
47.5k
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1934
1935
47.5k
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1936
0
  return;
1937
47.5k
      if (bfd_read (& dst, relsz, abfd) != relsz)
1938
30.3k
  return;
1939
1940
17.2k
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1941
17.2k
      if (bfd_seek (abfd, oldpos, 0) != 0)
1942
0
  return;
1943
17.2k
      if (n.r_vaddr < 0x10000)
1944
3.20k
  {
1945
3.20k
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1946
3.20k
    bfd_set_error (bfd_error_bad_value);
1947
3.20k
    return;
1948
3.20k
  }
1949
14.0k
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1950
14.0k
      section->rel_filepos += relsz;
1951
14.0k
    }
1952
260k
  else if (hdr->s_nreloc == 0xffff)
1953
0
    _bfd_error_handler
1954
0
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1955
0
       abfd);
1956
307k
}
pei-riscv64.c:coff_set_alignment_hook
Line
Count
Source
1872
273k
{
1873
273k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1874
273k
  size_t amt;
1875
273k
  unsigned int alignment_power_const
1876
273k
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1877
1878
273k
  switch (alignment_power_const)
1879
273k
    {
1880
5.56k
    case IMAGE_SCN_ALIGN_8192BYTES:
1881
6.77k
    case IMAGE_SCN_ALIGN_4096BYTES:
1882
13.3k
    case IMAGE_SCN_ALIGN_2048BYTES:
1883
15.8k
    case IMAGE_SCN_ALIGN_1024BYTES:
1884
19.9k
    case IMAGE_SCN_ALIGN_512BYTES:
1885
24.4k
    case IMAGE_SCN_ALIGN_256BYTES:
1886
29.1k
    case IMAGE_SCN_ALIGN_128BYTES:
1887
35.2k
    case IMAGE_SCN_ALIGN_64BYTES:
1888
44.7k
    case IMAGE_SCN_ALIGN_32BYTES:
1889
52.2k
    case IMAGE_SCN_ALIGN_16BYTES:
1890
67.0k
    case IMAGE_SCN_ALIGN_8BYTES:
1891
72.6k
    case IMAGE_SCN_ALIGN_4BYTES:
1892
86.1k
    case IMAGE_SCN_ALIGN_2BYTES:
1893
90.6k
    case IMAGE_SCN_ALIGN_1BYTES:
1894
90.6k
      section->alignment_power
1895
90.6k
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1896
90.6k
      break;
1897
183k
    default:
1898
183k
      break;
1899
273k
    }
1900
1901
  /* In a PE image file, the s_paddr field holds the virtual size of a
1902
     section, while the s_size field holds the raw size.  We also keep
1903
     the original section flag value, since not every bit can be
1904
     mapped onto a generic BFD section bit.  */
1905
273k
  if (coff_section_data (abfd, section) == NULL)
1906
273k
    {
1907
273k
      amt = sizeof (struct coff_section_tdata);
1908
273k
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1909
273k
      if (section->used_by_bfd == NULL)
1910
  /* FIXME: Return error.  */
1911
0
  abort ();
1912
273k
    }
1913
1914
273k
  if (pei_section_data (abfd, section) == NULL)
1915
273k
    {
1916
273k
      amt = sizeof (struct pei_section_tdata);
1917
273k
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1918
273k
      if (coff_section_data (abfd, section)->tdata == NULL)
1919
  /* FIXME: Return error.  */
1920
0
  abort ();
1921
273k
    }
1922
273k
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1923
273k
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1924
1925
273k
  section->lma = hdr->s_vaddr;
1926
1927
  /* Check for extended relocs.  */
1928
273k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1929
40.2k
    {
1930
40.2k
      struct external_reloc dst;
1931
40.2k
      struct internal_reloc n;
1932
40.2k
      file_ptr oldpos = bfd_tell (abfd);
1933
40.2k
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1934
1935
40.2k
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1936
0
  return;
1937
40.2k
      if (bfd_read (& dst, relsz, abfd) != relsz)
1938
24.7k
  return;
1939
1940
15.4k
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1941
15.4k
      if (bfd_seek (abfd, oldpos, 0) != 0)
1942
0
  return;
1943
15.4k
      if (n.r_vaddr < 0x10000)
1944
7.25k
  {
1945
7.25k
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1946
7.25k
    bfd_set_error (bfd_error_bad_value);
1947
7.25k
    return;
1948
7.25k
  }
1949
8.22k
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1950
8.22k
      section->rel_filepos += relsz;
1951
8.22k
    }
1952
233k
  else if (hdr->s_nreloc == 0xffff)
1953
0
    _bfd_error_handler
1954
0
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1955
0
       abfd);
1956
273k
}
pe-arm-wince.c:coff_set_alignment_hook
Line
Count
Source
1872
86.3k
{
1873
86.3k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1874
86.3k
  size_t amt;
1875
86.3k
  unsigned int alignment_power_const
1876
86.3k
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1877
1878
86.3k
  switch (alignment_power_const)
1879
86.3k
    {
1880
3.71k
    case IMAGE_SCN_ALIGN_8192BYTES:
1881
4.74k
    case IMAGE_SCN_ALIGN_4096BYTES:
1882
6.24k
    case IMAGE_SCN_ALIGN_2048BYTES:
1883
8.19k
    case IMAGE_SCN_ALIGN_1024BYTES:
1884
10.0k
    case IMAGE_SCN_ALIGN_512BYTES:
1885
11.1k
    case IMAGE_SCN_ALIGN_256BYTES:
1886
12.0k
    case IMAGE_SCN_ALIGN_128BYTES:
1887
14.8k
    case IMAGE_SCN_ALIGN_64BYTES:
1888
17.7k
    case IMAGE_SCN_ALIGN_32BYTES:
1889
21.1k
    case IMAGE_SCN_ALIGN_16BYTES:
1890
24.1k
    case IMAGE_SCN_ALIGN_8BYTES:
1891
29.4k
    case IMAGE_SCN_ALIGN_4BYTES:
1892
34.9k
    case IMAGE_SCN_ALIGN_2BYTES:
1893
37.2k
    case IMAGE_SCN_ALIGN_1BYTES:
1894
37.2k
      section->alignment_power
1895
37.2k
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1896
37.2k
      break;
1897
49.1k
    default:
1898
49.1k
      break;
1899
86.3k
    }
1900
1901
  /* In a PE image file, the s_paddr field holds the virtual size of a
1902
     section, while the s_size field holds the raw size.  We also keep
1903
     the original section flag value, since not every bit can be
1904
     mapped onto a generic BFD section bit.  */
1905
86.3k
  if (coff_section_data (abfd, section) == NULL)
1906
86.3k
    {
1907
86.3k
      amt = sizeof (struct coff_section_tdata);
1908
86.3k
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1909
86.3k
      if (section->used_by_bfd == NULL)
1910
  /* FIXME: Return error.  */
1911
0
  abort ();
1912
86.3k
    }
1913
1914
86.3k
  if (pei_section_data (abfd, section) == NULL)
1915
86.3k
    {
1916
86.3k
      amt = sizeof (struct pei_section_tdata);
1917
86.3k
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1918
86.3k
      if (coff_section_data (abfd, section)->tdata == NULL)
1919
  /* FIXME: Return error.  */
1920
0
  abort ();
1921
86.3k
    }
1922
86.3k
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1923
86.3k
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1924
1925
86.3k
  section->lma = hdr->s_vaddr;
1926
1927
  /* Check for extended relocs.  */
1928
86.3k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1929
24.6k
    {
1930
24.6k
      struct external_reloc dst;
1931
24.6k
      struct internal_reloc n;
1932
24.6k
      file_ptr oldpos = bfd_tell (abfd);
1933
24.6k
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1934
1935
24.6k
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1936
0
  return;
1937
24.6k
      if (bfd_read (& dst, relsz, abfd) != relsz)
1938
17.8k
  return;
1939
1940
6.76k
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1941
6.76k
      if (bfd_seek (abfd, oldpos, 0) != 0)
1942
0
  return;
1943
6.76k
      if (n.r_vaddr < 0x10000)
1944
1.68k
  {
1945
1.68k
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1946
1.68k
    bfd_set_error (bfd_error_bad_value);
1947
1.68k
    return;
1948
1.68k
  }
1949
5.07k
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1950
5.07k
      section->rel_filepos += relsz;
1951
5.07k
    }
1952
61.6k
  else if (hdr->s_nreloc == 0xffff)
1953
2.98k
    _bfd_error_handler
1954
2.98k
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1955
2.98k
       abfd);
1956
86.3k
}
pe-arm.c:coff_set_alignment_hook
Line
Count
Source
1872
86.3k
{
1873
86.3k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1874
86.3k
  size_t amt;
1875
86.3k
  unsigned int alignment_power_const
1876
86.3k
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1877
1878
86.3k
  switch (alignment_power_const)
1879
86.3k
    {
1880
3.71k
    case IMAGE_SCN_ALIGN_8192BYTES:
1881
4.74k
    case IMAGE_SCN_ALIGN_4096BYTES:
1882
6.24k
    case IMAGE_SCN_ALIGN_2048BYTES:
1883
8.19k
    case IMAGE_SCN_ALIGN_1024BYTES:
1884
10.0k
    case IMAGE_SCN_ALIGN_512BYTES:
1885
11.1k
    case IMAGE_SCN_ALIGN_256BYTES:
1886
12.0k
    case IMAGE_SCN_ALIGN_128BYTES:
1887
14.8k
    case IMAGE_SCN_ALIGN_64BYTES:
1888
17.7k
    case IMAGE_SCN_ALIGN_32BYTES:
1889
21.1k
    case IMAGE_SCN_ALIGN_16BYTES:
1890
24.1k
    case IMAGE_SCN_ALIGN_8BYTES:
1891
29.4k
    case IMAGE_SCN_ALIGN_4BYTES:
1892
34.9k
    case IMAGE_SCN_ALIGN_2BYTES:
1893
37.2k
    case IMAGE_SCN_ALIGN_1BYTES:
1894
37.2k
      section->alignment_power
1895
37.2k
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1896
37.2k
      break;
1897
49.1k
    default:
1898
49.1k
      break;
1899
86.3k
    }
1900
1901
  /* In a PE image file, the s_paddr field holds the virtual size of a
1902
     section, while the s_size field holds the raw size.  We also keep
1903
     the original section flag value, since not every bit can be
1904
     mapped onto a generic BFD section bit.  */
1905
86.3k
  if (coff_section_data (abfd, section) == NULL)
1906
86.3k
    {
1907
86.3k
      amt = sizeof (struct coff_section_tdata);
1908
86.3k
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1909
86.3k
      if (section->used_by_bfd == NULL)
1910
  /* FIXME: Return error.  */
1911
0
  abort ();
1912
86.3k
    }
1913
1914
86.3k
  if (pei_section_data (abfd, section) == NULL)
1915
86.3k
    {
1916
86.3k
      amt = sizeof (struct pei_section_tdata);
1917
86.3k
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1918
86.3k
      if (coff_section_data (abfd, section)->tdata == NULL)
1919
  /* FIXME: Return error.  */
1920
0
  abort ();
1921
86.3k
    }
1922
86.3k
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1923
86.3k
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1924
1925
86.3k
  section->lma = hdr->s_vaddr;
1926
1927
  /* Check for extended relocs.  */
1928
86.3k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1929
24.6k
    {
1930
24.6k
      struct external_reloc dst;
1931
24.6k
      struct internal_reloc n;
1932
24.6k
      file_ptr oldpos = bfd_tell (abfd);
1933
24.6k
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1934
1935
24.6k
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1936
0
  return;
1937
24.6k
      if (bfd_read (& dst, relsz, abfd) != relsz)
1938
17.8k
  return;
1939
1940
6.76k
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1941
6.76k
      if (bfd_seek (abfd, oldpos, 0) != 0)
1942
0
  return;
1943
6.76k
      if (n.r_vaddr < 0x10000)
1944
1.68k
  {
1945
1.68k
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1946
1.68k
    bfd_set_error (bfd_error_bad_value);
1947
1.68k
    return;
1948
1.68k
  }
1949
5.07k
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1950
5.07k
      section->rel_filepos += relsz;
1951
5.07k
    }
1952
61.6k
  else if (hdr->s_nreloc == 0xffff)
1953
2.98k
    _bfd_error_handler
1954
2.98k
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1955
2.98k
       abfd);
1956
86.3k
}
pe-i386.c:coff_set_alignment_hook
Line
Count
Source
1872
191k
{
1873
191k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1874
191k
  size_t amt;
1875
191k
  unsigned int alignment_power_const
1876
191k
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1877
1878
191k
  switch (alignment_power_const)
1879
191k
    {
1880
5.88k
    case IMAGE_SCN_ALIGN_8192BYTES:
1881
7.58k
    case IMAGE_SCN_ALIGN_4096BYTES:
1882
11.5k
    case IMAGE_SCN_ALIGN_2048BYTES:
1883
12.6k
    case IMAGE_SCN_ALIGN_1024BYTES:
1884
15.8k
    case IMAGE_SCN_ALIGN_512BYTES:
1885
21.2k
    case IMAGE_SCN_ALIGN_256BYTES:
1886
24.2k
    case IMAGE_SCN_ALIGN_128BYTES:
1887
30.6k
    case IMAGE_SCN_ALIGN_64BYTES:
1888
37.6k
    case IMAGE_SCN_ALIGN_32BYTES:
1889
40.7k
    case IMAGE_SCN_ALIGN_16BYTES:
1890
45.8k
    case IMAGE_SCN_ALIGN_8BYTES:
1891
53.8k
    case IMAGE_SCN_ALIGN_4BYTES:
1892
73.8k
    case IMAGE_SCN_ALIGN_2BYTES:
1893
76.9k
    case IMAGE_SCN_ALIGN_1BYTES:
1894
76.9k
      section->alignment_power
1895
76.9k
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1896
76.9k
      break;
1897
114k
    default:
1898
114k
      break;
1899
191k
    }
1900
1901
  /* In a PE image file, the s_paddr field holds the virtual size of a
1902
     section, while the s_size field holds the raw size.  We also keep
1903
     the original section flag value, since not every bit can be
1904
     mapped onto a generic BFD section bit.  */
1905
191k
  if (coff_section_data (abfd, section) == NULL)
1906
191k
    {
1907
191k
      amt = sizeof (struct coff_section_tdata);
1908
191k
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1909
191k
      if (section->used_by_bfd == NULL)
1910
  /* FIXME: Return error.  */
1911
0
  abort ();
1912
191k
    }
1913
1914
191k
  if (pei_section_data (abfd, section) == NULL)
1915
191k
    {
1916
191k
      amt = sizeof (struct pei_section_tdata);
1917
191k
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1918
191k
      if (coff_section_data (abfd, section)->tdata == NULL)
1919
  /* FIXME: Return error.  */
1920
0
  abort ();
1921
191k
    }
1922
191k
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1923
191k
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1924
1925
191k
  section->lma = hdr->s_vaddr;
1926
1927
  /* Check for extended relocs.  */
1928
191k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1929
46.1k
    {
1930
46.1k
      struct external_reloc dst;
1931
46.1k
      struct internal_reloc n;
1932
46.1k
      file_ptr oldpos = bfd_tell (abfd);
1933
46.1k
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1934
1935
46.1k
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1936
0
  return;
1937
46.1k
      if (bfd_read (& dst, relsz, abfd) != relsz)
1938
33.2k
  return;
1939
1940
12.9k
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1941
12.9k
      if (bfd_seek (abfd, oldpos, 0) != 0)
1942
0
  return;
1943
12.9k
      if (n.r_vaddr < 0x10000)
1944
3.20k
  {
1945
3.20k
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1946
3.20k
    bfd_set_error (bfd_error_bad_value);
1947
3.20k
    return;
1948
3.20k
  }
1949
9.72k
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1950
9.72k
      section->rel_filepos += relsz;
1951
9.72k
    }
1952
145k
  else if (hdr->s_nreloc == 0xffff)
1953
5.27k
    _bfd_error_handler
1954
5.27k
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1955
5.27k
       abfd);
1956
191k
}
pe-mcore.c:coff_set_alignment_hook
Line
Count
Source
1872
217k
{
1873
217k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1874
217k
  size_t amt;
1875
217k
  unsigned int alignment_power_const
1876
217k
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1877
1878
217k
  switch (alignment_power_const)
1879
217k
    {
1880
10.2k
    case IMAGE_SCN_ALIGN_8192BYTES:
1881
11.0k
    case IMAGE_SCN_ALIGN_4096BYTES:
1882
20.0k
    case IMAGE_SCN_ALIGN_2048BYTES:
1883
22.6k
    case IMAGE_SCN_ALIGN_1024BYTES:
1884
31.0k
    case IMAGE_SCN_ALIGN_512BYTES:
1885
35.1k
    case IMAGE_SCN_ALIGN_256BYTES:
1886
41.6k
    case IMAGE_SCN_ALIGN_128BYTES:
1887
44.5k
    case IMAGE_SCN_ALIGN_64BYTES:
1888
53.7k
    case IMAGE_SCN_ALIGN_32BYTES:
1889
58.1k
    case IMAGE_SCN_ALIGN_16BYTES:
1890
68.1k
    case IMAGE_SCN_ALIGN_8BYTES:
1891
73.4k
    case IMAGE_SCN_ALIGN_4BYTES:
1892
87.9k
    case IMAGE_SCN_ALIGN_2BYTES:
1893
91.7k
    case IMAGE_SCN_ALIGN_1BYTES:
1894
91.7k
      section->alignment_power
1895
91.7k
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1896
91.7k
      break;
1897
126k
    default:
1898
126k
      break;
1899
217k
    }
1900
1901
  /* In a PE image file, the s_paddr field holds the virtual size of a
1902
     section, while the s_size field holds the raw size.  We also keep
1903
     the original section flag value, since not every bit can be
1904
     mapped onto a generic BFD section bit.  */
1905
217k
  if (coff_section_data (abfd, section) == NULL)
1906
217k
    {
1907
217k
      amt = sizeof (struct coff_section_tdata);
1908
217k
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1909
217k
      if (section->used_by_bfd == NULL)
1910
  /* FIXME: Return error.  */
1911
0
  abort ();
1912
217k
    }
1913
1914
217k
  if (pei_section_data (abfd, section) == NULL)
1915
217k
    {
1916
217k
      amt = sizeof (struct pei_section_tdata);
1917
217k
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1918
217k
      if (coff_section_data (abfd, section)->tdata == NULL)
1919
  /* FIXME: Return error.  */
1920
0
  abort ();
1921
217k
    }
1922
217k
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1923
217k
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1924
1925
217k
  section->lma = hdr->s_vaddr;
1926
1927
  /* Check for extended relocs.  */
1928
217k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1929
35.4k
    {
1930
35.4k
      struct external_reloc dst;
1931
35.4k
      struct internal_reloc n;
1932
35.4k
      file_ptr oldpos = bfd_tell (abfd);
1933
35.4k
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1934
1935
35.4k
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1936
0
  return;
1937
35.4k
      if (bfd_read (& dst, relsz, abfd) != relsz)
1938
23.2k
  return;
1939
1940
12.2k
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1941
12.2k
      if (bfd_seek (abfd, oldpos, 0) != 0)
1942
0
  return;
1943
12.2k
      if (n.r_vaddr < 0x10000)
1944
3.03k
  {
1945
3.03k
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1946
3.03k
    bfd_set_error (bfd_error_bad_value);
1947
3.03k
    return;
1948
3.03k
  }
1949
9.18k
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1950
9.18k
      section->rel_filepos += relsz;
1951
9.18k
    }
1952
182k
  else if (hdr->s_nreloc == 0xffff)
1953
6.42k
    _bfd_error_handler
1954
6.42k
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1955
6.42k
       abfd);
1956
217k
}
pe-sh.c:coff_set_alignment_hook
Line
Count
Source
1872
163k
{
1873
163k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1874
163k
  size_t amt;
1875
163k
  unsigned int alignment_power_const
1876
163k
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1877
1878
163k
  switch (alignment_power_const)
1879
163k
    {
1880
7.59k
    case IMAGE_SCN_ALIGN_8192BYTES:
1881
10.2k
    case IMAGE_SCN_ALIGN_4096BYTES:
1882
13.6k
    case IMAGE_SCN_ALIGN_2048BYTES:
1883
14.9k
    case IMAGE_SCN_ALIGN_1024BYTES:
1884
16.7k
    case IMAGE_SCN_ALIGN_512BYTES:
1885
18.5k
    case IMAGE_SCN_ALIGN_256BYTES:
1886
21.1k
    case IMAGE_SCN_ALIGN_128BYTES:
1887
24.8k
    case IMAGE_SCN_ALIGN_64BYTES:
1888
34.2k
    case IMAGE_SCN_ALIGN_32BYTES:
1889
39.3k
    case IMAGE_SCN_ALIGN_16BYTES:
1890
41.2k
    case IMAGE_SCN_ALIGN_8BYTES:
1891
48.2k
    case IMAGE_SCN_ALIGN_4BYTES:
1892
58.9k
    case IMAGE_SCN_ALIGN_2BYTES:
1893
61.6k
    case IMAGE_SCN_ALIGN_1BYTES:
1894
61.6k
      section->alignment_power
1895
61.6k
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1896
61.6k
      break;
1897
101k
    default:
1898
101k
      break;
1899
163k
    }
1900
1901
  /* In a PE image file, the s_paddr field holds the virtual size of a
1902
     section, while the s_size field holds the raw size.  We also keep
1903
     the original section flag value, since not every bit can be
1904
     mapped onto a generic BFD section bit.  */
1905
163k
  if (coff_section_data (abfd, section) == NULL)
1906
163k
    {
1907
163k
      amt = sizeof (struct coff_section_tdata);
1908
163k
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1909
163k
      if (section->used_by_bfd == NULL)
1910
  /* FIXME: Return error.  */
1911
0
  abort ();
1912
163k
    }
1913
1914
163k
  if (pei_section_data (abfd, section) == NULL)
1915
163k
    {
1916
163k
      amt = sizeof (struct pei_section_tdata);
1917
163k
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1918
163k
      if (coff_section_data (abfd, section)->tdata == NULL)
1919
  /* FIXME: Return error.  */
1920
0
  abort ();
1921
163k
    }
1922
163k
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1923
163k
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1924
1925
163k
  section->lma = hdr->s_vaddr;
1926
1927
  /* Check for extended relocs.  */
1928
163k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1929
37.1k
    {
1930
37.1k
      struct external_reloc dst;
1931
37.1k
      struct internal_reloc n;
1932
37.1k
      file_ptr oldpos = bfd_tell (abfd);
1933
37.1k
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1934
1935
37.1k
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1936
0
  return;
1937
37.1k
      if (bfd_read (& dst, relsz, abfd) != relsz)
1938
25.4k
  return;
1939
1940
11.7k
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1941
11.7k
      if (bfd_seek (abfd, oldpos, 0) != 0)
1942
0
  return;
1943
11.7k
      if (n.r_vaddr < 0x10000)
1944
2.95k
  {
1945
2.95k
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1946
2.95k
    bfd_set_error (bfd_error_bad_value);
1947
2.95k
    return;
1948
2.95k
  }
1949
8.81k
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1950
8.81k
      section->rel_filepos += relsz;
1951
8.81k
    }
1952
126k
  else if (hdr->s_nreloc == 0xffff)
1953
4.69k
    _bfd_error_handler
1954
4.69k
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1955
4.69k
       abfd);
1956
163k
}
pei-arm-wince.c:coff_set_alignment_hook
Line
Count
Source
1872
266k
{
1873
266k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1874
266k
  size_t amt;
1875
266k
  unsigned int alignment_power_const
1876
266k
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1877
1878
266k
  switch (alignment_power_const)
1879
266k
    {
1880
8.79k
    case IMAGE_SCN_ALIGN_8192BYTES:
1881
11.3k
    case IMAGE_SCN_ALIGN_4096BYTES:
1882
20.7k
    case IMAGE_SCN_ALIGN_2048BYTES:
1883
23.4k
    case IMAGE_SCN_ALIGN_1024BYTES:
1884
28.6k
    case IMAGE_SCN_ALIGN_512BYTES:
1885
31.5k
    case IMAGE_SCN_ALIGN_256BYTES:
1886
36.8k
    case IMAGE_SCN_ALIGN_128BYTES:
1887
41.8k
    case IMAGE_SCN_ALIGN_64BYTES:
1888
51.1k
    case IMAGE_SCN_ALIGN_32BYTES:
1889
57.3k
    case IMAGE_SCN_ALIGN_16BYTES:
1890
65.2k
    case IMAGE_SCN_ALIGN_8BYTES:
1891
76.7k
    case IMAGE_SCN_ALIGN_4BYTES:
1892
102k
    case IMAGE_SCN_ALIGN_2BYTES:
1893
109k
    case IMAGE_SCN_ALIGN_1BYTES:
1894
109k
      section->alignment_power
1895
109k
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1896
109k
      break;
1897
156k
    default:
1898
156k
      break;
1899
266k
    }
1900
1901
  /* In a PE image file, the s_paddr field holds the virtual size of a
1902
     section, while the s_size field holds the raw size.  We also keep
1903
     the original section flag value, since not every bit can be
1904
     mapped onto a generic BFD section bit.  */
1905
266k
  if (coff_section_data (abfd, section) == NULL)
1906
266k
    {
1907
266k
      amt = sizeof (struct coff_section_tdata);
1908
266k
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1909
266k
      if (section->used_by_bfd == NULL)
1910
  /* FIXME: Return error.  */
1911
0
  abort ();
1912
266k
    }
1913
1914
266k
  if (pei_section_data (abfd, section) == NULL)
1915
266k
    {
1916
266k
      amt = sizeof (struct pei_section_tdata);
1917
266k
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1918
266k
      if (coff_section_data (abfd, section)->tdata == NULL)
1919
  /* FIXME: Return error.  */
1920
0
  abort ();
1921
266k
    }
1922
266k
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1923
266k
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1924
1925
266k
  section->lma = hdr->s_vaddr;
1926
1927
  /* Check for extended relocs.  */
1928
266k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1929
72.5k
    {
1930
72.5k
      struct external_reloc dst;
1931
72.5k
      struct internal_reloc n;
1932
72.5k
      file_ptr oldpos = bfd_tell (abfd);
1933
72.5k
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1934
1935
72.5k
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1936
0
  return;
1937
72.5k
      if (bfd_read (& dst, relsz, abfd) != relsz)
1938
52.2k
  return;
1939
1940
20.2k
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1941
20.2k
      if (bfd_seek (abfd, oldpos, 0) != 0)
1942
0
  return;
1943
20.2k
      if (n.r_vaddr < 0x10000)
1944
5.81k
  {
1945
5.81k
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1946
5.81k
    bfd_set_error (bfd_error_bad_value);
1947
5.81k
    return;
1948
5.81k
  }
1949
14.4k
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1950
14.4k
      section->rel_filepos += relsz;
1951
14.4k
    }
1952
193k
  else if (hdr->s_nreloc == 0xffff)
1953
0
    _bfd_error_handler
1954
0
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1955
0
       abfd);
1956
266k
}
pei-arm.c:coff_set_alignment_hook
Line
Count
Source
1872
330k
{
1873
330k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1874
330k
  size_t amt;
1875
330k
  unsigned int alignment_power_const
1876
330k
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1877
1878
330k
  switch (alignment_power_const)
1879
330k
    {
1880
11.1k
    case IMAGE_SCN_ALIGN_8192BYTES:
1881
14.2k
    case IMAGE_SCN_ALIGN_4096BYTES:
1882
28.6k
    case IMAGE_SCN_ALIGN_2048BYTES:
1883
32.4k
    case IMAGE_SCN_ALIGN_1024BYTES:
1884
37.5k
    case IMAGE_SCN_ALIGN_512BYTES:
1885
42.3k
    case IMAGE_SCN_ALIGN_256BYTES:
1886
52.5k
    case IMAGE_SCN_ALIGN_128BYTES:
1887
59.0k
    case IMAGE_SCN_ALIGN_64BYTES:
1888
72.3k
    case IMAGE_SCN_ALIGN_32BYTES:
1889
79.1k
    case IMAGE_SCN_ALIGN_16BYTES:
1890
88.7k
    case IMAGE_SCN_ALIGN_8BYTES:
1891
103k
    case IMAGE_SCN_ALIGN_4BYTES:
1892
134k
    case IMAGE_SCN_ALIGN_2BYTES:
1893
141k
    case IMAGE_SCN_ALIGN_1BYTES:
1894
141k
      section->alignment_power
1895
141k
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1896
141k
      break;
1897
189k
    default:
1898
189k
      break;
1899
330k
    }
1900
1901
  /* In a PE image file, the s_paddr field holds the virtual size of a
1902
     section, while the s_size field holds the raw size.  We also keep
1903
     the original section flag value, since not every bit can be
1904
     mapped onto a generic BFD section bit.  */
1905
330k
  if (coff_section_data (abfd, section) == NULL)
1906
330k
    {
1907
330k
      amt = sizeof (struct coff_section_tdata);
1908
330k
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1909
330k
      if (section->used_by_bfd == NULL)
1910
  /* FIXME: Return error.  */
1911
0
  abort ();
1912
330k
    }
1913
1914
330k
  if (pei_section_data (abfd, section) == NULL)
1915
330k
    {
1916
330k
      amt = sizeof (struct pei_section_tdata);
1917
330k
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1918
330k
      if (coff_section_data (abfd, section)->tdata == NULL)
1919
  /* FIXME: Return error.  */
1920
0
  abort ();
1921
330k
    }
1922
330k
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1923
330k
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1924
1925
330k
  section->lma = hdr->s_vaddr;
1926
1927
  /* Check for extended relocs.  */
1928
330k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1929
85.8k
    {
1930
85.8k
      struct external_reloc dst;
1931
85.8k
      struct internal_reloc n;
1932
85.8k
      file_ptr oldpos = bfd_tell (abfd);
1933
85.8k
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1934
1935
85.8k
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1936
0
  return;
1937
85.8k
      if (bfd_read (& dst, relsz, abfd) != relsz)
1938
62.4k
  return;
1939
1940
23.4k
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1941
23.4k
      if (bfd_seek (abfd, oldpos, 0) != 0)
1942
0
  return;
1943
23.4k
      if (n.r_vaddr < 0x10000)
1944
6.19k
  {
1945
6.19k
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1946
6.19k
    bfd_set_error (bfd_error_bad_value);
1947
6.19k
    return;
1948
6.19k
  }
1949
17.2k
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1950
17.2k
      section->rel_filepos += relsz;
1951
17.2k
    }
1952
245k
  else if (hdr->s_nreloc == 0xffff)
1953
0
    _bfd_error_handler
1954
0
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1955
0
       abfd);
1956
330k
}
pei-mcore.c:coff_set_alignment_hook
Line
Count
Source
1872
260k
{
1873
260k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1874
260k
  size_t amt;
1875
260k
  unsigned int alignment_power_const
1876
260k
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1877
1878
260k
  switch (alignment_power_const)
1879
260k
    {
1880
17.7k
    case IMAGE_SCN_ALIGN_8192BYTES:
1881
18.7k
    case IMAGE_SCN_ALIGN_4096BYTES:
1882
24.5k
    case IMAGE_SCN_ALIGN_2048BYTES:
1883
26.4k
    case IMAGE_SCN_ALIGN_1024BYTES:
1884
35.0k
    case IMAGE_SCN_ALIGN_512BYTES:
1885
37.1k
    case IMAGE_SCN_ALIGN_256BYTES:
1886
43.9k
    case IMAGE_SCN_ALIGN_128BYTES:
1887
47.4k
    case IMAGE_SCN_ALIGN_64BYTES:
1888
57.4k
    case IMAGE_SCN_ALIGN_32BYTES:
1889
60.7k
    case IMAGE_SCN_ALIGN_16BYTES:
1890
66.3k
    case IMAGE_SCN_ALIGN_8BYTES:
1891
76.0k
    case IMAGE_SCN_ALIGN_4BYTES:
1892
98.7k
    case IMAGE_SCN_ALIGN_2BYTES:
1893
103k
    case IMAGE_SCN_ALIGN_1BYTES:
1894
103k
      section->alignment_power
1895
103k
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1896
103k
      break;
1897
157k
    default:
1898
157k
      break;
1899
260k
    }
1900
1901
  /* In a PE image file, the s_paddr field holds the virtual size of a
1902
     section, while the s_size field holds the raw size.  We also keep
1903
     the original section flag value, since not every bit can be
1904
     mapped onto a generic BFD section bit.  */
1905
260k
  if (coff_section_data (abfd, section) == NULL)
1906
260k
    {
1907
260k
      amt = sizeof (struct coff_section_tdata);
1908
260k
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1909
260k
      if (section->used_by_bfd == NULL)
1910
  /* FIXME: Return error.  */
1911
0
  abort ();
1912
260k
    }
1913
1914
260k
  if (pei_section_data (abfd, section) == NULL)
1915
260k
    {
1916
260k
      amt = sizeof (struct pei_section_tdata);
1917
260k
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1918
260k
      if (coff_section_data (abfd, section)->tdata == NULL)
1919
  /* FIXME: Return error.  */
1920
0
  abort ();
1921
260k
    }
1922
260k
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1923
260k
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1924
1925
260k
  section->lma = hdr->s_vaddr;
1926
1927
  /* Check for extended relocs.  */
1928
260k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1929
53.6k
    {
1930
53.6k
      struct external_reloc dst;
1931
53.6k
      struct internal_reloc n;
1932
53.6k
      file_ptr oldpos = bfd_tell (abfd);
1933
53.6k
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1934
1935
53.6k
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1936
0
  return;
1937
53.6k
      if (bfd_read (& dst, relsz, abfd) != relsz)
1938
34.5k
  return;
1939
1940
19.0k
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1941
19.0k
      if (bfd_seek (abfd, oldpos, 0) != 0)
1942
0
  return;
1943
19.0k
      if (n.r_vaddr < 0x10000)
1944
6.47k
  {
1945
6.47k
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1946
6.47k
    bfd_set_error (bfd_error_bad_value);
1947
6.47k
    return;
1948
6.47k
  }
1949
12.5k
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1950
12.5k
      section->rel_filepos += relsz;
1951
12.5k
    }
1952
206k
  else if (hdr->s_nreloc == 0xffff)
1953
0
    _bfd_error_handler
1954
0
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1955
0
       abfd);
1956
260k
}
pei-sh.c:coff_set_alignment_hook
Line
Count
Source
1872
284k
{
1873
284k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1874
284k
  size_t amt;
1875
284k
  unsigned int alignment_power_const
1876
284k
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1877
1878
284k
  switch (alignment_power_const)
1879
284k
    {
1880
10.5k
    case IMAGE_SCN_ALIGN_8192BYTES:
1881
13.5k
    case IMAGE_SCN_ALIGN_4096BYTES:
1882
19.3k
    case IMAGE_SCN_ALIGN_2048BYTES:
1883
23.5k
    case IMAGE_SCN_ALIGN_1024BYTES:
1884
29.8k
    case IMAGE_SCN_ALIGN_512BYTES:
1885
32.0k
    case IMAGE_SCN_ALIGN_256BYTES:
1886
37.5k
    case IMAGE_SCN_ALIGN_128BYTES:
1887
42.5k
    case IMAGE_SCN_ALIGN_64BYTES:
1888
52.2k
    case IMAGE_SCN_ALIGN_32BYTES:
1889
57.3k
    case IMAGE_SCN_ALIGN_16BYTES:
1890
69.9k
    case IMAGE_SCN_ALIGN_8BYTES:
1891
81.7k
    case IMAGE_SCN_ALIGN_4BYTES:
1892
102k
    case IMAGE_SCN_ALIGN_2BYTES:
1893
109k
    case IMAGE_SCN_ALIGN_1BYTES:
1894
109k
      section->alignment_power
1895
109k
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1896
109k
      break;
1897
175k
    default:
1898
175k
      break;
1899
284k
    }
1900
1901
  /* In a PE image file, the s_paddr field holds the virtual size of a
1902
     section, while the s_size field holds the raw size.  We also keep
1903
     the original section flag value, since not every bit can be
1904
     mapped onto a generic BFD section bit.  */
1905
284k
  if (coff_section_data (abfd, section) == NULL)
1906
284k
    {
1907
284k
      amt = sizeof (struct coff_section_tdata);
1908
284k
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1909
284k
      if (section->used_by_bfd == NULL)
1910
  /* FIXME: Return error.  */
1911
0
  abort ();
1912
284k
    }
1913
1914
284k
  if (pei_section_data (abfd, section) == NULL)
1915
284k
    {
1916
284k
      amt = sizeof (struct pei_section_tdata);
1917
284k
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1918
284k
      if (coff_section_data (abfd, section)->tdata == NULL)
1919
  /* FIXME: Return error.  */
1920
0
  abort ();
1921
284k
    }
1922
284k
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1923
284k
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1924
1925
284k
  section->lma = hdr->s_vaddr;
1926
1927
  /* Check for extended relocs.  */
1928
284k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1929
66.3k
    {
1930
66.3k
      struct external_reloc dst;
1931
66.3k
      struct internal_reloc n;
1932
66.3k
      file_ptr oldpos = bfd_tell (abfd);
1933
66.3k
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1934
1935
66.3k
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1936
0
  return;
1937
66.3k
      if (bfd_read (& dst, relsz, abfd) != relsz)
1938
44.5k
  return;
1939
1940
21.7k
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1941
21.7k
      if (bfd_seek (abfd, oldpos, 0) != 0)
1942
0
  return;
1943
21.7k
      if (n.r_vaddr < 0x10000)
1944
5.14k
  {
1945
5.14k
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1946
5.14k
    bfd_set_error (bfd_error_bad_value);
1947
5.14k
    return;
1948
5.14k
  }
1949
16.6k
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1950
16.6k
      section->rel_filepos += relsz;
1951
16.6k
    }
1952
218k
  else if (hdr->s_nreloc == 0xffff)
1953
0
    _bfd_error_handler
1954
0
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1955
0
       abfd);
1956
284k
}
1957
#undef ALIGN_SET
1958
#undef ELIFALIGN_SET
1959
1960
#else /* ! COFF_WITH_PE */
1961
#ifdef RS6000COFF_C
1962
1963
/* We grossly abuse this function to handle XCOFF overflow headers.
1964
   When we see one, we correct the reloc and line number counts in the
1965
   real header, and remove the section we just created.  */
1966
1967
static void
1968
coff_set_alignment_hook (bfd *abfd, asection *section, void * scnhdr)
1969
31.7M
{
1970
31.7M
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1971
31.7M
  asection *real_sec;
1972
1973
31.7M
  if ((hdr->s_flags & STYP_OVRFLO) == 0)
1974
25.8M
    return;
1975
1976
5.96M
  real_sec = coff_section_from_bfd_index (abfd, (int) hdr->s_nreloc);
1977
5.96M
  if (real_sec == NULL)
1978
0
    return;
1979
1980
5.96M
  real_sec->reloc_count = hdr->s_paddr;
1981
5.96M
  real_sec->lineno_count = hdr->s_vaddr;
1982
1983
5.96M
  if (!bfd_section_removed_from_list (abfd, section))
1984
5.96M
    {
1985
5.96M
      bfd_section_list_remove (abfd, section);
1986
5.96M
      --abfd->section_count;
1987
5.96M
    }
1988
5.96M
}
coff64-rs6000.c:coff_set_alignment_hook
Line
Count
Source
1969
3.50M
{
1970
3.50M
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1971
3.50M
  asection *real_sec;
1972
1973
3.50M
  if ((hdr->s_flags & STYP_OVRFLO) == 0)
1974
2.84M
    return;
1975
1976
662k
  real_sec = coff_section_from_bfd_index (abfd, (int) hdr->s_nreloc);
1977
662k
  if (real_sec == NULL)
1978
0
    return;
1979
1980
662k
  real_sec->reloc_count = hdr->s_paddr;
1981
662k
  real_sec->lineno_count = hdr->s_vaddr;
1982
1983
662k
  if (!bfd_section_removed_from_list (abfd, section))
1984
662k
    {
1985
662k
      bfd_section_list_remove (abfd, section);
1986
662k
      --abfd->section_count;
1987
662k
    }
1988
662k
}
coff-rs6000.c:coff_set_alignment_hook
Line
Count
Source
1969
28.2M
{
1970
28.2M
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1971
28.2M
  asection *real_sec;
1972
1973
28.2M
  if ((hdr->s_flags & STYP_OVRFLO) == 0)
1974
22.9M
    return;
1975
1976
5.30M
  real_sec = coff_section_from_bfd_index (abfd, (int) hdr->s_nreloc);
1977
5.30M
  if (real_sec == NULL)
1978
0
    return;
1979
1980
5.30M
  real_sec->reloc_count = hdr->s_paddr;
1981
5.30M
  real_sec->lineno_count = hdr->s_vaddr;
1982
1983
5.30M
  if (!bfd_section_removed_from_list (abfd, section))
1984
5.30M
    {
1985
5.30M
      bfd_section_list_remove (abfd, section);
1986
5.30M
      --abfd->section_count;
1987
5.30M
    }
1988
5.30M
}
1989
1990
#else /* ! RS6000COFF_C */
1991
#if defined (COFF_GO32_EXE) || defined (COFF_GO32)
1992
1993
static void
1994
coff_set_alignment_hook (bfd * abfd, asection * section, void * scnhdr)
1995
6.36M
{
1996
6.36M
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1997
1998
  /* Check for extended relocs.  */
1999
6.36M
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
2000
1.89M
    {
2001
1.89M
      struct external_reloc dst;
2002
1.89M
      struct internal_reloc n;
2003
1.89M
      const file_ptr oldpos = bfd_tell (abfd);
2004
1.89M
      const bfd_size_type relsz = bfd_coff_relsz (abfd);
2005
2006
1.89M
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
2007
0
  return;
2008
1.89M
      if (bfd_read (& dst, relsz, abfd) != relsz)
2009
1.58M
  return;
2010
2011
309k
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
2012
309k
      if (bfd_seek (abfd, oldpos, 0) != 0)
2013
0
  return;
2014
309k
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
2015
309k
      section->rel_filepos += relsz;
2016
309k
    }
2017
4.46M
  else if (hdr->s_nreloc == 0xffff)
2018
87.7k
    _bfd_error_handler
2019
87.7k
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
2020
87.7k
       abfd);
2021
6.36M
}
coff-go32.c:coff_set_alignment_hook
Line
Count
Source
1995
5.17M
{
1996
5.17M
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1997
1998
  /* Check for extended relocs.  */
1999
5.17M
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
2000
1.45M
    {
2001
1.45M
      struct external_reloc dst;
2002
1.45M
      struct internal_reloc n;
2003
1.45M
      const file_ptr oldpos = bfd_tell (abfd);
2004
1.45M
      const bfd_size_type relsz = bfd_coff_relsz (abfd);
2005
2006
1.45M
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
2007
0
  return;
2008
1.45M
      if (bfd_read (& dst, relsz, abfd) != relsz)
2009
1.18M
  return;
2010
2011
269k
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
2012
269k
      if (bfd_seek (abfd, oldpos, 0) != 0)
2013
0
  return;
2014
269k
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
2015
269k
      section->rel_filepos += relsz;
2016
269k
    }
2017
3.71M
  else if (hdr->s_nreloc == 0xffff)
2018
70.3k
    _bfd_error_handler
2019
70.3k
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
2020
70.3k
       abfd);
2021
5.17M
}
coff-stgo32.c:coff_set_alignment_hook
Line
Count
Source
1995
1.18M
{
1996
1.18M
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1997
1998
  /* Check for extended relocs.  */
1999
1.18M
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
2000
435k
    {
2001
435k
      struct external_reloc dst;
2002
435k
      struct internal_reloc n;
2003
435k
      const file_ptr oldpos = bfd_tell (abfd);
2004
435k
      const bfd_size_type relsz = bfd_coff_relsz (abfd);
2005
2006
435k
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
2007
0
  return;
2008
435k
      if (bfd_read (& dst, relsz, abfd) != relsz)
2009
396k
  return;
2010
2011
39.4k
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
2012
39.4k
      if (bfd_seek (abfd, oldpos, 0) != 0)
2013
0
  return;
2014
39.4k
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
2015
39.4k
      section->rel_filepos += relsz;
2016
39.4k
    }
2017
752k
  else if (hdr->s_nreloc == 0xffff)
2018
17.4k
    _bfd_error_handler
2019
17.4k
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
2020
17.4k
       abfd);
2021
1.18M
}
2022
2023
#else /* ! COFF_GO32_EXE && ! COFF_GO32 */
2024
2025
static void
2026
coff_set_alignment_hook (bfd *abfd ATTRIBUTE_UNUSED,
2027
       asection *section ATTRIBUTE_UNUSED,
2028
       void *scnhdr ATTRIBUTE_UNUSED)
2029
74.9M
{
2030
74.9M
}
coff-x86_64.c:coff_set_alignment_hook
Line
Count
Source
2029
19.0M
{
2030
19.0M
}
cf-i386lynx.c:coff_set_alignment_hook
Line
Count
Source
2029
7.80M
{
2030
7.80M
}
coff-i386.c:coff_set_alignment_hook
Line
Count
Source
2029
6.65M
{
2030
6.65M
}
coff-sh.c:coff_set_alignment_hook
Line
Count
Source
2029
10.5M
{
2030
10.5M
}
coff-tic30.c:coff_set_alignment_hook
Line
Count
Source
2029
12.7M
{
2030
12.7M
}
coff-z8k.c:coff_set_alignment_hook
Line
Count
Source
2029
18.1M
{
2030
18.1M
}
2031
2032
#endif /* ! COFF_GO32_EXE && ! COFF_GO32 */
2033
#endif /* ! RS6000COFF_C */
2034
#endif /* ! COFF_WITH_PE */
2035
#endif /* ! COFF_ALIGN_IN_SECTION_HEADER */
2036
2037
#ifndef coff_mkobject
2038
2039
static bool
2040
coff_mkobject (bfd * abfd)
2041
718k
{
2042
718k
  coff_data_type *coff;
2043
718k
  size_t amt = sizeof (coff_data_type);
2044
2045
718k
  abfd->tdata.coff_obj_data = bfd_zalloc (abfd, amt);
2046
718k
  if (abfd->tdata.coff_obj_data == NULL)
2047
0
    return false;
2048
2049
718k
  coff = coff_data (abfd);
2050
718k
  coff->symbols = NULL;
2051
718k
  coff->conversion_table = NULL;
2052
718k
  coff->raw_syments = NULL;
2053
718k
  coff->relocbase = 0;
2054
718k
  coff->local_toc_sym_map = 0;
2055
2056
718k
  bfd_coff_long_section_names (abfd)
2057
718k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
2058
2059
/*  make_abs_section(abfd);*/
2060
2061
718k
  return true;
2062
718k
}
coff-x86_64.c:coff_mkobject
Line
Count
Source
2041
216k
{
2042
216k
  coff_data_type *coff;
2043
216k
  size_t amt = sizeof (coff_data_type);
2044
2045
216k
  abfd->tdata.coff_obj_data = bfd_zalloc (abfd, amt);
2046
216k
  if (abfd->tdata.coff_obj_data == NULL)
2047
0
    return false;
2048
2049
216k
  coff = coff_data (abfd);
2050
216k
  coff->symbols = NULL;
2051
216k
  coff->conversion_table = NULL;
2052
216k
  coff->raw_syments = NULL;
2053
216k
  coff->relocbase = 0;
2054
216k
  coff->local_toc_sym_map = 0;
2055
2056
216k
  bfd_coff_long_section_names (abfd)
2057
216k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
2058
2059
/*  make_abs_section(abfd);*/
2060
2061
216k
  return true;
2062
216k
}
cf-i386lynx.c:coff_mkobject
Line
Count
Source
2041
72.0k
{
2042
72.0k
  coff_data_type *coff;
2043
72.0k
  size_t amt = sizeof (coff_data_type);
2044
2045
72.0k
  abfd->tdata.coff_obj_data = bfd_zalloc (abfd, amt);
2046
72.0k
  if (abfd->tdata.coff_obj_data == NULL)
2047
0
    return false;
2048
2049
72.0k
  coff = coff_data (abfd);
2050
72.0k
  coff->symbols = NULL;
2051
72.0k
  coff->conversion_table = NULL;
2052
72.0k
  coff->raw_syments = NULL;
2053
72.0k
  coff->relocbase = 0;
2054
72.0k
  coff->local_toc_sym_map = 0;
2055
2056
72.0k
  bfd_coff_long_section_names (abfd)
2057
72.0k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
2058
2059
/*  make_abs_section(abfd);*/
2060
2061
72.0k
  return true;
2062
72.0k
}
coff-i386.c:coff_mkobject
Line
Count
Source
2041
68.9k
{
2042
68.9k
  coff_data_type *coff;
2043
68.9k
  size_t amt = sizeof (coff_data_type);
2044
2045
68.9k
  abfd->tdata.coff_obj_data = bfd_zalloc (abfd, amt);
2046
68.9k
  if (abfd->tdata.coff_obj_data == NULL)
2047
0
    return false;
2048
2049
68.9k
  coff = coff_data (abfd);
2050
68.9k
  coff->symbols = NULL;
2051
68.9k
  coff->conversion_table = NULL;
2052
68.9k
  coff->raw_syments = NULL;
2053
68.9k
  coff->relocbase = 0;
2054
68.9k
  coff->local_toc_sym_map = 0;
2055
2056
68.9k
  bfd_coff_long_section_names (abfd)
2057
68.9k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
2058
2059
/*  make_abs_section(abfd);*/
2060
2061
68.9k
  return true;
2062
68.9k
}
coff-sh.c:coff_mkobject
Line
Count
Source
2041
87.0k
{
2042
87.0k
  coff_data_type *coff;
2043
87.0k
  size_t amt = sizeof (coff_data_type);
2044
2045
87.0k
  abfd->tdata.coff_obj_data = bfd_zalloc (abfd, amt);
2046
87.0k
  if (abfd->tdata.coff_obj_data == NULL)
2047
0
    return false;
2048
2049
87.0k
  coff = coff_data (abfd);
2050
87.0k
  coff->symbols = NULL;
2051
87.0k
  coff->conversion_table = NULL;
2052
87.0k
  coff->raw_syments = NULL;
2053
87.0k
  coff->relocbase = 0;
2054
87.0k
  coff->local_toc_sym_map = 0;
2055
2056
87.0k
  bfd_coff_long_section_names (abfd)
2057
87.0k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
2058
2059
/*  make_abs_section(abfd);*/
2060
2061
87.0k
  return true;
2062
87.0k
}
coff-tic30.c:coff_mkobject
Line
Count
Source
2041
60.1k
{
2042
60.1k
  coff_data_type *coff;
2043
60.1k
  size_t amt = sizeof (coff_data_type);
2044
2045
60.1k
  abfd->tdata.coff_obj_data = bfd_zalloc (abfd, amt);
2046
60.1k
  if (abfd->tdata.coff_obj_data == NULL)
2047
0
    return false;
2048
2049
60.1k
  coff = coff_data (abfd);
2050
60.1k
  coff->symbols = NULL;
2051
60.1k
  coff->conversion_table = NULL;
2052
60.1k
  coff->raw_syments = NULL;
2053
60.1k
  coff->relocbase = 0;
2054
60.1k
  coff->local_toc_sym_map = 0;
2055
2056
60.1k
  bfd_coff_long_section_names (abfd)
2057
60.1k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
2058
2059
/*  make_abs_section(abfd);*/
2060
2061
60.1k
  return true;
2062
60.1k
}
Unexecuted instantiation: coff-tic4x.c:coff_mkobject
coff-tic54x.c:coff_mkobject
Line
Count
Source
2041
116k
{
2042
116k
  coff_data_type *coff;
2043
116k
  size_t amt = sizeof (coff_data_type);
2044
2045
116k
  abfd->tdata.coff_obj_data = bfd_zalloc (abfd, amt);
2046
116k
  if (abfd->tdata.coff_obj_data == NULL)
2047
0
    return false;
2048
2049
116k
  coff = coff_data (abfd);
2050
116k
  coff->symbols = NULL;
2051
116k
  coff->conversion_table = NULL;
2052
116k
  coff->raw_syments = NULL;
2053
116k
  coff->relocbase = 0;
2054
116k
  coff->local_toc_sym_map = 0;
2055
2056
116k
  bfd_coff_long_section_names (abfd)
2057
116k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
2058
2059
/*  make_abs_section(abfd);*/
2060
2061
116k
  return true;
2062
116k
}
coff-z80.c:coff_mkobject
Line
Count
Source
2041
46.8k
{
2042
46.8k
  coff_data_type *coff;
2043
46.8k
  size_t amt = sizeof (coff_data_type);
2044
2045
46.8k
  abfd->tdata.coff_obj_data = bfd_zalloc (abfd, amt);
2046
46.8k
  if (abfd->tdata.coff_obj_data == NULL)
2047
0
    return false;
2048
2049
46.8k
  coff = coff_data (abfd);
2050
46.8k
  coff->symbols = NULL;
2051
46.8k
  coff->conversion_table = NULL;
2052
46.8k
  coff->raw_syments = NULL;
2053
46.8k
  coff->relocbase = 0;
2054
46.8k
  coff->local_toc_sym_map = 0;
2055
2056
46.8k
  bfd_coff_long_section_names (abfd)
2057
46.8k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
2058
2059
/*  make_abs_section(abfd);*/
2060
2061
46.8k
  return true;
2062
46.8k
}
coff-z8k.c:coff_mkobject
Line
Count
Source
2041
51.0k
{
2042
51.0k
  coff_data_type *coff;
2043
51.0k
  size_t amt = sizeof (coff_data_type);
2044
2045
51.0k
  abfd->tdata.coff_obj_data = bfd_zalloc (abfd, amt);
2046
51.0k
  if (abfd->tdata.coff_obj_data == NULL)
2047
0
    return false;
2048
2049
51.0k
  coff = coff_data (abfd);
2050
51.0k
  coff->symbols = NULL;
2051
51.0k
  coff->conversion_table = NULL;
2052
51.0k
  coff->raw_syments = NULL;
2053
51.0k
  coff->relocbase = 0;
2054
51.0k
  coff->local_toc_sym_map = 0;
2055
2056
51.0k
  bfd_coff_long_section_names (abfd)
2057
51.0k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
2058
2059
/*  make_abs_section(abfd);*/
2060
2061
51.0k
  return true;
2062
51.0k
}
2063
#endif
2064
2065
/* Create the COFF backend specific information.  */
2066
2067
#ifndef coff_mkobject_hook
2068
static void *
2069
coff_mkobject_hook (bfd * abfd,
2070
        void * filehdr,
2071
        void * aouthdr ATTRIBUTE_UNUSED)
2072
992k
{
2073
992k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2074
992k
  coff_data_type *coff;
2075
2076
992k
  if (! coff_mkobject (abfd))
2077
0
    return NULL;
2078
2079
992k
  coff = coff_data (abfd);
2080
2081
992k
  coff->sym_filepos = internal_f->f_symptr;
2082
2083
  /* These members communicate important constants about the symbol
2084
     table to GDB's symbol-reading code.  These `constants'
2085
     unfortunately vary among coff implementations...  */
2086
992k
  coff->local_n_btmask = N_BTMASK;
2087
992k
  coff->local_n_btshft = N_BTSHFT;
2088
992k
  coff->local_n_tmask = N_TMASK;
2089
992k
  coff->local_n_tshift = N_TSHIFT;
2090
992k
  coff->local_symesz = bfd_coff_symesz (abfd);
2091
992k
  coff->local_auxesz = bfd_coff_auxesz (abfd);
2092
992k
  coff->local_linesz = bfd_coff_linesz (abfd);
2093
2094
992k
  coff->timestamp = internal_f->f_timdat;
2095
2096
992k
  obj_raw_syment_count (abfd) =
2097
992k
    obj_conv_table_size (abfd) =
2098
992k
      internal_f->f_nsyms;
2099
2100
#ifdef RS6000COFF_C
2101
202k
  if ((internal_f->f_flags & F_SHROBJ) != 0)
2102
62.3k
    abfd->flags |= DYNAMIC;
2103
202k
  if (aouthdr != NULL && internal_f->f_opthdr >= bfd_coff_aoutsz (abfd))
2104
48.1k
    {
2105
48.1k
      struct internal_aouthdr *internal_a =
2106
48.1k
  (struct internal_aouthdr *) aouthdr;
2107
48.1k
      struct xcoff_tdata *xcoff;
2108
2109
48.1k
      xcoff = xcoff_data (abfd);
2110
# ifdef U803XTOCMAGIC
2111
28.7k
      xcoff->xcoff64 = internal_f->f_magic == U803XTOCMAGIC;
2112
# else
2113
      xcoff->xcoff64 = 0;
2114
# endif
2115
48.1k
      xcoff->full_aouthdr = true;
2116
48.1k
      xcoff->toc = internal_a->o_toc;
2117
48.1k
      xcoff->sntoc = internal_a->o_sntoc;
2118
48.1k
      xcoff->snentry = internal_a->o_snentry;
2119
48.1k
      bfd_xcoff_text_align_power (abfd) = internal_a->o_algntext;
2120
48.1k
      bfd_xcoff_data_align_power (abfd) = internal_a->o_algndata;
2121
48.1k
      xcoff->modtype = internal_a->o_modtype;
2122
48.1k
      xcoff->cputype = internal_a->o_cputype;
2123
48.1k
      xcoff->maxdata = internal_a->o_maxdata;
2124
48.1k
      xcoff->maxstack = internal_a->o_maxstack;
2125
48.1k
    }
2126
#endif
2127
2128
#ifdef ARM
2129
  /* Set the flags field from the COFF header read in.  */
2130
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
2131
    coff->flags = 0;
2132
#endif
2133
2134
#ifdef COFF_WITH_PE
2135
  /* FIXME: I'm not sure this is ever executed, since peicode.h
2136
     defines coff_mkobject_hook.  */
2137
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
2138
    abfd->flags |= HAS_DEBUG;
2139
#endif
2140
2141
992k
  return coff;
2142
992k
}
coff-x86_64.c:coff_mkobject_hook
Line
Count
Source
2072
215k
{
2073
215k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2074
215k
  coff_data_type *coff;
2075
2076
215k
  if (! coff_mkobject (abfd))
2077
0
    return NULL;
2078
2079
215k
  coff = coff_data (abfd);
2080
2081
215k
  coff->sym_filepos = internal_f->f_symptr;
2082
2083
  /* These members communicate important constants about the symbol
2084
     table to GDB's symbol-reading code.  These `constants'
2085
     unfortunately vary among coff implementations...  */
2086
215k
  coff->local_n_btmask = N_BTMASK;
2087
215k
  coff->local_n_btshft = N_BTSHFT;
2088
215k
  coff->local_n_tmask = N_TMASK;
2089
215k
  coff->local_n_tshift = N_TSHIFT;
2090
215k
  coff->local_symesz = bfd_coff_symesz (abfd);
2091
215k
  coff->local_auxesz = bfd_coff_auxesz (abfd);
2092
215k
  coff->local_linesz = bfd_coff_linesz (abfd);
2093
2094
215k
  coff->timestamp = internal_f->f_timdat;
2095
2096
215k
  obj_raw_syment_count (abfd) =
2097
215k
    obj_conv_table_size (abfd) =
2098
215k
      internal_f->f_nsyms;
2099
2100
#ifdef RS6000COFF_C
2101
  if ((internal_f->f_flags & F_SHROBJ) != 0)
2102
    abfd->flags |= DYNAMIC;
2103
  if (aouthdr != NULL && internal_f->f_opthdr >= bfd_coff_aoutsz (abfd))
2104
    {
2105
      struct internal_aouthdr *internal_a =
2106
  (struct internal_aouthdr *) aouthdr;
2107
      struct xcoff_tdata *xcoff;
2108
2109
      xcoff = xcoff_data (abfd);
2110
# ifdef U803XTOCMAGIC
2111
      xcoff->xcoff64 = internal_f->f_magic == U803XTOCMAGIC;
2112
# else
2113
      xcoff->xcoff64 = 0;
2114
# endif
2115
      xcoff->full_aouthdr = true;
2116
      xcoff->toc = internal_a->o_toc;
2117
      xcoff->sntoc = internal_a->o_sntoc;
2118
      xcoff->snentry = internal_a->o_snentry;
2119
      bfd_xcoff_text_align_power (abfd) = internal_a->o_algntext;
2120
      bfd_xcoff_data_align_power (abfd) = internal_a->o_algndata;
2121
      xcoff->modtype = internal_a->o_modtype;
2122
      xcoff->cputype = internal_a->o_cputype;
2123
      xcoff->maxdata = internal_a->o_maxdata;
2124
      xcoff->maxstack = internal_a->o_maxstack;
2125
    }
2126
#endif
2127
2128
#ifdef ARM
2129
  /* Set the flags field from the COFF header read in.  */
2130
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
2131
    coff->flags = 0;
2132
#endif
2133
2134
#ifdef COFF_WITH_PE
2135
  /* FIXME: I'm not sure this is ever executed, since peicode.h
2136
     defines coff_mkobject_hook.  */
2137
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
2138
    abfd->flags |= HAS_DEBUG;
2139
#endif
2140
2141
215k
  return coff;
2142
215k
}
coff64-rs6000.c:coff_mkobject_hook
Line
Count
Source
2072
104k
{
2073
104k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2074
104k
  coff_data_type *coff;
2075
2076
104k
  if (! coff_mkobject (abfd))
2077
0
    return NULL;
2078
2079
104k
  coff = coff_data (abfd);
2080
2081
104k
  coff->sym_filepos = internal_f->f_symptr;
2082
2083
  /* These members communicate important constants about the symbol
2084
     table to GDB's symbol-reading code.  These `constants'
2085
     unfortunately vary among coff implementations...  */
2086
104k
  coff->local_n_btmask = N_BTMASK;
2087
104k
  coff->local_n_btshft = N_BTSHFT;
2088
104k
  coff->local_n_tmask = N_TMASK;
2089
104k
  coff->local_n_tshift = N_TSHIFT;
2090
104k
  coff->local_symesz = bfd_coff_symesz (abfd);
2091
104k
  coff->local_auxesz = bfd_coff_auxesz (abfd);
2092
104k
  coff->local_linesz = bfd_coff_linesz (abfd);
2093
2094
104k
  coff->timestamp = internal_f->f_timdat;
2095
2096
104k
  obj_raw_syment_count (abfd) =
2097
104k
    obj_conv_table_size (abfd) =
2098
104k
      internal_f->f_nsyms;
2099
2100
104k
#ifdef RS6000COFF_C
2101
104k
  if ((internal_f->f_flags & F_SHROBJ) != 0)
2102
32.8k
    abfd->flags |= DYNAMIC;
2103
104k
  if (aouthdr != NULL && internal_f->f_opthdr >= bfd_coff_aoutsz (abfd))
2104
28.7k
    {
2105
28.7k
      struct internal_aouthdr *internal_a =
2106
28.7k
  (struct internal_aouthdr *) aouthdr;
2107
28.7k
      struct xcoff_tdata *xcoff;
2108
2109
28.7k
      xcoff = xcoff_data (abfd);
2110
28.7k
# ifdef U803XTOCMAGIC
2111
28.7k
      xcoff->xcoff64 = internal_f->f_magic == U803XTOCMAGIC;
2112
# else
2113
      xcoff->xcoff64 = 0;
2114
# endif
2115
28.7k
      xcoff->full_aouthdr = true;
2116
28.7k
      xcoff->toc = internal_a->o_toc;
2117
28.7k
      xcoff->sntoc = internal_a->o_sntoc;
2118
28.7k
      xcoff->snentry = internal_a->o_snentry;
2119
28.7k
      bfd_xcoff_text_align_power (abfd) = internal_a->o_algntext;
2120
28.7k
      bfd_xcoff_data_align_power (abfd) = internal_a->o_algndata;
2121
28.7k
      xcoff->modtype = internal_a->o_modtype;
2122
28.7k
      xcoff->cputype = internal_a->o_cputype;
2123
28.7k
      xcoff->maxdata = internal_a->o_maxdata;
2124
28.7k
      xcoff->maxstack = internal_a->o_maxstack;
2125
28.7k
    }
2126
104k
#endif
2127
2128
#ifdef ARM
2129
  /* Set the flags field from the COFF header read in.  */
2130
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
2131
    coff->flags = 0;
2132
#endif
2133
2134
#ifdef COFF_WITH_PE
2135
  /* FIXME: I'm not sure this is ever executed, since peicode.h
2136
     defines coff_mkobject_hook.  */
2137
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
2138
    abfd->flags |= HAS_DEBUG;
2139
#endif
2140
2141
104k
  return coff;
2142
104k
}
cf-i386lynx.c:coff_mkobject_hook
Line
Count
Source
2072
72.0k
{
2073
72.0k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2074
72.0k
  coff_data_type *coff;
2075
2076
72.0k
  if (! coff_mkobject (abfd))
2077
0
    return NULL;
2078
2079
72.0k
  coff = coff_data (abfd);
2080
2081
72.0k
  coff->sym_filepos = internal_f->f_symptr;
2082
2083
  /* These members communicate important constants about the symbol
2084
     table to GDB's symbol-reading code.  These `constants'
2085
     unfortunately vary among coff implementations...  */
2086
72.0k
  coff->local_n_btmask = N_BTMASK;
2087
72.0k
  coff->local_n_btshft = N_BTSHFT;
2088
72.0k
  coff->local_n_tmask = N_TMASK;
2089
72.0k
  coff->local_n_tshift = N_TSHIFT;
2090
72.0k
  coff->local_symesz = bfd_coff_symesz (abfd);
2091
72.0k
  coff->local_auxesz = bfd_coff_auxesz (abfd);
2092
72.0k
  coff->local_linesz = bfd_coff_linesz (abfd);
2093
2094
72.0k
  coff->timestamp = internal_f->f_timdat;
2095
2096
72.0k
  obj_raw_syment_count (abfd) =
2097
72.0k
    obj_conv_table_size (abfd) =
2098
72.0k
      internal_f->f_nsyms;
2099
2100
#ifdef RS6000COFF_C
2101
  if ((internal_f->f_flags & F_SHROBJ) != 0)
2102
    abfd->flags |= DYNAMIC;
2103
  if (aouthdr != NULL && internal_f->f_opthdr >= bfd_coff_aoutsz (abfd))
2104
    {
2105
      struct internal_aouthdr *internal_a =
2106
  (struct internal_aouthdr *) aouthdr;
2107
      struct xcoff_tdata *xcoff;
2108
2109
      xcoff = xcoff_data (abfd);
2110
# ifdef U803XTOCMAGIC
2111
      xcoff->xcoff64 = internal_f->f_magic == U803XTOCMAGIC;
2112
# else
2113
      xcoff->xcoff64 = 0;
2114
# endif
2115
      xcoff->full_aouthdr = true;
2116
      xcoff->toc = internal_a->o_toc;
2117
      xcoff->sntoc = internal_a->o_sntoc;
2118
      xcoff->snentry = internal_a->o_snentry;
2119
      bfd_xcoff_text_align_power (abfd) = internal_a->o_algntext;
2120
      bfd_xcoff_data_align_power (abfd) = internal_a->o_algndata;
2121
      xcoff->modtype = internal_a->o_modtype;
2122
      xcoff->cputype = internal_a->o_cputype;
2123
      xcoff->maxdata = internal_a->o_maxdata;
2124
      xcoff->maxstack = internal_a->o_maxstack;
2125
    }
2126
#endif
2127
2128
#ifdef ARM
2129
  /* Set the flags field from the COFF header read in.  */
2130
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
2131
    coff->flags = 0;
2132
#endif
2133
2134
#ifdef COFF_WITH_PE
2135
  /* FIXME: I'm not sure this is ever executed, since peicode.h
2136
     defines coff_mkobject_hook.  */
2137
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
2138
    abfd->flags |= HAS_DEBUG;
2139
#endif
2140
2141
72.0k
  return coff;
2142
72.0k
}
coff-go32.c:coff_mkobject_hook
Line
Count
Source
2072
68.9k
{
2073
68.9k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2074
68.9k
  coff_data_type *coff;
2075
2076
68.9k
  if (! coff_mkobject (abfd))
2077
0
    return NULL;
2078
2079
68.9k
  coff = coff_data (abfd);
2080
2081
68.9k
  coff->sym_filepos = internal_f->f_symptr;
2082
2083
  /* These members communicate important constants about the symbol
2084
     table to GDB's symbol-reading code.  These `constants'
2085
     unfortunately vary among coff implementations...  */
2086
68.9k
  coff->local_n_btmask = N_BTMASK;
2087
68.9k
  coff->local_n_btshft = N_BTSHFT;
2088
68.9k
  coff->local_n_tmask = N_TMASK;
2089
68.9k
  coff->local_n_tshift = N_TSHIFT;
2090
68.9k
  coff->local_symesz = bfd_coff_symesz (abfd);
2091
68.9k
  coff->local_auxesz = bfd_coff_auxesz (abfd);
2092
68.9k
  coff->local_linesz = bfd_coff_linesz (abfd);
2093
2094
68.9k
  coff->timestamp = internal_f->f_timdat;
2095
2096
68.9k
  obj_raw_syment_count (abfd) =
2097
68.9k
    obj_conv_table_size (abfd) =
2098
68.9k
      internal_f->f_nsyms;
2099
2100
#ifdef RS6000COFF_C
2101
  if ((internal_f->f_flags & F_SHROBJ) != 0)
2102
    abfd->flags |= DYNAMIC;
2103
  if (aouthdr != NULL && internal_f->f_opthdr >= bfd_coff_aoutsz (abfd))
2104
    {
2105
      struct internal_aouthdr *internal_a =
2106
  (struct internal_aouthdr *) aouthdr;
2107
      struct xcoff_tdata *xcoff;
2108
2109
      xcoff = xcoff_data (abfd);
2110
# ifdef U803XTOCMAGIC
2111
      xcoff->xcoff64 = internal_f->f_magic == U803XTOCMAGIC;
2112
# else
2113
      xcoff->xcoff64 = 0;
2114
# endif
2115
      xcoff->full_aouthdr = true;
2116
      xcoff->toc = internal_a->o_toc;
2117
      xcoff->sntoc = internal_a->o_sntoc;
2118
      xcoff->snentry = internal_a->o_snentry;
2119
      bfd_xcoff_text_align_power (abfd) = internal_a->o_algntext;
2120
      bfd_xcoff_data_align_power (abfd) = internal_a->o_algndata;
2121
      xcoff->modtype = internal_a->o_modtype;
2122
      xcoff->cputype = internal_a->o_cputype;
2123
      xcoff->maxdata = internal_a->o_maxdata;
2124
      xcoff->maxstack = internal_a->o_maxstack;
2125
    }
2126
#endif
2127
2128
#ifdef ARM
2129
  /* Set the flags field from the COFF header read in.  */
2130
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
2131
    coff->flags = 0;
2132
#endif
2133
2134
#ifdef COFF_WITH_PE
2135
  /* FIXME: I'm not sure this is ever executed, since peicode.h
2136
     defines coff_mkobject_hook.  */
2137
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
2138
    abfd->flags |= HAS_DEBUG;
2139
#endif
2140
2141
68.9k
  return coff;
2142
68.9k
}
coff-i386.c:coff_mkobject_hook
Line
Count
Source
2072
68.9k
{
2073
68.9k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2074
68.9k
  coff_data_type *coff;
2075
2076
68.9k
  if (! coff_mkobject (abfd))
2077
0
    return NULL;
2078
2079
68.9k
  coff = coff_data (abfd);
2080
2081
68.9k
  coff->sym_filepos = internal_f->f_symptr;
2082
2083
  /* These members communicate important constants about the symbol
2084
     table to GDB's symbol-reading code.  These `constants'
2085
     unfortunately vary among coff implementations...  */
2086
68.9k
  coff->local_n_btmask = N_BTMASK;
2087
68.9k
  coff->local_n_btshft = N_BTSHFT;
2088
68.9k
  coff->local_n_tmask = N_TMASK;
2089
68.9k
  coff->local_n_tshift = N_TSHIFT;
2090
68.9k
  coff->local_symesz = bfd_coff_symesz (abfd);
2091
68.9k
  coff->local_auxesz = bfd_coff_auxesz (abfd);
2092
68.9k
  coff->local_linesz = bfd_coff_linesz (abfd);
2093
2094
68.9k
  coff->timestamp = internal_f->f_timdat;
2095
2096
68.9k
  obj_raw_syment_count (abfd) =
2097
68.9k
    obj_conv_table_size (abfd) =
2098
68.9k
      internal_f->f_nsyms;
2099
2100
#ifdef RS6000COFF_C
2101
  if ((internal_f->f_flags & F_SHROBJ) != 0)
2102
    abfd->flags |= DYNAMIC;
2103
  if (aouthdr != NULL && internal_f->f_opthdr >= bfd_coff_aoutsz (abfd))
2104
    {
2105
      struct internal_aouthdr *internal_a =
2106
  (struct internal_aouthdr *) aouthdr;
2107
      struct xcoff_tdata *xcoff;
2108
2109
      xcoff = xcoff_data (abfd);
2110
# ifdef U803XTOCMAGIC
2111
      xcoff->xcoff64 = internal_f->f_magic == U803XTOCMAGIC;
2112
# else
2113
      xcoff->xcoff64 = 0;
2114
# endif
2115
      xcoff->full_aouthdr = true;
2116
      xcoff->toc = internal_a->o_toc;
2117
      xcoff->sntoc = internal_a->o_sntoc;
2118
      xcoff->snentry = internal_a->o_snentry;
2119
      bfd_xcoff_text_align_power (abfd) = internal_a->o_algntext;
2120
      bfd_xcoff_data_align_power (abfd) = internal_a->o_algndata;
2121
      xcoff->modtype = internal_a->o_modtype;
2122
      xcoff->cputype = internal_a->o_cputype;
2123
      xcoff->maxdata = internal_a->o_maxdata;
2124
      xcoff->maxstack = internal_a->o_maxstack;
2125
    }
2126
#endif
2127
2128
#ifdef ARM
2129
  /* Set the flags field from the COFF header read in.  */
2130
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
2131
    coff->flags = 0;
2132
#endif
2133
2134
#ifdef COFF_WITH_PE
2135
  /* FIXME: I'm not sure this is ever executed, since peicode.h
2136
     defines coff_mkobject_hook.  */
2137
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
2138
    abfd->flags |= HAS_DEBUG;
2139
#endif
2140
2141
68.9k
  return coff;
2142
68.9k
}
coff-rs6000.c:coff_mkobject_hook
Line
Count
Source
2072
97.3k
{
2073
97.3k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2074
97.3k
  coff_data_type *coff;
2075
2076
97.3k
  if (! coff_mkobject (abfd))
2077
0
    return NULL;
2078
2079
97.3k
  coff = coff_data (abfd);
2080
2081
97.3k
  coff->sym_filepos = internal_f->f_symptr;
2082
2083
  /* These members communicate important constants about the symbol
2084
     table to GDB's symbol-reading code.  These `constants'
2085
     unfortunately vary among coff implementations...  */
2086
97.3k
  coff->local_n_btmask = N_BTMASK;
2087
97.3k
  coff->local_n_btshft = N_BTSHFT;
2088
97.3k
  coff->local_n_tmask = N_TMASK;
2089
97.3k
  coff->local_n_tshift = N_TSHIFT;
2090
97.3k
  coff->local_symesz = bfd_coff_symesz (abfd);
2091
97.3k
  coff->local_auxesz = bfd_coff_auxesz (abfd);
2092
97.3k
  coff->local_linesz = bfd_coff_linesz (abfd);
2093
2094
97.3k
  coff->timestamp = internal_f->f_timdat;
2095
2096
97.3k
  obj_raw_syment_count (abfd) =
2097
97.3k
    obj_conv_table_size (abfd) =
2098
97.3k
      internal_f->f_nsyms;
2099
2100
97.3k
#ifdef RS6000COFF_C
2101
97.3k
  if ((internal_f->f_flags & F_SHROBJ) != 0)
2102
29.4k
    abfd->flags |= DYNAMIC;
2103
97.3k
  if (aouthdr != NULL && internal_f->f_opthdr >= bfd_coff_aoutsz (abfd))
2104
19.4k
    {
2105
19.4k
      struct internal_aouthdr *internal_a =
2106
19.4k
  (struct internal_aouthdr *) aouthdr;
2107
19.4k
      struct xcoff_tdata *xcoff;
2108
2109
19.4k
      xcoff = xcoff_data (abfd);
2110
# ifdef U803XTOCMAGIC
2111
      xcoff->xcoff64 = internal_f->f_magic == U803XTOCMAGIC;
2112
# else
2113
19.4k
      xcoff->xcoff64 = 0;
2114
19.4k
# endif
2115
19.4k
      xcoff->full_aouthdr = true;
2116
19.4k
      xcoff->toc = internal_a->o_toc;
2117
19.4k
      xcoff->sntoc = internal_a->o_sntoc;
2118
19.4k
      xcoff->snentry = internal_a->o_snentry;
2119
19.4k
      bfd_xcoff_text_align_power (abfd) = internal_a->o_algntext;
2120
19.4k
      bfd_xcoff_data_align_power (abfd) = internal_a->o_algndata;
2121
19.4k
      xcoff->modtype = internal_a->o_modtype;
2122
19.4k
      xcoff->cputype = internal_a->o_cputype;
2123
19.4k
      xcoff->maxdata = internal_a->o_maxdata;
2124
19.4k
      xcoff->maxstack = internal_a->o_maxstack;
2125
19.4k
    }
2126
97.3k
#endif
2127
2128
#ifdef ARM
2129
  /* Set the flags field from the COFF header read in.  */
2130
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
2131
    coff->flags = 0;
2132
#endif
2133
2134
#ifdef COFF_WITH_PE
2135
  /* FIXME: I'm not sure this is ever executed, since peicode.h
2136
     defines coff_mkobject_hook.  */
2137
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
2138
    abfd->flags |= HAS_DEBUG;
2139
#endif
2140
2141
97.3k
  return coff;
2142
97.3k
}
coff-sh.c:coff_mkobject_hook
Line
Count
Source
2072
86.9k
{
2073
86.9k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2074
86.9k
  coff_data_type *coff;
2075
2076
86.9k
  if (! coff_mkobject (abfd))
2077
0
    return NULL;
2078
2079
86.9k
  coff = coff_data (abfd);
2080
2081
86.9k
  coff->sym_filepos = internal_f->f_symptr;
2082
2083
  /* These members communicate important constants about the symbol
2084
     table to GDB's symbol-reading code.  These `constants'
2085
     unfortunately vary among coff implementations...  */
2086
86.9k
  coff->local_n_btmask = N_BTMASK;
2087
86.9k
  coff->local_n_btshft = N_BTSHFT;
2088
86.9k
  coff->local_n_tmask = N_TMASK;
2089
86.9k
  coff->local_n_tshift = N_TSHIFT;
2090
86.9k
  coff->local_symesz = bfd_coff_symesz (abfd);
2091
86.9k
  coff->local_auxesz = bfd_coff_auxesz (abfd);
2092
86.9k
  coff->local_linesz = bfd_coff_linesz (abfd);
2093
2094
86.9k
  coff->timestamp = internal_f->f_timdat;
2095
2096
86.9k
  obj_raw_syment_count (abfd) =
2097
86.9k
    obj_conv_table_size (abfd) =
2098
86.9k
      internal_f->f_nsyms;
2099
2100
#ifdef RS6000COFF_C
2101
  if ((internal_f->f_flags & F_SHROBJ) != 0)
2102
    abfd->flags |= DYNAMIC;
2103
  if (aouthdr != NULL && internal_f->f_opthdr >= bfd_coff_aoutsz (abfd))
2104
    {
2105
      struct internal_aouthdr *internal_a =
2106
  (struct internal_aouthdr *) aouthdr;
2107
      struct xcoff_tdata *xcoff;
2108
2109
      xcoff = xcoff_data (abfd);
2110
# ifdef U803XTOCMAGIC
2111
      xcoff->xcoff64 = internal_f->f_magic == U803XTOCMAGIC;
2112
# else
2113
      xcoff->xcoff64 = 0;
2114
# endif
2115
      xcoff->full_aouthdr = true;
2116
      xcoff->toc = internal_a->o_toc;
2117
      xcoff->sntoc = internal_a->o_sntoc;
2118
      xcoff->snentry = internal_a->o_snentry;
2119
      bfd_xcoff_text_align_power (abfd) = internal_a->o_algntext;
2120
      bfd_xcoff_data_align_power (abfd) = internal_a->o_algndata;
2121
      xcoff->modtype = internal_a->o_modtype;
2122
      xcoff->cputype = internal_a->o_cputype;
2123
      xcoff->maxdata = internal_a->o_maxdata;
2124
      xcoff->maxstack = internal_a->o_maxstack;
2125
    }
2126
#endif
2127
2128
#ifdef ARM
2129
  /* Set the flags field from the COFF header read in.  */
2130
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
2131
    coff->flags = 0;
2132
#endif
2133
2134
#ifdef COFF_WITH_PE
2135
  /* FIXME: I'm not sure this is ever executed, since peicode.h
2136
     defines coff_mkobject_hook.  */
2137
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
2138
    abfd->flags |= HAS_DEBUG;
2139
#endif
2140
2141
86.9k
  return coff;
2142
86.9k
}
coff-stgo32.c:coff_mkobject_hook
Line
Count
Source
2072
3.39k
{
2073
3.39k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2074
3.39k
  coff_data_type *coff;
2075
2076
3.39k
  if (! coff_mkobject (abfd))
2077
0
    return NULL;
2078
2079
3.39k
  coff = coff_data (abfd);
2080
2081
3.39k
  coff->sym_filepos = internal_f->f_symptr;
2082
2083
  /* These members communicate important constants about the symbol
2084
     table to GDB's symbol-reading code.  These `constants'
2085
     unfortunately vary among coff implementations...  */
2086
3.39k
  coff->local_n_btmask = N_BTMASK;
2087
3.39k
  coff->local_n_btshft = N_BTSHFT;
2088
3.39k
  coff->local_n_tmask = N_TMASK;
2089
3.39k
  coff->local_n_tshift = N_TSHIFT;
2090
3.39k
  coff->local_symesz = bfd_coff_symesz (abfd);
2091
3.39k
  coff->local_auxesz = bfd_coff_auxesz (abfd);
2092
3.39k
  coff->local_linesz = bfd_coff_linesz (abfd);
2093
2094
3.39k
  coff->timestamp = internal_f->f_timdat;
2095
2096
3.39k
  obj_raw_syment_count (abfd) =
2097
3.39k
    obj_conv_table_size (abfd) =
2098
3.39k
      internal_f->f_nsyms;
2099
2100
#ifdef RS6000COFF_C
2101
  if ((internal_f->f_flags & F_SHROBJ) != 0)
2102
    abfd->flags |= DYNAMIC;
2103
  if (aouthdr != NULL && internal_f->f_opthdr >= bfd_coff_aoutsz (abfd))
2104
    {
2105
      struct internal_aouthdr *internal_a =
2106
  (struct internal_aouthdr *) aouthdr;
2107
      struct xcoff_tdata *xcoff;
2108
2109
      xcoff = xcoff_data (abfd);
2110
# ifdef U803XTOCMAGIC
2111
      xcoff->xcoff64 = internal_f->f_magic == U803XTOCMAGIC;
2112
# else
2113
      xcoff->xcoff64 = 0;
2114
# endif
2115
      xcoff->full_aouthdr = true;
2116
      xcoff->toc = internal_a->o_toc;
2117
      xcoff->sntoc = internal_a->o_sntoc;
2118
      xcoff->snentry = internal_a->o_snentry;
2119
      bfd_xcoff_text_align_power (abfd) = internal_a->o_algntext;
2120
      bfd_xcoff_data_align_power (abfd) = internal_a->o_algndata;
2121
      xcoff->modtype = internal_a->o_modtype;
2122
      xcoff->cputype = internal_a->o_cputype;
2123
      xcoff->maxdata = internal_a->o_maxdata;
2124
      xcoff->maxstack = internal_a->o_maxstack;
2125
    }
2126
#endif
2127
2128
#ifdef ARM
2129
  /* Set the flags field from the COFF header read in.  */
2130
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
2131
    coff->flags = 0;
2132
#endif
2133
2134
#ifdef COFF_WITH_PE
2135
  /* FIXME: I'm not sure this is ever executed, since peicode.h
2136
     defines coff_mkobject_hook.  */
2137
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
2138
    abfd->flags |= HAS_DEBUG;
2139
#endif
2140
2141
3.39k
  return coff;
2142
3.39k
}
coff-tic30.c:coff_mkobject_hook
Line
Count
Source
2072
60.0k
{
2073
60.0k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2074
60.0k
  coff_data_type *coff;
2075
2076
60.0k
  if (! coff_mkobject (abfd))
2077
0
    return NULL;
2078
2079
60.0k
  coff = coff_data (abfd);
2080
2081
60.0k
  coff->sym_filepos = internal_f->f_symptr;
2082
2083
  /* These members communicate important constants about the symbol
2084
     table to GDB's symbol-reading code.  These `constants'
2085
     unfortunately vary among coff implementations...  */
2086
60.0k
  coff->local_n_btmask = N_BTMASK;
2087
60.0k
  coff->local_n_btshft = N_BTSHFT;
2088
60.0k
  coff->local_n_tmask = N_TMASK;
2089
60.0k
  coff->local_n_tshift = N_TSHIFT;
2090
60.0k
  coff->local_symesz = bfd_coff_symesz (abfd);
2091
60.0k
  coff->local_auxesz = bfd_coff_auxesz (abfd);
2092
60.0k
  coff->local_linesz = bfd_coff_linesz (abfd);
2093
2094
60.0k
  coff->timestamp = internal_f->f_timdat;
2095
2096
60.0k
  obj_raw_syment_count (abfd) =
2097
60.0k
    obj_conv_table_size (abfd) =
2098
60.0k
      internal_f->f_nsyms;
2099
2100
#ifdef RS6000COFF_C
2101
  if ((internal_f->f_flags & F_SHROBJ) != 0)
2102
    abfd->flags |= DYNAMIC;
2103
  if (aouthdr != NULL && internal_f->f_opthdr >= bfd_coff_aoutsz (abfd))
2104
    {
2105
      struct internal_aouthdr *internal_a =
2106
  (struct internal_aouthdr *) aouthdr;
2107
      struct xcoff_tdata *xcoff;
2108
2109
      xcoff = xcoff_data (abfd);
2110
# ifdef U803XTOCMAGIC
2111
      xcoff->xcoff64 = internal_f->f_magic == U803XTOCMAGIC;
2112
# else
2113
      xcoff->xcoff64 = 0;
2114
# endif
2115
      xcoff->full_aouthdr = true;
2116
      xcoff->toc = internal_a->o_toc;
2117
      xcoff->sntoc = internal_a->o_sntoc;
2118
      xcoff->snentry = internal_a->o_snentry;
2119
      bfd_xcoff_text_align_power (abfd) = internal_a->o_algntext;
2120
      bfd_xcoff_data_align_power (abfd) = internal_a->o_algndata;
2121
      xcoff->modtype = internal_a->o_modtype;
2122
      xcoff->cputype = internal_a->o_cputype;
2123
      xcoff->maxdata = internal_a->o_maxdata;
2124
      xcoff->maxstack = internal_a->o_maxstack;
2125
    }
2126
#endif
2127
2128
#ifdef ARM
2129
  /* Set the flags field from the COFF header read in.  */
2130
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
2131
    coff->flags = 0;
2132
#endif
2133
2134
#ifdef COFF_WITH_PE
2135
  /* FIXME: I'm not sure this is ever executed, since peicode.h
2136
     defines coff_mkobject_hook.  */
2137
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
2138
    abfd->flags |= HAS_DEBUG;
2139
#endif
2140
2141
60.0k
  return coff;
2142
60.0k
}
Unexecuted instantiation: coff-tic4x.c:coff_mkobject_hook
coff-tic54x.c:coff_mkobject_hook
Line
Count
Source
2072
116k
{
2073
116k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2074
116k
  coff_data_type *coff;
2075
2076
116k
  if (! coff_mkobject (abfd))
2077
0
    return NULL;
2078
2079
116k
  coff = coff_data (abfd);
2080
2081
116k
  coff->sym_filepos = internal_f->f_symptr;
2082
2083
  /* These members communicate important constants about the symbol
2084
     table to GDB's symbol-reading code.  These `constants'
2085
     unfortunately vary among coff implementations...  */
2086
116k
  coff->local_n_btmask = N_BTMASK;
2087
116k
  coff->local_n_btshft = N_BTSHFT;
2088
116k
  coff->local_n_tmask = N_TMASK;
2089
116k
  coff->local_n_tshift = N_TSHIFT;
2090
116k
  coff->local_symesz = bfd_coff_symesz (abfd);
2091
116k
  coff->local_auxesz = bfd_coff_auxesz (abfd);
2092
116k
  coff->local_linesz = bfd_coff_linesz (abfd);
2093
2094
116k
  coff->timestamp = internal_f->f_timdat;
2095
2096
116k
  obj_raw_syment_count (abfd) =
2097
116k
    obj_conv_table_size (abfd) =
2098
116k
      internal_f->f_nsyms;
2099
2100
#ifdef RS6000COFF_C
2101
  if ((internal_f->f_flags & F_SHROBJ) != 0)
2102
    abfd->flags |= DYNAMIC;
2103
  if (aouthdr != NULL && internal_f->f_opthdr >= bfd_coff_aoutsz (abfd))
2104
    {
2105
      struct internal_aouthdr *internal_a =
2106
  (struct internal_aouthdr *) aouthdr;
2107
      struct xcoff_tdata *xcoff;
2108
2109
      xcoff = xcoff_data (abfd);
2110
# ifdef U803XTOCMAGIC
2111
      xcoff->xcoff64 = internal_f->f_magic == U803XTOCMAGIC;
2112
# else
2113
      xcoff->xcoff64 = 0;
2114
# endif
2115
      xcoff->full_aouthdr = true;
2116
      xcoff->toc = internal_a->o_toc;
2117
      xcoff->sntoc = internal_a->o_sntoc;
2118
      xcoff->snentry = internal_a->o_snentry;
2119
      bfd_xcoff_text_align_power (abfd) = internal_a->o_algntext;
2120
      bfd_xcoff_data_align_power (abfd) = internal_a->o_algndata;
2121
      xcoff->modtype = internal_a->o_modtype;
2122
      xcoff->cputype = internal_a->o_cputype;
2123
      xcoff->maxdata = internal_a->o_maxdata;
2124
      xcoff->maxstack = internal_a->o_maxstack;
2125
    }
2126
#endif
2127
2128
#ifdef ARM
2129
  /* Set the flags field from the COFF header read in.  */
2130
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
2131
    coff->flags = 0;
2132
#endif
2133
2134
#ifdef COFF_WITH_PE
2135
  /* FIXME: I'm not sure this is ever executed, since peicode.h
2136
     defines coff_mkobject_hook.  */
2137
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
2138
    abfd->flags |= HAS_DEBUG;
2139
#endif
2140
2141
116k
  return coff;
2142
116k
}
coff-z80.c:coff_mkobject_hook
Line
Count
Source
2072
46.7k
{
2073
46.7k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2074
46.7k
  coff_data_type *coff;
2075
2076
46.7k
  if (! coff_mkobject (abfd))
2077
0
    return NULL;
2078
2079
46.7k
  coff = coff_data (abfd);
2080
2081
46.7k
  coff->sym_filepos = internal_f->f_symptr;
2082
2083
  /* These members communicate important constants about the symbol
2084
     table to GDB's symbol-reading code.  These `constants'
2085
     unfortunately vary among coff implementations...  */
2086
46.7k
  coff->local_n_btmask = N_BTMASK;
2087
46.7k
  coff->local_n_btshft = N_BTSHFT;
2088
46.7k
  coff->local_n_tmask = N_TMASK;
2089
46.7k
  coff->local_n_tshift = N_TSHIFT;
2090
46.7k
  coff->local_symesz = bfd_coff_symesz (abfd);
2091
46.7k
  coff->local_auxesz = bfd_coff_auxesz (abfd);
2092
46.7k
  coff->local_linesz = bfd_coff_linesz (abfd);
2093
2094
46.7k
  coff->timestamp = internal_f->f_timdat;
2095
2096
46.7k
  obj_raw_syment_count (abfd) =
2097
46.7k
    obj_conv_table_size (abfd) =
2098
46.7k
      internal_f->f_nsyms;
2099
2100
#ifdef RS6000COFF_C
2101
  if ((internal_f->f_flags & F_SHROBJ) != 0)
2102
    abfd->flags |= DYNAMIC;
2103
  if (aouthdr != NULL && internal_f->f_opthdr >= bfd_coff_aoutsz (abfd))
2104
    {
2105
      struct internal_aouthdr *internal_a =
2106
  (struct internal_aouthdr *) aouthdr;
2107
      struct xcoff_tdata *xcoff;
2108
2109
      xcoff = xcoff_data (abfd);
2110
# ifdef U803XTOCMAGIC
2111
      xcoff->xcoff64 = internal_f->f_magic == U803XTOCMAGIC;
2112
# else
2113
      xcoff->xcoff64 = 0;
2114
# endif
2115
      xcoff->full_aouthdr = true;
2116
      xcoff->toc = internal_a->o_toc;
2117
      xcoff->sntoc = internal_a->o_sntoc;
2118
      xcoff->snentry = internal_a->o_snentry;
2119
      bfd_xcoff_text_align_power (abfd) = internal_a->o_algntext;
2120
      bfd_xcoff_data_align_power (abfd) = internal_a->o_algndata;
2121
      xcoff->modtype = internal_a->o_modtype;
2122
      xcoff->cputype = internal_a->o_cputype;
2123
      xcoff->maxdata = internal_a->o_maxdata;
2124
      xcoff->maxstack = internal_a->o_maxstack;
2125
    }
2126
#endif
2127
2128
#ifdef ARM
2129
  /* Set the flags field from the COFF header read in.  */
2130
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
2131
    coff->flags = 0;
2132
#endif
2133
2134
#ifdef COFF_WITH_PE
2135
  /* FIXME: I'm not sure this is ever executed, since peicode.h
2136
     defines coff_mkobject_hook.  */
2137
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
2138
    abfd->flags |= HAS_DEBUG;
2139
#endif
2140
2141
46.7k
  return coff;
2142
46.7k
}
coff-z8k.c:coff_mkobject_hook
Line
Count
Source
2072
50.9k
{
2073
50.9k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2074
50.9k
  coff_data_type *coff;
2075
2076
50.9k
  if (! coff_mkobject (abfd))
2077
0
    return NULL;
2078
2079
50.9k
  coff = coff_data (abfd);
2080
2081
50.9k
  coff->sym_filepos = internal_f->f_symptr;
2082
2083
  /* These members communicate important constants about the symbol
2084
     table to GDB's symbol-reading code.  These `constants'
2085
     unfortunately vary among coff implementations...  */
2086
50.9k
  coff->local_n_btmask = N_BTMASK;
2087
50.9k
  coff->local_n_btshft = N_BTSHFT;
2088
50.9k
  coff->local_n_tmask = N_TMASK;
2089
50.9k
  coff->local_n_tshift = N_TSHIFT;
2090
50.9k
  coff->local_symesz = bfd_coff_symesz (abfd);
2091
50.9k
  coff->local_auxesz = bfd_coff_auxesz (abfd);
2092
50.9k
  coff->local_linesz = bfd_coff_linesz (abfd);
2093
2094
50.9k
  coff->timestamp = internal_f->f_timdat;
2095
2096
50.9k
  obj_raw_syment_count (abfd) =
2097
50.9k
    obj_conv_table_size (abfd) =
2098
50.9k
      internal_f->f_nsyms;
2099
2100
#ifdef RS6000COFF_C
2101
  if ((internal_f->f_flags & F_SHROBJ) != 0)
2102
    abfd->flags |= DYNAMIC;
2103
  if (aouthdr != NULL && internal_f->f_opthdr >= bfd_coff_aoutsz (abfd))
2104
    {
2105
      struct internal_aouthdr *internal_a =
2106
  (struct internal_aouthdr *) aouthdr;
2107
      struct xcoff_tdata *xcoff;
2108
2109
      xcoff = xcoff_data (abfd);
2110
# ifdef U803XTOCMAGIC
2111
      xcoff->xcoff64 = internal_f->f_magic == U803XTOCMAGIC;
2112
# else
2113
      xcoff->xcoff64 = 0;
2114
# endif
2115
      xcoff->full_aouthdr = true;
2116
      xcoff->toc = internal_a->o_toc;
2117
      xcoff->sntoc = internal_a->o_sntoc;
2118
      xcoff->snentry = internal_a->o_snentry;
2119
      bfd_xcoff_text_align_power (abfd) = internal_a->o_algntext;
2120
      bfd_xcoff_data_align_power (abfd) = internal_a->o_algndata;
2121
      xcoff->modtype = internal_a->o_modtype;
2122
      xcoff->cputype = internal_a->o_cputype;
2123
      xcoff->maxdata = internal_a->o_maxdata;
2124
      xcoff->maxstack = internal_a->o_maxstack;
2125
    }
2126
#endif
2127
2128
#ifdef ARM
2129
  /* Set the flags field from the COFF header read in.  */
2130
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
2131
    coff->flags = 0;
2132
#endif
2133
2134
#ifdef COFF_WITH_PE
2135
  /* FIXME: I'm not sure this is ever executed, since peicode.h
2136
     defines coff_mkobject_hook.  */
2137
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
2138
    abfd->flags |= HAS_DEBUG;
2139
#endif
2140
2141
50.9k
  return coff;
2142
50.9k
}
2143
#endif
2144
2145
/* Determine the machine architecture and type.  FIXME: This is target
2146
   dependent because the magic numbers are defined in the target
2147
   dependent header files.  But there is no particular need for this.
2148
   If the magic numbers were moved to a separate file, this function
2149
   would be target independent and would also be much more successful
2150
   at linking together COFF files for different architectures.  */
2151
2152
static bool
2153
coff_set_arch_mach_hook (bfd *abfd, void * filehdr)
2154
2.77M
{
2155
2.77M
  unsigned long machine;
2156
2.77M
  enum bfd_architecture arch;
2157
2.77M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2158
2159
  /* Zero selects the default machine for an arch.  */
2160
2.77M
  machine = 0;
2161
2.77M
  switch (internal_f->f_magic)
2162
2.77M
    {
2163
#ifdef I386MAGIC
2164
283k
    case I386MAGIC:
2165
310k
    case I386PTXMAGIC:
2166
337k
    case I386AIXMAGIC:   /* Danbury PS/2 AIX C Compiler.  */
2167
443k
    case LYNXCOFFMAGIC:
2168
447k
    case I386_APPLE_MAGIC:
2169
447k
    case I386_FREEBSD_MAGIC:
2170
447k
    case I386_LINUX_MAGIC:
2171
454k
    case I386_NETBSD_MAGIC:
2172
454k
      arch = bfd_arch_i386;
2173
454k
      break;
2174
0
#endif
2175
#ifdef AMD64MAGIC
2176
83.2k
    case AMD64MAGIC:
2177
588k
    case AMD64_APPLE_MAGIC:
2178
589k
    case AMD64_FREEBSD_MAGIC:
2179
655k
    case AMD64_LINUX_MAGIC:
2180
659k
    case AMD64_NETBSD_MAGIC:
2181
659k
      arch = bfd_arch_i386;
2182
659k
      machine = bfd_mach_x86_64;
2183
659k
      break;
2184
0
#endif
2185
#ifdef IA64MAGIC
2186
116k
    case IA64MAGIC:
2187
116k
      arch = bfd_arch_ia64;
2188
116k
      break;
2189
0
#endif
2190
#ifdef ARMMAGIC
2191
240k
    case ARMMAGIC:
2192
268k
    case ARMPEMAGIC:
2193
301k
    case THUMBPEMAGIC:
2194
301k
      arch = bfd_arch_arm;
2195
301k
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2196
301k
      if (machine == bfd_mach_arm_unknown)
2197
301k
  {
2198
301k
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2199
301k
      {
2200
19.0k
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2201
25.0k
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2202
24.0k
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2203
144k
      default:
2204
153k
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2205
17.3k
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2206
18.4k
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2207
        /* The COFF header does not have enough bits available
2208
     to cover all the different ARM architectures.  So
2209
     we interpret F_ARM_5, the highest flag value to mean
2210
     "the highest ARM architecture known to BFD" which is
2211
     currently the XScale.  */
2212
44.5k
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2213
301k
      }
2214
301k
  }
2215
301k
      break;
2216
301k
#endif
2217
#ifdef AARCH64MAGIC
2218
178k
    case AARCH64MAGIC:
2219
178k
      arch = bfd_arch_aarch64;
2220
178k
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2221
178k
      break;
2222
0
#endif
2223
#ifdef LOONGARCH64MAGIC
2224
97.3k
    case LOONGARCH64MAGIC:
2225
97.3k
      arch = bfd_arch_loongarch;
2226
97.3k
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2227
97.3k
      break;
2228
0
#endif
2229
#ifdef RISCV64MAGIC
2230
89.7k
    case RISCV64MAGIC:
2231
89.7k
      arch = bfd_arch_riscv;
2232
89.7k
      machine = bfd_mach_riscv64;
2233
89.7k
      break;
2234
0
#endif
2235
#ifdef Z80MAGIC
2236
46.4k
    case Z80MAGIC:
2237
46.4k
      arch = bfd_arch_z80;
2238
46.4k
      switch (internal_f->f_flags & F_MACHMASK)
2239
46.4k
  {
2240
3.41k
  case bfd_mach_z80strict << 12:
2241
8.49k
  case bfd_mach_z80 << 12:
2242
14.0k
  case bfd_mach_z80n << 12:
2243
20.0k
  case bfd_mach_z80full << 12:
2244
25.5k
  case bfd_mach_r800 << 12:
2245
29.6k
  case bfd_mach_gbz80 << 12:
2246
35.1k
  case bfd_mach_z180 << 12:
2247
41.9k
  case bfd_mach_ez80_z80 << 12:
2248
45.9k
  case bfd_mach_ez80_adl << 12:
2249
45.9k
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2250
45.9k
    break;
2251
518
  default:
2252
518
    return false;
2253
46.4k
  }
2254
45.9k
      break;
2255
45.9k
#endif
2256
#ifdef Z8KMAGIC
2257
50.5k
    case Z8KMAGIC:
2258
50.5k
      arch = bfd_arch_z8k;
2259
50.5k
      switch (internal_f->f_flags & F_MACHMASK)
2260
50.5k
  {
2261
19.4k
  case F_Z8001:
2262
19.4k
    machine = bfd_mach_z8001;
2263
19.4k
    break;
2264
30.5k
  case F_Z8002:
2265
30.5k
    machine = bfd_mach_z8002;
2266
30.5k
    break;
2267
527
  default:
2268
527
    return false;
2269
50.5k
  }
2270
49.9k
      break;
2271
49.9k
#endif
2272
2273
#ifdef RS6000COFF_C
2274
#ifdef XCOFF64
2275
92.8k
    case U64_TOCMAGIC:
2276
103k
    case U803XTOCMAGIC:
2277
#else
2278
42.0k
    case U802ROMAGIC:
2279
57.0k
    case U802WRMAGIC:
2280
96.2k
    case U802TOCMAGIC:
2281
#endif
2282
96.2k
      {
2283
96.2k
  int cputype;
2284
2285
199k
  if (xcoff_data (abfd)->cputype != -1)
2286
47.5k
    cputype = xcoff_data (abfd)->cputype & 0xff;
2287
152k
  else
2288
152k
    {
2289
      /* We did not get a value from the a.out header.  If the
2290
         file has not been stripped, we may be able to get the
2291
         architecture information from the first symbol, if it
2292
         is a .file symbol.  */
2293
152k
      if (obj_raw_syment_count (abfd) == 0)
2294
73.6k
        cputype = 0;
2295
78.7k
      else
2296
78.7k
        {
2297
78.7k
    bfd_byte *buf;
2298
78.7k
    struct internal_syment sym;
2299
78.7k
    bfd_size_type amt = bfd_coff_symesz (abfd);
2300
2301
78.7k
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2302
804
      return false;
2303
77.9k
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2304
77.9k
    if (buf == NULL)
2305
1.82k
      return false;
2306
76.0k
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2307
76.0k
    if (sym.n_sclass == C_FILE)
2308
3.23k
      cputype = sym.n_type & 0xff;
2309
72.8k
    else
2310
72.8k
      cputype = 0;
2311
76.0k
    free (buf);
2312
76.0k
        }
2313
152k
    }
2314
2315
  /* FIXME: We don't handle all cases here.  */
2316
197k
  switch (cputype)
2317
197k
    {
2318
27.4k
    default:
2319
184k
    case 0:
2320
184k
      arch = bfd_xcoff_architecture (abfd);
2321
184k
      machine = bfd_xcoff_machine (abfd);
2322
184k
      break;
2323
2324
3.80k
    case 1:
2325
3.80k
      arch = bfd_arch_powerpc;
2326
3.80k
      machine = bfd_mach_ppc_601;
2327
3.80k
      break;
2328
2.94k
    case 2: /* 64 bit PowerPC */
2329
2.94k
      arch = bfd_arch_powerpc;
2330
2.94k
      machine = bfd_mach_ppc_620;
2331
2.94k
      break;
2332
2.92k
    case 3:
2333
2.92k
      arch = bfd_arch_powerpc;
2334
2.92k
      machine = bfd_mach_ppc;
2335
2.92k
      break;
2336
3.13k
    case 4:
2337
3.13k
      arch = bfd_arch_rs6000;
2338
3.13k
      machine = bfd_mach_rs6k;
2339
3.13k
      break;
2340
197k
    }
2341
197k
      }
2342
197k
      break;
2343
197k
#endif
2344
2345
#ifdef SH_ARCH_MAGIC_BIG
2346
169k
    case SH_ARCH_MAGIC_BIG:
2347
184k
    case SH_ARCH_MAGIC_LITTLE:
2348
#ifdef COFF_WITH_PE
2349
157k
    case SH_ARCH_MAGIC_WINCE:
2350
#endif
2351
157k
      arch = bfd_arch_sh;
2352
157k
      break;
2353
0
#endif
2354
2355
#ifdef MIPS_ARCH_MAGIC_WINCE
2356
    case MIPS_ARCH_MAGIC_WINCE:
2357
      arch = bfd_arch_mips;
2358
      break;
2359
#endif
2360
2361
#ifdef SPARCMAGIC
2362
    case SPARCMAGIC:
2363
#ifdef LYNXCOFFMAGIC
2364
    case LYNXCOFFMAGIC:
2365
#endif
2366
      arch = bfd_arch_sparc;
2367
      break;
2368
#endif
2369
2370
#ifdef TIC30MAGIC
2371
59.4k
    case TIC30MAGIC:
2372
59.4k
      arch = bfd_arch_tic30;
2373
59.4k
      break;
2374
0
#endif
2375
2376
#ifdef TICOFF0MAGIC
2377
#ifdef TICOFF_TARGET_ARCH
2378
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2379
104k
    case TICOFF0MAGIC:
2380
104k
      arch = TICOFF_TARGET_ARCH;
2381
104k
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2382
104k
      break;
2383
0
#endif
2384
0
#endif
2385
2386
#ifdef TICOFF1MAGIC
2387
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2388
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2389
4.97k
    case TICOFF1MAGIC:
2390
5.68k
    case TICOFF2MAGIC:
2391
5.68k
      switch (internal_f->f_target_id)
2392
5.68k
  {
2393
0
#ifdef TI_TARGET_ID
2394
5.68k
  case TI_TARGET_ID:
2395
5.68k
    arch = TICOFF_TARGET_ARCH;
2396
5.68k
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2397
5.68k
    break;
2398
0
#endif
2399
0
  default:
2400
0
    arch = bfd_arch_obscure;
2401
0
    _bfd_error_handler
2402
0
      (_("unrecognized TI COFF target id '0x%x'"),
2403
0
       internal_f->f_target_id);
2404
0
    break;
2405
5.68k
  }
2406
5.68k
      break;
2407
5.68k
#endif
2408
2409
#ifdef MCOREMAGIC
2410
153k
    case MCOREMAGIC:
2411
153k
      arch = bfd_arch_mcore;
2412
153k
      break;
2413
0
#endif
2414
2415
39.9k
    default:      /* Unreadable input file type.  */
2416
39.9k
      arch = bfd_arch_obscure;
2417
39.9k
      break;
2418
2.77M
    }
2419
2420
2.77M
  bfd_default_set_arch_mach (abfd, arch, machine);
2421
2.77M
  return true;
2422
2.77M
}
pei-i386.c:coff_set_arch_mach_hook
Line
Count
Source
2154
159k
{
2155
159k
  unsigned long machine;
2156
159k
  enum bfd_architecture arch;
2157
159k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2158
2159
  /* Zero selects the default machine for an arch.  */
2160
159k
  machine = 0;
2161
159k
  switch (internal_f->f_magic)
2162
159k
    {
2163
0
#ifdef I386MAGIC
2164
68.4k
    case I386MAGIC:
2165
80.1k
    case I386PTXMAGIC:
2166
95.0k
    case I386AIXMAGIC:   /* Danbury PS/2 AIX C Compiler.  */
2167
153k
    case LYNXCOFFMAGIC:
2168
154k
    case I386_APPLE_MAGIC:
2169
154k
    case I386_FREEBSD_MAGIC:
2170
154k
    case I386_LINUX_MAGIC:
2171
159k
    case I386_NETBSD_MAGIC:
2172
159k
      arch = bfd_arch_i386;
2173
159k
      break;
2174
0
#endif
2175
#ifdef AMD64MAGIC
2176
    case AMD64MAGIC:
2177
    case AMD64_APPLE_MAGIC:
2178
    case AMD64_FREEBSD_MAGIC:
2179
    case AMD64_LINUX_MAGIC:
2180
    case AMD64_NETBSD_MAGIC:
2181
      arch = bfd_arch_i386;
2182
      machine = bfd_mach_x86_64;
2183
      break;
2184
#endif
2185
#ifdef IA64MAGIC
2186
    case IA64MAGIC:
2187
      arch = bfd_arch_ia64;
2188
      break;
2189
#endif
2190
#ifdef ARMMAGIC
2191
    case ARMMAGIC:
2192
    case ARMPEMAGIC:
2193
    case THUMBPEMAGIC:
2194
      arch = bfd_arch_arm;
2195
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2196
      if (machine == bfd_mach_arm_unknown)
2197
  {
2198
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2199
      {
2200
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2201
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2202
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2203
      default:
2204
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2205
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2206
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2207
        /* The COFF header does not have enough bits available
2208
     to cover all the different ARM architectures.  So
2209
     we interpret F_ARM_5, the highest flag value to mean
2210
     "the highest ARM architecture known to BFD" which is
2211
     currently the XScale.  */
2212
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2213
      }
2214
  }
2215
      break;
2216
#endif
2217
#ifdef AARCH64MAGIC
2218
    case AARCH64MAGIC:
2219
      arch = bfd_arch_aarch64;
2220
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2221
      break;
2222
#endif
2223
#ifdef LOONGARCH64MAGIC
2224
    case LOONGARCH64MAGIC:
2225
      arch = bfd_arch_loongarch;
2226
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2227
      break;
2228
#endif
2229
#ifdef RISCV64MAGIC
2230
    case RISCV64MAGIC:
2231
      arch = bfd_arch_riscv;
2232
      machine = bfd_mach_riscv64;
2233
      break;
2234
#endif
2235
#ifdef Z80MAGIC
2236
    case Z80MAGIC:
2237
      arch = bfd_arch_z80;
2238
      switch (internal_f->f_flags & F_MACHMASK)
2239
  {
2240
  case bfd_mach_z80strict << 12:
2241
  case bfd_mach_z80 << 12:
2242
  case bfd_mach_z80n << 12:
2243
  case bfd_mach_z80full << 12:
2244
  case bfd_mach_r800 << 12:
2245
  case bfd_mach_gbz80 << 12:
2246
  case bfd_mach_z180 << 12:
2247
  case bfd_mach_ez80_z80 << 12:
2248
  case bfd_mach_ez80_adl << 12:
2249
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2250
    break;
2251
  default:
2252
    return false;
2253
  }
2254
      break;
2255
#endif
2256
#ifdef Z8KMAGIC
2257
    case Z8KMAGIC:
2258
      arch = bfd_arch_z8k;
2259
      switch (internal_f->f_flags & F_MACHMASK)
2260
  {
2261
  case F_Z8001:
2262
    machine = bfd_mach_z8001;
2263
    break;
2264
  case F_Z8002:
2265
    machine = bfd_mach_z8002;
2266
    break;
2267
  default:
2268
    return false;
2269
  }
2270
      break;
2271
#endif
2272
2273
#ifdef RS6000COFF_C
2274
#ifdef XCOFF64
2275
    case U64_TOCMAGIC:
2276
    case U803XTOCMAGIC:
2277
#else
2278
    case U802ROMAGIC:
2279
    case U802WRMAGIC:
2280
    case U802TOCMAGIC:
2281
#endif
2282
      {
2283
  int cputype;
2284
2285
  if (xcoff_data (abfd)->cputype != -1)
2286
    cputype = xcoff_data (abfd)->cputype & 0xff;
2287
  else
2288
    {
2289
      /* We did not get a value from the a.out header.  If the
2290
         file has not been stripped, we may be able to get the
2291
         architecture information from the first symbol, if it
2292
         is a .file symbol.  */
2293
      if (obj_raw_syment_count (abfd) == 0)
2294
        cputype = 0;
2295
      else
2296
        {
2297
    bfd_byte *buf;
2298
    struct internal_syment sym;
2299
    bfd_size_type amt = bfd_coff_symesz (abfd);
2300
2301
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2302
      return false;
2303
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2304
    if (buf == NULL)
2305
      return false;
2306
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2307
    if (sym.n_sclass == C_FILE)
2308
      cputype = sym.n_type & 0xff;
2309
    else
2310
      cputype = 0;
2311
    free (buf);
2312
        }
2313
    }
2314
2315
  /* FIXME: We don't handle all cases here.  */
2316
  switch (cputype)
2317
    {
2318
    default:
2319
    case 0:
2320
      arch = bfd_xcoff_architecture (abfd);
2321
      machine = bfd_xcoff_machine (abfd);
2322
      break;
2323
2324
    case 1:
2325
      arch = bfd_arch_powerpc;
2326
      machine = bfd_mach_ppc_601;
2327
      break;
2328
    case 2: /* 64 bit PowerPC */
2329
      arch = bfd_arch_powerpc;
2330
      machine = bfd_mach_ppc_620;
2331
      break;
2332
    case 3:
2333
      arch = bfd_arch_powerpc;
2334
      machine = bfd_mach_ppc;
2335
      break;
2336
    case 4:
2337
      arch = bfd_arch_rs6000;
2338
      machine = bfd_mach_rs6k;
2339
      break;
2340
    }
2341
      }
2342
      break;
2343
#endif
2344
2345
#ifdef SH_ARCH_MAGIC_BIG
2346
    case SH_ARCH_MAGIC_BIG:
2347
    case SH_ARCH_MAGIC_LITTLE:
2348
#ifdef COFF_WITH_PE
2349
    case SH_ARCH_MAGIC_WINCE:
2350
#endif
2351
      arch = bfd_arch_sh;
2352
      break;
2353
#endif
2354
2355
#ifdef MIPS_ARCH_MAGIC_WINCE
2356
    case MIPS_ARCH_MAGIC_WINCE:
2357
      arch = bfd_arch_mips;
2358
      break;
2359
#endif
2360
2361
#ifdef SPARCMAGIC
2362
    case SPARCMAGIC:
2363
#ifdef LYNXCOFFMAGIC
2364
    case LYNXCOFFMAGIC:
2365
#endif
2366
      arch = bfd_arch_sparc;
2367
      break;
2368
#endif
2369
2370
#ifdef TIC30MAGIC
2371
    case TIC30MAGIC:
2372
      arch = bfd_arch_tic30;
2373
      break;
2374
#endif
2375
2376
#ifdef TICOFF0MAGIC
2377
#ifdef TICOFF_TARGET_ARCH
2378
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2379
    case TICOFF0MAGIC:
2380
      arch = TICOFF_TARGET_ARCH;
2381
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2382
      break;
2383
#endif
2384
#endif
2385
2386
#ifdef TICOFF1MAGIC
2387
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2388
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2389
    case TICOFF1MAGIC:
2390
    case TICOFF2MAGIC:
2391
      switch (internal_f->f_target_id)
2392
  {
2393
#ifdef TI_TARGET_ID
2394
  case TI_TARGET_ID:
2395
    arch = TICOFF_TARGET_ARCH;
2396
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2397
    break;
2398
#endif
2399
  default:
2400
    arch = bfd_arch_obscure;
2401
    _bfd_error_handler
2402
      (_("unrecognized TI COFF target id '0x%x'"),
2403
       internal_f->f_target_id);
2404
    break;
2405
  }
2406
      break;
2407
#endif
2408
2409
#ifdef MCOREMAGIC
2410
    case MCOREMAGIC:
2411
      arch = bfd_arch_mcore;
2412
      break;
2413
#endif
2414
2415
0
    default:      /* Unreadable input file type.  */
2416
0
      arch = bfd_arch_obscure;
2417
0
      break;
2418
159k
    }
2419
2420
159k
  bfd_default_set_arch_mach (abfd, arch, machine);
2421
159k
  return true;
2422
159k
}
pe-x86_64.c:coff_set_arch_mach_hook
Line
Count
Source
2154
276k
{
2155
276k
  unsigned long machine;
2156
276k
  enum bfd_architecture arch;
2157
276k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2158
2159
  /* Zero selects the default machine for an arch.  */
2160
276k
  machine = 0;
2161
276k
  switch (internal_f->f_magic)
2162
276k
    {
2163
#ifdef I386MAGIC
2164
    case I386MAGIC:
2165
    case I386PTXMAGIC:
2166
    case I386AIXMAGIC:    /* Danbury PS/2 AIX C Compiler.  */
2167
    case LYNXCOFFMAGIC:
2168
    case I386_APPLE_MAGIC:
2169
    case I386_FREEBSD_MAGIC:
2170
    case I386_LINUX_MAGIC:
2171
    case I386_NETBSD_MAGIC:
2172
      arch = bfd_arch_i386;
2173
      break;
2174
#endif
2175
0
#ifdef AMD64MAGIC
2176
12.0k
    case AMD64MAGIC:
2177
266k
    case AMD64_APPLE_MAGIC:
2178
267k
    case AMD64_FREEBSD_MAGIC:
2179
274k
    case AMD64_LINUX_MAGIC:
2180
276k
    case AMD64_NETBSD_MAGIC:
2181
276k
      arch = bfd_arch_i386;
2182
276k
      machine = bfd_mach_x86_64;
2183
276k
      break;
2184
0
#endif
2185
#ifdef IA64MAGIC
2186
    case IA64MAGIC:
2187
      arch = bfd_arch_ia64;
2188
      break;
2189
#endif
2190
#ifdef ARMMAGIC
2191
    case ARMMAGIC:
2192
    case ARMPEMAGIC:
2193
    case THUMBPEMAGIC:
2194
      arch = bfd_arch_arm;
2195
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2196
      if (machine == bfd_mach_arm_unknown)
2197
  {
2198
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2199
      {
2200
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2201
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2202
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2203
      default:
2204
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2205
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2206
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2207
        /* The COFF header does not have enough bits available
2208
     to cover all the different ARM architectures.  So
2209
     we interpret F_ARM_5, the highest flag value to mean
2210
     "the highest ARM architecture known to BFD" which is
2211
     currently the XScale.  */
2212
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2213
      }
2214
  }
2215
      break;
2216
#endif
2217
#ifdef AARCH64MAGIC
2218
    case AARCH64MAGIC:
2219
      arch = bfd_arch_aarch64;
2220
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2221
      break;
2222
#endif
2223
#ifdef LOONGARCH64MAGIC
2224
    case LOONGARCH64MAGIC:
2225
      arch = bfd_arch_loongarch;
2226
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2227
      break;
2228
#endif
2229
#ifdef RISCV64MAGIC
2230
    case RISCV64MAGIC:
2231
      arch = bfd_arch_riscv;
2232
      machine = bfd_mach_riscv64;
2233
      break;
2234
#endif
2235
#ifdef Z80MAGIC
2236
    case Z80MAGIC:
2237
      arch = bfd_arch_z80;
2238
      switch (internal_f->f_flags & F_MACHMASK)
2239
  {
2240
  case bfd_mach_z80strict << 12:
2241
  case bfd_mach_z80 << 12:
2242
  case bfd_mach_z80n << 12:
2243
  case bfd_mach_z80full << 12:
2244
  case bfd_mach_r800 << 12:
2245
  case bfd_mach_gbz80 << 12:
2246
  case bfd_mach_z180 << 12:
2247
  case bfd_mach_ez80_z80 << 12:
2248
  case bfd_mach_ez80_adl << 12:
2249
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2250
    break;
2251
  default:
2252
    return false;
2253
  }
2254
      break;
2255
#endif
2256
#ifdef Z8KMAGIC
2257
    case Z8KMAGIC:
2258
      arch = bfd_arch_z8k;
2259
      switch (internal_f->f_flags & F_MACHMASK)
2260
  {
2261
  case F_Z8001:
2262
    machine = bfd_mach_z8001;
2263
    break;
2264
  case F_Z8002:
2265
    machine = bfd_mach_z8002;
2266
    break;
2267
  default:
2268
    return false;
2269
  }
2270
      break;
2271
#endif
2272
2273
#ifdef RS6000COFF_C
2274
#ifdef XCOFF64
2275
    case U64_TOCMAGIC:
2276
    case U803XTOCMAGIC:
2277
#else
2278
    case U802ROMAGIC:
2279
    case U802WRMAGIC:
2280
    case U802TOCMAGIC:
2281
#endif
2282
      {
2283
  int cputype;
2284
2285
  if (xcoff_data (abfd)->cputype != -1)
2286
    cputype = xcoff_data (abfd)->cputype & 0xff;
2287
  else
2288
    {
2289
      /* We did not get a value from the a.out header.  If the
2290
         file has not been stripped, we may be able to get the
2291
         architecture information from the first symbol, if it
2292
         is a .file symbol.  */
2293
      if (obj_raw_syment_count (abfd) == 0)
2294
        cputype = 0;
2295
      else
2296
        {
2297
    bfd_byte *buf;
2298
    struct internal_syment sym;
2299
    bfd_size_type amt = bfd_coff_symesz (abfd);
2300
2301
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2302
      return false;
2303
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2304
    if (buf == NULL)
2305
      return false;
2306
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2307
    if (sym.n_sclass == C_FILE)
2308
      cputype = sym.n_type & 0xff;
2309
    else
2310
      cputype = 0;
2311
    free (buf);
2312
        }
2313
    }
2314
2315
  /* FIXME: We don't handle all cases here.  */
2316
  switch (cputype)
2317
    {
2318
    default:
2319
    case 0:
2320
      arch = bfd_xcoff_architecture (abfd);
2321
      machine = bfd_xcoff_machine (abfd);
2322
      break;
2323
2324
    case 1:
2325
      arch = bfd_arch_powerpc;
2326
      machine = bfd_mach_ppc_601;
2327
      break;
2328
    case 2: /* 64 bit PowerPC */
2329
      arch = bfd_arch_powerpc;
2330
      machine = bfd_mach_ppc_620;
2331
      break;
2332
    case 3:
2333
      arch = bfd_arch_powerpc;
2334
      machine = bfd_mach_ppc;
2335
      break;
2336
    case 4:
2337
      arch = bfd_arch_rs6000;
2338
      machine = bfd_mach_rs6k;
2339
      break;
2340
    }
2341
      }
2342
      break;
2343
#endif
2344
2345
#ifdef SH_ARCH_MAGIC_BIG
2346
    case SH_ARCH_MAGIC_BIG:
2347
    case SH_ARCH_MAGIC_LITTLE:
2348
#ifdef COFF_WITH_PE
2349
    case SH_ARCH_MAGIC_WINCE:
2350
#endif
2351
      arch = bfd_arch_sh;
2352
      break;
2353
#endif
2354
2355
#ifdef MIPS_ARCH_MAGIC_WINCE
2356
    case MIPS_ARCH_MAGIC_WINCE:
2357
      arch = bfd_arch_mips;
2358
      break;
2359
#endif
2360
2361
#ifdef SPARCMAGIC
2362
    case SPARCMAGIC:
2363
#ifdef LYNXCOFFMAGIC
2364
    case LYNXCOFFMAGIC:
2365
#endif
2366
      arch = bfd_arch_sparc;
2367
      break;
2368
#endif
2369
2370
#ifdef TIC30MAGIC
2371
    case TIC30MAGIC:
2372
      arch = bfd_arch_tic30;
2373
      break;
2374
#endif
2375
2376
#ifdef TICOFF0MAGIC
2377
#ifdef TICOFF_TARGET_ARCH
2378
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2379
    case TICOFF0MAGIC:
2380
      arch = TICOFF_TARGET_ARCH;
2381
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2382
      break;
2383
#endif
2384
#endif
2385
2386
#ifdef TICOFF1MAGIC
2387
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2388
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2389
    case TICOFF1MAGIC:
2390
    case TICOFF2MAGIC:
2391
      switch (internal_f->f_target_id)
2392
  {
2393
#ifdef TI_TARGET_ID
2394
  case TI_TARGET_ID:
2395
    arch = TICOFF_TARGET_ARCH;
2396
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2397
    break;
2398
#endif
2399
  default:
2400
    arch = bfd_arch_obscure;
2401
    _bfd_error_handler
2402
      (_("unrecognized TI COFF target id '0x%x'"),
2403
       internal_f->f_target_id);
2404
    break;
2405
  }
2406
      break;
2407
#endif
2408
2409
#ifdef MCOREMAGIC
2410
    case MCOREMAGIC:
2411
      arch = bfd_arch_mcore;
2412
      break;
2413
#endif
2414
2415
0
    default:      /* Unreadable input file type.  */
2416
0
      arch = bfd_arch_obscure;
2417
0
      break;
2418
276k
    }
2419
2420
276k
  bfd_default_set_arch_mach (abfd, arch, machine);
2421
276k
  return true;
2422
276k
}
pei-x86_64.c:coff_set_arch_mach_hook
Line
Count
Source
2154
169k
{
2155
169k
  unsigned long machine;
2156
169k
  enum bfd_architecture arch;
2157
169k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2158
2159
  /* Zero selects the default machine for an arch.  */
2160
169k
  machine = 0;
2161
169k
  switch (internal_f->f_magic)
2162
169k
    {
2163
#ifdef I386MAGIC
2164
    case I386MAGIC:
2165
    case I386PTXMAGIC:
2166
    case I386AIXMAGIC:    /* Danbury PS/2 AIX C Compiler.  */
2167
    case LYNXCOFFMAGIC:
2168
    case I386_APPLE_MAGIC:
2169
    case I386_FREEBSD_MAGIC:
2170
    case I386_LINUX_MAGIC:
2171
    case I386_NETBSD_MAGIC:
2172
      arch = bfd_arch_i386;
2173
      break;
2174
#endif
2175
0
#ifdef AMD64MAGIC
2176
62.1k
    case AMD64MAGIC:
2177
115k
    case AMD64_APPLE_MAGIC:
2178
115k
    case AMD64_FREEBSD_MAGIC:
2179
169k
    case AMD64_LINUX_MAGIC:
2180
169k
    case AMD64_NETBSD_MAGIC:
2181
169k
      arch = bfd_arch_i386;
2182
169k
      machine = bfd_mach_x86_64;
2183
169k
      break;
2184
0
#endif
2185
#ifdef IA64MAGIC
2186
    case IA64MAGIC:
2187
      arch = bfd_arch_ia64;
2188
      break;
2189
#endif
2190
#ifdef ARMMAGIC
2191
    case ARMMAGIC:
2192
    case ARMPEMAGIC:
2193
    case THUMBPEMAGIC:
2194
      arch = bfd_arch_arm;
2195
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2196
      if (machine == bfd_mach_arm_unknown)
2197
  {
2198
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2199
      {
2200
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2201
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2202
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2203
      default:
2204
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2205
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2206
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2207
        /* The COFF header does not have enough bits available
2208
     to cover all the different ARM architectures.  So
2209
     we interpret F_ARM_5, the highest flag value to mean
2210
     "the highest ARM architecture known to BFD" which is
2211
     currently the XScale.  */
2212
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2213
      }
2214
  }
2215
      break;
2216
#endif
2217
#ifdef AARCH64MAGIC
2218
    case AARCH64MAGIC:
2219
      arch = bfd_arch_aarch64;
2220
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2221
      break;
2222
#endif
2223
#ifdef LOONGARCH64MAGIC
2224
    case LOONGARCH64MAGIC:
2225
      arch = bfd_arch_loongarch;
2226
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2227
      break;
2228
#endif
2229
#ifdef RISCV64MAGIC
2230
    case RISCV64MAGIC:
2231
      arch = bfd_arch_riscv;
2232
      machine = bfd_mach_riscv64;
2233
      break;
2234
#endif
2235
#ifdef Z80MAGIC
2236
    case Z80MAGIC:
2237
      arch = bfd_arch_z80;
2238
      switch (internal_f->f_flags & F_MACHMASK)
2239
  {
2240
  case bfd_mach_z80strict << 12:
2241
  case bfd_mach_z80 << 12:
2242
  case bfd_mach_z80n << 12:
2243
  case bfd_mach_z80full << 12:
2244
  case bfd_mach_r800 << 12:
2245
  case bfd_mach_gbz80 << 12:
2246
  case bfd_mach_z180 << 12:
2247
  case bfd_mach_ez80_z80 << 12:
2248
  case bfd_mach_ez80_adl << 12:
2249
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2250
    break;
2251
  default:
2252
    return false;
2253
  }
2254
      break;
2255
#endif
2256
#ifdef Z8KMAGIC
2257
    case Z8KMAGIC:
2258
      arch = bfd_arch_z8k;
2259
      switch (internal_f->f_flags & F_MACHMASK)
2260
  {
2261
  case F_Z8001:
2262
    machine = bfd_mach_z8001;
2263
    break;
2264
  case F_Z8002:
2265
    machine = bfd_mach_z8002;
2266
    break;
2267
  default:
2268
    return false;
2269
  }
2270
      break;
2271
#endif
2272
2273
#ifdef RS6000COFF_C
2274
#ifdef XCOFF64
2275
    case U64_TOCMAGIC:
2276
    case U803XTOCMAGIC:
2277
#else
2278
    case U802ROMAGIC:
2279
    case U802WRMAGIC:
2280
    case U802TOCMAGIC:
2281
#endif
2282
      {
2283
  int cputype;
2284
2285
  if (xcoff_data (abfd)->cputype != -1)
2286
    cputype = xcoff_data (abfd)->cputype & 0xff;
2287
  else
2288
    {
2289
      /* We did not get a value from the a.out header.  If the
2290
         file has not been stripped, we may be able to get the
2291
         architecture information from the first symbol, if it
2292
         is a .file symbol.  */
2293
      if (obj_raw_syment_count (abfd) == 0)
2294
        cputype = 0;
2295
      else
2296
        {
2297
    bfd_byte *buf;
2298
    struct internal_syment sym;
2299
    bfd_size_type amt = bfd_coff_symesz (abfd);
2300
2301
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2302
      return false;
2303
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2304
    if (buf == NULL)
2305
      return false;
2306
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2307
    if (sym.n_sclass == C_FILE)
2308
      cputype = sym.n_type & 0xff;
2309
    else
2310
      cputype = 0;
2311
    free (buf);
2312
        }
2313
    }
2314
2315
  /* FIXME: We don't handle all cases here.  */
2316
  switch (cputype)
2317
    {
2318
    default:
2319
    case 0:
2320
      arch = bfd_xcoff_architecture (abfd);
2321
      machine = bfd_xcoff_machine (abfd);
2322
      break;
2323
2324
    case 1:
2325
      arch = bfd_arch_powerpc;
2326
      machine = bfd_mach_ppc_601;
2327
      break;
2328
    case 2: /* 64 bit PowerPC */
2329
      arch = bfd_arch_powerpc;
2330
      machine = bfd_mach_ppc_620;
2331
      break;
2332
    case 3:
2333
      arch = bfd_arch_powerpc;
2334
      machine = bfd_mach_ppc;
2335
      break;
2336
    case 4:
2337
      arch = bfd_arch_rs6000;
2338
      machine = bfd_mach_rs6k;
2339
      break;
2340
    }
2341
      }
2342
      break;
2343
#endif
2344
2345
#ifdef SH_ARCH_MAGIC_BIG
2346
    case SH_ARCH_MAGIC_BIG:
2347
    case SH_ARCH_MAGIC_LITTLE:
2348
#ifdef COFF_WITH_PE
2349
    case SH_ARCH_MAGIC_WINCE:
2350
#endif
2351
      arch = bfd_arch_sh;
2352
      break;
2353
#endif
2354
2355
#ifdef MIPS_ARCH_MAGIC_WINCE
2356
    case MIPS_ARCH_MAGIC_WINCE:
2357
      arch = bfd_arch_mips;
2358
      break;
2359
#endif
2360
2361
#ifdef SPARCMAGIC
2362
    case SPARCMAGIC:
2363
#ifdef LYNXCOFFMAGIC
2364
    case LYNXCOFFMAGIC:
2365
#endif
2366
      arch = bfd_arch_sparc;
2367
      break;
2368
#endif
2369
2370
#ifdef TIC30MAGIC
2371
    case TIC30MAGIC:
2372
      arch = bfd_arch_tic30;
2373
      break;
2374
#endif
2375
2376
#ifdef TICOFF0MAGIC
2377
#ifdef TICOFF_TARGET_ARCH
2378
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2379
    case TICOFF0MAGIC:
2380
      arch = TICOFF_TARGET_ARCH;
2381
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2382
      break;
2383
#endif
2384
#endif
2385
2386
#ifdef TICOFF1MAGIC
2387
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2388
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2389
    case TICOFF1MAGIC:
2390
    case TICOFF2MAGIC:
2391
      switch (internal_f->f_target_id)
2392
  {
2393
#ifdef TI_TARGET_ID
2394
  case TI_TARGET_ID:
2395
    arch = TICOFF_TARGET_ARCH;
2396
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2397
    break;
2398
#endif
2399
  default:
2400
    arch = bfd_arch_obscure;
2401
    _bfd_error_handler
2402
      (_("unrecognized TI COFF target id '0x%x'"),
2403
       internal_f->f_target_id);
2404
    break;
2405
  }
2406
      break;
2407
#endif
2408
2409
#ifdef MCOREMAGIC
2410
    case MCOREMAGIC:
2411
      arch = bfd_arch_mcore;
2412
      break;
2413
#endif
2414
2415
0
    default:      /* Unreadable input file type.  */
2416
0
      arch = bfd_arch_obscure;
2417
0
      break;
2418
169k
    }
2419
2420
169k
  bfd_default_set_arch_mach (abfd, arch, machine);
2421
169k
  return true;
2422
169k
}
coff-x86_64.c:coff_set_arch_mach_hook
Line
Count
Source
2154
213k
{
2155
213k
  unsigned long machine;
2156
213k
  enum bfd_architecture arch;
2157
213k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2158
2159
  /* Zero selects the default machine for an arch.  */
2160
213k
  machine = 0;
2161
213k
  switch (internal_f->f_magic)
2162
213k
    {
2163
#ifdef I386MAGIC
2164
    case I386MAGIC:
2165
    case I386PTXMAGIC:
2166
    case I386AIXMAGIC:    /* Danbury PS/2 AIX C Compiler.  */
2167
    case LYNXCOFFMAGIC:
2168
    case I386_APPLE_MAGIC:
2169
    case I386_FREEBSD_MAGIC:
2170
    case I386_LINUX_MAGIC:
2171
    case I386_NETBSD_MAGIC:
2172
      arch = bfd_arch_i386;
2173
      break;
2174
#endif
2175
0
#ifdef AMD64MAGIC
2176
9.11k
    case AMD64MAGIC:
2177
206k
    case AMD64_APPLE_MAGIC:
2178
207k
    case AMD64_FREEBSD_MAGIC:
2179
212k
    case AMD64_LINUX_MAGIC:
2180
213k
    case AMD64_NETBSD_MAGIC:
2181
213k
      arch = bfd_arch_i386;
2182
213k
      machine = bfd_mach_x86_64;
2183
213k
      break;
2184
0
#endif
2185
#ifdef IA64MAGIC
2186
    case IA64MAGIC:
2187
      arch = bfd_arch_ia64;
2188
      break;
2189
#endif
2190
#ifdef ARMMAGIC
2191
    case ARMMAGIC:
2192
    case ARMPEMAGIC:
2193
    case THUMBPEMAGIC:
2194
      arch = bfd_arch_arm;
2195
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2196
      if (machine == bfd_mach_arm_unknown)
2197
  {
2198
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2199
      {
2200
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2201
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2202
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2203
      default:
2204
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2205
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2206
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2207
        /* The COFF header does not have enough bits available
2208
     to cover all the different ARM architectures.  So
2209
     we interpret F_ARM_5, the highest flag value to mean
2210
     "the highest ARM architecture known to BFD" which is
2211
     currently the XScale.  */
2212
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2213
      }
2214
  }
2215
      break;
2216
#endif
2217
#ifdef AARCH64MAGIC
2218
    case AARCH64MAGIC:
2219
      arch = bfd_arch_aarch64;
2220
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2221
      break;
2222
#endif
2223
#ifdef LOONGARCH64MAGIC
2224
    case LOONGARCH64MAGIC:
2225
      arch = bfd_arch_loongarch;
2226
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2227
      break;
2228
#endif
2229
#ifdef RISCV64MAGIC
2230
    case RISCV64MAGIC:
2231
      arch = bfd_arch_riscv;
2232
      machine = bfd_mach_riscv64;
2233
      break;
2234
#endif
2235
#ifdef Z80MAGIC
2236
    case Z80MAGIC:
2237
      arch = bfd_arch_z80;
2238
      switch (internal_f->f_flags & F_MACHMASK)
2239
  {
2240
  case bfd_mach_z80strict << 12:
2241
  case bfd_mach_z80 << 12:
2242
  case bfd_mach_z80n << 12:
2243
  case bfd_mach_z80full << 12:
2244
  case bfd_mach_r800 << 12:
2245
  case bfd_mach_gbz80 << 12:
2246
  case bfd_mach_z180 << 12:
2247
  case bfd_mach_ez80_z80 << 12:
2248
  case bfd_mach_ez80_adl << 12:
2249
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2250
    break;
2251
  default:
2252
    return false;
2253
  }
2254
      break;
2255
#endif
2256
#ifdef Z8KMAGIC
2257
    case Z8KMAGIC:
2258
      arch = bfd_arch_z8k;
2259
      switch (internal_f->f_flags & F_MACHMASK)
2260
  {
2261
  case F_Z8001:
2262
    machine = bfd_mach_z8001;
2263
    break;
2264
  case F_Z8002:
2265
    machine = bfd_mach_z8002;
2266
    break;
2267
  default:
2268
    return false;
2269
  }
2270
      break;
2271
#endif
2272
2273
#ifdef RS6000COFF_C
2274
#ifdef XCOFF64
2275
    case U64_TOCMAGIC:
2276
    case U803XTOCMAGIC:
2277
#else
2278
    case U802ROMAGIC:
2279
    case U802WRMAGIC:
2280
    case U802TOCMAGIC:
2281
#endif
2282
      {
2283
  int cputype;
2284
2285
  if (xcoff_data (abfd)->cputype != -1)
2286
    cputype = xcoff_data (abfd)->cputype & 0xff;
2287
  else
2288
    {
2289
      /* We did not get a value from the a.out header.  If the
2290
         file has not been stripped, we may be able to get the
2291
         architecture information from the first symbol, if it
2292
         is a .file symbol.  */
2293
      if (obj_raw_syment_count (abfd) == 0)
2294
        cputype = 0;
2295
      else
2296
        {
2297
    bfd_byte *buf;
2298
    struct internal_syment sym;
2299
    bfd_size_type amt = bfd_coff_symesz (abfd);
2300
2301
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2302
      return false;
2303
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2304
    if (buf == NULL)
2305
      return false;
2306
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2307
    if (sym.n_sclass == C_FILE)
2308
      cputype = sym.n_type & 0xff;
2309
    else
2310
      cputype = 0;
2311
    free (buf);
2312
        }
2313
    }
2314
2315
  /* FIXME: We don't handle all cases here.  */
2316
  switch (cputype)
2317
    {
2318
    default:
2319
    case 0:
2320
      arch = bfd_xcoff_architecture (abfd);
2321
      machine = bfd_xcoff_machine (abfd);
2322
      break;
2323
2324
    case 1:
2325
      arch = bfd_arch_powerpc;
2326
      machine = bfd_mach_ppc_601;
2327
      break;
2328
    case 2: /* 64 bit PowerPC */
2329
      arch = bfd_arch_powerpc;
2330
      machine = bfd_mach_ppc_620;
2331
      break;
2332
    case 3:
2333
      arch = bfd_arch_powerpc;
2334
      machine = bfd_mach_ppc;
2335
      break;
2336
    case 4:
2337
      arch = bfd_arch_rs6000;
2338
      machine = bfd_mach_rs6k;
2339
      break;
2340
    }
2341
      }
2342
      break;
2343
#endif
2344
2345
#ifdef SH_ARCH_MAGIC_BIG
2346
    case SH_ARCH_MAGIC_BIG:
2347
    case SH_ARCH_MAGIC_LITTLE:
2348
#ifdef COFF_WITH_PE
2349
    case SH_ARCH_MAGIC_WINCE:
2350
#endif
2351
      arch = bfd_arch_sh;
2352
      break;
2353
#endif
2354
2355
#ifdef MIPS_ARCH_MAGIC_WINCE
2356
    case MIPS_ARCH_MAGIC_WINCE:
2357
      arch = bfd_arch_mips;
2358
      break;
2359
#endif
2360
2361
#ifdef SPARCMAGIC
2362
    case SPARCMAGIC:
2363
#ifdef LYNXCOFFMAGIC
2364
    case LYNXCOFFMAGIC:
2365
#endif
2366
      arch = bfd_arch_sparc;
2367
      break;
2368
#endif
2369
2370
#ifdef TIC30MAGIC
2371
    case TIC30MAGIC:
2372
      arch = bfd_arch_tic30;
2373
      break;
2374
#endif
2375
2376
#ifdef TICOFF0MAGIC
2377
#ifdef TICOFF_TARGET_ARCH
2378
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2379
    case TICOFF0MAGIC:
2380
      arch = TICOFF_TARGET_ARCH;
2381
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2382
      break;
2383
#endif
2384
#endif
2385
2386
#ifdef TICOFF1MAGIC
2387
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2388
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2389
    case TICOFF1MAGIC:
2390
    case TICOFF2MAGIC:
2391
      switch (internal_f->f_target_id)
2392
  {
2393
#ifdef TI_TARGET_ID
2394
  case TI_TARGET_ID:
2395
    arch = TICOFF_TARGET_ARCH;
2396
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2397
    break;
2398
#endif
2399
  default:
2400
    arch = bfd_arch_obscure;
2401
    _bfd_error_handler
2402
      (_("unrecognized TI COFF target id '0x%x'"),
2403
       internal_f->f_target_id);
2404
    break;
2405
  }
2406
      break;
2407
#endif
2408
2409
#ifdef MCOREMAGIC
2410
    case MCOREMAGIC:
2411
      arch = bfd_arch_mcore;
2412
      break;
2413
#endif
2414
2415
0
    default:      /* Unreadable input file type.  */
2416
0
      arch = bfd_arch_obscure;
2417
0
      break;
2418
213k
    }
2419
2420
213k
  bfd_default_set_arch_mach (abfd, arch, machine);
2421
213k
  return true;
2422
213k
}
coff64-rs6000.c:coff_set_arch_mach_hook
Line
Count
Source
2154
103k
{
2155
103k
  unsigned long machine;
2156
103k
  enum bfd_architecture arch;
2157
103k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2158
2159
  /* Zero selects the default machine for an arch.  */
2160
103k
  machine = 0;
2161
103k
  switch (internal_f->f_magic)
2162
103k
    {
2163
#ifdef I386MAGIC
2164
    case I386MAGIC:
2165
    case I386PTXMAGIC:
2166
    case I386AIXMAGIC:    /* Danbury PS/2 AIX C Compiler.  */
2167
    case LYNXCOFFMAGIC:
2168
    case I386_APPLE_MAGIC:
2169
    case I386_FREEBSD_MAGIC:
2170
    case I386_LINUX_MAGIC:
2171
    case I386_NETBSD_MAGIC:
2172
      arch = bfd_arch_i386;
2173
      break;
2174
#endif
2175
#ifdef AMD64MAGIC
2176
    case AMD64MAGIC:
2177
    case AMD64_APPLE_MAGIC:
2178
    case AMD64_FREEBSD_MAGIC:
2179
    case AMD64_LINUX_MAGIC:
2180
    case AMD64_NETBSD_MAGIC:
2181
      arch = bfd_arch_i386;
2182
      machine = bfd_mach_x86_64;
2183
      break;
2184
#endif
2185
#ifdef IA64MAGIC
2186
    case IA64MAGIC:
2187
      arch = bfd_arch_ia64;
2188
      break;
2189
#endif
2190
#ifdef ARMMAGIC
2191
    case ARMMAGIC:
2192
    case ARMPEMAGIC:
2193
    case THUMBPEMAGIC:
2194
      arch = bfd_arch_arm;
2195
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2196
      if (machine == bfd_mach_arm_unknown)
2197
  {
2198
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2199
      {
2200
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2201
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2202
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2203
      default:
2204
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2205
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2206
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2207
        /* The COFF header does not have enough bits available
2208
     to cover all the different ARM architectures.  So
2209
     we interpret F_ARM_5, the highest flag value to mean
2210
     "the highest ARM architecture known to BFD" which is
2211
     currently the XScale.  */
2212
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2213
      }
2214
  }
2215
      break;
2216
#endif
2217
#ifdef AARCH64MAGIC
2218
    case AARCH64MAGIC:
2219
      arch = bfd_arch_aarch64;
2220
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2221
      break;
2222
#endif
2223
#ifdef LOONGARCH64MAGIC
2224
    case LOONGARCH64MAGIC:
2225
      arch = bfd_arch_loongarch;
2226
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2227
      break;
2228
#endif
2229
#ifdef RISCV64MAGIC
2230
    case RISCV64MAGIC:
2231
      arch = bfd_arch_riscv;
2232
      machine = bfd_mach_riscv64;
2233
      break;
2234
#endif
2235
#ifdef Z80MAGIC
2236
    case Z80MAGIC:
2237
      arch = bfd_arch_z80;
2238
      switch (internal_f->f_flags & F_MACHMASK)
2239
  {
2240
  case bfd_mach_z80strict << 12:
2241
  case bfd_mach_z80 << 12:
2242
  case bfd_mach_z80n << 12:
2243
  case bfd_mach_z80full << 12:
2244
  case bfd_mach_r800 << 12:
2245
  case bfd_mach_gbz80 << 12:
2246
  case bfd_mach_z180 << 12:
2247
  case bfd_mach_ez80_z80 << 12:
2248
  case bfd_mach_ez80_adl << 12:
2249
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2250
    break;
2251
  default:
2252
    return false;
2253
  }
2254
      break;
2255
#endif
2256
#ifdef Z8KMAGIC
2257
    case Z8KMAGIC:
2258
      arch = bfd_arch_z8k;
2259
      switch (internal_f->f_flags & F_MACHMASK)
2260
  {
2261
  case F_Z8001:
2262
    machine = bfd_mach_z8001;
2263
    break;
2264
  case F_Z8002:
2265
    machine = bfd_mach_z8002;
2266
    break;
2267
  default:
2268
    return false;
2269
  }
2270
      break;
2271
#endif
2272
2273
0
#ifdef RS6000COFF_C
2274
0
#ifdef XCOFF64
2275
92.8k
    case U64_TOCMAGIC:
2276
103k
    case U803XTOCMAGIC:
2277
#else
2278
    case U802ROMAGIC:
2279
    case U802WRMAGIC:
2280
    case U802TOCMAGIC:
2281
#endif
2282
103k
      {
2283
103k
  int cputype;
2284
2285
103k
  if (xcoff_data (abfd)->cputype != -1)
2286
28.2k
    cputype = xcoff_data (abfd)->cputype & 0xff;
2287
75.3k
  else
2288
75.3k
    {
2289
      /* We did not get a value from the a.out header.  If the
2290
         file has not been stripped, we may be able to get the
2291
         architecture information from the first symbol, if it
2292
         is a .file symbol.  */
2293
75.3k
      if (obj_raw_syment_count (abfd) == 0)
2294
43.4k
        cputype = 0;
2295
31.9k
      else
2296
31.9k
        {
2297
31.9k
    bfd_byte *buf;
2298
31.9k
    struct internal_syment sym;
2299
31.9k
    bfd_size_type amt = bfd_coff_symesz (abfd);
2300
2301
31.9k
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2302
804
      return false;
2303
31.1k
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2304
31.1k
    if (buf == NULL)
2305
874
      return false;
2306
30.2k
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2307
30.2k
    if (sym.n_sclass == C_FILE)
2308
1.67k
      cputype = sym.n_type & 0xff;
2309
28.5k
    else
2310
28.5k
      cputype = 0;
2311
30.2k
    free (buf);
2312
30.2k
        }
2313
75.3k
    }
2314
2315
  /* FIXME: We don't handle all cases here.  */
2316
101k
  switch (cputype)
2317
101k
    {
2318
16.5k
    default:
2319
93.9k
    case 0:
2320
93.9k
      arch = bfd_xcoff_architecture (abfd);
2321
93.9k
      machine = bfd_xcoff_machine (abfd);
2322
93.9k
      break;
2323
2324
2.46k
    case 1:
2325
2.46k
      arch = bfd_arch_powerpc;
2326
2.46k
      machine = bfd_mach_ppc_601;
2327
2.46k
      break;
2328
1.48k
    case 2: /* 64 bit PowerPC */
2329
1.48k
      arch = bfd_arch_powerpc;
2330
1.48k
      machine = bfd_mach_ppc_620;
2331
1.48k
      break;
2332
1.97k
    case 3:
2333
1.97k
      arch = bfd_arch_powerpc;
2334
1.97k
      machine = bfd_mach_ppc;
2335
1.97k
      break;
2336
2.09k
    case 4:
2337
2.09k
      arch = bfd_arch_rs6000;
2338
2.09k
      machine = bfd_mach_rs6k;
2339
2.09k
      break;
2340
101k
    }
2341
101k
      }
2342
101k
      break;
2343
101k
#endif
2344
2345
#ifdef SH_ARCH_MAGIC_BIG
2346
    case SH_ARCH_MAGIC_BIG:
2347
    case SH_ARCH_MAGIC_LITTLE:
2348
#ifdef COFF_WITH_PE
2349
    case SH_ARCH_MAGIC_WINCE:
2350
#endif
2351
      arch = bfd_arch_sh;
2352
      break;
2353
#endif
2354
2355
#ifdef MIPS_ARCH_MAGIC_WINCE
2356
    case MIPS_ARCH_MAGIC_WINCE:
2357
      arch = bfd_arch_mips;
2358
      break;
2359
#endif
2360
2361
#ifdef SPARCMAGIC
2362
    case SPARCMAGIC:
2363
#ifdef LYNXCOFFMAGIC
2364
    case LYNXCOFFMAGIC:
2365
#endif
2366
      arch = bfd_arch_sparc;
2367
      break;
2368
#endif
2369
2370
#ifdef TIC30MAGIC
2371
    case TIC30MAGIC:
2372
      arch = bfd_arch_tic30;
2373
      break;
2374
#endif
2375
2376
#ifdef TICOFF0MAGIC
2377
#ifdef TICOFF_TARGET_ARCH
2378
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2379
    case TICOFF0MAGIC:
2380
      arch = TICOFF_TARGET_ARCH;
2381
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2382
      break;
2383
#endif
2384
#endif
2385
2386
#ifdef TICOFF1MAGIC
2387
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2388
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2389
    case TICOFF1MAGIC:
2390
    case TICOFF2MAGIC:
2391
      switch (internal_f->f_target_id)
2392
  {
2393
#ifdef TI_TARGET_ID
2394
  case TI_TARGET_ID:
2395
    arch = TICOFF_TARGET_ARCH;
2396
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2397
    break;
2398
#endif
2399
  default:
2400
    arch = bfd_arch_obscure;
2401
    _bfd_error_handler
2402
      (_("unrecognized TI COFF target id '0x%x'"),
2403
       internal_f->f_target_id);
2404
    break;
2405
  }
2406
      break;
2407
#endif
2408
2409
#ifdef MCOREMAGIC
2410
    case MCOREMAGIC:
2411
      arch = bfd_arch_mcore;
2412
      break;
2413
#endif
2414
2415
101k
    default:      /* Unreadable input file type.  */
2416
0
      arch = bfd_arch_obscure;
2417
0
      break;
2418
103k
    }
2419
2420
101k
  bfd_default_set_arch_mach (abfd, arch, machine);
2421
101k
  return true;
2422
103k
}
pe-aarch64.c:coff_set_arch_mach_hook
Line
Count
Source
2154
66.9k
{
2155
66.9k
  unsigned long machine;
2156
66.9k
  enum bfd_architecture arch;
2157
66.9k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2158
2159
  /* Zero selects the default machine for an arch.  */
2160
66.9k
  machine = 0;
2161
66.9k
  switch (internal_f->f_magic)
2162
66.9k
    {
2163
#ifdef I386MAGIC
2164
    case I386MAGIC:
2165
    case I386PTXMAGIC:
2166
    case I386AIXMAGIC:    /* Danbury PS/2 AIX C Compiler.  */
2167
    case LYNXCOFFMAGIC:
2168
    case I386_APPLE_MAGIC:
2169
    case I386_FREEBSD_MAGIC:
2170
    case I386_LINUX_MAGIC:
2171
    case I386_NETBSD_MAGIC:
2172
      arch = bfd_arch_i386;
2173
      break;
2174
#endif
2175
#ifdef AMD64MAGIC
2176
    case AMD64MAGIC:
2177
    case AMD64_APPLE_MAGIC:
2178
    case AMD64_FREEBSD_MAGIC:
2179
    case AMD64_LINUX_MAGIC:
2180
    case AMD64_NETBSD_MAGIC:
2181
      arch = bfd_arch_i386;
2182
      machine = bfd_mach_x86_64;
2183
      break;
2184
#endif
2185
#ifdef IA64MAGIC
2186
    case IA64MAGIC:
2187
      arch = bfd_arch_ia64;
2188
      break;
2189
#endif
2190
#ifdef ARMMAGIC
2191
    case ARMMAGIC:
2192
    case ARMPEMAGIC:
2193
    case THUMBPEMAGIC:
2194
      arch = bfd_arch_arm;
2195
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2196
      if (machine == bfd_mach_arm_unknown)
2197
  {
2198
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2199
      {
2200
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2201
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2202
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2203
      default:
2204
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2205
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2206
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2207
        /* The COFF header does not have enough bits available
2208
     to cover all the different ARM architectures.  So
2209
     we interpret F_ARM_5, the highest flag value to mean
2210
     "the highest ARM architecture known to BFD" which is
2211
     currently the XScale.  */
2212
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2213
      }
2214
  }
2215
      break;
2216
#endif
2217
0
#ifdef AARCH64MAGIC
2218
66.9k
    case AARCH64MAGIC:
2219
66.9k
      arch = bfd_arch_aarch64;
2220
66.9k
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2221
66.9k
      break;
2222
0
#endif
2223
#ifdef LOONGARCH64MAGIC
2224
    case LOONGARCH64MAGIC:
2225
      arch = bfd_arch_loongarch;
2226
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2227
      break;
2228
#endif
2229
#ifdef RISCV64MAGIC
2230
    case RISCV64MAGIC:
2231
      arch = bfd_arch_riscv;
2232
      machine = bfd_mach_riscv64;
2233
      break;
2234
#endif
2235
#ifdef Z80MAGIC
2236
    case Z80MAGIC:
2237
      arch = bfd_arch_z80;
2238
      switch (internal_f->f_flags & F_MACHMASK)
2239
  {
2240
  case bfd_mach_z80strict << 12:
2241
  case bfd_mach_z80 << 12:
2242
  case bfd_mach_z80n << 12:
2243
  case bfd_mach_z80full << 12:
2244
  case bfd_mach_r800 << 12:
2245
  case bfd_mach_gbz80 << 12:
2246
  case bfd_mach_z180 << 12:
2247
  case bfd_mach_ez80_z80 << 12:
2248
  case bfd_mach_ez80_adl << 12:
2249
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2250
    break;
2251
  default:
2252
    return false;
2253
  }
2254
      break;
2255
#endif
2256
#ifdef Z8KMAGIC
2257
    case Z8KMAGIC:
2258
      arch = bfd_arch_z8k;
2259
      switch (internal_f->f_flags & F_MACHMASK)
2260
  {
2261
  case F_Z8001:
2262
    machine = bfd_mach_z8001;
2263
    break;
2264
  case F_Z8002:
2265
    machine = bfd_mach_z8002;
2266
    break;
2267
  default:
2268
    return false;
2269
  }
2270
      break;
2271
#endif
2272
2273
#ifdef RS6000COFF_C
2274
#ifdef XCOFF64
2275
    case U64_TOCMAGIC:
2276
    case U803XTOCMAGIC:
2277
#else
2278
    case U802ROMAGIC:
2279
    case U802WRMAGIC:
2280
    case U802TOCMAGIC:
2281
#endif
2282
      {
2283
  int cputype;
2284
2285
  if (xcoff_data (abfd)->cputype != -1)
2286
    cputype = xcoff_data (abfd)->cputype & 0xff;
2287
  else
2288
    {
2289
      /* We did not get a value from the a.out header.  If the
2290
         file has not been stripped, we may be able to get the
2291
         architecture information from the first symbol, if it
2292
         is a .file symbol.  */
2293
      if (obj_raw_syment_count (abfd) == 0)
2294
        cputype = 0;
2295
      else
2296
        {
2297
    bfd_byte *buf;
2298
    struct internal_syment sym;
2299
    bfd_size_type amt = bfd_coff_symesz (abfd);
2300
2301
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2302
      return false;
2303
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2304
    if (buf == NULL)
2305
      return false;
2306
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2307
    if (sym.n_sclass == C_FILE)
2308
      cputype = sym.n_type & 0xff;
2309
    else
2310
      cputype = 0;
2311
    free (buf);
2312
        }
2313
    }
2314
2315
  /* FIXME: We don't handle all cases here.  */
2316
  switch (cputype)
2317
    {
2318
    default:
2319
    case 0:
2320
      arch = bfd_xcoff_architecture (abfd);
2321
      machine = bfd_xcoff_machine (abfd);
2322
      break;
2323
2324
    case 1:
2325
      arch = bfd_arch_powerpc;
2326
      machine = bfd_mach_ppc_601;
2327
      break;
2328
    case 2: /* 64 bit PowerPC */
2329
      arch = bfd_arch_powerpc;
2330
      machine = bfd_mach_ppc_620;
2331
      break;
2332
    case 3:
2333
      arch = bfd_arch_powerpc;
2334
      machine = bfd_mach_ppc;
2335
      break;
2336
    case 4:
2337
      arch = bfd_arch_rs6000;
2338
      machine = bfd_mach_rs6k;
2339
      break;
2340
    }
2341
      }
2342
      break;
2343
#endif
2344
2345
#ifdef SH_ARCH_MAGIC_BIG
2346
    case SH_ARCH_MAGIC_BIG:
2347
    case SH_ARCH_MAGIC_LITTLE:
2348
#ifdef COFF_WITH_PE
2349
    case SH_ARCH_MAGIC_WINCE:
2350
#endif
2351
      arch = bfd_arch_sh;
2352
      break;
2353
#endif
2354
2355
#ifdef MIPS_ARCH_MAGIC_WINCE
2356
    case MIPS_ARCH_MAGIC_WINCE:
2357
      arch = bfd_arch_mips;
2358
      break;
2359
#endif
2360
2361
#ifdef SPARCMAGIC
2362
    case SPARCMAGIC:
2363
#ifdef LYNXCOFFMAGIC
2364
    case LYNXCOFFMAGIC:
2365
#endif
2366
      arch = bfd_arch_sparc;
2367
      break;
2368
#endif
2369
2370
#ifdef TIC30MAGIC
2371
    case TIC30MAGIC:
2372
      arch = bfd_arch_tic30;
2373
      break;
2374
#endif
2375
2376
#ifdef TICOFF0MAGIC
2377
#ifdef TICOFF_TARGET_ARCH
2378
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2379
    case TICOFF0MAGIC:
2380
      arch = TICOFF_TARGET_ARCH;
2381
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2382
      break;
2383
#endif
2384
#endif
2385
2386
#ifdef TICOFF1MAGIC
2387
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2388
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2389
    case TICOFF1MAGIC:
2390
    case TICOFF2MAGIC:
2391
      switch (internal_f->f_target_id)
2392
  {
2393
#ifdef TI_TARGET_ID
2394
  case TI_TARGET_ID:
2395
    arch = TICOFF_TARGET_ARCH;
2396
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2397
    break;
2398
#endif
2399
  default:
2400
    arch = bfd_arch_obscure;
2401
    _bfd_error_handler
2402
      (_("unrecognized TI COFF target id '0x%x'"),
2403
       internal_f->f_target_id);
2404
    break;
2405
  }
2406
      break;
2407
#endif
2408
2409
#ifdef MCOREMAGIC
2410
    case MCOREMAGIC:
2411
      arch = bfd_arch_mcore;
2412
      break;
2413
#endif
2414
2415
0
    default:      /* Unreadable input file type.  */
2416
0
      arch = bfd_arch_obscure;
2417
0
      break;
2418
66.9k
    }
2419
2420
66.9k
  bfd_default_set_arch_mach (abfd, arch, machine);
2421
66.9k
  return true;
2422
66.9k
}
pei-aarch64.c:coff_set_arch_mach_hook
Line
Count
Source
2154
111k
{
2155
111k
  unsigned long machine;
2156
111k
  enum bfd_architecture arch;
2157
111k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2158
2159
  /* Zero selects the default machine for an arch.  */
2160
111k
  machine = 0;
2161
111k
  switch (internal_f->f_magic)
2162
111k
    {
2163
#ifdef I386MAGIC
2164
    case I386MAGIC:
2165
    case I386PTXMAGIC:
2166
    case I386AIXMAGIC:    /* Danbury PS/2 AIX C Compiler.  */
2167
    case LYNXCOFFMAGIC:
2168
    case I386_APPLE_MAGIC:
2169
    case I386_FREEBSD_MAGIC:
2170
    case I386_LINUX_MAGIC:
2171
    case I386_NETBSD_MAGIC:
2172
      arch = bfd_arch_i386;
2173
      break;
2174
#endif
2175
#ifdef AMD64MAGIC
2176
    case AMD64MAGIC:
2177
    case AMD64_APPLE_MAGIC:
2178
    case AMD64_FREEBSD_MAGIC:
2179
    case AMD64_LINUX_MAGIC:
2180
    case AMD64_NETBSD_MAGIC:
2181
      arch = bfd_arch_i386;
2182
      machine = bfd_mach_x86_64;
2183
      break;
2184
#endif
2185
#ifdef IA64MAGIC
2186
    case IA64MAGIC:
2187
      arch = bfd_arch_ia64;
2188
      break;
2189
#endif
2190
#ifdef ARMMAGIC
2191
    case ARMMAGIC:
2192
    case ARMPEMAGIC:
2193
    case THUMBPEMAGIC:
2194
      arch = bfd_arch_arm;
2195
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2196
      if (machine == bfd_mach_arm_unknown)
2197
  {
2198
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2199
      {
2200
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2201
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2202
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2203
      default:
2204
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2205
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2206
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2207
        /* The COFF header does not have enough bits available
2208
     to cover all the different ARM architectures.  So
2209
     we interpret F_ARM_5, the highest flag value to mean
2210
     "the highest ARM architecture known to BFD" which is
2211
     currently the XScale.  */
2212
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2213
      }
2214
  }
2215
      break;
2216
#endif
2217
0
#ifdef AARCH64MAGIC
2218
111k
    case AARCH64MAGIC:
2219
111k
      arch = bfd_arch_aarch64;
2220
111k
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2221
111k
      break;
2222
0
#endif
2223
#ifdef LOONGARCH64MAGIC
2224
    case LOONGARCH64MAGIC:
2225
      arch = bfd_arch_loongarch;
2226
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2227
      break;
2228
#endif
2229
#ifdef RISCV64MAGIC
2230
    case RISCV64MAGIC:
2231
      arch = bfd_arch_riscv;
2232
      machine = bfd_mach_riscv64;
2233
      break;
2234
#endif
2235
#ifdef Z80MAGIC
2236
    case Z80MAGIC:
2237
      arch = bfd_arch_z80;
2238
      switch (internal_f->f_flags & F_MACHMASK)
2239
  {
2240
  case bfd_mach_z80strict << 12:
2241
  case bfd_mach_z80 << 12:
2242
  case bfd_mach_z80n << 12:
2243
  case bfd_mach_z80full << 12:
2244
  case bfd_mach_r800 << 12:
2245
  case bfd_mach_gbz80 << 12:
2246
  case bfd_mach_z180 << 12:
2247
  case bfd_mach_ez80_z80 << 12:
2248
  case bfd_mach_ez80_adl << 12:
2249
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2250
    break;
2251
  default:
2252
    return false;
2253
  }
2254
      break;
2255
#endif
2256
#ifdef Z8KMAGIC
2257
    case Z8KMAGIC:
2258
      arch = bfd_arch_z8k;
2259
      switch (internal_f->f_flags & F_MACHMASK)
2260
  {
2261
  case F_Z8001:
2262
    machine = bfd_mach_z8001;
2263
    break;
2264
  case F_Z8002:
2265
    machine = bfd_mach_z8002;
2266
    break;
2267
  default:
2268
    return false;
2269
  }
2270
      break;
2271
#endif
2272
2273
#ifdef RS6000COFF_C
2274
#ifdef XCOFF64
2275
    case U64_TOCMAGIC:
2276
    case U803XTOCMAGIC:
2277
#else
2278
    case U802ROMAGIC:
2279
    case U802WRMAGIC:
2280
    case U802TOCMAGIC:
2281
#endif
2282
      {
2283
  int cputype;
2284
2285
  if (xcoff_data (abfd)->cputype != -1)
2286
    cputype = xcoff_data (abfd)->cputype & 0xff;
2287
  else
2288
    {
2289
      /* We did not get a value from the a.out header.  If the
2290
         file has not been stripped, we may be able to get the
2291
         architecture information from the first symbol, if it
2292
         is a .file symbol.  */
2293
      if (obj_raw_syment_count (abfd) == 0)
2294
        cputype = 0;
2295
      else
2296
        {
2297
    bfd_byte *buf;
2298
    struct internal_syment sym;
2299
    bfd_size_type amt = bfd_coff_symesz (abfd);
2300
2301
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2302
      return false;
2303
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2304
    if (buf == NULL)
2305
      return false;
2306
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2307
    if (sym.n_sclass == C_FILE)
2308
      cputype = sym.n_type & 0xff;
2309
    else
2310
      cputype = 0;
2311
    free (buf);
2312
        }
2313
    }
2314
2315
  /* FIXME: We don't handle all cases here.  */
2316
  switch (cputype)
2317
    {
2318
    default:
2319
    case 0:
2320
      arch = bfd_xcoff_architecture (abfd);
2321
      machine = bfd_xcoff_machine (abfd);
2322
      break;
2323
2324
    case 1:
2325
      arch = bfd_arch_powerpc;
2326
      machine = bfd_mach_ppc_601;
2327
      break;
2328
    case 2: /* 64 bit PowerPC */
2329
      arch = bfd_arch_powerpc;
2330
      machine = bfd_mach_ppc_620;
2331
      break;
2332
    case 3:
2333
      arch = bfd_arch_powerpc;
2334
      machine = bfd_mach_ppc;
2335
      break;
2336
    case 4:
2337
      arch = bfd_arch_rs6000;
2338
      machine = bfd_mach_rs6k;
2339
      break;
2340
    }
2341
      }
2342
      break;
2343
#endif
2344
2345
#ifdef SH_ARCH_MAGIC_BIG
2346
    case SH_ARCH_MAGIC_BIG:
2347
    case SH_ARCH_MAGIC_LITTLE:
2348
#ifdef COFF_WITH_PE
2349
    case SH_ARCH_MAGIC_WINCE:
2350
#endif
2351
      arch = bfd_arch_sh;
2352
      break;
2353
#endif
2354
2355
#ifdef MIPS_ARCH_MAGIC_WINCE
2356
    case MIPS_ARCH_MAGIC_WINCE:
2357
      arch = bfd_arch_mips;
2358
      break;
2359
#endif
2360
2361
#ifdef SPARCMAGIC
2362
    case SPARCMAGIC:
2363
#ifdef LYNXCOFFMAGIC
2364
    case LYNXCOFFMAGIC:
2365
#endif
2366
      arch = bfd_arch_sparc;
2367
      break;
2368
#endif
2369
2370
#ifdef TIC30MAGIC
2371
    case TIC30MAGIC:
2372
      arch = bfd_arch_tic30;
2373
      break;
2374
#endif
2375
2376
#ifdef TICOFF0MAGIC
2377
#ifdef TICOFF_TARGET_ARCH
2378
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2379
    case TICOFF0MAGIC:
2380
      arch = TICOFF_TARGET_ARCH;
2381
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2382
      break;
2383
#endif
2384
#endif
2385
2386
#ifdef TICOFF1MAGIC
2387
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2388
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2389
    case TICOFF1MAGIC:
2390
    case TICOFF2MAGIC:
2391
      switch (internal_f->f_target_id)
2392
  {
2393
#ifdef TI_TARGET_ID
2394
  case TI_TARGET_ID:
2395
    arch = TICOFF_TARGET_ARCH;
2396
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2397
    break;
2398
#endif
2399
  default:
2400
    arch = bfd_arch_obscure;
2401
    _bfd_error_handler
2402
      (_("unrecognized TI COFF target id '0x%x'"),
2403
       internal_f->f_target_id);
2404
    break;
2405
  }
2406
      break;
2407
#endif
2408
2409
#ifdef MCOREMAGIC
2410
    case MCOREMAGIC:
2411
      arch = bfd_arch_mcore;
2412
      break;
2413
#endif
2414
2415
0
    default:      /* Unreadable input file type.  */
2416
0
      arch = bfd_arch_obscure;
2417
0
      break;
2418
111k
    }
2419
2420
111k
  bfd_default_set_arch_mach (abfd, arch, machine);
2421
111k
  return true;
2422
111k
}
pei-ia64.c:coff_set_arch_mach_hook
Line
Count
Source
2154
116k
{
2155
116k
  unsigned long machine;
2156
116k
  enum bfd_architecture arch;
2157
116k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2158
2159
  /* Zero selects the default machine for an arch.  */
2160
116k
  machine = 0;
2161
116k
  switch (internal_f->f_magic)
2162
116k
    {
2163
#ifdef I386MAGIC
2164
    case I386MAGIC:
2165
    case I386PTXMAGIC:
2166
    case I386AIXMAGIC:    /* Danbury PS/2 AIX C Compiler.  */
2167
    case LYNXCOFFMAGIC:
2168
    case I386_APPLE_MAGIC:
2169
    case I386_FREEBSD_MAGIC:
2170
    case I386_LINUX_MAGIC:
2171
    case I386_NETBSD_MAGIC:
2172
      arch = bfd_arch_i386;
2173
      break;
2174
#endif
2175
#ifdef AMD64MAGIC
2176
    case AMD64MAGIC:
2177
    case AMD64_APPLE_MAGIC:
2178
    case AMD64_FREEBSD_MAGIC:
2179
    case AMD64_LINUX_MAGIC:
2180
    case AMD64_NETBSD_MAGIC:
2181
      arch = bfd_arch_i386;
2182
      machine = bfd_mach_x86_64;
2183
      break;
2184
#endif
2185
0
#ifdef IA64MAGIC
2186
116k
    case IA64MAGIC:
2187
116k
      arch = bfd_arch_ia64;
2188
116k
      break;
2189
0
#endif
2190
#ifdef ARMMAGIC
2191
    case ARMMAGIC:
2192
    case ARMPEMAGIC:
2193
    case THUMBPEMAGIC:
2194
      arch = bfd_arch_arm;
2195
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2196
      if (machine == bfd_mach_arm_unknown)
2197
  {
2198
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2199
      {
2200
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2201
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2202
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2203
      default:
2204
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2205
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2206
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2207
        /* The COFF header does not have enough bits available
2208
     to cover all the different ARM architectures.  So
2209
     we interpret F_ARM_5, the highest flag value to mean
2210
     "the highest ARM architecture known to BFD" which is
2211
     currently the XScale.  */
2212
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2213
      }
2214
  }
2215
      break;
2216
#endif
2217
#ifdef AARCH64MAGIC
2218
    case AARCH64MAGIC:
2219
      arch = bfd_arch_aarch64;
2220
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2221
      break;
2222
#endif
2223
#ifdef LOONGARCH64MAGIC
2224
    case LOONGARCH64MAGIC:
2225
      arch = bfd_arch_loongarch;
2226
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2227
      break;
2228
#endif
2229
#ifdef RISCV64MAGIC
2230
    case RISCV64MAGIC:
2231
      arch = bfd_arch_riscv;
2232
      machine = bfd_mach_riscv64;
2233
      break;
2234
#endif
2235
#ifdef Z80MAGIC
2236
    case Z80MAGIC:
2237
      arch = bfd_arch_z80;
2238
      switch (internal_f->f_flags & F_MACHMASK)
2239
  {
2240
  case bfd_mach_z80strict << 12:
2241
  case bfd_mach_z80 << 12:
2242
  case bfd_mach_z80n << 12:
2243
  case bfd_mach_z80full << 12:
2244
  case bfd_mach_r800 << 12:
2245
  case bfd_mach_gbz80 << 12:
2246
  case bfd_mach_z180 << 12:
2247
  case bfd_mach_ez80_z80 << 12:
2248
  case bfd_mach_ez80_adl << 12:
2249
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2250
    break;
2251
  default:
2252
    return false;
2253
  }
2254
      break;
2255
#endif
2256
#ifdef Z8KMAGIC
2257
    case Z8KMAGIC:
2258
      arch = bfd_arch_z8k;
2259
      switch (internal_f->f_flags & F_MACHMASK)
2260
  {
2261
  case F_Z8001:
2262
    machine = bfd_mach_z8001;
2263
    break;
2264
  case F_Z8002:
2265
    machine = bfd_mach_z8002;
2266
    break;
2267
  default:
2268
    return false;
2269
  }
2270
      break;
2271
#endif
2272
2273
#ifdef RS6000COFF_C
2274
#ifdef XCOFF64
2275
    case U64_TOCMAGIC:
2276
    case U803XTOCMAGIC:
2277
#else
2278
    case U802ROMAGIC:
2279
    case U802WRMAGIC:
2280
    case U802TOCMAGIC:
2281
#endif
2282
      {
2283
  int cputype;
2284
2285
  if (xcoff_data (abfd)->cputype != -1)
2286
    cputype = xcoff_data (abfd)->cputype & 0xff;
2287
  else
2288
    {
2289
      /* We did not get a value from the a.out header.  If the
2290
         file has not been stripped, we may be able to get the
2291
         architecture information from the first symbol, if it
2292
         is a .file symbol.  */
2293
      if (obj_raw_syment_count (abfd) == 0)
2294
        cputype = 0;
2295
      else
2296
        {
2297
    bfd_byte *buf;
2298
    struct internal_syment sym;
2299
    bfd_size_type amt = bfd_coff_symesz (abfd);
2300
2301
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2302
      return false;
2303
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2304
    if (buf == NULL)
2305
      return false;
2306
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2307
    if (sym.n_sclass == C_FILE)
2308
      cputype = sym.n_type & 0xff;
2309
    else
2310
      cputype = 0;
2311
    free (buf);
2312
        }
2313
    }
2314
2315
  /* FIXME: We don't handle all cases here.  */
2316
  switch (cputype)
2317
    {
2318
    default:
2319
    case 0:
2320
      arch = bfd_xcoff_architecture (abfd);
2321
      machine = bfd_xcoff_machine (abfd);
2322
      break;
2323
2324
    case 1:
2325
      arch = bfd_arch_powerpc;
2326
      machine = bfd_mach_ppc_601;
2327
      break;
2328
    case 2: /* 64 bit PowerPC */
2329
      arch = bfd_arch_powerpc;
2330
      machine = bfd_mach_ppc_620;
2331
      break;
2332
    case 3:
2333
      arch = bfd_arch_powerpc;
2334
      machine = bfd_mach_ppc;
2335
      break;
2336
    case 4:
2337
      arch = bfd_arch_rs6000;
2338
      machine = bfd_mach_rs6k;
2339
      break;
2340
    }
2341
      }
2342
      break;
2343
#endif
2344
2345
#ifdef SH_ARCH_MAGIC_BIG
2346
    case SH_ARCH_MAGIC_BIG:
2347
    case SH_ARCH_MAGIC_LITTLE:
2348
#ifdef COFF_WITH_PE
2349
    case SH_ARCH_MAGIC_WINCE:
2350
#endif
2351
      arch = bfd_arch_sh;
2352
      break;
2353
#endif
2354
2355
#ifdef MIPS_ARCH_MAGIC_WINCE
2356
    case MIPS_ARCH_MAGIC_WINCE:
2357
      arch = bfd_arch_mips;
2358
      break;
2359
#endif
2360
2361
#ifdef SPARCMAGIC
2362
    case SPARCMAGIC:
2363
#ifdef LYNXCOFFMAGIC
2364
    case LYNXCOFFMAGIC:
2365
#endif
2366
      arch = bfd_arch_sparc;
2367
      break;
2368
#endif
2369
2370
#ifdef TIC30MAGIC
2371
    case TIC30MAGIC:
2372
      arch = bfd_arch_tic30;
2373
      break;
2374
#endif
2375
2376
#ifdef TICOFF0MAGIC
2377
#ifdef TICOFF_TARGET_ARCH
2378
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2379
    case TICOFF0MAGIC:
2380
      arch = TICOFF_TARGET_ARCH;
2381
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2382
      break;
2383
#endif
2384
#endif
2385
2386
#ifdef TICOFF1MAGIC
2387
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2388
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2389
    case TICOFF1MAGIC:
2390
    case TICOFF2MAGIC:
2391
      switch (internal_f->f_target_id)
2392
  {
2393
#ifdef TI_TARGET_ID
2394
  case TI_TARGET_ID:
2395
    arch = TICOFF_TARGET_ARCH;
2396
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2397
    break;
2398
#endif
2399
  default:
2400
    arch = bfd_arch_obscure;
2401
    _bfd_error_handler
2402
      (_("unrecognized TI COFF target id '0x%x'"),
2403
       internal_f->f_target_id);
2404
    break;
2405
  }
2406
      break;
2407
#endif
2408
2409
#ifdef MCOREMAGIC
2410
    case MCOREMAGIC:
2411
      arch = bfd_arch_mcore;
2412
      break;
2413
#endif
2414
2415
0
    default:      /* Unreadable input file type.  */
2416
0
      arch = bfd_arch_obscure;
2417
0
      break;
2418
116k
    }
2419
2420
116k
  bfd_default_set_arch_mach (abfd, arch, machine);
2421
116k
  return true;
2422
116k
}
pei-loongarch64.c:coff_set_arch_mach_hook
Line
Count
Source
2154
97.3k
{
2155
97.3k
  unsigned long machine;
2156
97.3k
  enum bfd_architecture arch;
2157
97.3k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2158
2159
  /* Zero selects the default machine for an arch.  */
2160
97.3k
  machine = 0;
2161
97.3k
  switch (internal_f->f_magic)
2162
97.3k
    {
2163
#ifdef I386MAGIC
2164
    case I386MAGIC:
2165
    case I386PTXMAGIC:
2166
    case I386AIXMAGIC:    /* Danbury PS/2 AIX C Compiler.  */
2167
    case LYNXCOFFMAGIC:
2168
    case I386_APPLE_MAGIC:
2169
    case I386_FREEBSD_MAGIC:
2170
    case I386_LINUX_MAGIC:
2171
    case I386_NETBSD_MAGIC:
2172
      arch = bfd_arch_i386;
2173
      break;
2174
#endif
2175
#ifdef AMD64MAGIC
2176
    case AMD64MAGIC:
2177
    case AMD64_APPLE_MAGIC:
2178
    case AMD64_FREEBSD_MAGIC:
2179
    case AMD64_LINUX_MAGIC:
2180
    case AMD64_NETBSD_MAGIC:
2181
      arch = bfd_arch_i386;
2182
      machine = bfd_mach_x86_64;
2183
      break;
2184
#endif
2185
#ifdef IA64MAGIC
2186
    case IA64MAGIC:
2187
      arch = bfd_arch_ia64;
2188
      break;
2189
#endif
2190
#ifdef ARMMAGIC
2191
    case ARMMAGIC:
2192
    case ARMPEMAGIC:
2193
    case THUMBPEMAGIC:
2194
      arch = bfd_arch_arm;
2195
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2196
      if (machine == bfd_mach_arm_unknown)
2197
  {
2198
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2199
      {
2200
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2201
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2202
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2203
      default:
2204
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2205
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2206
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2207
        /* The COFF header does not have enough bits available
2208
     to cover all the different ARM architectures.  So
2209
     we interpret F_ARM_5, the highest flag value to mean
2210
     "the highest ARM architecture known to BFD" which is
2211
     currently the XScale.  */
2212
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2213
      }
2214
  }
2215
      break;
2216
#endif
2217
#ifdef AARCH64MAGIC
2218
    case AARCH64MAGIC:
2219
      arch = bfd_arch_aarch64;
2220
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2221
      break;
2222
#endif
2223
0
#ifdef LOONGARCH64MAGIC
2224
97.3k
    case LOONGARCH64MAGIC:
2225
97.3k
      arch = bfd_arch_loongarch;
2226
97.3k
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2227
97.3k
      break;
2228
0
#endif
2229
#ifdef RISCV64MAGIC
2230
    case RISCV64MAGIC:
2231
      arch = bfd_arch_riscv;
2232
      machine = bfd_mach_riscv64;
2233
      break;
2234
#endif
2235
#ifdef Z80MAGIC
2236
    case Z80MAGIC:
2237
      arch = bfd_arch_z80;
2238
      switch (internal_f->f_flags & F_MACHMASK)
2239
  {
2240
  case bfd_mach_z80strict << 12:
2241
  case bfd_mach_z80 << 12:
2242
  case bfd_mach_z80n << 12:
2243
  case bfd_mach_z80full << 12:
2244
  case bfd_mach_r800 << 12:
2245
  case bfd_mach_gbz80 << 12:
2246
  case bfd_mach_z180 << 12:
2247
  case bfd_mach_ez80_z80 << 12:
2248
  case bfd_mach_ez80_adl << 12:
2249
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2250
    break;
2251
  default:
2252
    return false;
2253
  }
2254
      break;
2255
#endif
2256
#ifdef Z8KMAGIC
2257
    case Z8KMAGIC:
2258
      arch = bfd_arch_z8k;
2259
      switch (internal_f->f_flags & F_MACHMASK)
2260
  {
2261
  case F_Z8001:
2262
    machine = bfd_mach_z8001;
2263
    break;
2264
  case F_Z8002:
2265
    machine = bfd_mach_z8002;
2266
    break;
2267
  default:
2268
    return false;
2269
  }
2270
      break;
2271
#endif
2272
2273
#ifdef RS6000COFF_C
2274
#ifdef XCOFF64
2275
    case U64_TOCMAGIC:
2276
    case U803XTOCMAGIC:
2277
#else
2278
    case U802ROMAGIC:
2279
    case U802WRMAGIC:
2280
    case U802TOCMAGIC:
2281
#endif
2282
      {
2283
  int cputype;
2284
2285
  if (xcoff_data (abfd)->cputype != -1)
2286
    cputype = xcoff_data (abfd)->cputype & 0xff;
2287
  else
2288
    {
2289
      /* We did not get a value from the a.out header.  If the
2290
         file has not been stripped, we may be able to get the
2291
         architecture information from the first symbol, if it
2292
         is a .file symbol.  */
2293
      if (obj_raw_syment_count (abfd) == 0)
2294
        cputype = 0;
2295
      else
2296
        {
2297
    bfd_byte *buf;
2298
    struct internal_syment sym;
2299
    bfd_size_type amt = bfd_coff_symesz (abfd);
2300
2301
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2302
      return false;
2303
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2304
    if (buf == NULL)
2305
      return false;
2306
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2307
    if (sym.n_sclass == C_FILE)
2308
      cputype = sym.n_type & 0xff;
2309
    else
2310
      cputype = 0;
2311
    free (buf);
2312
        }
2313
    }
2314
2315
  /* FIXME: We don't handle all cases here.  */
2316
  switch (cputype)
2317
    {
2318
    default:
2319
    case 0:
2320
      arch = bfd_xcoff_architecture (abfd);
2321
      machine = bfd_xcoff_machine (abfd);
2322
      break;
2323
2324
    case 1:
2325
      arch = bfd_arch_powerpc;
2326
      machine = bfd_mach_ppc_601;
2327
      break;
2328
    case 2: /* 64 bit PowerPC */
2329
      arch = bfd_arch_powerpc;
2330
      machine = bfd_mach_ppc_620;
2331
      break;
2332
    case 3:
2333
      arch = bfd_arch_powerpc;
2334
      machine = bfd_mach_ppc;
2335
      break;
2336
    case 4:
2337
      arch = bfd_arch_rs6000;
2338
      machine = bfd_mach_rs6k;
2339
      break;
2340
    }
2341
      }
2342
      break;
2343
#endif
2344
2345
#ifdef SH_ARCH_MAGIC_BIG
2346
    case SH_ARCH_MAGIC_BIG:
2347
    case SH_ARCH_MAGIC_LITTLE:
2348
#ifdef COFF_WITH_PE
2349
    case SH_ARCH_MAGIC_WINCE:
2350
#endif
2351
      arch = bfd_arch_sh;
2352
      break;
2353
#endif
2354
2355
#ifdef MIPS_ARCH_MAGIC_WINCE
2356
    case MIPS_ARCH_MAGIC_WINCE:
2357
      arch = bfd_arch_mips;
2358
      break;
2359
#endif
2360
2361
#ifdef SPARCMAGIC
2362
    case SPARCMAGIC:
2363
#ifdef LYNXCOFFMAGIC
2364
    case LYNXCOFFMAGIC:
2365
#endif
2366
      arch = bfd_arch_sparc;
2367
      break;
2368
#endif
2369
2370
#ifdef TIC30MAGIC
2371
    case TIC30MAGIC:
2372
      arch = bfd_arch_tic30;
2373
      break;
2374
#endif
2375
2376
#ifdef TICOFF0MAGIC
2377
#ifdef TICOFF_TARGET_ARCH
2378
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2379
    case TICOFF0MAGIC:
2380
      arch = TICOFF_TARGET_ARCH;
2381
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2382
      break;
2383
#endif
2384
#endif
2385
2386
#ifdef TICOFF1MAGIC
2387
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2388
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2389
    case TICOFF1MAGIC:
2390
    case TICOFF2MAGIC:
2391
      switch (internal_f->f_target_id)
2392
  {
2393
#ifdef TI_TARGET_ID
2394
  case TI_TARGET_ID:
2395
    arch = TICOFF_TARGET_ARCH;
2396
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2397
    break;
2398
#endif
2399
  default:
2400
    arch = bfd_arch_obscure;
2401
    _bfd_error_handler
2402
      (_("unrecognized TI COFF target id '0x%x'"),
2403
       internal_f->f_target_id);
2404
    break;
2405
  }
2406
      break;
2407
#endif
2408
2409
#ifdef MCOREMAGIC
2410
    case MCOREMAGIC:
2411
      arch = bfd_arch_mcore;
2412
      break;
2413
#endif
2414
2415
0
    default:      /* Unreadable input file type.  */
2416
0
      arch = bfd_arch_obscure;
2417
0
      break;
2418
97.3k
    }
2419
2420
97.3k
  bfd_default_set_arch_mach (abfd, arch, machine);
2421
97.3k
  return true;
2422
97.3k
}
pei-riscv64.c:coff_set_arch_mach_hook
Line
Count
Source
2154
89.7k
{
2155
89.7k
  unsigned long machine;
2156
89.7k
  enum bfd_architecture arch;
2157
89.7k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2158
2159
  /* Zero selects the default machine for an arch.  */
2160
89.7k
  machine = 0;
2161
89.7k
  switch (internal_f->f_magic)
2162
89.7k
    {
2163
#ifdef I386MAGIC
2164
    case I386MAGIC:
2165
    case I386PTXMAGIC:
2166
    case I386AIXMAGIC:    /* Danbury PS/2 AIX C Compiler.  */
2167
    case LYNXCOFFMAGIC:
2168
    case I386_APPLE_MAGIC:
2169
    case I386_FREEBSD_MAGIC:
2170
    case I386_LINUX_MAGIC:
2171
    case I386_NETBSD_MAGIC:
2172
      arch = bfd_arch_i386;
2173
      break;
2174
#endif
2175
#ifdef AMD64MAGIC
2176
    case AMD64MAGIC:
2177
    case AMD64_APPLE_MAGIC:
2178
    case AMD64_FREEBSD_MAGIC:
2179
    case AMD64_LINUX_MAGIC:
2180
    case AMD64_NETBSD_MAGIC:
2181
      arch = bfd_arch_i386;
2182
      machine = bfd_mach_x86_64;
2183
      break;
2184
#endif
2185
#ifdef IA64MAGIC
2186
    case IA64MAGIC:
2187
      arch = bfd_arch_ia64;
2188
      break;
2189
#endif
2190
#ifdef ARMMAGIC
2191
    case ARMMAGIC:
2192
    case ARMPEMAGIC:
2193
    case THUMBPEMAGIC:
2194
      arch = bfd_arch_arm;
2195
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2196
      if (machine == bfd_mach_arm_unknown)
2197
  {
2198
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2199
      {
2200
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2201
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2202
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2203
      default:
2204
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2205
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2206
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2207
        /* The COFF header does not have enough bits available
2208
     to cover all the different ARM architectures.  So
2209
     we interpret F_ARM_5, the highest flag value to mean
2210
     "the highest ARM architecture known to BFD" which is
2211
     currently the XScale.  */
2212
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2213
      }
2214
  }
2215
      break;
2216
#endif
2217
#ifdef AARCH64MAGIC
2218
    case AARCH64MAGIC:
2219
      arch = bfd_arch_aarch64;
2220
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2221
      break;
2222
#endif
2223
#ifdef LOONGARCH64MAGIC
2224
    case LOONGARCH64MAGIC:
2225
      arch = bfd_arch_loongarch;
2226
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2227
      break;
2228
#endif
2229
0
#ifdef RISCV64MAGIC
2230
89.7k
    case RISCV64MAGIC:
2231
89.7k
      arch = bfd_arch_riscv;
2232
89.7k
      machine = bfd_mach_riscv64;
2233
89.7k
      break;
2234
0
#endif
2235
#ifdef Z80MAGIC
2236
    case Z80MAGIC:
2237
      arch = bfd_arch_z80;
2238
      switch (internal_f->f_flags & F_MACHMASK)
2239
  {
2240
  case bfd_mach_z80strict << 12:
2241
  case bfd_mach_z80 << 12:
2242
  case bfd_mach_z80n << 12:
2243
  case bfd_mach_z80full << 12:
2244
  case bfd_mach_r800 << 12:
2245
  case bfd_mach_gbz80 << 12:
2246
  case bfd_mach_z180 << 12:
2247
  case bfd_mach_ez80_z80 << 12:
2248
  case bfd_mach_ez80_adl << 12:
2249
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2250
    break;
2251
  default:
2252
    return false;
2253
  }
2254
      break;
2255
#endif
2256
#ifdef Z8KMAGIC
2257
    case Z8KMAGIC:
2258
      arch = bfd_arch_z8k;
2259
      switch (internal_f->f_flags & F_MACHMASK)
2260
  {
2261
  case F_Z8001:
2262
    machine = bfd_mach_z8001;
2263
    break;
2264
  case F_Z8002:
2265
    machine = bfd_mach_z8002;
2266
    break;
2267
  default:
2268
    return false;
2269
  }
2270
      break;
2271
#endif
2272
2273
#ifdef RS6000COFF_C
2274
#ifdef XCOFF64
2275
    case U64_TOCMAGIC:
2276
    case U803XTOCMAGIC:
2277
#else
2278
    case U802ROMAGIC:
2279
    case U802WRMAGIC:
2280
    case U802TOCMAGIC:
2281
#endif
2282
      {
2283
  int cputype;
2284
2285
  if (xcoff_data (abfd)->cputype != -1)
2286
    cputype = xcoff_data (abfd)->cputype & 0xff;
2287
  else
2288
    {
2289
      /* We did not get a value from the a.out header.  If the
2290
         file has not been stripped, we may be able to get the
2291
         architecture information from the first symbol, if it
2292
         is a .file symbol.  */
2293
      if (obj_raw_syment_count (abfd) == 0)
2294
        cputype = 0;
2295
      else
2296
        {
2297
    bfd_byte *buf;
2298
    struct internal_syment sym;
2299
    bfd_size_type amt = bfd_coff_symesz (abfd);
2300
2301
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2302
      return false;
2303
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2304
    if (buf == NULL)
2305
      return false;
2306
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2307
    if (sym.n_sclass == C_FILE)
2308
      cputype = sym.n_type & 0xff;
2309
    else
2310
      cputype = 0;
2311
    free (buf);
2312
        }
2313
    }
2314
2315
  /* FIXME: We don't handle all cases here.  */
2316
  switch (cputype)
2317
    {
2318
    default:
2319
    case 0:
2320
      arch = bfd_xcoff_architecture (abfd);
2321
      machine = bfd_xcoff_machine (abfd);
2322
      break;
2323
2324
    case 1:
2325
      arch = bfd_arch_powerpc;
2326
      machine = bfd_mach_ppc_601;
2327
      break;
2328
    case 2: /* 64 bit PowerPC */
2329
      arch = bfd_arch_powerpc;
2330
      machine = bfd_mach_ppc_620;
2331
      break;
2332
    case 3:
2333
      arch = bfd_arch_powerpc;
2334
      machine = bfd_mach_ppc;
2335
      break;
2336
    case 4:
2337
      arch = bfd_arch_rs6000;
2338
      machine = bfd_mach_rs6k;
2339
      break;
2340
    }
2341
      }
2342
      break;
2343
#endif
2344
2345
#ifdef SH_ARCH_MAGIC_BIG
2346
    case SH_ARCH_MAGIC_BIG:
2347
    case SH_ARCH_MAGIC_LITTLE:
2348
#ifdef COFF_WITH_PE
2349
    case SH_ARCH_MAGIC_WINCE:
2350
#endif
2351
      arch = bfd_arch_sh;
2352
      break;
2353
#endif
2354
2355
#ifdef MIPS_ARCH_MAGIC_WINCE
2356
    case MIPS_ARCH_MAGIC_WINCE:
2357
      arch = bfd_arch_mips;
2358
      break;
2359
#endif
2360
2361
#ifdef SPARCMAGIC
2362
    case SPARCMAGIC:
2363
#ifdef LYNXCOFFMAGIC
2364
    case LYNXCOFFMAGIC:
2365
#endif
2366
      arch = bfd_arch_sparc;
2367
      break;
2368
#endif
2369
2370
#ifdef TIC30MAGIC
2371
    case TIC30MAGIC:
2372
      arch = bfd_arch_tic30;
2373
      break;
2374
#endif
2375
2376
#ifdef TICOFF0MAGIC
2377
#ifdef TICOFF_TARGET_ARCH
2378
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2379
    case TICOFF0MAGIC:
2380
      arch = TICOFF_TARGET_ARCH;
2381
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2382
      break;
2383
#endif
2384
#endif
2385
2386
#ifdef TICOFF1MAGIC
2387
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2388
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2389
    case TICOFF1MAGIC:
2390
    case TICOFF2MAGIC:
2391
      switch (internal_f->f_target_id)
2392
  {
2393
#ifdef TI_TARGET_ID
2394
  case TI_TARGET_ID:
2395
    arch = TICOFF_TARGET_ARCH;
2396
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2397
    break;
2398
#endif
2399
  default:
2400
    arch = bfd_arch_obscure;
2401
    _bfd_error_handler
2402
      (_("unrecognized TI COFF target id '0x%x'"),
2403
       internal_f->f_target_id);
2404
    break;
2405
  }
2406
      break;
2407
#endif
2408
2409
#ifdef MCOREMAGIC
2410
    case MCOREMAGIC:
2411
      arch = bfd_arch_mcore;
2412
      break;
2413
#endif
2414
2415
0
    default:      /* Unreadable input file type.  */
2416
0
      arch = bfd_arch_obscure;
2417
0
      break;
2418
89.7k
    }
2419
2420
89.7k
  bfd_default_set_arch_mach (abfd, arch, machine);
2421
89.7k
  return true;
2422
89.7k
}
cf-i386lynx.c:coff_set_arch_mach_hook
Line
Count
Source
2154
69.8k
{
2155
69.8k
  unsigned long machine;
2156
69.8k
  enum bfd_architecture arch;
2157
69.8k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2158
2159
  /* Zero selects the default machine for an arch.  */
2160
69.8k
  machine = 0;
2161
69.8k
  switch (internal_f->f_magic)
2162
69.8k
    {
2163
0
#ifdef I386MAGIC
2164
51.1k
    case I386MAGIC:
2165
54.9k
    case I386PTXMAGIC:
2166
57.1k
    case I386AIXMAGIC:   /* Danbury PS/2 AIX C Compiler.  */
2167
68.7k
    case LYNXCOFFMAGIC:
2168
69.0k
    case I386_APPLE_MAGIC:
2169
69.0k
    case I386_FREEBSD_MAGIC:
2170
69.2k
    case I386_LINUX_MAGIC:
2171
69.8k
    case I386_NETBSD_MAGIC:
2172
69.8k
      arch = bfd_arch_i386;
2173
69.8k
      break;
2174
0
#endif
2175
#ifdef AMD64MAGIC
2176
    case AMD64MAGIC:
2177
    case AMD64_APPLE_MAGIC:
2178
    case AMD64_FREEBSD_MAGIC:
2179
    case AMD64_LINUX_MAGIC:
2180
    case AMD64_NETBSD_MAGIC:
2181
      arch = bfd_arch_i386;
2182
      machine = bfd_mach_x86_64;
2183
      break;
2184
#endif
2185
#ifdef IA64MAGIC
2186
    case IA64MAGIC:
2187
      arch = bfd_arch_ia64;
2188
      break;
2189
#endif
2190
#ifdef ARMMAGIC
2191
    case ARMMAGIC:
2192
    case ARMPEMAGIC:
2193
    case THUMBPEMAGIC:
2194
      arch = bfd_arch_arm;
2195
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2196
      if (machine == bfd_mach_arm_unknown)
2197
  {
2198
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2199
      {
2200
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2201
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2202
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2203
      default:
2204
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2205
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2206
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2207
        /* The COFF header does not have enough bits available
2208
     to cover all the different ARM architectures.  So
2209
     we interpret F_ARM_5, the highest flag value to mean
2210
     "the highest ARM architecture known to BFD" which is
2211
     currently the XScale.  */
2212
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2213
      }
2214
  }
2215
      break;
2216
#endif
2217
#ifdef AARCH64MAGIC
2218
    case AARCH64MAGIC:
2219
      arch = bfd_arch_aarch64;
2220
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2221
      break;
2222
#endif
2223
#ifdef LOONGARCH64MAGIC
2224
    case LOONGARCH64MAGIC:
2225
      arch = bfd_arch_loongarch;
2226
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2227
      break;
2228
#endif
2229
#ifdef RISCV64MAGIC
2230
    case RISCV64MAGIC:
2231
      arch = bfd_arch_riscv;
2232
      machine = bfd_mach_riscv64;
2233
      break;
2234
#endif
2235
#ifdef Z80MAGIC
2236
    case Z80MAGIC:
2237
      arch = bfd_arch_z80;
2238
      switch (internal_f->f_flags & F_MACHMASK)
2239
  {
2240
  case bfd_mach_z80strict << 12:
2241
  case bfd_mach_z80 << 12:
2242
  case bfd_mach_z80n << 12:
2243
  case bfd_mach_z80full << 12:
2244
  case bfd_mach_r800 << 12:
2245
  case bfd_mach_gbz80 << 12:
2246
  case bfd_mach_z180 << 12:
2247
  case bfd_mach_ez80_z80 << 12:
2248
  case bfd_mach_ez80_adl << 12:
2249
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2250
    break;
2251
  default:
2252
    return false;
2253
  }
2254
      break;
2255
#endif
2256
#ifdef Z8KMAGIC
2257
    case Z8KMAGIC:
2258
      arch = bfd_arch_z8k;
2259
      switch (internal_f->f_flags & F_MACHMASK)
2260
  {
2261
  case F_Z8001:
2262
    machine = bfd_mach_z8001;
2263
    break;
2264
  case F_Z8002:
2265
    machine = bfd_mach_z8002;
2266
    break;
2267
  default:
2268
    return false;
2269
  }
2270
      break;
2271
#endif
2272
2273
#ifdef RS6000COFF_C
2274
#ifdef XCOFF64
2275
    case U64_TOCMAGIC:
2276
    case U803XTOCMAGIC:
2277
#else
2278
    case U802ROMAGIC:
2279
    case U802WRMAGIC:
2280
    case U802TOCMAGIC:
2281
#endif
2282
      {
2283
  int cputype;
2284
2285
  if (xcoff_data (abfd)->cputype != -1)
2286
    cputype = xcoff_data (abfd)->cputype & 0xff;
2287
  else
2288
    {
2289
      /* We did not get a value from the a.out header.  If the
2290
         file has not been stripped, we may be able to get the
2291
         architecture information from the first symbol, if it
2292
         is a .file symbol.  */
2293
      if (obj_raw_syment_count (abfd) == 0)
2294
        cputype = 0;
2295
      else
2296
        {
2297
    bfd_byte *buf;
2298
    struct internal_syment sym;
2299
    bfd_size_type amt = bfd_coff_symesz (abfd);
2300
2301
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2302
      return false;
2303
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2304
    if (buf == NULL)
2305
      return false;
2306
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2307
    if (sym.n_sclass == C_FILE)
2308
      cputype = sym.n_type & 0xff;
2309
    else
2310
      cputype = 0;
2311
    free (buf);
2312
        }
2313
    }
2314
2315
  /* FIXME: We don't handle all cases here.  */
2316
  switch (cputype)
2317
    {
2318
    default:
2319
    case 0:
2320
      arch = bfd_xcoff_architecture (abfd);
2321
      machine = bfd_xcoff_machine (abfd);
2322
      break;
2323
2324
    case 1:
2325
      arch = bfd_arch_powerpc;
2326
      machine = bfd_mach_ppc_601;
2327
      break;
2328
    case 2: /* 64 bit PowerPC */
2329
      arch = bfd_arch_powerpc;
2330
      machine = bfd_mach_ppc_620;
2331
      break;
2332
    case 3:
2333
      arch = bfd_arch_powerpc;
2334
      machine = bfd_mach_ppc;
2335
      break;
2336
    case 4:
2337
      arch = bfd_arch_rs6000;
2338
      machine = bfd_mach_rs6k;
2339
      break;
2340
    }
2341
      }
2342
      break;
2343
#endif
2344
2345
#ifdef SH_ARCH_MAGIC_BIG
2346
    case SH_ARCH_MAGIC_BIG:
2347
    case SH_ARCH_MAGIC_LITTLE:
2348
#ifdef COFF_WITH_PE
2349
    case SH_ARCH_MAGIC_WINCE:
2350
#endif
2351
      arch = bfd_arch_sh;
2352
      break;
2353
#endif
2354
2355
#ifdef MIPS_ARCH_MAGIC_WINCE
2356
    case MIPS_ARCH_MAGIC_WINCE:
2357
      arch = bfd_arch_mips;
2358
      break;
2359
#endif
2360
2361
#ifdef SPARCMAGIC
2362
    case SPARCMAGIC:
2363
#ifdef LYNXCOFFMAGIC
2364
    case LYNXCOFFMAGIC:
2365
#endif
2366
      arch = bfd_arch_sparc;
2367
      break;
2368
#endif
2369
2370
#ifdef TIC30MAGIC
2371
    case TIC30MAGIC:
2372
      arch = bfd_arch_tic30;
2373
      break;
2374
#endif
2375
2376
#ifdef TICOFF0MAGIC
2377
#ifdef TICOFF_TARGET_ARCH
2378
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2379
    case TICOFF0MAGIC:
2380
      arch = TICOFF_TARGET_ARCH;
2381
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2382
      break;
2383
#endif
2384
#endif
2385
2386
#ifdef TICOFF1MAGIC
2387
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2388
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2389
    case TICOFF1MAGIC:
2390
    case TICOFF2MAGIC:
2391
      switch (internal_f->f_target_id)
2392
  {
2393
#ifdef TI_TARGET_ID
2394
  case TI_TARGET_ID:
2395
    arch = TICOFF_TARGET_ARCH;
2396
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2397
    break;
2398
#endif
2399
  default:
2400
    arch = bfd_arch_obscure;
2401
    _bfd_error_handler
2402
      (_("unrecognized TI COFF target id '0x%x'"),
2403
       internal_f->f_target_id);
2404
    break;
2405
  }
2406
      break;
2407
#endif
2408
2409
#ifdef MCOREMAGIC
2410
    case MCOREMAGIC:
2411
      arch = bfd_arch_mcore;
2412
      break;
2413
#endif
2414
2415
0
    default:      /* Unreadable input file type.  */
2416
0
      arch = bfd_arch_obscure;
2417
0
      break;
2418
69.8k
    }
2419
2420
69.8k
  bfd_default_set_arch_mach (abfd, arch, machine);
2421
69.8k
  return true;
2422
69.8k
}
coff-go32.c:coff_set_arch_mach_hook
Line
Count
Source
2154
66.7k
{
2155
66.7k
  unsigned long machine;
2156
66.7k
  enum bfd_architecture arch;
2157
66.7k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2158
2159
  /* Zero selects the default machine for an arch.  */
2160
66.7k
  machine = 0;
2161
66.7k
  switch (internal_f->f_magic)
2162
66.7k
    {
2163
0
#ifdef I386MAGIC
2164
49.5k
    case I386MAGIC:
2165
52.6k
    case I386PTXMAGIC:
2166
54.7k
    case I386AIXMAGIC:   /* Danbury PS/2 AIX C Compiler.  */
2167
66.2k
    case LYNXCOFFMAGIC:
2168
66.5k
    case I386_APPLE_MAGIC:
2169
66.5k
    case I386_FREEBSD_MAGIC:
2170
66.6k
    case I386_LINUX_MAGIC:
2171
66.7k
    case I386_NETBSD_MAGIC:
2172
66.7k
      arch = bfd_arch_i386;
2173
66.7k
      break;
2174
0
#endif
2175
#ifdef AMD64MAGIC
2176
    case AMD64MAGIC:
2177
    case AMD64_APPLE_MAGIC:
2178
    case AMD64_FREEBSD_MAGIC:
2179
    case AMD64_LINUX_MAGIC:
2180
    case AMD64_NETBSD_MAGIC:
2181
      arch = bfd_arch_i386;
2182
      machine = bfd_mach_x86_64;
2183
      break;
2184
#endif
2185
#ifdef IA64MAGIC
2186
    case IA64MAGIC:
2187
      arch = bfd_arch_ia64;
2188
      break;
2189
#endif
2190
#ifdef ARMMAGIC
2191
    case ARMMAGIC:
2192
    case ARMPEMAGIC:
2193
    case THUMBPEMAGIC:
2194
      arch = bfd_arch_arm;
2195
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2196
      if (machine == bfd_mach_arm_unknown)
2197
  {
2198
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2199
      {
2200
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2201
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2202
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2203
      default:
2204
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2205
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2206
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2207
        /* The COFF header does not have enough bits available
2208
     to cover all the different ARM architectures.  So
2209
     we interpret F_ARM_5, the highest flag value to mean
2210
     "the highest ARM architecture known to BFD" which is
2211
     currently the XScale.  */
2212
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2213
      }
2214
  }
2215
      break;
2216
#endif
2217
#ifdef AARCH64MAGIC
2218
    case AARCH64MAGIC:
2219
      arch = bfd_arch_aarch64;
2220
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2221
      break;
2222
#endif
2223
#ifdef LOONGARCH64MAGIC
2224
    case LOONGARCH64MAGIC:
2225
      arch = bfd_arch_loongarch;
2226
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2227
      break;
2228
#endif
2229
#ifdef RISCV64MAGIC
2230
    case RISCV64MAGIC:
2231
      arch = bfd_arch_riscv;
2232
      machine = bfd_mach_riscv64;
2233
      break;
2234
#endif
2235
#ifdef Z80MAGIC
2236
    case Z80MAGIC:
2237
      arch = bfd_arch_z80;
2238
      switch (internal_f->f_flags & F_MACHMASK)
2239
  {
2240
  case bfd_mach_z80strict << 12:
2241
  case bfd_mach_z80 << 12:
2242
  case bfd_mach_z80n << 12:
2243
  case bfd_mach_z80full << 12:
2244
  case bfd_mach_r800 << 12:
2245
  case bfd_mach_gbz80 << 12:
2246
  case bfd_mach_z180 << 12:
2247
  case bfd_mach_ez80_z80 << 12:
2248
  case bfd_mach_ez80_adl << 12:
2249
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2250
    break;
2251
  default:
2252
    return false;
2253
  }
2254
      break;
2255
#endif
2256
#ifdef Z8KMAGIC
2257
    case Z8KMAGIC:
2258
      arch = bfd_arch_z8k;
2259
      switch (internal_f->f_flags & F_MACHMASK)
2260
  {
2261
  case F_Z8001:
2262
    machine = bfd_mach_z8001;
2263
    break;
2264
  case F_Z8002:
2265
    machine = bfd_mach_z8002;
2266
    break;
2267
  default:
2268
    return false;
2269
  }
2270
      break;
2271
#endif
2272
2273
#ifdef RS6000COFF_C
2274
#ifdef XCOFF64
2275
    case U64_TOCMAGIC:
2276
    case U803XTOCMAGIC:
2277
#else
2278
    case U802ROMAGIC:
2279
    case U802WRMAGIC:
2280
    case U802TOCMAGIC:
2281
#endif
2282
      {
2283
  int cputype;
2284
2285
  if (xcoff_data (abfd)->cputype != -1)
2286
    cputype = xcoff_data (abfd)->cputype & 0xff;
2287
  else
2288
    {
2289
      /* We did not get a value from the a.out header.  If the
2290
         file has not been stripped, we may be able to get the
2291
         architecture information from the first symbol, if it
2292
         is a .file symbol.  */
2293
      if (obj_raw_syment_count (abfd) == 0)
2294
        cputype = 0;
2295
      else
2296
        {
2297
    bfd_byte *buf;
2298
    struct internal_syment sym;
2299
    bfd_size_type amt = bfd_coff_symesz (abfd);
2300
2301
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2302
      return false;
2303
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2304
    if (buf == NULL)
2305
      return false;
2306
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2307
    if (sym.n_sclass == C_FILE)
2308
      cputype = sym.n_type & 0xff;
2309
    else
2310
      cputype = 0;
2311
    free (buf);
2312
        }
2313
    }
2314
2315
  /* FIXME: We don't handle all cases here.  */
2316
  switch (cputype)
2317
    {
2318
    default:
2319
    case 0:
2320
      arch = bfd_xcoff_architecture (abfd);
2321
      machine = bfd_xcoff_machine (abfd);
2322
      break;
2323
2324
    case 1:
2325
      arch = bfd_arch_powerpc;
2326
      machine = bfd_mach_ppc_601;
2327
      break;
2328
    case 2: /* 64 bit PowerPC */
2329
      arch = bfd_arch_powerpc;
2330
      machine = bfd_mach_ppc_620;
2331
      break;
2332
    case 3:
2333
      arch = bfd_arch_powerpc;
2334
      machine = bfd_mach_ppc;
2335
      break;
2336
    case 4:
2337
      arch = bfd_arch_rs6000;
2338
      machine = bfd_mach_rs6k;
2339
      break;
2340
    }
2341
      }
2342
      break;
2343
#endif
2344
2345
#ifdef SH_ARCH_MAGIC_BIG
2346
    case SH_ARCH_MAGIC_BIG:
2347
    case SH_ARCH_MAGIC_LITTLE:
2348
#ifdef COFF_WITH_PE
2349
    case SH_ARCH_MAGIC_WINCE:
2350
#endif
2351
      arch = bfd_arch_sh;
2352
      break;
2353
#endif
2354
2355
#ifdef MIPS_ARCH_MAGIC_WINCE
2356
    case MIPS_ARCH_MAGIC_WINCE:
2357
      arch = bfd_arch_mips;
2358
      break;
2359
#endif
2360
2361
#ifdef SPARCMAGIC
2362
    case SPARCMAGIC:
2363
#ifdef LYNXCOFFMAGIC
2364
    case LYNXCOFFMAGIC:
2365
#endif
2366
      arch = bfd_arch_sparc;
2367
      break;
2368
#endif
2369
2370
#ifdef TIC30MAGIC
2371
    case TIC30MAGIC:
2372
      arch = bfd_arch_tic30;
2373
      break;
2374
#endif
2375
2376
#ifdef TICOFF0MAGIC
2377
#ifdef TICOFF_TARGET_ARCH
2378
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2379
    case TICOFF0MAGIC:
2380
      arch = TICOFF_TARGET_ARCH;
2381
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2382
      break;
2383
#endif
2384
#endif
2385
2386
#ifdef TICOFF1MAGIC
2387
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2388
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2389
    case TICOFF1MAGIC:
2390
    case TICOFF2MAGIC:
2391
      switch (internal_f->f_target_id)
2392
  {
2393
#ifdef TI_TARGET_ID
2394
  case TI_TARGET_ID:
2395
    arch = TICOFF_TARGET_ARCH;
2396
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2397
    break;
2398
#endif
2399
  default:
2400
    arch = bfd_arch_obscure;
2401
    _bfd_error_handler
2402
      (_("unrecognized TI COFF target id '0x%x'"),
2403
       internal_f->f_target_id);
2404
    break;
2405
  }
2406
      break;
2407
#endif
2408
2409
#ifdef MCOREMAGIC
2410
    case MCOREMAGIC:
2411
      arch = bfd_arch_mcore;
2412
      break;
2413
#endif
2414
2415
0
    default:      /* Unreadable input file type.  */
2416
0
      arch = bfd_arch_obscure;
2417
0
      break;
2418
66.7k
    }
2419
2420
66.7k
  bfd_default_set_arch_mach (abfd, arch, machine);
2421
66.7k
  return true;
2422
66.7k
}
coff-i386.c:coff_set_arch_mach_hook
Line
Count
Source
2154
66.7k
{
2155
66.7k
  unsigned long machine;
2156
66.7k
  enum bfd_architecture arch;
2157
66.7k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2158
2159
  /* Zero selects the default machine for an arch.  */
2160
66.7k
  machine = 0;
2161
66.7k
  switch (internal_f->f_magic)
2162
66.7k
    {
2163
0
#ifdef I386MAGIC
2164
49.5k
    case I386MAGIC:
2165
52.6k
    case I386PTXMAGIC:
2166
54.7k
    case I386AIXMAGIC:   /* Danbury PS/2 AIX C Compiler.  */
2167
66.2k
    case LYNXCOFFMAGIC:
2168
66.5k
    case I386_APPLE_MAGIC:
2169
66.5k
    case I386_FREEBSD_MAGIC:
2170
66.6k
    case I386_LINUX_MAGIC:
2171
66.7k
    case I386_NETBSD_MAGIC:
2172
66.7k
      arch = bfd_arch_i386;
2173
66.7k
      break;
2174
0
#endif
2175
#ifdef AMD64MAGIC
2176
    case AMD64MAGIC:
2177
    case AMD64_APPLE_MAGIC:
2178
    case AMD64_FREEBSD_MAGIC:
2179
    case AMD64_LINUX_MAGIC:
2180
    case AMD64_NETBSD_MAGIC:
2181
      arch = bfd_arch_i386;
2182
      machine = bfd_mach_x86_64;
2183
      break;
2184
#endif
2185
#ifdef IA64MAGIC
2186
    case IA64MAGIC:
2187
      arch = bfd_arch_ia64;
2188
      break;
2189
#endif
2190
#ifdef ARMMAGIC
2191
    case ARMMAGIC:
2192
    case ARMPEMAGIC:
2193
    case THUMBPEMAGIC:
2194
      arch = bfd_arch_arm;
2195
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2196
      if (machine == bfd_mach_arm_unknown)
2197
  {
2198
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2199
      {
2200
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2201
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2202
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2203
      default:
2204
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2205
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2206
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2207
        /* The COFF header does not have enough bits available
2208
     to cover all the different ARM architectures.  So
2209
     we interpret F_ARM_5, the highest flag value to mean
2210
     "the highest ARM architecture known to BFD" which is
2211
     currently the XScale.  */
2212
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2213
      }
2214
  }
2215
      break;
2216
#endif
2217
#ifdef AARCH64MAGIC
2218
    case AARCH64MAGIC:
2219
      arch = bfd_arch_aarch64;
2220
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2221
      break;
2222
#endif
2223
#ifdef LOONGARCH64MAGIC
2224
    case LOONGARCH64MAGIC:
2225
      arch = bfd_arch_loongarch;
2226
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2227
      break;
2228
#endif
2229
#ifdef RISCV64MAGIC
2230
    case RISCV64MAGIC:
2231
      arch = bfd_arch_riscv;
2232
      machine = bfd_mach_riscv64;
2233
      break;
2234
#endif
2235
#ifdef Z80MAGIC
2236
    case Z80MAGIC:
2237
      arch = bfd_arch_z80;
2238
      switch (internal_f->f_flags & F_MACHMASK)
2239
  {
2240
  case bfd_mach_z80strict << 12:
2241
  case bfd_mach_z80 << 12:
2242
  case bfd_mach_z80n << 12:
2243
  case bfd_mach_z80full << 12:
2244
  case bfd_mach_r800 << 12:
2245
  case bfd_mach_gbz80 << 12:
2246
  case bfd_mach_z180 << 12:
2247
  case bfd_mach_ez80_z80 << 12:
2248
  case bfd_mach_ez80_adl << 12:
2249
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2250
    break;
2251
  default:
2252
    return false;
2253
  }
2254
      break;
2255
#endif
2256
#ifdef Z8KMAGIC
2257
    case Z8KMAGIC:
2258
      arch = bfd_arch_z8k;
2259
      switch (internal_f->f_flags & F_MACHMASK)
2260
  {
2261
  case F_Z8001:
2262
    machine = bfd_mach_z8001;
2263
    break;
2264
  case F_Z8002:
2265
    machine = bfd_mach_z8002;
2266
    break;
2267
  default:
2268
    return false;
2269
  }
2270
      break;
2271
#endif
2272
2273
#ifdef RS6000COFF_C
2274
#ifdef XCOFF64
2275
    case U64_TOCMAGIC:
2276
    case U803XTOCMAGIC:
2277
#else
2278
    case U802ROMAGIC:
2279
    case U802WRMAGIC:
2280
    case U802TOCMAGIC:
2281
#endif
2282
      {
2283
  int cputype;
2284
2285
  if (xcoff_data (abfd)->cputype != -1)
2286
    cputype = xcoff_data (abfd)->cputype & 0xff;
2287
  else
2288
    {
2289
      /* We did not get a value from the a.out header.  If the
2290
         file has not been stripped, we may be able to get the
2291
         architecture information from the first symbol, if it
2292
         is a .file symbol.  */
2293
      if (obj_raw_syment_count (abfd) == 0)
2294
        cputype = 0;
2295
      else
2296
        {
2297
    bfd_byte *buf;
2298
    struct internal_syment sym;
2299
    bfd_size_type amt = bfd_coff_symesz (abfd);
2300
2301
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2302
      return false;
2303
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2304
    if (buf == NULL)
2305
      return false;
2306
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2307
    if (sym.n_sclass == C_FILE)
2308
      cputype = sym.n_type & 0xff;
2309
    else
2310
      cputype = 0;
2311
    free (buf);
2312
        }
2313
    }
2314
2315
  /* FIXME: We don't handle all cases here.  */
2316
  switch (cputype)
2317
    {
2318
    default:
2319
    case 0:
2320
      arch = bfd_xcoff_architecture (abfd);
2321
      machine = bfd_xcoff_machine (abfd);
2322
      break;
2323
2324
    case 1:
2325
      arch = bfd_arch_powerpc;
2326
      machine = bfd_mach_ppc_601;
2327
      break;
2328
    case 2: /* 64 bit PowerPC */
2329
      arch = bfd_arch_powerpc;
2330
      machine = bfd_mach_ppc_620;
2331
      break;
2332
    case 3:
2333
      arch = bfd_arch_powerpc;
2334
      machine = bfd_mach_ppc;
2335
      break;
2336
    case 4:
2337
      arch = bfd_arch_rs6000;
2338
      machine = bfd_mach_rs6k;
2339
      break;
2340
    }
2341
      }
2342
      break;
2343
#endif
2344
2345
#ifdef SH_ARCH_MAGIC_BIG
2346
    case SH_ARCH_MAGIC_BIG:
2347
    case SH_ARCH_MAGIC_LITTLE:
2348
#ifdef COFF_WITH_PE
2349
    case SH_ARCH_MAGIC_WINCE:
2350
#endif
2351
      arch = bfd_arch_sh;
2352
      break;
2353
#endif
2354
2355
#ifdef MIPS_ARCH_MAGIC_WINCE
2356
    case MIPS_ARCH_MAGIC_WINCE:
2357
      arch = bfd_arch_mips;
2358
      break;
2359
#endif
2360
2361
#ifdef SPARCMAGIC
2362
    case SPARCMAGIC:
2363
#ifdef LYNXCOFFMAGIC
2364
    case LYNXCOFFMAGIC:
2365
#endif
2366
      arch = bfd_arch_sparc;
2367
      break;
2368
#endif
2369
2370
#ifdef TIC30MAGIC
2371
    case TIC30MAGIC:
2372
      arch = bfd_arch_tic30;
2373
      break;
2374
#endif
2375
2376
#ifdef TICOFF0MAGIC
2377
#ifdef TICOFF_TARGET_ARCH
2378
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2379
    case TICOFF0MAGIC:
2380
      arch = TICOFF_TARGET_ARCH;
2381
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2382
      break;
2383
#endif
2384
#endif
2385
2386
#ifdef TICOFF1MAGIC
2387
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2388
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2389
    case TICOFF1MAGIC:
2390
    case TICOFF2MAGIC:
2391
      switch (internal_f->f_target_id)
2392
  {
2393
#ifdef TI_TARGET_ID
2394
  case TI_TARGET_ID:
2395
    arch = TICOFF_TARGET_ARCH;
2396
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2397
    break;
2398
#endif
2399
  default:
2400
    arch = bfd_arch_obscure;
2401
    _bfd_error_handler
2402
      (_("unrecognized TI COFF target id '0x%x'"),
2403
       internal_f->f_target_id);
2404
    break;
2405
  }
2406
      break;
2407
#endif
2408
2409
#ifdef MCOREMAGIC
2410
    case MCOREMAGIC:
2411
      arch = bfd_arch_mcore;
2412
      break;
2413
#endif
2414
2415
0
    default:      /* Unreadable input file type.  */
2416
0
      arch = bfd_arch_obscure;
2417
0
      break;
2418
66.7k
    }
2419
2420
66.7k
  bfd_default_set_arch_mach (abfd, arch, machine);
2421
66.7k
  return true;
2422
66.7k
}
coff-rs6000.c:coff_set_arch_mach_hook
Line
Count
Source
2154
96.2k
{
2155
96.2k
  unsigned long machine;
2156
96.2k
  enum bfd_architecture arch;
2157
96.2k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2158
2159
  /* Zero selects the default machine for an arch.  */
2160
96.2k
  machine = 0;
2161
96.2k
  switch (internal_f->f_magic)
2162
96.2k
    {
2163
#ifdef I386MAGIC
2164
    case I386MAGIC:
2165
    case I386PTXMAGIC:
2166
    case I386AIXMAGIC:    /* Danbury PS/2 AIX C Compiler.  */
2167
    case LYNXCOFFMAGIC:
2168
    case I386_APPLE_MAGIC:
2169
    case I386_FREEBSD_MAGIC:
2170
    case I386_LINUX_MAGIC:
2171
    case I386_NETBSD_MAGIC:
2172
      arch = bfd_arch_i386;
2173
      break;
2174
#endif
2175
#ifdef AMD64MAGIC
2176
    case AMD64MAGIC:
2177
    case AMD64_APPLE_MAGIC:
2178
    case AMD64_FREEBSD_MAGIC:
2179
    case AMD64_LINUX_MAGIC:
2180
    case AMD64_NETBSD_MAGIC:
2181
      arch = bfd_arch_i386;
2182
      machine = bfd_mach_x86_64;
2183
      break;
2184
#endif
2185
#ifdef IA64MAGIC
2186
    case IA64MAGIC:
2187
      arch = bfd_arch_ia64;
2188
      break;
2189
#endif
2190
#ifdef ARMMAGIC
2191
    case ARMMAGIC:
2192
    case ARMPEMAGIC:
2193
    case THUMBPEMAGIC:
2194
      arch = bfd_arch_arm;
2195
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2196
      if (machine == bfd_mach_arm_unknown)
2197
  {
2198
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2199
      {
2200
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2201
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2202
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2203
      default:
2204
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2205
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2206
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2207
        /* The COFF header does not have enough bits available
2208
     to cover all the different ARM architectures.  So
2209
     we interpret F_ARM_5, the highest flag value to mean
2210
     "the highest ARM architecture known to BFD" which is
2211
     currently the XScale.  */
2212
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2213
      }
2214
  }
2215
      break;
2216
#endif
2217
#ifdef AARCH64MAGIC
2218
    case AARCH64MAGIC:
2219
      arch = bfd_arch_aarch64;
2220
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2221
      break;
2222
#endif
2223
#ifdef LOONGARCH64MAGIC
2224
    case LOONGARCH64MAGIC:
2225
      arch = bfd_arch_loongarch;
2226
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2227
      break;
2228
#endif
2229
#ifdef RISCV64MAGIC
2230
    case RISCV64MAGIC:
2231
      arch = bfd_arch_riscv;
2232
      machine = bfd_mach_riscv64;
2233
      break;
2234
#endif
2235
#ifdef Z80MAGIC
2236
    case Z80MAGIC:
2237
      arch = bfd_arch_z80;
2238
      switch (internal_f->f_flags & F_MACHMASK)
2239
  {
2240
  case bfd_mach_z80strict << 12:
2241
  case bfd_mach_z80 << 12:
2242
  case bfd_mach_z80n << 12:
2243
  case bfd_mach_z80full << 12:
2244
  case bfd_mach_r800 << 12:
2245
  case bfd_mach_gbz80 << 12:
2246
  case bfd_mach_z180 << 12:
2247
  case bfd_mach_ez80_z80 << 12:
2248
  case bfd_mach_ez80_adl << 12:
2249
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2250
    break;
2251
  default:
2252
    return false;
2253
  }
2254
      break;
2255
#endif
2256
#ifdef Z8KMAGIC
2257
    case Z8KMAGIC:
2258
      arch = bfd_arch_z8k;
2259
      switch (internal_f->f_flags & F_MACHMASK)
2260
  {
2261
  case F_Z8001:
2262
    machine = bfd_mach_z8001;
2263
    break;
2264
  case F_Z8002:
2265
    machine = bfd_mach_z8002;
2266
    break;
2267
  default:
2268
    return false;
2269
  }
2270
      break;
2271
#endif
2272
2273
0
#ifdef RS6000COFF_C
2274
#ifdef XCOFF64
2275
    case U64_TOCMAGIC:
2276
    case U803XTOCMAGIC:
2277
#else
2278
42.0k
    case U802ROMAGIC:
2279
57.0k
    case U802WRMAGIC:
2280
96.2k
    case U802TOCMAGIC:
2281
96.2k
#endif
2282
96.2k
      {
2283
96.2k
  int cputype;
2284
2285
96.2k
  if (xcoff_data (abfd)->cputype != -1)
2286
19.2k
    cputype = xcoff_data (abfd)->cputype & 0xff;
2287
76.9k
  else
2288
76.9k
    {
2289
      /* We did not get a value from the a.out header.  If the
2290
         file has not been stripped, we may be able to get the
2291
         architecture information from the first symbol, if it
2292
         is a .file symbol.  */
2293
76.9k
      if (obj_raw_syment_count (abfd) == 0)
2294
30.2k
        cputype = 0;
2295
46.7k
      else
2296
46.7k
        {
2297
46.7k
    bfd_byte *buf;
2298
46.7k
    struct internal_syment sym;
2299
46.7k
    bfd_size_type amt = bfd_coff_symesz (abfd);
2300
2301
46.7k
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2302
0
      return false;
2303
46.7k
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2304
46.7k
    if (buf == NULL)
2305
947
      return false;
2306
45.8k
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2307
45.8k
    if (sym.n_sclass == C_FILE)
2308
1.55k
      cputype = sym.n_type & 0xff;
2309
44.2k
    else
2310
44.2k
      cputype = 0;
2311
45.8k
    free (buf);
2312
45.8k
        }
2313
76.9k
    }
2314
2315
  /* FIXME: We don't handle all cases here.  */
2316
95.3k
  switch (cputype)
2317
95.3k
    {
2318
10.9k
    default:
2319
90.4k
    case 0:
2320
90.4k
      arch = bfd_xcoff_architecture (abfd);
2321
90.4k
      machine = bfd_xcoff_machine (abfd);
2322
90.4k
      break;
2323
2324
1.34k
    case 1:
2325
1.34k
      arch = bfd_arch_powerpc;
2326
1.34k
      machine = bfd_mach_ppc_601;
2327
1.34k
      break;
2328
1.46k
    case 2: /* 64 bit PowerPC */
2329
1.46k
      arch = bfd_arch_powerpc;
2330
1.46k
      machine = bfd_mach_ppc_620;
2331
1.46k
      break;
2332
953
    case 3:
2333
953
      arch = bfd_arch_powerpc;
2334
953
      machine = bfd_mach_ppc;
2335
953
      break;
2336
1.04k
    case 4:
2337
1.04k
      arch = bfd_arch_rs6000;
2338
1.04k
      machine = bfd_mach_rs6k;
2339
1.04k
      break;
2340
95.3k
    }
2341
95.3k
      }
2342
95.3k
      break;
2343
95.3k
#endif
2344
2345
#ifdef SH_ARCH_MAGIC_BIG
2346
    case SH_ARCH_MAGIC_BIG:
2347
    case SH_ARCH_MAGIC_LITTLE:
2348
#ifdef COFF_WITH_PE
2349
    case SH_ARCH_MAGIC_WINCE:
2350
#endif
2351
      arch = bfd_arch_sh;
2352
      break;
2353
#endif
2354
2355
#ifdef MIPS_ARCH_MAGIC_WINCE
2356
    case MIPS_ARCH_MAGIC_WINCE:
2357
      arch = bfd_arch_mips;
2358
      break;
2359
#endif
2360
2361
#ifdef SPARCMAGIC
2362
    case SPARCMAGIC:
2363
#ifdef LYNXCOFFMAGIC
2364
    case LYNXCOFFMAGIC:
2365
#endif
2366
      arch = bfd_arch_sparc;
2367
      break;
2368
#endif
2369
2370
#ifdef TIC30MAGIC
2371
    case TIC30MAGIC:
2372
      arch = bfd_arch_tic30;
2373
      break;
2374
#endif
2375
2376
#ifdef TICOFF0MAGIC
2377
#ifdef TICOFF_TARGET_ARCH
2378
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2379
    case TICOFF0MAGIC:
2380
      arch = TICOFF_TARGET_ARCH;
2381
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2382
      break;
2383
#endif
2384
#endif
2385
2386
#ifdef TICOFF1MAGIC
2387
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2388
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2389
    case TICOFF1MAGIC:
2390
    case TICOFF2MAGIC:
2391
      switch (internal_f->f_target_id)
2392
  {
2393
#ifdef TI_TARGET_ID
2394
  case TI_TARGET_ID:
2395
    arch = TICOFF_TARGET_ARCH;
2396
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2397
    break;
2398
#endif
2399
  default:
2400
    arch = bfd_arch_obscure;
2401
    _bfd_error_handler
2402
      (_("unrecognized TI COFF target id '0x%x'"),
2403
       internal_f->f_target_id);
2404
    break;
2405
  }
2406
      break;
2407
#endif
2408
2409
#ifdef MCOREMAGIC
2410
    case MCOREMAGIC:
2411
      arch = bfd_arch_mcore;
2412
      break;
2413
#endif
2414
2415
95.3k
    default:      /* Unreadable input file type.  */
2416
0
      arch = bfd_arch_obscure;
2417
0
      break;
2418
96.2k
    }
2419
2420
95.3k
  bfd_default_set_arch_mach (abfd, arch, machine);
2421
95.3k
  return true;
2422
96.2k
}
coff-sh.c:coff_set_arch_mach_hook
Line
Count
Source
2154
82.9k
{
2155
82.9k
  unsigned long machine;
2156
82.9k
  enum bfd_architecture arch;
2157
82.9k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2158
2159
  /* Zero selects the default machine for an arch.  */
2160
82.9k
  machine = 0;
2161
82.9k
  switch (internal_f->f_magic)
2162
82.9k
    {
2163
#ifdef I386MAGIC
2164
    case I386MAGIC:
2165
    case I386PTXMAGIC:
2166
    case I386AIXMAGIC:    /* Danbury PS/2 AIX C Compiler.  */
2167
    case LYNXCOFFMAGIC:
2168
    case I386_APPLE_MAGIC:
2169
    case I386_FREEBSD_MAGIC:
2170
    case I386_LINUX_MAGIC:
2171
    case I386_NETBSD_MAGIC:
2172
      arch = bfd_arch_i386;
2173
      break;
2174
#endif
2175
#ifdef AMD64MAGIC
2176
    case AMD64MAGIC:
2177
    case AMD64_APPLE_MAGIC:
2178
    case AMD64_FREEBSD_MAGIC:
2179
    case AMD64_LINUX_MAGIC:
2180
    case AMD64_NETBSD_MAGIC:
2181
      arch = bfd_arch_i386;
2182
      machine = bfd_mach_x86_64;
2183
      break;
2184
#endif
2185
#ifdef IA64MAGIC
2186
    case IA64MAGIC:
2187
      arch = bfd_arch_ia64;
2188
      break;
2189
#endif
2190
#ifdef ARMMAGIC
2191
    case ARMMAGIC:
2192
    case ARMPEMAGIC:
2193
    case THUMBPEMAGIC:
2194
      arch = bfd_arch_arm;
2195
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2196
      if (machine == bfd_mach_arm_unknown)
2197
  {
2198
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2199
      {
2200
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2201
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2202
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2203
      default:
2204
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2205
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2206
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2207
        /* The COFF header does not have enough bits available
2208
     to cover all the different ARM architectures.  So
2209
     we interpret F_ARM_5, the highest flag value to mean
2210
     "the highest ARM architecture known to BFD" which is
2211
     currently the XScale.  */
2212
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2213
      }
2214
  }
2215
      break;
2216
#endif
2217
#ifdef AARCH64MAGIC
2218
    case AARCH64MAGIC:
2219
      arch = bfd_arch_aarch64;
2220
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2221
      break;
2222
#endif
2223
#ifdef LOONGARCH64MAGIC
2224
    case LOONGARCH64MAGIC:
2225
      arch = bfd_arch_loongarch;
2226
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2227
      break;
2228
#endif
2229
#ifdef RISCV64MAGIC
2230
    case RISCV64MAGIC:
2231
      arch = bfd_arch_riscv;
2232
      machine = bfd_mach_riscv64;
2233
      break;
2234
#endif
2235
#ifdef Z80MAGIC
2236
    case Z80MAGIC:
2237
      arch = bfd_arch_z80;
2238
      switch (internal_f->f_flags & F_MACHMASK)
2239
  {
2240
  case bfd_mach_z80strict << 12:
2241
  case bfd_mach_z80 << 12:
2242
  case bfd_mach_z80n << 12:
2243
  case bfd_mach_z80full << 12:
2244
  case bfd_mach_r800 << 12:
2245
  case bfd_mach_gbz80 << 12:
2246
  case bfd_mach_z180 << 12:
2247
  case bfd_mach_ez80_z80 << 12:
2248
  case bfd_mach_ez80_adl << 12:
2249
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2250
    break;
2251
  default:
2252
    return false;
2253
  }
2254
      break;
2255
#endif
2256
#ifdef Z8KMAGIC
2257
    case Z8KMAGIC:
2258
      arch = bfd_arch_z8k;
2259
      switch (internal_f->f_flags & F_MACHMASK)
2260
  {
2261
  case F_Z8001:
2262
    machine = bfd_mach_z8001;
2263
    break;
2264
  case F_Z8002:
2265
    machine = bfd_mach_z8002;
2266
    break;
2267
  default:
2268
    return false;
2269
  }
2270
      break;
2271
#endif
2272
2273
#ifdef RS6000COFF_C
2274
#ifdef XCOFF64
2275
    case U64_TOCMAGIC:
2276
    case U803XTOCMAGIC:
2277
#else
2278
    case U802ROMAGIC:
2279
    case U802WRMAGIC:
2280
    case U802TOCMAGIC:
2281
#endif
2282
      {
2283
  int cputype;
2284
2285
  if (xcoff_data (abfd)->cputype != -1)
2286
    cputype = xcoff_data (abfd)->cputype & 0xff;
2287
  else
2288
    {
2289
      /* We did not get a value from the a.out header.  If the
2290
         file has not been stripped, we may be able to get the
2291
         architecture information from the first symbol, if it
2292
         is a .file symbol.  */
2293
      if (obj_raw_syment_count (abfd) == 0)
2294
        cputype = 0;
2295
      else
2296
        {
2297
    bfd_byte *buf;
2298
    struct internal_syment sym;
2299
    bfd_size_type amt = bfd_coff_symesz (abfd);
2300
2301
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2302
      return false;
2303
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2304
    if (buf == NULL)
2305
      return false;
2306
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2307
    if (sym.n_sclass == C_FILE)
2308
      cputype = sym.n_type & 0xff;
2309
    else
2310
      cputype = 0;
2311
    free (buf);
2312
        }
2313
    }
2314
2315
  /* FIXME: We don't handle all cases here.  */
2316
  switch (cputype)
2317
    {
2318
    default:
2319
    case 0:
2320
      arch = bfd_xcoff_architecture (abfd);
2321
      machine = bfd_xcoff_machine (abfd);
2322
      break;
2323
2324
    case 1:
2325
      arch = bfd_arch_powerpc;
2326
      machine = bfd_mach_ppc_601;
2327
      break;
2328
    case 2: /* 64 bit PowerPC */
2329
      arch = bfd_arch_powerpc;
2330
      machine = bfd_mach_ppc_620;
2331
      break;
2332
    case 3:
2333
      arch = bfd_arch_powerpc;
2334
      machine = bfd_mach_ppc;
2335
      break;
2336
    case 4:
2337
      arch = bfd_arch_rs6000;
2338
      machine = bfd_mach_rs6k;
2339
      break;
2340
    }
2341
      }
2342
      break;
2343
#endif
2344
2345
0
#ifdef SH_ARCH_MAGIC_BIG
2346
60.2k
    case SH_ARCH_MAGIC_BIG:
2347
61.4k
    case SH_ARCH_MAGIC_LITTLE:
2348
#ifdef COFF_WITH_PE
2349
    case SH_ARCH_MAGIC_WINCE:
2350
#endif
2351
61.4k
      arch = bfd_arch_sh;
2352
61.4k
      break;
2353
0
#endif
2354
2355
#ifdef MIPS_ARCH_MAGIC_WINCE
2356
    case MIPS_ARCH_MAGIC_WINCE:
2357
      arch = bfd_arch_mips;
2358
      break;
2359
#endif
2360
2361
#ifdef SPARCMAGIC
2362
    case SPARCMAGIC:
2363
#ifdef LYNXCOFFMAGIC
2364
    case LYNXCOFFMAGIC:
2365
#endif
2366
      arch = bfd_arch_sparc;
2367
      break;
2368
#endif
2369
2370
#ifdef TIC30MAGIC
2371
    case TIC30MAGIC:
2372
      arch = bfd_arch_tic30;
2373
      break;
2374
#endif
2375
2376
#ifdef TICOFF0MAGIC
2377
#ifdef TICOFF_TARGET_ARCH
2378
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2379
    case TICOFF0MAGIC:
2380
      arch = TICOFF_TARGET_ARCH;
2381
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2382
      break;
2383
#endif
2384
#endif
2385
2386
#ifdef TICOFF1MAGIC
2387
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2388
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2389
    case TICOFF1MAGIC:
2390
    case TICOFF2MAGIC:
2391
      switch (internal_f->f_target_id)
2392
  {
2393
#ifdef TI_TARGET_ID
2394
  case TI_TARGET_ID:
2395
    arch = TICOFF_TARGET_ARCH;
2396
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2397
    break;
2398
#endif
2399
  default:
2400
    arch = bfd_arch_obscure;
2401
    _bfd_error_handler
2402
      (_("unrecognized TI COFF target id '0x%x'"),
2403
       internal_f->f_target_id);
2404
    break;
2405
  }
2406
      break;
2407
#endif
2408
2409
#ifdef MCOREMAGIC
2410
    case MCOREMAGIC:
2411
      arch = bfd_arch_mcore;
2412
      break;
2413
#endif
2414
2415
21.4k
    default:      /* Unreadable input file type.  */
2416
21.4k
      arch = bfd_arch_obscure;
2417
21.4k
      break;
2418
82.9k
    }
2419
2420
82.9k
  bfd_default_set_arch_mach (abfd, arch, machine);
2421
82.9k
  return true;
2422
82.9k
}
coff-stgo32.c:coff_set_arch_mach_hook
Line
Count
Source
2154
3.33k
{
2155
3.33k
  unsigned long machine;
2156
3.33k
  enum bfd_architecture arch;
2157
3.33k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2158
2159
  /* Zero selects the default machine for an arch.  */
2160
3.33k
  machine = 0;
2161
3.33k
  switch (internal_f->f_magic)
2162
3.33k
    {
2163
0
#ifdef I386MAGIC
2164
1.70k
    case I386MAGIC:
2165
2.46k
    case I386PTXMAGIC:
2166
2.60k
    case I386AIXMAGIC:   /* Danbury PS/2 AIX C Compiler.  */
2167
2.69k
    case LYNXCOFFMAGIC:
2168
2.69k
    case I386_APPLE_MAGIC:
2169
2.70k
    case I386_FREEBSD_MAGIC:
2170
2.71k
    case I386_LINUX_MAGIC:
2171
3.33k
    case I386_NETBSD_MAGIC:
2172
3.33k
      arch = bfd_arch_i386;
2173
3.33k
      break;
2174
0
#endif
2175
#ifdef AMD64MAGIC
2176
    case AMD64MAGIC:
2177
    case AMD64_APPLE_MAGIC:
2178
    case AMD64_FREEBSD_MAGIC:
2179
    case AMD64_LINUX_MAGIC:
2180
    case AMD64_NETBSD_MAGIC:
2181
      arch = bfd_arch_i386;
2182
      machine = bfd_mach_x86_64;
2183
      break;
2184
#endif
2185
#ifdef IA64MAGIC
2186
    case IA64MAGIC:
2187
      arch = bfd_arch_ia64;
2188
      break;
2189
#endif
2190
#ifdef ARMMAGIC
2191
    case ARMMAGIC:
2192
    case ARMPEMAGIC:
2193
    case THUMBPEMAGIC:
2194
      arch = bfd_arch_arm;
2195
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2196
      if (machine == bfd_mach_arm_unknown)
2197
  {
2198
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2199
      {
2200
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2201
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2202
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2203
      default:
2204
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2205
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2206
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2207
        /* The COFF header does not have enough bits available
2208
     to cover all the different ARM architectures.  So
2209
     we interpret F_ARM_5, the highest flag value to mean
2210
     "the highest ARM architecture known to BFD" which is
2211
     currently the XScale.  */
2212
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2213
      }
2214
  }
2215
      break;
2216
#endif
2217
#ifdef AARCH64MAGIC
2218
    case AARCH64MAGIC:
2219
      arch = bfd_arch_aarch64;
2220
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2221
      break;
2222
#endif
2223
#ifdef LOONGARCH64MAGIC
2224
    case LOONGARCH64MAGIC:
2225
      arch = bfd_arch_loongarch;
2226
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2227
      break;
2228
#endif
2229
#ifdef RISCV64MAGIC
2230
    case RISCV64MAGIC:
2231
      arch = bfd_arch_riscv;
2232
      machine = bfd_mach_riscv64;
2233
      break;
2234
#endif
2235
#ifdef Z80MAGIC
2236
    case Z80MAGIC:
2237
      arch = bfd_arch_z80;
2238
      switch (internal_f->f_flags & F_MACHMASK)
2239
  {
2240
  case bfd_mach_z80strict << 12:
2241
  case bfd_mach_z80 << 12:
2242
  case bfd_mach_z80n << 12:
2243
  case bfd_mach_z80full << 12:
2244
  case bfd_mach_r800 << 12:
2245
  case bfd_mach_gbz80 << 12:
2246
  case bfd_mach_z180 << 12:
2247
  case bfd_mach_ez80_z80 << 12:
2248
  case bfd_mach_ez80_adl << 12:
2249
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2250
    break;
2251
  default:
2252
    return false;
2253
  }
2254
      break;
2255
#endif
2256
#ifdef Z8KMAGIC
2257
    case Z8KMAGIC:
2258
      arch = bfd_arch_z8k;
2259
      switch (internal_f->f_flags & F_MACHMASK)
2260
  {
2261
  case F_Z8001:
2262
    machine = bfd_mach_z8001;
2263
    break;
2264
  case F_Z8002:
2265
    machine = bfd_mach_z8002;
2266
    break;
2267
  default:
2268
    return false;
2269
  }
2270
      break;
2271
#endif
2272
2273
#ifdef RS6000COFF_C
2274
#ifdef XCOFF64
2275
    case U64_TOCMAGIC:
2276
    case U803XTOCMAGIC:
2277
#else
2278
    case U802ROMAGIC:
2279
    case U802WRMAGIC:
2280
    case U802TOCMAGIC:
2281
#endif
2282
      {
2283
  int cputype;
2284
2285
  if (xcoff_data (abfd)->cputype != -1)
2286
    cputype = xcoff_data (abfd)->cputype & 0xff;
2287
  else
2288
    {
2289
      /* We did not get a value from the a.out header.  If the
2290
         file has not been stripped, we may be able to get the
2291
         architecture information from the first symbol, if it
2292
         is a .file symbol.  */
2293
      if (obj_raw_syment_count (abfd) == 0)
2294
        cputype = 0;
2295
      else
2296
        {
2297
    bfd_byte *buf;
2298
    struct internal_syment sym;
2299
    bfd_size_type amt = bfd_coff_symesz (abfd);
2300
2301
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2302
      return false;
2303
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2304
    if (buf == NULL)
2305
      return false;
2306
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2307
    if (sym.n_sclass == C_FILE)
2308
      cputype = sym.n_type & 0xff;
2309
    else
2310
      cputype = 0;
2311
    free (buf);
2312
        }
2313
    }
2314
2315
  /* FIXME: We don't handle all cases here.  */
2316
  switch (cputype)
2317
    {
2318
    default:
2319
    case 0:
2320
      arch = bfd_xcoff_architecture (abfd);
2321
      machine = bfd_xcoff_machine (abfd);
2322
      break;
2323
2324
    case 1:
2325
      arch = bfd_arch_powerpc;
2326
      machine = bfd_mach_ppc_601;
2327
      break;
2328
    case 2: /* 64 bit PowerPC */
2329
      arch = bfd_arch_powerpc;
2330
      machine = bfd_mach_ppc_620;
2331
      break;
2332
    case 3:
2333
      arch = bfd_arch_powerpc;
2334
      machine = bfd_mach_ppc;
2335
      break;
2336
    case 4:
2337
      arch = bfd_arch_rs6000;
2338
      machine = bfd_mach_rs6k;
2339
      break;
2340
    }
2341
      }
2342
      break;
2343
#endif
2344
2345
#ifdef SH_ARCH_MAGIC_BIG
2346
    case SH_ARCH_MAGIC_BIG:
2347
    case SH_ARCH_MAGIC_LITTLE:
2348
#ifdef COFF_WITH_PE
2349
    case SH_ARCH_MAGIC_WINCE:
2350
#endif
2351
      arch = bfd_arch_sh;
2352
      break;
2353
#endif
2354
2355
#ifdef MIPS_ARCH_MAGIC_WINCE
2356
    case MIPS_ARCH_MAGIC_WINCE:
2357
      arch = bfd_arch_mips;
2358
      break;
2359
#endif
2360
2361
#ifdef SPARCMAGIC
2362
    case SPARCMAGIC:
2363
#ifdef LYNXCOFFMAGIC
2364
    case LYNXCOFFMAGIC:
2365
#endif
2366
      arch = bfd_arch_sparc;
2367
      break;
2368
#endif
2369
2370
#ifdef TIC30MAGIC
2371
    case TIC30MAGIC:
2372
      arch = bfd_arch_tic30;
2373
      break;
2374
#endif
2375
2376
#ifdef TICOFF0MAGIC
2377
#ifdef TICOFF_TARGET_ARCH
2378
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2379
    case TICOFF0MAGIC:
2380
      arch = TICOFF_TARGET_ARCH;
2381
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2382
      break;
2383
#endif
2384
#endif
2385
2386
#ifdef TICOFF1MAGIC
2387
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2388
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2389
    case TICOFF1MAGIC:
2390
    case TICOFF2MAGIC:
2391
      switch (internal_f->f_target_id)
2392
  {
2393
#ifdef TI_TARGET_ID
2394
  case TI_TARGET_ID:
2395
    arch = TICOFF_TARGET_ARCH;
2396
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2397
    break;
2398
#endif
2399
  default:
2400
    arch = bfd_arch_obscure;
2401
    _bfd_error_handler
2402
      (_("unrecognized TI COFF target id '0x%x'"),
2403
       internal_f->f_target_id);
2404
    break;
2405
  }
2406
      break;
2407
#endif
2408
2409
#ifdef MCOREMAGIC
2410
    case MCOREMAGIC:
2411
      arch = bfd_arch_mcore;
2412
      break;
2413
#endif
2414
2415
0
    default:      /* Unreadable input file type.  */
2416
0
      arch = bfd_arch_obscure;
2417
0
      break;
2418
3.33k
    }
2419
2420
3.33k
  bfd_default_set_arch_mach (abfd, arch, machine);
2421
3.33k
  return true;
2422
3.33k
}
coff-tic30.c:coff_set_arch_mach_hook
Line
Count
Source
2154
59.4k
{
2155
59.4k
  unsigned long machine;
2156
59.4k
  enum bfd_architecture arch;
2157
59.4k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2158
2159
  /* Zero selects the default machine for an arch.  */
2160
59.4k
  machine = 0;
2161
59.4k
  switch (internal_f->f_magic)
2162
59.4k
    {
2163
#ifdef I386MAGIC
2164
    case I386MAGIC:
2165
    case I386PTXMAGIC:
2166
    case I386AIXMAGIC:    /* Danbury PS/2 AIX C Compiler.  */
2167
    case LYNXCOFFMAGIC:
2168
    case I386_APPLE_MAGIC:
2169
    case I386_FREEBSD_MAGIC:
2170
    case I386_LINUX_MAGIC:
2171
    case I386_NETBSD_MAGIC:
2172
      arch = bfd_arch_i386;
2173
      break;
2174
#endif
2175
#ifdef AMD64MAGIC
2176
    case AMD64MAGIC:
2177
    case AMD64_APPLE_MAGIC:
2178
    case AMD64_FREEBSD_MAGIC:
2179
    case AMD64_LINUX_MAGIC:
2180
    case AMD64_NETBSD_MAGIC:
2181
      arch = bfd_arch_i386;
2182
      machine = bfd_mach_x86_64;
2183
      break;
2184
#endif
2185
#ifdef IA64MAGIC
2186
    case IA64MAGIC:
2187
      arch = bfd_arch_ia64;
2188
      break;
2189
#endif
2190
#ifdef ARMMAGIC
2191
    case ARMMAGIC:
2192
    case ARMPEMAGIC:
2193
    case THUMBPEMAGIC:
2194
      arch = bfd_arch_arm;
2195
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2196
      if (machine == bfd_mach_arm_unknown)
2197
  {
2198
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2199
      {
2200
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2201
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2202
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2203
      default:
2204
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2205
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2206
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2207
        /* The COFF header does not have enough bits available
2208
     to cover all the different ARM architectures.  So
2209
     we interpret F_ARM_5, the highest flag value to mean
2210
     "the highest ARM architecture known to BFD" which is
2211
     currently the XScale.  */
2212
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2213
      }
2214
  }
2215
      break;
2216
#endif
2217
#ifdef AARCH64MAGIC
2218
    case AARCH64MAGIC:
2219
      arch = bfd_arch_aarch64;
2220
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2221
      break;
2222
#endif
2223
#ifdef LOONGARCH64MAGIC
2224
    case LOONGARCH64MAGIC:
2225
      arch = bfd_arch_loongarch;
2226
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2227
      break;
2228
#endif
2229
#ifdef RISCV64MAGIC
2230
    case RISCV64MAGIC:
2231
      arch = bfd_arch_riscv;
2232
      machine = bfd_mach_riscv64;
2233
      break;
2234
#endif
2235
#ifdef Z80MAGIC
2236
    case Z80MAGIC:
2237
      arch = bfd_arch_z80;
2238
      switch (internal_f->f_flags & F_MACHMASK)
2239
  {
2240
  case bfd_mach_z80strict << 12:
2241
  case bfd_mach_z80 << 12:
2242
  case bfd_mach_z80n << 12:
2243
  case bfd_mach_z80full << 12:
2244
  case bfd_mach_r800 << 12:
2245
  case bfd_mach_gbz80 << 12:
2246
  case bfd_mach_z180 << 12:
2247
  case bfd_mach_ez80_z80 << 12:
2248
  case bfd_mach_ez80_adl << 12:
2249
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2250
    break;
2251
  default:
2252
    return false;
2253
  }
2254
      break;
2255
#endif
2256
#ifdef Z8KMAGIC
2257
    case Z8KMAGIC:
2258
      arch = bfd_arch_z8k;
2259
      switch (internal_f->f_flags & F_MACHMASK)
2260
  {
2261
  case F_Z8001:
2262
    machine = bfd_mach_z8001;
2263
    break;
2264
  case F_Z8002:
2265
    machine = bfd_mach_z8002;
2266
    break;
2267
  default:
2268
    return false;
2269
  }
2270
      break;
2271
#endif
2272
2273
#ifdef RS6000COFF_C
2274
#ifdef XCOFF64
2275
    case U64_TOCMAGIC:
2276
    case U803XTOCMAGIC:
2277
#else
2278
    case U802ROMAGIC:
2279
    case U802WRMAGIC:
2280
    case U802TOCMAGIC:
2281
#endif
2282
      {
2283
  int cputype;
2284
2285
  if (xcoff_data (abfd)->cputype != -1)
2286
    cputype = xcoff_data (abfd)->cputype & 0xff;
2287
  else
2288
    {
2289
      /* We did not get a value from the a.out header.  If the
2290
         file has not been stripped, we may be able to get the
2291
         architecture information from the first symbol, if it
2292
         is a .file symbol.  */
2293
      if (obj_raw_syment_count (abfd) == 0)
2294
        cputype = 0;
2295
      else
2296
        {
2297
    bfd_byte *buf;
2298
    struct internal_syment sym;
2299
    bfd_size_type amt = bfd_coff_symesz (abfd);
2300
2301
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2302
      return false;
2303
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2304
    if (buf == NULL)
2305
      return false;
2306
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2307
    if (sym.n_sclass == C_FILE)
2308
      cputype = sym.n_type & 0xff;
2309
    else
2310
      cputype = 0;
2311
    free (buf);
2312
        }
2313
    }
2314
2315
  /* FIXME: We don't handle all cases here.  */
2316
  switch (cputype)
2317
    {
2318
    default:
2319
    case 0:
2320
      arch = bfd_xcoff_architecture (abfd);
2321
      machine = bfd_xcoff_machine (abfd);
2322
      break;
2323
2324
    case 1:
2325
      arch = bfd_arch_powerpc;
2326
      machine = bfd_mach_ppc_601;
2327
      break;
2328
    case 2: /* 64 bit PowerPC */
2329
      arch = bfd_arch_powerpc;
2330
      machine = bfd_mach_ppc_620;
2331
      break;
2332
    case 3:
2333
      arch = bfd_arch_powerpc;
2334
      machine = bfd_mach_ppc;
2335
      break;
2336
    case 4:
2337
      arch = bfd_arch_rs6000;
2338
      machine = bfd_mach_rs6k;
2339
      break;
2340
    }
2341
      }
2342
      break;
2343
#endif
2344
2345
#ifdef SH_ARCH_MAGIC_BIG
2346
    case SH_ARCH_MAGIC_BIG:
2347
    case SH_ARCH_MAGIC_LITTLE:
2348
#ifdef COFF_WITH_PE
2349
    case SH_ARCH_MAGIC_WINCE:
2350
#endif
2351
      arch = bfd_arch_sh;
2352
      break;
2353
#endif
2354
2355
#ifdef MIPS_ARCH_MAGIC_WINCE
2356
    case MIPS_ARCH_MAGIC_WINCE:
2357
      arch = bfd_arch_mips;
2358
      break;
2359
#endif
2360
2361
#ifdef SPARCMAGIC
2362
    case SPARCMAGIC:
2363
#ifdef LYNXCOFFMAGIC
2364
    case LYNXCOFFMAGIC:
2365
#endif
2366
      arch = bfd_arch_sparc;
2367
      break;
2368
#endif
2369
2370
0
#ifdef TIC30MAGIC
2371
59.4k
    case TIC30MAGIC:
2372
59.4k
      arch = bfd_arch_tic30;
2373
59.4k
      break;
2374
0
#endif
2375
2376
#ifdef TICOFF0MAGIC
2377
#ifdef TICOFF_TARGET_ARCH
2378
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2379
    case TICOFF0MAGIC:
2380
      arch = TICOFF_TARGET_ARCH;
2381
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2382
      break;
2383
#endif
2384
#endif
2385
2386
#ifdef TICOFF1MAGIC
2387
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2388
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2389
    case TICOFF1MAGIC:
2390
    case TICOFF2MAGIC:
2391
      switch (internal_f->f_target_id)
2392
  {
2393
#ifdef TI_TARGET_ID
2394
  case TI_TARGET_ID:
2395
    arch = TICOFF_TARGET_ARCH;
2396
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2397
    break;
2398
#endif
2399
  default:
2400
    arch = bfd_arch_obscure;
2401
    _bfd_error_handler
2402
      (_("unrecognized TI COFF target id '0x%x'"),
2403
       internal_f->f_target_id);
2404
    break;
2405
  }
2406
      break;
2407
#endif
2408
2409
#ifdef MCOREMAGIC
2410
    case MCOREMAGIC:
2411
      arch = bfd_arch_mcore;
2412
      break;
2413
#endif
2414
2415
0
    default:      /* Unreadable input file type.  */
2416
0
      arch = bfd_arch_obscure;
2417
0
      break;
2418
59.4k
    }
2419
2420
59.4k
  bfd_default_set_arch_mach (abfd, arch, machine);
2421
59.4k
  return true;
2422
59.4k
}
Unexecuted instantiation: coff-tic4x.c:coff_set_arch_mach_hook
coff-tic54x.c:coff_set_arch_mach_hook
Line
Count
Source
2154
110k
{
2155
110k
  unsigned long machine;
2156
110k
  enum bfd_architecture arch;
2157
110k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2158
2159
  /* Zero selects the default machine for an arch.  */
2160
110k
  machine = 0;
2161
110k
  switch (internal_f->f_magic)
2162
110k
    {
2163
#ifdef I386MAGIC
2164
    case I386MAGIC:
2165
    case I386PTXMAGIC:
2166
    case I386AIXMAGIC:    /* Danbury PS/2 AIX C Compiler.  */
2167
    case LYNXCOFFMAGIC:
2168
    case I386_APPLE_MAGIC:
2169
    case I386_FREEBSD_MAGIC:
2170
    case I386_LINUX_MAGIC:
2171
    case I386_NETBSD_MAGIC:
2172
      arch = bfd_arch_i386;
2173
      break;
2174
#endif
2175
#ifdef AMD64MAGIC
2176
    case AMD64MAGIC:
2177
    case AMD64_APPLE_MAGIC:
2178
    case AMD64_FREEBSD_MAGIC:
2179
    case AMD64_LINUX_MAGIC:
2180
    case AMD64_NETBSD_MAGIC:
2181
      arch = bfd_arch_i386;
2182
      machine = bfd_mach_x86_64;
2183
      break;
2184
#endif
2185
#ifdef IA64MAGIC
2186
    case IA64MAGIC:
2187
      arch = bfd_arch_ia64;
2188
      break;
2189
#endif
2190
#ifdef ARMMAGIC
2191
    case ARMMAGIC:
2192
    case ARMPEMAGIC:
2193
    case THUMBPEMAGIC:
2194
      arch = bfd_arch_arm;
2195
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2196
      if (machine == bfd_mach_arm_unknown)
2197
  {
2198
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2199
      {
2200
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2201
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2202
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2203
      default:
2204
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2205
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2206
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2207
        /* The COFF header does not have enough bits available
2208
     to cover all the different ARM architectures.  So
2209
     we interpret F_ARM_5, the highest flag value to mean
2210
     "the highest ARM architecture known to BFD" which is
2211
     currently the XScale.  */
2212
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2213
      }
2214
  }
2215
      break;
2216
#endif
2217
#ifdef AARCH64MAGIC
2218
    case AARCH64MAGIC:
2219
      arch = bfd_arch_aarch64;
2220
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2221
      break;
2222
#endif
2223
#ifdef LOONGARCH64MAGIC
2224
    case LOONGARCH64MAGIC:
2225
      arch = bfd_arch_loongarch;
2226
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2227
      break;
2228
#endif
2229
#ifdef RISCV64MAGIC
2230
    case RISCV64MAGIC:
2231
      arch = bfd_arch_riscv;
2232
      machine = bfd_mach_riscv64;
2233
      break;
2234
#endif
2235
#ifdef Z80MAGIC
2236
    case Z80MAGIC:
2237
      arch = bfd_arch_z80;
2238
      switch (internal_f->f_flags & F_MACHMASK)
2239
  {
2240
  case bfd_mach_z80strict << 12:
2241
  case bfd_mach_z80 << 12:
2242
  case bfd_mach_z80n << 12:
2243
  case bfd_mach_z80full << 12:
2244
  case bfd_mach_r800 << 12:
2245
  case bfd_mach_gbz80 << 12:
2246
  case bfd_mach_z180 << 12:
2247
  case bfd_mach_ez80_z80 << 12:
2248
  case bfd_mach_ez80_adl << 12:
2249
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2250
    break;
2251
  default:
2252
    return false;
2253
  }
2254
      break;
2255
#endif
2256
#ifdef Z8KMAGIC
2257
    case Z8KMAGIC:
2258
      arch = bfd_arch_z8k;
2259
      switch (internal_f->f_flags & F_MACHMASK)
2260
  {
2261
  case F_Z8001:
2262
    machine = bfd_mach_z8001;
2263
    break;
2264
  case F_Z8002:
2265
    machine = bfd_mach_z8002;
2266
    break;
2267
  default:
2268
    return false;
2269
  }
2270
      break;
2271
#endif
2272
2273
#ifdef RS6000COFF_C
2274
#ifdef XCOFF64
2275
    case U64_TOCMAGIC:
2276
    case U803XTOCMAGIC:
2277
#else
2278
    case U802ROMAGIC:
2279
    case U802WRMAGIC:
2280
    case U802TOCMAGIC:
2281
#endif
2282
      {
2283
  int cputype;
2284
2285
  if (xcoff_data (abfd)->cputype != -1)
2286
    cputype = xcoff_data (abfd)->cputype & 0xff;
2287
  else
2288
    {
2289
      /* We did not get a value from the a.out header.  If the
2290
         file has not been stripped, we may be able to get the
2291
         architecture information from the first symbol, if it
2292
         is a .file symbol.  */
2293
      if (obj_raw_syment_count (abfd) == 0)
2294
        cputype = 0;
2295
      else
2296
        {
2297
    bfd_byte *buf;
2298
    struct internal_syment sym;
2299
    bfd_size_type amt = bfd_coff_symesz (abfd);
2300
2301
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2302
      return false;
2303
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2304
    if (buf == NULL)
2305
      return false;
2306
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2307
    if (sym.n_sclass == C_FILE)
2308
      cputype = sym.n_type & 0xff;
2309
    else
2310
      cputype = 0;
2311
    free (buf);
2312
        }
2313
    }
2314
2315
  /* FIXME: We don't handle all cases here.  */
2316
  switch (cputype)
2317
    {
2318
    default:
2319
    case 0:
2320
      arch = bfd_xcoff_architecture (abfd);
2321
      machine = bfd_xcoff_machine (abfd);
2322
      break;
2323
2324
    case 1:
2325
      arch = bfd_arch_powerpc;
2326
      machine = bfd_mach_ppc_601;
2327
      break;
2328
    case 2: /* 64 bit PowerPC */
2329
      arch = bfd_arch_powerpc;
2330
      machine = bfd_mach_ppc_620;
2331
      break;
2332
    case 3:
2333
      arch = bfd_arch_powerpc;
2334
      machine = bfd_mach_ppc;
2335
      break;
2336
    case 4:
2337
      arch = bfd_arch_rs6000;
2338
      machine = bfd_mach_rs6k;
2339
      break;
2340
    }
2341
      }
2342
      break;
2343
#endif
2344
2345
#ifdef SH_ARCH_MAGIC_BIG
2346
    case SH_ARCH_MAGIC_BIG:
2347
    case SH_ARCH_MAGIC_LITTLE:
2348
#ifdef COFF_WITH_PE
2349
    case SH_ARCH_MAGIC_WINCE:
2350
#endif
2351
      arch = bfd_arch_sh;
2352
      break;
2353
#endif
2354
2355
#ifdef MIPS_ARCH_MAGIC_WINCE
2356
    case MIPS_ARCH_MAGIC_WINCE:
2357
      arch = bfd_arch_mips;
2358
      break;
2359
#endif
2360
2361
#ifdef SPARCMAGIC
2362
    case SPARCMAGIC:
2363
#ifdef LYNXCOFFMAGIC
2364
    case LYNXCOFFMAGIC:
2365
#endif
2366
      arch = bfd_arch_sparc;
2367
      break;
2368
#endif
2369
2370
#ifdef TIC30MAGIC
2371
    case TIC30MAGIC:
2372
      arch = bfd_arch_tic30;
2373
      break;
2374
#endif
2375
2376
0
#ifdef TICOFF0MAGIC
2377
0
#ifdef TICOFF_TARGET_ARCH
2378
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2379
104k
    case TICOFF0MAGIC:
2380
104k
      arch = TICOFF_TARGET_ARCH;
2381
104k
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2382
104k
      break;
2383
0
#endif
2384
0
#endif
2385
2386
0
#ifdef TICOFF1MAGIC
2387
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2388
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2389
4.97k
    case TICOFF1MAGIC:
2390
5.68k
    case TICOFF2MAGIC:
2391
5.68k
      switch (internal_f->f_target_id)
2392
5.68k
  {
2393
0
#ifdef TI_TARGET_ID
2394
5.68k
  case TI_TARGET_ID:
2395
5.68k
    arch = TICOFF_TARGET_ARCH;
2396
5.68k
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2397
5.68k
    break;
2398
0
#endif
2399
0
  default:
2400
0
    arch = bfd_arch_obscure;
2401
0
    _bfd_error_handler
2402
0
      (_("unrecognized TI COFF target id '0x%x'"),
2403
0
       internal_f->f_target_id);
2404
0
    break;
2405
5.68k
  }
2406
5.68k
      break;
2407
5.68k
#endif
2408
2409
#ifdef MCOREMAGIC
2410
    case MCOREMAGIC:
2411
      arch = bfd_arch_mcore;
2412
      break;
2413
#endif
2414
2415
5.68k
    default:      /* Unreadable input file type.  */
2416
0
      arch = bfd_arch_obscure;
2417
0
      break;
2418
110k
    }
2419
2420
110k
  bfd_default_set_arch_mach (abfd, arch, machine);
2421
110k
  return true;
2422
110k
}
coff-z80.c:coff_set_arch_mach_hook
Line
Count
Source
2154
46.4k
{
2155
46.4k
  unsigned long machine;
2156
46.4k
  enum bfd_architecture arch;
2157
46.4k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2158
2159
  /* Zero selects the default machine for an arch.  */
2160
46.4k
  machine = 0;
2161
46.4k
  switch (internal_f->f_magic)
2162
46.4k
    {
2163
#ifdef I386MAGIC
2164
    case I386MAGIC:
2165
    case I386PTXMAGIC:
2166
    case I386AIXMAGIC:    /* Danbury PS/2 AIX C Compiler.  */
2167
    case LYNXCOFFMAGIC:
2168
    case I386_APPLE_MAGIC:
2169
    case I386_FREEBSD_MAGIC:
2170
    case I386_LINUX_MAGIC:
2171
    case I386_NETBSD_MAGIC:
2172
      arch = bfd_arch_i386;
2173
      break;
2174
#endif
2175
#ifdef AMD64MAGIC
2176
    case AMD64MAGIC:
2177
    case AMD64_APPLE_MAGIC:
2178
    case AMD64_FREEBSD_MAGIC:
2179
    case AMD64_LINUX_MAGIC:
2180
    case AMD64_NETBSD_MAGIC:
2181
      arch = bfd_arch_i386;
2182
      machine = bfd_mach_x86_64;
2183
      break;
2184
#endif
2185
#ifdef IA64MAGIC
2186
    case IA64MAGIC:
2187
      arch = bfd_arch_ia64;
2188
      break;
2189
#endif
2190
#ifdef ARMMAGIC
2191
    case ARMMAGIC:
2192
    case ARMPEMAGIC:
2193
    case THUMBPEMAGIC:
2194
      arch = bfd_arch_arm;
2195
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2196
      if (machine == bfd_mach_arm_unknown)
2197
  {
2198
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2199
      {
2200
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2201
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2202
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2203
      default:
2204
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2205
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2206
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2207
        /* The COFF header does not have enough bits available
2208
     to cover all the different ARM architectures.  So
2209
     we interpret F_ARM_5, the highest flag value to mean
2210
     "the highest ARM architecture known to BFD" which is
2211
     currently the XScale.  */
2212
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2213
      }
2214
  }
2215
      break;
2216
#endif
2217
#ifdef AARCH64MAGIC
2218
    case AARCH64MAGIC:
2219
      arch = bfd_arch_aarch64;
2220
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2221
      break;
2222
#endif
2223
#ifdef LOONGARCH64MAGIC
2224
    case LOONGARCH64MAGIC:
2225
      arch = bfd_arch_loongarch;
2226
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2227
      break;
2228
#endif
2229
#ifdef RISCV64MAGIC
2230
    case RISCV64MAGIC:
2231
      arch = bfd_arch_riscv;
2232
      machine = bfd_mach_riscv64;
2233
      break;
2234
#endif
2235
0
#ifdef Z80MAGIC
2236
46.4k
    case Z80MAGIC:
2237
46.4k
      arch = bfd_arch_z80;
2238
46.4k
      switch (internal_f->f_flags & F_MACHMASK)
2239
46.4k
  {
2240
3.41k
  case bfd_mach_z80strict << 12:
2241
8.49k
  case bfd_mach_z80 << 12:
2242
14.0k
  case bfd_mach_z80n << 12:
2243
20.0k
  case bfd_mach_z80full << 12:
2244
25.5k
  case bfd_mach_r800 << 12:
2245
29.6k
  case bfd_mach_gbz80 << 12:
2246
35.1k
  case bfd_mach_z180 << 12:
2247
41.9k
  case bfd_mach_ez80_z80 << 12:
2248
45.9k
  case bfd_mach_ez80_adl << 12:
2249
45.9k
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2250
45.9k
    break;
2251
518
  default:
2252
518
    return false;
2253
46.4k
  }
2254
45.9k
      break;
2255
45.9k
#endif
2256
#ifdef Z8KMAGIC
2257
    case Z8KMAGIC:
2258
      arch = bfd_arch_z8k;
2259
      switch (internal_f->f_flags & F_MACHMASK)
2260
  {
2261
  case F_Z8001:
2262
    machine = bfd_mach_z8001;
2263
    break;
2264
  case F_Z8002:
2265
    machine = bfd_mach_z8002;
2266
    break;
2267
  default:
2268
    return false;
2269
  }
2270
      break;
2271
#endif
2272
2273
#ifdef RS6000COFF_C
2274
#ifdef XCOFF64
2275
    case U64_TOCMAGIC:
2276
    case U803XTOCMAGIC:
2277
#else
2278
    case U802ROMAGIC:
2279
    case U802WRMAGIC:
2280
    case U802TOCMAGIC:
2281
#endif
2282
      {
2283
  int cputype;
2284
2285
  if (xcoff_data (abfd)->cputype != -1)
2286
    cputype = xcoff_data (abfd)->cputype & 0xff;
2287
  else
2288
    {
2289
      /* We did not get a value from the a.out header.  If the
2290
         file has not been stripped, we may be able to get the
2291
         architecture information from the first symbol, if it
2292
         is a .file symbol.  */
2293
      if (obj_raw_syment_count (abfd) == 0)
2294
        cputype = 0;
2295
      else
2296
        {
2297
    bfd_byte *buf;
2298
    struct internal_syment sym;
2299
    bfd_size_type amt = bfd_coff_symesz (abfd);
2300
2301
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2302
      return false;
2303
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2304
    if (buf == NULL)
2305
      return false;
2306
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2307
    if (sym.n_sclass == C_FILE)
2308
      cputype = sym.n_type & 0xff;
2309
    else
2310
      cputype = 0;
2311
    free (buf);
2312
        }
2313
    }
2314
2315
  /* FIXME: We don't handle all cases here.  */
2316
  switch (cputype)
2317
    {
2318
    default:
2319
    case 0:
2320
      arch = bfd_xcoff_architecture (abfd);
2321
      machine = bfd_xcoff_machine (abfd);
2322
      break;
2323
2324
    case 1:
2325
      arch = bfd_arch_powerpc;
2326
      machine = bfd_mach_ppc_601;
2327
      break;
2328
    case 2: /* 64 bit PowerPC */
2329
      arch = bfd_arch_powerpc;
2330
      machine = bfd_mach_ppc_620;
2331
      break;
2332
    case 3:
2333
      arch = bfd_arch_powerpc;
2334
      machine = bfd_mach_ppc;
2335
      break;
2336
    case 4:
2337
      arch = bfd_arch_rs6000;
2338
      machine = bfd_mach_rs6k;
2339
      break;
2340
    }
2341
      }
2342
      break;
2343
#endif
2344
2345
#ifdef SH_ARCH_MAGIC_BIG
2346
    case SH_ARCH_MAGIC_BIG:
2347
    case SH_ARCH_MAGIC_LITTLE:
2348
#ifdef COFF_WITH_PE
2349
    case SH_ARCH_MAGIC_WINCE:
2350
#endif
2351
      arch = bfd_arch_sh;
2352
      break;
2353
#endif
2354
2355
#ifdef MIPS_ARCH_MAGIC_WINCE
2356
    case MIPS_ARCH_MAGIC_WINCE:
2357
      arch = bfd_arch_mips;
2358
      break;
2359
#endif
2360
2361
#ifdef SPARCMAGIC
2362
    case SPARCMAGIC:
2363
#ifdef LYNXCOFFMAGIC
2364
    case LYNXCOFFMAGIC:
2365
#endif
2366
      arch = bfd_arch_sparc;
2367
      break;
2368
#endif
2369
2370
#ifdef TIC30MAGIC
2371
    case TIC30MAGIC:
2372
      arch = bfd_arch_tic30;
2373
      break;
2374
#endif
2375
2376
#ifdef TICOFF0MAGIC
2377
#ifdef TICOFF_TARGET_ARCH
2378
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2379
    case TICOFF0MAGIC:
2380
      arch = TICOFF_TARGET_ARCH;
2381
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2382
      break;
2383
#endif
2384
#endif
2385
2386
#ifdef TICOFF1MAGIC
2387
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2388
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2389
    case TICOFF1MAGIC:
2390
    case TICOFF2MAGIC:
2391
      switch (internal_f->f_target_id)
2392
  {
2393
#ifdef TI_TARGET_ID
2394
  case TI_TARGET_ID:
2395
    arch = TICOFF_TARGET_ARCH;
2396
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2397
    break;
2398
#endif
2399
  default:
2400
    arch = bfd_arch_obscure;
2401
    _bfd_error_handler
2402
      (_("unrecognized TI COFF target id '0x%x'"),
2403
       internal_f->f_target_id);
2404
    break;
2405
  }
2406
      break;
2407
#endif
2408
2409
#ifdef MCOREMAGIC
2410
    case MCOREMAGIC:
2411
      arch = bfd_arch_mcore;
2412
      break;
2413
#endif
2414
2415
45.9k
    default:      /* Unreadable input file type.  */
2416
0
      arch = bfd_arch_obscure;
2417
0
      break;
2418
46.4k
    }
2419
2420
45.9k
  bfd_default_set_arch_mach (abfd, arch, machine);
2421
45.9k
  return true;
2422
46.4k
}
coff-z8k.c:coff_set_arch_mach_hook
Line
Count
Source
2154
50.5k
{
2155
50.5k
  unsigned long machine;
2156
50.5k
  enum bfd_architecture arch;
2157
50.5k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2158
2159
  /* Zero selects the default machine for an arch.  */
2160
50.5k
  machine = 0;
2161
50.5k
  switch (internal_f->f_magic)
2162
50.5k
    {
2163
#ifdef I386MAGIC
2164
    case I386MAGIC:
2165
    case I386PTXMAGIC:
2166
    case I386AIXMAGIC:    /* Danbury PS/2 AIX C Compiler.  */
2167
    case LYNXCOFFMAGIC:
2168
    case I386_APPLE_MAGIC:
2169
    case I386_FREEBSD_MAGIC:
2170
    case I386_LINUX_MAGIC:
2171
    case I386_NETBSD_MAGIC:
2172
      arch = bfd_arch_i386;
2173
      break;
2174
#endif
2175
#ifdef AMD64MAGIC
2176
    case AMD64MAGIC:
2177
    case AMD64_APPLE_MAGIC:
2178
    case AMD64_FREEBSD_MAGIC:
2179
    case AMD64_LINUX_MAGIC:
2180
    case AMD64_NETBSD_MAGIC:
2181
      arch = bfd_arch_i386;
2182
      machine = bfd_mach_x86_64;
2183
      break;
2184
#endif
2185
#ifdef IA64MAGIC
2186
    case IA64MAGIC:
2187
      arch = bfd_arch_ia64;
2188
      break;
2189
#endif
2190
#ifdef ARMMAGIC
2191
    case ARMMAGIC:
2192
    case ARMPEMAGIC:
2193
    case THUMBPEMAGIC:
2194
      arch = bfd_arch_arm;
2195
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2196
      if (machine == bfd_mach_arm_unknown)
2197
  {
2198
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2199
      {
2200
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2201
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2202
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2203
      default:
2204
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2205
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2206
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2207
        /* The COFF header does not have enough bits available
2208
     to cover all the different ARM architectures.  So
2209
     we interpret F_ARM_5, the highest flag value to mean
2210
     "the highest ARM architecture known to BFD" which is
2211
     currently the XScale.  */
2212
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2213
      }
2214
  }
2215
      break;
2216
#endif
2217
#ifdef AARCH64MAGIC
2218
    case AARCH64MAGIC:
2219
      arch = bfd_arch_aarch64;
2220
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2221
      break;
2222
#endif
2223
#ifdef LOONGARCH64MAGIC
2224
    case LOONGARCH64MAGIC:
2225
      arch = bfd_arch_loongarch;
2226
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2227
      break;
2228
#endif
2229
#ifdef RISCV64MAGIC
2230
    case RISCV64MAGIC:
2231
      arch = bfd_arch_riscv;
2232
      machine = bfd_mach_riscv64;
2233
      break;
2234
#endif
2235
#ifdef Z80MAGIC
2236
    case Z80MAGIC:
2237
      arch = bfd_arch_z80;
2238
      switch (internal_f->f_flags & F_MACHMASK)
2239
  {
2240
  case bfd_mach_z80strict << 12:
2241
  case bfd_mach_z80 << 12:
2242
  case bfd_mach_z80n << 12:
2243
  case bfd_mach_z80full << 12:
2244
  case bfd_mach_r800 << 12:
2245
  case bfd_mach_gbz80 << 12:
2246
  case bfd_mach_z180 << 12:
2247
  case bfd_mach_ez80_z80 << 12:
2248
  case bfd_mach_ez80_adl << 12:
2249
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2250
    break;
2251
  default:
2252
    return false;
2253
  }
2254
      break;
2255
#endif
2256
0
#ifdef Z8KMAGIC
2257
50.5k
    case Z8KMAGIC:
2258
50.5k
      arch = bfd_arch_z8k;
2259
50.5k
      switch (internal_f->f_flags & F_MACHMASK)
2260
50.5k
  {
2261
19.4k
  case F_Z8001:
2262
19.4k
    machine = bfd_mach_z8001;
2263
19.4k
    break;
2264
30.5k
  case F_Z8002:
2265
30.5k
    machine = bfd_mach_z8002;
2266
30.5k
    break;
2267
527
  default:
2268
527
    return false;
2269
50.5k
  }
2270
49.9k
      break;
2271
49.9k
#endif
2272
2273
#ifdef RS6000COFF_C
2274
#ifdef XCOFF64
2275
    case U64_TOCMAGIC:
2276
    case U803XTOCMAGIC:
2277
#else
2278
    case U802ROMAGIC:
2279
    case U802WRMAGIC:
2280
    case U802TOCMAGIC:
2281
#endif
2282
      {
2283
  int cputype;
2284
2285
  if (xcoff_data (abfd)->cputype != -1)
2286
    cputype = xcoff_data (abfd)->cputype & 0xff;
2287
  else
2288
    {
2289
      /* We did not get a value from the a.out header.  If the
2290
         file has not been stripped, we may be able to get the
2291
         architecture information from the first symbol, if it
2292
         is a .file symbol.  */
2293
      if (obj_raw_syment_count (abfd) == 0)
2294
        cputype = 0;
2295
      else
2296
        {
2297
    bfd_byte *buf;
2298
    struct internal_syment sym;
2299
    bfd_size_type amt = bfd_coff_symesz (abfd);
2300
2301
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2302
      return false;
2303
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2304
    if (buf == NULL)
2305
      return false;
2306
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2307
    if (sym.n_sclass == C_FILE)
2308
      cputype = sym.n_type & 0xff;
2309
    else
2310
      cputype = 0;
2311
    free (buf);
2312
        }
2313
    }
2314
2315
  /* FIXME: We don't handle all cases here.  */
2316
  switch (cputype)
2317
    {
2318
    default:
2319
    case 0:
2320
      arch = bfd_xcoff_architecture (abfd);
2321
      machine = bfd_xcoff_machine (abfd);
2322
      break;
2323
2324
    case 1:
2325
      arch = bfd_arch_powerpc;
2326
      machine = bfd_mach_ppc_601;
2327
      break;
2328
    case 2: /* 64 bit PowerPC */
2329
      arch = bfd_arch_powerpc;
2330
      machine = bfd_mach_ppc_620;
2331
      break;
2332
    case 3:
2333
      arch = bfd_arch_powerpc;
2334
      machine = bfd_mach_ppc;
2335
      break;
2336
    case 4:
2337
      arch = bfd_arch_rs6000;
2338
      machine = bfd_mach_rs6k;
2339
      break;
2340
    }
2341
      }
2342
      break;
2343
#endif
2344
2345
#ifdef SH_ARCH_MAGIC_BIG
2346
    case SH_ARCH_MAGIC_BIG:
2347
    case SH_ARCH_MAGIC_LITTLE:
2348
#ifdef COFF_WITH_PE
2349
    case SH_ARCH_MAGIC_WINCE:
2350
#endif
2351
      arch = bfd_arch_sh;
2352
      break;
2353
#endif
2354
2355
#ifdef MIPS_ARCH_MAGIC_WINCE
2356
    case MIPS_ARCH_MAGIC_WINCE:
2357
      arch = bfd_arch_mips;
2358
      break;
2359
#endif
2360
2361
#ifdef SPARCMAGIC
2362
    case SPARCMAGIC:
2363
#ifdef LYNXCOFFMAGIC
2364
    case LYNXCOFFMAGIC:
2365
#endif
2366
      arch = bfd_arch_sparc;
2367
      break;
2368
#endif
2369
2370
#ifdef TIC30MAGIC
2371
    case TIC30MAGIC:
2372
      arch = bfd_arch_tic30;
2373
      break;
2374
#endif
2375
2376
#ifdef TICOFF0MAGIC
2377
#ifdef TICOFF_TARGET_ARCH
2378
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2379
    case TICOFF0MAGIC:
2380
      arch = TICOFF_TARGET_ARCH;
2381
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2382
      break;
2383
#endif
2384
#endif
2385
2386
#ifdef TICOFF1MAGIC
2387
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2388
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2389
    case TICOFF1MAGIC:
2390
    case TICOFF2MAGIC:
2391
      switch (internal_f->f_target_id)
2392
  {
2393
#ifdef TI_TARGET_ID
2394
  case TI_TARGET_ID:
2395
    arch = TICOFF_TARGET_ARCH;
2396
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2397
    break;
2398
#endif
2399
  default:
2400
    arch = bfd_arch_obscure;
2401
    _bfd_error_handler
2402
      (_("unrecognized TI COFF target id '0x%x'"),
2403
       internal_f->f_target_id);
2404
    break;
2405
  }
2406
      break;
2407
#endif
2408
2409
#ifdef MCOREMAGIC
2410
    case MCOREMAGIC:
2411
      arch = bfd_arch_mcore;
2412
      break;
2413
#endif
2414
2415
49.9k
    default:      /* Unreadable input file type.  */
2416
0
      arch = bfd_arch_obscure;
2417
0
      break;
2418
50.5k
    }
2419
2420
49.9k
  bfd_default_set_arch_mach (abfd, arch, machine);
2421
49.9k
  return true;
2422
50.5k
}
pe-arm-wince.c:coff_set_arch_mach_hook
Line
Count
Source
2154
33.9k
{
2155
33.9k
  unsigned long machine;
2156
33.9k
  enum bfd_architecture arch;
2157
33.9k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2158
2159
  /* Zero selects the default machine for an arch.  */
2160
33.9k
  machine = 0;
2161
33.9k
  switch (internal_f->f_magic)
2162
33.9k
    {
2163
#ifdef I386MAGIC
2164
    case I386MAGIC:
2165
    case I386PTXMAGIC:
2166
    case I386AIXMAGIC:    /* Danbury PS/2 AIX C Compiler.  */
2167
    case LYNXCOFFMAGIC:
2168
    case I386_APPLE_MAGIC:
2169
    case I386_FREEBSD_MAGIC:
2170
    case I386_LINUX_MAGIC:
2171
    case I386_NETBSD_MAGIC:
2172
      arch = bfd_arch_i386;
2173
      break;
2174
#endif
2175
#ifdef AMD64MAGIC
2176
    case AMD64MAGIC:
2177
    case AMD64_APPLE_MAGIC:
2178
    case AMD64_FREEBSD_MAGIC:
2179
    case AMD64_LINUX_MAGIC:
2180
    case AMD64_NETBSD_MAGIC:
2181
      arch = bfd_arch_i386;
2182
      machine = bfd_mach_x86_64;
2183
      break;
2184
#endif
2185
#ifdef IA64MAGIC
2186
    case IA64MAGIC:
2187
      arch = bfd_arch_ia64;
2188
      break;
2189
#endif
2190
0
#ifdef ARMMAGIC
2191
24.9k
    case ARMMAGIC:
2192
27.1k
    case ARMPEMAGIC:
2193
31.8k
    case THUMBPEMAGIC:
2194
31.8k
      arch = bfd_arch_arm;
2195
31.8k
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2196
31.8k
      if (machine == bfd_mach_arm_unknown)
2197
31.8k
  {
2198
31.8k
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2199
31.8k
      {
2200
5.26k
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2201
5.44k
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2202
1.92k
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2203
12.6k
      default:
2204
12.9k
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2205
1.35k
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2206
2.00k
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2207
        /* The COFF header does not have enough bits available
2208
     to cover all the different ARM architectures.  So
2209
     we interpret F_ARM_5, the highest flag value to mean
2210
     "the highest ARM architecture known to BFD" which is
2211
     currently the XScale.  */
2212
2.87k
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2213
31.8k
      }
2214
31.8k
  }
2215
31.8k
      break;
2216
31.8k
#endif
2217
#ifdef AARCH64MAGIC
2218
    case AARCH64MAGIC:
2219
      arch = bfd_arch_aarch64;
2220
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2221
      break;
2222
#endif
2223
#ifdef LOONGARCH64MAGIC
2224
    case LOONGARCH64MAGIC:
2225
      arch = bfd_arch_loongarch;
2226
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2227
      break;
2228
#endif
2229
#ifdef RISCV64MAGIC
2230
    case RISCV64MAGIC:
2231
      arch = bfd_arch_riscv;
2232
      machine = bfd_mach_riscv64;
2233
      break;
2234
#endif
2235
#ifdef Z80MAGIC
2236
    case Z80MAGIC:
2237
      arch = bfd_arch_z80;
2238
      switch (internal_f->f_flags & F_MACHMASK)
2239
  {
2240
  case bfd_mach_z80strict << 12:
2241
  case bfd_mach_z80 << 12:
2242
  case bfd_mach_z80n << 12:
2243
  case bfd_mach_z80full << 12:
2244
  case bfd_mach_r800 << 12:
2245
  case bfd_mach_gbz80 << 12:
2246
  case bfd_mach_z180 << 12:
2247
  case bfd_mach_ez80_z80 << 12:
2248
  case bfd_mach_ez80_adl << 12:
2249
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2250
    break;
2251
  default:
2252
    return false;
2253
  }
2254
      break;
2255
#endif
2256
#ifdef Z8KMAGIC
2257
    case Z8KMAGIC:
2258
      arch = bfd_arch_z8k;
2259
      switch (internal_f->f_flags & F_MACHMASK)
2260
  {
2261
  case F_Z8001:
2262
    machine = bfd_mach_z8001;
2263
    break;
2264
  case F_Z8002:
2265
    machine = bfd_mach_z8002;
2266
    break;
2267
  default:
2268
    return false;
2269
  }
2270
      break;
2271
#endif
2272
2273
#ifdef RS6000COFF_C
2274
#ifdef XCOFF64
2275
    case U64_TOCMAGIC:
2276
    case U803XTOCMAGIC:
2277
#else
2278
    case U802ROMAGIC:
2279
    case U802WRMAGIC:
2280
    case U802TOCMAGIC:
2281
#endif
2282
      {
2283
  int cputype;
2284
2285
  if (xcoff_data (abfd)->cputype != -1)
2286
    cputype = xcoff_data (abfd)->cputype & 0xff;
2287
  else
2288
    {
2289
      /* We did not get a value from the a.out header.  If the
2290
         file has not been stripped, we may be able to get the
2291
         architecture information from the first symbol, if it
2292
         is a .file symbol.  */
2293
      if (obj_raw_syment_count (abfd) == 0)
2294
        cputype = 0;
2295
      else
2296
        {
2297
    bfd_byte *buf;
2298
    struct internal_syment sym;
2299
    bfd_size_type amt = bfd_coff_symesz (abfd);
2300
2301
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2302
      return false;
2303
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2304
    if (buf == NULL)
2305
      return false;
2306
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2307
    if (sym.n_sclass == C_FILE)
2308
      cputype = sym.n_type & 0xff;
2309
    else
2310
      cputype = 0;
2311
    free (buf);
2312
        }
2313
    }
2314
2315
  /* FIXME: We don't handle all cases here.  */
2316
  switch (cputype)
2317
    {
2318
    default:
2319
    case 0:
2320
      arch = bfd_xcoff_architecture (abfd);
2321
      machine = bfd_xcoff_machine (abfd);
2322
      break;
2323
2324
    case 1:
2325
      arch = bfd_arch_powerpc;
2326
      machine = bfd_mach_ppc_601;
2327
      break;
2328
    case 2: /* 64 bit PowerPC */
2329
      arch = bfd_arch_powerpc;
2330
      machine = bfd_mach_ppc_620;
2331
      break;
2332
    case 3:
2333
      arch = bfd_arch_powerpc;
2334
      machine = bfd_mach_ppc;
2335
      break;
2336
    case 4:
2337
      arch = bfd_arch_rs6000;
2338
      machine = bfd_mach_rs6k;
2339
      break;
2340
    }
2341
      }
2342
      break;
2343
#endif
2344
2345
#ifdef SH_ARCH_MAGIC_BIG
2346
    case SH_ARCH_MAGIC_BIG:
2347
    case SH_ARCH_MAGIC_LITTLE:
2348
#ifdef COFF_WITH_PE
2349
    case SH_ARCH_MAGIC_WINCE:
2350
#endif
2351
      arch = bfd_arch_sh;
2352
      break;
2353
#endif
2354
2355
#ifdef MIPS_ARCH_MAGIC_WINCE
2356
    case MIPS_ARCH_MAGIC_WINCE:
2357
      arch = bfd_arch_mips;
2358
      break;
2359
#endif
2360
2361
#ifdef SPARCMAGIC
2362
    case SPARCMAGIC:
2363
#ifdef LYNXCOFFMAGIC
2364
    case LYNXCOFFMAGIC:
2365
#endif
2366
      arch = bfd_arch_sparc;
2367
      break;
2368
#endif
2369
2370
#ifdef TIC30MAGIC
2371
    case TIC30MAGIC:
2372
      arch = bfd_arch_tic30;
2373
      break;
2374
#endif
2375
2376
#ifdef TICOFF0MAGIC
2377
#ifdef TICOFF_TARGET_ARCH
2378
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2379
    case TICOFF0MAGIC:
2380
      arch = TICOFF_TARGET_ARCH;
2381
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2382
      break;
2383
#endif
2384
#endif
2385
2386
#ifdef TICOFF1MAGIC
2387
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2388
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2389
    case TICOFF1MAGIC:
2390
    case TICOFF2MAGIC:
2391
      switch (internal_f->f_target_id)
2392
  {
2393
#ifdef TI_TARGET_ID
2394
  case TI_TARGET_ID:
2395
    arch = TICOFF_TARGET_ARCH;
2396
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2397
    break;
2398
#endif
2399
  default:
2400
    arch = bfd_arch_obscure;
2401
    _bfd_error_handler
2402
      (_("unrecognized TI COFF target id '0x%x'"),
2403
       internal_f->f_target_id);
2404
    break;
2405
  }
2406
      break;
2407
#endif
2408
2409
#ifdef MCOREMAGIC
2410
    case MCOREMAGIC:
2411
      arch = bfd_arch_mcore;
2412
      break;
2413
#endif
2414
2415
31.8k
    default:      /* Unreadable input file type.  */
2416
2.12k
      arch = bfd_arch_obscure;
2417
2.12k
      break;
2418
33.9k
    }
2419
2420
33.9k
  bfd_default_set_arch_mach (abfd, arch, machine);
2421
33.9k
  return true;
2422
33.9k
}
pe-arm.c:coff_set_arch_mach_hook
Line
Count
Source
2154
33.9k
{
2155
33.9k
  unsigned long machine;
2156
33.9k
  enum bfd_architecture arch;
2157
33.9k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2158
2159
  /* Zero selects the default machine for an arch.  */
2160
33.9k
  machine = 0;
2161
33.9k
  switch (internal_f->f_magic)
2162
33.9k
    {
2163
#ifdef I386MAGIC
2164
    case I386MAGIC:
2165
    case I386PTXMAGIC:
2166
    case I386AIXMAGIC:    /* Danbury PS/2 AIX C Compiler.  */
2167
    case LYNXCOFFMAGIC:
2168
    case I386_APPLE_MAGIC:
2169
    case I386_FREEBSD_MAGIC:
2170
    case I386_LINUX_MAGIC:
2171
    case I386_NETBSD_MAGIC:
2172
      arch = bfd_arch_i386;
2173
      break;
2174
#endif
2175
#ifdef AMD64MAGIC
2176
    case AMD64MAGIC:
2177
    case AMD64_APPLE_MAGIC:
2178
    case AMD64_FREEBSD_MAGIC:
2179
    case AMD64_LINUX_MAGIC:
2180
    case AMD64_NETBSD_MAGIC:
2181
      arch = bfd_arch_i386;
2182
      machine = bfd_mach_x86_64;
2183
      break;
2184
#endif
2185
#ifdef IA64MAGIC
2186
    case IA64MAGIC:
2187
      arch = bfd_arch_ia64;
2188
      break;
2189
#endif
2190
0
#ifdef ARMMAGIC
2191
24.9k
    case ARMMAGIC:
2192
27.1k
    case ARMPEMAGIC:
2193
31.8k
    case THUMBPEMAGIC:
2194
31.8k
      arch = bfd_arch_arm;
2195
31.8k
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2196
31.8k
      if (machine == bfd_mach_arm_unknown)
2197
31.8k
  {
2198
31.8k
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2199
31.8k
      {
2200
5.26k
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2201
5.44k
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2202
1.92k
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2203
12.6k
      default:
2204
12.9k
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2205
1.35k
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2206
2.00k
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2207
        /* The COFF header does not have enough bits available
2208
     to cover all the different ARM architectures.  So
2209
     we interpret F_ARM_5, the highest flag value to mean
2210
     "the highest ARM architecture known to BFD" which is
2211
     currently the XScale.  */
2212
2.87k
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2213
31.8k
      }
2214
31.8k
  }
2215
31.8k
      break;
2216
31.8k
#endif
2217
#ifdef AARCH64MAGIC
2218
    case AARCH64MAGIC:
2219
      arch = bfd_arch_aarch64;
2220
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2221
      break;
2222
#endif
2223
#ifdef LOONGARCH64MAGIC
2224
    case LOONGARCH64MAGIC:
2225
      arch = bfd_arch_loongarch;
2226
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2227
      break;
2228
#endif
2229
#ifdef RISCV64MAGIC
2230
    case RISCV64MAGIC:
2231
      arch = bfd_arch_riscv;
2232
      machine = bfd_mach_riscv64;
2233
      break;
2234
#endif
2235
#ifdef Z80MAGIC
2236
    case Z80MAGIC:
2237
      arch = bfd_arch_z80;
2238
      switch (internal_f->f_flags & F_MACHMASK)
2239
  {
2240
  case bfd_mach_z80strict << 12:
2241
  case bfd_mach_z80 << 12:
2242
  case bfd_mach_z80n << 12:
2243
  case bfd_mach_z80full << 12:
2244
  case bfd_mach_r800 << 12:
2245
  case bfd_mach_gbz80 << 12:
2246
  case bfd_mach_z180 << 12:
2247
  case bfd_mach_ez80_z80 << 12:
2248
  case bfd_mach_ez80_adl << 12:
2249
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2250
    break;
2251
  default:
2252
    return false;
2253
  }
2254
      break;
2255
#endif
2256
#ifdef Z8KMAGIC
2257
    case Z8KMAGIC:
2258
      arch = bfd_arch_z8k;
2259
      switch (internal_f->f_flags & F_MACHMASK)
2260
  {
2261
  case F_Z8001:
2262
    machine = bfd_mach_z8001;
2263
    break;
2264
  case F_Z8002:
2265
    machine = bfd_mach_z8002;
2266
    break;
2267
  default:
2268
    return false;
2269
  }
2270
      break;
2271
#endif
2272
2273
#ifdef RS6000COFF_C
2274
#ifdef XCOFF64
2275
    case U64_TOCMAGIC:
2276
    case U803XTOCMAGIC:
2277
#else
2278
    case U802ROMAGIC:
2279
    case U802WRMAGIC:
2280
    case U802TOCMAGIC:
2281
#endif
2282
      {
2283
  int cputype;
2284
2285
  if (xcoff_data (abfd)->cputype != -1)
2286
    cputype = xcoff_data (abfd)->cputype & 0xff;
2287
  else
2288
    {
2289
      /* We did not get a value from the a.out header.  If the
2290
         file has not been stripped, we may be able to get the
2291
         architecture information from the first symbol, if it
2292
         is a .file symbol.  */
2293
      if (obj_raw_syment_count (abfd) == 0)
2294
        cputype = 0;
2295
      else
2296
        {
2297
    bfd_byte *buf;
2298
    struct internal_syment sym;
2299
    bfd_size_type amt = bfd_coff_symesz (abfd);
2300
2301
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2302
      return false;
2303
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2304
    if (buf == NULL)
2305
      return false;
2306
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2307
    if (sym.n_sclass == C_FILE)
2308
      cputype = sym.n_type & 0xff;
2309
    else
2310
      cputype = 0;
2311
    free (buf);
2312
        }
2313
    }
2314
2315
  /* FIXME: We don't handle all cases here.  */
2316
  switch (cputype)
2317
    {
2318
    default:
2319
    case 0:
2320
      arch = bfd_xcoff_architecture (abfd);
2321
      machine = bfd_xcoff_machine (abfd);
2322
      break;
2323
2324
    case 1:
2325
      arch = bfd_arch_powerpc;
2326
      machine = bfd_mach_ppc_601;
2327
      break;
2328
    case 2: /* 64 bit PowerPC */
2329
      arch = bfd_arch_powerpc;
2330
      machine = bfd_mach_ppc_620;
2331
      break;
2332
    case 3:
2333
      arch = bfd_arch_powerpc;
2334
      machine = bfd_mach_ppc;
2335
      break;
2336
    case 4:
2337
      arch = bfd_arch_rs6000;
2338
      machine = bfd_mach_rs6k;
2339
      break;
2340
    }
2341
      }
2342
      break;
2343
#endif
2344
2345
#ifdef SH_ARCH_MAGIC_BIG
2346
    case SH_ARCH_MAGIC_BIG:
2347
    case SH_ARCH_MAGIC_LITTLE:
2348
#ifdef COFF_WITH_PE
2349
    case SH_ARCH_MAGIC_WINCE:
2350
#endif
2351
      arch = bfd_arch_sh;
2352
      break;
2353
#endif
2354
2355
#ifdef MIPS_ARCH_MAGIC_WINCE
2356
    case MIPS_ARCH_MAGIC_WINCE:
2357
      arch = bfd_arch_mips;
2358
      break;
2359
#endif
2360
2361
#ifdef SPARCMAGIC
2362
    case SPARCMAGIC:
2363
#ifdef LYNXCOFFMAGIC
2364
    case LYNXCOFFMAGIC:
2365
#endif
2366
      arch = bfd_arch_sparc;
2367
      break;
2368
#endif
2369
2370
#ifdef TIC30MAGIC
2371
    case TIC30MAGIC:
2372
      arch = bfd_arch_tic30;
2373
      break;
2374
#endif
2375
2376
#ifdef TICOFF0MAGIC
2377
#ifdef TICOFF_TARGET_ARCH
2378
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2379
    case TICOFF0MAGIC:
2380
      arch = TICOFF_TARGET_ARCH;
2381
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2382
      break;
2383
#endif
2384
#endif
2385
2386
#ifdef TICOFF1MAGIC
2387
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2388
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2389
    case TICOFF1MAGIC:
2390
    case TICOFF2MAGIC:
2391
      switch (internal_f->f_target_id)
2392
  {
2393
#ifdef TI_TARGET_ID
2394
  case TI_TARGET_ID:
2395
    arch = TICOFF_TARGET_ARCH;
2396
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2397
    break;
2398
#endif
2399
  default:
2400
    arch = bfd_arch_obscure;
2401
    _bfd_error_handler
2402
      (_("unrecognized TI COFF target id '0x%x'"),
2403
       internal_f->f_target_id);
2404
    break;
2405
  }
2406
      break;
2407
#endif
2408
2409
#ifdef MCOREMAGIC
2410
    case MCOREMAGIC:
2411
      arch = bfd_arch_mcore;
2412
      break;
2413
#endif
2414
2415
31.8k
    default:      /* Unreadable input file type.  */
2416
2.12k
      arch = bfd_arch_obscure;
2417
2.12k
      break;
2418
33.9k
    }
2419
2420
33.9k
  bfd_default_set_arch_mach (abfd, arch, machine);
2421
33.9k
  return true;
2422
33.9k
}
pe-i386.c:coff_set_arch_mach_hook
Line
Count
Source
2154
88.8k
{
2155
88.8k
  unsigned long machine;
2156
88.8k
  enum bfd_architecture arch;
2157
88.8k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2158
2159
  /* Zero selects the default machine for an arch.  */
2160
88.8k
  machine = 0;
2161
88.8k
  switch (internal_f->f_magic)
2162
88.8k
    {
2163
0
#ifdef I386MAGIC
2164
63.0k
    case I386MAGIC:
2165
67.1k
    case I386PTXMAGIC:
2166
73.4k
    case I386AIXMAGIC:   /* Danbury PS/2 AIX C Compiler.  */
2167
85.8k
    case LYNXCOFFMAGIC:
2168
87.8k
    case I386_APPLE_MAGIC:
2169
87.8k
    case I386_FREEBSD_MAGIC:
2170
87.9k
    case I386_LINUX_MAGIC:
2171
88.8k
    case I386_NETBSD_MAGIC:
2172
88.8k
      arch = bfd_arch_i386;
2173
88.8k
      break;
2174
0
#endif
2175
#ifdef AMD64MAGIC
2176
    case AMD64MAGIC:
2177
    case AMD64_APPLE_MAGIC:
2178
    case AMD64_FREEBSD_MAGIC:
2179
    case AMD64_LINUX_MAGIC:
2180
    case AMD64_NETBSD_MAGIC:
2181
      arch = bfd_arch_i386;
2182
      machine = bfd_mach_x86_64;
2183
      break;
2184
#endif
2185
#ifdef IA64MAGIC
2186
    case IA64MAGIC:
2187
      arch = bfd_arch_ia64;
2188
      break;
2189
#endif
2190
#ifdef ARMMAGIC
2191
    case ARMMAGIC:
2192
    case ARMPEMAGIC:
2193
    case THUMBPEMAGIC:
2194
      arch = bfd_arch_arm;
2195
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2196
      if (machine == bfd_mach_arm_unknown)
2197
  {
2198
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2199
      {
2200
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2201
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2202
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2203
      default:
2204
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2205
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2206
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2207
        /* The COFF header does not have enough bits available
2208
     to cover all the different ARM architectures.  So
2209
     we interpret F_ARM_5, the highest flag value to mean
2210
     "the highest ARM architecture known to BFD" which is
2211
     currently the XScale.  */
2212
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2213
      }
2214
  }
2215
      break;
2216
#endif
2217
#ifdef AARCH64MAGIC
2218
    case AARCH64MAGIC:
2219
      arch = bfd_arch_aarch64;
2220
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2221
      break;
2222
#endif
2223
#ifdef LOONGARCH64MAGIC
2224
    case LOONGARCH64MAGIC:
2225
      arch = bfd_arch_loongarch;
2226
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2227
      break;
2228
#endif
2229
#ifdef RISCV64MAGIC
2230
    case RISCV64MAGIC:
2231
      arch = bfd_arch_riscv;
2232
      machine = bfd_mach_riscv64;
2233
      break;
2234
#endif
2235
#ifdef Z80MAGIC
2236
    case Z80MAGIC:
2237
      arch = bfd_arch_z80;
2238
      switch (internal_f->f_flags & F_MACHMASK)
2239
  {
2240
  case bfd_mach_z80strict << 12:
2241
  case bfd_mach_z80 << 12:
2242
  case bfd_mach_z80n << 12:
2243
  case bfd_mach_z80full << 12:
2244
  case bfd_mach_r800 << 12:
2245
  case bfd_mach_gbz80 << 12:
2246
  case bfd_mach_z180 << 12:
2247
  case bfd_mach_ez80_z80 << 12:
2248
  case bfd_mach_ez80_adl << 12:
2249
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2250
    break;
2251
  default:
2252
    return false;
2253
  }
2254
      break;
2255
#endif
2256
#ifdef Z8KMAGIC
2257
    case Z8KMAGIC:
2258
      arch = bfd_arch_z8k;
2259
      switch (internal_f->f_flags & F_MACHMASK)
2260
  {
2261
  case F_Z8001:
2262
    machine = bfd_mach_z8001;
2263
    break;
2264
  case F_Z8002:
2265
    machine = bfd_mach_z8002;
2266
    break;
2267
  default:
2268
    return false;
2269
  }
2270
      break;
2271
#endif
2272
2273
#ifdef RS6000COFF_C
2274
#ifdef XCOFF64
2275
    case U64_TOCMAGIC:
2276
    case U803XTOCMAGIC:
2277
#else
2278
    case U802ROMAGIC:
2279
    case U802WRMAGIC:
2280
    case U802TOCMAGIC:
2281
#endif
2282
      {
2283
  int cputype;
2284
2285
  if (xcoff_data (abfd)->cputype != -1)
2286
    cputype = xcoff_data (abfd)->cputype & 0xff;
2287
  else
2288
    {
2289
      /* We did not get a value from the a.out header.  If the
2290
         file has not been stripped, we may be able to get the
2291
         architecture information from the first symbol, if it
2292
         is a .file symbol.  */
2293
      if (obj_raw_syment_count (abfd) == 0)
2294
        cputype = 0;
2295
      else
2296
        {
2297
    bfd_byte *buf;
2298
    struct internal_syment sym;
2299
    bfd_size_type amt = bfd_coff_symesz (abfd);
2300
2301
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2302
      return false;
2303
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2304
    if (buf == NULL)
2305
      return false;
2306
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2307
    if (sym.n_sclass == C_FILE)
2308
      cputype = sym.n_type & 0xff;
2309
    else
2310
      cputype = 0;
2311
    free (buf);
2312
        }
2313
    }
2314
2315
  /* FIXME: We don't handle all cases here.  */
2316
  switch (cputype)
2317
    {
2318
    default:
2319
    case 0:
2320
      arch = bfd_xcoff_architecture (abfd);
2321
      machine = bfd_xcoff_machine (abfd);
2322
      break;
2323
2324
    case 1:
2325
      arch = bfd_arch_powerpc;
2326
      machine = bfd_mach_ppc_601;
2327
      break;
2328
    case 2: /* 64 bit PowerPC */
2329
      arch = bfd_arch_powerpc;
2330
      machine = bfd_mach_ppc_620;
2331
      break;
2332
    case 3:
2333
      arch = bfd_arch_powerpc;
2334
      machine = bfd_mach_ppc;
2335
      break;
2336
    case 4:
2337
      arch = bfd_arch_rs6000;
2338
      machine = bfd_mach_rs6k;
2339
      break;
2340
    }
2341
      }
2342
      break;
2343
#endif
2344
2345
#ifdef SH_ARCH_MAGIC_BIG
2346
    case SH_ARCH_MAGIC_BIG:
2347
    case SH_ARCH_MAGIC_LITTLE:
2348
#ifdef COFF_WITH_PE
2349
    case SH_ARCH_MAGIC_WINCE:
2350
#endif
2351
      arch = bfd_arch_sh;
2352
      break;
2353
#endif
2354
2355
#ifdef MIPS_ARCH_MAGIC_WINCE
2356
    case MIPS_ARCH_MAGIC_WINCE:
2357
      arch = bfd_arch_mips;
2358
      break;
2359
#endif
2360
2361
#ifdef SPARCMAGIC
2362
    case SPARCMAGIC:
2363
#ifdef LYNXCOFFMAGIC
2364
    case LYNXCOFFMAGIC:
2365
#endif
2366
      arch = bfd_arch_sparc;
2367
      break;
2368
#endif
2369
2370
#ifdef TIC30MAGIC
2371
    case TIC30MAGIC:
2372
      arch = bfd_arch_tic30;
2373
      break;
2374
#endif
2375
2376
#ifdef TICOFF0MAGIC
2377
#ifdef TICOFF_TARGET_ARCH
2378
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2379
    case TICOFF0MAGIC:
2380
      arch = TICOFF_TARGET_ARCH;
2381
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2382
      break;
2383
#endif
2384
#endif
2385
2386
#ifdef TICOFF1MAGIC
2387
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2388
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2389
    case TICOFF1MAGIC:
2390
    case TICOFF2MAGIC:
2391
      switch (internal_f->f_target_id)
2392
  {
2393
#ifdef TI_TARGET_ID
2394
  case TI_TARGET_ID:
2395
    arch = TICOFF_TARGET_ARCH;
2396
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2397
    break;
2398
#endif
2399
  default:
2400
    arch = bfd_arch_obscure;
2401
    _bfd_error_handler
2402
      (_("unrecognized TI COFF target id '0x%x'"),
2403
       internal_f->f_target_id);
2404
    break;
2405
  }
2406
      break;
2407
#endif
2408
2409
#ifdef MCOREMAGIC
2410
    case MCOREMAGIC:
2411
      arch = bfd_arch_mcore;
2412
      break;
2413
#endif
2414
2415
0
    default:      /* Unreadable input file type.  */
2416
0
      arch = bfd_arch_obscure;
2417
0
      break;
2418
88.8k
    }
2419
2420
88.8k
  bfd_default_set_arch_mach (abfd, arch, machine);
2421
88.8k
  return true;
2422
88.8k
}
pe-mcore.c:coff_set_arch_mach_hook
Line
Count
Source
2154
67.5k
{
2155
67.5k
  unsigned long machine;
2156
67.5k
  enum bfd_architecture arch;
2157
67.5k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2158
2159
  /* Zero selects the default machine for an arch.  */
2160
67.5k
  machine = 0;
2161
67.5k
  switch (internal_f->f_magic)
2162
67.5k
    {
2163
#ifdef I386MAGIC
2164
    case I386MAGIC:
2165
    case I386PTXMAGIC:
2166
    case I386AIXMAGIC:    /* Danbury PS/2 AIX C Compiler.  */
2167
    case LYNXCOFFMAGIC:
2168
    case I386_APPLE_MAGIC:
2169
    case I386_FREEBSD_MAGIC:
2170
    case I386_LINUX_MAGIC:
2171
    case I386_NETBSD_MAGIC:
2172
      arch = bfd_arch_i386;
2173
      break;
2174
#endif
2175
#ifdef AMD64MAGIC
2176
    case AMD64MAGIC:
2177
    case AMD64_APPLE_MAGIC:
2178
    case AMD64_FREEBSD_MAGIC:
2179
    case AMD64_LINUX_MAGIC:
2180
    case AMD64_NETBSD_MAGIC:
2181
      arch = bfd_arch_i386;
2182
      machine = bfd_mach_x86_64;
2183
      break;
2184
#endif
2185
#ifdef IA64MAGIC
2186
    case IA64MAGIC:
2187
      arch = bfd_arch_ia64;
2188
      break;
2189
#endif
2190
#ifdef ARMMAGIC
2191
    case ARMMAGIC:
2192
    case ARMPEMAGIC:
2193
    case THUMBPEMAGIC:
2194
      arch = bfd_arch_arm;
2195
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2196
      if (machine == bfd_mach_arm_unknown)
2197
  {
2198
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2199
      {
2200
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2201
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2202
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2203
      default:
2204
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2205
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2206
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2207
        /* The COFF header does not have enough bits available
2208
     to cover all the different ARM architectures.  So
2209
     we interpret F_ARM_5, the highest flag value to mean
2210
     "the highest ARM architecture known to BFD" which is
2211
     currently the XScale.  */
2212
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2213
      }
2214
  }
2215
      break;
2216
#endif
2217
#ifdef AARCH64MAGIC
2218
    case AARCH64MAGIC:
2219
      arch = bfd_arch_aarch64;
2220
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2221
      break;
2222
#endif
2223
#ifdef LOONGARCH64MAGIC
2224
    case LOONGARCH64MAGIC:
2225
      arch = bfd_arch_loongarch;
2226
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2227
      break;
2228
#endif
2229
#ifdef RISCV64MAGIC
2230
    case RISCV64MAGIC:
2231
      arch = bfd_arch_riscv;
2232
      machine = bfd_mach_riscv64;
2233
      break;
2234
#endif
2235
#ifdef Z80MAGIC
2236
    case Z80MAGIC:
2237
      arch = bfd_arch_z80;
2238
      switch (internal_f->f_flags & F_MACHMASK)
2239
  {
2240
  case bfd_mach_z80strict << 12:
2241
  case bfd_mach_z80 << 12:
2242
  case bfd_mach_z80n << 12:
2243
  case bfd_mach_z80full << 12:
2244
  case bfd_mach_r800 << 12:
2245
  case bfd_mach_gbz80 << 12:
2246
  case bfd_mach_z180 << 12:
2247
  case bfd_mach_ez80_z80 << 12:
2248
  case bfd_mach_ez80_adl << 12:
2249
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2250
    break;
2251
  default:
2252
    return false;
2253
  }
2254
      break;
2255
#endif
2256
#ifdef Z8KMAGIC
2257
    case Z8KMAGIC:
2258
      arch = bfd_arch_z8k;
2259
      switch (internal_f->f_flags & F_MACHMASK)
2260
  {
2261
  case F_Z8001:
2262
    machine = bfd_mach_z8001;
2263
    break;
2264
  case F_Z8002:
2265
    machine = bfd_mach_z8002;
2266
    break;
2267
  default:
2268
    return false;
2269
  }
2270
      break;
2271
#endif
2272
2273
#ifdef RS6000COFF_C
2274
#ifdef XCOFF64
2275
    case U64_TOCMAGIC:
2276
    case U803XTOCMAGIC:
2277
#else
2278
    case U802ROMAGIC:
2279
    case U802WRMAGIC:
2280
    case U802TOCMAGIC:
2281
#endif
2282
      {
2283
  int cputype;
2284
2285
  if (xcoff_data (abfd)->cputype != -1)
2286
    cputype = xcoff_data (abfd)->cputype & 0xff;
2287
  else
2288
    {
2289
      /* We did not get a value from the a.out header.  If the
2290
         file has not been stripped, we may be able to get the
2291
         architecture information from the first symbol, if it
2292
         is a .file symbol.  */
2293
      if (obj_raw_syment_count (abfd) == 0)
2294
        cputype = 0;
2295
      else
2296
        {
2297
    bfd_byte *buf;
2298
    struct internal_syment sym;
2299
    bfd_size_type amt = bfd_coff_symesz (abfd);
2300
2301
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2302
      return false;
2303
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2304
    if (buf == NULL)
2305
      return false;
2306
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2307
    if (sym.n_sclass == C_FILE)
2308
      cputype = sym.n_type & 0xff;
2309
    else
2310
      cputype = 0;
2311
    free (buf);
2312
        }
2313
    }
2314
2315
  /* FIXME: We don't handle all cases here.  */
2316
  switch (cputype)
2317
    {
2318
    default:
2319
    case 0:
2320
      arch = bfd_xcoff_architecture (abfd);
2321
      machine = bfd_xcoff_machine (abfd);
2322
      break;
2323
2324
    case 1:
2325
      arch = bfd_arch_powerpc;
2326
      machine = bfd_mach_ppc_601;
2327
      break;
2328
    case 2: /* 64 bit PowerPC */
2329
      arch = bfd_arch_powerpc;
2330
      machine = bfd_mach_ppc_620;
2331
      break;
2332
    case 3:
2333
      arch = bfd_arch_powerpc;
2334
      machine = bfd_mach_ppc;
2335
      break;
2336
    case 4:
2337
      arch = bfd_arch_rs6000;
2338
      machine = bfd_mach_rs6k;
2339
      break;
2340
    }
2341
      }
2342
      break;
2343
#endif
2344
2345
#ifdef SH_ARCH_MAGIC_BIG
2346
    case SH_ARCH_MAGIC_BIG:
2347
    case SH_ARCH_MAGIC_LITTLE:
2348
#ifdef COFF_WITH_PE
2349
    case SH_ARCH_MAGIC_WINCE:
2350
#endif
2351
      arch = bfd_arch_sh;
2352
      break;
2353
#endif
2354
2355
#ifdef MIPS_ARCH_MAGIC_WINCE
2356
    case MIPS_ARCH_MAGIC_WINCE:
2357
      arch = bfd_arch_mips;
2358
      break;
2359
#endif
2360
2361
#ifdef SPARCMAGIC
2362
    case SPARCMAGIC:
2363
#ifdef LYNXCOFFMAGIC
2364
    case LYNXCOFFMAGIC:
2365
#endif
2366
      arch = bfd_arch_sparc;
2367
      break;
2368
#endif
2369
2370
#ifdef TIC30MAGIC
2371
    case TIC30MAGIC:
2372
      arch = bfd_arch_tic30;
2373
      break;
2374
#endif
2375
2376
#ifdef TICOFF0MAGIC
2377
#ifdef TICOFF_TARGET_ARCH
2378
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2379
    case TICOFF0MAGIC:
2380
      arch = TICOFF_TARGET_ARCH;
2381
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2382
      break;
2383
#endif
2384
#endif
2385
2386
#ifdef TICOFF1MAGIC
2387
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2388
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2389
    case TICOFF1MAGIC:
2390
    case TICOFF2MAGIC:
2391
      switch (internal_f->f_target_id)
2392
  {
2393
#ifdef TI_TARGET_ID
2394
  case TI_TARGET_ID:
2395
    arch = TICOFF_TARGET_ARCH;
2396
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2397
    break;
2398
#endif
2399
  default:
2400
    arch = bfd_arch_obscure;
2401
    _bfd_error_handler
2402
      (_("unrecognized TI COFF target id '0x%x'"),
2403
       internal_f->f_target_id);
2404
    break;
2405
  }
2406
      break;
2407
#endif
2408
2409
0
#ifdef MCOREMAGIC
2410
67.5k
    case MCOREMAGIC:
2411
67.5k
      arch = bfd_arch_mcore;
2412
67.5k
      break;
2413
0
#endif
2414
2415
0
    default:      /* Unreadable input file type.  */
2416
0
      arch = bfd_arch_obscure;
2417
0
      break;
2418
67.5k
    }
2419
2420
67.5k
  bfd_default_set_arch_mach (abfd, arch, machine);
2421
67.5k
  return true;
2422
67.5k
}
pe-sh.c:coff_set_arch_mach_hook
Line
Count
Source
2154
60.0k
{
2155
60.0k
  unsigned long machine;
2156
60.0k
  enum bfd_architecture arch;
2157
60.0k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2158
2159
  /* Zero selects the default machine for an arch.  */
2160
60.0k
  machine = 0;
2161
60.0k
  switch (internal_f->f_magic)
2162
60.0k
    {
2163
#ifdef I386MAGIC
2164
    case I386MAGIC:
2165
    case I386PTXMAGIC:
2166
    case I386AIXMAGIC:    /* Danbury PS/2 AIX C Compiler.  */
2167
    case LYNXCOFFMAGIC:
2168
    case I386_APPLE_MAGIC:
2169
    case I386_FREEBSD_MAGIC:
2170
    case I386_LINUX_MAGIC:
2171
    case I386_NETBSD_MAGIC:
2172
      arch = bfd_arch_i386;
2173
      break;
2174
#endif
2175
#ifdef AMD64MAGIC
2176
    case AMD64MAGIC:
2177
    case AMD64_APPLE_MAGIC:
2178
    case AMD64_FREEBSD_MAGIC:
2179
    case AMD64_LINUX_MAGIC:
2180
    case AMD64_NETBSD_MAGIC:
2181
      arch = bfd_arch_i386;
2182
      machine = bfd_mach_x86_64;
2183
      break;
2184
#endif
2185
#ifdef IA64MAGIC
2186
    case IA64MAGIC:
2187
      arch = bfd_arch_ia64;
2188
      break;
2189
#endif
2190
#ifdef ARMMAGIC
2191
    case ARMMAGIC:
2192
    case ARMPEMAGIC:
2193
    case THUMBPEMAGIC:
2194
      arch = bfd_arch_arm;
2195
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2196
      if (machine == bfd_mach_arm_unknown)
2197
  {
2198
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2199
      {
2200
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2201
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2202
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2203
      default:
2204
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2205
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2206
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2207
        /* The COFF header does not have enough bits available
2208
     to cover all the different ARM architectures.  So
2209
     we interpret F_ARM_5, the highest flag value to mean
2210
     "the highest ARM architecture known to BFD" which is
2211
     currently the XScale.  */
2212
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2213
      }
2214
  }
2215
      break;
2216
#endif
2217
#ifdef AARCH64MAGIC
2218
    case AARCH64MAGIC:
2219
      arch = bfd_arch_aarch64;
2220
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2221
      break;
2222
#endif
2223
#ifdef LOONGARCH64MAGIC
2224
    case LOONGARCH64MAGIC:
2225
      arch = bfd_arch_loongarch;
2226
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2227
      break;
2228
#endif
2229
#ifdef RISCV64MAGIC
2230
    case RISCV64MAGIC:
2231
      arch = bfd_arch_riscv;
2232
      machine = bfd_mach_riscv64;
2233
      break;
2234
#endif
2235
#ifdef Z80MAGIC
2236
    case Z80MAGIC:
2237
      arch = bfd_arch_z80;
2238
      switch (internal_f->f_flags & F_MACHMASK)
2239
  {
2240
  case bfd_mach_z80strict << 12:
2241
  case bfd_mach_z80 << 12:
2242
  case bfd_mach_z80n << 12:
2243
  case bfd_mach_z80full << 12:
2244
  case bfd_mach_r800 << 12:
2245
  case bfd_mach_gbz80 << 12:
2246
  case bfd_mach_z180 << 12:
2247
  case bfd_mach_ez80_z80 << 12:
2248
  case bfd_mach_ez80_adl << 12:
2249
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2250
    break;
2251
  default:
2252
    return false;
2253
  }
2254
      break;
2255
#endif
2256
#ifdef Z8KMAGIC
2257
    case Z8KMAGIC:
2258
      arch = bfd_arch_z8k;
2259
      switch (internal_f->f_flags & F_MACHMASK)
2260
  {
2261
  case F_Z8001:
2262
    machine = bfd_mach_z8001;
2263
    break;
2264
  case F_Z8002:
2265
    machine = bfd_mach_z8002;
2266
    break;
2267
  default:
2268
    return false;
2269
  }
2270
      break;
2271
#endif
2272
2273
#ifdef RS6000COFF_C
2274
#ifdef XCOFF64
2275
    case U64_TOCMAGIC:
2276
    case U803XTOCMAGIC:
2277
#else
2278
    case U802ROMAGIC:
2279
    case U802WRMAGIC:
2280
    case U802TOCMAGIC:
2281
#endif
2282
      {
2283
  int cputype;
2284
2285
  if (xcoff_data (abfd)->cputype != -1)
2286
    cputype = xcoff_data (abfd)->cputype & 0xff;
2287
  else
2288
    {
2289
      /* We did not get a value from the a.out header.  If the
2290
         file has not been stripped, we may be able to get the
2291
         architecture information from the first symbol, if it
2292
         is a .file symbol.  */
2293
      if (obj_raw_syment_count (abfd) == 0)
2294
        cputype = 0;
2295
      else
2296
        {
2297
    bfd_byte *buf;
2298
    struct internal_syment sym;
2299
    bfd_size_type amt = bfd_coff_symesz (abfd);
2300
2301
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2302
      return false;
2303
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2304
    if (buf == NULL)
2305
      return false;
2306
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2307
    if (sym.n_sclass == C_FILE)
2308
      cputype = sym.n_type & 0xff;
2309
    else
2310
      cputype = 0;
2311
    free (buf);
2312
        }
2313
    }
2314
2315
  /* FIXME: We don't handle all cases here.  */
2316
  switch (cputype)
2317
    {
2318
    default:
2319
    case 0:
2320
      arch = bfd_xcoff_architecture (abfd);
2321
      machine = bfd_xcoff_machine (abfd);
2322
      break;
2323
2324
    case 1:
2325
      arch = bfd_arch_powerpc;
2326
      machine = bfd_mach_ppc_601;
2327
      break;
2328
    case 2: /* 64 bit PowerPC */
2329
      arch = bfd_arch_powerpc;
2330
      machine = bfd_mach_ppc_620;
2331
      break;
2332
    case 3:
2333
      arch = bfd_arch_powerpc;
2334
      machine = bfd_mach_ppc;
2335
      break;
2336
    case 4:
2337
      arch = bfd_arch_rs6000;
2338
      machine = bfd_mach_rs6k;
2339
      break;
2340
    }
2341
      }
2342
      break;
2343
#endif
2344
2345
0
#ifdef SH_ARCH_MAGIC_BIG
2346
47.1k
    case SH_ARCH_MAGIC_BIG:
2347
48.2k
    case SH_ARCH_MAGIC_LITTLE:
2348
48.2k
#ifdef COFF_WITH_PE
2349
60.0k
    case SH_ARCH_MAGIC_WINCE:
2350
60.0k
#endif
2351
60.0k
      arch = bfd_arch_sh;
2352
60.0k
      break;
2353
0
#endif
2354
2355
#ifdef MIPS_ARCH_MAGIC_WINCE
2356
    case MIPS_ARCH_MAGIC_WINCE:
2357
      arch = bfd_arch_mips;
2358
      break;
2359
#endif
2360
2361
#ifdef SPARCMAGIC
2362
    case SPARCMAGIC:
2363
#ifdef LYNXCOFFMAGIC
2364
    case LYNXCOFFMAGIC:
2365
#endif
2366
      arch = bfd_arch_sparc;
2367
      break;
2368
#endif
2369
2370
#ifdef TIC30MAGIC
2371
    case TIC30MAGIC:
2372
      arch = bfd_arch_tic30;
2373
      break;
2374
#endif
2375
2376
#ifdef TICOFF0MAGIC
2377
#ifdef TICOFF_TARGET_ARCH
2378
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2379
    case TICOFF0MAGIC:
2380
      arch = TICOFF_TARGET_ARCH;
2381
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2382
      break;
2383
#endif
2384
#endif
2385
2386
#ifdef TICOFF1MAGIC
2387
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2388
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2389
    case TICOFF1MAGIC:
2390
    case TICOFF2MAGIC:
2391
      switch (internal_f->f_target_id)
2392
  {
2393
#ifdef TI_TARGET_ID
2394
  case TI_TARGET_ID:
2395
    arch = TICOFF_TARGET_ARCH;
2396
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2397
    break;
2398
#endif
2399
  default:
2400
    arch = bfd_arch_obscure;
2401
    _bfd_error_handler
2402
      (_("unrecognized TI COFF target id '0x%x'"),
2403
       internal_f->f_target_id);
2404
    break;
2405
  }
2406
      break;
2407
#endif
2408
2409
#ifdef MCOREMAGIC
2410
    case MCOREMAGIC:
2411
      arch = bfd_arch_mcore;
2412
      break;
2413
#endif
2414
2415
0
    default:      /* Unreadable input file type.  */
2416
0
      arch = bfd_arch_obscure;
2417
0
      break;
2418
60.0k
    }
2419
2420
60.0k
  bfd_default_set_arch_mach (abfd, arch, machine);
2421
60.0k
  return true;
2422
60.0k
}
pei-arm-wince.c:coff_set_arch_mach_hook
Line
Count
Source
2154
105k
{
2155
105k
  unsigned long machine;
2156
105k
  enum bfd_architecture arch;
2157
105k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2158
2159
  /* Zero selects the default machine for an arch.  */
2160
105k
  machine = 0;
2161
105k
  switch (internal_f->f_magic)
2162
105k
    {
2163
#ifdef I386MAGIC
2164
    case I386MAGIC:
2165
    case I386PTXMAGIC:
2166
    case I386AIXMAGIC:    /* Danbury PS/2 AIX C Compiler.  */
2167
    case LYNXCOFFMAGIC:
2168
    case I386_APPLE_MAGIC:
2169
    case I386_FREEBSD_MAGIC:
2170
    case I386_LINUX_MAGIC:
2171
    case I386_NETBSD_MAGIC:
2172
      arch = bfd_arch_i386;
2173
      break;
2174
#endif
2175
#ifdef AMD64MAGIC
2176
    case AMD64MAGIC:
2177
    case AMD64_APPLE_MAGIC:
2178
    case AMD64_FREEBSD_MAGIC:
2179
    case AMD64_LINUX_MAGIC:
2180
    case AMD64_NETBSD_MAGIC:
2181
      arch = bfd_arch_i386;
2182
      machine = bfd_mach_x86_64;
2183
      break;
2184
#endif
2185
#ifdef IA64MAGIC
2186
    case IA64MAGIC:
2187
      arch = bfd_arch_ia64;
2188
      break;
2189
#endif
2190
0
#ifdef ARMMAGIC
2191
84.6k
    case ARMMAGIC:
2192
90.0k
    case ARMPEMAGIC:
2193
99.3k
    case THUMBPEMAGIC:
2194
99.3k
      arch = bfd_arch_arm;
2195
99.3k
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2196
99.3k
      if (machine == bfd_mach_arm_unknown)
2197
99.3k
  {
2198
99.3k
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2199
99.3k
      {
2200
3.24k
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2201
5.94k
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2202
9.81k
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2203
46.1k
      default:
2204
48.7k
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2205
6.60k
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2206
7.05k
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2207
        /* The COFF header does not have enough bits available
2208
     to cover all the different ARM architectures.  So
2209
     we interpret F_ARM_5, the highest flag value to mean
2210
     "the highest ARM architecture known to BFD" which is
2211
     currently the XScale.  */
2212
17.8k
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2213
99.3k
      }
2214
99.3k
  }
2215
99.3k
      break;
2216
99.3k
#endif
2217
#ifdef AARCH64MAGIC
2218
    case AARCH64MAGIC:
2219
      arch = bfd_arch_aarch64;
2220
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2221
      break;
2222
#endif
2223
#ifdef LOONGARCH64MAGIC
2224
    case LOONGARCH64MAGIC:
2225
      arch = bfd_arch_loongarch;
2226
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2227
      break;
2228
#endif
2229
#ifdef RISCV64MAGIC
2230
    case RISCV64MAGIC:
2231
      arch = bfd_arch_riscv;
2232
      machine = bfd_mach_riscv64;
2233
      break;
2234
#endif
2235
#ifdef Z80MAGIC
2236
    case Z80MAGIC:
2237
      arch = bfd_arch_z80;
2238
      switch (internal_f->f_flags & F_MACHMASK)
2239
  {
2240
  case bfd_mach_z80strict << 12:
2241
  case bfd_mach_z80 << 12:
2242
  case bfd_mach_z80n << 12:
2243
  case bfd_mach_z80full << 12:
2244
  case bfd_mach_r800 << 12:
2245
  case bfd_mach_gbz80 << 12:
2246
  case bfd_mach_z180 << 12:
2247
  case bfd_mach_ez80_z80 << 12:
2248
  case bfd_mach_ez80_adl << 12:
2249
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2250
    break;
2251
  default:
2252
    return false;
2253
  }
2254
      break;
2255
#endif
2256
#ifdef Z8KMAGIC
2257
    case Z8KMAGIC:
2258
      arch = bfd_arch_z8k;
2259
      switch (internal_f->f_flags & F_MACHMASK)
2260
  {
2261
  case F_Z8001:
2262
    machine = bfd_mach_z8001;
2263
    break;
2264
  case F_Z8002:
2265
    machine = bfd_mach_z8002;
2266
    break;
2267
  default:
2268
    return false;
2269
  }
2270
      break;
2271
#endif
2272
2273
#ifdef RS6000COFF_C
2274
#ifdef XCOFF64
2275
    case U64_TOCMAGIC:
2276
    case U803XTOCMAGIC:
2277
#else
2278
    case U802ROMAGIC:
2279
    case U802WRMAGIC:
2280
    case U802TOCMAGIC:
2281
#endif
2282
      {
2283
  int cputype;
2284
2285
  if (xcoff_data (abfd)->cputype != -1)
2286
    cputype = xcoff_data (abfd)->cputype & 0xff;
2287
  else
2288
    {
2289
      /* We did not get a value from the a.out header.  If the
2290
         file has not been stripped, we may be able to get the
2291
         architecture information from the first symbol, if it
2292
         is a .file symbol.  */
2293
      if (obj_raw_syment_count (abfd) == 0)
2294
        cputype = 0;
2295
      else
2296
        {
2297
    bfd_byte *buf;
2298
    struct internal_syment sym;
2299
    bfd_size_type amt = bfd_coff_symesz (abfd);
2300
2301
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2302
      return false;
2303
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2304
    if (buf == NULL)
2305
      return false;
2306
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2307
    if (sym.n_sclass == C_FILE)
2308
      cputype = sym.n_type & 0xff;
2309
    else
2310
      cputype = 0;
2311
    free (buf);
2312
        }
2313
    }
2314
2315
  /* FIXME: We don't handle all cases here.  */
2316
  switch (cputype)
2317
    {
2318
    default:
2319
    case 0:
2320
      arch = bfd_xcoff_architecture (abfd);
2321
      machine = bfd_xcoff_machine (abfd);
2322
      break;
2323
2324
    case 1:
2325
      arch = bfd_arch_powerpc;
2326
      machine = bfd_mach_ppc_601;
2327
      break;
2328
    case 2: /* 64 bit PowerPC */
2329
      arch = bfd_arch_powerpc;
2330
      machine = bfd_mach_ppc_620;
2331
      break;
2332
    case 3:
2333
      arch = bfd_arch_powerpc;
2334
      machine = bfd_mach_ppc;
2335
      break;
2336
    case 4:
2337
      arch = bfd_arch_rs6000;
2338
      machine = bfd_mach_rs6k;
2339
      break;
2340
    }
2341
      }
2342
      break;
2343
#endif
2344
2345
#ifdef SH_ARCH_MAGIC_BIG
2346
    case SH_ARCH_MAGIC_BIG:
2347
    case SH_ARCH_MAGIC_LITTLE:
2348
#ifdef COFF_WITH_PE
2349
    case SH_ARCH_MAGIC_WINCE:
2350
#endif
2351
      arch = bfd_arch_sh;
2352
      break;
2353
#endif
2354
2355
#ifdef MIPS_ARCH_MAGIC_WINCE
2356
    case MIPS_ARCH_MAGIC_WINCE:
2357
      arch = bfd_arch_mips;
2358
      break;
2359
#endif
2360
2361
#ifdef SPARCMAGIC
2362
    case SPARCMAGIC:
2363
#ifdef LYNXCOFFMAGIC
2364
    case LYNXCOFFMAGIC:
2365
#endif
2366
      arch = bfd_arch_sparc;
2367
      break;
2368
#endif
2369
2370
#ifdef TIC30MAGIC
2371
    case TIC30MAGIC:
2372
      arch = bfd_arch_tic30;
2373
      break;
2374
#endif
2375
2376
#ifdef TICOFF0MAGIC
2377
#ifdef TICOFF_TARGET_ARCH
2378
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2379
    case TICOFF0MAGIC:
2380
      arch = TICOFF_TARGET_ARCH;
2381
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2382
      break;
2383
#endif
2384
#endif
2385
2386
#ifdef TICOFF1MAGIC
2387
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2388
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2389
    case TICOFF1MAGIC:
2390
    case TICOFF2MAGIC:
2391
      switch (internal_f->f_target_id)
2392
  {
2393
#ifdef TI_TARGET_ID
2394
  case TI_TARGET_ID:
2395
    arch = TICOFF_TARGET_ARCH;
2396
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2397
    break;
2398
#endif
2399
  default:
2400
    arch = bfd_arch_obscure;
2401
    _bfd_error_handler
2402
      (_("unrecognized TI COFF target id '0x%x'"),
2403
       internal_f->f_target_id);
2404
    break;
2405
  }
2406
      break;
2407
#endif
2408
2409
#ifdef MCOREMAGIC
2410
    case MCOREMAGIC:
2411
      arch = bfd_arch_mcore;
2412
      break;
2413
#endif
2414
2415
99.3k
    default:      /* Unreadable input file type.  */
2416
5.69k
      arch = bfd_arch_obscure;
2417
5.69k
      break;
2418
105k
    }
2419
2420
105k
  bfd_default_set_arch_mach (abfd, arch, machine);
2421
105k
  return true;
2422
105k
}
pei-arm.c:coff_set_arch_mach_hook
Line
Count
Source
2154
147k
{
2155
147k
  unsigned long machine;
2156
147k
  enum bfd_architecture arch;
2157
147k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2158
2159
  /* Zero selects the default machine for an arch.  */
2160
147k
  machine = 0;
2161
147k
  switch (internal_f->f_magic)
2162
147k
    {
2163
#ifdef I386MAGIC
2164
    case I386MAGIC:
2165
    case I386PTXMAGIC:
2166
    case I386AIXMAGIC:    /* Danbury PS/2 AIX C Compiler.  */
2167
    case LYNXCOFFMAGIC:
2168
    case I386_APPLE_MAGIC:
2169
    case I386_FREEBSD_MAGIC:
2170
    case I386_LINUX_MAGIC:
2171
    case I386_NETBSD_MAGIC:
2172
      arch = bfd_arch_i386;
2173
      break;
2174
#endif
2175
#ifdef AMD64MAGIC
2176
    case AMD64MAGIC:
2177
    case AMD64_APPLE_MAGIC:
2178
    case AMD64_FREEBSD_MAGIC:
2179
    case AMD64_LINUX_MAGIC:
2180
    case AMD64_NETBSD_MAGIC:
2181
      arch = bfd_arch_i386;
2182
      machine = bfd_mach_x86_64;
2183
      break;
2184
#endif
2185
#ifdef IA64MAGIC
2186
    case IA64MAGIC:
2187
      arch = bfd_arch_ia64;
2188
      break;
2189
#endif
2190
0
#ifdef ARMMAGIC
2191
106k
    case ARMMAGIC:
2192
123k
    case ARMPEMAGIC:
2193
139k
    case THUMBPEMAGIC:
2194
139k
      arch = bfd_arch_arm;
2195
139k
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2196
139k
      if (machine == bfd_mach_arm_unknown)
2197
139k
  {
2198
139k
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2199
139k
      {
2200
5.24k
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2201
8.20k
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2202
10.4k
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2203
73.5k
      default:
2204
78.8k
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2205
8.01k
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2206
7.41k
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2207
        /* The COFF header does not have enough bits available
2208
     to cover all the different ARM architectures.  So
2209
     we interpret F_ARM_5, the highest flag value to mean
2210
     "the highest ARM architecture known to BFD" which is
2211
     currently the XScale.  */
2212
20.8k
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2213
139k
      }
2214
139k
  }
2215
139k
      break;
2216
139k
#endif
2217
#ifdef AARCH64MAGIC
2218
    case AARCH64MAGIC:
2219
      arch = bfd_arch_aarch64;
2220
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2221
      break;
2222
#endif
2223
#ifdef LOONGARCH64MAGIC
2224
    case LOONGARCH64MAGIC:
2225
      arch = bfd_arch_loongarch;
2226
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2227
      break;
2228
#endif
2229
#ifdef RISCV64MAGIC
2230
    case RISCV64MAGIC:
2231
      arch = bfd_arch_riscv;
2232
      machine = bfd_mach_riscv64;
2233
      break;
2234
#endif
2235
#ifdef Z80MAGIC
2236
    case Z80MAGIC:
2237
      arch = bfd_arch_z80;
2238
      switch (internal_f->f_flags & F_MACHMASK)
2239
  {
2240
  case bfd_mach_z80strict << 12:
2241
  case bfd_mach_z80 << 12:
2242
  case bfd_mach_z80n << 12:
2243
  case bfd_mach_z80full << 12:
2244
  case bfd_mach_r800 << 12:
2245
  case bfd_mach_gbz80 << 12:
2246
  case bfd_mach_z180 << 12:
2247
  case bfd_mach_ez80_z80 << 12:
2248
  case bfd_mach_ez80_adl << 12:
2249
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2250
    break;
2251
  default:
2252
    return false;
2253
  }
2254
      break;
2255
#endif
2256
#ifdef Z8KMAGIC
2257
    case Z8KMAGIC:
2258
      arch = bfd_arch_z8k;
2259
      switch (internal_f->f_flags & F_MACHMASK)
2260
  {
2261
  case F_Z8001:
2262
    machine = bfd_mach_z8001;
2263
    break;
2264
  case F_Z8002:
2265
    machine = bfd_mach_z8002;
2266
    break;
2267
  default:
2268
    return false;
2269
  }
2270
      break;
2271
#endif
2272
2273
#ifdef RS6000COFF_C
2274
#ifdef XCOFF64
2275
    case U64_TOCMAGIC:
2276
    case U803XTOCMAGIC:
2277
#else
2278
    case U802ROMAGIC:
2279
    case U802WRMAGIC:
2280
    case U802TOCMAGIC:
2281
#endif
2282
      {
2283
  int cputype;
2284
2285
  if (xcoff_data (abfd)->cputype != -1)
2286
    cputype = xcoff_data (abfd)->cputype & 0xff;
2287
  else
2288
    {
2289
      /* We did not get a value from the a.out header.  If the
2290
         file has not been stripped, we may be able to get the
2291
         architecture information from the first symbol, if it
2292
         is a .file symbol.  */
2293
      if (obj_raw_syment_count (abfd) == 0)
2294
        cputype = 0;
2295
      else
2296
        {
2297
    bfd_byte *buf;
2298
    struct internal_syment sym;
2299
    bfd_size_type amt = bfd_coff_symesz (abfd);
2300
2301
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2302
      return false;
2303
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2304
    if (buf == NULL)
2305
      return false;
2306
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2307
    if (sym.n_sclass == C_FILE)
2308
      cputype = sym.n_type & 0xff;
2309
    else
2310
      cputype = 0;
2311
    free (buf);
2312
        }
2313
    }
2314
2315
  /* FIXME: We don't handle all cases here.  */
2316
  switch (cputype)
2317
    {
2318
    default:
2319
    case 0:
2320
      arch = bfd_xcoff_architecture (abfd);
2321
      machine = bfd_xcoff_machine (abfd);
2322
      break;
2323
2324
    case 1:
2325
      arch = bfd_arch_powerpc;
2326
      machine = bfd_mach_ppc_601;
2327
      break;
2328
    case 2: /* 64 bit PowerPC */
2329
      arch = bfd_arch_powerpc;
2330
      machine = bfd_mach_ppc_620;
2331
      break;
2332
    case 3:
2333
      arch = bfd_arch_powerpc;
2334
      machine = bfd_mach_ppc;
2335
      break;
2336
    case 4:
2337
      arch = bfd_arch_rs6000;
2338
      machine = bfd_mach_rs6k;
2339
      break;
2340
    }
2341
      }
2342
      break;
2343
#endif
2344
2345
#ifdef SH_ARCH_MAGIC_BIG
2346
    case SH_ARCH_MAGIC_BIG:
2347
    case SH_ARCH_MAGIC_LITTLE:
2348
#ifdef COFF_WITH_PE
2349
    case SH_ARCH_MAGIC_WINCE:
2350
#endif
2351
      arch = bfd_arch_sh;
2352
      break;
2353
#endif
2354
2355
#ifdef MIPS_ARCH_MAGIC_WINCE
2356
    case MIPS_ARCH_MAGIC_WINCE:
2357
      arch = bfd_arch_mips;
2358
      break;
2359
#endif
2360
2361
#ifdef SPARCMAGIC
2362
    case SPARCMAGIC:
2363
#ifdef LYNXCOFFMAGIC
2364
    case LYNXCOFFMAGIC:
2365
#endif
2366
      arch = bfd_arch_sparc;
2367
      break;
2368
#endif
2369
2370
#ifdef TIC30MAGIC
2371
    case TIC30MAGIC:
2372
      arch = bfd_arch_tic30;
2373
      break;
2374
#endif
2375
2376
#ifdef TICOFF0MAGIC
2377
#ifdef TICOFF_TARGET_ARCH
2378
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2379
    case TICOFF0MAGIC:
2380
      arch = TICOFF_TARGET_ARCH;
2381
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2382
      break;
2383
#endif
2384
#endif
2385
2386
#ifdef TICOFF1MAGIC
2387
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2388
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2389
    case TICOFF1MAGIC:
2390
    case TICOFF2MAGIC:
2391
      switch (internal_f->f_target_id)
2392
  {
2393
#ifdef TI_TARGET_ID
2394
  case TI_TARGET_ID:
2395
    arch = TICOFF_TARGET_ARCH;
2396
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2397
    break;
2398
#endif
2399
  default:
2400
    arch = bfd_arch_obscure;
2401
    _bfd_error_handler
2402
      (_("unrecognized TI COFF target id '0x%x'"),
2403
       internal_f->f_target_id);
2404
    break;
2405
  }
2406
      break;
2407
#endif
2408
2409
#ifdef MCOREMAGIC
2410
    case MCOREMAGIC:
2411
      arch = bfd_arch_mcore;
2412
      break;
2413
#endif
2414
2415
139k
    default:      /* Unreadable input file type.  */
2416
8.52k
      arch = bfd_arch_obscure;
2417
8.52k
      break;
2418
147k
    }
2419
2420
147k
  bfd_default_set_arch_mach (abfd, arch, machine);
2421
147k
  return true;
2422
147k
}
pei-mcore.c:coff_set_arch_mach_hook
Line
Count
Source
2154
85.5k
{
2155
85.5k
  unsigned long machine;
2156
85.5k
  enum bfd_architecture arch;
2157
85.5k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2158
2159
  /* Zero selects the default machine for an arch.  */
2160
85.5k
  machine = 0;
2161
85.5k
  switch (internal_f->f_magic)
2162
85.5k
    {
2163
#ifdef I386MAGIC
2164
    case I386MAGIC:
2165
    case I386PTXMAGIC:
2166
    case I386AIXMAGIC:    /* Danbury PS/2 AIX C Compiler.  */
2167
    case LYNXCOFFMAGIC:
2168
    case I386_APPLE_MAGIC:
2169
    case I386_FREEBSD_MAGIC:
2170
    case I386_LINUX_MAGIC:
2171
    case I386_NETBSD_MAGIC:
2172
      arch = bfd_arch_i386;
2173
      break;
2174
#endif
2175
#ifdef AMD64MAGIC
2176
    case AMD64MAGIC:
2177
    case AMD64_APPLE_MAGIC:
2178
    case AMD64_FREEBSD_MAGIC:
2179
    case AMD64_LINUX_MAGIC:
2180
    case AMD64_NETBSD_MAGIC:
2181
      arch = bfd_arch_i386;
2182
      machine = bfd_mach_x86_64;
2183
      break;
2184
#endif
2185
#ifdef IA64MAGIC
2186
    case IA64MAGIC:
2187
      arch = bfd_arch_ia64;
2188
      break;
2189
#endif
2190
#ifdef ARMMAGIC
2191
    case ARMMAGIC:
2192
    case ARMPEMAGIC:
2193
    case THUMBPEMAGIC:
2194
      arch = bfd_arch_arm;
2195
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2196
      if (machine == bfd_mach_arm_unknown)
2197
  {
2198
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2199
      {
2200
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2201
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2202
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2203
      default:
2204
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2205
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2206
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2207
        /* The COFF header does not have enough bits available
2208
     to cover all the different ARM architectures.  So
2209
     we interpret F_ARM_5, the highest flag value to mean
2210
     "the highest ARM architecture known to BFD" which is
2211
     currently the XScale.  */
2212
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2213
      }
2214
  }
2215
      break;
2216
#endif
2217
#ifdef AARCH64MAGIC
2218
    case AARCH64MAGIC:
2219
      arch = bfd_arch_aarch64;
2220
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2221
      break;
2222
#endif
2223
#ifdef LOONGARCH64MAGIC
2224
    case LOONGARCH64MAGIC:
2225
      arch = bfd_arch_loongarch;
2226
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2227
      break;
2228
#endif
2229
#ifdef RISCV64MAGIC
2230
    case RISCV64MAGIC:
2231
      arch = bfd_arch_riscv;
2232
      machine = bfd_mach_riscv64;
2233
      break;
2234
#endif
2235
#ifdef Z80MAGIC
2236
    case Z80MAGIC:
2237
      arch = bfd_arch_z80;
2238
      switch (internal_f->f_flags & F_MACHMASK)
2239
  {
2240
  case bfd_mach_z80strict << 12:
2241
  case bfd_mach_z80 << 12:
2242
  case bfd_mach_z80n << 12:
2243
  case bfd_mach_z80full << 12:
2244
  case bfd_mach_r800 << 12:
2245
  case bfd_mach_gbz80 << 12:
2246
  case bfd_mach_z180 << 12:
2247
  case bfd_mach_ez80_z80 << 12:
2248
  case bfd_mach_ez80_adl << 12:
2249
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2250
    break;
2251
  default:
2252
    return false;
2253
  }
2254
      break;
2255
#endif
2256
#ifdef Z8KMAGIC
2257
    case Z8KMAGIC:
2258
      arch = bfd_arch_z8k;
2259
      switch (internal_f->f_flags & F_MACHMASK)
2260
  {
2261
  case F_Z8001:
2262
    machine = bfd_mach_z8001;
2263
    break;
2264
  case F_Z8002:
2265
    machine = bfd_mach_z8002;
2266
    break;
2267
  default:
2268
    return false;
2269
  }
2270
      break;
2271
#endif
2272
2273
#ifdef RS6000COFF_C
2274
#ifdef XCOFF64
2275
    case U64_TOCMAGIC:
2276
    case U803XTOCMAGIC:
2277
#else
2278
    case U802ROMAGIC:
2279
    case U802WRMAGIC:
2280
    case U802TOCMAGIC:
2281
#endif
2282
      {
2283
  int cputype;
2284
2285
  if (xcoff_data (abfd)->cputype != -1)
2286
    cputype = xcoff_data (abfd)->cputype & 0xff;
2287
  else
2288
    {
2289
      /* We did not get a value from the a.out header.  If the
2290
         file has not been stripped, we may be able to get the
2291
         architecture information from the first symbol, if it
2292
         is a .file symbol.  */
2293
      if (obj_raw_syment_count (abfd) == 0)
2294
        cputype = 0;
2295
      else
2296
        {
2297
    bfd_byte *buf;
2298
    struct internal_syment sym;
2299
    bfd_size_type amt = bfd_coff_symesz (abfd);
2300
2301
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2302
      return false;
2303
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2304
    if (buf == NULL)
2305
      return false;
2306
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2307
    if (sym.n_sclass == C_FILE)
2308
      cputype = sym.n_type & 0xff;
2309
    else
2310
      cputype = 0;
2311
    free (buf);
2312
        }
2313
    }
2314
2315
  /* FIXME: We don't handle all cases here.  */
2316
  switch (cputype)
2317
    {
2318
    default:
2319
    case 0:
2320
      arch = bfd_xcoff_architecture (abfd);
2321
      machine = bfd_xcoff_machine (abfd);
2322
      break;
2323
2324
    case 1:
2325
      arch = bfd_arch_powerpc;
2326
      machine = bfd_mach_ppc_601;
2327
      break;
2328
    case 2: /* 64 bit PowerPC */
2329
      arch = bfd_arch_powerpc;
2330
      machine = bfd_mach_ppc_620;
2331
      break;
2332
    case 3:
2333
      arch = bfd_arch_powerpc;
2334
      machine = bfd_mach_ppc;
2335
      break;
2336
    case 4:
2337
      arch = bfd_arch_rs6000;
2338
      machine = bfd_mach_rs6k;
2339
      break;
2340
    }
2341
      }
2342
      break;
2343
#endif
2344
2345
#ifdef SH_ARCH_MAGIC_BIG
2346
    case SH_ARCH_MAGIC_BIG:
2347
    case SH_ARCH_MAGIC_LITTLE:
2348
#ifdef COFF_WITH_PE
2349
    case SH_ARCH_MAGIC_WINCE:
2350
#endif
2351
      arch = bfd_arch_sh;
2352
      break;
2353
#endif
2354
2355
#ifdef MIPS_ARCH_MAGIC_WINCE
2356
    case MIPS_ARCH_MAGIC_WINCE:
2357
      arch = bfd_arch_mips;
2358
      break;
2359
#endif
2360
2361
#ifdef SPARCMAGIC
2362
    case SPARCMAGIC:
2363
#ifdef LYNXCOFFMAGIC
2364
    case LYNXCOFFMAGIC:
2365
#endif
2366
      arch = bfd_arch_sparc;
2367
      break;
2368
#endif
2369
2370
#ifdef TIC30MAGIC
2371
    case TIC30MAGIC:
2372
      arch = bfd_arch_tic30;
2373
      break;
2374
#endif
2375
2376
#ifdef TICOFF0MAGIC
2377
#ifdef TICOFF_TARGET_ARCH
2378
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2379
    case TICOFF0MAGIC:
2380
      arch = TICOFF_TARGET_ARCH;
2381
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2382
      break;
2383
#endif
2384
#endif
2385
2386
#ifdef TICOFF1MAGIC
2387
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2388
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2389
    case TICOFF1MAGIC:
2390
    case TICOFF2MAGIC:
2391
      switch (internal_f->f_target_id)
2392
  {
2393
#ifdef TI_TARGET_ID
2394
  case TI_TARGET_ID:
2395
    arch = TICOFF_TARGET_ARCH;
2396
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2397
    break;
2398
#endif
2399
  default:
2400
    arch = bfd_arch_obscure;
2401
    _bfd_error_handler
2402
      (_("unrecognized TI COFF target id '0x%x'"),
2403
       internal_f->f_target_id);
2404
    break;
2405
  }
2406
      break;
2407
#endif
2408
2409
0
#ifdef MCOREMAGIC
2410
85.5k
    case MCOREMAGIC:
2411
85.5k
      arch = bfd_arch_mcore;
2412
85.5k
      break;
2413
0
#endif
2414
2415
0
    default:      /* Unreadable input file type.  */
2416
0
      arch = bfd_arch_obscure;
2417
0
      break;
2418
85.5k
    }
2419
2420
85.5k
  bfd_default_set_arch_mach (abfd, arch, machine);
2421
85.5k
  return true;
2422
85.5k
}
pei-sh.c:coff_set_arch_mach_hook
Line
Count
Source
2154
97.3k
{
2155
97.3k
  unsigned long machine;
2156
97.3k
  enum bfd_architecture arch;
2157
97.3k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2158
2159
  /* Zero selects the default machine for an arch.  */
2160
97.3k
  machine = 0;
2161
97.3k
  switch (internal_f->f_magic)
2162
97.3k
    {
2163
#ifdef I386MAGIC
2164
    case I386MAGIC:
2165
    case I386PTXMAGIC:
2166
    case I386AIXMAGIC:    /* Danbury PS/2 AIX C Compiler.  */
2167
    case LYNXCOFFMAGIC:
2168
    case I386_APPLE_MAGIC:
2169
    case I386_FREEBSD_MAGIC:
2170
    case I386_LINUX_MAGIC:
2171
    case I386_NETBSD_MAGIC:
2172
      arch = bfd_arch_i386;
2173
      break;
2174
#endif
2175
#ifdef AMD64MAGIC
2176
    case AMD64MAGIC:
2177
    case AMD64_APPLE_MAGIC:
2178
    case AMD64_FREEBSD_MAGIC:
2179
    case AMD64_LINUX_MAGIC:
2180
    case AMD64_NETBSD_MAGIC:
2181
      arch = bfd_arch_i386;
2182
      machine = bfd_mach_x86_64;
2183
      break;
2184
#endif
2185
#ifdef IA64MAGIC
2186
    case IA64MAGIC:
2187
      arch = bfd_arch_ia64;
2188
      break;
2189
#endif
2190
#ifdef ARMMAGIC
2191
    case ARMMAGIC:
2192
    case ARMPEMAGIC:
2193
    case THUMBPEMAGIC:
2194
      arch = bfd_arch_arm;
2195
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2196
      if (machine == bfd_mach_arm_unknown)
2197
  {
2198
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2199
      {
2200
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2201
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2202
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2203
      default:
2204
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2205
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2206
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2207
        /* The COFF header does not have enough bits available
2208
     to cover all the different ARM architectures.  So
2209
     we interpret F_ARM_5, the highest flag value to mean
2210
     "the highest ARM architecture known to BFD" which is
2211
     currently the XScale.  */
2212
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2213
      }
2214
  }
2215
      break;
2216
#endif
2217
#ifdef AARCH64MAGIC
2218
    case AARCH64MAGIC:
2219
      arch = bfd_arch_aarch64;
2220
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2221
      break;
2222
#endif
2223
#ifdef LOONGARCH64MAGIC
2224
    case LOONGARCH64MAGIC:
2225
      arch = bfd_arch_loongarch;
2226
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2227
      break;
2228
#endif
2229
#ifdef RISCV64MAGIC
2230
    case RISCV64MAGIC:
2231
      arch = bfd_arch_riscv;
2232
      machine = bfd_mach_riscv64;
2233
      break;
2234
#endif
2235
#ifdef Z80MAGIC
2236
    case Z80MAGIC:
2237
      arch = bfd_arch_z80;
2238
      switch (internal_f->f_flags & F_MACHMASK)
2239
  {
2240
  case bfd_mach_z80strict << 12:
2241
  case bfd_mach_z80 << 12:
2242
  case bfd_mach_z80n << 12:
2243
  case bfd_mach_z80full << 12:
2244
  case bfd_mach_r800 << 12:
2245
  case bfd_mach_gbz80 << 12:
2246
  case bfd_mach_z180 << 12:
2247
  case bfd_mach_ez80_z80 << 12:
2248
  case bfd_mach_ez80_adl << 12:
2249
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2250
    break;
2251
  default:
2252
    return false;
2253
  }
2254
      break;
2255
#endif
2256
#ifdef Z8KMAGIC
2257
    case Z8KMAGIC:
2258
      arch = bfd_arch_z8k;
2259
      switch (internal_f->f_flags & F_MACHMASK)
2260
  {
2261
  case F_Z8001:
2262
    machine = bfd_mach_z8001;
2263
    break;
2264
  case F_Z8002:
2265
    machine = bfd_mach_z8002;
2266
    break;
2267
  default:
2268
    return false;
2269
  }
2270
      break;
2271
#endif
2272
2273
#ifdef RS6000COFF_C
2274
#ifdef XCOFF64
2275
    case U64_TOCMAGIC:
2276
    case U803XTOCMAGIC:
2277
#else
2278
    case U802ROMAGIC:
2279
    case U802WRMAGIC:
2280
    case U802TOCMAGIC:
2281
#endif
2282
      {
2283
  int cputype;
2284
2285
  if (xcoff_data (abfd)->cputype != -1)
2286
    cputype = xcoff_data (abfd)->cputype & 0xff;
2287
  else
2288
    {
2289
      /* We did not get a value from the a.out header.  If the
2290
         file has not been stripped, we may be able to get the
2291
         architecture information from the first symbol, if it
2292
         is a .file symbol.  */
2293
      if (obj_raw_syment_count (abfd) == 0)
2294
        cputype = 0;
2295
      else
2296
        {
2297
    bfd_byte *buf;
2298
    struct internal_syment sym;
2299
    bfd_size_type amt = bfd_coff_symesz (abfd);
2300
2301
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2302
      return false;
2303
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2304
    if (buf == NULL)
2305
      return false;
2306
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2307
    if (sym.n_sclass == C_FILE)
2308
      cputype = sym.n_type & 0xff;
2309
    else
2310
      cputype = 0;
2311
    free (buf);
2312
        }
2313
    }
2314
2315
  /* FIXME: We don't handle all cases here.  */
2316
  switch (cputype)
2317
    {
2318
    default:
2319
    case 0:
2320
      arch = bfd_xcoff_architecture (abfd);
2321
      machine = bfd_xcoff_machine (abfd);
2322
      break;
2323
2324
    case 1:
2325
      arch = bfd_arch_powerpc;
2326
      machine = bfd_mach_ppc_601;
2327
      break;
2328
    case 2: /* 64 bit PowerPC */
2329
      arch = bfd_arch_powerpc;
2330
      machine = bfd_mach_ppc_620;
2331
      break;
2332
    case 3:
2333
      arch = bfd_arch_powerpc;
2334
      machine = bfd_mach_ppc;
2335
      break;
2336
    case 4:
2337
      arch = bfd_arch_rs6000;
2338
      machine = bfd_mach_rs6k;
2339
      break;
2340
    }
2341
      }
2342
      break;
2343
#endif
2344
2345
0
#ifdef SH_ARCH_MAGIC_BIG
2346
61.7k
    case SH_ARCH_MAGIC_BIG:
2347
74.6k
    case SH_ARCH_MAGIC_LITTLE:
2348
74.6k
#ifdef COFF_WITH_PE
2349
97.3k
    case SH_ARCH_MAGIC_WINCE:
2350
97.3k
#endif
2351
97.3k
      arch = bfd_arch_sh;
2352
97.3k
      break;
2353
0
#endif
2354
2355
#ifdef MIPS_ARCH_MAGIC_WINCE
2356
    case MIPS_ARCH_MAGIC_WINCE:
2357
      arch = bfd_arch_mips;
2358
      break;
2359
#endif
2360
2361
#ifdef SPARCMAGIC
2362
    case SPARCMAGIC:
2363
#ifdef LYNXCOFFMAGIC
2364
    case LYNXCOFFMAGIC:
2365
#endif
2366
      arch = bfd_arch_sparc;
2367
      break;
2368
#endif
2369
2370
#ifdef TIC30MAGIC
2371
    case TIC30MAGIC:
2372
      arch = bfd_arch_tic30;
2373
      break;
2374
#endif
2375
2376
#ifdef TICOFF0MAGIC
2377
#ifdef TICOFF_TARGET_ARCH
2378
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2379
    case TICOFF0MAGIC:
2380
      arch = TICOFF_TARGET_ARCH;
2381
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2382
      break;
2383
#endif
2384
#endif
2385
2386
#ifdef TICOFF1MAGIC
2387
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2388
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2389
    case TICOFF1MAGIC:
2390
    case TICOFF2MAGIC:
2391
      switch (internal_f->f_target_id)
2392
  {
2393
#ifdef TI_TARGET_ID
2394
  case TI_TARGET_ID:
2395
    arch = TICOFF_TARGET_ARCH;
2396
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2397
    break;
2398
#endif
2399
  default:
2400
    arch = bfd_arch_obscure;
2401
    _bfd_error_handler
2402
      (_("unrecognized TI COFF target id '0x%x'"),
2403
       internal_f->f_target_id);
2404
    break;
2405
  }
2406
      break;
2407
#endif
2408
2409
#ifdef MCOREMAGIC
2410
    case MCOREMAGIC:
2411
      arch = bfd_arch_mcore;
2412
      break;
2413
#endif
2414
2415
0
    default:      /* Unreadable input file type.  */
2416
0
      arch = bfd_arch_obscure;
2417
0
      break;
2418
97.3k
    }
2419
2420
97.3k
  bfd_default_set_arch_mach (abfd, arch, machine);
2421
97.3k
  return true;
2422
97.3k
}
2423
2424
static bool
2425
symname_in_debug_hook (bfd *abfd ATTRIBUTE_UNUSED,
2426
           struct internal_syment *sym ATTRIBUTE_UNUSED)
2427
2.56M
{
2428
#ifdef SYMNAME_IN_DEBUG
2429
238k
  return SYMNAME_IN_DEBUG (sym) != 0;
2430
#else
2431
  return false;
2432
#endif
2433
2.56M
}
pei-i386.c:symname_in_debug_hook
Line
Count
Source
2427
39.2k
{
2428
#ifdef SYMNAME_IN_DEBUG
2429
  return SYMNAME_IN_DEBUG (sym) != 0;
2430
#else
2431
39.2k
  return false;
2432
39.2k
#endif
2433
39.2k
}
pe-x86_64.c:symname_in_debug_hook
Line
Count
Source
2427
104k
{
2428
#ifdef SYMNAME_IN_DEBUG
2429
  return SYMNAME_IN_DEBUG (sym) != 0;
2430
#else
2431
104k
  return false;
2432
104k
#endif
2433
104k
}
pei-x86_64.c:symname_in_debug_hook
Line
Count
Source
2427
75.2k
{
2428
#ifdef SYMNAME_IN_DEBUG
2429
  return SYMNAME_IN_DEBUG (sym) != 0;
2430
#else
2431
75.2k
  return false;
2432
75.2k
#endif
2433
75.2k
}
coff-x86_64.c:symname_in_debug_hook
Line
Count
Source
2427
261k
{
2428
#ifdef SYMNAME_IN_DEBUG
2429
  return SYMNAME_IN_DEBUG (sym) != 0;
2430
#else
2431
261k
  return false;
2432
261k
#endif
2433
261k
}
coff64-rs6000.c:symname_in_debug_hook
Line
Count
Source
2427
156k
{
2428
156k
#ifdef SYMNAME_IN_DEBUG
2429
156k
  return SYMNAME_IN_DEBUG (sym) != 0;
2430
#else
2431
  return false;
2432
#endif
2433
156k
}
pe-aarch64.c:symname_in_debug_hook
Line
Count
Source
2427
133k
{
2428
#ifdef SYMNAME_IN_DEBUG
2429
  return SYMNAME_IN_DEBUG (sym) != 0;
2430
#else
2431
133k
  return false;
2432
133k
#endif
2433
133k
}
pei-aarch64.c:symname_in_debug_hook
Line
Count
Source
2427
79.7k
{
2428
#ifdef SYMNAME_IN_DEBUG
2429
  return SYMNAME_IN_DEBUG (sym) != 0;
2430
#else
2431
79.7k
  return false;
2432
79.7k
#endif
2433
79.7k
}
pei-ia64.c:symname_in_debug_hook
Line
Count
Source
2427
157k
{
2428
#ifdef SYMNAME_IN_DEBUG
2429
  return SYMNAME_IN_DEBUG (sym) != 0;
2430
#else
2431
157k
  return false;
2432
157k
#endif
2433
157k
}
pei-loongarch64.c:symname_in_debug_hook
Line
Count
Source
2427
116k
{
2428
#ifdef SYMNAME_IN_DEBUG
2429
  return SYMNAME_IN_DEBUG (sym) != 0;
2430
#else
2431
116k
  return false;
2432
116k
#endif
2433
116k
}
pei-riscv64.c:symname_in_debug_hook
Line
Count
Source
2427
135k
{
2428
#ifdef SYMNAME_IN_DEBUG
2429
  return SYMNAME_IN_DEBUG (sym) != 0;
2430
#else
2431
135k
  return false;
2432
135k
#endif
2433
135k
}
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
2427
81.7k
{
2428
81.7k
#ifdef SYMNAME_IN_DEBUG
2429
81.7k
  return SYMNAME_IN_DEBUG (sym) != 0;
2430
#else
2431
  return false;
2432
#endif
2433
81.7k
}
coff-sh.c:symname_in_debug_hook
Line
Count
Source
2427
103k
{
2428
#ifdef SYMNAME_IN_DEBUG
2429
  return SYMNAME_IN_DEBUG (sym) != 0;
2430
#else
2431
103k
  return false;
2432
103k
#endif
2433
103k
}
Unexecuted instantiation: coff-stgo32.c:symname_in_debug_hook
coff-tic30.c:symname_in_debug_hook
Line
Count
Source
2427
159k
{
2428
#ifdef SYMNAME_IN_DEBUG
2429
  return SYMNAME_IN_DEBUG (sym) != 0;
2430
#else
2431
159k
  return false;
2432
159k
#endif
2433
159k
}
Unexecuted instantiation: coff-tic4x.c:symname_in_debug_hook
coff-tic54x.c:symname_in_debug_hook
Line
Count
Source
2427
130k
{
2428
#ifdef SYMNAME_IN_DEBUG
2429
  return SYMNAME_IN_DEBUG (sym) != 0;
2430
#else
2431
130k
  return false;
2432
130k
#endif
2433
130k
}
coff-z80.c:symname_in_debug_hook
Line
Count
Source
2427
129k
{
2428
#ifdef SYMNAME_IN_DEBUG
2429
  return SYMNAME_IN_DEBUG (sym) != 0;
2430
#else
2431
129k
  return false;
2432
129k
#endif
2433
129k
}
coff-z8k.c:symname_in_debug_hook
Line
Count
Source
2427
143k
{
2428
#ifdef SYMNAME_IN_DEBUG
2429
  return SYMNAME_IN_DEBUG (sym) != 0;
2430
#else
2431
143k
  return false;
2432
143k
#endif
2433
143k
}
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
2427
103k
{
2428
#ifdef SYMNAME_IN_DEBUG
2429
  return SYMNAME_IN_DEBUG (sym) != 0;
2430
#else
2431
103k
  return false;
2432
103k
#endif
2433
103k
}
pe-mcore.c:symname_in_debug_hook
Line
Count
Source
2427
114k
{
2428
#ifdef SYMNAME_IN_DEBUG
2429
  return SYMNAME_IN_DEBUG (sym) != 0;
2430
#else
2431
114k
  return false;
2432
114k
#endif
2433
114k
}
pe-sh.c:symname_in_debug_hook
Line
Count
Source
2427
104k
{
2428
#ifdef SYMNAME_IN_DEBUG
2429
  return SYMNAME_IN_DEBUG (sym) != 0;
2430
#else
2431
104k
  return false;
2432
104k
#endif
2433
104k
}
pei-arm-wince.c:symname_in_debug_hook
Line
Count
Source
2427
50.2k
{
2428
#ifdef SYMNAME_IN_DEBUG
2429
  return SYMNAME_IN_DEBUG (sym) != 0;
2430
#else
2431
50.2k
  return false;
2432
50.2k
#endif
2433
50.2k
}
pei-arm.c:symname_in_debug_hook
Line
Count
Source
2427
46.6k
{
2428
#ifdef SYMNAME_IN_DEBUG
2429
  return SYMNAME_IN_DEBUG (sym) != 0;
2430
#else
2431
46.6k
  return false;
2432
46.6k
#endif
2433
46.6k
}
pei-mcore.c:symname_in_debug_hook
Line
Count
Source
2427
49.2k
{
2428
#ifdef SYMNAME_IN_DEBUG
2429
  return SYMNAME_IN_DEBUG (sym) != 0;
2430
#else
2431
49.2k
  return false;
2432
49.2k
#endif
2433
49.2k
}
pei-sh.c:symname_in_debug_hook
Line
Count
Source
2427
90.1k
{
2428
#ifdef SYMNAME_IN_DEBUG
2429
  return SYMNAME_IN_DEBUG (sym) != 0;
2430
#else
2431
90.1k
  return false;
2432
90.1k
#endif
2433
90.1k
}
2434
2435
#ifdef RS6000COFF_C
2436
2437
#ifdef XCOFF64
2438
#define FORCE_SYMNAMES_IN_STRINGS
2439
#endif
2440
2441
/* Handle the csect auxent of a C_EXT, C_AIX_WEAKEXT or C_HIDEXT symbol.  */
2442
2443
static bool
2444
coff_pointerize_aux_hook (bfd *abfd ATTRIBUTE_UNUSED,
2445
        combined_entry_type *table_base,
2446
        combined_entry_type *symbol,
2447
        unsigned int indaux,
2448
        combined_entry_type *aux)
2449
9.20M
{
2450
9.20M
  BFD_ASSERT (symbol->is_sym);
2451
9.20M
  int n_sclass = symbol->u.syment.n_sclass;
2452
2453
9.20M
  if (CSECT_SYM_P (n_sclass)
2454
9.20M
      && indaux + 1 == symbol->u.syment.n_numaux)
2455
49.0k
    {
2456
49.0k
      BFD_ASSERT (! aux->is_sym);
2457
49.0k
      if (SMTYP_SMTYP (aux->u.auxent.x_csect.x_smtyp) == XTY_LD
2458
49.0k
    && aux->u.auxent.x_csect.x_scnlen.u64 < obj_raw_syment_count (abfd))
2459
3.05k
  {
2460
3.05k
    aux->u.auxent.x_csect.x_scnlen.p =
2461
3.05k
      table_base + aux->u.auxent.x_csect.x_scnlen.u64;
2462
3.05k
    aux->fix_scnlen = 1;
2463
3.05k
  }
2464
2465
      /* Return TRUE to indicate that the caller should not do any
2466
   further work on this auxent.  */
2467
49.0k
      return true;
2468
49.0k
    }
2469
2470
  /* Return FALSE to indicate that this auxent should be handled by
2471
     the caller.  */
2472
9.15M
  return false;
2473
9.20M
}
coff64-rs6000.c:coff_pointerize_aux_hook
Line
Count
Source
2449
1.19M
{
2450
1.19M
  BFD_ASSERT (symbol->is_sym);
2451
1.19M
  int n_sclass = symbol->u.syment.n_sclass;
2452
2453
1.19M
  if (CSECT_SYM_P (n_sclass)
2454
1.19M
      && indaux + 1 == symbol->u.syment.n_numaux)
2455
1.93k
    {
2456
1.93k
      BFD_ASSERT (! aux->is_sym);
2457
1.93k
      if (SMTYP_SMTYP (aux->u.auxent.x_csect.x_smtyp) == XTY_LD
2458
1.93k
    && aux->u.auxent.x_csect.x_scnlen.u64 < obj_raw_syment_count (abfd))
2459
0
  {
2460
0
    aux->u.auxent.x_csect.x_scnlen.p =
2461
0
      table_base + aux->u.auxent.x_csect.x_scnlen.u64;
2462
0
    aux->fix_scnlen = 1;
2463
0
  }
2464
2465
      /* Return TRUE to indicate that the caller should not do any
2466
   further work on this auxent.  */
2467
1.93k
      return true;
2468
1.93k
    }
2469
2470
  /* Return FALSE to indicate that this auxent should be handled by
2471
     the caller.  */
2472
1.18M
  return false;
2473
1.19M
}
coff-rs6000.c:coff_pointerize_aux_hook
Line
Count
Source
2449
8.01M
{
2450
8.01M
  BFD_ASSERT (symbol->is_sym);
2451
8.01M
  int n_sclass = symbol->u.syment.n_sclass;
2452
2453
8.01M
  if (CSECT_SYM_P (n_sclass)
2454
8.01M
      && indaux + 1 == symbol->u.syment.n_numaux)
2455
47.0k
    {
2456
47.0k
      BFD_ASSERT (! aux->is_sym);
2457
47.0k
      if (SMTYP_SMTYP (aux->u.auxent.x_csect.x_smtyp) == XTY_LD
2458
47.0k
    && aux->u.auxent.x_csect.x_scnlen.u64 < obj_raw_syment_count (abfd))
2459
3.05k
  {
2460
3.05k
    aux->u.auxent.x_csect.x_scnlen.p =
2461
3.05k
      table_base + aux->u.auxent.x_csect.x_scnlen.u64;
2462
3.05k
    aux->fix_scnlen = 1;
2463
3.05k
  }
2464
2465
      /* Return TRUE to indicate that the caller should not do any
2466
   further work on this auxent.  */
2467
47.0k
      return true;
2468
47.0k
    }
2469
2470
  /* Return FALSE to indicate that this auxent should be handled by
2471
     the caller.  */
2472
7.96M
  return false;
2473
8.01M
}
2474
2475
#else
2476
#define coff_pointerize_aux_hook 0
2477
#endif /* ! RS6000COFF_C */
2478
2479
/* Print an aux entry.  This returns TRUE if it has printed it.  */
2480
2481
static bool
2482
coff_print_aux (bfd *abfd ATTRIBUTE_UNUSED,
2483
    FILE *file ATTRIBUTE_UNUSED,
2484
    combined_entry_type *table_base ATTRIBUTE_UNUSED,
2485
    combined_entry_type *symbol ATTRIBUTE_UNUSED,
2486
    combined_entry_type *aux ATTRIBUTE_UNUSED,
2487
    unsigned int indaux ATTRIBUTE_UNUSED)
2488
0
{
2489
0
  BFD_ASSERT (symbol->is_sym);
2490
0
  BFD_ASSERT (! aux->is_sym);
2491
#ifdef RS6000COFF_C
2492
0
  if (CSECT_SYM_P (symbol->u.syment.n_sclass)
2493
0
      && indaux + 1 == symbol->u.syment.n_numaux)
2494
0
    {
2495
      /* This is a csect entry.  */
2496
0
      fprintf (file, "AUX ");
2497
0
      if (SMTYP_SMTYP (aux->u.auxent.x_csect.x_smtyp) != XTY_LD)
2498
0
  {
2499
0
    BFD_ASSERT (! aux->fix_scnlen);
2500
0
    fprintf (file, "val %5" PRIu64,
2501
0
       aux->u.auxent.x_csect.x_scnlen.u64);
2502
0
  }
2503
0
      else
2504
0
  {
2505
0
    fprintf (file, "indx ");
2506
0
    if (! aux->fix_scnlen)
2507
0
      fprintf (file, "%4" PRIu64,
2508
0
         aux->u.auxent.x_csect.x_scnlen.u64);
2509
0
    else
2510
0
      fprintf (file, "%4ld",
2511
0
         (long) (aux->u.auxent.x_csect.x_scnlen.p - table_base));
2512
0
  }
2513
0
      fprintf (file,
2514
0
         " prmhsh %u snhsh %u typ %d algn %d clss %u stb %u snstb %u",
2515
0
         aux->u.auxent.x_csect.x_parmhash,
2516
0
         (unsigned int) aux->u.auxent.x_csect.x_snhash,
2517
0
         SMTYP_SMTYP (aux->u.auxent.x_csect.x_smtyp),
2518
0
         SMTYP_ALIGN (aux->u.auxent.x_csect.x_smtyp),
2519
0
         (unsigned int) aux->u.auxent.x_csect.x_smclas,
2520
0
         aux->u.auxent.x_csect.x_stab,
2521
0
         (unsigned int) aux->u.auxent.x_csect.x_snstab);
2522
0
      return true;
2523
0
    }
2524
0
#endif
2525
2526
  /* Return FALSE to indicate that no special action was taken.  */
2527
0
  return false;
2528
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: pei-riscv64.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
2529
2530
/*
2531
SUBSUBSECTION
2532
  Writing relocations
2533
2534
  To write relocations, the back end steps though the
2535
  canonical relocation table and create an
2536
  @code{internal_reloc}. The symbol index to use is removed from
2537
  the @code{offset} field in the symbol table supplied.  The
2538
  address comes directly from the sum of the section base
2539
  address and the relocation offset; the type is dug directly
2540
  from the howto field.  Then the @code{internal_reloc} is
2541
  swapped into the shape of an @code{external_reloc} and written
2542
  out to disk.
2543
2544
*/
2545
2546
#ifdef TARG_AUX
2547
2548
2549
/* AUX's ld wants relocations to be sorted.  */
2550
static int
2551
compare_arelent_ptr (const void * x, const void * y)
2552
{
2553
  const arelent **a = (const arelent **) x;
2554
  const arelent **b = (const arelent **) y;
2555
  bfd_size_type aadr = (*a)->address;
2556
  bfd_size_type badr = (*b)->address;
2557
2558
  return (aadr < badr ? -1 : badr < aadr ? 1 : 0);
2559
}
2560
2561
#endif /* TARG_AUX */
2562
2563
static bool
2564
coff_write_relocs (bfd * abfd, int first_undef)
2565
6
{
2566
6
  asection *s;
2567
2568
436
  for (s = abfd->sections; s != NULL; s = s->next)
2569
430
    {
2570
430
      unsigned int i;
2571
430
      struct external_reloc dst;
2572
430
      arelent **p;
2573
2574
430
#ifndef TARG_AUX
2575
430
      p = s->orelocation;
2576
#else
2577
      {
2578
  /* Sort relocations before we write them out.  */
2579
  bfd_size_type amt;
2580
2581
  amt = s->reloc_count;
2582
  amt *= sizeof (arelent *);
2583
  p = bfd_malloc (amt);
2584
  if (p == NULL)
2585
    {
2586
      if (s->reloc_count > 0)
2587
        return false;
2588
    }
2589
  else
2590
    {
2591
      memcpy (p, s->orelocation, (size_t) amt);
2592
      qsort (p, s->reloc_count, sizeof (arelent *), compare_arelent_ptr);
2593
    }
2594
      }
2595
#endif
2596
2597
430
      if (bfd_seek (abfd, s->rel_filepos, SEEK_SET) != 0)
2598
0
  return false;
2599
2600
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
2601
164
      if ((obj_pe (abfd) || obj_go32 (abfd)) && s->reloc_count >= 0xffff)
2602
0
  {
2603
    /* Encode real count here as first reloc.  */
2604
0
    struct internal_reloc n;
2605
2606
0
    memset (& n, 0, sizeof (n));
2607
    /* Add one to count *this* reloc (grr).  */
2608
0
    n.r_vaddr = s->reloc_count + 1;
2609
0
    coff_swap_reloc_out (abfd, &n, &dst);
2610
0
    if (bfd_write (&dst, bfd_coff_relsz (abfd), abfd)
2611
0
        != bfd_coff_relsz (abfd))
2612
0
      return false;
2613
0
  }
2614
164
#endif
2615
2616
430
      for (i = 0; i < s->reloc_count; i++)
2617
0
  {
2618
0
    struct internal_reloc n;
2619
0
    arelent *q = p[i];
2620
2621
0
    memset (& n, 0, sizeof (n));
2622
2623
    /* Now we've renumbered the symbols we know where the
2624
       undefined symbols live in the table.  Check the reloc
2625
       entries for symbols who's output bfd isn't the right one.
2626
       This is because the symbol was undefined (which means
2627
       that all the pointers are never made to point to the same
2628
       place). This is a bad thing,'cause the symbols attached
2629
       to the output bfd are indexed, so that the relocation
2630
       entries know which symbol index they point to.  So we
2631
       have to look up the output symbol here.  */
2632
2633
0
    if (q->sym_ptr_ptr[0] != NULL && q->sym_ptr_ptr[0]->the_bfd != abfd)
2634
0
      {
2635
0
        int j;
2636
0
        const char *sname = q->sym_ptr_ptr[0]->name;
2637
0
        asymbol **outsyms = abfd->outsymbols;
2638
2639
0
        for (j = first_undef; outsyms[j]; j++)
2640
0
    {
2641
0
      const char *intable = outsyms[j]->name;
2642
2643
0
      if (strcmp (intable, sname) == 0)
2644
0
        {
2645
          /* Got a hit, so repoint the reloc.  */
2646
0
          q->sym_ptr_ptr = outsyms + j;
2647
0
          break;
2648
0
        }
2649
0
    }
2650
0
      }
2651
2652
0
    n.r_vaddr = q->address + s->vma;
2653
2654
#ifdef R_IHCONST
2655
    /* The 29k const/consth reloc pair is a real kludge.  The consth
2656
       part doesn't have a symbol; it has an offset.  So rebuilt
2657
       that here.  */
2658
    if (q->howto->type == R_IHCONST)
2659
      n.r_symndx = q->addend;
2660
    else
2661
#endif
2662
0
      if (q->sym_ptr_ptr && q->sym_ptr_ptr[0] != NULL)
2663
0
        {
2664
#ifdef SECTION_RELATIVE_ABSOLUTE_SYMBOL_P
2665
0
    if (SECTION_RELATIVE_ABSOLUTE_SYMBOL_P (q, s))
2666
#else
2667
0
    if ((*q->sym_ptr_ptr)->section == bfd_abs_section_ptr
2668
0
        && ((*q->sym_ptr_ptr)->flags & BSF_SECTION_SYM) != 0)
2669
0
#endif
2670
      /* This is a relocation relative to the absolute symbol.  */
2671
0
      n.r_symndx = -1;
2672
0
    else
2673
0
      {
2674
0
        n.r_symndx = get_index ((*(q->sym_ptr_ptr)));
2675
        /* Check to see if the symbol reloc points to a symbol
2676
           we don't have in our symbol table.  */
2677
0
        if (n.r_symndx > obj_conv_table_size (abfd))
2678
0
          {
2679
0
      bfd_set_error (bfd_error_bad_value);
2680
      /* xgettext:c-format */
2681
0
      _bfd_error_handler (_("%pB: reloc against a non-existent"
2682
0
                " symbol index: %ld"),
2683
0
              abfd, n.r_symndx);
2684
0
      return false;
2685
0
          }
2686
0
      }
2687
0
        }
2688
2689
#ifdef SWAP_OUT_RELOC_OFFSET
2690
0
    n.r_offset = q->addend;
2691
0
#endif
2692
2693
#ifdef SELECT_RELOC
2694
    /* Work out reloc type from what is required.  */
2695
0
    if (q->howto)
2696
0
      SELECT_RELOC (n, q->howto);
2697
#else
2698
0
    if (q->howto)
2699
0
      n.r_type = q->howto->type;
2700
#endif
2701
0
    coff_swap_reloc_out (abfd, &n, &dst);
2702
2703
0
    if (bfd_write (&dst, bfd_coff_relsz (abfd), abfd)
2704
0
        != bfd_coff_relsz (abfd))
2705
0
      return false;
2706
0
  }
2707
2708
#ifdef TARG_AUX
2709
      free (p);
2710
#endif
2711
430
    }
2712
2713
6
  return true;
2714
6
}
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
2565
1
{
2566
1
  asection *s;
2567
2568
22
  for (s = abfd->sections; s != NULL; s = s->next)
2569
21
    {
2570
21
      unsigned int i;
2571
21
      struct external_reloc dst;
2572
21
      arelent **p;
2573
2574
21
#ifndef TARG_AUX
2575
21
      p = s->orelocation;
2576
#else
2577
      {
2578
  /* Sort relocations before we write them out.  */
2579
  bfd_size_type amt;
2580
2581
  amt = s->reloc_count;
2582
  amt *= sizeof (arelent *);
2583
  p = bfd_malloc (amt);
2584
  if (p == NULL)
2585
    {
2586
      if (s->reloc_count > 0)
2587
        return false;
2588
    }
2589
  else
2590
    {
2591
      memcpy (p, s->orelocation, (size_t) amt);
2592
      qsort (p, s->reloc_count, sizeof (arelent *), compare_arelent_ptr);
2593
    }
2594
      }
2595
#endif
2596
2597
21
      if (bfd_seek (abfd, s->rel_filepos, SEEK_SET) != 0)
2598
0
  return false;
2599
2600
21
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
2601
21
      if ((obj_pe (abfd) || obj_go32 (abfd)) && s->reloc_count >= 0xffff)
2602
0
  {
2603
    /* Encode real count here as first reloc.  */
2604
0
    struct internal_reloc n;
2605
2606
0
    memset (& n, 0, sizeof (n));
2607
    /* Add one to count *this* reloc (grr).  */
2608
0
    n.r_vaddr = s->reloc_count + 1;
2609
0
    coff_swap_reloc_out (abfd, &n, &dst);
2610
0
    if (bfd_write (&dst, bfd_coff_relsz (abfd), abfd)
2611
0
        != bfd_coff_relsz (abfd))
2612
0
      return false;
2613
0
  }
2614
21
#endif
2615
2616
21
      for (i = 0; i < s->reloc_count; i++)
2617
0
  {
2618
0
    struct internal_reloc n;
2619
0
    arelent *q = p[i];
2620
2621
0
    memset (& n, 0, sizeof (n));
2622
2623
    /* Now we've renumbered the symbols we know where the
2624
       undefined symbols live in the table.  Check the reloc
2625
       entries for symbols who's output bfd isn't the right one.
2626
       This is because the symbol was undefined (which means
2627
       that all the pointers are never made to point to the same
2628
       place). This is a bad thing,'cause the symbols attached
2629
       to the output bfd are indexed, so that the relocation
2630
       entries know which symbol index they point to.  So we
2631
       have to look up the output symbol here.  */
2632
2633
0
    if (q->sym_ptr_ptr[0] != NULL && q->sym_ptr_ptr[0]->the_bfd != abfd)
2634
0
      {
2635
0
        int j;
2636
0
        const char *sname = q->sym_ptr_ptr[0]->name;
2637
0
        asymbol **outsyms = abfd->outsymbols;
2638
2639
0
        for (j = first_undef; outsyms[j]; j++)
2640
0
    {
2641
0
      const char *intable = outsyms[j]->name;
2642
2643
0
      if (strcmp (intable, sname) == 0)
2644
0
        {
2645
          /* Got a hit, so repoint the reloc.  */
2646
0
          q->sym_ptr_ptr = outsyms + j;
2647
0
          break;
2648
0
        }
2649
0
    }
2650
0
      }
2651
2652
0
    n.r_vaddr = q->address + s->vma;
2653
2654
#ifdef R_IHCONST
2655
    /* The 29k const/consth reloc pair is a real kludge.  The consth
2656
       part doesn't have a symbol; it has an offset.  So rebuilt
2657
       that here.  */
2658
    if (q->howto->type == R_IHCONST)
2659
      n.r_symndx = q->addend;
2660
    else
2661
#endif
2662
0
      if (q->sym_ptr_ptr && q->sym_ptr_ptr[0] != NULL)
2663
0
        {
2664
#ifdef SECTION_RELATIVE_ABSOLUTE_SYMBOL_P
2665
    if (SECTION_RELATIVE_ABSOLUTE_SYMBOL_P (q, s))
2666
#else
2667
0
    if ((*q->sym_ptr_ptr)->section == bfd_abs_section_ptr
2668
0
        && ((*q->sym_ptr_ptr)->flags & BSF_SECTION_SYM) != 0)
2669
0
#endif
2670
      /* This is a relocation relative to the absolute symbol.  */
2671
0
      n.r_symndx = -1;
2672
0
    else
2673
0
      {
2674
0
        n.r_symndx = get_index ((*(q->sym_ptr_ptr)));
2675
        /* Check to see if the symbol reloc points to a symbol
2676
           we don't have in our symbol table.  */
2677
0
        if (n.r_symndx > obj_conv_table_size (abfd))
2678
0
          {
2679
0
      bfd_set_error (bfd_error_bad_value);
2680
      /* xgettext:c-format */
2681
0
      _bfd_error_handler (_("%pB: reloc against a non-existent"
2682
0
                " symbol index: %ld"),
2683
0
              abfd, n.r_symndx);
2684
0
      return false;
2685
0
          }
2686
0
      }
2687
0
        }
2688
2689
#ifdef SWAP_OUT_RELOC_OFFSET
2690
    n.r_offset = q->addend;
2691
#endif
2692
2693
0
#ifdef SELECT_RELOC
2694
    /* Work out reloc type from what is required.  */
2695
0
    if (q->howto)
2696
0
      SELECT_RELOC (n, q->howto);
2697
#else
2698
    if (q->howto)
2699
      n.r_type = q->howto->type;
2700
#endif
2701
0
    coff_swap_reloc_out (abfd, &n, &dst);
2702
2703
0
    if (bfd_write (&dst, bfd_coff_relsz (abfd), abfd)
2704
0
        != bfd_coff_relsz (abfd))
2705
0
      return false;
2706
0
  }
2707
2708
#ifdef TARG_AUX
2709
      free (p);
2710
#endif
2711
21
    }
2712
2713
1
  return true;
2714
1
}
coff-x86_64.c:coff_write_relocs
Line
Count
Source
2565
1
{
2566
1
  asection *s;
2567
2568
267
  for (s = abfd->sections; s != NULL; s = s->next)
2569
266
    {
2570
266
      unsigned int i;
2571
266
      struct external_reloc dst;
2572
266
      arelent **p;
2573
2574
266
#ifndef TARG_AUX
2575
266
      p = s->orelocation;
2576
#else
2577
      {
2578
  /* Sort relocations before we write them out.  */
2579
  bfd_size_type amt;
2580
2581
  amt = s->reloc_count;
2582
  amt *= sizeof (arelent *);
2583
  p = bfd_malloc (amt);
2584
  if (p == NULL)
2585
    {
2586
      if (s->reloc_count > 0)
2587
        return false;
2588
    }
2589
  else
2590
    {
2591
      memcpy (p, s->orelocation, (size_t) amt);
2592
      qsort (p, s->reloc_count, sizeof (arelent *), compare_arelent_ptr);
2593
    }
2594
      }
2595
#endif
2596
2597
266
      if (bfd_seek (abfd, s->rel_filepos, SEEK_SET) != 0)
2598
0
  return false;
2599
2600
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
2601
      if ((obj_pe (abfd) || obj_go32 (abfd)) && s->reloc_count >= 0xffff)
2602
  {
2603
    /* Encode real count here as first reloc.  */
2604
    struct internal_reloc n;
2605
2606
    memset (& n, 0, sizeof (n));
2607
    /* Add one to count *this* reloc (grr).  */
2608
    n.r_vaddr = s->reloc_count + 1;
2609
    coff_swap_reloc_out (abfd, &n, &dst);
2610
    if (bfd_write (&dst, bfd_coff_relsz (abfd), abfd)
2611
        != bfd_coff_relsz (abfd))
2612
      return false;
2613
  }
2614
#endif
2615
2616
266
      for (i = 0; i < s->reloc_count; i++)
2617
0
  {
2618
0
    struct internal_reloc n;
2619
0
    arelent *q = p[i];
2620
2621
0
    memset (& n, 0, sizeof (n));
2622
2623
    /* Now we've renumbered the symbols we know where the
2624
       undefined symbols live in the table.  Check the reloc
2625
       entries for symbols who's output bfd isn't the right one.
2626
       This is because the symbol was undefined (which means
2627
       that all the pointers are never made to point to the same
2628
       place). This is a bad thing,'cause the symbols attached
2629
       to the output bfd are indexed, so that the relocation
2630
       entries know which symbol index they point to.  So we
2631
       have to look up the output symbol here.  */
2632
2633
0
    if (q->sym_ptr_ptr[0] != NULL && q->sym_ptr_ptr[0]->the_bfd != abfd)
2634
0
      {
2635
0
        int j;
2636
0
        const char *sname = q->sym_ptr_ptr[0]->name;
2637
0
        asymbol **outsyms = abfd->outsymbols;
2638
2639
0
        for (j = first_undef; outsyms[j]; j++)
2640
0
    {
2641
0
      const char *intable = outsyms[j]->name;
2642
2643
0
      if (strcmp (intable, sname) == 0)
2644
0
        {
2645
          /* Got a hit, so repoint the reloc.  */
2646
0
          q->sym_ptr_ptr = outsyms + j;
2647
0
          break;
2648
0
        }
2649
0
    }
2650
0
      }
2651
2652
0
    n.r_vaddr = q->address + s->vma;
2653
2654
#ifdef R_IHCONST
2655
    /* The 29k const/consth reloc pair is a real kludge.  The consth
2656
       part doesn't have a symbol; it has an offset.  So rebuilt
2657
       that here.  */
2658
    if (q->howto->type == R_IHCONST)
2659
      n.r_symndx = q->addend;
2660
    else
2661
#endif
2662
0
      if (q->sym_ptr_ptr && q->sym_ptr_ptr[0] != NULL)
2663
0
        {
2664
#ifdef SECTION_RELATIVE_ABSOLUTE_SYMBOL_P
2665
    if (SECTION_RELATIVE_ABSOLUTE_SYMBOL_P (q, s))
2666
#else
2667
0
    if ((*q->sym_ptr_ptr)->section == bfd_abs_section_ptr
2668
0
        && ((*q->sym_ptr_ptr)->flags & BSF_SECTION_SYM) != 0)
2669
0
#endif
2670
      /* This is a relocation relative to the absolute symbol.  */
2671
0
      n.r_symndx = -1;
2672
0
    else
2673
0
      {
2674
0
        n.r_symndx = get_index ((*(q->sym_ptr_ptr)));
2675
        /* Check to see if the symbol reloc points to a symbol
2676
           we don't have in our symbol table.  */
2677
0
        if (n.r_symndx > obj_conv_table_size (abfd))
2678
0
          {
2679
0
      bfd_set_error (bfd_error_bad_value);
2680
      /* xgettext:c-format */
2681
0
      _bfd_error_handler (_("%pB: reloc against a non-existent"
2682
0
                " symbol index: %ld"),
2683
0
              abfd, n.r_symndx);
2684
0
      return false;
2685
0
          }
2686
0
      }
2687
0
        }
2688
2689
#ifdef SWAP_OUT_RELOC_OFFSET
2690
    n.r_offset = q->addend;
2691
#endif
2692
2693
0
#ifdef SELECT_RELOC
2694
    /* Work out reloc type from what is required.  */
2695
0
    if (q->howto)
2696
0
      SELECT_RELOC (n, q->howto);
2697
#else
2698
    if (q->howto)
2699
      n.r_type = q->howto->type;
2700
#endif
2701
0
    coff_swap_reloc_out (abfd, &n, &dst);
2702
2703
0
    if (bfd_write (&dst, bfd_coff_relsz (abfd), abfd)
2704
0
        != bfd_coff_relsz (abfd))
2705
0
      return false;
2706
0
  }
2707
2708
#ifdef TARG_AUX
2709
      free (p);
2710
#endif
2711
266
    }
2712
2713
1
  return true;
2714
1
}
Unexecuted instantiation: coff64-rs6000.c:coff_write_relocs
Unexecuted instantiation: pe-aarch64.c:coff_write_relocs
pei-aarch64.c:coff_write_relocs
Line
Count
Source
2565
1
{
2566
1
  asection *s;
2567
2568
132
  for (s = abfd->sections; s != NULL; s = s->next)
2569
131
    {
2570
131
      unsigned int i;
2571
131
      struct external_reloc dst;
2572
131
      arelent **p;
2573
2574
131
#ifndef TARG_AUX
2575
131
      p = s->orelocation;
2576
#else
2577
      {
2578
  /* Sort relocations before we write them out.  */
2579
  bfd_size_type amt;
2580
2581
  amt = s->reloc_count;
2582
  amt *= sizeof (arelent *);
2583
  p = bfd_malloc (amt);
2584
  if (p == NULL)
2585
    {
2586
      if (s->reloc_count > 0)
2587
        return false;
2588
    }
2589
  else
2590
    {
2591
      memcpy (p, s->orelocation, (size_t) amt);
2592
      qsort (p, s->reloc_count, sizeof (arelent *), compare_arelent_ptr);
2593
    }
2594
      }
2595
#endif
2596
2597
131
      if (bfd_seek (abfd, s->rel_filepos, SEEK_SET) != 0)
2598
0
  return false;
2599
2600
131
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
2601
131
      if ((obj_pe (abfd) || obj_go32 (abfd)) && s->reloc_count >= 0xffff)
2602
0
  {
2603
    /* Encode real count here as first reloc.  */
2604
0
    struct internal_reloc n;
2605
2606
0
    memset (& n, 0, sizeof (n));
2607
    /* Add one to count *this* reloc (grr).  */
2608
0
    n.r_vaddr = s->reloc_count + 1;
2609
0
    coff_swap_reloc_out (abfd, &n, &dst);
2610
0
    if (bfd_write (&dst, bfd_coff_relsz (abfd), abfd)
2611
0
        != bfd_coff_relsz (abfd))
2612
0
      return false;
2613
0
  }
2614
131
#endif
2615
2616
131
      for (i = 0; i < s->reloc_count; i++)
2617
0
  {
2618
0
    struct internal_reloc n;
2619
0
    arelent *q = p[i];
2620
2621
0
    memset (& n, 0, sizeof (n));
2622
2623
    /* Now we've renumbered the symbols we know where the
2624
       undefined symbols live in the table.  Check the reloc
2625
       entries for symbols who's output bfd isn't the right one.
2626
       This is because the symbol was undefined (which means
2627
       that all the pointers are never made to point to the same
2628
       place). This is a bad thing,'cause the symbols attached
2629
       to the output bfd are indexed, so that the relocation
2630
       entries know which symbol index they point to.  So we
2631
       have to look up the output symbol here.  */
2632
2633
0
    if (q->sym_ptr_ptr[0] != NULL && q->sym_ptr_ptr[0]->the_bfd != abfd)
2634
0
      {
2635
0
        int j;
2636
0
        const char *sname = q->sym_ptr_ptr[0]->name;
2637
0
        asymbol **outsyms = abfd->outsymbols;
2638
2639
0
        for (j = first_undef; outsyms[j]; j++)
2640
0
    {
2641
0
      const char *intable = outsyms[j]->name;
2642
2643
0
      if (strcmp (intable, sname) == 0)
2644
0
        {
2645
          /* Got a hit, so repoint the reloc.  */
2646
0
          q->sym_ptr_ptr = outsyms + j;
2647
0
          break;
2648
0
        }
2649
0
    }
2650
0
      }
2651
2652
0
    n.r_vaddr = q->address + s->vma;
2653
2654
#ifdef R_IHCONST
2655
    /* The 29k const/consth reloc pair is a real kludge.  The consth
2656
       part doesn't have a symbol; it has an offset.  So rebuilt
2657
       that here.  */
2658
    if (q->howto->type == R_IHCONST)
2659
      n.r_symndx = q->addend;
2660
    else
2661
#endif
2662
0
      if (q->sym_ptr_ptr && q->sym_ptr_ptr[0] != NULL)
2663
0
        {
2664
#ifdef SECTION_RELATIVE_ABSOLUTE_SYMBOL_P
2665
    if (SECTION_RELATIVE_ABSOLUTE_SYMBOL_P (q, s))
2666
#else
2667
0
    if ((*q->sym_ptr_ptr)->section == bfd_abs_section_ptr
2668
0
        && ((*q->sym_ptr_ptr)->flags & BSF_SECTION_SYM) != 0)
2669
0
#endif
2670
      /* This is a relocation relative to the absolute symbol.  */
2671
0
      n.r_symndx = -1;
2672
0
    else
2673
0
      {
2674
0
        n.r_symndx = get_index ((*(q->sym_ptr_ptr)));
2675
        /* Check to see if the symbol reloc points to a symbol
2676
           we don't have in our symbol table.  */
2677
0
        if (n.r_symndx > obj_conv_table_size (abfd))
2678
0
          {
2679
0
      bfd_set_error (bfd_error_bad_value);
2680
      /* xgettext:c-format */
2681
0
      _bfd_error_handler (_("%pB: reloc against a non-existent"
2682
0
                " symbol index: %ld"),
2683
0
              abfd, n.r_symndx);
2684
0
      return false;
2685
0
          }
2686
0
      }
2687
0
        }
2688
2689
#ifdef SWAP_OUT_RELOC_OFFSET
2690
    n.r_offset = q->addend;
2691
#endif
2692
2693
0
#ifdef SELECT_RELOC
2694
    /* Work out reloc type from what is required.  */
2695
0
    if (q->howto)
2696
0
      SELECT_RELOC (n, q->howto);
2697
#else
2698
    if (q->howto)
2699
      n.r_type = q->howto->type;
2700
#endif
2701
0
    coff_swap_reloc_out (abfd, &n, &dst);
2702
2703
0
    if (bfd_write (&dst, bfd_coff_relsz (abfd), abfd)
2704
0
        != bfd_coff_relsz (abfd))
2705
0
      return false;
2706
0
  }
2707
2708
#ifdef TARG_AUX
2709
      free (p);
2710
#endif
2711
131
    }
2712
2713
1
  return true;
2714
1
}
Unexecuted instantiation: pei-ia64.c:coff_write_relocs
Unexecuted instantiation: pei-loongarch64.c:coff_write_relocs
pei-riscv64.c:coff_write_relocs
Line
Count
Source
2565
3
{
2566
3
  asection *s;
2567
2568
15
  for (s = abfd->sections; s != NULL; s = s->next)
2569
12
    {
2570
12
      unsigned int i;
2571
12
      struct external_reloc dst;
2572
12
      arelent **p;
2573
2574
12
#ifndef TARG_AUX
2575
12
      p = s->orelocation;
2576
#else
2577
      {
2578
  /* Sort relocations before we write them out.  */
2579
  bfd_size_type amt;
2580
2581
  amt = s->reloc_count;
2582
  amt *= sizeof (arelent *);
2583
  p = bfd_malloc (amt);
2584
  if (p == NULL)
2585
    {
2586
      if (s->reloc_count > 0)
2587
        return false;
2588
    }
2589
  else
2590
    {
2591
      memcpy (p, s->orelocation, (size_t) amt);
2592
      qsort (p, s->reloc_count, sizeof (arelent *), compare_arelent_ptr);
2593
    }
2594
      }
2595
#endif
2596
2597
12
      if (bfd_seek (abfd, s->rel_filepos, SEEK_SET) != 0)
2598
0
  return false;
2599
2600
12
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
2601
12
      if ((obj_pe (abfd) || obj_go32 (abfd)) && s->reloc_count >= 0xffff)
2602
0
  {
2603
    /* Encode real count here as first reloc.  */
2604
0
    struct internal_reloc n;
2605
2606
0
    memset (& n, 0, sizeof (n));
2607
    /* Add one to count *this* reloc (grr).  */
2608
0
    n.r_vaddr = s->reloc_count + 1;
2609
0
    coff_swap_reloc_out (abfd, &n, &dst);
2610
0
    if (bfd_write (&dst, bfd_coff_relsz (abfd), abfd)
2611
0
        != bfd_coff_relsz (abfd))
2612
0
      return false;
2613
0
  }
2614
12
#endif
2615
2616
12
      for (i = 0; i < s->reloc_count; i++)
2617
0
  {
2618
0
    struct internal_reloc n;
2619
0
    arelent *q = p[i];
2620
2621
0
    memset (& n, 0, sizeof (n));
2622
2623
    /* Now we've renumbered the symbols we know where the
2624
       undefined symbols live in the table.  Check the reloc
2625
       entries for symbols who's output bfd isn't the right one.
2626
       This is because the symbol was undefined (which means
2627
       that all the pointers are never made to point to the same
2628
       place). This is a bad thing,'cause the symbols attached
2629
       to the output bfd are indexed, so that the relocation
2630
       entries know which symbol index they point to.  So we
2631
       have to look up the output symbol here.  */
2632
2633
0
    if (q->sym_ptr_ptr[0] != NULL && q->sym_ptr_ptr[0]->the_bfd != abfd)
2634
0
      {
2635
0
        int j;
2636
0
        const char *sname = q->sym_ptr_ptr[0]->name;
2637
0
        asymbol **outsyms = abfd->outsymbols;
2638
2639
0
        for (j = first_undef; outsyms[j]; j++)
2640
0
    {
2641
0
      const char *intable = outsyms[j]->name;
2642
2643
0
      if (strcmp (intable, sname) == 0)
2644
0
        {
2645
          /* Got a hit, so repoint the reloc.  */
2646
0
          q->sym_ptr_ptr = outsyms + j;
2647
0
          break;
2648
0
        }
2649
0
    }
2650
0
      }
2651
2652
0
    n.r_vaddr = q->address + s->vma;
2653
2654
#ifdef R_IHCONST
2655
    /* The 29k const/consth reloc pair is a real kludge.  The consth
2656
       part doesn't have a symbol; it has an offset.  So rebuilt
2657
       that here.  */
2658
    if (q->howto->type == R_IHCONST)
2659
      n.r_symndx = q->addend;
2660
    else
2661
#endif
2662
0
      if (q->sym_ptr_ptr && q->sym_ptr_ptr[0] != NULL)
2663
0
        {
2664
#ifdef SECTION_RELATIVE_ABSOLUTE_SYMBOL_P
2665
    if (SECTION_RELATIVE_ABSOLUTE_SYMBOL_P (q, s))
2666
#else
2667
0
    if ((*q->sym_ptr_ptr)->section == bfd_abs_section_ptr
2668
0
        && ((*q->sym_ptr_ptr)->flags & BSF_SECTION_SYM) != 0)
2669
0
#endif
2670
      /* This is a relocation relative to the absolute symbol.  */
2671
0
      n.r_symndx = -1;
2672
0
    else
2673
0
      {
2674
0
        n.r_symndx = get_index ((*(q->sym_ptr_ptr)));
2675
        /* Check to see if the symbol reloc points to a symbol
2676
           we don't have in our symbol table.  */
2677
0
        if (n.r_symndx > obj_conv_table_size (abfd))
2678
0
          {
2679
0
      bfd_set_error (bfd_error_bad_value);
2680
      /* xgettext:c-format */
2681
0
      _bfd_error_handler (_("%pB: reloc against a non-existent"
2682
0
                " symbol index: %ld"),
2683
0
              abfd, n.r_symndx);
2684
0
      return false;
2685
0
          }
2686
0
      }
2687
0
        }
2688
2689
0
#ifdef SWAP_OUT_RELOC_OFFSET
2690
0
    n.r_offset = q->addend;
2691
0
#endif
2692
2693
#ifdef SELECT_RELOC
2694
    /* Work out reloc type from what is required.  */
2695
    if (q->howto)
2696
      SELECT_RELOC (n, q->howto);
2697
#else
2698
0
    if (q->howto)
2699
0
      n.r_type = q->howto->type;
2700
0
#endif
2701
0
    coff_swap_reloc_out (abfd, &n, &dst);
2702
2703
0
    if (bfd_write (&dst, bfd_coff_relsz (abfd), abfd)
2704
0
        != bfd_coff_relsz (abfd))
2705
0
      return false;
2706
0
  }
2707
2708
#ifdef TARG_AUX
2709
      free (p);
2710
#endif
2711
12
    }
2712
2713
3
  return true;
2714
3
}
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
Unexecuted instantiation: pe-i386.c:coff_write_relocs
Unexecuted instantiation: pe-mcore.c:coff_write_relocs
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
2715
2716
/* Set flags and magic number of a coff file from architecture and machine
2717
   type.  Result is TRUE if we can represent the arch&type, FALSE if not.  */
2718
2719
static bool
2720
coff_set_flags (bfd * abfd,
2721
    unsigned int *magicp ATTRIBUTE_UNUSED,
2722
    unsigned short *flagsp ATTRIBUTE_UNUSED)
2723
2.65k
{
2724
2.65k
  switch (bfd_get_arch (abfd))
2725
2.65k
    {
2726
#ifdef Z80MAGIC
2727
85
    case bfd_arch_z80:
2728
85
      *magicp = Z80MAGIC;
2729
85
      switch (bfd_get_mach (abfd))
2730
85
  {
2731
4
  case bfd_mach_z80strict:
2732
6
  case bfd_mach_z80:
2733
22
  case bfd_mach_z80n:
2734
24
  case bfd_mach_z80full:
2735
24
  case bfd_mach_r800:
2736
24
  case bfd_mach_gbz80:
2737
24
  case bfd_mach_z180:
2738
85
  case bfd_mach_ez80_z80:
2739
85
  case bfd_mach_ez80_adl:
2740
85
    *flagsp = bfd_get_mach (abfd) << 12;
2741
85
    break;
2742
0
  default:
2743
0
    return false;
2744
85
  }
2745
85
      return true;
2746
0
#endif
2747
2748
#ifdef Z8KMAGIC
2749
153
    case bfd_arch_z8k:
2750
153
      *magicp = Z8KMAGIC;
2751
2752
153
      switch (bfd_get_mach (abfd))
2753
153
  {
2754
128
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2755
25
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2756
0
  default:       return false;
2757
153
  }
2758
153
      return true;
2759
0
#endif
2760
2761
#ifdef TIC30MAGIC
2762
114
    case bfd_arch_tic30:
2763
114
      *magicp = TIC30MAGIC;
2764
114
      return true;
2765
0
#endif
2766
2767
#ifdef TICOFF_DEFAULT_MAGIC
2768
140
    case TICOFF_TARGET_ARCH:
2769
      /* If there's no indication of which version we want, use the default.  */
2770
140
      if (!abfd->xvec )
2771
0
  *magicp = TICOFF_DEFAULT_MAGIC;
2772
140
      else
2773
140
  {
2774
    /* We may want to output in a different COFF version.  */
2775
140
    switch (abfd->xvec->name[4])
2776
140
      {
2777
140
      case '0':
2778
140
        *magicp = TICOFF0MAGIC;
2779
140
        break;
2780
0
      case '1':
2781
0
        *magicp = TICOFF1MAGIC;
2782
0
        break;
2783
0
      case '2':
2784
0
        *magicp = TICOFF2MAGIC;
2785
0
        break;
2786
0
      default:
2787
0
        return false;
2788
140
      }
2789
140
  }
2790
140
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2791
140
      return true;
2792
0
#endif
2793
2794
#ifdef AARCH64MAGIC
2795
277
    case bfd_arch_aarch64:
2796
277
      * magicp = AARCH64MAGIC;
2797
277
      return true;
2798
0
#endif
2799
2800
#ifdef LOONGARCH64MAGIC
2801
117
    case bfd_arch_loongarch:
2802
117
      * magicp = LOONGARCH64MAGIC;
2803
117
      return true;
2804
0
#endif
2805
2806
#ifdef RISCV64MAGIC
2807
94
    case bfd_arch_riscv:
2808
94
      * magicp = RISCV64MAGIC;
2809
94
      return true;
2810
0
#endif
2811
2812
#ifdef ARMMAGIC
2813
238
    case bfd_arch_arm:
2814
#ifdef ARM_WINCE
2815
      * magicp = ARMPEMAGIC;
2816
#else
2817
238
      * magicp = ARMMAGIC;
2818
238
#endif
2819
238
      * flagsp = 0;
2820
238
      if (APCS_SET (abfd))
2821
1
  {
2822
1
    if (APCS_26_FLAG (abfd))
2823
0
      * flagsp |= F_APCS26;
2824
2825
1
    if (APCS_FLOAT_FLAG (abfd))
2826
0
      * flagsp |= F_APCS_FLOAT;
2827
2828
1
    if (PIC_FLAG (abfd))
2829
0
      * flagsp |= F_PIC;
2830
1
  }
2831
238
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2832
0
  * flagsp |= F_INTERWORK;
2833
238
      switch (bfd_get_mach (abfd))
2834
238
  {
2835
0
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2836
0
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2837
0
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2838
238
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2839
0
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2840
0
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2841
0
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2842
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2843
       See also the comment in coff_set_arch_mach_hook().  */
2844
0
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2845
0
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2846
0
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2847
238
  }
2848
238
      return true;
2849
0
#endif
2850
2851
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2852
618
    case bfd_arch_i386:
2853
#if defined(I386MAGIC)
2854
245
      *magicp = I386MAGIC;
2855
#endif
2856
#if defined LYNXOS
2857
      /* Just overwrite the usual value if we're doing Lynx.  */
2858
0
      *magicp = LYNXCOFFMAGIC;
2859
#endif
2860
#if defined AMD64MAGIC
2861
373
      *magicp = AMD64MAGIC;
2862
#endif
2863
618
      return true;
2864
0
#endif
2865
2866
#ifdef IA64MAGIC
2867
100
    case bfd_arch_ia64:
2868
100
      *magicp = IA64MAGIC;
2869
100
      return true;
2870
0
#endif
2871
2872
#ifdef SH_ARCH_MAGIC_BIG
2873
330
    case bfd_arch_sh:
2874
#ifdef COFF_IMAGE_WITH_PE
2875
98
      *magicp = SH_ARCH_MAGIC_WINCE;
2876
#else
2877
232
      if (bfd_big_endian (abfd))
2878
4
  *magicp = SH_ARCH_MAGIC_BIG;
2879
228
      else
2880
228
  *magicp = SH_ARCH_MAGIC_LITTLE;
2881
#endif
2882
330
      return true;
2883
0
#endif
2884
2885
#ifdef MIPS_ARCH_MAGIC_WINCE
2886
    case bfd_arch_mips:
2887
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2888
      return true;
2889
#endif
2890
2891
#ifdef SPARCMAGIC
2892
    case bfd_arch_sparc:
2893
      *magicp = SPARCMAGIC;
2894
#ifdef LYNXOS
2895
      /* Just overwrite the usual value if we're doing Lynx.  */
2896
      *magicp = LYNXCOFFMAGIC;
2897
#endif
2898
      return true;
2899
#endif
2900
2901
#ifdef RS6000COFF_C
2902
159
    case bfd_arch_rs6000:
2903
236
    case bfd_arch_powerpc:
2904
236
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2905
236
      *magicp = bfd_xcoff_magic_number (abfd);
2906
236
      return true;
2907
0
#endif
2908
2909
#ifdef MCOREMAGIC
2910
157
    case bfd_arch_mcore:
2911
157
      * magicp = MCOREMAGIC;
2912
157
      return true;
2913
0
#endif
2914
2915
0
    default:      /* Unknown architecture.  */
2916
0
      break;
2917
2.65k
    }
2918
2919
0
  return false;
2920
2.65k
}
pei-i386.c:coff_set_flags
Line
Count
Source
2723
123
{
2724
123
  switch (bfd_get_arch (abfd))
2725
123
    {
2726
#ifdef Z80MAGIC
2727
    case bfd_arch_z80:
2728
      *magicp = Z80MAGIC;
2729
      switch (bfd_get_mach (abfd))
2730
  {
2731
  case bfd_mach_z80strict:
2732
  case bfd_mach_z80:
2733
  case bfd_mach_z80n:
2734
  case bfd_mach_z80full:
2735
  case bfd_mach_r800:
2736
  case bfd_mach_gbz80:
2737
  case bfd_mach_z180:
2738
  case bfd_mach_ez80_z80:
2739
  case bfd_mach_ez80_adl:
2740
    *flagsp = bfd_get_mach (abfd) << 12;
2741
    break;
2742
  default:
2743
    return false;
2744
  }
2745
      return true;
2746
#endif
2747
2748
#ifdef Z8KMAGIC
2749
    case bfd_arch_z8k:
2750
      *magicp = Z8KMAGIC;
2751
2752
      switch (bfd_get_mach (abfd))
2753
  {
2754
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2755
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2756
  default:       return false;
2757
  }
2758
      return true;
2759
#endif
2760
2761
#ifdef TIC30MAGIC
2762
    case bfd_arch_tic30:
2763
      *magicp = TIC30MAGIC;
2764
      return true;
2765
#endif
2766
2767
#ifdef TICOFF_DEFAULT_MAGIC
2768
    case TICOFF_TARGET_ARCH:
2769
      /* If there's no indication of which version we want, use the default.  */
2770
      if (!abfd->xvec )
2771
  *magicp = TICOFF_DEFAULT_MAGIC;
2772
      else
2773
  {
2774
    /* We may want to output in a different COFF version.  */
2775
    switch (abfd->xvec->name[4])
2776
      {
2777
      case '0':
2778
        *magicp = TICOFF0MAGIC;
2779
        break;
2780
      case '1':
2781
        *magicp = TICOFF1MAGIC;
2782
        break;
2783
      case '2':
2784
        *magicp = TICOFF2MAGIC;
2785
        break;
2786
      default:
2787
        return false;
2788
      }
2789
  }
2790
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2791
      return true;
2792
#endif
2793
2794
#ifdef AARCH64MAGIC
2795
    case bfd_arch_aarch64:
2796
      * magicp = AARCH64MAGIC;
2797
      return true;
2798
#endif
2799
2800
#ifdef LOONGARCH64MAGIC
2801
    case bfd_arch_loongarch:
2802
      * magicp = LOONGARCH64MAGIC;
2803
      return true;
2804
#endif
2805
2806
#ifdef RISCV64MAGIC
2807
    case bfd_arch_riscv:
2808
      * magicp = RISCV64MAGIC;
2809
      return true;
2810
#endif
2811
2812
#ifdef ARMMAGIC
2813
    case bfd_arch_arm:
2814
#ifdef ARM_WINCE
2815
      * magicp = ARMPEMAGIC;
2816
#else
2817
      * magicp = ARMMAGIC;
2818
#endif
2819
      * flagsp = 0;
2820
      if (APCS_SET (abfd))
2821
  {
2822
    if (APCS_26_FLAG (abfd))
2823
      * flagsp |= F_APCS26;
2824
2825
    if (APCS_FLOAT_FLAG (abfd))
2826
      * flagsp |= F_APCS_FLOAT;
2827
2828
    if (PIC_FLAG (abfd))
2829
      * flagsp |= F_PIC;
2830
  }
2831
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2832
  * flagsp |= F_INTERWORK;
2833
      switch (bfd_get_mach (abfd))
2834
  {
2835
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2836
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2837
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2838
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2839
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2840
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2841
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2842
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2843
       See also the comment in coff_set_arch_mach_hook().  */
2844
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2845
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2846
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2847
  }
2848
      return true;
2849
#endif
2850
2851
0
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2852
123
    case bfd_arch_i386:
2853
123
#if defined(I386MAGIC)
2854
123
      *magicp = I386MAGIC;
2855
123
#endif
2856
#if defined LYNXOS
2857
      /* Just overwrite the usual value if we're doing Lynx.  */
2858
      *magicp = LYNXCOFFMAGIC;
2859
#endif
2860
#if defined AMD64MAGIC
2861
      *magicp = AMD64MAGIC;
2862
#endif
2863
123
      return true;
2864
0
#endif
2865
2866
#ifdef IA64MAGIC
2867
    case bfd_arch_ia64:
2868
      *magicp = IA64MAGIC;
2869
      return true;
2870
#endif
2871
2872
#ifdef SH_ARCH_MAGIC_BIG
2873
    case bfd_arch_sh:
2874
#ifdef COFF_IMAGE_WITH_PE
2875
      *magicp = SH_ARCH_MAGIC_WINCE;
2876
#else
2877
      if (bfd_big_endian (abfd))
2878
  *magicp = SH_ARCH_MAGIC_BIG;
2879
      else
2880
  *magicp = SH_ARCH_MAGIC_LITTLE;
2881
#endif
2882
      return true;
2883
#endif
2884
2885
#ifdef MIPS_ARCH_MAGIC_WINCE
2886
    case bfd_arch_mips:
2887
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2888
      return true;
2889
#endif
2890
2891
#ifdef SPARCMAGIC
2892
    case bfd_arch_sparc:
2893
      *magicp = SPARCMAGIC;
2894
#ifdef LYNXOS
2895
      /* Just overwrite the usual value if we're doing Lynx.  */
2896
      *magicp = LYNXCOFFMAGIC;
2897
#endif
2898
      return true;
2899
#endif
2900
2901
#ifdef RS6000COFF_C
2902
    case bfd_arch_rs6000:
2903
    case bfd_arch_powerpc:
2904
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2905
      *magicp = bfd_xcoff_magic_number (abfd);
2906
      return true;
2907
#endif
2908
2909
#ifdef MCOREMAGIC
2910
    case bfd_arch_mcore:
2911
      * magicp = MCOREMAGIC;
2912
      return true;
2913
#endif
2914
2915
0
    default:      /* Unknown architecture.  */
2916
0
      break;
2917
123
    }
2918
2919
0
  return false;
2920
123
}
pe-x86_64.c:coff_set_flags
Line
Count
Source
2723
100
{
2724
100
  switch (bfd_get_arch (abfd))
2725
100
    {
2726
#ifdef Z80MAGIC
2727
    case bfd_arch_z80:
2728
      *magicp = Z80MAGIC;
2729
      switch (bfd_get_mach (abfd))
2730
  {
2731
  case bfd_mach_z80strict:
2732
  case bfd_mach_z80:
2733
  case bfd_mach_z80n:
2734
  case bfd_mach_z80full:
2735
  case bfd_mach_r800:
2736
  case bfd_mach_gbz80:
2737
  case bfd_mach_z180:
2738
  case bfd_mach_ez80_z80:
2739
  case bfd_mach_ez80_adl:
2740
    *flagsp = bfd_get_mach (abfd) << 12;
2741
    break;
2742
  default:
2743
    return false;
2744
  }
2745
      return true;
2746
#endif
2747
2748
#ifdef Z8KMAGIC
2749
    case bfd_arch_z8k:
2750
      *magicp = Z8KMAGIC;
2751
2752
      switch (bfd_get_mach (abfd))
2753
  {
2754
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2755
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2756
  default:       return false;
2757
  }
2758
      return true;
2759
#endif
2760
2761
#ifdef TIC30MAGIC
2762
    case bfd_arch_tic30:
2763
      *magicp = TIC30MAGIC;
2764
      return true;
2765
#endif
2766
2767
#ifdef TICOFF_DEFAULT_MAGIC
2768
    case TICOFF_TARGET_ARCH:
2769
      /* If there's no indication of which version we want, use the default.  */
2770
      if (!abfd->xvec )
2771
  *magicp = TICOFF_DEFAULT_MAGIC;
2772
      else
2773
  {
2774
    /* We may want to output in a different COFF version.  */
2775
    switch (abfd->xvec->name[4])
2776
      {
2777
      case '0':
2778
        *magicp = TICOFF0MAGIC;
2779
        break;
2780
      case '1':
2781
        *magicp = TICOFF1MAGIC;
2782
        break;
2783
      case '2':
2784
        *magicp = TICOFF2MAGIC;
2785
        break;
2786
      default:
2787
        return false;
2788
      }
2789
  }
2790
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2791
      return true;
2792
#endif
2793
2794
#ifdef AARCH64MAGIC
2795
    case bfd_arch_aarch64:
2796
      * magicp = AARCH64MAGIC;
2797
      return true;
2798
#endif
2799
2800
#ifdef LOONGARCH64MAGIC
2801
    case bfd_arch_loongarch:
2802
      * magicp = LOONGARCH64MAGIC;
2803
      return true;
2804
#endif
2805
2806
#ifdef RISCV64MAGIC
2807
    case bfd_arch_riscv:
2808
      * magicp = RISCV64MAGIC;
2809
      return true;
2810
#endif
2811
2812
#ifdef ARMMAGIC
2813
    case bfd_arch_arm:
2814
#ifdef ARM_WINCE
2815
      * magicp = ARMPEMAGIC;
2816
#else
2817
      * magicp = ARMMAGIC;
2818
#endif
2819
      * flagsp = 0;
2820
      if (APCS_SET (abfd))
2821
  {
2822
    if (APCS_26_FLAG (abfd))
2823
      * flagsp |= F_APCS26;
2824
2825
    if (APCS_FLOAT_FLAG (abfd))
2826
      * flagsp |= F_APCS_FLOAT;
2827
2828
    if (PIC_FLAG (abfd))
2829
      * flagsp |= F_PIC;
2830
  }
2831
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2832
  * flagsp |= F_INTERWORK;
2833
      switch (bfd_get_mach (abfd))
2834
  {
2835
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2836
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2837
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2838
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2839
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2840
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2841
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2842
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2843
       See also the comment in coff_set_arch_mach_hook().  */
2844
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2845
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2846
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2847
  }
2848
      return true;
2849
#endif
2850
2851
0
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2852
100
    case bfd_arch_i386:
2853
#if defined(I386MAGIC)
2854
      *magicp = I386MAGIC;
2855
#endif
2856
#if defined LYNXOS
2857
      /* Just overwrite the usual value if we're doing Lynx.  */
2858
      *magicp = LYNXCOFFMAGIC;
2859
#endif
2860
100
#if defined AMD64MAGIC
2861
100
      *magicp = AMD64MAGIC;
2862
100
#endif
2863
100
      return true;
2864
0
#endif
2865
2866
#ifdef IA64MAGIC
2867
    case bfd_arch_ia64:
2868
      *magicp = IA64MAGIC;
2869
      return true;
2870
#endif
2871
2872
#ifdef SH_ARCH_MAGIC_BIG
2873
    case bfd_arch_sh:
2874
#ifdef COFF_IMAGE_WITH_PE
2875
      *magicp = SH_ARCH_MAGIC_WINCE;
2876
#else
2877
      if (bfd_big_endian (abfd))
2878
  *magicp = SH_ARCH_MAGIC_BIG;
2879
      else
2880
  *magicp = SH_ARCH_MAGIC_LITTLE;
2881
#endif
2882
      return true;
2883
#endif
2884
2885
#ifdef MIPS_ARCH_MAGIC_WINCE
2886
    case bfd_arch_mips:
2887
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2888
      return true;
2889
#endif
2890
2891
#ifdef SPARCMAGIC
2892
    case bfd_arch_sparc:
2893
      *magicp = SPARCMAGIC;
2894
#ifdef LYNXOS
2895
      /* Just overwrite the usual value if we're doing Lynx.  */
2896
      *magicp = LYNXCOFFMAGIC;
2897
#endif
2898
      return true;
2899
#endif
2900
2901
#ifdef RS6000COFF_C
2902
    case bfd_arch_rs6000:
2903
    case bfd_arch_powerpc:
2904
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2905
      *magicp = bfd_xcoff_magic_number (abfd);
2906
      return true;
2907
#endif
2908
2909
#ifdef MCOREMAGIC
2910
    case bfd_arch_mcore:
2911
      * magicp = MCOREMAGIC;
2912
      return true;
2913
#endif
2914
2915
0
    default:      /* Unknown architecture.  */
2916
0
      break;
2917
100
    }
2918
2919
0
  return false;
2920
100
}
pei-x86_64.c:coff_set_flags
Line
Count
Source
2723
130
{
2724
130
  switch (bfd_get_arch (abfd))
2725
130
    {
2726
#ifdef Z80MAGIC
2727
    case bfd_arch_z80:
2728
      *magicp = Z80MAGIC;
2729
      switch (bfd_get_mach (abfd))
2730
  {
2731
  case bfd_mach_z80strict:
2732
  case bfd_mach_z80:
2733
  case bfd_mach_z80n:
2734
  case bfd_mach_z80full:
2735
  case bfd_mach_r800:
2736
  case bfd_mach_gbz80:
2737
  case bfd_mach_z180:
2738
  case bfd_mach_ez80_z80:
2739
  case bfd_mach_ez80_adl:
2740
    *flagsp = bfd_get_mach (abfd) << 12;
2741
    break;
2742
  default:
2743
    return false;
2744
  }
2745
      return true;
2746
#endif
2747
2748
#ifdef Z8KMAGIC
2749
    case bfd_arch_z8k:
2750
      *magicp = Z8KMAGIC;
2751
2752
      switch (bfd_get_mach (abfd))
2753
  {
2754
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2755
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2756
  default:       return false;
2757
  }
2758
      return true;
2759
#endif
2760
2761
#ifdef TIC30MAGIC
2762
    case bfd_arch_tic30:
2763
      *magicp = TIC30MAGIC;
2764
      return true;
2765
#endif
2766
2767
#ifdef TICOFF_DEFAULT_MAGIC
2768
    case TICOFF_TARGET_ARCH:
2769
      /* If there's no indication of which version we want, use the default.  */
2770
      if (!abfd->xvec )
2771
  *magicp = TICOFF_DEFAULT_MAGIC;
2772
      else
2773
  {
2774
    /* We may want to output in a different COFF version.  */
2775
    switch (abfd->xvec->name[4])
2776
      {
2777
      case '0':
2778
        *magicp = TICOFF0MAGIC;
2779
        break;
2780
      case '1':
2781
        *magicp = TICOFF1MAGIC;
2782
        break;
2783
      case '2':
2784
        *magicp = TICOFF2MAGIC;
2785
        break;
2786
      default:
2787
        return false;
2788
      }
2789
  }
2790
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2791
      return true;
2792
#endif
2793
2794
#ifdef AARCH64MAGIC
2795
    case bfd_arch_aarch64:
2796
      * magicp = AARCH64MAGIC;
2797
      return true;
2798
#endif
2799
2800
#ifdef LOONGARCH64MAGIC
2801
    case bfd_arch_loongarch:
2802
      * magicp = LOONGARCH64MAGIC;
2803
      return true;
2804
#endif
2805
2806
#ifdef RISCV64MAGIC
2807
    case bfd_arch_riscv:
2808
      * magicp = RISCV64MAGIC;
2809
      return true;
2810
#endif
2811
2812
#ifdef ARMMAGIC
2813
    case bfd_arch_arm:
2814
#ifdef ARM_WINCE
2815
      * magicp = ARMPEMAGIC;
2816
#else
2817
      * magicp = ARMMAGIC;
2818
#endif
2819
      * flagsp = 0;
2820
      if (APCS_SET (abfd))
2821
  {
2822
    if (APCS_26_FLAG (abfd))
2823
      * flagsp |= F_APCS26;
2824
2825
    if (APCS_FLOAT_FLAG (abfd))
2826
      * flagsp |= F_APCS_FLOAT;
2827
2828
    if (PIC_FLAG (abfd))
2829
      * flagsp |= F_PIC;
2830
  }
2831
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2832
  * flagsp |= F_INTERWORK;
2833
      switch (bfd_get_mach (abfd))
2834
  {
2835
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2836
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2837
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2838
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2839
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2840
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2841
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2842
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2843
       See also the comment in coff_set_arch_mach_hook().  */
2844
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2845
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2846
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2847
  }
2848
      return true;
2849
#endif
2850
2851
0
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2852
130
    case bfd_arch_i386:
2853
#if defined(I386MAGIC)
2854
      *magicp = I386MAGIC;
2855
#endif
2856
#if defined LYNXOS
2857
      /* Just overwrite the usual value if we're doing Lynx.  */
2858
      *magicp = LYNXCOFFMAGIC;
2859
#endif
2860
130
#if defined AMD64MAGIC
2861
130
      *magicp = AMD64MAGIC;
2862
130
#endif
2863
130
      return true;
2864
0
#endif
2865
2866
#ifdef IA64MAGIC
2867
    case bfd_arch_ia64:
2868
      *magicp = IA64MAGIC;
2869
      return true;
2870
#endif
2871
2872
#ifdef SH_ARCH_MAGIC_BIG
2873
    case bfd_arch_sh:
2874
#ifdef COFF_IMAGE_WITH_PE
2875
      *magicp = SH_ARCH_MAGIC_WINCE;
2876
#else
2877
      if (bfd_big_endian (abfd))
2878
  *magicp = SH_ARCH_MAGIC_BIG;
2879
      else
2880
  *magicp = SH_ARCH_MAGIC_LITTLE;
2881
#endif
2882
      return true;
2883
#endif
2884
2885
#ifdef MIPS_ARCH_MAGIC_WINCE
2886
    case bfd_arch_mips:
2887
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2888
      return true;
2889
#endif
2890
2891
#ifdef SPARCMAGIC
2892
    case bfd_arch_sparc:
2893
      *magicp = SPARCMAGIC;
2894
#ifdef LYNXOS
2895
      /* Just overwrite the usual value if we're doing Lynx.  */
2896
      *magicp = LYNXCOFFMAGIC;
2897
#endif
2898
      return true;
2899
#endif
2900
2901
#ifdef RS6000COFF_C
2902
    case bfd_arch_rs6000:
2903
    case bfd_arch_powerpc:
2904
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2905
      *magicp = bfd_xcoff_magic_number (abfd);
2906
      return true;
2907
#endif
2908
2909
#ifdef MCOREMAGIC
2910
    case bfd_arch_mcore:
2911
      * magicp = MCOREMAGIC;
2912
      return true;
2913
#endif
2914
2915
0
    default:      /* Unknown architecture.  */
2916
0
      break;
2917
130
    }
2918
2919
0
  return false;
2920
130
}
coff-x86_64.c:coff_set_flags
Line
Count
Source
2723
143
{
2724
143
  switch (bfd_get_arch (abfd))
2725
143
    {
2726
#ifdef Z80MAGIC
2727
    case bfd_arch_z80:
2728
      *magicp = Z80MAGIC;
2729
      switch (bfd_get_mach (abfd))
2730
  {
2731
  case bfd_mach_z80strict:
2732
  case bfd_mach_z80:
2733
  case bfd_mach_z80n:
2734
  case bfd_mach_z80full:
2735
  case bfd_mach_r800:
2736
  case bfd_mach_gbz80:
2737
  case bfd_mach_z180:
2738
  case bfd_mach_ez80_z80:
2739
  case bfd_mach_ez80_adl:
2740
    *flagsp = bfd_get_mach (abfd) << 12;
2741
    break;
2742
  default:
2743
    return false;
2744
  }
2745
      return true;
2746
#endif
2747
2748
#ifdef Z8KMAGIC
2749
    case bfd_arch_z8k:
2750
      *magicp = Z8KMAGIC;
2751
2752
      switch (bfd_get_mach (abfd))
2753
  {
2754
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2755
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2756
  default:       return false;
2757
  }
2758
      return true;
2759
#endif
2760
2761
#ifdef TIC30MAGIC
2762
    case bfd_arch_tic30:
2763
      *magicp = TIC30MAGIC;
2764
      return true;
2765
#endif
2766
2767
#ifdef TICOFF_DEFAULT_MAGIC
2768
    case TICOFF_TARGET_ARCH:
2769
      /* If there's no indication of which version we want, use the default.  */
2770
      if (!abfd->xvec )
2771
  *magicp = TICOFF_DEFAULT_MAGIC;
2772
      else
2773
  {
2774
    /* We may want to output in a different COFF version.  */
2775
    switch (abfd->xvec->name[4])
2776
      {
2777
      case '0':
2778
        *magicp = TICOFF0MAGIC;
2779
        break;
2780
      case '1':
2781
        *magicp = TICOFF1MAGIC;
2782
        break;
2783
      case '2':
2784
        *magicp = TICOFF2MAGIC;
2785
        break;
2786
      default:
2787
        return false;
2788
      }
2789
  }
2790
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2791
      return true;
2792
#endif
2793
2794
#ifdef AARCH64MAGIC
2795
    case bfd_arch_aarch64:
2796
      * magicp = AARCH64MAGIC;
2797
      return true;
2798
#endif
2799
2800
#ifdef LOONGARCH64MAGIC
2801
    case bfd_arch_loongarch:
2802
      * magicp = LOONGARCH64MAGIC;
2803
      return true;
2804
#endif
2805
2806
#ifdef RISCV64MAGIC
2807
    case bfd_arch_riscv:
2808
      * magicp = RISCV64MAGIC;
2809
      return true;
2810
#endif
2811
2812
#ifdef ARMMAGIC
2813
    case bfd_arch_arm:
2814
#ifdef ARM_WINCE
2815
      * magicp = ARMPEMAGIC;
2816
#else
2817
      * magicp = ARMMAGIC;
2818
#endif
2819
      * flagsp = 0;
2820
      if (APCS_SET (abfd))
2821
  {
2822
    if (APCS_26_FLAG (abfd))
2823
      * flagsp |= F_APCS26;
2824
2825
    if (APCS_FLOAT_FLAG (abfd))
2826
      * flagsp |= F_APCS_FLOAT;
2827
2828
    if (PIC_FLAG (abfd))
2829
      * flagsp |= F_PIC;
2830
  }
2831
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2832
  * flagsp |= F_INTERWORK;
2833
      switch (bfd_get_mach (abfd))
2834
  {
2835
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2836
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2837
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2838
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2839
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2840
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2841
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2842
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2843
       See also the comment in coff_set_arch_mach_hook().  */
2844
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2845
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2846
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2847
  }
2848
      return true;
2849
#endif
2850
2851
0
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2852
143
    case bfd_arch_i386:
2853
#if defined(I386MAGIC)
2854
      *magicp = I386MAGIC;
2855
#endif
2856
#if defined LYNXOS
2857
      /* Just overwrite the usual value if we're doing Lynx.  */
2858
      *magicp = LYNXCOFFMAGIC;
2859
#endif
2860
143
#if defined AMD64MAGIC
2861
143
      *magicp = AMD64MAGIC;
2862
143
#endif
2863
143
      return true;
2864
0
#endif
2865
2866
#ifdef IA64MAGIC
2867
    case bfd_arch_ia64:
2868
      *magicp = IA64MAGIC;
2869
      return true;
2870
#endif
2871
2872
#ifdef SH_ARCH_MAGIC_BIG
2873
    case bfd_arch_sh:
2874
#ifdef COFF_IMAGE_WITH_PE
2875
      *magicp = SH_ARCH_MAGIC_WINCE;
2876
#else
2877
      if (bfd_big_endian (abfd))
2878
  *magicp = SH_ARCH_MAGIC_BIG;
2879
      else
2880
  *magicp = SH_ARCH_MAGIC_LITTLE;
2881
#endif
2882
      return true;
2883
#endif
2884
2885
#ifdef MIPS_ARCH_MAGIC_WINCE
2886
    case bfd_arch_mips:
2887
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2888
      return true;
2889
#endif
2890
2891
#ifdef SPARCMAGIC
2892
    case bfd_arch_sparc:
2893
      *magicp = SPARCMAGIC;
2894
#ifdef LYNXOS
2895
      /* Just overwrite the usual value if we're doing Lynx.  */
2896
      *magicp = LYNXCOFFMAGIC;
2897
#endif
2898
      return true;
2899
#endif
2900
2901
#ifdef RS6000COFF_C
2902
    case bfd_arch_rs6000:
2903
    case bfd_arch_powerpc:
2904
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2905
      *magicp = bfd_xcoff_magic_number (abfd);
2906
      return true;
2907
#endif
2908
2909
#ifdef MCOREMAGIC
2910
    case bfd_arch_mcore:
2911
      * magicp = MCOREMAGIC;
2912
      return true;
2913
#endif
2914
2915
0
    default:      /* Unknown architecture.  */
2916
0
      break;
2917
143
    }
2918
2919
0
  return false;
2920
143
}
coff64-rs6000.c:coff_set_flags
Line
Count
Source
2723
77
{
2724
77
  switch (bfd_get_arch (abfd))
2725
77
    {
2726
#ifdef Z80MAGIC
2727
    case bfd_arch_z80:
2728
      *magicp = Z80MAGIC;
2729
      switch (bfd_get_mach (abfd))
2730
  {
2731
  case bfd_mach_z80strict:
2732
  case bfd_mach_z80:
2733
  case bfd_mach_z80n:
2734
  case bfd_mach_z80full:
2735
  case bfd_mach_r800:
2736
  case bfd_mach_gbz80:
2737
  case bfd_mach_z180:
2738
  case bfd_mach_ez80_z80:
2739
  case bfd_mach_ez80_adl:
2740
    *flagsp = bfd_get_mach (abfd) << 12;
2741
    break;
2742
  default:
2743
    return false;
2744
  }
2745
      return true;
2746
#endif
2747
2748
#ifdef Z8KMAGIC
2749
    case bfd_arch_z8k:
2750
      *magicp = Z8KMAGIC;
2751
2752
      switch (bfd_get_mach (abfd))
2753
  {
2754
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2755
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2756
  default:       return false;
2757
  }
2758
      return true;
2759
#endif
2760
2761
#ifdef TIC30MAGIC
2762
    case bfd_arch_tic30:
2763
      *magicp = TIC30MAGIC;
2764
      return true;
2765
#endif
2766
2767
#ifdef TICOFF_DEFAULT_MAGIC
2768
    case TICOFF_TARGET_ARCH:
2769
      /* If there's no indication of which version we want, use the default.  */
2770
      if (!abfd->xvec )
2771
  *magicp = TICOFF_DEFAULT_MAGIC;
2772
      else
2773
  {
2774
    /* We may want to output in a different COFF version.  */
2775
    switch (abfd->xvec->name[4])
2776
      {
2777
      case '0':
2778
        *magicp = TICOFF0MAGIC;
2779
        break;
2780
      case '1':
2781
        *magicp = TICOFF1MAGIC;
2782
        break;
2783
      case '2':
2784
        *magicp = TICOFF2MAGIC;
2785
        break;
2786
      default:
2787
        return false;
2788
      }
2789
  }
2790
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2791
      return true;
2792
#endif
2793
2794
#ifdef AARCH64MAGIC
2795
    case bfd_arch_aarch64:
2796
      * magicp = AARCH64MAGIC;
2797
      return true;
2798
#endif
2799
2800
#ifdef LOONGARCH64MAGIC
2801
    case bfd_arch_loongarch:
2802
      * magicp = LOONGARCH64MAGIC;
2803
      return true;
2804
#endif
2805
2806
#ifdef RISCV64MAGIC
2807
    case bfd_arch_riscv:
2808
      * magicp = RISCV64MAGIC;
2809
      return true;
2810
#endif
2811
2812
#ifdef ARMMAGIC
2813
    case bfd_arch_arm:
2814
#ifdef ARM_WINCE
2815
      * magicp = ARMPEMAGIC;
2816
#else
2817
      * magicp = ARMMAGIC;
2818
#endif
2819
      * flagsp = 0;
2820
      if (APCS_SET (abfd))
2821
  {
2822
    if (APCS_26_FLAG (abfd))
2823
      * flagsp |= F_APCS26;
2824
2825
    if (APCS_FLOAT_FLAG (abfd))
2826
      * flagsp |= F_APCS_FLOAT;
2827
2828
    if (PIC_FLAG (abfd))
2829
      * flagsp |= F_PIC;
2830
  }
2831
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2832
  * flagsp |= F_INTERWORK;
2833
      switch (bfd_get_mach (abfd))
2834
  {
2835
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2836
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2837
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2838
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2839
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2840
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2841
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2842
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2843
       See also the comment in coff_set_arch_mach_hook().  */
2844
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2845
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2846
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2847
  }
2848
      return true;
2849
#endif
2850
2851
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2852
    case bfd_arch_i386:
2853
#if defined(I386MAGIC)
2854
      *magicp = I386MAGIC;
2855
#endif
2856
#if defined LYNXOS
2857
      /* Just overwrite the usual value if we're doing Lynx.  */
2858
      *magicp = LYNXCOFFMAGIC;
2859
#endif
2860
#if defined AMD64MAGIC
2861
      *magicp = AMD64MAGIC;
2862
#endif
2863
      return true;
2864
#endif
2865
2866
#ifdef IA64MAGIC
2867
    case bfd_arch_ia64:
2868
      *magicp = IA64MAGIC;
2869
      return true;
2870
#endif
2871
2872
#ifdef SH_ARCH_MAGIC_BIG
2873
    case bfd_arch_sh:
2874
#ifdef COFF_IMAGE_WITH_PE
2875
      *magicp = SH_ARCH_MAGIC_WINCE;
2876
#else
2877
      if (bfd_big_endian (abfd))
2878
  *magicp = SH_ARCH_MAGIC_BIG;
2879
      else
2880
  *magicp = SH_ARCH_MAGIC_LITTLE;
2881
#endif
2882
      return true;
2883
#endif
2884
2885
#ifdef MIPS_ARCH_MAGIC_WINCE
2886
    case bfd_arch_mips:
2887
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2888
      return true;
2889
#endif
2890
2891
#ifdef SPARCMAGIC
2892
    case bfd_arch_sparc:
2893
      *magicp = SPARCMAGIC;
2894
#ifdef LYNXOS
2895
      /* Just overwrite the usual value if we're doing Lynx.  */
2896
      *magicp = LYNXCOFFMAGIC;
2897
#endif
2898
      return true;
2899
#endif
2900
2901
0
#ifdef RS6000COFF_C
2902
0
    case bfd_arch_rs6000:
2903
77
    case bfd_arch_powerpc:
2904
77
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2905
77
      *magicp = bfd_xcoff_magic_number (abfd);
2906
77
      return true;
2907
0
#endif
2908
2909
#ifdef MCOREMAGIC
2910
    case bfd_arch_mcore:
2911
      * magicp = MCOREMAGIC;
2912
      return true;
2913
#endif
2914
2915
0
    default:      /* Unknown architecture.  */
2916
0
      break;
2917
77
    }
2918
2919
0
  return false;
2920
77
}
pe-aarch64.c:coff_set_flags
Line
Count
Source
2723
113
{
2724
113
  switch (bfd_get_arch (abfd))
2725
113
    {
2726
#ifdef Z80MAGIC
2727
    case bfd_arch_z80:
2728
      *magicp = Z80MAGIC;
2729
      switch (bfd_get_mach (abfd))
2730
  {
2731
  case bfd_mach_z80strict:
2732
  case bfd_mach_z80:
2733
  case bfd_mach_z80n:
2734
  case bfd_mach_z80full:
2735
  case bfd_mach_r800:
2736
  case bfd_mach_gbz80:
2737
  case bfd_mach_z180:
2738
  case bfd_mach_ez80_z80:
2739
  case bfd_mach_ez80_adl:
2740
    *flagsp = bfd_get_mach (abfd) << 12;
2741
    break;
2742
  default:
2743
    return false;
2744
  }
2745
      return true;
2746
#endif
2747
2748
#ifdef Z8KMAGIC
2749
    case bfd_arch_z8k:
2750
      *magicp = Z8KMAGIC;
2751
2752
      switch (bfd_get_mach (abfd))
2753
  {
2754
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2755
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2756
  default:       return false;
2757
  }
2758
      return true;
2759
#endif
2760
2761
#ifdef TIC30MAGIC
2762
    case bfd_arch_tic30:
2763
      *magicp = TIC30MAGIC;
2764
      return true;
2765
#endif
2766
2767
#ifdef TICOFF_DEFAULT_MAGIC
2768
    case TICOFF_TARGET_ARCH:
2769
      /* If there's no indication of which version we want, use the default.  */
2770
      if (!abfd->xvec )
2771
  *magicp = TICOFF_DEFAULT_MAGIC;
2772
      else
2773
  {
2774
    /* We may want to output in a different COFF version.  */
2775
    switch (abfd->xvec->name[4])
2776
      {
2777
      case '0':
2778
        *magicp = TICOFF0MAGIC;
2779
        break;
2780
      case '1':
2781
        *magicp = TICOFF1MAGIC;
2782
        break;
2783
      case '2':
2784
        *magicp = TICOFF2MAGIC;
2785
        break;
2786
      default:
2787
        return false;
2788
      }
2789
  }
2790
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2791
      return true;
2792
#endif
2793
2794
0
#ifdef AARCH64MAGIC
2795
113
    case bfd_arch_aarch64:
2796
113
      * magicp = AARCH64MAGIC;
2797
113
      return true;
2798
0
#endif
2799
2800
#ifdef LOONGARCH64MAGIC
2801
    case bfd_arch_loongarch:
2802
      * magicp = LOONGARCH64MAGIC;
2803
      return true;
2804
#endif
2805
2806
#ifdef RISCV64MAGIC
2807
    case bfd_arch_riscv:
2808
      * magicp = RISCV64MAGIC;
2809
      return true;
2810
#endif
2811
2812
#ifdef ARMMAGIC
2813
    case bfd_arch_arm:
2814
#ifdef ARM_WINCE
2815
      * magicp = ARMPEMAGIC;
2816
#else
2817
      * magicp = ARMMAGIC;
2818
#endif
2819
      * flagsp = 0;
2820
      if (APCS_SET (abfd))
2821
  {
2822
    if (APCS_26_FLAG (abfd))
2823
      * flagsp |= F_APCS26;
2824
2825
    if (APCS_FLOAT_FLAG (abfd))
2826
      * flagsp |= F_APCS_FLOAT;
2827
2828
    if (PIC_FLAG (abfd))
2829
      * flagsp |= F_PIC;
2830
  }
2831
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2832
  * flagsp |= F_INTERWORK;
2833
      switch (bfd_get_mach (abfd))
2834
  {
2835
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2836
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2837
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2838
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2839
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2840
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2841
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2842
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2843
       See also the comment in coff_set_arch_mach_hook().  */
2844
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2845
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2846
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2847
  }
2848
      return true;
2849
#endif
2850
2851
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2852
    case bfd_arch_i386:
2853
#if defined(I386MAGIC)
2854
      *magicp = I386MAGIC;
2855
#endif
2856
#if defined LYNXOS
2857
      /* Just overwrite the usual value if we're doing Lynx.  */
2858
      *magicp = LYNXCOFFMAGIC;
2859
#endif
2860
#if defined AMD64MAGIC
2861
      *magicp = AMD64MAGIC;
2862
#endif
2863
      return true;
2864
#endif
2865
2866
#ifdef IA64MAGIC
2867
    case bfd_arch_ia64:
2868
      *magicp = IA64MAGIC;
2869
      return true;
2870
#endif
2871
2872
#ifdef SH_ARCH_MAGIC_BIG
2873
    case bfd_arch_sh:
2874
#ifdef COFF_IMAGE_WITH_PE
2875
      *magicp = SH_ARCH_MAGIC_WINCE;
2876
#else
2877
      if (bfd_big_endian (abfd))
2878
  *magicp = SH_ARCH_MAGIC_BIG;
2879
      else
2880
  *magicp = SH_ARCH_MAGIC_LITTLE;
2881
#endif
2882
      return true;
2883
#endif
2884
2885
#ifdef MIPS_ARCH_MAGIC_WINCE
2886
    case bfd_arch_mips:
2887
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2888
      return true;
2889
#endif
2890
2891
#ifdef SPARCMAGIC
2892
    case bfd_arch_sparc:
2893
      *magicp = SPARCMAGIC;
2894
#ifdef LYNXOS
2895
      /* Just overwrite the usual value if we're doing Lynx.  */
2896
      *magicp = LYNXCOFFMAGIC;
2897
#endif
2898
      return true;
2899
#endif
2900
2901
#ifdef RS6000COFF_C
2902
    case bfd_arch_rs6000:
2903
    case bfd_arch_powerpc:
2904
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2905
      *magicp = bfd_xcoff_magic_number (abfd);
2906
      return true;
2907
#endif
2908
2909
#ifdef MCOREMAGIC
2910
    case bfd_arch_mcore:
2911
      * magicp = MCOREMAGIC;
2912
      return true;
2913
#endif
2914
2915
0
    default:      /* Unknown architecture.  */
2916
0
      break;
2917
113
    }
2918
2919
0
  return false;
2920
113
}
pei-aarch64.c:coff_set_flags
Line
Count
Source
2723
164
{
2724
164
  switch (bfd_get_arch (abfd))
2725
164
    {
2726
#ifdef Z80MAGIC
2727
    case bfd_arch_z80:
2728
      *magicp = Z80MAGIC;
2729
      switch (bfd_get_mach (abfd))
2730
  {
2731
  case bfd_mach_z80strict:
2732
  case bfd_mach_z80:
2733
  case bfd_mach_z80n:
2734
  case bfd_mach_z80full:
2735
  case bfd_mach_r800:
2736
  case bfd_mach_gbz80:
2737
  case bfd_mach_z180:
2738
  case bfd_mach_ez80_z80:
2739
  case bfd_mach_ez80_adl:
2740
    *flagsp = bfd_get_mach (abfd) << 12;
2741
    break;
2742
  default:
2743
    return false;
2744
  }
2745
      return true;
2746
#endif
2747
2748
#ifdef Z8KMAGIC
2749
    case bfd_arch_z8k:
2750
      *magicp = Z8KMAGIC;
2751
2752
      switch (bfd_get_mach (abfd))
2753
  {
2754
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2755
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2756
  default:       return false;
2757
  }
2758
      return true;
2759
#endif
2760
2761
#ifdef TIC30MAGIC
2762
    case bfd_arch_tic30:
2763
      *magicp = TIC30MAGIC;
2764
      return true;
2765
#endif
2766
2767
#ifdef TICOFF_DEFAULT_MAGIC
2768
    case TICOFF_TARGET_ARCH:
2769
      /* If there's no indication of which version we want, use the default.  */
2770
      if (!abfd->xvec )
2771
  *magicp = TICOFF_DEFAULT_MAGIC;
2772
      else
2773
  {
2774
    /* We may want to output in a different COFF version.  */
2775
    switch (abfd->xvec->name[4])
2776
      {
2777
      case '0':
2778
        *magicp = TICOFF0MAGIC;
2779
        break;
2780
      case '1':
2781
        *magicp = TICOFF1MAGIC;
2782
        break;
2783
      case '2':
2784
        *magicp = TICOFF2MAGIC;
2785
        break;
2786
      default:
2787
        return false;
2788
      }
2789
  }
2790
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2791
      return true;
2792
#endif
2793
2794
0
#ifdef AARCH64MAGIC
2795
164
    case bfd_arch_aarch64:
2796
164
      * magicp = AARCH64MAGIC;
2797
164
      return true;
2798
0
#endif
2799
2800
#ifdef LOONGARCH64MAGIC
2801
    case bfd_arch_loongarch:
2802
      * magicp = LOONGARCH64MAGIC;
2803
      return true;
2804
#endif
2805
2806
#ifdef RISCV64MAGIC
2807
    case bfd_arch_riscv:
2808
      * magicp = RISCV64MAGIC;
2809
      return true;
2810
#endif
2811
2812
#ifdef ARMMAGIC
2813
    case bfd_arch_arm:
2814
#ifdef ARM_WINCE
2815
      * magicp = ARMPEMAGIC;
2816
#else
2817
      * magicp = ARMMAGIC;
2818
#endif
2819
      * flagsp = 0;
2820
      if (APCS_SET (abfd))
2821
  {
2822
    if (APCS_26_FLAG (abfd))
2823
      * flagsp |= F_APCS26;
2824
2825
    if (APCS_FLOAT_FLAG (abfd))
2826
      * flagsp |= F_APCS_FLOAT;
2827
2828
    if (PIC_FLAG (abfd))
2829
      * flagsp |= F_PIC;
2830
  }
2831
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2832
  * flagsp |= F_INTERWORK;
2833
      switch (bfd_get_mach (abfd))
2834
  {
2835
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2836
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2837
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2838
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2839
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2840
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2841
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2842
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2843
       See also the comment in coff_set_arch_mach_hook().  */
2844
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2845
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2846
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2847
  }
2848
      return true;
2849
#endif
2850
2851
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2852
    case bfd_arch_i386:
2853
#if defined(I386MAGIC)
2854
      *magicp = I386MAGIC;
2855
#endif
2856
#if defined LYNXOS
2857
      /* Just overwrite the usual value if we're doing Lynx.  */
2858
      *magicp = LYNXCOFFMAGIC;
2859
#endif
2860
#if defined AMD64MAGIC
2861
      *magicp = AMD64MAGIC;
2862
#endif
2863
      return true;
2864
#endif
2865
2866
#ifdef IA64MAGIC
2867
    case bfd_arch_ia64:
2868
      *magicp = IA64MAGIC;
2869
      return true;
2870
#endif
2871
2872
#ifdef SH_ARCH_MAGIC_BIG
2873
    case bfd_arch_sh:
2874
#ifdef COFF_IMAGE_WITH_PE
2875
      *magicp = SH_ARCH_MAGIC_WINCE;
2876
#else
2877
      if (bfd_big_endian (abfd))
2878
  *magicp = SH_ARCH_MAGIC_BIG;
2879
      else
2880
  *magicp = SH_ARCH_MAGIC_LITTLE;
2881
#endif
2882
      return true;
2883
#endif
2884
2885
#ifdef MIPS_ARCH_MAGIC_WINCE
2886
    case bfd_arch_mips:
2887
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2888
      return true;
2889
#endif
2890
2891
#ifdef SPARCMAGIC
2892
    case bfd_arch_sparc:
2893
      *magicp = SPARCMAGIC;
2894
#ifdef LYNXOS
2895
      /* Just overwrite the usual value if we're doing Lynx.  */
2896
      *magicp = LYNXCOFFMAGIC;
2897
#endif
2898
      return true;
2899
#endif
2900
2901
#ifdef RS6000COFF_C
2902
    case bfd_arch_rs6000:
2903
    case bfd_arch_powerpc:
2904
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2905
      *magicp = bfd_xcoff_magic_number (abfd);
2906
      return true;
2907
#endif
2908
2909
#ifdef MCOREMAGIC
2910
    case bfd_arch_mcore:
2911
      * magicp = MCOREMAGIC;
2912
      return true;
2913
#endif
2914
2915
0
    default:      /* Unknown architecture.  */
2916
0
      break;
2917
164
    }
2918
2919
0
  return false;
2920
164
}
pei-ia64.c:coff_set_flags
Line
Count
Source
2723
100
{
2724
100
  switch (bfd_get_arch (abfd))
2725
100
    {
2726
#ifdef Z80MAGIC
2727
    case bfd_arch_z80:
2728
      *magicp = Z80MAGIC;
2729
      switch (bfd_get_mach (abfd))
2730
  {
2731
  case bfd_mach_z80strict:
2732
  case bfd_mach_z80:
2733
  case bfd_mach_z80n:
2734
  case bfd_mach_z80full:
2735
  case bfd_mach_r800:
2736
  case bfd_mach_gbz80:
2737
  case bfd_mach_z180:
2738
  case bfd_mach_ez80_z80:
2739
  case bfd_mach_ez80_adl:
2740
    *flagsp = bfd_get_mach (abfd) << 12;
2741
    break;
2742
  default:
2743
    return false;
2744
  }
2745
      return true;
2746
#endif
2747
2748
#ifdef Z8KMAGIC
2749
    case bfd_arch_z8k:
2750
      *magicp = Z8KMAGIC;
2751
2752
      switch (bfd_get_mach (abfd))
2753
  {
2754
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2755
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2756
  default:       return false;
2757
  }
2758
      return true;
2759
#endif
2760
2761
#ifdef TIC30MAGIC
2762
    case bfd_arch_tic30:
2763
      *magicp = TIC30MAGIC;
2764
      return true;
2765
#endif
2766
2767
#ifdef TICOFF_DEFAULT_MAGIC
2768
    case TICOFF_TARGET_ARCH:
2769
      /* If there's no indication of which version we want, use the default.  */
2770
      if (!abfd->xvec )
2771
  *magicp = TICOFF_DEFAULT_MAGIC;
2772
      else
2773
  {
2774
    /* We may want to output in a different COFF version.  */
2775
    switch (abfd->xvec->name[4])
2776
      {
2777
      case '0':
2778
        *magicp = TICOFF0MAGIC;
2779
        break;
2780
      case '1':
2781
        *magicp = TICOFF1MAGIC;
2782
        break;
2783
      case '2':
2784
        *magicp = TICOFF2MAGIC;
2785
        break;
2786
      default:
2787
        return false;
2788
      }
2789
  }
2790
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2791
      return true;
2792
#endif
2793
2794
#ifdef AARCH64MAGIC
2795
    case bfd_arch_aarch64:
2796
      * magicp = AARCH64MAGIC;
2797
      return true;
2798
#endif
2799
2800
#ifdef LOONGARCH64MAGIC
2801
    case bfd_arch_loongarch:
2802
      * magicp = LOONGARCH64MAGIC;
2803
      return true;
2804
#endif
2805
2806
#ifdef RISCV64MAGIC
2807
    case bfd_arch_riscv:
2808
      * magicp = RISCV64MAGIC;
2809
      return true;
2810
#endif
2811
2812
#ifdef ARMMAGIC
2813
    case bfd_arch_arm:
2814
#ifdef ARM_WINCE
2815
      * magicp = ARMPEMAGIC;
2816
#else
2817
      * magicp = ARMMAGIC;
2818
#endif
2819
      * flagsp = 0;
2820
      if (APCS_SET (abfd))
2821
  {
2822
    if (APCS_26_FLAG (abfd))
2823
      * flagsp |= F_APCS26;
2824
2825
    if (APCS_FLOAT_FLAG (abfd))
2826
      * flagsp |= F_APCS_FLOAT;
2827
2828
    if (PIC_FLAG (abfd))
2829
      * flagsp |= F_PIC;
2830
  }
2831
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2832
  * flagsp |= F_INTERWORK;
2833
      switch (bfd_get_mach (abfd))
2834
  {
2835
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2836
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2837
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2838
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2839
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2840
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2841
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2842
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2843
       See also the comment in coff_set_arch_mach_hook().  */
2844
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2845
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2846
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2847
  }
2848
      return true;
2849
#endif
2850
2851
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2852
    case bfd_arch_i386:
2853
#if defined(I386MAGIC)
2854
      *magicp = I386MAGIC;
2855
#endif
2856
#if defined LYNXOS
2857
      /* Just overwrite the usual value if we're doing Lynx.  */
2858
      *magicp = LYNXCOFFMAGIC;
2859
#endif
2860
#if defined AMD64MAGIC
2861
      *magicp = AMD64MAGIC;
2862
#endif
2863
      return true;
2864
#endif
2865
2866
0
#ifdef IA64MAGIC
2867
100
    case bfd_arch_ia64:
2868
100
      *magicp = IA64MAGIC;
2869
100
      return true;
2870
0
#endif
2871
2872
#ifdef SH_ARCH_MAGIC_BIG
2873
    case bfd_arch_sh:
2874
#ifdef COFF_IMAGE_WITH_PE
2875
      *magicp = SH_ARCH_MAGIC_WINCE;
2876
#else
2877
      if (bfd_big_endian (abfd))
2878
  *magicp = SH_ARCH_MAGIC_BIG;
2879
      else
2880
  *magicp = SH_ARCH_MAGIC_LITTLE;
2881
#endif
2882
      return true;
2883
#endif
2884
2885
#ifdef MIPS_ARCH_MAGIC_WINCE
2886
    case bfd_arch_mips:
2887
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2888
      return true;
2889
#endif
2890
2891
#ifdef SPARCMAGIC
2892
    case bfd_arch_sparc:
2893
      *magicp = SPARCMAGIC;
2894
#ifdef LYNXOS
2895
      /* Just overwrite the usual value if we're doing Lynx.  */
2896
      *magicp = LYNXCOFFMAGIC;
2897
#endif
2898
      return true;
2899
#endif
2900
2901
#ifdef RS6000COFF_C
2902
    case bfd_arch_rs6000:
2903
    case bfd_arch_powerpc:
2904
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2905
      *magicp = bfd_xcoff_magic_number (abfd);
2906
      return true;
2907
#endif
2908
2909
#ifdef MCOREMAGIC
2910
    case bfd_arch_mcore:
2911
      * magicp = MCOREMAGIC;
2912
      return true;
2913
#endif
2914
2915
0
    default:      /* Unknown architecture.  */
2916
0
      break;
2917
100
    }
2918
2919
0
  return false;
2920
100
}
pei-loongarch64.c:coff_set_flags
Line
Count
Source
2723
117
{
2724
117
  switch (bfd_get_arch (abfd))
2725
117
    {
2726
#ifdef Z80MAGIC
2727
    case bfd_arch_z80:
2728
      *magicp = Z80MAGIC;
2729
      switch (bfd_get_mach (abfd))
2730
  {
2731
  case bfd_mach_z80strict:
2732
  case bfd_mach_z80:
2733
  case bfd_mach_z80n:
2734
  case bfd_mach_z80full:
2735
  case bfd_mach_r800:
2736
  case bfd_mach_gbz80:
2737
  case bfd_mach_z180:
2738
  case bfd_mach_ez80_z80:
2739
  case bfd_mach_ez80_adl:
2740
    *flagsp = bfd_get_mach (abfd) << 12;
2741
    break;
2742
  default:
2743
    return false;
2744
  }
2745
      return true;
2746
#endif
2747
2748
#ifdef Z8KMAGIC
2749
    case bfd_arch_z8k:
2750
      *magicp = Z8KMAGIC;
2751
2752
      switch (bfd_get_mach (abfd))
2753
  {
2754
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2755
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2756
  default:       return false;
2757
  }
2758
      return true;
2759
#endif
2760
2761
#ifdef TIC30MAGIC
2762
    case bfd_arch_tic30:
2763
      *magicp = TIC30MAGIC;
2764
      return true;
2765
#endif
2766
2767
#ifdef TICOFF_DEFAULT_MAGIC
2768
    case TICOFF_TARGET_ARCH:
2769
      /* If there's no indication of which version we want, use the default.  */
2770
      if (!abfd->xvec )
2771
  *magicp = TICOFF_DEFAULT_MAGIC;
2772
      else
2773
  {
2774
    /* We may want to output in a different COFF version.  */
2775
    switch (abfd->xvec->name[4])
2776
      {
2777
      case '0':
2778
        *magicp = TICOFF0MAGIC;
2779
        break;
2780
      case '1':
2781
        *magicp = TICOFF1MAGIC;
2782
        break;
2783
      case '2':
2784
        *magicp = TICOFF2MAGIC;
2785
        break;
2786
      default:
2787
        return false;
2788
      }
2789
  }
2790
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2791
      return true;
2792
#endif
2793
2794
#ifdef AARCH64MAGIC
2795
    case bfd_arch_aarch64:
2796
      * magicp = AARCH64MAGIC;
2797
      return true;
2798
#endif
2799
2800
0
#ifdef LOONGARCH64MAGIC
2801
117
    case bfd_arch_loongarch:
2802
117
      * magicp = LOONGARCH64MAGIC;
2803
117
      return true;
2804
0
#endif
2805
2806
#ifdef RISCV64MAGIC
2807
    case bfd_arch_riscv:
2808
      * magicp = RISCV64MAGIC;
2809
      return true;
2810
#endif
2811
2812
#ifdef ARMMAGIC
2813
    case bfd_arch_arm:
2814
#ifdef ARM_WINCE
2815
      * magicp = ARMPEMAGIC;
2816
#else
2817
      * magicp = ARMMAGIC;
2818
#endif
2819
      * flagsp = 0;
2820
      if (APCS_SET (abfd))
2821
  {
2822
    if (APCS_26_FLAG (abfd))
2823
      * flagsp |= F_APCS26;
2824
2825
    if (APCS_FLOAT_FLAG (abfd))
2826
      * flagsp |= F_APCS_FLOAT;
2827
2828
    if (PIC_FLAG (abfd))
2829
      * flagsp |= F_PIC;
2830
  }
2831
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2832
  * flagsp |= F_INTERWORK;
2833
      switch (bfd_get_mach (abfd))
2834
  {
2835
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2836
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2837
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2838
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2839
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2840
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2841
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2842
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2843
       See also the comment in coff_set_arch_mach_hook().  */
2844
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2845
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2846
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2847
  }
2848
      return true;
2849
#endif
2850
2851
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2852
    case bfd_arch_i386:
2853
#if defined(I386MAGIC)
2854
      *magicp = I386MAGIC;
2855
#endif
2856
#if defined LYNXOS
2857
      /* Just overwrite the usual value if we're doing Lynx.  */
2858
      *magicp = LYNXCOFFMAGIC;
2859
#endif
2860
#if defined AMD64MAGIC
2861
      *magicp = AMD64MAGIC;
2862
#endif
2863
      return true;
2864
#endif
2865
2866
#ifdef IA64MAGIC
2867
    case bfd_arch_ia64:
2868
      *magicp = IA64MAGIC;
2869
      return true;
2870
#endif
2871
2872
#ifdef SH_ARCH_MAGIC_BIG
2873
    case bfd_arch_sh:
2874
#ifdef COFF_IMAGE_WITH_PE
2875
      *magicp = SH_ARCH_MAGIC_WINCE;
2876
#else
2877
      if (bfd_big_endian (abfd))
2878
  *magicp = SH_ARCH_MAGIC_BIG;
2879
      else
2880
  *magicp = SH_ARCH_MAGIC_LITTLE;
2881
#endif
2882
      return true;
2883
#endif
2884
2885
#ifdef MIPS_ARCH_MAGIC_WINCE
2886
    case bfd_arch_mips:
2887
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2888
      return true;
2889
#endif
2890
2891
#ifdef SPARCMAGIC
2892
    case bfd_arch_sparc:
2893
      *magicp = SPARCMAGIC;
2894
#ifdef LYNXOS
2895
      /* Just overwrite the usual value if we're doing Lynx.  */
2896
      *magicp = LYNXCOFFMAGIC;
2897
#endif
2898
      return true;
2899
#endif
2900
2901
#ifdef RS6000COFF_C
2902
    case bfd_arch_rs6000:
2903
    case bfd_arch_powerpc:
2904
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2905
      *magicp = bfd_xcoff_magic_number (abfd);
2906
      return true;
2907
#endif
2908
2909
#ifdef MCOREMAGIC
2910
    case bfd_arch_mcore:
2911
      * magicp = MCOREMAGIC;
2912
      return true;
2913
#endif
2914
2915
0
    default:      /* Unknown architecture.  */
2916
0
      break;
2917
117
    }
2918
2919
0
  return false;
2920
117
}
pei-riscv64.c:coff_set_flags
Line
Count
Source
2723
94
{
2724
94
  switch (bfd_get_arch (abfd))
2725
94
    {
2726
#ifdef Z80MAGIC
2727
    case bfd_arch_z80:
2728
      *magicp = Z80MAGIC;
2729
      switch (bfd_get_mach (abfd))
2730
  {
2731
  case bfd_mach_z80strict:
2732
  case bfd_mach_z80:
2733
  case bfd_mach_z80n:
2734
  case bfd_mach_z80full:
2735
  case bfd_mach_r800:
2736
  case bfd_mach_gbz80:
2737
  case bfd_mach_z180:
2738
  case bfd_mach_ez80_z80:
2739
  case bfd_mach_ez80_adl:
2740
    *flagsp = bfd_get_mach (abfd) << 12;
2741
    break;
2742
  default:
2743
    return false;
2744
  }
2745
      return true;
2746
#endif
2747
2748
#ifdef Z8KMAGIC
2749
    case bfd_arch_z8k:
2750
      *magicp = Z8KMAGIC;
2751
2752
      switch (bfd_get_mach (abfd))
2753
  {
2754
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2755
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2756
  default:       return false;
2757
  }
2758
      return true;
2759
#endif
2760
2761
#ifdef TIC30MAGIC
2762
    case bfd_arch_tic30:
2763
      *magicp = TIC30MAGIC;
2764
      return true;
2765
#endif
2766
2767
#ifdef TICOFF_DEFAULT_MAGIC
2768
    case TICOFF_TARGET_ARCH:
2769
      /* If there's no indication of which version we want, use the default.  */
2770
      if (!abfd->xvec )
2771
  *magicp = TICOFF_DEFAULT_MAGIC;
2772
      else
2773
  {
2774
    /* We may want to output in a different COFF version.  */
2775
    switch (abfd->xvec->name[4])
2776
      {
2777
      case '0':
2778
        *magicp = TICOFF0MAGIC;
2779
        break;
2780
      case '1':
2781
        *magicp = TICOFF1MAGIC;
2782
        break;
2783
      case '2':
2784
        *magicp = TICOFF2MAGIC;
2785
        break;
2786
      default:
2787
        return false;
2788
      }
2789
  }
2790
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2791
      return true;
2792
#endif
2793
2794
#ifdef AARCH64MAGIC
2795
    case bfd_arch_aarch64:
2796
      * magicp = AARCH64MAGIC;
2797
      return true;
2798
#endif
2799
2800
#ifdef LOONGARCH64MAGIC
2801
    case bfd_arch_loongarch:
2802
      * magicp = LOONGARCH64MAGIC;
2803
      return true;
2804
#endif
2805
2806
0
#ifdef RISCV64MAGIC
2807
94
    case bfd_arch_riscv:
2808
94
      * magicp = RISCV64MAGIC;
2809
94
      return true;
2810
0
#endif
2811
2812
#ifdef ARMMAGIC
2813
    case bfd_arch_arm:
2814
#ifdef ARM_WINCE
2815
      * magicp = ARMPEMAGIC;
2816
#else
2817
      * magicp = ARMMAGIC;
2818
#endif
2819
      * flagsp = 0;
2820
      if (APCS_SET (abfd))
2821
  {
2822
    if (APCS_26_FLAG (abfd))
2823
      * flagsp |= F_APCS26;
2824
2825
    if (APCS_FLOAT_FLAG (abfd))
2826
      * flagsp |= F_APCS_FLOAT;
2827
2828
    if (PIC_FLAG (abfd))
2829
      * flagsp |= F_PIC;
2830
  }
2831
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2832
  * flagsp |= F_INTERWORK;
2833
      switch (bfd_get_mach (abfd))
2834
  {
2835
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2836
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2837
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2838
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2839
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2840
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2841
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2842
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2843
       See also the comment in coff_set_arch_mach_hook().  */
2844
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2845
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2846
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2847
  }
2848
      return true;
2849
#endif
2850
2851
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2852
    case bfd_arch_i386:
2853
#if defined(I386MAGIC)
2854
      *magicp = I386MAGIC;
2855
#endif
2856
#if defined LYNXOS
2857
      /* Just overwrite the usual value if we're doing Lynx.  */
2858
      *magicp = LYNXCOFFMAGIC;
2859
#endif
2860
#if defined AMD64MAGIC
2861
      *magicp = AMD64MAGIC;
2862
#endif
2863
      return true;
2864
#endif
2865
2866
#ifdef IA64MAGIC
2867
    case bfd_arch_ia64:
2868
      *magicp = IA64MAGIC;
2869
      return true;
2870
#endif
2871
2872
#ifdef SH_ARCH_MAGIC_BIG
2873
    case bfd_arch_sh:
2874
#ifdef COFF_IMAGE_WITH_PE
2875
      *magicp = SH_ARCH_MAGIC_WINCE;
2876
#else
2877
      if (bfd_big_endian (abfd))
2878
  *magicp = SH_ARCH_MAGIC_BIG;
2879
      else
2880
  *magicp = SH_ARCH_MAGIC_LITTLE;
2881
#endif
2882
      return true;
2883
#endif
2884
2885
#ifdef MIPS_ARCH_MAGIC_WINCE
2886
    case bfd_arch_mips:
2887
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2888
      return true;
2889
#endif
2890
2891
#ifdef SPARCMAGIC
2892
    case bfd_arch_sparc:
2893
      *magicp = SPARCMAGIC;
2894
#ifdef LYNXOS
2895
      /* Just overwrite the usual value if we're doing Lynx.  */
2896
      *magicp = LYNXCOFFMAGIC;
2897
#endif
2898
      return true;
2899
#endif
2900
2901
#ifdef RS6000COFF_C
2902
    case bfd_arch_rs6000:
2903
    case bfd_arch_powerpc:
2904
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2905
      *magicp = bfd_xcoff_magic_number (abfd);
2906
      return true;
2907
#endif
2908
2909
#ifdef MCOREMAGIC
2910
    case bfd_arch_mcore:
2911
      * magicp = MCOREMAGIC;
2912
      return true;
2913
#endif
2914
2915
0
    default:      /* Unknown architecture.  */
2916
0
      break;
2917
94
    }
2918
2919
0
  return false;
2920
94
}
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
2723
159
{
2724
159
  switch (bfd_get_arch (abfd))
2725
159
    {
2726
#ifdef Z80MAGIC
2727
    case bfd_arch_z80:
2728
      *magicp = Z80MAGIC;
2729
      switch (bfd_get_mach (abfd))
2730
  {
2731
  case bfd_mach_z80strict:
2732
  case bfd_mach_z80:
2733
  case bfd_mach_z80n:
2734
  case bfd_mach_z80full:
2735
  case bfd_mach_r800:
2736
  case bfd_mach_gbz80:
2737
  case bfd_mach_z180:
2738
  case bfd_mach_ez80_z80:
2739
  case bfd_mach_ez80_adl:
2740
    *flagsp = bfd_get_mach (abfd) << 12;
2741
    break;
2742
  default:
2743
    return false;
2744
  }
2745
      return true;
2746
#endif
2747
2748
#ifdef Z8KMAGIC
2749
    case bfd_arch_z8k:
2750
      *magicp = Z8KMAGIC;
2751
2752
      switch (bfd_get_mach (abfd))
2753
  {
2754
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2755
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2756
  default:       return false;
2757
  }
2758
      return true;
2759
#endif
2760
2761
#ifdef TIC30MAGIC
2762
    case bfd_arch_tic30:
2763
      *magicp = TIC30MAGIC;
2764
      return true;
2765
#endif
2766
2767
#ifdef TICOFF_DEFAULT_MAGIC
2768
    case TICOFF_TARGET_ARCH:
2769
      /* If there's no indication of which version we want, use the default.  */
2770
      if (!abfd->xvec )
2771
  *magicp = TICOFF_DEFAULT_MAGIC;
2772
      else
2773
  {
2774
    /* We may want to output in a different COFF version.  */
2775
    switch (abfd->xvec->name[4])
2776
      {
2777
      case '0':
2778
        *magicp = TICOFF0MAGIC;
2779
        break;
2780
      case '1':
2781
        *magicp = TICOFF1MAGIC;
2782
        break;
2783
      case '2':
2784
        *magicp = TICOFF2MAGIC;
2785
        break;
2786
      default:
2787
        return false;
2788
      }
2789
  }
2790
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2791
      return true;
2792
#endif
2793
2794
#ifdef AARCH64MAGIC
2795
    case bfd_arch_aarch64:
2796
      * magicp = AARCH64MAGIC;
2797
      return true;
2798
#endif
2799
2800
#ifdef LOONGARCH64MAGIC
2801
    case bfd_arch_loongarch:
2802
      * magicp = LOONGARCH64MAGIC;
2803
      return true;
2804
#endif
2805
2806
#ifdef RISCV64MAGIC
2807
    case bfd_arch_riscv:
2808
      * magicp = RISCV64MAGIC;
2809
      return true;
2810
#endif
2811
2812
#ifdef ARMMAGIC
2813
    case bfd_arch_arm:
2814
#ifdef ARM_WINCE
2815
      * magicp = ARMPEMAGIC;
2816
#else
2817
      * magicp = ARMMAGIC;
2818
#endif
2819
      * flagsp = 0;
2820
      if (APCS_SET (abfd))
2821
  {
2822
    if (APCS_26_FLAG (abfd))
2823
      * flagsp |= F_APCS26;
2824
2825
    if (APCS_FLOAT_FLAG (abfd))
2826
      * flagsp |= F_APCS_FLOAT;
2827
2828
    if (PIC_FLAG (abfd))
2829
      * flagsp |= F_PIC;
2830
  }
2831
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2832
  * flagsp |= F_INTERWORK;
2833
      switch (bfd_get_mach (abfd))
2834
  {
2835
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2836
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2837
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2838
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2839
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2840
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2841
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2842
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2843
       See also the comment in coff_set_arch_mach_hook().  */
2844
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2845
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2846
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2847
  }
2848
      return true;
2849
#endif
2850
2851
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2852
    case bfd_arch_i386:
2853
#if defined(I386MAGIC)
2854
      *magicp = I386MAGIC;
2855
#endif
2856
#if defined LYNXOS
2857
      /* Just overwrite the usual value if we're doing Lynx.  */
2858
      *magicp = LYNXCOFFMAGIC;
2859
#endif
2860
#if defined AMD64MAGIC
2861
      *magicp = AMD64MAGIC;
2862
#endif
2863
      return true;
2864
#endif
2865
2866
#ifdef IA64MAGIC
2867
    case bfd_arch_ia64:
2868
      *magicp = IA64MAGIC;
2869
      return true;
2870
#endif
2871
2872
#ifdef SH_ARCH_MAGIC_BIG
2873
    case bfd_arch_sh:
2874
#ifdef COFF_IMAGE_WITH_PE
2875
      *magicp = SH_ARCH_MAGIC_WINCE;
2876
#else
2877
      if (bfd_big_endian (abfd))
2878
  *magicp = SH_ARCH_MAGIC_BIG;
2879
      else
2880
  *magicp = SH_ARCH_MAGIC_LITTLE;
2881
#endif
2882
      return true;
2883
#endif
2884
2885
#ifdef MIPS_ARCH_MAGIC_WINCE
2886
    case bfd_arch_mips:
2887
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2888
      return true;
2889
#endif
2890
2891
#ifdef SPARCMAGIC
2892
    case bfd_arch_sparc:
2893
      *magicp = SPARCMAGIC;
2894
#ifdef LYNXOS
2895
      /* Just overwrite the usual value if we're doing Lynx.  */
2896
      *magicp = LYNXCOFFMAGIC;
2897
#endif
2898
      return true;
2899
#endif
2900
2901
0
#ifdef RS6000COFF_C
2902
159
    case bfd_arch_rs6000:
2903
159
    case bfd_arch_powerpc:
2904
159
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2905
159
      *magicp = bfd_xcoff_magic_number (abfd);
2906
159
      return true;
2907
0
#endif
2908
2909
#ifdef MCOREMAGIC
2910
    case bfd_arch_mcore:
2911
      * magicp = MCOREMAGIC;
2912
      return true;
2913
#endif
2914
2915
0
    default:      /* Unknown architecture.  */
2916
0
      break;
2917
159
    }
2918
2919
0
  return false;
2920
159
}
coff-sh.c:coff_set_flags
Line
Count
Source
2723
109
{
2724
109
  switch (bfd_get_arch (abfd))
2725
109
    {
2726
#ifdef Z80MAGIC
2727
    case bfd_arch_z80:
2728
      *magicp = Z80MAGIC;
2729
      switch (bfd_get_mach (abfd))
2730
  {
2731
  case bfd_mach_z80strict:
2732
  case bfd_mach_z80:
2733
  case bfd_mach_z80n:
2734
  case bfd_mach_z80full:
2735
  case bfd_mach_r800:
2736
  case bfd_mach_gbz80:
2737
  case bfd_mach_z180:
2738
  case bfd_mach_ez80_z80:
2739
  case bfd_mach_ez80_adl:
2740
    *flagsp = bfd_get_mach (abfd) << 12;
2741
    break;
2742
  default:
2743
    return false;
2744
  }
2745
      return true;
2746
#endif
2747
2748
#ifdef Z8KMAGIC
2749
    case bfd_arch_z8k:
2750
      *magicp = Z8KMAGIC;
2751
2752
      switch (bfd_get_mach (abfd))
2753
  {
2754
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2755
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2756
  default:       return false;
2757
  }
2758
      return true;
2759
#endif
2760
2761
#ifdef TIC30MAGIC
2762
    case bfd_arch_tic30:
2763
      *magicp = TIC30MAGIC;
2764
      return true;
2765
#endif
2766
2767
#ifdef TICOFF_DEFAULT_MAGIC
2768
    case TICOFF_TARGET_ARCH:
2769
      /* If there's no indication of which version we want, use the default.  */
2770
      if (!abfd->xvec )
2771
  *magicp = TICOFF_DEFAULT_MAGIC;
2772
      else
2773
  {
2774
    /* We may want to output in a different COFF version.  */
2775
    switch (abfd->xvec->name[4])
2776
      {
2777
      case '0':
2778
        *magicp = TICOFF0MAGIC;
2779
        break;
2780
      case '1':
2781
        *magicp = TICOFF1MAGIC;
2782
        break;
2783
      case '2':
2784
        *magicp = TICOFF2MAGIC;
2785
        break;
2786
      default:
2787
        return false;
2788
      }
2789
  }
2790
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2791
      return true;
2792
#endif
2793
2794
#ifdef AARCH64MAGIC
2795
    case bfd_arch_aarch64:
2796
      * magicp = AARCH64MAGIC;
2797
      return true;
2798
#endif
2799
2800
#ifdef LOONGARCH64MAGIC
2801
    case bfd_arch_loongarch:
2802
      * magicp = LOONGARCH64MAGIC;
2803
      return true;
2804
#endif
2805
2806
#ifdef RISCV64MAGIC
2807
    case bfd_arch_riscv:
2808
      * magicp = RISCV64MAGIC;
2809
      return true;
2810
#endif
2811
2812
#ifdef ARMMAGIC
2813
    case bfd_arch_arm:
2814
#ifdef ARM_WINCE
2815
      * magicp = ARMPEMAGIC;
2816
#else
2817
      * magicp = ARMMAGIC;
2818
#endif
2819
      * flagsp = 0;
2820
      if (APCS_SET (abfd))
2821
  {
2822
    if (APCS_26_FLAG (abfd))
2823
      * flagsp |= F_APCS26;
2824
2825
    if (APCS_FLOAT_FLAG (abfd))
2826
      * flagsp |= F_APCS_FLOAT;
2827
2828
    if (PIC_FLAG (abfd))
2829
      * flagsp |= F_PIC;
2830
  }
2831
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2832
  * flagsp |= F_INTERWORK;
2833
      switch (bfd_get_mach (abfd))
2834
  {
2835
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2836
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2837
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2838
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2839
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2840
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2841
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2842
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2843
       See also the comment in coff_set_arch_mach_hook().  */
2844
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2845
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2846
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2847
  }
2848
      return true;
2849
#endif
2850
2851
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2852
    case bfd_arch_i386:
2853
#if defined(I386MAGIC)
2854
      *magicp = I386MAGIC;
2855
#endif
2856
#if defined LYNXOS
2857
      /* Just overwrite the usual value if we're doing Lynx.  */
2858
      *magicp = LYNXCOFFMAGIC;
2859
#endif
2860
#if defined AMD64MAGIC
2861
      *magicp = AMD64MAGIC;
2862
#endif
2863
      return true;
2864
#endif
2865
2866
#ifdef IA64MAGIC
2867
    case bfd_arch_ia64:
2868
      *magicp = IA64MAGIC;
2869
      return true;
2870
#endif
2871
2872
0
#ifdef SH_ARCH_MAGIC_BIG
2873
109
    case bfd_arch_sh:
2874
#ifdef COFF_IMAGE_WITH_PE
2875
      *magicp = SH_ARCH_MAGIC_WINCE;
2876
#else
2877
109
      if (bfd_big_endian (abfd))
2878
4
  *magicp = SH_ARCH_MAGIC_BIG;
2879
105
      else
2880
105
  *magicp = SH_ARCH_MAGIC_LITTLE;
2881
109
#endif
2882
109
      return true;
2883
0
#endif
2884
2885
#ifdef MIPS_ARCH_MAGIC_WINCE
2886
    case bfd_arch_mips:
2887
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2888
      return true;
2889
#endif
2890
2891
#ifdef SPARCMAGIC
2892
    case bfd_arch_sparc:
2893
      *magicp = SPARCMAGIC;
2894
#ifdef LYNXOS
2895
      /* Just overwrite the usual value if we're doing Lynx.  */
2896
      *magicp = LYNXCOFFMAGIC;
2897
#endif
2898
      return true;
2899
#endif
2900
2901
#ifdef RS6000COFF_C
2902
    case bfd_arch_rs6000:
2903
    case bfd_arch_powerpc:
2904
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2905
      *magicp = bfd_xcoff_magic_number (abfd);
2906
      return true;
2907
#endif
2908
2909
#ifdef MCOREMAGIC
2910
    case bfd_arch_mcore:
2911
      * magicp = MCOREMAGIC;
2912
      return true;
2913
#endif
2914
2915
0
    default:      /* Unknown architecture.  */
2916
0
      break;
2917
109
    }
2918
2919
0
  return false;
2920
109
}
Unexecuted instantiation: coff-stgo32.c:coff_set_flags
coff-tic30.c:coff_set_flags
Line
Count
Source
2723
114
{
2724
114
  switch (bfd_get_arch (abfd))
2725
114
    {
2726
#ifdef Z80MAGIC
2727
    case bfd_arch_z80:
2728
      *magicp = Z80MAGIC;
2729
      switch (bfd_get_mach (abfd))
2730
  {
2731
  case bfd_mach_z80strict:
2732
  case bfd_mach_z80:
2733
  case bfd_mach_z80n:
2734
  case bfd_mach_z80full:
2735
  case bfd_mach_r800:
2736
  case bfd_mach_gbz80:
2737
  case bfd_mach_z180:
2738
  case bfd_mach_ez80_z80:
2739
  case bfd_mach_ez80_adl:
2740
    *flagsp = bfd_get_mach (abfd) << 12;
2741
    break;
2742
  default:
2743
    return false;
2744
  }
2745
      return true;
2746
#endif
2747
2748
#ifdef Z8KMAGIC
2749
    case bfd_arch_z8k:
2750
      *magicp = Z8KMAGIC;
2751
2752
      switch (bfd_get_mach (abfd))
2753
  {
2754
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2755
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2756
  default:       return false;
2757
  }
2758
      return true;
2759
#endif
2760
2761
0
#ifdef TIC30MAGIC
2762
114
    case bfd_arch_tic30:
2763
114
      *magicp = TIC30MAGIC;
2764
114
      return true;
2765
0
#endif
2766
2767
#ifdef TICOFF_DEFAULT_MAGIC
2768
    case TICOFF_TARGET_ARCH:
2769
      /* If there's no indication of which version we want, use the default.  */
2770
      if (!abfd->xvec )
2771
  *magicp = TICOFF_DEFAULT_MAGIC;
2772
      else
2773
  {
2774
    /* We may want to output in a different COFF version.  */
2775
    switch (abfd->xvec->name[4])
2776
      {
2777
      case '0':
2778
        *magicp = TICOFF0MAGIC;
2779
        break;
2780
      case '1':
2781
        *magicp = TICOFF1MAGIC;
2782
        break;
2783
      case '2':
2784
        *magicp = TICOFF2MAGIC;
2785
        break;
2786
      default:
2787
        return false;
2788
      }
2789
  }
2790
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2791
      return true;
2792
#endif
2793
2794
#ifdef AARCH64MAGIC
2795
    case bfd_arch_aarch64:
2796
      * magicp = AARCH64MAGIC;
2797
      return true;
2798
#endif
2799
2800
#ifdef LOONGARCH64MAGIC
2801
    case bfd_arch_loongarch:
2802
      * magicp = LOONGARCH64MAGIC;
2803
      return true;
2804
#endif
2805
2806
#ifdef RISCV64MAGIC
2807
    case bfd_arch_riscv:
2808
      * magicp = RISCV64MAGIC;
2809
      return true;
2810
#endif
2811
2812
#ifdef ARMMAGIC
2813
    case bfd_arch_arm:
2814
#ifdef ARM_WINCE
2815
      * magicp = ARMPEMAGIC;
2816
#else
2817
      * magicp = ARMMAGIC;
2818
#endif
2819
      * flagsp = 0;
2820
      if (APCS_SET (abfd))
2821
  {
2822
    if (APCS_26_FLAG (abfd))
2823
      * flagsp |= F_APCS26;
2824
2825
    if (APCS_FLOAT_FLAG (abfd))
2826
      * flagsp |= F_APCS_FLOAT;
2827
2828
    if (PIC_FLAG (abfd))
2829
      * flagsp |= F_PIC;
2830
  }
2831
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2832
  * flagsp |= F_INTERWORK;
2833
      switch (bfd_get_mach (abfd))
2834
  {
2835
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2836
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2837
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2838
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2839
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2840
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2841
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2842
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2843
       See also the comment in coff_set_arch_mach_hook().  */
2844
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2845
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2846
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2847
  }
2848
      return true;
2849
#endif
2850
2851
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2852
    case bfd_arch_i386:
2853
#if defined(I386MAGIC)
2854
      *magicp = I386MAGIC;
2855
#endif
2856
#if defined LYNXOS
2857
      /* Just overwrite the usual value if we're doing Lynx.  */
2858
      *magicp = LYNXCOFFMAGIC;
2859
#endif
2860
#if defined AMD64MAGIC
2861
      *magicp = AMD64MAGIC;
2862
#endif
2863
      return true;
2864
#endif
2865
2866
#ifdef IA64MAGIC
2867
    case bfd_arch_ia64:
2868
      *magicp = IA64MAGIC;
2869
      return true;
2870
#endif
2871
2872
#ifdef SH_ARCH_MAGIC_BIG
2873
    case bfd_arch_sh:
2874
#ifdef COFF_IMAGE_WITH_PE
2875
      *magicp = SH_ARCH_MAGIC_WINCE;
2876
#else
2877
      if (bfd_big_endian (abfd))
2878
  *magicp = SH_ARCH_MAGIC_BIG;
2879
      else
2880
  *magicp = SH_ARCH_MAGIC_LITTLE;
2881
#endif
2882
      return true;
2883
#endif
2884
2885
#ifdef MIPS_ARCH_MAGIC_WINCE
2886
    case bfd_arch_mips:
2887
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2888
      return true;
2889
#endif
2890
2891
#ifdef SPARCMAGIC
2892
    case bfd_arch_sparc:
2893
      *magicp = SPARCMAGIC;
2894
#ifdef LYNXOS
2895
      /* Just overwrite the usual value if we're doing Lynx.  */
2896
      *magicp = LYNXCOFFMAGIC;
2897
#endif
2898
      return true;
2899
#endif
2900
2901
#ifdef RS6000COFF_C
2902
    case bfd_arch_rs6000:
2903
    case bfd_arch_powerpc:
2904
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2905
      *magicp = bfd_xcoff_magic_number (abfd);
2906
      return true;
2907
#endif
2908
2909
#ifdef MCOREMAGIC
2910
    case bfd_arch_mcore:
2911
      * magicp = MCOREMAGIC;
2912
      return true;
2913
#endif
2914
2915
0
    default:      /* Unknown architecture.  */
2916
0
      break;
2917
114
    }
2918
2919
0
  return false;
2920
114
}
Unexecuted instantiation: coff-tic4x.c:coff_set_flags
coff-tic54x.c:coff_set_flags
Line
Count
Source
2723
140
{
2724
140
  switch (bfd_get_arch (abfd))
2725
140
    {
2726
#ifdef Z80MAGIC
2727
    case bfd_arch_z80:
2728
      *magicp = Z80MAGIC;
2729
      switch (bfd_get_mach (abfd))
2730
  {
2731
  case bfd_mach_z80strict:
2732
  case bfd_mach_z80:
2733
  case bfd_mach_z80n:
2734
  case bfd_mach_z80full:
2735
  case bfd_mach_r800:
2736
  case bfd_mach_gbz80:
2737
  case bfd_mach_z180:
2738
  case bfd_mach_ez80_z80:
2739
  case bfd_mach_ez80_adl:
2740
    *flagsp = bfd_get_mach (abfd) << 12;
2741
    break;
2742
  default:
2743
    return false;
2744
  }
2745
      return true;
2746
#endif
2747
2748
#ifdef Z8KMAGIC
2749
    case bfd_arch_z8k:
2750
      *magicp = Z8KMAGIC;
2751
2752
      switch (bfd_get_mach (abfd))
2753
  {
2754
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2755
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2756
  default:       return false;
2757
  }
2758
      return true;
2759
#endif
2760
2761
#ifdef TIC30MAGIC
2762
    case bfd_arch_tic30:
2763
      *magicp = TIC30MAGIC;
2764
      return true;
2765
#endif
2766
2767
0
#ifdef TICOFF_DEFAULT_MAGIC
2768
140
    case TICOFF_TARGET_ARCH:
2769
      /* If there's no indication of which version we want, use the default.  */
2770
140
      if (!abfd->xvec )
2771
0
  *magicp = TICOFF_DEFAULT_MAGIC;
2772
140
      else
2773
140
  {
2774
    /* We may want to output in a different COFF version.  */
2775
140
    switch (abfd->xvec->name[4])
2776
140
      {
2777
140
      case '0':
2778
140
        *magicp = TICOFF0MAGIC;
2779
140
        break;
2780
0
      case '1':
2781
0
        *magicp = TICOFF1MAGIC;
2782
0
        break;
2783
0
      case '2':
2784
0
        *magicp = TICOFF2MAGIC;
2785
0
        break;
2786
0
      default:
2787
0
        return false;
2788
140
      }
2789
140
  }
2790
140
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2791
140
      return true;
2792
0
#endif
2793
2794
#ifdef AARCH64MAGIC
2795
    case bfd_arch_aarch64:
2796
      * magicp = AARCH64MAGIC;
2797
      return true;
2798
#endif
2799
2800
#ifdef LOONGARCH64MAGIC
2801
    case bfd_arch_loongarch:
2802
      * magicp = LOONGARCH64MAGIC;
2803
      return true;
2804
#endif
2805
2806
#ifdef RISCV64MAGIC
2807
    case bfd_arch_riscv:
2808
      * magicp = RISCV64MAGIC;
2809
      return true;
2810
#endif
2811
2812
#ifdef ARMMAGIC
2813
    case bfd_arch_arm:
2814
#ifdef ARM_WINCE
2815
      * magicp = ARMPEMAGIC;
2816
#else
2817
      * magicp = ARMMAGIC;
2818
#endif
2819
      * flagsp = 0;
2820
      if (APCS_SET (abfd))
2821
  {
2822
    if (APCS_26_FLAG (abfd))
2823
      * flagsp |= F_APCS26;
2824
2825
    if (APCS_FLOAT_FLAG (abfd))
2826
      * flagsp |= F_APCS_FLOAT;
2827
2828
    if (PIC_FLAG (abfd))
2829
      * flagsp |= F_PIC;
2830
  }
2831
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2832
  * flagsp |= F_INTERWORK;
2833
      switch (bfd_get_mach (abfd))
2834
  {
2835
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2836
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2837
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2838
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2839
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2840
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2841
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2842
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2843
       See also the comment in coff_set_arch_mach_hook().  */
2844
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2845
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2846
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2847
  }
2848
      return true;
2849
#endif
2850
2851
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2852
    case bfd_arch_i386:
2853
#if defined(I386MAGIC)
2854
      *magicp = I386MAGIC;
2855
#endif
2856
#if defined LYNXOS
2857
      /* Just overwrite the usual value if we're doing Lynx.  */
2858
      *magicp = LYNXCOFFMAGIC;
2859
#endif
2860
#if defined AMD64MAGIC
2861
      *magicp = AMD64MAGIC;
2862
#endif
2863
      return true;
2864
#endif
2865
2866
#ifdef IA64MAGIC
2867
    case bfd_arch_ia64:
2868
      *magicp = IA64MAGIC;
2869
      return true;
2870
#endif
2871
2872
#ifdef SH_ARCH_MAGIC_BIG
2873
    case bfd_arch_sh:
2874
#ifdef COFF_IMAGE_WITH_PE
2875
      *magicp = SH_ARCH_MAGIC_WINCE;
2876
#else
2877
      if (bfd_big_endian (abfd))
2878
  *magicp = SH_ARCH_MAGIC_BIG;
2879
      else
2880
  *magicp = SH_ARCH_MAGIC_LITTLE;
2881
#endif
2882
      return true;
2883
#endif
2884
2885
#ifdef MIPS_ARCH_MAGIC_WINCE
2886
    case bfd_arch_mips:
2887
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2888
      return true;
2889
#endif
2890
2891
#ifdef SPARCMAGIC
2892
    case bfd_arch_sparc:
2893
      *magicp = SPARCMAGIC;
2894
#ifdef LYNXOS
2895
      /* Just overwrite the usual value if we're doing Lynx.  */
2896
      *magicp = LYNXCOFFMAGIC;
2897
#endif
2898
      return true;
2899
#endif
2900
2901
#ifdef RS6000COFF_C
2902
    case bfd_arch_rs6000:
2903
    case bfd_arch_powerpc:
2904
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2905
      *magicp = bfd_xcoff_magic_number (abfd);
2906
      return true;
2907
#endif
2908
2909
#ifdef MCOREMAGIC
2910
    case bfd_arch_mcore:
2911
      * magicp = MCOREMAGIC;
2912
      return true;
2913
#endif
2914
2915
0
    default:      /* Unknown architecture.  */
2916
0
      break;
2917
140
    }
2918
2919
0
  return false;
2920
140
}
coff-z80.c:coff_set_flags
Line
Count
Source
2723
85
{
2724
85
  switch (bfd_get_arch (abfd))
2725
85
    {
2726
0
#ifdef Z80MAGIC
2727
85
    case bfd_arch_z80:
2728
85
      *magicp = Z80MAGIC;
2729
85
      switch (bfd_get_mach (abfd))
2730
85
  {
2731
4
  case bfd_mach_z80strict:
2732
6
  case bfd_mach_z80:
2733
22
  case bfd_mach_z80n:
2734
24
  case bfd_mach_z80full:
2735
24
  case bfd_mach_r800:
2736
24
  case bfd_mach_gbz80:
2737
24
  case bfd_mach_z180:
2738
85
  case bfd_mach_ez80_z80:
2739
85
  case bfd_mach_ez80_adl:
2740
85
    *flagsp = bfd_get_mach (abfd) << 12;
2741
85
    break;
2742
0
  default:
2743
0
    return false;
2744
85
  }
2745
85
      return true;
2746
0
#endif
2747
2748
#ifdef Z8KMAGIC
2749
    case bfd_arch_z8k:
2750
      *magicp = Z8KMAGIC;
2751
2752
      switch (bfd_get_mach (abfd))
2753
  {
2754
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2755
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2756
  default:       return false;
2757
  }
2758
      return true;
2759
#endif
2760
2761
#ifdef TIC30MAGIC
2762
    case bfd_arch_tic30:
2763
      *magicp = TIC30MAGIC;
2764
      return true;
2765
#endif
2766
2767
#ifdef TICOFF_DEFAULT_MAGIC
2768
    case TICOFF_TARGET_ARCH:
2769
      /* If there's no indication of which version we want, use the default.  */
2770
      if (!abfd->xvec )
2771
  *magicp = TICOFF_DEFAULT_MAGIC;
2772
      else
2773
  {
2774
    /* We may want to output in a different COFF version.  */
2775
    switch (abfd->xvec->name[4])
2776
      {
2777
      case '0':
2778
        *magicp = TICOFF0MAGIC;
2779
        break;
2780
      case '1':
2781
        *magicp = TICOFF1MAGIC;
2782
        break;
2783
      case '2':
2784
        *magicp = TICOFF2MAGIC;
2785
        break;
2786
      default:
2787
        return false;
2788
      }
2789
  }
2790
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2791
      return true;
2792
#endif
2793
2794
#ifdef AARCH64MAGIC
2795
    case bfd_arch_aarch64:
2796
      * magicp = AARCH64MAGIC;
2797
      return true;
2798
#endif
2799
2800
#ifdef LOONGARCH64MAGIC
2801
    case bfd_arch_loongarch:
2802
      * magicp = LOONGARCH64MAGIC;
2803
      return true;
2804
#endif
2805
2806
#ifdef RISCV64MAGIC
2807
    case bfd_arch_riscv:
2808
      * magicp = RISCV64MAGIC;
2809
      return true;
2810
#endif
2811
2812
#ifdef ARMMAGIC
2813
    case bfd_arch_arm:
2814
#ifdef ARM_WINCE
2815
      * magicp = ARMPEMAGIC;
2816
#else
2817
      * magicp = ARMMAGIC;
2818
#endif
2819
      * flagsp = 0;
2820
      if (APCS_SET (abfd))
2821
  {
2822
    if (APCS_26_FLAG (abfd))
2823
      * flagsp |= F_APCS26;
2824
2825
    if (APCS_FLOAT_FLAG (abfd))
2826
      * flagsp |= F_APCS_FLOAT;
2827
2828
    if (PIC_FLAG (abfd))
2829
      * flagsp |= F_PIC;
2830
  }
2831
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2832
  * flagsp |= F_INTERWORK;
2833
      switch (bfd_get_mach (abfd))
2834
  {
2835
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2836
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2837
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2838
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2839
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2840
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2841
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2842
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2843
       See also the comment in coff_set_arch_mach_hook().  */
2844
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2845
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2846
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2847
  }
2848
      return true;
2849
#endif
2850
2851
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2852
    case bfd_arch_i386:
2853
#if defined(I386MAGIC)
2854
      *magicp = I386MAGIC;
2855
#endif
2856
#if defined LYNXOS
2857
      /* Just overwrite the usual value if we're doing Lynx.  */
2858
      *magicp = LYNXCOFFMAGIC;
2859
#endif
2860
#if defined AMD64MAGIC
2861
      *magicp = AMD64MAGIC;
2862
#endif
2863
      return true;
2864
#endif
2865
2866
#ifdef IA64MAGIC
2867
    case bfd_arch_ia64:
2868
      *magicp = IA64MAGIC;
2869
      return true;
2870
#endif
2871
2872
#ifdef SH_ARCH_MAGIC_BIG
2873
    case bfd_arch_sh:
2874
#ifdef COFF_IMAGE_WITH_PE
2875
      *magicp = SH_ARCH_MAGIC_WINCE;
2876
#else
2877
      if (bfd_big_endian (abfd))
2878
  *magicp = SH_ARCH_MAGIC_BIG;
2879
      else
2880
  *magicp = SH_ARCH_MAGIC_LITTLE;
2881
#endif
2882
      return true;
2883
#endif
2884
2885
#ifdef MIPS_ARCH_MAGIC_WINCE
2886
    case bfd_arch_mips:
2887
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2888
      return true;
2889
#endif
2890
2891
#ifdef SPARCMAGIC
2892
    case bfd_arch_sparc:
2893
      *magicp = SPARCMAGIC;
2894
#ifdef LYNXOS
2895
      /* Just overwrite the usual value if we're doing Lynx.  */
2896
      *magicp = LYNXCOFFMAGIC;
2897
#endif
2898
      return true;
2899
#endif
2900
2901
#ifdef RS6000COFF_C
2902
    case bfd_arch_rs6000:
2903
    case bfd_arch_powerpc:
2904
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2905
      *magicp = bfd_xcoff_magic_number (abfd);
2906
      return true;
2907
#endif
2908
2909
#ifdef MCOREMAGIC
2910
    case bfd_arch_mcore:
2911
      * magicp = MCOREMAGIC;
2912
      return true;
2913
#endif
2914
2915
0
    default:      /* Unknown architecture.  */
2916
0
      break;
2917
85
    }
2918
2919
0
  return false;
2920
85
}
coff-z8k.c:coff_set_flags
Line
Count
Source
2723
153
{
2724
153
  switch (bfd_get_arch (abfd))
2725
153
    {
2726
#ifdef Z80MAGIC
2727
    case bfd_arch_z80:
2728
      *magicp = Z80MAGIC;
2729
      switch (bfd_get_mach (abfd))
2730
  {
2731
  case bfd_mach_z80strict:
2732
  case bfd_mach_z80:
2733
  case bfd_mach_z80n:
2734
  case bfd_mach_z80full:
2735
  case bfd_mach_r800:
2736
  case bfd_mach_gbz80:
2737
  case bfd_mach_z180:
2738
  case bfd_mach_ez80_z80:
2739
  case bfd_mach_ez80_adl:
2740
    *flagsp = bfd_get_mach (abfd) << 12;
2741
    break;
2742
  default:
2743
    return false;
2744
  }
2745
      return true;
2746
#endif
2747
2748
0
#ifdef Z8KMAGIC
2749
153
    case bfd_arch_z8k:
2750
153
      *magicp = Z8KMAGIC;
2751
2752
153
      switch (bfd_get_mach (abfd))
2753
153
  {
2754
128
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2755
25
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2756
0
  default:       return false;
2757
153
  }
2758
153
      return true;
2759
0
#endif
2760
2761
#ifdef TIC30MAGIC
2762
    case bfd_arch_tic30:
2763
      *magicp = TIC30MAGIC;
2764
      return true;
2765
#endif
2766
2767
#ifdef TICOFF_DEFAULT_MAGIC
2768
    case TICOFF_TARGET_ARCH:
2769
      /* If there's no indication of which version we want, use the default.  */
2770
      if (!abfd->xvec )
2771
  *magicp = TICOFF_DEFAULT_MAGIC;
2772
      else
2773
  {
2774
    /* We may want to output in a different COFF version.  */
2775
    switch (abfd->xvec->name[4])
2776
      {
2777
      case '0':
2778
        *magicp = TICOFF0MAGIC;
2779
        break;
2780
      case '1':
2781
        *magicp = TICOFF1MAGIC;
2782
        break;
2783
      case '2':
2784
        *magicp = TICOFF2MAGIC;
2785
        break;
2786
      default:
2787
        return false;
2788
      }
2789
  }
2790
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2791
      return true;
2792
#endif
2793
2794
#ifdef AARCH64MAGIC
2795
    case bfd_arch_aarch64:
2796
      * magicp = AARCH64MAGIC;
2797
      return true;
2798
#endif
2799
2800
#ifdef LOONGARCH64MAGIC
2801
    case bfd_arch_loongarch:
2802
      * magicp = LOONGARCH64MAGIC;
2803
      return true;
2804
#endif
2805
2806
#ifdef RISCV64MAGIC
2807
    case bfd_arch_riscv:
2808
      * magicp = RISCV64MAGIC;
2809
      return true;
2810
#endif
2811
2812
#ifdef ARMMAGIC
2813
    case bfd_arch_arm:
2814
#ifdef ARM_WINCE
2815
      * magicp = ARMPEMAGIC;
2816
#else
2817
      * magicp = ARMMAGIC;
2818
#endif
2819
      * flagsp = 0;
2820
      if (APCS_SET (abfd))
2821
  {
2822
    if (APCS_26_FLAG (abfd))
2823
      * flagsp |= F_APCS26;
2824
2825
    if (APCS_FLOAT_FLAG (abfd))
2826
      * flagsp |= F_APCS_FLOAT;
2827
2828
    if (PIC_FLAG (abfd))
2829
      * flagsp |= F_PIC;
2830
  }
2831
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2832
  * flagsp |= F_INTERWORK;
2833
      switch (bfd_get_mach (abfd))
2834
  {
2835
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2836
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2837
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2838
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2839
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2840
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2841
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2842
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2843
       See also the comment in coff_set_arch_mach_hook().  */
2844
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2845
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2846
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2847
  }
2848
      return true;
2849
#endif
2850
2851
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2852
    case bfd_arch_i386:
2853
#if defined(I386MAGIC)
2854
      *magicp = I386MAGIC;
2855
#endif
2856
#if defined LYNXOS
2857
      /* Just overwrite the usual value if we're doing Lynx.  */
2858
      *magicp = LYNXCOFFMAGIC;
2859
#endif
2860
#if defined AMD64MAGIC
2861
      *magicp = AMD64MAGIC;
2862
#endif
2863
      return true;
2864
#endif
2865
2866
#ifdef IA64MAGIC
2867
    case bfd_arch_ia64:
2868
      *magicp = IA64MAGIC;
2869
      return true;
2870
#endif
2871
2872
#ifdef SH_ARCH_MAGIC_BIG
2873
    case bfd_arch_sh:
2874
#ifdef COFF_IMAGE_WITH_PE
2875
      *magicp = SH_ARCH_MAGIC_WINCE;
2876
#else
2877
      if (bfd_big_endian (abfd))
2878
  *magicp = SH_ARCH_MAGIC_BIG;
2879
      else
2880
  *magicp = SH_ARCH_MAGIC_LITTLE;
2881
#endif
2882
      return true;
2883
#endif
2884
2885
#ifdef MIPS_ARCH_MAGIC_WINCE
2886
    case bfd_arch_mips:
2887
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2888
      return true;
2889
#endif
2890
2891
#ifdef SPARCMAGIC
2892
    case bfd_arch_sparc:
2893
      *magicp = SPARCMAGIC;
2894
#ifdef LYNXOS
2895
      /* Just overwrite the usual value if we're doing Lynx.  */
2896
      *magicp = LYNXCOFFMAGIC;
2897
#endif
2898
      return true;
2899
#endif
2900
2901
#ifdef RS6000COFF_C
2902
    case bfd_arch_rs6000:
2903
    case bfd_arch_powerpc:
2904
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2905
      *magicp = bfd_xcoff_magic_number (abfd);
2906
      return true;
2907
#endif
2908
2909
#ifdef MCOREMAGIC
2910
    case bfd_arch_mcore:
2911
      * magicp = MCOREMAGIC;
2912
      return true;
2913
#endif
2914
2915
0
    default:      /* Unknown architecture.  */
2916
0
      break;
2917
153
    }
2918
2919
0
  return false;
2920
153
}
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
2723
122
{
2724
122
  switch (bfd_get_arch (abfd))
2725
122
    {
2726
#ifdef Z80MAGIC
2727
    case bfd_arch_z80:
2728
      *magicp = Z80MAGIC;
2729
      switch (bfd_get_mach (abfd))
2730
  {
2731
  case bfd_mach_z80strict:
2732
  case bfd_mach_z80:
2733
  case bfd_mach_z80n:
2734
  case bfd_mach_z80full:
2735
  case bfd_mach_r800:
2736
  case bfd_mach_gbz80:
2737
  case bfd_mach_z180:
2738
  case bfd_mach_ez80_z80:
2739
  case bfd_mach_ez80_adl:
2740
    *flagsp = bfd_get_mach (abfd) << 12;
2741
    break;
2742
  default:
2743
    return false;
2744
  }
2745
      return true;
2746
#endif
2747
2748
#ifdef Z8KMAGIC
2749
    case bfd_arch_z8k:
2750
      *magicp = Z8KMAGIC;
2751
2752
      switch (bfd_get_mach (abfd))
2753
  {
2754
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2755
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2756
  default:       return false;
2757
  }
2758
      return true;
2759
#endif
2760
2761
#ifdef TIC30MAGIC
2762
    case bfd_arch_tic30:
2763
      *magicp = TIC30MAGIC;
2764
      return true;
2765
#endif
2766
2767
#ifdef TICOFF_DEFAULT_MAGIC
2768
    case TICOFF_TARGET_ARCH:
2769
      /* If there's no indication of which version we want, use the default.  */
2770
      if (!abfd->xvec )
2771
  *magicp = TICOFF_DEFAULT_MAGIC;
2772
      else
2773
  {
2774
    /* We may want to output in a different COFF version.  */
2775
    switch (abfd->xvec->name[4])
2776
      {
2777
      case '0':
2778
        *magicp = TICOFF0MAGIC;
2779
        break;
2780
      case '1':
2781
        *magicp = TICOFF1MAGIC;
2782
        break;
2783
      case '2':
2784
        *magicp = TICOFF2MAGIC;
2785
        break;
2786
      default:
2787
        return false;
2788
      }
2789
  }
2790
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2791
      return true;
2792
#endif
2793
2794
#ifdef AARCH64MAGIC
2795
    case bfd_arch_aarch64:
2796
      * magicp = AARCH64MAGIC;
2797
      return true;
2798
#endif
2799
2800
#ifdef LOONGARCH64MAGIC
2801
    case bfd_arch_loongarch:
2802
      * magicp = LOONGARCH64MAGIC;
2803
      return true;
2804
#endif
2805
2806
#ifdef RISCV64MAGIC
2807
    case bfd_arch_riscv:
2808
      * magicp = RISCV64MAGIC;
2809
      return true;
2810
#endif
2811
2812
#ifdef ARMMAGIC
2813
    case bfd_arch_arm:
2814
#ifdef ARM_WINCE
2815
      * magicp = ARMPEMAGIC;
2816
#else
2817
      * magicp = ARMMAGIC;
2818
#endif
2819
      * flagsp = 0;
2820
      if (APCS_SET (abfd))
2821
  {
2822
    if (APCS_26_FLAG (abfd))
2823
      * flagsp |= F_APCS26;
2824
2825
    if (APCS_FLOAT_FLAG (abfd))
2826
      * flagsp |= F_APCS_FLOAT;
2827
2828
    if (PIC_FLAG (abfd))
2829
      * flagsp |= F_PIC;
2830
  }
2831
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2832
  * flagsp |= F_INTERWORK;
2833
      switch (bfd_get_mach (abfd))
2834
  {
2835
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2836
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2837
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2838
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2839
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2840
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2841
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2842
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2843
       See also the comment in coff_set_arch_mach_hook().  */
2844
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2845
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2846
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2847
  }
2848
      return true;
2849
#endif
2850
2851
0
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2852
122
    case bfd_arch_i386:
2853
122
#if defined(I386MAGIC)
2854
122
      *magicp = I386MAGIC;
2855
122
#endif
2856
#if defined LYNXOS
2857
      /* Just overwrite the usual value if we're doing Lynx.  */
2858
      *magicp = LYNXCOFFMAGIC;
2859
#endif
2860
#if defined AMD64MAGIC
2861
      *magicp = AMD64MAGIC;
2862
#endif
2863
122
      return true;
2864
0
#endif
2865
2866
#ifdef IA64MAGIC
2867
    case bfd_arch_ia64:
2868
      *magicp = IA64MAGIC;
2869
      return true;
2870
#endif
2871
2872
#ifdef SH_ARCH_MAGIC_BIG
2873
    case bfd_arch_sh:
2874
#ifdef COFF_IMAGE_WITH_PE
2875
      *magicp = SH_ARCH_MAGIC_WINCE;
2876
#else
2877
      if (bfd_big_endian (abfd))
2878
  *magicp = SH_ARCH_MAGIC_BIG;
2879
      else
2880
  *magicp = SH_ARCH_MAGIC_LITTLE;
2881
#endif
2882
      return true;
2883
#endif
2884
2885
#ifdef MIPS_ARCH_MAGIC_WINCE
2886
    case bfd_arch_mips:
2887
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2888
      return true;
2889
#endif
2890
2891
#ifdef SPARCMAGIC
2892
    case bfd_arch_sparc:
2893
      *magicp = SPARCMAGIC;
2894
#ifdef LYNXOS
2895
      /* Just overwrite the usual value if we're doing Lynx.  */
2896
      *magicp = LYNXCOFFMAGIC;
2897
#endif
2898
      return true;
2899
#endif
2900
2901
#ifdef RS6000COFF_C
2902
    case bfd_arch_rs6000:
2903
    case bfd_arch_powerpc:
2904
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2905
      *magicp = bfd_xcoff_magic_number (abfd);
2906
      return true;
2907
#endif
2908
2909
#ifdef MCOREMAGIC
2910
    case bfd_arch_mcore:
2911
      * magicp = MCOREMAGIC;
2912
      return true;
2913
#endif
2914
2915
0
    default:      /* Unknown architecture.  */
2916
0
      break;
2917
122
    }
2918
2919
0
  return false;
2920
122
}
pe-mcore.c:coff_set_flags
Line
Count
Source
2723
116
{
2724
116
  switch (bfd_get_arch (abfd))
2725
116
    {
2726
#ifdef Z80MAGIC
2727
    case bfd_arch_z80:
2728
      *magicp = Z80MAGIC;
2729
      switch (bfd_get_mach (abfd))
2730
  {
2731
  case bfd_mach_z80strict:
2732
  case bfd_mach_z80:
2733
  case bfd_mach_z80n:
2734
  case bfd_mach_z80full:
2735
  case bfd_mach_r800:
2736
  case bfd_mach_gbz80:
2737
  case bfd_mach_z180:
2738
  case bfd_mach_ez80_z80:
2739
  case bfd_mach_ez80_adl:
2740
    *flagsp = bfd_get_mach (abfd) << 12;
2741
    break;
2742
  default:
2743
    return false;
2744
  }
2745
      return true;
2746
#endif
2747
2748
#ifdef Z8KMAGIC
2749
    case bfd_arch_z8k:
2750
      *magicp = Z8KMAGIC;
2751
2752
      switch (bfd_get_mach (abfd))
2753
  {
2754
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2755
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2756
  default:       return false;
2757
  }
2758
      return true;
2759
#endif
2760
2761
#ifdef TIC30MAGIC
2762
    case bfd_arch_tic30:
2763
      *magicp = TIC30MAGIC;
2764
      return true;
2765
#endif
2766
2767
#ifdef TICOFF_DEFAULT_MAGIC
2768
    case TICOFF_TARGET_ARCH:
2769
      /* If there's no indication of which version we want, use the default.  */
2770
      if (!abfd->xvec )
2771
  *magicp = TICOFF_DEFAULT_MAGIC;
2772
      else
2773
  {
2774
    /* We may want to output in a different COFF version.  */
2775
    switch (abfd->xvec->name[4])
2776
      {
2777
      case '0':
2778
        *magicp = TICOFF0MAGIC;
2779
        break;
2780
      case '1':
2781
        *magicp = TICOFF1MAGIC;
2782
        break;
2783
      case '2':
2784
        *magicp = TICOFF2MAGIC;
2785
        break;
2786
      default:
2787
        return false;
2788
      }
2789
  }
2790
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2791
      return true;
2792
#endif
2793
2794
#ifdef AARCH64MAGIC
2795
    case bfd_arch_aarch64:
2796
      * magicp = AARCH64MAGIC;
2797
      return true;
2798
#endif
2799
2800
#ifdef LOONGARCH64MAGIC
2801
    case bfd_arch_loongarch:
2802
      * magicp = LOONGARCH64MAGIC;
2803
      return true;
2804
#endif
2805
2806
#ifdef RISCV64MAGIC
2807
    case bfd_arch_riscv:
2808
      * magicp = RISCV64MAGIC;
2809
      return true;
2810
#endif
2811
2812
#ifdef ARMMAGIC
2813
    case bfd_arch_arm:
2814
#ifdef ARM_WINCE
2815
      * magicp = ARMPEMAGIC;
2816
#else
2817
      * magicp = ARMMAGIC;
2818
#endif
2819
      * flagsp = 0;
2820
      if (APCS_SET (abfd))
2821
  {
2822
    if (APCS_26_FLAG (abfd))
2823
      * flagsp |= F_APCS26;
2824
2825
    if (APCS_FLOAT_FLAG (abfd))
2826
      * flagsp |= F_APCS_FLOAT;
2827
2828
    if (PIC_FLAG (abfd))
2829
      * flagsp |= F_PIC;
2830
  }
2831
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2832
  * flagsp |= F_INTERWORK;
2833
      switch (bfd_get_mach (abfd))
2834
  {
2835
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2836
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2837
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2838
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2839
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2840
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2841
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2842
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2843
       See also the comment in coff_set_arch_mach_hook().  */
2844
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2845
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2846
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2847
  }
2848
      return true;
2849
#endif
2850
2851
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2852
    case bfd_arch_i386:
2853
#if defined(I386MAGIC)
2854
      *magicp = I386MAGIC;
2855
#endif
2856
#if defined LYNXOS
2857
      /* Just overwrite the usual value if we're doing Lynx.  */
2858
      *magicp = LYNXCOFFMAGIC;
2859
#endif
2860
#if defined AMD64MAGIC
2861
      *magicp = AMD64MAGIC;
2862
#endif
2863
      return true;
2864
#endif
2865
2866
#ifdef IA64MAGIC
2867
    case bfd_arch_ia64:
2868
      *magicp = IA64MAGIC;
2869
      return true;
2870
#endif
2871
2872
#ifdef SH_ARCH_MAGIC_BIG
2873
    case bfd_arch_sh:
2874
#ifdef COFF_IMAGE_WITH_PE
2875
      *magicp = SH_ARCH_MAGIC_WINCE;
2876
#else
2877
      if (bfd_big_endian (abfd))
2878
  *magicp = SH_ARCH_MAGIC_BIG;
2879
      else
2880
  *magicp = SH_ARCH_MAGIC_LITTLE;
2881
#endif
2882
      return true;
2883
#endif
2884
2885
#ifdef MIPS_ARCH_MAGIC_WINCE
2886
    case bfd_arch_mips:
2887
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2888
      return true;
2889
#endif
2890
2891
#ifdef SPARCMAGIC
2892
    case bfd_arch_sparc:
2893
      *magicp = SPARCMAGIC;
2894
#ifdef LYNXOS
2895
      /* Just overwrite the usual value if we're doing Lynx.  */
2896
      *magicp = LYNXCOFFMAGIC;
2897
#endif
2898
      return true;
2899
#endif
2900
2901
#ifdef RS6000COFF_C
2902
    case bfd_arch_rs6000:
2903
    case bfd_arch_powerpc:
2904
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2905
      *magicp = bfd_xcoff_magic_number (abfd);
2906
      return true;
2907
#endif
2908
2909
0
#ifdef MCOREMAGIC
2910
116
    case bfd_arch_mcore:
2911
116
      * magicp = MCOREMAGIC;
2912
116
      return true;
2913
0
#endif
2914
2915
0
    default:      /* Unknown architecture.  */
2916
0
      break;
2917
116
    }
2918
2919
0
  return false;
2920
116
}
pe-sh.c:coff_set_flags
Line
Count
Source
2723
123
{
2724
123
  switch (bfd_get_arch (abfd))
2725
123
    {
2726
#ifdef Z80MAGIC
2727
    case bfd_arch_z80:
2728
      *magicp = Z80MAGIC;
2729
      switch (bfd_get_mach (abfd))
2730
  {
2731
  case bfd_mach_z80strict:
2732
  case bfd_mach_z80:
2733
  case bfd_mach_z80n:
2734
  case bfd_mach_z80full:
2735
  case bfd_mach_r800:
2736
  case bfd_mach_gbz80:
2737
  case bfd_mach_z180:
2738
  case bfd_mach_ez80_z80:
2739
  case bfd_mach_ez80_adl:
2740
    *flagsp = bfd_get_mach (abfd) << 12;
2741
    break;
2742
  default:
2743
    return false;
2744
  }
2745
      return true;
2746
#endif
2747
2748
#ifdef Z8KMAGIC
2749
    case bfd_arch_z8k:
2750
      *magicp = Z8KMAGIC;
2751
2752
      switch (bfd_get_mach (abfd))
2753
  {
2754
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2755
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2756
  default:       return false;
2757
  }
2758
      return true;
2759
#endif
2760
2761
#ifdef TIC30MAGIC
2762
    case bfd_arch_tic30:
2763
      *magicp = TIC30MAGIC;
2764
      return true;
2765
#endif
2766
2767
#ifdef TICOFF_DEFAULT_MAGIC
2768
    case TICOFF_TARGET_ARCH:
2769
      /* If there's no indication of which version we want, use the default.  */
2770
      if (!abfd->xvec )
2771
  *magicp = TICOFF_DEFAULT_MAGIC;
2772
      else
2773
  {
2774
    /* We may want to output in a different COFF version.  */
2775
    switch (abfd->xvec->name[4])
2776
      {
2777
      case '0':
2778
        *magicp = TICOFF0MAGIC;
2779
        break;
2780
      case '1':
2781
        *magicp = TICOFF1MAGIC;
2782
        break;
2783
      case '2':
2784
        *magicp = TICOFF2MAGIC;
2785
        break;
2786
      default:
2787
        return false;
2788
      }
2789
  }
2790
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2791
      return true;
2792
#endif
2793
2794
#ifdef AARCH64MAGIC
2795
    case bfd_arch_aarch64:
2796
      * magicp = AARCH64MAGIC;
2797
      return true;
2798
#endif
2799
2800
#ifdef LOONGARCH64MAGIC
2801
    case bfd_arch_loongarch:
2802
      * magicp = LOONGARCH64MAGIC;
2803
      return true;
2804
#endif
2805
2806
#ifdef RISCV64MAGIC
2807
    case bfd_arch_riscv:
2808
      * magicp = RISCV64MAGIC;
2809
      return true;
2810
#endif
2811
2812
#ifdef ARMMAGIC
2813
    case bfd_arch_arm:
2814
#ifdef ARM_WINCE
2815
      * magicp = ARMPEMAGIC;
2816
#else
2817
      * magicp = ARMMAGIC;
2818
#endif
2819
      * flagsp = 0;
2820
      if (APCS_SET (abfd))
2821
  {
2822
    if (APCS_26_FLAG (abfd))
2823
      * flagsp |= F_APCS26;
2824
2825
    if (APCS_FLOAT_FLAG (abfd))
2826
      * flagsp |= F_APCS_FLOAT;
2827
2828
    if (PIC_FLAG (abfd))
2829
      * flagsp |= F_PIC;
2830
  }
2831
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2832
  * flagsp |= F_INTERWORK;
2833
      switch (bfd_get_mach (abfd))
2834
  {
2835
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2836
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2837
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2838
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2839
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2840
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2841
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2842
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2843
       See also the comment in coff_set_arch_mach_hook().  */
2844
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2845
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2846
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2847
  }
2848
      return true;
2849
#endif
2850
2851
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2852
    case bfd_arch_i386:
2853
#if defined(I386MAGIC)
2854
      *magicp = I386MAGIC;
2855
#endif
2856
#if defined LYNXOS
2857
      /* Just overwrite the usual value if we're doing Lynx.  */
2858
      *magicp = LYNXCOFFMAGIC;
2859
#endif
2860
#if defined AMD64MAGIC
2861
      *magicp = AMD64MAGIC;
2862
#endif
2863
      return true;
2864
#endif
2865
2866
#ifdef IA64MAGIC
2867
    case bfd_arch_ia64:
2868
      *magicp = IA64MAGIC;
2869
      return true;
2870
#endif
2871
2872
0
#ifdef SH_ARCH_MAGIC_BIG
2873
123
    case bfd_arch_sh:
2874
#ifdef COFF_IMAGE_WITH_PE
2875
      *magicp = SH_ARCH_MAGIC_WINCE;
2876
#else
2877
123
      if (bfd_big_endian (abfd))
2878
0
  *magicp = SH_ARCH_MAGIC_BIG;
2879
123
      else
2880
123
  *magicp = SH_ARCH_MAGIC_LITTLE;
2881
123
#endif
2882
123
      return true;
2883
0
#endif
2884
2885
#ifdef MIPS_ARCH_MAGIC_WINCE
2886
    case bfd_arch_mips:
2887
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2888
      return true;
2889
#endif
2890
2891
#ifdef SPARCMAGIC
2892
    case bfd_arch_sparc:
2893
      *magicp = SPARCMAGIC;
2894
#ifdef LYNXOS
2895
      /* Just overwrite the usual value if we're doing Lynx.  */
2896
      *magicp = LYNXCOFFMAGIC;
2897
#endif
2898
      return true;
2899
#endif
2900
2901
#ifdef RS6000COFF_C
2902
    case bfd_arch_rs6000:
2903
    case bfd_arch_powerpc:
2904
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2905
      *magicp = bfd_xcoff_magic_number (abfd);
2906
      return true;
2907
#endif
2908
2909
#ifdef MCOREMAGIC
2910
    case bfd_arch_mcore:
2911
      * magicp = MCOREMAGIC;
2912
      return true;
2913
#endif
2914
2915
0
    default:      /* Unknown architecture.  */
2916
0
      break;
2917
123
    }
2918
2919
0
  return false;
2920
123
}
pei-arm-wince.c:coff_set_flags
Line
Count
Source
2723
110
{
2724
110
  switch (bfd_get_arch (abfd))
2725
110
    {
2726
#ifdef Z80MAGIC
2727
    case bfd_arch_z80:
2728
      *magicp = Z80MAGIC;
2729
      switch (bfd_get_mach (abfd))
2730
  {
2731
  case bfd_mach_z80strict:
2732
  case bfd_mach_z80:
2733
  case bfd_mach_z80n:
2734
  case bfd_mach_z80full:
2735
  case bfd_mach_r800:
2736
  case bfd_mach_gbz80:
2737
  case bfd_mach_z180:
2738
  case bfd_mach_ez80_z80:
2739
  case bfd_mach_ez80_adl:
2740
    *flagsp = bfd_get_mach (abfd) << 12;
2741
    break;
2742
  default:
2743
    return false;
2744
  }
2745
      return true;
2746
#endif
2747
2748
#ifdef Z8KMAGIC
2749
    case bfd_arch_z8k:
2750
      *magicp = Z8KMAGIC;
2751
2752
      switch (bfd_get_mach (abfd))
2753
  {
2754
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2755
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2756
  default:       return false;
2757
  }
2758
      return true;
2759
#endif
2760
2761
#ifdef TIC30MAGIC
2762
    case bfd_arch_tic30:
2763
      *magicp = TIC30MAGIC;
2764
      return true;
2765
#endif
2766
2767
#ifdef TICOFF_DEFAULT_MAGIC
2768
    case TICOFF_TARGET_ARCH:
2769
      /* If there's no indication of which version we want, use the default.  */
2770
      if (!abfd->xvec )
2771
  *magicp = TICOFF_DEFAULT_MAGIC;
2772
      else
2773
  {
2774
    /* We may want to output in a different COFF version.  */
2775
    switch (abfd->xvec->name[4])
2776
      {
2777
      case '0':
2778
        *magicp = TICOFF0MAGIC;
2779
        break;
2780
      case '1':
2781
        *magicp = TICOFF1MAGIC;
2782
        break;
2783
      case '2':
2784
        *magicp = TICOFF2MAGIC;
2785
        break;
2786
      default:
2787
        return false;
2788
      }
2789
  }
2790
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2791
      return true;
2792
#endif
2793
2794
#ifdef AARCH64MAGIC
2795
    case bfd_arch_aarch64:
2796
      * magicp = AARCH64MAGIC;
2797
      return true;
2798
#endif
2799
2800
#ifdef LOONGARCH64MAGIC
2801
    case bfd_arch_loongarch:
2802
      * magicp = LOONGARCH64MAGIC;
2803
      return true;
2804
#endif
2805
2806
#ifdef RISCV64MAGIC
2807
    case bfd_arch_riscv:
2808
      * magicp = RISCV64MAGIC;
2809
      return true;
2810
#endif
2811
2812
0
#ifdef ARMMAGIC
2813
110
    case bfd_arch_arm:
2814
#ifdef ARM_WINCE
2815
      * magicp = ARMPEMAGIC;
2816
#else
2817
110
      * magicp = ARMMAGIC;
2818
110
#endif
2819
110
      * flagsp = 0;
2820
110
      if (APCS_SET (abfd))
2821
1
  {
2822
1
    if (APCS_26_FLAG (abfd))
2823
0
      * flagsp |= F_APCS26;
2824
2825
1
    if (APCS_FLOAT_FLAG (abfd))
2826
0
      * flagsp |= F_APCS_FLOAT;
2827
2828
1
    if (PIC_FLAG (abfd))
2829
0
      * flagsp |= F_PIC;
2830
1
  }
2831
110
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2832
0
  * flagsp |= F_INTERWORK;
2833
110
      switch (bfd_get_mach (abfd))
2834
110
  {
2835
0
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2836
0
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2837
0
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2838
110
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2839
0
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2840
0
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2841
0
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2842
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2843
       See also the comment in coff_set_arch_mach_hook().  */
2844
0
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2845
0
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2846
0
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2847
110
  }
2848
110
      return true;
2849
0
#endif
2850
2851
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2852
    case bfd_arch_i386:
2853
#if defined(I386MAGIC)
2854
      *magicp = I386MAGIC;
2855
#endif
2856
#if defined LYNXOS
2857
      /* Just overwrite the usual value if we're doing Lynx.  */
2858
      *magicp = LYNXCOFFMAGIC;
2859
#endif
2860
#if defined AMD64MAGIC
2861
      *magicp = AMD64MAGIC;
2862
#endif
2863
      return true;
2864
#endif
2865
2866
#ifdef IA64MAGIC
2867
    case bfd_arch_ia64:
2868
      *magicp = IA64MAGIC;
2869
      return true;
2870
#endif
2871
2872
#ifdef SH_ARCH_MAGIC_BIG
2873
    case bfd_arch_sh:
2874
#ifdef COFF_IMAGE_WITH_PE
2875
      *magicp = SH_ARCH_MAGIC_WINCE;
2876
#else
2877
      if (bfd_big_endian (abfd))
2878
  *magicp = SH_ARCH_MAGIC_BIG;
2879
      else
2880
  *magicp = SH_ARCH_MAGIC_LITTLE;
2881
#endif
2882
      return true;
2883
#endif
2884
2885
#ifdef MIPS_ARCH_MAGIC_WINCE
2886
    case bfd_arch_mips:
2887
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2888
      return true;
2889
#endif
2890
2891
#ifdef SPARCMAGIC
2892
    case bfd_arch_sparc:
2893
      *magicp = SPARCMAGIC;
2894
#ifdef LYNXOS
2895
      /* Just overwrite the usual value if we're doing Lynx.  */
2896
      *magicp = LYNXCOFFMAGIC;
2897
#endif
2898
      return true;
2899
#endif
2900
2901
#ifdef RS6000COFF_C
2902
    case bfd_arch_rs6000:
2903
    case bfd_arch_powerpc:
2904
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2905
      *magicp = bfd_xcoff_magic_number (abfd);
2906
      return true;
2907
#endif
2908
2909
#ifdef MCOREMAGIC
2910
    case bfd_arch_mcore:
2911
      * magicp = MCOREMAGIC;
2912
      return true;
2913
#endif
2914
2915
0
    default:      /* Unknown architecture.  */
2916
0
      break;
2917
110
    }
2918
2919
0
  return false;
2920
110
}
pei-arm.c:coff_set_flags
Line
Count
Source
2723
128
{
2724
128
  switch (bfd_get_arch (abfd))
2725
128
    {
2726
#ifdef Z80MAGIC
2727
    case bfd_arch_z80:
2728
      *magicp = Z80MAGIC;
2729
      switch (bfd_get_mach (abfd))
2730
  {
2731
  case bfd_mach_z80strict:
2732
  case bfd_mach_z80:
2733
  case bfd_mach_z80n:
2734
  case bfd_mach_z80full:
2735
  case bfd_mach_r800:
2736
  case bfd_mach_gbz80:
2737
  case bfd_mach_z180:
2738
  case bfd_mach_ez80_z80:
2739
  case bfd_mach_ez80_adl:
2740
    *flagsp = bfd_get_mach (abfd) << 12;
2741
    break;
2742
  default:
2743
    return false;
2744
  }
2745
      return true;
2746
#endif
2747
2748
#ifdef Z8KMAGIC
2749
    case bfd_arch_z8k:
2750
      *magicp = Z8KMAGIC;
2751
2752
      switch (bfd_get_mach (abfd))
2753
  {
2754
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2755
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2756
  default:       return false;
2757
  }
2758
      return true;
2759
#endif
2760
2761
#ifdef TIC30MAGIC
2762
    case bfd_arch_tic30:
2763
      *magicp = TIC30MAGIC;
2764
      return true;
2765
#endif
2766
2767
#ifdef TICOFF_DEFAULT_MAGIC
2768
    case TICOFF_TARGET_ARCH:
2769
      /* If there's no indication of which version we want, use the default.  */
2770
      if (!abfd->xvec )
2771
  *magicp = TICOFF_DEFAULT_MAGIC;
2772
      else
2773
  {
2774
    /* We may want to output in a different COFF version.  */
2775
    switch (abfd->xvec->name[4])
2776
      {
2777
      case '0':
2778
        *magicp = TICOFF0MAGIC;
2779
        break;
2780
      case '1':
2781
        *magicp = TICOFF1MAGIC;
2782
        break;
2783
      case '2':
2784
        *magicp = TICOFF2MAGIC;
2785
        break;
2786
      default:
2787
        return false;
2788
      }
2789
  }
2790
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2791
      return true;
2792
#endif
2793
2794
#ifdef AARCH64MAGIC
2795
    case bfd_arch_aarch64:
2796
      * magicp = AARCH64MAGIC;
2797
      return true;
2798
#endif
2799
2800
#ifdef LOONGARCH64MAGIC
2801
    case bfd_arch_loongarch:
2802
      * magicp = LOONGARCH64MAGIC;
2803
      return true;
2804
#endif
2805
2806
#ifdef RISCV64MAGIC
2807
    case bfd_arch_riscv:
2808
      * magicp = RISCV64MAGIC;
2809
      return true;
2810
#endif
2811
2812
0
#ifdef ARMMAGIC
2813
128
    case bfd_arch_arm:
2814
#ifdef ARM_WINCE
2815
      * magicp = ARMPEMAGIC;
2816
#else
2817
128
      * magicp = ARMMAGIC;
2818
128
#endif
2819
128
      * flagsp = 0;
2820
128
      if (APCS_SET (abfd))
2821
0
  {
2822
0
    if (APCS_26_FLAG (abfd))
2823
0
      * flagsp |= F_APCS26;
2824
2825
0
    if (APCS_FLOAT_FLAG (abfd))
2826
0
      * flagsp |= F_APCS_FLOAT;
2827
2828
0
    if (PIC_FLAG (abfd))
2829
0
      * flagsp |= F_PIC;
2830
0
  }
2831
128
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2832
0
  * flagsp |= F_INTERWORK;
2833
128
      switch (bfd_get_mach (abfd))
2834
128
  {
2835
0
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2836
0
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2837
0
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2838
128
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2839
0
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2840
0
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2841
0
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2842
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2843
       See also the comment in coff_set_arch_mach_hook().  */
2844
0
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2845
0
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2846
0
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2847
128
  }
2848
128
      return true;
2849
0
#endif
2850
2851
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2852
    case bfd_arch_i386:
2853
#if defined(I386MAGIC)
2854
      *magicp = I386MAGIC;
2855
#endif
2856
#if defined LYNXOS
2857
      /* Just overwrite the usual value if we're doing Lynx.  */
2858
      *magicp = LYNXCOFFMAGIC;
2859
#endif
2860
#if defined AMD64MAGIC
2861
      *magicp = AMD64MAGIC;
2862
#endif
2863
      return true;
2864
#endif
2865
2866
#ifdef IA64MAGIC
2867
    case bfd_arch_ia64:
2868
      *magicp = IA64MAGIC;
2869
      return true;
2870
#endif
2871
2872
#ifdef SH_ARCH_MAGIC_BIG
2873
    case bfd_arch_sh:
2874
#ifdef COFF_IMAGE_WITH_PE
2875
      *magicp = SH_ARCH_MAGIC_WINCE;
2876
#else
2877
      if (bfd_big_endian (abfd))
2878
  *magicp = SH_ARCH_MAGIC_BIG;
2879
      else
2880
  *magicp = SH_ARCH_MAGIC_LITTLE;
2881
#endif
2882
      return true;
2883
#endif
2884
2885
#ifdef MIPS_ARCH_MAGIC_WINCE
2886
    case bfd_arch_mips:
2887
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2888
      return true;
2889
#endif
2890
2891
#ifdef SPARCMAGIC
2892
    case bfd_arch_sparc:
2893
      *magicp = SPARCMAGIC;
2894
#ifdef LYNXOS
2895
      /* Just overwrite the usual value if we're doing Lynx.  */
2896
      *magicp = LYNXCOFFMAGIC;
2897
#endif
2898
      return true;
2899
#endif
2900
2901
#ifdef RS6000COFF_C
2902
    case bfd_arch_rs6000:
2903
    case bfd_arch_powerpc:
2904
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2905
      *magicp = bfd_xcoff_magic_number (abfd);
2906
      return true;
2907
#endif
2908
2909
#ifdef MCOREMAGIC
2910
    case bfd_arch_mcore:
2911
      * magicp = MCOREMAGIC;
2912
      return true;
2913
#endif
2914
2915
0
    default:      /* Unknown architecture.  */
2916
0
      break;
2917
128
    }
2918
2919
0
  return false;
2920
128
}
pei-mcore.c:coff_set_flags
Line
Count
Source
2723
41
{
2724
41
  switch (bfd_get_arch (abfd))
2725
41
    {
2726
#ifdef Z80MAGIC
2727
    case bfd_arch_z80:
2728
      *magicp = Z80MAGIC;
2729
      switch (bfd_get_mach (abfd))
2730
  {
2731
  case bfd_mach_z80strict:
2732
  case bfd_mach_z80:
2733
  case bfd_mach_z80n:
2734
  case bfd_mach_z80full:
2735
  case bfd_mach_r800:
2736
  case bfd_mach_gbz80:
2737
  case bfd_mach_z180:
2738
  case bfd_mach_ez80_z80:
2739
  case bfd_mach_ez80_adl:
2740
    *flagsp = bfd_get_mach (abfd) << 12;
2741
    break;
2742
  default:
2743
    return false;
2744
  }
2745
      return true;
2746
#endif
2747
2748
#ifdef Z8KMAGIC
2749
    case bfd_arch_z8k:
2750
      *magicp = Z8KMAGIC;
2751
2752
      switch (bfd_get_mach (abfd))
2753
  {
2754
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2755
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2756
  default:       return false;
2757
  }
2758
      return true;
2759
#endif
2760
2761
#ifdef TIC30MAGIC
2762
    case bfd_arch_tic30:
2763
      *magicp = TIC30MAGIC;
2764
      return true;
2765
#endif
2766
2767
#ifdef TICOFF_DEFAULT_MAGIC
2768
    case TICOFF_TARGET_ARCH:
2769
      /* If there's no indication of which version we want, use the default.  */
2770
      if (!abfd->xvec )
2771
  *magicp = TICOFF_DEFAULT_MAGIC;
2772
      else
2773
  {
2774
    /* We may want to output in a different COFF version.  */
2775
    switch (abfd->xvec->name[4])
2776
      {
2777
      case '0':
2778
        *magicp = TICOFF0MAGIC;
2779
        break;
2780
      case '1':
2781
        *magicp = TICOFF1MAGIC;
2782
        break;
2783
      case '2':
2784
        *magicp = TICOFF2MAGIC;
2785
        break;
2786
      default:
2787
        return false;
2788
      }
2789
  }
2790
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2791
      return true;
2792
#endif
2793
2794
#ifdef AARCH64MAGIC
2795
    case bfd_arch_aarch64:
2796
      * magicp = AARCH64MAGIC;
2797
      return true;
2798
#endif
2799
2800
#ifdef LOONGARCH64MAGIC
2801
    case bfd_arch_loongarch:
2802
      * magicp = LOONGARCH64MAGIC;
2803
      return true;
2804
#endif
2805
2806
#ifdef RISCV64MAGIC
2807
    case bfd_arch_riscv:
2808
      * magicp = RISCV64MAGIC;
2809
      return true;
2810
#endif
2811
2812
#ifdef ARMMAGIC
2813
    case bfd_arch_arm:
2814
#ifdef ARM_WINCE
2815
      * magicp = ARMPEMAGIC;
2816
#else
2817
      * magicp = ARMMAGIC;
2818
#endif
2819
      * flagsp = 0;
2820
      if (APCS_SET (abfd))
2821
  {
2822
    if (APCS_26_FLAG (abfd))
2823
      * flagsp |= F_APCS26;
2824
2825
    if (APCS_FLOAT_FLAG (abfd))
2826
      * flagsp |= F_APCS_FLOAT;
2827
2828
    if (PIC_FLAG (abfd))
2829
      * flagsp |= F_PIC;
2830
  }
2831
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2832
  * flagsp |= F_INTERWORK;
2833
      switch (bfd_get_mach (abfd))
2834
  {
2835
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2836
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2837
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2838
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2839
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2840
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2841
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2842
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2843
       See also the comment in coff_set_arch_mach_hook().  */
2844
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2845
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2846
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2847
  }
2848
      return true;
2849
#endif
2850
2851
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2852
    case bfd_arch_i386:
2853
#if defined(I386MAGIC)
2854
      *magicp = I386MAGIC;
2855
#endif
2856
#if defined LYNXOS
2857
      /* Just overwrite the usual value if we're doing Lynx.  */
2858
      *magicp = LYNXCOFFMAGIC;
2859
#endif
2860
#if defined AMD64MAGIC
2861
      *magicp = AMD64MAGIC;
2862
#endif
2863
      return true;
2864
#endif
2865
2866
#ifdef IA64MAGIC
2867
    case bfd_arch_ia64:
2868
      *magicp = IA64MAGIC;
2869
      return true;
2870
#endif
2871
2872
#ifdef SH_ARCH_MAGIC_BIG
2873
    case bfd_arch_sh:
2874
#ifdef COFF_IMAGE_WITH_PE
2875
      *magicp = SH_ARCH_MAGIC_WINCE;
2876
#else
2877
      if (bfd_big_endian (abfd))
2878
  *magicp = SH_ARCH_MAGIC_BIG;
2879
      else
2880
  *magicp = SH_ARCH_MAGIC_LITTLE;
2881
#endif
2882
      return true;
2883
#endif
2884
2885
#ifdef MIPS_ARCH_MAGIC_WINCE
2886
    case bfd_arch_mips:
2887
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2888
      return true;
2889
#endif
2890
2891
#ifdef SPARCMAGIC
2892
    case bfd_arch_sparc:
2893
      *magicp = SPARCMAGIC;
2894
#ifdef LYNXOS
2895
      /* Just overwrite the usual value if we're doing Lynx.  */
2896
      *magicp = LYNXCOFFMAGIC;
2897
#endif
2898
      return true;
2899
#endif
2900
2901
#ifdef RS6000COFF_C
2902
    case bfd_arch_rs6000:
2903
    case bfd_arch_powerpc:
2904
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2905
      *magicp = bfd_xcoff_magic_number (abfd);
2906
      return true;
2907
#endif
2908
2909
0
#ifdef MCOREMAGIC
2910
41
    case bfd_arch_mcore:
2911
41
      * magicp = MCOREMAGIC;
2912
41
      return true;
2913
0
#endif
2914
2915
0
    default:      /* Unknown architecture.  */
2916
0
      break;
2917
41
    }
2918
2919
0
  return false;
2920
41
}
pei-sh.c:coff_set_flags
Line
Count
Source
2723
98
{
2724
98
  switch (bfd_get_arch (abfd))
2725
98
    {
2726
#ifdef Z80MAGIC
2727
    case bfd_arch_z80:
2728
      *magicp = Z80MAGIC;
2729
      switch (bfd_get_mach (abfd))
2730
  {
2731
  case bfd_mach_z80strict:
2732
  case bfd_mach_z80:
2733
  case bfd_mach_z80n:
2734
  case bfd_mach_z80full:
2735
  case bfd_mach_r800:
2736
  case bfd_mach_gbz80:
2737
  case bfd_mach_z180:
2738
  case bfd_mach_ez80_z80:
2739
  case bfd_mach_ez80_adl:
2740
    *flagsp = bfd_get_mach (abfd) << 12;
2741
    break;
2742
  default:
2743
    return false;
2744
  }
2745
      return true;
2746
#endif
2747
2748
#ifdef Z8KMAGIC
2749
    case bfd_arch_z8k:
2750
      *magicp = Z8KMAGIC;
2751
2752
      switch (bfd_get_mach (abfd))
2753
  {
2754
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2755
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2756
  default:       return false;
2757
  }
2758
      return true;
2759
#endif
2760
2761
#ifdef TIC30MAGIC
2762
    case bfd_arch_tic30:
2763
      *magicp = TIC30MAGIC;
2764
      return true;
2765
#endif
2766
2767
#ifdef TICOFF_DEFAULT_MAGIC
2768
    case TICOFF_TARGET_ARCH:
2769
      /* If there's no indication of which version we want, use the default.  */
2770
      if (!abfd->xvec )
2771
  *magicp = TICOFF_DEFAULT_MAGIC;
2772
      else
2773
  {
2774
    /* We may want to output in a different COFF version.  */
2775
    switch (abfd->xvec->name[4])
2776
      {
2777
      case '0':
2778
        *magicp = TICOFF0MAGIC;
2779
        break;
2780
      case '1':
2781
        *magicp = TICOFF1MAGIC;
2782
        break;
2783
      case '2':
2784
        *magicp = TICOFF2MAGIC;
2785
        break;
2786
      default:
2787
        return false;
2788
      }
2789
  }
2790
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2791
      return true;
2792
#endif
2793
2794
#ifdef AARCH64MAGIC
2795
    case bfd_arch_aarch64:
2796
      * magicp = AARCH64MAGIC;
2797
      return true;
2798
#endif
2799
2800
#ifdef LOONGARCH64MAGIC
2801
    case bfd_arch_loongarch:
2802
      * magicp = LOONGARCH64MAGIC;
2803
      return true;
2804
#endif
2805
2806
#ifdef RISCV64MAGIC
2807
    case bfd_arch_riscv:
2808
      * magicp = RISCV64MAGIC;
2809
      return true;
2810
#endif
2811
2812
#ifdef ARMMAGIC
2813
    case bfd_arch_arm:
2814
#ifdef ARM_WINCE
2815
      * magicp = ARMPEMAGIC;
2816
#else
2817
      * magicp = ARMMAGIC;
2818
#endif
2819
      * flagsp = 0;
2820
      if (APCS_SET (abfd))
2821
  {
2822
    if (APCS_26_FLAG (abfd))
2823
      * flagsp |= F_APCS26;
2824
2825
    if (APCS_FLOAT_FLAG (abfd))
2826
      * flagsp |= F_APCS_FLOAT;
2827
2828
    if (PIC_FLAG (abfd))
2829
      * flagsp |= F_PIC;
2830
  }
2831
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2832
  * flagsp |= F_INTERWORK;
2833
      switch (bfd_get_mach (abfd))
2834
  {
2835
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2836
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2837
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2838
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2839
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2840
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2841
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2842
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2843
       See also the comment in coff_set_arch_mach_hook().  */
2844
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2845
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2846
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2847
  }
2848
      return true;
2849
#endif
2850
2851
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2852
    case bfd_arch_i386:
2853
#if defined(I386MAGIC)
2854
      *magicp = I386MAGIC;
2855
#endif
2856
#if defined LYNXOS
2857
      /* Just overwrite the usual value if we're doing Lynx.  */
2858
      *magicp = LYNXCOFFMAGIC;
2859
#endif
2860
#if defined AMD64MAGIC
2861
      *magicp = AMD64MAGIC;
2862
#endif
2863
      return true;
2864
#endif
2865
2866
#ifdef IA64MAGIC
2867
    case bfd_arch_ia64:
2868
      *magicp = IA64MAGIC;
2869
      return true;
2870
#endif
2871
2872
0
#ifdef SH_ARCH_MAGIC_BIG
2873
98
    case bfd_arch_sh:
2874
98
#ifdef COFF_IMAGE_WITH_PE
2875
98
      *magicp = SH_ARCH_MAGIC_WINCE;
2876
#else
2877
      if (bfd_big_endian (abfd))
2878
  *magicp = SH_ARCH_MAGIC_BIG;
2879
      else
2880
  *magicp = SH_ARCH_MAGIC_LITTLE;
2881
#endif
2882
98
      return true;
2883
0
#endif
2884
2885
#ifdef MIPS_ARCH_MAGIC_WINCE
2886
    case bfd_arch_mips:
2887
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2888
      return true;
2889
#endif
2890
2891
#ifdef SPARCMAGIC
2892
    case bfd_arch_sparc:
2893
      *magicp = SPARCMAGIC;
2894
#ifdef LYNXOS
2895
      /* Just overwrite the usual value if we're doing Lynx.  */
2896
      *magicp = LYNXCOFFMAGIC;
2897
#endif
2898
      return true;
2899
#endif
2900
2901
#ifdef RS6000COFF_C
2902
    case bfd_arch_rs6000:
2903
    case bfd_arch_powerpc:
2904
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2905
      *magicp = bfd_xcoff_magic_number (abfd);
2906
      return true;
2907
#endif
2908
2909
#ifdef MCOREMAGIC
2910
    case bfd_arch_mcore:
2911
      * magicp = MCOREMAGIC;
2912
      return true;
2913
#endif
2914
2915
0
    default:      /* Unknown architecture.  */
2916
0
      break;
2917
98
    }
2918
2919
0
  return false;
2920
98
}
2921
2922
static bool
2923
coff_set_arch_mach (bfd * abfd,
2924
        enum bfd_architecture arch,
2925
        unsigned long machine)
2926
2.66k
{
2927
2.66k
  unsigned dummy1;
2928
2.66k
  unsigned short dummy2;
2929
2930
2.66k
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2931
21
    return false;
2932
2933
2.63k
  if (arch != bfd_arch_unknown
2934
2.63k
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2935
0
    return false;   /* We can't represent this type.  */
2936
2937
2.63k
  return true;     /* We're easy...  */
2938
2.63k
}
pei-i386.c:coff_set_arch_mach
Line
Count
Source
2926
119
{
2927
119
  unsigned dummy1;
2928
119
  unsigned short dummy2;
2929
2930
119
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2931
0
    return false;
2932
2933
119
  if (arch != bfd_arch_unknown
2934
119
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2935
0
    return false;   /* We can't represent this type.  */
2936
2937
119
  return true;     /* We're easy...  */
2938
119
}
pe-x86_64.c:coff_set_arch_mach
Line
Count
Source
2926
100
{
2927
100
  unsigned dummy1;
2928
100
  unsigned short dummy2;
2929
2930
100
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2931
0
    return false;
2932
2933
100
  if (arch != bfd_arch_unknown
2934
100
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2935
0
    return false;   /* We can't represent this type.  */
2936
2937
100
  return true;     /* We're easy...  */
2938
100
}
pei-x86_64.c:coff_set_arch_mach
Line
Count
Source
2926
127
{
2927
127
  unsigned dummy1;
2928
127
  unsigned short dummy2;
2929
2930
127
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2931
0
    return false;
2932
2933
127
  if (arch != bfd_arch_unknown
2934
127
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2935
0
    return false;   /* We can't represent this type.  */
2936
2937
127
  return true;     /* We're easy...  */
2938
127
}
coff-x86_64.c:coff_set_arch_mach
Line
Count
Source
2926
139
{
2927
139
  unsigned dummy1;
2928
139
  unsigned short dummy2;
2929
2930
139
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2931
0
    return false;
2932
2933
139
  if (arch != bfd_arch_unknown
2934
139
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2935
0
    return false;   /* We can't represent this type.  */
2936
2937
139
  return true;     /* We're easy...  */
2938
139
}
coff64-rs6000.c:coff_set_arch_mach
Line
Count
Source
2926
77
{
2927
77
  unsigned dummy1;
2928
77
  unsigned short dummy2;
2929
2930
77
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2931
0
    return false;
2932
2933
77
  if (arch != bfd_arch_unknown
2934
77
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2935
0
    return false;   /* We can't represent this type.  */
2936
2937
77
  return true;     /* We're easy...  */
2938
77
}
pe-aarch64.c:coff_set_arch_mach
Line
Count
Source
2926
113
{
2927
113
  unsigned dummy1;
2928
113
  unsigned short dummy2;
2929
2930
113
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2931
0
    return false;
2932
2933
113
  if (arch != bfd_arch_unknown
2934
113
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2935
0
    return false;   /* We can't represent this type.  */
2936
2937
113
  return true;     /* We're easy...  */
2938
113
}
pei-aarch64.c:coff_set_arch_mach
Line
Count
Source
2926
162
{
2927
162
  unsigned dummy1;
2928
162
  unsigned short dummy2;
2929
2930
162
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2931
0
    return false;
2932
2933
162
  if (arch != bfd_arch_unknown
2934
162
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2935
0
    return false;   /* We can't represent this type.  */
2936
2937
162
  return true;     /* We're easy...  */
2938
162
}
pei-ia64.c:coff_set_arch_mach
Line
Count
Source
2926
99
{
2927
99
  unsigned dummy1;
2928
99
  unsigned short dummy2;
2929
2930
99
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2931
0
    return false;
2932
2933
99
  if (arch != bfd_arch_unknown
2934
99
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2935
0
    return false;   /* We can't represent this type.  */
2936
2937
99
  return true;     /* We're easy...  */
2938
99
}
pei-loongarch64.c:coff_set_arch_mach
Line
Count
Source
2926
117
{
2927
117
  unsigned dummy1;
2928
117
  unsigned short dummy2;
2929
2930
117
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2931
0
    return false;
2932
2933
117
  if (arch != bfd_arch_unknown
2934
117
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2935
0
    return false;   /* We can't represent this type.  */
2936
2937
117
  return true;     /* We're easy...  */
2938
117
}
pei-riscv64.c:coff_set_arch_mach
Line
Count
Source
2926
89
{
2927
89
  unsigned dummy1;
2928
89
  unsigned short dummy2;
2929
2930
89
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2931
0
    return false;
2932
2933
89
  if (arch != bfd_arch_unknown
2934
89
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2935
0
    return false;   /* We can't represent this type.  */
2936
2937
89
  return true;     /* We're easy...  */
2938
89
}
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
2926
159
{
2927
159
  unsigned dummy1;
2928
159
  unsigned short dummy2;
2929
2930
159
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2931
0
    return false;
2932
2933
159
  if (arch != bfd_arch_unknown
2934
159
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2935
0
    return false;   /* We can't represent this type.  */
2936
2937
159
  return true;     /* We're easy...  */
2938
159
}
coff-sh.c:coff_set_arch_mach
Line
Count
Source
2926
130
{
2927
130
  unsigned dummy1;
2928
130
  unsigned short dummy2;
2929
2930
130
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2931
21
    return false;
2932
2933
109
  if (arch != bfd_arch_unknown
2934
109
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2935
0
    return false;   /* We can't represent this type.  */
2936
2937
109
  return true;     /* We're easy...  */
2938
109
}
Unexecuted instantiation: coff-stgo32.c:coff_set_arch_mach
coff-tic30.c:coff_set_arch_mach
Line
Count
Source
2926
114
{
2927
114
  unsigned dummy1;
2928
114
  unsigned short dummy2;
2929
2930
114
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2931
0
    return false;
2932
2933
114
  if (arch != bfd_arch_unknown
2934
114
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2935
0
    return false;   /* We can't represent this type.  */
2936
2937
114
  return true;     /* We're easy...  */
2938
114
}
Unexecuted instantiation: coff-tic4x.c:coff_set_arch_mach
coff-tic54x.c:coff_set_arch_mach
Line
Count
Source
2926
140
{
2927
140
  unsigned dummy1;
2928
140
  unsigned short dummy2;
2929
2930
140
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2931
0
    return false;
2932
2933
140
  if (arch != bfd_arch_unknown
2934
140
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2935
0
    return false;   /* We can't represent this type.  */
2936
2937
140
  return true;     /* We're easy...  */
2938
140
}
coff-z80.c:coff_set_arch_mach
Line
Count
Source
2926
85
{
2927
85
  unsigned dummy1;
2928
85
  unsigned short dummy2;
2929
2930
85
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2931
0
    return false;
2932
2933
85
  if (arch != bfd_arch_unknown
2934
85
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2935
0
    return false;   /* We can't represent this type.  */
2936
2937
85
  return true;     /* We're easy...  */
2938
85
}
coff-z8k.c:coff_set_arch_mach
Line
Count
Source
2926
153
{
2927
153
  unsigned dummy1;
2928
153
  unsigned short dummy2;
2929
2930
153
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2931
0
    return false;
2932
2933
153
  if (arch != bfd_arch_unknown
2934
153
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2935
0
    return false;   /* We can't represent this type.  */
2936
2937
153
  return true;     /* We're easy...  */
2938
153
}
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
2926
122
{
2927
122
  unsigned dummy1;
2928
122
  unsigned short dummy2;
2929
2930
122
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2931
0
    return false;
2932
2933
122
  if (arch != bfd_arch_unknown
2934
122
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2935
0
    return false;   /* We can't represent this type.  */
2936
2937
122
  return true;     /* We're easy...  */
2938
122
}
pe-mcore.c:coff_set_arch_mach
Line
Count
Source
2926
116
{
2927
116
  unsigned dummy1;
2928
116
  unsigned short dummy2;
2929
2930
116
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2931
0
    return false;
2932
2933
116
  if (arch != bfd_arch_unknown
2934
116
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2935
0
    return false;   /* We can't represent this type.  */
2936
2937
116
  return true;     /* We're easy...  */
2938
116
}
pe-sh.c:coff_set_arch_mach
Line
Count
Source
2926
123
{
2927
123
  unsigned dummy1;
2928
123
  unsigned short dummy2;
2929
2930
123
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2931
0
    return false;
2932
2933
123
  if (arch != bfd_arch_unknown
2934
123
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2935
0
    return false;   /* We can't represent this type.  */
2936
2937
123
  return true;     /* We're easy...  */
2938
123
}
pei-arm-wince.c:coff_set_arch_mach
Line
Count
Source
2926
109
{
2927
109
  unsigned dummy1;
2928
109
  unsigned short dummy2;
2929
2930
109
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2931
0
    return false;
2932
2933
109
  if (arch != bfd_arch_unknown
2934
109
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2935
0
    return false;   /* We can't represent this type.  */
2936
2937
109
  return true;     /* We're easy...  */
2938
109
}
pei-arm.c:coff_set_arch_mach
Line
Count
Source
2926
128
{
2927
128
  unsigned dummy1;
2928
128
  unsigned short dummy2;
2929
2930
128
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2931
0
    return false;
2932
2933
128
  if (arch != bfd_arch_unknown
2934
128
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2935
0
    return false;   /* We can't represent this type.  */
2936
2937
128
  return true;     /* We're easy...  */
2938
128
}
pei-mcore.c:coff_set_arch_mach
Line
Count
Source
2926
41
{
2927
41
  unsigned dummy1;
2928
41
  unsigned short dummy2;
2929
2930
41
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2931
0
    return false;
2932
2933
41
  if (arch != bfd_arch_unknown
2934
41
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2935
0
    return false;   /* We can't represent this type.  */
2936
2937
41
  return true;     /* We're easy...  */
2938
41
}
pei-sh.c:coff_set_arch_mach
Line
Count
Source
2926
98
{
2927
98
  unsigned dummy1;
2928
98
  unsigned short dummy2;
2929
2930
98
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2931
0
    return false;
2932
2933
98
  if (arch != bfd_arch_unknown
2934
98
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2935
0
    return false;   /* We can't represent this type.  */
2936
2937
98
  return true;     /* We're easy...  */
2938
98
}
2939
2940
#ifdef COFF_IMAGE_WITH_PE
2941
2942
/* This is used to sort sections by VMA, as required by PE image
2943
   files.  */
2944
2945
static int
2946
sort_by_secaddr (const void * arg1, const void * arg2)
2947
535
{
2948
535
  const asection *a = *(const asection **) arg1;
2949
535
  const asection *b = *(const asection **) arg2;
2950
2951
535
  if (a->vma < b->vma)
2952
43
    return -1;
2953
492
  else if (a->vma > b->vma)
2954
21
    return 1;
2955
2956
471
  return 0;
2957
535
}
pei-i386.c:sort_by_secaddr
Line
Count
Source
2947
3
{
2948
3
  const asection *a = *(const asection **) arg1;
2949
3
  const asection *b = *(const asection **) arg2;
2950
2951
3
  if (a->vma < b->vma)
2952
1
    return -1;
2953
2
  else if (a->vma > b->vma)
2954
2
    return 1;
2955
2956
0
  return 0;
2957
3
}
pei-x86_64.c:sort_by_secaddr
Line
Count
Source
2947
63
{
2948
63
  const asection *a = *(const asection **) arg1;
2949
63
  const asection *b = *(const asection **) arg2;
2950
2951
63
  if (a->vma < b->vma)
2952
42
    return -1;
2953
21
  else if (a->vma > b->vma)
2954
19
    return 1;
2955
2956
2
  return 0;
2957
63
}
pei-aarch64.c:sort_by_secaddr
Line
Count
Source
2947
454
{
2948
454
  const asection *a = *(const asection **) arg1;
2949
454
  const asection *b = *(const asection **) arg2;
2950
2951
454
  if (a->vma < b->vma)
2952
0
    return -1;
2953
454
  else if (a->vma > b->vma)
2954
0
    return 1;
2955
2956
454
  return 0;
2957
454
}
pei-ia64.c:sort_by_secaddr
Line
Count
Source
2947
1
{
2948
1
  const asection *a = *(const asection **) arg1;
2949
1
  const asection *b = *(const asection **) arg2;
2950
2951
1
  if (a->vma < b->vma)
2952
0
    return -1;
2953
1
  else if (a->vma > b->vma)
2954
0
    return 1;
2955
2956
1
  return 0;
2957
1
}
Unexecuted instantiation: pei-loongarch64.c:sort_by_secaddr
pei-riscv64.c:sort_by_secaddr
Line
Count
Source
2947
14
{
2948
14
  const asection *a = *(const asection **) arg1;
2949
14
  const asection *b = *(const asection **) arg2;
2950
2951
14
  if (a->vma < b->vma)
2952
0
    return -1;
2953
14
  else if (a->vma > b->vma)
2954
0
    return 1;
2955
2956
14
  return 0;
2957
14
}
Unexecuted instantiation: pei-arm-wince.c:sort_by_secaddr
Unexecuted instantiation: pei-arm.c:sort_by_secaddr
Unexecuted instantiation: pei-mcore.c:sort_by_secaddr
Unexecuted instantiation: pei-sh.c:sort_by_secaddr
2958
2959
#endif /* COFF_IMAGE_WITH_PE */
2960
2961
/* Calculate the file position for each section.  */
2962
2963
#define ALIGN_SECTIONS_IN_FILE
2964
#ifdef TICOFF
2965
#undef ALIGN_SECTIONS_IN_FILE
2966
#endif
2967
2968
static bool
2969
coff_compute_section_file_positions (bfd * abfd)
2970
20
{
2971
20
  asection *current;
2972
20
  file_ptr sofar = bfd_coff_filhsz (abfd);
2973
20
  bool align_adjust;
2974
20
  unsigned int target_index;
2975
#ifdef ALIGN_SECTIONS_IN_FILE
2976
  asection *previous = NULL;
2977
  file_ptr old_sofar;
2978
#endif
2979
2980
#ifdef COFF_IMAGE_WITH_PE
2981
  unsigned int page_size;
2982
2983
16
  if (coff_data (abfd)->link_info
2984
16
      || (pe_data (abfd) && pe_data (abfd)->pe_opthdr.FileAlignment))
2985
13
    {
2986
13
      page_size = pe_data (abfd)->pe_opthdr.FileAlignment;
2987
2988
      /* If no file alignment has been set, default to one.
2989
   This repairs 'ld -r' for arm-wince-pe target.  */
2990
13
      if (page_size == 0)
2991
0
  page_size = 1;
2992
13
    }
2993
3
  else
2994
3
    page_size = PE_DEF_FILE_ALIGNMENT;
2995
#else
2996
#ifdef COFF_PAGE_SIZE
2997
4
  unsigned int page_size = COFF_PAGE_SIZE;
2998
#endif
2999
#endif
3000
3001
#ifdef RS6000COFF_C
3002
  /* On XCOFF, if we have symbols, set up the .debug section.  */
3003
0
  if (bfd_get_symcount (abfd) > 0)
3004
0
    {
3005
0
      bfd_size_type sz;
3006
0
      bfd_size_type i, symcount;
3007
0
      asymbol **symp;
3008
3009
      sz = 0;
3010
      symcount = bfd_get_symcount (abfd);
3011
0
      for (symp = abfd->outsymbols, i = 0; i < symcount; symp++, i++)
3012
0
  {
3013
0
    coff_symbol_type *cf;
3014
3015
0
    cf = coff_symbol_from (*symp);
3016
0
    if (cf != NULL
3017
0
        && cf->native != NULL
3018
0
        && cf->native->is_sym
3019
0
        && SYMNAME_IN_DEBUG (&cf->native->u.syment))
3020
0
      {
3021
0
        size_t len;
3022
3023
0
        len = strlen (bfd_asymbol_name (*symp));
3024
0
        if (len > SYMNMLEN || bfd_coff_force_symnames_in_strings (abfd))
3025
0
    sz += len + 1 + bfd_coff_debug_string_prefix_length (abfd);
3026
0
      }
3027
0
  }
3028
0
      if (sz > 0)
3029
0
  {
3030
0
    asection *dsec;
3031
3032
0
    dsec = bfd_make_section_old_way (abfd, DOT_DEBUG);
3033
0
    if (dsec == NULL)
3034
0
      abort ();
3035
0
    dsec->size = sz;
3036
0
    dsec->flags |= SEC_HAS_CONTENTS;
3037
0
  }
3038
0
    }
3039
0
#endif
3040
3041
20
  if (bfd_get_start_address (abfd))
3042
    /*  A start address may have been added to the original file. In this
3043
  case it will need an optional header to record it.  */
3044
6
    abfd->flags |= EXEC_P;
3045
3046
20
  if (abfd->flags & EXEC_P)
3047
14
    sofar += bfd_coff_aoutsz (abfd);
3048
#ifdef RS6000COFF_C
3049
0
  else if (xcoff_data (abfd)->full_aouthdr)
3050
0
    sofar += bfd_coff_aoutsz (abfd);
3051
0
  else
3052
0
    sofar += SMALL_AOUTSZ;
3053
#endif
3054
3055
20
  sofar += abfd->section_count * bfd_coff_scnhsz (abfd);
3056
3057
#ifdef RS6000COFF_C
3058
  /* XCOFF handles overflows in the reloc and line number count fields
3059
     by allocating a new section header to hold the correct counts.  */
3060
0
  for (current = abfd->sections; current != NULL; current = current->next)
3061
0
    if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3062
0
      sofar += bfd_coff_scnhsz (abfd);
3063
#endif
3064
3065
20
  if (coff_data (abfd)->section_by_target_index)
3066
0
    htab_empty (coff_data (abfd)->section_by_target_index);
3067
3068
#ifdef COFF_IMAGE_WITH_PE
3069
  {
3070
    /* PE requires the sections to be in memory order when listed in
3071
       the section headers.  It also does not like empty loadable
3072
       sections.  The sections apparently do not have to be in the
3073
       right order in the image file itself, but we do need to get the
3074
       target_index values right.  */
3075
3076
    unsigned int count;
3077
    asection **section_list;
3078
    unsigned int i;
3079
    bfd_size_type amt;
3080
3081
#ifdef COFF_PAGE_SIZE
3082
    /* Clear D_PAGED if section / file alignment aren't suitable for
3083
       paging at COFF_PAGE_SIZE granularity.  */
3084
11
   if (pe_data (abfd)->pe_opthdr.SectionAlignment < COFF_PAGE_SIZE
3085
11
       || page_size < COFF_PAGE_SIZE)
3086
11
     abfd->flags &= ~D_PAGED;
3087
#endif
3088
3089
    count = 0;
3090
199
    for (current = abfd->sections; current != NULL; current = current->next)
3091
183
      ++count;
3092
3093
    /* We allocate an extra cell to simplify the final loop.  */
3094
    amt = sizeof (struct asection *) * (count + 1);
3095
    section_list = (asection **) bfd_malloc (amt);
3096
16
    if (section_list == NULL)
3097
0
      return false;
3098
3099
16
    i = 0;
3100
199
    for (current = abfd->sections; current != NULL; current = current->next)
3101
183
      {
3102
183
  section_list[i] = current;
3103
183
  ++i;
3104
183
      }
3105
16
    section_list[i] = NULL;
3106
3107
16
    qsort (section_list, count, sizeof (asection *), sort_by_secaddr);
3108
3109
    /* Rethread the linked list into sorted order; at the same time,
3110
       assign target_index values.  */
3111
16
    target_index = 1;
3112
16
    abfd->sections = NULL;
3113
16
    abfd->section_last = NULL;
3114
199
    for (i = 0; i < count; i++)
3115
183
      {
3116
183
  current = section_list[i];
3117
183
  bfd_section_list_append (abfd, current);
3118
3119
  /* Later, if the section has zero size, we'll be throwing it
3120
     away, so we don't want to number it now.  Note that having
3121
     a zero size and having real contents are different
3122
     concepts: .bss has no contents, but (usually) non-zero
3123
     size.  */
3124
183
  if (current->size == 0)
3125
142
    {
3126
      /* Discard.  However, it still might have (valid) symbols
3127
         in it, so arbitrarily set it to section 1 (indexing is
3128
         1-based here; usually .text).  __end__ and other
3129
         contents of .endsection really have this happen.
3130
         FIXME: This seems somewhat dubious.  */
3131
142
      current->target_index = 1;
3132
142
    }
3133
41
  else
3134
41
    current->target_index = target_index++;
3135
183
      }
3136
3137
16
    free (section_list);
3138
16
  }
3139
#else /* ! COFF_IMAGE_WITH_PE */
3140
  {
3141
    /* Set the target_index field.  */
3142
    target_index = 1;
3143
273
    for (current = abfd->sections; current != NULL; current = current->next)
3144
269
      current->target_index = target_index++;
3145
  }
3146
#endif /* ! COFF_IMAGE_WITH_PE */
3147
3148
20
  if (target_index >= bfd_coff_max_nscns (abfd))
3149
0
    {
3150
0
      bfd_set_error (bfd_error_file_too_big);
3151
0
      _bfd_error_handler
3152
  /* xgettext:c-format */
3153
0
  (_("%pB: too many sections (%d)"), abfd, target_index);
3154
0
      return false;
3155
0
    }
3156
3157
20
  align_adjust = false;
3158
20
  for (current = abfd->sections;
3159
472
       current != NULL;
3160
452
       current = current->next)
3161
452
    {
3162
#ifdef COFF_IMAGE_WITH_PE
3163
      /* With PE we have to pad each section to be a multiple of its
3164
   page size too, and remember both sizes.  */
3165
183
      if (coff_section_data (abfd, current) == NULL)
3166
10
  {
3167
10
    size_t amt = sizeof (struct coff_section_tdata);
3168
3169
    current->used_by_bfd = bfd_zalloc (abfd, amt);
3170
10
    if (current->used_by_bfd == NULL)
3171
0
      return false;
3172
10
  }
3173
183
      if (pei_section_data (abfd, current) == NULL)
3174
10
  {
3175
10
    size_t amt = sizeof (struct pei_section_tdata);
3176
3177
10
    coff_section_data (abfd, current)->tdata = bfd_zalloc (abfd, amt);
3178
10
    if (coff_section_data (abfd, current)->tdata == NULL)
3179
0
      return false;
3180
10
  }
3181
183
      if (pei_section_data (abfd, current)->virt_size == 0)
3182
153
  pei_section_data (abfd, current)->virt_size = current->size;
3183
183
#endif
3184
3185
      /* Only deal with sections which have contents.  */
3186
452
      if (!(current->flags & SEC_HAS_CONTENTS))
3187
410
  continue;
3188
3189
42
      current->rawsize = current->size;
3190
3191
#ifdef COFF_IMAGE_WITH_PE
3192
      /* Make sure we skip empty sections in a PE image.  */
3193
39
      if (current->size == 0)
3194
0
  continue;
3195
39
#endif
3196
3197
      /* Align the sections in the file to the same boundary on
3198
   which they are aligned in virtual memory.  */
3199
#ifdef ALIGN_SECTIONS_IN_FILE
3200
42
      if ((abfd->flags & EXEC_P) != 0)
3201
37
  {
3202
    /* Make sure this section is aligned on the right boundary - by
3203
       padding the previous section up if necessary.  */
3204
37
    old_sofar = sofar;
3205
3206
#ifdef COFF_IMAGE_WITH_PE
3207
37
    sofar = BFD_ALIGN (sofar, page_size);
3208
#else
3209
0
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3210
#endif
3211
3212
#ifdef RS6000COFF_C
3213
    /* Make sure the file offset and the vma of .text/.data are at the
3214
       same page offset, so that the file can be mmap'ed without being
3215
       relocated.  Failing that, AIX is able to load and execute the
3216
       program, but it will be silently relocated (possible as
3217
       executables are PIE).  But the relocation is slightly costly and
3218
       complexify the use of addr2line or gdb.  So better to avoid it,
3219
       like does the native linker.  Usually gnu ld makes sure that
3220
       the vma of .text is the file offset so this issue shouldn't
3221
       appear unless you are stripping such an executable.
3222
3223
       AIX loader checks the text section alignment of (vma - filepos),
3224
       and the native linker doesn't try to align the text sections.
3225
       For example:
3226
3227
       0 .text       000054cc  10000128  10000128  00000128  2**5
3228
           CONTENTS, ALLOC, LOAD, CODE
3229
3230
       Don't perform the above tweak if the previous one is .tdata,
3231
       as it will increase the memory allocated for every threads
3232
       created and not just improve performances with gdb.
3233
    */
3234
3235
0
    if ((current->flags & SEC_LOAD) != 0
3236
0
        && (!strcmp (current->name, _TEXT)
3237
0
      || !strcmp (current->name, _DATA))
3238
0
        && (previous == NULL || strcmp(previous->name, _TDATA)))
3239
0
      {
3240
0
        bfd_vma align = 4096;
3241
0
        bfd_vma sofar_off = sofar % align;
3242
0
        bfd_vma vma_off = current->vma % align;
3243
3244
0
        if (vma_off > sofar_off)
3245
0
    sofar += vma_off - sofar_off;
3246
0
        else if (vma_off < sofar_off)
3247
0
    sofar += align + vma_off - sofar_off;
3248
0
      }
3249
#endif
3250
37
    if (previous != NULL
3251
37
        && (previous->flags & SEC_LOAD) != 0)
3252
14
      previous->size += sofar - old_sofar;
3253
37
  }
3254
3255
39
#endif
3256
3257
      /* In demand paged files the low order bits of the file offset
3258
   must match the low order bits of the virtual address.  */
3259
#ifdef COFF_PAGE_SIZE
3260
38
      if ((abfd->flags & D_PAGED) != 0
3261
38
    && (current->flags & SEC_ALLOC) != 0)
3262
1
  sofar += (current->vma - (bfd_vma) sofar) % page_size;
3263
#endif
3264
39
      current->filepos = sofar;
3265
3266
#ifdef COFF_IMAGE_WITH_PE
3267
      /* Set the padded size.  */
3268
      current->size = (current->size + page_size - 1) & -page_size;
3269
#endif
3270
3271
39
      sofar += current->size;
3272
3273
#ifdef ALIGN_SECTIONS_IN_FILE
3274
      /* Make sure that this section is of the right size too.  */
3275
42
      if ((abfd->flags & EXEC_P) == 0)
3276
5
  {
3277
5
    bfd_size_type old_size;
3278
3279
5
    old_size = current->size;
3280
5
    current->size = BFD_ALIGN (current->size,
3281
5
             (bfd_vma) 1 << current->alignment_power);
3282
5
    align_adjust = current->size != old_size;
3283
5
    sofar += current->size - old_size;
3284
5
  }
3285
37
      else
3286
37
  {
3287
37
    old_sofar = sofar;
3288
#ifdef COFF_IMAGE_WITH_PE
3289
37
    sofar = BFD_ALIGN (sofar, page_size);
3290
#else
3291
0
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3292
#endif
3293
37
    align_adjust = sofar != old_sofar;
3294
37
    current->size += sofar - old_sofar;
3295
37
  }
3296
#endif
3297
3298
#ifdef COFF_IMAGE_WITH_PE
3299
      /* For PE we need to make sure we pad out to the aligned
3300
   size, in case the caller only writes out data to the
3301
   unaligned size.  */
3302
39
      if (pei_section_data (abfd, current)->virt_size < current->size)
3303
27
  align_adjust = true;
3304
#endif
3305
3306
#ifdef _LIB
3307
      /* Force .lib sections to start at zero.  The vma is then
3308
   incremented in coff_set_section_contents.  This is right for
3309
   SVR3.2.  */
3310
42
      if (strcmp (current->name, _LIB) == 0)
3311
0
  bfd_set_section_vma (current, 0);
3312
#endif
3313
3314
#ifdef ALIGN_SECTIONS_IN_FILE
3315
      previous = current;
3316
#endif
3317
39
    }
3318
3319
  /* It is now safe to write to the output file.  If we needed an
3320
     alignment adjustment for the last section, then make sure that
3321
     there is a byte at offset sofar.  If there are no symbols and no
3322
     relocs, then nothing follows the last section.  If we don't force
3323
     the last byte out, then the file may appear to be truncated.  */
3324
20
  if (align_adjust)
3325
7
    {
3326
7
      bfd_byte b;
3327
3328
7
      b = 0;
3329
7
      if (bfd_seek (abfd, sofar - 1, SEEK_SET) != 0
3330
7
    || bfd_write (&b, 1, abfd) != 1)
3331
0
  return false;
3332
7
    }
3333
3334
  /* Make sure the relocations are aligned.  We don't need to make
3335
     sure that this byte exists, because it will only matter if there
3336
     really are relocs.  */
3337
20
  sofar = BFD_ALIGN (sofar,
3338
20
         (bfd_vma) 1 << COFF_DEFAULT_SECTION_ALIGNMENT_POWER);
3339
3340
20
  obj_relocbase (abfd) = sofar;
3341
20
  abfd->output_has_begun = true;
3342
3343
20
  return true;
3344
16
}
pei-i386.c:coff_compute_section_file_positions
Line
Count
Source
2970
4
{
2971
4
  asection *current;
2972
4
  file_ptr sofar = bfd_coff_filhsz (abfd);
2973
4
  bool align_adjust;
2974
4
  unsigned int target_index;
2975
4
#ifdef ALIGN_SECTIONS_IN_FILE
2976
4
  asection *previous = NULL;
2977
4
  file_ptr old_sofar;
2978
4
#endif
2979
2980
4
#ifdef COFF_IMAGE_WITH_PE
2981
4
  unsigned int page_size;
2982
2983
4
  if (coff_data (abfd)->link_info
2984
4
      || (pe_data (abfd) && pe_data (abfd)->pe_opthdr.FileAlignment))
2985
4
    {
2986
4
      page_size = pe_data (abfd)->pe_opthdr.FileAlignment;
2987
2988
      /* If no file alignment has been set, default to one.
2989
   This repairs 'ld -r' for arm-wince-pe target.  */
2990
4
      if (page_size == 0)
2991
0
  page_size = 1;
2992
4
    }
2993
0
  else
2994
0
    page_size = PE_DEF_FILE_ALIGNMENT;
2995
#else
2996
#ifdef COFF_PAGE_SIZE
2997
  unsigned int page_size = COFF_PAGE_SIZE;
2998
#endif
2999
#endif
3000
3001
#ifdef RS6000COFF_C
3002
  /* On XCOFF, if we have symbols, set up the .debug section.  */
3003
  if (bfd_get_symcount (abfd) > 0)
3004
    {
3005
      bfd_size_type sz;
3006
      bfd_size_type i, symcount;
3007
      asymbol **symp;
3008
3009
      sz = 0;
3010
      symcount = bfd_get_symcount (abfd);
3011
      for (symp = abfd->outsymbols, i = 0; i < symcount; symp++, i++)
3012
  {
3013
    coff_symbol_type *cf;
3014
3015
    cf = coff_symbol_from (*symp);
3016
    if (cf != NULL
3017
        && cf->native != NULL
3018
        && cf->native->is_sym
3019
        && SYMNAME_IN_DEBUG (&cf->native->u.syment))
3020
      {
3021
        size_t len;
3022
3023
        len = strlen (bfd_asymbol_name (*symp));
3024
        if (len > SYMNMLEN || bfd_coff_force_symnames_in_strings (abfd))
3025
    sz += len + 1 + bfd_coff_debug_string_prefix_length (abfd);
3026
      }
3027
  }
3028
      if (sz > 0)
3029
  {
3030
    asection *dsec;
3031
3032
    dsec = bfd_make_section_old_way (abfd, DOT_DEBUG);
3033
    if (dsec == NULL)
3034
      abort ();
3035
    dsec->size = sz;
3036
    dsec->flags |= SEC_HAS_CONTENTS;
3037
  }
3038
    }
3039
#endif
3040
3041
4
  if (bfd_get_start_address (abfd))
3042
    /*  A start address may have been added to the original file. In this
3043
  case it will need an optional header to record it.  */
3044
1
    abfd->flags |= EXEC_P;
3045
3046
4
  if (abfd->flags & EXEC_P)
3047
4
    sofar += bfd_coff_aoutsz (abfd);
3048
#ifdef RS6000COFF_C
3049
  else if (xcoff_data (abfd)->full_aouthdr)
3050
    sofar += bfd_coff_aoutsz (abfd);
3051
  else
3052
    sofar += SMALL_AOUTSZ;
3053
#endif
3054
3055
4
  sofar += abfd->section_count * bfd_coff_scnhsz (abfd);
3056
3057
#ifdef RS6000COFF_C
3058
  /* XCOFF handles overflows in the reloc and line number count fields
3059
     by allocating a new section header to hold the correct counts.  */
3060
  for (current = abfd->sections; current != NULL; current = current->next)
3061
    if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3062
      sofar += bfd_coff_scnhsz (abfd);
3063
#endif
3064
3065
4
  if (coff_data (abfd)->section_by_target_index)
3066
0
    htab_empty (coff_data (abfd)->section_by_target_index);
3067
3068
4
#ifdef COFF_IMAGE_WITH_PE
3069
4
  {
3070
    /* PE requires the sections to be in memory order when listed in
3071
       the section headers.  It also does not like empty loadable
3072
       sections.  The sections apparently do not have to be in the
3073
       right order in the image file itself, but we do need to get the
3074
       target_index values right.  */
3075
3076
4
    unsigned int count;
3077
4
    asection **section_list;
3078
4
    unsigned int i;
3079
4
    bfd_size_type amt;
3080
3081
4
#ifdef COFF_PAGE_SIZE
3082
    /* Clear D_PAGED if section / file alignment aren't suitable for
3083
       paging at COFF_PAGE_SIZE granularity.  */
3084
4
   if (pe_data (abfd)->pe_opthdr.SectionAlignment < COFF_PAGE_SIZE
3085
4
       || page_size < COFF_PAGE_SIZE)
3086
4
     abfd->flags &= ~D_PAGED;
3087
4
#endif
3088
3089
4
    count = 0;
3090
7
    for (current = abfd->sections; current != NULL; current = current->next)
3091
3
      ++count;
3092
3093
    /* We allocate an extra cell to simplify the final loop.  */
3094
4
    amt = sizeof (struct asection *) * (count + 1);
3095
4
    section_list = (asection **) bfd_malloc (amt);
3096
4
    if (section_list == NULL)
3097
0
      return false;
3098
3099
4
    i = 0;
3100
7
    for (current = abfd->sections; current != NULL; current = current->next)
3101
3
      {
3102
3
  section_list[i] = current;
3103
3
  ++i;
3104
3
      }
3105
4
    section_list[i] = NULL;
3106
3107
4
    qsort (section_list, count, sizeof (asection *), sort_by_secaddr);
3108
3109
    /* Rethread the linked list into sorted order; at the same time,
3110
       assign target_index values.  */
3111
4
    target_index = 1;
3112
4
    abfd->sections = NULL;
3113
4
    abfd->section_last = NULL;
3114
7
    for (i = 0; i < count; i++)
3115
3
      {
3116
3
  current = section_list[i];
3117
3
  bfd_section_list_append (abfd, current);
3118
3119
  /* Later, if the section has zero size, we'll be throwing it
3120
     away, so we don't want to number it now.  Note that having
3121
     a zero size and having real contents are different
3122
     concepts: .bss has no contents, but (usually) non-zero
3123
     size.  */
3124
3
  if (current->size == 0)
3125
0
    {
3126
      /* Discard.  However, it still might have (valid) symbols
3127
         in it, so arbitrarily set it to section 1 (indexing is
3128
         1-based here; usually .text).  __end__ and other
3129
         contents of .endsection really have this happen.
3130
         FIXME: This seems somewhat dubious.  */
3131
0
      current->target_index = 1;
3132
0
    }
3133
3
  else
3134
3
    current->target_index = target_index++;
3135
3
      }
3136
3137
4
    free (section_list);
3138
4
  }
3139
#else /* ! COFF_IMAGE_WITH_PE */
3140
  {
3141
    /* Set the target_index field.  */
3142
    target_index = 1;
3143
    for (current = abfd->sections; current != NULL; current = current->next)
3144
      current->target_index = target_index++;
3145
  }
3146
#endif /* ! COFF_IMAGE_WITH_PE */
3147
3148
4
  if (target_index >= bfd_coff_max_nscns (abfd))
3149
0
    {
3150
0
      bfd_set_error (bfd_error_file_too_big);
3151
0
      _bfd_error_handler
3152
  /* xgettext:c-format */
3153
0
  (_("%pB: too many sections (%d)"), abfd, target_index);
3154
0
      return false;
3155
0
    }
3156
3157
4
  align_adjust = false;
3158
4
  for (current = abfd->sections;
3159
7
       current != NULL;
3160
4
       current = current->next)
3161
3
    {
3162
3
#ifdef COFF_IMAGE_WITH_PE
3163
      /* With PE we have to pad each section to be a multiple of its
3164
   page size too, and remember both sizes.  */
3165
3
      if (coff_section_data (abfd, current) == NULL)
3166
0
  {
3167
0
    size_t amt = sizeof (struct coff_section_tdata);
3168
3169
0
    current->used_by_bfd = bfd_zalloc (abfd, amt);
3170
0
    if (current->used_by_bfd == NULL)
3171
0
      return false;
3172
0
  }
3173
3
      if (pei_section_data (abfd, current) == NULL)
3174
0
  {
3175
0
    size_t amt = sizeof (struct pei_section_tdata);
3176
3177
0
    coff_section_data (abfd, current)->tdata = bfd_zalloc (abfd, amt);
3178
0
    if (coff_section_data (abfd, current)->tdata == NULL)
3179
0
      return false;
3180
0
  }
3181
3
      if (pei_section_data (abfd, current)->virt_size == 0)
3182
0
  pei_section_data (abfd, current)->virt_size = current->size;
3183
3
#endif
3184
3185
      /* Only deal with sections which have contents.  */
3186
3
      if (!(current->flags & SEC_HAS_CONTENTS))
3187
0
  continue;
3188
3189
3
      current->rawsize = current->size;
3190
3191
3
#ifdef COFF_IMAGE_WITH_PE
3192
      /* Make sure we skip empty sections in a PE image.  */
3193
3
      if (current->size == 0)
3194
0
  continue;
3195
3
#endif
3196
3197
      /* Align the sections in the file to the same boundary on
3198
   which they are aligned in virtual memory.  */
3199
3
#ifdef ALIGN_SECTIONS_IN_FILE
3200
3
      if ((abfd->flags & EXEC_P) != 0)
3201
3
  {
3202
    /* Make sure this section is aligned on the right boundary - by
3203
       padding the previous section up if necessary.  */
3204
3
    old_sofar = sofar;
3205
3206
3
#ifdef COFF_IMAGE_WITH_PE
3207
3
    sofar = BFD_ALIGN (sofar, page_size);
3208
#else
3209
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3210
#endif
3211
3212
#ifdef RS6000COFF_C
3213
    /* Make sure the file offset and the vma of .text/.data are at the
3214
       same page offset, so that the file can be mmap'ed without being
3215
       relocated.  Failing that, AIX is able to load and execute the
3216
       program, but it will be silently relocated (possible as
3217
       executables are PIE).  But the relocation is slightly costly and
3218
       complexify the use of addr2line or gdb.  So better to avoid it,
3219
       like does the native linker.  Usually gnu ld makes sure that
3220
       the vma of .text is the file offset so this issue shouldn't
3221
       appear unless you are stripping such an executable.
3222
3223
       AIX loader checks the text section alignment of (vma - filepos),
3224
       and the native linker doesn't try to align the text sections.
3225
       For example:
3226
3227
       0 .text       000054cc  10000128  10000128  00000128  2**5
3228
           CONTENTS, ALLOC, LOAD, CODE
3229
3230
       Don't perform the above tweak if the previous one is .tdata,
3231
       as it will increase the memory allocated for every threads
3232
       created and not just improve performances with gdb.
3233
    */
3234
3235
    if ((current->flags & SEC_LOAD) != 0
3236
        && (!strcmp (current->name, _TEXT)
3237
      || !strcmp (current->name, _DATA))
3238
        && (previous == NULL || strcmp(previous->name, _TDATA)))
3239
      {
3240
        bfd_vma align = 4096;
3241
        bfd_vma sofar_off = sofar % align;
3242
        bfd_vma vma_off = current->vma % align;
3243
3244
        if (vma_off > sofar_off)
3245
    sofar += vma_off - sofar_off;
3246
        else if (vma_off < sofar_off)
3247
    sofar += align + vma_off - sofar_off;
3248
      }
3249
#endif
3250
3
    if (previous != NULL
3251
3
        && (previous->flags & SEC_LOAD) != 0)
3252
0
      previous->size += sofar - old_sofar;
3253
3
  }
3254
3255
3
#endif
3256
3257
      /* In demand paged files the low order bits of the file offset
3258
   must match the low order bits of the virtual address.  */
3259
3
#ifdef COFF_PAGE_SIZE
3260
3
      if ((abfd->flags & D_PAGED) != 0
3261
3
    && (current->flags & SEC_ALLOC) != 0)
3262
0
  sofar += (current->vma - (bfd_vma) sofar) % page_size;
3263
3
#endif
3264
3
      current->filepos = sofar;
3265
3266
3
#ifdef COFF_IMAGE_WITH_PE
3267
      /* Set the padded size.  */
3268
3
      current->size = (current->size + page_size - 1) & -page_size;
3269
3
#endif
3270
3271
3
      sofar += current->size;
3272
3273
3
#ifdef ALIGN_SECTIONS_IN_FILE
3274
      /* Make sure that this section is of the right size too.  */
3275
3
      if ((abfd->flags & EXEC_P) == 0)
3276
0
  {
3277
0
    bfd_size_type old_size;
3278
3279
0
    old_size = current->size;
3280
0
    current->size = BFD_ALIGN (current->size,
3281
0
             (bfd_vma) 1 << current->alignment_power);
3282
0
    align_adjust = current->size != old_size;
3283
0
    sofar += current->size - old_size;
3284
0
  }
3285
3
      else
3286
3
  {
3287
3
    old_sofar = sofar;
3288
3
#ifdef COFF_IMAGE_WITH_PE
3289
3
    sofar = BFD_ALIGN (sofar, page_size);
3290
#else
3291
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3292
#endif
3293
3
    align_adjust = sofar != old_sofar;
3294
3
    current->size += sofar - old_sofar;
3295
3
  }
3296
3
#endif
3297
3298
3
#ifdef COFF_IMAGE_WITH_PE
3299
      /* For PE we need to make sure we pad out to the aligned
3300
   size, in case the caller only writes out data to the
3301
   unaligned size.  */
3302
3
      if (pei_section_data (abfd, current)->virt_size < current->size)
3303
2
  align_adjust = true;
3304
3
#endif
3305
3306
3
#ifdef _LIB
3307
      /* Force .lib sections to start at zero.  The vma is then
3308
   incremented in coff_set_section_contents.  This is right for
3309
   SVR3.2.  */
3310
3
      if (strcmp (current->name, _LIB) == 0)
3311
0
  bfd_set_section_vma (current, 0);
3312
3
#endif
3313
3314
3
#ifdef ALIGN_SECTIONS_IN_FILE
3315
3
      previous = current;
3316
3
#endif
3317
3
    }
3318
3319
  /* It is now safe to write to the output file.  If we needed an
3320
     alignment adjustment for the last section, then make sure that
3321
     there is a byte at offset sofar.  If there are no symbols and no
3322
     relocs, then nothing follows the last section.  If we don't force
3323
     the last byte out, then the file may appear to be truncated.  */
3324
4
  if (align_adjust)
3325
1
    {
3326
1
      bfd_byte b;
3327
3328
1
      b = 0;
3329
1
      if (bfd_seek (abfd, sofar - 1, SEEK_SET) != 0
3330
1
    || bfd_write (&b, 1, abfd) != 1)
3331
0
  return false;
3332
1
    }
3333
3334
  /* Make sure the relocations are aligned.  We don't need to make
3335
     sure that this byte exists, because it will only matter if there
3336
     really are relocs.  */
3337
4
  sofar = BFD_ALIGN (sofar,
3338
4
         (bfd_vma) 1 << COFF_DEFAULT_SECTION_ALIGNMENT_POWER);
3339
3340
4
  obj_relocbase (abfd) = sofar;
3341
4
  abfd->output_has_begun = true;
3342
3343
4
  return true;
3344
4
}
Unexecuted instantiation: pe-x86_64.c:coff_compute_section_file_positions
pei-x86_64.c:coff_compute_section_file_positions
Line
Count
Source
2970
3
{
2971
3
  asection *current;
2972
3
  file_ptr sofar = bfd_coff_filhsz (abfd);
2973
3
  bool align_adjust;
2974
3
  unsigned int target_index;
2975
3
#ifdef ALIGN_SECTIONS_IN_FILE
2976
3
  asection *previous = NULL;
2977
3
  file_ptr old_sofar;
2978
3
#endif
2979
2980
3
#ifdef COFF_IMAGE_WITH_PE
2981
3
  unsigned int page_size;
2982
2983
3
  if (coff_data (abfd)->link_info
2984
3
      || (pe_data (abfd) && pe_data (abfd)->pe_opthdr.FileAlignment))
2985
3
    {
2986
3
      page_size = pe_data (abfd)->pe_opthdr.FileAlignment;
2987
2988
      /* If no file alignment has been set, default to one.
2989
   This repairs 'ld -r' for arm-wince-pe target.  */
2990
3
      if (page_size == 0)
2991
0
  page_size = 1;
2992
3
    }
2993
0
  else
2994
0
    page_size = PE_DEF_FILE_ALIGNMENT;
2995
#else
2996
#ifdef COFF_PAGE_SIZE
2997
  unsigned int page_size = COFF_PAGE_SIZE;
2998
#endif
2999
#endif
3000
3001
#ifdef RS6000COFF_C
3002
  /* On XCOFF, if we have symbols, set up the .debug section.  */
3003
  if (bfd_get_symcount (abfd) > 0)
3004
    {
3005
      bfd_size_type sz;
3006
      bfd_size_type i, symcount;
3007
      asymbol **symp;
3008
3009
      sz = 0;
3010
      symcount = bfd_get_symcount (abfd);
3011
      for (symp = abfd->outsymbols, i = 0; i < symcount; symp++, i++)
3012
  {
3013
    coff_symbol_type *cf;
3014
3015
    cf = coff_symbol_from (*symp);
3016
    if (cf != NULL
3017
        && cf->native != NULL
3018
        && cf->native->is_sym
3019
        && SYMNAME_IN_DEBUG (&cf->native->u.syment))
3020
      {
3021
        size_t len;
3022
3023
        len = strlen (bfd_asymbol_name (*symp));
3024
        if (len > SYMNMLEN || bfd_coff_force_symnames_in_strings (abfd))
3025
    sz += len + 1 + bfd_coff_debug_string_prefix_length (abfd);
3026
      }
3027
  }
3028
      if (sz > 0)
3029
  {
3030
    asection *dsec;
3031
3032
    dsec = bfd_make_section_old_way (abfd, DOT_DEBUG);
3033
    if (dsec == NULL)
3034
      abort ();
3035
    dsec->size = sz;
3036
    dsec->flags |= SEC_HAS_CONTENTS;
3037
  }
3038
    }
3039
#endif
3040
3041
3
  if (bfd_get_start_address (abfd))
3042
    /*  A start address may have been added to the original file. In this
3043
  case it will need an optional header to record it.  */
3044
2
    abfd->flags |= EXEC_P;
3045
3046
3
  if (abfd->flags & EXEC_P)
3047
3
    sofar += bfd_coff_aoutsz (abfd);
3048
#ifdef RS6000COFF_C
3049
  else if (xcoff_data (abfd)->full_aouthdr)
3050
    sofar += bfd_coff_aoutsz (abfd);
3051
  else
3052
    sofar += SMALL_AOUTSZ;
3053
#endif
3054
3055
3
  sofar += abfd->section_count * bfd_coff_scnhsz (abfd);
3056
3057
#ifdef RS6000COFF_C
3058
  /* XCOFF handles overflows in the reloc and line number count fields
3059
     by allocating a new section header to hold the correct counts.  */
3060
  for (current = abfd->sections; current != NULL; current = current->next)
3061
    if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3062
      sofar += bfd_coff_scnhsz (abfd);
3063
#endif
3064
3065
3
  if (coff_data (abfd)->section_by_target_index)
3066
0
    htab_empty (coff_data (abfd)->section_by_target_index);
3067
3068
3
#ifdef COFF_IMAGE_WITH_PE
3069
3
  {
3070
    /* PE requires the sections to be in memory order when listed in
3071
       the section headers.  It also does not like empty loadable
3072
       sections.  The sections apparently do not have to be in the
3073
       right order in the image file itself, but we do need to get the
3074
       target_index values right.  */
3075
3076
3
    unsigned int count;
3077
3
    asection **section_list;
3078
3
    unsigned int i;
3079
3
    bfd_size_type amt;
3080
3081
3
#ifdef COFF_PAGE_SIZE
3082
    /* Clear D_PAGED if section / file alignment aren't suitable for
3083
       paging at COFF_PAGE_SIZE granularity.  */
3084
3
   if (pe_data (abfd)->pe_opthdr.SectionAlignment < COFF_PAGE_SIZE
3085
3
       || page_size < COFF_PAGE_SIZE)
3086
3
     abfd->flags &= ~D_PAGED;
3087
3
#endif
3088
3089
3
    count = 0;
3090
32
    for (current = abfd->sections; current != NULL; current = current->next)
3091
29
      ++count;
3092
3093
    /* We allocate an extra cell to simplify the final loop.  */
3094
3
    amt = sizeof (struct asection *) * (count + 1);
3095
3
    section_list = (asection **) bfd_malloc (amt);
3096
3
    if (section_list == NULL)
3097
0
      return false;
3098
3099
3
    i = 0;
3100
32
    for (current = abfd->sections; current != NULL; current = current->next)
3101
29
      {
3102
29
  section_list[i] = current;
3103
29
  ++i;
3104
29
      }
3105
3
    section_list[i] = NULL;
3106
3107
3
    qsort (section_list, count, sizeof (asection *), sort_by_secaddr);
3108
3109
    /* Rethread the linked list into sorted order; at the same time,
3110
       assign target_index values.  */
3111
3
    target_index = 1;
3112
3
    abfd->sections = NULL;
3113
3
    abfd->section_last = NULL;
3114
32
    for (i = 0; i < count; i++)
3115
29
      {
3116
29
  current = section_list[i];
3117
29
  bfd_section_list_append (abfd, current);
3118
3119
  /* Later, if the section has zero size, we'll be throwing it
3120
     away, so we don't want to number it now.  Note that having
3121
     a zero size and having real contents are different
3122
     concepts: .bss has no contents, but (usually) non-zero
3123
     size.  */
3124
29
  if (current->size == 0)
3125
0
    {
3126
      /* Discard.  However, it still might have (valid) symbols
3127
         in it, so arbitrarily set it to section 1 (indexing is
3128
         1-based here; usually .text).  __end__ and other
3129
         contents of .endsection really have this happen.
3130
         FIXME: This seems somewhat dubious.  */
3131
0
      current->target_index = 1;
3132
0
    }
3133
29
  else
3134
29
    current->target_index = target_index++;
3135
29
      }
3136
3137
3
    free (section_list);
3138
3
  }
3139
#else /* ! COFF_IMAGE_WITH_PE */
3140
  {
3141
    /* Set the target_index field.  */
3142
    target_index = 1;
3143
    for (current = abfd->sections; current != NULL; current = current->next)
3144
      current->target_index = target_index++;
3145
  }
3146
#endif /* ! COFF_IMAGE_WITH_PE */
3147
3148
3
  if (target_index >= bfd_coff_max_nscns (abfd))
3149
0
    {
3150
0
      bfd_set_error (bfd_error_file_too_big);
3151
0
      _bfd_error_handler
3152
  /* xgettext:c-format */
3153
0
  (_("%pB: too many sections (%d)"), abfd, target_index);
3154
0
      return false;
3155
0
    }
3156
3157
3
  align_adjust = false;
3158
3
  for (current = abfd->sections;
3159
32
       current != NULL;
3160
29
       current = current->next)
3161
29
    {
3162
29
#ifdef COFF_IMAGE_WITH_PE
3163
      /* With PE we have to pad each section to be a multiple of its
3164
   page size too, and remember both sizes.  */
3165
29
      if (coff_section_data (abfd, current) == NULL)
3166
2
  {
3167
2
    size_t amt = sizeof (struct coff_section_tdata);
3168
3169
2
    current->used_by_bfd = bfd_zalloc (abfd, amt);
3170
2
    if (current->used_by_bfd == NULL)
3171
0
      return false;
3172
2
  }
3173
29
      if (pei_section_data (abfd, current) == NULL)
3174
2
  {
3175
2
    size_t amt = sizeof (struct pei_section_tdata);
3176
3177
2
    coff_section_data (abfd, current)->tdata = bfd_zalloc (abfd, amt);
3178
2
    if (coff_section_data (abfd, current)->tdata == NULL)
3179
0
      return false;
3180
2
  }
3181
29
      if (pei_section_data (abfd, current)->virt_size == 0)
3182
2
  pei_section_data (abfd, current)->virt_size = current->size;
3183
29
#endif
3184
3185
      /* Only deal with sections which have contents.  */
3186
29
      if (!(current->flags & SEC_HAS_CONTENTS))
3187
1
  continue;
3188
3189
28
      current->rawsize = current->size;
3190
3191
28
#ifdef COFF_IMAGE_WITH_PE
3192
      /* Make sure we skip empty sections in a PE image.  */
3193
28
      if (current->size == 0)
3194
0
  continue;
3195
28
#endif
3196
3197
      /* Align the sections in the file to the same boundary on
3198
   which they are aligned in virtual memory.  */
3199
28
#ifdef ALIGN_SECTIONS_IN_FILE
3200
28
      if ((abfd->flags & EXEC_P) != 0)
3201
28
  {
3202
    /* Make sure this section is aligned on the right boundary - by
3203
       padding the previous section up if necessary.  */
3204
28
    old_sofar = sofar;
3205
3206
28
#ifdef COFF_IMAGE_WITH_PE
3207
28
    sofar = BFD_ALIGN (sofar, page_size);
3208
#else
3209
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3210
#endif
3211
3212
#ifdef RS6000COFF_C
3213
    /* Make sure the file offset and the vma of .text/.data are at the
3214
       same page offset, so that the file can be mmap'ed without being
3215
       relocated.  Failing that, AIX is able to load and execute the
3216
       program, but it will be silently relocated (possible as
3217
       executables are PIE).  But the relocation is slightly costly and
3218
       complexify the use of addr2line or gdb.  So better to avoid it,
3219
       like does the native linker.  Usually gnu ld makes sure that
3220
       the vma of .text is the file offset so this issue shouldn't
3221
       appear unless you are stripping such an executable.
3222
3223
       AIX loader checks the text section alignment of (vma - filepos),
3224
       and the native linker doesn't try to align the text sections.
3225
       For example:
3226
3227
       0 .text       000054cc  10000128  10000128  00000128  2**5
3228
           CONTENTS, ALLOC, LOAD, CODE
3229
3230
       Don't perform the above tweak if the previous one is .tdata,
3231
       as it will increase the memory allocated for every threads
3232
       created and not just improve performances with gdb.
3233
    */
3234
3235
    if ((current->flags & SEC_LOAD) != 0
3236
        && (!strcmp (current->name, _TEXT)
3237
      || !strcmp (current->name, _DATA))
3238
        && (previous == NULL || strcmp(previous->name, _TDATA)))
3239
      {
3240
        bfd_vma align = 4096;
3241
        bfd_vma sofar_off = sofar % align;
3242
        bfd_vma vma_off = current->vma % align;
3243
3244
        if (vma_off > sofar_off)
3245
    sofar += vma_off - sofar_off;
3246
        else if (vma_off < sofar_off)
3247
    sofar += align + vma_off - sofar_off;
3248
      }
3249
#endif
3250
28
    if (previous != NULL
3251
28
        && (previous->flags & SEC_LOAD) != 0)
3252
14
      previous->size += sofar - old_sofar;
3253
28
  }
3254
3255
28
#endif
3256
3257
      /* In demand paged files the low order bits of the file offset
3258
   must match the low order bits of the virtual address.  */
3259
28
#ifdef COFF_PAGE_SIZE
3260
28
      if ((abfd->flags & D_PAGED) != 0
3261
28
    && (current->flags & SEC_ALLOC) != 0)
3262
0
  sofar += (current->vma - (bfd_vma) sofar) % page_size;
3263
28
#endif
3264
28
      current->filepos = sofar;
3265
3266
28
#ifdef COFF_IMAGE_WITH_PE
3267
      /* Set the padded size.  */
3268
28
      current->size = (current->size + page_size - 1) & -page_size;
3269
28
#endif
3270
3271
28
      sofar += current->size;
3272
3273
28
#ifdef ALIGN_SECTIONS_IN_FILE
3274
      /* Make sure that this section is of the right size too.  */
3275
28
      if ((abfd->flags & EXEC_P) == 0)
3276
0
  {
3277
0
    bfd_size_type old_size;
3278
3279
0
    old_size = current->size;
3280
0
    current->size = BFD_ALIGN (current->size,
3281
0
             (bfd_vma) 1 << current->alignment_power);
3282
0
    align_adjust = current->size != old_size;
3283
0
    sofar += current->size - old_size;
3284
0
  }
3285
28
      else
3286
28
  {
3287
28
    old_sofar = sofar;
3288
28
#ifdef COFF_IMAGE_WITH_PE
3289
28
    sofar = BFD_ALIGN (sofar, page_size);
3290
#else
3291
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3292
#endif
3293
28
    align_adjust = sofar != old_sofar;
3294
28
    current->size += sofar - old_sofar;
3295
28
  }
3296
28
#endif
3297
3298
28
#ifdef COFF_IMAGE_WITH_PE
3299
      /* For PE we need to make sure we pad out to the aligned
3300
   size, in case the caller only writes out data to the
3301
   unaligned size.  */
3302
28
      if (pei_section_data (abfd, current)->virt_size < current->size)
3303
19
  align_adjust = true;
3304
28
#endif
3305
3306
28
#ifdef _LIB
3307
      /* Force .lib sections to start at zero.  The vma is then
3308
   incremented in coff_set_section_contents.  This is right for
3309
   SVR3.2.  */
3310
28
      if (strcmp (current->name, _LIB) == 0)
3311
0
  bfd_set_section_vma (current, 0);
3312
28
#endif
3313
3314
28
#ifdef ALIGN_SECTIONS_IN_FILE
3315
28
      previous = current;
3316
28
#endif
3317
28
    }
3318
3319
  /* It is now safe to write to the output file.  If we needed an
3320
     alignment adjustment for the last section, then make sure that
3321
     there is a byte at offset sofar.  If there are no symbols and no
3322
     relocs, then nothing follows the last section.  If we don't force
3323
     the last byte out, then the file may appear to be truncated.  */
3324
3
  if (align_adjust)
3325
2
    {
3326
2
      bfd_byte b;
3327
3328
2
      b = 0;
3329
2
      if (bfd_seek (abfd, sofar - 1, SEEK_SET) != 0
3330
2
    || bfd_write (&b, 1, abfd) != 1)
3331
0
  return false;
3332
2
    }
3333
3334
  /* Make sure the relocations are aligned.  We don't need to make
3335
     sure that this byte exists, because it will only matter if there
3336
     really are relocs.  */
3337
3
  sofar = BFD_ALIGN (sofar,
3338
3
         (bfd_vma) 1 << COFF_DEFAULT_SECTION_ALIGNMENT_POWER);
3339
3340
3
  obj_relocbase (abfd) = sofar;
3341
3
  abfd->output_has_begun = true;
3342
3343
3
  return true;
3344
3
}
coff-x86_64.c:coff_compute_section_file_positions
Line
Count
Source
2970
4
{
2971
4
  asection *current;
2972
4
  file_ptr sofar = bfd_coff_filhsz (abfd);
2973
4
  bool align_adjust;
2974
4
  unsigned int target_index;
2975
4
#ifdef ALIGN_SECTIONS_IN_FILE
2976
4
  asection *previous = NULL;
2977
4
  file_ptr old_sofar;
2978
4
#endif
2979
2980
#ifdef COFF_IMAGE_WITH_PE
2981
  unsigned int page_size;
2982
2983
  if (coff_data (abfd)->link_info
2984
      || (pe_data (abfd) && pe_data (abfd)->pe_opthdr.FileAlignment))
2985
    {
2986
      page_size = pe_data (abfd)->pe_opthdr.FileAlignment;
2987
2988
      /* If no file alignment has been set, default to one.
2989
   This repairs 'ld -r' for arm-wince-pe target.  */
2990
      if (page_size == 0)
2991
  page_size = 1;
2992
    }
2993
  else
2994
    page_size = PE_DEF_FILE_ALIGNMENT;
2995
#else
2996
4
#ifdef COFF_PAGE_SIZE
2997
4
  unsigned int page_size = COFF_PAGE_SIZE;
2998
4
#endif
2999
4
#endif
3000
3001
#ifdef RS6000COFF_C
3002
  /* On XCOFF, if we have symbols, set up the .debug section.  */
3003
  if (bfd_get_symcount (abfd) > 0)
3004
    {
3005
      bfd_size_type sz;
3006
      bfd_size_type i, symcount;
3007
      asymbol **symp;
3008
3009
      sz = 0;
3010
      symcount = bfd_get_symcount (abfd);
3011
      for (symp = abfd->outsymbols, i = 0; i < symcount; symp++, i++)
3012
  {
3013
    coff_symbol_type *cf;
3014
3015
    cf = coff_symbol_from (*symp);
3016
    if (cf != NULL
3017
        && cf->native != NULL
3018
        && cf->native->is_sym
3019
        && SYMNAME_IN_DEBUG (&cf->native->u.syment))
3020
      {
3021
        size_t len;
3022
3023
        len = strlen (bfd_asymbol_name (*symp));
3024
        if (len > SYMNMLEN || bfd_coff_force_symnames_in_strings (abfd))
3025
    sz += len + 1 + bfd_coff_debug_string_prefix_length (abfd);
3026
      }
3027
  }
3028
      if (sz > 0)
3029
  {
3030
    asection *dsec;
3031
3032
    dsec = bfd_make_section_old_way (abfd, DOT_DEBUG);
3033
    if (dsec == NULL)
3034
      abort ();
3035
    dsec->size = sz;
3036
    dsec->flags |= SEC_HAS_CONTENTS;
3037
  }
3038
    }
3039
#endif
3040
3041
4
  if (bfd_get_start_address (abfd))
3042
    /*  A start address may have been added to the original file. In this
3043
  case it will need an optional header to record it.  */
3044
0
    abfd->flags |= EXEC_P;
3045
3046
4
  if (abfd->flags & EXEC_P)
3047
0
    sofar += bfd_coff_aoutsz (abfd);
3048
#ifdef RS6000COFF_C
3049
  else if (xcoff_data (abfd)->full_aouthdr)
3050
    sofar += bfd_coff_aoutsz (abfd);
3051
  else
3052
    sofar += SMALL_AOUTSZ;
3053
#endif
3054
3055
4
  sofar += abfd->section_count * bfd_coff_scnhsz (abfd);
3056
3057
#ifdef RS6000COFF_C
3058
  /* XCOFF handles overflows in the reloc and line number count fields
3059
     by allocating a new section header to hold the correct counts.  */
3060
  for (current = abfd->sections; current != NULL; current = current->next)
3061
    if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3062
      sofar += bfd_coff_scnhsz (abfd);
3063
#endif
3064
3065
4
  if (coff_data (abfd)->section_by_target_index)
3066
0
    htab_empty (coff_data (abfd)->section_by_target_index);
3067
3068
#ifdef COFF_IMAGE_WITH_PE
3069
  {
3070
    /* PE requires the sections to be in memory order when listed in
3071
       the section headers.  It also does not like empty loadable
3072
       sections.  The sections apparently do not have to be in the
3073
       right order in the image file itself, but we do need to get the
3074
       target_index values right.  */
3075
3076
    unsigned int count;
3077
    asection **section_list;
3078
    unsigned int i;
3079
    bfd_size_type amt;
3080
3081
#ifdef COFF_PAGE_SIZE
3082
    /* Clear D_PAGED if section / file alignment aren't suitable for
3083
       paging at COFF_PAGE_SIZE granularity.  */
3084
   if (pe_data (abfd)->pe_opthdr.SectionAlignment < COFF_PAGE_SIZE
3085
       || page_size < COFF_PAGE_SIZE)
3086
     abfd->flags &= ~D_PAGED;
3087
#endif
3088
3089
    count = 0;
3090
    for (current = abfd->sections; current != NULL; current = current->next)
3091
      ++count;
3092
3093
    /* We allocate an extra cell to simplify the final loop.  */
3094
    amt = sizeof (struct asection *) * (count + 1);
3095
    section_list = (asection **) bfd_malloc (amt);
3096
    if (section_list == NULL)
3097
      return false;
3098
3099
    i = 0;
3100
    for (current = abfd->sections; current != NULL; current = current->next)
3101
      {
3102
  section_list[i] = current;
3103
  ++i;
3104
      }
3105
    section_list[i] = NULL;
3106
3107
    qsort (section_list, count, sizeof (asection *), sort_by_secaddr);
3108
3109
    /* Rethread the linked list into sorted order; at the same time,
3110
       assign target_index values.  */
3111
    target_index = 1;
3112
    abfd->sections = NULL;
3113
    abfd->section_last = NULL;
3114
    for (i = 0; i < count; i++)
3115
      {
3116
  current = section_list[i];
3117
  bfd_section_list_append (abfd, current);
3118
3119
  /* Later, if the section has zero size, we'll be throwing it
3120
     away, so we don't want to number it now.  Note that having
3121
     a zero size and having real contents are different
3122
     concepts: .bss has no contents, but (usually) non-zero
3123
     size.  */
3124
  if (current->size == 0)
3125
    {
3126
      /* Discard.  However, it still might have (valid) symbols
3127
         in it, so arbitrarily set it to section 1 (indexing is
3128
         1-based here; usually .text).  __end__ and other
3129
         contents of .endsection really have this happen.
3130
         FIXME: This seems somewhat dubious.  */
3131
      current->target_index = 1;
3132
    }
3133
  else
3134
    current->target_index = target_index++;
3135
      }
3136
3137
    free (section_list);
3138
  }
3139
#else /* ! COFF_IMAGE_WITH_PE */
3140
4
  {
3141
    /* Set the target_index field.  */
3142
4
    target_index = 1;
3143
273
    for (current = abfd->sections; current != NULL; current = current->next)
3144
269
      current->target_index = target_index++;
3145
4
  }
3146
4
#endif /* ! COFF_IMAGE_WITH_PE */
3147
3148
4
  if (target_index >= bfd_coff_max_nscns (abfd))
3149
0
    {
3150
0
      bfd_set_error (bfd_error_file_too_big);
3151
0
      _bfd_error_handler
3152
  /* xgettext:c-format */
3153
0
  (_("%pB: too many sections (%d)"), abfd, target_index);
3154
0
      return false;
3155
0
    }
3156
3157
4
  align_adjust = false;
3158
4
  for (current = abfd->sections;
3159
273
       current != NULL;
3160
269
       current = current->next)
3161
269
    {
3162
#ifdef COFF_IMAGE_WITH_PE
3163
      /* With PE we have to pad each section to be a multiple of its
3164
   page size too, and remember both sizes.  */
3165
      if (coff_section_data (abfd, current) == NULL)
3166
  {
3167
    size_t amt = sizeof (struct coff_section_tdata);
3168
3169
    current->used_by_bfd = bfd_zalloc (abfd, amt);
3170
    if (current->used_by_bfd == NULL)
3171
      return false;
3172
  }
3173
      if (pei_section_data (abfd, current) == NULL)
3174
  {
3175
    size_t amt = sizeof (struct pei_section_tdata);
3176
3177
    coff_section_data (abfd, current)->tdata = bfd_zalloc (abfd, amt);
3178
    if (coff_section_data (abfd, current)->tdata == NULL)
3179
      return false;
3180
  }
3181
      if (pei_section_data (abfd, current)->virt_size == 0)
3182
  pei_section_data (abfd, current)->virt_size = current->size;
3183
#endif
3184
3185
      /* Only deal with sections which have contents.  */
3186
269
      if (!(current->flags & SEC_HAS_CONTENTS))
3187
266
  continue;
3188
3189
3
      current->rawsize = current->size;
3190
3191
#ifdef COFF_IMAGE_WITH_PE
3192
      /* Make sure we skip empty sections in a PE image.  */
3193
      if (current->size == 0)
3194
  continue;
3195
#endif
3196
3197
      /* Align the sections in the file to the same boundary on
3198
   which they are aligned in virtual memory.  */
3199
3
#ifdef ALIGN_SECTIONS_IN_FILE
3200
3
      if ((abfd->flags & EXEC_P) != 0)
3201
0
  {
3202
    /* Make sure this section is aligned on the right boundary - by
3203
       padding the previous section up if necessary.  */
3204
0
    old_sofar = sofar;
3205
3206
#ifdef COFF_IMAGE_WITH_PE
3207
    sofar = BFD_ALIGN (sofar, page_size);
3208
#else
3209
0
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3210
0
#endif
3211
3212
#ifdef RS6000COFF_C
3213
    /* Make sure the file offset and the vma of .text/.data are at the
3214
       same page offset, so that the file can be mmap'ed without being
3215
       relocated.  Failing that, AIX is able to load and execute the
3216
       program, but it will be silently relocated (possible as
3217
       executables are PIE).  But the relocation is slightly costly and
3218
       complexify the use of addr2line or gdb.  So better to avoid it,
3219
       like does the native linker.  Usually gnu ld makes sure that
3220
       the vma of .text is the file offset so this issue shouldn't
3221
       appear unless you are stripping such an executable.
3222
3223
       AIX loader checks the text section alignment of (vma - filepos),
3224
       and the native linker doesn't try to align the text sections.
3225
       For example:
3226
3227
       0 .text       000054cc  10000128  10000128  00000128  2**5
3228
           CONTENTS, ALLOC, LOAD, CODE
3229
3230
       Don't perform the above tweak if the previous one is .tdata,
3231
       as it will increase the memory allocated for every threads
3232
       created and not just improve performances with gdb.
3233
    */
3234
3235
    if ((current->flags & SEC_LOAD) != 0
3236
        && (!strcmp (current->name, _TEXT)
3237
      || !strcmp (current->name, _DATA))
3238
        && (previous == NULL || strcmp(previous->name, _TDATA)))
3239
      {
3240
        bfd_vma align = 4096;
3241
        bfd_vma sofar_off = sofar % align;
3242
        bfd_vma vma_off = current->vma % align;
3243
3244
        if (vma_off > sofar_off)
3245
    sofar += vma_off - sofar_off;
3246
        else if (vma_off < sofar_off)
3247
    sofar += align + vma_off - sofar_off;
3248
      }
3249
#endif
3250
0
    if (previous != NULL
3251
0
        && (previous->flags & SEC_LOAD) != 0)
3252
0
      previous->size += sofar - old_sofar;
3253
0
  }
3254
3255
3
#endif
3256
3257
      /* In demand paged files the low order bits of the file offset
3258
   must match the low order bits of the virtual address.  */
3259
3
#ifdef COFF_PAGE_SIZE
3260
3
      if ((abfd->flags & D_PAGED) != 0
3261
3
    && (current->flags & SEC_ALLOC) != 0)
3262
1
  sofar += (current->vma - (bfd_vma) sofar) % page_size;
3263
3
#endif
3264
3
      current->filepos = sofar;
3265
3266
#ifdef COFF_IMAGE_WITH_PE
3267
      /* Set the padded size.  */
3268
      current->size = (current->size + page_size - 1) & -page_size;
3269
#endif
3270
3271
3
      sofar += current->size;
3272
3273
3
#ifdef ALIGN_SECTIONS_IN_FILE
3274
      /* Make sure that this section is of the right size too.  */
3275
3
      if ((abfd->flags & EXEC_P) == 0)
3276
3
  {
3277
3
    bfd_size_type old_size;
3278
3279
3
    old_size = current->size;
3280
3
    current->size = BFD_ALIGN (current->size,
3281
3
             (bfd_vma) 1 << current->alignment_power);
3282
3
    align_adjust = current->size != old_size;
3283
3
    sofar += current->size - old_size;
3284
3
  }
3285
0
      else
3286
0
  {
3287
0
    old_sofar = sofar;
3288
#ifdef COFF_IMAGE_WITH_PE
3289
    sofar = BFD_ALIGN (sofar, page_size);
3290
#else
3291
0
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3292
0
#endif
3293
0
    align_adjust = sofar != old_sofar;
3294
0
    current->size += sofar - old_sofar;
3295
0
  }
3296
3
#endif
3297
3298
#ifdef COFF_IMAGE_WITH_PE
3299
      /* For PE we need to make sure we pad out to the aligned
3300
   size, in case the caller only writes out data to the
3301
   unaligned size.  */
3302
      if (pei_section_data (abfd, current)->virt_size < current->size)
3303
  align_adjust = true;
3304
#endif
3305
3306
3
#ifdef _LIB
3307
      /* Force .lib sections to start at zero.  The vma is then
3308
   incremented in coff_set_section_contents.  This is right for
3309
   SVR3.2.  */
3310
3
      if (strcmp (current->name, _LIB) == 0)
3311
0
  bfd_set_section_vma (current, 0);
3312
3
#endif
3313
3314
3
#ifdef ALIGN_SECTIONS_IN_FILE
3315
3
      previous = current;
3316
3
#endif
3317
3
    }
3318
3319
  /* It is now safe to write to the output file.  If we needed an
3320
     alignment adjustment for the last section, then make sure that
3321
     there is a byte at offset sofar.  If there are no symbols and no
3322
     relocs, then nothing follows the last section.  If we don't force
3323
     the last byte out, then the file may appear to be truncated.  */
3324
4
  if (align_adjust)
3325
0
    {
3326
0
      bfd_byte b;
3327
3328
0
      b = 0;
3329
0
      if (bfd_seek (abfd, sofar - 1, SEEK_SET) != 0
3330
0
    || bfd_write (&b, 1, abfd) != 1)
3331
0
  return false;
3332
0
    }
3333
3334
  /* Make sure the relocations are aligned.  We don't need to make
3335
     sure that this byte exists, because it will only matter if there
3336
     really are relocs.  */
3337
4
  sofar = BFD_ALIGN (sofar,
3338
4
         (bfd_vma) 1 << COFF_DEFAULT_SECTION_ALIGNMENT_POWER);
3339
3340
4
  obj_relocbase (abfd) = sofar;
3341
4
  abfd->output_has_begun = true;
3342
3343
4
  return true;
3344
4
}
Unexecuted instantiation: coff64-rs6000.c:coff_compute_section_file_positions
Unexecuted instantiation: pe-aarch64.c:coff_compute_section_file_positions
pei-aarch64.c:coff_compute_section_file_positions
Line
Count
Source
2970
2
{
2971
2
  asection *current;
2972
2
  file_ptr sofar = bfd_coff_filhsz (abfd);
2973
2
  bool align_adjust;
2974
2
  unsigned int target_index;
2975
2
#ifdef ALIGN_SECTIONS_IN_FILE
2976
2
  asection *previous = NULL;
2977
2
  file_ptr old_sofar;
2978
2
#endif
2979
2980
2
#ifdef COFF_IMAGE_WITH_PE
2981
2
  unsigned int page_size;
2982
2983
2
  if (coff_data (abfd)->link_info
2984
2
      || (pe_data (abfd) && pe_data (abfd)->pe_opthdr.FileAlignment))
2985
0
    {
2986
0
      page_size = pe_data (abfd)->pe_opthdr.FileAlignment;
2987
2988
      /* If no file alignment has been set, default to one.
2989
   This repairs 'ld -r' for arm-wince-pe target.  */
2990
0
      if (page_size == 0)
2991
0
  page_size = 1;
2992
0
    }
2993
2
  else
2994
2
    page_size = PE_DEF_FILE_ALIGNMENT;
2995
#else
2996
#ifdef COFF_PAGE_SIZE
2997
  unsigned int page_size = COFF_PAGE_SIZE;
2998
#endif
2999
#endif
3000
3001
#ifdef RS6000COFF_C
3002
  /* On XCOFF, if we have symbols, set up the .debug section.  */
3003
  if (bfd_get_symcount (abfd) > 0)
3004
    {
3005
      bfd_size_type sz;
3006
      bfd_size_type i, symcount;
3007
      asymbol **symp;
3008
3009
      sz = 0;
3010
      symcount = bfd_get_symcount (abfd);
3011
      for (symp = abfd->outsymbols, i = 0; i < symcount; symp++, i++)
3012
  {
3013
    coff_symbol_type *cf;
3014
3015
    cf = coff_symbol_from (*symp);
3016
    if (cf != NULL
3017
        && cf->native != NULL
3018
        && cf->native->is_sym
3019
        && SYMNAME_IN_DEBUG (&cf->native->u.syment))
3020
      {
3021
        size_t len;
3022
3023
        len = strlen (bfd_asymbol_name (*symp));
3024
        if (len > SYMNMLEN || bfd_coff_force_symnames_in_strings (abfd))
3025
    sz += len + 1 + bfd_coff_debug_string_prefix_length (abfd);
3026
      }
3027
  }
3028
      if (sz > 0)
3029
  {
3030
    asection *dsec;
3031
3032
    dsec = bfd_make_section_old_way (abfd, DOT_DEBUG);
3033
    if (dsec == NULL)
3034
      abort ();
3035
    dsec->size = sz;
3036
    dsec->flags |= SEC_HAS_CONTENTS;
3037
  }
3038
    }
3039
#endif
3040
3041
2
  if (bfd_get_start_address (abfd))
3042
    /*  A start address may have been added to the original file. In this
3043
  case it will need an optional header to record it.  */
3044
0
    abfd->flags |= EXEC_P;
3045
3046
2
  if (abfd->flags & EXEC_P)
3047
0
    sofar += bfd_coff_aoutsz (abfd);
3048
#ifdef RS6000COFF_C
3049
  else if (xcoff_data (abfd)->full_aouthdr)
3050
    sofar += bfd_coff_aoutsz (abfd);
3051
  else
3052
    sofar += SMALL_AOUTSZ;
3053
#endif
3054
3055
2
  sofar += abfd->section_count * bfd_coff_scnhsz (abfd);
3056
3057
#ifdef RS6000COFF_C
3058
  /* XCOFF handles overflows in the reloc and line number count fields
3059
     by allocating a new section header to hold the correct counts.  */
3060
  for (current = abfd->sections; current != NULL; current = current->next)
3061
    if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3062
      sofar += bfd_coff_scnhsz (abfd);
3063
#endif
3064
3065
2
  if (coff_data (abfd)->section_by_target_index)
3066
0
    htab_empty (coff_data (abfd)->section_by_target_index);
3067
3068
2
#ifdef COFF_IMAGE_WITH_PE
3069
2
  {
3070
    /* PE requires the sections to be in memory order when listed in
3071
       the section headers.  It also does not like empty loadable
3072
       sections.  The sections apparently do not have to be in the
3073
       right order in the image file itself, but we do need to get the
3074
       target_index values right.  */
3075
3076
2
    unsigned int count;
3077
2
    asection **section_list;
3078
2
    unsigned int i;
3079
2
    bfd_size_type amt;
3080
3081
2
#ifdef COFF_PAGE_SIZE
3082
    /* Clear D_PAGED if section / file alignment aren't suitable for
3083
       paging at COFF_PAGE_SIZE granularity.  */
3084
2
   if (pe_data (abfd)->pe_opthdr.SectionAlignment < COFF_PAGE_SIZE
3085
2
       || page_size < COFF_PAGE_SIZE)
3086
2
     abfd->flags &= ~D_PAGED;
3087
2
#endif
3088
3089
2
    count = 0;
3090
135
    for (current = abfd->sections; current != NULL; current = current->next)
3091
133
      ++count;
3092
3093
    /* We allocate an extra cell to simplify the final loop.  */
3094
2
    amt = sizeof (struct asection *) * (count + 1);
3095
2
    section_list = (asection **) bfd_malloc (amt);
3096
2
    if (section_list == NULL)
3097
0
      return false;
3098
3099
2
    i = 0;
3100
135
    for (current = abfd->sections; current != NULL; current = current->next)
3101
133
      {
3102
133
  section_list[i] = current;
3103
133
  ++i;
3104
133
      }
3105
2
    section_list[i] = NULL;
3106
3107
2
    qsort (section_list, count, sizeof (asection *), sort_by_secaddr);
3108
3109
    /* Rethread the linked list into sorted order; at the same time,
3110
       assign target_index values.  */
3111
2
    target_index = 1;
3112
2
    abfd->sections = NULL;
3113
2
    abfd->section_last = NULL;
3114
135
    for (i = 0; i < count; i++)
3115
133
      {
3116
133
  current = section_list[i];
3117
133
  bfd_section_list_append (abfd, current);
3118
3119
  /* Later, if the section has zero size, we'll be throwing it
3120
     away, so we don't want to number it now.  Note that having
3121
     a zero size and having real contents are different
3122
     concepts: .bss has no contents, but (usually) non-zero
3123
     size.  */
3124
133
  if (current->size == 0)
3125
130
    {
3126
      /* Discard.  However, it still might have (valid) symbols
3127
         in it, so arbitrarily set it to section 1 (indexing is
3128
         1-based here; usually .text).  __end__ and other
3129
         contents of .endsection really have this happen.
3130
         FIXME: This seems somewhat dubious.  */
3131
130
      current->target_index = 1;
3132
130
    }
3133
3
  else
3134
3
    current->target_index = target_index++;
3135
133
      }
3136
3137
2
    free (section_list);
3138
2
  }
3139
#else /* ! COFF_IMAGE_WITH_PE */
3140
  {
3141
    /* Set the target_index field.  */
3142
    target_index = 1;
3143
    for (current = abfd->sections; current != NULL; current = current->next)
3144
      current->target_index = target_index++;
3145
  }
3146
#endif /* ! COFF_IMAGE_WITH_PE */
3147
3148
2
  if (target_index >= bfd_coff_max_nscns (abfd))
3149
0
    {
3150
0
      bfd_set_error (bfd_error_file_too_big);
3151
0
      _bfd_error_handler
3152
  /* xgettext:c-format */
3153
0
  (_("%pB: too many sections (%d)"), abfd, target_index);
3154
0
      return false;
3155
0
    }
3156
3157
2
  align_adjust = false;
3158
2
  for (current = abfd->sections;
3159
135
       current != NULL;
3160
133
       current = current->next)
3161
133
    {
3162
133
#ifdef COFF_IMAGE_WITH_PE
3163
      /* With PE we have to pad each section to be a multiple of its
3164
   page size too, and remember both sizes.  */
3165
133
      if (coff_section_data (abfd, current) == NULL)
3166
2
  {
3167
2
    size_t amt = sizeof (struct coff_section_tdata);
3168
3169
2
    current->used_by_bfd = bfd_zalloc (abfd, amt);
3170
2
    if (current->used_by_bfd == NULL)
3171
0
      return false;
3172
2
  }
3173
133
      if (pei_section_data (abfd, current) == NULL)
3174
2
  {
3175
2
    size_t amt = sizeof (struct pei_section_tdata);
3176
3177
2
    coff_section_data (abfd, current)->tdata = bfd_zalloc (abfd, amt);
3178
2
    if (coff_section_data (abfd, current)->tdata == NULL)
3179
0
      return false;
3180
2
  }
3181
133
      if (pei_section_data (abfd, current)->virt_size == 0)
3182
133
  pei_section_data (abfd, current)->virt_size = current->size;
3183
133
#endif
3184
3185
      /* Only deal with sections which have contents.  */
3186
133
      if (!(current->flags & SEC_HAS_CONTENTS))
3187
131
  continue;
3188
3189
2
      current->rawsize = current->size;
3190
3191
2
#ifdef COFF_IMAGE_WITH_PE
3192
      /* Make sure we skip empty sections in a PE image.  */
3193
2
      if (current->size == 0)
3194
0
  continue;
3195
2
#endif
3196
3197
      /* Align the sections in the file to the same boundary on
3198
   which they are aligned in virtual memory.  */
3199
2
#ifdef ALIGN_SECTIONS_IN_FILE
3200
2
      if ((abfd->flags & EXEC_P) != 0)
3201
0
  {
3202
    /* Make sure this section is aligned on the right boundary - by
3203
       padding the previous section up if necessary.  */
3204
0
    old_sofar = sofar;
3205
3206
0
#ifdef COFF_IMAGE_WITH_PE
3207
0
    sofar = BFD_ALIGN (sofar, page_size);
3208
#else
3209
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3210
#endif
3211
3212
#ifdef RS6000COFF_C
3213
    /* Make sure the file offset and the vma of .text/.data are at the
3214
       same page offset, so that the file can be mmap'ed without being
3215
       relocated.  Failing that, AIX is able to load and execute the
3216
       program, but it will be silently relocated (possible as
3217
       executables are PIE).  But the relocation is slightly costly and
3218
       complexify the use of addr2line or gdb.  So better to avoid it,
3219
       like does the native linker.  Usually gnu ld makes sure that
3220
       the vma of .text is the file offset so this issue shouldn't
3221
       appear unless you are stripping such an executable.
3222
3223
       AIX loader checks the text section alignment of (vma - filepos),
3224
       and the native linker doesn't try to align the text sections.
3225
       For example:
3226
3227
       0 .text       000054cc  10000128  10000128  00000128  2**5
3228
           CONTENTS, ALLOC, LOAD, CODE
3229
3230
       Don't perform the above tweak if the previous one is .tdata,
3231
       as it will increase the memory allocated for every threads
3232
       created and not just improve performances with gdb.
3233
    */
3234
3235
    if ((current->flags & SEC_LOAD) != 0
3236
        && (!strcmp (current->name, _TEXT)
3237
      || !strcmp (current->name, _DATA))
3238
        && (previous == NULL || strcmp(previous->name, _TDATA)))
3239
      {
3240
        bfd_vma align = 4096;
3241
        bfd_vma sofar_off = sofar % align;
3242
        bfd_vma vma_off = current->vma % align;
3243
3244
        if (vma_off > sofar_off)
3245
    sofar += vma_off - sofar_off;
3246
        else if (vma_off < sofar_off)
3247
    sofar += align + vma_off - sofar_off;
3248
      }
3249
#endif
3250
0
    if (previous != NULL
3251
0
        && (previous->flags & SEC_LOAD) != 0)
3252
0
      previous->size += sofar - old_sofar;
3253
0
  }
3254
3255
2
#endif
3256
3257
      /* In demand paged files the low order bits of the file offset
3258
   must match the low order bits of the virtual address.  */
3259
2
#ifdef COFF_PAGE_SIZE
3260
2
      if ((abfd->flags & D_PAGED) != 0
3261
2
    && (current->flags & SEC_ALLOC) != 0)
3262
0
  sofar += (current->vma - (bfd_vma) sofar) % page_size;
3263
2
#endif
3264
2
      current->filepos = sofar;
3265
3266
2
#ifdef COFF_IMAGE_WITH_PE
3267
      /* Set the padded size.  */
3268
2
      current->size = (current->size + page_size - 1) & -page_size;
3269
2
#endif
3270
3271
2
      sofar += current->size;
3272
3273
2
#ifdef ALIGN_SECTIONS_IN_FILE
3274
      /* Make sure that this section is of the right size too.  */
3275
2
      if ((abfd->flags & EXEC_P) == 0)
3276
2
  {
3277
2
    bfd_size_type old_size;
3278
3279
2
    old_size = current->size;
3280
2
    current->size = BFD_ALIGN (current->size,
3281
2
             (bfd_vma) 1 << current->alignment_power);
3282
2
    align_adjust = current->size != old_size;
3283
2
    sofar += current->size - old_size;
3284
2
  }
3285
0
      else
3286
0
  {
3287
0
    old_sofar = sofar;
3288
0
#ifdef COFF_IMAGE_WITH_PE
3289
0
    sofar = BFD_ALIGN (sofar, page_size);
3290
#else
3291
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3292
#endif
3293
0
    align_adjust = sofar != old_sofar;
3294
0
    current->size += sofar - old_sofar;
3295
0
  }
3296
2
#endif
3297
3298
2
#ifdef COFF_IMAGE_WITH_PE
3299
      /* For PE we need to make sure we pad out to the aligned
3300
   size, in case the caller only writes out data to the
3301
   unaligned size.  */
3302
2
      if (pei_section_data (abfd, current)->virt_size < current->size)
3303
2
  align_adjust = true;
3304
2
#endif
3305
3306
2
#ifdef _LIB
3307
      /* Force .lib sections to start at zero.  The vma is then
3308
   incremented in coff_set_section_contents.  This is right for
3309
   SVR3.2.  */
3310
2
      if (strcmp (current->name, _LIB) == 0)
3311
0
  bfd_set_section_vma (current, 0);
3312
2
#endif
3313
3314
2
#ifdef ALIGN_SECTIONS_IN_FILE
3315
2
      previous = current;
3316
2
#endif
3317
2
    }
3318
3319
  /* It is now safe to write to the output file.  If we needed an
3320
     alignment adjustment for the last section, then make sure that
3321
     there is a byte at offset sofar.  If there are no symbols and no
3322
     relocs, then nothing follows the last section.  If we don't force
3323
     the last byte out, then the file may appear to be truncated.  */
3324
2
  if (align_adjust)
3325
1
    {
3326
1
      bfd_byte b;
3327
3328
1
      b = 0;
3329
1
      if (bfd_seek (abfd, sofar - 1, SEEK_SET) != 0
3330
1
    || bfd_write (&b, 1, abfd) != 1)
3331
0
  return false;
3332
1
    }
3333
3334
  /* Make sure the relocations are aligned.  We don't need to make
3335
     sure that this byte exists, because it will only matter if there
3336
     really are relocs.  */
3337
2
  sofar = BFD_ALIGN (sofar,
3338
2
         (bfd_vma) 1 << COFF_DEFAULT_SECTION_ALIGNMENT_POWER);
3339
3340
2
  obj_relocbase (abfd) = sofar;
3341
2
  abfd->output_has_begun = true;
3342
3343
2
  return true;
3344
2
}
pei-ia64.c:coff_compute_section_file_positions
Line
Count
Source
2970
1
{
2971
1
  asection *current;
2972
1
  file_ptr sofar = bfd_coff_filhsz (abfd);
2973
1
  bool align_adjust;
2974
1
  unsigned int target_index;
2975
1
#ifdef ALIGN_SECTIONS_IN_FILE
2976
1
  asection *previous = NULL;
2977
1
  file_ptr old_sofar;
2978
1
#endif
2979
2980
1
#ifdef COFF_IMAGE_WITH_PE
2981
1
  unsigned int page_size;
2982
2983
1
  if (coff_data (abfd)->link_info
2984
1
      || (pe_data (abfd) && pe_data (abfd)->pe_opthdr.FileAlignment))
2985
1
    {
2986
1
      page_size = pe_data (abfd)->pe_opthdr.FileAlignment;
2987
2988
      /* If no file alignment has been set, default to one.
2989
   This repairs 'ld -r' for arm-wince-pe target.  */
2990
1
      if (page_size == 0)
2991
0
  page_size = 1;
2992
1
    }
2993
0
  else
2994
0
    page_size = PE_DEF_FILE_ALIGNMENT;
2995
#else
2996
#ifdef COFF_PAGE_SIZE
2997
  unsigned int page_size = COFF_PAGE_SIZE;
2998
#endif
2999
#endif
3000
3001
#ifdef RS6000COFF_C
3002
  /* On XCOFF, if we have symbols, set up the .debug section.  */
3003
  if (bfd_get_symcount (abfd) > 0)
3004
    {
3005
      bfd_size_type sz;
3006
      bfd_size_type i, symcount;
3007
      asymbol **symp;
3008
3009
      sz = 0;
3010
      symcount = bfd_get_symcount (abfd);
3011
      for (symp = abfd->outsymbols, i = 0; i < symcount; symp++, i++)
3012
  {
3013
    coff_symbol_type *cf;
3014
3015
    cf = coff_symbol_from (*symp);
3016
    if (cf != NULL
3017
        && cf->native != NULL
3018
        && cf->native->is_sym
3019
        && SYMNAME_IN_DEBUG (&cf->native->u.syment))
3020
      {
3021
        size_t len;
3022
3023
        len = strlen (bfd_asymbol_name (*symp));
3024
        if (len > SYMNMLEN || bfd_coff_force_symnames_in_strings (abfd))
3025
    sz += len + 1 + bfd_coff_debug_string_prefix_length (abfd);
3026
      }
3027
  }
3028
      if (sz > 0)
3029
  {
3030
    asection *dsec;
3031
3032
    dsec = bfd_make_section_old_way (abfd, DOT_DEBUG);
3033
    if (dsec == NULL)
3034
      abort ();
3035
    dsec->size = sz;
3036
    dsec->flags |= SEC_HAS_CONTENTS;
3037
  }
3038
    }
3039
#endif
3040
3041
1
  if (bfd_get_start_address (abfd))
3042
    /*  A start address may have been added to the original file. In this
3043
  case it will need an optional header to record it.  */
3044
0
    abfd->flags |= EXEC_P;
3045
3046
1
  if (abfd->flags & EXEC_P)
3047
1
    sofar += bfd_coff_aoutsz (abfd);
3048
#ifdef RS6000COFF_C
3049
  else if (xcoff_data (abfd)->full_aouthdr)
3050
    sofar += bfd_coff_aoutsz (abfd);
3051
  else
3052
    sofar += SMALL_AOUTSZ;
3053
#endif
3054
3055
1
  sofar += abfd->section_count * bfd_coff_scnhsz (abfd);
3056
3057
#ifdef RS6000COFF_C
3058
  /* XCOFF handles overflows in the reloc and line number count fields
3059
     by allocating a new section header to hold the correct counts.  */
3060
  for (current = abfd->sections; current != NULL; current = current->next)
3061
    if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3062
      sofar += bfd_coff_scnhsz (abfd);
3063
#endif
3064
3065
1
  if (coff_data (abfd)->section_by_target_index)
3066
0
    htab_empty (coff_data (abfd)->section_by_target_index);
3067
3068
1
#ifdef COFF_IMAGE_WITH_PE
3069
1
  {
3070
    /* PE requires the sections to be in memory order when listed in
3071
       the section headers.  It also does not like empty loadable
3072
       sections.  The sections apparently do not have to be in the
3073
       right order in the image file itself, but we do need to get the
3074
       target_index values right.  */
3075
3076
1
    unsigned int count;
3077
1
    asection **section_list;
3078
1
    unsigned int i;
3079
1
    bfd_size_type amt;
3080
3081
1
#ifdef COFF_PAGE_SIZE
3082
    /* Clear D_PAGED if section / file alignment aren't suitable for
3083
       paging at COFF_PAGE_SIZE granularity.  */
3084
1
   if (pe_data (abfd)->pe_opthdr.SectionAlignment < COFF_PAGE_SIZE
3085
1
       || page_size < COFF_PAGE_SIZE)
3086
1
     abfd->flags &= ~D_PAGED;
3087
1
#endif
3088
3089
1
    count = 0;
3090
3
    for (current = abfd->sections; current != NULL; current = current->next)
3091
2
      ++count;
3092
3093
    /* We allocate an extra cell to simplify the final loop.  */
3094
1
    amt = sizeof (struct asection *) * (count + 1);
3095
1
    section_list = (asection **) bfd_malloc (amt);
3096
1
    if (section_list == NULL)
3097
0
      return false;
3098
3099
1
    i = 0;
3100
3
    for (current = abfd->sections; current != NULL; current = current->next)
3101
2
      {
3102
2
  section_list[i] = current;
3103
2
  ++i;
3104
2
      }
3105
1
    section_list[i] = NULL;
3106
3107
1
    qsort (section_list, count, sizeof (asection *), sort_by_secaddr);
3108
3109
    /* Rethread the linked list into sorted order; at the same time,
3110
       assign target_index values.  */
3111
1
    target_index = 1;
3112
1
    abfd->sections = NULL;
3113
1
    abfd->section_last = NULL;
3114
3
    for (i = 0; i < count; i++)
3115
2
      {
3116
2
  current = section_list[i];
3117
2
  bfd_section_list_append (abfd, current);
3118
3119
  /* Later, if the section has zero size, we'll be throwing it
3120
     away, so we don't want to number it now.  Note that having
3121
     a zero size and having real contents are different
3122
     concepts: .bss has no contents, but (usually) non-zero
3123
     size.  */
3124
2
  if (current->size == 0)
3125
0
    {
3126
      /* Discard.  However, it still might have (valid) symbols
3127
         in it, so arbitrarily set it to section 1 (indexing is
3128
         1-based here; usually .text).  __end__ and other
3129
         contents of .endsection really have this happen.
3130
         FIXME: This seems somewhat dubious.  */
3131
0
      current->target_index = 1;
3132
0
    }
3133
2
  else
3134
2
    current->target_index = target_index++;
3135
2
      }
3136
3137
1
    free (section_list);
3138
1
  }
3139
#else /* ! COFF_IMAGE_WITH_PE */
3140
  {
3141
    /* Set the target_index field.  */
3142
    target_index = 1;
3143
    for (current = abfd->sections; current != NULL; current = current->next)
3144
      current->target_index = target_index++;
3145
  }
3146
#endif /* ! COFF_IMAGE_WITH_PE */
3147
3148
1
  if (target_index >= bfd_coff_max_nscns (abfd))
3149
0
    {
3150
0
      bfd_set_error (bfd_error_file_too_big);
3151
0
      _bfd_error_handler
3152
  /* xgettext:c-format */
3153
0
  (_("%pB: too many sections (%d)"), abfd, target_index);
3154
0
      return false;
3155
0
    }
3156
3157
1
  align_adjust = false;
3158
1
  for (current = abfd->sections;
3159
3
       current != NULL;
3160
2
       current = current->next)
3161
2
    {
3162
2
#ifdef COFF_IMAGE_WITH_PE
3163
      /* With PE we have to pad each section to be a multiple of its
3164
   page size too, and remember both sizes.  */
3165
2
      if (coff_section_data (abfd, current) == NULL)
3166
2
  {
3167
2
    size_t amt = sizeof (struct coff_section_tdata);
3168
3169
2
    current->used_by_bfd = bfd_zalloc (abfd, amt);
3170
2
    if (current->used_by_bfd == NULL)
3171
0
      return false;
3172
2
  }
3173
2
      if (pei_section_data (abfd, current) == NULL)
3174
2
  {
3175
2
    size_t amt = sizeof (struct pei_section_tdata);
3176
3177
2
    coff_section_data (abfd, current)->tdata = bfd_zalloc (abfd, amt);
3178
2
    if (coff_section_data (abfd, current)->tdata == NULL)
3179
0
      return false;
3180
2
  }
3181
2
      if (pei_section_data (abfd, current)->virt_size == 0)
3182
2
  pei_section_data (abfd, current)->virt_size = current->size;
3183
2
#endif
3184
3185
      /* Only deal with sections which have contents.  */
3186
2
      if (!(current->flags & SEC_HAS_CONTENTS))
3187
0
  continue;
3188
3189
2
      current->rawsize = current->size;
3190
3191
2
#ifdef COFF_IMAGE_WITH_PE
3192
      /* Make sure we skip empty sections in a PE image.  */
3193
2
      if (current->size == 0)
3194
0
  continue;
3195
2
#endif
3196
3197
      /* Align the sections in the file to the same boundary on
3198
   which they are aligned in virtual memory.  */
3199
2
#ifdef ALIGN_SECTIONS_IN_FILE
3200
2
      if ((abfd->flags & EXEC_P) != 0)
3201
2
  {
3202
    /* Make sure this section is aligned on the right boundary - by
3203
       padding the previous section up if necessary.  */
3204
2
    old_sofar = sofar;
3205
3206
2
#ifdef COFF_IMAGE_WITH_PE
3207
2
    sofar = BFD_ALIGN (sofar, page_size);
3208
#else
3209
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3210
#endif
3211
3212
#ifdef RS6000COFF_C
3213
    /* Make sure the file offset and the vma of .text/.data are at the
3214
       same page offset, so that the file can be mmap'ed without being
3215
       relocated.  Failing that, AIX is able to load and execute the
3216
       program, but it will be silently relocated (possible as
3217
       executables are PIE).  But the relocation is slightly costly and
3218
       complexify the use of addr2line or gdb.  So better to avoid it,
3219
       like does the native linker.  Usually gnu ld makes sure that
3220
       the vma of .text is the file offset so this issue shouldn't
3221
       appear unless you are stripping such an executable.
3222
3223
       AIX loader checks the text section alignment of (vma - filepos),
3224
       and the native linker doesn't try to align the text sections.
3225
       For example:
3226
3227
       0 .text       000054cc  10000128  10000128  00000128  2**5
3228
           CONTENTS, ALLOC, LOAD, CODE
3229
3230
       Don't perform the above tweak if the previous one is .tdata,
3231
       as it will increase the memory allocated for every threads
3232
       created and not just improve performances with gdb.
3233
    */
3234
3235
    if ((current->flags & SEC_LOAD) != 0
3236
        && (!strcmp (current->name, _TEXT)
3237
      || !strcmp (current->name, _DATA))
3238
        && (previous == NULL || strcmp(previous->name, _TDATA)))
3239
      {
3240
        bfd_vma align = 4096;
3241
        bfd_vma sofar_off = sofar % align;
3242
        bfd_vma vma_off = current->vma % align;
3243
3244
        if (vma_off > sofar_off)
3245
    sofar += vma_off - sofar_off;
3246
        else if (vma_off < sofar_off)
3247
    sofar += align + vma_off - sofar_off;
3248
      }
3249
#endif
3250
2
    if (previous != NULL
3251
2
        && (previous->flags & SEC_LOAD) != 0)
3252
0
      previous->size += sofar - old_sofar;
3253
2
  }
3254
3255
2
#endif
3256
3257
      /* In demand paged files the low order bits of the file offset
3258
   must match the low order bits of the virtual address.  */
3259
2
#ifdef COFF_PAGE_SIZE
3260
2
      if ((abfd->flags & D_PAGED) != 0
3261
2
    && (current->flags & SEC_ALLOC) != 0)
3262
0
  sofar += (current->vma - (bfd_vma) sofar) % page_size;
3263
2
#endif
3264
2
      current->filepos = sofar;
3265
3266
2
#ifdef COFF_IMAGE_WITH_PE
3267
      /* Set the padded size.  */
3268
2
      current->size = (current->size + page_size - 1) & -page_size;
3269
2
#endif
3270
3271
2
      sofar += current->size;
3272
3273
2
#ifdef ALIGN_SECTIONS_IN_FILE
3274
      /* Make sure that this section is of the right size too.  */
3275
2
      if ((abfd->flags & EXEC_P) == 0)
3276
0
  {
3277
0
    bfd_size_type old_size;
3278
3279
0
    old_size = current->size;
3280
0
    current->size = BFD_ALIGN (current->size,
3281
0
             (bfd_vma) 1 << current->alignment_power);
3282
0
    align_adjust = current->size != old_size;
3283
0
    sofar += current->size - old_size;
3284
0
  }
3285
2
      else
3286
2
  {
3287
2
    old_sofar = sofar;
3288
2
#ifdef COFF_IMAGE_WITH_PE
3289
2
    sofar = BFD_ALIGN (sofar, page_size);
3290
#else
3291
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3292
#endif
3293
2
    align_adjust = sofar != old_sofar;
3294
2
    current->size += sofar - old_sofar;
3295
2
  }
3296
2
#endif
3297
3298
2
#ifdef COFF_IMAGE_WITH_PE
3299
      /* For PE we need to make sure we pad out to the aligned
3300
   size, in case the caller only writes out data to the
3301
   unaligned size.  */
3302
2
      if (pei_section_data (abfd, current)->virt_size < current->size)
3303
2
  align_adjust = true;
3304
2
#endif
3305
3306
2
#ifdef _LIB
3307
      /* Force .lib sections to start at zero.  The vma is then
3308
   incremented in coff_set_section_contents.  This is right for
3309
   SVR3.2.  */
3310
2
      if (strcmp (current->name, _LIB) == 0)
3311
0
  bfd_set_section_vma (current, 0);
3312
2
#endif
3313
3314
2
#ifdef ALIGN_SECTIONS_IN_FILE
3315
2
      previous = current;
3316
2
#endif
3317
2
    }
3318
3319
  /* It is now safe to write to the output file.  If we needed an
3320
     alignment adjustment for the last section, then make sure that
3321
     there is a byte at offset sofar.  If there are no symbols and no
3322
     relocs, then nothing follows the last section.  If we don't force
3323
     the last byte out, then the file may appear to be truncated.  */
3324
1
  if (align_adjust)
3325
1
    {
3326
1
      bfd_byte b;
3327
3328
1
      b = 0;
3329
1
      if (bfd_seek (abfd, sofar - 1, SEEK_SET) != 0
3330
1
    || bfd_write (&b, 1, abfd) != 1)
3331
0
  return false;
3332
1
    }
3333
3334
  /* Make sure the relocations are aligned.  We don't need to make
3335
     sure that this byte exists, because it will only matter if there
3336
     really are relocs.  */
3337
1
  sofar = BFD_ALIGN (sofar,
3338
1
         (bfd_vma) 1 << COFF_DEFAULT_SECTION_ALIGNMENT_POWER);
3339
3340
1
  obj_relocbase (abfd) = sofar;
3341
1
  abfd->output_has_begun = true;
3342
3343
1
  return true;
3344
1
}
Unexecuted instantiation: pei-loongarch64.c:coff_compute_section_file_positions
pei-riscv64.c:coff_compute_section_file_positions
Line
Count
Source
2970
5
{
2971
5
  asection *current;
2972
5
  file_ptr sofar = bfd_coff_filhsz (abfd);
2973
5
  bool align_adjust;
2974
5
  unsigned int target_index;
2975
5
#ifdef ALIGN_SECTIONS_IN_FILE
2976
5
  asection *previous = NULL;
2977
5
  file_ptr old_sofar;
2978
5
#endif
2979
2980
5
#ifdef COFF_IMAGE_WITH_PE
2981
5
  unsigned int page_size;
2982
2983
5
  if (coff_data (abfd)->link_info
2984
5
      || (pe_data (abfd) && pe_data (abfd)->pe_opthdr.FileAlignment))
2985
5
    {
2986
5
      page_size = pe_data (abfd)->pe_opthdr.FileAlignment;
2987
2988
      /* If no file alignment has been set, default to one.
2989
   This repairs 'ld -r' for arm-wince-pe target.  */
2990
5
      if (page_size == 0)
2991
0
  page_size = 1;
2992
5
    }
2993
0
  else
2994
0
    page_size = PE_DEF_FILE_ALIGNMENT;
2995
#else
2996
#ifdef COFF_PAGE_SIZE
2997
  unsigned int page_size = COFF_PAGE_SIZE;
2998
#endif
2999
#endif
3000
3001
#ifdef RS6000COFF_C
3002
  /* On XCOFF, if we have symbols, set up the .debug section.  */
3003
  if (bfd_get_symcount (abfd) > 0)
3004
    {
3005
      bfd_size_type sz;
3006
      bfd_size_type i, symcount;
3007
      asymbol **symp;
3008
3009
      sz = 0;
3010
      symcount = bfd_get_symcount (abfd);
3011
      for (symp = abfd->outsymbols, i = 0; i < symcount; symp++, i++)
3012
  {
3013
    coff_symbol_type *cf;
3014
3015
    cf = coff_symbol_from (*symp);
3016
    if (cf != NULL
3017
        && cf->native != NULL
3018
        && cf->native->is_sym
3019
        && SYMNAME_IN_DEBUG (&cf->native->u.syment))
3020
      {
3021
        size_t len;
3022
3023
        len = strlen (bfd_asymbol_name (*symp));
3024
        if (len > SYMNMLEN || bfd_coff_force_symnames_in_strings (abfd))
3025
    sz += len + 1 + bfd_coff_debug_string_prefix_length (abfd);
3026
      }
3027
  }
3028
      if (sz > 0)
3029
  {
3030
    asection *dsec;
3031
3032
    dsec = bfd_make_section_old_way (abfd, DOT_DEBUG);
3033
    if (dsec == NULL)
3034
      abort ();
3035
    dsec->size = sz;
3036
    dsec->flags |= SEC_HAS_CONTENTS;
3037
  }
3038
    }
3039
#endif
3040
3041
5
  if (bfd_get_start_address (abfd))
3042
    /*  A start address may have been added to the original file. In this
3043
  case it will need an optional header to record it.  */
3044
3
    abfd->flags |= EXEC_P;
3045
3046
5
  if (abfd->flags & EXEC_P)
3047
5
    sofar += bfd_coff_aoutsz (abfd);
3048
#ifdef RS6000COFF_C
3049
  else if (xcoff_data (abfd)->full_aouthdr)
3050
    sofar += bfd_coff_aoutsz (abfd);
3051
  else
3052
    sofar += SMALL_AOUTSZ;
3053
#endif
3054
3055
5
  sofar += abfd->section_count * bfd_coff_scnhsz (abfd);
3056
3057
#ifdef RS6000COFF_C
3058
  /* XCOFF handles overflows in the reloc and line number count fields
3059
     by allocating a new section header to hold the correct counts.  */
3060
  for (current = abfd->sections; current != NULL; current = current->next)
3061
    if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3062
      sofar += bfd_coff_scnhsz (abfd);
3063
#endif
3064
3065
5
  if (coff_data (abfd)->section_by_target_index)
3066
0
    htab_empty (coff_data (abfd)->section_by_target_index);
3067
3068
5
#ifdef COFF_IMAGE_WITH_PE
3069
5
  {
3070
    /* PE requires the sections to be in memory order when listed in
3071
       the section headers.  It also does not like empty loadable
3072
       sections.  The sections apparently do not have to be in the
3073
       right order in the image file itself, but we do need to get the
3074
       target_index values right.  */
3075
3076
5
    unsigned int count;
3077
5
    asection **section_list;
3078
5
    unsigned int i;
3079
5
    bfd_size_type amt;
3080
3081
#ifdef COFF_PAGE_SIZE
3082
    /* Clear D_PAGED if section / file alignment aren't suitable for
3083
       paging at COFF_PAGE_SIZE granularity.  */
3084
   if (pe_data (abfd)->pe_opthdr.SectionAlignment < COFF_PAGE_SIZE
3085
       || page_size < COFF_PAGE_SIZE)
3086
     abfd->flags &= ~D_PAGED;
3087
#endif
3088
3089
5
    count = 0;
3090
21
    for (current = abfd->sections; current != NULL; current = current->next)
3091
16
      ++count;
3092
3093
    /* We allocate an extra cell to simplify the final loop.  */
3094
5
    amt = sizeof (struct asection *) * (count + 1);
3095
5
    section_list = (asection **) bfd_malloc (amt);
3096
5
    if (section_list == NULL)
3097
0
      return false;
3098
3099
5
    i = 0;
3100
21
    for (current = abfd->sections; current != NULL; current = current->next)
3101
16
      {
3102
16
  section_list[i] = current;
3103
16
  ++i;
3104
16
      }
3105
5
    section_list[i] = NULL;
3106
3107
5
    qsort (section_list, count, sizeof (asection *), sort_by_secaddr);
3108
3109
    /* Rethread the linked list into sorted order; at the same time,
3110
       assign target_index values.  */
3111
5
    target_index = 1;
3112
5
    abfd->sections = NULL;
3113
5
    abfd->section_last = NULL;
3114
21
    for (i = 0; i < count; i++)
3115
16
      {
3116
16
  current = section_list[i];
3117
16
  bfd_section_list_append (abfd, current);
3118
3119
  /* Later, if the section has zero size, we'll be throwing it
3120
     away, so we don't want to number it now.  Note that having
3121
     a zero size and having real contents are different
3122
     concepts: .bss has no contents, but (usually) non-zero
3123
     size.  */
3124
16
  if (current->size == 0)
3125
12
    {
3126
      /* Discard.  However, it still might have (valid) symbols
3127
         in it, so arbitrarily set it to section 1 (indexing is
3128
         1-based here; usually .text).  __end__ and other
3129
         contents of .endsection really have this happen.
3130
         FIXME: This seems somewhat dubious.  */
3131
12
      current->target_index = 1;
3132
12
    }
3133
4
  else
3134
4
    current->target_index = target_index++;
3135
16
      }
3136
3137
5
    free (section_list);
3138
5
  }
3139
#else /* ! COFF_IMAGE_WITH_PE */
3140
  {
3141
    /* Set the target_index field.  */
3142
    target_index = 1;
3143
    for (current = abfd->sections; current != NULL; current = current->next)
3144
      current->target_index = target_index++;
3145
  }
3146
#endif /* ! COFF_IMAGE_WITH_PE */
3147
3148
5
  if (target_index >= bfd_coff_max_nscns (abfd))
3149
0
    {
3150
0
      bfd_set_error (bfd_error_file_too_big);
3151
0
      _bfd_error_handler
3152
  /* xgettext:c-format */
3153
0
  (_("%pB: too many sections (%d)"), abfd, target_index);
3154
0
      return false;
3155
0
    }
3156
3157
5
  align_adjust = false;
3158
5
  for (current = abfd->sections;
3159
21
       current != NULL;
3160
16
       current = current->next)
3161
16
    {
3162
16
#ifdef COFF_IMAGE_WITH_PE
3163
      /* With PE we have to pad each section to be a multiple of its
3164
   page size too, and remember both sizes.  */
3165
16
      if (coff_section_data (abfd, current) == NULL)
3166
4
  {
3167
4
    size_t amt = sizeof (struct coff_section_tdata);
3168
3169
4
    current->used_by_bfd = bfd_zalloc (abfd, amt);
3170
4
    if (current->used_by_bfd == NULL)
3171
0
      return false;
3172
4
  }
3173
16
      if (pei_section_data (abfd, current) == NULL)
3174
4
  {
3175
4
    size_t amt = sizeof (struct pei_section_tdata);
3176
3177
4
    coff_section_data (abfd, current)->tdata = bfd_zalloc (abfd, amt);
3178
4
    if (coff_section_data (abfd, current)->tdata == NULL)
3179
0
      return false;
3180
4
  }
3181
16
      if (pei_section_data (abfd, current)->virt_size == 0)
3182
16
  pei_section_data (abfd, current)->virt_size = current->size;
3183
16
#endif
3184
3185
      /* Only deal with sections which have contents.  */
3186
16
      if (!(current->flags & SEC_HAS_CONTENTS))
3187
12
  continue;
3188
3189
4
      current->rawsize = current->size;
3190
3191
4
#ifdef COFF_IMAGE_WITH_PE
3192
      /* Make sure we skip empty sections in a PE image.  */
3193
4
      if (current->size == 0)
3194
0
  continue;
3195
4
#endif
3196
3197
      /* Align the sections in the file to the same boundary on
3198
   which they are aligned in virtual memory.  */
3199
4
#ifdef ALIGN_SECTIONS_IN_FILE
3200
4
      if ((abfd->flags & EXEC_P) != 0)
3201
4
  {
3202
    /* Make sure this section is aligned on the right boundary - by
3203
       padding the previous section up if necessary.  */
3204
4
    old_sofar = sofar;
3205
3206
4
#ifdef COFF_IMAGE_WITH_PE
3207
4
    sofar = BFD_ALIGN (sofar, page_size);
3208
#else
3209
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3210
#endif
3211
3212
#ifdef RS6000COFF_C
3213
    /* Make sure the file offset and the vma of .text/.data are at the
3214
       same page offset, so that the file can be mmap'ed without being
3215
       relocated.  Failing that, AIX is able to load and execute the
3216
       program, but it will be silently relocated (possible as
3217
       executables are PIE).  But the relocation is slightly costly and
3218
       complexify the use of addr2line or gdb.  So better to avoid it,
3219
       like does the native linker.  Usually gnu ld makes sure that
3220
       the vma of .text is the file offset so this issue shouldn't
3221
       appear unless you are stripping such an executable.
3222
3223
       AIX loader checks the text section alignment of (vma - filepos),
3224
       and the native linker doesn't try to align the text sections.
3225
       For example:
3226
3227
       0 .text       000054cc  10000128  10000128  00000128  2**5
3228
           CONTENTS, ALLOC, LOAD, CODE
3229
3230
       Don't perform the above tweak if the previous one is .tdata,
3231
       as it will increase the memory allocated for every threads
3232
       created and not just improve performances with gdb.
3233
    */
3234
3235
    if ((current->flags & SEC_LOAD) != 0
3236
        && (!strcmp (current->name, _TEXT)
3237
      || !strcmp (current->name, _DATA))
3238
        && (previous == NULL || strcmp(previous->name, _TDATA)))
3239
      {
3240
        bfd_vma align = 4096;
3241
        bfd_vma sofar_off = sofar % align;
3242
        bfd_vma vma_off = current->vma % align;
3243
3244
        if (vma_off > sofar_off)
3245
    sofar += vma_off - sofar_off;
3246
        else if (vma_off < sofar_off)
3247
    sofar += align + vma_off - sofar_off;
3248
      }
3249
#endif
3250
4
    if (previous != NULL
3251
4
        && (previous->flags & SEC_LOAD) != 0)
3252
0
      previous->size += sofar - old_sofar;
3253
4
  }
3254
3255
4
#endif
3256
3257
      /* In demand paged files the low order bits of the file offset
3258
   must match the low order bits of the virtual address.  */
3259
#ifdef COFF_PAGE_SIZE
3260
      if ((abfd->flags & D_PAGED) != 0
3261
    && (current->flags & SEC_ALLOC) != 0)
3262
  sofar += (current->vma - (bfd_vma) sofar) % page_size;
3263
#endif
3264
4
      current->filepos = sofar;
3265
3266
4
#ifdef COFF_IMAGE_WITH_PE
3267
      /* Set the padded size.  */
3268
4
      current->size = (current->size + page_size - 1) & -page_size;
3269
4
#endif
3270
3271
4
      sofar += current->size;
3272
3273
4
#ifdef ALIGN_SECTIONS_IN_FILE
3274
      /* Make sure that this section is of the right size too.  */
3275
4
      if ((abfd->flags & EXEC_P) == 0)
3276
0
  {
3277
0
    bfd_size_type old_size;
3278
3279
0
    old_size = current->size;
3280
0
    current->size = BFD_ALIGN (current->size,
3281
0
             (bfd_vma) 1 << current->alignment_power);
3282
0
    align_adjust = current->size != old_size;
3283
0
    sofar += current->size - old_size;
3284
0
  }
3285
4
      else
3286
4
  {
3287
4
    old_sofar = sofar;
3288
4
#ifdef COFF_IMAGE_WITH_PE
3289
4
    sofar = BFD_ALIGN (sofar, page_size);
3290
#else
3291
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3292
#endif
3293
4
    align_adjust = sofar != old_sofar;
3294
4
    current->size += sofar - old_sofar;
3295
4
  }
3296
4
#endif
3297
3298
4
#ifdef COFF_IMAGE_WITH_PE
3299
      /* For PE we need to make sure we pad out to the aligned
3300
   size, in case the caller only writes out data to the
3301
   unaligned size.  */
3302
4
      if (pei_section_data (abfd, current)->virt_size < current->size)
3303
2
  align_adjust = true;
3304
4
#endif
3305
3306
4
#ifdef _LIB
3307
      /* Force .lib sections to start at zero.  The vma is then
3308
   incremented in coff_set_section_contents.  This is right for
3309
   SVR3.2.  */
3310
4
      if (strcmp (current->name, _LIB) == 0)
3311
0
  bfd_set_section_vma (current, 0);
3312
4
#endif
3313
3314
4
#ifdef ALIGN_SECTIONS_IN_FILE
3315
4
      previous = current;
3316
4
#endif
3317
4
    }
3318
3319
  /* It is now safe to write to the output file.  If we needed an
3320
     alignment adjustment for the last section, then make sure that
3321
     there is a byte at offset sofar.  If there are no symbols and no
3322
     relocs, then nothing follows the last section.  If we don't force
3323
     the last byte out, then the file may appear to be truncated.  */
3324
5
  if (align_adjust)
3325
2
    {
3326
2
      bfd_byte b;
3327
3328
2
      b = 0;
3329
2
      if (bfd_seek (abfd, sofar - 1, SEEK_SET) != 0
3330
2
    || bfd_write (&b, 1, abfd) != 1)
3331
0
  return false;
3332
2
    }
3333
3334
  /* Make sure the relocations are aligned.  We don't need to make
3335
     sure that this byte exists, because it will only matter if there
3336
     really are relocs.  */
3337
5
  sofar = BFD_ALIGN (sofar,
3338
5
         (bfd_vma) 1 << COFF_DEFAULT_SECTION_ALIGNMENT_POWER);
3339
3340
5
  obj_relocbase (abfd) = sofar;
3341
5
  abfd->output_has_begun = true;
3342
3343
5
  return true;
3344
5
}
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
Unexecuted instantiation: coff-sh.c:coff_compute_section_file_positions
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
Unexecuted instantiation: coff-z8k.c:coff_compute_section_file_positions
Unexecuted instantiation: pe-arm-wince.c:coff_compute_section_file_positions
Unexecuted instantiation: pe-arm.c:coff_compute_section_file_positions
Unexecuted instantiation: pe-i386.c:coff_compute_section_file_positions
Unexecuted instantiation: pe-mcore.c:coff_compute_section_file_positions
Unexecuted instantiation: pe-sh.c:coff_compute_section_file_positions
pei-arm-wince.c:coff_compute_section_file_positions
Line
Count
Source
2970
1
{
2971
1
  asection *current;
2972
1
  file_ptr sofar = bfd_coff_filhsz (abfd);
2973
1
  bool align_adjust;
2974
1
  unsigned int target_index;
2975
1
#ifdef ALIGN_SECTIONS_IN_FILE
2976
1
  asection *previous = NULL;
2977
1
  file_ptr old_sofar;
2978
1
#endif
2979
2980
1
#ifdef COFF_IMAGE_WITH_PE
2981
1
  unsigned int page_size;
2982
2983
1
  if (coff_data (abfd)->link_info
2984
1
      || (pe_data (abfd) && pe_data (abfd)->pe_opthdr.FileAlignment))
2985
0
    {
2986
0
      page_size = pe_data (abfd)->pe_opthdr.FileAlignment;
2987
2988
      /* If no file alignment has been set, default to one.
2989
   This repairs 'ld -r' for arm-wince-pe target.  */
2990
0
      if (page_size == 0)
2991
0
  page_size = 1;
2992
0
    }
2993
1
  else
2994
1
    page_size = PE_DEF_FILE_ALIGNMENT;
2995
#else
2996
#ifdef COFF_PAGE_SIZE
2997
  unsigned int page_size = COFF_PAGE_SIZE;
2998
#endif
2999
#endif
3000
3001
#ifdef RS6000COFF_C
3002
  /* On XCOFF, if we have symbols, set up the .debug section.  */
3003
  if (bfd_get_symcount (abfd) > 0)
3004
    {
3005
      bfd_size_type sz;
3006
      bfd_size_type i, symcount;
3007
      asymbol **symp;
3008
3009
      sz = 0;
3010
      symcount = bfd_get_symcount (abfd);
3011
      for (symp = abfd->outsymbols, i = 0; i < symcount; symp++, i++)
3012
  {
3013
    coff_symbol_type *cf;
3014
3015
    cf = coff_symbol_from (*symp);
3016
    if (cf != NULL
3017
        && cf->native != NULL
3018
        && cf->native->is_sym
3019
        && SYMNAME_IN_DEBUG (&cf->native->u.syment))
3020
      {
3021
        size_t len;
3022
3023
        len = strlen (bfd_asymbol_name (*symp));
3024
        if (len > SYMNMLEN || bfd_coff_force_symnames_in_strings (abfd))
3025
    sz += len + 1 + bfd_coff_debug_string_prefix_length (abfd);
3026
      }
3027
  }
3028
      if (sz > 0)
3029
  {
3030
    asection *dsec;
3031
3032
    dsec = bfd_make_section_old_way (abfd, DOT_DEBUG);
3033
    if (dsec == NULL)
3034
      abort ();
3035
    dsec->size = sz;
3036
    dsec->flags |= SEC_HAS_CONTENTS;
3037
  }
3038
    }
3039
#endif
3040
3041
1
  if (bfd_get_start_address (abfd))
3042
    /*  A start address may have been added to the original file. In this
3043
  case it will need an optional header to record it.  */
3044
0
    abfd->flags |= EXEC_P;
3045
3046
1
  if (abfd->flags & EXEC_P)
3047
1
    sofar += bfd_coff_aoutsz (abfd);
3048
#ifdef RS6000COFF_C
3049
  else if (xcoff_data (abfd)->full_aouthdr)
3050
    sofar += bfd_coff_aoutsz (abfd);
3051
  else
3052
    sofar += SMALL_AOUTSZ;
3053
#endif
3054
3055
1
  sofar += abfd->section_count * bfd_coff_scnhsz (abfd);
3056
3057
#ifdef RS6000COFF_C
3058
  /* XCOFF handles overflows in the reloc and line number count fields
3059
     by allocating a new section header to hold the correct counts.  */
3060
  for (current = abfd->sections; current != NULL; current = current->next)
3061
    if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3062
      sofar += bfd_coff_scnhsz (abfd);
3063
#endif
3064
3065
1
  if (coff_data (abfd)->section_by_target_index)
3066
0
    htab_empty (coff_data (abfd)->section_by_target_index);
3067
3068
1
#ifdef COFF_IMAGE_WITH_PE
3069
1
  {
3070
    /* PE requires the sections to be in memory order when listed in
3071
       the section headers.  It also does not like empty loadable
3072
       sections.  The sections apparently do not have to be in the
3073
       right order in the image file itself, but we do need to get the
3074
       target_index values right.  */
3075
3076
1
    unsigned int count;
3077
1
    asection **section_list;
3078
1
    unsigned int i;
3079
1
    bfd_size_type amt;
3080
3081
1
#ifdef COFF_PAGE_SIZE
3082
    /* Clear D_PAGED if section / file alignment aren't suitable for
3083
       paging at COFF_PAGE_SIZE granularity.  */
3084
1
   if (pe_data (abfd)->pe_opthdr.SectionAlignment < COFF_PAGE_SIZE
3085
1
       || page_size < COFF_PAGE_SIZE)
3086
1
     abfd->flags &= ~D_PAGED;
3087
1
#endif
3088
3089
1
    count = 0;
3090
1
    for (current = abfd->sections; current != NULL; current = current->next)
3091
0
      ++count;
3092
3093
    /* We allocate an extra cell to simplify the final loop.  */
3094
1
    amt = sizeof (struct asection *) * (count + 1);
3095
1
    section_list = (asection **) bfd_malloc (amt);
3096
1
    if (section_list == NULL)
3097
0
      return false;
3098
3099
1
    i = 0;
3100
1
    for (current = abfd->sections; current != NULL; current = current->next)
3101
0
      {
3102
0
  section_list[i] = current;
3103
0
  ++i;
3104
0
      }
3105
1
    section_list[i] = NULL;
3106
3107
1
    qsort (section_list, count, sizeof (asection *), sort_by_secaddr);
3108
3109
    /* Rethread the linked list into sorted order; at the same time,
3110
       assign target_index values.  */
3111
1
    target_index = 1;
3112
1
    abfd->sections = NULL;
3113
1
    abfd->section_last = NULL;
3114
1
    for (i = 0; i < count; i++)
3115
0
      {
3116
0
  current = section_list[i];
3117
0
  bfd_section_list_append (abfd, current);
3118
3119
  /* Later, if the section has zero size, we'll be throwing it
3120
     away, so we don't want to number it now.  Note that having
3121
     a zero size and having real contents are different
3122
     concepts: .bss has no contents, but (usually) non-zero
3123
     size.  */
3124
0
  if (current->size == 0)
3125
0
    {
3126
      /* Discard.  However, it still might have (valid) symbols
3127
         in it, so arbitrarily set it to section 1 (indexing is
3128
         1-based here; usually .text).  __end__ and other
3129
         contents of .endsection really have this happen.
3130
         FIXME: This seems somewhat dubious.  */
3131
0
      current->target_index = 1;
3132
0
    }
3133
0
  else
3134
0
    current->target_index = target_index++;
3135
0
      }
3136
3137
1
    free (section_list);
3138
1
  }
3139
#else /* ! COFF_IMAGE_WITH_PE */
3140
  {
3141
    /* Set the target_index field.  */
3142
    target_index = 1;
3143
    for (current = abfd->sections; current != NULL; current = current->next)
3144
      current->target_index = target_index++;
3145
  }
3146
#endif /* ! COFF_IMAGE_WITH_PE */
3147
3148
1
  if (target_index >= bfd_coff_max_nscns (abfd))
3149
0
    {
3150
0
      bfd_set_error (bfd_error_file_too_big);
3151
0
      _bfd_error_handler
3152
  /* xgettext:c-format */
3153
0
  (_("%pB: too many sections (%d)"), abfd, target_index);
3154
0
      return false;
3155
0
    }
3156
3157
1
  align_adjust = false;
3158
1
  for (current = abfd->sections;
3159
1
       current != NULL;
3160
1
       current = current->next)
3161
0
    {
3162
0
#ifdef COFF_IMAGE_WITH_PE
3163
      /* With PE we have to pad each section to be a multiple of its
3164
   page size too, and remember both sizes.  */
3165
0
      if (coff_section_data (abfd, current) == NULL)
3166
0
  {
3167
0
    size_t amt = sizeof (struct coff_section_tdata);
3168
3169
0
    current->used_by_bfd = bfd_zalloc (abfd, amt);
3170
0
    if (current->used_by_bfd == NULL)
3171
0
      return false;
3172
0
  }
3173
0
      if (pei_section_data (abfd, current) == NULL)
3174
0
  {
3175
0
    size_t amt = sizeof (struct pei_section_tdata);
3176
3177
0
    coff_section_data (abfd, current)->tdata = bfd_zalloc (abfd, amt);
3178
0
    if (coff_section_data (abfd, current)->tdata == NULL)
3179
0
      return false;
3180
0
  }
3181
0
      if (pei_section_data (abfd, current)->virt_size == 0)
3182
0
  pei_section_data (abfd, current)->virt_size = current->size;
3183
0
#endif
3184
3185
      /* Only deal with sections which have contents.  */
3186
0
      if (!(current->flags & SEC_HAS_CONTENTS))
3187
0
  continue;
3188
3189
0
      current->rawsize = current->size;
3190
3191
0
#ifdef COFF_IMAGE_WITH_PE
3192
      /* Make sure we skip empty sections in a PE image.  */
3193
0
      if (current->size == 0)
3194
0
  continue;
3195
0
#endif
3196
3197
      /* Align the sections in the file to the same boundary on
3198
   which they are aligned in virtual memory.  */
3199
0
#ifdef ALIGN_SECTIONS_IN_FILE
3200
0
      if ((abfd->flags & EXEC_P) != 0)
3201
0
  {
3202
    /* Make sure this section is aligned on the right boundary - by
3203
       padding the previous section up if necessary.  */
3204
0
    old_sofar = sofar;
3205
3206
0
#ifdef COFF_IMAGE_WITH_PE
3207
0
    sofar = BFD_ALIGN (sofar, page_size);
3208
#else
3209
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3210
#endif
3211
3212
#ifdef RS6000COFF_C
3213
    /* Make sure the file offset and the vma of .text/.data are at the
3214
       same page offset, so that the file can be mmap'ed without being
3215
       relocated.  Failing that, AIX is able to load and execute the
3216
       program, but it will be silently relocated (possible as
3217
       executables are PIE).  But the relocation is slightly costly and
3218
       complexify the use of addr2line or gdb.  So better to avoid it,
3219
       like does the native linker.  Usually gnu ld makes sure that
3220
       the vma of .text is the file offset so this issue shouldn't
3221
       appear unless you are stripping such an executable.
3222
3223
       AIX loader checks the text section alignment of (vma - filepos),
3224
       and the native linker doesn't try to align the text sections.
3225
       For example:
3226
3227
       0 .text       000054cc  10000128  10000128  00000128  2**5
3228
           CONTENTS, ALLOC, LOAD, CODE
3229
3230
       Don't perform the above tweak if the previous one is .tdata,
3231
       as it will increase the memory allocated for every threads
3232
       created and not just improve performances with gdb.
3233
    */
3234
3235
    if ((current->flags & SEC_LOAD) != 0
3236
        && (!strcmp (current->name, _TEXT)
3237
      || !strcmp (current->name, _DATA))
3238
        && (previous == NULL || strcmp(previous->name, _TDATA)))
3239
      {
3240
        bfd_vma align = 4096;
3241
        bfd_vma sofar_off = sofar % align;
3242
        bfd_vma vma_off = current->vma % align;
3243
3244
        if (vma_off > sofar_off)
3245
    sofar += vma_off - sofar_off;
3246
        else if (vma_off < sofar_off)
3247
    sofar += align + vma_off - sofar_off;
3248
      }
3249
#endif
3250
0
    if (previous != NULL
3251
0
        && (previous->flags & SEC_LOAD) != 0)
3252
0
      previous->size += sofar - old_sofar;
3253
0
  }
3254
3255
0
#endif
3256
3257
      /* In demand paged files the low order bits of the file offset
3258
   must match the low order bits of the virtual address.  */
3259
0
#ifdef COFF_PAGE_SIZE
3260
0
      if ((abfd->flags & D_PAGED) != 0
3261
0
    && (current->flags & SEC_ALLOC) != 0)
3262
0
  sofar += (current->vma - (bfd_vma) sofar) % page_size;
3263
0
#endif
3264
0
      current->filepos = sofar;
3265
3266
0
#ifdef COFF_IMAGE_WITH_PE
3267
      /* Set the padded size.  */
3268
0
      current->size = (current->size + page_size - 1) & -page_size;
3269
0
#endif
3270
3271
0
      sofar += current->size;
3272
3273
0
#ifdef ALIGN_SECTIONS_IN_FILE
3274
      /* Make sure that this section is of the right size too.  */
3275
0
      if ((abfd->flags & EXEC_P) == 0)
3276
0
  {
3277
0
    bfd_size_type old_size;
3278
3279
0
    old_size = current->size;
3280
0
    current->size = BFD_ALIGN (current->size,
3281
0
             (bfd_vma) 1 << current->alignment_power);
3282
0
    align_adjust = current->size != old_size;
3283
0
    sofar += current->size - old_size;
3284
0
  }
3285
0
      else
3286
0
  {
3287
0
    old_sofar = sofar;
3288
0
#ifdef COFF_IMAGE_WITH_PE
3289
0
    sofar = BFD_ALIGN (sofar, page_size);
3290
#else
3291
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3292
#endif
3293
0
    align_adjust = sofar != old_sofar;
3294
0
    current->size += sofar - old_sofar;
3295
0
  }
3296
0
#endif
3297
3298
0
#ifdef COFF_IMAGE_WITH_PE
3299
      /* For PE we need to make sure we pad out to the aligned
3300
   size, in case the caller only writes out data to the
3301
   unaligned size.  */
3302
0
      if (pei_section_data (abfd, current)->virt_size < current->size)
3303
0
  align_adjust = true;
3304
0
#endif
3305
3306
0
#ifdef _LIB
3307
      /* Force .lib sections to start at zero.  The vma is then
3308
   incremented in coff_set_section_contents.  This is right for
3309
   SVR3.2.  */
3310
0
      if (strcmp (current->name, _LIB) == 0)
3311
0
  bfd_set_section_vma (current, 0);
3312
0
#endif
3313
3314
0
#ifdef ALIGN_SECTIONS_IN_FILE
3315
0
      previous = current;
3316
0
#endif
3317
0
    }
3318
3319
  /* It is now safe to write to the output file.  If we needed an
3320
     alignment adjustment for the last section, then make sure that
3321
     there is a byte at offset sofar.  If there are no symbols and no
3322
     relocs, then nothing follows the last section.  If we don't force
3323
     the last byte out, then the file may appear to be truncated.  */
3324
1
  if (align_adjust)
3325
0
    {
3326
0
      bfd_byte b;
3327
3328
0
      b = 0;
3329
0
      if (bfd_seek (abfd, sofar - 1, SEEK_SET) != 0
3330
0
    || bfd_write (&b, 1, abfd) != 1)
3331
0
  return false;
3332
0
    }
3333
3334
  /* Make sure the relocations are aligned.  We don't need to make
3335
     sure that this byte exists, because it will only matter if there
3336
     really are relocs.  */
3337
1
  sofar = BFD_ALIGN (sofar,
3338
1
         (bfd_vma) 1 << COFF_DEFAULT_SECTION_ALIGNMENT_POWER);
3339
3340
1
  obj_relocbase (abfd) = sofar;
3341
1
  abfd->output_has_begun = true;
3342
3343
1
  return true;
3344
1
}
Unexecuted instantiation: pei-arm.c:coff_compute_section_file_positions
Unexecuted instantiation: pei-mcore.c:coff_compute_section_file_positions
Unexecuted instantiation: pei-sh.c:coff_compute_section_file_positions
3345
3346
#ifdef COFF_IMAGE_WITH_PE
3347
3348
static bool
3349
coff_read_word (bfd *abfd, unsigned int *value, unsigned int *pelength)
3350
14
{
3351
14
  unsigned char b[2];
3352
14
  int status;
3353
3354
14
  status = bfd_read (b, 2, abfd);
3355
14
  if (status < 1)
3356
0
    {
3357
0
      *value = 0;
3358
0
      return false;
3359
0
    }
3360
3361
14
  if (status == 1)
3362
0
    *value = (unsigned int) b[0];
3363
14
  else
3364
14
    *value = (unsigned int) (b[0] + (b[1] << 8));
3365
3366
14
  *pelength += status;
3367
3368
14
  return true;
3369
14
}
pei-i386.c:coff_read_word
Line
Count
Source
3350
4
{
3351
4
  unsigned char b[2];
3352
4
  int status;
3353
3354
4
  status = bfd_read (b, 2, abfd);
3355
4
  if (status < 1)
3356
0
    {
3357
0
      *value = 0;
3358
0
      return false;
3359
0
    }
3360
3361
4
  if (status == 1)
3362
0
    *value = (unsigned int) b[0];
3363
4
  else
3364
4
    *value = (unsigned int) (b[0] + (b[1] << 8));
3365
3366
4
  *pelength += status;
3367
3368
4
  return true;
3369
4
}
pei-x86_64.c:coff_read_word
Line
Count
Source
3350
3
{
3351
3
  unsigned char b[2];
3352
3
  int status;
3353
3354
3
  status = bfd_read (b, 2, abfd);
3355
3
  if (status < 1)
3356
0
    {
3357
0
      *value = 0;
3358
0
      return false;
3359
0
    }
3360
3361
3
  if (status == 1)
3362
0
    *value = (unsigned int) b[0];
3363
3
  else
3364
3
    *value = (unsigned int) (b[0] + (b[1] << 8));
3365
3366
3
  *pelength += status;
3367
3368
3
  return true;
3369
3
}
Unexecuted instantiation: pei-aarch64.c:coff_read_word
pei-ia64.c:coff_read_word
Line
Count
Source
3350
1
{
3351
1
  unsigned char b[2];
3352
1
  int status;
3353
3354
1
  status = bfd_read (b, 2, abfd);
3355
1
  if (status < 1)
3356
0
    {
3357
0
      *value = 0;
3358
0
      return false;
3359
0
    }
3360
3361
1
  if (status == 1)
3362
0
    *value = (unsigned int) b[0];
3363
1
  else
3364
1
    *value = (unsigned int) (b[0] + (b[1] << 8));
3365
3366
1
  *pelength += status;
3367
3368
1
  return true;
3369
1
}
Unexecuted instantiation: pei-loongarch64.c:coff_read_word
pei-riscv64.c:coff_read_word
Line
Count
Source
3350
5
{
3351
5
  unsigned char b[2];
3352
5
  int status;
3353
3354
5
  status = bfd_read (b, 2, abfd);
3355
5
  if (status < 1)
3356
0
    {
3357
0
      *value = 0;
3358
0
      return false;
3359
0
    }
3360
3361
5
  if (status == 1)
3362
0
    *value = (unsigned int) b[0];
3363
5
  else
3364
5
    *value = (unsigned int) (b[0] + (b[1] << 8));
3365
3366
5
  *pelength += status;
3367
3368
5
  return true;
3369
5
}
pei-arm-wince.c:coff_read_word
Line
Count
Source
3350
1
{
3351
1
  unsigned char b[2];
3352
1
  int status;
3353
3354
1
  status = bfd_read (b, 2, abfd);
3355
1
  if (status < 1)
3356
0
    {
3357
0
      *value = 0;
3358
0
      return false;
3359
0
    }
3360
3361
1
  if (status == 1)
3362
0
    *value = (unsigned int) b[0];
3363
1
  else
3364
1
    *value = (unsigned int) (b[0] + (b[1] << 8));
3365
3366
1
  *pelength += status;
3367
3368
1
  return true;
3369
1
}
Unexecuted instantiation: pei-arm.c:coff_read_word
Unexecuted instantiation: pei-mcore.c:coff_read_word
Unexecuted instantiation: pei-sh.c:coff_read_word
3370
3371
/* Read a two byte number from buffer B returning the result in VALUE.
3372
   No more than BUF_SIZE bytes will be read.
3373
   Returns true upobn success, false otherwise.
3374
   If successful, increases the value stored in PELENGTH by the number
3375
   of bytes read.  */
3376
3377
static bool
3378
coff_read_word_from_buffer (unsigned char *  b,
3379
          int              buf_size,
3380
                            unsigned int *   value,
3381
          unsigned int *   pelength)
3382
342k
{
3383
342k
  if (buf_size < 1)
3384
0
    {
3385
0
      *value = 0;
3386
0
      return false;
3387
0
    }
3388
3389
342k
  if (buf_size == 1)
3390
0
    {
3391
0
      *value = (unsigned int)b[0];
3392
0
      *pelength += 1;
3393
0
    }
3394
342k
  else
3395
342k
    {
3396
342k
      *value = (unsigned int)(b[0] + (b[1] << 8));
3397
342k
      *pelength += 2;
3398
342k
    }
3399
3400
342k
  return true;
3401
342k
}
pei-i386.c:coff_read_word_from_buffer
Line
Count
Source
3382
17.7k
{
3383
17.7k
  if (buf_size < 1)
3384
0
    {
3385
0
      *value = 0;
3386
0
      return false;
3387
0
    }
3388
3389
17.7k
  if (buf_size == 1)
3390
0
    {
3391
0
      *value = (unsigned int)b[0];
3392
0
      *pelength += 1;
3393
0
    }
3394
17.7k
  else
3395
17.7k
    {
3396
17.7k
      *value = (unsigned int)(b[0] + (b[1] << 8));
3397
17.7k
      *pelength += 2;
3398
17.7k
    }
3399
3400
17.7k
  return true;
3401
17.7k
}
pei-x86_64.c:coff_read_word_from_buffer
Line
Count
Source
3382
202k
{
3383
202k
  if (buf_size < 1)
3384
0
    {
3385
0
      *value = 0;
3386
0
      return false;
3387
0
    }
3388
3389
202k
  if (buf_size == 1)
3390
0
    {
3391
0
      *value = (unsigned int)b[0];
3392
0
      *pelength += 1;
3393
0
    }
3394
202k
  else
3395
202k
    {
3396
202k
      *value = (unsigned int)(b[0] + (b[1] << 8));
3397
202k
      *pelength += 2;
3398
202k
    }
3399
3400
202k
  return true;
3401
202k
}
Unexecuted instantiation: pei-aarch64.c:coff_read_word_from_buffer
pei-ia64.c:coff_read_word_from_buffer
Line
Count
Source
3382
3.07k
{
3383
3.07k
  if (buf_size < 1)
3384
0
    {
3385
0
      *value = 0;
3386
0
      return false;
3387
0
    }
3388
3389
3.07k
  if (buf_size == 1)
3390
0
    {
3391
0
      *value = (unsigned int)b[0];
3392
0
      *pelength += 1;
3393
0
    }
3394
3.07k
  else
3395
3.07k
    {
3396
3.07k
      *value = (unsigned int)(b[0] + (b[1] << 8));
3397
3.07k
      *pelength += 2;
3398
3.07k
    }
3399
3400
3.07k
  return true;
3401
3.07k
}
Unexecuted instantiation: pei-loongarch64.c:coff_read_word_from_buffer
pei-riscv64.c:coff_read_word_from_buffer
Line
Count
Source
3382
119k
{
3383
119k
  if (buf_size < 1)
3384
0
    {
3385
0
      *value = 0;
3386
0
      return false;
3387
0
    }
3388
3389
119k
  if (buf_size == 1)
3390
0
    {
3391
0
      *value = (unsigned int)b[0];
3392
0
      *pelength += 1;
3393
0
    }
3394
119k
  else
3395
119k
    {
3396
119k
      *value = (unsigned int)(b[0] + (b[1] << 8));
3397
119k
      *pelength += 2;
3398
119k
    }
3399
3400
119k
  return true;
3401
119k
}
pei-arm-wince.c:coff_read_word_from_buffer
Line
Count
Source
3382
188
{
3383
188
  if (buf_size < 1)
3384
0
    {
3385
0
      *value = 0;
3386
0
      return false;
3387
0
    }
3388
3389
188
  if (buf_size == 1)
3390
0
    {
3391
0
      *value = (unsigned int)b[0];
3392
0
      *pelength += 1;
3393
0
    }
3394
188
  else
3395
188
    {
3396
188
      *value = (unsigned int)(b[0] + (b[1] << 8));
3397
188
      *pelength += 2;
3398
188
    }
3399
3400
188
  return true;
3401
188
}
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
3402
3403
42
#define COFF_CHECKSUM_BUFFER_SIZE 0x800000
3404
3405
static unsigned int
3406
coff_compute_checksum (bfd *abfd, unsigned int *pelength)
3407
14
{
3408
14
  file_ptr filepos;
3409
14
  unsigned int value;
3410
14
  unsigned int total;
3411
14
  unsigned char *buf;
3412
14
  int buf_size;
3413
3414
14
  total = 0;
3415
14
  *pelength = 0;
3416
14
  filepos = (file_ptr) 0;
3417
14
  buf = (unsigned char *) bfd_malloc (COFF_CHECKSUM_BUFFER_SIZE);
3418
14
  if (buf == NULL)
3419
0
    return 0;
3420
14
  buf_size = 0;
3421
3422
14
  do
3423
28
    {
3424
28
      unsigned char *cur_buf;
3425
28
      int cur_buf_size;
3426
3427
28
      if (bfd_seek (abfd, filepos, SEEK_SET) != 0)
3428
0
  return 0;
3429
3430
28
      buf_size = bfd_read (buf, COFF_CHECKSUM_BUFFER_SIZE, abfd);
3431
28
      cur_buf_size = buf_size;
3432
28
      cur_buf = buf;
3433
3434
343k
      while (cur_buf_size > 0)
3435
342k
        {
3436
342k
          coff_read_word_from_buffer (cur_buf, cur_buf_size, &value, pelength);
3437
342k
          cur_buf += 2;
3438
342k
          cur_buf_size -= 2;
3439
342k
          total += value;
3440
342k
          total = 0xffff & (total + (total >> 0x10));
3441
342k
        }
3442
3443
28
      filepos += buf_size;
3444
28
    }
3445
28
  while (buf_size > 0);
3446
3447
14
  free (buf);
3448
3449
14
  return (0xffff & (total + (total >> 0x10)));
3450
14
}
pei-i386.c:coff_compute_checksum
Line
Count
Source
3407
4
{
3408
4
  file_ptr filepos;
3409
4
  unsigned int value;
3410
4
  unsigned int total;
3411
4
  unsigned char *buf;
3412
4
  int buf_size;
3413
3414
4
  total = 0;
3415
4
  *pelength = 0;
3416
4
  filepos = (file_ptr) 0;
3417
4
  buf = (unsigned char *) bfd_malloc (COFF_CHECKSUM_BUFFER_SIZE);
3418
4
  if (buf == NULL)
3419
0
    return 0;
3420
4
  buf_size = 0;
3421
3422
4
  do
3423
8
    {
3424
8
      unsigned char *cur_buf;
3425
8
      int cur_buf_size;
3426
3427
8
      if (bfd_seek (abfd, filepos, SEEK_SET) != 0)
3428
0
  return 0;
3429
3430
8
      buf_size = bfd_read (buf, COFF_CHECKSUM_BUFFER_SIZE, abfd);
3431
8
      cur_buf_size = buf_size;
3432
8
      cur_buf = buf;
3433
3434
17.7k
      while (cur_buf_size > 0)
3435
17.7k
        {
3436
17.7k
          coff_read_word_from_buffer (cur_buf, cur_buf_size, &value, pelength);
3437
17.7k
          cur_buf += 2;
3438
17.7k
          cur_buf_size -= 2;
3439
17.7k
          total += value;
3440
17.7k
          total = 0xffff & (total + (total >> 0x10));
3441
17.7k
        }
3442
3443
8
      filepos += buf_size;
3444
8
    }
3445
8
  while (buf_size > 0);
3446
3447
4
  free (buf);
3448
3449
4
  return (0xffff & (total + (total >> 0x10)));
3450
4
}
pei-x86_64.c:coff_compute_checksum
Line
Count
Source
3407
3
{
3408
3
  file_ptr filepos;
3409
3
  unsigned int value;
3410
3
  unsigned int total;
3411
3
  unsigned char *buf;
3412
3
  int buf_size;
3413
3414
3
  total = 0;
3415
3
  *pelength = 0;
3416
3
  filepos = (file_ptr) 0;
3417
3
  buf = (unsigned char *) bfd_malloc (COFF_CHECKSUM_BUFFER_SIZE);
3418
3
  if (buf == NULL)
3419
0
    return 0;
3420
3
  buf_size = 0;
3421
3422
3
  do
3423
6
    {
3424
6
      unsigned char *cur_buf;
3425
6
      int cur_buf_size;
3426
3427
6
      if (bfd_seek (abfd, filepos, SEEK_SET) != 0)
3428
0
  return 0;
3429
3430
6
      buf_size = bfd_read (buf, COFF_CHECKSUM_BUFFER_SIZE, abfd);
3431
6
      cur_buf_size = buf_size;
3432
6
      cur_buf = buf;
3433
3434
202k
      while (cur_buf_size > 0)
3435
202k
        {
3436
202k
          coff_read_word_from_buffer (cur_buf, cur_buf_size, &value, pelength);
3437
202k
          cur_buf += 2;
3438
202k
          cur_buf_size -= 2;
3439
202k
          total += value;
3440
202k
          total = 0xffff & (total + (total >> 0x10));
3441
202k
        }
3442
3443
6
      filepos += buf_size;
3444
6
    }
3445
6
  while (buf_size > 0);
3446
3447
3
  free (buf);
3448
3449
3
  return (0xffff & (total + (total >> 0x10)));
3450
3
}
Unexecuted instantiation: pei-aarch64.c:coff_compute_checksum
pei-ia64.c:coff_compute_checksum
Line
Count
Source
3407
1
{
3408
1
  file_ptr filepos;
3409
1
  unsigned int value;
3410
1
  unsigned int total;
3411
1
  unsigned char *buf;
3412
1
  int buf_size;
3413
3414
1
  total = 0;
3415
1
  *pelength = 0;
3416
1
  filepos = (file_ptr) 0;
3417
1
  buf = (unsigned char *) bfd_malloc (COFF_CHECKSUM_BUFFER_SIZE);
3418
1
  if (buf == NULL)
3419
0
    return 0;
3420
1
  buf_size = 0;
3421
3422
1
  do
3423
2
    {
3424
2
      unsigned char *cur_buf;
3425
2
      int cur_buf_size;
3426
3427
2
      if (bfd_seek (abfd, filepos, SEEK_SET) != 0)
3428
0
  return 0;
3429
3430
2
      buf_size = bfd_read (buf, COFF_CHECKSUM_BUFFER_SIZE, abfd);
3431
2
      cur_buf_size = buf_size;
3432
2
      cur_buf = buf;
3433
3434
3.07k
      while (cur_buf_size > 0)
3435
3.07k
        {
3436
3.07k
          coff_read_word_from_buffer (cur_buf, cur_buf_size, &value, pelength);
3437
3.07k
          cur_buf += 2;
3438
3.07k
          cur_buf_size -= 2;
3439
3.07k
          total += value;
3440
3.07k
          total = 0xffff & (total + (total >> 0x10));
3441
3.07k
        }
3442
3443
2
      filepos += buf_size;
3444
2
    }
3445
2
  while (buf_size > 0);
3446
3447
1
  free (buf);
3448
3449
1
  return (0xffff & (total + (total >> 0x10)));
3450
1
}
Unexecuted instantiation: pei-loongarch64.c:coff_compute_checksum
pei-riscv64.c:coff_compute_checksum
Line
Count
Source
3407
5
{
3408
5
  file_ptr filepos;
3409
5
  unsigned int value;
3410
5
  unsigned int total;
3411
5
  unsigned char *buf;
3412
5
  int buf_size;
3413
3414
5
  total = 0;
3415
5
  *pelength = 0;
3416
5
  filepos = (file_ptr) 0;
3417
5
  buf = (unsigned char *) bfd_malloc (COFF_CHECKSUM_BUFFER_SIZE);
3418
5
  if (buf == NULL)
3419
0
    return 0;
3420
5
  buf_size = 0;
3421
3422
5
  do
3423
10
    {
3424
10
      unsigned char *cur_buf;
3425
10
      int cur_buf_size;
3426
3427
10
      if (bfd_seek (abfd, filepos, SEEK_SET) != 0)
3428
0
  return 0;
3429
3430
10
      buf_size = bfd_read (buf, COFF_CHECKSUM_BUFFER_SIZE, abfd);
3431
10
      cur_buf_size = buf_size;
3432
10
      cur_buf = buf;
3433
3434
119k
      while (cur_buf_size > 0)
3435
119k
        {
3436
119k
          coff_read_word_from_buffer (cur_buf, cur_buf_size, &value, pelength);
3437
119k
          cur_buf += 2;
3438
119k
          cur_buf_size -= 2;
3439
119k
          total += value;
3440
119k
          total = 0xffff & (total + (total >> 0x10));
3441
119k
        }
3442
3443
10
      filepos += buf_size;
3444
10
    }
3445
10
  while (buf_size > 0);
3446
3447
5
  free (buf);
3448
3449
5
  return (0xffff & (total + (total >> 0x10)));
3450
5
}
pei-arm-wince.c:coff_compute_checksum
Line
Count
Source
3407
1
{
3408
1
  file_ptr filepos;
3409
1
  unsigned int value;
3410
1
  unsigned int total;
3411
1
  unsigned char *buf;
3412
1
  int buf_size;
3413
3414
1
  total = 0;
3415
1
  *pelength = 0;
3416
1
  filepos = (file_ptr) 0;
3417
1
  buf = (unsigned char *) bfd_malloc (COFF_CHECKSUM_BUFFER_SIZE);
3418
1
  if (buf == NULL)
3419
0
    return 0;
3420
1
  buf_size = 0;
3421
3422
1
  do
3423
2
    {
3424
2
      unsigned char *cur_buf;
3425
2
      int cur_buf_size;
3426
3427
2
      if (bfd_seek (abfd, filepos, SEEK_SET) != 0)
3428
0
  return 0;
3429
3430
2
      buf_size = bfd_read (buf, COFF_CHECKSUM_BUFFER_SIZE, abfd);
3431
2
      cur_buf_size = buf_size;
3432
2
      cur_buf = buf;
3433
3434
190
      while (cur_buf_size > 0)
3435
188
        {
3436
188
          coff_read_word_from_buffer (cur_buf, cur_buf_size, &value, pelength);
3437
188
          cur_buf += 2;
3438
188
          cur_buf_size -= 2;
3439
188
          total += value;
3440
188
          total = 0xffff & (total + (total >> 0x10));
3441
188
        }
3442
3443
2
      filepos += buf_size;
3444
2
    }
3445
2
  while (buf_size > 0);
3446
3447
1
  free (buf);
3448
3449
1
  return (0xffff & (total + (total >> 0x10)));
3450
1
}
Unexecuted instantiation: pei-arm.c:coff_compute_checksum
Unexecuted instantiation: pei-mcore.c:coff_compute_checksum
Unexecuted instantiation: pei-sh.c:coff_compute_checksum
3451
3452
static bool
3453
coff_apply_checksum (bfd *abfd)
3454
14
{
3455
14
  unsigned int computed;
3456
14
  unsigned int checksum = 0;
3457
14
  unsigned int peheader;
3458
14
  unsigned int pelength;
3459
3460
14
  if (bfd_seek (abfd, 0x3c, SEEK_SET) != 0)
3461
0
    return false;
3462
3463
14
  if (!coff_read_word (abfd, &peheader, &pelength))
3464
0
    return false;
3465
3466
14
  if (bfd_seek (abfd, peheader + 0x58, SEEK_SET) != 0)
3467
0
    return false;
3468
3469
14
  checksum = 0;
3470
14
  if (bfd_write (&checksum, 4, abfd) != 4)
3471
0
    return false;
3472
3473
14
  if (bfd_seek (abfd, peheader, SEEK_SET) != 0)
3474
0
    return false;
3475
3476
14
  computed = coff_compute_checksum (abfd, &pelength);
3477
3478
14
  checksum = computed + pelength;
3479
3480
14
  if (bfd_seek (abfd, peheader + 0x58, SEEK_SET) != 0)
3481
0
    return false;
3482
3483
14
  return bfd_write (&checksum, 4, abfd) == 4;
3484
14
}
pei-i386.c:coff_apply_checksum
Line
Count
Source
3454
4
{
3455
4
  unsigned int computed;
3456
4
  unsigned int checksum = 0;
3457
4
  unsigned int peheader;
3458
4
  unsigned int pelength;
3459
3460
4
  if (bfd_seek (abfd, 0x3c, SEEK_SET) != 0)
3461
0
    return false;
3462
3463
4
  if (!coff_read_word (abfd, &peheader, &pelength))
3464
0
    return false;
3465
3466
4
  if (bfd_seek (abfd, peheader + 0x58, SEEK_SET) != 0)
3467
0
    return false;
3468
3469
4
  checksum = 0;
3470
4
  if (bfd_write (&checksum, 4, abfd) != 4)
3471
0
    return false;
3472
3473
4
  if (bfd_seek (abfd, peheader, SEEK_SET) != 0)
3474
0
    return false;
3475
3476
4
  computed = coff_compute_checksum (abfd, &pelength);
3477
3478
4
  checksum = computed + pelength;
3479
3480
4
  if (bfd_seek (abfd, peheader + 0x58, SEEK_SET) != 0)
3481
0
    return false;
3482
3483
4
  return bfd_write (&checksum, 4, abfd) == 4;
3484
4
}
pei-x86_64.c:coff_apply_checksum
Line
Count
Source
3454
3
{
3455
3
  unsigned int computed;
3456
3
  unsigned int checksum = 0;
3457
3
  unsigned int peheader;
3458
3
  unsigned int pelength;
3459
3460
3
  if (bfd_seek (abfd, 0x3c, SEEK_SET) != 0)
3461
0
    return false;
3462
3463
3
  if (!coff_read_word (abfd, &peheader, &pelength))
3464
0
    return false;
3465
3466
3
  if (bfd_seek (abfd, peheader + 0x58, SEEK_SET) != 0)
3467
0
    return false;
3468
3469
3
  checksum = 0;
3470
3
  if (bfd_write (&checksum, 4, abfd) != 4)
3471
0
    return false;
3472
3473
3
  if (bfd_seek (abfd, peheader, SEEK_SET) != 0)
3474
0
    return false;
3475
3476
3
  computed = coff_compute_checksum (abfd, &pelength);
3477
3478
3
  checksum = computed + pelength;
3479
3480
3
  if (bfd_seek (abfd, peheader + 0x58, SEEK_SET) != 0)
3481
0
    return false;
3482
3483
3
  return bfd_write (&checksum, 4, abfd) == 4;
3484
3
}
Unexecuted instantiation: pei-aarch64.c:coff_apply_checksum
pei-ia64.c:coff_apply_checksum
Line
Count
Source
3454
1
{
3455
1
  unsigned int computed;
3456
1
  unsigned int checksum = 0;
3457
1
  unsigned int peheader;
3458
1
  unsigned int pelength;
3459
3460
1
  if (bfd_seek (abfd, 0x3c, SEEK_SET) != 0)
3461
0
    return false;
3462
3463
1
  if (!coff_read_word (abfd, &peheader, &pelength))
3464
0
    return false;
3465
3466
1
  if (bfd_seek (abfd, peheader + 0x58, SEEK_SET) != 0)
3467
0
    return false;
3468
3469
1
  checksum = 0;
3470
1
  if (bfd_write (&checksum, 4, abfd) != 4)
3471
0
    return false;
3472
3473
1
  if (bfd_seek (abfd, peheader, SEEK_SET) != 0)
3474
0
    return false;
3475
3476
1
  computed = coff_compute_checksum (abfd, &pelength);
3477
3478
1
  checksum = computed + pelength;
3479
3480
1
  if (bfd_seek (abfd, peheader + 0x58, SEEK_SET) != 0)
3481
0
    return false;
3482
3483
1
  return bfd_write (&checksum, 4, abfd) == 4;
3484
1
}
Unexecuted instantiation: pei-loongarch64.c:coff_apply_checksum
pei-riscv64.c:coff_apply_checksum
Line
Count
Source
3454
5
{
3455
5
  unsigned int computed;
3456
5
  unsigned int checksum = 0;
3457
5
  unsigned int peheader;
3458
5
  unsigned int pelength;
3459
3460
5
  if (bfd_seek (abfd, 0x3c, SEEK_SET) != 0)
3461
0
    return false;
3462
3463
5
  if (!coff_read_word (abfd, &peheader, &pelength))
3464
0
    return false;
3465
3466
5
  if (bfd_seek (abfd, peheader + 0x58, SEEK_SET) != 0)
3467
0
    return false;
3468
3469
5
  checksum = 0;
3470
5
  if (bfd_write (&checksum, 4, abfd) != 4)
3471
0
    return false;
3472
3473
5
  if (bfd_seek (abfd, peheader, SEEK_SET) != 0)
3474
0
    return false;
3475
3476
5
  computed = coff_compute_checksum (abfd, &pelength);
3477
3478
5
  checksum = computed + pelength;
3479
3480
5
  if (bfd_seek (abfd, peheader + 0x58, SEEK_SET) != 0)
3481
0
    return false;
3482
3483
5
  return bfd_write (&checksum, 4, abfd) == 4;
3484
5
}
pei-arm-wince.c:coff_apply_checksum
Line
Count
Source
3454
1
{
3455
1
  unsigned int computed;
3456
1
  unsigned int checksum = 0;
3457
1
  unsigned int peheader;
3458
1
  unsigned int pelength;
3459
3460
1
  if (bfd_seek (abfd, 0x3c, SEEK_SET) != 0)
3461
0
    return false;
3462
3463
1
  if (!coff_read_word (abfd, &peheader, &pelength))
3464
0
    return false;
3465
3466
1
  if (bfd_seek (abfd, peheader + 0x58, SEEK_SET) != 0)
3467
0
    return false;
3468
3469
1
  checksum = 0;
3470
1
  if (bfd_write (&checksum, 4, abfd) != 4)
3471
0
    return false;
3472
3473
1
  if (bfd_seek (abfd, peheader, SEEK_SET) != 0)
3474
0
    return false;
3475
3476
1
  computed = coff_compute_checksum (abfd, &pelength);
3477
3478
1
  checksum = computed + pelength;
3479
3480
1
  if (bfd_seek (abfd, peheader + 0x58, SEEK_SET) != 0)
3481
0
    return false;
3482
3483
1
  return bfd_write (&checksum, 4, abfd) == 4;
3484
1
}
Unexecuted instantiation: pei-arm.c:coff_apply_checksum
Unexecuted instantiation: pei-mcore.c:coff_apply_checksum
Unexecuted instantiation: pei-sh.c:coff_apply_checksum
3485
3486
#endif /* COFF_IMAGE_WITH_PE */
3487
3488
static bool
3489
coff_write_object_contents (bfd * abfd)
3490
20
{
3491
20
  asection *current;
3492
20
  bool hasrelocs = false;
3493
20
  bool haslinno = false;
3494
#ifdef COFF_IMAGE_WITH_PE
3495
  bool hasdebug = false;
3496
#endif
3497
20
  file_ptr scn_base;
3498
20
  file_ptr reloc_base;
3499
20
  file_ptr lineno_base;
3500
20
  file_ptr sym_base;
3501
20
  unsigned long reloc_size = 0, reloc_count = 0;
3502
20
  unsigned long lnno_size = 0;
3503
20
  bool long_section_names;
3504
20
  asection *text_sec = NULL;
3505
20
  asection *data_sec = NULL;
3506
20
  asection *bss_sec = NULL;
3507
#ifdef RS6000COFF_C
3508
  asection *tdata_sec = NULL;
3509
  asection *tbss_sec = NULL;
3510
#endif
3511
20
  struct internal_filehdr internal_f;
3512
20
  struct internal_aouthdr internal_a;
3513
#ifdef COFF_LONG_SECTION_NAMES
3514
16
  size_t string_size = STRING_SIZE_SIZE;
3515
#endif
3516
3517
20
  bfd_set_error (bfd_error_system_call);
3518
3519
  /* Make a pass through the symbol table to count line number entries and
3520
     put them into the correct asections.  */
3521
20
  lnno_size = coff_count_linenumbers (abfd) * bfd_coff_linesz (abfd);
3522
3523
20
  if (! abfd->output_has_begun)
3524
11
    {
3525
11
      if (! coff_compute_section_file_positions (abfd))
3526
0
  return false;
3527
11
    }
3528
3529
20
  reloc_base = obj_relocbase (abfd);
3530
3531
  /* Work out the size of the reloc and linno areas.  */
3532
3533
472
  for (current = abfd->sections; current != NULL; current =
3534
452
       current->next)
3535
452
    {
3536
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3537
      /* We store the actual reloc count in the first reloc's addr.  */
3538
183
      if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3539
0
  reloc_count ++;
3540
#endif
3541
452
      reloc_count += current->reloc_count;
3542
452
    }
3543
3544
20
  reloc_size = reloc_count * bfd_coff_relsz (abfd);
3545
3546
20
  lineno_base = reloc_base + reloc_size;
3547
20
  sym_base = lineno_base + lnno_size;
3548
3549
  /* Indicate in each section->line_filepos its actual file address.  */
3550
472
  for (current = abfd->sections; current != NULL; current =
3551
452
       current->next)
3552
452
    {
3553
452
      if (current->lineno_count)
3554
0
  {
3555
0
    current->line_filepos = lineno_base;
3556
0
    current->moving_line_filepos = lineno_base;
3557
0
    lineno_base += current->lineno_count * bfd_coff_linesz (abfd);
3558
0
  }
3559
452
      else
3560
452
  current->line_filepos = 0;
3561
3562
452
      if (current->reloc_count)
3563
0
  {
3564
0
    current->rel_filepos = reloc_base;
3565
0
    reloc_base += current->reloc_count * bfd_coff_relsz (abfd);
3566
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3567
    /* Extra reloc to hold real count.  */
3568
0
    if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3569
0
      reloc_base += bfd_coff_relsz (abfd);
3570
#endif
3571
0
  }
3572
452
      else
3573
452
  current->rel_filepos = 0;
3574
452
    }
3575
3576
  /* Write section headers to the file.  */
3577
20
  internal_f.f_nscns = 0;
3578
3579
20
  if ((abfd->flags & EXEC_P) != 0)
3580
14
    scn_base = bfd_coff_filhsz (abfd) + bfd_coff_aoutsz (abfd);
3581
6
  else
3582
6
    {
3583
6
      scn_base = bfd_coff_filhsz (abfd);
3584
#ifdef RS6000COFF_C
3585
#ifndef XCOFF64
3586
0
      if (xcoff_data (abfd)->full_aouthdr)
3587
0
  scn_base += bfd_coff_aoutsz (abfd);
3588
0
      else
3589
0
  scn_base += SMALL_AOUTSZ;
3590
#endif
3591
#endif
3592
6
    }
3593
3594
20
  if (bfd_seek (abfd, scn_base, SEEK_SET) != 0)
3595
0
    return false;
3596
3597
20
  long_section_names = false;
3598
20
  for (current = abfd->sections;
3599
472
       current != NULL;
3600
452
       current = current->next)
3601
452
    {
3602
452
      struct internal_scnhdr section;
3603
#ifdef COFF_IMAGE_WITH_PE
3604
      bool is_reloc_section = false;
3605
3606
183
      if (strcmp (current->name, DOT_RELOC) == 0)
3607
2
  {
3608
2
    is_reloc_section = true;
3609
2
    hasrelocs = true;
3610
2
    pe_data (abfd)->has_reloc_section = 1;
3611
2
  }
3612
#endif
3613
3614
452
      internal_f.f_nscns++;
3615
3616
452
      strncpy (section.s_name, current->name, SCNNMLEN);
3617
3618
#ifdef COFF_LONG_SECTION_NAMES
3619
      /* Handle long section names as in PE.  This must be compatible
3620
   with the code in coff_write_symbols and _bfd_coff_final_link.  */
3621
183
      if (bfd_coff_long_section_names (abfd))
3622
23
  {
3623
23
    size_t len;
3624
3625
    len = strlen (current->name);
3626
23
    if (len > SCNNMLEN)
3627
11
      {
3628
3629
        /* An inherent limitation of the /nnnnnnn notation used to indicate
3630
     the offset of the long name in the string table is that we
3631
     cannot address entries beyone the ten million byte boundary.  */
3632
11
        if (string_size < 10000000)
3633
11
    {
3634
      /* The s_name field is defined to be NUL-padded but need not
3635
         be NUL-terminated.  We use a temporary buffer so that we
3636
         can still sprintf all eight chars without splatting a
3637
         terminating NUL over the first byte of the following
3638
         member (s_paddr).  */
3639
      /* PR 21096: The +20 is to stop a bogus warning from gcc7
3640
         about a possible buffer overflow.  */
3641
      char s_name_buf[SCNNMLEN + 1 + 20];
3642
3643
      /* We do not need to use snprintf here as we have already
3644
         verified that string_size is not too big, plus we have
3645
         an overlarge buffer, just in case.  */
3646
11
      sprintf (s_name_buf, "/%lu", (unsigned long) string_size);
3647
      /* Then strncpy takes care of any padding for us.  */
3648
11
      strncpy (section.s_name, s_name_buf, SCNNMLEN);
3649
11
    }
3650
0
        else
3651
#ifdef COFF_WITH_PE
3652
0
    {
3653
      /* PE use a base 64 encoding for long section names whose
3654
         index is very large.  But contrary to RFC 4648, there is
3655
         no padding: 6 characters must be generated.  */
3656
0
      static const char base64[] =
3657
0
        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
3658
0
        "abcdefghijklmnopqrstuvwxyz"
3659
0
        "0123456789+/";
3660
0
      unsigned long off = string_size;
3661
0
      unsigned i;
3662
3663
0
      section.s_name[0] = '/';
3664
0
      section.s_name[1] = '/';
3665
0
      for (i = SCNNMLEN - 1; i >= 2; i--)
3666
0
        {
3667
0
          section.s_name[i] = base64[off & 0x3f];
3668
0
          off >>= 6;
3669
0
        }
3670
0
    }
3671
#endif
3672
11
        if (string_size > 0xffffffffUL - (len + 1)
3673
#ifndef COFF_WITH_PE
3674
0
      || string_size >= 10000000
3675
#endif
3676
0
      )
3677
0
    {
3678
0
      bfd_set_error (bfd_error_file_too_big);
3679
0
      _bfd_error_handler
3680
        /* xgettext:c-format */
3681
0
        (_("%pB: section %pA: string table overflow at offset %ld"),
3682
0
        abfd, current, (unsigned long) string_size);
3683
0
      return false;
3684
0
    }
3685
3686
11
        string_size += len + 1;
3687
11
        long_section_names = true;
3688
11
      }
3689
23
  }
3690
183
#endif
3691
3692
#ifdef _LIB
3693
      /* Always set s_vaddr of .lib to 0.  This is right for SVR3.2
3694
   Ian Taylor <ian@cygnus.com>.  */
3695
452
      if (strcmp (current->name, _LIB) == 0)
3696
0
  section.s_vaddr = 0;
3697
452
      else
3698
452
#endif
3699
452
      section.s_vaddr = current->vma;
3700
183
      section.s_paddr = current->lma;
3701
183
      section.s_size =  current->size;
3702
#ifdef coff_get_section_load_page
3703
0
      section.s_page = coff_get_section_load_page (current);
3704
#else
3705
      section.s_page = 0;
3706
#endif
3707
3708
#ifdef COFF_WITH_PE
3709
      section.s_paddr = 0;
3710
#endif
3711
#ifdef COFF_IMAGE_WITH_PE
3712
      /* Reminder: s_paddr holds the virtual size of the section.  */
3713
183
      if (coff_section_data (abfd, current) != NULL
3714
183
    && pei_section_data (abfd, current) != NULL)
3715
183
  section.s_paddr = pei_section_data (abfd, current)->virt_size;
3716
0
      else
3717
0
  section.s_paddr = 0;
3718
#endif
3719
3720
      /* If this section has no size or is unloadable then the scnptr
3721
   will be 0 too.  */
3722
452
      if (current->size == 0
3723
452
    || (current->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
3724
410
  section.s_scnptr = 0;
3725
42
      else
3726
42
  section.s_scnptr = current->filepos;
3727
3728
183
      section.s_relptr = current->rel_filepos;
3729
183
      section.s_lnnoptr = current->line_filepos;
3730
183
      section.s_nreloc = current->reloc_count;
3731
183
      section.s_nlnno = current->lineno_count;
3732
#ifndef COFF_IMAGE_WITH_PE
3733
      /* In PEI, relocs come in the .reloc section.  */
3734
269
      if (current->reloc_count != 0)
3735
0
  hasrelocs = true;
3736
#endif
3737
452
      if (current->lineno_count != 0)
3738
0
  haslinno = true;
3739
#ifdef COFF_IMAGE_WITH_PE
3740
183
      if ((current->flags & SEC_DEBUGGING) != 0
3741
183
    && ! is_reloc_section)
3742
21
  hasdebug = true;
3743
#endif
3744
3745
#ifdef RS6000COFF_C
3746
#ifndef XCOFF64
3747
      /* Indicate the use of an XCOFF overflow section header.  */
3748
0
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3749
0
  {
3750
0
    section.s_nreloc = 0xffff;
3751
0
    section.s_nlnno = 0xffff;
3752
0
  }
3753
#endif
3754
#endif
3755
3756
183
      section.s_flags = sec_to_styp_flags (current->name, current->flags);
3757
3758
452
      if (!strcmp (current->name, _TEXT))
3759
2
  text_sec = current;
3760
450
      else if (!strcmp (current->name, _DATA))
3761
2
  data_sec = current;
3762
448
      else if (!strcmp (current->name, _BSS))
3763
1
  bss_sec = current;
3764
#ifdef RS6000COFF_C
3765
0
      else if (!strcmp (current->name, _TDATA))
3766
0
  tdata_sec = current;
3767
0
      else if (!strcmp (current->name, _TBSS))
3768
0
  tbss_sec = current;
3769
#endif
3770
3771
3772
#ifdef COFF_ENCODE_ALIGNMENT
3773
183
      if (COFF_ENCODE_ALIGNMENT (abfd, section, current->alignment_power)
3774
183
    && (COFF_DECODE_ALIGNMENT (section.s_flags)
3775
133
        != current->alignment_power))
3776
0
  {
3777
0
    bool warn = (coff_data (abfd)->link_info
3778
0
           && !bfd_link_relocatable (coff_data (abfd)->link_info));
3779
3780
0
    _bfd_error_handler
3781
      /* xgettext:c-format */
3782
0
      (_("%pB:%s section %s: alignment 2**%u not representable"),
3783
0
       abfd, warn ? " warning:" : "", current->name,
3784
0
       current->alignment_power);
3785
0
    if (!warn)
3786
0
      {
3787
0
        bfd_set_error (bfd_error_nonrepresentable_section);
3788
0
        return false;
3789
0
      }
3790
0
  }
3791
183
#endif
3792
3793
#ifdef COFF_IMAGE_WITH_PE
3794
      /* Suppress output of the sections if they are null.  ld
3795
   includes the bss and data sections even if there is no size
3796
   assigned to them.  NT loader doesn't like it if these section
3797
   headers are included if the sections themselves are not
3798
   needed.  See also coff_compute_section_file_positions.  */
3799
183
      if (section.s_size == 0)
3800
142
  internal_f.f_nscns--;
3801
41
      else
3802
41
#endif
3803
41
  {
3804
310
    SCNHDR buff;
3805
310
    bfd_size_type amt = bfd_coff_scnhsz (abfd);
3806
3807
310
    if (bfd_coff_swap_scnhdr_out (abfd, &section, &buff) == 0
3808
310
        || bfd_write (& buff, amt, abfd) != amt)
3809
0
      return false;
3810
41
  }
3811
3812
#ifdef COFF_WITH_PE
3813
      /* PE stores COMDAT section information in the symbol table.  If
3814
   this section is supposed to have some COMDAT info, track down
3815
   the symbol in the symbol table and modify it.  */
3816
183
      if ((current->flags & SEC_LINK_ONCE) != 0)
3817
0
  {
3818
0
    unsigned int i, count;
3819
0
    asymbol **psym;
3820
0
    coff_symbol_type *csym = NULL;
3821
0
    asymbol **psymsec;
3822
3823
    psymsec = NULL;
3824
    count = bfd_get_symcount (abfd);
3825
0
    for (i = 0, psym = abfd->outsymbols; i < count; i++, psym++)
3826
0
      {
3827
0
        if ((*psym)->section != current)
3828
0
    continue;
3829
3830
        /* Remember the location of the first symbol in this
3831
     section.  */
3832
0
        if (psymsec == NULL)
3833
0
    psymsec = psym;
3834
3835
        /* See if this is the section symbol.  */
3836
0
        if (strcmp ((*psym)->name, current->name) == 0)
3837
0
    {
3838
0
      csym = coff_symbol_from (*psym);
3839
0
      if (csym == NULL
3840
0
          || csym->native == NULL
3841
0
          || ! csym->native->is_sym
3842
0
          || csym->native->u.syment.n_numaux < 1
3843
0
          || csym->native->u.syment.n_sclass != C_STAT
3844
0
          || csym->native->u.syment.n_type != T_NULL)
3845
0
        continue;
3846
3847
      /* Here *PSYM is the section symbol for CURRENT.  */
3848
3849
0
      break;
3850
0
    }
3851
0
      }
3852
3853
    /* Did we find it?
3854
       Note that we might not if we're converting the file from
3855
       some other object file format.  */
3856
0
    if (i < count)
3857
0
      {
3858
0
        combined_entry_type *aux;
3859
3860
        /* We don't touch the x_checksum field.  The
3861
     x_associated field is not currently supported.  */
3862
3863
0
        aux = csym->native + 1;
3864
0
        BFD_ASSERT (! aux->is_sym);
3865
0
        switch (current->flags & SEC_LINK_DUPLICATES)
3866
0
    {
3867
0
    case SEC_LINK_DUPLICATES_DISCARD:
3868
0
      aux->u.auxent.x_scn.x_comdat = IMAGE_COMDAT_SELECT_ANY;
3869
0
      break;
3870
3871
0
    case SEC_LINK_DUPLICATES_ONE_ONLY:
3872
0
      aux->u.auxent.x_scn.x_comdat =
3873
0
        IMAGE_COMDAT_SELECT_NODUPLICATES;
3874
0
      break;
3875
3876
0
    case SEC_LINK_DUPLICATES_SAME_SIZE:
3877
0
      aux->u.auxent.x_scn.x_comdat =
3878
0
        IMAGE_COMDAT_SELECT_SAME_SIZE;
3879
0
      break;
3880
3881
0
    case SEC_LINK_DUPLICATES_SAME_CONTENTS:
3882
0
      aux->u.auxent.x_scn.x_comdat =
3883
0
        IMAGE_COMDAT_SELECT_EXACT_MATCH;
3884
0
      break;
3885
0
    }
3886
3887
        /* The COMDAT symbol must be the first symbol from this
3888
     section in the symbol table.  In order to make this
3889
     work, we move the COMDAT symbol before the first
3890
     symbol we found in the search above.  It's OK to
3891
     rearrange the symbol table at this point, because
3892
     coff_renumber_symbols is going to rearrange it
3893
     further and fix up all the aux entries.  */
3894
0
        if (psym != psymsec)
3895
0
    {
3896
0
      asymbol *hold;
3897
0
      asymbol **pcopy;
3898
3899
0
      hold = *psym;
3900
0
      for (pcopy = psym; pcopy > psymsec; pcopy--)
3901
0
        pcopy[0] = pcopy[-1];
3902
0
      *psymsec = hold;
3903
0
    }
3904
0
      }
3905
0
  }
3906
#endif /* COFF_WITH_PE */
3907
183
    }
3908
3909
#ifdef RS6000COFF_C
3910
#ifndef XCOFF64
3911
  /* XCOFF handles overflows in the reloc and line number count fields
3912
     by creating a new section header to hold the correct values.  */
3913
0
  for (current = abfd->sections; current != NULL; current = current->next)
3914
0
    {
3915
0
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3916
0
  {
3917
0
    struct internal_scnhdr scnhdr;
3918
0
    SCNHDR buff;
3919
0
    bfd_size_type amt;
3920
3921
0
    internal_f.f_nscns++;
3922
0
    memcpy (scnhdr.s_name, ".ovrflo", 8);
3923
0
    scnhdr.s_paddr = current->reloc_count;
3924
0
    scnhdr.s_vaddr = current->lineno_count;
3925
0
    scnhdr.s_size = 0;
3926
0
    scnhdr.s_scnptr = 0;
3927
0
    scnhdr.s_relptr = current->rel_filepos;
3928
0
    scnhdr.s_lnnoptr = current->line_filepos;
3929
0
    scnhdr.s_nreloc = current->target_index;
3930
0
    scnhdr.s_nlnno = current->target_index;
3931
0
    scnhdr.s_flags = STYP_OVRFLO;
3932
0
    amt = bfd_coff_scnhsz (abfd);
3933
0
    if (bfd_coff_swap_scnhdr_out (abfd, &scnhdr, &buff) == 0
3934
0
        || bfd_write (& buff, amt, abfd) != amt)
3935
0
      return false;
3936
0
  }
3937
0
    }
3938
0
#endif
3939
#endif
3940
3941
#if defined (COFF_GO32_EXE) || defined (COFF_GO32)
3942
  /* Pad section headers.  */
3943
0
  if ((abfd->flags & EXEC_P) != 0)
3944
0
    {
3945
0
      asection *s = abfd->sections;
3946
0
      while (s != NULL && s->filepos == 0)
3947
0
  s = s->next;
3948
0
      if (s != NULL)
3949
0
  {
3950
0
    file_ptr cur_ptr
3951
0
      = scn_base + abfd->section_count * bfd_coff_scnhsz (abfd);
3952
0
    file_ptr fill_size = s->filepos - cur_ptr;
3953
0
    if (fill_size > 0)
3954
0
      {
3955
0
        bfd_byte *b = bfd_zmalloc (fill_size);
3956
0
        if (!b)
3957
0
    return false;
3958
0
        if (bfd_write (b, fill_size, abfd) != (ufile_ptr) fill_size)
3959
0
    {
3960
0
      free (b);
3961
0
      return false;
3962
0
    }
3963
0
        free (b);
3964
0
      }
3965
0
  }
3966
0
    }
3967
0
#endif
3968
3969
  /* OK, now set up the filehdr...  */
3970
3971
  /* Don't include the internal abs section in the section count */
3972
3973
  /* We will NOT put a fucking timestamp in the header here. Every time you
3974
     put it back, I will come in and take it out again.  I'm sorry.  This
3975
     field does not belong here.  We fill it with a 0 so it compares the
3976
     same but is not a reasonable time. -- gnu@cygnus.com  */
3977
20
  internal_f.f_timdat = 0;
3978
20
  internal_f.f_flags = 0;
3979
3980
20
  if (abfd->flags & EXEC_P)
3981
14
    internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3982
6
  else
3983
6
    {
3984
6
      internal_f.f_opthdr = 0;
3985
#ifdef RS6000COFF_C
3986
#ifndef XCOFF64
3987
0
      if (xcoff_data (abfd)->full_aouthdr)
3988
0
  internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3989
0
      else
3990
0
  internal_f.f_opthdr = SMALL_AOUTSZ;
3991
#endif
3992
#endif
3993
6
    }
3994
3995
20
  if (!hasrelocs)
3996
18
    internal_f.f_flags |= F_RELFLG;
3997
20
  if (!haslinno)
3998
20
    internal_f.f_flags |= F_LNNO;
3999
20
  if (abfd->flags & EXEC_P)
4000
14
    internal_f.f_flags |= F_EXEC;
4001
#ifdef COFF_IMAGE_WITH_PE
4002
16
  if (! hasdebug)
4003
10
    internal_f.f_flags |= IMAGE_FILE_DEBUG_STRIPPED;
4004
16
  if (pe_data (abfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
4005
11
    internal_f.f_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
4006
#endif
4007
4008
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64) && !defined (COFF_WITH_peRiscV64)
4009
#ifdef COFF_WITH_PE
4010
6
  internal_f.f_flags |= IMAGE_FILE_32BIT_MACHINE;
4011
#else
4012
4
  if (bfd_little_endian (abfd))
4013
4
    internal_f.f_flags |= F_AR32WR;
4014
0
  else
4015
0
    internal_f.f_flags |= F_AR32W;
4016
#endif
4017
#endif
4018
4019
#ifdef TI_TARGET_ID
4020
  /* Target id is used in TI COFF v1 and later; COFF0 won't use this field,
4021
     but it doesn't hurt to set it internally.  */
4022
0
  internal_f.f_target_id = TI_TARGET_ID;
4023
#endif
4024
4025
  /* FIXME, should do something about the other byte orders and
4026
     architectures.  */
4027
4028
#ifdef RS6000COFF_C
4029
0
  if ((abfd->flags & DYNAMIC) != 0)
4030
0
    internal_f.f_flags |= F_SHROBJ;
4031
0
  if (bfd_get_section_by_name (abfd, _LOADER) != NULL)
4032
0
    internal_f.f_flags |= F_DYNLOAD;
4033
#endif
4034
4035
20
  memset (&internal_a, 0, sizeof internal_a);
4036
4037
  /* Set up architecture-dependent stuff.  */
4038
20
  {
4039
20
    unsigned int magic = 0;
4040
20
    unsigned short flags = 0;
4041
4042
20
    coff_set_flags (abfd, &magic, &flags);
4043
20
    internal_f.f_magic = magic;
4044
20
    internal_f.f_flags |= flags;
4045
    /* ...and the "opt"hdr...  */
4046
4047
#ifdef TICOFF_AOUT_MAGIC
4048
0
    internal_a.magic = TICOFF_AOUT_MAGIC;
4049
#define __A_MAGIC_SET__
4050
#endif
4051
4052
#if defined(ARM)
4053
#define __A_MAGIC_SET__
4054
1
    internal_a.magic = ZMAGIC;
4055
#endif
4056
4057
#if defined(AARCH64)
4058
#define __A_MAGIC_SET__
4059
2
    internal_a.magic = ZMAGIC;
4060
#endif
4061
4062
#if defined(LOONGARCH64)
4063
#define __A_MAGIC_SET__
4064
0
    internal_a.magic = ZMAGIC;
4065
#endif
4066
4067
#if defined(RISCV64)
4068
#define __A_MAGIC_SET__
4069
5
    internal_a.magic = ZMAGIC;
4070
#endif
4071
4072
#if defined MCORE_PE
4073
#define __A_MAGIC_SET__
4074
0
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR_MAGIC;
4075
#endif
4076
4077
#if defined(I386)
4078
#define __A_MAGIC_SET__
4079
#if defined LYNXOS
4080
0
    internal_a.magic = LYNXCOFFMAGIC;
4081
#elif defined AMD64
4082
7
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR64_MAGIC;
4083
#else
4084
4
    internal_a.magic = ZMAGIC;
4085
#endif
4086
#endif /* I386 */
4087
4088
#if defined(IA64)
4089
#define __A_MAGIC_SET__
4090
1
    internal_a.magic = PE32PMAGIC;
4091
#endif /* IA64 */
4092
4093
#if defined(SPARC)
4094
#define __A_MAGIC_SET__
4095
#if defined(LYNXOS)
4096
    internal_a.magic = LYNXCOFFMAGIC;
4097
#endif /* LYNXOS */
4098
#endif /* SPARC */
4099
4100
#ifdef RS6000COFF_C
4101
#define __A_MAGIC_SET__
4102
0
    internal_a.magic = (abfd->flags & D_PAGED) ? RS6K_AOUTHDR_ZMAGIC :
4103
0
    (abfd->flags & WP_TEXT) ? RS6K_AOUTHDR_NMAGIC :
4104
0
    RS6K_AOUTHDR_OMAGIC;
4105
#endif
4106
4107
#if defined(SH) && defined(COFF_WITH_PE)
4108
#define __A_MAGIC_SET__
4109
0
    internal_a.magic = SH_PE_MAGIC;
4110
#endif
4111
4112
#if defined(MIPS) && defined(COFF_WITH_PE)
4113
#define __A_MAGIC_SET__
4114
    internal_a.magic = MIPS_PE_MAGIC;
4115
#endif
4116
4117
#ifndef __A_MAGIC_SET__
4118
#include "Your aouthdr magic number is not being set!"
4119
#else
4120
20
#undef __A_MAGIC_SET__
4121
20
#endif
4122
20
  }
4123
4124
#ifdef RS6000COFF_C
4125
  /* XCOFF 32bit needs this to have new behaviour for n_type field.  */
4126
  internal_a.vstamp = 2;
4127
#else
4128
  /* FIXME: Does anybody ever set this to another value?  */
4129
  internal_a.vstamp = 0;
4130
#endif
4131
4132
  /* Now should write relocs, strings, syms.  */
4133
20
  obj_sym_filepos (abfd) = sym_base;
4134
4135
20
  if (bfd_get_symcount (abfd) != 0)
4136
6
    {
4137
6
      int firstundef;
4138
4139
6
      if (!coff_renumber_symbols (abfd, &firstundef))
4140
0
  return false;
4141
6
      coff_mangle_symbols (abfd);
4142
6
      if (! coff_write_symbols (abfd))
4143
0
  return false;
4144
6
      if (! coff_write_linenumbers (abfd))
4145
0
  return false;
4146
6
      if (! coff_write_relocs (abfd, firstundef))
4147
0
  return false;
4148
6
    }
4149
#ifdef COFF_LONG_SECTION_NAMES
4150
11
  else if (long_section_names && ! obj_coff_strings_written (abfd))
4151
0
    {
4152
      /* If we have long section names we have to write out the string
4153
   table even if there are no symbols.  */
4154
0
      if (! coff_write_symbols (abfd))
4155
0
  return false;
4156
0
    }
4157
16
#endif
4158
  /* If bfd_get_symcount (abfd) != 0, then we are not using the COFF
4159
     backend linker, and obj_raw_syment_count is not valid until after
4160
     coff_write_symbols is called.  */
4161
20
  if (obj_raw_syment_count (abfd) != 0)
4162
6
    {
4163
6
      internal_f.f_symptr = sym_base;
4164
#ifdef RS6000COFF_C
4165
      /* AIX appears to require that F_RELFLG not be set if there are
4166
   local symbols but no relocations.  */
4167
0
      internal_f.f_flags &=~ F_RELFLG;
4168
#endif
4169
6
    }
4170
14
  else
4171
14
    {
4172
14
      if (long_section_names)
4173
0
  internal_f.f_symptr = sym_base;
4174
14
      else
4175
14
  internal_f.f_symptr = 0;
4176
14
      internal_f.f_flags |= F_LSYMS;
4177
14
    }
4178
4179
20
  if (text_sec)
4180
2
    {
4181
2
      internal_a.tsize = text_sec->size;
4182
2
      internal_a.text_start = internal_a.tsize ? text_sec->vma : 0;
4183
2
    }
4184
20
  if (data_sec)
4185
2
    {
4186
2
      internal_a.dsize = data_sec->size;
4187
2
      internal_a.data_start = internal_a.dsize ? data_sec->vma : 0;
4188
2
    }
4189
20
  if (bss_sec)
4190
1
    {
4191
1
      internal_a.bsize = bss_sec->size;
4192
1
      if (internal_a.bsize && bss_sec->vma < internal_a.data_start)
4193
0
  internal_a.data_start = bss_sec->vma;
4194
1
    }
4195
4196
20
  internal_a.entry = bfd_get_start_address (abfd);
4197
20
  internal_f.f_nsyms = obj_raw_syment_count (abfd);
4198
4199
#ifdef RS6000COFF_C
4200
0
  if (xcoff_data (abfd)->full_aouthdr)
4201
0
    {
4202
0
      bfd_vma toc;
4203
0
      asection *loader_sec;
4204
4205
      internal_a.vstamp = 2;
4206
4207
0
      internal_a.o_snentry = xcoff_data (abfd)->snentry;
4208
0
      if (internal_a.o_snentry == 0)
4209
0
  internal_a.entry = (bfd_vma) -1;
4210
4211
0
      if (text_sec != NULL)
4212
0
  {
4213
0
    internal_a.o_sntext = text_sec->target_index;
4214
0
    internal_a.o_algntext = bfd_section_alignment (text_sec);
4215
0
  }
4216
0
      else
4217
0
  {
4218
0
    internal_a.o_sntext = 0;
4219
0
    internal_a.o_algntext = 0;
4220
0
  }
4221
0
      if (data_sec != NULL)
4222
0
  {
4223
0
    internal_a.o_sndata = data_sec->target_index;
4224
0
    internal_a.o_algndata = bfd_section_alignment (data_sec);
4225
0
  }
4226
0
      else
4227
0
  {
4228
0
    internal_a.o_sndata = 0;
4229
0
    internal_a.o_algndata = 0;
4230
0
  }
4231
      loader_sec = bfd_get_section_by_name (abfd, ".loader");
4232
0
      if (loader_sec != NULL)
4233
0
  internal_a.o_snloader = loader_sec->target_index;
4234
0
      else
4235
0
  internal_a.o_snloader = 0;
4236
0
      if (bss_sec != NULL)
4237
0
  internal_a.o_snbss = bss_sec->target_index;
4238
0
      else
4239
0
  internal_a.o_snbss = 0;
4240
4241
0
      if (tdata_sec != NULL)
4242
0
  {
4243
0
    internal_a.o_sntdata = tdata_sec->target_index;
4244
    /* TODO: o_flags should be set to RS6K_AOUTHDR_TLS_LE
4245
       if there is at least one R_TLS_LE relocations.  */
4246
0
    internal_a.o_flags = 0;
4247
#ifdef XCOFF64
4248
    internal_a.o_x64flags = 0;
4249
#endif
4250
0
  }
4251
0
      else
4252
0
  {
4253
0
    internal_a.o_sntdata = 0;
4254
0
    internal_a.o_flags = 0;
4255
#ifdef XCOFF64
4256
    internal_a.o_x64flags = 0;
4257
#endif
4258
0
  }
4259
0
      if (tbss_sec != NULL)
4260
0
    internal_a.o_sntbss = tbss_sec->target_index;
4261
0
      else
4262
0
    internal_a.o_sntbss = 0;
4263
4264
0
      toc = xcoff_data (abfd)->toc;
4265
      internal_a.o_toc = toc;
4266
0
      internal_a.o_sntoc = xcoff_data (abfd)->sntoc;
4267
4268
0
      internal_a.o_modtype = xcoff_data (abfd)->modtype;
4269
0
      if (xcoff_data (abfd)->cputype != -1)
4270
0
  internal_a.o_cputype = xcoff_data (abfd)->cputype;
4271
0
      else
4272
0
  {
4273
0
    switch (bfd_get_arch (abfd))
4274
0
      {
4275
0
      case bfd_arch_rs6000:
4276
0
        internal_a.o_cputype = 4;
4277
0
        break;
4278
0
      case bfd_arch_powerpc:
4279
0
        if (bfd_get_mach (abfd) == bfd_mach_ppc)
4280
0
    internal_a.o_cputype = 3;
4281
0
        else if (bfd_get_mach (abfd) == bfd_mach_ppc_620)
4282
0
    internal_a.o_cputype = 2;
4283
0
        else
4284
0
    internal_a.o_cputype = 1;
4285
0
        break;
4286
0
      default:
4287
0
        abort ();
4288
0
      }
4289
0
  }
4290
0
      internal_a.o_maxstack = xcoff_data (abfd)->maxstack;
4291
0
      internal_a.o_maxdata = xcoff_data (abfd)->maxdata;
4292
0
    }
4293
0
#endif
4294
4295
#ifdef COFF_WITH_PE
4296
  {
4297
    /* After object contents are finalized so we can compute a reasonable hash,
4298
       but before header is written so we can update it to point to debug directory.  */
4299
16
    struct pe_tdata *pe = pe_data (abfd);
4300
4301
16
    if (pe->build_id.after_write_object_contents != NULL)
4302
0
      (*pe->build_id.after_write_object_contents) (abfd);
4303
  }
4304
#endif
4305
4306
  /* Now write header.  */
4307
20
  if (bfd_seek (abfd, 0, SEEK_SET) != 0)
4308
0
    return false;
4309
4310
20
  {
4311
20
    char * buff;
4312
20
    bfd_size_type amount = bfd_coff_filhsz (abfd);
4313
4314
20
    buff = (char *) bfd_malloc (amount);
4315
20
    if (buff == NULL)
4316
0
      return false;
4317
4318
20
    bfd_coff_swap_filehdr_out (abfd, & internal_f, buff);
4319
20
    amount = bfd_write (buff, amount, abfd);
4320
4321
20
    free (buff);
4322
4323
20
    if (amount != bfd_coff_filhsz (abfd))
4324
0
      return false;
4325
20
  }
4326
4327
20
  if (abfd->flags & EXEC_P)
4328
14
    {
4329
      /* Note that peicode.h fills in a PEAOUTHDR, not an AOUTHDR.
4330
   include/coff/pe.h sets AOUTSZ == sizeof (PEAOUTHDR)).  */
4331
14
      char * buff;
4332
14
      bfd_size_type amount = bfd_coff_aoutsz (abfd);
4333
4334
14
      buff = (char *) bfd_malloc (amount);
4335
14
      if (buff == NULL)
4336
0
  return false;
4337
4338
14
      coff_swap_aouthdr_out (abfd, & internal_a, buff);
4339
14
      amount = bfd_write (buff, amount, abfd);
4340
4341
14
      free (buff);
4342
4343
14
      if (amount != bfd_coff_aoutsz (abfd))
4344
0
  return false;
4345
4346
#ifdef COFF_IMAGE_WITH_PE
4347
14
      if (! coff_apply_checksum (abfd))
4348
0
  return false;
4349
#endif
4350
14
    }
4351
#ifdef RS6000COFF_C
4352
#ifndef XCOFF64
4353
  else
4354
0
    {
4355
0
      AOUTHDR buff;
4356
0
      size_t size;
4357
4358
      /* XCOFF32 seems to always write at least a small a.out header.  */
4359
0
      coff_swap_aouthdr_out (abfd, & internal_a, & buff);
4360
0
      if (xcoff_data (abfd)->full_aouthdr)
4361
0
  size = bfd_coff_aoutsz (abfd);
4362
0
      else
4363
0
  size = SMALL_AOUTSZ;
4364
0
      if (bfd_write (&buff, size, abfd) != size)
4365
0
  return false;
4366
0
    }
4367
0
#endif
4368
#endif
4369
4370
20
  return true;
4371
20
}
pei-i386.c:coff_write_object_contents
Line
Count
Source
3490
4
{
3491
4
  asection *current;
3492
4
  bool hasrelocs = false;
3493
4
  bool haslinno = false;
3494
4
#ifdef COFF_IMAGE_WITH_PE
3495
4
  bool hasdebug = false;
3496
4
#endif
3497
4
  file_ptr scn_base;
3498
4
  file_ptr reloc_base;
3499
4
  file_ptr lineno_base;
3500
4
  file_ptr sym_base;
3501
4
  unsigned long reloc_size = 0, reloc_count = 0;
3502
4
  unsigned long lnno_size = 0;
3503
4
  bool long_section_names;
3504
4
  asection *text_sec = NULL;
3505
4
  asection *data_sec = NULL;
3506
4
  asection *bss_sec = NULL;
3507
#ifdef RS6000COFF_C
3508
  asection *tdata_sec = NULL;
3509
  asection *tbss_sec = NULL;
3510
#endif
3511
4
  struct internal_filehdr internal_f;
3512
4
  struct internal_aouthdr internal_a;
3513
4
#ifdef COFF_LONG_SECTION_NAMES
3514
4
  size_t string_size = STRING_SIZE_SIZE;
3515
4
#endif
3516
3517
4
  bfd_set_error (bfd_error_system_call);
3518
3519
  /* Make a pass through the symbol table to count line number entries and
3520
     put them into the correct asections.  */
3521
4
  lnno_size = coff_count_linenumbers (abfd) * bfd_coff_linesz (abfd);
3522
3523
4
  if (! abfd->output_has_begun)
3524
3
    {
3525
3
      if (! coff_compute_section_file_positions (abfd))
3526
0
  return false;
3527
3
    }
3528
3529
4
  reloc_base = obj_relocbase (abfd);
3530
3531
  /* Work out the size of the reloc and linno areas.  */
3532
3533
7
  for (current = abfd->sections; current != NULL; current =
3534
3
       current->next)
3535
3
    {
3536
3
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3537
      /* We store the actual reloc count in the first reloc's addr.  */
3538
3
      if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3539
0
  reloc_count ++;
3540
3
#endif
3541
3
      reloc_count += current->reloc_count;
3542
3
    }
3543
3544
4
  reloc_size = reloc_count * bfd_coff_relsz (abfd);
3545
3546
4
  lineno_base = reloc_base + reloc_size;
3547
4
  sym_base = lineno_base + lnno_size;
3548
3549
  /* Indicate in each section->line_filepos its actual file address.  */
3550
7
  for (current = abfd->sections; current != NULL; current =
3551
3
       current->next)
3552
3
    {
3553
3
      if (current->lineno_count)
3554
0
  {
3555
0
    current->line_filepos = lineno_base;
3556
0
    current->moving_line_filepos = lineno_base;
3557
0
    lineno_base += current->lineno_count * bfd_coff_linesz (abfd);
3558
0
  }
3559
3
      else
3560
3
  current->line_filepos = 0;
3561
3562
3
      if (current->reloc_count)
3563
0
  {
3564
0
    current->rel_filepos = reloc_base;
3565
0
    reloc_base += current->reloc_count * bfd_coff_relsz (abfd);
3566
0
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3567
    /* Extra reloc to hold real count.  */
3568
0
    if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3569
0
      reloc_base += bfd_coff_relsz (abfd);
3570
0
#endif
3571
0
  }
3572
3
      else
3573
3
  current->rel_filepos = 0;
3574
3
    }
3575
3576
  /* Write section headers to the file.  */
3577
4
  internal_f.f_nscns = 0;
3578
3579
4
  if ((abfd->flags & EXEC_P) != 0)
3580
4
    scn_base = bfd_coff_filhsz (abfd) + bfd_coff_aoutsz (abfd);
3581
0
  else
3582
0
    {
3583
0
      scn_base = bfd_coff_filhsz (abfd);
3584
#ifdef RS6000COFF_C
3585
#ifndef XCOFF64
3586
      if (xcoff_data (abfd)->full_aouthdr)
3587
  scn_base += bfd_coff_aoutsz (abfd);
3588
      else
3589
  scn_base += SMALL_AOUTSZ;
3590
#endif
3591
#endif
3592
0
    }
3593
3594
4
  if (bfd_seek (abfd, scn_base, SEEK_SET) != 0)
3595
0
    return false;
3596
3597
4
  long_section_names = false;
3598
4
  for (current = abfd->sections;
3599
7
       current != NULL;
3600
4
       current = current->next)
3601
3
    {
3602
3
      struct internal_scnhdr section;
3603
3
#ifdef COFF_IMAGE_WITH_PE
3604
3
      bool is_reloc_section = false;
3605
3606
3
      if (strcmp (current->name, DOT_RELOC) == 0)
3607
0
  {
3608
0
    is_reloc_section = true;
3609
0
    hasrelocs = true;
3610
0
    pe_data (abfd)->has_reloc_section = 1;
3611
0
  }
3612
3
#endif
3613
3614
3
      internal_f.f_nscns++;
3615
3616
3
      strncpy (section.s_name, current->name, SCNNMLEN);
3617
3618
3
#ifdef COFF_LONG_SECTION_NAMES
3619
      /* Handle long section names as in PE.  This must be compatible
3620
   with the code in coff_write_symbols and _bfd_coff_final_link.  */
3621
3
      if (bfd_coff_long_section_names (abfd))
3622
0
  {
3623
0
    size_t len;
3624
3625
0
    len = strlen (current->name);
3626
0
    if (len > SCNNMLEN)
3627
0
      {
3628
3629
        /* An inherent limitation of the /nnnnnnn notation used to indicate
3630
     the offset of the long name in the string table is that we
3631
     cannot address entries beyone the ten million byte boundary.  */
3632
0
        if (string_size < 10000000)
3633
0
    {
3634
      /* The s_name field is defined to be NUL-padded but need not
3635
         be NUL-terminated.  We use a temporary buffer so that we
3636
         can still sprintf all eight chars without splatting a
3637
         terminating NUL over the first byte of the following
3638
         member (s_paddr).  */
3639
      /* PR 21096: The +20 is to stop a bogus warning from gcc7
3640
         about a possible buffer overflow.  */
3641
0
      char s_name_buf[SCNNMLEN + 1 + 20];
3642
3643
      /* We do not need to use snprintf here as we have already
3644
         verified that string_size is not too big, plus we have
3645
         an overlarge buffer, just in case.  */
3646
0
      sprintf (s_name_buf, "/%lu", (unsigned long) string_size);
3647
      /* Then strncpy takes care of any padding for us.  */
3648
0
      strncpy (section.s_name, s_name_buf, SCNNMLEN);
3649
0
    }
3650
0
        else
3651
0
#ifdef COFF_WITH_PE
3652
0
    {
3653
      /* PE use a base 64 encoding for long section names whose
3654
         index is very large.  But contrary to RFC 4648, there is
3655
         no padding: 6 characters must be generated.  */
3656
0
      static const char base64[] =
3657
0
        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
3658
0
        "abcdefghijklmnopqrstuvwxyz"
3659
0
        "0123456789+/";
3660
0
      unsigned long off = string_size;
3661
0
      unsigned i;
3662
3663
0
      section.s_name[0] = '/';
3664
0
      section.s_name[1] = '/';
3665
0
      for (i = SCNNMLEN - 1; i >= 2; i--)
3666
0
        {
3667
0
          section.s_name[i] = base64[off & 0x3f];
3668
0
          off >>= 6;
3669
0
        }
3670
0
    }
3671
0
#endif
3672
0
        if (string_size > 0xffffffffUL - (len + 1)
3673
#ifndef COFF_WITH_PE
3674
      || string_size >= 10000000
3675
#endif
3676
0
      )
3677
0
    {
3678
0
      bfd_set_error (bfd_error_file_too_big);
3679
0
      _bfd_error_handler
3680
        /* xgettext:c-format */
3681
0
        (_("%pB: section %pA: string table overflow at offset %ld"),
3682
0
        abfd, current, (unsigned long) string_size);
3683
0
      return false;
3684
0
    }
3685
3686
0
        string_size += len + 1;
3687
0
        long_section_names = true;
3688
0
      }
3689
0
  }
3690
3
#endif
3691
3692
3
#ifdef _LIB
3693
      /* Always set s_vaddr of .lib to 0.  This is right for SVR3.2
3694
   Ian Taylor <ian@cygnus.com>.  */
3695
3
      if (strcmp (current->name, _LIB) == 0)
3696
0
  section.s_vaddr = 0;
3697
3
      else
3698
3
#endif
3699
3
      section.s_vaddr = current->vma;
3700
3
      section.s_paddr = current->lma;
3701
3
      section.s_size =  current->size;
3702
#ifdef coff_get_section_load_page
3703
      section.s_page = coff_get_section_load_page (current);
3704
#else
3705
3
      section.s_page = 0;
3706
3
#endif
3707
3708
3
#ifdef COFF_WITH_PE
3709
3
      section.s_paddr = 0;
3710
3
#endif
3711
3
#ifdef COFF_IMAGE_WITH_PE
3712
      /* Reminder: s_paddr holds the virtual size of the section.  */
3713
3
      if (coff_section_data (abfd, current) != NULL
3714
3
    && pei_section_data (abfd, current) != NULL)
3715
3
  section.s_paddr = pei_section_data (abfd, current)->virt_size;
3716
0
      else
3717
0
  section.s_paddr = 0;
3718
3
#endif
3719
3720
      /* If this section has no size or is unloadable then the scnptr
3721
   will be 0 too.  */
3722
3
      if (current->size == 0
3723
3
    || (current->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
3724
0
  section.s_scnptr = 0;
3725
3
      else
3726
3
  section.s_scnptr = current->filepos;
3727
3728
3
      section.s_relptr = current->rel_filepos;
3729
3
      section.s_lnnoptr = current->line_filepos;
3730
3
      section.s_nreloc = current->reloc_count;
3731
3
      section.s_nlnno = current->lineno_count;
3732
#ifndef COFF_IMAGE_WITH_PE
3733
      /* In PEI, relocs come in the .reloc section.  */
3734
      if (current->reloc_count != 0)
3735
  hasrelocs = true;
3736
#endif
3737
3
      if (current->lineno_count != 0)
3738
0
  haslinno = true;
3739
3
#ifdef COFF_IMAGE_WITH_PE
3740
3
      if ((current->flags & SEC_DEBUGGING) != 0
3741
3
    && ! is_reloc_section)
3742
0
  hasdebug = true;
3743
3
#endif
3744
3745
#ifdef RS6000COFF_C
3746
#ifndef XCOFF64
3747
      /* Indicate the use of an XCOFF overflow section header.  */
3748
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3749
  {
3750
    section.s_nreloc = 0xffff;
3751
    section.s_nlnno = 0xffff;
3752
  }
3753
#endif
3754
#endif
3755
3756
3
      section.s_flags = sec_to_styp_flags (current->name, current->flags);
3757
3758
3
      if (!strcmp (current->name, _TEXT))
3759
0
  text_sec = current;
3760
3
      else if (!strcmp (current->name, _DATA))
3761
0
  data_sec = current;
3762
3
      else if (!strcmp (current->name, _BSS))
3763
0
  bss_sec = current;
3764
#ifdef RS6000COFF_C
3765
      else if (!strcmp (current->name, _TDATA))
3766
  tdata_sec = current;
3767
      else if (!strcmp (current->name, _TBSS))
3768
  tbss_sec = current;
3769
#endif
3770
3771
3772
3
#ifdef COFF_ENCODE_ALIGNMENT
3773
3
      if (COFF_ENCODE_ALIGNMENT (abfd, section, current->alignment_power)
3774
3
    && (COFF_DECODE_ALIGNMENT (section.s_flags)
3775
0
        != current->alignment_power))
3776
0
  {
3777
0
    bool warn = (coff_data (abfd)->link_info
3778
0
           && !bfd_link_relocatable (coff_data (abfd)->link_info));
3779
3780
0
    _bfd_error_handler
3781
      /* xgettext:c-format */
3782
0
      (_("%pB:%s section %s: alignment 2**%u not representable"),
3783
0
       abfd, warn ? " warning:" : "", current->name,
3784
0
       current->alignment_power);
3785
0
    if (!warn)
3786
0
      {
3787
0
        bfd_set_error (bfd_error_nonrepresentable_section);
3788
0
        return false;
3789
0
      }
3790
0
  }
3791
3
#endif
3792
3793
3
#ifdef COFF_IMAGE_WITH_PE
3794
      /* Suppress output of the sections if they are null.  ld
3795
   includes the bss and data sections even if there is no size
3796
   assigned to them.  NT loader doesn't like it if these section
3797
   headers are included if the sections themselves are not
3798
   needed.  See also coff_compute_section_file_positions.  */
3799
3
      if (section.s_size == 0)
3800
0
  internal_f.f_nscns--;
3801
3
      else
3802
3
#endif
3803
3
  {
3804
3
    SCNHDR buff;
3805
3
    bfd_size_type amt = bfd_coff_scnhsz (abfd);
3806
3807
3
    if (bfd_coff_swap_scnhdr_out (abfd, &section, &buff) == 0
3808
3
        || bfd_write (& buff, amt, abfd) != amt)
3809
0
      return false;
3810
3
  }
3811
3812
3
#ifdef COFF_WITH_PE
3813
      /* PE stores COMDAT section information in the symbol table.  If
3814
   this section is supposed to have some COMDAT info, track down
3815
   the symbol in the symbol table and modify it.  */
3816
3
      if ((current->flags & SEC_LINK_ONCE) != 0)
3817
0
  {
3818
0
    unsigned int i, count;
3819
0
    asymbol **psym;
3820
0
    coff_symbol_type *csym = NULL;
3821
0
    asymbol **psymsec;
3822
3823
0
    psymsec = NULL;
3824
0
    count = bfd_get_symcount (abfd);
3825
0
    for (i = 0, psym = abfd->outsymbols; i < count; i++, psym++)
3826
0
      {
3827
0
        if ((*psym)->section != current)
3828
0
    continue;
3829
3830
        /* Remember the location of the first symbol in this
3831
     section.  */
3832
0
        if (psymsec == NULL)
3833
0
    psymsec = psym;
3834
3835
        /* See if this is the section symbol.  */
3836
0
        if (strcmp ((*psym)->name, current->name) == 0)
3837
0
    {
3838
0
      csym = coff_symbol_from (*psym);
3839
0
      if (csym == NULL
3840
0
          || csym->native == NULL
3841
0
          || ! csym->native->is_sym
3842
0
          || csym->native->u.syment.n_numaux < 1
3843
0
          || csym->native->u.syment.n_sclass != C_STAT
3844
0
          || csym->native->u.syment.n_type != T_NULL)
3845
0
        continue;
3846
3847
      /* Here *PSYM is the section symbol for CURRENT.  */
3848
3849
0
      break;
3850
0
    }
3851
0
      }
3852
3853
    /* Did we find it?
3854
       Note that we might not if we're converting the file from
3855
       some other object file format.  */
3856
0
    if (i < count)
3857
0
      {
3858
0
        combined_entry_type *aux;
3859
3860
        /* We don't touch the x_checksum field.  The
3861
     x_associated field is not currently supported.  */
3862
3863
0
        aux = csym->native + 1;
3864
0
        BFD_ASSERT (! aux->is_sym);
3865
0
        switch (current->flags & SEC_LINK_DUPLICATES)
3866
0
    {
3867
0
    case SEC_LINK_DUPLICATES_DISCARD:
3868
0
      aux->u.auxent.x_scn.x_comdat = IMAGE_COMDAT_SELECT_ANY;
3869
0
      break;
3870
3871
0
    case SEC_LINK_DUPLICATES_ONE_ONLY:
3872
0
      aux->u.auxent.x_scn.x_comdat =
3873
0
        IMAGE_COMDAT_SELECT_NODUPLICATES;
3874
0
      break;
3875
3876
0
    case SEC_LINK_DUPLICATES_SAME_SIZE:
3877
0
      aux->u.auxent.x_scn.x_comdat =
3878
0
        IMAGE_COMDAT_SELECT_SAME_SIZE;
3879
0
      break;
3880
3881
0
    case SEC_LINK_DUPLICATES_SAME_CONTENTS:
3882
0
      aux->u.auxent.x_scn.x_comdat =
3883
0
        IMAGE_COMDAT_SELECT_EXACT_MATCH;
3884
0
      break;
3885
0
    }
3886
3887
        /* The COMDAT symbol must be the first symbol from this
3888
     section in the symbol table.  In order to make this
3889
     work, we move the COMDAT symbol before the first
3890
     symbol we found in the search above.  It's OK to
3891
     rearrange the symbol table at this point, because
3892
     coff_renumber_symbols is going to rearrange it
3893
     further and fix up all the aux entries.  */
3894
0
        if (psym != psymsec)
3895
0
    {
3896
0
      asymbol *hold;
3897
0
      asymbol **pcopy;
3898
3899
0
      hold = *psym;
3900
0
      for (pcopy = psym; pcopy > psymsec; pcopy--)
3901
0
        pcopy[0] = pcopy[-1];
3902
0
      *psymsec = hold;
3903
0
    }
3904
0
      }
3905
0
  }
3906
3
#endif /* COFF_WITH_PE */
3907
3
    }
3908
3909
#ifdef RS6000COFF_C
3910
#ifndef XCOFF64
3911
  /* XCOFF handles overflows in the reloc and line number count fields
3912
     by creating a new section header to hold the correct values.  */
3913
  for (current = abfd->sections; current != NULL; current = current->next)
3914
    {
3915
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3916
  {
3917
    struct internal_scnhdr scnhdr;
3918
    SCNHDR buff;
3919
    bfd_size_type amt;
3920
3921
    internal_f.f_nscns++;
3922
    memcpy (scnhdr.s_name, ".ovrflo", 8);
3923
    scnhdr.s_paddr = current->reloc_count;
3924
    scnhdr.s_vaddr = current->lineno_count;
3925
    scnhdr.s_size = 0;
3926
    scnhdr.s_scnptr = 0;
3927
    scnhdr.s_relptr = current->rel_filepos;
3928
    scnhdr.s_lnnoptr = current->line_filepos;
3929
    scnhdr.s_nreloc = current->target_index;
3930
    scnhdr.s_nlnno = current->target_index;
3931
    scnhdr.s_flags = STYP_OVRFLO;
3932
    amt = bfd_coff_scnhsz (abfd);
3933
    if (bfd_coff_swap_scnhdr_out (abfd, &scnhdr, &buff) == 0
3934
        || bfd_write (& buff, amt, abfd) != amt)
3935
      return false;
3936
  }
3937
    }
3938
#endif
3939
#endif
3940
3941
#if defined (COFF_GO32_EXE) || defined (COFF_GO32)
3942
  /* Pad section headers.  */
3943
  if ((abfd->flags & EXEC_P) != 0)
3944
    {
3945
      asection *s = abfd->sections;
3946
      while (s != NULL && s->filepos == 0)
3947
  s = s->next;
3948
      if (s != NULL)
3949
  {
3950
    file_ptr cur_ptr
3951
      = scn_base + abfd->section_count * bfd_coff_scnhsz (abfd);
3952
    file_ptr fill_size = s->filepos - cur_ptr;
3953
    if (fill_size > 0)
3954
      {
3955
        bfd_byte *b = bfd_zmalloc (fill_size);
3956
        if (!b)
3957
    return false;
3958
        if (bfd_write (b, fill_size, abfd) != (ufile_ptr) fill_size)
3959
    {
3960
      free (b);
3961
      return false;
3962
    }
3963
        free (b);
3964
      }
3965
  }
3966
    }
3967
#endif
3968
3969
  /* OK, now set up the filehdr...  */
3970
3971
  /* Don't include the internal abs section in the section count */
3972
3973
  /* We will NOT put a fucking timestamp in the header here. Every time you
3974
     put it back, I will come in and take it out again.  I'm sorry.  This
3975
     field does not belong here.  We fill it with a 0 so it compares the
3976
     same but is not a reasonable time. -- gnu@cygnus.com  */
3977
4
  internal_f.f_timdat = 0;
3978
4
  internal_f.f_flags = 0;
3979
3980
4
  if (abfd->flags & EXEC_P)
3981
4
    internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3982
0
  else
3983
0
    {
3984
0
      internal_f.f_opthdr = 0;
3985
#ifdef RS6000COFF_C
3986
#ifndef XCOFF64
3987
      if (xcoff_data (abfd)->full_aouthdr)
3988
  internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3989
      else
3990
  internal_f.f_opthdr = SMALL_AOUTSZ;
3991
#endif
3992
#endif
3993
0
    }
3994
3995
4
  if (!hasrelocs)
3996
4
    internal_f.f_flags |= F_RELFLG;
3997
4
  if (!haslinno)
3998
4
    internal_f.f_flags |= F_LNNO;
3999
4
  if (abfd->flags & EXEC_P)
4000
4
    internal_f.f_flags |= F_EXEC;
4001
4
#ifdef COFF_IMAGE_WITH_PE
4002
4
  if (! hasdebug)
4003
4
    internal_f.f_flags |= IMAGE_FILE_DEBUG_STRIPPED;
4004
4
  if (pe_data (abfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
4005
2
    internal_f.f_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
4006
4
#endif
4007
4008
4
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64) && !defined (COFF_WITH_peRiscV64)
4009
4
#ifdef COFF_WITH_PE
4010
4
  internal_f.f_flags |= IMAGE_FILE_32BIT_MACHINE;
4011
#else
4012
  if (bfd_little_endian (abfd))
4013
    internal_f.f_flags |= F_AR32WR;
4014
  else
4015
    internal_f.f_flags |= F_AR32W;
4016
#endif
4017
4
#endif
4018
4019
#ifdef TI_TARGET_ID
4020
  /* Target id is used in TI COFF v1 and later; COFF0 won't use this field,
4021
     but it doesn't hurt to set it internally.  */
4022
  internal_f.f_target_id = TI_TARGET_ID;
4023
#endif
4024
4025
  /* FIXME, should do something about the other byte orders and
4026
     architectures.  */
4027
4028
#ifdef RS6000COFF_C
4029
  if ((abfd->flags & DYNAMIC) != 0)
4030
    internal_f.f_flags |= F_SHROBJ;
4031
  if (bfd_get_section_by_name (abfd, _LOADER) != NULL)
4032
    internal_f.f_flags |= F_DYNLOAD;
4033
#endif
4034
4035
4
  memset (&internal_a, 0, sizeof internal_a);
4036
4037
  /* Set up architecture-dependent stuff.  */
4038
4
  {
4039
4
    unsigned int magic = 0;
4040
4
    unsigned short flags = 0;
4041
4042
4
    coff_set_flags (abfd, &magic, &flags);
4043
4
    internal_f.f_magic = magic;
4044
4
    internal_f.f_flags |= flags;
4045
    /* ...and the "opt"hdr...  */
4046
4047
#ifdef TICOFF_AOUT_MAGIC
4048
    internal_a.magic = TICOFF_AOUT_MAGIC;
4049
#define __A_MAGIC_SET__
4050
#endif
4051
4052
#if defined(ARM)
4053
#define __A_MAGIC_SET__
4054
    internal_a.magic = ZMAGIC;
4055
#endif
4056
4057
#if defined(AARCH64)
4058
#define __A_MAGIC_SET__
4059
    internal_a.magic = ZMAGIC;
4060
#endif
4061
4062
#if defined(LOONGARCH64)
4063
#define __A_MAGIC_SET__
4064
    internal_a.magic = ZMAGIC;
4065
#endif
4066
4067
#if defined(RISCV64)
4068
#define __A_MAGIC_SET__
4069
    internal_a.magic = ZMAGIC;
4070
#endif
4071
4072
#if defined MCORE_PE
4073
#define __A_MAGIC_SET__
4074
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR_MAGIC;
4075
#endif
4076
4077
4
#if defined(I386)
4078
4
#define __A_MAGIC_SET__
4079
#if defined LYNXOS
4080
    internal_a.magic = LYNXCOFFMAGIC;
4081
#elif defined AMD64
4082
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR64_MAGIC;
4083
#else
4084
4
    internal_a.magic = ZMAGIC;
4085
4
#endif
4086
4
#endif /* I386 */
4087
4088
#if defined(IA64)
4089
#define __A_MAGIC_SET__
4090
    internal_a.magic = PE32PMAGIC;
4091
#endif /* IA64 */
4092
4093
#if defined(SPARC)
4094
#define __A_MAGIC_SET__
4095
#if defined(LYNXOS)
4096
    internal_a.magic = LYNXCOFFMAGIC;
4097
#endif /* LYNXOS */
4098
#endif /* SPARC */
4099
4100
#ifdef RS6000COFF_C
4101
#define __A_MAGIC_SET__
4102
    internal_a.magic = (abfd->flags & D_PAGED) ? RS6K_AOUTHDR_ZMAGIC :
4103
    (abfd->flags & WP_TEXT) ? RS6K_AOUTHDR_NMAGIC :
4104
    RS6K_AOUTHDR_OMAGIC;
4105
#endif
4106
4107
#if defined(SH) && defined(COFF_WITH_PE)
4108
#define __A_MAGIC_SET__
4109
    internal_a.magic = SH_PE_MAGIC;
4110
#endif
4111
4112
#if defined(MIPS) && defined(COFF_WITH_PE)
4113
#define __A_MAGIC_SET__
4114
    internal_a.magic = MIPS_PE_MAGIC;
4115
#endif
4116
4117
#ifndef __A_MAGIC_SET__
4118
#include "Your aouthdr magic number is not being set!"
4119
#else
4120
4
#undef __A_MAGIC_SET__
4121
4
#endif
4122
4
  }
4123
4124
#ifdef RS6000COFF_C
4125
  /* XCOFF 32bit needs this to have new behaviour for n_type field.  */
4126
  internal_a.vstamp = 2;
4127
#else
4128
  /* FIXME: Does anybody ever set this to another value?  */
4129
4
  internal_a.vstamp = 0;
4130
4
#endif
4131
4132
  /* Now should write relocs, strings, syms.  */
4133
4
  obj_sym_filepos (abfd) = sym_base;
4134
4135
4
  if (bfd_get_symcount (abfd) != 0)
4136
0
    {
4137
0
      int firstundef;
4138
4139
0
      if (!coff_renumber_symbols (abfd, &firstundef))
4140
0
  return false;
4141
0
      coff_mangle_symbols (abfd);
4142
0
      if (! coff_write_symbols (abfd))
4143
0
  return false;
4144
0
      if (! coff_write_linenumbers (abfd))
4145
0
  return false;
4146
0
      if (! coff_write_relocs (abfd, firstundef))
4147
0
  return false;
4148
0
    }
4149
4
#ifdef COFF_LONG_SECTION_NAMES
4150
4
  else if (long_section_names && ! obj_coff_strings_written (abfd))
4151
0
    {
4152
      /* If we have long section names we have to write out the string
4153
   table even if there are no symbols.  */
4154
0
      if (! coff_write_symbols (abfd))
4155
0
  return false;
4156
0
    }
4157
4
#endif
4158
  /* If bfd_get_symcount (abfd) != 0, then we are not using the COFF
4159
     backend linker, and obj_raw_syment_count is not valid until after
4160
     coff_write_symbols is called.  */
4161
4
  if (obj_raw_syment_count (abfd) != 0)
4162
0
    {
4163
0
      internal_f.f_symptr = sym_base;
4164
#ifdef RS6000COFF_C
4165
      /* AIX appears to require that F_RELFLG not be set if there are
4166
   local symbols but no relocations.  */
4167
      internal_f.f_flags &=~ F_RELFLG;
4168
#endif
4169
0
    }
4170
4
  else
4171
4
    {
4172
4
      if (long_section_names)
4173
0
  internal_f.f_symptr = sym_base;
4174
4
      else
4175
4
  internal_f.f_symptr = 0;
4176
4
      internal_f.f_flags |= F_LSYMS;
4177
4
    }
4178
4179
4
  if (text_sec)
4180
0
    {
4181
0
      internal_a.tsize = text_sec->size;
4182
0
      internal_a.text_start = internal_a.tsize ? text_sec->vma : 0;
4183
0
    }
4184
4
  if (data_sec)
4185
0
    {
4186
0
      internal_a.dsize = data_sec->size;
4187
0
      internal_a.data_start = internal_a.dsize ? data_sec->vma : 0;
4188
0
    }
4189
4
  if (bss_sec)
4190
0
    {
4191
0
      internal_a.bsize = bss_sec->size;
4192
0
      if (internal_a.bsize && bss_sec->vma < internal_a.data_start)
4193
0
  internal_a.data_start = bss_sec->vma;
4194
0
    }
4195
4196
4
  internal_a.entry = bfd_get_start_address (abfd);
4197
4
  internal_f.f_nsyms = obj_raw_syment_count (abfd);
4198
4199
#ifdef RS6000COFF_C
4200
  if (xcoff_data (abfd)->full_aouthdr)
4201
    {
4202
      bfd_vma toc;
4203
      asection *loader_sec;
4204
4205
      internal_a.vstamp = 2;
4206
4207
      internal_a.o_snentry = xcoff_data (abfd)->snentry;
4208
      if (internal_a.o_snentry == 0)
4209
  internal_a.entry = (bfd_vma) -1;
4210
4211
      if (text_sec != NULL)
4212
  {
4213
    internal_a.o_sntext = text_sec->target_index;
4214
    internal_a.o_algntext = bfd_section_alignment (text_sec);
4215
  }
4216
      else
4217
  {
4218
    internal_a.o_sntext = 0;
4219
    internal_a.o_algntext = 0;
4220
  }
4221
      if (data_sec != NULL)
4222
  {
4223
    internal_a.o_sndata = data_sec->target_index;
4224
    internal_a.o_algndata = bfd_section_alignment (data_sec);
4225
  }
4226
      else
4227
  {
4228
    internal_a.o_sndata = 0;
4229
    internal_a.o_algndata = 0;
4230
  }
4231
      loader_sec = bfd_get_section_by_name (abfd, ".loader");
4232
      if (loader_sec != NULL)
4233
  internal_a.o_snloader = loader_sec->target_index;
4234
      else
4235
  internal_a.o_snloader = 0;
4236
      if (bss_sec != NULL)
4237
  internal_a.o_snbss = bss_sec->target_index;
4238
      else
4239
  internal_a.o_snbss = 0;
4240
4241
      if (tdata_sec != NULL)
4242
  {
4243
    internal_a.o_sntdata = tdata_sec->target_index;
4244
    /* TODO: o_flags should be set to RS6K_AOUTHDR_TLS_LE
4245
       if there is at least one R_TLS_LE relocations.  */
4246
    internal_a.o_flags = 0;
4247
#ifdef XCOFF64
4248
    internal_a.o_x64flags = 0;
4249
#endif
4250
  }
4251
      else
4252
  {
4253
    internal_a.o_sntdata = 0;
4254
    internal_a.o_flags = 0;
4255
#ifdef XCOFF64
4256
    internal_a.o_x64flags = 0;
4257
#endif
4258
  }
4259
      if (tbss_sec != NULL)
4260
    internal_a.o_sntbss = tbss_sec->target_index;
4261
      else
4262
    internal_a.o_sntbss = 0;
4263
4264
      toc = xcoff_data (abfd)->toc;
4265
      internal_a.o_toc = toc;
4266
      internal_a.o_sntoc = xcoff_data (abfd)->sntoc;
4267
4268
      internal_a.o_modtype = xcoff_data (abfd)->modtype;
4269
      if (xcoff_data (abfd)->cputype != -1)
4270
  internal_a.o_cputype = xcoff_data (abfd)->cputype;
4271
      else
4272
  {
4273
    switch (bfd_get_arch (abfd))
4274
      {
4275
      case bfd_arch_rs6000:
4276
        internal_a.o_cputype = 4;
4277
        break;
4278
      case bfd_arch_powerpc:
4279
        if (bfd_get_mach (abfd) == bfd_mach_ppc)
4280
    internal_a.o_cputype = 3;
4281
        else if (bfd_get_mach (abfd) == bfd_mach_ppc_620)
4282
    internal_a.o_cputype = 2;
4283
        else
4284
    internal_a.o_cputype = 1;
4285
        break;
4286
      default:
4287
        abort ();
4288
      }
4289
  }
4290
      internal_a.o_maxstack = xcoff_data (abfd)->maxstack;
4291
      internal_a.o_maxdata = xcoff_data (abfd)->maxdata;
4292
    }
4293
#endif
4294
4295
4
#ifdef COFF_WITH_PE
4296
4
  {
4297
    /* After object contents are finalized so we can compute a reasonable hash,
4298
       but before header is written so we can update it to point to debug directory.  */
4299
4
    struct pe_tdata *pe = pe_data (abfd);
4300
4301
4
    if (pe->build_id.after_write_object_contents != NULL)
4302
0
      (*pe->build_id.after_write_object_contents) (abfd);
4303
4
  }
4304
4
#endif
4305
4306
  /* Now write header.  */
4307
4
  if (bfd_seek (abfd, 0, SEEK_SET) != 0)
4308
0
    return false;
4309
4310
4
  {
4311
4
    char * buff;
4312
4
    bfd_size_type amount = bfd_coff_filhsz (abfd);
4313
4314
4
    buff = (char *) bfd_malloc (amount);
4315
4
    if (buff == NULL)
4316
0
      return false;
4317
4318
4
    bfd_coff_swap_filehdr_out (abfd, & internal_f, buff);
4319
4
    amount = bfd_write (buff, amount, abfd);
4320
4321
4
    free (buff);
4322
4323
4
    if (amount != bfd_coff_filhsz (abfd))
4324
0
      return false;
4325
4
  }
4326
4327
4
  if (abfd->flags & EXEC_P)
4328
4
    {
4329
      /* Note that peicode.h fills in a PEAOUTHDR, not an AOUTHDR.
4330
   include/coff/pe.h sets AOUTSZ == sizeof (PEAOUTHDR)).  */
4331
4
      char * buff;
4332
4
      bfd_size_type amount = bfd_coff_aoutsz (abfd);
4333
4334
4
      buff = (char *) bfd_malloc (amount);
4335
4
      if (buff == NULL)
4336
0
  return false;
4337
4338
4
      coff_swap_aouthdr_out (abfd, & internal_a, buff);
4339
4
      amount = bfd_write (buff, amount, abfd);
4340
4341
4
      free (buff);
4342
4343
4
      if (amount != bfd_coff_aoutsz (abfd))
4344
0
  return false;
4345
4346
4
#ifdef COFF_IMAGE_WITH_PE
4347
4
      if (! coff_apply_checksum (abfd))
4348
0
  return false;
4349
4
#endif
4350
4
    }
4351
#ifdef RS6000COFF_C
4352
#ifndef XCOFF64
4353
  else
4354
    {
4355
      AOUTHDR buff;
4356
      size_t size;
4357
4358
      /* XCOFF32 seems to always write at least a small a.out header.  */
4359
      coff_swap_aouthdr_out (abfd, & internal_a, & buff);
4360
      if (xcoff_data (abfd)->full_aouthdr)
4361
  size = bfd_coff_aoutsz (abfd);
4362
      else
4363
  size = SMALL_AOUTSZ;
4364
      if (bfd_write (&buff, size, abfd) != size)
4365
  return false;
4366
    }
4367
#endif
4368
#endif
4369
4370
4
  return true;
4371
4
}
Unexecuted instantiation: pe-x86_64.c:coff_write_object_contents
pei-x86_64.c:coff_write_object_contents
Line
Count
Source
3490
3
{
3491
3
  asection *current;
3492
3
  bool hasrelocs = false;
3493
3
  bool haslinno = false;
3494
3
#ifdef COFF_IMAGE_WITH_PE
3495
3
  bool hasdebug = false;
3496
3
#endif
3497
3
  file_ptr scn_base;
3498
3
  file_ptr reloc_base;
3499
3
  file_ptr lineno_base;
3500
3
  file_ptr sym_base;
3501
3
  unsigned long reloc_size = 0, reloc_count = 0;
3502
3
  unsigned long lnno_size = 0;
3503
3
  bool long_section_names;
3504
3
  asection *text_sec = NULL;
3505
3
  asection *data_sec = NULL;
3506
3
  asection *bss_sec = NULL;
3507
#ifdef RS6000COFF_C
3508
  asection *tdata_sec = NULL;
3509
  asection *tbss_sec = NULL;
3510
#endif
3511
3
  struct internal_filehdr internal_f;
3512
3
  struct internal_aouthdr internal_a;
3513
3
#ifdef COFF_LONG_SECTION_NAMES
3514
3
  size_t string_size = STRING_SIZE_SIZE;
3515
3
#endif
3516
3517
3
  bfd_set_error (bfd_error_system_call);
3518
3519
  /* Make a pass through the symbol table to count line number entries and
3520
     put them into the correct asections.  */
3521
3
  lnno_size = coff_count_linenumbers (abfd) * bfd_coff_linesz (abfd);
3522
3523
3
  if (! abfd->output_has_begun)
3524
0
    {
3525
0
      if (! coff_compute_section_file_positions (abfd))
3526
0
  return false;
3527
0
    }
3528
3529
3
  reloc_base = obj_relocbase (abfd);
3530
3531
  /* Work out the size of the reloc and linno areas.  */
3532
3533
32
  for (current = abfd->sections; current != NULL; current =
3534
29
       current->next)
3535
29
    {
3536
29
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3537
      /* We store the actual reloc count in the first reloc's addr.  */
3538
29
      if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3539
0
  reloc_count ++;
3540
29
#endif
3541
29
      reloc_count += current->reloc_count;
3542
29
    }
3543
3544
3
  reloc_size = reloc_count * bfd_coff_relsz (abfd);
3545
3546
3
  lineno_base = reloc_base + reloc_size;
3547
3
  sym_base = lineno_base + lnno_size;
3548
3549
  /* Indicate in each section->line_filepos its actual file address.  */
3550
32
  for (current = abfd->sections; current != NULL; current =
3551
29
       current->next)
3552
29
    {
3553
29
      if (current->lineno_count)
3554
0
  {
3555
0
    current->line_filepos = lineno_base;
3556
0
    current->moving_line_filepos = lineno_base;
3557
0
    lineno_base += current->lineno_count * bfd_coff_linesz (abfd);
3558
0
  }
3559
29
      else
3560
29
  current->line_filepos = 0;
3561
3562
29
      if (current->reloc_count)
3563
0
  {
3564
0
    current->rel_filepos = reloc_base;
3565
0
    reloc_base += current->reloc_count * bfd_coff_relsz (abfd);
3566
0
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3567
    /* Extra reloc to hold real count.  */
3568
0
    if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3569
0
      reloc_base += bfd_coff_relsz (abfd);
3570
0
#endif
3571
0
  }
3572
29
      else
3573
29
  current->rel_filepos = 0;
3574
29
    }
3575
3576
  /* Write section headers to the file.  */
3577
3
  internal_f.f_nscns = 0;
3578
3579
3
  if ((abfd->flags & EXEC_P) != 0)
3580
3
    scn_base = bfd_coff_filhsz (abfd) + bfd_coff_aoutsz (abfd);
3581
0
  else
3582
0
    {
3583
0
      scn_base = bfd_coff_filhsz (abfd);
3584
#ifdef RS6000COFF_C
3585
#ifndef XCOFF64
3586
      if (xcoff_data (abfd)->full_aouthdr)
3587
  scn_base += bfd_coff_aoutsz (abfd);
3588
      else
3589
  scn_base += SMALL_AOUTSZ;
3590
#endif
3591
#endif
3592
0
    }
3593
3594
3
  if (bfd_seek (abfd, scn_base, SEEK_SET) != 0)
3595
0
    return false;
3596
3597
3
  long_section_names = false;
3598
3
  for (current = abfd->sections;
3599
32
       current != NULL;
3600
29
       current = current->next)
3601
29
    {
3602
29
      struct internal_scnhdr section;
3603
29
#ifdef COFF_IMAGE_WITH_PE
3604
29
      bool is_reloc_section = false;
3605
3606
29
      if (strcmp (current->name, DOT_RELOC) == 0)
3607
2
  {
3608
2
    is_reloc_section = true;
3609
2
    hasrelocs = true;
3610
2
    pe_data (abfd)->has_reloc_section = 1;
3611
2
  }
3612
29
#endif
3613
3614
29
      internal_f.f_nscns++;
3615
3616
29
      strncpy (section.s_name, current->name, SCNNMLEN);
3617
3618
29
#ifdef COFF_LONG_SECTION_NAMES
3619
      /* Handle long section names as in PE.  This must be compatible
3620
   with the code in coff_write_symbols and _bfd_coff_final_link.  */
3621
29
      if (bfd_coff_long_section_names (abfd))
3622
23
  {
3623
23
    size_t len;
3624
3625
23
    len = strlen (current->name);
3626
23
    if (len > SCNNMLEN)
3627
11
      {
3628
3629
        /* An inherent limitation of the /nnnnnnn notation used to indicate
3630
     the offset of the long name in the string table is that we
3631
     cannot address entries beyone the ten million byte boundary.  */
3632
11
        if (string_size < 10000000)
3633
11
    {
3634
      /* The s_name field is defined to be NUL-padded but need not
3635
         be NUL-terminated.  We use a temporary buffer so that we
3636
         can still sprintf all eight chars without splatting a
3637
         terminating NUL over the first byte of the following
3638
         member (s_paddr).  */
3639
      /* PR 21096: The +20 is to stop a bogus warning from gcc7
3640
         about a possible buffer overflow.  */
3641
11
      char s_name_buf[SCNNMLEN + 1 + 20];
3642
3643
      /* We do not need to use snprintf here as we have already
3644
         verified that string_size is not too big, plus we have
3645
         an overlarge buffer, just in case.  */
3646
11
      sprintf (s_name_buf, "/%lu", (unsigned long) string_size);
3647
      /* Then strncpy takes care of any padding for us.  */
3648
11
      strncpy (section.s_name, s_name_buf, SCNNMLEN);
3649
11
    }
3650
0
        else
3651
0
#ifdef COFF_WITH_PE
3652
0
    {
3653
      /* PE use a base 64 encoding for long section names whose
3654
         index is very large.  But contrary to RFC 4648, there is
3655
         no padding: 6 characters must be generated.  */
3656
0
      static const char base64[] =
3657
0
        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
3658
0
        "abcdefghijklmnopqrstuvwxyz"
3659
0
        "0123456789+/";
3660
0
      unsigned long off = string_size;
3661
0
      unsigned i;
3662
3663
0
      section.s_name[0] = '/';
3664
0
      section.s_name[1] = '/';
3665
0
      for (i = SCNNMLEN - 1; i >= 2; i--)
3666
0
        {
3667
0
          section.s_name[i] = base64[off & 0x3f];
3668
0
          off >>= 6;
3669
0
        }
3670
0
    }
3671
11
#endif
3672
11
        if (string_size > 0xffffffffUL - (len + 1)
3673
#ifndef COFF_WITH_PE
3674
      || string_size >= 10000000
3675
#endif
3676
11
      )
3677
0
    {
3678
0
      bfd_set_error (bfd_error_file_too_big);
3679
0
      _bfd_error_handler
3680
        /* xgettext:c-format */
3681
0
        (_("%pB: section %pA: string table overflow at offset %ld"),
3682
0
        abfd, current, (unsigned long) string_size);
3683
0
      return false;
3684
0
    }
3685
3686
11
        string_size += len + 1;
3687
11
        long_section_names = true;
3688
11
      }
3689
23
  }
3690
29
#endif
3691
3692
29
#ifdef _LIB
3693
      /* Always set s_vaddr of .lib to 0.  This is right for SVR3.2
3694
   Ian Taylor <ian@cygnus.com>.  */
3695
29
      if (strcmp (current->name, _LIB) == 0)
3696
0
  section.s_vaddr = 0;
3697
29
      else
3698
29
#endif
3699
29
      section.s_vaddr = current->vma;
3700
29
      section.s_paddr = current->lma;
3701
29
      section.s_size =  current->size;
3702
#ifdef coff_get_section_load_page
3703
      section.s_page = coff_get_section_load_page (current);
3704
#else
3705
29
      section.s_page = 0;
3706
29
#endif
3707
3708
29
#ifdef COFF_WITH_PE
3709
29
      section.s_paddr = 0;
3710
29
#endif
3711
29
#ifdef COFF_IMAGE_WITH_PE
3712
      /* Reminder: s_paddr holds the virtual size of the section.  */
3713
29
      if (coff_section_data (abfd, current) != NULL
3714
29
    && pei_section_data (abfd, current) != NULL)
3715
29
  section.s_paddr = pei_section_data (abfd, current)->virt_size;
3716
0
      else
3717
0
  section.s_paddr = 0;
3718
29
#endif
3719
3720
      /* If this section has no size or is unloadable then the scnptr
3721
   will be 0 too.  */
3722
29
      if (current->size == 0
3723
29
    || (current->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
3724
1
  section.s_scnptr = 0;
3725
28
      else
3726
28
  section.s_scnptr = current->filepos;
3727
3728
29
      section.s_relptr = current->rel_filepos;
3729
29
      section.s_lnnoptr = current->line_filepos;
3730
29
      section.s_nreloc = current->reloc_count;
3731
29
      section.s_nlnno = current->lineno_count;
3732
#ifndef COFF_IMAGE_WITH_PE
3733
      /* In PEI, relocs come in the .reloc section.  */
3734
      if (current->reloc_count != 0)
3735
  hasrelocs = true;
3736
#endif
3737
29
      if (current->lineno_count != 0)
3738
0
  haslinno = true;
3739
29
#ifdef COFF_IMAGE_WITH_PE
3740
29
      if ((current->flags & SEC_DEBUGGING) != 0
3741
29
    && ! is_reloc_section)
3742
13
  hasdebug = true;
3743
29
#endif
3744
3745
#ifdef RS6000COFF_C
3746
#ifndef XCOFF64
3747
      /* Indicate the use of an XCOFF overflow section header.  */
3748
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3749
  {
3750
    section.s_nreloc = 0xffff;
3751
    section.s_nlnno = 0xffff;
3752
  }
3753
#endif
3754
#endif
3755
3756
29
      section.s_flags = sec_to_styp_flags (current->name, current->flags);
3757
3758
29
      if (!strcmp (current->name, _TEXT))
3759
2
  text_sec = current;
3760
27
      else if (!strcmp (current->name, _DATA))
3761
2
  data_sec = current;
3762
25
      else if (!strcmp (current->name, _BSS))
3763
1
  bss_sec = current;
3764
#ifdef RS6000COFF_C
3765
      else if (!strcmp (current->name, _TDATA))
3766
  tdata_sec = current;
3767
      else if (!strcmp (current->name, _TBSS))
3768
  tbss_sec = current;
3769
#endif
3770
3771
3772
29
#ifdef COFF_ENCODE_ALIGNMENT
3773
29
      if (COFF_ENCODE_ALIGNMENT (abfd, section, current->alignment_power)
3774
29
    && (COFF_DECODE_ALIGNMENT (section.s_flags)
3775
0
        != current->alignment_power))
3776
0
  {
3777
0
    bool warn = (coff_data (abfd)->link_info
3778
0
           && !bfd_link_relocatable (coff_data (abfd)->link_info));
3779
3780
0
    _bfd_error_handler
3781
      /* xgettext:c-format */
3782
0
      (_("%pB:%s section %s: alignment 2**%u not representable"),
3783
0
       abfd, warn ? " warning:" : "", current->name,
3784
0
       current->alignment_power);
3785
0
    if (!warn)
3786
0
      {
3787
0
        bfd_set_error (bfd_error_nonrepresentable_section);
3788
0
        return false;
3789
0
      }
3790
0
  }
3791
29
#endif
3792
3793
29
#ifdef COFF_IMAGE_WITH_PE
3794
      /* Suppress output of the sections if they are null.  ld
3795
   includes the bss and data sections even if there is no size
3796
   assigned to them.  NT loader doesn't like it if these section
3797
   headers are included if the sections themselves are not
3798
   needed.  See also coff_compute_section_file_positions.  */
3799
29
      if (section.s_size == 0)
3800
0
  internal_f.f_nscns--;
3801
29
      else
3802
29
#endif
3803
29
  {
3804
29
    SCNHDR buff;
3805
29
    bfd_size_type amt = bfd_coff_scnhsz (abfd);
3806
3807
29
    if (bfd_coff_swap_scnhdr_out (abfd, &section, &buff) == 0
3808
29
        || bfd_write (& buff, amt, abfd) != amt)
3809
0
      return false;
3810
29
  }
3811
3812
29
#ifdef COFF_WITH_PE
3813
      /* PE stores COMDAT section information in the symbol table.  If
3814
   this section is supposed to have some COMDAT info, track down
3815
   the symbol in the symbol table and modify it.  */
3816
29
      if ((current->flags & SEC_LINK_ONCE) != 0)
3817
0
  {
3818
0
    unsigned int i, count;
3819
0
    asymbol **psym;
3820
0
    coff_symbol_type *csym = NULL;
3821
0
    asymbol **psymsec;
3822
3823
0
    psymsec = NULL;
3824
0
    count = bfd_get_symcount (abfd);
3825
0
    for (i = 0, psym = abfd->outsymbols; i < count; i++, psym++)
3826
0
      {
3827
0
        if ((*psym)->section != current)
3828
0
    continue;
3829
3830
        /* Remember the location of the first symbol in this
3831
     section.  */
3832
0
        if (psymsec == NULL)
3833
0
    psymsec = psym;
3834
3835
        /* See if this is the section symbol.  */
3836
0
        if (strcmp ((*psym)->name, current->name) == 0)
3837
0
    {
3838
0
      csym = coff_symbol_from (*psym);
3839
0
      if (csym == NULL
3840
0
          || csym->native == NULL
3841
0
          || ! csym->native->is_sym
3842
0
          || csym->native->u.syment.n_numaux < 1
3843
0
          || csym->native->u.syment.n_sclass != C_STAT
3844
0
          || csym->native->u.syment.n_type != T_NULL)
3845
0
        continue;
3846
3847
      /* Here *PSYM is the section symbol for CURRENT.  */
3848
3849
0
      break;
3850
0
    }
3851
0
      }
3852
3853
    /* Did we find it?
3854
       Note that we might not if we're converting the file from
3855
       some other object file format.  */
3856
0
    if (i < count)
3857
0
      {
3858
0
        combined_entry_type *aux;
3859
3860
        /* We don't touch the x_checksum field.  The
3861
     x_associated field is not currently supported.  */
3862
3863
0
        aux = csym->native + 1;
3864
0
        BFD_ASSERT (! aux->is_sym);
3865
0
        switch (current->flags & SEC_LINK_DUPLICATES)
3866
0
    {
3867
0
    case SEC_LINK_DUPLICATES_DISCARD:
3868
0
      aux->u.auxent.x_scn.x_comdat = IMAGE_COMDAT_SELECT_ANY;
3869
0
      break;
3870
3871
0
    case SEC_LINK_DUPLICATES_ONE_ONLY:
3872
0
      aux->u.auxent.x_scn.x_comdat =
3873
0
        IMAGE_COMDAT_SELECT_NODUPLICATES;
3874
0
      break;
3875
3876
0
    case SEC_LINK_DUPLICATES_SAME_SIZE:
3877
0
      aux->u.auxent.x_scn.x_comdat =
3878
0
        IMAGE_COMDAT_SELECT_SAME_SIZE;
3879
0
      break;
3880
3881
0
    case SEC_LINK_DUPLICATES_SAME_CONTENTS:
3882
0
      aux->u.auxent.x_scn.x_comdat =
3883
0
        IMAGE_COMDAT_SELECT_EXACT_MATCH;
3884
0
      break;
3885
0
    }
3886
3887
        /* The COMDAT symbol must be the first symbol from this
3888
     section in the symbol table.  In order to make this
3889
     work, we move the COMDAT symbol before the first
3890
     symbol we found in the search above.  It's OK to
3891
     rearrange the symbol table at this point, because
3892
     coff_renumber_symbols is going to rearrange it
3893
     further and fix up all the aux entries.  */
3894
0
        if (psym != psymsec)
3895
0
    {
3896
0
      asymbol *hold;
3897
0
      asymbol **pcopy;
3898
3899
0
      hold = *psym;
3900
0
      for (pcopy = psym; pcopy > psymsec; pcopy--)
3901
0
        pcopy[0] = pcopy[-1];
3902
0
      *psymsec = hold;
3903
0
    }
3904
0
      }
3905
0
  }
3906
29
#endif /* COFF_WITH_PE */
3907
29
    }
3908
3909
#ifdef RS6000COFF_C
3910
#ifndef XCOFF64
3911
  /* XCOFF handles overflows in the reloc and line number count fields
3912
     by creating a new section header to hold the correct values.  */
3913
  for (current = abfd->sections; current != NULL; current = current->next)
3914
    {
3915
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3916
  {
3917
    struct internal_scnhdr scnhdr;
3918
    SCNHDR buff;
3919
    bfd_size_type amt;
3920
3921
    internal_f.f_nscns++;
3922
    memcpy (scnhdr.s_name, ".ovrflo", 8);
3923
    scnhdr.s_paddr = current->reloc_count;
3924
    scnhdr.s_vaddr = current->lineno_count;
3925
    scnhdr.s_size = 0;
3926
    scnhdr.s_scnptr = 0;
3927
    scnhdr.s_relptr = current->rel_filepos;
3928
    scnhdr.s_lnnoptr = current->line_filepos;
3929
    scnhdr.s_nreloc = current->target_index;
3930
    scnhdr.s_nlnno = current->target_index;
3931
    scnhdr.s_flags = STYP_OVRFLO;
3932
    amt = bfd_coff_scnhsz (abfd);
3933
    if (bfd_coff_swap_scnhdr_out (abfd, &scnhdr, &buff) == 0
3934
        || bfd_write (& buff, amt, abfd) != amt)
3935
      return false;
3936
  }
3937
    }
3938
#endif
3939
#endif
3940
3941
#if defined (COFF_GO32_EXE) || defined (COFF_GO32)
3942
  /* Pad section headers.  */
3943
  if ((abfd->flags & EXEC_P) != 0)
3944
    {
3945
      asection *s = abfd->sections;
3946
      while (s != NULL && s->filepos == 0)
3947
  s = s->next;
3948
      if (s != NULL)
3949
  {
3950
    file_ptr cur_ptr
3951
      = scn_base + abfd->section_count * bfd_coff_scnhsz (abfd);
3952
    file_ptr fill_size = s->filepos - cur_ptr;
3953
    if (fill_size > 0)
3954
      {
3955
        bfd_byte *b = bfd_zmalloc (fill_size);
3956
        if (!b)
3957
    return false;
3958
        if (bfd_write (b, fill_size, abfd) != (ufile_ptr) fill_size)
3959
    {
3960
      free (b);
3961
      return false;
3962
    }
3963
        free (b);
3964
      }
3965
  }
3966
    }
3967
#endif
3968
3969
  /* OK, now set up the filehdr...  */
3970
3971
  /* Don't include the internal abs section in the section count */
3972
3973
  /* We will NOT put a fucking timestamp in the header here. Every time you
3974
     put it back, I will come in and take it out again.  I'm sorry.  This
3975
     field does not belong here.  We fill it with a 0 so it compares the
3976
     same but is not a reasonable time. -- gnu@cygnus.com  */
3977
3
  internal_f.f_timdat = 0;
3978
3
  internal_f.f_flags = 0;
3979
3980
3
  if (abfd->flags & EXEC_P)
3981
3
    internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3982
0
  else
3983
0
    {
3984
0
      internal_f.f_opthdr = 0;
3985
#ifdef RS6000COFF_C
3986
#ifndef XCOFF64
3987
      if (xcoff_data (abfd)->full_aouthdr)
3988
  internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3989
      else
3990
  internal_f.f_opthdr = SMALL_AOUTSZ;
3991
#endif
3992
#endif
3993
0
    }
3994
3995
3
  if (!hasrelocs)
3996
1
    internal_f.f_flags |= F_RELFLG;
3997
3
  if (!haslinno)
3998
3
    internal_f.f_flags |= F_LNNO;
3999
3
  if (abfd->flags & EXEC_P)
4000
3
    internal_f.f_flags |= F_EXEC;
4001
3
#ifdef COFF_IMAGE_WITH_PE
4002
3
  if (! hasdebug)
4003
1
    internal_f.f_flags |= IMAGE_FILE_DEBUG_STRIPPED;
4004
3
  if (pe_data (abfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
4005
3
    internal_f.f_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
4006
3
#endif
4007
4008
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64) && !defined (COFF_WITH_peRiscV64)
4009
#ifdef COFF_WITH_PE
4010
  internal_f.f_flags |= IMAGE_FILE_32BIT_MACHINE;
4011
#else
4012
  if (bfd_little_endian (abfd))
4013
    internal_f.f_flags |= F_AR32WR;
4014
  else
4015
    internal_f.f_flags |= F_AR32W;
4016
#endif
4017
#endif
4018
4019
#ifdef TI_TARGET_ID
4020
  /* Target id is used in TI COFF v1 and later; COFF0 won't use this field,
4021
     but it doesn't hurt to set it internally.  */
4022
  internal_f.f_target_id = TI_TARGET_ID;
4023
#endif
4024
4025
  /* FIXME, should do something about the other byte orders and
4026
     architectures.  */
4027
4028
#ifdef RS6000COFF_C
4029
  if ((abfd->flags & DYNAMIC) != 0)
4030
    internal_f.f_flags |= F_SHROBJ;
4031
  if (bfd_get_section_by_name (abfd, _LOADER) != NULL)
4032
    internal_f.f_flags |= F_DYNLOAD;
4033
#endif
4034
4035
3
  memset (&internal_a, 0, sizeof internal_a);
4036
4037
  /* Set up architecture-dependent stuff.  */
4038
3
  {
4039
3
    unsigned int magic = 0;
4040
3
    unsigned short flags = 0;
4041
4042
3
    coff_set_flags (abfd, &magic, &flags);
4043
3
    internal_f.f_magic = magic;
4044
3
    internal_f.f_flags |= flags;
4045
    /* ...and the "opt"hdr...  */
4046
4047
#ifdef TICOFF_AOUT_MAGIC
4048
    internal_a.magic = TICOFF_AOUT_MAGIC;
4049
#define __A_MAGIC_SET__
4050
#endif
4051
4052
#if defined(ARM)
4053
#define __A_MAGIC_SET__
4054
    internal_a.magic = ZMAGIC;
4055
#endif
4056
4057
#if defined(AARCH64)
4058
#define __A_MAGIC_SET__
4059
    internal_a.magic = ZMAGIC;
4060
#endif
4061
4062
#if defined(LOONGARCH64)
4063
#define __A_MAGIC_SET__
4064
    internal_a.magic = ZMAGIC;
4065
#endif
4066
4067
#if defined(RISCV64)
4068
#define __A_MAGIC_SET__
4069
    internal_a.magic = ZMAGIC;
4070
#endif
4071
4072
#if defined MCORE_PE
4073
#define __A_MAGIC_SET__
4074
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR_MAGIC;
4075
#endif
4076
4077
3
#if defined(I386)
4078
3
#define __A_MAGIC_SET__
4079
#if defined LYNXOS
4080
    internal_a.magic = LYNXCOFFMAGIC;
4081
#elif defined AMD64
4082
3
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR64_MAGIC;
4083
#else
4084
    internal_a.magic = ZMAGIC;
4085
#endif
4086
3
#endif /* I386 */
4087
4088
#if defined(IA64)
4089
#define __A_MAGIC_SET__
4090
    internal_a.magic = PE32PMAGIC;
4091
#endif /* IA64 */
4092
4093
#if defined(SPARC)
4094
#define __A_MAGIC_SET__
4095
#if defined(LYNXOS)
4096
    internal_a.magic = LYNXCOFFMAGIC;
4097
#endif /* LYNXOS */
4098
#endif /* SPARC */
4099
4100
#ifdef RS6000COFF_C
4101
#define __A_MAGIC_SET__
4102
    internal_a.magic = (abfd->flags & D_PAGED) ? RS6K_AOUTHDR_ZMAGIC :
4103
    (abfd->flags & WP_TEXT) ? RS6K_AOUTHDR_NMAGIC :
4104
    RS6K_AOUTHDR_OMAGIC;
4105
#endif
4106
4107
#if defined(SH) && defined(COFF_WITH_PE)
4108
#define __A_MAGIC_SET__
4109
    internal_a.magic = SH_PE_MAGIC;
4110
#endif
4111
4112
#if defined(MIPS) && defined(COFF_WITH_PE)
4113
#define __A_MAGIC_SET__
4114
    internal_a.magic = MIPS_PE_MAGIC;
4115
#endif
4116
4117
#ifndef __A_MAGIC_SET__
4118
#include "Your aouthdr magic number is not being set!"
4119
#else
4120
3
#undef __A_MAGIC_SET__
4121
3
#endif
4122
3
  }
4123
4124
#ifdef RS6000COFF_C
4125
  /* XCOFF 32bit needs this to have new behaviour for n_type field.  */
4126
  internal_a.vstamp = 2;
4127
#else
4128
  /* FIXME: Does anybody ever set this to another value?  */
4129
3
  internal_a.vstamp = 0;
4130
3
#endif
4131
4132
  /* Now should write relocs, strings, syms.  */
4133
3
  obj_sym_filepos (abfd) = sym_base;
4134
4135
3
  if (bfd_get_symcount (abfd) != 0)
4136
1
    {
4137
1
      int firstundef;
4138
4139
1
      if (!coff_renumber_symbols (abfd, &firstundef))
4140
0
  return false;
4141
1
      coff_mangle_symbols (abfd);
4142
1
      if (! coff_write_symbols (abfd))
4143
0
  return false;
4144
1
      if (! coff_write_linenumbers (abfd))
4145
0
  return false;
4146
1
      if (! coff_write_relocs (abfd, firstundef))
4147
0
  return false;
4148
1
    }
4149
2
#ifdef COFF_LONG_SECTION_NAMES
4150
2
  else if (long_section_names && ! obj_coff_strings_written (abfd))
4151
0
    {
4152
      /* If we have long section names we have to write out the string
4153
   table even if there are no symbols.  */
4154
0
      if (! coff_write_symbols (abfd))
4155
0
  return false;
4156
0
    }
4157
3
#endif
4158
  /* If bfd_get_symcount (abfd) != 0, then we are not using the COFF
4159
     backend linker, and obj_raw_syment_count is not valid until after
4160
     coff_write_symbols is called.  */
4161
3
  if (obj_raw_syment_count (abfd) != 0)
4162
1
    {
4163
1
      internal_f.f_symptr = sym_base;
4164
#ifdef RS6000COFF_C
4165
      /* AIX appears to require that F_RELFLG not be set if there are
4166
   local symbols but no relocations.  */
4167
      internal_f.f_flags &=~ F_RELFLG;
4168
#endif
4169
1
    }
4170
2
  else
4171
2
    {
4172
2
      if (long_section_names)
4173
0
  internal_f.f_symptr = sym_base;
4174
2
      else
4175
2
  internal_f.f_symptr = 0;
4176
2
      internal_f.f_flags |= F_LSYMS;
4177
2
    }
4178
4179
3
  if (text_sec)
4180
2
    {
4181
2
      internal_a.tsize = text_sec->size;
4182
2
      internal_a.text_start = internal_a.tsize ? text_sec->vma : 0;
4183
2
    }
4184
3
  if (data_sec)
4185
2
    {
4186
2
      internal_a.dsize = data_sec->size;
4187
2
      internal_a.data_start = internal_a.dsize ? data_sec->vma : 0;
4188
2
    }
4189
3
  if (bss_sec)
4190
1
    {
4191
1
      internal_a.bsize = bss_sec->size;
4192
1
      if (internal_a.bsize && bss_sec->vma < internal_a.data_start)
4193
0
  internal_a.data_start = bss_sec->vma;
4194
1
    }
4195
4196
3
  internal_a.entry = bfd_get_start_address (abfd);
4197
3
  internal_f.f_nsyms = obj_raw_syment_count (abfd);
4198
4199
#ifdef RS6000COFF_C
4200
  if (xcoff_data (abfd)->full_aouthdr)
4201
    {
4202
      bfd_vma toc;
4203
      asection *loader_sec;
4204
4205
      internal_a.vstamp = 2;
4206
4207
      internal_a.o_snentry = xcoff_data (abfd)->snentry;
4208
      if (internal_a.o_snentry == 0)
4209
  internal_a.entry = (bfd_vma) -1;
4210
4211
      if (text_sec != NULL)
4212
  {
4213
    internal_a.o_sntext = text_sec->target_index;
4214
    internal_a.o_algntext = bfd_section_alignment (text_sec);
4215
  }
4216
      else
4217
  {
4218
    internal_a.o_sntext = 0;
4219
    internal_a.o_algntext = 0;
4220
  }
4221
      if (data_sec != NULL)
4222
  {
4223
    internal_a.o_sndata = data_sec->target_index;
4224
    internal_a.o_algndata = bfd_section_alignment (data_sec);
4225
  }
4226
      else
4227
  {
4228
    internal_a.o_sndata = 0;
4229
    internal_a.o_algndata = 0;
4230
  }
4231
      loader_sec = bfd_get_section_by_name (abfd, ".loader");
4232
      if (loader_sec != NULL)
4233
  internal_a.o_snloader = loader_sec->target_index;
4234
      else
4235
  internal_a.o_snloader = 0;
4236
      if (bss_sec != NULL)
4237
  internal_a.o_snbss = bss_sec->target_index;
4238
      else
4239
  internal_a.o_snbss = 0;
4240
4241
      if (tdata_sec != NULL)
4242
  {
4243
    internal_a.o_sntdata = tdata_sec->target_index;
4244
    /* TODO: o_flags should be set to RS6K_AOUTHDR_TLS_LE
4245
       if there is at least one R_TLS_LE relocations.  */
4246
    internal_a.o_flags = 0;
4247
#ifdef XCOFF64
4248
    internal_a.o_x64flags = 0;
4249
#endif
4250
  }
4251
      else
4252
  {
4253
    internal_a.o_sntdata = 0;
4254
    internal_a.o_flags = 0;
4255
#ifdef XCOFF64
4256
    internal_a.o_x64flags = 0;
4257
#endif
4258
  }
4259
      if (tbss_sec != NULL)
4260
    internal_a.o_sntbss = tbss_sec->target_index;
4261
      else
4262
    internal_a.o_sntbss = 0;
4263
4264
      toc = xcoff_data (abfd)->toc;
4265
      internal_a.o_toc = toc;
4266
      internal_a.o_sntoc = xcoff_data (abfd)->sntoc;
4267
4268
      internal_a.o_modtype = xcoff_data (abfd)->modtype;
4269
      if (xcoff_data (abfd)->cputype != -1)
4270
  internal_a.o_cputype = xcoff_data (abfd)->cputype;
4271
      else
4272
  {
4273
    switch (bfd_get_arch (abfd))
4274
      {
4275
      case bfd_arch_rs6000:
4276
        internal_a.o_cputype = 4;
4277
        break;
4278
      case bfd_arch_powerpc:
4279
        if (bfd_get_mach (abfd) == bfd_mach_ppc)
4280
    internal_a.o_cputype = 3;
4281
        else if (bfd_get_mach (abfd) == bfd_mach_ppc_620)
4282
    internal_a.o_cputype = 2;
4283
        else
4284
    internal_a.o_cputype = 1;
4285
        break;
4286
      default:
4287
        abort ();
4288
      }
4289
  }
4290
      internal_a.o_maxstack = xcoff_data (abfd)->maxstack;
4291
      internal_a.o_maxdata = xcoff_data (abfd)->maxdata;
4292
    }
4293
#endif
4294
4295
3
#ifdef COFF_WITH_PE
4296
3
  {
4297
    /* After object contents are finalized so we can compute a reasonable hash,
4298
       but before header is written so we can update it to point to debug directory.  */
4299
3
    struct pe_tdata *pe = pe_data (abfd);
4300
4301
3
    if (pe->build_id.after_write_object_contents != NULL)
4302
0
      (*pe->build_id.after_write_object_contents) (abfd);
4303
3
  }
4304
3
#endif
4305
4306
  /* Now write header.  */
4307
3
  if (bfd_seek (abfd, 0, SEEK_SET) != 0)
4308
0
    return false;
4309
4310
3
  {
4311
3
    char * buff;
4312
3
    bfd_size_type amount = bfd_coff_filhsz (abfd);
4313
4314
3
    buff = (char *) bfd_malloc (amount);
4315
3
    if (buff == NULL)
4316
0
      return false;
4317
4318
3
    bfd_coff_swap_filehdr_out (abfd, & internal_f, buff);
4319
3
    amount = bfd_write (buff, amount, abfd);
4320
4321
3
    free (buff);
4322
4323
3
    if (amount != bfd_coff_filhsz (abfd))
4324
0
      return false;
4325
3
  }
4326
4327
3
  if (abfd->flags & EXEC_P)
4328
3
    {
4329
      /* Note that peicode.h fills in a PEAOUTHDR, not an AOUTHDR.
4330
   include/coff/pe.h sets AOUTSZ == sizeof (PEAOUTHDR)).  */
4331
3
      char * buff;
4332
3
      bfd_size_type amount = bfd_coff_aoutsz (abfd);
4333
4334
3
      buff = (char *) bfd_malloc (amount);
4335
3
      if (buff == NULL)
4336
0
  return false;
4337
4338
3
      coff_swap_aouthdr_out (abfd, & internal_a, buff);
4339
3
      amount = bfd_write (buff, amount, abfd);
4340
4341
3
      free (buff);
4342
4343
3
      if (amount != bfd_coff_aoutsz (abfd))
4344
0
  return false;
4345
4346
3
#ifdef COFF_IMAGE_WITH_PE
4347
3
      if (! coff_apply_checksum (abfd))
4348
0
  return false;
4349
3
#endif
4350
3
    }
4351
#ifdef RS6000COFF_C
4352
#ifndef XCOFF64
4353
  else
4354
    {
4355
      AOUTHDR buff;
4356
      size_t size;
4357
4358
      /* XCOFF32 seems to always write at least a small a.out header.  */
4359
      coff_swap_aouthdr_out (abfd, & internal_a, & buff);
4360
      if (xcoff_data (abfd)->full_aouthdr)
4361
  size = bfd_coff_aoutsz (abfd);
4362
      else
4363
  size = SMALL_AOUTSZ;
4364
      if (bfd_write (&buff, size, abfd) != size)
4365
  return false;
4366
    }
4367
#endif
4368
#endif
4369
4370
3
  return true;
4371
3
}
coff-x86_64.c:coff_write_object_contents
Line
Count
Source
3490
4
{
3491
4
  asection *current;
3492
4
  bool hasrelocs = false;
3493
4
  bool haslinno = false;
3494
#ifdef COFF_IMAGE_WITH_PE
3495
  bool hasdebug = false;
3496
#endif
3497
4
  file_ptr scn_base;
3498
4
  file_ptr reloc_base;
3499
4
  file_ptr lineno_base;
3500
4
  file_ptr sym_base;
3501
4
  unsigned long reloc_size = 0, reloc_count = 0;
3502
4
  unsigned long lnno_size = 0;
3503
4
  bool long_section_names;
3504
4
  asection *text_sec = NULL;
3505
4
  asection *data_sec = NULL;
3506
4
  asection *bss_sec = NULL;
3507
#ifdef RS6000COFF_C
3508
  asection *tdata_sec = NULL;
3509
  asection *tbss_sec = NULL;
3510
#endif
3511
4
  struct internal_filehdr internal_f;
3512
4
  struct internal_aouthdr internal_a;
3513
#ifdef COFF_LONG_SECTION_NAMES
3514
  size_t string_size = STRING_SIZE_SIZE;
3515
#endif
3516
3517
4
  bfd_set_error (bfd_error_system_call);
3518
3519
  /* Make a pass through the symbol table to count line number entries and
3520
     put them into the correct asections.  */
3521
4
  lnno_size = coff_count_linenumbers (abfd) * bfd_coff_linesz (abfd);
3522
3523
4
  if (! abfd->output_has_begun)
3524
3
    {
3525
3
      if (! coff_compute_section_file_positions (abfd))
3526
0
  return false;
3527
3
    }
3528
3529
4
  reloc_base = obj_relocbase (abfd);
3530
3531
  /* Work out the size of the reloc and linno areas.  */
3532
3533
273
  for (current = abfd->sections; current != NULL; current =
3534
269
       current->next)
3535
269
    {
3536
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3537
      /* We store the actual reloc count in the first reloc's addr.  */
3538
      if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3539
  reloc_count ++;
3540
#endif
3541
269
      reloc_count += current->reloc_count;
3542
269
    }
3543
3544
4
  reloc_size = reloc_count * bfd_coff_relsz (abfd);
3545
3546
4
  lineno_base = reloc_base + reloc_size;
3547
4
  sym_base = lineno_base + lnno_size;
3548
3549
  /* Indicate in each section->line_filepos its actual file address.  */
3550
273
  for (current = abfd->sections; current != NULL; current =
3551
269
       current->next)
3552
269
    {
3553
269
      if (current->lineno_count)
3554
0
  {
3555
0
    current->line_filepos = lineno_base;
3556
0
    current->moving_line_filepos = lineno_base;
3557
0
    lineno_base += current->lineno_count * bfd_coff_linesz (abfd);
3558
0
  }
3559
269
      else
3560
269
  current->line_filepos = 0;
3561
3562
269
      if (current->reloc_count)
3563
0
  {
3564
0
    current->rel_filepos = reloc_base;
3565
0
    reloc_base += current->reloc_count * bfd_coff_relsz (abfd);
3566
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3567
    /* Extra reloc to hold real count.  */
3568
    if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3569
      reloc_base += bfd_coff_relsz (abfd);
3570
#endif
3571
0
  }
3572
269
      else
3573
269
  current->rel_filepos = 0;
3574
269
    }
3575
3576
  /* Write section headers to the file.  */
3577
4
  internal_f.f_nscns = 0;
3578
3579
4
  if ((abfd->flags & EXEC_P) != 0)
3580
0
    scn_base = bfd_coff_filhsz (abfd) + bfd_coff_aoutsz (abfd);
3581
4
  else
3582
4
    {
3583
4
      scn_base = bfd_coff_filhsz (abfd);
3584
#ifdef RS6000COFF_C
3585
#ifndef XCOFF64
3586
      if (xcoff_data (abfd)->full_aouthdr)
3587
  scn_base += bfd_coff_aoutsz (abfd);
3588
      else
3589
  scn_base += SMALL_AOUTSZ;
3590
#endif
3591
#endif
3592
4
    }
3593
3594
4
  if (bfd_seek (abfd, scn_base, SEEK_SET) != 0)
3595
0
    return false;
3596
3597
4
  long_section_names = false;
3598
4
  for (current = abfd->sections;
3599
273
       current != NULL;
3600
269
       current = current->next)
3601
269
    {
3602
269
      struct internal_scnhdr section;
3603
#ifdef COFF_IMAGE_WITH_PE
3604
      bool is_reloc_section = false;
3605
3606
      if (strcmp (current->name, DOT_RELOC) == 0)
3607
  {
3608
    is_reloc_section = true;
3609
    hasrelocs = true;
3610
    pe_data (abfd)->has_reloc_section = 1;
3611
  }
3612
#endif
3613
3614
269
      internal_f.f_nscns++;
3615
3616
269
      strncpy (section.s_name, current->name, SCNNMLEN);
3617
3618
#ifdef COFF_LONG_SECTION_NAMES
3619
      /* Handle long section names as in PE.  This must be compatible
3620
   with the code in coff_write_symbols and _bfd_coff_final_link.  */
3621
      if (bfd_coff_long_section_names (abfd))
3622
  {
3623
    size_t len;
3624
3625
    len = strlen (current->name);
3626
    if (len > SCNNMLEN)
3627
      {
3628
3629
        /* An inherent limitation of the /nnnnnnn notation used to indicate
3630
     the offset of the long name in the string table is that we
3631
     cannot address entries beyone the ten million byte boundary.  */
3632
        if (string_size < 10000000)
3633
    {
3634
      /* The s_name field is defined to be NUL-padded but need not
3635
         be NUL-terminated.  We use a temporary buffer so that we
3636
         can still sprintf all eight chars without splatting a
3637
         terminating NUL over the first byte of the following
3638
         member (s_paddr).  */
3639
      /* PR 21096: The +20 is to stop a bogus warning from gcc7
3640
         about a possible buffer overflow.  */
3641
      char s_name_buf[SCNNMLEN + 1 + 20];
3642
3643
      /* We do not need to use snprintf here as we have already
3644
         verified that string_size is not too big, plus we have
3645
         an overlarge buffer, just in case.  */
3646
      sprintf (s_name_buf, "/%lu", (unsigned long) string_size);
3647
      /* Then strncpy takes care of any padding for us.  */
3648
      strncpy (section.s_name, s_name_buf, SCNNMLEN);
3649
    }
3650
        else
3651
#ifdef COFF_WITH_PE
3652
    {
3653
      /* PE use a base 64 encoding for long section names whose
3654
         index is very large.  But contrary to RFC 4648, there is
3655
         no padding: 6 characters must be generated.  */
3656
      static const char base64[] =
3657
        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
3658
        "abcdefghijklmnopqrstuvwxyz"
3659
        "0123456789+/";
3660
      unsigned long off = string_size;
3661
      unsigned i;
3662
3663
      section.s_name[0] = '/';
3664
      section.s_name[1] = '/';
3665
      for (i = SCNNMLEN - 1; i >= 2; i--)
3666
        {
3667
          section.s_name[i] = base64[off & 0x3f];
3668
          off >>= 6;
3669
        }
3670
    }
3671
#endif
3672
        if (string_size > 0xffffffffUL - (len + 1)
3673
#ifndef COFF_WITH_PE
3674
      || string_size >= 10000000
3675
#endif
3676
      )
3677
    {
3678
      bfd_set_error (bfd_error_file_too_big);
3679
      _bfd_error_handler
3680
        /* xgettext:c-format */
3681
        (_("%pB: section %pA: string table overflow at offset %ld"),
3682
        abfd, current, (unsigned long) string_size);
3683
      return false;
3684
    }
3685
3686
        string_size += len + 1;
3687
        long_section_names = true;
3688
      }
3689
  }
3690
#endif
3691
3692
269
#ifdef _LIB
3693
      /* Always set s_vaddr of .lib to 0.  This is right for SVR3.2
3694
   Ian Taylor <ian@cygnus.com>.  */
3695
269
      if (strcmp (current->name, _LIB) == 0)
3696
0
  section.s_vaddr = 0;
3697
269
      else
3698
269
#endif
3699
269
      section.s_vaddr = current->vma;
3700
269
      section.s_paddr = current->lma;
3701
269
      section.s_size =  current->size;
3702
#ifdef coff_get_section_load_page
3703
      section.s_page = coff_get_section_load_page (current);
3704
#else
3705
269
      section.s_page = 0;
3706
269
#endif
3707
3708
#ifdef COFF_WITH_PE
3709
      section.s_paddr = 0;
3710
#endif
3711
#ifdef COFF_IMAGE_WITH_PE
3712
      /* Reminder: s_paddr holds the virtual size of the section.  */
3713
      if (coff_section_data (abfd, current) != NULL
3714
    && pei_section_data (abfd, current) != NULL)
3715
  section.s_paddr = pei_section_data (abfd, current)->virt_size;
3716
      else
3717
  section.s_paddr = 0;
3718
#endif
3719
3720
      /* If this section has no size or is unloadable then the scnptr
3721
   will be 0 too.  */
3722
269
      if (current->size == 0
3723
269
    || (current->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
3724
266
  section.s_scnptr = 0;
3725
3
      else
3726
3
  section.s_scnptr = current->filepos;
3727
3728
269
      section.s_relptr = current->rel_filepos;
3729
269
      section.s_lnnoptr = current->line_filepos;
3730
269
      section.s_nreloc = current->reloc_count;
3731
269
      section.s_nlnno = current->lineno_count;
3732
269
#ifndef COFF_IMAGE_WITH_PE
3733
      /* In PEI, relocs come in the .reloc section.  */
3734
269
      if (current->reloc_count != 0)
3735
0
  hasrelocs = true;
3736
269
#endif
3737
269
      if (current->lineno_count != 0)
3738
0
  haslinno = true;
3739
#ifdef COFF_IMAGE_WITH_PE
3740
      if ((current->flags & SEC_DEBUGGING) != 0
3741
    && ! is_reloc_section)
3742
  hasdebug = true;
3743
#endif
3744
3745
#ifdef RS6000COFF_C
3746
#ifndef XCOFF64
3747
      /* Indicate the use of an XCOFF overflow section header.  */
3748
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3749
  {
3750
    section.s_nreloc = 0xffff;
3751
    section.s_nlnno = 0xffff;
3752
  }
3753
#endif
3754
#endif
3755
3756
269
      section.s_flags = sec_to_styp_flags (current->name, current->flags);
3757
3758
269
      if (!strcmp (current->name, _TEXT))
3759
0
  text_sec = current;
3760
269
      else if (!strcmp (current->name, _DATA))
3761
0
  data_sec = current;
3762
269
      else if (!strcmp (current->name, _BSS))
3763
0
  bss_sec = current;
3764
#ifdef RS6000COFF_C
3765
      else if (!strcmp (current->name, _TDATA))
3766
  tdata_sec = current;
3767
      else if (!strcmp (current->name, _TBSS))
3768
  tbss_sec = current;
3769
#endif
3770
3771
3772
#ifdef COFF_ENCODE_ALIGNMENT
3773
      if (COFF_ENCODE_ALIGNMENT (abfd, section, current->alignment_power)
3774
    && (COFF_DECODE_ALIGNMENT (section.s_flags)
3775
        != current->alignment_power))
3776
  {
3777
    bool warn = (coff_data (abfd)->link_info
3778
           && !bfd_link_relocatable (coff_data (abfd)->link_info));
3779
3780
    _bfd_error_handler
3781
      /* xgettext:c-format */
3782
      (_("%pB:%s section %s: alignment 2**%u not representable"),
3783
       abfd, warn ? " warning:" : "", current->name,
3784
       current->alignment_power);
3785
    if (!warn)
3786
      {
3787
        bfd_set_error (bfd_error_nonrepresentable_section);
3788
        return false;
3789
      }
3790
  }
3791
#endif
3792
3793
#ifdef COFF_IMAGE_WITH_PE
3794
      /* Suppress output of the sections if they are null.  ld
3795
   includes the bss and data sections even if there is no size
3796
   assigned to them.  NT loader doesn't like it if these section
3797
   headers are included if the sections themselves are not
3798
   needed.  See also coff_compute_section_file_positions.  */
3799
      if (section.s_size == 0)
3800
  internal_f.f_nscns--;
3801
      else
3802
#endif
3803
269
  {
3804
269
    SCNHDR buff;
3805
269
    bfd_size_type amt = bfd_coff_scnhsz (abfd);
3806
3807
269
    if (bfd_coff_swap_scnhdr_out (abfd, &section, &buff) == 0
3808
269
        || bfd_write (& buff, amt, abfd) != amt)
3809
0
      return false;
3810
269
  }
3811
3812
#ifdef COFF_WITH_PE
3813
      /* PE stores COMDAT section information in the symbol table.  If
3814
   this section is supposed to have some COMDAT info, track down
3815
   the symbol in the symbol table and modify it.  */
3816
      if ((current->flags & SEC_LINK_ONCE) != 0)
3817
  {
3818
    unsigned int i, count;
3819
    asymbol **psym;
3820
    coff_symbol_type *csym = NULL;
3821
    asymbol **psymsec;
3822
3823
    psymsec = NULL;
3824
    count = bfd_get_symcount (abfd);
3825
    for (i = 0, psym = abfd->outsymbols; i < count; i++, psym++)
3826
      {
3827
        if ((*psym)->section != current)
3828
    continue;
3829
3830
        /* Remember the location of the first symbol in this
3831
     section.  */
3832
        if (psymsec == NULL)
3833
    psymsec = psym;
3834
3835
        /* See if this is the section symbol.  */
3836
        if (strcmp ((*psym)->name, current->name) == 0)
3837
    {
3838
      csym = coff_symbol_from (*psym);
3839
      if (csym == NULL
3840
          || csym->native == NULL
3841
          || ! csym->native->is_sym
3842
          || csym->native->u.syment.n_numaux < 1
3843
          || csym->native->u.syment.n_sclass != C_STAT
3844
          || csym->native->u.syment.n_type != T_NULL)
3845
        continue;
3846
3847
      /* Here *PSYM is the section symbol for CURRENT.  */
3848
3849
      break;
3850
    }
3851
      }
3852
3853
    /* Did we find it?
3854
       Note that we might not if we're converting the file from
3855
       some other object file format.  */
3856
    if (i < count)
3857
      {
3858
        combined_entry_type *aux;
3859
3860
        /* We don't touch the x_checksum field.  The
3861
     x_associated field is not currently supported.  */
3862
3863
        aux = csym->native + 1;
3864
        BFD_ASSERT (! aux->is_sym);
3865
        switch (current->flags & SEC_LINK_DUPLICATES)
3866
    {
3867
    case SEC_LINK_DUPLICATES_DISCARD:
3868
      aux->u.auxent.x_scn.x_comdat = IMAGE_COMDAT_SELECT_ANY;
3869
      break;
3870
3871
    case SEC_LINK_DUPLICATES_ONE_ONLY:
3872
      aux->u.auxent.x_scn.x_comdat =
3873
        IMAGE_COMDAT_SELECT_NODUPLICATES;
3874
      break;
3875
3876
    case SEC_LINK_DUPLICATES_SAME_SIZE:
3877
      aux->u.auxent.x_scn.x_comdat =
3878
        IMAGE_COMDAT_SELECT_SAME_SIZE;
3879
      break;
3880
3881
    case SEC_LINK_DUPLICATES_SAME_CONTENTS:
3882
      aux->u.auxent.x_scn.x_comdat =
3883
        IMAGE_COMDAT_SELECT_EXACT_MATCH;
3884
      break;
3885
    }
3886
3887
        /* The COMDAT symbol must be the first symbol from this
3888
     section in the symbol table.  In order to make this
3889
     work, we move the COMDAT symbol before the first
3890
     symbol we found in the search above.  It's OK to
3891
     rearrange the symbol table at this point, because
3892
     coff_renumber_symbols is going to rearrange it
3893
     further and fix up all the aux entries.  */
3894
        if (psym != psymsec)
3895
    {
3896
      asymbol *hold;
3897
      asymbol **pcopy;
3898
3899
      hold = *psym;
3900
      for (pcopy = psym; pcopy > psymsec; pcopy--)
3901
        pcopy[0] = pcopy[-1];
3902
      *psymsec = hold;
3903
    }
3904
      }
3905
  }
3906
#endif /* COFF_WITH_PE */
3907
269
    }
3908
3909
#ifdef RS6000COFF_C
3910
#ifndef XCOFF64
3911
  /* XCOFF handles overflows in the reloc and line number count fields
3912
     by creating a new section header to hold the correct values.  */
3913
  for (current = abfd->sections; current != NULL; current = current->next)
3914
    {
3915
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3916
  {
3917
    struct internal_scnhdr scnhdr;
3918
    SCNHDR buff;
3919
    bfd_size_type amt;
3920
3921
    internal_f.f_nscns++;
3922
    memcpy (scnhdr.s_name, ".ovrflo", 8);
3923
    scnhdr.s_paddr = current->reloc_count;
3924
    scnhdr.s_vaddr = current->lineno_count;
3925
    scnhdr.s_size = 0;
3926
    scnhdr.s_scnptr = 0;
3927
    scnhdr.s_relptr = current->rel_filepos;
3928
    scnhdr.s_lnnoptr = current->line_filepos;
3929
    scnhdr.s_nreloc = current->target_index;
3930
    scnhdr.s_nlnno = current->target_index;
3931
    scnhdr.s_flags = STYP_OVRFLO;
3932
    amt = bfd_coff_scnhsz (abfd);
3933
    if (bfd_coff_swap_scnhdr_out (abfd, &scnhdr, &buff) == 0
3934
        || bfd_write (& buff, amt, abfd) != amt)
3935
      return false;
3936
  }
3937
    }
3938
#endif
3939
#endif
3940
3941
#if defined (COFF_GO32_EXE) || defined (COFF_GO32)
3942
  /* Pad section headers.  */
3943
  if ((abfd->flags & EXEC_P) != 0)
3944
    {
3945
      asection *s = abfd->sections;
3946
      while (s != NULL && s->filepos == 0)
3947
  s = s->next;
3948
      if (s != NULL)
3949
  {
3950
    file_ptr cur_ptr
3951
      = scn_base + abfd->section_count * bfd_coff_scnhsz (abfd);
3952
    file_ptr fill_size = s->filepos - cur_ptr;
3953
    if (fill_size > 0)
3954
      {
3955
        bfd_byte *b = bfd_zmalloc (fill_size);
3956
        if (!b)
3957
    return false;
3958
        if (bfd_write (b, fill_size, abfd) != (ufile_ptr) fill_size)
3959
    {
3960
      free (b);
3961
      return false;
3962
    }
3963
        free (b);
3964
      }
3965
  }
3966
    }
3967
#endif
3968
3969
  /* OK, now set up the filehdr...  */
3970
3971
  /* Don't include the internal abs section in the section count */
3972
3973
  /* We will NOT put a fucking timestamp in the header here. Every time you
3974
     put it back, I will come in and take it out again.  I'm sorry.  This
3975
     field does not belong here.  We fill it with a 0 so it compares the
3976
     same but is not a reasonable time. -- gnu@cygnus.com  */
3977
4
  internal_f.f_timdat = 0;
3978
4
  internal_f.f_flags = 0;
3979
3980
4
  if (abfd->flags & EXEC_P)
3981
0
    internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3982
4
  else
3983
4
    {
3984
4
      internal_f.f_opthdr = 0;
3985
#ifdef RS6000COFF_C
3986
#ifndef XCOFF64
3987
      if (xcoff_data (abfd)->full_aouthdr)
3988
  internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3989
      else
3990
  internal_f.f_opthdr = SMALL_AOUTSZ;
3991
#endif
3992
#endif
3993
4
    }
3994
3995
4
  if (!hasrelocs)
3996
4
    internal_f.f_flags |= F_RELFLG;
3997
4
  if (!haslinno)
3998
4
    internal_f.f_flags |= F_LNNO;
3999
4
  if (abfd->flags & EXEC_P)
4000
0
    internal_f.f_flags |= F_EXEC;
4001
#ifdef COFF_IMAGE_WITH_PE
4002
  if (! hasdebug)
4003
    internal_f.f_flags |= IMAGE_FILE_DEBUG_STRIPPED;
4004
  if (pe_data (abfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
4005
    internal_f.f_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
4006
#endif
4007
4008
4
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64) && !defined (COFF_WITH_peRiscV64)
4009
#ifdef COFF_WITH_PE
4010
  internal_f.f_flags |= IMAGE_FILE_32BIT_MACHINE;
4011
#else
4012
4
  if (bfd_little_endian (abfd))
4013
4
    internal_f.f_flags |= F_AR32WR;
4014
0
  else
4015
0
    internal_f.f_flags |= F_AR32W;
4016
4
#endif
4017
4
#endif
4018
4019
#ifdef TI_TARGET_ID
4020
  /* Target id is used in TI COFF v1 and later; COFF0 won't use this field,
4021
     but it doesn't hurt to set it internally.  */
4022
  internal_f.f_target_id = TI_TARGET_ID;
4023
#endif
4024
4025
  /* FIXME, should do something about the other byte orders and
4026
     architectures.  */
4027
4028
#ifdef RS6000COFF_C
4029
  if ((abfd->flags & DYNAMIC) != 0)
4030
    internal_f.f_flags |= F_SHROBJ;
4031
  if (bfd_get_section_by_name (abfd, _LOADER) != NULL)
4032
    internal_f.f_flags |= F_DYNLOAD;
4033
#endif
4034
4035
4
  memset (&internal_a, 0, sizeof internal_a);
4036
4037
  /* Set up architecture-dependent stuff.  */
4038
4
  {
4039
4
    unsigned int magic = 0;
4040
4
    unsigned short flags = 0;
4041
4042
4
    coff_set_flags (abfd, &magic, &flags);
4043
4
    internal_f.f_magic = magic;
4044
4
    internal_f.f_flags |= flags;
4045
    /* ...and the "opt"hdr...  */
4046
4047
#ifdef TICOFF_AOUT_MAGIC
4048
    internal_a.magic = TICOFF_AOUT_MAGIC;
4049
#define __A_MAGIC_SET__
4050
#endif
4051
4052
#if defined(ARM)
4053
#define __A_MAGIC_SET__
4054
    internal_a.magic = ZMAGIC;
4055
#endif
4056
4057
#if defined(AARCH64)
4058
#define __A_MAGIC_SET__
4059
    internal_a.magic = ZMAGIC;
4060
#endif
4061
4062
#if defined(LOONGARCH64)
4063
#define __A_MAGIC_SET__
4064
    internal_a.magic = ZMAGIC;
4065
#endif
4066
4067
#if defined(RISCV64)
4068
#define __A_MAGIC_SET__
4069
    internal_a.magic = ZMAGIC;
4070
#endif
4071
4072
#if defined MCORE_PE
4073
#define __A_MAGIC_SET__
4074
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR_MAGIC;
4075
#endif
4076
4077
4
#if defined(I386)
4078
4
#define __A_MAGIC_SET__
4079
#if defined LYNXOS
4080
    internal_a.magic = LYNXCOFFMAGIC;
4081
#elif defined AMD64
4082
4
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR64_MAGIC;
4083
#else
4084
    internal_a.magic = ZMAGIC;
4085
#endif
4086
4
#endif /* I386 */
4087
4088
#if defined(IA64)
4089
#define __A_MAGIC_SET__
4090
    internal_a.magic = PE32PMAGIC;
4091
#endif /* IA64 */
4092
4093
#if defined(SPARC)
4094
#define __A_MAGIC_SET__
4095
#if defined(LYNXOS)
4096
    internal_a.magic = LYNXCOFFMAGIC;
4097
#endif /* LYNXOS */
4098
#endif /* SPARC */
4099
4100
#ifdef RS6000COFF_C
4101
#define __A_MAGIC_SET__
4102
    internal_a.magic = (abfd->flags & D_PAGED) ? RS6K_AOUTHDR_ZMAGIC :
4103
    (abfd->flags & WP_TEXT) ? RS6K_AOUTHDR_NMAGIC :
4104
    RS6K_AOUTHDR_OMAGIC;
4105
#endif
4106
4107
#if defined(SH) && defined(COFF_WITH_PE)
4108
#define __A_MAGIC_SET__
4109
    internal_a.magic = SH_PE_MAGIC;
4110
#endif
4111
4112
#if defined(MIPS) && defined(COFF_WITH_PE)
4113
#define __A_MAGIC_SET__
4114
    internal_a.magic = MIPS_PE_MAGIC;
4115
#endif
4116
4117
#ifndef __A_MAGIC_SET__
4118
#include "Your aouthdr magic number is not being set!"
4119
#else
4120
4
#undef __A_MAGIC_SET__
4121
4
#endif
4122
4
  }
4123
4124
#ifdef RS6000COFF_C
4125
  /* XCOFF 32bit needs this to have new behaviour for n_type field.  */
4126
  internal_a.vstamp = 2;
4127
#else
4128
  /* FIXME: Does anybody ever set this to another value?  */
4129
4
  internal_a.vstamp = 0;
4130
4
#endif
4131
4132
  /* Now should write relocs, strings, syms.  */
4133
4
  obj_sym_filepos (abfd) = sym_base;
4134
4135
4
  if (bfd_get_symcount (abfd) != 0)
4136
1
    {
4137
1
      int firstundef;
4138
4139
1
      if (!coff_renumber_symbols (abfd, &firstundef))
4140
0
  return false;
4141
1
      coff_mangle_symbols (abfd);
4142
1
      if (! coff_write_symbols (abfd))
4143
0
  return false;
4144
1
      if (! coff_write_linenumbers (abfd))
4145
0
  return false;
4146
1
      if (! coff_write_relocs (abfd, firstundef))
4147
0
  return false;
4148
1
    }
4149
#ifdef COFF_LONG_SECTION_NAMES
4150
  else if (long_section_names && ! obj_coff_strings_written (abfd))
4151
    {
4152
      /* If we have long section names we have to write out the string
4153
   table even if there are no symbols.  */
4154
      if (! coff_write_symbols (abfd))
4155
  return false;
4156
    }
4157
#endif
4158
  /* If bfd_get_symcount (abfd) != 0, then we are not using the COFF
4159
     backend linker, and obj_raw_syment_count is not valid until after
4160
     coff_write_symbols is called.  */
4161
4
  if (obj_raw_syment_count (abfd) != 0)
4162
1
    {
4163
1
      internal_f.f_symptr = sym_base;
4164
#ifdef RS6000COFF_C
4165
      /* AIX appears to require that F_RELFLG not be set if there are
4166
   local symbols but no relocations.  */
4167
      internal_f.f_flags &=~ F_RELFLG;
4168
#endif
4169
1
    }
4170
3
  else
4171
3
    {
4172
3
      if (long_section_names)
4173
0
  internal_f.f_symptr = sym_base;
4174
3
      else
4175
3
  internal_f.f_symptr = 0;
4176
3
      internal_f.f_flags |= F_LSYMS;
4177
3
    }
4178
4179
4
  if (text_sec)
4180
0
    {
4181
0
      internal_a.tsize = text_sec->size;
4182
0
      internal_a.text_start = internal_a.tsize ? text_sec->vma : 0;
4183
0
    }
4184
4
  if (data_sec)
4185
0
    {
4186
0
      internal_a.dsize = data_sec->size;
4187
0
      internal_a.data_start = internal_a.dsize ? data_sec->vma : 0;
4188
0
    }
4189
4
  if (bss_sec)
4190
0
    {
4191
0
      internal_a.bsize = bss_sec->size;
4192
0
      if (internal_a.bsize && bss_sec->vma < internal_a.data_start)
4193
0
  internal_a.data_start = bss_sec->vma;
4194
0
    }
4195
4196
4
  internal_a.entry = bfd_get_start_address (abfd);
4197
4
  internal_f.f_nsyms = obj_raw_syment_count (abfd);
4198
4199
#ifdef RS6000COFF_C
4200
  if (xcoff_data (abfd)->full_aouthdr)
4201
    {
4202
      bfd_vma toc;
4203
      asection *loader_sec;
4204
4205
      internal_a.vstamp = 2;
4206
4207
      internal_a.o_snentry = xcoff_data (abfd)->snentry;
4208
      if (internal_a.o_snentry == 0)
4209
  internal_a.entry = (bfd_vma) -1;
4210
4211
      if (text_sec != NULL)
4212
  {
4213
    internal_a.o_sntext = text_sec->target_index;
4214
    internal_a.o_algntext = bfd_section_alignment (text_sec);
4215
  }
4216
      else
4217
  {
4218
    internal_a.o_sntext = 0;
4219
    internal_a.o_algntext = 0;
4220
  }
4221
      if (data_sec != NULL)
4222
  {
4223
    internal_a.o_sndata = data_sec->target_index;
4224
    internal_a.o_algndata = bfd_section_alignment (data_sec);
4225
  }
4226
      else
4227
  {
4228
    internal_a.o_sndata = 0;
4229
    internal_a.o_algndata = 0;
4230
  }
4231
      loader_sec = bfd_get_section_by_name (abfd, ".loader");
4232
      if (loader_sec != NULL)
4233
  internal_a.o_snloader = loader_sec->target_index;
4234
      else
4235
  internal_a.o_snloader = 0;
4236
      if (bss_sec != NULL)
4237
  internal_a.o_snbss = bss_sec->target_index;
4238
      else
4239
  internal_a.o_snbss = 0;
4240
4241
      if (tdata_sec != NULL)
4242
  {
4243
    internal_a.o_sntdata = tdata_sec->target_index;
4244
    /* TODO: o_flags should be set to RS6K_AOUTHDR_TLS_LE
4245
       if there is at least one R_TLS_LE relocations.  */
4246
    internal_a.o_flags = 0;
4247
#ifdef XCOFF64
4248
    internal_a.o_x64flags = 0;
4249
#endif
4250
  }
4251
      else
4252
  {
4253
    internal_a.o_sntdata = 0;
4254
    internal_a.o_flags = 0;
4255
#ifdef XCOFF64
4256
    internal_a.o_x64flags = 0;
4257
#endif
4258
  }
4259
      if (tbss_sec != NULL)
4260
    internal_a.o_sntbss = tbss_sec->target_index;
4261
      else
4262
    internal_a.o_sntbss = 0;
4263
4264
      toc = xcoff_data (abfd)->toc;
4265
      internal_a.o_toc = toc;
4266
      internal_a.o_sntoc = xcoff_data (abfd)->sntoc;
4267
4268
      internal_a.o_modtype = xcoff_data (abfd)->modtype;
4269
      if (xcoff_data (abfd)->cputype != -1)
4270
  internal_a.o_cputype = xcoff_data (abfd)->cputype;
4271
      else
4272
  {
4273
    switch (bfd_get_arch (abfd))
4274
      {
4275
      case bfd_arch_rs6000:
4276
        internal_a.o_cputype = 4;
4277
        break;
4278
      case bfd_arch_powerpc:
4279
        if (bfd_get_mach (abfd) == bfd_mach_ppc)
4280
    internal_a.o_cputype = 3;
4281
        else if (bfd_get_mach (abfd) == bfd_mach_ppc_620)
4282
    internal_a.o_cputype = 2;
4283
        else
4284
    internal_a.o_cputype = 1;
4285
        break;
4286
      default:
4287
        abort ();
4288
      }
4289
  }
4290
      internal_a.o_maxstack = xcoff_data (abfd)->maxstack;
4291
      internal_a.o_maxdata = xcoff_data (abfd)->maxdata;
4292
    }
4293
#endif
4294
4295
#ifdef COFF_WITH_PE
4296
  {
4297
    /* After object contents are finalized so we can compute a reasonable hash,
4298
       but before header is written so we can update it to point to debug directory.  */
4299
    struct pe_tdata *pe = pe_data (abfd);
4300
4301
    if (pe->build_id.after_write_object_contents != NULL)
4302
      (*pe->build_id.after_write_object_contents) (abfd);
4303
  }
4304
#endif
4305
4306
  /* Now write header.  */
4307
4
  if (bfd_seek (abfd, 0, SEEK_SET) != 0)
4308
0
    return false;
4309
4310
4
  {
4311
4
    char * buff;
4312
4
    bfd_size_type amount = bfd_coff_filhsz (abfd);
4313
4314
4
    buff = (char *) bfd_malloc (amount);
4315
4
    if (buff == NULL)
4316
0
      return false;
4317
4318
4
    bfd_coff_swap_filehdr_out (abfd, & internal_f, buff);
4319
4
    amount = bfd_write (buff, amount, abfd);
4320
4321
4
    free (buff);
4322
4323
4
    if (amount != bfd_coff_filhsz (abfd))
4324
0
      return false;
4325
4
  }
4326
4327
4
  if (abfd->flags & EXEC_P)
4328
0
    {
4329
      /* Note that peicode.h fills in a PEAOUTHDR, not an AOUTHDR.
4330
   include/coff/pe.h sets AOUTSZ == sizeof (PEAOUTHDR)).  */
4331
0
      char * buff;
4332
0
      bfd_size_type amount = bfd_coff_aoutsz (abfd);
4333
4334
0
      buff = (char *) bfd_malloc (amount);
4335
0
      if (buff == NULL)
4336
0
  return false;
4337
4338
0
      coff_swap_aouthdr_out (abfd, & internal_a, buff);
4339
0
      amount = bfd_write (buff, amount, abfd);
4340
4341
0
      free (buff);
4342
4343
0
      if (amount != bfd_coff_aoutsz (abfd))
4344
0
  return false;
4345
4346
#ifdef COFF_IMAGE_WITH_PE
4347
      if (! coff_apply_checksum (abfd))
4348
  return false;
4349
#endif
4350
0
    }
4351
#ifdef RS6000COFF_C
4352
#ifndef XCOFF64
4353
  else
4354
    {
4355
      AOUTHDR buff;
4356
      size_t size;
4357
4358
      /* XCOFF32 seems to always write at least a small a.out header.  */
4359
      coff_swap_aouthdr_out (abfd, & internal_a, & buff);
4360
      if (xcoff_data (abfd)->full_aouthdr)
4361
  size = bfd_coff_aoutsz (abfd);
4362
      else
4363
  size = SMALL_AOUTSZ;
4364
      if (bfd_write (&buff, size, abfd) != size)
4365
  return false;
4366
    }
4367
#endif
4368
#endif
4369
4370
4
  return true;
4371
4
}
Unexecuted instantiation: coff64-rs6000.c:coff_write_object_contents
Unexecuted instantiation: pe-aarch64.c:coff_write_object_contents
pei-aarch64.c:coff_write_object_contents
Line
Count
Source
3490
2
{
3491
2
  asection *current;
3492
2
  bool hasrelocs = false;
3493
2
  bool haslinno = false;
3494
2
#ifdef COFF_IMAGE_WITH_PE
3495
2
  bool hasdebug = false;
3496
2
#endif
3497
2
  file_ptr scn_base;
3498
2
  file_ptr reloc_base;
3499
2
  file_ptr lineno_base;
3500
2
  file_ptr sym_base;
3501
2
  unsigned long reloc_size = 0, reloc_count = 0;
3502
2
  unsigned long lnno_size = 0;
3503
2
  bool long_section_names;
3504
2
  asection *text_sec = NULL;
3505
2
  asection *data_sec = NULL;
3506
2
  asection *bss_sec = NULL;
3507
#ifdef RS6000COFF_C
3508
  asection *tdata_sec = NULL;
3509
  asection *tbss_sec = NULL;
3510
#endif
3511
2
  struct internal_filehdr internal_f;
3512
2
  struct internal_aouthdr internal_a;
3513
2
#ifdef COFF_LONG_SECTION_NAMES
3514
2
  size_t string_size = STRING_SIZE_SIZE;
3515
2
#endif
3516
3517
2
  bfd_set_error (bfd_error_system_call);
3518
3519
  /* Make a pass through the symbol table to count line number entries and
3520
     put them into the correct asections.  */
3521
2
  lnno_size = coff_count_linenumbers (abfd) * bfd_coff_linesz (abfd);
3522
3523
2
  if (! abfd->output_has_begun)
3524
1
    {
3525
1
      if (! coff_compute_section_file_positions (abfd))
3526
0
  return false;
3527
1
    }
3528
3529
2
  reloc_base = obj_relocbase (abfd);
3530
3531
  /* Work out the size of the reloc and linno areas.  */
3532
3533
135
  for (current = abfd->sections; current != NULL; current =
3534
133
       current->next)
3535
133
    {
3536
133
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3537
      /* We store the actual reloc count in the first reloc's addr.  */
3538
133
      if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3539
0
  reloc_count ++;
3540
133
#endif
3541
133
      reloc_count += current->reloc_count;
3542
133
    }
3543
3544
2
  reloc_size = reloc_count * bfd_coff_relsz (abfd);
3545
3546
2
  lineno_base = reloc_base + reloc_size;
3547
2
  sym_base = lineno_base + lnno_size;
3548
3549
  /* Indicate in each section->line_filepos its actual file address.  */
3550
135
  for (current = abfd->sections; current != NULL; current =
3551
133
       current->next)
3552
133
    {
3553
133
      if (current->lineno_count)
3554
0
  {
3555
0
    current->line_filepos = lineno_base;
3556
0
    current->moving_line_filepos = lineno_base;
3557
0
    lineno_base += current->lineno_count * bfd_coff_linesz (abfd);
3558
0
  }
3559
133
      else
3560
133
  current->line_filepos = 0;
3561
3562
133
      if (current->reloc_count)
3563
0
  {
3564
0
    current->rel_filepos = reloc_base;
3565
0
    reloc_base += current->reloc_count * bfd_coff_relsz (abfd);
3566
0
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3567
    /* Extra reloc to hold real count.  */
3568
0
    if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3569
0
      reloc_base += bfd_coff_relsz (abfd);
3570
0
#endif
3571
0
  }
3572
133
      else
3573
133
  current->rel_filepos = 0;
3574
133
    }
3575
3576
  /* Write section headers to the file.  */
3577
2
  internal_f.f_nscns = 0;
3578
3579
2
  if ((abfd->flags & EXEC_P) != 0)
3580
0
    scn_base = bfd_coff_filhsz (abfd) + bfd_coff_aoutsz (abfd);
3581
2
  else
3582
2
    {
3583
2
      scn_base = bfd_coff_filhsz (abfd);
3584
#ifdef RS6000COFF_C
3585
#ifndef XCOFF64
3586
      if (xcoff_data (abfd)->full_aouthdr)
3587
  scn_base += bfd_coff_aoutsz (abfd);
3588
      else
3589
  scn_base += SMALL_AOUTSZ;
3590
#endif
3591
#endif
3592
2
    }
3593
3594
2
  if (bfd_seek (abfd, scn_base, SEEK_SET) != 0)
3595
0
    return false;
3596
3597
2
  long_section_names = false;
3598
2
  for (current = abfd->sections;
3599
135
       current != NULL;
3600
133
       current = current->next)
3601
133
    {
3602
133
      struct internal_scnhdr section;
3603
133
#ifdef COFF_IMAGE_WITH_PE
3604
133
      bool is_reloc_section = false;
3605
3606
133
      if (strcmp (current->name, DOT_RELOC) == 0)
3607
0
  {
3608
0
    is_reloc_section = true;
3609
0
    hasrelocs = true;
3610
0
    pe_data (abfd)->has_reloc_section = 1;
3611
0
  }
3612
133
#endif
3613
3614
133
      internal_f.f_nscns++;
3615
3616
133
      strncpy (section.s_name, current->name, SCNNMLEN);
3617
3618
133
#ifdef COFF_LONG_SECTION_NAMES
3619
      /* Handle long section names as in PE.  This must be compatible
3620
   with the code in coff_write_symbols and _bfd_coff_final_link.  */
3621
133
      if (bfd_coff_long_section_names (abfd))
3622
0
  {
3623
0
    size_t len;
3624
3625
0
    len = strlen (current->name);
3626
0
    if (len > SCNNMLEN)
3627
0
      {
3628
3629
        /* An inherent limitation of the /nnnnnnn notation used to indicate
3630
     the offset of the long name in the string table is that we
3631
     cannot address entries beyone the ten million byte boundary.  */
3632
0
        if (string_size < 10000000)
3633
0
    {
3634
      /* The s_name field is defined to be NUL-padded but need not
3635
         be NUL-terminated.  We use a temporary buffer so that we
3636
         can still sprintf all eight chars without splatting a
3637
         terminating NUL over the first byte of the following
3638
         member (s_paddr).  */
3639
      /* PR 21096: The +20 is to stop a bogus warning from gcc7
3640
         about a possible buffer overflow.  */
3641
0
      char s_name_buf[SCNNMLEN + 1 + 20];
3642
3643
      /* We do not need to use snprintf here as we have already
3644
         verified that string_size is not too big, plus we have
3645
         an overlarge buffer, just in case.  */
3646
0
      sprintf (s_name_buf, "/%lu", (unsigned long) string_size);
3647
      /* Then strncpy takes care of any padding for us.  */
3648
0
      strncpy (section.s_name, s_name_buf, SCNNMLEN);
3649
0
    }
3650
0
        else
3651
0
#ifdef COFF_WITH_PE
3652
0
    {
3653
      /* PE use a base 64 encoding for long section names whose
3654
         index is very large.  But contrary to RFC 4648, there is
3655
         no padding: 6 characters must be generated.  */
3656
0
      static const char base64[] =
3657
0
        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
3658
0
        "abcdefghijklmnopqrstuvwxyz"
3659
0
        "0123456789+/";
3660
0
      unsigned long off = string_size;
3661
0
      unsigned i;
3662
3663
0
      section.s_name[0] = '/';
3664
0
      section.s_name[1] = '/';
3665
0
      for (i = SCNNMLEN - 1; i >= 2; i--)
3666
0
        {
3667
0
          section.s_name[i] = base64[off & 0x3f];
3668
0
          off >>= 6;
3669
0
        }
3670
0
    }
3671
0
#endif
3672
0
        if (string_size > 0xffffffffUL - (len + 1)
3673
#ifndef COFF_WITH_PE
3674
      || string_size >= 10000000
3675
#endif
3676
0
      )
3677
0
    {
3678
0
      bfd_set_error (bfd_error_file_too_big);
3679
0
      _bfd_error_handler
3680
        /* xgettext:c-format */
3681
0
        (_("%pB: section %pA: string table overflow at offset %ld"),
3682
0
        abfd, current, (unsigned long) string_size);
3683
0
      return false;
3684
0
    }
3685
3686
0
        string_size += len + 1;
3687
0
        long_section_names = true;
3688
0
      }
3689
0
  }
3690
133
#endif
3691
3692
133
#ifdef _LIB
3693
      /* Always set s_vaddr of .lib to 0.  This is right for SVR3.2
3694
   Ian Taylor <ian@cygnus.com>.  */
3695
133
      if (strcmp (current->name, _LIB) == 0)
3696
0
  section.s_vaddr = 0;
3697
133
      else
3698
133
#endif
3699
133
      section.s_vaddr = current->vma;
3700
133
      section.s_paddr = current->lma;
3701
133
      section.s_size =  current->size;
3702
#ifdef coff_get_section_load_page
3703
      section.s_page = coff_get_section_load_page (current);
3704
#else
3705
133
      section.s_page = 0;
3706
133
#endif
3707
3708
133
#ifdef COFF_WITH_PE
3709
133
      section.s_paddr = 0;
3710
133
#endif
3711
133
#ifdef COFF_IMAGE_WITH_PE
3712
      /* Reminder: s_paddr holds the virtual size of the section.  */
3713
133
      if (coff_section_data (abfd, current) != NULL
3714
133
    && pei_section_data (abfd, current) != NULL)
3715
133
  section.s_paddr = pei_section_data (abfd, current)->virt_size;
3716
0
      else
3717
0
  section.s_paddr = 0;
3718
133
#endif
3719
3720
      /* If this section has no size or is unloadable then the scnptr
3721
   will be 0 too.  */
3722
133
      if (current->size == 0
3723
133
    || (current->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
3724
131
  section.s_scnptr = 0;
3725
2
      else
3726
2
  section.s_scnptr = current->filepos;
3727
3728
133
      section.s_relptr = current->rel_filepos;
3729
133
      section.s_lnnoptr = current->line_filepos;
3730
133
      section.s_nreloc = current->reloc_count;
3731
133
      section.s_nlnno = current->lineno_count;
3732
#ifndef COFF_IMAGE_WITH_PE
3733
      /* In PEI, relocs come in the .reloc section.  */
3734
      if (current->reloc_count != 0)
3735
  hasrelocs = true;
3736
#endif
3737
133
      if (current->lineno_count != 0)
3738
0
  haslinno = true;
3739
133
#ifdef COFF_IMAGE_WITH_PE
3740
133
      if ((current->flags & SEC_DEBUGGING) != 0
3741
133
    && ! is_reloc_section)
3742
2
  hasdebug = true;
3743
133
#endif
3744
3745
#ifdef RS6000COFF_C
3746
#ifndef XCOFF64
3747
      /* Indicate the use of an XCOFF overflow section header.  */
3748
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3749
  {
3750
    section.s_nreloc = 0xffff;
3751
    section.s_nlnno = 0xffff;
3752
  }
3753
#endif
3754
#endif
3755
3756
133
      section.s_flags = sec_to_styp_flags (current->name, current->flags);
3757
3758
133
      if (!strcmp (current->name, _TEXT))
3759
0
  text_sec = current;
3760
133
      else if (!strcmp (current->name, _DATA))
3761
0
  data_sec = current;
3762
133
      else if (!strcmp (current->name, _BSS))
3763
0
  bss_sec = current;
3764
#ifdef RS6000COFF_C
3765
      else if (!strcmp (current->name, _TDATA))
3766
  tdata_sec = current;
3767
      else if (!strcmp (current->name, _TBSS))
3768
  tbss_sec = current;
3769
#endif
3770
3771
3772
133
#ifdef COFF_ENCODE_ALIGNMENT
3773
133
      if (COFF_ENCODE_ALIGNMENT (abfd, section, current->alignment_power)
3774
133
    && (COFF_DECODE_ALIGNMENT (section.s_flags)
3775
133
        != current->alignment_power))
3776
0
  {
3777
0
    bool warn = (coff_data (abfd)->link_info
3778
0
           && !bfd_link_relocatable (coff_data (abfd)->link_info));
3779
3780
0
    _bfd_error_handler
3781
      /* xgettext:c-format */
3782
0
      (_("%pB:%s section %s: alignment 2**%u not representable"),
3783
0
       abfd, warn ? " warning:" : "", current->name,
3784
0
       current->alignment_power);
3785
0
    if (!warn)
3786
0
      {
3787
0
        bfd_set_error (bfd_error_nonrepresentable_section);
3788
0
        return false;
3789
0
      }
3790
0
  }
3791
133
#endif
3792
3793
133
#ifdef COFF_IMAGE_WITH_PE
3794
      /* Suppress output of the sections if they are null.  ld
3795
   includes the bss and data sections even if there is no size
3796
   assigned to them.  NT loader doesn't like it if these section
3797
   headers are included if the sections themselves are not
3798
   needed.  See also coff_compute_section_file_positions.  */
3799
133
      if (section.s_size == 0)
3800
130
  internal_f.f_nscns--;
3801
3
      else
3802
3
#endif
3803
3
  {
3804
3
    SCNHDR buff;
3805
3
    bfd_size_type amt = bfd_coff_scnhsz (abfd);
3806
3807
3
    if (bfd_coff_swap_scnhdr_out (abfd, &section, &buff) == 0
3808
3
        || bfd_write (& buff, amt, abfd) != amt)
3809
0
      return false;
3810
3
  }
3811
3812
133
#ifdef COFF_WITH_PE
3813
      /* PE stores COMDAT section information in the symbol table.  If
3814
   this section is supposed to have some COMDAT info, track down
3815
   the symbol in the symbol table and modify it.  */
3816
133
      if ((current->flags & SEC_LINK_ONCE) != 0)
3817
0
  {
3818
0
    unsigned int i, count;
3819
0
    asymbol **psym;
3820
0
    coff_symbol_type *csym = NULL;
3821
0
    asymbol **psymsec;
3822
3823
0
    psymsec = NULL;
3824
0
    count = bfd_get_symcount (abfd);
3825
0
    for (i = 0, psym = abfd->outsymbols; i < count; i++, psym++)
3826
0
      {
3827
0
        if ((*psym)->section != current)
3828
0
    continue;
3829
3830
        /* Remember the location of the first symbol in this
3831
     section.  */
3832
0
        if (psymsec == NULL)
3833
0
    psymsec = psym;
3834
3835
        /* See if this is the section symbol.  */
3836
0
        if (strcmp ((*psym)->name, current->name) == 0)
3837
0
    {
3838
0
      csym = coff_symbol_from (*psym);
3839
0
      if (csym == NULL
3840
0
          || csym->native == NULL
3841
0
          || ! csym->native->is_sym
3842
0
          || csym->native->u.syment.n_numaux < 1
3843
0
          || csym->native->u.syment.n_sclass != C_STAT
3844
0
          || csym->native->u.syment.n_type != T_NULL)
3845
0
        continue;
3846
3847
      /* Here *PSYM is the section symbol for CURRENT.  */
3848
3849
0
      break;
3850
0
    }
3851
0
      }
3852
3853
    /* Did we find it?
3854
       Note that we might not if we're converting the file from
3855
       some other object file format.  */
3856
0
    if (i < count)
3857
0
      {
3858
0
        combined_entry_type *aux;
3859
3860
        /* We don't touch the x_checksum field.  The
3861
     x_associated field is not currently supported.  */
3862
3863
0
        aux = csym->native + 1;
3864
0
        BFD_ASSERT (! aux->is_sym);
3865
0
        switch (current->flags & SEC_LINK_DUPLICATES)
3866
0
    {
3867
0
    case SEC_LINK_DUPLICATES_DISCARD:
3868
0
      aux->u.auxent.x_scn.x_comdat = IMAGE_COMDAT_SELECT_ANY;
3869
0
      break;
3870
3871
0
    case SEC_LINK_DUPLICATES_ONE_ONLY:
3872
0
      aux->u.auxent.x_scn.x_comdat =
3873
0
        IMAGE_COMDAT_SELECT_NODUPLICATES;
3874
0
      break;
3875
3876
0
    case SEC_LINK_DUPLICATES_SAME_SIZE:
3877
0
      aux->u.auxent.x_scn.x_comdat =
3878
0
        IMAGE_COMDAT_SELECT_SAME_SIZE;
3879
0
      break;
3880
3881
0
    case SEC_LINK_DUPLICATES_SAME_CONTENTS:
3882
0
      aux->u.auxent.x_scn.x_comdat =
3883
0
        IMAGE_COMDAT_SELECT_EXACT_MATCH;
3884
0
      break;
3885
0
    }
3886
3887
        /* The COMDAT symbol must be the first symbol from this
3888
     section in the symbol table.  In order to make this
3889
     work, we move the COMDAT symbol before the first
3890
     symbol we found in the search above.  It's OK to
3891
     rearrange the symbol table at this point, because
3892
     coff_renumber_symbols is going to rearrange it
3893
     further and fix up all the aux entries.  */
3894
0
        if (psym != psymsec)
3895
0
    {
3896
0
      asymbol *hold;
3897
0
      asymbol **pcopy;
3898
3899
0
      hold = *psym;
3900
0
      for (pcopy = psym; pcopy > psymsec; pcopy--)
3901
0
        pcopy[0] = pcopy[-1];
3902
0
      *psymsec = hold;
3903
0
    }
3904
0
      }
3905
0
  }
3906
133
#endif /* COFF_WITH_PE */
3907
133
    }
3908
3909
#ifdef RS6000COFF_C
3910
#ifndef XCOFF64
3911
  /* XCOFF handles overflows in the reloc and line number count fields
3912
     by creating a new section header to hold the correct values.  */
3913
  for (current = abfd->sections; current != NULL; current = current->next)
3914
    {
3915
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3916
  {
3917
    struct internal_scnhdr scnhdr;
3918
    SCNHDR buff;
3919
    bfd_size_type amt;
3920
3921
    internal_f.f_nscns++;
3922
    memcpy (scnhdr.s_name, ".ovrflo", 8);
3923
    scnhdr.s_paddr = current->reloc_count;
3924
    scnhdr.s_vaddr = current->lineno_count;
3925
    scnhdr.s_size = 0;
3926
    scnhdr.s_scnptr = 0;
3927
    scnhdr.s_relptr = current->rel_filepos;
3928
    scnhdr.s_lnnoptr = current->line_filepos;
3929
    scnhdr.s_nreloc = current->target_index;
3930
    scnhdr.s_nlnno = current->target_index;
3931
    scnhdr.s_flags = STYP_OVRFLO;
3932
    amt = bfd_coff_scnhsz (abfd);
3933
    if (bfd_coff_swap_scnhdr_out (abfd, &scnhdr, &buff) == 0
3934
        || bfd_write (& buff, amt, abfd) != amt)
3935
      return false;
3936
  }
3937
    }
3938
#endif
3939
#endif
3940
3941
#if defined (COFF_GO32_EXE) || defined (COFF_GO32)
3942
  /* Pad section headers.  */
3943
  if ((abfd->flags & EXEC_P) != 0)
3944
    {
3945
      asection *s = abfd->sections;
3946
      while (s != NULL && s->filepos == 0)
3947
  s = s->next;
3948
      if (s != NULL)
3949
  {
3950
    file_ptr cur_ptr
3951
      = scn_base + abfd->section_count * bfd_coff_scnhsz (abfd);
3952
    file_ptr fill_size = s->filepos - cur_ptr;
3953
    if (fill_size > 0)
3954
      {
3955
        bfd_byte *b = bfd_zmalloc (fill_size);
3956
        if (!b)
3957
    return false;
3958
        if (bfd_write (b, fill_size, abfd) != (ufile_ptr) fill_size)
3959
    {
3960
      free (b);
3961
      return false;
3962
    }
3963
        free (b);
3964
      }
3965
  }
3966
    }
3967
#endif
3968
3969
  /* OK, now set up the filehdr...  */
3970
3971
  /* Don't include the internal abs section in the section count */
3972
3973
  /* We will NOT put a fucking timestamp in the header here. Every time you
3974
     put it back, I will come in and take it out again.  I'm sorry.  This
3975
     field does not belong here.  We fill it with a 0 so it compares the
3976
     same but is not a reasonable time. -- gnu@cygnus.com  */
3977
2
  internal_f.f_timdat = 0;
3978
2
  internal_f.f_flags = 0;
3979
3980
2
  if (abfd->flags & EXEC_P)
3981
0
    internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3982
2
  else
3983
2
    {
3984
2
      internal_f.f_opthdr = 0;
3985
#ifdef RS6000COFF_C
3986
#ifndef XCOFF64
3987
      if (xcoff_data (abfd)->full_aouthdr)
3988
  internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3989
      else
3990
  internal_f.f_opthdr = SMALL_AOUTSZ;
3991
#endif
3992
#endif
3993
2
    }
3994
3995
2
  if (!hasrelocs)
3996
2
    internal_f.f_flags |= F_RELFLG;
3997
2
  if (!haslinno)
3998
2
    internal_f.f_flags |= F_LNNO;
3999
2
  if (abfd->flags & EXEC_P)
4000
0
    internal_f.f_flags |= F_EXEC;
4001
2
#ifdef COFF_IMAGE_WITH_PE
4002
2
  if (! hasdebug)
4003
1
    internal_f.f_flags |= IMAGE_FILE_DEBUG_STRIPPED;
4004
2
  if (pe_data (abfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
4005
0
    internal_f.f_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
4006
2
#endif
4007
4008
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64) && !defined (COFF_WITH_peRiscV64)
4009
#ifdef COFF_WITH_PE
4010
  internal_f.f_flags |= IMAGE_FILE_32BIT_MACHINE;
4011
#else
4012
  if (bfd_little_endian (abfd))
4013
    internal_f.f_flags |= F_AR32WR;
4014
  else
4015
    internal_f.f_flags |= F_AR32W;
4016
#endif
4017
#endif
4018
4019
#ifdef TI_TARGET_ID
4020
  /* Target id is used in TI COFF v1 and later; COFF0 won't use this field,
4021
     but it doesn't hurt to set it internally.  */
4022
  internal_f.f_target_id = TI_TARGET_ID;
4023
#endif
4024
4025
  /* FIXME, should do something about the other byte orders and
4026
     architectures.  */
4027
4028
#ifdef RS6000COFF_C
4029
  if ((abfd->flags & DYNAMIC) != 0)
4030
    internal_f.f_flags |= F_SHROBJ;
4031
  if (bfd_get_section_by_name (abfd, _LOADER) != NULL)
4032
    internal_f.f_flags |= F_DYNLOAD;
4033
#endif
4034
4035
2
  memset (&internal_a, 0, sizeof internal_a);
4036
4037
  /* Set up architecture-dependent stuff.  */
4038
2
  {
4039
2
    unsigned int magic = 0;
4040
2
    unsigned short flags = 0;
4041
4042
2
    coff_set_flags (abfd, &magic, &flags);
4043
2
    internal_f.f_magic = magic;
4044
2
    internal_f.f_flags |= flags;
4045
    /* ...and the "opt"hdr...  */
4046
4047
#ifdef TICOFF_AOUT_MAGIC
4048
    internal_a.magic = TICOFF_AOUT_MAGIC;
4049
#define __A_MAGIC_SET__
4050
#endif
4051
4052
#if defined(ARM)
4053
#define __A_MAGIC_SET__
4054
    internal_a.magic = ZMAGIC;
4055
#endif
4056
4057
2
#if defined(AARCH64)
4058
2
#define __A_MAGIC_SET__
4059
2
    internal_a.magic = ZMAGIC;
4060
2
#endif
4061
4062
#if defined(LOONGARCH64)
4063
#define __A_MAGIC_SET__
4064
    internal_a.magic = ZMAGIC;
4065
#endif
4066
4067
#if defined(RISCV64)
4068
#define __A_MAGIC_SET__
4069
    internal_a.magic = ZMAGIC;
4070
#endif
4071
4072
#if defined MCORE_PE
4073
#define __A_MAGIC_SET__
4074
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR_MAGIC;
4075
#endif
4076
4077
#if defined(I386)
4078
#define __A_MAGIC_SET__
4079
#if defined LYNXOS
4080
    internal_a.magic = LYNXCOFFMAGIC;
4081
#elif defined AMD64
4082
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR64_MAGIC;
4083
#else
4084
    internal_a.magic = ZMAGIC;
4085
#endif
4086
#endif /* I386 */
4087
4088
#if defined(IA64)
4089
#define __A_MAGIC_SET__
4090
    internal_a.magic = PE32PMAGIC;
4091
#endif /* IA64 */
4092
4093
#if defined(SPARC)
4094
#define __A_MAGIC_SET__
4095
#if defined(LYNXOS)
4096
    internal_a.magic = LYNXCOFFMAGIC;
4097
#endif /* LYNXOS */
4098
#endif /* SPARC */
4099
4100
#ifdef RS6000COFF_C
4101
#define __A_MAGIC_SET__
4102
    internal_a.magic = (abfd->flags & D_PAGED) ? RS6K_AOUTHDR_ZMAGIC :
4103
    (abfd->flags & WP_TEXT) ? RS6K_AOUTHDR_NMAGIC :
4104
    RS6K_AOUTHDR_OMAGIC;
4105
#endif
4106
4107
#if defined(SH) && defined(COFF_WITH_PE)
4108
#define __A_MAGIC_SET__
4109
    internal_a.magic = SH_PE_MAGIC;
4110
#endif
4111
4112
#if defined(MIPS) && defined(COFF_WITH_PE)
4113
#define __A_MAGIC_SET__
4114
    internal_a.magic = MIPS_PE_MAGIC;
4115
#endif
4116
4117
#ifndef __A_MAGIC_SET__
4118
#include "Your aouthdr magic number is not being set!"
4119
#else
4120
2
#undef __A_MAGIC_SET__
4121
2
#endif
4122
2
  }
4123
4124
#ifdef RS6000COFF_C
4125
  /* XCOFF 32bit needs this to have new behaviour for n_type field.  */
4126
  internal_a.vstamp = 2;
4127
#else
4128
  /* FIXME: Does anybody ever set this to another value?  */
4129
2
  internal_a.vstamp = 0;
4130
2
#endif
4131
4132
  /* Now should write relocs, strings, syms.  */
4133
2
  obj_sym_filepos (abfd) = sym_base;
4134
4135
2
  if (bfd_get_symcount (abfd) != 0)
4136
1
    {
4137
1
      int firstundef;
4138
4139
1
      if (!coff_renumber_symbols (abfd, &firstundef))
4140
0
  return false;
4141
1
      coff_mangle_symbols (abfd);
4142
1
      if (! coff_write_symbols (abfd))
4143
0
  return false;
4144
1
      if (! coff_write_linenumbers (abfd))
4145
0
  return false;
4146
1
      if (! coff_write_relocs (abfd, firstundef))
4147
0
  return false;
4148
1
    }
4149
1
#ifdef COFF_LONG_SECTION_NAMES
4150
1
  else if (long_section_names && ! obj_coff_strings_written (abfd))
4151
0
    {
4152
      /* If we have long section names we have to write out the string
4153
   table even if there are no symbols.  */
4154
0
      if (! coff_write_symbols (abfd))
4155
0
  return false;
4156
0
    }
4157
2
#endif
4158
  /* If bfd_get_symcount (abfd) != 0, then we are not using the COFF
4159
     backend linker, and obj_raw_syment_count is not valid until after
4160
     coff_write_symbols is called.  */
4161
2
  if (obj_raw_syment_count (abfd) != 0)
4162
1
    {
4163
1
      internal_f.f_symptr = sym_base;
4164
#ifdef RS6000COFF_C
4165
      /* AIX appears to require that F_RELFLG not be set if there are
4166
   local symbols but no relocations.  */
4167
      internal_f.f_flags &=~ F_RELFLG;
4168
#endif
4169
1
    }
4170
1
  else
4171
1
    {
4172
1
      if (long_section_names)
4173
0
  internal_f.f_symptr = sym_base;
4174
1
      else
4175
1
  internal_f.f_symptr = 0;
4176
1
      internal_f.f_flags |= F_LSYMS;
4177
1
    }
4178
4179
2
  if (text_sec)
4180
0
    {
4181
0
      internal_a.tsize = text_sec->size;
4182
0
      internal_a.text_start = internal_a.tsize ? text_sec->vma : 0;
4183
0
    }
4184
2
  if (data_sec)
4185
0
    {
4186
0
      internal_a.dsize = data_sec->size;
4187
0
      internal_a.data_start = internal_a.dsize ? data_sec->vma : 0;
4188
0
    }
4189
2
  if (bss_sec)
4190
0
    {
4191
0
      internal_a.bsize = bss_sec->size;
4192
0
      if (internal_a.bsize && bss_sec->vma < internal_a.data_start)
4193
0
  internal_a.data_start = bss_sec->vma;
4194
0
    }
4195
4196
2
  internal_a.entry = bfd_get_start_address (abfd);
4197
2
  internal_f.f_nsyms = obj_raw_syment_count (abfd);
4198
4199
#ifdef RS6000COFF_C
4200
  if (xcoff_data (abfd)->full_aouthdr)
4201
    {
4202
      bfd_vma toc;
4203
      asection *loader_sec;
4204
4205
      internal_a.vstamp = 2;
4206
4207
      internal_a.o_snentry = xcoff_data (abfd)->snentry;
4208
      if (internal_a.o_snentry == 0)
4209
  internal_a.entry = (bfd_vma) -1;
4210
4211
      if (text_sec != NULL)
4212
  {
4213
    internal_a.o_sntext = text_sec->target_index;
4214
    internal_a.o_algntext = bfd_section_alignment (text_sec);
4215
  }
4216
      else
4217
  {
4218
    internal_a.o_sntext = 0;
4219
    internal_a.o_algntext = 0;
4220
  }
4221
      if (data_sec != NULL)
4222
  {
4223
    internal_a.o_sndata = data_sec->target_index;
4224
    internal_a.o_algndata = bfd_section_alignment (data_sec);
4225
  }
4226
      else
4227
  {
4228
    internal_a.o_sndata = 0;
4229
    internal_a.o_algndata = 0;
4230
  }
4231
      loader_sec = bfd_get_section_by_name (abfd, ".loader");
4232
      if (loader_sec != NULL)
4233
  internal_a.o_snloader = loader_sec->target_index;
4234
      else
4235
  internal_a.o_snloader = 0;
4236
      if (bss_sec != NULL)
4237
  internal_a.o_snbss = bss_sec->target_index;
4238
      else
4239
  internal_a.o_snbss = 0;
4240
4241
      if (tdata_sec != NULL)
4242
  {
4243
    internal_a.o_sntdata = tdata_sec->target_index;
4244
    /* TODO: o_flags should be set to RS6K_AOUTHDR_TLS_LE
4245
       if there is at least one R_TLS_LE relocations.  */
4246
    internal_a.o_flags = 0;
4247
#ifdef XCOFF64
4248
    internal_a.o_x64flags = 0;
4249
#endif
4250
  }
4251
      else
4252
  {
4253
    internal_a.o_sntdata = 0;
4254
    internal_a.o_flags = 0;
4255
#ifdef XCOFF64
4256
    internal_a.o_x64flags = 0;
4257
#endif
4258
  }
4259
      if (tbss_sec != NULL)
4260
    internal_a.o_sntbss = tbss_sec->target_index;
4261
      else
4262
    internal_a.o_sntbss = 0;
4263
4264
      toc = xcoff_data (abfd)->toc;
4265
      internal_a.o_toc = toc;
4266
      internal_a.o_sntoc = xcoff_data (abfd)->sntoc;
4267
4268
      internal_a.o_modtype = xcoff_data (abfd)->modtype;
4269
      if (xcoff_data (abfd)->cputype != -1)
4270
  internal_a.o_cputype = xcoff_data (abfd)->cputype;
4271
      else
4272
  {
4273
    switch (bfd_get_arch (abfd))
4274
      {
4275
      case bfd_arch_rs6000:
4276
        internal_a.o_cputype = 4;
4277
        break;
4278
      case bfd_arch_powerpc:
4279
        if (bfd_get_mach (abfd) == bfd_mach_ppc)
4280
    internal_a.o_cputype = 3;
4281
        else if (bfd_get_mach (abfd) == bfd_mach_ppc_620)
4282
    internal_a.o_cputype = 2;
4283
        else
4284
    internal_a.o_cputype = 1;
4285
        break;
4286
      default:
4287
        abort ();
4288
      }
4289
  }
4290
      internal_a.o_maxstack = xcoff_data (abfd)->maxstack;
4291
      internal_a.o_maxdata = xcoff_data (abfd)->maxdata;
4292
    }
4293
#endif
4294
4295
2
#ifdef COFF_WITH_PE
4296
2
  {
4297
    /* After object contents are finalized so we can compute a reasonable hash,
4298
       but before header is written so we can update it to point to debug directory.  */
4299
2
    struct pe_tdata *pe = pe_data (abfd);
4300
4301
2
    if (pe->build_id.after_write_object_contents != NULL)
4302
0
      (*pe->build_id.after_write_object_contents) (abfd);
4303
2
  }
4304
2
#endif
4305
4306
  /* Now write header.  */
4307
2
  if (bfd_seek (abfd, 0, SEEK_SET) != 0)
4308
0
    return false;
4309
4310
2
  {
4311
2
    char * buff;
4312
2
    bfd_size_type amount = bfd_coff_filhsz (abfd);
4313
4314
2
    buff = (char *) bfd_malloc (amount);
4315
2
    if (buff == NULL)
4316
0
      return false;
4317
4318
2
    bfd_coff_swap_filehdr_out (abfd, & internal_f, buff);
4319
2
    amount = bfd_write (buff, amount, abfd);
4320
4321
2
    free (buff);
4322
4323
2
    if (amount != bfd_coff_filhsz (abfd))
4324
0
      return false;
4325
2
  }
4326
4327
2
  if (abfd->flags & EXEC_P)
4328
0
    {
4329
      /* Note that peicode.h fills in a PEAOUTHDR, not an AOUTHDR.
4330
   include/coff/pe.h sets AOUTSZ == sizeof (PEAOUTHDR)).  */
4331
0
      char * buff;
4332
0
      bfd_size_type amount = bfd_coff_aoutsz (abfd);
4333
4334
0
      buff = (char *) bfd_malloc (amount);
4335
0
      if (buff == NULL)
4336
0
  return false;
4337
4338
0
      coff_swap_aouthdr_out (abfd, & internal_a, buff);
4339
0
      amount = bfd_write (buff, amount, abfd);
4340
4341
0
      free (buff);
4342
4343
0
      if (amount != bfd_coff_aoutsz (abfd))
4344
0
  return false;
4345
4346
0
#ifdef COFF_IMAGE_WITH_PE
4347
0
      if (! coff_apply_checksum (abfd))
4348
0
  return false;
4349
0
#endif
4350
0
    }
4351
#ifdef RS6000COFF_C
4352
#ifndef XCOFF64
4353
  else
4354
    {
4355
      AOUTHDR buff;
4356
      size_t size;
4357
4358
      /* XCOFF32 seems to always write at least a small a.out header.  */
4359
      coff_swap_aouthdr_out (abfd, & internal_a, & buff);
4360
      if (xcoff_data (abfd)->full_aouthdr)
4361
  size = bfd_coff_aoutsz (abfd);
4362
      else
4363
  size = SMALL_AOUTSZ;
4364
      if (bfd_write (&buff, size, abfd) != size)
4365
  return false;
4366
    }
4367
#endif
4368
#endif
4369
4370
2
  return true;
4371
2
}
pei-ia64.c:coff_write_object_contents
Line
Count
Source
3490
1
{
3491
1
  asection *current;
3492
1
  bool hasrelocs = false;
3493
1
  bool haslinno = false;
3494
1
#ifdef COFF_IMAGE_WITH_PE
3495
1
  bool hasdebug = false;
3496
1
#endif
3497
1
  file_ptr scn_base;
3498
1
  file_ptr reloc_base;
3499
1
  file_ptr lineno_base;
3500
1
  file_ptr sym_base;
3501
1
  unsigned long reloc_size = 0, reloc_count = 0;
3502
1
  unsigned long lnno_size = 0;
3503
1
  bool long_section_names;
3504
1
  asection *text_sec = NULL;
3505
1
  asection *data_sec = NULL;
3506
1
  asection *bss_sec = NULL;
3507
#ifdef RS6000COFF_C
3508
  asection *tdata_sec = NULL;
3509
  asection *tbss_sec = NULL;
3510
#endif
3511
1
  struct internal_filehdr internal_f;
3512
1
  struct internal_aouthdr internal_a;
3513
1
#ifdef COFF_LONG_SECTION_NAMES
3514
1
  size_t string_size = STRING_SIZE_SIZE;
3515
1
#endif
3516
3517
1
  bfd_set_error (bfd_error_system_call);
3518
3519
  /* Make a pass through the symbol table to count line number entries and
3520
     put them into the correct asections.  */
3521
1
  lnno_size = coff_count_linenumbers (abfd) * bfd_coff_linesz (abfd);
3522
3523
1
  if (! abfd->output_has_begun)
3524
0
    {
3525
0
      if (! coff_compute_section_file_positions (abfd))
3526
0
  return false;
3527
0
    }
3528
3529
1
  reloc_base = obj_relocbase (abfd);
3530
3531
  /* Work out the size of the reloc and linno areas.  */
3532
3533
3
  for (current = abfd->sections; current != NULL; current =
3534
2
       current->next)
3535
2
    {
3536
2
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3537
      /* We store the actual reloc count in the first reloc's addr.  */
3538
2
      if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3539
0
  reloc_count ++;
3540
2
#endif
3541
2
      reloc_count += current->reloc_count;
3542
2
    }
3543
3544
1
  reloc_size = reloc_count * bfd_coff_relsz (abfd);
3545
3546
1
  lineno_base = reloc_base + reloc_size;
3547
1
  sym_base = lineno_base + lnno_size;
3548
3549
  /* Indicate in each section->line_filepos its actual file address.  */
3550
3
  for (current = abfd->sections; current != NULL; current =
3551
2
       current->next)
3552
2
    {
3553
2
      if (current->lineno_count)
3554
0
  {
3555
0
    current->line_filepos = lineno_base;
3556
0
    current->moving_line_filepos = lineno_base;
3557
0
    lineno_base += current->lineno_count * bfd_coff_linesz (abfd);
3558
0
  }
3559
2
      else
3560
2
  current->line_filepos = 0;
3561
3562
2
      if (current->reloc_count)
3563
0
  {
3564
0
    current->rel_filepos = reloc_base;
3565
0
    reloc_base += current->reloc_count * bfd_coff_relsz (abfd);
3566
0
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3567
    /* Extra reloc to hold real count.  */
3568
0
    if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3569
0
      reloc_base += bfd_coff_relsz (abfd);
3570
0
#endif
3571
0
  }
3572
2
      else
3573
2
  current->rel_filepos = 0;
3574
2
    }
3575
3576
  /* Write section headers to the file.  */
3577
1
  internal_f.f_nscns = 0;
3578
3579
1
  if ((abfd->flags & EXEC_P) != 0)
3580
1
    scn_base = bfd_coff_filhsz (abfd) + bfd_coff_aoutsz (abfd);
3581
0
  else
3582
0
    {
3583
0
      scn_base = bfd_coff_filhsz (abfd);
3584
#ifdef RS6000COFF_C
3585
#ifndef XCOFF64
3586
      if (xcoff_data (abfd)->full_aouthdr)
3587
  scn_base += bfd_coff_aoutsz (abfd);
3588
      else
3589
  scn_base += SMALL_AOUTSZ;
3590
#endif
3591
#endif
3592
0
    }
3593
3594
1
  if (bfd_seek (abfd, scn_base, SEEK_SET) != 0)
3595
0
    return false;
3596
3597
1
  long_section_names = false;
3598
1
  for (current = abfd->sections;
3599
3
       current != NULL;
3600
2
       current = current->next)
3601
2
    {
3602
2
      struct internal_scnhdr section;
3603
2
#ifdef COFF_IMAGE_WITH_PE
3604
2
      bool is_reloc_section = false;
3605
3606
2
      if (strcmp (current->name, DOT_RELOC) == 0)
3607
0
  {
3608
0
    is_reloc_section = true;
3609
0
    hasrelocs = true;
3610
0
    pe_data (abfd)->has_reloc_section = 1;
3611
0
  }
3612
2
#endif
3613
3614
2
      internal_f.f_nscns++;
3615
3616
2
      strncpy (section.s_name, current->name, SCNNMLEN);
3617
3618
2
#ifdef COFF_LONG_SECTION_NAMES
3619
      /* Handle long section names as in PE.  This must be compatible
3620
   with the code in coff_write_symbols and _bfd_coff_final_link.  */
3621
2
      if (bfd_coff_long_section_names (abfd))
3622
0
  {
3623
0
    size_t len;
3624
3625
0
    len = strlen (current->name);
3626
0
    if (len > SCNNMLEN)
3627
0
      {
3628
3629
        /* An inherent limitation of the /nnnnnnn notation used to indicate
3630
     the offset of the long name in the string table is that we
3631
     cannot address entries beyone the ten million byte boundary.  */
3632
0
        if (string_size < 10000000)
3633
0
    {
3634
      /* The s_name field is defined to be NUL-padded but need not
3635
         be NUL-terminated.  We use a temporary buffer so that we
3636
         can still sprintf all eight chars without splatting a
3637
         terminating NUL over the first byte of the following
3638
         member (s_paddr).  */
3639
      /* PR 21096: The +20 is to stop a bogus warning from gcc7
3640
         about a possible buffer overflow.  */
3641
0
      char s_name_buf[SCNNMLEN + 1 + 20];
3642
3643
      /* We do not need to use snprintf here as we have already
3644
         verified that string_size is not too big, plus we have
3645
         an overlarge buffer, just in case.  */
3646
0
      sprintf (s_name_buf, "/%lu", (unsigned long) string_size);
3647
      /* Then strncpy takes care of any padding for us.  */
3648
0
      strncpy (section.s_name, s_name_buf, SCNNMLEN);
3649
0
    }
3650
0
        else
3651
0
#ifdef COFF_WITH_PE
3652
0
    {
3653
      /* PE use a base 64 encoding for long section names whose
3654
         index is very large.  But contrary to RFC 4648, there is
3655
         no padding: 6 characters must be generated.  */
3656
0
      static const char base64[] =
3657
0
        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
3658
0
        "abcdefghijklmnopqrstuvwxyz"
3659
0
        "0123456789+/";
3660
0
      unsigned long off = string_size;
3661
0
      unsigned i;
3662
3663
0
      section.s_name[0] = '/';
3664
0
      section.s_name[1] = '/';
3665
0
      for (i = SCNNMLEN - 1; i >= 2; i--)
3666
0
        {
3667
0
          section.s_name[i] = base64[off & 0x3f];
3668
0
          off >>= 6;
3669
0
        }
3670
0
    }
3671
0
#endif
3672
0
        if (string_size > 0xffffffffUL - (len + 1)
3673
#ifndef COFF_WITH_PE
3674
      || string_size >= 10000000
3675
#endif
3676
0
      )
3677
0
    {
3678
0
      bfd_set_error (bfd_error_file_too_big);
3679
0
      _bfd_error_handler
3680
        /* xgettext:c-format */
3681
0
        (_("%pB: section %pA: string table overflow at offset %ld"),
3682
0
        abfd, current, (unsigned long) string_size);
3683
0
      return false;
3684
0
    }
3685
3686
0
        string_size += len + 1;
3687
0
        long_section_names = true;
3688
0
      }
3689
0
  }
3690
2
#endif
3691
3692
2
#ifdef _LIB
3693
      /* Always set s_vaddr of .lib to 0.  This is right for SVR3.2
3694
   Ian Taylor <ian@cygnus.com>.  */
3695
2
      if (strcmp (current->name, _LIB) == 0)
3696
0
  section.s_vaddr = 0;
3697
2
      else
3698
2
#endif
3699
2
      section.s_vaddr = current->vma;
3700
2
      section.s_paddr = current->lma;
3701
2
      section.s_size =  current->size;
3702
#ifdef coff_get_section_load_page
3703
      section.s_page = coff_get_section_load_page (current);
3704
#else
3705
2
      section.s_page = 0;
3706
2
#endif
3707
3708
2
#ifdef COFF_WITH_PE
3709
2
      section.s_paddr = 0;
3710
2
#endif
3711
2
#ifdef COFF_IMAGE_WITH_PE
3712
      /* Reminder: s_paddr holds the virtual size of the section.  */
3713
2
      if (coff_section_data (abfd, current) != NULL
3714
2
    && pei_section_data (abfd, current) != NULL)
3715
2
  section.s_paddr = pei_section_data (abfd, current)->virt_size;
3716
0
      else
3717
0
  section.s_paddr = 0;
3718
2
#endif
3719
3720
      /* If this section has no size or is unloadable then the scnptr
3721
   will be 0 too.  */
3722
2
      if (current->size == 0
3723
2
    || (current->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
3724
0
  section.s_scnptr = 0;
3725
2
      else
3726
2
  section.s_scnptr = current->filepos;
3727
3728
2
      section.s_relptr = current->rel_filepos;
3729
2
      section.s_lnnoptr = current->line_filepos;
3730
2
      section.s_nreloc = current->reloc_count;
3731
2
      section.s_nlnno = current->lineno_count;
3732
#ifndef COFF_IMAGE_WITH_PE
3733
      /* In PEI, relocs come in the .reloc section.  */
3734
      if (current->reloc_count != 0)
3735
  hasrelocs = true;
3736
#endif
3737
2
      if (current->lineno_count != 0)
3738
0
  haslinno = true;
3739
2
#ifdef COFF_IMAGE_WITH_PE
3740
2
      if ((current->flags & SEC_DEBUGGING) != 0
3741
2
    && ! is_reloc_section)
3742
2
  hasdebug = true;
3743
2
#endif
3744
3745
#ifdef RS6000COFF_C
3746
#ifndef XCOFF64
3747
      /* Indicate the use of an XCOFF overflow section header.  */
3748
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3749
  {
3750
    section.s_nreloc = 0xffff;
3751
    section.s_nlnno = 0xffff;
3752
  }
3753
#endif
3754
#endif
3755
3756
2
      section.s_flags = sec_to_styp_flags (current->name, current->flags);
3757
3758
2
      if (!strcmp (current->name, _TEXT))
3759
0
  text_sec = current;
3760
2
      else if (!strcmp (current->name, _DATA))
3761
0
  data_sec = current;
3762
2
      else if (!strcmp (current->name, _BSS))
3763
0
  bss_sec = current;
3764
#ifdef RS6000COFF_C
3765
      else if (!strcmp (current->name, _TDATA))
3766
  tdata_sec = current;
3767
      else if (!strcmp (current->name, _TBSS))
3768
  tbss_sec = current;
3769
#endif
3770
3771
3772
2
#ifdef COFF_ENCODE_ALIGNMENT
3773
2
      if (COFF_ENCODE_ALIGNMENT (abfd, section, current->alignment_power)
3774
2
    && (COFF_DECODE_ALIGNMENT (section.s_flags)
3775
0
        != current->alignment_power))
3776
0
  {
3777
0
    bool warn = (coff_data (abfd)->link_info
3778
0
           && !bfd_link_relocatable (coff_data (abfd)->link_info));
3779
3780
0
    _bfd_error_handler
3781
      /* xgettext:c-format */
3782
0
      (_("%pB:%s section %s: alignment 2**%u not representable"),
3783
0
       abfd, warn ? " warning:" : "", current->name,
3784
0
       current->alignment_power);
3785
0
    if (!warn)
3786
0
      {
3787
0
        bfd_set_error (bfd_error_nonrepresentable_section);
3788
0
        return false;
3789
0
      }
3790
0
  }
3791
2
#endif
3792
3793
2
#ifdef COFF_IMAGE_WITH_PE
3794
      /* Suppress output of the sections if they are null.  ld
3795
   includes the bss and data sections even if there is no size
3796
   assigned to them.  NT loader doesn't like it if these section
3797
   headers are included if the sections themselves are not
3798
   needed.  See also coff_compute_section_file_positions.  */
3799
2
      if (section.s_size == 0)
3800
0
  internal_f.f_nscns--;
3801
2
      else
3802
2
#endif
3803
2
  {
3804
2
    SCNHDR buff;
3805
2
    bfd_size_type amt = bfd_coff_scnhsz (abfd);
3806
3807
2
    if (bfd_coff_swap_scnhdr_out (abfd, &section, &buff) == 0
3808
2
        || bfd_write (& buff, amt, abfd) != amt)
3809
0
      return false;
3810
2
  }
3811
3812
2
#ifdef COFF_WITH_PE
3813
      /* PE stores COMDAT section information in the symbol table.  If
3814
   this section is supposed to have some COMDAT info, track down
3815
   the symbol in the symbol table and modify it.  */
3816
2
      if ((current->flags & SEC_LINK_ONCE) != 0)
3817
0
  {
3818
0
    unsigned int i, count;
3819
0
    asymbol **psym;
3820
0
    coff_symbol_type *csym = NULL;
3821
0
    asymbol **psymsec;
3822
3823
0
    psymsec = NULL;
3824
0
    count = bfd_get_symcount (abfd);
3825
0
    for (i = 0, psym = abfd->outsymbols; i < count; i++, psym++)
3826
0
      {
3827
0
        if ((*psym)->section != current)
3828
0
    continue;
3829
3830
        /* Remember the location of the first symbol in this
3831
     section.  */
3832
0
        if (psymsec == NULL)
3833
0
    psymsec = psym;
3834
3835
        /* See if this is the section symbol.  */
3836
0
        if (strcmp ((*psym)->name, current->name) == 0)
3837
0
    {
3838
0
      csym = coff_symbol_from (*psym);
3839
0
      if (csym == NULL
3840
0
          || csym->native == NULL
3841
0
          || ! csym->native->is_sym
3842
0
          || csym->native->u.syment.n_numaux < 1
3843
0
          || csym->native->u.syment.n_sclass != C_STAT
3844
0
          || csym->native->u.syment.n_type != T_NULL)
3845
0
        continue;
3846
3847
      /* Here *PSYM is the section symbol for CURRENT.  */
3848
3849
0
      break;
3850
0
    }
3851
0
      }
3852
3853
    /* Did we find it?
3854
       Note that we might not if we're converting the file from
3855
       some other object file format.  */
3856
0
    if (i < count)
3857
0
      {
3858
0
        combined_entry_type *aux;
3859
3860
        /* We don't touch the x_checksum field.  The
3861
     x_associated field is not currently supported.  */
3862
3863
0
        aux = csym->native + 1;
3864
0
        BFD_ASSERT (! aux->is_sym);
3865
0
        switch (current->flags & SEC_LINK_DUPLICATES)
3866
0
    {
3867
0
    case SEC_LINK_DUPLICATES_DISCARD:
3868
0
      aux->u.auxent.x_scn.x_comdat = IMAGE_COMDAT_SELECT_ANY;
3869
0
      break;
3870
3871
0
    case SEC_LINK_DUPLICATES_ONE_ONLY:
3872
0
      aux->u.auxent.x_scn.x_comdat =
3873
0
        IMAGE_COMDAT_SELECT_NODUPLICATES;
3874
0
      break;
3875
3876
0
    case SEC_LINK_DUPLICATES_SAME_SIZE:
3877
0
      aux->u.auxent.x_scn.x_comdat =
3878
0
        IMAGE_COMDAT_SELECT_SAME_SIZE;
3879
0
      break;
3880
3881
0
    case SEC_LINK_DUPLICATES_SAME_CONTENTS:
3882
0
      aux->u.auxent.x_scn.x_comdat =
3883
0
        IMAGE_COMDAT_SELECT_EXACT_MATCH;
3884
0
      break;
3885
0
    }
3886
3887
        /* The COMDAT symbol must be the first symbol from this
3888
     section in the symbol table.  In order to make this
3889
     work, we move the COMDAT symbol before the first
3890
     symbol we found in the search above.  It's OK to
3891
     rearrange the symbol table at this point, because
3892
     coff_renumber_symbols is going to rearrange it
3893
     further and fix up all the aux entries.  */
3894
0
        if (psym != psymsec)
3895
0
    {
3896
0
      asymbol *hold;
3897
0
      asymbol **pcopy;
3898
3899
0
      hold = *psym;
3900
0
      for (pcopy = psym; pcopy > psymsec; pcopy--)
3901
0
        pcopy[0] = pcopy[-1];
3902
0
      *psymsec = hold;
3903
0
    }
3904
0
      }
3905
0
  }
3906
2
#endif /* COFF_WITH_PE */
3907
2
    }
3908
3909
#ifdef RS6000COFF_C
3910
#ifndef XCOFF64
3911
  /* XCOFF handles overflows in the reloc and line number count fields
3912
     by creating a new section header to hold the correct values.  */
3913
  for (current = abfd->sections; current != NULL; current = current->next)
3914
    {
3915
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3916
  {
3917
    struct internal_scnhdr scnhdr;
3918
    SCNHDR buff;
3919
    bfd_size_type amt;
3920
3921
    internal_f.f_nscns++;
3922
    memcpy (scnhdr.s_name, ".ovrflo", 8);
3923
    scnhdr.s_paddr = current->reloc_count;
3924
    scnhdr.s_vaddr = current->lineno_count;
3925
    scnhdr.s_size = 0;
3926
    scnhdr.s_scnptr = 0;
3927
    scnhdr.s_relptr = current->rel_filepos;
3928
    scnhdr.s_lnnoptr = current->line_filepos;
3929
    scnhdr.s_nreloc = current->target_index;
3930
    scnhdr.s_nlnno = current->target_index;
3931
    scnhdr.s_flags = STYP_OVRFLO;
3932
    amt = bfd_coff_scnhsz (abfd);
3933
    if (bfd_coff_swap_scnhdr_out (abfd, &scnhdr, &buff) == 0
3934
        || bfd_write (& buff, amt, abfd) != amt)
3935
      return false;
3936
  }
3937
    }
3938
#endif
3939
#endif
3940
3941
#if defined (COFF_GO32_EXE) || defined (COFF_GO32)
3942
  /* Pad section headers.  */
3943
  if ((abfd->flags & EXEC_P) != 0)
3944
    {
3945
      asection *s = abfd->sections;
3946
      while (s != NULL && s->filepos == 0)
3947
  s = s->next;
3948
      if (s != NULL)
3949
  {
3950
    file_ptr cur_ptr
3951
      = scn_base + abfd->section_count * bfd_coff_scnhsz (abfd);
3952
    file_ptr fill_size = s->filepos - cur_ptr;
3953
    if (fill_size > 0)
3954
      {
3955
        bfd_byte *b = bfd_zmalloc (fill_size);
3956
        if (!b)
3957
    return false;
3958
        if (bfd_write (b, fill_size, abfd) != (ufile_ptr) fill_size)
3959
    {
3960
      free (b);
3961
      return false;
3962
    }
3963
        free (b);
3964
      }
3965
  }
3966
    }
3967
#endif
3968
3969
  /* OK, now set up the filehdr...  */
3970
3971
  /* Don't include the internal abs section in the section count */
3972
3973
  /* We will NOT put a fucking timestamp in the header here. Every time you
3974
     put it back, I will come in and take it out again.  I'm sorry.  This
3975
     field does not belong here.  We fill it with a 0 so it compares the
3976
     same but is not a reasonable time. -- gnu@cygnus.com  */
3977
1
  internal_f.f_timdat = 0;
3978
1
  internal_f.f_flags = 0;
3979
3980
1
  if (abfd->flags & EXEC_P)
3981
1
    internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3982
0
  else
3983
0
    {
3984
0
      internal_f.f_opthdr = 0;
3985
#ifdef RS6000COFF_C
3986
#ifndef XCOFF64
3987
      if (xcoff_data (abfd)->full_aouthdr)
3988
  internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3989
      else
3990
  internal_f.f_opthdr = SMALL_AOUTSZ;
3991
#endif
3992
#endif
3993
0
    }
3994
3995
1
  if (!hasrelocs)
3996
1
    internal_f.f_flags |= F_RELFLG;
3997
1
  if (!haslinno)
3998
1
    internal_f.f_flags |= F_LNNO;
3999
1
  if (abfd->flags & EXEC_P)
4000
1
    internal_f.f_flags |= F_EXEC;
4001
1
#ifdef COFF_IMAGE_WITH_PE
4002
1
  if (! hasdebug)
4003
0
    internal_f.f_flags |= IMAGE_FILE_DEBUG_STRIPPED;
4004
1
  if (pe_data (abfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
4005
1
    internal_f.f_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
4006
1
#endif
4007
4008
1
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64) && !defined (COFF_WITH_peRiscV64)
4009
1
#ifdef COFF_WITH_PE
4010
1
  internal_f.f_flags |= IMAGE_FILE_32BIT_MACHINE;
4011
#else
4012
  if (bfd_little_endian (abfd))
4013
    internal_f.f_flags |= F_AR32WR;
4014
  else
4015
    internal_f.f_flags |= F_AR32W;
4016
#endif
4017
1
#endif
4018
4019
#ifdef TI_TARGET_ID
4020
  /* Target id is used in TI COFF v1 and later; COFF0 won't use this field,
4021
     but it doesn't hurt to set it internally.  */
4022
  internal_f.f_target_id = TI_TARGET_ID;
4023
#endif
4024
4025
  /* FIXME, should do something about the other byte orders and
4026
     architectures.  */
4027
4028
#ifdef RS6000COFF_C
4029
  if ((abfd->flags & DYNAMIC) != 0)
4030
    internal_f.f_flags |= F_SHROBJ;
4031
  if (bfd_get_section_by_name (abfd, _LOADER) != NULL)
4032
    internal_f.f_flags |= F_DYNLOAD;
4033
#endif
4034
4035
1
  memset (&internal_a, 0, sizeof internal_a);
4036
4037
  /* Set up architecture-dependent stuff.  */
4038
1
  {
4039
1
    unsigned int magic = 0;
4040
1
    unsigned short flags = 0;
4041
4042
1
    coff_set_flags (abfd, &magic, &flags);
4043
1
    internal_f.f_magic = magic;
4044
1
    internal_f.f_flags |= flags;
4045
    /* ...and the "opt"hdr...  */
4046
4047
#ifdef TICOFF_AOUT_MAGIC
4048
    internal_a.magic = TICOFF_AOUT_MAGIC;
4049
#define __A_MAGIC_SET__
4050
#endif
4051
4052
#if defined(ARM)
4053
#define __A_MAGIC_SET__
4054
    internal_a.magic = ZMAGIC;
4055
#endif
4056
4057
#if defined(AARCH64)
4058
#define __A_MAGIC_SET__
4059
    internal_a.magic = ZMAGIC;
4060
#endif
4061
4062
#if defined(LOONGARCH64)
4063
#define __A_MAGIC_SET__
4064
    internal_a.magic = ZMAGIC;
4065
#endif
4066
4067
#if defined(RISCV64)
4068
#define __A_MAGIC_SET__
4069
    internal_a.magic = ZMAGIC;
4070
#endif
4071
4072
#if defined MCORE_PE
4073
#define __A_MAGIC_SET__
4074
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR_MAGIC;
4075
#endif
4076
4077
#if defined(I386)
4078
#define __A_MAGIC_SET__
4079
#if defined LYNXOS
4080
    internal_a.magic = LYNXCOFFMAGIC;
4081
#elif defined AMD64
4082
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR64_MAGIC;
4083
#else
4084
    internal_a.magic = ZMAGIC;
4085
#endif
4086
#endif /* I386 */
4087
4088
1
#if defined(IA64)
4089
1
#define __A_MAGIC_SET__
4090
1
    internal_a.magic = PE32PMAGIC;
4091
1
#endif /* IA64 */
4092
4093
#if defined(SPARC)
4094
#define __A_MAGIC_SET__
4095
#if defined(LYNXOS)
4096
    internal_a.magic = LYNXCOFFMAGIC;
4097
#endif /* LYNXOS */
4098
#endif /* SPARC */
4099
4100
#ifdef RS6000COFF_C
4101
#define __A_MAGIC_SET__
4102
    internal_a.magic = (abfd->flags & D_PAGED) ? RS6K_AOUTHDR_ZMAGIC :
4103
    (abfd->flags & WP_TEXT) ? RS6K_AOUTHDR_NMAGIC :
4104
    RS6K_AOUTHDR_OMAGIC;
4105
#endif
4106
4107
#if defined(SH) && defined(COFF_WITH_PE)
4108
#define __A_MAGIC_SET__
4109
    internal_a.magic = SH_PE_MAGIC;
4110
#endif
4111
4112
#if defined(MIPS) && defined(COFF_WITH_PE)
4113
#define __A_MAGIC_SET__
4114
    internal_a.magic = MIPS_PE_MAGIC;
4115
#endif
4116
4117
#ifndef __A_MAGIC_SET__
4118
#include "Your aouthdr magic number is not being set!"
4119
#else
4120
1
#undef __A_MAGIC_SET__
4121
1
#endif
4122
1
  }
4123
4124
#ifdef RS6000COFF_C
4125
  /* XCOFF 32bit needs this to have new behaviour for n_type field.  */
4126
  internal_a.vstamp = 2;
4127
#else
4128
  /* FIXME: Does anybody ever set this to another value?  */
4129
1
  internal_a.vstamp = 0;
4130
1
#endif
4131
4132
  /* Now should write relocs, strings, syms.  */
4133
1
  obj_sym_filepos (abfd) = sym_base;
4134
4135
1
  if (bfd_get_symcount (abfd) != 0)
4136
0
    {
4137
0
      int firstundef;
4138
4139
0
      if (!coff_renumber_symbols (abfd, &firstundef))
4140
0
  return false;
4141
0
      coff_mangle_symbols (abfd);
4142
0
      if (! coff_write_symbols (abfd))
4143
0
  return false;
4144
0
      if (! coff_write_linenumbers (abfd))
4145
0
  return false;
4146
0
      if (! coff_write_relocs (abfd, firstundef))
4147
0
  return false;
4148
0
    }
4149
1
#ifdef COFF_LONG_SECTION_NAMES
4150
1
  else if (long_section_names && ! obj_coff_strings_written (abfd))
4151
0
    {
4152
      /* If we have long section names we have to write out the string
4153
   table even if there are no symbols.  */
4154
0
      if (! coff_write_symbols (abfd))
4155
0
  return false;
4156
0
    }
4157
1
#endif
4158
  /* If bfd_get_symcount (abfd) != 0, then we are not using the COFF
4159
     backend linker, and obj_raw_syment_count is not valid until after
4160
     coff_write_symbols is called.  */
4161
1
  if (obj_raw_syment_count (abfd) != 0)
4162
0
    {
4163
0
      internal_f.f_symptr = sym_base;
4164
#ifdef RS6000COFF_C
4165
      /* AIX appears to require that F_RELFLG not be set if there are
4166
   local symbols but no relocations.  */
4167
      internal_f.f_flags &=~ F_RELFLG;
4168
#endif
4169
0
    }
4170
1
  else
4171
1
    {
4172
1
      if (long_section_names)
4173
0
  internal_f.f_symptr = sym_base;
4174
1
      else
4175
1
  internal_f.f_symptr = 0;
4176
1
      internal_f.f_flags |= F_LSYMS;
4177
1
    }
4178
4179
1
  if (text_sec)
4180
0
    {
4181
0
      internal_a.tsize = text_sec->size;
4182
0
      internal_a.text_start = internal_a.tsize ? text_sec->vma : 0;
4183
0
    }
4184
1
  if (data_sec)
4185
0
    {
4186
0
      internal_a.dsize = data_sec->size;
4187
0
      internal_a.data_start = internal_a.dsize ? data_sec->vma : 0;
4188
0
    }
4189
1
  if (bss_sec)
4190
0
    {
4191
0
      internal_a.bsize = bss_sec->size;
4192
0
      if (internal_a.bsize && bss_sec->vma < internal_a.data_start)
4193
0
  internal_a.data_start = bss_sec->vma;
4194
0
    }
4195
4196
1
  internal_a.entry = bfd_get_start_address (abfd);
4197
1
  internal_f.f_nsyms = obj_raw_syment_count (abfd);
4198
4199
#ifdef RS6000COFF_C
4200
  if (xcoff_data (abfd)->full_aouthdr)
4201
    {
4202
      bfd_vma toc;
4203
      asection *loader_sec;
4204
4205
      internal_a.vstamp = 2;
4206
4207
      internal_a.o_snentry = xcoff_data (abfd)->snentry;
4208
      if (internal_a.o_snentry == 0)
4209
  internal_a.entry = (bfd_vma) -1;
4210
4211
      if (text_sec != NULL)
4212
  {
4213
    internal_a.o_sntext = text_sec->target_index;
4214
    internal_a.o_algntext = bfd_section_alignment (text_sec);
4215
  }
4216
      else
4217
  {
4218
    internal_a.o_sntext = 0;
4219
    internal_a.o_algntext = 0;
4220
  }
4221
      if (data_sec != NULL)
4222
  {
4223
    internal_a.o_sndata = data_sec->target_index;
4224
    internal_a.o_algndata = bfd_section_alignment (data_sec);
4225
  }
4226
      else
4227
  {
4228
    internal_a.o_sndata = 0;
4229
    internal_a.o_algndata = 0;
4230
  }
4231
      loader_sec = bfd_get_section_by_name (abfd, ".loader");
4232
      if (loader_sec != NULL)
4233
  internal_a.o_snloader = loader_sec->target_index;
4234
      else
4235
  internal_a.o_snloader = 0;
4236
      if (bss_sec != NULL)
4237
  internal_a.o_snbss = bss_sec->target_index;
4238
      else
4239
  internal_a.o_snbss = 0;
4240
4241
      if (tdata_sec != NULL)
4242
  {
4243
    internal_a.o_sntdata = tdata_sec->target_index;
4244
    /* TODO: o_flags should be set to RS6K_AOUTHDR_TLS_LE
4245
       if there is at least one R_TLS_LE relocations.  */
4246
    internal_a.o_flags = 0;
4247
#ifdef XCOFF64
4248
    internal_a.o_x64flags = 0;
4249
#endif
4250
  }
4251
      else
4252
  {
4253
    internal_a.o_sntdata = 0;
4254
    internal_a.o_flags = 0;
4255
#ifdef XCOFF64
4256
    internal_a.o_x64flags = 0;
4257
#endif
4258
  }
4259
      if (tbss_sec != NULL)
4260
    internal_a.o_sntbss = tbss_sec->target_index;
4261
      else
4262
    internal_a.o_sntbss = 0;
4263
4264
      toc = xcoff_data (abfd)->toc;
4265
      internal_a.o_toc = toc;
4266
      internal_a.o_sntoc = xcoff_data (abfd)->sntoc;
4267
4268
      internal_a.o_modtype = xcoff_data (abfd)->modtype;
4269
      if (xcoff_data (abfd)->cputype != -1)
4270
  internal_a.o_cputype = xcoff_data (abfd)->cputype;
4271
      else
4272
  {
4273
    switch (bfd_get_arch (abfd))
4274
      {
4275
      case bfd_arch_rs6000:
4276
        internal_a.o_cputype = 4;
4277
        break;
4278
      case bfd_arch_powerpc:
4279
        if (bfd_get_mach (abfd) == bfd_mach_ppc)
4280
    internal_a.o_cputype = 3;
4281
        else if (bfd_get_mach (abfd) == bfd_mach_ppc_620)
4282
    internal_a.o_cputype = 2;
4283
        else
4284
    internal_a.o_cputype = 1;
4285
        break;
4286
      default:
4287
        abort ();
4288
      }
4289
  }
4290
      internal_a.o_maxstack = xcoff_data (abfd)->maxstack;
4291
      internal_a.o_maxdata = xcoff_data (abfd)->maxdata;
4292
    }
4293
#endif
4294
4295
1
#ifdef COFF_WITH_PE
4296
1
  {
4297
    /* After object contents are finalized so we can compute a reasonable hash,
4298
       but before header is written so we can update it to point to debug directory.  */
4299
1
    struct pe_tdata *pe = pe_data (abfd);
4300
4301
1
    if (pe->build_id.after_write_object_contents != NULL)
4302
0
      (*pe->build_id.after_write_object_contents) (abfd);
4303
1
  }
4304
1
#endif
4305
4306
  /* Now write header.  */
4307
1
  if (bfd_seek (abfd, 0, SEEK_SET) != 0)
4308
0
    return false;
4309
4310
1
  {
4311
1
    char * buff;
4312
1
    bfd_size_type amount = bfd_coff_filhsz (abfd);
4313
4314
1
    buff = (char *) bfd_malloc (amount);
4315
1
    if (buff == NULL)
4316
0
      return false;
4317
4318
1
    bfd_coff_swap_filehdr_out (abfd, & internal_f, buff);
4319
1
    amount = bfd_write (buff, amount, abfd);
4320
4321
1
    free (buff);
4322
4323
1
    if (amount != bfd_coff_filhsz (abfd))
4324
0
      return false;
4325
1
  }
4326
4327
1
  if (abfd->flags & EXEC_P)
4328
1
    {
4329
      /* Note that peicode.h fills in a PEAOUTHDR, not an AOUTHDR.
4330
   include/coff/pe.h sets AOUTSZ == sizeof (PEAOUTHDR)).  */
4331
1
      char * buff;
4332
1
      bfd_size_type amount = bfd_coff_aoutsz (abfd);
4333
4334
1
      buff = (char *) bfd_malloc (amount);
4335
1
      if (buff == NULL)
4336
0
  return false;
4337
4338
1
      coff_swap_aouthdr_out (abfd, & internal_a, buff);
4339
1
      amount = bfd_write (buff, amount, abfd);
4340
4341
1
      free (buff);
4342
4343
1
      if (amount != bfd_coff_aoutsz (abfd))
4344
0
  return false;
4345
4346
1
#ifdef COFF_IMAGE_WITH_PE
4347
1
      if (! coff_apply_checksum (abfd))
4348
0
  return false;
4349
1
#endif
4350
1
    }
4351
#ifdef RS6000COFF_C
4352
#ifndef XCOFF64
4353
  else
4354
    {
4355
      AOUTHDR buff;
4356
      size_t size;
4357
4358
      /* XCOFF32 seems to always write at least a small a.out header.  */
4359
      coff_swap_aouthdr_out (abfd, & internal_a, & buff);
4360
      if (xcoff_data (abfd)->full_aouthdr)
4361
  size = bfd_coff_aoutsz (abfd);
4362
      else
4363
  size = SMALL_AOUTSZ;
4364
      if (bfd_write (&buff, size, abfd) != size)
4365
  return false;
4366
    }
4367
#endif
4368
#endif
4369
4370
1
  return true;
4371
1
}
Unexecuted instantiation: pei-loongarch64.c:coff_write_object_contents
pei-riscv64.c:coff_write_object_contents
Line
Count
Source
3490
5
{
3491
5
  asection *current;
3492
5
  bool hasrelocs = false;
3493
5
  bool haslinno = false;
3494
5
#ifdef COFF_IMAGE_WITH_PE
3495
5
  bool hasdebug = false;
3496
5
#endif
3497
5
  file_ptr scn_base;
3498
5
  file_ptr reloc_base;
3499
5
  file_ptr lineno_base;
3500
5
  file_ptr sym_base;
3501
5
  unsigned long reloc_size = 0, reloc_count = 0;
3502
5
  unsigned long lnno_size = 0;
3503
5
  bool long_section_names;
3504
5
  asection *text_sec = NULL;
3505
5
  asection *data_sec = NULL;
3506
5
  asection *bss_sec = NULL;
3507
#ifdef RS6000COFF_C
3508
  asection *tdata_sec = NULL;
3509
  asection *tbss_sec = NULL;
3510
#endif
3511
5
  struct internal_filehdr internal_f;
3512
5
  struct internal_aouthdr internal_a;
3513
5
#ifdef COFF_LONG_SECTION_NAMES
3514
5
  size_t string_size = STRING_SIZE_SIZE;
3515
5
#endif
3516
3517
5
  bfd_set_error (bfd_error_system_call);
3518
3519
  /* Make a pass through the symbol table to count line number entries and
3520
     put them into the correct asections.  */
3521
5
  lnno_size = coff_count_linenumbers (abfd) * bfd_coff_linesz (abfd);
3522
3523
5
  if (! abfd->output_has_begun)
3524
3
    {
3525
3
      if (! coff_compute_section_file_positions (abfd))
3526
0
  return false;
3527
3
    }
3528
3529
5
  reloc_base = obj_relocbase (abfd);
3530
3531
  /* Work out the size of the reloc and linno areas.  */
3532
3533
21
  for (current = abfd->sections; current != NULL; current =
3534
16
       current->next)
3535
16
    {
3536
16
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3537
      /* We store the actual reloc count in the first reloc's addr.  */
3538
16
      if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3539
0
  reloc_count ++;
3540
16
#endif
3541
16
      reloc_count += current->reloc_count;
3542
16
    }
3543
3544
5
  reloc_size = reloc_count * bfd_coff_relsz (abfd);
3545
3546
5
  lineno_base = reloc_base + reloc_size;
3547
5
  sym_base = lineno_base + lnno_size;
3548
3549
  /* Indicate in each section->line_filepos its actual file address.  */
3550
21
  for (current = abfd->sections; current != NULL; current =
3551
16
       current->next)
3552
16
    {
3553
16
      if (current->lineno_count)
3554
0
  {
3555
0
    current->line_filepos = lineno_base;
3556
0
    current->moving_line_filepos = lineno_base;
3557
0
    lineno_base += current->lineno_count * bfd_coff_linesz (abfd);
3558
0
  }
3559
16
      else
3560
16
  current->line_filepos = 0;
3561
3562
16
      if (current->reloc_count)
3563
0
  {
3564
0
    current->rel_filepos = reloc_base;
3565
0
    reloc_base += current->reloc_count * bfd_coff_relsz (abfd);
3566
0
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3567
    /* Extra reloc to hold real count.  */
3568
0
    if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3569
0
      reloc_base += bfd_coff_relsz (abfd);
3570
0
#endif
3571
0
  }
3572
16
      else
3573
16
  current->rel_filepos = 0;
3574
16
    }
3575
3576
  /* Write section headers to the file.  */
3577
5
  internal_f.f_nscns = 0;
3578
3579
5
  if ((abfd->flags & EXEC_P) != 0)
3580
5
    scn_base = bfd_coff_filhsz (abfd) + bfd_coff_aoutsz (abfd);
3581
0
  else
3582
0
    {
3583
0
      scn_base = bfd_coff_filhsz (abfd);
3584
#ifdef RS6000COFF_C
3585
#ifndef XCOFF64
3586
      if (xcoff_data (abfd)->full_aouthdr)
3587
  scn_base += bfd_coff_aoutsz (abfd);
3588
      else
3589
  scn_base += SMALL_AOUTSZ;
3590
#endif
3591
#endif
3592
0
    }
3593
3594
5
  if (bfd_seek (abfd, scn_base, SEEK_SET) != 0)
3595
0
    return false;
3596
3597
5
  long_section_names = false;
3598
5
  for (current = abfd->sections;
3599
21
       current != NULL;
3600
16
       current = current->next)
3601
16
    {
3602
16
      struct internal_scnhdr section;
3603
16
#ifdef COFF_IMAGE_WITH_PE
3604
16
      bool is_reloc_section = false;
3605
3606
16
      if (strcmp (current->name, DOT_RELOC) == 0)
3607
0
  {
3608
0
    is_reloc_section = true;
3609
0
    hasrelocs = true;
3610
0
    pe_data (abfd)->has_reloc_section = 1;
3611
0
  }
3612
16
#endif
3613
3614
16
      internal_f.f_nscns++;
3615
3616
16
      strncpy (section.s_name, current->name, SCNNMLEN);
3617
3618
16
#ifdef COFF_LONG_SECTION_NAMES
3619
      /* Handle long section names as in PE.  This must be compatible
3620
   with the code in coff_write_symbols and _bfd_coff_final_link.  */
3621
16
      if (bfd_coff_long_section_names (abfd))
3622
0
  {
3623
0
    size_t len;
3624
3625
0
    len = strlen (current->name);
3626
0
    if (len > SCNNMLEN)
3627
0
      {
3628
3629
        /* An inherent limitation of the /nnnnnnn notation used to indicate
3630
     the offset of the long name in the string table is that we
3631
     cannot address entries beyone the ten million byte boundary.  */
3632
0
        if (string_size < 10000000)
3633
0
    {
3634
      /* The s_name field is defined to be NUL-padded but need not
3635
         be NUL-terminated.  We use a temporary buffer so that we
3636
         can still sprintf all eight chars without splatting a
3637
         terminating NUL over the first byte of the following
3638
         member (s_paddr).  */
3639
      /* PR 21096: The +20 is to stop a bogus warning from gcc7
3640
         about a possible buffer overflow.  */
3641
0
      char s_name_buf[SCNNMLEN + 1 + 20];
3642
3643
      /* We do not need to use snprintf here as we have already
3644
         verified that string_size is not too big, plus we have
3645
         an overlarge buffer, just in case.  */
3646
0
      sprintf (s_name_buf, "/%lu", (unsigned long) string_size);
3647
      /* Then strncpy takes care of any padding for us.  */
3648
0
      strncpy (section.s_name, s_name_buf, SCNNMLEN);
3649
0
    }
3650
0
        else
3651
0
#ifdef COFF_WITH_PE
3652
0
    {
3653
      /* PE use a base 64 encoding for long section names whose
3654
         index is very large.  But contrary to RFC 4648, there is
3655
         no padding: 6 characters must be generated.  */
3656
0
      static const char base64[] =
3657
0
        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
3658
0
        "abcdefghijklmnopqrstuvwxyz"
3659
0
        "0123456789+/";
3660
0
      unsigned long off = string_size;
3661
0
      unsigned i;
3662
3663
0
      section.s_name[0] = '/';
3664
0
      section.s_name[1] = '/';
3665
0
      for (i = SCNNMLEN - 1; i >= 2; i--)
3666
0
        {
3667
0
          section.s_name[i] = base64[off & 0x3f];
3668
0
          off >>= 6;
3669
0
        }
3670
0
    }
3671
0
#endif
3672
0
        if (string_size > 0xffffffffUL - (len + 1)
3673
#ifndef COFF_WITH_PE
3674
      || string_size >= 10000000
3675
#endif
3676
0
      )
3677
0
    {
3678
0
      bfd_set_error (bfd_error_file_too_big);
3679
0
      _bfd_error_handler
3680
        /* xgettext:c-format */
3681
0
        (_("%pB: section %pA: string table overflow at offset %ld"),
3682
0
        abfd, current, (unsigned long) string_size);
3683
0
      return false;
3684
0
    }
3685
3686
0
        string_size += len + 1;
3687
0
        long_section_names = true;
3688
0
      }
3689
0
  }
3690
16
#endif
3691
3692
16
#ifdef _LIB
3693
      /* Always set s_vaddr of .lib to 0.  This is right for SVR3.2
3694
   Ian Taylor <ian@cygnus.com>.  */
3695
16
      if (strcmp (current->name, _LIB) == 0)
3696
0
  section.s_vaddr = 0;
3697
16
      else
3698
16
#endif
3699
16
      section.s_vaddr = current->vma;
3700
16
      section.s_paddr = current->lma;
3701
16
      section.s_size =  current->size;
3702
#ifdef coff_get_section_load_page
3703
      section.s_page = coff_get_section_load_page (current);
3704
#else
3705
16
      section.s_page = 0;
3706
16
#endif
3707
3708
16
#ifdef COFF_WITH_PE
3709
16
      section.s_paddr = 0;
3710
16
#endif
3711
16
#ifdef COFF_IMAGE_WITH_PE
3712
      /* Reminder: s_paddr holds the virtual size of the section.  */
3713
16
      if (coff_section_data (abfd, current) != NULL
3714
16
    && pei_section_data (abfd, current) != NULL)
3715
16
  section.s_paddr = pei_section_data (abfd, current)->virt_size;
3716
0
      else
3717
0
  section.s_paddr = 0;
3718
16
#endif
3719
3720
      /* If this section has no size or is unloadable then the scnptr
3721
   will be 0 too.  */
3722
16
      if (current->size == 0
3723
16
    || (current->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
3724
12
  section.s_scnptr = 0;
3725
4
      else
3726
4
  section.s_scnptr = current->filepos;
3727
3728
16
      section.s_relptr = current->rel_filepos;
3729
16
      section.s_lnnoptr = current->line_filepos;
3730
16
      section.s_nreloc = current->reloc_count;
3731
16
      section.s_nlnno = current->lineno_count;
3732
#ifndef COFF_IMAGE_WITH_PE
3733
      /* In PEI, relocs come in the .reloc section.  */
3734
      if (current->reloc_count != 0)
3735
  hasrelocs = true;
3736
#endif
3737
16
      if (current->lineno_count != 0)
3738
0
  haslinno = true;
3739
16
#ifdef COFF_IMAGE_WITH_PE
3740
16
      if ((current->flags & SEC_DEBUGGING) != 0
3741
16
    && ! is_reloc_section)
3742
4
  hasdebug = true;
3743
16
#endif
3744
3745
#ifdef RS6000COFF_C
3746
#ifndef XCOFF64
3747
      /* Indicate the use of an XCOFF overflow section header.  */
3748
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3749
  {
3750
    section.s_nreloc = 0xffff;
3751
    section.s_nlnno = 0xffff;
3752
  }
3753
#endif
3754
#endif
3755
3756
16
      section.s_flags = sec_to_styp_flags (current->name, current->flags);
3757
3758
16
      if (!strcmp (current->name, _TEXT))
3759
0
  text_sec = current;
3760
16
      else if (!strcmp (current->name, _DATA))
3761
0
  data_sec = current;
3762
16
      else if (!strcmp (current->name, _BSS))
3763
0
  bss_sec = current;
3764
#ifdef RS6000COFF_C
3765
      else if (!strcmp (current->name, _TDATA))
3766
  tdata_sec = current;
3767
      else if (!strcmp (current->name, _TBSS))
3768
  tbss_sec = current;
3769
#endif
3770
3771
3772
16
#ifdef COFF_ENCODE_ALIGNMENT
3773
16
      if (COFF_ENCODE_ALIGNMENT (abfd, section, current->alignment_power)
3774
16
    && (COFF_DECODE_ALIGNMENT (section.s_flags)
3775
0
        != current->alignment_power))
3776
0
  {
3777
0
    bool warn = (coff_data (abfd)->link_info
3778
0
           && !bfd_link_relocatable (coff_data (abfd)->link_info));
3779
3780
0
    _bfd_error_handler
3781
      /* xgettext:c-format */
3782
0
      (_("%pB:%s section %s: alignment 2**%u not representable"),
3783
0
       abfd, warn ? " warning:" : "", current->name,
3784
0
       current->alignment_power);
3785
0
    if (!warn)
3786
0
      {
3787
0
        bfd_set_error (bfd_error_nonrepresentable_section);
3788
0
        return false;
3789
0
      }
3790
0
  }
3791
16
#endif
3792
3793
16
#ifdef COFF_IMAGE_WITH_PE
3794
      /* Suppress output of the sections if they are null.  ld
3795
   includes the bss and data sections even if there is no size
3796
   assigned to them.  NT loader doesn't like it if these section
3797
   headers are included if the sections themselves are not
3798
   needed.  See also coff_compute_section_file_positions.  */
3799
16
      if (section.s_size == 0)
3800
12
  internal_f.f_nscns--;
3801
4
      else
3802
4
#endif
3803
4
  {
3804
4
    SCNHDR buff;
3805
4
    bfd_size_type amt = bfd_coff_scnhsz (abfd);
3806
3807
4
    if (bfd_coff_swap_scnhdr_out (abfd, &section, &buff) == 0
3808
4
        || bfd_write (& buff, amt, abfd) != amt)
3809
0
      return false;
3810
4
  }
3811
3812
16
#ifdef COFF_WITH_PE
3813
      /* PE stores COMDAT section information in the symbol table.  If
3814
   this section is supposed to have some COMDAT info, track down
3815
   the symbol in the symbol table and modify it.  */
3816
16
      if ((current->flags & SEC_LINK_ONCE) != 0)
3817
0
  {
3818
0
    unsigned int i, count;
3819
0
    asymbol **psym;
3820
0
    coff_symbol_type *csym = NULL;
3821
0
    asymbol **psymsec;
3822
3823
0
    psymsec = NULL;
3824
0
    count = bfd_get_symcount (abfd);
3825
0
    for (i = 0, psym = abfd->outsymbols; i < count; i++, psym++)
3826
0
      {
3827
0
        if ((*psym)->section != current)
3828
0
    continue;
3829
3830
        /* Remember the location of the first symbol in this
3831
     section.  */
3832
0
        if (psymsec == NULL)
3833
0
    psymsec = psym;
3834
3835
        /* See if this is the section symbol.  */
3836
0
        if (strcmp ((*psym)->name, current->name) == 0)
3837
0
    {
3838
0
      csym = coff_symbol_from (*psym);
3839
0
      if (csym == NULL
3840
0
          || csym->native == NULL
3841
0
          || ! csym->native->is_sym
3842
0
          || csym->native->u.syment.n_numaux < 1
3843
0
          || csym->native->u.syment.n_sclass != C_STAT
3844
0
          || csym->native->u.syment.n_type != T_NULL)
3845
0
        continue;
3846
3847
      /* Here *PSYM is the section symbol for CURRENT.  */
3848
3849
0
      break;
3850
0
    }
3851
0
      }
3852
3853
    /* Did we find it?
3854
       Note that we might not if we're converting the file from
3855
       some other object file format.  */
3856
0
    if (i < count)
3857
0
      {
3858
0
        combined_entry_type *aux;
3859
3860
        /* We don't touch the x_checksum field.  The
3861
     x_associated field is not currently supported.  */
3862
3863
0
        aux = csym->native + 1;
3864
0
        BFD_ASSERT (! aux->is_sym);
3865
0
        switch (current->flags & SEC_LINK_DUPLICATES)
3866
0
    {
3867
0
    case SEC_LINK_DUPLICATES_DISCARD:
3868
0
      aux->u.auxent.x_scn.x_comdat = IMAGE_COMDAT_SELECT_ANY;
3869
0
      break;
3870
3871
0
    case SEC_LINK_DUPLICATES_ONE_ONLY:
3872
0
      aux->u.auxent.x_scn.x_comdat =
3873
0
        IMAGE_COMDAT_SELECT_NODUPLICATES;
3874
0
      break;
3875
3876
0
    case SEC_LINK_DUPLICATES_SAME_SIZE:
3877
0
      aux->u.auxent.x_scn.x_comdat =
3878
0
        IMAGE_COMDAT_SELECT_SAME_SIZE;
3879
0
      break;
3880
3881
0
    case SEC_LINK_DUPLICATES_SAME_CONTENTS:
3882
0
      aux->u.auxent.x_scn.x_comdat =
3883
0
        IMAGE_COMDAT_SELECT_EXACT_MATCH;
3884
0
      break;
3885
0
    }
3886
3887
        /* The COMDAT symbol must be the first symbol from this
3888
     section in the symbol table.  In order to make this
3889
     work, we move the COMDAT symbol before the first
3890
     symbol we found in the search above.  It's OK to
3891
     rearrange the symbol table at this point, because
3892
     coff_renumber_symbols is going to rearrange it
3893
     further and fix up all the aux entries.  */
3894
0
        if (psym != psymsec)
3895
0
    {
3896
0
      asymbol *hold;
3897
0
      asymbol **pcopy;
3898
3899
0
      hold = *psym;
3900
0
      for (pcopy = psym; pcopy > psymsec; pcopy--)
3901
0
        pcopy[0] = pcopy[-1];
3902
0
      *psymsec = hold;
3903
0
    }
3904
0
      }
3905
0
  }
3906
16
#endif /* COFF_WITH_PE */
3907
16
    }
3908
3909
#ifdef RS6000COFF_C
3910
#ifndef XCOFF64
3911
  /* XCOFF handles overflows in the reloc and line number count fields
3912
     by creating a new section header to hold the correct values.  */
3913
  for (current = abfd->sections; current != NULL; current = current->next)
3914
    {
3915
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3916
  {
3917
    struct internal_scnhdr scnhdr;
3918
    SCNHDR buff;
3919
    bfd_size_type amt;
3920
3921
    internal_f.f_nscns++;
3922
    memcpy (scnhdr.s_name, ".ovrflo", 8);
3923
    scnhdr.s_paddr = current->reloc_count;
3924
    scnhdr.s_vaddr = current->lineno_count;
3925
    scnhdr.s_size = 0;
3926
    scnhdr.s_scnptr = 0;
3927
    scnhdr.s_relptr = current->rel_filepos;
3928
    scnhdr.s_lnnoptr = current->line_filepos;
3929
    scnhdr.s_nreloc = current->target_index;
3930
    scnhdr.s_nlnno = current->target_index;
3931
    scnhdr.s_flags = STYP_OVRFLO;
3932
    amt = bfd_coff_scnhsz (abfd);
3933
    if (bfd_coff_swap_scnhdr_out (abfd, &scnhdr, &buff) == 0
3934
        || bfd_write (& buff, amt, abfd) != amt)
3935
      return false;
3936
  }
3937
    }
3938
#endif
3939
#endif
3940
3941
#if defined (COFF_GO32_EXE) || defined (COFF_GO32)
3942
  /* Pad section headers.  */
3943
  if ((abfd->flags & EXEC_P) != 0)
3944
    {
3945
      asection *s = abfd->sections;
3946
      while (s != NULL && s->filepos == 0)
3947
  s = s->next;
3948
      if (s != NULL)
3949
  {
3950
    file_ptr cur_ptr
3951
      = scn_base + abfd->section_count * bfd_coff_scnhsz (abfd);
3952
    file_ptr fill_size = s->filepos - cur_ptr;
3953
    if (fill_size > 0)
3954
      {
3955
        bfd_byte *b = bfd_zmalloc (fill_size);
3956
        if (!b)
3957
    return false;
3958
        if (bfd_write (b, fill_size, abfd) != (ufile_ptr) fill_size)
3959
    {
3960
      free (b);
3961
      return false;
3962
    }
3963
        free (b);
3964
      }
3965
  }
3966
    }
3967
#endif
3968
3969
  /* OK, now set up the filehdr...  */
3970
3971
  /* Don't include the internal abs section in the section count */
3972
3973
  /* We will NOT put a fucking timestamp in the header here. Every time you
3974
     put it back, I will come in and take it out again.  I'm sorry.  This
3975
     field does not belong here.  We fill it with a 0 so it compares the
3976
     same but is not a reasonable time. -- gnu@cygnus.com  */
3977
5
  internal_f.f_timdat = 0;
3978
5
  internal_f.f_flags = 0;
3979
3980
5
  if (abfd->flags & EXEC_P)
3981
5
    internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3982
0
  else
3983
0
    {
3984
0
      internal_f.f_opthdr = 0;
3985
#ifdef RS6000COFF_C
3986
#ifndef XCOFF64
3987
      if (xcoff_data (abfd)->full_aouthdr)
3988
  internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3989
      else
3990
  internal_f.f_opthdr = SMALL_AOUTSZ;
3991
#endif
3992
#endif
3993
0
    }
3994
3995
5
  if (!hasrelocs)
3996
5
    internal_f.f_flags |= F_RELFLG;
3997
5
  if (!haslinno)
3998
5
    internal_f.f_flags |= F_LNNO;
3999
5
  if (abfd->flags & EXEC_P)
4000
5
    internal_f.f_flags |= F_EXEC;
4001
5
#ifdef COFF_IMAGE_WITH_PE
4002
5
  if (! hasdebug)
4003
3
    internal_f.f_flags |= IMAGE_FILE_DEBUG_STRIPPED;
4004
5
  if (pe_data (abfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
4005
5
    internal_f.f_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
4006
5
#endif
4007
4008
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64) && !defined (COFF_WITH_peRiscV64)
4009
#ifdef COFF_WITH_PE
4010
  internal_f.f_flags |= IMAGE_FILE_32BIT_MACHINE;
4011
#else
4012
  if (bfd_little_endian (abfd))
4013
    internal_f.f_flags |= F_AR32WR;
4014
  else
4015
    internal_f.f_flags |= F_AR32W;
4016
#endif
4017
#endif
4018
4019
#ifdef TI_TARGET_ID
4020
  /* Target id is used in TI COFF v1 and later; COFF0 won't use this field,
4021
     but it doesn't hurt to set it internally.  */
4022
  internal_f.f_target_id = TI_TARGET_ID;
4023
#endif
4024
4025
  /* FIXME, should do something about the other byte orders and
4026
     architectures.  */
4027
4028
#ifdef RS6000COFF_C
4029
  if ((abfd->flags & DYNAMIC) != 0)
4030
    internal_f.f_flags |= F_SHROBJ;
4031
  if (bfd_get_section_by_name (abfd, _LOADER) != NULL)
4032
    internal_f.f_flags |= F_DYNLOAD;
4033
#endif
4034
4035
5
  memset (&internal_a, 0, sizeof internal_a);
4036
4037
  /* Set up architecture-dependent stuff.  */
4038
5
  {
4039
5
    unsigned int magic = 0;
4040
5
    unsigned short flags = 0;
4041
4042
5
    coff_set_flags (abfd, &magic, &flags);
4043
5
    internal_f.f_magic = magic;
4044
5
    internal_f.f_flags |= flags;
4045
    /* ...and the "opt"hdr...  */
4046
4047
#ifdef TICOFF_AOUT_MAGIC
4048
    internal_a.magic = TICOFF_AOUT_MAGIC;
4049
#define __A_MAGIC_SET__
4050
#endif
4051
4052
#if defined(ARM)
4053
#define __A_MAGIC_SET__
4054
    internal_a.magic = ZMAGIC;
4055
#endif
4056
4057
#if defined(AARCH64)
4058
#define __A_MAGIC_SET__
4059
    internal_a.magic = ZMAGIC;
4060
#endif
4061
4062
#if defined(LOONGARCH64)
4063
#define __A_MAGIC_SET__
4064
    internal_a.magic = ZMAGIC;
4065
#endif
4066
4067
5
#if defined(RISCV64)
4068
5
#define __A_MAGIC_SET__
4069
5
    internal_a.magic = ZMAGIC;
4070
5
#endif
4071
4072
#if defined MCORE_PE
4073
#define __A_MAGIC_SET__
4074
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR_MAGIC;
4075
#endif
4076
4077
#if defined(I386)
4078
#define __A_MAGIC_SET__
4079
#if defined LYNXOS
4080
    internal_a.magic = LYNXCOFFMAGIC;
4081
#elif defined AMD64
4082
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR64_MAGIC;
4083
#else
4084
    internal_a.magic = ZMAGIC;
4085
#endif
4086
#endif /* I386 */
4087
4088
#if defined(IA64)
4089
#define __A_MAGIC_SET__
4090
    internal_a.magic = PE32PMAGIC;
4091
#endif /* IA64 */
4092
4093
#if defined(SPARC)
4094
#define __A_MAGIC_SET__
4095
#if defined(LYNXOS)
4096
    internal_a.magic = LYNXCOFFMAGIC;
4097
#endif /* LYNXOS */
4098
#endif /* SPARC */
4099
4100
#ifdef RS6000COFF_C
4101
#define __A_MAGIC_SET__
4102
    internal_a.magic = (abfd->flags & D_PAGED) ? RS6K_AOUTHDR_ZMAGIC :
4103
    (abfd->flags & WP_TEXT) ? RS6K_AOUTHDR_NMAGIC :
4104
    RS6K_AOUTHDR_OMAGIC;
4105
#endif
4106
4107
#if defined(SH) && defined(COFF_WITH_PE)
4108
#define __A_MAGIC_SET__
4109
    internal_a.magic = SH_PE_MAGIC;
4110
#endif
4111
4112
#if defined(MIPS) && defined(COFF_WITH_PE)
4113
#define __A_MAGIC_SET__
4114
    internal_a.magic = MIPS_PE_MAGIC;
4115
#endif
4116
4117
#ifndef __A_MAGIC_SET__
4118
#include "Your aouthdr magic number is not being set!"
4119
#else
4120
5
#undef __A_MAGIC_SET__
4121
5
#endif
4122
5
  }
4123
4124
#ifdef RS6000COFF_C
4125
  /* XCOFF 32bit needs this to have new behaviour for n_type field.  */
4126
  internal_a.vstamp = 2;
4127
#else
4128
  /* FIXME: Does anybody ever set this to another value?  */
4129
5
  internal_a.vstamp = 0;
4130
5
#endif
4131
4132
  /* Now should write relocs, strings, syms.  */
4133
5
  obj_sym_filepos (abfd) = sym_base;
4134
4135
5
  if (bfd_get_symcount (abfd) != 0)
4136
3
    {
4137
3
      int firstundef;
4138
4139
3
      if (!coff_renumber_symbols (abfd, &firstundef))
4140
0
  return false;
4141
3
      coff_mangle_symbols (abfd);
4142
3
      if (! coff_write_symbols (abfd))
4143
0
  return false;
4144
3
      if (! coff_write_linenumbers (abfd))
4145
0
  return false;
4146
3
      if (! coff_write_relocs (abfd, firstundef))
4147
0
  return false;
4148
3
    }
4149
2
#ifdef COFF_LONG_SECTION_NAMES
4150
2
  else if (long_section_names && ! obj_coff_strings_written (abfd))
4151
0
    {
4152
      /* If we have long section names we have to write out the string
4153
   table even if there are no symbols.  */
4154
0
      if (! coff_write_symbols (abfd))
4155
0
  return false;
4156
0
    }
4157
5
#endif
4158
  /* If bfd_get_symcount (abfd) != 0, then we are not using the COFF
4159
     backend linker, and obj_raw_syment_count is not valid until after
4160
     coff_write_symbols is called.  */
4161
5
  if (obj_raw_syment_count (abfd) != 0)
4162
3
    {
4163
3
      internal_f.f_symptr = sym_base;
4164
#ifdef RS6000COFF_C
4165
      /* AIX appears to require that F_RELFLG not be set if there are
4166
   local symbols but no relocations.  */
4167
      internal_f.f_flags &=~ F_RELFLG;
4168
#endif
4169
3
    }
4170
2
  else
4171
2
    {
4172
2
      if (long_section_names)
4173
0
  internal_f.f_symptr = sym_base;
4174
2
      else
4175
2
  internal_f.f_symptr = 0;
4176
2
      internal_f.f_flags |= F_LSYMS;
4177
2
    }
4178
4179
5
  if (text_sec)
4180
0
    {
4181
0
      internal_a.tsize = text_sec->size;
4182
0
      internal_a.text_start = internal_a.tsize ? text_sec->vma : 0;
4183
0
    }
4184
5
  if (data_sec)
4185
0
    {
4186
0
      internal_a.dsize = data_sec->size;
4187
0
      internal_a.data_start = internal_a.dsize ? data_sec->vma : 0;
4188
0
    }
4189
5
  if (bss_sec)
4190
0
    {
4191
0
      internal_a.bsize = bss_sec->size;
4192
0
      if (internal_a.bsize && bss_sec->vma < internal_a.data_start)
4193
0
  internal_a.data_start = bss_sec->vma;
4194
0
    }
4195
4196
5
  internal_a.entry = bfd_get_start_address (abfd);
4197
5
  internal_f.f_nsyms = obj_raw_syment_count (abfd);
4198
4199
#ifdef RS6000COFF_C
4200
  if (xcoff_data (abfd)->full_aouthdr)
4201
    {
4202
      bfd_vma toc;
4203
      asection *loader_sec;
4204
4205
      internal_a.vstamp = 2;
4206
4207
      internal_a.o_snentry = xcoff_data (abfd)->snentry;
4208
      if (internal_a.o_snentry == 0)
4209
  internal_a.entry = (bfd_vma) -1;
4210
4211
      if (text_sec != NULL)
4212
  {
4213
    internal_a.o_sntext = text_sec->target_index;
4214
    internal_a.o_algntext = bfd_section_alignment (text_sec);
4215
  }
4216
      else
4217
  {
4218
    internal_a.o_sntext = 0;
4219
    internal_a.o_algntext = 0;
4220
  }
4221
      if (data_sec != NULL)
4222
  {
4223
    internal_a.o_sndata = data_sec->target_index;
4224
    internal_a.o_algndata = bfd_section_alignment (data_sec);
4225
  }
4226
      else
4227
  {
4228
    internal_a.o_sndata = 0;
4229
    internal_a.o_algndata = 0;
4230
  }
4231
      loader_sec = bfd_get_section_by_name (abfd, ".loader");
4232
      if (loader_sec != NULL)
4233
  internal_a.o_snloader = loader_sec->target_index;
4234
      else
4235
  internal_a.o_snloader = 0;
4236
      if (bss_sec != NULL)
4237
  internal_a.o_snbss = bss_sec->target_index;
4238
      else
4239
  internal_a.o_snbss = 0;
4240
4241
      if (tdata_sec != NULL)
4242
  {
4243
    internal_a.o_sntdata = tdata_sec->target_index;
4244
    /* TODO: o_flags should be set to RS6K_AOUTHDR_TLS_LE
4245
       if there is at least one R_TLS_LE relocations.  */
4246
    internal_a.o_flags = 0;
4247
#ifdef XCOFF64
4248
    internal_a.o_x64flags = 0;
4249
#endif
4250
  }
4251
      else
4252
  {
4253
    internal_a.o_sntdata = 0;
4254
    internal_a.o_flags = 0;
4255
#ifdef XCOFF64
4256
    internal_a.o_x64flags = 0;
4257
#endif
4258
  }
4259
      if (tbss_sec != NULL)
4260
    internal_a.o_sntbss = tbss_sec->target_index;
4261
      else
4262
    internal_a.o_sntbss = 0;
4263
4264
      toc = xcoff_data (abfd)->toc;
4265
      internal_a.o_toc = toc;
4266
      internal_a.o_sntoc = xcoff_data (abfd)->sntoc;
4267
4268
      internal_a.o_modtype = xcoff_data (abfd)->modtype;
4269
      if (xcoff_data (abfd)->cputype != -1)
4270
  internal_a.o_cputype = xcoff_data (abfd)->cputype;
4271
      else
4272
  {
4273
    switch (bfd_get_arch (abfd))
4274
      {
4275
      case bfd_arch_rs6000:
4276
        internal_a.o_cputype = 4;
4277
        break;
4278
      case bfd_arch_powerpc:
4279
        if (bfd_get_mach (abfd) == bfd_mach_ppc)
4280
    internal_a.o_cputype = 3;
4281
        else if (bfd_get_mach (abfd) == bfd_mach_ppc_620)
4282
    internal_a.o_cputype = 2;
4283
        else
4284
    internal_a.o_cputype = 1;
4285
        break;
4286
      default:
4287
        abort ();
4288
      }
4289
  }
4290
      internal_a.o_maxstack = xcoff_data (abfd)->maxstack;
4291
      internal_a.o_maxdata = xcoff_data (abfd)->maxdata;
4292
    }
4293
#endif
4294
4295
5
#ifdef COFF_WITH_PE
4296
5
  {
4297
    /* After object contents are finalized so we can compute a reasonable hash,
4298
       but before header is written so we can update it to point to debug directory.  */
4299
5
    struct pe_tdata *pe = pe_data (abfd);
4300
4301
5
    if (pe->build_id.after_write_object_contents != NULL)
4302
0
      (*pe->build_id.after_write_object_contents) (abfd);
4303
5
  }
4304
5
#endif
4305
4306
  /* Now write header.  */
4307
5
  if (bfd_seek (abfd, 0, SEEK_SET) != 0)
4308
0
    return false;
4309
4310
5
  {
4311
5
    char * buff;
4312
5
    bfd_size_type amount = bfd_coff_filhsz (abfd);
4313
4314
5
    buff = (char *) bfd_malloc (amount);
4315
5
    if (buff == NULL)
4316
0
      return false;
4317
4318
5
    bfd_coff_swap_filehdr_out (abfd, & internal_f, buff);
4319
5
    amount = bfd_write (buff, amount, abfd);
4320
4321
5
    free (buff);
4322
4323
5
    if (amount != bfd_coff_filhsz (abfd))
4324
0
      return false;
4325
5
  }
4326
4327
5
  if (abfd->flags & EXEC_P)
4328
5
    {
4329
      /* Note that peicode.h fills in a PEAOUTHDR, not an AOUTHDR.
4330
   include/coff/pe.h sets AOUTSZ == sizeof (PEAOUTHDR)).  */
4331
5
      char * buff;
4332
5
      bfd_size_type amount = bfd_coff_aoutsz (abfd);
4333
4334
5
      buff = (char *) bfd_malloc (amount);
4335
5
      if (buff == NULL)
4336
0
  return false;
4337
4338
5
      coff_swap_aouthdr_out (abfd, & internal_a, buff);
4339
5
      amount = bfd_write (buff, amount, abfd);
4340
4341
5
      free (buff);
4342
4343
5
      if (amount != bfd_coff_aoutsz (abfd))
4344
0
  return false;
4345
4346
5
#ifdef COFF_IMAGE_WITH_PE
4347
5
      if (! coff_apply_checksum (abfd))
4348
0
  return false;
4349
5
#endif
4350
5
    }
4351
#ifdef RS6000COFF_C
4352
#ifndef XCOFF64
4353
  else
4354
    {
4355
      AOUTHDR buff;
4356
      size_t size;
4357
4358
      /* XCOFF32 seems to always write at least a small a.out header.  */
4359
      coff_swap_aouthdr_out (abfd, & internal_a, & buff);
4360
      if (xcoff_data (abfd)->full_aouthdr)
4361
  size = bfd_coff_aoutsz (abfd);
4362
      else
4363
  size = SMALL_AOUTSZ;
4364
      if (bfd_write (&buff, size, abfd) != size)
4365
  return false;
4366
    }
4367
#endif
4368
#endif
4369
4370
5
  return true;
4371
5
}
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
Unexecuted instantiation: coff-sh.c:coff_write_object_contents
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
Unexecuted instantiation: coff-z8k.c:coff_write_object_contents
Unexecuted instantiation: pe-arm-wince.c:coff_write_object_contents
Unexecuted instantiation: pe-arm.c:coff_write_object_contents
Unexecuted instantiation: pe-i386.c:coff_write_object_contents
Unexecuted instantiation: pe-mcore.c:coff_write_object_contents
Unexecuted instantiation: pe-sh.c:coff_write_object_contents
pei-arm-wince.c:coff_write_object_contents
Line
Count
Source
3490
1
{
3491
1
  asection *current;
3492
1
  bool hasrelocs = false;
3493
1
  bool haslinno = false;
3494
1
#ifdef COFF_IMAGE_WITH_PE
3495
1
  bool hasdebug = false;
3496
1
#endif
3497
1
  file_ptr scn_base;
3498
1
  file_ptr reloc_base;
3499
1
  file_ptr lineno_base;
3500
1
  file_ptr sym_base;
3501
1
  unsigned long reloc_size = 0, reloc_count = 0;
3502
1
  unsigned long lnno_size = 0;
3503
1
  bool long_section_names;
3504
1
  asection *text_sec = NULL;
3505
1
  asection *data_sec = NULL;
3506
1
  asection *bss_sec = NULL;
3507
#ifdef RS6000COFF_C
3508
  asection *tdata_sec = NULL;
3509
  asection *tbss_sec = NULL;
3510
#endif
3511
1
  struct internal_filehdr internal_f;
3512
1
  struct internal_aouthdr internal_a;
3513
1
#ifdef COFF_LONG_SECTION_NAMES
3514
1
  size_t string_size = STRING_SIZE_SIZE;
3515
1
#endif
3516
3517
1
  bfd_set_error (bfd_error_system_call);
3518
3519
  /* Make a pass through the symbol table to count line number entries and
3520
     put them into the correct asections.  */
3521
1
  lnno_size = coff_count_linenumbers (abfd) * bfd_coff_linesz (abfd);
3522
3523
1
  if (! abfd->output_has_begun)
3524
1
    {
3525
1
      if (! coff_compute_section_file_positions (abfd))
3526
0
  return false;
3527
1
    }
3528
3529
1
  reloc_base = obj_relocbase (abfd);
3530
3531
  /* Work out the size of the reloc and linno areas.  */
3532
3533
1
  for (current = abfd->sections; current != NULL; current =
3534
0
       current->next)
3535
0
    {
3536
0
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3537
      /* We store the actual reloc count in the first reloc's addr.  */
3538
0
      if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3539
0
  reloc_count ++;
3540
0
#endif
3541
0
      reloc_count += current->reloc_count;
3542
0
    }
3543
3544
1
  reloc_size = reloc_count * bfd_coff_relsz (abfd);
3545
3546
1
  lineno_base = reloc_base + reloc_size;
3547
1
  sym_base = lineno_base + lnno_size;
3548
3549
  /* Indicate in each section->line_filepos its actual file address.  */
3550
1
  for (current = abfd->sections; current != NULL; current =
3551
0
       current->next)
3552
0
    {
3553
0
      if (current->lineno_count)
3554
0
  {
3555
0
    current->line_filepos = lineno_base;
3556
0
    current->moving_line_filepos = lineno_base;
3557
0
    lineno_base += current->lineno_count * bfd_coff_linesz (abfd);
3558
0
  }
3559
0
      else
3560
0
  current->line_filepos = 0;
3561
3562
0
      if (current->reloc_count)
3563
0
  {
3564
0
    current->rel_filepos = reloc_base;
3565
0
    reloc_base += current->reloc_count * bfd_coff_relsz (abfd);
3566
0
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3567
    /* Extra reloc to hold real count.  */
3568
0
    if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3569
0
      reloc_base += bfd_coff_relsz (abfd);
3570
0
#endif
3571
0
  }
3572
0
      else
3573
0
  current->rel_filepos = 0;
3574
0
    }
3575
3576
  /* Write section headers to the file.  */
3577
1
  internal_f.f_nscns = 0;
3578
3579
1
  if ((abfd->flags & EXEC_P) != 0)
3580
1
    scn_base = bfd_coff_filhsz (abfd) + bfd_coff_aoutsz (abfd);
3581
0
  else
3582
0
    {
3583
0
      scn_base = bfd_coff_filhsz (abfd);
3584
#ifdef RS6000COFF_C
3585
#ifndef XCOFF64
3586
      if (xcoff_data (abfd)->full_aouthdr)
3587
  scn_base += bfd_coff_aoutsz (abfd);
3588
      else
3589
  scn_base += SMALL_AOUTSZ;
3590
#endif
3591
#endif
3592
0
    }
3593
3594
1
  if (bfd_seek (abfd, scn_base, SEEK_SET) != 0)
3595
0
    return false;
3596
3597
1
  long_section_names = false;
3598
1
  for (current = abfd->sections;
3599
1
       current != NULL;
3600
1
       current = current->next)
3601
0
    {
3602
0
      struct internal_scnhdr section;
3603
0
#ifdef COFF_IMAGE_WITH_PE
3604
0
      bool is_reloc_section = false;
3605
3606
0
      if (strcmp (current->name, DOT_RELOC) == 0)
3607
0
  {
3608
0
    is_reloc_section = true;
3609
0
    hasrelocs = true;
3610
0
    pe_data (abfd)->has_reloc_section = 1;
3611
0
  }
3612
0
#endif
3613
3614
0
      internal_f.f_nscns++;
3615
3616
0
      strncpy (section.s_name, current->name, SCNNMLEN);
3617
3618
0
#ifdef COFF_LONG_SECTION_NAMES
3619
      /* Handle long section names as in PE.  This must be compatible
3620
   with the code in coff_write_symbols and _bfd_coff_final_link.  */
3621
0
      if (bfd_coff_long_section_names (abfd))
3622
0
  {
3623
0
    size_t len;
3624
3625
0
    len = strlen (current->name);
3626
0
    if (len > SCNNMLEN)
3627
0
      {
3628
3629
        /* An inherent limitation of the /nnnnnnn notation used to indicate
3630
     the offset of the long name in the string table is that we
3631
     cannot address entries beyone the ten million byte boundary.  */
3632
0
        if (string_size < 10000000)
3633
0
    {
3634
      /* The s_name field is defined to be NUL-padded but need not
3635
         be NUL-terminated.  We use a temporary buffer so that we
3636
         can still sprintf all eight chars without splatting a
3637
         terminating NUL over the first byte of the following
3638
         member (s_paddr).  */
3639
      /* PR 21096: The +20 is to stop a bogus warning from gcc7
3640
         about a possible buffer overflow.  */
3641
0
      char s_name_buf[SCNNMLEN + 1 + 20];
3642
3643
      /* We do not need to use snprintf here as we have already
3644
         verified that string_size is not too big, plus we have
3645
         an overlarge buffer, just in case.  */
3646
0
      sprintf (s_name_buf, "/%lu", (unsigned long) string_size);
3647
      /* Then strncpy takes care of any padding for us.  */
3648
0
      strncpy (section.s_name, s_name_buf, SCNNMLEN);
3649
0
    }
3650
0
        else
3651
0
#ifdef COFF_WITH_PE
3652
0
    {
3653
      /* PE use a base 64 encoding for long section names whose
3654
         index is very large.  But contrary to RFC 4648, there is
3655
         no padding: 6 characters must be generated.  */
3656
0
      static const char base64[] =
3657
0
        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
3658
0
        "abcdefghijklmnopqrstuvwxyz"
3659
0
        "0123456789+/";
3660
0
      unsigned long off = string_size;
3661
0
      unsigned i;
3662
3663
0
      section.s_name[0] = '/';
3664
0
      section.s_name[1] = '/';
3665
0
      for (i = SCNNMLEN - 1; i >= 2; i--)
3666
0
        {
3667
0
          section.s_name[i] = base64[off & 0x3f];
3668
0
          off >>= 6;
3669
0
        }
3670
0
    }
3671
0
#endif
3672
0
        if (string_size > 0xffffffffUL - (len + 1)
3673
#ifndef COFF_WITH_PE
3674
      || string_size >= 10000000
3675
#endif
3676
0
      )
3677
0
    {
3678
0
      bfd_set_error (bfd_error_file_too_big);
3679
0
      _bfd_error_handler
3680
        /* xgettext:c-format */
3681
0
        (_("%pB: section %pA: string table overflow at offset %ld"),
3682
0
        abfd, current, (unsigned long) string_size);
3683
0
      return false;
3684
0
    }
3685
3686
0
        string_size += len + 1;
3687
0
        long_section_names = true;
3688
0
      }
3689
0
  }
3690
0
#endif
3691
3692
0
#ifdef _LIB
3693
      /* Always set s_vaddr of .lib to 0.  This is right for SVR3.2
3694
   Ian Taylor <ian@cygnus.com>.  */
3695
0
      if (strcmp (current->name, _LIB) == 0)
3696
0
  section.s_vaddr = 0;
3697
0
      else
3698
0
#endif
3699
0
      section.s_vaddr = current->vma;
3700
0
      section.s_paddr = current->lma;
3701
0
      section.s_size =  current->size;
3702
#ifdef coff_get_section_load_page
3703
      section.s_page = coff_get_section_load_page (current);
3704
#else
3705
0
      section.s_page = 0;
3706
0
#endif
3707
3708
0
#ifdef COFF_WITH_PE
3709
0
      section.s_paddr = 0;
3710
0
#endif
3711
0
#ifdef COFF_IMAGE_WITH_PE
3712
      /* Reminder: s_paddr holds the virtual size of the section.  */
3713
0
      if (coff_section_data (abfd, current) != NULL
3714
0
    && pei_section_data (abfd, current) != NULL)
3715
0
  section.s_paddr = pei_section_data (abfd, current)->virt_size;
3716
0
      else
3717
0
  section.s_paddr = 0;
3718
0
#endif
3719
3720
      /* If this section has no size or is unloadable then the scnptr
3721
   will be 0 too.  */
3722
0
      if (current->size == 0
3723
0
    || (current->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
3724
0
  section.s_scnptr = 0;
3725
0
      else
3726
0
  section.s_scnptr = current->filepos;
3727
3728
0
      section.s_relptr = current->rel_filepos;
3729
0
      section.s_lnnoptr = current->line_filepos;
3730
0
      section.s_nreloc = current->reloc_count;
3731
0
      section.s_nlnno = current->lineno_count;
3732
#ifndef COFF_IMAGE_WITH_PE
3733
      /* In PEI, relocs come in the .reloc section.  */
3734
      if (current->reloc_count != 0)
3735
  hasrelocs = true;
3736
#endif
3737
0
      if (current->lineno_count != 0)
3738
0
  haslinno = true;
3739
0
#ifdef COFF_IMAGE_WITH_PE
3740
0
      if ((current->flags & SEC_DEBUGGING) != 0
3741
0
    && ! is_reloc_section)
3742
0
  hasdebug = true;
3743
0
#endif
3744
3745
#ifdef RS6000COFF_C
3746
#ifndef XCOFF64
3747
      /* Indicate the use of an XCOFF overflow section header.  */
3748
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3749
  {
3750
    section.s_nreloc = 0xffff;
3751
    section.s_nlnno = 0xffff;
3752
  }
3753
#endif
3754
#endif
3755
3756
0
      section.s_flags = sec_to_styp_flags (current->name, current->flags);
3757
3758
0
      if (!strcmp (current->name, _TEXT))
3759
0
  text_sec = current;
3760
0
      else if (!strcmp (current->name, _DATA))
3761
0
  data_sec = current;
3762
0
      else if (!strcmp (current->name, _BSS))
3763
0
  bss_sec = current;
3764
#ifdef RS6000COFF_C
3765
      else if (!strcmp (current->name, _TDATA))
3766
  tdata_sec = current;
3767
      else if (!strcmp (current->name, _TBSS))
3768
  tbss_sec = current;
3769
#endif
3770
3771
3772
0
#ifdef COFF_ENCODE_ALIGNMENT
3773
0
      if (COFF_ENCODE_ALIGNMENT (abfd, section, current->alignment_power)
3774
0
    && (COFF_DECODE_ALIGNMENT (section.s_flags)
3775
0
        != current->alignment_power))
3776
0
  {
3777
0
    bool warn = (coff_data (abfd)->link_info
3778
0
           && !bfd_link_relocatable (coff_data (abfd)->link_info));
3779
3780
0
    _bfd_error_handler
3781
      /* xgettext:c-format */
3782
0
      (_("%pB:%s section %s: alignment 2**%u not representable"),
3783
0
       abfd, warn ? " warning:" : "", current->name,
3784
0
       current->alignment_power);
3785
0
    if (!warn)
3786
0
      {
3787
0
        bfd_set_error (bfd_error_nonrepresentable_section);
3788
0
        return false;
3789
0
      }
3790
0
  }
3791
0
#endif
3792
3793
0
#ifdef COFF_IMAGE_WITH_PE
3794
      /* Suppress output of the sections if they are null.  ld
3795
   includes the bss and data sections even if there is no size
3796
   assigned to them.  NT loader doesn't like it if these section
3797
   headers are included if the sections themselves are not
3798
   needed.  See also coff_compute_section_file_positions.  */
3799
0
      if (section.s_size == 0)
3800
0
  internal_f.f_nscns--;
3801
0
      else
3802
0
#endif
3803
0
  {
3804
0
    SCNHDR buff;
3805
0
    bfd_size_type amt = bfd_coff_scnhsz (abfd);
3806
3807
0
    if (bfd_coff_swap_scnhdr_out (abfd, &section, &buff) == 0
3808
0
        || bfd_write (& buff, amt, abfd) != amt)
3809
0
      return false;
3810
0
  }
3811
3812
0
#ifdef COFF_WITH_PE
3813
      /* PE stores COMDAT section information in the symbol table.  If
3814
   this section is supposed to have some COMDAT info, track down
3815
   the symbol in the symbol table and modify it.  */
3816
0
      if ((current->flags & SEC_LINK_ONCE) != 0)
3817
0
  {
3818
0
    unsigned int i, count;
3819
0
    asymbol **psym;
3820
0
    coff_symbol_type *csym = NULL;
3821
0
    asymbol **psymsec;
3822
3823
0
    psymsec = NULL;
3824
0
    count = bfd_get_symcount (abfd);
3825
0
    for (i = 0, psym = abfd->outsymbols; i < count; i++, psym++)
3826
0
      {
3827
0
        if ((*psym)->section != current)
3828
0
    continue;
3829
3830
        /* Remember the location of the first symbol in this
3831
     section.  */
3832
0
        if (psymsec == NULL)
3833
0
    psymsec = psym;
3834
3835
        /* See if this is the section symbol.  */
3836
0
        if (strcmp ((*psym)->name, current->name) == 0)
3837
0
    {
3838
0
      csym = coff_symbol_from (*psym);
3839
0
      if (csym == NULL
3840
0
          || csym->native == NULL
3841
0
          || ! csym->native->is_sym
3842
0
          || csym->native->u.syment.n_numaux < 1
3843
0
          || csym->native->u.syment.n_sclass != C_STAT
3844
0
          || csym->native->u.syment.n_type != T_NULL)
3845
0
        continue;
3846
3847
      /* Here *PSYM is the section symbol for CURRENT.  */
3848
3849
0
      break;
3850
0
    }
3851
0
      }
3852
3853
    /* Did we find it?
3854
       Note that we might not if we're converting the file from
3855
       some other object file format.  */
3856
0
    if (i < count)
3857
0
      {
3858
0
        combined_entry_type *aux;
3859
3860
        /* We don't touch the x_checksum field.  The
3861
     x_associated field is not currently supported.  */
3862
3863
0
        aux = csym->native + 1;
3864
0
        BFD_ASSERT (! aux->is_sym);
3865
0
        switch (current->flags & SEC_LINK_DUPLICATES)
3866
0
    {
3867
0
    case SEC_LINK_DUPLICATES_DISCARD:
3868
0
      aux->u.auxent.x_scn.x_comdat = IMAGE_COMDAT_SELECT_ANY;
3869
0
      break;
3870
3871
0
    case SEC_LINK_DUPLICATES_ONE_ONLY:
3872
0
      aux->u.auxent.x_scn.x_comdat =
3873
0
        IMAGE_COMDAT_SELECT_NODUPLICATES;
3874
0
      break;
3875
3876
0
    case SEC_LINK_DUPLICATES_SAME_SIZE:
3877
0
      aux->u.auxent.x_scn.x_comdat =
3878
0
        IMAGE_COMDAT_SELECT_SAME_SIZE;
3879
0
      break;
3880
3881
0
    case SEC_LINK_DUPLICATES_SAME_CONTENTS:
3882
0
      aux->u.auxent.x_scn.x_comdat =
3883
0
        IMAGE_COMDAT_SELECT_EXACT_MATCH;
3884
0
      break;
3885
0
    }
3886
3887
        /* The COMDAT symbol must be the first symbol from this
3888
     section in the symbol table.  In order to make this
3889
     work, we move the COMDAT symbol before the first
3890
     symbol we found in the search above.  It's OK to
3891
     rearrange the symbol table at this point, because
3892
     coff_renumber_symbols is going to rearrange it
3893
     further and fix up all the aux entries.  */
3894
0
        if (psym != psymsec)
3895
0
    {
3896
0
      asymbol *hold;
3897
0
      asymbol **pcopy;
3898
3899
0
      hold = *psym;
3900
0
      for (pcopy = psym; pcopy > psymsec; pcopy--)
3901
0
        pcopy[0] = pcopy[-1];
3902
0
      *psymsec = hold;
3903
0
    }
3904
0
      }
3905
0
  }
3906
0
#endif /* COFF_WITH_PE */
3907
0
    }
3908
3909
#ifdef RS6000COFF_C
3910
#ifndef XCOFF64
3911
  /* XCOFF handles overflows in the reloc and line number count fields
3912
     by creating a new section header to hold the correct values.  */
3913
  for (current = abfd->sections; current != NULL; current = current->next)
3914
    {
3915
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3916
  {
3917
    struct internal_scnhdr scnhdr;
3918
    SCNHDR buff;
3919
    bfd_size_type amt;
3920
3921
    internal_f.f_nscns++;
3922
    memcpy (scnhdr.s_name, ".ovrflo", 8);
3923
    scnhdr.s_paddr = current->reloc_count;
3924
    scnhdr.s_vaddr = current->lineno_count;
3925
    scnhdr.s_size = 0;
3926
    scnhdr.s_scnptr = 0;
3927
    scnhdr.s_relptr = current->rel_filepos;
3928
    scnhdr.s_lnnoptr = current->line_filepos;
3929
    scnhdr.s_nreloc = current->target_index;
3930
    scnhdr.s_nlnno = current->target_index;
3931
    scnhdr.s_flags = STYP_OVRFLO;
3932
    amt = bfd_coff_scnhsz (abfd);
3933
    if (bfd_coff_swap_scnhdr_out (abfd, &scnhdr, &buff) == 0
3934
        || bfd_write (& buff, amt, abfd) != amt)
3935
      return false;
3936
  }
3937
    }
3938
#endif
3939
#endif
3940
3941
#if defined (COFF_GO32_EXE) || defined (COFF_GO32)
3942
  /* Pad section headers.  */
3943
  if ((abfd->flags & EXEC_P) != 0)
3944
    {
3945
      asection *s = abfd->sections;
3946
      while (s != NULL && s->filepos == 0)
3947
  s = s->next;
3948
      if (s != NULL)
3949
  {
3950
    file_ptr cur_ptr
3951
      = scn_base + abfd->section_count * bfd_coff_scnhsz (abfd);
3952
    file_ptr fill_size = s->filepos - cur_ptr;
3953
    if (fill_size > 0)
3954
      {
3955
        bfd_byte *b = bfd_zmalloc (fill_size);
3956
        if (!b)
3957
    return false;
3958
        if (bfd_write (b, fill_size, abfd) != (ufile_ptr) fill_size)
3959
    {
3960
      free (b);
3961
      return false;
3962
    }
3963
        free (b);
3964
      }
3965
  }
3966
    }
3967
#endif
3968
3969
  /* OK, now set up the filehdr...  */
3970
3971
  /* Don't include the internal abs section in the section count */
3972
3973
  /* We will NOT put a fucking timestamp in the header here. Every time you
3974
     put it back, I will come in and take it out again.  I'm sorry.  This
3975
     field does not belong here.  We fill it with a 0 so it compares the
3976
     same but is not a reasonable time. -- gnu@cygnus.com  */
3977
1
  internal_f.f_timdat = 0;
3978
1
  internal_f.f_flags = 0;
3979
3980
1
  if (abfd->flags & EXEC_P)
3981
1
    internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3982
0
  else
3983
0
    {
3984
0
      internal_f.f_opthdr = 0;
3985
#ifdef RS6000COFF_C
3986
#ifndef XCOFF64
3987
      if (xcoff_data (abfd)->full_aouthdr)
3988
  internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3989
      else
3990
  internal_f.f_opthdr = SMALL_AOUTSZ;
3991
#endif
3992
#endif
3993
0
    }
3994
3995
1
  if (!hasrelocs)
3996
1
    internal_f.f_flags |= F_RELFLG;
3997
1
  if (!haslinno)
3998
1
    internal_f.f_flags |= F_LNNO;
3999
1
  if (abfd->flags & EXEC_P)
4000
1
    internal_f.f_flags |= F_EXEC;
4001
1
#ifdef COFF_IMAGE_WITH_PE
4002
1
  if (! hasdebug)
4003
1
    internal_f.f_flags |= IMAGE_FILE_DEBUG_STRIPPED;
4004
1
  if (pe_data (abfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
4005
0
    internal_f.f_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
4006
1
#endif
4007
4008
1
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64) && !defined (COFF_WITH_peRiscV64)
4009
1
#ifdef COFF_WITH_PE
4010
1
  internal_f.f_flags |= IMAGE_FILE_32BIT_MACHINE;
4011
#else
4012
  if (bfd_little_endian (abfd))
4013
    internal_f.f_flags |= F_AR32WR;
4014
  else
4015
    internal_f.f_flags |= F_AR32W;
4016
#endif
4017
1
#endif
4018
4019
#ifdef TI_TARGET_ID
4020
  /* Target id is used in TI COFF v1 and later; COFF0 won't use this field,
4021
     but it doesn't hurt to set it internally.  */
4022
  internal_f.f_target_id = TI_TARGET_ID;
4023
#endif
4024
4025
  /* FIXME, should do something about the other byte orders and
4026
     architectures.  */
4027
4028
#ifdef RS6000COFF_C
4029
  if ((abfd->flags & DYNAMIC) != 0)
4030
    internal_f.f_flags |= F_SHROBJ;
4031
  if (bfd_get_section_by_name (abfd, _LOADER) != NULL)
4032
    internal_f.f_flags |= F_DYNLOAD;
4033
#endif
4034
4035
1
  memset (&internal_a, 0, sizeof internal_a);
4036
4037
  /* Set up architecture-dependent stuff.  */
4038
1
  {
4039
1
    unsigned int magic = 0;
4040
1
    unsigned short flags = 0;
4041
4042
1
    coff_set_flags (abfd, &magic, &flags);
4043
1
    internal_f.f_magic = magic;
4044
1
    internal_f.f_flags |= flags;
4045
    /* ...and the "opt"hdr...  */
4046
4047
#ifdef TICOFF_AOUT_MAGIC
4048
    internal_a.magic = TICOFF_AOUT_MAGIC;
4049
#define __A_MAGIC_SET__
4050
#endif
4051
4052
1
#if defined(ARM)
4053
1
#define __A_MAGIC_SET__
4054
1
    internal_a.magic = ZMAGIC;
4055
1
#endif
4056
4057
#if defined(AARCH64)
4058
#define __A_MAGIC_SET__
4059
    internal_a.magic = ZMAGIC;
4060
#endif
4061
4062
#if defined(LOONGARCH64)
4063
#define __A_MAGIC_SET__
4064
    internal_a.magic = ZMAGIC;
4065
#endif
4066
4067
#if defined(RISCV64)
4068
#define __A_MAGIC_SET__
4069
    internal_a.magic = ZMAGIC;
4070
#endif
4071
4072
#if defined MCORE_PE
4073
#define __A_MAGIC_SET__
4074
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR_MAGIC;
4075
#endif
4076
4077
#if defined(I386)
4078
#define __A_MAGIC_SET__
4079
#if defined LYNXOS
4080
    internal_a.magic = LYNXCOFFMAGIC;
4081
#elif defined AMD64
4082
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR64_MAGIC;
4083
#else
4084
    internal_a.magic = ZMAGIC;
4085
#endif
4086
#endif /* I386 */
4087
4088
#if defined(IA64)
4089
#define __A_MAGIC_SET__
4090
    internal_a.magic = PE32PMAGIC;
4091
#endif /* IA64 */
4092
4093
#if defined(SPARC)
4094
#define __A_MAGIC_SET__
4095
#if defined(LYNXOS)
4096
    internal_a.magic = LYNXCOFFMAGIC;
4097
#endif /* LYNXOS */
4098
#endif /* SPARC */
4099
4100
#ifdef RS6000COFF_C
4101
#define __A_MAGIC_SET__
4102
    internal_a.magic = (abfd->flags & D_PAGED) ? RS6K_AOUTHDR_ZMAGIC :
4103
    (abfd->flags & WP_TEXT) ? RS6K_AOUTHDR_NMAGIC :
4104
    RS6K_AOUTHDR_OMAGIC;
4105
#endif
4106
4107
#if defined(SH) && defined(COFF_WITH_PE)
4108
#define __A_MAGIC_SET__
4109
    internal_a.magic = SH_PE_MAGIC;
4110
#endif
4111
4112
#if defined(MIPS) && defined(COFF_WITH_PE)
4113
#define __A_MAGIC_SET__
4114
    internal_a.magic = MIPS_PE_MAGIC;
4115
#endif
4116
4117
#ifndef __A_MAGIC_SET__
4118
#include "Your aouthdr magic number is not being set!"
4119
#else
4120
1
#undef __A_MAGIC_SET__
4121
1
#endif
4122
1
  }
4123
4124
#ifdef RS6000COFF_C
4125
  /* XCOFF 32bit needs this to have new behaviour for n_type field.  */
4126
  internal_a.vstamp = 2;
4127
#else
4128
  /* FIXME: Does anybody ever set this to another value?  */
4129
1
  internal_a.vstamp = 0;
4130
1
#endif
4131
4132
  /* Now should write relocs, strings, syms.  */
4133
1
  obj_sym_filepos (abfd) = sym_base;
4134
4135
1
  if (bfd_get_symcount (abfd) != 0)
4136
0
    {
4137
0
      int firstundef;
4138
4139
0
      if (!coff_renumber_symbols (abfd, &firstundef))
4140
0
  return false;
4141
0
      coff_mangle_symbols (abfd);
4142
0
      if (! coff_write_symbols (abfd))
4143
0
  return false;
4144
0
      if (! coff_write_linenumbers (abfd))
4145
0
  return false;
4146
0
      if (! coff_write_relocs (abfd, firstundef))
4147
0
  return false;
4148
0
    }
4149
1
#ifdef COFF_LONG_SECTION_NAMES
4150
1
  else if (long_section_names && ! obj_coff_strings_written (abfd))
4151
0
    {
4152
      /* If we have long section names we have to write out the string
4153
   table even if there are no symbols.  */
4154
0
      if (! coff_write_symbols (abfd))
4155
0
  return false;
4156
0
    }
4157
1
#endif
4158
  /* If bfd_get_symcount (abfd) != 0, then we are not using the COFF
4159
     backend linker, and obj_raw_syment_count is not valid until after
4160
     coff_write_symbols is called.  */
4161
1
  if (obj_raw_syment_count (abfd) != 0)
4162
0
    {
4163
0
      internal_f.f_symptr = sym_base;
4164
#ifdef RS6000COFF_C
4165
      /* AIX appears to require that F_RELFLG not be set if there are
4166
   local symbols but no relocations.  */
4167
      internal_f.f_flags &=~ F_RELFLG;
4168
#endif
4169
0
    }
4170
1
  else
4171
1
    {
4172
1
      if (long_section_names)
4173
0
  internal_f.f_symptr = sym_base;
4174
1
      else
4175
1
  internal_f.f_symptr = 0;
4176
1
      internal_f.f_flags |= F_LSYMS;
4177
1
    }
4178
4179
1
  if (text_sec)
4180
0
    {
4181
0
      internal_a.tsize = text_sec->size;
4182
0
      internal_a.text_start = internal_a.tsize ? text_sec->vma : 0;
4183
0
    }
4184
1
  if (data_sec)
4185
0
    {
4186
0
      internal_a.dsize = data_sec->size;
4187
0
      internal_a.data_start = internal_a.dsize ? data_sec->vma : 0;
4188
0
    }
4189
1
  if (bss_sec)
4190
0
    {
4191
0
      internal_a.bsize = bss_sec->size;
4192
0
      if (internal_a.bsize && bss_sec->vma < internal_a.data_start)
4193
0
  internal_a.data_start = bss_sec->vma;
4194
0
    }
4195
4196
1
  internal_a.entry = bfd_get_start_address (abfd);
4197
1
  internal_f.f_nsyms = obj_raw_syment_count (abfd);
4198
4199
#ifdef RS6000COFF_C
4200
  if (xcoff_data (abfd)->full_aouthdr)
4201
    {
4202
      bfd_vma toc;
4203
      asection *loader_sec;
4204
4205
      internal_a.vstamp = 2;
4206
4207
      internal_a.o_snentry = xcoff_data (abfd)->snentry;
4208
      if (internal_a.o_snentry == 0)
4209
  internal_a.entry = (bfd_vma) -1;
4210
4211
      if (text_sec != NULL)
4212
  {
4213
    internal_a.o_sntext = text_sec->target_index;
4214
    internal_a.o_algntext = bfd_section_alignment (text_sec);
4215
  }
4216
      else
4217
  {
4218
    internal_a.o_sntext = 0;
4219
    internal_a.o_algntext = 0;
4220
  }
4221
      if (data_sec != NULL)
4222
  {
4223
    internal_a.o_sndata = data_sec->target_index;
4224
    internal_a.o_algndata = bfd_section_alignment (data_sec);
4225
  }
4226
      else
4227
  {
4228
    internal_a.o_sndata = 0;
4229
    internal_a.o_algndata = 0;
4230
  }
4231
      loader_sec = bfd_get_section_by_name (abfd, ".loader");
4232
      if (loader_sec != NULL)
4233
  internal_a.o_snloader = loader_sec->target_index;
4234
      else
4235
  internal_a.o_snloader = 0;
4236
      if (bss_sec != NULL)
4237
  internal_a.o_snbss = bss_sec->target_index;
4238
      else
4239
  internal_a.o_snbss = 0;
4240
4241
      if (tdata_sec != NULL)
4242
  {
4243
    internal_a.o_sntdata = tdata_sec->target_index;
4244
    /* TODO: o_flags should be set to RS6K_AOUTHDR_TLS_LE
4245
       if there is at least one R_TLS_LE relocations.  */
4246
    internal_a.o_flags = 0;
4247
#ifdef XCOFF64
4248
    internal_a.o_x64flags = 0;
4249
#endif
4250
  }
4251
      else
4252
  {
4253
    internal_a.o_sntdata = 0;
4254
    internal_a.o_flags = 0;
4255
#ifdef XCOFF64
4256
    internal_a.o_x64flags = 0;
4257
#endif
4258
  }
4259
      if (tbss_sec != NULL)
4260
    internal_a.o_sntbss = tbss_sec->target_index;
4261
      else
4262
    internal_a.o_sntbss = 0;
4263
4264
      toc = xcoff_data (abfd)->toc;
4265
      internal_a.o_toc = toc;
4266
      internal_a.o_sntoc = xcoff_data (abfd)->sntoc;
4267
4268
      internal_a.o_modtype = xcoff_data (abfd)->modtype;
4269
      if (xcoff_data (abfd)->cputype != -1)
4270
  internal_a.o_cputype = xcoff_data (abfd)->cputype;
4271
      else
4272
  {
4273
    switch (bfd_get_arch (abfd))
4274
      {
4275
      case bfd_arch_rs6000:
4276
        internal_a.o_cputype = 4;
4277
        break;
4278
      case bfd_arch_powerpc:
4279
        if (bfd_get_mach (abfd) == bfd_mach_ppc)
4280
    internal_a.o_cputype = 3;
4281
        else if (bfd_get_mach (abfd) == bfd_mach_ppc_620)
4282
    internal_a.o_cputype = 2;
4283
        else
4284
    internal_a.o_cputype = 1;
4285
        break;
4286
      default:
4287
        abort ();
4288
      }
4289
  }
4290
      internal_a.o_maxstack = xcoff_data (abfd)->maxstack;
4291
      internal_a.o_maxdata = xcoff_data (abfd)->maxdata;
4292
    }
4293
#endif
4294
4295
1
#ifdef COFF_WITH_PE
4296
1
  {
4297
    /* After object contents are finalized so we can compute a reasonable hash,
4298
       but before header is written so we can update it to point to debug directory.  */
4299
1
    struct pe_tdata *pe = pe_data (abfd);
4300
4301
1
    if (pe->build_id.after_write_object_contents != NULL)
4302
0
      (*pe->build_id.after_write_object_contents) (abfd);
4303
1
  }
4304
1
#endif
4305
4306
  /* Now write header.  */
4307
1
  if (bfd_seek (abfd, 0, SEEK_SET) != 0)
4308
0
    return false;
4309
4310
1
  {
4311
1
    char * buff;
4312
1
    bfd_size_type amount = bfd_coff_filhsz (abfd);
4313
4314
1
    buff = (char *) bfd_malloc (amount);
4315
1
    if (buff == NULL)
4316
0
      return false;
4317
4318
1
    bfd_coff_swap_filehdr_out (abfd, & internal_f, buff);
4319
1
    amount = bfd_write (buff, amount, abfd);
4320
4321
1
    free (buff);
4322
4323
1
    if (amount != bfd_coff_filhsz (abfd))
4324
0
      return false;
4325
1
  }
4326
4327
1
  if (abfd->flags & EXEC_P)
4328
1
    {
4329
      /* Note that peicode.h fills in a PEAOUTHDR, not an AOUTHDR.
4330
   include/coff/pe.h sets AOUTSZ == sizeof (PEAOUTHDR)).  */
4331
1
      char * buff;
4332
1
      bfd_size_type amount = bfd_coff_aoutsz (abfd);
4333
4334
1
      buff = (char *) bfd_malloc (amount);
4335
1
      if (buff == NULL)
4336
0
  return false;
4337
4338
1
      coff_swap_aouthdr_out (abfd, & internal_a, buff);
4339
1
      amount = bfd_write (buff, amount, abfd);
4340
4341
1
      free (buff);
4342
4343
1
      if (amount != bfd_coff_aoutsz (abfd))
4344
0
  return false;
4345
4346
1
#ifdef COFF_IMAGE_WITH_PE
4347
1
      if (! coff_apply_checksum (abfd))
4348
0
  return false;
4349
1
#endif
4350
1
    }
4351
#ifdef RS6000COFF_C
4352
#ifndef XCOFF64
4353
  else
4354
    {
4355
      AOUTHDR buff;
4356
      size_t size;
4357
4358
      /* XCOFF32 seems to always write at least a small a.out header.  */
4359
      coff_swap_aouthdr_out (abfd, & internal_a, & buff);
4360
      if (xcoff_data (abfd)->full_aouthdr)
4361
  size = bfd_coff_aoutsz (abfd);
4362
      else
4363
  size = SMALL_AOUTSZ;
4364
      if (bfd_write (&buff, size, abfd) != size)
4365
  return false;
4366
    }
4367
#endif
4368
#endif
4369
4370
1
  return true;
4371
1
}
Unexecuted instantiation: pei-arm.c:coff_write_object_contents
Unexecuted instantiation: pei-mcore.c:coff_write_object_contents
Unexecuted instantiation: pei-sh.c:coff_write_object_contents
4372
4373
static bool
4374
coff_set_section_contents (bfd * abfd,
4375
         sec_ptr section,
4376
         const void * location,
4377
         file_ptr offset,
4378
         bfd_size_type count)
4379
44
{
4380
44
  if (! abfd->output_has_begun)  /* Set by bfd.c handler.  */
4381
9
    {
4382
9
      if (! coff_compute_section_file_positions (abfd))
4383
0
  return false;
4384
9
    }
4385
4386
#if defined(_LIB) && !defined(TARG_AUX)
4387
   /* The physical address field of a .lib section is used to hold the
4388
      number of shared libraries in the section.  This code counts the
4389
      number of sections being written, and increments the lma field
4390
      with the number.
4391
4392
      I have found no documentation on the contents of this section.
4393
      Experimentation indicates that the section contains zero or more
4394
      records, each of which has the following structure:
4395
4396
      - a (four byte) word holding the length of this record, in words,
4397
      - a word that always seems to be set to "2",
4398
      - the path to a shared library, null-terminated and then padded
4399
  to a whole word boundary.
4400
4401
      bfd_assert calls have been added to alert if an attempt is made
4402
      to write a section which doesn't follow these assumptions.  The
4403
      code has been tested on ISC 4.1 by me, and on SCO by Robert Lipe
4404
      <robertl@arnet.com> (Thanks!).
4405
4406
      Gvran Uddeborg <gvran@uddeborg.pp.se>.  */
4407
44
    if (strcmp (section->name, _LIB) == 0)
4408
0
      {
4409
0
  bfd_byte *rec, *recend;
4410
4411
  rec = (bfd_byte *) location;
4412
  recend = rec + count;
4413
0
  while (recend - rec >= 4)
4414
0
    {
4415
0
      size_t len = bfd_get_32 (abfd, rec);
4416
0
      if (len == 0 || len > (size_t) (recend - rec) / 4)
4417
0
        break;
4418
0
      rec += len * 4;
4419
0
      ++section->lma;
4420
0
    }
4421
4422
0
  BFD_ASSERT (rec == recend);
4423
0
      }
4424
44
#endif
4425
4426
  /* Don't write out bss sections - one way to do this is to
4427
       see if the filepos has not been set.  */
4428
44
  if (section->filepos == 0)
4429
0
    return true;
4430
4431
44
  if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0)
4432
0
    return false;
4433
4434
44
  if (count == 0)
4435
0
    return true;
4436
4437
44
  return bfd_write (location, count, abfd) == count;
4438
44
}
pei-i386.c:coff_set_section_contents
Line
Count
Source
4379
4
{
4380
4
  if (! abfd->output_has_begun)  /* Set by bfd.c handler.  */
4381
1
    {
4382
1
      if (! coff_compute_section_file_positions (abfd))
4383
0
  return false;
4384
1
    }
4385
4386
4
#if defined(_LIB) && !defined(TARG_AUX)
4387
   /* The physical address field of a .lib section is used to hold the
4388
      number of shared libraries in the section.  This code counts the
4389
      number of sections being written, and increments the lma field
4390
      with the number.
4391
4392
      I have found no documentation on the contents of this section.
4393
      Experimentation indicates that the section contains zero or more
4394
      records, each of which has the following structure:
4395
4396
      - a (four byte) word holding the length of this record, in words,
4397
      - a word that always seems to be set to "2",
4398
      - the path to a shared library, null-terminated and then padded
4399
  to a whole word boundary.
4400
4401
      bfd_assert calls have been added to alert if an attempt is made
4402
      to write a section which doesn't follow these assumptions.  The
4403
      code has been tested on ISC 4.1 by me, and on SCO by Robert Lipe
4404
      <robertl@arnet.com> (Thanks!).
4405
4406
      Gvran Uddeborg <gvran@uddeborg.pp.se>.  */
4407
4
    if (strcmp (section->name, _LIB) == 0)
4408
0
      {
4409
0
  bfd_byte *rec, *recend;
4410
4411
0
  rec = (bfd_byte *) location;
4412
0
  recend = rec + count;
4413
0
  while (recend - rec >= 4)
4414
0
    {
4415
0
      size_t len = bfd_get_32 (abfd, rec);
4416
0
      if (len == 0 || len > (size_t) (recend - rec) / 4)
4417
0
        break;
4418
0
      rec += len * 4;
4419
0
      ++section->lma;
4420
0
    }
4421
4422
0
  BFD_ASSERT (rec == recend);
4423
0
      }
4424
4
#endif
4425
4426
  /* Don't write out bss sections - one way to do this is to
4427
       see if the filepos has not been set.  */
4428
4
  if (section->filepos == 0)
4429
0
    return true;
4430
4431
4
  if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0)
4432
0
    return false;
4433
4434
4
  if (count == 0)
4435
0
    return true;
4436
4437
4
  return bfd_write (location, count, abfd) == count;
4438
4
}
Unexecuted instantiation: pe-x86_64.c:coff_set_section_contents
pei-x86_64.c:coff_set_section_contents
Line
Count
Source
4379
30
{
4380
30
  if (! abfd->output_has_begun)  /* Set by bfd.c handler.  */
4381
3
    {
4382
3
      if (! coff_compute_section_file_positions (abfd))
4383
0
  return false;
4384
3
    }
4385
4386
30
#if defined(_LIB) && !defined(TARG_AUX)
4387
   /* The physical address field of a .lib section is used to hold the
4388
      number of shared libraries in the section.  This code counts the
4389
      number of sections being written, and increments the lma field
4390
      with the number.
4391
4392
      I have found no documentation on the contents of this section.
4393
      Experimentation indicates that the section contains zero or more
4394
      records, each of which has the following structure:
4395
4396
      - a (four byte) word holding the length of this record, in words,
4397
      - a word that always seems to be set to "2",
4398
      - the path to a shared library, null-terminated and then padded
4399
  to a whole word boundary.
4400
4401
      bfd_assert calls have been added to alert if an attempt is made
4402
      to write a section which doesn't follow these assumptions.  The
4403
      code has been tested on ISC 4.1 by me, and on SCO by Robert Lipe
4404
      <robertl@arnet.com> (Thanks!).
4405
4406
      Gvran Uddeborg <gvran@uddeborg.pp.se>.  */
4407
30
    if (strcmp (section->name, _LIB) == 0)
4408
0
      {
4409
0
  bfd_byte *rec, *recend;
4410
4411
0
  rec = (bfd_byte *) location;
4412
0
  recend = rec + count;
4413
0
  while (recend - rec >= 4)
4414
0
    {
4415
0
      size_t len = bfd_get_32 (abfd, rec);
4416
0
      if (len == 0 || len > (size_t) (recend - rec) / 4)
4417
0
        break;
4418
0
      rec += len * 4;
4419
0
      ++section->lma;
4420
0
    }
4421
4422
0
  BFD_ASSERT (rec == recend);
4423
0
      }
4424
30
#endif
4425
4426
  /* Don't write out bss sections - one way to do this is to
4427
       see if the filepos has not been set.  */
4428
30
  if (section->filepos == 0)
4429
0
    return true;
4430
4431
30
  if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0)
4432
0
    return false;
4433
4434
30
  if (count == 0)
4435
0
    return true;
4436
4437
30
  return bfd_write (location, count, abfd) == count;
4438
30
}
coff-x86_64.c:coff_set_section_contents
Line
Count
Source
4379
2
{
4380
2
  if (! abfd->output_has_begun)  /* Set by bfd.c handler.  */
4381
1
    {
4382
1
      if (! coff_compute_section_file_positions (abfd))
4383
0
  return false;
4384
1
    }
4385
4386
2
#if defined(_LIB) && !defined(TARG_AUX)
4387
   /* The physical address field of a .lib section is used to hold the
4388
      number of shared libraries in the section.  This code counts the
4389
      number of sections being written, and increments the lma field
4390
      with the number.
4391
4392
      I have found no documentation on the contents of this section.
4393
      Experimentation indicates that the section contains zero or more
4394
      records, each of which has the following structure:
4395
4396
      - a (four byte) word holding the length of this record, in words,
4397
      - a word that always seems to be set to "2",
4398
      - the path to a shared library, null-terminated and then padded
4399
  to a whole word boundary.
4400
4401
      bfd_assert calls have been added to alert if an attempt is made
4402
      to write a section which doesn't follow these assumptions.  The
4403
      code has been tested on ISC 4.1 by me, and on SCO by Robert Lipe
4404
      <robertl@arnet.com> (Thanks!).
4405
4406
      Gvran Uddeborg <gvran@uddeborg.pp.se>.  */
4407
2
    if (strcmp (section->name, _LIB) == 0)
4408
0
      {
4409
0
  bfd_byte *rec, *recend;
4410
4411
0
  rec = (bfd_byte *) location;
4412
0
  recend = rec + count;
4413
0
  while (recend - rec >= 4)
4414
0
    {
4415
0
      size_t len = bfd_get_32 (abfd, rec);
4416
0
      if (len == 0 || len > (size_t) (recend - rec) / 4)
4417
0
        break;
4418
0
      rec += len * 4;
4419
0
      ++section->lma;
4420
0
    }
4421
4422
0
  BFD_ASSERT (rec == recend);
4423
0
      }
4424
2
#endif
4425
4426
  /* Don't write out bss sections - one way to do this is to
4427
       see if the filepos has not been set.  */
4428
2
  if (section->filepos == 0)
4429
0
    return true;
4430
4431
2
  if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0)
4432
0
    return false;
4433
4434
2
  if (count == 0)
4435
0
    return true;
4436
4437
2
  return bfd_write (location, count, abfd) == count;
4438
2
}
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
4379
2
{
4380
2
  if (! abfd->output_has_begun)  /* Set by bfd.c handler.  */
4381
1
    {
4382
1
      if (! coff_compute_section_file_positions (abfd))
4383
0
  return false;
4384
1
    }
4385
4386
2
#if defined(_LIB) && !defined(TARG_AUX)
4387
   /* The physical address field of a .lib section is used to hold the
4388
      number of shared libraries in the section.  This code counts the
4389
      number of sections being written, and increments the lma field
4390
      with the number.
4391
4392
      I have found no documentation on the contents of this section.
4393
      Experimentation indicates that the section contains zero or more
4394
      records, each of which has the following structure:
4395
4396
      - a (four byte) word holding the length of this record, in words,
4397
      - a word that always seems to be set to "2",
4398
      - the path to a shared library, null-terminated and then padded
4399
  to a whole word boundary.
4400
4401
      bfd_assert calls have been added to alert if an attempt is made
4402
      to write a section which doesn't follow these assumptions.  The
4403
      code has been tested on ISC 4.1 by me, and on SCO by Robert Lipe
4404
      <robertl@arnet.com> (Thanks!).
4405
4406
      Gvran Uddeborg <gvran@uddeborg.pp.se>.  */
4407
2
    if (strcmp (section->name, _LIB) == 0)
4408
0
      {
4409
0
  bfd_byte *rec, *recend;
4410
4411
0
  rec = (bfd_byte *) location;
4412
0
  recend = rec + count;
4413
0
  while (recend - rec >= 4)
4414
0
    {
4415
0
      size_t len = bfd_get_32 (abfd, rec);
4416
0
      if (len == 0 || len > (size_t) (recend - rec) / 4)
4417
0
        break;
4418
0
      rec += len * 4;
4419
0
      ++section->lma;
4420
0
    }
4421
4422
0
  BFD_ASSERT (rec == recend);
4423
0
      }
4424
2
#endif
4425
4426
  /* Don't write out bss sections - one way to do this is to
4427
       see if the filepos has not been set.  */
4428
2
  if (section->filepos == 0)
4429
0
    return true;
4430
4431
2
  if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0)
4432
0
    return false;
4433
4434
2
  if (count == 0)
4435
0
    return true;
4436
4437
2
  return bfd_write (location, count, abfd) == count;
4438
2
}
pei-ia64.c:coff_set_section_contents
Line
Count
Source
4379
2
{
4380
2
  if (! abfd->output_has_begun)  /* Set by bfd.c handler.  */
4381
1
    {
4382
1
      if (! coff_compute_section_file_positions (abfd))
4383
0
  return false;
4384
1
    }
4385
4386
2
#if defined(_LIB) && !defined(TARG_AUX)
4387
   /* The physical address field of a .lib section is used to hold the
4388
      number of shared libraries in the section.  This code counts the
4389
      number of sections being written, and increments the lma field
4390
      with the number.
4391
4392
      I have found no documentation on the contents of this section.
4393
      Experimentation indicates that the section contains zero or more
4394
      records, each of which has the following structure:
4395
4396
      - a (four byte) word holding the length of this record, in words,
4397
      - a word that always seems to be set to "2",
4398
      - the path to a shared library, null-terminated and then padded
4399
  to a whole word boundary.
4400
4401
      bfd_assert calls have been added to alert if an attempt is made
4402
      to write a section which doesn't follow these assumptions.  The
4403
      code has been tested on ISC 4.1 by me, and on SCO by Robert Lipe
4404
      <robertl@arnet.com> (Thanks!).
4405
4406
      Gvran Uddeborg <gvran@uddeborg.pp.se>.  */
4407
2
    if (strcmp (section->name, _LIB) == 0)
4408
0
      {
4409
0
  bfd_byte *rec, *recend;
4410
4411
0
  rec = (bfd_byte *) location;
4412
0
  recend = rec + count;
4413
0
  while (recend - rec >= 4)
4414
0
    {
4415
0
      size_t len = bfd_get_32 (abfd, rec);
4416
0
      if (len == 0 || len > (size_t) (recend - rec) / 4)
4417
0
        break;
4418
0
      rec += len * 4;
4419
0
      ++section->lma;
4420
0
    }
4421
4422
0
  BFD_ASSERT (rec == recend);
4423
0
      }
4424
2
#endif
4425
4426
  /* Don't write out bss sections - one way to do this is to
4427
       see if the filepos has not been set.  */
4428
2
  if (section->filepos == 0)
4429
0
    return true;
4430
4431
2
  if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0)
4432
0
    return false;
4433
4434
2
  if (count == 0)
4435
0
    return true;
4436
4437
2
  return bfd_write (location, count, abfd) == count;
4438
2
}
Unexecuted instantiation: pei-loongarch64.c:coff_set_section_contents
pei-riscv64.c:coff_set_section_contents
Line
Count
Source
4379
4
{
4380
4
  if (! abfd->output_has_begun)  /* Set by bfd.c handler.  */
4381
2
    {
4382
2
      if (! coff_compute_section_file_positions (abfd))
4383
0
  return false;
4384
2
    }
4385
4386
4
#if defined(_LIB) && !defined(TARG_AUX)
4387
   /* The physical address field of a .lib section is used to hold the
4388
      number of shared libraries in the section.  This code counts the
4389
      number of sections being written, and increments the lma field
4390
      with the number.
4391
4392
      I have found no documentation on the contents of this section.
4393
      Experimentation indicates that the section contains zero or more
4394
      records, each of which has the following structure:
4395
4396
      - a (four byte) word holding the length of this record, in words,
4397
      - a word that always seems to be set to "2",
4398
      - the path to a shared library, null-terminated and then padded
4399
  to a whole word boundary.
4400
4401
      bfd_assert calls have been added to alert if an attempt is made
4402
      to write a section which doesn't follow these assumptions.  The
4403
      code has been tested on ISC 4.1 by me, and on SCO by Robert Lipe
4404
      <robertl@arnet.com> (Thanks!).
4405
4406
      Gvran Uddeborg <gvran@uddeborg.pp.se>.  */
4407
4
    if (strcmp (section->name, _LIB) == 0)
4408
0
      {
4409
0
  bfd_byte *rec, *recend;
4410
4411
0
  rec = (bfd_byte *) location;
4412
0
  recend = rec + count;
4413
0
  while (recend - rec >= 4)
4414
0
    {
4415
0
      size_t len = bfd_get_32 (abfd, rec);
4416
0
      if (len == 0 || len > (size_t) (recend - rec) / 4)
4417
0
        break;
4418
0
      rec += len * 4;
4419
0
      ++section->lma;
4420
0
    }
4421
4422
0
  BFD_ASSERT (rec == recend);
4423
0
      }
4424
4
#endif
4425
4426
  /* Don't write out bss sections - one way to do this is to
4427
       see if the filepos has not been set.  */
4428
4
  if (section->filepos == 0)
4429
0
    return true;
4430
4431
4
  if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0)
4432
0
    return false;
4433
4434
4
  if (count == 0)
4435
0
    return true;
4436
4437
4
  return bfd_write (location, count, abfd) == count;
4438
4
}
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
Unexecuted instantiation: coff-z8k.c:coff_set_section_contents
Unexecuted instantiation: pe-arm-wince.c:coff_set_section_contents
Unexecuted instantiation: pe-arm.c:coff_set_section_contents
Unexecuted instantiation: pe-i386.c:coff_set_section_contents
Unexecuted instantiation: pe-mcore.c:coff_set_section_contents
Unexecuted instantiation: pe-sh.c:coff_set_section_contents
Unexecuted instantiation: pei-arm-wince.c:coff_set_section_contents
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
4439
4440
static void *
4441
buy_and_read (bfd *abfd, file_ptr where,
4442
        bfd_size_type nmemb, bfd_size_type size)
4443
35.6k
{
4444
35.6k
  size_t amt;
4445
4446
35.6k
  if (_bfd_mul_overflow (nmemb, size, &amt))
4447
0
    {
4448
0
      bfd_set_error (bfd_error_file_too_big);
4449
0
      return NULL;
4450
0
    }
4451
35.6k
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4452
620
    return NULL;
4453
35.0k
  return _bfd_malloc_and_read (abfd, amt, amt);
4454
35.6k
}
pei-i386.c:buy_and_read
Line
Count
Source
4443
758
{
4444
758
  size_t amt;
4445
4446
758
  if (_bfd_mul_overflow (nmemb, size, &amt))
4447
0
    {
4448
0
      bfd_set_error (bfd_error_file_too_big);
4449
0
      return NULL;
4450
0
    }
4451
758
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4452
0
    return NULL;
4453
758
  return _bfd_malloc_and_read (abfd, amt, amt);
4454
758
}
pe-x86_64.c:buy_and_read
Line
Count
Source
4443
1.33k
{
4444
1.33k
  size_t amt;
4445
4446
1.33k
  if (_bfd_mul_overflow (nmemb, size, &amt))
4447
0
    {
4448
0
      bfd_set_error (bfd_error_file_too_big);
4449
0
      return NULL;
4450
0
    }
4451
1.33k
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4452
0
    return NULL;
4453
1.33k
  return _bfd_malloc_and_read (abfd, amt, amt);
4454
1.33k
}
pei-x86_64.c:buy_and_read
Line
Count
Source
4443
774
{
4444
774
  size_t amt;
4445
4446
774
  if (_bfd_mul_overflow (nmemb, size, &amt))
4447
0
    {
4448
0
      bfd_set_error (bfd_error_file_too_big);
4449
0
      return NULL;
4450
0
    }
4451
774
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4452
0
    return NULL;
4453
774
  return _bfd_malloc_and_read (abfd, amt, amt);
4454
774
}
coff-x86_64.c:buy_and_read
Line
Count
Source
4443
2.62k
{
4444
2.62k
  size_t amt;
4445
4446
2.62k
  if (_bfd_mul_overflow (nmemb, size, &amt))
4447
0
    {
4448
0
      bfd_set_error (bfd_error_file_too_big);
4449
0
      return NULL;
4450
0
    }
4451
2.62k
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4452
0
    return NULL;
4453
2.62k
  return _bfd_malloc_and_read (abfd, amt, amt);
4454
2.62k
}
coff64-rs6000.c:buy_and_read
Line
Count
Source
4443
1.37k
{
4444
1.37k
  size_t amt;
4445
4446
1.37k
  if (_bfd_mul_overflow (nmemb, size, &amt))
4447
0
    {
4448
0
      bfd_set_error (bfd_error_file_too_big);
4449
0
      return NULL;
4450
0
    }
4451
1.37k
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4452
620
    return NULL;
4453
758
  return _bfd_malloc_and_read (abfd, amt, amt);
4454
1.37k
}
pe-aarch64.c:buy_and_read
Line
Count
Source
4443
1.24k
{
4444
1.24k
  size_t amt;
4445
4446
1.24k
  if (_bfd_mul_overflow (nmemb, size, &amt))
4447
0
    {
4448
0
      bfd_set_error (bfd_error_file_too_big);
4449
0
      return NULL;
4450
0
    }
4451
1.24k
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4452
0
    return NULL;
4453
1.24k
  return _bfd_malloc_and_read (abfd, amt, amt);
4454
1.24k
}
pei-aarch64.c:buy_and_read
Line
Count
Source
4443
740
{
4444
740
  size_t amt;
4445
4446
740
  if (_bfd_mul_overflow (nmemb, size, &amt))
4447
0
    {
4448
0
      bfd_set_error (bfd_error_file_too_big);
4449
0
      return NULL;
4450
0
    }
4451
740
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4452
0
    return NULL;
4453
740
  return _bfd_malloc_and_read (abfd, amt, amt);
4454
740
}
pei-ia64.c:buy_and_read
Line
Count
Source
4443
651
{
4444
651
  size_t amt;
4445
4446
651
  if (_bfd_mul_overflow (nmemb, size, &amt))
4447
0
    {
4448
0
      bfd_set_error (bfd_error_file_too_big);
4449
0
      return NULL;
4450
0
    }
4451
651
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4452
0
    return NULL;
4453
651
  return _bfd_malloc_and_read (abfd, amt, amt);
4454
651
}
pei-loongarch64.c:buy_and_read
Line
Count
Source
4443
772
{
4444
772
  size_t amt;
4445
4446
772
  if (_bfd_mul_overflow (nmemb, size, &amt))
4447
0
    {
4448
0
      bfd_set_error (bfd_error_file_too_big);
4449
0
      return NULL;
4450
0
    }
4451
772
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4452
0
    return NULL;
4453
772
  return _bfd_malloc_and_read (abfd, amt, amt);
4454
772
}
pei-riscv64.c:buy_and_read
Line
Count
Source
4443
865
{
4444
865
  size_t amt;
4445
4446
865
  if (_bfd_mul_overflow (nmemb, size, &amt))
4447
0
    {
4448
0
      bfd_set_error (bfd_error_file_too_big);
4449
0
      return NULL;
4450
0
    }
4451
865
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4452
0
    return NULL;
4453
865
  return _bfd_malloc_and_read (abfd, amt, amt);
4454
865
}
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
4443
1.22k
{
4444
1.22k
  size_t amt;
4445
4446
1.22k
  if (_bfd_mul_overflow (nmemb, size, &amt))
4447
0
    {
4448
0
      bfd_set_error (bfd_error_file_too_big);
4449
0
      return NULL;
4450
0
    }
4451
1.22k
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4452
0
    return NULL;
4453
1.22k
  return _bfd_malloc_and_read (abfd, amt, amt);
4454
1.22k
}
coff-sh.c:buy_and_read
Line
Count
Source
4443
1.75k
{
4444
1.75k
  size_t amt;
4445
4446
1.75k
  if (_bfd_mul_overflow (nmemb, size, &amt))
4447
0
    {
4448
0
      bfd_set_error (bfd_error_file_too_big);
4449
0
      return NULL;
4450
0
    }
4451
1.75k
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4452
0
    return NULL;
4453
1.75k
  return _bfd_malloc_and_read (abfd, amt, amt);
4454
1.75k
}
Unexecuted instantiation: coff-stgo32.c:buy_and_read
coff-tic30.c:buy_and_read
Line
Count
Source
4443
7.19k
{
4444
7.19k
  size_t amt;
4445
4446
7.19k
  if (_bfd_mul_overflow (nmemb, size, &amt))
4447
0
    {
4448
0
      bfd_set_error (bfd_error_file_too_big);
4449
0
      return NULL;
4450
0
    }
4451
7.19k
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4452
0
    return NULL;
4453
7.19k
  return _bfd_malloc_and_read (abfd, amt, amt);
4454
7.19k
}
Unexecuted instantiation: coff-tic4x.c:buy_and_read
coff-tic54x.c:buy_and_read
Line
Count
Source
4443
2.65k
{
4444
2.65k
  size_t amt;
4445
4446
2.65k
  if (_bfd_mul_overflow (nmemb, size, &amt))
4447
0
    {
4448
0
      bfd_set_error (bfd_error_file_too_big);
4449
0
      return NULL;
4450
0
    }
4451
2.65k
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4452
0
    return NULL;
4453
2.65k
  return _bfd_malloc_and_read (abfd, amt, amt);
4454
2.65k
}
coff-z80.c:buy_and_read
Line
Count
Source
4443
4.24k
{
4444
4.24k
  size_t amt;
4445
4446
4.24k
  if (_bfd_mul_overflow (nmemb, size, &amt))
4447
0
    {
4448
0
      bfd_set_error (bfd_error_file_too_big);
4449
0
      return NULL;
4450
0
    }
4451
4.24k
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4452
0
    return NULL;
4453
4.24k
  return _bfd_malloc_and_read (abfd, amt, amt);
4454
4.24k
}
coff-z8k.c:buy_and_read
Line
Count
Source
4443
2.18k
{
4444
2.18k
  size_t amt;
4445
4446
2.18k
  if (_bfd_mul_overflow (nmemb, size, &amt))
4447
0
    {
4448
0
      bfd_set_error (bfd_error_file_too_big);
4449
0
      return NULL;
4450
0
    }
4451
2.18k
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4452
0
    return NULL;
4453
2.18k
  return _bfd_malloc_and_read (abfd, amt, amt);
4454
2.18k
}
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
4443
578
{
4444
578
  size_t amt;
4445
4446
578
  if (_bfd_mul_overflow (nmemb, size, &amt))
4447
0
    {
4448
0
      bfd_set_error (bfd_error_file_too_big);
4449
0
      return NULL;
4450
0
    }
4451
578
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4452
0
    return NULL;
4453
578
  return _bfd_malloc_and_read (abfd, amt, amt);
4454
578
}
pe-mcore.c:buy_and_read
Line
Count
Source
4443
961
{
4444
961
  size_t amt;
4445
4446
961
  if (_bfd_mul_overflow (nmemb, size, &amt))
4447
0
    {
4448
0
      bfd_set_error (bfd_error_file_too_big);
4449
0
      return NULL;
4450
0
    }
4451
961
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4452
0
    return NULL;
4453
961
  return _bfd_malloc_and_read (abfd, amt, amt);
4454
961
}
pe-sh.c:buy_and_read
Line
Count
Source
4443
1.00k
{
4444
1.00k
  size_t amt;
4445
4446
1.00k
  if (_bfd_mul_overflow (nmemb, size, &amt))
4447
0
    {
4448
0
      bfd_set_error (bfd_error_file_too_big);
4449
0
      return NULL;
4450
0
    }
4451
1.00k
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4452
0
    return NULL;
4453
1.00k
  return _bfd_malloc_and_read (abfd, amt, amt);
4454
1.00k
}
pei-arm-wince.c:buy_and_read
Line
Count
Source
4443
559
{
4444
559
  size_t amt;
4445
4446
559
  if (_bfd_mul_overflow (nmemb, size, &amt))
4447
0
    {
4448
0
      bfd_set_error (bfd_error_file_too_big);
4449
0
      return NULL;
4450
0
    }
4451
559
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4452
0
    return NULL;
4453
559
  return _bfd_malloc_and_read (abfd, amt, amt);
4454
559
}
pei-arm.c:buy_and_read
Line
Count
Source
4443
866
{
4444
866
  size_t amt;
4445
4446
866
  if (_bfd_mul_overflow (nmemb, size, &amt))
4447
0
    {
4448
0
      bfd_set_error (bfd_error_file_too_big);
4449
0
      return NULL;
4450
0
    }
4451
866
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4452
0
    return NULL;
4453
866
  return _bfd_malloc_and_read (abfd, amt, amt);
4454
866
}
pei-mcore.c:buy_and_read
Line
Count
Source
4443
648
{
4444
648
  size_t amt;
4445
4446
648
  if (_bfd_mul_overflow (nmemb, size, &amt))
4447
0
    {
4448
0
      bfd_set_error (bfd_error_file_too_big);
4449
0
      return NULL;
4450
0
    }
4451
648
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4452
0
    return NULL;
4453
648
  return _bfd_malloc_and_read (abfd, amt, amt);
4454
648
}
pei-sh.c:buy_and_read
Line
Count
Source
4443
621
{
4444
621
  size_t amt;
4445
4446
621
  if (_bfd_mul_overflow (nmemb, size, &amt))
4447
0
    {
4448
0
      bfd_set_error (bfd_error_file_too_big);
4449
0
      return NULL;
4450
0
    }
4451
621
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4452
0
    return NULL;
4453
621
  return _bfd_malloc_and_read (abfd, amt, amt);
4454
621
}
4455
4456
/*
4457
SUBSUBSECTION
4458
  Reading linenumbers
4459
4460
  Creating the linenumber table is done by reading in the entire
4461
  coff linenumber table, and creating another table for internal use.
4462
4463
  A coff linenumber table is structured so that each function
4464
  is marked as having a line number of 0. Each line within the
4465
  function is an offset from the first line in the function. The
4466
  base of the line number information for the table is stored in
4467
  the symbol associated with the function.
4468
4469
  Note: The PE format uses line number 0 for a flag indicating a
4470
  new source file.
4471
4472
  The information is copied from the external to the internal
4473
  table, and each symbol which marks a function is marked by
4474
  pointing its...
4475
4476
  How does this work ?
4477
*/
4478
4479
static int
4480
coff_sort_func_alent (const void * arg1, const void * arg2)
4481
20.9M
{
4482
20.9M
  const alent *al1 = *(const alent **) arg1;
4483
20.9M
  const alent *al2 = *(const alent **) arg2;
4484
20.9M
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4485
20.9M
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4486
4487
20.9M
  if (s1 == NULL || s2 == NULL)
4488
0
    return 0;
4489
20.9M
  if (s1->symbol.value < s2->symbol.value)
4490
274k
    return -1;
4491
20.7M
  else if (s1->symbol.value > s2->symbol.value)
4492
4.86M
    return 1;
4493
4494
15.8M
  return 0;
4495
20.9M
}
pei-i386.c:coff_sort_func_alent
Line
Count
Source
4481
563k
{
4482
563k
  const alent *al1 = *(const alent **) arg1;
4483
563k
  const alent *al2 = *(const alent **) arg2;
4484
563k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4485
563k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4486
4487
563k
  if (s1 == NULL || s2 == NULL)
4488
0
    return 0;
4489
563k
  if (s1->symbol.value < s2->symbol.value)
4490
8.37k
    return -1;
4491
555k
  else if (s1->symbol.value > s2->symbol.value)
4492
115k
    return 1;
4493
4494
440k
  return 0;
4495
563k
}
pe-x86_64.c:coff_sort_func_alent
Line
Count
Source
4481
799k
{
4482
799k
  const alent *al1 = *(const alent **) arg1;
4483
799k
  const alent *al2 = *(const alent **) arg2;
4484
799k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4485
799k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4486
4487
799k
  if (s1 == NULL || s2 == NULL)
4488
0
    return 0;
4489
799k
  if (s1->symbol.value < s2->symbol.value)
4490
10.4k
    return -1;
4491
789k
  else if (s1->symbol.value > s2->symbol.value)
4492
139k
    return 1;
4493
4494
649k
  return 0;
4495
799k
}
pei-x86_64.c:coff_sort_func_alent
Line
Count
Source
4481
323k
{
4482
323k
  const alent *al1 = *(const alent **) arg1;
4483
323k
  const alent *al2 = *(const alent **) arg2;
4484
323k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4485
323k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4486
4487
323k
  if (s1 == NULL || s2 == NULL)
4488
0
    return 0;
4489
323k
  if (s1->symbol.value < s2->symbol.value)
4490
7.08k
    return -1;
4491
316k
  else if (s1->symbol.value > s2->symbol.value)
4492
70.0k
    return 1;
4493
4494
246k
  return 0;
4495
323k
}
coff-x86_64.c:coff_sort_func_alent
Line
Count
Source
4481
1.39M
{
4482
1.39M
  const alent *al1 = *(const alent **) arg1;
4483
1.39M
  const alent *al2 = *(const alent **) arg2;
4484
1.39M
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4485
1.39M
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4486
4487
1.39M
  if (s1 == NULL || s2 == NULL)
4488
0
    return 0;
4489
1.39M
  if (s1->symbol.value < s2->symbol.value)
4490
12.4k
    return -1;
4491
1.37M
  else if (s1->symbol.value > s2->symbol.value)
4492
272k
    return 1;
4493
4494
1.10M
  return 0;
4495
1.39M
}
coff64-rs6000.c:coff_sort_func_alent
Line
Count
Source
4481
278k
{
4482
278k
  const alent *al1 = *(const alent **) arg1;
4483
278k
  const alent *al2 = *(const alent **) arg2;
4484
278k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4485
278k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4486
4487
278k
  if (s1 == NULL || s2 == NULL)
4488
0
    return 0;
4489
278k
  if (s1->symbol.value < s2->symbol.value)
4490
3.00k
    return -1;
4491
275k
  else if (s1->symbol.value > s2->symbol.value)
4492
27.9k
    return 1;
4493
4494
247k
  return 0;
4495
278k
}
pe-aarch64.c:coff_sort_func_alent
Line
Count
Source
4481
1.28M
{
4482
1.28M
  const alent *al1 = *(const alent **) arg1;
4483
1.28M
  const alent *al2 = *(const alent **) arg2;
4484
1.28M
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4485
1.28M
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4486
4487
1.28M
  if (s1 == NULL || s2 == NULL)
4488
0
    return 0;
4489
1.28M
  if (s1->symbol.value < s2->symbol.value)
4490
19.0k
    return -1;
4491
1.26M
  else if (s1->symbol.value > s2->symbol.value)
4492
381k
    return 1;
4493
4494
885k
  return 0;
4495
1.28M
}
pei-aarch64.c:coff_sort_func_alent
Line
Count
Source
4481
1.29M
{
4482
1.29M
  const alent *al1 = *(const alent **) arg1;
4483
1.29M
  const alent *al2 = *(const alent **) arg2;
4484
1.29M
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4485
1.29M
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4486
4487
1.29M
  if (s1 == NULL || s2 == NULL)
4488
0
    return 0;
4489
1.29M
  if (s1->symbol.value < s2->symbol.value)
4490
13.8k
    return -1;
4491
1.28M
  else if (s1->symbol.value > s2->symbol.value)
4492
186k
    return 1;
4493
4494
1.09M
  return 0;
4495
1.29M
}
pei-ia64.c:coff_sort_func_alent
Line
Count
Source
4481
1.23M
{
4482
1.23M
  const alent *al1 = *(const alent **) arg1;
4483
1.23M
  const alent *al2 = *(const alent **) arg2;
4484
1.23M
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4485
1.23M
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4486
4487
1.23M
  if (s1 == NULL || s2 == NULL)
4488
0
    return 0;
4489
1.23M
  if (s1->symbol.value < s2->symbol.value)
4490
10.2k
    return -1;
4491
1.22M
  else if (s1->symbol.value > s2->symbol.value)
4492
315k
    return 1;
4493
4494
913k
  return 0;
4495
1.23M
}
pei-loongarch64.c:coff_sort_func_alent
Line
Count
Source
4481
2.52M
{
4482
2.52M
  const alent *al1 = *(const alent **) arg1;
4483
2.52M
  const alent *al2 = *(const alent **) arg2;
4484
2.52M
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4485
2.52M
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4486
4487
2.52M
  if (s1 == NULL || s2 == NULL)
4488
0
    return 0;
4489
2.52M
  if (s1->symbol.value < s2->symbol.value)
4490
31.8k
    return -1;
4491
2.49M
  else if (s1->symbol.value > s2->symbol.value)
4492
684k
    return 1;
4493
4494
1.80M
  return 0;
4495
2.52M
}
pei-riscv64.c:coff_sort_func_alent
Line
Count
Source
4481
489k
{
4482
489k
  const alent *al1 = *(const alent **) arg1;
4483
489k
  const alent *al2 = *(const alent **) arg2;
4484
489k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4485
489k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4486
4487
489k
  if (s1 == NULL || s2 == NULL)
4488
0
    return 0;
4489
489k
  if (s1->symbol.value < s2->symbol.value)
4490
6.45k
    return -1;
4491
482k
  else if (s1->symbol.value > s2->symbol.value)
4492
111k
    return 1;
4493
4494
370k
  return 0;
4495
489k
}
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
4481
573k
{
4482
573k
  const alent *al1 = *(const alent **) arg1;
4483
573k
  const alent *al2 = *(const alent **) arg2;
4484
573k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4485
573k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4486
4487
573k
  if (s1 == NULL || s2 == NULL)
4488
0
    return 0;
4489
573k
  if (s1->symbol.value < s2->symbol.value)
4490
8.94k
    return -1;
4491
564k
  else if (s1->symbol.value > s2->symbol.value)
4492
128k
    return 1;
4493
4494
436k
  return 0;
4495
573k
}
coff-sh.c:coff_sort_func_alent
Line
Count
Source
4481
1.32M
{
4482
1.32M
  const alent *al1 = *(const alent **) arg1;
4483
1.32M
  const alent *al2 = *(const alent **) arg2;
4484
1.32M
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4485
1.32M
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4486
4487
1.32M
  if (s1 == NULL || s2 == NULL)
4488
0
    return 0;
4489
1.32M
  if (s1->symbol.value < s2->symbol.value)
4490
26.5k
    return -1;
4491
1.29M
  else if (s1->symbol.value > s2->symbol.value)
4492
211k
    return 1;
4493
4494
1.08M
  return 0;
4495
1.32M
}
Unexecuted instantiation: coff-stgo32.c:coff_sort_func_alent
coff-tic30.c:coff_sort_func_alent
Line
Count
Source
4481
398k
{
4482
398k
  const alent *al1 = *(const alent **) arg1;
4483
398k
  const alent *al2 = *(const alent **) arg2;
4484
398k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4485
398k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4486
4487
398k
  if (s1 == NULL || s2 == NULL)
4488
0
    return 0;
4489
398k
  if (s1->symbol.value < s2->symbol.value)
4490
7.45k
    return -1;
4491
390k
  else if (s1->symbol.value > s2->symbol.value)
4492
61.1k
    return 1;
4493
4494
329k
  return 0;
4495
398k
}
Unexecuted instantiation: coff-tic4x.c:coff_sort_func_alent
coff-tic54x.c:coff_sort_func_alent
Line
Count
Source
4481
726k
{
4482
726k
  const alent *al1 = *(const alent **) arg1;
4483
726k
  const alent *al2 = *(const alent **) arg2;
4484
726k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4485
726k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4486
4487
726k
  if (s1 == NULL || s2 == NULL)
4488
0
    return 0;
4489
726k
  if (s1->symbol.value < s2->symbol.value)
4490
6.92k
    return -1;
4491
719k
  else if (s1->symbol.value > s2->symbol.value)
4492
148k
    return 1;
4493
4494
570k
  return 0;
4495
726k
}
coff-z80.c:coff_sort_func_alent
Line
Count
Source
4481
413k
{
4482
413k
  const alent *al1 = *(const alent **) arg1;
4483
413k
  const alent *al2 = *(const alent **) arg2;
4484
413k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4485
413k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4486
4487
413k
  if (s1 == NULL || s2 == NULL)
4488
0
    return 0;
4489
413k
  if (s1->symbol.value < s2->symbol.value)
4490
5.79k
    return -1;
4491
408k
  else if (s1->symbol.value > s2->symbol.value)
4492
48.2k
    return 1;
4493
4494
359k
  return 0;
4495
413k
}
coff-z8k.c:coff_sort_func_alent
Line
Count
Source
4481
665k
{
4482
665k
  const alent *al1 = *(const alent **) arg1;
4483
665k
  const alent *al2 = *(const alent **) arg2;
4484
665k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4485
665k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4486
4487
665k
  if (s1 == NULL || s2 == NULL)
4488
0
    return 0;
4489
665k
  if (s1->symbol.value < s2->symbol.value)
4490
4.48k
    return -1;
4491
661k
  else if (s1->symbol.value > s2->symbol.value)
4492
121k
    return 1;
4493
4494
540k
  return 0;
4495
665k
}
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
4481
776k
{
4482
776k
  const alent *al1 = *(const alent **) arg1;
4483
776k
  const alent *al2 = *(const alent **) arg2;
4484
776k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4485
776k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4486
4487
776k
  if (s1 == NULL || s2 == NULL)
4488
0
    return 0;
4489
776k
  if (s1->symbol.value < s2->symbol.value)
4490
14.1k
    return -1;
4491
762k
  else if (s1->symbol.value > s2->symbol.value)
4492
231k
    return 1;
4493
4494
530k
  return 0;
4495
776k
}
pe-mcore.c:coff_sort_func_alent
Line
Count
Source
4481
2.28M
{
4482
2.28M
  const alent *al1 = *(const alent **) arg1;
4483
2.28M
  const alent *al2 = *(const alent **) arg2;
4484
2.28M
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4485
2.28M
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4486
4487
2.28M
  if (s1 == NULL || s2 == NULL)
4488
0
    return 0;
4489
2.28M
  if (s1->symbol.value < s2->symbol.value)
4490
12.8k
    return -1;
4491
2.27M
  else if (s1->symbol.value > s2->symbol.value)
4492
661k
    return 1;
4493
4494
1.61M
  return 0;
4495
2.28M
}
pe-sh.c:coff_sort_func_alent
Line
Count
Source
4481
1.50M
{
4482
1.50M
  const alent *al1 = *(const alent **) arg1;
4483
1.50M
  const alent *al2 = *(const alent **) arg2;
4484
1.50M
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4485
1.50M
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4486
4487
1.50M
  if (s1 == NULL || s2 == NULL)
4488
0
    return 0;
4489
1.50M
  if (s1->symbol.value < s2->symbol.value)
4490
31.7k
    return -1;
4491
1.47M
  else if (s1->symbol.value > s2->symbol.value)
4492
424k
    return 1;
4493
4494
1.05M
  return 0;
4495
1.50M
}
pei-arm-wince.c:coff_sort_func_alent
Line
Count
Source
4481
891k
{
4482
891k
  const alent *al1 = *(const alent **) arg1;
4483
891k
  const alent *al2 = *(const alent **) arg2;
4484
891k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4485
891k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4486
4487
891k
  if (s1 == NULL || s2 == NULL)
4488
0
    return 0;
4489
891k
  if (s1->symbol.value < s2->symbol.value)
4490
16.4k
    return -1;
4491
875k
  else if (s1->symbol.value > s2->symbol.value)
4492
215k
    return 1;
4493
4494
659k
  return 0;
4495
891k
}
pei-arm.c:coff_sort_func_alent
Line
Count
Source
4481
337k
{
4482
337k
  const alent *al1 = *(const alent **) arg1;
4483
337k
  const alent *al2 = *(const alent **) arg2;
4484
337k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4485
337k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4486
4487
337k
  if (s1 == NULL || s2 == NULL)
4488
0
    return 0;
4489
337k
  if (s1->symbol.value < s2->symbol.value)
4490
7.49k
    return -1;
4491
330k
  else if (s1->symbol.value > s2->symbol.value)
4492
67.6k
    return 1;
4493
4494
262k
  return 0;
4495
337k
}
pei-mcore.c:coff_sort_func_alent
Line
Count
Source
4481
506k
{
4482
506k
  const alent *al1 = *(const alent **) arg1;
4483
506k
  const alent *al2 = *(const alent **) arg2;
4484
506k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4485
506k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4486
4487
506k
  if (s1 == NULL || s2 == NULL)
4488
0
    return 0;
4489
506k
  if (s1->symbol.value < s2->symbol.value)
4490
4.33k
    return -1;
4491
501k
  else if (s1->symbol.value > s2->symbol.value)
4492
160k
    return 1;
4493
4494
341k
  return 0;
4495
506k
}
pei-sh.c:coff_sort_func_alent
Line
Count
Source
4481
379k
{
4482
379k
  const alent *al1 = *(const alent **) arg1;
4483
379k
  const alent *al2 = *(const alent **) arg2;
4484
379k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4485
379k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4486
4487
379k
  if (s1 == NULL || s2 == NULL)
4488
0
    return 0;
4489
379k
  if (s1->symbol.value < s2->symbol.value)
4490
4.36k
    return -1;
4491
374k
  else if (s1->symbol.value > s2->symbol.value)
4492
76.7k
    return 1;
4493
4494
297k
  return 0;
4495
379k
}
4496
4497
static bool
4498
coff_slurp_line_table (bfd *abfd, asection *asect)
4499
151k
{
4500
151k
  LINENO *native_lineno;
4501
151k
  alent *lineno_cache;
4502
151k
  unsigned int counter;
4503
151k
  alent *cache_ptr;
4504
151k
  bfd_vma prev_offset = 0;
4505
151k
  bool ordered = true;
4506
151k
  unsigned int nbr_func;
4507
151k
  LINENO *src;
4508
151k
  bool have_func;
4509
151k
  bool ret = true;
4510
151k
  size_t amt;
4511
4512
151k
  if (asect->lineno_count == 0)
4513
130k
    return true;
4514
4515
20.5k
  BFD_ASSERT (asect->lineno == NULL);
4516
4517
20.5k
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4518
20.5k
             asect->lineno_count,
4519
20.5k
             bfd_coff_linesz (abfd));
4520
20.5k
  if (native_lineno == NULL)
4521
10.5k
    {
4522
10.5k
      _bfd_error_handler
4523
10.5k
  (_("%pB: warning: line number table read failed"), abfd);
4524
10.5k
      return false;
4525
10.5k
    }
4526
4527
10.0k
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4528
0
    {
4529
0
      bfd_set_error (bfd_error_file_too_big);
4530
0
      free (native_lineno);
4531
0
      return false;
4532
0
    }
4533
10.0k
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4534
10.0k
  if (lineno_cache == NULL)
4535
0
    {
4536
0
      free (native_lineno);
4537
0
      return false;
4538
0
    }
4539
4540
10.0k
  cache_ptr = lineno_cache;
4541
10.0k
  asect->lineno = lineno_cache;
4542
10.0k
  src = native_lineno;
4543
10.0k
  nbr_func = 0;
4544
10.0k
  have_func = false;
4545
4546
17.5M
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4547
17.5M
    {
4548
17.5M
      struct internal_lineno dst;
4549
4550
17.5M
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4551
17.5M
      cache_ptr->line_number = dst.l_lnno;
4552
      /* Appease memory checkers that get all excited about
4553
   uninitialised memory when copying alents if u.offset is
4554
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4555
17.5M
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4556
4557
17.5M
      if (cache_ptr->line_number == 0)
4558
6.54M
  {
4559
6.54M
    combined_entry_type * ent;
4560
6.54M
    unsigned long symndx;
4561
6.54M
    coff_symbol_type *sym;
4562
4563
6.54M
    have_func = false;
4564
6.54M
    symndx = dst.l_addr.l_symndx;
4565
6.54M
    if (symndx >= obj_raw_syment_count (abfd))
4566
2.76M
      {
4567
2.76M
        _bfd_error_handler
4568
    /* xgettext:c-format */
4569
2.76M
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4570
2.76M
     abfd, symndx, counter);
4571
2.76M
        cache_ptr->line_number = -1;
4572
2.76M
        ret = false;
4573
2.76M
        continue;
4574
2.76M
      }
4575
4576
3.78M
    ent = obj_raw_syments (abfd) + symndx;
4577
    /* FIXME: We should not be casting between ints and
4578
       pointers like this.  */
4579
3.78M
    if (! ent->is_sym)
4580
568k
      {
4581
568k
        _bfd_error_handler
4582
    /* xgettext:c-format */
4583
568k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4584
568k
     abfd, symndx, counter);
4585
568k
        cache_ptr->line_number = -1;
4586
568k
        ret = false;
4587
568k
        continue;
4588
568k
      }
4589
3.21M
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4590
4591
    /* PR 17512 file: 078-10659-0.004  */
4592
3.21M
    if (sym < obj_symbols (abfd)
4593
3.21M
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4594
0
      {
4595
0
        _bfd_error_handler
4596
    /* xgettext:c-format */
4597
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4598
0
     abfd, counter);
4599
0
        cache_ptr->line_number = -1;
4600
0
        ret = false;
4601
0
        continue;
4602
0
      }
4603
4604
3.21M
    have_func = true;
4605
3.21M
    nbr_func++;
4606
3.21M
    cache_ptr->u.sym = (asymbol *) sym;
4607
3.21M
    if (sym->lineno != NULL)
4608
3.16M
      _bfd_error_handler
4609
        /* xgettext:c-format */
4610
3.16M
        (_("%pB: warning: duplicate line number information for `%s'"),
4611
3.16M
         abfd, bfd_asymbol_name (&sym->symbol));
4612
4613
3.21M
    sym->lineno = cache_ptr;
4614
3.21M
    if (sym->symbol.value < prev_offset)
4615
89.7k
      ordered = false;
4616
3.21M
    prev_offset = sym->symbol.value;
4617
3.21M
  }
4618
11.0M
      else if (!have_func)
4619
  /* Drop line information that has no associated function.
4620
     PR 17521: file: 078-10659-0.004.  */
4621
7.23M
  continue;
4622
3.78M
      else
4623
3.78M
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4624
7.00M
      cache_ptr++;
4625
7.00M
    }
4626
4627
10.0k
  asect->lineno_count = cache_ptr - lineno_cache;
4628
10.0k
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4629
10.0k
  free (native_lineno);
4630
4631
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4632
10.0k
  if (!ordered)
4633
5.12k
    {
4634
      /* Sort the table.  */
4635
5.12k
      alent **func_table;
4636
5.12k
      alent *n_lineno_cache;
4637
4638
      /* Create a table of functions.  */
4639
5.12k
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4640
0
  {
4641
0
    bfd_set_error (bfd_error_file_too_big);
4642
0
    ret = false;
4643
0
  }
4644
5.12k
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4645
5.12k
  {
4646
5.12k
    alent **p = func_table;
4647
5.12k
    unsigned int i;
4648
4649
6.40M
    for (i = 0; i < asect->lineno_count; i++)
4650
6.39M
      if (lineno_cache[i].line_number == 0)
4651
2.94M
        *p++ = &lineno_cache[i];
4652
4653
5.12k
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4654
4655
    /* Sort by functions.  */
4656
5.12k
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4657
4658
    /* Create the new sorted table.  */
4659
5.12k
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4660
0
      {
4661
0
        bfd_set_error (bfd_error_file_too_big);
4662
0
        ret = false;
4663
0
      }
4664
5.12k
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4665
5.12k
      {
4666
5.12k
        alent *n_cache_ptr = n_lineno_cache;
4667
4668
2.95M
        for (i = 0; i < nbr_func; i++)
4669
2.94M
    {
4670
2.94M
      coff_symbol_type *sym;
4671
2.94M
      alent *old_ptr = func_table[i];
4672
4673
      /* Update the function entry.  */
4674
2.94M
      sym = (coff_symbol_type *) old_ptr->u.sym;
4675
      /* PR binutils/17512: Point the lineno to where
4676
         this entry will be after the memcpy below.  */
4677
2.94M
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4678
      /* Copy the function and line number entries.  */
4679
2.94M
      do
4680
6.39M
        *n_cache_ptr++ = *old_ptr++;
4681
6.39M
      while (old_ptr->line_number != 0);
4682
2.94M
    }
4683
4684
5.12k
        memcpy (lineno_cache, n_lineno_cache,
4685
5.12k
          asect->lineno_count * sizeof (alent));
4686
5.12k
      }
4687
0
    else
4688
0
      ret = false;
4689
5.12k
    bfd_release (abfd, func_table);
4690
5.12k
  }
4691
0
      else
4692
0
  ret = false;
4693
5.12k
    }
4694
4695
10.0k
  return ret;
4696
10.0k
}
pei-i386.c:coff_slurp_line_table
Line
Count
Source
4499
1.26k
{
4500
1.26k
  LINENO *native_lineno;
4501
1.26k
  alent *lineno_cache;
4502
1.26k
  unsigned int counter;
4503
1.26k
  alent *cache_ptr;
4504
1.26k
  bfd_vma prev_offset = 0;
4505
1.26k
  bool ordered = true;
4506
1.26k
  unsigned int nbr_func;
4507
1.26k
  LINENO *src;
4508
1.26k
  bool have_func;
4509
1.26k
  bool ret = true;
4510
1.26k
  size_t amt;
4511
4512
1.26k
  if (asect->lineno_count == 0)
4513
511
    return true;
4514
4515
758
  BFD_ASSERT (asect->lineno == NULL);
4516
4517
758
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4518
758
             asect->lineno_count,
4519
758
             bfd_coff_linesz (abfd));
4520
758
  if (native_lineno == NULL)
4521
501
    {
4522
501
      _bfd_error_handler
4523
501
  (_("%pB: warning: line number table read failed"), abfd);
4524
501
      return false;
4525
501
    }
4526
4527
257
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4528
0
    {
4529
0
      bfd_set_error (bfd_error_file_too_big);
4530
0
      free (native_lineno);
4531
0
      return false;
4532
0
    }
4533
257
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4534
257
  if (lineno_cache == NULL)
4535
0
    {
4536
0
      free (native_lineno);
4537
0
      return false;
4538
0
    }
4539
4540
257
  cache_ptr = lineno_cache;
4541
257
  asect->lineno = lineno_cache;
4542
257
  src = native_lineno;
4543
257
  nbr_func = 0;
4544
257
  have_func = false;
4545
4546
339k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4547
339k
    {
4548
339k
      struct internal_lineno dst;
4549
4550
339k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4551
339k
      cache_ptr->line_number = dst.l_lnno;
4552
      /* Appease memory checkers that get all excited about
4553
   uninitialised memory when copying alents if u.offset is
4554
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4555
339k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4556
4557
339k
      if (cache_ptr->line_number == 0)
4558
176k
  {
4559
176k
    combined_entry_type * ent;
4560
176k
    unsigned long symndx;
4561
176k
    coff_symbol_type *sym;
4562
4563
176k
    have_func = false;
4564
176k
    symndx = dst.l_addr.l_symndx;
4565
176k
    if (symndx >= obj_raw_syment_count (abfd))
4566
76.1k
      {
4567
76.1k
        _bfd_error_handler
4568
    /* xgettext:c-format */
4569
76.1k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4570
76.1k
     abfd, symndx, counter);
4571
76.1k
        cache_ptr->line_number = -1;
4572
76.1k
        ret = false;
4573
76.1k
        continue;
4574
76.1k
      }
4575
4576
100k
    ent = obj_raw_syments (abfd) + symndx;
4577
    /* FIXME: We should not be casting between ints and
4578
       pointers like this.  */
4579
100k
    if (! ent->is_sym)
4580
9.91k
      {
4581
9.91k
        _bfd_error_handler
4582
    /* xgettext:c-format */
4583
9.91k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4584
9.91k
     abfd, symndx, counter);
4585
9.91k
        cache_ptr->line_number = -1;
4586
9.91k
        ret = false;
4587
9.91k
        continue;
4588
9.91k
      }
4589
90.2k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4590
4591
    /* PR 17512 file: 078-10659-0.004  */
4592
90.2k
    if (sym < obj_symbols (abfd)
4593
90.2k
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4594
0
      {
4595
0
        _bfd_error_handler
4596
    /* xgettext:c-format */
4597
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4598
0
     abfd, counter);
4599
0
        cache_ptr->line_number = -1;
4600
0
        ret = false;
4601
0
        continue;
4602
0
      }
4603
4604
90.2k
    have_func = true;
4605
90.2k
    nbr_func++;
4606
90.2k
    cache_ptr->u.sym = (asymbol *) sym;
4607
90.2k
    if (sym->lineno != NULL)
4608
88.6k
      _bfd_error_handler
4609
        /* xgettext:c-format */
4610
88.6k
        (_("%pB: warning: duplicate line number information for `%s'"),
4611
88.6k
         abfd, bfd_asymbol_name (&sym->symbol));
4612
4613
90.2k
    sym->lineno = cache_ptr;
4614
90.2k
    if (sym->symbol.value < prev_offset)
4615
2.73k
      ordered = false;
4616
90.2k
    prev_offset = sym->symbol.value;
4617
90.2k
  }
4618
162k
      else if (!have_func)
4619
  /* Drop line information that has no associated function.
4620
     PR 17521: file: 078-10659-0.004.  */
4621
98.3k
  continue;
4622
64.5k
      else
4623
64.5k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4624
154k
      cache_ptr++;
4625
154k
    }
4626
4627
257
  asect->lineno_count = cache_ptr - lineno_cache;
4628
257
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4629
257
  free (native_lineno);
4630
4631
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4632
257
  if (!ordered)
4633
155
    {
4634
      /* Sort the table.  */
4635
155
      alent **func_table;
4636
155
      alent *n_lineno_cache;
4637
4638
      /* Create a table of functions.  */
4639
155
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4640
0
  {
4641
0
    bfd_set_error (bfd_error_file_too_big);
4642
0
    ret = false;
4643
0
  }
4644
155
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4645
155
  {
4646
155
    alent **p = func_table;
4647
155
    unsigned int i;
4648
4649
150k
    for (i = 0; i < asect->lineno_count; i++)
4650
149k
      if (lineno_cache[i].line_number == 0)
4651
87.2k
        *p++ = &lineno_cache[i];
4652
4653
155
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4654
4655
    /* Sort by functions.  */
4656
155
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4657
4658
    /* Create the new sorted table.  */
4659
155
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4660
0
      {
4661
0
        bfd_set_error (bfd_error_file_too_big);
4662
0
        ret = false;
4663
0
      }
4664
155
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4665
155
      {
4666
155
        alent *n_cache_ptr = n_lineno_cache;
4667
4668
87.4k
        for (i = 0; i < nbr_func; i++)
4669
87.2k
    {
4670
87.2k
      coff_symbol_type *sym;
4671
87.2k
      alent *old_ptr = func_table[i];
4672
4673
      /* Update the function entry.  */
4674
87.2k
      sym = (coff_symbol_type *) old_ptr->u.sym;
4675
      /* PR binutils/17512: Point the lineno to where
4676
         this entry will be after the memcpy below.  */
4677
87.2k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4678
      /* Copy the function and line number entries.  */
4679
87.2k
      do
4680
149k
        *n_cache_ptr++ = *old_ptr++;
4681
149k
      while (old_ptr->line_number != 0);
4682
87.2k
    }
4683
4684
155
        memcpy (lineno_cache, n_lineno_cache,
4685
155
          asect->lineno_count * sizeof (alent));
4686
155
      }
4687
0
    else
4688
0
      ret = false;
4689
155
    bfd_release (abfd, func_table);
4690
155
  }
4691
0
      else
4692
0
  ret = false;
4693
155
    }
4694
4695
257
  return ret;
4696
257
}
pe-x86_64.c:coff_slurp_line_table
Line
Count
Source
4499
30.0k
{
4500
30.0k
  LINENO *native_lineno;
4501
30.0k
  alent *lineno_cache;
4502
30.0k
  unsigned int counter;
4503
30.0k
  alent *cache_ptr;
4504
30.0k
  bfd_vma prev_offset = 0;
4505
30.0k
  bool ordered = true;
4506
30.0k
  unsigned int nbr_func;
4507
30.0k
  LINENO *src;
4508
30.0k
  bool have_func;
4509
30.0k
  bool ret = true;
4510
30.0k
  size_t amt;
4511
4512
30.0k
  if (asect->lineno_count == 0)
4513
29.0k
    return true;
4514
4515
1.00k
  BFD_ASSERT (asect->lineno == NULL);
4516
4517
1.00k
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4518
1.00k
             asect->lineno_count,
4519
1.00k
             bfd_coff_linesz (abfd));
4520
1.00k
  if (native_lineno == NULL)
4521
469
    {
4522
469
      _bfd_error_handler
4523
469
  (_("%pB: warning: line number table read failed"), abfd);
4524
469
      return false;
4525
469
    }
4526
4527
534
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4528
0
    {
4529
0
      bfd_set_error (bfd_error_file_too_big);
4530
0
      free (native_lineno);
4531
0
      return false;
4532
0
    }
4533
534
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4534
534
  if (lineno_cache == NULL)
4535
0
    {
4536
0
      free (native_lineno);
4537
0
      return false;
4538
0
    }
4539
4540
534
  cache_ptr = lineno_cache;
4541
534
  asect->lineno = lineno_cache;
4542
534
  src = native_lineno;
4543
534
  nbr_func = 0;
4544
534
  have_func = false;
4545
4546
414k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4547
413k
    {
4548
413k
      struct internal_lineno dst;
4549
4550
413k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4551
413k
      cache_ptr->line_number = dst.l_lnno;
4552
      /* Appease memory checkers that get all excited about
4553
   uninitialised memory when copying alents if u.offset is
4554
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4555
413k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4556
4557
413k
      if (cache_ptr->line_number == 0)
4558
178k
  {
4559
178k
    combined_entry_type * ent;
4560
178k
    unsigned long symndx;
4561
178k
    coff_symbol_type *sym;
4562
4563
178k
    have_func = false;
4564
178k
    symndx = dst.l_addr.l_symndx;
4565
178k
    if (symndx >= obj_raw_syment_count (abfd))
4566
63.7k
      {
4567
63.7k
        _bfd_error_handler
4568
    /* xgettext:c-format */
4569
63.7k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4570
63.7k
     abfd, symndx, counter);
4571
63.7k
        cache_ptr->line_number = -1;
4572
63.7k
        ret = false;
4573
63.7k
        continue;
4574
63.7k
      }
4575
4576
114k
    ent = obj_raw_syments (abfd) + symndx;
4577
    /* FIXME: We should not be casting between ints and
4578
       pointers like this.  */
4579
114k
    if (! ent->is_sym)
4580
4.87k
      {
4581
4.87k
        _bfd_error_handler
4582
    /* xgettext:c-format */
4583
4.87k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4584
4.87k
     abfd, symndx, counter);
4585
4.87k
        cache_ptr->line_number = -1;
4586
4.87k
        ret = false;
4587
4.87k
        continue;
4588
4.87k
      }
4589
109k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4590
4591
    /* PR 17512 file: 078-10659-0.004  */
4592
109k
    if (sym < obj_symbols (abfd)
4593
109k
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4594
0
      {
4595
0
        _bfd_error_handler
4596
    /* xgettext:c-format */
4597
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4598
0
     abfd, counter);
4599
0
        cache_ptr->line_number = -1;
4600
0
        ret = false;
4601
0
        continue;
4602
0
      }
4603
4604
109k
    have_func = true;
4605
109k
    nbr_func++;
4606
109k
    cache_ptr->u.sym = (asymbol *) sym;
4607
109k
    if (sym->lineno != NULL)
4608
108k
      _bfd_error_handler
4609
        /* xgettext:c-format */
4610
108k
        (_("%pB: warning: duplicate line number information for `%s'"),
4611
108k
         abfd, bfd_asymbol_name (&sym->symbol));
4612
4613
109k
    sym->lineno = cache_ptr;
4614
109k
    if (sym->symbol.value < prev_offset)
4615
2.61k
      ordered = false;
4616
109k
    prev_offset = sym->symbol.value;
4617
109k
  }
4618
235k
      else if (!have_func)
4619
  /* Drop line information that has no associated function.
4620
     PR 17521: file: 078-10659-0.004.  */
4621
122k
  continue;
4622
112k
      else
4623
112k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4624
222k
      cache_ptr++;
4625
222k
    }
4626
4627
534
  asect->lineno_count = cache_ptr - lineno_cache;
4628
534
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4629
534
  free (native_lineno);
4630
4631
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4632
534
  if (!ordered)
4633
219
    {
4634
      /* Sort the table.  */
4635
219
      alent **func_table;
4636
219
      alent *n_lineno_cache;
4637
4638
      /* Create a table of functions.  */
4639
219
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4640
0
  {
4641
0
    bfd_set_error (bfd_error_file_too_big);
4642
0
    ret = false;
4643
0
  }
4644
219
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4645
219
  {
4646
219
    alent **p = func_table;
4647
219
    unsigned int i;
4648
4649
214k
    for (i = 0; i < asect->lineno_count; i++)
4650
214k
      if (lineno_cache[i].line_number == 0)
4651
106k
        *p++ = &lineno_cache[i];
4652
4653
219
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4654
4655
    /* Sort by functions.  */
4656
219
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4657
4658
    /* Create the new sorted table.  */
4659
219
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4660
0
      {
4661
0
        bfd_set_error (bfd_error_file_too_big);
4662
0
        ret = false;
4663
0
      }
4664
219
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4665
219
      {
4666
219
        alent *n_cache_ptr = n_lineno_cache;
4667
4668
107k
        for (i = 0; i < nbr_func; i++)
4669
106k
    {
4670
106k
      coff_symbol_type *sym;
4671
106k
      alent *old_ptr = func_table[i];
4672
4673
      /* Update the function entry.  */
4674
106k
      sym = (coff_symbol_type *) old_ptr->u.sym;
4675
      /* PR binutils/17512: Point the lineno to where
4676
         this entry will be after the memcpy below.  */
4677
106k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4678
      /* Copy the function and line number entries.  */
4679
106k
      do
4680
214k
        *n_cache_ptr++ = *old_ptr++;
4681
214k
      while (old_ptr->line_number != 0);
4682
106k
    }
4683
4684
219
        memcpy (lineno_cache, n_lineno_cache,
4685
219
          asect->lineno_count * sizeof (alent));
4686
219
      }
4687
0
    else
4688
0
      ret = false;
4689
219
    bfd_release (abfd, func_table);
4690
219
  }
4691
0
      else
4692
0
  ret = false;
4693
219
    }
4694
4695
534
  return ret;
4696
534
}
pei-x86_64.c:coff_slurp_line_table
Line
Count
Source
4499
8.21k
{
4500
8.21k
  LINENO *native_lineno;
4501
8.21k
  alent *lineno_cache;
4502
8.21k
  unsigned int counter;
4503
8.21k
  alent *cache_ptr;
4504
8.21k
  bfd_vma prev_offset = 0;
4505
8.21k
  bool ordered = true;
4506
8.21k
  unsigned int nbr_func;
4507
8.21k
  LINENO *src;
4508
8.21k
  bool have_func;
4509
8.21k
  bool ret = true;
4510
8.21k
  size_t amt;
4511
4512
8.21k
  if (asect->lineno_count == 0)
4513
7.44k
    return true;
4514
4515
774
  BFD_ASSERT (asect->lineno == NULL);
4516
4517
774
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4518
774
             asect->lineno_count,
4519
774
             bfd_coff_linesz (abfd));
4520
774
  if (native_lineno == NULL)
4521
411
    {
4522
411
      _bfd_error_handler
4523
411
  (_("%pB: warning: line number table read failed"), abfd);
4524
411
      return false;
4525
411
    }
4526
4527
363
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4528
0
    {
4529
0
      bfd_set_error (bfd_error_file_too_big);
4530
0
      free (native_lineno);
4531
0
      return false;
4532
0
    }
4533
363
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4534
363
  if (lineno_cache == NULL)
4535
0
    {
4536
0
      free (native_lineno);
4537
0
      return false;
4538
0
    }
4539
4540
363
  cache_ptr = lineno_cache;
4541
363
  asect->lineno = lineno_cache;
4542
363
  src = native_lineno;
4543
363
  nbr_func = 0;
4544
363
  have_func = false;
4545
4546
272k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4547
271k
    {
4548
271k
      struct internal_lineno dst;
4549
4550
271k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4551
271k
      cache_ptr->line_number = dst.l_lnno;
4552
      /* Appease memory checkers that get all excited about
4553
   uninitialised memory when copying alents if u.offset is
4554
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4555
271k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4556
4557
271k
      if (cache_ptr->line_number == 0)
4558
118k
  {
4559
118k
    combined_entry_type * ent;
4560
118k
    unsigned long symndx;
4561
118k
    coff_symbol_type *sym;
4562
4563
118k
    have_func = false;
4564
118k
    symndx = dst.l_addr.l_symndx;
4565
118k
    if (symndx >= obj_raw_syment_count (abfd))
4566
53.8k
      {
4567
53.8k
        _bfd_error_handler
4568
    /* xgettext:c-format */
4569
53.8k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4570
53.8k
     abfd, symndx, counter);
4571
53.8k
        cache_ptr->line_number = -1;
4572
53.8k
        ret = false;
4573
53.8k
        continue;
4574
53.8k
      }
4575
4576
64.3k
    ent = obj_raw_syments (abfd) + symndx;
4577
    /* FIXME: We should not be casting between ints and
4578
       pointers like this.  */
4579
64.3k
    if (! ent->is_sym)
4580
8.56k
      {
4581
8.56k
        _bfd_error_handler
4582
    /* xgettext:c-format */
4583
8.56k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4584
8.56k
     abfd, symndx, counter);
4585
8.56k
        cache_ptr->line_number = -1;
4586
8.56k
        ret = false;
4587
8.56k
        continue;
4588
8.56k
      }
4589
55.7k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4590
4591
    /* PR 17512 file: 078-10659-0.004  */
4592
55.7k
    if (sym < obj_symbols (abfd)
4593
55.7k
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4594
0
      {
4595
0
        _bfd_error_handler
4596
    /* xgettext:c-format */
4597
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4598
0
     abfd, counter);
4599
0
        cache_ptr->line_number = -1;
4600
0
        ret = false;
4601
0
        continue;
4602
0
      }
4603
4604
55.7k
    have_func = true;
4605
55.7k
    nbr_func++;
4606
55.7k
    cache_ptr->u.sym = (asymbol *) sym;
4607
55.7k
    if (sym->lineno != NULL)
4608
54.2k
      _bfd_error_handler
4609
        /* xgettext:c-format */
4610
54.2k
        (_("%pB: warning: duplicate line number information for `%s'"),
4611
54.2k
         abfd, bfd_asymbol_name (&sym->symbol));
4612
4613
55.7k
    sym->lineno = cache_ptr;
4614
55.7k
    if (sym->symbol.value < prev_offset)
4615
2.19k
      ordered = false;
4616
55.7k
    prev_offset = sym->symbol.value;
4617
55.7k
  }
4618
153k
      else if (!have_func)
4619
  /* Drop line information that has no associated function.
4620
     PR 17521: file: 078-10659-0.004.  */
4621
105k
  continue;
4622
48.0k
      else
4623
48.0k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4624
103k
      cache_ptr++;
4625
103k
    }
4626
4627
363
  asect->lineno_count = cache_ptr - lineno_cache;
4628
363
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4629
363
  free (native_lineno);
4630
4631
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4632
363
  if (!ordered)
4633
162
    {
4634
      /* Sort the table.  */
4635
162
      alent **func_table;
4636
162
      alent *n_lineno_cache;
4637
4638
      /* Create a table of functions.  */
4639
162
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4640
0
  {
4641
0
    bfd_set_error (bfd_error_file_too_big);
4642
0
    ret = false;
4643
0
  }
4644
162
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4645
162
  {
4646
162
    alent **p = func_table;
4647
162
    unsigned int i;
4648
4649
95.3k
    for (i = 0; i < asect->lineno_count; i++)
4650
95.2k
      if (lineno_cache[i].line_number == 0)
4651
51.1k
        *p++ = &lineno_cache[i];
4652
4653
162
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4654
4655
    /* Sort by functions.  */
4656
162
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4657
4658
    /* Create the new sorted table.  */
4659
162
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4660
0
      {
4661
0
        bfd_set_error (bfd_error_file_too_big);
4662
0
        ret = false;
4663
0
      }
4664
162
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4665
162
      {
4666
162
        alent *n_cache_ptr = n_lineno_cache;
4667
4668
51.3k
        for (i = 0; i < nbr_func; i++)
4669
51.1k
    {
4670
51.1k
      coff_symbol_type *sym;
4671
51.1k
      alent *old_ptr = func_table[i];
4672
4673
      /* Update the function entry.  */
4674
51.1k
      sym = (coff_symbol_type *) old_ptr->u.sym;
4675
      /* PR binutils/17512: Point the lineno to where
4676
         this entry will be after the memcpy below.  */
4677
51.1k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4678
      /* Copy the function and line number entries.  */
4679
51.1k
      do
4680
95.2k
        *n_cache_ptr++ = *old_ptr++;
4681
95.2k
      while (old_ptr->line_number != 0);
4682
51.1k
    }
4683
4684
162
        memcpy (lineno_cache, n_lineno_cache,
4685
162
          asect->lineno_count * sizeof (alent));
4686
162
      }
4687
0
    else
4688
0
      ret = false;
4689
162
    bfd_release (abfd, func_table);
4690
162
  }
4691
0
      else
4692
0
  ret = false;
4693
162
    }
4694
4695
363
  return ret;
4696
363
}
coff-x86_64.c:coff_slurp_line_table
Line
Count
Source
4499
51.9k
{
4500
51.9k
  LINENO *native_lineno;
4501
51.9k
  alent *lineno_cache;
4502
51.9k
  unsigned int counter;
4503
51.9k
  alent *cache_ptr;
4504
51.9k
  bfd_vma prev_offset = 0;
4505
51.9k
  bool ordered = true;
4506
51.9k
  unsigned int nbr_func;
4507
51.9k
  LINENO *src;
4508
51.9k
  bool have_func;
4509
51.9k
  bool ret = true;
4510
51.9k
  size_t amt;
4511
4512
51.9k
  if (asect->lineno_count == 0)
4513
50.4k
    return true;
4514
4515
1.43k
  BFD_ASSERT (asect->lineno == NULL);
4516
4517
1.43k
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4518
1.43k
             asect->lineno_count,
4519
1.43k
             bfd_coff_linesz (abfd));
4520
1.43k
  if (native_lineno == NULL)
4521
797
    {
4522
797
      _bfd_error_handler
4523
797
  (_("%pB: warning: line number table read failed"), abfd);
4524
797
      return false;
4525
797
    }
4526
4527
640
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4528
0
    {
4529
0
      bfd_set_error (bfd_error_file_too_big);
4530
0
      free (native_lineno);
4531
0
      return false;
4532
0
    }
4533
640
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4534
640
  if (lineno_cache == NULL)
4535
0
    {
4536
0
      free (native_lineno);
4537
0
      return false;
4538
0
    }
4539
4540
640
  cache_ptr = lineno_cache;
4541
640
  asect->lineno = lineno_cache;
4542
640
  src = native_lineno;
4543
640
  nbr_func = 0;
4544
640
  have_func = false;
4545
4546
929k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4547
929k
    {
4548
929k
      struct internal_lineno dst;
4549
4550
929k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4551
929k
      cache_ptr->line_number = dst.l_lnno;
4552
      /* Appease memory checkers that get all excited about
4553
   uninitialised memory when copying alents if u.offset is
4554
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4555
929k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4556
4557
929k
      if (cache_ptr->line_number == 0)
4558
405k
  {
4559
405k
    combined_entry_type * ent;
4560
405k
    unsigned long symndx;
4561
405k
    coff_symbol_type *sym;
4562
4563
405k
    have_func = false;
4564
405k
    symndx = dst.l_addr.l_symndx;
4565
405k
    if (symndx >= obj_raw_syment_count (abfd))
4566
145k
      {
4567
145k
        _bfd_error_handler
4568
    /* xgettext:c-format */
4569
145k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4570
145k
     abfd, symndx, counter);
4571
145k
        cache_ptr->line_number = -1;
4572
145k
        ret = false;
4573
145k
        continue;
4574
145k
      }
4575
4576
260k
    ent = obj_raw_syments (abfd) + symndx;
4577
    /* FIXME: We should not be casting between ints and
4578
       pointers like this.  */
4579
260k
    if (! ent->is_sym)
4580
29.6k
      {
4581
29.6k
        _bfd_error_handler
4582
    /* xgettext:c-format */
4583
29.6k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4584
29.6k
     abfd, symndx, counter);
4585
29.6k
        cache_ptr->line_number = -1;
4586
29.6k
        ret = false;
4587
29.6k
        continue;
4588
29.6k
      }
4589
230k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4590
4591
    /* PR 17512 file: 078-10659-0.004  */
4592
230k
    if (sym < obj_symbols (abfd)
4593
230k
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4594
0
      {
4595
0
        _bfd_error_handler
4596
    /* xgettext:c-format */
4597
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4598
0
     abfd, counter);
4599
0
        cache_ptr->line_number = -1;
4600
0
        ret = false;
4601
0
        continue;
4602
0
      }
4603
4604
230k
    have_func = true;
4605
230k
    nbr_func++;
4606
230k
    cache_ptr->u.sym = (asymbol *) sym;
4607
230k
    if (sym->lineno != NULL)
4608
228k
      _bfd_error_handler
4609
        /* xgettext:c-format */
4610
228k
        (_("%pB: warning: duplicate line number information for `%s'"),
4611
228k
         abfd, bfd_asymbol_name (&sym->symbol));
4612
4613
230k
    sym->lineno = cache_ptr;
4614
230k
    if (sym->symbol.value < prev_offset)
4615
4.09k
      ordered = false;
4616
230k
    prev_offset = sym->symbol.value;
4617
230k
  }
4618
523k
      else if (!have_func)
4619
  /* Drop line information that has no associated function.
4620
     PR 17521: file: 078-10659-0.004.  */
4621
325k
  continue;
4622
197k
      else
4623
197k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4624
428k
      cache_ptr++;
4625
428k
    }
4626
4627
640
  asect->lineno_count = cache_ptr - lineno_cache;
4628
640
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4629
640
  free (native_lineno);
4630
4631
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4632
640
  if (!ordered)
4633
274
    {
4634
      /* Sort the table.  */
4635
274
      alent **func_table;
4636
274
      alent *n_lineno_cache;
4637
4638
      /* Create a table of functions.  */
4639
274
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4640
0
  {
4641
0
    bfd_set_error (bfd_error_file_too_big);
4642
0
    ret = false;
4643
0
  }
4644
274
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4645
274
  {
4646
274
    alent **p = func_table;
4647
274
    unsigned int i;
4648
4649
300k
    for (i = 0; i < asect->lineno_count; i++)
4650
300k
      if (lineno_cache[i].line_number == 0)
4651
178k
        *p++ = &lineno_cache[i];
4652
4653
274
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4654
4655
    /* Sort by functions.  */
4656
274
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4657
4658
    /* Create the new sorted table.  */
4659
274
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4660
0
      {
4661
0
        bfd_set_error (bfd_error_file_too_big);
4662
0
        ret = false;
4663
0
      }
4664
274
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4665
274
      {
4666
274
        alent *n_cache_ptr = n_lineno_cache;
4667
4668
178k
        for (i = 0; i < nbr_func; i++)
4669
178k
    {
4670
178k
      coff_symbol_type *sym;
4671
178k
      alent *old_ptr = func_table[i];
4672
4673
      /* Update the function entry.  */
4674
178k
      sym = (coff_symbol_type *) old_ptr->u.sym;
4675
      /* PR binutils/17512: Point the lineno to where
4676
         this entry will be after the memcpy below.  */
4677
178k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4678
      /* Copy the function and line number entries.  */
4679
178k
      do
4680
300k
        *n_cache_ptr++ = *old_ptr++;
4681
300k
      while (old_ptr->line_number != 0);
4682
178k
    }
4683
4684
274
        memcpy (lineno_cache, n_lineno_cache,
4685
274
          asect->lineno_count * sizeof (alent));
4686
274
      }
4687
0
    else
4688
0
      ret = false;
4689
274
    bfd_release (abfd, func_table);
4690
274
  }
4691
0
      else
4692
0
  ret = false;
4693
274
    }
4694
4695
640
  return ret;
4696
640
}
coff64-rs6000.c:coff_slurp_line_table
Line
Count
Source
4499
4.96k
{
4500
4.96k
  LINENO *native_lineno;
4501
4.96k
  alent *lineno_cache;
4502
4.96k
  unsigned int counter;
4503
4.96k
  alent *cache_ptr;
4504
4.96k
  bfd_vma prev_offset = 0;
4505
4.96k
  bool ordered = true;
4506
4.96k
  unsigned int nbr_func;
4507
4.96k
  LINENO *src;
4508
4.96k
  bool have_func;
4509
4.96k
  bool ret = true;
4510
4.96k
  size_t amt;
4511
4512
4.96k
  if (asect->lineno_count == 0)
4513
3.78k
    return true;
4514
4515
1.18k
  BFD_ASSERT (asect->lineno == NULL);
4516
4517
1.18k
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4518
1.18k
             asect->lineno_count,
4519
1.18k
             bfd_coff_linesz (abfd));
4520
1.18k
  if (native_lineno == NULL)
4521
789
    {
4522
789
      _bfd_error_handler
4523
789
  (_("%pB: warning: line number table read failed"), abfd);
4524
789
      return false;
4525
789
    }
4526
4527
392
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4528
0
    {
4529
0
      bfd_set_error (bfd_error_file_too_big);
4530
0
      free (native_lineno);
4531
0
      return false;
4532
0
    }
4533
392
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4534
392
  if (lineno_cache == NULL)
4535
0
    {
4536
0
      free (native_lineno);
4537
0
      return false;
4538
0
    }
4539
4540
392
  cache_ptr = lineno_cache;
4541
392
  asect->lineno = lineno_cache;
4542
392
  src = native_lineno;
4543
392
  nbr_func = 0;
4544
392
  have_func = false;
4545
4546
325k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4547
325k
    {
4548
325k
      struct internal_lineno dst;
4549
4550
325k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4551
325k
      cache_ptr->line_number = dst.l_lnno;
4552
      /* Appease memory checkers that get all excited about
4553
   uninitialised memory when copying alents if u.offset is
4554
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4555
325k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4556
4557
325k
      if (cache_ptr->line_number == 0)
4558
126k
  {
4559
126k
    combined_entry_type * ent;
4560
126k
    unsigned long symndx;
4561
126k
    coff_symbol_type *sym;
4562
4563
126k
    have_func = false;
4564
126k
    symndx = dst.l_addr.l_symndx;
4565
126k
    if (symndx >= obj_raw_syment_count (abfd))
4566
27.6k
      {
4567
27.6k
        _bfd_error_handler
4568
    /* xgettext:c-format */
4569
27.6k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4570
27.6k
     abfd, symndx, counter);
4571
27.6k
        cache_ptr->line_number = -1;
4572
27.6k
        ret = false;
4573
27.6k
        continue;
4574
27.6k
      }
4575
4576
98.6k
    ent = obj_raw_syments (abfd) + symndx;
4577
    /* FIXME: We should not be casting between ints and
4578
       pointers like this.  */
4579
98.6k
    if (! ent->is_sym)
4580
2.10k
      {
4581
2.10k
        _bfd_error_handler
4582
    /* xgettext:c-format */
4583
2.10k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4584
2.10k
     abfd, symndx, counter);
4585
2.10k
        cache_ptr->line_number = -1;
4586
2.10k
        ret = false;
4587
2.10k
        continue;
4588
2.10k
      }
4589
96.5k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4590
4591
    /* PR 17512 file: 078-10659-0.004  */
4592
96.5k
    if (sym < obj_symbols (abfd)
4593
96.5k
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4594
0
      {
4595
0
        _bfd_error_handler
4596
    /* xgettext:c-format */
4597
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4598
0
     abfd, counter);
4599
0
        cache_ptr->line_number = -1;
4600
0
        ret = false;
4601
0
        continue;
4602
0
      }
4603
4604
96.5k
    have_func = true;
4605
96.5k
    nbr_func++;
4606
96.5k
    cache_ptr->u.sym = (asymbol *) sym;
4607
96.5k
    if (sym->lineno != NULL)
4608
95.4k
      _bfd_error_handler
4609
        /* xgettext:c-format */
4610
95.4k
        (_("%pB: warning: duplicate line number information for `%s'"),
4611
95.4k
         abfd, bfd_asymbol_name (&sym->symbol));
4612
4613
96.5k
    sym->lineno = cache_ptr;
4614
96.5k
    if (sym->symbol.value < prev_offset)
4615
1.37k
      ordered = false;
4616
96.5k
    prev_offset = sym->symbol.value;
4617
96.5k
  }
4618
199k
      else if (!have_func)
4619
  /* Drop line information that has no associated function.
4620
     PR 17521: file: 078-10659-0.004.  */
4621
116k
  continue;
4622
82.9k
      else
4623
82.9k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4624
179k
      cache_ptr++;
4625
179k
    }
4626
4627
392
  asect->lineno_count = cache_ptr - lineno_cache;
4628
392
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4629
392
  free (native_lineno);
4630
4631
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4632
392
  if (!ordered)
4633
220
    {
4634
      /* Sort the table.  */
4635
220
      alent **func_table;
4636
220
      alent *n_lineno_cache;
4637
4638
      /* Create a table of functions.  */
4639
220
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4640
0
  {
4641
0
    bfd_set_error (bfd_error_file_too_big);
4642
0
    ret = false;
4643
0
  }
4644
220
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4645
220
  {
4646
220
    alent **p = func_table;
4647
220
    unsigned int i;
4648
4649
121k
    for (i = 0; i < asect->lineno_count; i++)
4650
121k
      if (lineno_cache[i].line_number == 0)
4651
52.0k
        *p++ = &lineno_cache[i];
4652
4653
220
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4654
4655
    /* Sort by functions.  */
4656
220
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4657
4658
    /* Create the new sorted table.  */
4659
220
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4660
0
      {
4661
0
        bfd_set_error (bfd_error_file_too_big);
4662
0
        ret = false;
4663
0
      }
4664
220
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4665
220
      {
4666
220
        alent *n_cache_ptr = n_lineno_cache;
4667
4668
52.2k
        for (i = 0; i < nbr_func; i++)
4669
52.0k
    {
4670
52.0k
      coff_symbol_type *sym;
4671
52.0k
      alent *old_ptr = func_table[i];
4672
4673
      /* Update the function entry.  */
4674
52.0k
      sym = (coff_symbol_type *) old_ptr->u.sym;
4675
      /* PR binutils/17512: Point the lineno to where
4676
         this entry will be after the memcpy below.  */
4677
52.0k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4678
      /* Copy the function and line number entries.  */
4679
52.0k
      do
4680
121k
        *n_cache_ptr++ = *old_ptr++;
4681
121k
      while (old_ptr->line_number != 0);
4682
52.0k
    }
4683
4684
220
        memcpy (lineno_cache, n_lineno_cache,
4685
220
          asect->lineno_count * sizeof (alent));
4686
220
      }
4687
0
    else
4688
0
      ret = false;
4689
220
    bfd_release (abfd, func_table);
4690
220
  }
4691
0
      else
4692
0
  ret = false;
4693
220
    }
4694
4695
392
  return ret;
4696
392
}
pe-aarch64.c:coff_slurp_line_table
Line
Count
Source
4499
3.39k
{
4500
3.39k
  LINENO *native_lineno;
4501
3.39k
  alent *lineno_cache;
4502
3.39k
  unsigned int counter;
4503
3.39k
  alent *cache_ptr;
4504
3.39k
  bfd_vma prev_offset = 0;
4505
3.39k
  bool ordered = true;
4506
3.39k
  unsigned int nbr_func;
4507
3.39k
  LINENO *src;
4508
3.39k
  bool have_func;
4509
3.39k
  bool ret = true;
4510
3.39k
  size_t amt;
4511
4512
3.39k
  if (asect->lineno_count == 0)
4513
2.57k
    return true;
4514
4515
819
  BFD_ASSERT (asect->lineno == NULL);
4516
4517
819
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4518
819
             asect->lineno_count,
4519
819
             bfd_coff_linesz (abfd));
4520
819
  if (native_lineno == NULL)
4521
399
    {
4522
399
      _bfd_error_handler
4523
399
  (_("%pB: warning: line number table read failed"), abfd);
4524
399
      return false;
4525
399
    }
4526
4527
420
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4528
0
    {
4529
0
      bfd_set_error (bfd_error_file_too_big);
4530
0
      free (native_lineno);
4531
0
      return false;
4532
0
    }
4533
420
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4534
420
  if (lineno_cache == NULL)
4535
0
    {
4536
0
      free (native_lineno);
4537
0
      return false;
4538
0
    }
4539
4540
420
  cache_ptr = lineno_cache;
4541
420
  asect->lineno = lineno_cache;
4542
420
  src = native_lineno;
4543
420
  nbr_func = 0;
4544
420
  have_func = false;
4545
4546
798k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4547
798k
    {
4548
798k
      struct internal_lineno dst;
4549
4550
798k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4551
798k
      cache_ptr->line_number = dst.l_lnno;
4552
      /* Appease memory checkers that get all excited about
4553
   uninitialised memory when copying alents if u.offset is
4554
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4555
798k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4556
4557
798k
      if (cache_ptr->line_number == 0)
4558
323k
  {
4559
323k
    combined_entry_type * ent;
4560
323k
    unsigned long symndx;
4561
323k
    coff_symbol_type *sym;
4562
4563
323k
    have_func = false;
4564
323k
    symndx = dst.l_addr.l_symndx;
4565
323k
    if (symndx >= obj_raw_syment_count (abfd))
4566
131k
      {
4567
131k
        _bfd_error_handler
4568
    /* xgettext:c-format */
4569
131k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4570
131k
     abfd, symndx, counter);
4571
131k
        cache_ptr->line_number = -1;
4572
131k
        ret = false;
4573
131k
        continue;
4574
131k
      }
4575
4576
192k
    ent = obj_raw_syments (abfd) + symndx;
4577
    /* FIXME: We should not be casting between ints and
4578
       pointers like this.  */
4579
192k
    if (! ent->is_sym)
4580
28.6k
      {
4581
28.6k
        _bfd_error_handler
4582
    /* xgettext:c-format */
4583
28.6k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4584
28.6k
     abfd, symndx, counter);
4585
28.6k
        cache_ptr->line_number = -1;
4586
28.6k
        ret = false;
4587
28.6k
        continue;
4588
28.6k
      }
4589
163k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4590
4591
    /* PR 17512 file: 078-10659-0.004  */
4592
163k
    if (sym < obj_symbols (abfd)
4593
163k
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4594
0
      {
4595
0
        _bfd_error_handler
4596
    /* xgettext:c-format */
4597
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4598
0
     abfd, counter);
4599
0
        cache_ptr->line_number = -1;
4600
0
        ret = false;
4601
0
        continue;
4602
0
      }
4603
4604
163k
    have_func = true;
4605
163k
    nbr_func++;
4606
163k
    cache_ptr->u.sym = (asymbol *) sym;
4607
163k
    if (sym->lineno != NULL)
4608
161k
      _bfd_error_handler
4609
        /* xgettext:c-format */
4610
161k
        (_("%pB: warning: duplicate line number information for `%s'"),
4611
161k
         abfd, bfd_asymbol_name (&sym->symbol));
4612
4613
163k
    sym->lineno = cache_ptr;
4614
163k
    if (sym->symbol.value < prev_offset)
4615
6.47k
      ordered = false;
4616
163k
    prev_offset = sym->symbol.value;
4617
163k
  }
4618
474k
      else if (!have_func)
4619
  /* Drop line information that has no associated function.
4620
     PR 17521: file: 078-10659-0.004.  */
4621
304k
  continue;
4622
170k
      else
4623
170k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4624
334k
      cache_ptr++;
4625
334k
    }
4626
4627
420
  asect->lineno_count = cache_ptr - lineno_cache;
4628
420
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4629
420
  free (native_lineno);
4630
4631
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4632
420
  if (!ordered)
4633
213
    {
4634
      /* Sort the table.  */
4635
213
      alent **func_table;
4636
213
      alent *n_lineno_cache;
4637
4638
      /* Create a table of functions.  */
4639
213
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4640
0
  {
4641
0
    bfd_set_error (bfd_error_file_too_big);
4642
0
    ret = false;
4643
0
  }
4644
213
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4645
213
  {
4646
213
    alent **p = func_table;
4647
213
    unsigned int i;
4648
4649
326k
    for (i = 0; i < asect->lineno_count; i++)
4650
326k
      if (lineno_cache[i].line_number == 0)
4651
160k
        *p++ = &lineno_cache[i];
4652
4653
213
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4654
4655
    /* Sort by functions.  */
4656
213
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4657
4658
    /* Create the new sorted table.  */
4659
213
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4660
0
      {
4661
0
        bfd_set_error (bfd_error_file_too_big);
4662
0
        ret = false;
4663
0
      }
4664
213
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4665
213
      {
4666
213
        alent *n_cache_ptr = n_lineno_cache;
4667
4668
160k
        for (i = 0; i < nbr_func; i++)
4669
160k
    {
4670
160k
      coff_symbol_type *sym;
4671
160k
      alent *old_ptr = func_table[i];
4672
4673
      /* Update the function entry.  */
4674
160k
      sym = (coff_symbol_type *) old_ptr->u.sym;
4675
      /* PR binutils/17512: Point the lineno to where
4676
         this entry will be after the memcpy below.  */
4677
160k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4678
      /* Copy the function and line number entries.  */
4679
160k
      do
4680
326k
        *n_cache_ptr++ = *old_ptr++;
4681
326k
      while (old_ptr->line_number != 0);
4682
160k
    }
4683
4684
213
        memcpy (lineno_cache, n_lineno_cache,
4685
213
          asect->lineno_count * sizeof (alent));
4686
213
      }
4687
0
    else
4688
0
      ret = false;
4689
213
    bfd_release (abfd, func_table);
4690
213
  }
4691
0
      else
4692
0
  ret = false;
4693
213
    }
4694
4695
420
  return ret;
4696
420
}
pei-aarch64.c:coff_slurp_line_table
Line
Count
Source
4499
1.90k
{
4500
1.90k
  LINENO *native_lineno;
4501
1.90k
  alent *lineno_cache;
4502
1.90k
  unsigned int counter;
4503
1.90k
  alent *cache_ptr;
4504
1.90k
  bfd_vma prev_offset = 0;
4505
1.90k
  bool ordered = true;
4506
1.90k
  unsigned int nbr_func;
4507
1.90k
  LINENO *src;
4508
1.90k
  bool have_func;
4509
1.90k
  bool ret = true;
4510
1.90k
  size_t amt;
4511
4512
1.90k
  if (asect->lineno_count == 0)
4513
1.16k
    return true;
4514
4515
740
  BFD_ASSERT (asect->lineno == NULL);
4516
4517
740
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4518
740
             asect->lineno_count,
4519
740
             bfd_coff_linesz (abfd));
4520
740
  if (native_lineno == NULL)
4521
433
    {
4522
433
      _bfd_error_handler
4523
433
  (_("%pB: warning: line number table read failed"), abfd);
4524
433
      return false;
4525
433
    }
4526
4527
307
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4528
0
    {
4529
0
      bfd_set_error (bfd_error_file_too_big);
4530
0
      free (native_lineno);
4531
0
      return false;
4532
0
    }
4533
307
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4534
307
  if (lineno_cache == NULL)
4535
0
    {
4536
0
      free (native_lineno);
4537
0
      return false;
4538
0
    }
4539
4540
307
  cache_ptr = lineno_cache;
4541
307
  asect->lineno = lineno_cache;
4542
307
  src = native_lineno;
4543
307
  nbr_func = 0;
4544
307
  have_func = false;
4545
4546
1.41M
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4547
1.41M
    {
4548
1.41M
      struct internal_lineno dst;
4549
4550
1.41M
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4551
1.41M
      cache_ptr->line_number = dst.l_lnno;
4552
      /* Appease memory checkers that get all excited about
4553
   uninitialised memory when copying alents if u.offset is
4554
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4555
1.41M
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4556
4557
1.41M
      if (cache_ptr->line_number == 0)
4558
462k
  {
4559
462k
    combined_entry_type * ent;
4560
462k
    unsigned long symndx;
4561
462k
    coff_symbol_type *sym;
4562
4563
462k
    have_func = false;
4564
462k
    symndx = dst.l_addr.l_symndx;
4565
462k
    if (symndx >= obj_raw_syment_count (abfd))
4566
203k
      {
4567
203k
        _bfd_error_handler
4568
    /* xgettext:c-format */
4569
203k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4570
203k
     abfd, symndx, counter);
4571
203k
        cache_ptr->line_number = -1;
4572
203k
        ret = false;
4573
203k
        continue;
4574
203k
      }
4575
4576
259k
    ent = obj_raw_syments (abfd) + symndx;
4577
    /* FIXME: We should not be casting between ints and
4578
       pointers like this.  */
4579
259k
    if (! ent->is_sym)
4580
48.7k
      {
4581
48.7k
        _bfd_error_handler
4582
    /* xgettext:c-format */
4583
48.7k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4584
48.7k
     abfd, symndx, counter);
4585
48.7k
        cache_ptr->line_number = -1;
4586
48.7k
        ret = false;
4587
48.7k
        continue;
4588
48.7k
      }
4589
210k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4590
4591
    /* PR 17512 file: 078-10659-0.004  */
4592
210k
    if (sym < obj_symbols (abfd)
4593
210k
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4594
0
      {
4595
0
        _bfd_error_handler
4596
    /* xgettext:c-format */
4597
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4598
0
     abfd, counter);
4599
0
        cache_ptr->line_number = -1;
4600
0
        ret = false;
4601
0
        continue;
4602
0
      }
4603
4604
210k
    have_func = true;
4605
210k
    nbr_func++;
4606
210k
    cache_ptr->u.sym = (asymbol *) sym;
4607
210k
    if (sym->lineno != NULL)
4608
207k
      _bfd_error_handler
4609
        /* xgettext:c-format */
4610
207k
        (_("%pB: warning: duplicate line number information for `%s'"),
4611
207k
         abfd, bfd_asymbol_name (&sym->symbol));
4612
4613
210k
    sym->lineno = cache_ptr;
4614
210k
    if (sym->symbol.value < prev_offset)
4615
4.09k
      ordered = false;
4616
210k
    prev_offset = sym->symbol.value;
4617
210k
  }
4618
952k
      else if (!have_func)
4619
  /* Drop line information that has no associated function.
4620
     PR 17521: file: 078-10659-0.004.  */
4621
603k
  continue;
4622
348k
      else
4623
348k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4624
559k
      cache_ptr++;
4625
559k
    }
4626
4627
307
  asect->lineno_count = cache_ptr - lineno_cache;
4628
307
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4629
307
  free (native_lineno);
4630
4631
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4632
307
  if (!ordered)
4633
218
    {
4634
      /* Sort the table.  */
4635
218
      alent **func_table;
4636
218
      alent *n_lineno_cache;
4637
4638
      /* Create a table of functions.  */
4639
218
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4640
0
  {
4641
0
    bfd_set_error (bfd_error_file_too_big);
4642
0
    ret = false;
4643
0
  }
4644
218
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4645
218
  {
4646
218
    alent **p = func_table;
4647
218
    unsigned int i;
4648
4649
543k
    for (i = 0; i < asect->lineno_count; i++)
4650
543k
      if (lineno_cache[i].line_number == 0)
4651
207k
        *p++ = &lineno_cache[i];
4652
4653
218
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4654
4655
    /* Sort by functions.  */
4656
218
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4657
4658
    /* Create the new sorted table.  */
4659
218
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4660
0
      {
4661
0
        bfd_set_error (bfd_error_file_too_big);
4662
0
        ret = false;
4663
0
      }
4664
218
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4665
218
      {
4666
218
        alent *n_cache_ptr = n_lineno_cache;
4667
4668
207k
        for (i = 0; i < nbr_func; i++)
4669
207k
    {
4670
207k
      coff_symbol_type *sym;
4671
207k
      alent *old_ptr = func_table[i];
4672
4673
      /* Update the function entry.  */
4674
207k
      sym = (coff_symbol_type *) old_ptr->u.sym;
4675
      /* PR binutils/17512: Point the lineno to where
4676
         this entry will be after the memcpy below.  */
4677
207k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4678
      /* Copy the function and line number entries.  */
4679
207k
      do
4680
543k
        *n_cache_ptr++ = *old_ptr++;
4681
543k
      while (old_ptr->line_number != 0);
4682
207k
    }
4683
4684
218
        memcpy (lineno_cache, n_lineno_cache,
4685
218
          asect->lineno_count * sizeof (alent));
4686
218
      }
4687
0
    else
4688
0
      ret = false;
4689
218
    bfd_release (abfd, func_table);
4690
218
  }
4691
0
      else
4692
0
  ret = false;
4693
218
    }
4694
4695
307
  return ret;
4696
307
}
pei-ia64.c:coff_slurp_line_table
Line
Count
Source
4499
2.12k
{
4500
2.12k
  LINENO *native_lineno;
4501
2.12k
  alent *lineno_cache;
4502
2.12k
  unsigned int counter;
4503
2.12k
  alent *cache_ptr;
4504
2.12k
  bfd_vma prev_offset = 0;
4505
2.12k
  bool ordered = true;
4506
2.12k
  unsigned int nbr_func;
4507
2.12k
  LINENO *src;
4508
2.12k
  bool have_func;
4509
2.12k
  bool ret = true;
4510
2.12k
  size_t amt;
4511
4512
2.12k
  if (asect->lineno_count == 0)
4513
1.47k
    return true;
4514
4515
651
  BFD_ASSERT (asect->lineno == NULL);
4516
4517
651
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4518
651
             asect->lineno_count,
4519
651
             bfd_coff_linesz (abfd));
4520
651
  if (native_lineno == NULL)
4521
346
    {
4522
346
      _bfd_error_handler
4523
346
  (_("%pB: warning: line number table read failed"), abfd);
4524
346
      return false;
4525
346
    }
4526
4527
305
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4528
0
    {
4529
0
      bfd_set_error (bfd_error_file_too_big);
4530
0
      free (native_lineno);
4531
0
      return false;
4532
0
    }
4533
305
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4534
305
  if (lineno_cache == NULL)
4535
0
    {
4536
0
      free (native_lineno);
4537
0
      return false;
4538
0
    }
4539
4540
305
  cache_ptr = lineno_cache;
4541
305
  asect->lineno = lineno_cache;
4542
305
  src = native_lineno;
4543
305
  nbr_func = 0;
4544
305
  have_func = false;
4545
4546
1.05M
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4547
1.05M
    {
4548
1.05M
      struct internal_lineno dst;
4549
4550
1.05M
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4551
1.05M
      cache_ptr->line_number = dst.l_lnno;
4552
      /* Appease memory checkers that get all excited about
4553
   uninitialised memory when copying alents if u.offset is
4554
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4555
1.05M
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4556
4557
1.05M
      if (cache_ptr->line_number == 0)
4558
359k
  {
4559
359k
    combined_entry_type * ent;
4560
359k
    unsigned long symndx;
4561
359k
    coff_symbol_type *sym;
4562
4563
359k
    have_func = false;
4564
359k
    symndx = dst.l_addr.l_symndx;
4565
359k
    if (symndx >= obj_raw_syment_count (abfd))
4566
167k
      {
4567
167k
        _bfd_error_handler
4568
    /* xgettext:c-format */
4569
167k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4570
167k
     abfd, symndx, counter);
4571
167k
        cache_ptr->line_number = -1;
4572
167k
        ret = false;
4573
167k
        continue;
4574
167k
      }
4575
4576
192k
    ent = obj_raw_syments (abfd) + symndx;
4577
    /* FIXME: We should not be casting between ints and
4578
       pointers like this.  */
4579
192k
    if (! ent->is_sym)
4580
38.3k
      {
4581
38.3k
        _bfd_error_handler
4582
    /* xgettext:c-format */
4583
38.3k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4584
38.3k
     abfd, symndx, counter);
4585
38.3k
        cache_ptr->line_number = -1;
4586
38.3k
        ret = false;
4587
38.3k
        continue;
4588
38.3k
      }
4589
154k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4590
4591
    /* PR 17512 file: 078-10659-0.004  */
4592
154k
    if (sym < obj_symbols (abfd)
4593
154k
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4594
0
      {
4595
0
        _bfd_error_handler
4596
    /* xgettext:c-format */
4597
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4598
0
     abfd, counter);
4599
0
        cache_ptr->line_number = -1;
4600
0
        ret = false;
4601
0
        continue;
4602
0
      }
4603
4604
154k
    have_func = true;
4605
154k
    nbr_func++;
4606
154k
    cache_ptr->u.sym = (asymbol *) sym;
4607
154k
    if (sym->lineno != NULL)
4608
151k
      _bfd_error_handler
4609
        /* xgettext:c-format */
4610
151k
        (_("%pB: warning: duplicate line number information for `%s'"),
4611
151k
         abfd, bfd_asymbol_name (&sym->symbol));
4612
4613
154k
    sym->lineno = cache_ptr;
4614
154k
    if (sym->symbol.value < prev_offset)
4615
3.22k
      ordered = false;
4616
154k
    prev_offset = sym->symbol.value;
4617
154k
  }
4618
696k
      else if (!have_func)
4619
  /* Drop line information that has no associated function.
4620
     PR 17521: file: 078-10659-0.004.  */
4621
523k
  continue;
4622
173k
      else
4623
173k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4624
327k
      cache_ptr++;
4625
327k
    }
4626
4627
305
  asect->lineno_count = cache_ptr - lineno_cache;
4628
305
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4629
305
  free (native_lineno);
4630
4631
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4632
305
  if (!ordered)
4633
172
    {
4634
      /* Sort the table.  */
4635
172
      alent **func_table;
4636
172
      alent *n_lineno_cache;
4637
4638
      /* Create a table of functions.  */
4639
172
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4640
0
  {
4641
0
    bfd_set_error (bfd_error_file_too_big);
4642
0
    ret = false;
4643
0
  }
4644
172
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4645
172
  {
4646
172
    alent **p = func_table;
4647
172
    unsigned int i;
4648
4649
320k
    for (i = 0; i < asect->lineno_count; i++)
4650
320k
      if (lineno_cache[i].line_number == 0)
4651
152k
        *p++ = &lineno_cache[i];
4652
4653
172
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4654
4655
    /* Sort by functions.  */
4656
172
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4657
4658
    /* Create the new sorted table.  */
4659
172
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4660
0
      {
4661
0
        bfd_set_error (bfd_error_file_too_big);
4662
0
        ret = false;
4663
0
      }
4664
172
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4665
172
      {
4666
172
        alent *n_cache_ptr = n_lineno_cache;
4667
4668
152k
        for (i = 0; i < nbr_func; i++)
4669
152k
    {
4670
152k
      coff_symbol_type *sym;
4671
152k
      alent *old_ptr = func_table[i];
4672
4673
      /* Update the function entry.  */
4674
152k
      sym = (coff_symbol_type *) old_ptr->u.sym;
4675
      /* PR binutils/17512: Point the lineno to where
4676
         this entry will be after the memcpy below.  */
4677
152k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4678
      /* Copy the function and line number entries.  */
4679
152k
      do
4680
320k
        *n_cache_ptr++ = *old_ptr++;
4681
320k
      while (old_ptr->line_number != 0);
4682
152k
    }
4683
4684
172
        memcpy (lineno_cache, n_lineno_cache,
4685
172
          asect->lineno_count * sizeof (alent));
4686
172
      }
4687
0
    else
4688
0
      ret = false;
4689
172
    bfd_release (abfd, func_table);
4690
172
  }
4691
0
      else
4692
0
  ret = false;
4693
172
    }
4694
4695
305
  return ret;
4696
305
}
pei-loongarch64.c:coff_slurp_line_table
Line
Count
Source
4499
1.77k
{
4500
1.77k
  LINENO *native_lineno;
4501
1.77k
  alent *lineno_cache;
4502
1.77k
  unsigned int counter;
4503
1.77k
  alent *cache_ptr;
4504
1.77k
  bfd_vma prev_offset = 0;
4505
1.77k
  bool ordered = true;
4506
1.77k
  unsigned int nbr_func;
4507
1.77k
  LINENO *src;
4508
1.77k
  bool have_func;
4509
1.77k
  bool ret = true;
4510
1.77k
  size_t amt;
4511
4512
1.77k
  if (asect->lineno_count == 0)
4513
1.00k
    return true;
4514
4515
772
  BFD_ASSERT (asect->lineno == NULL);
4516
4517
772
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4518
772
             asect->lineno_count,
4519
772
             bfd_coff_linesz (abfd));
4520
772
  if (native_lineno == NULL)
4521
411
    {
4522
411
      _bfd_error_handler
4523
411
  (_("%pB: warning: line number table read failed"), abfd);
4524
411
      return false;
4525
411
    }
4526
4527
361
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4528
0
    {
4529
0
      bfd_set_error (bfd_error_file_too_big);
4530
0
      free (native_lineno);
4531
0
      return false;
4532
0
    }
4533
361
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4534
361
  if (lineno_cache == NULL)
4535
0
    {
4536
0
      free (native_lineno);
4537
0
      return false;
4538
0
    }
4539
4540
361
  cache_ptr = lineno_cache;
4541
361
  asect->lineno = lineno_cache;
4542
361
  src = native_lineno;
4543
361
  nbr_func = 0;
4544
361
  have_func = false;
4545
4546
1.61M
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4547
1.61M
    {
4548
1.61M
      struct internal_lineno dst;
4549
4550
1.61M
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4551
1.61M
      cache_ptr->line_number = dst.l_lnno;
4552
      /* Appease memory checkers that get all excited about
4553
   uninitialised memory when copying alents if u.offset is
4554
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4555
1.61M
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4556
4557
1.61M
      if (cache_ptr->line_number == 0)
4558
704k
  {
4559
704k
    combined_entry_type * ent;
4560
704k
    unsigned long symndx;
4561
704k
    coff_symbol_type *sym;
4562
4563
704k
    have_func = false;
4564
704k
    symndx = dst.l_addr.l_symndx;
4565
704k
    if (symndx >= obj_raw_syment_count (abfd))
4566
318k
      {
4567
318k
        _bfd_error_handler
4568
    /* xgettext:c-format */
4569
318k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4570
318k
     abfd, symndx, counter);
4571
318k
        cache_ptr->line_number = -1;
4572
318k
        ret = false;
4573
318k
        continue;
4574
318k
      }
4575
4576
386k
    ent = obj_raw_syments (abfd) + symndx;
4577
    /* FIXME: We should not be casting between ints and
4578
       pointers like this.  */
4579
386k
    if (! ent->is_sym)
4580
69.3k
      {
4581
69.3k
        _bfd_error_handler
4582
    /* xgettext:c-format */
4583
69.3k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4584
69.3k
     abfd, symndx, counter);
4585
69.3k
        cache_ptr->line_number = -1;
4586
69.3k
        ret = false;
4587
69.3k
        continue;
4588
69.3k
      }
4589
316k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4590
4591
    /* PR 17512 file: 078-10659-0.004  */
4592
316k
    if (sym < obj_symbols (abfd)
4593
316k
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4594
0
      {
4595
0
        _bfd_error_handler
4596
    /* xgettext:c-format */
4597
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4598
0
     abfd, counter);
4599
0
        cache_ptr->line_number = -1;
4600
0
        ret = false;
4601
0
        continue;
4602
0
      }
4603
4604
316k
    have_func = true;
4605
316k
    nbr_func++;
4606
316k
    cache_ptr->u.sym = (asymbol *) sym;
4607
316k
    if (sym->lineno != NULL)
4608
312k
      _bfd_error_handler
4609
        /* xgettext:c-format */
4610
312k
        (_("%pB: warning: duplicate line number information for `%s'"),
4611
312k
         abfd, bfd_asymbol_name (&sym->symbol));
4612
4613
316k
    sym->lineno = cache_ptr;
4614
316k
    if (sym->symbol.value < prev_offset)
4615
9.75k
      ordered = false;
4616
316k
    prev_offset = sym->symbol.value;
4617
316k
  }
4618
910k
      else if (!have_func)
4619
  /* Drop line information that has no associated function.
4620
     PR 17521: file: 078-10659-0.004.  */
4621
585k
  continue;
4622
325k
      else
4623
325k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4624
642k
      cache_ptr++;
4625
642k
    }
4626
4627
361
  asect->lineno_count = cache_ptr - lineno_cache;
4628
361
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4629
361
  free (native_lineno);
4630
4631
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4632
361
  if (!ordered)
4633
255
    {
4634
      /* Sort the table.  */
4635
255
      alent **func_table;
4636
255
      alent *n_lineno_cache;
4637
4638
      /* Create a table of functions.  */
4639
255
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4640
0
  {
4641
0
    bfd_set_error (bfd_error_file_too_big);
4642
0
    ret = false;
4643
0
  }
4644
255
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4645
255
  {
4646
255
    alent **p = func_table;
4647
255
    unsigned int i;
4648
4649
639k
    for (i = 0; i < asect->lineno_count; i++)
4650
639k
      if (lineno_cache[i].line_number == 0)
4651
315k
        *p++ = &lineno_cache[i];
4652
4653
255
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4654
4655
    /* Sort by functions.  */
4656
255
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4657
4658
    /* Create the new sorted table.  */
4659
255
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4660
0
      {
4661
0
        bfd_set_error (bfd_error_file_too_big);
4662
0
        ret = false;
4663
0
      }
4664
255
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4665
255
      {
4666
255
        alent *n_cache_ptr = n_lineno_cache;
4667
4668
315k
        for (i = 0; i < nbr_func; i++)
4669
315k
    {
4670
315k
      coff_symbol_type *sym;
4671
315k
      alent *old_ptr = func_table[i];
4672
4673
      /* Update the function entry.  */
4674
315k
      sym = (coff_symbol_type *) old_ptr->u.sym;
4675
      /* PR binutils/17512: Point the lineno to where
4676
         this entry will be after the memcpy below.  */
4677
315k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4678
      /* Copy the function and line number entries.  */
4679
315k
      do
4680
639k
        *n_cache_ptr++ = *old_ptr++;
4681
639k
      while (old_ptr->line_number != 0);
4682
315k
    }
4683
4684
255
        memcpy (lineno_cache, n_lineno_cache,
4685
255
          asect->lineno_count * sizeof (alent));
4686
255
      }
4687
0
    else
4688
0
      ret = false;
4689
255
    bfd_release (abfd, func_table);
4690
255
  }
4691
0
      else
4692
0
  ret = false;
4693
255
    }
4694
4695
361
  return ret;
4696
361
}
pei-riscv64.c:coff_slurp_line_table
Line
Count
Source
4499
1.71k
{
4500
1.71k
  LINENO *native_lineno;
4501
1.71k
  alent *lineno_cache;
4502
1.71k
  unsigned int counter;
4503
1.71k
  alent *cache_ptr;
4504
1.71k
  bfd_vma prev_offset = 0;
4505
1.71k
  bool ordered = true;
4506
1.71k
  unsigned int nbr_func;
4507
1.71k
  LINENO *src;
4508
1.71k
  bool have_func;
4509
1.71k
  bool ret = true;
4510
1.71k
  size_t amt;
4511
4512
1.71k
  if (asect->lineno_count == 0)
4513
853
    return true;
4514
4515
865
  BFD_ASSERT (asect->lineno == NULL);
4516
4517
865
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4518
865
             asect->lineno_count,
4519
865
             bfd_coff_linesz (abfd));
4520
865
  if (native_lineno == NULL)
4521
485
    {
4522
485
      _bfd_error_handler
4523
485
  (_("%pB: warning: line number table read failed"), abfd);
4524
485
      return false;
4525
485
    }
4526
4527
380
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4528
0
    {
4529
0
      bfd_set_error (bfd_error_file_too_big);
4530
0
      free (native_lineno);
4531
0
      return false;
4532
0
    }
4533
380
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4534
380
  if (lineno_cache == NULL)
4535
0
    {
4536
0
      free (native_lineno);
4537
0
      return false;
4538
0
    }
4539
4540
380
  cache_ptr = lineno_cache;
4541
380
  asect->lineno = lineno_cache;
4542
380
  src = native_lineno;
4543
380
  nbr_func = 0;
4544
380
  have_func = false;
4545
4546
383k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4547
382k
    {
4548
382k
      struct internal_lineno dst;
4549
4550
382k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4551
382k
      cache_ptr->line_number = dst.l_lnno;
4552
      /* Appease memory checkers that get all excited about
4553
   uninitialised memory when copying alents if u.offset is
4554
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4555
382k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4556
4557
382k
      if (cache_ptr->line_number == 0)
4558
189k
  {
4559
189k
    combined_entry_type * ent;
4560
189k
    unsigned long symndx;
4561
189k
    coff_symbol_type *sym;
4562
4563
189k
    have_func = false;
4564
189k
    symndx = dst.l_addr.l_symndx;
4565
189k
    if (symndx >= obj_raw_syment_count (abfd))
4566
82.3k
      {
4567
82.3k
        _bfd_error_handler
4568
    /* xgettext:c-format */
4569
82.3k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4570
82.3k
     abfd, symndx, counter);
4571
82.3k
        cache_ptr->line_number = -1;
4572
82.3k
        ret = false;
4573
82.3k
        continue;
4574
82.3k
      }
4575
4576
106k
    ent = obj_raw_syments (abfd) + symndx;
4577
    /* FIXME: We should not be casting between ints and
4578
       pointers like this.  */
4579
106k
    if (! ent->is_sym)
4580
9.32k
      {
4581
9.32k
        _bfd_error_handler
4582
    /* xgettext:c-format */
4583
9.32k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4584
9.32k
     abfd, symndx, counter);
4585
9.32k
        cache_ptr->line_number = -1;
4586
9.32k
        ret = false;
4587
9.32k
        continue;
4588
9.32k
      }
4589
97.5k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4590
4591
    /* PR 17512 file: 078-10659-0.004  */
4592
97.5k
    if (sym < obj_symbols (abfd)
4593
97.5k
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4594
0
      {
4595
0
        _bfd_error_handler
4596
    /* xgettext:c-format */
4597
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4598
0
     abfd, counter);
4599
0
        cache_ptr->line_number = -1;
4600
0
        ret = false;
4601
0
        continue;
4602
0
      }
4603
4604
97.5k
    have_func = true;
4605
97.5k
    nbr_func++;
4606
97.5k
    cache_ptr->u.sym = (asymbol *) sym;
4607
97.5k
    if (sym->lineno != NULL)
4608
96.1k
      _bfd_error_handler
4609
        /* xgettext:c-format */
4610
96.1k
        (_("%pB: warning: duplicate line number information for `%s'"),
4611
96.1k
         abfd, bfd_asymbol_name (&sym->symbol));
4612
4613
97.5k
    sym->lineno = cache_ptr;
4614
97.5k
    if (sym->symbol.value < prev_offset)
4615
2.63k
      ordered = false;
4616
97.5k
    prev_offset = sym->symbol.value;
4617
97.5k
  }
4618
193k
      else if (!have_func)
4619
  /* Drop line information that has no associated function.
4620
     PR 17521: file: 078-10659-0.004.  */
4621
124k
  continue;
4622
69.0k
      else
4623
69.0k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4624
166k
      cache_ptr++;
4625
166k
    }
4626
4627
380
  asect->lineno_count = cache_ptr - lineno_cache;
4628
380
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4629
380
  free (native_lineno);
4630
4631
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4632
380
  if (!ordered)
4633
219
    {
4634
      /* Sort the table.  */
4635
219
      alent **func_table;
4636
219
      alent *n_lineno_cache;
4637
4638
      /* Create a table of functions.  */
4639
219
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4640
0
  {
4641
0
    bfd_set_error (bfd_error_file_too_big);
4642
0
    ret = false;
4643
0
  }
4644
219
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4645
219
  {
4646
219
    alent **p = func_table;
4647
219
    unsigned int i;
4648
4649
141k
    for (i = 0; i < asect->lineno_count; i++)
4650
141k
      if (lineno_cache[i].line_number == 0)
4651
76.3k
        *p++ = &lineno_cache[i];
4652
4653
219
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4654
4655
    /* Sort by functions.  */
4656
219
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4657
4658
    /* Create the new sorted table.  */
4659
219
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4660
0
      {
4661
0
        bfd_set_error (bfd_error_file_too_big);
4662
0
        ret = false;
4663
0
      }
4664
219
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4665
219
      {
4666
219
        alent *n_cache_ptr = n_lineno_cache;
4667
4668
76.5k
        for (i = 0; i < nbr_func; i++)
4669
76.3k
    {
4670
76.3k
      coff_symbol_type *sym;
4671
76.3k
      alent *old_ptr = func_table[i];
4672
4673
      /* Update the function entry.  */
4674
76.3k
      sym = (coff_symbol_type *) old_ptr->u.sym;
4675
      /* PR binutils/17512: Point the lineno to where
4676
         this entry will be after the memcpy below.  */
4677
76.3k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4678
      /* Copy the function and line number entries.  */
4679
76.3k
      do
4680
141k
        *n_cache_ptr++ = *old_ptr++;
4681
141k
      while (old_ptr->line_number != 0);
4682
76.3k
    }
4683
4684
219
        memcpy (lineno_cache, n_lineno_cache,
4685
219
          asect->lineno_count * sizeof (alent));
4686
219
      }
4687
0
    else
4688
0
      ret = false;
4689
219
    bfd_release (abfd, func_table);
4690
219
  }
4691
0
      else
4692
0
  ret = false;
4693
219
    }
4694
4695
380
  return ret;
4696
380
}
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
4499
5.24k
{
4500
5.24k
  LINENO *native_lineno;
4501
5.24k
  alent *lineno_cache;
4502
5.24k
  unsigned int counter;
4503
5.24k
  alent *cache_ptr;
4504
5.24k
  bfd_vma prev_offset = 0;
4505
5.24k
  bool ordered = true;
4506
5.24k
  unsigned int nbr_func;
4507
5.24k
  LINENO *src;
4508
5.24k
  bool have_func;
4509
5.24k
  bool ret = true;
4510
5.24k
  size_t amt;
4511
4512
5.24k
  if (asect->lineno_count == 0)
4513
4.15k
    return true;
4514
4515
1.09k
  BFD_ASSERT (asect->lineno == NULL);
4516
4517
1.09k
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4518
1.09k
             asect->lineno_count,
4519
1.09k
             bfd_coff_linesz (abfd));
4520
1.09k
  if (native_lineno == NULL)
4521
676
    {
4522
676
      _bfd_error_handler
4523
676
  (_("%pB: warning: line number table read failed"), abfd);
4524
676
      return false;
4525
676
    }
4526
4527
422
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4528
0
    {
4529
0
      bfd_set_error (bfd_error_file_too_big);
4530
0
      free (native_lineno);
4531
0
      return false;
4532
0
    }
4533
422
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4534
422
  if (lineno_cache == NULL)
4535
0
    {
4536
0
      free (native_lineno);
4537
0
      return false;
4538
0
    }
4539
4540
422
  cache_ptr = lineno_cache;
4541
422
  asect->lineno = lineno_cache;
4542
422
  src = native_lineno;
4543
422
  nbr_func = 0;
4544
422
  have_func = false;
4545
4546
547k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4547
547k
    {
4548
547k
      struct internal_lineno dst;
4549
4550
547k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4551
547k
      cache_ptr->line_number = dst.l_lnno;
4552
      /* Appease memory checkers that get all excited about
4553
   uninitialised memory when copying alents if u.offset is
4554
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4555
547k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4556
4557
547k
      if (cache_ptr->line_number == 0)
4558
233k
  {
4559
233k
    combined_entry_type * ent;
4560
233k
    unsigned long symndx;
4561
233k
    coff_symbol_type *sym;
4562
4563
233k
    have_func = false;
4564
233k
    symndx = dst.l_addr.l_symndx;
4565
233k
    if (symndx >= obj_raw_syment_count (abfd))
4566
101k
      {
4567
101k
        _bfd_error_handler
4568
    /* xgettext:c-format */
4569
101k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4570
101k
     abfd, symndx, counter);
4571
101k
        cache_ptr->line_number = -1;
4572
101k
        ret = false;
4573
101k
        continue;
4574
101k
      }
4575
4576
132k
    ent = obj_raw_syments (abfd) + symndx;
4577
    /* FIXME: We should not be casting between ints and
4578
       pointers like this.  */
4579
132k
    if (! ent->is_sym)
4580
22.9k
      {
4581
22.9k
        _bfd_error_handler
4582
    /* xgettext:c-format */
4583
22.9k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4584
22.9k
     abfd, symndx, counter);
4585
22.9k
        cache_ptr->line_number = -1;
4586
22.9k
        ret = false;
4587
22.9k
        continue;
4588
22.9k
      }
4589
109k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4590
4591
    /* PR 17512 file: 078-10659-0.004  */
4592
109k
    if (sym < obj_symbols (abfd)
4593
109k
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4594
0
      {
4595
0
        _bfd_error_handler
4596
    /* xgettext:c-format */
4597
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4598
0
     abfd, counter);
4599
0
        cache_ptr->line_number = -1;
4600
0
        ret = false;
4601
0
        continue;
4602
0
      }
4603
4604
109k
    have_func = true;
4605
109k
    nbr_func++;
4606
109k
    cache_ptr->u.sym = (asymbol *) sym;
4607
109k
    if (sym->lineno != NULL)
4608
108k
      _bfd_error_handler
4609
        /* xgettext:c-format */
4610
108k
        (_("%pB: warning: duplicate line number information for `%s'"),
4611
108k
         abfd, bfd_asymbol_name (&sym->symbol));
4612
4613
109k
    sym->lineno = cache_ptr;
4614
109k
    if (sym->symbol.value < prev_offset)
4615
4.28k
      ordered = false;
4616
109k
    prev_offset = sym->symbol.value;
4617
109k
  }
4618
313k
      else if (!have_func)
4619
  /* Drop line information that has no associated function.
4620
     PR 17521: file: 078-10659-0.004.  */
4621
179k
  continue;
4622
133k
      else
4623
133k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4624
243k
      cache_ptr++;
4625
243k
    }
4626
4627
422
  asect->lineno_count = cache_ptr - lineno_cache;
4628
422
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4629
422
  free (native_lineno);
4630
4631
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4632
422
  if (!ordered)
4633
202
    {
4634
      /* Sort the table.  */
4635
202
      alent **func_table;
4636
202
      alent *n_lineno_cache;
4637
4638
      /* Create a table of functions.  */
4639
202
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4640
0
  {
4641
0
    bfd_set_error (bfd_error_file_too_big);
4642
0
    ret = false;
4643
0
  }
4644
202
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4645
202
  {
4646
202
    alent **p = func_table;
4647
202
    unsigned int i;
4648
4649
210k
    for (i = 0; i < asect->lineno_count; i++)
4650
210k
      if (lineno_cache[i].line_number == 0)
4651
85.8k
        *p++ = &lineno_cache[i];
4652
4653
202
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4654
4655
    /* Sort by functions.  */
4656
202
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4657
4658
    /* Create the new sorted table.  */
4659
202
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4660
0
      {
4661
0
        bfd_set_error (bfd_error_file_too_big);
4662
0
        ret = false;
4663
0
      }
4664
202
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4665
202
      {
4666
202
        alent *n_cache_ptr = n_lineno_cache;
4667
4668
86.0k
        for (i = 0; i < nbr_func; i++)
4669
85.8k
    {
4670
85.8k
      coff_symbol_type *sym;
4671
85.8k
      alent *old_ptr = func_table[i];
4672
4673
      /* Update the function entry.  */
4674
85.8k
      sym = (coff_symbol_type *) old_ptr->u.sym;
4675
      /* PR binutils/17512: Point the lineno to where
4676
         this entry will be after the memcpy below.  */
4677
85.8k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4678
      /* Copy the function and line number entries.  */
4679
85.8k
      do
4680
210k
        *n_cache_ptr++ = *old_ptr++;
4681
210k
      while (old_ptr->line_number != 0);
4682
85.8k
    }
4683
4684
202
        memcpy (lineno_cache, n_lineno_cache,
4685
202
          asect->lineno_count * sizeof (alent));
4686
202
      }
4687
0
    else
4688
0
      ret = false;
4689
202
    bfd_release (abfd, func_table);
4690
202
  }
4691
0
      else
4692
0
  ret = false;
4693
202
    }
4694
4695
422
  return ret;
4696
422
}
coff-sh.c:coff_slurp_line_table
Line
Count
Source
4499
5.65k
{
4500
5.65k
  LINENO *native_lineno;
4501
5.65k
  alent *lineno_cache;
4502
5.65k
  unsigned int counter;
4503
5.65k
  alent *cache_ptr;
4504
5.65k
  bfd_vma prev_offset = 0;
4505
5.65k
  bool ordered = true;
4506
5.65k
  unsigned int nbr_func;
4507
5.65k
  LINENO *src;
4508
5.65k
  bool have_func;
4509
5.65k
  bool ret = true;
4510
5.65k
  size_t amt;
4511
4512
5.65k
  if (asect->lineno_count == 0)
4513
4.73k
    return true;
4514
4515
919
  BFD_ASSERT (asect->lineno == NULL);
4516
4517
919
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4518
919
             asect->lineno_count,
4519
919
             bfd_coff_linesz (abfd));
4520
919
  if (native_lineno == NULL)
4521
496
    {
4522
496
      _bfd_error_handler
4523
496
  (_("%pB: warning: line number table read failed"), abfd);
4524
496
      return false;
4525
496
    }
4526
4527
423
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4528
0
    {
4529
0
      bfd_set_error (bfd_error_file_too_big);
4530
0
      free (native_lineno);
4531
0
      return false;
4532
0
    }
4533
423
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4534
423
  if (lineno_cache == NULL)
4535
0
    {
4536
0
      free (native_lineno);
4537
0
      return false;
4538
0
    }
4539
4540
423
  cache_ptr = lineno_cache;
4541
423
  asect->lineno = lineno_cache;
4542
423
  src = native_lineno;
4543
423
  nbr_func = 0;
4544
423
  have_func = false;
4545
4546
1.66M
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4547
1.66M
    {
4548
1.66M
      struct internal_lineno dst;
4549
4550
1.66M
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4551
1.66M
      cache_ptr->line_number = dst.l_lnno;
4552
      /* Appease memory checkers that get all excited about
4553
   uninitialised memory when copying alents if u.offset is
4554
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4555
1.66M
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4556
4557
1.66M
      if (cache_ptr->line_number == 0)
4558
414k
  {
4559
414k
    combined_entry_type * ent;
4560
414k
    unsigned long symndx;
4561
414k
    coff_symbol_type *sym;
4562
4563
414k
    have_func = false;
4564
414k
    symndx = dst.l_addr.l_symndx;
4565
414k
    if (symndx >= obj_raw_syment_count (abfd))
4566
157k
      {
4567
157k
        _bfd_error_handler
4568
    /* xgettext:c-format */
4569
157k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4570
157k
     abfd, symndx, counter);
4571
157k
        cache_ptr->line_number = -1;
4572
157k
        ret = false;
4573
157k
        continue;
4574
157k
      }
4575
4576
256k
    ent = obj_raw_syments (abfd) + symndx;
4577
    /* FIXME: We should not be casting between ints and
4578
       pointers like this.  */
4579
256k
    if (! ent->is_sym)
4580
57.5k
      {
4581
57.5k
        _bfd_error_handler
4582
    /* xgettext:c-format */
4583
57.5k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4584
57.5k
     abfd, symndx, counter);
4585
57.5k
        cache_ptr->line_number = -1;
4586
57.5k
        ret = false;
4587
57.5k
        continue;
4588
57.5k
      }
4589
198k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4590
4591
    /* PR 17512 file: 078-10659-0.004  */
4592
198k
    if (sym < obj_symbols (abfd)
4593
198k
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4594
0
      {
4595
0
        _bfd_error_handler
4596
    /* xgettext:c-format */
4597
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4598
0
     abfd, counter);
4599
0
        cache_ptr->line_number = -1;
4600
0
        ret = false;
4601
0
        continue;
4602
0
      }
4603
4604
198k
    have_func = true;
4605
198k
    nbr_func++;
4606
198k
    cache_ptr->u.sym = (asymbol *) sym;
4607
198k
    if (sym->lineno != NULL)
4608
193k
      _bfd_error_handler
4609
        /* xgettext:c-format */
4610
193k
        (_("%pB: warning: duplicate line number information for `%s'"),
4611
193k
         abfd, bfd_asymbol_name (&sym->symbol));
4612
4613
198k
    sym->lineno = cache_ptr;
4614
198k
    if (sym->symbol.value < prev_offset)
4615
7.45k
      ordered = false;
4616
198k
    prev_offset = sym->symbol.value;
4617
198k
  }
4618
1.25M
      else if (!have_func)
4619
  /* Drop line information that has no associated function.
4620
     PR 17521: file: 078-10659-0.004.  */
4621
779k
  continue;
4622
474k
      else
4623
474k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4624
673k
      cache_ptr++;
4625
673k
    }
4626
4627
423
  asect->lineno_count = cache_ptr - lineno_cache;
4628
423
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4629
423
  free (native_lineno);
4630
4631
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4632
423
  if (!ordered)
4633
220
    {
4634
      /* Sort the table.  */
4635
220
      alent **func_table;
4636
220
      alent *n_lineno_cache;
4637
4638
      /* Create a table of functions.  */
4639
220
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4640
0
  {
4641
0
    bfd_set_error (bfd_error_file_too_big);
4642
0
    ret = false;
4643
0
  }
4644
220
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4645
220
  {
4646
220
    alent **p = func_table;
4647
220
    unsigned int i;
4648
4649
666k
    for (i = 0; i < asect->lineno_count; i++)
4650
666k
      if (lineno_cache[i].line_number == 0)
4651
196k
        *p++ = &lineno_cache[i];
4652
4653
220
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4654
4655
    /* Sort by functions.  */
4656
220
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4657
4658
    /* Create the new sorted table.  */
4659
220
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4660
0
      {
4661
0
        bfd_set_error (bfd_error_file_too_big);
4662
0
        ret = false;
4663
0
      }
4664
220
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4665
220
      {
4666
220
        alent *n_cache_ptr = n_lineno_cache;
4667
4668
196k
        for (i = 0; i < nbr_func; i++)
4669
196k
    {
4670
196k
      coff_symbol_type *sym;
4671
196k
      alent *old_ptr = func_table[i];
4672
4673
      /* Update the function entry.  */
4674
196k
      sym = (coff_symbol_type *) old_ptr->u.sym;
4675
      /* PR binutils/17512: Point the lineno to where
4676
         this entry will be after the memcpy below.  */
4677
196k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4678
      /* Copy the function and line number entries.  */
4679
196k
      do
4680
666k
        *n_cache_ptr++ = *old_ptr++;
4681
666k
      while (old_ptr->line_number != 0);
4682
196k
    }
4683
4684
220
        memcpy (lineno_cache, n_lineno_cache,
4685
220
          asect->lineno_count * sizeof (alent));
4686
220
      }
4687
0
    else
4688
0
      ret = false;
4689
220
    bfd_release (abfd, func_table);
4690
220
  }
4691
0
      else
4692
0
  ret = false;
4693
220
    }
4694
4695
423
  return ret;
4696
423
}
Unexecuted instantiation: coff-stgo32.c:coff_slurp_line_table
coff-tic30.c:coff_slurp_line_table
Line
Count
Source
4499
4.90k
{
4500
4.90k
  LINENO *native_lineno;
4501
4.90k
  alent *lineno_cache;
4502
4.90k
  unsigned int counter;
4503
4.90k
  alent *cache_ptr;
4504
4.90k
  bfd_vma prev_offset = 0;
4505
4.90k
  bool ordered = true;
4506
4.90k
  unsigned int nbr_func;
4507
4.90k
  LINENO *src;
4508
4.90k
  bool have_func;
4509
4.90k
  bool ret = true;
4510
4.90k
  size_t amt;
4511
4512
4.90k
  if (asect->lineno_count == 0)
4513
3.61k
    return true;
4514
4515
1.28k
  BFD_ASSERT (asect->lineno == NULL);
4516
4517
1.28k
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4518
1.28k
             asect->lineno_count,
4519
1.28k
             bfd_coff_linesz (abfd));
4520
1.28k
  if (native_lineno == NULL)
4521
630
    {
4522
630
      _bfd_error_handler
4523
630
  (_("%pB: warning: line number table read failed"), abfd);
4524
630
      return false;
4525
630
    }
4526
4527
658
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4528
0
    {
4529
0
      bfd_set_error (bfd_error_file_too_big);
4530
0
      free (native_lineno);
4531
0
      return false;
4532
0
    }
4533
658
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4534
658
  if (lineno_cache == NULL)
4535
0
    {
4536
0
      free (native_lineno);
4537
0
      return false;
4538
0
    }
4539
4540
658
  cache_ptr = lineno_cache;
4541
658
  asect->lineno = lineno_cache;
4542
658
  src = native_lineno;
4543
658
  nbr_func = 0;
4544
658
  have_func = false;
4545
4546
571k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4547
571k
    {
4548
571k
      struct internal_lineno dst;
4549
4550
571k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4551
571k
      cache_ptr->line_number = dst.l_lnno;
4552
      /* Appease memory checkers that get all excited about
4553
   uninitialised memory when copying alents if u.offset is
4554
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4555
571k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4556
4557
571k
      if (cache_ptr->line_number == 0)
4558
145k
  {
4559
145k
    combined_entry_type * ent;
4560
145k
    unsigned long symndx;
4561
145k
    coff_symbol_type *sym;
4562
4563
145k
    have_func = false;
4564
145k
    symndx = dst.l_addr.l_symndx;
4565
145k
    if (symndx >= obj_raw_syment_count (abfd))
4566
51.6k
      {
4567
51.6k
        _bfd_error_handler
4568
    /* xgettext:c-format */
4569
51.6k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4570
51.6k
     abfd, symndx, counter);
4571
51.6k
        cache_ptr->line_number = -1;
4572
51.6k
        ret = false;
4573
51.6k
        continue;
4574
51.6k
      }
4575
4576
94.1k
    ent = obj_raw_syments (abfd) + symndx;
4577
    /* FIXME: We should not be casting between ints and
4578
       pointers like this.  */
4579
94.1k
    if (! ent->is_sym)
4580
14.9k
      {
4581
14.9k
        _bfd_error_handler
4582
    /* xgettext:c-format */
4583
14.9k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4584
14.9k
     abfd, symndx, counter);
4585
14.9k
        cache_ptr->line_number = -1;
4586
14.9k
        ret = false;
4587
14.9k
        continue;
4588
14.9k
      }
4589
79.2k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4590
4591
    /* PR 17512 file: 078-10659-0.004  */
4592
79.2k
    if (sym < obj_symbols (abfd)
4593
79.2k
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4594
0
      {
4595
0
        _bfd_error_handler
4596
    /* xgettext:c-format */
4597
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4598
0
     abfd, counter);
4599
0
        cache_ptr->line_number = -1;
4600
0
        ret = false;
4601
0
        continue;
4602
0
      }
4603
4604
79.2k
    have_func = true;
4605
79.2k
    nbr_func++;
4606
79.2k
    cache_ptr->u.sym = (asymbol *) sym;
4607
79.2k
    if (sym->lineno != NULL)
4608
76.5k
      _bfd_error_handler
4609
        /* xgettext:c-format */
4610
76.5k
        (_("%pB: warning: duplicate line number information for `%s'"),
4611
76.5k
         abfd, bfd_asymbol_name (&sym->symbol));
4612
4613
79.2k
    sym->lineno = cache_ptr;
4614
79.2k
    if (sym->symbol.value < prev_offset)
4615
2.67k
      ordered = false;
4616
79.2k
    prev_offset = sym->symbol.value;
4617
79.2k
  }
4618
425k
      else if (!have_func)
4619
  /* Drop line information that has no associated function.
4620
     PR 17521: file: 078-10659-0.004.  */
4621
270k
  continue;
4622
154k
      else
4623
154k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4624
234k
      cache_ptr++;
4625
234k
    }
4626
4627
658
  asect->lineno_count = cache_ptr - lineno_cache;
4628
658
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4629
658
  free (native_lineno);
4630
4631
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4632
658
  if (!ordered)
4633
301
    {
4634
      /* Sort the table.  */
4635
301
      alent **func_table;
4636
301
      alent *n_lineno_cache;
4637
4638
      /* Create a table of functions.  */
4639
301
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4640
0
  {
4641
0
    bfd_set_error (bfd_error_file_too_big);
4642
0
    ret = false;
4643
0
  }
4644
301
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4645
301
  {
4646
301
    alent **p = func_table;
4647
301
    unsigned int i;
4648
4649
208k
    for (i = 0; i < asect->lineno_count; i++)
4650
208k
      if (lineno_cache[i].line_number == 0)
4651
69.5k
        *p++ = &lineno_cache[i];
4652
4653
301
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4654
4655
    /* Sort by functions.  */
4656
301
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4657
4658
    /* Create the new sorted table.  */
4659
301
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4660
0
      {
4661
0
        bfd_set_error (bfd_error_file_too_big);
4662
0
        ret = false;
4663
0
      }
4664
301
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4665
301
      {
4666
301
        alent *n_cache_ptr = n_lineno_cache;
4667
4668
69.9k
        for (i = 0; i < nbr_func; i++)
4669
69.5k
    {
4670
69.5k
      coff_symbol_type *sym;
4671
69.5k
      alent *old_ptr = func_table[i];
4672
4673
      /* Update the function entry.  */
4674
69.5k
      sym = (coff_symbol_type *) old_ptr->u.sym;
4675
      /* PR binutils/17512: Point the lineno to where
4676
         this entry will be after the memcpy below.  */
4677
69.5k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4678
      /* Copy the function and line number entries.  */
4679
69.5k
      do
4680
208k
        *n_cache_ptr++ = *old_ptr++;
4681
208k
      while (old_ptr->line_number != 0);
4682
69.5k
    }
4683
4684
301
        memcpy (lineno_cache, n_lineno_cache,
4685
301
          asect->lineno_count * sizeof (alent));
4686
301
      }
4687
0
    else
4688
0
      ret = false;
4689
301
    bfd_release (abfd, func_table);
4690
301
  }
4691
0
      else
4692
0
  ret = false;
4693
301
    }
4694
4695
658
  return ret;
4696
658
}
Unexecuted instantiation: coff-tic4x.c:coff_slurp_line_table
coff-tic54x.c:coff_slurp_line_table
Line
Count
Source
4499
7.51k
{
4500
7.51k
  LINENO *native_lineno;
4501
7.51k
  alent *lineno_cache;
4502
7.51k
  unsigned int counter;
4503
7.51k
  alent *cache_ptr;
4504
7.51k
  bfd_vma prev_offset = 0;
4505
7.51k
  bool ordered = true;
4506
7.51k
  unsigned int nbr_func;
4507
7.51k
  LINENO *src;
4508
7.51k
  bool have_func;
4509
7.51k
  bool ret = true;
4510
7.51k
  size_t amt;
4511
4512
7.51k
  if (asect->lineno_count == 0)
4513
6.25k
    return true;
4514
4515
1.26k
  BFD_ASSERT (asect->lineno == NULL);
4516
4517
1.26k
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4518
1.26k
             asect->lineno_count,
4519
1.26k
             bfd_coff_linesz (abfd));
4520
1.26k
  if (native_lineno == NULL)
4521
511
    {
4522
511
      _bfd_error_handler
4523
511
  (_("%pB: warning: line number table read failed"), abfd);
4524
511
      return false;
4525
511
    }
4526
4527
753
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4528
0
    {
4529
0
      bfd_set_error (bfd_error_file_too_big);
4530
0
      free (native_lineno);
4531
0
      return false;
4532
0
    }
4533
753
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4534
753
  if (lineno_cache == NULL)
4535
0
    {
4536
0
      free (native_lineno);
4537
0
      return false;
4538
0
    }
4539
4540
753
  cache_ptr = lineno_cache;
4541
753
  asect->lineno = lineno_cache;
4542
753
  src = native_lineno;
4543
753
  nbr_func = 0;
4544
753
  have_func = false;
4545
4546
1.08M
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4547
1.08M
    {
4548
1.08M
      struct internal_lineno dst;
4549
4550
1.08M
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4551
1.08M
      cache_ptr->line_number = dst.l_lnno;
4552
      /* Appease memory checkers that get all excited about
4553
   uninitialised memory when copying alents if u.offset is
4554
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4555
1.08M
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4556
4557
1.08M
      if (cache_ptr->line_number == 0)
4558
289k
  {
4559
289k
    combined_entry_type * ent;
4560
289k
    unsigned long symndx;
4561
289k
    coff_symbol_type *sym;
4562
4563
289k
    have_func = false;
4564
289k
    symndx = dst.l_addr.l_symndx;
4565
289k
    if (symndx >= obj_raw_syment_count (abfd))
4566
101k
      {
4567
101k
        _bfd_error_handler
4568
    /* xgettext:c-format */
4569
101k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4570
101k
     abfd, symndx, counter);
4571
101k
        cache_ptr->line_number = -1;
4572
101k
        ret = false;
4573
101k
        continue;
4574
101k
      }
4575
4576
187k
    ent = obj_raw_syments (abfd) + symndx;
4577
    /* FIXME: We should not be casting between ints and
4578
       pointers like this.  */
4579
187k
    if (! ent->is_sym)
4580
37.7k
      {
4581
37.7k
        _bfd_error_handler
4582
    /* xgettext:c-format */
4583
37.7k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4584
37.7k
     abfd, symndx, counter);
4585
37.7k
        cache_ptr->line_number = -1;
4586
37.7k
        ret = false;
4587
37.7k
        continue;
4588
37.7k
      }
4589
149k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4590
4591
    /* PR 17512 file: 078-10659-0.004  */
4592
149k
    if (sym < obj_symbols (abfd)
4593
149k
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4594
0
      {
4595
0
        _bfd_error_handler
4596
    /* xgettext:c-format */
4597
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4598
0
     abfd, counter);
4599
0
        cache_ptr->line_number = -1;
4600
0
        ret = false;
4601
0
        continue;
4602
0
      }
4603
4604
149k
    have_func = true;
4605
149k
    nbr_func++;
4606
149k
    cache_ptr->u.sym = (asymbol *) sym;
4607
149k
    if (sym->lineno != NULL)
4608
147k
      _bfd_error_handler
4609
        /* xgettext:c-format */
4610
147k
        (_("%pB: warning: duplicate line number information for `%s'"),
4611
147k
         abfd, bfd_asymbol_name (&sym->symbol));
4612
4613
149k
    sym->lineno = cache_ptr;
4614
149k
    if (sym->symbol.value < prev_offset)
4615
3.14k
      ordered = false;
4616
149k
    prev_offset = sym->symbol.value;
4617
149k
  }
4618
792k
      else if (!have_func)
4619
  /* Drop line information that has no associated function.
4620
     PR 17521: file: 078-10659-0.004.  */
4621
570k
  continue;
4622
221k
      else
4623
221k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4624
371k
      cache_ptr++;
4625
371k
    }
4626
4627
753
  asect->lineno_count = cache_ptr - lineno_cache;
4628
753
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4629
753
  free (native_lineno);
4630
4631
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4632
753
  if (!ordered)
4633
308
    {
4634
      /* Sort the table.  */
4635
308
      alent **func_table;
4636
308
      alent *n_lineno_cache;
4637
4638
      /* Create a table of functions.  */
4639
308
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4640
0
  {
4641
0
    bfd_set_error (bfd_error_file_too_big);
4642
0
    ret = false;
4643
0
  }
4644
308
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4645
308
  {
4646
308
    alent **p = func_table;
4647
308
    unsigned int i;
4648
4649
230k
    for (i = 0; i < asect->lineno_count; i++)
4650
229k
      if (lineno_cache[i].line_number == 0)
4651
116k
        *p++ = &lineno_cache[i];
4652
4653
308
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4654
4655
    /* Sort by functions.  */
4656
308
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4657
4658
    /* Create the new sorted table.  */
4659
308
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4660
0
      {
4661
0
        bfd_set_error (bfd_error_file_too_big);
4662
0
        ret = false;
4663
0
      }
4664
308
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4665
308
      {
4666
308
        alent *n_cache_ptr = n_lineno_cache;
4667
4668
117k
        for (i = 0; i < nbr_func; i++)
4669
116k
    {
4670
116k
      coff_symbol_type *sym;
4671
116k
      alent *old_ptr = func_table[i];
4672
4673
      /* Update the function entry.  */
4674
116k
      sym = (coff_symbol_type *) old_ptr->u.sym;
4675
      /* PR binutils/17512: Point the lineno to where
4676
         this entry will be after the memcpy below.  */
4677
116k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4678
      /* Copy the function and line number entries.  */
4679
116k
      do
4680
229k
        *n_cache_ptr++ = *old_ptr++;
4681
229k
      while (old_ptr->line_number != 0);
4682
116k
    }
4683
4684
308
        memcpy (lineno_cache, n_lineno_cache,
4685
308
          asect->lineno_count * sizeof (alent));
4686
308
      }
4687
0
    else
4688
0
      ret = false;
4689
308
    bfd_release (abfd, func_table);
4690
308
  }
4691
0
      else
4692
0
  ret = false;
4693
308
    }
4694
4695
753
  return ret;
4696
753
}
coff-z80.c:coff_slurp_line_table
Line
Count
Source
4499
6.20k
{
4500
6.20k
  LINENO *native_lineno;
4501
6.20k
  alent *lineno_cache;
4502
6.20k
  unsigned int counter;
4503
6.20k
  alent *cache_ptr;
4504
6.20k
  bfd_vma prev_offset = 0;
4505
6.20k
  bool ordered = true;
4506
6.20k
  unsigned int nbr_func;
4507
6.20k
  LINENO *src;
4508
6.20k
  bool have_func;
4509
6.20k
  bool ret = true;
4510
6.20k
  size_t amt;
4511
4512
6.20k
  if (asect->lineno_count == 0)
4513
4.89k
    return true;
4514
4515
1.31k
  BFD_ASSERT (asect->lineno == NULL);
4516
4517
1.31k
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4518
1.31k
             asect->lineno_count,
4519
1.31k
             bfd_coff_linesz (abfd));
4520
1.31k
  if (native_lineno == NULL)
4521
581
    {
4522
581
      _bfd_error_handler
4523
581
  (_("%pB: warning: line number table read failed"), abfd);
4524
581
      return false;
4525
581
    }
4526
4527
732
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4528
0
    {
4529
0
      bfd_set_error (bfd_error_file_too_big);
4530
0
      free (native_lineno);
4531
0
      return false;
4532
0
    }
4533
732
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4534
732
  if (lineno_cache == NULL)
4535
0
    {
4536
0
      free (native_lineno);
4537
0
      return false;
4538
0
    }
4539
4540
732
  cache_ptr = lineno_cache;
4541
732
  asect->lineno = lineno_cache;
4542
732
  src = native_lineno;
4543
732
  nbr_func = 0;
4544
732
  have_func = false;
4545
4546
480k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4547
479k
    {
4548
479k
      struct internal_lineno dst;
4549
4550
479k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4551
479k
      cache_ptr->line_number = dst.l_lnno;
4552
      /* Appease memory checkers that get all excited about
4553
   uninitialised memory when copying alents if u.offset is
4554
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4555
479k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4556
4557
479k
      if (cache_ptr->line_number == 0)
4558
133k
  {
4559
133k
    combined_entry_type * ent;
4560
133k
    unsigned long symndx;
4561
133k
    coff_symbol_type *sym;
4562
4563
133k
    have_func = false;
4564
133k
    symndx = dst.l_addr.l_symndx;
4565
133k
    if (symndx >= obj_raw_syment_count (abfd))
4566
41.4k
      {
4567
41.4k
        _bfd_error_handler
4568
    /* xgettext:c-format */
4569
41.4k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4570
41.4k
     abfd, symndx, counter);
4571
41.4k
        cache_ptr->line_number = -1;
4572
41.4k
        ret = false;
4573
41.4k
        continue;
4574
41.4k
      }
4575
4576
92.5k
    ent = obj_raw_syments (abfd) + symndx;
4577
    /* FIXME: We should not be casting between ints and
4578
       pointers like this.  */
4579
92.5k
    if (! ent->is_sym)
4580
11.5k
      {
4581
11.5k
        _bfd_error_handler
4582
    /* xgettext:c-format */
4583
11.5k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4584
11.5k
     abfd, symndx, counter);
4585
11.5k
        cache_ptr->line_number = -1;
4586
11.5k
        ret = false;
4587
11.5k
        continue;
4588
11.5k
      }
4589
81.0k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4590
4591
    /* PR 17512 file: 078-10659-0.004  */
4592
81.0k
    if (sym < obj_symbols (abfd)
4593
81.0k
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4594
0
      {
4595
0
        _bfd_error_handler
4596
    /* xgettext:c-format */
4597
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4598
0
     abfd, counter);
4599
0
        cache_ptr->line_number = -1;
4600
0
        ret = false;
4601
0
        continue;
4602
0
      }
4603
4604
81.0k
    have_func = true;
4605
81.0k
    nbr_func++;
4606
81.0k
    cache_ptr->u.sym = (asymbol *) sym;
4607
81.0k
    if (sym->lineno != NULL)
4608
79.0k
      _bfd_error_handler
4609
        /* xgettext:c-format */
4610
79.0k
        (_("%pB: warning: duplicate line number information for `%s'"),
4611
79.0k
         abfd, bfd_asymbol_name (&sym->symbol));
4612
4613
81.0k
    sym->lineno = cache_ptr;
4614
81.0k
    if (sym->symbol.value < prev_offset)
4615
1.90k
      ordered = false;
4616
81.0k
    prev_offset = sym->symbol.value;
4617
81.0k
  }
4618
345k
      else if (!have_func)
4619
  /* Drop line information that has no associated function.
4620
     PR 17521: file: 078-10659-0.004.  */
4621
229k
  continue;
4622
115k
      else
4623
115k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4624
196k
      cache_ptr++;
4625
196k
    }
4626
4627
732
  asect->lineno_count = cache_ptr - lineno_cache;
4628
732
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4629
732
  free (native_lineno);
4630
4631
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4632
732
  if (!ordered)
4633
272
    {
4634
      /* Sort the table.  */
4635
272
      alent **func_table;
4636
272
      alent *n_lineno_cache;
4637
4638
      /* Create a table of functions.  */
4639
272
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4640
0
  {
4641
0
    bfd_set_error (bfd_error_file_too_big);
4642
0
    ret = false;
4643
0
  }
4644
272
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4645
272
  {
4646
272
    alent **p = func_table;
4647
272
    unsigned int i;
4648
4649
186k
    for (i = 0; i < asect->lineno_count; i++)
4650
186k
      if (lineno_cache[i].line_number == 0)
4651
76.2k
        *p++ = &lineno_cache[i];
4652
4653
272
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4654
4655
    /* Sort by functions.  */
4656
272
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4657
4658
    /* Create the new sorted table.  */
4659
272
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4660
0
      {
4661
0
        bfd_set_error (bfd_error_file_too_big);
4662
0
        ret = false;
4663
0
      }
4664
272
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4665
272
      {
4666
272
        alent *n_cache_ptr = n_lineno_cache;
4667
4668
76.5k
        for (i = 0; i < nbr_func; i++)
4669
76.2k
    {
4670
76.2k
      coff_symbol_type *sym;
4671
76.2k
      alent *old_ptr = func_table[i];
4672
4673
      /* Update the function entry.  */
4674
76.2k
      sym = (coff_symbol_type *) old_ptr->u.sym;
4675
      /* PR binutils/17512: Point the lineno to where
4676
         this entry will be after the memcpy below.  */
4677
76.2k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4678
      /* Copy the function and line number entries.  */
4679
76.2k
      do
4680
186k
        *n_cache_ptr++ = *old_ptr++;
4681
186k
      while (old_ptr->line_number != 0);
4682
76.2k
    }
4683
4684
272
        memcpy (lineno_cache, n_lineno_cache,
4685
272
          asect->lineno_count * sizeof (alent));
4686
272
      }
4687
0
    else
4688
0
      ret = false;
4689
272
    bfd_release (abfd, func_table);
4690
272
  }
4691
0
      else
4692
0
  ret = false;
4693
272
    }
4694
4695
732
  return ret;
4696
732
}
coff-z8k.c:coff_slurp_line_table
Line
Count
Source
4499
3.10k
{
4500
3.10k
  LINENO *native_lineno;
4501
3.10k
  alent *lineno_cache;
4502
3.10k
  unsigned int counter;
4503
3.10k
  alent *cache_ptr;
4504
3.10k
  bfd_vma prev_offset = 0;
4505
3.10k
  bool ordered = true;
4506
3.10k
  unsigned int nbr_func;
4507
3.10k
  LINENO *src;
4508
3.10k
  bool have_func;
4509
3.10k
  bool ret = true;
4510
3.10k
  size_t amt;
4511
4512
3.10k
  if (asect->lineno_count == 0)
4513
2.17k
    return true;
4514
4515
926
  BFD_ASSERT (asect->lineno == NULL);
4516
4517
926
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4518
926
             asect->lineno_count,
4519
926
             bfd_coff_linesz (abfd));
4520
926
  if (native_lineno == NULL)
4521
503
    {
4522
503
      _bfd_error_handler
4523
503
  (_("%pB: warning: line number table read failed"), abfd);
4524
503
      return false;
4525
503
    }
4526
4527
423
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4528
0
    {
4529
0
      bfd_set_error (bfd_error_file_too_big);
4530
0
      free (native_lineno);
4531
0
      return false;
4532
0
    }
4533
423
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4534
423
  if (lineno_cache == NULL)
4535
0
    {
4536
0
      free (native_lineno);
4537
0
      return false;
4538
0
    }
4539
4540
423
  cache_ptr = lineno_cache;
4541
423
  asect->lineno = lineno_cache;
4542
423
  src = native_lineno;
4543
423
  nbr_func = 0;
4544
423
  have_func = false;
4545
4546
721k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4547
721k
    {
4548
721k
      struct internal_lineno dst;
4549
4550
721k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4551
721k
      cache_ptr->line_number = dst.l_lnno;
4552
      /* Appease memory checkers that get all excited about
4553
   uninitialised memory when copying alents if u.offset is
4554
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4555
721k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4556
4557
721k
      if (cache_ptr->line_number == 0)
4558
194k
  {
4559
194k
    combined_entry_type * ent;
4560
194k
    unsigned long symndx;
4561
194k
    coff_symbol_type *sym;
4562
4563
194k
    have_func = false;
4564
194k
    symndx = dst.l_addr.l_symndx;
4565
194k
    if (symndx >= obj_raw_syment_count (abfd))
4566
68.9k
      {
4567
68.9k
        _bfd_error_handler
4568
    /* xgettext:c-format */
4569
68.9k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4570
68.9k
     abfd, symndx, counter);
4571
68.9k
        cache_ptr->line_number = -1;
4572
68.9k
        ret = false;
4573
68.9k
        continue;
4574
68.9k
      }
4575
4576
125k
    ent = obj_raw_syments (abfd) + symndx;
4577
    /* FIXME: We should not be casting between ints and
4578
       pointers like this.  */
4579
125k
    if (! ent->is_sym)
4580
7.20k
      {
4581
7.20k
        _bfd_error_handler
4582
    /* xgettext:c-format */
4583
7.20k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4584
7.20k
     abfd, symndx, counter);
4585
7.20k
        cache_ptr->line_number = -1;
4586
7.20k
        ret = false;
4587
7.20k
        continue;
4588
7.20k
      }
4589
118k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4590
4591
    /* PR 17512 file: 078-10659-0.004  */
4592
118k
    if (sym < obj_symbols (abfd)
4593
118k
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4594
0
      {
4595
0
        _bfd_error_handler
4596
    /* xgettext:c-format */
4597
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4598
0
     abfd, counter);
4599
0
        cache_ptr->line_number = -1;
4600
0
        ret = false;
4601
0
        continue;
4602
0
      }
4603
4604
118k
    have_func = true;
4605
118k
    nbr_func++;
4606
118k
    cache_ptr->u.sym = (asymbol *) sym;
4607
118k
    if (sym->lineno != NULL)
4608
117k
      _bfd_error_handler
4609
        /* xgettext:c-format */
4610
117k
        (_("%pB: warning: duplicate line number information for `%s'"),
4611
117k
         abfd, bfd_asymbol_name (&sym->symbol));
4612
4613
118k
    sym->lineno = cache_ptr;
4614
118k
    if (sym->symbol.value < prev_offset)
4615
1.94k
      ordered = false;
4616
118k
    prev_offset = sym->symbol.value;
4617
118k
  }
4618
526k
      else if (!have_func)
4619
  /* Drop line information that has no associated function.
4620
     PR 17521: file: 078-10659-0.004.  */
4621
364k
  continue;
4622
161k
      else
4623
161k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4624
280k
      cache_ptr++;
4625
280k
    }
4626
4627
423
  asect->lineno_count = cache_ptr - lineno_cache;
4628
423
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4629
423
  free (native_lineno);
4630
4631
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4632
423
  if (!ordered)
4633
190
    {
4634
      /* Sort the table.  */
4635
190
      alent **func_table;
4636
190
      alent *n_lineno_cache;
4637
4638
      /* Create a table of functions.  */
4639
190
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4640
0
  {
4641
0
    bfd_set_error (bfd_error_file_too_big);
4642
0
    ret = false;
4643
0
  }
4644
190
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4645
190
  {
4646
190
    alent **p = func_table;
4647
190
    unsigned int i;
4648
4649
242k
    for (i = 0; i < asect->lineno_count; i++)
4650
241k
      if (lineno_cache[i].line_number == 0)
4651
100k
        *p++ = &lineno_cache[i];
4652
4653
190
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4654
4655
    /* Sort by functions.  */
4656
190
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4657
4658
    /* Create the new sorted table.  */
4659
190
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4660
0
      {
4661
0
        bfd_set_error (bfd_error_file_too_big);
4662
0
        ret = false;
4663
0
      }
4664
190
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4665
190
      {
4666
190
        alent *n_cache_ptr = n_lineno_cache;
4667
4668
100k
        for (i = 0; i < nbr_func; i++)
4669
100k
    {
4670
100k
      coff_symbol_type *sym;
4671
100k
      alent *old_ptr = func_table[i];
4672
4673
      /* Update the function entry.  */
4674
100k
      sym = (coff_symbol_type *) old_ptr->u.sym;
4675
      /* PR binutils/17512: Point the lineno to where
4676
         this entry will be after the memcpy below.  */
4677
100k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4678
      /* Copy the function and line number entries.  */
4679
100k
      do
4680
241k
        *n_cache_ptr++ = *old_ptr++;
4681
241k
      while (old_ptr->line_number != 0);
4682
100k
    }
4683
4684
190
        memcpy (lineno_cache, n_lineno_cache,
4685
190
          asect->lineno_count * sizeof (alent));
4686
190
      }
4687
0
    else
4688
0
      ret = false;
4689
190
    bfd_release (abfd, func_table);
4690
190
  }
4691
0
      else
4692
0
  ret = false;
4693
190
    }
4694
4695
423
  return ret;
4696
423
}
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
4499
958
{
4500
958
  LINENO *native_lineno;
4501
958
  alent *lineno_cache;
4502
958
  unsigned int counter;
4503
958
  alent *cache_ptr;
4504
958
  bfd_vma prev_offset = 0;
4505
958
  bool ordered = true;
4506
958
  unsigned int nbr_func;
4507
958
  LINENO *src;
4508
958
  bool have_func;
4509
958
  bool ret = true;
4510
958
  size_t amt;
4511
4512
958
  if (asect->lineno_count == 0)
4513
445
    return true;
4514
4515
513
  BFD_ASSERT (asect->lineno == NULL);
4516
4517
513
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4518
513
             asect->lineno_count,
4519
513
             bfd_coff_linesz (abfd));
4520
513
  if (native_lineno == NULL)
4521
200
    {
4522
200
      _bfd_error_handler
4523
200
  (_("%pB: warning: line number table read failed"), abfd);
4524
200
      return false;
4525
200
    }
4526
4527
313
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4528
0
    {
4529
0
      bfd_set_error (bfd_error_file_too_big);
4530
0
      free (native_lineno);
4531
0
      return false;
4532
0
    }
4533
313
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4534
313
  if (lineno_cache == NULL)
4535
0
    {
4536
0
      free (native_lineno);
4537
0
      return false;
4538
0
    }
4539
4540
313
  cache_ptr = lineno_cache;
4541
313
  asect->lineno = lineno_cache;
4542
313
  src = native_lineno;
4543
313
  nbr_func = 0;
4544
313
  have_func = false;
4545
4546
667k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4547
666k
    {
4548
666k
      struct internal_lineno dst;
4549
4550
666k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4551
666k
      cache_ptr->line_number = dst.l_lnno;
4552
      /* Appease memory checkers that get all excited about
4553
   uninitialised memory when copying alents if u.offset is
4554
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4555
666k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4556
4557
666k
      if (cache_ptr->line_number == 0)
4558
233k
  {
4559
233k
    combined_entry_type * ent;
4560
233k
    unsigned long symndx;
4561
233k
    coff_symbol_type *sym;
4562
4563
233k
    have_func = false;
4564
233k
    symndx = dst.l_addr.l_symndx;
4565
233k
    if (symndx >= obj_raw_syment_count (abfd))
4566
110k
      {
4567
110k
        _bfd_error_handler
4568
    /* xgettext:c-format */
4569
110k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4570
110k
     abfd, symndx, counter);
4571
110k
        cache_ptr->line_number = -1;
4572
110k
        ret = false;
4573
110k
        continue;
4574
110k
      }
4575
4576
123k
    ent = obj_raw_syments (abfd) + symndx;
4577
    /* FIXME: We should not be casting between ints and
4578
       pointers like this.  */
4579
123k
    if (! ent->is_sym)
4580
18.8k
      {
4581
18.8k
        _bfd_error_handler
4582
    /* xgettext:c-format */
4583
18.8k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4584
18.8k
     abfd, symndx, counter);
4585
18.8k
        cache_ptr->line_number = -1;
4586
18.8k
        ret = false;
4587
18.8k
        continue;
4588
18.8k
      }
4589
104k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4590
4591
    /* PR 17512 file: 078-10659-0.004  */
4592
104k
    if (sym < obj_symbols (abfd)
4593
104k
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4594
0
      {
4595
0
        _bfd_error_handler
4596
    /* xgettext:c-format */
4597
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4598
0
     abfd, counter);
4599
0
        cache_ptr->line_number = -1;
4600
0
        ret = false;
4601
0
        continue;
4602
0
      }
4603
4604
104k
    have_func = true;
4605
104k
    nbr_func++;
4606
104k
    cache_ptr->u.sym = (asymbol *) sym;
4607
104k
    if (sym->lineno != NULL)
4608
102k
      _bfd_error_handler
4609
        /* xgettext:c-format */
4610
102k
        (_("%pB: warning: duplicate line number information for `%s'"),
4611
102k
         abfd, bfd_asymbol_name (&sym->symbol));
4612
4613
104k
    sym->lineno = cache_ptr;
4614
104k
    if (sym->symbol.value < prev_offset)
4615
4.75k
      ordered = false;
4616
104k
    prev_offset = sym->symbol.value;
4617
104k
  }
4618
432k
      else if (!have_func)
4619
  /* Drop line information that has no associated function.
4620
     PR 17521: file: 078-10659-0.004.  */
4621
312k
  continue;
4622
120k
      else
4623
120k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4624
225k
      cache_ptr++;
4625
225k
    }
4626
4627
313
  asect->lineno_count = cache_ptr - lineno_cache;
4628
313
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4629
313
  free (native_lineno);
4630
4631
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4632
313
  if (!ordered)
4633
211
    {
4634
      /* Sort the table.  */
4635
211
      alent **func_table;
4636
211
      alent *n_lineno_cache;
4637
4638
      /* Create a table of functions.  */
4639
211
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4640
0
  {
4641
0
    bfd_set_error (bfd_error_file_too_big);
4642
0
    ret = false;
4643
0
  }
4644
211
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4645
211
  {
4646
211
    alent **p = func_table;
4647
211
    unsigned int i;
4648
4649
223k
    for (i = 0; i < asect->lineno_count; i++)
4650
222k
      if (lineno_cache[i].line_number == 0)
4651
103k
        *p++ = &lineno_cache[i];
4652
4653
211
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4654
4655
    /* Sort by functions.  */
4656
211
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4657
4658
    /* Create the new sorted table.  */
4659
211
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4660
0
      {
4661
0
        bfd_set_error (bfd_error_file_too_big);
4662
0
        ret = false;
4663
0
      }
4664
211
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4665
211
      {
4666
211
        alent *n_cache_ptr = n_lineno_cache;
4667
4668
103k
        for (i = 0; i < nbr_func; i++)
4669
103k
    {
4670
103k
      coff_symbol_type *sym;
4671
103k
      alent *old_ptr = func_table[i];
4672
4673
      /* Update the function entry.  */
4674
103k
      sym = (coff_symbol_type *) old_ptr->u.sym;
4675
      /* PR binutils/17512: Point the lineno to where
4676
         this entry will be after the memcpy below.  */
4677
103k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4678
      /* Copy the function and line number entries.  */
4679
103k
      do
4680
222k
        *n_cache_ptr++ = *old_ptr++;
4681
222k
      while (old_ptr->line_number != 0);
4682
103k
    }
4683
4684
211
        memcpy (lineno_cache, n_lineno_cache,
4685
211
          asect->lineno_count * sizeof (alent));
4686
211
      }
4687
0
    else
4688
0
      ret = false;
4689
211
    bfd_release (abfd, func_table);
4690
211
  }
4691
0
      else
4692
0
  ret = false;
4693
211
    }
4694
4695
313
  return ret;
4696
313
}
pe-mcore.c:coff_slurp_line_table
Line
Count
Source
4499
2.92k
{
4500
2.92k
  LINENO *native_lineno;
4501
2.92k
  alent *lineno_cache;
4502
2.92k
  unsigned int counter;
4503
2.92k
  alent *cache_ptr;
4504
2.92k
  bfd_vma prev_offset = 0;
4505
2.92k
  bool ordered = true;
4506
2.92k
  unsigned int nbr_func;
4507
2.92k
  LINENO *src;
4508
2.92k
  bool have_func;
4509
2.92k
  bool ret = true;
4510
2.92k
  size_t amt;
4511
4512
2.92k
  if (asect->lineno_count == 0)
4513
2.16k
    return true;
4514
4515
754
  BFD_ASSERT (asect->lineno == NULL);
4516
4517
754
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4518
754
             asect->lineno_count,
4519
754
             bfd_coff_linesz (abfd));
4520
754
  if (native_lineno == NULL)
4521
265
    {
4522
265
      _bfd_error_handler
4523
265
  (_("%pB: warning: line number table read failed"), abfd);
4524
265
      return false;
4525
265
    }
4526
4527
489
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4528
0
    {
4529
0
      bfd_set_error (bfd_error_file_too_big);
4530
0
      free (native_lineno);
4531
0
      return false;
4532
0
    }
4533
489
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4534
489
  if (lineno_cache == NULL)
4535
0
    {
4536
0
      free (native_lineno);
4537
0
      return false;
4538
0
    }
4539
4540
489
  cache_ptr = lineno_cache;
4541
489
  asect->lineno = lineno_cache;
4542
489
  src = native_lineno;
4543
489
  nbr_func = 0;
4544
489
  have_func = false;
4545
4546
1.39M
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4547
1.39M
    {
4548
1.39M
      struct internal_lineno dst;
4549
4550
1.39M
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4551
1.39M
      cache_ptr->line_number = dst.l_lnno;
4552
      /* Appease memory checkers that get all excited about
4553
   uninitialised memory when copying alents if u.offset is
4554
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4555
1.39M
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4556
4557
1.39M
      if (cache_ptr->line_number == 0)
4558
633k
  {
4559
633k
    combined_entry_type * ent;
4560
633k
    unsigned long symndx;
4561
633k
    coff_symbol_type *sym;
4562
4563
633k
    have_func = false;
4564
633k
    symndx = dst.l_addr.l_symndx;
4565
633k
    if (symndx >= obj_raw_syment_count (abfd))
4566
281k
      {
4567
281k
        _bfd_error_handler
4568
    /* xgettext:c-format */
4569
281k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4570
281k
     abfd, symndx, counter);
4571
281k
        cache_ptr->line_number = -1;
4572
281k
        ret = false;
4573
281k
        continue;
4574
281k
      }
4575
4576
351k
    ent = obj_raw_syments (abfd) + symndx;
4577
    /* FIXME: We should not be casting between ints and
4578
       pointers like this.  */
4579
351k
    if (! ent->is_sym)
4580
60.8k
      {
4581
60.8k
        _bfd_error_handler
4582
    /* xgettext:c-format */
4583
60.8k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4584
60.8k
     abfd, symndx, counter);
4585
60.8k
        cache_ptr->line_number = -1;
4586
60.8k
        ret = false;
4587
60.8k
        continue;
4588
60.8k
      }
4589
290k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4590
4591
    /* PR 17512 file: 078-10659-0.004  */
4592
290k
    if (sym < obj_symbols (abfd)
4593
290k
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4594
0
      {
4595
0
        _bfd_error_handler
4596
    /* xgettext:c-format */
4597
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4598
0
     abfd, counter);
4599
0
        cache_ptr->line_number = -1;
4600
0
        ret = false;
4601
0
        continue;
4602
0
      }
4603
4604
290k
    have_func = true;
4605
290k
    nbr_func++;
4606
290k
    cache_ptr->u.sym = (asymbol *) sym;
4607
290k
    if (sym->lineno != NULL)
4608
287k
      _bfd_error_handler
4609
        /* xgettext:c-format */
4610
287k
        (_("%pB: warning: duplicate line number information for `%s'"),
4611
287k
         abfd, bfd_asymbol_name (&sym->symbol));
4612
4613
290k
    sym->lineno = cache_ptr;
4614
290k
    if (sym->symbol.value < prev_offset)
4615
5.08k
      ordered = false;
4616
290k
    prev_offset = sym->symbol.value;
4617
290k
  }
4618
761k
      else if (!have_func)
4619
  /* Drop line information that has no associated function.
4620
     PR 17521: file: 078-10659-0.004.  */
4621
521k
  continue;
4622
240k
      else
4623
240k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4624
530k
      cache_ptr++;
4625
530k
    }
4626
4627
489
  asect->lineno_count = cache_ptr - lineno_cache;
4628
489
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4629
489
  free (native_lineno);
4630
4631
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4632
489
  if (!ordered)
4633
249
    {
4634
      /* Sort the table.  */
4635
249
      alent **func_table;
4636
249
      alent *n_lineno_cache;
4637
4638
      /* Create a table of functions.  */
4639
249
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4640
0
  {
4641
0
    bfd_set_error (bfd_error_file_too_big);
4642
0
    ret = false;
4643
0
  }
4644
249
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4645
249
  {
4646
249
    alent **p = func_table;
4647
249
    unsigned int i;
4648
4649
515k
    for (i = 0; i < asect->lineno_count; i++)
4650
515k
      if (lineno_cache[i].line_number == 0)
4651
283k
        *p++ = &lineno_cache[i];
4652
4653
249
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4654
4655
    /* Sort by functions.  */
4656
249
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4657
4658
    /* Create the new sorted table.  */
4659
249
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4660
0
      {
4661
0
        bfd_set_error (bfd_error_file_too_big);
4662
0
        ret = false;
4663
0
      }
4664
249
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4665
249
      {
4666
249
        alent *n_cache_ptr = n_lineno_cache;
4667
4668
284k
        for (i = 0; i < nbr_func; i++)
4669
283k
    {
4670
283k
      coff_symbol_type *sym;
4671
283k
      alent *old_ptr = func_table[i];
4672
4673
      /* Update the function entry.  */
4674
283k
      sym = (coff_symbol_type *) old_ptr->u.sym;
4675
      /* PR binutils/17512: Point the lineno to where
4676
         this entry will be after the memcpy below.  */
4677
283k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4678
      /* Copy the function and line number entries.  */
4679
283k
      do
4680
515k
        *n_cache_ptr++ = *old_ptr++;
4681
515k
      while (old_ptr->line_number != 0);
4682
283k
    }
4683
4684
249
        memcpy (lineno_cache, n_lineno_cache,
4685
249
          asect->lineno_count * sizeof (alent));
4686
249
      }
4687
0
    else
4688
0
      ret = false;
4689
249
    bfd_release (abfd, func_table);
4690
249
  }
4691
0
      else
4692
0
  ret = false;
4693
249
    }
4694
4695
489
  return ret;
4696
489
}
pe-sh.c:coff_slurp_line_table
Line
Count
Source
4499
1.65k
{
4500
1.65k
  LINENO *native_lineno;
4501
1.65k
  alent *lineno_cache;
4502
1.65k
  unsigned int counter;
4503
1.65k
  alent *cache_ptr;
4504
1.65k
  bfd_vma prev_offset = 0;
4505
1.65k
  bool ordered = true;
4506
1.65k
  unsigned int nbr_func;
4507
1.65k
  LINENO *src;
4508
1.65k
  bool have_func;
4509
1.65k
  bool ret = true;
4510
1.65k
  size_t amt;
4511
4512
1.65k
  if (asect->lineno_count == 0)
4513
850
    return true;
4514
4515
809
  BFD_ASSERT (asect->lineno == NULL);
4516
4517
809
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4518
809
             asect->lineno_count,
4519
809
             bfd_coff_linesz (abfd));
4520
809
  if (native_lineno == NULL)
4521
350
    {
4522
350
      _bfd_error_handler
4523
350
  (_("%pB: warning: line number table read failed"), abfd);
4524
350
      return false;
4525
350
    }
4526
4527
459
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4528
0
    {
4529
0
      bfd_set_error (bfd_error_file_too_big);
4530
0
      free (native_lineno);
4531
0
      return false;
4532
0
    }
4533
459
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4534
459
  if (lineno_cache == NULL)
4535
0
    {
4536
0
      free (native_lineno);
4537
0
      return false;
4538
0
    }
4539
4540
459
  cache_ptr = lineno_cache;
4541
459
  asect->lineno = lineno_cache;
4542
459
  src = native_lineno;
4543
459
  nbr_func = 0;
4544
459
  have_func = false;
4545
4546
1.22M
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4547
1.22M
    {
4548
1.22M
      struct internal_lineno dst;
4549
4550
1.22M
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4551
1.22M
      cache_ptr->line_number = dst.l_lnno;
4552
      /* Appease memory checkers that get all excited about
4553
   uninitialised memory when copying alents if u.offset is
4554
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4555
1.22M
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4556
4557
1.22M
      if (cache_ptr->line_number == 0)
4558
452k
  {
4559
452k
    combined_entry_type * ent;
4560
452k
    unsigned long symndx;
4561
452k
    coff_symbol_type *sym;
4562
4563
452k
    have_func = false;
4564
452k
    symndx = dst.l_addr.l_symndx;
4565
452k
    if (symndx >= obj_raw_syment_count (abfd))
4566
202k
      {
4567
202k
        _bfd_error_handler
4568
    /* xgettext:c-format */
4569
202k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4570
202k
     abfd, symndx, counter);
4571
202k
        cache_ptr->line_number = -1;
4572
202k
        ret = false;
4573
202k
        continue;
4574
202k
      }
4575
4576
250k
    ent = obj_raw_syments (abfd) + symndx;
4577
    /* FIXME: We should not be casting between ints and
4578
       pointers like this.  */
4579
250k
    if (! ent->is_sym)
4580
43.8k
      {
4581
43.8k
        _bfd_error_handler
4582
    /* xgettext:c-format */
4583
43.8k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4584
43.8k
     abfd, symndx, counter);
4585
43.8k
        cache_ptr->line_number = -1;
4586
43.8k
        ret = false;
4587
43.8k
        continue;
4588
43.8k
      }
4589
206k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4590
4591
    /* PR 17512 file: 078-10659-0.004  */
4592
206k
    if (sym < obj_symbols (abfd)
4593
206k
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4594
0
      {
4595
0
        _bfd_error_handler
4596
    /* xgettext:c-format */
4597
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4598
0
     abfd, counter);
4599
0
        cache_ptr->line_number = -1;
4600
0
        ret = false;
4601
0
        continue;
4602
0
      }
4603
4604
206k
    have_func = true;
4605
206k
    nbr_func++;
4606
206k
    cache_ptr->u.sym = (asymbol *) sym;
4607
206k
    if (sym->lineno != NULL)
4608
202k
      _bfd_error_handler
4609
        /* xgettext:c-format */
4610
202k
        (_("%pB: warning: duplicate line number information for `%s'"),
4611
202k
         abfd, bfd_asymbol_name (&sym->symbol));
4612
4613
206k
    sym->lineno = cache_ptr;
4614
206k
    if (sym->symbol.value < prev_offset)
4615
7.43k
      ordered = false;
4616
206k
    prev_offset = sym->symbol.value;
4617
206k
  }
4618
775k
      else if (!have_func)
4619
  /* Drop line information that has no associated function.
4620
     PR 17521: file: 078-10659-0.004.  */
4621
500k
  continue;
4622
275k
      else
4623
275k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4624
481k
      cache_ptr++;
4625
481k
    }
4626
4627
459
  asect->lineno_count = cache_ptr - lineno_cache;
4628
459
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4629
459
  free (native_lineno);
4630
4631
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4632
459
  if (!ordered)
4633
237
    {
4634
      /* Sort the table.  */
4635
237
      alent **func_table;
4636
237
      alent *n_lineno_cache;
4637
4638
      /* Create a table of functions.  */
4639
237
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4640
0
  {
4641
0
    bfd_set_error (bfd_error_file_too_big);
4642
0
    ret = false;
4643
0
  }
4644
237
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4645
237
  {
4646
237
    alent **p = func_table;
4647
237
    unsigned int i;
4648
4649
477k
    for (i = 0; i < asect->lineno_count; i++)
4650
476k
      if (lineno_cache[i].line_number == 0)
4651
203k
        *p++ = &lineno_cache[i];
4652
4653
237
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4654
4655
    /* Sort by functions.  */
4656
237
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4657
4658
    /* Create the new sorted table.  */
4659
237
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4660
0
      {
4661
0
        bfd_set_error (bfd_error_file_too_big);
4662
0
        ret = false;
4663
0
      }
4664
237
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4665
237
      {
4666
237
        alent *n_cache_ptr = n_lineno_cache;
4667
4668
203k
        for (i = 0; i < nbr_func; i++)
4669
203k
    {
4670
203k
      coff_symbol_type *sym;
4671
203k
      alent *old_ptr = func_table[i];
4672
4673
      /* Update the function entry.  */
4674
203k
      sym = (coff_symbol_type *) old_ptr->u.sym;
4675
      /* PR binutils/17512: Point the lineno to where
4676
         this entry will be after the memcpy below.  */
4677
203k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4678
      /* Copy the function and line number entries.  */
4679
203k
      do
4680
476k
        *n_cache_ptr++ = *old_ptr++;
4681
476k
      while (old_ptr->line_number != 0);
4682
203k
    }
4683
4684
237
        memcpy (lineno_cache, n_lineno_cache,
4685
237
          asect->lineno_count * sizeof (alent));
4686
237
      }
4687
0
    else
4688
0
      ret = false;
4689
237
    bfd_release (abfd, func_table);
4690
237
  }
4691
0
      else
4692
0
  ret = false;
4693
237
    }
4694
4695
459
  return ret;
4696
459
}
pei-arm-wince.c:coff_slurp_line_table
Line
Count
Source
4499
812
{
4500
812
  LINENO *native_lineno;
4501
812
  alent *lineno_cache;
4502
812
  unsigned int counter;
4503
812
  alent *cache_ptr;
4504
812
  bfd_vma prev_offset = 0;
4505
812
  bool ordered = true;
4506
812
  unsigned int nbr_func;
4507
812
  LINENO *src;
4508
812
  bool have_func;
4509
812
  bool ret = true;
4510
812
  size_t amt;
4511
4512
812
  if (asect->lineno_count == 0)
4513
253
    return true;
4514
4515
559
  BFD_ASSERT (asect->lineno == NULL);
4516
4517
559
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4518
559
             asect->lineno_count,
4519
559
             bfd_coff_linesz (abfd));
4520
559
  if (native_lineno == NULL)
4521
192
    {
4522
192
      _bfd_error_handler
4523
192
  (_("%pB: warning: line number table read failed"), abfd);
4524
192
      return false;
4525
192
    }
4526
4527
367
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4528
0
    {
4529
0
      bfd_set_error (bfd_error_file_too_big);
4530
0
      free (native_lineno);
4531
0
      return false;
4532
0
    }
4533
367
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4534
367
  if (lineno_cache == NULL)
4535
0
    {
4536
0
      free (native_lineno);
4537
0
      return false;
4538
0
    }
4539
4540
367
  cache_ptr = lineno_cache;
4541
367
  asect->lineno = lineno_cache;
4542
367
  src = native_lineno;
4543
367
  nbr_func = 0;
4544
367
  have_func = false;
4545
4546
746k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4547
746k
    {
4548
746k
      struct internal_lineno dst;
4549
4550
746k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4551
746k
      cache_ptr->line_number = dst.l_lnno;
4552
      /* Appease memory checkers that get all excited about
4553
   uninitialised memory when copying alents if u.offset is
4554
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4555
746k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4556
4557
746k
      if (cache_ptr->line_number == 0)
4558
350k
  {
4559
350k
    combined_entry_type * ent;
4560
350k
    unsigned long symndx;
4561
350k
    coff_symbol_type *sym;
4562
4563
350k
    have_func = false;
4564
350k
    symndx = dst.l_addr.l_symndx;
4565
350k
    if (symndx >= obj_raw_syment_count (abfd))
4566
173k
      {
4567
173k
        _bfd_error_handler
4568
    /* xgettext:c-format */
4569
173k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4570
173k
     abfd, symndx, counter);
4571
173k
        cache_ptr->line_number = -1;
4572
173k
        ret = false;
4573
173k
        continue;
4574
173k
      }
4575
4576
176k
    ent = obj_raw_syments (abfd) + symndx;
4577
    /* FIXME: We should not be casting between ints and
4578
       pointers like this.  */
4579
176k
    if (! ent->is_sym)
4580
22.7k
      {
4581
22.7k
        _bfd_error_handler
4582
    /* xgettext:c-format */
4583
22.7k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4584
22.7k
     abfd, symndx, counter);
4585
22.7k
        cache_ptr->line_number = -1;
4586
22.7k
        ret = false;
4587
22.7k
        continue;
4588
22.7k
      }
4589
154k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4590
4591
    /* PR 17512 file: 078-10659-0.004  */
4592
154k
    if (sym < obj_symbols (abfd)
4593
154k
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4594
0
      {
4595
0
        _bfd_error_handler
4596
    /* xgettext:c-format */
4597
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4598
0
     abfd, counter);
4599
0
        cache_ptr->line_number = -1;
4600
0
        ret = false;
4601
0
        continue;
4602
0
      }
4603
4604
154k
    have_func = true;
4605
154k
    nbr_func++;
4606
154k
    cache_ptr->u.sym = (asymbol *) sym;
4607
154k
    if (sym->lineno != NULL)
4608
150k
      _bfd_error_handler
4609
        /* xgettext:c-format */
4610
150k
        (_("%pB: warning: duplicate line number information for `%s'"),
4611
150k
         abfd, bfd_asymbol_name (&sym->symbol));
4612
4613
154k
    sym->lineno = cache_ptr;
4614
154k
    if (sym->symbol.value < prev_offset)
4615
5.38k
      ordered = false;
4616
154k
    prev_offset = sym->symbol.value;
4617
154k
  }
4618
395k
      else if (!have_func)
4619
  /* Drop line information that has no associated function.
4620
     PR 17521: file: 078-10659-0.004.  */
4621
267k
  continue;
4622
128k
      else
4623
128k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4624
282k
      cache_ptr++;
4625
282k
    }
4626
4627
367
  asect->lineno_count = cache_ptr - lineno_cache;
4628
367
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4629
367
  free (native_lineno);
4630
4631
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4632
367
  if (!ordered)
4633
257
    {
4634
      /* Sort the table.  */
4635
257
      alent **func_table;
4636
257
      alent *n_lineno_cache;
4637
4638
      /* Create a table of functions.  */
4639
257
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4640
0
  {
4641
0
    bfd_set_error (bfd_error_file_too_big);
4642
0
    ret = false;
4643
0
  }
4644
257
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4645
257
  {
4646
257
    alent **p = func_table;
4647
257
    unsigned int i;
4648
4649
266k
    for (i = 0; i < asect->lineno_count; i++)
4650
266k
      if (lineno_cache[i].line_number == 0)
4651
144k
        *p++ = &lineno_cache[i];
4652
4653
257
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4654
4655
    /* Sort by functions.  */
4656
257
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4657
4658
    /* Create the new sorted table.  */
4659
257
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4660
0
      {
4661
0
        bfd_set_error (bfd_error_file_too_big);
4662
0
        ret = false;
4663
0
      }
4664
257
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4665
257
      {
4666
257
        alent *n_cache_ptr = n_lineno_cache;
4667
4668
144k
        for (i = 0; i < nbr_func; i++)
4669
144k
    {
4670
144k
      coff_symbol_type *sym;
4671
144k
      alent *old_ptr = func_table[i];
4672
4673
      /* Update the function entry.  */
4674
144k
      sym = (coff_symbol_type *) old_ptr->u.sym;
4675
      /* PR binutils/17512: Point the lineno to where
4676
         this entry will be after the memcpy below.  */
4677
144k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4678
      /* Copy the function and line number entries.  */
4679
144k
      do
4680
266k
        *n_cache_ptr++ = *old_ptr++;
4681
266k
      while (old_ptr->line_number != 0);
4682
144k
    }
4683
4684
257
        memcpy (lineno_cache, n_lineno_cache,
4685
257
          asect->lineno_count * sizeof (alent));
4686
257
      }
4687
0
    else
4688
0
      ret = false;
4689
257
    bfd_release (abfd, func_table);
4690
257
  }
4691
0
      else
4692
0
  ret = false;
4693
257
    }
4694
4695
367
  return ret;
4696
367
}
pei-arm.c:coff_slurp_line_table
Line
Count
Source
4499
2.14k
{
4500
2.14k
  LINENO *native_lineno;
4501
2.14k
  alent *lineno_cache;
4502
2.14k
  unsigned int counter;
4503
2.14k
  alent *cache_ptr;
4504
2.14k
  bfd_vma prev_offset = 0;
4505
2.14k
  bool ordered = true;
4506
2.14k
  unsigned int nbr_func;
4507
2.14k
  LINENO *src;
4508
2.14k
  bool have_func;
4509
2.14k
  bool ret = true;
4510
2.14k
  size_t amt;
4511
4512
2.14k
  if (asect->lineno_count == 0)
4513
1.27k
    return true;
4514
4515
866
  BFD_ASSERT (asect->lineno == NULL);
4516
4517
866
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4518
866
             asect->lineno_count,
4519
866
             bfd_coff_linesz (abfd));
4520
866
  if (native_lineno == NULL)
4521
498
    {
4522
498
      _bfd_error_handler
4523
498
  (_("%pB: warning: line number table read failed"), abfd);
4524
498
      return false;
4525
498
    }
4526
4527
368
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4528
0
    {
4529
0
      bfd_set_error (bfd_error_file_too_big);
4530
0
      free (native_lineno);
4531
0
      return false;
4532
0
    }
4533
368
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4534
368
  if (lineno_cache == NULL)
4535
0
    {
4536
0
      free (native_lineno);
4537
0
      return false;
4538
0
    }
4539
4540
368
  cache_ptr = lineno_cache;
4541
368
  asect->lineno = lineno_cache;
4542
368
  src = native_lineno;
4543
368
  nbr_func = 0;
4544
368
  have_func = false;
4545
4546
285k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4547
285k
    {
4548
285k
      struct internal_lineno dst;
4549
4550
285k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4551
285k
      cache_ptr->line_number = dst.l_lnno;
4552
      /* Appease memory checkers that get all excited about
4553
   uninitialised memory when copying alents if u.offset is
4554
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4555
285k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4556
4557
285k
      if (cache_ptr->line_number == 0)
4558
129k
  {
4559
129k
    combined_entry_type * ent;
4560
129k
    unsigned long symndx;
4561
129k
    coff_symbol_type *sym;
4562
4563
129k
    have_func = false;
4564
129k
    symndx = dst.l_addr.l_symndx;
4565
129k
    if (symndx >= obj_raw_syment_count (abfd))
4566
49.1k
      {
4567
49.1k
        _bfd_error_handler
4568
    /* xgettext:c-format */
4569
49.1k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4570
49.1k
     abfd, symndx, counter);
4571
49.1k
        cache_ptr->line_number = -1;
4572
49.1k
        ret = false;
4573
49.1k
        continue;
4574
49.1k
      }
4575
4576
80.5k
    ent = obj_raw_syments (abfd) + symndx;
4577
    /* FIXME: We should not be casting between ints and
4578
       pointers like this.  */
4579
80.5k
    if (! ent->is_sym)
4580
6.15k
      {
4581
6.15k
        _bfd_error_handler
4582
    /* xgettext:c-format */
4583
6.15k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4584
6.15k
     abfd, symndx, counter);
4585
6.15k
        cache_ptr->line_number = -1;
4586
6.15k
        ret = false;
4587
6.15k
        continue;
4588
6.15k
      }
4589
74.3k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4590
4591
    /* PR 17512 file: 078-10659-0.004  */
4592
74.3k
    if (sym < obj_symbols (abfd)
4593
74.3k
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4594
0
      {
4595
0
        _bfd_error_handler
4596
    /* xgettext:c-format */
4597
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4598
0
     abfd, counter);
4599
0
        cache_ptr->line_number = -1;
4600
0
        ret = false;
4601
0
        continue;
4602
0
      }
4603
4604
74.3k
    have_func = true;
4605
74.3k
    nbr_func++;
4606
74.3k
    cache_ptr->u.sym = (asymbol *) sym;
4607
74.3k
    if (sym->lineno != NULL)
4608
72.6k
      _bfd_error_handler
4609
        /* xgettext:c-format */
4610
72.6k
        (_("%pB: warning: duplicate line number information for `%s'"),
4611
72.6k
         abfd, bfd_asymbol_name (&sym->symbol));
4612
4613
74.3k
    sym->lineno = cache_ptr;
4614
74.3k
    if (sym->symbol.value < prev_offset)
4615
2.65k
      ordered = false;
4616
74.3k
    prev_offset = sym->symbol.value;
4617
74.3k
  }
4618
155k
      else if (!have_func)
4619
  /* Drop line information that has no associated function.
4620
     PR 17521: file: 078-10659-0.004.  */
4621
104k
  continue;
4622
51.7k
      else
4623
51.7k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4624
126k
      cache_ptr++;
4625
126k
    }
4626
4627
368
  asect->lineno_count = cache_ptr - lineno_cache;
4628
368
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4629
368
  free (native_lineno);
4630
4631
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4632
368
  if (!ordered)
4633
180
    {
4634
      /* Sort the table.  */
4635
180
      alent **func_table;
4636
180
      alent *n_lineno_cache;
4637
4638
      /* Create a table of functions.  */
4639
180
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4640
0
  {
4641
0
    bfd_set_error (bfd_error_file_too_big);
4642
0
    ret = false;
4643
0
  }
4644
180
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4645
180
  {
4646
180
    alent **p = func_table;
4647
180
    unsigned int i;
4648
4649
91.1k
    for (i = 0; i < asect->lineno_count; i++)
4650
90.9k
      if (lineno_cache[i].line_number == 0)
4651
56.8k
        *p++ = &lineno_cache[i];
4652
4653
180
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4654
4655
    /* Sort by functions.  */
4656
180
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4657
4658
    /* Create the new sorted table.  */
4659
180
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4660
0
      {
4661
0
        bfd_set_error (bfd_error_file_too_big);
4662
0
        ret = false;
4663
0
      }
4664
180
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4665
180
      {
4666
180
        alent *n_cache_ptr = n_lineno_cache;
4667
4668
57.0k
        for (i = 0; i < nbr_func; i++)
4669
56.8k
    {
4670
56.8k
      coff_symbol_type *sym;
4671
56.8k
      alent *old_ptr = func_table[i];
4672
4673
      /* Update the function entry.  */
4674
56.8k
      sym = (coff_symbol_type *) old_ptr->u.sym;
4675
      /* PR binutils/17512: Point the lineno to where
4676
         this entry will be after the memcpy below.  */
4677
56.8k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4678
      /* Copy the function and line number entries.  */
4679
56.8k
      do
4680
90.9k
        *n_cache_ptr++ = *old_ptr++;
4681
90.9k
      while (old_ptr->line_number != 0);
4682
56.8k
    }
4683
4684
180
        memcpy (lineno_cache, n_lineno_cache,
4685
180
          asect->lineno_count * sizeof (alent));
4686
180
      }
4687
0
    else
4688
0
      ret = false;
4689
180
    bfd_release (abfd, func_table);
4690
180
  }
4691
0
      else
4692
0
  ret = false;
4693
180
    }
4694
4695
368
  return ret;
4696
368
}
pei-mcore.c:coff_slurp_line_table
Line
Count
Source
4499
1.00k
{
4500
1.00k
  LINENO *native_lineno;
4501
1.00k
  alent *lineno_cache;
4502
1.00k
  unsigned int counter;
4503
1.00k
  alent *cache_ptr;
4504
1.00k
  bfd_vma prev_offset = 0;
4505
1.00k
  bool ordered = true;
4506
1.00k
  unsigned int nbr_func;
4507
1.00k
  LINENO *src;
4508
1.00k
  bool have_func;
4509
1.00k
  bool ret = true;
4510
1.00k
  size_t amt;
4511
4512
1.00k
  if (asect->lineno_count == 0)
4513
352
    return true;
4514
4515
648
  BFD_ASSERT (asect->lineno == NULL);
4516
4517
648
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4518
648
             asect->lineno_count,
4519
648
             bfd_coff_linesz (abfd));
4520
648
  if (native_lineno == NULL)
4521
339
    {
4522
339
      _bfd_error_handler
4523
339
  (_("%pB: warning: line number table read failed"), abfd);
4524
339
      return false;
4525
339
    }
4526
4527
309
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4528
0
    {
4529
0
      bfd_set_error (bfd_error_file_too_big);
4530
0
      free (native_lineno);
4531
0
      return false;
4532
0
    }
4533
309
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4534
309
  if (lineno_cache == NULL)
4535
0
    {
4536
0
      free (native_lineno);
4537
0
      return false;
4538
0
    }
4539
4540
309
  cache_ptr = lineno_cache;
4541
309
  asect->lineno = lineno_cache;
4542
309
  src = native_lineno;
4543
309
  nbr_func = 0;
4544
309
  have_func = false;
4545
4546
271k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4547
271k
    {
4548
271k
      struct internal_lineno dst;
4549
4550
271k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4551
271k
      cache_ptr->line_number = dst.l_lnno;
4552
      /* Appease memory checkers that get all excited about
4553
   uninitialised memory when copying alents if u.offset is
4554
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4555
271k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4556
4557
271k
      if (cache_ptr->line_number == 0)
4558
114k
  {
4559
114k
    combined_entry_type * ent;
4560
114k
    unsigned long symndx;
4561
114k
    coff_symbol_type *sym;
4562
4563
114k
    have_func = false;
4564
114k
    symndx = dst.l_addr.l_symndx;
4565
114k
    if (symndx >= obj_raw_syment_count (abfd))
4566
47.2k
      {
4567
47.2k
        _bfd_error_handler
4568
    /* xgettext:c-format */
4569
47.2k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4570
47.2k
     abfd, symndx, counter);
4571
47.2k
        cache_ptr->line_number = -1;
4572
47.2k
        ret = false;
4573
47.2k
        continue;
4574
47.2k
      }
4575
4576
66.8k
    ent = obj_raw_syments (abfd) + symndx;
4577
    /* FIXME: We should not be casting between ints and
4578
       pointers like this.  */
4579
66.8k
    if (! ent->is_sym)
4580
8.15k
      {
4581
8.15k
        _bfd_error_handler
4582
    /* xgettext:c-format */
4583
8.15k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4584
8.15k
     abfd, symndx, counter);
4585
8.15k
        cache_ptr->line_number = -1;
4586
8.15k
        ret = false;
4587
8.15k
        continue;
4588
8.15k
      }
4589
58.7k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4590
4591
    /* PR 17512 file: 078-10659-0.004  */
4592
58.7k
    if (sym < obj_symbols (abfd)
4593
58.7k
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4594
0
      {
4595
0
        _bfd_error_handler
4596
    /* xgettext:c-format */
4597
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4598
0
     abfd, counter);
4599
0
        cache_ptr->line_number = -1;
4600
0
        ret = false;
4601
0
        continue;
4602
0
      }
4603
4604
58.7k
    have_func = true;
4605
58.7k
    nbr_func++;
4606
58.7k
    cache_ptr->u.sym = (asymbol *) sym;
4607
58.7k
    if (sym->lineno != NULL)
4608
57.9k
      _bfd_error_handler
4609
        /* xgettext:c-format */
4610
57.9k
        (_("%pB: warning: duplicate line number information for `%s'"),
4611
57.9k
         abfd, bfd_asymbol_name (&sym->symbol));
4612
4613
58.7k
    sym->lineno = cache_ptr;
4614
58.7k
    if (sym->symbol.value < prev_offset)
4615
1.64k
      ordered = false;
4616
58.7k
    prev_offset = sym->symbol.value;
4617
58.7k
  }
4618
157k
      else if (!have_func)
4619
  /* Drop line information that has no associated function.
4620
     PR 17521: file: 078-10659-0.004.  */
4621
109k
  continue;
4622
47.7k
      else
4623
47.7k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4624
106k
      cache_ptr++;
4625
106k
    }
4626
4627
309
  asect->lineno_count = cache_ptr - lineno_cache;
4628
309
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4629
309
  free (native_lineno);
4630
4631
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4632
309
  if (!ordered)
4633
174
    {
4634
      /* Sort the table.  */
4635
174
      alent **func_table;
4636
174
      alent *n_lineno_cache;
4637
4638
      /* Create a table of functions.  */
4639
174
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4640
0
  {
4641
0
    bfd_set_error (bfd_error_file_too_big);
4642
0
    ret = false;
4643
0
  }
4644
174
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4645
174
  {
4646
174
    alent **p = func_table;
4647
174
    unsigned int i;
4648
4649
105k
    for (i = 0; i < asect->lineno_count; i++)
4650
104k
      if (lineno_cache[i].line_number == 0)
4651
57.8k
        *p++ = &lineno_cache[i];
4652
4653
174
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4654
4655
    /* Sort by functions.  */
4656
174
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4657
4658
    /* Create the new sorted table.  */
4659
174
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4660
0
      {
4661
0
        bfd_set_error (bfd_error_file_too_big);
4662
0
        ret = false;
4663
0
      }
4664
174
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4665
174
      {
4666
174
        alent *n_cache_ptr = n_lineno_cache;
4667
4668
58.0k
        for (i = 0; i < nbr_func; i++)
4669
57.8k
    {
4670
57.8k
      coff_symbol_type *sym;
4671
57.8k
      alent *old_ptr = func_table[i];
4672
4673
      /* Update the function entry.  */
4674
57.8k
      sym = (coff_symbol_type *) old_ptr->u.sym;
4675
      /* PR binutils/17512: Point the lineno to where
4676
         this entry will be after the memcpy below.  */
4677
57.8k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4678
      /* Copy the function and line number entries.  */
4679
57.8k
      do
4680
104k
        *n_cache_ptr++ = *old_ptr++;
4681
104k
      while (old_ptr->line_number != 0);
4682
57.8k
    }
4683
4684
174
        memcpy (lineno_cache, n_lineno_cache,
4685
174
          asect->lineno_count * sizeof (alent));
4686
174
      }
4687
0
    else
4688
0
      ret = false;
4689
174
    bfd_release (abfd, func_table);
4690
174
  }
4691
0
      else
4692
0
  ret = false;
4693
174
    }
4694
4695
309
  return ret;
4696
309
}
pei-sh.c:coff_slurp_line_table
Line
Count
Source
4499
1.70k
{
4500
1.70k
  LINENO *native_lineno;
4501
1.70k
  alent *lineno_cache;
4502
1.70k
  unsigned int counter;
4503
1.70k
  alent *cache_ptr;
4504
1.70k
  bfd_vma prev_offset = 0;
4505
1.70k
  bool ordered = true;
4506
1.70k
  unsigned int nbr_func;
4507
1.70k
  LINENO *src;
4508
1.70k
  bool have_func;
4509
1.70k
  bool ret = true;
4510
1.70k
  size_t amt;
4511
4512
1.70k
  if (asect->lineno_count == 0)
4513
1.08k
    return true;
4514
4515
621
  BFD_ASSERT (asect->lineno == NULL);
4516
4517
621
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4518
621
             asect->lineno_count,
4519
621
             bfd_coff_linesz (abfd));
4520
621
  if (native_lineno == NULL)
4521
279
    {
4522
279
      _bfd_error_handler
4523
279
  (_("%pB: warning: line number table read failed"), abfd);
4524
279
      return false;
4525
279
    }
4526
4527
342
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4528
0
    {
4529
0
      bfd_set_error (bfd_error_file_too_big);
4530
0
      free (native_lineno);
4531
0
      return false;
4532
0
    }
4533
342
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4534
342
  if (lineno_cache == NULL)
4535
0
    {
4536
0
      free (native_lineno);
4537
0
      return false;
4538
0
    }
4539
4540
342
  cache_ptr = lineno_cache;
4541
342
  asect->lineno = lineno_cache;
4542
342
  src = native_lineno;
4543
342
  nbr_func = 0;
4544
342
  have_func = false;
4545
4546
360k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4547
359k
    {
4548
359k
      struct internal_lineno dst;
4549
4550
359k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4551
359k
      cache_ptr->line_number = dst.l_lnno;
4552
      /* Appease memory checkers that get all excited about
4553
   uninitialised memory when copying alents if u.offset is
4554
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4555
359k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4556
4557
359k
      if (cache_ptr->line_number == 0)
4558
177k
  {
4559
177k
    combined_entry_type * ent;
4560
177k
    unsigned long symndx;
4561
177k
    coff_symbol_type *sym;
4562
4563
177k
    have_func = false;
4564
177k
    symndx = dst.l_addr.l_symndx;
4565
177k
    if (symndx >= obj_raw_syment_count (abfd))
4566
104k
      {
4567
104k
        _bfd_error_handler
4568
    /* xgettext:c-format */
4569
104k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4570
104k
     abfd, symndx, counter);
4571
104k
        cache_ptr->line_number = -1;
4572
104k
        ret = false;
4573
104k
        continue;
4574
104k
      }
4575
4576
72.9k
    ent = obj_raw_syments (abfd) + symndx;
4577
    /* FIXME: We should not be casting between ints and
4578
       pointers like this.  */
4579
72.9k
    if (! ent->is_sym)
4580
6.87k
      {
4581
6.87k
        _bfd_error_handler
4582
    /* xgettext:c-format */
4583
6.87k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4584
6.87k
     abfd, symndx, counter);
4585
6.87k
        cache_ptr->line_number = -1;
4586
6.87k
        ret = false;
4587
6.87k
        continue;
4588
6.87k
      }
4589
66.0k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4590
4591
    /* PR 17512 file: 078-10659-0.004  */
4592
66.0k
    if (sym < obj_symbols (abfd)
4593
66.0k
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4594
0
      {
4595
0
        _bfd_error_handler
4596
    /* xgettext:c-format */
4597
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4598
0
     abfd, counter);
4599
0
        cache_ptr->line_number = -1;
4600
0
        ret = false;
4601
0
        continue;
4602
0
      }
4603
4604
66.0k
    have_func = true;
4605
66.0k
    nbr_func++;
4606
66.0k
    cache_ptr->u.sym = (asymbol *) sym;
4607
66.0k
    if (sym->lineno != NULL)
4608
64.7k
      _bfd_error_handler
4609
        /* xgettext:c-format */
4610
64.7k
        (_("%pB: warning: duplicate line number information for `%s'"),
4611
64.7k
         abfd, bfd_asymbol_name (&sym->symbol));
4612
4613
66.0k
    sym->lineno = cache_ptr;
4614
66.0k
    if (sym->symbol.value < prev_offset)
4615
2.13k
      ordered = false;
4616
66.0k
    prev_offset = sym->symbol.value;
4617
66.0k
  }
4618
182k
      else if (!have_func)
4619
  /* Drop line information that has no associated function.
4620
     PR 17521: file: 078-10659-0.004.  */
4621
119k
  continue;
4622
62.6k
      else
4623
62.6k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4624
128k
      cache_ptr++;
4625
128k
    }
4626
4627
342
  asect->lineno_count = cache_ptr - lineno_cache;
4628
342
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4629
342
  free (native_lineno);
4630
4631
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4632
342
  if (!ordered)
4633
218
    {
4634
      /* Sort the table.  */
4635
218
      alent **func_table;
4636
218
      alent *n_lineno_cache;
4637
4638
      /* Create a table of functions.  */
4639
218
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4640
0
  {
4641
0
    bfd_set_error (bfd_error_file_too_big);
4642
0
    ret = false;
4643
0
  }
4644
218
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4645
218
  {
4646
218
    alent **p = func_table;
4647
218
    unsigned int i;
4648
4649
124k
    for (i = 0; i < asect->lineno_count; i++)
4650
123k
      if (lineno_cache[i].line_number == 0)
4651
63.9k
        *p++ = &lineno_cache[i];
4652
4653
218
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4654
4655
    /* Sort by functions.  */
4656
218
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4657
4658
    /* Create the new sorted table.  */
4659
218
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4660
0
      {
4661
0
        bfd_set_error (bfd_error_file_too_big);
4662
0
        ret = false;
4663
0
      }
4664
218
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4665
218
      {
4666
218
        alent *n_cache_ptr = n_lineno_cache;
4667
4668
64.1k
        for (i = 0; i < nbr_func; i++)
4669
63.9k
    {
4670
63.9k
      coff_symbol_type *sym;
4671
63.9k
      alent *old_ptr = func_table[i];
4672
4673
      /* Update the function entry.  */
4674
63.9k
      sym = (coff_symbol_type *) old_ptr->u.sym;
4675
      /* PR binutils/17512: Point the lineno to where
4676
         this entry will be after the memcpy below.  */
4677
63.9k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4678
      /* Copy the function and line number entries.  */
4679
63.9k
      do
4680
123k
        *n_cache_ptr++ = *old_ptr++;
4681
123k
      while (old_ptr->line_number != 0);
4682
63.9k
    }
4683
4684
218
        memcpy (lineno_cache, n_lineno_cache,
4685
218
          asect->lineno_count * sizeof (alent));
4686
218
      }
4687
0
    else
4688
0
      ret = false;
4689
218
    bfd_release (abfd, func_table);
4690
218
  }
4691
0
      else
4692
0
  ret = false;
4693
218
    }
4694
4695
342
  return ret;
4696
342
}
4697
4698
/* Slurp in the symbol table, converting it to generic form.  Note
4699
   that if coff_relocate_section is defined, the linker will read
4700
   symbols via coff_link_add_symbols, rather than via this routine.  */
4701
4702
static bool
4703
coff_slurp_symbol_table (bfd * abfd)
4704
108k
{
4705
108k
  combined_entry_type *native_symbols;
4706
108k
  coff_symbol_type *cached_area;
4707
108k
  unsigned int *table_ptr;
4708
108k
  unsigned int number_of_symbols = 0;
4709
108k
  bool ret = true;
4710
108k
  size_t amt;
4711
4712
108k
  if (obj_symbols (abfd))
4713
20.2k
    return true;
4714
4715
  /* Read in the symbol table.  */
4716
87.9k
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4717
63.7k
    return false;
4718
4719
  /* Allocate enough room for all the symbols in cached form.  */
4720
24.2k
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4721
24.2k
       sizeof (*cached_area), &amt))
4722
0
    {
4723
0
      bfd_set_error (bfd_error_file_too_big);
4724
0
      return false;
4725
0
    }
4726
24.2k
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4727
24.2k
  if (cached_area == NULL)
4728
0
    return false;
4729
4730
24.2k
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4731
24.2k
       sizeof (*table_ptr), &amt))
4732
0
    {
4733
0
      bfd_set_error (bfd_error_file_too_big);
4734
0
      return false;
4735
0
    }
4736
24.2k
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4737
24.2k
  if (table_ptr == NULL)
4738
0
    return false;
4739
24.2k
  else
4740
24.2k
    {
4741
24.2k
      coff_symbol_type *dst = cached_area;
4742
24.2k
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4743
24.2k
      unsigned int this_index = 0;
4744
4745
5.67M
      while (this_index < last_native_index)
4746
5.65M
  {
4747
5.65M
    combined_entry_type *src = native_symbols + this_index;
4748
5.65M
    table_ptr[this_index] = number_of_symbols;
4749
4750
5.65M
    dst->symbol.the_bfd = abfd;
4751
5.65M
    BFD_ASSERT (src->is_sym);
4752
5.65M
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4753
    /* We use the native name field to point to the cached field.  */
4754
5.65M
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4755
5.65M
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4756
5.65M
                 src->u.syment.n_scnum);
4757
5.65M
    dst->symbol.flags = 0;
4758
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4759
5.65M
    dst->symbol.value = 0;
4760
5.65M
    dst->done_lineno = false;
4761
4762
5.65M
    switch (src->u.syment.n_sclass)
4763
5.65M
      {
4764
162k
      case C_EXT:
4765
169k
      case C_WEAKEXT:
4766
#if defined ARM
4767
4.90k
      case C_THUMBEXT:
4768
4.98k
      case C_THUMBEXTFUNC:
4769
#endif
4770
#ifdef RS6000COFF_C
4771
40.7k
      case C_HIDEXT:
4772
40.7k
#ifndef AIX_WEAK_SUPPORT
4773
44.6k
      case C_AIX_WEAKEXT:
4774
#endif
4775
#endif
4776
44.6k
#ifdef C_SYSTEM
4777
198k
      case C_SYSTEM: /* System Wide variable.  */
4778
198k
#endif
4779
#ifdef COFF_WITH_PE
4780
      /* In PE, 0x68 (104) denotes a section symbol.  */
4781
113k
      case C_SECTION:
4782
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4783
159k
      case C_NT_WEAK:
4784
#endif
4785
159k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4786
159k
    {
4787
216k
    case COFF_SYMBOL_GLOBAL:
4788
216k
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4789
#if defined COFF_WITH_PE
4790
      /* PE sets the symbol to a value relative to the
4791
         start of the section.  */
4792
      dst->symbol.value = src->u.syment.n_value;
4793
#else
4794
      dst->symbol.value = (src->u.syment.n_value
4795
               - dst->symbol.section->vma);
4796
#endif
4797
216k
      if (ISFCN ((src->u.syment.n_type)))
4798
        /* A function ext does not go at the end of a
4799
           file.  */
4800
10.6k
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4801
216k
      break;
4802
4803
16.7k
    case COFF_SYMBOL_COMMON:
4804
16.7k
      dst->symbol.section = bfd_com_section_ptr;
4805
16.7k
      dst->symbol.value = src->u.syment.n_value;
4806
16.7k
      break;
4807
4808
10.9k
    case COFF_SYMBOL_UNDEFINED:
4809
10.9k
      dst->symbol.section = bfd_und_section_ptr;
4810
10.9k
      dst->symbol.value = 0;
4811
10.9k
      break;
4812
4813
472
    case COFF_SYMBOL_PE_SECTION:
4814
472
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4815
472
      dst->symbol.value = 0;
4816
472
      break;
4817
4818
1.81k
    case COFF_SYMBOL_LOCAL:
4819
1.81k
      dst->symbol.flags = BSF_LOCAL;
4820
#if defined COFF_WITH_PE
4821
      /* PE sets the symbol to a value relative to the
4822
         start of the section.  */
4823
      dst->symbol.value = src->u.syment.n_value;
4824
#else
4825
      dst->symbol.value = (src->u.syment.n_value
4826
               - dst->symbol.section->vma);
4827
#endif
4828
1.81k
      if (ISFCN ((src->u.syment.n_type)))
4829
1.12k
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4830
1.81k
      break;
4831
159k
    }
4832
4833
#ifdef RS6000COFF_C
4834
        /* A symbol with a csect entry should not go at the end.  */
4835
48.0k
        if (src->u.syment.n_numaux > 0)
4836
43.5k
    dst->symbol.flags |= BSF_NOT_AT_END;
4837
#endif
4838
4839
#ifdef COFF_WITH_PE
4840
159k
        if (src->u.syment.n_sclass == C_NT_WEAK)
4841
45.3k
    dst->symbol.flags |= BSF_WEAK;
4842
4843
159k
        if (src->u.syment.n_sclass == C_SECTION
4844
159k
      && src->u.syment.n_scnum > 0)
4845
472
    dst->symbol.flags = BSF_LOCAL;
4846
#endif
4847
246k
        if (src->u.syment.n_sclass == C_WEAKEXT
4848
#ifdef RS6000COFF_C
4849
46.9k
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4850
#endif
4851
39.1k
      )
4852
10.7k
    dst->symbol.flags |= BSF_WEAK;
4853
4854
39.1k
        break;
4855
4856
114k
      case C_STAT:  /* Static.  */
4857
#if defined ARM
4858
4.77k
      case C_THUMBSTAT:    /* Thumb static.  */
4859
4.85k
      case C_THUMBLABEL:   /* Thumb label.  */
4860
5.01k
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4861
#endif
4862
#ifdef RS6000COFF_C
4863
6.29k
      case C_DWARF:  /* A label in a dwarf section.  */
4864
11.8k
      case C_INFO:  /* A label in a comment section.  */
4865
#endif
4866
156k
      case C_LABEL:  /* Label.  */
4867
156k
        if (src->u.syment.n_scnum == N_DEBUG)
4868
110
    dst->symbol.flags = BSF_DEBUGGING;
4869
156k
        else
4870
156k
    dst->symbol.flags = BSF_LOCAL;
4871
4872
        /* Base the value as an index from the base of the
4873
     section, if there is one.  */
4874
156k
        if (dst->symbol.section)
4875
156k
    {
4876
#if defined COFF_WITH_PE
4877
      /* PE sets the symbol to a value relative to the
4878
         start of the section.  */
4879
      dst->symbol.value = src->u.syment.n_value;
4880
#else
4881
      dst->symbol.value = (src->u.syment.n_value
4882
               - dst->symbol.section->vma);
4883
#endif
4884
156k
    }
4885
0
        else
4886
0
    dst->symbol.value = src->u.syment.n_value;
4887
156k
        break;
4888
4889
40.1k
      case C_FILE: /* File name.  */
4890
40.1k
        dst->symbol.flags = BSF_FILE;
4891
        /* Fall through.  */
4892
78.6k
      case C_MOS:   /* Member of structure.  */
4893
97.3k
      case C_EOS:   /* End of structure.  */
4894
114k
      case C_REGPARM: /* Register parameter.  */
4895
166k
      case C_REG:   /* register variable.  */
4896
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4897
188k
      case C_TPDEF: /* Type definition.  */
4898
230k
      case C_ARG:
4899
430k
      case C_AUTO: /* Automatic variable.  */
4900
450k
      case C_FIELD: /* Bit field.  */
4901
465k
      case C_ENTAG: /* Enumeration tag.  */
4902
495k
      case C_MOE:   /* Member of enumeration.  */
4903
524k
      case C_MOU:   /* Member of union.  */
4904
549k
      case C_UNTAG: /* Union tag.  */
4905
587k
      case C_STRTAG: /* Structure tag.  */
4906
#ifdef RS6000COFF_C
4907
68.7k
      case C_GSYM:
4908
71.8k
      case C_LSYM:
4909
72.1k
      case C_PSYM:
4910
73.2k
      case C_RSYM:
4911
73.8k
      case C_RPSYM:
4912
74.2k
      case C_STSYM:
4913
75.0k
      case C_TCSYM:
4914
75.8k
      case C_BCOMM:
4915
76.4k
      case C_ECOML:
4916
77.1k
      case C_ECOMM:
4917
77.9k
      case C_DECL:
4918
78.1k
      case C_ENTRY:
4919
78.4k
      case C_FUN:
4920
79.5k
      case C_ESTAT:
4921
#endif
4922
599k
        dst->symbol.flags |= BSF_DEBUGGING;
4923
79.5k
        dst->symbol.value = (src->u.syment.n_value);
4924
79.5k
        break;
4925
4926
#ifdef RS6000COFF_C
4927
6.82k
      case C_BINCL: /* Beginning of include file.  */
4928
9.63k
      case C_EINCL: /* Ending of include file.  */
4929
        /* The value is actually a pointer into the line numbers
4930
     of the file.  We locate the line number entry, and
4931
     set the section to the section which contains it, and
4932
     the value to the index in that section.  */
4933
9.63k
        {
4934
9.63k
    asection *sec;
4935
4936
9.63k
    dst->symbol.flags = BSF_DEBUGGING;
4937
2.66M
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4938
2.65M
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4939
2.65M
          && ((file_ptr) (sec->line_filepos
4940
2.33M
              + sec->lineno_count * bfd_coff_linesz (abfd))
4941
2.33M
        > (file_ptr) src->u.syment.n_value))
4942
4.27k
        break;
4943
9.63k
    if (sec == NULL)
4944
5.35k
      dst->symbol.value = 0;
4945
4.27k
    else
4946
4.27k
      {
4947
4.27k
        dst->symbol.section = sec;
4948
4.27k
        dst->symbol.value = ((src->u.syment.n_value
4949
4.27k
            - sec->line_filepos)
4950
4.27k
           / bfd_coff_linesz (abfd));
4951
4.27k
        src->fix_line = 1;
4952
4.27k
      }
4953
9.63k
        }
4954
9.63k
        break;
4955
4956
1.30k
      case C_BSTAT:
4957
1.30k
        dst->symbol.flags = BSF_DEBUGGING;
4958
4959
1.30k
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4960
1.28k
    dst->symbol.value = 0;
4961
18
        else
4962
18
    {
4963
      /* The value is actually a symbol index.  Save a pointer
4964
         to the symbol instead of the index.  FIXME: This
4965
         should use a union.  */
4966
18
      src->u.syment.n_value
4967
18
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4968
18
      dst->symbol.value = src->u.syment.n_value;
4969
18
      src->fix_value = 1;
4970
18
    }
4971
1.30k
        break;
4972
0
#endif
4973
4974
12.7k
      case C_BLOCK: /* ".bb" or ".eb".  */
4975
96.3k
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4976
119k
      case C_EFCN: /* Physical end of function.  */
4977
#if defined COFF_WITH_PE
4978
        /* PE sets the symbol to a value relative to the start
4979
     of the section.  */
4980
        dst->symbol.value = src->u.syment.n_value;
4981
84.4k
        if (strcmp (dst->symbol.name, ".bf") != 0)
4982
84.4k
    {
4983
      /* PE uses funny values for .ef and .lf; don't
4984
         relocate them.  */
4985
84.4k
      dst->symbol.flags = BSF_DEBUGGING;
4986
84.4k
    }
4987
48
        else
4988
48
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4989
#else
4990
        /* Base the value as an index from the base of the
4991
     section.  */
4992
35.3k
        dst->symbol.flags = BSF_LOCAL;
4993
        dst->symbol.value = (src->u.syment.n_value
4994
           - dst->symbol.section->vma);
4995
#endif
4996
119k
        break;
4997
4998
16.4k
      case C_STATLAB: /* Static load time label.  */
4999
16.4k
        dst->symbol.value = src->u.syment.n_value;
5000
16.4k
        dst->symbol.flags = BSF_GLOBAL;
5001
16.4k
        break;
5002
5003
3.50M
      case C_NULL:
5004
        /* PE DLLs sometimes have zeroed out symbols for some
5005
     reason.  Just ignore them without a warning.  */
5006
3.50M
        if (src->u.syment.n_type == 0
5007
3.50M
      && src->u.syment.n_value == 0
5008
3.50M
      && src->u.syment.n_scnum == 0)
5009
1.21M
    break;
5010
#ifdef RS6000COFF_C
5011
        /* XCOFF specific: deleted entry.  */
5012
150k
        if (src->u.syment.n_value == C_NULL_VALUE)
5013
2
    break;
5014
150k
#endif
5015
        /* Fall through.  */
5016
2.29M
      case C_EXTDEF: /* External definition.  */
5017
2.30M
      case C_ULABEL: /* Undefined label.  */
5018
2.30M
      case C_USTATIC: /* Undefined static.  */
5019
#ifndef COFF_WITH_PE
5020
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5021
         class to represent a section symbol.  */
5022
786k
      case C_LINE: /* line # reformatted as symbol table entry.  */
5023
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5024
801k
      case C_ALIAS: /* Duplicate tag.  */
5025
801k
#endif
5026
        /* New storage classes for TI COFF.  */
5027
#ifdef TICOFF
5028
136k
      case C_UEXT: /* Tentative external definition.  */
5029
#endif
5030
2.33M
      case C_EXTLAB: /* External load time label.  */
5031
3.28M
      default:
5032
3.28M
        _bfd_error_handler
5033
    /* xgettext:c-format */
5034
3.28M
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5035
3.28M
     abfd, src->u.syment.n_sclass,
5036
3.28M
     dst->symbol.section->name, dst->symbol.name);
5037
3.28M
        ret = false;
5038
        /* Fall through.  */
5039
3.28M
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5040
        /* PR 20722: These symbols can also be generated by
5041
     building DLLs with --gc-sections enabled.  */
5042
3.28M
        dst->symbol.flags = BSF_DEBUGGING;
5043
3.28M
        dst->symbol.value = (src->u.syment.n_value);
5044
3.28M
        break;
5045
5.65M
      }
5046
5047
5.65M
    dst->native = src;
5048
5.65M
    dst->symbol.udata.i = 0;
5049
5.65M
    dst->lineno = NULL;
5050
5051
5.65M
    this_index += (src->u.syment.n_numaux) + 1;
5052
5.65M
    dst++;
5053
5.65M
    number_of_symbols++;
5054
5.65M
  }
5055
24.2k
    }
5056
5057
24.2k
  obj_symbols (abfd) = cached_area;
5058
24.2k
  obj_raw_syments (abfd) = native_symbols;
5059
5060
24.2k
  abfd->symcount = number_of_symbols;
5061
24.2k
  obj_convert (abfd) = table_ptr;
5062
  /* Slurp the line tables for each section too.  */
5063
24.2k
  {
5064
24.2k
    asection *p;
5065
5066
24.2k
    p = abfd->sections;
5067
157k
    while (p)
5068
151k
      {
5069
151k
  if (! coff_slurp_line_table (abfd, p))
5070
18.2k
    return false;
5071
132k
  p = p->next;
5072
132k
      }
5073
24.2k
  }
5074
5075
5.95k
  return ret;
5076
24.2k
}
pei-i386.c:coff_slurp_symbol_table
Line
Count
Source
4704
1.46k
{
4705
1.46k
  combined_entry_type *native_symbols;
4706
1.46k
  coff_symbol_type *cached_area;
4707
1.46k
  unsigned int *table_ptr;
4708
1.46k
  unsigned int number_of_symbols = 0;
4709
1.46k
  bool ret = true;
4710
1.46k
  size_t amt;
4711
4712
1.46k
  if (obj_symbols (abfd))
4713
144
    return true;
4714
4715
  /* Read in the symbol table.  */
4716
1.31k
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4717
535
    return false;
4718
4719
  /* Allocate enough room for all the symbols in cached form.  */
4720
782
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4721
782
       sizeof (*cached_area), &amt))
4722
0
    {
4723
0
      bfd_set_error (bfd_error_file_too_big);
4724
0
      return false;
4725
0
    }
4726
782
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4727
782
  if (cached_area == NULL)
4728
0
    return false;
4729
4730
782
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4731
782
       sizeof (*table_ptr), &amt))
4732
0
    {
4733
0
      bfd_set_error (bfd_error_file_too_big);
4734
0
      return false;
4735
0
    }
4736
782
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4737
782
  if (table_ptr == NULL)
4738
0
    return false;
4739
782
  else
4740
782
    {
4741
782
      coff_symbol_type *dst = cached_area;
4742
782
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4743
782
      unsigned int this_index = 0;
4744
4745
92.5k
      while (this_index < last_native_index)
4746
91.7k
  {
4747
91.7k
    combined_entry_type *src = native_symbols + this_index;
4748
91.7k
    table_ptr[this_index] = number_of_symbols;
4749
4750
91.7k
    dst->symbol.the_bfd = abfd;
4751
91.7k
    BFD_ASSERT (src->is_sym);
4752
91.7k
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4753
    /* We use the native name field to point to the cached field.  */
4754
91.7k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4755
91.7k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4756
91.7k
                 src->u.syment.n_scnum);
4757
91.7k
    dst->symbol.flags = 0;
4758
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4759
91.7k
    dst->symbol.value = 0;
4760
91.7k
    dst->done_lineno = false;
4761
4762
91.7k
    switch (src->u.syment.n_sclass)
4763
91.7k
      {
4764
1.56k
      case C_EXT:
4765
1.68k
      case C_WEAKEXT:
4766
#if defined ARM
4767
      case C_THUMBEXT:
4768
      case C_THUMBEXTFUNC:
4769
#endif
4770
#ifdef RS6000COFF_C
4771
      case C_HIDEXT:
4772
#ifndef AIX_WEAK_SUPPORT
4773
      case C_AIX_WEAKEXT:
4774
#endif
4775
#endif
4776
1.68k
#ifdef C_SYSTEM
4777
1.88k
      case C_SYSTEM: /* System Wide variable.  */
4778
1.88k
#endif
4779
1.88k
#ifdef COFF_WITH_PE
4780
      /* In PE, 0x68 (104) denotes a section symbol.  */
4781
1.91k
      case C_SECTION:
4782
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4783
2.91k
      case C_NT_WEAK:
4784
2.91k
#endif
4785
2.91k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4786
2.91k
    {
4787
2.47k
    case COFF_SYMBOL_GLOBAL:
4788
2.47k
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4789
2.47k
#if defined COFF_WITH_PE
4790
      /* PE sets the symbol to a value relative to the
4791
         start of the section.  */
4792
2.47k
      dst->symbol.value = src->u.syment.n_value;
4793
#else
4794
      dst->symbol.value = (src->u.syment.n_value
4795
               - dst->symbol.section->vma);
4796
#endif
4797
2.47k
      if (ISFCN ((src->u.syment.n_type)))
4798
        /* A function ext does not go at the end of a
4799
           file.  */
4800
74
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4801
2.47k
      break;
4802
4803
282
    case COFF_SYMBOL_COMMON:
4804
282
      dst->symbol.section = bfd_com_section_ptr;
4805
282
      dst->symbol.value = src->u.syment.n_value;
4806
282
      break;
4807
4808
165
    case COFF_SYMBOL_UNDEFINED:
4809
165
      dst->symbol.section = bfd_und_section_ptr;
4810
165
      dst->symbol.value = 0;
4811
165
      break;
4812
4813
0
    case COFF_SYMBOL_PE_SECTION:
4814
0
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4815
0
      dst->symbol.value = 0;
4816
0
      break;
4817
4818
0
    case COFF_SYMBOL_LOCAL:
4819
0
      dst->symbol.flags = BSF_LOCAL;
4820
0
#if defined COFF_WITH_PE
4821
      /* PE sets the symbol to a value relative to the
4822
         start of the section.  */
4823
0
      dst->symbol.value = src->u.syment.n_value;
4824
#else
4825
      dst->symbol.value = (src->u.syment.n_value
4826
               - dst->symbol.section->vma);
4827
#endif
4828
0
      if (ISFCN ((src->u.syment.n_type)))
4829
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4830
0
      break;
4831
2.91k
    }
4832
4833
#ifdef RS6000COFF_C
4834
        /* A symbol with a csect entry should not go at the end.  */
4835
        if (src->u.syment.n_numaux > 0)
4836
    dst->symbol.flags |= BSF_NOT_AT_END;
4837
#endif
4838
4839
2.91k
#ifdef COFF_WITH_PE
4840
2.91k
        if (src->u.syment.n_sclass == C_NT_WEAK)
4841
999
    dst->symbol.flags |= BSF_WEAK;
4842
4843
2.91k
        if (src->u.syment.n_sclass == C_SECTION
4844
2.91k
      && src->u.syment.n_scnum > 0)
4845
0
    dst->symbol.flags = BSF_LOCAL;
4846
2.91k
#endif
4847
2.91k
        if (src->u.syment.n_sclass == C_WEAKEXT
4848
#ifdef RS6000COFF_C
4849
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4850
#endif
4851
2.91k
      )
4852
119
    dst->symbol.flags |= BSF_WEAK;
4853
4854
2.91k
        break;
4855
4856
2.05k
      case C_STAT:  /* Static.  */
4857
#if defined ARM
4858
      case C_THUMBSTAT:    /* Thumb static.  */
4859
      case C_THUMBLABEL:   /* Thumb label.  */
4860
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4861
#endif
4862
#ifdef RS6000COFF_C
4863
      case C_DWARF:  /* A label in a dwarf section.  */
4864
      case C_INFO:   /* A label in a comment section.  */
4865
#endif
4866
2.54k
      case C_LABEL:  /* Label.  */
4867
2.54k
        if (src->u.syment.n_scnum == N_DEBUG)
4868
2
    dst->symbol.flags = BSF_DEBUGGING;
4869
2.54k
        else
4870
2.54k
    dst->symbol.flags = BSF_LOCAL;
4871
4872
        /* Base the value as an index from the base of the
4873
     section, if there is one.  */
4874
2.54k
        if (dst->symbol.section)
4875
2.54k
    {
4876
2.54k
#if defined COFF_WITH_PE
4877
      /* PE sets the symbol to a value relative to the
4878
         start of the section.  */
4879
2.54k
      dst->symbol.value = src->u.syment.n_value;
4880
#else
4881
      dst->symbol.value = (src->u.syment.n_value
4882
               - dst->symbol.section->vma);
4883
#endif
4884
2.54k
    }
4885
0
        else
4886
0
    dst->symbol.value = src->u.syment.n_value;
4887
2.54k
        break;
4888
4889
581
      case C_FILE: /* File name.  */
4890
581
        dst->symbol.flags = BSF_FILE;
4891
        /* Fall through.  */
4892
1.80k
      case C_MOS:   /* Member of structure.  */
4893
2.13k
      case C_EOS:   /* End of structure.  */
4894
2.45k
      case C_REGPARM: /* Register parameter.  */
4895
3.18k
      case C_REG:   /* register variable.  */
4896
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4897
3.47k
      case C_TPDEF: /* Type definition.  */
4898
4.29k
      case C_ARG:
4899
7.91k
      case C_AUTO: /* Automatic variable.  */
4900
8.36k
      case C_FIELD: /* Bit field.  */
4901
8.62k
      case C_ENTAG: /* Enumeration tag.  */
4902
9.11k
      case C_MOE:   /* Member of enumeration.  */
4903
9.32k
      case C_MOU:   /* Member of union.  */
4904
9.60k
      case C_UNTAG: /* Union tag.  */
4905
10.3k
      case C_STRTAG: /* Structure tag.  */
4906
#ifdef RS6000COFF_C
4907
      case C_GSYM:
4908
      case C_LSYM:
4909
      case C_PSYM:
4910
      case C_RSYM:
4911
      case C_RPSYM:
4912
      case C_STSYM:
4913
      case C_TCSYM:
4914
      case C_BCOMM:
4915
      case C_ECOML:
4916
      case C_ECOMM:
4917
      case C_DECL:
4918
      case C_ENTRY:
4919
      case C_FUN:
4920
      case C_ESTAT:
4921
#endif
4922
10.3k
        dst->symbol.flags |= BSF_DEBUGGING;
4923
10.3k
        dst->symbol.value = (src->u.syment.n_value);
4924
10.3k
        break;
4925
4926
#ifdef RS6000COFF_C
4927
      case C_BINCL: /* Beginning of include file.  */
4928
      case C_EINCL: /* Ending of include file.  */
4929
        /* The value is actually a pointer into the line numbers
4930
     of the file.  We locate the line number entry, and
4931
     set the section to the section which contains it, and
4932
     the value to the index in that section.  */
4933
        {
4934
    asection *sec;
4935
4936
    dst->symbol.flags = BSF_DEBUGGING;
4937
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4938
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4939
          && ((file_ptr) (sec->line_filepos
4940
              + sec->lineno_count * bfd_coff_linesz (abfd))
4941
        > (file_ptr) src->u.syment.n_value))
4942
        break;
4943
    if (sec == NULL)
4944
      dst->symbol.value = 0;
4945
    else
4946
      {
4947
        dst->symbol.section = sec;
4948
        dst->symbol.value = ((src->u.syment.n_value
4949
            - sec->line_filepos)
4950
           / bfd_coff_linesz (abfd));
4951
        src->fix_line = 1;
4952
      }
4953
        }
4954
        break;
4955
4956
      case C_BSTAT:
4957
        dst->symbol.flags = BSF_DEBUGGING;
4958
4959
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4960
    dst->symbol.value = 0;
4961
        else
4962
    {
4963
      /* The value is actually a symbol index.  Save a pointer
4964
         to the symbol instead of the index.  FIXME: This
4965
         should use a union.  */
4966
      src->u.syment.n_value
4967
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4968
      dst->symbol.value = src->u.syment.n_value;
4969
      src->fix_value = 1;
4970
    }
4971
        break;
4972
#endif
4973
4974
334
      case C_BLOCK: /* ".bb" or ".eb".  */
4975
1.88k
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4976
2.36k
      case C_EFCN: /* Physical end of function.  */
4977
2.36k
#if defined COFF_WITH_PE
4978
        /* PE sets the symbol to a value relative to the start
4979
     of the section.  */
4980
2.36k
        dst->symbol.value = src->u.syment.n_value;
4981
2.36k
        if (strcmp (dst->symbol.name, ".bf") != 0)
4982
2.36k
    {
4983
      /* PE uses funny values for .ef and .lf; don't
4984
         relocate them.  */
4985
2.36k
      dst->symbol.flags = BSF_DEBUGGING;
4986
2.36k
    }
4987
1
        else
4988
1
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4989
#else
4990
        /* Base the value as an index from the base of the
4991
     section.  */
4992
        dst->symbol.flags = BSF_LOCAL;
4993
        dst->symbol.value = (src->u.syment.n_value
4994
           - dst->symbol.section->vma);
4995
#endif
4996
2.36k
        break;
4997
4998
348
      case C_STATLAB: /* Static load time label.  */
4999
348
        dst->symbol.value = src->u.syment.n_value;
5000
348
        dst->symbol.flags = BSF_GLOBAL;
5001
348
        break;
5002
5003
53.8k
      case C_NULL:
5004
        /* PE DLLs sometimes have zeroed out symbols for some
5005
     reason.  Just ignore them without a warning.  */
5006
53.8k
        if (src->u.syment.n_type == 0
5007
53.8k
      && src->u.syment.n_value == 0
5008
53.8k
      && src->u.syment.n_scnum == 0)
5009
12.4k
    break;
5010
#ifdef RS6000COFF_C
5011
        /* XCOFF specific: deleted entry.  */
5012
        if (src->u.syment.n_value == C_NULL_VALUE)
5013
    break;
5014
#endif
5015
        /* Fall through.  */
5016
41.6k
      case C_EXTDEF: /* External definition.  */
5017
41.9k
      case C_ULABEL: /* Undefined label.  */
5018
42.0k
      case C_USTATIC: /* Undefined static.  */
5019
#ifndef COFF_WITH_PE
5020
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5021
         class to represent a section symbol.  */
5022
      case C_LINE:  /* line # reformatted as symbol table entry.  */
5023
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5024
      case C_ALIAS: /* Duplicate tag.  */
5025
#endif
5026
        /* New storage classes for TI COFF.  */
5027
#ifdef TICOFF
5028
      case C_UEXT:  /* Tentative external definition.  */
5029
#endif
5030
42.0k
      case C_EXTLAB: /* External load time label.  */
5031
60.6k
      default:
5032
60.6k
        _bfd_error_handler
5033
    /* xgettext:c-format */
5034
60.6k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5035
60.6k
     abfd, src->u.syment.n_sclass,
5036
60.6k
     dst->symbol.section->name, dst->symbol.name);
5037
60.6k
        ret = false;
5038
        /* Fall through.  */
5039
60.7k
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5040
        /* PR 20722: These symbols can also be generated by
5041
     building DLLs with --gc-sections enabled.  */
5042
60.7k
        dst->symbol.flags = BSF_DEBUGGING;
5043
60.7k
        dst->symbol.value = (src->u.syment.n_value);
5044
60.7k
        break;
5045
91.7k
      }
5046
5047
91.7k
    dst->native = src;
5048
91.7k
    dst->symbol.udata.i = 0;
5049
91.7k
    dst->lineno = NULL;
5050
5051
91.7k
    this_index += (src->u.syment.n_numaux) + 1;
5052
91.7k
    dst++;
5053
91.7k
    number_of_symbols++;
5054
91.7k
  }
5055
782
    }
5056
5057
782
  obj_symbols (abfd) = cached_area;
5058
782
  obj_raw_syments (abfd) = native_symbols;
5059
5060
782
  abfd->symcount = number_of_symbols;
5061
782
  obj_convert (abfd) = table_ptr;
5062
  /* Slurp the line tables for each section too.  */
5063
782
  {
5064
782
    asection *p;
5065
5066
782
    p = abfd->sections;
5067
1.33k
    while (p)
5068
1.26k
      {
5069
1.26k
  if (! coff_slurp_line_table (abfd, p))
5070
721
    return false;
5071
548
  p = p->next;
5072
548
      }
5073
782
  }
5074
5075
61
  return ret;
5076
782
}
pe-x86_64.c:coff_slurp_symbol_table
Line
Count
Source
4704
3.23k
{
4705
3.23k
  combined_entry_type *native_symbols;
4706
3.23k
  coff_symbol_type *cached_area;
4707
3.23k
  unsigned int *table_ptr;
4708
3.23k
  unsigned int number_of_symbols = 0;
4709
3.23k
  bool ret = true;
4710
3.23k
  size_t amt;
4711
4712
3.23k
  if (obj_symbols (abfd))
4713
737
    return true;
4714
4715
  /* Read in the symbol table.  */
4716
2.50k
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4717
1.09k
    return false;
4718
4719
  /* Allocate enough room for all the symbols in cached form.  */
4720
1.40k
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4721
1.40k
       sizeof (*cached_area), &amt))
4722
0
    {
4723
0
      bfd_set_error (bfd_error_file_too_big);
4724
0
      return false;
4725
0
    }
4726
1.40k
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4727
1.40k
  if (cached_area == NULL)
4728
0
    return false;
4729
4730
1.40k
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4731
1.40k
       sizeof (*table_ptr), &amt))
4732
0
    {
4733
0
      bfd_set_error (bfd_error_file_too_big);
4734
0
      return false;
4735
0
    }
4736
1.40k
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4737
1.40k
  if (table_ptr == NULL)
4738
0
    return false;
4739
1.40k
  else
4740
1.40k
    {
4741
1.40k
      coff_symbol_type *dst = cached_area;
4742
1.40k
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4743
1.40k
      unsigned int this_index = 0;
4744
4745
266k
      while (this_index < last_native_index)
4746
265k
  {
4747
265k
    combined_entry_type *src = native_symbols + this_index;
4748
265k
    table_ptr[this_index] = number_of_symbols;
4749
4750
265k
    dst->symbol.the_bfd = abfd;
4751
265k
    BFD_ASSERT (src->is_sym);
4752
265k
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4753
    /* We use the native name field to point to the cached field.  */
4754
265k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4755
265k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4756
265k
                 src->u.syment.n_scnum);
4757
265k
    dst->symbol.flags = 0;
4758
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4759
265k
    dst->symbol.value = 0;
4760
265k
    dst->done_lineno = false;
4761
4762
265k
    switch (src->u.syment.n_sclass)
4763
265k
      {
4764
4.05k
      case C_EXT:
4765
4.37k
      case C_WEAKEXT:
4766
#if defined ARM
4767
      case C_THUMBEXT:
4768
      case C_THUMBEXTFUNC:
4769
#endif
4770
#ifdef RS6000COFF_C
4771
      case C_HIDEXT:
4772
#ifndef AIX_WEAK_SUPPORT
4773
      case C_AIX_WEAKEXT:
4774
#endif
4775
#endif
4776
4.37k
#ifdef C_SYSTEM
4777
5.10k
      case C_SYSTEM: /* System Wide variable.  */
4778
5.10k
#endif
4779
5.10k
#ifdef COFF_WITH_PE
4780
      /* In PE, 0x68 (104) denotes a section symbol.  */
4781
5.74k
      case C_SECTION:
4782
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4783
8.47k
      case C_NT_WEAK:
4784
8.47k
#endif
4785
8.47k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4786
8.47k
    {
4787
6.96k
    case COFF_SYMBOL_GLOBAL:
4788
6.96k
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4789
6.96k
#if defined COFF_WITH_PE
4790
      /* PE sets the symbol to a value relative to the
4791
         start of the section.  */
4792
6.96k
      dst->symbol.value = src->u.syment.n_value;
4793
#else
4794
      dst->symbol.value = (src->u.syment.n_value
4795
               - dst->symbol.section->vma);
4796
#endif
4797
6.96k
      if (ISFCN ((src->u.syment.n_type)))
4798
        /* A function ext does not go at the end of a
4799
           file.  */
4800
130
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4801
6.96k
      break;
4802
4803
651
    case COFF_SYMBOL_COMMON:
4804
651
      dst->symbol.section = bfd_com_section_ptr;
4805
651
      dst->symbol.value = src->u.syment.n_value;
4806
651
      break;
4807
4808
386
    case COFF_SYMBOL_UNDEFINED:
4809
386
      dst->symbol.section = bfd_und_section_ptr;
4810
386
      dst->symbol.value = 0;
4811
386
      break;
4812
4813
472
    case COFF_SYMBOL_PE_SECTION:
4814
472
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4815
472
      dst->symbol.value = 0;
4816
472
      break;
4817
4818
0
    case COFF_SYMBOL_LOCAL:
4819
0
      dst->symbol.flags = BSF_LOCAL;
4820
0
#if defined COFF_WITH_PE
4821
      /* PE sets the symbol to a value relative to the
4822
         start of the section.  */
4823
0
      dst->symbol.value = src->u.syment.n_value;
4824
#else
4825
      dst->symbol.value = (src->u.syment.n_value
4826
               - dst->symbol.section->vma);
4827
#endif
4828
0
      if (ISFCN ((src->u.syment.n_type)))
4829
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4830
0
      break;
4831
8.47k
    }
4832
4833
#ifdef RS6000COFF_C
4834
        /* A symbol with a csect entry should not go at the end.  */
4835
        if (src->u.syment.n_numaux > 0)
4836
    dst->symbol.flags |= BSF_NOT_AT_END;
4837
#endif
4838
4839
8.47k
#ifdef COFF_WITH_PE
4840
8.47k
        if (src->u.syment.n_sclass == C_NT_WEAK)
4841
2.73k
    dst->symbol.flags |= BSF_WEAK;
4842
4843
8.47k
        if (src->u.syment.n_sclass == C_SECTION
4844
8.47k
      && src->u.syment.n_scnum > 0)
4845
472
    dst->symbol.flags = BSF_LOCAL;
4846
8.47k
#endif
4847
8.47k
        if (src->u.syment.n_sclass == C_WEAKEXT
4848
#ifdef RS6000COFF_C
4849
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4850
#endif
4851
8.47k
      )
4852
313
    dst->symbol.flags |= BSF_WEAK;
4853
4854
8.47k
        break;
4855
4856
2.64k
      case C_STAT:  /* Static.  */
4857
#if defined ARM
4858
      case C_THUMBSTAT:    /* Thumb static.  */
4859
      case C_THUMBLABEL:   /* Thumb label.  */
4860
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4861
#endif
4862
#ifdef RS6000COFF_C
4863
      case C_DWARF:  /* A label in a dwarf section.  */
4864
      case C_INFO:   /* A label in a comment section.  */
4865
#endif
4866
3.42k
      case C_LABEL:  /* Label.  */
4867
3.42k
        if (src->u.syment.n_scnum == N_DEBUG)
4868
11
    dst->symbol.flags = BSF_DEBUGGING;
4869
3.41k
        else
4870
3.41k
    dst->symbol.flags = BSF_LOCAL;
4871
4872
        /* Base the value as an index from the base of the
4873
     section, if there is one.  */
4874
3.42k
        if (dst->symbol.section)
4875
3.42k
    {
4876
3.42k
#if defined COFF_WITH_PE
4877
      /* PE sets the symbol to a value relative to the
4878
         start of the section.  */
4879
3.42k
      dst->symbol.value = src->u.syment.n_value;
4880
#else
4881
      dst->symbol.value = (src->u.syment.n_value
4882
               - dst->symbol.section->vma);
4883
#endif
4884
3.42k
    }
4885
0
        else
4886
0
    dst->symbol.value = src->u.syment.n_value;
4887
3.42k
        break;
4888
4889
2.06k
      case C_FILE: /* File name.  */
4890
2.06k
        dst->symbol.flags = BSF_FILE;
4891
        /* Fall through.  */
4892
4.49k
      case C_MOS:   /* Member of structure.  */
4893
5.10k
      case C_EOS:   /* End of structure.  */
4894
5.92k
      case C_REGPARM: /* Register parameter.  */
4895
6.79k
      case C_REG:   /* register variable.  */
4896
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4897
7.33k
      case C_TPDEF: /* Type definition.  */
4898
8.66k
      case C_ARG:
4899
14.5k
      case C_AUTO: /* Automatic variable.  */
4900
16.1k
      case C_FIELD: /* Bit field.  */
4901
16.8k
      case C_ENTAG: /* Enumeration tag.  */
4902
18.4k
      case C_MOE:   /* Member of enumeration.  */
4903
19.0k
      case C_MOU:   /* Member of union.  */
4904
20.1k
      case C_UNTAG: /* Union tag.  */
4905
21.4k
      case C_STRTAG: /* Structure tag.  */
4906
#ifdef RS6000COFF_C
4907
      case C_GSYM:
4908
      case C_LSYM:
4909
      case C_PSYM:
4910
      case C_RSYM:
4911
      case C_RPSYM:
4912
      case C_STSYM:
4913
      case C_TCSYM:
4914
      case C_BCOMM:
4915
      case C_ECOML:
4916
      case C_ECOMM:
4917
      case C_DECL:
4918
      case C_ENTRY:
4919
      case C_FUN:
4920
      case C_ESTAT:
4921
#endif
4922
21.4k
        dst->symbol.flags |= BSF_DEBUGGING;
4923
21.4k
        dst->symbol.value = (src->u.syment.n_value);
4924
21.4k
        break;
4925
4926
#ifdef RS6000COFF_C
4927
      case C_BINCL: /* Beginning of include file.  */
4928
      case C_EINCL: /* Ending of include file.  */
4929
        /* The value is actually a pointer into the line numbers
4930
     of the file.  We locate the line number entry, and
4931
     set the section to the section which contains it, and
4932
     the value to the index in that section.  */
4933
        {
4934
    asection *sec;
4935
4936
    dst->symbol.flags = BSF_DEBUGGING;
4937
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4938
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4939
          && ((file_ptr) (sec->line_filepos
4940
              + sec->lineno_count * bfd_coff_linesz (abfd))
4941
        > (file_ptr) src->u.syment.n_value))
4942
        break;
4943
    if (sec == NULL)
4944
      dst->symbol.value = 0;
4945
    else
4946
      {
4947
        dst->symbol.section = sec;
4948
        dst->symbol.value = ((src->u.syment.n_value
4949
            - sec->line_filepos)
4950
           / bfd_coff_linesz (abfd));
4951
        src->fix_line = 1;
4952
      }
4953
        }
4954
        break;
4955
4956
      case C_BSTAT:
4957
        dst->symbol.flags = BSF_DEBUGGING;
4958
4959
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4960
    dst->symbol.value = 0;
4961
        else
4962
    {
4963
      /* The value is actually a symbol index.  Save a pointer
4964
         to the symbol instead of the index.  FIXME: This
4965
         should use a union.  */
4966
      src->u.syment.n_value
4967
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4968
      dst->symbol.value = src->u.syment.n_value;
4969
      src->fix_value = 1;
4970
    }
4971
        break;
4972
#endif
4973
4974
634
      case C_BLOCK: /* ".bb" or ".eb".  */
4975
4.73k
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4976
5.84k
      case C_EFCN: /* Physical end of function.  */
4977
5.84k
#if defined COFF_WITH_PE
4978
        /* PE sets the symbol to a value relative to the start
4979
     of the section.  */
4980
5.84k
        dst->symbol.value = src->u.syment.n_value;
4981
5.84k
        if (strcmp (dst->symbol.name, ".bf") != 0)
4982
5.84k
    {
4983
      /* PE uses funny values for .ef and .lf; don't
4984
         relocate them.  */
4985
5.84k
      dst->symbol.flags = BSF_DEBUGGING;
4986
5.84k
    }
4987
2
        else
4988
2
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4989
#else
4990
        /* Base the value as an index from the base of the
4991
     section.  */
4992
        dst->symbol.flags = BSF_LOCAL;
4993
        dst->symbol.value = (src->u.syment.n_value
4994
           - dst->symbol.section->vma);
4995
#endif
4996
5.84k
        break;
4997
4998
586
      case C_STATLAB: /* Static load time label.  */
4999
586
        dst->symbol.value = src->u.syment.n_value;
5000
586
        dst->symbol.flags = BSF_GLOBAL;
5001
586
        break;
5002
5003
180k
      case C_NULL:
5004
        /* PE DLLs sometimes have zeroed out symbols for some
5005
     reason.  Just ignore them without a warning.  */
5006
180k
        if (src->u.syment.n_type == 0
5007
180k
      && src->u.syment.n_value == 0
5008
180k
      && src->u.syment.n_scnum == 0)
5009
77.4k
    break;
5010
#ifdef RS6000COFF_C
5011
        /* XCOFF specific: deleted entry.  */
5012
        if (src->u.syment.n_value == C_NULL_VALUE)
5013
    break;
5014
#endif
5015
        /* Fall through.  */
5016
103k
      case C_EXTDEF: /* External definition.  */
5017
103k
      case C_ULABEL: /* Undefined label.  */
5018
103k
      case C_USTATIC: /* Undefined static.  */
5019
#ifndef COFF_WITH_PE
5020
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5021
         class to represent a section symbol.  */
5022
      case C_LINE:  /* line # reformatted as symbol table entry.  */
5023
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5024
      case C_ALIAS: /* Duplicate tag.  */
5025
#endif
5026
        /* New storage classes for TI COFF.  */
5027
#ifdef TICOFF
5028
      case C_UEXT:  /* Tentative external definition.  */
5029
#endif
5030
103k
      case C_EXTLAB: /* External load time label.  */
5031
147k
      default:
5032
147k
        _bfd_error_handler
5033
    /* xgettext:c-format */
5034
147k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5035
147k
     abfd, src->u.syment.n_sclass,
5036
147k
     dst->symbol.section->name, dst->symbol.name);
5037
147k
        ret = false;
5038
        /* Fall through.  */
5039
147k
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5040
        /* PR 20722: These symbols can also be generated by
5041
     building DLLs with --gc-sections enabled.  */
5042
147k
        dst->symbol.flags = BSF_DEBUGGING;
5043
147k
        dst->symbol.value = (src->u.syment.n_value);
5044
147k
        break;
5045
265k
      }
5046
5047
265k
    dst->native = src;
5048
265k
    dst->symbol.udata.i = 0;
5049
265k
    dst->lineno = NULL;
5050
5051
265k
    this_index += (src->u.syment.n_numaux) + 1;
5052
265k
    dst++;
5053
265k
    number_of_symbols++;
5054
265k
  }
5055
1.40k
    }
5056
5057
1.40k
  obj_symbols (abfd) = cached_area;
5058
1.40k
  obj_raw_syments (abfd) = native_symbols;
5059
5060
1.40k
  abfd->symcount = number_of_symbols;
5061
1.40k
  obj_convert (abfd) = table_ptr;
5062
  /* Slurp the line tables for each section too.  */
5063
1.40k
  {
5064
1.40k
    asection *p;
5065
5066
1.40k
    p = abfd->sections;
5067
30.5k
    while (p)
5068
30.0k
      {
5069
30.0k
  if (! coff_slurp_line_table (abfd, p))
5070
860
    return false;
5071
29.1k
  p = p->next;
5072
29.1k
      }
5073
1.40k
  }
5074
5075
545
  return ret;
5076
1.40k
}
pei-x86_64.c:coff_slurp_symbol_table
Line
Count
Source
4704
2.09k
{
4705
2.09k
  combined_entry_type *native_symbols;
4706
2.09k
  coff_symbol_type *cached_area;
4707
2.09k
  unsigned int *table_ptr;
4708
2.09k
  unsigned int number_of_symbols = 0;
4709
2.09k
  bool ret = true;
4710
2.09k
  size_t amt;
4711
4712
2.09k
  if (obj_symbols (abfd))
4713
478
    return true;
4714
4715
  /* Read in the symbol table.  */
4716
1.61k
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4717
631
    return false;
4718
4719
  /* Allocate enough room for all the symbols in cached form.  */
4720
982
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4721
982
       sizeof (*cached_area), &amt))
4722
0
    {
4723
0
      bfd_set_error (bfd_error_file_too_big);
4724
0
      return false;
4725
0
    }
4726
982
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4727
982
  if (cached_area == NULL)
4728
0
    return false;
4729
4730
982
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4731
982
       sizeof (*table_ptr), &amt))
4732
0
    {
4733
0
      bfd_set_error (bfd_error_file_too_big);
4734
0
      return false;
4735
0
    }
4736
982
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4737
982
  if (table_ptr == NULL)
4738
0
    return false;
4739
982
  else
4740
982
    {
4741
982
      coff_symbol_type *dst = cached_area;
4742
982
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4743
982
      unsigned int this_index = 0;
4744
4745
166k
      while (this_index < last_native_index)
4746
165k
  {
4747
165k
    combined_entry_type *src = native_symbols + this_index;
4748
165k
    table_ptr[this_index] = number_of_symbols;
4749
4750
165k
    dst->symbol.the_bfd = abfd;
4751
165k
    BFD_ASSERT (src->is_sym);
4752
165k
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4753
    /* We use the native name field to point to the cached field.  */
4754
165k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4755
165k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4756
165k
                 src->u.syment.n_scnum);
4757
165k
    dst->symbol.flags = 0;
4758
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4759
165k
    dst->symbol.value = 0;
4760
165k
    dst->done_lineno = false;
4761
4762
165k
    switch (src->u.syment.n_sclass)
4763
165k
      {
4764
24.6k
      case C_EXT:
4765
24.6k
      case C_WEAKEXT:
4766
#if defined ARM
4767
      case C_THUMBEXT:
4768
      case C_THUMBEXTFUNC:
4769
#endif
4770
#ifdef RS6000COFF_C
4771
      case C_HIDEXT:
4772
#ifndef AIX_WEAK_SUPPORT
4773
      case C_AIX_WEAKEXT:
4774
#endif
4775
#endif
4776
24.6k
#ifdef C_SYSTEM
4777
25.0k
      case C_SYSTEM: /* System Wide variable.  */
4778
25.0k
#endif
4779
25.0k
#ifdef COFF_WITH_PE
4780
      /* In PE, 0x68 (104) denotes a section symbol.  */
4781
25.0k
      case C_SECTION:
4782
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4783
26.4k
      case C_NT_WEAK:
4784
26.4k
#endif
4785
26.4k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4786
26.4k
    {
4787
22.2k
    case COFF_SYMBOL_GLOBAL:
4788
22.2k
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4789
22.2k
#if defined COFF_WITH_PE
4790
      /* PE sets the symbol to a value relative to the
4791
         start of the section.  */
4792
22.2k
      dst->symbol.value = src->u.syment.n_value;
4793
#else
4794
      dst->symbol.value = (src->u.syment.n_value
4795
               - dst->symbol.section->vma);
4796
#endif
4797
22.2k
      if (ISFCN ((src->u.syment.n_type)))
4798
        /* A function ext does not go at the end of a
4799
           file.  */
4800
4.29k
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4801
22.2k
      break;
4802
4803
332
    case COFF_SYMBOL_COMMON:
4804
332
      dst->symbol.section = bfd_com_section_ptr;
4805
332
      dst->symbol.value = src->u.syment.n_value;
4806
332
      break;
4807
4808
3.86k
    case COFF_SYMBOL_UNDEFINED:
4809
3.86k
      dst->symbol.section = bfd_und_section_ptr;
4810
3.86k
      dst->symbol.value = 0;
4811
3.86k
      break;
4812
4813
0
    case COFF_SYMBOL_PE_SECTION:
4814
0
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4815
0
      dst->symbol.value = 0;
4816
0
      break;
4817
4818
0
    case COFF_SYMBOL_LOCAL:
4819
0
      dst->symbol.flags = BSF_LOCAL;
4820
0
#if defined COFF_WITH_PE
4821
      /* PE sets the symbol to a value relative to the
4822
         start of the section.  */
4823
0
      dst->symbol.value = src->u.syment.n_value;
4824
#else
4825
      dst->symbol.value = (src->u.syment.n_value
4826
               - dst->symbol.section->vma);
4827
#endif
4828
0
      if (ISFCN ((src->u.syment.n_type)))
4829
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4830
0
      break;
4831
26.4k
    }
4832
4833
#ifdef RS6000COFF_C
4834
        /* A symbol with a csect entry should not go at the end.  */
4835
        if (src->u.syment.n_numaux > 0)
4836
    dst->symbol.flags |= BSF_NOT_AT_END;
4837
#endif
4838
4839
26.4k
#ifdef COFF_WITH_PE
4840
26.4k
        if (src->u.syment.n_sclass == C_NT_WEAK)
4841
1.42k
    dst->symbol.flags |= BSF_WEAK;
4842
4843
26.4k
        if (src->u.syment.n_sclass == C_SECTION
4844
26.4k
      && src->u.syment.n_scnum > 0)
4845
0
    dst->symbol.flags = BSF_LOCAL;
4846
26.4k
#endif
4847
26.4k
        if (src->u.syment.n_sclass == C_WEAKEXT
4848
#ifdef RS6000COFF_C
4849
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4850
#endif
4851
26.4k
      )
4852
75
    dst->symbol.flags |= BSF_WEAK;
4853
4854
26.4k
        break;
4855
4856
42.6k
      case C_STAT:  /* Static.  */
4857
#if defined ARM
4858
      case C_THUMBSTAT:    /* Thumb static.  */
4859
      case C_THUMBLABEL:   /* Thumb label.  */
4860
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4861
#endif
4862
#ifdef RS6000COFF_C
4863
      case C_DWARF:  /* A label in a dwarf section.  */
4864
      case C_INFO:   /* A label in a comment section.  */
4865
#endif
4866
43.0k
      case C_LABEL:  /* Label.  */
4867
43.0k
        if (src->u.syment.n_scnum == N_DEBUG)
4868
2
    dst->symbol.flags = BSF_DEBUGGING;
4869
43.0k
        else
4870
43.0k
    dst->symbol.flags = BSF_LOCAL;
4871
4872
        /* Base the value as an index from the base of the
4873
     section, if there is one.  */
4874
43.0k
        if (dst->symbol.section)
4875
43.0k
    {
4876
43.0k
#if defined COFF_WITH_PE
4877
      /* PE sets the symbol to a value relative to the
4878
         start of the section.  */
4879
43.0k
      dst->symbol.value = src->u.syment.n_value;
4880
#else
4881
      dst->symbol.value = (src->u.syment.n_value
4882
               - dst->symbol.section->vma);
4883
#endif
4884
43.0k
    }
4885
0
        else
4886
0
    dst->symbol.value = src->u.syment.n_value;
4887
43.0k
        break;
4888
4889
4.50k
      case C_FILE: /* File name.  */
4890
4.50k
        dst->symbol.flags = BSF_FILE;
4891
        /* Fall through.  */
4892
4.91k
      case C_MOS:   /* Member of structure.  */
4893
5.29k
      case C_EOS:   /* End of structure.  */
4894
5.58k
      case C_REGPARM: /* Register parameter.  */
4895
6.41k
      case C_REG:   /* register variable.  */
4896
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4897
6.65k
      case C_TPDEF: /* Type definition.  */
4898
7.26k
      case C_ARG:
4899
11.3k
      case C_AUTO: /* Automatic variable.  */
4900
11.7k
      case C_FIELD: /* Bit field.  */
4901
12.2k
      case C_ENTAG: /* Enumeration tag.  */
4902
12.6k
      case C_MOE:   /* Member of enumeration.  */
4903
13.5k
      case C_MOU:   /* Member of union.  */
4904
13.8k
      case C_UNTAG: /* Union tag.  */
4905
14.5k
      case C_STRTAG: /* Structure tag.  */
4906
#ifdef RS6000COFF_C
4907
      case C_GSYM:
4908
      case C_LSYM:
4909
      case C_PSYM:
4910
      case C_RSYM:
4911
      case C_RPSYM:
4912
      case C_STSYM:
4913
      case C_TCSYM:
4914
      case C_BCOMM:
4915
      case C_ECOML:
4916
      case C_ECOMM:
4917
      case C_DECL:
4918
      case C_ENTRY:
4919
      case C_FUN:
4920
      case C_ESTAT:
4921
#endif
4922
14.5k
        dst->symbol.flags |= BSF_DEBUGGING;
4923
14.5k
        dst->symbol.value = (src->u.syment.n_value);
4924
14.5k
        break;
4925
4926
#ifdef RS6000COFF_C
4927
      case C_BINCL: /* Beginning of include file.  */
4928
      case C_EINCL: /* Ending of include file.  */
4929
        /* The value is actually a pointer into the line numbers
4930
     of the file.  We locate the line number entry, and
4931
     set the section to the section which contains it, and
4932
     the value to the index in that section.  */
4933
        {
4934
    asection *sec;
4935
4936
    dst->symbol.flags = BSF_DEBUGGING;
4937
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4938
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4939
          && ((file_ptr) (sec->line_filepos
4940
              + sec->lineno_count * bfd_coff_linesz (abfd))
4941
        > (file_ptr) src->u.syment.n_value))
4942
        break;
4943
    if (sec == NULL)
4944
      dst->symbol.value = 0;
4945
    else
4946
      {
4947
        dst->symbol.section = sec;
4948
        dst->symbol.value = ((src->u.syment.n_value
4949
            - sec->line_filepos)
4950
           / bfd_coff_linesz (abfd));
4951
        src->fix_line = 1;
4952
      }
4953
        }
4954
        break;
4955
4956
      case C_BSTAT:
4957
        dst->symbol.flags = BSF_DEBUGGING;
4958
4959
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4960
    dst->symbol.value = 0;
4961
        else
4962
    {
4963
      /* The value is actually a symbol index.  Save a pointer
4964
         to the symbol instead of the index.  FIXME: This
4965
         should use a union.  */
4966
      src->u.syment.n_value
4967
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4968
      dst->symbol.value = src->u.syment.n_value;
4969
      src->fix_value = 1;
4970
    }
4971
        break;
4972
#endif
4973
4974
248
      case C_BLOCK: /* ".bb" or ".eb".  */
4975
1.87k
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4976
2.33k
      case C_EFCN: /* Physical end of function.  */
4977
2.33k
#if defined COFF_WITH_PE
4978
        /* PE sets the symbol to a value relative to the start
4979
     of the section.  */
4980
2.33k
        dst->symbol.value = src->u.syment.n_value;
4981
2.33k
        if (strcmp (dst->symbol.name, ".bf") != 0)
4982
2.32k
    {
4983
      /* PE uses funny values for .ef and .lf; don't
4984
         relocate them.  */
4985
2.32k
      dst->symbol.flags = BSF_DEBUGGING;
4986
2.32k
    }
4987
7
        else
4988
7
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4989
#else
4990
        /* Base the value as an index from the base of the
4991
     section.  */
4992
        dst->symbol.flags = BSF_LOCAL;
4993
        dst->symbol.value = (src->u.syment.n_value
4994
           - dst->symbol.section->vma);
4995
#endif
4996
2.33k
        break;
4997
4998
139
      case C_STATLAB: /* Static load time label.  */
4999
139
        dst->symbol.value = src->u.syment.n_value;
5000
139
        dst->symbol.flags = BSF_GLOBAL;
5001
139
        break;
5002
5003
58.5k
      case C_NULL:
5004
        /* PE DLLs sometimes have zeroed out symbols for some
5005
     reason.  Just ignore them without a warning.  */
5006
58.5k
        if (src->u.syment.n_type == 0
5007
58.5k
      && src->u.syment.n_value == 0
5008
58.5k
      && src->u.syment.n_scnum == 0)
5009
15.3k
    break;
5010
#ifdef RS6000COFF_C
5011
        /* XCOFF specific: deleted entry.  */
5012
        if (src->u.syment.n_value == C_NULL_VALUE)
5013
    break;
5014
#endif
5015
        /* Fall through.  */
5016
43.3k
      case C_EXTDEF: /* External definition.  */
5017
43.4k
      case C_ULABEL: /* Undefined label.  */
5018
43.4k
      case C_USTATIC: /* Undefined static.  */
5019
#ifndef COFF_WITH_PE
5020
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5021
         class to represent a section symbol.  */
5022
      case C_LINE:  /* line # reformatted as symbol table entry.  */
5023
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5024
      case C_ALIAS: /* Duplicate tag.  */
5025
#endif
5026
        /* New storage classes for TI COFF.  */
5027
#ifdef TICOFF
5028
      case C_UEXT:  /* Tentative external definition.  */
5029
#endif
5030
43.5k
      case C_EXTLAB: /* External load time label.  */
5031
63.1k
      default:
5032
63.1k
        _bfd_error_handler
5033
    /* xgettext:c-format */
5034
63.1k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5035
63.1k
     abfd, src->u.syment.n_sclass,
5036
63.1k
     dst->symbol.section->name, dst->symbol.name);
5037
63.1k
        ret = false;
5038
        /* Fall through.  */
5039
63.2k
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5040
        /* PR 20722: These symbols can also be generated by
5041
     building DLLs with --gc-sections enabled.  */
5042
63.2k
        dst->symbol.flags = BSF_DEBUGGING;
5043
63.2k
        dst->symbol.value = (src->u.syment.n_value);
5044
63.2k
        break;
5045
165k
      }
5046
5047
165k
    dst->native = src;
5048
165k
    dst->symbol.udata.i = 0;
5049
165k
    dst->lineno = NULL;
5050
5051
165k
    this_index += (src->u.syment.n_numaux) + 1;
5052
165k
    dst++;
5053
165k
    number_of_symbols++;
5054
165k
  }
5055
982
    }
5056
5057
982
  obj_symbols (abfd) = cached_area;
5058
982
  obj_raw_syments (abfd) = native_symbols;
5059
5060
982
  abfd->symcount = number_of_symbols;
5061
982
  obj_convert (abfd) = table_ptr;
5062
  /* Slurp the line tables for each section too.  */
5063
982
  {
5064
982
    asection *p;
5065
5066
982
    p = abfd->sections;
5067
8.51k
    while (p)
5068
8.21k
      {
5069
8.21k
  if (! coff_slurp_line_table (abfd, p))
5070
687
    return false;
5071
7.52k
  p = p->next;
5072
7.52k
      }
5073
982
  }
5074
5075
295
  return ret;
5076
982
}
coff-x86_64.c:coff_slurp_symbol_table
Line
Count
Source
4704
17.4k
{
4705
17.4k
  combined_entry_type *native_symbols;
4706
17.4k
  coff_symbol_type *cached_area;
4707
17.4k
  unsigned int *table_ptr;
4708
17.4k
  unsigned int number_of_symbols = 0;
4709
17.4k
  bool ret = true;
4710
17.4k
  size_t amt;
4711
4712
17.4k
  if (obj_symbols (abfd))
4713
2.02k
    return true;
4714
4715
  /* Read in the symbol table.  */
4716
15.4k
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4717
13.6k
    return false;
4718
4719
  /* Allocate enough room for all the symbols in cached form.  */
4720
1.77k
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4721
1.77k
       sizeof (*cached_area), &amt))
4722
0
    {
4723
0
      bfd_set_error (bfd_error_file_too_big);
4724
0
      return false;
4725
0
    }
4726
1.77k
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4727
1.77k
  if (cached_area == NULL)
4728
0
    return false;
4729
4730
1.77k
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4731
1.77k
       sizeof (*table_ptr), &amt))
4732
0
    {
4733
0
      bfd_set_error (bfd_error_file_too_big);
4734
0
      return false;
4735
0
    }
4736
1.77k
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4737
1.77k
  if (table_ptr == NULL)
4738
0
    return false;
4739
1.77k
  else
4740
1.77k
    {
4741
1.77k
      coff_symbol_type *dst = cached_area;
4742
1.77k
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4743
1.77k
      unsigned int this_index = 0;
4744
4745
179k
      while (this_index < last_native_index)
4746
177k
  {
4747
177k
    combined_entry_type *src = native_symbols + this_index;
4748
177k
    table_ptr[this_index] = number_of_symbols;
4749
4750
177k
    dst->symbol.the_bfd = abfd;
4751
177k
    BFD_ASSERT (src->is_sym);
4752
177k
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4753
    /* We use the native name field to point to the cached field.  */
4754
177k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4755
177k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4756
177k
                 src->u.syment.n_scnum);
4757
177k
    dst->symbol.flags = 0;
4758
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4759
177k
    dst->symbol.value = 0;
4760
177k
    dst->done_lineno = false;
4761
4762
177k
    switch (src->u.syment.n_sclass)
4763
177k
      {
4764
3.04k
      case C_EXT:
4765
3.31k
      case C_WEAKEXT:
4766
#if defined ARM
4767
      case C_THUMBEXT:
4768
      case C_THUMBEXTFUNC:
4769
#endif
4770
#ifdef RS6000COFF_C
4771
      case C_HIDEXT:
4772
#ifndef AIX_WEAK_SUPPORT
4773
      case C_AIX_WEAKEXT:
4774
#endif
4775
#endif
4776
3.31k
#ifdef C_SYSTEM
4777
3.69k
      case C_SYSTEM: /* System Wide variable.  */
4778
3.69k
#endif
4779
#ifdef COFF_WITH_PE
4780
      /* In PE, 0x68 (104) denotes a section symbol.  */
4781
      case C_SECTION:
4782
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4783
      case C_NT_WEAK:
4784
#endif
4785
3.69k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4786
3.69k
    {
4787
2.93k
    case COFF_SYMBOL_GLOBAL:
4788
2.93k
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4789
#if defined COFF_WITH_PE
4790
      /* PE sets the symbol to a value relative to the
4791
         start of the section.  */
4792
      dst->symbol.value = src->u.syment.n_value;
4793
#else
4794
2.93k
      dst->symbol.value = (src->u.syment.n_value
4795
2.93k
               - dst->symbol.section->vma);
4796
2.93k
#endif
4797
2.93k
      if (ISFCN ((src->u.syment.n_type)))
4798
        /* A function ext does not go at the end of a
4799
           file.  */
4800
76
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4801
2.93k
      break;
4802
4803
581
    case COFF_SYMBOL_COMMON:
4804
581
      dst->symbol.section = bfd_com_section_ptr;
4805
581
      dst->symbol.value = src->u.syment.n_value;
4806
581
      break;
4807
4808
185
    case COFF_SYMBOL_UNDEFINED:
4809
185
      dst->symbol.section = bfd_und_section_ptr;
4810
185
      dst->symbol.value = 0;
4811
185
      break;
4812
4813
0
    case COFF_SYMBOL_PE_SECTION:
4814
0
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4815
0
      dst->symbol.value = 0;
4816
0
      break;
4817
4818
0
    case COFF_SYMBOL_LOCAL:
4819
0
      dst->symbol.flags = BSF_LOCAL;
4820
#if defined COFF_WITH_PE
4821
      /* PE sets the symbol to a value relative to the
4822
         start of the section.  */
4823
      dst->symbol.value = src->u.syment.n_value;
4824
#else
4825
0
      dst->symbol.value = (src->u.syment.n_value
4826
0
               - dst->symbol.section->vma);
4827
0
#endif
4828
0
      if (ISFCN ((src->u.syment.n_type)))
4829
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4830
0
      break;
4831
3.69k
    }
4832
4833
#ifdef RS6000COFF_C
4834
        /* A symbol with a csect entry should not go at the end.  */
4835
        if (src->u.syment.n_numaux > 0)
4836
    dst->symbol.flags |= BSF_NOT_AT_END;
4837
#endif
4838
4839
#ifdef COFF_WITH_PE
4840
        if (src->u.syment.n_sclass == C_NT_WEAK)
4841
    dst->symbol.flags |= BSF_WEAK;
4842
4843
        if (src->u.syment.n_sclass == C_SECTION
4844
      && src->u.syment.n_scnum > 0)
4845
    dst->symbol.flags = BSF_LOCAL;
4846
#endif
4847
3.69k
        if (src->u.syment.n_sclass == C_WEAKEXT
4848
#ifdef RS6000COFF_C
4849
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4850
#endif
4851
3.69k
      )
4852
272
    dst->symbol.flags |= BSF_WEAK;
4853
4854
3.69k
        break;
4855
4856
2.31k
      case C_STAT:  /* Static.  */
4857
#if defined ARM
4858
      case C_THUMBSTAT:    /* Thumb static.  */
4859
      case C_THUMBLABEL:   /* Thumb label.  */
4860
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4861
#endif
4862
#ifdef RS6000COFF_C
4863
      case C_DWARF:  /* A label in a dwarf section.  */
4864
      case C_INFO:   /* A label in a comment section.  */
4865
#endif
4866
3.03k
      case C_LABEL:  /* Label.  */
4867
3.03k
        if (src->u.syment.n_scnum == N_DEBUG)
4868
7
    dst->symbol.flags = BSF_DEBUGGING;
4869
3.03k
        else
4870
3.03k
    dst->symbol.flags = BSF_LOCAL;
4871
4872
        /* Base the value as an index from the base of the
4873
     section, if there is one.  */
4874
3.03k
        if (dst->symbol.section)
4875
3.03k
    {
4876
#if defined COFF_WITH_PE
4877
      /* PE sets the symbol to a value relative to the
4878
         start of the section.  */
4879
      dst->symbol.value = src->u.syment.n_value;
4880
#else
4881
3.03k
      dst->symbol.value = (src->u.syment.n_value
4882
3.03k
               - dst->symbol.section->vma);
4883
3.03k
#endif
4884
3.03k
    }
4885
0
        else
4886
0
    dst->symbol.value = src->u.syment.n_value;
4887
3.03k
        break;
4888
4889
920
      case C_FILE: /* File name.  */
4890
920
        dst->symbol.flags = BSF_FILE;
4891
        /* Fall through.  */
4892
2.61k
      case C_MOS:   /* Member of structure.  */
4893
3.06k
      case C_EOS:   /* End of structure.  */
4894
3.58k
      case C_REGPARM: /* Register parameter.  */
4895
4.26k
      case C_REG:   /* register variable.  */
4896
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4897
4.93k
      case C_TPDEF: /* Type definition.  */
4898
5.57k
      case C_ARG:
4899
11.8k
      case C_AUTO: /* Automatic variable.  */
4900
13.1k
      case C_FIELD: /* Bit field.  */
4901
13.7k
      case C_ENTAG: /* Enumeration tag.  */
4902
14.3k
      case C_MOE:   /* Member of enumeration.  */
4903
15.5k
      case C_MOU:   /* Member of union.  */
4904
16.6k
      case C_UNTAG: /* Union tag.  */
4905
18.0k
      case C_STRTAG: /* Structure tag.  */
4906
#ifdef RS6000COFF_C
4907
      case C_GSYM:
4908
      case C_LSYM:
4909
      case C_PSYM:
4910
      case C_RSYM:
4911
      case C_RPSYM:
4912
      case C_STSYM:
4913
      case C_TCSYM:
4914
      case C_BCOMM:
4915
      case C_ECOML:
4916
      case C_ECOMM:
4917
      case C_DECL:
4918
      case C_ENTRY:
4919
      case C_FUN:
4920
      case C_ESTAT:
4921
#endif
4922
18.0k
        dst->symbol.flags |= BSF_DEBUGGING;
4923
18.0k
        dst->symbol.value = (src->u.syment.n_value);
4924
18.0k
        break;
4925
4926
#ifdef RS6000COFF_C
4927
      case C_BINCL: /* Beginning of include file.  */
4928
      case C_EINCL: /* Ending of include file.  */
4929
        /* The value is actually a pointer into the line numbers
4930
     of the file.  We locate the line number entry, and
4931
     set the section to the section which contains it, and
4932
     the value to the index in that section.  */
4933
        {
4934
    asection *sec;
4935
4936
    dst->symbol.flags = BSF_DEBUGGING;
4937
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4938
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4939
          && ((file_ptr) (sec->line_filepos
4940
              + sec->lineno_count * bfd_coff_linesz (abfd))
4941
        > (file_ptr) src->u.syment.n_value))
4942
        break;
4943
    if (sec == NULL)
4944
      dst->symbol.value = 0;
4945
    else
4946
      {
4947
        dst->symbol.section = sec;
4948
        dst->symbol.value = ((src->u.syment.n_value
4949
            - sec->line_filepos)
4950
           / bfd_coff_linesz (abfd));
4951
        src->fix_line = 1;
4952
      }
4953
        }
4954
        break;
4955
4956
      case C_BSTAT:
4957
        dst->symbol.flags = BSF_DEBUGGING;
4958
4959
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4960
    dst->symbol.value = 0;
4961
        else
4962
    {
4963
      /* The value is actually a symbol index.  Save a pointer
4964
         to the symbol instead of the index.  FIXME: This
4965
         should use a union.  */
4966
      src->u.syment.n_value
4967
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4968
      dst->symbol.value = src->u.syment.n_value;
4969
      src->fix_value = 1;
4970
    }
4971
        break;
4972
#endif
4973
4974
441
      case C_BLOCK: /* ".bb" or ".eb".  */
4975
2.58k
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4976
3.23k
      case C_EFCN: /* Physical end of function.  */
4977
#if defined COFF_WITH_PE
4978
        /* PE sets the symbol to a value relative to the start
4979
     of the section.  */
4980
        dst->symbol.value = src->u.syment.n_value;
4981
        if (strcmp (dst->symbol.name, ".bf") != 0)
4982
    {
4983
      /* PE uses funny values for .ef and .lf; don't
4984
         relocate them.  */
4985
      dst->symbol.flags = BSF_DEBUGGING;
4986
    }
4987
        else
4988
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4989
#else
4990
        /* Base the value as an index from the base of the
4991
     section.  */
4992
3.23k
        dst->symbol.flags = BSF_LOCAL;
4993
3.23k
        dst->symbol.value = (src->u.syment.n_value
4994
3.23k
           - dst->symbol.section->vma);
4995
3.23k
#endif
4996
3.23k
        break;
4997
4998
477
      case C_STATLAB: /* Static load time label.  */
4999
477
        dst->symbol.value = src->u.syment.n_value;
5000
477
        dst->symbol.flags = BSF_GLOBAL;
5001
477
        break;
5002
5003
122k
      case C_NULL:
5004
        /* PE DLLs sometimes have zeroed out symbols for some
5005
     reason.  Just ignore them without a warning.  */
5006
122k
        if (src->u.syment.n_type == 0
5007
122k
      && src->u.syment.n_value == 0
5008
122k
      && src->u.syment.n_scnum == 0)
5009
57.2k
    break;
5010
#ifdef RS6000COFF_C
5011
        /* XCOFF specific: deleted entry.  */
5012
        if (src->u.syment.n_value == C_NULL_VALUE)
5013
    break;
5014
#endif
5015
        /* Fall through.  */
5016
65.0k
      case C_EXTDEF: /* External definition.  */
5017
65.2k
      case C_ULABEL: /* Undefined label.  */
5018
65.3k
      case C_USTATIC: /* Undefined static.  */
5019
65.3k
#ifndef COFF_WITH_PE
5020
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5021
         class to represent a section symbol.  */
5022
66.2k
      case C_LINE: /* line # reformatted as symbol table entry.  */
5023
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5024
67.4k
      case C_ALIAS: /* Duplicate tag.  */
5025
67.4k
#endif
5026
        /* New storage classes for TI COFF.  */
5027
#ifdef TICOFF
5028
      case C_UEXT:  /* Tentative external definition.  */
5029
#endif
5030
67.4k
      case C_EXTLAB: /* External load time label.  */
5031
91.9k
      default:
5032
91.9k
        _bfd_error_handler
5033
    /* xgettext:c-format */
5034
91.9k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5035
91.9k
     abfd, src->u.syment.n_sclass,
5036
91.9k
     dst->symbol.section->name, dst->symbol.name);
5037
91.9k
        ret = false;
5038
        /* Fall through.  */
5039
92.2k
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5040
        /* PR 20722: These symbols can also be generated by
5041
     building DLLs with --gc-sections enabled.  */
5042
92.2k
        dst->symbol.flags = BSF_DEBUGGING;
5043
92.2k
        dst->symbol.value = (src->u.syment.n_value);
5044
92.2k
        break;
5045
177k
      }
5046
5047
177k
    dst->native = src;
5048
177k
    dst->symbol.udata.i = 0;
5049
177k
    dst->lineno = NULL;
5050
5051
177k
    this_index += (src->u.syment.n_numaux) + 1;
5052
177k
    dst++;
5053
177k
    number_of_symbols++;
5054
177k
  }
5055
1.77k
    }
5056
5057
1.77k
  obj_symbols (abfd) = cached_area;
5058
1.77k
  obj_raw_syments (abfd) = native_symbols;
5059
5060
1.77k
  abfd->symcount = number_of_symbols;
5061
1.77k
  obj_convert (abfd) = table_ptr;
5062
  /* Slurp the line tables for each section too.  */
5063
1.77k
  {
5064
1.77k
    asection *p;
5065
5066
1.77k
    p = abfd->sections;
5067
52.4k
    while (p)
5068
51.9k
      {
5069
51.9k
  if (! coff_slurp_line_table (abfd, p))
5070
1.24k
    return false;
5071
50.6k
  p = p->next;
5072
50.6k
      }
5073
1.77k
  }
5074
5075
527
  return ret;
5076
1.77k
}
coff64-rs6000.c:coff_slurp_symbol_table
Line
Count
Source
4704
3.84k
{
4705
3.84k
  combined_entry_type *native_symbols;
4706
3.84k
  coff_symbol_type *cached_area;
4707
3.84k
  unsigned int *table_ptr;
4708
3.84k
  unsigned int number_of_symbols = 0;
4709
3.84k
  bool ret = true;
4710
3.84k
  size_t amt;
4711
4712
3.84k
  if (obj_symbols (abfd))
4713
229
    return true;
4714
4715
  /* Read in the symbol table.  */
4716
3.61k
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4717
2.29k
    return false;
4718
4719
  /* Allocate enough room for all the symbols in cached form.  */
4720
1.32k
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4721
1.32k
       sizeof (*cached_area), &amt))
4722
0
    {
4723
0
      bfd_set_error (bfd_error_file_too_big);
4724
0
      return false;
4725
0
    }
4726
1.32k
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4727
1.32k
  if (cached_area == NULL)
4728
0
    return false;
4729
4730
1.32k
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4731
1.32k
       sizeof (*table_ptr), &amt))
4732
0
    {
4733
0
      bfd_set_error (bfd_error_file_too_big);
4734
0
      return false;
4735
0
    }
4736
1.32k
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4737
1.32k
  if (table_ptr == NULL)
4738
0
    return false;
4739
1.32k
  else
4740
1.32k
    {
4741
1.32k
      coff_symbol_type *dst = cached_area;
4742
1.32k
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4743
1.32k
      unsigned int this_index = 0;
4744
4745
205k
      while (this_index < last_native_index)
4746
203k
  {
4747
203k
    combined_entry_type *src = native_symbols + this_index;
4748
203k
    table_ptr[this_index] = number_of_symbols;
4749
4750
203k
    dst->symbol.the_bfd = abfd;
4751
203k
    BFD_ASSERT (src->is_sym);
4752
203k
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4753
    /* We use the native name field to point to the cached field.  */
4754
203k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4755
203k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4756
203k
                 src->u.syment.n_scnum);
4757
203k
    dst->symbol.flags = 0;
4758
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4759
203k
    dst->symbol.value = 0;
4760
203k
    dst->done_lineno = false;
4761
4762
203k
    switch (src->u.syment.n_sclass)
4763
203k
      {
4764
1.70k
      case C_EXT:
4765
1.86k
      case C_WEAKEXT:
4766
#if defined ARM
4767
      case C_THUMBEXT:
4768
      case C_THUMBEXTFUNC:
4769
#endif
4770
1.86k
#ifdef RS6000COFF_C
4771
2.26k
      case C_HIDEXT:
4772
2.26k
#ifndef AIX_WEAK_SUPPORT
4773
3.97k
      case C_AIX_WEAKEXT:
4774
3.97k
#endif
4775
3.97k
#endif
4776
3.97k
#ifdef C_SYSTEM
4777
4.67k
      case C_SYSTEM: /* System Wide variable.  */
4778
4.67k
#endif
4779
#ifdef COFF_WITH_PE
4780
      /* In PE, 0x68 (104) denotes a section symbol.  */
4781
      case C_SECTION:
4782
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4783
      case C_NT_WEAK:
4784
#endif
4785
4.67k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4786
4.67k
    {
4787
3.71k
    case COFF_SYMBOL_GLOBAL:
4788
3.71k
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4789
#if defined COFF_WITH_PE
4790
      /* PE sets the symbol to a value relative to the
4791
         start of the section.  */
4792
      dst->symbol.value = src->u.syment.n_value;
4793
#else
4794
3.71k
      dst->symbol.value = (src->u.syment.n_value
4795
3.71k
               - dst->symbol.section->vma);
4796
3.71k
#endif
4797
3.71k
      if (ISFCN ((src->u.syment.n_type)))
4798
        /* A function ext does not go at the end of a
4799
           file.  */
4800
112
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4801
3.71k
      break;
4802
4803
243
    case COFF_SYMBOL_COMMON:
4804
243
      dst->symbol.section = bfd_com_section_ptr;
4805
243
      dst->symbol.value = src->u.syment.n_value;
4806
243
      break;
4807
4808
321
    case COFF_SYMBOL_UNDEFINED:
4809
321
      dst->symbol.section = bfd_und_section_ptr;
4810
321
      dst->symbol.value = 0;
4811
321
      break;
4812
4813
0
    case COFF_SYMBOL_PE_SECTION:
4814
0
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4815
0
      dst->symbol.value = 0;
4816
0
      break;
4817
4818
387
    case COFF_SYMBOL_LOCAL:
4819
387
      dst->symbol.flags = BSF_LOCAL;
4820
#if defined COFF_WITH_PE
4821
      /* PE sets the symbol to a value relative to the
4822
         start of the section.  */
4823
      dst->symbol.value = src->u.syment.n_value;
4824
#else
4825
387
      dst->symbol.value = (src->u.syment.n_value
4826
387
               - dst->symbol.section->vma);
4827
387
#endif
4828
387
      if (ISFCN ((src->u.syment.n_type)))
4829
52
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4830
387
      break;
4831
4.67k
    }
4832
4833
4.67k
#ifdef RS6000COFF_C
4834
        /* A symbol with a csect entry should not go at the end.  */
4835
4.67k
        if (src->u.syment.n_numaux > 0)
4836
2.00k
    dst->symbol.flags |= BSF_NOT_AT_END;
4837
4.67k
#endif
4838
4839
#ifdef COFF_WITH_PE
4840
        if (src->u.syment.n_sclass == C_NT_WEAK)
4841
    dst->symbol.flags |= BSF_WEAK;
4842
4843
        if (src->u.syment.n_sclass == C_SECTION
4844
      && src->u.syment.n_scnum > 0)
4845
    dst->symbol.flags = BSF_LOCAL;
4846
#endif
4847
4.67k
        if (src->u.syment.n_sclass == C_WEAKEXT
4848
4.67k
#ifdef RS6000COFF_C
4849
4.67k
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4850
4.67k
#endif
4851
4.67k
      )
4852
1.87k
    dst->symbol.flags |= BSF_WEAK;
4853
4854
4.67k
        break;
4855
4856
912
      case C_STAT:  /* Static.  */
4857
#if defined ARM
4858
      case C_THUMBSTAT:    /* Thumb static.  */
4859
      case C_THUMBLABEL:   /* Thumb label.  */
4860
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4861
#endif
4862
912
#ifdef RS6000COFF_C
4863
3.51k
      case C_DWARF:  /* A label in a dwarf section.  */
4864
6.71k
      case C_INFO:  /* A label in a comment section.  */
4865
6.71k
#endif
4866
7.39k
      case C_LABEL:  /* Label.  */
4867
7.39k
        if (src->u.syment.n_scnum == N_DEBUG)
4868
4
    dst->symbol.flags = BSF_DEBUGGING;
4869
7.39k
        else
4870
7.39k
    dst->symbol.flags = BSF_LOCAL;
4871
4872
        /* Base the value as an index from the base of the
4873
     section, if there is one.  */
4874
7.39k
        if (dst->symbol.section)
4875
7.39k
    {
4876
#if defined COFF_WITH_PE
4877
      /* PE sets the symbol to a value relative to the
4878
         start of the section.  */
4879
      dst->symbol.value = src->u.syment.n_value;
4880
#else
4881
7.39k
      dst->symbol.value = (src->u.syment.n_value
4882
7.39k
               - dst->symbol.section->vma);
4883
7.39k
#endif
4884
7.39k
    }
4885
0
        else
4886
0
    dst->symbol.value = src->u.syment.n_value;
4887
7.39k
        break;
4888
4889
1.45k
      case C_FILE: /* File name.  */
4890
1.45k
        dst->symbol.flags = BSF_FILE;
4891
        /* Fall through.  */
4892
2.31k
      case C_MOS:   /* Member of structure.  */
4893
2.87k
      case C_EOS:   /* End of structure.  */
4894
3.47k
      case C_REGPARM: /* Register parameter.  */
4895
4.37k
      case C_REG:   /* register variable.  */
4896
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4897
4.99k
      case C_TPDEF: /* Type definition.  */
4898
5.86k
      case C_ARG:
4899
13.9k
      case C_AUTO: /* Automatic variable.  */
4900
14.3k
      case C_FIELD: /* Bit field.  */
4901
14.6k
      case C_ENTAG: /* Enumeration tag.  */
4902
15.4k
      case C_MOE:   /* Member of enumeration.  */
4903
16.4k
      case C_MOU:   /* Member of union.  */
4904
16.9k
      case C_UNTAG: /* Union tag.  */
4905
18.3k
      case C_STRTAG: /* Structure tag.  */
4906
18.3k
#ifdef RS6000COFF_C
4907
18.7k
      case C_GSYM:
4908
18.8k
      case C_LSYM:
4909
18.9k
      case C_PSYM:
4910
19.1k
      case C_RSYM:
4911
19.2k
      case C_RPSYM:
4912
19.2k
      case C_STSYM:
4913
19.3k
      case C_TCSYM:
4914
19.4k
      case C_BCOMM:
4915
19.5k
      case C_ECOML:
4916
19.6k
      case C_ECOMM:
4917
19.7k
      case C_DECL:
4918
19.7k
      case C_ENTRY:
4919
19.8k
      case C_FUN:
4920
20.2k
      case C_ESTAT:
4921
20.2k
#endif
4922
20.2k
        dst->symbol.flags |= BSF_DEBUGGING;
4923
20.2k
        dst->symbol.value = (src->u.syment.n_value);
4924
20.2k
        break;
4925
4926
0
#ifdef RS6000COFF_C
4927
2.61k
      case C_BINCL: /* Beginning of include file.  */
4928
3.93k
      case C_EINCL: /* Ending of include file.  */
4929
        /* The value is actually a pointer into the line numbers
4930
     of the file.  We locate the line number entry, and
4931
     set the section to the section which contains it, and
4932
     the value to the index in that section.  */
4933
3.93k
        {
4934
3.93k
    asection *sec;
4935
4936
3.93k
    dst->symbol.flags = BSF_DEBUGGING;
4937
1.57M
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4938
1.57M
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4939
1.57M
          && ((file_ptr) (sec->line_filepos
4940
1.35M
              + sec->lineno_count * bfd_coff_linesz (abfd))
4941
1.35M
        > (file_ptr) src->u.syment.n_value))
4942
2.59k
        break;
4943
3.93k
    if (sec == NULL)
4944
1.33k
      dst->symbol.value = 0;
4945
2.59k
    else
4946
2.59k
      {
4947
2.59k
        dst->symbol.section = sec;
4948
2.59k
        dst->symbol.value = ((src->u.syment.n_value
4949
2.59k
            - sec->line_filepos)
4950
2.59k
           / bfd_coff_linesz (abfd));
4951
2.59k
        src->fix_line = 1;
4952
2.59k
      }
4953
3.93k
        }
4954
3.93k
        break;
4955
4956
118
      case C_BSTAT:
4957
118
        dst->symbol.flags = BSF_DEBUGGING;
4958
4959
118
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4960
109
    dst->symbol.value = 0;
4961
9
        else
4962
9
    {
4963
      /* The value is actually a symbol index.  Save a pointer
4964
         to the symbol instead of the index.  FIXME: This
4965
         should use a union.  */
4966
9
      src->u.syment.n_value
4967
9
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4968
9
      dst->symbol.value = src->u.syment.n_value;
4969
9
      src->fix_value = 1;
4970
9
    }
4971
118
        break;
4972
0
#endif
4973
4974
361
      case C_BLOCK: /* ".bb" or ".eb".  */
4975
4.29k
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4976
4.80k
      case C_EFCN: /* Physical end of function.  */
4977
#if defined COFF_WITH_PE
4978
        /* PE sets the symbol to a value relative to the start
4979
     of the section.  */
4980
        dst->symbol.value = src->u.syment.n_value;
4981
        if (strcmp (dst->symbol.name, ".bf") != 0)
4982
    {
4983
      /* PE uses funny values for .ef and .lf; don't
4984
         relocate them.  */
4985
      dst->symbol.flags = BSF_DEBUGGING;
4986
    }
4987
        else
4988
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4989
#else
4990
        /* Base the value as an index from the base of the
4991
     section.  */
4992
4.80k
        dst->symbol.flags = BSF_LOCAL;
4993
4.80k
        dst->symbol.value = (src->u.syment.n_value
4994
4.80k
           - dst->symbol.section->vma);
4995
4.80k
#endif
4996
4.80k
        break;
4997
4998
426
      case C_STATLAB: /* Static load time label.  */
4999
426
        dst->symbol.value = src->u.syment.n_value;
5000
426
        dst->symbol.flags = BSF_GLOBAL;
5001
426
        break;
5002
5003
132k
      case C_NULL:
5004
        /* PE DLLs sometimes have zeroed out symbols for some
5005
     reason.  Just ignore them without a warning.  */
5006
132k
        if (src->u.syment.n_type == 0
5007
132k
      && src->u.syment.n_value == 0
5008
132k
      && src->u.syment.n_scnum == 0)
5009
44.8k
    break;
5010
87.4k
#ifdef RS6000COFF_C
5011
        /* XCOFF specific: deleted entry.  */
5012
87.4k
        if (src->u.syment.n_value == C_NULL_VALUE)
5013
2
    break;
5014
87.4k
#endif
5015
        /* Fall through.  */
5016
87.5k
      case C_EXTDEF: /* External definition.  */
5017
87.7k
      case C_ULABEL: /* Undefined label.  */
5018
87.9k
      case C_USTATIC: /* Undefined static.  */
5019
87.9k
#ifndef COFF_WITH_PE
5020
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5021
         class to represent a section symbol.  */
5022
89.5k
      case C_LINE: /* line # reformatted as symbol table entry.  */
5023
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5024
92.1k
      case C_ALIAS: /* Duplicate tag.  */
5025
92.1k
#endif
5026
        /* New storage classes for TI COFF.  */
5027
#ifdef TICOFF
5028
      case C_UEXT:  /* Tentative external definition.  */
5029
#endif
5030
92.2k
      case C_EXTLAB: /* External load time label.  */
5031
117k
      default:
5032
117k
        _bfd_error_handler
5033
    /* xgettext:c-format */
5034
117k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5035
117k
     abfd, src->u.syment.n_sclass,
5036
117k
     dst->symbol.section->name, dst->symbol.name);
5037
117k
        ret = false;
5038
        /* Fall through.  */
5039
117k
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5040
        /* PR 20722: These symbols can also be generated by
5041
     building DLLs with --gc-sections enabled.  */
5042
117k
        dst->symbol.flags = BSF_DEBUGGING;
5043
117k
        dst->symbol.value = (src->u.syment.n_value);
5044
117k
        break;
5045
203k
      }
5046
5047
203k
    dst->native = src;
5048
203k
    dst->symbol.udata.i = 0;
5049
203k
    dst->lineno = NULL;
5050
5051
203k
    this_index += (src->u.syment.n_numaux) + 1;
5052
203k
    dst++;
5053
203k
    number_of_symbols++;
5054
203k
  }
5055
1.32k
    }
5056
5057
1.32k
  obj_symbols (abfd) = cached_area;
5058
1.32k
  obj_raw_syments (abfd) = native_symbols;
5059
5060
1.32k
  abfd->symcount = number_of_symbols;
5061
1.32k
  obj_convert (abfd) = table_ptr;
5062
  /* Slurp the line tables for each section too.  */
5063
1.32k
  {
5064
1.32k
    asection *p;
5065
5066
1.32k
    p = abfd->sections;
5067
5.14k
    while (p)
5068
4.96k
      {
5069
4.96k
  if (! coff_slurp_line_table (abfd, p))
5070
1.14k
    return false;
5071
3.82k
  p = p->next;
5072
3.82k
      }
5073
1.32k
  }
5074
5075
180
  return ret;
5076
1.32k
}
pe-aarch64.c:coff_slurp_symbol_table
Line
Count
Source
4704
2.48k
{
4705
2.48k
  combined_entry_type *native_symbols;
4706
2.48k
  coff_symbol_type *cached_area;
4707
2.48k
  unsigned int *table_ptr;
4708
2.48k
  unsigned int number_of_symbols = 0;
4709
2.48k
  bool ret = true;
4710
2.48k
  size_t amt;
4711
4712
2.48k
  if (obj_symbols (abfd))
4713
749
    return true;
4714
4715
  /* Read in the symbol table.  */
4716
1.73k
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4717
515
    return false;
4718
4719
  /* Allocate enough room for all the symbols in cached form.  */
4720
1.21k
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4721
1.21k
       sizeof (*cached_area), &amt))
4722
0
    {
4723
0
      bfd_set_error (bfd_error_file_too_big);
4724
0
      return false;
4725
0
    }
4726
1.21k
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4727
1.21k
  if (cached_area == NULL)
4728
0
    return false;
4729
4730
1.21k
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4731
1.21k
       sizeof (*table_ptr), &amt))
4732
0
    {
4733
0
      bfd_set_error (bfd_error_file_too_big);
4734
0
      return false;
4735
0
    }
4736
1.21k
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4737
1.21k
  if (table_ptr == NULL)
4738
0
    return false;
4739
1.21k
  else
4740
1.21k
    {
4741
1.21k
      coff_symbol_type *dst = cached_area;
4742
1.21k
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4743
1.21k
      unsigned int this_index = 0;
4744
4745
346k
      while (this_index < last_native_index)
4746
345k
  {
4747
345k
    combined_entry_type *src = native_symbols + this_index;
4748
345k
    table_ptr[this_index] = number_of_symbols;
4749
4750
345k
    dst->symbol.the_bfd = abfd;
4751
345k
    BFD_ASSERT (src->is_sym);
4752
345k
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4753
    /* We use the native name field to point to the cached field.  */
4754
345k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4755
345k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4756
345k
                 src->u.syment.n_scnum);
4757
345k
    dst->symbol.flags = 0;
4758
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4759
345k
    dst->symbol.value = 0;
4760
345k
    dst->done_lineno = false;
4761
4762
345k
    switch (src->u.syment.n_sclass)
4763
345k
      {
4764
11.4k
      case C_EXT:
4765
11.7k
      case C_WEAKEXT:
4766
#if defined ARM
4767
      case C_THUMBEXT:
4768
      case C_THUMBEXTFUNC:
4769
#endif
4770
#ifdef RS6000COFF_C
4771
      case C_HIDEXT:
4772
#ifndef AIX_WEAK_SUPPORT
4773
      case C_AIX_WEAKEXT:
4774
#endif
4775
#endif
4776
11.7k
#ifdef C_SYSTEM
4777
12.8k
      case C_SYSTEM: /* System Wide variable.  */
4778
12.8k
#endif
4779
12.8k
#ifdef COFF_WITH_PE
4780
      /* In PE, 0x68 (104) denotes a section symbol.  */
4781
13.1k
      case C_SECTION:
4782
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4783
17.6k
      case C_NT_WEAK:
4784
17.6k
#endif
4785
17.6k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4786
17.6k
    {
4787
15.9k
    case COFF_SYMBOL_GLOBAL:
4788
15.9k
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4789
15.9k
#if defined COFF_WITH_PE
4790
      /* PE sets the symbol to a value relative to the
4791
         start of the section.  */
4792
15.9k
      dst->symbol.value = src->u.syment.n_value;
4793
#else
4794
      dst->symbol.value = (src->u.syment.n_value
4795
               - dst->symbol.section->vma);
4796
#endif
4797
15.9k
      if (ISFCN ((src->u.syment.n_type)))
4798
        /* A function ext does not go at the end of a
4799
           file.  */
4800
449
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4801
15.9k
      break;
4802
4803
1.12k
    case COFF_SYMBOL_COMMON:
4804
1.12k
      dst->symbol.section = bfd_com_section_ptr;
4805
1.12k
      dst->symbol.value = src->u.syment.n_value;
4806
1.12k
      break;
4807
4808
630
    case COFF_SYMBOL_UNDEFINED:
4809
630
      dst->symbol.section = bfd_und_section_ptr;
4810
630
      dst->symbol.value = 0;
4811
630
      break;
4812
4813
0
    case COFF_SYMBOL_PE_SECTION:
4814
0
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4815
0
      dst->symbol.value = 0;
4816
0
      break;
4817
4818
0
    case COFF_SYMBOL_LOCAL:
4819
0
      dst->symbol.flags = BSF_LOCAL;
4820
0
#if defined COFF_WITH_PE
4821
      /* PE sets the symbol to a value relative to the
4822
         start of the section.  */
4823
0
      dst->symbol.value = src->u.syment.n_value;
4824
#else
4825
      dst->symbol.value = (src->u.syment.n_value
4826
               - dst->symbol.section->vma);
4827
#endif
4828
0
      if (ISFCN ((src->u.syment.n_type)))
4829
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4830
0
      break;
4831
17.6k
    }
4832
4833
#ifdef RS6000COFF_C
4834
        /* A symbol with a csect entry should not go at the end.  */
4835
        if (src->u.syment.n_numaux > 0)
4836
    dst->symbol.flags |= BSF_NOT_AT_END;
4837
#endif
4838
4839
17.6k
#ifdef COFF_WITH_PE
4840
17.6k
        if (src->u.syment.n_sclass == C_NT_WEAK)
4841
4.53k
    dst->symbol.flags |= BSF_WEAK;
4842
4843
17.6k
        if (src->u.syment.n_sclass == C_SECTION
4844
17.6k
      && src->u.syment.n_scnum > 0)
4845
0
    dst->symbol.flags = BSF_LOCAL;
4846
17.6k
#endif
4847
17.6k
        if (src->u.syment.n_sclass == C_WEAKEXT
4848
#ifdef RS6000COFF_C
4849
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4850
#endif
4851
17.6k
      )
4852
298
    dst->symbol.flags |= BSF_WEAK;
4853
4854
17.6k
        break;
4855
4856
6.08k
      case C_STAT:  /* Static.  */
4857
#if defined ARM
4858
      case C_THUMBSTAT:    /* Thumb static.  */
4859
      case C_THUMBLABEL:   /* Thumb label.  */
4860
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4861
#endif
4862
#ifdef RS6000COFF_C
4863
      case C_DWARF:  /* A label in a dwarf section.  */
4864
      case C_INFO:   /* A label in a comment section.  */
4865
#endif
4866
6.71k
      case C_LABEL:  /* Label.  */
4867
6.71k
        if (src->u.syment.n_scnum == N_DEBUG)
4868
3
    dst->symbol.flags = BSF_DEBUGGING;
4869
6.70k
        else
4870
6.70k
    dst->symbol.flags = BSF_LOCAL;
4871
4872
        /* Base the value as an index from the base of the
4873
     section, if there is one.  */
4874
6.71k
        if (dst->symbol.section)
4875
6.71k
    {
4876
6.71k
#if defined COFF_WITH_PE
4877
      /* PE sets the symbol to a value relative to the
4878
         start of the section.  */
4879
6.71k
      dst->symbol.value = src->u.syment.n_value;
4880
#else
4881
      dst->symbol.value = (src->u.syment.n_value
4882
               - dst->symbol.section->vma);
4883
#endif
4884
6.71k
    }
4885
0
        else
4886
0
    dst->symbol.value = src->u.syment.n_value;
4887
6.71k
        break;
4888
4889
2.64k
      case C_FILE: /* File name.  */
4890
2.64k
        dst->symbol.flags = BSF_FILE;
4891
        /* Fall through.  */
4892
4.22k
      case C_MOS:   /* Member of structure.  */
4893
5.28k
      case C_EOS:   /* End of structure.  */
4894
5.93k
      case C_REGPARM: /* Register parameter.  */
4895
8.05k
      case C_REG:   /* register variable.  */
4896
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4897
9.34k
      case C_TPDEF: /* Type definition.  */
4898
13.0k
      case C_ARG:
4899
27.1k
      case C_AUTO: /* Automatic variable.  */
4900
27.8k
      case C_FIELD: /* Bit field.  */
4901
28.5k
      case C_ENTAG: /* Enumeration tag.  */
4902
30.5k
      case C_MOE:   /* Member of enumeration.  */
4903
31.1k
      case C_MOU:   /* Member of union.  */
4904
32.6k
      case C_UNTAG: /* Union tag.  */
4905
35.6k
      case C_STRTAG: /* Structure tag.  */
4906
#ifdef RS6000COFF_C
4907
      case C_GSYM:
4908
      case C_LSYM:
4909
      case C_PSYM:
4910
      case C_RSYM:
4911
      case C_RPSYM:
4912
      case C_STSYM:
4913
      case C_TCSYM:
4914
      case C_BCOMM:
4915
      case C_ECOML:
4916
      case C_ECOMM:
4917
      case C_DECL:
4918
      case C_ENTRY:
4919
      case C_FUN:
4920
      case C_ESTAT:
4921
#endif
4922
35.6k
        dst->symbol.flags |= BSF_DEBUGGING;
4923
35.6k
        dst->symbol.value = (src->u.syment.n_value);
4924
35.6k
        break;
4925
4926
#ifdef RS6000COFF_C
4927
      case C_BINCL: /* Beginning of include file.  */
4928
      case C_EINCL: /* Ending of include file.  */
4929
        /* The value is actually a pointer into the line numbers
4930
     of the file.  We locate the line number entry, and
4931
     set the section to the section which contains it, and
4932
     the value to the index in that section.  */
4933
        {
4934
    asection *sec;
4935
4936
    dst->symbol.flags = BSF_DEBUGGING;
4937
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4938
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4939
          && ((file_ptr) (sec->line_filepos
4940
              + sec->lineno_count * bfd_coff_linesz (abfd))
4941
        > (file_ptr) src->u.syment.n_value))
4942
        break;
4943
    if (sec == NULL)
4944
      dst->symbol.value = 0;
4945
    else
4946
      {
4947
        dst->symbol.section = sec;
4948
        dst->symbol.value = ((src->u.syment.n_value
4949
            - sec->line_filepos)
4950
           / bfd_coff_linesz (abfd));
4951
        src->fix_line = 1;
4952
      }
4953
        }
4954
        break;
4955
4956
      case C_BSTAT:
4957
        dst->symbol.flags = BSF_DEBUGGING;
4958
4959
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4960
    dst->symbol.value = 0;
4961
        else
4962
    {
4963
      /* The value is actually a symbol index.  Save a pointer
4964
         to the symbol instead of the index.  FIXME: This
4965
         should use a union.  */
4966
      src->u.syment.n_value
4967
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4968
      dst->symbol.value = src->u.syment.n_value;
4969
      src->fix_value = 1;
4970
    }
4971
        break;
4972
#endif
4973
4974
774
      case C_BLOCK: /* ".bb" or ".eb".  */
4975
6.86k
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4976
8.31k
      case C_EFCN: /* Physical end of function.  */
4977
8.31k
#if defined COFF_WITH_PE
4978
        /* PE sets the symbol to a value relative to the start
4979
     of the section.  */
4980
8.31k
        dst->symbol.value = src->u.syment.n_value;
4981
8.31k
        if (strcmp (dst->symbol.name, ".bf") != 0)
4982
8.31k
    {
4983
      /* PE uses funny values for .ef and .lf; don't
4984
         relocate them.  */
4985
8.31k
      dst->symbol.flags = BSF_DEBUGGING;
4986
8.31k
    }
4987
6
        else
4988
6
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4989
#else
4990
        /* Base the value as an index from the base of the
4991
     section.  */
4992
        dst->symbol.flags = BSF_LOCAL;
4993
        dst->symbol.value = (src->u.syment.n_value
4994
           - dst->symbol.section->vma);
4995
#endif
4996
8.31k
        break;
4997
4998
1.34k
      case C_STATLAB: /* Static load time label.  */
4999
1.34k
        dst->symbol.value = src->u.syment.n_value;
5000
1.34k
        dst->symbol.flags = BSF_GLOBAL;
5001
1.34k
        break;
5002
5003
211k
      case C_NULL:
5004
        /* PE DLLs sometimes have zeroed out symbols for some
5005
     reason.  Just ignore them without a warning.  */
5006
211k
        if (src->u.syment.n_type == 0
5007
211k
      && src->u.syment.n_value == 0
5008
211k
      && src->u.syment.n_scnum == 0)
5009
56.9k
    break;
5010
#ifdef RS6000COFF_C
5011
        /* XCOFF specific: deleted entry.  */
5012
        if (src->u.syment.n_value == C_NULL_VALUE)
5013
    break;
5014
#endif
5015
        /* Fall through.  */
5016
155k
      case C_EXTDEF: /* External definition.  */
5017
155k
      case C_ULABEL: /* Undefined label.  */
5018
156k
      case C_USTATIC: /* Undefined static.  */
5019
#ifndef COFF_WITH_PE
5020
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5021
         class to represent a section symbol.  */
5022
      case C_LINE:  /* line # reformatted as symbol table entry.  */
5023
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5024
      case C_ALIAS: /* Duplicate tag.  */
5025
#endif
5026
        /* New storage classes for TI COFF.  */
5027
#ifdef TICOFF
5028
      case C_UEXT:  /* Tentative external definition.  */
5029
#endif
5030
156k
      case C_EXTLAB: /* External load time label.  */
5031
218k
      default:
5032
218k
        _bfd_error_handler
5033
    /* xgettext:c-format */
5034
218k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5035
218k
     abfd, src->u.syment.n_sclass,
5036
218k
     dst->symbol.section->name, dst->symbol.name);
5037
218k
        ret = false;
5038
        /* Fall through.  */
5039
218k
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5040
        /* PR 20722: These symbols can also be generated by
5041
     building DLLs with --gc-sections enabled.  */
5042
218k
        dst->symbol.flags = BSF_DEBUGGING;
5043
218k
        dst->symbol.value = (src->u.syment.n_value);
5044
218k
        break;
5045
345k
      }
5046
5047
345k
    dst->native = src;
5048
345k
    dst->symbol.udata.i = 0;
5049
345k
    dst->lineno = NULL;
5050
5051
345k
    this_index += (src->u.syment.n_numaux) + 1;
5052
345k
    dst++;
5053
345k
    number_of_symbols++;
5054
345k
  }
5055
1.21k
    }
5056
5057
1.21k
  obj_symbols (abfd) = cached_area;
5058
1.21k
  obj_raw_syments (abfd) = native_symbols;
5059
5060
1.21k
  abfd->symcount = number_of_symbols;
5061
1.21k
  obj_convert (abfd) = table_ptr;
5062
  /* Slurp the line tables for each section too.  */
5063
1.21k
  {
5064
1.21k
    asection *p;
5065
5066
1.21k
    p = abfd->sections;
5067
3.87k
    while (p)
5068
3.39k
      {
5069
3.39k
  if (! coff_slurp_line_table (abfd, p))
5070
736
    return false;
5071
2.66k
  p = p->next;
5072
2.66k
      }
5073
1.21k
  }
5074
5075
480
  return ret;
5076
1.21k
}
pei-aarch64.c:coff_slurp_symbol_table
Line
Count
Source
4704
1.67k
{
4705
1.67k
  combined_entry_type *native_symbols;
4706
1.67k
  coff_symbol_type *cached_area;
4707
1.67k
  unsigned int *table_ptr;
4708
1.67k
  unsigned int number_of_symbols = 0;
4709
1.67k
  bool ret = true;
4710
1.67k
  size_t amt;
4711
4712
1.67k
  if (obj_symbols (abfd))
4713
114
    return true;
4714
4715
  /* Read in the symbol table.  */
4716
1.56k
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4717
684
    return false;
4718
4719
  /* Allocate enough room for all the symbols in cached form.  */
4720
877
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4721
877
       sizeof (*cached_area), &amt))
4722
0
    {
4723
0
      bfd_set_error (bfd_error_file_too_big);
4724
0
      return false;
4725
0
    }
4726
877
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4727
877
  if (cached_area == NULL)
4728
0
    return false;
4729
4730
877
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4731
877
       sizeof (*table_ptr), &amt))
4732
0
    {
4733
0
      bfd_set_error (bfd_error_file_too_big);
4734
0
      return false;
4735
0
    }
4736
877
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4737
877
  if (table_ptr == NULL)
4738
0
    return false;
4739
877
  else
4740
877
    {
4741
877
      coff_symbol_type *dst = cached_area;
4742
877
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4743
877
      unsigned int this_index = 0;
4744
4745
220k
      while (this_index < last_native_index)
4746
220k
  {
4747
220k
    combined_entry_type *src = native_symbols + this_index;
4748
220k
    table_ptr[this_index] = number_of_symbols;
4749
4750
220k
    dst->symbol.the_bfd = abfd;
4751
220k
    BFD_ASSERT (src->is_sym);
4752
220k
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4753
    /* We use the native name field to point to the cached field.  */
4754
220k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4755
220k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4756
220k
                 src->u.syment.n_scnum);
4757
220k
    dst->symbol.flags = 0;
4758
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4759
220k
    dst->symbol.value = 0;
4760
220k
    dst->done_lineno = false;
4761
4762
220k
    switch (src->u.syment.n_sclass)
4763
220k
      {
4764
3.18k
      case C_EXT:
4765
3.31k
      case C_WEAKEXT:
4766
#if defined ARM
4767
      case C_THUMBEXT:
4768
      case C_THUMBEXTFUNC:
4769
#endif
4770
#ifdef RS6000COFF_C
4771
      case C_HIDEXT:
4772
#ifndef AIX_WEAK_SUPPORT
4773
      case C_AIX_WEAKEXT:
4774
#endif
4775
#endif
4776
3.31k
#ifdef C_SYSTEM
4777
4.76k
      case C_SYSTEM: /* System Wide variable.  */
4778
4.76k
#endif
4779
4.76k
#ifdef COFF_WITH_PE
4780
      /* In PE, 0x68 (104) denotes a section symbol.  */
4781
4.84k
      case C_SECTION:
4782
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4783
7.90k
      case C_NT_WEAK:
4784
7.90k
#endif
4785
7.90k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4786
7.90k
    {
4787
7.01k
    case COFF_SYMBOL_GLOBAL:
4788
7.01k
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4789
7.01k
#if defined COFF_WITH_PE
4790
      /* PE sets the symbol to a value relative to the
4791
         start of the section.  */
4792
7.01k
      dst->symbol.value = src->u.syment.n_value;
4793
#else
4794
      dst->symbol.value = (src->u.syment.n_value
4795
               - dst->symbol.section->vma);
4796
#endif
4797
7.01k
      if (ISFCN ((src->u.syment.n_type)))
4798
        /* A function ext does not go at the end of a
4799
           file.  */
4800
309
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4801
7.01k
      break;
4802
4803
583
    case COFF_SYMBOL_COMMON:
4804
583
      dst->symbol.section = bfd_com_section_ptr;
4805
583
      dst->symbol.value = src->u.syment.n_value;
4806
583
      break;
4807
4808
313
    case COFF_SYMBOL_UNDEFINED:
4809
313
      dst->symbol.section = bfd_und_section_ptr;
4810
313
      dst->symbol.value = 0;
4811
313
      break;
4812
4813
0
    case COFF_SYMBOL_PE_SECTION:
4814
0
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4815
0
      dst->symbol.value = 0;
4816
0
      break;
4817
4818
0
    case COFF_SYMBOL_LOCAL:
4819
0
      dst->symbol.flags = BSF_LOCAL;
4820
0
#if defined COFF_WITH_PE
4821
      /* PE sets the symbol to a value relative to the
4822
         start of the section.  */
4823
0
      dst->symbol.value = src->u.syment.n_value;
4824
#else
4825
      dst->symbol.value = (src->u.syment.n_value
4826
               - dst->symbol.section->vma);
4827
#endif
4828
0
      if (ISFCN ((src->u.syment.n_type)))
4829
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4830
0
      break;
4831
7.90k
    }
4832
4833
#ifdef RS6000COFF_C
4834
        /* A symbol with a csect entry should not go at the end.  */
4835
        if (src->u.syment.n_numaux > 0)
4836
    dst->symbol.flags |= BSF_NOT_AT_END;
4837
#endif
4838
4839
7.90k
#ifdef COFF_WITH_PE
4840
7.90k
        if (src->u.syment.n_sclass == C_NT_WEAK)
4841
3.06k
    dst->symbol.flags |= BSF_WEAK;
4842
4843
7.90k
        if (src->u.syment.n_sclass == C_SECTION
4844
7.90k
      && src->u.syment.n_scnum > 0)
4845
0
    dst->symbol.flags = BSF_LOCAL;
4846
7.90k
#endif
4847
7.90k
        if (src->u.syment.n_sclass == C_WEAKEXT
4848
#ifdef RS6000COFF_C
4849
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4850
#endif
4851
7.90k
      )
4852
135
    dst->symbol.flags |= BSF_WEAK;
4853
4854
7.90k
        break;
4855
4856
3.36k
      case C_STAT:  /* Static.  */
4857
#if defined ARM
4858
      case C_THUMBSTAT:    /* Thumb static.  */
4859
      case C_THUMBLABEL:   /* Thumb label.  */
4860
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4861
#endif
4862
#ifdef RS6000COFF_C
4863
      case C_DWARF:  /* A label in a dwarf section.  */
4864
      case C_INFO:   /* A label in a comment section.  */
4865
#endif
4866
8.99k
      case C_LABEL:  /* Label.  */
4867
8.99k
        if (src->u.syment.n_scnum == N_DEBUG)
4868
3
    dst->symbol.flags = BSF_DEBUGGING;
4869
8.99k
        else
4870
8.99k
    dst->symbol.flags = BSF_LOCAL;
4871
4872
        /* Base the value as an index from the base of the
4873
     section, if there is one.  */
4874
8.99k
        if (dst->symbol.section)
4875
8.99k
    {
4876
8.99k
#if defined COFF_WITH_PE
4877
      /* PE sets the symbol to a value relative to the
4878
         start of the section.  */
4879
8.99k
      dst->symbol.value = src->u.syment.n_value;
4880
#else
4881
      dst->symbol.value = (src->u.syment.n_value
4882
               - dst->symbol.section->vma);
4883
#endif
4884
8.99k
    }
4885
0
        else
4886
0
    dst->symbol.value = src->u.syment.n_value;
4887
8.99k
        break;
4888
4889
1.68k
      case C_FILE: /* File name.  */
4890
1.68k
        dst->symbol.flags = BSF_FILE;
4891
        /* Fall through.  */
4892
3.09k
      case C_MOS:   /* Member of structure.  */
4893
3.76k
      case C_EOS:   /* End of structure.  */
4894
4.54k
      case C_REGPARM: /* Register parameter.  */
4895
5.88k
      case C_REG:   /* register variable.  */
4896
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4897
6.28k
      case C_TPDEF: /* Type definition.  */
4898
7.61k
      case C_ARG:
4899
15.6k
      case C_AUTO: /* Automatic variable.  */
4900
16.5k
      case C_FIELD: /* Bit field.  */
4901
17.3k
      case C_ENTAG: /* Enumeration tag.  */
4902
18.9k
      case C_MOE:   /* Member of enumeration.  */
4903
20.8k
      case C_MOU:   /* Member of union.  */
4904
22.2k
      case C_UNTAG: /* Union tag.  */
4905
24.9k
      case C_STRTAG: /* Structure tag.  */
4906
#ifdef RS6000COFF_C
4907
      case C_GSYM:
4908
      case C_LSYM:
4909
      case C_PSYM:
4910
      case C_RSYM:
4911
      case C_RPSYM:
4912
      case C_STSYM:
4913
      case C_TCSYM:
4914
      case C_BCOMM:
4915
      case C_ECOML:
4916
      case C_ECOMM:
4917
      case C_DECL:
4918
      case C_ENTRY:
4919
      case C_FUN:
4920
      case C_ESTAT:
4921
#endif
4922
24.9k
        dst->symbol.flags |= BSF_DEBUGGING;
4923
24.9k
        dst->symbol.value = (src->u.syment.n_value);
4924
24.9k
        break;
4925
4926
#ifdef RS6000COFF_C
4927
      case C_BINCL: /* Beginning of include file.  */
4928
      case C_EINCL: /* Ending of include file.  */
4929
        /* The value is actually a pointer into the line numbers
4930
     of the file.  We locate the line number entry, and
4931
     set the section to the section which contains it, and
4932
     the value to the index in that section.  */
4933
        {
4934
    asection *sec;
4935
4936
    dst->symbol.flags = BSF_DEBUGGING;
4937
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4938
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4939
          && ((file_ptr) (sec->line_filepos
4940
              + sec->lineno_count * bfd_coff_linesz (abfd))
4941
        > (file_ptr) src->u.syment.n_value))
4942
        break;
4943
    if (sec == NULL)
4944
      dst->symbol.value = 0;
4945
    else
4946
      {
4947
        dst->symbol.section = sec;
4948
        dst->symbol.value = ((src->u.syment.n_value
4949
            - sec->line_filepos)
4950
           / bfd_coff_linesz (abfd));
4951
        src->fix_line = 1;
4952
      }
4953
        }
4954
        break;
4955
4956
      case C_BSTAT:
4957
        dst->symbol.flags = BSF_DEBUGGING;
4958
4959
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4960
    dst->symbol.value = 0;
4961
        else
4962
    {
4963
      /* The value is actually a symbol index.  Save a pointer
4964
         to the symbol instead of the index.  FIXME: This
4965
         should use a union.  */
4966
      src->u.syment.n_value
4967
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4968
      dst->symbol.value = src->u.syment.n_value;
4969
      src->fix_value = 1;
4970
    }
4971
        break;
4972
#endif
4973
4974
611
      case C_BLOCK: /* ".bb" or ".eb".  */
4975
4.66k
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4976
5.47k
      case C_EFCN: /* Physical end of function.  */
4977
5.47k
#if defined COFF_WITH_PE
4978
        /* PE sets the symbol to a value relative to the start
4979
     of the section.  */
4980
5.47k
        dst->symbol.value = src->u.syment.n_value;
4981
5.47k
        if (strcmp (dst->symbol.name, ".bf") != 0)
4982
5.47k
    {
4983
      /* PE uses funny values for .ef and .lf; don't
4984
         relocate them.  */
4985
5.47k
      dst->symbol.flags = BSF_DEBUGGING;
4986
5.47k
    }
4987
1
        else
4988
1
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4989
#else
4990
        /* Base the value as an index from the base of the
4991
     section.  */
4992
        dst->symbol.flags = BSF_LOCAL;
4993
        dst->symbol.value = (src->u.syment.n_value
4994
           - dst->symbol.section->vma);
4995
#endif
4996
5.47k
        break;
4997
4998
1.14k
      case C_STATLAB: /* Static load time label.  */
4999
1.14k
        dst->symbol.value = src->u.syment.n_value;
5000
1.14k
        dst->symbol.flags = BSF_GLOBAL;
5001
1.14k
        break;
5002
5003
130k
      case C_NULL:
5004
        /* PE DLLs sometimes have zeroed out symbols for some
5005
     reason.  Just ignore them without a warning.  */
5006
130k
        if (src->u.syment.n_type == 0
5007
130k
      && src->u.syment.n_value == 0
5008
130k
      && src->u.syment.n_scnum == 0)
5009
43.5k
    break;
5010
#ifdef RS6000COFF_C
5011
        /* XCOFF specific: deleted entry.  */
5012
        if (src->u.syment.n_value == C_NULL_VALUE)
5013
    break;
5014
#endif
5015
        /* Fall through.  */
5016
86.8k
      case C_EXTDEF: /* External definition.  */
5017
87.1k
      case C_ULABEL: /* Undefined label.  */
5018
87.3k
      case C_USTATIC: /* Undefined static.  */
5019
#ifndef COFF_WITH_PE
5020
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5021
         class to represent a section symbol.  */
5022
      case C_LINE:  /* line # reformatted as symbol table entry.  */
5023
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5024
      case C_ALIAS: /* Duplicate tag.  */
5025
#endif
5026
        /* New storage classes for TI COFF.  */
5027
#ifdef TICOFF
5028
      case C_UEXT:  /* Tentative external definition.  */
5029
#endif
5030
87.4k
      case C_EXTLAB: /* External load time label.  */
5031
127k
      default:
5032
127k
        _bfd_error_handler
5033
    /* xgettext:c-format */
5034
127k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5035
127k
     abfd, src->u.syment.n_sclass,
5036
127k
     dst->symbol.section->name, dst->symbol.name);
5037
127k
        ret = false;
5038
        /* Fall through.  */
5039
128k
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5040
        /* PR 20722: These symbols can also be generated by
5041
     building DLLs with --gc-sections enabled.  */
5042
128k
        dst->symbol.flags = BSF_DEBUGGING;
5043
128k
        dst->symbol.value = (src->u.syment.n_value);
5044
128k
        break;
5045
220k
      }
5046
5047
220k
    dst->native = src;
5048
220k
    dst->symbol.udata.i = 0;
5049
220k
    dst->lineno = NULL;
5050
5051
220k
    this_index += (src->u.syment.n_numaux) + 1;
5052
220k
    dst++;
5053
220k
    number_of_symbols++;
5054
220k
  }
5055
877
    }
5056
5057
877
  obj_symbols (abfd) = cached_area;
5058
877
  obj_raw_syments (abfd) = native_symbols;
5059
5060
877
  abfd->symcount = number_of_symbols;
5061
877
  obj_convert (abfd) = table_ptr;
5062
  /* Slurp the line tables for each section too.  */
5063
877
  {
5064
877
    asection *p;
5065
5066
877
    p = abfd->sections;
5067
2.06k
    while (p)
5068
1.90k
      {
5069
1.90k
  if (! coff_slurp_line_table (abfd, p))
5070
719
    return false;
5071
1.18k
  p = p->next;
5072
1.18k
      }
5073
877
  }
5074
5075
158
  return ret;
5076
877
}
pei-ia64.c:coff_slurp_symbol_table
Line
Count
Source
4704
1.44k
{
4705
1.44k
  combined_entry_type *native_symbols;
4706
1.44k
  coff_symbol_type *cached_area;
4707
1.44k
  unsigned int *table_ptr;
4708
1.44k
  unsigned int number_of_symbols = 0;
4709
1.44k
  bool ret = true;
4710
1.44k
  size_t amt;
4711
4712
1.44k
  if (obj_symbols (abfd))
4713
40
    return true;
4714
4715
  /* Read in the symbol table.  */
4716
1.40k
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4717
604
    return false;
4718
4719
  /* Allocate enough room for all the symbols in cached form.  */
4720
800
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4721
800
       sizeof (*cached_area), &amt))
4722
0
    {
4723
0
      bfd_set_error (bfd_error_file_too_big);
4724
0
      return false;
4725
0
    }
4726
800
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4727
800
  if (cached_area == NULL)
4728
0
    return false;
4729
4730
800
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4731
800
       sizeof (*table_ptr), &amt))
4732
0
    {
4733
0
      bfd_set_error (bfd_error_file_too_big);
4734
0
      return false;
4735
0
    }
4736
800
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4737
800
  if (table_ptr == NULL)
4738
0
    return false;
4739
800
  else
4740
800
    {
4741
800
      coff_symbol_type *dst = cached_area;
4742
800
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4743
800
      unsigned int this_index = 0;
4744
4745
431k
      while (this_index < last_native_index)
4746
430k
  {
4747
430k
    combined_entry_type *src = native_symbols + this_index;
4748
430k
    table_ptr[this_index] = number_of_symbols;
4749
4750
430k
    dst->symbol.the_bfd = abfd;
4751
430k
    BFD_ASSERT (src->is_sym);
4752
430k
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4753
    /* We use the native name field to point to the cached field.  */
4754
430k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4755
430k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4756
430k
                 src->u.syment.n_scnum);
4757
430k
    dst->symbol.flags = 0;
4758
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4759
430k
    dst->symbol.value = 0;
4760
430k
    dst->done_lineno = false;
4761
4762
430k
    switch (src->u.syment.n_sclass)
4763
430k
      {
4764
9.01k
      case C_EXT:
4765
9.25k
      case C_WEAKEXT:
4766
#if defined ARM
4767
      case C_THUMBEXT:
4768
      case C_THUMBEXTFUNC:
4769
#endif
4770
#ifdef RS6000COFF_C
4771
      case C_HIDEXT:
4772
#ifndef AIX_WEAK_SUPPORT
4773
      case C_AIX_WEAKEXT:
4774
#endif
4775
#endif
4776
9.25k
#ifdef C_SYSTEM
4777
9.90k
      case C_SYSTEM: /* System Wide variable.  */
4778
9.90k
#endif
4779
9.90k
#ifdef COFF_WITH_PE
4780
      /* In PE, 0x68 (104) denotes a section symbol.  */
4781
10.2k
      case C_SECTION:
4782
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4783
14.9k
      case C_NT_WEAK:
4784
14.9k
#endif
4785
14.9k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4786
14.9k
    {
4787
13.3k
    case COFF_SYMBOL_GLOBAL:
4788
13.3k
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4789
13.3k
#if defined COFF_WITH_PE
4790
      /* PE sets the symbol to a value relative to the
4791
         start of the section.  */
4792
13.3k
      dst->symbol.value = src->u.syment.n_value;
4793
#else
4794
      dst->symbol.value = (src->u.syment.n_value
4795
               - dst->symbol.section->vma);
4796
#endif
4797
13.3k
      if (ISFCN ((src->u.syment.n_type)))
4798
        /* A function ext does not go at the end of a
4799
           file.  */
4800
760
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4801
13.3k
      break;
4802
4803
858
    case COFF_SYMBOL_COMMON:
4804
858
      dst->symbol.section = bfd_com_section_ptr;
4805
858
      dst->symbol.value = src->u.syment.n_value;
4806
858
      break;
4807
4808
720
    case COFF_SYMBOL_UNDEFINED:
4809
720
      dst->symbol.section = bfd_und_section_ptr;
4810
720
      dst->symbol.value = 0;
4811
720
      break;
4812
4813
0
    case COFF_SYMBOL_PE_SECTION:
4814
0
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4815
0
      dst->symbol.value = 0;
4816
0
      break;
4817
4818
0
    case COFF_SYMBOL_LOCAL:
4819
0
      dst->symbol.flags = BSF_LOCAL;
4820
0
#if defined COFF_WITH_PE
4821
      /* PE sets the symbol to a value relative to the
4822
         start of the section.  */
4823
0
      dst->symbol.value = src->u.syment.n_value;
4824
#else
4825
      dst->symbol.value = (src->u.syment.n_value
4826
               - dst->symbol.section->vma);
4827
#endif
4828
0
      if (ISFCN ((src->u.syment.n_type)))
4829
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4830
0
      break;
4831
14.9k
    }
4832
4833
#ifdef RS6000COFF_C
4834
        /* A symbol with a csect entry should not go at the end.  */
4835
        if (src->u.syment.n_numaux > 0)
4836
    dst->symbol.flags |= BSF_NOT_AT_END;
4837
#endif
4838
4839
14.9k
#ifdef COFF_WITH_PE
4840
14.9k
        if (src->u.syment.n_sclass == C_NT_WEAK)
4841
4.71k
    dst->symbol.flags |= BSF_WEAK;
4842
4843
14.9k
        if (src->u.syment.n_sclass == C_SECTION
4844
14.9k
      && src->u.syment.n_scnum > 0)
4845
0
    dst->symbol.flags = BSF_LOCAL;
4846
14.9k
#endif
4847
14.9k
        if (src->u.syment.n_sclass == C_WEAKEXT
4848
#ifdef RS6000COFF_C
4849
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4850
#endif
4851
14.9k
      )
4852
238
    dst->symbol.flags |= BSF_WEAK;
4853
4854
14.9k
        break;
4855
4856
5.63k
      case C_STAT:  /* Static.  */
4857
#if defined ARM
4858
      case C_THUMBSTAT:    /* Thumb static.  */
4859
      case C_THUMBLABEL:   /* Thumb label.  */
4860
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4861
#endif
4862
#ifdef RS6000COFF_C
4863
      case C_DWARF:  /* A label in a dwarf section.  */
4864
      case C_INFO:   /* A label in a comment section.  */
4865
#endif
4866
6.93k
      case C_LABEL:  /* Label.  */
4867
6.93k
        if (src->u.syment.n_scnum == N_DEBUG)
4868
2
    dst->symbol.flags = BSF_DEBUGGING;
4869
6.93k
        else
4870
6.93k
    dst->symbol.flags = BSF_LOCAL;
4871
4872
        /* Base the value as an index from the base of the
4873
     section, if there is one.  */
4874
6.93k
        if (dst->symbol.section)
4875
6.93k
    {
4876
6.93k
#if defined COFF_WITH_PE
4877
      /* PE sets the symbol to a value relative to the
4878
         start of the section.  */
4879
6.93k
      dst->symbol.value = src->u.syment.n_value;
4880
#else
4881
      dst->symbol.value = (src->u.syment.n_value
4882
               - dst->symbol.section->vma);
4883
#endif
4884
6.93k
    }
4885
0
        else
4886
0
    dst->symbol.value = src->u.syment.n_value;
4887
6.93k
        break;
4888
4889
2.22k
      case C_FILE: /* File name.  */
4890
2.22k
        dst->symbol.flags = BSF_FILE;
4891
        /* Fall through.  */
4892
3.78k
      case C_MOS:   /* Member of structure.  */
4893
4.90k
      case C_EOS:   /* End of structure.  */
4894
5.74k
      case C_REGPARM: /* Register parameter.  */
4895
8.03k
      case C_REG:   /* register variable.  */
4896
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4897
9.22k
      case C_TPDEF: /* Type definition.  */
4898
11.1k
      case C_ARG:
4899
22.5k
      case C_AUTO: /* Automatic variable.  */
4900
23.7k
      case C_FIELD: /* Bit field.  */
4901
24.9k
      case C_ENTAG: /* Enumeration tag.  */
4902
27.1k
      case C_MOE:   /* Member of enumeration.  */
4903
29.1k
      case C_MOU:   /* Member of union.  */
4904
30.1k
      case C_UNTAG: /* Union tag.  */
4905
31.5k
      case C_STRTAG: /* Structure tag.  */
4906
#ifdef RS6000COFF_C
4907
      case C_GSYM:
4908
      case C_LSYM:
4909
      case C_PSYM:
4910
      case C_RSYM:
4911
      case C_RPSYM:
4912
      case C_STSYM:
4913
      case C_TCSYM:
4914
      case C_BCOMM:
4915
      case C_ECOML:
4916
      case C_ECOMM:
4917
      case C_DECL:
4918
      case C_ENTRY:
4919
      case C_FUN:
4920
      case C_ESTAT:
4921
#endif
4922
31.5k
        dst->symbol.flags |= BSF_DEBUGGING;
4923
31.5k
        dst->symbol.value = (src->u.syment.n_value);
4924
31.5k
        break;
4925
4926
#ifdef RS6000COFF_C
4927
      case C_BINCL: /* Beginning of include file.  */
4928
      case C_EINCL: /* Ending of include file.  */
4929
        /* The value is actually a pointer into the line numbers
4930
     of the file.  We locate the line number entry, and
4931
     set the section to the section which contains it, and
4932
     the value to the index in that section.  */
4933
        {
4934
    asection *sec;
4935
4936
    dst->symbol.flags = BSF_DEBUGGING;
4937
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4938
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4939
          && ((file_ptr) (sec->line_filepos
4940
              + sec->lineno_count * bfd_coff_linesz (abfd))
4941
        > (file_ptr) src->u.syment.n_value))
4942
        break;
4943
    if (sec == NULL)
4944
      dst->symbol.value = 0;
4945
    else
4946
      {
4947
        dst->symbol.section = sec;
4948
        dst->symbol.value = ((src->u.syment.n_value
4949
            - sec->line_filepos)
4950
           / bfd_coff_linesz (abfd));
4951
        src->fix_line = 1;
4952
      }
4953
        }
4954
        break;
4955
4956
      case C_BSTAT:
4957
        dst->symbol.flags = BSF_DEBUGGING;
4958
4959
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4960
    dst->symbol.value = 0;
4961
        else
4962
    {
4963
      /* The value is actually a symbol index.  Save a pointer
4964
         to the symbol instead of the index.  FIXME: This
4965
         should use a union.  */
4966
      src->u.syment.n_value
4967
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4968
      dst->symbol.value = src->u.syment.n_value;
4969
      src->fix_value = 1;
4970
    }
4971
        break;
4972
#endif
4973
4974
685
      case C_BLOCK: /* ".bb" or ".eb".  */
4975
6.32k
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4976
8.95k
      case C_EFCN: /* Physical end of function.  */
4977
8.95k
#if defined COFF_WITH_PE
4978
        /* PE sets the symbol to a value relative to the start
4979
     of the section.  */
4980
8.95k
        dst->symbol.value = src->u.syment.n_value;
4981
8.95k
        if (strcmp (dst->symbol.name, ".bf") != 0)
4982
8.95k
    {
4983
      /* PE uses funny values for .ef and .lf; don't
4984
         relocate them.  */
4985
8.95k
      dst->symbol.flags = BSF_DEBUGGING;
4986
8.95k
    }
4987
3
        else
4988
3
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4989
#else
4990
        /* Base the value as an index from the base of the
4991
     section.  */
4992
        dst->symbol.flags = BSF_LOCAL;
4993
        dst->symbol.value = (src->u.syment.n_value
4994
           - dst->symbol.section->vma);
4995
#endif
4996
8.95k
        break;
4997
4998
592
      case C_STATLAB: /* Static load time label.  */
4999
592
        dst->symbol.value = src->u.syment.n_value;
5000
592
        dst->symbol.flags = BSF_GLOBAL;
5001
592
        break;
5002
5003
294k
      case C_NULL:
5004
        /* PE DLLs sometimes have zeroed out symbols for some
5005
     reason.  Just ignore them without a warning.  */
5006
294k
        if (src->u.syment.n_type == 0
5007
294k
      && src->u.syment.n_value == 0
5008
294k
      && src->u.syment.n_scnum == 0)
5009
120k
    break;
5010
#ifdef RS6000COFF_C
5011
        /* XCOFF specific: deleted entry.  */
5012
        if (src->u.syment.n_value == C_NULL_VALUE)
5013
    break;
5014
#endif
5015
        /* Fall through.  */
5016
176k
      case C_EXTDEF: /* External definition.  */
5017
176k
      case C_ULABEL: /* Undefined label.  */
5018
176k
      case C_USTATIC: /* Undefined static.  */
5019
#ifndef COFF_WITH_PE
5020
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5021
         class to represent a section symbol.  */
5022
      case C_LINE:  /* line # reformatted as symbol table entry.  */
5023
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5024
      case C_ALIAS: /* Duplicate tag.  */
5025
#endif
5026
        /* New storage classes for TI COFF.  */
5027
#ifdef TICOFF
5028
      case C_UEXT:  /* Tentative external definition.  */
5029
#endif
5030
176k
      case C_EXTLAB: /* External load time label.  */
5031
246k
      default:
5032
246k
        _bfd_error_handler
5033
    /* xgettext:c-format */
5034
246k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5035
246k
     abfd, src->u.syment.n_sclass,
5036
246k
     dst->symbol.section->name, dst->symbol.name);
5037
246k
        ret = false;
5038
        /* Fall through.  */
5039
246k
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5040
        /* PR 20722: These symbols can also be generated by
5041
     building DLLs with --gc-sections enabled.  */
5042
246k
        dst->symbol.flags = BSF_DEBUGGING;
5043
246k
        dst->symbol.value = (src->u.syment.n_value);
5044
246k
        break;
5045
430k
      }
5046
5047
430k
    dst->native = src;
5048
430k
    dst->symbol.udata.i = 0;
5049
430k
    dst->lineno = NULL;
5050
5051
430k
    this_index += (src->u.syment.n_numaux) + 1;
5052
430k
    dst++;
5053
430k
    number_of_symbols++;
5054
430k
  }
5055
800
    }
5056
5057
800
  obj_symbols (abfd) = cached_area;
5058
800
  obj_raw_syments (abfd) = native_symbols;
5059
5060
800
  abfd->symcount = number_of_symbols;
5061
800
  obj_convert (abfd) = table_ptr;
5062
  /* Slurp the line tables for each section too.  */
5063
800
  {
5064
800
    asection *p;
5065
5066
800
    p = abfd->sections;
5067
2.30k
    while (p)
5068
2.12k
      {
5069
2.12k
  if (! coff_slurp_line_table (abfd, p))
5070
620
    return false;
5071
1.50k
  p = p->next;
5072
1.50k
      }
5073
800
  }
5074
5075
180
  return ret;
5076
800
}
pei-loongarch64.c:coff_slurp_symbol_table
Line
Count
Source
4704
1.72k
{
4705
1.72k
  combined_entry_type *native_symbols;
4706
1.72k
  coff_symbol_type *cached_area;
4707
1.72k
  unsigned int *table_ptr;
4708
1.72k
  unsigned int number_of_symbols = 0;
4709
1.72k
  bool ret = true;
4710
1.72k
  size_t amt;
4711
4712
1.72k
  if (obj_symbols (abfd))
4713
141
    return true;
4714
4715
  /* Read in the symbol table.  */
4716
1.58k
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4717
665
    return false;
4718
4719
  /* Allocate enough room for all the symbols in cached form.  */
4720
917
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4721
917
       sizeof (*cached_area), &amt))
4722
0
    {
4723
0
      bfd_set_error (bfd_error_file_too_big);
4724
0
      return false;
4725
0
    }
4726
917
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4727
917
  if (cached_area == NULL)
4728
0
    return false;
4729
4730
917
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4731
917
       sizeof (*table_ptr), &amt))
4732
0
    {
4733
0
      bfd_set_error (bfd_error_file_too_big);
4734
0
      return false;
4735
0
    }
4736
917
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4737
917
  if (table_ptr == NULL)
4738
0
    return false;
4739
917
  else
4740
917
    {
4741
917
      coff_symbol_type *dst = cached_area;
4742
917
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4743
917
      unsigned int this_index = 0;
4744
4745
266k
      while (this_index < last_native_index)
4746
265k
  {
4747
265k
    combined_entry_type *src = native_symbols + this_index;
4748
265k
    table_ptr[this_index] = number_of_symbols;
4749
4750
265k
    dst->symbol.the_bfd = abfd;
4751
265k
    BFD_ASSERT (src->is_sym);
4752
265k
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4753
    /* We use the native name field to point to the cached field.  */
4754
265k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4755
265k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4756
265k
                 src->u.syment.n_scnum);
4757
265k
    dst->symbol.flags = 0;
4758
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4759
265k
    dst->symbol.value = 0;
4760
265k
    dst->done_lineno = false;
4761
4762
265k
    switch (src->u.syment.n_sclass)
4763
265k
      {
4764
3.29k
      case C_EXT:
4765
3.61k
      case C_WEAKEXT:
4766
#if defined ARM
4767
      case C_THUMBEXT:
4768
      case C_THUMBEXTFUNC:
4769
#endif
4770
#ifdef RS6000COFF_C
4771
      case C_HIDEXT:
4772
#ifndef AIX_WEAK_SUPPORT
4773
      case C_AIX_WEAKEXT:
4774
#endif
4775
#endif
4776
3.61k
#ifdef C_SYSTEM
4777
4.28k
      case C_SYSTEM: /* System Wide variable.  */
4778
4.28k
#endif
4779
4.28k
#ifdef COFF_WITH_PE
4780
      /* In PE, 0x68 (104) denotes a section symbol.  */
4781
4.50k
      case C_SECTION:
4782
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4783
8.88k
      case C_NT_WEAK:
4784
8.88k
#endif
4785
8.88k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4786
8.88k
    {
4787
7.65k
    case COFF_SYMBOL_GLOBAL:
4788
7.65k
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4789
7.65k
#if defined COFF_WITH_PE
4790
      /* PE sets the symbol to a value relative to the
4791
         start of the section.  */
4792
7.65k
      dst->symbol.value = src->u.syment.n_value;
4793
#else
4794
      dst->symbol.value = (src->u.syment.n_value
4795
               - dst->symbol.section->vma);
4796
#endif
4797
7.65k
      if (ISFCN ((src->u.syment.n_type)))
4798
        /* A function ext does not go at the end of a
4799
           file.  */
4800
272
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4801
7.65k
      break;
4802
4803
768
    case COFF_SYMBOL_COMMON:
4804
768
      dst->symbol.section = bfd_com_section_ptr;
4805
768
      dst->symbol.value = src->u.syment.n_value;
4806
768
      break;
4807
4808
457
    case COFF_SYMBOL_UNDEFINED:
4809
457
      dst->symbol.section = bfd_und_section_ptr;
4810
457
      dst->symbol.value = 0;
4811
457
      break;
4812
4813
0
    case COFF_SYMBOL_PE_SECTION:
4814
0
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4815
0
      dst->symbol.value = 0;
4816
0
      break;
4817
4818
0
    case COFF_SYMBOL_LOCAL:
4819
0
      dst->symbol.flags = BSF_LOCAL;
4820
0
#if defined COFF_WITH_PE
4821
      /* PE sets the symbol to a value relative to the
4822
         start of the section.  */
4823
0
      dst->symbol.value = src->u.syment.n_value;
4824
#else
4825
      dst->symbol.value = (src->u.syment.n_value
4826
               - dst->symbol.section->vma);
4827
#endif
4828
0
      if (ISFCN ((src->u.syment.n_type)))
4829
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4830
0
      break;
4831
8.88k
    }
4832
4833
#ifdef RS6000COFF_C
4834
        /* A symbol with a csect entry should not go at the end.  */
4835
        if (src->u.syment.n_numaux > 0)
4836
    dst->symbol.flags |= BSF_NOT_AT_END;
4837
#endif
4838
4839
8.88k
#ifdef COFF_WITH_PE
4840
8.88k
        if (src->u.syment.n_sclass == C_NT_WEAK)
4841
4.37k
    dst->symbol.flags |= BSF_WEAK;
4842
4843
8.88k
        if (src->u.syment.n_sclass == C_SECTION
4844
8.88k
      && src->u.syment.n_scnum > 0)
4845
0
    dst->symbol.flags = BSF_LOCAL;
4846
8.88k
#endif
4847
8.88k
        if (src->u.syment.n_sclass == C_WEAKEXT
4848
#ifdef RS6000COFF_C
4849
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4850
#endif
4851
8.88k
      )
4852
319
    dst->symbol.flags |= BSF_WEAK;
4853
4854
8.88k
        break;
4855
4856
5.01k
      case C_STAT:  /* Static.  */
4857
#if defined ARM
4858
      case C_THUMBSTAT:    /* Thumb static.  */
4859
      case C_THUMBLABEL:   /* Thumb label.  */
4860
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4861
#endif
4862
#ifdef RS6000COFF_C
4863
      case C_DWARF:  /* A label in a dwarf section.  */
4864
      case C_INFO:   /* A label in a comment section.  */
4865
#endif
4866
5.52k
      case C_LABEL:  /* Label.  */
4867
5.52k
        if (src->u.syment.n_scnum == N_DEBUG)
4868
1
    dst->symbol.flags = BSF_DEBUGGING;
4869
5.52k
        else
4870
5.52k
    dst->symbol.flags = BSF_LOCAL;
4871
4872
        /* Base the value as an index from the base of the
4873
     section, if there is one.  */
4874
5.52k
        if (dst->symbol.section)
4875
5.52k
    {
4876
5.52k
#if defined COFF_WITH_PE
4877
      /* PE sets the symbol to a value relative to the
4878
         start of the section.  */
4879
5.52k
      dst->symbol.value = src->u.syment.n_value;
4880
#else
4881
      dst->symbol.value = (src->u.syment.n_value
4882
               - dst->symbol.section->vma);
4883
#endif
4884
5.52k
    }
4885
0
        else
4886
0
    dst->symbol.value = src->u.syment.n_value;
4887
5.52k
        break;
4888
4889
2.27k
      case C_FILE: /* File name.  */
4890
2.27k
        dst->symbol.flags = BSF_FILE;
4891
        /* Fall through.  */
4892
3.71k
      case C_MOS:   /* Member of structure.  */
4893
4.75k
      case C_EOS:   /* End of structure.  */
4894
5.36k
      case C_REGPARM: /* Register parameter.  */
4895
7.81k
      case C_REG:   /* register variable.  */
4896
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4897
8.55k
      case C_TPDEF: /* Type definition.  */
4898
10.2k
      case C_ARG:
4899
18.0k
      case C_AUTO: /* Automatic variable.  */
4900
18.8k
      case C_FIELD: /* Bit field.  */
4901
19.3k
      case C_ENTAG: /* Enumeration tag.  */
4902
20.6k
      case C_MOE:   /* Member of enumeration.  */
4903
21.8k
      case C_MOU:   /* Member of union.  */
4904
22.6k
      case C_UNTAG: /* Union tag.  */
4905
24.0k
      case C_STRTAG: /* Structure tag.  */
4906
#ifdef RS6000COFF_C
4907
      case C_GSYM:
4908
      case C_LSYM:
4909
      case C_PSYM:
4910
      case C_RSYM:
4911
      case C_RPSYM:
4912
      case C_STSYM:
4913
      case C_TCSYM:
4914
      case C_BCOMM:
4915
      case C_ECOML:
4916
      case C_ECOMM:
4917
      case C_DECL:
4918
      case C_ENTRY:
4919
      case C_FUN:
4920
      case C_ESTAT:
4921
#endif
4922
24.0k
        dst->symbol.flags |= BSF_DEBUGGING;
4923
24.0k
        dst->symbol.value = (src->u.syment.n_value);
4924
24.0k
        break;
4925
4926
#ifdef RS6000COFF_C
4927
      case C_BINCL: /* Beginning of include file.  */
4928
      case C_EINCL: /* Ending of include file.  */
4929
        /* The value is actually a pointer into the line numbers
4930
     of the file.  We locate the line number entry, and
4931
     set the section to the section which contains it, and
4932
     the value to the index in that section.  */
4933
        {
4934
    asection *sec;
4935
4936
    dst->symbol.flags = BSF_DEBUGGING;
4937
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4938
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4939
          && ((file_ptr) (sec->line_filepos
4940
              + sec->lineno_count * bfd_coff_linesz (abfd))
4941
        > (file_ptr) src->u.syment.n_value))
4942
        break;
4943
    if (sec == NULL)
4944
      dst->symbol.value = 0;
4945
    else
4946
      {
4947
        dst->symbol.section = sec;
4948
        dst->symbol.value = ((src->u.syment.n_value
4949
            - sec->line_filepos)
4950
           / bfd_coff_linesz (abfd));
4951
        src->fix_line = 1;
4952
      }
4953
        }
4954
        break;
4955
4956
      case C_BSTAT:
4957
        dst->symbol.flags = BSF_DEBUGGING;
4958
4959
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4960
    dst->symbol.value = 0;
4961
        else
4962
    {
4963
      /* The value is actually a symbol index.  Save a pointer
4964
         to the symbol instead of the index.  FIXME: This
4965
         should use a union.  */
4966
      src->u.syment.n_value
4967
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4968
      dst->symbol.value = src->u.syment.n_value;
4969
      src->fix_value = 1;
4970
    }
4971
        break;
4972
#endif
4973
4974
475
      case C_BLOCK: /* ".bb" or ".eb".  */
4975
5.87k
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4976
6.92k
      case C_EFCN: /* Physical end of function.  */
4977
6.92k
#if defined COFF_WITH_PE
4978
        /* PE sets the symbol to a value relative to the start
4979
     of the section.  */
4980
6.92k
        dst->symbol.value = src->u.syment.n_value;
4981
6.92k
        if (strcmp (dst->symbol.name, ".bf") != 0)
4982
6.92k
    {
4983
      /* PE uses funny values for .ef and .lf; don't
4984
         relocate them.  */
4985
6.92k
      dst->symbol.flags = BSF_DEBUGGING;
4986
6.92k
    }
4987
3
        else
4988
3
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4989
#else
4990
        /* Base the value as an index from the base of the
4991
     section.  */
4992
        dst->symbol.flags = BSF_LOCAL;
4993
        dst->symbol.value = (src->u.syment.n_value
4994
           - dst->symbol.section->vma);
4995
#endif
4996
6.92k
        break;
4997
4998
434
      case C_STATLAB: /* Static load time label.  */
4999
434
        dst->symbol.value = src->u.syment.n_value;
5000
434
        dst->symbol.flags = BSF_GLOBAL;
5001
434
        break;
5002
5003
162k
      case C_NULL:
5004
        /* PE DLLs sometimes have zeroed out symbols for some
5005
     reason.  Just ignore them without a warning.  */
5006
162k
        if (src->u.syment.n_type == 0
5007
162k
      && src->u.syment.n_value == 0
5008
162k
      && src->u.syment.n_scnum == 0)
5009
36.1k
    break;
5010
#ifdef RS6000COFF_C
5011
        /* XCOFF specific: deleted entry.  */
5012
        if (src->u.syment.n_value == C_NULL_VALUE)
5013
    break;
5014
#endif
5015
        /* Fall through.  */
5016
127k
      case C_EXTDEF: /* External definition.  */
5017
127k
      case C_ULABEL: /* Undefined label.  */
5018
128k
      case C_USTATIC: /* Undefined static.  */
5019
#ifndef COFF_WITH_PE
5020
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5021
         class to represent a section symbol.  */
5022
      case C_LINE:  /* line # reformatted as symbol table entry.  */
5023
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5024
      case C_ALIAS: /* Duplicate tag.  */
5025
#endif
5026
        /* New storage classes for TI COFF.  */
5027
#ifdef TICOFF
5028
      case C_UEXT:  /* Tentative external definition.  */
5029
#endif
5030
128k
      case C_EXTLAB: /* External load time label.  */
5031
183k
      default:
5032
183k
        _bfd_error_handler
5033
    /* xgettext:c-format */
5034
183k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5035
183k
     abfd, src->u.syment.n_sclass,
5036
183k
     dst->symbol.section->name, dst->symbol.name);
5037
183k
        ret = false;
5038
        /* Fall through.  */
5039
183k
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5040
        /* PR 20722: These symbols can also be generated by
5041
     building DLLs with --gc-sections enabled.  */
5042
183k
        dst->symbol.flags = BSF_DEBUGGING;
5043
183k
        dst->symbol.value = (src->u.syment.n_value);
5044
183k
        break;
5045
265k
      }
5046
5047
265k
    dst->native = src;
5048
265k
    dst->symbol.udata.i = 0;
5049
265k
    dst->lineno = NULL;
5050
5051
265k
    this_index += (src->u.syment.n_numaux) + 1;
5052
265k
    dst++;
5053
265k
    number_of_symbols++;
5054
265k
  }
5055
917
    }
5056
5057
917
  obj_symbols (abfd) = cached_area;
5058
917
  obj_raw_syments (abfd) = native_symbols;
5059
5060
917
  abfd->symcount = number_of_symbols;
5061
917
  obj_convert (abfd) = table_ptr;
5062
  /* Slurp the line tables for each section too.  */
5063
917
  {
5064
917
    asection *p;
5065
5066
917
    p = abfd->sections;
5067
1.93k
    while (p)
5068
1.77k
      {
5069
1.77k
  if (! coff_slurp_line_table (abfd, p))
5070
752
    return false;
5071
1.02k
  p = p->next;
5072
1.02k
      }
5073
917
  }
5074
5075
165
  return ret;
5076
917
}
pei-riscv64.c:coff_slurp_symbol_table
Line
Count
Source
4704
1.75k
{
4705
1.75k
  combined_entry_type *native_symbols;
4706
1.75k
  coff_symbol_type *cached_area;
4707
1.75k
  unsigned int *table_ptr;
4708
1.75k
  unsigned int number_of_symbols = 0;
4709
1.75k
  bool ret = true;
4710
1.75k
  size_t amt;
4711
4712
1.75k
  if (obj_symbols (abfd))
4713
131
    return true;
4714
4715
  /* Read in the symbol table.  */
4716
1.62k
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4717
663
    return false;
4718
4719
  /* Allocate enough room for all the symbols in cached form.  */
4720
957
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4721
957
       sizeof (*cached_area), &amt))
4722
0
    {
4723
0
      bfd_set_error (bfd_error_file_too_big);
4724
0
      return false;
4725
0
    }
4726
957
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4727
957
  if (cached_area == NULL)
4728
0
    return false;
4729
4730
957
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4731
957
       sizeof (*table_ptr), &amt))
4732
0
    {
4733
0
      bfd_set_error (bfd_error_file_too_big);
4734
0
      return false;
4735
0
    }
4736
957
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4737
957
  if (table_ptr == NULL)
4738
0
    return false;
4739
957
  else
4740
957
    {
4741
957
      coff_symbol_type *dst = cached_area;
4742
957
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4743
957
      unsigned int this_index = 0;
4744
4745
340k
      while (this_index < last_native_index)
4746
339k
  {
4747
339k
    combined_entry_type *src = native_symbols + this_index;
4748
339k
    table_ptr[this_index] = number_of_symbols;
4749
4750
339k
    dst->symbol.the_bfd = abfd;
4751
339k
    BFD_ASSERT (src->is_sym);
4752
339k
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4753
    /* We use the native name field to point to the cached field.  */
4754
339k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4755
339k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4756
339k
                 src->u.syment.n_scnum);
4757
339k
    dst->symbol.flags = 0;
4758
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4759
339k
    dst->symbol.value = 0;
4760
339k
    dst->done_lineno = false;
4761
4762
339k
    switch (src->u.syment.n_sclass)
4763
339k
      {
4764
3.94k
      case C_EXT:
4765
4.29k
      case C_WEAKEXT:
4766
#if defined ARM
4767
      case C_THUMBEXT:
4768
      case C_THUMBEXTFUNC:
4769
#endif
4770
#ifdef RS6000COFF_C
4771
      case C_HIDEXT:
4772
#ifndef AIX_WEAK_SUPPORT
4773
      case C_AIX_WEAKEXT:
4774
#endif
4775
#endif
4776
4.29k
#ifdef C_SYSTEM
4777
5.78k
      case C_SYSTEM: /* System Wide variable.  */
4778
5.78k
#endif
4779
5.78k
#ifdef COFF_WITH_PE
4780
      /* In PE, 0x68 (104) denotes a section symbol.  */
4781
5.90k
      case C_SECTION:
4782
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4783
10.0k
      case C_NT_WEAK:
4784
10.0k
#endif
4785
10.0k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4786
10.0k
    {
4787
8.72k
    case COFF_SYMBOL_GLOBAL:
4788
8.72k
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4789
8.72k
#if defined COFF_WITH_PE
4790
      /* PE sets the symbol to a value relative to the
4791
         start of the section.  */
4792
8.72k
      dst->symbol.value = src->u.syment.n_value;
4793
#else
4794
      dst->symbol.value = (src->u.syment.n_value
4795
               - dst->symbol.section->vma);
4796
#endif
4797
8.72k
      if (ISFCN ((src->u.syment.n_type)))
4798
        /* A function ext does not go at the end of a
4799
           file.  */
4800
273
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4801
8.72k
      break;
4802
4803
951
    case COFF_SYMBOL_COMMON:
4804
951
      dst->symbol.section = bfd_com_section_ptr;
4805
951
      dst->symbol.value = src->u.syment.n_value;
4806
951
      break;
4807
4808
355
    case COFF_SYMBOL_UNDEFINED:
4809
355
      dst->symbol.section = bfd_und_section_ptr;
4810
355
      dst->symbol.value = 0;
4811
355
      break;
4812
4813
0
    case COFF_SYMBOL_PE_SECTION:
4814
0
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4815
0
      dst->symbol.value = 0;
4816
0
      break;
4817
4818
0
    case COFF_SYMBOL_LOCAL:
4819
0
      dst->symbol.flags = BSF_LOCAL;
4820
0
#if defined COFF_WITH_PE
4821
      /* PE sets the symbol to a value relative to the
4822
         start of the section.  */
4823
0
      dst->symbol.value = src->u.syment.n_value;
4824
#else
4825
      dst->symbol.value = (src->u.syment.n_value
4826
               - dst->symbol.section->vma);
4827
#endif
4828
0
      if (ISFCN ((src->u.syment.n_type)))
4829
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4830
0
      break;
4831
10.0k
    }
4832
4833
#ifdef RS6000COFF_C
4834
        /* A symbol with a csect entry should not go at the end.  */
4835
        if (src->u.syment.n_numaux > 0)
4836
    dst->symbol.flags |= BSF_NOT_AT_END;
4837
#endif
4838
4839
10.0k
#ifdef COFF_WITH_PE
4840
10.0k
        if (src->u.syment.n_sclass == C_NT_WEAK)
4841
4.12k
    dst->symbol.flags |= BSF_WEAK;
4842
4843
10.0k
        if (src->u.syment.n_sclass == C_SECTION
4844
10.0k
      && src->u.syment.n_scnum > 0)
4845
0
    dst->symbol.flags = BSF_LOCAL;
4846
10.0k
#endif
4847
10.0k
        if (src->u.syment.n_sclass == C_WEAKEXT
4848
#ifdef RS6000COFF_C
4849
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4850
#endif
4851
10.0k
      )
4852
357
    dst->symbol.flags |= BSF_WEAK;
4853
4854
10.0k
        break;
4855
4856
5.63k
      case C_STAT:  /* Static.  */
4857
#if defined ARM
4858
      case C_THUMBSTAT:    /* Thumb static.  */
4859
      case C_THUMBLABEL:   /* Thumb label.  */
4860
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4861
#endif
4862
#ifdef RS6000COFF_C
4863
      case C_DWARF:  /* A label in a dwarf section.  */
4864
      case C_INFO:   /* A label in a comment section.  */
4865
#endif
4866
8.43k
      case C_LABEL:  /* Label.  */
4867
8.43k
        if (src->u.syment.n_scnum == N_DEBUG)
4868
6
    dst->symbol.flags = BSF_DEBUGGING;
4869
8.42k
        else
4870
8.42k
    dst->symbol.flags = BSF_LOCAL;
4871
4872
        /* Base the value as an index from the base of the
4873
     section, if there is one.  */
4874
8.43k
        if (dst->symbol.section)
4875
8.43k
    {
4876
8.43k
#if defined COFF_WITH_PE
4877
      /* PE sets the symbol to a value relative to the
4878
         start of the section.  */
4879
8.43k
      dst->symbol.value = src->u.syment.n_value;
4880
#else
4881
      dst->symbol.value = (src->u.syment.n_value
4882
               - dst->symbol.section->vma);
4883
#endif
4884
8.43k
    }
4885
0
        else
4886
0
    dst->symbol.value = src->u.syment.n_value;
4887
8.43k
        break;
4888
4889
2.22k
      case C_FILE: /* File name.  */
4890
2.22k
        dst->symbol.flags = BSF_FILE;
4891
        /* Fall through.  */
4892
2.88k
      case C_MOS:   /* Member of structure.  */
4893
4.49k
      case C_EOS:   /* End of structure.  */
4894
5.10k
      case C_REGPARM: /* Register parameter.  */
4895
10.7k
      case C_REG:   /* register variable.  */
4896
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4897
11.7k
      case C_TPDEF: /* Type definition.  */
4898
14.2k
      case C_ARG:
4899
25.7k
      case C_AUTO: /* Automatic variable.  */
4900
27.2k
      case C_FIELD: /* Bit field.  */
4901
27.9k
      case C_ENTAG: /* Enumeration tag.  */
4902
29.2k
      case C_MOE:   /* Member of enumeration.  */
4903
30.3k
      case C_MOU:   /* Member of union.  */
4904
31.3k
      case C_UNTAG: /* Union tag.  */
4905
34.5k
      case C_STRTAG: /* Structure tag.  */
4906
#ifdef RS6000COFF_C
4907
      case C_GSYM:
4908
      case C_LSYM:
4909
      case C_PSYM:
4910
      case C_RSYM:
4911
      case C_RPSYM:
4912
      case C_STSYM:
4913
      case C_TCSYM:
4914
      case C_BCOMM:
4915
      case C_ECOML:
4916
      case C_ECOMM:
4917
      case C_DECL:
4918
      case C_ENTRY:
4919
      case C_FUN:
4920
      case C_ESTAT:
4921
#endif
4922
34.5k
        dst->symbol.flags |= BSF_DEBUGGING;
4923
34.5k
        dst->symbol.value = (src->u.syment.n_value);
4924
34.5k
        break;
4925
4926
#ifdef RS6000COFF_C
4927
      case C_BINCL: /* Beginning of include file.  */
4928
      case C_EINCL: /* Ending of include file.  */
4929
        /* The value is actually a pointer into the line numbers
4930
     of the file.  We locate the line number entry, and
4931
     set the section to the section which contains it, and
4932
     the value to the index in that section.  */
4933
        {
4934
    asection *sec;
4935
4936
    dst->symbol.flags = BSF_DEBUGGING;
4937
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4938
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4939
          && ((file_ptr) (sec->line_filepos
4940
              + sec->lineno_count * bfd_coff_linesz (abfd))
4941
        > (file_ptr) src->u.syment.n_value))
4942
        break;
4943
    if (sec == NULL)
4944
      dst->symbol.value = 0;
4945
    else
4946
      {
4947
        dst->symbol.section = sec;
4948
        dst->symbol.value = ((src->u.syment.n_value
4949
            - sec->line_filepos)
4950
           / bfd_coff_linesz (abfd));
4951
        src->fix_line = 1;
4952
      }
4953
        }
4954
        break;
4955
4956
      case C_BSTAT:
4957
        dst->symbol.flags = BSF_DEBUGGING;
4958
4959
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4960
    dst->symbol.value = 0;
4961
        else
4962
    {
4963
      /* The value is actually a symbol index.  Save a pointer
4964
         to the symbol instead of the index.  FIXME: This
4965
         should use a union.  */
4966
      src->u.syment.n_value
4967
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4968
      dst->symbol.value = src->u.syment.n_value;
4969
      src->fix_value = 1;
4970
    }
4971
        break;
4972
#endif
4973
4974
773
      case C_BLOCK: /* ".bb" or ".eb".  */
4975
5.86k
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4976
7.17k
      case C_EFCN: /* Physical end of function.  */
4977
7.17k
#if defined COFF_WITH_PE
4978
        /* PE sets the symbol to a value relative to the start
4979
     of the section.  */
4980
7.17k
        dst->symbol.value = src->u.syment.n_value;
4981
7.17k
        if (strcmp (dst->symbol.name, ".bf") != 0)
4982
7.16k
    {
4983
      /* PE uses funny values for .ef and .lf; don't
4984
         relocate them.  */
4985
7.16k
      dst->symbol.flags = BSF_DEBUGGING;
4986
7.16k
    }
4987
2
        else
4988
2
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4989
#else
4990
        /* Base the value as an index from the base of the
4991
     section.  */
4992
        dst->symbol.flags = BSF_LOCAL;
4993
        dst->symbol.value = (src->u.syment.n_value
4994
           - dst->symbol.section->vma);
4995
#endif
4996
7.17k
        break;
4997
4998
327
      case C_STATLAB: /* Static load time label.  */
4999
327
        dst->symbol.value = src->u.syment.n_value;
5000
327
        dst->symbol.flags = BSF_GLOBAL;
5001
327
        break;
5002
5003
217k
      case C_NULL:
5004
        /* PE DLLs sometimes have zeroed out symbols for some
5005
     reason.  Just ignore them without a warning.  */
5006
217k
        if (src->u.syment.n_type == 0
5007
217k
      && src->u.syment.n_value == 0
5008
217k
      && src->u.syment.n_scnum == 0)
5009
72.9k
    break;
5010
#ifdef RS6000COFF_C
5011
        /* XCOFF specific: deleted entry.  */
5012
        if (src->u.syment.n_value == C_NULL_VALUE)
5013
    break;
5014
#endif
5015
        /* Fall through.  */
5016
144k
      case C_EXTDEF: /* External definition.  */
5017
144k
      case C_ULABEL: /* Undefined label.  */
5018
145k
      case C_USTATIC: /* Undefined static.  */
5019
#ifndef COFF_WITH_PE
5020
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5021
         class to represent a section symbol.  */
5022
      case C_LINE:  /* line # reformatted as symbol table entry.  */
5023
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5024
      case C_ALIAS: /* Duplicate tag.  */
5025
#endif
5026
        /* New storage classes for TI COFF.  */
5027
#ifdef TICOFF
5028
      case C_UEXT:  /* Tentative external definition.  */
5029
#endif
5030
145k
      case C_EXTLAB: /* External load time label.  */
5031
205k
      default:
5032
205k
        _bfd_error_handler
5033
    /* xgettext:c-format */
5034
205k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5035
205k
     abfd, src->u.syment.n_sclass,
5036
205k
     dst->symbol.section->name, dst->symbol.name);
5037
205k
        ret = false;
5038
        /* Fall through.  */
5039
206k
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5040
        /* PR 20722: These symbols can also be generated by
5041
     building DLLs with --gc-sections enabled.  */
5042
206k
        dst->symbol.flags = BSF_DEBUGGING;
5043
206k
        dst->symbol.value = (src->u.syment.n_value);
5044
206k
        break;
5045
339k
      }
5046
5047
339k
    dst->native = src;
5048
339k
    dst->symbol.udata.i = 0;
5049
339k
    dst->lineno = NULL;
5050
5051
339k
    this_index += (src->u.syment.n_numaux) + 1;
5052
339k
    dst++;
5053
339k
    number_of_symbols++;
5054
339k
  }
5055
957
    }
5056
5057
957
  obj_symbols (abfd) = cached_area;
5058
957
  obj_raw_syments (abfd) = native_symbols;
5059
5060
957
  abfd->symcount = number_of_symbols;
5061
957
  obj_convert (abfd) = table_ptr;
5062
  /* Slurp the line tables for each section too.  */
5063
957
  {
5064
957
    asection *p;
5065
5066
957
    p = abfd->sections;
5067
1.86k
    while (p)
5068
1.71k
      {
5069
1.71k
  if (! coff_slurp_line_table (abfd, p))
5070
807
    return false;
5071
911
  p = p->next;
5072
911
      }
5073
957
  }
5074
5075
150
  return ret;
5076
957
}
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
4704
10.2k
{
4705
10.2k
  combined_entry_type *native_symbols;
4706
10.2k
  coff_symbol_type *cached_area;
4707
10.2k
  unsigned int *table_ptr;
4708
10.2k
  unsigned int number_of_symbols = 0;
4709
10.2k
  bool ret = true;
4710
10.2k
  size_t amt;
4711
4712
10.2k
  if (obj_symbols (abfd))
4713
272
    return true;
4714
4715
  /* Read in the symbol table.  */
4716
9.96k
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4717
8.56k
    return false;
4718
4719
  /* Allocate enough room for all the symbols in cached form.  */
4720
1.40k
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4721
1.40k
       sizeof (*cached_area), &amt))
4722
0
    {
4723
0
      bfd_set_error (bfd_error_file_too_big);
4724
0
      return false;
4725
0
    }
4726
1.40k
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4727
1.40k
  if (cached_area == NULL)
4728
0
    return false;
4729
4730
1.40k
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4731
1.40k
       sizeof (*table_ptr), &amt))
4732
0
    {
4733
0
      bfd_set_error (bfd_error_file_too_big);
4734
0
      return false;
4735
0
    }
4736
1.40k
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4737
1.40k
  if (table_ptr == NULL)
4738
0
    return false;
4739
1.40k
  else
4740
1.40k
    {
4741
1.40k
      coff_symbol_type *dst = cached_area;
4742
1.40k
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4743
1.40k
      unsigned int this_index = 0;
4744
4745
350k
      while (this_index < last_native_index)
4746
349k
  {
4747
349k
    combined_entry_type *src = native_symbols + this_index;
4748
349k
    table_ptr[this_index] = number_of_symbols;
4749
4750
349k
    dst->symbol.the_bfd = abfd;
4751
349k
    BFD_ASSERT (src->is_sym);
4752
349k
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4753
    /* We use the native name field to point to the cached field.  */
4754
349k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4755
349k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4756
349k
                 src->u.syment.n_scnum);
4757
349k
    dst->symbol.flags = 0;
4758
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4759
349k
    dst->symbol.value = 0;
4760
349k
    dst->done_lineno = false;
4761
4762
349k
    switch (src->u.syment.n_sclass)
4763
349k
      {
4764
36.1k
      case C_EXT:
4765
37.0k
      case C_WEAKEXT:
4766
#if defined ARM
4767
      case C_THUMBEXT:
4768
      case C_THUMBEXTFUNC:
4769
#endif
4770
37.0k
#ifdef RS6000COFF_C
4771
38.4k
      case C_HIDEXT:
4772
38.4k
#ifndef AIX_WEAK_SUPPORT
4773
40.6k
      case C_AIX_WEAKEXT:
4774
40.6k
#endif
4775
40.6k
#endif
4776
40.6k
#ifdef C_SYSTEM
4777
43.3k
      case C_SYSTEM: /* System Wide variable.  */
4778
43.3k
#endif
4779
#ifdef COFF_WITH_PE
4780
      /* In PE, 0x68 (104) denotes a section symbol.  */
4781
      case C_SECTION:
4782
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4783
      case C_NT_WEAK:
4784
#endif
4785
43.3k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4786
43.3k
    {
4787
41.3k
    case COFF_SYMBOL_GLOBAL:
4788
41.3k
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4789
#if defined COFF_WITH_PE
4790
      /* PE sets the symbol to a value relative to the
4791
         start of the section.  */
4792
      dst->symbol.value = src->u.syment.n_value;
4793
#else
4794
41.3k
      dst->symbol.value = (src->u.syment.n_value
4795
41.3k
               - dst->symbol.section->vma);
4796
41.3k
#endif
4797
41.3k
      if (ISFCN ((src->u.syment.n_type)))
4798
        /* A function ext does not go at the end of a
4799
           file.  */
4800
1.25k
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4801
41.3k
      break;
4802
4803
424
    case COFF_SYMBOL_COMMON:
4804
424
      dst->symbol.section = bfd_com_section_ptr;
4805
424
      dst->symbol.value = src->u.syment.n_value;
4806
424
      break;
4807
4808
80
    case COFF_SYMBOL_UNDEFINED:
4809
80
      dst->symbol.section = bfd_und_section_ptr;
4810
80
      dst->symbol.value = 0;
4811
80
      break;
4812
4813
0
    case COFF_SYMBOL_PE_SECTION:
4814
0
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4815
0
      dst->symbol.value = 0;
4816
0
      break;
4817
4818
1.43k
    case COFF_SYMBOL_LOCAL:
4819
1.43k
      dst->symbol.flags = BSF_LOCAL;
4820
#if defined COFF_WITH_PE
4821
      /* PE sets the symbol to a value relative to the
4822
         start of the section.  */
4823
      dst->symbol.value = src->u.syment.n_value;
4824
#else
4825
1.43k
      dst->symbol.value = (src->u.syment.n_value
4826
1.43k
               - dst->symbol.section->vma);
4827
1.43k
#endif
4828
1.43k
      if (ISFCN ((src->u.syment.n_type)))
4829
1.07k
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4830
1.43k
      break;
4831
43.3k
    }
4832
4833
43.3k
#ifdef RS6000COFF_C
4834
        /* A symbol with a csect entry should not go at the end.  */
4835
43.3k
        if (src->u.syment.n_numaux > 0)
4836
41.5k
    dst->symbol.flags |= BSF_NOT_AT_END;
4837
43.3k
#endif
4838
4839
#ifdef COFF_WITH_PE
4840
        if (src->u.syment.n_sclass == C_NT_WEAK)
4841
    dst->symbol.flags |= BSF_WEAK;
4842
4843
        if (src->u.syment.n_sclass == C_SECTION
4844
      && src->u.syment.n_scnum > 0)
4845
    dst->symbol.flags = BSF_LOCAL;
4846
#endif
4847
43.3k
        if (src->u.syment.n_sclass == C_WEAKEXT
4848
43.3k
#ifdef RS6000COFF_C
4849
43.3k
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4850
43.3k
#endif
4851
43.3k
      )
4852
3.05k
    dst->symbol.flags |= BSF_WEAK;
4853
4854
43.3k
        break;
4855
4856
672
      case C_STAT:  /* Static.  */
4857
#if defined ARM
4858
      case C_THUMBSTAT:    /* Thumb static.  */
4859
      case C_THUMBLABEL:   /* Thumb label.  */
4860
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4861
#endif
4862
672
#ifdef RS6000COFF_C
4863
2.77k
      case C_DWARF:  /* A label in a dwarf section.  */
4864
5.17k
      case C_INFO:  /* A label in a comment section.  */
4865
5.17k
#endif
4866
5.84k
      case C_LABEL:  /* Label.  */
4867
5.84k
        if (src->u.syment.n_scnum == N_DEBUG)
4868
13
    dst->symbol.flags = BSF_DEBUGGING;
4869
5.82k
        else
4870
5.82k
    dst->symbol.flags = BSF_LOCAL;
4871
4872
        /* Base the value as an index from the base of the
4873
     section, if there is one.  */
4874
5.84k
        if (dst->symbol.section)
4875
5.84k
    {
4876
#if defined COFF_WITH_PE
4877
      /* PE sets the symbol to a value relative to the
4878
         start of the section.  */
4879
      dst->symbol.value = src->u.syment.n_value;
4880
#else
4881
5.84k
      dst->symbol.value = (src->u.syment.n_value
4882
5.84k
               - dst->symbol.section->vma);
4883
5.84k
#endif
4884
5.84k
    }
4885
0
        else
4886
0
    dst->symbol.value = src->u.syment.n_value;
4887
5.84k
        break;
4888
4889
1.28k
      case C_FILE: /* File name.  */
4890
1.28k
        dst->symbol.flags = BSF_FILE;
4891
        /* Fall through.  */
4892
6.26k
      case C_MOS:   /* Member of structure.  */
4893
7.99k
      case C_EOS:   /* End of structure.  */
4894
9.56k
      case C_REGPARM: /* Register parameter.  */
4895
17.7k
      case C_REG:   /* register variable.  */
4896
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4897
24.3k
      case C_TPDEF: /* Type definition.  */
4898
31.1k
      case C_ARG:
4899
38.1k
      case C_AUTO: /* Automatic variable.  */
4900
40.0k
      case C_FIELD: /* Bit field.  */
4901
40.2k
      case C_ENTAG: /* Enumeration tag.  */
4902
41.2k
      case C_MOE:   /* Member of enumeration.  */
4903
42.5k
      case C_MOU:   /* Member of union.  */
4904
45.9k
      case C_UNTAG: /* Union tag.  */
4905
49.3k
      case C_STRTAG: /* Structure tag.  */
4906
49.3k
#ifdef RS6000COFF_C
4907
50.0k
      case C_GSYM:
4908
53.0k
      case C_LSYM:
4909
53.2k
      case C_PSYM:
4910
54.1k
      case C_RSYM:
4911
54.6k
      case C_RPSYM:
4912
54.9k
      case C_STSYM:
4913
55.6k
      case C_TCSYM:
4914
56.4k
      case C_BCOMM:
4915
56.9k
      case C_ECOML:
4916
57.5k
      case C_ECOMM:
4917
58.2k
      case C_DECL:
4918
58.4k
      case C_ENTRY:
4919
58.5k
      case C_FUN:
4920
59.2k
      case C_ESTAT:
4921
59.2k
#endif
4922
59.2k
        dst->symbol.flags |= BSF_DEBUGGING;
4923
59.2k
        dst->symbol.value = (src->u.syment.n_value);
4924
59.2k
        break;
4925
4926
0
#ifdef RS6000COFF_C
4927
4.20k
      case C_BINCL: /* Beginning of include file.  */
4928
5.69k
      case C_EINCL: /* Ending of include file.  */
4929
        /* The value is actually a pointer into the line numbers
4930
     of the file.  We locate the line number entry, and
4931
     set the section to the section which contains it, and
4932
     the value to the index in that section.  */
4933
5.69k
        {
4934
5.69k
    asection *sec;
4935
4936
5.69k
    dst->symbol.flags = BSF_DEBUGGING;
4937
1.08M
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4938
1.08M
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4939
1.08M
          && ((file_ptr) (sec->line_filepos
4940
982k
              + sec->lineno_count * bfd_coff_linesz (abfd))
4941
982k
        > (file_ptr) src->u.syment.n_value))
4942
1.68k
        break;
4943
5.69k
    if (sec == NULL)
4944
4.01k
      dst->symbol.value = 0;
4945
1.68k
    else
4946
1.68k
      {
4947
1.68k
        dst->symbol.section = sec;
4948
1.68k
        dst->symbol.value = ((src->u.syment.n_value
4949
1.68k
            - sec->line_filepos)
4950
1.68k
           / bfd_coff_linesz (abfd));
4951
1.68k
        src->fix_line = 1;
4952
1.68k
      }
4953
5.69k
        }
4954
5.69k
        break;
4955
4956
1.18k
      case C_BSTAT:
4957
1.18k
        dst->symbol.flags = BSF_DEBUGGING;
4958
4959
1.18k
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4960
1.17k
    dst->symbol.value = 0;
4961
9
        else
4962
9
    {
4963
      /* The value is actually a symbol index.  Save a pointer
4964
         to the symbol instead of the index.  FIXME: This
4965
         should use a union.  */
4966
9
      src->u.syment.n_value
4967
9
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4968
9
      dst->symbol.value = src->u.syment.n_value;
4969
9
      src->fix_value = 1;
4970
9
    }
4971
1.18k
        break;
4972
0
#endif
4973
4974
983
      case C_BLOCK: /* ".bb" or ".eb".  */
4975
3.84k
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4976
4.37k
      case C_EFCN: /* Physical end of function.  */
4977
#if defined COFF_WITH_PE
4978
        /* PE sets the symbol to a value relative to the start
4979
     of the section.  */
4980
        dst->symbol.value = src->u.syment.n_value;
4981
        if (strcmp (dst->symbol.name, ".bf") != 0)
4982
    {
4983
      /* PE uses funny values for .ef and .lf; don't
4984
         relocate them.  */
4985
      dst->symbol.flags = BSF_DEBUGGING;
4986
    }
4987
        else
4988
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4989
#else
4990
        /* Base the value as an index from the base of the
4991
     section.  */
4992
4.37k
        dst->symbol.flags = BSF_LOCAL;
4993
4.37k
        dst->symbol.value = (src->u.syment.n_value
4994
4.37k
           - dst->symbol.section->vma);
4995
4.37k
#endif
4996
4.37k
        break;
4997
4998
4.32k
      case C_STATLAB: /* Static load time label.  */
4999
4.32k
        dst->symbol.value = src->u.syment.n_value;
5000
4.32k
        dst->symbol.flags = BSF_GLOBAL;
5001
4.32k
        break;
5002
5003
177k
      case C_NULL:
5004
        /* PE DLLs sometimes have zeroed out symbols for some
5005
     reason.  Just ignore them without a warning.  */
5006
177k
        if (src->u.syment.n_type == 0
5007
177k
      && src->u.syment.n_value == 0
5008
177k
      && src->u.syment.n_scnum == 0)
5009
114k
    break;
5010
63.1k
#ifdef RS6000COFF_C
5011
        /* XCOFF specific: deleted entry.  */
5012
63.1k
        if (src->u.syment.n_value == C_NULL_VALUE)
5013
0
    break;
5014
63.1k
#endif
5015
        /* Fall through.  */
5016
63.4k
      case C_EXTDEF: /* External definition.  */
5017
63.5k
      case C_ULABEL: /* Undefined label.  */
5018
63.7k
      case C_USTATIC: /* Undefined static.  */
5019
63.7k
#ifndef COFF_WITH_PE
5020
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5021
         class to represent a section symbol.  */
5022
65.1k
      case C_LINE: /* line # reformatted as symbol table entry.  */
5023
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5024
67.0k
      case C_ALIAS: /* Duplicate tag.  */
5025
67.0k
#endif
5026
        /* New storage classes for TI COFF.  */
5027
#ifdef TICOFF
5028
      case C_UEXT:  /* Tentative external definition.  */
5029
#endif
5030
67.1k
      case C_EXTLAB: /* External load time label.  */
5031
110k
      default:
5032
110k
        _bfd_error_handler
5033
    /* xgettext:c-format */
5034
110k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5035
110k
     abfd, src->u.syment.n_sclass,
5036
110k
     dst->symbol.section->name, dst->symbol.name);
5037
110k
        ret = false;
5038
        /* Fall through.  */
5039
110k
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5040
        /* PR 20722: These symbols can also be generated by
5041
     building DLLs with --gc-sections enabled.  */
5042
110k
        dst->symbol.flags = BSF_DEBUGGING;
5043
110k
        dst->symbol.value = (src->u.syment.n_value);
5044
110k
        break;
5045
349k
      }
5046
5047
349k
    dst->native = src;
5048
349k
    dst->symbol.udata.i = 0;
5049
349k
    dst->lineno = NULL;
5050
5051
349k
    this_index += (src->u.syment.n_numaux) + 1;
5052
349k
    dst++;
5053
349k
    number_of_symbols++;
5054
349k
  }
5055
1.40k
    }
5056
5057
1.40k
  obj_symbols (abfd) = cached_area;
5058
1.40k
  obj_raw_syments (abfd) = native_symbols;
5059
5060
1.40k
  abfd->symcount = number_of_symbols;
5061
1.40k
  obj_convert (abfd) = table_ptr;
5062
  /* Slurp the line tables for each section too.  */
5063
1.40k
  {
5064
1.40k
    asection *p;
5065
5066
1.40k
    p = abfd->sections;
5067
5.65k
    while (p)
5068
5.24k
      {
5069
5.24k
  if (! coff_slurp_line_table (abfd, p))
5070
1.00k
    return false;
5071
4.24k
  p = p->next;
5072
4.24k
      }
5073
1.40k
  }
5074
5075
403
  return ret;
5076
1.40k
}
coff-sh.c:coff_slurp_symbol_table
Line
Count
Source
4704
5.52k
{
4705
5.52k
  combined_entry_type *native_symbols;
4706
5.52k
  coff_symbol_type *cached_area;
4707
5.52k
  unsigned int *table_ptr;
4708
5.52k
  unsigned int number_of_symbols = 0;
4709
5.52k
  bool ret = true;
4710
5.52k
  size_t amt;
4711
4712
5.52k
  if (obj_symbols (abfd))
4713
1.04k
    return true;
4714
4715
  /* Read in the symbol table.  */
4716
4.48k
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4717
3.51k
    return false;
4718
4719
  /* Allocate enough room for all the symbols in cached form.  */
4720
973
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4721
973
       sizeof (*cached_area), &amt))
4722
0
    {
4723
0
      bfd_set_error (bfd_error_file_too_big);
4724
0
      return false;
4725
0
    }
4726
973
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4727
973
  if (cached_area == NULL)
4728
0
    return false;
4729
4730
973
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4731
973
       sizeof (*table_ptr), &amt))
4732
0
    {
4733
0
      bfd_set_error (bfd_error_file_too_big);
4734
0
      return false;
4735
0
    }
4736
973
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4737
973
  if (table_ptr == NULL)
4738
0
    return false;
4739
973
  else
4740
973
    {
4741
973
      coff_symbol_type *dst = cached_area;
4742
973
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4743
973
      unsigned int this_index = 0;
4744
4745
259k
      while (this_index < last_native_index)
4746
258k
  {
4747
258k
    combined_entry_type *src = native_symbols + this_index;
4748
258k
    table_ptr[this_index] = number_of_symbols;
4749
4750
258k
    dst->symbol.the_bfd = abfd;
4751
258k
    BFD_ASSERT (src->is_sym);
4752
258k
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4753
    /* We use the native name field to point to the cached field.  */
4754
258k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4755
258k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4756
258k
                 src->u.syment.n_scnum);
4757
258k
    dst->symbol.flags = 0;
4758
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4759
258k
    dst->symbol.value = 0;
4760
258k
    dst->done_lineno = false;
4761
4762
258k
    switch (src->u.syment.n_sclass)
4763
258k
      {
4764
12.8k
      case C_EXT:
4765
13.1k
      case C_WEAKEXT:
4766
#if defined ARM
4767
      case C_THUMBEXT:
4768
      case C_THUMBEXTFUNC:
4769
#endif
4770
#ifdef RS6000COFF_C
4771
      case C_HIDEXT:
4772
#ifndef AIX_WEAK_SUPPORT
4773
      case C_AIX_WEAKEXT:
4774
#endif
4775
#endif
4776
13.1k
#ifdef C_SYSTEM
4777
13.6k
      case C_SYSTEM: /* System Wide variable.  */
4778
13.6k
#endif
4779
#ifdef COFF_WITH_PE
4780
      /* In PE, 0x68 (104) denotes a section symbol.  */
4781
      case C_SECTION:
4782
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4783
      case C_NT_WEAK:
4784
#endif
4785
13.6k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4786
13.6k
    {
4787
11.8k
    case COFF_SYMBOL_GLOBAL:
4788
11.8k
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4789
#if defined COFF_WITH_PE
4790
      /* PE sets the symbol to a value relative to the
4791
         start of the section.  */
4792
      dst->symbol.value = src->u.syment.n_value;
4793
#else
4794
11.8k
      dst->symbol.value = (src->u.syment.n_value
4795
11.8k
               - dst->symbol.section->vma);
4796
11.8k
#endif
4797
11.8k
      if (ISFCN ((src->u.syment.n_type)))
4798
        /* A function ext does not go at the end of a
4799
           file.  */
4800
62
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4801
11.8k
      break;
4802
4803
1.66k
    case COFF_SYMBOL_COMMON:
4804
1.66k
      dst->symbol.section = bfd_com_section_ptr;
4805
1.66k
      dst->symbol.value = src->u.syment.n_value;
4806
1.66k
      break;
4807
4808
125
    case COFF_SYMBOL_UNDEFINED:
4809
125
      dst->symbol.section = bfd_und_section_ptr;
4810
125
      dst->symbol.value = 0;
4811
125
      break;
4812
4813
0
    case COFF_SYMBOL_PE_SECTION:
4814
0
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4815
0
      dst->symbol.value = 0;
4816
0
      break;
4817
4818
0
    case COFF_SYMBOL_LOCAL:
4819
0
      dst->symbol.flags = BSF_LOCAL;
4820
#if defined COFF_WITH_PE
4821
      /* PE sets the symbol to a value relative to the
4822
         start of the section.  */
4823
      dst->symbol.value = src->u.syment.n_value;
4824
#else
4825
0
      dst->symbol.value = (src->u.syment.n_value
4826
0
               - dst->symbol.section->vma);
4827
0
#endif
4828
0
      if (ISFCN ((src->u.syment.n_type)))
4829
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4830
0
      break;
4831
13.6k
    }
4832
4833
#ifdef RS6000COFF_C
4834
        /* A symbol with a csect entry should not go at the end.  */
4835
        if (src->u.syment.n_numaux > 0)
4836
    dst->symbol.flags |= BSF_NOT_AT_END;
4837
#endif
4838
4839
#ifdef COFF_WITH_PE
4840
        if (src->u.syment.n_sclass == C_NT_WEAK)
4841
    dst->symbol.flags |= BSF_WEAK;
4842
4843
        if (src->u.syment.n_sclass == C_SECTION
4844
      && src->u.syment.n_scnum > 0)
4845
    dst->symbol.flags = BSF_LOCAL;
4846
#endif
4847
13.6k
        if (src->u.syment.n_sclass == C_WEAKEXT
4848
#ifdef RS6000COFF_C
4849
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4850
#endif
4851
13.6k
      )
4852
319
    dst->symbol.flags |= BSF_WEAK;
4853
4854
13.6k
        break;
4855
4856
1.53k
      case C_STAT:  /* Static.  */
4857
#if defined ARM
4858
      case C_THUMBSTAT:    /* Thumb static.  */
4859
      case C_THUMBLABEL:   /* Thumb label.  */
4860
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4861
#endif
4862
#ifdef RS6000COFF_C
4863
      case C_DWARF:  /* A label in a dwarf section.  */
4864
      case C_INFO:   /* A label in a comment section.  */
4865
#endif
4866
2.46k
      case C_LABEL:  /* Label.  */
4867
2.46k
        if (src->u.syment.n_scnum == N_DEBUG)
4868
7
    dst->symbol.flags = BSF_DEBUGGING;
4869
2.46k
        else
4870
2.46k
    dst->symbol.flags = BSF_LOCAL;
4871
4872
        /* Base the value as an index from the base of the
4873
     section, if there is one.  */
4874
2.46k
        if (dst->symbol.section)
4875
2.46k
    {
4876
#if defined COFF_WITH_PE
4877
      /* PE sets the symbol to a value relative to the
4878
         start of the section.  */
4879
      dst->symbol.value = src->u.syment.n_value;
4880
#else
4881
2.46k
      dst->symbol.value = (src->u.syment.n_value
4882
2.46k
               - dst->symbol.section->vma);
4883
2.46k
#endif
4884
2.46k
    }
4885
0
        else
4886
0
    dst->symbol.value = src->u.syment.n_value;
4887
2.46k
        break;
4888
4889
982
      case C_FILE: /* File name.  */
4890
982
        dst->symbol.flags = BSF_FILE;
4891
        /* Fall through.  */
4892
1.93k
      case C_MOS:   /* Member of structure.  */
4893
2.46k
      case C_EOS:   /* End of structure.  */
4894
3.49k
      case C_REGPARM: /* Register parameter.  */
4895
5.25k
      case C_REG:   /* register variable.  */
4896
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4897
6.57k
      case C_TPDEF: /* Type definition.  */
4898
7.80k
      case C_ARG:
4899
21.1k
      case C_AUTO: /* Automatic variable.  */
4900
21.9k
      case C_FIELD: /* Bit field.  */
4901
22.6k
      case C_ENTAG: /* Enumeration tag.  */
4902
23.7k
      case C_MOE:   /* Member of enumeration.  */
4903
24.5k
      case C_MOU:   /* Member of union.  */
4904
25.3k
      case C_UNTAG: /* Union tag.  */
4905
27.2k
      case C_STRTAG: /* Structure tag.  */
4906
#ifdef RS6000COFF_C
4907
      case C_GSYM:
4908
      case C_LSYM:
4909
      case C_PSYM:
4910
      case C_RSYM:
4911
      case C_RPSYM:
4912
      case C_STSYM:
4913
      case C_TCSYM:
4914
      case C_BCOMM:
4915
      case C_ECOML:
4916
      case C_ECOMM:
4917
      case C_DECL:
4918
      case C_ENTRY:
4919
      case C_FUN:
4920
      case C_ESTAT:
4921
#endif
4922
27.2k
        dst->symbol.flags |= BSF_DEBUGGING;
4923
27.2k
        dst->symbol.value = (src->u.syment.n_value);
4924
27.2k
        break;
4925
4926
#ifdef RS6000COFF_C
4927
      case C_BINCL: /* Beginning of include file.  */
4928
      case C_EINCL: /* Ending of include file.  */
4929
        /* The value is actually a pointer into the line numbers
4930
     of the file.  We locate the line number entry, and
4931
     set the section to the section which contains it, and
4932
     the value to the index in that section.  */
4933
        {
4934
    asection *sec;
4935
4936
    dst->symbol.flags = BSF_DEBUGGING;
4937
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4938
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4939
          && ((file_ptr) (sec->line_filepos
4940
              + sec->lineno_count * bfd_coff_linesz (abfd))
4941
        > (file_ptr) src->u.syment.n_value))
4942
        break;
4943
    if (sec == NULL)
4944
      dst->symbol.value = 0;
4945
    else
4946
      {
4947
        dst->symbol.section = sec;
4948
        dst->symbol.value = ((src->u.syment.n_value
4949
            - sec->line_filepos)
4950
           / bfd_coff_linesz (abfd));
4951
        src->fix_line = 1;
4952
      }
4953
        }
4954
        break;
4955
4956
      case C_BSTAT:
4957
        dst->symbol.flags = BSF_DEBUGGING;
4958
4959
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4960
    dst->symbol.value = 0;
4961
        else
4962
    {
4963
      /* The value is actually a symbol index.  Save a pointer
4964
         to the symbol instead of the index.  FIXME: This
4965
         should use a union.  */
4966
      src->u.syment.n_value
4967
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4968
      dst->symbol.value = src->u.syment.n_value;
4969
      src->fix_value = 1;
4970
    }
4971
        break;
4972
#endif
4973
4974
409
      case C_BLOCK: /* ".bb" or ".eb".  */
4975
2.58k
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4976
3.65k
      case C_EFCN: /* Physical end of function.  */
4977
#if defined COFF_WITH_PE
4978
        /* PE sets the symbol to a value relative to the start
4979
     of the section.  */
4980
        dst->symbol.value = src->u.syment.n_value;
4981
        if (strcmp (dst->symbol.name, ".bf") != 0)
4982
    {
4983
      /* PE uses funny values for .ef and .lf; don't
4984
         relocate them.  */
4985
      dst->symbol.flags = BSF_DEBUGGING;
4986
    }
4987
        else
4988
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4989
#else
4990
        /* Base the value as an index from the base of the
4991
     section.  */
4992
3.65k
        dst->symbol.flags = BSF_LOCAL;
4993
3.65k
        dst->symbol.value = (src->u.syment.n_value
4994
3.65k
           - dst->symbol.section->vma);
4995
3.65k
#endif
4996
3.65k
        break;
4997
4998
398
      case C_STATLAB: /* Static load time label.  */
4999
398
        dst->symbol.value = src->u.syment.n_value;
5000
398
        dst->symbol.flags = BSF_GLOBAL;
5001
398
        break;
5002
5003
168k
      case C_NULL:
5004
        /* PE DLLs sometimes have zeroed out symbols for some
5005
     reason.  Just ignore them without a warning.  */
5006
168k
        if (src->u.syment.n_type == 0
5007
168k
      && src->u.syment.n_value == 0
5008
168k
      && src->u.syment.n_scnum == 0)
5009
51.1k
    break;
5010
#ifdef RS6000COFF_C
5011
        /* XCOFF specific: deleted entry.  */
5012
        if (src->u.syment.n_value == C_NULL_VALUE)
5013
    break;
5014
#endif
5015
        /* Fall through.  */
5016
117k
      case C_EXTDEF: /* External definition.  */
5017
117k
      case C_ULABEL: /* Undefined label.  */
5018
117k
      case C_USTATIC: /* Undefined static.  */
5019
117k
#ifndef COFF_WITH_PE
5020
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5021
         class to represent a section symbol.  */
5022
118k
      case C_LINE: /* line # reformatted as symbol table entry.  */
5023
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5024
120k
      case C_ALIAS: /* Duplicate tag.  */
5025
120k
#endif
5026
        /* New storage classes for TI COFF.  */
5027
#ifdef TICOFF
5028
      case C_UEXT:  /* Tentative external definition.  */
5029
#endif
5030
120k
      case C_EXTLAB: /* External load time label.  */
5031
160k
      default:
5032
160k
        _bfd_error_handler
5033
    /* xgettext:c-format */
5034
160k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5035
160k
     abfd, src->u.syment.n_sclass,
5036
160k
     dst->symbol.section->name, dst->symbol.name);
5037
160k
        ret = false;
5038
        /* Fall through.  */
5039
160k
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5040
        /* PR 20722: These symbols can also be generated by
5041
     building DLLs with --gc-sections enabled.  */
5042
160k
        dst->symbol.flags = BSF_DEBUGGING;
5043
160k
        dst->symbol.value = (src->u.syment.n_value);
5044
160k
        break;
5045
258k
      }
5046
5047
258k
    dst->native = src;
5048
258k
    dst->symbol.udata.i = 0;
5049
258k
    dst->lineno = NULL;
5050
5051
258k
    this_index += (src->u.syment.n_numaux) + 1;
5052
258k
    dst++;
5053
258k
    number_of_symbols++;
5054
258k
  }
5055
973
    }
5056
5057
973
  obj_symbols (abfd) = cached_area;
5058
973
  obj_raw_syments (abfd) = native_symbols;
5059
5060
973
  abfd->symcount = number_of_symbols;
5061
973
  obj_convert (abfd) = table_ptr;
5062
  /* Slurp the line tables for each section too.  */
5063
973
  {
5064
973
    asection *p;
5065
5066
973
    p = abfd->sections;
5067
5.83k
    while (p)
5068
5.65k
      {
5069
5.65k
  if (! coff_slurp_line_table (abfd, p))
5070
791
    return false;
5071
4.86k
  p = p->next;
5072
4.86k
      }
5073
973
  }
5074
5075
182
  return ret;
5076
973
}
Unexecuted instantiation: coff-stgo32.c:coff_slurp_symbol_table
coff-tic30.c:coff_slurp_symbol_table
Line
Count
Source
4704
14.3k
{
4705
14.3k
  combined_entry_type *native_symbols;
4706
14.3k
  coff_symbol_type *cached_area;
4707
14.3k
  unsigned int *table_ptr;
4708
14.3k
  unsigned int number_of_symbols = 0;
4709
14.3k
  bool ret = true;
4710
14.3k
  size_t amt;
4711
4712
14.3k
  if (obj_symbols (abfd))
4713
6.21k
    return true;
4714
4715
  /* Read in the symbol table.  */
4716
8.15k
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4717
6.73k
    return false;
4718
4719
  /* Allocate enough room for all the symbols in cached form.  */
4720
1.41k
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4721
1.41k
       sizeof (*cached_area), &amt))
4722
0
    {
4723
0
      bfd_set_error (bfd_error_file_too_big);
4724
0
      return false;
4725
0
    }
4726
1.41k
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4727
1.41k
  if (cached_area == NULL)
4728
0
    return false;
4729
4730
1.41k
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4731
1.41k
       sizeof (*table_ptr), &amt))
4732
0
    {
4733
0
      bfd_set_error (bfd_error_file_too_big);
4734
0
      return false;
4735
0
    }
4736
1.41k
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4737
1.41k
  if (table_ptr == NULL)
4738
0
    return false;
4739
1.41k
  else
4740
1.41k
    {
4741
1.41k
      coff_symbol_type *dst = cached_area;
4742
1.41k
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4743
1.41k
      unsigned int this_index = 0;
4744
4745
190k
      while (this_index < last_native_index)
4746
189k
  {
4747
189k
    combined_entry_type *src = native_symbols + this_index;
4748
189k
    table_ptr[this_index] = number_of_symbols;
4749
4750
189k
    dst->symbol.the_bfd = abfd;
4751
189k
    BFD_ASSERT (src->is_sym);
4752
189k
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4753
    /* We use the native name field to point to the cached field.  */
4754
189k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4755
189k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4756
189k
                 src->u.syment.n_scnum);
4757
189k
    dst->symbol.flags = 0;
4758
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4759
189k
    dst->symbol.value = 0;
4760
189k
    dst->done_lineno = false;
4761
4762
189k
    switch (src->u.syment.n_sclass)
4763
189k
      {
4764
2.99k
      case C_EXT:
4765
3.34k
      case C_WEAKEXT:
4766
#if defined ARM
4767
      case C_THUMBEXT:
4768
      case C_THUMBEXTFUNC:
4769
#endif
4770
#ifdef RS6000COFF_C
4771
      case C_HIDEXT:
4772
#ifndef AIX_WEAK_SUPPORT
4773
      case C_AIX_WEAKEXT:
4774
#endif
4775
#endif
4776
3.34k
#ifdef C_SYSTEM
4777
3.75k
      case C_SYSTEM: /* System Wide variable.  */
4778
3.75k
#endif
4779
#ifdef COFF_WITH_PE
4780
      /* In PE, 0x68 (104) denotes a section symbol.  */
4781
      case C_SECTION:
4782
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4783
      case C_NT_WEAK:
4784
#endif
4785
3.75k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4786
3.75k
    {
4787
2.66k
    case COFF_SYMBOL_GLOBAL:
4788
2.66k
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4789
#if defined COFF_WITH_PE
4790
      /* PE sets the symbol to a value relative to the
4791
         start of the section.  */
4792
      dst->symbol.value = src->u.syment.n_value;
4793
#else
4794
2.66k
      dst->symbol.value = (src->u.syment.n_value
4795
2.66k
               - dst->symbol.section->vma);
4796
2.66k
#endif
4797
2.66k
      if (ISFCN ((src->u.syment.n_type)))
4798
        /* A function ext does not go at the end of a
4799
           file.  */
4800
55
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4801
2.66k
      break;
4802
4803
938
    case COFF_SYMBOL_COMMON:
4804
938
      dst->symbol.section = bfd_com_section_ptr;
4805
938
      dst->symbol.value = src->u.syment.n_value;
4806
938
      break;
4807
4808
152
    case COFF_SYMBOL_UNDEFINED:
4809
152
      dst->symbol.section = bfd_und_section_ptr;
4810
152
      dst->symbol.value = 0;
4811
152
      break;
4812
4813
0
    case COFF_SYMBOL_PE_SECTION:
4814
0
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4815
0
      dst->symbol.value = 0;
4816
0
      break;
4817
4818
0
    case COFF_SYMBOL_LOCAL:
4819
0
      dst->symbol.flags = BSF_LOCAL;
4820
#if defined COFF_WITH_PE
4821
      /* PE sets the symbol to a value relative to the
4822
         start of the section.  */
4823
      dst->symbol.value = src->u.syment.n_value;
4824
#else
4825
0
      dst->symbol.value = (src->u.syment.n_value
4826
0
               - dst->symbol.section->vma);
4827
0
#endif
4828
0
      if (ISFCN ((src->u.syment.n_type)))
4829
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4830
0
      break;
4831
3.75k
    }
4832
4833
#ifdef RS6000COFF_C
4834
        /* A symbol with a csect entry should not go at the end.  */
4835
        if (src->u.syment.n_numaux > 0)
4836
    dst->symbol.flags |= BSF_NOT_AT_END;
4837
#endif
4838
4839
#ifdef COFF_WITH_PE
4840
        if (src->u.syment.n_sclass == C_NT_WEAK)
4841
    dst->symbol.flags |= BSF_WEAK;
4842
4843
        if (src->u.syment.n_sclass == C_SECTION
4844
      && src->u.syment.n_scnum > 0)
4845
    dst->symbol.flags = BSF_LOCAL;
4846
#endif
4847
3.75k
        if (src->u.syment.n_sclass == C_WEAKEXT
4848
#ifdef RS6000COFF_C
4849
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4850
#endif
4851
3.75k
      )
4852
343
    dst->symbol.flags |= BSF_WEAK;
4853
4854
3.75k
        break;
4855
4856
1.68k
      case C_STAT:  /* Static.  */
4857
#if defined ARM
4858
      case C_THUMBSTAT:    /* Thumb static.  */
4859
      case C_THUMBLABEL:   /* Thumb label.  */
4860
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4861
#endif
4862
#ifdef RS6000COFF_C
4863
      case C_DWARF:  /* A label in a dwarf section.  */
4864
      case C_INFO:   /* A label in a comment section.  */
4865
#endif
4866
3.18k
      case C_LABEL:  /* Label.  */
4867
3.18k
        if (src->u.syment.n_scnum == N_DEBUG)
4868
13
    dst->symbol.flags = BSF_DEBUGGING;
4869
3.17k
        else
4870
3.17k
    dst->symbol.flags = BSF_LOCAL;
4871
4872
        /* Base the value as an index from the base of the
4873
     section, if there is one.  */
4874
3.18k
        if (dst->symbol.section)
4875
3.18k
    {
4876
#if defined COFF_WITH_PE
4877
      /* PE sets the symbol to a value relative to the
4878
         start of the section.  */
4879
      dst->symbol.value = src->u.syment.n_value;
4880
#else
4881
3.18k
      dst->symbol.value = (src->u.syment.n_value
4882
3.18k
               - dst->symbol.section->vma);
4883
3.18k
#endif
4884
3.18k
    }
4885
0
        else
4886
0
    dst->symbol.value = src->u.syment.n_value;
4887
3.18k
        break;
4888
4889
1.34k
      case C_FILE: /* File name.  */
4890
1.34k
        dst->symbol.flags = BSF_FILE;
4891
        /* Fall through.  */
4892
1.91k
      case C_MOS:   /* Member of structure.  */
4893
2.42k
      case C_EOS:   /* End of structure.  */
4894
3.15k
      case C_REGPARM: /* Register parameter.  */
4895
4.28k
      case C_REG:   /* register variable.  */
4896
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4897
5.00k
      case C_TPDEF: /* Type definition.  */
4898
6.29k
      case C_ARG:
4899
16.6k
      case C_AUTO: /* Automatic variable.  */
4900
17.4k
      case C_FIELD: /* Bit field.  */
4901
17.8k
      case C_ENTAG: /* Enumeration tag.  */
4902
18.9k
      case C_MOE:   /* Member of enumeration.  */
4903
19.6k
      case C_MOU:   /* Member of union.  */
4904
20.2k
      case C_UNTAG: /* Union tag.  */
4905
21.7k
      case C_STRTAG: /* Structure tag.  */
4906
#ifdef RS6000COFF_C
4907
      case C_GSYM:
4908
      case C_LSYM:
4909
      case C_PSYM:
4910
      case C_RSYM:
4911
      case C_RPSYM:
4912
      case C_STSYM:
4913
      case C_TCSYM:
4914
      case C_BCOMM:
4915
      case C_ECOML:
4916
      case C_ECOMM:
4917
      case C_DECL:
4918
      case C_ENTRY:
4919
      case C_FUN:
4920
      case C_ESTAT:
4921
#endif
4922
21.7k
        dst->symbol.flags |= BSF_DEBUGGING;
4923
21.7k
        dst->symbol.value = (src->u.syment.n_value);
4924
21.7k
        break;
4925
4926
#ifdef RS6000COFF_C
4927
      case C_BINCL: /* Beginning of include file.  */
4928
      case C_EINCL: /* Ending of include file.  */
4929
        /* The value is actually a pointer into the line numbers
4930
     of the file.  We locate the line number entry, and
4931
     set the section to the section which contains it, and
4932
     the value to the index in that section.  */
4933
        {
4934
    asection *sec;
4935
4936
    dst->symbol.flags = BSF_DEBUGGING;
4937
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4938
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4939
          && ((file_ptr) (sec->line_filepos
4940
              + sec->lineno_count * bfd_coff_linesz (abfd))
4941
        > (file_ptr) src->u.syment.n_value))
4942
        break;
4943
    if (sec == NULL)
4944
      dst->symbol.value = 0;
4945
    else
4946
      {
4947
        dst->symbol.section = sec;
4948
        dst->symbol.value = ((src->u.syment.n_value
4949
            - sec->line_filepos)
4950
           / bfd_coff_linesz (abfd));
4951
        src->fix_line = 1;
4952
      }
4953
        }
4954
        break;
4955
4956
      case C_BSTAT:
4957
        dst->symbol.flags = BSF_DEBUGGING;
4958
4959
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4960
    dst->symbol.value = 0;
4961
        else
4962
    {
4963
      /* The value is actually a symbol index.  Save a pointer
4964
         to the symbol instead of the index.  FIXME: This
4965
         should use a union.  */
4966
      src->u.syment.n_value
4967
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4968
      dst->symbol.value = src->u.syment.n_value;
4969
      src->fix_value = 1;
4970
    }
4971
        break;
4972
#endif
4973
4974
449
      case C_BLOCK: /* ".bb" or ".eb".  */
4975
3.32k
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4976
4.02k
      case C_EFCN: /* Physical end of function.  */
4977
#if defined COFF_WITH_PE
4978
        /* PE sets the symbol to a value relative to the start
4979
     of the section.  */
4980
        dst->symbol.value = src->u.syment.n_value;
4981
        if (strcmp (dst->symbol.name, ".bf") != 0)
4982
    {
4983
      /* PE uses funny values for .ef and .lf; don't
4984
         relocate them.  */
4985
      dst->symbol.flags = BSF_DEBUGGING;
4986
    }
4987
        else
4988
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4989
#else
4990
        /* Base the value as an index from the base of the
4991
     section.  */
4992
4.02k
        dst->symbol.flags = BSF_LOCAL;
4993
4.02k
        dst->symbol.value = (src->u.syment.n_value
4994
4.02k
           - dst->symbol.section->vma);
4995
4.02k
#endif
4996
4.02k
        break;
4997
4998
296
      case C_STATLAB: /* Static load time label.  */
4999
296
        dst->symbol.value = src->u.syment.n_value;
5000
296
        dst->symbol.flags = BSF_GLOBAL;
5001
296
        break;
5002
5003
118k
      case C_NULL:
5004
        /* PE DLLs sometimes have zeroed out symbols for some
5005
     reason.  Just ignore them without a warning.  */
5006
118k
        if (src->u.syment.n_type == 0
5007
118k
      && src->u.syment.n_value == 0
5008
118k
      && src->u.syment.n_scnum == 0)
5009
22.7k
    break;
5010
#ifdef RS6000COFF_C
5011
        /* XCOFF specific: deleted entry.  */
5012
        if (src->u.syment.n_value == C_NULL_VALUE)
5013
    break;
5014
#endif
5015
        /* Fall through.  */
5016
95.4k
      case C_EXTDEF: /* External definition.  */
5017
95.6k
      case C_ULABEL: /* Undefined label.  */
5018
95.7k
      case C_USTATIC: /* Undefined static.  */
5019
95.7k
#ifndef COFF_WITH_PE
5020
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5021
         class to represent a section symbol.  */
5022
97.0k
      case C_LINE: /* line # reformatted as symbol table entry.  */
5023
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5024
98.9k
      case C_ALIAS: /* Duplicate tag.  */
5025
98.9k
#endif
5026
        /* New storage classes for TI COFF.  */
5027
#ifdef TICOFF
5028
      case C_UEXT:  /* Tentative external definition.  */
5029
#endif
5030
99.0k
      case C_EXTLAB: /* External load time label.  */
5031
133k
      default:
5032
133k
        _bfd_error_handler
5033
    /* xgettext:c-format */
5034
133k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5035
133k
     abfd, src->u.syment.n_sclass,
5036
133k
     dst->symbol.section->name, dst->symbol.name);
5037
133k
        ret = false;
5038
        /* Fall through.  */
5039
133k
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5040
        /* PR 20722: These symbols can also be generated by
5041
     building DLLs with --gc-sections enabled.  */
5042
133k
        dst->symbol.flags = BSF_DEBUGGING;
5043
133k
        dst->symbol.value = (src->u.syment.n_value);
5044
133k
        break;
5045
189k
      }
5046
5047
189k
    dst->native = src;
5048
189k
    dst->symbol.udata.i = 0;
5049
189k
    dst->lineno = NULL;
5050
5051
189k
    this_index += (src->u.syment.n_numaux) + 1;
5052
189k
    dst++;
5053
189k
    number_of_symbols++;
5054
189k
  }
5055
1.41k
    }
5056
5057
1.41k
  obj_symbols (abfd) = cached_area;
5058
1.41k
  obj_raw_syments (abfd) = native_symbols;
5059
5060
1.41k
  abfd->symcount = number_of_symbols;
5061
1.41k
  obj_convert (abfd) = table_ptr;
5062
  /* Slurp the line tables for each section too.  */
5063
1.41k
  {
5064
1.41k
    asection *p;
5065
5066
1.41k
    p = abfd->sections;
5067
5.20k
    while (p)
5068
4.90k
      {
5069
4.90k
  if (! coff_slurp_line_table (abfd, p))
5070
1.11k
    return false;
5071
3.78k
  p = p->next;
5072
3.78k
      }
5073
1.41k
  }
5074
5075
299
  return ret;
5076
1.41k
}
Unexecuted instantiation: coff-tic4x.c:coff_slurp_symbol_table
coff-tic54x.c:coff_slurp_symbol_table
Line
Count
Source
4704
11.9k
{
4705
11.9k
  combined_entry_type *native_symbols;
4706
11.9k
  coff_symbol_type *cached_area;
4707
11.9k
  unsigned int *table_ptr;
4708
11.9k
  unsigned int number_of_symbols = 0;
4709
11.9k
  bool ret = true;
4710
11.9k
  size_t amt;
4711
4712
11.9k
  if (obj_symbols (abfd))
4713
1.65k
    return true;
4714
4715
  /* Read in the symbol table.  */
4716
10.3k
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4717
9.06k
    return false;
4718
4719
  /* Allocate enough room for all the symbols in cached form.  */
4720
1.25k
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4721
1.25k
       sizeof (*cached_area), &amt))
4722
0
    {
4723
0
      bfd_set_error (bfd_error_file_too_big);
4724
0
      return false;
4725
0
    }
4726
1.25k
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4727
1.25k
  if (cached_area == NULL)
4728
0
    return false;
4729
4730
1.25k
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4731
1.25k
       sizeof (*table_ptr), &amt))
4732
0
    {
4733
0
      bfd_set_error (bfd_error_file_too_big);
4734
0
      return false;
4735
0
    }
4736
1.25k
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4737
1.25k
  if (table_ptr == NULL)
4738
0
    return false;
4739
1.25k
  else
4740
1.25k
    {
4741
1.25k
      coff_symbol_type *dst = cached_area;
4742
1.25k
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4743
1.25k
      unsigned int this_index = 0;
4744
4745
280k
      while (this_index < last_native_index)
4746
279k
  {
4747
279k
    combined_entry_type *src = native_symbols + this_index;
4748
279k
    table_ptr[this_index] = number_of_symbols;
4749
4750
279k
    dst->symbol.the_bfd = abfd;
4751
279k
    BFD_ASSERT (src->is_sym);
4752
279k
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4753
    /* We use the native name field to point to the cached field.  */
4754
279k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4755
279k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4756
279k
                 src->u.syment.n_scnum);
4757
279k
    dst->symbol.flags = 0;
4758
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4759
279k
    dst->symbol.value = 0;
4760
279k
    dst->done_lineno = false;
4761
4762
279k
    switch (src->u.syment.n_sclass)
4763
279k
      {
4764
6.03k
      case C_EXT:
4765
6.29k
      case C_WEAKEXT:
4766
#if defined ARM
4767
      case C_THUMBEXT:
4768
      case C_THUMBEXTFUNC:
4769
#endif
4770
#ifdef RS6000COFF_C
4771
      case C_HIDEXT:
4772
#ifndef AIX_WEAK_SUPPORT
4773
      case C_AIX_WEAKEXT:
4774
#endif
4775
#endif
4776
6.29k
#ifdef C_SYSTEM
4777
7.08k
      case C_SYSTEM: /* System Wide variable.  */
4778
7.08k
#endif
4779
#ifdef COFF_WITH_PE
4780
      /* In PE, 0x68 (104) denotes a section symbol.  */
4781
      case C_SECTION:
4782
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4783
      case C_NT_WEAK:
4784
#endif
4785
7.08k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4786
7.08k
    {
4787
5.51k
    case COFF_SYMBOL_GLOBAL:
4788
5.51k
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4789
#if defined COFF_WITH_PE
4790
      /* PE sets the symbol to a value relative to the
4791
         start of the section.  */
4792
      dst->symbol.value = src->u.syment.n_value;
4793
#else
4794
5.51k
      dst->symbol.value = (src->u.syment.n_value
4795
5.51k
               - dst->symbol.section->vma);
4796
5.51k
#endif
4797
5.51k
      if (ISFCN ((src->u.syment.n_type)))
4798
        /* A function ext does not go at the end of a
4799
           file.  */
4800
84
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4801
5.51k
      break;
4802
4803
1.24k
    case COFF_SYMBOL_COMMON:
4804
1.24k
      dst->symbol.section = bfd_com_section_ptr;
4805
1.24k
      dst->symbol.value = src->u.syment.n_value;
4806
1.24k
      break;
4807
4808
333
    case COFF_SYMBOL_UNDEFINED:
4809
333
      dst->symbol.section = bfd_und_section_ptr;
4810
333
      dst->symbol.value = 0;
4811
333
      break;
4812
4813
0
    case COFF_SYMBOL_PE_SECTION:
4814
0
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4815
0
      dst->symbol.value = 0;
4816
0
      break;
4817
4818
0
    case COFF_SYMBOL_LOCAL:
4819
0
      dst->symbol.flags = BSF_LOCAL;
4820
#if defined COFF_WITH_PE
4821
      /* PE sets the symbol to a value relative to the
4822
         start of the section.  */
4823
      dst->symbol.value = src->u.syment.n_value;
4824
#else
4825
0
      dst->symbol.value = (src->u.syment.n_value
4826
0
               - dst->symbol.section->vma);
4827
0
#endif
4828
0
      if (ISFCN ((src->u.syment.n_type)))
4829
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4830
0
      break;
4831
7.08k
    }
4832
4833
#ifdef RS6000COFF_C
4834
        /* A symbol with a csect entry should not go at the end.  */
4835
        if (src->u.syment.n_numaux > 0)
4836
    dst->symbol.flags |= BSF_NOT_AT_END;
4837
#endif
4838
4839
#ifdef COFF_WITH_PE
4840
        if (src->u.syment.n_sclass == C_NT_WEAK)
4841
    dst->symbol.flags |= BSF_WEAK;
4842
4843
        if (src->u.syment.n_sclass == C_SECTION
4844
      && src->u.syment.n_scnum > 0)
4845
    dst->symbol.flags = BSF_LOCAL;
4846
#endif
4847
7.08k
        if (src->u.syment.n_sclass == C_WEAKEXT
4848
#ifdef RS6000COFF_C
4849
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4850
#endif
4851
7.08k
      )
4852
256
    dst->symbol.flags |= BSF_WEAK;
4853
4854
7.08k
        break;
4855
4856
3.24k
      case C_STAT:  /* Static.  */
4857
#if defined ARM
4858
      case C_THUMBSTAT:    /* Thumb static.  */
4859
      case C_THUMBLABEL:   /* Thumb label.  */
4860
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4861
#endif
4862
#ifdef RS6000COFF_C
4863
      case C_DWARF:  /* A label in a dwarf section.  */
4864
      case C_INFO:   /* A label in a comment section.  */
4865
#endif
4866
4.26k
      case C_LABEL:  /* Label.  */
4867
4.26k
        if (src->u.syment.n_scnum == N_DEBUG)
4868
7
    dst->symbol.flags = BSF_DEBUGGING;
4869
4.25k
        else
4870
4.25k
    dst->symbol.flags = BSF_LOCAL;
4871
4872
        /* Base the value as an index from the base of the
4873
     section, if there is one.  */
4874
4.26k
        if (dst->symbol.section)
4875
4.26k
    {
4876
#if defined COFF_WITH_PE
4877
      /* PE sets the symbol to a value relative to the
4878
         start of the section.  */
4879
      dst->symbol.value = src->u.syment.n_value;
4880
#else
4881
4.26k
      dst->symbol.value = (src->u.syment.n_value
4882
4.26k
               - dst->symbol.section->vma);
4883
4.26k
#endif
4884
4.26k
    }
4885
0
        else
4886
0
    dst->symbol.value = src->u.syment.n_value;
4887
4.26k
        break;
4888
4889
1.45k
      case C_FILE: /* File name.  */
4890
1.45k
        dst->symbol.flags = BSF_FILE;
4891
        /* Fall through.  */
4892
3.51k
      case C_MOS:   /* Member of structure.  */
4893
4.17k
      case C_EOS:   /* End of structure.  */
4894
4.90k
      case C_REGPARM: /* Register parameter.  */
4895
9.25k
      case C_REG:   /* register variable.  */
4896
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4897
10.5k
      case C_TPDEF: /* Type definition.  */
4898
12.4k
      case C_ARG:
4899
27.0k
      case C_AUTO: /* Automatic variable.  */
4900
27.9k
      case C_FIELD: /* Bit field.  */
4901
28.6k
      case C_ENTAG: /* Enumeration tag.  */
4902
30.7k
      case C_MOE:   /* Member of enumeration.  */
4903
31.3k
      case C_MOU:   /* Member of union.  */
4904
32.2k
      case C_UNTAG: /* Union tag.  */
4905
34.3k
      case C_STRTAG: /* Structure tag.  */
4906
#ifdef RS6000COFF_C
4907
      case C_GSYM:
4908
      case C_LSYM:
4909
      case C_PSYM:
4910
      case C_RSYM:
4911
      case C_RPSYM:
4912
      case C_STSYM:
4913
      case C_TCSYM:
4914
      case C_BCOMM:
4915
      case C_ECOML:
4916
      case C_ECOMM:
4917
      case C_DECL:
4918
      case C_ENTRY:
4919
      case C_FUN:
4920
      case C_ESTAT:
4921
#endif
4922
34.3k
        dst->symbol.flags |= BSF_DEBUGGING;
4923
34.3k
        dst->symbol.value = (src->u.syment.n_value);
4924
34.3k
        break;
4925
4926
#ifdef RS6000COFF_C
4927
      case C_BINCL: /* Beginning of include file.  */
4928
      case C_EINCL: /* Ending of include file.  */
4929
        /* The value is actually a pointer into the line numbers
4930
     of the file.  We locate the line number entry, and
4931
     set the section to the section which contains it, and
4932
     the value to the index in that section.  */
4933
        {
4934
    asection *sec;
4935
4936
    dst->symbol.flags = BSF_DEBUGGING;
4937
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4938
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4939
          && ((file_ptr) (sec->line_filepos
4940
              + sec->lineno_count * bfd_coff_linesz (abfd))
4941
        > (file_ptr) src->u.syment.n_value))
4942
        break;
4943
    if (sec == NULL)
4944
      dst->symbol.value = 0;
4945
    else
4946
      {
4947
        dst->symbol.section = sec;
4948
        dst->symbol.value = ((src->u.syment.n_value
4949
            - sec->line_filepos)
4950
           / bfd_coff_linesz (abfd));
4951
        src->fix_line = 1;
4952
      }
4953
        }
4954
        break;
4955
4956
      case C_BSTAT:
4957
        dst->symbol.flags = BSF_DEBUGGING;
4958
4959
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4960
    dst->symbol.value = 0;
4961
        else
4962
    {
4963
      /* The value is actually a symbol index.  Save a pointer
4964
         to the symbol instead of the index.  FIXME: This
4965
         should use a union.  */
4966
      src->u.syment.n_value
4967
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4968
      dst->symbol.value = src->u.syment.n_value;
4969
      src->fix_value = 1;
4970
    }
4971
        break;
4972
#endif
4973
4974
570
      case C_BLOCK: /* ".bb" or ".eb".  */
4975
3.82k
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4976
5.22k
      case C_EFCN: /* Physical end of function.  */
4977
#if defined COFF_WITH_PE
4978
        /* PE sets the symbol to a value relative to the start
4979
     of the section.  */
4980
        dst->symbol.value = src->u.syment.n_value;
4981
        if (strcmp (dst->symbol.name, ".bf") != 0)
4982
    {
4983
      /* PE uses funny values for .ef and .lf; don't
4984
         relocate them.  */
4985
      dst->symbol.flags = BSF_DEBUGGING;
4986
    }
4987
        else
4988
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4989
#else
4990
        /* Base the value as an index from the base of the
4991
     section.  */
4992
5.22k
        dst->symbol.flags = BSF_LOCAL;
4993
5.22k
        dst->symbol.value = (src->u.syment.n_value
4994
5.22k
           - dst->symbol.section->vma);
4995
5.22k
#endif
4996
5.22k
        break;
4997
4998
591
      case C_STATLAB: /* Static load time label.  */
4999
591
        dst->symbol.value = src->u.syment.n_value;
5000
591
        dst->symbol.flags = BSF_GLOBAL;
5001
591
        break;
5002
5003
177k
      case C_NULL:
5004
        /* PE DLLs sometimes have zeroed out symbols for some
5005
     reason.  Just ignore them without a warning.  */
5006
177k
        if (src->u.syment.n_type == 0
5007
177k
      && src->u.syment.n_value == 0
5008
177k
      && src->u.syment.n_scnum == 0)
5009
45.1k
    break;
5010
#ifdef RS6000COFF_C
5011
        /* XCOFF specific: deleted entry.  */
5012
        if (src->u.syment.n_value == C_NULL_VALUE)
5013
    break;
5014
#endif
5015
        /* Fall through.  */
5016
132k
      case C_EXTDEF: /* External definition.  */
5017
133k
      case C_ULABEL: /* Undefined label.  */
5018
133k
      case C_USTATIC: /* Undefined static.  */
5019
133k
#ifndef COFF_WITH_PE
5020
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5021
         class to represent a section symbol.  */
5022
134k
      case C_LINE: /* line # reformatted as symbol table entry.  */
5023
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5024
136k
      case C_ALIAS: /* Duplicate tag.  */
5025
136k
#endif
5026
        /* New storage classes for TI COFF.  */
5027
136k
#ifdef TICOFF
5028
136k
      case C_UEXT: /* Tentative external definition.  */
5029
136k
#endif
5030
136k
      case C_EXTLAB: /* External load time label.  */
5031
182k
      default:
5032
182k
        _bfd_error_handler
5033
    /* xgettext:c-format */
5034
182k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5035
182k
     abfd, src->u.syment.n_sclass,
5036
182k
     dst->symbol.section->name, dst->symbol.name);
5037
182k
        ret = false;
5038
        /* Fall through.  */
5039
182k
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5040
        /* PR 20722: These symbols can also be generated by
5041
     building DLLs with --gc-sections enabled.  */
5042
182k
        dst->symbol.flags = BSF_DEBUGGING;
5043
182k
        dst->symbol.value = (src->u.syment.n_value);
5044
182k
        break;
5045
279k
      }
5046
5047
279k
    dst->native = src;
5048
279k
    dst->symbol.udata.i = 0;
5049
279k
    dst->lineno = NULL;
5050
5051
279k
    this_index += (src->u.syment.n_numaux) + 1;
5052
279k
    dst++;
5053
279k
    number_of_symbols++;
5054
279k
  }
5055
1.25k
    }
5056
5057
1.25k
  obj_symbols (abfd) = cached_area;
5058
1.25k
  obj_raw_syments (abfd) = native_symbols;
5059
5060
1.25k
  abfd->symcount = number_of_symbols;
5061
1.25k
  obj_convert (abfd) = table_ptr;
5062
  /* Slurp the line tables for each section too.  */
5063
1.25k
  {
5064
1.25k
    asection *p;
5065
5066
1.25k
    p = abfd->sections;
5067
7.78k
    while (p)
5068
7.51k
      {
5069
7.51k
  if (! coff_slurp_line_table (abfd, p))
5070
996
    return false;
5071
6.52k
  p = p->next;
5072
6.52k
      }
5073
1.25k
  }
5074
5075
263
  return ret;
5076
1.25k
}
coff-z80.c:coff_slurp_symbol_table
Line
Count
Source
4704
11.8k
{
4705
11.8k
  combined_entry_type *native_symbols;
4706
11.8k
  coff_symbol_type *cached_area;
4707
11.8k
  unsigned int *table_ptr;
4708
11.8k
  unsigned int number_of_symbols = 0;
4709
11.8k
  bool ret = true;
4710
11.8k
  size_t amt;
4711
4712
11.8k
  if (obj_symbols (abfd))
4713
3.25k
    return true;
4714
4715
  /* Read in the symbol table.  */
4716
8.63k
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4717
7.39k
    return false;
4718
4719
  /* Allocate enough room for all the symbols in cached form.  */
4720
1.23k
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4721
1.23k
       sizeof (*cached_area), &amt))
4722
0
    {
4723
0
      bfd_set_error (bfd_error_file_too_big);
4724
0
      return false;
4725
0
    }
4726
1.23k
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4727
1.23k
  if (cached_area == NULL)
4728
0
    return false;
4729
4730
1.23k
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4731
1.23k
       sizeof (*table_ptr), &amt))
4732
0
    {
4733
0
      bfd_set_error (bfd_error_file_too_big);
4734
0
      return false;
4735
0
    }
4736
1.23k
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4737
1.23k
  if (table_ptr == NULL)
4738
0
    return false;
4739
1.23k
  else
4740
1.23k
    {
4741
1.23k
      coff_symbol_type *dst = cached_area;
4742
1.23k
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4743
1.23k
      unsigned int this_index = 0;
4744
4745
147k
      while (this_index < last_native_index)
4746
146k
  {
4747
146k
    combined_entry_type *src = native_symbols + this_index;
4748
146k
    table_ptr[this_index] = number_of_symbols;
4749
4750
146k
    dst->symbol.the_bfd = abfd;
4751
146k
    BFD_ASSERT (src->is_sym);
4752
146k
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4753
    /* We use the native name field to point to the cached field.  */
4754
146k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4755
146k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4756
146k
                 src->u.syment.n_scnum);
4757
146k
    dst->symbol.flags = 0;
4758
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4759
146k
    dst->symbol.value = 0;
4760
146k
    dst->done_lineno = false;
4761
4762
146k
    switch (src->u.syment.n_sclass)
4763
146k
      {
4764
3.28k
      case C_EXT:
4765
3.52k
      case C_WEAKEXT:
4766
#if defined ARM
4767
      case C_THUMBEXT:
4768
      case C_THUMBEXTFUNC:
4769
#endif
4770
#ifdef RS6000COFF_C
4771
      case C_HIDEXT:
4772
#ifndef AIX_WEAK_SUPPORT
4773
      case C_AIX_WEAKEXT:
4774
#endif
4775
#endif
4776
3.52k
#ifdef C_SYSTEM
4777
3.84k
      case C_SYSTEM: /* System Wide variable.  */
4778
3.84k
#endif
4779
#ifdef COFF_WITH_PE
4780
      /* In PE, 0x68 (104) denotes a section symbol.  */
4781
      case C_SECTION:
4782
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4783
      case C_NT_WEAK:
4784
#endif
4785
3.84k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4786
3.84k
    {
4787
2.95k
    case COFF_SYMBOL_GLOBAL:
4788
2.95k
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4789
#if defined COFF_WITH_PE
4790
      /* PE sets the symbol to a value relative to the
4791
         start of the section.  */
4792
      dst->symbol.value = src->u.syment.n_value;
4793
#else
4794
2.95k
      dst->symbol.value = (src->u.syment.n_value
4795
2.95k
               - dst->symbol.section->vma);
4796
2.95k
#endif
4797
2.95k
      if (ISFCN ((src->u.syment.n_type)))
4798
        /* A function ext does not go at the end of a
4799
           file.  */
4800
210
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4801
2.95k
      break;
4802
4803
576
    case COFF_SYMBOL_COMMON:
4804
576
      dst->symbol.section = bfd_com_section_ptr;
4805
576
      dst->symbol.value = src->u.syment.n_value;
4806
576
      break;
4807
4808
314
    case COFF_SYMBOL_UNDEFINED:
4809
314
      dst->symbol.section = bfd_und_section_ptr;
4810
314
      dst->symbol.value = 0;
4811
314
      break;
4812
4813
0
    case COFF_SYMBOL_PE_SECTION:
4814
0
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4815
0
      dst->symbol.value = 0;
4816
0
      break;
4817
4818
0
    case COFF_SYMBOL_LOCAL:
4819
0
      dst->symbol.flags = BSF_LOCAL;
4820
#if defined COFF_WITH_PE
4821
      /* PE sets the symbol to a value relative to the
4822
         start of the section.  */
4823
      dst->symbol.value = src->u.syment.n_value;
4824
#else
4825
0
      dst->symbol.value = (src->u.syment.n_value
4826
0
               - dst->symbol.section->vma);
4827
0
#endif
4828
0
      if (ISFCN ((src->u.syment.n_type)))
4829
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4830
0
      break;
4831
3.84k
    }
4832
4833
#ifdef RS6000COFF_C
4834
        /* A symbol with a csect entry should not go at the end.  */
4835
        if (src->u.syment.n_numaux > 0)
4836
    dst->symbol.flags |= BSF_NOT_AT_END;
4837
#endif
4838
4839
#ifdef COFF_WITH_PE
4840
        if (src->u.syment.n_sclass == C_NT_WEAK)
4841
    dst->symbol.flags |= BSF_WEAK;
4842
4843
        if (src->u.syment.n_sclass == C_SECTION
4844
      && src->u.syment.n_scnum > 0)
4845
    dst->symbol.flags = BSF_LOCAL;
4846
#endif
4847
3.84k
        if (src->u.syment.n_sclass == C_WEAKEXT
4848
#ifdef RS6000COFF_C
4849
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4850
#endif
4851
3.84k
      )
4852
246
    dst->symbol.flags |= BSF_WEAK;
4853
4854
3.84k
        break;
4855
4856
3.42k
      case C_STAT:  /* Static.  */
4857
#if defined ARM
4858
      case C_THUMBSTAT:    /* Thumb static.  */
4859
      case C_THUMBLABEL:   /* Thumb label.  */
4860
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4861
#endif
4862
#ifdef RS6000COFF_C
4863
      case C_DWARF:  /* A label in a dwarf section.  */
4864
      case C_INFO:   /* A label in a comment section.  */
4865
#endif
4866
4.00k
      case C_LABEL:  /* Label.  */
4867
4.00k
        if (src->u.syment.n_scnum == N_DEBUG)
4868
10
    dst->symbol.flags = BSF_DEBUGGING;
4869
3.99k
        else
4870
3.99k
    dst->symbol.flags = BSF_LOCAL;
4871
4872
        /* Base the value as an index from the base of the
4873
     section, if there is one.  */
4874
4.00k
        if (dst->symbol.section)
4875
4.00k
    {
4876
#if defined COFF_WITH_PE
4877
      /* PE sets the symbol to a value relative to the
4878
         start of the section.  */
4879
      dst->symbol.value = src->u.syment.n_value;
4880
#else
4881
4.00k
      dst->symbol.value = (src->u.syment.n_value
4882
4.00k
               - dst->symbol.section->vma);
4883
4.00k
#endif
4884
4.00k
    }
4885
0
        else
4886
0
    dst->symbol.value = src->u.syment.n_value;
4887
4.00k
        break;
4888
4889
1.18k
      case C_FILE: /* File name.  */
4890
1.18k
        dst->symbol.flags = BSF_FILE;
4891
        /* Fall through.  */
4892
1.97k
      case C_MOS:   /* Member of structure.  */
4893
2.39k
      case C_EOS:   /* End of structure.  */
4894
2.65k
      case C_REGPARM: /* Register parameter.  */
4895
3.45k
      case C_REG:   /* register variable.  */
4896
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4897
3.75k
      case C_TPDEF: /* Type definition.  */
4898
4.34k
      case C_ARG:
4899
10.4k
      case C_AUTO: /* Automatic variable.  */
4900
10.9k
      case C_FIELD: /* Bit field.  */
4901
11.4k
      case C_ENTAG: /* Enumeration tag.  */
4902
12.0k
      case C_MOE:   /* Member of enumeration.  */
4903
12.5k
      case C_MOU:   /* Member of union.  */
4904
13.0k
      case C_UNTAG: /* Union tag.  */
4905
14.3k
      case C_STRTAG: /* Structure tag.  */
4906
#ifdef RS6000COFF_C
4907
      case C_GSYM:
4908
      case C_LSYM:
4909
      case C_PSYM:
4910
      case C_RSYM:
4911
      case C_RPSYM:
4912
      case C_STSYM:
4913
      case C_TCSYM:
4914
      case C_BCOMM:
4915
      case C_ECOML:
4916
      case C_ECOMM:
4917
      case C_DECL:
4918
      case C_ENTRY:
4919
      case C_FUN:
4920
      case C_ESTAT:
4921
#endif
4922
14.3k
        dst->symbol.flags |= BSF_DEBUGGING;
4923
14.3k
        dst->symbol.value = (src->u.syment.n_value);
4924
14.3k
        break;
4925
4926
#ifdef RS6000COFF_C
4927
      case C_BINCL: /* Beginning of include file.  */
4928
      case C_EINCL: /* Ending of include file.  */
4929
        /* The value is actually a pointer into the line numbers
4930
     of the file.  We locate the line number entry, and
4931
     set the section to the section which contains it, and
4932
     the value to the index in that section.  */
4933
        {
4934
    asection *sec;
4935
4936
    dst->symbol.flags = BSF_DEBUGGING;
4937
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4938
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4939
          && ((file_ptr) (sec->line_filepos
4940
              + sec->lineno_count * bfd_coff_linesz (abfd))
4941
        > (file_ptr) src->u.syment.n_value))
4942
        break;
4943
    if (sec == NULL)
4944
      dst->symbol.value = 0;
4945
    else
4946
      {
4947
        dst->symbol.section = sec;
4948
        dst->symbol.value = ((src->u.syment.n_value
4949
            - sec->line_filepos)
4950
           / bfd_coff_linesz (abfd));
4951
        src->fix_line = 1;
4952
      }
4953
        }
4954
        break;
4955
4956
      case C_BSTAT:
4957
        dst->symbol.flags = BSF_DEBUGGING;
4958
4959
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4960
    dst->symbol.value = 0;
4961
        else
4962
    {
4963
      /* The value is actually a symbol index.  Save a pointer
4964
         to the symbol instead of the index.  FIXME: This
4965
         should use a union.  */
4966
      src->u.syment.n_value
4967
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4968
      dst->symbol.value = src->u.syment.n_value;
4969
      src->fix_value = 1;
4970
    }
4971
        break;
4972
#endif
4973
4974
353
      case C_BLOCK: /* ".bb" or ".eb".  */
4975
2.46k
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4976
3.10k
      case C_EFCN: /* Physical end of function.  */
4977
#if defined COFF_WITH_PE
4978
        /* PE sets the symbol to a value relative to the start
4979
     of the section.  */
4980
        dst->symbol.value = src->u.syment.n_value;
4981
        if (strcmp (dst->symbol.name, ".bf") != 0)
4982
    {
4983
      /* PE uses funny values for .ef and .lf; don't
4984
         relocate them.  */
4985
      dst->symbol.flags = BSF_DEBUGGING;
4986
    }
4987
        else
4988
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4989
#else
4990
        /* Base the value as an index from the base of the
4991
     section.  */
4992
3.10k
        dst->symbol.flags = BSF_LOCAL;
4993
3.10k
        dst->symbol.value = (src->u.syment.n_value
4994
3.10k
           - dst->symbol.section->vma);
4995
3.10k
#endif
4996
3.10k
        break;
4997
4998
270
      case C_STATLAB: /* Static load time label.  */
4999
270
        dst->symbol.value = src->u.syment.n_value;
5000
270
        dst->symbol.flags = BSF_GLOBAL;
5001
270
        break;
5002
5003
93.5k
      case C_NULL:
5004
        /* PE DLLs sometimes have zeroed out symbols for some
5005
     reason.  Just ignore them without a warning.  */
5006
93.5k
        if (src->u.syment.n_type == 0
5007
93.5k
      && src->u.syment.n_value == 0
5008
93.5k
      && src->u.syment.n_scnum == 0)
5009
30.6k
    break;
5010
#ifdef RS6000COFF_C
5011
        /* XCOFF specific: deleted entry.  */
5012
        if (src->u.syment.n_value == C_NULL_VALUE)
5013
    break;
5014
#endif
5015
        /* Fall through.  */
5016
63.1k
      case C_EXTDEF: /* External definition.  */
5017
63.3k
      case C_ULABEL: /* Undefined label.  */
5018
63.5k
      case C_USTATIC: /* Undefined static.  */
5019
63.5k
#ifndef COFF_WITH_PE
5020
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5021
         class to represent a section symbol.  */
5022
64.4k
      case C_LINE: /* line # reformatted as symbol table entry.  */
5023
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5024
65.5k
      case C_ALIAS: /* Duplicate tag.  */
5025
65.5k
#endif
5026
        /* New storage classes for TI COFF.  */
5027
#ifdef TICOFF
5028
      case C_UEXT:  /* Tentative external definition.  */
5029
#endif
5030
65.6k
      case C_EXTLAB: /* External load time label.  */
5031
89.8k
      default:
5032
89.8k
        _bfd_error_handler
5033
    /* xgettext:c-format */
5034
89.8k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5035
89.8k
     abfd, src->u.syment.n_sclass,
5036
89.8k
     dst->symbol.section->name, dst->symbol.name);
5037
89.8k
        ret = false;
5038
        /* Fall through.  */
5039
89.9k
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5040
        /* PR 20722: These symbols can also be generated by
5041
     building DLLs with --gc-sections enabled.  */
5042
89.9k
        dst->symbol.flags = BSF_DEBUGGING;
5043
89.9k
        dst->symbol.value = (src->u.syment.n_value);
5044
89.9k
        break;
5045
146k
      }
5046
5047
146k
    dst->native = src;
5048
146k
    dst->symbol.udata.i = 0;
5049
146k
    dst->lineno = NULL;
5050
5051
146k
    this_index += (src->u.syment.n_numaux) + 1;
5052
146k
    dst++;
5053
146k
    number_of_symbols++;
5054
146k
  }
5055
1.23k
    }
5056
5057
1.23k
  obj_symbols (abfd) = cached_area;
5058
1.23k
  obj_raw_syments (abfd) = native_symbols;
5059
5060
1.23k
  abfd->symcount = number_of_symbols;
5061
1.23k
  obj_convert (abfd) = table_ptr;
5062
  /* Slurp the line tables for each section too.  */
5063
1.23k
  {
5064
1.23k
    asection *p;
5065
5066
1.23k
    p = abfd->sections;
5067
6.47k
    while (p)
5068
6.20k
      {
5069
6.20k
  if (! coff_slurp_line_table (abfd, p))
5070
972
    return false;
5071
5.23k
  p = p->next;
5072
5.23k
      }
5073
1.23k
  }
5074
5075
264
  return ret;
5076
1.23k
}
coff-z8k.c:coff_slurp_symbol_table
Line
Count
Source
4704
8.63k
{
4705
8.63k
  combined_entry_type *native_symbols;
4706
8.63k
  coff_symbol_type *cached_area;
4707
8.63k
  unsigned int *table_ptr;
4708
8.63k
  unsigned int number_of_symbols = 0;
4709
8.63k
  bool ret = true;
4710
8.63k
  size_t amt;
4711
4712
8.63k
  if (obj_symbols (abfd))
4713
1.37k
    return true;
4714
4715
  /* Read in the symbol table.  */
4716
7.26k
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4717
6.27k
    return false;
4718
4719
  /* Allocate enough room for all the symbols in cached form.  */
4720
981
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4721
981
       sizeof (*cached_area), &amt))
4722
0
    {
4723
0
      bfd_set_error (bfd_error_file_too_big);
4724
0
      return false;
4725
0
    }
4726
981
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4727
981
  if (cached_area == NULL)
4728
0
    return false;
4729
4730
981
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4731
981
       sizeof (*table_ptr), &amt))
4732
0
    {
4733
0
      bfd_set_error (bfd_error_file_too_big);
4734
0
      return false;
4735
0
    }
4736
981
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4737
981
  if (table_ptr == NULL)
4738
0
    return false;
4739
981
  else
4740
981
    {
4741
981
      coff_symbol_type *dst = cached_area;
4742
981
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4743
981
      unsigned int this_index = 0;
4744
4745
324k
      while (this_index < last_native_index)
4746
323k
  {
4747
323k
    combined_entry_type *src = native_symbols + this_index;
4748
323k
    table_ptr[this_index] = number_of_symbols;
4749
4750
323k
    dst->symbol.the_bfd = abfd;
4751
323k
    BFD_ASSERT (src->is_sym);
4752
323k
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4753
    /* We use the native name field to point to the cached field.  */
4754
323k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4755
323k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4756
323k
                 src->u.syment.n_scnum);
4757
323k
    dst->symbol.flags = 0;
4758
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4759
323k
    dst->symbol.value = 0;
4760
323k
    dst->done_lineno = false;
4761
4762
323k
    switch (src->u.syment.n_sclass)
4763
323k
      {
4764
4.32k
      case C_EXT:
4765
4.90k
      case C_WEAKEXT:
4766
#if defined ARM
4767
      case C_THUMBEXT:
4768
      case C_THUMBEXTFUNC:
4769
#endif
4770
#ifdef RS6000COFF_C
4771
      case C_HIDEXT:
4772
#ifndef AIX_WEAK_SUPPORT
4773
      case C_AIX_WEAKEXT:
4774
#endif
4775
#endif
4776
4.90k
#ifdef C_SYSTEM
4777
7.09k
      case C_SYSTEM: /* System Wide variable.  */
4778
7.09k
#endif
4779
#ifdef COFF_WITH_PE
4780
      /* In PE, 0x68 (104) denotes a section symbol.  */
4781
      case C_SECTION:
4782
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4783
      case C_NT_WEAK:
4784
#endif
4785
7.09k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4786
7.09k
    {
4787
5.60k
    case COFF_SYMBOL_GLOBAL:
4788
5.60k
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4789
#if defined COFF_WITH_PE
4790
      /* PE sets the symbol to a value relative to the
4791
         start of the section.  */
4792
      dst->symbol.value = src->u.syment.n_value;
4793
#else
4794
5.60k
      dst->symbol.value = (src->u.syment.n_value
4795
5.60k
               - dst->symbol.section->vma);
4796
5.60k
#endif
4797
5.60k
      if (ISFCN ((src->u.syment.n_type)))
4798
        /* A function ext does not go at the end of a
4799
           file.  */
4800
139
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4801
5.60k
      break;
4802
4803
1.27k
    case COFF_SYMBOL_COMMON:
4804
1.27k
      dst->symbol.section = bfd_com_section_ptr;
4805
1.27k
      dst->symbol.value = src->u.syment.n_value;
4806
1.27k
      break;
4807
4808
226
    case COFF_SYMBOL_UNDEFINED:
4809
226
      dst->symbol.section = bfd_und_section_ptr;
4810
226
      dst->symbol.value = 0;
4811
226
      break;
4812
4813
0
    case COFF_SYMBOL_PE_SECTION:
4814
0
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4815
0
      dst->symbol.value = 0;
4816
0
      break;
4817
4818
0
    case COFF_SYMBOL_LOCAL:
4819
0
      dst->symbol.flags = BSF_LOCAL;
4820
#if defined COFF_WITH_PE
4821
      /* PE sets the symbol to a value relative to the
4822
         start of the section.  */
4823
      dst->symbol.value = src->u.syment.n_value;
4824
#else
4825
0
      dst->symbol.value = (src->u.syment.n_value
4826
0
               - dst->symbol.section->vma);
4827
0
#endif
4828
0
      if (ISFCN ((src->u.syment.n_type)))
4829
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4830
0
      break;
4831
7.09k
    }
4832
4833
#ifdef RS6000COFF_C
4834
        /* A symbol with a csect entry should not go at the end.  */
4835
        if (src->u.syment.n_numaux > 0)
4836
    dst->symbol.flags |= BSF_NOT_AT_END;
4837
#endif
4838
4839
#ifdef COFF_WITH_PE
4840
        if (src->u.syment.n_sclass == C_NT_WEAK)
4841
    dst->symbol.flags |= BSF_WEAK;
4842
4843
        if (src->u.syment.n_sclass == C_SECTION
4844
      && src->u.syment.n_scnum > 0)
4845
    dst->symbol.flags = BSF_LOCAL;
4846
#endif
4847
7.09k
        if (src->u.syment.n_sclass == C_WEAKEXT
4848
#ifdef RS6000COFF_C
4849
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4850
#endif
4851
7.09k
      )
4852
579
    dst->symbol.flags |= BSF_WEAK;
4853
4854
7.09k
        break;
4855
4856
2.22k
      case C_STAT:  /* Static.  */
4857
#if defined ARM
4858
      case C_THUMBSTAT:    /* Thumb static.  */
4859
      case C_THUMBLABEL:   /* Thumb label.  */
4860
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4861
#endif
4862
#ifdef RS6000COFF_C
4863
      case C_DWARF:  /* A label in a dwarf section.  */
4864
      case C_INFO:   /* A label in a comment section.  */
4865
#endif
4866
3.65k
      case C_LABEL:  /* Label.  */
4867
3.65k
        if (src->u.syment.n_scnum == N_DEBUG)
4868
3
    dst->symbol.flags = BSF_DEBUGGING;
4869
3.65k
        else
4870
3.65k
    dst->symbol.flags = BSF_LOCAL;
4871
4872
        /* Base the value as an index from the base of the
4873
     section, if there is one.  */
4874
3.65k
        if (dst->symbol.section)
4875
3.65k
    {
4876
#if defined COFF_WITH_PE
4877
      /* PE sets the symbol to a value relative to the
4878
         start of the section.  */
4879
      dst->symbol.value = src->u.syment.n_value;
4880
#else
4881
3.65k
      dst->symbol.value = (src->u.syment.n_value
4882
3.65k
               - dst->symbol.section->vma);
4883
3.65k
#endif
4884
3.65k
    }
4885
0
        else
4886
0
    dst->symbol.value = src->u.syment.n_value;
4887
3.65k
        break;
4888
4889
1.82k
      case C_FILE: /* File name.  */
4890
1.82k
        dst->symbol.flags = BSF_FILE;
4891
        /* Fall through.  */
4892
3.60k
      case C_MOS:   /* Member of structure.  */
4893
4.37k
      case C_EOS:   /* End of structure.  */
4894
5.05k
      case C_REGPARM: /* Register parameter.  */
4895
8.13k
      case C_REG:   /* register variable.  */
4896
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4897
9.11k
      case C_TPDEF: /* Type definition.  */
4898
10.7k
      case C_ARG:
4899
25.7k
      case C_AUTO: /* Automatic variable.  */
4900
26.6k
      case C_FIELD: /* Bit field.  */
4901
27.4k
      case C_ENTAG: /* Enumeration tag.  */
4902
29.1k
      case C_MOE:   /* Member of enumeration.  */
4903
30.0k
      case C_MOU:   /* Member of union.  */
4904
31.2k
      case C_UNTAG: /* Union tag.  */
4905
32.9k
      case C_STRTAG: /* Structure tag.  */
4906
#ifdef RS6000COFF_C
4907
      case C_GSYM:
4908
      case C_LSYM:
4909
      case C_PSYM:
4910
      case C_RSYM:
4911
      case C_RPSYM:
4912
      case C_STSYM:
4913
      case C_TCSYM:
4914
      case C_BCOMM:
4915
      case C_ECOML:
4916
      case C_ECOMM:
4917
      case C_DECL:
4918
      case C_ENTRY:
4919
      case C_FUN:
4920
      case C_ESTAT:
4921
#endif
4922
32.9k
        dst->symbol.flags |= BSF_DEBUGGING;
4923
32.9k
        dst->symbol.value = (src->u.syment.n_value);
4924
32.9k
        break;
4925
4926
#ifdef RS6000COFF_C
4927
      case C_BINCL: /* Beginning of include file.  */
4928
      case C_EINCL: /* Ending of include file.  */
4929
        /* The value is actually a pointer into the line numbers
4930
     of the file.  We locate the line number entry, and
4931
     set the section to the section which contains it, and
4932
     the value to the index in that section.  */
4933
        {
4934
    asection *sec;
4935
4936
    dst->symbol.flags = BSF_DEBUGGING;
4937
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4938
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4939
          && ((file_ptr) (sec->line_filepos
4940
              + sec->lineno_count * bfd_coff_linesz (abfd))
4941
        > (file_ptr) src->u.syment.n_value))
4942
        break;
4943
    if (sec == NULL)
4944
      dst->symbol.value = 0;
4945
    else
4946
      {
4947
        dst->symbol.section = sec;
4948
        dst->symbol.value = ((src->u.syment.n_value
4949
            - sec->line_filepos)
4950
           / bfd_coff_linesz (abfd));
4951
        src->fix_line = 1;
4952
      }
4953
        }
4954
        break;
4955
4956
      case C_BSTAT:
4957
        dst->symbol.flags = BSF_DEBUGGING;
4958
4959
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4960
    dst->symbol.value = 0;
4961
        else
4962
    {
4963
      /* The value is actually a symbol index.  Save a pointer
4964
         to the symbol instead of the index.  FIXME: This
4965
         should use a union.  */
4966
      src->u.syment.n_value
4967
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4968
      dst->symbol.value = src->u.syment.n_value;
4969
      src->fix_value = 1;
4970
    }
4971
        break;
4972
#endif
4973
4974
501
      case C_BLOCK: /* ".bb" or ".eb".  */
4975
5.45k
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4976
6.95k
      case C_EFCN: /* Physical end of function.  */
4977
#if defined COFF_WITH_PE
4978
        /* PE sets the symbol to a value relative to the start
4979
     of the section.  */
4980
        dst->symbol.value = src->u.syment.n_value;
4981
        if (strcmp (dst->symbol.name, ".bf") != 0)
4982
    {
4983
      /* PE uses funny values for .ef and .lf; don't
4984
         relocate them.  */
4985
      dst->symbol.flags = BSF_DEBUGGING;
4986
    }
4987
        else
4988
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4989
#else
4990
        /* Base the value as an index from the base of the
4991
     section.  */
4992
6.95k
        dst->symbol.flags = BSF_LOCAL;
4993
6.95k
        dst->symbol.value = (src->u.syment.n_value
4994
6.95k
           - dst->symbol.section->vma);
4995
6.95k
#endif
4996
6.95k
        break;
4997
4998
1.08k
      case C_STATLAB: /* Static load time label.  */
4999
1.08k
        dst->symbol.value = src->u.syment.n_value;
5000
1.08k
        dst->symbol.flags = BSF_GLOBAL;
5001
1.08k
        break;
5002
5003
208k
      case C_NULL:
5004
        /* PE DLLs sometimes have zeroed out symbols for some
5005
     reason.  Just ignore them without a warning.  */
5006
208k
        if (src->u.syment.n_type == 0
5007
208k
      && src->u.syment.n_value == 0
5008
208k
      && src->u.syment.n_scnum == 0)
5009
60.8k
    break;
5010
#ifdef RS6000COFF_C
5011
        /* XCOFF specific: deleted entry.  */
5012
        if (src->u.syment.n_value == C_NULL_VALUE)
5013
    break;
5014
#endif
5015
        /* Fall through.  */
5016
147k
      case C_EXTDEF: /* External definition.  */
5017
147k
      case C_ULABEL: /* Undefined label.  */
5018
148k
      case C_USTATIC: /* Undefined static.  */
5019
148k
#ifndef COFF_WITH_PE
5020
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5021
         class to represent a section symbol.  */
5022
150k
      case C_LINE: /* line # reformatted as symbol table entry.  */
5023
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5024
153k
      case C_ALIAS: /* Duplicate tag.  */
5025
153k
#endif
5026
        /* New storage classes for TI COFF.  */
5027
#ifdef TICOFF
5028
      case C_UEXT:  /* Tentative external definition.  */
5029
#endif
5030
154k
      case C_EXTLAB: /* External load time label.  */
5031
210k
      default:
5032
210k
        _bfd_error_handler
5033
    /* xgettext:c-format */
5034
210k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5035
210k
     abfd, src->u.syment.n_sclass,
5036
210k
     dst->symbol.section->name, dst->symbol.name);
5037
210k
        ret = false;
5038
        /* Fall through.  */
5039
211k
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5040
        /* PR 20722: These symbols can also be generated by
5041
     building DLLs with --gc-sections enabled.  */
5042
211k
        dst->symbol.flags = BSF_DEBUGGING;
5043
211k
        dst->symbol.value = (src->u.syment.n_value);
5044
211k
        break;
5045
323k
      }
5046
5047
323k
    dst->native = src;
5048
323k
    dst->symbol.udata.i = 0;
5049
323k
    dst->lineno = NULL;
5050
5051
323k
    this_index += (src->u.syment.n_numaux) + 1;
5052
323k
    dst++;
5053
323k
    number_of_symbols++;
5054
323k
  }
5055
981
    }
5056
5057
981
  obj_symbols (abfd) = cached_area;
5058
981
  obj_raw_syments (abfd) = native_symbols;
5059
5060
981
  abfd->symcount = number_of_symbols;
5061
981
  obj_convert (abfd) = table_ptr;
5062
  /* Slurp the line tables for each section too.  */
5063
981
  {
5064
981
    asection *p;
5065
5066
981
    p = abfd->sections;
5067
3.27k
    while (p)
5068
3.10k
      {
5069
3.10k
  if (! coff_slurp_line_table (abfd, p))
5070
809
    return false;
5071
2.29k
  p = p->next;
5072
2.29k
      }
5073
981
  }
5074
5075
172
  return ret;
5076
981
}
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
4704
1.10k
{
4705
1.10k
  combined_entry_type *native_symbols;
4706
1.10k
  coff_symbol_type *cached_area;
4707
1.10k
  unsigned int *table_ptr;
4708
1.10k
  unsigned int number_of_symbols = 0;
4709
1.10k
  bool ret = true;
4710
1.10k
  size_t amt;
4711
4712
1.10k
  if (obj_symbols (abfd))
4713
248
    return true;
4714
4715
  /* Read in the symbol table.  */
4716
860
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4717
41
    return false;
4718
4719
  /* Allocate enough room for all the symbols in cached form.  */
4720
819
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4721
819
       sizeof (*cached_area), &amt))
4722
0
    {
4723
0
      bfd_set_error (bfd_error_file_too_big);
4724
0
      return false;
4725
0
    }
4726
819
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4727
819
  if (cached_area == NULL)
4728
0
    return false;
4729
4730
819
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4731
819
       sizeof (*table_ptr), &amt))
4732
0
    {
4733
0
      bfd_set_error (bfd_error_file_too_big);
4734
0
      return false;
4735
0
    }
4736
819
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4737
819
  if (table_ptr == NULL)
4738
0
    return false;
4739
819
  else
4740
819
    {
4741
819
      coff_symbol_type *dst = cached_area;
4742
819
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4743
819
      unsigned int this_index = 0;
4744
4745
287k
      while (this_index < last_native_index)
4746
286k
  {
4747
286k
    combined_entry_type *src = native_symbols + this_index;
4748
286k
    table_ptr[this_index] = number_of_symbols;
4749
4750
286k
    dst->symbol.the_bfd = abfd;
4751
286k
    BFD_ASSERT (src->is_sym);
4752
286k
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4753
    /* We use the native name field to point to the cached field.  */
4754
286k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4755
286k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4756
286k
                 src->u.syment.n_scnum);
4757
286k
    dst->symbol.flags = 0;
4758
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4759
286k
    dst->symbol.value = 0;
4760
286k
    dst->done_lineno = false;
4761
4762
286k
    switch (src->u.syment.n_sclass)
4763
286k
      {
4764
6.64k
      case C_EXT:
4765
6.86k
      case C_WEAKEXT:
4766
#if defined ARM
4767
      case C_THUMBEXT:
4768
      case C_THUMBEXTFUNC:
4769
#endif
4770
#ifdef RS6000COFF_C
4771
      case C_HIDEXT:
4772
#ifndef AIX_WEAK_SUPPORT
4773
      case C_AIX_WEAKEXT:
4774
#endif
4775
#endif
4776
6.86k
#ifdef C_SYSTEM
4777
10.0k
      case C_SYSTEM: /* System Wide variable.  */
4778
10.0k
#endif
4779
10.0k
#ifdef COFF_WITH_PE
4780
      /* In PE, 0x68 (104) denotes a section symbol.  */
4781
10.0k
      case C_SECTION:
4782
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4783
14.0k
      case C_NT_WEAK:
4784
14.0k
#endif
4785
14.0k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4786
14.0k
    {
4787
12.6k
    case COFF_SYMBOL_GLOBAL:
4788
12.6k
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4789
12.6k
#if defined COFF_WITH_PE
4790
      /* PE sets the symbol to a value relative to the
4791
         start of the section.  */
4792
12.6k
      dst->symbol.value = src->u.syment.n_value;
4793
#else
4794
      dst->symbol.value = (src->u.syment.n_value
4795
               - dst->symbol.section->vma);
4796
#endif
4797
12.6k
      if (ISFCN ((src->u.syment.n_type)))
4798
        /* A function ext does not go at the end of a
4799
           file.  */
4800
675
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4801
12.6k
      break;
4802
4803
989
    case COFF_SYMBOL_COMMON:
4804
989
      dst->symbol.section = bfd_com_section_ptr;
4805
989
      dst->symbol.value = src->u.syment.n_value;
4806
989
      break;
4807
4808
389
    case COFF_SYMBOL_UNDEFINED:
4809
389
      dst->symbol.section = bfd_und_section_ptr;
4810
389
      dst->symbol.value = 0;
4811
389
      break;
4812
4813
0
    case COFF_SYMBOL_PE_SECTION:
4814
0
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4815
0
      dst->symbol.value = 0;
4816
0
      break;
4817
4818
0
    case COFF_SYMBOL_LOCAL:
4819
0
      dst->symbol.flags = BSF_LOCAL;
4820
0
#if defined COFF_WITH_PE
4821
      /* PE sets the symbol to a value relative to the
4822
         start of the section.  */
4823
0
      dst->symbol.value = src->u.syment.n_value;
4824
#else
4825
      dst->symbol.value = (src->u.syment.n_value
4826
               - dst->symbol.section->vma);
4827
#endif
4828
0
      if (ISFCN ((src->u.syment.n_type)))
4829
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4830
0
      break;
4831
14.0k
    }
4832
4833
#ifdef RS6000COFF_C
4834
        /* A symbol with a csect entry should not go at the end.  */
4835
        if (src->u.syment.n_numaux > 0)
4836
    dst->symbol.flags |= BSF_NOT_AT_END;
4837
#endif
4838
4839
14.0k
#ifdef COFF_WITH_PE
4840
14.0k
        if (src->u.syment.n_sclass == C_NT_WEAK)
4841
3.98k
    dst->symbol.flags |= BSF_WEAK;
4842
4843
14.0k
        if (src->u.syment.n_sclass == C_SECTION
4844
14.0k
      && src->u.syment.n_scnum > 0)
4845
0
    dst->symbol.flags = BSF_LOCAL;
4846
14.0k
#endif
4847
14.0k
        if (src->u.syment.n_sclass == C_WEAKEXT
4848
#ifdef RS6000COFF_C
4849
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4850
#endif
4851
14.0k
      )
4852
222
    dst->symbol.flags |= BSF_WEAK;
4853
4854
14.0k
        break;
4855
4856
4.27k
      case C_STAT:  /* Static.  */
4857
#if defined ARM
4858
      case C_THUMBSTAT:    /* Thumb static.  */
4859
      case C_THUMBLABEL:   /* Thumb label.  */
4860
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4861
#endif
4862
#ifdef RS6000COFF_C
4863
      case C_DWARF:  /* A label in a dwarf section.  */
4864
      case C_INFO:   /* A label in a comment section.  */
4865
#endif
4866
6.32k
      case C_LABEL:  /* Label.  */
4867
6.32k
        if (src->u.syment.n_scnum == N_DEBUG)
4868
4
    dst->symbol.flags = BSF_DEBUGGING;
4869
6.32k
        else
4870
6.32k
    dst->symbol.flags = BSF_LOCAL;
4871
4872
        /* Base the value as an index from the base of the
4873
     section, if there is one.  */
4874
6.32k
        if (dst->symbol.section)
4875
6.32k
    {
4876
6.32k
#if defined COFF_WITH_PE
4877
      /* PE sets the symbol to a value relative to the
4878
         start of the section.  */
4879
6.32k
      dst->symbol.value = src->u.syment.n_value;
4880
#else
4881
      dst->symbol.value = (src->u.syment.n_value
4882
               - dst->symbol.section->vma);
4883
#endif
4884
6.32k
    }
4885
0
        else
4886
0
    dst->symbol.value = src->u.syment.n_value;
4887
6.32k
        break;
4888
4889
1.96k
      case C_FILE: /* File name.  */
4890
1.96k
        dst->symbol.flags = BSF_FILE;
4891
        /* Fall through.  */
4892
3.16k
      case C_MOS:   /* Member of structure.  */
4893
5.17k
      case C_EOS:   /* End of structure.  */
4894
5.74k
      case C_REGPARM: /* Register parameter.  */
4895
6.95k
      case C_REG:   /* register variable.  */
4896
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4897
7.25k
      case C_TPDEF: /* Type definition.  */
4898
8.41k
      case C_ARG:
4899
15.7k
      case C_AUTO: /* Automatic variable.  */
4900
16.4k
      case C_FIELD: /* Bit field.  */
4901
16.8k
      case C_ENTAG: /* Enumeration tag.  */
4902
19.3k
      case C_MOE:   /* Member of enumeration.  */
4903
22.9k
      case C_MOU:   /* Member of union.  */
4904
23.5k
      case C_UNTAG: /* Union tag.  */
4905
24.8k
      case C_STRTAG: /* Structure tag.  */
4906
#ifdef RS6000COFF_C
4907
      case C_GSYM:
4908
      case C_LSYM:
4909
      case C_PSYM:
4910
      case C_RSYM:
4911
      case C_RPSYM:
4912
      case C_STSYM:
4913
      case C_TCSYM:
4914
      case C_BCOMM:
4915
      case C_ECOML:
4916
      case C_ECOMM:
4917
      case C_DECL:
4918
      case C_ENTRY:
4919
      case C_FUN:
4920
      case C_ESTAT:
4921
#endif
4922
24.8k
        dst->symbol.flags |= BSF_DEBUGGING;
4923
24.8k
        dst->symbol.value = (src->u.syment.n_value);
4924
24.8k
        break;
4925
4926
#ifdef RS6000COFF_C
4927
      case C_BINCL: /* Beginning of include file.  */
4928
      case C_EINCL: /* Ending of include file.  */
4929
        /* The value is actually a pointer into the line numbers
4930
     of the file.  We locate the line number entry, and
4931
     set the section to the section which contains it, and
4932
     the value to the index in that section.  */
4933
        {
4934
    asection *sec;
4935
4936
    dst->symbol.flags = BSF_DEBUGGING;
4937
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4938
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4939
          && ((file_ptr) (sec->line_filepos
4940
              + sec->lineno_count * bfd_coff_linesz (abfd))
4941
        > (file_ptr) src->u.syment.n_value))
4942
        break;
4943
    if (sec == NULL)
4944
      dst->symbol.value = 0;
4945
    else
4946
      {
4947
        dst->symbol.section = sec;
4948
        dst->symbol.value = ((src->u.syment.n_value
4949
            - sec->line_filepos)
4950
           / bfd_coff_linesz (abfd));
4951
        src->fix_line = 1;
4952
      }
4953
        }
4954
        break;
4955
4956
      case C_BSTAT:
4957
        dst->symbol.flags = BSF_DEBUGGING;
4958
4959
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4960
    dst->symbol.value = 0;
4961
        else
4962
    {
4963
      /* The value is actually a symbol index.  Save a pointer
4964
         to the symbol instead of the index.  FIXME: This
4965
         should use a union.  */
4966
      src->u.syment.n_value
4967
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4968
      dst->symbol.value = src->u.syment.n_value;
4969
      src->fix_value = 1;
4970
    }
4971
        break;
4972
#endif
4973
4974
718
      case C_BLOCK: /* ".bb" or ".eb".  */
4975
5.52k
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4976
7.22k
      case C_EFCN: /* Physical end of function.  */
4977
7.22k
#if defined COFF_WITH_PE
4978
        /* PE sets the symbol to a value relative to the start
4979
     of the section.  */
4980
7.22k
        dst->symbol.value = src->u.syment.n_value;
4981
7.22k
        if (strcmp (dst->symbol.name, ".bf") != 0)
4982
7.21k
    {
4983
      /* PE uses funny values for .ef and .lf; don't
4984
         relocate them.  */
4985
7.21k
      dst->symbol.flags = BSF_DEBUGGING;
4986
7.21k
    }
4987
9
        else
4988
9
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4989
#else
4990
        /* Base the value as an index from the base of the
4991
     section.  */
4992
        dst->symbol.flags = BSF_LOCAL;
4993
        dst->symbol.value = (src->u.syment.n_value
4994
           - dst->symbol.section->vma);
4995
#endif
4996
7.22k
        break;
4997
4998
586
      case C_STATLAB: /* Static load time label.  */
4999
586
        dst->symbol.value = src->u.syment.n_value;
5000
586
        dst->symbol.flags = BSF_GLOBAL;
5001
586
        break;
5002
5003
178k
      case C_NULL:
5004
        /* PE DLLs sometimes have zeroed out symbols for some
5005
     reason.  Just ignore them without a warning.  */
5006
178k
        if (src->u.syment.n_type == 0
5007
178k
      && src->u.syment.n_value == 0
5008
178k
      && src->u.syment.n_scnum == 0)
5009
60.0k
    break;
5010
#ifdef RS6000COFF_C
5011
        /* XCOFF specific: deleted entry.  */
5012
        if (src->u.syment.n_value == C_NULL_VALUE)
5013
    break;
5014
#endif
5015
        /* Fall through.  */
5016
119k
      case C_EXTDEF: /* External definition.  */
5017
119k
      case C_ULABEL: /* Undefined label.  */
5018
119k
      case C_USTATIC: /* Undefined static.  */
5019
#ifndef COFF_WITH_PE
5020
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5021
         class to represent a section symbol.  */
5022
      case C_LINE:  /* line # reformatted as symbol table entry.  */
5023
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5024
      case C_ALIAS: /* Duplicate tag.  */
5025
#endif
5026
        /* New storage classes for TI COFF.  */
5027
#ifdef TICOFF
5028
      case C_UEXT:  /* Tentative external definition.  */
5029
#endif
5030
119k
      case C_EXTLAB: /* External load time label.  */
5031
172k
      default:
5032
172k
        _bfd_error_handler
5033
    /* xgettext:c-format */
5034
172k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5035
172k
     abfd, src->u.syment.n_sclass,
5036
172k
     dst->symbol.section->name, dst->symbol.name);
5037
172k
        ret = false;
5038
        /* Fall through.  */
5039
173k
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5040
        /* PR 20722: These symbols can also be generated by
5041
     building DLLs with --gc-sections enabled.  */
5042
173k
        dst->symbol.flags = BSF_DEBUGGING;
5043
173k
        dst->symbol.value = (src->u.syment.n_value);
5044
173k
        break;
5045
286k
      }
5046
5047
286k
    dst->native = src;
5048
286k
    dst->symbol.udata.i = 0;
5049
286k
    dst->lineno = NULL;
5050
5051
286k
    this_index += (src->u.syment.n_numaux) + 1;
5052
286k
    dst++;
5053
286k
    number_of_symbols++;
5054
286k
  }
5055
819
    }
5056
5057
819
  obj_symbols (abfd) = cached_area;
5058
819
  obj_raw_syments (abfd) = native_symbols;
5059
5060
819
  abfd->symcount = number_of_symbols;
5061
819
  obj_convert (abfd) = table_ptr;
5062
  /* Slurp the line tables for each section too.  */
5063
819
  {
5064
819
    asection *p;
5065
5066
819
    p = abfd->sections;
5067
1.28k
    while (p)
5068
958
      {
5069
958
  if (! coff_slurp_line_table (abfd, p))
5070
496
    return false;
5071
462
  p = p->next;
5072
462
      }
5073
819
  }
5074
5075
323
  return ret;
5076
819
}
pe-mcore.c:coff_slurp_symbol_table
Line
Count
Source
4704
1.93k
{
4705
1.93k
  combined_entry_type *native_symbols;
4706
1.93k
  coff_symbol_type *cached_area;
4707
1.93k
  unsigned int *table_ptr;
4708
1.93k
  unsigned int number_of_symbols = 0;
4709
1.93k
  bool ret = true;
4710
1.93k
  size_t amt;
4711
4712
1.93k
  if (obj_symbols (abfd))
4713
552
    return true;
4714
4715
  /* Read in the symbol table.  */
4716
1.38k
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4717
263
    return false;
4718
4719
  /* Allocate enough room for all the symbols in cached form.  */
4720
1.11k
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4721
1.11k
       sizeof (*cached_area), &amt))
4722
0
    {
4723
0
      bfd_set_error (bfd_error_file_too_big);
4724
0
      return false;
4725
0
    }
4726
1.11k
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4727
1.11k
  if (cached_area == NULL)
4728
0
    return false;
4729
4730
1.11k
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4731
1.11k
       sizeof (*table_ptr), &amt))
4732
0
    {
4733
0
      bfd_set_error (bfd_error_file_too_big);
4734
0
      return false;
4735
0
    }
4736
1.11k
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4737
1.11k
  if (table_ptr == NULL)
4738
0
    return false;
4739
1.11k
  else
4740
1.11k
    {
4741
1.11k
      coff_symbol_type *dst = cached_area;
4742
1.11k
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4743
1.11k
      unsigned int this_index = 0;
4744
4745
345k
      while (this_index < last_native_index)
4746
344k
  {
4747
344k
    combined_entry_type *src = native_symbols + this_index;
4748
344k
    table_ptr[this_index] = number_of_symbols;
4749
4750
344k
    dst->symbol.the_bfd = abfd;
4751
344k
    BFD_ASSERT (src->is_sym);
4752
344k
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4753
    /* We use the native name field to point to the cached field.  */
4754
344k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4755
344k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4756
344k
                 src->u.syment.n_scnum);
4757
344k
    dst->symbol.flags = 0;
4758
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4759
344k
    dst->symbol.value = 0;
4760
344k
    dst->done_lineno = false;
4761
4762
344k
    switch (src->u.syment.n_sclass)
4763
344k
      {
4764
6.72k
      case C_EXT:
4765
7.14k
      case C_WEAKEXT:
4766
#if defined ARM
4767
      case C_THUMBEXT:
4768
      case C_THUMBEXTFUNC:
4769
#endif
4770
#ifdef RS6000COFF_C
4771
      case C_HIDEXT:
4772
#ifndef AIX_WEAK_SUPPORT
4773
      case C_AIX_WEAKEXT:
4774
#endif
4775
#endif
4776
7.14k
#ifdef C_SYSTEM
4777
8.70k
      case C_SYSTEM: /* System Wide variable.  */
4778
8.70k
#endif
4779
8.70k
#ifdef COFF_WITH_PE
4780
      /* In PE, 0x68 (104) denotes a section symbol.  */
4781
8.83k
      case C_SECTION:
4782
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4783
12.3k
      case C_NT_WEAK:
4784
12.3k
#endif
4785
12.3k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4786
12.3k
    {
4787
11.0k
    case COFF_SYMBOL_GLOBAL:
4788
11.0k
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4789
11.0k
#if defined COFF_WITH_PE
4790
      /* PE sets the symbol to a value relative to the
4791
         start of the section.  */
4792
11.0k
      dst->symbol.value = src->u.syment.n_value;
4793
#else
4794
      dst->symbol.value = (src->u.syment.n_value
4795
               - dst->symbol.section->vma);
4796
#endif
4797
11.0k
      if (ISFCN ((src->u.syment.n_type)))
4798
        /* A function ext does not go at the end of a
4799
           file.  */
4800
223
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4801
11.0k
      break;
4802
4803
867
    case COFF_SYMBOL_COMMON:
4804
867
      dst->symbol.section = bfd_com_section_ptr;
4805
867
      dst->symbol.value = src->u.syment.n_value;
4806
867
      break;
4807
4808
408
    case COFF_SYMBOL_UNDEFINED:
4809
408
      dst->symbol.section = bfd_und_section_ptr;
4810
408
      dst->symbol.value = 0;
4811
408
      break;
4812
4813
0
    case COFF_SYMBOL_PE_SECTION:
4814
0
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4815
0
      dst->symbol.value = 0;
4816
0
      break;
4817
4818
0
    case COFF_SYMBOL_LOCAL:
4819
0
      dst->symbol.flags = BSF_LOCAL;
4820
0
#if defined COFF_WITH_PE
4821
      /* PE sets the symbol to a value relative to the
4822
         start of the section.  */
4823
0
      dst->symbol.value = src->u.syment.n_value;
4824
#else
4825
      dst->symbol.value = (src->u.syment.n_value
4826
               - dst->symbol.section->vma);
4827
#endif
4828
0
      if (ISFCN ((src->u.syment.n_type)))
4829
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4830
0
      break;
4831
12.3k
    }
4832
4833
#ifdef RS6000COFF_C
4834
        /* A symbol with a csect entry should not go at the end.  */
4835
        if (src->u.syment.n_numaux > 0)
4836
    dst->symbol.flags |= BSF_NOT_AT_END;
4837
#endif
4838
4839
12.3k
#ifdef COFF_WITH_PE
4840
12.3k
        if (src->u.syment.n_sclass == C_NT_WEAK)
4841
3.53k
    dst->symbol.flags |= BSF_WEAK;
4842
4843
12.3k
        if (src->u.syment.n_sclass == C_SECTION
4844
12.3k
      && src->u.syment.n_scnum > 0)
4845
0
    dst->symbol.flags = BSF_LOCAL;
4846
12.3k
#endif
4847
12.3k
        if (src->u.syment.n_sclass == C_WEAKEXT
4848
#ifdef RS6000COFF_C
4849
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4850
#endif
4851
12.3k
      )
4852
422
    dst->symbol.flags |= BSF_WEAK;
4853
4854
12.3k
        break;
4855
4856
6.43k
      case C_STAT:  /* Static.  */
4857
#if defined ARM
4858
      case C_THUMBSTAT:    /* Thumb static.  */
4859
      case C_THUMBLABEL:   /* Thumb label.  */
4860
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4861
#endif
4862
#ifdef RS6000COFF_C
4863
      case C_DWARF:  /* A label in a dwarf section.  */
4864
      case C_INFO:   /* A label in a comment section.  */
4865
#endif
4866
9.47k
      case C_LABEL:  /* Label.  */
4867
9.47k
        if (src->u.syment.n_scnum == N_DEBUG)
4868
1
    dst->symbol.flags = BSF_DEBUGGING;
4869
9.47k
        else
4870
9.47k
    dst->symbol.flags = BSF_LOCAL;
4871
4872
        /* Base the value as an index from the base of the
4873
     section, if there is one.  */
4874
9.47k
        if (dst->symbol.section)
4875
9.47k
    {
4876
9.47k
#if defined COFF_WITH_PE
4877
      /* PE sets the symbol to a value relative to the
4878
         start of the section.  */
4879
9.47k
      dst->symbol.value = src->u.syment.n_value;
4880
#else
4881
      dst->symbol.value = (src->u.syment.n_value
4882
               - dst->symbol.section->vma);
4883
#endif
4884
9.47k
    }
4885
0
        else
4886
0
    dst->symbol.value = src->u.syment.n_value;
4887
9.47k
        break;
4888
4889
2.09k
      case C_FILE: /* File name.  */
4890
2.09k
        dst->symbol.flags = BSF_FILE;
4891
        /* Fall through.  */
4892
7.70k
      case C_MOS:   /* Member of structure.  */
4893
8.71k
      case C_EOS:   /* End of structure.  */
4894
9.41k
      case C_REGPARM: /* Register parameter.  */
4895
15.5k
      case C_REG:   /* register variable.  */
4896
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4897
16.8k
      case C_TPDEF: /* Type definition.  */
4898
18.9k
      case C_ARG:
4899
38.5k
      case C_AUTO: /* Automatic variable.  */
4900
39.2k
      case C_FIELD: /* Bit field.  */
4901
40.5k
      case C_ENTAG: /* Enumeration tag.  */
4902
42.0k
      case C_MOE:   /* Member of enumeration.  */
4903
45.7k
      case C_MOU:   /* Member of union.  */
4904
47.8k
      case C_UNTAG: /* Union tag.  */
4905
50.8k
      case C_STRTAG: /* Structure tag.  */
4906
#ifdef RS6000COFF_C
4907
      case C_GSYM:
4908
      case C_LSYM:
4909
      case C_PSYM:
4910
      case C_RSYM:
4911
      case C_RPSYM:
4912
      case C_STSYM:
4913
      case C_TCSYM:
4914
      case C_BCOMM:
4915
      case C_ECOML:
4916
      case C_ECOMM:
4917
      case C_DECL:
4918
      case C_ENTRY:
4919
      case C_FUN:
4920
      case C_ESTAT:
4921
#endif
4922
50.8k
        dst->symbol.flags |= BSF_DEBUGGING;
4923
50.8k
        dst->symbol.value = (src->u.syment.n_value);
4924
50.8k
        break;
4925
4926
#ifdef RS6000COFF_C
4927
      case C_BINCL: /* Beginning of include file.  */
4928
      case C_EINCL: /* Ending of include file.  */
4929
        /* The value is actually a pointer into the line numbers
4930
     of the file.  We locate the line number entry, and
4931
     set the section to the section which contains it, and
4932
     the value to the index in that section.  */
4933
        {
4934
    asection *sec;
4935
4936
    dst->symbol.flags = BSF_DEBUGGING;
4937
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4938
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4939
          && ((file_ptr) (sec->line_filepos
4940
              + sec->lineno_count * bfd_coff_linesz (abfd))
4941
        > (file_ptr) src->u.syment.n_value))
4942
        break;
4943
    if (sec == NULL)
4944
      dst->symbol.value = 0;
4945
    else
4946
      {
4947
        dst->symbol.section = sec;
4948
        dst->symbol.value = ((src->u.syment.n_value
4949
            - sec->line_filepos)
4950
           / bfd_coff_linesz (abfd));
4951
        src->fix_line = 1;
4952
      }
4953
        }
4954
        break;
4955
4956
      case C_BSTAT:
4957
        dst->symbol.flags = BSF_DEBUGGING;
4958
4959
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4960
    dst->symbol.value = 0;
4961
        else
4962
    {
4963
      /* The value is actually a symbol index.  Save a pointer
4964
         to the symbol instead of the index.  FIXME: This
4965
         should use a union.  */
4966
      src->u.syment.n_value
4967
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4968
      dst->symbol.value = src->u.syment.n_value;
4969
      src->fix_value = 1;
4970
    }
4971
        break;
4972
#endif
4973
4974
971
      case C_BLOCK: /* ".bb" or ".eb".  */
4975
6.01k
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4976
7.40k
      case C_EFCN: /* Physical end of function.  */
4977
7.40k
#if defined COFF_WITH_PE
4978
        /* PE sets the symbol to a value relative to the start
4979
     of the section.  */
4980
7.40k
        dst->symbol.value = src->u.syment.n_value;
4981
7.40k
        if (strcmp (dst->symbol.name, ".bf") != 0)
4982
7.40k
    {
4983
      /* PE uses funny values for .ef and .lf; don't
4984
         relocate them.  */
4985
7.40k
      dst->symbol.flags = BSF_DEBUGGING;
4986
7.40k
    }
4987
5
        else
4988
5
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4989
#else
4990
        /* Base the value as an index from the base of the
4991
     section.  */
4992
        dst->symbol.flags = BSF_LOCAL;
4993
        dst->symbol.value = (src->u.syment.n_value
4994
           - dst->symbol.section->vma);
4995
#endif
4996
7.40k
        break;
4997
4998
1.00k
      case C_STATLAB: /* Static load time label.  */
4999
1.00k
        dst->symbol.value = src->u.syment.n_value;
5000
1.00k
        dst->symbol.flags = BSF_GLOBAL;
5001
1.00k
        break;
5002
5003
205k
      case C_NULL:
5004
        /* PE DLLs sometimes have zeroed out symbols for some
5005
     reason.  Just ignore them without a warning.  */
5006
205k
        if (src->u.syment.n_type == 0
5007
205k
      && src->u.syment.n_value == 0
5008
205k
      && src->u.syment.n_scnum == 0)
5009
75.3k
    break;
5010
#ifdef RS6000COFF_C
5011
        /* XCOFF specific: deleted entry.  */
5012
        if (src->u.syment.n_value == C_NULL_VALUE)
5013
    break;
5014
#endif
5015
        /* Fall through.  */
5016
130k
      case C_EXTDEF: /* External definition.  */
5017
130k
      case C_ULABEL: /* Undefined label.  */
5018
130k
      case C_USTATIC: /* Undefined static.  */
5019
#ifndef COFF_WITH_PE
5020
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5021
         class to represent a section symbol.  */
5022
      case C_LINE:  /* line # reformatted as symbol table entry.  */
5023
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5024
      case C_ALIAS: /* Duplicate tag.  */
5025
#endif
5026
        /* New storage classes for TI COFF.  */
5027
#ifdef TICOFF
5028
      case C_UEXT:  /* Tentative external definition.  */
5029
#endif
5030
131k
      case C_EXTLAB: /* External load time label.  */
5031
187k
      default:
5032
187k
        _bfd_error_handler
5033
    /* xgettext:c-format */
5034
187k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5035
187k
     abfd, src->u.syment.n_sclass,
5036
187k
     dst->symbol.section->name, dst->symbol.name);
5037
187k
        ret = false;
5038
        /* Fall through.  */
5039
187k
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5040
        /* PR 20722: These symbols can also be generated by
5041
     building DLLs with --gc-sections enabled.  */
5042
187k
        dst->symbol.flags = BSF_DEBUGGING;
5043
187k
        dst->symbol.value = (src->u.syment.n_value);
5044
187k
        break;
5045
344k
      }
5046
5047
344k
    dst->native = src;
5048
344k
    dst->symbol.udata.i = 0;
5049
344k
    dst->lineno = NULL;
5050
5051
344k
    this_index += (src->u.syment.n_numaux) + 1;
5052
344k
    dst++;
5053
344k
    number_of_symbols++;
5054
344k
  }
5055
1.11k
    }
5056
5057
1.11k
  obj_symbols (abfd) = cached_area;
5058
1.11k
  obj_raw_syments (abfd) = native_symbols;
5059
5060
1.11k
  abfd->symcount = number_of_symbols;
5061
1.11k
  obj_convert (abfd) = table_ptr;
5062
  /* Slurp the line tables for each section too.  */
5063
1.11k
  {
5064
1.11k
    asection *p;
5065
5066
1.11k
    p = abfd->sections;
5067
3.42k
    while (p)
5068
2.92k
      {
5069
2.92k
  if (! coff_slurp_line_table (abfd, p))
5070
617
    return false;
5071
2.30k
  p = p->next;
5072
2.30k
      }
5073
1.11k
  }
5074
5075
500
  return ret;
5076
1.11k
}
pe-sh.c:coff_slurp_symbol_table
Line
Count
Source
4704
1.67k
{
4705
1.67k
  combined_entry_type *native_symbols;
4706
1.67k
  coff_symbol_type *cached_area;
4707
1.67k
  unsigned int *table_ptr;
4708
1.67k
  unsigned int number_of_symbols = 0;
4709
1.67k
  bool ret = true;
4710
1.67k
  size_t amt;
4711
4712
1.67k
  if (obj_symbols (abfd))
4713
544
    return true;
4714
4715
  /* Read in the symbol table.  */
4716
1.13k
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4717
117
    return false;
4718
4719
  /* Allocate enough room for all the symbols in cached form.  */
4720
1.01k
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4721
1.01k
       sizeof (*cached_area), &amt))
4722
0
    {
4723
0
      bfd_set_error (bfd_error_file_too_big);
4724
0
      return false;
4725
0
    }
4726
1.01k
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4727
1.01k
  if (cached_area == NULL)
4728
0
    return false;
4729
4730
1.01k
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4731
1.01k
       sizeof (*table_ptr), &amt))
4732
0
    {
4733
0
      bfd_set_error (bfd_error_file_too_big);
4734
0
      return false;
4735
0
    }
4736
1.01k
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4737
1.01k
  if (table_ptr == NULL)
4738
0
    return false;
4739
1.01k
  else
4740
1.01k
    {
4741
1.01k
      coff_symbol_type *dst = cached_area;
4742
1.01k
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4743
1.01k
      unsigned int this_index = 0;
4744
4745
276k
      while (this_index < last_native_index)
4746
275k
  {
4747
275k
    combined_entry_type *src = native_symbols + this_index;
4748
275k
    table_ptr[this_index] = number_of_symbols;
4749
4750
275k
    dst->symbol.the_bfd = abfd;
4751
275k
    BFD_ASSERT (src->is_sym);
4752
275k
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4753
    /* We use the native name field to point to the cached field.  */
4754
275k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4755
275k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4756
275k
                 src->u.syment.n_scnum);
4757
275k
    dst->symbol.flags = 0;
4758
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4759
275k
    dst->symbol.value = 0;
4760
275k
    dst->done_lineno = false;
4761
4762
275k
    switch (src->u.syment.n_sclass)
4763
275k
      {
4764
6.42k
      case C_EXT:
4765
6.81k
      case C_WEAKEXT:
4766
#if defined ARM
4767
      case C_THUMBEXT:
4768
      case C_THUMBEXTFUNC:
4769
#endif
4770
#ifdef RS6000COFF_C
4771
      case C_HIDEXT:
4772
#ifndef AIX_WEAK_SUPPORT
4773
      case C_AIX_WEAKEXT:
4774
#endif
4775
#endif
4776
6.81k
#ifdef C_SYSTEM
4777
8.22k
      case C_SYSTEM: /* System Wide variable.  */
4778
8.22k
#endif
4779
8.22k
#ifdef COFF_WITH_PE
4780
      /* In PE, 0x68 (104) denotes a section symbol.  */
4781
8.33k
      case C_SECTION:
4782
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4783
11.8k
      case C_NT_WEAK:
4784
11.8k
#endif
4785
11.8k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4786
11.8k
    {
4787
10.6k
    case COFF_SYMBOL_GLOBAL:
4788
10.6k
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4789
10.6k
#if defined COFF_WITH_PE
4790
      /* PE sets the symbol to a value relative to the
4791
         start of the section.  */
4792
10.6k
      dst->symbol.value = src->u.syment.n_value;
4793
#else
4794
      dst->symbol.value = (src->u.syment.n_value
4795
               - dst->symbol.section->vma);
4796
#endif
4797
10.6k
      if (ISFCN ((src->u.syment.n_type)))
4798
        /* A function ext does not go at the end of a
4799
           file.  */
4800
404
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4801
10.6k
      break;
4802
4803
818
    case COFF_SYMBOL_COMMON:
4804
818
      dst->symbol.section = bfd_com_section_ptr;
4805
818
      dst->symbol.value = src->u.syment.n_value;
4806
818
      break;
4807
4808
430
    case COFF_SYMBOL_UNDEFINED:
4809
430
      dst->symbol.section = bfd_und_section_ptr;
4810
430
      dst->symbol.value = 0;
4811
430
      break;
4812
4813
0
    case COFF_SYMBOL_PE_SECTION:
4814
0
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4815
0
      dst->symbol.value = 0;
4816
0
      break;
4817
4818
0
    case COFF_SYMBOL_LOCAL:
4819
0
      dst->symbol.flags = BSF_LOCAL;
4820
0
#if defined COFF_WITH_PE
4821
      /* PE sets the symbol to a value relative to the
4822
         start of the section.  */
4823
0
      dst->symbol.value = src->u.syment.n_value;
4824
#else
4825
      dst->symbol.value = (src->u.syment.n_value
4826
               - dst->symbol.section->vma);
4827
#endif
4828
0
      if (ISFCN ((src->u.syment.n_type)))
4829
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4830
0
      break;
4831
11.8k
    }
4832
4833
#ifdef RS6000COFF_C
4834
        /* A symbol with a csect entry should not go at the end.  */
4835
        if (src->u.syment.n_numaux > 0)
4836
    dst->symbol.flags |= BSF_NOT_AT_END;
4837
#endif
4838
4839
11.8k
#ifdef COFF_WITH_PE
4840
11.8k
        if (src->u.syment.n_sclass == C_NT_WEAK)
4841
3.53k
    dst->symbol.flags |= BSF_WEAK;
4842
4843
11.8k
        if (src->u.syment.n_sclass == C_SECTION
4844
11.8k
      && src->u.syment.n_scnum > 0)
4845
0
    dst->symbol.flags = BSF_LOCAL;
4846
11.8k
#endif
4847
11.8k
        if (src->u.syment.n_sclass == C_WEAKEXT
4848
#ifdef RS6000COFF_C
4849
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4850
#endif
4851
11.8k
      )
4852
387
    dst->symbol.flags |= BSF_WEAK;
4853
4854
11.8k
        break;
4855
4856
4.16k
      case C_STAT:  /* Static.  */
4857
#if defined ARM
4858
      case C_THUMBSTAT:    /* Thumb static.  */
4859
      case C_THUMBLABEL:   /* Thumb label.  */
4860
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4861
#endif
4862
#ifdef RS6000COFF_C
4863
      case C_DWARF:  /* A label in a dwarf section.  */
4864
      case C_INFO:   /* A label in a comment section.  */
4865
#endif
4866
6.11k
      case C_LABEL:  /* Label.  */
4867
6.11k
        if (src->u.syment.n_scnum == N_DEBUG)
4868
4
    dst->symbol.flags = BSF_DEBUGGING;
4869
6.10k
        else
4870
6.10k
    dst->symbol.flags = BSF_LOCAL;
4871
4872
        /* Base the value as an index from the base of the
4873
     section, if there is one.  */
4874
6.11k
        if (dst->symbol.section)
4875
6.11k
    {
4876
6.11k
#if defined COFF_WITH_PE
4877
      /* PE sets the symbol to a value relative to the
4878
         start of the section.  */
4879
6.11k
      dst->symbol.value = src->u.syment.n_value;
4880
#else
4881
      dst->symbol.value = (src->u.syment.n_value
4882
               - dst->symbol.section->vma);
4883
#endif
4884
6.11k
    }
4885
0
        else
4886
0
    dst->symbol.value = src->u.syment.n_value;
4887
6.11k
        break;
4888
4889
1.86k
      case C_FILE: /* File name.  */
4890
1.86k
        dst->symbol.flags = BSF_FILE;
4891
        /* Fall through.  */
4892
3.51k
      case C_MOS:   /* Member of structure.  */
4893
4.52k
      case C_EOS:   /* End of structure.  */
4894
5.90k
      case C_REGPARM: /* Register parameter.  */
4895
10.4k
      case C_REG:   /* register variable.  */
4896
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4897
11.5k
      case C_TPDEF: /* Type definition.  */
4898
16.2k
      case C_ARG:
4899
25.1k
      case C_AUTO: /* Automatic variable.  */
4900
25.9k
      case C_FIELD: /* Bit field.  */
4901
27.0k
      case C_ENTAG: /* Enumeration tag.  */
4902
29.1k
      case C_MOE:   /* Member of enumeration.  */
4903
30.8k
      case C_MOU:   /* Member of union.  */
4904
33.7k
      case C_UNTAG: /* Union tag.  */
4905
34.8k
      case C_STRTAG: /* Structure tag.  */
4906
#ifdef RS6000COFF_C
4907
      case C_GSYM:
4908
      case C_LSYM:
4909
      case C_PSYM:
4910
      case C_RSYM:
4911
      case C_RPSYM:
4912
      case C_STSYM:
4913
      case C_TCSYM:
4914
      case C_BCOMM:
4915
      case C_ECOML:
4916
      case C_ECOMM:
4917
      case C_DECL:
4918
      case C_ENTRY:
4919
      case C_FUN:
4920
      case C_ESTAT:
4921
#endif
4922
34.8k
        dst->symbol.flags |= BSF_DEBUGGING;
4923
34.8k
        dst->symbol.value = (src->u.syment.n_value);
4924
34.8k
        break;
4925
4926
#ifdef RS6000COFF_C
4927
      case C_BINCL: /* Beginning of include file.  */
4928
      case C_EINCL: /* Ending of include file.  */
4929
        /* The value is actually a pointer into the line numbers
4930
     of the file.  We locate the line number entry, and
4931
     set the section to the section which contains it, and
4932
     the value to the index in that section.  */
4933
        {
4934
    asection *sec;
4935
4936
    dst->symbol.flags = BSF_DEBUGGING;
4937
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4938
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4939
          && ((file_ptr) (sec->line_filepos
4940
              + sec->lineno_count * bfd_coff_linesz (abfd))
4941
        > (file_ptr) src->u.syment.n_value))
4942
        break;
4943
    if (sec == NULL)
4944
      dst->symbol.value = 0;
4945
    else
4946
      {
4947
        dst->symbol.section = sec;
4948
        dst->symbol.value = ((src->u.syment.n_value
4949
            - sec->line_filepos)
4950
           / bfd_coff_linesz (abfd));
4951
        src->fix_line = 1;
4952
      }
4953
        }
4954
        break;
4955
4956
      case C_BSTAT:
4957
        dst->symbol.flags = BSF_DEBUGGING;
4958
4959
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4960
    dst->symbol.value = 0;
4961
        else
4962
    {
4963
      /* The value is actually a symbol index.  Save a pointer
4964
         to the symbol instead of the index.  FIXME: This
4965
         should use a union.  */
4966
      src->u.syment.n_value
4967
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4968
      dst->symbol.value = src->u.syment.n_value;
4969
      src->fix_value = 1;
4970
    }
4971
        break;
4972
#endif
4973
4974
681
      case C_BLOCK: /* ".bb" or ".eb".  */
4975
5.31k
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4976
6.60k
      case C_EFCN: /* Physical end of function.  */
4977
6.60k
#if defined COFF_WITH_PE
4978
        /* PE sets the symbol to a value relative to the start
4979
     of the section.  */
4980
6.60k
        dst->symbol.value = src->u.syment.n_value;
4981
6.60k
        if (strcmp (dst->symbol.name, ".bf") != 0)
4982
6.60k
    {
4983
      /* PE uses funny values for .ef and .lf; don't
4984
         relocate them.  */
4985
6.60k
      dst->symbol.flags = BSF_DEBUGGING;
4986
6.60k
    }
4987
0
        else
4988
0
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4989
#else
4990
        /* Base the value as an index from the base of the
4991
     section.  */
4992
        dst->symbol.flags = BSF_LOCAL;
4993
        dst->symbol.value = (src->u.syment.n_value
4994
           - dst->symbol.section->vma);
4995
#endif
4996
6.60k
        break;
4997
4998
1.08k
      case C_STATLAB: /* Static load time label.  */
4999
1.08k
        dst->symbol.value = src->u.syment.n_value;
5000
1.08k
        dst->symbol.flags = BSF_GLOBAL;
5001
1.08k
        break;
5002
5003
162k
      case C_NULL:
5004
        /* PE DLLs sometimes have zeroed out symbols for some
5005
     reason.  Just ignore them without a warning.  */
5006
162k
        if (src->u.syment.n_type == 0
5007
162k
      && src->u.syment.n_value == 0
5008
162k
      && src->u.syment.n_scnum == 0)
5009
41.8k
    break;
5010
#ifdef RS6000COFF_C
5011
        /* XCOFF specific: deleted entry.  */
5012
        if (src->u.syment.n_value == C_NULL_VALUE)
5013
    break;
5014
#endif
5015
        /* Fall through.  */
5016
120k
      case C_EXTDEF: /* External definition.  */
5017
121k
      case C_ULABEL: /* Undefined label.  */
5018
121k
      case C_USTATIC: /* Undefined static.  */
5019
#ifndef COFF_WITH_PE
5020
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5021
         class to represent a section symbol.  */
5022
      case C_LINE:  /* line # reformatted as symbol table entry.  */
5023
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5024
      case C_ALIAS: /* Duplicate tag.  */
5025
#endif
5026
        /* New storage classes for TI COFF.  */
5027
#ifdef TICOFF
5028
      case C_UEXT:  /* Tentative external definition.  */
5029
#endif
5030
121k
      case C_EXTLAB: /* External load time label.  */
5031
172k
      default:
5032
172k
        _bfd_error_handler
5033
    /* xgettext:c-format */
5034
172k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5035
172k
     abfd, src->u.syment.n_sclass,
5036
172k
     dst->symbol.section->name, dst->symbol.name);
5037
172k
        ret = false;
5038
        /* Fall through.  */
5039
173k
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5040
        /* PR 20722: These symbols can also be generated by
5041
     building DLLs with --gc-sections enabled.  */
5042
173k
        dst->symbol.flags = BSF_DEBUGGING;
5043
173k
        dst->symbol.value = (src->u.syment.n_value);
5044
173k
        break;
5045
275k
      }
5046
5047
275k
    dst->native = src;
5048
275k
    dst->symbol.udata.i = 0;
5049
275k
    dst->lineno = NULL;
5050
5051
275k
    this_index += (src->u.syment.n_numaux) + 1;
5052
275k
    dst++;
5053
275k
    number_of_symbols++;
5054
275k
  }
5055
1.01k
    }
5056
5057
1.01k
  obj_symbols (abfd) = cached_area;
5058
1.01k
  obj_raw_syments (abfd) = native_symbols;
5059
5060
1.01k
  abfd->symcount = number_of_symbols;
5061
1.01k
  obj_convert (abfd) = table_ptr;
5062
  /* Slurp the line tables for each section too.  */
5063
1.01k
  {
5064
1.01k
    asection *p;
5065
5066
1.01k
    p = abfd->sections;
5067
1.97k
    while (p)
5068
1.65k
      {
5069
1.65k
  if (! coff_slurp_line_table (abfd, p))
5070
700
    return false;
5071
959
  p = p->next;
5072
959
      }
5073
1.01k
  }
5074
5075
315
  return ret;
5076
1.01k
}
pei-arm-wince.c:coff_slurp_symbol_table
Line
Count
Source
4704
716
{
4705
716
  combined_entry_type *native_symbols;
4706
716
  coff_symbol_type *cached_area;
4707
716
  unsigned int *table_ptr;
4708
716
  unsigned int number_of_symbols = 0;
4709
716
  bool ret = true;
4710
716
  size_t amt;
4711
4712
716
  if (obj_symbols (abfd))
4713
22
    return true;
4714
4715
  /* Read in the symbol table.  */
4716
694
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4717
55
    return false;
4718
4719
  /* Allocate enough room for all the symbols in cached form.  */
4720
639
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4721
639
       sizeof (*cached_area), &amt))
4722
0
    {
4723
0
      bfd_set_error (bfd_error_file_too_big);
4724
0
      return false;
4725
0
    }
4726
639
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4727
639
  if (cached_area == NULL)
4728
0
    return false;
4729
4730
639
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4731
639
       sizeof (*table_ptr), &amt))
4732
0
    {
4733
0
      bfd_set_error (bfd_error_file_too_big);
4734
0
      return false;
4735
0
    }
4736
639
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4737
639
  if (table_ptr == NULL)
4738
0
    return false;
4739
639
  else
4740
639
    {
4741
639
      coff_symbol_type *dst = cached_area;
4742
639
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4743
639
      unsigned int this_index = 0;
4744
4745
118k
      while (this_index < last_native_index)
4746
118k
  {
4747
118k
    combined_entry_type *src = native_symbols + this_index;
4748
118k
    table_ptr[this_index] = number_of_symbols;
4749
4750
118k
    dst->symbol.the_bfd = abfd;
4751
118k
    BFD_ASSERT (src->is_sym);
4752
118k
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4753
    /* We use the native name field to point to the cached field.  */
4754
118k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4755
118k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4756
118k
                 src->u.syment.n_scnum);
4757
118k
    dst->symbol.flags = 0;
4758
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4759
118k
    dst->symbol.value = 0;
4760
118k
    dst->done_lineno = false;
4761
4762
118k
    switch (src->u.syment.n_sclass)
4763
118k
      {
4764
2.21k
      case C_EXT:
4765
2.32k
      case C_WEAKEXT:
4766
2.32k
#if defined ARM
4767
2.37k
      case C_THUMBEXT:
4768
2.40k
      case C_THUMBEXTFUNC:
4769
2.40k
#endif
4770
#ifdef RS6000COFF_C
4771
      case C_HIDEXT:
4772
#ifndef AIX_WEAK_SUPPORT
4773
      case C_AIX_WEAKEXT:
4774
#endif
4775
#endif
4776
2.40k
#ifdef C_SYSTEM
4777
2.97k
      case C_SYSTEM: /* System Wide variable.  */
4778
2.97k
#endif
4779
2.97k
#ifdef COFF_WITH_PE
4780
      /* In PE, 0x68 (104) denotes a section symbol.  */
4781
3.03k
      case C_SECTION:
4782
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4783
4.70k
      case C_NT_WEAK:
4784
4.70k
#endif
4785
4.70k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4786
4.70k
    {
4787
4.13k
    case COFF_SYMBOL_GLOBAL:
4788
4.13k
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4789
4.13k
#if defined COFF_WITH_PE
4790
      /* PE sets the symbol to a value relative to the
4791
         start of the section.  */
4792
4.13k
      dst->symbol.value = src->u.syment.n_value;
4793
#else
4794
      dst->symbol.value = (src->u.syment.n_value
4795
               - dst->symbol.section->vma);
4796
#endif
4797
4.13k
      if (ISFCN ((src->u.syment.n_type)))
4798
        /* A function ext does not go at the end of a
4799
           file.  */
4800
146
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4801
4.13k
      break;
4802
4803
288
    case COFF_SYMBOL_COMMON:
4804
288
      dst->symbol.section = bfd_com_section_ptr;
4805
288
      dst->symbol.value = src->u.syment.n_value;
4806
288
      break;
4807
4808
287
    case COFF_SYMBOL_UNDEFINED:
4809
287
      dst->symbol.section = bfd_und_section_ptr;
4810
287
      dst->symbol.value = 0;
4811
287
      break;
4812
4813
0
    case COFF_SYMBOL_PE_SECTION:
4814
0
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4815
0
      dst->symbol.value = 0;
4816
0
      break;
4817
4818
0
    case COFF_SYMBOL_LOCAL:
4819
0
      dst->symbol.flags = BSF_LOCAL;
4820
0
#if defined COFF_WITH_PE
4821
      /* PE sets the symbol to a value relative to the
4822
         start of the section.  */
4823
0
      dst->symbol.value = src->u.syment.n_value;
4824
#else
4825
      dst->symbol.value = (src->u.syment.n_value
4826
               - dst->symbol.section->vma);
4827
#endif
4828
0
      if (ISFCN ((src->u.syment.n_type)))
4829
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4830
0
      break;
4831
4.70k
    }
4832
4833
#ifdef RS6000COFF_C
4834
        /* A symbol with a csect entry should not go at the end.  */
4835
        if (src->u.syment.n_numaux > 0)
4836
    dst->symbol.flags |= BSF_NOT_AT_END;
4837
#endif
4838
4839
4.70k
#ifdef COFF_WITH_PE
4840
4.70k
        if (src->u.syment.n_sclass == C_NT_WEAK)
4841
1.67k
    dst->symbol.flags |= BSF_WEAK;
4842
4843
4.70k
        if (src->u.syment.n_sclass == C_SECTION
4844
4.70k
      && src->u.syment.n_scnum > 0)
4845
0
    dst->symbol.flags = BSF_LOCAL;
4846
4.70k
#endif
4847
4.70k
        if (src->u.syment.n_sclass == C_WEAKEXT
4848
#ifdef RS6000COFF_C
4849
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4850
#endif
4851
4.70k
      )
4852
103
    dst->symbol.flags |= BSF_WEAK;
4853
4854
4.70k
        break;
4855
4856
2.62k
      case C_STAT:  /* Static.  */
4857
2.62k
#if defined ARM
4858
2.74k
      case C_THUMBSTAT:    /* Thumb static.  */
4859
2.79k
      case C_THUMBLABEL:   /* Thumb label.  */
4860
2.87k
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4861
2.87k
#endif
4862
#ifdef RS6000COFF_C
4863
      case C_DWARF:  /* A label in a dwarf section.  */
4864
      case C_INFO:   /* A label in a comment section.  */
4865
#endif
4866
3.29k
      case C_LABEL:  /* Label.  */
4867
3.29k
        if (src->u.syment.n_scnum == N_DEBUG)
4868
2
    dst->symbol.flags = BSF_DEBUGGING;
4869
3.29k
        else
4870
3.29k
    dst->symbol.flags = BSF_LOCAL;
4871
4872
        /* Base the value as an index from the base of the
4873
     section, if there is one.  */
4874
3.29k
        if (dst->symbol.section)
4875
3.29k
    {
4876
3.29k
#if defined COFF_WITH_PE
4877
      /* PE sets the symbol to a value relative to the
4878
         start of the section.  */
4879
3.29k
      dst->symbol.value = src->u.syment.n_value;
4880
#else
4881
      dst->symbol.value = (src->u.syment.n_value
4882
               - dst->symbol.section->vma);
4883
#endif
4884
3.29k
    }
4885
0
        else
4886
0
    dst->symbol.value = src->u.syment.n_value;
4887
3.29k
        break;
4888
4889
1.08k
      case C_FILE: /* File name.  */
4890
1.08k
        dst->symbol.flags = BSF_FILE;
4891
        /* Fall through.  */
4892
1.83k
      case C_MOS:   /* Member of structure.  */
4893
2.36k
      case C_EOS:   /* End of structure.  */
4894
2.52k
      case C_REGPARM: /* Register parameter.  */
4895
3.20k
      case C_REG:   /* register variable.  */
4896
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4897
3.56k
      case C_TPDEF: /* Type definition.  */
4898
4.63k
      case C_ARG:
4899
7.90k
      case C_AUTO: /* Automatic variable.  */
4900
8.08k
      case C_FIELD: /* Bit field.  */
4901
8.62k
      case C_ENTAG: /* Enumeration tag.  */
4902
9.14k
      case C_MOE:   /* Member of enumeration.  */
4903
10.2k
      case C_MOU:   /* Member of union.  */
4904
10.9k
      case C_UNTAG: /* Union tag.  */
4905
11.6k
      case C_STRTAG: /* Structure tag.  */
4906
#ifdef RS6000COFF_C
4907
      case C_GSYM:
4908
      case C_LSYM:
4909
      case C_PSYM:
4910
      case C_RSYM:
4911
      case C_RPSYM:
4912
      case C_STSYM:
4913
      case C_TCSYM:
4914
      case C_BCOMM:
4915
      case C_ECOML:
4916
      case C_ECOMM:
4917
      case C_DECL:
4918
      case C_ENTRY:
4919
      case C_FUN:
4920
      case C_ESTAT:
4921
#endif
4922
11.6k
        dst->symbol.flags |= BSF_DEBUGGING;
4923
11.6k
        dst->symbol.value = (src->u.syment.n_value);
4924
11.6k
        break;
4925
4926
#ifdef RS6000COFF_C
4927
      case C_BINCL: /* Beginning of include file.  */
4928
      case C_EINCL: /* Ending of include file.  */
4929
        /* The value is actually a pointer into the line numbers
4930
     of the file.  We locate the line number entry, and
4931
     set the section to the section which contains it, and
4932
     the value to the index in that section.  */
4933
        {
4934
    asection *sec;
4935
4936
    dst->symbol.flags = BSF_DEBUGGING;
4937
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4938
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4939
          && ((file_ptr) (sec->line_filepos
4940
              + sec->lineno_count * bfd_coff_linesz (abfd))
4941
        > (file_ptr) src->u.syment.n_value))
4942
        break;
4943
    if (sec == NULL)
4944
      dst->symbol.value = 0;
4945
    else
4946
      {
4947
        dst->symbol.section = sec;
4948
        dst->symbol.value = ((src->u.syment.n_value
4949
            - sec->line_filepos)
4950
           / bfd_coff_linesz (abfd));
4951
        src->fix_line = 1;
4952
      }
4953
        }
4954
        break;
4955
4956
      case C_BSTAT:
4957
        dst->symbol.flags = BSF_DEBUGGING;
4958
4959
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4960
    dst->symbol.value = 0;
4961
        else
4962
    {
4963
      /* The value is actually a symbol index.  Save a pointer
4964
         to the symbol instead of the index.  FIXME: This
4965
         should use a union.  */
4966
      src->u.syment.n_value
4967
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4968
      dst->symbol.value = src->u.syment.n_value;
4969
      src->fix_value = 1;
4970
    }
4971
        break;
4972
#endif
4973
4974
333
      case C_BLOCK: /* ".bb" or ".eb".  */
4975
3.08k
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4976
3.56k
      case C_EFCN: /* Physical end of function.  */
4977
3.56k
#if defined COFF_WITH_PE
4978
        /* PE sets the symbol to a value relative to the start
4979
     of the section.  */
4980
3.56k
        dst->symbol.value = src->u.syment.n_value;
4981
3.56k
        if (strcmp (dst->symbol.name, ".bf") != 0)
4982
3.55k
    {
4983
      /* PE uses funny values for .ef and .lf; don't
4984
         relocate them.  */
4985
3.55k
      dst->symbol.flags = BSF_DEBUGGING;
4986
3.55k
    }
4987
2
        else
4988
2
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4989
#else
4990
        /* Base the value as an index from the base of the
4991
     section.  */
4992
        dst->symbol.flags = BSF_LOCAL;
4993
        dst->symbol.value = (src->u.syment.n_value
4994
           - dst->symbol.section->vma);
4995
#endif
4996
3.56k
        break;
4997
4998
163
      case C_STATLAB: /* Static load time label.  */
4999
163
        dst->symbol.value = src->u.syment.n_value;
5000
163
        dst->symbol.flags = BSF_GLOBAL;
5001
163
        break;
5002
5003
66.9k
      case C_NULL:
5004
        /* PE DLLs sometimes have zeroed out symbols for some
5005
     reason.  Just ignore them without a warning.  */
5006
66.9k
        if (src->u.syment.n_type == 0
5007
66.9k
      && src->u.syment.n_value == 0
5008
66.9k
      && src->u.syment.n_scnum == 0)
5009
11.5k
    break;
5010
#ifdef RS6000COFF_C
5011
        /* XCOFF specific: deleted entry.  */
5012
        if (src->u.syment.n_value == C_NULL_VALUE)
5013
    break;
5014
#endif
5015
        /* Fall through.  */
5016
55.6k
      case C_EXTDEF: /* External definition.  */
5017
56.0k
      case C_ULABEL: /* Undefined label.  */
5018
56.1k
      case C_USTATIC: /* Undefined static.  */
5019
#ifndef COFF_WITH_PE
5020
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5021
         class to represent a section symbol.  */
5022
      case C_LINE:  /* line # reformatted as symbol table entry.  */
5023
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5024
      case C_ALIAS: /* Duplicate tag.  */
5025
#endif
5026
        /* New storage classes for TI COFF.  */
5027
#ifdef TICOFF
5028
      case C_UEXT:  /* Tentative external definition.  */
5029
#endif
5030
56.1k
      case C_EXTLAB: /* External load time label.  */
5031
83.1k
      default:
5032
83.1k
        _bfd_error_handler
5033
    /* xgettext:c-format */
5034
83.1k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5035
83.1k
     abfd, src->u.syment.n_sclass,
5036
83.1k
     dst->symbol.section->name, dst->symbol.name);
5037
83.1k
        ret = false;
5038
        /* Fall through.  */
5039
83.2k
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5040
        /* PR 20722: These symbols can also be generated by
5041
     building DLLs with --gc-sections enabled.  */
5042
83.2k
        dst->symbol.flags = BSF_DEBUGGING;
5043
83.2k
        dst->symbol.value = (src->u.syment.n_value);
5044
83.2k
        break;
5045
118k
      }
5046
5047
118k
    dst->native = src;
5048
118k
    dst->symbol.udata.i = 0;
5049
118k
    dst->lineno = NULL;
5050
5051
118k
    this_index += (src->u.syment.n_numaux) + 1;
5052
118k
    dst++;
5053
118k
    number_of_symbols++;
5054
118k
  }
5055
639
    }
5056
5057
639
  obj_symbols (abfd) = cached_area;
5058
639
  obj_raw_syments (abfd) = native_symbols;
5059
5060
639
  abfd->symcount = number_of_symbols;
5061
639
  obj_convert (abfd) = table_ptr;
5062
  /* Slurp the line tables for each section too.  */
5063
639
  {
5064
639
    asection *p;
5065
5066
639
    p = abfd->sections;
5067
919
    while (p)
5068
812
      {
5069
812
  if (! coff_slurp_line_table (abfd, p))
5070
532
    return false;
5071
280
  p = p->next;
5072
280
      }
5073
639
  }
5074
5075
107
  return ret;
5076
639
}
pei-arm.c:coff_slurp_symbol_table
Line
Count
Source
4704
1.02k
{
4705
1.02k
  combined_entry_type *native_symbols;
4706
1.02k
  coff_symbol_type *cached_area;
4707
1.02k
  unsigned int *table_ptr;
4708
1.02k
  unsigned int number_of_symbols = 0;
4709
1.02k
  bool ret = true;
4710
1.02k
  size_t amt;
4711
4712
1.02k
  if (obj_symbols (abfd))
4713
60
    return true;
4714
4715
  /* Read in the symbol table.  */
4716
968
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4717
107
    return false;
4718
4719
  /* Allocate enough room for all the symbols in cached form.  */
4720
861
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4721
861
       sizeof (*cached_area), &amt))
4722
0
    {
4723
0
      bfd_set_error (bfd_error_file_too_big);
4724
0
      return false;
4725
0
    }
4726
861
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4727
861
  if (cached_area == NULL)
4728
0
    return false;
4729
4730
861
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4731
861
       sizeof (*table_ptr), &amt))
4732
0
    {
4733
0
      bfd_set_error (bfd_error_file_too_big);
4734
0
      return false;
4735
0
    }
4736
861
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4737
861
  if (table_ptr == NULL)
4738
0
    return false;
4739
861
  else
4740
861
    {
4741
861
      coff_symbol_type *dst = cached_area;
4742
861
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4743
861
      unsigned int this_index = 0;
4744
4745
112k
      while (this_index < last_native_index)
4746
111k
  {
4747
111k
    combined_entry_type *src = native_symbols + this_index;
4748
111k
    table_ptr[this_index] = number_of_symbols;
4749
4750
111k
    dst->symbol.the_bfd = abfd;
4751
111k
    BFD_ASSERT (src->is_sym);
4752
111k
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4753
    /* We use the native name field to point to the cached field.  */
4754
111k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4755
111k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4756
111k
                 src->u.syment.n_scnum);
4757
111k
    dst->symbol.flags = 0;
4758
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4759
111k
    dst->symbol.value = 0;
4760
111k
    dst->done_lineno = false;
4761
4762
111k
    switch (src->u.syment.n_sclass)
4763
111k
      {
4764
2.36k
      case C_EXT:
4765
2.47k
      case C_WEAKEXT:
4766
2.47k
#if defined ARM
4767
2.53k
      case C_THUMBEXT:
4768
2.57k
      case C_THUMBEXTFUNC:
4769
2.57k
#endif
4770
#ifdef RS6000COFF_C
4771
      case C_HIDEXT:
4772
#ifndef AIX_WEAK_SUPPORT
4773
      case C_AIX_WEAKEXT:
4774
#endif
4775
#endif
4776
2.57k
#ifdef C_SYSTEM
4777
3.03k
      case C_SYSTEM: /* System Wide variable.  */
4778
3.03k
#endif
4779
3.03k
#ifdef COFF_WITH_PE
4780
      /* In PE, 0x68 (104) denotes a section symbol.  */
4781
3.13k
      case C_SECTION:
4782
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4783
4.78k
      case C_NT_WEAK:
4784
4.78k
#endif
4785
4.78k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4786
4.78k
    {
4787
4.26k
    case COFF_SYMBOL_GLOBAL:
4788
4.26k
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4789
4.26k
#if defined COFF_WITH_PE
4790
      /* PE sets the symbol to a value relative to the
4791
         start of the section.  */
4792
4.26k
      dst->symbol.value = src->u.syment.n_value;
4793
#else
4794
      dst->symbol.value = (src->u.syment.n_value
4795
               - dst->symbol.section->vma);
4796
#endif
4797
4.26k
      if (ISFCN ((src->u.syment.n_type)))
4798
        /* A function ext does not go at the end of a
4799
           file.  */
4800
87
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4801
4.26k
      break;
4802
4803
273
    case COFF_SYMBOL_COMMON:
4804
273
      dst->symbol.section = bfd_com_section_ptr;
4805
273
      dst->symbol.value = src->u.syment.n_value;
4806
273
      break;
4807
4808
240
    case COFF_SYMBOL_UNDEFINED:
4809
240
      dst->symbol.section = bfd_und_section_ptr;
4810
240
      dst->symbol.value = 0;
4811
240
      break;
4812
4813
0
    case COFF_SYMBOL_PE_SECTION:
4814
0
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4815
0
      dst->symbol.value = 0;
4816
0
      break;
4817
4818
0
    case COFF_SYMBOL_LOCAL:
4819
0
      dst->symbol.flags = BSF_LOCAL;
4820
0
#if defined COFF_WITH_PE
4821
      /* PE sets the symbol to a value relative to the
4822
         start of the section.  */
4823
0
      dst->symbol.value = src->u.syment.n_value;
4824
#else
4825
      dst->symbol.value = (src->u.syment.n_value
4826
               - dst->symbol.section->vma);
4827
#endif
4828
0
      if (ISFCN ((src->u.syment.n_type)))
4829
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4830
0
      break;
4831
4.78k
    }
4832
4833
#ifdef RS6000COFF_C
4834
        /* A symbol with a csect entry should not go at the end.  */
4835
        if (src->u.syment.n_numaux > 0)
4836
    dst->symbol.flags |= BSF_NOT_AT_END;
4837
#endif
4838
4839
4.78k
#ifdef COFF_WITH_PE
4840
4.78k
        if (src->u.syment.n_sclass == C_NT_WEAK)
4841
1.64k
    dst->symbol.flags |= BSF_WEAK;
4842
4843
4.78k
        if (src->u.syment.n_sclass == C_SECTION
4844
4.78k
      && src->u.syment.n_scnum > 0)
4845
0
    dst->symbol.flags = BSF_LOCAL;
4846
4.78k
#endif
4847
4.78k
        if (src->u.syment.n_sclass == C_WEAKEXT
4848
#ifdef RS6000COFF_C
4849
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4850
#endif
4851
4.78k
      )
4852
109
    dst->symbol.flags |= BSF_WEAK;
4853
4854
4.78k
        break;
4855
4856
1.94k
      case C_STAT:  /* Static.  */
4857
1.94k
#if defined ARM
4858
2.02k
      case C_THUMBSTAT:    /* Thumb static.  */
4859
2.05k
      case C_THUMBLABEL:   /* Thumb label.  */
4860
2.13k
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4861
2.13k
#endif
4862
#ifdef RS6000COFF_C
4863
      case C_DWARF:  /* A label in a dwarf section.  */
4864
      case C_INFO:   /* A label in a comment section.  */
4865
#endif
4866
2.73k
      case C_LABEL:  /* Label.  */
4867
2.73k
        if (src->u.syment.n_scnum == N_DEBUG)
4868
3
    dst->symbol.flags = BSF_DEBUGGING;
4869
2.73k
        else
4870
2.73k
    dst->symbol.flags = BSF_LOCAL;
4871
4872
        /* Base the value as an index from the base of the
4873
     section, if there is one.  */
4874
2.73k
        if (dst->symbol.section)
4875
2.73k
    {
4876
2.73k
#if defined COFF_WITH_PE
4877
      /* PE sets the symbol to a value relative to the
4878
         start of the section.  */
4879
2.73k
      dst->symbol.value = src->u.syment.n_value;
4880
#else
4881
      dst->symbol.value = (src->u.syment.n_value
4882
               - dst->symbol.section->vma);
4883
#endif
4884
2.73k
    }
4885
0
        else
4886
0
    dst->symbol.value = src->u.syment.n_value;
4887
2.73k
        break;
4888
4889
1.03k
      case C_FILE: /* File name.  */
4890
1.03k
        dst->symbol.flags = BSF_FILE;
4891
        /* Fall through.  */
4892
1.90k
      case C_MOS:   /* Member of structure.  */
4893
2.35k
      case C_EOS:   /* End of structure.  */
4894
2.55k
      case C_REGPARM: /* Register parameter.  */
4895
3.04k
      case C_REG:   /* register variable.  */
4896
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4897
3.25k
      case C_TPDEF: /* Type definition.  */
4898
4.12k
      case C_ARG:
4899
7.10k
      case C_AUTO: /* Automatic variable.  */
4900
7.42k
      case C_FIELD: /* Bit field.  */
4901
7.86k
      case C_ENTAG: /* Enumeration tag.  */
4902
8.41k
      case C_MOE:   /* Member of enumeration.  */
4903
9.34k
      case C_MOU:   /* Member of union.  */
4904
9.96k
      case C_UNTAG: /* Union tag.  */
4905
10.6k
      case C_STRTAG: /* Structure tag.  */
4906
#ifdef RS6000COFF_C
4907
      case C_GSYM:
4908
      case C_LSYM:
4909
      case C_PSYM:
4910
      case C_RSYM:
4911
      case C_RPSYM:
4912
      case C_STSYM:
4913
      case C_TCSYM:
4914
      case C_BCOMM:
4915
      case C_ECOML:
4916
      case C_ECOMM:
4917
      case C_DECL:
4918
      case C_ENTRY:
4919
      case C_FUN:
4920
      case C_ESTAT:
4921
#endif
4922
10.6k
        dst->symbol.flags |= BSF_DEBUGGING;
4923
10.6k
        dst->symbol.value = (src->u.syment.n_value);
4924
10.6k
        break;
4925
4926
#ifdef RS6000COFF_C
4927
      case C_BINCL: /* Beginning of include file.  */
4928
      case C_EINCL: /* Ending of include file.  */
4929
        /* The value is actually a pointer into the line numbers
4930
     of the file.  We locate the line number entry, and
4931
     set the section to the section which contains it, and
4932
     the value to the index in that section.  */
4933
        {
4934
    asection *sec;
4935
4936
    dst->symbol.flags = BSF_DEBUGGING;
4937
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4938
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4939
          && ((file_ptr) (sec->line_filepos
4940
              + sec->lineno_count * bfd_coff_linesz (abfd))
4941
        > (file_ptr) src->u.syment.n_value))
4942
        break;
4943
    if (sec == NULL)
4944
      dst->symbol.value = 0;
4945
    else
4946
      {
4947
        dst->symbol.section = sec;
4948
        dst->symbol.value = ((src->u.syment.n_value
4949
            - sec->line_filepos)
4950
           / bfd_coff_linesz (abfd));
4951
        src->fix_line = 1;
4952
      }
4953
        }
4954
        break;
4955
4956
      case C_BSTAT:
4957
        dst->symbol.flags = BSF_DEBUGGING;
4958
4959
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4960
    dst->symbol.value = 0;
4961
        else
4962
    {
4963
      /* The value is actually a symbol index.  Save a pointer
4964
         to the symbol instead of the index.  FIXME: This
4965
         should use a union.  */
4966
      src->u.syment.n_value
4967
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4968
      dst->symbol.value = src->u.syment.n_value;
4969
      src->fix_value = 1;
4970
    }
4971
        break;
4972
#endif
4973
4974
345
      case C_BLOCK: /* ".bb" or ".eb".  */
4975
2.92k
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4976
3.30k
      case C_EFCN: /* Physical end of function.  */
4977
3.30k
#if defined COFF_WITH_PE
4978
        /* PE sets the symbol to a value relative to the start
4979
     of the section.  */
4980
3.30k
        dst->symbol.value = src->u.syment.n_value;
4981
3.30k
        if (strcmp (dst->symbol.name, ".bf") != 0)
4982
3.29k
    {
4983
      /* PE uses funny values for .ef and .lf; don't
4984
         relocate them.  */
4985
3.29k
      dst->symbol.flags = BSF_DEBUGGING;
4986
3.29k
    }
4987
3
        else
4988
3
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4989
#else
4990
        /* Base the value as an index from the base of the
4991
     section.  */
4992
        dst->symbol.flags = BSF_LOCAL;
4993
        dst->symbol.value = (src->u.syment.n_value
4994
           - dst->symbol.section->vma);
4995
#endif
4996
3.30k
        break;
4997
4998
147
      case C_STATLAB: /* Static load time label.  */
4999
147
        dst->symbol.value = src->u.syment.n_value;
5000
147
        dst->symbol.flags = BSF_GLOBAL;
5001
147
        break;
5002
5003
64.6k
      case C_NULL:
5004
        /* PE DLLs sometimes have zeroed out symbols for some
5005
     reason.  Just ignore them without a warning.  */
5006
64.6k
        if (src->u.syment.n_type == 0
5007
64.6k
      && src->u.syment.n_value == 0
5008
64.6k
      && src->u.syment.n_scnum == 0)
5009
10.7k
    break;
5010
#ifdef RS6000COFF_C
5011
        /* XCOFF specific: deleted entry.  */
5012
        if (src->u.syment.n_value == C_NULL_VALUE)
5013
    break;
5014
#endif
5015
        /* Fall through.  */
5016
54.0k
      case C_EXTDEF: /* External definition.  */
5017
54.3k
      case C_ULABEL: /* Undefined label.  */
5018
54.4k
      case C_USTATIC: /* Undefined static.  */
5019
#ifndef COFF_WITH_PE
5020
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5021
         class to represent a section symbol.  */
5022
      case C_LINE:  /* line # reformatted as symbol table entry.  */
5023
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5024
      case C_ALIAS: /* Duplicate tag.  */
5025
#endif
5026
        /* New storage classes for TI COFF.  */
5027
#ifdef TICOFF
5028
      case C_UEXT:  /* Tentative external definition.  */
5029
#endif
5030
54.5k
      case C_EXTLAB: /* External load time label.  */
5031
79.2k
      default:
5032
79.2k
        _bfd_error_handler
5033
    /* xgettext:c-format */
5034
79.2k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5035
79.2k
     abfd, src->u.syment.n_sclass,
5036
79.2k
     dst->symbol.section->name, dst->symbol.name);
5037
79.2k
        ret = false;
5038
        /* Fall through.  */
5039
79.3k
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5040
        /* PR 20722: These symbols can also be generated by
5041
     building DLLs with --gc-sections enabled.  */
5042
79.3k
        dst->symbol.flags = BSF_DEBUGGING;
5043
79.3k
        dst->symbol.value = (src->u.syment.n_value);
5044
79.3k
        break;
5045
111k
      }
5046
5047
111k
    dst->native = src;
5048
111k
    dst->symbol.udata.i = 0;
5049
111k
    dst->lineno = NULL;
5050
5051
111k
    this_index += (src->u.syment.n_numaux) + 1;
5052
111k
    dst++;
5053
111k
    number_of_symbols++;
5054
111k
  }
5055
861
    }
5056
5057
861
  obj_symbols (abfd) = cached_area;
5058
861
  obj_raw_syments (abfd) = native_symbols;
5059
5060
861
  abfd->symcount = number_of_symbols;
5061
861
  obj_convert (abfd) = table_ptr;
5062
  /* Slurp the line tables for each section too.  */
5063
861
  {
5064
861
    asection *p;
5065
5066
861
    p = abfd->sections;
5067
2.22k
    while (p)
5068
2.14k
      {
5069
2.14k
  if (! coff_slurp_line_table (abfd, p))
5070
779
    return false;
5071
1.36k
  p = p->next;
5072
1.36k
      }
5073
861
  }
5074
5075
82
  return ret;
5076
861
}
pei-mcore.c:coff_slurp_symbol_table
Line
Count
Source
4704
868
{
4705
868
  combined_entry_type *native_symbols;
4706
868
  coff_symbol_type *cached_area;
4707
868
  unsigned int *table_ptr;
4708
868
  unsigned int number_of_symbols = 0;
4709
868
  bool ret = true;
4710
868
  size_t amt;
4711
4712
868
  if (obj_symbols (abfd))
4713
24
    return true;
4714
4715
  /* Read in the symbol table.  */
4716
844
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4717
140
    return false;
4718
4719
  /* Allocate enough room for all the symbols in cached form.  */
4720
704
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4721
704
       sizeof (*cached_area), &amt))
4722
0
    {
4723
0
      bfd_set_error (bfd_error_file_too_big);
4724
0
      return false;
4725
0
    }
4726
704
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4727
704
  if (cached_area == NULL)
4728
0
    return false;
4729
4730
704
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4731
704
       sizeof (*table_ptr), &amt))
4732
0
    {
4733
0
      bfd_set_error (bfd_error_file_too_big);
4734
0
      return false;
4735
0
    }
4736
704
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4737
704
  if (table_ptr == NULL)
4738
0
    return false;
4739
704
  else
4740
704
    {
4741
704
      coff_symbol_type *dst = cached_area;
4742
704
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4743
704
      unsigned int this_index = 0;
4744
4745
121k
      while (this_index < last_native_index)
4746
120k
  {
4747
120k
    combined_entry_type *src = native_symbols + this_index;
4748
120k
    table_ptr[this_index] = number_of_symbols;
4749
4750
120k
    dst->symbol.the_bfd = abfd;
4751
120k
    BFD_ASSERT (src->is_sym);
4752
120k
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4753
    /* We use the native name field to point to the cached field.  */
4754
120k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4755
120k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4756
120k
                 src->u.syment.n_scnum);
4757
120k
    dst->symbol.flags = 0;
4758
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4759
120k
    dst->symbol.value = 0;
4760
120k
    dst->done_lineno = false;
4761
4762
120k
    switch (src->u.syment.n_sclass)
4763
120k
      {
4764
1.86k
      case C_EXT:
4765
2.22k
      case C_WEAKEXT:
4766
#if defined ARM
4767
      case C_THUMBEXT:
4768
      case C_THUMBEXTFUNC:
4769
#endif
4770
#ifdef RS6000COFF_C
4771
      case C_HIDEXT:
4772
#ifndef AIX_WEAK_SUPPORT
4773
      case C_AIX_WEAKEXT:
4774
#endif
4775
#endif
4776
2.22k
#ifdef C_SYSTEM
4777
2.53k
      case C_SYSTEM: /* System Wide variable.  */
4778
2.53k
#endif
4779
2.53k
#ifdef COFF_WITH_PE
4780
      /* In PE, 0x68 (104) denotes a section symbol.  */
4781
2.60k
      case C_SECTION:
4782
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4783
4.65k
      case C_NT_WEAK:
4784
4.65k
#endif
4785
4.65k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4786
4.65k
    {
4787
4.08k
    case COFF_SYMBOL_GLOBAL:
4788
4.08k
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4789
4.08k
#if defined COFF_WITH_PE
4790
      /* PE sets the symbol to a value relative to the
4791
         start of the section.  */
4792
4.08k
      dst->symbol.value = src->u.syment.n_value;
4793
#else
4794
      dst->symbol.value = (src->u.syment.n_value
4795
               - dst->symbol.section->vma);
4796
#endif
4797
4.08k
      if (ISFCN ((src->u.syment.n_type)))
4798
        /* A function ext does not go at the end of a
4799
           file.  */
4800
136
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4801
4.08k
      break;
4802
4803
387
    case COFF_SYMBOL_COMMON:
4804
387
      dst->symbol.section = bfd_com_section_ptr;
4805
387
      dst->symbol.value = src->u.syment.n_value;
4806
387
      break;
4807
4808
181
    case COFF_SYMBOL_UNDEFINED:
4809
181
      dst->symbol.section = bfd_und_section_ptr;
4810
181
      dst->symbol.value = 0;
4811
181
      break;
4812
4813
0
    case COFF_SYMBOL_PE_SECTION:
4814
0
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4815
0
      dst->symbol.value = 0;
4816
0
      break;
4817
4818
0
    case COFF_SYMBOL_LOCAL:
4819
0
      dst->symbol.flags = BSF_LOCAL;
4820
0
#if defined COFF_WITH_PE
4821
      /* PE sets the symbol to a value relative to the
4822
         start of the section.  */
4823
0
      dst->symbol.value = src->u.syment.n_value;
4824
#else
4825
      dst->symbol.value = (src->u.syment.n_value
4826
               - dst->symbol.section->vma);
4827
#endif
4828
0
      if (ISFCN ((src->u.syment.n_type)))
4829
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4830
0
      break;
4831
4.65k
    }
4832
4833
#ifdef RS6000COFF_C
4834
        /* A symbol with a csect entry should not go at the end.  */
4835
        if (src->u.syment.n_numaux > 0)
4836
    dst->symbol.flags |= BSF_NOT_AT_END;
4837
#endif
4838
4839
4.65k
#ifdef COFF_WITH_PE
4840
4.65k
        if (src->u.syment.n_sclass == C_NT_WEAK)
4841
2.04k
    dst->symbol.flags |= BSF_WEAK;
4842
4843
4.65k
        if (src->u.syment.n_sclass == C_SECTION
4844
4.65k
      && src->u.syment.n_scnum > 0)
4845
0
    dst->symbol.flags = BSF_LOCAL;
4846
4.65k
#endif
4847
4.65k
        if (src->u.syment.n_sclass == C_WEAKEXT
4848
#ifdef RS6000COFF_C
4849
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4850
#endif
4851
4.65k
      )
4852
363
    dst->symbol.flags |= BSF_WEAK;
4853
4854
4.65k
        break;
4855
4856
2.67k
      case C_STAT:  /* Static.  */
4857
#if defined ARM
4858
      case C_THUMBSTAT:    /* Thumb static.  */
4859
      case C_THUMBLABEL:   /* Thumb label.  */
4860
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4861
#endif
4862
#ifdef RS6000COFF_C
4863
      case C_DWARF:  /* A label in a dwarf section.  */
4864
      case C_INFO:   /* A label in a comment section.  */
4865
#endif
4866
4.74k
      case C_LABEL:  /* Label.  */
4867
4.74k
        if (src->u.syment.n_scnum == N_DEBUG)
4868
2
    dst->symbol.flags = BSF_DEBUGGING;
4869
4.74k
        else
4870
4.74k
    dst->symbol.flags = BSF_LOCAL;
4871
4872
        /* Base the value as an index from the base of the
4873
     section, if there is one.  */
4874
4.74k
        if (dst->symbol.section)
4875
4.74k
    {
4876
4.74k
#if defined COFF_WITH_PE
4877
      /* PE sets the symbol to a value relative to the
4878
         start of the section.  */
4879
4.74k
      dst->symbol.value = src->u.syment.n_value;
4880
#else
4881
      dst->symbol.value = (src->u.syment.n_value
4882
               - dst->symbol.section->vma);
4883
#endif
4884
4.74k
    }
4885
0
        else
4886
0
    dst->symbol.value = src->u.syment.n_value;
4887
4.74k
        break;
4888
4889
1.03k
      case C_FILE: /* File name.  */
4890
1.03k
        dst->symbol.flags = BSF_FILE;
4891
        /* Fall through.  */
4892
1.99k
      case C_MOS:   /* Member of structure.  */
4893
2.45k
      case C_EOS:   /* End of structure.  */
4894
2.86k
      case C_REGPARM: /* Register parameter.  */
4895
3.29k
      case C_REG:   /* register variable.  */
4896
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4897
3.76k
      case C_TPDEF: /* Type definition.  */
4898
4.31k
      case C_ARG:
4899
8.01k
      case C_AUTO: /* Automatic variable.  */
4900
8.39k
      case C_FIELD: /* Bit field.  */
4901
8.65k
      case C_ENTAG: /* Enumeration tag.  */
4902
9.35k
      case C_MOE:   /* Member of enumeration.  */
4903
9.75k
      case C_MOU:   /* Member of union.  */
4904
10.4k
      case C_UNTAG: /* Union tag.  */
4905
11.0k
      case C_STRTAG: /* Structure tag.  */
4906
#ifdef RS6000COFF_C
4907
      case C_GSYM:
4908
      case C_LSYM:
4909
      case C_PSYM:
4910
      case C_RSYM:
4911
      case C_RPSYM:
4912
      case C_STSYM:
4913
      case C_TCSYM:
4914
      case C_BCOMM:
4915
      case C_ECOML:
4916
      case C_ECOMM:
4917
      case C_DECL:
4918
      case C_ENTRY:
4919
      case C_FUN:
4920
      case C_ESTAT:
4921
#endif
4922
11.0k
        dst->symbol.flags |= BSF_DEBUGGING;
4923
11.0k
        dst->symbol.value = (src->u.syment.n_value);
4924
11.0k
        break;
4925
4926
#ifdef RS6000COFF_C
4927
      case C_BINCL: /* Beginning of include file.  */
4928
      case C_EINCL: /* Ending of include file.  */
4929
        /* The value is actually a pointer into the line numbers
4930
     of the file.  We locate the line number entry, and
4931
     set the section to the section which contains it, and
4932
     the value to the index in that section.  */
4933
        {
4934
    asection *sec;
4935
4936
    dst->symbol.flags = BSF_DEBUGGING;
4937
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4938
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4939
          && ((file_ptr) (sec->line_filepos
4940
              + sec->lineno_count * bfd_coff_linesz (abfd))
4941
        > (file_ptr) src->u.syment.n_value))
4942
        break;
4943
    if (sec == NULL)
4944
      dst->symbol.value = 0;
4945
    else
4946
      {
4947
        dst->symbol.section = sec;
4948
        dst->symbol.value = ((src->u.syment.n_value
4949
            - sec->line_filepos)
4950
           / bfd_coff_linesz (abfd));
4951
        src->fix_line = 1;
4952
      }
4953
        }
4954
        break;
4955
4956
      case C_BSTAT:
4957
        dst->symbol.flags = BSF_DEBUGGING;
4958
4959
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4960
    dst->symbol.value = 0;
4961
        else
4962
    {
4963
      /* The value is actually a symbol index.  Save a pointer
4964
         to the symbol instead of the index.  FIXME: This
4965
         should use a union.  */
4966
      src->u.syment.n_value
4967
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4968
      dst->symbol.value = src->u.syment.n_value;
4969
      src->fix_value = 1;
4970
    }
4971
        break;
4972
#endif
4973
4974
269
      case C_BLOCK: /* ".bb" or ".eb".  */
4975
2.72k
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4976
3.20k
      case C_EFCN: /* Physical end of function.  */
4977
3.20k
#if defined COFF_WITH_PE
4978
        /* PE sets the symbol to a value relative to the start
4979
     of the section.  */
4980
3.20k
        dst->symbol.value = src->u.syment.n_value;
4981
3.20k
        if (strcmp (dst->symbol.name, ".bf") != 0)
4982
3.20k
    {
4983
      /* PE uses funny values for .ef and .lf; don't
4984
         relocate them.  */
4985
3.20k
      dst->symbol.flags = BSF_DEBUGGING;
4986
3.20k
    }
4987
1
        else
4988
1
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4989
#else
4990
        /* Base the value as an index from the base of the
4991
     section.  */
4992
        dst->symbol.flags = BSF_LOCAL;
4993
        dst->symbol.value = (src->u.syment.n_value
4994
           - dst->symbol.section->vma);
4995
#endif
4996
3.20k
        break;
4997
4998
252
      case C_STATLAB: /* Static load time label.  */
4999
252
        dst->symbol.value = src->u.syment.n_value;
5000
252
        dst->symbol.flags = BSF_GLOBAL;
5001
252
        break;
5002
5003
70.0k
      case C_NULL:
5004
        /* PE DLLs sometimes have zeroed out symbols for some
5005
     reason.  Just ignore them without a warning.  */
5006
70.0k
        if (src->u.syment.n_type == 0
5007
70.0k
      && src->u.syment.n_value == 0
5008
70.0k
      && src->u.syment.n_scnum == 0)
5009
15.5k
    break;
5010
#ifdef RS6000COFF_C
5011
        /* XCOFF specific: deleted entry.  */
5012
        if (src->u.syment.n_value == C_NULL_VALUE)
5013
    break;
5014
#endif
5015
        /* Fall through.  */
5016
54.6k
      case C_EXTDEF: /* External definition.  */
5017
54.8k
      case C_ULABEL: /* Undefined label.  */
5018
54.9k
      case C_USTATIC: /* Undefined static.  */
5019
#ifndef COFF_WITH_PE
5020
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5021
         class to represent a section symbol.  */
5022
      case C_LINE:  /* line # reformatted as symbol table entry.  */
5023
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5024
      case C_ALIAS: /* Duplicate tag.  */
5025
#endif
5026
        /* New storage classes for TI COFF.  */
5027
#ifdef TICOFF
5028
      case C_UEXT:  /* Tentative external definition.  */
5029
#endif
5030
55.0k
      case C_EXTLAB: /* External load time label.  */
5031
81.1k
      default:
5032
81.1k
        _bfd_error_handler
5033
    /* xgettext:c-format */
5034
81.1k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5035
81.1k
     abfd, src->u.syment.n_sclass,
5036
81.1k
     dst->symbol.section->name, dst->symbol.name);
5037
81.1k
        ret = false;
5038
        /* Fall through.  */
5039
81.2k
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5040
        /* PR 20722: These symbols can also be generated by
5041
     building DLLs with --gc-sections enabled.  */
5042
81.2k
        dst->symbol.flags = BSF_DEBUGGING;
5043
81.2k
        dst->symbol.value = (src->u.syment.n_value);
5044
81.2k
        break;
5045
120k
      }
5046
5047
120k
    dst->native = src;
5048
120k
    dst->symbol.udata.i = 0;
5049
120k
    dst->lineno = NULL;
5050
5051
120k
    this_index += (src->u.syment.n_numaux) + 1;
5052
120k
    dst++;
5053
120k
    number_of_symbols++;
5054
120k
  }
5055
704
    }
5056
5057
704
  obj_symbols (abfd) = cached_area;
5058
704
  obj_raw_syments (abfd) = native_symbols;
5059
5060
704
  abfd->symcount = number_of_symbols;
5061
704
  obj_convert (abfd) = table_ptr;
5062
  /* Slurp the line tables for each section too.  */
5063
704
  {
5064
704
    asection *p;
5065
5066
704
    p = abfd->sections;
5067
1.11k
    while (p)
5068
1.00k
      {
5069
1.00k
  if (! coff_slurp_line_table (abfd, p))
5070
587
    return false;
5071
413
  p = p->next;
5072
413
      }
5073
704
  }
5074
5075
117
  return ret;
5076
704
}
pei-sh.c:coff_slurp_symbol_table
Line
Count
Source
4704
1.18k
{
4705
1.18k
  combined_entry_type *native_symbols;
4706
1.18k
  coff_symbol_type *cached_area;
4707
1.18k
  unsigned int *table_ptr;
4708
1.18k
  unsigned int number_of_symbols = 0;
4709
1.18k
  bool ret = true;
4710
1.18k
  size_t amt;
4711
4712
1.18k
  if (obj_symbols (abfd))
4713
240
    return true;
4714
4715
  /* Read in the symbol table.  */
4716
945
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4717
162
    return false;
4718
4719
  /* Allocate enough room for all the symbols in cached form.  */
4720
783
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4721
783
       sizeof (*cached_area), &amt))
4722
0
    {
4723
0
      bfd_set_error (bfd_error_file_too_big);
4724
0
      return false;
4725
0
    }
4726
783
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4727
783
  if (cached_area == NULL)
4728
0
    return false;
4729
4730
783
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4731
783
       sizeof (*table_ptr), &amt))
4732
0
    {
4733
0
      bfd_set_error (bfd_error_file_too_big);
4734
0
      return false;
4735
0
    }
4736
783
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4737
783
  if (table_ptr == NULL)
4738
0
    return false;
4739
783
  else
4740
783
    {
4741
783
      coff_symbol_type *dst = cached_area;
4742
783
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4743
783
      unsigned int this_index = 0;
4744
4745
346k
      while (this_index < last_native_index)
4746
345k
  {
4747
345k
    combined_entry_type *src = native_symbols + this_index;
4748
345k
    table_ptr[this_index] = number_of_symbols;
4749
4750
345k
    dst->symbol.the_bfd = abfd;
4751
345k
    BFD_ASSERT (src->is_sym);
4752
345k
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4753
    /* We use the native name field to point to the cached field.  */
4754
345k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4755
345k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4756
345k
                 src->u.syment.n_scnum);
4757
345k
    dst->symbol.flags = 0;
4758
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4759
345k
    dst->symbol.value = 0;
4760
345k
    dst->done_lineno = false;
4761
4762
345k
    switch (src->u.syment.n_sclass)
4763
345k
      {
4764
5.05k
      case C_EXT:
4765
5.45k
      case C_WEAKEXT:
4766
#if defined ARM
4767
      case C_THUMBEXT:
4768
      case C_THUMBEXTFUNC:
4769
#endif
4770
#ifdef RS6000COFF_C
4771
      case C_HIDEXT:
4772
#ifndef AIX_WEAK_SUPPORT
4773
      case C_AIX_WEAKEXT:
4774
#endif
4775
#endif
4776
5.45k
#ifdef C_SYSTEM
4777
6.39k
      case C_SYSTEM: /* System Wide variable.  */
4778
6.39k
#endif
4779
6.39k
#ifdef COFF_WITH_PE
4780
      /* In PE, 0x68 (104) denotes a section symbol.  */
4781
6.48k
      case C_SECTION:
4782
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4783
9.48k
      case C_NT_WEAK:
4784
9.48k
#endif
4785
9.48k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4786
9.48k
    {
4787
8.42k
    case COFF_SYMBOL_GLOBAL:
4788
8.42k
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4789
8.42k
#if defined COFF_WITH_PE
4790
      /* PE sets the symbol to a value relative to the
4791
         start of the section.  */
4792
8.42k
      dst->symbol.value = src->u.syment.n_value;
4793
#else
4794
      dst->symbol.value = (src->u.syment.n_value
4795
               - dst->symbol.section->vma);
4796
#endif
4797
8.42k
      if (ISFCN ((src->u.syment.n_type)))
4798
        /* A function ext does not go at the end of a
4799
           file.  */
4800
448
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4801
8.42k
      break;
4802
4803
682
    case COFF_SYMBOL_COMMON:
4804
682
      dst->symbol.section = bfd_com_section_ptr;
4805
682
      dst->symbol.value = src->u.syment.n_value;
4806
682
      break;
4807
4808
381
    case COFF_SYMBOL_UNDEFINED:
4809
381
      dst->symbol.section = bfd_und_section_ptr;
4810
381
      dst->symbol.value = 0;
4811
381
      break;
4812
4813
0
    case COFF_SYMBOL_PE_SECTION:
4814
0
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4815
0
      dst->symbol.value = 0;
4816
0
      break;
4817
4818
0
    case COFF_SYMBOL_LOCAL:
4819
0
      dst->symbol.flags = BSF_LOCAL;
4820
0
#if defined COFF_WITH_PE
4821
      /* PE sets the symbol to a value relative to the
4822
         start of the section.  */
4823
0
      dst->symbol.value = src->u.syment.n_value;
4824
#else
4825
      dst->symbol.value = (src->u.syment.n_value
4826
               - dst->symbol.section->vma);
4827
#endif
4828
0
      if (ISFCN ((src->u.syment.n_type)))
4829
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4830
0
      break;
4831
9.48k
    }
4832
4833
#ifdef RS6000COFF_C
4834
        /* A symbol with a csect entry should not go at the end.  */
4835
        if (src->u.syment.n_numaux > 0)
4836
    dst->symbol.flags |= BSF_NOT_AT_END;
4837
#endif
4838
4839
9.48k
#ifdef COFF_WITH_PE
4840
9.48k
        if (src->u.syment.n_sclass == C_NT_WEAK)
4841
3.00k
    dst->symbol.flags |= BSF_WEAK;
4842
4843
9.48k
        if (src->u.syment.n_sclass == C_SECTION
4844
9.48k
      && src->u.syment.n_scnum > 0)
4845
0
    dst->symbol.flags = BSF_LOCAL;
4846
9.48k
#endif
4847
9.48k
        if (src->u.syment.n_sclass == C_WEAKEXT
4848
#ifdef RS6000COFF_C
4849
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4850
#endif
4851
9.48k
      )
4852
393
    dst->symbol.flags |= BSF_WEAK;
4853
4854
9.48k
        break;
4855
4856
3.76k
      case C_STAT:  /* Static.  */
4857
#if defined ARM
4858
      case C_THUMBSTAT:    /* Thumb static.  */
4859
      case C_THUMBLABEL:   /* Thumb label.  */
4860
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4861
#endif
4862
#ifdef RS6000COFF_C
4863
      case C_DWARF:  /* A label in a dwarf section.  */
4864
      case C_INFO:   /* A label in a comment section.  */
4865
#endif
4866
4.67k
      case C_LABEL:  /* Label.  */
4867
4.67k
        if (src->u.syment.n_scnum == N_DEBUG)
4868
0
    dst->symbol.flags = BSF_DEBUGGING;
4869
4.67k
        else
4870
4.67k
    dst->symbol.flags = BSF_LOCAL;
4871
4872
        /* Base the value as an index from the base of the
4873
     section, if there is one.  */
4874
4.67k
        if (dst->symbol.section)
4875
4.67k
    {
4876
4.67k
#if defined COFF_WITH_PE
4877
      /* PE sets the symbol to a value relative to the
4878
         start of the section.  */
4879
4.67k
      dst->symbol.value = src->u.syment.n_value;
4880
#else
4881
      dst->symbol.value = (src->u.syment.n_value
4882
               - dst->symbol.section->vma);
4883
#endif
4884
4.67k
    }
4885
0
        else
4886
0
    dst->symbol.value = src->u.syment.n_value;
4887
4.67k
        break;
4888
4889
2.40k
      case C_FILE: /* File name.  */
4890
2.40k
        dst->symbol.flags = BSF_FILE;
4891
        /* Fall through.  */
4892
5.53k
      case C_MOS:   /* Member of structure.  */
4893
6.28k
      case C_EOS:   /* End of structure.  */
4894
8.66k
      case C_REGPARM: /* Register parameter.  */
4895
10.1k
      case C_REG:   /* register variable.  */
4896
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4897
10.8k
      case C_TPDEF: /* Type definition.  */
4898
12.7k
      case C_ARG:
4899
20.5k
      case C_AUTO: /* Automatic variable.  */
4900
22.2k
      case C_FIELD: /* Bit field.  */
4901
22.8k
      case C_ENTAG: /* Enumeration tag.  */
4902
26.1k
      case C_MOE:   /* Member of enumeration.  */
4903
27.8k
      case C_MOU:   /* Member of union.  */
4904
28.7k
      case C_UNTAG: /* Union tag.  */
4905
30.4k
      case C_STRTAG: /* Structure tag.  */
4906
#ifdef RS6000COFF_C
4907
      case C_GSYM:
4908
      case C_LSYM:
4909
      case C_PSYM:
4910
      case C_RSYM:
4911
      case C_RPSYM:
4912
      case C_STSYM:
4913
      case C_TCSYM:
4914
      case C_BCOMM:
4915
      case C_ECOML:
4916
      case C_ECOMM:
4917
      case C_DECL:
4918
      case C_ENTRY:
4919
      case C_FUN:
4920
      case C_ESTAT:
4921
#endif
4922
30.4k
        dst->symbol.flags |= BSF_DEBUGGING;
4923
30.4k
        dst->symbol.value = (src->u.syment.n_value);
4924
30.4k
        break;
4925
4926
#ifdef RS6000COFF_C
4927
      case C_BINCL: /* Beginning of include file.  */
4928
      case C_EINCL: /* Ending of include file.  */
4929
        /* The value is actually a pointer into the line numbers
4930
     of the file.  We locate the line number entry, and
4931
     set the section to the section which contains it, and
4932
     the value to the index in that section.  */
4933
        {
4934
    asection *sec;
4935
4936
    dst->symbol.flags = BSF_DEBUGGING;
4937
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4938
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4939
          && ((file_ptr) (sec->line_filepos
4940
              + sec->lineno_count * bfd_coff_linesz (abfd))
4941
        > (file_ptr) src->u.syment.n_value))
4942
        break;
4943
    if (sec == NULL)
4944
      dst->symbol.value = 0;
4945
    else
4946
      {
4947
        dst->symbol.section = sec;
4948
        dst->symbol.value = ((src->u.syment.n_value
4949
            - sec->line_filepos)
4950
           / bfd_coff_linesz (abfd));
4951
        src->fix_line = 1;
4952
      }
4953
        }
4954
        break;
4955
4956
      case C_BSTAT:
4957
        dst->symbol.flags = BSF_DEBUGGING;
4958
4959
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4960
    dst->symbol.value = 0;
4961
        else
4962
    {
4963
      /* The value is actually a symbol index.  Save a pointer
4964
         to the symbol instead of the index.  FIXME: This
4965
         should use a union.  */
4966
      src->u.syment.n_value
4967
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4968
      dst->symbol.value = src->u.syment.n_value;
4969
      src->fix_value = 1;
4970
    }
4971
        break;
4972
#endif
4973
4974
782
      case C_BLOCK: /* ".bb" or ".eb".  */
4975
4.33k
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4976
5.81k
      case C_EFCN: /* Physical end of function.  */
4977
5.81k
#if defined COFF_WITH_PE
4978
        /* PE sets the symbol to a value relative to the start
4979
     of the section.  */
4980
5.81k
        dst->symbol.value = src->u.syment.n_value;
4981
5.81k
        if (strcmp (dst->symbol.name, ".bf") != 0)
4982
5.81k
    {
4983
      /* PE uses funny values for .ef and .lf; don't
4984
         relocate them.  */
4985
5.81k
      dst->symbol.flags = BSF_DEBUGGING;
4986
5.81k
    }
4987
3
        else
4988
3
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4989
#else
4990
        /* Base the value as an index from the base of the
4991
     section.  */
4992
        dst->symbol.flags = BSF_LOCAL;
4993
        dst->symbol.value = (src->u.syment.n_value
4994
           - dst->symbol.section->vma);
4995
#endif
4996
5.81k
        break;
4997
4998
461
      case C_STATLAB: /* Static load time label.  */
4999
461
        dst->symbol.value = src->u.syment.n_value;
5000
461
        dst->symbol.flags = BSF_GLOBAL;
5001
461
        break;
5002
5003
246k
      case C_NULL:
5004
        /* PE DLLs sometimes have zeroed out symbols for some
5005
     reason.  Just ignore them without a warning.  */
5006
246k
        if (src->u.syment.n_type == 0
5007
246k
      && src->u.syment.n_value == 0
5008
246k
      && src->u.syment.n_scnum == 0)
5009
136k
    break;
5010
#ifdef RS6000COFF_C
5011
        /* XCOFF specific: deleted entry.  */
5012
        if (src->u.syment.n_value == C_NULL_VALUE)
5013
    break;
5014
#endif
5015
        /* Fall through.  */
5016
110k
      case C_EXTDEF: /* External definition.  */
5017
111k
      case C_ULABEL: /* Undefined label.  */
5018
111k
      case C_USTATIC: /* Undefined static.  */
5019
#ifndef COFF_WITH_PE
5020
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5021
         class to represent a section symbol.  */
5022
      case C_LINE:  /* line # reformatted as symbol table entry.  */
5023
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5024
      case C_ALIAS: /* Duplicate tag.  */
5025
#endif
5026
        /* New storage classes for TI COFF.  */
5027
#ifdef TICOFF
5028
      case C_UEXT:  /* Tentative external definition.  */
5029
#endif
5030
111k
      case C_EXTLAB: /* External load time label.  */
5031
158k
      default:
5032
158k
        _bfd_error_handler
5033
    /* xgettext:c-format */
5034
158k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5035
158k
     abfd, src->u.syment.n_sclass,
5036
158k
     dst->symbol.section->name, dst->symbol.name);
5037
158k
        ret = false;
5038
        /* Fall through.  */
5039
158k
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5040
        /* PR 20722: These symbols can also be generated by
5041
     building DLLs with --gc-sections enabled.  */
5042
158k
        dst->symbol.flags = BSF_DEBUGGING;
5043
158k
        dst->symbol.value = (src->u.syment.n_value);
5044
158k
        break;
5045
345k
      }
5046
5047
345k
    dst->native = src;
5048
345k
    dst->symbol.udata.i = 0;
5049
345k
    dst->lineno = NULL;
5050
5051
345k
    this_index += (src->u.syment.n_numaux) + 1;
5052
345k
    dst++;
5053
345k
    number_of_symbols++;
5054
345k
  }
5055
783
    }
5056
5057
783
  obj_symbols (abfd) = cached_area;
5058
783
  obj_raw_syments (abfd) = native_symbols;
5059
5060
783
  abfd->symcount = number_of_symbols;
5061
783
  obj_convert (abfd) = table_ptr;
5062
  /* Slurp the line tables for each section too.  */
5063
783
  {
5064
783
    asection *p;
5065
5066
783
    p = abfd->sections;
5067
1.88k
    while (p)
5068
1.70k
      {
5069
1.70k
  if (! coff_slurp_line_table (abfd, p))
5070
595
    return false;
5071
1.10k
  p = p->next;
5072
1.10k
      }
5073
783
  }
5074
5075
188
  return ret;
5076
783
}
5077
5078
/* Classify a COFF symbol.  A couple of targets have globally visible
5079
   symbols which are not class C_EXT, and this handles those.  It also
5080
   recognizes some special PE cases.  */
5081
5082
static enum coff_symbol_classification
5083
coff_classify_symbol (bfd *abfd,
5084
          struct internal_syment *syment)
5085
258k
{
5086
  /* FIXME: This partially duplicates the switch in
5087
     coff_slurp_symbol_table.  */
5088
258k
  switch (syment->n_sclass)
5089
258k
    {
5090
162k
    case C_EXT:
5091
169k
    case C_WEAKEXT:
5092
#ifdef ARM
5093
4.90k
    case C_THUMBEXT:
5094
4.98k
    case C_THUMBEXTFUNC:
5095
#endif
5096
#ifdef RS6000COFF_C
5097
40.7k
    case C_HIDEXT:
5098
40.7k
#ifndef AIX_WEAK_SUPPORT
5099
44.6k
    case C_AIX_WEAKEXT:
5100
#endif
5101
#endif
5102
44.6k
#ifdef C_SYSTEM
5103
198k
    case C_SYSTEM:
5104
198k
#endif
5105
#ifdef COFF_WITH_PE
5106
157k
    case C_NT_WEAK:
5107
#endif
5108
244k
      if (syment->n_scnum == 0)
5109
25.8k
  {
5110
25.8k
    if (syment->n_value == 0)
5111
9.09k
      return COFF_SYMBOL_UNDEFINED;
5112
16.8k
    else
5113
16.8k
      return COFF_SYMBOL_COMMON;
5114
25.8k
  }
5115
#ifdef RS6000COFF_C
5116
46.9k
      if (syment->n_sclass == C_HIDEXT)
5117
1.81k
  return COFF_SYMBOL_LOCAL;
5118
45.1k
#endif
5119
216k
      return COFF_SYMBOL_GLOBAL;
5120
5121
14.2k
    default:
5122
14.2k
      break;
5123
258k
    }
5124
5125
#ifdef COFF_WITH_PE
5126
13.5k
  if (syment->n_sclass == C_STAT)
5127
277
    {
5128
277
      if (syment->n_scnum == 0)
5129
  /* The Microsoft compiler sometimes generates these if a
5130
     small static function is inlined every time it is used.
5131
     The function is discarded, but the symbol table entry
5132
     remains.  */
5133
0
  return COFF_SYMBOL_LOCAL;
5134
5135
#ifdef STRICT_PE_FORMAT
5136
      /* This is correct for Microsoft generated objects, but it
5137
   breaks gas generated objects.  */
5138
      if (syment->n_value == 0)
5139
  {
5140
    const asection *sec;
5141
    const char *name;
5142
    char buf[SYMNMLEN + 1];
5143
5144
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5145
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5146
    if (sec != NULL && name != NULL
5147
        && (strcmp (bfd_section_name (sec), name) == 0))
5148
      return COFF_SYMBOL_PE_SECTION;
5149
  }
5150
#endif
5151
5152
277
      return COFF_SYMBOL_LOCAL;
5153
277
    }
5154
5155
13.2k
  if (syment->n_sclass == C_SECTION)
5156
2.36k
    {
5157
      /* In some cases in a DLL generated by the Microsoft linker, the
5158
   n_value field will contain garbage.  FIXME: This should
5159
   probably be handled by the swapping function instead.  */
5160
2.36k
      syment->n_value = 0;
5161
2.36k
      if (syment->n_scnum == 0)
5162
1.88k
  return COFF_SYMBOL_UNDEFINED;
5163
472
      return COFF_SYMBOL_PE_SECTION;
5164
2.36k
    }
5165
10.8k
#endif /* COFF_WITH_PE */
5166
5167
  /* If it is not a global symbol, we presume it is a local symbol.  */
5168
11.5k
  if (syment->n_scnum == 0)
5169
11.5k
    {
5170
11.5k
      char buf[SYMNMLEN + 1];
5171
5172
11.5k
      _bfd_error_handler
5173
  /* xgettext:c-format */
5174
11.5k
  (_("warning: %pB: local symbol `%s' has no section"),
5175
11.5k
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5176
11.5k
    }
5177
5178
11.5k
  return COFF_SYMBOL_LOCAL;
5179
13.2k
}
pei-i386.c:coff_classify_symbol
Line
Count
Source
5085
2.91k
{
5086
  /* FIXME: This partially duplicates the switch in
5087
     coff_slurp_symbol_table.  */
5088
2.91k
  switch (syment->n_sclass)
5089
2.91k
    {
5090
1.56k
    case C_EXT:
5091
1.68k
    case C_WEAKEXT:
5092
#ifdef ARM
5093
    case C_THUMBEXT:
5094
    case C_THUMBEXTFUNC:
5095
#endif
5096
#ifdef RS6000COFF_C
5097
    case C_HIDEXT:
5098
#ifndef AIX_WEAK_SUPPORT
5099
    case C_AIX_WEAKEXT:
5100
#endif
5101
#endif
5102
1.68k
#ifdef C_SYSTEM
5103
1.88k
    case C_SYSTEM:
5104
1.88k
#endif
5105
1.88k
#ifdef COFF_WITH_PE
5106
2.88k
    case C_NT_WEAK:
5107
2.88k
#endif
5108
2.88k
      if (syment->n_scnum == 0)
5109
409
  {
5110
409
    if (syment->n_value == 0)
5111
127
      return COFF_SYMBOL_UNDEFINED;
5112
282
    else
5113
282
      return COFF_SYMBOL_COMMON;
5114
409
  }
5115
#ifdef RS6000COFF_C
5116
      if (syment->n_sclass == C_HIDEXT)
5117
  return COFF_SYMBOL_LOCAL;
5118
#endif
5119
2.47k
      return COFF_SYMBOL_GLOBAL;
5120
5121
38
    default:
5122
38
      break;
5123
2.91k
    }
5124
5125
38
#ifdef COFF_WITH_PE
5126
38
  if (syment->n_sclass == C_STAT)
5127
0
    {
5128
0
      if (syment->n_scnum == 0)
5129
  /* The Microsoft compiler sometimes generates these if a
5130
     small static function is inlined every time it is used.
5131
     The function is discarded, but the symbol table entry
5132
     remains.  */
5133
0
  return COFF_SYMBOL_LOCAL;
5134
5135
#ifdef STRICT_PE_FORMAT
5136
      /* This is correct for Microsoft generated objects, but it
5137
   breaks gas generated objects.  */
5138
      if (syment->n_value == 0)
5139
  {
5140
    const asection *sec;
5141
    const char *name;
5142
    char buf[SYMNMLEN + 1];
5143
5144
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5145
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5146
    if (sec != NULL && name != NULL
5147
        && (strcmp (bfd_section_name (sec), name) == 0))
5148
      return COFF_SYMBOL_PE_SECTION;
5149
  }
5150
#endif
5151
5152
0
      return COFF_SYMBOL_LOCAL;
5153
0
    }
5154
5155
38
  if (syment->n_sclass == C_SECTION)
5156
38
    {
5157
      /* In some cases in a DLL generated by the Microsoft linker, the
5158
   n_value field will contain garbage.  FIXME: This should
5159
   probably be handled by the swapping function instead.  */
5160
38
      syment->n_value = 0;
5161
38
      if (syment->n_scnum == 0)
5162
38
  return COFF_SYMBOL_UNDEFINED;
5163
0
      return COFF_SYMBOL_PE_SECTION;
5164
38
    }
5165
0
#endif /* COFF_WITH_PE */
5166
5167
  /* If it is not a global symbol, we presume it is a local symbol.  */
5168
0
  if (syment->n_scnum == 0)
5169
0
    {
5170
0
      char buf[SYMNMLEN + 1];
5171
5172
0
      _bfd_error_handler
5173
  /* xgettext:c-format */
5174
0
  (_("warning: %pB: local symbol `%s' has no section"),
5175
0
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5176
0
    }
5177
5178
0
  return COFF_SYMBOL_LOCAL;
5179
38
}
pe-x86_64.c:coff_classify_symbol
Line
Count
Source
5085
8.47k
{
5086
  /* FIXME: This partially duplicates the switch in
5087
     coff_slurp_symbol_table.  */
5088
8.47k
  switch (syment->n_sclass)
5089
8.47k
    {
5090
4.05k
    case C_EXT:
5091
4.37k
    case C_WEAKEXT:
5092
#ifdef ARM
5093
    case C_THUMBEXT:
5094
    case C_THUMBEXTFUNC:
5095
#endif
5096
#ifdef RS6000COFF_C
5097
    case C_HIDEXT:
5098
#ifndef AIX_WEAK_SUPPORT
5099
    case C_AIX_WEAKEXT:
5100
#endif
5101
#endif
5102
4.37k
#ifdef C_SYSTEM
5103
5.10k
    case C_SYSTEM:
5104
5.10k
#endif
5105
5.10k
#ifdef COFF_WITH_PE
5106
7.83k
    case C_NT_WEAK:
5107
7.83k
#endif
5108
7.83k
      if (syment->n_scnum == 0)
5109
870
  {
5110
870
    if (syment->n_value == 0)
5111
219
      return COFF_SYMBOL_UNDEFINED;
5112
651
    else
5113
651
      return COFF_SYMBOL_COMMON;
5114
870
  }
5115
#ifdef RS6000COFF_C
5116
      if (syment->n_sclass == C_HIDEXT)
5117
  return COFF_SYMBOL_LOCAL;
5118
#endif
5119
6.96k
      return COFF_SYMBOL_GLOBAL;
5120
5121
639
    default:
5122
639
      break;
5123
8.47k
    }
5124
5125
639
#ifdef COFF_WITH_PE
5126
639
  if (syment->n_sclass == C_STAT)
5127
0
    {
5128
0
      if (syment->n_scnum == 0)
5129
  /* The Microsoft compiler sometimes generates these if a
5130
     small static function is inlined every time it is used.
5131
     The function is discarded, but the symbol table entry
5132
     remains.  */
5133
0
  return COFF_SYMBOL_LOCAL;
5134
5135
#ifdef STRICT_PE_FORMAT
5136
      /* This is correct for Microsoft generated objects, but it
5137
   breaks gas generated objects.  */
5138
      if (syment->n_value == 0)
5139
  {
5140
    const asection *sec;
5141
    const char *name;
5142
    char buf[SYMNMLEN + 1];
5143
5144
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5145
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5146
    if (sec != NULL && name != NULL
5147
        && (strcmp (bfd_section_name (sec), name) == 0))
5148
      return COFF_SYMBOL_PE_SECTION;
5149
  }
5150
#endif
5151
5152
0
      return COFF_SYMBOL_LOCAL;
5153
0
    }
5154
5155
639
  if (syment->n_sclass == C_SECTION)
5156
639
    {
5157
      /* In some cases in a DLL generated by the Microsoft linker, the
5158
   n_value field will contain garbage.  FIXME: This should
5159
   probably be handled by the swapping function instead.  */
5160
639
      syment->n_value = 0;
5161
639
      if (syment->n_scnum == 0)
5162
167
  return COFF_SYMBOL_UNDEFINED;
5163
472
      return COFF_SYMBOL_PE_SECTION;
5164
639
    }
5165
0
#endif /* COFF_WITH_PE */
5166
5167
  /* If it is not a global symbol, we presume it is a local symbol.  */
5168
0
  if (syment->n_scnum == 0)
5169
0
    {
5170
0
      char buf[SYMNMLEN + 1];
5171
5172
0
      _bfd_error_handler
5173
  /* xgettext:c-format */
5174
0
  (_("warning: %pB: local symbol `%s' has no section"),
5175
0
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5176
0
    }
5177
5178
0
  return COFF_SYMBOL_LOCAL;
5179
639
}
pei-x86_64.c:coff_classify_symbol
Line
Count
Source
5085
26.8k
{
5086
  /* FIXME: This partially duplicates the switch in
5087
     coff_slurp_symbol_table.  */
5088
26.8k
  switch (syment->n_sclass)
5089
26.8k
    {
5090
24.7k
    case C_EXT:
5091
24.8k
    case C_WEAKEXT:
5092
#ifdef ARM
5093
    case C_THUMBEXT:
5094
    case C_THUMBEXTFUNC:
5095
#endif
5096
#ifdef RS6000COFF_C
5097
    case C_HIDEXT:
5098
#ifndef AIX_WEAK_SUPPORT
5099
    case C_AIX_WEAKEXT:
5100
#endif
5101
#endif
5102
24.8k
#ifdef C_SYSTEM
5103
25.1k
    case C_SYSTEM:
5104
25.1k
#endif
5105
25.1k
#ifdef COFF_WITH_PE
5106
26.5k
    case C_NT_WEAK:
5107
26.5k
#endif
5108
26.5k
      if (syment->n_scnum == 0)
5109
4.20k
  {
5110
4.20k
    if (syment->n_value == 0)
5111
3.86k
      return COFF_SYMBOL_UNDEFINED;
5112
343
    else
5113
343
      return COFF_SYMBOL_COMMON;
5114
4.20k
  }
5115
#ifdef RS6000COFF_C
5116
      if (syment->n_sclass == C_HIDEXT)
5117
  return COFF_SYMBOL_LOCAL;
5118
#endif
5119
22.3k
      return COFF_SYMBOL_GLOBAL;
5120
5121
344
    default:
5122
344
      break;
5123
26.8k
    }
5124
5125
344
#ifdef COFF_WITH_PE
5126
344
  if (syment->n_sclass == C_STAT)
5127
277
    {
5128
277
      if (syment->n_scnum == 0)
5129
  /* The Microsoft compiler sometimes generates these if a
5130
     small static function is inlined every time it is used.
5131
     The function is discarded, but the symbol table entry
5132
     remains.  */
5133
0
  return COFF_SYMBOL_LOCAL;
5134
5135
#ifdef STRICT_PE_FORMAT
5136
      /* This is correct for Microsoft generated objects, but it
5137
   breaks gas generated objects.  */
5138
      if (syment->n_value == 0)
5139
  {
5140
    const asection *sec;
5141
    const char *name;
5142
    char buf[SYMNMLEN + 1];
5143
5144
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5145
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5146
    if (sec != NULL && name != NULL
5147
        && (strcmp (bfd_section_name (sec), name) == 0))
5148
      return COFF_SYMBOL_PE_SECTION;
5149
  }
5150
#endif
5151
5152
277
      return COFF_SYMBOL_LOCAL;
5153
277
    }
5154
5155
67
  if (syment->n_sclass == C_SECTION)
5156
39
    {
5157
      /* In some cases in a DLL generated by the Microsoft linker, the
5158
   n_value field will contain garbage.  FIXME: This should
5159
   probably be handled by the swapping function instead.  */
5160
39
      syment->n_value = 0;
5161
39
      if (syment->n_scnum == 0)
5162
39
  return COFF_SYMBOL_UNDEFINED;
5163
0
      return COFF_SYMBOL_PE_SECTION;
5164
39
    }
5165
28
#endif /* COFF_WITH_PE */
5166
5167
  /* If it is not a global symbol, we presume it is a local symbol.  */
5168
28
  if (syment->n_scnum == 0)
5169
0
    {
5170
0
      char buf[SYMNMLEN + 1];
5171
5172
0
      _bfd_error_handler
5173
  /* xgettext:c-format */
5174
0
  (_("warning: %pB: local symbol `%s' has no section"),
5175
0
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5176
0
    }
5177
5178
28
  return COFF_SYMBOL_LOCAL;
5179
67
}
coff-x86_64.c:coff_classify_symbol
Line
Count
Source
5085
4.36k
{
5086
  /* FIXME: This partially duplicates the switch in
5087
     coff_slurp_symbol_table.  */
5088
4.36k
  switch (syment->n_sclass)
5089
4.36k
    {
5090
3.04k
    case C_EXT:
5091
3.31k
    case C_WEAKEXT:
5092
#ifdef ARM
5093
    case C_THUMBEXT:
5094
    case C_THUMBEXTFUNC:
5095
#endif
5096
#ifdef RS6000COFF_C
5097
    case C_HIDEXT:
5098
#ifndef AIX_WEAK_SUPPORT
5099
    case C_AIX_WEAKEXT:
5100
#endif
5101
#endif
5102
3.31k
#ifdef C_SYSTEM
5103
3.69k
    case C_SYSTEM:
5104
3.69k
#endif
5105
#ifdef COFF_WITH_PE
5106
    case C_NT_WEAK:
5107
#endif
5108
3.69k
      if (syment->n_scnum == 0)
5109
766
  {
5110
766
    if (syment->n_value == 0)
5111
185
      return COFF_SYMBOL_UNDEFINED;
5112
581
    else
5113
581
      return COFF_SYMBOL_COMMON;
5114
766
  }
5115
#ifdef RS6000COFF_C
5116
      if (syment->n_sclass == C_HIDEXT)
5117
  return COFF_SYMBOL_LOCAL;
5118
#endif
5119
2.93k
      return COFF_SYMBOL_GLOBAL;
5120
5121
670
    default:
5122
670
      break;
5123
4.36k
    }
5124
5125
#ifdef COFF_WITH_PE
5126
  if (syment->n_sclass == C_STAT)
5127
    {
5128
      if (syment->n_scnum == 0)
5129
  /* The Microsoft compiler sometimes generates these if a
5130
     small static function is inlined every time it is used.
5131
     The function is discarded, but the symbol table entry
5132
     remains.  */
5133
  return COFF_SYMBOL_LOCAL;
5134
5135
#ifdef STRICT_PE_FORMAT
5136
      /* This is correct for Microsoft generated objects, but it
5137
   breaks gas generated objects.  */
5138
      if (syment->n_value == 0)
5139
  {
5140
    const asection *sec;
5141
    const char *name;
5142
    char buf[SYMNMLEN + 1];
5143
5144
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5145
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5146
    if (sec != NULL && name != NULL
5147
        && (strcmp (bfd_section_name (sec), name) == 0))
5148
      return COFF_SYMBOL_PE_SECTION;
5149
  }
5150
#endif
5151
5152
      return COFF_SYMBOL_LOCAL;
5153
    }
5154
5155
  if (syment->n_sclass == C_SECTION)
5156
    {
5157
      /* In some cases in a DLL generated by the Microsoft linker, the
5158
   n_value field will contain garbage.  FIXME: This should
5159
   probably be handled by the swapping function instead.  */
5160
      syment->n_value = 0;
5161
      if (syment->n_scnum == 0)
5162
  return COFF_SYMBOL_UNDEFINED;
5163
      return COFF_SYMBOL_PE_SECTION;
5164
    }
5165
#endif /* COFF_WITH_PE */
5166
5167
  /* If it is not a global symbol, we presume it is a local symbol.  */
5168
670
  if (syment->n_scnum == 0)
5169
670
    {
5170
670
      char buf[SYMNMLEN + 1];
5171
5172
670
      _bfd_error_handler
5173
  /* xgettext:c-format */
5174
670
  (_("warning: %pB: local symbol `%s' has no section"),
5175
670
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5176
670
    }
5177
5178
670
  return COFF_SYMBOL_LOCAL;
5179
4.36k
}
coff64-rs6000.c:coff_classify_symbol
Line
Count
Source
5085
4.67k
{
5086
  /* FIXME: This partially duplicates the switch in
5087
     coff_slurp_symbol_table.  */
5088
4.67k
  switch (syment->n_sclass)
5089
4.67k
    {
5090
1.70k
    case C_EXT:
5091
1.86k
    case C_WEAKEXT:
5092
#ifdef ARM
5093
    case C_THUMBEXT:
5094
    case C_THUMBEXTFUNC:
5095
#endif
5096
1.86k
#ifdef RS6000COFF_C
5097
2.26k
    case C_HIDEXT:
5098
2.26k
#ifndef AIX_WEAK_SUPPORT
5099
3.97k
    case C_AIX_WEAKEXT:
5100
3.97k
#endif
5101
3.97k
#endif
5102
3.97k
#ifdef C_SYSTEM
5103
4.67k
    case C_SYSTEM:
5104
4.67k
#endif
5105
#ifdef COFF_WITH_PE
5106
    case C_NT_WEAK:
5107
#endif
5108
4.67k
      if (syment->n_scnum == 0)
5109
564
  {
5110
564
    if (syment->n_value == 0)
5111
321
      return COFF_SYMBOL_UNDEFINED;
5112
243
    else
5113
243
      return COFF_SYMBOL_COMMON;
5114
564
  }
5115
4.10k
#ifdef RS6000COFF_C
5116
4.10k
      if (syment->n_sclass == C_HIDEXT)
5117
387
  return COFF_SYMBOL_LOCAL;
5118
3.71k
#endif
5119
3.71k
      return COFF_SYMBOL_GLOBAL;
5120
5121
0
    default:
5122
0
      break;
5123
4.67k
    }
5124
5125
#ifdef COFF_WITH_PE
5126
  if (syment->n_sclass == C_STAT)
5127
    {
5128
      if (syment->n_scnum == 0)
5129
  /* The Microsoft compiler sometimes generates these if a
5130
     small static function is inlined every time it is used.
5131
     The function is discarded, but the symbol table entry
5132
     remains.  */
5133
  return COFF_SYMBOL_LOCAL;
5134
5135
#ifdef STRICT_PE_FORMAT
5136
      /* This is correct for Microsoft generated objects, but it
5137
   breaks gas generated objects.  */
5138
      if (syment->n_value == 0)
5139
  {
5140
    const asection *sec;
5141
    const char *name;
5142
    char buf[SYMNMLEN + 1];
5143
5144
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5145
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5146
    if (sec != NULL && name != NULL
5147
        && (strcmp (bfd_section_name (sec), name) == 0))
5148
      return COFF_SYMBOL_PE_SECTION;
5149
  }
5150
#endif
5151
5152
      return COFF_SYMBOL_LOCAL;
5153
    }
5154
5155
  if (syment->n_sclass == C_SECTION)
5156
    {
5157
      /* In some cases in a DLL generated by the Microsoft linker, the
5158
   n_value field will contain garbage.  FIXME: This should
5159
   probably be handled by the swapping function instead.  */
5160
      syment->n_value = 0;
5161
      if (syment->n_scnum == 0)
5162
  return COFF_SYMBOL_UNDEFINED;
5163
      return COFF_SYMBOL_PE_SECTION;
5164
    }
5165
#endif /* COFF_WITH_PE */
5166
5167
  /* If it is not a global symbol, we presume it is a local symbol.  */
5168
0
  if (syment->n_scnum == 0)
5169
0
    {
5170
0
      char buf[SYMNMLEN + 1];
5171
5172
0
      _bfd_error_handler
5173
  /* xgettext:c-format */
5174
0
  (_("warning: %pB: local symbol `%s' has no section"),
5175
0
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5176
0
    }
5177
5178
0
  return COFF_SYMBOL_LOCAL;
5179
4.67k
}
pe-aarch64.c:coff_classify_symbol
Line
Count
Source
5085
17.6k
{
5086
  /* FIXME: This partially duplicates the switch in
5087
     coff_slurp_symbol_table.  */
5088
17.6k
  switch (syment->n_sclass)
5089
17.6k
    {
5090
11.4k
    case C_EXT:
5091
11.7k
    case C_WEAKEXT:
5092
#ifdef ARM
5093
    case C_THUMBEXT:
5094
    case C_THUMBEXTFUNC:
5095
#endif
5096
#ifdef RS6000COFF_C
5097
    case C_HIDEXT:
5098
#ifndef AIX_WEAK_SUPPORT
5099
    case C_AIX_WEAKEXT:
5100
#endif
5101
#endif
5102
11.7k
#ifdef C_SYSTEM
5103
12.8k
    case C_SYSTEM:
5104
12.8k
#endif
5105
12.8k
#ifdef COFF_WITH_PE
5106
17.4k
    case C_NT_WEAK:
5107
17.4k
#endif
5108
17.4k
      if (syment->n_scnum == 0)
5109
1.47k
  {
5110
1.47k
    if (syment->n_value == 0)
5111
353
      return COFF_SYMBOL_UNDEFINED;
5112
1.12k
    else
5113
1.12k
      return COFF_SYMBOL_COMMON;
5114
1.47k
  }
5115
#ifdef RS6000COFF_C
5116
      if (syment->n_sclass == C_HIDEXT)
5117
  return COFF_SYMBOL_LOCAL;
5118
#endif
5119
15.9k
      return COFF_SYMBOL_GLOBAL;
5120
5121
277
    default:
5122
277
      break;
5123
17.6k
    }
5124
5125
277
#ifdef COFF_WITH_PE
5126
277
  if (syment->n_sclass == C_STAT)
5127
0
    {
5128
0
      if (syment->n_scnum == 0)
5129
  /* The Microsoft compiler sometimes generates these if a
5130
     small static function is inlined every time it is used.
5131
     The function is discarded, but the symbol table entry
5132
     remains.  */
5133
0
  return COFF_SYMBOL_LOCAL;
5134
5135
#ifdef STRICT_PE_FORMAT
5136
      /* This is correct for Microsoft generated objects, but it
5137
   breaks gas generated objects.  */
5138
      if (syment->n_value == 0)
5139
  {
5140
    const asection *sec;
5141
    const char *name;
5142
    char buf[SYMNMLEN + 1];
5143
5144
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5145
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5146
    if (sec != NULL && name != NULL
5147
        && (strcmp (bfd_section_name (sec), name) == 0))
5148
      return COFF_SYMBOL_PE_SECTION;
5149
  }
5150
#endif
5151
5152
0
      return COFF_SYMBOL_LOCAL;
5153
0
    }
5154
5155
277
  if (syment->n_sclass == C_SECTION)
5156
277
    {
5157
      /* In some cases in a DLL generated by the Microsoft linker, the
5158
   n_value field will contain garbage.  FIXME: This should
5159
   probably be handled by the swapping function instead.  */
5160
277
      syment->n_value = 0;
5161
277
      if (syment->n_scnum == 0)
5162
277
  return COFF_SYMBOL_UNDEFINED;
5163
0
      return COFF_SYMBOL_PE_SECTION;
5164
277
    }
5165
0
#endif /* COFF_WITH_PE */
5166
5167
  /* If it is not a global symbol, we presume it is a local symbol.  */
5168
0
  if (syment->n_scnum == 0)
5169
0
    {
5170
0
      char buf[SYMNMLEN + 1];
5171
5172
0
      _bfd_error_handler
5173
  /* xgettext:c-format */
5174
0
  (_("warning: %pB: local symbol `%s' has no section"),
5175
0
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5176
0
    }
5177
5178
0
  return COFF_SYMBOL_LOCAL;
5179
277
}
pei-aarch64.c:coff_classify_symbol
Line
Count
Source
5085
9.84k
{
5086
  /* FIXME: This partially duplicates the switch in
5087
     coff_slurp_symbol_table.  */
5088
9.84k
  switch (syment->n_sclass)
5089
9.84k
    {
5090
3.18k
    case C_EXT:
5091
3.31k
    case C_WEAKEXT:
5092
#ifdef ARM
5093
    case C_THUMBEXT:
5094
    case C_THUMBEXTFUNC:
5095
#endif
5096
#ifdef RS6000COFF_C
5097
    case C_HIDEXT:
5098
#ifndef AIX_WEAK_SUPPORT
5099
    case C_AIX_WEAKEXT:
5100
#endif
5101
#endif
5102
3.31k
#ifdef C_SYSTEM
5103
4.76k
    case C_SYSTEM:
5104
4.76k
#endif
5105
4.76k
#ifdef COFF_WITH_PE
5106
7.82k
    case C_NT_WEAK:
5107
7.82k
#endif
5108
7.82k
      if (syment->n_scnum == 0)
5109
815
  {
5110
815
    if (syment->n_value == 0)
5111
232
      return COFF_SYMBOL_UNDEFINED;
5112
583
    else
5113
583
      return COFF_SYMBOL_COMMON;
5114
815
  }
5115
#ifdef RS6000COFF_C
5116
      if (syment->n_sclass == C_HIDEXT)
5117
  return COFF_SYMBOL_LOCAL;
5118
#endif
5119
7.01k
      return COFF_SYMBOL_GLOBAL;
5120
5121
2.01k
    default:
5122
2.01k
      break;
5123
9.84k
    }
5124
5125
2.01k
#ifdef COFF_WITH_PE
5126
2.01k
  if (syment->n_sclass == C_STAT)
5127
0
    {
5128
0
      if (syment->n_scnum == 0)
5129
  /* The Microsoft compiler sometimes generates these if a
5130
     small static function is inlined every time it is used.
5131
     The function is discarded, but the symbol table entry
5132
     remains.  */
5133
0
  return COFF_SYMBOL_LOCAL;
5134
5135
#ifdef STRICT_PE_FORMAT
5136
      /* This is correct for Microsoft generated objects, but it
5137
   breaks gas generated objects.  */
5138
      if (syment->n_value == 0)
5139
  {
5140
    const asection *sec;
5141
    const char *name;
5142
    char buf[SYMNMLEN + 1];
5143
5144
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5145
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5146
    if (sec != NULL && name != NULL
5147
        && (strcmp (bfd_section_name (sec), name) == 0))
5148
      return COFF_SYMBOL_PE_SECTION;
5149
  }
5150
#endif
5151
5152
0
      return COFF_SYMBOL_LOCAL;
5153
0
    }
5154
5155
2.01k
  if (syment->n_sclass == C_SECTION)
5156
81
    {
5157
      /* In some cases in a DLL generated by the Microsoft linker, the
5158
   n_value field will contain garbage.  FIXME: This should
5159
   probably be handled by the swapping function instead.  */
5160
81
      syment->n_value = 0;
5161
81
      if (syment->n_scnum == 0)
5162
81
  return COFF_SYMBOL_UNDEFINED;
5163
0
      return COFF_SYMBOL_PE_SECTION;
5164
81
    }
5165
1.93k
#endif /* COFF_WITH_PE */
5166
5167
  /* If it is not a global symbol, we presume it is a local symbol.  */
5168
1.93k
  if (syment->n_scnum == 0)
5169
1.93k
    {
5170
1.93k
      char buf[SYMNMLEN + 1];
5171
5172
1.93k
      _bfd_error_handler
5173
  /* xgettext:c-format */
5174
1.93k
  (_("warning: %pB: local symbol `%s' has no section"),
5175
1.93k
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5176
1.93k
    }
5177
5178
1.93k
  return COFF_SYMBOL_LOCAL;
5179
2.01k
}
pei-ia64.c:coff_classify_symbol
Line
Count
Source
5085
14.9k
{
5086
  /* FIXME: This partially duplicates the switch in
5087
     coff_slurp_symbol_table.  */
5088
14.9k
  switch (syment->n_sclass)
5089
14.9k
    {
5090
9.01k
    case C_EXT:
5091
9.25k
    case C_WEAKEXT:
5092
#ifdef ARM
5093
    case C_THUMBEXT:
5094
    case C_THUMBEXTFUNC:
5095
#endif
5096
#ifdef RS6000COFF_C
5097
    case C_HIDEXT:
5098
#ifndef AIX_WEAK_SUPPORT
5099
    case C_AIX_WEAKEXT:
5100
#endif
5101
#endif
5102
9.25k
#ifdef C_SYSTEM
5103
9.90k
    case C_SYSTEM:
5104
9.90k
#endif
5105
9.90k
#ifdef COFF_WITH_PE
5106
14.6k
    case C_NT_WEAK:
5107
14.6k
#endif
5108
14.6k
      if (syment->n_scnum == 0)
5109
1.25k
  {
5110
1.25k
    if (syment->n_value == 0)
5111
394
      return COFF_SYMBOL_UNDEFINED;
5112
858
    else
5113
858
      return COFF_SYMBOL_COMMON;
5114
1.25k
  }
5115
#ifdef RS6000COFF_C
5116
      if (syment->n_sclass == C_HIDEXT)
5117
  return COFF_SYMBOL_LOCAL;
5118
#endif
5119
13.3k
      return COFF_SYMBOL_GLOBAL;
5120
5121
326
    default:
5122
326
      break;
5123
14.9k
    }
5124
5125
326
#ifdef COFF_WITH_PE
5126
326
  if (syment->n_sclass == C_STAT)
5127
0
    {
5128
0
      if (syment->n_scnum == 0)
5129
  /* The Microsoft compiler sometimes generates these if a
5130
     small static function is inlined every time it is used.
5131
     The function is discarded, but the symbol table entry
5132
     remains.  */
5133
0
  return COFF_SYMBOL_LOCAL;
5134
5135
#ifdef STRICT_PE_FORMAT
5136
      /* This is correct for Microsoft generated objects, but it
5137
   breaks gas generated objects.  */
5138
      if (syment->n_value == 0)
5139
  {
5140
    const asection *sec;
5141
    const char *name;
5142
    char buf[SYMNMLEN + 1];
5143
5144
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5145
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5146
    if (sec != NULL && name != NULL
5147
        && (strcmp (bfd_section_name (sec), name) == 0))
5148
      return COFF_SYMBOL_PE_SECTION;
5149
  }
5150
#endif
5151
5152
0
      return COFF_SYMBOL_LOCAL;
5153
0
    }
5154
5155
326
  if (syment->n_sclass == C_SECTION)
5156
326
    {
5157
      /* In some cases in a DLL generated by the Microsoft linker, the
5158
   n_value field will contain garbage.  FIXME: This should
5159
   probably be handled by the swapping function instead.  */
5160
326
      syment->n_value = 0;
5161
326
      if (syment->n_scnum == 0)
5162
326
  return COFF_SYMBOL_UNDEFINED;
5163
0
      return COFF_SYMBOL_PE_SECTION;
5164
326
    }
5165
0
#endif /* COFF_WITH_PE */
5166
5167
  /* If it is not a global symbol, we presume it is a local symbol.  */
5168
0
  if (syment->n_scnum == 0)
5169
0
    {
5170
0
      char buf[SYMNMLEN + 1];
5171
5172
0
      _bfd_error_handler
5173
  /* xgettext:c-format */
5174
0
  (_("warning: %pB: local symbol `%s' has no section"),
5175
0
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5176
0
    }
5177
5178
0
  return COFF_SYMBOL_LOCAL;
5179
326
}
pei-loongarch64.c:coff_classify_symbol
Line
Count
Source
5085
8.88k
{
5086
  /* FIXME: This partially duplicates the switch in
5087
     coff_slurp_symbol_table.  */
5088
8.88k
  switch (syment->n_sclass)
5089
8.88k
    {
5090
3.29k
    case C_EXT:
5091
3.61k
    case C_WEAKEXT:
5092
#ifdef ARM
5093
    case C_THUMBEXT:
5094
    case C_THUMBEXTFUNC:
5095
#endif
5096
#ifdef RS6000COFF_C
5097
    case C_HIDEXT:
5098
#ifndef AIX_WEAK_SUPPORT
5099
    case C_AIX_WEAKEXT:
5100
#endif
5101
#endif
5102
3.61k
#ifdef C_SYSTEM
5103
4.28k
    case C_SYSTEM:
5104
4.28k
#endif
5105
4.28k
#ifdef COFF_WITH_PE
5106
8.66k
    case C_NT_WEAK:
5107
8.66k
#endif
5108
8.66k
      if (syment->n_scnum == 0)
5109
1.00k
  {
5110
1.00k
    if (syment->n_value == 0)
5111
238
      return COFF_SYMBOL_UNDEFINED;
5112
768
    else
5113
768
      return COFF_SYMBOL_COMMON;
5114
1.00k
  }
5115
#ifdef RS6000COFF_C
5116
      if (syment->n_sclass == C_HIDEXT)
5117
  return COFF_SYMBOL_LOCAL;
5118
#endif
5119
7.65k
      return COFF_SYMBOL_GLOBAL;
5120
5121
219
    default:
5122
219
      break;
5123
8.88k
    }
5124
5125
219
#ifdef COFF_WITH_PE
5126
219
  if (syment->n_sclass == C_STAT)
5127
0
    {
5128
0
      if (syment->n_scnum == 0)
5129
  /* The Microsoft compiler sometimes generates these if a
5130
     small static function is inlined every time it is used.
5131
     The function is discarded, but the symbol table entry
5132
     remains.  */
5133
0
  return COFF_SYMBOL_LOCAL;
5134
5135
#ifdef STRICT_PE_FORMAT
5136
      /* This is correct for Microsoft generated objects, but it
5137
   breaks gas generated objects.  */
5138
      if (syment->n_value == 0)
5139
  {
5140
    const asection *sec;
5141
    const char *name;
5142
    char buf[SYMNMLEN + 1];
5143
5144
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5145
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5146
    if (sec != NULL && name != NULL
5147
        && (strcmp (bfd_section_name (sec), name) == 0))
5148
      return COFF_SYMBOL_PE_SECTION;
5149
  }
5150
#endif
5151
5152
0
      return COFF_SYMBOL_LOCAL;
5153
0
    }
5154
5155
219
  if (syment->n_sclass == C_SECTION)
5156
219
    {
5157
      /* In some cases in a DLL generated by the Microsoft linker, the
5158
   n_value field will contain garbage.  FIXME: This should
5159
   probably be handled by the swapping function instead.  */
5160
219
      syment->n_value = 0;
5161
219
      if (syment->n_scnum == 0)
5162
219
  return COFF_SYMBOL_UNDEFINED;
5163
0
      return COFF_SYMBOL_PE_SECTION;
5164
219
    }
5165
0
#endif /* COFF_WITH_PE */
5166
5167
  /* If it is not a global symbol, we presume it is a local symbol.  */
5168
0
  if (syment->n_scnum == 0)
5169
0
    {
5170
0
      char buf[SYMNMLEN + 1];
5171
5172
0
      _bfd_error_handler
5173
  /* xgettext:c-format */
5174
0
  (_("warning: %pB: local symbol `%s' has no section"),
5175
0
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5176
0
    }
5177
5178
0
  return COFF_SYMBOL_LOCAL;
5179
219
}
pei-riscv64.c:coff_classify_symbol
Line
Count
Source
5085
18.9k
{
5086
  /* FIXME: This partially duplicates the switch in
5087
     coff_slurp_symbol_table.  */
5088
18.9k
  switch (syment->n_sclass)
5089
18.9k
    {
5090
3.94k
    case C_EXT:
5091
4.29k
    case C_WEAKEXT:
5092
#ifdef ARM
5093
    case C_THUMBEXT:
5094
    case C_THUMBEXTFUNC:
5095
#endif
5096
#ifdef RS6000COFF_C
5097
    case C_HIDEXT:
5098
#ifndef AIX_WEAK_SUPPORT
5099
    case C_AIX_WEAKEXT:
5100
#endif
5101
#endif
5102
4.29k
#ifdef C_SYSTEM
5103
5.78k
    case C_SYSTEM:
5104
5.78k
#endif
5105
5.78k
#ifdef COFF_WITH_PE
5106
9.90k
    case C_NT_WEAK:
5107
9.90k
#endif
5108
9.90k
      if (syment->n_scnum == 0)
5109
1.18k
  {
5110
1.18k
    if (syment->n_value == 0)
5111
231
      return COFF_SYMBOL_UNDEFINED;
5112
951
    else
5113
951
      return COFF_SYMBOL_COMMON;
5114
1.18k
  }
5115
#ifdef RS6000COFF_C
5116
      if (syment->n_sclass == C_HIDEXT)
5117
  return COFF_SYMBOL_LOCAL;
5118
#endif
5119
8.72k
      return COFF_SYMBOL_GLOBAL;
5120
5121
9.05k
    default:
5122
9.05k
      break;
5123
18.9k
    }
5124
5125
9.05k
#ifdef COFF_WITH_PE
5126
9.05k
  if (syment->n_sclass == C_STAT)
5127
0
    {
5128
0
      if (syment->n_scnum == 0)
5129
  /* The Microsoft compiler sometimes generates these if a
5130
     small static function is inlined every time it is used.
5131
     The function is discarded, but the symbol table entry
5132
     remains.  */
5133
0
  return COFF_SYMBOL_LOCAL;
5134
5135
#ifdef STRICT_PE_FORMAT
5136
      /* This is correct for Microsoft generated objects, but it
5137
   breaks gas generated objects.  */
5138
      if (syment->n_value == 0)
5139
  {
5140
    const asection *sec;
5141
    const char *name;
5142
    char buf[SYMNMLEN + 1];
5143
5144
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5145
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5146
    if (sec != NULL && name != NULL
5147
        && (strcmp (bfd_section_name (sec), name) == 0))
5148
      return COFF_SYMBOL_PE_SECTION;
5149
  }
5150
#endif
5151
5152
0
      return COFF_SYMBOL_LOCAL;
5153
0
    }
5154
5155
9.05k
  if (syment->n_sclass == C_SECTION)
5156
125
    {
5157
      /* In some cases in a DLL generated by the Microsoft linker, the
5158
   n_value field will contain garbage.  FIXME: This should
5159
   probably be handled by the swapping function instead.  */
5160
125
      syment->n_value = 0;
5161
125
      if (syment->n_scnum == 0)
5162
125
  return COFF_SYMBOL_UNDEFINED;
5163
0
      return COFF_SYMBOL_PE_SECTION;
5164
125
    }
5165
8.92k
#endif /* COFF_WITH_PE */
5166
5167
  /* If it is not a global symbol, we presume it is a local symbol.  */
5168
8.92k
  if (syment->n_scnum == 0)
5169
8.92k
    {
5170
8.92k
      char buf[SYMNMLEN + 1];
5171
5172
8.92k
      _bfd_error_handler
5173
  /* xgettext:c-format */
5174
8.92k
  (_("warning: %pB: local symbol `%s' has no section"),
5175
8.92k
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5176
8.92k
    }
5177
5178
8.92k
  return COFF_SYMBOL_LOCAL;
5179
9.05k
}
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
5085
43.3k
{
5086
  /* FIXME: This partially duplicates the switch in
5087
     coff_slurp_symbol_table.  */
5088
43.3k
  switch (syment->n_sclass)
5089
43.3k
    {
5090
36.1k
    case C_EXT:
5091
37.0k
    case C_WEAKEXT:
5092
#ifdef ARM
5093
    case C_THUMBEXT:
5094
    case C_THUMBEXTFUNC:
5095
#endif
5096
37.0k
#ifdef RS6000COFF_C
5097
38.4k
    case C_HIDEXT:
5098
38.4k
#ifndef AIX_WEAK_SUPPORT
5099
40.6k
    case C_AIX_WEAKEXT:
5100
40.6k
#endif
5101
40.6k
#endif
5102
40.6k
#ifdef C_SYSTEM
5103
43.3k
    case C_SYSTEM:
5104
43.3k
#endif
5105
#ifdef COFF_WITH_PE
5106
    case C_NT_WEAK:
5107
#endif
5108
43.3k
      if (syment->n_scnum == 0)
5109
504
  {
5110
504
    if (syment->n_value == 0)
5111
80
      return COFF_SYMBOL_UNDEFINED;
5112
424
    else
5113
424
      return COFF_SYMBOL_COMMON;
5114
504
  }
5115
42.8k
#ifdef RS6000COFF_C
5116
42.8k
      if (syment->n_sclass == C_HIDEXT)
5117
1.43k
  return COFF_SYMBOL_LOCAL;
5118
41.3k
#endif
5119
41.3k
      return COFF_SYMBOL_GLOBAL;
5120
5121
0
    default:
5122
0
      break;
5123
43.3k
    }
5124
5125
#ifdef COFF_WITH_PE
5126
  if (syment->n_sclass == C_STAT)
5127
    {
5128
      if (syment->n_scnum == 0)
5129
  /* The Microsoft compiler sometimes generates these if a
5130
     small static function is inlined every time it is used.
5131
     The function is discarded, but the symbol table entry
5132
     remains.  */
5133
  return COFF_SYMBOL_LOCAL;
5134
5135
#ifdef STRICT_PE_FORMAT
5136
      /* This is correct for Microsoft generated objects, but it
5137
   breaks gas generated objects.  */
5138
      if (syment->n_value == 0)
5139
  {
5140
    const asection *sec;
5141
    const char *name;
5142
    char buf[SYMNMLEN + 1];
5143
5144
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5145
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5146
    if (sec != NULL && name != NULL
5147
        && (strcmp (bfd_section_name (sec), name) == 0))
5148
      return COFF_SYMBOL_PE_SECTION;
5149
  }
5150
#endif
5151
5152
      return COFF_SYMBOL_LOCAL;
5153
    }
5154
5155
  if (syment->n_sclass == C_SECTION)
5156
    {
5157
      /* In some cases in a DLL generated by the Microsoft linker, the
5158
   n_value field will contain garbage.  FIXME: This should
5159
   probably be handled by the swapping function instead.  */
5160
      syment->n_value = 0;
5161
      if (syment->n_scnum == 0)
5162
  return COFF_SYMBOL_UNDEFINED;
5163
      return COFF_SYMBOL_PE_SECTION;
5164
    }
5165
#endif /* COFF_WITH_PE */
5166
5167
  /* If it is not a global symbol, we presume it is a local symbol.  */
5168
0
  if (syment->n_scnum == 0)
5169
0
    {
5170
0
      char buf[SYMNMLEN + 1];
5171
5172
0
      _bfd_error_handler
5173
  /* xgettext:c-format */
5174
0
  (_("warning: %pB: local symbol `%s' has no section"),
5175
0
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5176
0
    }
5177
5178
0
  return COFF_SYMBOL_LOCAL;
5179
43.3k
}
coff-sh.c:coff_classify_symbol
Line
Count
Source
5085
13.6k
{
5086
  /* FIXME: This partially duplicates the switch in
5087
     coff_slurp_symbol_table.  */
5088
13.6k
  switch (syment->n_sclass)
5089
13.6k
    {
5090
12.8k
    case C_EXT:
5091
13.1k
    case C_WEAKEXT:
5092
#ifdef ARM
5093
    case C_THUMBEXT:
5094
    case C_THUMBEXTFUNC:
5095
#endif
5096
#ifdef RS6000COFF_C
5097
    case C_HIDEXT:
5098
#ifndef AIX_WEAK_SUPPORT
5099
    case C_AIX_WEAKEXT:
5100
#endif
5101
#endif
5102
13.1k
#ifdef C_SYSTEM
5103
13.6k
    case C_SYSTEM:
5104
13.6k
#endif
5105
#ifdef COFF_WITH_PE
5106
    case C_NT_WEAK:
5107
#endif
5108
13.6k
      if (syment->n_scnum == 0)
5109
1.79k
  {
5110
1.79k
    if (syment->n_value == 0)
5111
125
      return COFF_SYMBOL_UNDEFINED;
5112
1.66k
    else
5113
1.66k
      return COFF_SYMBOL_COMMON;
5114
1.79k
  }
5115
#ifdef RS6000COFF_C
5116
      if (syment->n_sclass == C_HIDEXT)
5117
  return COFF_SYMBOL_LOCAL;
5118
#endif
5119
11.8k
      return COFF_SYMBOL_GLOBAL;
5120
5121
0
    default:
5122
0
      break;
5123
13.6k
    }
5124
5125
#ifdef COFF_WITH_PE
5126
  if (syment->n_sclass == C_STAT)
5127
    {
5128
      if (syment->n_scnum == 0)
5129
  /* The Microsoft compiler sometimes generates these if a
5130
     small static function is inlined every time it is used.
5131
     The function is discarded, but the symbol table entry
5132
     remains.  */
5133
  return COFF_SYMBOL_LOCAL;
5134
5135
#ifdef STRICT_PE_FORMAT
5136
      /* This is correct for Microsoft generated objects, but it
5137
   breaks gas generated objects.  */
5138
      if (syment->n_value == 0)
5139
  {
5140
    const asection *sec;
5141
    const char *name;
5142
    char buf[SYMNMLEN + 1];
5143
5144
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5145
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5146
    if (sec != NULL && name != NULL
5147
        && (strcmp (bfd_section_name (sec), name) == 0))
5148
      return COFF_SYMBOL_PE_SECTION;
5149
  }
5150
#endif
5151
5152
      return COFF_SYMBOL_LOCAL;
5153
    }
5154
5155
  if (syment->n_sclass == C_SECTION)
5156
    {
5157
      /* In some cases in a DLL generated by the Microsoft linker, the
5158
   n_value field will contain garbage.  FIXME: This should
5159
   probably be handled by the swapping function instead.  */
5160
      syment->n_value = 0;
5161
      if (syment->n_scnum == 0)
5162
  return COFF_SYMBOL_UNDEFINED;
5163
      return COFF_SYMBOL_PE_SECTION;
5164
    }
5165
#endif /* COFF_WITH_PE */
5166
5167
  /* If it is not a global symbol, we presume it is a local symbol.  */
5168
0
  if (syment->n_scnum == 0)
5169
0
    {
5170
0
      char buf[SYMNMLEN + 1];
5171
5172
0
      _bfd_error_handler
5173
  /* xgettext:c-format */
5174
0
  (_("warning: %pB: local symbol `%s' has no section"),
5175
0
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5176
0
    }
5177
5178
0
  return COFF_SYMBOL_LOCAL;
5179
13.6k
}
Unexecuted instantiation: coff-stgo32.c:coff_classify_symbol
coff-tic30.c:coff_classify_symbol
Line
Count
Source
5085
3.75k
{
5086
  /* FIXME: This partially duplicates the switch in
5087
     coff_slurp_symbol_table.  */
5088
3.75k
  switch (syment->n_sclass)
5089
3.75k
    {
5090
2.99k
    case C_EXT:
5091
3.34k
    case C_WEAKEXT:
5092
#ifdef ARM
5093
    case C_THUMBEXT:
5094
    case C_THUMBEXTFUNC:
5095
#endif
5096
#ifdef RS6000COFF_C
5097
    case C_HIDEXT:
5098
#ifndef AIX_WEAK_SUPPORT
5099
    case C_AIX_WEAKEXT:
5100
#endif
5101
#endif
5102
3.34k
#ifdef C_SYSTEM
5103
3.75k
    case C_SYSTEM:
5104
3.75k
#endif
5105
#ifdef COFF_WITH_PE
5106
    case C_NT_WEAK:
5107
#endif
5108
3.75k
      if (syment->n_scnum == 0)
5109
1.09k
  {
5110
1.09k
    if (syment->n_value == 0)
5111
152
      return COFF_SYMBOL_UNDEFINED;
5112
938
    else
5113
938
      return COFF_SYMBOL_COMMON;
5114
1.09k
  }
5115
#ifdef RS6000COFF_C
5116
      if (syment->n_sclass == C_HIDEXT)
5117
  return COFF_SYMBOL_LOCAL;
5118
#endif
5119
2.66k
      return COFF_SYMBOL_GLOBAL;
5120
5121
0
    default:
5122
0
      break;
5123
3.75k
    }
5124
5125
#ifdef COFF_WITH_PE
5126
  if (syment->n_sclass == C_STAT)
5127
    {
5128
      if (syment->n_scnum == 0)
5129
  /* The Microsoft compiler sometimes generates these if a
5130
     small static function is inlined every time it is used.
5131
     The function is discarded, but the symbol table entry
5132
     remains.  */
5133
  return COFF_SYMBOL_LOCAL;
5134
5135
#ifdef STRICT_PE_FORMAT
5136
      /* This is correct for Microsoft generated objects, but it
5137
   breaks gas generated objects.  */
5138
      if (syment->n_value == 0)
5139
  {
5140
    const asection *sec;
5141
    const char *name;
5142
    char buf[SYMNMLEN + 1];
5143
5144
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5145
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5146
    if (sec != NULL && name != NULL
5147
        && (strcmp (bfd_section_name (sec), name) == 0))
5148
      return COFF_SYMBOL_PE_SECTION;
5149
  }
5150
#endif
5151
5152
      return COFF_SYMBOL_LOCAL;
5153
    }
5154
5155
  if (syment->n_sclass == C_SECTION)
5156
    {
5157
      /* In some cases in a DLL generated by the Microsoft linker, the
5158
   n_value field will contain garbage.  FIXME: This should
5159
   probably be handled by the swapping function instead.  */
5160
      syment->n_value = 0;
5161
      if (syment->n_scnum == 0)
5162
  return COFF_SYMBOL_UNDEFINED;
5163
      return COFF_SYMBOL_PE_SECTION;
5164
    }
5165
#endif /* COFF_WITH_PE */
5166
5167
  /* If it is not a global symbol, we presume it is a local symbol.  */
5168
0
  if (syment->n_scnum == 0)
5169
0
    {
5170
0
      char buf[SYMNMLEN + 1];
5171
5172
0
      _bfd_error_handler
5173
  /* xgettext:c-format */
5174
0
  (_("warning: %pB: local symbol `%s' has no section"),
5175
0
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5176
0
    }
5177
5178
0
  return COFF_SYMBOL_LOCAL;
5179
3.75k
}
Unexecuted instantiation: coff-tic4x.c:coff_classify_symbol
coff-tic54x.c:coff_classify_symbol
Line
Count
Source
5085
7.08k
{
5086
  /* FIXME: This partially duplicates the switch in
5087
     coff_slurp_symbol_table.  */
5088
7.08k
  switch (syment->n_sclass)
5089
7.08k
    {
5090
6.03k
    case C_EXT:
5091
6.29k
    case C_WEAKEXT:
5092
#ifdef ARM
5093
    case C_THUMBEXT:
5094
    case C_THUMBEXTFUNC:
5095
#endif
5096
#ifdef RS6000COFF_C
5097
    case C_HIDEXT:
5098
#ifndef AIX_WEAK_SUPPORT
5099
    case C_AIX_WEAKEXT:
5100
#endif
5101
#endif
5102
6.29k
#ifdef C_SYSTEM
5103
7.08k
    case C_SYSTEM:
5104
7.08k
#endif
5105
#ifdef COFF_WITH_PE
5106
    case C_NT_WEAK:
5107
#endif
5108
7.08k
      if (syment->n_scnum == 0)
5109
1.57k
  {
5110
1.57k
    if (syment->n_value == 0)
5111
333
      return COFF_SYMBOL_UNDEFINED;
5112
1.24k
    else
5113
1.24k
      return COFF_SYMBOL_COMMON;
5114
1.57k
  }
5115
#ifdef RS6000COFF_C
5116
      if (syment->n_sclass == C_HIDEXT)
5117
  return COFF_SYMBOL_LOCAL;
5118
#endif
5119
5.51k
      return COFF_SYMBOL_GLOBAL;
5120
5121
0
    default:
5122
0
      break;
5123
7.08k
    }
5124
5125
#ifdef COFF_WITH_PE
5126
  if (syment->n_sclass == C_STAT)
5127
    {
5128
      if (syment->n_scnum == 0)
5129
  /* The Microsoft compiler sometimes generates these if a
5130
     small static function is inlined every time it is used.
5131
     The function is discarded, but the symbol table entry
5132
     remains.  */
5133
  return COFF_SYMBOL_LOCAL;
5134
5135
#ifdef STRICT_PE_FORMAT
5136
      /* This is correct for Microsoft generated objects, but it
5137
   breaks gas generated objects.  */
5138
      if (syment->n_value == 0)
5139
  {
5140
    const asection *sec;
5141
    const char *name;
5142
    char buf[SYMNMLEN + 1];
5143
5144
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5145
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5146
    if (sec != NULL && name != NULL
5147
        && (strcmp (bfd_section_name (sec), name) == 0))
5148
      return COFF_SYMBOL_PE_SECTION;
5149
  }
5150
#endif
5151
5152
      return COFF_SYMBOL_LOCAL;
5153
    }
5154
5155
  if (syment->n_sclass == C_SECTION)
5156
    {
5157
      /* In some cases in a DLL generated by the Microsoft linker, the
5158
   n_value field will contain garbage.  FIXME: This should
5159
   probably be handled by the swapping function instead.  */
5160
      syment->n_value = 0;
5161
      if (syment->n_scnum == 0)
5162
  return COFF_SYMBOL_UNDEFINED;
5163
      return COFF_SYMBOL_PE_SECTION;
5164
    }
5165
#endif /* COFF_WITH_PE */
5166
5167
  /* If it is not a global symbol, we presume it is a local symbol.  */
5168
0
  if (syment->n_scnum == 0)
5169
0
    {
5170
0
      char buf[SYMNMLEN + 1];
5171
5172
0
      _bfd_error_handler
5173
  /* xgettext:c-format */
5174
0
  (_("warning: %pB: local symbol `%s' has no section"),
5175
0
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5176
0
    }
5177
5178
0
  return COFF_SYMBOL_LOCAL;
5179
7.08k
}
coff-z80.c:coff_classify_symbol
Line
Count
Source
5085
3.84k
{
5086
  /* FIXME: This partially duplicates the switch in
5087
     coff_slurp_symbol_table.  */
5088
3.84k
  switch (syment->n_sclass)
5089
3.84k
    {
5090
3.28k
    case C_EXT:
5091
3.52k
    case C_WEAKEXT:
5092
#ifdef ARM
5093
    case C_THUMBEXT:
5094
    case C_THUMBEXTFUNC:
5095
#endif
5096
#ifdef RS6000COFF_C
5097
    case C_HIDEXT:
5098
#ifndef AIX_WEAK_SUPPORT
5099
    case C_AIX_WEAKEXT:
5100
#endif
5101
#endif
5102
3.52k
#ifdef C_SYSTEM
5103
3.84k
    case C_SYSTEM:
5104
3.84k
#endif
5105
#ifdef COFF_WITH_PE
5106
    case C_NT_WEAK:
5107
#endif
5108
3.84k
      if (syment->n_scnum == 0)
5109
890
  {
5110
890
    if (syment->n_value == 0)
5111
314
      return COFF_SYMBOL_UNDEFINED;
5112
576
    else
5113
576
      return COFF_SYMBOL_COMMON;
5114
890
  }
5115
#ifdef RS6000COFF_C
5116
      if (syment->n_sclass == C_HIDEXT)
5117
  return COFF_SYMBOL_LOCAL;
5118
#endif
5119
2.95k
      return COFF_SYMBOL_GLOBAL;
5120
5121
0
    default:
5122
0
      break;
5123
3.84k
    }
5124
5125
#ifdef COFF_WITH_PE
5126
  if (syment->n_sclass == C_STAT)
5127
    {
5128
      if (syment->n_scnum == 0)
5129
  /* The Microsoft compiler sometimes generates these if a
5130
     small static function is inlined every time it is used.
5131
     The function is discarded, but the symbol table entry
5132
     remains.  */
5133
  return COFF_SYMBOL_LOCAL;
5134
5135
#ifdef STRICT_PE_FORMAT
5136
      /* This is correct for Microsoft generated objects, but it
5137
   breaks gas generated objects.  */
5138
      if (syment->n_value == 0)
5139
  {
5140
    const asection *sec;
5141
    const char *name;
5142
    char buf[SYMNMLEN + 1];
5143
5144
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5145
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5146
    if (sec != NULL && name != NULL
5147
        && (strcmp (bfd_section_name (sec), name) == 0))
5148
      return COFF_SYMBOL_PE_SECTION;
5149
  }
5150
#endif
5151
5152
      return COFF_SYMBOL_LOCAL;
5153
    }
5154
5155
  if (syment->n_sclass == C_SECTION)
5156
    {
5157
      /* In some cases in a DLL generated by the Microsoft linker, the
5158
   n_value field will contain garbage.  FIXME: This should
5159
   probably be handled by the swapping function instead.  */
5160
      syment->n_value = 0;
5161
      if (syment->n_scnum == 0)
5162
  return COFF_SYMBOL_UNDEFINED;
5163
      return COFF_SYMBOL_PE_SECTION;
5164
    }
5165
#endif /* COFF_WITH_PE */
5166
5167
  /* If it is not a global symbol, we presume it is a local symbol.  */
5168
0
  if (syment->n_scnum == 0)
5169
0
    {
5170
0
      char buf[SYMNMLEN + 1];
5171
5172
0
      _bfd_error_handler
5173
  /* xgettext:c-format */
5174
0
  (_("warning: %pB: local symbol `%s' has no section"),
5175
0
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5176
0
    }
5177
5178
0
  return COFF_SYMBOL_LOCAL;
5179
3.84k
}
coff-z8k.c:coff_classify_symbol
Line
Count
Source
5085
7.09k
{
5086
  /* FIXME: This partially duplicates the switch in
5087
     coff_slurp_symbol_table.  */
5088
7.09k
  switch (syment->n_sclass)
5089
7.09k
    {
5090
4.32k
    case C_EXT:
5091
4.90k
    case C_WEAKEXT:
5092
#ifdef ARM
5093
    case C_THUMBEXT:
5094
    case C_THUMBEXTFUNC:
5095
#endif
5096
#ifdef RS6000COFF_C
5097
    case C_HIDEXT:
5098
#ifndef AIX_WEAK_SUPPORT
5099
    case C_AIX_WEAKEXT:
5100
#endif
5101
#endif
5102
4.90k
#ifdef C_SYSTEM
5103
7.09k
    case C_SYSTEM:
5104
7.09k
#endif
5105
#ifdef COFF_WITH_PE
5106
    case C_NT_WEAK:
5107
#endif
5108
7.09k
      if (syment->n_scnum == 0)
5109
1.49k
  {
5110
1.49k
    if (syment->n_value == 0)
5111
226
      return COFF_SYMBOL_UNDEFINED;
5112
1.27k
    else
5113
1.27k
      return COFF_SYMBOL_COMMON;
5114
1.49k
  }
5115
#ifdef RS6000COFF_C
5116
      if (syment->n_sclass == C_HIDEXT)
5117
  return COFF_SYMBOL_LOCAL;
5118
#endif
5119
5.60k
      return COFF_SYMBOL_GLOBAL;
5120
5121
0
    default:
5122
0
      break;
5123
7.09k
    }
5124
5125
#ifdef COFF_WITH_PE
5126
  if (syment->n_sclass == C_STAT)
5127
    {
5128
      if (syment->n_scnum == 0)
5129
  /* The Microsoft compiler sometimes generates these if a
5130
     small static function is inlined every time it is used.
5131
     The function is discarded, but the symbol table entry
5132
     remains.  */
5133
  return COFF_SYMBOL_LOCAL;
5134
5135
#ifdef STRICT_PE_FORMAT
5136
      /* This is correct for Microsoft generated objects, but it
5137
   breaks gas generated objects.  */
5138
      if (syment->n_value == 0)
5139
  {
5140
    const asection *sec;
5141
    const char *name;
5142
    char buf[SYMNMLEN + 1];
5143
5144
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5145
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5146
    if (sec != NULL && name != NULL
5147
        && (strcmp (bfd_section_name (sec), name) == 0))
5148
      return COFF_SYMBOL_PE_SECTION;
5149
  }
5150
#endif
5151
5152
      return COFF_SYMBOL_LOCAL;
5153
    }
5154
5155
  if (syment->n_sclass == C_SECTION)
5156
    {
5157
      /* In some cases in a DLL generated by the Microsoft linker, the
5158
   n_value field will contain garbage.  FIXME: This should
5159
   probably be handled by the swapping function instead.  */
5160
      syment->n_value = 0;
5161
      if (syment->n_scnum == 0)
5162
  return COFF_SYMBOL_UNDEFINED;
5163
      return COFF_SYMBOL_PE_SECTION;
5164
    }
5165
#endif /* COFF_WITH_PE */
5166
5167
  /* If it is not a global symbol, we presume it is a local symbol.  */
5168
0
  if (syment->n_scnum == 0)
5169
0
    {
5170
0
      char buf[SYMNMLEN + 1];
5171
5172
0
      _bfd_error_handler
5173
  /* xgettext:c-format */
5174
0
  (_("warning: %pB: local symbol `%s' has no section"),
5175
0
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5176
0
    }
5177
5178
0
  return COFF_SYMBOL_LOCAL;
5179
7.09k
}
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
5085
14.0k
{
5086
  /* FIXME: This partially duplicates the switch in
5087
     coff_slurp_symbol_table.  */
5088
14.0k
  switch (syment->n_sclass)
5089
14.0k
    {
5090
6.64k
    case C_EXT:
5091
6.86k
    case C_WEAKEXT:
5092
#ifdef ARM
5093
    case C_THUMBEXT:
5094
    case C_THUMBEXTFUNC:
5095
#endif
5096
#ifdef RS6000COFF_C
5097
    case C_HIDEXT:
5098
#ifndef AIX_WEAK_SUPPORT
5099
    case C_AIX_WEAKEXT:
5100
#endif
5101
#endif
5102
6.86k
#ifdef C_SYSTEM
5103
10.0k
    case C_SYSTEM:
5104
10.0k
#endif
5105
10.0k
#ifdef COFF_WITH_PE
5106
13.9k
    case C_NT_WEAK:
5107
13.9k
#endif
5108
13.9k
      if (syment->n_scnum == 0)
5109
1.31k
  {
5110
1.31k
    if (syment->n_value == 0)
5111
327
      return COFF_SYMBOL_UNDEFINED;
5112
989
    else
5113
989
      return COFF_SYMBOL_COMMON;
5114
1.31k
  }
5115
#ifdef RS6000COFF_C
5116
      if (syment->n_sclass == C_HIDEXT)
5117
  return COFF_SYMBOL_LOCAL;
5118
#endif
5119
12.6k
      return COFF_SYMBOL_GLOBAL;
5120
5121
62
    default:
5122
62
      break;
5123
14.0k
    }
5124
5125
62
#ifdef COFF_WITH_PE
5126
62
  if (syment->n_sclass == C_STAT)
5127
0
    {
5128
0
      if (syment->n_scnum == 0)
5129
  /* The Microsoft compiler sometimes generates these if a
5130
     small static function is inlined every time it is used.
5131
     The function is discarded, but the symbol table entry
5132
     remains.  */
5133
0
  return COFF_SYMBOL_LOCAL;
5134
5135
#ifdef STRICT_PE_FORMAT
5136
      /* This is correct for Microsoft generated objects, but it
5137
   breaks gas generated objects.  */
5138
      if (syment->n_value == 0)
5139
  {
5140
    const asection *sec;
5141
    const char *name;
5142
    char buf[SYMNMLEN + 1];
5143
5144
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5145
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5146
    if (sec != NULL && name != NULL
5147
        && (strcmp (bfd_section_name (sec), name) == 0))
5148
      return COFF_SYMBOL_PE_SECTION;
5149
  }
5150
#endif
5151
5152
0
      return COFF_SYMBOL_LOCAL;
5153
0
    }
5154
5155
62
  if (syment->n_sclass == C_SECTION)
5156
62
    {
5157
      /* In some cases in a DLL generated by the Microsoft linker, the
5158
   n_value field will contain garbage.  FIXME: This should
5159
   probably be handled by the swapping function instead.  */
5160
62
      syment->n_value = 0;
5161
62
      if (syment->n_scnum == 0)
5162
62
  return COFF_SYMBOL_UNDEFINED;
5163
0
      return COFF_SYMBOL_PE_SECTION;
5164
62
    }
5165
0
#endif /* COFF_WITH_PE */
5166
5167
  /* If it is not a global symbol, we presume it is a local symbol.  */
5168
0
  if (syment->n_scnum == 0)
5169
0
    {
5170
0
      char buf[SYMNMLEN + 1];
5171
5172
0
      _bfd_error_handler
5173
  /* xgettext:c-format */
5174
0
  (_("warning: %pB: local symbol `%s' has no section"),
5175
0
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5176
0
    }
5177
5178
0
  return COFF_SYMBOL_LOCAL;
5179
62
}
pe-mcore.c:coff_classify_symbol
Line
Count
Source
5085
12.3k
{
5086
  /* FIXME: This partially duplicates the switch in
5087
     coff_slurp_symbol_table.  */
5088
12.3k
  switch (syment->n_sclass)
5089
12.3k
    {
5090
6.72k
    case C_EXT:
5091
7.14k
    case C_WEAKEXT:
5092
#ifdef ARM
5093
    case C_THUMBEXT:
5094
    case C_THUMBEXTFUNC:
5095
#endif
5096
#ifdef RS6000COFF_C
5097
    case C_HIDEXT:
5098
#ifndef AIX_WEAK_SUPPORT
5099
    case C_AIX_WEAKEXT:
5100
#endif
5101
#endif
5102
7.14k
#ifdef C_SYSTEM
5103
8.70k
    case C_SYSTEM:
5104
8.70k
#endif
5105
8.70k
#ifdef COFF_WITH_PE
5106
12.2k
    case C_NT_WEAK:
5107
12.2k
#endif
5108
12.2k
      if (syment->n_scnum == 0)
5109
1.14k
  {
5110
1.14k
    if (syment->n_value == 0)
5111
279
      return COFF_SYMBOL_UNDEFINED;
5112
867
    else
5113
867
      return COFF_SYMBOL_COMMON;
5114
1.14k
  }
5115
#ifdef RS6000COFF_C
5116
      if (syment->n_sclass == C_HIDEXT)
5117
  return COFF_SYMBOL_LOCAL;
5118
#endif
5119
11.0k
      return COFF_SYMBOL_GLOBAL;
5120
5121
129
    default:
5122
129
      break;
5123
12.3k
    }
5124
5125
129
#ifdef COFF_WITH_PE
5126
129
  if (syment->n_sclass == C_STAT)
5127
0
    {
5128
0
      if (syment->n_scnum == 0)
5129
  /* The Microsoft compiler sometimes generates these if a
5130
     small static function is inlined every time it is used.
5131
     The function is discarded, but the symbol table entry
5132
     remains.  */
5133
0
  return COFF_SYMBOL_LOCAL;
5134
5135
#ifdef STRICT_PE_FORMAT
5136
      /* This is correct for Microsoft generated objects, but it
5137
   breaks gas generated objects.  */
5138
      if (syment->n_value == 0)
5139
  {
5140
    const asection *sec;
5141
    const char *name;
5142
    char buf[SYMNMLEN + 1];
5143
5144
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5145
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5146
    if (sec != NULL && name != NULL
5147
        && (strcmp (bfd_section_name (sec), name) == 0))
5148
      return COFF_SYMBOL_PE_SECTION;
5149
  }
5150
#endif
5151
5152
0
      return COFF_SYMBOL_LOCAL;
5153
0
    }
5154
5155
129
  if (syment->n_sclass == C_SECTION)
5156
129
    {
5157
      /* In some cases in a DLL generated by the Microsoft linker, the
5158
   n_value field will contain garbage.  FIXME: This should
5159
   probably be handled by the swapping function instead.  */
5160
129
      syment->n_value = 0;
5161
129
      if (syment->n_scnum == 0)
5162
129
  return COFF_SYMBOL_UNDEFINED;
5163
0
      return COFF_SYMBOL_PE_SECTION;
5164
129
    }
5165
0
#endif /* COFF_WITH_PE */
5166
5167
  /* If it is not a global symbol, we presume it is a local symbol.  */
5168
0
  if (syment->n_scnum == 0)
5169
0
    {
5170
0
      char buf[SYMNMLEN + 1];
5171
5172
0
      _bfd_error_handler
5173
  /* xgettext:c-format */
5174
0
  (_("warning: %pB: local symbol `%s' has no section"),
5175
0
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5176
0
    }
5177
5178
0
  return COFF_SYMBOL_LOCAL;
5179
129
}
pe-sh.c:coff_classify_symbol
Line
Count
Source
5085
11.8k
{
5086
  /* FIXME: This partially duplicates the switch in
5087
     coff_slurp_symbol_table.  */
5088
11.8k
  switch (syment->n_sclass)
5089
11.8k
    {
5090
6.42k
    case C_EXT:
5091
6.81k
    case C_WEAKEXT:
5092
#ifdef ARM
5093
    case C_THUMBEXT:
5094
    case C_THUMBEXTFUNC:
5095
#endif
5096
#ifdef RS6000COFF_C
5097
    case C_HIDEXT:
5098
#ifndef AIX_WEAK_SUPPORT
5099
    case C_AIX_WEAKEXT:
5100
#endif
5101
#endif
5102
6.81k
#ifdef C_SYSTEM
5103
8.22k
    case C_SYSTEM:
5104
8.22k
#endif
5105
8.22k
#ifdef COFF_WITH_PE
5106
11.7k
    case C_NT_WEAK:
5107
11.7k
#endif
5108
11.7k
      if (syment->n_scnum == 0)
5109
1.13k
  {
5110
1.13k
    if (syment->n_value == 0)
5111
313
      return COFF_SYMBOL_UNDEFINED;
5112
818
    else
5113
818
      return COFF_SYMBOL_COMMON;
5114
1.13k
  }
5115
#ifdef RS6000COFF_C
5116
      if (syment->n_sclass == C_HIDEXT)
5117
  return COFF_SYMBOL_LOCAL;
5118
#endif
5119
10.6k
      return COFF_SYMBOL_GLOBAL;
5120
5121
117
    default:
5122
117
      break;
5123
11.8k
    }
5124
5125
117
#ifdef COFF_WITH_PE
5126
117
  if (syment->n_sclass == C_STAT)
5127
0
    {
5128
0
      if (syment->n_scnum == 0)
5129
  /* The Microsoft compiler sometimes generates these if a
5130
     small static function is inlined every time it is used.
5131
     The function is discarded, but the symbol table entry
5132
     remains.  */
5133
0
  return COFF_SYMBOL_LOCAL;
5134
5135
#ifdef STRICT_PE_FORMAT
5136
      /* This is correct for Microsoft generated objects, but it
5137
   breaks gas generated objects.  */
5138
      if (syment->n_value == 0)
5139
  {
5140
    const asection *sec;
5141
    const char *name;
5142
    char buf[SYMNMLEN + 1];
5143
5144
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5145
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5146
    if (sec != NULL && name != NULL
5147
        && (strcmp (bfd_section_name (sec), name) == 0))
5148
      return COFF_SYMBOL_PE_SECTION;
5149
  }
5150
#endif
5151
5152
0
      return COFF_SYMBOL_LOCAL;
5153
0
    }
5154
5155
117
  if (syment->n_sclass == C_SECTION)
5156
117
    {
5157
      /* In some cases in a DLL generated by the Microsoft linker, the
5158
   n_value field will contain garbage.  FIXME: This should
5159
   probably be handled by the swapping function instead.  */
5160
117
      syment->n_value = 0;
5161
117
      if (syment->n_scnum == 0)
5162
117
  return COFF_SYMBOL_UNDEFINED;
5163
0
      return COFF_SYMBOL_PE_SECTION;
5164
117
    }
5165
0
#endif /* COFF_WITH_PE */
5166
5167
  /* If it is not a global symbol, we presume it is a local symbol.  */
5168
0
  if (syment->n_scnum == 0)
5169
0
    {
5170
0
      char buf[SYMNMLEN + 1];
5171
5172
0
      _bfd_error_handler
5173
  /* xgettext:c-format */
5174
0
  (_("warning: %pB: local symbol `%s' has no section"),
5175
0
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5176
0
    }
5177
5178
0
  return COFF_SYMBOL_LOCAL;
5179
117
}
pei-arm-wince.c:coff_classify_symbol
Line
Count
Source
5085
4.70k
{
5086
  /* FIXME: This partially duplicates the switch in
5087
     coff_slurp_symbol_table.  */
5088
4.70k
  switch (syment->n_sclass)
5089
4.70k
    {
5090
2.21k
    case C_EXT:
5091
2.32k
    case C_WEAKEXT:
5092
2.32k
#ifdef ARM
5093
2.37k
    case C_THUMBEXT:
5094
2.40k
    case C_THUMBEXTFUNC:
5095
2.40k
#endif
5096
#ifdef RS6000COFF_C
5097
    case C_HIDEXT:
5098
#ifndef AIX_WEAK_SUPPORT
5099
    case C_AIX_WEAKEXT:
5100
#endif
5101
#endif
5102
2.40k
#ifdef C_SYSTEM
5103
2.97k
    case C_SYSTEM:
5104
2.97k
#endif
5105
2.97k
#ifdef COFF_WITH_PE
5106
4.65k
    case C_NT_WEAK:
5107
4.65k
#endif
5108
4.65k
      if (syment->n_scnum == 0)
5109
517
  {
5110
517
    if (syment->n_value == 0)
5111
229
      return COFF_SYMBOL_UNDEFINED;
5112
288
    else
5113
288
      return COFF_SYMBOL_COMMON;
5114
517
  }
5115
#ifdef RS6000COFF_C
5116
      if (syment->n_sclass == C_HIDEXT)
5117
  return COFF_SYMBOL_LOCAL;
5118
#endif
5119
4.13k
      return COFF_SYMBOL_GLOBAL;
5120
5121
58
    default:
5122
58
      break;
5123
4.70k
    }
5124
5125
58
#ifdef COFF_WITH_PE
5126
58
  if (syment->n_sclass == C_STAT)
5127
0
    {
5128
0
      if (syment->n_scnum == 0)
5129
  /* The Microsoft compiler sometimes generates these if a
5130
     small static function is inlined every time it is used.
5131
     The function is discarded, but the symbol table entry
5132
     remains.  */
5133
0
  return COFF_SYMBOL_LOCAL;
5134
5135
#ifdef STRICT_PE_FORMAT
5136
      /* This is correct for Microsoft generated objects, but it
5137
   breaks gas generated objects.  */
5138
      if (syment->n_value == 0)
5139
  {
5140
    const asection *sec;
5141
    const char *name;
5142
    char buf[SYMNMLEN + 1];
5143
5144
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5145
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5146
    if (sec != NULL && name != NULL
5147
        && (strcmp (bfd_section_name (sec), name) == 0))
5148
      return COFF_SYMBOL_PE_SECTION;
5149
  }
5150
#endif
5151
5152
0
      return COFF_SYMBOL_LOCAL;
5153
0
    }
5154
5155
58
  if (syment->n_sclass == C_SECTION)
5156
58
    {
5157
      /* In some cases in a DLL generated by the Microsoft linker, the
5158
   n_value field will contain garbage.  FIXME: This should
5159
   probably be handled by the swapping function instead.  */
5160
58
      syment->n_value = 0;
5161
58
      if (syment->n_scnum == 0)
5162
58
  return COFF_SYMBOL_UNDEFINED;
5163
0
      return COFF_SYMBOL_PE_SECTION;
5164
58
    }
5165
0
#endif /* COFF_WITH_PE */
5166
5167
  /* If it is not a global symbol, we presume it is a local symbol.  */
5168
0
  if (syment->n_scnum == 0)
5169
0
    {
5170
0
      char buf[SYMNMLEN + 1];
5171
5172
0
      _bfd_error_handler
5173
  /* xgettext:c-format */
5174
0
  (_("warning: %pB: local symbol `%s' has no section"),
5175
0
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5176
0
    }
5177
5178
0
  return COFF_SYMBOL_LOCAL;
5179
58
}
pei-arm.c:coff_classify_symbol
Line
Count
Source
5085
4.78k
{
5086
  /* FIXME: This partially duplicates the switch in
5087
     coff_slurp_symbol_table.  */
5088
4.78k
  switch (syment->n_sclass)
5089
4.78k
    {
5090
2.36k
    case C_EXT:
5091
2.47k
    case C_WEAKEXT:
5092
2.47k
#ifdef ARM
5093
2.53k
    case C_THUMBEXT:
5094
2.57k
    case C_THUMBEXTFUNC:
5095
2.57k
#endif
5096
#ifdef RS6000COFF_C
5097
    case C_HIDEXT:
5098
#ifndef AIX_WEAK_SUPPORT
5099
    case C_AIX_WEAKEXT:
5100
#endif
5101
#endif
5102
2.57k
#ifdef C_SYSTEM
5103
3.03k
    case C_SYSTEM:
5104
3.03k
#endif
5105
3.03k
#ifdef COFF_WITH_PE
5106
4.67k
    case C_NT_WEAK:
5107
4.67k
#endif
5108
4.67k
      if (syment->n_scnum == 0)
5109
412
  {
5110
412
    if (syment->n_value == 0)
5111
139
      return COFF_SYMBOL_UNDEFINED;
5112
273
    else
5113
273
      return COFF_SYMBOL_COMMON;
5114
412
  }
5115
#ifdef RS6000COFF_C
5116
      if (syment->n_sclass == C_HIDEXT)
5117
  return COFF_SYMBOL_LOCAL;
5118
#endif
5119
4.26k
      return COFF_SYMBOL_GLOBAL;
5120
5121
101
    default:
5122
101
      break;
5123
4.78k
    }
5124
5125
101
#ifdef COFF_WITH_PE
5126
101
  if (syment->n_sclass == C_STAT)
5127
0
    {
5128
0
      if (syment->n_scnum == 0)
5129
  /* The Microsoft compiler sometimes generates these if a
5130
     small static function is inlined every time it is used.
5131
     The function is discarded, but the symbol table entry
5132
     remains.  */
5133
0
  return COFF_SYMBOL_LOCAL;
5134
5135
#ifdef STRICT_PE_FORMAT
5136
      /* This is correct for Microsoft generated objects, but it
5137
   breaks gas generated objects.  */
5138
      if (syment->n_value == 0)
5139
  {
5140
    const asection *sec;
5141
    const char *name;
5142
    char buf[SYMNMLEN + 1];
5143
5144
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5145
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5146
    if (sec != NULL && name != NULL
5147
        && (strcmp (bfd_section_name (sec), name) == 0))
5148
      return COFF_SYMBOL_PE_SECTION;
5149
  }
5150
#endif
5151
5152
0
      return COFF_SYMBOL_LOCAL;
5153
0
    }
5154
5155
101
  if (syment->n_sclass == C_SECTION)
5156
101
    {
5157
      /* In some cases in a DLL generated by the Microsoft linker, the
5158
   n_value field will contain garbage.  FIXME: This should
5159
   probably be handled by the swapping function instead.  */
5160
101
      syment->n_value = 0;
5161
101
      if (syment->n_scnum == 0)
5162
101
  return COFF_SYMBOL_UNDEFINED;
5163
0
      return COFF_SYMBOL_PE_SECTION;
5164
101
    }
5165
0
#endif /* COFF_WITH_PE */
5166
5167
  /* If it is not a global symbol, we presume it is a local symbol.  */
5168
0
  if (syment->n_scnum == 0)
5169
0
    {
5170
0
      char buf[SYMNMLEN + 1];
5171
5172
0
      _bfd_error_handler
5173
  /* xgettext:c-format */
5174
0
  (_("warning: %pB: local symbol `%s' has no section"),
5175
0
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5176
0
    }
5177
5178
0
  return COFF_SYMBOL_LOCAL;
5179
101
}
pei-mcore.c:coff_classify_symbol
Line
Count
Source
5085
4.65k
{
5086
  /* FIXME: This partially duplicates the switch in
5087
     coff_slurp_symbol_table.  */
5088
4.65k
  switch (syment->n_sclass)
5089
4.65k
    {
5090
1.86k
    case C_EXT:
5091
2.22k
    case C_WEAKEXT:
5092
#ifdef ARM
5093
    case C_THUMBEXT:
5094
    case C_THUMBEXTFUNC:
5095
#endif
5096
#ifdef RS6000COFF_C
5097
    case C_HIDEXT:
5098
#ifndef AIX_WEAK_SUPPORT
5099
    case C_AIX_WEAKEXT:
5100
#endif
5101
#endif
5102
2.22k
#ifdef C_SYSTEM
5103
2.53k
    case C_SYSTEM:
5104
2.53k
#endif
5105
2.53k
#ifdef COFF_WITH_PE
5106
4.58k
    case C_NT_WEAK:
5107
4.58k
#endif
5108
4.58k
      if (syment->n_scnum == 0)
5109
500
  {
5110
500
    if (syment->n_value == 0)
5111
113
      return COFF_SYMBOL_UNDEFINED;
5112
387
    else
5113
387
      return COFF_SYMBOL_COMMON;
5114
500
  }
5115
#ifdef RS6000COFF_C
5116
      if (syment->n_sclass == C_HIDEXT)
5117
  return COFF_SYMBOL_LOCAL;
5118
#endif
5119
4.08k
      return COFF_SYMBOL_GLOBAL;
5120
5121
68
    default:
5122
68
      break;
5123
4.65k
    }
5124
5125
68
#ifdef COFF_WITH_PE
5126
68
  if (syment->n_sclass == C_STAT)
5127
0
    {
5128
0
      if (syment->n_scnum == 0)
5129
  /* The Microsoft compiler sometimes generates these if a
5130
     small static function is inlined every time it is used.
5131
     The function is discarded, but the symbol table entry
5132
     remains.  */
5133
0
  return COFF_SYMBOL_LOCAL;
5134
5135
#ifdef STRICT_PE_FORMAT
5136
      /* This is correct for Microsoft generated objects, but it
5137
   breaks gas generated objects.  */
5138
      if (syment->n_value == 0)
5139
  {
5140
    const asection *sec;
5141
    const char *name;
5142
    char buf[SYMNMLEN + 1];
5143
5144
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5145
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5146
    if (sec != NULL && name != NULL
5147
        && (strcmp (bfd_section_name (sec), name) == 0))
5148
      return COFF_SYMBOL_PE_SECTION;
5149
  }
5150
#endif
5151
5152
0
      return COFF_SYMBOL_LOCAL;
5153
0
    }
5154
5155
68
  if (syment->n_sclass == C_SECTION)
5156
68
    {
5157
      /* In some cases in a DLL generated by the Microsoft linker, the
5158
   n_value field will contain garbage.  FIXME: This should
5159
   probably be handled by the swapping function instead.  */
5160
68
      syment->n_value = 0;
5161
68
      if (syment->n_scnum == 0)
5162
68
  return COFF_SYMBOL_UNDEFINED;
5163
0
      return COFF_SYMBOL_PE_SECTION;
5164
68
    }
5165
0
#endif /* COFF_WITH_PE */
5166
5167
  /* If it is not a global symbol, we presume it is a local symbol.  */
5168
0
  if (syment->n_scnum == 0)
5169
0
    {
5170
0
      char buf[SYMNMLEN + 1];
5171
5172
0
      _bfd_error_handler
5173
  /* xgettext:c-format */
5174
0
  (_("warning: %pB: local symbol `%s' has no section"),
5175
0
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5176
0
    }
5177
5178
0
  return COFF_SYMBOL_LOCAL;
5179
68
}
pei-sh.c:coff_classify_symbol
Line
Count
Source
5085
9.48k
{
5086
  /* FIXME: This partially duplicates the switch in
5087
     coff_slurp_symbol_table.  */
5088
9.48k
  switch (syment->n_sclass)
5089
9.48k
    {
5090
5.05k
    case C_EXT:
5091
5.45k
    case C_WEAKEXT:
5092
#ifdef ARM
5093
    case C_THUMBEXT:
5094
    case C_THUMBEXTFUNC:
5095
#endif
5096
#ifdef RS6000COFF_C
5097
    case C_HIDEXT:
5098
#ifndef AIX_WEAK_SUPPORT
5099
    case C_AIX_WEAKEXT:
5100
#endif
5101
#endif
5102
5.45k
#ifdef C_SYSTEM
5103
6.39k
    case C_SYSTEM:
5104
6.39k
#endif
5105
6.39k
#ifdef COFF_WITH_PE
5106
9.40k
    case C_NT_WEAK:
5107
9.40k
#endif
5108
9.40k
      if (syment->n_scnum == 0)
5109
981
  {
5110
981
    if (syment->n_value == 0)
5111
299
      return COFF_SYMBOL_UNDEFINED;
5112
682
    else
5113
682
      return COFF_SYMBOL_COMMON;
5114
981
  }
5115
#ifdef RS6000COFF_C
5116
      if (syment->n_sclass == C_HIDEXT)
5117
  return COFF_SYMBOL_LOCAL;
5118
#endif
5119
8.42k
      return COFF_SYMBOL_GLOBAL;
5120
5121
82
    default:
5122
82
      break;
5123
9.48k
    }
5124
5125
82
#ifdef COFF_WITH_PE
5126
82
  if (syment->n_sclass == C_STAT)
5127
0
    {
5128
0
      if (syment->n_scnum == 0)
5129
  /* The Microsoft compiler sometimes generates these if a
5130
     small static function is inlined every time it is used.
5131
     The function is discarded, but the symbol table entry
5132
     remains.  */
5133
0
  return COFF_SYMBOL_LOCAL;
5134
5135
#ifdef STRICT_PE_FORMAT
5136
      /* This is correct for Microsoft generated objects, but it
5137
   breaks gas generated objects.  */
5138
      if (syment->n_value == 0)
5139
  {
5140
    const asection *sec;
5141
    const char *name;
5142
    char buf[SYMNMLEN + 1];
5143
5144
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5145
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5146
    if (sec != NULL && name != NULL
5147
        && (strcmp (bfd_section_name (sec), name) == 0))
5148
      return COFF_SYMBOL_PE_SECTION;
5149
  }
5150
#endif
5151
5152
0
      return COFF_SYMBOL_LOCAL;
5153
0
    }
5154
5155
82
  if (syment->n_sclass == C_SECTION)
5156
82
    {
5157
      /* In some cases in a DLL generated by the Microsoft linker, the
5158
   n_value field will contain garbage.  FIXME: This should
5159
   probably be handled by the swapping function instead.  */
5160
82
      syment->n_value = 0;
5161
82
      if (syment->n_scnum == 0)
5162
82
  return COFF_SYMBOL_UNDEFINED;
5163
0
      return COFF_SYMBOL_PE_SECTION;
5164
82
    }
5165
0
#endif /* COFF_WITH_PE */
5166
5167
  /* If it is not a global symbol, we presume it is a local symbol.  */
5168
0
  if (syment->n_scnum == 0)
5169
0
    {
5170
0
      char buf[SYMNMLEN + 1];
5171
5172
0
      _bfd_error_handler
5173
  /* xgettext:c-format */
5174
0
  (_("warning: %pB: local symbol `%s' has no section"),
5175
0
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5176
0
    }
5177
5178
0
  return COFF_SYMBOL_LOCAL;
5179
82
}
5180
5181
/*
5182
SUBSUBSECTION
5183
  Reading relocations
5184
5185
  Coff relocations are easily transformed into the internal BFD form
5186
  (@code{arelent}).
5187
5188
  Reading a coff relocation table is done in the following stages:
5189
5190
  o Read the entire coff relocation table into memory.
5191
5192
  o Process each relocation in turn; first swap it from the
5193
  external to the internal form.
5194
5195
  o Turn the symbol referenced in the relocation's symbol index
5196
  into a pointer into the canonical symbol table.
5197
  This table is the same as the one returned by a call to
5198
  @code{bfd_canonicalize_symtab}. The back end will call that
5199
  routine and save the result if a canonicalization hasn't been done.
5200
5201
  o The reloc index is turned into a pointer to a howto
5202
  structure, in a back end specific way. For instance, the 386
5203
  uses the @code{r_type} to directly produce an index
5204
  into a howto table vector.
5205
5206
  o Note that @code{arelent.addend} for COFF is often not what
5207
  most people understand as a relocation addend, but rather an
5208
  adjustment to the relocation addend stored in section contents
5209
  of relocatable object files.  The value found in section
5210
  contents may also be confusing, depending on both symbol value
5211
  and addend somewhat similar to the field value for a
5212
  final-linked object.  See @code{CALC_ADDEND}.
5213
*/
5214
5215
#ifdef COFF_WITH_PE
5216
1.03k
#define COFF_PE_ADDEND_BIAS(ptr) 0 /* Symbol value not stored in raw data.  */
5217
#else
5218
1.64k
#define COFF_PE_ADDEND_BIAS(ptr) ((ptr)->value)
5219
#endif
5220
5221
#ifndef CALC_ADDEND
5222
#define CALC_ADDEND(abfd, ptr, reloc, cache_ptr)    \
5223
1.36k
  {               \
5224
1.36k
    coff_symbol_type *coffsym = NULL;       \
5225
1.36k
                \
5226
1.36k
    if (ptr && bfd_asymbol_bfd (ptr) != abfd)     \
5227
1.36k
      coffsym = (obj_symbols (abfd)       \
5228
0
     + (cache_ptr->sym_ptr_ptr - symbols));   \
5229
1.36k
    else if (ptr)           \
5230
1.36k
      coffsym = coff_symbol_from (ptr);       \
5231
1.36k
    if (coffsym != NULL            \
5232
1.36k
  && coffsym->native->is_sym        \
5233
1.36k
  && coffsym->native->u.syment.n_scnum == 0)   \
5234
1.36k
      cache_ptr->addend = 0;         \
5235
1.36k
    else if (ptr && bfd_asymbol_bfd (ptr) == abfd    \
5236
962
       && ptr->section != NULL)       \
5237
962
      cache_ptr->addend = - (ptr->section->vma      \
5238
507
           + COFF_PE_ADDEND_BIAS (ptr)); \
5239
962
    else              \
5240
962
      cache_ptr->addend = 0;         \
5241
1.36k
  }
5242
#endif
5243
5244
static bool
5245
coff_slurp_reloc_table (bfd * abfd, sec_ptr asect, asymbol ** symbols)
5246
63.3k
{
5247
63.3k
  bfd_byte *native_relocs;
5248
63.3k
  arelent *reloc_cache;
5249
63.3k
  arelent *cache_ptr;
5250
63.3k
  unsigned int idx;
5251
63.3k
  size_t amt;
5252
5253
63.3k
  if (asect->relocation)
5254
344
    return true;
5255
63.0k
  if (asect->reloc_count == 0)
5256
2.08k
    return true;
5257
60.9k
  if (asect->flags & SEC_CONSTRUCTOR)
5258
0
    return true;
5259
60.9k
  if (!coff_slurp_symbol_table (abfd))
5260
45.8k
    return false;
5261
5262
15.0k
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5263
15.0k
               asect->reloc_count,
5264
15.0k
               bfd_coff_relsz (abfd));
5265
15.0k
  if (native_relocs == NULL)
5266
8.87k
    return false;
5267
5268
6.18k
  if (_bfd_mul_overflow (asect->reloc_count, sizeof (arelent), &amt))
5269
0
    {
5270
0
      bfd_set_error (bfd_error_file_too_big);
5271
0
      return false;
5272
0
    }
5273
6.18k
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5274
6.18k
  if (reloc_cache == NULL)
5275
0
    {
5276
0
      free (native_relocs);
5277
0
      return false;
5278
0
    }
5279
5280
56.8k
  for (idx = 0; idx < asect->reloc_count; idx++)
5281
56.0k
    {
5282
56.0k
      struct internal_reloc dst;
5283
56.0k
      void *src;
5284
#ifndef RELOC_PROCESSING
5285
      asymbol *ptr;
5286
#endif
5287
5288
56.0k
      cache_ptr = reloc_cache + idx;
5289
56.0k
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5290
5291
56.0k
      dst.r_offset = 0;
5292
56.0k
      bfd_coff_swap_reloc_in (abfd, src, &dst);
5293
5294
#ifdef RELOC_PROCESSING
5295
32.8k
      RELOC_PROCESSING (cache_ptr, &dst, symbols, abfd, asect);
5296
#else
5297
      cache_ptr->address = dst.r_vaddr;
5298
5299
23.1k
      if (dst.r_symndx != -1 && symbols != NULL)
5300
14.2k
  {
5301
14.2k
    if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
5302
4.98k
      {
5303
4.98k
        _bfd_error_handler
5304
    /* xgettext:c-format */
5305
4.98k
    (_("%pB: warning: illegal symbol index %ld in relocs"),
5306
4.98k
     abfd, dst.r_symndx);
5307
4.98k
        cache_ptr->sym_ptr_ptr = &bfd_abs_section_ptr->symbol;
5308
4.98k
        ptr = NULL;
5309
4.98k
      }
5310
9.27k
    else
5311
9.27k
      {
5312
9.27k
        cache_ptr->sym_ptr_ptr = (symbols
5313
9.27k
          + obj_convert (abfd)[dst.r_symndx]);
5314
9.27k
        ptr = *(cache_ptr->sym_ptr_ptr);
5315
9.27k
      }
5316
14.2k
  }
5317
8.94k
      else
5318
8.94k
  {
5319
8.94k
    cache_ptr->sym_ptr_ptr = &bfd_abs_section_ptr->symbol;
5320
8.94k
    ptr = NULL;
5321
8.94k
  }
5322
5323
      /* The symbols definitions that we have read in have been
5324
   relocated as if their sections started at 0. But the offsets
5325
   refering to the symbols in the raw data have not been
5326
   modified, so we have to have a negative addend to compensate.
5327
5328
   Note that symbols which used to be common must be left alone.  */
5329
5330
      /* Calculate any reloc addend by looking at the symbol.  */
5331
23.1k
      CALC_ADDEND (abfd, ptr, dst, cache_ptr);
5332
      (void) ptr;
5333
5334
      cache_ptr->address -= asect->vma;
5335
      /* !! cache_ptr->section = NULL;*/
5336
5337
      /* Fill in the cache_ptr->howto field from dst.r_type.  */
5338
23.1k
      RTYPE2HOWTO (cache_ptr, &dst);
5339
#endif  /* RELOC_PROCESSING */
5340
5341
56.0k
      if (cache_ptr->howto == NULL)
5342
5.32k
  {
5343
5.32k
    _bfd_error_handler
5344
      /* xgettext:c-format */
5345
5.32k
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5346
5.32k
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5347
5.32k
    bfd_set_error (bfd_error_bad_value);
5348
5.32k
    free (native_relocs);
5349
5.32k
    return false;
5350
5.32k
  }
5351
56.0k
    }
5352
5353
861
  free (native_relocs);
5354
861
  asect->relocation = reloc_cache;
5355
861
  return true;
5356
6.18k
}
pei-i386.c:coff_slurp_reloc_table
Line
Count
Source
5246
34
{
5247
34
  bfd_byte *native_relocs;
5248
34
  arelent *reloc_cache;
5249
34
  arelent *cache_ptr;
5250
34
  unsigned int idx;
5251
34
  size_t amt;
5252
5253
34
  if (asect->relocation)
5254
29
    return true;
5255
5
  if (asect->reloc_count == 0)
5256
5
    return true;
5257
0
  if (asect->flags & SEC_CONSTRUCTOR)
5258
0
    return true;
5259
0
  if (!coff_slurp_symbol_table (abfd))
5260
0
    return false;
5261
5262
0
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5263
0
               asect->reloc_count,
5264
0
               bfd_coff_relsz (abfd));
5265
0
  if (native_relocs == NULL)
5266
0
    return false;
5267
5268
0
  if (_bfd_mul_overflow (asect->reloc_count, sizeof (arelent), &amt))
5269
0
    {
5270
0
      bfd_set_error (bfd_error_file_too_big);
5271
0
      return false;
5272
0
    }
5273
0
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5274
0
  if (reloc_cache == NULL)
5275
0
    {
5276
0
      free (native_relocs);
5277
0
      return false;
5278
0
    }
5279
5280
0
  for (idx = 0; idx < asect->reloc_count; idx++)
5281
0
    {
5282
0
      struct internal_reloc dst;
5283
0
      void *src;
5284
0
#ifndef RELOC_PROCESSING
5285
0
      asymbol *ptr;
5286
0
#endif
5287
5288
0
      cache_ptr = reloc_cache + idx;
5289
0
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5290
5291
0
      dst.r_offset = 0;
5292
0
      bfd_coff_swap_reloc_in (abfd, src, &dst);
5293
5294
#ifdef RELOC_PROCESSING
5295
      RELOC_PROCESSING (cache_ptr, &dst, symbols, abfd, asect);
5296
#else
5297
0
      cache_ptr->address = dst.r_vaddr;
5298
5299
0
      if (dst.r_symndx != -1 && symbols != NULL)
5300
0
  {
5301
0
    if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
5302
0
      {
5303
0
        _bfd_error_handler
5304
    /* xgettext:c-format */
5305
0
    (_("%pB: warning: illegal symbol index %ld in relocs"),
5306
0
     abfd, dst.r_symndx);
5307
0
        cache_ptr->sym_ptr_ptr = &bfd_abs_section_ptr->symbol;
5308
0
        ptr = NULL;
5309
0
      }
5310
0
    else
5311
0
      {
5312
0
        cache_ptr->sym_ptr_ptr = (symbols
5313
0
          + obj_convert (abfd)[dst.r_symndx]);
5314
0
        ptr = *(cache_ptr->sym_ptr_ptr);
5315
0
      }
5316
0
  }
5317
0
      else
5318
0
  {
5319
0
    cache_ptr->sym_ptr_ptr = &bfd_abs_section_ptr->symbol;
5320
0
    ptr = NULL;
5321
0
  }
5322
5323
      /* The symbols definitions that we have read in have been
5324
   relocated as if their sections started at 0. But the offsets
5325
   refering to the symbols in the raw data have not been
5326
   modified, so we have to have a negative addend to compensate.
5327
5328
   Note that symbols which used to be common must be left alone.  */
5329
5330
      /* Calculate any reloc addend by looking at the symbol.  */
5331
0
      CALC_ADDEND (abfd, ptr, dst, cache_ptr);
5332
0
      (void) ptr;
5333
5334
0
      cache_ptr->address -= asect->vma;
5335
      /* !! cache_ptr->section = NULL;*/
5336
5337
      /* Fill in the cache_ptr->howto field from dst.r_type.  */
5338
0
      RTYPE2HOWTO (cache_ptr, &dst);
5339
0
#endif  /* RELOC_PROCESSING */
5340
5341
0
      if (cache_ptr->howto == NULL)
5342
0
  {
5343
0
    _bfd_error_handler
5344
      /* xgettext:c-format */
5345
0
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5346
0
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5347
0
    bfd_set_error (bfd_error_bad_value);
5348
0
    free (native_relocs);
5349
0
    return false;
5350
0
  }
5351
0
    }
5352
5353
0
  free (native_relocs);
5354
0
  asect->relocation = reloc_cache;
5355
0
  return true;
5356
0
}
pe-x86_64.c:coff_slurp_reloc_table
Line
Count
Source
5246
556
{
5247
556
  bfd_byte *native_relocs;
5248
556
  arelent *reloc_cache;
5249
556
  arelent *cache_ptr;
5250
556
  unsigned int idx;
5251
556
  size_t amt;
5252
5253
556
  if (asect->relocation)
5254
7
    return true;
5255
549
  if (asect->reloc_count == 0)
5256
73
    return true;
5257
476
  if (asect->flags & SEC_CONSTRUCTOR)
5258
0
    return true;
5259
476
  if (!coff_slurp_symbol_table (abfd))
5260
146
    return false;
5261
5262
330
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5263
330
               asect->reloc_count,
5264
330
               bfd_coff_relsz (abfd));
5265
330
  if (native_relocs == NULL)
5266
102
    return false;
5267
5268
228
  if (_bfd_mul_overflow (asect->reloc_count, sizeof (arelent), &amt))
5269
0
    {
5270
0
      bfd_set_error (bfd_error_file_too_big);
5271
0
      return false;
5272
0
    }
5273
228
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5274
228
  if (reloc_cache == NULL)
5275
0
    {
5276
0
      free (native_relocs);
5277
0
      return false;
5278
0
    }
5279
5280
4.33k
  for (idx = 0; idx < asect->reloc_count; idx++)
5281
4.25k
    {
5282
4.25k
      struct internal_reloc dst;
5283
4.25k
      void *src;
5284
4.25k
#ifndef RELOC_PROCESSING
5285
4.25k
      asymbol *ptr;
5286
4.25k
#endif
5287
5288
4.25k
      cache_ptr = reloc_cache + idx;
5289
4.25k
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5290
5291
4.25k
      dst.r_offset = 0;
5292
4.25k
      bfd_coff_swap_reloc_in (abfd, src, &dst);
5293
5294
#ifdef RELOC_PROCESSING
5295
      RELOC_PROCESSING (cache_ptr, &dst, symbols, abfd, asect);
5296
#else
5297
4.25k
      cache_ptr->address = dst.r_vaddr;
5298
5299
4.25k
      if (dst.r_symndx != -1 && symbols != NULL)
5300
765
  {
5301
765
    if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
5302
402
      {
5303
402
        _bfd_error_handler
5304
    /* xgettext:c-format */
5305
402
    (_("%pB: warning: illegal symbol index %ld in relocs"),
5306
402
     abfd, dst.r_symndx);
5307
402
        cache_ptr->sym_ptr_ptr = &bfd_abs_section_ptr->symbol;
5308
402
        ptr = NULL;
5309
402
      }
5310
363
    else
5311
363
      {
5312
363
        cache_ptr->sym_ptr_ptr = (symbols
5313
363
          + obj_convert (abfd)[dst.r_symndx]);
5314
363
        ptr = *(cache_ptr->sym_ptr_ptr);
5315
363
      }
5316
765
  }
5317
3.48k
      else
5318
3.48k
  {
5319
3.48k
    cache_ptr->sym_ptr_ptr = &bfd_abs_section_ptr->symbol;
5320
3.48k
    ptr = NULL;
5321
3.48k
  }
5322
5323
      /* The symbols definitions that we have read in have been
5324
   relocated as if their sections started at 0. But the offsets
5325
   refering to the symbols in the raw data have not been
5326
   modified, so we have to have a negative addend to compensate.
5327
5328
   Note that symbols which used to be common must be left alone.  */
5329
5330
      /* Calculate any reloc addend by looking at the symbol.  */
5331
4.25k
      CALC_ADDEND (abfd, ptr, dst, cache_ptr);
5332
4.25k
      (void) ptr;
5333
5334
4.25k
      cache_ptr->address -= asect->vma;
5335
      /* !! cache_ptr->section = NULL;*/
5336
5337
      /* Fill in the cache_ptr->howto field from dst.r_type.  */
5338
4.25k
      RTYPE2HOWTO (cache_ptr, &dst);
5339
4.25k
#endif  /* RELOC_PROCESSING */
5340
5341
4.25k
      if (cache_ptr->howto == NULL)
5342
147
  {
5343
147
    _bfd_error_handler
5344
      /* xgettext:c-format */
5345
147
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5346
147
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5347
147
    bfd_set_error (bfd_error_bad_value);
5348
147
    free (native_relocs);
5349
147
    return false;
5350
147
  }
5351
4.25k
    }
5352
5353
81
  free (native_relocs);
5354
81
  asect->relocation = reloc_cache;
5355
81
  return true;
5356
228
}
pei-x86_64.c:coff_slurp_reloc_table
Line
Count
Source
5246
60
{
5247
60
  bfd_byte *native_relocs;
5248
60
  arelent *reloc_cache;
5249
60
  arelent *cache_ptr;
5250
60
  unsigned int idx;
5251
60
  size_t amt;
5252
5253
60
  if (asect->relocation)
5254
19
    return true;
5255
41
  if (asect->reloc_count == 0)
5256
41
    return true;
5257
0
  if (asect->flags & SEC_CONSTRUCTOR)
5258
0
    return true;
5259
0
  if (!coff_slurp_symbol_table (abfd))
5260
0
    return false;
5261
5262
0
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5263
0
               asect->reloc_count,
5264
0
               bfd_coff_relsz (abfd));
5265
0
  if (native_relocs == NULL)
5266
0
    return false;
5267
5268
0
  if (_bfd_mul_overflow (asect->reloc_count, sizeof (arelent), &amt))
5269
0
    {
5270
0
      bfd_set_error (bfd_error_file_too_big);
5271
0
      return false;
5272
0
    }
5273
0
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5274
0
  if (reloc_cache == NULL)
5275
0
    {
5276
0
      free (native_relocs);
5277
0
      return false;
5278
0
    }
5279
5280
0
  for (idx = 0; idx < asect->reloc_count; idx++)
5281
0
    {
5282
0
      struct internal_reloc dst;
5283
0
      void *src;
5284
0
#ifndef RELOC_PROCESSING
5285
0
      asymbol *ptr;
5286
0
#endif
5287
5288
0
      cache_ptr = reloc_cache + idx;
5289
0
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5290
5291
0
      dst.r_offset = 0;
5292
0
      bfd_coff_swap_reloc_in (abfd, src, &dst);
5293
5294
#ifdef RELOC_PROCESSING
5295
      RELOC_PROCESSING (cache_ptr, &dst, symbols, abfd, asect);
5296
#else
5297
0
      cache_ptr->address = dst.r_vaddr;
5298
5299
0
      if (dst.r_symndx != -1 && symbols != NULL)
5300
0
  {
5301
0
    if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
5302
0
      {
5303
0
        _bfd_error_handler
5304
    /* xgettext:c-format */
5305
0
    (_("%pB: warning: illegal symbol index %ld in relocs"),
5306
0
     abfd, dst.r_symndx);
5307
0
        cache_ptr->sym_ptr_ptr = &bfd_abs_section_ptr->symbol;
5308
0
        ptr = NULL;
5309
0
      }
5310
0
    else
5311
0
      {
5312
0
        cache_ptr->sym_ptr_ptr = (symbols
5313
0
          + obj_convert (abfd)[dst.r_symndx]);
5314
0
        ptr = *(cache_ptr->sym_ptr_ptr);
5315
0
      }
5316
0
  }
5317
0
      else
5318
0
  {
5319
0
    cache_ptr->sym_ptr_ptr = &bfd_abs_section_ptr->symbol;
5320
0
    ptr = NULL;
5321
0
  }
5322
5323
      /* The symbols definitions that we have read in have been
5324
   relocated as if their sections started at 0. But the offsets
5325
   refering to the symbols in the raw data have not been
5326
   modified, so we have to have a negative addend to compensate.
5327
5328
   Note that symbols which used to be common must be left alone.  */
5329
5330
      /* Calculate any reloc addend by looking at the symbol.  */
5331
0
      CALC_ADDEND (abfd, ptr, dst, cache_ptr);
5332
0
      (void) ptr;
5333
5334
0
      cache_ptr->address -= asect->vma;
5335
      /* !! cache_ptr->section = NULL;*/
5336
5337
      /* Fill in the cache_ptr->howto field from dst.r_type.  */
5338
0
      RTYPE2HOWTO (cache_ptr, &dst);
5339
0
#endif  /* RELOC_PROCESSING */
5340
5341
0
      if (cache_ptr->howto == NULL)
5342
0
  {
5343
0
    _bfd_error_handler
5344
      /* xgettext:c-format */
5345
0
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5346
0
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5347
0
    bfd_set_error (bfd_error_bad_value);
5348
0
    free (native_relocs);
5349
0
    return false;
5350
0
  }
5351
0
    }
5352
5353
0
  free (native_relocs);
5354
0
  asect->relocation = reloc_cache;
5355
0
  return true;
5356
0
}
coff-x86_64.c:coff_slurp_reloc_table
Line
Count
Source
5246
12.5k
{
5247
12.5k
  bfd_byte *native_relocs;
5248
12.5k
  arelent *reloc_cache;
5249
12.5k
  arelent *cache_ptr;
5250
12.5k
  unsigned int idx;
5251
12.5k
  size_t amt;
5252
5253
12.5k
  if (asect->relocation)
5254
127
    return true;
5255
12.4k
  if (asect->reloc_count == 0)
5256
1.38k
    return true;
5257
11.0k
  if (asect->flags & SEC_CONSTRUCTOR)
5258
0
    return true;
5259
11.0k
  if (!coff_slurp_symbol_table (abfd))
5260
9.88k
    return false;
5261
5262
1.18k
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5263
1.18k
               asect->reloc_count,
5264
1.18k
               bfd_coff_relsz (abfd));
5265
1.18k
  if (native_relocs == NULL)
5266
432
    return false;
5267
5268
756
  if (_bfd_mul_overflow (asect->reloc_count, sizeof (arelent), &amt))
5269
0
    {
5270
0
      bfd_set_error (bfd_error_file_too_big);
5271
0
      return false;
5272
0
    }
5273
756
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5274
756
  if (reloc_cache == NULL)
5275
0
    {
5276
0
      free (native_relocs);
5277
0
      return false;
5278
0
    }
5279
5280
10.0k
  for (idx = 0; idx < asect->reloc_count; idx++)
5281
9.77k
    {
5282
9.77k
      struct internal_reloc dst;
5283
9.77k
      void *src;
5284
9.77k
#ifndef RELOC_PROCESSING
5285
9.77k
      asymbol *ptr;
5286
9.77k
#endif
5287
5288
9.77k
      cache_ptr = reloc_cache + idx;
5289
9.77k
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5290
5291
9.77k
      dst.r_offset = 0;
5292
9.77k
      bfd_coff_swap_reloc_in (abfd, src, &dst);
5293
5294
#ifdef RELOC_PROCESSING
5295
      RELOC_PROCESSING (cache_ptr, &dst, symbols, abfd, asect);
5296
#else
5297
9.77k
      cache_ptr->address = dst.r_vaddr;
5298
5299
9.77k
      if (dst.r_symndx != -1 && symbols != NULL)
5300
6.61k
  {
5301
6.61k
    if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
5302
887
      {
5303
887
        _bfd_error_handler
5304
    /* xgettext:c-format */
5305
887
    (_("%pB: warning: illegal symbol index %ld in relocs"),
5306
887
     abfd, dst.r_symndx);
5307
887
        cache_ptr->sym_ptr_ptr = &bfd_abs_section_ptr->symbol;
5308
887
        ptr = NULL;
5309
887
      }
5310
5.72k
    else
5311
5.72k
      {
5312
5.72k
        cache_ptr->sym_ptr_ptr = (symbols
5313
5.72k
          + obj_convert (abfd)[dst.r_symndx]);
5314
5.72k
        ptr = *(cache_ptr->sym_ptr_ptr);
5315
5.72k
      }
5316
6.61k
  }
5317
3.16k
      else
5318
3.16k
  {
5319
3.16k
    cache_ptr->sym_ptr_ptr = &bfd_abs_section_ptr->symbol;
5320
3.16k
    ptr = NULL;
5321
3.16k
  }
5322
5323
      /* The symbols definitions that we have read in have been
5324
   relocated as if their sections started at 0. But the offsets
5325
   refering to the symbols in the raw data have not been
5326
   modified, so we have to have a negative addend to compensate.
5327
5328
   Note that symbols which used to be common must be left alone.  */
5329
5330
      /* Calculate any reloc addend by looking at the symbol.  */
5331
9.77k
      CALC_ADDEND (abfd, ptr, dst, cache_ptr);
5332
9.77k
      (void) ptr;
5333
5334
9.77k
      cache_ptr->address -= asect->vma;
5335
      /* !! cache_ptr->section = NULL;*/
5336
5337
      /* Fill in the cache_ptr->howto field from dst.r_type.  */
5338
9.77k
      RTYPE2HOWTO (cache_ptr, &dst);
5339
9.77k
#endif  /* RELOC_PROCESSING */
5340
5341
9.77k
      if (cache_ptr->howto == NULL)
5342
447
  {
5343
447
    _bfd_error_handler
5344
      /* xgettext:c-format */
5345
447
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5346
447
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5347
447
    bfd_set_error (bfd_error_bad_value);
5348
447
    free (native_relocs);
5349
447
    return false;
5350
447
  }
5351
9.77k
    }
5352
5353
309
  free (native_relocs);
5354
309
  asect->relocation = reloc_cache;
5355
309
  return true;
5356
756
}
coff64-rs6000.c:coff_slurp_reloc_table
Line
Count
Source
5246
1.71k
{
5247
1.71k
  bfd_byte *native_relocs;
5248
1.71k
  arelent *reloc_cache;
5249
1.71k
  arelent *cache_ptr;
5250
1.71k
  unsigned int idx;
5251
1.71k
  size_t amt;
5252
5253
1.71k
  if (asect->relocation)
5254
0
    return true;
5255
1.71k
  if (asect->reloc_count == 0)
5256
12
    return true;
5257
1.69k
  if (asect->flags & SEC_CONSTRUCTOR)
5258
0
    return true;
5259
1.69k
  if (!coff_slurp_symbol_table (abfd))
5260
1.50k
    return false;
5261
5262
197
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5263
197
               asect->reloc_count,
5264
197
               bfd_coff_relsz (abfd));
5265
197
  if (native_relocs == NULL)
5266
197
    return false;
5267
5268
0
  if (_bfd_mul_overflow (asect->reloc_count, sizeof (arelent), &amt))
5269
0
    {
5270
0
      bfd_set_error (bfd_error_file_too_big);
5271
0
      return false;
5272
0
    }
5273
0
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5274
0
  if (reloc_cache == NULL)
5275
0
    {
5276
0
      free (native_relocs);
5277
0
      return false;
5278
0
    }
5279
5280
0
  for (idx = 0; idx < asect->reloc_count; idx++)
5281
0
    {
5282
0
      struct internal_reloc dst;
5283
0
      void *src;
5284
0
#ifndef RELOC_PROCESSING
5285
0
      asymbol *ptr;
5286
0
#endif
5287
5288
0
      cache_ptr = reloc_cache + idx;
5289
0
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5290
5291
0
      dst.r_offset = 0;
5292
0
      bfd_coff_swap_reloc_in (abfd, src, &dst);
5293
5294
#ifdef RELOC_PROCESSING
5295
      RELOC_PROCESSING (cache_ptr, &dst, symbols, abfd, asect);
5296
#else
5297
0
      cache_ptr->address = dst.r_vaddr;
5298
5299
0
      if (dst.r_symndx != -1 && symbols != NULL)
5300
0
  {
5301
0
    if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
5302
0
      {
5303
0
        _bfd_error_handler
5304
    /* xgettext:c-format */
5305
0
    (_("%pB: warning: illegal symbol index %ld in relocs"),
5306
0
     abfd, dst.r_symndx);
5307
0
        cache_ptr->sym_ptr_ptr = &bfd_abs_section_ptr->symbol;
5308
0
        ptr = NULL;
5309
0
      }
5310
0
    else
5311
0
      {
5312
0
        cache_ptr->sym_ptr_ptr = (symbols
5313
0
          + obj_convert (abfd)[dst.r_symndx]);
5314
0
        ptr = *(cache_ptr->sym_ptr_ptr);
5315
0
      }
5316
0
  }
5317
0
      else
5318
0
  {
5319
0
    cache_ptr->sym_ptr_ptr = &bfd_abs_section_ptr->symbol;
5320
0
    ptr = NULL;
5321
0
  }
5322
5323
      /* The symbols definitions that we have read in have been
5324
   relocated as if their sections started at 0. But the offsets
5325
   refering to the symbols in the raw data have not been
5326
   modified, so we have to have a negative addend to compensate.
5327
5328
   Note that symbols which used to be common must be left alone.  */
5329
5330
      /* Calculate any reloc addend by looking at the symbol.  */
5331
0
      CALC_ADDEND (abfd, ptr, dst, cache_ptr);
5332
0
      (void) ptr;
5333
5334
0
      cache_ptr->address -= asect->vma;
5335
      /* !! cache_ptr->section = NULL;*/
5336
5337
      /* Fill in the cache_ptr->howto field from dst.r_type.  */
5338
0
      RTYPE2HOWTO (cache_ptr, &dst);
5339
0
#endif  /* RELOC_PROCESSING */
5340
5341
0
      if (cache_ptr->howto == NULL)
5342
0
  {
5343
0
    _bfd_error_handler
5344
      /* xgettext:c-format */
5345
0
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5346
0
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5347
0
    bfd_set_error (bfd_error_bad_value);
5348
0
    free (native_relocs);
5349
0
    return false;
5350
0
  }
5351
0
    }
5352
5353
0
  free (native_relocs);
5354
0
  asect->relocation = reloc_cache;
5355
0
  return true;
5356
0
}
pe-aarch64.c:coff_slurp_reloc_table
Line
Count
Source
5246
504
{
5247
504
  bfd_byte *native_relocs;
5248
504
  arelent *reloc_cache;
5249
504
  arelent *cache_ptr;
5250
504
  unsigned int idx;
5251
504
  size_t amt;
5252
5253
504
  if (asect->relocation)
5254
13
    return true;
5255
491
  if (asect->reloc_count == 0)
5256
25
    return true;
5257
466
  if (asect->flags & SEC_CONSTRUCTOR)
5258
0
    return true;
5259
466
  if (!coff_slurp_symbol_table (abfd))
5260
37
    return false;
5261
5262
429
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5263
429
               asect->reloc_count,
5264
429
               bfd_coff_relsz (abfd));
5265
429
  if (native_relocs == NULL)
5266
173
    return false;
5267
5268
256
  if (_bfd_mul_overflow (asect->reloc_count, sizeof (arelent), &amt))
5269
0
    {
5270
0
      bfd_set_error (bfd_error_file_too_big);
5271
0
      return false;
5272
0
    }
5273
256
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5274
256
  if (reloc_cache == NULL)
5275
0
    {
5276
0
      free (native_relocs);
5277
0
      return false;
5278
0
    }
5279
5280
1.16k
  for (idx = 0; idx < asect->reloc_count; idx++)
5281
1.11k
    {
5282
1.11k
      struct internal_reloc dst;
5283
1.11k
      void *src;
5284
1.11k
#ifndef RELOC_PROCESSING
5285
1.11k
      asymbol *ptr;
5286
1.11k
#endif
5287
5288
1.11k
      cache_ptr = reloc_cache + idx;
5289
1.11k
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5290
5291
1.11k
      dst.r_offset = 0;
5292
1.11k
      bfd_coff_swap_reloc_in (abfd, src, &dst);
5293
5294
#ifdef RELOC_PROCESSING
5295
      RELOC_PROCESSING (cache_ptr, &dst, symbols, abfd, asect);
5296
#else
5297
1.11k
      cache_ptr->address = dst.r_vaddr;
5298
5299
1.11k
      if (dst.r_symndx != -1 && symbols != NULL)
5300
901
  {
5301
901
    if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
5302
430
      {
5303
430
        _bfd_error_handler
5304
    /* xgettext:c-format */
5305
430
    (_("%pB: warning: illegal symbol index %ld in relocs"),
5306
430
     abfd, dst.r_symndx);
5307
430
        cache_ptr->sym_ptr_ptr = &bfd_abs_section_ptr->symbol;
5308
430
        ptr = NULL;
5309
430
      }
5310
471
    else
5311
471
      {
5312
471
        cache_ptr->sym_ptr_ptr = (symbols
5313
471
          + obj_convert (abfd)[dst.r_symndx]);
5314
471
        ptr = *(cache_ptr->sym_ptr_ptr);
5315
471
      }
5316
901
  }
5317
214
      else
5318
214
  {
5319
214
    cache_ptr->sym_ptr_ptr = &bfd_abs_section_ptr->symbol;
5320
214
    ptr = NULL;
5321
214
  }
5322
5323
      /* The symbols definitions that we have read in have been
5324
   relocated as if their sections started at 0. But the offsets
5325
   refering to the symbols in the raw data have not been
5326
   modified, so we have to have a negative addend to compensate.
5327
5328
   Note that symbols which used to be common must be left alone.  */
5329
5330
      /* Calculate any reloc addend by looking at the symbol.  */
5331
1.11k
      CALC_ADDEND (abfd, ptr, dst, cache_ptr);
5332
1.11k
      (void) ptr;
5333
5334
1.11k
      cache_ptr->address -= asect->vma;
5335
      /* !! cache_ptr->section = NULL;*/
5336
5337
      /* Fill in the cache_ptr->howto field from dst.r_type.  */
5338
1.11k
      RTYPE2HOWTO (cache_ptr, &dst);
5339
1.11k
#endif  /* RELOC_PROCESSING */
5340
5341
1.11k
      if (cache_ptr->howto == NULL)
5342
205
  {
5343
205
    _bfd_error_handler
5344
      /* xgettext:c-format */
5345
205
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5346
205
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5347
205
    bfd_set_error (bfd_error_bad_value);
5348
205
    free (native_relocs);
5349
205
    return false;
5350
205
  }
5351
1.11k
    }
5352
5353
51
  free (native_relocs);
5354
51
  asect->relocation = reloc_cache;
5355
51
  return true;
5356
256
}
pei-aarch64.c:coff_slurp_reloc_table
Line
Count
Source
5246
31
{
5247
31
  bfd_byte *native_relocs;
5248
31
  arelent *reloc_cache;
5249
31
  arelent *cache_ptr;
5250
31
  unsigned int idx;
5251
31
  size_t amt;
5252
5253
31
  if (asect->relocation)
5254
20
    return true;
5255
11
  if (asect->reloc_count == 0)
5256
11
    return true;
5257
0
  if (asect->flags & SEC_CONSTRUCTOR)
5258
0
    return true;
5259
0
  if (!coff_slurp_symbol_table (abfd))
5260
0
    return false;
5261
5262
0
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5263
0
               asect->reloc_count,
5264
0
               bfd_coff_relsz (abfd));
5265
0
  if (native_relocs == NULL)
5266
0
    return false;
5267
5268
0
  if (_bfd_mul_overflow (asect->reloc_count, sizeof (arelent), &amt))
5269
0
    {
5270
0
      bfd_set_error (bfd_error_file_too_big);
5271
0
      return false;
5272
0
    }
5273
0
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5274
0
  if (reloc_cache == NULL)
5275
0
    {
5276
0
      free (native_relocs);
5277
0
      return false;
5278
0
    }
5279
5280
0
  for (idx = 0; idx < asect->reloc_count; idx++)
5281
0
    {
5282
0
      struct internal_reloc dst;
5283
0
      void *src;
5284
0
#ifndef RELOC_PROCESSING
5285
0
      asymbol *ptr;
5286
0
#endif
5287
5288
0
      cache_ptr = reloc_cache + idx;
5289
0
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5290
5291
0
      dst.r_offset = 0;
5292
0
      bfd_coff_swap_reloc_in (abfd, src, &dst);
5293
5294
#ifdef RELOC_PROCESSING
5295
      RELOC_PROCESSING (cache_ptr, &dst, symbols, abfd, asect);
5296
#else
5297
0
      cache_ptr->address = dst.r_vaddr;
5298
5299
0
      if (dst.r_symndx != -1 && symbols != NULL)
5300
0
  {
5301
0
    if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
5302
0
      {
5303
0
        _bfd_error_handler
5304
    /* xgettext:c-format */
5305
0
    (_("%pB: warning: illegal symbol index %ld in relocs"),
5306
0
     abfd, dst.r_symndx);
5307
0
        cache_ptr->sym_ptr_ptr = &bfd_abs_section_ptr->symbol;
5308
0
        ptr = NULL;
5309
0
      }
5310
0
    else
5311
0
      {
5312
0
        cache_ptr->sym_ptr_ptr = (symbols
5313
0
          + obj_convert (abfd)[dst.r_symndx]);
5314
0
        ptr = *(cache_ptr->sym_ptr_ptr);
5315
0
      }
5316
0
  }
5317
0
      else
5318
0
  {
5319
0
    cache_ptr->sym_ptr_ptr = &bfd_abs_section_ptr->symbol;
5320
0
    ptr = NULL;
5321
0
  }
5322
5323
      /* The symbols definitions that we have read in have been
5324
   relocated as if their sections started at 0. But the offsets
5325
   refering to the symbols in the raw data have not been
5326
   modified, so we have to have a negative addend to compensate.
5327
5328
   Note that symbols which used to be common must be left alone.  */
5329
5330
      /* Calculate any reloc addend by looking at the symbol.  */
5331
0
      CALC_ADDEND (abfd, ptr, dst, cache_ptr);
5332
0
      (void) ptr;
5333
5334
0
      cache_ptr->address -= asect->vma;
5335
      /* !! cache_ptr->section = NULL;*/
5336
5337
      /* Fill in the cache_ptr->howto field from dst.r_type.  */
5338
0
      RTYPE2HOWTO (cache_ptr, &dst);
5339
0
#endif  /* RELOC_PROCESSING */
5340
5341
0
      if (cache_ptr->howto == NULL)
5342
0
  {
5343
0
    _bfd_error_handler
5344
      /* xgettext:c-format */
5345
0
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5346
0
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5347
0
    bfd_set_error (bfd_error_bad_value);
5348
0
    free (native_relocs);
5349
0
    return false;
5350
0
  }
5351
0
    }
5352
5353
0
  free (native_relocs);
5354
0
  asect->relocation = reloc_cache;
5355
0
  return true;
5356
0
}
pei-ia64.c:coff_slurp_reloc_table
Line
Count
Source
5246
1
{
5247
1
  bfd_byte *native_relocs;
5248
1
  arelent *reloc_cache;
5249
1
  arelent *cache_ptr;
5250
1
  unsigned int idx;
5251
1
  size_t amt;
5252
5253
1
  if (asect->relocation)
5254
0
    return true;
5255
1
  if (asect->reloc_count == 0)
5256
1
    return true;
5257
0
  if (asect->flags & SEC_CONSTRUCTOR)
5258
0
    return true;
5259
0
  if (!coff_slurp_symbol_table (abfd))
5260
0
    return false;
5261
5262
0
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5263
0
               asect->reloc_count,
5264
0
               bfd_coff_relsz (abfd));
5265
0
  if (native_relocs == NULL)
5266
0
    return false;
5267
5268
0
  if (_bfd_mul_overflow (asect->reloc_count, sizeof (arelent), &amt))
5269
0
    {
5270
0
      bfd_set_error (bfd_error_file_too_big);
5271
0
      return false;
5272
0
    }
5273
0
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5274
0
  if (reloc_cache == NULL)
5275
0
    {
5276
0
      free (native_relocs);
5277
0
      return false;
5278
0
    }
5279
5280
0
  for (idx = 0; idx < asect->reloc_count; idx++)
5281
0
    {
5282
0
      struct internal_reloc dst;
5283
0
      void *src;
5284
0
#ifndef RELOC_PROCESSING
5285
0
      asymbol *ptr;
5286
0
#endif
5287
5288
0
      cache_ptr = reloc_cache + idx;
5289
0
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5290
5291
0
      dst.r_offset = 0;
5292
0
      bfd_coff_swap_reloc_in (abfd, src, &dst);
5293
5294
#ifdef RELOC_PROCESSING
5295
      RELOC_PROCESSING (cache_ptr, &dst, symbols, abfd, asect);
5296
#else
5297
0
      cache_ptr->address = dst.r_vaddr;
5298
5299
0
      if (dst.r_symndx != -1 && symbols != NULL)
5300
0
  {
5301
0
    if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
5302
0
      {
5303
0
        _bfd_error_handler
5304
    /* xgettext:c-format */
5305
0
    (_("%pB: warning: illegal symbol index %ld in relocs"),
5306
0
     abfd, dst.r_symndx);
5307
0
        cache_ptr->sym_ptr_ptr = &bfd_abs_section_ptr->symbol;
5308
0
        ptr = NULL;
5309
0
      }
5310
0
    else
5311
0
      {
5312
0
        cache_ptr->sym_ptr_ptr = (symbols
5313
0
          + obj_convert (abfd)[dst.r_symndx]);
5314
0
        ptr = *(cache_ptr->sym_ptr_ptr);
5315
0
      }
5316
0
  }
5317
0
      else
5318
0
  {
5319
0
    cache_ptr->sym_ptr_ptr = &bfd_abs_section_ptr->symbol;
5320
0
    ptr = NULL;
5321
0
  }
5322
5323
      /* The symbols definitions that we have read in have been
5324
   relocated as if their sections started at 0. But the offsets
5325
   refering to the symbols in the raw data have not been
5326
   modified, so we have to have a negative addend to compensate.
5327
5328
   Note that symbols which used to be common must be left alone.  */
5329
5330
      /* Calculate any reloc addend by looking at the symbol.  */
5331
0
      CALC_ADDEND (abfd, ptr, dst, cache_ptr);
5332
0
      (void) ptr;
5333
5334
0
      cache_ptr->address -= asect->vma;
5335
      /* !! cache_ptr->section = NULL;*/
5336
5337
      /* Fill in the cache_ptr->howto field from dst.r_type.  */
5338
0
      RTYPE2HOWTO (cache_ptr, &dst);
5339
0
#endif  /* RELOC_PROCESSING */
5340
5341
0
      if (cache_ptr->howto == NULL)
5342
0
  {
5343
0
    _bfd_error_handler
5344
      /* xgettext:c-format */
5345
0
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5346
0
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5347
0
    bfd_set_error (bfd_error_bad_value);
5348
0
    free (native_relocs);
5349
0
    return false;
5350
0
  }
5351
0
    }
5352
5353
0
  free (native_relocs);
5354
0
  asect->relocation = reloc_cache;
5355
0
  return true;
5356
0
}
pei-loongarch64.c:coff_slurp_reloc_table
Line
Count
Source
5246
24
{
5247
24
  bfd_byte *native_relocs;
5248
24
  arelent *reloc_cache;
5249
24
  arelent *cache_ptr;
5250
24
  unsigned int idx;
5251
24
  size_t amt;
5252
5253
24
  if (asect->relocation)
5254
21
    return true;
5255
3
  if (asect->reloc_count == 0)
5256
3
    return true;
5257
0
  if (asect->flags & SEC_CONSTRUCTOR)
5258
0
    return true;
5259
0
  if (!coff_slurp_symbol_table (abfd))
5260
0
    return false;
5261
5262
0
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5263
0
               asect->reloc_count,
5264
0
               bfd_coff_relsz (abfd));
5265
0
  if (native_relocs == NULL)
5266
0
    return false;
5267
5268
0
  if (_bfd_mul_overflow (asect->reloc_count, sizeof (arelent), &amt))
5269
0
    {
5270
0
      bfd_set_error (bfd_error_file_too_big);
5271
0
      return false;
5272
0
    }
5273
0
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5274
0
  if (reloc_cache == NULL)
5275
0
    {
5276
0
      free (native_relocs);
5277
0
      return false;
5278
0
    }
5279
5280
0
  for (idx = 0; idx < asect->reloc_count; idx++)
5281
0
    {
5282
0
      struct internal_reloc dst;
5283
0
      void *src;
5284
0
#ifndef RELOC_PROCESSING
5285
0
      asymbol *ptr;
5286
0
#endif
5287
5288
0
      cache_ptr = reloc_cache + idx;
5289
0
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5290
5291
0
      dst.r_offset = 0;
5292
0
      bfd_coff_swap_reloc_in (abfd, src, &dst);
5293
5294
#ifdef RELOC_PROCESSING
5295
      RELOC_PROCESSING (cache_ptr, &dst, symbols, abfd, asect);
5296
#else
5297
0
      cache_ptr->address = dst.r_vaddr;
5298
5299
0
      if (dst.r_symndx != -1 && symbols != NULL)
5300
0
  {
5301
0
    if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
5302
0
      {
5303
0
        _bfd_error_handler
5304
    /* xgettext:c-format */
5305
0
    (_("%pB: warning: illegal symbol index %ld in relocs"),
5306
0
     abfd, dst.r_symndx);
5307
0
        cache_ptr->sym_ptr_ptr = &bfd_abs_section_ptr->symbol;
5308
0
        ptr = NULL;
5309
0
      }
5310
0
    else
5311
0
      {
5312
0
        cache_ptr->sym_ptr_ptr = (symbols
5313
0
          + obj_convert (abfd)[dst.r_symndx]);
5314
0
        ptr = *(cache_ptr->sym_ptr_ptr);
5315
0
      }
5316
0
  }
5317
0
      else
5318
0
  {
5319
0
    cache_ptr->sym_ptr_ptr = &bfd_abs_section_ptr->symbol;
5320
0
    ptr = NULL;
5321
0
  }
5322
5323
      /* The symbols definitions that we have read in have been
5324
   relocated as if their sections started at 0. But the offsets
5325
   refering to the symbols in the raw data have not been
5326
   modified, so we have to have a negative addend to compensate.
5327
5328
   Note that symbols which used to be common must be left alone.  */
5329
5330
      /* Calculate any reloc addend by looking at the symbol.  */
5331
0
      CALC_ADDEND (abfd, ptr, dst, cache_ptr);
5332
0
      (void) ptr;
5333
5334
0
      cache_ptr->address -= asect->vma;
5335
      /* !! cache_ptr->section = NULL;*/
5336
5337
      /* Fill in the cache_ptr->howto field from dst.r_type.  */
5338
0
      RTYPE2HOWTO (cache_ptr, &dst);
5339
0
#endif  /* RELOC_PROCESSING */
5340
5341
0
      if (cache_ptr->howto == NULL)
5342
0
  {
5343
0
    _bfd_error_handler
5344
      /* xgettext:c-format */
5345
0
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5346
0
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5347
0
    bfd_set_error (bfd_error_bad_value);
5348
0
    free (native_relocs);
5349
0
    return false;
5350
0
  }
5351
0
    }
5352
5353
0
  free (native_relocs);
5354
0
  asect->relocation = reloc_cache;
5355
0
  return true;
5356
0
}
pei-riscv64.c:coff_slurp_reloc_table
Line
Count
Source
5246
37
{
5247
37
  bfd_byte *native_relocs;
5248
37
  arelent *reloc_cache;
5249
37
  arelent *cache_ptr;
5250
37
  unsigned int idx;
5251
37
  size_t amt;
5252
5253
37
  if (asect->relocation)
5254
27
    return true;
5255
10
  if (asect->reloc_count == 0)
5256
10
    return true;
5257
0
  if (asect->flags & SEC_CONSTRUCTOR)
5258
0
    return true;
5259
0
  if (!coff_slurp_symbol_table (abfd))
5260
0
    return false;
5261
5262
0
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5263
0
               asect->reloc_count,
5264
0
               bfd_coff_relsz (abfd));
5265
0
  if (native_relocs == NULL)
5266
0
    return false;
5267
5268
0
  if (_bfd_mul_overflow (asect->reloc_count, sizeof (arelent), &amt))
5269
0
    {
5270
0
      bfd_set_error (bfd_error_file_too_big);
5271
0
      return false;
5272
0
    }
5273
0
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5274
0
  if (reloc_cache == NULL)
5275
0
    {
5276
0
      free (native_relocs);
5277
0
      return false;
5278
0
    }
5279
5280
0
  for (idx = 0; idx < asect->reloc_count; idx++)
5281
0
    {
5282
0
      struct internal_reloc dst;
5283
0
      void *src;
5284
0
#ifndef RELOC_PROCESSING
5285
0
      asymbol *ptr;
5286
0
#endif
5287
5288
0
      cache_ptr = reloc_cache + idx;
5289
0
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5290
5291
0
      dst.r_offset = 0;
5292
0
      bfd_coff_swap_reloc_in (abfd, src, &dst);
5293
5294
#ifdef RELOC_PROCESSING
5295
      RELOC_PROCESSING (cache_ptr, &dst, symbols, abfd, asect);
5296
#else
5297
0
      cache_ptr->address = dst.r_vaddr;
5298
5299
0
      if (dst.r_symndx != -1 && symbols != NULL)
5300
0
  {
5301
0
    if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
5302
0
      {
5303
0
        _bfd_error_handler
5304
    /* xgettext:c-format */
5305
0
    (_("%pB: warning: illegal symbol index %ld in relocs"),
5306
0
     abfd, dst.r_symndx);
5307
0
        cache_ptr->sym_ptr_ptr = &bfd_abs_section_ptr->symbol;
5308
0
        ptr = NULL;
5309
0
      }
5310
0
    else
5311
0
      {
5312
0
        cache_ptr->sym_ptr_ptr = (symbols
5313
0
          + obj_convert (abfd)[dst.r_symndx]);
5314
0
        ptr = *(cache_ptr->sym_ptr_ptr);
5315
0
      }
5316
0
  }
5317
0
      else
5318
0
  {
5319
0
    cache_ptr->sym_ptr_ptr = &bfd_abs_section_ptr->symbol;
5320
0
    ptr = NULL;
5321
0
  }
5322
5323
      /* The symbols definitions that we have read in have been
5324
   relocated as if their sections started at 0. But the offsets
5325
   refering to the symbols in the raw data have not been
5326
   modified, so we have to have a negative addend to compensate.
5327
5328
   Note that symbols which used to be common must be left alone.  */
5329
5330
      /* Calculate any reloc addend by looking at the symbol.  */
5331
0
      CALC_ADDEND (abfd, ptr, dst, cache_ptr);
5332
0
      (void) ptr;
5333
5334
0
      cache_ptr->address -= asect->vma;
5335
      /* !! cache_ptr->section = NULL;*/
5336
5337
      /* Fill in the cache_ptr->howto field from dst.r_type.  */
5338
0
      RTYPE2HOWTO (cache_ptr, &dst);
5339
0
#endif  /* RELOC_PROCESSING */
5340
5341
0
      if (cache_ptr->howto == NULL)
5342
0
  {
5343
0
    _bfd_error_handler
5344
      /* xgettext:c-format */
5345
0
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5346
0
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5347
0
    bfd_set_error (bfd_error_bad_value);
5348
0
    free (native_relocs);
5349
0
    return false;
5350
0
  }
5351
0
    }
5352
5353
0
  free (native_relocs);
5354
0
  asect->relocation = reloc_cache;
5355
0
  return true;
5356
0
}
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
coff-rs6000.c:coff_slurp_reloc_table
Line
Count
Source
5246
7.97k
{
5247
7.97k
  bfd_byte *native_relocs;
5248
7.97k
  arelent *reloc_cache;
5249
7.97k
  arelent *cache_ptr;
5250
7.97k
  unsigned int idx;
5251
7.97k
  size_t amt;
5252
5253
7.97k
  if (asect->relocation)
5254
0
    return true;
5255
7.97k
  if (asect->reloc_count == 0)
5256
32
    return true;
5257
7.94k
  if (asect->flags & SEC_CONSTRUCTOR)
5258
0
    return true;
5259
7.94k
  if (!coff_slurp_symbol_table (abfd))
5260
7.82k
    return false;
5261
5262
122
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5263
122
               asect->reloc_count,
5264
122
               bfd_coff_relsz (abfd));
5265
122
  if (native_relocs == NULL)
5266
122
    return false;
5267
5268
0
  if (_bfd_mul_overflow (asect->reloc_count, sizeof (arelent), &amt))
5269
0
    {
5270
0
      bfd_set_error (bfd_error_file_too_big);
5271
0
      return false;
5272
0
    }
5273
0
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5274
0
  if (reloc_cache == NULL)
5275
0
    {
5276
0
      free (native_relocs);
5277
0
      return false;
5278
0
    }
5279
5280
0
  for (idx = 0; idx < asect->reloc_count; idx++)
5281
0
    {
5282
0
      struct internal_reloc dst;
5283
0
      void *src;
5284
0
#ifndef RELOC_PROCESSING
5285
0
      asymbol *ptr;
5286
0
#endif
5287
5288
0
      cache_ptr = reloc_cache + idx;
5289
0
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5290
5291
0
      dst.r_offset = 0;
5292
0
      bfd_coff_swap_reloc_in (abfd, src, &dst);
5293
5294
#ifdef RELOC_PROCESSING
5295
      RELOC_PROCESSING (cache_ptr, &dst, symbols, abfd, asect);
5296
#else
5297
0
      cache_ptr->address = dst.r_vaddr;
5298
5299
0
      if (dst.r_symndx != -1 && symbols != NULL)
5300
0
  {
5301
0
    if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
5302
0
      {
5303
0
        _bfd_error_handler
5304
    /* xgettext:c-format */
5305
0
    (_("%pB: warning: illegal symbol index %ld in relocs"),
5306
0
     abfd, dst.r_symndx);
5307
0
        cache_ptr->sym_ptr_ptr = &bfd_abs_section_ptr->symbol;
5308
0
        ptr = NULL;
5309
0
      }
5310
0
    else
5311
0
      {
5312
0
        cache_ptr->sym_ptr_ptr = (symbols
5313
0
          + obj_convert (abfd)[dst.r_symndx]);
5314
0
        ptr = *(cache_ptr->sym_ptr_ptr);
5315
0
      }
5316
0
  }
5317
0
      else
5318
0
  {
5319
0
    cache_ptr->sym_ptr_ptr = &bfd_abs_section_ptr->symbol;
5320
0
    ptr = NULL;
5321
0
  }
5322
5323
      /* The symbols definitions that we have read in have been
5324
   relocated as if their sections started at 0. But the offsets
5325
   refering to the symbols in the raw data have not been
5326
   modified, so we have to have a negative addend to compensate.
5327
5328
   Note that symbols which used to be common must be left alone.  */
5329
5330
      /* Calculate any reloc addend by looking at the symbol.  */
5331
0
      CALC_ADDEND (abfd, ptr, dst, cache_ptr);
5332
0
      (void) ptr;
5333
5334
0
      cache_ptr->address -= asect->vma;
5335
      /* !! cache_ptr->section = NULL;*/
5336
5337
      /* Fill in the cache_ptr->howto field from dst.r_type.  */
5338
0
      RTYPE2HOWTO (cache_ptr, &dst);
5339
0
#endif  /* RELOC_PROCESSING */
5340
5341
0
      if (cache_ptr->howto == NULL)
5342
0
  {
5343
0
    _bfd_error_handler
5344
      /* xgettext:c-format */
5345
0
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5346
0
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5347
0
    bfd_set_error (bfd_error_bad_value);
5348
0
    free (native_relocs);
5349
0
    return false;
5350
0
  }
5351
0
    }
5352
5353
0
  free (native_relocs);
5354
0
  asect->relocation = reloc_cache;
5355
0
  return true;
5356
0
}
coff-sh.c:coff_slurp_reloc_table
Line
Count
Source
5246
3.58k
{
5247
3.58k
  bfd_byte *native_relocs;
5248
3.58k
  arelent *reloc_cache;
5249
3.58k
  arelent *cache_ptr;
5250
3.58k
  unsigned int idx;
5251
3.58k
  size_t amt;
5252
5253
3.58k
  if (asect->relocation)
5254
3
    return true;
5255
3.57k
  if (asect->reloc_count == 0)
5256
209
    return true;
5257
3.36k
  if (asect->flags & SEC_CONSTRUCTOR)
5258
0
    return true;
5259
3.36k
  if (!coff_slurp_symbol_table (abfd))
5260
2.53k
    return false;
5261
5262
836
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5263
836
               asect->reloc_count,
5264
836
               bfd_coff_relsz (abfd));
5265
836
  if (native_relocs == NULL)
5266
459
    return false;
5267
5268
377
  if (_bfd_mul_overflow (asect->reloc_count, sizeof (arelent), &amt))
5269
0
    {
5270
0
      bfd_set_error (bfd_error_file_too_big);
5271
0
      return false;
5272
0
    }
5273
377
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5274
377
  if (reloc_cache == NULL)
5275
0
    {
5276
0
      free (native_relocs);
5277
0
      return false;
5278
0
    }
5279
5280
4.67k
  for (idx = 0; idx < asect->reloc_count; idx++)
5281
4.57k
    {
5282
4.57k
      struct internal_reloc dst;
5283
4.57k
      void *src;
5284
4.57k
#ifndef RELOC_PROCESSING
5285
4.57k
      asymbol *ptr;
5286
4.57k
#endif
5287
5288
4.57k
      cache_ptr = reloc_cache + idx;
5289
4.57k
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5290
5291
4.57k
      dst.r_offset = 0;
5292
4.57k
      bfd_coff_swap_reloc_in (abfd, src, &dst);
5293
5294
#ifdef RELOC_PROCESSING
5295
      RELOC_PROCESSING (cache_ptr, &dst, symbols, abfd, asect);
5296
#else
5297
4.57k
      cache_ptr->address = dst.r_vaddr;
5298
5299
4.57k
      if (dst.r_symndx != -1 && symbols != NULL)
5300
3.17k
  {
5301
3.17k
    if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
5302
2.42k
      {
5303
2.42k
        _bfd_error_handler
5304
    /* xgettext:c-format */
5305
2.42k
    (_("%pB: warning: illegal symbol index %ld in relocs"),
5306
2.42k
     abfd, dst.r_symndx);
5307
2.42k
        cache_ptr->sym_ptr_ptr = &bfd_abs_section_ptr->symbol;
5308
2.42k
        ptr = NULL;
5309
2.42k
      }
5310
746
    else
5311
746
      {
5312
746
        cache_ptr->sym_ptr_ptr = (symbols
5313
746
          + obj_convert (abfd)[dst.r_symndx]);
5314
746
        ptr = *(cache_ptr->sym_ptr_ptr);
5315
746
      }
5316
3.17k
  }
5317
1.40k
      else
5318
1.40k
  {
5319
1.40k
    cache_ptr->sym_ptr_ptr = &bfd_abs_section_ptr->symbol;
5320
1.40k
    ptr = NULL;
5321
1.40k
  }
5322
5323
      /* The symbols definitions that we have read in have been
5324
   relocated as if their sections started at 0. But the offsets
5325
   refering to the symbols in the raw data have not been
5326
   modified, so we have to have a negative addend to compensate.
5327
5328
   Note that symbols which used to be common must be left alone.  */
5329
5330
      /* Calculate any reloc addend by looking at the symbol.  */
5331
4.57k
      CALC_ADDEND (abfd, ptr, dst, cache_ptr);
5332
4.57k
      (void) ptr;
5333
5334
4.57k
      cache_ptr->address -= asect->vma;
5335
      /* !! cache_ptr->section = NULL;*/
5336
5337
      /* Fill in the cache_ptr->howto field from dst.r_type.  */
5338
4.57k
      RTYPE2HOWTO (cache_ptr, &dst);
5339
4.57k
#endif  /* RELOC_PROCESSING */
5340
5341
4.57k
      if (cache_ptr->howto == NULL)
5342
273
  {
5343
273
    _bfd_error_handler
5344
      /* xgettext:c-format */
5345
273
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5346
273
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5347
273
    bfd_set_error (bfd_error_bad_value);
5348
273
    free (native_relocs);
5349
273
    return false;
5350
273
  }
5351
4.57k
    }
5352
5353
104
  free (native_relocs);
5354
104
  asect->relocation = reloc_cache;
5355
104
  return true;
5356
377
}
Unexecuted instantiation: coff-stgo32.c:coff_slurp_reloc_table
coff-tic30.c:coff_slurp_reloc_table
Line
Count
Source
5246
10.0k
{
5247
10.0k
  bfd_byte *native_relocs;
5248
10.0k
  arelent *reloc_cache;
5249
10.0k
  arelent *cache_ptr;
5250
10.0k
  unsigned int idx;
5251
10.0k
  size_t amt;
5252
5253
10.0k
  if (asect->relocation)
5254
0
    return true;
5255
10.0k
  if (asect->reloc_count == 0)
5256
80
    return true;
5257
10.0k
  if (asect->flags & SEC_CONSTRUCTOR)
5258
0
    return true;
5259
10.0k
  if (!coff_slurp_symbol_table (abfd))
5260
4.09k
    return false;
5261
5262
5.91k
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5263
5.91k
               asect->reloc_count,
5264
5.91k
               bfd_coff_relsz (abfd));
5265
5.91k
  if (native_relocs == NULL)
5266
3.77k
    return false;
5267
5268
2.14k
  if (_bfd_mul_overflow (asect->reloc_count, sizeof (arelent), &amt))
5269
0
    {
5270
0
      bfd_set_error (bfd_error_file_too_big);
5271
0
      return false;
5272
0
    }
5273
2.14k
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5274
2.14k
  if (reloc_cache == NULL)
5275
0
    {
5276
0
      free (native_relocs);
5277
0
      return false;
5278
0
    }
5279
5280
2.33k
  for (idx = 0; idx < asect->reloc_count; idx++)
5281
2.31k
    {
5282
2.31k
      struct internal_reloc dst;
5283
2.31k
      void *src;
5284
#ifndef RELOC_PROCESSING
5285
      asymbol *ptr;
5286
#endif
5287
5288
2.31k
      cache_ptr = reloc_cache + idx;
5289
2.31k
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5290
5291
2.31k
      dst.r_offset = 0;
5292
2.31k
      bfd_coff_swap_reloc_in (abfd, src, &dst);
5293
5294
2.31k
#ifdef RELOC_PROCESSING
5295
2.31k
      RELOC_PROCESSING (cache_ptr, &dst, symbols, abfd, asect);
5296
#else
5297
      cache_ptr->address = dst.r_vaddr;
5298
5299
      if (dst.r_symndx != -1 && symbols != NULL)
5300
  {
5301
    if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
5302
      {
5303
        _bfd_error_handler
5304
    /* xgettext:c-format */
5305
    (_("%pB: warning: illegal symbol index %ld in relocs"),
5306
     abfd, dst.r_symndx);
5307
        cache_ptr->sym_ptr_ptr = &bfd_abs_section_ptr->symbol;
5308
        ptr = NULL;
5309
      }
5310
    else
5311
      {
5312
        cache_ptr->sym_ptr_ptr = (symbols
5313
          + obj_convert (abfd)[dst.r_symndx]);
5314
        ptr = *(cache_ptr->sym_ptr_ptr);
5315
      }
5316
  }
5317
      else
5318
  {
5319
    cache_ptr->sym_ptr_ptr = &bfd_abs_section_ptr->symbol;
5320
    ptr = NULL;
5321
  }
5322
5323
      /* The symbols definitions that we have read in have been
5324
   relocated as if their sections started at 0. But the offsets
5325
   refering to the symbols in the raw data have not been
5326
   modified, so we have to have a negative addend to compensate.
5327
5328
   Note that symbols which used to be common must be left alone.  */
5329
5330
      /* Calculate any reloc addend by looking at the symbol.  */
5331
      CALC_ADDEND (abfd, ptr, dst, cache_ptr);
5332
      (void) ptr;
5333
5334
      cache_ptr->address -= asect->vma;
5335
      /* !! cache_ptr->section = NULL;*/
5336
5337
      /* Fill in the cache_ptr->howto field from dst.r_type.  */
5338
      RTYPE2HOWTO (cache_ptr, &dst);
5339
#endif  /* RELOC_PROCESSING */
5340
5341
2.31k
      if (cache_ptr->howto == NULL)
5342
2.12k
  {
5343
2.12k
    _bfd_error_handler
5344
      /* xgettext:c-format */
5345
2.12k
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5346
2.12k
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5347
2.12k
    bfd_set_error (bfd_error_bad_value);
5348
2.12k
    free (native_relocs);
5349
2.12k
    return false;
5350
2.12k
  }
5351
2.31k
    }
5352
5353
21
  free (native_relocs);
5354
21
  asect->relocation = reloc_cache;
5355
21
  return true;
5356
2.14k
}
Unexecuted instantiation: coff-tic4x.c:coff_slurp_reloc_table
coff-tic54x.c:coff_slurp_reloc_table
Line
Count
Source
5246
9.18k
{
5247
9.18k
  bfd_byte *native_relocs;
5248
9.18k
  arelent *reloc_cache;
5249
9.18k
  arelent *cache_ptr;
5250
9.18k
  unsigned int idx;
5251
9.18k
  size_t amt;
5252
5253
9.18k
  if (asect->relocation)
5254
0
    return true;
5255
9.18k
  if (asect->reloc_count == 0)
5256
142
    return true;
5257
9.04k
  if (asect->flags & SEC_CONSTRUCTOR)
5258
0
    return true;
5259
9.04k
  if (!coff_slurp_symbol_table (abfd))
5260
7.65k
    return false;
5261
5262
1.38k
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5263
1.38k
               asect->reloc_count,
5264
1.38k
               bfd_coff_relsz (abfd));
5265
1.38k
  if (native_relocs == NULL)
5266
1.09k
    return false;
5267
5268
292
  if (_bfd_mul_overflow (asect->reloc_count, sizeof (arelent), &amt))
5269
0
    {
5270
0
      bfd_set_error (bfd_error_file_too_big);
5271
0
      return false;
5272
0
    }
5273
292
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5274
292
  if (reloc_cache == NULL)
5275
0
    {
5276
0
      free (native_relocs);
5277
0
      return false;
5278
0
    }
5279
5280
383
  for (idx = 0; idx < asect->reloc_count; idx++)
5281
365
    {
5282
365
      struct internal_reloc dst;
5283
365
      void *src;
5284
#ifndef RELOC_PROCESSING
5285
      asymbol *ptr;
5286
#endif
5287
5288
365
      cache_ptr = reloc_cache + idx;
5289
365
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5290
5291
365
      dst.r_offset = 0;
5292
365
      bfd_coff_swap_reloc_in (abfd, src, &dst);
5293
5294
365
#ifdef RELOC_PROCESSING
5295
365
      RELOC_PROCESSING (cache_ptr, &dst, symbols, abfd, asect);
5296
#else
5297
      cache_ptr->address = dst.r_vaddr;
5298
5299
      if (dst.r_symndx != -1 && symbols != NULL)
5300
  {
5301
    if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
5302
      {
5303
        _bfd_error_handler
5304
    /* xgettext:c-format */
5305
    (_("%pB: warning: illegal symbol index %ld in relocs"),
5306
     abfd, dst.r_symndx);
5307
        cache_ptr->sym_ptr_ptr = &bfd_abs_section_ptr->symbol;
5308
        ptr = NULL;
5309
      }
5310
    else
5311
      {
5312
        cache_ptr->sym_ptr_ptr = (symbols
5313
          + obj_convert (abfd)[dst.r_symndx]);
5314
        ptr = *(cache_ptr->sym_ptr_ptr);
5315
      }
5316
  }
5317
      else
5318
  {
5319
    cache_ptr->sym_ptr_ptr = &bfd_abs_section_ptr->symbol;
5320
    ptr = NULL;
5321
  }
5322
5323
      /* The symbols definitions that we have read in have been
5324
   relocated as if their sections started at 0. But the offsets
5325
   refering to the symbols in the raw data have not been
5326
   modified, so we have to have a negative addend to compensate.
5327
5328
   Note that symbols which used to be common must be left alone.  */
5329
5330
      /* Calculate any reloc addend by looking at the symbol.  */
5331
      CALC_ADDEND (abfd, ptr, dst, cache_ptr);
5332
      (void) ptr;
5333
5334
      cache_ptr->address -= asect->vma;
5335
      /* !! cache_ptr->section = NULL;*/
5336
5337
      /* Fill in the cache_ptr->howto field from dst.r_type.  */
5338
      RTYPE2HOWTO (cache_ptr, &dst);
5339
#endif  /* RELOC_PROCESSING */
5340
5341
365
      if (cache_ptr->howto == NULL)
5342
274
  {
5343
274
    _bfd_error_handler
5344
      /* xgettext:c-format */
5345
274
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5346
274
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5347
274
    bfd_set_error (bfd_error_bad_value);
5348
274
    free (native_relocs);
5349
274
    return false;
5350
274
  }
5351
365
    }
5352
5353
18
  free (native_relocs);
5354
18
  asect->relocation = reloc_cache;
5355
18
  return true;
5356
292
}
coff-z80.c:coff_slurp_reloc_table
Line
Count
Source
5246
9.52k
{
5247
9.52k
  bfd_byte *native_relocs;
5248
9.52k
  arelent *reloc_cache;
5249
9.52k
  arelent *cache_ptr;
5250
9.52k
  unsigned int idx;
5251
9.52k
  size_t amt;
5252
5253
9.52k
  if (asect->relocation)
5254
0
    return true;
5255
9.52k
  if (asect->reloc_count == 0)
5256
19
    return true;
5257
9.51k
  if (asect->flags & SEC_CONSTRUCTOR)
5258
0
    return true;
5259
9.51k
  if (!coff_slurp_symbol_table (abfd))
5260
6.58k
    return false;
5261
5262
2.93k
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5263
2.93k
               asect->reloc_count,
5264
2.93k
               bfd_coff_relsz (abfd));
5265
2.93k
  if (native_relocs == NULL)
5266
1.46k
    return false;
5267
5268
1.46k
  if (_bfd_mul_overflow (asect->reloc_count, sizeof (arelent), &amt))
5269
0
    {
5270
0
      bfd_set_error (bfd_error_file_too_big);
5271
0
      return false;
5272
0
    }
5273
1.46k
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5274
1.46k
  if (reloc_cache == NULL)
5275
0
    {
5276
0
      free (native_relocs);
5277
0
      return false;
5278
0
    }
5279
5280
29.9k
  for (idx = 0; idx < asect->reloc_count; idx++)
5281
29.7k
    {
5282
29.7k
      struct internal_reloc dst;
5283
29.7k
      void *src;
5284
#ifndef RELOC_PROCESSING
5285
      asymbol *ptr;
5286
#endif
5287
5288
29.7k
      cache_ptr = reloc_cache + idx;
5289
29.7k
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5290
5291
29.7k
      dst.r_offset = 0;
5292
29.7k
      bfd_coff_swap_reloc_in (abfd, src, &dst);
5293
5294
29.7k
#ifdef RELOC_PROCESSING
5295
29.7k
      RELOC_PROCESSING (cache_ptr, &dst, symbols, abfd, asect);
5296
#else
5297
      cache_ptr->address = dst.r_vaddr;
5298
5299
      if (dst.r_symndx != -1 && symbols != NULL)
5300
  {
5301
    if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
5302
      {
5303
        _bfd_error_handler
5304
    /* xgettext:c-format */
5305
    (_("%pB: warning: illegal symbol index %ld in relocs"),
5306
     abfd, dst.r_symndx);
5307
        cache_ptr->sym_ptr_ptr = &bfd_abs_section_ptr->symbol;
5308
        ptr = NULL;
5309
      }
5310
    else
5311
      {
5312
        cache_ptr->sym_ptr_ptr = (symbols
5313
          + obj_convert (abfd)[dst.r_symndx]);
5314
        ptr = *(cache_ptr->sym_ptr_ptr);
5315
      }
5316
  }
5317
      else
5318
  {
5319
    cache_ptr->sym_ptr_ptr = &bfd_abs_section_ptr->symbol;
5320
    ptr = NULL;
5321
  }
5322
5323
      /* The symbols definitions that we have read in have been
5324
   relocated as if their sections started at 0. But the offsets
5325
   refering to the symbols in the raw data have not been
5326
   modified, so we have to have a negative addend to compensate.
5327
5328
   Note that symbols which used to be common must be left alone.  */
5329
5330
      /* Calculate any reloc addend by looking at the symbol.  */
5331
      CALC_ADDEND (abfd, ptr, dst, cache_ptr);
5332
      (void) ptr;
5333
5334
      cache_ptr->address -= asect->vma;
5335
      /* !! cache_ptr->section = NULL;*/
5336
5337
      /* Fill in the cache_ptr->howto field from dst.r_type.  */
5338
      RTYPE2HOWTO (cache_ptr, &dst);
5339
#endif  /* RELOC_PROCESSING */
5340
5341
29.7k
      if (cache_ptr->howto == NULL)
5342
1.29k
  {
5343
1.29k
    _bfd_error_handler
5344
      /* xgettext:c-format */
5345
1.29k
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5346
1.29k
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5347
1.29k
    bfd_set_error (bfd_error_bad_value);
5348
1.29k
    free (native_relocs);
5349
1.29k
    return false;
5350
1.29k
  }
5351
29.7k
    }
5352
5353
162
  free (native_relocs);
5354
162
  asect->relocation = reloc_cache;
5355
162
  return true;
5356
1.46k
}
coff-z8k.c:coff_slurp_reloc_table
Line
Count
Source
5246
6.86k
{
5247
6.86k
  bfd_byte *native_relocs;
5248
6.86k
  arelent *reloc_cache;
5249
6.86k
  arelent *cache_ptr;
5250
6.86k
  unsigned int idx;
5251
6.86k
  size_t amt;
5252
5253
6.86k
  if (asect->relocation)
5254
0
    return true;
5255
6.86k
  if (asect->reloc_count == 0)
5256
14
    return true;
5257
6.84k
  if (asect->flags & SEC_CONSTRUCTOR)
5258
0
    return true;
5259
6.84k
  if (!coff_slurp_symbol_table (abfd))
5260
5.58k
    return false;
5261
5262
1.26k
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5263
1.26k
               asect->reloc_count,
5264
1.26k
               bfd_coff_relsz (abfd));
5265
1.26k
  if (native_relocs == NULL)
5266
928
    return false;
5267
5268
333
  if (_bfd_mul_overflow (asect->reloc_count, sizeof (arelent), &amt))
5269
0
    {
5270
0
      bfd_set_error (bfd_error_file_too_big);
5271
0
      return false;
5272
0
    }
5273
333
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5274
333
  if (reloc_cache == NULL)
5275
0
    {
5276
0
      free (native_relocs);
5277
0
      return false;
5278
0
    }
5279
5280
366
  for (idx = 0; idx < asect->reloc_count; idx++)
5281
360
    {
5282
360
      struct internal_reloc dst;
5283
360
      void *src;
5284
#ifndef RELOC_PROCESSING
5285
      asymbol *ptr;
5286
#endif
5287
5288
360
      cache_ptr = reloc_cache + idx;
5289
360
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5290
5291
360
      dst.r_offset = 0;
5292
360
      bfd_coff_swap_reloc_in (abfd, src, &dst);
5293
5294
360
#ifdef RELOC_PROCESSING
5295
360
      RELOC_PROCESSING (cache_ptr, &dst, symbols, abfd, asect);
5296
#else
5297
      cache_ptr->address = dst.r_vaddr;
5298
5299
      if (dst.r_symndx != -1 && symbols != NULL)
5300
  {
5301
    if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
5302
      {
5303
        _bfd_error_handler
5304
    /* xgettext:c-format */
5305
    (_("%pB: warning: illegal symbol index %ld in relocs"),
5306
     abfd, dst.r_symndx);
5307
        cache_ptr->sym_ptr_ptr = &bfd_abs_section_ptr->symbol;
5308
        ptr = NULL;
5309
      }
5310
    else
5311
      {
5312
        cache_ptr->sym_ptr_ptr = (symbols
5313
          + obj_convert (abfd)[dst.r_symndx]);
5314
        ptr = *(cache_ptr->sym_ptr_ptr);
5315
      }
5316
  }
5317
      else
5318
  {
5319
    cache_ptr->sym_ptr_ptr = &bfd_abs_section_ptr->symbol;
5320
    ptr = NULL;
5321
  }
5322
5323
      /* The symbols definitions that we have read in have been
5324
   relocated as if their sections started at 0. But the offsets
5325
   refering to the symbols in the raw data have not been
5326
   modified, so we have to have a negative addend to compensate.
5327
5328
   Note that symbols which used to be common must be left alone.  */
5329
5330
      /* Calculate any reloc addend by looking at the symbol.  */
5331
      CALC_ADDEND (abfd, ptr, dst, cache_ptr);
5332
      (void) ptr;
5333
5334
      cache_ptr->address -= asect->vma;
5335
      /* !! cache_ptr->section = NULL;*/
5336
5337
      /* Fill in the cache_ptr->howto field from dst.r_type.  */
5338
      RTYPE2HOWTO (cache_ptr, &dst);
5339
#endif  /* RELOC_PROCESSING */
5340
5341
360
      if (cache_ptr->howto == NULL)
5342
327
  {
5343
327
    _bfd_error_handler
5344
      /* xgettext:c-format */
5345
327
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5346
327
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5347
327
    bfd_set_error (bfd_error_bad_value);
5348
327
    free (native_relocs);
5349
327
    return false;
5350
327
  }
5351
360
    }
5352
5353
6
  free (native_relocs);
5354
6
  asect->relocation = reloc_cache;
5355
6
  return true;
5356
333
}
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
5246
67
{
5247
67
  bfd_byte *native_relocs;
5248
67
  arelent *reloc_cache;
5249
67
  arelent *cache_ptr;
5250
67
  unsigned int idx;
5251
67
  size_t amt;
5252
5253
67
  if (asect->relocation)
5254
0
    return true;
5255
67
  if (asect->reloc_count == 0)
5256
1
    return true;
5257
66
  if (asect->flags & SEC_CONSTRUCTOR)
5258
0
    return true;
5259
66
  if (!coff_slurp_symbol_table (abfd))
5260
1
    return false;
5261
5262
65
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5263
65
               asect->reloc_count,
5264
65
               bfd_coff_relsz (abfd));
5265
65
  if (native_relocs == NULL)
5266
5
    return false;
5267
5268
60
  if (_bfd_mul_overflow (asect->reloc_count, sizeof (arelent), &amt))
5269
0
    {
5270
0
      bfd_set_error (bfd_error_file_too_big);
5271
0
      return false;
5272
0
    }
5273
60
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5274
60
  if (reloc_cache == NULL)
5275
0
    {
5276
0
      free (native_relocs);
5277
0
      return false;
5278
0
    }
5279
5280
749
  for (idx = 0; idx < asect->reloc_count; idx++)
5281
725
    {
5282
725
      struct internal_reloc dst;
5283
725
      void *src;
5284
725
#ifndef RELOC_PROCESSING
5285
725
      asymbol *ptr;
5286
725
#endif
5287
5288
725
      cache_ptr = reloc_cache + idx;
5289
725
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5290
5291
725
      dst.r_offset = 0;
5292
725
      bfd_coff_swap_reloc_in (abfd, src, &dst);
5293
5294
#ifdef RELOC_PROCESSING
5295
      RELOC_PROCESSING (cache_ptr, &dst, symbols, abfd, asect);
5296
#else
5297
725
      cache_ptr->address = dst.r_vaddr;
5298
5299
725
      if (dst.r_symndx != -1 && symbols != NULL)
5300
591
  {
5301
591
    if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
5302
186
      {
5303
186
        _bfd_error_handler
5304
    /* xgettext:c-format */
5305
186
    (_("%pB: warning: illegal symbol index %ld in relocs"),
5306
186
     abfd, dst.r_symndx);
5307
186
        cache_ptr->sym_ptr_ptr = &bfd_abs_section_ptr->symbol;
5308
186
        ptr = NULL;
5309
186
      }
5310
405
    else
5311
405
      {
5312
405
        cache_ptr->sym_ptr_ptr = (symbols
5313
405
          + obj_convert (abfd)[dst.r_symndx]);
5314
405
        ptr = *(cache_ptr->sym_ptr_ptr);
5315
405
      }
5316
591
  }
5317
134
      else
5318
134
  {
5319
134
    cache_ptr->sym_ptr_ptr = &bfd_abs_section_ptr->symbol;
5320
134
    ptr = NULL;
5321
134
  }
5322
5323
      /* The symbols definitions that we have read in have been
5324
   relocated as if their sections started at 0. But the offsets
5325
   refering to the symbols in the raw data have not been
5326
   modified, so we have to have a negative addend to compensate.
5327
5328
   Note that symbols which used to be common must be left alone.  */
5329
5330
      /* Calculate any reloc addend by looking at the symbol.  */
5331
725
      CALC_ADDEND (abfd, ptr, dst, cache_ptr);
5332
725
      (void) ptr;
5333
5334
725
      cache_ptr->address -= asect->vma;
5335
      /* !! cache_ptr->section = NULL;*/
5336
5337
      /* Fill in the cache_ptr->howto field from dst.r_type.  */
5338
725
      RTYPE2HOWTO (cache_ptr, &dst);
5339
725
#endif  /* RELOC_PROCESSING */
5340
5341
725
      if (cache_ptr->howto == NULL)
5342
36
  {
5343
36
    _bfd_error_handler
5344
      /* xgettext:c-format */
5345
36
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5346
36
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5347
36
    bfd_set_error (bfd_error_bad_value);
5348
36
    free (native_relocs);
5349
36
    return false;
5350
36
  }
5351
725
    }
5352
5353
24
  free (native_relocs);
5354
24
  asect->relocation = reloc_cache;
5355
24
  return true;
5356
60
}
pe-mcore.c:coff_slurp_reloc_table
Line
Count
Source
5246
237
{
5247
237
  bfd_byte *native_relocs;
5248
237
  arelent *reloc_cache;
5249
237
  arelent *cache_ptr;
5250
237
  unsigned int idx;
5251
237
  size_t amt;
5252
5253
237
  if (asect->relocation)
5254
3
    return true;
5255
234
  if (asect->reloc_count == 0)
5256
7
    return true;
5257
227
  if (asect->flags & SEC_CONSTRUCTOR)
5258
0
    return true;
5259
227
  if (!coff_slurp_symbol_table (abfd))
5260
20
    return false;
5261
5262
207
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5263
207
               asect->reloc_count,
5264
207
               bfd_coff_relsz (abfd));
5265
207
  if (native_relocs == NULL)
5266
71
    return false;
5267
5268
136
  if (_bfd_mul_overflow (asect->reloc_count, sizeof (arelent), &amt))
5269
0
    {
5270
0
      bfd_set_error (bfd_error_file_too_big);
5271
0
      return false;
5272
0
    }
5273
136
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5274
136
  if (reloc_cache == NULL)
5275
0
    {
5276
0
      free (native_relocs);
5277
0
      return false;
5278
0
    }
5279
5280
1.06k
  for (idx = 0; idx < asect->reloc_count; idx++)
5281
1.00k
    {
5282
1.00k
      struct internal_reloc dst;
5283
1.00k
      void *src;
5284
1.00k
#ifndef RELOC_PROCESSING
5285
1.00k
      asymbol *ptr;
5286
1.00k
#endif
5287
5288
1.00k
      cache_ptr = reloc_cache + idx;
5289
1.00k
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5290
5291
1.00k
      dst.r_offset = 0;
5292
1.00k
      bfd_coff_swap_reloc_in (abfd, src, &dst);
5293
5294
#ifdef RELOC_PROCESSING
5295
      RELOC_PROCESSING (cache_ptr, &dst, symbols, abfd, asect);
5296
#else
5297
1.00k
      cache_ptr->address = dst.r_vaddr;
5298
5299
1.00k
      if (dst.r_symndx != -1 && symbols != NULL)
5300
957
  {
5301
957
    if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
5302
332
      {
5303
332
        _bfd_error_handler
5304
    /* xgettext:c-format */
5305
332
    (_("%pB: warning: illegal symbol index %ld in relocs"),
5306
332
     abfd, dst.r_symndx);
5307
332
        cache_ptr->sym_ptr_ptr = &bfd_abs_section_ptr->symbol;
5308
332
        ptr = NULL;
5309
332
      }
5310
625
    else
5311
625
      {
5312
625
        cache_ptr->sym_ptr_ptr = (symbols
5313
625
          + obj_convert (abfd)[dst.r_symndx]);
5314
625
        ptr = *(cache_ptr->sym_ptr_ptr);
5315
625
      }
5316
957
  }
5317
44
      else
5318
44
  {
5319
44
    cache_ptr->sym_ptr_ptr = &bfd_abs_section_ptr->symbol;
5320
44
    ptr = NULL;
5321
44
  }
5322
5323
      /* The symbols definitions that we have read in have been
5324
   relocated as if their sections started at 0. But the offsets
5325
   refering to the symbols in the raw data have not been
5326
   modified, so we have to have a negative addend to compensate.
5327
5328
   Note that symbols which used to be common must be left alone.  */
5329
5330
      /* Calculate any reloc addend by looking at the symbol.  */
5331
1.00k
      CALC_ADDEND (abfd, ptr, dst, cache_ptr);
5332
1.00k
      (void) ptr;
5333
5334
1.00k
      cache_ptr->address -= asect->vma;
5335
      /* !! cache_ptr->section = NULL;*/
5336
5337
      /* Fill in the cache_ptr->howto field from dst.r_type.  */
5338
1.00k
      RTYPE2HOWTO (cache_ptr, &dst);
5339
1.00k
#endif  /* RELOC_PROCESSING */
5340
5341
1.00k
      if (cache_ptr->howto == NULL)
5342
70
  {
5343
70
    _bfd_error_handler
5344
      /* xgettext:c-format */
5345
70
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5346
70
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5347
70
    bfd_set_error (bfd_error_bad_value);
5348
70
    free (native_relocs);
5349
70
    return false;
5350
70
  }
5351
1.00k
    }
5352
5353
66
  free (native_relocs);
5354
66
  asect->relocation = reloc_cache;
5355
66
  return true;
5356
136
}
pe-sh.c:coff_slurp_reloc_table
Line
Count
Source
5246
226
{
5247
226
  bfd_byte *native_relocs;
5248
226
  arelent *reloc_cache;
5249
226
  arelent *cache_ptr;
5250
226
  unsigned int idx;
5251
226
  size_t amt;
5252
5253
226
  if (asect->relocation)
5254
0
    return true;
5255
226
  if (asect->reloc_count == 0)
5256
4
    return true;
5257
222
  if (asect->flags & SEC_CONSTRUCTOR)
5258
0
    return true;
5259
222
  if (!coff_slurp_symbol_table (abfd))
5260
27
    return false;
5261
5262
195
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5263
195
               asect->reloc_count,
5264
195
               bfd_coff_relsz (abfd));
5265
195
  if (native_relocs == NULL)
5266
50
    return false;
5267
5268
145
  if (_bfd_mul_overflow (asect->reloc_count, sizeof (arelent), &amt))
5269
0
    {
5270
0
      bfd_set_error (bfd_error_file_too_big);
5271
0
      return false;
5272
0
    }
5273
145
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5274
145
  if (reloc_cache == NULL)
5275
0
    {
5276
0
      free (native_relocs);
5277
0
      return false;
5278
0
    }
5279
5280
1.77k
  for (idx = 0; idx < asect->reloc_count; idx++)
5281
1.75k
    {
5282
1.75k
      struct internal_reloc dst;
5283
1.75k
      void *src;
5284
1.75k
#ifndef RELOC_PROCESSING
5285
1.75k
      asymbol *ptr;
5286
1.75k
#endif
5287
5288
1.75k
      cache_ptr = reloc_cache + idx;
5289
1.75k
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5290
5291
1.75k
      dst.r_offset = 0;
5292
1.75k
      bfd_coff_swap_reloc_in (abfd, src, &dst);
5293
5294
#ifdef RELOC_PROCESSING
5295
      RELOC_PROCESSING (cache_ptr, &dst, symbols, abfd, asect);
5296
#else
5297
1.75k
      cache_ptr->address = dst.r_vaddr;
5298
5299
1.75k
      if (dst.r_symndx != -1 && symbols != NULL)
5300
1.25k
  {
5301
1.25k
    if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
5302
317
      {
5303
317
        _bfd_error_handler
5304
    /* xgettext:c-format */
5305
317
    (_("%pB: warning: illegal symbol index %ld in relocs"),
5306
317
     abfd, dst.r_symndx);
5307
317
        cache_ptr->sym_ptr_ptr = &bfd_abs_section_ptr->symbol;
5308
317
        ptr = NULL;
5309
317
      }
5310
941
    else
5311
941
      {
5312
941
        cache_ptr->sym_ptr_ptr = (symbols
5313
941
          + obj_convert (abfd)[dst.r_symndx]);
5314
941
        ptr = *(cache_ptr->sym_ptr_ptr);
5315
941
      }
5316
1.25k
  }
5317
494
      else
5318
494
  {
5319
494
    cache_ptr->sym_ptr_ptr = &bfd_abs_section_ptr->symbol;
5320
494
    ptr = NULL;
5321
494
  }
5322
5323
      /* The symbols definitions that we have read in have been
5324
   relocated as if their sections started at 0. But the offsets
5325
   refering to the symbols in the raw data have not been
5326
   modified, so we have to have a negative addend to compensate.
5327
5328
   Note that symbols which used to be common must be left alone.  */
5329
5330
      /* Calculate any reloc addend by looking at the symbol.  */
5331
1.75k
      CALC_ADDEND (abfd, ptr, dst, cache_ptr);
5332
1.75k
      (void) ptr;
5333
5334
1.75k
      cache_ptr->address -= asect->vma;
5335
      /* !! cache_ptr->section = NULL;*/
5336
5337
      /* Fill in the cache_ptr->howto field from dst.r_type.  */
5338
1.75k
      RTYPE2HOWTO (cache_ptr, &dst);
5339
1.75k
#endif  /* RELOC_PROCESSING */
5340
5341
1.75k
      if (cache_ptr->howto == NULL)
5342
126
  {
5343
126
    _bfd_error_handler
5344
      /* xgettext:c-format */
5345
126
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5346
126
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5347
126
    bfd_set_error (bfd_error_bad_value);
5348
126
    free (native_relocs);
5349
126
    return false;
5350
126
  }
5351
1.75k
    }
5352
5353
19
  free (native_relocs);
5354
19
  asect->relocation = reloc_cache;
5355
19
  return true;
5356
145
}
Unexecuted instantiation: pei-arm-wince.c:coff_slurp_reloc_table
pei-arm.c:coff_slurp_reloc_table
Line
Count
Source
5246
13
{
5247
13
  bfd_byte *native_relocs;
5248
13
  arelent *reloc_cache;
5249
13
  arelent *cache_ptr;
5250
13
  unsigned int idx;
5251
13
  size_t amt;
5252
5253
13
  if (asect->relocation)
5254
7
    return true;
5255
6
  if (asect->reloc_count == 0)
5256
6
    return true;
5257
0
  if (asect->flags & SEC_CONSTRUCTOR)
5258
0
    return true;
5259
0
  if (!coff_slurp_symbol_table (abfd))
5260
0
    return false;
5261
5262
0
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5263
0
               asect->reloc_count,
5264
0
               bfd_coff_relsz (abfd));
5265
0
  if (native_relocs == NULL)
5266
0
    return false;
5267
5268
0
  if (_bfd_mul_overflow (asect->reloc_count, sizeof (arelent), &amt))
5269
0
    {
5270
0
      bfd_set_error (bfd_error_file_too_big);
5271
0
      return false;
5272
0
    }
5273
0
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5274
0
  if (reloc_cache == NULL)
5275
0
    {
5276
0
      free (native_relocs);
5277
0
      return false;
5278
0
    }
5279
5280
0
  for (idx = 0; idx < asect->reloc_count; idx++)
5281
0
    {
5282
0
      struct internal_reloc dst;
5283
0
      void *src;
5284
0
#ifndef RELOC_PROCESSING
5285
0
      asymbol *ptr;
5286
0
#endif
5287
5288
0
      cache_ptr = reloc_cache + idx;
5289
0
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5290
5291
0
      dst.r_offset = 0;
5292
0
      bfd_coff_swap_reloc_in (abfd, src, &dst);
5293
5294
#ifdef RELOC_PROCESSING
5295
      RELOC_PROCESSING (cache_ptr, &dst, symbols, abfd, asect);
5296
#else
5297
0
      cache_ptr->address = dst.r_vaddr;
5298
5299
0
      if (dst.r_symndx != -1 && symbols != NULL)
5300
0
  {
5301
0
    if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
5302
0
      {
5303
0
        _bfd_error_handler
5304
    /* xgettext:c-format */
5305
0
    (_("%pB: warning: illegal symbol index %ld in relocs"),
5306
0
     abfd, dst.r_symndx);
5307
0
        cache_ptr->sym_ptr_ptr = &bfd_abs_section_ptr->symbol;
5308
0
        ptr = NULL;
5309
0
      }
5310
0
    else
5311
0
      {
5312
0
        cache_ptr->sym_ptr_ptr = (symbols
5313
0
          + obj_convert (abfd)[dst.r_symndx]);
5314
0
        ptr = *(cache_ptr->sym_ptr_ptr);
5315
0
      }
5316
0
  }
5317
0
      else
5318
0
  {
5319
0
    cache_ptr->sym_ptr_ptr = &bfd_abs_section_ptr->symbol;
5320
0
    ptr = NULL;
5321
0
  }
5322
5323
      /* The symbols definitions that we have read in have been
5324
   relocated as if their sections started at 0. But the offsets
5325
   refering to the symbols in the raw data have not been
5326
   modified, so we have to have a negative addend to compensate.
5327
5328
   Note that symbols which used to be common must be left alone.  */
5329
5330
      /* Calculate any reloc addend by looking at the symbol.  */
5331
0
      CALC_ADDEND (abfd, ptr, dst, cache_ptr);
5332
0
      (void) ptr;
5333
5334
0
      cache_ptr->address -= asect->vma;
5335
      /* !! cache_ptr->section = NULL;*/
5336
5337
      /* Fill in the cache_ptr->howto field from dst.r_type.  */
5338
0
      RTYPE2HOWTO (cache_ptr, &dst);
5339
0
#endif  /* RELOC_PROCESSING */
5340
5341
0
      if (cache_ptr->howto == NULL)
5342
0
  {
5343
0
    _bfd_error_handler
5344
      /* xgettext:c-format */
5345
0
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5346
0
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5347
0
    bfd_set_error (bfd_error_bad_value);
5348
0
    free (native_relocs);
5349
0
    return false;
5350
0
  }
5351
0
    }
5352
5353
0
  free (native_relocs);
5354
0
  asect->relocation = reloc_cache;
5355
0
  return true;
5356
0
}
pei-mcore.c:coff_slurp_reloc_table
Line
Count
Source
5246
1
{
5247
1
  bfd_byte *native_relocs;
5248
1
  arelent *reloc_cache;
5249
1
  arelent *cache_ptr;
5250
1
  unsigned int idx;
5251
1
  size_t amt;
5252
5253
1
  if (asect->relocation)
5254
0
    return true;
5255
1
  if (asect->reloc_count == 0)
5256
1
    return true;
5257
0
  if (asect->flags & SEC_CONSTRUCTOR)
5258
0
    return true;
5259
0
  if (!coff_slurp_symbol_table (abfd))
5260
0
    return false;
5261
5262
0
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5263
0
               asect->reloc_count,
5264
0
               bfd_coff_relsz (abfd));
5265
0
  if (native_relocs == NULL)
5266
0
    return false;
5267
5268
0
  if (_bfd_mul_overflow (asect->reloc_count, sizeof (arelent), &amt))
5269
0
    {
5270
0
      bfd_set_error (bfd_error_file_too_big);
5271
0
      return false;
5272
0
    }
5273
0
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5274
0
  if (reloc_cache == NULL)
5275
0
    {
5276
0
      free (native_relocs);
5277
0
      return false;
5278
0
    }
5279
5280
0
  for (idx = 0; idx < asect->reloc_count; idx++)
5281
0
    {
5282
0
      struct internal_reloc dst;
5283
0
      void *src;
5284
0
#ifndef RELOC_PROCESSING
5285
0
      asymbol *ptr;
5286
0
#endif
5287
5288
0
      cache_ptr = reloc_cache + idx;
5289
0
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5290
5291
0
      dst.r_offset = 0;
5292
0
      bfd_coff_swap_reloc_in (abfd, src, &dst);
5293
5294
#ifdef RELOC_PROCESSING
5295
      RELOC_PROCESSING (cache_ptr, &dst, symbols, abfd, asect);
5296
#else
5297
0
      cache_ptr->address = dst.r_vaddr;
5298
5299
0
      if (dst.r_symndx != -1 && symbols != NULL)
5300
0
  {
5301
0
    if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
5302
0
      {
5303
0
        _bfd_error_handler
5304
    /* xgettext:c-format */
5305
0
    (_("%pB: warning: illegal symbol index %ld in relocs"),
5306
0
     abfd, dst.r_symndx);
5307
0
        cache_ptr->sym_ptr_ptr = &bfd_abs_section_ptr->symbol;
5308
0
        ptr = NULL;
5309
0
      }
5310
0
    else
5311
0
      {
5312
0
        cache_ptr->sym_ptr_ptr = (symbols
5313
0
          + obj_convert (abfd)[dst.r_symndx]);
5314
0
        ptr = *(cache_ptr->sym_ptr_ptr);
5315
0
      }
5316
0
  }
5317
0
      else
5318
0
  {
5319
0
    cache_ptr->sym_ptr_ptr = &bfd_abs_section_ptr->symbol;
5320
0
    ptr = NULL;
5321
0
  }
5322
5323
      /* The symbols definitions that we have read in have been
5324
   relocated as if their sections started at 0. But the offsets
5325
   refering to the symbols in the raw data have not been
5326
   modified, so we have to have a negative addend to compensate.
5327
5328
   Note that symbols which used to be common must be left alone.  */
5329
5330
      /* Calculate any reloc addend by looking at the symbol.  */
5331
0
      CALC_ADDEND (abfd, ptr, dst, cache_ptr);
5332
0
      (void) ptr;
5333
5334
0
      cache_ptr->address -= asect->vma;
5335
      /* !! cache_ptr->section = NULL;*/
5336
5337
      /* Fill in the cache_ptr->howto field from dst.r_type.  */
5338
0
      RTYPE2HOWTO (cache_ptr, &dst);
5339
0
#endif  /* RELOC_PROCESSING */
5340
5341
0
      if (cache_ptr->howto == NULL)
5342
0
  {
5343
0
    _bfd_error_handler
5344
      /* xgettext:c-format */
5345
0
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5346
0
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5347
0
    bfd_set_error (bfd_error_bad_value);
5348
0
    free (native_relocs);
5349
0
    return false;
5350
0
  }
5351
0
    }
5352
5353
0
  free (native_relocs);
5354
0
  asect->relocation = reloc_cache;
5355
0
  return true;
5356
0
}
pei-sh.c:coff_slurp_reloc_table
Line
Count
Source
5246
69
{
5247
69
  bfd_byte *native_relocs;
5248
69
  arelent *reloc_cache;
5249
69
  arelent *cache_ptr;
5250
69
  unsigned int idx;
5251
69
  size_t amt;
5252
5253
69
  if (asect->relocation)
5254
68
    return true;
5255
1
  if (asect->reloc_count == 0)
5256
1
    return true;
5257
0
  if (asect->flags & SEC_CONSTRUCTOR)
5258
0
    return true;
5259
0
  if (!coff_slurp_symbol_table (abfd))
5260
0
    return false;
5261
5262
0
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5263
0
               asect->reloc_count,
5264
0
               bfd_coff_relsz (abfd));
5265
0
  if (native_relocs == NULL)
5266
0
    return false;
5267
5268
0
  if (_bfd_mul_overflow (asect->reloc_count, sizeof (arelent), &amt))
5269
0
    {
5270
0
      bfd_set_error (bfd_error_file_too_big);
5271
0
      return false;
5272
0
    }
5273
0
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5274
0
  if (reloc_cache == NULL)
5275
0
    {
5276
0
      free (native_relocs);
5277
0
      return false;
5278
0
    }
5279
5280
0
  for (idx = 0; idx < asect->reloc_count; idx++)
5281
0
    {
5282
0
      struct internal_reloc dst;
5283
0
      void *src;
5284
0
#ifndef RELOC_PROCESSING
5285
0
      asymbol *ptr;
5286
0
#endif
5287
5288
0
      cache_ptr = reloc_cache + idx;
5289
0
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5290
5291
0
      dst.r_offset = 0;
5292
0
      bfd_coff_swap_reloc_in (abfd, src, &dst);
5293
5294
#ifdef RELOC_PROCESSING
5295
      RELOC_PROCESSING (cache_ptr, &dst, symbols, abfd, asect);
5296
#else
5297
0
      cache_ptr->address = dst.r_vaddr;
5298
5299
0
      if (dst.r_symndx != -1 && symbols != NULL)
5300
0
  {
5301
0
    if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
5302
0
      {
5303
0
        _bfd_error_handler
5304
    /* xgettext:c-format */
5305
0
    (_("%pB: warning: illegal symbol index %ld in relocs"),
5306
0
     abfd, dst.r_symndx);
5307
0
        cache_ptr->sym_ptr_ptr = &bfd_abs_section_ptr->symbol;
5308
0
        ptr = NULL;
5309
0
      }
5310
0
    else
5311
0
      {
5312
0
        cache_ptr->sym_ptr_ptr = (symbols
5313
0
          + obj_convert (abfd)[dst.r_symndx]);
5314
0
        ptr = *(cache_ptr->sym_ptr_ptr);
5315
0
      }
5316
0
  }
5317
0
      else
5318
0
  {
5319
0
    cache_ptr->sym_ptr_ptr = &bfd_abs_section_ptr->symbol;
5320
0
    ptr = NULL;
5321
0
  }
5322
5323
      /* The symbols definitions that we have read in have been
5324
   relocated as if their sections started at 0. But the offsets
5325
   refering to the symbols in the raw data have not been
5326
   modified, so we have to have a negative addend to compensate.
5327
5328
   Note that symbols which used to be common must be left alone.  */
5329
5330
      /* Calculate any reloc addend by looking at the symbol.  */
5331
0
      CALC_ADDEND (abfd, ptr, dst, cache_ptr);
5332
0
      (void) ptr;
5333
5334
0
      cache_ptr->address -= asect->vma;
5335
      /* !! cache_ptr->section = NULL;*/
5336
5337
      /* Fill in the cache_ptr->howto field from dst.r_type.  */
5338
0
      RTYPE2HOWTO (cache_ptr, &dst);
5339
0
#endif  /* RELOC_PROCESSING */
5340
5341
0
      if (cache_ptr->howto == NULL)
5342
0
  {
5343
0
    _bfd_error_handler
5344
      /* xgettext:c-format */
5345
0
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5346
0
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5347
0
    bfd_set_error (bfd_error_bad_value);
5348
0
    free (native_relocs);
5349
0
    return false;
5350
0
  }
5351
0
    }
5352
5353
0
  free (native_relocs);
5354
0
  asect->relocation = reloc_cache;
5355
0
  return true;
5356
0
}
5357
5358
#ifndef coff_rtype_to_howto
5359
#ifdef RTYPE2HOWTO
5360
5361
/* Get the howto structure for a reloc.  This is only used if the file
5362
   including this one defines coff_relocate_section to be
5363
   _bfd_coff_generic_relocate_section, so it is OK if it does not
5364
   always work.  It is the responsibility of the including file to
5365
   make sure it is reasonable if it is needed.  */
5366
5367
static reloc_howto_type *
5368
coff_rtype_to_howto (bfd *abfd ATTRIBUTE_UNUSED,
5369
         asection *sec ATTRIBUTE_UNUSED,
5370
         struct internal_reloc *rel ATTRIBUTE_UNUSED,
5371
         struct coff_link_hash_entry *h ATTRIBUTE_UNUSED,
5372
         struct internal_syment *sym ATTRIBUTE_UNUSED,
5373
         bfd_vma *addendp ATTRIBUTE_UNUSED)
5374
0
{
5375
0
  arelent genrel;
5376
5377
0
  genrel.howto = NULL;
5378
0
  RTYPE2HOWTO (&genrel, rel);
5379
0
  return genrel.howto;
5380
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: pei-riscv64.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
5381
5382
#else /* ! defined (RTYPE2HOWTO) */
5383
5384
#define coff_rtype_to_howto NULL
5385
5386
#endif /* ! defined (RTYPE2HOWTO) */
5387
#endif /* ! defined (coff_rtype_to_howto) */
5388
5389
/* This is stupid.  This function should be a boolean predicate.  */
5390
5391
static long
5392
coff_canonicalize_reloc (bfd * abfd,
5393
       sec_ptr section,
5394
       arelent ** relptr,
5395
       asymbol ** symbols)
5396
63.3k
{
5397
63.3k
  arelent *tblptr = section->relocation;
5398
63.3k
  unsigned int count = 0;
5399
5400
63.3k
  if (section->flags & SEC_CONSTRUCTOR)
5401
0
    {
5402
      /* This section has relocs made up by us, they are not in the
5403
   file, so take them out of their chain and place them into
5404
   the data area provided.  */
5405
0
      arelent_chain *chain = section->constructor_chain;
5406
5407
0
      for (count = 0; count < section->reloc_count; count++)
5408
0
  {
5409
0
    *relptr++ = &chain->relent;
5410
0
    chain = chain->next;
5411
0
  }
5412
0
    }
5413
63.3k
  else
5414
63.3k
    {
5415
63.3k
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5416
60.0k
  return -1;
5417
5418
3.28k
      tblptr = section->relocation;
5419
5420
18.4k
      for (; count++ < section->reloc_count;)
5421
15.1k
  *relptr++ = tblptr++;
5422
3.28k
    }
5423
3.28k
  *relptr = 0;
5424
3.28k
  return section->reloc_count;
5425
63.3k
}
pei-i386.c:coff_canonicalize_reloc
Line
Count
Source
5396
34
{
5397
34
  arelent *tblptr = section->relocation;
5398
34
  unsigned int count = 0;
5399
5400
34
  if (section->flags & SEC_CONSTRUCTOR)
5401
0
    {
5402
      /* This section has relocs made up by us, they are not in the
5403
   file, so take them out of their chain and place them into
5404
   the data area provided.  */
5405
0
      arelent_chain *chain = section->constructor_chain;
5406
5407
0
      for (count = 0; count < section->reloc_count; count++)
5408
0
  {
5409
0
    *relptr++ = &chain->relent;
5410
0
    chain = chain->next;
5411
0
  }
5412
0
    }
5413
34
  else
5414
34
    {
5415
34
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5416
0
  return -1;
5417
5418
34
      tblptr = section->relocation;
5419
5420
63
      for (; count++ < section->reloc_count;)
5421
29
  *relptr++ = tblptr++;
5422
34
    }
5423
34
  *relptr = 0;
5424
34
  return section->reloc_count;
5425
34
}
pe-x86_64.c:coff_canonicalize_reloc
Line
Count
Source
5396
556
{
5397
556
  arelent *tblptr = section->relocation;
5398
556
  unsigned int count = 0;
5399
5400
556
  if (section->flags & SEC_CONSTRUCTOR)
5401
0
    {
5402
      /* This section has relocs made up by us, they are not in the
5403
   file, so take them out of their chain and place them into
5404
   the data area provided.  */
5405
0
      arelent_chain *chain = section->constructor_chain;
5406
5407
0
      for (count = 0; count < section->reloc_count; count++)
5408
0
  {
5409
0
    *relptr++ = &chain->relent;
5410
0
    chain = chain->next;
5411
0
  }
5412
0
    }
5413
556
  else
5414
556
    {
5415
556
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5416
395
  return -1;
5417
5418
161
      tblptr = section->relocation;
5419
5420
1.57k
      for (; count++ < section->reloc_count;)
5421
1.41k
  *relptr++ = tblptr++;
5422
161
    }
5423
161
  *relptr = 0;
5424
161
  return section->reloc_count;
5425
556
}
pei-x86_64.c:coff_canonicalize_reloc
Line
Count
Source
5396
60
{
5397
60
  arelent *tblptr = section->relocation;
5398
60
  unsigned int count = 0;
5399
5400
60
  if (section->flags & SEC_CONSTRUCTOR)
5401
0
    {
5402
      /* This section has relocs made up by us, they are not in the
5403
   file, so take them out of their chain and place them into
5404
   the data area provided.  */
5405
0
      arelent_chain *chain = section->constructor_chain;
5406
5407
0
      for (count = 0; count < section->reloc_count; count++)
5408
0
  {
5409
0
    *relptr++ = &chain->relent;
5410
0
    chain = chain->next;
5411
0
  }
5412
0
    }
5413
60
  else
5414
60
    {
5415
60
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5416
0
  return -1;
5417
5418
60
      tblptr = section->relocation;
5419
5420
79
      for (; count++ < section->reloc_count;)
5421
19
  *relptr++ = tblptr++;
5422
60
    }
5423
60
  *relptr = 0;
5424
60
  return section->reloc_count;
5425
60
}
coff-x86_64.c:coff_canonicalize_reloc
Line
Count
Source
5396
12.5k
{
5397
12.5k
  arelent *tblptr = section->relocation;
5398
12.5k
  unsigned int count = 0;
5399
5400
12.5k
  if (section->flags & SEC_CONSTRUCTOR)
5401
0
    {
5402
      /* This section has relocs made up by us, they are not in the
5403
   file, so take them out of their chain and place them into
5404
   the data area provided.  */
5405
0
      arelent_chain *chain = section->constructor_chain;
5406
5407
0
      for (count = 0; count < section->reloc_count; count++)
5408
0
  {
5409
0
    *relptr++ = &chain->relent;
5410
0
    chain = chain->next;
5411
0
  }
5412
0
    }
5413
12.5k
  else
5414
12.5k
    {
5415
12.5k
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5416
10.7k
  return -1;
5417
5418
1.82k
      tblptr = section->relocation;
5419
5420
6.35k
      for (; count++ < section->reloc_count;)
5421
4.53k
  *relptr++ = tblptr++;
5422
1.82k
    }
5423
1.82k
  *relptr = 0;
5424
1.82k
  return section->reloc_count;
5425
12.5k
}
coff64-rs6000.c:coff_canonicalize_reloc
Line
Count
Source
5396
1.71k
{
5397
1.71k
  arelent *tblptr = section->relocation;
5398
1.71k
  unsigned int count = 0;
5399
5400
1.71k
  if (section->flags & SEC_CONSTRUCTOR)
5401
0
    {
5402
      /* This section has relocs made up by us, they are not in the
5403
   file, so take them out of their chain and place them into
5404
   the data area provided.  */
5405
0
      arelent_chain *chain = section->constructor_chain;
5406
5407
0
      for (count = 0; count < section->reloc_count; count++)
5408
0
  {
5409
0
    *relptr++ = &chain->relent;
5410
0
    chain = chain->next;
5411
0
  }
5412
0
    }
5413
1.71k
  else
5414
1.71k
    {
5415
1.71k
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5416
1.69k
  return -1;
5417
5418
12
      tblptr = section->relocation;
5419
5420
12
      for (; count++ < section->reloc_count;)
5421
0
  *relptr++ = tblptr++;
5422
12
    }
5423
12
  *relptr = 0;
5424
12
  return section->reloc_count;
5425
1.71k
}
pe-aarch64.c:coff_canonicalize_reloc
Line
Count
Source
5396
504
{
5397
504
  arelent *tblptr = section->relocation;
5398
504
  unsigned int count = 0;
5399
5400
504
  if (section->flags & SEC_CONSTRUCTOR)
5401
0
    {
5402
      /* This section has relocs made up by us, they are not in the
5403
   file, so take them out of their chain and place them into
5404
   the data area provided.  */
5405
0
      arelent_chain *chain = section->constructor_chain;
5406
5407
0
      for (count = 0; count < section->reloc_count; count++)
5408
0
  {
5409
0
    *relptr++ = &chain->relent;
5410
0
    chain = chain->next;
5411
0
  }
5412
0
    }
5413
504
  else
5414
504
    {
5415
504
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5416
415
  return -1;
5417
5418
89
      tblptr = section->relocation;
5419
5420
346
      for (; count++ < section->reloc_count;)
5421
257
  *relptr++ = tblptr++;
5422
89
    }
5423
89
  *relptr = 0;
5424
89
  return section->reloc_count;
5425
504
}
pei-aarch64.c:coff_canonicalize_reloc
Line
Count
Source
5396
31
{
5397
31
  arelent *tblptr = section->relocation;
5398
31
  unsigned int count = 0;
5399
5400
31
  if (section->flags & SEC_CONSTRUCTOR)
5401
0
    {
5402
      /* This section has relocs made up by us, they are not in the
5403
   file, so take them out of their chain and place them into
5404
   the data area provided.  */
5405
0
      arelent_chain *chain = section->constructor_chain;
5406
5407
0
      for (count = 0; count < section->reloc_count; count++)
5408
0
  {
5409
0
    *relptr++ = &chain->relent;
5410
0
    chain = chain->next;
5411
0
  }
5412
0
    }
5413
31
  else
5414
31
    {
5415
31
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5416
0
  return -1;
5417
5418
31
      tblptr = section->relocation;
5419
5420
51
      for (; count++ < section->reloc_count;)
5421
20
  *relptr++ = tblptr++;
5422
31
    }
5423
31
  *relptr = 0;
5424
31
  return section->reloc_count;
5425
31
}
pei-ia64.c:coff_canonicalize_reloc
Line
Count
Source
5396
1
{
5397
1
  arelent *tblptr = section->relocation;
5398
1
  unsigned int count = 0;
5399
5400
1
  if (section->flags & SEC_CONSTRUCTOR)
5401
0
    {
5402
      /* This section has relocs made up by us, they are not in the
5403
   file, so take them out of their chain and place them into
5404
   the data area provided.  */
5405
0
      arelent_chain *chain = section->constructor_chain;
5406
5407
0
      for (count = 0; count < section->reloc_count; count++)
5408
0
  {
5409
0
    *relptr++ = &chain->relent;
5410
0
    chain = chain->next;
5411
0
  }
5412
0
    }
5413
1
  else
5414
1
    {
5415
1
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5416
0
  return -1;
5417
5418
1
      tblptr = section->relocation;
5419
5420
1
      for (; count++ < section->reloc_count;)
5421
0
  *relptr++ = tblptr++;
5422
1
    }
5423
1
  *relptr = 0;
5424
1
  return section->reloc_count;
5425
1
}
pei-loongarch64.c:coff_canonicalize_reloc
Line
Count
Source
5396
24
{
5397
24
  arelent *tblptr = section->relocation;
5398
24
  unsigned int count = 0;
5399
5400
24
  if (section->flags & SEC_CONSTRUCTOR)
5401
0
    {
5402
      /* This section has relocs made up by us, they are not in the
5403
   file, so take them out of their chain and place them into
5404
   the data area provided.  */
5405
0
      arelent_chain *chain = section->constructor_chain;
5406
5407
0
      for (count = 0; count < section->reloc_count; count++)
5408
0
  {
5409
0
    *relptr++ = &chain->relent;
5410
0
    chain = chain->next;
5411
0
  }
5412
0
    }
5413
24
  else
5414
24
    {
5415
24
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5416
0
  return -1;
5417
5418
24
      tblptr = section->relocation;
5419
5420
45
      for (; count++ < section->reloc_count;)
5421
21
  *relptr++ = tblptr++;
5422
24
    }
5423
24
  *relptr = 0;
5424
24
  return section->reloc_count;
5425
24
}
pei-riscv64.c:coff_canonicalize_reloc
Line
Count
Source
5396
37
{
5397
37
  arelent *tblptr = section->relocation;
5398
37
  unsigned int count = 0;
5399
5400
37
  if (section->flags & SEC_CONSTRUCTOR)
5401
0
    {
5402
      /* This section has relocs made up by us, they are not in the
5403
   file, so take them out of their chain and place them into
5404
   the data area provided.  */
5405
0
      arelent_chain *chain = section->constructor_chain;
5406
5407
0
      for (count = 0; count < section->reloc_count; count++)
5408
0
  {
5409
0
    *relptr++ = &chain->relent;
5410
0
    chain = chain->next;
5411
0
  }
5412
0
    }
5413
37
  else
5414
37
    {
5415
37
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5416
0
  return -1;
5417
5418
37
      tblptr = section->relocation;
5419
5420
64
      for (; count++ < section->reloc_count;)
5421
27
  *relptr++ = tblptr++;
5422
37
    }
5423
37
  *relptr = 0;
5424
37
  return section->reloc_count;
5425
37
}
Unexecuted instantiation: cf-i386lynx.c:coff_canonicalize_reloc
Unexecuted instantiation: coff-go32.c:coff_canonicalize_reloc
Unexecuted instantiation: coff-i386.c:coff_canonicalize_reloc
coff-rs6000.c:coff_canonicalize_reloc
Line
Count
Source
5396
7.97k
{
5397
7.97k
  arelent *tblptr = section->relocation;
5398
7.97k
  unsigned int count = 0;
5399
5400
7.97k
  if (section->flags & SEC_CONSTRUCTOR)
5401
0
    {
5402
      /* This section has relocs made up by us, they are not in the
5403
   file, so take them out of their chain and place them into
5404
   the data area provided.  */
5405
0
      arelent_chain *chain = section->constructor_chain;
5406
5407
0
      for (count = 0; count < section->reloc_count; count++)
5408
0
  {
5409
0
    *relptr++ = &chain->relent;
5410
0
    chain = chain->next;
5411
0
  }
5412
0
    }
5413
7.97k
  else
5414
7.97k
    {
5415
7.97k
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5416
7.94k
  return -1;
5417
5418
32
      tblptr = section->relocation;
5419
5420
32
      for (; count++ < section->reloc_count;)
5421
0
  *relptr++ = tblptr++;
5422
32
    }
5423
32
  *relptr = 0;
5424
32
  return section->reloc_count;
5425
7.97k
}
coff-sh.c:coff_canonicalize_reloc
Line
Count
Source
5396
3.58k
{
5397
3.58k
  arelent *tblptr = section->relocation;
5398
3.58k
  unsigned int count = 0;
5399
5400
3.58k
  if (section->flags & SEC_CONSTRUCTOR)
5401
0
    {
5402
      /* This section has relocs made up by us, they are not in the
5403
   file, so take them out of their chain and place them into
5404
   the data area provided.  */
5405
0
      arelent_chain *chain = section->constructor_chain;
5406
5407
0
      for (count = 0; count < section->reloc_count; count++)
5408
0
  {
5409
0
    *relptr++ = &chain->relent;
5410
0
    chain = chain->next;
5411
0
  }
5412
0
    }
5413
3.58k
  else
5414
3.58k
    {
5415
3.58k
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5416
3.26k
  return -1;
5417
5418
316
      tblptr = section->relocation;
5419
5420
1.28k
      for (; count++ < section->reloc_count;)
5421
964
  *relptr++ = tblptr++;
5422
316
    }
5423
316
  *relptr = 0;
5424
316
  return section->reloc_count;
5425
3.58k
}
Unexecuted instantiation: coff-stgo32.c:coff_canonicalize_reloc
coff-tic30.c:coff_canonicalize_reloc
Line
Count
Source
5396
10.0k
{
5397
10.0k
  arelent *tblptr = section->relocation;
5398
10.0k
  unsigned int count = 0;
5399
5400
10.0k
  if (section->flags & SEC_CONSTRUCTOR)
5401
0
    {
5402
      /* This section has relocs made up by us, they are not in the
5403
   file, so take them out of their chain and place them into
5404
   the data area provided.  */
5405
0
      arelent_chain *chain = section->constructor_chain;
5406
5407
0
      for (count = 0; count < section->reloc_count; count++)
5408
0
  {
5409
0
    *relptr++ = &chain->relent;
5410
0
    chain = chain->next;
5411
0
  }
5412
0
    }
5413
10.0k
  else
5414
10.0k
    {
5415
10.0k
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5416
9.98k
  return -1;
5417
5418
101
      tblptr = section->relocation;
5419
5420
165
      for (; count++ < section->reloc_count;)
5421
64
  *relptr++ = tblptr++;
5422
101
    }
5423
101
  *relptr = 0;
5424
101
  return section->reloc_count;
5425
10.0k
}
Unexecuted instantiation: coff-tic4x.c:coff_canonicalize_reloc
coff-tic54x.c:coff_canonicalize_reloc
Line
Count
Source
5396
9.18k
{
5397
9.18k
  arelent *tblptr = section->relocation;
5398
9.18k
  unsigned int count = 0;
5399
5400
9.18k
  if (section->flags & SEC_CONSTRUCTOR)
5401
0
    {
5402
      /* This section has relocs made up by us, they are not in the
5403
   file, so take them out of their chain and place them into
5404
   the data area provided.  */
5405
0
      arelent_chain *chain = section->constructor_chain;
5406
5407
0
      for (count = 0; count < section->reloc_count; count++)
5408
0
  {
5409
0
    *relptr++ = &chain->relent;
5410
0
    chain = chain->next;
5411
0
  }
5412
0
    }
5413
9.18k
  else
5414
9.18k
    {
5415
9.18k
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5416
9.02k
  return -1;
5417
5418
160
      tblptr = section->relocation;
5419
5420
186
      for (; count++ < section->reloc_count;)
5421
26
  *relptr++ = tblptr++;
5422
160
    }
5423
160
  *relptr = 0;
5424
160
  return section->reloc_count;
5425
9.18k
}
coff-z80.c:coff_canonicalize_reloc
Line
Count
Source
5396
9.52k
{
5397
9.52k
  arelent *tblptr = section->relocation;
5398
9.52k
  unsigned int count = 0;
5399
5400
9.52k
  if (section->flags & SEC_CONSTRUCTOR)
5401
0
    {
5402
      /* This section has relocs made up by us, they are not in the
5403
   file, so take them out of their chain and place them into
5404
   the data area provided.  */
5405
0
      arelent_chain *chain = section->constructor_chain;
5406
5407
0
      for (count = 0; count < section->reloc_count; count++)
5408
0
  {
5409
0
    *relptr++ = &chain->relent;
5410
0
    chain = chain->next;
5411
0
  }
5412
0
    }
5413
9.52k
  else
5414
9.52k
    {
5415
9.52k
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5416
9.34k
  return -1;
5417
5418
181
      tblptr = section->relocation;
5419
5420
6.11k
      for (; count++ < section->reloc_count;)
5421
5.93k
  *relptr++ = tblptr++;
5422
181
    }
5423
181
  *relptr = 0;
5424
181
  return section->reloc_count;
5425
9.52k
}
coff-z8k.c:coff_canonicalize_reloc
Line
Count
Source
5396
6.86k
{
5397
6.86k
  arelent *tblptr = section->relocation;
5398
6.86k
  unsigned int count = 0;
5399
5400
6.86k
  if (section->flags & SEC_CONSTRUCTOR)
5401
0
    {
5402
      /* This section has relocs made up by us, they are not in the
5403
   file, so take them out of their chain and place them into
5404
   the data area provided.  */
5405
0
      arelent_chain *chain = section->constructor_chain;
5406
5407
0
      for (count = 0; count < section->reloc_count; count++)
5408
0
  {
5409
0
    *relptr++ = &chain->relent;
5410
0
    chain = chain->next;
5411
0
  }
5412
0
    }
5413
6.86k
  else
5414
6.86k
    {
5415
6.86k
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5416
6.84k
  return -1;
5417
5418
20
      tblptr = section->relocation;
5419
5420
27
      for (; count++ < section->reloc_count;)
5421
7
  *relptr++ = tblptr++;
5422
20
    }
5423
20
  *relptr = 0;
5424
20
  return section->reloc_count;
5425
6.86k
}
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
5396
67
{
5397
67
  arelent *tblptr = section->relocation;
5398
67
  unsigned int count = 0;
5399
5400
67
  if (section->flags & SEC_CONSTRUCTOR)
5401
0
    {
5402
      /* This section has relocs made up by us, they are not in the
5403
   file, so take them out of their chain and place them into
5404
   the data area provided.  */
5405
0
      arelent_chain *chain = section->constructor_chain;
5406
5407
0
      for (count = 0; count < section->reloc_count; count++)
5408
0
  {
5409
0
    *relptr++ = &chain->relent;
5410
0
    chain = chain->next;
5411
0
  }
5412
0
    }
5413
67
  else
5414
67
    {
5415
67
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5416
42
  return -1;
5417
5418
25
      tblptr = section->relocation;
5419
5420
427
      for (; count++ < section->reloc_count;)
5421
402
  *relptr++ = tblptr++;
5422
25
    }
5423
25
  *relptr = 0;
5424
25
  return section->reloc_count;
5425
67
}
pe-mcore.c:coff_canonicalize_reloc
Line
Count
Source
5396
237
{
5397
237
  arelent *tblptr = section->relocation;
5398
237
  unsigned int count = 0;
5399
5400
237
  if (section->flags & SEC_CONSTRUCTOR)
5401
0
    {
5402
      /* This section has relocs made up by us, they are not in the
5403
   file, so take them out of their chain and place them into
5404
   the data area provided.  */
5405
0
      arelent_chain *chain = section->constructor_chain;
5406
5407
0
      for (count = 0; count < section->reloc_count; count++)
5408
0
  {
5409
0
    *relptr++ = &chain->relent;
5410
0
    chain = chain->next;
5411
0
  }
5412
0
    }
5413
237
  else
5414
237
    {
5415
237
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5416
161
  return -1;
5417
5418
76
      tblptr = section->relocation;
5419
5420
846
      for (; count++ < section->reloc_count;)
5421
770
  *relptr++ = tblptr++;
5422
76
    }
5423
76
  *relptr = 0;
5424
76
  return section->reloc_count;
5425
237
}
pe-sh.c:coff_canonicalize_reloc
Line
Count
Source
5396
226
{
5397
226
  arelent *tblptr = section->relocation;
5398
226
  unsigned int count = 0;
5399
5400
226
  if (section->flags & SEC_CONSTRUCTOR)
5401
0
    {
5402
      /* This section has relocs made up by us, they are not in the
5403
   file, so take them out of their chain and place them into
5404
   the data area provided.  */
5405
0
      arelent_chain *chain = section->constructor_chain;
5406
5407
0
      for (count = 0; count < section->reloc_count; count++)
5408
0
  {
5409
0
    *relptr++ = &chain->relent;
5410
0
    chain = chain->next;
5411
0
  }
5412
0
    }
5413
226
  else
5414
226
    {
5415
226
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5416
203
  return -1;
5417
5418
23
      tblptr = section->relocation;
5419
5420
576
      for (; count++ < section->reloc_count;)
5421
553
  *relptr++ = tblptr++;
5422
23
    }
5423
23
  *relptr = 0;
5424
23
  return section->reloc_count;
5425
226
}
Unexecuted instantiation: pei-arm-wince.c:coff_canonicalize_reloc
pei-arm.c:coff_canonicalize_reloc
Line
Count
Source
5396
13
{
5397
13
  arelent *tblptr = section->relocation;
5398
13
  unsigned int count = 0;
5399
5400
13
  if (section->flags & SEC_CONSTRUCTOR)
5401
0
    {
5402
      /* This section has relocs made up by us, they are not in the
5403
   file, so take them out of their chain and place them into
5404
   the data area provided.  */
5405
0
      arelent_chain *chain = section->constructor_chain;
5406
5407
0
      for (count = 0; count < section->reloc_count; count++)
5408
0
  {
5409
0
    *relptr++ = &chain->relent;
5410
0
    chain = chain->next;
5411
0
  }
5412
0
    }
5413
13
  else
5414
13
    {
5415
13
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5416
0
  return -1;
5417
5418
13
      tblptr = section->relocation;
5419
5420
20
      for (; count++ < section->reloc_count;)
5421
7
  *relptr++ = tblptr++;
5422
13
    }
5423
13
  *relptr = 0;
5424
13
  return section->reloc_count;
5425
13
}
pei-mcore.c:coff_canonicalize_reloc
Line
Count
Source
5396
1
{
5397
1
  arelent *tblptr = section->relocation;
5398
1
  unsigned int count = 0;
5399
5400
1
  if (section->flags & SEC_CONSTRUCTOR)
5401
0
    {
5402
      /* This section has relocs made up by us, they are not in the
5403
   file, so take them out of their chain and place them into
5404
   the data area provided.  */
5405
0
      arelent_chain *chain = section->constructor_chain;
5406
5407
0
      for (count = 0; count < section->reloc_count; count++)
5408
0
  {
5409
0
    *relptr++ = &chain->relent;
5410
0
    chain = chain->next;
5411
0
  }
5412
0
    }
5413
1
  else
5414
1
    {
5415
1
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5416
0
  return -1;
5417
5418
1
      tblptr = section->relocation;
5419
5420
1
      for (; count++ < section->reloc_count;)
5421
0
  *relptr++ = tblptr++;
5422
1
    }
5423
1
  *relptr = 0;
5424
1
  return section->reloc_count;
5425
1
}
pei-sh.c:coff_canonicalize_reloc
Line
Count
Source
5396
69
{
5397
69
  arelent *tblptr = section->relocation;
5398
69
  unsigned int count = 0;
5399
5400
69
  if (section->flags & SEC_CONSTRUCTOR)
5401
0
    {
5402
      /* This section has relocs made up by us, they are not in the
5403
   file, so take them out of their chain and place them into
5404
   the data area provided.  */
5405
0
      arelent_chain *chain = section->constructor_chain;
5406
5407
0
      for (count = 0; count < section->reloc_count; count++)
5408
0
  {
5409
0
    *relptr++ = &chain->relent;
5410
0
    chain = chain->next;
5411
0
  }
5412
0
    }
5413
69
  else
5414
69
    {
5415
69
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5416
0
  return -1;
5417
5418
69
      tblptr = section->relocation;
5419
5420
137
      for (; count++ < section->reloc_count;)
5421
68
  *relptr++ = tblptr++;
5422
69
    }
5423
69
  *relptr = 0;
5424
69
  return section->reloc_count;
5425
69
}
5426
5427
#ifndef coff_set_reloc
5428
#define coff_set_reloc _bfd_generic_set_reloc
5429
#endif
5430
5431
#ifndef coff_reloc16_estimate
5432
#define coff_reloc16_estimate dummy_reloc16_estimate
5433
5434
static int
5435
dummy_reloc16_estimate (bfd *abfd ATTRIBUTE_UNUSED,
5436
      asection *input_section ATTRIBUTE_UNUSED,
5437
      arelent *reloc ATTRIBUTE_UNUSED,
5438
      unsigned int shrink ATTRIBUTE_UNUSED,
5439
      struct bfd_link_info *link_info ATTRIBUTE_UNUSED)
5440
0
{
5441
0
  abort ();
5442
0
  return 0;
5443
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: pei-riscv64.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
5444
5445
#endif
5446
5447
#ifndef coff_reloc16_extra_cases
5448
5449
#define coff_reloc16_extra_cases dummy_reloc16_extra_cases
5450
5451
static bool
5452
dummy_reloc16_extra_cases (bfd *abfd ATTRIBUTE_UNUSED,
5453
         struct bfd_link_info *link_info ATTRIBUTE_UNUSED,
5454
         struct bfd_link_order *link_order ATTRIBUTE_UNUSED,
5455
         arelent *reloc ATTRIBUTE_UNUSED,
5456
         bfd_byte *data ATTRIBUTE_UNUSED,
5457
         size_t *src_ptr ATTRIBUTE_UNUSED,
5458
         size_t *dst_ptr ATTRIBUTE_UNUSED)
5459
0
{
5460
0
  return false;
5461
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: pei-riscv64.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
5462
#endif
5463
5464
/* If coff_relocate_section is defined, we can use the optimized COFF
5465
   backend linker.  Otherwise we must continue to use the old linker.  */
5466
5467
#ifdef coff_relocate_section
5468
5469
#ifndef coff_bfd_link_hash_table_create
5470
#define coff_bfd_link_hash_table_create _bfd_coff_link_hash_table_create
5471
#endif
5472
#ifndef coff_bfd_link_add_symbols
5473
#define coff_bfd_link_add_symbols _bfd_coff_link_add_symbols
5474
#endif
5475
#ifndef coff_bfd_final_link
5476
#define coff_bfd_final_link _bfd_coff_final_link
5477
#endif
5478
5479
#else /* ! defined (coff_relocate_section) */
5480
5481
#define coff_relocate_section NULL
5482
#ifndef coff_bfd_link_hash_table_create
5483
#define coff_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
5484
#endif
5485
#ifndef coff_bfd_link_add_symbols
5486
#define coff_bfd_link_add_symbols _bfd_generic_link_add_symbols
5487
#endif
5488
#define coff_bfd_final_link _bfd_generic_final_link
5489
5490
#endif /* ! defined (coff_relocate_section) */
5491
5492
#define coff_bfd_link_just_syms      _bfd_generic_link_just_syms
5493
#define coff_bfd_copy_link_hash_symbol_type \
5494
  _bfd_generic_copy_link_hash_symbol_type
5495
#define coff_bfd_link_split_section  _bfd_generic_link_split_section
5496
5497
#define coff_bfd_link_check_relocs   _bfd_generic_link_check_relocs
5498
5499
#ifndef coff_start_final_link
5500
#define coff_start_final_link NULL
5501
#endif
5502
5503
#ifndef coff_adjust_symndx
5504
#define coff_adjust_symndx NULL
5505
#endif
5506
5507
#ifndef coff_link_output_has_begun
5508
5509
static bool
5510
coff_link_output_has_begun (bfd * abfd,
5511
          struct coff_final_link_info * info ATTRIBUTE_UNUSED)
5512
0
{
5513
0
  return abfd->output_has_begun;
5514
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: pei-riscv64.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
5515
#endif
5516
5517
#ifndef coff_final_link_postscript
5518
5519
static bool
5520
coff_final_link_postscript (bfd * abfd ATTRIBUTE_UNUSED,
5521
          struct coff_final_link_info * pfinfo ATTRIBUTE_UNUSED)
5522
0
{
5523
0
  return true;
5524
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
5525
#endif
5526
5527
#ifndef coff_SWAP_aux_in
5528
#define coff_SWAP_aux_in coff_swap_aux_in
5529
#endif
5530
#ifndef coff_SWAP_sym_in
5531
#define coff_SWAP_sym_in coff_swap_sym_in
5532
#endif
5533
#ifndef coff_SWAP_lineno_in
5534
#define coff_SWAP_lineno_in coff_swap_lineno_in
5535
#endif
5536
#ifndef coff_SWAP_aux_out
5537
#define coff_SWAP_aux_out coff_swap_aux_out
5538
#endif
5539
#ifndef coff_SWAP_sym_out
5540
#define coff_SWAP_sym_out coff_swap_sym_out
5541
#endif
5542
#ifndef coff_SWAP_lineno_out
5543
#define coff_SWAP_lineno_out coff_swap_lineno_out
5544
#endif
5545
#ifndef coff_SWAP_reloc_out
5546
#define coff_SWAP_reloc_out coff_swap_reloc_out
5547
#endif
5548
#ifndef coff_SWAP_filehdr_out
5549
#define coff_SWAP_filehdr_out coff_swap_filehdr_out
5550
#endif
5551
#ifndef coff_SWAP_aouthdr_out
5552
#define coff_SWAP_aouthdr_out coff_swap_aouthdr_out
5553
#endif
5554
#ifndef coff_SWAP_scnhdr_out
5555
#define coff_SWAP_scnhdr_out coff_swap_scnhdr_out
5556
#endif
5557
#ifndef coff_SWAP_reloc_in
5558
#define coff_SWAP_reloc_in coff_swap_reloc_in
5559
#endif
5560
#ifndef coff_SWAP_filehdr_in
5561
#define coff_SWAP_filehdr_in coff_swap_filehdr_in
5562
#endif
5563
#ifndef coff_SWAP_aouthdr_in
5564
#define coff_SWAP_aouthdr_in coff_swap_aouthdr_in
5565
#endif
5566
#ifndef coff_SWAP_scnhdr_in
5567
#define coff_SWAP_scnhdr_in coff_swap_scnhdr_in
5568
#endif
5569
5570
#define COFF_SWAP_TABLE (void *) &bfd_coff_std_swap_table
5571
5572
static const bfd_coff_backend_data bfd_coff_std_swap_table ATTRIBUTE_UNUSED =
5573
{
5574
  coff_SWAP_aux_in, coff_SWAP_sym_in, coff_SWAP_lineno_in,
5575
  coff_SWAP_aux_out, coff_SWAP_sym_out,
5576
  coff_SWAP_lineno_out, coff_SWAP_reloc_out,
5577
  coff_SWAP_filehdr_out, coff_SWAP_aouthdr_out,
5578
  coff_SWAP_scnhdr_out,
5579
  FILHSZ, AOUTSZ, SCNHSZ, SYMESZ, AUXESZ, RELSZ, LINESZ, FILNMLEN,
5580
#ifdef COFF_LONG_FILENAMES
5581
  true,
5582
#else
5583
  false,
5584
#endif
5585
  COFF_DEFAULT_LONG_SECTION_NAMES,
5586
  COFF_DEFAULT_SECTION_ALIGNMENT_POWER,
5587
#ifdef COFF_FORCE_SYMBOLS_IN_STRINGS
5588
  true,
5589
#else
5590
  false,
5591
#endif
5592
#ifdef COFF_DEBUG_STRING_WIDE_PREFIX
5593
  4,
5594
#else
5595
  2,
5596
#endif
5597
  32768,
5598
  coff_SWAP_filehdr_in, coff_SWAP_aouthdr_in, coff_SWAP_scnhdr_in,
5599
  coff_SWAP_reloc_in, coff_bad_format_hook, coff_set_arch_mach_hook,
5600
  coff_mkobject_hook, styp_to_sec_flags, coff_set_alignment_hook,
5601
  coff_slurp_symbol_table, symname_in_debug_hook, coff_pointerize_aux_hook,
5602
  coff_print_aux, coff_reloc16_extra_cases, coff_reloc16_estimate,
5603
  coff_classify_symbol, coff_compute_section_file_positions,
5604
  coff_start_final_link, coff_relocate_section, coff_rtype_to_howto,
5605
  coff_adjust_symndx,
5606
  coff_link_output_has_begun, coff_final_link_postscript,
5607
  bfd_pe_print_pdata
5608
};
5609
5610
#ifdef TICOFF
5611
/* COFF0 differs in file/section header size and relocation entry size.  */
5612
5613
static const bfd_coff_backend_data ticoff0_swap_table =
5614
{
5615
  coff_SWAP_aux_in, coff_SWAP_sym_in, coff_SWAP_lineno_in,
5616
  coff_SWAP_aux_out, coff_SWAP_sym_out,
5617
  coff_SWAP_lineno_out, coff_swap_reloc_v0_out,
5618
  coff_SWAP_filehdr_out, coff_SWAP_aouthdr_out,
5619
  coff_SWAP_scnhdr_out,
5620
  FILHSZ_V0, AOUTSZ, SCNHSZ_V01, SYMESZ, AUXESZ, RELSZ_V0, LINESZ, FILNMLEN,
5621
#ifdef COFF_LONG_FILENAMES
5622
  true,
5623
#else
5624
  false,
5625
#endif
5626
  COFF_DEFAULT_LONG_SECTION_NAMES,
5627
  COFF_DEFAULT_SECTION_ALIGNMENT_POWER,
5628
#ifdef COFF_FORCE_SYMBOLS_IN_STRINGS
5629
  true,
5630
#else
5631
  false,
5632
#endif
5633
#ifdef COFF_DEBUG_STRING_WIDE_PREFIX
5634
  4,
5635
#else
5636
  2,
5637
#endif
5638
  32768,
5639
  coff_SWAP_filehdr_in, coff_SWAP_aouthdr_in, coff_SWAP_scnhdr_in,
5640
  coff_swap_reloc_v0_in, ticoff0_bad_format_hook, coff_set_arch_mach_hook,
5641
  coff_mkobject_hook, styp_to_sec_flags, coff_set_alignment_hook,
5642
  coff_slurp_symbol_table, symname_in_debug_hook, coff_pointerize_aux_hook,
5643
  coff_print_aux, coff_reloc16_extra_cases, coff_reloc16_estimate,
5644
  coff_classify_symbol, coff_compute_section_file_positions,
5645
  coff_start_final_link, coff_relocate_section, coff_rtype_to_howto,
5646
  coff_adjust_symndx,
5647
  coff_link_output_has_begun, coff_final_link_postscript,
5648
  bfd_pe_print_pdata
5649
};
5650
#endif
5651
5652
#ifdef TICOFF
5653
/* COFF1 differs in section header size.  */
5654
5655
static const bfd_coff_backend_data ticoff1_swap_table =
5656
{
5657
  coff_SWAP_aux_in, coff_SWAP_sym_in, coff_SWAP_lineno_in,
5658
  coff_SWAP_aux_out, coff_SWAP_sym_out,
5659
  coff_SWAP_lineno_out, coff_SWAP_reloc_out,
5660
  coff_SWAP_filehdr_out, coff_SWAP_aouthdr_out,
5661
  coff_SWAP_scnhdr_out,
5662
  FILHSZ, AOUTSZ, SCNHSZ_V01, SYMESZ, AUXESZ, RELSZ, LINESZ, FILNMLEN,
5663
#ifdef COFF_LONG_FILENAMES
5664
  true,
5665
#else
5666
  false,
5667
#endif
5668
  COFF_DEFAULT_LONG_SECTION_NAMES,
5669
  COFF_DEFAULT_SECTION_ALIGNMENT_POWER,
5670
#ifdef COFF_FORCE_SYMBOLS_IN_STRINGS
5671
  true,
5672
#else
5673
  false,
5674
#endif
5675
#ifdef COFF_DEBUG_STRING_WIDE_PREFIX
5676
  4,
5677
#else
5678
  2,
5679
#endif
5680
  32768,
5681
  coff_SWAP_filehdr_in, coff_SWAP_aouthdr_in, coff_SWAP_scnhdr_in,
5682
  coff_SWAP_reloc_in, ticoff1_bad_format_hook, coff_set_arch_mach_hook,
5683
  coff_mkobject_hook, styp_to_sec_flags, coff_set_alignment_hook,
5684
  coff_slurp_symbol_table, symname_in_debug_hook, coff_pointerize_aux_hook,
5685
  coff_print_aux, coff_reloc16_extra_cases, coff_reloc16_estimate,
5686
  coff_classify_symbol, coff_compute_section_file_positions,
5687
  coff_start_final_link, coff_relocate_section, coff_rtype_to_howto,
5688
  coff_adjust_symndx,
5689
  coff_link_output_has_begun, coff_final_link_postscript,
5690
  bfd_pe_print_pdata  /* huh */
5691
};
5692
#endif
5693
5694
#ifdef COFF_WITH_PE_BIGOBJ
5695
/* The UID for bigobj files.  */
5696
5697
static const char header_bigobj_classid[16] =
5698
{
5699
  0xC7, 0xA1, 0xBA, 0xD1,
5700
  0xEE, 0xBA,
5701
  0xa9, 0x4b,
5702
  0xAF, 0x20,
5703
  0xFA, 0xF6, 0x6A, 0xA4, 0xDC, 0xB8
5704
};
5705
5706
/* Swap routines.  */
5707
5708
static void
5709
coff_bigobj_swap_filehdr_in (bfd * abfd, void * src, void * dst)
5710
6.10M
{
5711
6.10M
  struct external_ANON_OBJECT_HEADER_BIGOBJ *filehdr_src =
5712
6.10M
    (struct external_ANON_OBJECT_HEADER_BIGOBJ *) src;
5713
6.10M
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
5714
5715
6.10M
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->Machine);
5716
6.10M
  filehdr_dst->f_nscns  = H_GET_32 (abfd, filehdr_src->NumberOfSections);
5717
6.10M
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->TimeDateStamp);
5718
6.10M
  filehdr_dst->f_symptr =
5719
6.10M
    GET_FILEHDR_SYMPTR (abfd, filehdr_src->PointerToSymbolTable);
5720
6.10M
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->NumberOfSymbols);
5721
6.10M
  filehdr_dst->f_opthdr = 0;
5722
6.10M
  filehdr_dst->f_flags  = 0;
5723
5724
  /* Check other magic numbers.  */
5725
6.10M
  if (H_GET_16 (abfd, filehdr_src->Sig1) != IMAGE_FILE_MACHINE_UNKNOWN
5726
6.10M
      || H_GET_16 (abfd, filehdr_src->Sig2) != 0xffff
5727
6.10M
      || H_GET_16 (abfd, filehdr_src->Version) != 2
5728
6.10M
      || memcmp (filehdr_src->ClassID, header_bigobj_classid, 16) != 0)
5729
6.10M
    filehdr_dst->f_opthdr = 0xffff;
5730
5731
  /* Note that CLR metadata are ignored.  */
5732
6.10M
}
pe-x86_64.c:coff_bigobj_swap_filehdr_in
Line
Count
Source
5710
3.05M
{
5711
3.05M
  struct external_ANON_OBJECT_HEADER_BIGOBJ *filehdr_src =
5712
3.05M
    (struct external_ANON_OBJECT_HEADER_BIGOBJ *) src;
5713
3.05M
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
5714
5715
3.05M
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->Machine);
5716
3.05M
  filehdr_dst->f_nscns  = H_GET_32 (abfd, filehdr_src->NumberOfSections);
5717
3.05M
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->TimeDateStamp);
5718
3.05M
  filehdr_dst->f_symptr =
5719
3.05M
    GET_FILEHDR_SYMPTR (abfd, filehdr_src->PointerToSymbolTable);
5720
3.05M
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->NumberOfSymbols);
5721
3.05M
  filehdr_dst->f_opthdr = 0;
5722
3.05M
  filehdr_dst->f_flags  = 0;
5723
5724
  /* Check other magic numbers.  */
5725
3.05M
  if (H_GET_16 (abfd, filehdr_src->Sig1) != IMAGE_FILE_MACHINE_UNKNOWN
5726
3.05M
      || H_GET_16 (abfd, filehdr_src->Sig2) != 0xffff
5727
3.05M
      || H_GET_16 (abfd, filehdr_src->Version) != 2
5728
3.05M
      || memcmp (filehdr_src->ClassID, header_bigobj_classid, 16) != 0)
5729
3.05M
    filehdr_dst->f_opthdr = 0xffff;
5730
5731
  /* Note that CLR metadata are ignored.  */
5732
3.05M
}
pe-i386.c:coff_bigobj_swap_filehdr_in
Line
Count
Source
5710
3.04M
{
5711
3.04M
  struct external_ANON_OBJECT_HEADER_BIGOBJ *filehdr_src =
5712
3.04M
    (struct external_ANON_OBJECT_HEADER_BIGOBJ *) src;
5713
3.04M
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
5714
5715
3.04M
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->Machine);
5716
3.04M
  filehdr_dst->f_nscns  = H_GET_32 (abfd, filehdr_src->NumberOfSections);
5717
3.04M
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->TimeDateStamp);
5718
3.04M
  filehdr_dst->f_symptr =
5719
3.04M
    GET_FILEHDR_SYMPTR (abfd, filehdr_src->PointerToSymbolTable);
5720
3.04M
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->NumberOfSymbols);
5721
3.04M
  filehdr_dst->f_opthdr = 0;
5722
3.04M
  filehdr_dst->f_flags  = 0;
5723
5724
  /* Check other magic numbers.  */
5725
3.04M
  if (H_GET_16 (abfd, filehdr_src->Sig1) != IMAGE_FILE_MACHINE_UNKNOWN
5726
3.04M
      || H_GET_16 (abfd, filehdr_src->Sig2) != 0xffff
5727
3.04M
      || H_GET_16 (abfd, filehdr_src->Version) != 2
5728
3.04M
      || memcmp (filehdr_src->ClassID, header_bigobj_classid, 16) != 0)
5729
3.04M
    filehdr_dst->f_opthdr = 0xffff;
5730
5731
  /* Note that CLR metadata are ignored.  */
5732
3.04M
}
5733
5734
static unsigned int
5735
coff_bigobj_swap_filehdr_out (bfd *abfd, void * in, void * out)
5736
0
{
5737
0
  struct internal_filehdr *filehdr_in = (struct internal_filehdr *) in;
5738
0
  struct external_ANON_OBJECT_HEADER_BIGOBJ *filehdr_out =
5739
0
    (struct external_ANON_OBJECT_HEADER_BIGOBJ *) out;
5740
5741
0
  memset (filehdr_out, 0, sizeof (*filehdr_out));
5742
5743
0
  H_PUT_16 (abfd, IMAGE_FILE_MACHINE_UNKNOWN, filehdr_out->Sig1);
5744
0
  H_PUT_16 (abfd, 0xffff, filehdr_out->Sig2);
5745
0
  H_PUT_16 (abfd, 2, filehdr_out->Version);
5746
0
  memcpy (filehdr_out->ClassID, header_bigobj_classid, 16);
5747
0
  H_PUT_16 (abfd, filehdr_in->f_magic, filehdr_out->Machine);
5748
0
  H_PUT_32 (abfd, filehdr_in->f_nscns, filehdr_out->NumberOfSections);
5749
0
  H_PUT_32 (abfd, filehdr_in->f_timdat, filehdr_out->TimeDateStamp);
5750
0
  PUT_FILEHDR_SYMPTR (abfd, filehdr_in->f_symptr,
5751
0
          filehdr_out->PointerToSymbolTable);
5752
0
  H_PUT_32 (abfd, filehdr_in->f_nsyms, filehdr_out->NumberOfSymbols);
5753
5754
0
  return bfd_coff_filhsz (abfd);
5755
0
}
Unexecuted instantiation: pe-x86_64.c:coff_bigobj_swap_filehdr_out
Unexecuted instantiation: pe-i386.c:coff_bigobj_swap_filehdr_out
5756
5757
static void
5758
coff_bigobj_swap_sym_in (bfd * abfd, void * ext1, void * in1)
5759
126k
{
5760
126k
  SYMENT_BIGOBJ *ext = (SYMENT_BIGOBJ *) ext1;
5761
126k
  struct internal_syment *in = (struct internal_syment *) in1;
5762
5763
126k
  if (ext->e.e_name[0] == 0)
5764
89.7k
    {
5765
89.7k
      in->_n._n_n._n_zeroes = 0;
5766
89.7k
      in->_n._n_n._n_offset = H_GET_32 (abfd, ext->e.e.e_offset);
5767
89.7k
    }
5768
36.4k
  else
5769
36.4k
    {
5770
#if SYMNMLEN != E_SYMNMLEN
5771
#error we need to cope with truncating or extending SYMNMLEN
5772
#else
5773
36.4k
      memcpy (in->_n._n_name, ext->e.e_name, SYMNMLEN);
5774
36.4k
#endif
5775
36.4k
    }
5776
5777
126k
  in->n_value = H_GET_32 (abfd, ext->e_value);
5778
126k
  BFD_ASSERT (sizeof (in->n_scnum) >= 4);
5779
126k
  in->n_scnum = H_GET_32 (abfd, ext->e_scnum);
5780
126k
  in->n_type = H_GET_16 (abfd, ext->e_type);
5781
126k
  in->n_sclass = H_GET_8 (abfd, ext->e_sclass);
5782
126k
  in->n_numaux = H_GET_8 (abfd, ext->e_numaux);
5783
126k
}
pe-x86_64.c:coff_bigobj_swap_sym_in
Line
Count
Source
5759
121k
{
5760
121k
  SYMENT_BIGOBJ *ext = (SYMENT_BIGOBJ *) ext1;
5761
121k
  struct internal_syment *in = (struct internal_syment *) in1;
5762
5763
121k
  if (ext->e.e_name[0] == 0)
5764
87.8k
    {
5765
87.8k
      in->_n._n_n._n_zeroes = 0;
5766
87.8k
      in->_n._n_n._n_offset = H_GET_32 (abfd, ext->e.e.e_offset);
5767
87.8k
    }
5768
34.0k
  else
5769
34.0k
    {
5770
#if SYMNMLEN != E_SYMNMLEN
5771
#error we need to cope with truncating or extending SYMNMLEN
5772
#else
5773
34.0k
      memcpy (in->_n._n_name, ext->e.e_name, SYMNMLEN);
5774
34.0k
#endif
5775
34.0k
    }
5776
5777
121k
  in->n_value = H_GET_32 (abfd, ext->e_value);
5778
121k
  BFD_ASSERT (sizeof (in->n_scnum) >= 4);
5779
121k
  in->n_scnum = H_GET_32 (abfd, ext->e_scnum);
5780
121k
  in->n_type = H_GET_16 (abfd, ext->e_type);
5781
121k
  in->n_sclass = H_GET_8 (abfd, ext->e_sclass);
5782
121k
  in->n_numaux = H_GET_8 (abfd, ext->e_numaux);
5783
121k
}
pe-i386.c:coff_bigobj_swap_sym_in
Line
Count
Source
5759
4.24k
{
5760
4.24k
  SYMENT_BIGOBJ *ext = (SYMENT_BIGOBJ *) ext1;
5761
4.24k
  struct internal_syment *in = (struct internal_syment *) in1;
5762
5763
4.24k
  if (ext->e.e_name[0] == 0)
5764
1.84k
    {
5765
1.84k
      in->_n._n_n._n_zeroes = 0;
5766
1.84k
      in->_n._n_n._n_offset = H_GET_32 (abfd, ext->e.e.e_offset);
5767
1.84k
    }
5768
2.40k
  else
5769
2.40k
    {
5770
#if SYMNMLEN != E_SYMNMLEN
5771
#error we need to cope with truncating or extending SYMNMLEN
5772
#else
5773
2.40k
      memcpy (in->_n._n_name, ext->e.e_name, SYMNMLEN);
5774
2.40k
#endif
5775
2.40k
    }
5776
5777
4.24k
  in->n_value = H_GET_32 (abfd, ext->e_value);
5778
4.24k
  BFD_ASSERT (sizeof (in->n_scnum) >= 4);
5779
4.24k
  in->n_scnum = H_GET_32 (abfd, ext->e_scnum);
5780
4.24k
  in->n_type = H_GET_16 (abfd, ext->e_type);
5781
4.24k
  in->n_sclass = H_GET_8 (abfd, ext->e_sclass);
5782
4.24k
  in->n_numaux = H_GET_8 (abfd, ext->e_numaux);
5783
4.24k
}
5784
5785
static unsigned int
5786
coff_bigobj_swap_sym_out (bfd * abfd, void * inp, void * extp)
5787
0
{
5788
0
  struct internal_syment *in = (struct internal_syment *) inp;
5789
0
  SYMENT_BIGOBJ *ext = (SYMENT_BIGOBJ *) extp;
5790
5791
0
  if (in->_n._n_name[0] == 0)
5792
0
    {
5793
0
      H_PUT_32 (abfd, 0, ext->e.e.e_zeroes);
5794
0
      H_PUT_32 (abfd, in->_n._n_n._n_offset, ext->e.e.e_offset);
5795
0
    }
5796
0
  else
5797
0
    {
5798
#if SYMNMLEN != E_SYMNMLEN
5799
#error we need to cope with truncating or extending SYMNMLEN
5800
#else
5801
0
      memcpy (ext->e.e_name, in->_n._n_name, SYMNMLEN);
5802
0
#endif
5803
0
    }
5804
5805
0
  H_PUT_32 (abfd, in->n_value, ext->e_value);
5806
0
  H_PUT_32 (abfd, in->n_scnum, ext->e_scnum);
5807
5808
0
  H_PUT_16 (abfd, in->n_type, ext->e_type);
5809
0
  H_PUT_8 (abfd, in->n_sclass, ext->e_sclass);
5810
0
  H_PUT_8 (abfd, in->n_numaux, ext->e_numaux);
5811
5812
0
  return SYMESZ_BIGOBJ;
5813
0
}
Unexecuted instantiation: pe-x86_64.c:coff_bigobj_swap_sym_out
Unexecuted instantiation: pe-i386.c:coff_bigobj_swap_sym_out
5814
5815
static void
5816
coff_bigobj_swap_aux_in (bfd *abfd,
5817
       void * ext1,
5818
       int type,
5819
       int in_class,
5820
       int indx ATTRIBUTE_UNUSED,
5821
       int numaux ATTRIBUTE_UNUSED,
5822
       void * in1)
5823
941k
{
5824
941k
  AUXENT_BIGOBJ *ext = (AUXENT_BIGOBJ *) ext1;
5825
941k
  union internal_auxent *in = (union internal_auxent *) in1;
5826
5827
  /* Make sure that all fields in the aux structure are
5828
     initialised.  */
5829
941k
  memset (in, 0, sizeof * in);
5830
941k
  switch (in_class)
5831
941k
    {
5832
4.20k
    case C_FILE:
5833
4.20k
      memcpy (in->x_file.x_n.x_fname, ext->File.Name, sizeof (ext->File.Name));
5834
4.20k
      break;
5835
5836
4.23k
    case C_STAT:
5837
5.27k
    case C_LEAFSTAT:
5838
10.6k
    case C_HIDDEN:
5839
10.6k
      if (type == T_NULL)
5840
1.78k
  {
5841
1.78k
    in->x_scn.x_scnlen = H_GET_32 (abfd, ext->Section.Length);
5842
1.78k
    in->x_scn.x_nreloc =
5843
1.78k
      H_GET_16 (abfd, ext->Section.NumberOfRelocations);
5844
1.78k
    in->x_scn.x_nlinno =
5845
1.78k
      H_GET_16 (abfd, ext->Section.NumberOfLinenumbers);
5846
1.78k
    in->x_scn.x_checksum = H_GET_32 (abfd, ext->Section.Checksum);
5847
1.78k
    in->x_scn.x_associated = H_GET_16 (abfd, ext->Section.Number)
5848
1.78k
      | (H_GET_16 (abfd, ext->Section.HighNumber) << 16);
5849
1.78k
    in->x_scn.x_comdat = H_GET_8 (abfd, ext->Section.Selection);
5850
1.78k
    return;
5851
1.78k
  }
5852
8.87k
      break;
5853
5854
926k
    default:
5855
926k
      in->x_sym.x_tagndx.u32 = H_GET_32 (abfd, ext->Sym.WeakDefaultSymIndex);
5856
      /* Characteristics is ignored.  */
5857
926k
      break;
5858
941k
    }
5859
941k
}
pe-x86_64.c:coff_bigobj_swap_aux_in
Line
Count
Source
5823
941k
{
5824
941k
  AUXENT_BIGOBJ *ext = (AUXENT_BIGOBJ *) ext1;
5825
941k
  union internal_auxent *in = (union internal_auxent *) in1;
5826
5827
  /* Make sure that all fields in the aux structure are
5828
     initialised.  */
5829
941k
  memset (in, 0, sizeof * in);
5830
941k
  switch (in_class)
5831
941k
    {
5832
4.19k
    case C_FILE:
5833
4.19k
      memcpy (in->x_file.x_n.x_fname, ext->File.Name, sizeof (ext->File.Name));
5834
4.19k
      break;
5835
5836
4.23k
    case C_STAT:
5837
5.26k
    case C_LEAFSTAT:
5838
10.6k
    case C_HIDDEN:
5839
10.6k
      if (type == T_NULL)
5840
1.78k
  {
5841
1.78k
    in->x_scn.x_scnlen = H_GET_32 (abfd, ext->Section.Length);
5842
1.78k
    in->x_scn.x_nreloc =
5843
1.78k
      H_GET_16 (abfd, ext->Section.NumberOfRelocations);
5844
1.78k
    in->x_scn.x_nlinno =
5845
1.78k
      H_GET_16 (abfd, ext->Section.NumberOfLinenumbers);
5846
1.78k
    in->x_scn.x_checksum = H_GET_32 (abfd, ext->Section.Checksum);
5847
1.78k
    in->x_scn.x_associated = H_GET_16 (abfd, ext->Section.Number)
5848
1.78k
      | (H_GET_16 (abfd, ext->Section.HighNumber) << 16);
5849
1.78k
    in->x_scn.x_comdat = H_GET_8 (abfd, ext->Section.Selection);
5850
1.78k
    return;
5851
1.78k
  }
5852
8.87k
      break;
5853
5854
926k
    default:
5855
926k
      in->x_sym.x_tagndx.u32 = H_GET_32 (abfd, ext->Sym.WeakDefaultSymIndex);
5856
      /* Characteristics is ignored.  */
5857
926k
      break;
5858
941k
    }
5859
941k
}
pe-i386.c:coff_bigobj_swap_aux_in
Line
Count
Source
5823
288
{
5824
288
  AUXENT_BIGOBJ *ext = (AUXENT_BIGOBJ *) ext1;
5825
288
  union internal_auxent *in = (union internal_auxent *) in1;
5826
5827
  /* Make sure that all fields in the aux structure are
5828
     initialised.  */
5829
288
  memset (in, 0, sizeof * in);
5830
288
  switch (in_class)
5831
288
    {
5832
15
    case C_FILE:
5833
15
      memcpy (in->x_file.x_n.x_fname, ext->File.Name, sizeof (ext->File.Name));
5834
15
      break;
5835
5836
1
    case C_STAT:
5837
2
    case C_LEAFSTAT:
5838
3
    case C_HIDDEN:
5839
3
      if (type == T_NULL)
5840
2
  {
5841
2
    in->x_scn.x_scnlen = H_GET_32 (abfd, ext->Section.Length);
5842
2
    in->x_scn.x_nreloc =
5843
2
      H_GET_16 (abfd, ext->Section.NumberOfRelocations);
5844
2
    in->x_scn.x_nlinno =
5845
2
      H_GET_16 (abfd, ext->Section.NumberOfLinenumbers);
5846
2
    in->x_scn.x_checksum = H_GET_32 (abfd, ext->Section.Checksum);
5847
2
    in->x_scn.x_associated = H_GET_16 (abfd, ext->Section.Number)
5848
2
      | (H_GET_16 (abfd, ext->Section.HighNumber) << 16);
5849
2
    in->x_scn.x_comdat = H_GET_8 (abfd, ext->Section.Selection);
5850
2
    return;
5851
2
  }
5852
1
      break;
5853
5854
270
    default:
5855
270
      in->x_sym.x_tagndx.u32 = H_GET_32 (abfd, ext->Sym.WeakDefaultSymIndex);
5856
      /* Characteristics is ignored.  */
5857
270
      break;
5858
288
    }
5859
288
}
5860
5861
static unsigned int
5862
coff_bigobj_swap_aux_out (bfd * abfd,
5863
        void * inp,
5864
        int type,
5865
        int in_class,
5866
        int indx ATTRIBUTE_UNUSED,
5867
        int numaux ATTRIBUTE_UNUSED,
5868
        void * extp)
5869
0
{
5870
0
  union internal_auxent * in = (union internal_auxent *) inp;
5871
0
  AUXENT_BIGOBJ *ext = (AUXENT_BIGOBJ *) extp;
5872
5873
0
  memset (ext, 0, AUXESZ);
5874
5875
0
  switch (in_class)
5876
0
    {
5877
0
    case C_FILE:
5878
0
      memcpy (ext->File.Name, in->x_file.x_n.x_fname, sizeof (ext->File.Name));
5879
5880
0
      return AUXESZ;
5881
5882
0
    case C_STAT:
5883
0
    case C_LEAFSTAT:
5884
0
    case C_HIDDEN:
5885
0
      if (type == T_NULL)
5886
0
  {
5887
0
    H_PUT_32 (abfd, in->x_scn.x_scnlen, ext->Section.Length);
5888
0
    H_PUT_16 (abfd, in->x_scn.x_nreloc,
5889
0
        ext->Section.NumberOfRelocations);
5890
0
    H_PUT_16 (abfd, in->x_scn.x_nlinno,
5891
0
        ext->Section.NumberOfLinenumbers);
5892
0
    H_PUT_32 (abfd, in->x_scn.x_checksum, ext->Section.Checksum);
5893
0
    H_PUT_16 (abfd, in->x_scn.x_associated & 0xffff,
5894
0
        ext->Section.Number);
5895
0
    H_PUT_16 (abfd, (in->x_scn.x_associated >> 16),
5896
0
        ext->Section.HighNumber);
5897
0
    H_PUT_8 (abfd, in->x_scn.x_comdat, ext->Section.Selection);
5898
0
    return AUXESZ;
5899
0
  }
5900
0
      break;
5901
0
    }
5902
5903
0
  H_PUT_32 (abfd, in->x_sym.x_tagndx.u32, ext->Sym.WeakDefaultSymIndex);
5904
0
  H_PUT_32 (abfd, 1, ext->Sym.WeakSearchType);
5905
5906
0
  return AUXESZ;
5907
0
}
Unexecuted instantiation: pe-x86_64.c:coff_bigobj_swap_aux_out
Unexecuted instantiation: pe-i386.c:coff_bigobj_swap_aux_out
5908
5909
static const bfd_coff_backend_data bigobj_swap_table =
5910
{
5911
  coff_bigobj_swap_aux_in, coff_bigobj_swap_sym_in, coff_SWAP_lineno_in,
5912
  coff_bigobj_swap_aux_out, coff_bigobj_swap_sym_out,
5913
  coff_SWAP_lineno_out, coff_SWAP_reloc_out,
5914
  coff_bigobj_swap_filehdr_out, coff_SWAP_aouthdr_out,
5915
  coff_SWAP_scnhdr_out,
5916
  FILHSZ_BIGOBJ, AOUTSZ, SCNHSZ, SYMESZ_BIGOBJ, AUXESZ_BIGOBJ,
5917
   RELSZ, LINESZ, FILNMLEN_BIGOBJ,
5918
  true,
5919
  COFF_DEFAULT_LONG_SECTION_NAMES,
5920
  COFF_DEFAULT_SECTION_ALIGNMENT_POWER,
5921
  false,
5922
  2,
5923
  1U << 31,
5924
  coff_bigobj_swap_filehdr_in, coff_SWAP_aouthdr_in, coff_SWAP_scnhdr_in,
5925
  coff_SWAP_reloc_in, coff_bad_format_hook, coff_set_arch_mach_hook,
5926
  coff_mkobject_hook, styp_to_sec_flags, coff_set_alignment_hook,
5927
  coff_slurp_symbol_table, symname_in_debug_hook, coff_pointerize_aux_hook,
5928
  coff_print_aux, coff_reloc16_extra_cases, coff_reloc16_estimate,
5929
  coff_classify_symbol, coff_compute_section_file_positions,
5930
  coff_start_final_link, coff_relocate_section, coff_rtype_to_howto,
5931
  coff_adjust_symndx,
5932
  coff_link_output_has_begun, coff_final_link_postscript,
5933
  bfd_pe_print_pdata  /* huh */
5934
};
5935
5936
#endif /* COFF_WITH_PE_BIGOBJ */
5937
5938
#ifndef coff_close_and_cleanup
5939
#define coff_close_and_cleanup        _bfd_generic_close_and_cleanup
5940
#endif
5941
5942
#ifndef coff_bfd_free_cached_info
5943
#define coff_bfd_free_cached_info     _bfd_coff_free_cached_info
5944
#endif
5945
5946
#ifndef coff_get_section_contents
5947
#define coff_get_section_contents     _bfd_generic_get_section_contents
5948
#endif
5949
5950
#ifndef coff_bfd_copy_private_symbol_data
5951
#define coff_bfd_copy_private_symbol_data   _bfd_generic_bfd_copy_private_symbol_data
5952
#endif
5953
5954
#ifndef coff_bfd_copy_private_header_data
5955
#define coff_bfd_copy_private_header_data   _bfd_generic_bfd_copy_private_header_data
5956
#endif
5957
5958
#define coff_init_private_section_data      _bfd_generic_init_private_section_data
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
};